blob: 3cb90ab92776d241b9813b63887813c1e17ae10b [file] [log] [blame]
caryclark@google.coma461ff02012-10-11 12:54:23 +00001#include "EdgeWalker_Test.h"
2#include "Intersection_Tests.h"
3#include "ShapeOps.h"
4
5bool gShowOriginal = true;
6
7struct curve {
8 SkPath::Verb verb;
9 SkPoint pts[4];
10};
11
12struct curve test1[] = {
13{SkPath::kQuad_Verb, {{366.608826f, 151.196014f}, {378.803101f, 136.674606f}, {398.164948f, 136.674606f}}},
14{SkPath::kLine_Verb, {{354.009216f, 208.816208f}, {393.291473f, 102.232819f}}},
15{SkPath::kQuad_Verb, {{359.978058f, 136.581512f}, {378.315979f, 136.581512f}, {388.322723f, 149.613556f}}},
16{SkPath::kQuad_Verb, {{364.390686f, 157.898193f}, {375.281769f, 136.674606f}, {396.039917f, 136.674606f}}},
17{SkPath::kLine_Verb, {{396.039917f, 136.674606f}, {350, 120}}},
18{SkPath::kDone_Verb}
19};
20
caryclark@google.comf839c032012-10-26 21:03:50 +000021struct curve test2[] = {
22{SkPath::kQuad_Verb, {{366.608826f, 151.196014f}, {378.803101f, 136.674606f}, {398.164948f, 136.674606f}}},
23{SkPath::kQuad_Verb, {{359.978058f, 136.581512f}, {378.315979f, 136.581512f}, {388.322723f, 149.613556f}}},
24{SkPath::kQuad_Verb, {{364.390686f, 157.898193f}, {375.281769f, 136.674606f}, {396.039917f, 136.674606f}}},
25{SkPath::kDone_Verb}
26};
27
caryclark@google.coma461ff02012-10-11 12:54:23 +000028struct curve* testSet[] = {
caryclark@google.comf839c032012-10-26 21:03:50 +000029 test2,
caryclark@google.coma461ff02012-10-11 12:54:23 +000030 test1
31};
32
33size_t testSet_count = sizeof(testSet) / sizeof(testSet[0]);
34
35static void construct() {
36 for (size_t idx = 0; idx < testSet_count; ++idx) {
37 const curve* test = testSet[idx];
38 SkPath path;
39 bool pathComplete = false;
40 bool first = true;
41 do {
42 if (first) {
43 path.moveTo(test->pts[0].fX, test->pts[0].fY);
44 first = false;
45 } else if (test->verb != SkPath::kDone_Verb) {
46 path.lineTo(test->pts[0].fX, test->pts[0].fY);
47 }
48 switch (test->verb) {
49 case SkPath::kDone_Verb:
50 pathComplete = true;
51 break;
52 case SkPath::kLine_Verb:
53 path.lineTo(test->pts[1].fX, test->pts[1].fY);
54 break;
55 case SkPath::kQuad_Verb:
56 path.quadTo(test->pts[1].fX, test->pts[1].fY, test->pts[2].fX, test->pts[2].fY);
57 break;
58 case SkPath::kCubic_Verb:
59 path.cubicTo(test->pts[1].fX, test->pts[1].fY, test->pts[2].fX, test->pts[2].fY, test->pts[3].fX, test->pts[3].fY);
60 break;
caryclark@google.com9f3e9a52012-12-10 12:50:53 +000061 default:
62 SkASSERT(0);
caryclark@google.coma461ff02012-10-11 12:54:23 +000063 }
64 test++;
65 } while (!pathComplete);
66 path.close();
67 if (gShowOriginal) {
68 showPath(path, NULL);
69 SkDebugf("simplified:\n");
70 }
71 testSimplifyx(path);
72 }
73}
74
75static void (*tests[])() = {
76 construct,
77};
78
79static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
80
81static void (*firstTest)() = 0;
82static bool skipAll = false;
83
84void MiniSimplify_Test() {
85 if (skipAll) {
86 return;
87 }
88 size_t index = 0;
89 if (firstTest) {
90 while (index < testCount && tests[index] != firstTest) {
91 ++index;
92 }
93 }
94 bool firstTestComplete = false;
95 for ( ; index < testCount; ++index) {
96 (*tests[index])();
97 firstTestComplete = true;
98 }
99}