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

Unified Diff: src/core/SkRRect.cpp

Issue 14200044: RoundRect contains (Closed) Base URL: http://skia.googlecode.com/svn/trunk/
Patch Set: Fixed test Created 7 years, 8 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
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();)
« no previous file with comments | « include/core/SkRRect.h ('k') | tests/RoundRectTest.cpp » ('j') | tests/RoundRectTest.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698