blob: f6bf8240f53eaf13754caa3c1ae41d808dc88bb5 [file] [log] [blame]
caryclark@google.coma5764232012-03-28 16:20:21 +00001#include "EdgeWalker_Test.h"
2#include "Intersection_Tests.h"
caryclark@google.com198e0542012-03-30 18:47:02 +00003#include "SkBitmap.h"
4
5static SkBitmap bitmap;
caryclark@google.coma5764232012-03-28 16:20:21 +00006
7static void testSimplifyQuadratic1() {
8 SkPath path, out;
9 path.moveTo(0, 0);
10 path.quadTo(1, 0, 1, 1);
11 path.close();
12 path.moveTo(1, 0);
13 path.quadTo(0, 0, 0, 1);
14 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000015 testSimplify(path, true, out, bitmap);
caryclark@google.coma5764232012-03-28 16:20:21 +000016}
17
18static void testSimplifyQuadratic2() {
19 SkPath path, out;
20 path.moveTo(0, 0);
21 path.quadTo(20, 0, 20, 20);
22 path.close();
23 path.moveTo(20, 0);
24 path.quadTo(0, 0, 0, 20);
25 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000026 testSimplify(path, true, out, bitmap);
caryclark@google.coma5764232012-03-28 16:20:21 +000027}
28
29static void testSimplifyQuadratic3() {
30 SkPath path, out;
31 path.moveTo(0, 0);
32 path.quadTo(20, 0, 20, 20);
33 path.close();
34 path.moveTo(0, 20);
35 path.quadTo(0, 0, 20, 0);
36 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000037 testSimplify(path, true, out, bitmap);
38}
39
40static void testSimplifyQuadratic4() {
41 SkPath path, out;
42 path.moveTo(0, 20);
43 path.quadTo(20, 0, 40, 20);
44 path.close();
45 path.moveTo(40, 10);
46 path.quadTo(20, 30, 0, 10);
47 path.close();
48 testSimplify(path, true, out, bitmap);
caryclark@google.coma5764232012-03-28 16:20:21 +000049 drawAsciiPaths(path, out, true);
50}
51
caryclark@google.com78e17132012-04-17 11:40:34 +000052static void testSimplifyQuadratic5() {
53 SkPath path, out;
54 path.moveTo(0, 0);
55 path.quadTo(0, 0, 0, 0);
56 path.lineTo(0, 0);
57 path.close();
58 path.moveTo(0, 0);
59 path.lineTo(0, 0);
60 path.quadTo(0, 0, 0, 1);
61 path.close();
62 testSimplify(path, true, out, bitmap);
63 drawAsciiPaths(path, out, true);
64}
65
66static void testSimplifyQuadratic6() {
67 SkPath path, out;
68 path.moveTo(0, 0);
69 path.quadTo(0, 0, 0, 0);
70 path.lineTo(1, 0);
71 path.close();
72 path.moveTo(0, 0);
73 path.lineTo(0, 0);
74 path.quadTo(1, 0, 0, 1);
75 path.close();
76 testSimplify(path, true, out, bitmap);
77 drawAsciiPaths(path, out, true);
78}
79
80static void testSimplifyQuadratic7() {
81 SkPath path, out;
82 path.moveTo(0, 0);
83 path.quadTo(0, 0, 0, 0);
84 path.lineTo(0, 1);
85 path.close();
86 path.moveTo(0, 0);
87 path.lineTo(0, 0);
88 path.quadTo(1, 0, 0, 2);
89 path.close();
90 testSimplify(path, true, out, bitmap);
91 drawAsciiPaths(path, out, true);
92}
93
94static void testSimplifyQuadratic8() {
95 SkPath path, out;
96 path.moveTo(0, 0);
97 path.quadTo(0, 0, 0, 0);
98 path.lineTo(0, 0);
99 path.close();
100 path.moveTo(0, 0);
101 path.lineTo(0, 0);
102 path.quadTo(1, 0, 0, 2);
103 path.close();
104 testSimplify(path, true, out, bitmap);
105 drawAsciiPaths(path, out, true);
106}
107
108static void testSimplifyQuadratic9() {
109 SkPath path, out;
110 path.moveTo(0, 0);
111 path.quadTo(0, 0, 0, 0);
112 path.lineTo(1, 1);
113 path.close();
114 path.moveTo(0, 0);
115 path.lineTo(0, 0);
116 path.quadTo(1, 0, 2, 2);
117 path.close();
118 testSimplify(path, true, out, bitmap);
119 drawAsciiPaths(path, out, true);
120}
121
122static void testSimplifyQuadratic10() {
123 SkPath path, out;
124 path.moveTo(0, 0);
125 path.quadTo(0, 0, 0, 0);
126 path.lineTo(0, 0);
127 path.close();
128 path.moveTo(0, 0);
129 path.lineTo(0, 1);
130 path.quadTo(1, 1, 1, 2);
131 path.close();
132 testSimplify(path, true, out, bitmap);
133 drawAsciiPaths(path, out, true);
134}
135
136static void testSimplifyQuadratic11() {
137 SkPath path, out;
138 path.moveTo(0, 0);
139 path.quadTo(0, 0, 0, 0);
140 path.lineTo(0, 2);
141 path.close();
142 path.moveTo(0, 0);
143 path.lineTo(2, 1);
144 path.quadTo(2, 2, 3, 3);
145 path.close();
146 testSimplify(path, true, out, bitmap);
147 drawAsciiPaths(path, out, true);
148}
149
150static void testSimplifyQuadratic12() {
151 SkPath path, out;
152 path.moveTo(0, 0);
153 path.lineTo(0, 2);
154 path.lineTo(0, 0);
155 path.close();
156 path.moveTo(3, 0);
157 path.quadTo(1, 1, 0, 2);
158 path.lineTo(3, 0);
159 path.close();
160 testSimplify(path, true, out, bitmap);
161 drawAsciiPaths(path, out, true);
162}
163
164static void testSimplifyQuadratic13() {
165 SkPath path, out;
166path.moveTo(0, 0);
167path.quadTo(0, 0, 1, 0);
168path.lineTo(1, 1);
169path.lineTo(0, 0);
170path.close();
171path.moveTo(0, 0);
172path.quadTo(3, 0, 1, 1);
173path.lineTo(0, 0);
174path.close();
175 testSimplify(path, true, out, bitmap);
176 drawAsciiPaths(path, out, true);
177}
178
179static void testSimplifyQuadratic14() {
180 SkPath path, out;
181 path.moveTo(0, 0);
182 path.quadTo(0, 0, 0, 0);
183 path.lineTo(1, 1);
184 path.close();
185 path.moveTo(0, 0);
186 path.lineTo(0, 0);
187 path.quadTo(0, 1, 2, 1);
188 path.close();
189 testSimplify(path, true, out, bitmap);
190 drawAsciiPaths(path, out, true);
191}
192
193static void testSimplifyQuadratic15() {
194 SkPath path, out;
195 path.moveTo(0, 0);
196 path.quadTo(0, 0, 1, 3);
197 path.lineTo(3, 3);
198 path.close();
199 path.moveTo(0, 1);
200 path.lineTo(1, 1);
201 path.quadTo(0, 3, 3, 3);
202 path.close();
203 testSimplify(path, true, out, bitmap);
204 drawAsciiPaths(path, out, true);
205}
206
207static void testSimplifyQuadratic16() {
208 SkPath path, out;
209 path.moveTo(0, 0);
210 path.quadTo(0, 0, 0, 0);
211 path.lineTo(0, 1);
212 path.close();
213 path.moveTo(0, 0);
214 path.lineTo(0, 0);
215 path.quadTo(1, 0, 0, 1);
216 path.close();
217 testSimplify(path, true, out, bitmap);
218 drawAsciiPaths(path, out, true);
219}
220
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000221static void testSimplifyQuadratic17() {
222 SkPath path, out;
223 path.moveTo(0, 0);
224 path.quadTo(0, 0, 0, 0);
225 path.lineTo(2, 2);
226 path.close();
227 path.moveTo(0, 1);
228 path.lineTo(0, 1);
229 path.quadTo(2, 1, 3, 3);
230 path.close();
231 testSimplify(path, true, out, bitmap);
232 drawAsciiPaths(path, out, true);
233}
234
caryclark@google.coma5764232012-03-28 16:20:21 +0000235static void (*simplifyTests[])() = {
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000236 testSimplifyQuadratic17,
caryclark@google.com78e17132012-04-17 11:40:34 +0000237 testSimplifyQuadratic16,
238 testSimplifyQuadratic15,
239 testSimplifyQuadratic14,
240 testSimplifyQuadratic13,
241 testSimplifyQuadratic12,
242 testSimplifyQuadratic11,
243 testSimplifyQuadratic10,
244 testSimplifyQuadratic9,
245 testSimplifyQuadratic8,
246 testSimplifyQuadratic7,
247 testSimplifyQuadratic6,
248 testSimplifyQuadratic5,
caryclark@google.com198e0542012-03-30 18:47:02 +0000249 testSimplifyQuadratic4,
caryclark@google.coma5764232012-03-28 16:20:21 +0000250 testSimplifyQuadratic3,
251 testSimplifyQuadratic2,
252 testSimplifyQuadratic1,
253};
254
255static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]);
256
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000257static void (*firstTest)() = testSimplifyQuadratic14;
caryclark@google.comfb173422012-04-10 18:28:55 +0000258static bool skipAll = false;
caryclark@google.coma5764232012-03-28 16:20:21 +0000259
260void SimplifyQuadraticPaths_Test() {
caryclark@google.comfb173422012-04-10 18:28:55 +0000261 if (skipAll) {
262 return;
263 }
caryclark@google.coma5764232012-03-28 16:20:21 +0000264 size_t index = 0;
265 if (firstTest) {
266 while (index < simplifyTestsCount && simplifyTests[index] != firstTest) {
267 ++index;
268 }
269 }
270 bool firstTestComplete = false;
271 for ( ; index < simplifyTestsCount; ++index) {
272 (*simplifyTests[index])();
273 if (simplifyTests[index] == testSimplifyQuadratic1) {
274 SkDebugf("%s last fast quad test\n", __FUNCTION__);
275 }
276 firstTestComplete = true;
277 }
278}