blob: e795cd041016549d018f955df77251c8a7a15154 [file] [log] [blame]
caryclark@google.comd88e0892012-03-27 13:23:51 +00001#include "EdgeWalker_Test.h"
2#include "Intersection_Tests.h"
caryclark@google.com198e0542012-03-30 18:47:02 +00003
caryclark@google.comd88e0892012-03-27 13:23:51 +00004static void* testSimplify4x4QuadralateralsMain(void* data)
5{
caryclark@google.comd88e0892012-03-27 13:23:51 +00006 SkASSERT(data);
caryclark@google.com78e17132012-04-17 11:40:34 +00007 State4& state = *(State4*) data;
caryclark@google.com59823f72012-08-09 18:17:47 +00008 char pathStr[1024];
9 bzero(pathStr, sizeof(pathStr));
10 do {
11 int ax = state.a & 0x03;
12 int ay = state.a >> 2;
13 int bx = state.b & 0x03;
14 int by = state.b >> 2;
15 int cx = state.c & 0x03;
16 int cy = state.c >> 2;
17 int dx = state.d & 0x03;
18 int dy = state.d >> 2;
19 for (int e = 0 ; e < 16; ++e) {
20 int ex = e & 0x03;
21 int ey = e >> 2;
22 for (int f = e ; f < 16; ++f) {
23 int fx = f & 0x03;
24 int fy = f >> 2;
25 for (int g = f ; g < 16; ++g) {
26 int gx = g & 0x03;
27 int gy = g >> 2;
28 for (int h = g ; h < 16; ++h) {
29 int hx = h & 0x03;
30 int hy = h >> 2;
31 SkPath path, out;
32 path.setFillType(SkPath::kWinding_FillType);
33 path.moveTo(ax, ay);
34 path.lineTo(bx, by);
35 path.lineTo(cx, cy);
36 path.lineTo(dx, dy);
37 path.close();
38 path.moveTo(ex, ey);
39 path.lineTo(fx, fy);
40 path.lineTo(gx, gy);
41 path.lineTo(hx, hy);
42 path.close();
43 if (1) { // gdb: set print elements 400
44 char* str = pathStr;
45 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
46 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
47 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
48 str += sprintf(str, " path.lineTo(%d, %d);\n", dx, dy);
49 str += sprintf(str, " path.close();\n");
50 str += sprintf(str, " path.moveTo(%d, %d);\n", ex, ey);
51 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
52 str += sprintf(str, " path.lineTo(%d, %d);\n", gx, gy);
53 str += sprintf(str, " path.lineTo(%d, %d);\n", hx, hy);
54 str += sprintf(str, " path.close();\n");
55 }
56 outputProgress(state, pathStr);
57 testSimplifyx(path, out, state, pathStr);
58 state.testsRun++;
59 #if 0 // FIXME: enable once we have support for even/odd
60 path.setFillType(SkPath::kEvenOdd_FillType);
61 outputProgress(state, pathStr, SkPath::kEvenOdd_FillType);
62 testSimplifyx(path, true, out, state, pathStr);
63 state.testsRun++;
64 #endif
65 }
66 }
67 }
68 }
69 } while (runNextTestSet(state));
70 return NULL;
71}
72
73void Simplify4x4QuadralateralsThreaded_Test()
74{
75 SkDebugf("%s\n", __FUNCTION__);
76#ifdef SK_DEBUG
77 gDebugMaxWindSum = 4; // FIXME: 3?
78 gDebugMaxWindValue = 4;
79#endif
80 const char testStr[] = "testQuadralateral";
81 initializeTests(testStr, sizeof(testStr));
82 int testsRun = 0;
83 for (int a = 0; a < 16; ++a) {
84 for (int b = a ; b < 16; ++b) {
85 for (int c = b ; c < 16; ++c) {
86 for (int d = c; d < 16; ++d) {
87 testsRun += dispatchTest4(testSimplify4x4QuadralateralsMain,
88 a, b, c, d);
89 }
90 if (!gRunTestsInOneThread) SkDebugf(".");
91 }
92 if (!gRunTestsInOneThread) SkDebugf("%d", b);
93 }
94 if (!gRunTestsInOneThread) SkDebugf("\n%d", a);
95 }
96 testsRun += waitForCompletion();
97 SkDebugf("%s total tests run=%d\n", __FUNCTION__, testsRun);
98}
99
100
101static void* testSimplify4x4NondegeneratesMain(void* data) {
102 SkASSERT(data);
103 State4& state = *(State4*) data;
104 char pathStr[1024];
105 bzero(pathStr, sizeof(pathStr));
106 do {
107 int ax = state.a & 0x03;
108 int ay = state.a >> 2;
109 int bx = state.b & 0x03;
110 int by = state.b >> 2;
111 int cx = state.c & 0x03;
112 int cy = state.c >> 2;
113 for (int d = 0; d < 15; ++d) {
114 int dx = d & 0x03;
115 int dy = d >> 2;
116 for (int e = d + 1; e < 16; ++e) {
117 int ex = e & 0x03;
118 int ey = e >> 2;
119 for (int f = d + 1; f < 16; ++f) {
120 if (e == f) {
121 continue;
122 }
123 int fx = f & 0x03;
124 int fy = f >> 2;
125 if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) {
126 continue;
127 }
caryclark@google.comd88e0892012-03-27 13:23:51 +0000128 SkPath path, out;
129 path.setFillType(SkPath::kWinding_FillType);
130 path.moveTo(ax, ay);
131 path.lineTo(bx, by);
132 path.lineTo(cx, cy);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000133 path.close();
caryclark@google.com59823f72012-08-09 18:17:47 +0000134 path.moveTo(dx, dy);
135 path.lineTo(ex, ey);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000136 path.lineTo(fx, fy);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000137 path.close();
caryclark@google.com59823f72012-08-09 18:17:47 +0000138 if (1) {
caryclark@google.comd88e0892012-03-27 13:23:51 +0000139 char* str = pathStr;
140 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
141 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
142 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000143 str += sprintf(str, " path.close();\n");
caryclark@google.com59823f72012-08-09 18:17:47 +0000144 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
145 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000146 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
caryclark@google.com59823f72012-08-09 18:17:47 +0000147 str += sprintf(str, " path.close();\n");
caryclark@google.comd88e0892012-03-27 13:23:51 +0000148 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000149 outputProgress(state, pathStr);
150 testSimplifyx(path, out, state, pathStr);
151 state.testsRun++;
152 #if 0 // FIXME: enable once we have support for even/odd
caryclark@google.comd88e0892012-03-27 13:23:51 +0000153 path.setFillType(SkPath::kEvenOdd_FillType);
caryclark@google.com59823f72012-08-09 18:17:47 +0000154 outputProgress(state, pathStr, SkPath::kEvenOdd_FillType);
155 testSimplifyx(path, true, out, state, pathStr);
156 state.testsRun++;
157 #endif
caryclark@google.comd88e0892012-03-27 13:23:51 +0000158 }
159 }
160 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000161 } while (runNextTestSet(state));
caryclark@google.comd88e0892012-03-27 13:23:51 +0000162 return NULL;
163}
164
165void SimplifyNondegenerate4x4TrianglesThreaded_Test() {
caryclark@google.com59823f72012-08-09 18:17:47 +0000166 SkDebugf("%s\n", __FUNCTION__);
167#ifdef SK_DEBUG
168 gDebugMaxWindSum = 2;
169 gDebugMaxWindValue = 2;
170#endif
171 const char testStr[] = "testNondegenerate";
172 initializeTests(testStr, sizeof(testStr));
173 int testsRun = 0;
caryclark@google.comd88e0892012-03-27 13:23:51 +0000174 for (int a = 0; a < 15; ++a) {
175 int ax = a & 0x03;
176 int ay = a >> 2;
177 for (int b = a + 1; b < 16; ++b) {
178 int bx = b & 0x03;
179 int by = b >> 2;
180 for (int c = a + 1; c < 16; ++c) {
181 if (b == c) {
182 continue;
183 }
184 int cx = c & 0x03;
185 int cy = c >> 2;
186 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) {
187 continue;
188 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000189 testsRun += dispatchTest4(testSimplify4x4NondegeneratesMain,
190 a, b, c, 0);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000191 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000192 if (!gRunTestsInOneThread) SkDebugf(".");
caryclark@google.comd88e0892012-03-27 13:23:51 +0000193 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000194 if (!gRunTestsInOneThread) SkDebugf("\n%d", a);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000195 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000196 testsRun += waitForCompletion();
197 SkDebugf("%s total tests run=%d\n", __FUNCTION__, testsRun);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000198}
199
200static void* testSimplify4x4DegeneratesMain(void* data) {
caryclark@google.comd88e0892012-03-27 13:23:51 +0000201 SkASSERT(data);
caryclark@google.com78e17132012-04-17 11:40:34 +0000202 State4& state = *(State4*) data;
caryclark@google.com59823f72012-08-09 18:17:47 +0000203 char pathStr[1024];
204 bzero(pathStr, sizeof(pathStr));
205 do {
206 int ax = state.a & 0x03;
207 int ay = state.a >> 2;
208 int bx = state.b & 0x03;
209 int by = state.b >> 2;
210 int cx = state.c & 0x03;
211 int cy = state.c >> 2;
212 for (int d = 0; d < 16; ++d) {
213 int dx = d & 0x03;
214 int dy = d >> 2;
215 for (int e = d ; e < 16; ++e) {
216 int ex = e & 0x03;
217 int ey = e >> 2;
218 for (int f = d ; f < 16; ++f) {
219 int fx = f & 0x03;
220 int fy = f >> 2;
221 if (state.d && (ex - dx) * (fy - dy)
222 != (ey - dy) * (fx - dx)) {
223 continue;
224 }
225 SkPath path, out;
226 path.setFillType(SkPath::kWinding_FillType);
227 path.moveTo(ax, ay);
228 path.lineTo(bx, by);
229 path.lineTo(cx, cy);
230 path.close();
231 path.moveTo(dx, dy);
232 path.lineTo(ex, ey);
233 path.lineTo(fx, fy);
234 path.close();
235 if (1) {
236 char* str = pathStr;
237 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
238 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
239 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
240 str += sprintf(str, " path.close();\n");
241 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
242 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
243 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
244 str += sprintf(str, " path.close();\n");
245 }
246 outputProgress(state, pathStr);
247 testSimplifyx(path, out, state, pathStr);
248 state.testsRun++;
249 #if 0 // FIXME: enable once we have support for even/odd
250 path.setFillType(SkPath::kEvenOdd_FillType);
251 outputProgress(state, pathStr, SkPath::kEvenOdd_FillType);
252 testSimplifyx(path, true, out, state, pathStr);
253 state.testsRun++;
254 #endif
caryclark@google.comd88e0892012-03-27 13:23:51 +0000255 }
caryclark@google.comd88e0892012-03-27 13:23:51 +0000256 }
257 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000258 } while (runNextTestSet(state));
caryclark@google.comd88e0892012-03-27 13:23:51 +0000259 return NULL;
260}
261
262void SimplifyDegenerate4x4TrianglesThreaded_Test() {
caryclark@google.com59823f72012-08-09 18:17:47 +0000263 SkDebugf("%s\n", __FUNCTION__);
264#ifdef SK_DEBUG
265 gDebugMaxWindSum = 2;
266 gDebugMaxWindValue = 2;
267#endif
268 const char testStr[] = "testDegenerate";
269 initializeTests(testStr, sizeof(testStr));
270 int testsRun = 0;
caryclark@google.comd88e0892012-03-27 13:23:51 +0000271 for (int a = 0; a < 16; ++a) {
272 int ax = a & 0x03;
273 int ay = a >> 2;
274 for (int b = a ; b < 16; ++b) {
275 int bx = b & 0x03;
276 int by = b >> 2;
277 for (int c = a ; c < 16; ++c) {
278 int cx = c & 0x03;
279 int cy = c >> 2;
caryclark@google.com59823f72012-08-09 18:17:47 +0000280 bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax);
281 testsRun += dispatchTest4(testSimplify4x4DegeneratesMain,
282 a, b, c, abcIsATriangle);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000283 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000284 if (!gRunTestsInOneThread) SkDebugf(".");
caryclark@google.comd88e0892012-03-27 13:23:51 +0000285 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000286 if (!gRunTestsInOneThread) SkDebugf("\n%d", a);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000287 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000288 testsRun += waitForCompletion();
289 SkDebugf("%s total tests run=%d\n", __FUNCTION__, testsRun);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000290}
291