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

Side by Side Diff: include/core/SkRRect.h

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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | src/core/SkRRect.cpp » ('j') | src/core/SkRRect.cpp » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #ifndef SkRRect_DEFINED 8 #ifndef SkRRect_DEFINED
9 #define SkRRect_DEFINED 9 #define SkRRect_DEFINED
10 10
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
193 } 193 }
194 194
195 friend bool operator!=(const SkRRect& a, const SkRRect& b) { 195 friend bool operator!=(const SkRRect& a, const SkRRect& b) {
196 return a.fRect != b.fRect || 196 return a.fRect != b.fRect ||
197 !SkScalarsEqual(a.fRadii[0].asScalars(), 197 !SkScalarsEqual(a.fRadii[0].asScalars(),
198 b.fRadii[0].asScalars(), 8); 198 b.fRadii[0].asScalars(), 8);
199 } 199 }
200 200
201 /** 201 /**
202 * Returns true if (p.fX,p.fY) is inside the RR, and the RR 202 * Returns true if (p.fX,p.fY) is inside the RR, and the RR
203 * is not empty. 203 * is not empty. The 'loose' parameter controls the containment
204 * policly on the right and bottom edges (loose -> "<="; !loose ->
205 * "<"). It should be set to true when the point should be considered
206 * "in" when it lies on a R/B edge (e.g., the right edge of an SkRect).
204 * 207 *
205 * Contains treats the left and top differently from the right and bottom. 208 * Contains treats the left and top differently from the right and bottom.
206 * The left and top coordinates of the RR are themselves considered 209 * The left and top coordinates of the RR are themselves considered
207 * to be inside, while the right and bottom are not. All the points on the 210 * to be inside, while the right and bottom are not. All the points on the
208 * edges of the corners are considered to be inside. 211 * edges of the corners are considered to be inside.
209 */ 212 */
210 bool contains(const SkPoint& p) const { 213 bool contains(const SkPoint& p, bool loose = false) const {
211 return contains(p.fX, p.fY); 214 return contains(p.fX, p.fY, loose);
212 } 215 }
213 216
214 /** 217 /**
215 * Returns true if (x,y) is inside the RR, and the RR 218 * Returns true if (x,y) is inside the RR, and the RR
216 * is not empty. 219 * is not empty. The 'loose' parameter controls the containment
220 * policly on the right and bottom edges (loose -> "<="; !loose ->
221 * "<"). It should be set to true when the point should be considered
222 * "in" when it lies on a R/B edge (e.g., the right edge of an SkRect).
217 * 223 *
218 * Contains treats the left and top differently from the right and bottom. 224 * Contains treats the left and top differently from the right and bottom.
219 * The left and top coordinates of the RR are themselves considered 225 * The left and top coordinates of the RR are themselves considered
220 * to be inside, while the right and bottom are not. All the points on the 226 * to be inside, while the right and bottom are not. All the points on the
221 * edges of the corners are considered to be inside. 227 * edges of the corners are considered to be inside.
222 */ 228 */
223 bool contains(SkScalar x, SkScalar y) const; 229 bool contains(SkScalar x, SkScalar y, bool loose = false) const;
224 230
225 /** 231 /**
226 * Call inset on the bounds, and adjust the radii to reflect what happens 232 * Call inset on the bounds, and adjust the radii to reflect what happens
227 * in stroking: If the corner is sharp (no curvature), leave it alone, 233 * in stroking: If the corner is sharp (no curvature), leave it alone,
228 * otherwise we grow/shrink the radii by the amount of the inset. If a 234 * otherwise we grow/shrink the radii by the amount of the inset. If a
229 * given radius becomes negative, it is pinned to 0. 235 * given radius becomes negative, it is pinned to 0.
230 * 236 *
231 * It is valid for dst == this. 237 * It is valid for dst == this.
232 */ 238 */
233 void inset(SkScalar dx, SkScalar dy, SkRRect* dst) const; 239 void inset(SkScalar dx, SkScalar dy, SkRRect* dst) const;
(...skipping 10 matching lines...) Expand all
244 * 250 *
245 * It is valid for dst == this. 251 * It is valid for dst == this.
246 */ 252 */
247 void outset(SkScalar dx, SkScalar dy, SkRRect* dst) const { 253 void outset(SkScalar dx, SkScalar dy, SkRRect* dst) const {
248 this->inset(-dx, -dy, dst); 254 this->inset(-dx, -dy, dst);
249 } 255 }
250 void outset(SkScalar dx, SkScalar dy) { 256 void outset(SkScalar dx, SkScalar dy) {
251 this->inset(-dx, -dy, this); 257 this->inset(-dx, -dy, this);
252 } 258 }
253 259
260 /**
261 * Returns true if 'rect' is wholy inside the RR, and both
262 * are not empty.
263 *
264 * Contains treats the left and top differently from the right and bottom.
265 * The left and top coordinates of the RR are themselves considered
266 * to be inside, while the right and bottom are not. All the points on the
267 * edges of the corners are considered to be inside.
268 */
269 bool contains(const SkRect& rect) const;
270
254 SkDEBUGCODE(void validate() const;) 271 SkDEBUGCODE(void validate() const;)
255 272
256 enum { 273 enum {
257 kSizeInMemory = 12 * sizeof(SkScalar) 274 kSizeInMemory = 12 * sizeof(SkScalar)
258 }; 275 };
259 276
260 /** 277 /**
261 * Write the rrect into the specified buffer. This is guaranteed to always 278 * Write the rrect into the specified buffer. This is guaranteed to always
262 * write kSizeInMemory bytes, and that value is guaranteed to always be 279 * write kSizeInMemory bytes, and that value is guaranteed to always be
263 * a multiple of 4. Return kSizeInMemory. 280 * a multiple of 4. Return kSizeInMemory.
(...skipping 15 matching lines...) Expand all
279 // TODO: add padding so we can use memcpy for flattening and not copy 296 // TODO: add padding so we can use memcpy for flattening and not copy
280 // uninitialized data 297 // uninitialized data
281 298
282 void computeType() const; 299 void computeType() const;
283 300
284 // to access fRadii directly 301 // to access fRadii directly
285 friend class SkPath; 302 friend class SkPath;
286 }; 303 };
287 304
288 #endif 305 #endif
OLDNEW
« no previous file with comments | « no previous file | src/core/SkRRect.cpp » ('j') | src/core/SkRRect.cpp » ('J')

Powered by Google App Engine
This is Rietveld 408576698