diff options
author | perryuwang@tencent.com <perryuwang@tencent.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-30 05:09:10 +0000 |
---|---|---|
committer | perryuwang@tencent.com <perryuwang@tencent.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-04-30 05:09:10 +0000 |
commit | 9236621deac25ca36370c7a4b8d81eb8768a746c (patch) | |
tree | c2817c7727c2330b40fac726a22c0c5603c4c09e /cc | |
parent | dcd01e6569498369d50271ad850f449d9862062c (diff) | |
download | chromium_src-9236621deac25ca36370c7a4b8d81eb8768a746c.zip chromium_src-9236621deac25ca36370c7a4b8d81eb8768a746c.tar.gz chromium_src-9236621deac25ca36370c7a4b8d81eb8768a746c.tar.bz2 |
Fix scale on axis may be negative.
This patch modifies judgment condition whether is equal to zero for double type, avoid unnecessary sqrt calls in more case.
If "a" and "b" are both equal to zero, and "c" is less then zero, currently ScaleOnAxis will return "c" which is negative. So, we should ensure that the result is greater than zero.
BUG=none.
Review URL: https://codereview.chromium.org/253083002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@267078 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'cc')
-rw-r--r-- | cc/base/math_util.cc | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc index b492404..ca6e571 100644 --- a/cc/base/math_util.cc +++ b/cc/base/math_util.cc @@ -486,13 +486,17 @@ gfx::RectF MathUtil::ScaleRectProportional(const gfx::RectF& input_outer_rect, return output_inner_rect; } +static inline bool NearlyZero(double value) { + return std::abs(value) < std::numeric_limits<double>::epsilon(); +} + static inline float ScaleOnAxis(double a, double b, double c) { - if (!b && !c) - return a; - if (!a && !c) - return b; - if (!a && !b) - return c; + if (NearlyZero(b) && NearlyZero(c)) + return std::abs(a); + if (NearlyZero(a) && NearlyZero(c)) + return std::abs(b); + if (NearlyZero(a) && NearlyZero(b)) + return std::abs(c); // Do the sqrt as a double to not lose precision. return static_cast<float>(std::sqrt(a * a + b * b + c * c)); |