SimplifyNew_Test.cpp revision 8dcf114db9762c02d217beba6e29dffa4e92d298
1/*
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
8#include "EdgeWalker_Test.h"
9#include "Intersection_Tests.h"
10#include "ShapeOps.h"
11
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();
18    testSimplifyx(path);
19}
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);
53    testSimplifyx(path);
54}
55
56static void testLine3() {
57    SkPath path, simple;
58    addInnerCCWTriangle(path);
59    addOuterCWTriangle(path);
60    testSimplifyx(path);
61}
62
63static void testLine4() {
64    SkPath path, simple;
65    addOuterCCWTriangle(path);
66    addOuterCWTriangle(path);
67    testSimplifyx(path);
68}
69
70static void testLine5() {
71    SkPath path, simple;
72    addOuterCWTriangle(path);
73    addOuterCWTriangle(path);
74    testSimplifyx(path);
75}
76
77static 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
103static void testLine8() {
104    SkPath path, simple;
105    path.moveTo(0,4);
106    path.lineTo(4,4);
107    path.lineTo(2,2);
108    path.close();
109    path.moveTo(2,4);
110    path.lineTo(6,4);
111    path.lineTo(4,2);
112    path.close();
113    testSimplifyx(path);
114}
115
116static void testLine9() {
117    SkPath path, simple;
118    path.moveTo(0,4);
119    path.lineTo(4,4);
120    path.lineTo(2,2);
121    path.close();
122    path.moveTo(6,4);
123    path.lineTo(2,4);
124    path.lineTo(4,2);
125    path.close();
126    testSimplifyx(path);
127}
128
129static void testLine10() {
130    SkPath path, simple;
131    path.moveTo(0,4);
132    path.lineTo(4,4);
133    path.lineTo(2,2);
134    path.close();
135    path.moveTo(2,1);
136    path.lineTo(3,4);
137    path.lineTo(6,1);
138    path.close();
139    testSimplifyx(path);
140}
141
142static void testLine10a() {
143    SkPath path, simple;
144    path.moveTo(0,4);
145    path.lineTo(8,4);
146    path.lineTo(4,0);
147    path.close();
148    path.moveTo(2,2);
149    path.lineTo(3,3);
150    path.lineTo(4,2);
151    path.close();
152    testSimplifyx(path);
153}
154
155static void addCWContainer(SkPath& path) {
156    path.moveTo(6,4);
157    path.lineTo(0,4);
158    path.lineTo(3,1);
159    path.close();
160}
161
162static void addCCWContainer(SkPath& path) {
163    path.moveTo(0,4);
164    path.lineTo(6,4);
165    path.lineTo(3,1);
166    path.close();
167}
168
169static void addCWContents(SkPath& path) {
170    path.moveTo(2,3);
171    path.lineTo(3,2);
172    path.lineTo(4,3);
173    path.close();
174}
175
176static void addCCWContents(SkPath& path) {
177    path.moveTo(3,2);
178    path.lineTo(2,3);
179    path.lineTo(4,3);
180    path.close();
181}
182
183static void testLine11() {
184    SkPath path, simple;
185    addCWContainer(path);
186    addCWContents(path);
187    testSimplifyx(path);
188}
189
190static void testLine12() {
191    SkPath path, simple;
192    addCCWContainer(path);
193    addCWContents(path);
194    testSimplifyx(path);
195}
196
197static void testLine13() {
198    SkPath path, simple;
199    addCWContainer(path);
200    addCCWContents(path);
201    testSimplifyx(path);
202}
203
204static void testLine14() {
205    SkPath path, simple;
206    addCCWContainer(path);
207    addCCWContents(path);
208    testSimplifyx(path);
209}
210
211static void testLine15() {
212    SkPath path, simple;
213    path.addRect(0, 0, 9, 9, (SkPath::Direction) 0);
214    testSimplifyx(path);
215}
216
217static void testLine16() {
218    SkPath path, simple;
219    path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
220    path.addRect(0, 4, 9, 9, (SkPath::Direction) 0);
221    testSimplifyx(path);
222}
223
224static void testLine17() {
225    SkPath path, simple;
226    path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
227    path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
228    testSimplifyx(path);
229}
230
231static void testLine18() {
232    SkPath path, simple;
233    path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
234    path.addRect(12, 4, 21, 21, (SkPath::Direction) 0);
235    testSimplifyx(path);
236}
237
238static void testLine19() {
239    SkPath path, simple;
240    path.addRect(0, 0, 12, 12, (SkPath::Direction) 0);
241    path.addRect(12, 16, 21, 21, (SkPath::Direction) 0);
242    testSimplifyx(path);
243}
244
245static void testLine20() {
246    SkPath path, simple;
247    path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
248    path.addRect(0, 12, 9, 9, (SkPath::Direction) 0);
249    testSimplifyx(path);
250}
251
252static void testLine21() {
253    SkPath path, simple;
254    path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
255    path.addRect(0, 16, 9, 9, (SkPath::Direction) 0);
256    testSimplifyx(path);
257}
258
259static void testLine22() {
260    SkPath path, simple;
261    path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
262    path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
263    testSimplifyx(path);
264}
265
266static void testLine23() {
267    SkPath path, simple;
268    path.addRect(0, 12, 12, 12, (SkPath::Direction) 0);
269    path.addRect(12, 0, 21, 21, (SkPath::Direction) 0);
270    testSimplifyx(path);
271}
272
273
274
275static void testLine24a() {
276    SkPath path, simple;
277    path.moveTo(2,0);
278    path.lineTo(4,4);
279    path.lineTo(0,4);
280    path.close();
281    path.moveTo(2,0);
282    path.lineTo(1,2);
283    path.lineTo(2,2);
284    path.close();
285    testSimplifyx(path);
286}
287
288static void testLine24() {
289    SkPath path, simple;
290    path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
291    path.addRect(4, 12, 13, 13, (SkPath::Direction) 0);
292    testSimplifyx(path);
293}
294
295static void testLine25() {
296    SkPath path, simple;
297    path.addRect(0, 6, 12, 12, (SkPath::Direction) 0);
298    path.addRect(12, 0, 21, 21, (SkPath::Direction) 0);
299    testSimplifyx(path);
300}
301
302static void testLine26() {
303    SkPath path, simple;
304    path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
305    path.addRect(0, 12, 9, 9, (SkPath::Direction) 0);
306    testSimplifyx(path);
307}
308
309static void testLine27() {
310    SkPath path, simple;
311    path.addRect(0, 18, 12, 12, (SkPath::Direction) 0);
312    path.addRect(12, 8, 21, 21, (SkPath::Direction) 0);
313    testSimplifyx(path);
314}
315
316#define TEST(name) { name, #name }
317
318static struct {
319    void (*fun)();
320    const char* str;
321} tests[] = {
322    TEST(testLine1),
323    TEST(testLine2),
324    TEST(testLine3),
325    TEST(testLine4),
326    TEST(testLine5),
327    TEST(testLine6),
328    TEST(testLine7),
329    TEST(testLine8),
330    TEST(testLine9),
331    TEST(testLine10),
332    TEST(testLine10a),
333    TEST(testLine11),
334    TEST(testLine12),
335    TEST(testLine13),
336    TEST(testLine14),
337    TEST(testLine15),
338    TEST(testLine16),
339    TEST(testLine17),
340    TEST(testLine18),
341    TEST(testLine19),
342    TEST(testLine20),
343    TEST(testLine21),
344    TEST(testLine22),
345    TEST(testLine23),
346    TEST(testLine24a),
347    TEST(testLine24),
348    TEST(testLine25),
349    TEST(testLine26),
350    TEST(testLine27),
351};
352
353static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
354
355static void (*firstTest)() = 0;
356static bool skipAll = false;
357
358void SimplifyNew_Test() {
359    if (skipAll) {
360        return;
361    }
362    size_t index = 0;
363    if (firstTest) {
364        while (index < testCount && tests[index].fun != firstTest) {
365            ++index;
366        }
367    }
368    bool firstTestComplete = false;
369    for ( ; index < testCount; ++index) {
370        SkDebugf("%s [%s]\n", __FUNCTION__, tests[index].str);
371        (*tests[index].fun)();
372        firstTestComplete = true;
373    }
374}
375