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