blob: c8a50bb3e5730dcd5aa0e914d77515fb74e0fbbf [file] [log] [blame]
caryclark@google.comf839c032012-10-26 21:03:50 +00001<html>
2<head>
3<div style="height:0">
4
caryclark@google.comc83c70e2013-02-22 21:50:07 +00005<div id="cubicOp25i">
6debugShowActiveSpans 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
7debugShowActiveSpans 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
8</div>
9
caryclark@google.com47d73da2013-02-17 01:41:25 +000010<div id="cubicOp19i">
11debugShowActiveSpans 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
12debugShowActiveSpans 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
13debugShowActiveSpans 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
14debugShowActiveSpans id=4 (1,0 1,2) t=0 (1,0) tEnd=0.637627564 other=3 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0
15debugShowActiveSpans 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
16debugShowActiveSpans 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
17debugShowActiveSpans 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
18debugShowActiveSpans 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
19debugShowActiveSpans id=2 (6,2 0,2) t=0 (6,2) tEnd=0.711411698 other=1 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0
20debugShowActiveSpans 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
21debugShowActiveSpans id=2 (6,2 0,2) t=0.833333333 (1,2) tEnd=1 other=3 otherT=0 otherIndex=1 windSum=? windValue=1 oppValue=0
caryclark@google.com0b7da432012-10-31 19:00:20 +000022</div>
23
caryclark@google.comc83c70e2013-02-22 21:50:07 +000024<div id="cubicOp28u">
25debugShowActiveSpans 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
26debugShowActiveSpans 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
27debugShowActiveSpans 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
28debugShowActiveSpans id=4 (4,1 0,6) t=0 (4,1) tEnd=0.13678207 other=3 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0
29debugShowActiveSpans 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
30debugShowActiveSpans 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
31debugShowActiveSpans 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
32debugShowActiveSpans 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
33debugShowActiveSpans 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
34debugShowActiveSpans 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
35debugShowActiveSpans 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
36debugShowActiveSpans 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
37debugShowActiveSpans 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
38debugShowActiveSpans id=2 (3,2 0,1) t=0 (3,2) tEnd=0.0604518624 other=1 otherT=1 otherIndex=7 windSum=? windValue=1 oppValue=0
39debugShowActiveSpans 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
40debugShowActiveSpans 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
41</div>
42
caryclark@google.com7ff5c842013-02-26 15:56:05 +000043<div id="cubicOp31d">
44debugShowActiveSpans 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
45debugShowActiveSpans 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
46debugShowActiveSpans 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
47debugShowActiveSpans 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
48debugShowActiveSpans 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
49debugShowActiveSpans 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
50debugShowActiveSpans 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
51debugShowActiveSpans 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
52</div>
53
54<div id="cubicOp31da">
55debugShowActiveSpans 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
56debugShowActiveSpans 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
57debugShowActiveSpans 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
58debugShowActiveSpans 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
59debugShowActiveSpans 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
60debugShowActiveSpans 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
61</div>
62
caryclark@google.com4aaaaea2013-02-28 16:12:39 +000063<div id="cubicOp35d">
64 SimplifyNew_Test [cubicOp35d]
65debugShowCubicIntersection no self intersect {{0,1}, {1,5}, {2,1}, {4,0}}
66debugShowCubicLineIntersection 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
67debugShowCubicIntersection 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
68debugShowCubicLineIntersection wtTs[0]=0.646900486 {{0,1}, {1,5}, {2,1}, {4,0}} {{2.2114165293341985,1.6971458676664504}} wnTs[0]=0.697146 {{5,1}, {1,2}}
69debugShowCubicLineIntersection no intersect {{1,2}, {0,4}, {1,0}, {5,1}} {{4,0}, {0,1}}
70debugShowLineIntersection no intersect {{4,0}, {0,1}} {{5,1}, {1,2}}
71debugShowCubicIntersection wtTs[0]=0.002763735 {{1,2}, {0,4}, {1,0}, {5,1}} {{0.9917546455060533,2.0164451540317003}} wtTs[1]=0.461521979
72debugShowCubicLineIntersection 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
73debugShowActiveSpans 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
74debugShowActiveSpans 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
75debugShowActiveSpans 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
76debugShowActiveSpans 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
77debugShowActiveSpans id=2 (4,0 0,1) t=0 (4,0) tEnd=1 other=1 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0
78debugShowActiveSpans 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
79debugShowActiveSpans 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
80debugShowActiveSpans 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
81debugShowActiveSpans 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
82debugShowActiveSpans 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
83debugShowActiveSpans 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
84debugShowActiveSpans id=4 (5,1 1,2) t=0 (5,1) tEnd=0.697145868 other=3 otherT=1 otherIndex=6 windSum=? windValue=1 oppValue=0
85debugShowActiveSpans 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
86debugShowActiveSpans 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
87findTop debugShowSort contourWinding=0 oppContourWinding=0 sign=-1
88debugShowSort [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
89debugShowSort [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
90markWinding id=2 (4,0 0,1) t=0 [0] (4,0) newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1
91markWinding 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
92markWinding id=2 (4,0 0,1) t=0 [0] (4,0) newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1
93markWinding id=1 (0,1 1,5 2,1 4,0) t=0 [0] (0,1) newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1
94activeOp op=diff miFrom=1 miTo=0 suFrom=0 suTo=0 result=1
95findNextOp simple
96markDoneBinary id=2 (4,0 0,1) t=0 [0] (4,0) newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1
97bridgeOp current id=2 from=(0,1) to=(4,0)
98findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=-1
99debugShowSort [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
100debugShowSort [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
101debugShowSort [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
102debugShowSort [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
103findNextOp firstIndex=[1] sign=-1
104activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
105markWinding 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
106findNextOp chase.append id=3
107activeOp op=diff miFrom=1 miTo=0 suFrom=1 suTo=1 result=0
108markDoneBinary 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
109findNextOp chase.append id=1
110activeOp op=diff miFrom=0 miTo=0 suFrom=1 suTo=0 result=0
111markDoneBinary 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
112markDoneBinary id=4 (5,1 1,2) t=0 [0] (5,1) newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1
113findNextOp chase.append id=4
114markDoneBinary 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
115findNextOp from:[1] to:[3] start=5 end=4
116bridgeOp current id=1 from=(4,0) to=(2.85658813,0.932087123)
117path.moveTo(0,1);
118path.lineTo(4,0);
119path.cubicTo(3.57735038,0.211324871, 3.1993587,0.556624353, 2.85658813,0.932087123);
120findNextOp debugShowSort contourWinding=-1 oppContourWinding=1 sign=-1
121debugShowSort [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
122debugShowSort [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
123debugShowSort [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
124debugShowSort [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
125findNextOp firstIndex=[1] sign=-1
126activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
127markWinding id=4 (5,1 1,2) t=0.997925926 [2] (1.00829625,1.99792588) newWindSum=1 newOppSum=1 oppSum=? windSum=? windValue=1
128markWinding id=3 (1,2 0,4 1,0 5,1) t=0 [0] (1,2) newWindSum=1 newOppSum=1 oppSum=? windSum=? windValue=1
129findNextOp chase.append id=3
130activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
131markWinding 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
132findNextOp chase.append id=3
133activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
134markWinding id=4 (5,1 1,2) t=0.697145868 [1] (2.21141648,1.69714582) newWindSum=-1 newOppSum=1 oppSum=? windSum=? windValue=1
135findNextOp chase.append id=4
136markDoneBinary 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
137findNextOp from:[3] to:[4] start=2 end=3
138bridgeOp current id=3 from=(2.85658813,0.932087123) to=(1.00829625,1.99792588)
139path.cubicTo(1.96246409,1.13237906, 1.35749662,1.61008465, 1.00829625,1.99792588);
140findNextOp simple
141markDoneBinary id=4 (5,1 1,2) t=0.997925926 [2] (1.00829625,1.99792588) newWindSum=1 newOppSum=1 oppSum=1 windSum=1 windValue=1
142bridgeOp current id=4 from=(1.00829625,1.99792588) to=(1,2)
143Program received signal: “EXC_BAD_ACCESS”.
144findNextOp debugShowSort contourWinding=1 oppContourWinding=1 sign=1
145debugShowSort [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
146debugShowSort [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
147debugShowSort [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
148debugShowSort [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
149findNextOp firstIndex=[1] sign=1
150activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
151markWinding 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
152findNextOp chase.append id=3
153activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
154markWinding 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
155findNextOp chase.append id=3
156activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
157markDoneBinary 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
158findNextOp from:[3] to:[3] start=3 end=2
159bridgeOp current id=3 from=(1,2) to=(0.991754651,2.01644516)
160path.lineTo(1,2);
161path.cubicTo(0.997236252,2.0055275, 0.994487822,2.01100922, 0.991754651,2.01644516);
162findNextOp debugShowSort contourWinding=-1 oppContourWinding=1 sign=-1
163debugShowSort [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
164debugShowSort [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
165debugShowSort [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
166debugShowSort [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
167findNextOp firstIndex=[0] sign=-1
168activeOp op=diff miFrom=1 miTo=0 suFrom=0 suTo=0 result=1
169activeOp op=diff miFrom=0 miTo=0 suFrom=0 suTo=1 result=0
170activeOp op=diff miFrom=0 miTo=1 suFrom=1 suTo=1 result=0
171markDoneBinary 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
172findNextOp chase.append id=1
173markDoneBinary 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
174findNextOp from:[3] to:[1] start=1 end=0
175bridgeOp current id=3 from=(0.991754651,2.01644516) to=(0.640381813,2.56467652)
176path.cubicTo(0.739642859,2.30096555, 0.627014875,2.53316927, 0.640381813,2.56467652);
177findNextOp simple
178markDoneBinary 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
179bridgeOp current id=1 from=(0.640381813,2.56467652) to=(0,1)
180path.cubicTo(0.42071557,2.32885909, 0.2103578,1.84143114, 0,1);
181path.close();
182debugShowActiveSpans 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
183debugShowActiveSpans 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
184debugShowActiveSpans 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
185activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
186findNextOp debugShowSort contourWinding=0 oppContourWinding=1 sign=1
187debugShowSort [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
188debugShowSort [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
189debugShowSort [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
190debugShowSort [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
191findNextOp firstIndex=[0] sign=1
192activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
193activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
194activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
195markDoneBinary id=4 (5,1 1,2) t=0.697145868 [1] (2.21141648,1.69714582) newWindSum=-1 newOppSum=1 oppSum=1 windSum=-1 windValue=1
196findNextOp from:[4] to:[3] start=4 end=3
197bridgeOp current id=4 from=(2.21141648,1.69714582) to=(1.00829625,1.99792588)
198findNextOp debugShowSort contourWinding=0 oppContourWinding=1 sign=-1
199debugShowSort [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
200debugShowSort [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
201debugShowSort [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
202debugShowSort [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
203findNextOp firstIndex=[0] sign=-1
204activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
205activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=1 result=1
206activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
207markDoneBinary 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
208findNextOp from:[3] to:[3] start=1 end=2
209bridgeOp current id=3 from=(1.00829625,1.99792588) to=(0.991754651,2.01644516)
210path.moveTo(2.21141648,1.69714582);
211path.lineTo(1.00829625,1.99792588);
212path.cubicTo(1.00271726,2.0041225, 0.99720329,2.01029587, 0.991754651,2.01644516);
213findNextOp debugShowSort contourWinding=0 oppContourWinding=1 sign=1
214debugShowSort [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
215debugShowSort [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
216debugShowSort [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
217debugShowSort [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
218findNextOp firstIndex=[2] sign=1
219activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=1 result=0
220activeOp op=diff miFrom=1 miTo=1 suFrom=1 suTo=0 result=1
221activeOp op=diff miFrom=1 miTo=1 suFrom=0 suTo=0 result=0
222markDoneBinary 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
223findNextOp from:[3] to:[3] start=2 end=3
224bridgeOp current id=3 from=(0.991754651,2.01644516) to=(0.640381813,2.56467652)
225path.cubicTo(0.773483634,2.45056915, 0.652775407,2.59388947, 0.640381813,2.56467652);
226</div>
227
caryclark@google.comf839c032012-10-26 21:03:50 +0000228</div>
229
230<script type="text/javascript">
231
232var testDivs = [
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000233 cubicOp35d,
caryclark@google.com7ff5c842013-02-26 15:56:05 +0000234 cubicOp31da,
235 cubicOp31d,
caryclark@google.comc83c70e2013-02-22 21:50:07 +0000236 cubicOp28u,
237 cubicOp25i,
caryclark@google.com47d73da2013-02-17 01:41:25 +0000238 cubicOp19i,
caryclark@google.comf839c032012-10-26 21:03:50 +0000239];
240
241var decimal_places = 3; // make this 3 to show more precision
242
243var tests = [];
244var testTitles = [];
245var testIndex = 0;
246var ctx;
247
248var xmin;
249var ymin;
250var scale;
251var mouseX, mouseY;
252var srcLeft, srcTop;
253var srcWidth, srcHeight;
254var screenWidth, screenHeight;
caryclark@google.com47d73da2013-02-17 01:41:25 +0000255var drawnPts, drawnLines, drawnQuads, drawnCubics, deferredLines, deferredQuads, deferredCubics;
caryclark@google.comf839c032012-10-26 21:03:50 +0000256
257var ptLabels = true;
258var digit_mode = false;
259var index_mode = true;
260var index_bits = -1;
261var debug_xy = false;
262var info_mode = false;
263var intersect_mode = false;
264var sequence = -1;
265
266var SPAN_ID = 1;
267var SPAN_X1 = 2;
268var SPAN_Y1 = 3;
269var SPAN_X2 = 4;
270var SPAN_Y2 = 5;
271var SPAN_L_T = 6;
272var SPAN_L_TX = 7;
273var SPAN_L_TY = 8;
caryclark@google.com47d73da2013-02-17 01:41:25 +0000274var SPAN_L_TEND = 9;
275var SPAN_L_OTHER = 10;
276var SPAN_L_OTHERT = 11;
277var SPAN_L_OTHERI = 12;
278var SPAN_L_SUM = 13;
279var SPAN_L_VAL = 14;
280var SPAN_L_OPP = 15;
caryclark@google.comf839c032012-10-26 21:03:50 +0000281
282var SPAN_X3 = 6;
283var SPAN_Y3 = 7;
284var SPAN_Q_T = 8;
285var SPAN_Q_TX = 9;
286var SPAN_Q_TY = 10;
caryclark@google.com47d73da2013-02-17 01:41:25 +0000287var SPAN_Q_TEND = 11;
288var SPAN_Q_OTHER = 12;
289var SPAN_Q_OTHERT = 13;
290var SPAN_Q_OTHERI = 14;
291var SPAN_Q_SUM = 15;
292var SPAN_Q_VAL = 16;
293var SPAN_Q_OPP = 17;
294
295var SPAN_X4 = 8;
296var SPAN_Y4 = 9;
297var SPAN_C_T = 10;
298var SPAN_C_TX = 11;
299var SPAN_C_TY = 12;
300var SPAN_C_TEND = 13;
301var SPAN_C_OTHER = 14;
302var SPAN_C_OTHERT = 15;
303var SPAN_C_OTHERI = 16;
304var SPAN_C_SUM = 17;
305var SPAN_C_VAL = 18;
306var SPAN_C_OPP = 19;
caryclark@google.comf839c032012-10-26 21:03:50 +0000307
caryclark@google.com0b7da432012-10-31 19:00:20 +0000308var ACTIVE_LINE_SPAN = 1;
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000309var ACTIVE_QUAD_SPAN = ACTIVE_LINE_SPAN + 1;
310var ACTIVE_CUBIC_SPAN = ACTIVE_QUAD_SPAN + 1;
311
312var PATH_MOVETO = ACTIVE_CUBIC_SPAN + 1;
313var PATH_LINETO = PATH_MOVETO + 1;
314var PATH_QUADTO = PATH_LINETO + 1;
315var PATH_CUBICTO = PATH_QUADTO + 1;
316var PATH_CLOSE = PATH_CUBICTO + 1;
317
318var INTERSECT_LINE = PATH_CLOSE + 1;
319var INTERSECT_LINE_2 = INTERSECT_LINE + 1;
320var INTERSECT_LINE_NO = INTERSECT_LINE_2 + 1;
321var INTERSECT_QUAD_LINE = INTERSECT_LINE_NO + 1;
322var INTERSECT_QUAD_LINE_2 = INTERSECT_QUAD_LINE + 1;
323var INTERSECT_QUAD_LINE_NO = INTERSECT_QUAD_LINE_2 + 1;
324var INTERSECT_QUAD = INTERSECT_QUAD_LINE_NO + 1;
325var INTERSECT_QUAD_2 = INTERSECT_QUAD + 1;
326var INTERSECT_QUAD_NO = INTERSECT_QUAD_2 + 1;
327var INTERSECT_SELF_CUBIC = INTERSECT_QUAD_NO + 1;
328var INTERSECT_SELF_CUBIC_NO = INTERSECT_SELF_CUBIC + 1;
329var INTERSECT_CUBIC_LINE = INTERSECT_SELF_CUBIC_NO + 1;
330var INTERSECT_CUBIC_LINE_2 = INTERSECT_CUBIC_LINE + 1;
331var INTERSECT_CUBIC_LINE_3 = INTERSECT_CUBIC_LINE_2 + 1;
332var INTERSECT_CUBIC_LINE_NO = INTERSECT_CUBIC_LINE_3 + 1;
333// FIXME: add cubic/quad
334var INTERSECT_CUBIC = INTERSECT_CUBIC_LINE_NO + 1;
335var INTERSECT_CUBIC_2 = INTERSECT_CUBIC + 1;
336var INTERSECT_CUBIC_3 = INTERSECT_CUBIC_2 + 1;
337var INTERSECT_CUBIC_4 = INTERSECT_CUBIC_3 + 1;
338// FIXME: add cubic 5- 9
339var INTERSECT_CUBIC_NO = INTERSECT_CUBIC_4 + 1;
340
341var SORT_LINE = INTERSECT_CUBIC_NO + 1;
342var SORT_QUAD = SORT_LINE + 1;
343var SORT_CUBIC = SORT_QUAD + 1;
344
345var REC_TYPE_UNKNOWN = -1;
346var REC_TYPE_PATH = 0;
347var REC_TYPE_SECT = 1;
348var REC_TYPE_ACTIVE = 2;
349var REC_TYPE_ADD = 3;
350var REC_TYPE_SORT = 4;
caryclark@google.comf839c032012-10-26 21:03:50 +0000351
352function strs_to_nums(strs) {
353 var result = [];
354 for (var idx in strs) {
355 var str = strs[idx];
356 var num = parseFloat(str);
357 if (isNaN(num)) {
358 result.push(str);
359 } else {
360 result.push(num);
361 }
362 }
363 return result;
364}
365
caryclark@google.com0b7da432012-10-31 19:00:20 +0000366function construct_regexp(pattern) {
367 var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
368 escape = escape.replace(/PT_VAL/g, "(\\d+\\.?\\d*),(\\d+\\.?\\d*)");
369 escape = escape.replace(/T_VAL/g, "(\\d+\\.?\\d*e?-?\\d*)");
370 escape = escape.replace(/IDX/g, "(\\d+)");
371 escape = escape.replace(/OPT/g, "(\\?|-?\\d+)");
372 return new RegExp(escape, 'i');
373}
374
caryclark@google.comf839c032012-10-26 21:03:50 +0000375function parse_debugShowActiveSpans(test, title) {
caryclark@google.com47d73da2013-02-17 01:41:25 +0000376 var re_cubic = construct_regexp(" id=IDX (PT_VAL PT_VAL PT_VAL PT_VAL) t=T_VAL (PT_VAL) tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=IDX");
377 var re_quad = construct_regexp(" id=IDX (PT_VAL PT_VAL PT_VAL) t=T_VAL (PT_VAL) tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=IDX");
378 var re_line = construct_regexp(" id=IDX (PT_VAL PT_VAL) t=T_VAL (PT_VAL) tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=IDX");
caryclark@google.comf839c032012-10-26 21:03:50 +0000379
380 var strs = test.split("debugShowActiveSpans");
381 if (strs.length == 1)
382 return;
383 var spans = [];
384 for (var s in strs) {
385 var str = strs[s];
386 if (str == "\n") {
387 continue;
388 }
389 if (re_line.test(str)) {
390 var lineStrs = re_line.exec(str);
391 var line = strs_to_nums(lineStrs);
caryclark@google.com0b7da432012-10-31 19:00:20 +0000392 spans.push(ACTIVE_LINE_SPAN);
caryclark@google.comf839c032012-10-26 21:03:50 +0000393 spans.push(line);
394 } else if (re_quad.test(str)) {
395 var quadStrs = re_quad.exec(str);
396 var quad = strs_to_nums(quadStrs);
caryclark@google.com0b7da432012-10-31 19:00:20 +0000397 spans.push(ACTIVE_QUAD_SPAN);
caryclark@google.comf839c032012-10-26 21:03:50 +0000398 spans.push(quad);
caryclark@google.com47d73da2013-02-17 01:41:25 +0000399 } else if (re_cubic.test(str)) {
400 var cubicStrs = re_cubic.exec(str);
401 var cubic = strs_to_nums(cubicStrs);
402 spans.push(ACTIVE_CUBIC_SPAN);
403 spans.push(cubic);
caryclark@google.comf839c032012-10-26 21:03:50 +0000404 }
405 }
406 if (spans.length >= 1) {
407 tests.push(spans);
408 testTitles.push(title);
409 }
410}
411
caryclark@google.com0b7da432012-10-31 19:00:20 +0000412function filter_str_by(id, str, regex, array) {
413 if (regex.test(str)) {
414 var strs = regex.exec(str);
415 var result = strs_to_nums(strs);
416 array.push(id);
417 array.push(result);
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000418 return true;
caryclark@google.com0b7da432012-10-31 19:00:20 +0000419 }
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000420 return false;
caryclark@google.com0b7da432012-10-31 19:00:20 +0000421}
422
caryclark@google.com47d73da2013-02-17 01:41:25 +0000423// FIXME: add cubic support
caryclark@google.com0b7da432012-10-31 19:00:20 +0000424function parse_intersections(test, title) {
425 var re_quad_line = construct_regexp(" wtTs[0]=T_VAL (PT_VAL PT_VAL PT_VAL) (PT_VAL) wnTs[0]=T_VAL (PT_VAL PT_VAL) (PT_VAL)");
426 var re_quad_line_2 = construct_regexp(" wtTs[0]=T_VAL (PT_VAL PT_VAL PT_VAL) (PT_VAL) wtTs[1]=T_VAL (PT_VAL) wnTs[0]=T_VAL (PT_VAL PT_VAL) (PT_VAL) wnTs[1]=T_VAL (PT_VAL)");
427 var re_quad_line_no_intersect = construct_regexp(" no intersect (PT_VAL PT_VAL PT_VAL) (PT_VAL PT_VAL)");
428 var re_quad = construct_regexp(" wtTs[0]=T_VAL (PT_VAL PT_VAL PT_VAL) (PT_VAL) wnTs[0]=T_VAL (PT_VAL PT_VAL PT_VAL) (PT_VAL)");
429 var re_quad_2 = construct_regexp(" wtTs[0]=T_VAL (PT_VAL PT_VAL PT_VAL) (PT_VAL) wtTs[1]=T_VAL wnTs[0]=T_VAL (PT_VAL PT_VAL PT_VAL) (PT_VAL) wnTs[1]=T_VAL");
430 var re_quad_no_intersect = construct_regexp(" no intersect (PT_VAL PT_VAL PT_VAL) (PT_VAL PT_VAL PT_VAL)");
431
432 var strs = test.split(/debugShow[A-Za-z]+Intersection/);
433 if (strs.length == 1)
434 return;
435 var spans = [];
436 for (var s in strs) {
437 var str = strs[s];
438 if (str == "\n") {
439 continue;
440 }
441 filter_str_by(INTERSECT_QUAD_LINE, str, re_quad_line, spans);
442 filter_str_by(INTERSECT_QUAD_LINE_2, str, re_quad_line_2, spans);
443 filter_str_by(INTERSECT_QUAD_LINE_NO, str, re_quad_line_no_intersect, spans);
444 filter_str_by(INTERSECT_QUAD, str, re_quad, spans);
445 filter_str_by(INTERSECT_QUAD_2, str, re_quad_2, spans);
446 filter_str_by(INTERSECT_QUAD_NO, str, re_quad_no_intersect, spans);
447 }
448 if (spans.length >= 1) {
449 tests.push(spans);
450 testTitles.push(title);
451 }
452}
453
caryclark@google.com4aaaaea2013-02-28 16:12:39 +0000454function construct_regexp2(pattern) {
455 var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
456 escape = escape.replace(/CUBIC_VAL/g, "\\(P_VAL P_VAL P_VAL P_VAL\\)");
457 escape = escape.replace(/QUAD_VAL/g, "\\(P_VAL P_VAL P_VAL\\)");
458 escape = escape.replace(/LINE_VAL/g, "\\(P_VAL P_VAL\\)");
459 escape = escape.replace(/PT_VAL/g, "\\(P_VAL\\)");
460 escape = escape.replace(/P_VAL/g, "(\\d+\\.?\\d*),(\\d+\\.?\\d*)");
461 escape = escape.replace(/T_VAL/g, "(\\d+\\.?\\d*e?-?\\d*)");
462 escape = escape.replace(/IDX/g, "(\\d+)");
463 escape = escape.replace(/NUM/g, "(-?\\d+)");
464 escape = escape.replace(/OPT/g, "(\\?|-?\\d+)");
465 return new RegExp(escape, 'i');
466}
467
468function construct_regexp2c(pattern) {
469 var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
470 escape = escape.replace(/CUBIC_VAL/g, "\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}");
471 escape = escape.replace(/QUAD_VAL/g, "\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}");
472 escape = escape.replace(/LINE_VAL/g, "\\{\\{P_VAL\\}, \\{P_VAL\\}\\}");
473 escape = escape.replace(/PT_VAL/g, "\\{\\{P_VAL\\}\\}");
474 escape = escape.replace(/P_VAL/g, "(\\d+\\.?\\d*),(\\d+\\.?\\d*)");
475 escape = escape.replace(/T_VAL/g, "(\\d+\\.?\\d*e?-?\\d*)");
476 escape = escape.replace(/IDX/g, "(\\d+)");
477 escape = escape.replace(/NUM/g, "(-?\\d+)");
478 escape = escape.replace(/OPT/g, "(\\?|-?\\d+)");
479 return new RegExp(escape, 'i');
480}
481
482function match_regexp(str, lineNo, array, id, pattern) {
483 var regex = construct_regexp2(pattern);
484 if (filter_str_by(id, str, regex, array)) {
485 return true;
486 }
487 regex = construct_regexp2c(pattern);
488 return filter_str_by(id, str, regex, array);
489}
490
491function parse_all(test, title) {
492 var lines = test.match(/[^\r\n]+/g);
493 var records = []; // a rec can be the original paths, a set of intersections, a set of active spans, a sort, or a path add
494 var record = [];
495 var recType = REC_TYPE_UNKNOWN;
496 for (var lineNo in lines) {
497 var line = lines[lineNo];
498 var type = line.lastIndexOf("debugShowSort", 0) === 0 ? REC_TYPE_SORT
499 : line.lastIndexOf("debugShowActiveSpans", 0) === 0 ? REC_TYPE_ACTIVE
500 : line.lastIndexOf("debugShow", 0) === 0 ? REC_TYPE_SECT
501 : line.lastIndexOf("path.", 0) === 0 ? REC_TYPE_ADD
502 : line.lastIndexOf("{{", 0) === 0 ? REC_TYPE_PATH
503 : REC_TYPE_UNKNOWN;
504 if (recType != type) {
505 if (recType != REC_TYPE_UNKNOWN) {
506 records.push(recType);
507 records.push(lineNo);
508 records.push(record);
509 }
510 record = [];
511 recType = type;
512 }
513 var found = false;
514 switch (recType) {
515 case REC_TYPE_ACTIVE:
516 found = match_regexp(line, lineNo, record, ACTIVE_LINE_SPAN, "debugShowActiveSpans" +
517" id=IDX LINE_VAL t=T_VAL PT_VAL tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=IDX"
518 ) || match_regexp(line, lineNo, record, ACTIVE_QUAD_SPAN, "debugShowActiveSpans" +
519" id=IDX QUAD_VAL t=T_VAL PT_VAL tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=IDX"
520 ) || match_regexp(line, lineNo, record, ACTIVE_CUBIC_SPAN, "debugShowActiveSpans" +
521" id=IDX CUBIC_VAL t=T_VAL PT_VAL tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=IDX"
522 );
523 break;
524 case REC_TYPE_ADD:
525 found = match_regexp(line, lineNo, record, PATH_MOVETO, "path.moveToPT_VAL;"
526 ) || match_regexp(line, lineNo, record, PATH_LINETO, "path.lineTo(P_VAL);"
527 ) || match_regexp(line, lineNo, record, PATH_QUADTO, "path.quadTo(P_VAL, P_VAL);"
528 ) || match_regexp(line, lineNo, record, PATH_CUBICTO, "path.cubicTo(P_VAL, P_VAL, P_VAL);"
529 ) || match_regexp(line, lineNo, record, PATH_CLOSE, "path.close();"
530 );
531 break;
532 case REC_TYPE_SECT:
533 found = match_regexp(line, lineNo, record, INTERSECT_LINE, "debugShowLineIntersection" +
534" wtTs[0]=T_VAL LINE_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
535 ) || match_regexp(line, lineNo, record, INTERSECT_LINE_2, "debugShowLineIntersection" +
536" wtTs[0]=T_VAL LINE_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
537 ) || match_regexp(line, lineNo, record, INTERSECT_LINE_NO, "debugShowLineIntersection" +
538" no intersect LINE_VAL LINE_VAL"
539 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE, "debugShowQuadLineIntersection" +
540" wtTs[0]=T_VAL QUAD_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
541 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE_2, "debugShowQuadLineIntersection" +
542" wtTs[0]=T_VAL QUAD_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
543 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE_NO, "debugShowQuadLineIntersection" +
544" no intersect QUAD_VAL LINE_VAL"
545 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD, "debugShowQuadIntersection" +
546" wtTs[0]=T_VAL QUAD_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL"
547 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_2, "debugShowQuadIntersection" +
548" wtTs[0]=T_VAL QUAD_VAL PT_VAL wtTs[1]=T_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL"
549 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_NO, "debugShowQuadIntersection" +
550" no intersect QUAD_VAL QUAD_VAL"
551 ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC, "debugShowCubicIntersection" +
552" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL"
553 ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC_NO, "debugShowCubicIntersection" +
554" no self intersect CUBIC_VAL"
555 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE, "debugShowCubicLineIntersection" +
556" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
557 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_2, "debugShowCubicLineIntersection" +
558" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
559 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_3, "debugShowCubicLineIntersection" +
560" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wtTs[2]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL wnTs[2]=T_VAL"
561 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_NO, "debugShowCubicLineIntersection" +
562" no intersect CUBIC_VAL LINE_VAL"
563 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC, "debugShowCubicIntersection" +
564" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL"
565 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_2, "debugShowCubicIntersection" +
566" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL wnTs[1]=T_VAL"
567 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_3, "debugShowCubicIntersection" +
568" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wtTs[2]=T_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL wnTs[1]=T_VAL wnTs[2]=T_VAL"
569 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_4, "debugShowCubicIntersection" +
570" 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"
571 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_NO, "debugShowCubicIntersection" +
572" no intersect CUBIC_VAL CUBIC_VAL"
573 );
574 break;
575 case REC_TYPE_SORT:
576 found = match_regexp(line, lineNo, record, SORT_LINE, "debugShowSort" +
577" [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"
578 ) || match_regexp(line, lineNo, record, SORT_QUAD, "debugShowSort" +
579" [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"
580 ) || match_regexp(line, lineNo, record, SORT_CUBIC, "debugShowSort" +
581" [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"
582 );
583 break;
584 case REC_TYPE_UNKNOWN:
585 found = true;
586 break;
587 }
588 if (!found) {
589 console.log(line + " [" + lineNo + "] of type " + type + " not found");
590 }
591 }
592 if (records.length >= 1) {
593 tests.push(records);
594 testTitles.push(title);
595 }
596}
597
caryclark@google.comf839c032012-10-26 21:03:50 +0000598function init(test) {
599 var canvas = document.getElementById('canvas');
600 if (!canvas.getContext) return;
601 screenWidth = canvas.width = window.innerWidth - 20;
602 screenHeight = canvas.height = window.innerHeight - 20;
603 ctx = canvas.getContext('2d');
604 xmin = Infinity;
605 var xmax = -Infinity;
606 ymin = Infinity;
607 var ymax = -Infinity;
caryclark@google.com0b7da432012-10-31 19:00:20 +0000608 var scanType = -1;
609 for (var scansStr in test) {
610 var scans = parseInt(scansStr);
caryclark@google.comf839c032012-10-26 21:03:50 +0000611 var scan = test[scans];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000612 if (scanType == -1) {
613 scanType = scan;
614 continue;
caryclark@google.comf839c032012-10-26 21:03:50 +0000615 }
caryclark@google.com47d73da2013-02-17 01:41:25 +0000616 if (scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN
617 || scanType == ACTIVE_CUBIC_SPAN) {
618 var last = scanType == ACTIVE_CUBIC_SPAN ? SPAN_X4
619 : scanType == ACTIVE_QUAD_SPAN ? SPAN_X3 : SPAN_X2;
caryclark@google.com0b7da432012-10-31 19:00:20 +0000620 for (var idx = SPAN_X1; idx <= last; idx += 2) {
621 xmin = Math.min(xmin, scan[idx]);
622 xmax = Math.max(xmax, scan[idx]);
623 ymin = Math.min(ymin, scan[idx + 1]);
624 ymax = Math.max(ymax, scan[idx + 1]);
625 }
626 } else {
627 var start = 1;
628 if (scanType != INTERSECT_QUAD_LINE_NO && scanType != INTERSECT_QUAD_NO) {
629 start = 2;
630 }
631 for (var idx = start; idx < start + 6; idx += 2) {
632 xmin = Math.min(xmin, scan[idx]);
633 xmax = Math.max(xmax, scan[idx]);
634 ymin = Math.min(ymin, scan[idx + 1]);
635 ymax = Math.max(ymax, scan[idx + 1]);
636 }
637 start = start + 6;
638 if (scanType == INTERSECT_QUAD_LINE || scanType == INTERSECT_QUAD) {
639 start += 3;
640 }
641 if (scanType == INTERSECT_QUAD_LINE_2) {
642 start += 6;
643 }
644 if (scanType == INTERSECT_QUAD_2) {
645 start += 4;
646 }
647 var end = start + 4;
648 if (scanType == INTERSECT_QUAD || scanType == INTERSECT_QUAD_2 || scanType == INTERSECT_QUAD_NO) {
649 end += 2;
650 }
651 for (var idx = start; idx < end; idx += 2) {
652 xmin = Math.min(xmin, scan[idx]);
653 xmax = Math.max(xmax, scan[idx]);
654 ymin = Math.min(ymin, scan[idx + 1]);
655 ymax = Math.max(ymax, scan[idx + 1]);
656 }
657 }
658 scanType = -1;
caryclark@google.comf839c032012-10-26 21:03:50 +0000659 }
660 srcWidth = xmax - xmin;
661 srcHeight = ymax - ymin;
662 var hscale = ctx.canvas.width / srcWidth;
663 var vscale = ctx.canvas.height / srcHeight;
664 var minScale = Math.min(hscale, vscale);
665 scale = minScale;
666 srcLeft = xmin;
667 srcTop = ymin;
668}
669
670function drawPoint(px, py) {
671 for (var pts = 0; pts < drawnPts.length; pts += 2) {
672 var x = drawnPts[pts];
673 var y = drawnPts[pts + 1];
674 if (px == x && py == y) {
675 return;
676 }
677 }
678 drawnPts.push(px);
679 drawnPts.push(py);
680 var label = px.toFixed(decimal_places) + ", " + py.toFixed(decimal_places);
681 var _px = (px - srcLeft)* scale;
682 var _py = (py - srcTop) * scale;
683 ctx.beginPath();
684 ctx.arc(_px, _py, 3, 0, Math.PI*2, true);
685 ctx.closePath();
686 ctx.fill();
687 ctx.fillText(label, _px + 5, _py);
688}
689
caryclark@google.com0b7da432012-10-31 19:00:20 +0000690function drawLine(x1, y1, x2, y2, selected) {
691 for (var pts = 0; pts < drawnLines.length; pts += 4) {
692 if (x1 == drawnLines[pts] && y1 == drawnLines[pts + 1]) {
693 return;
694 }
695 if (x2 == drawnLines[pts + 2] && x2 == drawnLines[pts + 3]) {
696 return;
697 }
698 }
699 if (selected) {
700 drawnLines.push(x1);
701 drawnLines.push(y1);
702 drawnLines.push(x2);
703 drawnLines.push(y2);
704 ctx.beginPath();
705 ctx.moveTo((x1 - srcLeft) * scale,
706 (y1 - srcTop) * scale);
707 ctx.lineTo((x2 - srcLeft) * scale,
708 (y2 - srcTop) * scale);
709 ctx.stroke();
710 return;
711 }
712 deferredLines.push(x1);
713 deferredLines.push(y1);
714 deferredLines.push(x2);
715 deferredLines.push(y2);
716}
717
caryclark@google.com47d73da2013-02-17 01:41:25 +0000718function drawLinePartial(x1, y1, x2, y2, t1, t2) {
719 var dx = x1 - x2;
720 var dy = y1 - y2;
721 var ax = x1 - t1 * dx;
722 var ay = y1 - t1 * dy;
723 var bx = x1 - t2 * dx;
724 var by = y1 - t2 * dy;
725 ctx.beginPath();
726 ctx.moveTo((ax - srcLeft) * scale,
727 (ay - srcTop) * scale);
728 ctx.lineTo((bx - srcLeft) * scale,
729 (by - srcTop) * scale);
730 ctx.stroke();
731}
732
caryclark@google.com0b7da432012-10-31 19:00:20 +0000733function drawQuad(x1, y1, x2, y2, x3, y3, selected) {
734 for (var pts = 0; pts < drawnQuads.length; pts += 6) {
735 if (x1 == drawnQuads[pts] && y1 == drawnQuads[pts + 1]) {
736 return;
737 }
738 if (x2 == drawnQuads[pts + 2] && x2 == drawnQuads[pts + 3]) {
739 return;
740 }
741 if (x2 == drawnQuads[pts + 4] && x2 == drawnQuads[pts + 5]) {
742 return;
743 }
744 }
745 if (selected) {
746 drawnQuads.push(x1);
747 drawnQuads.push(y1);
748 drawnQuads.push(x2);
749 drawnQuads.push(y2);
750 drawnQuads.push(x3);
751 drawnQuads.push(y3);
752 ctx.beginPath();
753 ctx.moveTo((x1 - srcLeft) * scale,
754 (y1 - srcTop) * scale);
755 ctx.quadraticCurveTo((x2 - srcLeft) * scale,
756 (y2 - srcTop) * scale,
757 (x3 - srcLeft) * scale,
758 (y3 - srcTop) * scale);
759 ctx.stroke();
760 return;
761 }
762 deferredQuads.push(x1);
763 deferredQuads.push(y1);
764 deferredQuads.push(x2);
765 deferredQuads.push(y2);
766 deferredQuads.push(x3);
767 deferredQuads.push(y3);
768}
769
caryclark@google.com47d73da2013-02-17 01:41:25 +0000770function interp(A, B, t) {
771 return A + (B - A) * t;
772}
773
774function interp_quad_coords(x1, x2, x3, t)
775{
776 var ab = interp(x1, x2, t);
777 var bc = interp(x2, x3, t);
778 var abc = interp(ab, bc, t);
779 return abc;
780}
781
782function drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2) {
783 var ax = interp_quad_coords(x1, x2, x3, t1);
784 var ay = interp_quad_coords(y1, y2, y3, t1);
785 var dx = interp_quad_coords(x1, x2, x3, (t1 + t2) / 2);
786 var dy = interp_quad_coords(y1, y2, y3, (t1 + t2) / 2);
787 var cx = interp_quad_coords(x1, x2, x3, t2);
788 var cy = interp_quad_coords(y1, y2, y3, t2);
789 var bx = 2*dx - (ax + cx)/2;
790 var by = 2*dy - (ay + cy)/2;
791 ctx.beginPath();
792 ctx.moveTo((ax - srcLeft) * scale,
793 (ay - srcTop) * scale);
794 ctx.quadraticCurveTo((bx - srcLeft) * scale,
795 (by - srcTop) * scale,
796 (cx - srcLeft) * scale,
797 (cy - srcTop) * scale);
798 ctx.stroke();
799}
800
801function drawCubic(x1, y1, x2, y2, x3, y3, x4, y4, selected) {
802 for (var pts = 0; pts < drawnCubics.length; pts += 8) {
803 if (x1 == drawnCubics[pts] && y1 == drawnCubics[pts + 1]) {
804 return;
805 }
806 if (x2 == drawnCubics[pts + 2] && x2 == drawnCubics[pts + 3]) {
807 return;
808 }
809 if (x2 == drawnCubics[pts + 4] && x2 == drawnCubics[pts + 5]) {
810 return;
811 }
812 if (x2 == drawnCubics[pts + 6] && x2 == drawnCubics[pts + 7]) {
813 return;
814 }
815 }
816 if (selected) {
817 drawnCubics.push(x1);
818 drawnCubics.push(y1);
819 drawnCubics.push(x2);
820 drawnCubics.push(y2);
821 drawnCubics.push(x3);
822 drawnCubics.push(y3);
823 drawnCubics.push(x4);
824 drawnCubics.push(y4);
825 ctx.beginPath();
826 ctx.moveTo((x1 - srcLeft) * scale,
827 (y1 - srcTop) * scale);
828 ctx.bezierCurveTo((x2 - srcLeft) * scale,
829 (y2 - srcTop) * scale,
830 (x3 - srcLeft) * scale,
831 (y3 - srcTop) * scale,
832 (x4 - srcLeft) * scale,
833 (y4 - srcTop) * scale);
834 ctx.stroke();
835 return;
836 }
837 deferredCubics.push(x1);
838 deferredCubics.push(y1);
839 deferredCubics.push(x2);
840 deferredCubics.push(y2);
841 deferredCubics.push(x3);
842 deferredCubics.push(y3);
843 deferredCubics.push(x4);
844 deferredCubics.push(y4);
845}
846
847function interp_cubic_coords(x1, x2, x3, x4, t)
848{
849 var ab = interp(x1, x2, t);
850 var bc = interp(x2, x3, t);
851 var cd = interp(x3, x4, t);
852 var abc = interp(ab, bc, t);
853 var bcd = interp(bc, cd, t);
854 var abcd = interp(abc, bcd, t);
855 return abcd;
856}
857
858function drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2) {
859 var ax = interp_cubic_coords(x1, x2, x3, x4, t1);
860 var ay = interp_cubic_coords(y1, y2, y3, y4, t1);
861 var ex = interp_cubic_coords(x1, x2, x3, x4, (t1*2+t2)/3);
862 var ey = interp_cubic_coords(y1, y2, y3, y4, (t1*2+t2)/3);
863 var fx = interp_cubic_coords(x1, x2, x3, x4, (t1+t2*2)/3);
864 var fy = interp_cubic_coords(y1, y2, y3, y4, (t1+t2*2)/3);
865 var dx = interp_cubic_coords(x1, x2, x3, x4, t2);
866 var dy = interp_cubic_coords(y1, y2, y3, y4, t2);
867 var mx = ex * 27 - ax * 8 - dx;
868 var my = ey * 27 - ay * 8 - dy;
869 var nx = fx * 27 - ax - dx * 8;
870 var ny = fy * 27 - ay - dy * 8;
871 var bx = (mx * 2 - nx) / 18;
872 var by = (my * 2 - ny) / 18;
873 var cx = (nx * 2 - mx) / 18;
874 var cy = (ny * 2 - my) / 18;
875 ctx.beginPath();
876 ctx.moveTo((ax - srcLeft) * scale,
877 (ay - srcTop) * scale);
878 ctx.bezierCurveTo((bx - srcLeft) * scale,
879 (by - srcTop) * scale,
880 (cx - srcLeft) * scale,
881 (cy - srcTop) * scale,
882 (dx - srcLeft) * scale,
883 (dy - srcTop) * scale,
884 (ex - srcLeft) * scale,
885 (ey - srcTop) * scale);
886 ctx.stroke();
887}
888
889function drawPartial(test) {
890 ctx.lineWidth = 3;
891 ctx.strokeStyle = "rgba(0,0,255, 0.3)";
892 var scanType = -1;
893 var partIndex = 0;
894 for (var scansStr in test) {
895 var scans = parseInt(scansStr);
896 var scan = test[scans];
897 if (scanType == -1) {
898 scanType = scan;
899 continue;
900 }
901 partIndex++;
902 var hasId = scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN
903 || scanType == ACTIVE_CUBIC_SPAN ? SPAN_ID : -1;
904 if (hasId < 0) {
905 continue;
906 }
907 var types = [scanType == ACTIVE_LINE_SPAN ? 0 : scanType == ACTIVE_QUAD_SPAN ? 1 : 2];
908 var x1 = scan[SPAN_X1];
909 var y1 = scan[SPAN_Y1];
910 var x2 = scan[SPAN_X2];
911 var y2 = scan[SPAN_Y2];
912 var x3, y3, x3, y4, t1, t2;
913 switch(scanType) {
914 case ACTIVE_LINE_SPAN:
915 t1 = scan[SPAN_L_T];
916 t2 = scan[SPAN_L_TEND];
917 drawLinePartial(x1, y1, x2, y2, t1, t2);
918 break;
919 case ACTIVE_QUAD_SPAN:
920 x3 = scan[SPAN_X3];
921 y3 = scan[SPAN_Y3];
922 t1 = scan[SPAN_Q_T];
923 t2 = scan[SPAN_Q_TEND];
924 drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2);
925 break;
926 case ACTIVE_CUBIC_SPAN:
927 x3 = scan[SPAN_X3];
928 y3 = scan[SPAN_Y3];
929 x4 = scan[SPAN_X4];
930 y4 = scan[SPAN_Y4];
931 t1 = scan[SPAN_C_T];
932 t2 = scan[SPAN_C_TEND];
933 drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2);
934 break;
935 }
936 scanType = -1;
937 }
938}
939
caryclark@google.com0b7da432012-10-31 19:00:20 +0000940function drawDeferred() {
caryclark@google.com47d73da2013-02-17 01:41:25 +0000941 for (var pts = 0; pts < deferredCubics.length; pts += 8) {
942 drawCubic(deferredCubics[pts], deferredCubics[pts + 1],
943 deferredCubics[pts + 2], deferredCubics[pts + 3],
944 deferredCubics[pts + 4], deferredCubics[pts + 5],
945 deferredCubics[pts + 6], deferredCubics[pts + 7], true);
946 }
caryclark@google.com0b7da432012-10-31 19:00:20 +0000947 for (var pts = 0; pts < deferredQuads.length; pts += 6) {
948 drawQuad(deferredQuads[pts], deferredQuads[pts + 1],
949 deferredQuads[pts + 2], deferredQuads[pts + 3],
950 deferredQuads[pts + 4], deferredQuads[pts + 5], true);
951 }
952 for (var pts = 0; pts < deferredLines.length; pts += 4) {
953 drawLine(deferredLines[pts], deferredLines[pts + 1],
954 deferredLines[pts + 2], deferredLines[pts + 3], true);
955 }
956}
957
caryclark@google.comf839c032012-10-26 21:03:50 +0000958function draw(test, title) {
959 ctx.fillStyle = "rgba(0,0,0, 0.1)";
960 ctx.font = "normal 50px Arial";
961 ctx.fillText(title, 50, 50);
962 ctx.font = "normal 10px Arial";
963 ctx.lineWidth = "1.001"; "0.999";
caryclark@google.com0b7da432012-10-31 19:00:20 +0000964 var curId = -1;
caryclark@google.comf839c032012-10-26 21:03:50 +0000965 var firstIdx;
966 var lastIdx;
967 var index_tst = -1;
968 drawnPts = [];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000969 drawnLines = [];
970 drawnQuads = [];
caryclark@google.com47d73da2013-02-17 01:41:25 +0000971 drawnCubics = [];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000972 deferredLines = [];
973 deferredQuads = [];
caryclark@google.com47d73da2013-02-17 01:41:25 +0000974 deferredCubics = [];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000975 var scanType = -1;
976 var partIndex = 0;
caryclark@google.comf839c032012-10-26 21:03:50 +0000977 for (var scansStr in test) {
978 var scans = parseInt(scansStr);
979 var scan = test[scans];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000980 if (scanType == -1) {
981 scanType = scan;
caryclark@google.comf839c032012-10-26 21:03:50 +0000982 continue;
983 }
caryclark@google.com0b7da432012-10-31 19:00:20 +0000984 partIndex++;
caryclark@google.com47d73da2013-02-17 01:41:25 +0000985 var hasId = scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN
986 || scanType == ACTIVE_CUBIC_SPAN ? SPAN_ID : -1;
caryclark@google.com0b7da432012-10-31 19:00:20 +0000987 if (hasId >= 0 && curId != scan[hasId]) {
caryclark@google.com47d73da2013-02-17 01:41:25 +0000988 curId = scan[hasId];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000989 firstIdx = lastIdx = partIndex;
990 index_tst++;
991 var nextIdx = lastIdx + 1;
992 while (nextIdx * 2 < test.length && test[nextIdx * 2][hasId] == curId) {
993 lastIdx = nextIdx++;
994 }
995 } else if (hasId < 0) {
996 firstIdx = lastIdx = partIndex;
997 index_tst++;
caryclark@google.comf839c032012-10-26 21:03:50 +0000998 }
caryclark@google.com0b7da432012-10-31 19:00:20 +0000999 var seq = sequence % (test.length / 2);
1000 var selected = sequence >= 0 ? seq == partIndex
1001 : (index_bits & (1 << index_tst)) != 0 && partIndex == firstIdx;
1002 var skippable = (sequence >= 0 && seq >= firstIdx && seq <= lastIdx)
1003 || partIndex != firstIdx;
1004 if (skippable && !selected) {
1005 scanType = -1;
1006 continue;
1007 }
caryclark@google.com47d73da2013-02-17 01:41:25 +00001008 var types = [scanType == ACTIVE_LINE_SPAN ? 0 : scanType == ACTIVE_QUAD_SPAN ? 1 : 2];
caryclark@google.com0b7da432012-10-31 19:00:20 +00001009 var pts = [];
caryclark@google.com47d73da2013-02-17 01:41:25 +00001010 if (scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN || scanType == ACTIVE_CUBIC_SPAN) {
caryclark@google.com0b7da432012-10-31 19:00:20 +00001011 pts.push(SPAN_X1);
1012 } else {
1013 pts.push(scanType != INTERSECT_QUAD_NO && scanType != INTERSECT_QUAD_LINE_NO ? 2 : 1);
1014 types.push(scanType == INTERSECT_QUAD_NO || scanType == INTERSECT_QUAD || scanType == INTERSECT_QUAD_2 ? 1 : 0);
1015 pts.push(scanType == INTERSECT_QUAD_LINE || scanType == INTERSECT_QUAD ? 11
1016 : scanType == INTERSECT_QUAD_LINE_2 ? 14 : scanType == INTERSECT_QUAD_2 ? 12 : 7);
1017 }
1018 ctx.strokeStyle = "red";
1019 for (var typeIndex = 0; typeIndex < types.length; ++typeIndex) {
1020 var type = types[typeIndex];
1021 var index = pts[typeIndex];
caryclark@google.com47d73da2013-02-17 01:41:25 +00001022 if (type == 2) {
1023 drawCubic(scan[index + 0], scan[index + 1], scan[index + 2], scan[index + 3],
1024 scan[index + 4], scan[index + 5], scan[index + 6], scan[index + 7],
1025 selected);
1026 } else if (type == 1) {
caryclark@google.com0b7da432012-10-31 19:00:20 +00001027 drawQuad(scan[index + 0], scan[index + 1], scan[index + 2], scan[index + 3],
1028 scan[index + 4], scan[index + 5], selected);
1029 } else {
1030 drawLine(scan[index + 0], scan[index + 1], scan[index + 2], scan[index + 3],
1031 selected);
1032 }
1033 }
caryclark@google.comf839c032012-10-26 21:03:50 +00001034 if (debug_xy && selected) {
1035 var debugText = "";
caryclark@google.com0b7da432012-10-31 19:00:20 +00001036 for (var typeIndex = 0; typeIndex < types.length; ++typeIndex) {
1037 var type = types[typeIndex];
1038 var index = pts[typeIndex];
caryclark@google.com47d73da2013-02-17 01:41:25 +00001039 for (var idx = pts[typeIndex]; idx < pts[typeIndex] + (type + 1) * 2; idx += 2) {
caryclark@google.com0b7da432012-10-31 19:00:20 +00001040 var screenX = (scan[idx] - srcLeft) * scale;
1041 var screenY = (scan[idx + 1] - srcTop) * scale;
1042 debugText += screenX.toFixed(decimal_places) + ", ";
1043 debugText += screenY.toFixed(decimal_places) + " ";
1044 }
caryclark@google.comf839c032012-10-26 21:03:50 +00001045 }
1046 ctx.fillStyle="blue";
caryclark@google.com0b7da432012-10-31 19:00:20 +00001047 ctx.fillText(debugText, 50, partIndex * 50 + 100);
caryclark@google.comf839c032012-10-26 21:03:50 +00001048 }
1049 if (ptLabels && selected) {
1050 ctx.fillStyle="blue";
caryclark@google.com0b7da432012-10-31 19:00:20 +00001051 for (var typeIndex = 0; typeIndex < types.length; ++typeIndex) {
1052 var type = types[typeIndex];
1053 var index = pts[typeIndex];
caryclark@google.com47d73da2013-02-17 01:41:25 +00001054 for (var idx = pts[typeIndex]; idx < pts[typeIndex] + (type + 1) * 2; idx += 2) {
caryclark@google.com0b7da432012-10-31 19:00:20 +00001055 drawPoint(scan[idx], scan[idx + 1]);
1056 }
caryclark@google.comf839c032012-10-26 21:03:50 +00001057 }
1058 }
caryclark@google.com0b7da432012-10-31 19:00:20 +00001059 var infoText = "";
caryclark@google.comf839c032012-10-26 21:03:50 +00001060 if (info_mode && selected) {
caryclark@google.com0b7da432012-10-31 19:00:20 +00001061 infoText += hasId >= 0 ? "id=" + scan[hasId] : partIndex;
1062 }
1063 if (intersect_mode && selected) {
caryclark@google.com47d73da2013-02-17 01:41:25 +00001064 if (scanType == ACTIVE_CUBIC_SPAN) {
1065 infoText += " t=" + scan[SPAN_C_T];
1066 } else if (scanType == ACTIVE_QUAD_SPAN) {
caryclark@google.com0b7da432012-10-31 19:00:20 +00001067 infoText += " t=" + scan[SPAN_Q_T];
1068 } else if (scanType == ACTIVE_LINE_SPAN) {
1069 infoText += " t=" + scan[SPAN_L_T];
1070 } else if (scanType == INTERSECT_QUAD_LINE ||scanType == INTERSECT_QUAD) {
1071 infoText += " t0[0]=" + scan[1] + " t1[0]=" + scan[10];
1072 } else if (scanType == INTERSECT_QUAD_LINE_2 || scanType == INTERSECT_QUAD_2) {
1073 infoText += " t0[0]=" + scan[1] + " t0[1]=" + scan[10] + " t1[0]=" + scan[13];
1074 if (scanType == INTERSECT_QUAD_LINE_2) {
1075 infoText += " t1[1]=" + scan[18];
1076 } else {
1077 infoText += " t0[1]=" + scan[20];
1078 }
1079 }
1080 }
1081 if (infoText.length > 0) {
caryclark@google.comf839c032012-10-26 21:03:50 +00001082 ctx.fillStyle="green";
caryclark@google.com0b7da432012-10-31 19:00:20 +00001083 ctx.fillText(infoText, 10, (hasId >= 0 && sequence >= 0
1084 ? hasId : partIndex) * 30 + 50);
caryclark@google.comf839c032012-10-26 21:03:50 +00001085 }
1086 if (intersect_mode && selected) {
1087 ctx.fillStyle="rgba(50,100,200, 1.0)";
caryclark@google.com47d73da2013-02-17 01:41:25 +00001088 if (scanType == ACTIVE_CUBIC_SPAN) {
1089 drawPoint(scan[SPAN_C_TX], scan[SPAN_C_TY]);
1090 } else if (scanType == ACTIVE_QUAD_SPAN) {
caryclark@google.comf839c032012-10-26 21:03:50 +00001091 drawPoint(scan[SPAN_Q_TX], scan[SPAN_Q_TY]);
caryclark@google.com0b7da432012-10-31 19:00:20 +00001092 } else if (scanType == ACTIVE_LINE_SPAN) {
caryclark@google.comf839c032012-10-26 21:03:50 +00001093 drawPoint(scan[SPAN_L_TX], scan[SPAN_L_TY]);
caryclark@google.com0b7da432012-10-31 19:00:20 +00001094 } else if (scanType != INTERSECT_QUAD_NO && scanType != INTERSECT_QUAD_LINE_NO) {
1095 drawPoint(scan[8], scan[9]);
1096 if (scanType == INTERSECT_QUAD_LINE_2 || scanType == INTERSECT_QUAD_2) {
1097 drawPoint(scan[11], scan[12]);
1098 }
caryclark@google.comf839c032012-10-26 21:03:50 +00001099 }
1100 }
caryclark@google.com0b7da432012-10-31 19:00:20 +00001101 ctx.strokeStyle = "rgba(0,0,0, 0.2)";
1102 scanType = -1;
caryclark@google.comf839c032012-10-26 21:03:50 +00001103 }
caryclark@google.com0b7da432012-10-31 19:00:20 +00001104 drawDeferred();
caryclark@google.com47d73da2013-02-17 01:41:25 +00001105 drawPartial(test);
caryclark@google.comf839c032012-10-26 21:03:50 +00001106}
1107
1108function drawTop() {
1109 init(tests[testIndex]);
1110 redraw();
1111}
1112
1113function redraw() {
1114 ctx.beginPath();
1115 ctx.rect(0, 0, ctx.canvas.width, ctx.canvas.height);
1116 ctx.fillStyle="white";
1117 ctx.fill();
1118 draw(tests[testIndex], testTitles[testIndex]);
1119}
1120
1121function doKeyPress(evt) {
1122 var char = String.fromCharCode(evt.charCode);
1123 switch (char) {
1124 case '0':
1125 case '1':
1126 case '2':
1127 case '3':
1128 case '4':
1129 case '5':
1130 case '6':
1131 case '7':
1132 case '8':
1133 case '9':
1134 if (digit_mode) {
1135 decimal_places = char - '0';
1136 } else if (index_mode) {
1137 index_bits ^= 1 << (char - '0');
1138 }
1139 redraw();
1140 break;
1141 case 'd':
1142 digit_mode = true;
1143 index_mode = false;
1144 break;
1145 case 'f':
1146 info_mode ^= true;
1147 redraw();
1148 break;
1149 case 'i':
1150 digit_mode = false;
1151 if (sequence >= 0) {
1152 sequence = -1;
1153 index_mode = false;
1154 } else {
1155 index_mode ^= true;
1156 }
1157 if (index_mode) {
1158 index_bits = 0;
1159 } else {
1160 index_bits = -1;
1161 }
1162 redraw();
1163 break;
1164 case 'N':
1165 testIndex += 9;
1166 case 'n':
1167 if (++testIndex >= tests.length)
1168 testIndex = 0;
1169 drawTop();
1170 break;
1171 case 'P':
1172 testIndex -= 9;
1173 case 'p':
1174 if (--testIndex < 0)
1175 testIndex = tests.length - 1;
1176 drawTop();
1177 break;
1178 case 's':
1179 sequence++;
caryclark@google.com0b7da432012-10-31 19:00:20 +00001180 redraw();
1181 break;
1182 case 'S':
1183 sequence--;
1184 if (sequence < 0) {
1185 sequence = 0;
1186 }
1187 redraw();
caryclark@google.comf839c032012-10-26 21:03:50 +00001188 break;
1189 case 't':
1190 intersect_mode ^= true;
1191 redraw();
1192 break;
1193 case 'x':
1194 ptLabels ^= true;
1195 redraw();
1196 break;
1197 case 'y':
1198 debug_xy ^= true;
1199 redraw();
1200 break;
1201 case '-':
1202 scale /= 2;
1203 calcLeftTop();
1204 redraw();
1205 break;
1206 case '=':
1207 case '+':
1208 scale *= 2;
1209 calcLeftTop();
1210 redraw();
1211 break;
1212 }
1213}
1214
1215function calcXY() {
1216 var e = window.event;
1217 var tgt = e.target || e.srcElement;
1218 var left = tgt.offsetLeft;
1219 var top = tgt.offsetTop;
1220 var unit = scale;
1221 mouseX = (e.clientX - left) / scale + srcLeft;
1222 mouseY = (e.clientY - top) / scale + srcTop;
1223}
1224
1225function calcLeftTop() {
1226 srcLeft = mouseX - screenWidth / 2 / scale;
1227 srcTop = mouseY - screenHeight / 2 / scale;
1228}
1229
1230function handleMouseClick() {
1231 calcXY();
1232 calcLeftTop();
1233 redraw();
1234}
1235
1236function handleMouseOver() {
1237 calcXY();
1238 var num = mouseX.toFixed(decimal_places) + ", " + mouseY.toFixed(decimal_places);
1239 ctx.beginPath();
1240 ctx.rect(300,100,200,10);
1241 ctx.fillStyle="white";
1242 ctx.fill();
1243 ctx.fillStyle="black";
1244 ctx.fillText(num, 300, 108);
1245}
1246
1247function start() {
1248 for (i = 0; i < testDivs.length; ++i) {
1249 var title = testDivs[i].id.toString();
1250 var str = testDivs[i].firstChild.data;
caryclark@google.com4aaaaea2013-02-28 16:12:39 +00001251 parse_all(str, title);
caryclark@google.comf839c032012-10-26 21:03:50 +00001252 parse_debugShowActiveSpans(str, title);
caryclark@google.com0b7da432012-10-31 19:00:20 +00001253 parse_intersections(str, title);
caryclark@google.comf839c032012-10-26 21:03:50 +00001254 }
1255 drawTop();
1256 window.addEventListener('keypress', doKeyPress, true);
1257 window.onresize = function() {
1258 drawTop();
1259 }
1260}
1261
1262</script>
1263</head>
1264
1265<body onLoad="start();">
1266<canvas id="canvas" width="750" height="500"
1267 onmousemove="handleMouseOver()"
1268 onclick="handleMouseClick()"
1269 ></canvas >
1270</body>
1271</html>