caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1 | <html> |
| 2 | <head> |
| 3 | <div style="height:0"> |
| 4 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 5 | <div id="cubicOp36u"> |
| 6 | SimplifyNew_Test [cubicOp36u] |
| 7 | {{0,1}, {1,6}, {2,0}, {5,1}}, |
| 8 | {{5,1}, {0,1}}, |
| 9 | op union |
| 10 | {{0,2}, {1,5}, {1,0}, {6,1}}, |
| 11 | {{6,1}, {0,2}}, |
| 12 | debugShowCubicIntersection no self intersect {{0,2}, {1,5}, {1,0}, {6,1}} |
| 13 | debugShowCubicLineIntersection wtTs[0]=0 {{0,2}, {1,5}, {1,0}, {6,1}} {{0,2}} wtTs[1]=0.633333333 {{2.2208888888888882,1.6298518518518521}} wtTs[2]=1 {{6,1}} wnTs[0]=1 {{6,1}, {0,2}} wnTs[1]=0.629851852 wnTs[2]=0 |
| 14 | debugShowCubicIntersection wtTs[0]=0.281761651 {{0,2}, {1,5}, {1,0}, {6,1}} {{0.74132978521392334,2.9436691246202122}} wtTs[1]=0.83051493 {{3.8593908381032738,0.94043932231067462}} wtTs[2]=0.830515061 {{3.8593922073023155,0.94043907360367252}} wtTs[3]=0.867315861 {{4.2597986321159249,0.88613622701319239}} wtTs[4]=0.867316009 {{4.2598003089230945,0.88613607359480184}} wnTs[0]=0.23811 {{0,1}, {1,6}, {2,0}, {5,1}} wnTs[1]=0.860977989 wnTs[2]=0.860978176 wnTs[3]=0.912837717 wnTs[4]=0.912837923 |
| 15 | debugShowCubicLineIntersection wtTs[0]=0.803214143 {{0,2}, {1,5}, {1,0}, {6,1}} {{3.5833594368204942,1}} wnTs[0]=0.283328 {{5,1}, {0,1}} |
| 16 | debugShowCubicLineIntersection wtTs[0]=0.0764226429 {{0,1}, {1,6}, {2,0}, {5,1}} {{0.23016060940409022,1.9616398984326517}} wtTs[1]=0.691654855 {{2.7367211708698314,1.543879804855028}} wnTs[0]=0.96164 {{6,1}, {0,2}} wnTs[1]=0.543879805 |
| 17 | debugShowLineIntersection no intersect {{6,1}, {0,2}} {{5,1}, {0,1}} |
| 18 | debugShowCubicIntersection no self intersect {{0,1}, {1,6}, {2,0}, {5,1}} |
| 19 | debugShowCubicLineIntersection wtTs[0]=0 {{0,1}, {1,6}, {2,0}, {5,1}} {{0,1}} wtTs[1]=0.833333333 {{3.6574074074074132,0.99999999999999789}} wtTs[2]=1 {{5,1}} wnTs[0]=1 {{5,1}, {0,1}} wnTs[1]=0.268518519 wnTs[2]=0 |
| 20 | debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0 (0,2) tEnd=0.281761651 other=4 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0 |
| 21 | debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.281761651 (0.741329789,2.94366908) tEnd=0.633333333 other=1 otherT=0.238109917 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 22 | debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.633333333 (2.22088885,1.62985182) tEnd=0.803214143 other=4 otherT=0.629851852 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 23 | debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.803214143 (3.58335948,1) tEnd=0.83051493 other=2 otherT=0.283328113 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 24 | debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.83051493 (3.85939074,0.940439343) tEnd=0.830515061 other=1 otherT=0.860977989 otherIndex=5 windSum=? windValue=1 oppValue=0 |
| 25 | debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.830515061 (3.85939217,0.940439045) tEnd=0.867315861 other=1 otherT=0.860978176 otherIndex=6 windSum=? windValue=1 oppValue=0 |
| 26 | debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.867315861 (4.25979853,0.886136234) tEnd=0.867316009 other=1 otherT=0.912837717 otherIndex=7 windSum=? windValue=1 oppValue=0 |
| 27 | debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.867316009 (4.25980043,0.886136055) tEnd=1 other=1 otherT=0.912837923 otherIndex=8 windSum=? windValue=1 oppValue=0 |
| 28 | debugShowActiveSpans id=4 (6,1 0,2) t=0 (6,1) tEnd=0.543879805 other=3 otherT=1 otherIndex=8 windSum=? windValue=1 oppValue=0 |
| 29 | debugShowActiveSpans id=4 (6,1 0,2) t=0.543879805 (2.73672128,1.54387975) tEnd=0.629851852 other=1 otherT=0.691654855 otherIndex=3 windSum=? windValue=1 oppValue=0 |
| 30 | debugShowActiveSpans id=4 (6,1 0,2) t=0.629851852 (2.22088885,1.62985182) tEnd=0.961639898 other=3 otherT=0.633333333 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 31 | debugShowActiveSpans id=4 (6,1 0,2) t=0.961639898 (0.230160609,1.96163988) tEnd=1 other=1 otherT=0.0764226429 otherIndex=1 windSum=? windValue=1 oppValue=0 |
| 32 | debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0 (0,1) tEnd=0.0764226429 other=2 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0 |
| 33 | debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.0764226429 (0.230160609,1.96163988) tEnd=0.238109917 other=4 otherT=0.961639898 otherIndex=3 windSum=? windValue=1 oppValue=0 |
| 34 | debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.238109917 (0.741329789,2.94366908) tEnd=0.691654855 other=3 otherT=0.281761651 otherIndex=1 windSum=? windValue=1 oppValue=0 |
| 35 | debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.691654855 (2.73672128,1.54387975) tEnd=0.833333333 other=4 otherT=0.543879805 otherIndex=1 windSum=? windValue=1 oppValue=0 |
| 36 | debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.833333333 (3.65740752,1) tEnd=0.860977989 other=2 otherT=0.268518519 otherIndex=1 windSum=? windValue=1 oppValue=0 |
| 37 | debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.860977989 (3.85939074,0.940439343) tEnd=0.860978176 other=3 otherT=0.83051493 otherIndex=4 windSum=? windValue=1 oppValue=0 |
| 38 | debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.860978176 (3.85939217,0.940439045) tEnd=0.912837717 other=3 otherT=0.830515061 otherIndex=5 windSum=? windValue=1 oppValue=0 |
| 39 | debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.912837717 (4.25979853,0.886136234) tEnd=0.912837923 other=3 otherT=0.867315861 otherIndex=6 windSum=? windValue=1 oppValue=0 |
| 40 | debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.912837923 (4.25980043,0.886136055) tEnd=1 other=3 otherT=0.867316009 otherIndex=7 windSum=? windValue=1 oppValue=0 |
| 41 | debugShowActiveSpans id=2 (5,1 0,1) t=0 (5,1) tEnd=0.268518519 other=1 otherT=1 otherIndex=9 windSum=? windValue=1 oppValue=0 |
| 42 | debugShowActiveSpans id=2 (5,1 0,1) t=0.268518519 (3.65740752,1) tEnd=0.283328113 other=1 otherT=0.833333333 otherIndex=4 windSum=? windValue=1 oppValue=0 |
| 43 | debugShowActiveSpans id=2 (5,1 0,1) t=0.283328113 (3.58335948,1) tEnd=1 other=3 otherT=0.803214143 otherIndex=3 windSum=? windValue=1 oppValue=0 |
| 44 | findTop debugShowSort contourWinding=0 oppContourWinding=0 sign=1 |
| 45 | debugShowSort [0] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=1 tEnd=0.867316009 sign=1 windValue=1 windSum=? 0->-1 (max=-1) done=0 tiny=0 opp=0 |
| 46 | debugShowSort [1] {{6,1}, {0,2}} tStart=0 tEnd=0.543879805 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=0 |
| 47 | findTop xyE=(6,1) xyS=(4.25980043,0.886136055) |
| 48 | findTop dxyE=(15,3) dxyS=(11.3363714,-1.03721189) cross=-49.5672913 bumpsUp=true |
| 49 | markWinding id=3 (0,2 1,5 1,0 6,1) t=0.867316009 [7] (4.25980043,0.886136055) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 |
| 50 | markWinding id=4 (6,1 0,2) t=0 [0] (6,1) tEnd=0.543879805 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 |
| 51 | markWinding id=3 (0,2 1,5 1,0 6,1) t=0.867316009 [7] (4.25980043,0.886136055) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 |
| 52 | activeOp op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1 |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 53 | findNextOp simple |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 54 | markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.867316009 [7] (4.25980043,0.886136055) tEnd=1 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 |
| 55 | bridgeOp current id=3 from=(4.25980043,0.886136055) to=(6,1) |
| 56 | path.moveTo(4.25980043,0.886136055); |
| 57 | path.cubicTo(4.76118517,0.840262294, 5.33658028,0.867316008, 6,1); |
| 58 | findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=1 |
| 59 | debugShowSort [0] {{6,1}, {0,2}} tStart=0.543879805 tEnd=0 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=0 tiny=0 opp=0 |
| 60 | debugShowSort [1] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.691654855 tEnd=0.833333333 sign=-1 windValue=1 windSum=? 0->1 (max=1) done=0 tiny=0 opp=1 |
| 61 | debugShowSort [2] {{6,1}, {0,2}} tStart=0.543879805 tEnd=0.629851852 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=0 |
| 62 | debugShowSort [3] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.691654855 tEnd=0.238109917 sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=1 |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 63 | findNextOp firstIndex=[0] sign=1 |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 64 | activeOp op=union miFrom=0 miTo=1 suFrom=1 suTo=1 result=0 |
| 65 | markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.691654855 [3] (2.73672128,1.54387975) tEnd=0.833333333 newWindSum=1 newOppSum=-1 oppSum=? windSum=? windValue=1 |
| 66 | findNextOp chase.append id=1 |
| 67 | activeOp op=union miFrom=1 miTo=1 suFrom=1 suTo=0 result=0 |
| 68 | markDoneBinary id=4 (6,1 0,2) t=0.543879805 [1] (2.73672128,1.54387975) tEnd=0.629851852 newWindSum=-1 newOppSum=1 oppSum=? windSum=? windValue=1 |
| 69 | findNextOp chase.append id=4 |
| 70 | activeOp op=union miFrom=1 miTo=0 suFrom=0 suTo=0 result=1 |
| 71 | markWinding id=1 (0,1 1,6 2,0 5,1) t=0.238109917 [2] (0.741329789,2.94366908) tEnd=0.691654855 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1 |
| 72 | findNextOp chase.append id=1 |
| 73 | markDoneBinary id=4 (6,1 0,2Program received signal: “EXC_BAD_ACCESS”. |
| 74 | ) t=0 [0] (6,1) tEnd=0.543879805 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 |
| 75 | findNextOp from:[4] to:[1] start=3 end=2 |
| 76 | bridgeOp current id=4 from=(6,1) to=(2.73672128,1.54387975) |
| 77 | findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=-1 |
| 78 | debugShowSort [3] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.238109917 tEnd=0.691654855 sign=-1 windValue=1 windSum=1 0->1 (max=1) done=0 tiny=0 opp=0 |
| 79 | debugShowSort [0] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.281761651 tEnd=0.633333333 sign=-1 windValue=1 windSum=? 0->1 (max=1) done=0 tiny=0 opp=1 |
| 80 | debugShowSort [1] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.238109917 tEnd=0.0764226429 sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=0 |
| 81 | debugShowSort [2] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.281761651 tEnd=0 sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=1 |
| 82 | findNextOp firstIndex=[3] sign=-1 |
| 83 | activeOp op=union miFrom=1 miTo=1 suFrom=0 suTo=1 result=0 |
| 84 | markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.281761651 [1] (0.741329789,2.94366908) tEnd=0.633333333 newWindSum=1 newOppSum=1 oppSum=? windSum=? windValue=1 |
| 85 | findNextOp chase.append id=3 |
| 86 | activeOp op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0 |
| 87 | markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.0764226429 [1] (0.230160609,1.96163988) tEnd=0.238109917 newWindSum=1 newOppSum=1 oppSum=? windSum=? windValue=1 |
| 88 | findNextOp chase.append id=1 |
| 89 | activeOp op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1 |
| 90 | markWinding id=3 (0,2 1,5 1,0 6,1) t=0 [0] (0,2) tEnd=0.281761651 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1 |
| 91 | markWinding id=4 (6,1 0,2) t=0.961639898 [3] (0.230160609,1.96163988) tEnd=1 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1 |
| 92 | findNextOp chase.append id=4 |
| 93 | markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.238109917 [2] (0.741329789,2.94366908) tEnd=0.691654855 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1 |
| 94 | findNextOp from:[1] to:[3] start=1 end=0 |
| 95 | bridgeOp current id=1 from=(2.73672128,1.54387975) to=(0.741329789,2.94366908) |
| 96 | path.lineTo(2.73672128,1.54387975); |
| 97 | path.cubicTo(1.84923673,2.27202392, 1.2463032,3.29839373, 0.741329789,2.94366908); |
| 98 | findNextOp simple |
| 99 | markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0 [0] (0,2) tEnd=0.281761651 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1 |
| 100 | bridgeOp current id=3 from=(0.741329789,2.94366908) to=(0,2) |
| 101 | path.cubicTo(0.484133661,3.05545282, 0.281761646,2.84528494, 0,2); |
| 102 | findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=-1 |
| 103 | debugShowSort [2] {{6,1}, {0,2}} tStart=0.961639898 tEnd=1 sign=-1 windValue=1 windSum=1 0->1 (max=1) done=0 tiny=0 opp=0 |
| 104 | debugShowSort [3] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.0764226429 tEnd=0.238109917 sign=-1 windValue=1 windSum=1 0->1 (max=1) done=1 tiny=0 opp=1 |
| 105 | debugShowSort [0] {{6,1}, {0,2}} tStart=0.961639898 tEnd=0.629851852 sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=0 |
| 106 | debugShowSort [1] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.0764226429 tEnd=0 sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=1 |
| 107 | findNextOp firstIndex=[2] sign=-1 |
| 108 | activeOp op=union miFrom=0 miTo=1 suFrom=1 suTo=1 result=0 |
| 109 | activeOp op=union miFrom=1 miTo=1 suFrom=1 suTo=0 result=0 |
| 110 | markDoneBinary id=4 (6,1 0,2) t=0.629851852 [2] (2.22088885,1.62985182) tEnd=0.961639898 newWindSum=1 newOppSum=1 oppSum=? windSum=? windValue=1 |
| 111 | findNextOp chase.append id=4 |
| 112 | activeOp op=union miFrom=1 miTo=0 suFrom=0 suTo=0 result=1 |
| 113 | markWinding id=1 (0,1 1,6 2,0 5,1) t=0 [0] (0,1) tEnd=0.0764226429 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1 |
| 114 | markWinding id=2 (5,1 0,1) t=0.283328113 [2] (3.58335948,1) tEnd=1 newWindSum=1 newOppSum=0 oppSum=? windSum=? windValue=1 |
| 115 | findNextOp chase.append id=2 |
| 116 | markDoneBinary id=4 (6,1 0,2) t=0.961639898 [3] (0.230160609,1.96163988) tEnd=1 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1 |
| 117 | findNextOp from:[4] to:[1] start=1 end=0 |
| 118 | bridgeOp current id=4 from=(0,2) to=(0.230160609,1.96163988) |
| 119 | findNextOp simple |
| 120 | markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0 [0] (0,1) tEnd=0.0764226429 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1 |
| 121 | bridgeOp current id=1 from=(0.230160609,1.96163988) to=(0,1) |
| 122 | path.lineTo(0.230160609,1.96163988); |
| 123 | path.cubicTo(0.152845293,1.69998181, 0.0764226392,1.38211322, 0,1); |
| 124 | findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=-1 |
| 125 | debugShowSort [1] {{5,1}, {0,1}} tStart=0.283328113 tEnd=1 sign=-1 windValue=1 windSum=1 0->1 (max=1) done=0 tiny=0 opp=0 |
| 126 | debugShowSort [2] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.803214143 tEnd=0.633333333 sign=1 windValue=1 windSum=? 0->-1 (max=-1) done=0 tiny=0 opp=1 |
| 127 | debugShowSort [3] {{5,1}, {0,1}} tStart=0.283328113 tEnd=0.268518519 sign=1 windValue=1 windSum=? 1->0 (max=1) done=0 tiny=0 opp=0 |
| 128 | debugShowSort [0] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.803214143 tEnd=0.83051493 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=1 |
| 129 | findNextOp firstIndex=[1] sign=-1 |
| 130 | activeOp op=union miFrom=1 miTo=1 suFrom=0 suTo=1 result=0 |
| 131 | markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.633333333 [2] (2.22088885,1.62985182) tEnd=0.803214143 newWindSum=-1 newOppSum=1 oppSum=? windSum=? windValue=1 |
| 132 | findNextOp chase.append id=3 |
| 133 | activeOp op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0 |
| 134 | markDoneBinary id=2 (5,1 0,1) t=0.268518519 [1] (3.65740752,1) tEnd=0.283328113 newWindSum=1 newOppSum=-1 oppSum=? windSum=? windValue=1 |
| 135 | findNextOp chase.append id=2 |
| 136 | activeOp op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1 |
| 137 | markWinding id=3 (0,2 1,5 1,0 6,1) t=0.803214143 [3] (3.58335948,1) tEnd=0.83051493 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 |
| 138 | findNextOp chase.append id=3 |
| 139 | markDoneBinary id=2 (5,1 0,1) t=0.283328113 [2] (3.58335948,1) tEnd=1 newWindSum=1 newOppSum=0 oppSum=0 windSum=1 windValue=1 |
| 140 | findNextOp from:[2] to:[3] start=3 end=4 |
| 141 | bridgeOp current id=2 from=(0,1) to=(3.58335948,1) |
| 142 | findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=1 |
| 143 | debugShowSort [0] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.83051493 tEnd=0.803214143 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=0 tiny=0 opp=0 |
| 144 | debugShowSort [1] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.860977989 tEnd=0.833333333 sign=1 windValue=1 windSum=? 0->-1 (max=-1) done=0 tiny=0 opp=1 |
| 145 | debugShowSort [2] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.860977989 tEnd=0.860978176 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=1 |
| 146 | debugShowSort [3] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.83051493 tEnd=0.830515061 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=0 |
| 147 | findNextOp firstIndex=[0] sign=1 |
| 148 | activeOp op=union miFrom=0 miTo=1 suFrom=1 suTo=1 result=0 |
| 149 | markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.833333333 [4] (3.65740752,1) tEnd=0.860977989 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1 |
| 150 | findNextOp chase.append id=1 |
| 151 | activeOp op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0 |
| 152 | markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.860977989 [5] (3.85939074,0.940439343) tEnd=0.860978176 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1 |
| 153 | findNextOp chase.append id=1 |
| 154 | activeOp op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1 |
| 155 | markWinding id=3 (0,2 1,5 1,0 6,1) t=0.83051493 [4] (3.85939074,0.940439343) tEnd=0.830515061 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 |
| 156 | findNextOp chase.append id=3 |
| 157 | markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.803214143 [3] (3.58335948,1) tEnd=0.83051493 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 |
| 158 | findNextOp from:[3] to:[3] start=4 end=5 |
| 159 | bridgeOp current id=3 from=(3.58335948,1) to=(3.85939074,0.940439343) |
| 160 | path.lineTo(3.58335948,1); |
| 161 | path.cubicTo(3.67248249,0.97763288, 3.76445246,0.957684338, 3.85939074,0.940439343); |
| 162 | findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=1 |
| 163 | debugShowSort [2] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.830515061 tEnd=0.83051493 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=0 tiny=0 opp=0 |
| 164 | debugShowSort [3] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.860978176 tEnd=0.860977989 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=1 |
| 165 | debugShowSort [0] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.830515061 tEnd=0.867315861 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=0 |
| 166 | debugShowSort [1] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.860978176 tEnd=0.912837717 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=1 |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 167 | findNextOp firstIndex=[2] sign=1 |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 168 | activeOp op=union miFrom=0 miTo=1 suFrom=1 suTo=1 result=0 |
| 169 | activeOp op=union miFrom=1 miTo=1 suFrom=1 suTo=0 result=0 |
| 170 | markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.830515061 [5] (3.85939217,0.940439045) tEnd=0.867315861 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1 |
| 171 | findNextOp chase.append id=3 |
| 172 | activeOp op=union miFrom=1 miTo=0 suFrom=0 suTo=0 result=1 |
| 173 | markWinding id=1 (0,1 1,6 2,0 5,1) t=0.860978176 [6] (3.85939217,0.940439045) tEnd=0.912837717 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 |
| 174 | findNextOp chase.append id=1 |
| 175 | markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.83051493 [4] (3.85939074,0.940439343) tEnd=0.830515061 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 |
| 176 | findNextOp from:[3] to:[1] start=6 end=7 |
| 177 | bridgeOp current id=3 from=(3.85939074,0.940439343) to=(3.85939217,0.940439045) |
| 178 | path.cubicTo(3.85939145,0.940439224, 3.85939169,0.940439165, 3.85939217,0.940439045); |
| 179 | findNextOp debugShowSort contourWinding=0 oppContourWinding=0 sign=1 |
| 180 | debugShowSort [0] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.912837717 tEnd=0.860978176 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=0 tiny=0 opp=0 |
| 181 | debugShowSort [1] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.867315861 tEnd=0.830515061 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=1 |
| 182 | debugShowSort [2] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.912837717 tEnd=0.912837923 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=0 |
| 183 | debugShowSort [3] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.867315861 tEnd=0.867316009 sign=-1 windValue=1 windSum=? -1->0 (max=-1) done=0 tiny=0 opp=1 |
| 184 | findNextOp firstIndex=[0] sign=1 |
| 185 | activeOp op=union miFrom=1 miTo=1 suFrom=0 suTo=1 result=0 |
| 186 | activeOp op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0 |
| 187 | markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.912837717 [7] (4.25979853,0.886136234) tEnd=0.912837923 newWindSum=-1 newOppSum=-1 oppSum=? windSum=? windValue=1 |
| 188 | findNextOp chase.append id=1 |
| 189 | activeOp op=union miFrom=0 miTo=0 suFrom=1 suTo=0 result=1 |
| 190 | markWinding id=3 (0,2 1,5 1,0 6,1) t=0.867315861 [6] (4.25979853,0.886136234) tEnd=0.867316009 newWindSum=-1 newOppSum=0 oppSum=? windSum=? windValue=1 |
| 191 | findNextOp chase.append id=3 |
| 192 | markDoneBinary id=1 (0,1 1,6 2,0 5,1) t=0.860978176 [6] (3.85939217,0.940439045) tEnd=0.912837717 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 |
| 193 | findNextOp from:[1] to:[3] start=6 end=7 |
| 194 | bridgeOp current id=1 from=(3.85939217,0.940439045) to=(4.25979853,0.886136234) |
| 195 | path.cubicTo(3.98813701,0.909405351, 4.12151289,0.890467525, 4.25980043,0.886136055); |
| 196 | path.close(); |
| 197 | debugShowActiveSpans id=3 (0,2 1,5 1,0 6,1) t=0.867315861 (4.25979853,0.886136234) tEnd=0.867316009 other=1 otherT=0.912837717 otherIndex=7 windSum=-1 windValue=1 oppValue=0 |
| 198 | debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.912837923 (4.25980043,0.886136055) tEnd=1 other=3 otherT=0.867316009 otherIndex=7 windSum=? windValue=1 oppValue=0 |
| 199 | debugShowActiveSpans id=2 (5,1 0,1) t=0 (5,1) tEnd=0.268518519 other=1 otherT=1 otherIndex=9 windSum=? windValue=1 oppValue=0 |
| 200 | activeOp op=union miFrom=0 miTo=0 suFrom=0 suTo=1 result=1 |
| 201 | findNextOp debugShowSort contourWinding=-1 oppContourWinding=0 sign=-1 |
| 202 | debugShowSort [3] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.867315861 tEnd=0.867316009 sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=0 tiny=0 opp=0 |
| 203 | debugShowSort [0] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.912837717 tEnd=0.860978176 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=1 |
| 204 | debugShowSort [1] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.867315861 tEnd=0.830515061 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=0 |
| 205 | debugShowSort [2] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.912837717 tEnd=0.912837923 sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=1 tiny=0 opp=1 |
| 206 | findNextOp firstIndex=[3] sign=-1 |
| 207 | activeOp op=union miFrom=0 miTo=1 suFrom=0 suTo=0 result=1 |
| 208 | activeOp op=union miFrom=1 miTo=1 suFrom=0 suTo=1 result=0 |
| 209 | activeOp op=union miFrom=1 miTo=0 suFrom=1 suTo=1 result=0 |
| 210 | markDoneBinary id=3 (0,2 1,5 1,0 6,1) t=0.867315861 [6] (4.25979853,0.886136234) tEnd=0.867316009 newWindSum=-1 newOppSum=0 oppSum=0 windSum=-1 windValue=1 |
| 211 | findNextOp from:[3] to:[1] start=7 end=6 |
| 212 | bridgeOp current id=3 from=(4.25980043,0.886136055) to=(4.25979853,0.886136234) |
| 213 | path.moveTo(4.25980043,0.886136055); |
| 214 | path.cubicTo(4.25979948,0.886136115, 4.25979948,0.886136174, 4.25979853,0.886136234); |
| 215 | findNextOp debugShowSort contourWinding=-1 oppContourWinding=0 sign=-1 |
| 216 | debugShowSort [1] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.860978176 tEnd=0.912837717 sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=1 tiny=0 opp=0 |
| 217 | debugShowSort [2] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.830515061 tEnd=0.83051493 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=1 |
| 218 | debugShowSort [3] {{0,1}, {1,6}, {2,0}, {5,1}} tStart=0.860978176 tEnd=0.860977989 sign=1 windValue=1 windSum=-1 0->-1 (max=-1) done=1 tiny=0 opp=0 |
| 219 | debugShowSort [0] {{0,2}, {1,5}, {1,0}, {6,1}} tStart=0.830515061 tEnd=0.867315861 sign=-1 windValue=1 windSum=-1 -1->0 (max=-1) done=1 tiny=0 opp=1 |
| 220 | findNextOp firstIndex=[1] sign=-1 |
| 221 | activeOp op=union miFrom=0 miTo=0 suFrom=0 suTo=1 result=1 |
| 222 | activeOp op=union miFrom=0 miTo=1 suFrom=1 suTo=1 result=0 |
| 223 | activeOp op=union miFrom=1 miTo=1 suFrom=1 suTo=0 result=0 |
| 224 | findNextOp from:[1] to:[3] start=5 end=4 |
| 225 | bridgeOp current id=1 from=(4.25979853,0.886136234) to=(3.85939217,0.940439045) |
| 226 | path.cubicTo(4.12151289,0.890467525, 3.98813701,0.909405351, 3.85939217,0.940439045); |
| 227 | debugShowActiveSpans id=1 (0,1 1,6 2,0 5,1) t=0.912837923 (4.25980043,0.886136055) tEnd=1 other=3 otherT=0.867316009 otherIndex=7 windSum=? windValue=1 oppValue=0 |
| 228 | debugShowActiveSpans id=2 (5,1 0,1) t=0 (5,1) tEnd=0.268518519 other=1 otherT=1 otherIndex=9 windSum=? windValue=1 oppValue=0 |
| 229 | </div> |
| 230 | |
| 231 | <div id="cubicOp35da"> |
| 232 | {{x = 0.44618727783085621, y = 2.2840286415243063}, {x = 0.51170845243761109, y = 2.4044088819954914}, {x = 0.57783675570457882, y = 2.4985733182515446}, {x = 0.64483584772311509, y = 2.5694222112973661}} |
| 233 | {{x = 0.64244110111854291, y = 2.5673840215265367}, {x = 0.63479413812245555, y = 2.5620057200094775}, {x = 0.64115438240274059, y = 2.533597555954064}, {x = 0.6620248993310307, y = 2.4876932484482714}} |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 234 | </div> |
| 235 | |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 236 | </div> |
| 237 | |
| 238 | <script type="text/javascript"> |
| 239 | |
| 240 | var testDivs = [ |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 241 | cubicOp36u, |
| 242 | cubicOp35da, |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 243 | ]; |
| 244 | |
| 245 | var decimal_places = 3; // make this 3 to show more precision |
| 246 | |
| 247 | var tests = []; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 248 | var testLines = []; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 249 | var testTitles = []; |
| 250 | var testIndex = 0; |
| 251 | var ctx; |
| 252 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 253 | var xmin, xmax; |
| 254 | var ymin, ymax; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 255 | var scale; |
| 256 | var mouseX, mouseY; |
| 257 | var srcLeft, srcTop; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 258 | var screenWidth, screenHeight; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 259 | var drawnPts, drawnLines, drawnQuads, drawnCubics; |
| 260 | var curveT = 0; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 261 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 262 | var pt_labels = true; |
| 263 | var control_lines = false; |
| 264 | var curve_t = false; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 265 | var debug_xy = false; |
| 266 | var info_mode = false; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 267 | var step_limit = 0; |
| 268 | var draw_active = false; |
| 269 | var draw_add = false; |
| 270 | var draw_intersection = false; |
| 271 | var draw_intersectT = false; |
| 272 | var draw_legend = false; |
| 273 | var draw_log = false; |
| 274 | var draw_mark = false; |
| 275 | var draw_sort = false; |
| 276 | var draw_path = true; |
| 277 | var draw_computed = 0; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 278 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 279 | var SPAN_ID = 0; |
| 280 | var SPAN_X1 = SPAN_ID + 1; |
| 281 | var SPAN_Y1 = SPAN_X1 + 1; |
| 282 | var SPAN_X2 = SPAN_Y1 + 1; |
| 283 | var SPAN_Y2 = SPAN_X2 + 1; |
| 284 | var SPAN_L_T = SPAN_Y2 + 1; |
| 285 | var SPAN_L_TX = SPAN_L_T + 1; |
| 286 | var SPAN_L_TY = SPAN_L_TX + 1; |
| 287 | var SPAN_L_TEND = SPAN_L_TY + 1; |
| 288 | var SPAN_L_OTHER = SPAN_L_TEND + 1; |
| 289 | var SPAN_L_OTHERT = SPAN_L_OTHER + 1; |
| 290 | var SPAN_L_OTHERI = SPAN_L_OTHERT + 1; |
| 291 | var SPAN_L_SUM = SPAN_L_OTHERI + 1; |
| 292 | var SPAN_L_VAL = SPAN_L_SUM + 1; |
| 293 | var SPAN_L_OPP = SPAN_L_VAL + 1; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 294 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 295 | var SPAN_X3 = SPAN_Y2 + 1; |
| 296 | var SPAN_Y3 = SPAN_X3 + 1; |
| 297 | var SPAN_Q_T = SPAN_Y3 + 1; |
| 298 | var SPAN_Q_TX = SPAN_Q_T + 1; |
| 299 | var SPAN_Q_TY = SPAN_Q_TX + 1; |
| 300 | var SPAN_Q_TEND = SPAN_Q_TY + 1; |
| 301 | var SPAN_Q_OTHER = SPAN_Q_TEND + 1; |
| 302 | var SPAN_Q_OTHERT = SPAN_Q_OTHER + 1; |
| 303 | var SPAN_Q_OTHERI = SPAN_Q_OTHERT + 1; |
| 304 | var SPAN_Q_SUM = SPAN_Q_OTHERI + 1; |
| 305 | var SPAN_Q_VAL = SPAN_Q_SUM + 1; |
| 306 | var SPAN_Q_OPP = SPAN_Q_VAL + 1; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 307 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 308 | var SPAN_X4 = SPAN_Y3 + 1; |
| 309 | var SPAN_Y4 = SPAN_X4 + 1; |
| 310 | var SPAN_C_T = SPAN_Y4 + 1; |
| 311 | var SPAN_C_TX = SPAN_C_T + 1; |
| 312 | var SPAN_C_TY = SPAN_C_TX + 1; |
| 313 | var SPAN_C_TEND = SPAN_C_TY + 1; |
| 314 | var SPAN_C_OTHER = SPAN_C_TEND + 1; |
| 315 | var SPAN_C_OTHERT = SPAN_C_OTHER + 1; |
| 316 | var SPAN_C_OTHERI = SPAN_C_OTHERT + 1; |
| 317 | var SPAN_C_SUM = SPAN_C_OTHERI + 1; |
| 318 | var SPAN_C_VAL = SPAN_C_SUM + 1; |
| 319 | var SPAN_C_OPP = SPAN_C_VAL + 1; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 320 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 321 | var ACTIVE_LINE_SPAN = 1; |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 322 | var ACTIVE_QUAD_SPAN = ACTIVE_LINE_SPAN + 1; |
| 323 | var ACTIVE_CUBIC_SPAN = ACTIVE_QUAD_SPAN + 1; |
| 324 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 325 | var ADD_MOVETO = ACTIVE_CUBIC_SPAN + 1; |
| 326 | var ADD_LINETO = ADD_MOVETO + 1; |
| 327 | var ADD_QUADTO = ADD_LINETO + 1; |
| 328 | var ADD_CUBICTO = ADD_QUADTO + 1; |
| 329 | var ADD_CLOSE = ADD_CUBICTO + 1; |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 330 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 331 | var PATH_LINE = ADD_CLOSE + 1; |
| 332 | var PATH_QUAD = PATH_LINE + 1; |
| 333 | var PATH_CUBIC = PATH_QUAD + 1; |
| 334 | |
| 335 | var INTERSECT_LINE = PATH_CUBIC + 1; |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 336 | var INTERSECT_LINE_2 = INTERSECT_LINE + 1; |
| 337 | var INTERSECT_LINE_NO = INTERSECT_LINE_2 + 1; |
| 338 | var INTERSECT_QUAD_LINE = INTERSECT_LINE_NO + 1; |
| 339 | var INTERSECT_QUAD_LINE_2 = INTERSECT_QUAD_LINE + 1; |
| 340 | var INTERSECT_QUAD_LINE_NO = INTERSECT_QUAD_LINE_2 + 1; |
| 341 | var INTERSECT_QUAD = INTERSECT_QUAD_LINE_NO + 1; |
| 342 | var INTERSECT_QUAD_2 = INTERSECT_QUAD + 1; |
| 343 | var INTERSECT_QUAD_NO = INTERSECT_QUAD_2 + 1; |
| 344 | var INTERSECT_SELF_CUBIC = INTERSECT_QUAD_NO + 1; |
| 345 | var INTERSECT_SELF_CUBIC_NO = INTERSECT_SELF_CUBIC + 1; |
| 346 | var INTERSECT_CUBIC_LINE = INTERSECT_SELF_CUBIC_NO + 1; |
| 347 | var INTERSECT_CUBIC_LINE_2 = INTERSECT_CUBIC_LINE + 1; |
| 348 | var INTERSECT_CUBIC_LINE_3 = INTERSECT_CUBIC_LINE_2 + 1; |
| 349 | var INTERSECT_CUBIC_LINE_NO = INTERSECT_CUBIC_LINE_3 + 1; |
| 350 | // FIXME: add cubic/quad |
| 351 | var INTERSECT_CUBIC = INTERSECT_CUBIC_LINE_NO + 1; |
| 352 | var INTERSECT_CUBIC_2 = INTERSECT_CUBIC + 1; |
| 353 | var INTERSECT_CUBIC_3 = INTERSECT_CUBIC_2 + 1; |
| 354 | var INTERSECT_CUBIC_4 = INTERSECT_CUBIC_3 + 1; |
| 355 | // FIXME: add cubic 5- 9 |
| 356 | var INTERSECT_CUBIC_NO = INTERSECT_CUBIC_4 + 1; |
| 357 | |
| 358 | var SORT_LINE = INTERSECT_CUBIC_NO + 1; |
| 359 | var SORT_QUAD = SORT_LINE + 1; |
| 360 | var SORT_CUBIC = SORT_QUAD + 1; |
| 361 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 362 | var OP_DIFFERENCE = SORT_CUBIC + 1; |
| 363 | var OP_INTERSECT = OP_DIFFERENCE + 1; |
| 364 | var OP_UNION = OP_INTERSECT + 1; |
| 365 | var OP_XOR = OP_UNION + 1; |
| 366 | |
| 367 | var MARK_LINE = OP_XOR + 1; |
| 368 | var MARK_QUAD = MARK_LINE + 1; |
| 369 | var MARK_CUBIC = MARK_QUAD + 1; |
| 370 | var MARK_DONE_LINE = MARK_CUBIC + 1; |
| 371 | var MARK_DONE_QUAD = MARK_DONE_LINE + 1; |
| 372 | var MARK_DONE_CUBIC = MARK_DONE_QUAD + 1; |
| 373 | |
| 374 | var COMPUTED_ORIGINAL = MARK_DONE_CUBIC + 1; |
| 375 | var COMPUTED_QUAD = COMPUTED_ORIGINAL + 1; |
| 376 | |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 377 | var REC_TYPE_UNKNOWN = -1; |
| 378 | var REC_TYPE_PATH = 0; |
| 379 | var REC_TYPE_SECT = 1; |
| 380 | var REC_TYPE_ACTIVE = 2; |
| 381 | var REC_TYPE_ADD = 3; |
| 382 | var REC_TYPE_SORT = 4; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 383 | var REC_TYPE_OP = 5; |
| 384 | var REC_TYPE_MARK = 6; |
| 385 | var REC_TYPE_COMPUTED = 7; |
| 386 | var REC_TYPE_LAST = REC_TYPE_COMPUTED; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 387 | |
| 388 | function strs_to_nums(strs) { |
| 389 | var result = []; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 390 | for (var idx = 1; idx < strs.length; ++idx) { |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 391 | var str = strs[idx]; |
| 392 | var num = parseFloat(str); |
| 393 | if (isNaN(num)) { |
| 394 | result.push(str); |
| 395 | } else { |
| 396 | result.push(num); |
| 397 | } |
| 398 | } |
| 399 | return result; |
| 400 | } |
| 401 | |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 402 | function construct_regexp(pattern) { |
| 403 | var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); |
| 404 | escape = escape.replace(/PT_VAL/g, "(\\d+\\.?\\d*),(\\d+\\.?\\d*)"); |
| 405 | escape = escape.replace(/T_VAL/g, "(\\d+\\.?\\d*e?-?\\d*)"); |
| 406 | escape = escape.replace(/IDX/g, "(\\d+)"); |
| 407 | escape = escape.replace(/OPT/g, "(\\?|-?\\d+)"); |
| 408 | return new RegExp(escape, 'i'); |
| 409 | } |
| 410 | |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 411 | function parse_debugShowActiveSpans(test, title) { |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 412 | var re_cubic = construct_regexp(" id=IDX (PT_VAL PT_VAL PT_VAL PT_VAL) t=T_VAL (PT_VAL) tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=IDX"); |
| 413 | var re_quad = construct_regexp(" id=IDX (PT_VAL PT_VAL PT_VAL) t=T_VAL (PT_VAL) tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=IDX"); |
| 414 | var re_line = construct_regexp(" id=IDX (PT_VAL PT_VAL) t=T_VAL (PT_VAL) tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=IDX"); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 415 | |
| 416 | var strs = test.split("debugShowActiveSpans"); |
| 417 | if (strs.length == 1) |
| 418 | return; |
| 419 | var spans = []; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 420 | for (var s = 0; s < strs.length; ++s) { |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 421 | var str = strs[s]; |
| 422 | if (str == "\n") { |
| 423 | continue; |
| 424 | } |
| 425 | if (re_line.test(str)) { |
| 426 | var lineStrs = re_line.exec(str); |
| 427 | var line = strs_to_nums(lineStrs); |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 428 | spans.push(ACTIVE_LINE_SPAN); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 429 | spans.push(line); |
| 430 | } else if (re_quad.test(str)) { |
| 431 | var quadStrs = re_quad.exec(str); |
| 432 | var quad = strs_to_nums(quadStrs); |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 433 | spans.push(ACTIVE_QUAD_SPAN); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 434 | spans.push(quad); |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 435 | } else if (re_cubic.test(str)) { |
| 436 | var cubicStrs = re_cubic.exec(str); |
| 437 | var cubic = strs_to_nums(cubicStrs); |
| 438 | spans.push(ACTIVE_CUBIC_SPAN); |
| 439 | spans.push(cubic); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 440 | } |
| 441 | } |
| 442 | if (spans.length >= 1) { |
| 443 | tests.push(spans); |
| 444 | testTitles.push(title); |
| 445 | } |
| 446 | } |
| 447 | |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 448 | function filter_str_by(id, str, regex, array) { |
| 449 | if (regex.test(str)) { |
| 450 | var strs = regex.exec(str); |
| 451 | var result = strs_to_nums(strs); |
| 452 | array.push(id); |
| 453 | array.push(result); |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 454 | return true; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 455 | } |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 456 | return false; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 457 | } |
| 458 | |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 459 | // FIXME: add cubic support |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 460 | function parse_intersections(test, title) { |
| 461 | var re_quad_line = construct_regexp(" wtTs[0]=T_VAL (PT_VAL PT_VAL PT_VAL) (PT_VAL) wnTs[0]=T_VAL (PT_VAL PT_VAL) (PT_VAL)"); |
| 462 | var re_quad_line_2 = construct_regexp(" wtTs[0]=T_VAL (PT_VAL PT_VAL PT_VAL) (PT_VAL) wtTs[1]=T_VAL (PT_VAL) wnTs[0]=T_VAL (PT_VAL PT_VAL) (PT_VAL) wnTs[1]=T_VAL (PT_VAL)"); |
| 463 | var re_quad_line_no_intersect = construct_regexp(" no intersect (PT_VAL PT_VAL PT_VAL) (PT_VAL PT_VAL)"); |
| 464 | var re_quad = construct_regexp(" wtTs[0]=T_VAL (PT_VAL PT_VAL PT_VAL) (PT_VAL) wnTs[0]=T_VAL (PT_VAL PT_VAL PT_VAL) (PT_VAL)"); |
| 465 | var re_quad_2 = construct_regexp(" wtTs[0]=T_VAL (PT_VAL PT_VAL PT_VAL) (PT_VAL) wtTs[1]=T_VAL wnTs[0]=T_VAL (PT_VAL PT_VAL PT_VAL) (PT_VAL) wnTs[1]=T_VAL"); |
| 466 | var re_quad_no_intersect = construct_regexp(" no intersect (PT_VAL PT_VAL PT_VAL) (PT_VAL PT_VAL PT_VAL)"); |
| 467 | |
| 468 | var strs = test.split(/debugShow[A-Za-z]+Intersection/); |
| 469 | if (strs.length == 1) |
| 470 | return; |
| 471 | var spans = []; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 472 | for (var s = 0; s < strs.length; ++s) { |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 473 | var str = strs[s]; |
| 474 | if (str == "\n") { |
| 475 | continue; |
| 476 | } |
| 477 | filter_str_by(INTERSECT_QUAD_LINE, str, re_quad_line, spans); |
| 478 | filter_str_by(INTERSECT_QUAD_LINE_2, str, re_quad_line_2, spans); |
| 479 | filter_str_by(INTERSECT_QUAD_LINE_NO, str, re_quad_line_no_intersect, spans); |
| 480 | filter_str_by(INTERSECT_QUAD, str, re_quad, spans); |
| 481 | filter_str_by(INTERSECT_QUAD_2, str, re_quad_2, spans); |
| 482 | filter_str_by(INTERSECT_QUAD_NO, str, re_quad_no_intersect, spans); |
| 483 | } |
| 484 | if (spans.length >= 1) { |
| 485 | tests.push(spans); |
| 486 | testTitles.push(title); |
| 487 | } |
| 488 | } |
| 489 | |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 490 | function construct_regexp2(pattern) { |
| 491 | var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); |
| 492 | escape = escape.replace(/CUBIC_VAL/g, "\\(P_VAL P_VAL P_VAL P_VAL\\)"); |
| 493 | escape = escape.replace(/QUAD_VAL/g, "\\(P_VAL P_VAL P_VAL\\)"); |
| 494 | escape = escape.replace(/LINE_VAL/g, "\\(P_VAL P_VAL\\)"); |
| 495 | escape = escape.replace(/PT_VAL/g, "\\(P_VAL\\)"); |
| 496 | escape = escape.replace(/P_VAL/g, "(\\d+\\.?\\d*),(\\d+\\.?\\d*)"); |
| 497 | escape = escape.replace(/T_VAL/g, "(\\d+\\.?\\d*e?-?\\d*)"); |
| 498 | escape = escape.replace(/IDX/g, "(\\d+)"); |
| 499 | escape = escape.replace(/NUM/g, "(-?\\d+)"); |
| 500 | escape = escape.replace(/OPT/g, "(\\?|-?\\d+)"); |
| 501 | return new RegExp(escape, 'i'); |
| 502 | } |
| 503 | |
| 504 | function construct_regexp2c(pattern) { |
| 505 | var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); |
| 506 | escape = escape.replace(/CUBIC_VAL/g, "\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}"); |
| 507 | escape = escape.replace(/QUAD_VAL/g, "\\{\\{P_VAL\\}, \\{P_VAL\\}, \\{P_VAL\\}\\}"); |
| 508 | escape = escape.replace(/LINE_VAL/g, "\\{\\{P_VAL\\}, \\{P_VAL\\}\\}"); |
| 509 | escape = escape.replace(/PT_VAL/g, "\\{\\{P_VAL\\}\\}"); |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 510 | escape = escape.replace(/P_VAL/g, "(?:x = )?(\\d+\\.?\\d*),(?: y = )?(\\d+\\.?\\d*)"); |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 511 | escape = escape.replace(/T_VAL/g, "(\\d+\\.?\\d*e?-?\\d*)"); |
| 512 | escape = escape.replace(/IDX/g, "(\\d+)"); |
| 513 | escape = escape.replace(/NUM/g, "(-?\\d+)"); |
| 514 | escape = escape.replace(/OPT/g, "(\\?|-?\\d+)"); |
| 515 | return new RegExp(escape, 'i'); |
| 516 | } |
| 517 | |
| 518 | function match_regexp(str, lineNo, array, id, pattern) { |
| 519 | var regex = construct_regexp2(pattern); |
| 520 | if (filter_str_by(id, str, regex, array)) { |
| 521 | return true; |
| 522 | } |
| 523 | regex = construct_regexp2c(pattern); |
| 524 | return filter_str_by(id, str, regex, array); |
| 525 | } |
| 526 | |
| 527 | function parse_all(test, title) { |
| 528 | var lines = test.match(/[^\r\n]+/g); |
| 529 | var records = []; // a rec can be the original paths, a set of intersections, a set of active spans, a sort, or a path add |
| 530 | var record = []; |
| 531 | var recType = REC_TYPE_UNKNOWN; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 532 | var lastLineNo; |
| 533 | for (var lineNo = 0; lineNo < lines.length; ++lineNo) { |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 534 | var line = lines[lineNo]; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 535 | if (line.length == 0) { |
| 536 | continue; |
| 537 | } |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 538 | var type = line.lastIndexOf("debugShowSort", 0) === 0 ? REC_TYPE_SORT |
| 539 | : line.lastIndexOf("debugShowActiveSpans", 0) === 0 ? REC_TYPE_ACTIVE |
| 540 | : line.lastIndexOf("debugShow", 0) === 0 ? REC_TYPE_SECT |
| 541 | : line.lastIndexOf("path.", 0) === 0 ? REC_TYPE_ADD |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 542 | : line.lastIndexOf("mark", 0) === 0 ? REC_TYPE_MARK |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 543 | : line.lastIndexOf("{{", 0) === 0 ? REC_TYPE_PATH |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 544 | : line.lastIndexOf(" {{", 0) === 0 ? REC_TYPE_COMPUTED |
| 545 | : line.lastIndexOf("op", 0) === 0 ? REC_TYPE_OP |
| 546 | : line.lastIndexOf("computed", 0) === 0 ? REC_TYPE_COMPUTED |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 547 | : REC_TYPE_UNKNOWN; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 548 | if (recType != type || recType == REC_TYPE_ADD) { |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 549 | if (recType != REC_TYPE_UNKNOWN) { |
| 550 | records.push(recType); |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 551 | records.push(lastLineNo); |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 552 | records.push(record); |
| 553 | } |
| 554 | record = []; |
| 555 | recType = type; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 556 | lastLineNo = lineNo; |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 557 | } |
| 558 | var found = false; |
| 559 | switch (recType) { |
| 560 | case REC_TYPE_ACTIVE: |
| 561 | found = match_regexp(line, lineNo, record, ACTIVE_LINE_SPAN, "debugShowActiveSpans" + |
| 562 | " id=IDX LINE_VAL t=T_VAL PT_VAL tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=IDX" |
| 563 | ) || match_regexp(line, lineNo, record, ACTIVE_QUAD_SPAN, "debugShowActiveSpans" + |
| 564 | " id=IDX QUAD_VAL t=T_VAL PT_VAL tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=IDX" |
| 565 | ) || match_regexp(line, lineNo, record, ACTIVE_CUBIC_SPAN, "debugShowActiveSpans" + |
| 566 | " id=IDX CUBIC_VAL t=T_VAL PT_VAL tEnd=T_VAL other=IDX otherT=T_VAL otherIndex=IDX windSum=OPT windValue=IDX oppValue=IDX" |
| 567 | ); |
| 568 | break; |
| 569 | case REC_TYPE_ADD: |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 570 | found = match_regexp(line, lineNo, record, ADD_MOVETO, "path.moveTo(P_VAL);" |
| 571 | ) || match_regexp(line, lineNo, record, ADD_LINETO, "path.lineTo(P_VAL);" |
| 572 | ) || match_regexp(line, lineNo, record, ADD_QUADTO, "path.quadTo(P_VAL, P_VAL);" |
| 573 | ) || match_regexp(line, lineNo, record, ADD_CUBICTO, "path.cubicTo(P_VAL, P_VAL, P_VAL);" |
| 574 | ) || match_regexp(line, lineNo, record, ADD_CLOSE, "path.close();" |
| 575 | ); |
| 576 | break; |
| 577 | case REC_TYPE_COMPUTED: |
| 578 | found = line == "computed quadratics given" |
| 579 | || match_regexp(line, lineNo, record, PATH_QUAD, " QUAD_VAL," |
| 580 | ) || match_regexp(line, lineNo, record, PATH_CUBIC, " CUBIC_VAL," |
| 581 | ); |
| 582 | break; |
| 583 | case REC_TYPE_PATH: |
| 584 | found = match_regexp(line, lineNo, record, PATH_LINE, "LINE_VAL" |
| 585 | ) || match_regexp(line, lineNo, record, PATH_QUAD, "QUAD_VAL" |
| 586 | ) || match_regexp(line, lineNo, record, PATH_CUBIC, "CUBIC_VAL" |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 587 | ); |
| 588 | break; |
| 589 | case REC_TYPE_SECT: |
| 590 | found = match_regexp(line, lineNo, record, INTERSECT_LINE, "debugShowLineIntersection" + |
| 591 | " wtTs[0]=T_VAL LINE_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL" |
| 592 | ) || match_regexp(line, lineNo, record, INTERSECT_LINE_2, "debugShowLineIntersection" + |
| 593 | " wtTs[0]=T_VAL LINE_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL" |
| 594 | ) || match_regexp(line, lineNo, record, INTERSECT_LINE_NO, "debugShowLineIntersection" + |
| 595 | " no intersect LINE_VAL LINE_VAL" |
| 596 | ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE, "debugShowQuadLineIntersection" + |
| 597 | " wtTs[0]=T_VAL QUAD_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL" |
| 598 | ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE_2, "debugShowQuadLineIntersection" + |
| 599 | " wtTs[0]=T_VAL QUAD_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL" |
| 600 | ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_LINE_NO, "debugShowQuadLineIntersection" + |
| 601 | " no intersect QUAD_VAL LINE_VAL" |
| 602 | ) || match_regexp(line, lineNo, record, INTERSECT_QUAD, "debugShowQuadIntersection" + |
| 603 | " wtTs[0]=T_VAL QUAD_VAL PT_VAL wnTs[0]=T_VAL QUAD_VAL" |
| 604 | ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_2, "debugShowQuadIntersection" + |
| 605 | " wtTs[0]=T_VAL QUAD_VAL PT_VAL wtTs[1]=T_VAL wnTs[0]=T_VAL QUAD_VAL wnTs[1]=T_VAL" |
| 606 | ) || match_regexp(line, lineNo, record, INTERSECT_QUAD_NO, "debugShowQuadIntersection" + |
| 607 | " no intersect QUAD_VAL QUAD_VAL" |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 608 | ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE, "debugShowCubicLineIntersection" + |
| 609 | " wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL" |
| 610 | ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_2, "debugShowCubicLineIntersection" + |
| 611 | " wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL LINE_VAL wnTs[1]=T_VAL" |
| 612 | ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_3, "debugShowCubicLineIntersection" + |
| 613 | " 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" |
| 614 | ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_LINE_NO, "debugShowCubicLineIntersection" + |
| 615 | " no intersect CUBIC_VAL LINE_VAL" |
| 616 | ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC, "debugShowCubicIntersection" + |
| 617 | " wtTs[0]=T_VAL CUBIC_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL" |
| 618 | ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_2, "debugShowCubicIntersection" + |
| 619 | " wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL PT_VAL wnTs[0]=T_VAL CUBIC_VAL wnTs[1]=T_VAL" |
| 620 | ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_3, "debugShowCubicIntersection" + |
| 621 | " 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" |
| 622 | ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_4, "debugShowCubicIntersection" + |
| 623 | " 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" |
| 624 | ) || match_regexp(line, lineNo, record, INTERSECT_CUBIC_NO, "debugShowCubicIntersection" + |
| 625 | " no intersect CUBIC_VAL CUBIC_VAL" |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 626 | ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC, "debugShowCubicIntersection" + |
| 627 | " wtTs[0]=T_VAL CUBIC_VAL PT_VAL wtTs[1]=T_VAL" |
| 628 | ) || match_regexp(line, lineNo, record, INTERSECT_SELF_CUBIC_NO, "debugShowCubicIntersection" + |
| 629 | " no self intersect CUBIC_VAL" |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 630 | ); |
| 631 | break; |
| 632 | case REC_TYPE_SORT: |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 633 | found = match_regexp(line, lineNo, record, SORT_LINE, "debugShowSort" + |
| 634 | " [IDX] LINE_VAL tStart=T_VAL tEnd=T_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX" |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 635 | ) || match_regexp(line, lineNo, record, SORT_QUAD, "debugShowSort" + |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 636 | " [IDX] QUAD_VAL tStart=T_VAL tEnd=T_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX" |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 637 | ) || match_regexp(line, lineNo, record, SORT_CUBIC, "debugShowSort" + |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 638 | " [IDX] CUBIC_VAL tStart=T_VAL tEnd=T_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX" |
| 639 | ) || match_regexp(line, lineNo, record, SORT_LINE_COMPACT, "debugShowSort" + |
| 640 | " [IDX] id=IDX line start=IDX PT_VAL end=IDX PT_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX" |
| 641 | ) || match_regexp(line, lineNo, record, SORT_QUAD_COMPACT, "debugShowSort" + |
| 642 | " [IDX] id=IDX quad start=IDX PT_VAL end=IDX PT_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX" |
| 643 | ) || match_regexp(line, lineNo, record, SORT_CUBIC_COMPACT, "debugShowSort" + |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 644 | " [IDX] id=IDX cubic start=IDX PT_VAL end=IDX PT_VAL sign=NUM windValue=IDX windSum=OPT NUM->NUM (max=NUM) done=IDX tiny=IDX opp=IDX" |
| 645 | ); |
| 646 | break; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 647 | case REC_TYPE_MARK: |
| 648 | found = match_regexp(line, lineNo, record, MARK_LINE, "markWinding" + |
| 649 | " id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX" |
| 650 | ) || match_regexp(line, lineNo, record, MARK_QUAD, "markWinding" + |
| 651 | " id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX" |
| 652 | ) || match_regexp(line, lineNo, record, MARK_CUBIC, "markWinding" + |
| 653 | " id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX" |
| 654 | ) || match_regexp(line, lineNo, record, MARK_DONE_LINE, "markDoneBinary" + |
| 655 | " id=IDX LINE_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX" |
| 656 | ) || match_regexp(line, lineNo, record, MARK_DONE_QUAD, "markDoneBinary" + |
| 657 | " id=IDX QUAD_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX" |
| 658 | ) || match_regexp(line, lineNo, record, MARK_DONE_CUBIC, "markDoneBinary" + |
| 659 | " id=IDX CUBIC_VAL t=T_VAL [IDX] PT_VAL tEnd=T_VAL newWindSum=NUM newOppSum=NUM oppSum=OPT windSum=OPT windValue=IDX" |
| 660 | ); |
| 661 | break; |
| 662 | case REC_TYPE_OP: |
| 663 | found = match_regexp(line, lineNo, record, OP_DIFFERENCE, "op difference" |
| 664 | ) || match_regexp(line, lineNo, record, OP_INTERSECT, "op intersect" |
| 665 | ) || match_regexp(line, lineNo, record, OP_UNION, "op union" |
| 666 | ) || match_regexp(line, lineNo, record, OP_XOR, "op xor" |
| 667 | ); |
| 668 | break; |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 669 | case REC_TYPE_UNKNOWN: |
| 670 | found = true; |
| 671 | break; |
| 672 | } |
| 673 | if (!found) { |
| 674 | console.log(line + " [" + lineNo + "] of type " + type + " not found"); |
| 675 | } |
| 676 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 677 | if (recType != REC_TYPE_UNKNOWN) { |
| 678 | records.push(recType); |
| 679 | records.push(lastLineNo); |
| 680 | records.push(record); |
| 681 | } |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 682 | if (records.length >= 1) { |
| 683 | tests.push(records); |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 684 | testLines.push(lines); |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 685 | testTitles.push(title); |
| 686 | } |
| 687 | } |
| 688 | |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 689 | function init(test) { |
| 690 | var canvas = document.getElementById('canvas'); |
| 691 | if (!canvas.getContext) return; |
| 692 | screenWidth = canvas.width = window.innerWidth - 20; |
| 693 | screenHeight = canvas.height = window.innerHeight - 20; |
| 694 | ctx = canvas.getContext('2d'); |
| 695 | xmin = Infinity; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 696 | xmax = -Infinity; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 697 | ymin = Infinity; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 698 | ymax = -Infinity; |
| 699 | for (var testIndex = 0; testIndex < test.length; testIndex += 3) { |
| 700 | var recType = test[testIndex]; |
| 701 | if (!typeof recType == 'number' || recType < REC_TYPE_UNKNOWN || recType > REC_TYPE_LAST) { |
| 702 | console.log("unknown rec type: " + recType); |
| 703 | throw "stop execution"; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 704 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 705 | var records = test[testIndex + 2]; |
| 706 | for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) { |
| 707 | var fragType = records[recordIndex]; |
| 708 | if (!typeof fragType == 'number' || fragType < 1 || recType > SORT_CUBIC) { |
| 709 | console.log("unknown in range frag type: " + fragType); |
| 710 | throw "stop execution"; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 711 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 712 | var frags = records[recordIndex + 1]; |
| 713 | var first = 0; |
| 714 | var last = -1; |
| 715 | var first2 = 0; |
| 716 | var last2 = 0; |
| 717 | switch (recType) { |
| 718 | case REC_TYPE_COMPUTED: |
| 719 | case REC_TYPE_PATH: |
| 720 | switch (fragType) { |
| 721 | case PATH_LINE: |
| 722 | last = 4; |
| 723 | break; |
| 724 | case PATH_QUAD: |
| 725 | last = 6; |
| 726 | break; |
| 727 | case PATH_CUBIC: |
| 728 | last = 8; |
| 729 | break; |
| 730 | default: |
| 731 | console.log("unknown " + (recType == REC_TYPE_PATH ? "REC_TYPE_PATH" |
| 732 | : "REC_TYPE_COMPUTED") + " frag type:" + fragType); |
| 733 | throw "stop execution"; |
| 734 | } |
| 735 | break; |
| 736 | case REC_TYPE_ACTIVE: |
| 737 | first = 1; |
| 738 | switch (fragType) { |
| 739 | case ACTIVE_LINE_SPAN: |
| 740 | last = 5; |
| 741 | break; |
| 742 | case ACTIVE_QUAD_SPAN: |
| 743 | last = 7; |
| 744 | break; |
| 745 | case ACTIVE_CUBIC_SPAN: |
| 746 | last = 9; |
| 747 | break; |
| 748 | default: |
| 749 | console.log("unknown REC_TYPE_ACTIVE frag type: " + fragType); |
| 750 | throw "stop execution"; |
| 751 | } |
| 752 | break; |
| 753 | case REC_TYPE_ADD: |
| 754 | switch (fragType) { |
| 755 | case ADD_MOVETO: |
| 756 | last = 2; |
| 757 | break; |
| 758 | case ADD_LINETO: |
| 759 | last = 2; |
| 760 | break; |
| 761 | case ADD_QUADTO: |
| 762 | last = 4; |
| 763 | break; |
| 764 | case ADD_CUBICTO: |
| 765 | last = 6; |
| 766 | break; |
| 767 | case ADD_CLOSE: |
| 768 | break; |
| 769 | default: |
| 770 | console.log("unknown REC_TYPE_ADD frag type: " + fragType); |
| 771 | throw "stop execution"; |
| 772 | } |
| 773 | break; |
| 774 | case REC_TYPE_SECT: |
| 775 | switch (fragType) { |
| 776 | case INTERSECT_LINE: |
| 777 | first = 1; last = 5; first2 = 8; last2 = 12; |
| 778 | break; |
| 779 | case INTERSECT_LINE_2: |
| 780 | first = 1; last = 5; first2 = 11; last2 = 15; |
| 781 | break; |
| 782 | case INTERSECT_LINE_NO: |
| 783 | first = 0; last = 4; first2 = 4; last2 = 8; |
| 784 | break; |
| 785 | case INTERSECT_QUAD_LINE: |
| 786 | first = 1; last = 7; first2 = 10; last2 = 14; |
| 787 | break; |
| 788 | case INTERSECT_QUAD_LINE_2: |
| 789 | first = 1; last = 7; first2 = 13; last2 = 17; |
| 790 | break; |
| 791 | case INTERSECT_QUAD_LINE_NO: |
| 792 | first = 0; last = 6; first2 = 6; last2 = 10; |
| 793 | break; |
| 794 | case INTERSECT_QUAD: |
| 795 | first = 1; last = 7; first2 = 10; last2 = 16; |
| 796 | break; |
| 797 | case INTERSECT_QUAD_2: |
| 798 | first = 1; last = 7; first2 = 13; last2 = 19; |
| 799 | break; |
| 800 | case INTERSECT_QUAD_NO: |
| 801 | first = 0; last = 6; first2 = 6; last2 = 12; |
| 802 | break; |
| 803 | case INTERSECT_SELF_CUBIC: |
| 804 | first = 1; last = 9; |
| 805 | break; |
| 806 | case INTERSECT_SELF_CUBIC_NO: |
| 807 | first = 0; last = 8; |
| 808 | break; |
| 809 | case INTERSECT_CUBIC_LINE: |
| 810 | first = 1; last = 9; first2 = 12; last2 = 16; |
| 811 | break; |
| 812 | case INTERSECT_CUBIC_LINE_2: |
| 813 | first = 1; last = 9; first2 = 15; last2 = 19; |
| 814 | break; |
| 815 | case INTERSECT_CUBIC_LINE_3: |
| 816 | first = 1; last = 9; first2 = 18; last2 = 22; |
| 817 | break; |
| 818 | case INTERSECT_CUBIC_LINE_NO: |
| 819 | first = 0; last = 8; first2 = 8; last2 = 12; |
| 820 | break; |
| 821 | case INTERSECT_CUBIC: |
| 822 | first = 1; last = 9; first2 = 12; last2 = 20; |
| 823 | break; |
| 824 | case INTERSECT_CUBIC_2: |
| 825 | first = 1; last = 9; first2 = 15; last2 = 23; |
| 826 | break; |
| 827 | case INTERSECT_CUBIC_3: |
| 828 | first = 1; last = 9; first2 = 18; last2 = 26; |
| 829 | break; |
| 830 | case INTERSECT_CUBIC_4: |
| 831 | first = 1; last = 9; first2 = 21; last2 = 29; |
| 832 | break; |
| 833 | case INTERSECT_CUBIC_NO: |
| 834 | first = 0; last = 8; first2 = 8; last2 = 16; |
| 835 | break; |
| 836 | default: |
| 837 | console.log("unknown REC_TYPE_SECT frag type: " + fragType); |
| 838 | throw "stop execution"; |
| 839 | } |
| 840 | break; |
| 841 | default: |
| 842 | continue; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 843 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 844 | for (var idx = first; idx < last; idx += 2) { |
| 845 | xmin = Math.min(xmin, frags[idx]); |
| 846 | xmax = Math.max(xmax, frags[idx]); |
| 847 | ymin = Math.min(ymin, frags[idx + 1]); |
| 848 | ymax = Math.max(ymax, frags[idx + 1]); |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 849 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 850 | for (var idx = first2; idx < last2; idx += 2) { |
| 851 | xmin = Math.min(xmin, frags[idx]); |
| 852 | xmax = Math.max(xmax, frags[idx]); |
| 853 | ymin = Math.min(ymin, frags[idx + 1]); |
| 854 | ymax = Math.max(ymax, frags[idx + 1]); |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 855 | } |
| 856 | } |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 857 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 858 | setScale(); |
| 859 | } |
| 860 | |
| 861 | function setScale() { |
| 862 | var srcWidth = xmax - xmin; |
| 863 | var srcHeight = ymax - ymin; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 864 | var hscale = ctx.canvas.width / srcWidth; |
| 865 | var vscale = ctx.canvas.height / srcHeight; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 866 | scale = Math.min(hscale, vscale); |
| 867 | var invScale = 1 / scale; |
| 868 | var sxmin = xmin - invScale * 5; |
| 869 | var symin = ymin - invScale * 10; |
| 870 | var sxmax = xmax + invScale * (6 * decimal_places + 10); |
| 871 | var symax = ymax + invScale * 10; |
| 872 | srcWidth = sxmax - sxmin; |
| 873 | srcHeight = symax - symin; |
| 874 | hscale = ctx.canvas.width / srcWidth; |
| 875 | vscale = ctx.canvas.height / srcHeight; |
| 876 | scale = Math.min(hscale, vscale); |
| 877 | srcLeft = sxmin; |
| 878 | srcTop = symin; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 879 | } |
| 880 | |
| 881 | function drawPoint(px, py) { |
| 882 | for (var pts = 0; pts < drawnPts.length; pts += 2) { |
| 883 | var x = drawnPts[pts]; |
| 884 | var y = drawnPts[pts + 1]; |
| 885 | if (px == x && py == y) { |
| 886 | return; |
| 887 | } |
| 888 | } |
| 889 | drawnPts.push(px); |
| 890 | drawnPts.push(py); |
| 891 | var label = px.toFixed(decimal_places) + ", " + py.toFixed(decimal_places); |
| 892 | var _px = (px - srcLeft)* scale; |
| 893 | var _py = (py - srcTop) * scale; |
| 894 | ctx.beginPath(); |
| 895 | ctx.arc(_px, _py, 3, 0, Math.PI*2, true); |
| 896 | ctx.closePath(); |
| 897 | ctx.fill(); |
| 898 | ctx.fillText(label, _px + 5, _py); |
| 899 | } |
| 900 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 901 | function drawPoints(ptArray, curveType) { |
| 902 | var count = (curveType - PATH_LINE + 2) * 2; |
| 903 | for (var idx = 0; idx < count; idx += 2) { |
| 904 | drawPoint(ptArray[idx], ptArray[idx + 1]); |
| 905 | } |
| 906 | } |
| 907 | |
| 908 | function drawControlLines(curve, curveType) { |
| 909 | if (curveType == PATH_LINE) { |
| 910 | return; |
| 911 | } |
| 912 | ctx.strokeStyle = "rgba(0,0,0, 0.3)"; |
| 913 | drawLine(curve[0], curve[1], curve[2], curve[3]); |
| 914 | drawLine(curve[2], curve[3], curve[4], curve[5]); |
| 915 | if (curveType == PATH_CUBIC) |
| 916 | drawLine(curve[4], curve[5], curve[4], curve[5]); |
| 917 | } |
| 918 | |
| 919 | function drawPointAtT(curve, curveType) { |
| 920 | var x, y; |
| 921 | var t = curveT; |
| 922 | switch (curveType) { |
| 923 | case PATH_LINE: |
| 924 | var a = 1 - t; |
| 925 | var b = t; |
| 926 | x = a * curve[0] + b * curve[2]; |
| 927 | y = a * curve[1] + b * curve[3]; |
| 928 | break; |
| 929 | case PATH_QUAD: |
| 930 | var one_t = 1 - t; |
| 931 | var a = one_t * one_t; |
| 932 | var b = 2 * one_t * t; |
| 933 | var c = t * t; |
| 934 | x = a * curve[0] + b * curve[2] + c * curve[4]; |
| 935 | y = a * curve[1] + b * curve[3] + c * curve[5]; |
| 936 | break; |
| 937 | case PATH_CUBIC: |
| 938 | var one_t = 1 - t; |
| 939 | var one_t2 = one_t * one_t; |
| 940 | var a = one_t2 * one_t; |
| 941 | var b = 3 * one_t2 * t; |
| 942 | var t2 = t * t; |
| 943 | var c = 3 * one_t * t2; |
| 944 | var d = t2 * t; |
| 945 | x = a * curve[0] + b * curve[2] + c * curve[4] + d * curve[6]; |
| 946 | y = a * curve[1] + b * curve[3] + c * curve[5] + d * curve[7]; |
| 947 | break; |
| 948 | } |
| 949 | drawPoint(x, y); |
| 950 | if (!draw_intersectT) { |
| 951 | return; |
| 952 | } |
| 953 | ctx.fillStyle = "red"; |
| 954 | drawTAtPointUp(x, y, curveT); |
| 955 | } |
| 956 | |
| 957 | function drawTAtPointUp(px, py, t) { |
| 958 | var label = t.toFixed(decimal_places); |
| 959 | var _px = (px - srcLeft)* scale; |
| 960 | var _py = (py - srcTop) * scale; |
| 961 | ctx.fillText(label, _px + 5, _py - 10); |
| 962 | } |
| 963 | |
| 964 | function drawTAtPointDown(px, py, t) { |
| 965 | var label = t.toFixed(decimal_places); |
| 966 | var _px = (px - srcLeft)* scale; |
| 967 | var _py = (py - srcTop) * scale; |
| 968 | ctx.fillText(label, _px + 5, _py + 10); |
| 969 | } |
| 970 | |
| 971 | function drawLine(x1, y1, x2, y2) { |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 972 | for (var pts = 0; pts < drawnLines.length; pts += 4) { |
| 973 | if (x1 == drawnLines[pts] && y1 == drawnLines[pts + 1]) { |
| 974 | return; |
| 975 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 976 | if (x2 == drawnLines[pts + 2] && y2 == drawnLines[pts + 3]) { |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 977 | return; |
| 978 | } |
| 979 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 980 | drawnLines.push(x1); |
| 981 | drawnLines.push(y1); |
| 982 | drawnLines.push(x2); |
| 983 | drawnLines.push(y2); |
| 984 | ctx.beginPath(); |
| 985 | ctx.moveTo((x1 - srcLeft) * scale, |
| 986 | (y1 - srcTop) * scale); |
| 987 | ctx.lineTo((x2 - srcLeft) * scale, |
| 988 | (y2 - srcTop) * scale); |
| 989 | ctx.stroke(); |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 990 | } |
| 991 | |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 992 | function drawLinePartial(x1, y1, x2, y2, t1, t2) { |
| 993 | var dx = x1 - x2; |
| 994 | var dy = y1 - y2; |
| 995 | var ax = x1 - t1 * dx; |
| 996 | var ay = y1 - t1 * dy; |
| 997 | var bx = x1 - t2 * dx; |
| 998 | var by = y1 - t2 * dy; |
| 999 | ctx.beginPath(); |
| 1000 | ctx.moveTo((ax - srcLeft) * scale, |
| 1001 | (ay - srcTop) * scale); |
| 1002 | ctx.lineTo((bx - srcLeft) * scale, |
| 1003 | (by - srcTop) * scale); |
| 1004 | ctx.stroke(); |
| 1005 | } |
| 1006 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1007 | function drawQuad(x1, y1, x2, y2, x3, y3) { |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 1008 | for (var pts = 0; pts < drawnQuads.length; pts += 6) { |
| 1009 | if (x1 == drawnQuads[pts] && y1 == drawnQuads[pts + 1]) { |
| 1010 | return; |
| 1011 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1012 | if (x2 == drawnQuads[pts + 2] && y2 == drawnQuads[pts + 3]) { |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 1013 | return; |
| 1014 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1015 | if (x3 == drawnQuads[pts + 4] && x3 == drawnQuads[pts + 5]) { |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 1016 | return; |
| 1017 | } |
| 1018 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1019 | drawnQuads.push(x1); |
| 1020 | drawnQuads.push(y1); |
| 1021 | drawnQuads.push(x2); |
| 1022 | drawnQuads.push(y2); |
| 1023 | drawnQuads.push(x3); |
| 1024 | drawnQuads.push(y3); |
| 1025 | ctx.beginPath(); |
| 1026 | ctx.moveTo((x1 - srcLeft) * scale, |
| 1027 | (y1 - srcTop) * scale); |
| 1028 | ctx.quadraticCurveTo((x2 - srcLeft) * scale, |
| 1029 | (y2 - srcTop) * scale, |
| 1030 | (x3 - srcLeft) * scale, |
| 1031 | (y3 - srcTop) * scale); |
| 1032 | ctx.stroke(); |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 1033 | } |
| 1034 | |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 1035 | function interp(A, B, t) { |
| 1036 | return A + (B - A) * t; |
| 1037 | } |
| 1038 | |
| 1039 | function interp_quad_coords(x1, x2, x3, t) |
| 1040 | { |
| 1041 | var ab = interp(x1, x2, t); |
| 1042 | var bc = interp(x2, x3, t); |
| 1043 | var abc = interp(ab, bc, t); |
| 1044 | return abc; |
| 1045 | } |
| 1046 | |
| 1047 | function drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2) { |
| 1048 | var ax = interp_quad_coords(x1, x2, x3, t1); |
| 1049 | var ay = interp_quad_coords(y1, y2, y3, t1); |
| 1050 | var dx = interp_quad_coords(x1, x2, x3, (t1 + t2) / 2); |
| 1051 | var dy = interp_quad_coords(y1, y2, y3, (t1 + t2) / 2); |
| 1052 | var cx = interp_quad_coords(x1, x2, x3, t2); |
| 1053 | var cy = interp_quad_coords(y1, y2, y3, t2); |
| 1054 | var bx = 2*dx - (ax + cx)/2; |
| 1055 | var by = 2*dy - (ay + cy)/2; |
| 1056 | ctx.beginPath(); |
| 1057 | ctx.moveTo((ax - srcLeft) * scale, |
| 1058 | (ay - srcTop) * scale); |
| 1059 | ctx.quadraticCurveTo((bx - srcLeft) * scale, |
| 1060 | (by - srcTop) * scale, |
| 1061 | (cx - srcLeft) * scale, |
| 1062 | (cy - srcTop) * scale); |
| 1063 | ctx.stroke(); |
| 1064 | } |
| 1065 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1066 | function drawCubic(x1, y1, x2, y2, x3, y3, x4, y4) { |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 1067 | for (var pts = 0; pts < drawnCubics.length; pts += 8) { |
| 1068 | if (x1 == drawnCubics[pts] && y1 == drawnCubics[pts + 1]) { |
| 1069 | return; |
| 1070 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1071 | if (x2 == drawnCubics[pts + 2] && y2 == drawnCubics[pts + 3]) { |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 1072 | return; |
| 1073 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1074 | if (x3 == drawnCubics[pts + 4] && y3 == drawnCubics[pts + 5]) { |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 1075 | return; |
| 1076 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1077 | if (x4 == drawnCubics[pts + 6] && y4 == drawnCubics[pts + 7]) { |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 1078 | return; |
| 1079 | } |
| 1080 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1081 | drawnCubics.push(x1); |
| 1082 | drawnCubics.push(y1); |
| 1083 | drawnCubics.push(x2); |
| 1084 | drawnCubics.push(y2); |
| 1085 | drawnCubics.push(x3); |
| 1086 | drawnCubics.push(y3); |
| 1087 | drawnCubics.push(x4); |
| 1088 | drawnCubics.push(y4); |
| 1089 | ctx.beginPath(); |
| 1090 | ctx.moveTo((x1 - srcLeft) * scale, |
| 1091 | (y1 - srcTop) * scale); |
| 1092 | ctx.bezierCurveTo((x2 - srcLeft) * scale, |
| 1093 | (y2 - srcTop) * scale, |
| 1094 | (x3 - srcLeft) * scale, |
| 1095 | (y3 - srcTop) * scale, |
| 1096 | (x4 - srcLeft) * scale, |
| 1097 | (y4 - srcTop) * scale); |
| 1098 | ctx.stroke(); |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 1099 | } |
| 1100 | |
| 1101 | function interp_cubic_coords(x1, x2, x3, x4, t) |
| 1102 | { |
| 1103 | var ab = interp(x1, x2, t); |
| 1104 | var bc = interp(x2, x3, t); |
| 1105 | var cd = interp(x3, x4, t); |
| 1106 | var abc = interp(ab, bc, t); |
| 1107 | var bcd = interp(bc, cd, t); |
| 1108 | var abcd = interp(abc, bcd, t); |
| 1109 | return abcd; |
| 1110 | } |
| 1111 | |
| 1112 | function drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2) { |
| 1113 | var ax = interp_cubic_coords(x1, x2, x3, x4, t1); |
| 1114 | var ay = interp_cubic_coords(y1, y2, y3, y4, t1); |
| 1115 | var ex = interp_cubic_coords(x1, x2, x3, x4, (t1*2+t2)/3); |
| 1116 | var ey = interp_cubic_coords(y1, y2, y3, y4, (t1*2+t2)/3); |
| 1117 | var fx = interp_cubic_coords(x1, x2, x3, x4, (t1+t2*2)/3); |
| 1118 | var fy = interp_cubic_coords(y1, y2, y3, y4, (t1+t2*2)/3); |
| 1119 | var dx = interp_cubic_coords(x1, x2, x3, x4, t2); |
| 1120 | var dy = interp_cubic_coords(y1, y2, y3, y4, t2); |
| 1121 | var mx = ex * 27 - ax * 8 - dx; |
| 1122 | var my = ey * 27 - ay * 8 - dy; |
| 1123 | var nx = fx * 27 - ax - dx * 8; |
| 1124 | var ny = fy * 27 - ay - dy * 8; |
| 1125 | var bx = (mx * 2 - nx) / 18; |
| 1126 | var by = (my * 2 - ny) / 18; |
| 1127 | var cx = (nx * 2 - mx) / 18; |
| 1128 | var cy = (ny * 2 - my) / 18; |
| 1129 | ctx.beginPath(); |
| 1130 | ctx.moveTo((ax - srcLeft) * scale, |
| 1131 | (ay - srcTop) * scale); |
| 1132 | ctx.bezierCurveTo((bx - srcLeft) * scale, |
| 1133 | (by - srcTop) * scale, |
| 1134 | (cx - srcLeft) * scale, |
| 1135 | (cy - srcTop) * scale, |
| 1136 | (dx - srcLeft) * scale, |
| 1137 | (dy - srcTop) * scale, |
| 1138 | (ex - srcLeft) * scale, |
| 1139 | (ey - srcTop) * scale); |
| 1140 | ctx.stroke(); |
| 1141 | } |
| 1142 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1143 | function draw(test, lines, title) { |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1144 | ctx.fillStyle = "rgba(0,0,0, 0.1)"; |
| 1145 | ctx.font = "normal 50px Arial"; |
| 1146 | ctx.fillText(title, 50, 50); |
| 1147 | ctx.font = "normal 10px Arial"; |
| 1148 | ctx.lineWidth = "1.001"; "0.999"; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1149 | var moveX, moveY; |
| 1150 | var secondPath = test.length; |
| 1151 | var closeCount = 0; |
| 1152 | var logStart = -1; |
| 1153 | var logRange = 0; |
| 1154 | // find last active rec type at this step |
| 1155 | var curType = test[0]; |
| 1156 | var curStep = 0; |
| 1157 | var lastIndex = test.length - 1; |
| 1158 | var hasOp = false; |
| 1159 | var lastActive = 0; |
| 1160 | var lastSort = 0; |
| 1161 | var lastMark = 0; |
| 1162 | var activeCount = 0; |
| 1163 | var sortCount = 0; |
| 1164 | var markCount = 0; |
| 1165 | for (var testIndex = 0; testIndex < test.length; testIndex += 3) { |
| 1166 | var recType = test[testIndex]; |
| 1167 | if (!typeof recType == 'number' || recType < REC_TYPE_UNKNOWN || recType > REC_TYPE_LAST) { |
| 1168 | console.log("unknown rec type: " + recType); |
| 1169 | throw "stop execution"; |
| 1170 | } |
| 1171 | // if (curType == recType && curType != REC_TYPE_ADD) { |
| 1172 | // continue; |
| 1173 | // } |
| 1174 | if (step_limit > 0 && curStep >= step_limit) { |
| 1175 | break; |
| 1176 | } |
| 1177 | curType = recType; |
| 1178 | if (recType == REC_TYPE_OP) { |
| 1179 | hasOp = true; |
| 1180 | continue; |
| 1181 | } |
| 1182 | if (recType == REC_TYPE_SECT || recType == REC_TYPE_UNKNOWN) { |
| 1183 | // these types do not advance step |
| 1184 | continue; |
| 1185 | } |
| 1186 | if (recType == REC_TYPE_ADD) { |
| 1187 | var records = test[testIndex + 2]; |
| 1188 | if (records.length != 2) { |
| 1189 | console.log("expect only two elements: " + records.length); |
| 1190 | throw "stop execution"; |
| 1191 | } |
| 1192 | var fragType = records[0]; |
| 1193 | if (fragType == ADD_MOVETO || fragType == ADD_CLOSE) { |
| 1194 | continue; |
| 1195 | } |
| 1196 | if (!draw_add) { |
| 1197 | continue; |
| 1198 | } |
| 1199 | } |
| 1200 | if ((recType == REC_TYPE_PATH || recType == REC_TYPE_COMPUTED) && hasOp) { |
| 1201 | secondPath = testIndex; |
| 1202 | } |
| 1203 | if (recType == REC_TYPE_ACTIVE) { |
| 1204 | if (!draw_active) { |
| 1205 | continue; |
| 1206 | } |
| 1207 | lastActive = testIndex; |
| 1208 | ++activeCount; |
| 1209 | } |
| 1210 | if (recType == REC_TYPE_SORT) { |
| 1211 | if (!draw_sort) { |
| 1212 | continue; |
| 1213 | } |
| 1214 | lastSort = testIndex; |
| 1215 | ++sortCount; |
| 1216 | } |
| 1217 | if (recType = REC_TYPE_MARK) { |
| 1218 | if (!draw_mark) { |
| 1219 | continue; |
| 1220 | } |
| 1221 | lastMark = testIndex; |
| 1222 | ++markCount; |
| 1223 | } |
| 1224 | lastIndex = testIndex; |
| 1225 | ++curStep; |
| 1226 | } |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1227 | drawnPts = []; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 1228 | drawnLines = []; |
| 1229 | drawnQuads = []; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 1230 | drawnCubics = []; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1231 | var opLetter = 'S'; |
| 1232 | for (var testIndex = 0; testIndex <= lastIndex; testIndex += 3) { |
| 1233 | var recType = test[testIndex]; |
| 1234 | logStart = test[testIndex + 1]; |
| 1235 | var records = test[testIndex + 2]; |
| 1236 | logRange = records.length / 2; |
| 1237 | for (var recordIndex = 0; recordIndex < records.length; recordIndex += 2) { |
| 1238 | var fragType = records[recordIndex]; |
| 1239 | if (!typeof fragType == 'number' || fragType < 1 || recType > SORT_CUBIC) { |
| 1240 | console.log("unknown in range frag type: " + fragType); |
| 1241 | throw "stop execution"; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 1242 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1243 | var frags = records[recordIndex + 1]; |
| 1244 | switch (recType) { |
| 1245 | case REC_TYPE_COMPUTED: |
| 1246 | if (draw_computed == 0) { |
| 1247 | continue; |
| 1248 | } |
| 1249 | ctx.lineWidth = 1; |
| 1250 | ctx.strokeStyle = testIndex < secondPath ? "black" : "red"; |
| 1251 | ctx.fillStyle = "blue"; |
| 1252 | switch (fragType) { |
| 1253 | case PATH_QUAD: |
| 1254 | if (draw_computed & 1) { |
| 1255 | drawQuad(frags[0], frags[1], frags[2], frags[3], |
| 1256 | frags[4], frags[5]); |
| 1257 | } |
| 1258 | break; |
| 1259 | case PATH_CUBIC: |
| 1260 | if (draw_computed & 2) { |
| 1261 | drawCubic(frags[0], frags[1], frags[2], frags[3], |
| 1262 | frags[4], frags[5], frags[6], frags[7]); |
| 1263 | } |
| 1264 | break; |
| 1265 | default: |
| 1266 | console.log("unknown REC_TYPE_COMPUTED frag type: " + fragType); |
| 1267 | throw "stop execution"; |
| 1268 | } |
| 1269 | if ((draw_computed & (fragType - PATH_LINE)) == 0) { |
| 1270 | break; |
| 1271 | } |
| 1272 | if (pt_labels) { |
| 1273 | drawPoints(frags, fragType); |
| 1274 | } |
| 1275 | if (control_lines) { |
| 1276 | drawControlLines(frags, fragType); |
| 1277 | } |
| 1278 | if (curve_t) { |
| 1279 | drawPointAtT(frags, fragType); |
| 1280 | } |
| 1281 | break; |
| 1282 | case REC_TYPE_PATH: |
| 1283 | if (!draw_path) { |
| 1284 | continue; |
| 1285 | } |
| 1286 | ctx.lineWidth = 1; |
| 1287 | ctx.strokeStyle = testIndex < secondPath ? "black" : "red"; |
| 1288 | ctx.fillStyle = "blue"; |
| 1289 | switch (fragType) { |
| 1290 | case PATH_LINE: |
| 1291 | drawLine(frags[0], frags[1], frags[2], frags[3]); |
| 1292 | break; |
| 1293 | case PATH_QUAD: |
| 1294 | drawQuad(frags[0], frags[1], frags[2], frags[3], |
| 1295 | frags[4], frags[5]); |
| 1296 | break; |
| 1297 | case PATH_CUBIC: |
| 1298 | drawCubic(frags[0], frags[1], frags[2], frags[3], |
| 1299 | frags[4], frags[5], frags[6], frags[7]); |
| 1300 | break; |
| 1301 | default: |
| 1302 | console.log("unknown REC_TYPE_PATH frag type: " + fragType); |
| 1303 | throw "stop execution"; |
| 1304 | } |
| 1305 | if (pt_labels) { |
| 1306 | drawPoints(frags, fragType); |
| 1307 | } |
| 1308 | if (control_lines) { |
| 1309 | drawControlLines(frags, fragType); |
| 1310 | } |
| 1311 | if (curve_t) { |
| 1312 | drawPointAtT(frags, fragType); |
| 1313 | } |
| 1314 | break; |
| 1315 | case REC_TYPE_OP: |
| 1316 | switch (fragType) { |
| 1317 | case OP_INTERSECT: opLetter = 'I'; break; |
| 1318 | case OP_DIFFERENCE: opLetter = 'D'; break; |
| 1319 | case OP_UNION: opLetter = 'U'; break; |
| 1320 | case OP_XOR: opLetter = 'X'; break; |
| 1321 | default: |
| 1322 | console.log("unknown REC_TYPE_OP frag type: " + fragType); |
| 1323 | throw "stop execution"; |
| 1324 | } |
| 1325 | break; |
| 1326 | case REC_TYPE_ACTIVE: |
| 1327 | if (!draw_active || testIndex < lastActive) { |
| 1328 | continue; |
| 1329 | } |
| 1330 | var x1 = frags[SPAN_X1]; |
| 1331 | var y1 = frags[SPAN_Y1]; |
| 1332 | var x2 = frags[SPAN_X2]; |
| 1333 | var y2 = frags[SPAN_Y2]; |
| 1334 | var x3, y3, x3, y4, t1, t2; |
| 1335 | ctx.lineWidth = 3; |
| 1336 | ctx.strokeStyle = "rgba(0,0,255, 0.3)"; |
| 1337 | switch (fragType) { |
| 1338 | case ACTIVE_LINE_SPAN: |
| 1339 | t1 = frags[SPAN_L_T]; |
| 1340 | t2 = frags[SPAN_L_TEND]; |
| 1341 | drawLinePartial(x1, y1, x2, y2, t1, t2); |
| 1342 | break; |
| 1343 | case ACTIVE_QUAD_SPAN: |
| 1344 | x3 = frags[SPAN_X3]; |
| 1345 | y3 = frags[SPAN_Y3]; |
| 1346 | t1 = frags[SPAN_Q_T]; |
| 1347 | t2 = frags[SPAN_Q_TEND]; |
| 1348 | drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2); |
| 1349 | break; |
| 1350 | case ACTIVE_CUBIC_SPAN: |
| 1351 | x3 = frags[SPAN_X3]; |
| 1352 | y3 = frags[SPAN_Y3]; |
| 1353 | x4 = frags[SPAN_X4]; |
| 1354 | y4 = frags[SPAN_Y4]; |
| 1355 | t1 = frags[SPAN_C_T]; |
| 1356 | t2 = frags[SPAN_C_TEND]; |
| 1357 | drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2); |
| 1358 | break; |
| 1359 | default: |
| 1360 | console.log("unknown REC_TYPE_ACTIVE frag type: " + fragType); |
| 1361 | throw "stop execution"; |
| 1362 | } |
| 1363 | break; |
| 1364 | case REC_TYPE_ADD: |
| 1365 | if (!draw_add) { |
| 1366 | continue; |
| 1367 | } |
| 1368 | ctx.lineWidth = 3; |
| 1369 | ctx.strokeStyle = closeCount == 0 ? "rgba(0,0,255, 0.3)" |
| 1370 | : closeCount == 1 ? "rgba(0,127,0, 0.3)" |
| 1371 | : closeCount == 2 ? "rgba(0,127,127, 0.3)" |
| 1372 | : closeCount == 3 ? "rgba(127,127,0, 0.3)" |
| 1373 | : "rgba(127,0,127, 0.3)"; |
| 1374 | switch (fragType) { |
| 1375 | case ADD_MOVETO: |
| 1376 | moveX = frags[0]; |
| 1377 | moveY = frags[1]; |
| 1378 | break; |
| 1379 | case ADD_LINETO: |
| 1380 | drawLine(moveX, moveY, frags[0], frags[1], true); |
| 1381 | moveX = frags[0]; |
| 1382 | moveY = frags[1]; |
| 1383 | break; |
| 1384 | case ADD_QUADTO: |
| 1385 | drawQuad(moveX, moveY, frags[0], frags[1], frags[2], frags[3], true); |
| 1386 | moveX = frags[2]; |
| 1387 | moveY = frags[3]; |
| 1388 | break; |
| 1389 | case ADD_CUBICTO: |
| 1390 | drawCubic(moveX, moveY, frags[0], frags[1], frags[2], frags[3], |
| 1391 | frags[4], frags[5], true); |
| 1392 | moveX = frags[4]; |
| 1393 | moveY = frags[5]; |
| 1394 | break; |
| 1395 | case ADD_CLOSE: |
| 1396 | ++closeCount; |
| 1397 | break; |
| 1398 | default: |
| 1399 | console.log("unknown REC_TYPE_ADD frag type: " + fragType); |
| 1400 | throw "stop execution"; |
| 1401 | } |
| 1402 | break; |
| 1403 | case REC_TYPE_SECT: |
| 1404 | if (!draw_intersection) { |
| 1405 | continue; |
| 1406 | } |
| 1407 | ctx.lineWidth = 1; |
| 1408 | ctx.strokeStyle = "rgba(0,0,255, 0.3)"; |
| 1409 | ctx.fillStyle = "blue"; |
| 1410 | var f = []; |
| 1411 | switch (fragType) { |
| 1412 | case INTERSECT_LINE: |
| 1413 | f.push(5, 6, 0, 7); |
| 1414 | break; |
| 1415 | case INTERSECT_LINE_2: |
| 1416 | f.push(5, 6, 0, 10); |
| 1417 | f.push(8, 9, 7, 15); |
| 1418 | break; |
| 1419 | case INTERSECT_LINE_NO: |
| 1420 | break; |
| 1421 | case INTERSECT_QUAD_LINE: |
| 1422 | f.push(7, 8, 0, 9); |
| 1423 | break; |
| 1424 | case INTERSECT_QUAD_LINE_2: |
| 1425 | f.push(7, 8, 0, 12); |
| 1426 | f.push(10, 11, 9, 17); |
| 1427 | break; |
| 1428 | case INTERSECT_QUAD_LINE_NO: |
| 1429 | break; |
| 1430 | case INTERSECT_QUAD: |
| 1431 | f.push(7, 8, 0, 9); |
| 1432 | break; |
| 1433 | case INTERSECT_QUAD_2: |
| 1434 | f.push(7, 8, 0, 12); |
| 1435 | f.push(10, 11, 9, 19); |
| 1436 | break; |
| 1437 | case INTERSECT_QUAD_NO: |
| 1438 | break; |
| 1439 | case INTERSECT_SELF_CUBIC: |
| 1440 | f.push(9, 10, 0, 11); |
| 1441 | break; |
| 1442 | case INTERSECT_SELF_CUBIC_NO: |
| 1443 | break; |
| 1444 | case INTERSECT_CUBIC_LINE: |
| 1445 | f.push(9, 10, 0, 11); |
| 1446 | break; |
| 1447 | case INTERSECT_CUBIC_LINE_2: |
| 1448 | f.push(9, 10, 0, 14); |
| 1449 | f.push(12, 13, 11, 19); |
| 1450 | break; |
| 1451 | case INTERSECT_CUBIC_LINE_3: |
| 1452 | f.push(9, 10, 0, 17); |
| 1453 | f.push(12, 13, 11, 22); |
| 1454 | f.push(15, 16, 14, 23); |
| 1455 | break; |
| 1456 | case INTERSECT_CUBIC_LINE_NO: |
| 1457 | break; |
| 1458 | case INTERSECT_CUBIC: |
| 1459 | f.push(9, 10, 0, 11); |
| 1460 | break; |
| 1461 | case INTERSECT_CUBIC_2: |
| 1462 | f.push(9, 10, 0, 14); |
| 1463 | f.push(12, 13, 11, 23); |
| 1464 | break; |
| 1465 | case INTERSECT_CUBIC_3: |
| 1466 | f.push(9, 10, 0, 17); |
| 1467 | f.push(12, 13, 11, 26); |
| 1468 | f.push(15, 16, 14, 27); |
| 1469 | break; |
| 1470 | case INTERSECT_CUBIC_4: |
| 1471 | f.push(9, 10, 0, 20); |
| 1472 | f.push(12, 13, 11, 29); |
| 1473 | f.push(15, 16, 14, 30); |
| 1474 | f.push(18, 19, 17, 31); |
| 1475 | break; |
| 1476 | case INTERSECT_CUBIC_NO: |
| 1477 | break; |
| 1478 | default: |
| 1479 | console.log("unknown REC_TYPE_SECT frag type: " + fragType); |
| 1480 | throw "stop execution"; |
| 1481 | } |
| 1482 | for (var idx = 0; idx < f.length; idx += 4) { |
| 1483 | drawPoint(frags[f[idx]], frags[f[idx + 1]]); |
| 1484 | } |
| 1485 | if (!draw_intersectT) { |
| 1486 | break; |
| 1487 | } |
| 1488 | ctx.fillStyle = "red"; |
| 1489 | for (var idx = 0; idx < f.length; idx += 4) { |
| 1490 | drawTAtPointUp(frags[f[idx]], frags[f[idx + 1]], frags[f[idx + 2]]); |
| 1491 | drawTAtPointDown(frags[f[idx]], frags[f[idx + 1]], frags[f[idx + 3]]); |
| 1492 | } |
| 1493 | break; |
| 1494 | case REC_TYPE_SORT: |
| 1495 | if (!draw_sort || testIndex < lastSort) { |
| 1496 | continue; |
| 1497 | } |
| 1498 | ctx.lineWidth = 3; |
| 1499 | ctx.strokeStyle = "rgba(127,127,0, 0.5)"; |
| 1500 | switch (fragType) { |
| 1501 | case SORT_LINE: |
| 1502 | drawLinePartial(frags[1], frags[2], frags[3], frags[4], |
| 1503 | frags[5], frags[6]); |
| 1504 | break; |
| 1505 | case SORT_QUAD: |
| 1506 | drawQuadPartial(frags[1], frags[2], frags[3], frags[4], |
| 1507 | frags[5], frags[6], frags[7], frags[8]); |
| 1508 | break; |
| 1509 | case SORT_CUBIC: |
| 1510 | drawCubicPartial(frags[1], frags[2], frags[3], frags[4], |
| 1511 | frags[5], frags[6], frags[7], frags[8], frags[9], frags[10]); |
| 1512 | break; |
| 1513 | } |
| 1514 | break; |
| 1515 | case REC_TYPE_MARK: |
| 1516 | if (!draw_mark || testIndex < lastMark) { |
| 1517 | continue; |
| 1518 | } |
| 1519 | ctx.lineWidth = 3; |
| 1520 | ctx.strokeStyle = fragType >= MARK_DONE_LINE ? |
| 1521 | "rgba(127,0,127, 0.5)" : "rgba(127,127,0, 0.5)"; |
| 1522 | switch (fragType) { |
| 1523 | case MARK_LINE: |
| 1524 | drawLinePartial(frags[1], frags[2], frags[3], frags[4], |
| 1525 | frags[5], frags[9]); |
| 1526 | break; |
| 1527 | case MARK_QUAD: |
| 1528 | drawQuadPartial(frags[1], frags[2], frags[3], frags[4], |
| 1529 | frags[5], frags[6], frags[7], frags[11]); |
| 1530 | break; |
| 1531 | case MARK_CUBIC: |
| 1532 | drawCubicPartial(frags[1], frags[2], frags[3], frags[4], |
| 1533 | frags[5], frags[6], frags[7], frags[8], frags[9], frags[13]); |
| 1534 | break; |
| 1535 | case MARK_DONE_LINE: |
| 1536 | drawLinePartial(frags[1], frags[2], frags[3], frags[4], |
| 1537 | frags[5], frags[9]); |
| 1538 | break; |
| 1539 | case MARK_DONE_QUAD: |
| 1540 | drawQuadPartial(frags[1], frags[2], frags[3], frags[4], |
| 1541 | frags[5], frags[6], frags[7], frags[11]); |
| 1542 | break; |
| 1543 | case MARK_DONE_CUBIC: |
| 1544 | drawCubicPartial(frags[1], frags[2], frags[3], frags[4], |
| 1545 | frags[5], frags[6], frags[7], frags[8], frags[9], frags[13]); |
| 1546 | break; |
| 1547 | } |
| 1548 | break; |
| 1549 | default: |
| 1550 | continue; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 1551 | } |
| 1552 | } |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1553 | } |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1554 | if (draw_log && logStart >= 0) { |
| 1555 | ctx.font = "normal 10px Arial"; |
| 1556 | ctx.beginPath(); |
| 1557 | ctx.rect(50,550, 200,30); |
| 1558 | ctx.fillStyle = "white"; |
| 1559 | ctx.fill(); |
| 1560 | ctx.fillStyle = "rgba(0,0,0, 0.5)"; |
| 1561 | if (logStart > 0) { |
| 1562 | ctx.fillText(lines[logStart - 1], 50, 558); |
| 1563 | } |
| 1564 | ctx.fillStyle = "black"; |
| 1565 | for (var idx = 0; idx < logRange; ++idx) { |
| 1566 | ctx.fillText(lines[logStart + idx], 50, 568 + 10 * idx); |
| 1567 | } |
| 1568 | ctx.fillStyle = "rgba(0,0,0, 0.5)"; |
| 1569 | if (logStart + logRange < lines.length) { |
| 1570 | ctx.fillText(lines[logStart + logRange], 50, 568 + 10 * logRange); |
| 1571 | } |
| 1572 | } |
| 1573 | if (draw_legend) { |
| 1574 | var pos = 0; |
| 1575 | drawBox(pos++, "yellow", "black", opLetter, true, ''); |
| 1576 | drawBox(pos++, "rgba(0,0,255, 0.3)", "black", "X", draw_intersection, intersectionKey); |
| 1577 | drawBox(pos++, "rgba(0,0,255, 0.3)", "black", "+", draw_add, addKey); |
| 1578 | drawBox(pos++, "rgba(0,0,255, 0.3)", "black", activeCount, draw_active, activeKey); |
| 1579 | drawBox(pos++, "rgba(127,127,0, 0.3)", "black", sortCount, draw_sort, sortKey); |
| 1580 | drawBox(pos++, "rgba(127,0,127, 0.3)", "black", markCount, draw_mark, markKey); |
| 1581 | drawBox(pos++, "black", "white", "P", draw_path, pathKey); |
| 1582 | var computedLabel = ['Q', 'Q', 'C', 'QC']; |
| 1583 | drawBox(pos++, "rgba(0,63,0, 0.7)", "white", (new Array('Q', 'Q', 'C', 'QC'))[draw_computed], |
| 1584 | draw_computed != 0, computedKey); |
| 1585 | drawBox(pos++, "green", "black", curStep, true, ''); |
| 1586 | drawBox(pos++, "green", "black", step_limit, true, ''); |
| 1587 | drawBox(pos++, "red", "black", lastIndex, true, ''); |
| 1588 | drawBox(pos++, "red", "black", test.length - 1, true, ''); |
| 1589 | if (curve_t) { |
| 1590 | drawCurveTControl(); |
| 1591 | } |
| 1592 | } |
| 1593 | } |
| 1594 | |
| 1595 | function drawBox(y, backC, foreC, str, enable, label) { |
| 1596 | ctx.beginPath(); |
| 1597 | ctx.fillStyle = backC; |
| 1598 | ctx.rect(ctx.canvas.width - 40, y * 50 + 50, 40, 30); |
| 1599 | ctx.fill(); |
| 1600 | ctx.font = "normal 16px Arial"; |
| 1601 | ctx.fillStyle = foreC; |
| 1602 | ctx.textAlign = "center"; |
| 1603 | ctx.fillText(str, ctx.canvas.width - 20, y * 50 + 72); |
| 1604 | if (!enable) { |
| 1605 | ctx.fillStyle = "rgba(255,255,255, 0.5)"; |
| 1606 | ctx.fill(); |
| 1607 | } |
| 1608 | if (label != '') { |
| 1609 | ctx.font = "normal 9px Arial"; |
| 1610 | ctx.fillStyle = "black"; |
| 1611 | ctx.fillText(label, ctx.canvas.width - 47, y * 50 + 80); |
| 1612 | } |
| 1613 | ctx.textAlign = "left"; |
| 1614 | } |
| 1615 | |
| 1616 | function drawCurveTControl() { |
| 1617 | ctx.lineWidth = 2; |
| 1618 | ctx.strokeStyle = "rgba(0,0,0, 0.3)"; |
| 1619 | ctx.beginPath(); |
| 1620 | ctx.rect(ctx.canvas.width - 80, 40, 28, ctx.canvas.height - 80); |
| 1621 | ctx.stroke(); |
| 1622 | var ty = 40 + curveT * (ctx.canvas.height - 80); |
| 1623 | ctx.beginPath(); |
| 1624 | ctx.moveTo(ctx.canvas.width - 80, ty); |
| 1625 | ctx.lineTo(ctx.canvas.width - 85, ty - 5); |
| 1626 | ctx.lineTo(ctx.canvas.width - 85, ty + 5); |
| 1627 | ctx.lineTo(ctx.canvas.width - 80, ty); |
| 1628 | ctx.fillStyle = "rgba(0,0,0, 0.6)"; |
| 1629 | ctx.fill(); |
| 1630 | var num = curveT.toFixed(decimal_places); |
| 1631 | ctx.font = "normal 10px Arial"; |
| 1632 | ctx.fillText(num, ctx.canvas.width - 78, ty); |
| 1633 | } |
| 1634 | |
| 1635 | function ptInTControl() { |
| 1636 | var e = window.event; |
| 1637 | var tgt = e.target || e.srcElement; |
| 1638 | var left = tgt.offsetLeft; |
| 1639 | var top = tgt.offsetTop; |
| 1640 | var x = (e.clientX - left); |
| 1641 | var y = (e.clientY - top); |
| 1642 | if (x < ctx.canvas.width - 80 || x > ctx.canvas.width - 50) { |
| 1643 | return false; |
| 1644 | } |
| 1645 | if (y < 40 || y > ctx.canvas.height - 80) { |
| 1646 | return false; |
| 1647 | } |
| 1648 | curveT = (y - 40) / (ctx.canvas.height - 120); |
| 1649 | if (curveT < 0 || curveT > 1) { |
| 1650 | throw "stop execution"; |
| 1651 | } |
| 1652 | return true; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1653 | } |
| 1654 | |
| 1655 | function drawTop() { |
| 1656 | init(tests[testIndex]); |
| 1657 | redraw(); |
| 1658 | } |
| 1659 | |
| 1660 | function redraw() { |
| 1661 | ctx.beginPath(); |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1662 | ctx.fillStyle = "white"; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1663 | ctx.rect(0, 0, ctx.canvas.width, ctx.canvas.height); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1664 | ctx.fill(); |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1665 | draw(tests[testIndex], testLines[testIndex], testTitles[testIndex]); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1666 | } |
| 1667 | |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1668 | var activeKey = 'a'; |
| 1669 | var addKey = 'd'; |
| 1670 | var centerKey = 'c'; |
| 1671 | var computedKey = 'q'; |
| 1672 | var computedBackKey = 'Q'; |
| 1673 | var controlLinesKey = 'v'; |
| 1674 | var curveTKey = 'u'; |
| 1675 | var intersectTKey = 't'; |
| 1676 | var intersectionKey = 'i'; |
| 1677 | var infoKey = 'f'; |
| 1678 | var logKey = 'l'; |
| 1679 | var markKey = 'm'; |
| 1680 | var nextBy10Key = 'N'; |
| 1681 | var nextKey = 'n'; |
| 1682 | var pathKey = 'b'; |
| 1683 | var previousBy10Key = 'P'; |
| 1684 | var previousKey = 'p'; |
| 1685 | var ptsKey = 'x'; |
| 1686 | var sortKey = 'o'; |
| 1687 | var stepBackKey = 'S'; |
| 1688 | var stepKey = 's'; |
| 1689 | var xyKey = 'y'; |
| 1690 | |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1691 | function doKeyPress(evt) { |
| 1692 | var char = String.fromCharCode(evt.charCode); |
| 1693 | switch (char) { |
| 1694 | case '0': |
| 1695 | case '1': |
| 1696 | case '2': |
| 1697 | case '3': |
| 1698 | case '4': |
| 1699 | case '5': |
| 1700 | case '6': |
| 1701 | case '7': |
| 1702 | case '8': |
| 1703 | case '9': |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1704 | decimal_places = char - '0'; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1705 | redraw(); |
| 1706 | break; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1707 | case activeKey: |
| 1708 | draw_active ^= true; |
| 1709 | redraw(); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1710 | break; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1711 | case centerKey: |
| 1712 | setScale(); |
| 1713 | redraw(); |
| 1714 | break; |
| 1715 | case controlLinesKey: |
| 1716 | control_lines ^= true; |
| 1717 | redraw(); |
| 1718 | break; |
| 1719 | case curveTKey: |
| 1720 | curve_t ^= true; |
| 1721 | redraw(); |
| 1722 | break; |
| 1723 | case computedBackKey: |
| 1724 | draw_computed = (draw_computed - 1) & 3; // four-state |
| 1725 | redraw(); |
| 1726 | break; |
| 1727 | case computedKey: |
| 1728 | draw_computed = (draw_computed + 1) & 3; // four-state |
| 1729 | redraw(); |
| 1730 | break; |
| 1731 | case pathKey: |
| 1732 | draw_path ^= true; |
| 1733 | redraw(); |
| 1734 | break; |
| 1735 | case addKey: |
| 1736 | draw_add ^= true; |
| 1737 | redraw(); |
| 1738 | break; |
| 1739 | case infoKey: |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1740 | info_mode ^= true; |
| 1741 | redraw(); |
| 1742 | break; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1743 | case intersectionKey: |
| 1744 | draw_intersection ^= true; |
| 1745 | redraw(); |
| 1746 | break; |
| 1747 | case logKey: |
| 1748 | draw_log ^= true; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1749 | redraw(); |
| 1750 | break; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1751 | case markKey: |
| 1752 | draw_mark ^= true; |
| 1753 | redraw(); |
| 1754 | break; |
| 1755 | case nextBy10Key: |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1756 | testIndex += 9; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1757 | case nextKey: |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1758 | if (++testIndex >= tests.length) |
| 1759 | testIndex = 0; |
| 1760 | drawTop(); |
| 1761 | break; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1762 | case previousBy10Key: |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1763 | testIndex -= 9; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1764 | case previousKey: |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1765 | if (--testIndex < 0) |
| 1766 | testIndex = tests.length - 1; |
| 1767 | drawTop(); |
| 1768 | break; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1769 | case stepKey: |
| 1770 | step_limit++; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 1771 | redraw(); |
| 1772 | break; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1773 | case stepBackKey: |
| 1774 | step_limit--; |
| 1775 | if (step_limit < 0) { |
| 1776 | step_limit = 0; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 1777 | } |
| 1778 | redraw(); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1779 | break; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1780 | case sortKey: |
| 1781 | draw_sort ^= true; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1782 | redraw(); |
| 1783 | break; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1784 | case intersectTKey: |
| 1785 | draw_intersectT ^= true; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1786 | redraw(); |
| 1787 | break; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1788 | case ptsKey: |
| 1789 | pt_labels ^= true; |
| 1790 | redraw(); |
| 1791 | break; |
| 1792 | case xyKey: |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1793 | debug_xy ^= true; |
| 1794 | redraw(); |
| 1795 | break; |
| 1796 | case '-': |
| 1797 | scale /= 2; |
| 1798 | calcLeftTop(); |
| 1799 | redraw(); |
| 1800 | break; |
| 1801 | case '=': |
| 1802 | case '+': |
| 1803 | scale *= 2; |
| 1804 | calcLeftTop(); |
| 1805 | redraw(); |
| 1806 | break; |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1807 | case '/': |
| 1808 | case '?': |
| 1809 | draw_legend ^= true; |
| 1810 | redraw(); |
| 1811 | break; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1812 | } |
| 1813 | } |
| 1814 | |
| 1815 | function calcXY() { |
| 1816 | var e = window.event; |
| 1817 | var tgt = e.target || e.srcElement; |
| 1818 | var left = tgt.offsetLeft; |
| 1819 | var top = tgt.offsetTop; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1820 | mouseX = (e.clientX - left) / scale + srcLeft; |
| 1821 | mouseY = (e.clientY - top) / scale + srcTop; |
| 1822 | } |
| 1823 | |
| 1824 | function calcLeftTop() { |
| 1825 | srcLeft = mouseX - screenWidth / 2 / scale; |
| 1826 | srcTop = mouseY - screenHeight / 2 / scale; |
| 1827 | } |
| 1828 | |
| 1829 | function handleMouseClick() { |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1830 | if (!curve_t || !ptInTControl()) { |
| 1831 | calcXY(); |
| 1832 | calcLeftTop(); |
| 1833 | } |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1834 | redraw(); |
| 1835 | } |
| 1836 | |
| 1837 | function handleMouseOver() { |
| 1838 | calcXY(); |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1839 | if (!debug_xy) { |
| 1840 | return; |
| 1841 | } |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1842 | var num = mouseX.toFixed(decimal_places) + ", " + mouseY.toFixed(decimal_places); |
| 1843 | ctx.beginPath(); |
| 1844 | ctx.rect(300,100,200,10); |
| 1845 | ctx.fillStyle="white"; |
| 1846 | ctx.fill(); |
| 1847 | ctx.fillStyle="black"; |
| 1848 | ctx.fillText(num, 300, 108); |
| 1849 | } |
| 1850 | |
| 1851 | function start() { |
| 1852 | for (i = 0; i < testDivs.length; ++i) { |
| 1853 | var title = testDivs[i].id.toString(); |
| 1854 | var str = testDivs[i].firstChild.data; |
caryclark@google.com | 4aaaaea | 2013-02-28 16:12:39 +0000 | [diff] [blame] | 1855 | parse_all(str, title); |
caryclark@google.com | d4c8e1e | 2013-03-05 14:13:13 +0000 | [diff] [blame] | 1856 | // parse_debugShowActiveSpans(str, title); |
| 1857 | // parse_intersections(str, title); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1858 | } |
| 1859 | drawTop(); |
| 1860 | window.addEventListener('keypress', doKeyPress, true); |
| 1861 | window.onresize = function() { |
| 1862 | drawTop(); |
| 1863 | } |
| 1864 | } |
| 1865 | |
| 1866 | </script> |
| 1867 | </head> |
| 1868 | |
| 1869 | <body onLoad="start();"> |
| 1870 | <canvas id="canvas" width="750" height="500" |
| 1871 | onmousemove="handleMouseOver()" |
| 1872 | onclick="handleMouseClick()" |
| 1873 | ></canvas > |
| 1874 | </body> |
| 1875 | </html> |