| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
| 5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
| 6 */ | 6 */ |
| 7 | 7 |
| 8 #include "SkRRect.h" | 8 #include "SkRRect.h" |
| 9 | 9 |
| 10 /////////////////////////////////////////////////////////////////////////////// | 10 /////////////////////////////////////////////////////////////////////////////// |
| (...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 109 } | 109 } |
| 110 | 110 |
| 111 // At this point we're either oval, simple, or complex (not empty or rect) | 111 // At this point we're either oval, simple, or complex (not empty or rect) |
| 112 // but we lazily resolve the type to avoid the work if the information | 112 // but we lazily resolve the type to avoid the work if the information |
| 113 // isn't required. | 113 // isn't required. |
| 114 fType = (SkRRect::Type) kUnknown_Type; | 114 fType = (SkRRect::Type) kUnknown_Type; |
| 115 | 115 |
| 116 SkDEBUGCODE(this->validate();) | 116 SkDEBUGCODE(this->validate();) |
| 117 } | 117 } |
| 118 | 118 |
| 119 bool SkRRect::contains(SkScalar x, SkScalar y) const { | |
| 120 SkDEBUGCODE(this->validate();) | |
| 121 | |
| 122 if (kEmpty_Type == this->type()) { | |
| 123 return false; | |
| 124 } | |
| 125 | |
| 126 if (!fRect.contains(x, y)) { | |
| 127 return false; | |
| 128 } | |
| 129 | |
| 130 if (kRect_Type == this->type()) { | |
| 131 // the 'fRect' test above was sufficient | |
| 132 return true; | |
| 133 } | |
| 134 | |
| 135 // We know the point is inside the RR's bounds. The only way it can | |
| 136 // be out is if it outside one of the corners | |
| 137 return checkCornerContainment(x, y); | |
| 138 } | |
| 139 | |
| 140 // This method determines if a point known to be inside the RRect's bounds is | 119 // This method determines if a point known to be inside the RRect's bounds is |
| 141 // inside all the corners. | 120 // inside all the corners. |
| 142 bool SkRRect::checkCornerContainment(SkScalar x, SkScalar y) const { | 121 bool SkRRect::checkCornerContainment(SkScalar x, SkScalar y) const { |
| 143 SkPoint canonicalPt; // (x,y) translated to one of the quadrants | 122 SkPoint canonicalPt; // (x,y) translated to one of the quadrants |
| 144 int index; | 123 int index; |
| 145 | 124 |
| 146 if (kOval_Type == this->type()) { | 125 if (kOval_Type == this->type()) { |
| 147 canonicalPt.set(x - fRect.centerX(), y - fRect.centerY()); | 126 canonicalPt.set(x - fRect.centerX(), y - fRect.centerY()); |
| 148 index = kUpperLeft_Corner; // any corner will do in this case | 127 index = kUpperLeft_Corner; // any corner will do in this case |
| 149 } else { | 128 } else { |
| (...skipping 202 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 352 SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare); | 331 SkASSERT(!allRadiiZero && !allRadiiSame && !allCornersSquare); |
| 353 break; | 332 break; |
| 354 case kUnknown_Type: | 333 case kUnknown_Type: |
| 355 // no limits on this | 334 // no limits on this |
| 356 break; | 335 break; |
| 357 } | 336 } |
| 358 } | 337 } |
| 359 #endif // SK_DEBUG | 338 #endif // SK_DEBUG |
| 360 | 339 |
| 361 /////////////////////////////////////////////////////////////////////////////// | 340 /////////////////////////////////////////////////////////////////////////////// |
| OLD | NEW |