shape ops work in progress

git-svn-id: http://skia.googlecode.com/svn/trunk@6470 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/Intersection/ShapeOps.cpp b/experimental/Intersection/ShapeOps.cpp
index fa29ab7..17a19e8 100644
--- a/experimental/Intersection/ShapeOps.cpp
+++ b/experimental/Intersection/ShapeOps.cpp
@@ -171,10 +171,12 @@
             contourWinding = oppContourWinding = 0;
             firstContour = false;
         } else {
-            int sumWinding = current->windSum(SkMin32(index, endIndex));
+            int minIndex = SkMin32(index, endIndex);
+            int sumWinding = current->windSum(minIndex);
+            int oppSumWinding = current->oppSum(minIndex);
             // FIXME: don't I have to adjust windSum to get contourWinding?
             if (sumWinding == SK_MinS32) {
-                sumWinding = current->computeSum(index, endIndex);
+                sumWinding = current->computeSum(index, endIndex, &oppSumWinding);
             }
             if (sumWinding == SK_MinS32) {
                 contourWinding = innerContourCheck(contourList, current,
@@ -182,21 +184,12 @@
                 oppContourWinding = innerContourCheck(contourList, current,
                         index, endIndex, true);
             } else {
-                contourWinding = sumWinding;
-                oppContourWinding = 0;
-                SkASSERT(0);
-                // FIXME: need to get oppContourWinding by building sort wheel and
-                // retrieving sumWinding of uphill opposite span, calling inner contour check
-                // if need be
-                int spanWinding = current->spanSign(index, endIndex);
-                bool inner = useInnerWinding(sumWinding - spanWinding, sumWinding);
-                if (inner) {
-                    contourWinding -= spanWinding;
-                }
+                int spanWinding, oppWinding;
+                contourWinding = updateWindings(current, index, endIndex, spanWinding, oppWinding,
+                        oppContourWinding);
 #if DEBUG_WINDING
-                SkDebugf("%s sumWinding=%d spanWinding=%d sign=%d inner=%d result=%d\n", __FUNCTION__,
-                        sumWinding, spanWinding, SkSign32(index - endIndex),
-                        inner, contourWinding);
+                SkDebugf("%s contourWinding=%d oppContourWinding=%d spanWinding=%d oppWinding=%d\n",
+                        __FUNCTION__, contourWinding, oppContourWinding, spanWinding, oppWinding);
 #endif
             }
 #if DEBUG_WINDING
diff --git a/experimental/Intersection/Simplify.cpp b/experimental/Intersection/Simplify.cpp
index 30044c5..d6396ea 100644
--- a/experimental/Intersection/Simplify.cpp
+++ b/experimental/Intersection/Simplify.cpp
@@ -29,7 +29,7 @@
 #define TRY_ROTATE 1
 
 #define DEBUG_UNUSED 0 // set to expose unused functions
-#define FORCE_RELEASE 1  // set force release to 1 for multiple thread -- no debugging
+#define FORCE_RELEASE 0  // set force release to 1 for multiple thread -- no debugging
 
 #if FORCE_RELEASE || defined SK_RELEASE
 
@@ -1476,7 +1476,15 @@
         const double oStartT = oTest->fT;
         do {
             if (transfer) {
-                if (!decrementThis & !thisXor & !opp) {
+                if (opp) {
+                    if (decrementThis) {
+                        if (decrementSpan(end)) {
+                            TrackOutside(outsideTs, end->fT, oStartT);
+                        }
+                    } else {
+                        end->fOppValue += oTest->fWindValue;
+                    }
+                } else if (!decrementThis & !thisXor) {
             #ifdef SK_DEBUG
                     SkASSERT(abs(end->fWindValue) < gDebugMaxWindValue);
             #endif
@@ -1484,14 +1492,6 @@
                 } else if (decrementSpan(end)) {
                     TrackOutside(outsideTs, end->fT, oStartT);
                 }
-            } else if (opp) {
-                if (decrementThis) {
-                    if (decrementSpan(end)) {
-                        TrackOutside(outsideTs, end->fT, oStartT);
-                    }
-                } else {
-                    end->fOppValue += oTest->fWindValue;
-                }
             } else if (oTest->fWindValue) {
                 SkASSERT(decrementThis);
                 if (startIndex > 0 && fTs[startIndex - 1].fWindValue) {
@@ -1520,7 +1520,15 @@
         while (!approximately_negative(oEndT - oEnd->fT)
                 && approximately_negative(oEnd->fT - otherTMatch)) {
             if (transfer) {
-                if (decrementThis & !otherXor & !opp) {
+                if (opp) {
+                    if (decrementThis) {
+                        oEnd->fOppValue += test->fWindValue;
+                    } else {
+                        if (decrementSpan(oEnd)) {
+                            TrackOutside(oOutsideTs, oEnd->fT, startT);
+                        }
+                    }
+                } else if (decrementThis & !otherXor & !opp) {
              #ifdef SK_DEBUG
                    SkASSERT(abs(oEnd->fWindValue) < gDebugMaxWindValue);
             #endif
@@ -1528,14 +1536,6 @@
                 } else if (decrementSpan(oEnd)) {
                     TrackOutside(oOutsideTs, oEnd->fT, startT);
                 }
-            } else if (opp) {
-                if (decrementThis) {
-                    oEnd->fOppValue += test->fWindValue;
-                } else {
-                    if (decrementSpan(oEnd)) {
-                        TrackOutside(oOutsideTs, oEnd->fT, startT);
-                    }
-                }
             } else if (test->fWindValue) {
                 SkASSERT(decrementThis);
                 if (oStartIndex > 0 && fTs[oStartIndex - 1].fWindValue) {
@@ -1579,7 +1579,7 @@
         SkTDArray<double> xOutsideTs;
         SkTDArray<double> oOutsideTs;
         do {
-            bool transfer = test->fWindValue && oTest->fWindValue && !opp;
+            bool transfer = test->fWindValue && oTest->fWindValue;
             bool decrementThis = test->fWindValue < oTest->fWindValue;
             if (decrementThis) {
                 oIndex = other.bumpCoincidentOther(test, transfer, decrementThis, otherXor, opp,
@@ -1689,7 +1689,7 @@
         other->addTwoAngles(next, oIndex, angles);
     }
 
-    int computeSum(int startIndex, int endIndex) {
+    int computeSum(int startIndex, int endIndex, int* oppoSum) {
         SkTDArray<Angle> angles;
         addTwoAngles(startIndex, endIndex, angles);
         buildAngles(endIndex, angles, false);
@@ -1751,7 +1751,11 @@
                 segment->markAndChaseWinding(angle, maxWinding);
             }
         } while (++nextIndex != lastIndex);
-        return windSum(SkMin32(startIndex, endIndex));
+        int minIndex = SkMin32(startIndex, endIndex);
+        if (oppoSum) {
+            *oppoSum = oppSum(minIndex);
+        }
+        return windSum(minIndex);
     }
 
     int crossedSpan(const SkPoint& basePt, SkScalar& bestY, double& hitT) const {
@@ -3233,6 +3237,15 @@
         return xyAtT(span).fY;
     }
 
+    void zeroSpan(Span* span) {
+        SkASSERT(span->fWindValue > 0);
+        span->fWindValue = 0;
+        if (!span->fDone) {
+            span->fDone = true;
+            ++fDoneSpans;
+        }
+    }
+
 #if DEBUG_DUMP
     void dump() const {
         const char className[] = "Segment";
@@ -4990,7 +5003,7 @@
             int sumWinding = current->windSum(SkMin32(index, endIndex));
             // FIXME: don't I have to adjust windSum to get contourWinding?
             if (sumWinding == SK_MinS32) {
-                sumWinding = current->computeSum(index, endIndex);
+                sumWinding = current->computeSum(index, endIndex, NULL);
             }
             if (sumWinding == SK_MinS32) {
                 contourWinding = innerContourCheck(contourList, current,