summaryrefslogtreecommitdiffstats
path: root/libs/hwui/Rect.h
diff options
context:
space:
mode:
Diffstat (limited to 'libs/hwui/Rect.h')
-rw-r--r--libs/hwui/Rect.h44
1 files changed, 31 insertions, 13 deletions
diff --git a/libs/hwui/Rect.h b/libs/hwui/Rect.h
index 5baada3..2ca4f50 100644
--- a/libs/hwui/Rect.h
+++ b/libs/hwui/Rect.h
@@ -29,17 +29,6 @@ namespace uirenderer {
///////////////////////////////////////////////////////////////////////////////
class Rect {
- static inline float min(float a, float b) { return (a<b) ? a : b; }
- static inline float max(float a, float b) { return (a>b) ? a : b; }
- Rect intersectWith(float l, float t, float r, float b) const {
- Rect tmp;
- tmp.left = max(left, l);
- tmp.top = max(top, t);
- tmp.right = min(right, r);
- tmp.bottom = min(bottom, b);
- return tmp;
- }
-
public:
float left;
float top;
@@ -115,7 +104,7 @@ public:
}
bool intersects(float l, float t, float r, float b) const {
- return !intersectWith(l,t,r,b).isEmpty();
+ return !intersectWith(l, t, r, b).isEmpty();
}
bool intersects(const Rect& r) const {
@@ -123,7 +112,8 @@ public:
}
bool intersect(float l, float t, float r, float b) {
- Rect tmp(intersectWith(l,t,r,b));
+ Rect tmp(l, t, r, b);
+ intersectWith(tmp);
if (!tmp.isEmpty()) {
set(tmp);
return true;
@@ -135,6 +125,14 @@ public:
return intersect(r.left, r.top, r.right, r.bottom);
}
+ bool contains(float l, float t, float r, float b) {
+ return l >= left && t >= top && r <= right && b <= bottom;
+ }
+
+ bool contains(const Rect& r) {
+ return contains(r.left, r.top, r.right, r.bottom);
+ }
+
bool unionWith(const Rect& r) {
if (r.left < r.right && r.top < r.bottom) {
if (left < right && top < bottom) {
@@ -172,6 +170,26 @@ public:
ALOGD("Rect[l=%f t=%f r=%f b=%f]", left, top, right, bottom);
}
+private:
+ static inline float min(float a, float b) { return (a < b) ? a : b; }
+ static inline float max(float a, float b) { return (a > b) ? a : b; }
+
+ void intersectWith(Rect& tmp) const {
+ tmp.left = max(left, tmp.left);
+ tmp.top = max(top, tmp.top);
+ tmp.right = min(right, tmp.right);
+ tmp.bottom = min(bottom, tmp.bottom);
+ }
+
+ Rect intersectWith(float l, float t, float r, float b) const {
+ Rect tmp;
+ tmp.left = max(left, l);
+ tmp.top = max(top, t);
+ tmp.right = min(right, r);
+ tmp.bottom = min(bottom, b);
+ return tmp;
+ }
+
}; // class Rect
}; // namespace uirenderer