diff options
author | 2014-05-05 16:04:42 +0000 | |
---|---|---|
committer | 2014-05-05 16:04:42 +0000 | |
commit | 4e332f82fce0126045e9cb2ef0a2097a6c4c40a3 (patch) | |
tree | f2bef88528e573fc428eebfb8a653f4ed0d4a186 /include/core/SkRect.h | |
parent | 3df4e954029919ae894797635c9f310681dc83fd (diff) |
add rounding-using-doubles methods on SkScalar and SkRect
Inspired by the excellent repro case for https://crbug.com/364224
patch from issue 265933010
BUG=skia:
R=bungeman@google.com
Author: reed@google.com
Review URL: https://codereview.chromium.org/267003002
git-svn-id: http://skia.googlecode.com/svn/trunk@14566 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core/SkRect.h')
-rw-r--r-- | include/core/SkRect.h | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/include/core/SkRect.h b/include/core/SkRect.h index 397e4a03ee..fd8cb16020 100644 --- a/include/core/SkRect.h +++ b/include/core/SkRect.h @@ -732,6 +732,24 @@ struct SK_API SkRect { } /** + * Variant of round() that explicitly performs the rounding step (i.e. floor(x + 0.5)) using + * double instead of SkScalar (float). It does this by calling SkDScalarRoundToInt(), which + * may be slower than calling SkScalarRountToInt(), but gives slightly more accurate results. + * + * e.g. + * SkScalar x = 0.49999997f; + * int ix = SkScalarRoundToInt(x); + * SkASSERT(0 == ix); // <--- fails + * ix = SkDScalarRoundToInt(x); + * SkASSERT(0 == ix); // <--- succeeds + */ + void dround(SkIRect* dst) const { + SkASSERT(dst); + dst->set(SkDScalarRoundToInt(fLeft), SkDScalarRoundToInt(fTop), + SkDScalarRoundToInt(fRight), SkDScalarRoundToInt(fBottom)); + } + + /** * Set the dst rectangle by rounding "out" this rectangle, choosing the * SkScalarFloor of top and left, and the SkScalarCeil of right and bottom. */ |