| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
| 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 #ifndef SkMatrix44_DEFINED | 8 #ifndef SkMatrix44_DEFINED |
| 9 #define SkMatrix44_DEFINED | 9 #define SkMatrix44_DEFINED |
| 10 | 10 |
| (...skipping 11 matching lines...) Expand all Loading... |
| 22 } | 22 } |
| 23 static inline float SkMScalarToFloat(double x) { | 23 static inline float SkMScalarToFloat(double x) { |
| 24 return static_cast<float>(x); | 24 return static_cast<float>(x); |
| 25 } | 25 } |
| 26 static inline double SkDoubleToMScalar(double x) { | 26 static inline double SkDoubleToMScalar(double x) { |
| 27 return x; | 27 return x; |
| 28 } | 28 } |
| 29 static inline double SkMScalarToDouble(double x) { | 29 static inline double SkMScalarToDouble(double x) { |
| 30 return x; | 30 return x; |
| 31 } | 31 } |
| 32 static inline double SkMScalarAbs(double x) { |
| 33 return fabs(x); |
| 34 } |
| 32 static const SkMScalar SK_MScalarPI = 3.141592653589793; | 35 static const SkMScalar SK_MScalarPI = 3.141592653589793; |
| 33 #elif defined SK_MSCALAR_IS_FLOAT | 36 #elif defined SK_MSCALAR_IS_FLOAT |
| 34 #ifdef SK_MSCALAR_IS_DOUBLE | 37 #ifdef SK_MSCALAR_IS_DOUBLE |
| 35 #error "can't define MSCALAR both as DOUBLE and FLOAT" | 38 #error "can't define MSCALAR both as DOUBLE and FLOAT" |
| 36 #endif | 39 #endif |
| 37 typedef float SkMScalar; | 40 typedef float SkMScalar; |
| 38 | 41 |
| 39 static inline float SkFloatToMScalar(float x) { | 42 static inline float SkFloatToMScalar(float x) { |
| 40 return x; | 43 return x; |
| 41 } | 44 } |
| 42 static inline float SkMScalarToFloat(float x) { | 45 static inline float SkMScalarToFloat(float x) { |
| 43 return x; | 46 return x; |
| 44 } | 47 } |
| 45 static inline float SkDoubleToMScalar(double x) { | 48 static inline float SkDoubleToMScalar(double x) { |
| 46 return static_cast<float>(x); | 49 return static_cast<float>(x); |
| 47 } | 50 } |
| 48 static inline double SkMScalarToDouble(float x) { | 51 static inline double SkMScalarToDouble(float x) { |
| 49 return static_cast<double>(x); | 52 return static_cast<double>(x); |
| 50 } | 53 } |
| 54 static inline float SkMScalarAbs(float x) { |
| 55 return sk_float_abs(x); |
| 56 } |
| 51 static const SkMScalar SK_MScalarPI = 3.14159265f; | 57 static const SkMScalar SK_MScalarPI = 3.14159265f; |
| 52 #endif | 58 #endif |
| 53 | 59 |
| 54 #define SkMScalarToScalar SkMScalarToFloat | 60 #define SkMScalarToScalar SkMScalarToFloat |
| 55 #define SkScalarToMScalar SkFloatToMScalar | 61 #define SkScalarToMScalar SkFloatToMScalar |
| 56 | 62 |
| 57 static const SkMScalar SK_MScalar1 = 1; | 63 static const SkMScalar SK_MScalar1 = 1; |
| 58 | 64 |
| 59 /////////////////////////////////////////////////////////////////////////////// | 65 /////////////////////////////////////////////////////////////////////////////// |
| 60 | 66 |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 * map an array of [x, y, 0, 1] through the matrix, returning an array | 376 * map an array of [x, y, 0, 1] through the matrix, returning an array |
| 371 * of [x', y', z', w']. | 377 * of [x', y', z', w']. |
| 372 * | 378 * |
| 373 * @param src2 array of [x, y] pairs, with implied z=0 and w=1 | 379 * @param src2 array of [x, y] pairs, with implied z=0 and w=1 |
| 374 * @param count number of [x, y] pairs in src2 | 380 * @param count number of [x, y] pairs in src2 |
| 375 * @param dst4 array of [x', y', z', w'] quads as the output. | 381 * @param dst4 array of [x', y', z', w'] quads as the output. |
| 376 */ | 382 */ |
| 377 void map2(const float src2[], int count, float dst4[]) const; | 383 void map2(const float src2[], int count, float dst4[]) const; |
| 378 void map2(const double src2[], int count, double dst4[]) const; | 384 void map2(const double src2[], int count, double dst4[]) const; |
| 379 | 385 |
| 386 /** Returns true if transformating an axis-aligned square in 2d by this matr
ix |
| 387 will produce another 2d axis-aligned square; typically means the matrix |
| 388 is a scale with perhaps a 90-degree rotation. A 3d rotation through 90 |
| 389 degrees into a perpendicular plane collapses a square to a line, but |
| 390 is still considered to be axis-aligned. |
| 391 |
| 392 By default, tolerates very slight error due to float imprecisions; |
| 393 a 90-degree rotation can still end up with 10^-17 of |
| 394 "non-axis-aligned" result. |
| 395 */ |
| 396 bool preserves2dAxisAlignment(SkMScalar epsilon = SK_ScalarNearlyZero) const
; |
| 397 |
| 380 void dump() const; | 398 void dump() const; |
| 381 | 399 |
| 382 double determinant() const; | 400 double determinant() const; |
| 383 | 401 |
| 384 private: | 402 private: |
| 385 SkMScalar fMat[4][4]; | 403 SkMScalar fMat[4][4]; |
| 386 mutable unsigned fTypeMask; | 404 mutable unsigned fTypeMask; |
| 387 | 405 |
| 388 enum { | 406 enum { |
| 389 kUnknown_Mask = 0x80, | 407 kUnknown_Mask = 0x80, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 417 /** | 435 /** |
| 418 * Does not take the time to 'compute' the typemask. Only returns true if | 436 * Does not take the time to 'compute' the typemask. Only returns true if |
| 419 * we already know that this matrix is identity. | 437 * we already know that this matrix is identity. |
| 420 */ | 438 */ |
| 421 inline bool isTriviallyIdentity() const { | 439 inline bool isTriviallyIdentity() const { |
| 422 return 0 == fTypeMask; | 440 return 0 == fTypeMask; |
| 423 } | 441 } |
| 424 }; | 442 }; |
| 425 | 443 |
| 426 #endif | 444 #endif |
| OLD | NEW |