OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2006 The Android Open Source Project | 2 * Copyright 2006 The Android Open Source Project |
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 "SkMatrix.h" | 8 #include "SkMatrix.h" |
9 #include "SkFloatBits.h" | 9 #include "SkFloatBits.h" |
10 #include "SkString.h" | 10 #include "SkString.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 if (!(mask & kAffine_Mask)) { | 169 if (!(mask & kAffine_Mask)) { |
170 return !SkScalarNearlyZero(mx) && SkScalarNearlyEqual(SkScalarAbs(mx), S
kScalarAbs(my)); | 170 return !SkScalarNearlyZero(mx) && SkScalarNearlyEqual(SkScalarAbs(mx), S
kScalarAbs(my)); |
171 } | 171 } |
172 SkScalar sx = fMat[kMSkewX]; | 172 SkScalar sx = fMat[kMSkewX]; |
173 SkScalar sy = fMat[kMSkewY]; | 173 SkScalar sy = fMat[kMSkewY]; |
174 | 174 |
175 if (is_degenerate_2x2(mx, sx, sy, my)) { | 175 if (is_degenerate_2x2(mx, sx, sy, my)) { |
176 return false; | 176 return false; |
177 } | 177 } |
178 | 178 |
179 // it has scales and skews, but it could also be rotation, check it out. | 179 // upper 2x2 is rotation/reflection + uniform scale if basis vectors |
180 SkVector vec[2]; | 180 // are 90 degree rotations of each other |
181 vec[0].set(mx, sx); | 181 return (SkScalarNearlyEqual(mx, my, tol) && SkScalarNearlyEqual(sx, -sy, tol
)) |
182 vec[1].set(sy, my); | 182 || (SkScalarNearlyEqual(mx, -my, tol) && SkScalarNearlyEqual(sx, sy, tol
)); |
183 | |
184 return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)) && | |
185 SkScalarNearlyEqual(vec[0].lengthSqd(), vec[1].lengthSqd(), | |
186 SkScalarSquare(tol)); | |
187 } | 183 } |
188 | 184 |
189 bool SkMatrix::preservesRightAngles(SkScalar tol) const { | 185 bool SkMatrix::preservesRightAngles(SkScalar tol) const { |
190 TypeMask mask = this->getType(); | 186 TypeMask mask = this->getType(); |
191 | 187 |
192 if (mask <= (SkMatrix::kTranslate_Mask | SkMatrix::kScale_Mask)) { | 188 if (mask <= kTranslate_Mask) { |
193 // identity, translate and/or scale | 189 // identity, translate and/or scale |
194 return true; | 190 return true; |
195 } | 191 } |
196 if (mask & kPerspective_Mask) { | 192 if (mask & kPerspective_Mask) { |
197 return false; | 193 return false; |
198 } | 194 } |
199 | 195 |
200 SkASSERT(mask & kAffine_Mask); | 196 SkASSERT(mask & (kAffine_Mask | kScale_Mask)); |
201 | 197 |
202 SkScalar mx = fMat[kMScaleX]; | 198 SkScalar mx = fMat[kMScaleX]; |
203 SkScalar my = fMat[kMScaleY]; | 199 SkScalar my = fMat[kMScaleY]; |
204 SkScalar sx = fMat[kMSkewX]; | 200 SkScalar sx = fMat[kMSkewX]; |
205 SkScalar sy = fMat[kMSkewY]; | 201 SkScalar sy = fMat[kMSkewY]; |
206 | 202 |
207 if (is_degenerate_2x2(mx, sx, sy, my)) { | 203 if (is_degenerate_2x2(mx, sx, sy, my)) { |
208 return false; | 204 return false; |
209 } | 205 } |
210 | 206 |
211 // it has scales and skews, but it could also be rotation, check it out. | 207 // upper 2x2 is scale + rotation/reflection if basis vectors are orthogonal |
212 SkVector vec[2]; | 208 SkVector vec[2]; |
213 vec[0].set(mx, sx); | 209 vec[0].set(mx, sy); |
214 vec[1].set(sy, my); | 210 vec[1].set(sx, my); |
215 | 211 |
216 return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)) && | 212 return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)); |
217 SkScalarNearlyEqual(vec[0].lengthSqd(), vec[1].lengthSqd(), | |
218 SkScalarSquare(tol)); | |
219 } | 213 } |
220 | 214 |
221 /////////////////////////////////////////////////////////////////////////////// | 215 /////////////////////////////////////////////////////////////////////////////// |
222 | 216 |
223 static inline SkScalar sdot(SkScalar a, SkScalar b, SkScalar c, SkScalar d) { | 217 static inline SkScalar sdot(SkScalar a, SkScalar b, SkScalar c, SkScalar d) { |
224 return a * b + c * d; | 218 return a * b + c * d; |
225 } | 219 } |
226 | 220 |
227 static inline SkScalar sdot(SkScalar a, SkScalar b, SkScalar c, SkScalar d, | 221 static inline SkScalar sdot(SkScalar a, SkScalar b, SkScalar c, SkScalar d, |
228 SkScalar e, SkScalar f) { | 222 SkScalar e, SkScalar f) { |
(...skipping 1551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1780 rotation1->fX = cos1; | 1774 rotation1->fX = cos1; |
1781 rotation1->fY = sin1; | 1775 rotation1->fY = sin1; |
1782 } | 1776 } |
1783 if (NULL != rotation2) { | 1777 if (NULL != rotation2) { |
1784 rotation2->fX = cos2; | 1778 rotation2->fX = cos2; |
1785 rotation2->fY = sin2; | 1779 rotation2->fY = sin2; |
1786 } | 1780 } |
1787 | 1781 |
1788 return true; | 1782 return true; |
1789 } | 1783 } |
OLD | NEW |