OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 SkRect_DEFINED | 8 #ifndef SkRect_DEFINED |
9 #define SkRect_DEFINED | 9 #define SkRect_DEFINED |
10 | 10 |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 } | 260 } |
261 | 261 |
262 bool containsNoEmptyCheck(const SkIRect& r) const { | 262 bool containsNoEmptyCheck(const SkIRect& r) const { |
263 return containsNoEmptyCheck(r.fLeft, r.fTop, r.fRight, r.fBottom); | 263 return containsNoEmptyCheck(r.fLeft, r.fTop, r.fRight, r.fBottom); |
264 } | 264 } |
265 | 265 |
266 /** If r intersects this rectangle, return true and set this rectangle to th
at | 266 /** If r intersects this rectangle, return true and set this rectangle to th
at |
267 intersection, otherwise return false and do not change this rectangle. | 267 intersection, otherwise return false and do not change this rectangle. |
268 If either rectangle is empty, do nothing and return false. | 268 If either rectangle is empty, do nothing and return false. |
269 */ | 269 */ |
270 bool intersect(const SkIRect& r) { | 270 bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& r) { |
271 SkASSERT(&r); | 271 SkASSERT(&r); |
272 return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom); | 272 return this->intersect(r.fLeft, r.fTop, r.fRight, r.fBottom); |
273 } | 273 } |
274 | 274 |
275 /** If rectangles a and b intersect, return true and set this rectangle to | 275 /** If rectangles a and b intersect, return true and set this rectangle to |
276 that intersection, otherwise return false and do not change this | 276 that intersection, otherwise return false and do not change this |
277 rectangle. If either rectangle is empty, do nothing and return false. | 277 rectangle. If either rectangle is empty, do nothing and return false. |
278 */ | 278 */ |
279 bool intersect(const SkIRect& a, const SkIRect& b) { | 279 bool SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b) { |
280 | 280 |
281 if (!a.isEmpty() && !b.isEmpty() && | 281 if (!a.isEmpty() && !b.isEmpty() && |
282 a.fLeft < b.fRight && b.fLeft < a.fRight && | 282 a.fLeft < b.fRight && b.fLeft < a.fRight && |
283 a.fTop < b.fBottom && b.fTop < a.fBottom) { | 283 a.fTop < b.fBottom && b.fTop < a.fBottom) { |
284 fLeft = SkMax32(a.fLeft, b.fLeft); | 284 fLeft = SkMax32(a.fLeft, b.fLeft); |
285 fTop = SkMax32(a.fTop, b.fTop); | 285 fTop = SkMax32(a.fTop, b.fTop); |
286 fRight = SkMin32(a.fRight, b.fRight); | 286 fRight = SkMin32(a.fRight, b.fRight); |
287 fBottom = SkMin32(a.fBottom, b.fBottom); | 287 fBottom = SkMin32(a.fBottom, b.fBottom); |
288 return true; | 288 return true; |
289 } | 289 } |
290 return false; | 290 return false; |
291 } | 291 } |
292 | 292 |
293 /** If rectangles a and b intersect, return true and set this rectangle to | 293 /** If rectangles a and b intersect, return true and set this rectangle to |
294 that intersection, otherwise return false and do not change this | 294 that intersection, otherwise return false and do not change this |
295 rectangle. For speed, no check to see if a or b are empty is performed. | 295 rectangle. For speed, no check to see if a or b are empty is performed. |
296 If either is, then the return result is undefined. In the debug build, | 296 If either is, then the return result is undefined. In the debug build, |
297 we assert that both rectangles are non-empty. | 297 we assert that both rectangles are non-empty. |
298 */ | 298 */ |
299 bool intersectNoEmptyCheck(const SkIRect& a, const SkIRect& b) { | 299 bool SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect& a, const SkI
Rect& b) { |
300 SkASSERT(!a.isEmpty() && !b.isEmpty()); | 300 SkASSERT(!a.isEmpty() && !b.isEmpty()); |
301 | 301 |
302 if (a.fLeft < b.fRight && b.fLeft < a.fRight && | 302 if (a.fLeft < b.fRight && b.fLeft < a.fRight && |
303 a.fTop < b.fBottom && b.fTop < a.fBottom) { | 303 a.fTop < b.fBottom && b.fTop < a.fBottom) { |
304 fLeft = SkMax32(a.fLeft, b.fLeft); | 304 fLeft = SkMax32(a.fLeft, b.fLeft); |
305 fTop = SkMax32(a.fTop, b.fTop); | 305 fTop = SkMax32(a.fTop, b.fTop); |
306 fRight = SkMin32(a.fRight, b.fRight); | 306 fRight = SkMin32(a.fRight, b.fRight); |
307 fBottom = SkMin32(a.fBottom, b.fBottom); | 307 fBottom = SkMin32(a.fBottom, b.fBottom); |
308 return true; | 308 return true; |
309 } | 309 } |
310 return false; | 310 return false; |
311 } | 311 } |
312 | 312 |
313 /** If the rectangle specified by left,top,right,bottom intersects this rect
angle, | 313 /** If the rectangle specified by left,top,right,bottom intersects this rect
angle, |
314 return true and set this rectangle to that intersection, | 314 return true and set this rectangle to that intersection, |
315 otherwise return false and do not change this rectangle. | 315 otherwise return false and do not change this rectangle. |
316 If either rectangle is empty, do nothing and return false. | 316 If either rectangle is empty, do nothing and return false. |
317 */ | 317 */ |
318 bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom) { | 318 bool SK_WARN_UNUSED_RESULT intersect(int32_t left, int32_t top, |
| 319 int32_t right, int32_t bottom) { |
319 if (left < right && top < bottom && !this->isEmpty() && | 320 if (left < right && top < bottom && !this->isEmpty() && |
320 fLeft < right && left < fRight && fTop < bottom && top < fBottom
) { | 321 fLeft < right && left < fRight && fTop < bottom && top < fBottom
) { |
321 if (fLeft < left) fLeft = left; | 322 if (fLeft < left) fLeft = left; |
322 if (fTop < top) fTop = top; | 323 if (fTop < top) fTop = top; |
323 if (fRight > right) fRight = right; | 324 if (fRight > right) fRight = right; |
324 if (fBottom > bottom) fBottom = bottom; | 325 if (fBottom > bottom) fBottom = bottom; |
325 return true; | 326 return true; |
326 } | 327 } |
327 return false; | 328 return false; |
328 } | 329 } |
329 | 330 |
330 /** Returns true if a and b are not empty, and they intersect | 331 /** Returns true if a and b are not empty, and they intersect |
331 */ | 332 */ |
332 static bool Intersects(const SkIRect& a, const SkIRect& b) { | 333 static bool Intersects(const SkIRect& a, const SkIRect& b) { |
333 return !a.isEmpty() && !b.isEmpty() && // check for emptie
s | 334 return !a.isEmpty() && !b.isEmpty() && // check for emptie
s |
334 a.fLeft < b.fRight && b.fLeft < a.fRight && | 335 a.fLeft < b.fRight && b.fLeft < a.fRight && |
335 a.fTop < b.fBottom && b.fTop < a.fBottom; | 336 a.fTop < b.fBottom && b.fTop < a.fBottom; |
336 } | 337 } |
337 | 338 |
338 /** | 339 /** |
339 * Returns true if a and b intersect. debug-asserts that neither are empty. | 340 * Returns true if a and b intersect. debug-asserts that neither are empty. |
340 */ | 341 */ |
341 static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b) { | 342 static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b) { |
342 SkASSERT(!a.isEmpty()); | 343 SkASSERT(!a.isEmpty()); |
343 SkASSERT(!b.isEmpty()); | 344 SkASSERT(!b.isEmpty()); |
344 return a.fLeft < b.fRight && b.fLeft < a.fRight && | 345 return a.fLeft < b.fRight && b.fLeft < a.fRight && |
345 a.fTop < b.fBottom && b.fTop < a.fBottom; | 346 a.fTop < b.fBottom && b.fTop < a.fBottom; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
649 moved outwards, making the rectangle wider. If dx is negative, then the | 650 moved outwards, making the rectangle wider. If dx is negative, then the |
650 sides are moved inwards, making the rectangle narrower. The same holds | 651 sides are moved inwards, making the rectangle narrower. The same holds |
651 true for dy and the top and bottom. | 652 true for dy and the top and bottom. |
652 */ | 653 */ |
653 void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy); } | 654 void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy); } |
654 | 655 |
655 /** If this rectangle intersects r, return true and set this rectangle to th
at | 656 /** If this rectangle intersects r, return true and set this rectangle to th
at |
656 intersection, otherwise return false and do not change this rectangle. | 657 intersection, otherwise return false and do not change this rectangle. |
657 If either rectangle is empty, do nothing and return false. | 658 If either rectangle is empty, do nothing and return false. |
658 */ | 659 */ |
659 bool intersect(const SkRect& r); | 660 bool SK_WARN_UNUSED_RESULT intersect(const SkRect& r); |
660 | 661 |
661 /** If this rectangle intersects the rectangle specified by left, top, right
, bottom, | 662 /** If this rectangle intersects the rectangle specified by left, top, right
, bottom, |
662 return true and set this rectangle to that intersection, otherwise retur
n false | 663 return true and set this rectangle to that intersection, otherwise retur
n false |
663 and do not change this rectangle. | 664 and do not change this rectangle. |
664 If either rectangle is empty, do nothing and return false. | 665 If either rectangle is empty, do nothing and return false. |
665 */ | 666 */ |
666 bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
; | 667 bool SK_WARN_UNUSED_RESULT intersect(SkScalar left, SkScalar top, |
| 668 SkScalar right, SkScalar bottom); |
667 | 669 |
668 /** | 670 /** |
669 * If rectangles a and b intersect, return true and set this rectangle to | 671 * If rectangles a and b intersect, return true and set this rectangle to |
670 * that intersection, otherwise return false and do not change this | 672 * that intersection, otherwise return false and do not change this |
671 * rectangle. If either rectangle is empty, do nothing and return false. | 673 * rectangle. If either rectangle is empty, do nothing and return false. |
672 */ | 674 */ |
673 bool intersect(const SkRect& a, const SkRect& b); | 675 bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b); |
674 | 676 |
675 | 677 |
676 private: | 678 private: |
677 static bool Intersects(SkScalar al, SkScalar at, SkScalar ar, SkScalar ab, | 679 static bool Intersects(SkScalar al, SkScalar at, SkScalar ar, SkScalar ab, |
678 SkScalar bl, SkScalar bt, SkScalar br, SkScalar bb) { | 680 SkScalar bl, SkScalar bt, SkScalar br, SkScalar bb) { |
679 SkScalar L = SkMaxScalar(al, bl); | 681 SkScalar L = SkMaxScalar(al, bl); |
680 SkScalar R = SkMinScalar(ar, br); | 682 SkScalar R = SkMinScalar(ar, br); |
681 SkScalar T = SkMaxScalar(at, bt); | 683 SkScalar T = SkMaxScalar(at, bt); |
682 SkScalar B = SkMinScalar(ab, bb); | 684 SkScalar B = SkMinScalar(ab, bb); |
683 return L < R && T < B; | 685 return L < R && T < B; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 * cast-safe way to treat the rect as an array of (4) SkScalars. | 874 * cast-safe way to treat the rect as an array of (4) SkScalars. |
873 */ | 875 */ |
874 const SkScalar* asScalars() const { return &fLeft; } | 876 const SkScalar* asScalars() const { return &fLeft; } |
875 | 877 |
876 void dump(bool asHex) const; | 878 void dump(bool asHex) const; |
877 void dump() const { this->dump(false); } | 879 void dump() const { this->dump(false); } |
878 void dumpHex() const { this->dump(true); } | 880 void dumpHex() const { this->dump(true); } |
879 }; | 881 }; |
880 | 882 |
881 #endif | 883 #endif |
OLD | NEW |