diff options
author | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-09 14:01:44 +0000 |
---|---|---|
committer | robertphillips@google.com <robertphillips@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-04-09 14:01:44 +0000 |
commit | 5b0f4b63c1ecef4655e1cef93a2972c8b0743d08 (patch) | |
tree | 143f4513181ebaf17924bfda56aa26cf25cdae8b /core/SkMatrix.cpp | |
parent | 2c8476449b09bd7be6dcf787923b99b198499144 (diff) | |
download | src-5b0f4b63c1ecef4655e1cef93a2972c8b0743d08.tar.gz |
First pass at Rect Effect
https://codereview.chromium.org/13521006/
git-svn-id: http://skia.googlecode.com/svn/trunk/src@8571 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'core/SkMatrix.cpp')
-rw-r--r-- | core/SkMatrix.cpp | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/core/SkMatrix.cpp b/core/SkMatrix.cpp index d9675f39..ad7b1dfa 100644 --- a/core/SkMatrix.cpp +++ b/core/SkMatrix.cpp @@ -189,6 +189,7 @@ bool SkMatrix::isSimilarity(SkScalar tol) const { SkScalar sx = fMat[kMSkewX]; SkScalar sy = fMat[kMSkewY]; + // TODO: I (rphillips) think there should be an || in here (see preservesRightAngles) // degenerate matrix, non-similarity if (SkScalarNearlyZero(mx) && SkScalarNearlyZero(my) && SkScalarNearlyZero(sx) && SkScalarNearlyZero(sy)) { @@ -202,7 +203,41 @@ bool SkMatrix::isSimilarity(SkScalar tol) const { return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)) && SkScalarNearlyEqual(vec[0].lengthSqd(), vec[1].lengthSqd(), - SkScalarSquare(tol)); + SkScalarSquare(tol)); +} + +bool SkMatrix::preservesRightAngles(SkScalar tol) const { + TypeMask mask = this->getType(); + + if (mask <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) { + // identity, translate and/or scale + return true; + } + if (mask & kPerspective_Mask) { + return false; + } + + SkASSERT(mask & kAffine_Mask); + + SkScalar mx = fMat[kMScaleX]; + SkScalar my = fMat[kMScaleY]; + SkScalar sx = fMat[kMSkewX]; + SkScalar sy = fMat[kMSkewY]; + + if ((SkScalarNearlyZero(mx) && SkScalarNearlyZero(sx)) || + (SkScalarNearlyZero(my) && SkScalarNearlyZero(sy))) { + // degenerate matrix + 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)); } /////////////////////////////////////////////////////////////////////////////// |