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); |
} |
} |
+ |