shape ops work in progress

good checkpoint: nearly all tests pass solidly here

git-svn-id: http://skia.googlecode.com/svn/trunk@7420 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/Intersection/qc.htm b/experimental/Intersection/qc.htm
index 2cf3592..9b1cbbe 100644
--- a/experimental/Intersection/qc.htm
+++ b/experimental/Intersection/qc.htm
@@ -1639,11 +1639,82 @@
   {{72.9633878,95.6593007}, {42.7738746,88.4730382}, {31.1932785,80.2458029}},
 </div>
 
+<div id="cubic25">
+{{x = 39.765160968417838, y = 33.060396198677083}, {x = 5.1922921581157908, y = 66.854301452103215}, {x = 31.619281802149157, y = 25.269248720849514}, {x = 81.541621071073038, y = 70.025341524754353}}
+{{x = 46.078911165743556, y = 48.259962651999651}, {x = 20.24450549867214, y = 49.403916182650214}, {x = 0.26325131778756683, y = 24.46489805563581}, {x = 15.915006546264051, y = 83.515023059917155}}
+  {{39.765161,33.0603962}, {30.6426004,41.804305}, {26.9359756,44.8138368}},
+  {{26.9359756,44.8138368}, {21.5667569,48.8605535}, {26.2727712,47.6735862}},
+  {{26.2727712,47.6735862}, {31.3832959,46.2642047}, {45.8264929,49.1528875}},
+  {{45.8264929,49.1528875}, {60.2696898,52.0415702}, {81.5416211,70.0253415}},
+
+  {{46.0789112,48.2599627}, {35.5887068,48.1941457}, {27.2014026,45.6924463}},
+  {{27.2014026,45.6924463}, {19.5490336,43.4817863}, {15.020365,44.2719744}},
+  {{15.020365,44.2719744}, {10.4916964,45.0621625}, {10.3896311,53.6689795}},
+  {{10.3896311,53.6689795}, {10.2875658,62.2757965}, {15.9150065,83.5150231}},
+</div>
+
+<div id="cubic26">
+{{x = 95.837747722788592, y = 45.025976907939643}, {x = 16.564570095652982, y = 0.72959763963222402}, {x = 63.209855865319199, y = 68.047528419665767}, {x = 57.640240647662544, y = 59.524565264361243}}
+{{x = 51.593891741518817, y = 38.53849970667553}, {x = 62.34752929878772, y = 74.924924725166022}, {x = 74.810149322641152, y = 34.17966562983564}, {x = 29.368398119401373, y = 94.66719277886078}}
+  {{95.8377477,45.0259769}, {72.4120612,32.1119735}, {61.9589898,30.3422249}},
+  {{61.9589898,30.3422249}, {51.5059185,28.5724763}, {49.7502617,33.4480576}},
+  {{49.7502617,33.4480576}, {47.9946048,38.3236388}, {50.6611618,45.345625}},
+  {{50.6611618,45.345625}, {53.3277187,52.3676112}, {56.1412886,57.0370775}},
+  {{56.1412886,57.0370775}, {58.9548585,61.7065438}, {57.6402406,59.5245653}},
+
+  {{51.5938917,38.5384997}, {54.39659,47.5609728}, {56.9124968,51.2509862}},
+  {{56.9124968,51.2509862}, {59.4284036,54.9409997}, {60.7901347,55.8937858}},
+  {{60.7901347,55.8937858}, {63.1940269,56.8659601}, {59.551481,59.5998651}},
+  {{59.551481,59.5998651}, {56.8806183,61.8512737}, {49.6576236,69.6523525}},
+  {{49.6576236,69.6523525}, {42.434629,77.4534313}, {29.3683981,94.6671928}},
+</div>
+
+<div id="quad23">
+{{x = 56.14128857485079, y = 57.037077517172825}, {x = 58.954858484191291, y = 61.706543802985237}, {x = 57.640240647662544, y = 59.524565264361243}}
+{{x = 59.551480981235549, y = 59.599865066889976}, {x = 56.880618274428095, y = 61.851273706132794}, {x = 49.657623623535379, y = 69.652352522894546}}
+</div>
+
+<div id="cubic27">
+{{x = 56.14128857485079, y = 57.037077517172825}, {x = 57.779490695232283, y = 59.900114769069532}, {x = 58.754163691193881, y = 61.229157895422141}, {x = 57.640240647662544, y = 59.524565264361243}}
+{{x = 56.14128857485079, y = 57.037077517172825}, {x = 58.954858484191291, y = 61.706543802985237}, {x = 57.640240647662544, y = 59.524565264361243}}
+</div>
+
+<div id="testCubic1">
+{{0, 0}, {0, 1}, {1, 1}, {1, 0}},
+{{1, 0}, {0, 0}, {0, 1}, {1, 1}},
+
+  {{0,0}, {0.0185185185,0.5}, {0.259259259,0.666666667}},
+  {{0.259259259,0.666666667}, {0.5,0.833333333}, {0.740740741,0.666666667}},
+  {{0.740740741,0.666666667}, {0.981481481,0.5}, {1,0}},
+
+  {{1,0}, {0.5,0.0185185185}, {0.333333333,0.259259259}},
+  {{0.333333333,0.259259259}, {0.166666667,0.5}, {0.333333333,0.740740741}},
+  {{0.333333333,0.740740741}, {0.5,0.981481481}, {1,1}},
+</div>
+
+<div id="testCubic1a">
+{{x = 0.30075438676757493, y = 0.69070348972827045}, {x = 0.30339450221247349, y = 0.69543451478800855}, {x = 0.30613761677734441, y = 0.7001387457168422}, {x = 0.30898373046218741, y = 0.70481409186990207}}
+{{x = 0.29518590813009821, y = 0.69101626953781281}, {x = 0.29986125428315819, y = 0.69386238322265548}, {x = 0.30456548521199123, y = 0.69660549778752689}, {x = 0.30929651027172955, y = 0.69924561323242507}}
+</div>
+
+<div id="testCubic1b">
+{{x = 0.3039751936710845, y = 0.69622610811401087}, {x = 0.3037698832307662, y = 0.69610758676672113}}
+{{x = 0.3037698832307662, y = 0.69610758676672113}, {x = 0.30387252963474076, y = 0.69616688005807803}}
+{{x = 0.30387252963474076, y = 0.69616688005807803}, {x = 0.3039751936710845, y = 0.69622610811401087}}
+</div>
+
 </div>
 
 <script type="text/javascript">
 
 var testDivs = [
+    testCubic1b,
+    testCubic1a,
+    testCubic1,
+    cubic27,
+    cubic26,
+    quad23,
+    cubic25,
     quad22,
     cubic24,
     quad21,
@@ -1857,8 +1928,7 @@
 var ticks = 10;
 var at_x = 13 + 0.5;
 var at_y = 23 + 0.5;
-var init_decimal_places = 1; // make this 3 to show more precision
-var decimal_places;
+var decimal_places = 3;
 var tests = [];
 var testTitles = [];
 var testIndex = 0;
@@ -1869,6 +1939,7 @@
 var drawCubics = true;
 var drawQuads = true;
 var drawControlLines = true;
+var xmin, xmax, ymin, ymax;
 
 function parse(test, title) {
     var curveStrs = test.split("{{");
@@ -1900,10 +1971,10 @@
     canvas.width = window.innerWidth - at_x;
     canvas.height = window.innerHeight - at_y;
     ctx = canvas.getContext('2d');
-    var xmin = Infinity;
-    var xmax = -Infinity;
-    var ymin = Infinity;
-    var ymax = -Infinity;
+    xmin = Infinity;
+    xmax = -Infinity;
+    ymin = Infinity;
+    ymax = -Infinity;
     for (var curves in test) {
         var curve = test[curves];
         var last = curve.length;
@@ -1923,14 +1994,18 @@
     while (testW * subscale > 10 && testH * subscale > 10) {
         subscale /= 10;
     }
+    calcFromScale();
+}
+
+function calcFromScale() {
     xStart = Math.floor(xmin * subscale) / subscale;
     yStart = Math.floor(ymin * subscale) / subscale;
     var xEnd = Math.ceil(xmin * subscale) / subscale;
     var yEnd = Math.ceil(ymin * subscale) / subscale;
     var cCelsW = Math.floor(ctx.canvas.width / 10);
     var cCelsH = Math.floor(ctx.canvas.height / 10);
-    testW = xEnd - xStart;
-    testH = yEnd - yStart; 
+    var testW = xEnd - xStart;
+    var testH = yEnd - yStart; 
     var scaleWH = 1;
     while (cCelsW > testW * scaleWH * 10 && cCelsH > testH * scaleWH * 10) {
         scaleWH *= 10;
@@ -2009,6 +2084,10 @@
         ctx.beginPath();
         ctx.moveTo(xoffset + curve[0] * unit, yoffset + curve[1] * unit);
         switch (curve.length) {
+            case 4:
+                ctx.lineTo(
+                    xoffset + curve[2] * unit, yoffset + curve[3] * unit);
+                break;
             case 6:
                 ctx.quadraticCurveTo(
                     xoffset + curve[2] * unit, yoffset + curve[3] * unit,
@@ -2023,7 +2102,7 @@
         }
         if (curves == 2) ctx.strokeStyle = curves ? "red" : "blue";
         ctx.stroke();
-        if (drawControlLines) {
+        if (drawControlLines && curve.length >= 6) {
             ctx.strokeStyle = "rgba(0,0,0, 0.3)";
             ctx.beginPath();
             ctx.moveTo(xoffset + curve[0] * unit, yoffset + curve[1] * unit);
@@ -2037,6 +2116,12 @@
             var x, y;
             var t = curveT;
             switch (curve.length) {
+                case 4:
+                    var a = 1 - t;
+                    var b = t;
+                    x = a * curve[0] + b * curve[2];
+                    y = a * curve[1] + b * curve[3];
+                    break;
                 case 6:
                     var one_t = 1 - t;
                     var a = one_t * one_t;
@@ -2058,7 +2143,7 @@
                     break;
             }
             drawPoint(x, y, xoffset, yoffset, unit);
-            var num = curveT.toFixed(3);
+            var num = curveT.toFixed(decimal_places);
             ctx.beginPath();
             ctx.rect(200,10,200,10);
             ctx.fillStyle="white";
@@ -2106,6 +2191,17 @@
         drawCubics ^= true;
         redraw();
         break;
+    case 'd':
+        decimal_places++;
+        redraw();
+        break;
+    case 'D':
+        decimal_places--;
+        if (decimal_places < 1) {
+            decimal_places = 1;
+        }
+        redraw();
+        break;
     case 'l':
         drawControlLines ^= true;
         redraw();
@@ -2135,6 +2231,18 @@
         drawQuads ^= true;
         redraw();
         break;
+    case '-':
+    case '_':
+        subscale /= 2;
+        calcFromScale();
+        redraw();
+        break;
+    case '+':
+    case '=':
+        subscale *= 2;
+        calcFromScale();
+        redraw();
+        break;
     }
 }
 
@@ -2159,7 +2267,7 @@
 
 function handleMouseOver() {
     calcXY();
-    var num = mouseX.toFixed(3) + ", " + mouseY.toFixed(3);
+    var num = mouseX.toFixed(decimal_places) + ", " + mouseY.toFixed(decimal_places);
     ctx.beginPath();
     ctx.rect(30,10,200,10);
     ctx.fillStyle="white";