shape ops work in progress

git-svn-id: http://skia.googlecode.com/svn/trunk@7738 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/Intersection/Intersections.h b/experimental/Intersection/Intersections.h
index d873ba0..d339116 100644
--- a/experimental/Intersection/Intersections.h
+++ b/experimental/Intersection/Intersections.h
@@ -11,60 +11,40 @@
 public:
     Intersections()
         : fFlip(0)
-        , fSwap(0)
 #if SK_DEBUG
         , fDepth(0)
 #endif
+        , fSwap(0)
     {
-        // OPTIMIZE: don't need to be initialized in release
+#if SK_DEBUG
+        bzero(fPt, sizeof(fPt));
         bzero(fT, sizeof(fT));
-        bzero(fCoincidentT, sizeof(fCoincidentT));
+        bzero(fIsCoincident, sizeof(fIsCoincident));
+#endif
         reset();
     }
 
-    void add(double one, double two) {
-        for (int index = 0; index < fUsed; ++index) {
-            if (approximately_equal(fT[fSwap][index], one)
-                    && approximately_equal(fT[fSwap ^ 1][index], two)) {
-                return;
-            }
-        }
-        SkASSERT(fUsed < 9);
-        fT[fSwap][fUsed] = one;
-        fT[fSwap ^ 1][fUsed] = two;
-        ++fUsed;
-    }
-
-    // start if index == 0 : end if index == 1
-    void addCoincident(double one, double two) {
-        for (int index = 0; index < fCoincidentUsed; ++index) {
-            if (approximately_equal(fCoincidentT[fSwap][index], one)
-                    && approximately_equal(fCoincidentT[fSwap ^ 1][index], two)) {
-                return;
-            }
-        }
-        SkASSERT(fCoincidentUsed < 9);
-        fCoincidentT[fSwap][fCoincidentUsed] = one;
-        fCoincidentT[fSwap ^ 1][fCoincidentUsed] = two;
-        ++fCoincidentUsed;
-    }
-
-    void addCoincident(double s1, double e1, double s2, double e2);
-
-    // FIXME: this is necessary because curve/curve intersections are noisy
-    // remove once curve/curve intersections are improved
-    void cleanUp();
-
     int coincidentUsed() const {
-        return fCoincidentUsed;
+        if (!fIsCoincident[0]) {
+            SkASSERT(!fIsCoincident[0]);
+            return 0;
+        }
+        int count = 0;
+        SkDEBUGCODE(int count2 = 0;)
+        for (int index = 0; index < fUsed; ++index) {
+            if (fIsCoincident[0] & (1 << index)) {
+                ++count;
+            }
+    #if SK_DEBUG
+            if (fIsCoincident[1] & (1 << index)) {
+                ++count2;
+            }
+    #endif
+        }
+        SkASSERT(count == count2);
+        return count;
     }
 
-#if SK_DEBUG
-    int depth() const {
-        return fDepth;
-    }
-#endif
-
     void offset(int base, double start, double end) {
         for (int index = base; index < fUsed; ++index) {
             double val = fT[fSwap][index];
@@ -74,20 +54,34 @@
         }
     }
 
-    void insert(double one, double two);
-    void insertOne(double t, int side);
+    int insert(double one, double two, const _Point& pt);
 
+    // start if index == 0 : end if index == 1
+    void insertCoincident(double one, double two, const _Point& pt) {
+        int index = insertSwap(one, two, pt);
+        int bit = 1 << index;
+        fIsCoincident[0] |= bit;
+        fIsCoincident[1] |= bit;
+    }
+    
+    void insertCoincidentPair(double s1, double e1, double s2, double e2,
+            const _Point& startPt, const _Point& endPt);
+
+    int insertSwap(double one, double two, const _Point& pt) {
+        if (fSwap) {
+            return insert(two, one, pt);
+        } else {
+            return insert(one, two, pt);
+        }
+    }
+    
     bool intersected() const {
         return fUsed > 0;
     }
 
-    bool insertBalanced() const {
-        return fUsed == fUsed2;
-    }
-
     // leaves flip, swap alone
     void reset() {
-        fUsed = fUsed2 = fCoincidentUsed = 0;
+        fUsed = /* fUsed2 = fCoincidentUsed = */ 0;
         fUnsortable = false;
     }
 
@@ -122,11 +116,16 @@
         SkASSERT(++fDepth < 16);
     }
 
+#if SK_DEBUG
+    int depth() const {
+        return fDepth;
+    }
+#endif
+
+    _Point fPt[9];
     double fT[2][9];
-    double fCoincidentT[2][9];
-    int fUsed;
-    int fUsed2;
-    int fCoincidentUsed;
+    unsigned short fIsCoincident[2]; // bit arrays, one bit set for each coincident T
+    unsigned char fUsed;
     bool fFlip;
     bool fUnsortable;
 #if SK_DEBUG
@@ -134,9 +133,9 @@
 #endif
 protected:
     // used by addCoincident to remove ordinary intersections in range
-    void remove(double one, double two);
+    void remove(double one, double two, const _Point& startPt, const _Point& endPt);
 private:
-    int fSwap;
+    bool fSwap;
 };
 
 #endif