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 SK_WARN_UNUSED_RESULT intersect(const SkIRect& r) { | 270 bool 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 SK_WARN_UNUSED_RESULT intersect(const SkIRect& a, const SkIRect& b) { | 279 bool 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 SK_WARN_UNUSED_RESULT intersectNoEmptyCheck(const SkIRect& a, const SkI
Rect& b) { | 299 bool intersectNoEmptyCheck(const SkIRect& a, const SkIRect& 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 SK_WARN_UNUSED_RESULT intersect(int32_t left, int32_t top, | 318 bool intersect(int32_t left, int32_t top, int32_t right, int32_t bottom) { |
319 int32_t right, int32_t bottom) { | |
320 if (left < right && top < bottom && !this->isEmpty() && | 319 if (left < right && top < bottom && !this->isEmpty() && |
321 fLeft < right && left < fRight && fTop < bottom && top < fBottom
) { | 320 fLeft < right && left < fRight && fTop < bottom && top < fBottom
) { |
322 if (fLeft < left) fLeft = left; | 321 if (fLeft < left) fLeft = left; |
323 if (fTop < top) fTop = top; | 322 if (fTop < top) fTop = top; |
324 if (fRight > right) fRight = right; | 323 if (fRight > right) fRight = right; |
325 if (fBottom > bottom) fBottom = bottom; | 324 if (fBottom > bottom) fBottom = bottom; |
326 return true; | 325 return true; |
327 } | 326 } |
328 return false; | 327 return false; |
329 } | 328 } |
330 | 329 |
331 /** Returns true if a and b are not empty, and they intersect | 330 /** Returns true if a and b are not empty, and they intersect |
332 */ | 331 */ |
333 static bool Intersects(const SkIRect& a, const SkIRect& b) { | 332 static bool Intersects(const SkIRect& a, const SkIRect& b) { |
334 return !a.isEmpty() && !b.isEmpty() && // check for emptie
s | 333 return !a.isEmpty() && !b.isEmpty() && // check for emptie
s |
335 a.fLeft < b.fRight && b.fLeft < a.fRight && | 334 a.fLeft < b.fRight && b.fLeft < a.fRight && |
336 a.fTop < b.fBottom && b.fTop < a.fBottom; | 335 a.fTop < b.fBottom && b.fTop < a.fBottom; |
337 } | 336 } |
338 | 337 |
339 /** | 338 /** |
340 * Returns true if a and b intersect. debug-asserts that neither are empty. | 339 * Returns true if a and b intersect. debug-asserts that neither are empty. |
341 */ | 340 */ |
342 static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b) { | 341 static bool IntersectsNoEmptyCheck(const SkIRect& a, const SkIRect& b) { |
343 SkASSERT(!a.isEmpty()); | 342 SkASSERT(!a.isEmpty()); |
344 SkASSERT(!b.isEmpty()); | 343 SkASSERT(!b.isEmpty()); |
345 return a.fLeft < b.fRight && b.fLeft < a.fRight && | 344 return a.fLeft < b.fRight && b.fLeft < a.fRight && |
346 a.fTop < b.fBottom && b.fTop < a.fBottom; | 345 a.fTop < b.fBottom && b.fTop < a.fBottom; |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
650 moved outwards, making the rectangle wider. If dx is negative, then the | 649 moved outwards, making the rectangle wider. If dx is negative, then the |
651 sides are moved inwards, making the rectangle narrower. The same holds | 650 sides are moved inwards, making the rectangle narrower. The same holds |
652 true for dy and the top and bottom. | 651 true for dy and the top and bottom. |
653 */ | 652 */ |
654 void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy); } | 653 void outset(SkScalar dx, SkScalar dy) { this->inset(-dx, -dy); } |
655 | 654 |
656 /** If this rectangle intersects r, return true and set this rectangle to th
at | 655 /** If this rectangle intersects r, return true and set this rectangle to th
at |
657 intersection, otherwise return false and do not change this rectangle. | 656 intersection, otherwise return false and do not change this rectangle. |
658 If either rectangle is empty, do nothing and return false. | 657 If either rectangle is empty, do nothing and return false. |
659 */ | 658 */ |
660 bool SK_WARN_UNUSED_RESULT intersect(const SkRect& r); | 659 bool intersect(const SkRect& r); |
661 | 660 |
662 /** If this rectangle intersects the rectangle specified by left, top, right
, bottom, | 661 /** If this rectangle intersects the rectangle specified by left, top, right
, bottom, |
663 return true and set this rectangle to that intersection, otherwise retur
n false | 662 return true and set this rectangle to that intersection, otherwise retur
n false |
664 and do not change this rectangle. | 663 and do not change this rectangle. |
665 If either rectangle is empty, do nothing and return false. | 664 If either rectangle is empty, do nothing and return false. |
666 */ | 665 */ |
667 bool SK_WARN_UNUSED_RESULT intersect(SkScalar left, SkScalar top, | 666 bool intersect(SkScalar left, SkScalar top, SkScalar right, SkScalar bottom)
; |
668 SkScalar right, SkScalar bottom); | |
669 | 667 |
670 /** | 668 /** |
671 * If rectangles a and b intersect, return true and set this rectangle to | 669 * If rectangles a and b intersect, return true and set this rectangle to |
672 * that intersection, otherwise return false and do not change this | 670 * that intersection, otherwise return false and do not change this |
673 * rectangle. If either rectangle is empty, do nothing and return false. | 671 * rectangle. If either rectangle is empty, do nothing and return false. |
674 */ | 672 */ |
675 bool SK_WARN_UNUSED_RESULT intersect(const SkRect& a, const SkRect& b); | 673 bool intersect(const SkRect& a, const SkRect& b); |
676 | 674 |
677 | 675 |
678 private: | 676 private: |
679 static bool Intersects(SkScalar al, SkScalar at, SkScalar ar, SkScalar ab, | 677 static bool Intersects(SkScalar al, SkScalar at, SkScalar ar, SkScalar ab, |
680 SkScalar bl, SkScalar bt, SkScalar br, SkScalar bb) { | 678 SkScalar bl, SkScalar bt, SkScalar br, SkScalar bb) { |
681 SkScalar L = SkMaxScalar(al, bl); | 679 SkScalar L = SkMaxScalar(al, bl); |
682 SkScalar R = SkMinScalar(ar, br); | 680 SkScalar R = SkMinScalar(ar, br); |
683 SkScalar T = SkMaxScalar(at, bt); | 681 SkScalar T = SkMaxScalar(at, bt); |
684 SkScalar B = SkMinScalar(ab, bb); | 682 SkScalar B = SkMinScalar(ab, bb); |
685 return L < R && T < B; | 683 return L < R && T < B; |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
874 * cast-safe way to treat the rect as an array of (4) SkScalars. | 872 * cast-safe way to treat the rect as an array of (4) SkScalars. |
875 */ | 873 */ |
876 const SkScalar* asScalars() const { return &fLeft; } | 874 const SkScalar* asScalars() const { return &fLeft; } |
877 | 875 |
878 void dump(bool asHex) const; | 876 void dump(bool asHex) const; |
879 void dump() const { this->dump(false); } | 877 void dump() const { this->dump(false); } |
880 void dumpHex() const { this->dump(true); } | 878 void dumpHex() const { this->dump(true); } |
881 }; | 879 }; |
882 | 880 |
883 #endif | 881 #endif |
OLD | NEW |