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 "SkOnce.h" | 10 #include "SkOnce.h" |
(...skipping 1438 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1449 return true; | 1449 return true; |
1450 } | 1450 } |
1451 | 1451 |
1452 /////////////////////////////////////////////////////////////////////////////// | 1452 /////////////////////////////////////////////////////////////////////////////// |
1453 | 1453 |
1454 enum MinOrMax { | 1454 enum MinOrMax { |
1455 kMin_MinOrMax, | 1455 kMin_MinOrMax, |
1456 kMax_MinOrMax | 1456 kMax_MinOrMax |
1457 }; | 1457 }; |
1458 | 1458 |
1459 template <MinOrMax MIN_OR_MAX> SkScalar get_stretch_factor(SkMatrix::TypeMask ty
peMask, | 1459 template <MinOrMax MIN_OR_MAX> SkScalar get_scale_factor(SkMatrix::TypeMask type
Mask, |
1460 const SkScalar m[9])
{ | 1460 const SkScalar m[9]) { |
1461 if (typeMask & SkMatrix::kPerspective_Mask) { | 1461 if (typeMask & SkMatrix::kPerspective_Mask) { |
1462 return -1; | 1462 return -1; |
1463 } | 1463 } |
1464 if (SkMatrix::kIdentity_Mask == typeMask) { | 1464 if (SkMatrix::kIdentity_Mask == typeMask) { |
1465 return 1; | 1465 return 1; |
1466 } | 1466 } |
1467 if (!(typeMask & SkMatrix::kAffine_Mask)) { | 1467 if (!(typeMask & SkMatrix::kAffine_Mask)) { |
1468 if (kMin_MinOrMax == MIN_OR_MAX) { | 1468 if (kMin_MinOrMax == MIN_OR_MAX) { |
1469 return SkMinScalar(SkScalarAbs(m[SkMatrix::kMScaleX]), | 1469 return SkMinScalar(SkScalarAbs(m[SkMatrix::kMScaleX]), |
1470 SkScalarAbs(m[SkMatrix::kMScaleY])); | 1470 SkScalarAbs(m[SkMatrix::kMScaleY])); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1503 if (kMin_MinOrMax == MIN_OR_MAX) { | 1503 if (kMin_MinOrMax == MIN_OR_MAX) { |
1504 chosenRoot = apluscdiv2 - x; | 1504 chosenRoot = apluscdiv2 - x; |
1505 } else { | 1505 } else { |
1506 chosenRoot = apluscdiv2 + x; | 1506 chosenRoot = apluscdiv2 + x; |
1507 } | 1507 } |
1508 } | 1508 } |
1509 SkASSERT(chosenRoot >= 0); | 1509 SkASSERT(chosenRoot >= 0); |
1510 return SkScalarSqrt(chosenRoot); | 1510 return SkScalarSqrt(chosenRoot); |
1511 } | 1511 } |
1512 | 1512 |
1513 SkScalar SkMatrix::getMinStretch() const { | 1513 SkScalar SkMatrix::getMinScale() const { |
1514 return get_stretch_factor<kMin_MinOrMax>(this->getType(), fMat); | 1514 return get_scale_factor<kMin_MinOrMax>(this->getType(), fMat); |
1515 } | 1515 } |
1516 | 1516 |
1517 SkScalar SkMatrix::getMaxStretch() const { | 1517 SkScalar SkMatrix::getMaxScale() const { |
1518 return get_stretch_factor<kMax_MinOrMax>(this->getType(), fMat); | 1518 return get_scale_factor<kMax_MinOrMax>(this->getType(), fMat); |
1519 } | 1519 } |
1520 | 1520 |
1521 static void reset_identity_matrix(SkMatrix* identity) { | 1521 static void reset_identity_matrix(SkMatrix* identity) { |
1522 identity->reset(); | 1522 identity->reset(); |
1523 } | 1523 } |
1524 | 1524 |
1525 const SkMatrix& SkMatrix::I() { | 1525 const SkMatrix& SkMatrix::I() { |
1526 // If you can use C++11 now, you might consider replacing this with a conste
xpr constructor. | 1526 // If you can use C++11 now, you might consider replacing this with a conste
xpr constructor. |
1527 static SkMatrix gIdentity; | 1527 static SkMatrix gIdentity; |
1528 SK_DECLARE_STATIC_ONCE(once); | 1528 SK_DECLARE_STATIC_ONCE(once); |
(...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1728 rotation1->fX = cos1; | 1728 rotation1->fX = cos1; |
1729 rotation1->fY = sin1; | 1729 rotation1->fY = sin1; |
1730 } | 1730 } |
1731 if (NULL != rotation2) { | 1731 if (NULL != rotation2) { |
1732 rotation2->fX = cos2; | 1732 rotation2->fX = cos2; |
1733 rotation2->fY = sin2; | 1733 rotation2->fY = sin2; |
1734 } | 1734 } |
1735 | 1735 |
1736 return true; | 1736 return true; |
1737 } | 1737 } |
OLD | NEW |