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 807 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
818 * Set the dst rectangle by rounding this rectangle's coordinates to their | 818 * Set the dst rectangle by rounding this rectangle's coordinates to their |
819 * nearest integer values using SkScalarRoundToInt. | 819 * nearest integer values using SkScalarRoundToInt. |
820 */ | 820 */ |
821 void round(SkIRect* dst) const { | 821 void round(SkIRect* dst) const { |
822 SkASSERT(dst); | 822 SkASSERT(dst); |
823 dst->set(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), | 823 dst->set(SkScalarRoundToInt(fLeft), SkScalarRoundToInt(fTop), |
824 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)); | 824 SkScalarRoundToInt(fRight), SkScalarRoundToInt(fBottom)); |
825 } | 825 } |
826 | 826 |
827 /** | 827 /** |
828 * Variant of round() that explicitly performs the rounding step (i.e. floo
r(x + 0.5)) using | |
829 * double instead of SkScalar (float). It does this by calling SkDScalarRou
ndToInt(), which | |
830 * may be slower than calling SkScalarRountToInt(), but gives slightly more
accurate results. | |
831 * | |
832 * e.g. | |
833 * SkScalar x = 0.49999997f; | |
834 * int ix = SkScalarRoundToInt(x); | |
835 * SkASSERT(0 == ix); // <--- fails | |
836 * ix = SkDScalarRoundToInt(x); | |
837 * SkASSERT(0 == ix); // <--- succeeds | |
838 */ | |
839 void dround(SkIRect* dst) const { | |
840 SkASSERT(dst); | |
841 dst->set(SkDScalarRoundToInt(fLeft), SkDScalarRoundToInt(fTop), | |
842 SkDScalarRoundToInt(fRight), SkDScalarRoundToInt(fBottom)); | |
843 } | |
844 | |
845 /** | |
846 * Set the dst rectangle by rounding "out" this rectangle, choosing the | 828 * Set the dst rectangle by rounding "out" this rectangle, choosing the |
847 * SkScalarFloor of top and left, and the SkScalarCeil of right and bottom. | 829 * SkScalarFloor of top and left, and the SkScalarCeil of right and bottom. |
848 */ | 830 */ |
849 void roundOut(SkIRect* dst) const { | 831 void roundOut(SkIRect* dst) const { |
850 SkASSERT(dst); | 832 SkASSERT(dst); |
851 dst->set(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), | 833 dst->set(SkScalarFloorToInt(fLeft), SkScalarFloorToInt(fTop), |
852 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)); | 834 SkScalarCeilToInt(fRight), SkScalarCeilToInt(fBottom)); |
853 } | 835 } |
854 | 836 |
855 /** | 837 /** |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
917 void dumpHex() const { this->dump(true); } | 899 void dumpHex() const { this->dump(true); } |
918 }; | 900 }; |
919 | 901 |
920 inline bool SkIRect::contains(const SkRect& r) const { | 902 inline bool SkIRect::contains(const SkRect& r) const { |
921 return !r.isEmpty() && !this->isEmpty() && // check for empties | 903 return !r.isEmpty() && !this->isEmpty() && // check for empties |
922 (SkScalar)fLeft <= r.fLeft && (SkScalar)fTop <= r.fTop && | 904 (SkScalar)fLeft <= r.fLeft && (SkScalar)fTop <= r.fTop && |
923 (SkScalar)fRight >= r.fRight && (SkScalar)fBottom >= r.fBottom; | 905 (SkScalar)fRight >= r.fRight && (SkScalar)fBottom >= r.fBottom; |
924 } | 906 } |
925 | 907 |
926 #endif | 908 #endif |
OLD | NEW |