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 |
11 #include "SkPoint.h" | 11 #include "SkPoint.h" |
12 #include "SkSize.h" | 12 #include "SkSize.h" |
13 #include "../private/SkNx.h" | |
14 | 13 |
15 struct SkRect; | 14 struct SkRect; |
16 | 15 |
17 /** \struct SkIRect | 16 /** \struct SkIRect |
18 | 17 |
19 SkIRect holds four 32 bit integer coordinates for a rectangle | 18 SkIRect holds four 32 bit integer coordinates for a rectangle |
20 */ | 19 */ |
21 struct SK_API SkIRect { | 20 struct SK_API SkIRect { |
22 int32_t fLeft, fTop, fRight, fBottom; | 21 int32_t fLeft, fTop, fRight, fBottom; |
23 | 22 |
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
863 this->round(&ir); | 862 this->round(&ir); |
864 return ir; | 863 return ir; |
865 } | 864 } |
866 | 865 |
867 //! Returns the result of calling roundOut(&dst) | 866 //! Returns the result of calling roundOut(&dst) |
868 SkIRect roundOut() const { | 867 SkIRect roundOut() const { |
869 SkIRect ir; | 868 SkIRect ir; |
870 this->roundOut(&ir); | 869 this->roundOut(&ir); |
871 return ir; | 870 return ir; |
872 } | 871 } |
873 | 872 |
874 /** | |
875 * Round the rect's values and return the result as a new SkIRect. | |
876 * This follows the same semantics as SkScalarRoundToInt(). | |
877 */ | |
878 SkIRect round2i() const { | |
879 SkIRect dst; | |
880 Sk4s rd = (Sk4s::Load(&fLeft) + Sk4s(0.5)).floor(); | |
881 SkNx_cast<int32_t>(rd).store(&dst.fLeft); | |
882 return dst; | |
883 } | |
884 | |
885 /** | |
886 * Round the rect's values and return the result as a new SkRect. | |
887 * This follows the same semantics as SkScalarRoundToScalar(). | |
888 */ | |
889 SkRect round2s() const { | |
890 SkRect dst; | |
891 (Sk4s::Load(&fLeft) + Sk4s(0.5)).floor().store(&dst.fLeft); | |
892 return dst; | |
893 } | |
894 | |
895 /** | 873 /** |
896 * Swap top/bottom or left/right if there are flipped (i.e. if width() | 874 * Swap top/bottom or left/right if there are flipped (i.e. if width() |
897 * or height() would have returned a negative value.) This should be called | 875 * or height() would have returned a negative value.) This should be called |
898 * if the edges are computed separately, and may have crossed over each | 876 * if the edges are computed separately, and may have crossed over each |
899 * other. When this returns, left <= right && top <= bottom | 877 * other. When this returns, left <= right && top <= bottom |
900 */ | 878 */ |
901 void sort() { | 879 void sort() { |
902 if (fLeft > fRight) { | 880 if (fLeft > fRight) { |
903 SkTSwap<SkScalar>(fLeft, fRight); | 881 SkTSwap<SkScalar>(fLeft, fRight); |
904 } | 882 } |
(...skipping 13 matching lines...) Expand all Loading... |
918 void dumpHex() const { this->dump(true); } | 896 void dumpHex() const { this->dump(true); } |
919 }; | 897 }; |
920 | 898 |
921 inline bool SkIRect::contains(const SkRect& r) const { | 899 inline bool SkIRect::contains(const SkRect& r) const { |
922 return !r.isEmpty() && !this->isEmpty() && // check for empties | 900 return !r.isEmpty() && !this->isEmpty() && // check for empties |
923 (SkScalar)fLeft <= r.fLeft && (SkScalar)fTop <= r.fTop && | 901 (SkScalar)fLeft <= r.fLeft && (SkScalar)fTop <= r.fTop && |
924 (SkScalar)fRight >= r.fRight && (SkScalar)fBottom >= r.fBottom; | 902 (SkScalar)fRight >= r.fRight && (SkScalar)fBottom >= r.fBottom; |
925 } | 903 } |
926 | 904 |
927 #endif | 905 #endif |
OLD | NEW |