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 712 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
723 */ | 723 */ |
724 bool contains(const SkRect& r) const { | 724 bool contains(const SkRect& r) const { |
725 // todo: can we eliminate the this->isEmpty check? | 725 // todo: can we eliminate the this->isEmpty check? |
726 return !r.isEmpty() && !this->isEmpty() && | 726 return !r.isEmpty() && !this->isEmpty() && |
727 fLeft <= r.fLeft && fTop <= r.fTop && | 727 fLeft <= r.fLeft && fTop <= r.fTop && |
728 fRight >= r.fRight && fBottom >= r.fBottom; | 728 fRight >= r.fRight && fBottom >= r.fBottom; |
729 } | 729 } |
730 | 730 |
731 /** | 731 /** |
732 * Set the dst rectangle by rounding this rectangle's coordinates to their | 732 * Set the dst rectangle by rounding this rectangle's coordinates to their |
733 * nearest integer values using SkScalarRound. | 733 * nearest integer values using SkScalarRoundToInt. |
734 */ | 734 */ |
735 void round(SkIRect* dst) const { | 735 void round(SkIRect* dst) const { |
736 SkASSERT(dst); | 736 SkASSERT(dst); |
737 dst->set(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), | 737 dst->set(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), |
738 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)); | 738 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)); |
739 } | 739 } |
740 | 740 |
741 /** | 741 /** |
742 * Set the dst rectangle by rounding "out" this rectangle, choosing the | 742 * Set the dst rectangle by rounding "out" this rectangle, choosing the |
743 * SkScalarFloor of top and left, and the SkScalarCeil of right and bottom. | 743 * SkScalarFloor of top and left, and the SkScalarCeil of right and bottom. |
(...skipping 21 matching lines...) Expand all Loading... |
765 * ceil of top and left, and the floor of right and bottom. This does *not* | 765 * ceil of top and left, and the floor of right and bottom. This does *not* |
766 * call sort(), so it is possible that the resulting rect is inverted... | 766 * call sort(), so it is possible that the resulting rect is inverted... |
767 * e.g. left >= right or top >= bottom. Call isEmpty() to detect that. | 767 * e.g. left >= right or top >= bottom. Call isEmpty() to detect that. |
768 */ | 768 */ |
769 void roundIn(SkIRect* dst) const { | 769 void roundIn(SkIRect* dst) const { |
770 SkASSERT(dst); | 770 SkASSERT(dst); |
771 dst->set(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop), | 771 dst->set(SkScalarCeilToInt(fLeft), SkScalarCeilToInt(fTop), |
772 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)); | 772 SkScalarFloorToInt(fRight), SkScalarFloorToInt(fBottom)); |
773 } | 773 } |
774 | 774 |
| 775 /** |
| 776 * Return a new SkIRect which is contains the rounded coordinates of this |
| 777 * rect using SkScalarRoundToInt. |
| 778 */ |
| 779 SkIRect round() const { |
| 780 SkIRect ir; |
| 781 this->round(&ir); |
| 782 return ir; |
| 783 } |
775 | 784 |
776 /** | 785 /** |
777 * Swap top/bottom or left/right if there are flipped (i.e. if width() | 786 * Swap top/bottom or left/right if there are flipped (i.e. if width() |
778 * or height() would have returned a negative value.) This should be called | 787 * or height() would have returned a negative value.) This should be called |
779 * if the edges are computed separately, and may have crossed over each | 788 * if the edges are computed separately, and may have crossed over each |
780 * other. When this returns, left <= right && top <= bottom | 789 * other. When this returns, left <= right && top <= bottom |
781 */ | 790 */ |
782 void sort(); | 791 void sort(); |
783 | 792 |
784 /** | 793 /** |
785 * cast-safe way to treat the rect as an array of (4) SkScalars. | 794 * cast-safe way to treat the rect as an array of (4) SkScalars. |
786 */ | 795 */ |
787 const SkScalar* asScalars() const { return &fLeft; } | 796 const SkScalar* asScalars() const { return &fLeft; } |
788 }; | 797 }; |
789 | 798 |
790 #endif | 799 #endif |
OLD | NEW |