shape ops work in progress

git-svn-id: http://skia.googlecode.com/svn/trunk@7978 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/experimental/Intersection/as.htm b/experimental/Intersection/as.htm
index c8a50bb..e1efc3d 100644
--- a/experimental/Intersection/as.htm
+++ b/experimental/Intersection/as.htm
@@ -2,227 +2,235 @@
 <head>
 <div style="height:0">
 
-<div id="cubicOp25i">
-debugShowActiveSpans id=1 (0,1 2,4 5,0 3,2) t=0.466666667 (2.84355545,1.9478519) tEnd=0.605057566 other=2 otherT=0.0521481481 otherIndex=1 windSum=-1 windValue=1 oppValue=0
-debugShowActiveSpans id=2 (3,2 0,1) t=0.0521481481 (2.84355545,1.9478519) tEnd=0.377811276 other=1 otherT=0.466666667 otherIndex=2 windSum=1 windValue=1 oppValue=0
-</div>
-
-<div id="cubicOp19i">
-debugShowActiveSpans id=3 (1,2 2,6 2,0 1,0) t=0 (1,2) tEnd=0.578464835 other=4 otherT=1 otherIndex=2 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 2,6 2,0 1,0) t=0.578464835 (1.73152983,2) tEnd=0.692069746 other=2 otherT=0.711411698 otherIndex=1 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 2,6 2,0 1,0) t=0.692069746 (1.63932765,1.25154662) tEnd=1 other=1 otherT=0.522705723 otherIndex=2 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=4 (1,0 1,2) t=0 (1,0) tEnd=0.637627564 other=3 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=4 (1,0 1,2) t=0.637627564 (1,1.27525508) tEnd=1 other=1 otherT=0.40824829 otherIndex=1 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,2 0,0.5 6,2) t=0 (0,2) tEnd=0.40824829 other=2 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,2 0,0.5 6,2) t=0.40824829 (1,1.27525508) tEnd=0.522705723 other=4 otherT=0.637627564 otherIndex=1 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,2 0,0.5 6,2) t=0.522705723 (1.63932765,1.25154662) tEnd=1 other=3 otherT=0.692069746 otherIndex=3 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=2 (6,2 0,2) t=0 (6,2) tEnd=0.711411698 other=1 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=2 (6,2 0,2) t=0.711411698 (1.73152983,2) tEnd=0.833333333 other=3 otherT=0.578464835 otherIndex=2 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=2 (6,2 0,2) t=0.833333333 (1,2) tEnd=1 other=3 otherT=0 otherIndex=1 windSum=? windValue=1 oppValue=0
-</div>
-
-<div id="cubicOp28u">
-debugShowActiveSpans id=3 (0,6 2,3 1,0 4,1) t=0 (0,6) tEnd=0.473902244 other=4 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=3 (0,6 2,3 1,0 4,1) t=0.473902244 (1.5671773,2.16060209) tEnd=0.57224743 other=1 otherT=0.287206281 otherIndex=1 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=3 (0,6 2,3 1,0 4,1) t=0.57224743 (1.79802597,1.59934199) tEnd=1 other=2 otherT=0.400657994 otherIndex=2 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=4 (4,1 0,6) t=0 (4,1) tEnd=0.13678207 other=3 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=4 (4,1 0,6) t=0.13678207 (3.4528718,1.68391037) tEnd=0.145041093 other=1 otherT=0.583645693 otherIndex=3 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=4 (4,1 0,6) t=0.145041093 (3.41983557,1.72520542) tEnd=1 other=1 otherT=0.945703361 otherIndex=6 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0 (0,1) tEnd=0.287206281 other=2 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0.287206281 (1.5671773,2.16060209) tEnd=0.470588235 other=3 otherT=0.473902244 otherIndex=1 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0.470588235 (2.81864452,1.93954813) tEnd=0.583645693 other=2 otherT=0.0604518624 otherIndex=1 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0.583645693 (3.4528718,1.68391037) tEnd=0.614942976 other=4 otherT=0.13678207 otherIndex=1 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0.614942976 (3.59216309,1.61630249) tEnd=0.916307024 other=1 otherT=0.916307024 otherIndex=5 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0.916307024 (3.59216309,1.61630249) tEnd=0.945703361 other=1 otherT=0.614942976 otherIndex=4 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0.945703361 (3.41983557,1.72520542) tEnd=1 other=4 otherT=0.145041093 otherIndex=2 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=2 (3,2 0,1) t=0 (3,2) tEnd=0.0604518624 other=1 otherT=1 otherIndex=7 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=2 (3,2 0,1) t=0.0604518624 (2.81864452,1.93954813) tEnd=0.400657994 other=1 otherT=0.470588235 otherIndex=2 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=2 (3,2 0,1) t=0.400657994 (1.79802597,1.59934199) tEnd=1 other=3 otherT=0.57224743 otherIndex=2 windSum=? windValue=1 oppValue=0
-</div>
-
-<div id="cubicOp31d">
-debugShowActiveSpans id=1 (0,2 0,3 2,1 4,0) t=0 (0,2) tEnd=0.5 other=2 otherT=1 otherIndex=3 windSum=1 windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,2 0,3 2,1 4,0) t=0.5 (1.25,1.75) tEnd=1 other=4 otherT=0.875 otherIndex=2 windSum=1 windValue=1 oppValue=0
-debugShowActiveSpans id=2 (4,0 0,2) t=0 (4,0) tEnd=0.5 other=1 otherT=1 otherIndex=3 windSum=1 windValue=1 oppValue=0
-debugShowActiveSpans id=2 (4,0 0,2) t=0.586298186 (1.65480721,1.17259634) tEnd=1 other=3 otherT=0.622399169 otherIndex=3 windSum=1 windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 0,4 2,0 3,0) t=0 (1,2) tEnd=0.5 other=4 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 0,4 2,0 3,0) t=0.500000008 (1.25,1.75) tEnd=0.622399169 other=1 otherT=0.5 otherIndex=1 windSum=-1 windValue=1 oppValue=0
-debugShowActiveSpans id=4 (3,0 1,2) t=0.5 (2,1) tEnd=0.875 other=2 otherT=0.5 otherIndex=1 windSum=-1 windValue=1 oppValue=0
-debugShowActiveSpans id=4 (3,0 1,2) t=0.875 (1.25,1.75) tEnd=1 other=1 otherT=0.5 otherIndex=2 windSum=? windValue=1 oppValue=0
-</div>
-
-<div id="cubicOp31da">
-debugShowActiveSpans id=1 (0,2 0,3 2,1 4,0) t=0 (0,2) tEnd=0.5 other=2 otherT=1 otherIndex=3 windSum=1 windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,2 0,3 2,1 4,0) t=0.5 (1.25,1.75) tEnd=1 other=4 otherT=0.875 otherIndex=2 windSum=1 windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 0,4 2,0 3,0) t=0 (1,2) tEnd=0.5 other=4 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 0,4 2,0 3,0) t=0.500000008 (1.25,1.75) tEnd=0.622399169 other=1 otherT=0.5 otherIndex=1 windSum=-1 windValue=1 oppValue=0
-debugShowActiveSpans id=4 (3,0 1,2) t=0.5 (2,1) tEnd=0.875 other=2 otherT=0.5 otherIndex=1 windSum=-1 windValue=1 oppValue=0
-debugShowActiveSpans id=4 (3,0 1,2) t=0.875 (1.25,1.75) tEnd=1 other=1 otherT=0.5 otherIndex=2 windSum=? windValue=1 oppValue=0
-</div>
-
-<div id="cubicOp35d">
-  SimplifyNew_Test [cubicOp35d]
-debugShowCubicIntersection no self intersect {{0,1}, {1,5}, {2,1}, {4,0}}
-debugShowCubicLineIntersection wtTs[0]=0 {{0,1}, {1,5}, {2,1}, {4,0}} {{0,1}} wtTs[1]=1 {{4,0}} wnTs[0]=1 {{4,0}, {0,1}} wnTs[1]=0
-debugShowCubicIntersection wtTs[0]=0.210357794 {{0,1}, {1,5}, {2,1}, {4,0}} {{0.64038179843233178,2.5646764769093426}} wtTs[1]=0.788675135 {{2.8565880156561105,0.93208711896642604}} wnTs[0]=0.223476 {{1,2}, {0,4}, {1,0}, {5,1}} wnTs[1]=0.788675135
-debugShowCubicLineIntersection wtTs[0]=0.646900486 {{0,1}, {1,5}, {2,1}, {4,0}} {{2.2114165293341985,1.6971458676664504}} wnTs[0]=0.697146 {{5,1}, {1,2}}
-debugShowCubicLineIntersection no intersect {{1,2}, {0,4}, {1,0}, {5,1}} {{4,0}, {0,1}}
-debugShowLineIntersection no intersect {{4,0}, {0,1}} {{5,1}, {1,2}}
-debugShowCubicIntersection wtTs[0]=0.002763735 {{1,2}, {0,4}, {1,0}, {5,1}} {{0.9917546455060533,2.0164451540317003}} wtTs[1]=0.461521979
-debugShowCubicLineIntersection wtTs[0]=0 {{1,2}, {0,4}, {1,0}, {5,1}} {{1,2}} wtTs[1]=0.466666667 {{1.0082962962962965,1.9979259259259259}} wtTs[2]=1 {{5,1}} wnTs[0]=1 {{5,1}, {1,2}} wnTs[1]=0.997925926 wnTs[2]=0
-debugShowActiveSpans id=1 (0,1 1,5 2,1 4,0) t=0 (0,1) tEnd=0.210357794 other=2 otherT=1 otherIndex=1 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,1 1,5 2,1 4,0) t=0.210357794 (0.640381813,2.56467652) tEnd=0.646900486 other=3 otherT=0.223476406 otherIndex=2 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,1 1,5 2,1 4,0) t=0.646900486 (2.21141648,1.69714582) tEnd=0.788675135 other=4 otherT=0.697145868 otherIndex=1 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=1 (0,1 1,5 2,1 4,0) t=0.788675135 (2.85658813,0.932087123) tEnd=1 other=3 otherT=0.788675135 otherIndex=5 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=2 (4,0 0,1) t=0 (4,0) tEnd=1 other=1 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 0,4 1,0 5,1) t=0 (1,2) tEnd=0.002763735 other=4 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 0,4 1,0 5,1) t=0.002763735 (0.991754651,2.01644516) tEnd=0.223476406 other=3 otherT=0.461521979 otherIndex=3 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 0,4 1,0 5,1) t=0.223476406 (0.640381813,2.56467652) tEnd=0.461521979 other=1 otherT=0.210357794 otherIndex=1 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 0,4 1,0 5,1) t=0.461521979 (0.991754651,2.01644516) tEnd=0.466666667 other=3 otherT=0.002763735 otherIndex=1 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 0,4 1,0 5,1) t=0.466666667 (1.00829625,1.99792588) tEnd=0.788675135 other=4 otherT=0.997925926 otherIndex=2 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 0,4 1,0 5,1) t=0.788675135 (2.85658813,0.932087123) tEnd=1 other=1 otherT=0.788675135 otherIndex=3 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=4 (5,1 1,2) t=0 (5,1) tEnd=0.697145868 other=3 otherT=1 otherIndex=6 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=4 (5,1 1,2) t=0.697145868 (2.21141648,1.69714582) tEnd=0.997925926 other=1 otherT=0.646900486 otherIndex=2 windSum=? windValue=1 oppValue=0
-debugShowActiveSpans id=4 (5,1 1,2) t=0.997925926 (1.00829625,1.99792588) tEnd=1 other=3 otherT=0.466666667 otherIndex=4 windSum=? windValue=1 oppValue=0
-findTop debugShowSort contourWinding=0 oppContourWinding=0 sign=-1
-debugShowSort [0] id=2 line start=0 (4,0) end=1 (0,1) sign=-1 windValue=1 windSum=? 0->1 (max=1) done=0 tiny=0 opp=0
-debugShowSort [1] id=1 cubic start=4 (4,0) end=3 (2.85658813,0.932087123) sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=0
-markWinding id=2 (4,0 0,1) t=0 [0] (4,0) newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1
-markWinding id=1 (0,1 1,5 2,1 4,0) t=0.788675135 [3] (2.85658813,0.932087123) newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1
-markWinding id=2 (4,0 0,1) t=0 [0] (4,0) newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1
-markWinding id=1 (0,1 1,5 2,1 4,0) t=0 [0] (0,1) newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1
-activeOp op=diff miFrom=1 miTo=0 suFrom=0 suTo=0 result=1
+<div id="cubicOp36u">
+  SimplifyNew_Test [cubicOp36u]
+{{0,1}, {1,6}, {2,0}, {5,1}},
+{{5,1}, {0,1}},
+op union
+{{0,2}, {1,5}, {1,0}, {6,1}},
+{{6,1}, {0,2}},
+debugShowCubicIntersection no self intersect {{0,2}, {1,5}, {1,0}, {6,1}}
+debugShowCubicLineIntersection wtTs[0]=0 {{0,2}, {1,5}, {1,0}, {6,1}} {{0,2}} wtTs[1]=0.633333333 {{2.2208888888888882,1.6298518518518521}} wtTs[2]=1 {{6,1}} wnTs[0]=1 {{6,1}, {0,2}} wnTs[1]=0.629851852 wnTs[2]=0
+debugShowCubicIntersection wtTs[0]=0.281761651 {{0,2}, {1,5}, {1,0}, {6,1}} {{0.74132978521392334,2.9436691246202122}} wtTs[1]=0.83051493 {{3.8593908381032738,0.94043932231067462}} wtTs[2]=0.830515061 {{3.8593922073023155,0.94043907360367252}} wtTs[3]=0.867315861 {{4.2597986321159249,0.88613622701319239}} wtTs[4]=0.867316009 {{4.2598003089230945,0.88613607359480184}} wnTs[0]=0.23811 {{0,1}, {1,6}, {2,0}, {5,1}} wnTs[1]=0.860977989 wnTs[2]=0.860978176 wnTs[3]=0.912837717 wnTs[4]=0.912837923
+debugShowCubicLineIntersection wtTs[0]=0.803214143 {{0,2}, {1,5}, {1,0}, {6,1}} {{3.5833594368204942,1}} wnTs[0]=0.283328 {{5,1}, {0,1}}
+debugShowCubicLineIntersection wtTs[0]=0.0764226429 {{0,1}, {1,6}, {2,0}, {5,1}} {{0.23016060940409022,1.9616398984326517}} wtTs[1]=0.691654855 {{2.7367211708698314,1.543879804855028}} wnTs[0]=0.96164 {{6,1}, {0,2}} wnTs[1]=0.543879805
+debugShowLineIntersection no intersect {{6,1}, {0,2}} {{5,1}, {0,1}}
+debugShowCubicIntersection no self intersect {{0,1}, {1,6}, {2,0}, {5,1}}
+debugShowCubicLineIntersection wtTs[0]=0 {{0,1}, {1,6}, {2,0}, {5,1}} {{0,1}} wtTs[1]=0.833333333 {{3.6574074074074132,0.99999999999999789}} wtTs[2]=1 {{5,1}} wnTs[0]=1 {{5,1}, {0,1}} wnTs[1]=0.268518519 wnTs[2]=0
+debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0 (0,2) tEnd=0.281761651 other=4 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.281761651 (0.741329789,2.94366908) tEnd=0.633333333 other=1 otherT=0.238109917 otherIndex=2 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.633333333 (2.22088885,1.62985182) tEnd=0.803214143 other=4 otherT=0.629851852 otherIndex=2 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.803214143 (3.58335948,1) tEnd=0.83051493 other=2 otherT=0.283328113 otherIndex=2 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.83051493 (3.85939074,0.940439343) tEnd=0.830515061 other=1 otherT=0.860977989 otherIndex=5 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.830515061 (3.85939217,0.940439045) tEnd=0.867315861 other=1 otherT=0.860978176 otherIndex=6 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.867315861 (4.25979853,0.886136234) tEnd=0.867316009 other=1 otherT=0.912837717 otherIndex=7 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.867316009 (4.25980043,0.886136055) tEnd=1 other=1 otherT=0.912837923 otherIndex=8 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=4 (6,1 0,2) t=0 (6,1) tEnd=0.543879805 other=3 otherT=1 otherIndex=8 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=4 (6,1 0,2) t=0.543879805 (2.73672128,1.54387975) tEnd=0.629851852 other=1 otherT=0.691654855 otherIndex=3 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=4 (6,1 0,2) t=0.629851852 (2.22088885,1.62985182) tEnd=0.961639898 other=3 otherT=0.633333333 otherIndex=2 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=4 (6,1 0,2) t=0.961639898 (0.230160609,1.96163988) tEnd=1 other=1 otherT=0.0764226429 otherIndex=1 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0 (0,1) tEnd=0.0764226429 other=2 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.0764226429 (0.230160609,1.96163988) tEnd=0.238109917 other=4 otherT=0.961639898 otherIndex=3 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.238109917 (0.741329789,2.94366908) tEnd=0.691654855 other=3 otherT=0.281761651 otherIndex=1 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.691654855 (2.73672128,1.54387975) tEnd=0.833333333 other=4 otherT=0.543879805 otherIndex=1 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.833333333 (3.65740752,1) tEnd=0.860977989 other=2 otherT=0.268518519 otherIndex=1 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.860977989 (3.85939074,0.940439343) tEnd=0.860978176 other=3 otherT=0.83051493 otherIndex=4 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.860978176 (3.85939217,0.940439045) tEnd=0.912837717 other=3 otherT=0.830515061 otherIndex=5 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.912837717 (4.25979853,0.886136234) tEnd=0.912837923 other=3 otherT=0.867315861 otherIndex=6 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.912837923 (4.25980043,0.886136055) tEnd=1 other=3 otherT=0.867316009 otherIndex=7 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=2 (5,1 0,1) t=0 (5,1) tEnd=0.268518519 other=1 otherT=1 otherIndex=9 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=2 (5,1 0,1) t=0.268518519 (3.65740752,1) tEnd=0.283328113 other=1 otherT=0.833333333 otherIndex=4 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=2 (5,1 0,1) t=0.283328113 (3.58335948,1) tEnd=1 other=3 otherT=0.803214143 otherIndex=3 windSum=? windValue=1 oppValue=0
+findTop debugShowSort contourWinding=0 oppContourWinding=0 sign=1
+debugShowSort [0] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=1 tEnd=0.867316009 sign=1 windValue=1 windSum=? 0->-1 (max=-1) done=0 tiny=0 opp=0
+debugShowSort [1] {{6,1}, {0,2}} tStart=0 tEnd=0.543879805 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=0
+findTop xyE=(6,1) xyS=(4.25980043,0.886136055)
+findTop dxyE=(15,3) dxyS=(11.3363714,-1.03721189) cross=-49.5672913 bumpsUp=true
+markWinding id=3 (0,2 1,5 1,0 6,1) t=0.867316009 [7] (4.25980043,0.886136055) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1
+markWinding id=4 (6,1 0,2) t=0 [0] (6,1) tEnd=0.543879805 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1
+markWinding id=3 (0,2 1,5 1,0 6,1) t=0.867316009 [7] (4.25980043,0.886136055) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1
+activeOp op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1
 findNextOp simple
