OLD | NEW |
---|---|
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
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 #include "SkMatrix44.h" | 8 #include "SkMatrix44.h" |
9 | 9 |
10 namespace { | |
11 | |
12 // Taken from Chromium's gfx::Transform | |
danakj
2014/09/19 16:29:47
Haha, hilarious since it says "Taken from SkMatrix
Ian Vollick
2014/09/19 16:32:06
Yeah, it was taken from here, but has since been r
| |
13 const SkMScalar kEpsilon = 1e-8f; | |
reed1
2014/09/19 16:45:14
Can we actually document here the meaning/reason f
tomhudson
2014/09/19 18:21:19
If you go back a few years I think the comment in
| |
14 | |
15 } | |
16 | |
10 static inline bool eq4(const SkMScalar* SK_RESTRICT a, | 17 static inline bool eq4(const SkMScalar* SK_RESTRICT a, |
11 const SkMScalar* SK_RESTRICT b) { | 18 const SkMScalar* SK_RESTRICT b) { |
12 return (a[0] == b[0]) & (a[1] == b[1]) & (a[2] == b[2]) & (a[3] == b[3]); | 19 return (a[0] == b[0]) & (a[1] == b[1]) & (a[2] == b[2]) & (a[3] == b[3]); |
13 } | 20 } |
14 | 21 |
15 bool SkMatrix44::operator==(const SkMatrix44& other) const { | 22 bool SkMatrix44::operator==(const SkMatrix44& other) const { |
16 if (this == &other) { | 23 if (this == &other) { |
17 return true; | 24 return true; |
18 } | 25 } |
19 | 26 |
(...skipping 830 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
850 void SkMatrix44::map2(const double src2[], int count, double dst4[]) const { | 857 void SkMatrix44::map2(const double src2[], int count, double dst4[]) const { |
851 static const Map2Procd gProc[] = { | 858 static const Map2Procd gProc[] = { |
852 map2_id, map2_td, map2_sd, map2_sd, map2_ad, map2_ad, map2_ad, map2_ad | 859 map2_id, map2_td, map2_sd, map2_sd, map2_ad, map2_ad, map2_ad, map2_ad |
853 }; | 860 }; |
854 | 861 |
855 TypeMask mask = this->getType(); | 862 TypeMask mask = this->getType(); |
856 Map2Procd proc = (mask & kPerspective_Mask) ? map2_pd : gProc[mask]; | 863 Map2Procd proc = (mask & kPerspective_Mask) ? map2_pd : gProc[mask]; |
857 proc(fMat, src2, count, dst4); | 864 proc(fMat, src2, count, dst4); |
858 } | 865 } |
859 | 866 |
867 bool SkMatrix44::preserves2dAxisAlignment () const { | |
reed1
2014/09/19 16:45:14
Did you consider taking an explicit epsilon (perha
tomhudson
2014/09/19 18:21:19
Done.
| |
868 | |
869 // Can't check (mask & kPerspective_Mask) because Z isn't relevant here. | |
870 if (0 != perspX() || 0 != perspY()) return false; | |
871 | |
872 int col0 = 0; | |
873 int col1 = 0; | |
874 int row0 = 0; | |
875 int row1 = 0; | |
876 | |
877 // Must test against kEpsilon, not 0, because we can get values | |
878 // around 6e-17 in the matrix that "should" be 0. | |
879 | |
880 if (sk_float_abs(fMat[0][0]) > kEpsilon) { | |
reed1
2014/09/19 16:45:14
Since SkMScalar may not always be a float, we shou
tomhudson
2014/09/19 18:21:19
Done.
| |
881 col0++; | |
882 row0++; | |
883 } | |
884 if (sk_float_abs(fMat[0][1]) > kEpsilon) { | |
885 col1++; | |
886 row0++; | |
887 } | |
888 if (sk_float_abs(fMat[1][0]) > kEpsilon) { | |
889 col0++; | |
890 row1++; | |
891 } | |
892 if (sk_float_abs(fMat[1][1]) > kEpsilon) { | |
893 col1++; | |
894 row1++; | |
895 } | |
896 if (col0 > 1 || col1 > 1 || row0 > 1 || row1 > 1) return false; | |
reed1
2014/09/19 16:45:14
add comment why 1 big value is OK, but two are not
tomhudson
2014/09/19 18:21:19
Done.
| |
897 | |
898 return true; | |
899 } | |
900 | |
860 /////////////////////////////////////////////////////////////////////////////// | 901 /////////////////////////////////////////////////////////////////////////////// |
861 | 902 |
862 void SkMatrix44::dump() const { | 903 void SkMatrix44::dump() const { |
863 static const char* format = | 904 static const char* format = |
864 "[%g %g %g %g][%g %g %g %g][%g %g %g %g][%g %g %g %g]\n"; | 905 "[%g %g %g %g][%g %g %g %g][%g %g %g %g][%g %g %g %g]\n"; |
865 #if 0 | 906 #if 0 |
866 SkDebugf(format, | 907 SkDebugf(format, |
867 fMat[0][0], fMat[1][0], fMat[2][0], fMat[3][0], | 908 fMat[0][0], fMat[1][0], fMat[2][0], fMat[3][0], |
868 fMat[0][1], fMat[1][1], fMat[2][1], fMat[3][1], | 909 fMat[0][1], fMat[1][1], fMat[2][1], fMat[3][1], |
869 fMat[0][2], fMat[1][2], fMat[2][2], fMat[3][2], | 910 fMat[0][2], fMat[1][2], fMat[2][2], fMat[3][2], |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
923 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]); | 964 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]); |
924 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]); | 965 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]); |
925 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]); | 966 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]); |
926 | 967 |
927 dst[SkMatrix::kMPersp0] = SkMScalarToScalar(fMat[0][3]); | 968 dst[SkMatrix::kMPersp0] = SkMScalarToScalar(fMat[0][3]); |
928 dst[SkMatrix::kMPersp1] = SkMScalarToScalar(fMat[1][3]); | 969 dst[SkMatrix::kMPersp1] = SkMScalarToScalar(fMat[1][3]); |
929 dst[SkMatrix::kMPersp2] = SkMScalarToScalar(fMat[3][3]); | 970 dst[SkMatrix::kMPersp2] = SkMScalarToScalar(fMat[3][3]); |
930 | 971 |
931 return dst; | 972 return dst; |
932 } | 973 } |
OLD | NEW |