OLD | NEW |
---|---|
1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "cc/base/math_util.h" | 5 #include "cc/base/math_util.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <cmath> | 8 #include <cmath> |
9 #include <limits> | 9 #include <limits> |
10 | 10 |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
113 (*num_vertices_in_clipped_quad)++; | 113 (*num_vertices_in_clipped_quad)++; |
114 } | 114 } |
115 | 115 |
116 static inline void AddVertexToClippedQuad3d(const gfx::Point3F& new_vertex, | 116 static inline void AddVertexToClippedQuad3d(const gfx::Point3F& new_vertex, |
117 gfx::Point3F clipped_quad[8], | 117 gfx::Point3F clipped_quad[8], |
118 int* num_vertices_in_clipped_quad) { | 118 int* num_vertices_in_clipped_quad) { |
119 clipped_quad[*num_vertices_in_clipped_quad] = new_vertex; | 119 clipped_quad[*num_vertices_in_clipped_quad] = new_vertex; |
120 (*num_vertices_in_clipped_quad)++; | 120 (*num_vertices_in_clipped_quad)++; |
121 } | 121 } |
122 | 122 |
123 float MathUtil::RoundToFixedPrecision(float value, int precision) { | |
124 // Return the same value, as higher precision is not possible with float. | |
125 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
| |
126 return value; | |
127 | |
128 float factor = std::pow(10, precision); | |
129 float integral; | |
130 float fractional = std::modf(value, &integral); | |
131 fractional = std::round(fractional * factor) / factor; | |
132 return integral + fractional; | |
133 } | |
134 | |
123 gfx::Rect MathUtil::MapEnclosingClippedRect(const gfx::Transform& transform, | 135 gfx::Rect MathUtil::MapEnclosingClippedRect(const gfx::Transform& transform, |
124 const gfx::Rect& src_rect) { | 136 const gfx::Rect& src_rect) { |
125 if (transform.IsIdentityOrIntegerTranslation()) { | 137 if (transform.IsIdentityOrIntegerTranslation()) { |
126 gfx::Vector2d offset(static_cast<int>(transform.matrix().getFloat(0, 3)), | 138 gfx::Vector2d offset(static_cast<int>(transform.matrix().getFloat(0, 3)), |
127 static_cast<int>(transform.matrix().getFloat(1, 3))); | 139 static_cast<int>(transform.matrix().getFloat(1, 3))); |
128 return src_rect + offset; | 140 return src_rect + offset; |
129 } | 141 } |
130 gfx::RectF mapped_rect = MapClippedRect(transform, gfx::RectF(src_rect)); | 142 gfx::RectF mapped_rect = MapClippedRect(transform, gfx::RectF(src_rect)); |
131 | 143 |
132 // gfx::ToEnclosingRect crashes if called on a RectF with any NaN coordinate. | 144 // gfx::ToEnclosingRect crashes if called on a RectF with any NaN coordinate. |
(...skipping 756 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
889 transform.matrix().getFloat(2, 0)); | 901 transform.matrix().getFloat(2, 0)); |
890 } | 902 } |
891 | 903 |
892 gfx::Vector3dF MathUtil::GetYAxis(const gfx::Transform& transform) { | 904 gfx::Vector3dF MathUtil::GetYAxis(const gfx::Transform& transform) { |
893 return gfx::Vector3dF(transform.matrix().getFloat(0, 1), | 905 return gfx::Vector3dF(transform.matrix().getFloat(0, 1), |
894 transform.matrix().getFloat(1, 1), | 906 transform.matrix().getFloat(1, 1), |
895 transform.matrix().getFloat(2, 1)); | 907 transform.matrix().getFloat(2, 1)); |
896 } | 908 } |
897 | 909 |
898 } // namespace cc | 910 } // namespace cc |
OLD | NEW |