OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 #include "PathOpsCubicIntersectionTestData.h" | 7 #include "PathOpsCubicIntersectionTestData.h" |
8 #include "PathOpsTestCommon.h" | 8 #include "PathOpsTestCommon.h" |
| 9 #include "SkGeometry.h" |
9 #include "SkIntersections.h" | 10 #include "SkIntersections.h" |
10 #include "SkPathOpsRect.h" | 11 #include "SkPathOpsRect.h" |
11 #include "SkReduceOrder.h" | 12 #include "SkReduceOrder.h" |
12 #include "Test.h" | 13 #include "Test.h" |
13 | 14 |
14 const int firstCubicIntersectionTest = 9; | 15 const int firstCubicIntersectionTest = 9; |
15 | 16 |
16 static void standardTestCases(skiatest::Reporter* reporter) { | 17 static void standardTestCases(skiatest::Reporter* reporter) { |
17 for (size_t index = firstCubicIntersectionTest; index < tests_count; ++index
) { | 18 for (size_t index = firstCubicIntersectionTest; index < tests_count; ++index
) { |
18 int iIndex = static_cast<int>(index); | 19 int iIndex = static_cast<int>(index); |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 | 156 |
156 {{{18.1312339, 31.6473732}, {95.5711034, 63.5350219}, {92.3283165, 62.0158945}, | 157 {{{18.1312339, 31.6473732}, {95.5711034, 63.5350219}, {92.3283165, 62.0158945}, |
157 {18.5656052, 32.1268808}}}, | 158 {18.5656052, 32.1268808}}}, |
158 {{{97.402018, 35.7169972}, {33.1127443, 25.8935163}, {1.13970027, 54.9424981}, | 159 {{{97.402018, 35.7169972}, {33.1127443, 25.8935163}, {1.13970027, 54.9424981}, |
159 {56.4860195, 60.529264}}}, | 160 {56.4860195, 60.529264}}}, |
160 }; | 161 }; |
161 | 162 |
162 const int testSetCount = (int) SK_ARRAY_COUNT(testSet); | 163 const int testSetCount = (int) SK_ARRAY_COUNT(testSet); |
163 | 164 |
164 static const SkDCubic newTestSet[] = { | 165 static const SkDCubic newTestSet[] = { |
| 166 {{{980.026001,1481.276}, {980.026001,1481.276}, {980.02594,1481.27576}, {980.025
879,1481.27527}}}, |
| 167 {{{980.025879,1481.27527}, {980.025452,1481.27222}, {980.023743,1481.26038}, {98
0.02179,1481.24072}}}, |
| 168 |
| 169 {{{1.80943513,3.07782435}, {1.66686702,2.16806936}, {1.68301272,0}, {3,0}}}, |
| 170 {{{0,1}, {0,3}, {3,2}, {5,2}}}, |
| 171 |
| 172 {{{3.4386673,2.66977954}, {4.06668949,2.17046738}, {4.78887367,1.59629118}, {6,2
}}}, |
| 173 {{{1.71985495,3.49467373}, {2.11620402,2.7201426}, {2.91897964,1.15138781}, {6,3
}}}, |
| 174 |
| 175 {{{0,1}, {0.392703831,1.78540766}, {0.219947904,2.05676103}, {0.218561709,2.0563
0541}}}, |
| 176 {{{0.218561709,2.05630541}, {0.216418028,2.05560064}, {0.624105453,1.40486407},
{4.16666651,1.00000012}}}, |
| 177 |
| 178 {{{0, 1}, {3, 5}, {2, 1}, {3, 1}}}, |
| 179 {{{1.01366711f, 2.21379328f}, {1.09074128f, 2.23241305f}, {1.60246587f, 0.451849
401f}, {5, 3}}}, |
| 180 |
| 181 {{{0, 1}, {0.541499972f, 3.16599989f}, {1.08299994f, 2.69299984f}, {2.10083938f,
1.80391729f}}}, |
| 182 {{{0.806384504f, 2.85426903f}, {1.52740121f, 1.99355423f}, {2.81689167f, 0.45422
2918f}, {5, 1}}}, |
| 183 |
| 184 {{{0, 1}, {1.90192389f, 2.90192389f}, {2.59807634f, 2.79422879f}, {3.1076951f, 2
.71539044f}}}, |
| 185 {{{2, 3}, {2.36602545f, 3.36602545f}, {2.330127f, 3.06217766f}, {2.28460979f, 2.
67691422f}}}, |
| 186 |
| 187 {{{0, 1}, {1.90192389f, 2.90192389f}, {2.59807634f, 2.79422879f}, {3.1076951f, 2
.71539044f}}}, |
| 188 {{{2.28460979f, 2.67691422f}, {2.20577145f, 2.00961876f}, {2.09807634f, 1.098076
22f}, {4, 3}}}, |
| 189 |
| 190 {{{0, 1}, {0.8211091160774231, 2.0948121547698975}, {0.91805583238601685, 2.5154
04224395752}, {0.91621249914169312, 2.5146586894989014}}}, |
| 191 {{{0.91621249914169312, 2.5146586894989014}, {0.91132104396820068, 2.51268076896
66748}, {0.21079301834106445, -0.45617169141769409}, {10.5, -1.6666665077209473}
}}, |
| 192 |
| 193 {{{42.6237564,68.9841232}, {32.449646,81.963089}, {14.7713947,103.565269}, {12.6
310005,105.247002}}}, |
| 194 {{{37.2640038,95.3540039}, {37.2640038,95.3540039}, {11.3710003,83.7339935}, {-2
5.0779991,124.912003}}}, |
| 195 |
| 196 {{{0,1}, {4,5}, {6,0}, {1,0}}}, |
| 197 {{{0,6}, {0,1}, {1,0}, {5,4}}}, |
| 198 |
| 199 {{{0,1}, {4,6}, {5,1}, {6,2}}}, |
| 200 {{{1,5}, {2,6}, {1,0}, {6,4}}}, |
| 201 |
| 202 {{{322, 896.04803466796875}, {314.09201049804687, 833.4376220703125}, {260.24713
134765625, 785}, {195, 785}}}, |
| 203 {{{195, 785}, {265.14016723632812, 785}, {322, 842.30755615234375}, {322, 913}}}
, |
| 204 |
| 205 {{{1, 4}, {4, 5}, {3, 2}, {6, 3}}}, |
| 206 {{{2, 3}, {3, 6}, {4, 1}, {5, 4}}}, |
| 207 |
| 208 {{{67, 913}, {67, 917.388916015625}, {67.224380493164063, 921.72576904296875}, {
67.662384033203125, 926}}}, |
| 209 {{{194, 1041}, {123.85984039306641, 1041}, {67, 983.69244384765625}, {67, 913}}}
, |
| 210 |
| 211 {{{1,4}, {1,5}, {6,0}, {5,1}}}, |
| 212 {{{0,6}, {1,5}, {4,1}, {5,1}}}, |
| 213 |
| 214 {{{0,1}, {4,5}, {6,0}, {1,0}}}, |
| 215 {{{0,6}, {0,1}, {1,0}, {5,4}}}, |
| 216 |
| 217 {{{0,1}, {4,6}, {2,0}, {2,0}}}, |
| 218 {{{0,2}, {0,2}, {1,0}, {6,4}}}, |
| 219 |
165 {{{980.9000244140625, 1474.3280029296875}, {980.9000244140625, 1474.328002929687
5}, {978.89300537109375, 1471.95703125}, {981.791015625, 1469.487060546875}}}, | 220 {{{980.9000244140625, 1474.3280029296875}, {980.9000244140625, 1474.328002929687
5}, {978.89300537109375, 1471.95703125}, {981.791015625, 1469.487060546875}}}, |
166 {{{981.791015625, 1469.487060546875}, {981.791015625, 1469.4859619140625}, {983.
3580322265625, 1472.72900390625}, {980.9000244140625, 1474.3280029296875}}}, | 221 {{{981.791015625, 1469.487060546875}, {981.791015625, 1469.4859619140625}, {983.
3580322265625, 1472.72900390625}, {980.9000244140625, 1474.3280029296875}}}, |
167 | 222 |
168 {{{275,532}, {277.209137,532}, {279,530.209106}, {279,528}}}, | 223 {{{275,532}, {277.209137,532}, {279,530.209106}, {279,528}}}, |
169 {{{278,529}, {278,530.65686}, {276.65686,532}, {275,532}}}, | 224 {{{278,529}, {278,530.65686}, {276.65686,532}, {275,532}}}, |
170 | 225 |
171 #if 0 // FIXME: asserts coincidence, not working yet | 226 #if 0 // FIXME: asserts coincidence, not working yet |
172 {{{195, 785}, {124.30755615234375, 785}, {67, 841.85986328125}, {67, 912}}}, | 227 {{{195, 785}, {124.30755615234375, 785}, {67, 841.85986328125}, {67, 912}}}, |
173 {{{67, 913}, {67, 842.30755615234375}, {123.85984039306641, 785}, {194, 785}}}, | 228 {{{67, 913}, {67, 842.30755615234375}, {123.85984039306641, 785}, {194, 785}}}, |
174 #endif | 229 #endif |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
299 {{{0, 1}, {0, 1}, {2, 1}, {6, 5}}}, | 354 {{{0, 1}, {0, 1}, {2, 1}, {6, 5}}}, |
300 | 355 |
301 {{{0, 6}, {1, 2}, {1, 0}, {1, 0}}}, | 356 {{{0, 6}, {1, 2}, {1, 0}, {1, 0}}}, |
302 {{{0, 1}, {0, 1}, {6, 0}, {2, 1}}}, | 357 {{{0, 1}, {0, 1}, {6, 0}, {2, 1}}}, |
303 | 358 |
304 {{{0, 2}, {0, 1}, {3, 0}, {1, 0}}}, | 359 {{{0, 2}, {0, 1}, {3, 0}, {1, 0}}}, |
305 {{{0, 3}, {0, 1}, {2, 0}, {1, 0}}}, | 360 {{{0, 3}, {0, 1}, {2, 0}, {1, 0}}}, |
306 }; | 361 }; |
307 | 362 |
308 const int newTestSetCount = (int) SK_ARRAY_COUNT(newTestSet); | 363 const int newTestSetCount = (int) SK_ARRAY_COUNT(newTestSet); |
309 | |
310 static void oneOff(skiatest::Reporter* reporter, const SkDCubic& cubic1, const S
kDCubic& cubic2, | 364 static void oneOff(skiatest::Reporter* reporter, const SkDCubic& cubic1, const S
kDCubic& cubic2, |
311 bool coin) { | 365 bool coin) { |
312 SkASSERT(ValidCubic(cubic1)); | 366 SkASSERT(ValidCubic(cubic1)); |
313 SkASSERT(ValidCubic(cubic2)); | 367 SkASSERT(ValidCubic(cubic2)); |
314 #if ONE_OFF_DEBUG | 368 #if ONE_OFF_DEBUG |
315 SkDebugf("computed quadratics given\n"); | 369 SkDebugf("computed quadratics given\n"); |
316 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n"
, | 370 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n"
, |
317 cubic1[0].fX, cubic1[0].fY, cubic1[1].fX, cubic1[1].fY, | 371 cubic1[0].fX, cubic1[0].fY, cubic1[1].fX, cubic1[1].fY, |
318 cubic1[2].fX, cubic1[2].fY, cubic1[3].fX, cubic1[3].fY); | 372 cubic1[2].fX, cubic1[2].fY, cubic1[3].fX, cubic1[3].fY); |
319 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n"
, | 373 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n"
, |
320 cubic2[0].fX, cubic2[0].fY, cubic2[1].fX, cubic2[1].fY, | 374 cubic2[0].fX, cubic2[0].fY, cubic2[1].fX, cubic2[1].fY, |
321 cubic2[2].fX, cubic2[2].fY, cubic2[3].fX, cubic2[3].fY); | 375 cubic2[2].fX, cubic2[2].fY, cubic2[3].fX, cubic2[3].fY); |
322 #endif | 376 #endif |
323 SkTArray<SkDQuad, true> quads1; | 377 SkIntersections intersections; |
324 CubicToQuads(cubic1, cubic1.calcPrecision(), quads1); | 378 intersections.intersect(cubic1, cubic2); |
325 #if ONE_OFF_DEBUG | 379 #if DEBUG_T_SECT_DUMP == 3 |
326 SkDebugf("computed quadratics set 1\n"); | 380 SkDebugf("</div>\n\n"); |
327 for (int index = 0; index < quads1.count(); ++index) { | 381 SkDebugf("<script type=\"text/javascript\">\n\n"); |
328 const SkDQuad& q = quads1[index]; | 382 SkDebugf("var testDivs = [\n"); |
329 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", q[0].fX,
q[0].fY, | 383 for (int index = 1; index <= gDumpTSectNum; ++index) { |
330 q[1].fX, q[1].fY, q[2].fX, q[2].fY); | 384 SkDebugf("sect%d,\n", index); |
331 } | 385 } |
332 #endif | 386 #endif |
333 SkTArray<SkDQuad, true> quads2; | 387 if (coin && intersections.used() != 2) { |
334 CubicToQuads(cubic2, cubic2.calcPrecision(), quads2); | 388 SkDebugf(""); |
335 #if ONE_OFF_DEBUG | |
336 SkDebugf("computed quadratics set 2\n"); | |
337 for (int index = 0; index < quads2.count(); ++index) { | |
338 const SkDQuad& q = quads2[index]; | |
339 SkDebugf(" {{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}},\n", q[0].fX,
q[0].fY, | |
340 q[1].fX, q[1].fY, q[2].fX, q[2].fY); | |
341 } | 389 } |
342 #endif | |
343 SkIntersections intersections; | |
344 intersections.intersect(cubic1, cubic2); | |
345 REPORTER_ASSERT(reporter, !coin || intersections.used() == 2); | 390 REPORTER_ASSERT(reporter, !coin || intersections.used() == 2); |
346 double tt1, tt2; | 391 double tt1, tt2; |
347 SkDPoint xy1, xy2; | 392 SkDPoint xy1, xy2; |
348 for (int pt3 = 0; pt3 < intersections.used(); ++pt3) { | 393 for (int pt3 = 0; pt3 < intersections.used(); ++pt3) { |
349 tt1 = intersections[0][pt3]; | 394 tt1 = intersections[0][pt3]; |
350 xy1 = cubic1.ptAtT(tt1); | 395 xy1 = cubic1.ptAtT(tt1); |
351 tt2 = intersections[1][pt3]; | 396 tt2 = intersections[1][pt3]; |
352 xy2 = cubic2.ptAtT(tt2); | 397 xy2 = cubic2.ptAtT(tt2); |
353 const SkDPoint& iPt = intersections.pt(pt3); | 398 const SkDPoint& iPt = intersections.pt(pt3); |
354 #if ONE_OFF_DEBUG | 399 #if ONE_OFF_DEBUG |
(...skipping 196 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
551 {{{3.34, 8.98}, {1.95, 10.27}, {3.76, 7.65}, {4.96, 10.64}}}, | 596 {{{3.34, 8.98}, {1.95, 10.27}, {3.76, 7.65}, {4.96, 10.64}}}, |
552 {{{3.13, 2.74}, {1.08, 4.62}, {3.71, 0.94}, {2.01, 3.81}}}, | 597 {{{3.13, 2.74}, {1.08, 4.62}, {3.71, 0.94}, {2.01, 3.81}}}, |
553 {{{6.71, 3.14}, {7.99, 2.75}, {8.27, 1.96}, {6.35, 3.57}}}, | 598 {{{6.71, 3.14}, {7.99, 2.75}, {8.27, 1.96}, {6.35, 3.57}}}, |
554 {{{12.81, 7.27}, {7.22, 6.98}, {12.49, 8.97}, {11.42, 6.18}}}, | 599 {{{12.81, 7.27}, {7.22, 6.98}, {12.49, 8.97}, {11.42, 6.18}}}, |
555 }; | 600 }; |
556 | 601 |
557 int selfSetCount = (int) SK_ARRAY_COUNT(selfSet); | 602 int selfSetCount = (int) SK_ARRAY_COUNT(selfSet); |
558 | 603 |
559 static void selfOneOff(skiatest::Reporter* reporter, int index) { | 604 static void selfOneOff(skiatest::Reporter* reporter, int index) { |
560 const SkDCubic& cubic = selfSet[index]; | 605 const SkDCubic& cubic = selfSet[index]; |
561 #if ONE_OFF_DEBUG | 606 SkPoint c[4]; |
562 int idx2; | 607 for (int i = 0; i < 4; ++i) { |
563 double max[3]; | 608 c[i] = cubic[i].asSkPoint(); |
564 int ts = cubic.findMaxCurvature(max); | |
565 for (idx2 = 0; idx2 < ts; ++idx2) { | |
566 SkDebugf("%s max[%d]=%1.9g (%1.9g, %1.9g)\n", __FUNCTION__, idx2, | |
567 max[idx2], cubic.ptAtT(max[idx2]).fX, cubic.ptAtT(max[idx2]).fY)
; | |
568 } | 609 } |
569 SkTArray<double, true> ts1; | 610 SkScalar loopT; |
570 SkTArray<SkDQuad, true> quads1; | 611 SkScalar d[3]; |
571 cubic.toQuadraticTs(cubic.calcPrecision(), &ts1); | 612 SkCubicType cubicType = SkClassifyCubic(c, d); |
572 for (idx2 = 0; idx2 < ts1.count(); ++idx2) { | 613 if (SkDCubic::ComplexBreak(c, &loopT) && cubicType == SkCubicType::kLoop_SkC
ubicType) { |
573 SkDebugf("%s t[%d]=%1.9g\n", __FUNCTION__, idx2, ts1[idx2]); | 614 SkIntersections i; |
| 615 SkPoint twoCubics[7]; |
| 616 SkChopCubicAt(c, twoCubics, loopT); |
| 617 SkDCubic chopped[2]; |
| 618 chopped[0].set(&twoCubics[0]); |
| 619 chopped[1].set(&twoCubics[3]); |
| 620 int result = i.intersect(chopped[0], chopped[1]); |
| 621 REPORTER_ASSERT(reporter, result == 2); |
| 622 REPORTER_ASSERT(reporter, i.used() == 2); |
| 623 for (int index = 0; index < result; ++index) { |
| 624 SkDPoint pt1 = chopped[0].ptAtT(i[0][index]); |
| 625 SkDPoint pt2 = chopped[1].ptAtT(i[1][index]); |
| 626 REPORTER_ASSERT(reporter, pt1.approximatelyEqual(pt2)); |
| 627 reporter->bumpTestCount(); |
| 628 } |
574 } | 629 } |
575 CubicToQuads(cubic, cubic.calcPrecision(), quads1); | |
576 for (idx2 = 0; idx2 < quads1.count(); ++idx2) { | |
577 const SkDQuad& q = quads1[idx2]; | |
578 SkDebugf(" {{{%1.9g,%1.9g}, {%1.9g,%1.9g}, {%1.9g,%1.9g}}},\n", | |
579 q[0].fX, q[0].fY, q[1].fX, q[1].fY, q[2].fX, q[2].fY); | |
580 } | |
581 SkDebugf("\n"); | |
582 #endif | |
583 SkIntersections i; | |
584 int result = i.intersect(cubic); | |
585 REPORTER_ASSERT(reporter, result == 1); | |
586 REPORTER_ASSERT(reporter, i.used() == 1); | |
587 REPORTER_ASSERT(reporter, !approximately_equal(i[0][0], i[1][0])); | |
588 SkDPoint pt1 = cubic.ptAtT(i[0][0]); | |
589 SkDPoint pt2 = cubic.ptAtT(i[1][0]); | |
590 REPORTER_ASSERT(reporter, pt1.approximatelyEqual(pt2)); | |
591 reporter->bumpTestCount(); | |
592 } | 630 } |
593 | 631 |
594 static void cubicIntersectionSelfTest(skiatest::Reporter* reporter) { | 632 static void cubicIntersectionSelfTest(skiatest::Reporter* reporter) { |
595 int firstFail = 0; | 633 int firstFail = 0; |
596 for (int index = firstFail; index < selfSetCount; ++index) { | 634 for (int index = firstFail; index < selfSetCount; ++index) { |
597 selfOneOff(reporter, index); | 635 selfOneOff(reporter, index); |
598 } | 636 } |
599 } | 637 } |
600 | 638 |
601 static const SkDCubic coinSet[] = { | 639 static const SkDCubic coinSet[] = { |
| 640 {{{2, 3}, {0, 4}, {3, 2}, {5, 3}}}, |
| 641 {{{2, 3}, {0, 4}, {3, 2}, {5, 3}}}, |
| 642 |
602 {{{317, 711}, {322.52285766601562, 711}, {327, 715.4771728515625}, {327, 721
}}}, | 643 {{{317, 711}, {322.52285766601562, 711}, {327, 715.4771728515625}, {327, 721
}}}, |
603 {{{324.07107543945312, 713.928955078125}, {324.4051513671875, 714.2630004882
8125}, | 644 {{{324.07107543945312, 713.928955078125}, {324.4051513671875, 714.2630004882
8125}, |
604 {324.71566772460937, 714.62060546875}, {325, 714.9990234375}}}, | 645 {324.71566772460937, 714.62060546875}, {325, 714.9990234375}}}, |
605 | |
606 {{{2, 3}, {0, 4}, {3, 2}, {5, 3}}}, | |
607 {{{2, 3}, {0, 4}, {3, 2}, {5, 3}}}, | |
608 }; | 646 }; |
609 | 647 |
610 static int coinSetCount = (int) SK_ARRAY_COUNT(coinSet); | 648 static int coinSetCount = (int) SK_ARRAY_COUNT(coinSet); |
611 | 649 |
612 static void coinOneOff(skiatest::Reporter* reporter, int index) { | 650 static void coinOneOff(skiatest::Reporter* reporter, int index) { |
613 const SkDCubic& cubic1 = coinSet[index]; | 651 const SkDCubic& cubic1 = coinSet[index]; |
614 const SkDCubic& cubic2 = coinSet[index + 1]; | 652 const SkDCubic& cubic2 = coinSet[index + 1]; |
615 oneOff(reporter, cubic1, cubic2, true); | 653 oneOff(reporter, cubic1, cubic2, true); |
616 } | 654 } |
617 | 655 |
(...skipping 17 matching lines...) Expand all Loading... |
635 } | 673 } |
636 | 674 |
637 DEF_TEST(PathOpsCubicIntersection, reporter) { | 675 DEF_TEST(PathOpsCubicIntersection, reporter) { |
638 oneOffTests(reporter); | 676 oneOffTests(reporter); |
639 cubicIntersectionSelfTest(reporter); | 677 cubicIntersectionSelfTest(reporter); |
640 cubicIntersectionCoinTest(reporter); | 678 cubicIntersectionCoinTest(reporter); |
641 standardTestCases(reporter); | 679 standardTestCases(reporter); |
642 if (false) CubicIntersection_IntersectionFinder(); | 680 if (false) CubicIntersection_IntersectionFinder(); |
643 if (false) CubicIntersection_RandTest(reporter); | 681 if (false) CubicIntersection_RandTest(reporter); |
644 } | 682 } |
OLD | NEW |