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 | } |
caryclark@google.com | 24bec79 | 2012-08-20 12:43:57 +0000 | [diff] [blame] | 56 | outputProgress(state, pathStr, SkPath::kWinding_FillType); |
| 57 | testSimplifyx(path, false, out, state, pathStr); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 58 | state.testsRun++; |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 59 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 60 | outputProgress(state, pathStr, SkPath::kEvenOdd_FillType); |
| 61 | testSimplifyx(path, true, out, state, pathStr); |
| 62 | state.testsRun++; |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | } |
| 66 | } |
| 67 | } while (runNextTestSet(state)); |
| 68 | return NULL; |
| 69 | } |
| 70 | |
caryclark@google.com | 24bec79 | 2012-08-20 12:43:57 +0000 | [diff] [blame] | 71 | void Simplify4x4QuadralateralsThreaded_Test(int& testsRun) |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 72 | { |
| 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.com | 24bec79 | 2012-08-20 12:43:57 +0000 | [diff] [blame] | 80 | int testsStart = testsRun; |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 81 | for (int a = 0; a < 16; ++a) { |
| 82 | for (int b = a ; b < 16; ++b) { |
| 83 | for (int c = b ; c < 16; ++c) { |
| 84 | for (int d = c; d < 16; ++d) { |
| 85 | 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.com | 24bec79 | 2012-08-20 12:43:57 +0000 | [diff] [blame] | 95 | SkDebugf("%s tests=%d total=%d\n", __FUNCTION__, testsRun - testsStart, testsRun); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | |
| 99 | static 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.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 126 | 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.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 131 | path.close(); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 132 | path.moveTo(dx, dy); |
| 133 | path.lineTo(ex, ey); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 134 | path.lineTo(fx, fy); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 135 | path.close(); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 136 | if (1) { |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 137 | 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.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 141 | str += sprintf(str, " path.close();\n"); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 142 | str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy); |
| 143 | str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 144 | str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 145 | str += sprintf(str, " path.close();\n"); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 146 | } |
caryclark@google.com | 24bec79 | 2012-08-20 12:43:57 +0000 | [diff] [blame] | 147 | outputProgress(state, pathStr, SkPath::kWinding_FillType); |
| 148 | testSimplifyx(path, false, out, state, pathStr); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 149 | state.testsRun++; |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 150 | path.setFillType(SkPath::kEvenOdd_FillType); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 151 | outputProgress(state, pathStr, SkPath::kEvenOdd_FillType); |
| 152 | testSimplifyx(path, true, out, state, pathStr); |
| 153 | state.testsRun++; |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 154 | } |
| 155 | } |
| 156 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 157 | } while (runNextTestSet(state)); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 158 | return NULL; |
| 159 | } |
| 160 | |
caryclark@google.com | 24bec79 | 2012-08-20 12:43:57 +0000 | [diff] [blame] | 161 | void SimplifyNondegenerate4x4TrianglesThreaded_Test(int& testsRun) { |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 162 | 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.com | 24bec79 | 2012-08-20 12:43:57 +0000 | [diff] [blame] | 169 | int testsStart = testsRun; |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 170 | 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.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 185 | testsRun += dispatchTest4(testSimplify4x4NondegeneratesMain, |
| 186 | a, b, c, 0); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 187 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 188 | if (!gRunTestsInOneThread) SkDebugf("."); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 189 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 190 | if (!gRunTestsInOneThread) SkDebugf("\n%d", a); |
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 | testsRun += waitForCompletion(); |
caryclark@google.com | 24bec79 | 2012-08-20 12:43:57 +0000 | [diff] [blame] | 193 | SkDebugf("%s tests=%d total=%d\n", __FUNCTION__, testsRun - testsStart, testsRun); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static void* testSimplify4x4DegeneratesMain(void* data) { |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 197 | SkASSERT(data); |
caryclark@google.com | 78e1713 | 2012-04-17 11:40:34 +0000 | [diff] [blame] | 198 | State4& state = *(State4*) data; |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 199 | 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.com | 24bec79 | 2012-08-20 12:43:57 +0000 | [diff] [blame] | 242 | outputProgress(state, pathStr, SkPath::kWinding_FillType); |
| 243 | testSimplifyx(path, false, out, state, pathStr); |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 244 | state.testsRun++; |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 245 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 246 | outputProgress(state, pathStr, SkPath::kEvenOdd_FillType); |
| 247 | testSimplifyx(path, true, out, state, pathStr); |
| 248 | state.testsRun++; |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 249 | } |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 250 | } |
| 251 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 252 | } while (runNextTestSet(state)); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 253 | return NULL; |
| 254 | } |
| 255 | |
caryclark@google.com | 24bec79 | 2012-08-20 12:43:57 +0000 | [diff] [blame] | 256 | void SimplifyDegenerate4x4TrianglesThreaded_Test(int& testsRun) { |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 257 | 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.com | 24bec79 | 2012-08-20 12:43:57 +0000 | [diff] [blame] | 264 | int testsStart = testsRun; |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 265 | 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.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 274 | bool abcIsATriangle = (bx - ax) * (cy - ay) != (by - ay) * (cx - ax); |
| 275 | testsRun += dispatchTest4(testSimplify4x4DegeneratesMain, |
| 276 | a, b, c, abcIsATriangle); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 277 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 278 | if (!gRunTestsInOneThread) SkDebugf("."); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 279 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 280 | if (!gRunTestsInOneThread) SkDebugf("\n%d", a); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 281 | } |
caryclark@google.com | 59823f7 | 2012-08-09 18:17:47 +0000 | [diff] [blame] | 282 | testsRun += waitForCompletion(); |
caryclark@google.com | 24bec79 | 2012-08-20 12:43:57 +0000 | [diff] [blame] | 283 | SkDebugf("%s tests=%d total=%d\n", __FUNCTION__, testsRun - testsStart, testsRun); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 284 | } |
| 285 | |