blob: 06b0167ec9bc96201d9204cffc55ebd0493b8ef9 [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.com8dcf1142012-07-02 20:27:02 +0000399#define TEST(name) { name, #name }
400
401static struct {
402 void (*fun)();
403 const char* str;
404} tests[] = {
405 TEST(testLine1),
406 TEST(testLine2),
407 TEST(testLine3),
408 TEST(testLine4),
409 TEST(testLine5),
410 TEST(testLine6),
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000411 TEST(testLine7a),
412 TEST(testLine7b),
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000413 TEST(testLine7),
414 TEST(testLine8),
415 TEST(testLine9),
416 TEST(testLine10),
417 TEST(testLine10a),
418 TEST(testLine11),
419 TEST(testLine12),
420 TEST(testLine13),
421 TEST(testLine14),
422 TEST(testLine15),
423 TEST(testLine16),
424 TEST(testLine17),
425 TEST(testLine18),
426 TEST(testLine19),
427 TEST(testLine20),
428 TEST(testLine21),
429 TEST(testLine22),
430 TEST(testLine23),
431 TEST(testLine24a),
432 TEST(testLine24),
433 TEST(testLine25),
434 TEST(testLine26),
435 TEST(testLine27),
caryclark@google.comfa4a6e92012-07-11 17:52:32 +0000436 TEST(testLine28),
437 TEST(testLine29),
438 TEST(testLine30),
439 TEST(testLine31),
440 TEST(testLine32),
caryclark@google.com210acaf2012-07-12 21:05:13 +0000441 TEST(testLine33),
442 TEST(testLine34),
443 TEST(testLine35),
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000444};
445
446static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
447
caryclark@google.com9764cc62012-07-12 19:29:45 +0000448static void (*firstTest)() = 0;
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000449static bool skipAll = false;
450
451void SimplifyNew_Test() {
452 if (skipAll) {
453 return;
454 }
455 size_t index = 0;
456 if (firstTest) {
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000457 while (index < testCount && tests[index].fun != firstTest) {
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000458 ++index;
459 }
460 }
461 bool firstTestComplete = false;
462 for ( ; index < testCount; ++index) {
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000463 SkDebugf("%s [%s]\n", __FUNCTION__, tests[index].str);
464 (*tests[index].fun)();
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000465 firstTestComplete = true;
466 }
467}