caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 1 | #include "EdgeWalker_Test.h" |
| 2 | #include "Intersection_Tests.h" |
| 3 | |
| 4 | static 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(); |
| 16 | simplify(path, true, out); |
| 17 | comparePaths(path, out); |
| 18 | } |
| 19 | |
| 20 | static void testSimplify4x4Quadralaterals() { |
| 21 | char pathStr[1024]; |
| 22 | bzero(pathStr, sizeof(pathStr)); |
| 23 | for (int a = 0; a < 16; ++a) { |
| 24 | int ax = a & 0x03; |
| 25 | int ay = a >> 2; |
| 26 | for (int b = a ; b < 16; ++b) { |
| 27 | int bx = b & 0x03; |
| 28 | int by = b >> 2; |
| 29 | for (int c = b ; c < 16; ++c) { |
| 30 | int cx = c & 0x03; |
| 31 | int cy = c >> 2; |
| 32 | for (int d = c; d < 16; ++d) { |
| 33 | int dx = d & 0x03; |
| 34 | int dy = d >> 2; |
| 35 | for (int e = 0 ; e < 16; ++e) { |
| 36 | int ex = e & 0x03; |
| 37 | int ey = e >> 2; |
| 38 | for (int f = e ; f < 16; ++f) { |
| 39 | int fx = f & 0x03; |
| 40 | int fy = f >> 2; |
| 41 | for (int g = f ; g < 16; ++g) { |
| 42 | int gx = g & 0x03; |
| 43 | int gy = g >> 2; |
| 44 | for (int h = g ; g < 16; ++g) { |
| 45 | int hx = h & 0x03; |
| 46 | int hy = h >> 2; |
| 47 | SkPath path, out; |
| 48 | path.setFillType(SkPath::kWinding_FillType); |
| 49 | path.moveTo(ax, ay); |
| 50 | path.lineTo(bx, by); |
| 51 | path.lineTo(cx, cy); |
| 52 | path.lineTo(dx, dy); |
| 53 | path.close(); |
| 54 | path.moveTo(ex, ey); |
| 55 | path.lineTo(fx, fy); |
| 56 | path.lineTo(gx, gy); |
| 57 | path.lineTo(hx, hy); |
| 58 | path.close(); |
| 59 | if (1) { |
| 60 | char* str = pathStr; |
| 61 | str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay); |
| 62 | str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by); |
| 63 | str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy); |
| 64 | str += sprintf(str, " path.lineTo(%d, %d);\n", dx, dy); |
| 65 | str += sprintf(str, " path.close();\n"); |
| 66 | str += sprintf(str, " path.moveTo(%d, %d);\n", ex, ey); |
| 67 | str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); |
| 68 | str += sprintf(str, " path.lineTo(%d, %d);\n", gx, gy); |
| 69 | str += sprintf(str, " path.lineTo(%d, %d);\n", hx, hy); |
| 70 | str += sprintf(str, " path.close();"); |
| 71 | } |
| 72 | simplify(path, true, out); |
| 73 | comparePaths(path, out); |
| 74 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 75 | simplify(path, true, out); |
| 76 | comparePaths(path, out); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | |
| 88 | |
| 89 | static void (*simplifyTests[])() = { |
| 90 | testSimplifyQuad1, |
| 91 | testSimplify4x4Quadralaterals, |
| 92 | }; |
| 93 | |
| 94 | static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]); |
| 95 | |
| 96 | static void (*firstTest)() = 0; |
| 97 | |
| 98 | void SimplifyQuadralateralPaths_Test() { |
| 99 | size_t index = 0; |
| 100 | if (firstTest) { |
| 101 | while (index < simplifyTestsCount && simplifyTests[index] != firstTest) { |
| 102 | ++index; |
| 103 | } |
| 104 | } |
| 105 | for ( ; index < simplifyTestsCount; ++index) { |
| 106 | (*simplifyTests[index])(); |
| 107 | } |
| 108 | } |