shape ops work in progress

git-svn-id: http://skia.googlecode.com/svn/trunk@6020 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/Intersection/DataTypes.h b/experimental/Intersection/DataTypes.h
index e9543d1..e68f303 100644
--- a/experimental/Intersection/DataTypes.h
+++ b/experimental/Intersection/DataTypes.h
@@ -115,10 +115,18 @@
     return x > 1 - FLT_EPSILON;
 }
 
+inline bool precisely_greater_than_one(double x) {
+    return x > 1 - DBL_EPSILON;
+}
+
 inline bool approximately_less_than_zero(double x) {
     return x < FLT_EPSILON;
 }
 
+inline bool precisely_less_than_zero(double x) {
+    return x < DBL_EPSILON;
+}
+
 inline bool approximately_negative(double x) {
     return x < FLT_EPSILON;
 }
diff --git a/experimental/Intersection/EdgeDemo.cpp b/experimental/Intersection/EdgeDemo.cpp
index 1d2c2b8..09701ce 100644
--- a/experimental/Intersection/EdgeDemo.cpp
+++ b/experimental/Intersection/EdgeDemo.cpp
@@ -292,7 +292,7 @@
     }
 #endif
     paint.getPosTextPath(testStr, testStrLen, textPos, &path);
-#if 0
+#if 1
     tryRonco(path);
 #endif
 #if 0
diff --git a/experimental/Intersection/EdgeDemoApp.mm b/experimental/Intersection/EdgeDemoApp.mm
index 8acc283..a3b9c57 100644
--- a/experimental/Intersection/EdgeDemoApp.mm
+++ b/experimental/Intersection/EdgeDemoApp.mm
@@ -16,7 +16,7 @@
     };
 protected:
     virtual void onDraw(SkCanvas* canvas) {
-        static int step = 0; // 17909 ; // drawLetters first error
+        static int step = 17909 ; // drawLetters first error
                              // drawStars triggers error at 23275
                              // drawStars error not easy to debug last time I checked
         static double seconds;
diff --git a/experimental/Intersection/Simplify.cpp b/experimental/Intersection/Simplify.cpp
index 62439d0..1ea5b19 100644
--- a/experimental/Intersection/Simplify.cpp
+++ b/experimental/Intersection/Simplify.cpp
@@ -29,7 +29,7 @@
 #define SORTABLE_CONTOURS 0 // set to 1 for old code that works most of the time
 
 #define DEBUG_UNUSED 0 // set to expose unused functions
-#define FORCE_RELEASE 0
+#define FORCE_RELEASE 1
 
 #if FORCE_RELEASE || defined SK_RELEASE // set force release to 1 for multiple thread -- no debugging
 
@@ -42,7 +42,7 @@
 #define DEBUG_CONCIDENT 0
 #define DEBUG_CROSS 0
 #define DEBUG_MARK_DONE 0
-#define DEBUG_PATH_CONSTRUCTION 0
+#define DEBUG_PATH_CONSTRUCTION 1
 #define DEBUG_SORT 0
 #define DEBUG_WIND_BUMP 0
 #define DEBUG_WINDING 0
@@ -553,6 +553,14 @@
                 return longer < rhLonger;
             }
         }
+        if ((fVerb == SkPath::kLine_Verb && approximately_zero(x) && approximately_zero(y))
+                || (rh.fVerb == SkPath::kLine_Verb && approximately_zero(rx) && approximately_zero(ry))) {
+            // See general unsortable comment below. This case can happen when
+            // one line has a non-zero change in t but no change in x and y.
+            fUnsortable = true;
+            rh.fUnsortable = true;
+            return this < &rh; // even with no solution, return a stable sort
+        }
         SkASSERT(fVerb == SkPath::kQuad_Verb); // worry about cubics later
         SkASSERT(rh.fVerb == SkPath::kQuad_Verb);
         // FIXME: until I can think of something better, project a ray from the
@@ -1084,6 +1092,11 @@
     // add 2 to edge or out of range values to get T extremes
     void addOtherT(int index, double otherT, int otherIndex) {
         Span& span = fTs[index];
+        if (precisely_less_than_zero(otherT)) {
+            otherT = 0;
+        } else if (precisely_greater_than_one(otherT)) {
+            otherT = 1;
+        }
         span.fOtherT = otherT;
         span.fOtherIndex = otherIndex;
     }
@@ -1106,10 +1119,9 @@
         int insertedAt = -1;
         size_t tCount = fTs.count();
         // FIXME: only do this pinning here (e.g. this is done also in quad/line intersect)
