aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/core/SkMatrix.cpp
diff options
context:
space:
mode:
authorGravatar kolczyk <kolczyk@opera.com>2016-07-19 03:49:14 -0700
committerGravatar Commit bot <commit-bot@chromium.org>2016-07-19 03:49:14 -0700
commit718aab1e3f02f57f79072f70906acab866ace155 (patch)
tree752aa4ac5413f193490adee8dbc04c81b2f199c0 /src/core/SkMatrix.cpp
parent2812f03d54b7fa4fd3d724505155d44a5343d91b (diff)
Fix the assert and clamping in SkMatrix::get*Scale[s]().
Diffstat (limited to 'src/core/SkMatrix.cpp')
-rw-r--r--src/core/SkMatrix.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/core/SkMatrix.cpp b/src/core/SkMatrix.cpp
index fc698530ec..0fd802087f 100644
--- a/src/core/SkMatrix.cpp
+++ b/src/core/SkMatrix.cpp
@@ -1571,19 +1571,22 @@ template <MinMaxOrBoth MIN_MAX_OR_BOTH> bool get_scale_factor(SkMatrix::TypeMask
if (!SkScalarIsFinite(results[0])) {
return false;
}
- if (results[0] < 0 && results[0] > -SK_ScalarNearlyZero) {
+ // Due to the floating point inaccuracy, there might be an error in a, b, c
+ // calculated by sdot, further deepened by subsequent arithmetic operations
+ // on them. Therefore, we allow and cap the nearly-zero negative values.
+ SkASSERT(results[0] >= -SK_ScalarNearlyZero);
+ if (results[0] < 0) {
results[0] = 0;
}
- SkASSERT(results[0] >= 0);
results[0] = SkScalarSqrt(results[0]);
if (kBoth_MinMaxOrBoth == MIN_MAX_OR_BOTH) {
if (!SkScalarIsFinite(results[1])) {
return false;
}
- if (results[1] < 0 && results[1] > -SK_ScalarNearlyZero) {
+ SkASSERT(results[1] >= -SK_ScalarNearlyZero);
+ if (results[1] < 0) {
results[1] = 0;
}
- SkASSERT(results[1] >= 0);
results[1] = SkScalarSqrt(results[1]);
}
return true;