caryclark@google.com | f839c03 | 2012-10-26 21:03:50 +0000 | [diff] [blame] | 1 | <html> |
| 2 | <head> |
| 3 | <div style="height:0"> |
| 4 | |
| 5 | <div id="quad56"> |
| 6 | debugShowActiveSpans id=1 (366.608826,151.196014 378.803101,136.674606 398.164948,136.674606) t=0.490456543 (380.294495,140.44487) other=7 otherT=0.578520747 otherIndex=3 windSum=? windValue=1 |
| 7 | debugShowActiveSpans id=2 (398.164948,136.674606 354.009216,208.816208) t=0 (398.164948,136.674606) other=1 otherT=1 otherIndex=4 windSum=? windValue=1 |
| 8 | debugShowActiveSpans id=3 (354.009216,208.816208 393.291473,102.232819) t=0 (354.009216,208.816208) other=2 otherT=1 otherIndex=1 windSum=? windValue=1 |
| 9 | debugShowActiveSpans id=3 (354.009216,208.816208 393.291473,102.232819) t=0.508945199 (374.00174,154.571106) other=6 otherT=0.598402499 otherIndex=1 windSum=? windValue=1 |
| 10 | debugShowActiveSpans id=3 (354.009216,208.816208 393.291473,102.232819) t=0.634079491 (378.917297,141.233871) other=7 otherT=0.536512741 otherIndex=1 windSum=-1 windValue=1 |
| 11 | debugShowActiveSpans id=5 (359.978058,136.581512 378.315979,136.581512 388.322723,149.613556) t=0.597488996 (378.917297,141.233856) other=7 otherT=0.536512973 otherIndex=2 windSum=? windValue=1 |
| 12 | debugShowActiveSpans id=6 (388.322723,149.613556 364.390686,157.898193) t=0 (388.322723,149.613556) other=5 otherT=1 otherIndex=4 windSum=? windValue=1 |
| 13 | debugShowActiveSpans id=6 (388.322723,149.613556 364.390686,157.898193) t=0.598402499 (374.00174,154.571106) other=3 otherT=0.508945199 otherIndex=1 windSum=? windValue=1 |
| 14 | debugShowActiveSpans id=7 (364.390686,157.898193 375.281769,136.674606 396.039917,136.674606) t=0 (364.390686,157.898193) other=6 otherT=1 otherIndex=2 windSum=? windValue=1 |
| 15 | debugShowActiveSpans id=7 (364.390686,157.898193 375.281769,136.674606 396.039917,136.674606) t=0.536512741 (378.917297,141.233871) other=3 otherT=0.634079491 otherIndex=2 windSum=? windValue=1 |
| 16 | debugShowActiveSpans id=7 (364.390686,157.898193 375.281769,136.674606 396.039917,136.674606) t=0.536512973 (378.917297,141.233856) other=5 otherT=0.597488996 otherIndex=3 windSum=-1 windValue=1 |
| 17 | </div> |
| 18 | |
| 19 | <div id="quad57c"> |
| 20 | debugShowActiveSpans id=1 (303.12088,141.299606 330.463562,217.659027) t=0.845414865 (326.236786,205.854996) other=13 otherT=0.999999913 otherIndex=3 windSum=? windValue=1 |
| 21 | debugShowActiveSpans id=2 (330.463562,217.659027 358.606506,141.299606) t=-0 (330.463562,217.659027) other=1 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 22 | debugShowActiveSpans id=2 (330.463562,217.659027 358.606506,141.299606) t=0.154585135 (334.814056,205.854996) other=13 otherT=0.812241055 otherIndex=2 windSum=? windValue=1 |
| 23 | debugShowActiveSpans id=2 (330.463562,217.659027 358.606506,141.299606) t=0.283842806 (338.451721,195.984955) other=16 otherT=0.363593784 otherIndex=1 windSum=? windValue=1 |
| 24 | debugShowActiveSpans id=4 (362.874634,159.705902 335.665344,233.397751) t=0.379109438 (352.559326,187.643173) other=17 otherT=0.412818074 otherIndex=1 windSum=? windValue=1 |
| 25 | debugShowActiveSpans id=13 (371.919067,205.854996 326.236786,205.854996) t=0.812241055 (334.814056,205.854996) other=2 otherT=0.154585135 otherIndex=1 windSum=? windValue=1 |
| 26 | debugShowActiveSpans id=14 (326.236786,205.854996 329.104431,231.663818 351.512085,231.663818) t=0.962138429 (349.843323,231.626816) other=15 otherT=0.0583966647 otherIndex=1 windSum=1 windValue=1 |
| 27 | debugShowActiveSpans id=15 (351.512085,231.663818 322.935669,231.030273) t=0 (351.512085,231.663818) other=14 otherT=1 otherIndex=3 windSum=1 windValue=1 |
| 28 | debugShowActiveSpans id=16 (326.837006,195.984955 358.78125,195.984955) t=0 (326.837006,195.984955) other=18 otherT=1 otherIndex=1 windSum=? windValue=1 |
| 29 | debugShowActiveSpans id=16 (326.837006,195.984955 358.78125,195.984955) t=0.363593784 (338.451721,195.984955) other=2 otherT=0.283842806 otherIndex=2 windSum=? windValue=1 |
| 30 | debugShowActiveSpans id=16 (326.837006,195.984955 358.78125,195.984955) t=0.708806554 (349.479309,195.984955) other=4 otherT=0.492307539 otherIndex=3 windSum=? windValue=1 |
| 31 | debugShowActiveSpans id=17 (358.78125,195.984955 343.709442,175.778046) t=-0 (358.78125,195.984955) other=16 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 32 | debugShowActiveSpans id=17 (358.78125,195.984955 343.709442,175.778046) t=0.412818074 (352.559326,187.643173) other=4 otherT=0.379109438 otherIndex=2 windSum=? windValue=1 |
| 33 | debugShowActiveSpans id=17 (358.78125,195.984955 343.709442,175.778046) t=0.902761903 (345.174988,177.74292) other=2 otherT=0.522739691 otherIndex=3 windSum=? windValue=1 |
| 34 | debugShowActiveSpans id=18 (343.709442,175.778046 328.570923,175.778046 326.837006,195.984955) t=0 (343.709442,175.778046) other=17 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 35 | </div> |
| 36 | |
| 37 | <div id="quad57b"> |
| 38 | debugShowActiveSpans id=1 (303.12088,141.299606 330.463562,217.659027) t=0.845414865 (326.236786,205.854996) other=13 otherT=0.999999913 otherIndex=3 windSum=1 windValue=1 |
| 39 | debugShowActiveSpans id=2 (330.463562,217.659027 358.606506,141.299606) t=-0 (330.463562,217.659027) other=1 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 40 | debugShowActiveSpans id=2 (330.463562,217.659027 358.606506,141.299606) t=0.154585135 (334.814056,205.854996) other=13 otherT=0.812241055 otherIndex=2 windSum=? windValue=1 |
| 41 | debugShowActiveSpans id=2 (330.463562,217.659027 358.606506,141.299606) t=0.283842806 (338.451721,195.984955) other=16 otherT=0.363593784 otherIndex=1 windSum=? windValue=1 |
| 42 | debugShowActiveSpans id=4 (362.874634,159.705902 335.665344,233.397751) t=0.379109438 (352.559326,187.643173) other=17 otherT=0.412818074 otherIndex=1 windSum=? windValue=1 |
| 43 | debugShowActiveSpans id=13 (371.919067,205.854996 326.236786,205.854996) t=0.812241055 (334.814056,205.854996) other=2 otherT=0.154585135 otherIndex=1 windSum=? windValue=1 |
| 44 | debugShowActiveSpans id=16 (326.837006,195.984955 358.78125,195.984955) t=0 (326.837006,195.984955) other=18 otherT=1 otherIndex=1 windSum=? windValue=1 |
| 45 | debugShowActiveSpans id=16 (326.837006,195.984955 358.78125,195.984955) t=0.363593784 (338.451721,195.984955) other=2 otherT=0.283842806 otherIndex=2 windSum=? windValue=1 |
| 46 | debugShowActiveSpans id=16 (326.837006,195.984955 358.78125,195.984955) t=0.708806554 (349.479309,195.984955) other=4 otherT=0.492307539 otherIndex=3 windSum=? windValue=1 |
| 47 | debugShowActiveSpans id=17 (358.78125,195.984955 343.709442,175.778046) t=-0 (358.78125,195.984955) other=16 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 48 | debugShowActiveSpans id=17 (358.78125,195.984955 343.709442,175.778046) t=0.412818074 (352.559326,187.643173) other=4 otherT=0.379109438 otherIndex=2 windSum=? windValue=1 |
| 49 | debugShowActiveSpans id=17 (358.78125,195.984955 343.709442,175.778046) t=0.902761903 (345.174988,177.74292) other=2 otherT=0.522739691 otherIndex=3 windSum=? windValue=1 |
| 50 | debugShowActiveSpans id=18 (343.709442,175.778046 328.570923,175.778046 326.837006,195.984955) t=0 (343.709442,175.778046) other=17 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 51 | </div> |
| 52 | |
| 53 | <div id="quad57a"> |
| 54 | debugShowActiveSpans id=2 (330.463562,217.659027 358.606506,141.299606) t=0.154585135 (334.814056,205.854996) other=13 otherT=0.812241055 otherIndex=2 windSum=-1 windValue=1 |
| 55 | debugShowActiveSpans id=2 (330.463562,217.659027 358.606506,141.299606) t=0.283842806 (338.451721,195.984955) other=16 otherT=0.363593784 otherIndex=1 windSum=? windValue=1 |
| 56 | debugShowActiveSpans id=4 (362.874634,159.705902 335.665344,233.397751) t=0.379109438 (352.559326,187.643173) other=17 otherT=0.412818074 otherIndex=1 windSum=? windValue=1 |
| 57 | debugShowActiveSpans id=16 (326.837006,195.984955 358.78125,195.984955) t=0 (326.837006,195.984955) other=18 otherT=1 otherIndex=1 windSum=? windValue=1 |
| 58 | debugShowActiveSpans id=16 (326.837006,195.984955 358.78125,195.984955) t=0.363593784 (338.451721,195.984955) other=2 otherT=0.283842806 otherIndex=2 windSum=? windValue=1 |
| 59 | debugShowActiveSpans id=16 (326.837006,195.984955 358.78125,195.984955) t=0.708806554 (349.479309,195.984955) other=4 otherT=0.492307539 otherIndex=3 windSum=? windValue=1 |
| 60 | debugShowActiveSpans id=17 (358.78125,195.984955 343.709442,175.778046) t=-0 (358.78125,195.984955) other=16 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 61 | debugShowActiveSpans id=17 (358.78125,195.984955 343.709442,175.778046) t=0.412818074 (352.559326,187.643173) other=4 otherT=0.379109438 otherIndex=2 windSum=? windValue=1 |
| 62 | debugShowActiveSpans id=17 (358.78125,195.984955 343.709442,175.778046) t=0.902761903 (345.174988,177.74292) other=2 otherT=0.522739691 otherIndex=3 windSum=? windValue=1 |
| 63 | debugShowActiveSpans id=18 (343.709442,175.778046 328.570923,175.778046 326.837006,195.984955) t=0 (343.709442,175.778046) other=17 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 64 | </div> |
| 65 | |
| 66 | <div id="quad58b"> |
| 67 | debugShowActiveSpans id=3 (303.12088,141.299606 330.463562,217.659027) t=0.845414865 (326.236786,205.854996) other=16 otherT=0.999999913 otherIndex=3 windSum=1 windValue=1 |
| 68 | debugShowActiveSpans id=4 (330.463562,217.659027 358.606506,141.299606) t=-0 (330.463562,217.659027) other=3 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 69 | debugShowActiveSpans id=4 (330.463562,217.659027 358.606506,141.299606) t=0.154585135 (334.814056,205.854996) other=16 otherT=0.812241055 otherIndex=2 windSum=? windValue=1 |
| 70 | debugShowActiveSpans id=4 (330.463562,217.659027 358.606506,141.299606) t=0.283842806 (338.451721,195.984955) other=19 otherT=0.363593784 otherIndex=1 windSum=? windValue=1 |
| 71 | debugShowActiveSpans id=6 (362.874634,159.705902 335.665344,233.397751) t=0.287405665 (355.054535,180.885361) other=20 otherT=0.497256785 otherIndex=1 windSum=? windValue=1 |
| 72 | debugShowActiveSpans id=16 (371.919067,205.854996 326.236786,205.854996) t=0.812241055 (334.814056,205.854996) other=4 otherT=0.154585135 otherIndex=1 windSum=? windValue=1 |
| 73 | debugShowActiveSpans id=19 (326.837006,195.984955 358.78125,195.984955) t=0 (326.837006,195.984955) other=21 otherT=1 otherIndex=1 windSum=? windValue=1 |
| 74 | debugShowActiveSpans id=19 (326.837006,195.984955 358.78125,195.984955) t=0.363593784 (338.451721,195.984955) other=4 otherT=0.283842806 otherIndex=2 windSum=? windValue=1 |
| 75 | debugShowActiveSpans id=19 (326.837006,195.984955 358.78125,195.984955) t=0.708806554 (349.479309,195.984955) other=6 otherT=0.492307539 otherIndex=3 windSum=? windValue=1 |
| 76 | debugShowActiveSpans id=20 (358.78125,195.984955 358.78125,175.778046 343.709442,175.778046) t=0 (358.78125,195.984955) other=19 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 77 | debugShowActiveSpans id=20 (358.78125,195.984955 358.78125,175.778046 343.709442,175.778046) t=0.497256785 (355.054535,180.885361) other=6 otherT=0.287405665 otherIndex=2 windSum=? windValue=1 |
| 78 | debugShowActiveSpans id=20 (358.78125,195.984955 358.78125,175.778046 343.709442,175.778046) t=0.925970638 (345.858368,175.888794) other=4 otherT=0.547021444 otherIndex=3 windSum=? windValue=1 |
| 79 | debugShowActiveSpans id=21 (343.709442,175.778046 328.570923,175.778046 326.837006,195.984955) t=0 (343.709442,175.778046) other=20 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 80 | </div> |
| 81 | |
| 82 | <div id="quad58a"> |
| 83 | debugShowActiveSpans id=4 (330.463562,217.659027 358.606506,141.299606) t=0.154585135 (334.814056,205.854996) other=16 otherT=0.812241055 otherIndex=2 windSum=-1 windValue=1 |
| 84 | debugShowActiveSpans id=4 (330.463562,217.659027 358.606506,141.299606) t=0.283842806 (338.451721,195.984955) other=19 otherT=0.363593784 otherIndex=1 windSum=? windValue=1 |
| 85 | debugShowActiveSpans id=6 (362.874634,159.705902 335.665344,233.397751) t=0.287405665 (355.054535,180.885361) other=20 otherT=0.497256785 otherIndex=1 windSum=? windValue=1 |
| 86 | debugShowActiveSpans id=19 (326.837006,195.984955 358.78125,195.984955) t=0 (326.837006,195.984955) other=21 otherT=1 otherIndex=1 windSum=? windValue=1 |
| 87 | debugShowActiveSpans id=19 (326.837006,195.984955 358.78125,195.984955) t=0.363593784 (338.451721,195.984955) other=4 otherT=0.283842806 otherIndex=2 windSum=? windValue=1 |
| 88 | debugShowActiveSpans id=19 (326.837006,195.984955 358.78125,195.984955) t=0.708806554 (349.479309,195.984955) other=6 otherT=0.492307539 otherIndex=3 windSum=? windValue=1 |
| 89 | debugShowActiveSpans id=20 (358.78125,195.984955 358.78125,175.778046 343.709442,175.778046) t=0 (358.78125,195.984955) other=19 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 90 | debugShowActiveSpans id=20 (358.78125,195.984955 358.78125,175.778046 343.709442,175.778046) t=0.497256785 (355.054535,180.885361) other=6 otherT=0.287405665 otherIndex=2 windSum=? windValue=1 |
| 91 | debugShowActiveSpans id=20 (358.78125,195.984955 358.78125,175.778046 343.709442,175.778046) t=0.925970638 (345.858368,175.888794) other=4 otherT=0.547021444 otherIndex=3 windSum=? windValue=1 |
| 92 | debugShowActiveSpans id=21 (343.709442,175.778046 328.570923,175.778046 326.837006,195.984955) t=0 (343.709442,175.778046) other=20 otherT=1 otherIndex=3 windSum=? windValue=1 |
| 93 | </div> |
| 94 | |
| 95 | </div> |
| 96 | |
| 97 | <script type="text/javascript"> |
| 98 | |
| 99 | var testDivs = [ |
| 100 | quad58b, |
| 101 | quad58a, |
| 102 | quad57c, |
| 103 | quad57b, |
| 104 | quad57a, |
| 105 | quad56, |
| 106 | ]; |
| 107 | |
| 108 | var decimal_places = 3; // make this 3 to show more precision |
| 109 | |
| 110 | var tests = []; |
| 111 | var testTitles = []; |
| 112 | var testIndex = 0; |
| 113 | var ctx; |
| 114 | |
| 115 | var xmin; |
| 116 | var ymin; |
| 117 | var scale; |
| 118 | var mouseX, mouseY; |
| 119 | var srcLeft, srcTop; |
| 120 | var srcWidth, srcHeight; |
| 121 | var screenWidth, screenHeight; |
| 122 | var drawnPts; |
| 123 | |
| 124 | var ptLabels = true; |
| 125 | var digit_mode = false; |
| 126 | var index_mode = true; |
| 127 | var index_bits = -1; |
| 128 | var debug_xy = false; |
| 129 | var info_mode = false; |
| 130 | var intersect_mode = false; |
| 131 | var sequence = -1; |
| 132 | |
| 133 | var SPAN_ID = 1; |
| 134 | var SPAN_X1 = 2; |
| 135 | var SPAN_Y1 = 3; |
| 136 | var SPAN_X2 = 4; |
| 137 | var SPAN_Y2 = 5; |
| 138 | var SPAN_L_T = 6; |
| 139 | var SPAN_L_TX = 7; |
| 140 | var SPAN_L_TY = 8; |
| 141 | var SPAN_L_OTHER = 9; |
| 142 | var SPAN_L_OTHERT = 10; |
| 143 | var SPAN_L_OTHERI = 11; |
| 144 | var SPAN_L_SUM = 12; |
| 145 | var SPAN_L_VAL = 13; |
| 146 | |
| 147 | var SPAN_X3 = 6; |
| 148 | var SPAN_Y3 = 7; |
| 149 | var SPAN_Q_T = 8; |
| 150 | var SPAN_Q_TX = 9; |
| 151 | var SPAN_Q_TY = 10; |
| 152 | var SPAN_Q_OTHER = 11; |
| 153 | var SPAN_Q_OTHERT = 12; |
| 154 | var SPAN_Q_OTHERI = 13; |
| 155 | var SPAN_Q_SUM = 14; |
| 156 | var SPAN_Q_VAL = 15; |
| 157 | |
| 158 | var Q_LENGTH = 18; |
| 159 | |
| 160 | function strs_to_nums(strs) { |
| 161 | var result = []; |
| 162 | for (var idx in strs) { |
| 163 | var str = strs[idx]; |
| 164 | var num = parseFloat(str); |
| 165 | if (isNaN(num)) { |
| 166 | result.push(str); |
| 167 | } else { |
| 168 | result.push(num); |
| 169 | } |
| 170 | } |
| 171 | return result; |
| 172 | } |
| 173 | |
| 174 | function parse_debugShowActiveSpans(test, title) { |
| 175 | var re_quad = / id=(\d+) \((\d+\.?\d*),(\d+\.?\d*) (\d+\.?\d*),(\d+\.?\d*) (\d+\.?\d*),(\d+\.?\d*)\) t=(\d+\.?\d*) \((\d+\.?\d*),(\d+\.?\d*)\) other=(\d+) otherT=(\d+\.?\d*) otherIndex=(\d+) windSum=(\?|-?\d+) windValue=(\d+)/; |
| 176 | var re_line = / id=(\d+) \((\d+\.?\d*),(\d+\.?\d*) (\d+\.?\d*),(\d+\.?\d*)\) t=(\d+\.?\d*) \((\d+\.?\d*),(\d+\.?\d*)\) other=(\d+) otherT=(\d+\.?\d*) otherIndex=(\d+) windSum=(\?|-?\d+) windValue=(\d+)/; |
| 177 | |
| 178 | var strs = test.split("debugShowActiveSpans"); |
| 179 | if (strs.length == 1) |
| 180 | return; |
| 181 | var spans = []; |
| 182 | for (var s in strs) { |
| 183 | var str = strs[s]; |
| 184 | if (str == "\n") { |
| 185 | continue; |
| 186 | } |
| 187 | if (re_line.test(str)) { |
| 188 | var lineStrs = re_line.exec(str); |
| 189 | var line = strs_to_nums(lineStrs); |
| 190 | spans.push(line); |
| 191 | } else if (re_quad.test(str)) { |
| 192 | var quadStrs = re_quad.exec(str); |
| 193 | var quad = strs_to_nums(quadStrs); |
| 194 | spans.push(quad); |
| 195 | } |
| 196 | } |
| 197 | if (spans.length >= 1) { |
| 198 | tests.push(spans); |
| 199 | testTitles.push(title); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | function init(test) { |
| 204 | var canvas = document.getElementById('canvas'); |
| 205 | if (!canvas.getContext) return; |
| 206 | screenWidth = canvas.width = window.innerWidth - 20; |
| 207 | screenHeight = canvas.height = window.innerHeight - 20; |
| 208 | ctx = canvas.getContext('2d'); |
| 209 | xmin = Infinity; |
| 210 | var xmax = -Infinity; |
| 211 | ymin = Infinity; |
| 212 | var ymax = -Infinity; |
| 213 | for (var scans in test) { |
| 214 | var scan = test[scans]; |
| 215 | var last = scan.length >= Q_LENGTH ? SPAN_X3 : SPAN_X2; |
| 216 | for (var idx = SPAN_X1; idx <= last; idx += 2) { |
| 217 | xmin = Math.min(xmin, scan[idx]); |
| 218 | xmax = Math.max(xmax, scan[idx]); |
| 219 | ymin = Math.min(ymin, scan[idx + 1]); |
| 220 | ymax = Math.max(ymax, scan[idx + 1]); |
| 221 | } |
| 222 | } |
| 223 | srcWidth = xmax - xmin; |
| 224 | srcHeight = ymax - ymin; |
| 225 | var hscale = ctx.canvas.width / srcWidth; |
| 226 | var vscale = ctx.canvas.height / srcHeight; |
| 227 | var minScale = Math.min(hscale, vscale); |
| 228 | scale = minScale; |
| 229 | srcLeft = xmin; |
| 230 | srcTop = ymin; |
| 231 | } |
| 232 | |
| 233 | function drawPoint(px, py) { |
| 234 | for (var pts = 0; pts < drawnPts.length; pts += 2) { |
| 235 | var x = drawnPts[pts]; |
| 236 | var y = drawnPts[pts + 1]; |
| 237 | if (px == x && py == y) { |
| 238 | return; |
| 239 | } |
| 240 | } |
| 241 | drawnPts.push(px); |
| 242 | drawnPts.push(py); |
| 243 | var label = px.toFixed(decimal_places) + ", " + py.toFixed(decimal_places); |
| 244 | var _px = (px - srcLeft)* scale; |
| 245 | var _py = (py - srcTop) * scale; |
| 246 | ctx.beginPath(); |
| 247 | ctx.arc(_px, _py, 3, 0, Math.PI*2, true); |
| 248 | ctx.closePath(); |
| 249 | ctx.fill(); |
| 250 | ctx.fillText(label, _px + 5, _py); |
| 251 | } |
| 252 | |
| 253 | function draw(test, title) { |
| 254 | ctx.fillStyle = "rgba(0,0,0, 0.1)"; |
| 255 | ctx.font = "normal 50px Arial"; |
| 256 | ctx.fillText(title, 50, 50); |
| 257 | ctx.font = "normal 10px Arial"; |
| 258 | ctx.lineWidth = "1.001"; "0.999"; |
| 259 | var id = -1; |
| 260 | var firstIdx; |
| 261 | var lastIdx; |
| 262 | var index_tst = -1; |
| 263 | drawnPts = []; |
| 264 | for (var scansStr in test) { |
| 265 | var scans = parseInt(scansStr); |
| 266 | var scan = test[scans]; |
| 267 | var isQuad = scan.length >= Q_LENGTH; |
| 268 | if (id != scan[SPAN_ID]) { |
| 269 | id = scan[SPAN_ID]; |
| 270 | firstIdx = lastIdx = scans; |
| 271 | ++index_tst; |
| 272 | var nextIdx = lastIdx + 1; |
| 273 | while (nextIdx < test.length && test[nextIdx][SPAN_ID] == id) { |
| 274 | lastIdx = nextIdx++; |
| 275 | } |
| 276 | } |
| 277 | var seq = sequence % test.length; |
| 278 | var selected = sequence >= 0 ? seq == scans |
| 279 | : (index_bits & (1 << index_tst)) != 0 && scans == firstIdx; |
| 280 | var skippable = (sequence >= 0 && seq >= firstIdx && seq <= lastIdx) |
| 281 | || scans != firstIdx; |
| 282 | if (skippable && !selected) { |
| 283 | continue; |
| 284 | } |
| 285 | ctx.strokeStyle = selected ? "red" : "rgba(0,0,0, 0.2)"; |
| 286 | ctx.beginPath(); |
| 287 | ctx.moveTo((scan[SPAN_X1] - srcLeft)* scale, |
| 288 | (scan[SPAN_Y1] - srcTop) * scale); |
| 289 | if (isQuad) { |
| 290 | ctx.quadraticCurveTo((scan[SPAN_X2] - srcLeft) * scale, |
| 291 | (scan[SPAN_Y2] - srcTop) * scale, |
| 292 | (scan[SPAN_X3] - srcLeft) * scale, |
| 293 | (scan[SPAN_Y3] - srcTop) * scale); |
| 294 | } else { |
| 295 | ctx.lineTo((scan[SPAN_X2] - srcLeft)* scale, |
| 296 | (scan[SPAN_Y2] - srcTop) * scale); |
| 297 | } |
| 298 | ctx.stroke(); |
| 299 | if (debug_xy && selected) { |
| 300 | var debugText = ""; |
| 301 | for (var idx = SPAN_X1; idx <= (isQuad ? SPAN_X3 : SPAN_X2); idx += 2) { |
| 302 | var screenX = (scan[idx] - srcLeft) * scale; |
| 303 | var screenY = (scan[idx + 1] - srcTop) * scale; |
| 304 | debugText += screenX.toFixed(decimal_places) + ", "; |
| 305 | debugText += screenY.toFixed(decimal_places) + " "; |
| 306 | } |
| 307 | ctx.fillStyle="blue"; |
| 308 | ctx.fillText(debugText, 50, scans * 50 + 100); |
| 309 | } |
| 310 | if (ptLabels && selected) { |
| 311 | ctx.fillStyle="blue"; |
| 312 | drawPoint(scan[SPAN_X1], scan[SPAN_Y1]); |
| 313 | drawPoint(scan[SPAN_X2], scan[SPAN_Y2]); |
| 314 | if (scan.length >= Q_LENGTH) { |
| 315 | drawPoint(scan[SPAN_X3], scan[SPAN_Y3]); |
| 316 | } |
| 317 | } |
| 318 | if (info_mode && selected) { |
| 319 | var infoText = "id=" + scan[SPAN_ID]; |
| 320 | ctx.fillStyle="green"; |
| 321 | ctx.fillText(infoText, 10, scans * 50 + 100); |
| 322 | } |
| 323 | if (intersect_mode && selected) { |
| 324 | ctx.fillStyle="rgba(50,100,200, 1.0)"; |
| 325 | if (isQuad) { |
| 326 | drawPoint(scan[SPAN_Q_TX], scan[SPAN_Q_TY]); |
| 327 | } else { |
| 328 | drawPoint(scan[SPAN_L_TX], scan[SPAN_L_TY]); |
| 329 | } |
| 330 | } |
| 331 | } |
| 332 | } |
| 333 | |
| 334 | function drawTop() { |
| 335 | init(tests[testIndex]); |
| 336 | redraw(); |
| 337 | } |
| 338 | |
| 339 | function redraw() { |
| 340 | ctx.beginPath(); |
| 341 | ctx.rect(0, 0, ctx.canvas.width, ctx.canvas.height); |
| 342 | ctx.fillStyle="white"; |
| 343 | ctx.fill(); |
| 344 | draw(tests[testIndex], testTitles[testIndex]); |
| 345 | } |
| 346 | |
| 347 | function doKeyPress(evt) { |
| 348 | var char = String.fromCharCode(evt.charCode); |
| 349 | switch (char) { |
| 350 | case '0': |
| 351 | case '1': |
| 352 | case '2': |
| 353 | case '3': |
| 354 | case '4': |
| 355 | case '5': |
| 356 | case '6': |
| 357 | case '7': |
| 358 | case '8': |
| 359 | case '9': |
| 360 | if (digit_mode) { |
| 361 | decimal_places = char - '0'; |
| 362 | } else if (index_mode) { |
| 363 | index_bits ^= 1 << (char - '0'); |
| 364 | } |
| 365 | redraw(); |
| 366 | break; |
| 367 | case 'd': |
| 368 | digit_mode = true; |
| 369 | index_mode = false; |
| 370 | break; |
| 371 | case 'f': |
| 372 | info_mode ^= true; |
| 373 | redraw(); |
| 374 | break; |
| 375 | case 'i': |
| 376 | digit_mode = false; |
| 377 | if (sequence >= 0) { |
| 378 | sequence = -1; |
| 379 | index_mode = false; |
| 380 | } else { |
| 381 | index_mode ^= true; |
| 382 | } |
| 383 | if (index_mode) { |
| 384 | index_bits = 0; |
| 385 | } else { |
| 386 | index_bits = -1; |
| 387 | } |
| 388 | redraw(); |
| 389 | break; |
| 390 | case 'N': |
| 391 | testIndex += 9; |
| 392 | case 'n': |
| 393 | if (++testIndex >= tests.length) |
| 394 | testIndex = 0; |
| 395 | drawTop(); |
| 396 | break; |
| 397 | case 'P': |
| 398 | testIndex -= 9; |
| 399 | case 'p': |
| 400 | if (--testIndex < 0) |
| 401 | testIndex = tests.length - 1; |
| 402 | drawTop(); |
| 403 | break; |
| 404 | case 's': |
| 405 | sequence++; |
| 406 | drawTop(); |
| 407 | break; |
| 408 | case 't': |
| 409 | intersect_mode ^= true; |
| 410 | redraw(); |
| 411 | break; |
| 412 | case 'x': |
| 413 | ptLabels ^= true; |
| 414 | redraw(); |
| 415 | break; |
| 416 | case 'y': |
| 417 | debug_xy ^= true; |
| 418 | redraw(); |
| 419 | break; |
| 420 | case '-': |
| 421 | scale /= 2; |
| 422 | calcLeftTop(); |
| 423 | redraw(); |
| 424 | break; |
| 425 | case '=': |
| 426 | case '+': |
| 427 | scale *= 2; |
| 428 | calcLeftTop(); |
| 429 | redraw(); |
| 430 | break; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | function calcXY() { |
| 435 | var e = window.event; |
| 436 | var tgt = e.target || e.srcElement; |
| 437 | var left = tgt.offsetLeft; |
| 438 | var top = tgt.offsetTop; |
| 439 | var unit = scale; |
| 440 | mouseX = (e.clientX - left) / scale + srcLeft; |
| 441 | mouseY = (e.clientY - top) / scale + srcTop; |
| 442 | } |
| 443 | |
| 444 | function calcLeftTop() { |
| 445 | srcLeft = mouseX - screenWidth / 2 / scale; |
| 446 | srcTop = mouseY - screenHeight / 2 / scale; |
| 447 | } |
| 448 | |
| 449 | function handleMouseClick() { |
| 450 | calcXY(); |
| 451 | calcLeftTop(); |
| 452 | redraw(); |
| 453 | } |
| 454 | |
| 455 | function handleMouseOver() { |
| 456 | calcXY(); |
| 457 | var num = mouseX.toFixed(decimal_places) + ", " + mouseY.toFixed(decimal_places); |
| 458 | ctx.beginPath(); |
| 459 | ctx.rect(300,100,200,10); |
| 460 | ctx.fillStyle="white"; |
| 461 | ctx.fill(); |
| 462 | ctx.fillStyle="black"; |
| 463 | ctx.fillText(num, 300, 108); |
| 464 | } |
| 465 | |
| 466 | function start() { |
| 467 | for (i = 0; i < testDivs.length; ++i) { |
| 468 | var title = testDivs[i].id.toString(); |
| 469 | var str = testDivs[i].firstChild.data; |
| 470 | parse_debugShowActiveSpans(str, title); |
| 471 | } |
| 472 | drawTop(); |
| 473 | window.addEventListener('keypress', doKeyPress, true); |
| 474 | window.onresize = function() { |
| 475 | drawTop(); |
| 476 | } |
| 477 | } |
| 478 | |
| 479 | </script> |
| 480 | </head> |
| 481 | |
| 482 | <body onLoad="start();"> |
| 483 | <canvas id="canvas" width="750" height="500" |
| 484 | onmousemove="handleMouseOver()" |
| 485 | onclick="handleMouseClick()" |
| 486 | ></canvas > |
| 487 | </body> |
| 488 | </html> |