-        if (approximately_less_than_zero(newT)) {
+        if (precisely_less_than_zero(newT)) {
             newT = 0;
-        }
-        if (approximately_greater_than_one(newT)) {
+        } else if (precisely_greater_than_one(newT)) {
             newT = 1;
         }
         for (size_t index = 0; index < tCount; ++index) {
diff --git a/experimental/Intersection/SimplifyNew_Test.cpp b/experimental/Intersection/SimplifyNew_Test.cpp
index 4cd7f01..667b596 100644
--- a/experimental/Intersection/SimplifyNew_Test.cpp
+++ b/experimental/Intersection/SimplifyNew_Test.cpp
@@ -2841,7 +2841,7 @@
     testSimplifyx(path);
 }
 
-static void (*firstTest)() = testQuadratic51;
+static void (*firstTest)() = 0;
 
 static struct {
     void (*fun)();
@@ -3127,7 +3127,7 @@
 
 static bool skipAll = false;
 static bool runSubTests = false;
-static bool runReverse = true;
+static bool runReverse = false;
 
 void SimplifyNew_Test() {
     if (skipAll) {
diff --git a/experimental/Intersection/op.htm b/experimental/Intersection/op.htm
index e1c0188..7973755 100644
--- a/experimental/Intersection/op.htm
+++ b/experimental/Intersection/op.htm
@@ -2414,11 +2414,72 @@
 path.close();
 </div>
 
+<div id="testQuadratic52o">
+path.moveTo(366.400513, 204.162521);
+path.lineTo(411.545044, 81.6732483);
+path.lineTo(366.400513, 204.162521);
+path.close();
+path.moveTo(331.585693, 138.050415);
+path.quadTo(345.867188, 121.147957, 368.11853, 121.147957);
+path.quadTo(389.193115, 121.147957, 400.693176, 136.124817);
+path.lineTo(331.585693, 138.050415);
+path.close();
+path.moveTo(369.863983, 145.645813);
+path.quadTo(382.380371, 121.254936, 406.236359, 121.254936);
+path.lineTo(369.863983, 145.645813);
+path.close();
+path.moveTo(369.970581, 137.94342);
+path.quadTo(383.98465, 121.254936, 406.235992, 121.254936);
+path.lineTo(369.970581, 137.94342);
+path.close();
+</div>
+
+<div id="testQuadratic52s">
+path.moveTo(331.585693, 138.050415);
+path.quadTo(345.867188,121.147957, 368.11853,121.147957);
+path.quadTo(378.797424,121.147957, 387.017914,124.993469);
+path.quadTo(391.577667,123.030998, 396.645874,122.098694);
+path.quadTo(401.232697,121.254936, 406.235992,121.254936);
+path.close();
+path.moveTo(383.340973, 136.608322);
+path.lineTo(369.863983,145.645813);
+path.quadTo(372.378204,140.746292, 375.350006,136.830978);
+path.lineTo(372.197113,136.918823);
+path.lineTo(369.970581,137.94342);
+path.quadTo(370.390961,137.442825, 370.818756,136.95723);
+path.lineTo(331.585693,138.050415);
+path.quadTo(345.867188,121.147957, 368.11853,121.147957);
+path.quadTo(378.797424,121.147957, 387.017914,124.993469);
+path.quadTo(391.577667,123.030998, 396.645874,122.098694);
+path.quadTo(401.232697,121.254936, 406.235992,121.254936);
+path.close();
+path.moveTo(383.340973, 136.608322);
+path.lineTo(391.380798,136.384293);
+path.lineTo(400.693176,136.124817);
+path.quadTo(397.721985,132.255341, 394.111664,129.385605);
+path.lineTo(406.236359,121.254936);
+path.quadTo(406.236176,121.254936, 406.235992,121.254936);
+path.lineTo(406.235992,121.254936);
+path.quadTo(401.232697,121.254936, 396.645874,122.098694);
+path.quadTo(391.577667,123.030998, 387.017914,124.993469);
+path.quadTo(378.797424,121.147957, 368.11853,121.147957);
+path.quadTo(345.867188,121.147957, 331.585693,138.050415);
+path.lineTo(370.818756,136.95723);
+path.quadTo(370.390961,137.442825, 369.970581,137.94342);
+path.lineTo(372.197113,136.918823);
+path.lineTo(375.350006,136.830978);
+path.quadTo(372.378204,140.746292, 369.863983,145.645813);
+path.lineTo(383.340973,136.608322);
+path.close();
+</div>
+
 </div>
 
 <script type="text/javascript">
 
 var testDivs = [
+    testQuadratic52o,
+    testQuadratic52s,
     testQuadratic51,
     testQuadratic50o,
     testQuadratic50s,