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