Skip to content

Commit

Permalink
Use point to line distance instead of area for colinear check
Browse files Browse the repository at this point in the history
Bug: chromium:1018218
Change-Id: I9a33332a06a63075dd016f038d5cd4ede59f9a5d
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/252042
Reviewed-by: Brian Salomon <bsalomon@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
  • Loading branch information
lhkbob authored and Skia Commit-Bot committed Oct 31, 2019
1 parent 5b6ccbb commit b4577fb
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions src/gpu/ops/GrAAConvexTessellator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b4577fb

Please sign in to comment.