caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 7 | #include "PathOpsTestCommon.h" |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 8 | #include "SkIntersections.h" |
| 9 | #include "SkTDArray.h" |
| 10 | #include "Test.h" |
| 11 | |
| 12 | // check intersections for consistency |
| 13 | |
| 14 | struct Curve { |
| 15 | int ptCount; |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 16 | CubicPts curve; // largest can hold lines / quads/ cubics |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | static const Curve testSet0[] = { // extracted from skpClip2 |
| 20 | {4, {{{134,11414}, {131.990234,11414}, {130.32666,11415.4824}, {130.042755,11417.4131}}} }, |
| 21 | {4, {{{130.042755,11417.4131}, {130.233124,11418.3193}, {131.037079,11419}, {132,11419}}} }, |
| 22 | {4, {{{132,11419}, {130.895432,11419}, {130,11418.1045}, {130,11417}}} }, |
| 23 | }; |
| 24 | |
| 25 | static const Curve testSet1[] = { // extracted from cubicOp85i |
| 26 | {4, {{{3,4}, {1,5}, {4,3}, {6,4}}} }, |
| 27 | {1, {{{6,4}, {3,4}}} }, |
| 28 | {4, {{{3,4}, {4,6}, {4,3}, {5,1}}} }, |
| 29 | {1, {{{5,1}, {3,4}}} }, |
| 30 | }; |
| 31 | |
| 32 | static const struct TestSet { |
| 33 | const Curve* tests; |
| 34 | int testCount; |
| 35 | } testSets[] = { |
| 36 | { testSet0, (int) SK_ARRAY_COUNT(testSet0) }, |
| 37 | { testSet1, (int) SK_ARRAY_COUNT(testSet1) }, |
| 38 | }; |
| 39 | |
| 40 | static const int testSetsCount = (int) SK_ARRAY_COUNT(testSets); |
| 41 | |
| 42 | static void testSetTest(skiatest::Reporter* reporter, int index) { |
| 43 | const TestSet& testSet = testSets[index]; |
| 44 | int testCount = testSet.testCount; |
| 45 | SkASSERT(testCount > 1); |
| 46 | SkTDArray<SkIntersections> combos; |
| 47 | for (int outer = 0; outer < testCount - 1; ++outer) { |
| 48 | const Curve& oTest = testSet.tests[outer]; |
| 49 | for (int inner = outer + 1; inner < testCount; ++inner) { |
| 50 | const Curve& iTest = testSet.tests[inner]; |
| 51 | SkIntersections* i = combos.append(); |
| 52 | sk_bzero(i, sizeof(SkIntersections)); |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 53 | SkDLine oLine = {{ oTest.curve.fPts[0], oTest.curve.fPts[1] }}; |
| 54 | SkDLine iLine = {{ iTest.curve.fPts[0], iTest.curve.fPts[1] }}; |
| 55 | SkDCubic iCurve, oCurve; |
| 56 | iCurve.debugSet(iTest.curve.fPts); |
| 57 | oCurve.debugSet(oTest.curve.fPts); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 58 | if (oTest.ptCount == 1 && iTest.ptCount == 1) { |
caryclark | 5435929 | 2015-03-26 07:52:43 -0700 | [diff] [blame] | 59 | i->intersect(oLine, iLine); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 60 | } else if (oTest.ptCount == 1 && iTest.ptCount == 4) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 61 | i->intersect(iCurve, oLine); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 62 | } else if (oTest.ptCount == 4 && iTest.ptCount == 1) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 63 | i->intersect(oCurve, iLine); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 64 | } else if (oTest.ptCount == 4 && iTest.ptCount == 4) { |
caryclark | a35ab3e | 2016-10-20 08:32:18 -0700 | [diff] [blame] | 65 | i->intersect(oCurve, iCurve); |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 66 | } else { |
| 67 | SkASSERT(0); |
| 68 | } |
| 69 | // i->dump(); |
| 70 | } |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | DEF_TEST(PathOpsThreeWay, reporter) { |
| 75 | for (int index = 0; index < testSetsCount; ++index) { |
| 76 | testSetTest(reporter, index); |
| 77 | reporter->bumpTestCount(); |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | DEF_TEST(PathOpsThreeWayOneOff, reporter) { |
caryclark | 27c015d | 2016-09-23 05:47:20 -0700 | [diff] [blame] | 82 | int index = 0; |
caryclark | 45fa447 | 2015-01-16 07:04:10 -0800 | [diff] [blame] | 83 | testSetTest(reporter, index); |
| 84 | } |