-markDoneBinary id=2 (4,0 0,1) t=0 [0] (4,0) newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1
-bridgeOp current id=2 from=(0,1) to=(4,0)
-findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=-1
-debugShowSort [1] id=1 cubic start=3 (2.85658813,0.932087123) end=4 (4,0) sign=-1 windValue=1 windSum=1 0->1 (max=1) done=0 tiny=0 opp=0
-debugShowSort [2] id=3 cubic start=5 (2.85658813,0.932087123) end=4 (1.00829625,1.99792588) sign=1 windValue=1 windSum=? 0->-1 (max=-1) done=0 tiny=0 opp=1
-debugShowSort [3] id=1 cubic start=3 (2.85658813,0.932087123) end=2 (2.21141648,1.69714582) sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=0
-debugShowSort [0] id=3 cubic start=5 (2.85658813,0.932087123) end=6 (5,1) sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=1
-findNextOp firstIndex=[1] sign=-1
-activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
-markWinding id=3 (1,2 0,4 1,0 5,1) t=0.466666667 [4] (1.00829625,1.99792588) newWindSum=-1 newOppSum=1 oppSum=? windSum=? windValue=1
-findNextOp chase.append id=3
-activeOp op=diff miFrom=1 miTo=0 suFrom=1 suTo=1 result=0
-markDoneBinary id=1 (0,1 1,5 2,1 4,0) t=0.646900486 [2] (2.21141648,1.69714582) newWindSum=1 newOppSum=-1 oppSum=? windSum=? windValue=1
-findNextOp chase.append id=1
-activeOp op=diff miFrom=0 miTo=0 suFrom=1 suTo=0 result=0
-markDoneBinary id=3 (1,2 0,4 1,0 5,1) t=0.788675135 [5] (2.85658813,0.932087123) newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1
-markDoneBinary id=4 (5,1 1,2) t=0 [0] (5,1) newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1
-findNextOp chase.append id=4
-markDoneBinary id=1 (0,1 1,5 2,1 4,0) t=0.788675135 [3] (2.85658813,0.932087123) newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1
-findNextOp from:[1] to:[3] start=5 end=4
-bridgeOp current id=1 from=(4,0) to=(2.85658813,0.932087123)
-path.moveTo(0,1);
-path.lineTo(4,0);
-path.cubicTo(3.57735038,0.211324871, 3.1993587,0.556624353, 2.85658813,0.932087123);
-findNextOp debugShowSort contourWinding=-1 oppContourWinding=1 sign=-1
-debugShowSort [1] id=3 cubic start=4 (1.00829625,1.99792588) end=5 (2.85658813,0.932087123) sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=0 tiny=0 opp=0
-debugShowSort [2] id=4 line start=2 (1.00829625,1.99792588) end=3 (1,2) sign=-1 windValue=1 windSum=? 0->1 (max=1) done=0 tiny=0 opp=0
-debugShowSort [3] id=3 cubic start=4 (1.00829625,1.99792588) end=3 (0.991754651,2.01644516) sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=0
-debugShowSort [0] id=4 line start=2 (1.00829625,1.99792588) end=1 (2.21141648,1.69714582) sign=1 windValue=1 windSum=? 0->-1 (max=-1) done=0 tiny=0 opp=0
-findNextOp firstIndex=[1] sign=-1
-activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
-markWinding id=4 (5,1 1,2) t=0.997925926 [2] (1.00829625,1.99792588) newWindSum=1 newOppSum=1 oppSum=? windSum=? windValue=1
-markWinding id=3 (1,2 0,4 1,0 5,1) t=0 [0] (1,2) newWindSum=1 newOppSum=1 oppSum=? windSum=? windValue=1
-findNextOp chase.append id=3
-activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
-markWinding id=3 (1,2 0,4 1,0 5,1) t=0.461521979 [3] (0.991754651,2.01644516) newWindSum=1 newOppSum=1 oppSum=? windSum=? windValue=1
-findNextOp chase.append id=3
-activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
-markWinding id=4 (5,1 1,2) t=0.697145868 [1] (2.21141648,1.69714582) newWindSum=-1 newOppSum=1 oppSum=? windSum=? windValue=1
-findNextOp chase.append id=4
-markDoneBinary id=3 (1,2 0,4 1,0 5,1) t=0.466666667 [4] (1.00829625,1.99792588) newWindSum=-1 newOppSum=1 oppSum=1 windSum=-1 windValue=1
-findNextOp from:[3] to:[4] start=2 end=3
-bridgeOp current id=3 from=(2.85658813,0.932087123) to=(1.00829625,1.99792588)
-path.cubicTo(1.96246409,1.13237906, 1.35749662,1.61008465, 1.00829625,1.99792588);
-findNextOp simple
-markDoneBinary id=4 (5,1 1,2) t=0.997925926 [2] (1.00829625,1.99792588) newWindSum=1 newOppSum=1 oppSum=1 windSum=1 windValue=1
-bridgeOp current id=4 from=(1.00829625,1.99792588) to=(1,2)
-Program received signal:  “EXC_BAD_ACCESS”.
-findNextOp debugShowSort contourWinding=1 oppContourWinding=1 sign=1
-debugShowSort [1] id=3 cubic start=1 (0.991754651,2.01644516) end=0 (1,2) sign=1 windValue=1 windSum=1 1->0 (max=1) done=0 tiny=0 opp=0
-debugShowSort [2] id=3 cubic start=3 (0.991754651,2.01644516) end=2 (0.640381813,2.56467652) sign=1 windValue=1 windSum=? 0->-1 (max=-1) done=0 tiny=0 opp=0
-debugShowSort [3] id=3 cubic start=1 (0.991754651,2.01644516) end=2 (0.640381813,2.56467652) sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=0
-debugShowSort [0] id=3 cubic start=3 (0.991754651,2.01644516) end=4 (1.00829625,1.99792588) sign=-1 windValue=1 windSum=1 0->1 (max=1) done=0 tiny=0 opp=0
-findNextOp firstIndex=[1] sign=1
-activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
-markWinding id=3 (1,2 0,4 1,0 5,1) t=0.223476406 [2] (0.640381813,2.56467652) newWindSum=-1 newOppSum=1 oppSum=? windSum=? windValue=1
-findNextOp chase.append id=3
-activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
-markWinding id=3 (1,2 0,4 1,0 5,1) t=0.002763735 [1] (0.991754651,2.01644516) newWindSum=-1 newOppSum=1 oppSum=? windSum=? windValue=1
-findNextOp chase.append id=3
-activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
-markDoneBinary id=3 (1,2 0,4 1,0 5,1) t=0 [0] (1,2) newWindSum=1 newOppSum=1 oppSum=1 windSum=1 windValue=1
-findNextOp from:[3] to:[3] start=3 end=2
-bridgeOp current id=3 from=(1,2) to=(0.991754651,2.01644516)
-path.lineTo(1,2);
-path.cubicTo(0.997236252,2.0055275, 0.994487822,2.01100922, 0.991754651,2.01644516);
-findNextOp debugShowSort contourWinding=-1 oppContourWinding=1 sign=-1
-debugShowSort [0] id=3 cubic start=2 (0.640381813,2.56467652) end=3 (0.991754651,2.01644516) sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=0 tiny=0 opp=0
-debugShowSort [1] id=1 cubic start=1 (0.640381813,2.56467652) end=0 (0,1) sign=1 windValue=1 windSum=1 1->0 (max=1) done=0 tiny=0 opp=1
-debugShowSort [2] id=3 cubic start=2 (0.640381813,2.56467652) end=1 (0.991754651,2.01644516) sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=0 tiny=0 opp=0
-debugShowSort [3] id=1 cubic start=1 (0.640381813,2.56467652) end=2 (2.21141648,1.69714582) sign=-1 windValue=1 windSum=? 0->1 (max=1) done=0 tiny=0 opp=1
-findNextOp firstIndex=[0] sign=-1
-activeOp op=diff miFrom=1 miTo=0 suFrom=0 suTo=0 result=1
-activeOp op=diff miFrom=0 miTo=0 suFrom=0 suTo=1 result=0
-activeOp op=diff miFrom=0 miTo=1 suFrom=1 suTo=1 result=0
-markDoneBinary id=1 (0,1 1,5 2,1 4,0) t=0.210357794 [1] (0.640381813,2.56467652) newWindSum=1 newOppSum=-1 oppSum=? windSum=? windValue=1
-findNextOp chase.append id=1
-markDoneBinary id=3 (1,2 0,4 1,0 5,1) t=0.223476406 [2] (0.640381813,2.56467652) newWindSum=-1 newOppSum=1 oppSum=1 windSum=-1 windValue=1
-findNextOp from:[3] to:[1] start=1 end=0
-bridgeOp current id=3 from=(0.991754651,2.01644516) to=(0.640381813,2.56467652)
-path.cubicTo(0.739642859,2.30096555, 0.627014875,2.53316927, 0.640381813,2.56467652);
-findNextOp simple
-markDoneBinary id=1 (0,1 1,5 2,1 4,0) t=0 [0] (0,1) newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1
-bridgeOp current id=1 from=(0.640381813,2.56467652) to=(0,1)
-path.cubicTo(0.42071557,2.32885909, 0.2103578,1.84143114, 0,1);
-path.close();
-debugShowActiveSpans id=3 (1,2 0,4 1,0 5,1) t=0.002763735 (0.991754651,2.01644516) tEnd=0.223476406 other=3 otherT=0.461521979 otherIndex=3 windSum=-1 windValue=1 oppValue=0
-debugShowActiveSpans id=3 (1,2 0,4 1,0 5,1) t=0.461521979 (0.991754651,2.01644516) tEnd=0.466666667 other=3 otherT=0.002763735 otherIndex=1 windSum=1 windValue=1 oppValue=0
-debugShowActiveSpans id=4 (5,1 1,2) t=0.697145868 (2.21141648,1.69714582) tEnd=0.997925926 other=1 otherT=0.646900486 otherIndex=2 windSum=-1 windValue=1 oppValue=0
-activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
-findNextOp debugShowSort contourWinding=0 oppContourWinding=1 sign=1
-debugShowSort [0] id=4 line start=2 (1.00829625,1.99792588) end=1 (2.21141648,1.69714582) sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=0 tiny=0 opp=0
-debugShowSort [1] id=3 cubic start=4 (1.00829625,1.99792588) end=5 (2.85658813,0.932087123) sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=1 tiny=0 opp=0
-debugShowSort [2] id=4 line start=2 (1.00829625,1.99792588) end=3 (1,2) sign=-1 windValue=1 windSum=1 0->1 (max=1) done=1 tiny=0 opp=0
-debugShowSort [3] id=3 cubic start=4 (1.00829625,1.99792588) end=3 (0.991754651,2.01644516) sign=1 windValue=1 windSum=1 1->0 (max=1) done=0 tiny=0 opp=0
+markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.867316009 [7] (4.25980043,0.886136055) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1
+bridgeOp current id=3 from=(4.25980043,0.886136055) to=(6,1)
+path.moveTo(4.25980043,0.886136055);
+path.cubicTo(4.76118517,0.840262294, 5.33658028,0.867316008, 6,1);
+findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=1
+debugShowSort [0] {{6,1}, {0,2}} tStart=0.543879805 tEnd=0 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=0 tiny=0 opp=0
+debugShowSort [1] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.691654855 tEnd=0.833333333 sign=-1 windValue=1 windSum=? 0->1 (max=1) done=0 tiny=0 opp=1
+debugShowSort [2] {{6,1}, {0,2}} tStart=0.543879805 tEnd=0.629851852 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=0
+debugShowSort [3] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.691654855 tEnd=0.238109917 sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=1
 findNextOp firstIndex=[0] sign=1
-activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
-activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
-activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
-markDoneBinary id=4 (5,1 1,2) t=0.697145868 [1] (2.21141648,1.69714582) newWindSum=-1 newOppSum=1 oppSum=1 windSum=-1 windValue=1
-findNextOp from:[4] to:[3] start=4 end=3
-bridgeOp current id=4 from=(2.21141648,1.69714582) to=(1.00829625,1.99792588)
-findNextOp debugShowSort contourWinding=0 oppContourWinding=1 sign=-1
-debugShowSort [0] id=3 cubic start=3 (0.991754651,2.01644516) end=4 (1.00829625,1.99792588) sign=-1 windValue=1 windSum=1 0->1 (max=1) done=0 tiny=0 opp=0
-debugShowSort [1] id=3 cubic start=1 (0.991754651,2.01644516) end=0 (1,2) sign=1 windValue=1 windSum=1 1->0 (max=1) done=1 tiny=0 opp=0
-debugShowSort [2] id=3 cubic start=3 (0.991754651,2.01644516) end=2 (0.640381813,2.56467652) sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=0
-debugShowSort [3] id=3 cubic start=1 (0.991754651,2.01644516) end=2 (0.640381813,2.56467652) sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=0 tiny=0 opp=0
-findNextOp firstIndex=[0] sign=-1
-activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
-activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
-activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
-markDoneBinary id=3 (1,2 0,4 1,0 5,1) t=0.461521979 [3] (0.991754651,2.01644516) newWindSum=1 newOppSum=1 oppSum=1 windSum=1 windValue=1
-findNextOp from:[3] to:[3] start=1 end=2
-bridgeOp current id=3 from=(1.00829625,1.99792588) to=(0.991754651,2.01644516)
-path.moveTo(2.21141648,1.69714582);
-path.lineTo(1.00829625,1.99792588);
-path.cubicTo(1.00271726,2.0041225, 0.99720329,2.01029587, 0.991754651,2.01644516);
-findNextOp debugShowSort contourWinding=0 oppContourWinding=1 sign=1
-debugShowSort [2] id=3 cubic start=2 (0.640381813,2.56467652) end=1 (0.991754651,2.01644516) sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=0 tiny=0 opp=0
-debugShowSort [3] id=1 cubic start=1 (0.640381813,2.56467652) end=2 (2.21141648,1.69714582) sign=-1 windValue=1 windSum=1 1->2 (max=2) done=1 tiny=0 opp=1
-debugShowSort [0] id=3 cubic start=2 (0.640381813,2.56467652) end=3 (0.991754651,2.01644516) sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=1 tiny=0 opp=0
-debugShowSort [1] id=1 cubic start=1 (0.640381813,2.56467652) end=0 (0,1) sign=1 windValue=1 windSum=1 2->1 (max=2) done=1 tiny=0 opp=1
+activeOp op=union miFrom=0 miTo=1 suFrom=1 suTo=1 result=0
+markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.691654855 [3] (2.73672128,1.54387975) tEnd=0.833333333 newWindSum=1 newOppSum=-1 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=1
+activeOp op=union miFrom=1 miTo=1 suFrom=1 suTo=0 result=0
+markDoneBinary id=4 (6,1 0,2) t=0.543879805 [1] (2.73672128,1.54387975) tEnd=0.629851852 newWindSum=-1 newOppSum=1 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=4
+activeOp op=union miFrom=1 miTo=0 suFrom=0 suTo=0 result=1
+markWinding id=1 (0,1 1,6 2,0 5,1) t=0.238109917 [2] (0.741329789,2.94366908) tEnd=0.691654855 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=1
+markDoneBinary id=4 (6,1 0,2Program received signal:  “EXC_BAD_ACCESS”.
+) t=0 [0] (6,1) tEnd=0.543879805 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1
+findNextOp from:[4] to:[1] start=3 end=2
+bridgeOp current id=4 from=(6,1) to=(2.73672128,1.54387975)
+findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=-1
+debugShowSort [3] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.238109917 tEnd=0.691654855 sign=-1 windValue=1 windSum=1 0->1 (max=1) done=0 tiny=0 opp=0
+debugShowSort [0] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.281761651 tEnd=0.633333333 sign=-1 windValue=1 windSum=? 0->1 (max=1) done=0 tiny=0 opp=1
+debugShowSort [1] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.238109917 tEnd=0.0764226429 sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=0
+debugShowSort [2] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.281761651 tEnd=0 sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=1
+findNextOp firstIndex=[3] sign=-1
+activeOp op=union miFrom=1 miTo=1 suFrom=0 suTo=1 result=0
+markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.281761651 [1] (0.741329789,2.94366908) tEnd=0.633333333 newWindSum=1 newOppSum=1 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=3
+activeOp op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0
+markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.0764226429 [1] (0.230160609,1.96163988) tEnd=0.238109917 newWindSum=1 newOppSum=1 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=1
+activeOp op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1
+markWinding id=3 (0,2 1,5 1,0 6,1) t=0 [0] (0,2) tEnd=0.281761651 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1
+markWinding id=4 (6,1 0,2) t=0.961639898 [3] (0.230160609,1.96163988) tEnd=1 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=4
+markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.238109917 [2] (0.741329789,2.94366908) tEnd=0.691654855 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1
+findNextOp from:[1] to:[3] start=1 end=0
+bridgeOp current id=1 from=(2.73672128,1.54387975) to=(0.741329789,2.94366908)
+path.lineTo(2.73672128,1.54387975);
+path.cubicTo(1.84923673,2.27202392, 1.2463032,3.29839373, 0.741329789,2.94366908);
+findNextOp simple
+markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0 [0] (0,2) tEnd=0.281761651 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1
+bridgeOp current id=3 from=(0.741329789,2.94366908) to=(0,2)
+path.cubicTo(0.484133661,3.05545282, 0.281761646,2.84528494, 0,2);
+findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=-1
+debugShowSort [2] {{6,1}, {0,2}} tStart=0.961639898 tEnd=1 sign=-1 windValue=1 windSum=1 0->1 (max=1) done=0 tiny=0 opp=0
+debugShowSort [3] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.0764226429 tEnd=0.238109917 sign=-1 windValue=1 windSum=1 0->1 (max=1) done=1 tiny=0 opp=1
+debugShowSort [0] {{6,1}, {0,2}} tStart=0.961639898 tEnd=0.629851852 sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=0
+debugShowSort [1] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.0764226429 tEnd=0 sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=1
+findNextOp firstIndex=[2] sign=-1
+activeOp op=union miFrom=0 miTo=1 suFrom=1 suTo=1 result=0
+activeOp op=union miFrom=1 miTo=1 suFrom=1 suTo=0 result=0
+markDoneBinary id=4 (6,1 0,2) t=0.629851852 [2] (2.22088885,1.62985182) tEnd=0.961639898 newWindSum=1 newOppSum=1 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=4
+activeOp op=union miFrom=1 miTo=0 suFrom=0 suTo=0 result=1
+markWinding id=1 (0,1 1,6 2,0 5,1) t=0 [0] (0,1) tEnd=0.0764226429 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1
+markWinding id=2 (5,1 0,1) t=0.283328113 [2] (3.58335948,1) tEnd=1 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=2
+markDoneBinary id=4 (6,1 0,2) t=0.961639898 [3] (0.230160609,1.96163988) tEnd=1 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1
+findNextOp from:[4] to:[1] start=1 end=0
+bridgeOp current id=4 from=(0,2) to=(0.230160609,1.96163988)
+findNextOp simple
+markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0 [0] (0,1) tEnd=0.0764226429 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1
+bridgeOp current id=1 from=(0.230160609,1.96163988) to=(0,1)
+path.lineTo(0.230160609,1.96163988);
+path.cubicTo(0.152845293,1.69998181, 0.0764226392,1.38211322, 0,1);
+findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=-1
+debugShowSort [1] {{5,1}, {0,1}} tStart=0.283328113 tEnd=1 sign=-1 windValue=1 windSum=1 0->1 (max=1) done=0 tiny=0 opp=0
+debugShowSort [2] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.803214143 tEnd=0.633333333 sign=1 windValue=1 windSum=? 0->-1 (max=-1) done=0 tiny=0 opp=1
+debugShowSort [3] {{5,1}, {0,1}} tStart=0.283328113 tEnd=0.268518519 sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=0
+debugShowSort [0] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.803214143 tEnd=0.83051493 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=1
+findNextOp firstIndex=[1] sign=-1
+activeOp op=union miFrom=1 miTo=1 suFrom=0 suTo=1 result=0
+markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.633333333 [2] (2.22088885,1.62985182) tEnd=0.803214143 newWindSum=-1 newOppSum=1 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=3
+activeOp op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0
+markDoneBinary id=2 (5,1 0,1) t=0.268518519 [1] (3.65740752,1) tEnd=0.283328113 newWindSum=1 newOppSum=-1 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=2
+activeOp op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1
+markWinding id=3 (0,2 1,5 1,0 6,1) t=0.803214143 [3] (3.58335948,1) tEnd=0.83051493 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=3
+markDoneBinary id=2 (5,1 0,1) t=0.283328113 [2] (3.58335948,1) tEnd=1 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1
+findNextOp from:[2] to:[3] start=3 end=4
+bridgeOp current id=2 from=(0,1) to=(3.58335948,1)
+findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=1
+debugShowSort [0] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.83051493 tEnd=0.803214143 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=0 tiny=0 opp=0
+debugShowSort [1] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.860977989 tEnd=0.833333333 sign=1 windValue=1 windSum=? 0->-1 (max=-1) done=0 tiny=0 opp=1
+debugShowSort [2] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.860977989 tEnd=0.860978176 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=1
+debugShowSort [3] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.83051493 tEnd=0.830515061 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=0
+findNextOp firstIndex=[0] sign=1
+activeOp op=union miFrom=0 miTo=1 suFrom=1 suTo=1 result=0
+markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.833333333 [4] (3.65740752,1) tEnd=0.860977989 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=1
+activeOp op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0
+markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.860977989 [5] (3.85939074,0.940439343) tEnd=0.860978176 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=1
+activeOp op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1
+markWinding id=3 (0,2 1,5 1,0 6,1) t=0.83051493 [4] (3.85939074,0.940439343) tEnd=0.830515061 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=3
+markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.803214143 [3] (3.58335948,1) tEnd=0.83051493 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1
+findNextOp from:[3] to:[3] start=4 end=5
+bridgeOp current id=3 from=(3.58335948,1) to=(3.85939074,0.940439343)
+path.lineTo(3.58335948,1);
+path.cubicTo(3.67248249,0.97763288, 3.76445246,0.957684338, 3.85939074,0.940439343);
+findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=1
+debugShowSort [2] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.830515061 tEnd=0.83051493 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=0 tiny=0 opp=0
+debugShowSort [3] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.860978176 tEnd=0.860977989 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=1
+debugShowSort [0] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.830515061 tEnd=0.867315861 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=0
+debugShowSort [1] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.860978176 tEnd=0.912837717 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=1
 findNextOp firstIndex=[2] sign=1
-activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=1 result=0
-activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
-activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=0 result=0
-markDoneBinary id=3 (1,2 0,4 1,0 5,1) t=0.002763735 [1] (0.991754651,2.01644516) newWindSum=-1 newOppSum=1 oppSum=1 windSum=-1 windValue=1
-findNextOp from:[3] to:[3] start=2 end=3
-bridgeOp current id=3 from=(0.991754651,2.01644516) to=(0.640381813,2.56467652)
-path.cubicTo(0.773483634,2.45056915, 0.652775407,2.59388947, 0.640381813,2.56467652);
+activeOp op=union miFrom=0 miTo=1 suFrom=1 suTo=1 result=0
+activeOp op=union miFrom=1 miTo=1 suFrom=1 suTo=0 result=0
+markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.830515061 [5] (3.85939217,0.940439045) tEnd=0.867315861 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=3
+activeOp op=union miFrom=1 miTo=0 suFrom=0 suTo=0 result=1
+markWinding id=1 (0,1 1,6 2,0 5,1) t=0.860978176 [6] (3.85939217,0.940439045) tEnd=0.912837717 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=1
+markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.83051493 [4] (3.85939074,0.940439343) tEnd=0.830515061 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1
+findNextOp from:[3] to:[1] start=6 end=7
+bridgeOp current id=3 from=(3.85939074,0.940439343) to=(3.85939217,0.940439045)
+path.cubicTo(3.85939145,0.940439224, 3.85939169,0.940439165, 3.85939217,0.940439045);
+findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=1
+debugShowSort [0] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.912837717 tEnd=0.860978176 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=0 tiny=0 opp=0
+debugShowSort [1] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.867315861 tEnd=0.830515061 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=1
+debugShowSort [2] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.912837717 tEnd=0.912837923 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=0
+debugShowSort [3] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.867315861 tEnd=0.867316009 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=1
+findNextOp firstIndex=[0] sign=1
+activeOp op=union miFrom=1 miTo=1 suFrom=0 suTo=1 result=0
+activeOp op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0
+markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.912837717 [7] (4.25979853,0.886136234) tEnd=0.912837923 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=1
+activeOp op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1
+markWinding id=3 (0,2 1,5 1,0 6,1) t=0.867315861 [6] (4.25979853,0.886136234) tEnd=0.867316009 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1
+findNextOp chase.append id=3
+markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.860978176 [6] (3.85939217,0.940439045) tEnd=0.912837717 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1
+findNextOp from:[1] to:[3] start=6 end=7
+bridgeOp current id=1 from=(3.85939217,0.940439045) to=(4.25979853,0.886136234)
+path.cubicTo(3.98813701,0.909405351, 4.12151289,0.890467525, 4.25980043,0.886136055);
+path.close();
+debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.867315861 (4.25979853,0.886136234) tEnd=0.867316009 other=1 otherT=0.912837717 otherIndex=7 windSum=-1 windValue=1 oppValue=0
+debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.912837923 (4.25980043,0.886136055) tEnd=1 other=3 otherT=0.867316009 otherIndex=7 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=2 (5,1 0,1) t=0 (5,1) tEnd=0.268518519 other=1 otherT=1 otherIndex=9 windSum=? windValue=1 oppValue=0
+activeOp op=union miFrom=0 miTo=0 suFrom=0 suTo=1 result=1
+findNextOp debugShowSort contourWinding=-1 oppContourWinding=0 sign=-1
+debugShowSort [3] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.867315861 tEnd=0.867316009 sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=0 tiny=0 opp=0
+debugShowSort [0] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.912837717 tEnd=0.860978176 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=1
+debugShowSort [1] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.867315861 tEnd=0.830515061 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=0
+debugShowSort [2] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.912837717 tEnd=0.912837923 sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=1 tiny=0 opp=1
+findNextOp firstIndex=[3] sign=-1
+activeOp op=union miFrom=0 miTo=1 suFrom=0 suTo=0 result=1
+activeOp op=union miFrom=1 miTo=1 suFrom=0 suTo=1 result=0
+activeOp op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0
+markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.867315861 [6] (4.25979853,0.886136234) tEnd=0.867316009 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1
+findNextOp from:[3] to:[1] start=7 end=6
+bridgeOp current id=3 from=(4.25980043,0.886136055) to=(4.25979853,0.886136234)
+path.moveTo(4.25980043,0.886136055);
+path.cubicTo(4.25979948,0.886136115, 4.25979948,0.886136174, 4.25979853,0.886136234);
+findNextOp debugShowSort contourWinding=-1 oppContourWinding=0 sign=-1
+debugShowSort [1] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.860978176 tEnd=0.912837717 sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=1 tiny=0 opp=0
+debugShowSort [2] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.830515061 tEnd=0.83051493 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=1
+debugShowSort [3] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.860978176 tEnd=0.860977989 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=0
+debugShowSort [0] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.830515061 tEnd=0.867315861 sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=1 tiny=0 opp=1
+findNextOp firstIndex=[1] sign=-1
+activeOp op=union miFrom=0 miTo=0 suFrom=0 suTo=1 result=1
+activeOp op=union miFrom=0 miTo=1 suFrom=1 suTo=1 result=0
+activeOp op=union miFrom=1 miTo=1 suFrom=1 suTo=0 result=0
+findNextOp from:[1] to:[3] start=5 end=4
+bridgeOp current id=1 from=(4.25979853,0.886136234) to=(3.85939217,0.940439045)
+path.cubicTo(4.12151289,0.890467525, 3.98813701,0.909405351, 3.85939217,0.940439045);
+debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.912837923 (4.25980043,0.886136055) tEnd=1 other=3 otherT=0.867316009 otherIndex=7 windSum=? windValue=1 oppValue=0
+debugShowActiveSpans id=2 (5,1 0,1) t=0 (5,1) tEnd=0.268518519 other=1 otherT=1 otherIndex=9 windSum=? windValue=1 oppValue=0
+</div>
+
+<div id="cubicOp35da">
+{{x = 0.44618727783085621, y = 2.2840286415243063}, {x = 0.51170845243761109, y = 2.4044088819954914}, {x = 0.57783675570457882, y = 2.4985733182515446}, {x = 0.64483584772311509, y = 2.5694222112973661}}
+{{x = 0.64244110111854291, y = 2.5673840215265367}, {x = 0.63479413812245555, y = 2.5620057200094775}, {x = 0.64115438240274059, y = 2.533597555954064}, {x = 0.6620248993310307, y = 2.4876932484482714}}
 </div>
 
 </div>
