blob: f920ebac53fd374726c9b8ecbd8b2b938b1f754c [file] [log] [blame]
caryclark@google.comfa0588f2012-04-26 21:01:06 +00001#include "CurveIntersection.h"
2#include "Intersections.h"
3#include "LineIntersection.h"
4#include "SkPath.h"
5#include "SkRect.h"
6#include "SkTArray.h"
7#include "SkTDArray.h"
8#include "ShapeOps.h"
9#include "TSearch.h"
caryclark@google.coma833b5c2012-04-30 19:38:50 +000010#include <algorithm> // used for std::min
caryclark@google.comfa0588f2012-04-26 21:01:06 +000011
12namespace SimplifyAddIntersectingTsTest {
13
14#include "Simplify.cpp"
15
16} // end of SimplifyAddIntersectingTsTest namespace
17
18#include "Intersection_Tests.h"
19
20static const SkPoint lines[][2] = {
21 {{ 1, 1}, { 1, 1}}, // degenerate
22 {{ 1, 1}, { 4, 1}}, // horizontal
23 {{ 4, 1}, { 9, 1}},
24 {{ 2, 1}, { 3, 1}},
25 {{ 2, 1}, { 6, 1}},
26 {{ 5, 1}, { 9, 1}},
27 {{ 1, 1}, { 1, 4}}, // vertical
28 {{ 1, 2}, { 1, 3}},
29 {{ 1, 2}, { 1, 6}},
30 {{ 1, 5}, { 1, 9}},
31 {{ 1, 1}, { 3, 3}}, // diagonal
32 {{ 2, 2}, { 4, 4}},
33 {{ 2, 4}, { 4, 2}},
34};
35
36static const size_t lineCount = sizeof(lines) / sizeof(lines[0]);
37
38static const SkPoint quads[][3] = {
39 {{ 1, 1}, { 1, 1}, { 1, 1}}, // degenerate
40 {{ 1, 1}, { 4, 1}, { 5, 1}}, // line
41 {{ 1, 1}, { 4, 1}, { 4, 4}}, // curve
42};
43
44static const size_t quadCount = sizeof(quads) / sizeof(quads[0]);
45
46static const SkPoint cubics[][4] = {
47 {{ 1, 1}, { 1, 1}, { 1, 1}, { 1, 1}}, // degenerate
48 {{ 1, 1}, { 4, 1}, { 5, 1}, { 6, 1}}, // line
49 {{ 1, 1}, { 3, 1}, { 4, 2}, { 4, 4}}, // curve
50};
51
52static const size_t cubicCount = sizeof(cubics) / sizeof(cubics[0]);
53static const size_t testCount = lineCount + quadCount + cubicCount;
54
55static SkPath::Verb setPath(int outer, SkPath& path, const SkPoint*& pts1) {
56 SkPath::Verb c1Type;
57 if (outer < lineCount) {
58 path.moveTo(lines[outer][0].fX, lines[outer][0].fY);
59 path.lineTo(lines[outer][1].fX, lines[outer][1].fY);
60 c1Type = SkPath::kLine_Verb;
61 pts1 = lines[outer];
62 } else {
63 outer -= lineCount;
64 if (outer < quadCount) {
65 path.moveTo(quads[outer][0].fX, quads[outer][0].fY);
66 path.quadTo(quads[outer][1].fX, quads[outer][1].fY,
67 quads[outer][2].fX, quads[outer][2].fY);
68 c1Type = SkPath::kQuad_Verb;
69 pts1 = quads[outer];
70 } else {
71 outer -= quadCount;
72 path.moveTo(cubics[outer][0].fX, cubics[outer][0].fY);
73 path.cubicTo(cubics[outer][1].fX, cubics[outer][1].fY,
74 cubics[outer][2].fX, cubics[outer][2].fY,
75 cubics[outer][3].fX, cubics[outer][3].fY);
76 c1Type = SkPath::kCubic_Verb;
77 pts1 = cubics[outer];
78 }
79 }
80 return c1Type;
81}
82
83static void testPath(const SkPath& path, const SkPoint* pts1, SkPath::Verb c1Type,
84 const SkPoint* pts2, SkPath::Verb c2Type) {
85 SkTArray<SimplifyAddIntersectingTsTest::Contour> contour;
86 SimplifyAddIntersectingTsTest::EdgeBuilder builder(path, contour);
87 if (contour.count() < 2) {
88 return;
89 }
90 SimplifyAddIntersectingTsTest::Contour& c1 = contour[0];
91 SimplifyAddIntersectingTsTest::Contour& c2 = contour[1];
caryclark@google.coma833b5c2012-04-30 19:38:50 +000092 addIntersectTs(&c1, &c2, 1);
caryclark@google.comfa0588f2012-04-26 21:01:06 +000093 bool c1Intersected = c1.fSegments[0].intersected();
94 bool c2Intersected = c2.fSegments[0].intersected();
95#if DEBUG_DUMP
96 SkDebugf("%s %s (%1.9g,%1.9g %1.9g,%1.9g) %s %s (%1.9g,%1.9g %1.9g,%1.9g)\n",
97 __FUNCTION__, SimplifyAddIntersectingTsTest::kLVerbStr[c1Type],
98 pts1[0].fX, pts1[0].fY,
99 pts1[c1Type].fX, pts1[c1Type].fY,
100 c1Intersected ? "intersects" : "does not intersect",
101 SimplifyAddIntersectingTsTest::kLVerbStr[c2Type],
102 pts2[0].fX, pts2[0].fY,
103 pts2[c2Type].fX, pts2[c2Type].fY);
104 if (c1Intersected) {
105 c1.dump();
106 c2.dump();
107 }
108#endif
109}
110
111static const int firstO = 6;
112static const int firstI = 1;
113
114void SimplifyAddIntersectingTs_Test() {
115 const SkPoint* pts1, * pts2;
116 if (firstO > 0 || firstI > 0) {
117 SkPath path;
118 SkPath::Verb c1Type = setPath(firstO, path, pts1);
119 SkPath path2(path);
120 SkPath::Verb c2Type = setPath(firstI, path2, pts2);
121 testPath(path2, pts1, c1Type, pts2, c2Type);
122 }
123 for (int o = 0; o < testCount; ++o) {
124 SkPath path;
125 SkPath::Verb c1Type = setPath(o, path, pts1);
126 for (int i = 0; i < testCount; ++i) {
127 SkPath path2(path);
128 SkPath::Verb c2Type = setPath(i, path2, pts2);
129 testPath(path2, pts1, c1Type, pts2, c2Type);
130 }
131 }
132}
133