blob: 624ef3880b2643a42850b523d7e622843b530c9c [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 }
caryclark@google.com24bec792012-08-20 12:43:57 +000056 outputProgress(state, pathStr, SkPath::kWinding_FillType);
57 testSimplifyx(path, false, out, state, pathStr);
caryclark@google.com59823f72012-08-09 18:17:47 +000058 state.testsRun++;
caryclark@google.com59823f72012-08-09 18:17:47 +000059 path.setFillType(SkPath::kEvenOdd_FillType);
60 outputProgress(state, pathStr, SkPath::kEvenOdd_FillType);
61 testSimplifyx(path, true, out, state, pathStr);
62 state.testsRun++;
caryclark@google.com59823f72012-08-09 18:17:47 +000063 }
64 }
65 }
66 }
67 } while (runNextTestSet(state));
68 return NULL;
69}
70
caryclark@google.com24bec792012-08-20 12:43:57 +000071void Simplify4x4QuadralateralsThreaded_Test(int& testsRun)
caryclark@google.com59823f72012-08-09 18:17:47 +000072{
73 SkDebugf("%s\n", __FUNCTION__);
74#ifdef SK_DEBUG
75 gDebugMaxWindSum = 4; // FIXME: 3?
76 gDebugMaxWindValue = 4;
77#endif
78 const char testStr[] = "testQuadralateral";
79 initializeTests(testStr, sizeof(testStr));
caryclark@google.com24bec792012-08-20 12:43:57 +000080 int testsStart = testsRun;
caryclark@google.com59823f72012-08-09 18:17:47 +000081 for (int a = 0; a < 16; ++a) {
82 for (int b = a ; b < 16; ++b) {
83 for (int c = b ; c < 16; ++c) {
rmistry@google.comd6176b02012-08-23 18:14:13 +000084 for (int d = c; d < 16; ++d) {
caryclark@google.com59823f72012-08-09 18:17:47 +000085 testsRun += dispatchTest4(testSimplify4x4QuadralateralsMain,
86 a, b, c, d);
87 }
88 if (!gRunTestsInOneThread) SkDebugf(".");
89 }
90 if (!gRunTestsInOneThread) SkDebugf("%d", b);
91 }
92 if (!gRunTestsInOneThread) SkDebugf("\n%d", a);
93 }
94 testsRun += waitForCompletion();
caryclark@google.com24bec792012-08-20 12:43:57 +000095 SkDebugf("%s tests=%d total=%d\n", __FUNCTION__, testsRun - testsStart, testsRun);
caryclark@google.com59823f72012-08-09 18:17:47 +000096}
97
98
99static void* testSimplify4x4NondegeneratesMain(void* data) {
100 SkASSERT(data);
101 State4& state = *(State4*) data;
102 char pathStr[1024];
103 bzero(pathStr, sizeof(pathStr));
104 do {
105 int ax = state.a & 0x03;
106 int ay = state.a >> 2;
107 int bx = state.b & 0x03;
108 int by = state.b >> 2;
109 int cx = state.c & 0x03;
110 int cy = state.c >> 2;
111 for (int d = 0; d < 15; ++d) {
112 int dx = d & 0x03;
113 int dy = d >> 2;
114 for (int e = d + 1; e < 16; ++e) {
115 int ex = e & 0x03;
116 int ey = e >> 2;
117 for (int f = d + 1; f < 16; ++f) {
118 if (e == f) {
119 continue;
120 }
121 int fx = f & 0x03;
122 int fy = f >> 2;
123 if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) {
124 continue;
125 }
caryclark@google.comd88e0892012-03-27 13:23:51 +0000126 SkPath path, out;
127 path.setFillType(SkPath::kWinding_FillType);
128 path.moveTo(ax, ay);
129 path.lineTo(bx, by);
130 path.lineTo(cx, cy);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000131 path.close();
caryclark@google.com59823f72012-08-09 18:17:47 +0000132 path.moveTo(dx, dy);
133 path.lineTo(ex, ey);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000134 path.lineTo(fx, fy);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000135 path.close();
caryclark@google.com59823f72012-08-09 18:17:47 +0000136 if (1) {
caryclark@google.comd88e0892012-03-27 13:23:51 +0000137 char* str = pathStr;
138 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
139 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
140 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000141 str += sprintf(str, " path.close();\n");
caryclark@google.com59823f72012-08-09 18:17:47 +0000142 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
143 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000144 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
caryclark@google.com59823f72012-08-09 18:17:47 +0000145 str += sprintf(str, " path.close();\n");
caryclark@google.comd88e0892012-03-27 13:23:51 +0000146 }
caryclark@google.com24bec792012-08-20 12:43:57 +0000147 outputProgress(state, pathStr, SkPath::kWinding_FillType);
148 testSimplifyx(path, false, out, state, pathStr);
caryclark@google.com59823f72012-08-09 18:17:47 +0000149 state.testsRun++;
caryclark@google.comd88e0892012-03-27 13:23:51 +0000150 path.setFillType(SkPath::kEvenOdd_FillType);
caryclark@google.com59823f72012-08-09 18:17:47 +0000151 outputProgress(state, pathStr, SkPath::kEvenOdd_FillType);
152 testSimplifyx(path, true, out, state, pathStr);
153 state.testsRun++;
caryclark@google.comd88e0892012-03-27 13:23:51 +0000154 }
155 }
156 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000157 } while (runNextTestSet(state));
caryclark@google.comd88e0892012-03-27 13:23:51 +0000158 return NULL;
159}
160
caryclark@google.com24bec792012-08-20 12:43:57 +0000161void SimplifyNondegenerate4x4TrianglesThreaded_Test(int& testsRun) {
caryclark@google.com59823f72012-08-09 18:17:47 +0000162 SkDebugf("%s\n", __FUNCTION__);
163#ifdef SK_DEBUG
164 gDebugMaxWindSum = 2;
165 gDebugMaxWindValue = 2;
166#endif
167 const char testStr[] = "testNondegenerate";
168 initializeTests(testStr, sizeof(testStr));
caryclark@google.com24bec792012-08-20 12:43:57 +0000169 int testsStart = testsRun;
caryclark@google.comd88e0892012-03-27 13:23:51 +0000170 for (int a = 0; a < 15; ++a) {
171 int ax = a & 0x03;
172 int ay = a >> 2;
173 for (int b = a + 1; b < 16; ++b) {
174 int bx = b & 0x03;
175 int by = b >> 2;
176 for (int c = a + 1; c < 16; ++c) {
177 if (b == c) {
178 continue;
179 }
180 int cx = c & 0x03;
181 int cy = c >> 2;
182 if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) {
183 continue;
184 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000185 testsRun += dispatchTest4(testSimplify4x4NondegeneratesMain,
186 a, b, c, 0);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000187 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000188 if (!gRunTestsInOneThread) SkDebugf(".");
caryclark@google.comd88e0892012-03-27 13:23:51 +0000189 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000190 if (!gRunTestsInOneThread) SkDebugf("\n%d", a);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000191 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000192 testsRun += waitForCompletion();
caryclark@google.com24bec792012-08-20 12:43:57 +0000193 SkDebugf("%s tests=%d total=%d\n", __FUNCTION__, testsRun - testsStart, testsRun);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000194}
195
196static void* testSimplify4x4DegeneratesMain(void* data) {
caryclark@google.comd88e0892012-03-27 13:23:51 +0000197 SkASSERT(data);
caryclark@google.com78e17132012-04-17 11:40:34 +0000198 State4& state = *(State4*) data;
caryclark@google.com59823f72012-08-09 18:17:47 +0000199 char pathStr[1024];
200 bzero(pathStr, sizeof(pathStr));
201 do {
202 int ax = state.a & 0x03;
203 int ay = state.a >> 2;
204 int bx = state.b & 0x03;
205 int by = state.b >> 2;
206 int cx = state.c & 0x03;
207 int cy = state.c >> 2;
208 for (int d = 0; d < 16; ++d) {
209 int dx = d & 0x03;
210 int dy = d >> 2;
211 for (int e = d ; e < 16; ++e) {
212 int ex = e & 0x03;
213 int ey = e >> 2;
214 for (int f = d ; f < 16; ++f) {
215 int fx = f & 0x03;
216 int fy = f >> 2;
217 if (state.d && (ex - dx) * (fy - dy)
218 != (ey - dy) * (fx - dx)) {
219 continue;
220 }
221 SkPath path, out;
222 path.setFillType(SkPath::kWinding_FillType);
223 path.moveTo(ax, ay);
224 path.lineTo(bx, by);
225 path.lineTo(cx, cy);
226 path.close();
227 path.moveTo(dx, dy);
228 path.lineTo(ex, ey);
229 path.lineTo(fx, fy);
230 path.close();
231 if (1) {
232 char* str = pathStr;
233 str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay);
234 str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by);
235 str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy);
236 str += sprintf(str, " path.close();\n");
237 str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy);
238 str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey);
239 str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy);
240 str += sprintf(str, " path.close();\n");
241 }
caryclark@google.com24bec792012-08-20 12:43:57 +0000242 outputProgress(state, pathStr, SkPath::kWinding_FillType);
243 testSimplifyx(path, false, out, state, pathStr);
caryclark@google.com59823f72012-08-09 18:17:47 +0000244 state.testsRun++;
caryclark@google.com59823f72012-08-09 18:17:47 +0000245 path.setFillType(SkPath::kEvenOdd_FillType);
246 outputProgress(state, pathStr, SkPath::kEvenOdd_FillType);
247 testSimplifyx(path, true, out, state, pathStr);
248 state.testsRun++;
caryclark@google.comd88e0892012-03-27 13:23:51 +0000249 }
caryclark@google.comd88e0892012-03-27 13:23:51 +0000250 }
251 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000252 } while (runNextTestSet(state));
caryclark@google.comd88e0892012-03-27 13:23:51 +0000253 return NULL;
254}
255
caryclark@google.com24bec792012-08-20 12:43:57 +0000256void SimplifyDegenerate4x4TrianglesThreaded_Test(int& testsRun) {
caryclark@google.com59823f72012-08-09 18:17:47 +0000257 SkDebugf("%s\n", __FUNCTION__);
258#ifdef SK_DEBUG
259 gDebugMaxWindSum = 2;
260 gDebugMaxWindValue = 2;
261#endif
262 const char testStr[] = "testDegenerate";
263 initializeTests(testStr, sizeof(testStr));
caryclark@google.com24bec792012-08-20 12:43:57 +0000264 int testsStart = testsRun;
caryclark@google.comd88e0892012-03-27 13:23:51 +0000265 for (int a = 0; a < 16; ++a) {
266 int ax = a & 0x03;
267 int ay = a >> 2;
268 for (int b = a ; b < 16; ++b) {
269 int bx = b & 0x03;
270 int by = b >> 2;
271 for (int c = a ; c < 16; ++c) {
272 int cx = c & 0x03;
273 int cy = c >> 2;
caryclark@google.com59823f72012-08-09 18:17:47 +0000274 bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax);
275 testsRun += dispatchTest4(testSimplify4x4DegeneratesMain,
276 a, b, c, abcIsATriangle);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000277 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000278 if (!gRunTestsInOneThread) SkDebugf(".");
caryclark@google.comd88e0892012-03-27 13:23:51 +0000279 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000280 if (!gRunTestsInOneThread) SkDebugf("\n%d", a);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000281 }
caryclark@google.com59823f72012-08-09 18:17:47 +0000282 testsRun += waitForCompletion();
caryclark@google.com24bec792012-08-20 12:43:57 +0000283 SkDebugf("%s tests=%d total=%d\n", __FUNCTION__, testsRun - testsStart, testsRun);
caryclark@google.comd88e0892012-03-27 13:23:51 +0000284}
285