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 <bsalomon@google.com>
Commit-Queue: Michael Ludwig <michaelludwig@google.com>
This commit is contained in:
Michael Ludwig 2019-10-31 15:14:09 -04:00 committed by Skia Commit-Bot
parent 5b6ccbb6b5
commit b4577fb2cf

View File

@ -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,