blob: 888f59ed1b06ff96c868f908df12c8340bfa029e [file] [log] [blame]
caryclark@google.comaf46cff2012-05-22 21:12:00 +00001/*
2 * Copyright 2012 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
caryclark@google.comaf46cff2012-05-22 21:12:00 +00008#include "EdgeWalker_Test.h"
9#include "Intersection_Tests.h"
caryclark@google.com8dcf1142012-07-02 20:27:02 +000010#include "ShapeOps.h"
caryclark@google.comaf46cff2012-05-22 21:12:00 +000011
caryclark@google.com47580692012-07-23 12:14:49 +000012#define TEST(name) { name, #name }
13
caryclark@google.comaf46cff2012-05-22 21:12:00 +000014static void testLine1() {
15 SkPath path, simple;
16 path.moveTo(2,0);
17 path.lineTo(1,1);
18 path.lineTo(0,0);
19 path.close();
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000020 testSimplifyx(path);
caryclark@google.comaf46cff2012-05-22 21:12:00 +000021}
22
23static void addInnerCWTriangle(SkPath& path) {
24 path.moveTo(3,0);
25 path.lineTo(4,1);
26 path.lineTo(2,1);
27 path.close();
28}
29
30static void addInnerCCWTriangle(SkPath& path) {
31 path.moveTo(3,0);
32 path.lineTo(2,1);
33 path.lineTo(4,1);
34 path.close();
35}
36
37static void addOuterCWTriangle(SkPath& path) {
38 path.moveTo(3,0);
39 path.lineTo(6,2);
40 path.lineTo(0,2);
41 path.close();
42}
43
44static void addOuterCCWTriangle(SkPath& path) {
45 path.moveTo(3,0);
46 path.lineTo(0,2);
47 path.lineTo(6,2);
48 path.close();
49}
50
51static void testLine2() {
52 SkPath path, simple;
53 addInnerCWTriangle(path);
54 addOuterCWTriangle(path);
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000055 testSimplifyx(path);
caryclark@google.comaf46cff2012-05-22 21:12:00 +000056}
57
caryclark@google.com495f8e42012-05-31 13:13:11 +000058static void testLine3() {
59 SkPath path, simple;
60 addInnerCCWTriangle(path);
61 addOuterCWTriangle(path);
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000062 testSimplifyx(path);
caryclark@google.com495f8e42012-05-31 13:13:11 +000063}
64
65static void testLine4() {
66 SkPath path, simple;
67 addOuterCCWTriangle(path);
68 addOuterCWTriangle(path);
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000069 testSimplifyx(path);
caryclark@google.com495f8e42012-05-31 13:13:11 +000070}
71
72static void testLine5() {
73 SkPath path, simple;
74 addOuterCWTriangle(path);
75 addOuterCWTriangle(path);
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000076 testSimplifyx(path);
caryclark@google.com495f8e42012-05-31 13:13:11 +000077}
caryclark@google.comaf46cff2012-05-22 21:12:00 +000078
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000079static void testLine6() {
80 SkPath path, simple;
81 path.moveTo(0,0);
82 path.lineTo(4,0);
83 path.lineTo(2,2);
84 path.close();
85 path.moveTo(2,0);
86 path.lineTo(6,0);
87 path.lineTo(4,2);
88 path.close();
89 testSimplifyx(path);
90}
91
92static void testLine7() {
93 SkPath path, simple;
94 path.moveTo(0,0);
95 path.lineTo(4,0);
96 path.lineTo(2,2);
97 path.close();
98 path.moveTo(6,0);
99 path.lineTo(2,0);
100 path.lineTo(4,2);
101 path.close();
102 testSimplifyx(path);
103}
104
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000105static void testLine7a() {
106 SkPath path, simple;
107 path.moveTo(0,0);
108 path.lineTo(4,0);
109 path.lineTo(2,2);
110 path.close();
111 testSimplifyx(path);
112}
113
114static void testLine7b() {
115 SkPath path, simple;
116 path.moveTo(0,0);
117 path.lineTo(4,0);
118 path.close();
119 path.moveTo(6,0);
120 path.lineTo(2,0);
121 path.lineTo(4,2);
122 path.close();
123 testSimplifyx(path);
124}
125
caryclark@google.com88f7d0c2012-06-07 21:09:20 +0000126static void testLine8() {
127 SkPath path, simple;
128 path.moveTo(0,4);
129 path.lineTo(4,4);
130 path.lineTo(2,2);
131 path.close();
132 path.moveTo(2,4);
133 path.lineTo(6,4);
134 path.lineTo(4,2);
135 path.close();
136 testSimplifyx(path);
137}
138
139static void testLine9() {
140 SkPath path, simple;
141 path.moveTo(0,4);
142 path.lineTo(4,4);
143 path.lineTo(2,2);
144 path.close();
145 path.moveTo(6,4);
146 path.lineTo(2,4);
147 path.lineTo(4,2);
148 path.close();
149 testSimplifyx(path);
150}
151
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000152static void testLine10() {
153 SkPath path, simple;
154 path.moveTo(0,4);
155 path.lineTo(4,4);
156 path.lineTo(2,2);
157 path.close();
158 path.moveTo(2,1);
159 path.lineTo(3,4);
160 path.lineTo(6,1);
161 path.close();
162 testSimplifyx(path);
163}
caryclark@google.com88f7d0c2012-06-07 21:09:20 +0000164
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000165static void testLine10a() {
166 SkPath path, simple;
167 path.moveTo(0,4);
168 path.lineTo(8,4);
169 path.lineTo(4,0);
170 path.close();
171 path.moveTo(2,2);
172 path.lineTo(3,3);
173 path.lineTo(4,2);
174 path.close();
175 testSimplifyx(path);
176}
177
178static void addCWContainer(SkPath& path) {
179 path.moveTo(6,4);
180 path.lineTo(0,4);
181 path.lineTo(3,1);
182 path.close();
183}
184
185static void addCCWContainer(SkPath& path) {
186 path.moveTo(0,4);
187 path.lineTo(6,4);
188 path.lineTo(3,1);
189 path.close();
190}
191
192static void addCWContents(SkPath& path) {
193 path.moveTo(2,3);
194 path.lineTo(3,2);
195 path.lineTo(4,3);
196 path.close();
197}
198
199static void addCCWContents(SkPath& path) {
200 path.moveTo(3,2);
201 path.lineTo(2,3);
202 path.lineTo(4,3);
203 path.close();
204}
205
206static void testLine11() {
207 SkPath path, simple;
208 addCWContainer(path);
209 addCWContents(path);
210 testSimplifyx(path);
211}
212
213static void testLine12() {
214 SkPath path, simple;
215 addCCWContainer(path);
216 addCWContents(path);
217 testSimplifyx(path);
218}
219
220static void testLine13() {
221 SkPath path, simple;
222 addCWContainer(path);
223 addCCWContents(path);
224 testSimplifyx(path);
225}
226
227static void testLine14() {
228 SkPath path, simple;
229 addCCWContainer(path);
230 addCCWContents(path);
231 testSimplifyx(path);
232}
233
234static void testLine15() {
235 SkPath path, simple;
236 path.addRect(0, 0, 9, 9, (SkPath::Direction) 0);
237 testSimplifyx(path);
238}
239
240static void testLine16() {
241 SkPath path, simple;
242 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
243 path.addRect(0, 4, 9, 9, (SkPath::Direction) 0);
244 testSimplifyx(path);
245}
246
247static void testLine17() {
248 SkPath path, simple;
249 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
250 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
251 testSimplifyx(path);
252}
253
254static void testLine18() {
255 SkPath path, simple;
256 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
257 path.addRect(12, 4, 21, 21, (SkPath::Direction) 0);
258 testSimplifyx(path);
259}
260
261static void testLine19() {
262 SkPath path, simple;
263 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
264 path.addRect(12, 16, 21, 21, (SkPath::Direction) 0);
265 testSimplifyx(path);
266}
267
268static void testLine20() {
269 SkPath path, simple;
270 path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
271 path.addRect(0, 12, 9, 9, (SkPath::Direction) 0);
272 testSimplifyx(path);
273}
274
275static void testLine21() {
276 SkPath path, simple;
277 path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
278 path.addRect(0, 16, 9, 9, (SkPath::Direction) 0);
279 testSimplifyx(path);
280}
281
282static void testLine22() {
283 SkPath path, simple;
284 path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
285 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
286 testSimplifyx(path);
287}
288
289static void testLine23() {
290 SkPath path, simple;
291 path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
292 path.addRect(12, 0, 21, 21, (SkPath::Direction) 0);
293 testSimplifyx(path);
294}
295
296
297
298static void testLine24a() {
299 SkPath path, simple;
300 path.moveTo(2,0);
301 path.lineTo(4,4);
302 path.lineTo(0,4);
303 path.close();
304 path.moveTo(2,0);
305 path.lineTo(1,2);
306 path.lineTo(2,2);
307 path.close();
308 testSimplifyx(path);
309}
310
311static void testLine24() {
312 SkPath path, simple;
313 path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
314 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
315 testSimplifyx(path);
316}
317
318static void testLine25() {
319 SkPath path, simple;
320 path.addRect(0, 6, 12, 12, (SkPath::Direction) 0);
321 path.addRect(12, 0, 21, 21, (SkPath::Direction) 0);
322 testSimplifyx(path);
323}
324
325static void testLine26() {
326 SkPath path, simple;
327 path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
328 path.addRect(0, 12, 9, 9, (SkPath::Direction) 0);
329 testSimplifyx(path);
330}
331
332static void testLine27() {
333 SkPath path, simple;
334 path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
335 path.addRect(12, 8, 21, 21, (SkPath::Direction) 0);
336 testSimplifyx(path);
337}
338
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000339static void testLine28() {
340 SkPath path, simple;
341 path.addRect(0, 6, 12, 12, (SkPath::Direction) 0);
342 path.addRect(0, 0, 9, 9, (SkPath::Direction) 0);
343 testSimplifyx(path);
344}
345
346static void testLine29() {
347 SkPath path, simple;
348 path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
349 path.addRect(12, 12, 21, 21, (SkPath::Direction) 0);
350 testSimplifyx(path);
351}
352
353static void testLine30() {
354 SkPath path, simple;
355 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
356 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
357 path.addRect(4, 4, 13, 13, (SkPath::Direction) 0);
358 testSimplifyx(path);
359}
360
361static void testLine31() {
362 SkPath path, simple;
363 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
364 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
365 path.addRect(0, 4, 9, 9, (SkPath::Direction) 0);
366 testSimplifyx(path);
367}
368
369static void testLine32() {
370 SkPath path, simple;
371 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
372 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
373 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
374 testSimplifyx(path);
375}
376
caryclark@google.com210acaf2012-07-12 21:05:13 +0000377static void testLine33() {
378 SkPath path, simple;
379 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
380 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
381 path.addRect(4, 16, 13, 13, (SkPath::Direction) 0);
382 testSimplifyx(path);
383}
384
385static void testLine34() {
386 SkPath path, simple;
387 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
388 path.addRect(0, 6, 12, 12, (SkPath::Direction) 0);
389 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
390 testSimplifyx(path);
391}
392
393static void testLine35() {
394 SkPath path, simple;
395 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
396 path.addRect(6, 0, 18, 18, (SkPath::Direction) 0);
397 path.addRect(4, 16, 13, 13, (SkPath::Direction) 0);
398 testSimplifyx(path);
399}
400
caryclark@google.com0e08a192012-07-13 21:07:52 +0000401static void testLine36() {
402 SkPath path, simple;
403 path.addRect(0, 10, 20, 20, (SkPath::Direction) 0);
404 path.addRect(6, 12, 18, 18, (SkPath::Direction) 0);
405 path.addRect(4, 16, 13, 13, (SkPath::Direction) 0);
406 testSimplifyx(path);
407}
408
caryclark@google.com47580692012-07-23 12:14:49 +0000409static void testLine37() {
410 SkPath path, simple;
411 path.addRect(0, 20, 20, 20, (SkPath::Direction) 0);
412 path.addRect(18, 24, 30, 30, (SkPath::Direction) 0);
413 path.addRect(0, 0, 9, 9, (SkPath::Direction) 0);
414 testSimplifyx(path);
415}
416
417static void testLine38() {
418 SkPath path, simple;
419 path.addRect(10, 0, 30, 30, (SkPath::Direction) 0);
420 path.addRect(6, 12, 18, 18, (SkPath::Direction) 0);
421 path.addRect(12, 12, 21, 21, (SkPath::Direction) 0);
422 testSimplifyx(path);
423}
424
425static void testLine40() {
426 SkPath path, simple;
427 path.addRect(10, 0, 30, 30, (SkPath::Direction) 0);
428 path.addRect(12, 18, 24, 24, (SkPath::Direction) 0);
429 path.addRect(4, 16, 13, 13, (SkPath::Direction) 0);
430 testSimplifyx(path);
431}
432
433static void testLine41() {
434 SkPath path, simple;
435 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
436 path.addRect(18, 24, 30, 30, (SkPath::Direction) 0);
437 path.addRect(12, 0, 21, 21, (SkPath::Direction) 0);
438 testSimplifyx(path);
439}
440
441static void testLine42() {
442 SkPath path, simple;
443 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
444 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
445 path.addRect(8, 16, 17, 17, (SkPath::Direction) 0);
446 testSimplifyx(path);
447}
448
449static void testLine43() {
450 SkPath path, simple;
451 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
452 path.addRect(6, 24, 18, 18, (SkPath::Direction) 0);
453 path.addRect(0, 32, 9, 36, (SkPath::Direction) 1);
454 testSimplifyx(path);
455}
456
457static void testLine44() {
458 SkPath path, simple;
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 testSimplifyx(path);
463}
464
465static void testLine45() {
466 SkPath path, simple;
467 path.addRect(10, 0, 30, 30, (SkPath::Direction) 0);
468 path.addRect(18, 0, 30, 30, (SkPath::Direction) 0);
469 path.addRect(24, 32, 33, 36, (SkPath::Direction) 0);
470 testSimplifyx(path);
471}
472
473static void testLine46() {
474 SkPath path, simple;
475 path.addRect(10, 40, 30, 30, (SkPath::Direction) 0);
476 path.addRect(24, 0, 36, 36, (SkPath::Direction) 0);
477 path.addRect(24, 32, 33, 36, (SkPath::Direction) 0);
478 testSimplifyx(path);
479}
480
481static void testLine47() {
482 SkPath path, simple;
483 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
484 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
485 path.addRect(0, 0, 9, 9, (SkPath::Direction) 1);
486 testSimplifyx(path);
487}
488
489static void testLine48() {
490 SkPath path, simple;
491 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
492 path.addRect(0, 6, 12, 12, (SkPath::Direction) 0);
493 path.addRect(0, 0, 9, 9, (SkPath::Direction) 1);
494 testSimplifyx(path);
495}
496
497static void testLine49() {
498 SkPath path, simple;
499 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
500 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
501 path.addRect(0, 0, 9, 9, (SkPath::Direction) 0);
502 testSimplifyx(path);
503}
504
505static void testLine50() {
506 SkPath path, simple;
507 path.addRect(10, 30, 30, 30, (SkPath::Direction) 0);
508 path.addRect(24, 20, 36, 30, (SkPath::Direction) 0);
509 testSimplifyx(path);
510}
511
512
513static void testLine51() {
514 SkPath path, simple;
515 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
516 path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
517 path.addRect(4, 12, 13, 13, (SkPath::Direction) 1);
518 testSimplifyx(path);
519}
520
caryclark@google.come21cb182012-07-23 21:26:31 +0000521static void testLine52() {
522 SkPath path, simple;
523 path.addRect(0, 30, 20, 20, (SkPath::Direction) 0);
524 path.addRect(6, 20, 18, 30, (SkPath::Direction) 0);
525 path.addRect(32, 0, 36, 41, (SkPath::Direction) 0);
526 testSimplifyx(path);
527}
528
529static void testLine53() {
530 SkPath path, simple;
531 path.addRect(10, 30, 30, 30, (SkPath::Direction) 0);
532 path.addRect(12, 20, 24, 30, (SkPath::Direction) 0);
533 path.addRect(12, 32, 21, 36, (SkPath::Direction) 1);
534 testSimplifyx(path);
535}
536
537static void testLine54() {
538 SkPath path, simple;
539 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
540 path.addRect(6, 0, 18, 18, (SkPath::Direction) 0);
541 path.addRect(8, 4, 17, 17, (SkPath::Direction) 1);
542 testSimplifyx(path);
543}
544
545static void testLine55() {
546 SkPath path, simple;
547 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
548 path.addRect(6, 6, 18, 18, (SkPath::Direction) 0);
549 path.addRect(4, 4, 13, 13, (SkPath::Direction) 1);
550 testSimplifyx(path);
551}
552
553static void (*firstTest)() = 0;
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000554
555static struct {
556 void (*fun)();
557 const char* str;
558} tests[] = {
caryclark@google.come21cb182012-07-23 21:26:31 +0000559 TEST(testLine55),
560 TEST(testLine54),
561 TEST(testLine53),
562 TEST(testLine52),
caryclark@google.com47580692012-07-23 12:14:49 +0000563 TEST(testLine51),
564 TEST(testLine50),
565 TEST(testLine49),
566 TEST(testLine48),
567 TEST(testLine47),
568 TEST(testLine46),
569 TEST(testLine45),
570 TEST(testLine44),
571 TEST(testLine43),
572 TEST(testLine42),
573 TEST(testLine41),
574 TEST(testLine40),
575 TEST(testLine38),
576 TEST(testLine37),
577 TEST(testLine36),
578 TEST(testLine35),
579 TEST(testLine34),
580 TEST(testLine33),
581 TEST(testLine32),
582 TEST(testLine31),
583 TEST(testLine30),
584 TEST(testLine29),
585 TEST(testLine28),
586 TEST(testLine27),
587 TEST(testLine26),
588 TEST(testLine25),
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000589 TEST(testLine24a),
590 TEST(testLine24),
caryclark@google.com47580692012-07-23 12:14:49 +0000591 TEST(testLine23),
592 TEST(testLine22),
593 TEST(testLine21),
594 TEST(testLine20),
595 TEST(testLine19),
596 TEST(testLine18),
597 TEST(testLine17),
598 TEST(testLine16),
599 TEST(testLine15),
600 TEST(testLine14),
601 TEST(testLine13),
602 TEST(testLine12),
603 TEST(testLine11),
604 TEST(testLine10a),
605 TEST(testLine10),
606 TEST(testLine9),
607 TEST(testLine8),
608 TEST(testLine7b),
609 TEST(testLine7a),
610 TEST(testLine7),
611 TEST(testLine6),
612 TEST(testLine5),
613 TEST(testLine4),
614 TEST(testLine3),
615 TEST(testLine2),
616 TEST(testLine1),
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000617};
618
619static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
620
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000621static bool skipAll = false;
622
623void SimplifyNew_Test() {
624 if (skipAll) {
625 return;
626 }
caryclark@google.com47580692012-07-23 12:14:49 +0000627#ifdef SK_DEBUG
628 gDebugMaxWindSum = 3;
629 gDebugMaxWindValue = 3;
630#endif
caryclark@google.come21cb182012-07-23 21:26:31 +0000631 size_t index = testCount - 1;
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000632 if (firstTest) {
caryclark@google.come21cb182012-07-23 21:26:31 +0000633 while (index > 0 && tests[index].fun != firstTest) {
634 --index;
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000635 }
636 }
637 bool firstTestComplete = false;
caryclark@google.come21cb182012-07-23 21:26:31 +0000638 do {
639 SkDebugf(" %s [%s]\n", __FUNCTION__, tests[index].str);
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000640 (*tests[index].fun)();
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000641 firstTestComplete = true;
caryclark@google.come21cb182012-07-23 21:26:31 +0000642 } while (index--);
caryclark@google.com47580692012-07-23 12:14:49 +0000643#ifdef SK_DEBUG
644 gDebugMaxWindSum = SK_MaxS32;
645 gDebugMaxWindValue = SK_MaxS32;
646#endif
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000647}