1cb93a386Sopenharmony_ci/* 2cb93a386Sopenharmony_ci * Copyright 2014 Google Inc. 3cb93a386Sopenharmony_ci * 4cb93a386Sopenharmony_ci * Use of this source code is governed by a BSD-style license that can be 5cb93a386Sopenharmony_ci * found in the LICENSE file. 6cb93a386Sopenharmony_ci */ 7cb93a386Sopenharmony_ci#include "include/private/SkTDArray.h" 8cb93a386Sopenharmony_ci#include "src/pathops/SkIntersections.h" 9cb93a386Sopenharmony_ci#include "tests/PathOpsTestCommon.h" 10cb93a386Sopenharmony_ci#include "tests/Test.h" 11cb93a386Sopenharmony_ci 12cb93a386Sopenharmony_ci// check intersections for consistency 13cb93a386Sopenharmony_ci 14cb93a386Sopenharmony_cistruct Curve { 15cb93a386Sopenharmony_ci int ptCount; 16cb93a386Sopenharmony_ci CubicPts curve; // largest can hold lines / quads/ cubics 17cb93a386Sopenharmony_ci}; 18cb93a386Sopenharmony_ci 19cb93a386Sopenharmony_cistatic const Curve testSet0[] = { // extracted from skpClip2 20cb93a386Sopenharmony_ci {4, {{{134,11414}, {131.990234,11414}, {130.32666,11415.4824}, {130.042755,11417.4131}}} }, 21cb93a386Sopenharmony_ci {4, {{{130.042755,11417.4131}, {130.233124,11418.3193}, {131.037079,11419}, {132,11419}}} }, 22cb93a386Sopenharmony_ci {4, {{{132,11419}, {130.895432,11419}, {130,11418.1045}, {130,11417}}} }, 23cb93a386Sopenharmony_ci}; 24cb93a386Sopenharmony_ci 25cb93a386Sopenharmony_cistatic const Curve testSet1[] = { // extracted from cubicOp85i 26cb93a386Sopenharmony_ci {4, {{{3,4}, {1,5}, {4,3}, {6,4}}} }, 27cb93a386Sopenharmony_ci {1, {{{6,4}, {3,4}}} }, 28cb93a386Sopenharmony_ci {4, {{{3,4}, {4,6}, {4,3}, {5,1}}} }, 29cb93a386Sopenharmony_ci {1, {{{5,1}, {3,4}}} }, 30cb93a386Sopenharmony_ci}; 31cb93a386Sopenharmony_ci 32cb93a386Sopenharmony_cistatic const struct TestSet { 33cb93a386Sopenharmony_ci const Curve* tests; 34cb93a386Sopenharmony_ci int testCount; 35cb93a386Sopenharmony_ci} testSets[] = { 36cb93a386Sopenharmony_ci { testSet0, (int) SK_ARRAY_COUNT(testSet0) }, 37cb93a386Sopenharmony_ci { testSet1, (int) SK_ARRAY_COUNT(testSet1) }, 38cb93a386Sopenharmony_ci}; 39cb93a386Sopenharmony_ci 40cb93a386Sopenharmony_cistatic const int testSetsCount = (int) SK_ARRAY_COUNT(testSets); 41cb93a386Sopenharmony_ci 42cb93a386Sopenharmony_cistatic void testSetTest(skiatest::Reporter* reporter, int index) { 43cb93a386Sopenharmony_ci const TestSet& testSet = testSets[index]; 44cb93a386Sopenharmony_ci int testCount = testSet.testCount; 45cb93a386Sopenharmony_ci SkASSERT(testCount > 1); 46cb93a386Sopenharmony_ci SkTDArray<SkIntersections> combos; 47cb93a386Sopenharmony_ci for (int outer = 0; outer < testCount - 1; ++outer) { 48cb93a386Sopenharmony_ci const Curve& oTest = testSet.tests[outer]; 49cb93a386Sopenharmony_ci for (int inner = outer + 1; inner < testCount; ++inner) { 50cb93a386Sopenharmony_ci const Curve& iTest = testSet.tests[inner]; 51cb93a386Sopenharmony_ci SkIntersections* i = combos.append(); 52cb93a386Sopenharmony_ci sk_bzero(i, sizeof(SkIntersections)); 53cb93a386Sopenharmony_ci SkDLine oLine = {{ oTest.curve.fPts[0], oTest.curve.fPts[1] }}; 54cb93a386Sopenharmony_ci SkDLine iLine = {{ iTest.curve.fPts[0], iTest.curve.fPts[1] }}; 55cb93a386Sopenharmony_ci SkDCubic iCurve, oCurve; 56cb93a386Sopenharmony_ci iCurve.debugSet(iTest.curve.fPts); 57cb93a386Sopenharmony_ci oCurve.debugSet(oTest.curve.fPts); 58cb93a386Sopenharmony_ci if (oTest.ptCount == 1 && iTest.ptCount == 1) { 59cb93a386Sopenharmony_ci i->intersect(oLine, iLine); 60cb93a386Sopenharmony_ci } else if (oTest.ptCount == 1 && iTest.ptCount == 4) { 61cb93a386Sopenharmony_ci i->intersect(iCurve, oLine); 62cb93a386Sopenharmony_ci } else if (oTest.ptCount == 4 && iTest.ptCount == 1) { 63cb93a386Sopenharmony_ci i->intersect(oCurve, iLine); 64cb93a386Sopenharmony_ci } else if (oTest.ptCount == 4 && iTest.ptCount == 4) { 65cb93a386Sopenharmony_ci i->intersect(oCurve, iCurve); 66cb93a386Sopenharmony_ci } else { 67cb93a386Sopenharmony_ci SkASSERT(0); 68cb93a386Sopenharmony_ci } 69cb93a386Sopenharmony_ci// i->dump(); 70cb93a386Sopenharmony_ci } 71cb93a386Sopenharmony_ci } 72cb93a386Sopenharmony_ci} 73cb93a386Sopenharmony_ci 74cb93a386Sopenharmony_ciDEF_TEST(PathOpsThreeWay, reporter) { 75cb93a386Sopenharmony_ci for (int index = 0; index < testSetsCount; ++index) { 76cb93a386Sopenharmony_ci testSetTest(reporter, index); 77cb93a386Sopenharmony_ci reporter->bumpTestCount(); 78cb93a386Sopenharmony_ci } 79cb93a386Sopenharmony_ci} 80cb93a386Sopenharmony_ci 81cb93a386Sopenharmony_ciDEF_TEST(PathOpsThreeWayOneOff, reporter) { 82cb93a386Sopenharmony_ci int index = 0; 83cb93a386Sopenharmony_ci testSetTest(reporter, index); 84cb93a386Sopenharmony_ci} 85