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

Unified Diff: src/core/SkRect.cpp

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 | « include/core/SkRect.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/core/SkRect.cpp
diff --git a/src/core/SkRect.cpp b/src/core/SkRect.cpp
index 12f76526a5d0fc0dc52e00430869156befc6f2bd..7340098d2fb479df095a32c83354a20f02909648 100644
--- a/src/core/SkRect.cpp
+++ b/src/core/SkRect.cpp
@@ -99,51 +99,27 @@ bool SkRect::setBoundsCheck(const SkPoint pts[], int count) {
return isFinite;
}
-bool SkRect::intersect(SkScalar left, SkScalar top, SkScalar right,
- SkScalar bottom) {
- if (left < right && top < bottom && !this->isEmpty() && // check for empties
- fLeft < right && left < fRight && fTop < bottom && top < fBottom)
- {
- if (fLeft < left) fLeft = left;
- if (fTop < top) fTop = top;
- if (fRight > right) fRight = right;
- if (fBottom > bottom) fBottom = bottom;
- return true;
- }
- return false;
+#define CHECK_INTERSECT(al, at, ar, ab, bl, bt, br, bb) \
+ SkScalar L = SkMaxScalar(al, bl); \
+ SkScalar R = SkMinScalar(ar, br); \
+ SkScalar T = SkMaxScalar(at, bt); \
+ SkScalar B = SkMinScalar(ab, bb); \
+ do { if (L >= R || T >= B) return false; } while (0)
+
+bool SkRect::intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
+ CHECK_INTERSECT(left, top, right, bottom, fLeft, fTop, fRight, fBottom);
+ this->setLTRB(L, T, R, B);
+ return true;
}
bool SkRect::intersect(const SkRect& r) {
return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom);
}
-bool SkRect::intersect2(const SkRect& r) {
- SkScalar L = SkMaxScalar(fLeft, r.fLeft);
- SkScalar R = SkMinScalar(fRight, r.fRight);
- if (L >= R) {
- return false;
- }
- SkScalar T = SkMaxScalar(fTop, r.fTop);
- SkScalar B = SkMinScalar(fBottom, r.fBottom);
- if (T >= B) {
- return false;
- }
- this->set(L, T, R, B);
- return true;
-}
-
bool SkRect::intersect(const SkRect& a, const SkRect& b) {
-
- if (!a.isEmpty() && !b.isEmpty() &&
- a.fLeft < b.fRight && b.fLeft < a.fRight &&
- a.fTop < b.fBottom && b.fTop < a.fBottom) {
- fLeft = SkMaxScalar(a.fLeft, b.fLeft);
- fTop = SkMaxScalar(a.fTop, b.fTop);
- fRight = SkMinScalar(a.fRight, b.fRight);
- fBottom = SkMinScalar(a.fBottom, b.fBottom);
- return true;
- }
- return false;
+ CHECK_INTERSECT(a.fLeft, a.fTop, a.fRight, a.fBottom, b.fLeft, b.fTop, b.fRight, b.fBottom);
+ this->setLTRB(L, T, R, B);
+ return true;
}
void SkRect::join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom) {
@@ -162,3 +138,4 @@ void SkRect::join(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
fBottom = SkMaxScalar(fBottom, bottom);
}
}
+
« no previous file with comments | « include/core/SkRect.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698