Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(452)

Side by Side Diff: experimental/Intersection/SimplifyAddIntersectingTs_Test.cpp

Issue 867213004: remove prototype pathops code (Closed) Base URL: https://skia.googlesource.com/skia.git@master
Patch Set: Created 5 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /*
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"
8
9 namespace SimplifyAddIntersectingTsTest {
10
11 #include "Simplify.cpp"
12
13 } // end of SimplifyAddIntersectingTsTest namespace
14 /*
15 * Copyright 2012 Google Inc.
16 *
17 * Use of this source code is governed by a BSD-style license that can be
18 * found in the LICENSE file.
19 */
20
21 #include "Intersection_Tests.h"
22
23 static const SkPoint lines[][2] = {
24 {{ 1, 1}, { 1, 1}}, // degenerate
25 {{ 1, 1}, { 4, 1}}, // horizontal
26 {{ 4, 1}, { 9, 1}},
27 {{ 2, 1}, { 3, 1}},
28 {{ 2, 1}, { 6, 1}},
29 {{ 5, 1}, { 9, 1}},
30 {{ 1, 1}, { 1, 4}}, // vertical
31 {{ 1, 2}, { 1, 3}},
32 {{ 1, 2}, { 1, 6}},
33 {{ 1, 5}, { 1, 9}},
34 {{ 1, 1}, { 3, 3}}, // diagonal
35 {{ 2, 2}, { 4, 4}},
36 {{ 2, 4}, { 4, 2}},
37 };
38
39 static const size_t lineCount = sizeof(lines) / sizeof(lines[0]);
40
41 static const SkPoint quads[][3] = {
42 {{ 1, 1}, { 1, 1}, { 1, 1}}, // degenerate
43 {{ 1, 1}, { 4, 1}, { 5, 1}}, // line
44 {{ 1, 1}, { 4, 1}, { 4, 4}}, // curve
45 };
46
47 static const size_t quadCount = sizeof(quads) / sizeof(quads[0]);
48
49 static const SkPoint cubics[][4] = {
50 {{ 1, 1}, { 1, 1}, { 1, 1}, { 1, 1}}, // degenerate
51 {{ 1, 1}, { 4, 1}, { 5, 1}, { 6, 1}}, // line
52 {{ 1, 1}, { 3, 1}, { 4, 2}, { 4, 4}}, // curve
53 };
54
55 static const size_t cubicCount = sizeof(cubics) / sizeof(cubics[0]);
56 static const size_t testCount = lineCount + quadCount + cubicCount;
57
58 static SkPath::Verb setPath(size_t outer, SkPath& path, const SkPoint*& pts1) {
59 SkPath::Verb c1Type;
60 if (outer < lineCount) {
61 path.moveTo(lines[outer][0].fX, lines[outer][0].fY);
62 path.lineTo(lines[outer][1].fX, lines[outer][1].fY);
63 c1Type = SkPath::kLine_Verb;
64 pts1 = lines[outer];
65 } else {
66 outer -= lineCount;
67 if (outer < quadCount) {
68 path.moveTo(quads[outer][0].fX, quads[outer][0].fY);
69 path.quadTo(quads[outer][1].fX, quads[outer][1].fY,
70 quads[outer][2].fX, quads[outer][2].fY);
71 c1Type = SkPath::kQuad_Verb;
72 pts1 = quads[outer];
73 } else {
74 outer -= quadCount;
75 path.moveTo(cubics[outer][0].fX, cubics[outer][0].fY);
76 path.cubicTo(cubics[outer][1].fX, cubics[outer][1].fY,
77 cubics[outer][2].fX, cubics[outer][2].fY,
78 cubics[outer][3].fX, cubics[outer][3].fY);
79 c1Type = SkPath::kCubic_Verb;
80 pts1 = cubics[outer];
81 }
82 }
83 return c1Type;
84 }
85
86 static void testPath(const SkPath& path, const SkPoint* pts1, SkPath::Verb c1Typ e,
87 const SkPoint* pts2, SkPath::Verb c2Type) {
88 SkTArray<SimplifyAddIntersectingTsTest::Contour> contour;
89 SimplifyAddIntersectingTsTest::EdgeBuilder builder(path, contour);
90 if (contour.count() < 2) {
91 return;
92 }
93 SimplifyAddIntersectingTsTest::Contour& c1 = contour[0];
94 SimplifyAddIntersectingTsTest::Contour& c2 = contour[1];
95 addIntersectTs(&c1, &c2);
96 #if DEBUG_DUMP
97 bool c1Intersected = c1.segments()[0].intersected();
98 // bool c2Intersected = c2.fSegments[0].intersected();
99 SkDebugf("%s %s (%1.9g,%1.9g %1.9g,%1.9g) %s %s (%1.9g,%1.9g %1.9g,%1.9g)\n" ,
100 __FUNCTION__, SimplifyAddIntersectingTsTest::kLVerbStr[c1Type],
101 pts1[0].fX, pts1[0].fY,
102 pts1[c1Type].fX, pts1[c1Type].fY,
103 c1Intersected ? "intersects" : "does not intersect",
104 SimplifyAddIntersectingTsTest::kLVerbStr[c2Type],
105 pts2[0].fX, pts2[0].fY,
106 pts2[c2Type].fX, pts2[c2Type].fY);
107 if (c1Intersected) {
108 c1.dump();
109 c2.dump();
110 }
111 #endif
112 }
113
114 static const size_t firstO = 6;
115 static const size_t firstI = 1;
116
117 void SimplifyAddIntersectingTs_Test() {
118 const SkPoint* pts1, * pts2;
119 if (firstO > 0 || firstI > 0) {
120 SkPath path;
121 SkPath::Verb c1Type = setPath(firstO, path, pts1);
122 SkPath path2(path);
123 SkPath::Verb c2Type = setPath(firstI, path2, pts2);
124 testPath(path2, pts1, c1Type, pts2, c2Type);
125 }
126 for (size_t o = 0; o < testCount; ++o) {
127 SkPath path;
128 SkPath::Verb c1Type = setPath(o, path, pts1);
129 for (size_t i = 0; i < testCount; ++i) {
130 SkPath path2(path);
131 SkPath::Verb c2Type = setPath(i, path2, pts2);
132 testPath(path2, pts1, c1Type, pts2, c2Type);
133 }
134 }
135 }
OLDNEW
« no previous file with comments | « experimental/Intersection/Simplify.cpp ('k') | experimental/Intersection/SimplifyAngle_Test.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698