GrTessellator: avoid split with zero primary and out-of-range secondary.

Sometimes the intersector will return an intersection which is on the
same primary sort criterion (eg., Y coordinate), but out-of-range on the
secondary. We shouldn't do splits in this case. The only case we really
care about is if it's less than one epsilon and greater than zero,
and thus numerically unsplittable.

Bug: 851914
Change-Id: Ia772763b6a66a14ca159cf409a832835244e83bc
Reviewed-on: https://skia-review.googlesource.com/136803
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Stephen White <senorblanco@chromium.org>
diff --git a/src/gpu/GrTessellator.cpp b/src/gpu/GrTessellator.cpp
index 2dd82a0..d6a64cd 100644
--- a/src/gpu/GrTessellator.cpp
+++ b/src/gpu/GrTessellator.cpp
@@ -1199,7 +1199,7 @@
 bool nearly_flat(Comparator& c, Edge* edge) {
     SkPoint diff = edge->fBottom->fPoint - edge->fTop->fPoint;
     float primaryDiff = c.fDirection == Comparator::Direction::kHorizontal ? diff.fX : diff.fY;
-    return fabs(primaryDiff) < std::numeric_limits<float>::epsilon();
+    return fabs(primaryDiff) < std::numeric_limits<float>::epsilon() && primaryDiff != 0.0f;
 }
 
 SkPoint clamp(SkPoint p, SkPoint min, SkPoint max, Comparator& c) {
diff --git a/tests/TessellatingPathRendererTests.cpp b/tests/TessellatingPathRendererTests.cpp
index 6f2d896..0b30fee 100644
--- a/tests/TessellatingPathRendererTests.cpp
+++ b/tests/TessellatingPathRendererTests.cpp
@@ -546,6 +546,20 @@
     return path;
 }
 
+// Reduction from crbug.com/851914.
+static SkPath create_path_38() {
+    SkPath path;
+    path.moveTo(14.400531768798828125, 17.711114883422851562);
+    path.lineTo(14.621990203857421875,   171563104293879808);
+    path.lineTo(14.027951240539550781,   872585759381520384);
+    path.lineTo( 14.0216827392578125,   872665817571917824);
+    path.lineTo(7.699314117431640625,    -3417320793833472);
+    path.moveTo(11.606547355651855469,       17.40966796875);
+    path.lineTo( 7642114886926860288, 21.08358001708984375);
+    path.lineTo(11.606547355651855469, 21.08358001708984375);
+    return path;
+}
+
 static std::unique_ptr<GrFragmentProcessor> create_linear_gradient_processor(GrContext* ctx) {
 
     SkPoint pts[2] = { {0, 0}, {1, 1} };
@@ -643,4 +657,5 @@
     test_path(ctx, rtc.get(), create_path_35());
     test_path(ctx, rtc.get(), create_path_36());
     test_path(ctx, rtc.get(), create_path_37());
+    test_path(ctx, rtc.get(), create_path_38(), SkMatrix(), GrAAType::kCoverage);
 }