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#include "EdgeWalker_Test.h"
8#include "Intersection_Tests.h"
9#include "SkBitmap.h"
10
11static SkBitmap bitmap;
12
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();
24    testSimplify(path, true, out, bitmap); // expect |\/|
25                                   //        |__|
26}
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();
38    testSimplify(path, true, out, bitmap);
39}
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();
51    testSimplify(path, true, out, bitmap);
52}
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();
64    testSimplify(path, true, out, bitmap);
65}
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();
79    testSimplify(path, true, out, bitmap);
80}
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();
94    testSimplify(path, true, out, bitmap);
95}
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();
109    testSimplify(path, true, out, bitmap);
110}
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();
124    testSimplify(path, true, out, bitmap);
125}
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();
139    testSimplify(path, true, out, bitmap);
140}
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();
154    testSimplify(path, true, out, bitmap);
155}
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();
169    testSimplify(path, true, out, bitmap);
170}
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();
184    testSimplify(path, true, out, bitmap);
185}
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();
199    testSimplify(path, true, out, bitmap);
200}
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();
213    testSimplify(path, true, out, bitmap);
214}
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();
226    testSimplify(path, true, out, bitmap);
227}
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();
239    testSimplify(path, true, out, bitmap);
240}
241
242static 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();
252    testSimplify(path, true, out, bitmap);
253}
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();
266    testSimplify(path, true, out, bitmap);
267}
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();
279    testSimplify(path, true, out, bitmap);
280}
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();
292    testSimplify(path, true, out, bitmap);
293}
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();
305    testSimplify(path, true, out, bitmap);
306}
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();
318    testSimplify(path, true, out, bitmap);
319}
320
321static void testSimplifyWindingParallelogram() {
322    SkPath path, out;
323    path.setFillType(SkPath::kWinding_FillType);
324    path.moveTo(20,10); // parallelogram  _
325    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();
334    testSimplify(path, true, out, bitmap); // expect   _
335                                   //         / \     .
336}                                  //        /___\    .
337
338static void testSimplifyXorParallelogram() {
339    SkPath path, out;
340    path.setFillType(SkPath::kEvenOdd_FillType);
341    path.moveTo(20,10); // parallelogram  _
342    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();
351    testSimplify(path, true, out, bitmap); // expect   _
352}                                  //         \ /
353
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();
361    path.moveTo(10,10); // triangle       _
362    path.lineTo(20,10); //               \ |
363    path.lineTo(20,30); //                \|
364    path.close();                  //         _
365    testSimplify(path, true, out, bitmap); // expect | |
366}                                  //        |_|
367
368#if 0
369static 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();
376    for (float x = .1f; x <= 2.9ff; x += .1f) {
377        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}
388#endif
389
390static void simplify(const char* functionName, const SkPath& path,
391        bool fill, SkPath& out) {
392    if (false) SkDebugf("%s\n", functionName);
393    simplify(path, fill, out);
394}
395
396static 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();
414        simplify(path, true, out);
415    }
416}
417
418static void testSimplifySkinnyTriangle2() {
419        SkPath path, out;
420#if 01
421path.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);
426path.close();
427#endif
428path.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);
433path.close();
434#if 0
435path.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);
440path.close();
441#endif
442    simplify(__FUNCTION__, path, true, out);
443}
444
445static void testSimplifySkinnyTriangle3() {
446        SkPath path, out;
447        path.moveTo(591, 627.534851f);
448        path.lineTo(541, 560.707642f);
449        path.lineTo(491, 493.880310f);
450        path.lineTo(441, 427.053101f);
451        path.close();
452        path.moveTo(317, 592.013306f);
453        path.lineTo(366, 542.986572f);
454        path.lineTo(416, 486.978577f);
455        path.lineTo(465, 430.970581f);
456        path.close();
457    simplify(__FUNCTION__, path, true, out);
458}
459
460static void testSimplifySkinnyTriangle4() {
461        SkPath path, out;
462path.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);
467path.close();
468path.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);
473path.close();
474path.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);
479path.close();
480    simplify(__FUNCTION__, path, true, out);
481}
482
483static void testSimplifySkinnyTriangle5() {
484        SkPath path, out;
485path.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);
490path.close();
491path.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);
496path.close();
497path.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);
502path.close();
503    simplify(__FUNCTION__, path, true, out);
504}
505
506static void testSimplifySkinnyTriangle6() {
507        SkPath path, out;
508path.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);
513path.close();
514path.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);
519path.close();
520path.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);
525path.close();
526    simplify(__FUNCTION__, path, true, out);
527}
528
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();
539    testSimplify(path, true, out, bitmap);
540}
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();
552    testSimplify(path, true, out, bitmap);
553}
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();
565    testSimplify(path, true, out, bitmap);
566}
567
568static void testSimplifySkinnyTriangle7() {
569        SkPath path, out;
570path.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);
575path.close();
576path.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);
581path.close();
582path.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);
587path.close();
588    simplify(__FUNCTION__, path, true, out);
589}
590
591static void testSimplifySkinnyTriangle8() {
592        SkPath path, out;
593path.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);
598path.close();
599path.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);
604path.close();
605path.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);
610path.close();
611    simplify(__FUNCTION__, path, true, out);
612}
613
614static void testSimplifySkinnyTriangle9() {
615        SkPath path, out;
616path.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);
621path.close();
622path.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);
627path.close();
628path.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);
633path.close();
634path.close();
635    simplify(__FUNCTION__, path, true, out);
636}
637
638static void testSimplifySkinnyTriangle10() {
639        SkPath path, out;
640#if 0
641path.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);
646path.close();
647#endif
648path.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);
653path.close();
654path.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);
659path.close();
660    simplify(__FUNCTION__, path, true, out);
661}
662
663static void testSimplifySkinnyTriangle11() {
664        SkPath path, out;
665path.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);
670path.close();
671path.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);
676path.close();
677path.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);
682path.close();
683    simplify(__FUNCTION__, path, true, out);
684}
685
686static void testSimplifySkinnyTriangle12() {
687        SkPath path, out;
688path.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);
693path.close();
694path.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);
699path.close();
700path.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);
705path.close();
706    simplify(__FUNCTION__, path, true, out);
707}
708
709static void testSimplifySkinnyTriangle13() {
710        SkPath path, out;
711path.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);
716path.close();
717path.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);
722path.close();
723    simplify(__FUNCTION__, path, true, out);
724}
725
726static void (*simplifyTests[])() = {
727    testSimplifySkinnyTriangle13,
728    testSimplifySkinnyTriangle12,
729    testSimplifySkinnyTriangle11,
730    testSimplifySkinnyTriangle10,
731    testSimplifySkinnyTriangle9,
732    testSimplifySkinnyTriangle8,
733    testSimplifySkinnyTriangle7,
734    testSimplifySkinnyTriangle6,
735    testSimplifySkinnyTriangle5,
736    testSimplifySkinnyTriangle4,
737    testSimplifySkinnyTriangle3,
738    testSimplifySkinnyTriangle2,
739    testSimplifySkinnyTriangle1,
740    testSimplifyTriangle24,
741    testSimplifyTriangle23,
742    testSimplifyTriangle22,
743    testSimplifyDegenerateTriangle2,
744    testSimplifyDegenerateTriangle1,
745    testSimplifyTriangle21,
746    testSimplifyTriangle20,
747    testSimplifyTriangle19,
748    testSimplifyTriangle18,
749    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,
768//    testPathTriangleRendering,
769};
770
771static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]);
772
773static void (*firstTest)() = testSimplifySkinnyTriangle12;
774
775void SimplifyPolygonPaths_Test() {
776    size_t index = 0;
777    if (firstTest) {
778        while (index < simplifyTestsCount && simplifyTests[index] != firstTest) {
779            ++index;
780        }
781    }
782    bool firstTestComplete = false;
783    for ( ; index < simplifyTestsCount; ++index) {
784        (*simplifyTests[index])();
785        if (simplifyTests[index] == testSimplifySkinnyTriangle2) {
786            if (false) SkDebugf("%s last fast skinny test\n", __FUNCTION__);
787        }
788        firstTestComplete = true;
789    }
790}
791