Chromium Code Reviews| 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 | |
| 105 bool isValid() const { | |
|
reed1
2013/09/04 18:49:36
Is this the same as
return this->width() >= 0 &&
reed1
2013/09/04 18:49:36
Suggest we move this into SkValidatingUtils.h
sugoi1
2013/09/04 20:14:52
Done.
sugoi1
2013/09/04 20:14:52
Hmmm... I'm not sure. In the case of width(), for
| |
| 106 return !isInverted() && | |
| 107 // Make sure width() and height() are also valid | |
| 108 ((fLeft >= 0) || (fRight <= 0) || ((fRight - SK_MaxS32) <= fLeft) ) && | |
| 109 ((fTop >= 0) || (fBottom <= 0) || ((fBottom - SK_MaxS32) <= fTop) ); | |
| 110 } | |
| 111 | |
| 103 bool isLargest() const { return SK_MinS32 == fLeft && | 112 bool isLargest() const { return SK_MinS32 == fLeft && |
| 104 SK_MinS32 == fTop && | 113 SK_MinS32 == fTop && |
| 105 SK_MaxS32 == fRight && | 114 SK_MaxS32 == fRight && |
| 106 SK_MaxS32 == fBottom; } | 115 SK_MaxS32 == fBottom; } |
| 107 | 116 |
| 108 friend bool operator==(const SkIRect& a, const SkIRect& b) { | 117 friend bool operator==(const SkIRect& a, const SkIRect& b) { |
| 109 return !memcmp(&a, &b, sizeof(a)); | 118 return !memcmp(&a, &b, sizeof(a)); |
| 110 } | 119 } |
| 111 | 120 |
| 112 friend bool operator!=(const SkIRect& a, const SkIRect& b) { | 121 friend bool operator!=(const SkIRect& a, const SkIRect& b) { |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 412 SkIntToScalar(irect.fRight), | 421 SkIntToScalar(irect.fRight), |
| 413 SkIntToScalar(irect.fBottom)); | 422 SkIntToScalar(irect.fBottom)); |
| 414 return r; | 423 return r; |
| 415 } | 424 } |
| 416 | 425 |
| 417 /** | 426 /** |
| 418 * Return true if the rectangle's width or height are <= 0 | 427 * Return true if the rectangle's width or height are <= 0 |
| 419 */ | 428 */ |
| 420 bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; } | 429 bool isEmpty() const { return fLeft >= fRight || fTop >= fBottom; } |
| 421 | 430 |
| 431 bool isInverted() const { return fLeft > fRight || fTop > fBottom; } | |
| 432 | |
| 433 bool isValid() const { | |
|
reed1
2013/09/04 18:49:36
Given the size an somewhat arbitrary nature of "va
sugoi1
2013/09/04 20:14:52
Done.
| |
| 434 return SkScalarIsFinite(fLeft) && | |
| 435 SkScalarIsFinite(fTop) && | |
| 436 SkScalarIsFinite(fRight) && | |
| 437 SkScalarIsFinite(fBottom) && | |
| 438 !isInverted() && | |
| 439 // Make sure width() and height() are also valid | |
| 440 ((fLeft >= 0) || (fRight <= 0) || ((fRight - SK_ScalarMax) <= fLe ft)) && | |
| 441 ((fTop >= 0) || (fBottom <= 0) || ((fBottom - SK_ScalarMax) <= fT op)); } | |
| 422 /** | 442 /** |
| 423 * Returns true iff all values in the rect are finite. If any are | 443 * Returns true iff all values in the rect are finite. If any are |
| 424 * infinite or NaN (or SK_FixedNaN when SkScalar is fixed) then this | 444 * infinite or NaN (or SK_FixedNaN when SkScalar is fixed) then this |
| 425 * returns false. | 445 * returns false. |
| 426 */ | 446 */ |
| 427 bool isFinite() const { | 447 bool isFinite() const { |
| 428 #ifdef SK_SCALAR_IS_FLOAT | 448 #ifdef SK_SCALAR_IS_FLOAT |
| 429 float accum = 0; | 449 float accum = 0; |
| 430 accum *= fLeft; | 450 accum *= fLeft; |
| 431 accum *= fTop; | 451 accum *= fTop; |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 797 */ | 817 */ |
| 798 void sort(); | 818 void sort(); |
| 799 | 819 |
| 800 /** | 820 /** |
| 801 * cast-safe way to treat the rect as an array of (4) SkScalars. | 821 * cast-safe way to treat the rect as an array of (4) SkScalars. |
| 802 */ | 822 */ |
| 803 const SkScalar* asScalars() const { return &fLeft; } | 823 const SkScalar* asScalars() const { return &fLeft; } |
| 804 }; | 824 }; |
| 805 | 825 |
| 806 #endif | 826 #endif |
| OLD | NEW |