Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(334)

Unified Diff: include/core/SkRect.h

Issue 640723004: cleanup and optimize rect intersect routines (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: cleanup the new bench Created 6 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « gyp/bench.gypi ('k') | src/core/SkRect.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: include/core/SkRect.h
diff --git a/include/core/SkRect.h b/include/core/SkRect.h
index d249aee8d0b7d5c5db9239e08870784961215855..d9ef7a5ecfc2cbc2ee79bbcb717c13c0eac461a2 100644
--- a/include/core/SkRect.h
+++ b/include/core/SkRect.h
@@ -651,7 +651,6 @@ struct SK_API SkRect {
If either rectangle is empty, do nothing and return false.
*/
bool intersect(const SkRect& r);
- bool intersect2(const SkRect& r);
/** If this rectangle intersects the rectangle specified by left, top, right, bottom,
return true and set this rectangle to that intersection, otherwise return false
@@ -661,31 +660,38 @@ struct SK_API SkRect {
bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom);
/**
+ * If rectangles a and b intersect, return true and set this rectangle to
+ * that intersection, otherwise return false and do not change this
+ * rectangle. If either rectangle is empty, do nothing and return false.
+ */
+ bool intersect(const SkRect& a, const SkRect& b);
+
+
+private:
+ static bool Intersects(SkScalar al, SkScalar at, SkScalar ar, SkScalar ab,
+ SkScalar bl, SkScalar bt, SkScalar br, SkScalar bb) {
+ SkScalar L = SkMaxScalar(al, bl);
+ SkScalar R = SkMinScalar(ar, br);
+ SkScalar T = SkMaxScalar(at, bt);
+ SkScalar B = SkMinScalar(ab, bb);
+ return L < R && T < B;
+ }
+
+public:
+ /**
* Return true if this rectangle is not empty, and the specified sides of
* a rectangle are not empty, and they intersect.
*/
bool intersects(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) const {
- return // first check that both are not empty
- left < right && top < bottom &&
- fLeft < fRight && fTop < fBottom &&
- // now check for intersection
- fLeft < right && left < fRight &&
- fTop < bottom && top < fBottom;
+ return Intersects(fLeft, fTop, fRight, fBottom, left, top, right, bottom);
}
- /** If rectangles a and b intersect, return true and set this rectangle to
- * that intersection, otherwise return false and do not change this
- * rectangle. If either rectangle is empty, do nothing and return false.
- */
- bool intersect(const SkRect& a, const SkRect& b);
-
/**
* Return true if rectangles a and b are not empty and intersect.
*/
static bool Intersects(const SkRect& a, const SkRect& b) {
- return !a.isEmpty() && !b.isEmpty() &&
- a.fLeft < b.fRight && b.fLeft < a.fRight &&
- a.fTop < b.fBottom && b.fTop < a.fBottom;
+ return Intersects(a.fLeft, a.fTop, a.fRight, a.fBottom,
+ b.fLeft, b.fTop, b.fRight, b.fBottom);
}
/**
« no previous file with comments | « gyp/bench.gypi ('k') | src/core/SkRect.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698