blob: 5cec64f5bfe7bedad7c7f76bda13e449fd5829ce [file] [log] [blame]
caryclarkdac1d172014-06-17 05:15:38 -07001<html>
2<head>
3<div height="0" hidden="true">
caryclarkdac1d172014-06-17 05:15:38 -07004
caryclark27c015d2016-09-23 05:47:20 -07005<div id="loop17">
6seg=1 {{{1, 2}, {0, 3}, {-0.333333343f, 3.33333325f}, {0.833333373f, 3.5f}}}
7seg=2 {{{0.833333373f, 3.5f}, {1, 2}}}
8op sect
9seg=3 {{{0, 3}, {-0.333333343f, 3.33333325f}, {0.833333373f, 3.5f}, {1, 2}}}
10seg=4 {{{1, 2}, {0, 3}}}
11debugShowCubicLineIntersection wtTs[0]=0 {{{0,3}, {-0.333333343,3.33333325}, {0.833333373,3.5}, {1,2}}} {{0,3}} wtTs[1]=1 {{1,2}} wnTs[0]=1 {{{1,2}, {0,3}}} wnTs[1]=0
12id=1 1=(0,1) [4,2] id=2 2=(0,0.5) [1] 4=(0.5,1) [1]
13id=1 1=(0,0.5) [4] 3=(0.5,1) [2,4] id=2 2=(0,0) [3] 4=(0.5,1) [3,1]
14id=1 1=(0,0.5) [4] 3=(0.5,0.75) [4] 5=(1,1) [2] id=2 2=(0,0) [5] 4=(0.5,1) [3,1]
15id=1 1=(0,0.5) [4] 5=(1,1) [2] id=2 2=(0,0) [5] 4=(0.5,0.75) [1]
16id=1 7=(0.25,0.5) [4] 5=(1,1) [2] id=2 2=(0,0) [5] 4=(0.5,0.75) [7]
17id=1 7=(0.25,0.375) [4] 9=(0.375,0.5) [4] 5=(1,1) [2] id=2 2=(0,0) [5] 4=(0.5,0.75) [9,7]
18id=1 7=(0.25,0.375) [8,4] 5=(1,1) [2] id=2 2=(0,0) [5] 4=(0.5,0.625) [7] 8=(0.625,0.75) [7]
19id=1 7=(0.25,0.375) [10,8] 5=(1,1) [2] id=2 2=(0,0) [5] 10=(0.5625,0.625) [7] 8=(0.625,0.75) [7]
20id=1 11=(0.3125,0.375) [8] 5=(1,1) [2] id=2 2=(0,0) [5] 8=(0.625,0.75) [11]
21id=1 11=(0.3125,0.375) [8] 5=(1,1) [2] id=2 2=(0,0) [5] 8=(0.625,0.6875) [11]
22id=1 13=(0.34375,0.375) [8] 5=(1,1) [2] id=2 2=(0,0) [5] 8=(0.625,0.6875) [13]
23id=1 13=(0.34375,0.375) [8] 5=(1,1) [2] id=2 2=(0,0) [5] 8=(0.625,0.65625) [13]
24id=1 15=(0.359375,0.375) [8] 5=(1,1) [2] id=2 2=(0,0) [5] 8=(0.625,0.65625) [15]
25id=1 15=(0.359375,0.375) [8] 5=(1,1) [2] id=2 2=(0,0) [5] 8=(0.625,0.640625) [15]
26id=1 15=(0.359375,0.367188) [8] 17=(0.367188,0.375) [8] 5=(1,1) [2] id=2 2=(0,0) [5] 8=(0.625,0.640625) [17,15]
27id=1 15=(0.359375,0.367188) [18] 5=(1,1) [2] id=2 2=(0,0) [5] 18=(0.632813,0.640625) [15]
28id=1 19=(0.363281,0.367188) [18] 5=(1,1) [2] id=2 2=(0,0) [5] 18=(0.632813,0.640625) [19]
29setPerp t=0.36328125 cPt=(0.110739922,3.22537946) != oppT=0.627603681 fPerpPt=(0.110965509,3.21864052)
30setPerp t=0.3671875 cPt=(0.115765816,3.22551414) != oppT=0.636601379 fPerpPt=(0.115710094,3.22827643)
31setPerp t=0.6328125 cPt=(0.113641506,3.22423955) != oppT=0.363729545 fPerpPt=(0.111313976,3.22539824)
32setPerp t=0.63470694 cPt=(0.114662928,3.22626175) != oppT=0.367452497 fPerpPt=(0.116108709,3.2255209)
33setPerp t=0.635654159 cPt=(0.115183291,3.22727003) != oppT=0.369275918 fPerpPt=(0.118474752,3.22555923)
34setPerp t=0.636127769 cPt=(0.115445887,3.22777346) != oppT=0.370178237 fPerpPt=(0.119649848,3.22557288)
35setPerp t=0.636364574 cPt=(0.115577789,3.228025) != oppT=0.370627065 fPerpPt=(0.120235406,3.22557836)
36setPerp t=0.636482977 cPt=(0.115643891,3.22815073) != oppT=0.370850898 fPerpPt=(0.120527686,3.22558077)
37setPerp t=0.636542178 cPt=(0.11567698,3.22821358) != oppT=0.370962669 fPerpPt=(0.120673701,3.22558189)
38setPerp t=0.636571779 cPt=(0.115693534,3.22824501) != oppT=0.371018519 fPerpPt=(0.120746678,3.22558243)
39setPerp t=0.636586579 cPt=(0.115701813,3.22826072) != oppT=0.371046435 fPerpPt=(0.120783158,3.22558269)
40setPerp t=0.636593979 cPt=(0.115705954,3.22826857) != oppT=0.37106039 fPerpPt=(0.120801396,3.22558282)
41setPerp t=0.636597679 cPt=(0.115708024,3.2282725) != oppT=0.371067368 fPerpPt=(0.120810515,3.22558289)
42setPerp t=0.636599529 cPt=(0.115709059,3.22827446) != oppT=0.371070856 fPerpPt=(0.120815074,3.22558292)
43setPerp t=0.636600454 cPt=(0.115709577,3.22827545) != oppT=0.3710726 fPerpPt=(0.120817354,3.22558294)
44setPerp t=0.636600917 cPt=(0.115709835,3.22827594) != oppT=0.371073472 fPerpPt=(0.120818494,3.22558294)
45setPerp t=0.636601148 cPt=(0.115709965,3.22827618) != oppT=0.371073908 fPerpPt=(0.120819063,3.22558295)
46setPerp t=0.636601264 cPt=(0.11571003,3.2282763) != oppT=0.371074126 fPerpPt=(0.120819348,3.22558295)
47setPerp t=0.636601322 cPt=(0.115710062,3.22827637) != oppT=0.371074235 fPerpPt=(0.120819491,3.22558295)
48setPerp t=0.63660135 cPt=(0.115710078,3.2282764) != oppT=0.37107429 fPerpPt=(0.120819562,3.22558295)
49setPerp t=0.636601365 cPt=(0.115710086,3.22827641) != oppT=0.371074317 fPerpPt=(0.120819598,3.22558295)
50setPerp t=0.636601372 cPt=(0.11571009,3.22827642) != oppT=0.371074331 fPerpPt=(0.120819616,3.22558295)
51setPerp t=0.636601376 cPt=(0.115710092,3.22827642) != oppT=0.371074338 fPerpPt=(0.120819624,3.22558295)
52setPerp t=0.636601378 cPt=(0.115710093,3.22827643) != oppT=0.371074341 fPerpPt=(0.120819629,3.22558295)
53setPerp t=0.636601378 cPt=(0.115710094,3.22827643) != oppT=0.371074343 fPerpPt=(0.120819631,3.22558295)
54setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819632,3.22558295)
55setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
56setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
57setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
58setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
59setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
60setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
61setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
62setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
63setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
64setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
65setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
66setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
67setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
68setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
69setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
70setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
71setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
72setPerp t=0.636601379 cPt=(0.115710094,3.22827643) != oppT=0.371074344 fPerpPt=(0.120819633,3.22558295)
73id=1 5=(1,1) [2] id=2 2=(0,0) [5]
74debugShowCubicIntersection wtTs[0]=1 {{{0,3}, {-0.333333343,3.33333325}, {0.833333373,3.5}, {1,2}}} {{1,2}} wnTs[0]=0 {{{1,2}, {0,3}, {-0.333333343,3.33333325}, {0.833333373,3.5}}}
75debugShowCubicLineIntersection wtTs[0]=1 {{{0,3}, {-0.333333343,3.33333325}, {0.833333373,3.5}, {1,2}}} {{1,2}} wnTs[0]=1 {{{0.833333373,3.5}, {1,2}}}
76debugShowCubicLineIntersection wtTs[0]=0 {{{1,2}, {0,3}, {-0.333333343,3.33333325}, {0.833333373,3.5}}} {{1,2}} wnTs[0]=0 {{{1,2}, {0,3}}}
77debugShowLineIntersection wtTs[0]=0 {{{1,2}, {0,3}}} {{1,2}} wnTs[0]=1 {{{0.833333373,3.5}, {1,2}}}
78debugShowCubicLineIntersection wtTs[0]=0 {{{1,2}, {0,3}, {-0.333333343,3.33333325}, {0.833333373,3.5}}} {{1,2}} wtTs[1]=1 {{0.833333373,3.5}} wnTs[0]=1 {{{0.833333373,3.5}, {1,2}}} wnTs[1]=0
79----------------------------------- start
80----------------------------------- addExpanded
81----------------------------------- moveMultiples
82----------------------------------- moveNearby
83----------------------------------- addEndMovedSpans
84----------------------------------- addMissing2
85----------------------------------- moveNearby2
86----------------------------------- expand2
87----------------------------------- addExpanded3
88----------------------------------- mark1
89----------------------------------- missingCoincidence2
90----------------------------------- missingCoincidence3
91----------------------------------- coincidence.reorder
92----------------------------------- pairs->apply
93----------------------------------- pairs->findOverlaps
caryclarke839e782016-09-15 07:48:18 -070094SkOpSegment::sortAngles [3] tStart=1 [6]
caryclark27c015d2016-09-23 05:47:20 -070095SkOpAngle::after [3/1] 21/20 tStart=1 tEnd=0 < [1/3] 20/21 tStart=0 tEnd=1 < [2/4] 21/21 tStart=1 tEnd=0 F 7
96SkOpAngle::afterPart {{{1,2}, {0.833333373,3.5}, {-0.333333343,3.33333325}, {0,3}}} id=3
97SkOpAngle::afterPart {{{1,2}, {0,3}, {-0.333333343,3.33333325}, {0.833333373,3.5}}} id=1
98SkOpAngle::afterPart {{{1,2}, {0.833333373,3.5}}} id=2
99SkOpAngle::after [3/1] 21/20 tStart=1 tEnd=0 < [4/2] 19/19 tStart=0 tEnd=1 < [2/4] 21/21 tStart=1 tEnd=0 F 5
100SkOpAngle::afterPart {{{1,2}, {0.833333373,3.5}, {-0.333333343,3.33333325}, {0,3}}} id=3
101SkOpAngle::afterPart {{{1,2}, {0,3}}} id=4
102SkOpAngle::afterPart {{{1,2}, {0.833333373,3.5}}} id=2
103SkOpAngle::after [2/4] 21/21 tStart=1 tEnd=0 < [4/2] 19/19 tStart=0 tEnd=1 < [1/3] 20/21 tStart=0 tEnd=1 T 5
104SkOpAngle::afterPart {{{1,2}, {0.833333373,3.5}}} id=2
105SkOpAngle::afterPart {{{1,2}, {0,3}}} id=4
106SkOpAngle::afterPart {{{1,2}, {0,3}, {-0.333333343,3.33333325}, {0.833333373,3.5}}} id=1
107SkOpSegment::sortAngles [4] tStart=0 [7]
108SkOpSegment::sortAngles [1] tStart=0 [1]
109SkOpSegment::sortAngles [2] tStart=1 [4]
110SkOpSegment::debugShowActiveSpans id=3 (0,3 -0.333333343,3.33333325 0.833333373,3.5 1,2) t=0 tEnd=1 windSum=? windValue=1
111SkOpSegment::debugShowActiveSpans id=4 (1,2 0,3) t=0 tEnd=1 windSum=? windValue=1
112SkOpSegment::debugShowActiveSpans id=1 (1,2 0,3 -0.333333343,3.33333325 0.833333373,3.5) t=0 tEnd=1 windSum=? windValue=1
113SkOpSegment::debugShowActiveSpans id=2 (0.833333373,3.5 1,2) t=0 tEnd=1 windSum=? windValue=1
114SkOpSpan::sortableTop dir=kTop seg=3 t=0.5 pt=(0.3125,3.1875)
115SkOpSpan::sortableTop [0] valid=1 operand=1 span=7 ccw=0 seg=4 {{{1, 2}, {0, 3}}} t=0.6875 pt=(0.3125,2.6875) slope=(-1,1)
116SkOpSpan::sortableTop [1] valid=1 operand=0 span=1 ccw=0 seg=1 {{{1, 2}, {0, 3}, {-0.333333343f, 3.33333325f}, {0.833333373f, 3.5f}}} t=0.293719533 pt=(0.3125,2.72128606) slope=(-1.60944396,1.95452854)
117SkOpSpan::sortableTop [2] valid=1 operand=1 span=5 ccw=1 seg=3 {{{0, 3}, {-0.333333343f, 3.33333325f}, {0.833333373f, 3.5f}, {1, 2}}} t=0.5 pt=(0.3125,3.1875) slope=(1.62500004,-0.62499994)
118SkOpSegment::markWinding id=4 (1,2 0,3) t=0 [7] (1,2) tEnd=1 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1 oppValue=0
119SkOpSegment::markWinding id=3 (0,3 -0.333333343,3.33333325 0.833333373,3.5 1,2) t=0 [5] (0,3) tEnd=1 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
120SkOpSegment::markWinding id=4 (1,2 0,3) t=0 [7] (1,2) tEnd=1 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1 oppValue=0
121SkOpSegment::markWinding id=1 (1,2 0,3 -0.333333343,3.33333325 0.833333373,3.5) t=0 [1] (1,2) tEnd=1 newWindSum=1 newOppSum=1 oppSum=1 windSum=1 windValue=1 oppValue=0
122SkOpSegment::markWinding id=2 (0.833333373,3.5 1,2) t=0 [3] (0.833333373,3.5) tEnd=1 newWindSum=1 newOppSum=1 oppSum=? windSum=? windValue=1 oppValue=0
123SkOpSegment::markWinding id=1 (1,2 0,3 -0.333333343,3.33333325 0.833333373,3.5) t=0 [1] (1,2) tEnd=1 newWindSum=1 newOppSum=1 oppSum=1 windSum=1 windValue=1 oppValue=0
124SkOpSegment::activeOp id=3 t=1 tEnd=0 op=sect miFrom=0 miTo=0 suFrom=1 suTo=0 result=0
125SkOpSegment::markDone id=3 (0,3 -0.333333343,3.33333325 0.833333373,3.5 1,2) t=0 [5] (0,3) tEnd=1 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1 oppValue=0
126SkOpSegment::markDone id=4 (1,2 0,3) t=0 [7] (1,2) tEnd=1 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1 oppValue=0
127bridgeOp chase.append id=4 windSum=1
128SkOpSegment::debugShowActiveSpans id=1 (1,2 0,3 -0.333333343,3.33333325 0.833333373,3.5) t=0 tEnd=1 windSum=1 oppSum=1 windValue=1 oppValue=0
129SkOpSegment::debugShowActiveSpans id=2 (0.833333373,3.5 1,2) t=0 tEnd=1 windSum=1 oppSum=1 windValue=1 oppValue=0
130SkOpSegment::activeOp id=1 t=0 tEnd=1 op=sect miFrom=0 miTo=1 suFrom=1 suTo=1 result=1
131SkOpSegment::findNextOp simple
132SkOpSegment::markDone id=1 (1,2 0,3 -0.333333343,3.33333325 0.833333373,3.5) t=0 [1] (1,2) tEnd=1 newWindSum=1 newOppSum=1 oppSum=1 windSum=1 windValue=1 oppValue=0
133bridgeOp current id=1 from=(1,2) to=(0.833333373,3.5)
134path.moveTo(1,2);
135path.cubicTo(0,3, -0.333333343,3.33333325, 0.833333373,3.5);
136SkOpSegment::findNextOp
137SkOpAngle::dumpOne [2/4] next=4/2 sect=21/21 s=1 [4] e=0 [3] sgn=1 windVal=1 windSum=1 oppVal=0 oppSum=1
138SkOpAngle::dumpOne [4/2] next=1/3 sect=19/19 s=0 [7] e=1 [8] sgn=-1 windVal=1 windSum=1 oppVal=0 oppSum=0 done operand
139SkOpAngle::dumpOne [1/3] next=3/1 sect=20/21 s=0 [1] e=1 [2] sgn=-1 windVal=1 windSum=1 oppVal=0 oppSum=1 done
140SkOpAngle::dumpOne [3/1] next=2/4 sect=21/20 s=1 [6] e=0 [5] sgn=1 windVal=1 windSum=1 oppVal=0 oppSum=0 done operand
141SkOpSegment::activeOp id=4 t=0 tEnd=1 op=sect miFrom=0 miTo=0 suFrom=1 suTo=1 result=0
142SkOpSegment::activeOp id=1 t=0 tEnd=1 op=sect miFrom=0 miTo=1 suFrom=1 suTo=1 result=1
143SkOpSegment::activeOp id=3 t=1 tEnd=0 op=sect miFrom=1 miTo=1 suFrom=1 suTo=1 result=0
144SkOpSegment::markDone id=2 (0.833333373,3.5 1,2) t=0 [3] (0.833333373,3.5) tEnd=1 newWindSum=1 newOppSum=1 oppSum=1 windSum=1 windValue=1 oppValue=0
145SkOpSegment::findNextOp from:[2] to:[1] start=20180984 end=20181096
146bridgeOp current id=2 from=(0.833333373,3.5) to=(1,2)
147path.lineTo(1,2);
148path.close();
caryclarkdac1d172014-06-17 05:15:38 -0700149</div>
caryclark26ad22a2015-10-16 09:03:38 -0700150
caryclarkdac1d172014-06-17 05:15:38 -0700151</div>
152
153<script type="text/javascript">
154
caryclark55888e42016-07-18 10:01:36 -0700155 var testDivs = [
caryclark27c015d2016-09-23 05:47:20 -0700156 loop17,
caryclark30b9fdd2016-08-31 14:36:29 -0700157 ];
caryclarkdac1d172014-06-17 05:15:38 -0700158
159var decimal_places = 3; // make this 3 to show more precision
160
161var tests = [];
162var testLines = [];
163var testTitles = [];
164var testIndex = 0;
165var ctx;
166
167var xmin, xmax, focusXmin, focusXmax;
168var ymin, ymax, focusYmin, focusYmax;
169var scale;
170var mouseX, mouseY;
171var srcLeft, srcTop;
172var screenWidth, screenHeight;
caryclark1049f122015-04-20 08:31:59 -0700173var drawnPts, drawnLines, drawnQuads, drawnConics, drawnCubics;
caryclarkdac1d172014-06-17 05:15:38 -0700174var curveT = 0;
175
176var pt_labels = 2;
177var collect_bounds = false;
178var control_lines = 0;
179var curve_t = false;
180var debug_xy = 1;
181var focus_enabled = false;
182var focus_on_selection = false;
183var step_limit = 0;
184var draw_active = false;
185var draw_add = false;
186var draw_angle = 0;
caryclark624637c2015-05-11 07:21:27 -0700187var draw_coincidence = false;
caryclarkdac1d172014-06-17 05:15:38 -0700188var draw_deriviatives = 0;
189var draw_hints = false;
caryclarkdac1d172014-06-17 05:15:38 -0700190var draw_id = false;
191var draw_intersection = 0;
192var draw_intersectT = false;
193var draw_legend = true;
194var draw_log = false;
195var draw_mark = false;
196var draw_midpoint = false;
197var draw_op = 0;
198var draw_sequence = false;
199var draw_sort = 0;
caryclark03b03ca2015-04-23 09:13:37 -0700200var draw_top = false;
caryclarkdac1d172014-06-17 05:15:38 -0700201var draw_path = 3;
202var draw_computed = 0;
203var retina_scale = !!window.devicePixelRatio;
204
205var activeCount = 0;
206var addCount = 0;
207var angleCount = 0;
caryclark624637c2015-05-11 07:21:27 -0700208var coinCount = 0;
caryclarkdac1d172014-06-17 05:15:38 -0700209var opCount = 0;
210var sectCount = 0;
211var sortCount = 0;
caryclark03b03ca2015-04-23 09:13:37 -0700212var topCount = 0;
caryclarkdac1d172014-06-17 05:15:38 -0700213var markCount = 0;
214var activeMax = 0;
215var addMax = 0;
216var angleMax = 0;
caryclark624637c2015-05-11 07:21:27 -0700217var coinMax = 0;
caryclarkdac1d172014-06-17 05:15:38 -0700218var sectMax = 0;
219var sectMax2 = 0;
220var sortMax = 0;
caryclark03b03ca2015-04-23 09:13:37 -0700221var topMax = 0;
caryclarkdac1d172014-06-17 05:15:38 -0700222var markMax = 0;
223var opMax = 0;
224var stepMax = 0;
225var lastIndex = 0;
226var hasPath = false;
caryclark26ad22a2015-10-16 09:03:38 -0700227var hasAlignedPath = false;
caryclarkdac1d172014-06-17 05:15:38 -0700228var hasComputedPath = false;
caryclark54359292015-03-26 07:52:43 -0700229var angleBetween = false;
230var afterIndex = 0;
caryclarkdac1d172014-06-17 05:15:38 -0700231
232var firstActiveSpan = -1;
233var logStart = -1;
234var logRange = 0;
235
236var SPAN_ID = 0;
237var SPAN_X1 = SPAN_ID + 1;
238var SPAN_Y1 = SPAN_X1 + 1;
239var SPAN_X2 = SPAN_Y1 + 1;
240var SPAN_Y2 = SPAN_X2 + 1;
caryclark1049f122015-04-20 08:31:59 -0700241
caryclark55888e42016-07-18 10:01:36 -0700242var SPAN_L_TX = SPAN_Y2 + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700243var SPAN_L_TY = SPAN_L_TX + 1;
caryclark55888e42016-07-18 10:01:36 -0700244var SPAN_L_OTHER = SPAN_L_TY + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700245var SPAN_L_OTHERT = SPAN_L_OTHER + 1;
246var SPAN_L_OTHERI = SPAN_L_OTHERT + 1;
247var SPAN_L_SUM = SPAN_L_OTHERI + 1;
248var SPAN_L_VAL = SPAN_L_SUM + 1;
249var SPAN_L_OPP = SPAN_L_VAL + 1;
250
251var SPAN_X3 = SPAN_Y2 + 1;
252var SPAN_Y3 = SPAN_X3 + 1;
caryclark1049f122015-04-20 08:31:59 -0700253
caryclark55888e42016-07-18 10:01:36 -0700254var SPAN_Q_TX = SPAN_Y3 + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700255var SPAN_Q_TY = SPAN_Q_TX + 1;
caryclark55888e42016-07-18 10:01:36 -0700256var SPAN_Q_OTHER = SPAN_Q_TY + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700257var SPAN_Q_OTHERT = SPAN_Q_OTHER + 1;
258var SPAN_Q_OTHERI = SPAN_Q_OTHERT + 1;
259var SPAN_Q_SUM = SPAN_Q_OTHERI + 1;
260var SPAN_Q_VAL = SPAN_Q_SUM + 1;
261var SPAN_Q_OPP = SPAN_Q_VAL + 1;
262
caryclark1049f122015-04-20 08:31:59 -0700263var SPAN_K_W = SPAN_Y3 + 1;
caryclark55888e42016-07-18 10:01:36 -0700264var SPAN_K_TX = SPAN_K_W + 1;
caryclark1049f122015-04-20 08:31:59 -0700265var SPAN_K_TY = SPAN_K_TX + 1;
caryclark55888e42016-07-18 10:01:36 -0700266var SPAN_K_OTHER = SPAN_K_TY + 1;
caryclark1049f122015-04-20 08:31:59 -0700267var SPAN_K_OTHERT = SPAN_K_OTHER + 1;
268var SPAN_K_OTHERI = SPAN_K_OTHERT + 1;
269var SPAN_K_SUM = SPAN_K_OTHERI + 1;
270var SPAN_K_VAL = SPAN_K_SUM + 1;
271var SPAN_K_OPP = SPAN_K_VAL + 1;
272
caryclarkdac1d172014-06-17 05:15:38 -0700273var SPAN_X4 = SPAN_Y3 + 1;
274var SPAN_Y4 = SPAN_X4 + 1;
caryclark1049f122015-04-20 08:31:59 -0700275
caryclark55888e42016-07-18 10:01:36 -0700276var SPAN_C_TX = SPAN_Y4 + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700277var SPAN_C_TY = SPAN_C_TX + 1;
caryclark55888e42016-07-18 10:01:36 -0700278var SPAN_C_OTHER = SPAN_C_TY + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700279var SPAN_C_OTHERT = SPAN_C_OTHER + 1;
280var SPAN_C_OTHERI = SPAN_C_OTHERT + 1;
281var SPAN_C_SUM = SPAN_C_OTHERI + 1;
282var SPAN_C_VAL = SPAN_C_SUM + 1;
283var SPAN_C_OPP = SPAN_C_VAL + 1;
284
285var ACTIVE_LINE_SPAN = 1;
286var ACTIVE_QUAD_SPAN = ACTIVE_LINE_SPAN + 1;
caryclark1049f122015-04-20 08:31:59 -0700287var ACTIVE_CONIC_SPAN = ACTIVE_QUAD_SPAN + 1;
288var ACTIVE_CUBIC_SPAN = ACTIVE_CONIC_SPAN + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700289
290var ADD_MOVETO = ACTIVE_CUBIC_SPAN + 1;
291var ADD_LINETO = ADD_MOVETO + 1;
292var ADD_QUADTO = ADD_LINETO + 1;
caryclark1049f122015-04-20 08:31:59 -0700293var ADD_CONICTO = ADD_QUADTO + 1;
294var ADD_CUBICTO = ADD_CONICTO + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700295var ADD_CLOSE = ADD_CUBICTO + 1;
296var ADD_FILL = ADD_CLOSE + 1;
297
298var PATH_LINE = ADD_FILL + 1;
299var PATH_QUAD = PATH_LINE + 1;
caryclark1049f122015-04-20 08:31:59 -0700300var PATH_CONIC = PATH_QUAD + 1;
301var PATH_CUBIC = PATH_CONIC + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700302
303var INTERSECT_LINE = PATH_CUBIC + 1;
304var INTERSECT_LINE_2 = INTERSECT_LINE + 1;
305var INTERSECT_LINE_NO = INTERSECT_LINE_2 + 1;
306var INTERSECT_QUAD_LINE = INTERSECT_LINE_NO + 1;
307var INTERSECT_QUAD_LINE_2 = INTERSECT_QUAD_LINE + 1;
308var INTERSECT_QUAD_LINE_NO = INTERSECT_QUAD_LINE_2 + 1;
309var INTERSECT_QUAD = INTERSECT_QUAD_LINE_NO + 1;
310var INTERSECT_QUAD_2 = INTERSECT_QUAD + 1;
311var INTERSECT_QUAD_NO = INTERSECT_QUAD_2 + 1;
caryclark1049f122015-04-20 08:31:59 -0700312var INTERSECT_CONIC_LINE = INTERSECT_QUAD_NO + 1;
313var INTERSECT_CONIC_LINE_2 = INTERSECT_CONIC_LINE + 1;
314var INTERSECT_CONIC_LINE_NO = INTERSECT_CONIC_LINE_2 + 1;
caryclark55888e42016-07-18 10:01:36 -0700315var INTERSECT_CONIC_QUAD = INTERSECT_CONIC_LINE_NO + 1;
316var INTERSECT_CONIC_QUAD_2 = INTERSECT_CONIC_QUAD + 1;
317var INTERSECT_CONIC_QUAD_NO = INTERSECT_CONIC_QUAD_2 + 1;
318var INTERSECT_CONIC = INTERSECT_CONIC_QUAD_NO + 1;
caryclark1049f122015-04-20 08:31:59 -0700319var INTERSECT_CONIC_2 = INTERSECT_CONIC + 1;
320var INTERSECT_CONIC_NO = INTERSECT_CONIC_2 + 1;
321var INTERSECT_SELF_CUBIC = INTERSECT_CONIC_NO + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700322var INTERSECT_SELF_CUBIC_NO = INTERSECT_SELF_CUBIC + 1;
323var INTERSECT_CUBIC_LINE = INTERSECT_SELF_CUBIC_NO + 1;
324var INTERSECT_CUBIC_LINE_2 = INTERSECT_CUBIC_LINE + 1;
325var INTERSECT_CUBIC_LINE_3 = INTERSECT_CUBIC_LINE_2 + 1;
326var INTERSECT_CUBIC_LINE_NO = INTERSECT_CUBIC_LINE_3 + 1;
327var INTERSECT_CUBIC_QUAD = INTERSECT_CUBIC_LINE_NO + 1;
328var INTERSECT_CUBIC_QUAD_2 = INTERSECT_CUBIC_QUAD + 1;
329var INTERSECT_CUBIC_QUAD_3 = INTERSECT_CUBIC_QUAD_2 + 1;
330var INTERSECT_CUBIC_QUAD_4 = INTERSECT_CUBIC_QUAD_3 + 1;
331var INTERSECT_CUBIC_QUAD_NO = INTERSECT_CUBIC_QUAD_4 + 1;
332var INTERSECT_CUBIC = INTERSECT_CUBIC_QUAD_NO + 1;
333var INTERSECT_CUBIC_2 = INTERSECT_CUBIC + 1;
334var INTERSECT_CUBIC_3 = INTERSECT_CUBIC_2 + 1;
335var INTERSECT_CUBIC_4 = INTERSECT_CUBIC_3 + 1;
336// FIXME: add cubic 5- 9
337var INTERSECT_CUBIC_NO = INTERSECT_CUBIC_4 + 1;
338
339var SORT_UNARY = INTERSECT_CUBIC_NO + 1;
340var SORT_BINARY = SORT_UNARY + 1;
341
342var OP_DIFFERENCE = SORT_BINARY + 1;
343var OP_INTERSECT = OP_DIFFERENCE + 1;
344var OP_UNION = OP_INTERSECT + 1;
345var OP_XOR = OP_UNION + 1;
346
347var MARK_LINE = OP_XOR + 1;
348var MARK_QUAD = MARK_LINE + 1;
caryclark1049f122015-04-20 08:31:59 -0700349var MARK_CONIC = MARK_QUAD + 1;
350var MARK_CUBIC = MARK_CONIC + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700351var MARK_DONE_LINE = MARK_CUBIC + 1;
352var MARK_DONE_QUAD = MARK_DONE_LINE + 1;
caryclark1049f122015-04-20 08:31:59 -0700353var MARK_DONE_CONIC = MARK_DONE_QUAD + 1;
354var MARK_DONE_CUBIC = MARK_DONE_CONIC + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700355var MARK_UNSORTABLE_LINE = MARK_DONE_CUBIC + 1;
356var MARK_UNSORTABLE_QUAD = MARK_UNSORTABLE_LINE + 1;
caryclark1049f122015-04-20 08:31:59 -0700357var MARK_UNSORTABLE_CONIC = MARK_UNSORTABLE_QUAD + 1;
358var MARK_UNSORTABLE_CUBIC = MARK_UNSORTABLE_CONIC + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700359var MARK_SIMPLE_LINE = MARK_UNSORTABLE_CUBIC + 1;
360var MARK_SIMPLE_QUAD = MARK_SIMPLE_LINE + 1;
caryclark1049f122015-04-20 08:31:59 -0700361var MARK_SIMPLE_CONIC = MARK_SIMPLE_QUAD + 1;
362var MARK_SIMPLE_CUBIC = MARK_SIMPLE_CONIC + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700363var MARK_SIMPLE_DONE_LINE = MARK_SIMPLE_CUBIC + 1;
364var MARK_SIMPLE_DONE_QUAD = MARK_SIMPLE_DONE_LINE + 1;
caryclark1049f122015-04-20 08:31:59 -0700365var MARK_SIMPLE_DONE_CONIC = MARK_SIMPLE_DONE_QUAD + 1;
366var MARK_SIMPLE_DONE_CUBIC = MARK_SIMPLE_DONE_CONIC + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700367var MARK_DONE_UNARY_LINE = MARK_SIMPLE_DONE_CUBIC + 1;
368var MARK_DONE_UNARY_QUAD = MARK_DONE_UNARY_LINE + 1;
caryclark1049f122015-04-20 08:31:59 -0700369var MARK_DONE_UNARY_CONIC = MARK_DONE_UNARY_QUAD + 1;
370var MARK_DONE_UNARY_CUBIC = MARK_DONE_UNARY_CONIC + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700371var MARK_ANGLE_LAST = MARK_DONE_UNARY_CUBIC + 1;
372
373var COMPUTED_SET_1 = MARK_ANGLE_LAST + 1;
374var COMPUTED_SET_2 = COMPUTED_SET_1 + 1;
375
caryclark624637c2015-05-11 07:21:27 -0700376var ANGLE_AFTER = COMPUTED_SET_2 + 1;
caryclark54359292015-03-26 07:52:43 -0700377var ANGLE_AFTERPART = ANGLE_AFTER + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700378
caryclark54359292015-03-26 07:52:43 -0700379var ACTIVE_OP = ANGLE_AFTERPART + 1;
caryclarkdac1d172014-06-17 05:15:38 -0700380
caryclark624637c2015-05-11 07:21:27 -0700381var COIN_MAIN_SPAN = ACTIVE_OP + 1;
382var COIN_OPP_SPAN = COIN_MAIN_SPAN + 1;
383
384var FRAG_TYPE_LAST = COIN_OPP_SPAN;
caryclarkdac1d172014-06-17 05:15:38 -0700385
386var REC_TYPE_UNKNOWN = -1;
387var REC_TYPE_PATH = 0;
caryclark54359292015-03-26 07:52:43 -0700388var REC_TYPE_PATH2 = 1;
389var REC_TYPE_SECT = 2;
390var REC_TYPE_ACTIVE = 3;
391var REC_TYPE_ADD = 4;
392var REC_TYPE_SORT = 5;
393var REC_TYPE_OP = 6;
394var REC_TYPE_MARK = 7;
395var REC_TYPE_COMPUTED = 8;
396var REC_TYPE_COIN = 9;
397var REC_TYPE_ANGLE = 10;
398var REC_TYPE_ACTIVE_OP = 11;
399var REC_TYPE_AFTERPART = 12;
caryclark03b03ca2015-04-23 09:13:37 -0700400var REC_TYPE_TOP = 13;
caryclark624637c2015-05-11 07:21:27 -0700401var REC_TYPE_COINCIDENCE = 14;
caryclark26ad22a2015-10-16 09:03:38 -0700402var REC_TYPE_ALIGNED = 15;
403var REC_TYPE_LAST = REC_TYPE_ALIGNED;
caryclarkdac1d172014-06-17 05:15:38 -0700404
405function strs_to_nums(strs) {
406 var result = [];
407 for (var idx = 1; idx < strs.length; ++idx) {
408 var str = strs[idx];
409 var num = parseFloat(str);
410 if (isNaN(num)) {
411 result.push(str);
412 } else {
413 result.push(num);
414 }
415 }
416 return result;
417}
418
419function filter_str_by(id, str, regex, array) {
420 if (regex.test(str)) {
421 var strs = regex.exec(str);
422 var result = strs_to_nums(strs);
423 array.push(id);
424 array.push(result);
425 return true;
426 }
427 return false;
428}
429
430function construct_regexp2(pattern) {
431 var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
432 escape = escape.replace(/UNSORTABLE/g, "\\*\\*\\* UNSORTABLE \\*\\*\\*");
433 escape = escape.replace(/CUBIC_VAL/g, "\\(P_VAL P_VAL P_VAL P_VAL\\)");
caryclark1049f122015-04-20 08:31:59 -0700434 escape = escape.replace(/CONIC_VAL/g, "\\(P_VAL P_VAL P_VAL W_VAL\\)");
caryclarkdac1d172014-06-17 05:15:38 -0700435 escape = escape.replace(/QUAD_VAL/g, "\\(P_VAL P_VAL P_VAL\\)");
436 escape = escape.replace(/LINE_VAL/g, "\\(P_VAL P_VAL\\)");
437 escape = escape.replace(/FILL_TYPE/g, "SkPath::k[a-zA-Z]+_FillType");
caryclark54359292015-03-26 07:52:43 -0700438 escape = escape.replace(/PTR_VAL/g, "0x[0-9A-F]+");
caryclarkdac1d172014-06-17 05:15:38 -0700439 escape = escape.replace(/PT_VAL/g, "\\(P_VAL\\)");
440 escape = escape.replace(/P_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?, ?(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?");
441 escape = escape.replace(/T_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)");
caryclark1049f122015-04-20 08:31:59 -0700442 escape = escape.replace(/W_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?");
caryclarkdac1d172014-06-17 05:15:38 -0700443 escape = escape.replace(/PATH/g, "pathB?");
caryclark1049f122015-04-20 08:31:59 -0700444 escape = escape.replace(/IDX/g, "(-?\\d+)");
caryclarkdac1d172014-06-17 05:15:38 -0700445 escape = escape.replace(/NUM/g, "(-?\\d+)");
446 escape = escape.replace(/OPT/g, "(\\?|-?\\d+)");
447 return new RegExp(escape, 'i');
448}
449
450function construct_regexp2c(pattern) {
451 var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
452 escape = escape.replace(/UNSORTABLE/g, "\\*\\*\\* UNSORTABLE \\*\\*\\*");
caryclark54359292015-03-26 07:52:43 -0700453 escape = escape.replace(/CUBIC_VAL/g, "(?:\\$\\d = )?\\{\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}\\}");
caryclark1049f122015-04-20 08:31:59 -0700454 escape = escape.replace(/CONIC_VAL/g, "(?:\\$\\d = )?\\{\\{\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}\\}, W_VAL\\}");
caryclark54359292015-03-26 07:52:43 -0700455 escape = escape.replace(/QUAD_VAL/g, "(?:\\$\\d = )?\\{\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}\\}");
456 escape = escape.replace(/LINE_VAL/g, "(?:\\$\\d = )?\\{\\{\\{P_VAL\\}, \\{P_VAL\\}\\}\\}");
caryclarkdac1d172014-06-17 05:15:38 -0700457 escape = escape.replace(/FILL_TYPE/g, "SkPath::k[a-zA-Z]+_FillType");
caryclark54359292015-03-26 07:52:43 -0700458 escape = escape.replace(/PTR_VAL/g, "0x[0-9A-F]+");
caryclarkdac1d172014-06-17 05:15:38 -0700459 escape = escape.replace(/PT_VAL/g, "\\{\\{P_VAL\\}\\}");
caryclark54359292015-03-26 07:52:43 -0700460 escape = escape.replace(/P_VAL/g, "(?:f?[xX] = )?(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?, *(?: f?[yY] = )?(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?");
caryclarkdac1d172014-06-17 05:15:38 -0700461 escape = escape.replace(/T_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)");
caryclark1049f122015-04-20 08:31:59 -0700462 escape = escape.replace(/W_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?");
caryclarkdac1d172014-06-17 05:15:38 -0700463 escape = escape.replace(/OPER/g, "[a-z]+");
464 escape = escape.replace(/PATH/g, "pathB?");
465 escape = escape.replace(/T_F/g, "([TF])");
caryclark1049f122015-04-20 08:31:59 -0700466 escape = escape.replace(/IDX/g, "(-?\\d+)");
caryclarkdac1d172014-06-17 05:15:38 -0700467 escape = escape.replace(/NUM/g, "(-?\\d+)");
468 escape = escape.replace(/OPT/g, "(\\?|-?\\d+)");
469 return new RegExp(escape, 'i');
470}
471
472function match_regexp(str, lineNo, array, id, pattern) {
473 var regex = construct_regexp2(pattern);
474 if (filter_str_by(id, str, regex, array)) {
475 return true;
476 }
477 regex = construct_regexp2c(pattern);
478 return filter_str_by(id, str, regex, array);
479}
480
481function endsWith(str, suffix) {
482 return str.indexOf(suffix, str.length - suffix.length) !== -1;
483}
484
485function parse_all(test) {
486 var lines = test.match(/[^\r\n]+/g);
487 var records = []; // a rec can be the original paths, a set of intersections, a set of active spans, a sort, or a path add
488 var record = [];
489 var recType = REC_TYPE_UNKNOWN;
490 var lastLineNo;
491 var moveX, moveY;
492 for (var lineNo = 0; lineNo < lines.length; ++lineNo) {
493 var line = lines[lineNo];
494 if (line.length == 0) {
495 continue;
496 }
497 var opStart = "SkOpSegment::";
498 if (line.lastIndexOf(opStart, 0) === 0) {
499 line = line.substr(opStart.length);
500 }
501 var angleStart = "SkOpAngle::";
502 if (line.lastIndexOf(angleStart, 0) === 0) {
503 line = line.substr(angleStart.length);
504 }
caryclark624637c2015-05-11 07:21:27 -0700505 var coinStart = "SkOpCoincidence::";
506 if (line.lastIndexOf(coinStart, 0) === 0) {
507 line = line.substr(coinStart.length);
508 }
caryclark54359292015-03-26 07:52:43 -0700509 var type = line.lastIndexOf("debugShowActiveSpans", 0) === 0 ? REC_TYPE_ACTIVE
caryclark624637c2015-05-11 07:21:27 -0700510 : line.lastIndexOf("debugShowCoincidence", 0) === 0 ? REC_TYPE_COINCIDENCE
caryclark54359292015-03-26 07:52:43 -0700511 : line.lastIndexOf("((SkOpSegment*)", 0) === 0 ? REC_TYPE_PATH2
caryclark55888e42016-07-18 10:01:36 -0700512 : line.lastIndexOf("debugShowTs", 0) === 0 ? REC_TYPE_COIN
caryclark54359292015-03-26 07:52:43 -0700513 : line.lastIndexOf("afterPart", 0) === 0 ? REC_TYPE_AFTERPART
caryclarkdac1d172014-06-17 05:15:38 -0700514 : line.lastIndexOf("debugShow", 0) === 0 ? REC_TYPE_SECT
515 : line.lastIndexOf("activeOp", 0) === 0 ? REC_TYPE_ACTIVE_OP
516 : line.lastIndexOf("computed", 0) === 0 ? REC_TYPE_COMPUTED
517 : line.lastIndexOf("debugOne", 0) === 0 ? REC_TYPE_SORT
caryclark26ad22a2015-10-16 09:03:38 -0700518 : line.lastIndexOf("aligned=", 0) === 0 ? REC_TYPE_ALIGNED
caryclarkdac1d172014-06-17 05:15:38 -0700519 : line.lastIndexOf("dumpOne", 0) === 0 ? REC_TYPE_SORT
caryclark03b03ca2015-04-23 09:13:37 -0700520 : line.lastIndexOf("findTop", 0) === 0 ? REC_TYPE_TOP
caryclarkdac1d172014-06-17 05:15:38 -0700521 : line.lastIndexOf("pathB.", 0) === 0 ? REC_TYPE_ADD
522 : line.lastIndexOf("path.", 0) === 0 ? REC_TYPE_ADD
523 : line.lastIndexOf("after", 0) === 0 ? REC_TYPE_ANGLE
524 : line.lastIndexOf("mark", 0) === 0 ? REC_TYPE_MARK
525 : line.lastIndexOf(" {{", 0) === 0 ? REC_TYPE_COMPUTED
caryclark54359292015-03-26 07:52:43 -0700526 : line.lastIndexOf("seg=", 0) === 0 ? REC_TYPE_PATH
caryclarkdac1d172014-06-17 05:15:38 -0700527 : line.lastIndexOf("op", 0) === 0 ? REC_TYPE_OP
528 : line.lastIndexOf("$", 0) === 0 ? REC_TYPE_PATH
529 : REC_TYPE_UNKNOWN;
530 if (recType != type || recType == REC_TYPE_ADD || recType == REC_TYPE_SECT
531 || recType == REC_TYPE_ACTIVE_OP || recType == REC_TYPE_ANGLE) {
532 if (recType != REC_TYPE_UNKNOWN) {
533 records.push(recType);
534 records.push(lastLineNo);
535 records.push(record);
536 }
537 record = [];
538 recType = type;
539 lastLineNo = lineNo;
540 }
541 var found = false;
542 switch (recType) {
543 case REC_TYPE_ACTIVE:
544 found = match_regexp(line, lineNo, record, ACTIVE_LINE_SPAN, "debugShowActiveSpans" +
caryclark55888e42016-07-18 10:01:36 -0700545" id=IDX LINE_VAL t=T_VAL tEnd=T_VAL windSum=OPT windValue=IDX"
caryclarkdac1d172014-06-17 05:15:38 -0700546 ) || match_regexp(line, lineNo, record, ACTIVE_QUAD_SPAN, "debugShowActiveSpans" +
caryclark55888e42016-07-18 10:01:36 -0700547" id=IDX QUAD_VAL t=T_VAL tEnd=T_VAL windSum=OPT windValue=IDX"
caryclark1049f122015-04-20 08:31:59 -0700548 ) || match_regexp(line, lineNo, record, ACTIVE_CONIC_SPAN, "debugShowActiveSpans" +
caryclark55888e42016-07-18 10:01:36 -0700549" id=IDX CONIC_VAL t=T_VAL tEnd=T_VAL windSum=OPT windValue=IDX"
caryclarkdac1d172014-06-17 05:15:38 -0700550 ) || match_regexp(line, lineNo, record, ACTIVE_CUBIC_SPAN, "debugShowActiveSpans" +
caryclark55888e42016-07-18 10:01:36 -0700551" id=IDX CUBIC_VAL t=T_VAL tEnd=T_VAL windSum=OPT windValue=IDX"
caryclark624637c2015-05-11 07:21:27 -0700552 ) || match_regexp(line, lineNo, record, ACTIVE_LINE_SPAN, "debugShowActiveSpans" +
caryclark55888e42016-07-18 10:01:36 -0700553" id=IDX LINE_VAL t=T_VAL tEnd=T_VAL windSum=OPT oppSum=OPT windValue=IDX oppValue=NUM"
caryclark624637c2015-05-11 07:21:27 -0700554 ) || match_regexp(line, lineNo, record, ACTIVE_QUAD_SPAN, "debugShowActiveSpans" +
caryclark55888e42016-07-18 10:01:36 -0700555" id=IDX QUAD_VAL t=T_VAL tEnd=T_VAL windSum=OPT oppSum=OPT windValue=IDX oppValue=NUM"
caryclark624637c2015-05-11 07:21:27 -0700556 ) || match_regexp(line, lineNo, record, ACTIVE_CONIC_SPAN, "debugShowActiveSpans" +
caryclark55888e42016-07-18 10:01:36 -0700557" id=IDX CONIC_VAL t=T_VAL tEnd=T_VAL windSum=OPT oppSum=OPT windValue=IDX oppValue=NUM"
caryclark624637c2015-05-11 07:21:27 -0700558 ) || match_regexp(line, lineNo, record, ACTIVE_CUBIC_SPAN, "debugShowActiveSpans" +
caryclark55888e42016-07-18 10:01:36 -0700559" id=IDX CUBIC_VAL t=T_VAL tEnd=T_VAL windSum=OPT oppSum=OPT windValue=IDX oppValue=NUM"
caryclarkdac1d172014-06-17 05:15:38 -0700560 );
561 break;
562 case REC_TYPE_ACTIVE_OP:
563 found = match_regexp(line, lineNo, record, ACTIVE_OP, "activeOp" +
564" id=IDX t=T_VAL tEnd=T_VAL op=OPER miFrom=NUM miTo=NUM suFrom=NUM suTo=NUM result=IDX"
565 );
566 break;
567 case REC_TYPE_ADD:
568 if (match_regexp(line, lineNo, record, ADD_MOVETO, "PATH.moveTo(P_VAL);")) {
569 moveX = record[1][0];
570 moveY = record[1][1];
571 found = true;
572 } else if (match_regexp(line, lineNo, record, ADD_LINETO, "PATH.lineTo(P_VAL);")) {
573 record[1].unshift(moveY);
574 record[1].unshift(moveX);
575 moveX = record[1][2];
576 moveY = record[1][3];
577 found = true;
578 } else if (match_regexp(line, lineNo, record, ADD_QUADTO, "PATH.quadTo(P_VAL, P_VAL);")) {
579 record[1].unshift(moveY);
580 record[1].unshift(moveX);
581 moveX = record[1][4];
582 moveY = record[1][5];
583 found = true;
caryclark1049f122015-04-20 08:31:59 -0700584 } else if (match_regexp(line, lineNo, record, ADD_CONICTO, "PATH.conicTo(P_VAL, P_VAL, T_VAL);")) {
585 record[1].unshift(moveY);
586 record[1].unshift(moveX);
587 moveX = record[1][4];
588 moveY = record[1][5];
589 found = true;
caryclarkdac1d172014-06-17 05:15:38 -0700590 } else if (match_regexp(line, lineNo, record, ADD_CUBICTO, "PATH.cubicTo(P_VAL, P_VAL, P_VAL);")) {
591 record[1].unshift(moveY);
592 record[1].unshift(moveX);
593 moveX = record[1][6];
594 moveY = record[1][7];
595 found = true;
596 } else if (match_regexp(line, lineNo, record, ADD_FILL, "PATH.setFillType(FILL_TYPE);")) {
597 found = true;
598 } else {
599 found = match_regexp(line, lineNo, record, ADD_CLOSE, "PATH.close();");
600 }
601 break;
caryclark54359292015-03-26 07:52:43 -0700602 case REC_TYPE_AFTERPART:
603 found = match_regexp(line, lineNo, record, PATH_LINE, "afterPart LINE_VAL")
604 || match_regexp(line, lineNo, record, PATH_QUAD, "afterPart QUAD_VAL")
caryclark1049f122015-04-20 08:31:59 -0700605 || match_regexp(line, lineNo, record, PATH_CONIC, "afterPart CONIC_VAL")
caryclark54359292015-03-26 07:52:43 -0700606 || match_regexp(line, lineNo, record, PATH_CUBIC, "afterPart CUBIC_VAL")
607 break;
caryclark26ad22a2015-10-16 09:03:38 -0700608 case REC_TYPE_ALIGNED:
609 found = match_regexp(line, lineNo, record, PATH_LINE, "aligned=IDX LINE_VAL"
610 ) || match_regexp(line, lineNo, record, PATH_QUAD, "aligned=IDX QUAD_VAL"
611 ) || match_regexp(line, lineNo, record, PATH_CONIC, "aligned=IDX CONIC_VAL"
612 ) || match_regexp(line, lineNo, record, PATH_CUBIC, "aligned=IDX CUBIC_VAL"
613 );
614 break;
caryclarkdac1d172014-06-17 05:15:38 -0700615 case REC_TYPE_ANGLE:
616 found = match_regexp(line, lineNo, record, ANGLE_AFTER, "after " +
caryclarkdac1d172014-06-17 05:15:38 -0700617"[IDX/IDX] NUM/NUM tStart=T_VAL tEnd=T_VAL < [IDX/IDX] NUM/NUM tStart=T_VAL tEnd=T_VAL < [IDX/IDX] NUM/NUM tStart=T_VAL tEnd=T_VAL T_F IDX");
618 break;
619 case REC_TYPE_COIN:
620 found = true;
621 break;
caryclark624637c2015-05-11 07:21:27 -0700622 case REC_TYPE_COINCIDENCE:
623 found = match_regexp(line, lineNo, record, COIN_MAIN_SPAN, "debugShowCoincidence" +
624" + id=IDX t=T_VAL tEnd=T_VAL"
625 ) || match_regexp(line, lineNo, record, COIN_OPP_SPAN, "debugShowCoincidence" +
626" - id=IDX t=T_VAL tEnd=T_VAL"
627 );
628 break;
caryclarkdac1d172014-06-17 05:15:38 -0700629 case REC_TYPE_COMPUTED:
630 found = line == "computed quadratics given"
631 || match_regexp(line, lineNo, record, COMPUTED_SET_1, "computed quadratics set 1"
632 ) || match_regexp(line, lineNo, record, COMPUTED_SET_2, "computed quadratics set 2"
633 ) || match_regexp(line, lineNo, record, PATH_QUAD, " QUAD_VAL,"
caryclark1049f122015-04-20 08:31:59 -0700634 ) || match_regexp(line, lineNo, record, PATH_CONIC, " CONIC_VAL,"
caryclarkdac1d172014-06-17 05:15:38 -0700635 ) || match_regexp(line, lineNo, record, PATH_CUBIC, " CUBIC_VAL,"
636 );
637 break;
638 case REC_TYPE_PATH:
caryclark54359292015-03-26 07:52:43 -0700639 found = match_regexp(line, lineNo, record, PATH_LINE, "seg=IDX LINE_VAL"
640 ) || match_regexp(line, lineNo, record, PATH_QUAD, "seg=IDX QUAD_VAL"
caryclark1049f122015-04-20 08:31:59 -0700641 ) || match_regexp(line, lineNo, record, PATH_CONIC, "seg=IDX CONIC_VAL"
caryclark54359292015-03-26 07:52:43 -0700642 ) || match_regexp(line, lineNo, record, PATH_CUBIC, "seg=IDX CUBIC_VAL"
643 );
644 break;
645 case REC_TYPE_PATH2:
646 found = match_regexp(line, lineNo, record, PATH_LINE, "((SkOpSegment*) PTR_VAL) [IDX] {LINE_VAL}"
647 ) || match_regexp(line, lineNo, record, PATH_QUAD, "((SkOpSegment*) PTR_VAL) [IDX] {QUAD_VAL}"
caryclark1049f122015-04-20 08:31:59 -0700648 ) || match_regexp(line, lineNo, record, PATH_CONIC, "((SkOpSegment*) PTR_VAL) [IDX] {CONIC_VAL}"
caryclark54359292015-03-26 07:52:43 -0700649 ) || match_regexp(line, lineNo, record, PATH_CUBIC, "((SkOpSegment*) PTR_VAL) [IDX] {CUBIC_VAL}"
caryclarkdac1d172014-06-17 05:15:38 -0700650 );
651 break;
652 case REC_TYPE_SECT:
653 found = match_regexp(line, lineNo, record, INTERSECT_LINE, "debugShowLineIntersection" +
654" wtTs[0]=T_VAL LINE_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
655 ) || match_regexp(line, lineNo, record, INTERSECT_LINE_2, "debugShowLineIntersection" +
656" wtTs[0]=T_VAL LINE_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
657 ) || match_regexp(line, lineNo, record, INTERSECT_LINE_NO, "debugShowLineIntersection" +
658" no intersect LINE_VAL LINE_VAL"
659 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE, "debugShowQuadLineIntersection" +
660" wtTs[0]=T_VAL QUAD_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
661 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE_2, "debugShowQuadLineIntersection" +
662" wtTs[0]=T_VAL QUAD_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
663 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE_NO, "debugShowQuadLineIntersection" +
664" no intersect QUAD_VAL LINE_VAL"
665 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD, "debugShowQuadIntersection" +
666" wtTs[0]=T_VAL QUAD_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL"
667 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_2, "debugShowQuadIntersection" +
668" wtTs[0]=T_VAL QUAD_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL"
669 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_NO, "debugShowQuadIntersection" +
670" no intersect QUAD_VAL QUAD_VAL"
caryclark55888e42016-07-18 10:01:36 -0700671
caryclark1049f122015-04-20 08:31:59 -0700672 ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_LINE, "debugShowConicLineIntersection" +
673" wtTs[0]=T_VAL CONIC_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
674 ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_LINE_2, "debugShowConicLineIntersection" +
675" wtTs[0]=T_VAL CONIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
676 ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_LINE_NO, "debugShowConicLineIntersection" +
677" no intersect CONIC_VAL LINE_VAL"
caryclark55888e42016-07-18 10:01:36 -0700678
679 ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_QUAD, "debugShowConicQuadIntersection" +
680" wtTs[0]=T_VAL CONIC_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL"
681 ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_QUAD_2, "debugShowConicQuadIntersection" +
682" wtTs[0]=T_VAL CONIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL"
683 ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_QUAD_NO, "debugShowConicQuadIntersection" +
684" no intersect CONIC_VAL QUAD_VAL"
685
caryclark1049f122015-04-20 08:31:59 -0700686 ) || match_regexp(line, lineNo, record, INTERSECT_CONIC, "debugShowConicIntersection" +
687" wtTs[0]=T_VAL CONIC_VAL PT_VAL wnTs[0]=T_VAL CONIC_VAL"
688 ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_2, "debugShowConicIntersection" +
689" wtTs[0]=T_VAL CONIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL CONIC_VAL wnTs[1]=T_VAL"
690 ) || match_regexp(line, lineNo, record, INTERSECT_CONIC_NO, "debugShowConicIntersection" +
691" no intersect CONIC_VAL CONIC_VAL"
caryclarkdac1d172014-06-17 05:15:38 -0700692 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE, "debugShowCubicLineIntersection" +
693" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
694 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_2, "debugShowCubicLineIntersection" +
695" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
696 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_3, "debugShowCubicLineIntersection" +
697" 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"
698 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_NO, "debugShowCubicLineIntersection" +
699" no intersect CUBIC_VAL LINE_VAL"
700 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD, "debugShowCubicQuadIntersection" +
701" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL"
702 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD_2, "debugShowCubicQuadIntersection" +
703" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL"
704 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD_3, "debugShowCubicQuadIntersection" +
705" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wtTs[2]=T_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL wnTs[2]=T_VAL"
706 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD_4, "debugShowCubicQuadIntersection" +
707" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wtTs[2]=T_VAL wtTs[3]=T_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL wnTs[2]=T_VAL wnTs[3]=T_VAL"
708 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD_NO, "debugShowCubicQuadIntersection" +
709" no intersect CUBIC_VAL QUAD_VAL"
710 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC, "debugShowCubicIntersection" +
711" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL"
712 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_2, "debugShowCubicIntersection" +
713" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL wnTs[1]=T_VAL"
714 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_3, "debugShowCubicIntersection" +
715" 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"
716 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_4, "debugShowCubicIntersection" +
717" 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"
718 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_NO, "debugShowCubicIntersection" +
719" no intersect CUBIC_VAL CUBIC_VAL"
720 ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC, "debugShowCubicIntersection" +
721" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL"
722 ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC_NO, "debugShowCubicIntersection" +
723" no self intersect CUBIC_VAL"
724 );
725 break;
726 case REC_TYPE_SORT:
727 var hasDone = / done/.test(line);
728 var hasUnorderable = / unorderable/.test(line);
729 var hasSmall = / small/.test(line);
730 var hasTiny = / tiny/.test(line);
731 var hasOperand = / operand/.test(line);
732 var hasStop = / stop/.test(line);
733 line.replace(/[ a-z]+$/, "");
734 found = match_regexp(line, lineNo, record, SORT_UNARY, "debugOne" +
735" [IDX/IDX] next=IDX/IDX sect=IDX/IDX s=T_VAL [IDX] e=T_VAL [IDX] sgn=NUM windVal=IDX windSum=OPT"
736 ) || match_regexp(line, lineNo, record, SORT_BINARY, "debugOne" +
737" [IDX/IDX] next=IDX/IDX sect=IDX/IDX s=T_VAL [IDX] e=T_VAL [IDX] sgn=NUM windVal=IDX windSum=OPT oppVal=IDX oppSum=OPT"
738 ) || match_regexp(line, lineNo, record, SORT_UNARY, "dumpOne" +
739" [IDX/IDX] next=IDX/IDX sect=NUM/NUM s=T_VAL [IDX] e=T_VAL [IDX] sgn=NUM windVal=IDX windSum=OPT"
740 ) || match_regexp(line, lineNo, record, SORT_BINARY, "dumpOne" +
741" [IDX/IDX] next=IDX/IDX sect=NUM/NUM s=T_VAL [IDX] e=T_VAL [IDX] sgn=NUM windVal=IDX windSum=OPT oppVal=IDX oppSum=OPT"
742 );
743 if (found) {
744 record[1].push(hasDone);
745 record[1].push(hasUnorderable);
746 record[1].push(hasSmall);
747 record[1].push(hasTiny);
748 record[1].push(hasOperand);
749 record[1].push(hasStop);
750 }
751 break;
caryclark03b03ca2015-04-23 09:13:37 -0700752 case REC_TYPE_TOP:
753 found = match_regexp(line, lineNo, record, ACTIVE_OP, "findTop" +
754" id=IDX s=T_VAL e=T_VAL cw=NUM swap=NUM inflections=NUM monotonic=NUM"
755 ) || match_regexp(line, lineNo, record, ACTIVE_OP, "findTop" +
756" id=IDX s=T_VAL e=T_VAL (-) cw=NUM swap=NUM inflections=NUM monotonic=NUM"
757 ) || match_regexp(line, lineNo, record, ACTIVE_OP, "findTop" +
758" id=IDX s=T_VAL e=T_VAL (+) cw=NUM swap=NUM inflections=NUM monotonic=NUM"
759 );
760 break;
caryclarkdac1d172014-06-17 05:15:38 -0700761 case REC_TYPE_MARK:
762 found = match_regexp(line, lineNo, record, MARK_LINE, "markWinding" +
caryclark54359292015-03-26 07:52:43 -0700763" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX"
caryclarkdac1d172014-06-17 05:15:38 -0700764 ) || match_regexp(line, lineNo, record, MARK_QUAD, "markWinding" +
caryclark54359292015-03-26 07:52:43 -0700765" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX"
caryclark1049f122015-04-20 08:31:59 -0700766 ) || match_regexp(line, lineNo, record, MARK_CONIC, "markWinding" +
767" id=IDX CONIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX"
caryclarkdac1d172014-06-17 05:15:38 -0700768 ) || match_regexp(line, lineNo, record, MARK_CUBIC, "markWinding" +
caryclark54359292015-03-26 07:52:43 -0700769" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX"
770 ) || match_regexp(line, lineNo, record, MARK_DONE_LINE, "markDone" +
771" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=OPT newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX oppValue=OPT"
772 ) || match_regexp(line, lineNo, record, MARK_DONE_QUAD, "markDone" +
773" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=OPT newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX oppValue=OPT"
caryclark1049f122015-04-20 08:31:59 -0700774 ) || match_regexp(line, lineNo, record, MARK_DONE_CONIC, "markDone" +
775" id=IDX CONIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=OPT newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX oppValue=OPT"
caryclark54359292015-03-26 07:52:43 -0700776 ) || match_regexp(line, lineNo, record, MARK_DONE_CUBIC, "markDone" +
777" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=OPT newOppSum=OPT oppSum=OPT windSum=OPT windValue=IDX oppValue=OPT"
caryclarkdac1d172014-06-17 05:15:38 -0700778 ) || match_regexp(line, lineNo, record, MARK_SIMPLE_LINE, "markWinding" +
779" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
780 ) || match_regexp(line, lineNo, record, MARK_SIMPLE_QUAD, "markWinding" +
781" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
caryclark1049f122015-04-20 08:31:59 -0700782 ) || match_regexp(line, lineNo, record, MARK_SIMPLE_CONIC, "markWinding" +
783" id=IDX CONIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
caryclarkdac1d172014-06-17 05:15:38 -0700784 ) || match_regexp(line, lineNo, record, MARK_SIMPLE_CUBIC, "markWinding" +
785" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
caryclarkdac1d172014-06-17 05:15:38 -0700786 ) || match_regexp(line, lineNo, record, MARK_ANGLE_LAST, "markAngle" +
caryclark1049f122015-04-20 08:31:59 -0700787" last segment=IDX span=IDX"
caryclark54359292015-03-26 07:52:43 -0700788 ) || match_regexp(line, lineNo, record, MARK_ANGLE_LAST, "markAngle" +
caryclark55888e42016-07-18 10:01:36 -0700789" last seg=IDX span=IDX"
790 ) || match_regexp(line, lineNo, record, MARK_ANGLE_LAST, "markAngle" +
791" last segment=IDX span=IDX windSum=OPT"
792 ) || match_regexp(line, lineNo, record, MARK_ANGLE_LAST, "markAngle" +
793" last seg=IDX span=IDX windSum=OPT"
794 );
caryclarkdac1d172014-06-17 05:15:38 -0700795 break;
796 case REC_TYPE_OP:
797 if (line.lastIndexOf("oppSign oppSign=", 0) === 0
798 || line.lastIndexOf("operator<", 0) === 0) {
799 found = true;
800 break;
801 }
caryclark54359292015-03-26 07:52:43 -0700802 found = match_regexp(line, lineNo, record, OP_DIFFERENCE, "op diff"
caryclarkdac1d172014-06-17 05:15:38 -0700803 ) || match_regexp(line, lineNo, record, OP_INTERSECT, "op intersect"
caryclark54359292015-03-26 07:52:43 -0700804 ) || match_regexp(line, lineNo, record, OP_INTERSECT, "op sect"
caryclarkdac1d172014-06-17 05:15:38 -0700805 ) || match_regexp(line, lineNo, record, OP_UNION, "op union"
806 ) || match_regexp(line, lineNo, record, OP_XOR, "op xor"
807 );
808 break;
809 case REC_TYPE_UNKNOWN:
810 found = true;
811 break;
812 }
813 if (!found) {
814 console.log(line + " [" + lineNo + "] of type " + type + " not found");
815 }
816 }
817 if (recType != REC_TYPE_UNKNOWN) {
818 records.push(recType);
819 records.push(lastLineNo);
820 records.push(record);
821 }
822 if (records.length >= 1) {
823 tests[testIndex] = records;
824 testLines[testIndex] = lines;
825 }
826}
827
828function init(test) {
829 var canvas = document.getElementById('canvas');
830 if (!canvas.getContext) return;
831 ctx = canvas.getContext('2d');
832 var resScale = retina_scale && window.devicePixelRatio ? window.devicePixelRatio : 1;
833 var unscaledWidth = window.innerWidth - 20;
834 var unscaledHeight = window.innerHeight - 20;
835 screenWidth = unscaledWidth;
836 screenHeight = unscaledHeight;
837 canvas.width = unscaledWidth * resScale;
838 canvas.height = unscaledHeight * resScale;
839 canvas.style.width = unscaledWidth + 'px';
840 canvas.style.height = unscaledHeight + 'px';
841 if (resScale != 1) {
842 ctx.scale(resScale, resScale);
843 }
844 xmin = Infinity;
845 xmax = -Infinity;
846 ymin = Infinity;
847 ymax = -Infinity;
caryclark26ad22a2015-10-16 09:03:38 -0700848 hasPath = hasAlignedPath = hasComputedPath = false;
caryclarkdac1d172014-06-17 05:15:38 -0700849 firstActiveSpan = -1;
850 for (var tIndex = 0; tIndex < test.length; tIndex += 3) {
851 var recType = test[tIndex];
852 if (!typeof recType == 'number' || recType < REC_TYPE_UNKNOWN || recType > REC_TYPE_LAST) {
853 console.log("unknown rec type: " + recType);
854 throw "stop execution";
855 }
856 var records = test[tIndex + 2];
857 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
858 var fragType = records[recordIndex];
859 if (!typeof fragType == 'number' || fragType < 1 || fragType > FRAG_TYPE_LAST) {
860 console.log("unknown in range frag type: " + fragType);
861 throw "stop execution";
862 }
863 var frags = records[recordIndex + 1];
864 var first = 0;
865 var last = -1;
866 var first2 = 0;
867 var last2 = 0;
868 switch (recType) {
caryclark26ad22a2015-10-16 09:03:38 -0700869 case REC_TYPE_ALIGNED:
870 hasAlignedPath = true;
caryclarkdac1d172014-06-17 05:15:38 -0700871 case REC_TYPE_COMPUTED:
872 if (fragType == COMPUTED_SET_1 || fragType == COMPUTED_SET_2) {
873 break;
874 }
caryclark26ad22a2015-10-16 09:03:38 -0700875 if (REC_TYPE_COMPUTED == recType) {
876 hasComputedPath = true;
877 }
caryclarkdac1d172014-06-17 05:15:38 -0700878 case REC_TYPE_PATH:
caryclark54359292015-03-26 07:52:43 -0700879 first = 1;
caryclarkdac1d172014-06-17 05:15:38 -0700880 switch (fragType) {
881 case PATH_LINE:
caryclark54359292015-03-26 07:52:43 -0700882 last = 5;
caryclarkdac1d172014-06-17 05:15:38 -0700883 break;
caryclark1049f122015-04-20 08:31:59 -0700884 case PATH_CONIC:
caryclarkdac1d172014-06-17 05:15:38 -0700885 case PATH_QUAD:
caryclark54359292015-03-26 07:52:43 -0700886 last = 7;
caryclarkdac1d172014-06-17 05:15:38 -0700887 break;
888 case PATH_CUBIC:
caryclark54359292015-03-26 07:52:43 -0700889 last = 9;
caryclarkdac1d172014-06-17 05:15:38 -0700890 break;
891 default:
caryclark55888e42016-07-18 10:01:36 -0700892 console.log("unknown " + (recType == REC_TYPE_PATH ? "REC_TYPE_PATH"
caryclarkdac1d172014-06-17 05:15:38 -0700893 : "REC_TYPE_COMPUTED") + " frag type:" + fragType);
894 throw "stop execution";
895 }
896 if (recType == REC_TYPE_PATH) {
897 hasPath = true;
898 }
899 break;
caryclark54359292015-03-26 07:52:43 -0700900 case REC_TYPE_PATH2:
901 first = 1;
902 switch (fragType) {
903 case PATH_LINE:
904 last = 5;
905 break;
caryclark1049f122015-04-20 08:31:59 -0700906 case PATH_CONIC:
caryclark54359292015-03-26 07:52:43 -0700907 case PATH_QUAD:
908 last = 7;
909 break;
910 case PATH_CUBIC:
911 last = 9;
912 break;
913 default:
caryclark55888e42016-07-18 10:01:36 -0700914 console.log("unknown " + (recType == REC_TYPE_PATH2 ? "REC_TYPE_PATH2"
caryclark54359292015-03-26 07:52:43 -0700915 : "REC_TYPE_COMPUTED") + " frag type:" + fragType);
916 throw "stop execution";
917 }
918 if (recType == REC_TYPE_PATH2) {
919 hasPath = true;
920 }
921 break;
caryclarkdac1d172014-06-17 05:15:38 -0700922 case REC_TYPE_ACTIVE:
923 if (firstActiveSpan < 0) {
924 firstActiveSpan = tIndex;
925 }
926 first = 1;
927 switch (fragType) {
928 case ACTIVE_LINE_SPAN:
929 last = 5;
930 break;
caryclark1049f122015-04-20 08:31:59 -0700931 case ACTIVE_CONIC_SPAN:
caryclarkdac1d172014-06-17 05:15:38 -0700932 case ACTIVE_QUAD_SPAN:
933 last = 7;
934 break;
935 case ACTIVE_CUBIC_SPAN:
936 last = 9;
937 break;
938 default:
939 console.log("unknown REC_TYPE_ACTIVE frag type: " + fragType);
940 throw "stop execution";
941 }
942 break;
943 case REC_TYPE_ADD:
944 switch (fragType) {
945 case ADD_MOVETO:
946 break;
947 case ADD_LINETO:
948 last = 4;
949 break;
caryclark1049f122015-04-20 08:31:59 -0700950 case ADD_CONICTO:
caryclarkdac1d172014-06-17 05:15:38 -0700951 case ADD_QUADTO:
952 last = 6;
953 break;
954 case ADD_CUBICTO:
955 last = 8;
956 break;
957 case ADD_CLOSE:
958 case ADD_FILL:
959 break;
960 default:
961 console.log("unknown REC_TYPE_ADD frag type: " + fragType);
962 throw "stop execution";
963 }
964 break;
caryclark54359292015-03-26 07:52:43 -0700965 case REC_TYPE_AFTERPART:
966 switch (fragType) {
967 case PATH_LINE:
968 last = 4;
969 break;
caryclark1049f122015-04-20 08:31:59 -0700970 case PATH_CONIC:
caryclark54359292015-03-26 07:52:43 -0700971 case PATH_QUAD:
972 last = 6;
973 break;
974 case PATH_CUBIC:
975 last = 8;
976 break;
977 default:
978 console.log("unknown REC_TYPE_ACTIVEPART frag type: " + fragType);
979 throw "stop execution";
980 }
981 break;
caryclarkdac1d172014-06-17 05:15:38 -0700982 case REC_TYPE_SECT:
983 switch (fragType) {
984 case INTERSECT_LINE:
985 first = 1; last = 5; first2 = 8; last2 = 12;
986 break;
987 case INTERSECT_LINE_2:
988 first = 1; last = 5; first2 = 11; last2 = 15;
989 break;
990 case INTERSECT_LINE_NO:
991 first = 0; last = 4; first2 = 4; last2 = 8;
992 break;
caryclark1049f122015-04-20 08:31:59 -0700993 case INTERSECT_CONIC_LINE:
994 first = 1; last = 7; first2 = 11; last2 = 15;
995 break;
caryclarkdac1d172014-06-17 05:15:38 -0700996 case INTERSECT_QUAD_LINE:
997 first = 1; last = 7; first2 = 10; last2 = 14;
998 break;
caryclark1049f122015-04-20 08:31:59 -0700999 case INTERSECT_CONIC_LINE_2:
1000 first = 1; last = 7; first2 = 14; last2 = 18;
1001 break;
caryclarkdac1d172014-06-17 05:15:38 -07001002 case INTERSECT_QUAD_LINE_2:
1003 first = 1; last = 7; first2 = 13; last2 = 17;
1004 break;
caryclark1049f122015-04-20 08:31:59 -07001005 case INTERSECT_CONIC_LINE_NO:
1006 first = 0; last = 6; first2 = 7; last2 = 11;
1007 break;
caryclarkdac1d172014-06-17 05:15:38 -07001008 case INTERSECT_QUAD_LINE_NO:
1009 first = 0; last = 6; first2 = 6; last2 = 10;
1010 break;
caryclark1049f122015-04-20 08:31:59 -07001011 case INTERSECT_CONIC:
1012 first = 1; last = 7; first2 = 11; last2 = 17;
1013 break;
caryclarkdac1d172014-06-17 05:15:38 -07001014 case INTERSECT_QUAD:
1015 first = 1; last = 7; first2 = 10; last2 = 16;
1016 break;
caryclark1049f122015-04-20 08:31:59 -07001017 case INTERSECT_CONIC_2:
1018 first = 1; last = 7; first2 = 14; last2 = 20;
1019 break;
caryclarkdac1d172014-06-17 05:15:38 -07001020 case INTERSECT_QUAD_2:
1021 first = 1; last = 7; first2 = 13; last2 = 19;
1022 break;
caryclark1049f122015-04-20 08:31:59 -07001023 case INTERSECT_CONIC_NO:
1024 first = 0; last = 6; first2 = 7; last2 = 13;
1025 break;
caryclarkdac1d172014-06-17 05:15:38 -07001026 case INTERSECT_QUAD_NO:
1027 first = 0; last = 6; first2 = 6; last2 = 12;
1028 break;
1029 case INTERSECT_SELF_CUBIC:
1030 first = 1; last = 9;
1031 break;
1032 case INTERSECT_SELF_CUBIC_NO:
1033 first = 0; last = 8;
1034 break;
1035 case INTERSECT_CUBIC_LINE:
1036 first = 1; last = 9; first2 = 12; last2 = 16;
1037 break;
1038 case INTERSECT_CUBIC_LINE_2:
1039 first = 1; last = 9; first2 = 15; last2 = 19;
1040 break;
1041 case INTERSECT_CUBIC_LINE_3:
1042 first = 1; last = 9; first2 = 18; last2 = 22;
1043 break;
1044 case INTERSECT_CUBIC_LINE_NO:
1045 first = 0; last = 8; first2 = 8; last2 = 12;
1046 break;
caryclark55888e42016-07-18 10:01:36 -07001047 case INTERSECT_CONIC_QUAD:
1048 first = 1; last = 7; first2 = 11; last2 = 17;
1049 break;
1050 case INTERSECT_CONIC_QUAD_2:
1051 first = 1; last = 7; first2 = 14; last2 = 20;
1052 break;
1053 case INTERSECT_CONIC_QUAD_NO:
1054 first = 0; last = 6; first2 = 7; last2 = 13;
1055 break;
caryclarkdac1d172014-06-17 05:15:38 -07001056 case INTERSECT_CUBIC_QUAD:
1057 first = 1; last = 9; first2 = 12; last2 = 18;
1058 break;
1059 case INTERSECT_CUBIC_QUAD_2:
1060 first = 1; last = 9; first2 = 15; last2 = 21;
1061 break;
1062 case INTERSECT_CUBIC_QUAD_3:
1063 first = 1; last = 9; first2 = 18; last2 = 24;
1064 break;
1065 case INTERSECT_CUBIC_QUAD_4:
1066 first = 1; last = 9; first2 = 21; last2 = 27;
1067 break;
1068 case INTERSECT_CUBIC_QUAD_NO:
1069 first = 0; last = 8; first2 = 8; last2 = 14;
1070 break;
1071 case INTERSECT_CUBIC:
1072 first = 1; last = 9; first2 = 12; last2 = 20;
1073 break;
1074 case INTERSECT_CUBIC_2:
1075 first = 1; last = 9; first2 = 15; last2 = 23;
1076 break;
1077 case INTERSECT_CUBIC_3:
1078 first = 1; last = 9; first2 = 18; last2 = 26;
1079 break;
1080 case INTERSECT_CUBIC_4:
1081 first = 1; last = 9; first2 = 21; last2 = 29;
1082 break;
1083 case INTERSECT_CUBIC_NO:
1084 first = 0; last = 8; first2 = 8; last2 = 16;
1085 break;
1086 default:
1087 console.log("unknown REC_TYPE_SECT frag type: " + fragType);
1088 throw "stop execution";
1089 }
1090 break;
1091 default:
1092 continue;
1093 }
1094 for (var idx = first; idx < last; idx += 2) {
1095 xmin = Math.min(xmin, frags[idx]);
1096 xmax = Math.max(xmax, frags[idx]);
1097 ymin = Math.min(ymin, frags[idx + 1]);
1098 ymax = Math.max(ymax, frags[idx + 1]);
1099 }
1100 for (var idx = first2; idx < last2; idx += 2) {
1101 xmin = Math.min(xmin, frags[idx]);
1102 xmax = Math.max(xmax, frags[idx]);
1103 ymin = Math.min(ymin, frags[idx + 1]);
1104 ymax = Math.max(ymax, frags[idx + 1]);
1105 }
1106 }
1107 }
1108 var angleBounds = [Infinity, Infinity, -Infinity, -Infinity];
1109 for (var tIndex = 0; tIndex < test.length; tIndex += 3) {
1110 var recType = test[tIndex];
1111 var records = test[tIndex + 2];
1112 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
1113 var fragType = records[recordIndex];
1114 var frags = records[recordIndex + 1];
1115 switch (recType) {
1116 case REC_TYPE_ACTIVE_OP:
1117 if (!draw_op) {
1118 break;
1119 }
1120 {
1121 var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
1122 curve_extremes(curve, angleBounds);
1123 }
1124 break;
1125 case REC_TYPE_ANGLE:
1126 if (!draw_angle) {
1127 break;
1128 }
caryclark54359292015-03-26 07:52:43 -07001129 {
caryclarkdac1d172014-06-17 05:15:38 -07001130 var curve = curvePartialByID(test, frags[0], frags[4], frags[5]);
1131 curve_extremes(curve, angleBounds);
1132 curve = curvePartialByID(test, frags[6], frags[10], frags[11]);
1133 curve_extremes(curve, angleBounds);
1134 curve = curvePartialByID(test, frags[12], frags[16], frags[17]);
1135 }
1136 break;
caryclark624637c2015-05-11 07:21:27 -07001137 case REC_TYPE_COINCIDENCE:
1138 if (!draw_coincidence) {
1139 break;
1140 }
1141 {
1142 var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
1143 curve_extremes(curve, angleBounds);
1144 }
1145 break;
caryclarkdac1d172014-06-17 05:15:38 -07001146 case REC_TYPE_SORT:
1147 if (!draw_sort) {
1148 break;
1149 }
1150 if (fragType == SORT_UNARY || fragType == SORT_BINARY) {
1151 var curve = curvePartialByID(test, frags[0], frags[6], frags[8]);
1152 curve_extremes(curve, angleBounds);
1153 }
1154 break;
caryclark03b03ca2015-04-23 09:13:37 -07001155 case REC_TYPE_TOP:
1156 if (!draw_top) {
1157 break;
1158 }
1159 {
1160 var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
1161 curve_extremes(curve, angleBounds);
1162 }
1163 break;
caryclarkdac1d172014-06-17 05:15:38 -07001164 }
1165 }
1166 }
1167 xmin = Math.min(xmin, angleBounds[0]);
1168 ymin = Math.min(ymin, angleBounds[1]);
1169 xmax = Math.max(xmax, angleBounds[2]);
1170 ymax = Math.max(ymax, angleBounds[3]);
1171 setScale(xmin, xmax, ymin, ymax);
1172 if (hasPath == false && hasComputedPath == true && !draw_computed) {
caryclark1049f122015-04-20 08:31:59 -07001173 draw_computed = 7; // show quadratics, conics, and cubics
caryclarkdac1d172014-06-17 05:15:38 -07001174 }
1175 if (hasPath == true && hasComputedPath == false && draw_computed) {
1176 draw_computed = 0;
1177 }
1178}
1179
caryclark26ad22a2015-10-16 09:03:38 -07001180function curveByIDMatch(test, id, recMatch) {
caryclark54359292015-03-26 07:52:43 -07001181 var tIndex = -3;
1182 while ((tIndex += 3) < test.length) {
caryclarkdac1d172014-06-17 05:15:38 -07001183 var recType = test[tIndex];
caryclark54359292015-03-26 07:52:43 -07001184 if (recType == REC_TYPE_OP) {
1185 continue;
1186 }
caryclark26ad22a2015-10-16 09:03:38 -07001187 if (recType != recMatch) {
caryclarkdac1d172014-06-17 05:15:38 -07001188 return [];
1189 }
1190 var records = test[tIndex + 2];
1191 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
1192 var fragType = records[recordIndex];
1193 var frags = records[recordIndex + 1];
1194 if (frags[0] == id) {
1195 switch (fragType) {
caryclark54359292015-03-26 07:52:43 -07001196 case PATH_LINE:
caryclarkdac1d172014-06-17 05:15:38 -07001197 return [frags[1], frags[2], frags[3], frags[4]];
caryclark54359292015-03-26 07:52:43 -07001198 case PATH_QUAD:
caryclarkdac1d172014-06-17 05:15:38 -07001199 return [frags[1], frags[2], frags[3], frags[4],
1200 frags[5], frags[6]];
caryclark1049f122015-04-20 08:31:59 -07001201 case PATH_CONIC:
1202 return [frags[1], frags[2], frags[3], frags[4],
1203 frags[5], frags[6], frags[7]];
caryclark54359292015-03-26 07:52:43 -07001204 case PATH_CUBIC:
caryclarkdac1d172014-06-17 05:15:38 -07001205 return [frags[1], frags[2], frags[3], frags[4],
1206 frags[5], frags[6], frags[7], frags[8]];
1207 }
1208 }
1209 }
caryclarkdac1d172014-06-17 05:15:38 -07001210 }
1211 return [];
1212}
1213
caryclark26ad22a2015-10-16 09:03:38 -07001214function curveByID(test, id) {
1215 var result = draw_path >= 4 ? curveByIDMatch(test, id, REC_TYPE_ALIGNED) : [];
1216 if (!result.length) {
1217 result = curveByIDMatch(test, id, REC_TYPE_PATH);
1218 }
1219 return result;
1220}
1221
1222function curvePartialByIDMatch(test, id, t0, t1, recMatch) {
caryclark54359292015-03-26 07:52:43 -07001223 var tIndex = -3;
1224 while ((tIndex += 3) < test.length) {
caryclarkdac1d172014-06-17 05:15:38 -07001225 var recType = test[tIndex];
caryclark54359292015-03-26 07:52:43 -07001226 if (recType == REC_TYPE_OP) {
1227 continue;
1228 }
caryclark26ad22a2015-10-16 09:03:38 -07001229 if (recType != recMatch) {
caryclarkdac1d172014-06-17 05:15:38 -07001230 return [];
1231 }
1232 var records = test[tIndex + 2];
1233 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
1234 var fragType = records[recordIndex];
1235 var frags = records[recordIndex + 1];
1236 if (frags[0] == id) {
1237 switch (fragType) {
caryclark54359292015-03-26 07:52:43 -07001238 case PATH_LINE:
caryclarkdac1d172014-06-17 05:15:38 -07001239 return linePartial(frags[1], frags[2], frags[3], frags[4], t0, t1);
caryclark54359292015-03-26 07:52:43 -07001240 case PATH_QUAD:
caryclarkdac1d172014-06-17 05:15:38 -07001241 return quadPartial(frags[1], frags[2], frags[3], frags[4],
1242 frags[5], frags[6], t0, t1);
caryclark1049f122015-04-20 08:31:59 -07001243 case PATH_CONIC:
1244 return conicPartial(frags[1], frags[2], frags[3], frags[4],
1245 frags[5], frags[6], frags[7], t0, t1);
caryclark54359292015-03-26 07:52:43 -07001246 case PATH_CUBIC:
caryclarkdac1d172014-06-17 05:15:38 -07001247 return cubicPartial(frags[1], frags[2], frags[3], frags[4],
1248 frags[5], frags[6], frags[7], frags[8], t0, t1);
1249 }
1250 }
1251 }
caryclarkdac1d172014-06-17 05:15:38 -07001252 }
1253 return [];
1254}
1255
caryclark26ad22a2015-10-16 09:03:38 -07001256function curvePartialByID(test, id, t0, t1) {
1257 var result = draw_path >= 4 ? curvePartialByIDMatch(test, id, t0, t1, REC_TYPE_ALIGNED) : [];
1258 if (!result.length) {
1259 result = curvePartialByIDMatch(test, id, t0, t1, REC_TYPE_PATH);
1260 }
1261 return result;
1262}
1263
1264function idByCurveIDMatch(test, frag, type, recMatch) {
caryclark54359292015-03-26 07:52:43 -07001265 var tIndex = 0;
caryclarkdac1d172014-06-17 05:15:38 -07001266 while (tIndex < test.length) {
1267 var recType = test[tIndex];
caryclark26ad22a2015-10-16 09:03:38 -07001268 if (recType != recMatch) {
caryclark54359292015-03-26 07:52:43 -07001269 ++tIndex;
1270 continue;
caryclarkdac1d172014-06-17 05:15:38 -07001271 }
1272 var records = test[tIndex + 2];
1273 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
1274 var fragType = records[recordIndex];
1275 var frags = records[recordIndex + 1];
caryclark54359292015-03-26 07:52:43 -07001276 if (frag.length != frags.length - 1) {
1277 continue;
1278 }
caryclarkdac1d172014-06-17 05:15:38 -07001279 switch (fragType) {
caryclark54359292015-03-26 07:52:43 -07001280 case PATH_LINE:
caryclarkdac1d172014-06-17 05:15:38 -07001281 if (frag[0] != frags[1] || frag[1] != frags[2]
1282 || frag[2] != frags[3] || frag[3] != frags[4]) {
1283 continue;
1284 }
1285 return frags[0];
caryclark54359292015-03-26 07:52:43 -07001286 case PATH_QUAD:
caryclarkdac1d172014-06-17 05:15:38 -07001287 if (frag[0] != frags[1] || frag[1] != frags[2]
1288 || frag[2] != frags[3] || frag[3] != frags[4]
1289 || frag[4] != frags[5] || frag[5] != frags[6]) {
1290 continue;
1291 }
1292 return frags[0];
caryclark1049f122015-04-20 08:31:59 -07001293 case PATH_CONIC:
1294 if (frag[0] != frags[1] || frag[1] != frags[2]
1295 || frag[2] != frags[3] || frag[3] != frags[4]
1296 || frag[4] != frags[5] || frag[5] != frags[6]
1297 || frag[6] != frags[7]) {
1298 continue;
1299 }
1300 return frags[0];
caryclark54359292015-03-26 07:52:43 -07001301 case PATH_CUBIC:
caryclarkdac1d172014-06-17 05:15:38 -07001302 if (frag[0] != frags[1] || frag[1] != frags[2]
1303 || frag[2] != frags[3] || frag[3] != frags[4]
1304 || frag[4] != frags[5] || frag[5] != frags[6]
1305 || frag[6] != frags[7] || frag[7] != frags[8]) {
1306 continue;
1307 }
1308 return frags[0];
1309 }
1310 }
1311 ++tIndex;
1312 }
1313 return -1;
1314}
1315
caryclark26ad22a2015-10-16 09:03:38 -07001316function idByCurve(test, frag, type) {
1317 var result = draw_path >= 4 ? idByCurveIDMatch(test, frag, type, REC_TYPE_ALIGNED) : [];
1318 if (!result.length) {
1319 result = idByCurveIDMatch(test, frag, type, REC_TYPE_PATH);
1320 }
1321 return result;
1322}
1323
caryclarkdac1d172014-06-17 05:15:38 -07001324function curve_extremes(curve, bounds) {
caryclark1049f122015-04-20 08:31:59 -07001325 var length = curve.length == 7 ? 6 : curve.length;
caryclarked0935a2015-10-22 07:23:52 -07001326 for (var index = 0; index < length; index += 2) {
caryclarkdac1d172014-06-17 05:15:38 -07001327 var x = curve[index];
1328 var y = curve[index + 1];
1329 bounds[0] = Math.min(bounds[0], x);
1330 bounds[1] = Math.min(bounds[1], y);
1331 bounds[2] = Math.max(bounds[2], x);
1332 bounds[3] = Math.max(bounds[3], y);
1333 }
1334}
1335
1336function setScale(x0, x1, y0, y1) {
1337 var srcWidth = x1 - x0;
1338 var srcHeight = y1 - y0;
1339 var usableWidth = screenWidth;
1340 var xDigits = Math.ceil(Math.log(Math.abs(xmax)) / Math.log(10));
1341 var yDigits = Math.ceil(Math.log(Math.abs(ymax)) / Math.log(10));
1342 usableWidth -= (xDigits + yDigits) * 10;
1343 usableWidth -= decimal_places * 10;
1344 if (draw_legend) {
1345 usableWidth -= 40;
1346 }
1347 var hscale = usableWidth / srcWidth;
1348 var vscale = screenHeight / srcHeight;
1349 scale = Math.min(hscale, vscale);
1350 var invScale = 1 / scale;
1351 var sxmin = x0 - invScale * 5;
1352 var symin = y0 - invScale * 10;
1353 var sxmax = x1 + invScale * (6 * decimal_places + 10);
1354 var symax = y1 + invScale * 10;
1355 srcWidth = sxmax - sxmin;
1356 srcHeight = symax - symin;
1357 hscale = usableWidth / srcWidth;
1358 vscale = screenHeight / srcHeight;
1359 scale = Math.min(hscale, vscale);
1360 srcLeft = sxmin;
1361 srcTop = symin;
1362}
1363
1364function drawArc(curve, op, from, to) {
1365 var type = PATH_LINE + (curve.length / 2 - 2);
1366 var pt = pointAtT(curve, type, op ? 0.4 : 0.6);
1367 var dy = pt.y - curve[1];
1368 var dx = pt.x - curve[0];
1369 var dist = Math.sqrt(dy * dy + dx * dx);
1370 var _dist = dist * scale;
1371 var angle = Math.atan2(dy, dx);
1372 var _px = (curve[0] - srcLeft) * scale;
1373 var _py = (curve[1] - srcTop) * scale;
1374 var divisor = 4;
1375 var endDist;
1376 do {
1377 var ends = [];
1378 for (var index = -1; index <= 1; index += 2) {
1379 var px = Math.cos(index * Math.PI / divisor);
1380 var py = Math.sin(index * Math.PI / divisor);
1381 ends.push(px);
1382 ends.push(py);
1383 }
1384 var endDx = (ends[2] - ends[0]) * scale * dist;
1385 var endDy = (ends[3] - ends[1]) * scale * dist;
1386 endDist = Math.sqrt(endDx * endDx + endDy * endDy);
1387 if (endDist < 100) {
1388 break;
1389 }
1390 divisor *= 2;
1391 } while (true);
1392 if (endDist < 30) {
1393 return;
1394 }
1395 if (op) {
1396 divisor *= 2;
1397 }
1398 ctx.strokeStyle = op ? "rgba(210,0,45, 0.4)" : "rgba(90,90,90, 0.5)";
1399 ctx.beginPath();
1400 ctx.arc(_px, _py, _dist, angle - Math.PI / divisor, angle + Math.PI / divisor, false);
1401 ctx.stroke();
1402 var saveAlign = ctx.textAlign;
1403 var saveStyle = ctx.fillStyle;
1404 var saveFont = ctx.font;
1405 ctx.textAlign = "center";
1406 ctx.fillStyle = "black";
1407 ctx.font = "normal 24px Arial";
1408 divisor *= 0.8;
1409 for (var index = -1; index <= 1; index += 2) {
1410 var px = curve[0] + Math.cos(angle + index * Math.PI / divisor) * dist;
1411 var py = curve[1] + Math.sin(angle + index * Math.PI / divisor) * dist;
1412 var _px = (px - srcLeft) * scale;
1413 var _py = (py - srcTop) * scale;
1414 ctx.fillText(index < 0 ? to.toString() : from.toString(), _px, _py + 8);
1415 }
1416 ctx.textAlign = saveAlign;
1417 ctx.fillStyle = saveStyle;
1418 ctx.font = saveFont;
1419}
1420
1421function drawPoint(px, py, end) {
caryclark1049f122015-04-20 08:31:59 -07001422 var length = drawnPts.length == 7 ? 6 : drawnPts.length;
1423 for (var pts = 0; pts < length; pts += 2) {
caryclarkdac1d172014-06-17 05:15:38 -07001424 var x = drawnPts[pts];
1425 var y = drawnPts[pts + 1];
1426 if (px == x && py == y) {
1427 return;
1428 }
1429 }
1430 drawnPts.push(px);
1431 drawnPts.push(py);
1432 var label = px.toFixed(decimal_places) + ", " + py.toFixed(decimal_places);
1433 var _px = (px - srcLeft) * scale;
1434 var _py = (py - srcTop) * scale;
1435 ctx.beginPath();
1436 ctx.arc(_px, _py, 3, 0, Math.PI*2, true);
1437 ctx.closePath();
1438 if (end) {
1439 ctx.fill();
1440 } else {
1441 ctx.stroke();
1442 }
1443 if (debug_xy) {
1444 ctx.textAlign = "left";
1445 ctx.fillText(label, _px + 5, _py);
1446 }
1447}
1448
caryclark1049f122015-04-20 08:31:59 -07001449function coordCount(curveType) {
1450 switch (curveType) {
1451 case PATH_LINE:
1452 return 4;
1453 case PATH_QUAD:
1454 return 6;
1455 case PATH_CONIC:
1456 return 6;
1457 case PATH_CUBIC:
1458 return 8;
1459 }
1460 return -1;
1461}
1462
caryclarkdac1d172014-06-17 05:15:38 -07001463function drawPoints(ptArray, curveType, drawControls) {
caryclark1049f122015-04-20 08:31:59 -07001464 var count = coordCount(curveType);
caryclarkdac1d172014-06-17 05:15:38 -07001465 for (var idx = 0; idx < count; idx += 2) {
1466 if (!drawControls && idx != 0 && idx != count - 2) {
1467 continue;
1468 }
1469 drawPoint(ptArray[idx], ptArray[idx + 1], idx == 0 || idx == count - 2);
1470 }
1471}
1472
1473function drawControlLines(curve, curveType, drawEnd) {
1474 if (curveType == PATH_LINE) {
1475 return;
1476 }
1477 ctx.strokeStyle = "rgba(0,0,0, 0.3)";
1478 drawLine(curve[0], curve[1], curve[2], curve[3]);
1479 drawLine(curve[2], curve[3], curve[4], curve[5]);
1480 if (curveType == PATH_CUBIC) {
1481 drawLine(curve[4], curve[5], curve[6], curve[7]);
1482 if (drawEnd > 1) {
1483 drawLine(curve[6], curve[7], curve[0], curve[1]);
1484 if (drawEnd > 2) {
1485 drawLine(curve[0], curve[1], curve[4], curve[5]);
1486 drawLine(curve[6], curve[7], curve[2], curve[3]);
1487 }
1488 }
1489 } else if (drawEnd > 1) {
1490 drawLine(curve[4], curve[5], curve[0], curve[1]);
1491 }
1492}
1493
1494function pointAtT(curve, curveType, t) {
1495 var xy = {};
1496 switch (curveType) {
1497 case PATH_LINE:
1498 var a = 1 - t;
1499 var b = t;
1500 xy.x = a * curve[0] + b * curve[2];
1501 xy.y = a * curve[1] + b * curve[3];
1502 break;
1503 case PATH_QUAD:
1504 var one_t = 1 - t;
1505 var a = one_t * one_t;
1506 var b = 2 * one_t * t;
1507 var c = t * t;
1508 xy.x = a * curve[0] + b * curve[2] + c * curve[4];
1509 xy.y = a * curve[1] + b * curve[3] + c * curve[5];
1510 break;
caryclark1049f122015-04-20 08:31:59 -07001511 case PATH_CONIC:
1512 var one_t = 1 - t;
1513 var a = one_t * one_t;
1514 var b = 2 * one_t * t;
1515 var c = t * t;
1516 xy.x = a * curve[0] + b * curve[2] * curve[6] + c * curve[4];
1517 xy.y = a * curve[1] + b * curve[3] * curve[6] + c * curve[5];
1518 var d = a + b * curve[6] + c;
1519 xy.x /= d;
1520 xy.y /= d;
1521 break;
caryclarkdac1d172014-06-17 05:15:38 -07001522 case PATH_CUBIC:
1523 var one_t = 1 - t;
1524 var one_t2 = one_t * one_t;
1525 var a = one_t2 * one_t;
1526 var b = 3 * one_t2 * t;
1527 var t2 = t * t;
1528 var c = 3 * one_t * t2;
1529 var d = t2 * t;
1530 xy.x = a * curve[0] + b * curve[2] + c * curve[4] + d * curve[6];
1531 xy.y = a * curve[1] + b * curve[3] + c * curve[5] + d * curve[7];
1532 break;
1533 }
1534 return xy;
1535}
caryclark55888e42016-07-18 10:01:36 -07001536
caryclarkdac1d172014-06-17 05:15:38 -07001537function drawPointAtT(curve, curveType) {
1538 var x, y;
1539 var xy = pointAtT(curve, curveType, curveT);
1540 drawPoint(xy.x, xy.y, true);
1541 if (!draw_intersectT) {
1542 return;
1543 }
1544 ctx.fillStyle = "red";
1545 drawTAtPointUp(xy.x, xy.y, curveT);
1546}
1547
1548function drawTAtPointUp(px, py, t) {
1549 var label = t.toFixed(decimal_places);
1550 var _px = (px - srcLeft)* scale;
1551 var _py = (py - srcTop) * scale;
1552 ctx.fillText(label, _px + 5, _py - 10);
1553}
1554
1555function drawTAtPointDown(px, py, t) {
1556 var label = t.toFixed(decimal_places);
1557 var _px = (px - srcLeft)* scale;
1558 var _py = (py - srcTop) * scale;
1559 ctx.fillText(label, _px + 5, _py + 10);
1560}
1561
1562function alreadyDrawnLine(x1, y1, x2, y2) {
1563 if (collect_bounds) {
1564 if (focus_enabled) {
1565 focusXmin = Math.min(focusXmin, x1, x2);
1566 focusYmin = Math.min(focusYmin, y1, y2);
1567 focusXmax = Math.max(focusXmax, x1, x2);
1568 focusYmax = Math.max(focusYmax, y1, y2);
1569 }
1570 return true;
1571 }
1572 for (var pts = 0; pts < drawnLines.length; pts += 4) {
1573 if (x1 == drawnLines[pts] && y1 == drawnLines[pts + 1]
1574 && x2 == drawnLines[pts + 2] && y2 == drawnLines[pts + 3]) {
1575 return true;
1576 }
1577 }
1578 drawnLines.push(x1);
1579 drawnLines.push(y1);
1580 drawnLines.push(x2);
1581 drawnLines.push(y2);
1582 return false;
1583}
1584
1585function drawLine(x1, y1, x2, y2) {
1586 if (alreadyDrawnLine(x1, y1, x2, y2)) {
1587 return;
1588 }
1589 ctx.beginPath();
1590 ctx.moveTo((x1 - srcLeft) * scale,
1591 (y1 - srcTop) * scale);
1592 ctx.lineTo((x2 - srcLeft) * scale,
1593 (y2 - srcTop) * scale);
1594 ctx.stroke();
1595}
1596
1597function linePartial(x1, y1, x2, y2, t1, t2) {
1598 var dx = x1 - x2;
1599 var dy = y1 - y2;
1600 var array = [
1601 x1 - t1 * dx,
1602 y1 - t1 * dy,
1603 x1 - t2 * dx,
1604 y1 - t2 * dy
1605 ];
1606 return array;
1607}
1608
1609function drawLinePartial(x1, y1, x2, y2, t1, t2) {
1610 var a = linePartial(x1, y1, x2, y2, t1, t2);
1611 var ax = a[0];
1612 var ay = a[1];
1613 var bx = a[2];
1614 var by = a[3];
1615 if (alreadyDrawnLine(ax, ay, bx, by)) {
1616 return;
1617 }
1618 ctx.beginPath();
1619 ctx.moveTo((ax - srcLeft) * scale,
1620 (ay - srcTop) * scale);
1621 ctx.lineTo((bx - srcLeft) * scale,
1622 (by - srcTop) * scale);
1623 ctx.stroke();
1624}
1625
1626function alreadyDrawnQuad(x1, y1, x2, y2, x3, y3) {
1627 if (collect_bounds) {
1628 if (focus_enabled) {
1629 focusXmin = Math.min(focusXmin, x1, x2, x3);
1630 focusYmin = Math.min(focusYmin, y1, y2, y3);
1631 focusXmax = Math.max(focusXmax, x1, x2, x3);
1632 focusYmax = Math.max(focusYmax, y1, y2, y3);
1633 }
1634 return true;
1635 }
1636 for (var pts = 0; pts < drawnQuads.length; pts += 6) {
1637 if (x1 == drawnQuads[pts] && y1 == drawnQuads[pts + 1]
1638 && x2 == drawnQuads[pts + 2] && y2 == drawnQuads[pts + 3]
1639 && x3 == drawnQuads[pts + 4] && y3 == drawnQuads[pts + 5]) {
1640 return true;
1641 }
1642 }
1643 drawnQuads.push(x1);
1644 drawnQuads.push(y1);
1645 drawnQuads.push(x2);
1646 drawnQuads.push(y2);
1647 drawnQuads.push(x3);
1648 drawnQuads.push(y3);
1649 return false;
1650}
1651
1652function drawQuad(x1, y1, x2, y2, x3, y3) {
1653 if (alreadyDrawnQuad(x1, y1, x2, y2, x3, y3)) {
1654 return;
1655 }
1656 ctx.beginPath();
1657 ctx.moveTo((x1 - srcLeft) * scale,
1658 (y1 - srcTop) * scale);
1659 ctx.quadraticCurveTo((x2 - srcLeft) * scale,
1660 (y2 - srcTop) * scale,
1661 (x3 - srcLeft) * scale,
1662 (y3 - srcTop) * scale);
1663 ctx.stroke();
1664}
1665
1666function interp(A, B, t) {
1667 return A + (B - A) * t;
1668}
1669
1670function interp_quad_coords(x1, x2, x3, t)
1671{
1672 var ab = interp(x1, x2, t);
1673 var bc = interp(x2, x3, t);
1674 var abc = interp(ab, bc, t);
1675 return abc;
1676}
1677
1678function quadPartial(x1, y1, x2, y2, x3, y3, t1, t2) {
1679 var ax = interp_quad_coords(x1, x2, x3, t1);
1680 var ay = interp_quad_coords(y1, y2, y3, t1);
1681 var dx = interp_quad_coords(x1, x2, x3, (t1 + t2) / 2);
1682 var dy = interp_quad_coords(y1, y2, y3, (t1 + t2) / 2);
1683 var cx = interp_quad_coords(x1, x2, x3, t2);
1684 var cy = interp_quad_coords(y1, y2, y3, t2);
1685 var bx = 2*dx - (ax + cx)/2;
1686 var by = 2*dy - (ay + cy)/2;
1687 var array = [
1688 ax, ay, bx, by, cx, cy
1689 ];
1690 return array;
1691}
1692
1693function drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2) {
1694 var a = quadPartial(x1, y1, x2, y2, x3, y3, t1, t2);
1695 var ax = a[0];
1696 var ay = a[1];
1697 var bx = a[2];
1698 var by = a[3];
1699 var cx = a[4];
1700 var cy = a[5];
1701 if (alreadyDrawnQuad(ax, ay, bx, by, cx, cy)) {
1702 return;
1703 }
1704 ctx.beginPath();
1705 ctx.moveTo((ax - srcLeft) * scale,
1706 (ay - srcTop) * scale);
1707 ctx.quadraticCurveTo((bx - srcLeft) * scale,
1708 (by - srcTop) * scale,
1709 (cx - srcLeft) * scale,
1710 (cy - srcTop) * scale);
1711 ctx.stroke();
1712}
1713
caryclark1049f122015-04-20 08:31:59 -07001714function alreadyDrawnConic(x1, y1, x2, y2, x3, y3, w) {
1715 if (collect_bounds) {
1716 if (focus_enabled) {
1717 focusXmin = Math.min(focusXmin, x1, x2, x3);
1718 focusYmin = Math.min(focusYmin, y1, y2, y3);
1719 focusXmax = Math.max(focusXmax, x1, x2, x3);
1720 focusYmax = Math.max(focusYmax, y1, y2, y3);
1721 }
1722 return true;
1723 }
1724 for (var pts = 0; pts < drawnConics.length; pts += 8) {
1725 if (x1 == drawnConics[pts] && y1 == drawnCubics[pts + 1]
caryclark55888e42016-07-18 10:01:36 -07001726 && x2 == drawnCubics[pts + 2] && y2 == drawnCubics[pts + 3]
1727 && x3 == drawnCubics[pts + 4] && y3 == drawnCubics[pts + 5]
caryclark1049f122015-04-20 08:31:59 -07001728 && w == drawnCubics[pts + 6]) {
1729 return true;
1730 }
1731 }
1732 drawnConics.push(x1);
1733 drawnConics.push(y1);
1734 drawnConics.push(x2);
1735 drawnConics.push(y2);
1736 drawnConics.push(x3);
1737 drawnConics.push(y3);
1738 drawnCubics.push(w);
1739 return false;
1740}
1741
1742var kMaxConicToQuadPOW2 = 5;
1743
1744function computeQuadPOW2(curve, tol) {
1745 var a = curve[6] - 1;
1746 var k = a / (4 * (2 + a));
1747 var x = k * (curve[0] - 2 * curve[2] + curve[4]);
1748 var y = k * (curve[1] - 2 * curve[3] + curve[5]);
1749
1750 var error = Math.sqrt(x * x + y * y);
1751 var pow2;
1752 for (pow2 = 0; pow2 < kMaxConicToQuadPOW2; ++pow2) {
1753 if (error <= tol) {
1754 break;
1755 }
1756 error *= 0.25;
1757 }
1758 return pow2;
1759}
1760
1761function subdivide_w_value(w) {
1762 return Math.sqrt(0.5 + w * 0.5);
1763}
1764
1765function chop(curve, part1, part2) {
1766 var w = curve[6];
1767 var scale = 1 / (1 + w);
1768 part1[0] = curve[0];
1769 part1[1] = curve[1];
1770 part1[2] = (curve[0] + curve[2] * w) * scale;
1771 part1[3] = (curve[1] + curve[3] * w) * scale;
1772 part1[4] = part2[0] = (curve[0] + (curve[2] * w) * 2 + curve[4]) * scale * 0.5;
1773 part1[5] = part2[1] = (curve[1] + (curve[3] * w) * 2 + curve[5]) * scale * 0.5;
1774 part2[2] = (curve[2] * w + curve[4]) * scale;
1775 part2[3] = (curve[3] * w + curve[5]) * scale;
1776 part2[4] = curve[4];
1777 part2[5] = curve[5];
1778 part1[6] = part2[6] = subdivide_w_value(w);
1779}
1780
1781function subdivide(curve, level, pts) {
1782 if (0 == level) {
1783 pts.push(curve[2]);
1784 pts.push(curve[3]);
1785 pts.push(curve[4]);
1786 pts.push(curve[5]);
1787 } else {
1788 var part1 = [], part2 = [];
1789 chop(curve, part1, part2);
1790 --level;
1791 subdivide(part1, level, pts);
1792 subdivide(part2, level, pts);
1793 }
1794}
1795
1796function chopIntoQuadsPOW2(curve, pow2, pts) {
1797 subdivide(curve, pow2, pts);
1798 return 1 << pow2;
1799}
1800
1801function drawConicWithQuads(x1, y1, x2, y2, x3, y3, w) {
1802 if (alreadyDrawnConic(x1, y1, x2, y2, x3, y3, w)) {
1803 return;
1804 }
1805 ctx.beginPath();
1806 ctx.moveTo((x1 - srcLeft) * scale,
1807 (y1 - srcTop) * scale);
1808 var tol = 1 / scale;
1809 var curve = [x1, y1, x2, y2, x3, y3, w];
1810 var pow2 = computeQuadPOW2(curve, tol);
1811 var pts = [];
1812 chopIntoQuadsPOW2(curve, pow2, pts);
1813 for (var i = 0; i < pts.length; i += 4) {
1814 ctx.quadraticCurveTo(
1815 (pts[i + 0] - srcLeft) * scale, (pts[i + 1] - srcTop) * scale,
1816 (pts[i + 2] - srcLeft) * scale, (pts[i + 3] - srcTop) * scale);
1817 }
1818 ctx.stroke();
1819}
1820
1821function conic_eval_numerator(x1, x2, x3, w, t) {
1822 var src2w = x2 * w;
1823 var C = x1;
1824 var A = x3 - 2 * src2w + C;
1825 var B = 2 * (src2w - C);
1826 return (A * t + B) * t + C;
1827}
1828
1829
1830function conic_eval_denominator(w, t) {
1831 var B = 2 * (w - 1);
1832 var C = 1;
1833 var A = -B;
1834 return (A * t + B) * t + C;
1835}
1836
1837function conicPartial(x1, y1, x2, y2, x3, y3, w, t1, t2) {
1838 var ax = conic_eval_numerator(x1, x2, x3, w, t1);
1839 var ay = conic_eval_numerator(y1, y2, y3, w, t1);
1840 var az = conic_eval_denominator(w, t1);
1841 var midT = (t1 + t2) / 2;
1842 var dx = conic_eval_numerator(x1, x2, x3, w, midT);
1843 var dy = conic_eval_numerator(y1, y2, y3, w, midT);
1844 var dz = conic_eval_denominator(w, midT);
1845 var cx = conic_eval_numerator(x1, x2, x3, w, t2);
1846 var cy = conic_eval_numerator(y1, y2, y3, w, t2);
1847 var cz = conic_eval_denominator(w, t2);
1848 var bx = 2 * dx - (ax + cx) / 2;
1849 var by = 2 * dy - (ay + cy) / 2;
1850 var bz = 2 * dz - (az + cz) / 2;
1851 var dt = t2 - t1;
1852 var dt_1 = 1 - dt;
caryclark1049f122015-04-20 08:31:59 -07001853 var array = [
caryclarked0935a2015-10-22 07:23:52 -07001854 ax / az, ay / az, bx / bz, by / bz, cx / cz, cy / cz, 0
caryclark1049f122015-04-20 08:31:59 -07001855 ];
caryclarked0935a2015-10-22 07:23:52 -07001856 var dMidAC = { x:(array[0] + array[4]) / 2, y:(array[1] + array[5]) / 2 };
1857 var dMid = { x:dx / dz, y:dy / dz };
1858 var dWNumer = { x:dMidAC.x - dMid.x, y:dMidAC.y - dMid.y };
1859 var dWDenom = { x:dMid.x - array[2], y:dMid.y - array[3] };
1860 var partW = Math.sqrt(dWNumer.x * dWNumer.x + dWNumer.y * dWNumer.y)
1861 / Math.sqrt(dWDenom.x * dWDenom.x + dWDenom.y * dWDenom.y);
1862 array[6] = partW;
caryclark1049f122015-04-20 08:31:59 -07001863 return array;
1864}
caryclark55888e42016-07-18 10:01:36 -07001865
caryclark1049f122015-04-20 08:31:59 -07001866function drawConicPartial(x1, y1, x2, y2, x3, y3, w, t1, t2) {
1867 var a = conicPartial(x1, y1, x2, y2, x3, y3, w, t1, t2);
1868 var ax = a[0];
1869 var ay = a[1];
1870 var bx = a[2];
1871 var by = a[3];
1872 var cx = a[4];
1873 var cy = a[5];
1874 var w_ = a[6];
1875 drawConicWithQuads(ax, ay, bx, by, cx, cy, w_);
1876}
1877
caryclarkdac1d172014-06-17 05:15:38 -07001878function alreadyDrawnCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
1879 if (collect_bounds) {
1880 if (focus_enabled) {
1881 focusXmin = Math.min(focusXmin, x1, x2, x3, x4);
1882 focusYmin = Math.min(focusYmin, y1, y2, y3, y4);
1883 focusXmax = Math.max(focusXmax, x1, x2, x3, x4);
1884 focusYmax = Math.max(focusYmax, y1, y2, y3, y4);
1885 }
1886 return true;
1887 }
1888 for (var pts = 0; pts < drawnCubics.length; pts += 8) {
1889 if (x1 == drawnCubics[pts] && y1 == drawnCubics[pts + 1]
caryclark55888e42016-07-18 10:01:36 -07001890 && x2 == drawnCubics[pts + 2] && y2 == drawnCubics[pts + 3]
1891 && x3 == drawnCubics[pts + 4] && y3 == drawnCubics[pts + 5]
caryclarkdac1d172014-06-17 05:15:38 -07001892 && x4 == drawnCubics[pts + 6] && y4 == drawnCubics[pts + 7]) {
1893 return true;
1894 }
1895 }
1896 drawnCubics.push(x1);
1897 drawnCubics.push(y1);
1898 drawnCubics.push(x2);
1899 drawnCubics.push(y2);
1900 drawnCubics.push(x3);
1901 drawnCubics.push(y3);
1902 drawnCubics.push(x4);
1903 drawnCubics.push(y4);
1904 return false;
1905}
1906
1907function drawCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
1908 if (alreadyDrawnCubic(x1, y1, x2, y2, x3, y3, x4, y4)) {
1909 return;
1910 }
1911 ctx.beginPath();
1912 ctx.moveTo((x1 - srcLeft) * scale,
1913 (y1 - srcTop) * scale);
1914 ctx.bezierCurveTo((x2 - srcLeft) * scale,
1915 (y2 - srcTop) * scale,
1916 (x3 - srcLeft) * scale,
1917 (y3 - srcTop) * scale,
1918 (x4 - srcLeft) * scale,
1919 (y4 - srcTop) * scale);
1920 ctx.stroke();
1921}
1922
1923function interp_cubic_coords(x1, x2, x3, x4, t)
1924{
1925 var ab = interp(x1, x2, t);
1926 var bc = interp(x2, x3, t);
1927 var cd = interp(x3, x4, t);
1928 var abc = interp(ab, bc, t);
1929 var bcd = interp(bc, cd, t);
1930 var abcd = interp(abc, bcd, t);
1931 return abcd;
1932}
1933
1934function cubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2) {
1935 var ax = interp_cubic_coords(x1, x2, x3, x4, t1);
1936 var ay = interp_cubic_coords(y1, y2, y3, y4, t1);
1937 var ex = interp_cubic_coords(x1, x2, x3, x4, (t1*2+t2)/3);
1938 var ey = interp_cubic_coords(y1, y2, y3, y4, (t1*2+t2)/3);
1939 var fx = interp_cubic_coords(x1, x2, x3, x4, (t1+t2*2)/3);
1940 var fy = interp_cubic_coords(y1, y2, y3, y4, (t1+t2*2)/3);
1941 var dx = interp_cubic_coords(x1, x2, x3, x4, t2);
1942 var dy = interp_cubic_coords(y1, y2, y3, y4, t2);
1943 var mx = ex * 27 - ax * 8 - dx;
1944 var my = ey * 27 - ay * 8 - dy;
1945 var nx = fx * 27 - ax - dx * 8;
1946 var ny = fy * 27 - ay - dy * 8;
1947 var bx = (mx * 2 - nx) / 18;
1948 var by = (my * 2 - ny) / 18;
1949 var cx = (nx * 2 - mx) / 18;
1950 var cy = (ny * 2 - my) / 18;
1951 var array = [
1952 ax, ay, bx, by, cx, cy, dx, dy
1953 ];
1954 return array;
1955}
caryclark55888e42016-07-18 10:01:36 -07001956
caryclarkdac1d172014-06-17 05:15:38 -07001957function drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2) {
1958 var a = cubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2);
1959 var ax = a[0];
1960 var ay = a[1];
1961 var bx = a[2];
1962 var by = a[3];
1963 var cx = a[4];
1964 var cy = a[5];
1965 var dx = a[6];
1966 var dy = a[7];
1967 if (alreadyDrawnCubic(ax, ay, bx, by, cx, cy, dx, dy)) {
1968 return;
1969 }
1970 ctx.beginPath();
1971 ctx.moveTo((ax - srcLeft) * scale,
1972 (ay - srcTop) * scale);
1973 ctx.bezierCurveTo((bx - srcLeft) * scale,
1974 (by - srcTop) * scale,
1975 (cx - srcLeft) * scale,
1976 (cy - srcTop) * scale,
1977 (dx - srcLeft) * scale,
1978 (dy - srcTop) * scale);
1979 ctx.stroke();
1980}
1981
1982function drawCurve(c) {
1983 switch (c.length) {
1984 case 4:
1985 drawLine(c[0], c[1], c[2], c[3]);
1986 break;
1987 case 6:
1988 drawQuad(c[0], c[1], c[2], c[3], c[4], c[5]);
1989 break;
caryclark1049f122015-04-20 08:31:59 -07001990 case 7:
1991 drawConicWithQuads(c[0], c[1], c[2], c[3], c[4], c[5], c[6]);
1992 break;
caryclarkdac1d172014-06-17 05:15:38 -07001993 case 8:
1994 drawCubic(c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
1995 break;
1996 }
1997}
1998
1999function boundsWidth(pts) {
2000 var min = pts[0];
2001 var max = pts[0];
caryclark1049f122015-04-20 08:31:59 -07002002 var length = pts.length == 7 ? 6 : pts.length;
2003 for (var idx = 2; idx < length; idx += 2) {
caryclarkdac1d172014-06-17 05:15:38 -07002004 min = Math.min(min, pts[idx]);
2005 max = Math.max(max, pts[idx]);
2006 }
2007 return max - min;
2008}
2009
2010function boundsHeight(pts) {
2011 var min = pts[1];
2012 var max = pts[1];
caryclark1049f122015-04-20 08:31:59 -07002013 var length = pts.length == 7 ? 6 : pts.length;
2014 for (var idx = 3; idx < length; idx += 2) {
caryclarkdac1d172014-06-17 05:15:38 -07002015 min = Math.min(min, pts[idx]);
2016 max = Math.max(max, pts[idx]);
2017 }
2018 return max - min;
2019}
2020
2021function tangent(pts) {
2022 var dx = pts[2] - pts[0];
2023 var dy = pts[3] - pts[1];
2024 if (dx == 0 && dy == 0 && pts.length > 4) {
2025 dx = pts[4] - pts[0];
2026 dy = pts[5] - pts[1];
caryclark1049f122015-04-20 08:31:59 -07002027 if (dx == 0 && dy == 0 && pts.length == 8) {
caryclarkdac1d172014-06-17 05:15:38 -07002028 dx = pts[6] - pts[0];
2029 dy = pts[7] - pts[1];
2030 }
2031 }
2032 return Math.atan2(-dy, dx);
2033}
2034
2035function hodograph(cubic) {
2036 var hodo = [];
2037 hodo[0] = 3 * (cubic[2] - cubic[0]);
2038 hodo[1] = 3 * (cubic[3] - cubic[1]);
2039 hodo[2] = 3 * (cubic[4] - cubic[2]);
2040 hodo[3] = 3 * (cubic[5] - cubic[3]);
2041 hodo[4] = 3 * (cubic[6] - cubic[4]);
2042 hodo[5] = 3 * (cubic[7] - cubic[5]);
2043 return hodo;
2044}
2045
2046function hodograph2(cubic) {
2047 var quad = hodograph(cubic);
2048 var hodo = [];
2049 hodo[0] = 2 * (quad[2] - quad[0]);
2050 hodo[1] = 2 * (quad[3] - quad[1]);
2051 hodo[2] = 2 * (quad[4] - quad[2]);
2052 hodo[3] = 2 * (quad[5] - quad[3]);
2053 return hodo;
2054}
2055
2056function quadraticRootsReal(A, B, C, s) {
2057 if (A == 0) {
2058 if (B == 0) {
2059 s[0] = 0;
2060 return C == 0;
2061 }
2062 s[0] = -C / B;
2063 return 1;
2064 }
2065 /* normal form: x^2 + px + q = 0 */
2066 var p = B / (2 * A);
2067 var q = C / A;
2068 var p2 = p * p;
2069 if (p2 < q) {
2070 return 0;
2071 }
2072 var sqrt_D = 0;
2073 if (p2 > q) {
2074 sqrt_D = sqrt(p2 - q);
2075 }
2076 s[0] = sqrt_D - p;
2077 s[1] = -sqrt_D - p;
2078 return 1 + s[0] != s[1];
2079}
2080
2081function add_valid_ts(s, realRoots, t) {
2082 var foundRoots = 0;
2083 for (var index = 0; index < realRoots; ++index) {
2084 var tValue = s[index];
2085 if (tValue >= 0 && tValue <= 1) {
2086 for (var idx2 = 0; idx2 < foundRoots; ++idx2) {
2087 if (t[idx2] != tValue) {
2088 t[foundRoots++] = tValue;
2089 }
2090 }
2091 }
2092 }
2093 return foundRoots;
2094}
2095
2096function quadraticRootsValidT(a, b, c, t) {
2097 var s = [];
2098 var realRoots = quadraticRootsReal(A, B, C, s);
2099 var foundRoots = add_valid_ts(s, realRoots, t);
2100 return foundRoots != 0;
2101}
2102
2103function find_cubic_inflections(cubic, tValues) {
2104 var Ax = src[2] - src[0];
2105 var Ay = src[3] - src[1];
2106 var Bx = src[4] - 2 * src[2] + src[0];
2107 var By = src[5] - 2 * src[3] + src[1];
2108 var Cx = src[6] + 3 * (src[2] - src[4]) - src[0];
2109 var Cy = src[7] + 3 * (src[3] - src[5]) - src[1];
2110 return quadraticRootsValidT(Bx * Cy - By * Cx, (Ax * Cy - Ay * Cx),
2111 Ax * By - Ay * Bx, tValues);
2112}
2113
2114function dxy_at_t(curve, type, t) {
2115 var dxy = {};
2116 if (type == PATH_QUAD) {
2117 var a = t - 1;
2118 var b = 1 - 2 * t;
2119 var c = t;
2120 dxy.x = a * curve[0] + b * curve[2] + c * curve[4];
2121 dxy.y = a * curve[1] + b * curve[3] + c * curve[5];
caryclark1049f122015-04-20 08:31:59 -07002122 } else if (type == PATH_CONIC) {
2123 var p20x = curve[4] - curve[0];
2124 var p20y = curve[5] - curve[1];
2125 var p10xw = (curve[2] - curve[0]) * curve[6];
2126 var p10yw = (curve[3] - curve[1]) * curve[6];
2127 var coeff0x = curve[6] * p20x - p20x;
2128 var coeff0y = curve[6] * p20y - p20y;
2129 var coeff1x = p20x - 2 * p10xw;
2130 var coeff1y = p20y - 2 * p10yw;
2131 dxy.x = t * (t * coeff0x + coeff1x) + p10xw;
2132 dxy.y = t * (t * coeff0y + coeff1y) + p10yw;
caryclarkdac1d172014-06-17 05:15:38 -07002133 } else if (type == PATH_CUBIC) {
2134 var one_t = 1 - t;
2135 var a = curve[0];
2136 var b = curve[2];
2137 var c = curve[4];
2138 var d = curve[6];
2139 dxy.x = 3 * ((b - a) * one_t * one_t + 2 * (c - b) * t * one_t + (d - c) * t * t);
2140 a = curve[1];
2141 b = curve[3];
2142 c = curve[5];
2143 d = curve[7];
2144 dxy.y = 3 * ((b - a) * one_t * one_t + 2 * (c - b) * t * one_t + (d - c) * t * t);
2145 }
2146 return dxy;
2147}
2148
2149function drawLabel(num, px, py) {
2150 ctx.beginPath();
2151 ctx.arc(px, py, 8, 0, Math.PI*2, true);
2152 ctx.closePath();
2153 ctx.strokeStyle = "rgba(0,0,0, 0.4)";
2154 ctx.lineWidth = num == 0 || num == 3 ? 2 : 1;
2155 ctx.stroke();
2156 ctx.fillStyle = "black";
2157 ctx.font = "normal 10px Arial";
2158 // ctx.rotate(0.001);
2159 ctx.fillText(num, px - 2, py + 3);
2160 // ctx.rotate(-0.001);
2161}
2162
2163function drawLabelX(ymin, num, loc) {
2164 var px = (loc - srcLeft) * scale;
2165 var py = (ymin - srcTop) * scale - 20;
2166 drawLabel(num, px, py);
2167}
2168
2169function drawLabelY(xmin, num, loc) {
2170 var px = (xmin - srcLeft) * scale - 20;
2171 var py = (loc - srcTop) * scale;
2172 drawLabel(num, px, py);
2173}
2174
2175function drawHodoOrigin(hx, hy, hMinX, hMinY, hMaxX, hMaxY) {
2176 ctx.beginPath();
2177 ctx.moveTo(hx, hy - 100);
2178 ctx.lineTo(hx, hy);
2179 ctx.strokeStyle = hMinY < 0 ? "green" : "blue";
2180 ctx.stroke();
2181 ctx.beginPath();
2182 ctx.moveTo(hx, hy);
2183 ctx.lineTo(hx, hy + 100);
2184 ctx.strokeStyle = hMaxY > 0 ? "green" : "blue";
2185 ctx.stroke();
2186 ctx.beginPath();
2187 ctx.moveTo(hx - 100, hy);
2188 ctx.lineTo(hx, hy);
2189 ctx.strokeStyle = hMinX < 0 ? "green" : "blue";
2190 ctx.stroke();
2191 ctx.beginPath();
2192 ctx.moveTo(hx, hy);
2193 ctx.lineTo(hx + 100, hy);
2194 ctx.strokeStyle = hMaxX > 0 ? "green" : "blue";
2195 ctx.stroke();
2196}
2197
2198function scalexy(x, y, mag) {
2199 var length = Math.sqrt(x * x + y * y);
2200 return mag / length;
2201}
2202
caryclark03b03ca2015-04-23 09:13:37 -07002203function drawArrow(x, y, dx, dy, s) {
2204 var dscale = scalexy(dx, dy, 1 / scale * 100 * s);
caryclarkdac1d172014-06-17 05:15:38 -07002205 dx *= dscale;
2206 dy *= dscale;
2207 ctx.beginPath();
2208 ctx.moveTo((x - srcLeft) * scale, (y - srcTop) * scale);
2209 x += dx;
2210 y += dy;
2211 ctx.lineTo((x - srcLeft) * scale, (y - srcTop) * scale);
2212 dx /= 10;
2213 dy /= 10;
2214 ctx.lineTo((x - dy - srcLeft) * scale, (y + dx - srcTop) * scale);
2215 ctx.lineTo((x + dx * 2 - srcLeft) * scale, (y + dy * 2 - srcTop) * scale);
2216 ctx.lineTo((x + dy - srcLeft) * scale, (y - dx - srcTop) * scale);
2217 ctx.lineTo((x - srcLeft) * scale, (y - srcTop) * scale);
2218 ctx.strokeStyle = "rgba(0,75,0, 0.4)";
2219 ctx.stroke();
2220}
2221
2222function x_at_t(curve, t) {
2223 var one_t = 1 - t;
2224 if (curve.length == 4) {
2225 return one_t * curve[0] + t * curve[2];
2226 }
2227 var one_t2 = one_t * one_t;
2228 var t2 = t * t;
2229 if (curve.length == 6) {
2230 return one_t2 * curve[0] + 2 * one_t * t * curve[2] + t2 * curve[4];
2231 }
caryclark1049f122015-04-20 08:31:59 -07002232 if (curve.length == 7) {
2233 return (one_t2 * curve[0] + 2 * one_t * t * curve[2] * curve[6] + t2 * curve[4])
2234 / (one_t2 +2 * one_t * t * curve[6] + t2);
2235 }
caryclarkdac1d172014-06-17 05:15:38 -07002236 var a = one_t2 * one_t;
2237 var b = 3 * one_t2 * t;
2238 var c = 3 * one_t * t2;
2239 var d = t2 * t;
2240 return a * curve[0] + b * curve[2] + c * curve[4] + d * curve[6];
2241}
2242
2243function y_at_t(curve, t) {
2244 var one_t = 1 - t;
2245 if (curve.length == 4) {
2246 return one_t * curve[1] + t * curve[3];
2247 }
2248 var one_t2 = one_t * one_t;
2249 var t2 = t * t;
2250 if (curve.length == 6) {
2251 return one_t2 * curve[1] + 2 * one_t * t * curve[3] + t2 * curve[5];
2252 }
caryclark1049f122015-04-20 08:31:59 -07002253 if (curve.length == 7) {
2254 return (one_t2 * curve[1] + 2 * one_t * t * curve[3] * curve[6] + t2 * curve[5])
2255 / (one_t2 +2 * one_t * t * curve[6] + t2);
2256 }
caryclarkdac1d172014-06-17 05:15:38 -07002257 var a = one_t2 * one_t;
2258 var b = 3 * one_t2 * t;
2259 var c = 3 * one_t * t2;
2260 var d = t2 * t;
2261 return a * curve[1] + b * curve[3] + c * curve[5] + d * curve[7];
2262}
2263
2264function drawOrder(curve, label) {
2265 var px = x_at_t(curve, 0.75);
2266 var py = y_at_t(curve, 0.75);
2267 var _px = (px - srcLeft) * scale;
2268 var _py = (py - srcTop) * scale;
2269 ctx.beginPath();
2270 ctx.arc(_px, _py, 15, 0, Math.PI * 2, true);
2271 ctx.closePath();
2272 ctx.fillStyle = "white";
2273 ctx.fill();
2274 if (label == 'L') {
2275 ctx.strokeStyle = "rgba(255,0,0, 1)";
2276 ctx.fillStyle = "rgba(255,0,0, 1)";
2277 } else {
2278 ctx.strokeStyle = "rgba(0,0,255, 1)";
2279 ctx.fillStyle = "rgba(0,0,255, 1)";
2280 }
2281 ctx.stroke();
2282 ctx.font = "normal 16px Arial";
2283 ctx.textAlign = "center";
2284 ctx.fillText(label, _px, _py + 5);
2285 ctx.font = "normal 10px Arial";
2286}
2287
2288function drawID(curve, id) {
2289 var px = x_at_t(curve, 0.5);
2290 var py = y_at_t(curve, 0.5);
2291 var _px = (px - srcLeft) * scale;
2292 var _py = (py - srcTop) * scale;
2293 draw_id_at(id, _px, _py);
2294}
2295
2296function draw_id_at(id, _px, _py) {
2297 ctx.beginPath();
2298 ctx.arc(_px, _py, 15, 0, Math.PI * 2, true);
2299 ctx.closePath();
2300 ctx.fillStyle = "white";
2301 ctx.fill();
2302 ctx.strokeStyle = "rgba(127,127,0, 1)";
2303 ctx.fillStyle = "rgba(127,127,0, 1)";
2304 ctx.stroke();
2305 ctx.font = "normal 16px Arial";
2306 ctx.textAlign = "center";
2307 ctx.fillText(id, _px, _py + 5);
2308 ctx.font = "normal 10px Arial";
2309}
2310
2311function drawLinePartialID(id, x1, y1, x2, y2, t1, t2) {
2312 var curve = [x1, y1, x2, y2];
2313 drawCurvePartialID(id, curve, t1, t2);
2314}
2315
caryclark55888e42016-07-18 10:01:36 -07002316function drawLineID(id, x1, y1, x2, y2) {
2317 drawLinePartialID(id, x1, y1, x2, y2, 0, 1);
2318}
2319
caryclarkdac1d172014-06-17 05:15:38 -07002320function drawQuadPartialID(id, x1, y1, x2, y2, x3, y3, t1, t2) {
2321 var curve = [x1, y1, x2, y2, x3, y3];
2322 drawCurvePartialID(id, curve, t1, t2);
2323}
2324
caryclark55888e42016-07-18 10:01:36 -07002325function drawQuadID(id, x1, y1, x2, y2, x3, y3) {
2326 drawQuadPartialID(id, x1, y1, x2, y2, x3, y3, 0, 1);
2327}
2328
caryclark1049f122015-04-20 08:31:59 -07002329function drawConicPartialID(id, x1, y1, x2, y2, x3, y3, w, t1, t2) {
2330 var curve = [x1, y1, x2, y2, x3, y3, w];
2331 drawCurvePartialID(id, curve, t1, t2);
2332}
2333
caryclark55888e42016-07-18 10:01:36 -07002334function drawConicID(id, x1, y1, x2, y2, x3, y3, w) {
2335 drawConicPartialID(id, x1, y1, x2, y2, x3, y3, w, 0, 1);
2336}
2337
caryclarkdac1d172014-06-17 05:15:38 -07002338function drawCubicPartialID(id, x1, y1, x2, y2, x3, y3, x4, y4, t1, t2) {
2339 var curve = [x1, y1, x2, y2, x3, y3, x4, y4];
2340 drawCurvePartialID(id, curve, t1, t2);
2341}
2342
caryclark55888e42016-07-18 10:01:36 -07002343function drawCubicID(id, x1, y1, x2, y2, x3, y3, x4, y4) {
2344 drawCubicPartialID(id, x1, y1, x2, y2, x3, y3, x4, y4, 0, 1);
2345}
2346
caryclarkdac1d172014-06-17 05:15:38 -07002347function drawCurvePartialID(id, curve, t1, t2) {
2348 var px = x_at_t(curve, (t1 + t2) / 2);
2349 var py = y_at_t(curve, (t1 + t2) / 2);
2350 var _px = (px - srcLeft) * scale;
2351 var _py = (py - srcTop) * scale;
2352 draw_id_at(id, _px, _py);
2353}
2354
2355function drawCurveSpecials(test, curve, type) {
2356 if (pt_labels) {
2357 drawPoints(curve, type, pt_labels == 2);
2358 }
2359 if (control_lines != 0) {
2360 drawControlLines(curve, type, control_lines);
2361 }
2362 if (curve_t) {
2363 drawPointAtT(curve, type);
2364 }
2365 if (draw_midpoint) {
2366 var mid = pointAtT(curve, type, 0.5);
2367 drawPoint(mid.x, mid.y, true);
2368 }
2369 if (draw_id) {
2370 var id = idByCurve(test, curve, type);
2371 if (id >= 0) {
2372 drawID(curve, id);
2373 }
2374 }
2375 if (type == PATH_LINE) {
2376 return;
2377 }
2378 if (draw_deriviatives > 0) {
2379 var d = dxy_at_t(curve, type, 0);
caryclark03b03ca2015-04-23 09:13:37 -07002380 drawArrow(curve[0], curve[1], d.x, d.y, 1);
caryclarkdac1d172014-06-17 05:15:38 -07002381 if (draw_deriviatives == 2) {
2382 d = dxy_at_t(curve, type, 1);
2383 if (type == PATH_CUBIC) {
caryclark03b03ca2015-04-23 09:13:37 -07002384 drawArrow(curve[6], curve[7], d.x, d.y, 1);
caryclarkdac1d172014-06-17 05:15:38 -07002385 } else {
caryclark03b03ca2015-04-23 09:13:37 -07002386 drawArrow(curve[4], curve[5], d.x, d.y, 1);
caryclarkdac1d172014-06-17 05:15:38 -07002387 }
2388 }
2389 if (draw_midpoint) {
2390 var mid = pointAtT(curve, type, 0.5);
2391 d = dxy_at_t(curve, type, 0.5);
caryclark03b03ca2015-04-23 09:13:37 -07002392 drawArrow(mid.x, mid.y, d.x, d.y, 1);
caryclarkdac1d172014-06-17 05:15:38 -07002393 }
2394 }
2395 if (type != PATH_CUBIC) {
2396 return;
2397 }
caryclarkdac1d172014-06-17 05:15:38 -07002398 if (draw_sequence) {
2399 var ymin = Math.min(curve[1], curve[3], curve[5], curve[7]);
2400 for (var i = 0; i < 8; i+= 2) {
2401 drawLabelX(ymin, i >> 1, curve[i]);
2402 }
2403 var xmin = Math.min(curve[0], curve[2], curve[4], curve[6]);
2404 for (var i = 1; i < 8; i+= 2) {
2405 drawLabelY(xmin, i >> 1, curve[i]);
2406 }
2407 }
2408}
2409
2410function logCurves(test) {
2411 for (curves in test) {
2412 var curve = test[curves];
2413 dumpCurve(curve);
2414 }
2415}
2416
2417function curveToString(curve) {
2418 var str = "{{";
caryclark1049f122015-04-20 08:31:59 -07002419 var length = curve.length == 7 ? 6 : curve.length;
2420 if (curve.length == 7) {
2421 str += "{";
2422 }
2423 for (i = 0; i < length; i += 2) {
caryclarkdac1d172014-06-17 05:15:38 -07002424 str += curve[i].toFixed(decimal_places) + "," + curve[i + 1].toFixed(decimal_places);
2425 if (i < curve.length - 2) {
2426 str += "}, {";
2427 }
2428 }
caryclark1049f122015-04-20 08:31:59 -07002429 str += "}";
2430 if (curve.length == 7) {
2431 str += "}, " + curve[6].toFixed(decimal_places);
2432 }
2433 str += "}";
caryclarkdac1d172014-06-17 05:15:38 -07002434 return str;
2435}
2436
2437function dumpCurve(curve) {
2438 console.log(curveToString(curve));
2439}
2440
2441function draw(test, lines, title) {
2442 ctx.fillStyle = "rgba(0,0,0, 0.1)";
2443 ctx.font = "normal 50px Arial";
2444 ctx.textAlign = "left";
2445 ctx.fillText(title, 50, 50);
2446 ctx.font = "normal 10px Arial";
2447 ctx.lineWidth = "1.001"; "0.999";
2448 var secondPath = test.length;
2449 var closeCount = 0;
2450 logStart = -1;
2451 logRange = 0;
2452 // find last active rec type at this step
2453 var curType = test[0];
2454 var curStep = 0;
2455 var hasOp = false;
2456 var lastActive = 0;
2457 var lastAdd = 0;
caryclark624637c2015-05-11 07:21:27 -07002458 var lastCoin = 0;
caryclarkdac1d172014-06-17 05:15:38 -07002459 var lastSect = 0;
2460 var lastSort = 0;
2461 var lastMark = 0;
caryclark03b03ca2015-04-23 09:13:37 -07002462 var lastTop = 0;
caryclarkdac1d172014-06-17 05:15:38 -07002463 activeCount = 0;
2464 addCount = 0;
2465 angleCount = 0;
2466 opCount = 0;
2467 sectCount = 0;
2468 sortCount = 0;
caryclark03b03ca2015-04-23 09:13:37 -07002469 topCount = 0;
caryclarkdac1d172014-06-17 05:15:38 -07002470 markCount = 0;
2471 activeMax = 0;
2472 addMax = 0;
2473 angleMax = 0;
caryclark624637c2015-05-11 07:21:27 -07002474 coinMax = 0;
caryclarkdac1d172014-06-17 05:15:38 -07002475 opMax = 0;
2476 sectMax = 0;
2477 sectMax2 = 0;
2478 sortMax = 0;
caryclark03b03ca2015-04-23 09:13:37 -07002479 topMax = 0;
caryclarkdac1d172014-06-17 05:15:38 -07002480 markMax = 0;
2481 lastIndex = test.length - 3;
2482 for (var tIndex = 0; tIndex < test.length; tIndex += 3) {
2483 var recType = test[tIndex];
2484 if (!typeof recType == 'number' || recType < REC_TYPE_UNKNOWN || recType > REC_TYPE_LAST) {
2485 console.log("unknown rec type: " + recType);
2486 throw "stop execution";
2487 }
2488 // if (curType == recType && curType != REC_TYPE_ADD) {
2489 // continue;
2490 // }
2491 var inStepRange = step_limit == 0 || curStep < step_limit;
2492 curType = recType;
2493 if (recType == REC_TYPE_OP) {
2494 hasOp = true;
2495 continue;
2496 }
2497 if (recType == REC_TYPE_UNKNOWN) {
2498 // these types do not advance step
2499 continue;
2500 }
2501 var bumpStep = false;
2502 var records = test[tIndex + 2];
2503 var fragType = records[0];
2504 if (recType == REC_TYPE_ADD) {
2505 if (records.length != 2) {
2506 console.log("expect only two elements: " + records.length);
2507 throw "stop execution";
2508 }
2509 if (fragType == ADD_MOVETO || fragType == ADD_CLOSE) {
2510 continue;
2511 }
2512 ++addMax;
2513 if (!draw_add || !inStepRange) {
2514 continue;
2515 }
2516 lastAdd = tIndex;
2517 ++addCount;
2518 bumpStep = true;
2519 }
2520 if (recType == REC_TYPE_PATH && hasOp) {
2521 secondPath = tIndex;
2522 }
caryclark54359292015-03-26 07:52:43 -07002523 if (recType == REC_TYPE_PATH2 && hasOp) {
2524 secondPath = tIndex;
2525 }
caryclarkdac1d172014-06-17 05:15:38 -07002526 if (recType == REC_TYPE_ACTIVE) {
2527 ++activeMax;
2528 if (!draw_active || !inStepRange) {
2529 continue;
2530 }
2531 lastActive = tIndex;
2532 ++activeCount;
2533 bumpStep = true;
2534 }
2535 if (recType == REC_TYPE_ACTIVE_OP) {
2536 ++opMax;
2537 if (!draw_op || !inStepRange) {
2538 continue;
2539 }
2540 lastOp = tIndex;
2541 ++opCount;
2542 bumpStep = true;
2543 }
caryclark54359292015-03-26 07:52:43 -07002544 if (recType == REC_TYPE_AFTERPART) {
2545 if (draw_angle != 3 || !inStepRange) {
2546 continue;
2547 }
2548 lastAngle = tIndex;
2549 ++angleCount;
2550 bumpStep = true;
2551 }
caryclarkdac1d172014-06-17 05:15:38 -07002552 if (recType == REC_TYPE_ANGLE) {
2553 ++angleMax;
caryclark54359292015-03-26 07:52:43 -07002554 if (draw_angle == 0 || draw_angle == 3 || !inStepRange) {
caryclarkdac1d172014-06-17 05:15:38 -07002555 continue;
2556 }
2557 lastAngle = tIndex;
2558 ++angleCount;
2559 bumpStep = true;
2560 }
caryclark624637c2015-05-11 07:21:27 -07002561 if (recType == REC_TYPE_COINCIDENCE) {
2562 ++coinMax;
2563 if (!draw_coincidence || !inStepRange) {
2564 continue;
2565 }
2566 lastCoin = tIndex;
2567 ++coinCount;
2568 bumpStep = true;
2569 }
caryclarkdac1d172014-06-17 05:15:38 -07002570 if (recType == REC_TYPE_SECT) {
2571 if (records.length != 2) {
2572 console.log("expect only two elements: " + records.length);
2573 throw "stop execution";
2574 }
2575 ++sectMax;
2576 var sectBump = 1;
2577 switch (fragType) {
2578 case INTERSECT_LINE:
2579 case INTERSECT_QUAD_LINE:
2580 case INTERSECT_QUAD:
caryclark1049f122015-04-20 08:31:59 -07002581 case INTERSECT_CONIC_LINE:
caryclark55888e42016-07-18 10:01:36 -07002582 case INTERSECT_CONIC_QUAD:
caryclark1049f122015-04-20 08:31:59 -07002583 case INTERSECT_CONIC:
caryclarkdac1d172014-06-17 05:15:38 -07002584 case INTERSECT_SELF_CUBIC:
2585 case INTERSECT_CUBIC_LINE:
2586 case INTERSECT_CUBIC_QUAD:
2587 case INTERSECT_CUBIC:
2588 sectBump = 1;
2589 break;
2590 case INTERSECT_LINE_2:
2591 case INTERSECT_QUAD_LINE_2:
2592 case INTERSECT_QUAD_2:
caryclark1049f122015-04-20 08:31:59 -07002593 case INTERSECT_CONIC_LINE_2:
caryclark55888e42016-07-18 10:01:36 -07002594 case INTERSECT_CONIC_QUAD_2:
caryclark1049f122015-04-20 08:31:59 -07002595 case INTERSECT_CONIC_2:
caryclarkdac1d172014-06-17 05:15:38 -07002596 case INTERSECT_CUBIC_LINE_2:
2597 case INTERSECT_CUBIC_QUAD_2:
2598 case INTERSECT_CUBIC_2:
2599 sectBump = 2;
2600 break;
2601 case INTERSECT_LINE_NO:
2602 case INTERSECT_QUAD_LINE_NO:
2603 case INTERSECT_QUAD_NO:
caryclark1049f122015-04-20 08:31:59 -07002604 case INTERSECT_CONIC_LINE_NO:
caryclark55888e42016-07-18 10:01:36 -07002605 case INTERSECT_CONIC_QUAD_NO:
caryclark1049f122015-04-20 08:31:59 -07002606 case INTERSECT_CONIC_NO:
caryclarkdac1d172014-06-17 05:15:38 -07002607 case INTERSECT_SELF_CUBIC_NO:
2608 case INTERSECT_CUBIC_LINE_NO:
2609 case INTERSECT_CUBIC_QUAD_NO:
2610 case INTERSECT_CUBIC_NO:
2611 sectBump = 0;
2612 break;
2613 case INTERSECT_CUBIC_LINE_3:
2614 case INTERSECT_CUBIC_QUAD_3:
2615 case INTERSECT_CUBIC_3:
2616 sectBump = 3;
2617 break;
2618 case INTERSECT_CUBIC_QUAD_4:
2619 case INTERSECT_CUBIC_4:
2620 sectBump = 4;
2621 break;
2622 default:
2623 console.log("missing case " + records.length);
2624 throw "stop execution";
2625 }
2626 sectMax2 += sectBump;
2627 if (draw_intersection <= 1 || !inStepRange) {
2628 continue;
2629 }
2630 lastSect = tIndex;
2631 sectCount += sectBump;
2632 bumpStep = true;
2633 }
2634 if (recType == REC_TYPE_SORT) {
2635 ++sortMax;
2636 if (!draw_sort || !inStepRange) {
2637 continue;
2638 }
2639 lastSort = tIndex;
2640 ++sortCount;
2641 bumpStep = true;
2642 }
caryclark03b03ca2015-04-23 09:13:37 -07002643 if (recType == REC_TYPE_TOP) {
2644 ++topMax;
2645 if (!draw_top || !inStepRange) {
2646 continue;
2647 }
2648 lastTop = tIndex;
2649 ++topCount;
2650 bumpStep = true;
2651 }
caryclarkdac1d172014-06-17 05:15:38 -07002652 if (recType == REC_TYPE_MARK) {
2653 ++markMax;
2654 if (!draw_mark || !inStepRange) {
2655 continue;
2656 }
2657 lastMark = tIndex;
2658 ++markCount;
2659 bumpStep = true;
2660 }
2661 if (bumpStep) {
2662 lastIndex = tIndex;
2663 logStart = test[tIndex + 1];
2664 logRange = records.length / 2;
2665 ++curStep;
2666 }
2667 }
2668 stepMax = (draw_add ? addMax : 0)
2669 + (draw_active ? activeMax : 0)
reed0dc4dd62015-03-24 13:55:33 -07002670 + (draw_angle ? angleMax : 0)
caryclark624637c2015-05-11 07:21:27 -07002671 + (draw_coincidence ? coinMax : 0)
caryclark54359292015-03-26 07:52:43 -07002672 + (draw_op ? opMax : 0)
caryclarkdac1d172014-06-17 05:15:38 -07002673 + (draw_sort ? sortMax : 0)
caryclark03b03ca2015-04-23 09:13:37 -07002674 + (draw_top ? topMax : 0)
caryclarkdac1d172014-06-17 05:15:38 -07002675 + (draw_mark ? markMax : 0)
2676 + (draw_intersection == 2 ? sectMax : draw_intersection == 3 ? sectMax2 : 0);
2677 if (stepMax == 0) {
caryclark624637c2015-05-11 07:21:27 -07002678 stepMax = addMax + activeMax + angleMax + coinMax + opMax + sortMax + topMax + markMax;
caryclarkdac1d172014-06-17 05:15:38 -07002679 }
2680 drawnPts = [];
2681 drawnLines = [];
2682 drawnQuads = [];
caryclark1049f122015-04-20 08:31:59 -07002683 drawnConics = [];
caryclarkdac1d172014-06-17 05:15:38 -07002684 drawnCubics = [];
2685 focusXmin = focusYmin = Infinity;
2686 focusXmax = focusYmax = -Infinity;
2687 var pathIndex = 0;
2688 var opLetter = 'S';
2689 for (var tIndex = lastIndex; tIndex >= 0; tIndex -= 3) {
2690 var recType = test[tIndex];
2691 var records = test[tIndex + 2];
2692 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
2693 var fragType = records[recordIndex];
2694 if (!typeof fragType == 'number' || fragType < 1 || fragType > FRAG_TYPE_LAST) {
2695 console.log("unknown in range frag type: " + fragType);
2696 throw "stop execution";
2697 }
2698 var frags = records[recordIndex + 1];
2699 focus_enabled = false;
2700 switch (recType) {
2701 case REC_TYPE_COMPUTED:
2702 if (draw_computed == 0) {
2703 continue;
2704 }
2705 ctx.lineWidth = 1;
2706 ctx.strokeStyle = pathIndex == 0 ? "black" : "red";
2707 ctx.fillStyle = "blue";
2708 var drawThis = false;
2709 switch (fragType) {
2710 case PATH_QUAD:
caryclark1049f122015-04-20 08:31:59 -07002711 if ((draw_computed & 0x9) == 1 || ((draw_computed & 8) != 0
2712 && (draw_computed & 7) == pathIndex)) {
caryclarkdac1d172014-06-17 05:15:38 -07002713 drawQuad(frags[0], frags[1], frags[2], frags[3],
2714 frags[4], frags[5]);
2715 drawThis = true;
2716 }
2717 break;
caryclark1049f122015-04-20 08:31:59 -07002718 case PATH_CONIC:
2719 if ((draw_computed & 0xA) == 2 || ((draw_computed & 8) != 0
2720 && (draw_computed & 7) == pathIndex)) {
2721 drawConicWithQuads(frags[0], frags[1], frags[2], frags[3],
2722 frags[4], frags[5], frags[6]);
2723 drawThis = true;
2724 }
2725 break;
caryclarkdac1d172014-06-17 05:15:38 -07002726 case PATH_CUBIC:
caryclark1049f122015-04-20 08:31:59 -07002727 if ((draw_computed & 0xC) == 4 || ((draw_computed & 8) != 0
2728 && (draw_computed & 7) == pathIndex)) {
caryclarkdac1d172014-06-17 05:15:38 -07002729 drawCubic(frags[0], frags[1], frags[2], frags[3],
2730 frags[4], frags[5], frags[6], frags[7]);
2731 drawThis = true;
2732 }
2733 ++pathIndex;
2734 break;
2735 case COMPUTED_SET_1:
2736 pathIndex = 0;
2737 break;
2738 case COMPUTED_SET_2:
2739 pathIndex = 1;
2740 break;
2741 default:
2742 console.log("unknown REC_TYPE_COMPUTED frag type: " + fragType);
2743 throw "stop execution";
2744 }
2745 if (!drawThis || collect_bounds) {
2746 break;
2747 }
2748 drawCurveSpecials(test, frags, fragType);
2749 break;
caryclark26ad22a2015-10-16 09:03:38 -07002750 case REC_TYPE_ALIGNED:
2751 if (draw_path < 4) {
2752 continue;
2753 }
caryclarkdac1d172014-06-17 05:15:38 -07002754 case REC_TYPE_PATH:
caryclark54359292015-03-26 07:52:43 -07002755 case REC_TYPE_PATH2:
caryclark26ad22a2015-10-16 09:03:38 -07002756 if (REC_TYPE_ALIGNED != recType && draw_path >= 4) {
2757 continue;
2758 }
caryclarkdac1d172014-06-17 05:15:38 -07002759 if (!draw_path) {
2760 continue;
2761 }
2762 var firstPath = tIndex < secondPath;
2763 if ((draw_path & (firstPath ? 1 : 2)) == 0) {
2764 continue;
2765 }
2766 ctx.lineWidth = 1;
2767 ctx.strokeStyle = firstPath ? "black" : "red";
2768 ctx.fillStyle = "blue";
caryclark55888e42016-07-18 10:01:36 -07002769 var frags2 = [];
caryclarkdac1d172014-06-17 05:15:38 -07002770 switch (fragType) {
2771 case PATH_LINE:
caryclark54359292015-03-26 07:52:43 -07002772 for (var i = 0; i < 4; ++ i) { frags2[i] = frags[i + 1]; }
2773 drawLine(frags2[0], frags2[1], frags2[2], frags2[3]);
caryclarkdac1d172014-06-17 05:15:38 -07002774 break;
2775 case PATH_QUAD:
caryclark54359292015-03-26 07:52:43 -07002776 for (var i = 0; i < 6; ++ i) { frags2[i] = frags[i + 1]; }
2777 drawQuad(frags2[0], frags2[1], frags2[2], frags2[3],
2778 frags2[4], frags2[5]);
caryclarkdac1d172014-06-17 05:15:38 -07002779 break;
caryclark1049f122015-04-20 08:31:59 -07002780 case PATH_CONIC:
2781 for (var i = 0; i < 7; ++ i) { frags2[i] = frags[i + 1]; }
2782 drawConicWithQuads(frags2[0], frags2[1], frags2[2], frags2[3],
2783 frags2[4], frags2[5], frags2[6]);
2784 break;
caryclarkdac1d172014-06-17 05:15:38 -07002785 case PATH_CUBIC:
caryclark54359292015-03-26 07:52:43 -07002786 for (var i = 0; i < 8; ++ i) { frags2[i] = frags[i + 1]; }
2787 drawCubic(frags2[0], frags2[1], frags2[2], frags2[3],
2788 frags2[4], frags2[5], frags2[6], frags2[7]);
caryclarkdac1d172014-06-17 05:15:38 -07002789 break;
2790 default:
caryclark26ad22a2015-10-16 09:03:38 -07002791 console.log("unknown " + recType + " frag type: " + fragType);
caryclarkdac1d172014-06-17 05:15:38 -07002792 throw "stop execution";
2793 }
2794 if (collect_bounds) {
2795 break;
2796 }
caryclark54359292015-03-26 07:52:43 -07002797 drawCurveSpecials(test, frags2, fragType);
caryclarkdac1d172014-06-17 05:15:38 -07002798 break;
2799 case REC_TYPE_OP:
2800 switch (fragType) {
2801 case OP_INTERSECT: opLetter = 'I'; break;
2802 case OP_DIFFERENCE: opLetter = 'D'; break;
2803 case OP_UNION: opLetter = 'U'; break;
2804 case OP_XOR: opLetter = 'X'; break;
2805 default:
2806 console.log("unknown REC_TYPE_OP frag type: " + fragType);
2807 throw "stop execution";
2808 }
2809 break;
2810 case REC_TYPE_ACTIVE:
2811 if (!draw_active || (step_limit > 0 && tIndex < lastActive)) {
2812 continue;
2813 }
2814 var x1 = frags[SPAN_X1];
2815 var y1 = frags[SPAN_Y1];
2816 var x2 = frags[SPAN_X2];
2817 var y2 = frags[SPAN_Y2];
caryclark55888e42016-07-18 10:01:36 -07002818 var x3, y3, x3, y4, w;
caryclarkdac1d172014-06-17 05:15:38 -07002819 ctx.lineWidth = 3;
2820 ctx.strokeStyle = "rgba(0,0,255, 0.3)";
2821 focus_enabled = true;
2822 switch (fragType) {
2823 case ACTIVE_LINE_SPAN:
caryclark55888e42016-07-18 10:01:36 -07002824 drawLine(x1, y1, x2, y2);
caryclarkdac1d172014-06-17 05:15:38 -07002825 if (draw_id) {
caryclark55888e42016-07-18 10:01:36 -07002826 drawLineID(frags[0], x1, y1, x2, y2);
2827 }
2828 if (pt_labels) {
2829 var curve = [x1, y1, x2, y2];
2830 ctx.fillStyle = "blue";
2831 drawPoints(curve, PATH_LINE, pt_labels == 2);
caryclarkdac1d172014-06-17 05:15:38 -07002832 }
2833 break;
2834 case ACTIVE_QUAD_SPAN:
2835 x3 = frags[SPAN_X3];
2836 y3 = frags[SPAN_Y3];
caryclark55888e42016-07-18 10:01:36 -07002837 drawQuad(x1, y1, x2, y2, x3, y3);
caryclarkdac1d172014-06-17 05:15:38 -07002838 if (draw_id) {
caryclark55888e42016-07-18 10:01:36 -07002839 drawQuadID(frags[0], x1, y1, x2, y2, x3, y3);
2840 }
2841 if (pt_labels) {
2842 var curve = [x1, y1, x2, y2, x3, y3];
2843 ctx.fillStyle = "blue";
2844 drawPoints(curve, PATH_QUAD, pt_labels == 2);
caryclarkdac1d172014-06-17 05:15:38 -07002845 }
2846 break;
caryclark1049f122015-04-20 08:31:59 -07002847 case ACTIVE_CONIC_SPAN:
2848 x3 = frags[SPAN_X3];
2849 y3 = frags[SPAN_Y3];
caryclark1049f122015-04-20 08:31:59 -07002850 w = frags[SPAN_K_W];
caryclark55888e42016-07-18 10:01:36 -07002851 drawConicWithQuads(x1, y1, x2, y2, x3, y3, w);
caryclark1049f122015-04-20 08:31:59 -07002852 if (draw_id) {
caryclark55888e42016-07-18 10:01:36 -07002853 drawConicID(frags[0], x1, y1, x2, y2, x3, y3, w);
2854 }
2855 if (pt_labels) {
2856 var curve = [x1, y1, x2, y2, x3, y3, w];
2857 ctx.fillStyle = "blue";
2858 drawPoints(curve, PATH_CONIC, pt_labels == 2);
caryclark1049f122015-04-20 08:31:59 -07002859 }
2860 break;
caryclarkdac1d172014-06-17 05:15:38 -07002861 case ACTIVE_CUBIC_SPAN:
2862 x3 = frags[SPAN_X3];
2863 y3 = frags[SPAN_Y3];
2864 x4 = frags[SPAN_X4];
2865 y4 = frags[SPAN_Y4];
caryclark55888e42016-07-18 10:01:36 -07002866 drawCubic(x1, y1, x2, y2, x3, y3, x4, y4);
caryclarkdac1d172014-06-17 05:15:38 -07002867 if (draw_id) {
caryclark55888e42016-07-18 10:01:36 -07002868 drawCubicID(frags[0], x1, y1, x2, y2, x3, y3, x4, y4);
2869 }
2870 if (pt_labels) {
2871 var curve = [x1, y1, x2, y2, x3, y3, x4, y4];
2872 ctx.fillStyle = "blue";
2873 drawPoints(curve, PATH_CUBIC, pt_labels == 2);
caryclarkdac1d172014-06-17 05:15:38 -07002874 }
2875 break;
2876 default:
2877 console.log("unknown REC_TYPE_ACTIVE frag type: " + fragType);
2878 throw "stop execution";
2879 }
2880 break;
2881 case REC_TYPE_ACTIVE_OP:
2882 if (!draw_op || (step_limit > 0 && tIndex < lastOp)) {
2883 continue;
2884 }
2885 focus_enabled = true;
2886 ctx.lineWidth = 3;
2887 var activeSpan = frags[7] == "1";
2888 ctx.strokeStyle = activeSpan ? "rgba(45,160,0, 0.3)" : "rgba(255,45,0, 0.5)";
2889 var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
2890 drawCurve(curve);
2891 if (draw_op > 1) {
2892 drawArc(curve, false, frags[3], frags[4]);
2893 drawArc(curve, true, frags[5], frags[6]);
2894 }
2895 break;
2896 case REC_TYPE_ADD:
2897 if (!draw_add) {
2898 continue;
2899 }
2900 ctx.lineWidth = 3;
2901 ctx.strokeStyle = closeCount == 0 ? "rgba(0,0,255, 0.3)"
2902 : closeCount == 1 ? "rgba(0,127,0, 0.3)"
2903 : closeCount == 2 ? "rgba(0,127,127, 0.3)"
2904 : closeCount == 3 ? "rgba(127,127,0, 0.3)"
2905 : "rgba(127,0,127, 0.3)";
2906 focus_enabled = true;
2907 switch (fragType) {
2908 case ADD_MOVETO:
2909 break;
2910 case ADD_LINETO:
2911 if (step_limit == 0 || tIndex >= lastAdd) {
2912 drawLine(frags[0], frags[1], frags[2], frags[3]);
2913 }
2914 break;
2915 case ADD_QUADTO:
2916 if (step_limit == 0 || tIndex >= lastAdd) {
2917 drawQuad(frags[0], frags[1], frags[2], frags[3], frags[4], frags[5]);
2918 }
2919 break;
caryclark1049f122015-04-20 08:31:59 -07002920 case ADD_CONICTO:
2921 if (step_limit == 0 || tIndex >= lastAdd) {
2922 drawConicWithQuads(frags[0], frags[1], frags[2], frags[3],
2923 frags[4], frags[5], frags[6]);
2924 }
2925 break;
caryclarkdac1d172014-06-17 05:15:38 -07002926 case ADD_CUBICTO:
2927 if (step_limit == 0 || tIndex >= lastAdd) {
2928 drawCubic(frags[0], frags[1], frags[2], frags[3],
2929 frags[4], frags[5], frags[6], frags[7]);
2930 }
2931 break;
2932 case ADD_CLOSE:
2933 ++closeCount;
2934 break;
2935 case ADD_FILL:
2936 break;
2937 default:
2938 console.log("unknown REC_TYPE_ADD frag type: " + fragType);
2939 throw "stop execution";
2940 }
2941 break;
2942 case REC_TYPE_ANGLE:
caryclark54359292015-03-26 07:52:43 -07002943 angleBetween = frags[18] == "T";
2944 afterIndex = 0;
2945 if (draw_angle == 0 || draw_angle == 3 || (step_limit > 0 && tIndex < lastAngle)) {
caryclarkdac1d172014-06-17 05:15:38 -07002946 continue;
2947 }
2948 focus_enabled = true;
2949 ctx.lineWidth = 3;
2950 ctx.strokeStyle = "rgba(127,45,127, 0.3)";
caryclark54359292015-03-26 07:52:43 -07002951 var leftCurve = curvePartialByID(test, frags[0], frags[4], frags[5]);
2952 var midCurve = curvePartialByID(test, frags[6], frags[10], frags[11]);
2953 var rightCurve = curvePartialByID(test, frags[12], frags[16], frags[17]);
caryclarkdac1d172014-06-17 05:15:38 -07002954 drawCurve(leftCurve);
2955 drawCurve(rightCurve);
caryclark54359292015-03-26 07:52:43 -07002956 ctx.strokeStyle = angleBetween ? "rgba(0,160,45, 0.3)" : "rgba(255,0,45, 0.5)";
caryclarkdac1d172014-06-17 05:15:38 -07002957 drawCurve(midCurve);
2958 if (draw_angle > 1) {
2959 drawOrder(leftCurve, 'L');
2960 drawOrder(rightCurve, 'R');
2961 }
2962 break;
caryclark54359292015-03-26 07:52:43 -07002963 case REC_TYPE_AFTERPART:
2964 if (draw_angle != 3 || (step_limit > 0 && tIndex < lastAngle)) {
2965 continue;
2966 }
2967 ctx.strokeStyle = afterIndex == 0 ? "rgba(255,0,0, 1.0)"
2968 : (afterIndex == 1) == angleBetween ? "rgba(0,128,0, 1.0)"
2969 : "rgba(0,0,255, 1.0)";
2970 switch (fragType) {
2971 case PATH_LINE:
2972 drawLine(frags[0], frags[1], frags[2], frags[3]);
2973 break;
2974 case PATH_QUAD:
2975 drawQuad(frags[0], frags[1], frags[2], frags[3],
2976 frags[4], frags[5]);
2977 break;
caryclark1049f122015-04-20 08:31:59 -07002978 case PATH_CONIC:
2979 drawConicWithQuads(frags[0], frags[1], frags[2], frags[3],
2980 frags[4], frags[5], frags[6]);
2981 break;
caryclark54359292015-03-26 07:52:43 -07002982 case PATH_CUBIC:
2983 drawCubic(frags[0], frags[1], frags[2], frags[3],
caryclark1049f122015-04-20 08:31:59 -07002984 frags[4], frags[5], frags[6], frags[7]);
caryclark54359292015-03-26 07:52:43 -07002985 break;
2986 default:
2987 console.log("unknown REC_TYPE_AFTERPART frag type: " + fragType);
2988 throw "stop execution";
2989 }
2990 ++afterIndex;
2991 break;
caryclark624637c2015-05-11 07:21:27 -07002992 case REC_TYPE_COINCIDENCE:
2993 if (!draw_coincidence || (step_limit > 0 && tIndex < lastCoin)) {
2994 continue;
2995 }
2996 focus_enabled = true;
2997 ctx.lineWidth = 3;
2998 ctx.strokeStyle = "rgba(127,45,63, 0.3)";
2999 var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
3000 drawCurve(curve);
3001 break;
caryclarkdac1d172014-06-17 05:15:38 -07003002 case REC_TYPE_SECT:
3003 if (!draw_intersection) {
3004 continue;
3005 }
3006 if (draw_intersection != 1 && (step_limit > 0 && tIndex < lastSect)) {
3007 continue;
3008 }
3009 // draw_intersection == 1 : show all
3010 // draw_intersection == 2 : step == 0 ? show all : show intersection line #step
3011 // draw_intersection == 3 : step == 0 ? show all : show intersection #step
3012 ctx.lineWidth = 1;
3013 ctx.strokeStyle = "rgba(0,0,255, 0.3)";
3014 ctx.fillStyle = "blue";
3015 focus_enabled = true;
3016 var f = [];
3017 var c1s;
3018 var c1l;
3019 var c2s;
3020 var c2l;
3021 switch (fragType) {
3022 case INTERSECT_LINE:
3023 f.push(5, 6, 0, 7);
3024 c1s = 1; c1l = 4; c2s = 8; c2l = 4;
3025 break;
3026 case INTERSECT_LINE_2:
3027 f.push(5, 6, 0, 10);
3028 f.push(8, 9, 7, 15);
3029 c1s = 1; c1l = 4; c2s = 11; c2l = 4;
3030 break;
3031 case INTERSECT_LINE_NO:
3032 c1s = 0; c1l = 4; c2s = 4; c2l = 4;
3033 break;
3034 case INTERSECT_QUAD_LINE:
3035 f.push(7, 8, 0, 9);
3036 c1s = 1; c1l = 6; c2s = 10; c2l = 4;
3037 break;
3038 case INTERSECT_QUAD_LINE_2:
3039 f.push(7, 8, 0, 12);
3040 f.push(10, 11, 9, 17);
3041 c1s = 1; c1l = 6; c2s = 13; c2l = 4;
3042 break;
3043 case INTERSECT_QUAD_LINE_NO:
3044 c1s = 0; c1l = 6; c2s = 6; c2l = 4;
3045 break;
3046 case INTERSECT_QUAD:
3047 f.push(7, 8, 0, 9);
3048 c1s = 1; c1l = 6; c2s = 10; c2l = 6;
3049 break;
3050 case INTERSECT_QUAD_2:
3051 f.push(7, 8, 0, 12);
3052 f.push(10, 11, 9, 19);
3053 c1s = 1; c1l = 6; c2s = 13; c2l = 6;
3054 break;
3055 case INTERSECT_QUAD_NO:
3056 c1s = 0; c1l = 6; c2s = 6; c2l = 6;
3057 break;
caryclark1049f122015-04-20 08:31:59 -07003058 case INTERSECT_CONIC_LINE:
3059 f.push(8, 9, 0, 10);
3060 c1s = 1; c1l = 7; c2s = 11; c2l = 4;
3061 break;
3062 case INTERSECT_CONIC_LINE_2:
3063 f.push(8, 9, 0, 12);
3064 f.push(11, 12, 10, 18);
3065 c1s = 1; c1l = 7; c2s = 14; c2l = 4;
3066 break;
3067 case INTERSECT_CONIC_LINE_NO:
3068 c1s = 0; c1l = 7; c2s = 7; c2l = 4;
3069 break;
caryclark55888e42016-07-18 10:01:36 -07003070 case INTERSECT_CONIC_QUAD:
3071 f.push(8, 9, 0, 10);
3072 c1s = 1; c1l = 7; c2s = 11; c2l = 6;
3073 break;
3074 case INTERSECT_CONIC_QUAD_2:
3075 f.push(8, 9, 0, 12);
3076 f.push(11, 12, 10, 18);
3077 c1s = 1; c1l = 7; c2s = 14; c2l = 6;
3078 break;
3079 case INTERSECT_CONIC_QUAD_NO:
3080 c1s = 0; c1l = 7; c2s = 7; c2l = 6;
3081 break;
caryclark1049f122015-04-20 08:31:59 -07003082 case INTERSECT_CONIC:
3083 f.push(8, 9, 0, 10);
3084 c1s = 1; c1l = 7; c2s = 11; c2l = 7;
3085 break;
3086 case INTERSECT_CONIC_2:
3087 f.push(8, 9, 0, 13);
3088 f.push(11, 12, 10, 21);
3089 c1s = 1; c1l = 7; c2s = 14; c2l = 7;
3090 break;
3091 case INTERSECT_CONIC_NO:
3092 c1s = 0; c1l = 7; c2s = 7; c2l = 7;
3093 break;
caryclarkdac1d172014-06-17 05:15:38 -07003094 case INTERSECT_SELF_CUBIC:
3095 f.push(9, 10, 0, 11);
3096 c1s = 1; c1l = 8; c2s = 0; c2l = 0;
3097 break;
3098 case INTERSECT_SELF_CUBIC_NO:
3099 c1s = 0; c1l = 8; c2s = 0; c2l = 0;
3100 break;
3101 case INTERSECT_CUBIC_LINE:
3102 f.push(9, 10, 0, 11);
3103 c1s = 1; c1l = 8; c2s = 12; c2l = 4;
3104 break;
3105 case INTERSECT_CUBIC_LINE_2:
3106 f.push(9, 10, 0, 14);
3107 f.push(12, 13, 11, 19);
3108 c1s = 1; c1l = 8; c2s = 15; c2l = 4;
3109 break;
3110 case INTERSECT_CUBIC_LINE_3:
3111 f.push(9, 10, 0, 17);
3112 f.push(12, 13, 11, 22);
3113 f.push(15, 16, 14, 23);
3114 c1s = 1; c1l = 8; c2s = 18; c2l = 4;
3115 break;
3116 case INTERSECT_CUBIC_QUAD_NO:
3117 c1s = 0; c1l = 8; c2s = 8; c2l = 6;
3118 break;
3119 case INTERSECT_CUBIC_QUAD:
3120 f.push(9, 10, 0, 11);
3121 c1s = 1; c1l = 8; c2s = 12; c2l = 6;
3122 break;
3123 case INTERSECT_CUBIC_QUAD_2:
3124 f.push(9, 10, 0, 14);
3125 f.push(12, 13, 11, 21);
3126 c1s = 1; c1l = 8; c2s = 15; c2l = 6;
3127 break;
3128 case INTERSECT_CUBIC_QUAD_3:
3129 f.push(9, 10, 0, 17);
3130 f.push(12, 13, 11, 24);
3131 f.push(15, 16, 14, 25);
3132 c1s = 1; c1l = 8; c2s = 18; c2l = 6;
3133 break;
3134 case INTERSECT_CUBIC_QUAD_4:
3135 f.push(9, 10, 0, 20);
3136 f.push(12, 13, 11, 27);
3137 f.push(15, 16, 14, 28);
3138 f.push(18, 19, 17, 29);
3139 c1s = 1; c1l = 8; c2s = 21; c2l = 6;
3140 break;
3141 case INTERSECT_CUBIC_LINE_NO:
3142 c1s = 0; c1l = 8; c2s = 8; c2l = 4;
3143 break;
3144 case INTERSECT_CUBIC:
3145 f.push(9, 10, 0, 11);
3146 c1s = 1; c1l = 8; c2s = 12; c2l = 8;
3147 break;
3148 case INTERSECT_CUBIC_2:
3149 f.push(9, 10, 0, 14);
3150 f.push(12, 13, 11, 23);
3151 c1s = 1; c1l = 8; c2s = 15; c2l = 8;
3152 break;
3153 case INTERSECT_CUBIC_3:
3154 f.push(9, 10, 0, 17);
3155 f.push(12, 13, 11, 26);
3156 f.push(15, 16, 14, 27);
3157 c1s = 1; c1l = 8; c2s = 18; c2l = 8;
3158 break;
3159 case INTERSECT_CUBIC_4:
3160 f.push(9, 10, 0, 20);
3161 f.push(12, 13, 11, 29);
3162 f.push(15, 16, 14, 30);
3163 f.push(18, 19, 17, 31);
3164 c1s = 1; c1l = 8; c2s = 21; c2l = 8;
3165 break;
3166 case INTERSECT_CUBIC_NO:
3167 c1s = 0; c1l = 8; c2s = 8; c2l = 8;
3168 break;
3169 default:
3170 console.log("unknown REC_TYPE_SECT frag type: " + fragType);
3171 throw "stop execution";
3172 }
3173 if (draw_intersection != 1) {
3174 var id = -1;
3175 var curve;
3176 switch (c1l) {
caryclark55888e42016-07-18 10:01:36 -07003177 case 4:
caryclarkdac1d172014-06-17 05:15:38 -07003178 drawLine(frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3]);
3179 if (draw_id) {
3180 curve = [frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3]];
3181 id = idByCurve(test, curve, PATH_LINE);
3182 }
3183 break;
3184 case 6:
3185 drawQuad(frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
3186 frags[c1s + 4], frags[c1s + 5]);
3187 if (draw_id) {
3188 curve = [frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
3189 frags[c1s + 4], frags[c1s + 5]];
3190 id = idByCurve(test, curve, PATH_QUAD);
3191 }
3192 break;
caryclark1049f122015-04-20 08:31:59 -07003193 case 7:
3194 drawConicWithQuads(frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
3195 frags[c1s + 4], frags[c1s + 5], frags[c1s + 6]);
3196 if (draw_id) {
3197 curve = [frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
3198 frags[c1s + 4], frags[c1s + 5], frags[c1s + 6]];
3199 id = idByCurve(test, curve, PATH_CONIC);
3200 }
3201 break;
caryclarkdac1d172014-06-17 05:15:38 -07003202 case 8:
3203 drawCubic(frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
3204 frags[c1s + 4], frags[c1s + 5], frags[c1s + 6], frags[c1s + 7]);
3205 if (draw_id) {
3206 curve = [frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
3207 frags[c1s + 4], frags[c1s + 5], frags[c1s + 6], frags[c1s + 7]];
3208 id = idByCurve(test, curve, PATH_CUBIC);
3209 }
3210 break;
3211 }
3212 if (id >= 0) {
3213 drawID(curve, id);
3214 }
3215 id = -1;
3216 switch (c2l) {
3217 case 0:
3218 break;
caryclark55888e42016-07-18 10:01:36 -07003219 case 4:
caryclarkdac1d172014-06-17 05:15:38 -07003220 drawLine(frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3]);
3221 if (draw_id) {
3222 curve = [frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3]];
3223 id = idByCurve(test, curve, PATH_LINE);
3224 }
3225 break;
3226 case 6:
3227 drawQuad(frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
3228 frags[c2s + 4], frags[c2s + 5]);
3229 if (draw_id) {
3230 curve = [frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
3231 frags[c2s + 4], frags[c2s + 5]];
3232 id = idByCurve(test, curve, PATH_QUAD);
3233 }
3234 break;
caryclark1049f122015-04-20 08:31:59 -07003235 case 7:
3236 drawConicWithQuads(frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
3237 frags[c2s + 4], frags[c2s + 5], frags[c2s + 6]);
3238 if (draw_id) {
3239 curve = [frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
3240 frags[c2s + 4], frags[c2s + 5], frags[c2s + 6]];
3241 id = idByCurve(test, curve, PATH_CONIC);
3242 }
3243 break;
caryclarkdac1d172014-06-17 05:15:38 -07003244 case 8:
3245 drawCubic(frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
3246 frags[c2s + 4], frags[c2s + 5], frags[c2s + 6], frags[c2s + 7]);
3247 if (draw_id) {
3248 curve = [frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
3249 frags[c2s + 4], frags[c2s + 5], frags[c2s + 6], frags[c2s + 7]];
3250 id = idByCurve(test, curve, PATH_CUBIC);
3251 }
3252 break;
3253 }
3254 if (id >= 0) {
3255 drawID(curve, id);
3256 }
3257 }
3258 if (collect_bounds) {
3259 break;
3260 }
caryclark54359292015-03-26 07:52:43 -07003261 if (draw_intersection != 3 || step_limit == 0 || tIndex >= lastSect) {
3262 for (var idx = 0; idx < f.length; idx += 4) {
caryclarkdac1d172014-06-17 05:15:38 -07003263 drawPoint(frags[f[idx]], frags[f[idx + 1]], true);
3264 }
3265 }
3266 if (!draw_intersectT) {
3267 break;
3268 }
3269 ctx.fillStyle = "red";
caryclark54359292015-03-26 07:52:43 -07003270 if (draw_intersection != 3 || step_limit == 0 || tIndex >= lastSect) {
3271 for (var idx = 0; idx < f.length; idx += 4) {
caryclarkdac1d172014-06-17 05:15:38 -07003272 drawTAtPointUp(frags[f[idx]], frags[f[idx + 1]], frags[f[idx + 2]]);
3273 drawTAtPointDown(frags[f[idx]], frags[f[idx + 1]], frags[f[idx + 3]]);
3274 }
3275 }
3276 break;
3277 case REC_TYPE_SORT:
3278 if (!draw_sort || (step_limit > 0 && tIndex < lastSort)) {
3279 continue;
3280 }
3281 ctx.lineWidth = 3;
3282 ctx.strokeStyle = "rgba(127,127,0, 0.5)";
3283 focus_enabled = true;
3284 switch (fragType) {
3285 case SORT_UNARY:
3286 case SORT_BINARY:
3287 var curve = curvePartialByID(test, frags[0], frags[6], frags[8]);
3288 drawCurve(curve);
3289 break;
3290 default:
3291 console.log("unknown REC_TYPE_SORT frag type: " + fragType);
3292 throw "stop execution";
3293 }
3294 break;
caryclark03b03ca2015-04-23 09:13:37 -07003295 case REC_TYPE_TOP:
3296 if (!draw_top || (step_limit > 0 && tIndex < lastTop)) {
3297 continue;
3298 }
3299 ctx.lineWidth = 3;
3300 ctx.strokeStyle = "rgba(127,127,0, 0.5)";
3301 focus_enabled = true;
3302 {
3303 var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
3304 drawCurve(curve);
3305 var type = PATH_LINE + (curve.length / 2 - 2);
3306 var mid = pointAtT(curve, type, 0.5);
3307 var d = dxy_at_t(curve, type, 0.5);
3308 drawArrow(mid.x, mid.y, d.x, d.y, 0.3);
3309 }
3310 break;
caryclarkdac1d172014-06-17 05:15:38 -07003311 case REC_TYPE_MARK:
3312 if (!draw_mark || (step_limit > 0 && tIndex < lastMark)) {
3313 continue;
3314 }
3315 ctx.lineWidth = 3;
3316 ctx.strokeStyle = fragType >= MARK_DONE_LINE ?
3317 "rgba(127,0,127, 0.5)" : "rgba(127,127,0, 0.5)";
3318 focus_enabled = true;
3319 switch (fragType) {
3320 case MARK_LINE:
3321 case MARK_DONE_LINE:
3322 case MARK_UNSORTABLE_LINE:
3323 case MARK_SIMPLE_LINE:
3324 case MARK_SIMPLE_DONE_LINE:
3325 case MARK_DONE_UNARY_LINE:
3326 drawLinePartial(frags[1], frags[2], frags[3], frags[4],
3327 frags[5], frags[9]);
3328 if (draw_id) {
3329 drawLinePartialID(frags[0], frags[1], frags[2], frags[3], frags[4],
3330 frags[5], frags[9]);
3331 }
3332 break;
3333 case MARK_QUAD:
3334 case MARK_DONE_QUAD:
3335 case MARK_UNSORTABLE_QUAD:
3336 case MARK_SIMPLE_QUAD:
3337 case MARK_SIMPLE_DONE_QUAD:
3338 case MARK_DONE_UNARY_QUAD:
3339 drawQuadPartial(frags[1], frags[2], frags[3], frags[4],
3340 frags[5], frags[6], frags[7], frags[11]);
3341 if (draw_id) {
3342 drawQuadPartialID(frags[0], frags[1], frags[2], frags[3], frags[4],
3343 frags[5], frags[6], frags[7], frags[11]);
3344 }
3345 break;
3346 case MARK_CUBIC:
3347 case MARK_DONE_CUBIC:
3348 case MARK_UNSORTABLE_CUBIC:
3349 case MARK_SIMPLE_CUBIC:
3350 case MARK_SIMPLE_DONE_CUBIC:
3351 case MARK_DONE_UNARY_CUBIC:
3352 drawCubicPartial(frags[1], frags[2], frags[3], frags[4],
3353 frags[5], frags[6], frags[7], frags[8], frags[9], frags[13]);
3354 if (draw_id) {
3355 drawCubicPartialID(frags[0], frags[1], frags[2], frags[3], frags[4],
3356 frags[5], frags[6], frags[7], frags[8], frags[9], frags[13]);
3357 }
3358 break;
3359 case MARK_ANGLE_LAST:
3360 // FIXME: ignored for now
3361 break;
3362 default:
3363 console.log("unknown REC_TYPE_MARK frag type: " + fragType);
3364 throw "stop execution";
3365 }
3366 break;
3367 default:
3368 continue;
3369 }
3370 }
3371 switch (recType) {
3372 case REC_TYPE_SORT:
3373 if (!draw_sort || (step_limit > 0 && tIndex < lastSort)) {
3374 break;
3375 }
3376 var angles = []; // use tangent lines to describe arcs
3377 var windFrom = [];
3378 var windTo = [];
3379 var opp = [];
3380 var minXY = Number.MAX_VALUE;
3381 var partial;
3382 focus_enabled = true;
3383 var someUnsortable = false;
3384 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
3385 var fragType = records[recordIndex];
3386 var frags = records[recordIndex + 1];
3387 var unsortable = (fragType == SORT_UNARY && frags[14]) ||
3388 (fragType == SORT_BINARY && frags[16]);
3389 someUnsortable |= unsortable;
3390 switch (fragType) {
3391 case SORT_UNARY:
3392 case SORT_BINARY:
3393 partial = curvePartialByID(test, frags[0], frags[6], frags[8]);
3394 break;
3395 default:
3396 console.log("unknown REC_TYPE_SORT frag type: " + fragType);
3397 throw "stop execution";
3398 }
3399 var dx = boundsWidth(partial);
3400 var dy = boundsHeight(partial);
3401 minXY = Math.min(minXY, dx * dx + dy * dy);
3402 if (collect_bounds) {
3403 continue;
3404 }
3405 angles.push(tangent(partial));
3406 var from = frags[12];
3407 var to = frags[12];
3408 var sgn = frags[10];
3409 if (sgn < 0) {
3410 from -= frags[11];
3411 } else if (sgn > 0) {
3412 to -= frags[11];
3413 }
3414 windFrom.push(from + (unsortable ? "!" : ""));
3415 windTo.push(to + (unsortable ? "!" : ""));
3416 opp.push(fragType == SORT_BINARY);
3417 if (draw_sort == 1) {
3418 drawOrder(partial, frags[12]);
3419 } else {
3420 drawOrder(partial, (recordIndex / 2) + 1);
3421 }
3422 }
3423 var radius = Math.sqrt(minXY) / 2 * scale;
3424 radius = Math.min(50, radius);
3425 var scaledRadius = radius / scale;
3426 var centerX = partial[0];
3427 var centerY = partial[1];
3428 if (collect_bounds) {
3429 if (focus_enabled) {
3430 focusXmin = Math.min(focusXmin, centerX - scaledRadius);
3431 focusYmin = Math.min(focusYmin, centerY - scaledRadius);
3432 focusXmax = Math.max(focusXmax, centerX + scaledRadius);
3433 focusYmax = Math.max(focusYmax, centerY + scaledRadius);
3434 }
3435 break;
3436 }
3437 break;
3438 default:
3439 break;
3440 }
3441 }
3442 if (collect_bounds) {
3443 return;
3444 }
3445 if (draw_log && logStart >= 0) {
3446 ctx.font = "normal 10px Arial";
3447 ctx.textAlign = "left";
3448 ctx.beginPath();
3449 var top = screenHeight - 20 - (logRange + 2) * 10;
3450 ctx.rect(50, top, screenWidth - 100, (logRange + 2) * 10);
3451 ctx.fillStyle = "white";
3452 ctx.fill();
3453 ctx.fillStyle = "rgba(0,0,0, 0.5)";
3454 if (logStart > 0) {
3455 ctx.fillText(lines[logStart - 1], 50, top + 8);
3456 }
3457 ctx.fillStyle = "black";
3458 for (var idx = 0; idx < logRange; ++idx) {
3459 ctx.fillText(lines[logStart + idx], 50, top + 18 + 10 * idx);
3460 }
3461 ctx.fillStyle = "rgba(0,0,0, 0.5)";
3462 if (logStart + logRange < lines.length) {
3463 ctx.fillText(lines[logStart + logRange], 50, top + 18 + 10 * logRange);
3464 }
3465 }
3466 if (draw_legend) {
3467 var pos = 0;
caryclark624637c2015-05-11 07:21:27 -07003468 var drawSomething = draw_add | draw_active | draw_angle | draw_coincidence | draw_sort | draw_mark;
caryclarkdac1d172014-06-17 05:15:38 -07003469 // drawBox(pos++, "yellow", "black", opLetter, true, '');
3470 drawBox(pos++, "rgba(0,0,255, 0.3)", "black", draw_intersection > 1 ? sectCount : sectMax2, draw_intersection, intersectionKey);
3471 drawBox(pos++, "rgba(0,0,255, 0.3)", "black", draw_add ? addCount : addMax, draw_add, addKey);
3472 drawBox(pos++, "rgba(0,0,255, 0.3)", "black", draw_active ? activeCount : activeMax, draw_active, activeKey);
3473 drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_angle ? angleCount : angleMax, draw_angle, angleKey);
caryclark624637c2015-05-11 07:21:27 -07003474 drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_coincidence ? coinCount : coinMax, draw_coincidence, coincidenceKey);
caryclarkdac1d172014-06-17 05:15:38 -07003475 drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_op ? opCount : opMax, draw_op, opKey);
3476 drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_sort ? sortCount : sortMax, draw_sort, sortKey);
caryclark03b03ca2015-04-23 09:13:37 -07003477 drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_top ? topCount : topMax, draw_top, topKey);
caryclarkdac1d172014-06-17 05:15:38 -07003478 drawBox(pos++, "rgba(127,0,127, 0.3)", "black", draw_mark ? markCount : markMax, draw_mark, markKey);
caryclark55888e42016-07-18 10:01:36 -07003479 drawBox(pos++, "black", "white",
caryclark26ad22a2015-10-16 09:03:38 -07003480 (new Array('P', 'P1', 'P2', 'P', 'p', 'p1', 'p2'))[draw_path], draw_path != 0, pathKey);
caryclarkdac1d172014-06-17 05:15:38 -07003481 drawBox(pos++, "rgba(0,63,0, 0.7)", "white",
3482 (new Array('Q', 'Q', 'C', 'QC', 'Qc', 'Cq'))[draw_computed],
3483 draw_computed != 0, computedKey);
3484 drawBox(pos++, "green", "black", step_limit, drawSomething, '');
3485 drawBox(pos++, "green", "black", stepMax, drawSomething, '');
3486 drawBox(pos++, "rgba(255,0,0, 0.6)", "black", lastIndex, drawSomething & draw_log, '');
3487 drawBox(pos++, "rgba(255,0,0, 0.6)", "black", test.length - 1, drawSomething & draw_log, '');
3488 if (curve_t) {
3489 drawCurveTControl();
3490 }
3491 ctx.font = "normal 20px Arial";
3492 ctx.fillStyle = "rgba(0,0,0, 0.3)";
3493 ctx.textAlign = "right";
3494 ctx.fillText(scale.toFixed(decimal_places) + 'x' , screenWidth - 10, screenHeight - 5);
3495 }
3496 if (draw_hints) {
3497 ctx.font = "normal 10px Arial";
3498 ctx.fillStyle = "rgba(0,0,0, 0.5)";
3499 ctx.textAlign = "right";
3500 var y = 4;
3501 ctx.fillText("control lines : " + controlLinesKey, ctx.screenWidthwidth - 10, pos * 50 + y++ * 10);
3502 ctx.fillText("curve t : " + curveTKey, screenWidth - 10, pos * 50 + y++ * 10);
3503 ctx.fillText("deriviatives : " + deriviativesKey, screenWidth - 10, pos * 50 + y++ * 10);
3504 ctx.fillText("intersect t : " + intersectTKey, screenWidth - 10, pos * 50 + y++ * 10);
caryclarkdac1d172014-06-17 05:15:38 -07003505 ctx.fillText("log : " + logKey, screenWidth - 10, pos * 50 + y++ * 10);
3506 ctx.fillText("log curve : " + logCurvesKey, screenWidth - 10, pos * 50 + y++ * 10);
3507 ctx.fillText("mid point : " + midpointKey, screenWidth - 10, pos * 50 + y++ * 10);
3508 ctx.fillText("points : " + ptsKey, screenWidth - 10, pos * 50 + y++ * 10);
3509 ctx.fillText("sequence : " + sequenceKey, screenWidth - 10, pos * 50 + y++ * 10);
3510 ctx.fillText("xy : " + xyKey, screenWidth - 10, pos * 50 + y++ * 10);
3511 }
3512}
3513
3514function drawBox(y, backC, foreC, str, enable, label) {
3515 ctx.beginPath();
3516 ctx.fillStyle = backC;
3517 ctx.rect(screenWidth - 40, y * 50 + 10, 40, 30);
3518 ctx.fill();
3519 ctx.font = "normal 16px Arial";
3520 ctx.fillStyle = foreC;
3521 ctx.textAlign = "center";
3522 ctx.fillText(str, screenWidth - 20, y * 50 + 32);
3523 if (!enable) {
3524 ctx.fillStyle = "rgba(255,255,255, 0.5)";
3525 ctx.fill();
3526 }
3527 if (label != '') {
3528 ctx.font = "normal 9px Arial";
3529 ctx.fillStyle = "black";
3530 ctx.fillText(label, screenWidth - 47, y * 50 + 40);
3531 }
3532}
3533
3534function drawCurveTControl() {
3535 ctx.lineWidth = 2;
3536 ctx.strokeStyle = "rgba(0,0,0, 0.3)";
3537 ctx.beginPath();
3538 ctx.rect(screenWidth - 80, 40, 28, screenHeight - 80);
3539 ctx.stroke();
3540 var ty = 40 + curveT * (screenHeight - 80);
3541 ctx.beginPath();
3542 ctx.moveTo(screenWidth - 80, ty);
3543 ctx.lineTo(screenWidth - 85, ty - 5);
3544 ctx.lineTo(screenWidth - 85, ty + 5);
3545 ctx.lineTo(screenWidth - 80, ty);
3546 ctx.fillStyle = "rgba(0,0,0, 0.6)";
3547 ctx.fill();
3548 var num = curveT.toFixed(decimal_places);
3549 ctx.font = "normal 10px Arial";
3550 ctx.textAlign = "left";
3551 ctx.fillText(num, screenWidth - 78, ty);
3552}
3553
3554function ptInTControl() {
3555 var e = window.event;
caryclark55888e42016-07-18 10:01:36 -07003556 var tgt = e.target || e.srcElement;
caryclarkdac1d172014-06-17 05:15:38 -07003557 var left = tgt.offsetLeft;
3558 var top = tgt.offsetTop;
3559 var x = (e.clientX - left);
3560 var y = (e.clientY - top);
3561 if (x < screenWidth - 80 || x > screenWidth - 50) {
3562 return false;
3563 }
3564 if (y < 40 || y > screenHeight - 80) {
3565 return false;
3566 }
3567 curveT = (y - 40) / (screenHeight - 120);
3568 if (curveT < 0 || curveT > 1) {
3569 throw "stop execution";
3570 }
3571 return true;
3572}
3573
3574function drawTop() {
3575 if (tests[testIndex] == null) {
3576 var str = testDivs[testIndex].textContent;
3577 parse_all(str);
3578 var title = testDivs[testIndex].id.toString();
3579 testTitles[testIndex] = title;
3580 }
3581 init(tests[testIndex]);
3582 redraw();
3583}
3584
3585function redraw() {
3586 if (focus_on_selection) {
3587 collect_bounds = true;
3588 draw(tests[testIndex], testLines[testIndex], testTitles[testIndex]);
3589 collect_bounds = false;
3590 if (focusXmin < focusXmax && focusYmin < focusYmax) {
3591 setScale(focusXmin, focusXmax, focusYmin, focusYmax);
3592 }
3593 }
3594 ctx.beginPath();
3595 ctx.fillStyle = "white";
3596 ctx.rect(0, 0, screenWidth, screenHeight);
3597 ctx.fill();
3598 draw(tests[testIndex], testLines[testIndex], testTitles[testIndex]);
3599}
3600
3601function dumpCurvePartial(test, id, t0, t1) {
3602 var curve = curveByID(test, id);
3603 var name = ["line", "quad", "cubic"][curve.length / 2 - 2];
3604 console.log("id=" + id + " " + name + "=" + curveToString(curve)
3605 + " t0=" + t0 + " t1=" + t1
3606 + " partial=" + curveToString(curvePartialByID(test, id, t0, t1)));
3607}
3608
3609function dumpAngleTest(test, id, t0, t1) {
3610 var curve = curveByID(test, id);
caryclark55888e42016-07-18 10:01:36 -07003611 console.log(" { {" + curveToString(curve) + "}, "
caryclarkdac1d172014-06-17 05:15:38 -07003612 + curve.length / 2 + ", " + t0 + ", " + t1 + ", {} }, //");
3613}
3614
3615function dumpLogToConsole() {
3616 if (logStart < 0) {
3617 return;
3618 }
3619 var test = tests[testIndex];
3620 var recType = REC_TYPE_UNKNOWN;
3621 var records;
3622 for (var index = 0; index < test.length; index += 3) {
3623 var lastLineNo = test[index + 1];
3624 if (lastLineNo >= logStart && lastLineNo < logStart + logRange) {
3625 recType = test[index];
3626 records = test[index + 2];
3627 break;
3628 }
3629 }
3630 if (recType == REC_TYPE_UNKNOWN) {
3631 return;
3632 }
3633 var lines = testLines[testIndex];
3634 for (var idx = 0; idx < logRange; ++idx) {
3635 var line = lines[logStart + idx];
3636 console.log(line);
3637 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
3638 var fragType = records[recordIndex];
3639 var frags = records[recordIndex + 1];
3640 if (recType == REC_TYPE_ANGLE && fragType == ANGLE_AFTER) {
caryclarkdac1d172014-06-17 05:15:38 -07003641 dumpCurvePartial(test, frags[0], frags[4], frags[5]);
3642 dumpCurvePartial(test, frags[6], frags[10], frags[11]);
3643 dumpCurvePartial(test, frags[12], frags[16], frags[17]);
3644 console.log("\nstatic IntersectData intersectDataSet[] = { //");
3645 dumpAngleTest(test, frags[0], frags[4], frags[5]);
3646 dumpAngleTest(test, frags[6], frags[10], frags[11]);
3647 dumpAngleTest(test, frags[12], frags[16], frags[17]);
3648 console.log("}; //");
3649 }
3650 }
3651 }
3652}
3653
3654var activeKey = 'a';
3655var pathKey = 'b';
3656var pathBackKey = 'B';
3657var centerKey = 'c';
caryclark624637c2015-05-11 07:21:27 -07003658var coincidenceKey = 'C';
caryclarkdac1d172014-06-17 05:15:38 -07003659var addKey = 'd';
3660var deriviativesKey = 'f';
3661var angleKey = 'g';
3662var angleBackKey = 'G';
caryclarkdac1d172014-06-17 05:15:38 -07003663var intersectionKey = 'i';
3664var intersectionBackKey = 'I';
3665var sequenceKey = 'j';
3666var midpointKey = 'k';
3667var logKey = 'l';
3668var logToConsoleKey = 'L';
3669var markKey = 'm';
3670var sortKey = 'o';
3671var opKey = 'p';
3672var opBackKey = 'P';
3673var computedKey = 'q';
3674var computedBackKey = 'Q';
3675var stepKey = 's';
3676var stepBackKey = 'S';
3677var intersectTKey = 't';
caryclark03b03ca2015-04-23 09:13:37 -07003678var topKey = 'T';
caryclarkdac1d172014-06-17 05:15:38 -07003679var curveTKey = 'u';
3680var controlLinesBackKey = 'V';
3681var controlLinesKey = 'v';
3682var ptsKey = 'x';
3683var xyKey = 'y';
3684var logCurvesKey = 'z';
3685var focusKey = '`';
3686var idKey = '.';
3687var retinaKey = '\\';
3688
3689function doKeyPress(evt) {
3690 var char = String.fromCharCode(evt.charCode);
3691 var focusWasOn = false;
3692 switch (char) {
3693 case '0':
3694 case '1':
3695 case '2':
3696 case '3':
3697 case '4':
3698 case '5':
3699 case '6':
3700 case '7':
3701 case '8':
3702 case '9':
3703 decimal_places = char - '0';
3704 redraw();
3705 break;
3706 case activeKey:
3707 draw_active ^= true;
caryclark55888e42016-07-18 10:01:36 -07003708 redraw();
caryclarkdac1d172014-06-17 05:15:38 -07003709 break;
3710 case addKey:
3711 draw_add ^= true;
caryclark55888e42016-07-18 10:01:36 -07003712 redraw();
caryclarkdac1d172014-06-17 05:15:38 -07003713 break;
3714 case angleKey:
caryclark54359292015-03-26 07:52:43 -07003715 draw_angle = (draw_angle + 1) % 4;
caryclarkdac1d172014-06-17 05:15:38 -07003716 redraw();
3717 break;
3718 case angleBackKey:
3719 draw_angle = (draw_angle + 2) % 3;
3720 redraw();
3721 break;
3722 case centerKey:
3723 setScale(xmin, xmax, ymin, ymax);
caryclark55888e42016-07-18 10:01:36 -07003724 redraw();
caryclarkdac1d172014-06-17 05:15:38 -07003725 break;
caryclark624637c2015-05-11 07:21:27 -07003726 case coincidenceKey:
3727 draw_coincidence ^= true;
3728 redraw();
3729 break;
caryclarkdac1d172014-06-17 05:15:38 -07003730 case controlLinesBackKey:
3731 control_lines = (control_lines + 3) % 4;
caryclark55888e42016-07-18 10:01:36 -07003732 redraw();
caryclarkdac1d172014-06-17 05:15:38 -07003733 break;
3734 case controlLinesKey:
3735 control_lines = (control_lines + 1) % 4;
caryclark55888e42016-07-18 10:01:36 -07003736 redraw();
caryclarkdac1d172014-06-17 05:15:38 -07003737 break;
3738 case computedBackKey:
3739 draw_computed = (draw_computed + 5) % 6;
caryclark55888e42016-07-18 10:01:36 -07003740 redraw();
caryclarkdac1d172014-06-17 05:15:38 -07003741 break;
3742 case computedKey:
3743 draw_computed = (draw_computed + 1) % 6;
caryclark55888e42016-07-18 10:01:36 -07003744 redraw();
caryclarkdac1d172014-06-17 05:15:38 -07003745 break;
3746 case curveTKey:
3747 curve_t ^= true;
3748 if (curve_t) {
3749 draw_legend = true;
3750 }
3751 redraw();
3752 break;
3753 case deriviativesKey:
3754 draw_deriviatives = (draw_deriviatives + 1) % 3;
3755 redraw();
3756 break;
3757 case focusKey:
3758 focus_on_selection ^= true;
3759 setScale(xmin, xmax, ymin, ymax);
3760 redraw();
3761 break;
caryclarkdac1d172014-06-17 05:15:38 -07003762 case idKey:
3763 draw_id ^= true;
3764 redraw();
3765 break;
3766 case intersectionBackKey:
3767 draw_intersection = (draw_intersection + 3) % 4;
caryclark55888e42016-07-18 10:01:36 -07003768 redraw();
caryclarkdac1d172014-06-17 05:15:38 -07003769 break;
3770 case intersectionKey:
3771 draw_intersection = (draw_intersection + 1) % 4;
caryclark55888e42016-07-18 10:01:36 -07003772 redraw();
caryclarkdac1d172014-06-17 05:15:38 -07003773 break;
3774 case intersectTKey:
3775 draw_intersectT ^= true;
3776 redraw();
3777 break;
3778 case logCurvesKey:
3779 logCurves(tests[testIndex]);
3780 break;
3781 case logKey:
3782 draw_log ^= true;
3783 redraw();
3784 break;
3785 case logToConsoleKey:
3786 if (draw_log) {
3787 dumpLogToConsole();
3788 }
3789 break;
3790 case markKey:
3791 draw_mark ^= true;
3792 redraw();
3793 break;
3794 case midpointKey:
3795 draw_midpoint ^= true;
3796 redraw();
3797 break;
3798 case opKey:
3799 draw_op = (draw_op + 1) % 3;
3800 redraw();
3801 break;
3802 case opBackKey:
3803 draw_op = (draw_op + 2) % 3;
3804 redraw();
3805 break;
3806 case pathKey:
caryclark26ad22a2015-10-16 09:03:38 -07003807 draw_path = (draw_path + 1) % (4 + (hasAlignedPath ? 3 : 0));
caryclark55888e42016-07-18 10:01:36 -07003808 redraw();
caryclarkdac1d172014-06-17 05:15:38 -07003809 break;
3810 case pathBackKey:
caryclark26ad22a2015-10-16 09:03:38 -07003811 draw_path = (draw_path + 3 + (hasAlignedPath ? 3 : 0)) % (4 + (hasAlignedPath ? 3 : 0));
caryclark55888e42016-07-18 10:01:36 -07003812 redraw();
caryclarkdac1d172014-06-17 05:15:38 -07003813 break;
3814 case ptsKey:
3815 pt_labels = (pt_labels + 1) % 3;
3816 redraw();
3817 break;
3818 case retinaKey:
3819 retina_scale ^= true;
3820 drawTop();
3821 break;
3822 case sequenceKey:
3823 draw_sequence ^= true;
3824 redraw();
3825 break;
3826 case sortKey:
3827 draw_sort = (draw_sort + 1) % 3;
3828 drawTop();
3829 break;
3830 case stepKey:
3831 step_limit++;
3832 if (step_limit > stepMax) {
3833 step_limit = stepMax;
3834 }
3835 redraw();
3836 break;
3837 case stepBackKey:
3838 step_limit--;
3839 if (step_limit < 0) {
3840 step_limit = 0;
3841 }
3842 redraw();
3843 break;
caryclark03b03ca2015-04-23 09:13:37 -07003844 case topKey:
3845 draw_top ^= true;
3846 redraw();
3847 break;
caryclarkdac1d172014-06-17 05:15:38 -07003848 case xyKey:
3849 debug_xy = (debug_xy + 1) % 3;
3850 redraw();
3851 break;
3852 case '-':
3853 focusWasOn = focus_on_selection;
3854 if (focusWasOn) {
3855 focus_on_selection = false;
3856 scale /= 1.2;
3857 } else {
3858 scale /= 2;
3859 calcLeftTop();
3860 }
3861 redraw();
3862 focus_on_selection = focusWasOn;
3863 break;
3864 case '=':
3865 case '+':
3866 focusWasOn = focus_on_selection;
3867 if (focusWasOn) {
3868 focus_on_selection = false;
3869 scale *= 1.2;
3870 } else {
3871 scale *= 2;
3872 calcLeftTop();
3873 }
3874 redraw();
3875 focus_on_selection = focusWasOn;
3876 break;
3877 case '?':
3878 draw_hints ^= true;
3879 if (draw_hints && !draw_legend) {
3880 draw_legend = true;
3881 }
3882 redraw();
3883 break;
3884 case '/':
3885 draw_legend ^= true;
3886 redraw();
3887 break;
3888 }
3889}
3890
3891function doKeyDown(evt) {
3892 var char = evt.keyCode;
3893 var preventDefault = false;
3894 switch (char) {
3895 case 37: // left arrow
3896 if (evt.shiftKey) {
3897 testIndex -= 9;
3898 }
3899 if (--testIndex < 0)
3900 testIndex = tests.length - 1;
3901 drawTop();
3902 preventDefault = true;
3903 break;
3904 case 39: // right arrow
3905 if (evt.shiftKey) {
3906 testIndex += 9;
3907 }
3908 if (++testIndex >= tests.length)
3909 testIndex = 0;
3910 drawTop();
3911 preventDefault = true;
3912 break;
3913 }
3914 if (preventDefault) {
3915 evt.preventDefault();
3916 return false;
3917 }
3918 return true;
3919}
3920
3921(function() {
3922 var hidden = "hidden";
3923
3924 // Standards:
3925 if (hidden in document)
3926 document.addEventListener("visibilitychange", onchange);
3927 else if ((hidden = "mozHidden") in document)
3928 document.addEventListener("mozvisibilitychange", onchange);
3929 else if ((hidden = "webkitHidden") in document)
3930 document.addEventListener("webkitvisibilitychange", onchange);
3931 else if ((hidden = "msHidden") in document)
3932 document.addEventListener("msvisibilitychange", onchange);
3933 // IE 9 and lower:
3934 else if ('onfocusin' in document)
3935 document.onfocusin = document.onfocusout = onchange;
3936 // All others:
3937 else
caryclark55888e42016-07-18 10:01:36 -07003938 window.onpageshow = window.onpagehide
caryclarkdac1d172014-06-17 05:15:38 -07003939 = window.onfocus = window.onblur = onchange;
3940
3941 function onchange (evt) {
3942 var v = 'visible', h = 'hidden',
caryclark55888e42016-07-18 10:01:36 -07003943 evtMap = {
3944 focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h
caryclarkdac1d172014-06-17 05:15:38 -07003945 };
3946
3947 evt = evt || window.event;
3948 if (evt.type in evtMap)
3949 document.body.className = evtMap[evt.type];
caryclark55888e42016-07-18 10:01:36 -07003950 else
caryclarkdac1d172014-06-17 05:15:38 -07003951 document.body.className = this[hidden] ? "hidden" : "visible";
3952 }
3953})();
3954
3955function calcXY() {
3956 var e = window.event;
caryclark55888e42016-07-18 10:01:36 -07003957 var tgt = e.target || e.srcElement;
caryclarkdac1d172014-06-17 05:15:38 -07003958 var left = tgt.offsetLeft;
3959 var top = tgt.offsetTop;
3960 mouseX = (e.clientX - left) / scale + srcLeft;
3961 mouseY = (e.clientY - top) / scale + srcTop;
3962}
3963
3964function calcLeftTop() {
3965 srcLeft = mouseX - screenWidth / 2 / scale;
3966 srcTop = mouseY - screenHeight / 2 / scale;
3967}
3968
3969var disableClick = false;
3970
3971function handleMouseClick() {
3972 if (disableClick) {
3973 return;
3974 }
3975 if (!curve_t || !ptInTControl()) {
3976 calcXY();
3977 calcLeftTop();
3978 }
3979 redraw();
3980// if (!curve_t || !ptInTControl()) {
3981// mouseX = screenWidth / 2 / scale + srcLeft;
3982// mouseY = screenHeight / 2 / scale + srcTop;
3983// }
3984}
3985
3986function handleMouseOver() {
3987 calcXY();
3988 if (debug_xy != 2) {
3989 return;
3990 }
3991 var num = mouseX.toFixed(decimal_places) + ", " + mouseY.toFixed(decimal_places);
3992 ctx.beginPath();
3993 ctx.rect(300,100,num.length * 6,10);
3994 ctx.fillStyle="white";
3995 ctx.fill();
3996 ctx.font = "normal 10px Arial";
3997 ctx.fillStyle="black";
3998 ctx.textAlign = "left";
3999 ctx.fillText(num, 300, 108);
4000}
4001
4002function start() {
4003 for (var i = 0; i < testDivs.length; ++i) {
4004 tests[i] = null;
4005 }
4006 testIndex = 0;
4007 drawTop();
4008 window.addEventListener('keypress', doKeyPress, true);
4009 window.addEventListener('keydown', doKeyDown, true);
4010 window.onresize = function() {
4011 drawTop();
4012 }
4013 /*
4014 window.onpagehide = function() {
4015 disableClick = true;
4016 }
4017 */
4018 window.onpageshow = function () {
4019 disableClick = false;
4020 }
4021}
4022
4023</script>
4024</head>
4025
4026<body onLoad="start();">
4027<canvas id="canvas" width="750" height="500"
4028 onmousemove="handleMouseOver()"
4029 onclick="handleMouseClick()"
4030 ></canvas >
4031</body>
4032</html>