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 #include "SkMatrix44.h" | 8 #include "SkMatrix44.h" |
9 | 9 |
10 static inline bool eq4(const SkMScalar* SK_RESTRICT a, | 10 static inline bool eq4(const SkMScalar* SK_RESTRICT a, |
(...skipping 511 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 double b06 = a20 * a31 - a21 * a30; | 522 double b06 = a20 * a31 - a21 * a30; |
523 double b07 = a20 * a32 - a22 * a30; | 523 double b07 = a20 * a32 - a22 * a30; |
524 double b08 = a20 * a33 - a23 * a30; | 524 double b08 = a20 * a33 - a23 * a30; |
525 double b09 = a21 * a32 - a22 * a31; | 525 double b09 = a21 * a32 - a22 * a31; |
526 double b10 = a21 * a33 - a23 * a31; | 526 double b10 = a21 * a33 - a23 * a31; |
527 double b11 = a22 * a33 - a23 * a32; | 527 double b11 = a22 * a33 - a23 * a32; |
528 | 528 |
529 // Calculate the determinant | 529 // Calculate the determinant |
530 double det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05
* b06; | 530 double det = b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05
* b06; |
531 | 531 |
532 if (dabs(det) < TOO_SMALL_FOR_DETERMINANT) { | 532 double invdet = 1.0 / det; |
| 533 // If det is zero, we want to return false. However, we also want to return
false |
| 534 // if 1/det overflows to infinity (i.e. det is denormalized). Both of these
are |
| 535 // handled by checking that 1/det is finite. |
| 536 if (!sk_float_isfinite(invdet)) { |
533 return false; | 537 return false; |
534 } | 538 } |
535 if (NULL == inverse) { | 539 if (NULL == inverse) { |
536 return true; | 540 return true; |
537 } | 541 } |
538 double invdet = 1.0 / det; | |
539 | 542 |
540 b00 *= invdet; | 543 b00 *= invdet; |
541 b01 *= invdet; | 544 b01 *= invdet; |
542 b02 *= invdet; | 545 b02 *= invdet; |
543 b03 *= invdet; | 546 b03 *= invdet; |
544 b04 *= invdet; | 547 b04 *= invdet; |
545 b05 *= invdet; | 548 b05 *= invdet; |
546 b06 *= invdet; | 549 b06 *= invdet; |
547 b07 *= invdet; | 550 b07 *= invdet; |
548 b08 *= invdet; | 551 b08 *= invdet; |
(...skipping 12 matching lines...) Expand all Loading... |
561 inverse->fMat[2][0] = SkDoubleToMScalar(a10 * b10 - a11 * b08 + a13 * b06); | 564 inverse->fMat[2][0] = SkDoubleToMScalar(a10 * b10 - a11 * b08 + a13 * b06); |
562 inverse->fMat[2][1] = SkDoubleToMScalar(a01 * b08 - a00 * b10 - a03 * b06); | 565 inverse->fMat[2][1] = SkDoubleToMScalar(a01 * b08 - a00 * b10 - a03 * b06); |
563 inverse->fMat[2][2] = SkDoubleToMScalar(a30 * b04 - a31 * b02 + a33 * b00); | 566 inverse->fMat[2][2] = SkDoubleToMScalar(a30 * b04 - a31 * b02 + a33 * b00); |
564 inverse->fMat[2][3] = SkDoubleToMScalar(a21 * b02 - a20 * b04 - a23 * b00); | 567 inverse->fMat[2][3] = SkDoubleToMScalar(a21 * b02 - a20 * b04 - a23 * b00); |
565 inverse->fMat[3][0] = SkDoubleToMScalar(a11 * b07 - a10 * b09 - a12 * b06); | 568 inverse->fMat[3][0] = SkDoubleToMScalar(a11 * b07 - a10 * b09 - a12 * b06); |
566 inverse->fMat[3][1] = SkDoubleToMScalar(a00 * b09 - a01 * b07 + a02 * b06); | 569 inverse->fMat[3][1] = SkDoubleToMScalar(a00 * b09 - a01 * b07 + a02 * b06); |
567 inverse->fMat[3][2] = SkDoubleToMScalar(a31 * b01 - a30 * b03 - a32 * b00); | 570 inverse->fMat[3][2] = SkDoubleToMScalar(a31 * b01 - a30 * b03 - a32 * b00); |
568 inverse->fMat[3][3] = SkDoubleToMScalar(a20 * b03 - a21 * b01 + a22 * b00); | 571 inverse->fMat[3][3] = SkDoubleToMScalar(a20 * b03 - a21 * b01 + a22 * b00); |
569 inverse->dirtyTypeMask(); | 572 inverse->dirtyTypeMask(); |
570 | 573 |
571 inverse->dirtyTypeMask(); | |
572 return true; | 574 return true; |
573 } | 575 } |
574 | 576 |
575 /////////////////////////////////////////////////////////////////////////////// | 577 /////////////////////////////////////////////////////////////////////////////// |
576 | 578 |
577 void SkMatrix44::transpose() { | 579 void SkMatrix44::transpose() { |
578 SkTSwap(fMat[0][1], fMat[1][0]); | 580 SkTSwap(fMat[0][1], fMat[1][0]); |
579 SkTSwap(fMat[0][2], fMat[2][0]); | 581 SkTSwap(fMat[0][2], fMat[2][0]); |
580 SkTSwap(fMat[0][3], fMat[3][0]); | 582 SkTSwap(fMat[0][3], fMat[3][0]); |
581 SkTSwap(fMat[1][2], fMat[2][1]); | 583 SkTSwap(fMat[1][2], fMat[2][1]); |
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
845 dst[SkMatrix::kMScaleX] = SkMScalarToScalar(fMat[0][0]); | 847 dst[SkMatrix::kMScaleX] = SkMScalarToScalar(fMat[0][0]); |
846 dst[SkMatrix::kMSkewX] = SkMScalarToScalar(fMat[1][0]); | 848 dst[SkMatrix::kMSkewX] = SkMScalarToScalar(fMat[1][0]); |
847 dst[SkMatrix::kMTransX] = SkMScalarToScalar(fMat[3][0]); | 849 dst[SkMatrix::kMTransX] = SkMScalarToScalar(fMat[3][0]); |
848 | 850 |
849 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]); | 851 dst[SkMatrix::kMSkewY] = SkMScalarToScalar(fMat[0][1]); |
850 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]); | 852 dst[SkMatrix::kMScaleY] = SkMScalarToScalar(fMat[1][1]); |
851 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]); | 853 dst[SkMatrix::kMTransY] = SkMScalarToScalar(fMat[3][1]); |
852 | 854 |
853 return dst; | 855 return dst; |
854 } | 856 } |
OLD | NEW |