Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2543)

Unified Diff: cc/base/math_util.cc

Issue 253083002: Fix scale on axis may be negative. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: cc/base/math_util.cc
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc
index b492404683a881045225b71876b8de17d7f7bc9b..ca6e5711760f8b6a16ccfcb9f3e10c82b1f3ada7 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));
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698