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 | |
| 103 | static void testLine8() { |
| 104 | SkPath path, simple; |
| 105 | path.moveTo(0,4); |
| 106 | path.lineTo(4,4); |
| 107 | path.lineTo(2,2); |
| 108 | path.close(); |
| 109 | path.moveTo(2,4); |
| 110 | path.lineTo(6,4); |
| 111 | path.lineTo(4,2); |
| 112 | path.close(); |
| 113 | testSimplifyx(path); |
| 114 | } |
| 115 | |
| 116 | static void testLine9() { |
| 117 | SkPath path, simple; |
| 118 | path.moveTo(0,4); |
| 119 | path.lineTo(4,4); |
| 120 | path.lineTo(2,2); |
| 121 | path.close(); |
| 122 | path.moveTo(6,4); |
| 123 | path.lineTo(2,4); |
| 124 | path.lineTo(4,2); |
| 125 | path.close(); |
| 126 | testSimplifyx(path); |
| 127 | } |
| 128 | |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 129 | static void testLine10() { |
| 130 | SkPath path, simple; |
| 131 | path.moveTo(0,4); |
| 132 | path.lineTo(4,4); |
| 133 | path.lineTo(2,2); |
| 134 | path.close(); |
| 135 | path.moveTo(2,1); |
| 136 | path.lineTo(3,4); |
| 137 | path.lineTo(6,1); |
| 138 | path.close(); |
| 139 | testSimplifyx(path); |
| 140 | } |
caryclark@google.com | 88f7d0c | 2012-06-07 21:09:20 +0000 | [diff] [blame] | 141 | |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 142 | static void testLine10a() { |
| 143 | SkPath path, simple; |
| 144 | path.moveTo(0,4); |
| 145 | path.lineTo(8,4); |
| 146 | path.lineTo(4,0); |
| 147 | path.close(); |
| 148 | path.moveTo(2,2); |
| 149 | path.lineTo(3,3); |
| 150 | path.lineTo(4,2); |
| 151 | path.close(); |
| 152 | testSimplifyx(path); |
| 153 | } |
| 154 | |
| 155 | static void addCWContainer(SkPath& path) { |
| 156 | path.moveTo(6,4); |
| 157 | path.lineTo(0,4); |
| 158 | path.lineTo(3,1); |
| 159 | path.close(); |
| 160 | } |
| 161 | |
| 162 | static void addCCWContainer(SkPath& path) { |
| 163 | path.moveTo(0,4); |
| 164 | path.lineTo(6,4); |
| 165 | path.lineTo(3,1); |
| 166 | path.close(); |
| 167 | } |
| 168 | |
| 169 | static void addCWContents(SkPath& path) { |
| 170 | path.moveTo(2,3); |
| 171 | path.lineTo(3,2); |
| 172 | path.lineTo(4,3); |
| 173 | path.close(); |
| 174 | } |
| 175 | |
| 176 | static void addCCWContents(SkPath& path) { |
| 177 | path.moveTo(3,2); |
| 178 | path.lineTo(2,3); |
| 179 | path.lineTo(4,3); |
| 180 | path.close(); |
| 181 | } |
| 182 | |
| 183 | static void testLine11() { |
| 184 | SkPath path, simple; |
| 185 | addCWContainer(path); |
| 186 | addCWContents(path); |
| 187 | testSimplifyx(path); |
| 188 | } |
| 189 | |
| 190 | static void testLine12() { |
| 191 | SkPath path, simple; |
| 192 | addCCWContainer(path); |
| 193 | addCWContents(path); |
| 194 | testSimplifyx(path); |
| 195 | } |
| 196 | |
| 197 | static void testLine13() { |
| 198 | SkPath path, simple; |
| 199 | addCWContainer(path); |
| 200 | addCCWContents(path); |
| 201 | testSimplifyx(path); |
| 202 | } |
| 203 | |
| 204 | static void testLine14() { |
| 205 | SkPath path, simple; |
| 206 | addCCWContainer(path); |
| 207 | addCCWContents(path); |
| 208 | testSimplifyx(path); |
| 209 | } |
| 210 | |
| 211 | static void testLine15() { |
| 212 | SkPath path, simple; |
| 213 | path.addRect(0, 0, 9, 9, (SkPath::Direction) 0); |
| 214 | testSimplifyx(path); |
| 215 | } |
| 216 | |
| 217 | static void testLine16() { |
| 218 | SkPath path, simple; |
| 219 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 220 | path.addRect(0, 4, 9, 9, (SkPath::Direction) 0); |
| 221 | testSimplifyx(path); |
| 222 | } |
| 223 | |
| 224 | static void testLine17() { |
| 225 | SkPath path, simple; |
| 226 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 227 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 0); |
| 228 | testSimplifyx(path); |
| 229 | } |
| 230 | |
| 231 | static void testLine18() { |
| 232 | SkPath path, simple; |
| 233 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 234 | path.addRect(12, 4, 21, 21, (SkPath::Direction) 0); |
| 235 | testSimplifyx(path); |
| 236 | } |
| 237 | |
| 238 | static void testLine19() { |
| 239 | SkPath path, simple; |
| 240 | path.addRect(0, 0, 12, 12, (SkPath::Direction) 0); |
| 241 | path.addRect(12, 16, 21, 21, (SkPath::Direction) 0); |
| 242 | testSimplifyx(path); |
| 243 | } |
| 244 | |
| 245 | static void testLine20() { |
| 246 | SkPath path, simple; |
| 247 | path.addRect(0, 12, 12, 12, (SkPath::Direction) 0); |
| 248 | path.addRect(0, 12, 9, 9, (SkPath::Direction) 0); |
| 249 | testSimplifyx(path); |
| 250 | } |
| 251 | |
| 252 | static void testLine21() { |
| 253 | SkPath path, simple; |
| 254 | path.addRect(0, 12, 12, 12, (SkPath::Direction) 0); |
| 255 | path.addRect(0, 16, 9, 9, (SkPath::Direction) 0); |
| 256 | testSimplifyx(path); |
| 257 | } |
| 258 | |
| 259 | static void testLine22() { |
| 260 | SkPath path, simple; |
| 261 | path.addRect(0, 12, 12, 12, (SkPath::Direction) 0); |
| 262 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 0); |
| 263 | testSimplifyx(path); |
| 264 | } |
| 265 | |
| 266 | static void testLine23() { |
| 267 | SkPath path, simple; |
| 268 | path.addRect(0, 12, 12, 12, (SkPath::Direction) 0); |
| 269 | path.addRect(12, 0, 21, 21, (SkPath::Direction) 0); |
| 270 | testSimplifyx(path); |
| 271 | } |
| 272 | |
| 273 | |
| 274 | |
| 275 | static void testLine24a() { |
| 276 | SkPath path, simple; |
| 277 | path.moveTo(2,0); |
| 278 | path.lineTo(4,4); |
| 279 | path.lineTo(0,4); |
| 280 | path.close(); |
| 281 | path.moveTo(2,0); |
| 282 | path.lineTo(1,2); |
| 283 | path.lineTo(2,2); |
| 284 | path.close(); |
| 285 | testSimplifyx(path); |
| 286 | } |
| 287 | |
| 288 | static void testLine24() { |
| 289 | SkPath path, simple; |
| 290 | path.addRect(0, 18, 12, 12, (SkPath::Direction) 0); |
| 291 | path.addRect(4, 12, 13, 13, (SkPath::Direction) 0); |
| 292 | testSimplifyx(path); |
| 293 | } |
| 294 | |
| 295 | static void testLine25() { |
| 296 | SkPath path, simple; |
| 297 | path.addRect(0, 6, 12, 12, (SkPath::Direction) 0); |
| 298 | path.addRect(12, 0, 21, 21, (SkPath::Direction) 0); |
| 299 | testSimplifyx(path); |
| 300 | } |
| 301 | |
| 302 | static void testLine26() { |
| 303 | SkPath path, simple; |
| 304 | path.addRect(0, 18, 12, 12, (SkPath::Direction) 0); |
| 305 | path.addRect(0, 12, 9, 9, (SkPath::Direction) 0); |
| 306 | testSimplifyx(path); |
| 307 | } |
| 308 | |
| 309 | static void testLine27() { |
| 310 | SkPath path, simple; |
| 311 | path.addRect(0, 18, 12, 12, (SkPath::Direction) 0); |
| 312 | path.addRect(12, 8, 21, 21, (SkPath::Direction) 0); |
| 313 | testSimplifyx(path); |
| 314 | } |
| 315 | |
| 316 | #define TEST(name) { name, #name } |
| 317 | |
| 318 | static struct { |
| 319 | void (*fun)(); |
| 320 | const char* str; |
| 321 | } tests[] = { |
| 322 | TEST(testLine1), |
| 323 | TEST(testLine2), |
| 324 | TEST(testLine3), |
| 325 | TEST(testLine4), |
| 326 | TEST(testLine5), |
| 327 | TEST(testLine6), |
| 328 | TEST(testLine7), |
| 329 | TEST(testLine8), |
| 330 | TEST(testLine9), |
| 331 | TEST(testLine10), |
| 332 | TEST(testLine10a), |
| 333 | TEST(testLine11), |
| 334 | TEST(testLine12), |
| 335 | TEST(testLine13), |
| 336 | TEST(testLine14), |
| 337 | TEST(testLine15), |
| 338 | TEST(testLine16), |
| 339 | TEST(testLine17), |
| 340 | TEST(testLine18), |
| 341 | TEST(testLine19), |
| 342 | TEST(testLine20), |
| 343 | TEST(testLine21), |
| 344 | TEST(testLine22), |
| 345 | TEST(testLine23), |
| 346 | TEST(testLine24a), |
| 347 | TEST(testLine24), |
| 348 | TEST(testLine25), |
| 349 | TEST(testLine26), |
| 350 | TEST(testLine27), |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 351 | }; |
| 352 | |
| 353 | static const size_t testCount = sizeof(tests) / sizeof(tests[0]); |
| 354 | |
caryclark@google.com | 66ca2fb | 2012-07-03 14:30:08 +0000 | [diff] [blame] | 355 | static void (*firstTest)() = testLine20; |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 356 | static bool skipAll = false; |
| 357 | |
| 358 | void SimplifyNew_Test() { |
| 359 | if (skipAll) { |
| 360 | return; |
| 361 | } |
| 362 | size_t index = 0; |
| 363 | if (firstTest) { |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 364 | while (index < testCount && tests[index].fun != firstTest) { |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 365 | ++index; |
| 366 | } |
| 367 | } |
| 368 | bool firstTestComplete = false; |
| 369 | for ( ; index < testCount; ++index) { |
caryclark@google.com | 8dcf114 | 2012-07-02 20:27:02 +0000 | [diff] [blame] | 370 | SkDebugf("%s [%s]\n", __FUNCTION__, tests[index].str); |
| 371 | (*tests[index].fun)(); |
caryclark@google.com | af46cff | 2012-05-22 21:12:00 +0000 | [diff] [blame] | 372 | firstTestComplete = true; |
| 373 | } |
| 374 | } |