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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/utils/SkMatrix44.h ('k') | tests/Matrix44Test.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/utils/SkMatrix44.cpp
diff --git a/src/utils/SkMatrix44.cpp b/src/utils/SkMatrix44.cpp
index a7133ec1a75fb9d8c82fae09aa31197b250e7b12..1835635f1d2fc4944b57014949de8d3e306ddb15 100644
--- a/src/utils/SkMatrix44.cpp
+++ b/src/utils/SkMatrix44.cpp
@@ -857,6 +857,46 @@ void SkMatrix44::map2(const double src2[], int count, double dst4[]) const {
proc(fMat, src2, count, dst4);
}
+bool SkMatrix44::preserves2dAxisAlignment (SkMScalar epsilon) const {
+
+ // Can't check (mask & kPerspective_Mask) because Z isn't relevant here.
+ if (0 != perspX() || 0 != perspY()) return false;
+
+ // A matrix with two non-zeroish values in any of the upper right
+ // rows or columns will skew. If only one value in each row or
+ // column is non-zeroish, we get a scale plus perhaps a 90-degree
+ // rotation.
+ int col0 = 0;
+ int col1 = 0;
+ int row0 = 0;
+ int row1 = 0;
+
+ // Must test against epsilon, not 0, because we can get values
+ // around 6e-17 in the matrix that "should" be 0.
+
+ if (SkMScalarAbs(fMat[0][0]) > epsilon) {
+ col0++;
+ row0++;
+ }
+ if (SkMScalarAbs(fMat[0][1]) > epsilon) {
+ col1++;
+ row0++;
+ }
+ if (SkMScalarAbs(fMat[1][0]) > epsilon) {
+ col0++;
+ row1++;
+ }
+ if (SkMScalarAbs(fMat[1][1]) > epsilon) {
+ col1++;
+ row1++;
+ }
+ if (col0 > 1 || col1 > 1 || row0 > 1 || row1 > 1) {
+ return false;
reed1 2014/09/26 18:34:28 evil, but you could say for speed: if ((col0 | co
+ }
+
+ return true;
+}
+
///////////////////////////////////////////////////////////////////////////////
void SkMatrix44::dump() const {
« 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