@@ -230,92 +238,101 @@
 <script type="text/javascript">
 
 var testDivs = [
-    cubicOp35d,
-    cubicOp31da,
-    cubicOp31d,
-    cubicOp28u,
-    cubicOp25i,
-    cubicOp19i,
+    cubicOp36u,
+    cubicOp35da,
 ];
 
 var decimal_places = 3; // make this 3 to show more precision
 
 var tests = [];
+var testLines = [];
 var testTitles = [];
 var testIndex = 0;
 var ctx;
 
-var xmin;
-var ymin;
+var xmin, xmax;
+var ymin, ymax;
 var scale;
 var mouseX, mouseY;
 var srcLeft, srcTop;
-var srcWidth, srcHeight;
 var screenWidth, screenHeight;
-var drawnPts, drawnLines, drawnQuads, drawnCubics, deferredLines, deferredQuads, deferredCubics;
+var drawnPts, drawnLines, drawnQuads, drawnCubics;
+var curveT = 0;
 
-var ptLabels = true;
-var digit_mode = false;
-var index_mode = true;
-var index_bits = -1;
+var pt_labels = true;
+var control_lines = false;
+var curve_t = false;
 var debug_xy = false;
 var info_mode = false;
-var intersect_mode = false;
-var sequence = -1;
+var step_limit = 0;
+var draw_active = false;
+var draw_add = false;
+var draw_intersection = false;
+var draw_intersectT = false;
+var draw_legend = false;
+var draw_log = false;
+var draw_mark = false;
+var draw_sort = false;
+var draw_path = true;
+var draw_computed = 0;
 
-var SPAN_ID = 1;
-var SPAN_X1 = 2;
-var SPAN_Y1 = 3;
-var SPAN_X2 = 4;
-var SPAN_Y2 = 5;
-var SPAN_L_T = 6;
-var SPAN_L_TX = 7;
-var SPAN_L_TY = 8;
-var SPAN_L_TEND = 9;
-var SPAN_L_OTHER = 10;
-var SPAN_L_OTHERT = 11;
-var SPAN_L_OTHERI = 12;
-var SPAN_L_SUM = 13;
-var SPAN_L_VAL = 14;
-var SPAN_L_OPP = 15;
+var SPAN_ID = 0;
+var SPAN_X1 = SPAN_ID + 1;
+var SPAN_Y1 = SPAN_X1 + 1;
+var SPAN_X2 = SPAN_Y1 + 1;
+var SPAN_Y2 = SPAN_X2 + 1;
+var SPAN_L_T = SPAN_Y2 + 1;
+var SPAN_L_TX = SPAN_L_T + 1;
+var SPAN_L_TY = SPAN_L_TX + 1;
+var SPAN_L_TEND = SPAN_L_TY + 1;
+var SPAN_L_OTHER = SPAN_L_TEND + 1;
+var SPAN_L_OTHERT = SPAN_L_OTHER + 1;
+var SPAN_L_OTHERI = SPAN_L_OTHERT + 1;
+var SPAN_L_SUM = SPAN_L_OTHERI + 1;
+var SPAN_L_VAL = SPAN_L_SUM + 1;
+var SPAN_L_OPP = SPAN_L_VAL + 1;
 
-var SPAN_X3 = 6;
-var SPAN_Y3 = 7;
-var SPAN_Q_T = 8;
-var SPAN_Q_TX = 9;
-var SPAN_Q_TY = 10;
-var SPAN_Q_TEND = 11;
-var SPAN_Q_OTHER = 12;
-var SPAN_Q_OTHERT = 13;
-var SPAN_Q_OTHERI = 14;
-var SPAN_Q_SUM = 15;
-var SPAN_Q_VAL = 16;
-var SPAN_Q_OPP = 17;
+var SPAN_X3 = SPAN_Y2 + 1;
+var SPAN_Y3 = SPAN_X3 + 1;
+var SPAN_Q_T = SPAN_Y3 + 1;
+var SPAN_Q_TX = SPAN_Q_T + 1;
+var SPAN_Q_TY = SPAN_Q_TX + 1;
+var SPAN_Q_TEND = SPAN_Q_TY + 1;
+var SPAN_Q_OTHER = SPAN_Q_TEND + 1;
+var SPAN_Q_OTHERT = SPAN_Q_OTHER + 1;
+var SPAN_Q_OTHERI = SPAN_Q_OTHERT + 1;
+var SPAN_Q_SUM = SPAN_Q_OTHERI + 1;
+var SPAN_Q_VAL = SPAN_Q_SUM + 1;
+var SPAN_Q_OPP = SPAN_Q_VAL + 1;
 
-var SPAN_X4 = 8;
-var SPAN_Y4 = 9;
-var SPAN_C_T = 10;
-var SPAN_C_TX = 11;
-var SPAN_C_TY = 12;
-var SPAN_C_TEND = 13;
-var SPAN_C_OTHER = 14;
-var SPAN_C_OTHERT = 15;
-var SPAN_C_OTHERI = 16;
-var SPAN_C_SUM = 17;
-var SPAN_C_VAL = 18;
-var SPAN_C_OPP = 19;
+var SPAN_X4 = SPAN_Y3 + 1;
+var SPAN_Y4 = SPAN_X4 + 1;
+var SPAN_C_T = SPAN_Y4 + 1;
+var SPAN_C_TX = SPAN_C_T + 1;
+var SPAN_C_TY = SPAN_C_TX + 1;
+var SPAN_C_TEND = SPAN_C_TY + 1;
+var SPAN_C_OTHER = SPAN_C_TEND + 1;
+var SPAN_C_OTHERT = SPAN_C_OTHER + 1;
+var SPAN_C_OTHERI = SPAN_C_OTHERT + 1;
+var SPAN_C_SUM = SPAN_C_OTHERI + 1;
+var SPAN_C_VAL = SPAN_C_SUM + 1;
+var SPAN_C_OPP = SPAN_C_VAL + 1;
 
-var ACTIVE_LINE_SPAN = 1;
+var ACTIVE_LINE_SPAN =        1;
 var ACTIVE_QUAD_SPAN =        ACTIVE_LINE_SPAN + 1;
 var ACTIVE_CUBIC_SPAN =       ACTIVE_QUAD_SPAN + 1;
 
-var PATH_MOVETO =             ACTIVE_CUBIC_SPAN + 1;
-var PATH_LINETO =             PATH_MOVETO + 1;
-var PATH_QUADTO =             PATH_LINETO + 1;
-var PATH_CUBICTO =            PATH_QUADTO + 1;
-var PATH_CLOSE =              PATH_CUBICTO + 1;
+var ADD_MOVETO =              ACTIVE_CUBIC_SPAN + 1;
+var ADD_LINETO =              ADD_MOVETO + 1;
+var ADD_QUADTO =              ADD_LINETO + 1;
+var ADD_CUBICTO =             ADD_QUADTO + 1;
+var ADD_CLOSE =               ADD_CUBICTO + 1;
 
-var INTERSECT_LINE =          PATH_CLOSE + 1;
+var PATH_LINE =               ADD_CLOSE + 1;
+var PATH_QUAD =               PATH_LINE + 1;
+var PATH_CUBIC =              PATH_QUAD + 1;
+
+var INTERSECT_LINE =          PATH_CUBIC + 1;
 var INTERSECT_LINE_2 =        INTERSECT_LINE + 1;
 var INTERSECT_LINE_NO =       INTERSECT_LINE_2 + 1;
 var INTERSECT_QUAD_LINE =     INTERSECT_LINE_NO + 1;
@@ -342,16 +359,35 @@
 var SORT_QUAD =               SORT_LINE + 1;
 var SORT_CUBIC =              SORT_QUAD + 1;
 
+var OP_DIFFERENCE =           SORT_CUBIC + 1;
+var OP_INTERSECT =            OP_DIFFERENCE + 1;
+var OP_UNION =                OP_INTERSECT + 1;
+var OP_XOR =                  OP_UNION + 1;
+
+var MARK_LINE =               OP_XOR + 1;
+var MARK_QUAD =               MARK_LINE + 1;
+var MARK_CUBIC =              MARK_QUAD + 1;
+var MARK_DONE_LINE =          MARK_CUBIC + 1;
+var MARK_DONE_QUAD =          MARK_DONE_LINE + 1;
+var MARK_DONE_CUBIC =         MARK_DONE_QUAD + 1;
+
+var COMPUTED_ORIGINAL =       MARK_DONE_CUBIC + 1;
+var COMPUTED_QUAD =           COMPUTED_ORIGINAL + 1;
+
 var REC_TYPE_UNKNOWN = -1;
 var REC_TYPE_PATH = 0;
 var REC_TYPE_SECT = 1;
 var REC_TYPE_ACTIVE = 2;
 var REC_TYPE_ADD = 3;
 var REC_TYPE_SORT = 4;
