Index: cc/base/math_util.cc |
diff --git a/cc/base/math_util.cc b/cc/base/math_util.cc |
index d28c195971f6cd14eb753b6d9eddd51d1dd082fb..ff9906c064a69150d86984a852e7dfd8f681a567 100644 |
--- a/cc/base/math_util.cc |
+++ b/cc/base/math_util.cc |
@@ -155,9 +155,36 @@ static inline void ExpandBoundsToIncludePoint(float* xmin, |
*ymax = std::max(p.y(), *ymax); |
} |
+static inline bool IsNearlyTheSame(const float f, const float g) { |
+ // The idea behind this is to use this fraction of the larger of the |
+ // two numbers as the limit of the difference. This breaks down near |
+ // zero, so we reuse this as the minimum absolute size we will use |
+ // for the base of the scale too. |
+ static const float epsilon_scale = 0.00001f; |
+ return std::abs(f - g) < |
+ epsilon_scale * |
+ std::max(std::max(std::abs(f), std::abs(g)), epsilon_scale); |
+} |
+ |
+static inline bool IsNearlyTheSame(const gfx::PointF& lhs, |
+ const gfx::PointF& rhs) { |
+ return IsNearlyTheSame(lhs.x(), rhs.x()) && IsNearlyTheSame(lhs.y(), rhs.y()); |
+} |
+ |
+static inline bool IsNearlyTheSame(const gfx::Point3F& lhs, |
+ const gfx::Point3F& rhs) { |
+ return IsNearlyTheSame(lhs.x(), rhs.x()) && |
+ IsNearlyTheSame(lhs.y(), rhs.y()) && IsNearlyTheSame(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 && |
+ IsNearlyTheSame(clipped_quad[*num_vertices_in_clipped_quad - 1], |
+ new_vertex)) |
+ return; |
+ |
clipped_quad[*num_vertices_in_clipped_quad] = new_vertex; |
(*num_vertices_in_clipped_quad)++; |
} |
@@ -165,6 +192,11 @@ 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 && |
+ IsNearlyTheSame(clipped_quad[*num_vertices_in_clipped_quad - 1], |
+ new_vertex)) |
+ return; |
+ |
clipped_quad[*num_vertices_in_clipped_quad] = new_vertex; |
(*num_vertices_in_clipped_quad)++; |
} |
@@ -345,6 +377,11 @@ void MathUtil::MapClippedQuad(const gfx::Transform& transform, |
clipped_quad, num_vertices_in_clipped_quad); |
} |
+ if (*num_vertices_in_clipped_quad > 2 && |
+ IsNearlyTheSame(clipped_quad[0], |
+ clipped_quad[*num_vertices_in_clipped_quad - 1])) |
+ *num_vertices_in_clipped_quad -= 1; |
+ |
DCHECK_LE(*num_vertices_in_clipped_quad, 8); |
} |
@@ -406,6 +443,11 @@ bool MathUtil::MapClippedQuad3d(const gfx::Transform& transform, |
clipped_quad, num_vertices_in_clipped_quad); |
} |
+ if (*num_vertices_in_clipped_quad > 2 && |
+ IsNearlyTheSame(clipped_quad[0], |
+ clipped_quad[*num_vertices_in_clipped_quad - 1])) |
+ *num_vertices_in_clipped_quad -= 1; |
+ |
DCHECK_LE(*num_vertices_in_clipped_quad, 8); |
return (*num_vertices_in_clipped_quad >= 4); |
} |
@@ -935,4 +977,18 @@ ScopedSubnormalFloatDisabler::~ScopedSubnormalFloatDisabler() { |
#endif |
} |
+bool IsNearlyTheSameForTesting(float left, float right) { |
+ return IsNearlyTheSame(left, right); |
+} |
+ |
+bool IsNearlyTheSameForTesting(const gfx::PointF& left, |
+ const gfx::PointF& right) { |
+ return IsNearlyTheSame(left, right); |
+} |
+ |
+bool IsNearlyTheSameForTesting(const gfx::Point3F& left, |
+ const gfx::Point3F& right) { |
+ return IsNearlyTheSame(left, right); |
+} |
+ |
} // namespace cc |