blob: a7c5c31fd78f66ad1f69795319bafc078001e752 [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
12static void testLine1() {
13 SkPath path, simple;
14 path.moveTo(2,0);
15 path.lineTo(1,1);
16 path.lineTo(0,0);
17 path.close();
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000018 testSimplifyx(path);
caryclark@google.comaf46cff2012-05-22 21:12:00 +000019}
20
21static void addInnerCWTriangle(SkPath& path) {
22 path.moveTo(3,0);
23 path.lineTo(4,1);
24 path.lineTo(2,1);
25 path.close();
26}
27
28static void addInnerCCWTriangle(SkPath& path) {
29 path.moveTo(3,0);
30 path.lineTo(2,1);
31 path.lineTo(4,1);
32 path.close();
33}
34
35static void addOuterCWTriangle(SkPath& path) {
36 path.moveTo(3,0);
37 path.lineTo(6,2);
38 path.lineTo(0,2);
39 path.close();
40}
41
42static void addOuterCCWTriangle(SkPath& path) {
43 path.moveTo(3,0);
44 path.lineTo(0,2);
45 path.lineTo(6,2);
46 path.close();
47}
48
49static void testLine2() {
50 SkPath path, simple;
51 addInnerCWTriangle(path);
52 addOuterCWTriangle(path);
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000053 testSimplifyx(path);
caryclark@google.comaf46cff2012-05-22 21:12:00 +000054}
55
caryclark@google.com495f8e42012-05-31 13:13:11 +000056static void testLine3() {
57 SkPath path, simple;
58 addInnerCCWTriangle(path);
59 addOuterCWTriangle(path);
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000060 testSimplifyx(path);
caryclark@google.com495f8e42012-05-31 13:13:11 +000061}
62
63static void testLine4() {
64 SkPath path, simple;
65 addOuterCCWTriangle(path);
66 addOuterCWTriangle(path);
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000067 testSimplifyx(path);
caryclark@google.com495f8e42012-05-31 13:13:11 +000068}
69
70static void testLine5() {
71 SkPath path, simple;
72 addOuterCWTriangle(path);
73 addOuterCWTriangle(path);
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000074 testSimplifyx(path);
caryclark@google.com495f8e42012-05-31 13:13:11 +000075}
caryclark@google.comaf46cff2012-05-22 21:12:00 +000076
caryclark@google.com88f7d0c2012-06-07 21:09:20 +000077static void testLine6() {
78 SkPath path, simple;
79 path.moveTo(0,0);
80 path.lineTo(4,0);
81 path.lineTo(2,2);
82 path.close();
83 path.moveTo(2,0);
84 path.lineTo(6,0);
85 path.lineTo(4,2);
86 path.close();
87 testSimplifyx(path);
88}
89
90static void testLine7() {
91 SkPath path, simple;
92 path.moveTo(0,0);
93 path.lineTo(4,0);
94 path.lineTo(2,2);
95 path.close();
96 path.moveTo(6,0);
97 path.lineTo(2,0);
98 path.lineTo(4,2);
99 path.close();
100 testSimplifyx(path);
101}
102
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000103static void testLine7a() {
104 SkPath path, simple;
105 path.moveTo(0,0);
106 path.lineTo(4,0);
107 path.lineTo(2,2);
108 path.close();
109 testSimplifyx(path);
110}
111
112static void testLine7b() {
113 SkPath path, simple;
114 path.moveTo(0,0);
115 path.lineTo(4,0);
116 path.close();
117 path.moveTo(6,0);
118 path.lineTo(2,0);
119 path.lineTo(4,2);
120 path.close();
121 testSimplifyx(path);
122}
123
caryclark@google.com88f7d0c2012-06-07 21:09:20 +0000124static void testLine8() {
125 SkPath path, simple;
126 path.moveTo(0,4);
127 path.lineTo(4,4);
128 path.lineTo(2,2);
129 path.close();
130 path.moveTo(2,4);
131 path.lineTo(6,4);
132 path.lineTo(4,2);
133 path.close();
134 testSimplifyx(path);
135}
136
137static void testLine9() {
138 SkPath path, simple;
139 path.moveTo(0,4);
140 path.lineTo(4,4);
141 path.lineTo(2,2);
142 path.close();
143 path.moveTo(6,4);
144 path.lineTo(2,4);
145 path.lineTo(4,2);
146 path.close();
147 testSimplifyx(path);
148}
149
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000150static void testLine10() {
151 SkPath path, simple;
152 path.moveTo(0,4);
153 path.lineTo(4,4);
154 path.lineTo(2,2);
155 path.close();
156 path.moveTo(2,1);
157 path.lineTo(3,4);
158 path.lineTo(6,1);
159 path.close();
160 testSimplifyx(path);
161}
caryclark@google.com88f7d0c2012-06-07 21:09:20 +0000162
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000163static void testLine10a() {
164 SkPath path, simple;
165 path.moveTo(0,4);
166 path.lineTo(8,4);
167 path.lineTo(4,0);
168 path.close();
169 path.moveTo(2,2);
170 path.lineTo(3,3);
171 path.lineTo(4,2);
172 path.close();
173 testSimplifyx(path);
174}
175
176static void addCWContainer(SkPath& path) {
177 path.moveTo(6,4);
178 path.lineTo(0,4);
179 path.lineTo(3,1);
180 path.close();
181}
182
183static void addCCWContainer(SkPath& path) {
184 path.moveTo(0,4);
185 path.lineTo(6,4);
186 path.lineTo(3,1);
187 path.close();
188}
189
190static void addCWContents(SkPath& path) {
191 path.moveTo(2,3);
192 path.lineTo(3,2);
193 path.lineTo(4,3);
194 path.close();
195}
196
197static void addCCWContents(SkPath& path) {
198 path.moveTo(3,2);
199 path.lineTo(2,3);
200 path.lineTo(4,3);
201 path.close();
202}
203
204static void testLine11() {
205 SkPath path, simple;
206 addCWContainer(path);
207 addCWContents(path);
208 testSimplifyx(path);
209}
210
211static void testLine12() {
212 SkPath path, simple;
213 addCCWContainer(path);
214 addCWContents(path);
215 testSimplifyx(path);
216}
217
218static void testLine13() {
219 SkPath path, simple;
220 addCWContainer(path);
221 addCCWContents(path);
222 testSimplifyx(path);
223}
224
225static void testLine14() {
226 SkPath path, simple;
227 addCCWContainer(path);
228 addCCWContents(path);
229 testSimplifyx(path);
230}
231
232static void testLine15() {
233 SkPath path, simple;
234 path.addRect(0, 0, 9, 9, (SkPath::Direction) 0);
235 testSimplifyx(path);
236}
237
238static void testLine16() {
239 SkPath path, simple;
240 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
241 path.addRect(0, 4, 9, 9, (SkPath::Direction) 0);
242 testSimplifyx(path);
243}
244
245static void testLine17() {
246 SkPath path, simple;
247 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
248 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
249 testSimplifyx(path);
250}
251
252static void testLine18() {
253 SkPath path, simple;
254 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
255 path.addRect(12, 4, 21, 21, (SkPath::Direction) 0);
256 testSimplifyx(path);
257}
258
259static void testLine19() {
260 SkPath path, simple;
261 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
262 path.addRect(12, 16, 21, 21, (SkPath::Direction) 0);
263 testSimplifyx(path);
264}
265
266static void testLine20() {
267 SkPath path, simple;
268 path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
269 path.addRect(0, 12, 9, 9, (SkPath::Direction) 0);
270 testSimplifyx(path);
271}
272
273static void testLine21() {
274 SkPath path, simple;
275 path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
276 path.addRect(0, 16, 9, 9, (SkPath::Direction) 0);
277 testSimplifyx(path);
278}
279
280static void testLine22() {
281 SkPath path, simple;
282 path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
283 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
284 testSimplifyx(path);
285}
286
287static void testLine23() {
288 SkPath path, simple;
289 path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
290 path.addRect(12, 0, 21, 21, (SkPath::Direction) 0);
291 testSimplifyx(path);
292}
293
294
295
296static void testLine24a() {
297 SkPath path, simple;
298 path.moveTo(2,0);
299 path.lineTo(4,4);
300 path.lineTo(0,4);
301 path.close();
302 path.moveTo(2,0);
303 path.lineTo(1,2);
304 path.lineTo(2,2);
305 path.close();
306 testSimplifyx(path);
307}
308
309static void testLine24() {
310 SkPath path, simple;
311 path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
312 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
313 testSimplifyx(path);
314}
315
316static void testLine25() {
317 SkPath path, simple;
318 path.addRect(0, 6, 12, 12, (SkPath::Direction) 0);
319 path.addRect(12, 0, 21, 21, (SkPath::Direction) 0);
320 testSimplifyx(path);
321}
322
323static void testLine26() {
324 SkPath path, simple;
325 path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
326 path.addRect(0, 12, 9, 9, (SkPath::Direction) 0);
327 testSimplifyx(path);
328}
329
330static void testLine27() {
331 SkPath path, simple;
332 path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
333 path.addRect(12, 8, 21, 21, (SkPath::Direction) 0);
334 testSimplifyx(path);
335}
336
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000337static void testLine28() {
338 SkPath path, simple;
339 path.addRect(0, 6, 12, 12, (SkPath::Direction) 0);
340 path.addRect(0, 0, 9, 9, (SkPath::Direction) 0);
341 testSimplifyx(path);
342}
343
344static void testLine29() {
345 SkPath path, simple;
346 path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
347 path.addRect(12, 12, 21, 21, (SkPath::Direction) 0);
348 testSimplifyx(path);
349}
350
351static void testLine30() {
352 SkPath path, simple;
353 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
354 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
355 path.addRect(4, 4, 13, 13, (SkPath::Direction) 0);
356 testSimplifyx(path);
357}
358
359static void testLine31() {
360 SkPath path, simple;
361 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
362 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
363 path.addRect(0, 4, 9, 9, (SkPath::Direction) 0);
364 testSimplifyx(path);
365}
366
367static void testLine32() {
368 SkPath path, simple;
369 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
370 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
371 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
372 testSimplifyx(path);
373}
374
caryclark@google.com210acaf2012-07-12 21:05:13 +0000375static void testLine33() {
376 SkPath path, simple;
377 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
378 path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
379 path.addRect(4, 16, 13, 13, (SkPath::Direction) 0);
380 testSimplifyx(path);
381}
382
383static void testLine34() {
384 SkPath path, simple;
385 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
386 path.addRect(0, 6, 12, 12, (SkPath::Direction) 0);
387 path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
388 testSimplifyx(path);
389}
390
391static void testLine35() {
392 SkPath path, simple;
393 path.addRect(0, 0, 20, 20, (SkPath::Direction) 0);
394 path.addRect(6, 0, 18, 18, (SkPath::Direction) 0);
395 path.addRect(4, 16, 13, 13, (SkPath::Direction) 0);
396 testSimplifyx(path);
397}
398
caryclark@google.com0e08a192012-07-13 21:07:52 +0000399static void testLine36() {
400 SkPath path, simple;
401 path.addRect(0, 10, 20, 20, (SkPath::Direction) 0);
402 path.addRect(6, 12, 18, 18, (SkPath::Direction) 0);
403 path.addRect(4, 16, 13, 13, (SkPath::Direction) 0);
404 testSimplifyx(path);
405}
406
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000407#define TEST(name) { name, #name }
408
409static struct {
410 void (*fun)();
411 const char* str;
412} tests[] = {
413 TEST(testLine1),
414 TEST(testLine2),
415 TEST(testLine3),
416 TEST(testLine4),
417 TEST(testLine5),
418 TEST(testLine6),
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000419 TEST(testLine7a),
420 TEST(testLine7b),
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000421 TEST(testLine7),
422 TEST(testLine8),
423 TEST(testLine9),
424 TEST(testLine10),
425 TEST(testLine10a),
426 TEST(testLine11),
427 TEST(testLine12),
428 TEST(testLine13),
429 TEST(testLine14),
430 TEST(testLine15),
431 TEST(testLine16),
432 TEST(testLine17),
433 TEST(testLine18),
434 TEST(testLine19),
435 TEST(testLine20),
436 TEST(testLine21),
437 TEST(testLine22),
438 TEST(testLine23),
439 TEST(testLine24a),
440 TEST(testLine24),
441 TEST(testLine25),
442 TEST(testLine26),
443 TEST(testLine27),
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000444 TEST(testLine28),
445 TEST(testLine29),
446 TEST(testLine30),
447 TEST(testLine31),
448 TEST(testLine32),
caryclark@google.com210acaf2012-07-12 21:05:13 +0000449 TEST(testLine33),
450 TEST(testLine34),
451 TEST(testLine35),
caryclark@google.com0e08a192012-07-13 21:07:52 +0000452 TEST(testLine36),
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000453};
454
455static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
456
caryclark@google.com9764cc62012-07-12 19:29:45 +0000457static void (*firstTest)() = 0;
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000458static bool skipAll = false;
459
460void SimplifyNew_Test() {
461 if (skipAll) {
462 return;
463 }
464 size_t index = 0;
465 if (firstTest) {
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000466 while (index < testCount && tests[index].fun != firstTest) {
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000467 ++index;
468 }
469 }
470 bool firstTestComplete = false;
471 for ( ; index < testCount; ++index) {
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000472 SkDebugf("%s [%s]\n", __FUNCTION__, tests[index].str);
473 (*tests[index].fun)();
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000474 firstTestComplete = true;
475 }
476}