Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(57)

Side by Side Diff: src/utils/SkMatrix44.cpp

Issue 508303005: SkMatrix44::preserves2dAxisAlignment() (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: unit test review fixes Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « include/utils/SkMatrix44.h ('k') | tests/Matrix44Test.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 static inline bool eq4(const SkMScalar* SK_RESTRICT a, 10 static inline bool eq4(const SkMScalar* SK_RESTRICT a,
(...skipping 839 matching lines...) Expand 10 before | Expand all | Expand 10 after
850 void SkMatrix44::map2(const double src2[], int count, double dst4[]) const { 850 void SkMatrix44::map2(const double src2[], int count, double dst4[]) const {
851 static const Map2Procd gProc[] = { 851 static const Map2Procd gProc[] = {
852 map2_id, map2_td, map2_sd, map2_sd, map2_ad, map2_ad, map2_ad, map2_ad 852 map2_id, map2_td, map2_sd, map2_sd, map2_ad, map2_ad, map2_ad, map2_ad
853 }; 853 };
854 854
855 TypeMask mask = this->getType(); 855 TypeMask mask = this->getType();
856 Map2Procd proc = (mask & kPerspective_Mask) ? map2_pd : gProc[mask]; 856 Map2Procd proc = (mask & kPerspective_Mask) ? map2_pd : gProc[mask];
857 proc(fMat, src2, count, dst4); 857 proc(fMat, src2, count, dst4);
858 } 858 }
859 859
860 bool SkMatrix44::preserves2dAxisAlignment (SkMScalar epsilon) const {
861
862 // Can't check (mask & kPerspective_Mask) because Z isn't relevant here.
863 if (0 != perspX() || 0 != perspY()) return false;
864
865 // A matrix with two non-zeroish values in any of the upper right
866 // rows or columns will skew. If only one value in each row or
867 // column is non-zeroish, we get a scale plus perhaps a 90-degree
868 // rotation.
869 int col0 = 0;
870 int col1 = 0;
871 int row0 = 0;
872 int row1 = 0;
873
874 // Must test against epsilon, not 0, because we can get values
875 // around 6e-17 in the matrix that "should" be 0.
876
877 if (SkMScalarAbs(fMat[0][0]) > epsilon) {
878 col0++;
879 row0++;
880 }
881 if (SkMScalarAbs(fMat[0][1]) > epsilon) {
882 col1++;
883 row0++;
884 }
885 if (SkMScalarAbs(fMat[1][0]) > epsilon) {
886 col0++;
887 row1++;
888 }
889 if (SkMScalarAbs(fMat[1][1]) > epsilon) {
890 col1++;
891 row1++;
892 }
893 if (col0 > 1 || col1 > 1 || row0 > 1 || row1 > 1) {
894 return false;
reed1 2014/09/26 18:34:28 evil, but you could say for speed: if ((col0 | co
895 }
896
897 return true;
898 }
899
860 /////////////////////////////////////////////////////////////////////////////// 900 ///////////////////////////////////////////////////////////////////////////////
861 901
862 void SkMatrix44::dump() const { 902 void SkMatrix44::dump() const {
863 static const char* format = 903 static const char* format =
864 "[%g %g %g %g][%g %g %g %g][%g %g %g %g][%g %g %g %g]\n"; 904 "[%g %g %g %g][%g %g %g %g][%g %g %g %g][%g %g %g %g]\n";
865 #if 0 905 #if 0
866 SkDebugf(format, 906 SkDebugf(format,
867 fMat[0][0], fMat[1][0], fMat[2][0], fMat[3][0], 907 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], 908 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], 909 fMat[0][2], fMat[1][2], fMat[2][2], fMat[3][2],
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
923 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]); 963 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]);
924 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]); 964 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]);
925 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]); 965 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]);
926 966
927 dst[SkMatrix::kMPersp0] = SkMScalarToScalar(fMat[0][3]); 967 dst[SkMatrix::kMPersp0] = SkMScalarToScalar(fMat[0][3]);
928 dst[SkMatrix::kMPersp1] = SkMScalarToScalar(fMat[1][3]); 968 dst[SkMatrix::kMPersp1] = SkMScalarToScalar(fMat[1][3]);
929 dst[SkMatrix::kMPersp2] = SkMScalarToScalar(fMat[3][3]); 969 dst[SkMatrix::kMPersp2] = SkMScalarToScalar(fMat[3][3]);
930 970
931 return dst; 971 return dst;
932 } 972 }
OLDNEW
« no previous file with comments | « include/utils/SkMatrix44.h ('k') | tests/Matrix44Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698