blob: febc9722595dc3b6c05392450d37e24efbf8bbc1 [file] [log] [blame]
caryclark@google.com9e49fb62012-08-27 14:11: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 */
caryclark@google.coma5764232012-03-28 16:20:21 +00007#include "EdgeWalker_Test.h"
8#include "Intersection_Tests.h"
caryclark@google.com198e0542012-03-30 18:47:02 +00009#include "SkBitmap.h"
10
11static SkBitmap bitmap;
caryclark@google.coma5764232012-03-28 16:20:21 +000012
13static void testSimplifyQuadratic1() {
14 SkPath path, out;
15 path.moveTo(0, 0);
16 path.quadTo(1, 0, 1, 1);
17 path.close();
18 path.moveTo(1, 0);
19 path.quadTo(0, 0, 0, 1);
20 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000021 testSimplify(path, true, out, bitmap);
caryclark@google.coma5764232012-03-28 16:20:21 +000022}
23
24static void testSimplifyQuadratic2() {
25 SkPath path, out;
26 path.moveTo(0, 0);
27 path.quadTo(20, 0, 20, 20);
28 path.close();
29 path.moveTo(20, 0);
30 path.quadTo(0, 0, 0, 20);
31 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000032 testSimplify(path, true, out, bitmap);
caryclark@google.coma5764232012-03-28 16:20:21 +000033}
34
35static void testSimplifyQuadratic3() {
36 SkPath path, out;
37 path.moveTo(0, 0);
38 path.quadTo(20, 0, 20, 20);
39 path.close();
40 path.moveTo(0, 20);
41 path.quadTo(0, 0, 20, 0);
42 path.close();
caryclark@google.com198e0542012-03-30 18:47:02 +000043 testSimplify(path, true, out, bitmap);
44}
45
46static void testSimplifyQuadratic4() {
47 SkPath path, out;
48 path.moveTo(0, 20);
49 path.quadTo(20, 0, 40, 20);
50 path.close();
51 path.moveTo(40, 10);
52 path.quadTo(20, 30, 0, 10);
53 path.close();
54 testSimplify(path, true, out, bitmap);
caryclark@google.coma5764232012-03-28 16:20:21 +000055 drawAsciiPaths(path, out, true);
56}
57
caryclark@google.com78e17132012-04-17 11:40:34 +000058static void testSimplifyQuadratic5() {
59 SkPath path, out;
60 path.moveTo(0, 0);
61 path.quadTo(0, 0, 0, 0);
62 path.lineTo(0, 0);
63 path.close();
64 path.moveTo(0, 0);
65 path.lineTo(0, 0);
66 path.quadTo(0, 0, 0, 1);
67 path.close();
68 testSimplify(path, true, out, bitmap);
69 drawAsciiPaths(path, out, true);
70}
71
72static void testSimplifyQuadratic6() {
73 SkPath path, out;
74 path.moveTo(0, 0);
75 path.quadTo(0, 0, 0, 0);
76 path.lineTo(1, 0);
77 path.close();
78 path.moveTo(0, 0);
79 path.lineTo(0, 0);
80 path.quadTo(1, 0, 0, 1);
81 path.close();
82 testSimplify(path, true, out, bitmap);
83 drawAsciiPaths(path, out, true);
84}
85
86static void testSimplifyQuadratic7() {
87 SkPath path, out;
88 path.moveTo(0, 0);
89 path.quadTo(0, 0, 0, 0);
90 path.lineTo(0, 1);
91 path.close();
92 path.moveTo(0, 0);
93 path.lineTo(0, 0);
94 path.quadTo(1, 0, 0, 2);
95 path.close();
96 testSimplify(path, true, out, bitmap);
97 drawAsciiPaths(path, out, true);
98}
99
100static void testSimplifyQuadratic8() {
101 SkPath path, out;
102 path.moveTo(0, 0);
103 path.quadTo(0, 0, 0, 0);
104 path.lineTo(0, 0);
105 path.close();
106 path.moveTo(0, 0);
107 path.lineTo(0, 0);
108 path.quadTo(1, 0, 0, 2);
109 path.close();
110 testSimplify(path, true, out, bitmap);
111 drawAsciiPaths(path, out, true);
112}
113
114static void testSimplifyQuadratic9() {
115 SkPath path, out;
116 path.moveTo(0, 0);
117 path.quadTo(0, 0, 0, 0);
118 path.lineTo(1, 1);
119 path.close();
120 path.moveTo(0, 0);
121 path.lineTo(0, 0);
122 path.quadTo(1, 0, 2, 2);
123 path.close();
124 testSimplify(path, true, out, bitmap);
125 drawAsciiPaths(path, out, true);
126}
127
128static void testSimplifyQuadratic10() {
129 SkPath path, out;
130 path.moveTo(0, 0);
131 path.quadTo(0, 0, 0, 0);
132 path.lineTo(0, 0);
133 path.close();
134 path.moveTo(0, 0);
135 path.lineTo(0, 1);
136 path.quadTo(1, 1, 1, 2);
137 path.close();
138 testSimplify(path, true, out, bitmap);
139 drawAsciiPaths(path, out, true);
140}
141
142static void testSimplifyQuadratic11() {
143 SkPath path, out;
144 path.moveTo(0, 0);
145 path.quadTo(0, 0, 0, 0);
146 path.lineTo(0, 2);
147 path.close();
148 path.moveTo(0, 0);
149 path.lineTo(2, 1);
150 path.quadTo(2, 2, 3, 3);
151 path.close();
152 testSimplify(path, true, out, bitmap);
153 drawAsciiPaths(path, out, true);
154}
155
156static void testSimplifyQuadratic12() {
157 SkPath path, out;
158 path.moveTo(0, 0);
159 path.lineTo(0, 2);
160 path.lineTo(0, 0);
161 path.close();
162 path.moveTo(3, 0);
163 path.quadTo(1, 1, 0, 2);
164 path.lineTo(3, 0);
165 path.close();
166 testSimplify(path, true, out, bitmap);
167 drawAsciiPaths(path, out, true);
168}
169
170static void testSimplifyQuadratic13() {
171 SkPath path, out;
172path.moveTo(0, 0);
173path.quadTo(0, 0, 1, 0);
174path.lineTo(1, 1);
175path.lineTo(0, 0);
176path.close();
177path.moveTo(0, 0);
178path.quadTo(3, 0, 1, 1);
179path.lineTo(0, 0);
180path.close();
181 testSimplify(path, true, out, bitmap);
182 drawAsciiPaths(path, out, true);
183}
184
185static void testSimplifyQuadratic14() {
186 SkPath path, out;
187 path.moveTo(0, 0);
188 path.quadTo(0, 0, 0, 0);
189 path.lineTo(1, 1);
190 path.close();
191 path.moveTo(0, 0);
192 path.lineTo(0, 0);
193 path.quadTo(0, 1, 2, 1);
194 path.close();
195 testSimplify(path, true, out, bitmap);
196 drawAsciiPaths(path, out, true);
197}
198
199static void testSimplifyQuadratic15() {
200 SkPath path, out;
201 path.moveTo(0, 0);
202 path.quadTo(0, 0, 1, 3);
203 path.lineTo(3, 3);
204 path.close();
205 path.moveTo(0, 1);
206 path.lineTo(1, 1);
207 path.quadTo(0, 3, 3, 3);
208 path.close();
209 testSimplify(path, true, out, bitmap);
210 drawAsciiPaths(path, out, true);
211}
212
213static void testSimplifyQuadratic16() {
214 SkPath path, out;
215 path.moveTo(0, 0);
216 path.quadTo(0, 0, 0, 0);
217 path.lineTo(0, 1);
218 path.close();
219 path.moveTo(0, 0);
220 path.lineTo(0, 0);
221 path.quadTo(1, 0, 0, 1);
222 path.close();
223 testSimplify(path, true, out, bitmap);
224 drawAsciiPaths(path, out, true);
225}
226
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000227static void testSimplifyQuadratic17() {
228 SkPath path, out;
229 path.moveTo(0, 0);
230 path.quadTo(0, 0, 0, 0);
231 path.lineTo(2, 2);
232 path.close();
233 path.moveTo(0, 1);
234 path.lineTo(0, 1);
235 path.quadTo(2, 1, 3, 3);
236 path.close();
237 testSimplify(path, true, out, bitmap);
238 drawAsciiPaths(path, out, true);
239}
240
caryclark@google.coma5764232012-03-28 16:20:21 +0000241static void (*simplifyTests[])() = {
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000242 testSimplifyQuadratic17,
caryclark@google.com78e17132012-04-17 11:40:34 +0000243 testSimplifyQuadratic16,
244 testSimplifyQuadratic15,
245 testSimplifyQuadratic14,
246 testSimplifyQuadratic13,
247 testSimplifyQuadratic12,
248 testSimplifyQuadratic11,
249 testSimplifyQuadratic10,
250 testSimplifyQuadratic9,
251 testSimplifyQuadratic8,
252 testSimplifyQuadratic7,
253 testSimplifyQuadratic6,
254 testSimplifyQuadratic5,
caryclark@google.com198e0542012-03-30 18:47:02 +0000255 testSimplifyQuadratic4,
caryclark@google.coma5764232012-03-28 16:20:21 +0000256 testSimplifyQuadratic3,
257 testSimplifyQuadratic2,
258 testSimplifyQuadratic1,
259};
260
261static size_t simplifyTestsCount = sizeof(simplifyTests) / sizeof(simplifyTests[0]);
262
caryclark@google.comfa0588f2012-04-26 21:01:06 +0000263static void (*firstTest)() = testSimplifyQuadratic14;
caryclark@google.comfb173422012-04-10 18:28:55 +0000264static bool skipAll = false;
caryclark@google.coma5764232012-03-28 16:20:21 +0000265
266void SimplifyQuadraticPaths_Test() {
caryclark@google.comfb173422012-04-10 18:28:55 +0000267 if (skipAll) {
268 return;
269 }
caryclark@google.coma5764232012-03-28 16:20:21 +0000270 size_t index = 0;
271 if (firstTest) {
272 while (index < simplifyTestsCount && simplifyTests[index] != firstTest) {
273 ++index;
274 }
275 }
276 bool firstTestComplete = false;
277 for ( ; index < simplifyTestsCount; ++index) {
278 (*simplifyTests[index])();
279 if (simplifyTests[index] == testSimplifyQuadratic1) {
280 SkDebugf("%s last fast quad test\n", __FUNCTION__);
281 }
282 firstTestComplete = true;
283 }
284}