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 "SkFloatBits.h" | 8 #include "SkFloatBits.h" |
9 #include "SkMatrix.h" | 9 #include "SkMatrix.h" |
10 #include "SkNx.h" | 10 #include "SkNx.h" |
(...skipping 1553 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1564 } else if (kMax_MinMaxOrBoth == MIN_MAX_OR_BOTH) { | 1564 } else if (kMax_MinMaxOrBoth == MIN_MAX_OR_BOTH) { |
1565 results[0] = apluscdiv2 + x; | 1565 results[0] = apluscdiv2 + x; |
1566 } else { | 1566 } else { |
1567 results[0] = apluscdiv2 - x; | 1567 results[0] = apluscdiv2 - x; |
1568 results[1] = apluscdiv2 + x; | 1568 results[1] = apluscdiv2 + x; |
1569 } | 1569 } |
1570 } | 1570 } |
1571 if (!SkScalarIsFinite(results[0])) { | 1571 if (!SkScalarIsFinite(results[0])) { |
1572 return false; | 1572 return false; |
1573 } | 1573 } |
1574 if (results[0] < 0 && results[0] > -SK_ScalarNearlyZero) { | 1574 // Due to the floating point inaccuracy, there might be an error in a, b, c |
| 1575 // calculated by sdot, further deepened by subsequent arithmetic operations |
| 1576 // on them. Therefore, we allow and cap the nearly-zero negative values. |
| 1577 SkASSERT(results[0] >= -SK_ScalarNearlyZero); |
| 1578 if (results[0] < 0) { |
1575 results[0] = 0; | 1579 results[0] = 0; |
1576 } | 1580 } |
1577 SkASSERT(results[0] >= 0); | |
1578 results[0] = SkScalarSqrt(results[0]); | 1581 results[0] = SkScalarSqrt(results[0]); |
1579 if (kBoth_MinMaxOrBoth == MIN_MAX_OR_BOTH) { | 1582 if (kBoth_MinMaxOrBoth == MIN_MAX_OR_BOTH) { |
1580 if (!SkScalarIsFinite(results[1])) { | 1583 if (!SkScalarIsFinite(results[1])) { |
1581 return false; | 1584 return false; |
1582 } | 1585 } |
1583 if (results[1] < 0 && results[1] > -SK_ScalarNearlyZero) { | 1586 SkASSERT(results[1] >= -SK_ScalarNearlyZero); |
| 1587 if (results[1] < 0) { |
1584 results[1] = 0; | 1588 results[1] = 0; |
1585 } | 1589 } |
1586 SkASSERT(results[1] >= 0); | |
1587 results[1] = SkScalarSqrt(results[1]); | 1590 results[1] = SkScalarSqrt(results[1]); |
1588 } | 1591 } |
1589 return true; | 1592 return true; |
1590 } | 1593 } |
1591 | 1594 |
1592 SkScalar SkMatrix::getMinScale() const { | 1595 SkScalar SkMatrix::getMinScale() const { |
1593 SkScalar factor; | 1596 SkScalar factor; |
1594 if (get_scale_factor<kMin_MinMaxOrBoth>(this->getType(), fMat, &factor)) { | 1597 if (get_scale_factor<kMin_MinMaxOrBoth>(this->getType(), fMat, &factor)) { |
1595 return factor; | 1598 return factor; |
1596 } else { | 1599 } else { |
(...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1883 const SkScalar m10 = -m01; | 1886 const SkScalar m10 = -m01; |
1884 const SkScalar m11 = m00; | 1887 const SkScalar m11 = m00; |
1885 const SkScalar m12 = fTy; | 1888 const SkScalar m12 = fTy; |
1886 | 1889 |
1887 quad[0].set(m02, m12); | 1890 quad[0].set(m02, m12); |
1888 quad[1].set(m00 * width + m02, m10 * width + m12); | 1891 quad[1].set(m00 * width + m02, m10 * width + m12); |
1889 quad[2].set(m00 * width + m01 * height + m02, m10 * width + m11 * height + m
12); | 1892 quad[2].set(m00 * width + m01 * height + m02, m10 * width + m11 * height + m
12); |
1890 quad[3].set(m01 * height + m02, m11 * height + m12); | 1893 quad[3].set(m01 * height + m02, m11 * height + m12); |
1891 #endif | 1894 #endif |
1892 } | 1895 } |
OLD | NEW |