Chromium Code Reviews| Index: cc/base/math_util.cc |
| diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc |
| index 6e5ac0bd45db73b47d318a7d4b3aef0f42af0078..f4bc359059f9dfb57cc8aa103514048ca8d906e3 100644 |
| --- a/cc/base/math_util.cc |
| +++ b/cc/base/math_util.cc |
| @@ -120,6 +120,18 @@ static inline void AddVertexToClippedQuad3d(const gfx::Point3F& new_vertex, |
| (*num_vertices_in_clipped_quad)++; |
| } |
| +float MathUtil::RoundToFixedPrecision(float value, int precision) { |
| + // Return the same value, as higher precision is not possible with float. |
| + if (precision < 1 || precision > (std::numeric_limits<float>::digits10 - 1)) |
|
ericrk
2015/10/19 16:40:50
drive-by-nit: Should we DCHECK that precision >= 1
vmpstr
2015/10/19 18:58:38
I agree, this should be a DCHECK instead of an ear
|
| + return value; |
| + |
| + float factor = std::pow(10, precision); |
| + float integral; |
| + float fractional = std::modf(value, &integral); |
| + fractional = std::round(fractional * factor) / factor; |
| + return integral + fractional; |
| +} |
| + |
| gfx::Rect MathUtil::MapEnclosingClippedRect(const gfx::Transform& transform, |
| const gfx::Rect& src_rect) { |
| if (transform.IsIdentityOrIntegerTranslation()) { |