aboutsummaryrefslogtreecommitdiffhomepage
path: root/include/core/SkRect.h
diff options
context:
space:
mode:
authorGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-06 22:02:51 +0000
committerGravatar reed@google.com <reed@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2012-11-06 22:02:51 +0000
commit4d3038379d98074612a92ef2bc85250cd205cfa9 (patch)
treec5b01b23edb5fb9a0f1ed2310686b5df9fa2dcdb /include/core/SkRect.h
parent411bb7237e5148dc398ae0f3e53ea5f2eb4402de (diff)
add more utilities: roundIn(), offsetTo()
git-svn-id: http://skia.googlecode.com/svn/trunk@6320 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'include/core/SkRect.h')
-rw-r--r--include/core/SkRect.h41
1 files changed, 37 insertions, 4 deletions
diff --git a/include/core/SkRect.h b/include/core/SkRect.h
index 89014b365d..7210bf9cd6 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -142,6 +142,16 @@ struct SK_API SkIRect {
this->offset(delta.fX, delta.fY);
}
+ /**
+ * Offset this rect such its new x() and y() will equal newX and newY.
+ */
+ void offsetTo(int32_t newX, int32_t newY) {
+ fRight += newX - fLeft;
+ fBottom += newY - fTop;
+ fLeft = newX;
+ fTop = newY;
+ }
+
/** Inset the rectangle by (dx,dy). If dx is positive, then the sides are moved inwards,
making the rectangle narrower. If dx is negative, then the sides are moved outwards,
making the rectangle wider. The same holds true for dy and the top and bottom.
@@ -519,6 +529,16 @@ struct SK_API SkRect {
this->offset(delta.fX, delta.fY);
}
+ /**
+ * Offset this rect such its new x() and y() will equal newX and newY.
+ */
+ void offsetTo(SkScalar newX, SkScalar newY) {
+ fRight += newX - fLeft;
+ fBottom += newY - fTop;
+ fLeft = newX;
+ fTop = newY;
+ }
+
/** Inset the rectangle by (dx,dy). If dx is positive, then the sides are
moved inwards, making the rectangle narrower. If dx is negative, then
the sides are moved outwards, making the rectangle wider. The same holds
@@ -656,8 +676,8 @@ struct SK_API SkRect {
*/
void round(SkIRect* dst) const {
SkASSERT(dst);
- dst->set(SkScalarRound(fLeft), SkScalarRound(fTop),
- SkScalarRound(fRight), SkScalarRound(fBottom));
+ dst->set(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop),
+ SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom));
}
/**
@@ -666,8 +686,8 @@ struct SK_API SkRect {
*/
void roundOut(SkIRect* dst) const {
SkASSERT(dst);
- dst->set(SkScalarFloor(fLeft), SkScalarFloor(fTop),
- SkScalarCeil(fRight), SkScalarCeil(fBottom));
+ dst->set(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop),
+ SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom));
}
/**
@@ -683,6 +703,19 @@ struct SK_API SkRect {
}
/**
+ * Set the dst rectangle by rounding "in" this rectangle, choosing the
+ * ceil of top and left, and the floor of right and bottom. This does *not*
+ * call sort(), so it is possible that the resulting rect is inverted...
+ * e.g. left >= right or top >= bottom. Call isEmpty() to detect that.
+ */
+ void roundIn(SkIRect* dst) const {
+ SkASSERT(dst);
+ dst->set(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop),
+ SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom));
+ }
+
+
+ /**
* Swap top/bottom or left/right if there are flipped (i.e. if width()
* or height() would have returned a negative value.) This should be called
* if the edges are computed separately, and may have crossed over each