caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 1 | #include "EdgeWalker_Test.h" |
| 2 | #include "Intersection_Tests.h" |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 3 | #include "SkBitmap.h" |
| 4 | |
| 5 | static SkBitmap bitmap; |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 6 | |
| 7 | static void testSimplifyTriangle() { |
| 8 | SkPath path, out; |
| 9 | path.setFillType(SkPath::kWinding_FillType); |
| 10 | path.moveTo(10,10); // triangle |\ . |
| 11 | path.lineTo(10,30); // |_\ . |
| 12 | path.lineTo(20,30); |
| 13 | path.close(); |
| 14 | path.moveTo(20,10); // triangle /| |
| 15 | path.lineTo(10,30); // /_| |
| 16 | path.lineTo(20,30); |
| 17 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 18 | testSimplify(path, true, out, bitmap); // expect |\/| |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 19 | // |__| |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 20 | } |
| 21 | |
| 22 | static void testSimplifyTriangle3() { |
| 23 | SkPath path, out; |
| 24 | path.moveTo(0, 0); |
| 25 | path.lineTo(1, 0); |
| 26 | path.lineTo(0, 1); |
| 27 | path.close(); |
| 28 | path.moveTo(0, 0); |
| 29 | path.lineTo(1, 0); |
| 30 | path.lineTo(3, 1); |
| 31 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 32 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 33 | } |
| 34 | |
| 35 | static void testSimplifyTriangle4() { |
| 36 | SkPath path, out; |
| 37 | path.moveTo(0, 0); |
| 38 | path.lineTo(1, 0); |
| 39 | path.lineTo(0, 1); |
| 40 | path.close(); |
| 41 | path.moveTo(0, 0); |
| 42 | path.lineTo(1, 0); |
| 43 | path.lineTo(2, 1); |
| 44 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 45 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | static void testSimplifyTriangle5() { |
| 49 | SkPath path, out; |
| 50 | path.moveTo(0, 0); |
| 51 | path.lineTo(1, 0); |
| 52 | path.lineTo(0, 1); |
| 53 | path.close(); |
| 54 | path.moveTo(0, 0); |
| 55 | path.lineTo(1, 1); |
| 56 | path.lineTo(2, 1); |
| 57 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 58 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | static void testSimplifyTriangle6() { |
| 62 | SkPath path, out; |
| 63 | path.moveTo(0, 0); |
| 64 | path.lineTo(1, 0); |
| 65 | path.lineTo(0, 1); |
| 66 | path.lineTo(0, 0); |
| 67 | path.close(); |
| 68 | path.moveTo(0, 0); |
| 69 | path.lineTo(0, 1); |
| 70 | path.lineTo(3, 1); |
| 71 | path.lineTo(0, 0); |
| 72 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 73 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | static void testSimplifyTriangle7() { |
| 77 | SkPath path, out; |
| 78 | path.moveTo(0, 0); |
| 79 | path.lineTo(1, 0); |
| 80 | path.lineTo(0, 1); |
| 81 | path.lineTo(0, 0); |
| 82 | path.close(); |
| 83 | path.moveTo(0, 0); |
| 84 | path.lineTo(1, 1); |
| 85 | path.lineTo(0, 2); |
| 86 | path.lineTo(0, 0); |
| 87 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 88 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | static void testSimplifyTriangle8() { |
| 92 | SkPath path, out; |
| 93 | path.moveTo(0, 0); |
| 94 | path.lineTo(1, 0); |
| 95 | path.lineTo(0, 1); |
| 96 | path.lineTo(0, 0); |
| 97 | path.close(); |
| 98 | path.moveTo(0, 1); |
| 99 | path.lineTo(1, 2); |
| 100 | path.lineTo(1, 3); |
| 101 | path.lineTo(0, 1); |
| 102 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 103 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 104 | } |
| 105 | |
| 106 | static void testSimplifyTriangle9() { |
| 107 | SkPath path, out; |
| 108 | path.moveTo(0, 0); |
| 109 | path.lineTo(1, 0); |
| 110 | path.lineTo(1, 1); |
| 111 | path.lineTo(0, 0); |
| 112 | path.close(); |
| 113 | path.moveTo(0, 0); |
| 114 | path.lineTo(1, 1); |
| 115 | path.lineTo(2, 1); |
| 116 | path.lineTo(0, 0); |
| 117 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 118 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 119 | } |
| 120 | |
| 121 | static void testSimplifyTriangle10() { |
| 122 | SkPath path, out; |
| 123 | path.moveTo(0, 0); |
| 124 | path.lineTo(1, 0); |
| 125 | path.lineTo(1, 1); |
| 126 | path.lineTo(0, 0); |
| 127 | path.close(); |
| 128 | path.moveTo(0, 0); |
| 129 | path.lineTo(2, 0); |
| 130 | path.lineTo(0, 1); |
| 131 | path.lineTo(0, 0); |
| 132 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 133 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | static void testSimplifyTriangle11() { |
| 137 | SkPath path, out; |
| 138 | path.moveTo(0, 0); |
| 139 | path.lineTo(1, 0); |
| 140 | path.lineTo(0, 2); |
| 141 | path.lineTo(0, 0); |
| 142 | path.close(); |
| 143 | path.moveTo(0, 0); |
| 144 | path.lineTo(2, 1); |
| 145 | path.lineTo(2, 2); |
| 146 | path.lineTo(0, 0); |
| 147 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 148 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static void testSimplifyTriangle12() { |
| 152 | SkPath path, out; |
| 153 | path.moveTo(0, 0); |
| 154 | path.lineTo(1, 0); |
| 155 | path.lineTo(1, 2); |
| 156 | path.lineTo(0, 0); |
| 157 | path.close(); |
| 158 | path.moveTo(2, 0); |
| 159 | path.lineTo(0, 3); |
| 160 | path.lineTo(1, 1); |
| 161 | path.lineTo(2, 0); |
| 162 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 163 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 164 | } |
| 165 | |
| 166 | static void testSimplifyTriangle13() { |
| 167 | SkPath path, out; |
| 168 | path.moveTo(0, 0); |
| 169 | path.lineTo(1, 0); |
| 170 | path.lineTo(0, 3); |
| 171 | path.lineTo(0, 0); |
| 172 | path.close(); |
| 173 | path.moveTo(3, 0); |
| 174 | path.lineTo(0, 3); |
| 175 | path.lineTo(1, 1); |
| 176 | path.lineTo(3, 0); |
| 177 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 178 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | static void testSimplifyTriangle14() { |
| 182 | SkPath path, out; |
| 183 | path.moveTo(0, 0); |
| 184 | path.lineTo(1, 0); |
| 185 | path.lineTo(0, 1); |
| 186 | path.lineTo(0, 0); |
| 187 | path.close(); |
| 188 | path.moveTo(0, 0); |
| 189 | path.lineTo(1, 0); |
| 190 | path.lineTo(0, 1); |
| 191 | path.lineTo(0, 0); |
| 192 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 193 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 194 | } |
| 195 | |
| 196 | static void testSimplifyTriangle15() { |
| 197 | SkPath path, out; |
| 198 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 199 | path.moveTo(0, 0); |
| 200 | path.lineTo(0, 1); |
| 201 | path.lineTo(1, 2); |
| 202 | path.close(); |
| 203 | path.moveTo(0, 0); |
| 204 | path.lineTo(0, 1); |
| 205 | path.lineTo(2, 2); |
| 206 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 207 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | static void testSimplifyTriangle16() { |
| 211 | SkPath path, out; |
| 212 | path.moveTo(0, 0); |
| 213 | path.lineTo(0, 1); |
| 214 | path.lineTo(1, 2); |
| 215 | path.close(); |
| 216 | path.moveTo(0, 0); |
| 217 | path.lineTo(0, 1); |
| 218 | path.lineTo(1, 3); |
| 219 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 220 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | static void testSimplifyTriangle17() { |
| 224 | SkPath path, out; |
| 225 | path.moveTo(0, 0); |
| 226 | path.lineTo(0, 1); |
| 227 | path.lineTo(1, 2); |
| 228 | path.close(); |
| 229 | path.moveTo(0, 0); |
| 230 | path.lineTo(1, 3); |
| 231 | path.lineTo(0, 1); |
| 232 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 233 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 234 | } |
| 235 | |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 236 | static void testSimplifyTriangle18() { |
| 237 | SkPath path, out; |
| 238 | path.moveTo(0, 0); |
| 239 | path.lineTo(0, 1); |
| 240 | path.lineTo(1, 2); |
| 241 | path.close(); |
| 242 | path.moveTo(1, 0); |
| 243 | path.lineTo(0, 1); |
| 244 | path.lineTo(0, 3); |
| 245 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 246 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 247 | } |
| 248 | |
| 249 | static void testSimplifyTriangle19() { |
| 250 | SkPath path, out; |
| 251 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 252 | path.moveTo(0, 0); |
| 253 | path.lineTo(0, 1); |
| 254 | path.lineTo(3, 2); |
| 255 | path.close(); |
| 256 | path.moveTo(0, 0); |
| 257 | path.lineTo(1, 1); |
| 258 | path.lineTo(2, 1); |
| 259 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 260 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 261 | } |
| 262 | |
| 263 | static void testSimplifyTriangle20() { |
| 264 | SkPath path, out; |
| 265 | path.moveTo(0, 0); |
| 266 | path.lineTo(2, 1); |
| 267 | path.lineTo(1, 3); |
| 268 | path.close(); |
| 269 | path.moveTo(2, 0); |
| 270 | path.lineTo(3, 2); |
| 271 | path.lineTo(0, 3); |
| 272 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 273 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | static void testSimplifyTriangle21() { |
| 277 | SkPath path, out; |
| 278 | path.moveTo(0, 0); |
| 279 | path.lineTo(1, 0); |
| 280 | path.lineTo(1, 2); |
| 281 | path.close(); |
| 282 | path.moveTo(2, 0); |
| 283 | path.lineTo(2, 1); |
| 284 | path.lineTo(0, 3); |
| 285 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 286 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | static void testSimplifyDegenerateTriangle1() { |
| 290 | SkPath path, out; |
| 291 | path.moveTo(0, 0); |
| 292 | path.lineTo(0, 0); |
| 293 | path.lineTo(0, 0); |
| 294 | path.close(); |
| 295 | path.moveTo(0, 0); |
| 296 | path.lineTo(0, 0); |
| 297 | path.lineTo(0, 0); |
| 298 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 299 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | static void testSimplifyDegenerateTriangle2() { |
| 303 | SkPath path, out; |
| 304 | path.moveTo(0, 0); |
| 305 | path.lineTo(1, 1); |
| 306 | path.lineTo(2, 2); |
| 307 | path.close(); |
| 308 | path.moveTo(1, 0); |
| 309 | path.lineTo(2, 2); |
| 310 | path.lineTo(3, 3); |
| 311 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 312 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 313 | } |
| 314 | |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 315 | static void testSimplifyWindingParallelogram() { |
| 316 | SkPath path, out; |
| 317 | path.setFillType(SkPath::kWinding_FillType); |
| 318 | path.moveTo(20,10); // parallelogram _ |
| 319 | path.lineTo(30,30); // \ \ . |
| 320 | path.lineTo(40,30); // \_\ . |
| 321 | path.lineTo(30,10); |
| 322 | path.close(); |
| 323 | path.moveTo(20,10); // parallelogram _ |
| 324 | path.lineTo(10,30); // / / |
| 325 | path.lineTo(20,30); // /_/ |
| 326 | path.lineTo(30,10); |
| 327 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 328 | testSimplify(path, true, out, bitmap); // expect _ |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 329 | // / \ . |
| 330 | } // /___\ . |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 331 | |
| 332 | static void testSimplifyXorParallelogram() { |
| 333 | SkPath path, out; |
| 334 | path.setFillType(SkPath::kEvenOdd_FillType); |
| 335 | path.moveTo(20,10); // parallelogram _ |
| 336 | path.lineTo(30,30); // \ \ . |
| 337 | path.lineTo(40,30); // \_\ . |
| 338 | path.lineTo(30,10); |
| 339 | path.close(); |
| 340 | path.moveTo(20,10); // parallelogram _ |
| 341 | path.lineTo(10,30); // / / |
| 342 | path.lineTo(20,30); // /_/ |
| 343 | path.lineTo(30,10); |
| 344 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 345 | testSimplify(path, true, out, bitmap); // expect _ |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 346 | } // \ / |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 347 | |
| 348 | static void testSimplifyTriangle2() { |
| 349 | SkPath path, out; |
| 350 | path.setFillType(SkPath::kWinding_FillType); |
| 351 | path.moveTo(10,10); // triangle |\ . |
| 352 | path.lineTo(10,30); // |_\ . |
| 353 | path.lineTo(20,30); |
| 354 | path.close(); |
| 355 | path.moveTo(10,10); // triangle _ |
| 356 | path.lineTo(20,10); // \ | |
| 357 | path.lineTo(20,30); // \| |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 358 | path.close(); // _ |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 359 | testSimplify(path, true, out, bitmap); // expect | | |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 360 | } // |_| |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 361 | |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 362 | #if 0 |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 363 | static void testPathTriangleRendering() { |
| 364 | SkPath one, two; |
| 365 | one.moveTo(0, 0); |
| 366 | one.lineTo(3, 3); |
| 367 | one.lineTo(0, 3); |
| 368 | one.lineTo(1, 2); |
| 369 | one.close(); |
| 370 | for (float x = .1f; x <= 2.9f; x += .1f) { |
| 371 | SkDebugf("%s x=%g\n", __FUNCTION__, x); |
| 372 | two.moveTo(0, 0); |
| 373 | two.lineTo(x, x); |
| 374 | two.lineTo(3, 3); |
| 375 | two.lineTo(0, 3); |
| 376 | two.lineTo(1, 2); |
| 377 | two.close(); |
| 378 | comparePaths(one, two); |
| 379 | two.reset(); |
| 380 | } |
| 381 | } |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 382 | #endif |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 383 | |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 384 | static void simplify(const char* functionName, const SkPath& path, |
| 385 | bool fill, SkPath& out) { |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 386 | if (false) SkDebugf("%s\n", functionName); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 387 | simplify(path, fill, out); |
| 388 | } |
| 389 | |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 390 | static void testSimplifySkinnyTriangle1() { |
| 391 | for (int x = 1; x < 255; ++x) { |
| 392 | SkPath path, out; |
| 393 | path.moveTo((x * 101) % 10, 0); |
| 394 | path.lineTo((x * 91) % 10, 1000); |
| 395 | path.lineTo((x * 71) % 10, 2000); |
| 396 | path.lineTo((x * 51) % 10, 3000); |
| 397 | path.close(); |
| 398 | path.moveTo((x * 101) % 20, 0); |
| 399 | path.lineTo((x * 91) % 20, 1000); |
| 400 | path.lineTo((x * 71) % 20, 2000); |
| 401 | path.lineTo((x * 51) % 20, 3000); |
| 402 | path.close(); |
| 403 | path.moveTo((x * 101) % 30, 0); |
| 404 | path.lineTo((x * 91) % 30, 1000); |
| 405 | path.lineTo((x * 71) % 30, 2000); |
| 406 | path.lineTo((x * 51) % 30, 3000); |
| 407 | path.close(); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 408 | simplify(path, true, out); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 409 | } |
| 410 | } |
| 411 | |
| 412 | static void testSimplifySkinnyTriangle2() { |
| 413 | SkPath path, out; |
| 414 | #if 01 |
| 415 | path.moveTo(591.091064, 627.534851); |
| 416 | path.lineTo(541.088135, 560.707642); |
| 417 | path.lineTo(491.085175, 493.880310); |
| 418 | path.lineTo(441.082214, 427.053101); |
| 419 | //path.lineTo(591.091064, 627.534851); |
| 420 | path.close(); |
| 421 | #endif |
| 422 | path.moveTo(317.093445, 592.013306); |
| 423 | path.lineTo(366.316162, 542.986572); |
| 424 | path.lineTo(416.051514, 486.978577); |
| 425 | path.lineTo(465.786865, 430.970581); |
| 426 | //path.lineTo(317.093445, 592.013306); |
| 427 | path.close(); |
| 428 | #if 0 |
| 429 | path.moveTo(289.392517, 517.138489); |
| 430 | path.lineTo(249.886078, 508.598022); |
| 431 | path.lineTo(217.110916, 450.916443); |
| 432 | path.lineTo(196.621033, 394.917633); |
| 433 | //path.lineTo(289.392517, 517.138489); |
| 434 | path.close(); |
| 435 | #endif |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 436 | simplify(__FUNCTION__, path, true, out); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 437 | } |
| 438 | |
| 439 | static void testSimplifySkinnyTriangle3() { |
| 440 | SkPath path, out; |
| 441 | path.moveTo(591, 627.534851); |
| 442 | path.lineTo(541, 560.707642); |
| 443 | path.lineTo(491, 493.880310); |
| 444 | path.lineTo(441, 427.053101); |
| 445 | path.close(); |
| 446 | path.moveTo(317, 592.013306); |
| 447 | path.lineTo(366, 542.986572); |
| 448 | path.lineTo(416, 486.978577); |
| 449 | path.lineTo(465, 430.970581); |
| 450 | path.close(); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 451 | simplify(__FUNCTION__, path, true, out); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | static void testSimplifySkinnyTriangle4() { |
| 455 | SkPath path, out; |
| 456 | path.moveTo(572.655212, 614.959961); |
| 457 | path.lineTo(524.618896, 549.339600); |
| 458 | path.lineTo(476.582581, 483.719269); |
| 459 | path.lineTo(428.546265, 418.098938); |
| 460 | path.lineTo(572.655212, 614.959961); |
| 461 | path.close(); |
| 462 | path.moveTo(312.166382, 583.723083); |
| 463 | path.lineTo(361.047791, 529.824219); |
| 464 | path.lineTo(409.929230, 475.925354); |
| 465 | path.lineTo(458.810669, 422.026520); |
| 466 | path.lineTo(312.166382, 583.723083); |
| 467 | path.close(); |
| 468 | path.moveTo(278.742737, 508.065643); |
| 469 | path.lineTo(241.475800, 493.465118); |
| 470 | path.lineTo(210.344177, 437.315125); |
| 471 | path.lineTo(197.019455, 383.794556); |
| 472 | path.lineTo(278.742737, 508.065643); |
| 473 | path.close(); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 474 | simplify(__FUNCTION__, path, true, out); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 475 | } |
| 476 | |
| 477 | static void testSimplifySkinnyTriangle5() { |
| 478 | SkPath path, out; |
| 479 | path.moveTo(554.690613, 602.286072); |
| 480 | path.lineTo(508.590057, 537.906250); |
| 481 | path.lineTo(462.489441, 473.526520); |
| 482 | path.lineTo(416.388855, 409.146729); |
| 483 | path.lineTo(554.690613, 602.286072); |
| 484 | path.close(); |
| 485 | path.moveTo(307.216949, 575.189270); |
| 486 | path.lineTo(355.826965, 516.804688); |
| 487 | path.lineTo(403.815918, 464.990753); |
| 488 | path.lineTo(451.804871, 413.176819); |
| 489 | path.lineTo(307.216949, 575.189270); |
| 490 | path.close(); |
| 491 | path.moveTo(271.998901, 521.301025); |
| 492 | path.lineTo(234.619705, 499.687683); |
| 493 | path.lineTo(203.059692, 441.332336); |
| 494 | path.lineTo(195.994370, 386.856506); |
| 495 | path.lineTo(271.998901, 521.301025); |
| 496 | path.close(); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 497 | simplify(__FUNCTION__, path, true, out); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 498 | } |
| 499 | |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 500 | static void testSimplifySkinnyTriangle6() { |
| 501 | SkPath path, out; |
| 502 | path.moveTo(591.091064, 627.534851); |
| 503 | path.lineTo(541.088135, 560.707642); |
| 504 | path.lineTo(491.085175, 493.880310); |
| 505 | path.lineTo(441.082214, 427.053101); |
| 506 | path.lineTo(591.091064, 627.534851); |
| 507 | path.close(); |
| 508 | path.moveTo(317.093445, 592.013306); |
| 509 | path.lineTo(366.316162, 542.986572); |
| 510 | path.lineTo(416.051514, 486.978577); |
| 511 | path.lineTo(465.786865, 430.970581); |
| 512 | path.lineTo(317.093445, 592.013306); |
| 513 | path.close(); |
| 514 | path.moveTo(289.392517, 517.138489); |
| 515 | path.lineTo(249.886078, 508.598022); |
| 516 | path.lineTo(217.110916, 450.916443); |
| 517 | path.lineTo(196.621033, 394.917633); |
| 518 | path.lineTo(289.392517, 517.138489); |
| 519 | path.close(); |
| 520 | simplify(__FUNCTION__, path, true, out); |
| 521 | } |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 522 | |
| 523 | static void testSimplifyTriangle22() { |
| 524 | SkPath path, out; |
| 525 | path.moveTo(0, 0); |
| 526 | path.lineTo(1, 0); |
| 527 | path.lineTo(0, 2); |
| 528 | path.close(); |
| 529 | path.moveTo(1, 0); |
| 530 | path.lineTo(0, 2); |
| 531 | path.lineTo(0, 1); |
| 532 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 533 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 534 | } |
| 535 | |
| 536 | static void testSimplifyTriangle23() { |
| 537 | SkPath path, out; |
| 538 | path.moveTo(0, 0); |
| 539 | path.lineTo(0, 0); |
| 540 | path.lineTo(0, 0); |
| 541 | path.close(); |
| 542 | path.moveTo(0, 0); |
| 543 | path.lineTo(0, 1); |
| 544 | path.lineTo(1, 2); |
| 545 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 546 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 547 | } |
| 548 | |
| 549 | static void testSimplifyTriangle24() { |
| 550 | SkPath path, out; |
| 551 | path.moveTo(0, 0); |
| 552 | path.lineTo(0, 0); |
| 553 | path.lineTo(0, 1); |
| 554 | path.close(); |
| 555 | path.moveTo(0, 0); |
| 556 | path.lineTo(1, 0); |
| 557 | path.lineTo(0, 1); |
| 558 | path.close(); |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 559 | testSimplify(path, true, out, bitmap); |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 560 | } |
| 561 | |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 562 | static void testSimplifySkinnyTriangle7() { |
| 563 | SkPath path, out; |
| 564 | path.moveTo(487.502319, 550.811279); |
| 565 | path.lineTo(448.826050, 491.720123); |
| 566 | path.lineTo(410.149780, 432.628967); |
| 567 | path.lineTo(371.473572, 373.537781); |
| 568 | path.lineTo(487.502319, 550.811279); |
| 569 | path.close(); |
| 570 | path.moveTo(295.817108, 532.655579); |
| 571 | path.lineTo(342.896271, 485.912292); |
| 572 | path.lineTo(389.975433, 439.169006); |
| 573 | path.lineTo(437.054596, 392.425781); |
| 574 | path.lineTo(295.817108, 532.655579); |
| 575 | path.close(); |
| 576 | path.moveTo(239.726822, 575.025269); |
| 577 | path.lineTo(204.117569, 521.429688); |
| 578 | path.lineTo(171.275452, 454.110382); |
| 579 | path.lineTo(193.328583, 397.859497); |
| 580 | path.lineTo(239.726822, 575.025269); |
| 581 | path.close(); |
| 582 | simplify(__FUNCTION__, path, true, out); |
| 583 | } |
| 584 | |
| 585 | static void testSimplifySkinnyTriangle8() { |
| 586 | SkPath path, out; |
| 587 | path.moveTo(441.943115, 511.678040); |
| 588 | path.lineTo(408.487549, 456.880920); |
| 589 | path.lineTo(375.031952, 402.083801); |
| 590 | path.lineTo(341.576385, 347.286682); |
| 591 | path.lineTo(441.943115, 511.678040); |
| 592 | path.close(); |
| 593 | path.moveTo(297.548492, 557.246704); |
| 594 | path.lineTo(350.768494, 507.627014); |
| 595 | path.lineTo(403.988525, 458.007385); |
| 596 | path.lineTo(457.208527, 408.387695); |
| 597 | path.lineTo(297.548492, 557.246704); |
| 598 | path.close(); |
| 599 | path.moveTo(209.857895, 615.802979); |
| 600 | path.lineTo(178.249481, 534.230347); |
| 601 | path.lineTo(144.905640, 460.056824); |
| 602 | path.lineTo(192.953125, 404.972900); |
| 603 | path.lineTo(209.857895, 615.802979); |
| 604 | path.close(); |
| 605 | simplify(__FUNCTION__, path, true, out); |
| 606 | } |
| 607 | |
| 608 | static void testSimplifySkinnyTriangle9() { |
| 609 | SkPath path, out; |
| 610 | path.moveTo(439.867065, 528.291931); |
| 611 | path.lineTo(405.413025, 469.107178); |
| 612 | path.lineTo(370.958954, 409.922363); |
| 613 | path.lineTo(336.504883, 350.737610); |
| 614 | path.lineTo(439.867065, 528.291931); |
| 615 | path.close(); |
| 616 | path.moveTo(298.922455, 573.251953); |
| 617 | path.lineTo(356.360962, 521.905090); |
| 618 | path.lineTo(413.799438, 470.558228); |
| 619 | path.lineTo(471.237915, 419.211365); |
| 620 | path.lineTo(298.922455, 573.251953); |
| 621 | path.close(); |
| 622 | path.moveTo(187.200775, 643.035156); |
| 623 | path.lineTo(159.713165, 540.993774); |
| 624 | path.lineTo(126.257164, 462.198517); |
| 625 | path.lineTo(193.534012, 409.266235); |
| 626 | path.lineTo(187.200775, 643.035156); |
| 627 | path.close(); |
| 628 | path.close(); |
| 629 | simplify(__FUNCTION__, path, true, out); |
| 630 | } |
| 631 | |
| 632 | static void testSimplifySkinnyTriangle10() { |
| 633 | SkPath path, out; |
| 634 | #if 0 |
| 635 | path.moveTo(99.270325, 239.365234); |
| 636 | path.lineTo(105.967056, 173.361206); |
| 637 | path.lineTo(148.821381, 141.309891); |
| 638 | path.lineTo(159.101013, 189.235138); |
| 639 | path.lineTo(99.270325, 239.365234); |
| 640 | path.close(); |
| 641 | #endif |
| 642 | path.moveTo(213.673737, 413.292938); |
| 643 | path.lineTo(225.200134, 343.616821); |
| 644 | path.lineTo(236.726532, 273.940704); |
| 645 | path.lineTo(219.386414, 231.373322); |
| 646 | path.lineTo(213.673737, 413.292938); |
| 647 | path.close(); |
| 648 | path.moveTo(43.485352, 308.984497); |
| 649 | path.lineTo(122.610657, 305.950134); |
| 650 | path.lineTo(201.735962, 302.915802); |
| 651 | path.lineTo(280.861267, 299.881470); |
| 652 | path.lineTo(43.485352, 308.984497); |
| 653 | path.close(); |
| 654 | simplify(__FUNCTION__, path, true, out); |
| 655 | } |
| 656 | |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 657 | static void testSimplifySkinnyTriangle11() { |
| 658 | SkPath path, out; |
| 659 | path.moveTo(-177.878387, 265.368988); |
| 660 | path.lineTo(-254.415771, 303.709961); |
| 661 | path.lineTo(-317.465363, 271.325562); |
| 662 | path.lineTo(-374.520386, 207.507660); |
| 663 | path.lineTo(-177.878387, 265.368988); |
| 664 | path.close(); |
| 665 | path.moveTo(-63.582489, -3.679123); |
| 666 | path.lineTo(-134.496841, 26.434566); |
| 667 | path.lineTo(-205.411209, 56.548256); |
| 668 | path.lineTo(-276.325562, 86.661942); |
| 669 | path.lineTo(-63.582489, -3.679123); |
| 670 | path.close(); |
| 671 | path.moveTo(-57.078423, 162.633453); |
| 672 | path.lineTo(-95.963928, 106.261139); |
| 673 | path.lineTo(-134.849457, 49.888824); |
| 674 | path.lineTo(-173.734955, -6.483480); |
| 675 | path.lineTo(-57.078423, 162.633453); |
| 676 | path.close(); |
| 677 | simplify(__FUNCTION__, path, true, out); |
| 678 | } |
| 679 | |
| 680 | static void testSimplifySkinnyTriangle12() { |
| 681 | SkPath path, out; |
| 682 | path.moveTo(98.666489, -94.295059); |
| 683 | path.lineTo(156.584320, -61.939133); |
| 684 | path.lineTo(174.672974, -12.343765); |
| 685 | path.lineTo(158.622345, 52.028267); |
| 686 | path.lineTo(98.666489, -94.295059); |
| 687 | path.close(); |
| 688 | path.moveTo(-133.225616, -48.622055); |
| 689 | path.lineTo(-73.855499, -10.375397); |
| 690 | path.lineTo(-14.485367, 27.871277); |
| 691 | path.lineTo(44.884750, 66.117935); |
| 692 | path.lineTo(-133.225616, -48.622055); |
| 693 | path.close(); |
| 694 | path.moveTo( 9.030045, -163.413132); |
| 695 | path.lineTo(-19.605331, -89.588760); |
| 696 | path.lineTo(-48.240707, -15.764404); |
| 697 | path.lineTo(-76.876053, 58.059944); |
| 698 | path.lineTo( 9.030045, -163.413132); |
| 699 | path.close(); |
| 700 | simplify(__FUNCTION__, path, true, out); |
| 701 | } |
| 702 | |
| 703 | static void testSimplifySkinnyTriangle13() { |
| 704 | SkPath path, out; |
| 705 | path.moveTo(340.41568, -170.97171); |
| 706 | path.lineTo(418.846893, -142.428329); |
| 707 | path.lineTo(497.278107, -113.884933); |
| 708 | path.lineTo(449.18222, -45.6723022); |
| 709 | path.lineTo(340.41568, -170.97171); |
| 710 | path.close(); |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 711 | path.moveTo(326.610535, 34.0393639); |
| 712 | path.lineTo(371.334595, -14.9620667); |
| 713 | path.lineTo(416.058624, -63.9634857); |
| 714 | path.lineTo(460.782654, -112.96492); |
| 715 | path.lineTo(326.610535, 34.0393639); |
| 716 | path.close(); |
| 717 | simplify(__FUNCTION__, path, true, out); |
| 718 | } |
| 719 | |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 720 | static void (*simplifyTests[])() = { |
caryclark@google.com | d88e089 | 2012-03-27 13:23:51 +0000 | [diff] [blame] | 721 | testSimplifySkinnyTriangle13, |
| 722 | testSimplifySkinnyTriangle12, |
| 723 | testSimplifySkinnyTriangle11, |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 724 | testSimplifySkinnyTriangle10, |
| 725 | testSimplifySkinnyTriangle9, |
| 726 | testSimplifySkinnyTriangle8, |
| 727 | testSimplifySkinnyTriangle7, |
| 728 | testSimplifySkinnyTriangle6, |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 729 | testSimplifySkinnyTriangle5, |
| 730 | testSimplifySkinnyTriangle4, |
| 731 | testSimplifySkinnyTriangle3, |
| 732 | testSimplifySkinnyTriangle2, |
| 733 | testSimplifySkinnyTriangle1, |
| 734 | testSimplifyTriangle24, |
| 735 | testSimplifyTriangle23, |
| 736 | testSimplifyTriangle22, |
caryclark@google.com | 4917f17 | 2012-03-05 22:01:21 +0000 | [diff] [blame] | 737 | testSimplifyDegenerateTriangle2, |
| 738 | testSimplifyDegenerateTriangle1, |
| 739 | testSimplifyTriangle21, |
| 740 | testSimplifyTriangle20, |
| 741 | testSimplifyTriangle19, |
| 742 | testSimplifyTriangle18, |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 743 | testSimplifyTriangle17, |
| 744 | testSimplifyTriangle16, |
| 745 | testSimplifyTriangle15, |
| 746 | testSimplifyTriangle14, |
| 747 | testSimplifyTriangle13, |
| 748 | testSimplifyTriangle12, |
| 749 | testSimplifyTriangle11, |
| 750 | testSimplifyTriangle10, |
| 751 | testSimplifyTriangle7, |
| 752 | testSimplifyTriangle9, |
| 753 | testSimplifyTriangle8, |
| 754 | testSimplifyTriangle6, |
| 755 | testSimplifyTriangle5, |
| 756 | testSimplifyTriangle4, |
| 757 | testSimplifyTriangle3, |
| 758 | testSimplifyTriangle, |
| 759 | testSimplifyTriangle2, |
| 760 | testSimplifyWindingParallelogram, |
| 761 | testSimplifyXorParallelogram, |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 762 | // testPathTriangleRendering, |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 763 | }; |
| 764 | |
| 765 | static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]); |
| 766 | |
caryclark@google.com | a576423 | 2012-03-28 16:20:21 +0000 | [diff] [blame] | 767 | static void (*firstTest)() = testSimplifySkinnyTriangle12; |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 768 | |
| 769 | void SimplifyPolygonPaths_Test() { |
| 770 | size_t index = 0; |
| 771 | if (firstTest) { |
| 772 | while (index < simplifyTestsCount && simplifyTests[index] != firstTest) { |
| 773 | ++index; |
| 774 | } |
| 775 | } |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 776 | bool firstTestComplete = false; |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 777 | for ( ; index < simplifyTestsCount; ++index) { |
| 778 | (*simplifyTests[index])(); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 779 | if (simplifyTests[index] == testSimplifySkinnyTriangle2) { |
caryclark@google.com | 198e054 | 2012-03-30 18:47:02 +0000 | [diff] [blame] | 780 | if (false) SkDebugf("%s last fast skinny test\n", __FUNCTION__); |
caryclark@google.com | 752b60e | 2012-03-22 21:11:17 +0000 | [diff] [blame] | 781 | } |
caryclark@google.com | 2e7f4c8 | 2012-03-20 21:11:59 +0000 | [diff] [blame] | 782 | firstTestComplete = true; |
caryclark@google.com | cd4421d | 2012-03-01 19:16:31 +0000 | [diff] [blame] | 783 | } |
| 784 | } |
| 785 | |