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 | c83c70e | 2013-02-22 21:50:07 +0000 | [diff] [blame] | 5 | <div id="cubicOp25i"> |
| 6 | debugShowActiveSpans id=1 (0,1 2,4 5,0 3,2) t=0.466666667 (2.84355545,1.9478519) tEnd=0.605057566 other=2 otherT=0.0521481481 otherIndex=1 windSum=-1 windValue=1 oppValue=0 |
| 7 | debugShowActiveSpans id=2 (3,2 0,1) t=0.0521481481 (2.84355545,1.9478519) tEnd=0.377811276 other=1 otherT=0.466666667 otherIndex=2 windSum=1 windValue=1 oppValue=0 |
| 8 | </div> |
| 9 | |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 10 | <div id="cubicOp19i"> |
| 11 | debugShowActiveSpans id=3 (1,2 2,6 2,0 1,0) t=0 (1,2) tEnd=0.578464835 other=4 otherT=1 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 12 | debugShowActiveSpans id=3 (1,2 2,6 2,0 1,0) t=0.578464835 (1.73152983,2) tEnd=0.692069746 other=2 otherT=0.711411698 otherIndex=1 windSum=? windValue=1 oppValue=0 |
| 13 | debugShowActiveSpans id=3 (1,2 2,6 2,0 1,0) t=0.692069746 (1.63932765,1.25154662) tEnd=1 other=1 otherT=0.522705723 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 14 | debugShowActiveSpans id=4 (1,0 1,2) t=0 (1,0) tEnd=0.637627564 other=3 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0 |
| 15 | debugShowActiveSpans id=4 (1,0 1,2) t=0.637627564 (1,1.27525508) tEnd=1 other=1 otherT=0.40824829 otherIndex=1 windSum=? windValue=1 oppValue=0 |
| 16 | debugShowActiveSpans id=1 (0,2 0,0.5 6,2) t=0 (0,2) tEnd=0.40824829 other=2 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0 |
| 17 | debugShowActiveSpans id=1 (0,2 0,0.5 6,2) t=0.40824829 (1,1.27525508) tEnd=0.522705723 other=4 otherT=0.637627564 otherIndex=1 windSum=? windValue=1 oppValue=0 |
| 18 | debugShowActiveSpans id=1 (0,2 0,0.5 6,2) t=0.522705723 (1.63932765,1.25154662) tEnd=1 other=3 otherT=0.692069746 otherIndex=3 windSum=? windValue=1 oppValue=0 |
| 19 | debugShowActiveSpans id=2 (6,2 0,2) t=0 (6,2) tEnd=0.711411698 other=1 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0 |
| 20 | debugShowActiveSpans id=2 (6,2 0,2) t=0.711411698 (1.73152983,2) tEnd=0.833333333 other=3 otherT=0.578464835 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 21 | debugShowActiveSpans id=2 (6,2 0,2) t=0.833333333 (1,2) tEnd=1 other=3 otherT=0 otherIndex=1 windSum=? windValue=1 oppValue=0 |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 22 | </div> |
| 23 | |
caryclark@google.com | c83c70e | 2013-02-22 21:50:07 +0000 | [diff] [blame] | 24 | <div id="cubicOp28u"> |
| 25 | debugShowActiveSpans id=3 (0,6 2,3 1,0 4,1) t=0 (0,6) tEnd=0.473902244 other=4 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0 |
| 26 | debugShowActiveSpans id=3 (0,6 2,3 1,0 4,1) t=0.473902244 (1.5671773,2.16060209) tEnd=0.57224743 other=1 otherT=0.287206281 otherIndex=1 windSum=? windValue=1 oppValue=0 |
| 27 | debugShowActiveSpans id=3 (0,6 2,3 1,0 4,1) t=0.57224743 (1.79802597,1.59934199) tEnd=1 other=2 otherT=0.400657994 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 28 | debugShowActiveSpans id=4 (4,1 0,6) t=0 (4,1) tEnd=0.13678207 other=3 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0 |
| 29 | debugShowActiveSpans id=4 (4,1 0,6) t=0.13678207 (3.4528718,1.68391037) tEnd=0.145041093 other=1 otherT=0.583645693 otherIndex=3 windSum=? windValue=1 oppValue=0 |
| 30 | debugShowActiveSpans id=4 (4,1 0,6) t=0.145041093 (3.41983557,1.72520542) tEnd=1 other=1 otherT=0.945703361 otherIndex=6 windSum=? windValue=1 oppValue=0 |
| 31 | debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0 (0,1) tEnd=0.287206281 other=2 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0 |
| 32 | debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0.287206281 (1.5671773,2.16060209) tEnd=0.470588235 other=3 otherT=0.473902244 otherIndex=1 windSum=? windValue=1 oppValue=0 |
| 33 | debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0.470588235 (2.81864452,1.93954813) tEnd=0.583645693 other=2 otherT=0.0604518624 otherIndex=1 windSum=? windValue=1 oppValue=0 |
| 34 | debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0.583645693 (3.4528718,1.68391037) tEnd=0.614942976 other=4 otherT=0.13678207 otherIndex=1 windSum=? windValue=1 oppValue=0 |
| 35 | debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0.614942976 (3.59216309,1.61630249) tEnd=0.916307024 other=1 otherT=0.916307024 otherIndex=5 windSum=? windValue=1 oppValue=0 |
| 36 | debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0.916307024 (3.59216309,1.61630249) tEnd=0.945703361 other=1 otherT=0.614942976 otherIndex=4 windSum=? windValue=1 oppValue=0 |
| 37 | debugShowActiveSpans id=1 (0,1 1,4 6,0 3,2) t=0.945703361 (3.41983557,1.72520542) tEnd=1 other=4 otherT=0.145041093 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 38 | debugShowActiveSpans id=2 (3,2 0,1) t=0 (3,2) tEnd=0.0604518624 other=1 otherT=1 otherIndex=7 windSum=? windValue=1 oppValue=0 |
| 39 | debugShowActiveSpans id=2 (3,2 0,1) t=0.0604518624 (2.81864452,1.93954813) tEnd=0.400657994 other=1 otherT=0.470588235 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 40 | debugShowActiveSpans id=2 (3,2 0,1) t=0.400657994 (1.79802597,1.59934199) tEnd=1 other=3 otherT=0.57224743 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 41 | </div> |
| 42 | |
caryclark@google.com | 7ff5c84 | 2013-02-26 15:56:05 +0000 | [diff] [blame] | 43 | <div id="cubicOp31d"> |
| 44 | debugShowActiveSpans id=1 (0,2 0,3 2,1 4,0) t=0 (0,2) tEnd=0.5 other=2 otherT=1 otherIndex=3 windSum=1 windValue=1 oppValue=0 |
| 45 | debugShowActiveSpans id=1 (0,2 0,3 2,1 4,0) t=0.5 (1.25,1.75) tEnd=1 other=4 otherT=0.875 otherIndex=2 windSum=1 windValue=1 oppValue=0 |
| 46 | debugShowActiveSpans id=2 (4,0 0,2) t=0 (4,0) tEnd=0.5 other=1 otherT=1 otherIndex=3 windSum=1 windValue=1 oppValue=0 |
| 47 | debugShowActiveSpans id=2 (4,0 0,2) t=0.586298186 (1.65480721,1.17259634) tEnd=1 other=3 otherT=0.622399169 otherIndex=3 windSum=1 windValue=1 oppValue=0 |
| 48 | debugShowActiveSpans id=3 (1,2 0,4 2,0 3,0) t=0 (1,2) tEnd=0.5 other=4 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0 |
| 49 | debugShowActiveSpans id=3 (1,2 0,4 2,0 3,0) t=0.500000008 (1.25,1.75) tEnd=0.622399169 other=1 otherT=0.5 otherIndex=1 windSum=-1 windValue=1 oppValue=0 |
| 50 | debugShowActiveSpans id=4 (3,0 1,2) t=0.5 (2,1) tEnd=0.875 other=2 otherT=0.5 otherIndex=1 windSum=-1 windValue=1 oppValue=0 |
| 51 | debugShowActiveSpans id=4 (3,0 1,2) t=0.875 (1.25,1.75) tEnd=1 other=1 otherT=0.5 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 52 | </div> |
| 53 | |
| 54 | <div id="cubicOp31da"> |
| 55 | debugShowActiveSpans id=1 (0,2 0,3 2,1 4,0) t=0 (0,2) tEnd=0.5 other=2 otherT=1 otherIndex=3 windSum=1 windValue=1 oppValue=0 |
| 56 | debugShowActiveSpans id=1 (0,2 0,3 2,1 4,0) t=0.5 (1.25,1.75) tEnd=1 other=4 otherT=0.875 otherIndex=2 windSum=1 windValue=1 oppValue=0 |
| 57 | debugShowActiveSpans id=3 (1,2 0,4 2,0 3,0) t=0 (1,2) tEnd=0.5 other=4 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0 |
| 58 | debugShowActiveSpans id=3 (1,2 0,4 2,0 3,0) t=0.500000008 (1.25,1.75) tEnd=0.622399169 other=1 otherT=0.5 otherIndex=1 windSum=-1 windValue=1 oppValue=0 |
| 59 | debugShowActiveSpans id=4 (3,0 1,2) t=0.5 (2,1) tEnd=0.875 other=2 otherT=0.5 otherIndex=1 windSum=-1 windValue=1 oppValue=0 |
| 60 | debugShowActiveSpans id=4 (3,0 1,2) t=0.875 (1.25,1.75) tEnd=1 other=1 otherT=0.5 otherIndex=2 windSum=? windValue=1 oppValue=0 |
| 61 | </div> |
| 62 | |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 63 | </div> |
| 64 | |
| 65 | <script type="text/javascript"> |
| 66 | |
| 67 | var testDivs = [ |
caryclark@google.com | 7ff5c84 | 2013-02-26 15:56:05 +0000 | [diff] [blame] | 68 | cubicOp31da, |
| 69 | cubicOp31d, |
caryclark@google.com | c83c70e | 2013-02-22 21:50:07 +0000 | [diff] [blame] | 70 | cubicOp28u, |
| 71 | cubicOp25i, |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 72 | cubicOp19i, |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 73 | ]; |
| 74 | |
| 75 | var decimal_places = 3; // make this 3 to show more precision |
| 76 | |
| 77 | var tests = []; |
| 78 | var testTitles = []; |
| 79 | var testIndex = 0; |
| 80 | var ctx; |
| 81 | |
| 82 | var xmin; |
| 83 | var ymin; |
| 84 | var scale; |
| 85 | var mouseX, mouseY; |
| 86 | var srcLeft, srcTop; |
| 87 | var srcWidth, srcHeight; |
| 88 | var screenWidth, screenHeight; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 89 | var drawnPts, drawnLines, drawnQuads, drawnCubics, deferredLines, deferredQuads, deferredCubics; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 90 | |
| 91 | var ptLabels = true; |
| 92 | var digit_mode = false; |
| 93 | var index_mode = true; |
| 94 | var index_bits = -1; |
| 95 | var debug_xy = false; |
| 96 | var info_mode = false; |
| 97 | var intersect_mode = false; |
| 98 | var sequence = -1; |
| 99 | |
| 100 | var SPAN_ID = 1; |
| 101 | var SPAN_X1 = 2; |
| 102 | var SPAN_Y1 = 3; |
| 103 | var SPAN_X2 = 4; |
| 104 | var SPAN_Y2 = 5; |
| 105 | var SPAN_L_T = 6; |
| 106 | var SPAN_L_TX = 7; |
| 107 | var SPAN_L_TY = 8; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 108 | var SPAN_L_TEND = 9; |
| 109 | var SPAN_L_OTHER = 10; |
| 110 | var SPAN_L_OTHERT = 11; |
| 111 | var SPAN_L_OTHERI = 12; |
| 112 | var SPAN_L_SUM = 13; |
| 113 | var SPAN_L_VAL = 14; |
| 114 | var SPAN_L_OPP = 15; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 115 | |
| 116 | var SPAN_X3 = 6; |
| 117 | var SPAN_Y3 = 7; |
| 118 | var SPAN_Q_T = 8; |
| 119 | var SPAN_Q_TX = 9; |
| 120 | var SPAN_Q_TY = 10; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 121 | var SPAN_Q_TEND = 11; |
| 122 | var SPAN_Q_OTHER = 12; |
| 123 | var SPAN_Q_OTHERT = 13; |
| 124 | var SPAN_Q_OTHERI = 14; |
| 125 | var SPAN_Q_SUM = 15; |
| 126 | var SPAN_Q_VAL = 16; |
| 127 | var SPAN_Q_OPP = 17; |
| 128 | |
| 129 | var SPAN_X4 = 8; |
| 130 | var SPAN_Y4 = 9; |
| 131 | var SPAN_C_T = 10; |
| 132 | var SPAN_C_TX = 11; |
| 133 | var SPAN_C_TY = 12; |
| 134 | var SPAN_C_TEND = 13; |
| 135 | var SPAN_C_OTHER = 14; |
| 136 | var SPAN_C_OTHERT = 15; |
| 137 | var SPAN_C_OTHERI = 16; |
| 138 | var SPAN_C_SUM = 17; |
| 139 | var SPAN_C_VAL = 18; |
| 140 | var SPAN_C_OPP = 19; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 141 | |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 142 | var ACTIVE_LINE_SPAN = 1; |
| 143 | var ACTIVE_QUAD_SPAN = 2; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 144 | var ACTIVE_CUBIC_SPAN = 3; |
| 145 | var INTERSECT_QUAD_LINE = 4; |
| 146 | var INTERSECT_QUAD_LINE_2 = 5; |
| 147 | var INTERSECT_QUAD_LINE_NO = 6; |
| 148 | var INTERSECT_QUAD = 7; |
| 149 | var INTERSECT_QUAD_2 = 8; |
| 150 | var INTERSECT_QUAD_NO = 9; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 151 | |
| 152 | function strs_to_nums(strs) { |
| 153 | var result = []; |
| 154 | for (var idx in strs) { |
| 155 | var str = strs[idx]; |
| 156 | var num = parseFloat(str); |
| 157 | if (isNaN(num)) { |
| 158 | result.push(str); |
| 159 | } else { |
| 160 | result.push(num); |
| 161 | } |
| 162 | } |
| 163 | return result; |
| 164 | } |
| 165 | |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 166 | function construct_regexp(pattern) { |
| 167 | var escape = pattern.replace(/[-/\\^$*+?.()|[\]{}]/g, '\\$&'); |
| 168 | escape = escape.replace(/PT_VAL/g, "(\\d+\\.?\\d*),(\\d+\\.?\\d*)"); |
| 169 | escape = escape.replace(/T_VAL/g, "(\\d+\\.?\\d*e?-?\\d*)"); |
| 170 | escape = escape.replace(/IDX/g, "(\\d+)"); |
| 171 | escape = escape.replace(/OPT/g, "(\\?|-?\\d+)"); |
| 172 | return new RegExp(escape, 'i'); |
| 173 | } |
| 174 | |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 175 | function parse_debugShowActiveSpans(test, title) { |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 176 | 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"); |
| 177 | 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"); |
| 178 | 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] | 179 | |
| 180 | var strs = test.split("debugShowActiveSpans"); |
| 181 | if (strs.length == 1) |
| 182 | return; |
| 183 | var spans = []; |
| 184 | for (var s in strs) { |
| 185 | var str = strs[s]; |
| 186 | if (str == "\n") { |
| 187 | continue; |
| 188 | } |
| 189 | if (re_line.test(str)) { |
| 190 | var lineStrs = re_line.exec(str); |
| 191 | var line = strs_to_nums(lineStrs); |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 192 | spans.push(ACTIVE_LINE_SPAN); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 193 | spans.push(line); |
| 194 | } else if (re_quad.test(str)) { |
| 195 | var quadStrs = re_quad.exec(str); |
| 196 | var quad = strs_to_nums(quadStrs); |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 197 | spans.push(ACTIVE_QUAD_SPAN); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 198 | spans.push(quad); |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 199 | } else if (re_cubic.test(str)) { |
| 200 | var cubicStrs = re_cubic.exec(str); |
| 201 | var cubic = strs_to_nums(cubicStrs); |
| 202 | spans.push(ACTIVE_CUBIC_SPAN); |
| 203 | spans.push(cubic); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | if (spans.length >= 1) { |
| 207 | tests.push(spans); |
| 208 | testTitles.push(title); |
| 209 | } |
| 210 | } |
| 211 | |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 212 | function filter_str_by(id, str, regex, array) { |
| 213 | if (regex.test(str)) { |
| 214 | var strs = regex.exec(str); |
| 215 | var result = strs_to_nums(strs); |
| 216 | array.push(id); |
| 217 | array.push(result); |
| 218 | } |
| 219 | } |
| 220 | |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 221 | // FIXME: add cubic support |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 222 | function parse_intersections(test, title) { |
| 223 | 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)"); |
| 224 | 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)"); |
| 225 | var re_quad_line_no_intersect = construct_regexp(" no intersect (PT_VAL PT_VAL PT_VAL) (PT_VAL PT_VAL)"); |
| 226 | 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)"); |
| 227 | 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"); |
| 228 | var re_quad_no_intersect = construct_regexp(" no intersect (PT_VAL PT_VAL PT_VAL) (PT_VAL PT_VAL PT_VAL)"); |
| 229 | |
| 230 | var strs = test.split(/debugShow[A-Za-z]+Intersection/); |
| 231 | if (strs.length == 1) |
| 232 | return; |
| 233 | var spans = []; |
| 234 | for (var s in strs) { |
| 235 | var str = strs[s]; |
| 236 | if (str == "\n") { |
| 237 | continue; |
| 238 | } |
| 239 | filter_str_by(INTERSECT_QUAD_LINE, str, re_quad_line, spans); |
| 240 | filter_str_by(INTERSECT_QUAD_LINE_2, str, re_quad_line_2, spans); |
| 241 | filter_str_by(INTERSECT_QUAD_LINE_NO, str, re_quad_line_no_intersect, spans); |
| 242 | filter_str_by(INTERSECT_QUAD, str, re_quad, spans); |
| 243 | filter_str_by(INTERSECT_QUAD_2, str, re_quad_2, spans); |
| 244 | filter_str_by(INTERSECT_QUAD_NO, str, re_quad_no_intersect, spans); |
| 245 | } |
| 246 | if (spans.length >= 1) { |
| 247 | tests.push(spans); |
| 248 | testTitles.push(title); |
| 249 | } |
| 250 | } |
| 251 | |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 252 | function init(test) { |
| 253 | var canvas = document.getElementById('canvas'); |
| 254 | if (!canvas.getContext) return; |
| 255 | screenWidth = canvas.width = window.innerWidth - 20; |
| 256 | screenHeight = canvas.height = window.innerHeight - 20; |
| 257 | ctx = canvas.getContext('2d'); |
| 258 | xmin = Infinity; |
| 259 | var xmax = -Infinity; |
| 260 | ymin = Infinity; |
| 261 | var ymax = -Infinity; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 262 | var scanType = -1; |
| 263 | for (var scansStr in test) { |
| 264 | var scans = parseInt(scansStr); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 265 | var scan = test[scans]; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 266 | if (scanType == -1) { |
| 267 | scanType = scan; |
| 268 | continue; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 269 | } |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 270 | if (scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN |
| 271 | || scanType == ACTIVE_CUBIC_SPAN) { |
| 272 | var last = scanType == ACTIVE_CUBIC_SPAN ? SPAN_X4 |
| 273 | : scanType == ACTIVE_QUAD_SPAN ? SPAN_X3 : SPAN_X2; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 274 | for (var idx = SPAN_X1; idx <= last; idx += 2) { |
| 275 | xmin = Math.min(xmin, scan[idx]); |
| 276 | xmax = Math.max(xmax, scan[idx]); |
| 277 | ymin = Math.min(ymin, scan[idx + 1]); |
| 278 | ymax = Math.max(ymax, scan[idx + 1]); |
| 279 | } |
| 280 | } else { |
| 281 | var start = 1; |
| 282 | if (scanType != INTERSECT_QUAD_LINE_NO && scanType != INTERSECT_QUAD_NO) { |
| 283 | start = 2; |
| 284 | } |
| 285 | for (var idx = start; idx < start + 6; idx += 2) { |
| 286 | xmin = Math.min(xmin, scan[idx]); |
| 287 | xmax = Math.max(xmax, scan[idx]); |
| 288 | ymin = Math.min(ymin, scan[idx + 1]); |
| 289 | ymax = Math.max(ymax, scan[idx + 1]); |
| 290 | } |
| 291 | start = start + 6; |
| 292 | if (scanType == INTERSECT_QUAD_LINE || scanType == INTERSECT_QUAD) { |
| 293 | start += 3; |
| 294 | } |
| 295 | if (scanType == INTERSECT_QUAD_LINE_2) { |
| 296 | start += 6; |
| 297 | } |
| 298 | if (scanType == INTERSECT_QUAD_2) { |
| 299 | start += 4; |
| 300 | } |
| 301 | var end = start + 4; |
| 302 | if (scanType == INTERSECT_QUAD || scanType == INTERSECT_QUAD_2 || scanType == INTERSECT_QUAD_NO) { |
| 303 | end += 2; |
| 304 | } |
| 305 | for (var idx = start; idx < end; idx += 2) { |
| 306 | xmin = Math.min(xmin, scan[idx]); |
| 307 | xmax = Math.max(xmax, scan[idx]); |
| 308 | ymin = Math.min(ymin, scan[idx + 1]); |
| 309 | ymax = Math.max(ymax, scan[idx + 1]); |
| 310 | } |
| 311 | } |
| 312 | scanType = -1; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 313 | } |
| 314 | srcWidth = xmax - xmin; |
| 315 | srcHeight = ymax - ymin; |
| 316 | var hscale = ctx.canvas.width / srcWidth; |
| 317 | var vscale = ctx.canvas.height / srcHeight; |
| 318 | var minScale = Math.min(hscale, vscale); |
| 319 | scale = minScale; |
| 320 | srcLeft = xmin; |
| 321 | srcTop = ymin; |
| 322 | } |
| 323 | |
| 324 | function drawPoint(px, py) { |
| 325 | for (var pts = 0; pts < drawnPts.length; pts += 2) { |
| 326 | var x = drawnPts[pts]; |
| 327 | var y = drawnPts[pts + 1]; |
| 328 | if (px == x && py == y) { |
| 329 | return; |
| 330 | } |
| 331 | } |
| 332 | drawnPts.push(px); |
| 333 | drawnPts.push(py); |
| 334 | var label = px.toFixed(decimal_places) + ", " + py.toFixed(decimal_places); |
| 335 | var _px = (px - srcLeft)* scale; |
| 336 | var _py = (py - srcTop) * scale; |
| 337 | ctx.beginPath(); |
| 338 | ctx.arc(_px, _py, 3, 0, Math.PI*2, true); |
| 339 | ctx.closePath(); |
| 340 | ctx.fill(); |
| 341 | ctx.fillText(label, _px + 5, _py); |
| 342 | } |
| 343 | |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 344 | function drawLine(x1, y1, x2, y2, selected) { |
| 345 | for (var pts = 0; pts < drawnLines.length; pts += 4) { |
| 346 | if (x1 == drawnLines[pts] && y1 == drawnLines[pts + 1]) { |
| 347 | return; |
| 348 | } |
| 349 | if (x2 == drawnLines[pts + 2] && x2 == drawnLines[pts + 3]) { |
| 350 | return; |
| 351 | } |
| 352 | } |
| 353 | if (selected) { |
| 354 | drawnLines.push(x1); |
| 355 | drawnLines.push(y1); |
| 356 | drawnLines.push(x2); |
| 357 | drawnLines.push(y2); |
| 358 | ctx.beginPath(); |
| 359 | ctx.moveTo((x1 - srcLeft) * scale, |
| 360 | (y1 - srcTop) * scale); |
| 361 | ctx.lineTo((x2 - srcLeft) * scale, |
| 362 | (y2 - srcTop) * scale); |
| 363 | ctx.stroke(); |
| 364 | return; |
| 365 | } |
| 366 | deferredLines.push(x1); |
| 367 | deferredLines.push(y1); |
| 368 | deferredLines.push(x2); |
| 369 | deferredLines.push(y2); |
| 370 | } |
| 371 | |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 372 | function drawLinePartial(x1, y1, x2, y2, t1, t2) { |
| 373 | var dx = x1 - x2; |
| 374 | var dy = y1 - y2; |
| 375 | var ax = x1 - t1 * dx; |
| 376 | var ay = y1 - t1 * dy; |
| 377 | var bx = x1 - t2 * dx; |
| 378 | var by = y1 - t2 * dy; |
| 379 | ctx.beginPath(); |
| 380 | ctx.moveTo((ax - srcLeft) * scale, |
| 381 | (ay - srcTop) * scale); |
| 382 | ctx.lineTo((bx - srcLeft) * scale, |
| 383 | (by - srcTop) * scale); |
| 384 | ctx.stroke(); |
| 385 | } |
| 386 | |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 387 | function drawQuad(x1, y1, x2, y2, x3, y3, selected) { |
| 388 | for (var pts = 0; pts < drawnQuads.length; pts += 6) { |
| 389 | if (x1 == drawnQuads[pts] && y1 == drawnQuads[pts + 1]) { |
| 390 | return; |
| 391 | } |
| 392 | if (x2 == drawnQuads[pts + 2] && x2 == drawnQuads[pts + 3]) { |
| 393 | return; |
| 394 | } |
| 395 | if (x2 == drawnQuads[pts + 4] && x2 == drawnQuads[pts + 5]) { |
| 396 | return; |
| 397 | } |
| 398 | } |
| 399 | if (selected) { |
| 400 | drawnQuads.push(x1); |
| 401 | drawnQuads.push(y1); |
| 402 | drawnQuads.push(x2); |
| 403 | drawnQuads.push(y2); |
| 404 | drawnQuads.push(x3); |
| 405 | drawnQuads.push(y3); |
| 406 | ctx.beginPath(); |
| 407 | ctx.moveTo((x1 - srcLeft) * scale, |
| 408 | (y1 - srcTop) * scale); |
| 409 | ctx.quadraticCurveTo((x2 - srcLeft) * scale, |
| 410 | (y2 - srcTop) * scale, |
| 411 | (x3 - srcLeft) * scale, |
| 412 | (y3 - srcTop) * scale); |
| 413 | ctx.stroke(); |
| 414 | return; |
| 415 | } |
| 416 | deferredQuads.push(x1); |
| 417 | deferredQuads.push(y1); |
| 418 | deferredQuads.push(x2); |
| 419 | deferredQuads.push(y2); |
| 420 | deferredQuads.push(x3); |
| 421 | deferredQuads.push(y3); |
| 422 | } |
| 423 | |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 424 | function interp(A, B, t) { |
| 425 | return A + (B - A) * t; |
| 426 | } |
| 427 | |
| 428 | function interp_quad_coords(x1, x2, x3, t) |
| 429 | { |
| 430 | var ab = interp(x1, x2, t); |
| 431 | var bc = interp(x2, x3, t); |
| 432 | var abc = interp(ab, bc, t); |
| 433 | return abc; |
| 434 | } |
| 435 | |
| 436 | function drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2) { |
| 437 | var ax = interp_quad_coords(x1, x2, x3, t1); |
| 438 | var ay = interp_quad_coords(y1, y2, y3, t1); |
| 439 | var dx = interp_quad_coords(x1, x2, x3, (t1 + t2) / 2); |
| 440 | var dy = interp_quad_coords(y1, y2, y3, (t1 + t2) / 2); |
| 441 | var cx = interp_quad_coords(x1, x2, x3, t2); |
| 442 | var cy = interp_quad_coords(y1, y2, y3, t2); |
| 443 | var bx = 2*dx - (ax + cx)/2; |
| 444 | var by = 2*dy - (ay + cy)/2; |
| 445 | ctx.beginPath(); |
| 446 | ctx.moveTo((ax - srcLeft) * scale, |
| 447 | (ay - srcTop) * scale); |
| 448 | ctx.quadraticCurveTo((bx - srcLeft) * scale, |
| 449 | (by - srcTop) * scale, |
| 450 | (cx - srcLeft) * scale, |
| 451 | (cy - srcTop) * scale); |
| 452 | ctx.stroke(); |
| 453 | } |
| 454 | |
| 455 | function drawCubic(x1, y1, x2, y2, x3, y3, x4, y4, selected) { |
| 456 | for (var pts = 0; pts < drawnCubics.length; pts += 8) { |
| 457 | if (x1 == drawnCubics[pts] && y1 == drawnCubics[pts + 1]) { |
| 458 | return; |
| 459 | } |
| 460 | if (x2 == drawnCubics[pts + 2] && x2 == drawnCubics[pts + 3]) { |
| 461 | return; |
| 462 | } |
| 463 | if (x2 == drawnCubics[pts + 4] && x2 == drawnCubics[pts + 5]) { |
| 464 | return; |
| 465 | } |
| 466 | if (x2 == drawnCubics[pts + 6] && x2 == drawnCubics[pts + 7]) { |
| 467 | return; |
| 468 | } |
| 469 | } |
| 470 | if (selected) { |
| 471 | drawnCubics.push(x1); |
| 472 | drawnCubics.push(y1); |
| 473 | drawnCubics.push(x2); |
| 474 | drawnCubics.push(y2); |
| 475 | drawnCubics.push(x3); |
| 476 | drawnCubics.push(y3); |
| 477 | drawnCubics.push(x4); |
| 478 | drawnCubics.push(y4); |
| 479 | ctx.beginPath(); |
| 480 | ctx.moveTo((x1 - srcLeft) * scale, |
| 481 | (y1 - srcTop) * scale); |
| 482 | ctx.bezierCurveTo((x2 - srcLeft) * scale, |
| 483 | (y2 - srcTop) * scale, |
| 484 | (x3 - srcLeft) * scale, |
| 485 | (y3 - srcTop) * scale, |
| 486 | (x4 - srcLeft) * scale, |
| 487 | (y4 - srcTop) * scale); |
| 488 | ctx.stroke(); |
| 489 | return; |
| 490 | } |
| 491 | deferredCubics.push(x1); |
| 492 | deferredCubics.push(y1); |
| 493 | deferredCubics.push(x2); |
| 494 | deferredCubics.push(y2); |
| 495 | deferredCubics.push(x3); |
| 496 | deferredCubics.push(y3); |
| 497 | deferredCubics.push(x4); |
| 498 | deferredCubics.push(y4); |
| 499 | } |
| 500 | |
| 501 | function interp_cubic_coords(x1, x2, x3, x4, t) |
| 502 | { |
| 503 | var ab = interp(x1, x2, t); |
| 504 | var bc = interp(x2, x3, t); |
| 505 | var cd = interp(x3, x4, t); |
| 506 | var abc = interp(ab, bc, t); |
| 507 | var bcd = interp(bc, cd, t); |
| 508 | var abcd = interp(abc, bcd, t); |
| 509 | return abcd; |
| 510 | } |
| 511 | |
| 512 | function drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2) { |
| 513 | var ax = interp_cubic_coords(x1, x2, x3, x4, t1); |
| 514 | var ay = interp_cubic_coords(y1, y2, y3, y4, t1); |
| 515 | var ex = interp_cubic_coords(x1, x2, x3, x4, (t1*2+t2)/3); |
| 516 | var ey = interp_cubic_coords(y1, y2, y3, y4, (t1*2+t2)/3); |
| 517 | var fx = interp_cubic_coords(x1, x2, x3, x4, (t1+t2*2)/3); |
| 518 | var fy = interp_cubic_coords(y1, y2, y3, y4, (t1+t2*2)/3); |
| 519 | var dx = interp_cubic_coords(x1, x2, x3, x4, t2); |
| 520 | var dy = interp_cubic_coords(y1, y2, y3, y4, t2); |
| 521 | var mx = ex * 27 - ax * 8 - dx; |
| 522 | var my = ey * 27 - ay * 8 - dy; |
| 523 | var nx = fx * 27 - ax - dx * 8; |
| 524 | var ny = fy * 27 - ay - dy * 8; |
| 525 | var bx = (mx * 2 - nx) / 18; |
| 526 | var by = (my * 2 - ny) / 18; |
| 527 | var cx = (nx * 2 - mx) / 18; |
| 528 | var cy = (ny * 2 - my) / 18; |
| 529 | ctx.beginPath(); |
| 530 | ctx.moveTo((ax - srcLeft) * scale, |
| 531 | (ay - srcTop) * scale); |
| 532 | ctx.bezierCurveTo((bx - srcLeft) * scale, |
| 533 | (by - srcTop) * scale, |
| 534 | (cx - srcLeft) * scale, |
| 535 | (cy - srcTop) * scale, |
| 536 | (dx - srcLeft) * scale, |
| 537 | (dy - srcTop) * scale, |
| 538 | (ex - srcLeft) * scale, |
| 539 | (ey - srcTop) * scale); |
| 540 | ctx.stroke(); |
| 541 | } |
| 542 | |
| 543 | function drawPartial(test) { |
| 544 | ctx.lineWidth = 3; |
| 545 | ctx.strokeStyle = "rgba(0,0,255, 0.3)"; |
| 546 | var scanType = -1; |
| 547 | var partIndex = 0; |
| 548 | for (var scansStr in test) { |
| 549 | var scans = parseInt(scansStr); |
| 550 | var scan = test[scans]; |
| 551 | if (scanType == -1) { |
| 552 | scanType = scan; |
| 553 | continue; |
| 554 | } |
| 555 | partIndex++; |
| 556 | var hasId = scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN |
| 557 | || scanType == ACTIVE_CUBIC_SPAN ? SPAN_ID : -1; |
| 558 | if (hasId < 0) { |
| 559 | continue; |
| 560 | } |
| 561 | var types = [scanType == ACTIVE_LINE_SPAN ? 0 : scanType == ACTIVE_QUAD_SPAN ? 1 : 2]; |
| 562 | var x1 = scan[SPAN_X1]; |
| 563 | var y1 = scan[SPAN_Y1]; |
| 564 | var x2 = scan[SPAN_X2]; |
| 565 | var y2 = scan[SPAN_Y2]; |
| 566 | var x3, y3, x3, y4, t1, t2; |
| 567 | switch(scanType) { |
| 568 | case ACTIVE_LINE_SPAN: |
| 569 | t1 = scan[SPAN_L_T]; |
| 570 | t2 = scan[SPAN_L_TEND]; |
| 571 | drawLinePartial(x1, y1, x2, y2, t1, t2); |
| 572 | break; |
| 573 | case ACTIVE_QUAD_SPAN: |
| 574 | x3 = scan[SPAN_X3]; |
| 575 | y3 = scan[SPAN_Y3]; |
| 576 | t1 = scan[SPAN_Q_T]; |
| 577 | t2 = scan[SPAN_Q_TEND]; |
| 578 | drawQuadPartial(x1, y1, x2, y2, x3, y3, t1, t2); |
| 579 | break; |
| 580 | case ACTIVE_CUBIC_SPAN: |
| 581 | x3 = scan[SPAN_X3]; |
| 582 | y3 = scan[SPAN_Y3]; |
| 583 | x4 = scan[SPAN_X4]; |
| 584 | y4 = scan[SPAN_Y4]; |
| 585 | t1 = scan[SPAN_C_T]; |
| 586 | t2 = scan[SPAN_C_TEND]; |
| 587 | drawCubicPartial(x1, y1, x2, y2, x3, y3, x4, y4, t1, t2); |
| 588 | break; |
| 589 | } |
| 590 | scanType = -1; |
| 591 | } |
| 592 | } |
| 593 | |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 594 | function drawDeferred() { |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 595 | for (var pts = 0; pts < deferredCubics.length; pts += 8) { |
| 596 | drawCubic(deferredCubics[pts], deferredCubics[pts + 1], |
| 597 | deferredCubics[pts + 2], deferredCubics[pts + 3], |
| 598 | deferredCubics[pts + 4], deferredCubics[pts + 5], |
| 599 | deferredCubics[pts + 6], deferredCubics[pts + 7], true); |
| 600 | } |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 601 | for (var pts = 0; pts < deferredQuads.length; pts += 6) { |
| 602 | drawQuad(deferredQuads[pts], deferredQuads[pts + 1], |
| 603 | deferredQuads[pts + 2], deferredQuads[pts + 3], |
| 604 | deferredQuads[pts + 4], deferredQuads[pts + 5], true); |
| 605 | } |
| 606 | for (var pts = 0; pts < deferredLines.length; pts += 4) { |
| 607 | drawLine(deferredLines[pts], deferredLines[pts + 1], |
| 608 | deferredLines[pts + 2], deferredLines[pts + 3], true); |
| 609 | } |
| 610 | } |
| 611 | |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 612 | function draw(test, title) { |
| 613 | ctx.fillStyle = "rgba(0,0,0, 0.1)"; |
| 614 | ctx.font = "normal 50px Arial"; |
| 615 | ctx.fillText(title, 50, 50); |
| 616 | ctx.font = "normal 10px Arial"; |
| 617 | ctx.lineWidth = "1.001"; "0.999"; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 618 | var curId = -1; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 619 | var firstIdx; |
| 620 | var lastIdx; |
| 621 | var index_tst = -1; |
| 622 | drawnPts = []; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 623 | drawnLines = []; |
| 624 | drawnQuads = []; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 625 | drawnCubics = []; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 626 | deferredLines = []; |
| 627 | deferredQuads = []; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 628 | deferredCubics = []; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 629 | var scanType = -1; |
| 630 | var partIndex = 0; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 631 | for (var scansStr in test) { |
| 632 | var scans = parseInt(scansStr); |
| 633 | var scan = test[scans]; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 634 | if (scanType == -1) { |
| 635 | scanType = scan; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 636 | continue; |
| 637 | } |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 638 | partIndex++; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 639 | var hasId = scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN |
| 640 | || scanType == ACTIVE_CUBIC_SPAN ? SPAN_ID : -1; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 641 | if (hasId >= 0 && curId != scan[hasId]) { |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 642 | curId = scan[hasId]; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 643 | firstIdx = lastIdx = partIndex; |
| 644 | index_tst++; |
| 645 | var nextIdx = lastIdx + 1; |
| 646 | while (nextIdx * 2 < test.length && test[nextIdx * 2][hasId] == curId) { |
| 647 | lastIdx = nextIdx++; |
| 648 | } |
| 649 | } else if (hasId < 0) { |
| 650 | firstIdx = lastIdx = partIndex; |
| 651 | index_tst++; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 652 | } |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 653 | var seq = sequence % (test.length / 2); |
| 654 | var selected = sequence >= 0 ? seq == partIndex |
| 655 | : (index_bits & (1 << index_tst)) != 0 && partIndex == firstIdx; |
| 656 | var skippable = (sequence >= 0 && seq >= firstIdx && seq <= lastIdx) |
| 657 | || partIndex != firstIdx; |
| 658 | if (skippable && !selected) { |
| 659 | scanType = -1; |
| 660 | continue; |
| 661 | } |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 662 | var types = [scanType == ACTIVE_LINE_SPAN ? 0 : scanType == ACTIVE_QUAD_SPAN ? 1 : 2]; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 663 | var pts = []; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 664 | if (scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN || scanType == ACTIVE_CUBIC_SPAN) { |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 665 | pts.push(SPAN_X1); |
| 666 | } else { |
| 667 | pts.push(scanType != INTERSECT_QUAD_NO && scanType != INTERSECT_QUAD_LINE_NO ? 2 : 1); |
| 668 | types.push(scanType == INTERSECT_QUAD_NO || scanType == INTERSECT_QUAD || scanType == INTERSECT_QUAD_2 ? 1 : 0); |
| 669 | pts.push(scanType == INTERSECT_QUAD_LINE || scanType == INTERSECT_QUAD ? 11 |
| 670 | : scanType == INTERSECT_QUAD_LINE_2 ? 14 : scanType == INTERSECT_QUAD_2 ? 12 : 7); |
| 671 | } |
| 672 | ctx.strokeStyle = "red"; |
| 673 | for (var typeIndex = 0; typeIndex < types.length; ++typeIndex) { |
| 674 | var type = types[typeIndex]; |
| 675 | var index = pts[typeIndex]; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 676 | if (type == 2) { |
| 677 | drawCubic(scan[index + 0], scan[index + 1], scan[index + 2], scan[index + 3], |
| 678 | scan[index + 4], scan[index + 5], scan[index + 6], scan[index + 7], |
| 679 | selected); |
| 680 | } else if (type == 1) { |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 681 | drawQuad(scan[index + 0], scan[index + 1], scan[index + 2], scan[index + 3], |
| 682 | scan[index + 4], scan[index + 5], selected); |
| 683 | } else { |
| 684 | drawLine(scan[index + 0], scan[index + 1], scan[index + 2], scan[index + 3], |
| 685 | selected); |
| 686 | } |
| 687 | } |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 688 | if (debug_xy && selected) { |
| 689 | var debugText = ""; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 690 | for (var typeIndex = 0; typeIndex < types.length; ++typeIndex) { |
| 691 | var type = types[typeIndex]; |
| 692 | var index = pts[typeIndex]; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 693 | for (var idx = pts[typeIndex]; idx < pts[typeIndex] + (type + 1) * 2; idx += 2) { |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 694 | var screenX = (scan[idx] - srcLeft) * scale; |
| 695 | var screenY = (scan[idx + 1] - srcTop) * scale; |
| 696 | debugText += screenX.toFixed(decimal_places) + ", "; |
| 697 | debugText += screenY.toFixed(decimal_places) + " "; |
| 698 | } |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 699 | } |
| 700 | ctx.fillStyle="blue"; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 701 | ctx.fillText(debugText, 50, partIndex * 50 + 100); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 702 | } |
| 703 | if (ptLabels && selected) { |
| 704 | ctx.fillStyle="blue"; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 705 | for (var typeIndex = 0; typeIndex < types.length; ++typeIndex) { |
| 706 | var type = types[typeIndex]; |
| 707 | var index = pts[typeIndex]; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 708 | for (var idx = pts[typeIndex]; idx < pts[typeIndex] + (type + 1) * 2; idx += 2) { |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 709 | drawPoint(scan[idx], scan[idx + 1]); |
| 710 | } |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 711 | } |
| 712 | } |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 713 | var infoText = ""; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 714 | if (info_mode && selected) { |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 715 | infoText += hasId >= 0 ? "id=" + scan[hasId] : partIndex; |
| 716 | } |
| 717 | if (intersect_mode && selected) { |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 718 | if (scanType == ACTIVE_CUBIC_SPAN) { |
| 719 | infoText += " t=" + scan[SPAN_C_T]; |
| 720 | } else if (scanType == ACTIVE_QUAD_SPAN) { |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 721 | infoText += " t=" + scan[SPAN_Q_T]; |
| 722 | } else if (scanType == ACTIVE_LINE_SPAN) { |
| 723 | infoText += " t=" + scan[SPAN_L_T]; |
| 724 | } else if (scanType == INTERSECT_QUAD_LINE ||scanType == INTERSECT_QUAD) { |
| 725 | infoText += " t0[0]=" + scan[1] + " t1[0]=" + scan[10]; |
| 726 | } else if (scanType == INTERSECT_QUAD_LINE_2 || scanType == INTERSECT_QUAD_2) { |
| 727 | infoText += " t0[0]=" + scan[1] + " t0[1]=" + scan[10] + " t1[0]=" + scan[13]; |
| 728 | if (scanType == INTERSECT_QUAD_LINE_2) { |
| 729 | infoText += " t1[1]=" + scan[18]; |
| 730 | } else { |
| 731 | infoText += " t0[1]=" + scan[20]; |
| 732 | } |
| 733 | } |
| 734 | } |
| 735 | if (infoText.length > 0) { |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 736 | ctx.fillStyle="green"; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 737 | ctx.fillText(infoText, 10, (hasId >= 0 && sequence >= 0 |
| 738 | ? hasId : partIndex) * 30 + 50); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 739 | } |
| 740 | if (intersect_mode && selected) { |
| 741 | ctx.fillStyle="rgba(50,100,200, 1.0)"; |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 742 | if (scanType == ACTIVE_CUBIC_SPAN) { |
| 743 | drawPoint(scan[SPAN_C_TX], scan[SPAN_C_TY]); |
| 744 | } else if (scanType == ACTIVE_QUAD_SPAN) { |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 745 | drawPoint(scan[SPAN_Q_TX], scan[SPAN_Q_TY]); |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 746 | } else if (scanType == ACTIVE_LINE_SPAN) { |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 747 | drawPoint(scan[SPAN_L_TX], scan[SPAN_L_TY]); |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 748 | } else if (scanType != INTERSECT_QUAD_NO && scanType != INTERSECT_QUAD_LINE_NO) { |
| 749 | drawPoint(scan[8], scan[9]); |
| 750 | if (scanType == INTERSECT_QUAD_LINE_2 || scanType == INTERSECT_QUAD_2) { |
| 751 | drawPoint(scan[11], scan[12]); |
| 752 | } |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 753 | } |
| 754 | } |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 755 | ctx.strokeStyle = "rgba(0,0,0, 0.2)"; |
| 756 | scanType = -1; |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 757 | } |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 758 | drawDeferred(); |
caryclark@google.com | 47d73da | 2013-02-17 01:41:25 +0000 | [diff] [blame] | 759 | drawPartial(test); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | function drawTop() { |
| 763 | init(tests[testIndex]); |
| 764 | redraw(); |
| 765 | } |
| 766 | |
| 767 | function redraw() { |
| 768 | ctx.beginPath(); |
| 769 | ctx.rect(0, 0, ctx.canvas.width, ctx.canvas.height); |
| 770 | ctx.fillStyle="white"; |
| 771 | ctx.fill(); |
| 772 | draw(tests[testIndex], testTitles[testIndex]); |
| 773 | } |
| 774 | |
| 775 | function doKeyPress(evt) { |
| 776 | var char = String.fromCharCode(evt.charCode); |
| 777 | switch (char) { |
| 778 | case '0': |
| 779 | case '1': |
| 780 | case '2': |
| 781 | case '3': |
| 782 | case '4': |
| 783 | case '5': |
| 784 | case '6': |
| 785 | case '7': |
| 786 | case '8': |
| 787 | case '9': |
| 788 | if (digit_mode) { |
| 789 | decimal_places = char - '0'; |
| 790 | } else if (index_mode) { |
| 791 | index_bits ^= 1 << (char - '0'); |
| 792 | } |
| 793 | redraw(); |
| 794 | break; |
| 795 | case 'd': |
| 796 | digit_mode = true; |
| 797 | index_mode = false; |
| 798 | break; |
| 799 | case 'f': |
| 800 | info_mode ^= true; |
| 801 | redraw(); |
| 802 | break; |
| 803 | case 'i': |
| 804 | digit_mode = false; |
| 805 | if (sequence >= 0) { |
| 806 | sequence = -1; |
| 807 | index_mode = false; |
| 808 | } else { |
| 809 | index_mode ^= true; |
| 810 | } |
| 811 | if (index_mode) { |
| 812 | index_bits = 0; |
| 813 | } else { |
| 814 | index_bits = -1; |
| 815 | } |
| 816 | redraw(); |
| 817 | break; |
| 818 | case 'N': |
| 819 | testIndex += 9; |
| 820 | case 'n': |
| 821 | if (++testIndex >= tests.length) |
| 822 | testIndex = 0; |
| 823 | drawTop(); |
| 824 | break; |
| 825 | case 'P': |
| 826 | testIndex -= 9; |
| 827 | case 'p': |
| 828 | if (--testIndex < 0) |
| 829 | testIndex = tests.length - 1; |
| 830 | drawTop(); |
| 831 | break; |
| 832 | case 's': |
| 833 | sequence++; |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 834 | redraw(); |
| 835 | break; |
| 836 | case 'S': |
| 837 | sequence--; |
| 838 | if (sequence < 0) { |
| 839 | sequence = 0; |
| 840 | } |
| 841 | redraw(); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 842 | break; |
| 843 | case 't': |
| 844 | intersect_mode ^= true; |
| 845 | redraw(); |
| 846 | break; |
| 847 | case 'x': |
| 848 | ptLabels ^= true; |
| 849 | redraw(); |
| 850 | break; |
| 851 | case 'y': |
| 852 | debug_xy ^= true; |
| 853 | redraw(); |
| 854 | break; |
| 855 | case '-': |
| 856 | scale /= 2; |
| 857 | calcLeftTop(); |
| 858 | redraw(); |
| 859 | break; |
| 860 | case '=': |
| 861 | case '+': |
| 862 | scale *= 2; |
| 863 | calcLeftTop(); |
| 864 | redraw(); |
| 865 | break; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | function calcXY() { |
| 870 | var e = window.event; |
| 871 | var tgt = e.target || e.srcElement; |
| 872 | var left = tgt.offsetLeft; |
| 873 | var top = tgt.offsetTop; |
| 874 | var unit = scale; |
| 875 | mouseX = (e.clientX - left) / scale + srcLeft; |
| 876 | mouseY = (e.clientY - top) / scale + srcTop; |
| 877 | } |
| 878 | |
| 879 | function calcLeftTop() { |
| 880 | srcLeft = mouseX - screenWidth / 2 / scale; |
| 881 | srcTop = mouseY - screenHeight / 2 / scale; |
| 882 | } |
| 883 | |
| 884 | function handleMouseClick() { |
| 885 | calcXY(); |
| 886 | calcLeftTop(); |
| 887 | redraw(); |
| 888 | } |
| 889 | |
| 890 | function handleMouseOver() { |
| 891 | calcXY(); |
| 892 | var num = mouseX.toFixed(decimal_places) + ", " + mouseY.toFixed(decimal_places); |
| 893 | ctx.beginPath(); |
| 894 | ctx.rect(300,100,200,10); |
| 895 | ctx.fillStyle="white"; |
| 896 | ctx.fill(); |
| 897 | ctx.fillStyle="black"; |
| 898 | ctx.fillText(num, 300, 108); |
| 899 | } |
| 900 | |
| 901 | function start() { |
| 902 | for (i = 0; i < testDivs.length; ++i) { |
| 903 | var title = testDivs[i].id.toString(); |
| 904 | var str = testDivs[i].firstChild.data; |
| 905 | parse_debugShowActiveSpans(str, title); |
caryclark@google.com | 0b7da43 | 2012-10-31 19:00:20 +0000 | [diff] [blame] | 906 | parse_intersections(str, title); |
caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 907 | } |
| 908 | drawTop(); |
| 909 | window.addEventListener('keypress', doKeyPress, true); |
| 910 | window.onresize = function() { |
| 911 | drawTop(); |
| 912 | } |
| 913 | } |
| 914 | |
| 915 | </script> |
| 916 | </head> |
| 917 | |
| 918 | <body onLoad="start();"> |
| 919 | <canvas id="canvas" width="750" height="500" |
| 920 | onmousemove="handleMouseOver()" |
| 921 | onclick="handleMouseClick()" |
| 922 | ></canvas > |
| 923 | </body> |
| 924 | </html> |