aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkMatrix.cpp
diff options
context:
space:
mode:
authorGravatar jvanverth <jvanverth@google.com>2014-09-02 13:15:40 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2014-09-02 13:15:41 -0700
commit17a845f76094eb3b5ac464556fced2a60dd0f088 (patch)
tree4e9908315386d1f3c5d9997336d5e3c2e9c21382 /src/core/SkMatrix.cpp
parent7f91c3359fe6d7d9deb3aee5efb163e0bd7112d4 (diff)
Fix matrix similarity test on arm64
Addresses precision issue by using a simpler test. Also fixes issues with IvMatrix::preservesRightAngles, and adds unit tests. BUG=skia:2405 R=robertphillips@google.com, egdaniel@google.com, djsollen@google.com, reed@google.com Author: jvanverth@google.com Review URL: https://codereview.chromium.org/520123002
Diffstat (limited to 'src/core/SkMatrix.cpp')
-rw-r--r--src/core/SkMatrix.cpp26
1 files changed, 10 insertions, 16 deletions
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index 95662fc4cd..814f16a5ea 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -176,20 +176,16 @@ bool SkMatrix::isSimilarity(SkScalar tol) const {
return false;
}
- // it has scales and skews, but it could also be rotation, check it out.
- SkVector vec[2];
- vec[0].set(mx, sx);
- vec[1].set(sy, my);
-
- return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)) &&
- SkScalarNearlyEqual(vec[0].lengthSqd(), vec[1].lengthSqd(),
- SkScalarSquare(tol));
+ // upper 2x2 is rotation/reflection + uniform scale if basis vectors
+ // are 90 degree rotations of each other
+ return (SkScalarNearlyEqual(mx, my, tol) && SkScalarNearlyEqual(sx, -sy, tol))
+ || (SkScalarNearlyEqual(mx, -my, tol) && SkScalarNearlyEqual(sx, sy, tol));
}
bool SkMatrix::preservesRightAngles(SkScalar tol) const {
TypeMask mask = this->getType();
- if (mask <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) {
+ if (mask <= kTranslate_Mask) {
// identity, translate and/or scale
return true;
}
@@ -197,7 +193,7 @@ bool SkMatrix::preservesRightAngles(SkScalar tol) const {
return false;
}
- SkASSERT(mask & kAffine_Mask);
+ SkASSERT(mask & (kAffine_Mask | kScale_Mask));
SkScalar mx = fMat[kMScaleX];
SkScalar my = fMat[kMScaleY];
@@ -208,14 +204,12 @@ bool SkMatrix::preservesRightAngles(SkScalar tol) const {
return false;
}
- // it has scales and skews, but it could also be rotation, check it out.
+ // upper 2x2 is scale + rotation/reflection if basis vectors are orthogonal
SkVector vec[2];
- vec[0].set(mx, sx);
- vec[1].set(sy, my);
+ vec[0].set(mx, sy);
+ vec[1].set(sx, my);
- return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)) &&
- SkScalarNearlyEqual(vec[0].lengthSqd(), vec[1].lengthSqd(),
- SkScalarSquare(tol));
+ return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol));
}
///////////////////////////////////////////////////////////////////////////////