OLD | NEW |
1 | 1 |
2 /* | 2 /* |
3 * Copyright 2006 The Android Open Source Project | 3 * Copyright 2006 The Android Open Source Project |
4 * | 4 * |
5 * Use of this source code is governed by a BSD-style license that can be | 5 * Use of this source code is governed by a BSD-style license that can be |
6 * found in the LICENSE file. | 6 * found in the LICENSE file. |
7 */ | 7 */ |
8 | 8 |
9 | 9 |
10 #ifndef SkRect_DEFINED | 10 #ifndef SkRect_DEFINED |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 * This is a specific "truncation" of the average, which is different than | 93 * This is a specific "truncation" of the average, which is different than |
94 * (bottom + top) / 2 when the sum is negative. | 94 * (bottom + top) / 2 when the sum is negative. |
95 */ | 95 */ |
96 int centerY() const { return (fBottom + fTop) >> 1; } | 96 int centerY() const { return (fBottom + fTop) >> 1; } |
97 | 97 |
98 /** | 98 /** |
99 * Return true if the rectangle's width or height are <= 0 | 99 * Return true if the rectangle's width or height are <= 0 |
100 */ | 100 */ |
101 bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; } | 101 bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; } |
102 | 102 |
| 103 bool isInverted() const { return fLeft > fRight || fTop > fBottom; } |
| 104 |
103 bool isLargest() const { return SK_MinS32 == fLeft && | 105 bool isLargest() const { return SK_MinS32 == fLeft && |
104 SK_MinS32 == fTop && | 106 SK_MinS32 == fTop && |
105 SK_MaxS32 == fRight && | 107 SK_MaxS32 == fRight && |
106 SK_MaxS32 == fBottom; } | 108 SK_MaxS32 == fBottom; } |
107 | 109 |
108 friend bool operator==(const SkIRect& a, const SkIRect& b) { | 110 friend bool operator==(const SkIRect& a, const SkIRect& b) { |
109 return !memcmp(&a, &b, sizeof(a)); | 111 return !memcmp(&a, &b, sizeof(a)); |
110 } | 112 } |
111 | 113 |
112 friend bool operator!=(const SkIRect& a, const SkIRect& b) { | 114 friend bool operator!=(const SkIRect& a, const SkIRect& b) { |
(...skipping 305 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 SkIntToScalar(irect.fRight), | 420 SkIntToScalar(irect.fRight), |
419 SkIntToScalar(irect.fBottom)); | 421 SkIntToScalar(irect.fBottom)); |
420 return r; | 422 return r; |
421 } | 423 } |
422 | 424 |
423 /** | 425 /** |
424 * Return true if the rectangle's width or height are <= 0 | 426 * Return true if the rectangle's width or height are <= 0 |
425 */ | 427 */ |
426 bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; } | 428 bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; } |
427 | 429 |
| 430 bool isInverted() const { return fLeft > fRight || fTop > fBottom; } |
| 431 |
428 bool isLargest() const { return SK_ScalarMin == fLeft && | 432 bool isLargest() const { return SK_ScalarMin == fLeft && |
429 SK_ScalarMin == fTop && | 433 SK_ScalarMin == fTop && |
430 SK_ScalarMax == fRight && | 434 SK_ScalarMax == fRight && |
431 SK_ScalarMax == fBottom; } | 435 SK_ScalarMax == fBottom; } |
432 | 436 |
| 437 bool isValid() const { return SkScalarIsFinite(fLeft) && |
| 438 SkScalarIsFinite(fTop) && |
| 439 SkScalarIsFinite(fRight) && |
| 440 SkScalarIsFinite(fBottom) && |
| 441 (fLeft <= fRight) && |
| 442 (fTop <= fBottom); } |
433 /** | 443 /** |
434 * Returns true iff all values in the rect are finite. If any are | 444 * Returns true iff all values in the rect are finite. If any are |
435 * infinite or NaN (or SK_FixedNaN when SkScalar is fixed) then this | 445 * infinite or NaN (or SK_FixedNaN when SkScalar is fixed) then this |
436 * returns false. | 446 * returns false. |
437 */ | 447 */ |
438 bool isFinite() const { | 448 bool isFinite() const { |
439 #ifdef SK_SCALAR_IS_FLOAT | 449 #ifdef SK_SCALAR_IS_FLOAT |
440 float accum = 0; | 450 float accum = 0; |
441 accum *= fLeft; | 451 accum *= fLeft; |
442 accum *= fTop; | 452 accum *= fTop; |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 */ | 818 */ |
809 void sort(); | 819 void sort(); |
810 | 820 |
811 /** | 821 /** |
812 * cast-safe way to treat the rect as an array of (4) SkScalars. | 822 * cast-safe way to treat the rect as an array of (4) SkScalars. |
813 */ | 823 */ |
814 const SkScalar* asScalars() const { return &fLeft; } | 824 const SkScalar* asScalars() const { return &fLeft; } |
815 }; | 825 }; |
816 | 826 |
817 #endif | 827 #endif |
OLD | NEW |