blob: 78269c40974f8947435e7771a2372bf6d223d788 [file] [log] [blame]
caryclark@google.comcd4421d2012-03-01 19:16:31 +00001#include "EdgeWalker_Test.h"
2#include "Intersection_Tests.h"
caryclark@google.com198e0542012-03-30 18:47:02 +00003#include "SkBitmap.h"
4
5static SkBitmap bitmap;
caryclark@google.comcd4421d2012-03-01 19:16:31 +00006
7static void testSimplifyTriangle() {
8 SkPath path, out;
9 path.setFillType(SkPath::kWinding_FillType);
10 path.moveTo(10,10); // triangle |\ .
11 path.lineTo(10,30); // |_\ .
12 path.lineTo(20,30);
13 path.close();
14 path.moveTo(20,10); // triangle /|
15 path.lineTo(10,30); // /_|
16 path.lineTo(20,30);
17 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000018 testSimplify(path, true, out, bitmap); // expect |\/|
rmistry@google.comd6176b02012-08-23 18:14:13 +000019 // |__|
caryclark@google.comcd4421d2012-03-01 19:16:31 +000020}
21
22static void testSimplifyTriangle3() {
23 SkPath path, out;
24 path.moveTo(0, 0);
25 path.lineTo(1, 0);
26 path.lineTo(0, 1);
27 path.close();
28 path.moveTo(0, 0);
29 path.lineTo(1, 0);
30 path.lineTo(3, 1);
31 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000032 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +000033}
34
35static void testSimplifyTriangle4() {
36 SkPath path, out;
37 path.moveTo(0, 0);
38 path.lineTo(1, 0);
39 path.lineTo(0, 1);
40 path.close();
41 path.moveTo(0, 0);
42 path.lineTo(1, 0);
43 path.lineTo(2, 1);
44 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000045 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +000046}
47
48static void testSimplifyTriangle5() {
49 SkPath path, out;
50 path.moveTo(0, 0);
51 path.lineTo(1, 0);
52 path.lineTo(0, 1);
53 path.close();
54 path.moveTo(0, 0);
55 path.lineTo(1, 1);
56 path.lineTo(2, 1);
57 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000058 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +000059}
60
61static void testSimplifyTriangle6() {
62 SkPath path, out;
63 path.moveTo(0, 0);
64 path.lineTo(1, 0);
65 path.lineTo(0, 1);
66 path.lineTo(0, 0);
67 path.close();
68 path.moveTo(0, 0);
69 path.lineTo(0, 1);
70 path.lineTo(3, 1);
71 path.lineTo(0, 0);
72 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000073 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +000074}
75
76static void testSimplifyTriangle7() {
77 SkPath path, out;
78 path.moveTo(0, 0);
79 path.lineTo(1, 0);
80 path.lineTo(0, 1);
81 path.lineTo(0, 0);
82 path.close();
83 path.moveTo(0, 0);
84 path.lineTo(1, 1);
85 path.lineTo(0, 2);
86 path.lineTo(0, 0);
87 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000088 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +000089}
90
91static void testSimplifyTriangle8() {
92 SkPath path, out;
93 path.moveTo(0, 0);
94 path.lineTo(1, 0);
95 path.lineTo(0, 1);
96 path.lineTo(0, 0);
97 path.close();
98 path.moveTo(0, 1);
99 path.lineTo(1, 2);
100 path.lineTo(1, 3);
101 path.lineTo(0, 1);
102 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000103 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000104}
105
106static void testSimplifyTriangle9() {
107 SkPath path, out;
108 path.moveTo(0, 0);
109 path.lineTo(1, 0);
110 path.lineTo(1, 1);
111 path.lineTo(0, 0);
112 path.close();
113 path.moveTo(0, 0);
114 path.lineTo(1, 1);
115 path.lineTo(2, 1);
116 path.lineTo(0, 0);
117 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000118 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000119}
120
121static void testSimplifyTriangle10() {
122 SkPath path, out;
123 path.moveTo(0, 0);
124 path.lineTo(1, 0);
125 path.lineTo(1, 1);
126 path.lineTo(0, 0);
127 path.close();
128 path.moveTo(0, 0);
129 path.lineTo(2, 0);
130 path.lineTo(0, 1);
131 path.lineTo(0, 0);
132 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000133 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000134}
135
136static void testSimplifyTriangle11() {
137 SkPath path, out;
138 path.moveTo(0, 0);
139 path.lineTo(1, 0);
140 path.lineTo(0, 2);
141 path.lineTo(0, 0);
142 path.close();
143 path.moveTo(0, 0);
144 path.lineTo(2, 1);
145 path.lineTo(2, 2);
146 path.lineTo(0, 0);
147 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000148 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000149}
150
151static void testSimplifyTriangle12() {
152 SkPath path, out;
153 path.moveTo(0, 0);
154 path.lineTo(1, 0);
155 path.lineTo(1, 2);
156 path.lineTo(0, 0);
157 path.close();
158 path.moveTo(2, 0);
159 path.lineTo(0, 3);
160 path.lineTo(1, 1);
161 path.lineTo(2, 0);
162 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000163 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000164}
165
166static void testSimplifyTriangle13() {
167 SkPath path, out;
168 path.moveTo(0, 0);
169 path.lineTo(1, 0);
170 path.lineTo(0, 3);
171 path.lineTo(0, 0);
172 path.close();
173 path.moveTo(3, 0);
174 path.lineTo(0, 3);
175 path.lineTo(1, 1);
176 path.lineTo(3, 0);
177 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000178 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000179}
180
181static void testSimplifyTriangle14() {
182 SkPath path, out;
183 path.moveTo(0, 0);
184 path.lineTo(1, 0);
185 path.lineTo(0, 1);
186 path.lineTo(0, 0);
187 path.close();
188 path.moveTo(0, 0);
189 path.lineTo(1, 0);
190 path.lineTo(0, 1);
191 path.lineTo(0, 0);
192 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000193 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000194}
195
196static void testSimplifyTriangle15() {
197 SkPath path, out;
198 path.setFillType(SkPath::kEvenOdd_FillType);
199 path.moveTo(0, 0);
200 path.lineTo(0, 1);
201 path.lineTo(1, 2);
202 path.close();
203 path.moveTo(0, 0);
204 path.lineTo(0, 1);
205 path.lineTo(2, 2);
206 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000207 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000208}
209
210static void testSimplifyTriangle16() {
211 SkPath path, out;
212 path.moveTo(0, 0);
213 path.lineTo(0, 1);
214 path.lineTo(1, 2);
215 path.close();
216 path.moveTo(0, 0);
217 path.lineTo(0, 1);
218 path.lineTo(1, 3);
219 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000220 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000221}
222
223static void testSimplifyTriangle17() {
224 SkPath path, out;
225 path.moveTo(0, 0);
226 path.lineTo(0, 1);
227 path.lineTo(1, 2);
228 path.close();
229 path.moveTo(0, 0);
230 path.lineTo(1, 3);
231 path.lineTo(0, 1);
232 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000233 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000234}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000235
caryclark@google.com4917f172012-03-05 22:01:21 +0000236static void testSimplifyTriangle18() {
237 SkPath path, out;
238 path.moveTo(0, 0);
239 path.lineTo(0, 1);
240 path.lineTo(1, 2);
241 path.close();
242 path.moveTo(1, 0);
243 path.lineTo(0, 1);
244 path.lineTo(0, 3);
245 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000246 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000247}
248
249static void testSimplifyTriangle19() {
250 SkPath path, out;
251 path.setFillType(SkPath::kEvenOdd_FillType);
252 path.moveTo(0, 0);
253 path.lineTo(0, 1);
254 path.lineTo(3, 2);
255 path.close();
256 path.moveTo(0, 0);
257 path.lineTo(1, 1);
258 path.lineTo(2, 1);
259 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000260 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000261}
262
263static void testSimplifyTriangle20() {
264 SkPath path, out;
265 path.moveTo(0, 0);
266 path.lineTo(2, 1);
267 path.lineTo(1, 3);
268 path.close();
269 path.moveTo(2, 0);
270 path.lineTo(3, 2);
271 path.lineTo(0, 3);
272 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000273 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000274}
275
276static void testSimplifyTriangle21() {
277 SkPath path, out;
278 path.moveTo(0, 0);
279 path.lineTo(1, 0);
280 path.lineTo(1, 2);
281 path.close();
282 path.moveTo(2, 0);
283 path.lineTo(2, 1);
284 path.lineTo(0, 3);
285 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000286 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000287}
288
289static void testSimplifyDegenerateTriangle1() {
290 SkPath path, out;
291 path.moveTo(0, 0);
292 path.lineTo(0, 0);
293 path.lineTo(0, 0);
294 path.close();
295 path.moveTo(0, 0);
296 path.lineTo(0, 0);
297 path.lineTo(0, 0);
298 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000299 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000300}
301
302static void testSimplifyDegenerateTriangle2() {
303 SkPath path, out;
304 path.moveTo(0, 0);
305 path.lineTo(1, 1);
306 path.lineTo(2, 2);
307 path.close();
308 path.moveTo(1, 0);
309 path.lineTo(2, 2);
310 path.lineTo(3, 3);
311 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000312 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000313}
314
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000315static void testSimplifyWindingParallelogram() {
316 SkPath path, out;
317 path.setFillType(SkPath::kWinding_FillType);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000318 path.moveTo(20,10); // parallelogram _
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000319 path.lineTo(30,30); // \ \ .
320 path.lineTo(40,30); // \_\ .
321 path.lineTo(30,10);
322 path.close();
323 path.moveTo(20,10); // parallelogram _
324 path.lineTo(10,30); // / /
325 path.lineTo(20,30); // /_/
326 path.lineTo(30,10);
327 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000328 testSimplify(path, true, out, bitmap); // expect _
rmistry@google.comd6176b02012-08-23 18:14:13 +0000329 // / \ .
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000330} // /___\ .
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000331
332static void testSimplifyXorParallelogram() {
333 SkPath path, out;
334 path.setFillType(SkPath::kEvenOdd_FillType);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000335 path.moveTo(20,10); // parallelogram _
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000336 path.lineTo(30,30); // \ \ .
337 path.lineTo(40,30); // \_\ .
338 path.lineTo(30,10);
339 path.close();
340 path.moveTo(20,10); // parallelogram _
341 path.lineTo(10,30); // / /
342 path.lineTo(20,30); // /_/
343 path.lineTo(30,10);
344 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000345 testSimplify(path, true, out, bitmap); // expect _
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000346} // \ /
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000347
348static void testSimplifyTriangle2() {
349 SkPath path, out;
350 path.setFillType(SkPath::kWinding_FillType);
351 path.moveTo(10,10); // triangle |\ .
352 path.lineTo(10,30); // |_\ .
353 path.lineTo(20,30);
354 path.close();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000355 path.moveTo(10,10); // triangle _
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000356 path.lineTo(20,10); // \ |
357 path.lineTo(20,30); // \|
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000358 path.close(); // _
caryclark@google.com198e0542012-03-30 18:47:02 +0000359 testSimplify(path, true, out, bitmap); // expect | |
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000360} // |_|
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000361
caryclark@google.com198e0542012-03-30 18:47:02 +0000362#if 0
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000363static void testPathTriangleRendering() {
364 SkPath one, two;
365 one.moveTo(0, 0);
366 one.lineTo(3, 3);
367 one.lineTo(0, 3);
368 one.lineTo(1, 2);
369 one.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000370 for (float x = .1f; x <= 2.9ff; x += .1f) {
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000371 SkDebugf("%s x=%g\n", __FUNCTION__, x);
372 two.moveTo(0, 0);
373 two.lineTo(x, x);
374 two.lineTo(3, 3);
375 two.lineTo(0, 3);
376 two.lineTo(1, 2);
377 two.close();
378 comparePaths(one, two);
379 two.reset();
380 }
381}
caryclark@google.com198e0542012-03-30 18:47:02 +0000382#endif
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000383
caryclark@google.com752b60e2012-03-22 21:11:17 +0000384static void simplify(const char* functionName, const SkPath& path,
385 bool fill, SkPath& out) {
caryclark@google.com198e0542012-03-30 18:47:02 +0000386 if (false) SkDebugf("%s\n", functionName);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000387 simplify(path, fill, out);
388}
389
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000390static void testSimplifySkinnyTriangle1() {
391 for (int x = 1; x < 255; ++x) {
392 SkPath path, out;
393 path.moveTo((x * 101) % 10, 0);
394 path.lineTo((x * 91) % 10, 1000);
395 path.lineTo((x * 71) % 10, 2000);
396 path.lineTo((x * 51) % 10, 3000);
397 path.close();
398 path.moveTo((x * 101) % 20, 0);
399 path.lineTo((x * 91) % 20, 1000);
400 path.lineTo((x * 71) % 20, 2000);
401 path.lineTo((x * 51) % 20, 3000);
402 path.close();
403 path.moveTo((x * 101) % 30, 0);
404 path.lineTo((x * 91) % 30, 1000);
405 path.lineTo((x * 71) % 30, 2000);
406 path.lineTo((x * 51) % 30, 3000);
407 path.close();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000408 simplify(path, true, out);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000409 }
410}
411
412static void testSimplifySkinnyTriangle2() {
413 SkPath path, out;
414#if 01
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000415path.moveTo(591.091064f, 627.534851f);
416path.lineTo(541.088135f, 560.707642f);
417path.lineTo(491.085175f, 493.880310f);
418path.lineTo(441.082214f, 427.053101f);
419//path.lineTo(591.091064f, 627.534851f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000420path.close();
421#endif
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000422path.moveTo(317.093445f, 592.013306f);
423path.lineTo(366.316162f, 542.986572f);
424path.lineTo(416.051514f, 486.978577f);
425path.lineTo(465.786865f, 430.970581f);
426//path.lineTo(317.093445f, 592.013306f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000427path.close();
428#if 0
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000429path.moveTo(289.392517f, 517.138489f);
430path.lineTo(249.886078f, 508.598022f);
431path.lineTo(217.110916f, 450.916443f);
432path.lineTo(196.621033f, 394.917633f);
433//path.lineTo(289.392517f, 517.138489f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000434path.close();
435#endif
caryclark@google.com752b60e2012-03-22 21:11:17 +0000436 simplify(__FUNCTION__, path, true, out);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000437}
438
439static void testSimplifySkinnyTriangle3() {
440 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000441 path.moveTo(591, 627.534851f);
442 path.lineTo(541, 560.707642f);
443 path.lineTo(491, 493.880310f);
444 path.lineTo(441, 427.053101f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000445 path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000446 path.moveTo(317, 592.013306f);
447 path.lineTo(366, 542.986572f);
448 path.lineTo(416, 486.978577f);
449 path.lineTo(465, 430.970581f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000450 path.close();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000451 simplify(__FUNCTION__, path, true, out);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000452}
453
454static void testSimplifySkinnyTriangle4() {
455 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000456path.moveTo(572.655212f, 614.959961f);
457path.lineTo(524.618896f, 549.339600f);
458path.lineTo(476.582581f, 483.719269f);
459path.lineTo(428.546265f, 418.098938f);
460path.lineTo(572.655212f, 614.959961f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000461path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000462path.moveTo(312.166382f, 583.723083f);
463path.lineTo(361.047791f, 529.824219f);
464path.lineTo(409.929230f, 475.925354f);
465path.lineTo(458.810669f, 422.026520f);
466path.lineTo(312.166382f, 583.723083f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000467path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000468path.moveTo(278.742737f, 508.065643f);
469path.lineTo(241.475800f, 493.465118f);
470path.lineTo(210.344177f, 437.315125f);
471path.lineTo(197.019455f, 383.794556f);
472path.lineTo(278.742737f, 508.065643f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000473path.close();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000474 simplify(__FUNCTION__, path, true, out);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000475}
476
477static void testSimplifySkinnyTriangle5() {
478 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000479path.moveTo(554.690613f, 602.286072f);
480path.lineTo(508.590057f, 537.906250f);
481path.lineTo(462.489441f, 473.526520f);
482path.lineTo(416.388855f, 409.146729f);
483path.lineTo(554.690613f, 602.286072f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000484path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000485path.moveTo(307.216949f, 575.189270f);
486path.lineTo(355.826965f, 516.804688f);
487path.lineTo(403.815918f, 464.990753f);
488path.lineTo(451.804871f, 413.176819f);
489path.lineTo(307.216949f, 575.189270f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000490path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000491path.moveTo(271.998901f, 521.301025f);
492path.lineTo(234.619705f, 499.687683f);
493path.lineTo(203.059692f, 441.332336f);
494path.lineTo(195.994370f, 386.856506f);
495path.lineTo(271.998901f, 521.301025f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000496path.close();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000497 simplify(__FUNCTION__, path, true, out);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000498}
499
caryclark@google.com752b60e2012-03-22 21:11:17 +0000500static void testSimplifySkinnyTriangle6() {
501 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000502path.moveTo(591.091064f, 627.534851f);
503path.lineTo(541.088135f, 560.707642f);
504path.lineTo(491.085175f, 493.880310f);
505path.lineTo(441.082214f, 427.053101f);
506path.lineTo(591.091064f, 627.534851f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000507path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000508path.moveTo(317.093445f, 592.013306f);
509path.lineTo(366.316162f, 542.986572f);
510path.lineTo(416.051514f, 486.978577f);
511path.lineTo(465.786865f, 430.970581f);
512path.lineTo(317.093445f, 592.013306f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000513path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000514path.moveTo(289.392517f, 517.138489f);
515path.lineTo(249.886078f, 508.598022f);
516path.lineTo(217.110916f, 450.916443f);
517path.lineTo(196.621033f, 394.917633f);
518path.lineTo(289.392517f, 517.138489f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000519path.close();
520 simplify(__FUNCTION__, path, true, out);
521}
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000522
523static void testSimplifyTriangle22() {
524 SkPath path, out;
525 path.moveTo(0, 0);
526 path.lineTo(1, 0);
527 path.lineTo(0, 2);
528 path.close();
529 path.moveTo(1, 0);
530 path.lineTo(0, 2);
531 path.lineTo(0, 1);
532 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000533 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000534}
535
536static void testSimplifyTriangle23() {
537 SkPath path, out;
538 path.moveTo(0, 0);
539 path.lineTo(0, 0);
540 path.lineTo(0, 0);
541 path.close();
542 path.moveTo(0, 0);
543 path.lineTo(0, 1);
544 path.lineTo(1, 2);
545 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000546 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000547}
548
549static void testSimplifyTriangle24() {
550 SkPath path, out;
551 path.moveTo(0, 0);
552 path.lineTo(0, 0);
553 path.lineTo(0, 1);
554 path.close();
555 path.moveTo(0, 0);
556 path.lineTo(1, 0);
557 path.lineTo(0, 1);
558 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000559 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000560}
561
caryclark@google.com752b60e2012-03-22 21:11:17 +0000562static void testSimplifySkinnyTriangle7() {
563 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000564path.moveTo(487.502319f, 550.811279f);
565path.lineTo(448.826050f, 491.720123f);
566path.lineTo(410.149780f, 432.628967f);
567path.lineTo(371.473572f, 373.537781f);
568path.lineTo(487.502319f, 550.811279f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000569path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000570path.moveTo(295.817108f, 532.655579f);
571path.lineTo(342.896271f, 485.912292f);
572path.lineTo(389.975433f, 439.169006f);
573path.lineTo(437.054596f, 392.425781f);
574path.lineTo(295.817108f, 532.655579f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000575path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000576path.moveTo(239.726822f, 575.025269f);
577path.lineTo(204.117569f, 521.429688f);
578path.lineTo(171.275452f, 454.110382f);
579path.lineTo(193.328583f, 397.859497f);
580path.lineTo(239.726822f, 575.025269f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000581path.close();
582 simplify(__FUNCTION__, path, true, out);
583}
584
585static void testSimplifySkinnyTriangle8() {
586 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000587path.moveTo(441.943115f, 511.678040f);
588path.lineTo(408.487549f, 456.880920f);
589path.lineTo(375.031952f, 402.083801f);
590path.lineTo(341.576385f, 347.286682f);
591path.lineTo(441.943115f, 511.678040f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000592path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000593path.moveTo(297.548492f, 557.246704f);
594path.lineTo(350.768494f, 507.627014f);
595path.lineTo(403.988525f, 458.007385f);
596path.lineTo(457.208527f, 408.387695f);
597path.lineTo(297.548492f, 557.246704f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000598path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000599path.moveTo(209.857895f, 615.802979f);
600path.lineTo(178.249481f, 534.230347f);
601path.lineTo(144.905640f, 460.056824f);
602path.lineTo(192.953125f, 404.972900f);
603path.lineTo(209.857895f, 615.802979f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000604path.close();
605 simplify(__FUNCTION__, path, true, out);
606}
607
608static void testSimplifySkinnyTriangle9() {
609 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000610path.moveTo(439.867065f, 528.291931f);
611path.lineTo(405.413025f, 469.107178f);
612path.lineTo(370.958954f, 409.922363f);
613path.lineTo(336.504883f, 350.737610f);
614path.lineTo(439.867065f, 528.291931f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000615path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000616path.moveTo(298.922455f, 573.251953f);
617path.lineTo(356.360962f, 521.905090f);
618path.lineTo(413.799438f, 470.558228f);
619path.lineTo(471.237915f, 419.211365f);
620path.lineTo(298.922455f, 573.251953f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000621path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000622path.moveTo(187.200775f, 643.035156f);
623path.lineTo(159.713165f, 540.993774f);
624path.lineTo(126.257164f, 462.198517f);
625path.lineTo(193.534012f, 409.266235f);
626path.lineTo(187.200775f, 643.035156f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000627path.close();
628path.close();
629 simplify(__FUNCTION__, path, true, out);
630}
631
632static void testSimplifySkinnyTriangle10() {
633 SkPath path, out;
634#if 0
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000635path.moveTo(99.270325f, 239.365234f);
636path.lineTo(105.967056f, 173.361206f);
637path.lineTo(148.821381f, 141.309891f);
638path.lineTo(159.101013f, 189.235138f);
639path.lineTo(99.270325f, 239.365234f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000640path.close();
641#endif
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000642path.moveTo(213.673737f, 413.292938f);
643path.lineTo(225.200134f, 343.616821f);
644path.lineTo(236.726532f, 273.940704f);
645path.lineTo(219.386414f, 231.373322f);
646path.lineTo(213.673737f, 413.292938f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000647path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000648path.moveTo(43.485352f, 308.984497f);
649path.lineTo(122.610657f, 305.950134f);
650path.lineTo(201.735962f, 302.915802f);
651path.lineTo(280.861267f, 299.881470f);
652path.lineTo(43.485352f, 308.984497f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000653path.close();
654 simplify(__FUNCTION__, path, true, out);
655}
656
caryclark@google.comd88e0892012-03-27 13:23:51 +0000657static void testSimplifySkinnyTriangle11() {
658 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000659path.moveTo(-177.878387f, 265.368988f);
660path.lineTo(-254.415771f, 303.709961f);
661path.lineTo(-317.465363f, 271.325562f);
662path.lineTo(-374.520386f, 207.507660f);
663path.lineTo(-177.878387f, 265.368988f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000664path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000665path.moveTo(-63.582489f, -3.679123f);
666path.lineTo(-134.496841f, 26.434566f);
667path.lineTo(-205.411209f, 56.548256f);
668path.lineTo(-276.325562f, 86.661942f);
669path.lineTo(-63.582489f, -3.679123f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000670path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000671path.moveTo(-57.078423f, 162.633453f);
672path.lineTo(-95.963928f, 106.261139f);
673path.lineTo(-134.849457f, 49.888824f);
674path.lineTo(-173.734955f, -6.483480f);
675path.lineTo(-57.078423f, 162.633453f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000676path.close();
677 simplify(__FUNCTION__, path, true, out);
678}
679
680static void testSimplifySkinnyTriangle12() {
681 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000682path.moveTo(98.666489f, -94.295059f);
683path.lineTo(156.584320f, -61.939133f);
684path.lineTo(174.672974f, -12.343765f);
685path.lineTo(158.622345f, 52.028267f);
686path.lineTo(98.666489f, -94.295059f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000687path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000688path.moveTo(-133.225616f, -48.622055f);
689path.lineTo(-73.855499f, -10.375397f);
690path.lineTo(-14.485367f, 27.871277f);
691path.lineTo(44.884750f, 66.117935f);
692path.lineTo(-133.225616f, -48.622055f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000693path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000694path.moveTo( 9.030045f, -163.413132f);
695path.lineTo(-19.605331f, -89.588760f);
696path.lineTo(-48.240707f, -15.764404f);
697path.lineTo(-76.876053f, 58.059944f);
698path.lineTo( 9.030045f, -163.413132f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000699path.close();
700 simplify(__FUNCTION__, path, true, out);
701}
702
703static void testSimplifySkinnyTriangle13() {
704 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000705path.moveTo(340.41568f, -170.97171f);
706path.lineTo(418.846893f, -142.428329f);
707path.lineTo(497.278107f, -113.884933f);
708path.lineTo(449.18222f, -45.6723022f);
709path.lineTo(340.41568f, -170.97171f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000710path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000711path.moveTo(326.610535f, 34.0393639f);
712path.lineTo(371.334595f, -14.9620667f);
713path.lineTo(416.058624f, -63.9634857f);
714path.lineTo(460.782654f, -112.96492f);
715path.lineTo(326.610535f, 34.0393639f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000716path.close();
717 simplify(__FUNCTION__, path, true, out);
718}
719
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000720static void (*simplifyTests[])() = {
caryclark@google.comd88e0892012-03-27 13:23:51 +0000721 testSimplifySkinnyTriangle13,
722 testSimplifySkinnyTriangle12,
723 testSimplifySkinnyTriangle11,
caryclark@google.com752b60e2012-03-22 21:11:17 +0000724 testSimplifySkinnyTriangle10,
725 testSimplifySkinnyTriangle9,
726 testSimplifySkinnyTriangle8,
727 testSimplifySkinnyTriangle7,
728 testSimplifySkinnyTriangle6,
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000729 testSimplifySkinnyTriangle5,
730 testSimplifySkinnyTriangle4,
731 testSimplifySkinnyTriangle3,
732 testSimplifySkinnyTriangle2,
733 testSimplifySkinnyTriangle1,
734 testSimplifyTriangle24,
735 testSimplifyTriangle23,
736 testSimplifyTriangle22,
caryclark@google.com4917f172012-03-05 22:01:21 +0000737 testSimplifyDegenerateTriangle2,
738 testSimplifyDegenerateTriangle1,
739 testSimplifyTriangle21,
740 testSimplifyTriangle20,
741 testSimplifyTriangle19,
742 testSimplifyTriangle18,
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000743 testSimplifyTriangle17,
744 testSimplifyTriangle16,
745 testSimplifyTriangle15,
746 testSimplifyTriangle14,
747 testSimplifyTriangle13,
748 testSimplifyTriangle12,
749 testSimplifyTriangle11,
750 testSimplifyTriangle10,
751 testSimplifyTriangle7,
752 testSimplifyTriangle9,
753 testSimplifyTriangle8,
754 testSimplifyTriangle6,
755 testSimplifyTriangle5,
756 testSimplifyTriangle4,
757 testSimplifyTriangle3,
758 testSimplifyTriangle,
759 testSimplifyTriangle2,
760 testSimplifyWindingParallelogram,
761 testSimplifyXorParallelogram,
caryclark@google.com198e0542012-03-30 18:47:02 +0000762// testPathTriangleRendering,
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000763};
764
765static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]);
766
caryclark@google.coma5764232012-03-28 16:20:21 +0000767static void (*firstTest)() = testSimplifySkinnyTriangle12;
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000768
769void SimplifyPolygonPaths_Test() {
770 size_t index = 0;
771 if (firstTest) {
772 while (index < simplifyTestsCount && simplifyTests[index] != firstTest) {
773 ++index;
774 }
775 }
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000776 bool firstTestComplete = false;
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000777 for ( ; index < simplifyTestsCount; ++index) {
778 (*simplifyTests[index])();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000779 if (simplifyTests[index] == testSimplifySkinnyTriangle2) {
caryclark@google.com198e0542012-03-30 18:47:02 +0000780 if (false) SkDebugf("%s last fast skinny test\n", __FUNCTION__);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000781 }
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000782 firstTestComplete = true;
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000783 }
784}
785