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