caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 1 | #include "EdgeWalker_Test.h" |
| 2 | #include "Intersection_Tests.h" |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 3 | |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 4 | static void* testSimplify4x4QuadralateralsMain(void* data) |
| 5 | { |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 6 | SkASSERT(data); |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 7 | State4& state = *(State4*) data; |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 8 | 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 | |
| 73 | void 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 | |
| 101 | static 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.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 128 | 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.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 133 | path.close(); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 134 | path.moveTo(dx, dy); |
| 135 | path.lineTo(ex, ey); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 136 | path.lineTo(fx, fy); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 137 | path.close(); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 138 | if (1) { |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 139 | 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.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 143 | str += sprintf(str, " path.close();\n"); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 144 | str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy); |
| 145 | str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 146 | str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 147 | str += sprintf(str, " path.close();\n"); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 148 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 149 | 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.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 153 | path.setFillType(SkPath::kEvenOdd_FillType); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 154 | outputProgress(state, pathStr, SkPath::kEvenOdd_FillType); |
| 155 | testSimplifyx(path, true, out, state, pathStr); |
| 156 | state.testsRun++; |
| 157 | #endif |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 158 | } |
| 159 | } |
| 160 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 161 | } while (runNextTestSet(state)); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 162 | return NULL; |
| 163 | } |
| 164 | |
| 165 | void SimplifyNondegenerate4x4TrianglesThreaded_Test() { |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 166 | 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.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 174 | 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.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 189 | testsRun += dispatchTest4(testSimplify4x4NondegeneratesMain, |
| 190 | a, b, c, 0); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 191 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 192 | if (!gRunTestsInOneThread) SkDebugf("."); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 193 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 194 | if (!gRunTestsInOneThread) SkDebugf("\n%d", a); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 195 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 196 | testsRun += waitForCompletion(); |
| 197 | SkDebugf("%s total tests run=%d\n", __FUNCTION__, testsRun); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 198 | } |
| 199 | |
| 200 | static void* testSimplify4x4DegeneratesMain(void* data) { |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 201 | SkASSERT(data); |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 202 | State4& state = *(State4*) data; |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 203 | 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.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 255 | } |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 256 | } |
| 257 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 258 | } while (runNextTestSet(state)); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 259 | return NULL; |
| 260 | } |
| 261 | |
| 262 | void SimplifyDegenerate4x4TrianglesThreaded_Test() { |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 263 | 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.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 271 | 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.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 280 | bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax); |
| 281 | testsRun += dispatchTest4(testSimplify4x4DegeneratesMain, |
| 282 | a, b, c, abcIsATriangle); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 283 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 284 | if (!gRunTestsInOneThread) SkDebugf("."); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 285 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 286 | if (!gRunTestsInOneThread) SkDebugf("\n%d", a); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 287 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame^] | 288 | testsRun += waitForCompletion(); |
| 289 | SkDebugf("%s total tests run=%d\n", __FUNCTION__, testsRun); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 290 | } |
| 291 | |