From b4577fb2cff8c8e52cf2af7f2156b68b5d36b990 Mon Sep 17 00:00:00 2001 From: Michael Ludwig Date: Thu, 31 Oct 2019 15:14:09 -0400 Subject: [PATCH] Use point to line distance instead of area for colinear check Bug: chromium:1018218 Change-Id: I9a33332a06a63075dd016f038d5cd4ede59f9a5d Reviewed-on: https://skia-review.googlesource.com/c/skia/+/252042 Reviewed-by: Brian Salomon Commit-Queue: Michael Ludwig --- src/gpu/ops/GrAAConvexTessellator.cpp | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/gpu/ops/GrAAConvexTessellator.cpp b/src/gpu/ops/GrAAConvexTessellator.cpp index 9952491b64..c345c333b6 100644 --- a/src/gpu/ops/GrAAConvexTessellator.cpp +++ b/src/gpu/ops/GrAAConvexTessellator.cpp @@ -61,12 +61,20 @@ static bool duplicate_pt(const SkPoint& p0, const SkPoint& p1) { static bool points_are_colinear_and_b_is_middle(const SkPoint& a, const SkPoint& b, const SkPoint& c) { - // 'area' is twice the area of the triangle with corners a, b, and c. - SkScalar area = a.fX * (b.fY - c.fY) + b.fX * (c.fY - a.fY) + c.fX * (a.fY - b.fY); - if (SkScalarAbs(area) >= 2 * kCloseSqd) { + // First check distance from b to the infinite line through a, c + SkVector aToC = c - a; + SkVector n = {aToC.fY, -aToC.fX}; + n.normalize(); + + SkScalar distBToLineAC = n.dot(b) - n.dot(a); + if (SkScalarAbs(distBToLineAC) >= kClose) { + // Too far from the line, cannot be colinear return false; } - return (a - b).dot(b - c) >= 0; + + // b is colinear, but it may not be in the line segment between a and c. It's in the middle if + // both the angle at a and the angle at c are acute. + return aToC.dot(b - a) > 0 && aToC.dot(c - b) > 0; } int GrAAConvexTessellator::addPt(const SkPoint& pt,