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