summaryrefslogtreecommitdiff
path: root/core/SkRect.h
diff options
context:
space:
mode:
Diffstat (limited to 'core/SkRect.h')
-rw-r--r--core/SkRect.h18
1 files changed, 18 insertions, 0 deletions
diff --git a/core/SkRect.h b/core/SkRect.h
index 397e4a0..fd8cb16 100644
--- a/core/SkRect.h
+++ b/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.
*/