blob: 022518b8b3b5c0f63da9ccb5ab6190dde2d60e2b [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
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
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000129static 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}
caryclark@google.com88f7d0c2012-06-07 21:09:20 +0000141
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000142static 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),
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000351};
352
353static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
354
caryclark@google.com88f7d0c2012-06-07 21:09:20 +0000355static void (*firstTest)() = 0;
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000356static bool skipAll = false;
357
358void SimplifyNew_Test() {
359 if (skipAll) {
360 return;
361 }
362 size_t index = 0;
363 if (firstTest) {
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000364 while (index < testCount && tests[index].fun != firstTest) {
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000365 ++index;
366 }
367 }
368 bool firstTestComplete = false;
369 for ( ; index < testCount; ++index) {
caryclark@google.com8dcf1142012-07-02 20:27:02 +0000370 SkDebugf("%s [%s]\n", __FUNCTION__, tests[index].str);
371 (*tests[index].fun)();
caryclark@google.comaf46cff2012-05-22 21:12:00 +0000372 firstTestComplete = true;
373 }
374}