Index: cc/base/math_util.cc |
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc |
index d28c195971f6cd14eb753b6d9eddd51d1dd082fb..8b10750291ab7e1c67f6e89ca6df4c4d6258f0ee 100644 |
--- a/cc/base/math_util.cc |
+++ b/cc/base/math_util.cc |
@@ -155,9 +155,31 @@ static inline void ExpandBoundsToIncludePoint(float* xmin, |
*ymax = std::max(p.y(), *ymax); |
} |
+static inline bool approx(const float f, const float g) { |
flackr
2016/12/08 23:31:06
Maybe approximatelyEqual to be verbose?
Peter Mayo
2016/12/14 23:13:11
I think nearlyTheSame covers all of the overloaded
|
+ static const float epsilon_scale = 0.00001; |
flackr
2016/12/08 23:31:06
nit: 0.00001f
Peter Mayo
2016/12/14 23:13:11
Acknowledged.
|
+ return std::abs(f - g) < |
flackr
2016/12/08 23:31:06
nit: I think <= might be safer in case of precisio
Peter Mayo
2016/12/14 23:13:11
I worry that it would worsely cover over inappropr
|
+ epsilon_scale * |
+ std::max(std::max(std::abs(f), std::abs(g)), epsilon_scale); |
+} |
+ |
+static inline bool approx(const gfx::PointF& lhs, const gfx::PointF& rhs) { |
+ return approx(lhs.x(), rhs.x()) && approx(lhs.y(), rhs.y()); |
+} |
+ |
+static inline bool approx(const gfx::Point3F& lhs, const gfx::Point3F& rhs) { |
+ return approx(lhs.x(), rhs.x()) && approx(lhs.y(), rhs.y()) && |
+ approx(lhs.z(), rhs.z()); |
+} |
+ |
static inline void AddVertexToClippedQuad(const gfx::PointF& new_vertex, |
gfx::PointF clipped_quad[8], |
int* num_vertices_in_clipped_quad) { |
+ if (*num_vertices_in_clipped_quad > 0) { |
+ if (approx(clipped_quad[*num_vertices_in_clipped_quad - 1], new_vertex)) |
+ return; |
+ if (approx(clipped_quad[0], new_vertex)) |
+ return; |
+ } |
clipped_quad[*num_vertices_in_clipped_quad] = new_vertex; |
(*num_vertices_in_clipped_quad)++; |
} |
@@ -165,6 +187,12 @@ static inline void AddVertexToClippedQuad(const gfx::PointF& new_vertex, |
static inline void AddVertexToClippedQuad3d(const gfx::Point3F& new_vertex, |
gfx::Point3F clipped_quad[8], |
int* num_vertices_in_clipped_quad) { |
+ if (*num_vertices_in_clipped_quad > 0) { |
+ if (approx(clipped_quad[*num_vertices_in_clipped_quad - 1], new_vertex)) |
+ return; |
+ if (approx(clipped_quad[0], new_vertex)) |
+ return; |
+ } |
clipped_quad[*num_vertices_in_clipped_quad] = new_vertex; |
(*num_vertices_in_clipped_quad)++; |
} |
@@ -935,4 +963,18 @@ ScopedSubnormalFloatDisabler::~ScopedSubnormalFloatDisabler() { |
#endif |
} |
+bool IsApproximatelyForUnitTesting(const float left, const float right) { |
+ return approx(left, right); |
+} |
+ |
+bool IsApproximatelyForUnitTesting(const gfx::PointF& left, |
+ const gfx::PointF& right) { |
+ return approx(left, right); |
+} |
+ |
+bool IsApproximatelyForUnitTesting(const gfx::Point3F& left, |
+ const gfx::Point3F& right) { |
+ return approx(left, right); |
+} |
+ |
} // namespace cc |