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 "Sk64.h" | 9 #include "Sk64.h" |
10 #include "SkFloatBits.h" | 10 #include "SkFloatBits.h" |
11 #include "SkOnce.h" | 11 #include "SkOnce.h" |
12 #include "SkScalarCompare.h" | |
13 #include "SkString.h" | 12 #include "SkString.h" |
14 | 13 |
15 #ifdef SK_SCALAR_IS_FLOAT | 14 #ifdef SK_SCALAR_IS_FLOAT |
16 #define kMatrix22Elem SK_Scalar1 | 15 #define kMatrix22Elem SK_Scalar1 |
17 | 16 |
18 static inline float SkDoubleToFloat(double x) { | 17 static inline float SkDoubleToFloat(double x) { |
19 return static_cast<float>(x); | 18 return static_cast<float>(x); |
20 } | 19 } |
21 #else | 20 #else |
22 #define kMatrix22Elem SK_Fract1 | 21 #define kMatrix22Elem SK_Fract1 |
(...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 vec[1].set(sy, my); | 243 vec[1].set(sy, my); |
245 | 244 |
246 return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)) && | 245 return SkScalarNearlyZero(vec[0].dot(vec[1]), SkScalarSquare(tol)) && |
247 SkScalarNearlyEqual(vec[0].lengthSqd(), vec[1].lengthSqd(), | 246 SkScalarNearlyEqual(vec[0].lengthSqd(), vec[1].lengthSqd(), |
248 SkScalarSquare(tol)); | 247 SkScalarSquare(tol)); |
249 } | 248 } |
250 | 249 |
251 /////////////////////////////////////////////////////////////////////////////// | 250 /////////////////////////////////////////////////////////////////////////////// |
252 | 251 |
253 void SkMatrix::setTranslate(SkScalar dx, SkScalar dy) { | 252 void SkMatrix::setTranslate(SkScalar dx, SkScalar dy) { |
254 if (SkScalarToCompareType(dx) || SkScalarToCompareType(dy)) { | 253 if (dx || dy) { |
255 fMat[kMTransX] = dx; | 254 fMat[kMTransX] = dx; |
256 fMat[kMTransY] = dy; | 255 fMat[kMTransY] = dy; |
257 | 256 |
258 fMat[kMScaleX] = fMat[kMScaleY] = SK_Scalar1; | 257 fMat[kMScaleX] = fMat[kMScaleY] = SK_Scalar1; |
259 fMat[kMSkewX] = fMat[kMSkewY] = | 258 fMat[kMSkewX] = fMat[kMSkewY] = |
260 fMat[kMPersp0] = fMat[kMPersp1] = 0; | 259 fMat[kMPersp0] = fMat[kMPersp1] = 0; |
261 fMat[kMPersp2] = kMatrix22Elem; | 260 fMat[kMPersp2] = kMatrix22Elem; |
262 | 261 |
263 this->setTypeMask(kTranslate_Mask | kRectStaysRect_Mask); | 262 this->setTypeMask(kTranslate_Mask | kRectStaysRect_Mask); |
264 } else { | 263 } else { |
265 this->reset(); | 264 this->reset(); |
266 } | 265 } |
267 } | 266 } |
268 | 267 |
269 bool SkMatrix::preTranslate(SkScalar dx, SkScalar dy) { | 268 bool SkMatrix::preTranslate(SkScalar dx, SkScalar dy) { |
270 if (this->hasPerspective()) { | 269 if (this->hasPerspective()) { |
271 SkMatrix m; | 270 SkMatrix m; |
272 m.setTranslate(dx, dy); | 271 m.setTranslate(dx, dy); |
273 return this->preConcat(m); | 272 return this->preConcat(m); |
274 } | 273 } |
275 | 274 |
276 if (SkScalarToCompareType(dx) || SkScalarToCompareType(dy)) { | 275 if (dx || dy) { |
277 fMat[kMTransX] += SkScalarMul(fMat[kMScaleX], dx) + | 276 fMat[kMTransX] += SkScalarMul(fMat[kMScaleX], dx) + |
278 SkScalarMul(fMat[kMSkewX], dy); | 277 SkScalarMul(fMat[kMSkewX], dy); |
279 fMat[kMTransY] += SkScalarMul(fMat[kMSkewY], dx) + | 278 fMat[kMTransY] += SkScalarMul(fMat[kMSkewY], dx) + |
280 SkScalarMul(fMat[kMScaleY], dy); | 279 SkScalarMul(fMat[kMScaleY], dy); |
281 | 280 |
282 this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask); | 281 this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask); |
283 } | 282 } |
284 return true; | 283 return true; |
285 } | 284 } |
286 | 285 |
287 bool SkMatrix::postTranslate(SkScalar dx, SkScalar dy) { | 286 bool SkMatrix::postTranslate(SkScalar dx, SkScalar dy) { |
288 if (this->hasPerspective()) { | 287 if (this->hasPerspective()) { |
289 SkMatrix m; | 288 SkMatrix m; |
290 m.setTranslate(dx, dy); | 289 m.setTranslate(dx, dy); |
291 return this->postConcat(m); | 290 return this->postConcat(m); |
292 } | 291 } |
293 | 292 |
294 if (SkScalarToCompareType(dx) || SkScalarToCompareType(dy)) { | 293 if (dx || dy) { |
295 fMat[kMTransX] += dx; | 294 fMat[kMTransX] += dx; |
296 fMat[kMTransY] += dy; | 295 fMat[kMTransY] += dy; |
297 this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask); | 296 this->setTypeMask(kUnknown_Mask | kOnlyPerspectiveValid_Mask); |
298 } | 297 } |
299 return true; | 298 return true; |
300 } | 299 } |
301 | 300 |
302 /////////////////////////////////////////////////////////////////////////////// | 301 /////////////////////////////////////////////////////////////////////////////// |
303 | 302 |
304 void SkMatrix::setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) { | 303 void SkMatrix::setScale(SkScalar sx, SkScalar sy, SkScalar px, SkScalar py) { |
(...skipping 1833 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2138 rotation1->fX = cos1; | 2137 rotation1->fX = cos1; |
2139 rotation1->fY = sin1; | 2138 rotation1->fY = sin1; |
2140 } | 2139 } |
2141 if (NULL != rotation2) { | 2140 if (NULL != rotation2) { |
2142 rotation2->fX = cos2; | 2141 rotation2->fX = cos2; |
2143 rotation2->fY = sin2; | 2142 rotation2->fY = sin2; |
2144 } | 2143 } |
2145 | 2144 |
2146 return true; | 2145 return true; |
2147 } | 2146 } |
OLD | NEW |