aboutsummaryrefslogtreecommitdiff
path: root/common/rect.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/rect.h')
-rw-r--r--common/rect.h20
1 files changed, 17 insertions, 3 deletions
diff --git a/common/rect.h b/common/rect.h
index 768d1ebbb9..8d1243f7e4 100644
--- a/common/rect.h
+++ b/common/rect.h
@@ -170,6 +170,20 @@ struct Rect {
}
/**
+ * Find the intersecting rectangle between this rectangle and the given rectangle
+ *
+ * @param r the intersecting rectangle
+ *
+ * @return the intersection of the rectangles or an empty rectangle if not intersecting
+ */
+ Rect findIntersectingRect(const Rect &r) const {
+ if (!intersects(r))
+ return Rect();
+
+ return Rect(MAX(r.left, left), MAX(r.top, top), MIN(r.right, right), MIN(r.bottom, bottom));
+ }
+
+ /**
* Extend this rectangle so that it contains r
*
* @param r the rectangle to extend by
@@ -244,11 +258,11 @@ struct Rect {
/**
* Create a rectangle around the given center.
+ * @note the center point is rounded up and left when given an odd width and height
*/
static Rect center(int16 cx, int16 cy, int16 w, int16 h) {
- w /= 2;
- h /= 2;
- return Rect(cx - w, cy - h, cx + w, cy + h);
+ int x = cx - w / 2, y = cy - h / 2;
+ return Rect(x, y, x + w, y + h);
}
};