blob: 6cb24171a4bcf17a9bb3425f091f5b32d0edb8c2 [file] [log] [blame]
caryclark@google.com4917f172012-03-05 22:01:21 +00001#include "EdgeWalker_Test.h"
2#include "Intersection_Tests.h"
3
4static void testSimplifyQuad1() {
5 SkPath path, out;
6 path.moveTo(0, 0);
7 path.lineTo(1, 0);
8 path.lineTo(3, 2);
9 path.lineTo(3, 3);
10 path.close();
11 path.moveTo(1, 0);
12 path.lineTo(1, 3);
13 path.lineTo(1, 3);
14 path.lineTo(1, 3);
15 path.close();
caryclark@google.com2e7f4c82012-03-20 21:11:59 +000016 testSimplify(path, true, out);
17}
18
19static void testSimplifyQuad2() {
20 SkPath path, out;
21 path.moveTo(0, 0);
22 path.lineTo(0, 0);
23 path.lineTo(0, 0);
24 path.lineTo(0, 2);
25 path.close();
26 path.moveTo(0, 1);
27 path.lineTo(0, 1);
28 path.lineTo(1, 1);
29 path.lineTo(0, 2);
30 path.close();
31 testSimplify(path, true, out);
32}
33
34static void testSimplifyQuad3() {
35 SkPath path, out;
36 path.moveTo(0, 0);
37 path.lineTo(0, 0);
38 path.lineTo(1, 0);
39 path.lineTo(1, 2);
40 path.close();
41 path.moveTo(0, 1);
42 path.lineTo(1, 1);
43 path.lineTo(2, 1);
44 path.lineTo(0, 2);
45 path.close();
46 testSimplify(path, true, out);
47}
48
49static void testSimplifyQuad4() {
50 SkPath path, out;
51 path.moveTo(0, 0);
52 path.lineTo(0, 0);
53 path.lineTo(1, 0);
54 path.lineTo(2, 2);
55 path.close();
56 path.moveTo(0, 0);
57 path.lineTo(2, 1);
58 path.lineTo(3, 1);
59 path.lineTo(3, 3);
60 path.close();
61 testSimplify(path, true, out);
62}
63
64static void testSimplifyQuad5() {
65 SkPath path, out;
66 path.moveTo(0, 0);
67 path.lineTo(0, 0);
68 path.lineTo(1, 0);
69 path.lineTo(3, 2);
70 path.close();
71 path.moveTo(0, 1);
72 path.lineTo(1, 1);
73 path.lineTo(2, 1);
74 path.lineTo(0, 2);
75 path.close();
76 testSimplify(path, true, out);
77}
78
79static void testSimplifyQuad6() {
80 SkPath path, out;
81 path.moveTo(0, 0);
82 path.lineTo(1, 0);
83 path.lineTo(1, 1);
84 path.lineTo(3, 3);
85 path.close();
86 path.moveTo(1, 1);
87 path.lineTo(1, 1);
88 path.lineTo(1, 1);
89 path.lineTo(2, 2);
90 path.close();
91 testSimplify(path, true, out);
caryclark@google.com4917f172012-03-05 22:01:21 +000092}
93
94static void testSimplify4x4Quadralaterals() {
95 char pathStr[1024];
96 bzero(pathStr, sizeof(pathStr));
97 for (int a = 0; a < 16; ++a) {
98 int ax = a & 0x03;
99 int ay = a >> 2;
100 for (int b = a ; b < 16; ++b) {
101 int bx = b & 0x03;
102 int by = b >> 2;
103 for (int c = b ; c < 16; ++c) {
104 int cx = c & 0x03;
105 int cy = c >> 2;
106 for (int d = c; d < 16; ++d) {
107 int dx = d & 0x03;
108 int dy = d >> 2;
109 for (int e = 0 ; e < 16; ++e) {
110 int ex = e & 0x03;
111 int ey = e >> 2;
112 for (int f = e ; f < 16; ++f) {
113 int fx = f & 0x03;
114 int fy = f >> 2;
115 for (int g = f ; g < 16; ++g) {
116 int gx = g & 0x03;
117 int gy = g >> 2;
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000118 for (int h = g ; h < 16; ++h) {
caryclark@google.com4917f172012-03-05 22:01:21 +0000119 int hx = h & 0x03;
120 int hy = h >> 2;
121 SkPath path, out;
122 path.setFillType(SkPath::kWinding_FillType);
123 path.moveTo(ax, ay);
124 path.lineTo(bx, by);
125 path.lineTo(cx, cy);
126 path.lineTo(dx, dy);
127 path.close();
128 path.moveTo(ex, ey);
129 path.lineTo(fx, fy);
130 path.lineTo(gx, gy);
131 path.lineTo(hx, hy);
132 path.close();
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000133 if (1) { // gdb: set print elements 400
caryclark@google.com4917f172012-03-05 22:01:21 +0000134 char* str = pathStr;
135 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
136 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
137 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
138 str += sprintf(str, " path.lineTo(%d, %d);\n", dx, dy);
139 str += sprintf(str, " path.close();\n");
140 str += sprintf(str, " path.moveTo(%d, %d);\n", ex, ey);
141 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
142 str += sprintf(str, " path.lineTo(%d, %d);\n", gx, gy);
143 str += sprintf(str, " path.lineTo(%d, %d);\n", hx, hy);
144 str += sprintf(str, " path.close();");
145 }
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000146 if (!testSimplify(path, true, out)) {
147 SkDebugf("*/\n{ SkPath::kWinding_FillType, %d, %d, %d, %d, %d, %d, %d, %d },\n/*\n",
148 a, b, c, d, e, f, g, h);
149 }
caryclark@google.com4917f172012-03-05 22:01:21 +0000150 path.setFillType(SkPath::kEvenOdd_FillType);
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000151 if (!testSimplify(path, true, out)) {
152 SkDebugf("*/\n{ SkPath::kEvenOdd_FillType, %d, %d, %d, %d, %d, %d, %d, %d },\n/*\n",
153 a, b, c, d, e, f, g, h);
154 }
caryclark@google.com4917f172012-03-05 22:01:21 +0000155 }
156 }
157 }
158 }
159 }
160 }
161 }
162 }
163}
164
165
166
167static void (*simplifyTests[])() = {
caryclark@google.com2e7f4c82012-03-20 21:11:59 +0000168 testSimplifyQuad6,
169 testSimplifyQuad5,
170 testSimplifyQuad4,
171 testSimplifyQuad3,
172 testSimplifyQuad2,
caryclark@google.com4917f172012-03-05 22:01:21 +0000173 testSimplifyQuad1,
174 testSimplify4x4Quadralaterals,
175};
176
177static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]);
178
179static void (*firstTest)() = 0;
180
181void SimplifyQuadralateralPaths_Test() {
182 size_t index = 0;
183 if (firstTest) {
184 while (index < simplifyTestsCount && simplifyTests[index] != firstTest) {
185 ++index;
186 }
187 }
188 for ( ; index < simplifyTestsCount; ++index) {
189 (*simplifyTests[index])();
190 }
191}