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(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 16 | testSimplify(path, true, out); |
| 17 | } |
| 18 | |
| 19 | static void testSimplifyQuad2() { |
| 20 | SkPath path, out; |
| 21 | path.moveTo(0, 0); |
| 22 | path.lineTo(0, 0); |
| 23 | path.lineTo(0, 0); |
| 24 | path.lineTo(0, 2); |
| 25 | path.close(); |
| 26 | path.moveTo(0, 1); |
| 27 | path.lineTo(0, 1); |
| 28 | path.lineTo(1, 1); |
| 29 | path.lineTo(0, 2); |
| 30 | path.close(); |
| 31 | testSimplify(path, true, out); |
| 32 | } |
| 33 | |
| 34 | static void testSimplifyQuad3() { |
| 35 | SkPath path, out; |
| 36 | path.moveTo(0, 0); |
| 37 | path.lineTo(0, 0); |
| 38 | path.lineTo(1, 0); |
| 39 | path.lineTo(1, 2); |
| 40 | path.close(); |
| 41 | path.moveTo(0, 1); |
| 42 | path.lineTo(1, 1); |
| 43 | path.lineTo(2, 1); |
| 44 | path.lineTo(0, 2); |
| 45 | path.close(); |
| 46 | testSimplify(path, true, out); |
| 47 | } |
| 48 | |
| 49 | static void testSimplifyQuad4() { |
| 50 | SkPath path, out; |
| 51 | path.moveTo(0, 0); |
| 52 | path.lineTo(0, 0); |
| 53 | path.lineTo(1, 0); |
| 54 | path.lineTo(2, 2); |
| 55 | path.close(); |
| 56 | path.moveTo(0, 0); |
| 57 | path.lineTo(2, 1); |
| 58 | path.lineTo(3, 1); |
| 59 | path.lineTo(3, 3); |
| 60 | path.close(); |
| 61 | testSimplify(path, true, out); |
| 62 | } |
| 63 | |
| 64 | static void testSimplifyQuad5() { |
| 65 | SkPath path, out; |
| 66 | path.moveTo(0, 0); |
| 67 | path.lineTo(0, 0); |
| 68 | path.lineTo(1, 0); |
| 69 | path.lineTo(3, 2); |
| 70 | path.close(); |
| 71 | path.moveTo(0, 1); |
| 72 | path.lineTo(1, 1); |
| 73 | path.lineTo(2, 1); |
| 74 | path.lineTo(0, 2); |
| 75 | path.close(); |
| 76 | testSimplify(path, true, out); |
| 77 | } |
| 78 | |
| 79 | static void testSimplifyQuad6() { |
| 80 | SkPath path, out; |
| 81 | path.moveTo(0, 0); |
| 82 | path.lineTo(1, 0); |
| 83 | path.lineTo(1, 1); |
| 84 | path.lineTo(3, 3); |
| 85 | path.close(); |
| 86 | path.moveTo(1, 1); |
| 87 | path.lineTo(1, 1); |
| 88 | path.lineTo(1, 1); |
| 89 | path.lineTo(2, 2); |
| 90 | path.close(); |
| 91 | testSimplify(path, true, out); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | static void testSimplify4x4Quadralaterals() { |
| 95 | char pathStr[1024]; |
| 96 | bzero(pathStr, sizeof(pathStr)); |
| 97 | for (int a = 0; a < 16; ++a) { |
| 98 | int ax = a & 0x03; |
| 99 | int ay = a >> 2; |
| 100 | for (int b = a ; b < 16; ++b) { |
| 101 | int bx = b & 0x03; |
| 102 | int by = b >> 2; |
| 103 | for (int c = b ; c < 16; ++c) { |
| 104 | int cx = c & 0x03; |
| 105 | int cy = c >> 2; |
| 106 | for (int d = c; d < 16; ++d) { |
| 107 | int dx = d & 0x03; |
| 108 | int dy = d >> 2; |
| 109 | for (int e = 0 ; e < 16; ++e) { |
| 110 | int ex = e & 0x03; |
| 111 | int ey = e >> 2; |
| 112 | for (int f = e ; f < 16; ++f) { |
| 113 | int fx = f & 0x03; |
| 114 | int fy = f >> 2; |
| 115 | for (int g = f ; g < 16; ++g) { |
| 116 | int gx = g & 0x03; |
| 117 | int gy = g >> 2; |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 118 | for (int h = g ; h < 16; ++h) { |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 119 | int hx = h & 0x03; |
| 120 | int hy = h >> 2; |
| 121 | SkPath path, out; |
| 122 | path.setFillType(SkPath::kWinding_FillType); |
| 123 | path.moveTo(ax, ay); |
| 124 | path.lineTo(bx, by); |
| 125 | path.lineTo(cx, cy); |
| 126 | path.lineTo(dx, dy); |
| 127 | path.close(); |
| 128 | path.moveTo(ex, ey); |
| 129 | path.lineTo(fx, fy); |
| 130 | path.lineTo(gx, gy); |
| 131 | path.lineTo(hx, hy); |
| 132 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 133 | if (1) { // gdb: set print elements 400 |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 134 | char* str = pathStr; |
| 135 | str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay); |
| 136 | str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by); |
| 137 | str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy); |
| 138 | str += sprintf(str, " path.lineTo(%d, %d);\n", dx, dy); |
| 139 | str += sprintf(str, " path.close();\n"); |
| 140 | str += sprintf(str, " path.moveTo(%d, %d);\n", ex, ey); |
| 141 | str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); |
| 142 | str += sprintf(str, " path.lineTo(%d, %d);\n", gx, gy); |
| 143 | str += sprintf(str, " path.lineTo(%d, %d);\n", hx, hy); |
| 144 | str += sprintf(str, " path.close();"); |
| 145 | } |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 146 | if (!testSimplify(path, true, out)) { |
| 147 | SkDebugf("*/\n{ SkPath::kWinding_FillType, %d, %d, %d, %d, %d, %d, %d, %d },\n/*\n", |
| 148 | a, b, c, d, e, f, g, h); |
| 149 | } |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 150 | path.setFillType(SkPath::kEvenOdd_FillType); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 151 | if (!testSimplify(path, true, out)) { |
| 152 | SkDebugf("*/\n{ SkPath::kEvenOdd_FillType, %d, %d, %d, %d, %d, %d, %d, %d },\n/*\n", |
| 153 | a, b, c, d, e, f, g, h); |
| 154 | } |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 155 | } |
| 156 | } |
| 157 | } |
| 158 | } |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | |
| 166 | |
| 167 | static void (*simplifyTests[])() = { |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 168 | testSimplifyQuad6, |
| 169 | testSimplifyQuad5, |
| 170 | testSimplifyQuad4, |
| 171 | testSimplifyQuad3, |
| 172 | testSimplifyQuad2, |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 173 | testSimplifyQuad1, |
| 174 | testSimplify4x4Quadralaterals, |
| 175 | }; |
| 176 | |
| 177 | static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]); |
| 178 | |
| 179 | static void (*firstTest)() = 0; |
| 180 | |
| 181 | void SimplifyQuadralateralPaths_Test() { |
| 182 | size_t index = 0; |
| 183 | if (firstTest) { |
| 184 | while (index < simplifyTestsCount && simplifyTests[index] != firstTest) { |
| 185 | ++index; |
| 186 | } |
| 187 | } |
| 188 | for ( ; index < simplifyTestsCount; ++index) { |
| 189 | (*simplifyTests[index])(); |
| 190 | } |
| 191 | } |