Index: cc/base/math_util.cc |
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc |
index 6e5ac0bd45db73b47d318a7d4b3aef0f42af0078..388fcd694eb4daed1a17cd6eb5b41ab41035ef9f 100644 |
--- a/cc/base/math_util.cc |
+++ b/cc/base/math_util.cc |
@@ -120,6 +120,21 @@ static inline void AddVertexToClippedQuad3d(const gfx::Point3F& new_vertex, |
(*num_vertices_in_clipped_quad)++; |
} |
+float MathUtil::RoundToFixedPrecision(float value) { |
+ const int kScalePrecision = 4; |
vmpstr
2015/10/16 17:58:17
Can you just write const float kFactor = 1e4 inste
prashant.n
2015/10/17 01:28:13
I'll add precision as a parameter, I was thinking
|
+ // Limiting precision 1 <= kScalePrecision <= 8, as floating point precision |
+ // of >= 12 gives different values, 8 on a safer side. |
+ DCHECK(kScalePrecision >= 1 && kScalePrecision <= 8); |
+ |
+ const float factor = pow(10, kScalePrecision); |
+ float integral; |
+ float fractional = std::modf(value, &integral); |
+ fractional *= factor; |
vmpstr
2015/10/16 17:58:17
nit: I'd just write these three things in one line
|
+ fractional = std::round(fractional); |
+ fractional /= factor; |
+ return integral + fractional; |
+} |
+ |
gfx::Rect MathUtil::MapEnclosingClippedRect(const gfx::Transform& transform, |
const gfx::Rect& src_rect) { |
if (transform.IsIdentityOrIntegerTranslation()) { |