+var REC_TYPE_OP = 5;
+var REC_TYPE_MARK = 6;
+var REC_TYPE_COMPUTED = 7;
+var REC_TYPE_LAST = REC_TYPE_COMPUTED;
 
 function strs_to_nums(strs) {
     var result = [];
-    for (var idx in strs) {
+    for (var idx = 1; idx < strs.length; ++idx) {
         var str = strs[idx];
         var num = parseFloat(str);
         if (isNaN(num)) {
@@ -381,7 +417,7 @@
     if (strs.length == 1)
         return;
     var spans = [];
-    for (var s in strs) {
+    for (var s = 0; s < strs.length; ++s) {
         var str = strs[s];
         if (str == "\n") {
             continue;
@@ -433,7 +469,7 @@
     if (strs.length == 1)
         return;
     var spans = [];
-    for (var s in strs) {
+    for (var s = 0; s < strs.length; ++s) {
         var str = strs[s];
         if (str == "\n") {
             continue;
@@ -471,7 +507,7 @@
     escape = escape.replace(/QUAD_VAL/g, "\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}");
     escape = escape.replace(/LINE_VAL/g, "\\{\\{P_VAL\\}, \\{P_VAL\\}\\}");
     escape = escape.replace(/PT_VAL/g, "\\{\\{P_VAL\\}\\}");
-    escape = escape.replace(/P_VAL/g, "(\\d+\\.?\\d*),(\\d+\\.?\\d*)");
+    escape = escape.replace(/P_VAL/g, "(?:x = )?(\\d+\\.?\\d*),(?: y = )?(\\d+\\.?\\d*)");
     escape = escape.replace(/T_VAL/g, "(\\d+\\.?\\d*e?-?\\d*)");
     escape = escape.replace(/IDX/g, "(\\d+)");
     escape = escape.replace(/NUM/g, "(-?\\d+)");
@@ -493,22 +529,31 @@
     var records = []; // a rec can be the original paths, a set of intersections, a set of active spans, a sort, or a path add
     var record = [];
     var recType = REC_TYPE_UNKNOWN;
-    for (var lineNo in lines) {
+    var lastLineNo;
+    for (var lineNo = 0; lineNo < lines.length; ++lineNo) {
         var line = lines[lineNo];
+        if (line.length == 0) {
+            continue;
+        }
         var type = line.lastIndexOf("debugShowSort", 0) === 0 ? REC_TYPE_SORT
                 : line.lastIndexOf("debugShowActiveSpans", 0) === 0 ? REC_TYPE_ACTIVE 
                 : line.lastIndexOf("debugShow", 0) === 0 ? REC_TYPE_SECT 
                 : line.lastIndexOf("path.", 0) === 0 ? REC_TYPE_ADD
+                : line.lastIndexOf("mark", 0) === 0 ? REC_TYPE_MARK
                 : line.lastIndexOf("{{", 0) === 0 ? REC_TYPE_PATH
+                : line.lastIndexOf("  {{", 0) === 0 ? REC_TYPE_COMPUTED
+                : line.lastIndexOf("op", 0) === 0 ? REC_TYPE_OP
+                : line.lastIndexOf("computed", 0) === 0 ? REC_TYPE_COMPUTED
                 : REC_TYPE_UNKNOWN;
-        if (recType != type) {
+        if (recType != type || recType == REC_TYPE_ADD) {
             if (recType != REC_TYPE_UNKNOWN) {
                 records.push(recType);
-                records.push(lineNo);
+                records.push(lastLineNo);
                 records.push(record);
             }
             record = [];
             recType = type;
+            lastLineNo = lineNo;
         }
         var found = false;
         switch (recType) {
@@ -522,11 +567,23 @@
                 );
                 break;
             case REC_TYPE_ADD:
-                found = match_regexp(line, lineNo, record, PATH_MOVETO, "path.moveToPT_VAL;"
-                ) || match_regexp(line, lineNo, record, PATH_LINETO, "path.lineTo(P_VAL);"
-                ) || match_regexp(line, lineNo, record, PATH_QUADTO, "path.quadTo(P_VAL, P_VAL);"
-                ) || match_regexp(line, lineNo, record, PATH_CUBICTO, "path.cubicTo(P_VAL, P_VAL, P_VAL);"
-                ) || match_regexp(line, lineNo, record, PATH_CLOSE, "path.close();"
+                found = match_regexp(line, lineNo, record, ADD_MOVETO, "path.moveTo(P_VAL);"
+                ) || match_regexp(line, lineNo, record, ADD_LINETO, "path.lineTo(P_VAL);"
+                ) || match_regexp(line, lineNo, record, ADD_QUADTO, "path.quadTo(P_VAL, P_VAL);"
+                ) || match_regexp(line, lineNo, record, ADD_CUBICTO, "path.cubicTo(P_VAL, P_VAL, P_VAL);"
+                ) || match_regexp(line, lineNo, record, ADD_CLOSE, "path.close();"
+                );
+                break;
+            case REC_TYPE_COMPUTED:
+                found = line == "computed quadratics given"
+                  || match_regexp(line, lineNo, record, PATH_QUAD, "  QUAD_VAL,"
+                ) || match_regexp(line, lineNo, record, PATH_CUBIC, "  CUBIC_VAL,"
+                );
+                break;
+            case REC_TYPE_PATH:
+                found = match_regexp(line, lineNo, record, PATH_LINE, "LINE_VAL"
+                ) || match_regexp(line, lineNo, record, PATH_QUAD, "QUAD_VAL"
+                ) || match_regexp(line, lineNo, record, PATH_CUBIC, "CUBIC_VAL"
                 );
                 break;
             case REC_TYPE_SECT:
@@ -548,10 +605,6 @@
 " wtTs[0]=T_VAL QUAD_VAL PT_VAL wtTs[1]=T_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL"
                 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_NO, "debugShowQuadIntersection" +
 " no intersect QUAD_VAL QUAD_VAL"
-                ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC, "debugShowCubicIntersection" +
-" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL"
-                ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC_NO, "debugShowCubicIntersection" +
-" no self intersect CUBIC_VAL"
                 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE, "debugShowCubicLineIntersection" +
 " wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
                 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_2, "debugShowCubicLineIntersection" +
@@ -570,17 +623,49 @@
 " wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wtTs[2]=T_VAL PT_VAL wtTs[3]=T_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL wnTs[1]=T_VAL wnTs[2]=T_VAL wnTs[3]=T_VAL"
                 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_NO, "debugShowCubicIntersection" +
 " no intersect CUBIC_VAL CUBIC_VAL"
+                ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC, "debugShowCubicIntersection" +
+" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL"
+                ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC_NO, "debugShowCubicIntersection" +
+" no self intersect CUBIC_VAL"
                 );
                 break;
             case REC_TYPE_SORT:
-                found = match_regexp(line, lineNo, record, SORT_LINE, "debugShowSort" +
-" [IDX] id=IDX line start=IDX PT_VAL end=IDX PT_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX"
+                found =  match_regexp(line, lineNo, record, SORT_LINE, "debugShowSort" +
+" [IDX] LINE_VAL tStart=T_VAL tEnd=T_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX"
                 ) || match_regexp(line, lineNo, record, SORT_QUAD, "debugShowSort" +
-" [IDX] id=IDX quad start=IDX PT_VAL end=IDX PT_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX"
+" [IDX] QUAD_VAL tStart=T_VAL tEnd=T_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX"
                 ) || match_regexp(line, lineNo, record, SORT_CUBIC, "debugShowSort" +
+" [IDX] CUBIC_VAL tStart=T_VAL tEnd=T_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX"
+                ) || match_regexp(line, lineNo, record, SORT_LINE_COMPACT, "debugShowSort" +
+" [IDX] id=IDX line start=IDX PT_VAL end=IDX PT_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX"
+                ) || match_regexp(line, lineNo, record, SORT_QUAD_COMPACT, "debugShowSort" +
+" [IDX] id=IDX quad start=IDX PT_VAL end=IDX PT_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX"
+                ) || match_regexp(line, lineNo, record, SORT_CUBIC_COMPACT, "debugShowSort" +
 " [IDX] id=IDX cubic start=IDX PT_VAL end=IDX PT_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX"
                 );
                 break;
+            case REC_TYPE_MARK:
+                found =  match_regexp(line, lineNo, record, MARK_LINE, "markWinding" +
+" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX"
+                ) || match_regexp(line, lineNo, record, MARK_QUAD, "markWinding" +
+" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX"
+                ) || match_regexp(line, lineNo, record, MARK_CUBIC, "markWinding" +
+" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX"
+                ) || match_regexp(line, lineNo, record, MARK_DONE_LINE, "markDoneBinary" +
+" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX"
+                ) || match_regexp(line, lineNo, record, MARK_DONE_QUAD, "markDoneBinary" +
+" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX"
+                ) || match_regexp(line, lineNo, record, MARK_DONE_CUBIC, "markDoneBinary" +
+" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX"
+                );
+                break;
+            case REC_TYPE_OP:
+                found = match_regexp(line, lineNo, record, OP_DIFFERENCE, "op difference"
+                ) || match_regexp(line, lineNo, record, OP_INTERSECT, "op intersect"
+                ) || match_regexp(line, lineNo, record, OP_UNION, "op union"
+                ) || match_regexp(line, lineNo, record, OP_XOR, "op xor"
+                );
+                break;
             case REC_TYPE_UNKNOWN:
                 found = true;
                 break;
@@ -589,8 +674,14 @@
             console.log(line + " [" + lineNo + "] of type " + type + " not found");
         }
     }
+    if (recType != REC_TYPE_UNKNOWN) {
+        records.push(recType);
+        records.push(lastLineNo);
+        records.push(record);
+    }
     if (records.length >= 1) {
         tests.push(records);
+        testLines.push(lines);
         testTitles.push(title);
     }
 }
@@ -602,69 +693,189 @@
     screenHeight = canvas.height = window.innerHeight - 20;
     ctx = canvas.getContext('2d');
     xmin = Infinity;
-    var xmax = -Infinity;
+    xmax = -Infinity;
     ymin = Infinity;
-    var ymax = -Infinity;
-    var scanType = -1;
-    for (var scansStr in test) {
-        var scans = parseInt(scansStr);
-        var scan = test[scans];
-        if (scanType == -1) {
-            scanType = scan;
-            continue;
+    ymax = -Infinity;
+    for (var testIndex = 0; testIndex < test.length; testIndex += 3) {
+        var recType = test[testIndex];
+        if (!typeof recType == 'number' || recType < REC_TYPE_UNKNOWN || recType > REC_TYPE_LAST) {
+            console.log("unknown rec type: " + recType);
+            throw "stop execution";
         }
-        if (scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN
-                || scanType == ACTIVE_CUBIC_SPAN) {
-            var last = scanType == ACTIVE_CUBIC_SPAN ? SPAN_X4
-                    : scanType == ACTIVE_QUAD_SPAN ? SPAN_X3 : SPAN_X2;
-            for (var idx = SPAN_X1; idx <= last; idx += 2) {
-                xmin = Math.min(xmin, scan[idx]);
-                xmax = Math.max(xmax, scan[idx]);
-                ymin = Math.min(ymin, scan[idx + 1]);
-                ymax = Math.max(ymax, scan[idx + 1]);
+        var records = test[testIndex + 2];
+        for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
+            var fragType = records[recordIndex];
+            if (!typeof fragType == 'number' || fragType < 1 || recType > SORT_CUBIC) {
+                console.log("unknown in range frag type: " + fragType);
+                throw "stop execution";
             }
-        } else {
-            var start = 1;
-            if (scanType != INTERSECT_QUAD_LINE_NO && scanType != INTERSECT_QUAD_NO) {
-                start = 2;
+            var frags = records[recordIndex + 1];
+            var first = 0;
+            var last = -1;
+            var first2 = 0;
+            var last2 = 0;
+            switch (recType) {
+                case REC_TYPE_COMPUTED:
+                case REC_TYPE_PATH:
+                    switch (fragType) {
+                        case PATH_LINE:
+                            last = 4;
+                            break;
+                        case PATH_QUAD:
+                            last = 6;
+                            break;
+                        case PATH_CUBIC:
+                            last = 8;
+                            break;
+                        default:
+                            console.log("unknown " + (recType == REC_TYPE_PATH ? "REC_TYPE_PATH" 
+                                    : "REC_TYPE_COMPUTED") + " frag type:" + fragType);
+                            throw "stop execution";
+                    }
+                    break;
+                case REC_TYPE_ACTIVE:
+                    first = 1;
+                    switch (fragType) {
+                        case ACTIVE_LINE_SPAN:
+                            last = 5;
+                            break;
+                        case ACTIVE_QUAD_SPAN:
+                            last = 7;
+                            break;
+                        case ACTIVE_CUBIC_SPAN:
+                            last = 9;
+                            break;
+                        default:
+                            console.log("unknown REC_TYPE_ACTIVE frag type: " + fragType);
+                            throw "stop execution";
+                    }
+                    break;
+                case REC_TYPE_ADD:
+                    switch (fragType) {
+                        case ADD_MOVETO:
+                            last = 2;
+                            break;
+                        case ADD_LINETO:
+                            last = 2;
+                            break;
+                        case ADD_QUADTO:
+                            last = 4;
+                            break;
+                        case ADD_CUBICTO:
+                            last = 6;
+                            break;
+                        case ADD_CLOSE:
+                            break;
+                        default:
+                            console.log("unknown REC_TYPE_ADD frag type: " + fragType);
+                            throw "stop execution";
+                    }
+                    break;
+                case REC_TYPE_SECT:
+                    switch (fragType) {
+                        case INTERSECT_LINE:
+                            first = 1; last = 5; first2 = 8; last2 = 12;
+                            break;
+                        case INTERSECT_LINE_2:
+                            first = 1; last = 5; first2 = 11; last2 = 15;
+                            break;
+                        case INTERSECT_LINE_NO:
+                            first = 0; last = 4; first2 = 4; last2 = 8;
+                            break;
+                        case INTERSECT_QUAD_LINE:
+                            first = 1; last = 7; first2 = 10; last2 = 14;
+                            break;
+                        case INTERSECT_QUAD_LINE_2:
+                            first = 1; last = 7; first2 = 13; last2 = 17;
+                            break;
+                        case INTERSECT_QUAD_LINE_NO:
+                            first = 0; last = 6; first2 = 6; last2 = 10;
+                            break;
+                        case INTERSECT_QUAD:
+                            first = 1; last = 7; first2 = 10; last2 = 16;
+                            break;
+                        case INTERSECT_QUAD_2:
+                            first = 1; last = 7; first2 = 13; last2 = 19;
+                            break;
+                        case INTERSECT_QUAD_NO:
+                            first = 0; last = 6; first2 = 6; last2 = 12;
+                            break;
+                        case INTERSECT_SELF_CUBIC:
+                            first = 1; last = 9;
+                            break;
+                        case INTERSECT_SELF_CUBIC_NO:
+                            first = 0; last = 8;
+                            break;
+                        case INTERSECT_CUBIC_LINE:
+                            first = 1; last = 9; first2 = 12; last2 = 16;
+                            break;
+                        case INTERSECT_CUBIC_LINE_2:
+                            first = 1; last = 9; first2 = 15; last2 = 19;
+                            break;
+                        case INTERSECT_CUBIC_LINE_3:
+                            first = 1; last = 9; first2 = 18; last2 = 22;
+                            break;
+                        case INTERSECT_CUBIC_LINE_NO:
+                            first = 0; last = 8; first2 = 8; last2 = 12;
+                            break;
+                        case INTERSECT_CUBIC:
+                            first = 1; last = 9; first2 = 12; last2 = 20;
+                            break;
+                        case INTERSECT_CUBIC_2:
+                            first = 1; last = 9; first2 = 15; last2 = 23;
+                            break;
+                        case INTERSECT_CUBIC_3:
+                            first = 1; last = 9; first2 = 18; last2 = 26;
+                            break;
+                        case INTERSECT_CUBIC_4:
+                            first = 1; last = 9; first2 = 21; last2 = 29;
+                            break;
+                        case INTERSECT_CUBIC_NO:
+                            first = 0; last = 8; first2 = 8; last2 = 16;
+                            break;
+                        default:
+                            console.log("unknown REC_TYPE_SECT frag type: " + fragType);
+                            throw "stop execution";
+                    }
+                    break;
+                default:
+                    continue;
             }
-            for (var idx = start; idx < start + 6; idx += 2) {
-                xmin = Math.min(xmin, scan[idx]);
-                xmax = Math.max(xmax, scan[idx]);
-                ymin = Math.min(ymin, scan[idx + 1]);
-                ymax = Math.max(ymax, scan[idx + 1]);
+            for (var idx = first; idx < last; idx += 2) {
+                xmin = Math.min(xmin, frags[idx]);
+                xmax = Math.max(xmax, frags[idx]);
+                ymin = Math.min(ymin, frags[idx + 1]);
+                ymax = Math.max(ymax, frags[idx + 1]);
             }
-            start = start + 6;
-            if (scanType == INTERSECT_QUAD_LINE || scanType == INTERSECT_QUAD) {
-                start += 3;
-            }
-            if (scanType == INTERSECT_QUAD_LINE_2) {
-                start += 6;
-            }
-            if (scanType == INTERSECT_QUAD_2) {
-                start += 4;
-            }
-            var end = start + 4;
-            if (scanType == INTERSECT_QUAD || scanType == INTERSECT_QUAD_2 || scanType == INTERSECT_QUAD_NO) {
-                end += 2;
-            }
-            for (var idx = start; idx < end; idx += 2) {
-                xmin = Math.min(xmin, scan[idx]);
-                xmax = Math.max(xmax, scan[idx]);
-                ymin = Math.min(ymin, scan[idx + 1]);
-                ymax = Math.max(ymax, scan[idx + 1]);
+            for (var idx = first2; idx < last2; idx += 2) {
+                xmin = Math.min(xmin, frags[idx]);
+                xmax = Math.max(xmax, frags[idx]);
+                ymin = Math.min(ymin, frags[idx + 1]);
+                ymax = Math.max(ymax, frags[idx + 1]);
             }
         }
-        scanType = -1;
     }
-    srcWidth = xmax - xmin;
-    srcHeight = ymax - ymin;
+    setScale();
+}
+
+function setScale() {
+    var srcWidth = xmax - xmin;
+    var srcHeight = ymax - ymin;
     var hscale = ctx.canvas.width / srcWidth;
     var vscale = ctx.canvas.height / srcHeight;
-    var minScale = Math.min(hscale, vscale);
-    scale = minScale;
-    srcLeft = xmin;
-    srcTop = ymin;
+    scale = Math.min(hscale, vscale);
+    var invScale = 1 / scale;
+    var sxmin = xmin - invScale * 5;
+    var symin = ymin - invScale * 10;
+    var sxmax = xmax + invScale * (6 * decimal_places + 10);
+    var symax = ymax + invScale * 10;
+    srcWidth = sxmax - sxmin;
+    srcHeight = symax - symin;
+    hscale = ctx.canvas.width / srcWidth;
+    vscale = ctx.canvas.height / srcHeight;
+    scale = Math.min(hscale, vscale);
+    srcLeft = sxmin;
+    srcTop = symin;
 }
 
 function drawPoint(px, py) {
@@ -687,32 +898,95 @@
     ctx.fillText(label, _px + 5, _py);
 }
 
-function drawLine(x1, y1, x2, y2, selected) {
+function drawPoints(ptArray, curveType) {
+    var count = (curveType - PATH_LINE + 2) * 2;
+    for (var idx = 0; idx < count; idx += 2) {
+        drawPoint(ptArray[idx], ptArray[idx + 1]);
+    }
+}
+
+function drawControlLines(curve, curveType) {
+    if (curveType == PATH_LINE) {
+        return;
+    }
+    ctx.strokeStyle = "rgba(0,0,0, 0.3)";
+    drawLine(curve[0], curve[1], curve[2], curve[3]);
+    drawLine(curve[2], curve[3], curve[4], curve[5]);
+    if (curveType == PATH_CUBIC)
+        drawLine(curve[4], curve[5], curve[4], curve[5]);
+}
+
+function drawPointAtT(curve, curveType) {
+    var x, y;
+    var t = curveT;
+    switch (curveType) {
+        case PATH_LINE:
+            var a = 1 - t;
+            var b = t;
+            x = a * curve[0] + b * curve[2];
+            y = a * curve[1] + b * curve[3];
+            break;
+        case PATH_QUAD:
+            var one_t = 1 - t;
+            var a = one_t * one_t;
+            var b = 2 * one_t * t;
+            var c = t * t;
+            x = a * curve[0] + b * curve[2] + c * curve[4];
+            y = a * curve[1] + b * curve[3] + c * curve[5];
+            break;
+        case PATH_CUBIC:
+            var one_t = 1 - t;
+            var one_t2 = one_t * one_t;
+            var a = one_t2 * one_t;
+            var b = 3 * one_t2 * t;
+            var t2 = t * t;
+            var c = 3 * one_t * t2;
+            var d = t2 * t;
+            x = a * curve[0] + b * curve[2] + c * curve[4] + d * curve[6];
+            y = a * curve[1] + b * curve[3] + c * curve[5] + d * curve[7];
+            break;
+    }
+    drawPoint(x, y);
+    if (!draw_intersectT) {
+        return;
+    }
+    ctx.fillStyle = "red";
+    drawTAtPointUp(x, y, curveT);
+}
+
+function drawTAtPointUp(px, py, t) {
+    var label = t.toFixed(decimal_places);
+    var _px = (px - srcLeft)* scale;
+    var _py = (py - srcTop) * scale;
+    ctx.fillText(label, _px + 5, _py - 10);
+}
+
+function drawTAtPointDown(px, py, t) {
+    var label = t.toFixed(decimal_places);
+    var _px = (px - srcLeft)* scale;
+    var _py = (py - srcTop) * scale;
+    ctx.fillText(label, _px + 5, _py + 10);
+}
+
+function drawLine(x1, y1, x2, y2) {
     for (var pts = 0; pts < drawnLines.length; pts += 4) {
         if (x1 == drawnLines[pts] && y1 == drawnLines[pts + 1]) {
             return;
         }
-        if (x2 == drawnLines[pts + 2] && x2 == drawnLines[pts + 3]) {
+        if (x2 == drawnLines[pts + 2] && y2 == drawnLines[pts + 3]) {
             return;
         }
     }
-    if (selected) {
-        drawnLines.push(x1);
-        drawnLines.push(y1);
-        drawnLines.push(x2);
-        drawnLines.push(y2);
-        ctx.beginPath();
-        ctx.moveTo((x1 - srcLeft) * scale,
-                (y1 - srcTop) * scale);
-        ctx.lineTo((x2 - srcLeft) * scale,
-                (y2 - srcTop) * scale);
-        ctx.stroke();
-        return;
-    }
-    deferredLines.push(x1);
-    deferredLines.push(y1);
-    deferredLines.push(x2);
-    deferredLines.push(y2);
+    drawnLines.push(x1);
+    drawnLines.push(y1);
+    drawnLines.push(x2);
+    drawnLines.push(y2);
+    ctx.beginPath();
+    ctx.moveTo((x1 - srcLeft) * scale,
+            (y1 - srcTop) * scale);
+    ctx.lineTo((x2 - srcLeft) * scale,
+            (y2 - srcTop) * scale);
+    ctx.stroke();
 }
 
 function drawLinePartial(x1, y1, x2, y2, t1, t2) {
@@ -730,41 +1004,32 @@
     ctx.stroke();
 }
 
-function drawQuad(x1, y1, x2, y2, x3, y3, selected) {
+function drawQuad(x1, y1, x2, y2, x3, y3) {
     for (var pts = 0; pts < drawnQuads.length; pts += 6) {
         if (x1 == drawnQuads[pts] && y1 == drawnQuads[pts + 1]) {
             return;
         }
-        if (x2 == drawnQuads[pts + 2] && x2 == drawnQuads[pts + 3]) {
+        if (x2 == drawnQuads[pts + 2] && y2 == drawnQuads[pts + 3]) {
             return;
         }
-        if (x2 == drawnQuads[pts + 4] && x2 == drawnQuads[pts + 5]) {
+        if (x3 == drawnQuads[pts + 4] && x3 == drawnQuads[pts + 5]) {
             return;
         }
     }
-    if (selected) {
-        drawnQuads.push(x1);
-        drawnQuads.push(y1);
-        drawnQuads.push(x2);
-        drawnQuads.push(y2);
-        drawnQuads.push(x3);
-        drawnQuads.push(y3);
-        ctx.beginPath();
-        ctx.moveTo((x1 - srcLeft) * scale,
-                (y1 - srcTop) * scale);
-        ctx.quadraticCurveTo((x2 - srcLeft) * scale,
-                (y2 - srcTop) * scale,
-                (x3 - srcLeft) * scale,
-                (y3 - srcTop) * scale);
-        ctx.stroke();
-        return;
-    }
-    deferredQuads.push(x1);
-    deferredQuads.push(y1);
-    deferredQuads.push(x2);
-    deferredQuads.push(y2);
-    deferredQuads.push(x3);
-    deferredQuads.push(y3);
+    drawnQuads.push(x1);
+    drawnQuads.push(y1);
+    drawnQuads.push(x2);
+    drawnQuads.push(y2);
+    drawnQuads.push(x3);
+    drawnQuads.push(y3);
+    ctx.beginPath();
+    ctx.moveTo((x1 - srcLeft) * scale,
+            (y1 - srcTop) * scale);
+    ctx.quadraticCurveTo((x2 - srcLeft) * scale,
+            (y2 - srcTop) * scale,
+            (x3 - srcLeft) * scale,
+            (y3 - srcTop) * scale);
+    ctx.stroke();
 }
 
 function interp(A, B, t) {
@@ -798,50 +1063,39 @@
     ctx.stroke();
 }
 
-function drawCubic(x1, y1, x2, y2, x3, y3, x4, y4, selected) {
+function drawCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
     for (var pts = 0; pts < drawnCubics.length; pts += 8) {
         if (x1 == drawnCubics[pts] && y1 == drawnCubics[pts + 1]) {
             return;
         }
-        if (x2 == drawnCubics[pts + 2] && x2 == drawnCubics[pts + 3]) {
+        if (x2 == drawnCubics[pts + 2] && y2 == drawnCubics[pts + 3]) {
             return;
         }
-        if (x2 == drawnCubics[pts + 4] && x2 == drawnCubics[pts + 5]) {
+        if (x3 == drawnCubics[pts + 4] && y3 == drawnCubics[pts + 5]) {
             return;
         }
-        if (x2 == drawnCubics[pts + 6] && x2 == drawnCubics[pts + 7]) {
+        if (x4 == drawnCubics[pts + 6] && y4 == drawnCubics[pts + 7]) {
             return;
         }
     }
-    if (selected) {
-        drawnCubics.push(x1);
-        drawnCubics.push(y1);
-        drawnCubics.push(x2);
-        drawnCubics.push(y2);
-        drawnCubics.push(x3);
-        drawnCubics.push(y3);
-        drawnCubics.push(x4);
-        drawnCubics.push(y4);
-        ctx.beginPath();
-        ctx.moveTo((x1 - srcLeft) * scale,
-                (y1 - srcTop) * scale);
-        ctx.bezierCurveTo((x2 - srcLeft) * scale,
-                (y2 - srcTop) * scale,
-                (x3 - srcLeft) * scale,
-                (y3 - srcTop) * scale,
-                (x4 - srcLeft) * scale,
-                (y4 - srcTop) * scale);
-        ctx.stroke();
-        return;
-    }
-    deferredCubics.push(x1);
-    deferredCubics.push(y1);
-    deferredCubics.push(x2);
-    deferredCubics.push(y2);
-    deferredCubics.push(x3);
-    deferredCubics.push(y3);
-    deferredCubics.push(x4);
-    deferredCubics.push(y4);
+    drawnCubics.push(x1);
+    drawnCubics.push(y1);
+    drawnCubics.push(x2);
+    drawnCubics.push(y2);
+    drawnCubics.push(x3);
+    drawnCubics.push(y3);
+    drawnCubics.push(x4);
+    drawnCubics.push(y4);
+    ctx.beginPath();
+    ctx.moveTo((x1 - srcLeft) * scale,
+            (y1 - srcTop) * scale);
+    ctx.bezierCurveTo((x2 - srcLeft) * scale,
+            (y2 - srcTop) * scale,
+            (x3 - srcLeft) * scale,
+            (y3 - srcTop) * scale,
+            (x4 - srcLeft) * scale,
+            (y4 - srcTop) * scale);
+    ctx.stroke();
 }
 
 function interp_cubic_coords(x1, x2, x3, x4, t)
@@ -886,223 +1140,516 @@
     ctx.stroke();
 }
 
-function drawPartial(test) {
-    ctx.lineWidth = 3;
-    ctx.strokeStyle = "rgba(0,0,255, 0.3)";
-    var scanType = -1;
-    var partIndex = 0;
-    for (var scansStr in test) {
-        var scans = parseInt(scansStr);
-        var scan = test[scans];
-        if (scanType == -1) {
-            scanType = scan;
-            continue;
-        }
-        partIndex++;
-        var hasId = scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN
-                || scanType == ACTIVE_CUBIC_SPAN ? SPAN_ID : -1;
-        if (hasId < 0) {
-            continue;
-        }
-        var types = [scanType == ACTIVE_LINE_SPAN ? 0 : scanType == ACTIVE_QUAD_SPAN ? 1 : 2];
-        var x1 = scan[SPAN_X1];
-        var y1 = scan[SPAN_Y1];
-        var x2 = scan[SPAN_X2];
-        var y2 = scan[SPAN_Y2];
-        var x3, y3, x3, y4, t1, t2;
-        switch(scanType) { 
-            case ACTIVE_LINE_SPAN:
-                t1 = scan[SPAN_L_T];
-                t2 = scan[SPAN_L_TEND];
-                drawLinePartial(x1, y1, x2, y2, t1, t2);
-                break;
-            case ACTIVE_QUAD_SPAN:
-                x3 = scan[SPAN_X3];
-                y3 = scan[SPAN_Y3];
-                t1 = scan[SPAN_Q_T];
-                t2 = scan[SPAN_Q_TEND];
-                drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2);
-                break;
-            case ACTIVE_CUBIC_SPAN:
-                x3 = scan[SPAN_X3];
-                y3 = scan[SPAN_Y3];
-                x4 = scan[SPAN_X4];
-                y4 = scan[SPAN_Y4];
-                t1 = scan[SPAN_C_T];
-                t2 = scan[SPAN_C_TEND];
-                drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2);
-                break;
-        }
-        scanType = -1;
-    }
-}
-
-function drawDeferred() {
-    for (var pts = 0; pts < deferredCubics.length; pts += 8) {
-        drawCubic(deferredCubics[pts], deferredCubics[pts + 1],
-                deferredCubics[pts + 2], deferredCubics[pts + 3],
-                deferredCubics[pts + 4], deferredCubics[pts + 5],
-                deferredCubics[pts + 6], deferredCubics[pts + 7], true);
-    }
-    for (var pts = 0; pts < deferredQuads.length; pts += 6) {
-        drawQuad(deferredQuads[pts], deferredQuads[pts + 1],
-                deferredQuads[pts + 2], deferredQuads[pts + 3],
-                deferredQuads[pts + 4], deferredQuads[pts + 5], true);
-    }
-    for (var pts = 0; pts < deferredLines.length; pts += 4) {
-        drawLine(deferredLines[pts], deferredLines[pts + 1],
-                deferredLines[pts + 2], deferredLines[pts + 3], true);
-    }
-}
-
-function draw(test, title) {
+function draw(test, lines, title) {
     ctx.fillStyle = "rgba(0,0,0, 0.1)";
     ctx.font = "normal 50px Arial";
     ctx.fillText(title, 50, 50);
     ctx.font = "normal 10px Arial";
     ctx.lineWidth = "1.001"; "0.999";
-    var curId = -1;
-    var firstIdx;
-    var lastIdx;
-    var index_tst = -1;
+    var moveX, moveY;
+    var secondPath = test.length;
+    var closeCount = 0;
+    var logStart = -1;
+    var logRange = 0;
+    // find last active rec type at this step
+    var curType = test[0];
+    var curStep = 0;
+    var lastIndex = test.length - 1;
+    var hasOp = false;
+    var lastActive = 0;
+    var lastSort = 0;
+    var lastMark = 0;
+    var activeCount = 0;
+    var sortCount = 0;
+    var markCount = 0;
+    for (var testIndex = 0; testIndex < test.length; testIndex += 3) {
+        var recType = test[testIndex];
+        if (!typeof recType == 'number' || recType < REC_TYPE_UNKNOWN || recType > REC_TYPE_LAST) {
+            console.log("unknown rec type: " + recType);
+            throw "stop execution";
+        }
+   //     if (curType == recType && curType != REC_TYPE_ADD) {
+   //         continue;
+   //     }
+        if (step_limit > 0 && curStep >= step_limit) {
+            break;
+        }
+        curType = recType;
+        if (recType == REC_TYPE_OP) {
+            hasOp = true;
+            continue;
+        }
+        if (recType == REC_TYPE_SECT || recType == REC_TYPE_UNKNOWN) {
+            // these types do not advance step
+            continue;
+        }
+        if (recType == REC_TYPE_ADD) {
+            var records = test[testIndex + 2];
+            if (records.length != 2) {
+                console.log("expect only two elements: " + records.length);
+                throw "stop execution";
+            }
+            var fragType = records[0];
+            if (fragType == ADD_MOVETO || fragType == ADD_CLOSE) {
+                continue;
+            }
+            if (!draw_add) {
+                continue;
+            }
+        }
+        if ((recType == REC_TYPE_PATH || recType == REC_TYPE_COMPUTED) && hasOp) {
+            secondPath = testIndex;
+        }
+        if (recType == REC_TYPE_ACTIVE) {
+            if (!draw_active) {
+                continue;
+            }
+            lastActive = testIndex;
+            ++activeCount;
+        }
+        if (recType == REC_TYPE_SORT) {
+            if (!draw_sort) {
+                continue;
+            }
+            lastSort = testIndex;
+            ++sortCount;
+        }
+        if (recType = REC_TYPE_MARK) {
+            if (!draw_mark) {
+                continue;
+            }
+            lastMark = testIndex;
+            ++markCount;
+        }
+        lastIndex = testIndex;
+        ++curStep;
+    }
     drawnPts = [];
     drawnLines = [];
     drawnQuads = [];
     drawnCubics = [];
-    deferredLines = [];
-    deferredQuads = [];
-    deferredCubics = [];
-    var scanType = -1;
-    var partIndex = 0;
-    for (var scansStr in test) {
-        var scans = parseInt(scansStr);
-        var scan = test[scans];
-        if (scanType == -1) {
-            scanType = scan;
-            continue;
-        }
-        partIndex++;
-        var hasId = scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN
-                || scanType == ACTIVE_CUBIC_SPAN ? SPAN_ID : -1;
-        if (hasId >= 0 && curId != scan[hasId]) {
-            curId = scan[hasId];
-            firstIdx = lastIdx = partIndex;
-            index_tst++;
-            var nextIdx = lastIdx + 1;
-            while (nextIdx * 2 < test.length && test[nextIdx * 2][hasId] == curId) {
-                lastIdx = nextIdx++;
+    var opLetter = 'S';
+    for (var testIndex = 0; testIndex <= lastIndex; testIndex += 3) {
+        var recType = test[testIndex];
+        logStart = test[testIndex + 1];
+        var records = test[testIndex + 2];
+        logRange = records.length / 2;
+        for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
+            var fragType = records[recordIndex];
+            if (!typeof fragType == 'number' || fragType < 1 || recType > SORT_CUBIC) {
+                console.log("unknown in range frag type: " + fragType);
+                throw "stop execution";
             }
-        } else if (hasId < 0) {
-            firstIdx = lastIdx = partIndex;
-            index_tst++;
-        }
-        var seq = sequence % (test.length / 2);
-        var selected = sequence >= 0 ? seq == partIndex
-                : (index_bits & (1 << index_tst)) != 0 && partIndex == firstIdx;
-        var skippable = (sequence >= 0 && seq >= firstIdx && seq <= lastIdx)
-                || partIndex != firstIdx;
-        if (skippable && !selected) {
-            scanType = -1;
-            continue;
-        }
-        var types = [scanType == ACTIVE_LINE_SPAN ? 0 : scanType == ACTIVE_QUAD_SPAN ? 1 : 2];
-        var pts = [];
-        if (scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN || scanType == ACTIVE_CUBIC_SPAN) {
-            pts.push(SPAN_X1);
-        } else {
-            pts.push(scanType != INTERSECT_QUAD_NO && scanType != INTERSECT_QUAD_LINE_NO ? 2 : 1);
-            types.push(scanType == INTERSECT_QUAD_NO || scanType == INTERSECT_QUAD || scanType == INTERSECT_QUAD_2 ? 1 : 0);
-            pts.push(scanType == INTERSECT_QUAD_LINE || scanType == INTERSECT_QUAD ? 11
-                    : scanType == INTERSECT_QUAD_LINE_2 ? 14 : scanType == INTERSECT_QUAD_2 ? 12 : 7);
-        }
-        ctx.strokeStyle = "red";
-        for (var typeIndex = 0; typeIndex < types.length; ++typeIndex) {
-            var type = types[typeIndex];
-            var index = pts[typeIndex];
-            if (type == 2) {
-                drawCubic(scan[index + 0], scan[index + 1], scan[index + 2], scan[index + 3],
-                        scan[index + 4], scan[index + 5], scan[index + 6], scan[index + 7],
-                        selected);
-            } else if (type == 1) {
-                drawQuad(scan[index + 0], scan[index + 1], scan[index + 2], scan[index + 3],
-                        scan[index + 4], scan[index + 5], selected);
-            } else {
-                drawLine(scan[index + 0], scan[index + 1], scan[index + 2], scan[index + 3],
-                        selected);
+            var frags = records[recordIndex + 1];
+            switch (recType) {
+                case REC_TYPE_COMPUTED:
+                    if (draw_computed == 0) {
+                        continue;
+                    }
+                    ctx.lineWidth = 1;
+                    ctx.strokeStyle = testIndex < secondPath ? "black" : "red";
+                    ctx.fillStyle = "blue";
+                    switch (fragType) {
+                        case PATH_QUAD:
+                            if (draw_computed & 1) {
+                                drawQuad(frags[0], frags[1], frags[2], frags[3],
+                                        frags[4], frags[5]);
+                            }
+                            break;
+                        case PATH_CUBIC:
+                            if (draw_computed & 2) {
+                                drawCubic(frags[0], frags[1], frags[2], frags[3],
+                                        frags[4], frags[5], frags[6], frags[7]);
+                            }
+                            break;
+                        default:
+                            console.log("unknown REC_TYPE_COMPUTED frag type: " + fragType);
+                            throw "stop execution";
+                    }
+                    if ((draw_computed & (fragType - PATH_LINE)) == 0) {
+                        break;
+                    }
+                    if (pt_labels) {
+                        drawPoints(frags, fragType);
+                    }
+                    if (control_lines) {
+                        drawControlLines(frags, fragType);
+                    }
+                    if (curve_t) {
+                        drawPointAtT(frags, fragType);
+                    }
+                    break;
+                case REC_TYPE_PATH:
+                    if (!draw_path) {
+                        continue;
+                    }
+                    ctx.lineWidth = 1;
+                    ctx.strokeStyle = testIndex < secondPath ? "black" : "red";
+                    ctx.fillStyle = "blue";
+                    switch (fragType) {
+                        case PATH_LINE:
+                            drawLine(frags[0], frags[1], frags[2], frags[3]);
+                            break;
+                        case PATH_QUAD:
+                            drawQuad(frags[0], frags[1], frags[2], frags[3],
+                                    frags[4], frags[5]);
+                            break;
+                        case PATH_CUBIC:
+                            drawCubic(frags[0], frags[1], frags[2], frags[3],
+                                    frags[4], frags[5], frags[6], frags[7]);
+                            break;
+                        default:
+                            console.log("unknown REC_TYPE_PATH frag type: " + fragType);
+                            throw "stop execution";
+                    }
+                    if (pt_labels) {
+                        drawPoints(frags, fragType);
+                    }
+                    if (control_lines) {
+                        drawControlLines(frags, fragType);
+                    }
+                    if (curve_t) {
+                        drawPointAtT(frags, fragType);
+                    }
+                    break;
+                case REC_TYPE_OP:
+                    switch (fragType) {
+                        case OP_INTERSECT: opLetter = 'I'; break;
+                        case OP_DIFFERENCE: opLetter = 'D'; break;
+                        case OP_UNION: opLetter = 'U'; break;
+                        case OP_XOR: opLetter = 'X'; break;
+                        default:
+                            console.log("unknown REC_TYPE_OP frag type: " + fragType);
+                            throw "stop execution";
+                    }
+                    break;
+                case REC_TYPE_ACTIVE:
+                    if (!draw_active || testIndex < lastActive) {
+                        continue;
+                    }
+                    var x1 = frags[SPAN_X1];
+                    var y1 = frags[SPAN_Y1];
+                    var x2 = frags[SPAN_X2];
+                    var y2 = frags[SPAN_Y2];
+                    var x3, y3, x3, y4, t1, t2;
+                    ctx.lineWidth = 3;
+                    ctx.strokeStyle = "rgba(0,0,255, 0.3)";
+                    switch (fragType) {
+                        case ACTIVE_LINE_SPAN:
+                            t1 = frags[SPAN_L_T];
+                            t2 = frags[SPAN_L_TEND];
+                            drawLinePartial(x1, y1, x2, y2, t1, t2);
+                            break;
+                        case ACTIVE_QUAD_SPAN:
+                            x3 = frags[SPAN_X3];
+                            y3 = frags[SPAN_Y3];
+                            t1 = frags[SPAN_Q_T];
+                            t2 = frags[SPAN_Q_TEND];
+                            drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2);
+                            break;
+                        case ACTIVE_CUBIC_SPAN:
+                            x3 = frags[SPAN_X3];
+                            y3 = frags[SPAN_Y3];
+                            x4 = frags[SPAN_X4];
+                            y4 = frags[SPAN_Y4];
+                            t1 = frags[SPAN_C_T];
+                            t2 = frags[SPAN_C_TEND];
+                            drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2);
+                            break;
+                        default:
+                            console.log("unknown REC_TYPE_ACTIVE frag type: " + fragType);
+                            throw "stop execution";
+                    }
+                    break;
+                case REC_TYPE_ADD:
+                    if (!draw_add) {
+                        continue;
+                    }
+                    ctx.lineWidth = 3;
+                    ctx.strokeStyle = closeCount == 0 ? "rgba(0,0,255, 0.3)"
+                            : closeCount == 1 ? "rgba(0,127,0, 0.3)"
+                            : closeCount == 2 ? "rgba(0,127,127, 0.3)"
+                            : closeCount == 3 ? "rgba(127,127,0, 0.3)"
+                            : "rgba(127,0,127, 0.3)";
+                    switch (fragType) {
+                        case ADD_MOVETO:
+                            moveX = frags[0];
+                            moveY = frags[1];
+                            break;
+                        case ADD_LINETO:
+                            drawLine(moveX, moveY, frags[0], frags[1], true);
+                            moveX = frags[0];
+                            moveY = frags[1];
+                           break;
+                        case ADD_QUADTO:
+                            drawQuad(moveX, moveY, frags[0], frags[1], frags[2], frags[3], true);
+                            moveX = frags[2];
+                            moveY = frags[3];
+                            break;
+                        case ADD_CUBICTO:
+                            drawCubic(moveX, moveY, frags[0], frags[1], frags[2], frags[3],
+                                    frags[4], frags[5], true);
+                            moveX = frags[4];
+                            moveY = frags[5];
+                            break;
+                        case ADD_CLOSE:
+                            ++closeCount;
+                            break;
+                        default:
+                            console.log("unknown REC_TYPE_ADD frag type: " + fragType);
+                            throw "stop execution";
+                    }
+                    break;
+                case REC_TYPE_SECT:
+                    if (!draw_intersection) {
+                        continue;
+                    }
+                    ctx.lineWidth = 1;
+                    ctx.strokeStyle = "rgba(0,0,255, 0.3)";
+                    ctx.fillStyle = "blue";
+                    var f = [];
+                    switch (fragType) {
+                        case INTERSECT_LINE:
+                            f.push(5, 6, 0, 7);
+                            break;
+                        case INTERSECT_LINE_2:
+                            f.push(5, 6, 0, 10);
+                            f.push(8, 9, 7, 15);
+                            break;
+                        case INTERSECT_LINE_NO:
+                            break;
+                        case INTERSECT_QUAD_LINE:
+                            f.push(7, 8, 0, 9);
+                            break;
+                        case INTERSECT_QUAD_LINE_2:
+                            f.push(7, 8, 0, 12);
+                            f.push(10, 11, 9, 17);
+                            break;
+                        case INTERSECT_QUAD_LINE_NO:
+                            break;
+                        case INTERSECT_QUAD:
+                            f.push(7, 8, 0, 9);
+                            break;
+                        case INTERSECT_QUAD_2:
+                            f.push(7, 8, 0, 12);
+                            f.push(10, 11, 9, 19);
+                            break;
+                        case INTERSECT_QUAD_NO:
+                            break;
+                        case INTERSECT_SELF_CUBIC:
+                            f.push(9, 10, 0, 11);
+                            break;
+                        case INTERSECT_SELF_CUBIC_NO:
+                            break;
+                        case INTERSECT_CUBIC_LINE:
+                            f.push(9, 10, 0, 11);
+                            break;
+                        case INTERSECT_CUBIC_LINE_2:
+                            f.push(9, 10, 0, 14);
+                            f.push(12, 13, 11, 19);
+                            break;
+                        case INTERSECT_CUBIC_LINE_3:
+                            f.push(9, 10, 0, 17);
+                            f.push(12, 13, 11, 22);
+                            f.push(15, 16, 14, 23);
+                            break;
+                        case INTERSECT_CUBIC_LINE_NO:
+                            break;
+                        case INTERSECT_CUBIC:
+                            f.push(9, 10, 0, 11);
+                            break;
+                        case INTERSECT_CUBIC_2:
+                            f.push(9, 10, 0, 14);
+                            f.push(12, 13, 11, 23);
+                            break;
+                        case INTERSECT_CUBIC_3:
+                            f.push(9, 10, 0, 17);
+                            f.push(12, 13, 11, 26);
+                            f.push(15, 16, 14, 27);
+                            break;
+                        case INTERSECT_CUBIC_4:
+                            f.push(9, 10, 0, 20);
+                            f.push(12, 13, 11, 29);
+                            f.push(15, 16, 14, 30);
+                            f.push(18, 19, 17, 31);
+                            break;
+                        case INTERSECT_CUBIC_NO:
+                            break;
+                        default:
+                            console.log("unknown REC_TYPE_SECT frag type: " + fragType);
+                            throw "stop execution";
+                    }
+                    for (var idx = 0; idx < f.length; idx += 4) {
+                        drawPoint(frags[f[idx]], frags[f[idx + 1]]);
+                    }
+                    if (!draw_intersectT) {
+                        break;
+                    }
+                    ctx.fillStyle = "red";
+                    for (var idx = 0; idx < f.length; idx += 4) {
+                        drawTAtPointUp(frags[f[idx]], frags[f[idx + 1]], frags[f[idx + 2]]);
+                        drawTAtPointDown(frags[f[idx]], frags[f[idx + 1]], frags[f[idx + 3]]);
+                    }
+                    break;
+                case REC_TYPE_SORT:
+                    if (!draw_sort || testIndex < lastSort) {
+                        continue;
+                    }
+                    ctx.lineWidth = 3;
+                    ctx.strokeStyle = "rgba(127,127,0, 0.5)";
+                    switch (fragType) {
+                        case SORT_LINE:
+                            drawLinePartial(frags[1], frags[2], frags[3], frags[4],
+                                frags[5], frags[6]);
+                            break;
+                        case SORT_QUAD:
+                            drawQuadPartial(frags[1], frags[2], frags[3], frags[4],
+                                frags[5], frags[6], frags[7], frags[8]);
+                            break;
+                        case SORT_CUBIC:
+                            drawCubicPartial(frags[1], frags[2], frags[3], frags[4],
+                                frags[5], frags[6], frags[7], frags[8], frags[9], frags[10]);
+                            break;
+                    }
+                    break;
+                case REC_TYPE_MARK:
+                    if (!draw_mark || testIndex < lastMark) {
+                        continue;
+                    }
+                    ctx.lineWidth = 3;
+                    ctx.strokeStyle = fragType >= MARK_DONE_LINE ?
+                            "rgba(127,0,127, 0.5)" : "rgba(127,127,0, 0.5)";
+                    switch (fragType) {
+                        case MARK_LINE:
+                            drawLinePartial(frags[1], frags[2], frags[3], frags[4],
+                                frags[5], frags[9]);
+                            break;
+                        case MARK_QUAD:
+                            drawQuadPartial(frags[1], frags[2], frags[3], frags[4],
+                                frags[5], frags[6], frags[7], frags[11]);
+                            break;
+                        case MARK_CUBIC:
+                            drawCubicPartial(frags[1], frags[2], frags[3], frags[4],
+                                frags[5], frags[6], frags[7], frags[8], frags[9], frags[13]);
+                            break;
+                        case MARK_DONE_LINE:
+                            drawLinePartial(frags[1], frags[2], frags[3], frags[4],
+                                frags[5], frags[9]);
+                            break;
+                        case MARK_DONE_QUAD:
+                            drawQuadPartial(frags[1], frags[2], frags[3], frags[4],
+                                frags[5], frags[6], frags[7], frags[11]);
+                            break;
+                        case MARK_DONE_CUBIC:
+                            drawCubicPartial(frags[1], frags[2], frags[3], frags[4],
+                                frags[5], frags[6], frags[7], frags[8], frags[9], frags[13]);
+                            break;
+                    }
+                    break;
+                default:
+                    continue;
             }
         }
-        if (debug_xy && selected) {
-            var debugText = "";
-            for (var typeIndex = 0; typeIndex < types.length; ++typeIndex) {
-                var type = types[typeIndex];
-                var index = pts[typeIndex];
-                for (var idx = pts[typeIndex]; idx < pts[typeIndex] + (type + 1) * 2; idx += 2) {
-                    var screenX = (scan[idx] - srcLeft) * scale;
-                    var screenY = (scan[idx + 1] - srcTop) * scale;
-                    debugText += screenX.toFixed(decimal_places) + ", ";
-                    debugText += screenY.toFixed(decimal_places) + " ";
-                }
-            }
-            ctx.fillStyle="blue";
-            ctx.fillText(debugText, 50, partIndex * 50 + 100);
-        }
-        if (ptLabels && selected) {
-            ctx.fillStyle="blue";
-            for (var typeIndex = 0; typeIndex < types.length; ++typeIndex) {
-                var type = types[typeIndex];
-                var index = pts[typeIndex];
-                for (var idx = pts[typeIndex]; idx < pts[typeIndex] + (type + 1) * 2; idx += 2) {
-                    drawPoint(scan[idx], scan[idx + 1]);
-                }
-            }
-        }
-        var infoText = "";
-        if (info_mode && selected) {
-            infoText += hasId >= 0 ? "id=" + scan[hasId] : partIndex;
-        }
-        if (intersect_mode && selected) {
-            if (scanType == ACTIVE_CUBIC_SPAN) {
-                infoText += " t=" + scan[SPAN_C_T];
-            } else if (scanType == ACTIVE_QUAD_SPAN) {
-                infoText += " t=" + scan[SPAN_Q_T];
-            } else if (scanType == ACTIVE_LINE_SPAN) {
-                infoText += " t=" + scan[SPAN_L_T];
-            } else if (scanType == INTERSECT_QUAD_LINE ||scanType == INTERSECT_QUAD) {
-                infoText += " t0[0]=" + scan[1] + " t1[0]=" + scan[10];
-            } else if (scanType == INTERSECT_QUAD_LINE_2 || scanType == INTERSECT_QUAD_2) {
-                infoText += " t0[0]=" + scan[1] + " t0[1]=" + scan[10] + " t1[0]=" + scan[13];
-                if (scanType == INTERSECT_QUAD_LINE_2) {
-                    infoText += " t1[1]=" + scan[18];
-                } else {
-                    infoText += " t0[1]=" + scan[20];
-                }
-            }
-        }
-        if (infoText.length > 0) {
-            ctx.fillStyle="green";
-            ctx.fillText(infoText, 10, (hasId >= 0 && sequence >= 0
-                    ? hasId : partIndex) * 30 + 50);
-        }
-        if (intersect_mode && selected) {
-            ctx.fillStyle="rgba(50,100,200, 1.0)";
-            if (scanType == ACTIVE_CUBIC_SPAN) {
-                drawPoint(scan[SPAN_C_TX], scan[SPAN_C_TY]);
-            } else if (scanType == ACTIVE_QUAD_SPAN) {
-                drawPoint(scan[SPAN_Q_TX], scan[SPAN_Q_TY]);
-            } else if (scanType == ACTIVE_LINE_SPAN) {
-                drawPoint(scan[SPAN_L_TX], scan[SPAN_L_TY]);
-            } else if (scanType != INTERSECT_QUAD_NO && scanType != INTERSECT_QUAD_LINE_NO) {
-                drawPoint(scan[8], scan[9]);
-                if (scanType == INTERSECT_QUAD_LINE_2 || scanType == INTERSECT_QUAD_2) {
-                    drawPoint(scan[11], scan[12]);
-                }
-            }
-        }
-        ctx.strokeStyle = "rgba(0,0,0, 0.2)";
-        scanType = -1;
     }
-    drawDeferred();
-    drawPartial(test);
+    if (draw_log && logStart >= 0) {
+        ctx.font = "normal 10px Arial";
+        ctx.beginPath();
+        ctx.rect(50,550, 200,30);
+        ctx.fillStyle = "white";
+        ctx.fill();
+        ctx.fillStyle = "rgba(0,0,0, 0.5)";
+        if (logStart > 0) {
+            ctx.fillText(lines[logStart - 1], 50, 558);
+        }
+        ctx.fillStyle = "black";
+        for (var idx = 0; idx < logRange; ++idx) {
+            ctx.fillText(lines[logStart + idx], 50, 568 + 10 * idx);
+        }
+        ctx.fillStyle = "rgba(0,0,0, 0.5)";
+        if (logStart + logRange < lines.length) {
+            ctx.fillText(lines[logStart + logRange], 50, 568 + 10 * logRange);
+        }
+    }
+    if (draw_legend) {
+        var pos = 0;
+        drawBox(pos++, "yellow", "black", opLetter, true, '');
+        drawBox(pos++, "rgba(0,0,255, 0.3)", "black", "X", draw_intersection, intersectionKey);
+        drawBox(pos++, "rgba(0,0,255, 0.3)", "black", "+", draw_add, addKey);
+        drawBox(pos++, "rgba(0,0,255, 0.3)", "black", activeCount, draw_active, activeKey);
+        drawBox(pos++, "rgba(127,127,0, 0.3)", "black", sortCount, draw_sort, sortKey);
+        drawBox(pos++, "rgba(127,0,127, 0.3)", "black", markCount, draw_mark, markKey);
+        drawBox(pos++, "black", "white", "P", draw_path, pathKey);
+        var computedLabel = ['Q', 'Q', 'C', 'QC'];
+        drawBox(pos++, "rgba(0,63,0, 0.7)", "white", (new Array('Q', 'Q', 'C', 'QC'))[draw_computed],
+                draw_computed != 0, computedKey);
+        drawBox(pos++, "green", "black", curStep, true, '');
+        drawBox(pos++, "green", "black", step_limit, true, '');
+        drawBox(pos++, "red", "black", lastIndex, true, '');
+        drawBox(pos++, "red", "black", test.length - 1, true, '');
+        if (curve_t) {
+            drawCurveTControl();
+        }
+    }
+}
+
+function drawBox(y, backC, foreC, str, enable, label) {
+    ctx.beginPath();
+    ctx.fillStyle = backC;
+    ctx.rect(ctx.canvas.width - 40, y * 50 + 50, 40, 30);
+    ctx.fill();
+    ctx.font = "normal 16px Arial";
+    ctx.fillStyle = foreC;
+    ctx.textAlign = "center";
+    ctx.fillText(str, ctx.canvas.width - 20, y * 50 + 72);
+    if (!enable) {
+        ctx.fillStyle = "rgba(255,255,255, 0.5)";
+        ctx.fill();
+    }
+    if (label != '') {
+        ctx.font = "normal 9px Arial";
+        ctx.fillStyle = "black";
+        ctx.fillText(label, ctx.canvas.width - 47, y * 50 + 80);
+    }
+    ctx.textAlign = "left";
+}
+
+function drawCurveTControl() {
+    ctx.lineWidth = 2;
+    ctx.strokeStyle = "rgba(0,0,0, 0.3)";
+    ctx.beginPath();
+    ctx.rect(ctx.canvas.width - 80, 40, 28, ctx.canvas.height - 80);
+    ctx.stroke();
+    var ty = 40 + curveT * (ctx.canvas.height - 80);
+    ctx.beginPath();
+    ctx.moveTo(ctx.canvas.width - 80, ty);
+    ctx.lineTo(ctx.canvas.width - 85, ty - 5);
+    ctx.lineTo(ctx.canvas.width - 85, ty + 5);
+    ctx.lineTo(ctx.canvas.width - 80, ty);
+    ctx.fillStyle = "rgba(0,0,0, 0.6)";
+    ctx.fill();
+    var num = curveT.toFixed(decimal_places);
+    ctx.font = "normal 10px Arial";
+    ctx.fillText(num, ctx.canvas.width - 78, ty);
+}
+
+function ptInTControl() {
+    var e = window.event;
+	var tgt = e.target || e.srcElement;
+    var left = tgt.offsetLeft;
+    var top = tgt.offsetTop;
+    var x = (e.clientX - left);
+    var y = (e.clientY - top);
+    if (x < ctx.canvas.width - 80 || x > ctx.canvas.width - 50) {
+        return false;
+    }
+    if (y < 40 || y > ctx.canvas.height - 80) {
+        return false;
+    }
+    curveT = (y - 40) / (ctx.canvas.height - 120);
+    if (curveT < 0 || curveT > 1) {
+        throw "stop execution";
+    }
+    return true;
 }
 
 function drawTop() {
@@ -1112,12 +1659,35 @@
 
 function redraw() {
     ctx.beginPath();
+    ctx.fillStyle = "white";
     ctx.rect(0, 0, ctx.canvas.width, ctx.canvas.height);
-    ctx.fillStyle="white";
     ctx.fill();
-    draw(tests[testIndex], testTitles[testIndex]);
+    draw(tests[testIndex], testLines[testIndex], testTitles[testIndex]);
 }
 
+var activeKey = 'a';
+var addKey = 'd';
+var centerKey = 'c';
+var computedKey = 'q';
+var computedBackKey = 'Q';
+var controlLinesKey = 'v';
+var curveTKey = 'u';
+var intersectTKey = 't';
+var intersectionKey = 'i';
+var infoKey = 'f';
+var logKey = 'l';
+var markKey = 'm';
+var nextBy10Key = 'N';
+var nextKey = 'n';
+var pathKey = 'b';
+var previousBy10Key = 'P';
+var previousKey = 'p';
+var ptsKey = 'x';
+var sortKey = 'o';
+var stepBackKey = 'S';
+var stepKey = 's';
+var xyKey = 'y';
+
 function doKeyPress(evt) {
     var char = String.fromCharCode(evt.charCode);
     switch (char) {
@@ -1131,70 +1701,95 @@
     case '7':
     case '8':
     case '9':
-        if (digit_mode) {
-            decimal_places = char - '0';
-        } else if (index_mode) {
-            index_bits ^= 1 << (char - '0');
-        }
+        decimal_places = char - '0';
         redraw();
         break;
-    case 'd':
-        digit_mode = true;
-        index_mode = false;
+    case activeKey:
+        draw_active ^= true;
+        redraw(); 
         break;
-    case 'f':
+    case centerKey:
+        setScale();
+        redraw(); 
+        break;
+    case controlLinesKey:
+        control_lines ^= true;
+        redraw(); 
+        break;
+    case curveTKey:
+        curve_t ^= true;
+        redraw();
+        break;
+    case computedBackKey:
+        draw_computed = (draw_computed - 1) & 3; // four-state
+        redraw(); 
+        break;
+    case computedKey:
+        draw_computed = (draw_computed + 1) & 3; // four-state
+        redraw(); 
+        break;
+    case pathKey:
+        draw_path ^= true;
+        redraw(); 
+        break;
+    case addKey:
+        draw_add ^= true;
+        redraw(); 
+        break;
+    case infoKey:
         info_mode ^= true;
         redraw();
         break;
-    case 'i':
-        digit_mode = false;
-        if (sequence >= 0) {
-            sequence = -1;
-            index_mode = false;
-        } else {
-            index_mode ^= true;
-        }
-        if (index_mode) {
-            index_bits = 0;
-        } else {
-            index_bits = -1;
-        }
+    case intersectionKey:
+        draw_intersection ^= true;
+        redraw(); 
+        break;
+    case logKey:
+        draw_log ^= true;
         redraw();
         break;
-    case 'N':
+    case markKey:
+        draw_mark ^= true;
+        redraw();
+        break;
+    case nextBy10Key:
         testIndex += 9;
-    case 'n':
+    case nextKey:
         if (++testIndex >= tests.length)
             testIndex = 0;
         drawTop();
         break;
-    case 'P':
+    case previousBy10Key:
         testIndex -= 9;
-    case 'p':
+    case previousKey:
         if (--testIndex < 0)
             testIndex = tests.length - 1;
         drawTop();
         break;
-    case 's':
-        sequence++;
+    case stepKey:
+        step_limit++;
         redraw();
         break;
-    case 'S':
-        sequence--;
-        if (sequence < 0) {
-            sequence = 0;
+    case stepBackKey:
+        step_limit--;
+        if (step_limit < 0) {
+            step_limit = 0;
         }
         redraw();
         break;
-    case 't':
-        intersect_mode ^= true;
+    case sortKey:
+        draw_sort ^= true;
         redraw();
         break;
-    case 'x':
-        ptLabels ^= true;
+    case intersectTKey:
+        draw_intersectT ^= true;
         redraw();
         break;
-    case 'y':
+    case ptsKey:
+        pt_labels ^= true;
+        redraw();
+        break;
+    case xyKey:
         debug_xy ^= true;
         redraw();
         break;
@@ -1209,6 +1804,11 @@
         calcLeftTop();
         redraw();
         break;
+    case '/':
+    case '?':
+        draw_legend ^= true;
+        redraw();
+        break;
     }
 }
 
@@ -1217,7 +1817,6 @@
 	var tgt = e.target || e.srcElement;
     var left = tgt.offsetLeft;
     var top = tgt.offsetTop;
-    var unit = scale;
     mouseX = (e.clientX - left) / scale + srcLeft;
     mouseY = (e.clientY - top) / scale + srcTop;
 }
@@ -1228,13 +1827,18 @@
 }
 
 function handleMouseClick() {
-    calcXY();
-    calcLeftTop();
+    if (!curve_t || !ptInTControl()) {
+        calcXY();
+        calcLeftTop();
+    }
     redraw();
 }
 
 function handleMouseOver() {
     calcXY();
+    if (!debug_xy) {
+        return;
+    }
     var num = mouseX.toFixed(decimal_places) + ", " + mouseY.toFixed(decimal_places);
     ctx.beginPath();
     ctx.rect(300,100,200,10);
@@ -1249,8 +1853,8 @@
         var title = testDivs[i].id.toString();
         var str = testDivs[i].firstChild.data;
         parse_all(str, title);
-        parse_debugShowActiveSpans(str, title);
-        parse_intersections(str, title);
+ //       parse_debugShowActiveSpans(str, title);
+ //       parse_intersections(str, title);
     }
     drawTop();
     window.addEventListener('keypress', doKeyPress, true);