blob: d2892b17409b19e127c6bb8c977052d7fa1aaf35 [file] [log] [blame]
caryclark@google.com752b60e2012-03-22 21:11:17 +00001<html>
2<head>
3<div style="height:0">
caryclark@google.comfa0588f2012-04-26 21:01:06 +00004
5<div id="testSimplifyQuadratic1">
6 SkPath path, out;
7 path.moveTo(0, 0);
8 path.quadTo(1, 0, 1, 1);
9 path.close();
10 path.moveTo(1, 0);
11 path.quadTo(0, 0, 0, 1);
12 path.close();
13 testSimplify(path, true, out, bitmap);
14}
caryclark@google.com752b60e2012-03-22 21:11:17 +000015</div>
caryclark@google.comfa0588f2012-04-26 21:01:06 +000016
17<div id="testSimplifyQuadratic2">
18 SkPath path, out;
19 path.moveTo(0, 0);
20 path.quadTo(20, 0, 20, 20);
21 path.close();
22 path.moveTo(20, 0);
23 path.quadTo(0, 0, 0, 20);
24 path.close();
25 testSimplify(path, true, out, bitmap);
26}
caryclark@google.comd88e0892012-03-27 13:23:51 +000027</div>
caryclark@google.comfa0588f2012-04-26 21:01:06 +000028
29<div id="testSimplifyQuadratic3">
30 SkPath path, out;
31 path.moveTo(0, 0);
32 path.quadTo(20, 0, 20, 20);
33 path.close();
34 path.moveTo(0, 20);
35 path.quadTo(0, 0, 20, 0);
36 path.close();
37 testSimplify(path, true, out, bitmap);
38}
caryclark@google.comd88e0892012-03-27 13:23:51 +000039</div>
caryclark@google.comfa0588f2012-04-26 21:01:06 +000040
41<div id="testSimplifyQuadratic4">
42 SkPath path, out;
43 path.moveTo(0, 20);
44 path.quadTo(20, 0, 40, 20);
45 path.close();
46 path.moveTo(40, 10);
47 path.quadTo(20, 30, 0, 10);
48 path.close();
49 testSimplify(path, true, out, bitmap);
50 drawAsciiPaths(path, out, true);
51}
caryclark@google.comd88e0892012-03-27 13:23:51 +000052</div>
caryclark@google.comfa0588f2012-04-26 21:01:06 +000053
54<div id="testSimplifyQuadratic5">
55 SkPath path, out;
56 path.moveTo(0, 0);
57 path.quadTo(0, 0, 0, 0);
58 path.lineTo(0, 0);
59 path.close();
60 path.moveTo(0, 0);
61 path.lineTo(0, 0);
62 path.quadTo(0, 0, 0, 1);
63 path.close();
64 testSimplify(path, true, out, bitmap);
65 drawAsciiPaths(path, out, true);
66}
caryclark@google.comfb173422012-04-10 18:28:55 +000067</div>
caryclark@google.comfa0588f2012-04-26 21:01:06 +000068
69<div id="testSimplifyQuadratic6">
70 SkPath path, out;
71 path.moveTo(0, 0);
72 path.quadTo(0, 0, 0, 0);
73 path.lineTo(1, 0);
74 path.close();
75 path.moveTo(0, 0);
76 path.lineTo(0, 0);
77 path.quadTo(1, 0, 0, 1);
78 path.close();
79 testSimplify(path, true, out, bitmap);
80 drawAsciiPaths(path, out, true);
81}
caryclark@google.comfb173422012-04-10 18:28:55 +000082</div>
caryclark@google.comfa0588f2012-04-26 21:01:06 +000083
84<div id="testSimplifyQuadratic7">
85 SkPath path, out;
86 path.moveTo(0, 0);
87 path.quadTo(0, 0, 0, 0);
88 path.lineTo(0, 1);
89 path.close();
90 path.moveTo(0, 0);
91 path.lineTo(0, 0);
92 path.quadTo(1, 0, 0, 2);
93 path.close();
94 testSimplify(path, true, out, bitmap);
95 drawAsciiPaths(path, out, true);
96}
97</div>
98
99<div id="testSimplifyQuadratic8">
100 SkPath path, out;
101 path.moveTo(0, 0);
102 path.quadTo(0, 0, 0, 0);
103 path.lineTo(0, 0);
104 path.close();
105 path.moveTo(0, 0);
106 path.lineTo(0, 0);
107 path.quadTo(1, 0, 0, 2);
108 path.close();
109 testSimplify(path, true, out, bitmap);
110 drawAsciiPaths(path, out, true);
111}
112</div>
113
114<div id="testSimplifyQuadratic9">
115 SkPath path, out;
116 path.moveTo(0, 0);
117 path.quadTo(0, 0, 0, 0);
118 path.lineTo(1, 1);
119 path.close();
120 path.moveTo(0, 0);
121 path.lineTo(0, 0);
122 path.quadTo(1, 0, 2, 2);
123 path.close();
124 testSimplify(path, true, out, bitmap);
125 drawAsciiPaths(path, out, true);
126}
127</div>
128
129<div id="testSimplifyQuadratic10">
130 SkPath path, out;
caryclark@google.com78e17132012-04-17 11:40:34 +0000131 path.moveTo(0, 0);
132 path.quadTo(0, 0, 0, 0);
133 path.lineTo(0, 0);
134 path.close();
135 path.moveTo(0, 0);
136 path.lineTo(0, 1);
137 path.quadTo(1, 1, 1, 2);
caryclark@google.com78e17132012-04-17 11:40:34 +0000138 path.close();
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000139 testSimplify(path, true, out, bitmap);
140 drawAsciiPaths(path, out, true);
141}
caryclark@google.com78e17132012-04-17 11:40:34 +0000142</div>
143
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000144<div id="testSimplifyQuadratic11">
145 SkPath path, out;
caryclark@google.com78e17132012-04-17 11:40:34 +0000146 path.moveTo(0, 0);
147 path.quadTo(0, 0, 0, 0);
148 path.lineTo(0, 2);
caryclark@google.com78e17132012-04-17 11:40:34 +0000149 path.close();
150 path.moveTo(0, 0);
151 path.lineTo(2, 1);
152 path.quadTo(2, 2, 3, 3);
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000153 path.close();
154 testSimplify(path, true, out, bitmap);
155 drawAsciiPaths(path, out, true);
156}
157</div>
158
159<div id="testSimplifyQuadratic12">
160 SkPath path, out;
161 path.moveTo(0, 0);
162 path.lineTo(0, 2);
caryclark@google.com78e17132012-04-17 11:40:34 +0000163 path.lineTo(0, 0);
164 path.close();
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000165 path.moveTo(3, 0);
166 path.quadTo(1, 1, 0, 2);
167 path.lineTo(3, 0);
168 path.close();
169 testSimplify(path, true, out, bitmap);
170 drawAsciiPaths(path, out, true);
171}
caryclark@google.com78e17132012-04-17 11:40:34 +0000172</div>
173
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000174<div id="testSimplifyQuadratic13">
175 SkPath path, out;
caryclark@google.com78e17132012-04-17 11:40:34 +0000176path.moveTo(0, 0);
177path.quadTo(0, 0, 1, 0);
178path.lineTo(1, 1);
179path.lineTo(0, 0);
180path.close();
181path.moveTo(0, 0);
182path.quadTo(3, 0, 1, 1);
183path.lineTo(0, 0);
184path.close();
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000185 testSimplify(path, true, out, bitmap);
186 drawAsciiPaths(path, out, true);
187}
caryclark@google.com78e17132012-04-17 11:40:34 +0000188</div>
189
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000190<div id="testSimplifyQuadratic14">
191 SkPath path, out;
caryclark@google.com78e17132012-04-17 11:40:34 +0000192 path.moveTo(0, 0);
193 path.quadTo(0, 0, 0, 0);
194 path.lineTo(1, 1);
caryclark@google.com78e17132012-04-17 11:40:34 +0000195 path.close();
196 path.moveTo(0, 0);
197 path.lineTo(0, 0);
198 path.quadTo(0, 1, 2, 1);
caryclark@google.com78e17132012-04-17 11:40:34 +0000199 path.close();
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000200 testSimplify(path, true, out, bitmap);
201 drawAsciiPaths(path, out, true);
202}
caryclark@google.com78e17132012-04-17 11:40:34 +0000203</div>
204
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000205<div id="testSimplifyQuadratic15">
206 SkPath path, out;
207 path.moveTo(0, 0);
208 path.quadTo(0, 0, 1, 3);
209 path.lineTo(3, 3);
210 path.close();
211 path.moveTo(0, 1);
212 path.lineTo(1, 1);
213 path.quadTo(0, 3, 3, 3);
214 path.close();
215 testSimplify(path, true, out, bitmap);
216 drawAsciiPaths(path, out, true);
217}
218</div>
219
220<div id="testSimplifyQuadratic16">
221 SkPath path, out;
222 path.moveTo(0, 0);
223 path.quadTo(0, 0, 0, 0);
224 path.lineTo(0, 1);
225 path.close();
226 path.moveTo(0, 0);
227 path.lineTo(0, 0);
228 path.quadTo(1, 0, 0, 1);
229 path.close();
230 testSimplify(path, true, out, bitmap);
231 drawAsciiPaths(path, out, true);
232}
233</div>
234
235<div id="testSimplifyQuadratic17">
236 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000237 path.moveTo(8, 8);
238 path.quadTo(10, 10, 8, -10);
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000239 path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000240 path.moveTo(8, 8);
241 path.quadTo(12, 12, 14, 4);
242 path.close();
243 path.moveTo(8, 8);
244 path.quadTo(9, 9, 10, 8);
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000245 path.close();
246 testSimplify(path, true, out, bitmap);
247 drawAsciiPaths(path, out, true);
248}
caryclark@google.com78e17132012-04-17 11:40:34 +0000249</div>
caryclark@google.comfb173422012-04-10 18:28:55 +0000250
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000251<div id="testSimplifyQuadratic18">
252 SkPath path, out;
253 path.moveTo(8.0000000000000071, 8.0000000000000071);
254 path.quadTo(8.7289570079366854, 8.7289570079366889, 9.3914917259458743, 9.0593802763083691);
255 path.close();
256 path.moveTo(8.0000000000000142, 8.0000000000000142);
257 path.quadTo(8.1250000000000107, 8.1250000000000071, 8.2500000000000071, 8.2187500000000053);
258 path.close();
259 testSimplify(path, true, out, bitmap);
260 drawAsciiPaths(path, out, true);
261</div>
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000262
263<div id="testSimplifyQuadratic19">
264 SkPath path, simple;
265 path.moveTo(0,4);
266 path.lineTo(6,4);
267 path.lineTo(3,1);
268 path.close();
269 path.moveTo(2,3);
270 path.lineTo(3,2);
271 path.lineTo(4,3);
272 path.close();
273 testSimplifyx(path);
274</div>
275
276<div id="testSimplifyQuadratic20">
277 SkPath path, simple;
278 path.moveTo(0,4);
279 path.lineTo(6,4);
280 path.lineTo(3,1);
281 path.close();
282 path.moveTo(2,3);
283 path.lineTo(4,3);
284 path.lineTo(3,2);
285 path.close();
286 testSimplifyx(path);
287</div>
288
289<div id="testSimplifyQuadratic21">
290 SkPath path, simple;
291 path.moveTo(0,4);
292 path.lineTo(8,4);
293 path.lineTo(4,0);
294 path.close();
295 path.moveTo(2,2);
296 path.lineTo(3,3);
297 path.lineTo(4,2);
298 path.close();
299 testSimplifyx(path);
300</div>
301
302<div id="testLine6">
303 SkPath path, simple;
304 path.moveTo(0,0);
305 path.lineTo(4,0);
306 path.lineTo(2,2);
307 path.close();
308 path.moveTo(2,0);
309 path.lineTo(6,0);
310 path.lineTo(4,2);
311 path.close();
312 testSimplifyx(path);
313</div>
314
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000315<div id="testLine7">
316 SkPath path, simple;
317 path.moveTo(0,0);
318 path.lineTo(4,0);
319 path.lineTo(2,2);
320 path.close();
321 path.moveTo(6,0);
322 path.lineTo(2,0);
323 path.lineTo(4,2);
324 path.close();
325 testSimplifyx(path);
326</div>
327
328<div id="testLine9">
329 SkPath path, simple;
330 path.moveTo(0,4);
331 path.lineTo(4,4);
332 path.lineTo(2,2);
333 path.close();
334 path.moveTo(6,4);
335 path.lineTo(2,4);
336 path.lineTo(4,2);
337 path.close();
338 testSimplifyx(path);
339</div>
340
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000341<div id="testLine17">
342 SkPath path, simple;
343 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
344 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
345 testSimplifyx(path);
346</div>
347
caryclark@google.com47580692012-07-23 12:14:49 +0000348<div id="testLine19">
349 SkPath path, simple;
350 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
351 path.addRect(12, 16, 21, 21, (SkPath::Direction) 0);
352 testSimplifyx(path);
353</div>
354
355<div id="testLine24">
356 path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
357 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
358</div>
359
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000360<div id="testLine28">
361 SkPath path, simple;
362 path.addRect(0, 6, 12, 12, (SkPath::Direction) 0);
363 path.addRect(0, 0, 9, 9, (SkPath::Direction) 0);
364 testSimplifyx(path);
365</div>
366
367<div id="testLine29">
368 SkPath path, simple;
369 path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
370 path.addRect(12, 12, 21, 21, (SkPath::Direction) 0);
371 testSimplifyx(path);
372</div>
373
374<div id="testLine30">
375 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
376 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
377 path.addRect(4, 4, 13, 13, (SkPath::Direction) 0);
378</div>
379
380<div id="testLine31">
381 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
382 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
383 path.addRect(0, 4, 9, 9, (SkPath::Direction) 0);
384</div>
385
386<div id="testLine32">
387 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
388 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
389 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
390</div>
391
caryclark@google.com9764cc62012-07-12 19:29:45 +0000392<div id="testLine33">
393 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
394 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
395 path.addRect(4, 16, 13, 13, (SkPath::Direction) 0);
396</div>
397
caryclark@google.com210acaf2012-07-12 21:05:13 +0000398<div id="testLine34">
399 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
400 path.addRect(0, 6, 12, 12, (SkPath::Direction) 0);
401 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
402</div>
403
404<div id="testLine35">
405 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
406 path.addRect(6, 0, 18, 18, (SkPath::Direction) 0);
407 path.addRect(4, 16, 13, 13, (SkPath::Direction) 0);
408</div>
409
caryclark@google.com0e08a192012-07-13 21:07:52 +0000410<div id="testLine36">
411 path.addRect(0, 10, 20, 20, (SkPath::Direction) 0);
412 path.addRect(6, 12, 18, 18, (SkPath::Direction) 0);
413 path.addRect(4, 16, 13, 13, (SkPath::Direction) 0);
414</div>
415
caryclark@google.com47580692012-07-23 12:14:49 +0000416<div id="testLine37">
417 path.addRect(0, 20, 20, 20, (SkPath::Direction) 0);
418 path.addRect(18, 24, 30, 30, (SkPath::Direction) 0);
419 path.addRect(0, 0, 9, 9, (SkPath::Direction) 0);
420</div>
421
422<div id="testLine38">
423 path.addRect(10, 0, 30, 30, (SkPath::Direction) 0);
424 path.addRect(6, 12, 18, 18, (SkPath::Direction) 0);
425 path.addRect(12, 12, 21, 21, (SkPath::Direction) 0);
426</div>
427
428<div id="testLine39">
429 path.addRect(10, 0, 30, 30, (SkPath::Direction) 0);
430 path.addRect(12, 6, 24, 24, (SkPath::Direction) 0);
431 path.addRect(12, 4, 21, 21, (SkPath::Direction) 0);
432</div>
433
434<div id="testLine40">
435 path.addRect(10, 0, 30, 30, (SkPath::Direction) 0);
436 path.addRect(12, 18, 24, 24, (SkPath::Direction) 0);
437 path.addRect(4, 16, 13, 13, (SkPath::Direction) 0);
438</div>
439
440<div id="testLine41">
441 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
442 path.addRect(18, 24, 30, 30, (SkPath::Direction) 0);
443 path.addRect(12, 0, 21, 21, (SkPath::Direction) 0);
444</div>
445
446<div id="testLine42">
447 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
448 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
449 path.addRect(8, 16, 17, 17, (SkPath::Direction) 0);
450</div>
451
452<div id="testLine43">
453 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
454 path.addRect(6, 24, 18, 18, (SkPath::Direction) 0);
455 path.addRect(0, 32, 9, 36, (SkPath::Direction) 1);
456</div>
457
458<div id="testLine44">
459 path.addRect(10, 40, 30, 30, (SkPath::Direction) 0);
460 path.addRect(18, 0, 30, 30, (SkPath::Direction) 0);
461 path.addRect(18, 32, 27, 36, (SkPath::Direction) 1);
462</div>
463
464<div id="testLine45">
465 path.addRect(10, 0, 30, 30, (SkPath::Direction) 0);
466 path.addRect(18, 0, 30, 30, (SkPath::Direction) 0);
467 path.addRect(24, 32, 33, 36, (SkPath::Direction) 0);
468</div>
469
470<div id="testLine46">
471 path.addRect(10, 40, 30, 30, (SkPath::Direction) 0);
472 path.addRect(24, 0, 36, 36, (SkPath::Direction) 0);
473 path.addRect(24, 32, 33, 36, (SkPath::Direction) 0);
474</div>
475
476<div id="testLine47">
477 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
478 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
479 path.addRect(0, 0, 9, 9, (SkPath::Direction) 1);
480</div>
481
482<div id="testLine48">
483 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
484 path.addRect(0, 6, 12, 12, (SkPath::Direction) 0);
485 path.addRect(0, 0, 9, 9, (SkPath::Direction) 1);
486</div>
487
488<div id="testLine49">
489 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
490 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
491 path.addRect(0, 0, 9, 9, (SkPath::Direction) 0);
492</div>
493
494<div id="testLine50">
495 path.addRect(10, 30, 30, 30, (SkPath::Direction) 0);
496 path.addRect(24, 20, 36, 30, (SkPath::Direction) 0);
497</div>
498
499<div id="testLine51">
500 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
501 path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
502 path.addRect(4, 12, 13, 13, (SkPath::Direction) 1);
503</div>
504
caryclark@google.com752b60e2012-03-22 21:11:17 +0000505</div>
506
507<script type="text/javascript">
508
509var testDivs = [
caryclark@google.com47580692012-07-23 12:14:49 +0000510 testLine51,
511 testLine50,
512 testLine49,
513 testLine48,
514 testLine47,
515 testLine46,
516 testLine45,
517 testLine44,
518 testLine43,
519 testLine42,
520 testLine41,
521 testLine40,
522 testLine39,
523 testLine38,
524 testLine37,
caryclark@google.com0e08a192012-07-13 21:07:52 +0000525 testLine36,
caryclark@google.com210acaf2012-07-12 21:05:13 +0000526 testLine35,
527 testLine34,
caryclark@google.com9764cc62012-07-12 19:29:45 +0000528 testLine33,
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000529 testLine30,
530 testLine32,
531 testLine31,
532 testLine29,
533 testLine28,
caryclark@google.com47580692012-07-23 12:14:49 +0000534 testLine24,
535 testLine19,
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000536 testLine17,
caryclark@google.com47580692012-07-23 12:14:49 +0000537 testLine9,
538 testLine7,
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000539 testSimplifyQuadratic21,
540 testSimplifyQuadratic20,
541 testSimplifyQuadratic19,
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000542 testSimplifyQuadratic18,
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000543 testSimplifyQuadratic17,
544 testSimplifyQuadratic16,
545 testSimplifyQuadratic15,
546 testSimplifyQuadratic14,
547 testSimplifyQuadratic13,
548 testSimplifyQuadratic12,
549 testSimplifyQuadratic11,
550 testSimplifyQuadratic10,
551 testSimplifyQuadratic9,
552 testSimplifyQuadratic8,
553 testSimplifyQuadratic7,
554 testSimplifyQuadratic6,
555 testSimplifyQuadratic5,
556 testSimplifyQuadratic4,
557 testSimplifyQuadratic3,
558 testSimplifyQuadratic2,
559 testSimplifyQuadratic1,
caryclark@google.com752b60e2012-03-22 21:11:17 +0000560];
561
562var scale, columns, rows, xStart, yStart;
563
564var ticks = 0.1;
565var at_x = 13 + 0.5;
566var at_y = 13 + 0.5;
567
568var tests = [];
caryclark@google.com0e08a192012-07-13 21:07:52 +0000569var testTitles = [];
caryclark@google.com752b60e2012-03-22 21:11:17 +0000570var testIndex = 0;
571
572var ctx;
573
caryclark@google.com0e08a192012-07-13 21:07:52 +0000574function parse(test, title) {
caryclark@google.com752b60e2012-03-22 21:11:17 +0000575 var contours = [];
576 var contourStrs = test.split("path.close();");
caryclark@google.comd88e0892012-03-27 13:23:51 +0000577 var pattern = /-?\d+\.*\d*/g;
caryclark@google.com752b60e2012-03-22 21:11:17 +0000578 for (var c in contourStrs) {
caryclark@google.comfb173422012-04-10 18:28:55 +0000579 var contour = contourStrs[c];
580 var verbStrs = contour.split("path");
581 var verbs = [];
582 for (var v in verbStrs) {
583 var verbStr = verbStrs[v];
584 var points = verbStr.match(pattern);
585 var pts = [];
586 for (var wd in points) {
587 var num = parseFloat(points[wd]);
588 if (isNaN(num)) continue;
589 pts.push(num);
590 }
591 if (pts.length > 0)
592 verbs.push(pts);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000593 }
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000594 if (verbs.length > 0) {
595 var lastIndex = verbs.length - 1;
596 var lastVerb = verbs[lastIndex];
597 var lastLen = lastVerb.length;
598 if (verbs[0][0] != lastVerb[lastLen - 2] && verbs[0][1] != lastVerb[lastLen - 1]) {
599 var lastPts = [];
600 lastPts.push(verbs[0][0]);
601 lastPts.push(verbs[0][1]);
602 verbs.push(lastPts);
603 }
caryclark@google.comfb173422012-04-10 18:28:55 +0000604 contours.push(verbs);
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000605 }
caryclark@google.com752b60e2012-03-22 21:11:17 +0000606 }
caryclark@google.com0e08a192012-07-13 21:07:52 +0000607 if (contours.length > 0) {
caryclark@google.comfb173422012-04-10 18:28:55 +0000608 tests.push(contours);
caryclark@google.com0e08a192012-07-13 21:07:52 +0000609 testTitles.push(title);
610 }
caryclark@google.com752b60e2012-03-22 21:11:17 +0000611}
612
caryclark@google.com0e08a192012-07-13 21:07:52 +0000613function parseRect(test, title) {
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000614 var contours = [];
615 var rectStrs = test.split("path.addRect");
616 var pattern = /-?\d+\.*\d*/g;
617 for (var r in rectStrs) {
618 var rect = rectStrs[r];
619 var sideStrs = rect.match(pattern);
620 var sides = [];
621 for (var wd in sideStrs) {
622 var num = parseFloat(sideStrs[wd]);
623 if (isNaN(num)) continue;
624 sides.push(num);
625 }
626 if (sides.length == 0)
627 continue;
628 var verbs = [];
629 var topLeft = [];
630 topLeft.push(sides[0]); topLeft.push(sides[1]);
631 var topRight = [];
632 topRight.push(sides[2]); topRight.push(sides[1]);
633 var botLeft = [];
634 botLeft.push(sides[0]); botLeft.push(sides[3]);
635 var botRight = [];
636 botRight.push(sides[2]); botRight.push(sides[3]);
637 verbs.push(topLeft);
638 if (sides[4] == 0) {
639 verbs.push(topRight);
640 verbs.push(botRight);
641 verbs.push(botLeft);
642 } else {
643 verbs.push(botLeft);
644 verbs.push(botRight);
645 verbs.push(topRight);
646 }
647 verbs.push(topLeft);
648 contours.push(verbs);
649 }
caryclark@google.com0e08a192012-07-13 21:07:52 +0000650 if (contours.length > 0) {
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000651 tests.push(contours);
caryclark@google.com0e08a192012-07-13 21:07:52 +0000652 testTitles.push(title);
653 }
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000654}
655
caryclark@google.com752b60e2012-03-22 21:11:17 +0000656function init(test) {
657 var canvas = document.getElementById('canvas');
658 if (!canvas.getContext) return;
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000659 canvas.width = document.width;
660 canvas.height = document.height;
caryclark@google.com752b60e2012-03-22 21:11:17 +0000661 ctx = canvas.getContext('2d');
662 var xmin = Infinity;
663 var xmax = -Infinity;
664 var ymin = Infinity;
665 var ymax = -Infinity;
caryclark@google.comfb173422012-04-10 18:28:55 +0000666 for (var contours in test) {
667 var contour = test[contours];
668 for (var verbs in contour) {
669 var verb = contour[verbs];
670 var last = verb.length;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000671 for (var idx = 0; idx < last; idx += 2) {
672 xmin = Math.min(xmin, verb[idx]);
673 xmax = Math.max(xmax, verb[idx]);
674 ymin = Math.min(ymin, verb[idx + 1]);
675 ymax = Math.max(ymax, verb[idx + 1]);
676 }
caryclark@google.com752b60e2012-03-22 21:11:17 +0000677 }
678 }
679 var subscale = 1;
680 while ((xmax - xmin) * subscale < 0.1 && (ymax - ymin) * subscale < 0.1) {
681 subscale *= 10;
682 }
683 columns = Math.ceil(xmax) - Math.floor(xmin) + 1;
684 rows = Math.ceil(ymax) - Math.floor(ymin) + 1;
685 xStart = Math.floor(xmin);
686 yStart = Math.floor(ymin);
687 var hscale = ctx.canvas.width / columns / ticks;
688 var vscale = ctx.canvas.height / rows / ticks;
689 scale = Math.floor(Math.min(hscale, vscale)) * subscale;
690}
691
692function drawPoint(px, py, xoffset, yoffset, unit) {
caryclark@google.comd88e0892012-03-27 13:23:51 +0000693 var label = px.toFixed(3) + ", " + py.toFixed(3);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000694 var _px = px * unit + xoffset;
695 var _py = py * unit + yoffset;
696 ctx.beginPath();
697 ctx.arc(_px, _py, 3, 0, Math.PI*2, true);
698 ctx.closePath();
699 ctx.fill();
700 ctx.fillText(label, _px + 5, _py);
701}
702
caryclark@google.com0e08a192012-07-13 21:07:52 +0000703function draw(test, title, _at_x, _at_y, scale) {
704 ctx.fillStyle = "rgba(0,0,0, 0.1)";
705 ctx.font = "normal 50px Arial";
706 ctx.fillText(title, 50, 50);
707 ctx.font = "normal 10px Arial";
708
caryclark@google.com752b60e2012-03-22 21:11:17 +0000709 var unit = scale * ticks;
710 ctx.lineWidth = 1;
711 var i;
712 for (i = 0; i <= rows * ticks; ++i) {
713 ctx.strokeStyle = (i % ticks) != 0 ? "rgb(160,160,160)" : "black";
714 ctx.beginPath();
715 ctx.moveTo(_at_x + 0, _at_y + i * scale);
716 ctx.lineTo(_at_x + unit * columns, _at_y + i * scale);
717 ctx.stroke();
718 }
719 for (i = 0; i <= columns * ticks; ++i) {
720 ctx.strokeStyle = (i % ticks) != 0 ? "rgb(160,160,160)" : "black";
721 ctx.beginPath();
722 ctx.moveTo(_at_x + i * scale, _at_y + 0);
723 ctx.lineTo(_at_x + i * scale, _at_y + unit * rows);
724 ctx.stroke();
725 }
726
727 var xoffset = xStart * -unit + _at_x;
728 var yoffset = yStart * -unit + _at_y;
729
730 ctx.fillStyle = "rgb(40,80,60)"
731 for (i = 0; i <= columns; i += (1 / ticks))
732 {
733 num = (xoffset - _at_x) / -unit + i;
734 ctx.fillText(num.toFixed(0), i * unit + _at_y - 5, 10);
735 }
736 for (i = 0; i <= rows; i += (1 / ticks))
737 {
738 num = (yoffset - _at_x) / -unit + i;
739 ctx.fillText(num.toFixed(0), 0, i * unit + _at_y + 0);
740 }
741 ctx.strokeStyle = "red";
caryclark@google.comfb173422012-04-10 18:28:55 +0000742 var contours, verbs, pts;
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000743 ctx.beginPath();
caryclark@google.comfb173422012-04-10 18:28:55 +0000744 for (contours in test) {
745 var contour = test[contours];
746 if (contours == 2) ctx.strokeStyle = "blue";
caryclark@google.comfb173422012-04-10 18:28:55 +0000747 var first = true;
748 for (verbs in contour) {
749 var verb = contour[verbs];
750 switch (verb.length) {
751 case 2:
752 if (first) {
753 ctx.moveTo(xoffset + verb[0] * unit, yoffset + verb[1] * unit);
754 first = false;
755 } else
756 ctx.lineTo(xoffset + verb[0] * unit, yoffset + verb[1] * unit);
757 break;
758 case 4:
759 ctx.quadraticCurveTo(xoffset + verb[0] * unit, yoffset + verb[1] * unit,
760 xoffset + verb[2] * unit, yoffset + verb[3] * unit);
761 break;
762 case 6:
763 ctx.bezierCurveTo(xoffset + verb[0] * unit, yoffset + verb[1] * unit,
764 xoffset + verb[2] * unit, yoffset + verb[3] * unit,
765 xoffset + verb[4] * unit, yoffset + verb[5] * unit);
766 break;
767 }
caryclark@google.com752b60e2012-03-22 21:11:17 +0000768 }
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000769 ctx.closePath();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000770 }
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000771 ctx.stroke();
772 ctx.fillStyle="rgba(192,192,255, 0.3)";
773 ctx.fill();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000774
775 ctx.fillStyle="blue";
caryclark@google.comfb173422012-04-10 18:28:55 +0000776 for (contours in test) {
777 var contour = test[contours];
778 for (verbs in contour) {
779 var verb = contour[verbs];
780 for (i = 0; i < verb.length; i += 2) {
781 x = verb[i];
782 y = verb[i + 1];
783 drawPoint(x, y, xoffset, yoffset, unit);
784 }
caryclark@google.com752b60e2012-03-22 21:11:17 +0000785 }
786 }
787}
788
789var mouseX = Infinity, mouseY;
790
791function calcXY() {
792 var e = window.event;
793 var tgt = e.target || e.srcElement;
794 var left = tgt.offsetLeft;
795 var top = tgt.offsetTop;
796 var unit = scale * ticks;
797 mouseX = (e.clientX - left - Math.ceil(at_x) + 1) / unit + xStart;
798 mouseY = (e.clientY - top - Math.ceil(at_y)) / unit + yStart;
799}
800
801function handleMouseOver() {
802 calcXY();
803 var num = mouseX.toFixed(3) + ", " + mouseY.toFixed(3);
804 ctx.beginPath();
805 ctx.rect(300,100,200,10);
806 ctx.fillStyle="white";
807 ctx.fill();
808 ctx.fillStyle="black";
809 ctx.fillText(num, 300, 108);
810}
811
812function handleMouseClick() {
813 calcXY();
814// drawInset();
815}
816
817function drawTop() {
818 init(tests[testIndex]);
819 redraw();
820}
821
822function redraw() {
823 ctx.beginPath();
824 ctx.rect(0, 0, ctx.canvas.width, ctx.canvas.height);
825 ctx.fillStyle="white";
826 ctx.fill();
caryclark@google.com0e08a192012-07-13 21:07:52 +0000827 draw(tests[testIndex], testTitles[testIndex], at_x, at_y, scale);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000828// if (insetScale != scale && mouseX != Infinity)
829// drawInset();
830}
831
832function doKeyPress(evt) {
833 var char = String.fromCharCode(evt.charCode);
834 switch (char) {
835 case 'N':
836 case 'n':
837 if (++testIndex >= tests.length)
838 testIndex = 0;
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000839 mouseX = Infinity;
840 drawTop();
841 break;
842 case 'P':
843 case 'p':
844 if (--testIndex < 0)
845 testIndex = tests.length - 1;
caryclark@google.com752b60e2012-03-22 21:11:17 +0000846 mouseX = Infinity;
847 drawTop();
848 break;
849 case 'T':
850 case 't':
caryclark@google.com752b60e2012-03-22 21:11:17 +0000851 break;
852 case '-':
caryclark@google.com752b60e2012-03-22 21:11:17 +0000853 redraw();
854 break;
855 case '=':
856 case '+':
caryclark@google.com752b60e2012-03-22 21:11:17 +0000857 redraw();
858 break;
859 }
860}
861
862function start() {
863 for (i = 0; i < testDivs.length; ++i) {
caryclark@google.com0e08a192012-07-13 21:07:52 +0000864 var title = testDivs[i].id.toString();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000865 var str = testDivs[i].firstChild.data;
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000866 if (str.split("addRect").length > 1) {
caryclark@google.com0e08a192012-07-13 21:07:52 +0000867 parseRect(str, title);
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000868 } else {
caryclark@google.com0e08a192012-07-13 21:07:52 +0000869 parse(str, title);
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000870 }
caryclark@google.com752b60e2012-03-22 21:11:17 +0000871 }
872 drawTop();
873 window.addEventListener('keypress', doKeyPress, true);
874}
875
876</script>
877</head>
878
879<body onLoad="start();">
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000880<canvas id="canvas" width="750" height="500"
caryclark@google.com752b60e2012-03-22 21:11:17 +0000881 onmousemove="handleMouseOver()"
882 onclick="handleMouseClick()"
883 ></canvas >
884</body>
885</html>