blob: 8cda8e6b565a83964e54c847def2a5889fcffb07 [file] [log] [blame]
caryclark@google.com9e49fb62012-08-27 14:11:33 +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 */
caryclark@google.comcd4421d2012-03-01 19:16:31 +00007#include "EdgeWalker_Test.h"
8#include "Intersection_Tests.h"
caryclark@google.com198e0542012-03-30 18:47:02 +00009#include "SkBitmap.h"
10
11static SkBitmap bitmap;
caryclark@google.comcd4421d2012-03-01 19:16:31 +000012
13static void testSimplifyTriangle() {
14 SkPath path, out;
15 path.setFillType(SkPath::kWinding_FillType);
16 path.moveTo(10,10); // triangle |\ .
17 path.lineTo(10,30); // |_\ .
18 path.lineTo(20,30);
19 path.close();
20 path.moveTo(20,10); // triangle /|
21 path.lineTo(10,30); // /_|
22 path.lineTo(20,30);
23 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000024 testSimplify(path, true, out, bitmap); // expect |\/|
rmistry@google.comd6176b02012-08-23 18:14:13 +000025 // |__|
caryclark@google.comcd4421d2012-03-01 19:16:31 +000026}
27
28static void testSimplifyTriangle3() {
29 SkPath path, out;
30 path.moveTo(0, 0);
31 path.lineTo(1, 0);
32 path.lineTo(0, 1);
33 path.close();
34 path.moveTo(0, 0);
35 path.lineTo(1, 0);
36 path.lineTo(3, 1);
37 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000038 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +000039}
40
41static void testSimplifyTriangle4() {
42 SkPath path, out;
43 path.moveTo(0, 0);
44 path.lineTo(1, 0);
45 path.lineTo(0, 1);
46 path.close();
47 path.moveTo(0, 0);
48 path.lineTo(1, 0);
49 path.lineTo(2, 1);
50 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000051 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +000052}
53
54static void testSimplifyTriangle5() {
55 SkPath path, out;
56 path.moveTo(0, 0);
57 path.lineTo(1, 0);
58 path.lineTo(0, 1);
59 path.close();
60 path.moveTo(0, 0);
61 path.lineTo(1, 1);
62 path.lineTo(2, 1);
63 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000064 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +000065}
66
67static void testSimplifyTriangle6() {
68 SkPath path, out;
69 path.moveTo(0, 0);
70 path.lineTo(1, 0);
71 path.lineTo(0, 1);
72 path.lineTo(0, 0);
73 path.close();
74 path.moveTo(0, 0);
75 path.lineTo(0, 1);
76 path.lineTo(3, 1);
77 path.lineTo(0, 0);
78 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000079 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +000080}
81
82static void testSimplifyTriangle7() {
83 SkPath path, out;
84 path.moveTo(0, 0);
85 path.lineTo(1, 0);
86 path.lineTo(0, 1);
87 path.lineTo(0, 0);
88 path.close();
89 path.moveTo(0, 0);
90 path.lineTo(1, 1);
91 path.lineTo(0, 2);
92 path.lineTo(0, 0);
93 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000094 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +000095}
96
97static void testSimplifyTriangle8() {
98 SkPath path, out;
99 path.moveTo(0, 0);
100 path.lineTo(1, 0);
101 path.lineTo(0, 1);
102 path.lineTo(0, 0);
103 path.close();
104 path.moveTo(0, 1);
105 path.lineTo(1, 2);
106 path.lineTo(1, 3);
107 path.lineTo(0, 1);
108 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000109 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000110}
111
112static void testSimplifyTriangle9() {
113 SkPath path, out;
114 path.moveTo(0, 0);
115 path.lineTo(1, 0);
116 path.lineTo(1, 1);
117 path.lineTo(0, 0);
118 path.close();
119 path.moveTo(0, 0);
120 path.lineTo(1, 1);
121 path.lineTo(2, 1);
122 path.lineTo(0, 0);
123 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000124 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000125}
126
127static void testSimplifyTriangle10() {
128 SkPath path, out;
129 path.moveTo(0, 0);
130 path.lineTo(1, 0);
131 path.lineTo(1, 1);
132 path.lineTo(0, 0);
133 path.close();
134 path.moveTo(0, 0);
135 path.lineTo(2, 0);
136 path.lineTo(0, 1);
137 path.lineTo(0, 0);
138 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000139 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000140}
141
142static void testSimplifyTriangle11() {
143 SkPath path, out;
144 path.moveTo(0, 0);
145 path.lineTo(1, 0);
146 path.lineTo(0, 2);
147 path.lineTo(0, 0);
148 path.close();
149 path.moveTo(0, 0);
150 path.lineTo(2, 1);
151 path.lineTo(2, 2);
152 path.lineTo(0, 0);
153 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000154 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000155}
156
157static void testSimplifyTriangle12() {
158 SkPath path, out;
159 path.moveTo(0, 0);
160 path.lineTo(1, 0);
161 path.lineTo(1, 2);
162 path.lineTo(0, 0);
163 path.close();
164 path.moveTo(2, 0);
165 path.lineTo(0, 3);
166 path.lineTo(1, 1);
167 path.lineTo(2, 0);
168 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000169 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000170}
171
172static void testSimplifyTriangle13() {
173 SkPath path, out;
174 path.moveTo(0, 0);
175 path.lineTo(1, 0);
176 path.lineTo(0, 3);
177 path.lineTo(0, 0);
178 path.close();
179 path.moveTo(3, 0);
180 path.lineTo(0, 3);
181 path.lineTo(1, 1);
182 path.lineTo(3, 0);
183 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000184 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000185}
186
187static void testSimplifyTriangle14() {
188 SkPath path, out;
189 path.moveTo(0, 0);
190 path.lineTo(1, 0);
191 path.lineTo(0, 1);
192 path.lineTo(0, 0);
193 path.close();
194 path.moveTo(0, 0);
195 path.lineTo(1, 0);
196 path.lineTo(0, 1);
197 path.lineTo(0, 0);
198 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000199 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000200}
201
202static void testSimplifyTriangle15() {
203 SkPath path, out;
204 path.setFillType(SkPath::kEvenOdd_FillType);
205 path.moveTo(0, 0);
206 path.lineTo(0, 1);
207 path.lineTo(1, 2);
208 path.close();
209 path.moveTo(0, 0);
210 path.lineTo(0, 1);
211 path.lineTo(2, 2);
212 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000213 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000214}
215
216static void testSimplifyTriangle16() {
217 SkPath path, out;
218 path.moveTo(0, 0);
219 path.lineTo(0, 1);
220 path.lineTo(1, 2);
221 path.close();
222 path.moveTo(0, 0);
223 path.lineTo(0, 1);
224 path.lineTo(1, 3);
225 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000226 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000227}
228
229static void testSimplifyTriangle17() {
230 SkPath path, out;
231 path.moveTo(0, 0);
232 path.lineTo(0, 1);
233 path.lineTo(1, 2);
234 path.close();
235 path.moveTo(0, 0);
236 path.lineTo(1, 3);
237 path.lineTo(0, 1);
238 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000239 testSimplify(path, true, out, bitmap);
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000240}
rmistry@google.comd6176b02012-08-23 18:14:13 +0000241
caryclark@google.com4917f172012-03-05 22:01:21 +0000242static void testSimplifyTriangle18() {
243 SkPath path, out;
244 path.moveTo(0, 0);
245 path.lineTo(0, 1);
246 path.lineTo(1, 2);
247 path.close();
248 path.moveTo(1, 0);
249 path.lineTo(0, 1);
250 path.lineTo(0, 3);
251 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000252 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000253}
254
255static void testSimplifyTriangle19() {
256 SkPath path, out;
257 path.setFillType(SkPath::kEvenOdd_FillType);
258 path.moveTo(0, 0);
259 path.lineTo(0, 1);
260 path.lineTo(3, 2);
261 path.close();
262 path.moveTo(0, 0);
263 path.lineTo(1, 1);
264 path.lineTo(2, 1);
265 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000266 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000267}
268
269static void testSimplifyTriangle20() {
270 SkPath path, out;
271 path.moveTo(0, 0);
272 path.lineTo(2, 1);
273 path.lineTo(1, 3);
274 path.close();
275 path.moveTo(2, 0);
276 path.lineTo(3, 2);
277 path.lineTo(0, 3);
278 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000279 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000280}
281
282static void testSimplifyTriangle21() {
283 SkPath path, out;
284 path.moveTo(0, 0);
285 path.lineTo(1, 0);
286 path.lineTo(1, 2);
287 path.close();
288 path.moveTo(2, 0);
289 path.lineTo(2, 1);
290 path.lineTo(0, 3);
291 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000292 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000293}
294
295static void testSimplifyDegenerateTriangle1() {
296 SkPath path, out;
297 path.moveTo(0, 0);
298 path.lineTo(0, 0);
299 path.lineTo(0, 0);
300 path.close();
301 path.moveTo(0, 0);
302 path.lineTo(0, 0);
303 path.lineTo(0, 0);
304 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000305 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000306}
307
308static void testSimplifyDegenerateTriangle2() {
309 SkPath path, out;
310 path.moveTo(0, 0);
311 path.lineTo(1, 1);
312 path.lineTo(2, 2);
313 path.close();
314 path.moveTo(1, 0);
315 path.lineTo(2, 2);
316 path.lineTo(3, 3);
317 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000318 testSimplify(path, true, out, bitmap);
caryclark@google.com4917f172012-03-05 22:01:21 +0000319}
320
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000321static void testSimplifyWindingParallelogram() {
322 SkPath path, out;
323 path.setFillType(SkPath::kWinding_FillType);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000324 path.moveTo(20,10); // parallelogram _
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000325 path.lineTo(30,30); // \ \ .
326 path.lineTo(40,30); // \_\ .
327 path.lineTo(30,10);
328 path.close();
329 path.moveTo(20,10); // parallelogram _
330 path.lineTo(10,30); // / /
331 path.lineTo(20,30); // /_/
332 path.lineTo(30,10);
333 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000334 testSimplify(path, true, out, bitmap); // expect _
rmistry@google.comd6176b02012-08-23 18:14:13 +0000335 // / \ .
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000336} // /___\ .
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000337
338static void testSimplifyXorParallelogram() {
339 SkPath path, out;
340 path.setFillType(SkPath::kEvenOdd_FillType);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000341 path.moveTo(20,10); // parallelogram _
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000342 path.lineTo(30,30); // \ \ .
343 path.lineTo(40,30); // \_\ .
344 path.lineTo(30,10);
345 path.close();
346 path.moveTo(20,10); // parallelogram _
347 path.lineTo(10,30); // / /
348 path.lineTo(20,30); // /_/
349 path.lineTo(30,10);
350 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000351 testSimplify(path, true, out, bitmap); // expect _
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000352} // \ /
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000353
354static void testSimplifyTriangle2() {
355 SkPath path, out;
356 path.setFillType(SkPath::kWinding_FillType);
357 path.moveTo(10,10); // triangle |\ .
358 path.lineTo(10,30); // |_\ .
359 path.lineTo(20,30);
360 path.close();
rmistry@google.comd6176b02012-08-23 18:14:13 +0000361 path.moveTo(10,10); // triangle _
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000362 path.lineTo(20,10); // \ |
363 path.lineTo(20,30); // \|
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000364 path.close(); // _
caryclark@google.com198e0542012-03-30 18:47:02 +0000365 testSimplify(path, true, out, bitmap); // expect | |
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000366} // |_|
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000367
caryclark@google.com198e0542012-03-30 18:47:02 +0000368#if 0
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000369static void testPathTriangleRendering() {
370 SkPath one, two;
371 one.moveTo(0, 0);
372 one.lineTo(3, 3);
373 one.lineTo(0, 3);
374 one.lineTo(1, 2);
375 one.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000376 for (float x = .1f; x <= 2.9ff; x += .1f) {
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000377 SkDebugf("%s x=%g\n", __FUNCTION__, x);
378 two.moveTo(0, 0);
379 two.lineTo(x, x);
380 two.lineTo(3, 3);
381 two.lineTo(0, 3);
382 two.lineTo(1, 2);
383 two.close();
384 comparePaths(one, two);
385 two.reset();
386 }
387}
caryclark@google.com198e0542012-03-30 18:47:02 +0000388#endif
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000389
caryclark@google.com752b60e2012-03-22 21:11:17 +0000390static void simplify(const char* functionName, const SkPath& path,
391 bool fill, SkPath& out) {
caryclark@google.com198e0542012-03-30 18:47:02 +0000392 if (false) SkDebugf("%s\n", functionName);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000393 simplify(path, fill, out);
394}
395
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000396static void testSimplifySkinnyTriangle1() {
397 for (int x = 1; x < 255; ++x) {
398 SkPath path, out;
399 path.moveTo((x * 101) % 10, 0);
400 path.lineTo((x * 91) % 10, 1000);
401 path.lineTo((x * 71) % 10, 2000);
402 path.lineTo((x * 51) % 10, 3000);
403 path.close();
404 path.moveTo((x * 101) % 20, 0);
405 path.lineTo((x * 91) % 20, 1000);
406 path.lineTo((x * 71) % 20, 2000);
407 path.lineTo((x * 51) % 20, 3000);
408 path.close();
409 path.moveTo((x * 101) % 30, 0);
410 path.lineTo((x * 91) % 30, 1000);
411 path.lineTo((x * 71) % 30, 2000);
412 path.lineTo((x * 51) % 30, 3000);
413 path.close();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000414 simplify(path, true, out);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000415 }
416}
417
418static void testSimplifySkinnyTriangle2() {
419 SkPath path, out;
420#if 01
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000421path.moveTo(591.091064f, 627.534851f);
422path.lineTo(541.088135f, 560.707642f);
423path.lineTo(491.085175f, 493.880310f);
424path.lineTo(441.082214f, 427.053101f);
425//path.lineTo(591.091064f, 627.534851f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000426path.close();
427#endif
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000428path.moveTo(317.093445f, 592.013306f);
429path.lineTo(366.316162f, 542.986572f);
430path.lineTo(416.051514f, 486.978577f);
431path.lineTo(465.786865f, 430.970581f);
432//path.lineTo(317.093445f, 592.013306f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000433path.close();
434#if 0
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000435path.moveTo(289.392517f, 517.138489f);
436path.lineTo(249.886078f, 508.598022f);
437path.lineTo(217.110916f, 450.916443f);
438path.lineTo(196.621033f, 394.917633f);
439//path.lineTo(289.392517f, 517.138489f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000440path.close();
441#endif
caryclark@google.com752b60e2012-03-22 21:11:17 +0000442 simplify(__FUNCTION__, path, true, out);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000443}
444
445static void testSimplifySkinnyTriangle3() {
446 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000447 path.moveTo(591, 627.534851f);
448 path.lineTo(541, 560.707642f);
449 path.lineTo(491, 493.880310f);
450 path.lineTo(441, 427.053101f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000451 path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000452 path.moveTo(317, 592.013306f);
453 path.lineTo(366, 542.986572f);
454 path.lineTo(416, 486.978577f);
455 path.lineTo(465, 430.970581f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000456 path.close();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000457 simplify(__FUNCTION__, path, true, out);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000458}
459
460static void testSimplifySkinnyTriangle4() {
461 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000462path.moveTo(572.655212f, 614.959961f);
463path.lineTo(524.618896f, 549.339600f);
464path.lineTo(476.582581f, 483.719269f);
465path.lineTo(428.546265f, 418.098938f);
466path.lineTo(572.655212f, 614.959961f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000467path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000468path.moveTo(312.166382f, 583.723083f);
469path.lineTo(361.047791f, 529.824219f);
470path.lineTo(409.929230f, 475.925354f);
471path.lineTo(458.810669f, 422.026520f);
472path.lineTo(312.166382f, 583.723083f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000473path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000474path.moveTo(278.742737f, 508.065643f);
475path.lineTo(241.475800f, 493.465118f);
476path.lineTo(210.344177f, 437.315125f);
477path.lineTo(197.019455f, 383.794556f);
478path.lineTo(278.742737f, 508.065643f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000479path.close();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000480 simplify(__FUNCTION__, path, true, out);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000481}
482
483static void testSimplifySkinnyTriangle5() {
484 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000485path.moveTo(554.690613f, 602.286072f);
486path.lineTo(508.590057f, 537.906250f);
487path.lineTo(462.489441f, 473.526520f);
488path.lineTo(416.388855f, 409.146729f);
489path.lineTo(554.690613f, 602.286072f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000490path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000491path.moveTo(307.216949f, 575.189270f);
492path.lineTo(355.826965f, 516.804688f);
493path.lineTo(403.815918f, 464.990753f);
494path.lineTo(451.804871f, 413.176819f);
495path.lineTo(307.216949f, 575.189270f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000496path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000497path.moveTo(271.998901f, 521.301025f);
498path.lineTo(234.619705f, 499.687683f);
499path.lineTo(203.059692f, 441.332336f);
500path.lineTo(195.994370f, 386.856506f);
501path.lineTo(271.998901f, 521.301025f);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000502path.close();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000503 simplify(__FUNCTION__, path, true, out);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000504}
505
caryclark@google.com752b60e2012-03-22 21:11:17 +0000506static void testSimplifySkinnyTriangle6() {
507 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000508path.moveTo(591.091064f, 627.534851f);
509path.lineTo(541.088135f, 560.707642f);
510path.lineTo(491.085175f, 493.880310f);
511path.lineTo(441.082214f, 427.053101f);
512path.lineTo(591.091064f, 627.534851f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000513path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000514path.moveTo(317.093445f, 592.013306f);
515path.lineTo(366.316162f, 542.986572f);
516path.lineTo(416.051514f, 486.978577f);
517path.lineTo(465.786865f, 430.970581f);
518path.lineTo(317.093445f, 592.013306f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000519path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000520path.moveTo(289.392517f, 517.138489f);
521path.lineTo(249.886078f, 508.598022f);
522path.lineTo(217.110916f, 450.916443f);
523path.lineTo(196.621033f, 394.917633f);
524path.lineTo(289.392517f, 517.138489f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000525path.close();
526 simplify(__FUNCTION__, path, true, out);
527}
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000528
529static void testSimplifyTriangle22() {
530 SkPath path, out;
531 path.moveTo(0, 0);
532 path.lineTo(1, 0);
533 path.lineTo(0, 2);
534 path.close();
535 path.moveTo(1, 0);
536 path.lineTo(0, 2);
537 path.lineTo(0, 1);
538 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000539 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000540}
541
542static void testSimplifyTriangle23() {
543 SkPath path, out;
544 path.moveTo(0, 0);
545 path.lineTo(0, 0);
546 path.lineTo(0, 0);
547 path.close();
548 path.moveTo(0, 0);
549 path.lineTo(0, 1);
550 path.lineTo(1, 2);
551 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000552 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000553}
554
555static void testSimplifyTriangle24() {
556 SkPath path, out;
557 path.moveTo(0, 0);
558 path.lineTo(0, 0);
559 path.lineTo(0, 1);
560 path.close();
561 path.moveTo(0, 0);
562 path.lineTo(1, 0);
563 path.lineTo(0, 1);
564 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +0000565 testSimplify(path, true, out, bitmap);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000566}
567
caryclark@google.com752b60e2012-03-22 21:11:17 +0000568static void testSimplifySkinnyTriangle7() {
569 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000570path.moveTo(487.502319f, 550.811279f);
571path.lineTo(448.826050f, 491.720123f);
572path.lineTo(410.149780f, 432.628967f);
573path.lineTo(371.473572f, 373.537781f);
574path.lineTo(487.502319f, 550.811279f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000575path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000576path.moveTo(295.817108f, 532.655579f);
577path.lineTo(342.896271f, 485.912292f);
578path.lineTo(389.975433f, 439.169006f);
579path.lineTo(437.054596f, 392.425781f);
580path.lineTo(295.817108f, 532.655579f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000581path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000582path.moveTo(239.726822f, 575.025269f);
583path.lineTo(204.117569f, 521.429688f);
584path.lineTo(171.275452f, 454.110382f);
585path.lineTo(193.328583f, 397.859497f);
586path.lineTo(239.726822f, 575.025269f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000587path.close();
588 simplify(__FUNCTION__, path, true, out);
589}
590
591static void testSimplifySkinnyTriangle8() {
592 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000593path.moveTo(441.943115f, 511.678040f);
594path.lineTo(408.487549f, 456.880920f);
595path.lineTo(375.031952f, 402.083801f);
596path.lineTo(341.576385f, 347.286682f);
597path.lineTo(441.943115f, 511.678040f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000598path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000599path.moveTo(297.548492f, 557.246704f);
600path.lineTo(350.768494f, 507.627014f);
601path.lineTo(403.988525f, 458.007385f);
602path.lineTo(457.208527f, 408.387695f);
603path.lineTo(297.548492f, 557.246704f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000604path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000605path.moveTo(209.857895f, 615.802979f);
606path.lineTo(178.249481f, 534.230347f);
607path.lineTo(144.905640f, 460.056824f);
608path.lineTo(192.953125f, 404.972900f);
609path.lineTo(209.857895f, 615.802979f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000610path.close();
611 simplify(__FUNCTION__, path, true, out);
612}
613
614static void testSimplifySkinnyTriangle9() {
615 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000616path.moveTo(439.867065f, 528.291931f);
617path.lineTo(405.413025f, 469.107178f);
618path.lineTo(370.958954f, 409.922363f);
619path.lineTo(336.504883f, 350.737610f);
620path.lineTo(439.867065f, 528.291931f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000621path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000622path.moveTo(298.922455f, 573.251953f);
623path.lineTo(356.360962f, 521.905090f);
624path.lineTo(413.799438f, 470.558228f);
625path.lineTo(471.237915f, 419.211365f);
626path.lineTo(298.922455f, 573.251953f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000627path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000628path.moveTo(187.200775f, 643.035156f);
629path.lineTo(159.713165f, 540.993774f);
630path.lineTo(126.257164f, 462.198517f);
631path.lineTo(193.534012f, 409.266235f);
632path.lineTo(187.200775f, 643.035156f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000633path.close();
634path.close();
635 simplify(__FUNCTION__, path, true, out);
636}
637
638static void testSimplifySkinnyTriangle10() {
639 SkPath path, out;
640#if 0
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000641path.moveTo(99.270325f, 239.365234f);
642path.lineTo(105.967056f, 173.361206f);
643path.lineTo(148.821381f, 141.309891f);
644path.lineTo(159.101013f, 189.235138f);
645path.lineTo(99.270325f, 239.365234f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000646path.close();
647#endif
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000648path.moveTo(213.673737f, 413.292938f);
649path.lineTo(225.200134f, 343.616821f);
650path.lineTo(236.726532f, 273.940704f);
651path.lineTo(219.386414f, 231.373322f);
652path.lineTo(213.673737f, 413.292938f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000653path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000654path.moveTo(43.485352f, 308.984497f);
655path.lineTo(122.610657f, 305.950134f);
656path.lineTo(201.735962f, 302.915802f);
657path.lineTo(280.861267f, 299.881470f);
658path.lineTo(43.485352f, 308.984497f);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000659path.close();
660 simplify(__FUNCTION__, path, true, out);
661}
662
caryclark@google.comd88e0892012-03-27 13:23:51 +0000663static void testSimplifySkinnyTriangle11() {
664 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000665path.moveTo(-177.878387f, 265.368988f);
666path.lineTo(-254.415771f, 303.709961f);
667path.lineTo(-317.465363f, 271.325562f);
668path.lineTo(-374.520386f, 207.507660f);
669path.lineTo(-177.878387f, 265.368988f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000670path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000671path.moveTo(-63.582489f, -3.679123f);
672path.lineTo(-134.496841f, 26.434566f);
673path.lineTo(-205.411209f, 56.548256f);
674path.lineTo(-276.325562f, 86.661942f);
675path.lineTo(-63.582489f, -3.679123f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000676path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000677path.moveTo(-57.078423f, 162.633453f);
678path.lineTo(-95.963928f, 106.261139f);
679path.lineTo(-134.849457f, 49.888824f);
680path.lineTo(-173.734955f, -6.483480f);
681path.lineTo(-57.078423f, 162.633453f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000682path.close();
683 simplify(__FUNCTION__, path, true, out);
684}
685
686static void testSimplifySkinnyTriangle12() {
687 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000688path.moveTo(98.666489f, -94.295059f);
689path.lineTo(156.584320f, -61.939133f);
690path.lineTo(174.672974f, -12.343765f);
691path.lineTo(158.622345f, 52.028267f);
692path.lineTo(98.666489f, -94.295059f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000693path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000694path.moveTo(-133.225616f, -48.622055f);
695path.lineTo(-73.855499f, -10.375397f);
696path.lineTo(-14.485367f, 27.871277f);
697path.lineTo(44.884750f, 66.117935f);
698path.lineTo(-133.225616f, -48.622055f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000699path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000700path.moveTo( 9.030045f, -163.413132f);
701path.lineTo(-19.605331f, -89.588760f);
702path.lineTo(-48.240707f, -15.764404f);
703path.lineTo(-76.876053f, 58.059944f);
704path.lineTo( 9.030045f, -163.413132f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000705path.close();
706 simplify(__FUNCTION__, path, true, out);
707}
708
709static void testSimplifySkinnyTriangle13() {
710 SkPath path, out;
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000711path.moveTo(340.41568f, -170.97171f);
712path.lineTo(418.846893f, -142.428329f);
713path.lineTo(497.278107f, -113.884933f);
714path.lineTo(449.18222f, -45.6723022f);
715path.lineTo(340.41568f, -170.97171f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000716path.close();
caryclark@google.comb45a1b42012-05-18 20:50:33 +0000717path.moveTo(326.610535f, 34.0393639f);
718path.lineTo(371.334595f, -14.9620667f);
719path.lineTo(416.058624f, -63.9634857f);
720path.lineTo(460.782654f, -112.96492f);
721path.lineTo(326.610535f, 34.0393639f);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000722path.close();
723 simplify(__FUNCTION__, path, true, out);
724}
725
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000726static void (*simplifyTests[])() = {
caryclark@google.comd88e0892012-03-27 13:23:51 +0000727 testSimplifySkinnyTriangle13,
728 testSimplifySkinnyTriangle12,
729 testSimplifySkinnyTriangle11,
caryclark@google.com752b60e2012-03-22 21:11:17 +0000730 testSimplifySkinnyTriangle10,
731 testSimplifySkinnyTriangle9,
732 testSimplifySkinnyTriangle8,
733 testSimplifySkinnyTriangle7,
734 testSimplifySkinnyTriangle6,
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000735 testSimplifySkinnyTriangle5,
736 testSimplifySkinnyTriangle4,
737 testSimplifySkinnyTriangle3,
738 testSimplifySkinnyTriangle2,
739 testSimplifySkinnyTriangle1,
740 testSimplifyTriangle24,
741 testSimplifyTriangle23,
742 testSimplifyTriangle22,
caryclark@google.com4917f172012-03-05 22:01:21 +0000743 testSimplifyDegenerateTriangle2,
744 testSimplifyDegenerateTriangle1,
745 testSimplifyTriangle21,
746 testSimplifyTriangle20,
747 testSimplifyTriangle19,
748 testSimplifyTriangle18,
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000749 testSimplifyTriangle17,
750 testSimplifyTriangle16,
751 testSimplifyTriangle15,
752 testSimplifyTriangle14,
753 testSimplifyTriangle13,
754 testSimplifyTriangle12,
755 testSimplifyTriangle11,
756 testSimplifyTriangle10,
757 testSimplifyTriangle7,
758 testSimplifyTriangle9,
759 testSimplifyTriangle8,
760 testSimplifyTriangle6,
761 testSimplifyTriangle5,
762 testSimplifyTriangle4,
763 testSimplifyTriangle3,
764 testSimplifyTriangle,
765 testSimplifyTriangle2,
766 testSimplifyWindingParallelogram,
767 testSimplifyXorParallelogram,
caryclark@google.com198e0542012-03-30 18:47:02 +0000768// testPathTriangleRendering,
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000769};
770
771static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]);
772
caryclark@google.coma5764232012-03-28 16:20:21 +0000773static void (*firstTest)() = testSimplifySkinnyTriangle12;
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000774
775void SimplifyPolygonPaths_Test() {
776 size_t index = 0;
777 if (firstTest) {
778 while (index < simplifyTestsCount && simplifyTests[index] != firstTest) {
779 ++index;
780 }
781 }
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000782 bool firstTestComplete = false;
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000783 for ( ; index < simplifyTestsCount; ++index) {
784 (*simplifyTests[index])();
caryclark@google.com752b60e2012-03-22 21:11:17 +0000785 if (simplifyTests[index] == testSimplifySkinnyTriangle2) {
caryclark@google.com198e0542012-03-30 18:47:02 +0000786 if (false) SkDebugf("%s last fast skinny test\n", __FUNCTION__);
caryclark@google.com752b60e2012-03-22 21:11:17 +0000787 }
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000788 firstTestComplete = true;
caryclark@google.comcd4421d2012-03-01 19:16:31 +0000789 }
790}