caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 1 | #include "EdgeWalker_Test.h" |
| 2 | #include "Intersection_Tests.h" |
| 3 | |
| 4 | static void testSimplifyTriangle() { |
| 5 | SkPath path, out; |
| 6 | path.setFillType(SkPath::kWinding_FillType); |
| 7 | path.moveTo(10,10); // triangle |\ . |
| 8 | path.lineTo(10,30); // |_\ . |
| 9 | path.lineTo(20,30); |
| 10 | path.close(); |
| 11 | path.moveTo(20,10); // triangle /| |
| 12 | path.lineTo(10,30); // /_| |
| 13 | path.lineTo(20,30); |
| 14 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 15 | testSimplify(path, true, out); // expect |\/| |
| 16 | // |__| |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 17 | } |
| 18 | |
| 19 | static void testSimplifyTriangle3() { |
| 20 | SkPath path, out; |
| 21 | path.moveTo(0, 0); |
| 22 | path.lineTo(1, 0); |
| 23 | path.lineTo(0, 1); |
| 24 | path.close(); |
| 25 | path.moveTo(0, 0); |
| 26 | path.lineTo(1, 0); |
| 27 | path.lineTo(3, 1); |
| 28 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 29 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 30 | } |
| 31 | |
| 32 | static void testSimplifyTriangle4() { |
| 33 | SkPath path, out; |
| 34 | path.moveTo(0, 0); |
| 35 | path.lineTo(1, 0); |
| 36 | path.lineTo(0, 1); |
| 37 | path.close(); |
| 38 | path.moveTo(0, 0); |
| 39 | path.lineTo(1, 0); |
| 40 | path.lineTo(2, 1); |
| 41 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 42 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 43 | } |
| 44 | |
| 45 | static void testSimplifyTriangle5() { |
| 46 | SkPath path, out; |
| 47 | path.moveTo(0, 0); |
| 48 | path.lineTo(1, 0); |
| 49 | path.lineTo(0, 1); |
| 50 | path.close(); |
| 51 | path.moveTo(0, 0); |
| 52 | path.lineTo(1, 1); |
| 53 | path.lineTo(2, 1); |
| 54 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 55 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | static void testSimplifyTriangle6() { |
| 59 | SkPath path, out; |
| 60 | path.moveTo(0, 0); |
| 61 | path.lineTo(1, 0); |
| 62 | path.lineTo(0, 1); |
| 63 | path.lineTo(0, 0); |
| 64 | path.close(); |
| 65 | path.moveTo(0, 0); |
| 66 | path.lineTo(0, 1); |
| 67 | path.lineTo(3, 1); |
| 68 | path.lineTo(0, 0); |
| 69 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 70 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 71 | } |
| 72 | |
| 73 | static void testSimplifyTriangle7() { |
| 74 | SkPath path, out; |
| 75 | path.moveTo(0, 0); |
| 76 | path.lineTo(1, 0); |
| 77 | path.lineTo(0, 1); |
| 78 | path.lineTo(0, 0); |
| 79 | path.close(); |
| 80 | path.moveTo(0, 0); |
| 81 | path.lineTo(1, 1); |
| 82 | path.lineTo(0, 2); |
| 83 | path.lineTo(0, 0); |
| 84 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 85 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | static void testSimplifyTriangle8() { |
| 89 | SkPath path, out; |
| 90 | path.moveTo(0, 0); |
| 91 | path.lineTo(1, 0); |
| 92 | path.lineTo(0, 1); |
| 93 | path.lineTo(0, 0); |
| 94 | path.close(); |
| 95 | path.moveTo(0, 1); |
| 96 | path.lineTo(1, 2); |
| 97 | path.lineTo(1, 3); |
| 98 | path.lineTo(0, 1); |
| 99 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 100 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | static void testSimplifyTriangle9() { |
| 104 | SkPath path, out; |
| 105 | path.moveTo(0, 0); |
| 106 | path.lineTo(1, 0); |
| 107 | path.lineTo(1, 1); |
| 108 | path.lineTo(0, 0); |
| 109 | path.close(); |
| 110 | path.moveTo(0, 0); |
| 111 | path.lineTo(1, 1); |
| 112 | path.lineTo(2, 1); |
| 113 | path.lineTo(0, 0); |
| 114 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 115 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static void testSimplifyTriangle10() { |
| 119 | SkPath path, out; |
| 120 | path.moveTo(0, 0); |
| 121 | path.lineTo(1, 0); |
| 122 | path.lineTo(1, 1); |
| 123 | path.lineTo(0, 0); |
| 124 | path.close(); |
| 125 | path.moveTo(0, 0); |
| 126 | path.lineTo(2, 0); |
| 127 | path.lineTo(0, 1); |
| 128 | path.lineTo(0, 0); |
| 129 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 130 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | static void testSimplifyTriangle11() { |
| 134 | SkPath path, out; |
| 135 | path.moveTo(0, 0); |
| 136 | path.lineTo(1, 0); |
| 137 | path.lineTo(0, 2); |
| 138 | path.lineTo(0, 0); |
| 139 | path.close(); |
| 140 | path.moveTo(0, 0); |
| 141 | path.lineTo(2, 1); |
| 142 | path.lineTo(2, 2); |
| 143 | path.lineTo(0, 0); |
| 144 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 145 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 146 | } |
| 147 | |
| 148 | static void testSimplifyTriangle12() { |
| 149 | SkPath path, out; |
| 150 | path.moveTo(0, 0); |
| 151 | path.lineTo(1, 0); |
| 152 | path.lineTo(1, 2); |
| 153 | path.lineTo(0, 0); |
| 154 | path.close(); |
| 155 | path.moveTo(2, 0); |
| 156 | path.lineTo(0, 3); |
| 157 | path.lineTo(1, 1); |
| 158 | path.lineTo(2, 0); |
| 159 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 160 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 161 | } |
| 162 | |
| 163 | static void testSimplifyTriangle13() { |
| 164 | SkPath path, out; |
| 165 | path.moveTo(0, 0); |
| 166 | path.lineTo(1, 0); |
| 167 | path.lineTo(0, 3); |
| 168 | path.lineTo(0, 0); |
| 169 | path.close(); |
| 170 | path.moveTo(3, 0); |
| 171 | path.lineTo(0, 3); |
| 172 | path.lineTo(1, 1); |
| 173 | path.lineTo(3, 0); |
| 174 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 175 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | static void testSimplifyTriangle14() { |
| 179 | SkPath path, out; |
| 180 | path.moveTo(0, 0); |
| 181 | path.lineTo(1, 0); |
| 182 | path.lineTo(0, 1); |
| 183 | path.lineTo(0, 0); |
| 184 | path.close(); |
| 185 | path.moveTo(0, 0); |
| 186 | path.lineTo(1, 0); |
| 187 | path.lineTo(0, 1); |
| 188 | path.lineTo(0, 0); |
| 189 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 190 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 191 | } |
| 192 | |
| 193 | static void testSimplifyTriangle15() { |
| 194 | SkPath path, out; |
| 195 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 196 | path.moveTo(0, 0); |
| 197 | path.lineTo(0, 1); |
| 198 | path.lineTo(1, 2); |
| 199 | path.close(); |
| 200 | path.moveTo(0, 0); |
| 201 | path.lineTo(0, 1); |
| 202 | path.lineTo(2, 2); |
| 203 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 204 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | static void testSimplifyTriangle16() { |
| 208 | SkPath path, out; |
| 209 | path.moveTo(0, 0); |
| 210 | path.lineTo(0, 1); |
| 211 | path.lineTo(1, 2); |
| 212 | path.close(); |
| 213 | path.moveTo(0, 0); |
| 214 | path.lineTo(0, 1); |
| 215 | path.lineTo(1, 3); |
| 216 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 217 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 218 | } |
| 219 | |
| 220 | static void testSimplifyTriangle17() { |
| 221 | SkPath path, out; |
| 222 | path.moveTo(0, 0); |
| 223 | path.lineTo(0, 1); |
| 224 | path.lineTo(1, 2); |
| 225 | path.close(); |
| 226 | path.moveTo(0, 0); |
| 227 | path.lineTo(1, 3); |
| 228 | path.lineTo(0, 1); |
| 229 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 230 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 231 | } |
| 232 | |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 233 | static void testSimplifyTriangle18() { |
| 234 | SkPath path, out; |
| 235 | path.moveTo(0, 0); |
| 236 | path.lineTo(0, 1); |
| 237 | path.lineTo(1, 2); |
| 238 | path.close(); |
| 239 | path.moveTo(1, 0); |
| 240 | path.lineTo(0, 1); |
| 241 | path.lineTo(0, 3); |
| 242 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 243 | testSimplify(path, true, out); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | static void testSimplifyTriangle19() { |
| 247 | SkPath path, out; |
| 248 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 249 | path.moveTo(0, 0); |
| 250 | path.lineTo(0, 1); |
| 251 | path.lineTo(3, 2); |
| 252 | path.close(); |
| 253 | path.moveTo(0, 0); |
| 254 | path.lineTo(1, 1); |
| 255 | path.lineTo(2, 1); |
| 256 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 257 | testSimplify(path, true, out); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 258 | } |
| 259 | |
| 260 | static void testSimplifyTriangle20() { |
| 261 | SkPath path, out; |
| 262 | path.moveTo(0, 0); |
| 263 | path.lineTo(2, 1); |
| 264 | path.lineTo(1, 3); |
| 265 | path.close(); |
| 266 | path.moveTo(2, 0); |
| 267 | path.lineTo(3, 2); |
| 268 | path.lineTo(0, 3); |
| 269 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 270 | testSimplify(path, true, out); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | static void testSimplifyTriangle21() { |
| 274 | SkPath path, out; |
| 275 | path.moveTo(0, 0); |
| 276 | path.lineTo(1, 0); |
| 277 | path.lineTo(1, 2); |
| 278 | path.close(); |
| 279 | path.moveTo(2, 0); |
| 280 | path.lineTo(2, 1); |
| 281 | path.lineTo(0, 3); |
| 282 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 283 | testSimplify(path, true, out); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | static void testSimplifyDegenerateTriangle1() { |
| 287 | SkPath path, out; |
| 288 | path.moveTo(0, 0); |
| 289 | path.lineTo(0, 0); |
| 290 | path.lineTo(0, 0); |
| 291 | path.close(); |
| 292 | path.moveTo(0, 0); |
| 293 | path.lineTo(0, 0); |
| 294 | path.lineTo(0, 0); |
| 295 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 296 | testSimplify(path, true, out); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | static void testSimplifyDegenerateTriangle2() { |
| 300 | SkPath path, out; |
| 301 | path.moveTo(0, 0); |
| 302 | path.lineTo(1, 1); |
| 303 | path.lineTo(2, 2); |
| 304 | path.close(); |
| 305 | path.moveTo(1, 0); |
| 306 | path.lineTo(2, 2); |
| 307 | path.lineTo(3, 3); |
| 308 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 309 | testSimplify(path, true, out); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 310 | } |
| 311 | |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 312 | static void testSimplifyWindingParallelogram() { |
| 313 | SkPath path, out; |
| 314 | path.setFillType(SkPath::kWinding_FillType); |
| 315 | path.moveTo(20,10); // parallelogram _ |
| 316 | path.lineTo(30,30); // \ \ . |
| 317 | path.lineTo(40,30); // \_\ . |
| 318 | path.lineTo(30,10); |
| 319 | path.close(); |
| 320 | path.moveTo(20,10); // parallelogram _ |
| 321 | path.lineTo(10,30); // / / |
| 322 | path.lineTo(20,30); // /_/ |
| 323 | path.lineTo(30,10); |
| 324 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 325 | testSimplify(path, true, out); // expect _ |
| 326 | // / \ . |
| 327 | } // /___\ . |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 328 | |
| 329 | static void testSimplifyXorParallelogram() { |
| 330 | SkPath path, out; |
| 331 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 332 | path.moveTo(20,10); // parallelogram _ |
| 333 | path.lineTo(30,30); // \ \ . |
| 334 | path.lineTo(40,30); // \_\ . |
| 335 | path.lineTo(30,10); |
| 336 | path.close(); |
| 337 | path.moveTo(20,10); // parallelogram _ |
| 338 | path.lineTo(10,30); // / / |
| 339 | path.lineTo(20,30); // /_/ |
| 340 | path.lineTo(30,10); |
| 341 | path.close(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 342 | testSimplify(path, true, out); // expect _ |
| 343 | } // \ / |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 344 | |
| 345 | static void testSimplifyTriangle2() { |
| 346 | SkPath path, out; |
| 347 | path.setFillType(SkPath::kWinding_FillType); |
| 348 | path.moveTo(10,10); // triangle |\ . |
| 349 | path.lineTo(10,30); // |_\ . |
| 350 | path.lineTo(20,30); |
| 351 | path.close(); |
| 352 | path.moveTo(10,10); // triangle _ |
| 353 | path.lineTo(20,10); // \ | |
| 354 | path.lineTo(20,30); // \| |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 355 | path.close(); // _ |
| 356 | testSimplify(path, true, out); // expect | | |
| 357 | } // |_| |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 358 | |
| 359 | static void testSimplifyNondegenerate4x4Triangles() { |
| 360 | char pathStr[1024]; |
| 361 | bzero(pathStr, sizeof(pathStr)); |
| 362 | for (int a = 0; a < 15; ++a) { |
| 363 | int ax = a & 0x03; |
| 364 | int ay = a >> 2; |
| 365 | for (int b = a + 1; b < 16; ++b) { |
| 366 | int bx = b & 0x03; |
| 367 | int by = b >> 2; |
| 368 | for (int c = a + 1; c < 16; ++c) { |
| 369 | if (b == c) { |
| 370 | continue; |
| 371 | } |
| 372 | int cx = c & 0x03; |
| 373 | int cy = c >> 2; |
| 374 | if ((bx - ax) * (cy - ay) == (by - ay) * (cx - ax)) { |
| 375 | continue; |
| 376 | } |
| 377 | for (int d = 0; d < 15; ++d) { |
| 378 | int dx = d & 0x03; |
| 379 | int dy = d >> 2; |
| 380 | for (int e = d + 1; e < 16; ++e) { |
| 381 | int ex = e & 0x03; |
| 382 | int ey = e >> 2; |
| 383 | for (int f = d + 1; f < 16; ++f) { |
| 384 | if (e == f) { |
| 385 | continue; |
| 386 | } |
| 387 | int fx = f & 0x03; |
| 388 | int fy = f >> 2; |
| 389 | if ((ex - dx) * (fy - dy) == (ey - dy) * (fx - dx)) { |
| 390 | continue; |
| 391 | } |
| 392 | SkPath path, out; |
| 393 | path.setFillType(SkPath::kWinding_FillType); |
| 394 | path.moveTo(ax, ay); |
| 395 | path.lineTo(bx, by); |
| 396 | path.lineTo(cx, cy); |
| 397 | path.close(); |
| 398 | path.moveTo(dx, dy); |
| 399 | path.lineTo(ex, ey); |
| 400 | path.lineTo(fx, fy); |
| 401 | path.close(); |
| 402 | if (1) { |
| 403 | char* str = pathStr; |
| 404 | str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay); |
| 405 | str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by); |
| 406 | str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy); |
| 407 | str += sprintf(str, " path.close();\n"); |
| 408 | str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy); |
| 409 | str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey); |
| 410 | str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); |
| 411 | str += sprintf(str, " path.close();"); |
| 412 | } |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 413 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 414 | path.setFillType(SkPath::kEvenOdd_FillType); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 415 | testSimplify(path, true, out); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 416 | } |
| 417 | } |
| 418 | } |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | } |
| 423 | |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 424 | static void testSimplifyDegenerate4x4Triangles() { |
| 425 | char pathStr[1024]; |
| 426 | bzero(pathStr, sizeof(pathStr)); |
| 427 | for (int a = 0; a < 16; ++a) { |
| 428 | int ax = a & 0x03; |
| 429 | int ay = a >> 2; |
| 430 | for (int b = a ; b < 16; ++b) { |
| 431 | int bx = b & 0x03; |
| 432 | int by = b >> 2; |
| 433 | for (int c = a ; c < 16; ++c) { |
| 434 | int cx = c & 0x03; |
| 435 | int cy = c >> 2; |
| 436 | bool abcIsATriangle = (bx - ax) * (cy - ay) |
| 437 | != (by - ay) * (cx - ax); |
| 438 | for (int d = 0; d < 16; ++d) { |
| 439 | int dx = d & 0x03; |
| 440 | int dy = d >> 2; |
| 441 | for (int e = d ; e < 16; ++e) { |
| 442 | int ex = e & 0x03; |
| 443 | int ey = e >> 2; |
| 444 | for (int f = d ; f < 16; ++f) { |
| 445 | int fx = f & 0x03; |
| 446 | int fy = f >> 2; |
| 447 | if (abcIsATriangle && (ex - dx) * (fy - dy) |
| 448 | != (ey - dy) * (fx - dx)) { |
| 449 | continue; |
| 450 | } |
| 451 | SkPath path, out; |
| 452 | path.setFillType(SkPath::kWinding_FillType); |
| 453 | path.moveTo(ax, ay); |
| 454 | path.lineTo(bx, by); |
| 455 | path.lineTo(cx, cy); |
| 456 | path.close(); |
| 457 | path.moveTo(dx, dy); |
| 458 | path.lineTo(ex, ey); |
| 459 | path.lineTo(fx, fy); |
| 460 | path.close(); |
| 461 | if (1) { |
| 462 | char* str = pathStr; |
| 463 | str += sprintf(str, " path.moveTo(%d, %d);\n", ax, ay); |
| 464 | str += sprintf(str, " path.lineTo(%d, %d);\n", bx, by); |
| 465 | str += sprintf(str, " path.lineTo(%d, %d);\n", cx, cy); |
| 466 | str += sprintf(str, " path.close();\n"); |
| 467 | str += sprintf(str, " path.moveTo(%d, %d);\n", dx, dy); |
| 468 | str += sprintf(str, " path.lineTo(%d, %d);\n", ex, ey); |
| 469 | str += sprintf(str, " path.lineTo(%d, %d);\n", fx, fy); |
| 470 | str += sprintf(str, " path.close();"); |
| 471 | } |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 472 | testSimplify(path, true, out); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 473 | path.setFillType(SkPath::kEvenOdd_FillType); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 474 | testSimplify(path, true, out); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | } |
| 478 | } |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 483 | static void testPathTriangleRendering() { |
| 484 | SkPath one, two; |
| 485 | one.moveTo(0, 0); |
| 486 | one.lineTo(3, 3); |
| 487 | one.lineTo(0, 3); |
| 488 | one.lineTo(1, 2); |
| 489 | one.close(); |
| 490 | for (float x = .1f; x <= 2.9f; x += .1f) { |
| 491 | SkDebugf("%s x=%g\n", __FUNCTION__, x); |
| 492 | two.moveTo(0, 0); |
| 493 | two.lineTo(x, x); |
| 494 | two.lineTo(3, 3); |
| 495 | two.lineTo(0, 3); |
| 496 | two.lineTo(1, 2); |
| 497 | two.close(); |
| 498 | comparePaths(one, two); |
| 499 | two.reset(); |
| 500 | } |
| 501 | } |
| 502 | |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 503 | static void testSimplifySkinnyTriangle1() { |
| 504 | for (int x = 1; x < 255; ++x) { |
| 505 | SkPath path, out; |
| 506 | path.moveTo((x * 101) % 10, 0); |
| 507 | path.lineTo((x * 91) % 10, 1000); |
| 508 | path.lineTo((x * 71) % 10, 2000); |
| 509 | path.lineTo((x * 51) % 10, 3000); |
| 510 | path.close(); |
| 511 | path.moveTo((x * 101) % 20, 0); |
| 512 | path.lineTo((x * 91) % 20, 1000); |
| 513 | path.lineTo((x * 71) % 20, 2000); |
| 514 | path.lineTo((x * 51) % 20, 3000); |
| 515 | path.close(); |
| 516 | path.moveTo((x * 101) % 30, 0); |
| 517 | path.lineTo((x * 91) % 30, 1000); |
| 518 | path.lineTo((x * 71) % 30, 2000); |
| 519 | path.lineTo((x * 51) % 30, 3000); |
| 520 | path.close(); |
| 521 | testSimplify(path, true, out); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | static void testSimplifySkinnyTriangle2() { |
| 526 | SkPath path, out; |
| 527 | #if 01 |
| 528 | path.moveTo(591.091064, 627.534851); |
| 529 | path.lineTo(541.088135, 560.707642); |
| 530 | path.lineTo(491.085175, 493.880310); |
| 531 | path.lineTo(441.082214, 427.053101); |
| 532 | //path.lineTo(591.091064, 627.534851); |
| 533 | path.close(); |
| 534 | #endif |
| 535 | path.moveTo(317.093445, 592.013306); |
| 536 | path.lineTo(366.316162, 542.986572); |
| 537 | path.lineTo(416.051514, 486.978577); |
| 538 | path.lineTo(465.786865, 430.970581); |
| 539 | //path.lineTo(317.093445, 592.013306); |
| 540 | path.close(); |
| 541 | #if 0 |
| 542 | path.moveTo(289.392517, 517.138489); |
| 543 | path.lineTo(249.886078, 508.598022); |
| 544 | path.lineTo(217.110916, 450.916443); |
| 545 | path.lineTo(196.621033, 394.917633); |
| 546 | //path.lineTo(289.392517, 517.138489); |
| 547 | path.close(); |
| 548 | #endif |
| 549 | testSimplify(path, true, out); |
| 550 | } |
| 551 | |
| 552 | static void testSimplifySkinnyTriangle3() { |
| 553 | SkPath path, out; |
| 554 | path.moveTo(591, 627.534851); |
| 555 | path.lineTo(541, 560.707642); |
| 556 | path.lineTo(491, 493.880310); |
| 557 | path.lineTo(441, 427.053101); |
| 558 | path.close(); |
| 559 | path.moveTo(317, 592.013306); |
| 560 | path.lineTo(366, 542.986572); |
| 561 | path.lineTo(416, 486.978577); |
| 562 | path.lineTo(465, 430.970581); |
| 563 | path.close(); |
| 564 | testSimplify(path, true, out); |
| 565 | } |
| 566 | |
| 567 | static void testSimplifySkinnyTriangle4() { |
| 568 | SkPath path, out; |
| 569 | path.moveTo(572.655212, 614.959961); |
| 570 | path.lineTo(524.618896, 549.339600); |
| 571 | path.lineTo(476.582581, 483.719269); |
| 572 | path.lineTo(428.546265, 418.098938); |
| 573 | path.lineTo(572.655212, 614.959961); |
| 574 | path.close(); |
| 575 | path.moveTo(312.166382, 583.723083); |
| 576 | path.lineTo(361.047791, 529.824219); |
| 577 | path.lineTo(409.929230, 475.925354); |
| 578 | path.lineTo(458.810669, 422.026520); |
| 579 | path.lineTo(312.166382, 583.723083); |
| 580 | path.close(); |
| 581 | path.moveTo(278.742737, 508.065643); |
| 582 | path.lineTo(241.475800, 493.465118); |
| 583 | path.lineTo(210.344177, 437.315125); |
| 584 | path.lineTo(197.019455, 383.794556); |
| 585 | path.lineTo(278.742737, 508.065643); |
| 586 | path.close(); |
| 587 | testSimplify(path, true, out); |
| 588 | } |
| 589 | |
| 590 | static void testSimplifySkinnyTriangle5() { |
| 591 | SkPath path, out; |
| 592 | path.moveTo(554.690613, 602.286072); |
| 593 | path.lineTo(508.590057, 537.906250); |
| 594 | path.lineTo(462.489441, 473.526520); |
| 595 | path.lineTo(416.388855, 409.146729); |
| 596 | path.lineTo(554.690613, 602.286072); |
| 597 | path.close(); |
| 598 | path.moveTo(307.216949, 575.189270); |
| 599 | path.lineTo(355.826965, 516.804688); |
| 600 | path.lineTo(403.815918, 464.990753); |
| 601 | path.lineTo(451.804871, 413.176819); |
| 602 | path.lineTo(307.216949, 575.189270); |
| 603 | path.close(); |
| 604 | path.moveTo(271.998901, 521.301025); |
| 605 | path.lineTo(234.619705, 499.687683); |
| 606 | path.lineTo(203.059692, 441.332336); |
| 607 | path.lineTo(195.994370, 386.856506); |
| 608 | path.lineTo(271.998901, 521.301025); |
| 609 | path.close(); |
| 610 | testSimplify(path, true, out); |
| 611 | } |
| 612 | |
| 613 | |
| 614 | static void testSimplifyTriangle22() { |
| 615 | SkPath path, out; |
| 616 | path.moveTo(0, 0); |
| 617 | path.lineTo(1, 0); |
| 618 | path.lineTo(0, 2); |
| 619 | path.close(); |
| 620 | path.moveTo(1, 0); |
| 621 | path.lineTo(0, 2); |
| 622 | path.lineTo(0, 1); |
| 623 | path.close(); |
| 624 | testSimplify(path, true, out); |
| 625 | } |
| 626 | |
| 627 | static void testSimplifyTriangle23() { |
| 628 | SkPath path, out; |
| 629 | path.moveTo(0, 0); |
| 630 | path.lineTo(0, 0); |
| 631 | path.lineTo(0, 0); |
| 632 | path.close(); |
| 633 | path.moveTo(0, 0); |
| 634 | path.lineTo(0, 1); |
| 635 | path.lineTo(1, 2); |
| 636 | path.close(); |
| 637 | testSimplify(path, true, out); |
| 638 | } |
| 639 | |
| 640 | static void testSimplifyTriangle24() { |
| 641 | SkPath path, out; |
| 642 | path.moveTo(0, 0); |
| 643 | path.lineTo(0, 0); |
| 644 | path.lineTo(0, 1); |
| 645 | path.close(); |
| 646 | path.moveTo(0, 0); |
| 647 | path.lineTo(1, 0); |
| 648 | path.lineTo(0, 1); |
| 649 | path.close(); |
| 650 | testSimplify(path, true, out); |
| 651 | } |
| 652 | |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 653 | static void (*simplifyTests[])() = { |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 654 | testSimplifySkinnyTriangle5, |
| 655 | testSimplifySkinnyTriangle4, |
| 656 | testSimplifySkinnyTriangle3, |
| 657 | testSimplifySkinnyTriangle2, |
| 658 | testSimplifySkinnyTriangle1, |
| 659 | testSimplifyTriangle24, |
| 660 | testSimplifyTriangle23, |
| 661 | testSimplifyTriangle22, |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 662 | testSimplifyDegenerateTriangle2, |
| 663 | testSimplifyDegenerateTriangle1, |
| 664 | testSimplifyTriangle21, |
| 665 | testSimplifyTriangle20, |
| 666 | testSimplifyTriangle19, |
| 667 | testSimplifyTriangle18, |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 668 | testSimplifyTriangle17, |
| 669 | testSimplifyTriangle16, |
| 670 | testSimplifyTriangle15, |
| 671 | testSimplifyTriangle14, |
| 672 | testSimplifyTriangle13, |
| 673 | testSimplifyTriangle12, |
| 674 | testSimplifyTriangle11, |
| 675 | testSimplifyTriangle10, |
| 676 | testSimplifyTriangle7, |
| 677 | testSimplifyTriangle9, |
| 678 | testSimplifyTriangle8, |
| 679 | testSimplifyTriangle6, |
| 680 | testSimplifyTriangle5, |
| 681 | testSimplifyTriangle4, |
| 682 | testSimplifyTriangle3, |
| 683 | testSimplifyTriangle, |
| 684 | testSimplifyTriangle2, |
| 685 | testSimplifyWindingParallelogram, |
| 686 | testSimplifyXorParallelogram, |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 687 | testSimplifyDegenerate4x4Triangles, |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 688 | testSimplifyNondegenerate4x4Triangles, |
| 689 | testPathTriangleRendering, |
| 690 | }; |
| 691 | |
| 692 | static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]); |
| 693 | |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 694 | static void (*firstTest)() = testSimplifySkinnyTriangle4; |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 695 | |
| 696 | void SimplifyPolygonPaths_Test() { |
| 697 | size_t index = 0; |
| 698 | if (firstTest) { |
| 699 | while (index < simplifyTestsCount && simplifyTests[index] != firstTest) { |
| 700 | ++index; |
| 701 | } |
| 702 | } |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 703 | bool firstTestComplete = false; |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 704 | for ( ; index < simplifyTestsCount; ++index) { |
| 705 | (*simplifyTests[index])(); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame^] | 706 | firstTestComplete = true; |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 707 | } |
| 708 | } |
| 709 | |