Chromium Code Reviews| Index: src/core/SkRRect.cpp |
| =================================================================== |
| --- src/core/SkRRect.cpp (revision 8834) |
| +++ src/core/SkRRect.cpp (working copy) |
| @@ -116,15 +116,34 @@ |
| SkDEBUGCODE(this->validate();) |
| } |
| -bool SkRRect::contains(SkScalar x, SkScalar y) const { |
| +namespace { |
| + |
| +bool loose_contains(const SkRect& rect, SkScalar x, SkScalar y) { |
| + return !rect.isEmpty() && |
| + rect.fLeft <= x && x <= rect.fRight && |
| + rect.fTop <= y && y <= rect.fBottom; |
| +} |
| + |
| +}; |
| + |
| +bool SkRRect::contains(SkScalar x, SkScalar y, bool loose) const { |
| SkDEBUGCODE(this->validate();) |
| if (kEmpty_Type == this->type()) { |
| return false; |
| } |
| - if (!fRect.contains(x, y)) { |
| - return false; |
| + if (loose) { |
| + // points on the left and right edges of a rect have a slightly |
| + // different containment definition (since they technically aren't |
| + // "in" the rect) |
| + if (!loose_contains(fRect, x, y)) { |
| + return false; |
| + } |
| + } else { |
| + if (!fRect.contains(x, y)) { |
| + return false; |
| + } |
| } |
| if (kRect_Type == this->type()) { |
| @@ -184,6 +203,24 @@ |
| return dist <= SK_Scalar1; |
| } |
| +bool SkRRect::contains(const SkRect& rect) const { |
| + if (!this->getBounds().contains(rect)) { |
| + // If 'rect' isn't contained by the RR's bounds then the |
| + // RR definitely doesn't contain it |
| + return false; |
| + } |
| + |
| + if (this->isRect()) { |
| + // the prior test was sufficient |
| + return true; |
| + } |
| + |
|
jvanverth1
2013/04/24 15:29:30
You're checking to see if the corners are in the b
robertphillips
2013/04/24 16:11:57
Done.
|
| + return this->contains(rect.fLeft, rect.fTop, false) && |
| + this->contains(rect.fRight, rect.fTop, true) && |
| + this->contains(rect.fRight, rect.fBottom, true) && |
| + this->contains(rect.fLeft, rect.fBottom, true); |
| +} |
| + |
| // There is a simplified version of this method in setRectXY |
| void SkRRect::computeType() const { |
| SkDEBUGCODE(this->validate();) |