blob: 7c109ee3e1c8ce47cc91723a4b38787c43b9ca96 [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
caryclark19eb3b22014-07-18 05:08:14 -07005<div id="issue2753">
6 RunTestSet [issue2753]
caryclarkdac1d172014-06-17 05:15:38 -07007
caryclark19eb3b22014-07-18 05:08:14 -07008{{142.701004,110.568001}, {142.957001,100}},
9{{142.957001,100}, {153.835007,100}},
10{{153.835007,100}, {154.591995,108.188004}},
11{{154.591995,108.188004}, {154.591995,108.188004}, {153.173004,108.483002}, {152.830002,109.412003}},
12{{152.830002,109.412003}, {152.830002,109.412003}, {142.701004,110.568001}, {142.701004,110.568001}},
13op union
14{{39,124.000999}, {39,124.000999}, {50.5999985,117.000999}, {50.5999985,117.000999}},
15{{50.5999985,117.000999}, {50.5999985,117.000999}, {164.600998,85.1999969}, {188.201004,117.600998}},
16{{188.201004,117.600998}, {188.201004,117.600998}, {174.800995,93}, {39,124.000999}},
17debugShowCubicIntersection no self intersect {{154.591995,108.188004}, {154.591995,108.188004}, {153.173004,108.483002}, {152.830002,109.412003}}
18debugShowLineIntersection wtTs[0]=1 {{142.701004,110.568001}, {142.957001,100}} {{142.957001,100}} wnTs[0]=0 {{142.957001,100}, {153.835007,100}}
19debugShowLineIntersection wtTs[0]=0 {{142.701004,110.568001}, {142.957001,100}} {{142.701004,110.568001}} wnTs[0]=1 {{152.830002,109.412003}, {142.701004,110.568001}}
20debugShowLineIntersection wtTs[0]=0 {{153.835007,100}, {154.591995,108.188004}} {{153.835007,100}} wnTs[0]=1 {{142.957001,100}, {153.835007,100}}
21debugShowCubicLineIntersection wtTs[0]=0 {{154.591995,108.188004}, {154.591995,108.188004}, {153.173004,108.483002}, {152.830002,109.412003}} {{154.591995,108.188004}} wnTs[0]=1 {{153.835007,100}, {154.591995,108.188004}}
22debugShowCubicLineIntersection wtTs[0]=1 {{154.591995,108.188004}, {154.591995,108.188004}, {153.173004,108.483002}, {152.830002,109.412003}} {{152.830002,109.412003}} wnTs[0]=0 {{152.830002,109.412003}, {142.701004,110.568001}}
23debugShowCubicLineIntersection wtTs[0]=0.671281996 {{50.5999985,117.000999}, {50.5999985,117.000999}, {164.600998,85.1999969}, {188.201004,117.600998}} {{142.883102,103.050758}} wnTs[0]=0.711321 {{142.701004,110.568001}, {142.957001,100}}
24debugShowCubicLineIntersection wtTs[0]=0.642192755 {{188.201004,117.600998}, {188.201004,117.600998}, {174.800995,93}, {39,124.000999}} {{142.753387,108.405373}} wnTs[0]=0.204639 {{142.701004,110.568001}, {142.957001,100}}
25debugShowCubicLineIntersection wtTs[0]=0.734814757 {{50.5999985,117.000999}, {50.5999985,117.000999}, {164.600998,85.1999969}, {188.201004,117.600998}} {{154.165848,103.578537}} wnTs[0]=0.437047 {{153.835007,100}, {154.591995,108.188004}}
26debugShowCubicIntersection no intersect {{154.591995,108.188004}, {154.591995,108.188004}, {153.173004,108.483002}, {152.830002,109.412003}} {{50.5999985,117.000999}, {50.5999985,117.000999}, {164.600998,85.1999969}, {188.201004,117.600998}}
27debugShowCubicIntersection no intersect {{154.591995,108.188004}, {154.591995,108.188004}, {153.173004,108.483002}, {152.830002,109.412003}} {{188.201004,117.600998}, {188.201004,117.600998}, {174.800995,93}, {39,124.000999}}
28debugShowCubicLineIntersection no intersect {{50.5999985,117.000999}, {50.5999985,117.000999}, {164.600998,85.1999969}, {188.201004,117.600998}} {{152.830002,109.412003}, {142.701004,110.568001}}
29debugShowCubicLineIntersection no intersect {{188.201004,117.600998}, {188.201004,117.600998}, {174.800995,93}, {39,124.000999}} {{152.830002,109.412003}, {142.701004,110.568001}}
30debugShowCubicIntersection no self intersect {{50.5999985,117.000999}, {50.5999985,117.000999}, {164.600998,85.1999969}, {188.201004,117.600998}}
31debugShowCubicIntersection no self intersect {{188.201004,117.600998}, {188.201004,117.600998}, {174.800995,93}, {39,124.000999}}
32debugShowCubicLineIntersection wtTs[0]=0 {{50.5999985,117.000999}, {50.5999985,117.000999}, {164.600998,85.1999969}, {188.201004,117.600998}} {{50.5999985,117.000999}} wnTs[0]=1 {{39,124.000999}, {50.5999985,117.000999}}
33debugShowCubicLineIntersection wtTs[0]=1 {{188.201004,117.600998}, {188.201004,117.600998}, {174.800995,93}, {39,124.000999}} {{39,124.000999}} wnTs[0]=0 {{39,124.000999}, {50.5999985,117.000999}}
34debugShowCubicIntersection wtTs[0]=1 {{50.5999985,117.000999}, {50.5999985,117.000999}, {164.600998,85.1999969}, {188.201004,117.600998}} {{188.201004,117.600998}} wnTs[0]=0 {{188.201004,117.600998}, {188.201004,117.600998}, {174.800995,93}, {39,124.000999}}
35SkOpSegment::sortAngles [0] tStart=0.204639461 [1]
36SkOpAngle::after [0/1] 21/21 tStart=0.204639461 tEnd=0 < [7/1] 1/29 tStart=0.642192755 tEnd=0 < [0/2] 5/5 tStart=0.204639461 tEnd=0.711321242 T 4
37SkOpAngle::after [0/1] 21/21 tStart=0.204639461 tEnd=0 < [7/2] 17/17 tStart=0.642192755 tEnd=1 < [7/1] 1/29 tStart=0.642192755 tEnd=0 F 4
38SkOpAngle::after [7/1] 1/29 tStart=0.642192755 tEnd=0 < [7/2] 17/17 tStart=0.642192755 tEnd=1 < [0/2] 5/5 tStart=0.204639461 tEnd=0.711321242 F 4
39SkOpAngle::after [0/2] 5/5 tStart=0.204639461 tEnd=0.711321242 < [7/2] 17/17 tStart=0.642192755 tEnd=1 < [0/1] 21/21 tStart=0.204639461 tEnd=0 T 4
40SkOpSegment::sortAngles [0] tStart=0.711321242 [2]
41SkOpAngle::after [0/3] 21/21 tStart=0.711321242 tEnd=0.204639461 < [6/1] 13/17 tStart=0.671281996 tEnd=0 < [0/4] 5/5 tStart=0.711321242 tEnd=1 F 4
42SkOpAngle::after [0/3] 21/21 tStart=0.711321242 tEnd=0.204639461 < [6/2] 29/29 tStart=0.671281996 tEnd=0.734814757 < [0/4] 5/5 tStart=0.711321242 tEnd=1 T 4
43SkOpSegment::sortAngles [2] tStart=0.437046747 [1]
44SkOpAngle::after [2/1] 9/9 tStart=0.437046747 tEnd=0 < [6/3] 13/13 tStart=0.734814757 tEnd=0.671281996 < [2/2] 25/25 tStart=0.437046747 tEnd=1 T 4
45SkOpAngle::after [2/1] 9/9 tStart=0.437046747 tEnd=0 < [6/4] 29/29 tStart=0.734814757 tEnd=1 < [6/3] 13/13 tStart=0.734814757 tEnd=0.671281996 F 4
46SkOpAngle::after [6/3] 13/13 tStart=0.734814757 tEnd=0.671281996 < [6/4] 29/29 tStart=0.734814757 tEnd=1 < [2/2] 25/25 tStart=0.437046747 tEnd=1 F 4
47SkOpAngle::after [2/2] 25/25 tStart=0.437046747 tEnd=1 < [6/4] 29/29 tStart=0.734814757 tEnd=1 < [2/1] 9/9 tStart=0.437046747 tEnd=0 T 4
48SkOpSegment::debugShowActiveSpans id=0 (142.701004,110.568001 142.957001,100) t=0 (142.701004,110.568001) tEnd=0.204639461 other=4 otherT=1 otherIndex=1 windSum=? windValue=1 oppValue=0
49SkOpSegment::debugShowActiveSpans id=0 (142.701004,110.568001 142.957001,100) t=0.204639461 (142.753387,108.405373) tEnd=0.711321242 other=7 otherT=0.642192755 otherIndex=1 windSum=? windValue=1 oppValue=0
50SkOpSegment::debugShowActiveSpans id=0 (142.701004,110.568001 142.957001,100) t=0.711321242 (142.883102,103.050758) tEnd=1 other=6 otherT=0.671281996 otherIndex=1 windSum=? windValue=1 oppValue=0
51SkOpSegment::debugShowActiveSpans id=1 (142.957001,100 153.835007,100) t=0 (142.957001,100) tEnd=1 other=0 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0
52SkOpSegment::debugShowActiveSpans id=2 (153.835007,100 154.591995,108.188004) t=0 (153.835007,100) tEnd=0.437046747 other=1 otherT=1 otherIndex=1 windSum=? windValue=1 oppValue=0
53SkOpSegment::debugShowActiveSpans id=2 (153.835007,100 154.591995,108.188004) t=0.437046747 (154.165848,103.578537) tEnd=1 other=6 otherT=0.734814757 otherIndex=2 windSum=? windValue=1 oppValue=0
54SkOpSegment::debugShowActiveSpans id=3 (154.591995,108.188004 154.591995,108.188004 153.173004,108.483002 152.830002,109.412003) t=0 (154.591995,108.188004) tEnd=1 other=2 otherT=1 otherIndex=2 windSum=? windValue=1 oppValue=0
55SkOpSegment::debugShowActiveSpans id=4 (152.830002,109.412003 142.701004,110.568001) t=0 (152.830002,109.412003) tEnd=1 other=3 otherT=1 otherIndex=1 windSum=? windValue=1 oppValue=0
56SkOpSegment::debugShowActiveSpans id=5 (39,124.000999 50.5999985,117.000999) t=0 (39,124.000999) tEnd=1 other=7 otherT=1 otherIndex=2 windSum=? windValue=1 oppValue=0
57SkOpSegment::debugShowActiveSpans id=6 (50.5999985,117.000999 50.5999985,117.000999 164.600998,85.1999969 188.201004,117.600998) t=0 (50.5999985,117.000999) tEnd=0.671281996 other=5 otherT=1 otherIndex=1 windSum=? windValue=1 oppValue=0
58SkOpSegment::debugShowActiveSpans id=6 (50.5999985,117.000999 50.5999985,117.000999 164.600998,85.1999969 188.201004,117.600998) t=0.671281996 (142.883102,103.050758) tEnd=0.734814757 other=0 otherT=0.711321242 otherIndex=2 windSum=? windValue=1 oppValue=0
59SkOpSegment::debugShowActiveSpans id=6 (50.5999985,117.000999 50.5999985,117.000999 164.600998,85.1999969 188.201004,117.600998) t=0.734814757 (154.165848,103.578537) tEnd=1 other=2 otherT=0.437046747 otherIndex=1 windSum=? windValue=1 oppValue=0
60SkOpSegment::debugShowActiveSpans id=7 (188.201004,117.600998 188.201004,117.600998 174.800995,93 39,124.000999) t=0 (188.201004,117.600998) tEnd=0.642192755 other=6 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0
61SkOpSegment::debugShowActiveSpans id=7 (188.201004,117.600998 188.201004,117.600998 174.800995,93 39,124.000999) t=0.642192755 (142.753387,108.405373) tEnd=1 other=0 otherT=0.204639461 otherIndex=1 windSum=? windValue=1 oppValue=0
62SkOpSegment::findTop
63SkOpAngle::dumpOne [0/5] next=1/1 sect=21/21 s=1 [3] e=0.711321242 [2] sgn=1 windVal=1 windSum=?
64SkOpAngle::dumpOne [1/1] next=0/5 sect=31/31 s=0 [0] e=1 [1] sgn=-1 windVal=1 windSum=? stop
65SkOpSegment::markWinding id=0 (142.701004,110.568001 142.957001,100) t=0.711321242 [2] (142.883102,103.050758) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
66SkOpSegment::nextChase mismatched signs
67SkOpSegment::markWinding id=1 (142.957001,100 153.835007,100) t=0 [0] (142.957001,100) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
68SkOpSegment::markWinding id=2 (153.835007,100 154.591995,108.188004) t=0 [0] (153.835007,100) tEnd=0.437046747 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
69SkOpSegment::markWinding id=0 (142.701004,110.568001 142.957001,100) t=0.711321242 [2] (142.883102,103.050758) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
70SkOpSegment::activeOp id=0 t=0.711321242 tEnd=1 op=union miFrom=1 miTo=0 suFrom=0 suTo=0 result=1
71SkOpSegment::nextChase mismatched signs
72SkOpSegment::findNextOp simple
73SkOpSegment::markDoneBinary id=0 (142.701004,110.568001 142.957001,100) t=0.711321242 [2] (142.883102,103.050758) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
74bridgeOp current id=0 from=(142.883102,103.050758) to=(142.957001,100)
75SkOpSegment::findNextOp simple
76SkOpSegment::markDoneBinary id=1 (142.957001,100 153.835007,100) t=0 [0] (142.957001,100) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
77bridgeOp current id=1 from=(142.957001,100) to=(153.835007,100)
78path.moveTo(142.883102,103.050758);
79path.lineTo(142.957001,100);
80SkOpSegment::markWinding id=6 (50.5999985,117.000999 50.5999985,117.000999 164.600998,85.1999969 188.201004,117.600998) t=0.671281996 [1] (142.883102,103.050758) tEnd=0.734814757 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1 oppValue=0
81SkOpSegment::markAngle last id=6 windSum=-1 small=0
82SkOpSegment::markWinding id=2 (153.835007,100 154.591995,108.188004) t=0.437046747 [1] (154.165848,103.578537) tEnd=1 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1 oppValue=0
83SkOpSegment::markWinding id=3 (154.591995,108.188004 154.591995,108.188004 153.173004,108.483002 152.830002,109.412003) t=0 [0] (154.591995,108.188004) tEnd=1 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1 oppValue=0
84SkOpSegment::markWinding id=4 (152.830002,109.412003 142.701004,110.568001) t=0 [0] (152.830002,109.412003) tEnd=1 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1 oppValue=0
85SkOpSegment::markWinding id=0 (142.701004,110.568001 142.957001,100) t=0 [0] (142.701004,110.568001) tEnd=0.204639461 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1 oppValue=0
86SkOpSegment::markAngle last id=0 windSum=? small=0
87SkOpSegment::markWinding id=6 (50.5999985,117.000999 50.5999985,117.000999 164.600998,85.1999969 188.201004,117.600998) t=0.734814757 [2] (154.165848,103.578537) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
88SkOpSegment::markWinding id=7 (188.201004,117.600998 188.201004,117.600998 174.800995,93 39,124.000999) t=0 [0] (188.201004,117.600998) tEnd=0.642192755 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 oppValue=0
89SkOpSegment::markAngle last id=7 windSum=? small=0
90SkOpSegment::findNextOp
91SkOpAngle::dumpOne [2/1] next=6/3 sect=9/9 s=0.437046747 [1] e=0 [0] sgn=1 windVal=1 windSum=-1 oppVal=0 oppSum=0
92SkOpAngle::dumpOne [6/3] next=2/2 sect=13/13 s=0.734814757 [2] e=0.671281996 [1] sgn=1 windVal=1 windSum=-1 oppVal=0 oppSum=-1 operand
93SkOpAngle::dumpOne [2/2] next=6/4 sect=25/25 s=0.437046747 [1] e=1 [2] sgn=-1 windVal=1 windSum=-1 oppVal=0 oppSum=-1
94SkOpAngle::dumpOne [6/4] next=2/1 sect=29/29 s=0.734814757 [2] e=1 [3] sgn=-1 windVal=1 windSum=-1 oppVal=0 oppSum=0 operand
95SkOpSegment::activeOp id=6 t=0.734814757 tEnd=0.671281996 op=union miFrom=1 miTo=1 suFrom=0 suTo=1 result=0
96SkOpSegment::markDoneBinary id=6 (50.5999985,117.000999 50.5999985,117.000999 164.600998,85.1999969 188.201004,117.600998) t=0.671281996 [1] (142.883102,103.050758) tEnd=0.734814757 newWindSum=-1 newOppSum=-1 oppSum=-1 windSum=-1 windValue=1 oppValue=0
97SkOpSegment::findNextOp chase.append id=6 windSum=-1 small=0
98SkOpSegment::activeOp id=2 t=0.437046747 tEnd=1 op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0
99SkOpSegment::markDoneBinary id=2 (153.835007,100 154.591995,108.188004) t=0.437046747 [1] (154.165848,103.578537) tEnd=1 newWindSum=-1 newOppSum=-1 oppSum=-1 windSum=-1 windValue=1 oppValue=0
100SkOpSegment::markDoneBinary id=3 (154.591995,108.188004 154.591995,108.188004 153.173004,108.483002 152.830002,109.412003) t=0 [0] (154.591995,108.188004) tEnd=1 newWindSum=-1 newOppSum=-1 oppSum=-1 windSum=-1 windValue=1 oppValue=0
101SkOpSegment::markDoneBinary id=4 (152.830002,109.412003 142.701004,110.568001) t=0 [0] (152.830002,109.412003) tEnd=1 newWindSum=-1 newOppSum=-1 oppSum=-1 windSum=-1 windValue=1 oppValue=0
102SkOpSegment::markDoneBinary id=0 (142.701004,110.568001 142.957001,100) t=0 [0] (142.701004,110.568001) tEnd=0.204639461 newWindSum=-1 newOppSum=-1 oppSum=-1 windSum=-1 windValue=1 oppValue=0
103SkOpSegment::findNextOp chase.append id=0 windSum=-2147483647 small=0
104SkOpSegment::activeOp id=6 t=0.734814757 tEnd=1 op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1
105SkOpSegment::findNextOp chase.append id=7 windSum=-2147483647 small=0
106SkOpSegment::markDoneBinary id=2 (153.835007,100 154.591995,108.188004) t=0 [0] (153.835007,100) tEnd=0.437046747 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
107SkOpSegment::findNextOp from:[2] to:[6] start=2 end=3
108bridgeOp current id=2 from=(153.835007,100) to=(154.165848,103.578537)
109path.lineTo(153.835007,100);
110SkOpSegment::findNextOp simple
111SkOpSegment::markDoneBinary id=6 (50.5999985,117.000999 50.5999985,117.000999 164.600998,85.1999969 188.201004,117.600998) t=0.734814757 [2] (154.165848,103.578537) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
112bridgeOp current id=6 from=(154.165848,103.578537) to=(188.201004,117.600998)
113path.lineTo(154.165848,103.578537);
114path.cubicTo(169.326965,104.931351, 181.942627,109.008728, 188.201004,117.600998);
115SkOpSegment::markWinding id=0 (142.701004,110.568001 142.957001,100) t=0.204639461 [1] (142.753387,108.405373) tEnd=0.711321242 newWindSum=1 newOppSum=-1 oppSum=? windSum=? windValue=1 oppValue=0
116SkOpSegment::markAngle last id=0 windSum=-1 small=0
117SkOpSegment::markWinding id=7 (188.201004,117.600998 188.201004,117.600998 174.800995,93 39,124.000999) t=0.642192755 [1] (142.753387,108.405373) tEnd=1 newWindSum=-1 newOppSum=1 oppSum=? windSum=? windValue=1 oppValue=0
118SkOpSegment::markWinding id=5 (39,124.000999 50.5999985,117.000999) t=0 [0] (39,124.000999) tEnd=1 newWindSum=-1 newOppSum=1 oppSum=? windSum=? windValue=1 oppValue=0
119SkOpSegment::markWinding id=6 (50.5999985,117.000999 50.5999985,117.000999 164.600998,85.1999969 188.201004,117.600998) t=0 [0] (50.5999985,117.000999) tEnd=0.671281996 newWindSum=-1 newOppSum=1 oppSum=? windSum=? windValue=1 oppValue=0
120SkOpSegment::markAngle last id=6 windSum=-1 small=0
121SkOpSegment::findNextOp
122SkOpAngle::dumpOne [7/1] next=0/2 sect=1/29 s=0.642192755 [1] e=0 [0] sgn=1 windVal=1 windSum=-1 oppVal=0 oppSum=0 operand
123SkOpAngle::dumpOne [0/2] next=7/2 sect=5/5 s=0.204639461 [1] e=0.711321242 [2] sgn=-1 windVal=1 windSum=1 oppVal=0 oppSum=-1
124SkOpAngle::dumpOne [7/2] next=0/1 sect=17/17 s=0.642192755 [1] e=1 [2] sgn=-1 windVal=1 windSum=-1 oppVal=0 oppSum=1 operand
125SkOpAngle::dumpOne [0/1] next=7/1 sect=21/21 s=0.204639461 [1] e=0 [0] sgn=1 windVal=1 windSum=-1 oppVal=0 oppSum=-1 done
126SkOpSegment::activeOp id=0 t=0.204639461 tEnd=0.711321242 op=union miFrom=0 miTo=1 suFrom=1 suTo=1 result=0
127SkOpSegment::markDoneBinary id=0 (142.701004,110.568001 142.957001,100) t=0.204639461 [1] (142.753387,108.405373) tEnd=0.711321242 newWindSum=1 newOppSum=-1 oppSum=-1 windSum=1 windValue=1 oppValue=0
128SkOpSegment::findNextOp chase.append id=0 windSum=-1 small=0
129SkOpSegment::activeOp id=7 t=0.642192755 tEnd=1 op=union miFrom=1 miTo=1 suFrom=1 suTo=0 result=0
130SkOpSegment::markDoneBinary id=7 (188.201004,117.600998 188.201004,117.600998 174.800995,93 39,124.000999) t=0.642192755 [1] (142.753387,108.405373) tEnd=1 newWindSum=-1 newOppSum=1 oppSum=1 windSum=-1 windValue=1 oppValue=0
131SkOpSegment::markDoneBinary id=5 (39,124.000999 50.5999985,117.000999) t=0 [0] (39,124.000999) tEnd=1 newWindSum=-1 newOppSum=1 oppSum=1 windSum=-1 windValue=1 oppValue=0
132SkOpSegment::markDoneBinary id=6 (50.5999985,117.000999 50.5999985,117.000999 164.600998,85.1999969 188.201004,117.600998) t=0 [0] (50.5999985,117.000999) tEnd=0.671281996 newWindSum=-1 newOppSum=1 oppSum=1 windSum=-1 windValue=1 oppValue=0
133SkOpSegment::activeOp id=0 t=0.204639461 tEnd=0 op=union miFrom=1 miTo=0 suFrom=0 suTo=0 result=1
134SkOpSegment::markDoneBinary id=7 (188.201004,117.600998 188.201004,117.600998 174.800995,93 39,124.000999) t=0 [0] (188.201004,117.600998) tEnd=0.642192755 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 oppValue=0
135SkOpSegment::findNextOp from:[7] to:[0] start=1 end=0
136bridgeOp current id=7 from=(188.201004,117.600998) to=(142.753387,108.405373)
137path.cubicTo(188.201004,117.600998, 182.674683,107.455261, 142.753387,108.405373);
caryclarkdac1d172014-06-17 05:15:38 -0700138</div>
139
140</div>
141
142<script type="text/javascript">
143
144var testDivs = [
caryclark19eb3b22014-07-18 05:08:14 -0700145 issue2753,
caryclarkdac1d172014-06-17 05:15:38 -0700146];
147
148var decimal_places = 3; // make this 3 to show more precision
149
150var tests = [];
151var testLines = [];
152var testTitles = [];
153var testIndex = 0;
154var ctx;
155
156var xmin, xmax, focusXmin, focusXmax;
157var ymin, ymax, focusYmin, focusYmax;
158var scale;
159var mouseX, mouseY;
160var srcLeft, srcTop;
161var screenWidth, screenHeight;
162var drawnPts, drawnLines, drawnQuads, drawnCubics;
163var curveT = 0;
164
165var pt_labels = 2;
166var collect_bounds = false;
167var control_lines = 0;
168var curve_t = false;
169var debug_xy = 1;
170var focus_enabled = false;
171var focus_on_selection = false;
172var step_limit = 0;
173var draw_active = false;
174var draw_add = false;
175var draw_angle = 0;
176var draw_deriviatives = 0;
177var draw_hints = false;
178var draw_hodo = 0;
179var draw_id = false;
180var draw_intersection = 0;
181var draw_intersectT = false;
182var draw_legend = true;
183var draw_log = false;
184var draw_mark = false;
185var draw_midpoint = false;
186var draw_op = 0;
187var draw_sequence = false;
188var draw_sort = 0;
189var draw_path = 3;
190var draw_computed = 0;
191var retina_scale = !!window.devicePixelRatio;
192
193var activeCount = 0;
194var addCount = 0;
195var angleCount = 0;
196var opCount = 0;
197var sectCount = 0;
198var sortCount = 0;
199var markCount = 0;
200var activeMax = 0;
201var addMax = 0;
202var angleMax = 0;
203var sectMax = 0;
204var sectMax2 = 0;
205var sortMax = 0;
206var markMax = 0;
207var opMax = 0;
208var stepMax = 0;
209var lastIndex = 0;
210var hasPath = false;
211var hasComputedPath = false;
212
213var firstActiveSpan = -1;
214var logStart = -1;
215var logRange = 0;
216
217var SPAN_ID = 0;
218var SPAN_X1 = SPAN_ID + 1;
219var SPAN_Y1 = SPAN_X1 + 1;
220var SPAN_X2 = SPAN_Y1 + 1;
221var SPAN_Y2 = SPAN_X2 + 1;
222var SPAN_L_T = SPAN_Y2 + 1;
223var SPAN_L_TX = SPAN_L_T + 1;
224var SPAN_L_TY = SPAN_L_TX + 1;
225var SPAN_L_TEND = SPAN_L_TY + 1;
226var SPAN_L_OTHER = SPAN_L_TEND + 1;
227var SPAN_L_OTHERT = SPAN_L_OTHER + 1;
228var SPAN_L_OTHERI = SPAN_L_OTHERT + 1;
229var SPAN_L_SUM = SPAN_L_OTHERI + 1;
230var SPAN_L_VAL = SPAN_L_SUM + 1;
231var SPAN_L_OPP = SPAN_L_VAL + 1;
232
233var SPAN_X3 = SPAN_Y2 + 1;
234var SPAN_Y3 = SPAN_X3 + 1;
235var SPAN_Q_T = SPAN_Y3 + 1;
236var SPAN_Q_TX = SPAN_Q_T + 1;
237var SPAN_Q_TY = SPAN_Q_TX + 1;
238var SPAN_Q_TEND = SPAN_Q_TY + 1;
239var SPAN_Q_OTHER = SPAN_Q_TEND + 1;
240var SPAN_Q_OTHERT = SPAN_Q_OTHER + 1;
241var SPAN_Q_OTHERI = SPAN_Q_OTHERT + 1;
242var SPAN_Q_SUM = SPAN_Q_OTHERI + 1;
243var SPAN_Q_VAL = SPAN_Q_SUM + 1;
244var SPAN_Q_OPP = SPAN_Q_VAL + 1;
245
246var SPAN_X4 = SPAN_Y3 + 1;
247var SPAN_Y4 = SPAN_X4 + 1;
248var SPAN_C_T = SPAN_Y4 + 1;
249var SPAN_C_TX = SPAN_C_T + 1;
250var SPAN_C_TY = SPAN_C_TX + 1;
251var SPAN_C_TEND = SPAN_C_TY + 1;
252var SPAN_C_OTHER = SPAN_C_TEND + 1;
253var SPAN_C_OTHERT = SPAN_C_OTHER + 1;
254var SPAN_C_OTHERI = SPAN_C_OTHERT + 1;
255var SPAN_C_SUM = SPAN_C_OTHERI + 1;
256var SPAN_C_VAL = SPAN_C_SUM + 1;
257var SPAN_C_OPP = SPAN_C_VAL + 1;
258
259var ACTIVE_LINE_SPAN = 1;
260var ACTIVE_QUAD_SPAN = ACTIVE_LINE_SPAN + 1;
261var ACTIVE_CUBIC_SPAN = ACTIVE_QUAD_SPAN + 1;
262
263var ADD_MOVETO = ACTIVE_CUBIC_SPAN + 1;
264var ADD_LINETO = ADD_MOVETO + 1;
265var ADD_QUADTO = ADD_LINETO + 1;
266var ADD_CUBICTO = ADD_QUADTO + 1;
267var ADD_CLOSE = ADD_CUBICTO + 1;
268var ADD_FILL = ADD_CLOSE + 1;
269
270var PATH_LINE = ADD_FILL + 1;
271var PATH_QUAD = PATH_LINE + 1;
272var PATH_CUBIC = PATH_QUAD + 1;
273
274var INTERSECT_LINE = PATH_CUBIC + 1;
275var INTERSECT_LINE_2 = INTERSECT_LINE + 1;
276var INTERSECT_LINE_NO = INTERSECT_LINE_2 + 1;
277var INTERSECT_QUAD_LINE = INTERSECT_LINE_NO + 1;
278var INTERSECT_QUAD_LINE_2 = INTERSECT_QUAD_LINE + 1;
279var INTERSECT_QUAD_LINE_NO = INTERSECT_QUAD_LINE_2 + 1;
280var INTERSECT_QUAD = INTERSECT_QUAD_LINE_NO + 1;
281var INTERSECT_QUAD_2 = INTERSECT_QUAD + 1;
282var INTERSECT_QUAD_NO = INTERSECT_QUAD_2 + 1;
283var INTERSECT_SELF_CUBIC = INTERSECT_QUAD_NO + 1;
284var INTERSECT_SELF_CUBIC_NO = INTERSECT_SELF_CUBIC + 1;
285var INTERSECT_CUBIC_LINE = INTERSECT_SELF_CUBIC_NO + 1;
286var INTERSECT_CUBIC_LINE_2 = INTERSECT_CUBIC_LINE + 1;
287var INTERSECT_CUBIC_LINE_3 = INTERSECT_CUBIC_LINE_2 + 1;
288var INTERSECT_CUBIC_LINE_NO = INTERSECT_CUBIC_LINE_3 + 1;
289var INTERSECT_CUBIC_QUAD = INTERSECT_CUBIC_LINE_NO + 1;
290var INTERSECT_CUBIC_QUAD_2 = INTERSECT_CUBIC_QUAD + 1;
291var INTERSECT_CUBIC_QUAD_3 = INTERSECT_CUBIC_QUAD_2 + 1;
292var INTERSECT_CUBIC_QUAD_4 = INTERSECT_CUBIC_QUAD_3 + 1;
293var INTERSECT_CUBIC_QUAD_NO = INTERSECT_CUBIC_QUAD_4 + 1;
294var INTERSECT_CUBIC = INTERSECT_CUBIC_QUAD_NO + 1;
295var INTERSECT_CUBIC_2 = INTERSECT_CUBIC + 1;
296var INTERSECT_CUBIC_3 = INTERSECT_CUBIC_2 + 1;
297var INTERSECT_CUBIC_4 = INTERSECT_CUBIC_3 + 1;
298// FIXME: add cubic 5- 9
299var INTERSECT_CUBIC_NO = INTERSECT_CUBIC_4 + 1;
300
301var SORT_UNARY = INTERSECT_CUBIC_NO + 1;
302var SORT_BINARY = SORT_UNARY + 1;
303
304var OP_DIFFERENCE = SORT_BINARY + 1;
305var OP_INTERSECT = OP_DIFFERENCE + 1;
306var OP_UNION = OP_INTERSECT + 1;
307var OP_XOR = OP_UNION + 1;
308
309var MARK_LINE = OP_XOR + 1;
310var MARK_QUAD = MARK_LINE + 1;
311var MARK_CUBIC = MARK_QUAD + 1;
312var MARK_DONE_LINE = MARK_CUBIC + 1;
313var MARK_DONE_QUAD = MARK_DONE_LINE + 1;
314var MARK_DONE_CUBIC = MARK_DONE_QUAD + 1;
315var MARK_UNSORTABLE_LINE = MARK_DONE_CUBIC + 1;
316var MARK_UNSORTABLE_QUAD = MARK_UNSORTABLE_LINE + 1;
317var MARK_UNSORTABLE_CUBIC = MARK_UNSORTABLE_QUAD + 1;
318var MARK_SIMPLE_LINE = MARK_UNSORTABLE_CUBIC + 1;
319var MARK_SIMPLE_QUAD = MARK_SIMPLE_LINE + 1;
320var MARK_SIMPLE_CUBIC = MARK_SIMPLE_QUAD + 1;
321var MARK_SIMPLE_DONE_LINE = MARK_SIMPLE_CUBIC + 1;
322var MARK_SIMPLE_DONE_QUAD = MARK_SIMPLE_DONE_LINE + 1;
323var MARK_SIMPLE_DONE_CUBIC = MARK_SIMPLE_DONE_QUAD + 1;
324var MARK_DONE_UNARY_LINE = MARK_SIMPLE_DONE_CUBIC + 1;
325var MARK_DONE_UNARY_QUAD = MARK_DONE_UNARY_LINE + 1;
326var MARK_DONE_UNARY_CUBIC = MARK_DONE_UNARY_QUAD + 1;
327var MARK_ANGLE_LAST = MARK_DONE_UNARY_CUBIC + 1;
328
329var COMPUTED_SET_1 = MARK_ANGLE_LAST + 1;
330var COMPUTED_SET_2 = COMPUTED_SET_1 + 1;
331
332var ANGLE_AFTER = COMPUTED_SET_2;
333var ANGLE_AFTER2 = ANGLE_AFTER + 1;
334
335var ACTIVE_OP = ANGLE_AFTER2 + 1;
336
337var FRAG_TYPE_LAST = ACTIVE_OP;
338
339var REC_TYPE_UNKNOWN = -1;
340var REC_TYPE_PATH = 0;
341var REC_TYPE_SECT = 1;
342var REC_TYPE_ACTIVE = 2;
343var REC_TYPE_ADD = 3;
344var REC_TYPE_SORT = 4;
345var REC_TYPE_OP = 5;
346var REC_TYPE_MARK = 6;
347var REC_TYPE_COMPUTED = 7;
348var REC_TYPE_COIN = 8;
349var REC_TYPE_ANGLE = 9;
350var REC_TYPE_ACTIVE_OP = 10;
351var REC_TYPE_LAST = REC_TYPE_ACTIVE_OP;
352
353function strs_to_nums(strs) {
354 var result = [];
355 for (var idx = 1; idx < strs.length; ++idx) {
356 var str = strs[idx];
357 var num = parseFloat(str);
358 if (isNaN(num)) {
359 result.push(str);
360 } else {
361 result.push(num);
362 }
363 }
364 return result;
365}
366
367function filter_str_by(id, str, regex, array) {
368 if (regex.test(str)) {
369 var strs = regex.exec(str);
370 var result = strs_to_nums(strs);
371 array.push(id);
372 array.push(result);
373 return true;
374 }
375 return false;
376}
377
378function construct_regexp2(pattern) {
379 var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
380 escape = escape.replace(/UNSORTABLE/g, "\\*\\*\\* UNSORTABLE \\*\\*\\*");
381 escape = escape.replace(/CUBIC_VAL/g, "\\(P_VAL P_VAL P_VAL P_VAL\\)");
382 escape = escape.replace(/QUAD_VAL/g, "\\(P_VAL P_VAL P_VAL\\)");
383 escape = escape.replace(/LINE_VAL/g, "\\(P_VAL P_VAL\\)");
384 escape = escape.replace(/FILL_TYPE/g, "SkPath::k[a-zA-Z]+_FillType");
385 escape = escape.replace(/PT_VAL/g, "\\(P_VAL\\)");
386 escape = escape.replace(/P_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?, ?(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?");
387 escape = escape.replace(/T_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)");
388 escape = escape.replace(/PATH/g, "pathB?");
389 escape = escape.replace(/IDX/g, "(\\d+)");
390 escape = escape.replace(/NUM/g, "(-?\\d+)");
391 escape = escape.replace(/OPT/g, "(\\?|-?\\d+)");
392 return new RegExp(escape, 'i');
393}
394
395function construct_regexp2c(pattern) {
396 var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&');
397 escape = escape.replace(/UNSORTABLE/g, "\\*\\*\\* UNSORTABLE \\*\\*\\*");
398 escape = escape.replace(/CUBIC_VAL/g, "(?:\\$\\d = )?\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}");
399 escape = escape.replace(/QUAD_VAL/g, "(?:\\$\\d = )?\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}");
400 escape = escape.replace(/LINE_VAL/g, "(?:\\$\\d = )?\\{\\{P_VAL\\}, \\{P_VAL\\}\\}");
401 escape = escape.replace(/FILL_TYPE/g, "SkPath::k[a-zA-Z]+_FillType");
402 escape = escape.replace(/PT_VAL/g, "\\{\\{P_VAL\\}\\}");
403 escape = escape.replace(/P_VAL/g, "(?:f?[xX] = )?(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?,(?: f?[yY] = )?(-?\\d+\\.?\\d*(?:e-?\\d+)?)[Ff]?");
404 escape = escape.replace(/T_VAL/g, "(-?\\d+\\.?\\d*(?:e-?\\d+)?)");
405 escape = escape.replace(/OPER/g, "[a-z]+");
406 escape = escape.replace(/PATH/g, "pathB?");
407 escape = escape.replace(/T_F/g, "([TF])");
408 escape = escape.replace(/IDX/g, "(\\d+)");
409 escape = escape.replace(/NUM/g, "(-?\\d+)");
410 escape = escape.replace(/OPT/g, "(\\?|-?\\d+)");
411 return new RegExp(escape, 'i');
412}
413
414function match_regexp(str, lineNo, array, id, pattern) {
415 var regex = construct_regexp2(pattern);
416 if (filter_str_by(id, str, regex, array)) {
417 return true;
418 }
419 regex = construct_regexp2c(pattern);
420 return filter_str_by(id, str, regex, array);
421}
422
423function endsWith(str, suffix) {
424 return str.indexOf(suffix, str.length - suffix.length) !== -1;
425}
426
427function parse_all(test) {
428 var lines = test.match(/[^\r\n]+/g);
429 var records = []; // a rec can be the original paths, a set of intersections, a set of active spans, a sort, or a path add
430 var record = [];
431 var recType = REC_TYPE_UNKNOWN;
432 var lastLineNo;
433 var moveX, moveY;
434 for (var lineNo = 0; lineNo < lines.length; ++lineNo) {
435 var line = lines[lineNo];
436 if (line.length == 0) {
437 continue;
438 }
439 var opStart = "SkOpSegment::";
440 if (line.lastIndexOf(opStart, 0) === 0) {
441 line = line.substr(opStart.length);
442 }
443 var angleStart = "SkOpAngle::";
444 if (line.lastIndexOf(angleStart, 0) === 0) {
445 line = line.substr(angleStart.length);
446 }
447 var type = line.lastIndexOf("debugShowActiveSpans", 0) === 0 ? REC_TYPE_ACTIVE
448 : line.lastIndexOf("debugShowTs", 0) === 0 ? REC_TYPE_COIN
449 : line.lastIndexOf("debugShow", 0) === 0 ? REC_TYPE_SECT
450 : line.lastIndexOf("activeOp", 0) === 0 ? REC_TYPE_ACTIVE_OP
451 : line.lastIndexOf("computed", 0) === 0 ? REC_TYPE_COMPUTED
452 : line.lastIndexOf("debugOne", 0) === 0 ? REC_TYPE_SORT
453 : line.lastIndexOf("dumpOne", 0) === 0 ? REC_TYPE_SORT
454 : line.lastIndexOf("pathB.", 0) === 0 ? REC_TYPE_ADD
455 : line.lastIndexOf("path.", 0) === 0 ? REC_TYPE_ADD
456 : line.lastIndexOf("after", 0) === 0 ? REC_TYPE_ANGLE
457 : line.lastIndexOf("mark", 0) === 0 ? REC_TYPE_MARK
458 : line.lastIndexOf(" {{", 0) === 0 ? REC_TYPE_COMPUTED
459 : line.lastIndexOf("{{", 0) === 0 ? REC_TYPE_PATH
460 : line.lastIndexOf("op", 0) === 0 ? REC_TYPE_OP
461 : line.lastIndexOf("$", 0) === 0 ? REC_TYPE_PATH
462 : REC_TYPE_UNKNOWN;
463 if (recType != type || recType == REC_TYPE_ADD || recType == REC_TYPE_SECT
464 || recType == REC_TYPE_ACTIVE_OP || recType == REC_TYPE_ANGLE) {
465 if (recType != REC_TYPE_UNKNOWN) {
466 records.push(recType);
467 records.push(lastLineNo);
468 records.push(record);
469 }
470 record = [];
471 recType = type;
472 lastLineNo = lineNo;
473 }
474 var found = false;
475 switch (recType) {
476 case REC_TYPE_ACTIVE:
477 found = match_regexp(line, lineNo, record, ACTIVE_LINE_SPAN, "debugShowActiveSpans" +
478" id=IDX LINE_VAL t=T_VAL PT_VAL tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=NUM"
479 ) || match_regexp(line, lineNo, record, ACTIVE_QUAD_SPAN, "debugShowActiveSpans" +
480" id=IDX QUAD_VAL t=T_VAL PT_VAL tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=NUM"
481 ) || match_regexp(line, lineNo, record, ACTIVE_CUBIC_SPAN, "debugShowActiveSpans" +
482" id=IDX CUBIC_VAL t=T_VAL PT_VAL tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=NUM"
483 );
484 break;
485 case REC_TYPE_ACTIVE_OP:
486 found = match_regexp(line, lineNo, record, ACTIVE_OP, "activeOp" +
487" id=IDX t=T_VAL tEnd=T_VAL op=OPER miFrom=NUM miTo=NUM suFrom=NUM suTo=NUM result=IDX"
488 );
489 break;
490 case REC_TYPE_ADD:
491 if (match_regexp(line, lineNo, record, ADD_MOVETO, "PATH.moveTo(P_VAL);")) {
492 moveX = record[1][0];
493 moveY = record[1][1];
494 found = true;
495 } else if (match_regexp(line, lineNo, record, ADD_LINETO, "PATH.lineTo(P_VAL);")) {
496 record[1].unshift(moveY);
497 record[1].unshift(moveX);
498 moveX = record[1][2];
499 moveY = record[1][3];
500 found = true;
501 } else if (match_regexp(line, lineNo, record, ADD_QUADTO, "PATH.quadTo(P_VAL, P_VAL);")) {
502 record[1].unshift(moveY);
503 record[1].unshift(moveX);
504 moveX = record[1][4];
505 moveY = record[1][5];
506 found = true;
507 } else if (match_regexp(line, lineNo, record, ADD_CUBICTO, "PATH.cubicTo(P_VAL, P_VAL, P_VAL);")) {
508 record[1].unshift(moveY);
509 record[1].unshift(moveX);
510 moveX = record[1][6];
511 moveY = record[1][7];
512 found = true;
513 } else if (match_regexp(line, lineNo, record, ADD_FILL, "PATH.setFillType(FILL_TYPE);")) {
514 found = true;
515 } else {
516 found = match_regexp(line, lineNo, record, ADD_CLOSE, "PATH.close();");
517 }
518 break;
519 case REC_TYPE_ANGLE:
520 found = match_regexp(line, lineNo, record, ANGLE_AFTER, "after " +
521"id=IDX IDX/IDX tStart=T_VAL tEnd=T_VAL < id=IDX IDX/IDX tStart=T_VAL tEnd=T_VAL < id=IDX IDX/IDX tStart=T_VAL tEnd=T_VAL T_F IDX");
522 if (found) {
523 break;
524 }
525 found = match_regexp(line, lineNo, record, ANGLE_AFTER2, "after " +
526"[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");
527 break;
528 case REC_TYPE_COIN:
529 found = true;
530 break;
531 case REC_TYPE_COMPUTED:
532 found = line == "computed quadratics given"
533 || match_regexp(line, lineNo, record, COMPUTED_SET_1, "computed quadratics set 1"
534 ) || match_regexp(line, lineNo, record, COMPUTED_SET_2, "computed quadratics set 2"
535 ) || match_regexp(line, lineNo, record, PATH_QUAD, " QUAD_VAL,"
536 ) || match_regexp(line, lineNo, record, PATH_CUBIC, " CUBIC_VAL,"
537 );
538 break;
539 case REC_TYPE_PATH:
540 found = match_regexp(line, lineNo, record, PATH_LINE, "LINE_VAL"
541 ) || match_regexp(line, lineNo, record, PATH_QUAD, "QUAD_VAL"
542 ) || match_regexp(line, lineNo, record, PATH_CUBIC, "CUBIC_VAL"
543 );
544 break;
545 case REC_TYPE_SECT:
546 found = match_regexp(line, lineNo, record, INTERSECT_LINE, "debugShowLineIntersection" +
547" wtTs[0]=T_VAL LINE_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
548 ) || match_regexp(line, lineNo, record, INTERSECT_LINE_2, "debugShowLineIntersection" +
549" wtTs[0]=T_VAL LINE_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
550 ) || match_regexp(line, lineNo, record, INTERSECT_LINE_NO, "debugShowLineIntersection" +
551" no intersect LINE_VAL LINE_VAL"
552 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE, "debugShowQuadLineIntersection" +
553" wtTs[0]=T_VAL QUAD_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
554 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE_2, "debugShowQuadLineIntersection" +
555" wtTs[0]=T_VAL QUAD_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
556 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE_NO, "debugShowQuadLineIntersection" +
557" no intersect QUAD_VAL LINE_VAL"
558 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD, "debugShowQuadIntersection" +
559" wtTs[0]=T_VAL QUAD_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL"
560 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_2, "debugShowQuadIntersection" +
561" wtTs[0]=T_VAL QUAD_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL"
562 ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_NO, "debugShowQuadIntersection" +
563" no intersect QUAD_VAL QUAD_VAL"
564 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE, "debugShowCubicLineIntersection" +
565" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL"
566 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_2, "debugShowCubicLineIntersection" +
567" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL"
568 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_3, "debugShowCubicLineIntersection" +
569" 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"
570 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_NO, "debugShowCubicLineIntersection" +
571" no intersect CUBIC_VAL LINE_VAL"
572 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD, "debugShowCubicQuadIntersection" +
573" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL"
574 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD_2, "debugShowCubicQuadIntersection" +
575" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL"
576 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD_3, "debugShowCubicQuadIntersection" +
577" 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"
578 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD_4, "debugShowCubicQuadIntersection" +
579" 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"
580 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_QUAD_NO, "debugShowCubicQuadIntersection" +
581" no intersect CUBIC_VAL QUAD_VAL"
582 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC, "debugShowCubicIntersection" +
583" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL"
584 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_2, "debugShowCubicIntersection" +
585" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL wnTs[1]=T_VAL"
586 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_3, "debugShowCubicIntersection" +
587" 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"
588 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_4, "debugShowCubicIntersection" +
589" 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"
590 ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_NO, "debugShowCubicIntersection" +
591" no intersect CUBIC_VAL CUBIC_VAL"
592 ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC, "debugShowCubicIntersection" +
593" wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL"
594 ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC_NO, "debugShowCubicIntersection" +
595" no self intersect CUBIC_VAL"
596 );
597 break;
598 case REC_TYPE_SORT:
599 var hasDone = / done/.test(line);
600 var hasUnorderable = / unorderable/.test(line);
601 var hasSmall = / small/.test(line);
602 var hasTiny = / tiny/.test(line);
603 var hasOperand = / operand/.test(line);
604 var hasStop = / stop/.test(line);
605 line.replace(/[ a-z]+$/, "");
606 found = match_regexp(line, lineNo, record, SORT_UNARY, "debugOne" +
607" [IDX/IDX] next=IDX/IDX sect=IDX/IDX s=T_VAL [IDX] e=T_VAL [IDX] sgn=NUM windVal=IDX windSum=OPT"
608 ) || match_regexp(line, lineNo, record, SORT_BINARY, "debugOne" +
609" [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"
610 ) || match_regexp(line, lineNo, record, SORT_UNARY, "dumpOne" +
611" [IDX/IDX] next=IDX/IDX sect=NUM/NUM s=T_VAL [IDX] e=T_VAL [IDX] sgn=NUM windVal=IDX windSum=OPT"
612 ) || match_regexp(line, lineNo, record, SORT_BINARY, "dumpOne" +
613" [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"
614 );
615 if (found) {
616 record[1].push(hasDone);
617 record[1].push(hasUnorderable);
618 record[1].push(hasSmall);
619 record[1].push(hasTiny);
620 record[1].push(hasOperand);
621 record[1].push(hasStop);
622 }
623 break;
624 case REC_TYPE_MARK:
625 found = match_regexp(line, lineNo, record, MARK_LINE, "markWinding" +
626" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX"
627 ) || match_regexp(line, lineNo, record, MARK_QUAD, "markWinding" +
628" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX"
629 ) || match_regexp(line, lineNo, record, MARK_CUBIC, "markWinding" +
630" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX"
631 ) || match_regexp(line, lineNo, record, MARK_DONE_LINE, "markDoneBinary" +
632" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX"
633 ) || match_regexp(line, lineNo, record, MARK_DONE_QUAD, "markDoneBinary" +
634" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX"
635 ) || match_regexp(line, lineNo, record, MARK_DONE_CUBIC, "markDoneBinary" +
636" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX"
637 ) || match_regexp(line, lineNo, record, MARK_UNSORTABLE_LINE, "markUnsortable" +
638" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
639 ) || match_regexp(line, lineNo, record, MARK_UNSORTABLE_QUAD, "markUnsortable" +
640" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
641 ) || match_regexp(line, lineNo, record, MARK_UNSORTABLE_CUBIC, "markUnsortable" +
642" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
643 ) || match_regexp(line, lineNo, record, MARK_SIMPLE_LINE, "markWinding" +
644" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
645 ) || match_regexp(line, lineNo, record, MARK_SIMPLE_QUAD, "markWinding" +
646" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
647 ) || match_regexp(line, lineNo, record, MARK_SIMPLE_CUBIC, "markWinding" +
648" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
649 ) || match_regexp(line, lineNo, record, MARK_SIMPLE_DONE_LINE, "markDone" +
650" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
651 ) || match_regexp(line, lineNo, record, MARK_SIMPLE_DONE_QUAD, "markDone" +
652" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
653 ) || match_regexp(line, lineNo, record, MARK_SIMPLE_DONE_CUBIC, "markDone" +
654" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
655 ) || match_regexp(line, lineNo, record, MARK_DONE_UNARY_LINE, "markDoneUnary" +
656" id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
657 ) || match_regexp(line, lineNo, record, MARK_DONE_UNARY_QUAD, "markDoneUnary" +
658" id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
659 ) || match_regexp(line, lineNo, record, MARK_DONE_UNARY_CUBIC, "markDoneUnary" +
660" id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM windSum=OPT windValue=IDX"
661 ) || match_regexp(line, lineNo, record, MARK_ANGLE_LAST, "markAngle" +
662" last id=IDX windSum=OPT small=IDX");
663 break;
664 case REC_TYPE_OP:
665 if (line.lastIndexOf("oppSign oppSign=", 0) === 0
666 || line.lastIndexOf("operator<", 0) === 0) {
667 found = true;
668 break;
669 }
670 found = match_regexp(line, lineNo, record, OP_DIFFERENCE, "op difference"
671 ) || match_regexp(line, lineNo, record, OP_INTERSECT, "op intersect"
672 ) || match_regexp(line, lineNo, record, OP_UNION, "op union"
673 ) || match_regexp(line, lineNo, record, OP_XOR, "op xor"
674 );
675 break;
676 case REC_TYPE_UNKNOWN:
677 found = true;
678 break;
679 }
680 if (!found) {
681 console.log(line + " [" + lineNo + "] of type " + type + " not found");
682 }
683 }
684 if (recType != REC_TYPE_UNKNOWN) {
685 records.push(recType);
686 records.push(lastLineNo);
687 records.push(record);
688 }
689 if (records.length >= 1) {
690 tests[testIndex] = records;
691 testLines[testIndex] = lines;
692 }
693}
694
695function init(test) {
696 var canvas = document.getElementById('canvas');
697 if (!canvas.getContext) return;
698 ctx = canvas.getContext('2d');
699 var resScale = retina_scale && window.devicePixelRatio ? window.devicePixelRatio : 1;
700 var unscaledWidth = window.innerWidth - 20;
701 var unscaledHeight = window.innerHeight - 20;
702 screenWidth = unscaledWidth;
703 screenHeight = unscaledHeight;
704 canvas.width = unscaledWidth * resScale;
705 canvas.height = unscaledHeight * resScale;
706 canvas.style.width = unscaledWidth + 'px';
707 canvas.style.height = unscaledHeight + 'px';
708 if (resScale != 1) {
709 ctx.scale(resScale, resScale);
710 }
711 xmin = Infinity;
712 xmax = -Infinity;
713 ymin = Infinity;
714 ymax = -Infinity;
715 hasPath = hasComputedPath = false;
716 firstActiveSpan = -1;
717 for (var tIndex = 0; tIndex < test.length; tIndex += 3) {
718 var recType = test[tIndex];
719 if (!typeof recType == 'number' || recType < REC_TYPE_UNKNOWN || recType > REC_TYPE_LAST) {
720 console.log("unknown rec type: " + recType);
721 throw "stop execution";
722 }
723 var records = test[tIndex + 2];
724 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
725 var fragType = records[recordIndex];
726 if (!typeof fragType == 'number' || fragType < 1 || fragType > FRAG_TYPE_LAST) {
727 console.log("unknown in range frag type: " + fragType);
728 throw "stop execution";
729 }
730 var frags = records[recordIndex + 1];
731 var first = 0;
732 var last = -1;
733 var first2 = 0;
734 var last2 = 0;
735 switch (recType) {
736 case REC_TYPE_COMPUTED:
737 if (fragType == COMPUTED_SET_1 || fragType == COMPUTED_SET_2) {
738 break;
739 }
740 hasComputedPath = true;
741 case REC_TYPE_PATH:
742 switch (fragType) {
743 case PATH_LINE:
744 last = 4;
745 break;
746 case PATH_QUAD:
747 last = 6;
748 break;
749 case PATH_CUBIC:
750 last = 8;
751 break;
752 default:
753 console.log("unknown " + (recType == REC_TYPE_PATH ? "REC_TYPE_PATH"
754 : "REC_TYPE_COMPUTED") + " frag type:" + fragType);
755 throw "stop execution";
756 }
757 if (recType == REC_TYPE_PATH) {
758 hasPath = true;
759 }
760 break;
761 case REC_TYPE_ACTIVE:
762 if (firstActiveSpan < 0) {
763 firstActiveSpan = tIndex;
764 }
765 first = 1;
766 switch (fragType) {
767 case ACTIVE_LINE_SPAN:
768 last = 5;
769 break;
770 case ACTIVE_QUAD_SPAN:
771 last = 7;
772 break;
773 case ACTIVE_CUBIC_SPAN:
774 last = 9;
775 break;
776 default:
777 console.log("unknown REC_TYPE_ACTIVE frag type: " + fragType);
778 throw "stop execution";
779 }
780 break;
781 case REC_TYPE_ADD:
782 switch (fragType) {
783 case ADD_MOVETO:
784 break;
785 case ADD_LINETO:
786 last = 4;
787 break;
788 case ADD_QUADTO:
789 last = 6;
790 break;
791 case ADD_CUBICTO:
792 last = 8;
793 break;
794 case ADD_CLOSE:
795 case ADD_FILL:
796 break;
797 default:
798 console.log("unknown REC_TYPE_ADD frag type: " + fragType);
799 throw "stop execution";
800 }
801 break;
802 case REC_TYPE_SECT:
803 switch (fragType) {
804 case INTERSECT_LINE:
805 first = 1; last = 5; first2 = 8; last2 = 12;
806 break;
807 case INTERSECT_LINE_2:
808 first = 1; last = 5; first2 = 11; last2 = 15;
809 break;
810 case INTERSECT_LINE_NO:
811 first = 0; last = 4; first2 = 4; last2 = 8;
812 break;
813 case INTERSECT_QUAD_LINE:
814 first = 1; last = 7; first2 = 10; last2 = 14;
815 break;
816 case INTERSECT_QUAD_LINE_2:
817 first = 1; last = 7; first2 = 13; last2 = 17;
818 break;
819 case INTERSECT_QUAD_LINE_NO:
820 first = 0; last = 6; first2 = 6; last2 = 10;
821 break;
822 case INTERSECT_QUAD:
823 first = 1; last = 7; first2 = 10; last2 = 16;
824 break;
825 case INTERSECT_QUAD_2:
826 first = 1; last = 7; first2 = 13; last2 = 19;
827 break;
828 case INTERSECT_QUAD_NO:
829 first = 0; last = 6; first2 = 6; last2 = 12;
830 break;
831 case INTERSECT_SELF_CUBIC:
832 first = 1; last = 9;
833 break;
834 case INTERSECT_SELF_CUBIC_NO:
835 first = 0; last = 8;
836 break;
837 case INTERSECT_CUBIC_LINE:
838 first = 1; last = 9; first2 = 12; last2 = 16;
839 break;
840 case INTERSECT_CUBIC_LINE_2:
841 first = 1; last = 9; first2 = 15; last2 = 19;
842 break;
843 case INTERSECT_CUBIC_LINE_3:
844 first = 1; last = 9; first2 = 18; last2 = 22;
845 break;
846 case INTERSECT_CUBIC_LINE_NO:
847 first = 0; last = 8; first2 = 8; last2 = 12;
848 break;
849 case INTERSECT_CUBIC_QUAD:
850 first = 1; last = 9; first2 = 12; last2 = 18;
851 break;
852 case INTERSECT_CUBIC_QUAD_2:
853 first = 1; last = 9; first2 = 15; last2 = 21;
854 break;
855 case INTERSECT_CUBIC_QUAD_3:
856 first = 1; last = 9; first2 = 18; last2 = 24;
857 break;
858 case INTERSECT_CUBIC_QUAD_4:
859 first = 1; last = 9; first2 = 21; last2 = 27;
860 break;
861 case INTERSECT_CUBIC_QUAD_NO:
862 first = 0; last = 8; first2 = 8; last2 = 14;
863 break;
864 case INTERSECT_CUBIC:
865 first = 1; last = 9; first2 = 12; last2 = 20;
866 break;
867 case INTERSECT_CUBIC_2:
868 first = 1; last = 9; first2 = 15; last2 = 23;
869 break;
870 case INTERSECT_CUBIC_3:
871 first = 1; last = 9; first2 = 18; last2 = 26;
872 break;
873 case INTERSECT_CUBIC_4:
874 first = 1; last = 9; first2 = 21; last2 = 29;
875 break;
876 case INTERSECT_CUBIC_NO:
877 first = 0; last = 8; first2 = 8; last2 = 16;
878 break;
879 default:
880 console.log("unknown REC_TYPE_SECT frag type: " + fragType);
881 throw "stop execution";
882 }
883 break;
884 default:
885 continue;
886 }
887 for (var idx = first; idx < last; idx += 2) {
888 xmin = Math.min(xmin, frags[idx]);
889 xmax = Math.max(xmax, frags[idx]);
890 ymin = Math.min(ymin, frags[idx + 1]);
891 ymax = Math.max(ymax, frags[idx + 1]);
892 }
893 for (var idx = first2; idx < last2; idx += 2) {
894 xmin = Math.min(xmin, frags[idx]);
895 xmax = Math.max(xmax, frags[idx]);
896 ymin = Math.min(ymin, frags[idx + 1]);
897 ymax = Math.max(ymax, frags[idx + 1]);
898 }
899 }
900 }
901 var angleBounds = [Infinity, Infinity, -Infinity, -Infinity];
902 for (var tIndex = 0; tIndex < test.length; tIndex += 3) {
903 var recType = test[tIndex];
904 var records = test[tIndex + 2];
905 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
906 var fragType = records[recordIndex];
907 var frags = records[recordIndex + 1];
908 switch (recType) {
909 case REC_TYPE_ACTIVE_OP:
910 if (!draw_op) {
911 break;
912 }
913 {
914 var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
915 curve_extremes(curve, angleBounds);
916 }
917 break;
918 case REC_TYPE_ANGLE:
919 if (!draw_angle) {
920 break;
921 }
922 if (fragType == ANGLE_AFTER) {
923 var curve = curvePartialByID(test, frags[0], frags[3], frags[4]);
924 curve_extremes(curve, angleBounds);
925 curve = curvePartialByID(test, frags[5], frags[8], frags[9]);
926 curve_extremes(curve, angleBounds);
927 curve = curvePartialByID(test, frags[10], frags[13], frags[14]);
928 } else if (fragType == ANGLE_AFTER2) {
929 var curve = curvePartialByID(test, frags[0], frags[4], frags[5]);
930 curve_extremes(curve, angleBounds);
931 curve = curvePartialByID(test, frags[6], frags[10], frags[11]);
932 curve_extremes(curve, angleBounds);
933 curve = curvePartialByID(test, frags[12], frags[16], frags[17]);
934 }
935 break;
936 case REC_TYPE_SORT:
937 if (!draw_sort) {
938 break;
939 }
940 if (fragType == SORT_UNARY || fragType == SORT_BINARY) {
941 var curve = curvePartialByID(test, frags[0], frags[6], frags[8]);
942 curve_extremes(curve, angleBounds);
943 }
944 break;
945 }
946 }
947 }
948 xmin = Math.min(xmin, angleBounds[0]);
949 ymin = Math.min(ymin, angleBounds[1]);
950 xmax = Math.max(xmax, angleBounds[2]);
951 ymax = Math.max(ymax, angleBounds[3]);
952 setScale(xmin, xmax, ymin, ymax);
953 if (hasPath == false && hasComputedPath == true && !draw_computed) {
954 draw_computed = 3; // show both quadratics and cubics
955 }
956 if (hasPath == true && hasComputedPath == false && draw_computed) {
957 draw_computed = 0;
958 }
959}
960
961function curveByID(test, id) {
962 var tIndex = firstActiveSpan;
963 if (tIndex < 0) {
964 return [];
965 }
966 while (tIndex < test.length) {
967 var recType = test[tIndex];
968 if (recType != REC_TYPE_ACTIVE) {
969 return [];
970 }
971 var records = test[tIndex + 2];
972 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
973 var fragType = records[recordIndex];
974 var frags = records[recordIndex + 1];
975 if (frags[0] == id) {
976 switch (fragType) {
977 case ACTIVE_LINE_SPAN:
978 return [frags[1], frags[2], frags[3], frags[4]];
979 case ACTIVE_QUAD_SPAN:
980 return [frags[1], frags[2], frags[3], frags[4],
981 frags[5], frags[6]];
982 case ACTIVE_CUBIC_SPAN:
983 return [frags[1], frags[2], frags[3], frags[4],
984 frags[5], frags[6], frags[7], frags[8]];
985 }
986 }
987 }
988 tIndex += 3;
989 }
990 return [];
991}
992
993function curvePartialByID(test, id, t0, t1) {
994 var tIndex = firstActiveSpan;
995 if (tIndex < 0) {
996 return [];
997 }
998 while (tIndex < test.length) {
999 var recType = test[tIndex];
1000 if (recType != REC_TYPE_ACTIVE) {
1001 return [];
1002 }
1003 var records = test[tIndex + 2];
1004 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
1005 var fragType = records[recordIndex];
1006 var frags = records[recordIndex + 1];
1007 if (frags[0] == id) {
1008 switch (fragType) {
1009 case ACTIVE_LINE_SPAN:
1010 return linePartial(frags[1], frags[2], frags[3], frags[4], t0, t1);
1011 case ACTIVE_QUAD_SPAN:
1012 return quadPartial(frags[1], frags[2], frags[3], frags[4],
1013 frags[5], frags[6], t0, t1);
1014 case ACTIVE_CUBIC_SPAN:
1015 return cubicPartial(frags[1], frags[2], frags[3], frags[4],
1016 frags[5], frags[6], frags[7], frags[8], t0, t1);
1017 }
1018 }
1019 }
1020 tIndex += 3;
1021 }
1022 return [];
1023}
1024
1025function idByCurve(test, frag, type) {
1026 var tIndex = firstActiveSpan;
1027 if (tIndex < 0) {
1028 return -1;
1029 }
1030 while (tIndex < test.length) {
1031 var recType = test[tIndex];
1032 if (recType != REC_TYPE_ACTIVE) {
1033 return -1;
1034 }
1035 var records = test[tIndex + 2];
1036 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
1037 var fragType = records[recordIndex];
1038 var frags = records[recordIndex + 1];
1039 switch (fragType) {
1040 case ACTIVE_LINE_SPAN:
1041 if (type != PATH_LINE) {
1042 continue;
1043 }
1044 if (frag[0] != frags[1] || frag[1] != frags[2]
1045 || frag[2] != frags[3] || frag[3] != frags[4]) {
1046 continue;
1047 }
1048 return frags[0];
1049 case ACTIVE_QUAD_SPAN:
1050 if (type != PATH_QUAD) {
1051 continue;
1052 }
1053 if (frag[0] != frags[1] || frag[1] != frags[2]
1054 || frag[2] != frags[3] || frag[3] != frags[4]
1055 || frag[4] != frags[5] || frag[5] != frags[6]) {
1056 continue;
1057 }
1058 return frags[0];
1059 case ACTIVE_CUBIC_SPAN:
1060 if (type != PATH_CUBIC) {
1061 continue;
1062 }
1063 if (frag[0] != frags[1] || frag[1] != frags[2]
1064 || frag[2] != frags[3] || frag[3] != frags[4]
1065 || frag[4] != frags[5] || frag[5] != frags[6]
1066 || frag[6] != frags[7] || frag[7] != frags[8]) {
1067 continue;
1068 }
1069 return frags[0];
1070 }
1071 }
1072 ++tIndex;
1073 }
1074 return -1;
1075}
1076
1077function curve_extremes(curve, bounds) {
1078 for (var index = 0; index < curve.length; index += 2) {
1079 var x = curve[index];
1080 var y = curve[index + 1];
1081 bounds[0] = Math.min(bounds[0], x);
1082 bounds[1] = Math.min(bounds[1], y);
1083 bounds[2] = Math.max(bounds[2], x);
1084 bounds[3] = Math.max(bounds[3], y);
1085 }
1086}
1087
1088function setScale(x0, x1, y0, y1) {
1089 var srcWidth = x1 - x0;
1090 var srcHeight = y1 - y0;
1091 var usableWidth = screenWidth;
1092 var xDigits = Math.ceil(Math.log(Math.abs(xmax)) / Math.log(10));
1093 var yDigits = Math.ceil(Math.log(Math.abs(ymax)) / Math.log(10));
1094 usableWidth -= (xDigits + yDigits) * 10;
1095 usableWidth -= decimal_places * 10;
1096 if (draw_legend) {
1097 usableWidth -= 40;
1098 }
1099 var hscale = usableWidth / srcWidth;
1100 var vscale = screenHeight / srcHeight;
1101 scale = Math.min(hscale, vscale);
1102 var invScale = 1 / scale;
1103 var sxmin = x0 - invScale * 5;
1104 var symin = y0 - invScale * 10;
1105 var sxmax = x1 + invScale * (6 * decimal_places + 10);
1106 var symax = y1 + invScale * 10;
1107 srcWidth = sxmax - sxmin;
1108 srcHeight = symax - symin;
1109 hscale = usableWidth / srcWidth;
1110 vscale = screenHeight / srcHeight;
1111 scale = Math.min(hscale, vscale);
1112 srcLeft = sxmin;
1113 srcTop = symin;
1114}
1115
1116function drawArc(curve, op, from, to) {
1117 var type = PATH_LINE + (curve.length / 2 - 2);
1118 var pt = pointAtT(curve, type, op ? 0.4 : 0.6);
1119 var dy = pt.y - curve[1];
1120 var dx = pt.x - curve[0];
1121 var dist = Math.sqrt(dy * dy + dx * dx);
1122 var _dist = dist * scale;
1123 var angle = Math.atan2(dy, dx);
1124 var _px = (curve[0] - srcLeft) * scale;
1125 var _py = (curve[1] - srcTop) * scale;
1126 var divisor = 4;
1127 var endDist;
1128 do {
1129 var ends = [];
1130 for (var index = -1; index <= 1; index += 2) {
1131 var px = Math.cos(index * Math.PI / divisor);
1132 var py = Math.sin(index * Math.PI / divisor);
1133 ends.push(px);
1134 ends.push(py);
1135 }
1136 var endDx = (ends[2] - ends[0]) * scale * dist;
1137 var endDy = (ends[3] - ends[1]) * scale * dist;
1138 endDist = Math.sqrt(endDx * endDx + endDy * endDy);
1139 if (endDist < 100) {
1140 break;
1141 }
1142 divisor *= 2;
1143 } while (true);
1144 if (endDist < 30) {
1145 return;
1146 }
1147 if (op) {
1148 divisor *= 2;
1149 }
1150 ctx.strokeStyle = op ? "rgba(210,0,45, 0.4)" : "rgba(90,90,90, 0.5)";
1151 ctx.beginPath();
1152 ctx.arc(_px, _py, _dist, angle - Math.PI / divisor, angle + Math.PI / divisor, false);
1153 ctx.stroke();
1154 var saveAlign = ctx.textAlign;
1155 var saveStyle = ctx.fillStyle;
1156 var saveFont = ctx.font;
1157 ctx.textAlign = "center";
1158 ctx.fillStyle = "black";
1159 ctx.font = "normal 24px Arial";
1160 divisor *= 0.8;
1161 for (var index = -1; index <= 1; index += 2) {
1162 var px = curve[0] + Math.cos(angle + index * Math.PI / divisor) * dist;
1163 var py = curve[1] + Math.sin(angle + index * Math.PI / divisor) * dist;
1164 var _px = (px - srcLeft) * scale;
1165 var _py = (py - srcTop) * scale;
1166 ctx.fillText(index < 0 ? to.toString() : from.toString(), _px, _py + 8);
1167 }
1168 ctx.textAlign = saveAlign;
1169 ctx.fillStyle = saveStyle;
1170 ctx.font = saveFont;
1171}
1172
1173function drawPoint(px, py, end) {
1174 for (var pts = 0; pts < drawnPts.length; pts += 2) {
1175 var x = drawnPts[pts];
1176 var y = drawnPts[pts + 1];
1177 if (px == x && py == y) {
1178 return;
1179 }
1180 }
1181 drawnPts.push(px);
1182 drawnPts.push(py);
1183 var label = px.toFixed(decimal_places) + ", " + py.toFixed(decimal_places);
1184 var _px = (px - srcLeft) * scale;
1185 var _py = (py - srcTop) * scale;
1186 ctx.beginPath();
1187 ctx.arc(_px, _py, 3, 0, Math.PI*2, true);
1188 ctx.closePath();
1189 if (end) {
1190 ctx.fill();
1191 } else {
1192 ctx.stroke();
1193 }
1194 if (debug_xy) {
1195 ctx.textAlign = "left";
1196 ctx.fillText(label, _px + 5, _py);
1197 }
1198}
1199
1200function drawPoints(ptArray, curveType, drawControls) {
1201 var count = (curveType - PATH_LINE + 2) * 2;
1202 for (var idx = 0; idx < count; idx += 2) {
1203 if (!drawControls && idx != 0 && idx != count - 2) {
1204 continue;
1205 }
1206 drawPoint(ptArray[idx], ptArray[idx + 1], idx == 0 || idx == count - 2);
1207 }
1208}
1209
1210function drawControlLines(curve, curveType, drawEnd) {
1211 if (curveType == PATH_LINE) {
1212 return;
1213 }
1214 ctx.strokeStyle = "rgba(0,0,0, 0.3)";
1215 drawLine(curve[0], curve[1], curve[2], curve[3]);
1216 drawLine(curve[2], curve[3], curve[4], curve[5]);
1217 if (curveType == PATH_CUBIC) {
1218 drawLine(curve[4], curve[5], curve[6], curve[7]);
1219 if (drawEnd > 1) {
1220 drawLine(curve[6], curve[7], curve[0], curve[1]);
1221 if (drawEnd > 2) {
1222 drawLine(curve[0], curve[1], curve[4], curve[5]);
1223 drawLine(curve[6], curve[7], curve[2], curve[3]);
1224 }
1225 }
1226 } else if (drawEnd > 1) {
1227 drawLine(curve[4], curve[5], curve[0], curve[1]);
1228 }
1229}
1230
1231function pointAtT(curve, curveType, t) {
1232 var xy = {};
1233 switch (curveType) {
1234 case PATH_LINE:
1235 var a = 1 - t;
1236 var b = t;
1237 xy.x = a * curve[0] + b * curve[2];
1238 xy.y = a * curve[1] + b * curve[3];
1239 break;
1240 case PATH_QUAD:
1241 var one_t = 1 - t;
1242 var a = one_t * one_t;
1243 var b = 2 * one_t * t;
1244 var c = t * t;
1245 xy.x = a * curve[0] + b * curve[2] + c * curve[4];
1246 xy.y = a * curve[1] + b * curve[3] + c * curve[5];
1247 break;
1248 case PATH_CUBIC:
1249 var one_t = 1 - t;
1250 var one_t2 = one_t * one_t;
1251 var a = one_t2 * one_t;
1252 var b = 3 * one_t2 * t;
1253 var t2 = t * t;
1254 var c = 3 * one_t * t2;
1255 var d = t2 * t;
1256 xy.x = a * curve[0] + b * curve[2] + c * curve[4] + d * curve[6];
1257 xy.y = a * curve[1] + b * curve[3] + c * curve[5] + d * curve[7];
1258 break;
1259 }
1260 return xy;
1261}
1262
1263function drawPointAtT(curve, curveType) {
1264 var x, y;
1265 var xy = pointAtT(curve, curveType, curveT);
1266 drawPoint(xy.x, xy.y, true);
1267 if (!draw_intersectT) {
1268 return;
1269 }
1270 ctx.fillStyle = "red";
1271 drawTAtPointUp(xy.x, xy.y, curveT);
1272}
1273
1274function drawTAtPointUp(px, py, t) {
1275 var label = t.toFixed(decimal_places);
1276 var _px = (px - srcLeft)* scale;
1277 var _py = (py - srcTop) * scale;
1278 ctx.fillText(label, _px + 5, _py - 10);
1279}
1280
1281function drawTAtPointDown(px, py, t) {
1282 var label = t.toFixed(decimal_places);
1283 var _px = (px - srcLeft)* scale;
1284 var _py = (py - srcTop) * scale;
1285 ctx.fillText(label, _px + 5, _py + 10);
1286}
1287
1288function alreadyDrawnLine(x1, y1, x2, y2) {
1289 if (collect_bounds) {
1290 if (focus_enabled) {
1291 focusXmin = Math.min(focusXmin, x1, x2);
1292 focusYmin = Math.min(focusYmin, y1, y2);
1293 focusXmax = Math.max(focusXmax, x1, x2);
1294 focusYmax = Math.max(focusYmax, y1, y2);
1295 }
1296 return true;
1297 }
1298 for (var pts = 0; pts < drawnLines.length; pts += 4) {
1299 if (x1 == drawnLines[pts] && y1 == drawnLines[pts + 1]
1300 && x2 == drawnLines[pts + 2] && y2 == drawnLines[pts + 3]) {
1301 return true;
1302 }
1303 }
1304 drawnLines.push(x1);
1305 drawnLines.push(y1);
1306 drawnLines.push(x2);
1307 drawnLines.push(y2);
1308 return false;
1309}
1310
1311function drawLine(x1, y1, x2, y2) {
1312 if (alreadyDrawnLine(x1, y1, x2, y2)) {
1313 return;
1314 }
1315 ctx.beginPath();
1316 ctx.moveTo((x1 - srcLeft) * scale,
1317 (y1 - srcTop) * scale);
1318 ctx.lineTo((x2 - srcLeft) * scale,
1319 (y2 - srcTop) * scale);
1320 ctx.stroke();
1321}
1322
1323function linePartial(x1, y1, x2, y2, t1, t2) {
1324 var dx = x1 - x2;
1325 var dy = y1 - y2;
1326 var array = [
1327 x1 - t1 * dx,
1328 y1 - t1 * dy,
1329 x1 - t2 * dx,
1330 y1 - t2 * dy
1331 ];
1332 return array;
1333}
1334
1335function drawLinePartial(x1, y1, x2, y2, t1, t2) {
1336 var a = linePartial(x1, y1, x2, y2, t1, t2);
1337 var ax = a[0];
1338 var ay = a[1];
1339 var bx = a[2];
1340 var by = a[3];
1341 if (alreadyDrawnLine(ax, ay, bx, by)) {
1342 return;
1343 }
1344 ctx.beginPath();
1345 ctx.moveTo((ax - srcLeft) * scale,
1346 (ay - srcTop) * scale);
1347 ctx.lineTo((bx - srcLeft) * scale,
1348 (by - srcTop) * scale);
1349 ctx.stroke();
1350}
1351
1352function alreadyDrawnQuad(x1, y1, x2, y2, x3, y3) {
1353 if (collect_bounds) {
1354 if (focus_enabled) {
1355 focusXmin = Math.min(focusXmin, x1, x2, x3);
1356 focusYmin = Math.min(focusYmin, y1, y2, y3);
1357 focusXmax = Math.max(focusXmax, x1, x2, x3);
1358 focusYmax = Math.max(focusYmax, y1, y2, y3);
1359 }
1360 return true;
1361 }
1362 for (var pts = 0; pts < drawnQuads.length; pts += 6) {
1363 if (x1 == drawnQuads[pts] && y1 == drawnQuads[pts + 1]
1364 && x2 == drawnQuads[pts + 2] && y2 == drawnQuads[pts + 3]
1365 && x3 == drawnQuads[pts + 4] && y3 == drawnQuads[pts + 5]) {
1366 return true;
1367 }
1368 }
1369 drawnQuads.push(x1);
1370 drawnQuads.push(y1);
1371 drawnQuads.push(x2);
1372 drawnQuads.push(y2);
1373 drawnQuads.push(x3);
1374 drawnQuads.push(y3);
1375 return false;
1376}
1377
1378function drawQuad(x1, y1, x2, y2, x3, y3) {
1379 if (alreadyDrawnQuad(x1, y1, x2, y2, x3, y3)) {
1380 return;
1381 }
1382 ctx.beginPath();
1383 ctx.moveTo((x1 - srcLeft) * scale,
1384 (y1 - srcTop) * scale);
1385 ctx.quadraticCurveTo((x2 - srcLeft) * scale,
1386 (y2 - srcTop) * scale,
1387 (x3 - srcLeft) * scale,
1388 (y3 - srcTop) * scale);
1389 ctx.stroke();
1390}
1391
1392function interp(A, B, t) {
1393 return A + (B - A) * t;
1394}
1395
1396function interp_quad_coords(x1, x2, x3, t)
1397{
1398 var ab = interp(x1, x2, t);
1399 var bc = interp(x2, x3, t);
1400 var abc = interp(ab, bc, t);
1401 return abc;
1402}
1403
1404function quadPartial(x1, y1, x2, y2, x3, y3, t1, t2) {
1405 var ax = interp_quad_coords(x1, x2, x3, t1);
1406 var ay = interp_quad_coords(y1, y2, y3, t1);
1407 var dx = interp_quad_coords(x1, x2, x3, (t1 + t2) / 2);
1408 var dy = interp_quad_coords(y1, y2, y3, (t1 + t2) / 2);
1409 var cx = interp_quad_coords(x1, x2, x3, t2);
1410 var cy = interp_quad_coords(y1, y2, y3, t2);
1411 var bx = 2*dx - (ax + cx)/2;
1412 var by = 2*dy - (ay + cy)/2;
1413 var array = [
1414 ax, ay, bx, by, cx, cy
1415 ];
1416 return array;
1417}
1418
1419function drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2) {
1420 var a = quadPartial(x1, y1, x2, y2, x3, y3, t1, t2);
1421 var ax = a[0];
1422 var ay = a[1];
1423 var bx = a[2];
1424 var by = a[3];
1425 var cx = a[4];
1426 var cy = a[5];
1427 if (alreadyDrawnQuad(ax, ay, bx, by, cx, cy)) {
1428 return;
1429 }
1430 ctx.beginPath();
1431 ctx.moveTo((ax - srcLeft) * scale,
1432 (ay - srcTop) * scale);
1433 ctx.quadraticCurveTo((bx - srcLeft) * scale,
1434 (by - srcTop) * scale,
1435 (cx - srcLeft) * scale,
1436 (cy - srcTop) * scale);
1437 ctx.stroke();
1438}
1439
1440function alreadyDrawnCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
1441 if (collect_bounds) {
1442 if (focus_enabled) {
1443 focusXmin = Math.min(focusXmin, x1, x2, x3, x4);
1444 focusYmin = Math.min(focusYmin, y1, y2, y3, y4);
1445 focusXmax = Math.max(focusXmax, x1, x2, x3, x4);
1446 focusYmax = Math.max(focusYmax, y1, y2, y3, y4);
1447 }
1448 return true;
1449 }
1450 for (var pts = 0; pts < drawnCubics.length; pts += 8) {
1451 if (x1 == drawnCubics[pts] && y1 == drawnCubics[pts + 1]
1452 && x2 == drawnCubics[pts + 2] && y2 == drawnCubics[pts + 3]
1453 && x3 == drawnCubics[pts + 4] && y3 == drawnCubics[pts + 5]
1454 && x4 == drawnCubics[pts + 6] && y4 == drawnCubics[pts + 7]) {
1455 return true;
1456 }
1457 }
1458 drawnCubics.push(x1);
1459 drawnCubics.push(y1);
1460 drawnCubics.push(x2);
1461 drawnCubics.push(y2);
1462 drawnCubics.push(x3);
1463 drawnCubics.push(y3);
1464 drawnCubics.push(x4);
1465 drawnCubics.push(y4);
1466 return false;
1467}
1468
1469function drawCubic(x1, y1, x2, y2, x3, y3, x4, y4) {
1470 if (alreadyDrawnCubic(x1, y1, x2, y2, x3, y3, x4, y4)) {
1471 return;
1472 }
1473 ctx.beginPath();
1474 ctx.moveTo((x1 - srcLeft) * scale,
1475 (y1 - srcTop) * scale);
1476 ctx.bezierCurveTo((x2 - srcLeft) * scale,
1477 (y2 - srcTop) * scale,
1478 (x3 - srcLeft) * scale,
1479 (y3 - srcTop) * scale,
1480 (x4 - srcLeft) * scale,
1481 (y4 - srcTop) * scale);
1482 ctx.stroke();
1483}
1484
1485function interp_cubic_coords(x1, x2, x3, x4, t)
1486{
1487 var ab = interp(x1, x2, t);
1488 var bc = interp(x2, x3, t);
1489 var cd = interp(x3, x4, t);
1490 var abc = interp(ab, bc, t);
1491 var bcd = interp(bc, cd, t);
1492 var abcd = interp(abc, bcd, t);
1493 return abcd;
1494}
1495
1496function cubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2) {
1497 var ax = interp_cubic_coords(x1, x2, x3, x4, t1);
1498 var ay = interp_cubic_coords(y1, y2, y3, y4, t1);
1499 var ex = interp_cubic_coords(x1, x2, x3, x4, (t1*2+t2)/3);
1500 var ey = interp_cubic_coords(y1, y2, y3, y4, (t1*2+t2)/3);
1501 var fx = interp_cubic_coords(x1, x2, x3, x4, (t1+t2*2)/3);
1502 var fy = interp_cubic_coords(y1, y2, y3, y4, (t1+t2*2)/3);
1503 var dx = interp_cubic_coords(x1, x2, x3, x4, t2);
1504 var dy = interp_cubic_coords(y1, y2, y3, y4, t2);
1505 var mx = ex * 27 - ax * 8 - dx;
1506 var my = ey * 27 - ay * 8 - dy;
1507 var nx = fx * 27 - ax - dx * 8;
1508 var ny = fy * 27 - ay - dy * 8;
1509 var bx = (mx * 2 - nx) / 18;
1510 var by = (my * 2 - ny) / 18;
1511 var cx = (nx * 2 - mx) / 18;
1512 var cy = (ny * 2 - my) / 18;
1513 var array = [
1514 ax, ay, bx, by, cx, cy, dx, dy
1515 ];
1516 return array;
1517}
1518
1519function drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2) {
1520 var a = cubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2);
1521 var ax = a[0];
1522 var ay = a[1];
1523 var bx = a[2];
1524 var by = a[3];
1525 var cx = a[4];
1526 var cy = a[5];
1527 var dx = a[6];
1528 var dy = a[7];
1529 if (alreadyDrawnCubic(ax, ay, bx, by, cx, cy, dx, dy)) {
1530 return;
1531 }
1532 ctx.beginPath();
1533 ctx.moveTo((ax - srcLeft) * scale,
1534 (ay - srcTop) * scale);
1535 ctx.bezierCurveTo((bx - srcLeft) * scale,
1536 (by - srcTop) * scale,
1537 (cx - srcLeft) * scale,
1538 (cy - srcTop) * scale,
1539 (dx - srcLeft) * scale,
1540 (dy - srcTop) * scale);
1541 ctx.stroke();
1542}
1543
1544function drawCurve(c) {
1545 switch (c.length) {
1546 case 4:
1547 drawLine(c[0], c[1], c[2], c[3]);
1548 break;
1549 case 6:
1550 drawQuad(c[0], c[1], c[2], c[3], c[4], c[5]);
1551 break;
1552 case 8:
1553 drawCubic(c[0], c[1], c[2], c[3], c[4], c[5], c[6], c[7]);
1554 break;
1555 }
1556}
1557
1558function boundsWidth(pts) {
1559 var min = pts[0];
1560 var max = pts[0];
1561 for (var idx = 2; idx < pts.length; idx += 2) {
1562 min = Math.min(min, pts[idx]);
1563 max = Math.max(max, pts[idx]);
1564 }
1565 return max - min;
1566}
1567
1568function boundsHeight(pts) {
1569 var min = pts[1];
1570 var max = pts[1];
1571 for (var idx = 3; idx < pts.length; idx += 2) {
1572 min = Math.min(min, pts[idx]);
1573 max = Math.max(max, pts[idx]);
1574 }
1575 return max - min;
1576}
1577
1578function tangent(pts) {
1579 var dx = pts[2] - pts[0];
1580 var dy = pts[3] - pts[1];
1581 if (dx == 0 && dy == 0 && pts.length > 4) {
1582 dx = pts[4] - pts[0];
1583 dy = pts[5] - pts[1];
1584 if (dx == 0 && dy == 0 && pts.length > 6) {
1585 dx = pts[6] - pts[0];
1586 dy = pts[7] - pts[1];
1587 }
1588 }
1589 return Math.atan2(-dy, dx);
1590}
1591
1592function hodograph(cubic) {
1593 var hodo = [];
1594 hodo[0] = 3 * (cubic[2] - cubic[0]);
1595 hodo[1] = 3 * (cubic[3] - cubic[1]);
1596 hodo[2] = 3 * (cubic[4] - cubic[2]);
1597 hodo[3] = 3 * (cubic[5] - cubic[3]);
1598 hodo[4] = 3 * (cubic[6] - cubic[4]);
1599 hodo[5] = 3 * (cubic[7] - cubic[5]);
1600 return hodo;
1601}
1602
1603function hodograph2(cubic) {
1604 var quad = hodograph(cubic);
1605 var hodo = [];
1606 hodo[0] = 2 * (quad[2] - quad[0]);
1607 hodo[1] = 2 * (quad[3] - quad[1]);
1608 hodo[2] = 2 * (quad[4] - quad[2]);
1609 hodo[3] = 2 * (quad[5] - quad[3]);
1610 return hodo;
1611}
1612
1613function quadraticRootsReal(A, B, C, s) {
1614 if (A == 0) {
1615 if (B == 0) {
1616 s[0] = 0;
1617 return C == 0;
1618 }
1619 s[0] = -C / B;
1620 return 1;
1621 }
1622 /* normal form: x^2 + px + q = 0 */
1623 var p = B / (2 * A);
1624 var q = C / A;
1625 var p2 = p * p;
1626 if (p2 < q) {
1627 return 0;
1628 }
1629 var sqrt_D = 0;
1630 if (p2 > q) {
1631 sqrt_D = sqrt(p2 - q);
1632 }
1633 s[0] = sqrt_D - p;
1634 s[1] = -sqrt_D - p;
1635 return 1 + s[0] != s[1];
1636}
1637
1638function add_valid_ts(s, realRoots, t) {
1639 var foundRoots = 0;
1640 for (var index = 0; index < realRoots; ++index) {
1641 var tValue = s[index];
1642 if (tValue >= 0 && tValue <= 1) {
1643 for (var idx2 = 0; idx2 < foundRoots; ++idx2) {
1644 if (t[idx2] != tValue) {
1645 t[foundRoots++] = tValue;
1646 }
1647 }
1648 }
1649 }
1650 return foundRoots;
1651}
1652
1653function quadraticRootsValidT(a, b, c, t) {
1654 var s = [];
1655 var realRoots = quadraticRootsReal(A, B, C, s);
1656 var foundRoots = add_valid_ts(s, realRoots, t);
1657 return foundRoots != 0;
1658}
1659
1660function find_cubic_inflections(cubic, tValues) {
1661 var Ax = src[2] - src[0];
1662 var Ay = src[3] - src[1];
1663 var Bx = src[4] - 2 * src[2] + src[0];
1664 var By = src[5] - 2 * src[3] + src[1];
1665 var Cx = src[6] + 3 * (src[2] - src[4]) - src[0];
1666 var Cy = src[7] + 3 * (src[3] - src[5]) - src[1];
1667 return quadraticRootsValidT(Bx * Cy - By * Cx, (Ax * Cy - Ay * Cx),
1668 Ax * By - Ay * Bx, tValues);
1669}
1670
1671function dxy_at_t(curve, type, t) {
1672 var dxy = {};
1673 if (type == PATH_QUAD) {
1674 var a = t - 1;
1675 var b = 1 - 2 * t;
1676 var c = t;
1677 dxy.x = a * curve[0] + b * curve[2] + c * curve[4];
1678 dxy.y = a * curve[1] + b * curve[3] + c * curve[5];
1679 } else if (type == PATH_CUBIC) {
1680 var one_t = 1 - t;
1681 var a = curve[0];
1682 var b = curve[2];
1683 var c = curve[4];
1684 var d = curve[6];
1685 dxy.x = 3 * ((b - a) * one_t * one_t + 2 * (c - b) * t * one_t + (d - c) * t * t);
1686 a = curve[1];
1687 b = curve[3];
1688 c = curve[5];
1689 d = curve[7];
1690 dxy.y = 3 * ((b - a) * one_t * one_t + 2 * (c - b) * t * one_t + (d - c) * t * t);
1691 }
1692 return dxy;
1693}
1694
1695function drawLabel(num, px, py) {
1696 ctx.beginPath();
1697 ctx.arc(px, py, 8, 0, Math.PI*2, true);
1698 ctx.closePath();
1699 ctx.strokeStyle = "rgba(0,0,0, 0.4)";
1700 ctx.lineWidth = num == 0 || num == 3 ? 2 : 1;
1701 ctx.stroke();
1702 ctx.fillStyle = "black";
1703 ctx.font = "normal 10px Arial";
1704 // ctx.rotate(0.001);
1705 ctx.fillText(num, px - 2, py + 3);
1706 // ctx.rotate(-0.001);
1707}
1708
1709function drawLabelX(ymin, num, loc) {
1710 var px = (loc - srcLeft) * scale;
1711 var py = (ymin - srcTop) * scale - 20;
1712 drawLabel(num, px, py);
1713}
1714
1715function drawLabelY(xmin, num, loc) {
1716 var px = (xmin - srcLeft) * scale - 20;
1717 var py = (loc - srcTop) * scale;
1718 drawLabel(num, px, py);
1719}
1720
1721function drawHodoOrigin(hx, hy, hMinX, hMinY, hMaxX, hMaxY) {
1722 ctx.beginPath();
1723 ctx.moveTo(hx, hy - 100);
1724 ctx.lineTo(hx, hy);
1725 ctx.strokeStyle = hMinY < 0 ? "green" : "blue";
1726 ctx.stroke();
1727 ctx.beginPath();
1728 ctx.moveTo(hx, hy);
1729 ctx.lineTo(hx, hy + 100);
1730 ctx.strokeStyle = hMaxY > 0 ? "green" : "blue";
1731 ctx.stroke();
1732 ctx.beginPath();
1733 ctx.moveTo(hx - 100, hy);
1734 ctx.lineTo(hx, hy);
1735 ctx.strokeStyle = hMinX < 0 ? "green" : "blue";
1736 ctx.stroke();
1737 ctx.beginPath();
1738 ctx.moveTo(hx, hy);
1739 ctx.lineTo(hx + 100, hy);
1740 ctx.strokeStyle = hMaxX > 0 ? "green" : "blue";
1741 ctx.stroke();
1742}
1743
1744function scalexy(x, y, mag) {
1745 var length = Math.sqrt(x * x + y * y);
1746 return mag / length;
1747}
1748
1749function drawArrow(x, y, dx, dy) {
1750 var dscale = scalexy(dx, dy, 1 / scale * 100);
1751 dx *= dscale;
1752 dy *= dscale;
1753 ctx.beginPath();
1754 ctx.moveTo((x - srcLeft) * scale, (y - srcTop) * scale);
1755 x += dx;
1756 y += dy;
1757 ctx.lineTo((x - srcLeft) * scale, (y - srcTop) * scale);
1758 dx /= 10;
1759 dy /= 10;
1760 ctx.lineTo((x - dy - srcLeft) * scale, (y + dx - srcTop) * scale);
1761 ctx.lineTo((x + dx * 2 - srcLeft) * scale, (y + dy * 2 - srcTop) * scale);
1762 ctx.lineTo((x + dy - srcLeft) * scale, (y - dx - srcTop) * scale);
1763 ctx.lineTo((x - srcLeft) * scale, (y - srcTop) * scale);
1764 ctx.strokeStyle = "rgba(0,75,0, 0.4)";
1765 ctx.stroke();
1766}
1767
1768function x_at_t(curve, t) {
1769 var one_t = 1 - t;
1770 if (curve.length == 4) {
1771 return one_t * curve[0] + t * curve[2];
1772 }
1773 var one_t2 = one_t * one_t;
1774 var t2 = t * t;
1775 if (curve.length == 6) {
1776 return one_t2 * curve[0] + 2 * one_t * t * curve[2] + t2 * curve[4];
1777 }
1778 var a = one_t2 * one_t;
1779 var b = 3 * one_t2 * t;
1780 var c = 3 * one_t * t2;
1781 var d = t2 * t;
1782 return a * curve[0] + b * curve[2] + c * curve[4] + d * curve[6];
1783}
1784
1785function y_at_t(curve, t) {
1786 var one_t = 1 - t;
1787 if (curve.length == 4) {
1788 return one_t * curve[1] + t * curve[3];
1789 }
1790 var one_t2 = one_t * one_t;
1791 var t2 = t * t;
1792 if (curve.length == 6) {
1793 return one_t2 * curve[1] + 2 * one_t * t * curve[3] + t2 * curve[5];
1794 }
1795 var a = one_t2 * one_t;
1796 var b = 3 * one_t2 * t;
1797 var c = 3 * one_t * t2;
1798 var d = t2 * t;
1799 return a * curve[1] + b * curve[3] + c * curve[5] + d * curve[7];
1800}
1801
1802function drawOrder(curve, label) {
1803 var px = x_at_t(curve, 0.75);
1804 var py = y_at_t(curve, 0.75);
1805 var _px = (px - srcLeft) * scale;
1806 var _py = (py - srcTop) * scale;
1807 ctx.beginPath();
1808 ctx.arc(_px, _py, 15, 0, Math.PI * 2, true);
1809 ctx.closePath();
1810 ctx.fillStyle = "white";
1811 ctx.fill();
1812 if (label == 'L') {
1813 ctx.strokeStyle = "rgba(255,0,0, 1)";
1814 ctx.fillStyle = "rgba(255,0,0, 1)";
1815 } else {
1816 ctx.strokeStyle = "rgba(0,0,255, 1)";
1817 ctx.fillStyle = "rgba(0,0,255, 1)";
1818 }
1819 ctx.stroke();
1820 ctx.font = "normal 16px Arial";
1821 ctx.textAlign = "center";
1822 ctx.fillText(label, _px, _py + 5);
1823 ctx.font = "normal 10px Arial";
1824}
1825
1826function drawID(curve, id) {
1827 var px = x_at_t(curve, 0.5);
1828 var py = y_at_t(curve, 0.5);
1829 var _px = (px - srcLeft) * scale;
1830 var _py = (py - srcTop) * scale;
1831 draw_id_at(id, _px, _py);
1832}
1833
1834function draw_id_at(id, _px, _py) {
1835 ctx.beginPath();
1836 ctx.arc(_px, _py, 15, 0, Math.PI * 2, true);
1837 ctx.closePath();
1838 ctx.fillStyle = "white";
1839 ctx.fill();
1840 ctx.strokeStyle = "rgba(127,127,0, 1)";
1841 ctx.fillStyle = "rgba(127,127,0, 1)";
1842 ctx.stroke();
1843 ctx.font = "normal 16px Arial";
1844 ctx.textAlign = "center";
1845 ctx.fillText(id, _px, _py + 5);
1846 ctx.font = "normal 10px Arial";
1847}
1848
1849function drawLinePartialID(id, x1, y1, x2, y2, t1, t2) {
1850 var curve = [x1, y1, x2, y2];
1851 drawCurvePartialID(id, curve, t1, t2);
1852}
1853
1854function drawQuadPartialID(id, x1, y1, x2, y2, x3, y3, t1, t2) {
1855 var curve = [x1, y1, x2, y2, x3, y3];
1856 drawCurvePartialID(id, curve, t1, t2);
1857}
1858
1859function drawCubicPartialID(id, x1, y1, x2, y2, x3, y3, x4, y4, t1, t2) {
1860 var curve = [x1, y1, x2, y2, x3, y3, x4, y4];
1861 drawCurvePartialID(id, curve, t1, t2);
1862}
1863
1864function drawCurvePartialID(id, curve, t1, t2) {
1865 var px = x_at_t(curve, (t1 + t2) / 2);
1866 var py = y_at_t(curve, (t1 + t2) / 2);
1867 var _px = (px - srcLeft) * scale;
1868 var _py = (py - srcTop) * scale;
1869 draw_id_at(id, _px, _py);
1870}
1871
1872function drawCurveSpecials(test, curve, type) {
1873 if (pt_labels) {
1874 drawPoints(curve, type, pt_labels == 2);
1875 }
1876 if (control_lines != 0) {
1877 drawControlLines(curve, type, control_lines);
1878 }
1879 if (curve_t) {
1880 drawPointAtT(curve, type);
1881 }
1882 if (draw_midpoint) {
1883 var mid = pointAtT(curve, type, 0.5);
1884 drawPoint(mid.x, mid.y, true);
1885 }
1886 if (draw_id) {
1887 var id = idByCurve(test, curve, type);
1888 if (id >= 0) {
1889 drawID(curve, id);
1890 }
1891 }
1892 if (type == PATH_LINE) {
1893 return;
1894 }
1895 if (draw_deriviatives > 0) {
1896 var d = dxy_at_t(curve, type, 0);
1897 drawArrow(curve[0], curve[1], d.x, d.y);
1898 if (draw_deriviatives == 2) {
1899 d = dxy_at_t(curve, type, 1);
1900 if (type == PATH_CUBIC) {
1901 drawArrow(curve[6], curve[7], d.x, d.y);
1902 } else {
1903 drawArrow(curve[4], curve[5], d.x, d.y);
1904 }
1905 }
1906 if (draw_midpoint) {
1907 var mid = pointAtT(curve, type, 0.5);
1908 d = dxy_at_t(curve, type, 0.5);
1909 drawArrow(mid.x, mid.y, d.x, d.y);
1910 }
1911 }
1912 if (type != PATH_CUBIC) {
1913 return;
1914 }
1915 if (draw_hodo == 1 || draw_hodo == 2) {
1916 var hodo = hodograph(curve);
1917 var hMinX = Math.min(0, hodo[0], hodo[2], hodo[4]);
1918 var hMinY = Math.min(0, hodo[1], hodo[3], hodo[5]);
1919 var hMaxX = Math.max(0, hodo[0], hodo[2], hodo[4]);
1920 var hMaxY = Math.max(0, hodo[1], hodo[3], hodo[5]);
1921 var hScaleX = hMaxX - hMinX > 0 ? screenWidth / (hMaxX - hMinX) : 1;
1922 var hScaleY = hMaxY - hMinY > 0 ? screenHeight / (hMaxY - hMinY) : 1;
1923 var hUnit = Math.min(hScaleX, hScaleY);
1924 hUnit /= 2;
1925 var hx = xoffset - hMinX * hUnit;
1926 var hy = yoffset - hMinY * hUnit;
1927 ctx.moveTo(hx + hodo[0] * hUnit, hy + hodo[1] * hUnit);
1928 ctx.quadraticCurveTo(
1929 hx + hodo[2] * hUnit, hy + hodo[3] * hUnit,
1930 hx + hodo[4] * hUnit, hy + hodo[5] * hUnit);
1931 ctx.strokeStyle = "red";
1932 ctx.stroke();
1933 if (draw_hodo == 1) {
1934 drawHodoOrigin(hx, hy, hMinX, hMinY, hMaxX, hMaxY);
1935 }
1936 }
1937 if (draw_hodo == 3) {
1938 var hodo = hodograph2(curve);
1939 var hMinX = Math.min(0, hodo[0], hodo[2]);
1940 var hMinY = Math.min(0, hodo[1], hodo[3]);
1941 var hMaxX = Math.max(0, hodo[0], hodo[2]);
1942 var hMaxY = Math.max(0, hodo[1], hodo[3]);
1943 var hScaleX = hMaxX - hMinX > 0 ? screenWidth / (hMaxX - hMinX) : 1;
1944 var hScaleY = hMaxY - hMinY > 0 ? screenHeight / (hMaxY - hMinY) : 1;
1945 var hUnit = Math.min(hScaleX, hScaleY);
1946 hUnit /= 2;
1947 var hx = xoffset - hMinX * hUnit;
1948 var hy = yoffset - hMinY * hUnit;
1949 ctx.moveTo(hx + hodo[0] * hUnit, hy + hodo[1] * hUnit);
1950 ctx.lineTo(hx + hodo[2] * hUnit, hy + hodo[3] * hUnit);
1951 ctx.strokeStyle = "red";
1952 ctx.stroke();
1953 drawHodoOrigin(hx, hy, hMinX, hMinY, hMaxX, hMaxY);
1954 }
1955 if (draw_sequence) {
1956 var ymin = Math.min(curve[1], curve[3], curve[5], curve[7]);
1957 for (var i = 0; i < 8; i+= 2) {
1958 drawLabelX(ymin, i >> 1, curve[i]);
1959 }
1960 var xmin = Math.min(curve[0], curve[2], curve[4], curve[6]);
1961 for (var i = 1; i < 8; i+= 2) {
1962 drawLabelY(xmin, i >> 1, curve[i]);
1963 }
1964 }
1965}
1966
1967function logCurves(test) {
1968 for (curves in test) {
1969 var curve = test[curves];
1970 dumpCurve(curve);
1971 }
1972}
1973
1974function curveToString(curve) {
1975 var str = "{{";
1976 for (i = 0; i < curve.length; i += 2) {
1977 str += curve[i].toFixed(decimal_places) + "," + curve[i + 1].toFixed(decimal_places);
1978 if (i < curve.length - 2) {
1979 str += "}, {";
1980 }
1981 }
1982 str += "}}";
1983 return str;
1984}
1985
1986function dumpCurve(curve) {
1987 console.log(curveToString(curve));
1988}
1989
1990function draw(test, lines, title) {
1991 ctx.fillStyle = "rgba(0,0,0, 0.1)";
1992 ctx.font = "normal 50px Arial";
1993 ctx.textAlign = "left";
1994 ctx.fillText(title, 50, 50);
1995 ctx.font = "normal 10px Arial";
1996 ctx.lineWidth = "1.001"; "0.999";
1997 var secondPath = test.length;
1998 var closeCount = 0;
1999 logStart = -1;
2000 logRange = 0;
2001 // find last active rec type at this step
2002 var curType = test[0];
2003 var curStep = 0;
2004 var hasOp = false;
2005 var lastActive = 0;
2006 var lastAdd = 0;
2007 var lastSect = 0;
2008 var lastSort = 0;
2009 var lastMark = 0;
2010 activeCount = 0;
2011 addCount = 0;
2012 angleCount = 0;
2013 opCount = 0;
2014 sectCount = 0;
2015 sortCount = 0;
2016 markCount = 0;
2017 activeMax = 0;
2018 addMax = 0;
2019 angleMax = 0;
2020 opMax = 0;
2021 sectMax = 0;
2022 sectMax2 = 0;
2023 sortMax = 0;
2024 markMax = 0;
2025 lastIndex = test.length - 3;
2026 for (var tIndex = 0; tIndex < test.length; tIndex += 3) {
2027 var recType = test[tIndex];
2028 if (!typeof recType == 'number' || recType < REC_TYPE_UNKNOWN || recType > REC_TYPE_LAST) {
2029 console.log("unknown rec type: " + recType);
2030 throw "stop execution";
2031 }
2032 // if (curType == recType && curType != REC_TYPE_ADD) {
2033 // continue;
2034 // }
2035 var inStepRange = step_limit == 0 || curStep < step_limit;
2036 curType = recType;
2037 if (recType == REC_TYPE_OP) {
2038 hasOp = true;
2039 continue;
2040 }
2041 if (recType == REC_TYPE_UNKNOWN) {
2042 // these types do not advance step
2043 continue;
2044 }
2045 var bumpStep = false;
2046 var records = test[tIndex + 2];
2047 var fragType = records[0];
2048 if (recType == REC_TYPE_ADD) {
2049 if (records.length != 2) {
2050 console.log("expect only two elements: " + records.length);
2051 throw "stop execution";
2052 }
2053 if (fragType == ADD_MOVETO || fragType == ADD_CLOSE) {
2054 continue;
2055 }
2056 ++addMax;
2057 if (!draw_add || !inStepRange) {
2058 continue;
2059 }
2060 lastAdd = tIndex;
2061 ++addCount;
2062 bumpStep = true;
2063 }
2064 if (recType == REC_TYPE_PATH && hasOp) {
2065 secondPath = tIndex;
2066 }
2067 if (recType == REC_TYPE_ACTIVE) {
2068 ++activeMax;
2069 if (!draw_active || !inStepRange) {
2070 continue;
2071 }
2072 lastActive = tIndex;
2073 ++activeCount;
2074 bumpStep = true;
2075 }
2076 if (recType == REC_TYPE_ACTIVE_OP) {
2077 ++opMax;
2078 if (!draw_op || !inStepRange) {
2079 continue;
2080 }
2081 lastOp = tIndex;
2082 ++opCount;
2083 bumpStep = true;
2084 }
2085 if (recType == REC_TYPE_ANGLE) {
2086 ++angleMax;
2087 if (!draw_angle || !inStepRange) {
2088 continue;
2089 }
2090 lastAngle = tIndex;
2091 ++angleCount;
2092 bumpStep = true;
2093 }
2094 if (recType == REC_TYPE_SECT) {
2095 if (records.length != 2) {
2096 console.log("expect only two elements: " + records.length);
2097 throw "stop execution";
2098 }
2099 ++sectMax;
2100 var sectBump = 1;
2101 switch (fragType) {
2102 case INTERSECT_LINE:
2103 case INTERSECT_QUAD_LINE:
2104 case INTERSECT_QUAD:
2105 case INTERSECT_SELF_CUBIC:
2106 case INTERSECT_CUBIC_LINE:
2107 case INTERSECT_CUBIC_QUAD:
2108 case INTERSECT_CUBIC:
2109 sectBump = 1;
2110 break;
2111 case INTERSECT_LINE_2:
2112 case INTERSECT_QUAD_LINE_2:
2113 case INTERSECT_QUAD_2:
2114 case INTERSECT_CUBIC_LINE_2:
2115 case INTERSECT_CUBIC_QUAD_2:
2116 case INTERSECT_CUBIC_2:
2117 sectBump = 2;
2118 break;
2119 case INTERSECT_LINE_NO:
2120 case INTERSECT_QUAD_LINE_NO:
2121 case INTERSECT_QUAD_NO:
2122 case INTERSECT_SELF_CUBIC_NO:
2123 case INTERSECT_CUBIC_LINE_NO:
2124 case INTERSECT_CUBIC_QUAD_NO:
2125 case INTERSECT_CUBIC_NO:
2126 sectBump = 0;
2127 break;
2128 case INTERSECT_CUBIC_LINE_3:
2129 case INTERSECT_CUBIC_QUAD_3:
2130 case INTERSECT_CUBIC_3:
2131 sectBump = 3;
2132 break;
2133 case INTERSECT_CUBIC_QUAD_4:
2134 case INTERSECT_CUBIC_4:
2135 sectBump = 4;
2136 break;
2137 default:
2138 console.log("missing case " + records.length);
2139 throw "stop execution";
2140 }
2141 sectMax2 += sectBump;
2142 if (draw_intersection <= 1 || !inStepRange) {
2143 continue;
2144 }
2145 lastSect = tIndex;
2146 sectCount += sectBump;
2147 bumpStep = true;
2148 }
2149 if (recType == REC_TYPE_SORT) {
2150 ++sortMax;
2151 if (!draw_sort || !inStepRange) {
2152 continue;
2153 }
2154 lastSort = tIndex;
2155 ++sortCount;
2156 bumpStep = true;
2157 }
2158 if (recType == REC_TYPE_MARK) {
2159 ++markMax;
2160 if (!draw_mark || !inStepRange) {
2161 continue;
2162 }
2163 lastMark = tIndex;
2164 ++markCount;
2165 bumpStep = true;
2166 }
2167 if (bumpStep) {
2168 lastIndex = tIndex;
2169 logStart = test[tIndex + 1];
2170 logRange = records.length / 2;
2171 ++curStep;
2172 }
2173 }
2174 stepMax = (draw_add ? addMax : 0)
2175 + (draw_active ? activeMax : 0)
2176 + (draw_op ? opMax : 0)
2177 + (draw_angle ? angleMax : 0)
2178 + (draw_sort ? sortMax : 0)
2179 + (draw_mark ? markMax : 0)
2180 + (draw_intersection == 2 ? sectMax : draw_intersection == 3 ? sectMax2 : 0);
2181 if (stepMax == 0) {
2182 stepMax = addMax + activeMax + angleMax + opMax + sortMax + markMax;
2183 }
2184 drawnPts = [];
2185 drawnLines = [];
2186 drawnQuads = [];
2187 drawnCubics = [];
2188 focusXmin = focusYmin = Infinity;
2189 focusXmax = focusYmax = -Infinity;
2190 var pathIndex = 0;
2191 var opLetter = 'S';
2192 for (var tIndex = lastIndex; tIndex >= 0; tIndex -= 3) {
2193 var recType = test[tIndex];
2194 var records = test[tIndex + 2];
2195 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
2196 var fragType = records[recordIndex];
2197 if (!typeof fragType == 'number' || fragType < 1 || fragType > FRAG_TYPE_LAST) {
2198 console.log("unknown in range frag type: " + fragType);
2199 throw "stop execution";
2200 }
2201 var frags = records[recordIndex + 1];
2202 focus_enabled = false;
2203 switch (recType) {
2204 case REC_TYPE_COMPUTED:
2205 if (draw_computed == 0) {
2206 continue;
2207 }
2208 ctx.lineWidth = 1;
2209 ctx.strokeStyle = pathIndex == 0 ? "black" : "red";
2210 ctx.fillStyle = "blue";
2211 var drawThis = false;
2212 switch (fragType) {
2213 case PATH_QUAD:
2214 if ((draw_computed & 5) == 1 || ((draw_computed & 4) != 0
2215 && (draw_computed & 1) == pathIndex)) {
2216 drawQuad(frags[0], frags[1], frags[2], frags[3],
2217 frags[4], frags[5]);
2218 drawThis = true;
2219 }
2220 break;
2221 case PATH_CUBIC:
2222 if ((draw_computed & 6) == 2 || ((draw_computed & 4) != 0
2223 && (draw_computed & 1) != pathIndex)) {
2224 drawCubic(frags[0], frags[1], frags[2], frags[3],
2225 frags[4], frags[5], frags[6], frags[7]);
2226 drawThis = true;
2227 }
2228 ++pathIndex;
2229 break;
2230 case COMPUTED_SET_1:
2231 pathIndex = 0;
2232 break;
2233 case COMPUTED_SET_2:
2234 pathIndex = 1;
2235 break;
2236 default:
2237 console.log("unknown REC_TYPE_COMPUTED frag type: " + fragType);
2238 throw "stop execution";
2239 }
2240 if (!drawThis || collect_bounds) {
2241 break;
2242 }
2243 drawCurveSpecials(test, frags, fragType);
2244 break;
2245 case REC_TYPE_PATH:
2246 if (!draw_path) {
2247 continue;
2248 }
2249 var firstPath = tIndex < secondPath;
2250 if ((draw_path & (firstPath ? 1 : 2)) == 0) {
2251 continue;
2252 }
2253 ctx.lineWidth = 1;
2254 ctx.strokeStyle = firstPath ? "black" : "red";
2255 ctx.fillStyle = "blue";
2256 switch (fragType) {
2257 case PATH_LINE:
2258 drawLine(frags[0], frags[1], frags[2], frags[3]);
2259 break;
2260 case PATH_QUAD:
2261 drawQuad(frags[0], frags[1], frags[2], frags[3],
2262 frags[4], frags[5]);
2263 break;
2264 case PATH_CUBIC:
2265 drawCubic(frags[0], frags[1], frags[2], frags[3],
2266 frags[4], frags[5], frags[6], frags[7]);
2267 break;
2268 default:
2269 console.log("unknown REC_TYPE_PATH frag type: " + fragType);
2270 throw "stop execution";
2271 }
2272 if (collect_bounds) {
2273 break;
2274 }
2275 drawCurveSpecials(test, frags, fragType);
2276 break;
2277 case REC_TYPE_OP:
2278 switch (fragType) {
2279 case OP_INTERSECT: opLetter = 'I'; break;
2280 case OP_DIFFERENCE: opLetter = 'D'; break;
2281 case OP_UNION: opLetter = 'U'; break;
2282 case OP_XOR: opLetter = 'X'; break;
2283 default:
2284 console.log("unknown REC_TYPE_OP frag type: " + fragType);
2285 throw "stop execution";
2286 }
2287 break;
2288 case REC_TYPE_ACTIVE:
2289 if (!draw_active || (step_limit > 0 && tIndex < lastActive)) {
2290 continue;
2291 }
2292 var x1 = frags[SPAN_X1];
2293 var y1 = frags[SPAN_Y1];
2294 var x2 = frags[SPAN_X2];
2295 var y2 = frags[SPAN_Y2];
2296 var x3, y3, x3, y4, t1, t2;
2297 ctx.lineWidth = 3;
2298 ctx.strokeStyle = "rgba(0,0,255, 0.3)";
2299 focus_enabled = true;
2300 switch (fragType) {
2301 case ACTIVE_LINE_SPAN:
2302 t1 = frags[SPAN_L_T];
2303 t2 = frags[SPAN_L_TEND];
2304 drawLinePartial(x1, y1, x2, y2, t1, t2);
2305 if (draw_id) {
2306 drawLinePartialID(frags[0], x1, y1, x2, y2, t1, t2);
2307 }
2308 break;
2309 case ACTIVE_QUAD_SPAN:
2310 x3 = frags[SPAN_X3];
2311 y3 = frags[SPAN_Y3];
2312 t1 = frags[SPAN_Q_T];
2313 t2 = frags[SPAN_Q_TEND];
2314 drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2);
2315 if (draw_id) {
2316 drawQuadPartialID(frags[0], x1, y1, x2, y2, x3, y3, t1, t2);
2317 }
2318 break;
2319 case ACTIVE_CUBIC_SPAN:
2320 x3 = frags[SPAN_X3];
2321 y3 = frags[SPAN_Y3];
2322 x4 = frags[SPAN_X4];
2323 y4 = frags[SPAN_Y4];
2324 t1 = frags[SPAN_C_T];
2325 t2 = frags[SPAN_C_TEND];
2326 drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2);
2327 if (draw_id) {
2328 drawCubicPartialID(frags[0], x1, y1, x2, y2, x3, y3, x4, y4, t1, t2);
2329 }
2330 break;
2331 default:
2332 console.log("unknown REC_TYPE_ACTIVE frag type: " + fragType);
2333 throw "stop execution";
2334 }
2335 break;
2336 case REC_TYPE_ACTIVE_OP:
2337 if (!draw_op || (step_limit > 0 && tIndex < lastOp)) {
2338 continue;
2339 }
2340 focus_enabled = true;
2341 ctx.lineWidth = 3;
2342 var activeSpan = frags[7] == "1";
2343 ctx.strokeStyle = activeSpan ? "rgba(45,160,0, 0.3)" : "rgba(255,45,0, 0.5)";
2344 var curve = curvePartialByID(test, frags[0], frags[1], frags[2]);
2345 drawCurve(curve);
2346 if (draw_op > 1) {
2347 drawArc(curve, false, frags[3], frags[4]);
2348 drawArc(curve, true, frags[5], frags[6]);
2349 }
2350 break;
2351 case REC_TYPE_ADD:
2352 if (!draw_add) {
2353 continue;
2354 }
2355 ctx.lineWidth = 3;
2356 ctx.strokeStyle = closeCount == 0 ? "rgba(0,0,255, 0.3)"
2357 : closeCount == 1 ? "rgba(0,127,0, 0.3)"
2358 : closeCount == 2 ? "rgba(0,127,127, 0.3)"
2359 : closeCount == 3 ? "rgba(127,127,0, 0.3)"
2360 : "rgba(127,0,127, 0.3)";
2361 focus_enabled = true;
2362 switch (fragType) {
2363 case ADD_MOVETO:
2364 break;
2365 case ADD_LINETO:
2366 if (step_limit == 0 || tIndex >= lastAdd) {
2367 drawLine(frags[0], frags[1], frags[2], frags[3]);
2368 }
2369 break;
2370 case ADD_QUADTO:
2371 if (step_limit == 0 || tIndex >= lastAdd) {
2372 drawQuad(frags[0], frags[1], frags[2], frags[3], frags[4], frags[5]);
2373 }
2374 break;
2375 case ADD_CUBICTO:
2376 if (step_limit == 0 || tIndex >= lastAdd) {
2377 drawCubic(frags[0], frags[1], frags[2], frags[3],
2378 frags[4], frags[5], frags[6], frags[7]);
2379 }
2380 break;
2381 case ADD_CLOSE:
2382 ++closeCount;
2383 break;
2384 case ADD_FILL:
2385 break;
2386 default:
2387 console.log("unknown REC_TYPE_ADD frag type: " + fragType);
2388 throw "stop execution";
2389 }
2390 break;
2391 case REC_TYPE_ANGLE:
2392 if (!draw_angle || (step_limit > 0 && tIndex < lastAngle)) {
2393 continue;
2394 }
2395 if (fragType != ANGLE_AFTER && fragType != ANGLE_AFTER2) {
2396 continue;
2397 }
2398 focus_enabled = true;
2399 ctx.lineWidth = 3;
2400 ctx.strokeStyle = "rgba(127,45,127, 0.3)";
2401 var leftCurve, midCurve, rightCurve;
2402 if (fragType == ANGLE_AFTER) {
2403 leftCurve = curvePartialByID(test, frags[0], frags[3], frags[4]);
2404 midCurve = curvePartialByID(test, frags[5], frags[8], frags[9]);
2405 rightCurve = curvePartialByID(test, frags[10], frags[13], frags[14]);
2406 } else {
2407 leftCurve = curvePartialByID(test, frags[0], frags[4], frags[5]);
2408 midCurve = curvePartialByID(test, frags[6], frags[10], frags[11]);
2409 rightCurve = curvePartialByID(test, frags[12], frags[16], frags[17]);
2410 }
2411 drawCurve(leftCurve);
2412 drawCurve(rightCurve);
2413 var inBetween = frags[fragType == ANGLE_AFTER ? 15 : 18] == "T";
2414 ctx.strokeStyle = inBetween ? "rgba(0,160,45, 0.3)" : "rgba(255,0,45, 0.5)";
2415 drawCurve(midCurve);
2416 if (draw_angle > 1) {
2417 drawOrder(leftCurve, 'L');
2418 drawOrder(rightCurve, 'R');
2419 }
2420 break;
2421 case REC_TYPE_SECT:
2422 if (!draw_intersection) {
2423 continue;
2424 }
2425 if (draw_intersection != 1 && (step_limit > 0 && tIndex < lastSect)) {
2426 continue;
2427 }
2428 // draw_intersection == 1 : show all
2429 // draw_intersection == 2 : step == 0 ? show all : show intersection line #step
2430 // draw_intersection == 3 : step == 0 ? show all : show intersection #step
2431 ctx.lineWidth = 1;
2432 ctx.strokeStyle = "rgba(0,0,255, 0.3)";
2433 ctx.fillStyle = "blue";
2434 focus_enabled = true;
2435 var f = [];
2436 var c1s;
2437 var c1l;
2438 var c2s;
2439 var c2l;
2440 switch (fragType) {
2441 case INTERSECT_LINE:
2442 f.push(5, 6, 0, 7);
2443 c1s = 1; c1l = 4; c2s = 8; c2l = 4;
2444 break;
2445 case INTERSECT_LINE_2:
2446 f.push(5, 6, 0, 10);
2447 f.push(8, 9, 7, 15);
2448 c1s = 1; c1l = 4; c2s = 11; c2l = 4;
2449 break;
2450 case INTERSECT_LINE_NO:
2451 c1s = 0; c1l = 4; c2s = 4; c2l = 4;
2452 break;
2453 case INTERSECT_QUAD_LINE:
2454 f.push(7, 8, 0, 9);
2455 c1s = 1; c1l = 6; c2s = 10; c2l = 4;
2456 break;
2457 case INTERSECT_QUAD_LINE_2:
2458 f.push(7, 8, 0, 12);
2459 f.push(10, 11, 9, 17);
2460 c1s = 1; c1l = 6; c2s = 13; c2l = 4;
2461 break;
2462 case INTERSECT_QUAD_LINE_NO:
2463 c1s = 0; c1l = 6; c2s = 6; c2l = 4;
2464 break;
2465 case INTERSECT_QUAD:
2466 f.push(7, 8, 0, 9);
2467 c1s = 1; c1l = 6; c2s = 10; c2l = 6;
2468 break;
2469 case INTERSECT_QUAD_2:
2470 f.push(7, 8, 0, 12);
2471 f.push(10, 11, 9, 19);
2472 c1s = 1; c1l = 6; c2s = 13; c2l = 6;
2473 break;
2474 case INTERSECT_QUAD_NO:
2475 c1s = 0; c1l = 6; c2s = 6; c2l = 6;
2476 break;
2477 case INTERSECT_SELF_CUBIC:
2478 f.push(9, 10, 0, 11);
2479 c1s = 1; c1l = 8; c2s = 0; c2l = 0;
2480 break;
2481 case INTERSECT_SELF_CUBIC_NO:
2482 c1s = 0; c1l = 8; c2s = 0; c2l = 0;
2483 break;
2484 case INTERSECT_CUBIC_LINE:
2485 f.push(9, 10, 0, 11);
2486 c1s = 1; c1l = 8; c2s = 12; c2l = 4;
2487 break;
2488 case INTERSECT_CUBIC_LINE_2:
2489 f.push(9, 10, 0, 14);
2490 f.push(12, 13, 11, 19);
2491 c1s = 1; c1l = 8; c2s = 15; c2l = 4;
2492 break;
2493 case INTERSECT_CUBIC_LINE_3:
2494 f.push(9, 10, 0, 17);
2495 f.push(12, 13, 11, 22);
2496 f.push(15, 16, 14, 23);
2497 c1s = 1; c1l = 8; c2s = 18; c2l = 4;
2498 break;
2499 case INTERSECT_CUBIC_QUAD_NO:
2500 c1s = 0; c1l = 8; c2s = 8; c2l = 6;
2501 break;
2502 case INTERSECT_CUBIC_QUAD:
2503 f.push(9, 10, 0, 11);
2504 c1s = 1; c1l = 8; c2s = 12; c2l = 6;
2505 break;
2506 case INTERSECT_CUBIC_QUAD_2:
2507 f.push(9, 10, 0, 14);
2508 f.push(12, 13, 11, 21);
2509 c1s = 1; c1l = 8; c2s = 15; c2l = 6;
2510 break;
2511 case INTERSECT_CUBIC_QUAD_3:
2512 f.push(9, 10, 0, 17);
2513 f.push(12, 13, 11, 24);
2514 f.push(15, 16, 14, 25);
2515 c1s = 1; c1l = 8; c2s = 18; c2l = 6;
2516 break;
2517 case INTERSECT_CUBIC_QUAD_4:
2518 f.push(9, 10, 0, 20);
2519 f.push(12, 13, 11, 27);
2520 f.push(15, 16, 14, 28);
2521 f.push(18, 19, 17, 29);
2522 c1s = 1; c1l = 8; c2s = 21; c2l = 6;
2523 break;
2524 case INTERSECT_CUBIC_LINE_NO:
2525 c1s = 0; c1l = 8; c2s = 8; c2l = 4;
2526 break;
2527 case INTERSECT_CUBIC:
2528 f.push(9, 10, 0, 11);
2529 c1s = 1; c1l = 8; c2s = 12; c2l = 8;
2530 break;
2531 case INTERSECT_CUBIC_2:
2532 f.push(9, 10, 0, 14);
2533 f.push(12, 13, 11, 23);
2534 c1s = 1; c1l = 8; c2s = 15; c2l = 8;
2535 break;
2536 case INTERSECT_CUBIC_3:
2537 f.push(9, 10, 0, 17);
2538 f.push(12, 13, 11, 26);
2539 f.push(15, 16, 14, 27);
2540 c1s = 1; c1l = 8; c2s = 18; c2l = 8;
2541 break;
2542 case INTERSECT_CUBIC_4:
2543 f.push(9, 10, 0, 20);
2544 f.push(12, 13, 11, 29);
2545 f.push(15, 16, 14, 30);
2546 f.push(18, 19, 17, 31);
2547 c1s = 1; c1l = 8; c2s = 21; c2l = 8;
2548 break;
2549 case INTERSECT_CUBIC_NO:
2550 c1s = 0; c1l = 8; c2s = 8; c2l = 8;
2551 break;
2552 default:
2553 console.log("unknown REC_TYPE_SECT frag type: " + fragType);
2554 throw "stop execution";
2555 }
2556 if (draw_intersection != 1) {
2557 var id = -1;
2558 var curve;
2559 switch (c1l) {
2560 case 4:
2561 drawLine(frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3]);
2562 if (draw_id) {
2563 curve = [frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3]];
2564 id = idByCurve(test, curve, PATH_LINE);
2565 }
2566 break;
2567 case 6:
2568 drawQuad(frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
2569 frags[c1s + 4], frags[c1s + 5]);
2570 if (draw_id) {
2571 curve = [frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
2572 frags[c1s + 4], frags[c1s + 5]];
2573 id = idByCurve(test, curve, PATH_QUAD);
2574 }
2575 break;
2576 case 8:
2577 drawCubic(frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
2578 frags[c1s + 4], frags[c1s + 5], frags[c1s + 6], frags[c1s + 7]);
2579 if (draw_id) {
2580 curve = [frags[c1s], frags[c1s + 1], frags[c1s + 2], frags[c1s + 3],
2581 frags[c1s + 4], frags[c1s + 5], frags[c1s + 6], frags[c1s + 7]];
2582 id = idByCurve(test, curve, PATH_CUBIC);
2583 }
2584 break;
2585 }
2586 if (id >= 0) {
2587 drawID(curve, id);
2588 }
2589 id = -1;
2590 switch (c2l) {
2591 case 0:
2592 break;
2593 case 4:
2594 drawLine(frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3]);
2595 if (draw_id) {
2596 curve = [frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3]];
2597 id = idByCurve(test, curve, PATH_LINE);
2598 }
2599 break;
2600 case 6:
2601 drawQuad(frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
2602 frags[c2s + 4], frags[c2s + 5]);
2603 if (draw_id) {
2604 curve = [frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
2605 frags[c2s + 4], frags[c2s + 5]];
2606 id = idByCurve(test, curve, PATH_QUAD);
2607 }
2608 break;
2609 case 8:
2610 drawCubic(frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
2611 frags[c2s + 4], frags[c2s + 5], frags[c2s + 6], frags[c2s + 7]);
2612 if (draw_id) {
2613 curve = [frags[c2s], frags[c2s + 1], frags[c2s + 2], frags[c2s + 3],
2614 frags[c2s + 4], frags[c2s + 5], frags[c2s + 6], frags[c2s + 7]];
2615 id = idByCurve(test, curve, PATH_CUBIC);
2616 }
2617 break;
2618 }
2619 if (id >= 0) {
2620 drawID(curve, id);
2621 }
2622 }
2623 if (collect_bounds) {
2624 break;
2625 }
2626 for (var idx = 0; idx < f.length; idx += 4) {
2627 if (draw_intersection != 3 || idx == lastSect - tIndex) {
2628 drawPoint(frags[f[idx]], frags[f[idx + 1]], true);
2629 }
2630 }
2631 if (!draw_intersectT) {
2632 break;
2633 }
2634 ctx.fillStyle = "red";
2635 for (var idx = 0; idx < f.length; idx += 4) {
2636 if (draw_intersection != 3 || idx == lastSect - tIndex) {
2637 drawTAtPointUp(frags[f[idx]], frags[f[idx + 1]], frags[f[idx + 2]]);
2638 drawTAtPointDown(frags[f[idx]], frags[f[idx + 1]], frags[f[idx + 3]]);
2639 }
2640 }
2641 break;
2642 case REC_TYPE_SORT:
2643 if (!draw_sort || (step_limit > 0 && tIndex < lastSort)) {
2644 continue;
2645 }
2646 ctx.lineWidth = 3;
2647 ctx.strokeStyle = "rgba(127,127,0, 0.5)";
2648 focus_enabled = true;
2649 switch (fragType) {
2650 case SORT_UNARY:
2651 case SORT_BINARY:
2652 var curve = curvePartialByID(test, frags[0], frags[6], frags[8]);
2653 drawCurve(curve);
2654 break;
2655 default:
2656 console.log("unknown REC_TYPE_SORT frag type: " + fragType);
2657 throw "stop execution";
2658 }
2659 break;
2660 case REC_TYPE_MARK:
2661 if (!draw_mark || (step_limit > 0 && tIndex < lastMark)) {
2662 continue;
2663 }
2664 ctx.lineWidth = 3;
2665 ctx.strokeStyle = fragType >= MARK_DONE_LINE ?
2666 "rgba(127,0,127, 0.5)" : "rgba(127,127,0, 0.5)";
2667 focus_enabled = true;
2668 switch (fragType) {
2669 case MARK_LINE:
2670 case MARK_DONE_LINE:
2671 case MARK_UNSORTABLE_LINE:
2672 case MARK_SIMPLE_LINE:
2673 case MARK_SIMPLE_DONE_LINE:
2674 case MARK_DONE_UNARY_LINE:
2675 drawLinePartial(frags[1], frags[2], frags[3], frags[4],
2676 frags[5], frags[9]);
2677 if (draw_id) {
2678 drawLinePartialID(frags[0], frags[1], frags[2], frags[3], frags[4],
2679 frags[5], frags[9]);
2680 }
2681 break;
2682 case MARK_QUAD:
2683 case MARK_DONE_QUAD:
2684 case MARK_UNSORTABLE_QUAD:
2685 case MARK_SIMPLE_QUAD:
2686 case MARK_SIMPLE_DONE_QUAD:
2687 case MARK_DONE_UNARY_QUAD:
2688 drawQuadPartial(frags[1], frags[2], frags[3], frags[4],
2689 frags[5], frags[6], frags[7], frags[11]);
2690 if (draw_id) {
2691 drawQuadPartialID(frags[0], frags[1], frags[2], frags[3], frags[4],
2692 frags[5], frags[6], frags[7], frags[11]);
2693 }
2694 break;
2695 case MARK_CUBIC:
2696 case MARK_DONE_CUBIC:
2697 case MARK_UNSORTABLE_CUBIC:
2698 case MARK_SIMPLE_CUBIC:
2699 case MARK_SIMPLE_DONE_CUBIC:
2700 case MARK_DONE_UNARY_CUBIC:
2701 drawCubicPartial(frags[1], frags[2], frags[3], frags[4],
2702 frags[5], frags[6], frags[7], frags[8], frags[9], frags[13]);
2703 if (draw_id) {
2704 drawCubicPartialID(frags[0], frags[1], frags[2], frags[3], frags[4],
2705 frags[5], frags[6], frags[7], frags[8], frags[9], frags[13]);
2706 }
2707 break;
2708 case MARK_ANGLE_LAST:
2709 // FIXME: ignored for now
2710 break;
2711 default:
2712 console.log("unknown REC_TYPE_MARK frag type: " + fragType);
2713 throw "stop execution";
2714 }
2715 break;
2716 default:
2717 continue;
2718 }
2719 }
2720 switch (recType) {
2721 case REC_TYPE_SORT:
2722 if (!draw_sort || (step_limit > 0 && tIndex < lastSort)) {
2723 break;
2724 }
2725 var angles = []; // use tangent lines to describe arcs
2726 var windFrom = [];
2727 var windTo = [];
2728 var opp = [];
2729 var minXY = Number.MAX_VALUE;
2730 var partial;
2731 focus_enabled = true;
2732 var someUnsortable = false;
2733 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
2734 var fragType = records[recordIndex];
2735 var frags = records[recordIndex + 1];
2736 var unsortable = (fragType == SORT_UNARY && frags[14]) ||
2737 (fragType == SORT_BINARY && frags[16]);
2738 someUnsortable |= unsortable;
2739 switch (fragType) {
2740 case SORT_UNARY:
2741 case SORT_BINARY:
2742 partial = curvePartialByID(test, frags[0], frags[6], frags[8]);
2743 break;
2744 default:
2745 console.log("unknown REC_TYPE_SORT frag type: " + fragType);
2746 throw "stop execution";
2747 }
2748 var dx = boundsWidth(partial);
2749 var dy = boundsHeight(partial);
2750 minXY = Math.min(minXY, dx * dx + dy * dy);
2751 if (collect_bounds) {
2752 continue;
2753 }
2754 angles.push(tangent(partial));
2755 var from = frags[12];
2756 var to = frags[12];
2757 var sgn = frags[10];
2758 if (sgn < 0) {
2759 from -= frags[11];
2760 } else if (sgn > 0) {
2761 to -= frags[11];
2762 }
2763 windFrom.push(from + (unsortable ? "!" : ""));
2764 windTo.push(to + (unsortable ? "!" : ""));
2765 opp.push(fragType == SORT_BINARY);
2766 if (draw_sort == 1) {
2767 drawOrder(partial, frags[12]);
2768 } else {
2769 drawOrder(partial, (recordIndex / 2) + 1);
2770 }
2771 }
2772 var radius = Math.sqrt(minXY) / 2 * scale;
2773 radius = Math.min(50, radius);
2774 var scaledRadius = radius / scale;
2775 var centerX = partial[0];
2776 var centerY = partial[1];
2777 if (collect_bounds) {
2778 if (focus_enabled) {
2779 focusXmin = Math.min(focusXmin, centerX - scaledRadius);
2780 focusYmin = Math.min(focusYmin, centerY - scaledRadius);
2781 focusXmax = Math.max(focusXmax, centerX + scaledRadius);
2782 focusYmax = Math.max(focusYmax, centerY + scaledRadius);
2783 }
2784 break;
2785 }
2786 break;
2787 default:
2788 break;
2789 }
2790 }
2791 if (collect_bounds) {
2792 return;
2793 }
2794 if (draw_log && logStart >= 0) {
2795 ctx.font = "normal 10px Arial";
2796 ctx.textAlign = "left";
2797 ctx.beginPath();
2798 var top = screenHeight - 20 - (logRange + 2) * 10;
2799 ctx.rect(50, top, screenWidth - 100, (logRange + 2) * 10);
2800 ctx.fillStyle = "white";
2801 ctx.fill();
2802 ctx.fillStyle = "rgba(0,0,0, 0.5)";
2803 if (logStart > 0) {
2804 ctx.fillText(lines[logStart - 1], 50, top + 8);
2805 }
2806 ctx.fillStyle = "black";
2807 for (var idx = 0; idx < logRange; ++idx) {
2808 ctx.fillText(lines[logStart + idx], 50, top + 18 + 10 * idx);
2809 }
2810 ctx.fillStyle = "rgba(0,0,0, 0.5)";
2811 if (logStart + logRange < lines.length) {
2812 ctx.fillText(lines[logStart + logRange], 50, top + 18 + 10 * logRange);
2813 }
2814 }
2815 if (draw_legend) {
2816 var pos = 0;
2817 var drawSomething = draw_add | draw_active | draw_sort | draw_mark;
2818 // drawBox(pos++, "yellow", "black", opLetter, true, '');
2819 drawBox(pos++, "rgba(0,0,255, 0.3)", "black", draw_intersection > 1 ? sectCount : sectMax2, draw_intersection, intersectionKey);
2820 drawBox(pos++, "rgba(0,0,255, 0.3)", "black", draw_add ? addCount : addMax, draw_add, addKey);
2821 drawBox(pos++, "rgba(0,0,255, 0.3)", "black", draw_active ? activeCount : activeMax, draw_active, activeKey);
2822 drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_angle ? angleCount : angleMax, draw_angle, angleKey);
2823 drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_op ? opCount : opMax, draw_op, opKey);
2824 drawBox(pos++, "rgba(127,127,0, 0.3)", "black", draw_sort ? sortCount : sortMax, draw_sort, sortKey);
2825 drawBox(pos++, "rgba(127,0,127, 0.3)", "black", draw_mark ? markCount : markMax, draw_mark, markKey);
2826 drawBox(pos++, "black", "white",
2827 (new Array('P', 'P1', 'P2', 'P'))[draw_path], draw_path != 0, pathKey);
2828 drawBox(pos++, "rgba(0,63,0, 0.7)", "white",
2829 (new Array('Q', 'Q', 'C', 'QC', 'Qc', 'Cq'))[draw_computed],
2830 draw_computed != 0, computedKey);
2831 drawBox(pos++, "green", "black", step_limit, drawSomething, '');
2832 drawBox(pos++, "green", "black", stepMax, drawSomething, '');
2833 drawBox(pos++, "rgba(255,0,0, 0.6)", "black", lastIndex, drawSomething & draw_log, '');
2834 drawBox(pos++, "rgba(255,0,0, 0.6)", "black", test.length - 1, drawSomething & draw_log, '');
2835 if (curve_t) {
2836 drawCurveTControl();
2837 }
2838 ctx.font = "normal 20px Arial";
2839 ctx.fillStyle = "rgba(0,0,0, 0.3)";
2840 ctx.textAlign = "right";
2841 ctx.fillText(scale.toFixed(decimal_places) + 'x' , screenWidth - 10, screenHeight - 5);
2842 }
2843 if (draw_hints) {
2844 ctx.font = "normal 10px Arial";
2845 ctx.fillStyle = "rgba(0,0,0, 0.5)";
2846 ctx.textAlign = "right";
2847 var y = 4;
2848 ctx.fillText("control lines : " + controlLinesKey, ctx.screenWidthwidth - 10, pos * 50 + y++ * 10);
2849 ctx.fillText("curve t : " + curveTKey, screenWidth - 10, pos * 50 + y++ * 10);
2850 ctx.fillText("deriviatives : " + deriviativesKey, screenWidth - 10, pos * 50 + y++ * 10);
2851 ctx.fillText("intersect t : " + intersectTKey, screenWidth - 10, pos * 50 + y++ * 10);
2852 ctx.fillText("hodo : " + hodoKey, screenWidth - 10, pos * 50 + y++ * 10);
2853 ctx.fillText("log : " + logKey, screenWidth - 10, pos * 50 + y++ * 10);
2854 ctx.fillText("log curve : " + logCurvesKey, screenWidth - 10, pos * 50 + y++ * 10);
2855 ctx.fillText("mid point : " + midpointKey, screenWidth - 10, pos * 50 + y++ * 10);
2856 ctx.fillText("points : " + ptsKey, screenWidth - 10, pos * 50 + y++ * 10);
2857 ctx.fillText("sequence : " + sequenceKey, screenWidth - 10, pos * 50 + y++ * 10);
2858 ctx.fillText("xy : " + xyKey, screenWidth - 10, pos * 50 + y++ * 10);
2859 }
2860}
2861
2862function drawBox(y, backC, foreC, str, enable, label) {
2863 ctx.beginPath();
2864 ctx.fillStyle = backC;
2865 ctx.rect(screenWidth - 40, y * 50 + 10, 40, 30);
2866 ctx.fill();
2867 ctx.font = "normal 16px Arial";
2868 ctx.fillStyle = foreC;
2869 ctx.textAlign = "center";
2870 ctx.fillText(str, screenWidth - 20, y * 50 + 32);
2871 if (!enable) {
2872 ctx.fillStyle = "rgba(255,255,255, 0.5)";
2873 ctx.fill();
2874 }
2875 if (label != '') {
2876 ctx.font = "normal 9px Arial";
2877 ctx.fillStyle = "black";
2878 ctx.fillText(label, screenWidth - 47, y * 50 + 40);
2879 }
2880}
2881
2882function drawCurveTControl() {
2883 ctx.lineWidth = 2;
2884 ctx.strokeStyle = "rgba(0,0,0, 0.3)";
2885 ctx.beginPath();
2886 ctx.rect(screenWidth - 80, 40, 28, screenHeight - 80);
2887 ctx.stroke();
2888 var ty = 40 + curveT * (screenHeight - 80);
2889 ctx.beginPath();
2890 ctx.moveTo(screenWidth - 80, ty);
2891 ctx.lineTo(screenWidth - 85, ty - 5);
2892 ctx.lineTo(screenWidth - 85, ty + 5);
2893 ctx.lineTo(screenWidth - 80, ty);
2894 ctx.fillStyle = "rgba(0,0,0, 0.6)";
2895 ctx.fill();
2896 var num = curveT.toFixed(decimal_places);
2897 ctx.font = "normal 10px Arial";
2898 ctx.textAlign = "left";
2899 ctx.fillText(num, screenWidth - 78, ty);
2900}
2901
2902function ptInTControl() {
2903 var e = window.event;
2904 var tgt = e.target || e.srcElement;
2905 var left = tgt.offsetLeft;
2906 var top = tgt.offsetTop;
2907 var x = (e.clientX - left);
2908 var y = (e.clientY - top);
2909 if (x < screenWidth - 80 || x > screenWidth - 50) {
2910 return false;
2911 }
2912 if (y < 40 || y > screenHeight - 80) {
2913 return false;
2914 }
2915 curveT = (y - 40) / (screenHeight - 120);
2916 if (curveT < 0 || curveT > 1) {
2917 throw "stop execution";
2918 }
2919 return true;
2920}
2921
2922function drawTop() {
2923 if (tests[testIndex] == null) {
2924 var str = testDivs[testIndex].textContent;
2925 parse_all(str);
2926 var title = testDivs[testIndex].id.toString();
2927 testTitles[testIndex] = title;
2928 }
2929 init(tests[testIndex]);
2930 redraw();
2931}
2932
2933function redraw() {
2934 if (focus_on_selection) {
2935 collect_bounds = true;
2936 draw(tests[testIndex], testLines[testIndex], testTitles[testIndex]);
2937 collect_bounds = false;
2938 if (focusXmin < focusXmax && focusYmin < focusYmax) {
2939 setScale(focusXmin, focusXmax, focusYmin, focusYmax);
2940 }
2941 }
2942 ctx.beginPath();
2943 ctx.fillStyle = "white";
2944 ctx.rect(0, 0, screenWidth, screenHeight);
2945 ctx.fill();
2946 draw(tests[testIndex], testLines[testIndex], testTitles[testIndex]);
2947}
2948
2949function dumpCurvePartial(test, id, t0, t1) {
2950 var curve = curveByID(test, id);
2951 var name = ["line", "quad", "cubic"][curve.length / 2 - 2];
2952 console.log("id=" + id + " " + name + "=" + curveToString(curve)
2953 + " t0=" + t0 + " t1=" + t1
2954 + " partial=" + curveToString(curvePartialByID(test, id, t0, t1)));
2955}
2956
2957function dumpAngleTest(test, id, t0, t1) {
2958 var curve = curveByID(test, id);
2959 console.log(" { {" + curveToString(curve) + "}, "
2960 + curve.length / 2 + ", " + t0 + ", " + t1 + ", {} }, //");
2961}
2962
2963function dumpLogToConsole() {
2964 if (logStart < 0) {
2965 return;
2966 }
2967 var test = tests[testIndex];
2968 var recType = REC_TYPE_UNKNOWN;
2969 var records;
2970 for (var index = 0; index < test.length; index += 3) {
2971 var lastLineNo = test[index + 1];
2972 if (lastLineNo >= logStart && lastLineNo < logStart + logRange) {
2973 recType = test[index];
2974 records = test[index + 2];
2975 break;
2976 }
2977 }
2978 if (recType == REC_TYPE_UNKNOWN) {
2979 return;
2980 }
2981 var lines = testLines[testIndex];
2982 for (var idx = 0; idx < logRange; ++idx) {
2983 var line = lines[logStart + idx];
2984 console.log(line);
2985 for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) {
2986 var fragType = records[recordIndex];
2987 var frags = records[recordIndex + 1];
2988 if (recType == REC_TYPE_ANGLE && fragType == ANGLE_AFTER) {
2989 dumpCurvePartial(test, frags[0], frags[3], frags[4]);
2990 dumpCurvePartial(test, frags[5], frags[8], frags[9]);
2991 dumpCurvePartial(test, frags[10], frags[13], frags[14]);
2992 console.log("\nstatic IntersectData intersectDataSet[] = {");
2993 dumpAngleTest(test, frags[0], frags[3], frags[4]);
2994 dumpAngleTest(test, frags[5], frags[8], frags[9]);
2995 dumpAngleTest(test, frags[10], frags[13], frags[14]);
2996 console.log("};");
2997 } else if (recType == REC_TYPE_ANGLE && fragType == ANGLE_AFTER2) {
2998 dumpCurvePartial(test, frags[0], frags[4], frags[5]);
2999 dumpCurvePartial(test, frags[6], frags[10], frags[11]);
3000 dumpCurvePartial(test, frags[12], frags[16], frags[17]);
3001 console.log("\nstatic IntersectData intersectDataSet[] = { //");
3002 dumpAngleTest(test, frags[0], frags[4], frags[5]);
3003 dumpAngleTest(test, frags[6], frags[10], frags[11]);
3004 dumpAngleTest(test, frags[12], frags[16], frags[17]);
3005 console.log("}; //");
3006 }
3007 }
3008 }
3009}
3010
3011var activeKey = 'a';
3012var pathKey = 'b';
3013var pathBackKey = 'B';
3014var centerKey = 'c';
3015var addKey = 'd';
3016var deriviativesKey = 'f';
3017var angleKey = 'g';
3018var angleBackKey = 'G';
3019var hodoKey = 'h';
3020var intersectionKey = 'i';
3021var intersectionBackKey = 'I';
3022var sequenceKey = 'j';
3023var midpointKey = 'k';
3024var logKey = 'l';
3025var logToConsoleKey = 'L';
3026var markKey = 'm';
3027var sortKey = 'o';
3028var opKey = 'p';
3029var opBackKey = 'P';
3030var computedKey = 'q';
3031var computedBackKey = 'Q';
3032var stepKey = 's';
3033var stepBackKey = 'S';
3034var intersectTKey = 't';
3035var curveTKey = 'u';
3036var controlLinesBackKey = 'V';
3037var controlLinesKey = 'v';
3038var ptsKey = 'x';
3039var xyKey = 'y';
3040var logCurvesKey = 'z';
3041var focusKey = '`';
3042var idKey = '.';
3043var retinaKey = '\\';
3044
3045function doKeyPress(evt) {
3046 var char = String.fromCharCode(evt.charCode);
3047 var focusWasOn = false;
3048 switch (char) {
3049 case '0':
3050 case '1':
3051 case '2':
3052 case '3':
3053 case '4':
3054 case '5':
3055 case '6':
3056 case '7':
3057 case '8':
3058 case '9':
3059 decimal_places = char - '0';
3060 redraw();
3061 break;
3062 case activeKey:
3063 draw_active ^= true;
3064 redraw();
3065 break;
3066 case addKey:
3067 draw_add ^= true;
3068 redraw();
3069 break;
3070 case angleKey:
3071 draw_angle = (draw_angle + 1) % 3;
3072 redraw();
3073 break;
3074 case angleBackKey:
3075 draw_angle = (draw_angle + 2) % 3;
3076 redraw();
3077 break;
3078 case centerKey:
3079 setScale(xmin, xmax, ymin, ymax);
3080 redraw();
3081 break;
3082 case controlLinesBackKey:
3083 control_lines = (control_lines + 3) % 4;
3084 redraw();
3085 break;
3086 case controlLinesKey:
3087 control_lines = (control_lines + 1) % 4;
3088 redraw();
3089 break;
3090 case computedBackKey:
3091 draw_computed = (draw_computed + 5) % 6;
3092 redraw();
3093 break;
3094 case computedKey:
3095 draw_computed = (draw_computed + 1) % 6;
3096 redraw();
3097 break;
3098 case curveTKey:
3099 curve_t ^= true;
3100 if (curve_t) {
3101 draw_legend = true;
3102 }
3103 redraw();
3104 break;
3105 case deriviativesKey:
3106 draw_deriviatives = (draw_deriviatives + 1) % 3;
3107 redraw();
3108 break;
3109 case focusKey:
3110 focus_on_selection ^= true;
3111 setScale(xmin, xmax, ymin, ymax);
3112 redraw();
3113 break;
3114 case hodoKey:
3115 draw_hodo = (draw_hodo + 1) % 4;
3116 redraw();
3117 break;
3118 case idKey:
3119 draw_id ^= true;
3120 redraw();
3121 break;
3122 case intersectionBackKey:
3123 draw_intersection = (draw_intersection + 3) % 4;
3124 redraw();
3125 break;
3126 case intersectionKey:
3127 draw_intersection = (draw_intersection + 1) % 4;
3128 redraw();
3129 break;
3130 case intersectTKey:
3131 draw_intersectT ^= true;
3132 redraw();
3133 break;
3134 case logCurvesKey:
3135 logCurves(tests[testIndex]);
3136 break;
3137 case logKey:
3138 draw_log ^= true;
3139 redraw();
3140 break;
3141 case logToConsoleKey:
3142 if (draw_log) {
3143 dumpLogToConsole();
3144 }
3145 break;
3146 case markKey:
3147 draw_mark ^= true;
3148 redraw();
3149 break;
3150 case midpointKey:
3151 draw_midpoint ^= true;
3152 redraw();
3153 break;
3154 case opKey:
3155 draw_op = (draw_op + 1) % 3;
3156 redraw();
3157 break;
3158 case opBackKey:
3159 draw_op = (draw_op + 2) % 3;
3160 redraw();
3161 break;
3162 case pathKey:
3163 draw_path = (draw_path + 1) % 4;
3164 redraw();
3165 break;
3166 case pathBackKey:
3167 draw_path = (draw_path + 3) % 4;
3168 redraw();
3169 break;
3170 case ptsKey:
3171 pt_labels = (pt_labels + 1) % 3;
3172 redraw();
3173 break;
3174 case retinaKey:
3175 retina_scale ^= true;
3176 drawTop();
3177 break;
3178 case sequenceKey:
3179 draw_sequence ^= true;
3180 redraw();
3181 break;
3182 case sortKey:
3183 draw_sort = (draw_sort + 1) % 3;
3184 drawTop();
3185 break;
3186 case stepKey:
3187 step_limit++;
3188 if (step_limit > stepMax) {
3189 step_limit = stepMax;
3190 }
3191 redraw();
3192 break;
3193 case stepBackKey:
3194 step_limit--;
3195 if (step_limit < 0) {
3196 step_limit = 0;
3197 }
3198 redraw();
3199 break;
3200 case xyKey:
3201 debug_xy = (debug_xy + 1) % 3;
3202 redraw();
3203 break;
3204 case '-':
3205 focusWasOn = focus_on_selection;
3206 if (focusWasOn) {
3207 focus_on_selection = false;
3208 scale /= 1.2;
3209 } else {
3210 scale /= 2;
3211 calcLeftTop();
3212 }
3213 redraw();
3214 focus_on_selection = focusWasOn;
3215 break;
3216 case '=':
3217 case '+':
3218 focusWasOn = focus_on_selection;
3219 if (focusWasOn) {
3220 focus_on_selection = false;
3221 scale *= 1.2;
3222 } else {
3223 scale *= 2;
3224 calcLeftTop();
3225 }
3226 redraw();
3227 focus_on_selection = focusWasOn;
3228 break;
3229 case '?':
3230 draw_hints ^= true;
3231 if (draw_hints && !draw_legend) {
3232 draw_legend = true;
3233 }
3234 redraw();
3235 break;
3236 case '/':
3237 draw_legend ^= true;
3238 redraw();
3239 break;
3240 }
3241}
3242
3243function doKeyDown(evt) {
3244 var char = evt.keyCode;
3245 var preventDefault = false;
3246 switch (char) {
3247 case 37: // left arrow
3248 if (evt.shiftKey) {
3249 testIndex -= 9;
3250 }
3251 if (--testIndex < 0)
3252 testIndex = tests.length - 1;
3253 drawTop();
3254 preventDefault = true;
3255 break;
3256 case 39: // right arrow
3257 if (evt.shiftKey) {
3258 testIndex += 9;
3259 }
3260 if (++testIndex >= tests.length)
3261 testIndex = 0;
3262 drawTop();
3263 preventDefault = true;
3264 break;
3265 }
3266 if (preventDefault) {
3267 evt.preventDefault();
3268 return false;
3269 }
3270 return true;
3271}
3272
3273(function() {
3274 var hidden = "hidden";
3275
3276 // Standards:
3277 if (hidden in document)
3278 document.addEventListener("visibilitychange", onchange);
3279 else if ((hidden = "mozHidden") in document)
3280 document.addEventListener("mozvisibilitychange", onchange);
3281 else if ((hidden = "webkitHidden") in document)
3282 document.addEventListener("webkitvisibilitychange", onchange);
3283 else if ((hidden = "msHidden") in document)
3284 document.addEventListener("msvisibilitychange", onchange);
3285 // IE 9 and lower:
3286 else if ('onfocusin' in document)
3287 document.onfocusin = document.onfocusout = onchange;
3288 // All others:
3289 else
3290 window.onpageshow = window.onpagehide
3291 = window.onfocus = window.onblur = onchange;
3292
3293 function onchange (evt) {
3294 var v = 'visible', h = 'hidden',
3295 evtMap = {
3296 focus:v, focusin:v, pageshow:v, blur:h, focusout:h, pagehide:h
3297 };
3298
3299 evt = evt || window.event;
3300 if (evt.type in evtMap)
3301 document.body.className = evtMap[evt.type];
3302 else
3303 document.body.className = this[hidden] ? "hidden" : "visible";
3304 }
3305})();
3306
3307function calcXY() {
3308 var e = window.event;
3309 var tgt = e.target || e.srcElement;
3310 var left = tgt.offsetLeft;
3311 var top = tgt.offsetTop;
3312 mouseX = (e.clientX - left) / scale + srcLeft;
3313 mouseY = (e.clientY - top) / scale + srcTop;
3314}
3315
3316function calcLeftTop() {
3317 srcLeft = mouseX - screenWidth / 2 / scale;
3318 srcTop = mouseY - screenHeight / 2 / scale;
3319}
3320
3321var disableClick = false;
3322
3323function handleMouseClick() {
3324 if (disableClick) {
3325 return;
3326 }
3327 if (!curve_t || !ptInTControl()) {
3328 calcXY();
3329 calcLeftTop();
3330 }
3331 redraw();
3332// if (!curve_t || !ptInTControl()) {
3333// mouseX = screenWidth / 2 / scale + srcLeft;
3334// mouseY = screenHeight / 2 / scale + srcTop;
3335// }
3336}
3337
3338function handleMouseOver() {
3339 calcXY();
3340 if (debug_xy != 2) {
3341 return;
3342 }
3343 var num = mouseX.toFixed(decimal_places) + ", " + mouseY.toFixed(decimal_places);
3344 ctx.beginPath();
3345 ctx.rect(300,100,num.length * 6,10);
3346 ctx.fillStyle="white";
3347 ctx.fill();
3348 ctx.font = "normal 10px Arial";
3349 ctx.fillStyle="black";
3350 ctx.textAlign = "left";
3351 ctx.fillText(num, 300, 108);
3352}
3353
3354function start() {
3355 for (var i = 0; i < testDivs.length; ++i) {
3356 tests[i] = null;
3357 }
3358 testIndex = 0;
3359 drawTop();
3360 window.addEventListener('keypress', doKeyPress, true);
3361 window.addEventListener('keydown', doKeyDown, true);
3362 window.onresize = function() {
3363 drawTop();
3364 }
3365 /*
3366 window.onpagehide = function() {
3367 disableClick = true;
3368 }
3369 */
3370 window.onpageshow = function () {
3371 disableClick = false;
3372 }
3373}
3374
3375</script>
3376</head>
3377
3378<body onLoad="start();">
3379<canvas id="canvas" width="750" height="500"
3380 onmousemove="handleMouseOver()"
3381 onclick="handleMouseClick()"
3382 ></canvas >
3383</body>
3384</html>