blob: 6d6036c0ff298d243c10803ff1347c8d3f0eae09 [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;
61 }
62 test++;
63 } while (!pathComplete);
64 path.close();
65 if (gShowOriginal) {
66 showPath(path, NULL);
67 SkDebugf("simplified:\n");
68 }
69 testSimplifyx(path);
70 }
71}
72
73static void (*tests[])() = {
74 construct,
75};
76
77static const size_t testCount = sizeof(tests) / sizeof(tests[0]);
78
79static void (*firstTest)() = 0;
80static bool skipAll = false;
81
82void MiniSimplify_Test() {
83 if (skipAll) {
84 return;
85 }
86 size_t index = 0;
87 if (firstTest) {
88 while (index < testCount && tests[index] != firstTest) {
89 ++index;
90 }
91 }
92 bool firstTestComplete = false;
93 for ( ; index < testCount; ++index) {
94 (*tests[index])();
95 firstTestComplete = true;
96 }
97}