caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2012 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 8 | #include "EdgeWalker_Test.h" |
| 9 | #include "Intersection_Tests.h" |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 10 | #include "ShapeOps.h" |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 11 | |
| 12 | static void testLine1() { |
| 13 | SkPath path, simple; |
| 14 | path.moveTo(2,0); |
| 15 | path.lineTo(1,1); |
| 16 | path.lineTo(0,0); |
| 17 | path.close(); |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame] | 18 | testSimplifyx(path); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 19 | } |
| 20 | |
| 21 | static void addInnerCWTriangle(SkPath& path) { |
| 22 | path.moveTo(3,0); |
| 23 | path.lineTo(4,1); |
| 24 | path.lineTo(2,1); |
| 25 | path.close(); |
| 26 | } |
| 27 | |
| 28 | static void addInnerCCWTriangle(SkPath& path) { |
| 29 | path.moveTo(3,0); |
| 30 | path.lineTo(2,1); |
| 31 | path.lineTo(4,1); |
| 32 | path.close(); |
| 33 | } |
| 34 | |
| 35 | static void addOuterCWTriangle(SkPath& path) { |
| 36 | path.moveTo(3,0); |
| 37 | path.lineTo(6,2); |
| 38 | path.lineTo(0,2); |
| 39 | path.close(); |
| 40 | } |
| 41 | |
| 42 | static void addOuterCCWTriangle(SkPath& path) { |
| 43 | path.moveTo(3,0); |
| 44 | path.lineTo(0,2); |
| 45 | path.lineTo(6,2); |
| 46 | path.close(); |
| 47 | } |
| 48 | |
| 49 | static void testLine2() { |
| 50 | SkPath path, simple; |
| 51 | addInnerCWTriangle(path); |
| 52 | addOuterCWTriangle(path); |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame] | 53 | testSimplifyx(path); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 54 | } |
| 55 | |
caryclark@google.com | 495f8e4 | 2012-05-31 13:13:11 +0000 | [diff] [blame] | 56 | static void testLine3() { |
| 57 | SkPath path, simple; |
| 58 | addInnerCCWTriangle(path); |
| 59 | addOuterCWTriangle(path); |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame] | 60 | testSimplifyx(path); |
caryclark@google.com | 495f8e4 | 2012-05-31 13:13:11 +0000 | [diff] [blame] | 61 | } |
| 62 | |
| 63 | static void testLine4() { |
| 64 | SkPath path, simple; |
| 65 | addOuterCCWTriangle(path); |
| 66 | addOuterCWTriangle(path); |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame] | 67 | testSimplifyx(path); |
caryclark@google.com | 495f8e4 | 2012-05-31 13:13:11 +0000 | [diff] [blame] | 68 | } |
| 69 | |
| 70 | static void testLine5() { |
| 71 | SkPath path, simple; |
| 72 | addOuterCWTriangle(path); |
| 73 | addOuterCWTriangle(path); |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame] | 74 | testSimplifyx(path); |
caryclark@google.com | 495f8e4 | 2012-05-31 13:13:11 +0000 | [diff] [blame] | 75 | } |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 76 | |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame] | 77 | static void testLine6() { |
| 78 | SkPath path, simple; |
| 79 | path.moveTo(0,0); |
| 80 | path.lineTo(4,0); |
| 81 | path.lineTo(2,2); |
| 82 | path.close(); |
| 83 | path.moveTo(2,0); |
| 84 | path.lineTo(6,0); |
| 85 | path.lineTo(4,2); |
| 86 | path.close(); |
| 87 | testSimplifyx(path); |
| 88 | } |
| 89 | |
| 90 | static void testLine7() { |
| 91 | SkPath path, simple; |
| 92 | path.moveTo(0,0); |
| 93 | path.lineTo(4,0); |
| 94 | path.lineTo(2,2); |
| 95 | path.close(); |
| 96 | path.moveTo(6,0); |
| 97 | path.lineTo(2,0); |
| 98 | path.lineTo(4,2); |
| 99 | path.close(); |
| 100 | testSimplifyx(path); |
| 101 | } |
| 102 | |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 103 | static void testLine7a() { |
| 104 | SkPath path, simple; |
| 105 | path.moveTo(0,0); |
| 106 | path.lineTo(4,0); |
| 107 | path.lineTo(2,2); |
| 108 | path.close(); |
| 109 | testSimplifyx(path); |
| 110 | } |
| 111 | |
| 112 | static void testLine7b() { |
| 113 | SkPath path, simple; |
| 114 | path.moveTo(0,0); |
| 115 | path.lineTo(4,0); |
| 116 | path.close(); |
| 117 | path.moveTo(6,0); |
| 118 | path.lineTo(2,0); |
| 119 | path.lineTo(4,2); |
| 120 | path.close(); |
| 121 | testSimplifyx(path); |
| 122 | } |
| 123 | |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame] | 124 | static void testLine8() { |
| 125 | SkPath path, simple; |
| 126 | path.moveTo(0,4); |
| 127 | path.lineTo(4,4); |
| 128 | path.lineTo(2,2); |
| 129 | path.close(); |
| 130 | path.moveTo(2,4); |
| 131 | path.lineTo(6,4); |
| 132 | path.lineTo(4,2); |
| 133 | path.close(); |
| 134 | testSimplifyx(path); |
| 135 | } |
| 136 | |
| 137 | static void testLine9() { |
| 138 | SkPath path, simple; |
| 139 | path.moveTo(0,4); |
| 140 | path.lineTo(4,4); |
| 141 | path.lineTo(2,2); |
| 142 | path.close(); |
| 143 | path.moveTo(6,4); |
| 144 | path.lineTo(2,4); |
| 145 | path.lineTo(4,2); |
| 146 | path.close(); |
| 147 | testSimplifyx(path); |
| 148 | } |
| 149 | |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 150 | static void testLine10() { |
| 151 | SkPath path, simple; |
| 152 | path.moveTo(0,4); |
| 153 | path.lineTo(4,4); |
| 154 | path.lineTo(2,2); |
| 155 | path.close(); |
| 156 | path.moveTo(2,1); |
| 157 | path.lineTo(3,4); |
| 158 | path.lineTo(6,1); |
| 159 | path.close(); |
| 160 | testSimplifyx(path); |
| 161 | } |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame] | 162 | |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 163 | static void testLine10a() { |
| 164 | SkPath path, simple; |
| 165 | path.moveTo(0,4); |
| 166 | path.lineTo(8,4); |
| 167 | path.lineTo(4,0); |
| 168 | path.close(); |
| 169 | path.moveTo(2,2); |
| 170 | path.lineTo(3,3); |
| 171 | path.lineTo(4,2); |
| 172 | path.close(); |
| 173 | testSimplifyx(path); |
| 174 | } |
| 175 | |
| 176 | static void addCWContainer(SkPath& path) { |
| 177 | path.moveTo(6,4); |
| 178 | path.lineTo(0,4); |
| 179 | path.lineTo(3,1); |
| 180 | path.close(); |
| 181 | } |
| 182 | |
| 183 | static void addCCWContainer(SkPath& path) { |
| 184 | path.moveTo(0,4); |
| 185 | path.lineTo(6,4); |
| 186 | path.lineTo(3,1); |
| 187 | path.close(); |
| 188 | } |
| 189 | |
| 190 | static void addCWContents(SkPath& path) { |
| 191 | path.moveTo(2,3); |
| 192 | path.lineTo(3,2); |
| 193 | path.lineTo(4,3); |
| 194 | path.close(); |
| 195 | } |
| 196 | |
| 197 | static void addCCWContents(SkPath& path) { |
| 198 | path.moveTo(3,2); |
| 199 | path.lineTo(2,3); |
| 200 | path.lineTo(4,3); |
| 201 | path.close(); |
| 202 | } |
| 203 | |
| 204 | static void testLine11() { |
| 205 | SkPath path, simple; |
| 206 | addCWContainer(path); |
| 207 | addCWContents(path); |
| 208 | testSimplifyx(path); |
| 209 | } |
| 210 | |
| 211 | static void testLine12() { |
| 212 | SkPath path, simple; |
| 213 | addCCWContainer(path); |
| 214 | addCWContents(path); |
| 215 | testSimplifyx(path); |
| 216 | } |
| 217 | |
| 218 | static void testLine13() { |
| 219 | SkPath path, simple; |
| 220 | addCWContainer(path); |
| 221 | addCCWContents(path); |
| 222 | testSimplifyx(path); |
| 223 | } |
| 224 | |
| 225 | static void testLine14() { |
| 226 | SkPath path, simple; |
| 227 | addCCWContainer(path); |
| 228 | addCCWContents(path); |
| 229 | testSimplifyx(path); |
| 230 | } |
| 231 | |
| 232 | static void testLine15() { |
| 233 | SkPath path, simple; |
| 234 | path.addRect(0, 0, 9, 9, (SkPath::Direction) 0); |
| 235 | testSimplifyx(path); |
| 236 | } |
| 237 | |
| 238 | static void testLine16() { |
| 239 | SkPath path, simple; |
| 240 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 241 | path.addRect(0, 4, 9, 9, (SkPath::Direction) 0); |
| 242 | testSimplifyx(path); |
| 243 | } |
| 244 | |
| 245 | static void testLine17() { |
| 246 | SkPath path, simple; |
| 247 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 248 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 0); |
| 249 | testSimplifyx(path); |
| 250 | } |
| 251 | |
| 252 | static void testLine18() { |
| 253 | SkPath path, simple; |
| 254 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 255 | path.addRect(12, 4, 21, 21, (SkPath::Direction) 0); |
| 256 | testSimplifyx(path); |
| 257 | } |
| 258 | |
| 259 | static void testLine19() { |
| 260 | SkPath path, simple; |
| 261 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 262 | path.addRect(12, 16, 21, 21, (SkPath::Direction) 0); |
| 263 | testSimplifyx(path); |
| 264 | } |
| 265 | |
| 266 | static void testLine20() { |
| 267 | SkPath path, simple; |
| 268 | path.addRect(0, 12, 12, 12, (SkPath::Direction) 0); |
| 269 | path.addRect(0, 12, 9, 9, (SkPath::Direction) 0); |
| 270 | testSimplifyx(path); |
| 271 | } |
| 272 | |
| 273 | static void testLine21() { |
| 274 | SkPath path, simple; |
| 275 | path.addRect(0, 12, 12, 12, (SkPath::Direction) 0); |
| 276 | path.addRect(0, 16, 9, 9, (SkPath::Direction) 0); |
| 277 | testSimplifyx(path); |
| 278 | } |
| 279 | |
| 280 | static void testLine22() { |
| 281 | SkPath path, simple; |
| 282 | path.addRect(0, 12, 12, 12, (SkPath::Direction) 0); |
| 283 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 0); |
| 284 | testSimplifyx(path); |
| 285 | } |
| 286 | |
| 287 | static void testLine23() { |
| 288 | SkPath path, simple; |
| 289 | path.addRect(0, 12, 12, 12, (SkPath::Direction) 0); |
| 290 | path.addRect(12, 0, 21, 21, (SkPath::Direction) 0); |
| 291 | testSimplifyx(path); |
| 292 | } |
| 293 | |
| 294 | |
| 295 | |
| 296 | static void testLine24a() { |
| 297 | SkPath path, simple; |
| 298 | path.moveTo(2,0); |
| 299 | path.lineTo(4,4); |
| 300 | path.lineTo(0,4); |
| 301 | path.close(); |
| 302 | path.moveTo(2,0); |
| 303 | path.lineTo(1,2); |
| 304 | path.lineTo(2,2); |
| 305 | path.close(); |
| 306 | testSimplifyx(path); |
| 307 | } |
| 308 | |
| 309 | static void testLine24() { |
| 310 | SkPath path, simple; |
| 311 | path.addRect(0, 18, 12, 12, (SkPath::Direction) 0); |
| 312 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 0); |
| 313 | testSimplifyx(path); |
| 314 | } |
| 315 | |
| 316 | static void testLine25() { |
| 317 | SkPath path, simple; |
| 318 | path.addRect(0, 6, 12, 12, (SkPath::Direction) 0); |
| 319 | path.addRect(12, 0, 21, 21, (SkPath::Direction) 0); |
| 320 | testSimplifyx(path); |
| 321 | } |
| 322 | |
| 323 | static void testLine26() { |
| 324 | SkPath path, simple; |
| 325 | path.addRect(0, 18, 12, 12, (SkPath::Direction) 0); |
| 326 | path.addRect(0, 12, 9, 9, (SkPath::Direction) 0); |
| 327 | testSimplifyx(path); |
| 328 | } |
| 329 | |
| 330 | static void testLine27() { |
| 331 | SkPath path, simple; |
| 332 | path.addRect(0, 18, 12, 12, (SkPath::Direction) 0); |
| 333 | path.addRect(12, 8, 21, 21, (SkPath::Direction) 0); |
| 334 | testSimplifyx(path); |
| 335 | } |
| 336 | |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 337 | static void testLine28() { |
| 338 | SkPath path, simple; |
| 339 | path.addRect(0, 6, 12, 12, (SkPath::Direction) 0); |
| 340 | path.addRect(0, 0, 9, 9, (SkPath::Direction) 0); |
| 341 | testSimplifyx(path); |
| 342 | } |
| 343 | |
| 344 | static void testLine29() { |
| 345 | SkPath path, simple; |
| 346 | path.addRect(0, 18, 12, 12, (SkPath::Direction) 0); |
| 347 | path.addRect(12, 12, 21, 21, (SkPath::Direction) 0); |
| 348 | testSimplifyx(path); |
| 349 | } |
| 350 | |
| 351 | static void testLine30() { |
| 352 | SkPath path, simple; |
| 353 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 354 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 355 | path.addRect(4, 4, 13, 13, (SkPath::Direction) 0); |
| 356 | testSimplifyx(path); |
| 357 | } |
| 358 | |
| 359 | static void testLine31() { |
| 360 | SkPath path, simple; |
| 361 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 362 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 363 | path.addRect(0, 4, 9, 9, (SkPath::Direction) 0); |
| 364 | testSimplifyx(path); |
| 365 | } |
| 366 | |
| 367 | static void testLine32() { |
| 368 | SkPath path, simple; |
| 369 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 370 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 371 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 0); |
| 372 | testSimplifyx(path); |
| 373 | } |
| 374 | |
caryclark@google.com | 210acaf | 2012-07-12 21:05:13 +0000 | [diff] [blame^] | 375 | static void testLine33() { |
| 376 | SkPath path, simple; |
| 377 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 378 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 379 | path.addRect(4, 16, 13, 13, (SkPath::Direction) 0); |
| 380 | testSimplifyx(path); |
| 381 | } |
| 382 | |
| 383 | static void testLine34() { |
| 384 | SkPath path, simple; |
| 385 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 386 | path.addRect(0, 6, 12, 12, (SkPath::Direction) 0); |
| 387 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 0); |
| 388 | testSimplifyx(path); |
| 389 | } |
| 390 | |
| 391 | static void testLine35() { |
| 392 | SkPath path, simple; |
| 393 | path.addRect(0, 0, 20, 20, (SkPath::Direction) 0); |
| 394 | path.addRect(6, 0, 18, 18, (SkPath::Direction) 0); |
| 395 | path.addRect(4, 16, 13, 13, (SkPath::Direction) 0); |
| 396 | testSimplifyx(path); |
| 397 | } |
| 398 | |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 399 | #define TEST(name) { name, #name } |
| 400 | |
| 401 | static struct { |
| 402 | void (*fun)(); |
| 403 | const char* str; |
| 404 | } tests[] = { |
| 405 | TEST(testLine1), |
| 406 | TEST(testLine2), |
| 407 | TEST(testLine3), |
| 408 | TEST(testLine4), |
| 409 | TEST(testLine5), |
| 410 | TEST(testLine6), |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 411 | TEST(testLine7a), |
| 412 | TEST(testLine7b), |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 413 | TEST(testLine7), |
| 414 | TEST(testLine8), |
| 415 | TEST(testLine9), |
| 416 | TEST(testLine10), |
| 417 | TEST(testLine10a), |
| 418 | TEST(testLine11), |
| 419 | TEST(testLine12), |
| 420 | TEST(testLine13), |
| 421 | TEST(testLine14), |
| 422 | TEST(testLine15), |
| 423 | TEST(testLine16), |
| 424 | TEST(testLine17), |
| 425 | TEST(testLine18), |
| 426 | TEST(testLine19), |
| 427 | TEST(testLine20), |
| 428 | TEST(testLine21), |
| 429 | TEST(testLine22), |
| 430 | TEST(testLine23), |
| 431 | TEST(testLine24a), |
| 432 | TEST(testLine24), |
| 433 | TEST(testLine25), |
| 434 | TEST(testLine26), |
| 435 | TEST(testLine27), |
caryclark@google.com | fa4a6e9 | 2012-07-11 17:52:32 +0000 | [diff] [blame] | 436 | TEST(testLine28), |
| 437 | TEST(testLine29), |
| 438 | TEST(testLine30), |
| 439 | TEST(testLine31), |
| 440 | TEST(testLine32), |
caryclark@google.com | 210acaf | 2012-07-12 21:05:13 +0000 | [diff] [blame^] | 441 | TEST(testLine33), |
| 442 | TEST(testLine34), |
| 443 | TEST(testLine35), |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 444 | }; |
| 445 | |
| 446 | static const size_t testCount = sizeof(tests) / sizeof(tests[0]); |
| 447 | |
caryclark@google.com | 9764cc6 | 2012-07-12 19:29:45 +0000 | [diff] [blame] | 448 | static void (*firstTest)() = 0; |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 449 | static bool skipAll = false; |
| 450 | |
| 451 | void SimplifyNew_Test() { |
| 452 | if (skipAll) { |
| 453 | return; |
| 454 | } |
| 455 | size_t index = 0; |
| 456 | if (firstTest) { |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 457 | while (index < testCount && tests[index].fun != firstTest) { |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 458 | ++index; |
| 459 | } |
| 460 | } |
| 461 | bool firstTestComplete = false; |
| 462 | for ( ; index < testCount; ++index) { |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 463 | SkDebugf("%s [%s]\n", __FUNCTION__, tests[index].str); |
| 464 | (*tests[index].fun)(); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 465 | firstTestComplete = true; |
| 466 | } |
| 467 | } |