blob: 0a4127b4d1e514bea18235cdd7d2c5f93422b114 [file] [log] [blame]
caryclark45fa4472015-01-16 07:04:10 -08001/*
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 */
Mike Kleinc0bd9f92019-04-23 12:05:21 -05007#include "include/private/SkTDArray.h"
8#include "src/pathops/SkIntersections.h"
9#include "tests/PathOpsTestCommon.h"
10#include "tests/Test.h"
caryclark45fa4472015-01-16 07:04:10 -080011
12// check intersections for consistency
13
14struct Curve {
15 int ptCount;
caryclarka35ab3e2016-10-20 08:32:18 -070016 CubicPts curve; // largest can hold lines / quads/ cubics
caryclark45fa4472015-01-16 07:04:10 -080017};
18
19static 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
25static 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
32static 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
40static const int testSetsCount = (int) SK_ARRAY_COUNT(testSets);
41
42static 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));
caryclarka35ab3e2016-10-20 08:32:18 -070053 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);
caryclark45fa4472015-01-16 07:04:10 -080058 if (oTest.ptCount == 1 && iTest.ptCount == 1) {
caryclark54359292015-03-26 07:52:43 -070059 i->intersect(oLine, iLine);
caryclark45fa4472015-01-16 07:04:10 -080060 } else if (oTest.ptCount == 1 && iTest.ptCount == 4) {
caryclarka35ab3e2016-10-20 08:32:18 -070061 i->intersect(iCurve, oLine);
caryclark45fa4472015-01-16 07:04:10 -080062 } else if (oTest.ptCount == 4 && iTest.ptCount == 1) {
caryclarka35ab3e2016-10-20 08:32:18 -070063 i->intersect(oCurve, iLine);
caryclark45fa4472015-01-16 07:04:10 -080064 } else if (oTest.ptCount == 4 && iTest.ptCount == 4) {
caryclarka35ab3e2016-10-20 08:32:18 -070065 i->intersect(oCurve, iCurve);
caryclark45fa4472015-01-16 07:04:10 -080066 } else {
67 SkASSERT(0);
68 }
69// i->dump();
70 }
71 }
72}
73
74DEF_TEST(PathOpsThreeWay, reporter) {
75 for (int index = 0; index < testSetsCount; ++index) {
76 testSetTest(reporter, index);
77 reporter->bumpTestCount();
78 }
79}
80
81DEF_TEST(PathOpsThreeWayOneOff, reporter) {
caryclark27c015d2016-09-23 05:47:20 -070082 int index = 0;
caryclark45fa4472015-01-16 07:04:10 -080083 testSetTest(reporter, index);
84}