blob: bf634f9f7e72f404291f841ff4fcd93fe4dcc251 [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 */
7#include "SkIntersections.h"
8#include "SkTDArray.h"
9#include "Test.h"
10
11// check intersections for consistency
12
13struct Curve {
14 int ptCount;
15 SkDCubic curve; // largest can hold lines / quads/ cubics
16};
17
18static 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
24static 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
31static 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
39static const int testSetsCount = (int) SK_ARRAY_COUNT(testSets);
40
41static 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));
caryclark54359292015-03-26 07:52:43 -070052 SkDLine oLine = {{ oTest.curve[0], oTest.curve[1] }};
53 SkDLine iLine = {{ iTest.curve[0], iTest.curve[1] }};
caryclark45fa4472015-01-16 07:04:10 -080054 if (oTest.ptCount == 1 && iTest.ptCount == 1) {
caryclark54359292015-03-26 07:52:43 -070055 i->intersect(oLine, iLine);
caryclark45fa4472015-01-16 07:04:10 -080056 } else if (oTest.ptCount == 1 && iTest.ptCount == 4) {
caryclark54359292015-03-26 07:52:43 -070057 i->intersect(iTest.curve, oLine);
caryclark45fa4472015-01-16 07:04:10 -080058 } else if (oTest.ptCount == 4 && iTest.ptCount == 1) {
caryclark54359292015-03-26 07:52:43 -070059 i->intersect(oTest.curve, iLine);
caryclark45fa4472015-01-16 07:04:10 -080060 } else if (oTest.ptCount == 4 && iTest.ptCount == 4) {
caryclark54359292015-03-26 07:52:43 -070061 i->intersect(oTest.curve, iTest.curve);
caryclark45fa4472015-01-16 07:04:10 -080062 } else {
63 SkASSERT(0);
64 }
65// i->dump();
66 }
67 }
68}
69
70DEF_TEST(PathOpsThreeWay, reporter) {
71 for (int index = 0; index < testSetsCount; ++index) {
72 testSetTest(reporter, index);
73 reporter->bumpTestCount();
74 }
75}
76
77DEF_TEST(PathOpsThreeWayOneOff, reporter) {
78 int index = 1;
79 testSetTest(reporter, index);
80}