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