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 729 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
740 void join(const SkRect& r) { | 740 void join(const SkRect& r) { |
741 this->join(r.fLeft, r.fTop, r.fRight, r.fBottom); | 741 this->join(r.fLeft, r.fTop, r.fRight, r.fBottom); |
742 } | 742 } |
743 | 743 |
744 void joinNonEmptyArg(const SkRect& r) { | 744 void joinNonEmptyArg(const SkRect& r) { |
745 SkASSERT(!r.isEmpty()); | 745 SkASSERT(!r.isEmpty()); |
746 // if we are empty, just assign | 746 // if we are empty, just assign |
747 if (fLeft >= fRight || fTop >= fBottom) { | 747 if (fLeft >= fRight || fTop >= fBottom) { |
748 *this = r; | 748 *this = r; |
749 } else { | 749 } else { |
750 fLeft = SkMinScalar(fLeft, r.left()); | 750 this->joinPossiblyEmptyRect(r); |
751 fTop = SkMinScalar(fTop, r.top()); | |
752 fRight = SkMaxScalar(fRight, r.right()); | |
753 fBottom = SkMaxScalar(fBottom, r.bottom()); | |
754 } | 751 } |
755 } | 752 } |
756 | 753 |
757 /** | 754 /** |
| 755 * Joins the rectangle with another without checking if either are empty (ma
y produce unexpected |
| 756 * results if either rect is inverted). |
| 757 */ |
| 758 void joinPossiblyEmptyRect(const SkRect& r) { |
| 759 fLeft = SkMinScalar(fLeft, r.left()); |
| 760 fTop = SkMinScalar(fTop, r.top()); |
| 761 fRight = SkMaxScalar(fRight, r.right()); |
| 762 fBottom = SkMaxScalar(fBottom, r.bottom()); |
| 763 } |
| 764 |
| 765 /** |
758 * Grow the rect to include the specified (x,y). After this call, the | 766 * Grow the rect to include the specified (x,y). After this call, the |
759 * following will be true: fLeft <= x <= fRight && fTop <= y <= fBottom. | 767 * following will be true: fLeft <= x <= fRight && fTop <= y <= fBottom. |
760 * | 768 * |
761 * This is close, but not quite the same contract as contains(), since | 769 * This is close, but not quite the same contract as contains(), since |
762 * contains() treats the left and top different from the right and bottom. | 770 * contains() treats the left and top different from the right and bottom. |
763 * contains(x,y) -> fLeft <= x < fRight && fTop <= y < fBottom. Also note | 771 * contains(x,y) -> fLeft <= x < fRight && fTop <= y < fBottom. Also note |
764 * that contains(x,y) always returns false if the rect is empty. | 772 * that contains(x,y) always returns false if the rect is empty. |
765 */ | 773 */ |
766 void growToInclude(SkScalar x, SkScalar y) { | 774 void growToInclude(SkScalar x, SkScalar y) { |
767 fLeft = SkMinScalar(x, fLeft); | 775 fLeft = SkMinScalar(x, fLeft); |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 void dumpHex() const { this->dump(true); } | 917 void dumpHex() const { this->dump(true); } |
910 }; | 918 }; |
911 | 919 |
912 inline bool SkIRect::contains(const SkRect& r) const { | 920 inline bool SkIRect::contains(const SkRect& r) const { |
913 return !r.isEmpty() && !this->isEmpty() && // check for empties | 921 return !r.isEmpty() && !this->isEmpty() && // check for empties |
914 (SkScalar)fLeft <= r.fLeft && (SkScalar)fTop <= r.fTop && | 922 (SkScalar)fLeft <= r.fLeft && (SkScalar)fTop <= r.fTop && |
915 (SkScalar)fRight >= r.fRight && (SkScalar)fBottom >= r.fBottom; | 923 (SkScalar)fRight >= r.fRight && (SkScalar)fBottom >= r.fBottom; |
916 } | 924 } |
917 | 925 |
918 #endif | 926 #endif |
OLD | NEW |