blob: 93845cbbc7ef89e96201f5c6f56b3e9380d0bb93 [file] [log] [blame]
caryclark@google.comf839c032012-10-26 21:03:50 +00001<html>
2<head>
3<div style="height:0">
4
caryclark@google.comc83c70e2013-02-22 21:50:07 +00005<div id="cubicOp25i">
6debugShowActiveSpans 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
7debugShowActiveSpans 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.com47d73da2013-02-17 01:41:25 +000010<div id="cubicOp19i">
11debugShowActiveSpans 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
12debugShowActiveSpans 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
13debugShowActiveSpans 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
14debugShowActiveSpans id=4 (1,0 1,2) t=0 (1,0) tEnd=0.637627564 other=3 otherT=1 otherIndex=4 windSum=? windValue=1 oppValue=0
15debugShowActiveSpans 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
16debugShowActiveSpans 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
17debugShowActiveSpans 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
18debugShowActiveSpans 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
19debugShowActiveSpans id=2 (6,2 0,2) t=0 (6,2) tEnd=0.711411698 other=1 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0
20debugShowActiveSpans 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
21debugShowActiveSpans 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.com0b7da432012-10-31 19:00:20 +000022</div>
23
caryclark@google.comc83c70e2013-02-22 21:50:07 +000024<div id="cubicOp28u">
25debugShowActiveSpans 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
26debugShowActiveSpans 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
27debugShowActiveSpans 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
28debugShowActiveSpans id=4 (4,1 0,6) t=0 (4,1) tEnd=0.13678207 other=3 otherT=1 otherIndex=3 windSum=? windValue=1 oppValue=0
29debugShowActiveSpans 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
30debugShowActiveSpans 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
31debugShowActiveSpans 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
32debugShowActiveSpans 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
33debugShowActiveSpans 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
34debugShowActiveSpans 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
35debugShowActiveSpans 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
36debugShowActiveSpans 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
37debugShowActiveSpans 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
38debugShowActiveSpans id=2 (3,2 0,1) t=0 (3,2) tEnd=0.0604518624 other=1 otherT=1 otherIndex=7 windSum=? windValue=1 oppValue=0
39debugShowActiveSpans 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
40debugShowActiveSpans 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.com7ff5c842013-02-26 15:56:05 +000043<div id="cubicOp31d">
44debugShowActiveSpans 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
45debugShowActiveSpans 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
46debugShowActiveSpans 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
47debugShowActiveSpans 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
48debugShowActiveSpans 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
49debugShowActiveSpans 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
50debugShowActiveSpans 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
51debugShowActiveSpans 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">
55debugShowActiveSpans 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
56debugShowActiveSpans 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
57debugShowActiveSpans 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
58debugShowActiveSpans 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
59debugShowActiveSpans 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
60debugShowActiveSpans 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.comf839c032012-10-26 21:03:50 +000063</div>
64
65<script type="text/javascript">
66
67var testDivs = [
caryclark@google.com7ff5c842013-02-26 15:56:05 +000068 cubicOp31da,
69 cubicOp31d,
caryclark@google.comc83c70e2013-02-22 21:50:07 +000070 cubicOp28u,
71 cubicOp25i,
caryclark@google.com47d73da2013-02-17 01:41:25 +000072 cubicOp19i,
caryclark@google.comf839c032012-10-26 21:03:50 +000073];
74
75var decimal_places = 3; // make this 3 to show more precision
76
77var tests = [];
78var testTitles = [];
79var testIndex = 0;
80var ctx;
81
82var xmin;
83var ymin;
84var scale;
85var mouseX, mouseY;
86var srcLeft, srcTop;
87var srcWidth, srcHeight;
88var screenWidth, screenHeight;
caryclark@google.com47d73da2013-02-17 01:41:25 +000089var drawnPts, drawnLines, drawnQuads, drawnCubics, deferredLines, deferredQuads, deferredCubics;
caryclark@google.comf839c032012-10-26 21:03:50 +000090
91var ptLabels = true;
92var digit_mode = false;
93var index_mode = true;
94var index_bits = -1;
95var debug_xy = false;
96var info_mode = false;
97var intersect_mode = false;
98var sequence = -1;
99
100var SPAN_ID = 1;
101var SPAN_X1 = 2;
102var SPAN_Y1 = 3;
103var SPAN_X2 = 4;
104var SPAN_Y2 = 5;
105var SPAN_L_T = 6;
106var SPAN_L_TX = 7;
107var SPAN_L_TY = 8;
caryclark@google.com47d73da2013-02-17 01:41:25 +0000108var SPAN_L_TEND = 9;
109var SPAN_L_OTHER = 10;
110var SPAN_L_OTHERT = 11;
111var SPAN_L_OTHERI = 12;
112var SPAN_L_SUM = 13;
113var SPAN_L_VAL = 14;
114var SPAN_L_OPP = 15;
caryclark@google.comf839c032012-10-26 21:03:50 +0000115
116var SPAN_X3 = 6;
117var SPAN_Y3 = 7;
118var SPAN_Q_T = 8;
119var SPAN_Q_TX = 9;
120var SPAN_Q_TY = 10;
caryclark@google.com47d73da2013-02-17 01:41:25 +0000121var SPAN_Q_TEND = 11;
122var SPAN_Q_OTHER = 12;
123var SPAN_Q_OTHERT = 13;
124var SPAN_Q_OTHERI = 14;
125var SPAN_Q_SUM = 15;
126var SPAN_Q_VAL = 16;
127var SPAN_Q_OPP = 17;
128
129var SPAN_X4 = 8;
130var SPAN_Y4 = 9;
131var SPAN_C_T = 10;
132var SPAN_C_TX = 11;
133var SPAN_C_TY = 12;
134var SPAN_C_TEND = 13;
135var SPAN_C_OTHER = 14;
136var SPAN_C_OTHERT = 15;
137var SPAN_C_OTHERI = 16;
138var SPAN_C_SUM = 17;
139var SPAN_C_VAL = 18;
140var SPAN_C_OPP = 19;
caryclark@google.comf839c032012-10-26 21:03:50 +0000141
caryclark@google.com0b7da432012-10-31 19:00:20 +0000142var ACTIVE_LINE_SPAN = 1;
143var ACTIVE_QUAD_SPAN = 2;
caryclark@google.com47d73da2013-02-17 01:41:25 +0000144var ACTIVE_CUBIC_SPAN = 3;
145var INTERSECT_QUAD_LINE = 4;
146var INTERSECT_QUAD_LINE_2 = 5;
147var INTERSECT_QUAD_LINE_NO = 6;
148var INTERSECT_QUAD = 7;
149var INTERSECT_QUAD_2 = 8;
150var INTERSECT_QUAD_NO = 9;
caryclark@google.comf839c032012-10-26 21:03:50 +0000151
152function 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.com0b7da432012-10-31 19:00:20 +0000166function 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.comf839c032012-10-26 21:03:50 +0000175function parse_debugShowActiveSpans(test, title) {
caryclark@google.com47d73da2013-02-17 01:41:25 +0000176 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.comf839c032012-10-26 21:03:50 +0000179
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.com0b7da432012-10-31 19:00:20 +0000192 spans.push(ACTIVE_LINE_SPAN);
caryclark@google.comf839c032012-10-26 21:03:50 +0000193 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.com0b7da432012-10-31 19:00:20 +0000197 spans.push(ACTIVE_QUAD_SPAN);
caryclark@google.comf839c032012-10-26 21:03:50 +0000198 spans.push(quad);
caryclark@google.com47d73da2013-02-17 01:41:25 +0000199 } 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.comf839c032012-10-26 21:03:50 +0000204 }
205 }
206 if (spans.length >= 1) {
207 tests.push(spans);
208 testTitles.push(title);
209 }
210}
211
caryclark@google.com0b7da432012-10-31 19:00:20 +0000212function 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.com47d73da2013-02-17 01:41:25 +0000221// FIXME: add cubic support
caryclark@google.com0b7da432012-10-31 19:00:20 +0000222function 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.comf839c032012-10-26 21:03:50 +0000252function 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.com0b7da432012-10-31 19:00:20 +0000262 var scanType = -1;
263 for (var scansStr in test) {
264 var scans = parseInt(scansStr);
caryclark@google.comf839c032012-10-26 21:03:50 +0000265 var scan = test[scans];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000266 if (scanType == -1) {
267 scanType = scan;
268 continue;
caryclark@google.comf839c032012-10-26 21:03:50 +0000269 }
caryclark@google.com47d73da2013-02-17 01:41:25 +0000270 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.com0b7da432012-10-31 19:00:20 +0000274 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.comf839c032012-10-26 21:03:50 +0000313 }
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
324function 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.com0b7da432012-10-31 19:00:20 +0000344function 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.com47d73da2013-02-17 01:41:25 +0000372function 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.com0b7da432012-10-31 19:00:20 +0000387function 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.com47d73da2013-02-17 01:41:25 +0000424function interp(A, B, t) {
425 return A + (B - A) * t;
426}
427
428function 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
436function 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
455function 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
501function 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
512function 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
543function 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.com0b7da432012-10-31 19:00:20 +0000594function drawDeferred() {
caryclark@google.com47d73da2013-02-17 01:41:25 +0000595 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.com0b7da432012-10-31 19:00:20 +0000601 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.comf839c032012-10-26 21:03:50 +0000612function 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.com0b7da432012-10-31 19:00:20 +0000618 var curId = -1;
caryclark@google.comf839c032012-10-26 21:03:50 +0000619 var firstIdx;
620 var lastIdx;
621 var index_tst = -1;
622 drawnPts = [];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000623 drawnLines = [];
624 drawnQuads = [];
caryclark@google.com47d73da2013-02-17 01:41:25 +0000625 drawnCubics = [];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000626 deferredLines = [];
627 deferredQuads = [];
caryclark@google.com47d73da2013-02-17 01:41:25 +0000628 deferredCubics = [];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000629 var scanType = -1;
630 var partIndex = 0;
caryclark@google.comf839c032012-10-26 21:03:50 +0000631 for (var scansStr in test) {
632 var scans = parseInt(scansStr);
633 var scan = test[scans];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000634 if (scanType == -1) {
635 scanType = scan;
caryclark@google.comf839c032012-10-26 21:03:50 +0000636 continue;
637 }
caryclark@google.com0b7da432012-10-31 19:00:20 +0000638 partIndex++;
caryclark@google.com47d73da2013-02-17 01:41:25 +0000639 var hasId = scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN
640 || scanType == ACTIVE_CUBIC_SPAN ? SPAN_ID : -1;
caryclark@google.com0b7da432012-10-31 19:00:20 +0000641 if (hasId >= 0 && curId != scan[hasId]) {
caryclark@google.com47d73da2013-02-17 01:41:25 +0000642 curId = scan[hasId];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000643 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.comf839c032012-10-26 21:03:50 +0000652 }
caryclark@google.com0b7da432012-10-31 19:00:20 +0000653 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.com47d73da2013-02-17 01:41:25 +0000662 var types = [scanType == ACTIVE_LINE_SPAN ? 0 : scanType == ACTIVE_QUAD_SPAN ? 1 : 2];
caryclark@google.com0b7da432012-10-31 19:00:20 +0000663 var pts = [];
caryclark@google.com47d73da2013-02-17 01:41:25 +0000664 if (scanType == ACTIVE_LINE_SPAN || scanType == ACTIVE_QUAD_SPAN || scanType == ACTIVE_CUBIC_SPAN) {
caryclark@google.com0b7da432012-10-31 19:00:20 +0000665 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.com47d73da2013-02-17 01:41:25 +0000676 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.com0b7da432012-10-31 19:00:20 +0000681 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.comf839c032012-10-26 21:03:50 +0000688 if (debug_xy && selected) {
689 var debugText = "";
caryclark@google.com0b7da432012-10-31 19:00:20 +0000690 for (var typeIndex = 0; typeIndex < types.length; ++typeIndex) {
691 var type = types[typeIndex];
692 var index = pts[typeIndex];
caryclark@google.com47d73da2013-02-17 01:41:25 +0000693 for (var idx = pts[typeIndex]; idx < pts[typeIndex] + (type + 1) * 2; idx += 2) {
caryclark@google.com0b7da432012-10-31 19:00:20 +0000694 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.comf839c032012-10-26 21:03:50 +0000699 }
700 ctx.fillStyle="blue";
caryclark@google.com0b7da432012-10-31 19:00:20 +0000701 ctx.fillText(debugText, 50, partIndex * 50 + 100);
caryclark@google.comf839c032012-10-26 21:03:50 +0000702 }
703 if (ptLabels && selected) {
704 ctx.fillStyle="blue";
caryclark@google.com0b7da432012-10-31 19:00:20 +0000705 for (var typeIndex = 0; typeIndex < types.length; ++typeIndex) {
706 var type = types[typeIndex];
707 var index = pts[typeIndex];
caryclark@google.com47d73da2013-02-17 01:41:25 +0000708 for (var idx = pts[typeIndex]; idx < pts[typeIndex] + (type + 1) * 2; idx += 2) {
caryclark@google.com0b7da432012-10-31 19:00:20 +0000709 drawPoint(scan[idx], scan[idx + 1]);
710 }
caryclark@google.comf839c032012-10-26 21:03:50 +0000711 }
712 }
caryclark@google.com0b7da432012-10-31 19:00:20 +0000713 var infoText = "";
caryclark@google.comf839c032012-10-26 21:03:50 +0000714 if (info_mode && selected) {
caryclark@google.com0b7da432012-10-31 19:00:20 +0000715 infoText += hasId >= 0 ? "id=" + scan[hasId] : partIndex;
716 }
717 if (intersect_mode && selected) {
caryclark@google.com47d73da2013-02-17 01:41:25 +0000718 if (scanType == ACTIVE_CUBIC_SPAN) {
719 infoText += " t=" + scan[SPAN_C_T];
720 } else if (scanType == ACTIVE_QUAD_SPAN) {
caryclark@google.com0b7da432012-10-31 19:00:20 +0000721 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.comf839c032012-10-26 21:03:50 +0000736 ctx.fillStyle="green";
caryclark@google.com0b7da432012-10-31 19:00:20 +0000737 ctx.fillText(infoText, 10, (hasId >= 0 && sequence >= 0
738 ? hasId : partIndex) * 30 + 50);
caryclark@google.comf839c032012-10-26 21:03:50 +0000739 }
740 if (intersect_mode && selected) {
741 ctx.fillStyle="rgba(50,100,200, 1.0)";
caryclark@google.com47d73da2013-02-17 01:41:25 +0000742 if (scanType == ACTIVE_CUBIC_SPAN) {
743 drawPoint(scan[SPAN_C_TX], scan[SPAN_C_TY]);
744 } else if (scanType == ACTIVE_QUAD_SPAN) {
caryclark@google.comf839c032012-10-26 21:03:50 +0000745 drawPoint(scan[SPAN_Q_TX], scan[SPAN_Q_TY]);
caryclark@google.com0b7da432012-10-31 19:00:20 +0000746 } else if (scanType == ACTIVE_LINE_SPAN) {
caryclark@google.comf839c032012-10-26 21:03:50 +0000747 drawPoint(scan[SPAN_L_TX], scan[SPAN_L_TY]);
caryclark@google.com0b7da432012-10-31 19:00:20 +0000748 } 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.comf839c032012-10-26 21:03:50 +0000753 }
754 }
caryclark@google.com0b7da432012-10-31 19:00:20 +0000755 ctx.strokeStyle = "rgba(0,0,0, 0.2)";
756 scanType = -1;
caryclark@google.comf839c032012-10-26 21:03:50 +0000757 }
caryclark@google.com0b7da432012-10-31 19:00:20 +0000758 drawDeferred();
caryclark@google.com47d73da2013-02-17 01:41:25 +0000759 drawPartial(test);
caryclark@google.comf839c032012-10-26 21:03:50 +0000760}
761
762function drawTop() {
763 init(tests[testIndex]);
764 redraw();
765}
766
767function 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
775function 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.com0b7da432012-10-31 19:00:20 +0000834 redraw();
835 break;
836 case 'S':
837 sequence--;
838 if (sequence < 0) {
839 sequence = 0;
840 }
841 redraw();
caryclark@google.comf839c032012-10-26 21:03:50 +0000842 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
869function 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
879function calcLeftTop() {
880 srcLeft = mouseX - screenWidth / 2 / scale;
881 srcTop = mouseY - screenHeight / 2 / scale;
882}
883
884function handleMouseClick() {
885 calcXY();
886 calcLeftTop();
887 redraw();
888}
889
890function 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
901function 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.com0b7da432012-10-31 19:00:20 +0000906 parse_intersections(str, title);
caryclark@google.comf839c032012-10-26 21:03:50 +0000907 }
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>