path ops -- rewrite angle sort

This is a major change resulting from a minor
tweak. In the old code, the intersection point
of two curves was shared between them, but the
intersection points and end points of sorted edges was
computed directly from the intersection T value.

In this CL, both intersection points and sorted points
are the same, and intermediate control points are computed
to preserve their slope.

The sort itself has been completely rewritten to be more
robust and remove 'magic' checks, conditions that empirically
worked but couldn't be rationalized.

This CL was triggered by errors generated computing the clips
of SKP files. At this point, all 73M standard tests work and
at least the first troublesome SKPs work.

Review URL: https://codereview.chromium.org/15338003

git-svn-id: http://skia.googlecode.com/svn/trunk@9432 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/src/pathops/SkDCubicIntersection.cpp b/src/pathops/SkDCubicIntersection.cpp
index 922c103..5106bbb 100644
--- a/src/pathops/SkDCubicIntersection.cpp
+++ b/src/pathops/SkDCubicIntersection.cpp
@@ -426,6 +426,35 @@
             && pt[0].approximatelyEqual(pt[1])) {
         removeOne(used() - 2);
     }
+    // vet the pairs of t values to see if the mid value is also on the curve. If so, mark
+    // the span as coincident
+    if (fUsed >= 2 && !coincidentUsed()) {
+        int last = fUsed - 1;
+        int match = 0;
+        for (int index = 0; index < last; ++index) {
+            double mid1 = (fT[0][index] + fT[0][index + 1]) / 2;
+            double mid2 = (fT[1][index] + fT[1][index + 1]) / 2;
+            pt[0] = c1.xyAtT(mid1);
+            pt[1] = c2.xyAtT(mid2);
+            if (pt[0].approximatelyEqual(pt[1])) {
+                match |= 1 << index;
+            }
+        }
+        if (match) {
+            if (((match + 1) & match) != 0) {
+                SkDebugf("%s coincident hole\n", __FUNCTION__);
+            }
+            // for now, assume that everything from start to finish is coincident
+            if (fUsed > 2) {
+                  fPt[1] = fPt[last];
+                  fT[0][1] = fT[0][last];
+                  fT[1][1] = fT[1][last];
+                  fIsCoincident[0] = 0x03;
+                  fIsCoincident[1] = 0x03;
+                  fUsed = 2;
+            }
+        }
+    }
     return fUsed;
 }