blob: 3f07ae04bc5aa87396bf512c928ae0ec75ef6600 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 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 */
reed@google.comcc8be772013-10-15 15:35:29 +00007
reed@android.com3abec1d2009-03-02 05:36:20 +00008#include "Test.h"
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +00009#include "TestClassDef.h"
reed@google.com8cae8352012-09-14 15:18:41 +000010#include "SkCanvas.h"
reed@google.com55b5f4b2011-09-07 12:23:41 +000011#include "SkPaint.h"
reed@android.com3abec1d2009-03-02 05:36:20 +000012#include "SkPath.h"
reed@google.com04863fa2011-05-15 04:08:24 +000013#include "SkParse.h"
reed@google.com3e71a882012-01-10 18:44:37 +000014#include "SkParsePath.h"
reed@google.com8b06f1a2012-05-29 12:03:46 +000015#include "SkPathEffect.h"
schenney@chromium.org6630d8d2012-01-04 21:05:51 +000016#include "SkRandom.h"
reed@google.com53effc52011-09-21 19:05:12 +000017#include "SkReader32.h"
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +000018#include "SkRRect.h"
reed@android.com60bc6d52010-02-11 11:09:39 +000019#include "SkSize.h"
reed@google.com8cae8352012-09-14 15:18:41 +000020#include "SkSurface.h"
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000021#include "SkTypes.h"
22#include "SkWriter32.h"
reed@google.com8cae8352012-09-14 15:18:41 +000023
reed@google.comcc8be772013-10-15 15:35:29 +000024static void make_path0(SkPath* path) {
25 // from * https://code.google.com/p/skia/issues/detail?id=1706
26
27 path->moveTo(146.939f, 1012.84f);
28 path->lineTo(181.747f, 1009.18f);
29 path->lineTo(182.165f, 1013.16f);
30 path->lineTo(147.357f, 1016.82f);
31 path->lineTo(146.939f, 1012.84f);
32 path->close();
33}
34
35static void make_path1(SkPath* path) {
36 path->addRect(SkRect::MakeXYWH(10, 10, 10, 1));
37}
38
39typedef void (*PathProc)(SkPath*);
40
41/*
42 * Regression test: we used to crash (overwrite internal storage) during
43 * construction of the region when the path was INVERSE. That is now fixed,
44 * so test these regions (which used to assert/crash).
45 *
46 * https://code.google.com/p/skia/issues/detail?id=1706
47 */
48static void test_path_to_region(skiatest::Reporter* reporter) {
49 PathProc procs[] = {
50 make_path0,
51 make_path1,
52 };
skia.committer@gmail.com47262912013-10-16 07:02:24 +000053
reed@google.comcc8be772013-10-15 15:35:29 +000054 SkRegion clip;
55 clip.setRect(0, 0, 1255, 1925);
skia.committer@gmail.com47262912013-10-16 07:02:24 +000056
reed@google.comcc8be772013-10-15 15:35:29 +000057 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
58 SkPath path;
59 procs[i](&path);
skia.committer@gmail.com47262912013-10-16 07:02:24 +000060
reed@google.comcc8be772013-10-15 15:35:29 +000061 SkRegion rgn;
62 rgn.setPath(path, clip);
63 path.toggleInverseFillType();
64 rgn.setPath(path, clip);
65 }
66}
67
caryclark@google.com56f233a2012-11-19 13:06:06 +000068#if defined(WIN32)
69 #define SUPPRESS_VISIBILITY_WARNING
70#else
71 #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
72#endif
73
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +000074static void test_path_close_issue1474(skiatest::Reporter* reporter) {
75 // This test checks that r{Line,Quad,Conic,Cubic}To following a close()
76 // are relative to the point we close to, not relative to the point we close from.
77 SkPath path;
78 SkPoint last;
79
80 // Test rLineTo().
81 path.rLineTo(0, 100);
82 path.rLineTo(100, 0);
83 path.close(); // Returns us back to 0,0.
84 path.rLineTo(50, 50); // This should go to 50,50.
85
86 path.getLastPt(&last);
87 REPORTER_ASSERT(reporter, 50 == last.fX);
88 REPORTER_ASSERT(reporter, 50 == last.fY);
89
90 // Test rQuadTo().
91 path.rewind();
92 path.rLineTo(0, 100);
93 path.rLineTo(100, 0);
94 path.close();
95 path.rQuadTo(50, 50, 75, 75);
96
97 path.getLastPt(&last);
98 REPORTER_ASSERT(reporter, 75 == last.fX);
99 REPORTER_ASSERT(reporter, 75 == last.fY);
100
101 // Test rConicTo().
102 path.rewind();
103 path.rLineTo(0, 100);
104 path.rLineTo(100, 0);
105 path.close();
106 path.rConicTo(50, 50, 85, 85, 2);
107
108 path.getLastPt(&last);
109 REPORTER_ASSERT(reporter, 85 == last.fX);
110 REPORTER_ASSERT(reporter, 85 == last.fY);
111
112 // Test rCubicTo().
113 path.rewind();
114 path.rLineTo(0, 100);
115 path.rLineTo(100, 0);
116 path.close();
117 path.rCubicTo(50, 50, 85, 85, 95, 95);
118
119 path.getLastPt(&last);
120 REPORTER_ASSERT(reporter, 95 == last.fX);
121 REPORTER_ASSERT(reporter, 95 == last.fY);
122}
123
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000124static void test_android_specific_behavior(skiatest::Reporter* reporter) {
125#ifdef SK_BUILD_FOR_ANDROID
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000126 // Make sure we treat fGenerationID and fSourcePath correctly for each of
127 // copy, assign, rewind, reset, and swap.
128 SkPath original, source, anotherSource;
129 original.setSourcePath(&source);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000130 original.moveTo(0, 0);
131 original.lineTo(1, 1);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000132 REPORTER_ASSERT(reporter, original.getSourcePath() == &source);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000133
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000134 uint32_t copyID, assignID;
135
136 // Test copy constructor. Copy generation ID, copy source path.
137 SkPath copy(original);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000138 REPORTER_ASSERT(reporter, copy.getGenerationID() == original.getGenerationID());
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000139 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath());
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000140
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000141 // Test assigment operator. Change generation ID, copy source path.
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000142 SkPath assign;
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000143 assignID = assign.getGenerationID();
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000144 assign = original;
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000145 REPORTER_ASSERT(reporter, assign.getGenerationID() != assignID);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000146 REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath());
147
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000148 // Test rewind. Change generation ID, don't touch source path.
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000149 copyID = copy.getGenerationID();
150 copy.rewind();
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000151 REPORTER_ASSERT(reporter, copy.getGenerationID() != copyID);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000152 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath());
153
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000154 // Test reset. Change generation ID, don't touch source path.
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000155 assignID = assign.getGenerationID();
156 assign.reset();
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000157 REPORTER_ASSERT(reporter, assign.getGenerationID() != assignID);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000158 REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath());
159
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000160 // Test swap. Swap the generation IDs, swap source paths.
161 copy.reset();
162 copy.moveTo(2, 2);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000163 copy.setSourcePath(&anotherSource);
164 copyID = copy.getGenerationID();
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000165 assign.moveTo(3, 3);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000166 assignID = assign.getGenerationID();
167 copy.swap(assign);
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000168 REPORTER_ASSERT(reporter, copy.getGenerationID() != copyID);
169 REPORTER_ASSERT(reporter, assign.getGenerationID() != assignID);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000170 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath());
171 REPORTER_ASSERT(reporter, assign.getSourcePath() == &anotherSource);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000172#endif
173}
174
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000175static void test_gen_id(skiatest::Reporter* reporter) {
176 SkPath a, b;
177 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
178
179 a.moveTo(0, 0);
180 const uint32_t z = a.getGenerationID();
181 REPORTER_ASSERT(reporter, z != b.getGenerationID());
182
183 a.reset();
184 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
185
186 a.moveTo(1, 1);
187 const uint32_t y = a.getGenerationID();
188 REPORTER_ASSERT(reporter, z != y);
189
190 b.moveTo(2, 2);
191 const uint32_t x = b.getGenerationID();
192 REPORTER_ASSERT(reporter, x != y && x != z);
193
194 a.swap(b);
195 REPORTER_ASSERT(reporter, b.getGenerationID() == y && a.getGenerationID() == x);
196
197 b = a;
198 REPORTER_ASSERT(reporter, b.getGenerationID() == x);
199
200 SkPath c(a);
201 REPORTER_ASSERT(reporter, c.getGenerationID() == x);
202
203 c.lineTo(3, 3);
204 const uint32_t w = c.getGenerationID();
205 REPORTER_ASSERT(reporter, b.getGenerationID() == x);
206 REPORTER_ASSERT(reporter, a.getGenerationID() == x);
207 REPORTER_ASSERT(reporter, w != x);
208
209#ifdef SK_BUILD_FOR_ANDROID
210 static bool kExpectGenIDToIgnoreFill = false;
211#else
212 static bool kExpectGenIDToIgnoreFill = true;
213#endif
214
215 c.toggleInverseFillType();
216 const uint32_t v = c.getGenerationID();
217 REPORTER_ASSERT(reporter, (v == w) == kExpectGenIDToIgnoreFill);
218
219 c.rewind();
220 REPORTER_ASSERT(reporter, v != c.getGenerationID());
221}
222
reed@google.com3eff3592013-05-08 21:08:21 +0000223// This used to assert in the debug build, as the edges did not all line-up.
224static void test_bad_cubic_crbug234190() {
225 SkPath path;
226 path.moveTo(13.8509f, 3.16858f);
227 path.cubicTo(-2.35893e+08f, -4.21044e+08f,
228 -2.38991e+08f, -4.26573e+08f,
229 -2.41016e+08f, -4.30188e+08f);
230
231 SkPaint paint;
232 paint.setAntiAlias(true);
reed@google.comd28ba802013-09-20 19:33:52 +0000233 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(84, 88));
reed@google.com3eff3592013-05-08 21:08:21 +0000234 surface->getCanvas()->drawPath(path, paint);
235}
236
reed@google.com7a90daf2013-04-10 18:44:00 +0000237static void test_bad_cubic_crbug229478() {
238 const SkPoint pts[] = {
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000239 { 4595.91064f, -11596.9873f },
240 { 4597.2168f, -11595.9414f },
241 { 4598.52344f, -11594.8955f },
242 { 4599.83008f, -11593.8496f },
reed@google.com7a90daf2013-04-10 18:44:00 +0000243 };
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000244
reed@google.com7a90daf2013-04-10 18:44:00 +0000245 SkPath path;
246 path.moveTo(pts[0]);
247 path.cubicTo(pts[1], pts[2], pts[3]);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000248
reed@google.com7a90daf2013-04-10 18:44:00 +0000249 SkPaint paint;
250 paint.setStyle(SkPaint::kStroke_Style);
251 paint.setStrokeWidth(20);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000252
reed@google.com7a90daf2013-04-10 18:44:00 +0000253 SkPath dst;
254 // Before the fix, this would infinite-recurse, and run out of stack
255 // because we would keep trying to subdivide a degenerate cubic segment.
256 paint.getFillPath(path, &dst, NULL);
257}
258
reed@google.com64d62952013-01-18 17:49:28 +0000259static void build_path_170666(SkPath& path) {
260 path.moveTo(17.9459f, 21.6344f);
261 path.lineTo(139.545f, -47.8105f);
262 path.lineTo(139.545f, -47.8105f);
263 path.lineTo(131.07f, -47.3888f);
264 path.lineTo(131.07f, -47.3888f);
265 path.lineTo(122.586f, -46.9532f);
266 path.lineTo(122.586f, -46.9532f);
267 path.lineTo(18076.6f, 31390.9f);
268 path.lineTo(18076.6f, 31390.9f);
269 path.lineTo(18085.1f, 31390.5f);
270 path.lineTo(18085.1f, 31390.5f);
271 path.lineTo(18076.6f, 31390.9f);
272 path.lineTo(18076.6f, 31390.9f);
273 path.lineTo(17955, 31460.3f);
274 path.lineTo(17955, 31460.3f);
275 path.lineTo(17963.5f, 31459.9f);
276 path.lineTo(17963.5f, 31459.9f);
277 path.lineTo(17971.9f, 31459.5f);
278 path.lineTo(17971.9f, 31459.5f);
279 path.lineTo(17.9551f, 21.6205f);
280 path.lineTo(17.9551f, 21.6205f);
281 path.lineTo(9.47091f, 22.0561f);
282 path.lineTo(9.47091f, 22.0561f);
283 path.lineTo(17.9459f, 21.6344f);
284 path.lineTo(17.9459f, 21.6344f);
285 path.close();path.moveTo(0.995934f, 22.4779f);
286 path.lineTo(0.986725f, 22.4918f);
287 path.lineTo(0.986725f, 22.4918f);
288 path.lineTo(17955, 31460.4f);
289 path.lineTo(17955, 31460.4f);
290 path.lineTo(17971.9f, 31459.5f);
291 path.lineTo(17971.9f, 31459.5f);
292 path.lineTo(18093.6f, 31390.1f);
293 path.lineTo(18093.6f, 31390.1f);
294 path.lineTo(18093.6f, 31390);
295 path.lineTo(18093.6f, 31390);
296 path.lineTo(139.555f, -47.8244f);
297 path.lineTo(139.555f, -47.8244f);
298 path.lineTo(122.595f, -46.9671f);
299 path.lineTo(122.595f, -46.9671f);
300 path.lineTo(0.995934f, 22.4779f);
301 path.lineTo(0.995934f, 22.4779f);
302 path.close();
303 path.moveTo(5.43941f, 25.5223f);
304 path.lineTo(798267, -28871.1f);
305 path.lineTo(798267, -28871.1f);
306 path.lineTo(3.12512e+06f, -113102);
307 path.lineTo(3.12512e+06f, -113102);
308 path.cubicTo(5.16324e+06f, -186882, 8.15247e+06f, -295092, 1.1957e+07f, -432813);
309 path.cubicTo(1.95659e+07f, -708257, 3.04359e+07f, -1.10175e+06f, 4.34798e+07f, -1.57394e+06f);
310 path.cubicTo(6.95677e+07f, -2.51831e+06f, 1.04352e+08f, -3.77748e+06f, 1.39135e+08f, -5.03666e+06f);
311 path.cubicTo(1.73919e+08f, -6.29583e+06f, 2.08703e+08f, -7.555e+06f, 2.34791e+08f, -8.49938e+06f);
312 path.cubicTo(2.47835e+08f, -8.97157e+06f, 2.58705e+08f, -9.36506e+06f, 2.66314e+08f, -9.6405e+06f);
313 path.cubicTo(2.70118e+08f, -9.77823e+06f, 2.73108e+08f, -9.88644e+06f, 2.75146e+08f, -9.96022e+06f);
314 path.cubicTo(2.76165e+08f, -9.99711e+06f, 2.76946e+08f, -1.00254e+07f, 2.77473e+08f, -1.00444e+07f);
315 path.lineTo(2.78271e+08f, -1.00733e+07f);
316 path.lineTo(2.78271e+08f, -1.00733e+07f);
317 path.cubicTo(2.78271e+08f, -1.00733e+07f, 2.08703e+08f, -7.555e+06f, 135.238f, 23.3517f);
318 path.cubicTo(131.191f, 23.4981f, 125.995f, 23.7976f, 123.631f, 24.0206f);
319 path.cubicTo(121.267f, 24.2436f, 122.631f, 24.3056f, 126.677f, 24.1591f);
320 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
321 path.lineTo(2.77473e+08f, -1.00444e+07f);
322 path.lineTo(2.77473e+08f, -1.00444e+07f);
323 path.cubicTo(2.76946e+08f, -1.00254e+07f, 2.76165e+08f, -9.99711e+06f, 2.75146e+08f, -9.96022e+06f);
324 path.cubicTo(2.73108e+08f, -9.88644e+06f, 2.70118e+08f, -9.77823e+06f, 2.66314e+08f, -9.6405e+06f);
325 path.cubicTo(2.58705e+08f, -9.36506e+06f, 2.47835e+08f, -8.97157e+06f, 2.34791e+08f, -8.49938e+06f);
326 path.cubicTo(2.08703e+08f, -7.555e+06f, 1.73919e+08f, -6.29583e+06f, 1.39135e+08f, -5.03666e+06f);
327 path.cubicTo(1.04352e+08f, -3.77749e+06f, 6.95677e+07f, -2.51831e+06f, 4.34798e+07f, -1.57394e+06f);
328 path.cubicTo(3.04359e+07f, -1.10175e+06f, 1.95659e+07f, -708258, 1.1957e+07f, -432814);
329 path.cubicTo(8.15248e+06f, -295092, 5.16324e+06f, -186883, 3.12513e+06f, -113103);
330 path.lineTo(798284, -28872);
331 path.lineTo(798284, -28872);
332 path.lineTo(22.4044f, 24.6677f);
333 path.lineTo(22.4044f, 24.6677f);
334 path.cubicTo(22.5186f, 24.5432f, 18.8134f, 24.6337f, 14.1287f, 24.8697f);
335 path.cubicTo(9.4439f, 25.1057f, 5.55359f, 25.3978f, 5.43941f, 25.5223f);
336 path.close();
337}
338
339static void build_path_simple_170666(SkPath& path) {
340 path.moveTo(126.677f, 24.1591f);
341 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
342}
343
344// This used to assert in the SK_DEBUG build, as the clip step would fail with
345// too-few interations in our cubic-line intersection code. That code now runs
346// 24 interations (instead of 16).
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000347static void test_crbug_170666() {
reed@google.com64d62952013-01-18 17:49:28 +0000348 SkPath path;
349 SkPaint paint;
350 paint.setAntiAlias(true);
351
reed@google.comd28ba802013-09-20 19:33:52 +0000352 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(1000, 1000));
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000353
reed@google.com64d62952013-01-18 17:49:28 +0000354 build_path_simple_170666(path);
355 surface->getCanvas()->drawPath(path, paint);
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000356
reed@google.com64d62952013-01-18 17:49:28 +0000357 build_path_170666(path);
358 surface->getCanvas()->drawPath(path, paint);
359}
360
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000361static void test_addrect(skiatest::Reporter* reporter) {
362 SkPath path;
363 path.lineTo(0, 0);
364 path.addRect(SkRect::MakeWH(50, 100));
365 REPORTER_ASSERT(reporter, path.isRect(NULL));
366
367 path.reset();
368 path.lineTo(FLT_EPSILON, FLT_EPSILON);
369 path.addRect(SkRect::MakeWH(50, 100));
370 REPORTER_ASSERT(reporter, !path.isRect(NULL));
371
372 path.reset();
373 path.quadTo(0, 0, 0, 0);
374 path.addRect(SkRect::MakeWH(50, 100));
375 REPORTER_ASSERT(reporter, !path.isRect(NULL));
376
377 path.reset();
378 path.conicTo(0, 0, 0, 0, 0.5f);
379 path.addRect(SkRect::MakeWH(50, 100));
380 REPORTER_ASSERT(reporter, !path.isRect(NULL));
381
382 path.reset();
383 path.cubicTo(0, 0, 0, 0, 0, 0);
384 path.addRect(SkRect::MakeWH(50, 100));
385 REPORTER_ASSERT(reporter, !path.isRect(NULL));
386}
387
reed@google.coma8790de2012-10-24 21:04:04 +0000388// Make sure we stay non-finite once we get there (unless we reset or rewind).
389static void test_addrect_isfinite(skiatest::Reporter* reporter) {
390 SkPath path;
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000391
reed@google.coma8790de2012-10-24 21:04:04 +0000392 path.addRect(SkRect::MakeWH(50, 100));
393 REPORTER_ASSERT(reporter, path.isFinite());
394
395 path.moveTo(0, 0);
396 path.lineTo(SK_ScalarInfinity, 42);
397 REPORTER_ASSERT(reporter, !path.isFinite());
398
399 path.addRect(SkRect::MakeWH(50, 100));
400 REPORTER_ASSERT(reporter, !path.isFinite());
401
402 path.reset();
403 REPORTER_ASSERT(reporter, path.isFinite());
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000404
reed@google.coma8790de2012-10-24 21:04:04 +0000405 path.addRect(SkRect::MakeWH(50, 100));
406 REPORTER_ASSERT(reporter, path.isFinite());
407}
408
reed@google.com848148e2013-01-15 15:51:59 +0000409static void build_big_path(SkPath* path, bool reducedCase) {
410 if (reducedCase) {
411 path->moveTo(577330, 1971.72f);
412 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
413 } else {
414 path->moveTo(60.1631f, 7.70567f);
415 path->quadTo(60.1631f, 7.70567f, 0.99474f, 0.901199f);
416 path->lineTo(577379, 1977.77f);
417 path->quadTo(577364, 1979.57f, 577325, 1980.26f);
418 path->quadTo(577286, 1980.95f, 577245, 1980.13f);
419 path->quadTo(577205, 1979.3f, 577187, 1977.45f);
420 path->quadTo(577168, 1975.6f, 577183, 1973.8f);
421 path->quadTo(577198, 1972, 577238, 1971.31f);
422 path->quadTo(577277, 1970.62f, 577317, 1971.45f);
423 path->quadTo(577330, 1971.72f, 577341, 1972.11f);
424 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
425 path->moveTo(306.718f, -32.912f);
426 path->cubicTo(30.531f, 10.0005f, 1502.47f, 13.2804f, 84.3088f, 9.99601f);
427 }
428}
429
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000430static void test_clipped_cubic() {
reed@google.comd28ba802013-09-20 19:33:52 +0000431 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(640, 480));
reed@google.com848148e2013-01-15 15:51:59 +0000432
433 // This path used to assert, because our cubic-chopping code incorrectly
434 // moved control points after the chop. This test should be run in SK_DEBUG
435 // mode to ensure that we no long assert.
436 SkPath path;
437 for (int doReducedCase = 0; doReducedCase <= 1; ++doReducedCase) {
438 build_big_path(&path, SkToBool(doReducedCase));
skia.committer@gmail.comff21c2e2013-01-16 07:05:56 +0000439
reed@google.com848148e2013-01-15 15:51:59 +0000440 SkPaint paint;
441 for (int doAA = 0; doAA <= 1; ++doAA) {
442 paint.setAntiAlias(SkToBool(doAA));
443 surface->getCanvas()->drawPath(path, paint);
444 }
445 }
446}
447
reed@google.com8cae8352012-09-14 15:18:41 +0000448// Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/
449// which triggered an assert, from a tricky cubic. This test replicates that
450// example, so we can ensure that we handle it (in SkEdge.cpp), and don't
451// assert in the SK_DEBUG build.
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000452static void test_tricky_cubic() {
reed@google.com8cae8352012-09-14 15:18:41 +0000453 const SkPoint pts[] = {
skia.committer@gmail.com055c7c22012-09-15 02:01:41 +0000454 { SkDoubleToScalar(18.8943768), SkDoubleToScalar(129.121277) },
455 { SkDoubleToScalar(18.8937435), SkDoubleToScalar(129.121689) },
456 { SkDoubleToScalar(18.8950119), SkDoubleToScalar(129.120422) },
457 { SkDoubleToScalar(18.5030727), SkDoubleToScalar(129.13121) },
reed@google.com8cae8352012-09-14 15:18:41 +0000458 };
459
460 SkPath path;
461 path.moveTo(pts[0]);
462 path.cubicTo(pts[1], pts[2], pts[3]);
463
464 SkPaint paint;
465 paint.setAntiAlias(true);
466
reed@google.comd28ba802013-09-20 19:33:52 +0000467 SkSurface* surface = SkSurface::NewRasterPMColor(19, 130);
reed@google.com8cae8352012-09-14 15:18:41 +0000468 surface->getCanvas()->drawPath(path, paint);
469 surface->unref();
470}
reed@android.com3abec1d2009-03-02 05:36:20 +0000471
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000472// Inspired by http://code.google.com/p/chromium/issues/detail?id=141651
473//
474static void test_isfinite_after_transform(skiatest::Reporter* reporter) {
475 SkPath path;
476 path.quadTo(157, 366, 286, 208);
477 path.arcTo(37, 442, 315, 163, 957494590897113.0f);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000478
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000479 SkMatrix matrix;
480 matrix.setScale(1000*1000, 1000*1000);
481
482 // Be sure that path::transform correctly updates isFinite and the bounds
483 // if the transformation overflows. The previous bug was that isFinite was
484 // set to true in this case, but the bounds were not set to empty (which
485 // they should be).
486 while (path.isFinite()) {
487 REPORTER_ASSERT(reporter, path.getBounds().isFinite());
488 REPORTER_ASSERT(reporter, !path.getBounds().isEmpty());
489 path.transform(matrix);
490 }
491 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
492
493 matrix.setTranslate(SK_Scalar1, SK_Scalar1);
494 path.transform(matrix);
495 // we need to still be non-finite
496 REPORTER_ASSERT(reporter, !path.isFinite());
497 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
498}
499
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000500static void add_corner_arc(SkPath* path, const SkRect& rect,
501 SkScalar xIn, SkScalar yIn,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000502 int startAngle)
503{
504
505 SkScalar rx = SkMinScalar(rect.width(), xIn);
506 SkScalar ry = SkMinScalar(rect.height(), yIn);
507
508 SkRect arcRect;
509 arcRect.set(-rx, -ry, rx, ry);
510 switch (startAngle) {
511 case 0:
512 arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom);
513 break;
514 case 90:
515 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom);
516 break;
517 case 180:
518 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop);
519 break;
520 case 270:
521 arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop);
522 break;
523 default:
524 break;
525 }
526
527 path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false);
528}
529
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000530static void make_arb_round_rect(SkPath* path, const SkRect& r,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000531 SkScalar xCorner, SkScalar yCorner) {
532 // we are lazy here and use the same x & y for each corner
533 add_corner_arc(path, r, xCorner, yCorner, 270);
534 add_corner_arc(path, r, xCorner, yCorner, 0);
535 add_corner_arc(path, r, xCorner, yCorner, 90);
536 add_corner_arc(path, r, xCorner, yCorner, 180);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000537 path->close();
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000538}
539
540// Chrome creates its own round rects with each corner possibly being different.
541// Performance will suffer if they are not convex.
542// Note: PathBench::ArbRoundRectBench performs almost exactly
543// the same test (but with drawing)
544static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000545 SkRandom rand;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000546 SkRect r;
547
548 for (int i = 0; i < 5000; ++i) {
549
robertphillips@google.com158618e2012-10-23 16:56:56 +0000550 SkScalar size = rand.nextUScalar1() * 30;
551 if (size < SK_Scalar1) {
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000552 continue;
553 }
554 r.fLeft = rand.nextUScalar1() * 300;
555 r.fTop = rand.nextUScalar1() * 300;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000556 r.fRight = r.fLeft + 2 * size;
557 r.fBottom = r.fTop + 2 * size;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000558
559 SkPath temp;
560
561 make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
562
563 REPORTER_ASSERT(reporter, temp.isConvex());
564 }
565}
566
robertphillips@google.com158618e2012-10-23 16:56:56 +0000567// Chrome will sometimes create a 0 radius round rect. The degenerate
568// quads prevent the path from being converted to a rect
569// Note: PathBench::ArbRoundRectBench performs almost exactly
570// the same test (but with drawing)
571static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000572 SkRandom rand;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000573 SkRect r;
574
575 for (int i = 0; i < 5000; ++i) {
576
577 SkScalar size = rand.nextUScalar1() * 30;
578 if (size < SK_Scalar1) {
579 continue;
580 }
581 r.fLeft = rand.nextUScalar1() * 300;
582 r.fTop = rand.nextUScalar1() * 300;
583 r.fRight = r.fLeft + 2 * size;
584 r.fBottom = r.fTop + 2 * size;
585
586 SkPath temp;
587
588 make_arb_round_rect(&temp, r, 0, 0);
589
robertphillips@google.com158618e2012-10-23 16:56:56 +0000590 SkRect result;
591 REPORTER_ASSERT(reporter, temp.isRect(&result));
592 REPORTER_ASSERT(reporter, r == result);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000593 }
594}
595
reed@google.com0bb18bb2012-07-26 15:20:36 +0000596static void test_rect_isfinite(skiatest::Reporter* reporter) {
597 const SkScalar inf = SK_ScalarInfinity;
caryclark@google.com7abfa492013-04-12 11:59:41 +0000598 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000599 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000600
reed@google.com0bb18bb2012-07-26 15:20:36 +0000601 SkRect r;
602 r.setEmpty();
603 REPORTER_ASSERT(reporter, r.isFinite());
caryclark@google.com7abfa492013-04-12 11:59:41 +0000604 r.set(0, 0, inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000605 REPORTER_ASSERT(reporter, !r.isFinite());
606 r.set(0, 0, nan, 0);
607 REPORTER_ASSERT(reporter, !r.isFinite());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000608
reed@google.com0bb18bb2012-07-26 15:20:36 +0000609 SkPoint pts[] = {
610 { 0, 0 },
611 { SK_Scalar1, 0 },
612 { 0, SK_Scalar1 },
613 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000614
reed@google.com0bb18bb2012-07-26 15:20:36 +0000615 bool isFine = r.setBoundsCheck(pts, 3);
616 REPORTER_ASSERT(reporter, isFine);
617 REPORTER_ASSERT(reporter, !r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000618
reed@google.com0bb18bb2012-07-26 15:20:36 +0000619 pts[1].set(inf, 0);
620 isFine = r.setBoundsCheck(pts, 3);
621 REPORTER_ASSERT(reporter, !isFine);
622 REPORTER_ASSERT(reporter, r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000623
reed@google.com0bb18bb2012-07-26 15:20:36 +0000624 pts[1].set(nan, 0);
625 isFine = r.setBoundsCheck(pts, 3);
626 REPORTER_ASSERT(reporter, !isFine);
627 REPORTER_ASSERT(reporter, r.isEmpty());
628}
629
630static void test_path_isfinite(skiatest::Reporter* reporter) {
631 const SkScalar inf = SK_ScalarInfinity;
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000632 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000633 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000634
reed@google.com0bb18bb2012-07-26 15:20:36 +0000635 SkPath path;
636 REPORTER_ASSERT(reporter, path.isFinite());
637
638 path.reset();
639 REPORTER_ASSERT(reporter, path.isFinite());
640
641 path.reset();
642 path.moveTo(SK_Scalar1, 0);
643 REPORTER_ASSERT(reporter, path.isFinite());
644
645 path.reset();
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000646 path.moveTo(inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000647 REPORTER_ASSERT(reporter, !path.isFinite());
648
649 path.reset();
650 path.moveTo(nan, 0);
651 REPORTER_ASSERT(reporter, !path.isFinite());
652}
653
654static void test_isfinite(skiatest::Reporter* reporter) {
655 test_rect_isfinite(reporter);
656 test_path_isfinite(reporter);
657}
658
reed@google.com744faba2012-05-29 19:54:52 +0000659// assert that we always
660// start with a moveTo
661// only have 1 moveTo
662// only have Lines after that
663// end with a single close
664// only have (at most) 1 close
665//
666static void test_poly(skiatest::Reporter* reporter, const SkPath& path,
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000667 const SkPoint srcPts[], bool expectClose) {
reed@google.com744faba2012-05-29 19:54:52 +0000668 SkPath::RawIter iter(path);
669 SkPoint pts[4];
reed@google.com744faba2012-05-29 19:54:52 +0000670
671 bool firstTime = true;
672 bool foundClose = false;
673 for (;;) {
674 switch (iter.next(pts)) {
675 case SkPath::kMove_Verb:
676 REPORTER_ASSERT(reporter, firstTime);
677 REPORTER_ASSERT(reporter, pts[0] == srcPts[0]);
678 srcPts++;
679 firstTime = false;
680 break;
681 case SkPath::kLine_Verb:
682 REPORTER_ASSERT(reporter, !firstTime);
683 REPORTER_ASSERT(reporter, pts[1] == srcPts[0]);
684 srcPts++;
685 break;
686 case SkPath::kQuad_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000687 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected quad verb");
reed@google.com744faba2012-05-29 19:54:52 +0000688 break;
reed@google.com277c3f82013-05-31 15:17:50 +0000689 case SkPath::kConic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000690 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected conic verb");
reed@google.com277c3f82013-05-31 15:17:50 +0000691 break;
reed@google.com744faba2012-05-29 19:54:52 +0000692 case SkPath::kCubic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000693 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected cubic verb");
reed@google.com744faba2012-05-29 19:54:52 +0000694 break;
695 case SkPath::kClose_Verb:
696 REPORTER_ASSERT(reporter, !firstTime);
697 REPORTER_ASSERT(reporter, !foundClose);
698 REPORTER_ASSERT(reporter, expectClose);
699 foundClose = true;
700 break;
701 case SkPath::kDone_Verb:
702 goto DONE;
703 }
704 }
705DONE:
706 REPORTER_ASSERT(reporter, foundClose == expectClose);
707}
708
709static void test_addPoly(skiatest::Reporter* reporter) {
710 SkPoint pts[32];
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000711 SkRandom rand;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000712
reed@google.com744faba2012-05-29 19:54:52 +0000713 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
714 pts[i].fX = rand.nextSScalar1();
715 pts[i].fY = rand.nextSScalar1();
716 }
717
718 for (int doClose = 0; doClose <= 1; ++doClose) {
719 for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) {
720 SkPath path;
721 path.addPoly(pts, count, SkToBool(doClose));
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000722 test_poly(reporter, path, pts, SkToBool(doClose));
reed@google.com744faba2012-05-29 19:54:52 +0000723 }
724 }
725}
726
reed@google.com8b06f1a2012-05-29 12:03:46 +0000727static void test_strokerec(skiatest::Reporter* reporter) {
728 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
729 REPORTER_ASSERT(reporter, rec.isFillStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000730
reed@google.com8b06f1a2012-05-29 12:03:46 +0000731 rec.setHairlineStyle();
732 REPORTER_ASSERT(reporter, rec.isHairlineStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000733
reed@google.com8b06f1a2012-05-29 12:03:46 +0000734 rec.setStrokeStyle(SK_Scalar1, false);
735 REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000736
reed@google.com8b06f1a2012-05-29 12:03:46 +0000737 rec.setStrokeStyle(SK_Scalar1, true);
738 REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000739
reed@google.com8b06f1a2012-05-29 12:03:46 +0000740 rec.setStrokeStyle(0, false);
741 REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000742
reed@google.com8b06f1a2012-05-29 12:03:46 +0000743 rec.setStrokeStyle(0, true);
744 REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle());
745}
746
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000747// Set this for paths that don't have a consistent direction such as a bowtie.
748// (cheapComputeDirection is not expected to catch these.)
749static const SkPath::Direction kDontCheckDir = static_cast<SkPath::Direction>(-1);
750
751static void check_direction(skiatest::Reporter* reporter, const SkPath& path,
752 SkPath::Direction expected) {
753 if (expected == kDontCheckDir) {
754 return;
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000755 }
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000756 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
757
758 SkPath::Direction dir;
759 if (copy.cheapComputeDirection(&dir)) {
760 REPORTER_ASSERT(reporter, dir == expected);
761 } else {
762 REPORTER_ASSERT(reporter, SkPath::kUnknown_Direction == expected);
763 }
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000764}
765
reed@google.com3e71a882012-01-10 18:44:37 +0000766static void test_direction(skiatest::Reporter* reporter) {
767 size_t i;
768 SkPath path;
769 REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
770 REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCW_Direction));
771 REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCCW_Direction));
reed@google.coma8a3b3d2012-11-26 18:16:27 +0000772 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kUnknown_Direction));
reed@google.com3e71a882012-01-10 18:44:37 +0000773
774 static const char* gDegen[] = {
775 "M 10 10",
776 "M 10 10 M 20 20",
777 "M 10 10 L 20 20",
778 "M 10 10 L 10 10 L 10 10",
779 "M 10 10 Q 10 10 10 10",
780 "M 10 10 C 10 10 10 10 10 10",
781 };
782 for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) {
783 path.reset();
784 bool valid = SkParsePath::FromSVGString(gDegen[i], &path);
785 REPORTER_ASSERT(reporter, valid);
786 REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
787 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000788
reed@google.com3e71a882012-01-10 18:44:37 +0000789 static const char* gCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000790 "M 10 10 L 10 10 Q 20 10 20 20",
reed@google.com3e71a882012-01-10 18:44:37 +0000791 "M 10 10 C 20 10 20 20 20 20",
reed@google.comd4146662012-01-31 15:42:29 +0000792 "M 20 10 Q 20 20 30 20 L 10 20", // test double-back at y-max
bsalomon@google.com4eefe612012-07-10 18:28:12 +0000793 // rect with top two corners replaced by cubics with identical middle
794 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000795 "M 10 10 C 10 0 10 0 20 0 L 40 0 C 50 0 50 0 50 10",
796 "M 20 10 L 0 10 Q 10 10 20 0", // left, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000797 };
798 for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) {
799 path.reset();
800 bool valid = SkParsePath::FromSVGString(gCW[i], &path);
801 REPORTER_ASSERT(reporter, valid);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000802 check_direction(reporter, path, SkPath::kCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000803 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000804
reed@google.com3e71a882012-01-10 18:44:37 +0000805 static const char* gCCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000806 "M 10 10 L 10 10 Q 20 10 20 -20",
reed@google.com3e71a882012-01-10 18:44:37 +0000807 "M 10 10 C 20 10 20 -20 20 -20",
reed@google.comd4146662012-01-31 15:42:29 +0000808 "M 20 10 Q 20 20 10 20 L 30 20", // test double-back at y-max
bsalomon@google.com4eefe612012-07-10 18:28:12 +0000809 // rect with top two corners replaced by cubics with identical middle
810 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000811 "M 50 10 C 50 0 50 0 40 0 L 20 0 C 10 0 10 0 10 10",
812 "M 10 10 L 30 10 Q 20 10 10 0", // right, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000813 };
814 for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) {
815 path.reset();
816 bool valid = SkParsePath::FromSVGString(gCCW[i], &path);
817 REPORTER_ASSERT(reporter, valid);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000818 check_direction(reporter, path, SkPath::kCCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000819 }
reed@google.comac8543f2012-01-30 20:51:25 +0000820
821 // Test two donuts, each wound a different direction. Only the outer contour
822 // determines the cheap direction
823 path.reset();
824 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCW_Direction);
825 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000826 check_direction(reporter, path, SkPath::kCW_Direction);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000827
reed@google.comac8543f2012-01-30 20:51:25 +0000828 path.reset();
829 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCW_Direction);
830 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000831 check_direction(reporter, path, SkPath::kCCW_Direction);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000832
833 // triangle with one point really far from the origin.
834 path.reset();
835 // the first point is roughly 1.05e10, 1.05e10
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +0000836 path.moveTo(SkBits2Float(0x501c7652), SkBits2Float(0x501c7652));
bsalomon@google.com53aab782012-02-23 14:54:49 +0000837 path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1);
838 path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000839 check_direction(reporter, path, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000840
841 path.reset();
842 path.conicTo(20, 0, 20, 20, 0.5f);
843 path.close();
844 check_direction(reporter, path, SkPath::kCW_Direction);
845
846 path.reset();
847 path.lineTo(1, 1e7f);
848 path.lineTo(1e7f, 2e7f);
849 path.close();
850 REPORTER_ASSERT(reporter, SkPath::kConvex_Convexity == path.getConvexity());
851 check_direction(reporter, path, SkPath::kCCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000852}
853
reed@google.comffdb0182011-11-14 19:29:14 +0000854static void add_rect(SkPath* path, const SkRect& r) {
855 path->moveTo(r.fLeft, r.fTop);
856 path->lineTo(r.fRight, r.fTop);
857 path->lineTo(r.fRight, r.fBottom);
858 path->lineTo(r.fLeft, r.fBottom);
859 path->close();
860}
861
862static void test_bounds(skiatest::Reporter* reporter) {
863 static const SkRect rects[] = {
reed@google.com3563c9e2011-11-14 19:34:57 +0000864 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) },
865 { SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) },
866 { SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) },
867 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) },
reed@google.comffdb0182011-11-14 19:29:14 +0000868 };
869
870 SkPath path0, path1;
871 for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) {
872 path0.addRect(rects[i]);
873 add_rect(&path1, rects[i]);
874 }
875
876 REPORTER_ASSERT(reporter, path0.getBounds() == path1.getBounds());
877}
878
reed@google.com55b5f4b2011-09-07 12:23:41 +0000879static void stroke_cubic(const SkPoint pts[4]) {
880 SkPath path;
881 path.moveTo(pts[0]);
882 path.cubicTo(pts[1], pts[2], pts[3]);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000883
reed@google.com55b5f4b2011-09-07 12:23:41 +0000884 SkPaint paint;
885 paint.setStyle(SkPaint::kStroke_Style);
886 paint.setStrokeWidth(SK_Scalar1 * 2);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000887
reed@google.com55b5f4b2011-09-07 12:23:41 +0000888 SkPath fill;
889 paint.getFillPath(path, &fill);
890}
891
892// just ensure this can run w/o any SkASSERTS firing in the debug build
893// we used to assert due to differences in how we determine a degenerate vector
894// but that was fixed with the introduction of SkPoint::CanNormalize
895static void stroke_tiny_cubic() {
896 SkPoint p0[] = {
897 { 372.0f, 92.0f },
898 { 372.0f, 92.0f },
899 { 372.0f, 92.0f },
900 { 372.0f, 92.0f },
901 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000902
reed@google.com55b5f4b2011-09-07 12:23:41 +0000903 stroke_cubic(p0);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000904
reed@google.com55b5f4b2011-09-07 12:23:41 +0000905 SkPoint p1[] = {
906 { 372.0f, 92.0f },
907 { 372.0007f, 92.000755f },
908 { 371.99927f, 92.003922f },
909 { 371.99826f, 92.003899f },
910 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000911
reed@google.com55b5f4b2011-09-07 12:23:41 +0000912 stroke_cubic(p1);
913}
914
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000915static void check_close(skiatest::Reporter* reporter, const SkPath& path) {
916 for (int i = 0; i < 2; ++i) {
robertphillips@google.com09042b82012-04-06 20:01:46 +0000917 SkPath::Iter iter(path, SkToBool(i));
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000918 SkPoint mv;
919 SkPoint pts[4];
920 SkPath::Verb v;
921 int nMT = 0;
922 int nCL = 0;
tomhudson@google.com221db3c2011-07-28 21:10:29 +0000923 mv.set(0, 0);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000924 while (SkPath::kDone_Verb != (v = iter.next(pts))) {
925 switch (v) {
926 case SkPath::kMove_Verb:
927 mv = pts[0];
928 ++nMT;
929 break;
930 case SkPath::kClose_Verb:
931 REPORTER_ASSERT(reporter, mv == pts[0]);
932 ++nCL;
933 break;
934 default:
935 break;
936 }
937 }
938 // if we force a close on the interator we should have a close
939 // for every moveTo
940 REPORTER_ASSERT(reporter, !i || nMT == nCL);
941 }
942}
943
944static void test_close(skiatest::Reporter* reporter) {
945 SkPath closePt;
946 closePt.moveTo(0, 0);
947 closePt.close();
948 check_close(reporter, closePt);
949
950 SkPath openPt;
951 openPt.moveTo(0, 0);
952 check_close(reporter, openPt);
953
954 SkPath empty;
955 check_close(reporter, empty);
956 empty.close();
957 check_close(reporter, empty);
958
959 SkPath rect;
960 rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
961 check_close(reporter, rect);
962 rect.close();
963 check_close(reporter, rect);
964
965 SkPath quad;
966 quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
967 check_close(reporter, quad);
968 quad.close();
969 check_close(reporter, quad);
970
971 SkPath cubic;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000972 quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1,
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000973 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1);
974 check_close(reporter, cubic);
975 cubic.close();
976 check_close(reporter, cubic);
977
978 SkPath line;
979 line.moveTo(SK_Scalar1, SK_Scalar1);
980 line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1);
981 check_close(reporter, line);
982 line.close();
983 check_close(reporter, line);
984
985 SkPath rect2;
986 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
987 rect2.close();
988 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
989 check_close(reporter, rect2);
990 rect2.close();
991 check_close(reporter, rect2);
992
993 SkPath oval3;
994 oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100));
995 oval3.close();
996 oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200));
997 check_close(reporter, oval3);
998 oval3.close();
999 check_close(reporter, oval3);
1000
1001 SkPath moves;
1002 moves.moveTo(SK_Scalar1, SK_Scalar1);
1003 moves.moveTo(5 * SK_Scalar1, SK_Scalar1);
1004 moves.moveTo(SK_Scalar1, 10 * SK_Scalar1);
1005 moves.moveTo(10 *SK_Scalar1, SK_Scalar1);
1006 check_close(reporter, moves);
reed@google.com55b5f4b2011-09-07 12:23:41 +00001007
1008 stroke_tiny_cubic();
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001009}
1010
reed@google.com7c424812011-05-15 04:38:34 +00001011static void check_convexity(skiatest::Reporter* reporter, const SkPath& path,
1012 SkPath::Convexity expected) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001013 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
1014 SkPath::Convexity c = copy.getConvexity();
reed@google.com7c424812011-05-15 04:38:34 +00001015 REPORTER_ASSERT(reporter, c == expected);
1016}
1017
1018static void test_convexity2(skiatest::Reporter* reporter) {
1019 SkPath pt;
1020 pt.moveTo(0, 0);
1021 pt.close();
reed@google.comb54455e2011-05-16 14:16:04 +00001022 check_convexity(reporter, pt, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001023 check_direction(reporter, pt, SkPath::kUnknown_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001024
reed@google.com7c424812011-05-15 04:38:34 +00001025 SkPath line;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001026 line.moveTo(12*SK_Scalar1, 20*SK_Scalar1);
1027 line.lineTo(-12*SK_Scalar1, -20*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001028 line.close();
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001029 check_convexity(reporter, line, SkPath::kConvex_Convexity);
1030 check_direction(reporter, line, SkPath::kUnknown_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001031
reed@google.com7c424812011-05-15 04:38:34 +00001032 SkPath triLeft;
1033 triLeft.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001034 triLeft.lineTo(SK_Scalar1, 0);
1035 triLeft.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001036 triLeft.close();
1037 check_convexity(reporter, triLeft, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001038 check_direction(reporter, triLeft, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001039
reed@google.com7c424812011-05-15 04:38:34 +00001040 SkPath triRight;
1041 triRight.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001042 triRight.lineTo(-SK_Scalar1, 0);
1043 triRight.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001044 triRight.close();
1045 check_convexity(reporter, triRight, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001046 check_direction(reporter, triRight, SkPath::kCCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001047
reed@google.com7c424812011-05-15 04:38:34 +00001048 SkPath square;
1049 square.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001050 square.lineTo(SK_Scalar1, 0);
1051 square.lineTo(SK_Scalar1, SK_Scalar1);
1052 square.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001053 square.close();
1054 check_convexity(reporter, square, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001055 check_direction(reporter, square, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001056
reed@google.com7c424812011-05-15 04:38:34 +00001057 SkPath redundantSquare;
1058 redundantSquare.moveTo(0, 0);
1059 redundantSquare.lineTo(0, 0);
1060 redundantSquare.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001061 redundantSquare.lineTo(SK_Scalar1, 0);
1062 redundantSquare.lineTo(SK_Scalar1, 0);
1063 redundantSquare.lineTo(SK_Scalar1, 0);
1064 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1065 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1066 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1067 redundantSquare.lineTo(0, SK_Scalar1);
1068 redundantSquare.lineTo(0, SK_Scalar1);
1069 redundantSquare.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001070 redundantSquare.close();
1071 check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001072 check_direction(reporter, redundantSquare, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001073
reed@google.com7c424812011-05-15 04:38:34 +00001074 SkPath bowTie;
1075 bowTie.moveTo(0, 0);
1076 bowTie.lineTo(0, 0);
1077 bowTie.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001078 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1079 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1080 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1081 bowTie.lineTo(SK_Scalar1, 0);
1082 bowTie.lineTo(SK_Scalar1, 0);
1083 bowTie.lineTo(SK_Scalar1, 0);
1084 bowTie.lineTo(0, SK_Scalar1);
1085 bowTie.lineTo(0, SK_Scalar1);
1086 bowTie.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001087 bowTie.close();
1088 check_convexity(reporter, bowTie, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001089 check_direction(reporter, bowTie, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001090
reed@google.com7c424812011-05-15 04:38:34 +00001091 SkPath spiral;
1092 spiral.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001093 spiral.lineTo(100*SK_Scalar1, 0);
1094 spiral.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1095 spiral.lineTo(0, 100*SK_Scalar1);
1096 spiral.lineTo(0, 50*SK_Scalar1);
1097 spiral.lineTo(50*SK_Scalar1, 50*SK_Scalar1);
1098 spiral.lineTo(50*SK_Scalar1, 75*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001099 spiral.close();
reed@google.com85b6e392011-05-15 20:25:17 +00001100 check_convexity(reporter, spiral, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001101 check_direction(reporter, spiral, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001102
reed@google.com7c424812011-05-15 04:38:34 +00001103 SkPath dent;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001104 dent.moveTo(0, 0);
1105 dent.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1106 dent.lineTo(0, 100*SK_Scalar1);
1107 dent.lineTo(-50*SK_Scalar1, 200*SK_Scalar1);
1108 dent.lineTo(-200*SK_Scalar1, 100*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001109 dent.close();
1110 check_convexity(reporter, dent, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001111 check_direction(reporter, dent, SkPath::kCW_Direction);
reed@google.com7c424812011-05-15 04:38:34 +00001112}
1113
reed@android.com6b82d1a2009-06-03 02:35:01 +00001114static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
1115 const SkRect& bounds) {
1116 REPORTER_ASSERT(reporter, p.isConvex());
1117 REPORTER_ASSERT(reporter, p.getBounds() == bounds);
reed@google.com62047cf2011-02-07 19:39:09 +00001118
reed@android.com6b82d1a2009-06-03 02:35:01 +00001119 SkPath p2(p);
1120 REPORTER_ASSERT(reporter, p2.isConvex());
1121 REPORTER_ASSERT(reporter, p2.getBounds() == bounds);
1122
1123 SkPath other;
1124 other.swap(p2);
1125 REPORTER_ASSERT(reporter, other.isConvex());
1126 REPORTER_ASSERT(reporter, other.getBounds() == bounds);
1127}
1128
reed@google.com04863fa2011-05-15 04:08:24 +00001129static void setFromString(SkPath* path, const char str[]) {
1130 bool first = true;
1131 while (str) {
1132 SkScalar x, y;
1133 str = SkParse::FindScalar(str, &x);
1134 if (NULL == str) {
1135 break;
1136 }
1137 str = SkParse::FindScalar(str, &y);
1138 SkASSERT(str);
1139 if (first) {
1140 path->moveTo(x, y);
1141 first = false;
1142 } else {
1143 path->lineTo(x, y);
1144 }
1145 }
1146}
1147
1148static void test_convexity(skiatest::Reporter* reporter) {
reed@google.com04863fa2011-05-15 04:08:24 +00001149 SkPath path;
1150
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001151 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001152 path.addCircle(0, 0, SkIntToScalar(10));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001153 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001154 path.addCircle(0, 0, SkIntToScalar(10)); // 2nd circle
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001155 check_convexity(reporter, path, SkPath::kConcave_Convexity);
1156
reed@google.com04863fa2011-05-15 04:08:24 +00001157 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001158 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001159 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.com3e71a882012-01-10 18:44:37 +00001160 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCCW_Direction));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001161
reed@google.com04863fa2011-05-15 04:08:24 +00001162 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001163 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001164 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.com3e71a882012-01-10 18:44:37 +00001165 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCW_Direction));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001166
reed@google.com04863fa2011-05-15 04:08:24 +00001167 static const struct {
1168 const char* fPathStr;
1169 SkPath::Convexity fExpectedConvexity;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001170 SkPath::Direction fExpectedDirection;
reed@google.com04863fa2011-05-15 04:08:24 +00001171 } gRec[] = {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001172 { "", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1173 { "0 0", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1174 { "0 0 10 10", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1175 { "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity, SkPath::kUnknown_Direction },
1176 { "0 0 10 10 10 20", SkPath::kConvex_Convexity, SkPath::kCW_Direction },
1177 { "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPath::kCCW_Direction },
1178 { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir },
1179 { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity, SkPath::kCW_Direction },
reed@google.com04863fa2011-05-15 04:08:24 +00001180 };
1181
1182 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1183 SkPath path;
1184 setFromString(&path, gRec[i].fPathStr);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001185 check_convexity(reporter, path, gRec[i].fExpectedConvexity);
1186 check_direction(reporter, path, gRec[i].fExpectedDirection);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001187 // check after setting the initial convex and direction
1188 if (kDontCheckDir != gRec[i].fExpectedDirection) {
1189 SkPath copy(path);
1190 SkPath::Direction dir;
1191 bool foundDir = copy.cheapComputeDirection(&dir);
1192 REPORTER_ASSERT(reporter, (gRec[i].fExpectedDirection == SkPath::kUnknown_Direction)
1193 ^ foundDir);
1194 REPORTER_ASSERT(reporter, !foundDir || gRec[i].fExpectedDirection == dir);
1195 check_convexity(reporter, copy, gRec[i].fExpectedConvexity);
1196 }
1197 REPORTER_ASSERT(reporter, gRec[i].fExpectedConvexity == path.getConvexity());
1198 check_direction(reporter, path, gRec[i].fExpectedDirection);
reed@google.com04863fa2011-05-15 04:08:24 +00001199 }
1200}
1201
reed@google.com7e6c4d12012-05-10 14:05:43 +00001202static void test_isLine(skiatest::Reporter* reporter) {
1203 SkPath path;
1204 SkPoint pts[2];
1205 const SkScalar value = SkIntToScalar(5);
1206
1207 REPORTER_ASSERT(reporter, !path.isLine(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001208
reed@google.com7e6c4d12012-05-10 14:05:43 +00001209 // set some non-zero values
1210 pts[0].set(value, value);
1211 pts[1].set(value, value);
1212 REPORTER_ASSERT(reporter, !path.isLine(pts));
1213 // check that pts was untouched
1214 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1215 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1216
1217 const SkScalar moveX = SkIntToScalar(1);
1218 const SkScalar moveY = SkIntToScalar(2);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001219 REPORTER_ASSERT(reporter, value != moveX && value != moveY);
reed@google.com7e6c4d12012-05-10 14:05:43 +00001220
1221 path.moveTo(moveX, moveY);
1222 REPORTER_ASSERT(reporter, !path.isLine(NULL));
1223 REPORTER_ASSERT(reporter, !path.isLine(pts));
1224 // check that pts was untouched
1225 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1226 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1227
1228 const SkScalar lineX = SkIntToScalar(2);
1229 const SkScalar lineY = SkIntToScalar(2);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001230 REPORTER_ASSERT(reporter, value != lineX && value != lineY);
reed@google.com7e6c4d12012-05-10 14:05:43 +00001231
1232 path.lineTo(lineX, lineY);
1233 REPORTER_ASSERT(reporter, path.isLine(NULL));
1234
1235 REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY));
1236 REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY));
1237 REPORTER_ASSERT(reporter, path.isLine(pts));
1238 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1239 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
1240
1241 path.lineTo(0, 0); // too many points/verbs
1242 REPORTER_ASSERT(reporter, !path.isLine(NULL));
1243 REPORTER_ASSERT(reporter, !path.isLine(pts));
1244 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1245 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001246
1247 path.reset();
1248 path.quadTo(1, 1, 2, 2);
1249 REPORTER_ASSERT(reporter, !path.isLine(NULL));
reed@google.com7e6c4d12012-05-10 14:05:43 +00001250}
1251
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001252static void test_conservativelyContains(skiatest::Reporter* reporter) {
1253 SkPath path;
1254
1255 // kBaseRect is used to construct most our test paths: a rect, a circle, and a round-rect.
1256 static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
1257
1258 // A circle that bounds kBaseRect (with a significant amount of slop)
1259 SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height());
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001260 circleR = SkScalarMul(circleR, 1.75f) / 2;
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001261 static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()};
1262
1263 // round-rect radii
1264 static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)};
skia.committer@gmail.comcec8de62012-11-14 02:01:22 +00001265
caryclark@google.com56f233a2012-11-19 13:06:06 +00001266 static const struct SUPPRESS_VISIBILITY_WARNING {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001267 SkRect fQueryRect;
1268 bool fInRect;
1269 bool fInCircle;
1270 bool fInRR;
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001271 bool fInCubicRR;
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001272 } kQueries[] = {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001273 {kBaseRect, true, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001274
1275 // rect well inside of kBaseRect
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001276 {SkRect::MakeLTRB(kBaseRect.fLeft + 0.25f*kBaseRect.width(),
1277 kBaseRect.fTop + 0.25f*kBaseRect.height(),
1278 kBaseRect.fRight - 0.25f*kBaseRect.width(),
1279 kBaseRect.fBottom - 0.25f*kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001280 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001281
1282 // rects with edges off by one from kBaseRect's edges
1283 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1284 kBaseRect.width(), kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001285 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001286 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1287 kBaseRect.width() + 1, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001288 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001289 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1290 kBaseRect.width() + 1, kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001291 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001292 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1293 kBaseRect.width(), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001294 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001295 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1296 kBaseRect.width(), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001297 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001298 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1299 kBaseRect.width() + 2, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001300 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001301 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1302 kBaseRect.width() + 2, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001303 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001304
1305 // zero-w/h rects at each corner of kBaseRect
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001306 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, false, false},
1307 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, false, true},
1308 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true, false, true},
1309 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true, false, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001310
1311 // far away rect
1312 {SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom,
1313 SkIntToScalar(10), SkIntToScalar(10)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001314 false, false, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001315
1316 // very large rect containing kBaseRect
1317 {SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(),
1318 kBaseRect.fTop - 5 * kBaseRect.height(),
1319 11 * kBaseRect.width(), 11 * kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001320 false, false, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001321
1322 // skinny rect that spans same y-range as kBaseRect
1323 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1324 SkIntToScalar(1), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001325 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001326
1327 // short rect that spans same x-range as kBaseRect
1328 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(), SkScalar(1)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001329 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001330
1331 // skinny rect that spans slightly larger y-range than kBaseRect
1332 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1333 SkIntToScalar(1), kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001334 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001335
1336 // short rect that spans slightly larger x-range than kBaseRect
1337 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(),
1338 kBaseRect.width() + 1, SkScalar(1)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001339 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001340 };
1341
1342 for (int inv = 0; inv < 4; ++inv) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001343 for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001344 SkRect qRect = kQueries[q].fQueryRect;
1345 if (inv & 0x1) {
1346 SkTSwap(qRect.fLeft, qRect.fRight);
1347 }
1348 if (inv & 0x2) {
1349 SkTSwap(qRect.fTop, qRect.fBottom);
1350 }
1351 for (int d = 0; d < 2; ++d) {
1352 SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
1353 path.reset();
1354 path.addRect(kBaseRect, dir);
1355 REPORTER_ASSERT(reporter, kQueries[q].fInRect ==
1356 path.conservativelyContainsRect(qRect));
1357
1358 path.reset();
1359 path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir);
1360 REPORTER_ASSERT(reporter, kQueries[q].fInCircle ==
1361 path.conservativelyContainsRect(qRect));
1362
1363 path.reset();
1364 path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir);
1365 REPORTER_ASSERT(reporter, kQueries[q].fInRR ==
1366 path.conservativelyContainsRect(qRect));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001367
1368 path.reset();
1369 path.moveTo(kBaseRect.fLeft + kRRRadii[0], kBaseRect.fTop);
1370 path.cubicTo(kBaseRect.fLeft + kRRRadii[0] / 2, kBaseRect.fTop,
1371 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1] / 2,
1372 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1]);
1373 path.lineTo(kBaseRect.fLeft, kBaseRect.fBottom);
1374 path.lineTo(kBaseRect.fRight, kBaseRect.fBottom);
1375 path.lineTo(kBaseRect.fRight, kBaseRect.fTop);
1376 path.close();
1377 REPORTER_ASSERT(reporter, kQueries[q].fInCubicRR ==
1378 path.conservativelyContainsRect(qRect));
1379
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001380 }
1381 // Slightly non-convex shape, shouldn't contain any rects.
1382 path.reset();
1383 path.moveTo(0, 0);
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001384 path.lineTo(SkIntToScalar(50), 0.05f);
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001385 path.lineTo(SkIntToScalar(100), 0);
1386 path.lineTo(SkIntToScalar(100), SkIntToScalar(100));
1387 path.lineTo(0, SkIntToScalar(100));
1388 path.close();
1389 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect));
1390 }
1391 }
1392
1393 // make sure a minimal convex shape works, a right tri with edges along pos x and y axes.
1394 path.reset();
1395 path.moveTo(0, 0);
1396 path.lineTo(SkIntToScalar(100), 0);
1397 path.lineTo(0, SkIntToScalar(100));
1398
1399 // inside, on along top edge
1400 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1401 SkIntToScalar(10),
1402 SkIntToScalar(10))));
1403 // above
1404 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1405 SkRect::MakeXYWH(SkIntToScalar(50),
1406 SkIntToScalar(-10),
1407 SkIntToScalar(10),
1408 SkIntToScalar(10))));
1409 // to the left
1410 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(-10),
1411 SkIntToScalar(5),
1412 SkIntToScalar(5),
1413 SkIntToScalar(5))));
1414
1415 // outside the diagonal edge
1416 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(10),
1417 SkIntToScalar(200),
1418 SkIntToScalar(20),
1419 SkIntToScalar(5))));
commit-bot@chromium.org62df5262013-08-01 15:35:06 +00001420
1421 // same as above path and first test but with an extra moveTo.
1422 path.reset();
1423 path.moveTo(100, 100);
1424 path.moveTo(0, 0);
1425 path.lineTo(SkIntToScalar(100), 0);
1426 path.lineTo(0, SkIntToScalar(100));
1427
1428 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1429 SkIntToScalar(10),
1430 SkIntToScalar(10))));
1431
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001432 path.reset();
1433 path.lineTo(100, 100);
1434 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(0, 0, 1, 1)));
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001435}
1436
reed@google.comf32322b2013-10-16 15:14:04 +00001437static void test_isRect_open_close(skiatest::Reporter* reporter) {
1438 SkPath path;
1439 bool isClosed;
1440
1441 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1);
1442
1443 if (false) {
1444 // I think these should pass, but isRect() doesn't behave
1445 // this way... yet
1446 REPORTER_ASSERT(reporter, path.isRect(NULL, NULL));
1447 REPORTER_ASSERT(reporter, path.isRect(&isClosed, NULL));
1448 REPORTER_ASSERT(reporter, !isClosed);
1449 }
1450
1451 path.close();
1452 REPORTER_ASSERT(reporter, path.isRect(NULL, NULL));
1453 REPORTER_ASSERT(reporter, path.isRect(&isClosed, NULL));
1454 REPORTER_ASSERT(reporter, isClosed);
1455}
1456
caryclark@google.comf1316942011-07-26 19:54:45 +00001457// Simple isRect test is inline TestPath, below.
1458// test_isRect provides more extensive testing.
1459static void test_isRect(skiatest::Reporter* reporter) {
reed@google.comf32322b2013-10-16 15:14:04 +00001460 test_isRect_open_close(reporter);
1461
caryclark@google.comf1316942011-07-26 19:54:45 +00001462 // passing tests (all moveTo / lineTo...
1463 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1464 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1465 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1466 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
1467 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
1468 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1469 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1470 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1471 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001472 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}};
1473 SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, {0, 1}, {0, .5f}};
caryclark@google.comf1316942011-07-26 19:54:45 +00001474 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}};
1475 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
1476 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}};
caryclark@google.combfe90372012-11-21 13:56:20 +00001477 SkPoint rf[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}};
rmistry@google.comd6176b02012-08-23 18:14:13 +00001478
caryclark@google.comf1316942011-07-26 19:54:45 +00001479 // failing tests
1480 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1481 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1482 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1483 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1484 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1485 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1486 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1487 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
caryclark@google.combfe90372012-11-21 13:56:20 +00001488 SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps
1489 SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non colinear gap
1490 SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short
rmistry@google.comd6176b02012-08-23 18:14:13 +00001491
caryclark@google.comf1316942011-07-26 19:54:45 +00001492 // failing, no close
1493 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
1494 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
1495
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001496 struct IsRectTest {
1497 SkPoint *fPoints;
1498 size_t fPointCount;
1499 bool fClose;
1500 bool fIsRect;
1501 } tests[] = {
1502 { r1, SK_ARRAY_COUNT(r1), true, true },
1503 { r2, SK_ARRAY_COUNT(r2), true, true },
1504 { r3, SK_ARRAY_COUNT(r3), true, true },
1505 { r4, SK_ARRAY_COUNT(r4), true, true },
1506 { r5, SK_ARRAY_COUNT(r5), true, true },
1507 { r6, SK_ARRAY_COUNT(r6), true, true },
1508 { r7, SK_ARRAY_COUNT(r7), true, true },
1509 { r8, SK_ARRAY_COUNT(r8), true, true },
1510 { r9, SK_ARRAY_COUNT(r9), true, true },
1511 { ra, SK_ARRAY_COUNT(ra), true, true },
1512 { rb, SK_ARRAY_COUNT(rb), true, true },
1513 { rc, SK_ARRAY_COUNT(rc), true, true },
1514 { rd, SK_ARRAY_COUNT(rd), true, true },
1515 { re, SK_ARRAY_COUNT(re), true, true },
1516 { rf, SK_ARRAY_COUNT(rf), true, true },
1517
1518 { f1, SK_ARRAY_COUNT(f1), true, false },
1519 { f2, SK_ARRAY_COUNT(f2), true, false },
1520 { f3, SK_ARRAY_COUNT(f3), true, false },
1521 { f4, SK_ARRAY_COUNT(f4), true, false },
1522 { f5, SK_ARRAY_COUNT(f5), true, false },
1523 { f6, SK_ARRAY_COUNT(f6), true, false },
1524 { f7, SK_ARRAY_COUNT(f7), true, false },
1525 { f8, SK_ARRAY_COUNT(f8), true, false },
1526 { f9, SK_ARRAY_COUNT(f9), true, false },
1527 { fa, SK_ARRAY_COUNT(fa), true, false },
1528 { fb, SK_ARRAY_COUNT(fb), true, false },
1529
1530 { c1, SK_ARRAY_COUNT(c1), false, false },
1531 { c2, SK_ARRAY_COUNT(c2), false, false },
caryclark@google.comf1316942011-07-26 19:54:45 +00001532 };
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001533
1534 const size_t testCount = SK_ARRAY_COUNT(tests);
caryclark@google.comf1316942011-07-26 19:54:45 +00001535 size_t index;
1536 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1537 SkPath path;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001538 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1539 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1540 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.comf1316942011-07-26 19:54:45 +00001541 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001542 if (tests[testIndex].fClose) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001543 path.close();
1544 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001545 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL));
1546 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL, NULL));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001547
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001548 if (tests[testIndex].fIsRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001549 SkRect computed, expected;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001550 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001551 REPORTER_ASSERT(reporter, path.isRect(&computed));
1552 REPORTER_ASSERT(reporter, expected == computed);
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +00001553
caryclark@google.comf68154a2012-11-21 15:18:06 +00001554 bool isClosed;
1555 SkPath::Direction direction, cheapDirection;
1556 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection));
robertphillips@google.com8fd16032013-06-25 15:39:58 +00001557 REPORTER_ASSERT(reporter, path.isRect(&isClosed, &direction));
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001558 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001559 REPORTER_ASSERT(reporter, direction == cheapDirection);
1560 } else {
1561 SkRect computed;
1562 computed.set(123, 456, 789, 1011);
1563 REPORTER_ASSERT(reporter, !path.isRect(&computed));
1564 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456);
1565 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011);
1566
1567 bool isClosed = (bool) -1;
1568 SkPath::Direction direction = (SkPath::Direction) -1;
robertphillips@google.com8fd16032013-06-25 15:39:58 +00001569 REPORTER_ASSERT(reporter, !path.isRect(&isClosed, &direction));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001570 REPORTER_ASSERT(reporter, isClosed == (bool) -1);
1571 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001572 }
caryclark@google.comf1316942011-07-26 19:54:45 +00001573 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00001574
caryclark@google.comf1316942011-07-26 19:54:45 +00001575 // fail, close then line
1576 SkPath path1;
1577 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001578 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001579 path1.lineTo(r1[index].fX, r1[index].fY);
1580 }
1581 path1.close();
1582 path1.lineTo(1, 0);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001583 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001584
caryclark@google.comf1316942011-07-26 19:54:45 +00001585 // fail, move in the middle
1586 path1.reset();
1587 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001588 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001589 if (index == 2) {
1590 path1.moveTo(1, .5f);
1591 }
1592 path1.lineTo(r1[index].fX, r1[index].fY);
1593 }
1594 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001595 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00001596
1597 // fail, move on the edge
1598 path1.reset();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001599 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001600 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1601 path1.lineTo(r1[index].fX, r1[index].fY);
1602 }
1603 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001604 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001605
caryclark@google.comf1316942011-07-26 19:54:45 +00001606 // fail, quad
1607 path1.reset();
1608 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001609 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001610 if (index == 2) {
1611 path1.quadTo(1, .5f, 1, .5f);
1612 }
1613 path1.lineTo(r1[index].fX, r1[index].fY);
1614 }
1615 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001616 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001617
caryclark@google.comf1316942011-07-26 19:54:45 +00001618 // fail, cubic
1619 path1.reset();
1620 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001621 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001622 if (index == 2) {
1623 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1624 }
1625 path1.lineTo(r1[index].fX, r1[index].fY);
1626 }
1627 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001628 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00001629}
1630
caryclark@google.com56f233a2012-11-19 13:06:06 +00001631static void test_isNestedRects(skiatest::Reporter* reporter) {
1632 // passing tests (all moveTo / lineTo...
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001633 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001634 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1635 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1636 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001637 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001638 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1639 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1640 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1641 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001642 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; // CCW
1643 SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, {0, 1}, {0, .5f}}; // CW
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001644 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW
1645 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW
1646 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001647
1648 // failing tests
1649 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1650 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1651 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1652 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1653 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1654 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1655 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1656 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
1657
1658 // failing, no close
1659 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
1660 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
1661
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001662 struct IsNestedRectTest {
1663 SkPoint *fPoints;
1664 size_t fPointCount;
1665 SkPath::Direction fDirection;
1666 bool fClose;
1667 bool fIsNestedRect; // nests with path.addRect(-1, -1, 2, 2);
1668 } tests[] = {
1669 { r1, SK_ARRAY_COUNT(r1), SkPath::kCW_Direction , true, true },
1670 { r2, SK_ARRAY_COUNT(r2), SkPath::kCW_Direction , true, true },
1671 { r3, SK_ARRAY_COUNT(r3), SkPath::kCW_Direction , true, true },
1672 { r4, SK_ARRAY_COUNT(r4), SkPath::kCW_Direction , true, true },
1673 { r5, SK_ARRAY_COUNT(r5), SkPath::kCCW_Direction, true, true },
1674 { r6, SK_ARRAY_COUNT(r6), SkPath::kCCW_Direction, true, true },
1675 { r7, SK_ARRAY_COUNT(r7), SkPath::kCCW_Direction, true, true },
1676 { r8, SK_ARRAY_COUNT(r8), SkPath::kCCW_Direction, true, true },
1677 { r9, SK_ARRAY_COUNT(r9), SkPath::kCCW_Direction, true, true },
1678 { ra, SK_ARRAY_COUNT(ra), SkPath::kCCW_Direction, true, true },
1679 { rb, SK_ARRAY_COUNT(rb), SkPath::kCW_Direction, true, true },
1680 { rc, SK_ARRAY_COUNT(rc), SkPath::kCW_Direction, true, true },
1681 { rd, SK_ARRAY_COUNT(rd), SkPath::kCCW_Direction, true, true },
1682 { re, SK_ARRAY_COUNT(re), SkPath::kCW_Direction, true, true },
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001683
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001684 { f1, SK_ARRAY_COUNT(f1), SkPath::kUnknown_Direction, true, false },
1685 { f2, SK_ARRAY_COUNT(f2), SkPath::kUnknown_Direction, true, false },
1686 { f3, SK_ARRAY_COUNT(f3), SkPath::kUnknown_Direction, true, false },
1687 { f4, SK_ARRAY_COUNT(f4), SkPath::kUnknown_Direction, true, false },
1688 { f5, SK_ARRAY_COUNT(f5), SkPath::kUnknown_Direction, true, false },
1689 { f6, SK_ARRAY_COUNT(f6), SkPath::kUnknown_Direction, true, false },
1690 { f7, SK_ARRAY_COUNT(f7), SkPath::kUnknown_Direction, true, false },
1691 { f8, SK_ARRAY_COUNT(f8), SkPath::kUnknown_Direction, true, false },
1692
1693 { c1, SK_ARRAY_COUNT(c1), SkPath::kUnknown_Direction, false, false },
1694 { c2, SK_ARRAY_COUNT(c2), SkPath::kUnknown_Direction, false, false },
1695 };
1696
1697 const size_t testCount = SK_ARRAY_COUNT(tests);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001698 size_t index;
1699 for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001700 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1701 SkPath path;
1702 if (rectFirst) {
1703 path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1704 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001705 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1706 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1707 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001708 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001709 if (tests[testIndex].fClose) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001710 path.close();
1711 }
1712 if (!rectFirst) {
1713 path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1714 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001715 REPORTER_ASSERT(reporter, tests[testIndex].fIsNestedRect == path.isNestedRects(NULL));
1716 if (tests[testIndex].fIsNestedRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001717 SkRect expected[2], computed[2];
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001718 SkPath::Direction expectedDirs[2], computedDirs[2];
caryclark@google.com56f233a2012-11-19 13:06:06 +00001719 SkRect testBounds;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001720 testBounds.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001721 expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2);
1722 expected[1] = testBounds;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001723 if (rectFirst) {
1724 expectedDirs[0] = SkPath::kCW_Direction;
1725 } else {
1726 expectedDirs[0] = SkPath::kCCW_Direction;
1727 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001728 expectedDirs[1] = tests[testIndex].fDirection;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001729 REPORTER_ASSERT(reporter, path.isNestedRects(computed, computedDirs));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001730 REPORTER_ASSERT(reporter, expected[0] == computed[0]);
1731 REPORTER_ASSERT(reporter, expected[1] == computed[1]);
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001732 REPORTER_ASSERT(reporter, expectedDirs[0] == computedDirs[0]);
1733 REPORTER_ASSERT(reporter, expectedDirs[1] == computedDirs[1]);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001734 }
caryclark@google.com56f233a2012-11-19 13:06:06 +00001735 }
1736
1737 // fail, close then line
1738 SkPath path1;
1739 if (rectFirst) {
1740 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1741 }
1742 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001743 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001744 path1.lineTo(r1[index].fX, r1[index].fY);
1745 }
1746 path1.close();
1747 path1.lineTo(1, 0);
1748 if (!rectFirst) {
1749 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1750 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001751 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001752
1753 // fail, move in the middle
1754 path1.reset();
1755 if (rectFirst) {
1756 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1757 }
1758 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001759 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001760 if (index == 2) {
1761 path1.moveTo(1, .5f);
1762 }
1763 path1.lineTo(r1[index].fX, r1[index].fY);
1764 }
1765 path1.close();
1766 if (!rectFirst) {
1767 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1768 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001769 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001770
1771 // fail, move on the edge
1772 path1.reset();
1773 if (rectFirst) {
1774 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1775 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001776 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001777 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1778 path1.lineTo(r1[index].fX, r1[index].fY);
1779 }
1780 path1.close();
1781 if (!rectFirst) {
1782 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1783 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001784 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001785
1786 // fail, quad
1787 path1.reset();
1788 if (rectFirst) {
1789 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1790 }
1791 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001792 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001793 if (index == 2) {
1794 path1.quadTo(1, .5f, 1, .5f);
1795 }
1796 path1.lineTo(r1[index].fX, r1[index].fY);
1797 }
1798 path1.close();
1799 if (!rectFirst) {
1800 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1801 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001802 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001803
1804 // fail, cubic
1805 path1.reset();
1806 if (rectFirst) {
1807 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1808 }
1809 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001810 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001811 if (index == 2) {
1812 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1813 }
1814 path1.lineTo(r1[index].fX, r1[index].fY);
1815 }
1816 path1.close();
1817 if (!rectFirst) {
1818 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1819 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001820 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001821
caryclark@google.com56f233a2012-11-19 13:06:06 +00001822 // fail, not nested
1823 path1.reset();
1824 path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction);
1825 path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001826 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001827 }
caryclark@google.combfe90372012-11-21 13:56:20 +00001828
1829 // pass, stroke rect
1830 SkPath src, dst;
1831 src.addRect(1, 1, 7, 7, SkPath::kCW_Direction);
1832 SkPaint strokePaint;
1833 strokePaint.setStyle(SkPaint::kStroke_Style);
1834 strokePaint.setStrokeWidth(2);
1835 strokePaint.getFillPath(src, &dst);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001836 REPORTER_ASSERT(reporter, dst.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001837}
1838
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001839static void write_and_read_back(skiatest::Reporter* reporter,
1840 const SkPath& p) {
1841 SkWriter32 writer(100);
1842 writer.writePath(p);
reed@google.com44699382013-10-31 17:28:30 +00001843 size_t size = writer.bytesWritten();
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001844 SkAutoMalloc storage(size);
1845 writer.flatten(storage.get());
1846 SkReader32 reader(storage.get(), size);
1847
1848 SkPath readBack;
1849 REPORTER_ASSERT(reporter, readBack != p);
1850 reader.readPath(&readBack);
1851 REPORTER_ASSERT(reporter, readBack == p);
1852
rmistry@google.comd6176b02012-08-23 18:14:13 +00001853 REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() ==
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001854 p.getConvexityOrUnknown());
1855
1856 REPORTER_ASSERT(reporter, readBack.isOval(NULL) == p.isOval(NULL));
1857
1858 const SkRect& origBounds = p.getBounds();
1859 const SkRect& readBackBounds = readBack.getBounds();
1860
1861 REPORTER_ASSERT(reporter, origBounds == readBackBounds);
1862}
1863
reed@google.com53effc52011-09-21 19:05:12 +00001864static void test_flattening(skiatest::Reporter* reporter) {
1865 SkPath p;
1866
1867 static const SkPoint pts[] = {
1868 { 0, 0 },
1869 { SkIntToScalar(10), SkIntToScalar(10) },
1870 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 },
1871 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }
1872 };
1873 p.moveTo(pts[0]);
1874 p.lineTo(pts[1]);
1875 p.quadTo(pts[2], pts[3]);
1876 p.cubicTo(pts[4], pts[5], pts[6]);
1877
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001878 write_and_read_back(reporter, p);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00001879
1880 // create a buffer that should be much larger than the path so we don't
1881 // kill our stack if writer goes too far.
1882 char buffer[1024];
commit-bot@chromium.org4faa8692013-11-05 15:46:56 +00001883 size_t size1 = p.writeToMemory(NULL);
1884 size_t size2 = p.writeToMemory(buffer);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00001885 REPORTER_ASSERT(reporter, size1 == size2);
1886
1887 SkPath p2;
commit-bot@chromium.org4faa8692013-11-05 15:46:56 +00001888 size_t size3 = p2.readFromMemory(buffer, 1024);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00001889 REPORTER_ASSERT(reporter, size1 == size3);
1890 REPORTER_ASSERT(reporter, p == p2);
1891
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001892 size3 = p2.readFromMemory(buffer, 0);
1893 REPORTER_ASSERT(reporter, !size3);
1894
1895 SkPath tooShort;
1896 size3 = tooShort.readFromMemory(buffer, size1 - 1);
1897 REPORTER_ASSERT(reporter, tooShort.isEmpty());
1898
djsollen@google.com94e75ee2012-06-08 18:30:46 +00001899 char buffer2[1024];
1900 size3 = p2.writeToMemory(buffer2);
1901 REPORTER_ASSERT(reporter, size1 == size3);
1902 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001903
1904 // test persistence of the oval flag & convexity
1905 {
1906 SkPath oval;
1907 SkRect rect = SkRect::MakeWH(10, 10);
1908 oval.addOval(rect);
1909
1910 write_and_read_back(reporter, oval);
1911 }
reed@google.com53effc52011-09-21 19:05:12 +00001912}
1913
1914static void test_transform(skiatest::Reporter* reporter) {
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00001915 SkPath p;
rmistry@google.comd6176b02012-08-23 18:14:13 +00001916
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001917#define CONIC_PERSPECTIVE_BUG_FIXED 0
reed@google.com53effc52011-09-21 19:05:12 +00001918 static const SkPoint pts[] = {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001919 { 0, 0 }, // move
1920 { SkIntToScalar(10), SkIntToScalar(10) }, // line
1921 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, // quad
1922 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }, // cubic
1923#if CONIC_PERSPECTIVE_BUG_FIXED
1924 { 0, 0 }, { SkIntToScalar(20), SkIntToScalar(10) }, // conic
1925#endif
reed@google.com53effc52011-09-21 19:05:12 +00001926 };
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001927 const int kPtCount = SK_ARRAY_COUNT(pts);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00001928
reed@google.com53effc52011-09-21 19:05:12 +00001929 p.moveTo(pts[0]);
1930 p.lineTo(pts[1]);
1931 p.quadTo(pts[2], pts[3]);
1932 p.cubicTo(pts[4], pts[5], pts[6]);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001933#if CONIC_PERSPECTIVE_BUG_FIXED
1934 p.conicTo(pts[4], pts[5], 0.5f);
1935#endif
1936 p.close();
rmistry@google.comd6176b02012-08-23 18:14:13 +00001937
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00001938 {
1939 SkMatrix matrix;
1940 matrix.reset();
1941 SkPath p1;
1942 p.transform(matrix, &p1);
1943 REPORTER_ASSERT(reporter, p == p1);
reed@google.com53effc52011-09-21 19:05:12 +00001944 }
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001945
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00001946
1947 {
1948 SkMatrix matrix;
1949 matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3);
1950
1951 SkPath p1; // Leave p1 non-unique (i.e., the empty path)
1952
skia.committer@gmail.com6e515d62013-12-04 07:02:26 +00001953 p.transform(matrix, &p1);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00001954 SkPoint pts1[kPtCount];
skia.committer@gmail.com6e515d62013-12-04 07:02:26 +00001955 int count = p1.getPoints(pts1, kPtCount);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00001956 REPORTER_ASSERT(reporter, kPtCount == count);
1957 for (int i = 0; i < count; ++i) {
1958 SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3);
1959 REPORTER_ASSERT(reporter, newPt == pts1[i]);
1960 }
1961 }
1962
1963 {
1964 SkMatrix matrix;
1965 matrix.reset();
1966 matrix.setPerspX(SkScalarToPersp(4));
1967
1968 SkPath p1;
1969 p1.moveTo(SkPoint::Make(0, 0));
1970
1971 p.transform(matrix, &p1);
1972 REPORTER_ASSERT(reporter, matrix.invert(&matrix));
1973 p1.transform(matrix, NULL);
1974 SkRect pBounds = p.getBounds();
1975 SkRect p1Bounds = p1.getBounds();
1976 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fLeft, p1Bounds.fLeft));
1977 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fTop, p1Bounds.fTop));
1978 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fRight, p1Bounds.fRight));
1979 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fBottom, p1Bounds.fBottom));
1980 }
1981
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001982 p.reset();
1983 p.addCircle(0, 0, 1, SkPath::kCW_Direction);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00001984
1985 {
1986 SkMatrix matrix;
1987 matrix.reset();
1988 SkPath p1;
1989 p1.moveTo(SkPoint::Make(0, 0));
1990
1991 p.transform(matrix, &p1);
1992 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCW_Direction));
1993 }
1994
1995
1996 {
1997 SkMatrix matrix;
1998 matrix.reset();
1999 matrix.setScaleX(-1);
2000 SkPath p1;
2001 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
2002
2003 p.transform(matrix, &p1);
2004 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCCW_Direction));
2005 }
2006
2007 {
2008 SkMatrix matrix;
2009 matrix.setAll(1, 1, 0, 1, 1, 0, 0, 0, 1);
2010 SkPath p1;
2011 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
2012
2013 p.transform(matrix, &p1);
2014 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kUnknown_Direction));
2015 }
reed@google.com53effc52011-09-21 19:05:12 +00002016}
2017
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002018static void test_zero_length_paths(skiatest::Reporter* reporter) {
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002019 SkPath p;
schenney@chromium.org7e963602012-06-13 17:05:43 +00002020 uint8_t verbs[32];
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002021
caryclark@google.com56f233a2012-11-19 13:06:06 +00002022 struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData {
schenney@chromium.org7e963602012-06-13 17:05:43 +00002023 const char* testPath;
2024 const size_t numResultPts;
2025 const SkRect resultBound;
2026 const SkPath::Verb* resultVerbs;
2027 const size_t numResultVerbs;
2028 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002029
schenney@chromium.org7e963602012-06-13 17:05:43 +00002030 static const SkPath::Verb resultVerbs1[] = { SkPath::kMove_Verb };
2031 static const SkPath::Verb resultVerbs2[] = { SkPath::kMove_Verb, SkPath::kMove_Verb };
2032 static const SkPath::Verb resultVerbs3[] = { SkPath::kMove_Verb, SkPath::kClose_Verb };
2033 static const SkPath::Verb resultVerbs4[] = { SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb };
2034 static const SkPath::Verb resultVerbs5[] = { SkPath::kMove_Verb, SkPath::kLine_Verb };
2035 static const SkPath::Verb resultVerbs6[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb };
2036 static const SkPath::Verb resultVerbs7[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb };
2037 static const SkPath::Verb resultVerbs8[] = {
2038 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb
2039 };
2040 static const SkPath::Verb resultVerbs9[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb };
2041 static const SkPath::Verb resultVerbs10[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb };
2042 static const SkPath::Verb resultVerbs11[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb };
2043 static const SkPath::Verb resultVerbs12[] = {
2044 SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb
2045 };
2046 static const SkPath::Verb resultVerbs13[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb };
2047 static const SkPath::Verb resultVerbs14[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb };
2048 static const SkPath::Verb resultVerbs15[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb };
2049 static const SkPath::Verb resultVerbs16[] = {
2050 SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb
2051 };
2052 static const struct zeroPathTestData gZeroLengthTests[] = {
2053 { "M 1 1", 1, {0, 0, 0, 0}, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002054 { "M 1 1 M 2 1", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
schenney@chromium.org7e963602012-06-13 17:05:43 +00002055 { "M 1 1 z", 1, {0, 0, 0, 0}, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002056 { "M 1 1 z M 2 1 z", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
2057 { "M 1 1 L 1 1", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) },
2058 { "M 1 1 L 1 1 M 2 1 L 2 1", 4, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs6, SK_ARRAY_COUNT(resultVerbs6) },
2059 { "M 1 1 L 1 1 z", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs7, SK_ARRAY_COUNT(resultVerbs7) },
2060 { "M 1 1 L 1 1 z M 2 1 L 2 1 z", 4, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs8, SK_ARRAY_COUNT(resultVerbs8) },
2061 { "M 1 1 Q 1 1 1 1", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs9, SK_ARRAY_COUNT(resultVerbs9) },
2062 { "M 1 1 Q 1 1 1 1 M 2 1 Q 2 1 2 1", 6, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs10, SK_ARRAY_COUNT(resultVerbs10) },
2063 { "M 1 1 Q 1 1 1 1 z", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs11, SK_ARRAY_COUNT(resultVerbs11) },
2064 { "M 1 1 Q 1 1 1 1 z M 2 1 Q 2 1 2 1 z", 6, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs12, SK_ARRAY_COUNT(resultVerbs12) },
2065 { "M 1 1 C 1 1 1 1 1 1", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs13, SK_ARRAY_COUNT(resultVerbs13) },
2066 { "M 1 1 C 1 1 1 1 1 1 M 2 1 C 2 1 2 1 2 1", 8, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs14,
schenney@chromium.org7e963602012-06-13 17:05:43 +00002067 SK_ARRAY_COUNT(resultVerbs14)
2068 },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002069 { "M 1 1 C 1 1 1 1 1 1 z", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs15, SK_ARRAY_COUNT(resultVerbs15) },
2070 { "M 1 1 C 1 1 1 1 1 1 z M 2 1 C 2 1 2 1 2 1 z", 8, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs16,
schenney@chromium.org7e963602012-06-13 17:05:43 +00002071 SK_ARRAY_COUNT(resultVerbs16)
2072 }
2073 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002074
schenney@chromium.org7e963602012-06-13 17:05:43 +00002075 for (size_t i = 0; i < SK_ARRAY_COUNT(gZeroLengthTests); ++i) {
2076 p.reset();
2077 bool valid = SkParsePath::FromSVGString(gZeroLengthTests[i].testPath, &p);
2078 REPORTER_ASSERT(reporter, valid);
2079 REPORTER_ASSERT(reporter, !p.isEmpty());
2080 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultPts == (size_t)p.countPoints());
2081 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultBound == p.getBounds());
2082 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultVerbs == (size_t)p.getVerbs(verbs, SK_ARRAY_COUNT(verbs)));
2083 for (size_t j = 0; j < gZeroLengthTests[i].numResultVerbs; ++j) {
2084 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultVerbs[j] == verbs[j]);
2085 }
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002086 }
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002087}
2088
2089struct SegmentInfo {
2090 SkPath fPath;
2091 int fPointCount;
2092};
2093
reed@google.com10296cc2011-09-21 12:29:05 +00002094#define kCurveSegmentMask (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask)
2095
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002096static void test_segment_masks(skiatest::Reporter* reporter) {
reed@google.comeef938c2012-08-01 20:01:49 +00002097 SkPath p, p2;
2098
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002099 p.moveTo(0, 0);
2100 p.quadTo(100, 100, 200, 200);
2101 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == p.getSegmentMasks());
2102 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00002103 p2 = p;
2104 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002105 p.cubicTo(100, 100, 200, 200, 300, 300);
2106 REPORTER_ASSERT(reporter, kCurveSegmentMask == p.getSegmentMasks());
2107 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00002108 p2 = p;
2109 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
2110
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002111 p.reset();
2112 p.moveTo(0, 0);
2113 p.cubicTo(100, 100, 200, 200, 300, 300);
2114 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == p.getSegmentMasks());
reed@google.comeef938c2012-08-01 20:01:49 +00002115 p2 = p;
2116 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
rmistry@google.comd6176b02012-08-23 18:14:13 +00002117
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002118 REPORTER_ASSERT(reporter, !p.isEmpty());
2119}
2120
2121static void test_iter(skiatest::Reporter* reporter) {
schenney@chromium.org7e963602012-06-13 17:05:43 +00002122 SkPath p;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002123 SkPoint pts[4];
2124
2125 // Test an iterator with no path
2126 SkPath::Iter noPathIter;
2127 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002128
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002129 // Test that setting an empty path works
2130 noPathIter.setPath(p, false);
2131 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002132
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002133 // Test that close path makes no difference for an empty path
2134 noPathIter.setPath(p, true);
2135 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002136
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002137 // Test an iterator with an initial empty path
2138 SkPath::Iter iter(p, false);
2139 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2140
2141 // Test that close path makes no difference
schenney@chromium.org7e963602012-06-13 17:05:43 +00002142 iter.setPath(p, true);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002143 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2144
rmistry@google.comd6176b02012-08-23 18:14:13 +00002145
schenney@chromium.org7e963602012-06-13 17:05:43 +00002146 struct iterTestData {
2147 const char* testPath;
2148 const bool forceClose;
2149 const bool consumeDegenerates;
2150 const size_t* numResultPtsPerVerb;
2151 const SkPoint* resultPts;
2152 const SkPath::Verb* resultVerbs;
2153 const size_t numResultVerbs;
2154 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002155
schenney@chromium.org7e963602012-06-13 17:05:43 +00002156 static const SkPath::Verb resultVerbs1[] = { SkPath::kDone_Verb };
2157 static const SkPath::Verb resultVerbs2[] = {
2158 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kDone_Verb
2159 };
2160 static const SkPath::Verb resultVerbs3[] = {
2161 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2162 };
2163 static const SkPath::Verb resultVerbs4[] = {
2164 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2165 };
2166 static const SkPath::Verb resultVerbs5[] = {
2167 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2168 };
2169 static const size_t resultPtsSizes1[] = { 0 };
schenney@chromium.orgfedd09b2012-06-13 18:29:20 +00002170 static const size_t resultPtsSizes2[] = { 1, 2, 2, 0 };
2171 static const size_t resultPtsSizes3[] = { 1, 2, 2, 2, 1, 0 };
2172 static const size_t resultPtsSizes4[] = { 1, 2, 1, 1, 0 };
2173 static const size_t resultPtsSizes5[] = { 1, 2, 1, 1, 1, 0 };
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002174 static const SkPoint* resultPts1 = 0;
schenney@chromium.org7e963602012-06-13 17:05:43 +00002175 static const SkPoint resultPts2[] = {
2176 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 }
2177 };
2178 static const SkPoint resultPts3[] = {
2179 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 },
2180 { 0, SK_Scalar1 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }
2181 };
2182 static const SkPoint resultPts4[] = {
2183 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
2184 };
2185 static const SkPoint resultPts5[] = {
2186 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
2187 };
2188 static const struct iterTestData gIterTests[] = {
2189 { "M 1 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002190 { "M 1 0 M 2 0 M 3 0 M 4 0 M 5 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2191 { "M 1 0 M 1 0 M 3 0 M 4 0 M 5 0", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.org7e963602012-06-13 17:05:43 +00002192 { "z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2193 { "z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2194 { "z M 1 0 z z M 2 0 z M 3 0 M 4 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2195 { "z M 1 0 z z M 2 0 z M 3 0 M 4 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002196 { "M 1 0 L 1 1 L 0 1 M 0 0 z", false, true, resultPtsSizes2, resultPts2, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
2197 { "M 1 0 L 1 1 L 0 1 M 0 0 z", true, true, resultPtsSizes3, resultPts3, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
2198 { "M 1 0 L 1 0 M 0 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2199 { "M 1 0 L 1 0 M 0 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2200 { "M 1 0 L 1 0 M 0 0 z", false, false, resultPtsSizes4, resultPts4, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
2201 { "M 1 0 L 1 0 M 0 0 z", true, false, resultPtsSizes5, resultPts5, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) }
schenney@chromium.org7e963602012-06-13 17:05:43 +00002202 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002203
schenney@chromium.org7e963602012-06-13 17:05:43 +00002204 for (size_t i = 0; i < SK_ARRAY_COUNT(gIterTests); ++i) {
2205 p.reset();
2206 bool valid = SkParsePath::FromSVGString(gIterTests[i].testPath, &p);
2207 REPORTER_ASSERT(reporter, valid);
2208 iter.setPath(p, gIterTests[i].forceClose);
2209 int j = 0, l = 0;
2210 do {
2211 REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegenerates) == gIterTests[i].resultVerbs[j]);
2212 for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k) {
2213 REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]);
2214 }
2215 } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb);
2216 REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs);
2217 }
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002218
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002219 p.reset();
2220 iter.setPath(p, false);
2221 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2222 p.lineTo(1, 1);
2223 p.close();
2224 iter.setPath(p, false);
2225 REPORTER_ASSERT(reporter, iter.isClosedContour());
2226 p.reset();
2227 iter.setPath(p, true);
2228 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2229 p.lineTo(1, 1);
2230 iter.setPath(p, true);
2231 REPORTER_ASSERT(reporter, iter.isClosedContour());
2232 p.moveTo(0, 0);
2233 p.lineTo(2, 2);
2234 iter.setPath(p, false);
2235 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2236
2237 // this checks to see if the NaN logic is executed in SkPath::autoClose(), but does not
2238 // check to see if the result is correct.
2239 for (int setNaN = 0; setNaN < 4; ++setNaN) {
2240 p.reset();
2241 p.moveTo(setNaN == 0 ? SK_ScalarNaN : 0, setNaN == 1 ? SK_ScalarNaN : 0);
2242 p.lineTo(setNaN == 2 ? SK_ScalarNaN : 1, setNaN == 3 ? SK_ScalarNaN : 1);
2243 iter.setPath(p, true);
2244 iter.next(pts, false);
2245 iter.next(pts, false);
2246 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == iter.next(pts, false));
2247 }
2248
2249 p.reset();
2250 p.quadTo(0, 0, 0, 0);
2251 iter.setPath(p, false);
2252 iter.next(pts, false);
2253 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == iter.next(pts, false));
2254 iter.setPath(p, false);
2255 iter.next(pts, false);
2256 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2257
2258 p.reset();
2259 p.conicTo(0, 0, 0, 0, 0.5f);
2260 iter.setPath(p, false);
2261 iter.next(pts, false);
2262 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts, false));
2263 iter.setPath(p, false);
2264 iter.next(pts, false);
2265 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2266
2267 p.reset();
2268 p.cubicTo(0, 0, 0, 0, 0, 0);
2269 iter.setPath(p, false);
2270 iter.next(pts, false);
2271 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
2272 iter.setPath(p, false);
2273 iter.next(pts, false);
2274 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2275
2276 p.moveTo(1, 1); // add a trailing moveto
2277 iter.setPath(p, false);
2278 iter.next(pts, false);
2279 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
2280 iter.setPath(p, false);
2281 iter.next(pts, false);
2282 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2283
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002284 // The GM degeneratesegments.cpp test is more extensive
2285}
2286
2287static void test_raw_iter(skiatest::Reporter* reporter) {
2288 SkPath p;
2289 SkPoint pts[4];
2290
2291 // Test an iterator with no path
2292 SkPath::RawIter noPathIter;
2293 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
2294 // Test that setting an empty path works
2295 noPathIter.setPath(p);
2296 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
rmistry@google.comd6176b02012-08-23 18:14:13 +00002297
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002298 // Test an iterator with an initial empty path
2299 SkPath::RawIter iter(p);
2300 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2301
2302 // Test that a move-only path returns the move.
2303 p.moveTo(SK_Scalar1, 0);
2304 iter.setPath(p);
2305 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2306 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2307 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2308 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2309
2310 // No matter how many moves we add, we should get them all back
2311 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2312 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2313 iter.setPath(p);
2314 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2315 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2316 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2317 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2318 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2319 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2320 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2321 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2322 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2323 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2324
2325 // Initial close is never ever stored
2326 p.reset();
2327 p.close();
2328 iter.setPath(p);
2329 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2330
2331 // Move/close sequences
2332 p.reset();
2333 p.close(); // Not stored, no purpose
2334 p.moveTo(SK_Scalar1, 0);
2335 p.close();
2336 p.close(); // Not stored, no purpose
2337 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2338 p.close();
2339 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2340 p.moveTo(SK_Scalar1*4, SK_Scalar1*3);
2341 p.close();
2342 iter.setPath(p);
2343 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2344 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2345 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2346 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2347 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2348 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2349 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2350 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2351 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2352 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2353 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2354 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2355 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2356 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2357 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2358 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2359 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2360 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2361 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2362 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2363 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2364 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2365
2366 // Generate random paths and verify
2367 SkPoint randomPts[25];
2368 for (int i = 0; i < 5; ++i) {
2369 for (int j = 0; j < 5; ++j) {
2370 randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j);
2371 }
2372 }
2373
2374 // Max of 10 segments, max 3 points per segment
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +00002375 SkRandom rand(9876543);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002376 SkPoint expectedPts[31]; // May have leading moveTo
reed@google.comd335d1d2012-01-12 18:17:11 +00002377 SkPath::Verb expectedVerbs[22]; // May have leading moveTo
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002378 SkPath::Verb nextVerb;
reed@google.comd335d1d2012-01-12 18:17:11 +00002379
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002380 for (int i = 0; i < 500; ++i) {
2381 p.reset();
2382 bool lastWasClose = true;
2383 bool haveMoveTo = false;
reed@google.comd335d1d2012-01-12 18:17:11 +00002384 SkPoint lastMoveToPt = { 0, 0 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002385 int numPoints = 0;
2386 int numVerbs = (rand.nextU() >> 16) % 10;
2387 int numIterVerbs = 0;
2388 for (int j = 0; j < numVerbs; ++j) {
2389 do {
2390 nextVerb = static_cast<SkPath::Verb>((rand.nextU() >> 16) % SkPath::kDone_Verb);
2391 } while (lastWasClose && nextVerb == SkPath::kClose_Verb);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002392 switch (nextVerb) {
2393 case SkPath::kMove_Verb:
2394 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2395 p.moveTo(expectedPts[numPoints]);
reed@google.comd335d1d2012-01-12 18:17:11 +00002396 lastMoveToPt = expectedPts[numPoints];
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002397 numPoints += 1;
2398 lastWasClose = false;
2399 haveMoveTo = true;
2400 break;
2401 case SkPath::kLine_Verb:
2402 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002403 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002404 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2405 haveMoveTo = true;
2406 }
2407 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2408 p.lineTo(expectedPts[numPoints]);
2409 numPoints += 1;
2410 lastWasClose = false;
2411 break;
2412 case SkPath::kQuad_Verb:
2413 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002414 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002415 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2416 haveMoveTo = true;
2417 }
2418 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2419 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2420 p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]);
2421 numPoints += 2;
2422 lastWasClose = false;
2423 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002424 case SkPath::kConic_Verb:
2425 if (!haveMoveTo) {
2426 expectedPts[numPoints++] = lastMoveToPt;
2427 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2428 haveMoveTo = true;
2429 }
2430 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2431 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2432 p.conicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2433 rand.nextUScalar1() * 4);
2434 numPoints += 2;
2435 lastWasClose = false;
2436 break;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002437 case SkPath::kCubic_Verb:
2438 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002439 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002440 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2441 haveMoveTo = true;
2442 }
2443 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2444 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2445 expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25];
2446 p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2447 expectedPts[numPoints + 2]);
2448 numPoints += 3;
2449 lastWasClose = false;
2450 break;
2451 case SkPath::kClose_Verb:
2452 p.close();
reed@google.comd335d1d2012-01-12 18:17:11 +00002453 haveMoveTo = false;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002454 lastWasClose = true;
2455 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002456 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002457 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002458 }
2459 expectedVerbs[numIterVerbs++] = nextVerb;
2460 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00002461
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002462 iter.setPath(p);
2463 numVerbs = numIterVerbs;
2464 numIterVerbs = 0;
2465 int numIterPts = 0;
2466 SkPoint lastMoveTo;
2467 SkPoint lastPt;
2468 lastMoveTo.set(0, 0);
2469 lastPt.set(0, 0);
2470 while ((nextVerb = iter.next(pts)) != SkPath::kDone_Verb) {
2471 REPORTER_ASSERT(reporter, nextVerb == expectedVerbs[numIterVerbs]);
2472 numIterVerbs++;
2473 switch (nextVerb) {
2474 case SkPath::kMove_Verb:
2475 REPORTER_ASSERT(reporter, numIterPts < numPoints);
2476 REPORTER_ASSERT(reporter, pts[0] == expectedPts[numIterPts]);
2477 lastPt = lastMoveTo = pts[0];
2478 numIterPts += 1;
2479 break;
2480 case SkPath::kLine_Verb:
2481 REPORTER_ASSERT(reporter, numIterPts < numPoints + 1);
2482 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2483 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2484 lastPt = pts[1];
2485 numIterPts += 1;
2486 break;
2487 case SkPath::kQuad_Verb:
reed@google.com277c3f82013-05-31 15:17:50 +00002488 case SkPath::kConic_Verb:
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002489 REPORTER_ASSERT(reporter, numIterPts < numPoints + 2);
2490 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2491 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2492 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2493 lastPt = pts[2];
2494 numIterPts += 2;
2495 break;
2496 case SkPath::kCubic_Verb:
2497 REPORTER_ASSERT(reporter, numIterPts < numPoints + 3);
2498 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2499 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2500 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2501 REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]);
2502 lastPt = pts[3];
2503 numIterPts += 3;
2504 break;
2505 case SkPath::kClose_Verb:
2506 REPORTER_ASSERT(reporter, pts[0] == lastMoveTo);
2507 lastPt = lastMoveTo;
2508 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002509 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002510 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002511 }
2512 }
2513 REPORTER_ASSERT(reporter, numIterPts == numPoints);
2514 REPORTER_ASSERT(reporter, numIterVerbs == numVerbs);
2515 }
2516}
2517
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002518static void check_for_circle(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002519 const SkPath& path,
2520 bool expectedCircle,
2521 SkPath::Direction expectedDir) {
robertphillips@google.com466310d2013-12-03 16:43:54 +00002522 SkRect rect = SkRect::MakeEmpty();
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002523 REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle);
2524 REPORTER_ASSERT(reporter, path.cheapIsDirection(expectedDir));
skia.committer@gmail.comfbb0ed92012-11-13 21:46:06 +00002525
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002526 if (expectedCircle) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002527 REPORTER_ASSERT(reporter, rect.height() == rect.width());
2528 }
2529}
2530
2531static void test_circle_skew(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002532 const SkPath& path,
2533 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002534 SkPath tmp;
2535
2536 SkMatrix m;
2537 m.setSkew(SkIntToScalar(3), SkIntToScalar(5));
2538 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002539 // this matrix reverses the direction.
2540 if (SkPath::kCCW_Direction == dir) {
2541 dir = SkPath::kCW_Direction;
2542 } else {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002543 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002544 dir = SkPath::kCCW_Direction;
2545 }
2546 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002547}
2548
2549static void test_circle_translate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002550 const SkPath& path,
2551 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002552 SkPath tmp;
2553
2554 // translate at small offset
2555 SkMatrix m;
2556 m.setTranslate(SkIntToScalar(15), SkIntToScalar(15));
2557 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002558 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002559
2560 tmp.reset();
2561 m.reset();
2562
2563 // translate at a relatively big offset
2564 m.setTranslate(SkIntToScalar(1000), SkIntToScalar(1000));
2565 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002566 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002567}
2568
2569static void test_circle_rotate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002570 const SkPath& path,
2571 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002572 for (int angle = 0; angle < 360; ++angle) {
2573 SkPath tmp;
2574 SkMatrix m;
2575 m.setRotate(SkIntToScalar(angle));
2576 path.transform(m, &tmp);
2577
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002578 // TODO: a rotated circle whose rotated angle is not a multiple of 90
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002579 // degrees is not an oval anymore, this can be improved. we made this
2580 // for the simplicity of our implementation.
2581 if (angle % 90 == 0) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002582 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002583 } else {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002584 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002585 }
2586 }
2587}
2588
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002589static void test_circle_mirror_x(skiatest::Reporter* reporter,
2590 const SkPath& path,
2591 SkPath::Direction dir) {
2592 SkPath tmp;
2593 SkMatrix m;
2594 m.reset();
2595 m.setScaleX(-SK_Scalar1);
2596 path.transform(m, &tmp);
2597
2598 if (SkPath::kCW_Direction == dir) {
2599 dir = SkPath::kCCW_Direction;
2600 } else {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002601 REPORTER_ASSERT(reporter, SkPath::kCCW_Direction == dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002602 dir = SkPath::kCW_Direction;
2603 }
2604
2605 check_for_circle(reporter, tmp, true, dir);
2606}
2607
2608static void test_circle_mirror_y(skiatest::Reporter* reporter,
2609 const SkPath& path,
2610 SkPath::Direction dir) {
2611 SkPath tmp;
2612 SkMatrix m;
2613 m.reset();
2614 m.setScaleY(-SK_Scalar1);
2615 path.transform(m, &tmp);
2616
2617 if (SkPath::kCW_Direction == dir) {
2618 dir = SkPath::kCCW_Direction;
2619 } else {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002620 REPORTER_ASSERT(reporter, SkPath::kCCW_Direction == dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002621 dir = SkPath::kCW_Direction;
2622 }
2623
2624 check_for_circle(reporter, tmp, true, dir);
2625}
2626
2627static void test_circle_mirror_xy(skiatest::Reporter* reporter,
2628 const SkPath& path,
2629 SkPath::Direction dir) {
2630 SkPath tmp;
2631 SkMatrix m;
2632 m.reset();
2633 m.setScaleX(-SK_Scalar1);
2634 m.setScaleY(-SK_Scalar1);
2635 path.transform(m, &tmp);
2636
2637 check_for_circle(reporter, tmp, true, dir);
2638}
2639
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002640static void test_circle_with_direction(skiatest::Reporter* reporter,
2641 SkPath::Direction dir) {
2642 SkPath path;
2643
2644 // circle at origin
2645 path.addCircle(0, 0, SkIntToScalar(20), dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002646 check_for_circle(reporter, path, true, dir);
2647 test_circle_rotate(reporter, path, dir);
2648 test_circle_translate(reporter, path, dir);
2649 test_circle_skew(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002650
2651 // circle at an offset at (10, 10)
2652 path.reset();
2653 path.addCircle(SkIntToScalar(10), SkIntToScalar(10),
2654 SkIntToScalar(20), dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002655 check_for_circle(reporter, path, true, dir);
2656 test_circle_rotate(reporter, path, dir);
2657 test_circle_translate(reporter, path, dir);
2658 test_circle_skew(reporter, path, dir);
2659 test_circle_mirror_x(reporter, path, dir);
2660 test_circle_mirror_y(reporter, path, dir);
2661 test_circle_mirror_xy(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002662}
2663
2664static void test_circle_with_add_paths(skiatest::Reporter* reporter) {
2665 SkPath path;
2666 SkPath circle;
2667 SkPath rect;
2668 SkPath empty;
2669
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002670 static const SkPath::Direction kCircleDir = SkPath::kCW_Direction;
2671 static const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction;
2672
2673 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002674 rect.addRect(SkIntToScalar(5), SkIntToScalar(5),
2675 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction);
2676
2677 SkMatrix translate;
2678 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12));
2679
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00002680 // Although all the path concatenation related operations leave
2681 // the path a circle, most mark it as a non-circle for simplicity
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002682
2683 // empty + circle (translate)
2684 path = empty;
2685 path.addPath(circle, translate);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002686 check_for_circle(reporter, path, false, kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002687
2688 // circle + empty (translate)
2689 path = circle;
2690 path.addPath(empty, translate);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00002691 check_for_circle(reporter, path, true, kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002692
2693 // test reverseAddPath
2694 path = circle;
2695 path.reverseAddPath(rect);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002696 check_for_circle(reporter, path, false, kCircleDirOpposite);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002697}
2698
2699static void test_circle(skiatest::Reporter* reporter) {
2700 test_circle_with_direction(reporter, SkPath::kCW_Direction);
2701 test_circle_with_direction(reporter, SkPath::kCCW_Direction);
2702
2703 // multiple addCircle()
2704 SkPath path;
2705 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2706 path.addCircle(0, 0, SkIntToScalar(20), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002707 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002708
2709 // some extra lineTo() would make isOval() fail
2710 path.reset();
2711 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2712 path.lineTo(0, 0);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002713 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002714
2715 // not back to the original point
2716 path.reset();
2717 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2718 path.setLastPt(SkIntToScalar(5), SkIntToScalar(5));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002719 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002720
2721 test_circle_with_add_paths(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002722
2723 // test negative radius
2724 path.reset();
2725 path.addCircle(0, 0, -1, SkPath::kCW_Direction);
2726 REPORTER_ASSERT(reporter, path.isEmpty());
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002727}
2728
2729static void test_oval(skiatest::Reporter* reporter) {
2730 SkRect rect;
2731 SkMatrix m;
2732 SkPath path;
2733
2734 rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50));
2735 path.addOval(rect);
2736
2737 REPORTER_ASSERT(reporter, path.isOval(NULL));
2738
2739 m.setRotate(SkIntToScalar(90));
2740 SkPath tmp;
2741 path.transform(m, &tmp);
2742 // an oval rotated 90 degrees is still an oval.
2743 REPORTER_ASSERT(reporter, tmp.isOval(NULL));
2744
2745 m.reset();
2746 m.setRotate(SkIntToScalar(30));
2747 tmp.reset();
2748 path.transform(m, &tmp);
2749 // an oval rotated 30 degrees is not an oval anymore.
2750 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2751
2752 // since empty path being transformed.
2753 path.reset();
2754 tmp.reset();
2755 m.reset();
2756 path.transform(m, &tmp);
2757 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2758
2759 // empty path is not an oval
2760 tmp.reset();
2761 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2762
2763 // only has moveTo()s
2764 tmp.reset();
2765 tmp.moveTo(0, 0);
2766 tmp.moveTo(SkIntToScalar(10), SkIntToScalar(10));
2767 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2768
2769 // mimic WebKit's calling convention,
2770 // call moveTo() first and then call addOval()
2771 path.reset();
2772 path.moveTo(0, 0);
2773 path.addOval(rect);
2774 REPORTER_ASSERT(reporter, path.isOval(NULL));
2775
2776 // copy path
2777 path.reset();
2778 tmp.reset();
2779 tmp.addOval(rect);
2780 path = tmp;
2781 REPORTER_ASSERT(reporter, path.isOval(NULL));
2782}
2783
bungeman@google.coma5809a32013-06-21 15:13:34 +00002784static void test_empty(skiatest::Reporter* reporter, const SkPath& p) {
2785 SkPath empty;
reed@android.com80e39a72009-04-02 16:59:40 +00002786
reed@android.com3abec1d2009-03-02 05:36:20 +00002787 REPORTER_ASSERT(reporter, p.isEmpty());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002788 REPORTER_ASSERT(reporter, 0 == p.countPoints());
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002789 REPORTER_ASSERT(reporter, 0 == p.countVerbs());
reed@google.com10296cc2011-09-21 12:29:05 +00002790 REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks());
reed@google.comb54455e2011-05-16 14:16:04 +00002791 REPORTER_ASSERT(reporter, p.isConvex());
reed@android.com3abec1d2009-03-02 05:36:20 +00002792 REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType);
2793 REPORTER_ASSERT(reporter, !p.isInverseFillType());
bungeman@google.coma5809a32013-06-21 15:13:34 +00002794 REPORTER_ASSERT(reporter, p == empty);
2795 REPORTER_ASSERT(reporter, !(p != empty));
2796}
2797
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002798static void test_rrect_is_convex(skiatest::Reporter* reporter, SkPath* path,
2799 SkPath::Direction dir) {
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00002800 REPORTER_ASSERT(reporter, path->isConvex());
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002801 REPORTER_ASSERT(reporter, path->cheapIsDirection(dir));
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00002802 path->setConvexity(SkPath::kUnknown_Convexity);
2803 REPORTER_ASSERT(reporter, path->isConvex());
2804 path->reset();
2805}
2806
2807static void test_rrect(skiatest::Reporter* reporter) {
2808 SkPath p;
2809 SkRRect rr;
2810 SkVector radii[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
2811 SkRect r = {10, 20, 30, 40};
2812 rr.setRectRadii(r, radii);
2813 p.addRRect(rr);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002814 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00002815 p.addRRect(rr, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002816 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00002817 p.addRoundRect(r, &radii[0].fX);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002818 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00002819 p.addRoundRect(r, &radii[0].fX, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002820 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00002821 p.addRoundRect(r, radii[1].fX, radii[1].fY);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002822 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00002823 p.addRoundRect(r, radii[1].fX, radii[1].fY, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002824 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
2825 for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) {
2826 SkVector save = radii[i];
2827 radii[i].set(0, 0);
2828 rr.setRectRadii(r, radii);
2829 p.addRRect(rr);
2830 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
2831 radii[i] = save;
2832 }
2833 p.addRoundRect(r, 0, 0);
2834 SkRect returnedRect;
2835 REPORTER_ASSERT(reporter, p.isRect(&returnedRect));
2836 REPORTER_ASSERT(reporter, returnedRect == r);
2837 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
2838 SkVector zeroRadii[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
2839 rr.setRectRadii(r, zeroRadii);
2840 p.addRRect(rr);
2841 bool closed;
2842 SkPath::Direction dir;
2843 REPORTER_ASSERT(reporter, p.isRect(&closed, &dir));
2844 REPORTER_ASSERT(reporter, closed);
2845 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
2846 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
2847 p.addRRect(rr, SkPath::kCW_Direction);
2848 p.addRRect(rr, SkPath::kCW_Direction);
2849 REPORTER_ASSERT(reporter, !p.isConvex());
2850 p.reset();
2851 p.addRRect(rr, SkPath::kCCW_Direction);
2852 p.addRRect(rr, SkPath::kCCW_Direction);
2853 REPORTER_ASSERT(reporter, !p.isConvex());
2854 p.reset();
2855 SkRect emptyR = {10, 20, 10, 30};
2856 rr.setRectRadii(emptyR, radii);
2857 p.addRRect(rr);
2858 REPORTER_ASSERT(reporter, p.isEmpty());
2859 SkRect largeR = {0, 0, SK_ScalarMax, SK_ScalarMax};
2860 rr.setRectRadii(largeR, radii);
2861 p.addRRect(rr);
2862 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
2863 SkRect infR = {0, 0, SK_ScalarMax, SK_ScalarInfinity};
2864 rr.setRectRadii(infR, radii);
2865 p.addRRect(rr);
2866 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
2867 SkRect tinyR = {0, 0, 1e-9f, 1e-9f};
2868 p.addRoundRect(tinyR, 5e-11f, 5e-11f);
2869 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00002870}
2871
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002872static void test_arc(skiatest::Reporter* reporter) {
2873 SkPath p;
2874 SkRect emptyOval = {10, 20, 30, 20};
2875 REPORTER_ASSERT(reporter, emptyOval.isEmpty());
2876 p.addArc(emptyOval, 1, 2);
2877 REPORTER_ASSERT(reporter, p.isEmpty());
2878 p.reset();
2879 SkRect oval = {10, 20, 30, 40};
2880 p.addArc(oval, 1, 0);
2881 REPORTER_ASSERT(reporter, p.isEmpty());
2882 p.reset();
2883 SkPath cwOval;
2884 cwOval.addOval(oval);
2885 p.addArc(oval, 1, 360);
2886 REPORTER_ASSERT(reporter, p == cwOval);
2887 p.reset();
2888 SkPath ccwOval;
2889 ccwOval.addOval(oval, SkPath::kCCW_Direction);
2890 p.addArc(oval, 1, -360);
2891 REPORTER_ASSERT(reporter, p == ccwOval);
2892 p.reset();
2893 p.addArc(oval, 1, 180);
2894 REPORTER_ASSERT(reporter, p.isConvex());
2895 REPORTER_ASSERT(reporter, p.cheapIsDirection(SkPath::kCW_Direction));
2896 p.setConvexity(SkPath::kUnknown_Convexity);
2897 REPORTER_ASSERT(reporter, p.isConvex());
2898}
2899
2900static void check_move(skiatest::Reporter* reporter, SkPath::RawIter* iter,
2901 SkScalar x0, SkScalar y0) {
2902 SkPoint pts[4];
2903 SkPath::Verb v = iter->next(pts);
2904 REPORTER_ASSERT(reporter, v == SkPath::kMove_Verb);
2905 REPORTER_ASSERT(reporter, pts[0].fX == x0);
2906 REPORTER_ASSERT(reporter, pts[0].fY == y0);
2907}
2908
2909static void check_line(skiatest::Reporter* reporter, SkPath::RawIter* iter,
2910 SkScalar x1, SkScalar y1) {
2911 SkPoint pts[4];
2912 SkPath::Verb v = iter->next(pts);
2913 REPORTER_ASSERT(reporter, v == SkPath::kLine_Verb);
2914 REPORTER_ASSERT(reporter, pts[1].fX == x1);
2915 REPORTER_ASSERT(reporter, pts[1].fY == y1);
2916}
2917
2918static void check_quad(skiatest::Reporter* reporter, SkPath::RawIter* iter,
2919 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
2920 SkPoint pts[4];
2921 SkPath::Verb v = iter->next(pts);
2922 REPORTER_ASSERT(reporter, v == SkPath::kQuad_Verb);
2923 REPORTER_ASSERT(reporter, pts[1].fX == x1);
2924 REPORTER_ASSERT(reporter, pts[1].fY == y1);
2925 REPORTER_ASSERT(reporter, pts[2].fX == x2);
2926 REPORTER_ASSERT(reporter, pts[2].fY == y2);
2927}
2928
2929static void check_done(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
2930 SkPoint pts[4];
2931 SkPath::Verb v = iter->next(pts);
2932 REPORTER_ASSERT(reporter, v == SkPath::kDone_Verb);
2933}
2934
2935static void check_done_and_reset(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
2936 check_done(reporter, p, iter);
2937 p->reset();
2938}
2939
2940static void check_path_is_move_and_reset(skiatest::Reporter* reporter, SkPath* p,
2941 SkScalar x0, SkScalar y0) {
2942 SkPath::RawIter iter(*p);
2943 check_move(reporter, &iter, x0, y0);
2944 check_done_and_reset(reporter, p, &iter);
2945}
2946
2947static void check_path_is_line_and_reset(skiatest::Reporter* reporter, SkPath* p,
2948 SkScalar x1, SkScalar y1) {
2949 SkPath::RawIter iter(*p);
2950 check_move(reporter, &iter, 0, 0);
2951 check_line(reporter, &iter, x1, y1);
2952 check_done_and_reset(reporter, p, &iter);
2953}
2954
2955static void check_path_is_line(skiatest::Reporter* reporter, SkPath* p,
2956 SkScalar x1, SkScalar y1) {
2957 SkPath::RawIter iter(*p);
2958 check_move(reporter, &iter, 0, 0);
2959 check_line(reporter, &iter, x1, y1);
2960 check_done(reporter, p, &iter);
2961}
2962
2963static void check_path_is_line_pair_and_reset(skiatest::Reporter* reporter, SkPath* p,
2964 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
2965 SkPath::RawIter iter(*p);
2966 check_move(reporter, &iter, 0, 0);
2967 check_line(reporter, &iter, x1, y1);
2968 check_line(reporter, &iter, x2, y2);
2969 check_done_and_reset(reporter, p, &iter);
2970}
2971
2972static void check_path_is_quad_and_reset(skiatest::Reporter* reporter, SkPath* p,
2973 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
2974 SkPath::RawIter iter(*p);
2975 check_move(reporter, &iter, 0, 0);
2976 check_quad(reporter, &iter, x1, y1, x2, y2);
2977 check_done_and_reset(reporter, p, &iter);
2978}
2979
2980static void test_arcTo(skiatest::Reporter* reporter) {
2981 SkPath p;
2982 p.arcTo(0, 0, 1, 2, 1);
2983 check_path_is_line_and_reset(reporter, &p, 0, 0);
2984 p.arcTo(1, 2, 1, 2, 1);
2985 check_path_is_line_and_reset(reporter, &p, 1, 2);
2986 p.arcTo(1, 2, 3, 4, 0);
2987 check_path_is_line_and_reset(reporter, &p, 1, 2);
2988 p.arcTo(1, 2, 0, 0, 1);
2989 check_path_is_line_and_reset(reporter, &p, 1, 2);
2990 p.arcTo(1, 0, 1, 1, 1);
2991 SkPoint pt;
2992 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == 1);
2993 p.reset();
2994 p.arcTo(1, 0, 1, -1, 1);
2995 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == -1);
2996 p.reset();
2997 SkRect oval = {1, 2, 3, 4};
2998 p.arcTo(oval, 0, 0, true);
2999 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3000 p.arcTo(oval, 0, 0, false);
3001 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3002 p.arcTo(oval, 360, 0, true);
3003 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3004 p.arcTo(oval, 360, 0, false);
3005 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3006 for (float sweep = 359, delta = 0.5f; sweep != (float) (sweep + delta); ) {
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00003007 p.arcTo(oval, 0, sweep, false);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003008 REPORTER_ASSERT(reporter, p.getBounds() == oval);
3009 sweep += delta;
3010 delta /= 2;
3011 }
3012 for (float sweep = 361, delta = 0.5f; sweep != (float) (sweep - delta);) {
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00003013 p.arcTo(oval, 0, sweep, false);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003014 REPORTER_ASSERT(reporter, p.getBounds() == oval);
3015 sweep -= delta;
3016 delta /= 2;
3017 }
3018 SkRect noOvalWidth = {1, 2, 0, 3};
3019 p.reset();
3020 p.arcTo(noOvalWidth, 0, 360, false);
3021 REPORTER_ASSERT(reporter, p.isEmpty());
3022
3023 SkRect noOvalHeight = {1, 2, 3, 1};
3024 p.reset();
3025 p.arcTo(noOvalHeight, 0, 360, false);
3026 REPORTER_ASSERT(reporter, p.isEmpty());
3027}
3028
3029static void test_addPath(skiatest::Reporter* reporter) {
3030 SkPath p, q;
3031 p.lineTo(1, 2);
3032 q.moveTo(4, 4);
3033 q.lineTo(7, 8);
3034 q.conicTo(8, 7, 6, 5, 0.5f);
3035 q.quadTo(6, 7, 8, 6);
3036 q.cubicTo(5, 6, 7, 8, 7, 5);
3037 q.close();
3038 p.addPath(q, -4, -4);
3039 SkRect expected = {0, 0, 4, 4};
3040 REPORTER_ASSERT(reporter, p.getBounds() == expected);
3041 p.reset();
3042 p.reverseAddPath(q);
3043 SkRect reverseExpected = {4, 4, 8, 8};
3044 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
3045}
3046
3047static void test_conicTo_special_case(skiatest::Reporter* reporter) {
3048 SkPath p;
3049 p.conicTo(1, 2, 3, 4, -1);
3050 check_path_is_line_and_reset(reporter, &p, 3, 4);
3051 p.conicTo(1, 2, 3, 4, SK_ScalarInfinity);
3052 check_path_is_line_pair_and_reset(reporter, &p, 1, 2, 3, 4);
3053 p.conicTo(1, 2, 3, 4, 1);
3054 check_path_is_quad_and_reset(reporter, &p, 1, 2, 3, 4);
3055}
3056
3057static void test_get_point(skiatest::Reporter* reporter) {
3058 SkPath p;
3059 SkPoint pt = p.getPoint(0);
3060 REPORTER_ASSERT(reporter, pt == SkPoint::Make(0, 0));
3061 REPORTER_ASSERT(reporter, !p.getLastPt(NULL));
3062 REPORTER_ASSERT(reporter, !p.getLastPt(&pt) && pt == SkPoint::Make(0, 0));
3063 p.setLastPt(10, 10);
3064 pt = p.getPoint(0);
3065 REPORTER_ASSERT(reporter, pt == SkPoint::Make(10, 10));
3066 REPORTER_ASSERT(reporter, p.getLastPt(NULL));
3067 p.rMoveTo(10, 10);
3068 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt == SkPoint::Make(20, 20));
3069}
3070
3071static void test_contains(skiatest::Reporter* reporter) {
3072 SkPath p;
3073 p.setFillType(SkPath::kInverseWinding_FillType);
3074 REPORTER_ASSERT(reporter, p.contains(0, 0));
3075 p.setFillType(SkPath::kWinding_FillType);
3076 REPORTER_ASSERT(reporter, !p.contains(0, 0));
3077 p.moveTo(4, 4);
3078 p.lineTo(6, 8);
3079 p.lineTo(8, 4);
3080 // test quick reject
3081 REPORTER_ASSERT(reporter, !p.contains(4, 0));
3082 REPORTER_ASSERT(reporter, !p.contains(0, 4));
3083 REPORTER_ASSERT(reporter, !p.contains(4, 10));
3084 REPORTER_ASSERT(reporter, !p.contains(10, 4));
3085 // test various crossings in x
3086 REPORTER_ASSERT(reporter, !p.contains(5, 7));
3087 REPORTER_ASSERT(reporter, p.contains(6, 7));
3088 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3089 p.reset();
3090 p.moveTo(4, 4);
3091 p.lineTo(8, 6);
3092 p.lineTo(4, 8);
3093 // test various crossings in y
3094 REPORTER_ASSERT(reporter, !p.contains(7, 5));
3095 REPORTER_ASSERT(reporter, p.contains(7, 6));
3096 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3097 // test quads
3098 p.reset();
3099 p.moveTo(4, 4);
3100 p.quadTo(6, 6, 8, 8);
3101 p.quadTo(6, 8, 4, 8);
3102 p.quadTo(4, 6, 4, 4);
3103 REPORTER_ASSERT(reporter, p.contains(5, 6));
3104 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3105
3106 p.reset();
3107 p.moveTo(6, 6);
3108 p.quadTo(8, 8, 6, 8);
3109 p.quadTo(4, 8, 4, 6);
3110 p.quadTo(4, 4, 6, 6);
3111 REPORTER_ASSERT(reporter, p.contains(5, 6));
3112 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3113
3114#define CONIC_CONTAINS_BUG_FIXED 0
3115#if CONIC_CONTAINS_BUG_FIXED
3116 p.reset();
3117 p.moveTo(4, 4);
3118 p.conicTo(6, 6, 8, 8, 0.5f);
3119 p.conicTo(6, 8, 4, 8, 0.5f);
3120 p.conicTo(4, 6, 4, 4, 0.5f);
3121 REPORTER_ASSERT(reporter, p.contains(5, 6));
3122 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3123#endif
3124
3125 // test cubics
3126 SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5, 4}, {6, 5}, {7, 6}};
3127 for (int i = 0; i < 3; ++i) {
3128 p.reset();
3129 p.setFillType(SkPath::kEvenOdd_FillType);
3130 p.moveTo(pts[i].fX, pts[i].fY);
3131 p.cubicTo(pts[i + 1].fX, pts[i + 1].fY, pts[i + 2].fX, pts[i + 2].fY, pts[i + 3].fX, pts[i + 3].fY);
3132 p.cubicTo(pts[i + 4].fX, pts[i + 4].fY, pts[i + 5].fX, pts[i + 5].fY, pts[i + 6].fX, pts[i + 6].fY);
3133 p.close();
3134 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f));
3135 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f));
3136 }
3137}
3138
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003139class PathRefTest_Private {
3140public:
3141 static void TestPathRef(skiatest::Reporter* reporter) {
3142 static const int kRepeatCnt = 10;
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003143
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003144 SkAutoTUnref<SkPathRef> pathRef(SkNEW(SkPathRef));
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003145
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003146 SkPathRef::Editor ed(&pathRef);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003147
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003148 {
3149 ed.growForRepeatedVerb(SkPath::kMove_Verb, kRepeatCnt);
3150 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3151 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
3152 REPORTER_ASSERT(reporter, 0 == pathRef->getSegmentMasks());
3153 for (int i = 0; i < kRepeatCnt; ++i) {
3154 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == pathRef->atVerb(i));
3155 }
3156 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003157 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003158
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003159 {
3160 ed.growForRepeatedVerb(SkPath::kLine_Verb, kRepeatCnt);
3161 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3162 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
3163 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == pathRef->getSegmentMasks());
3164 for (int i = 0; i < kRepeatCnt; ++i) {
3165 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == pathRef->atVerb(i));
3166 }
3167 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003168 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003169
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003170 {
3171 ed.growForRepeatedVerb(SkPath::kQuad_Verb, kRepeatCnt);
3172 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3173 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
3174 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == pathRef->getSegmentMasks());
3175 for (int i = 0; i < kRepeatCnt; ++i) {
3176 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == pathRef->atVerb(i));
3177 }
3178 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003179 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003180
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003181 {
3182 SkScalar* weights = NULL;
3183 ed.growForRepeatedVerb(SkPath::kConic_Verb, kRepeatCnt, &weights);
3184 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3185 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
3186 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countWeights());
3187 REPORTER_ASSERT(reporter, SkPath::kConic_SegmentMask == pathRef->getSegmentMasks());
3188 REPORTER_ASSERT(reporter, NULL != weights);
3189 for (int i = 0; i < kRepeatCnt; ++i) {
3190 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == pathRef->atVerb(i));
3191 }
3192 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003193 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003194
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003195 {
3196 ed.growForRepeatedVerb(SkPath::kCubic_Verb, kRepeatCnt);
3197 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3198 REPORTER_ASSERT(reporter, 3*kRepeatCnt == pathRef->countPoints());
3199 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == pathRef->getSegmentMasks());
3200 for (int i = 0; i < kRepeatCnt; ++i) {
3201 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == pathRef->atVerb(i));
3202 }
3203 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003204 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003205 }
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003206};
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003207
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003208static void test_operatorEqual(skiatest::Reporter* reporter) {
3209 SkPath a;
3210 SkPath b;
3211 REPORTER_ASSERT(reporter, a == a);
3212 REPORTER_ASSERT(reporter, a == b);
3213 a.setFillType(SkPath::kInverseWinding_FillType);
3214 REPORTER_ASSERT(reporter, a != b);
3215 a.reset();
3216 REPORTER_ASSERT(reporter, a == b);
3217 a.lineTo(1, 1);
3218 REPORTER_ASSERT(reporter, a != b);
3219 a.reset();
3220 REPORTER_ASSERT(reporter, a == b);
3221 a.lineTo(1, 1);
3222 b.lineTo(1, 2);
3223 REPORTER_ASSERT(reporter, a != b);
3224 a.reset();
3225 a.lineTo(1, 2);
3226 REPORTER_ASSERT(reporter, a == b);
3227}
3228
3229class PathTest_Private {
3230public:
3231 static void TestPathTo(skiatest::Reporter* reporter) {
3232 SkPath p, q;
3233 p.lineTo(4, 4);
3234 p.reversePathTo(q);
3235 check_path_is_line(reporter, &p, 4, 4);
3236 q.moveTo(-4, -4);
3237 p.reversePathTo(q);
3238 check_path_is_line(reporter, &p, 4, 4);
3239 q.lineTo(7, 8);
3240 q.conicTo(8, 7, 6, 5, 0.5f);
3241 q.quadTo(6, 7, 8, 6);
3242 q.cubicTo(5, 6, 7, 8, 7, 5);
3243 q.close();
3244 p.reversePathTo(q);
3245 SkRect reverseExpected = {-4, -4, 8, 8};
3246 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
3247 }
3248};
3249
tfarina@chromium.orge4fafb12013-12-12 21:11:12 +00003250DEF_TEST(Path, reporter) {
bungeman@google.coma5809a32013-06-21 15:13:34 +00003251 SkTSize<SkScalar>::Make(3,4);
3252
3253 SkPath p, empty;
3254 SkRect bounds, bounds2;
3255 test_empty(reporter, p);
reed@android.com3abec1d2009-03-02 05:36:20 +00003256
reed@android.comd252db02009-04-01 18:31:44 +00003257 REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
reed@android.com80e39a72009-04-02 16:59:40 +00003258
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003259 // this triggers a code path in SkPath::operator= which is otherwise unexercised
3260 SkPath& self = p;
3261 p = self;
3262
3263 // this triggers a code path in SkPath::swap which is otherwise unexercised
3264 p.swap(self);
3265
reed@android.com3abec1d2009-03-02 05:36:20 +00003266 bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
reed@android.com6b82d1a2009-06-03 02:35:01 +00003267
reed@android.com6b82d1a2009-06-03 02:35:01 +00003268 p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1);
3269 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00003270 // we have quads or cubics
3271 REPORTER_ASSERT(reporter, p.getSegmentMasks() & kCurveSegmentMask);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003272 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00003273
reed@android.com6b82d1a2009-06-03 02:35:01 +00003274 p.reset();
bungeman@google.coma5809a32013-06-21 15:13:34 +00003275 test_empty(reporter, p);
reed@google.com10296cc2011-09-21 12:29:05 +00003276
reed@android.com6b82d1a2009-06-03 02:35:01 +00003277 p.addOval(bounds);
3278 check_convex_bounds(reporter, p, bounds);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003279 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00003280
bungeman@google.coma5809a32013-06-21 15:13:34 +00003281 p.rewind();
3282 test_empty(reporter, p);
3283
reed@android.com3abec1d2009-03-02 05:36:20 +00003284 p.addRect(bounds);
reed@android.com6b82d1a2009-06-03 02:35:01 +00003285 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00003286 // we have only lines
3287 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == p.getSegmentMasks());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003288 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@android.com3abec1d2009-03-02 05:36:20 +00003289
bungeman@google.coma5809a32013-06-21 15:13:34 +00003290 REPORTER_ASSERT(reporter, p != empty);
3291 REPORTER_ASSERT(reporter, !(p == empty));
reed@android.com3abec1d2009-03-02 05:36:20 +00003292
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00003293 // do getPoints and getVerbs return the right result
3294 REPORTER_ASSERT(reporter, p.getPoints(NULL, 0) == 4);
3295 REPORTER_ASSERT(reporter, p.getVerbs(NULL, 0) == 5);
reed@android.com3abec1d2009-03-02 05:36:20 +00003296 SkPoint pts[4];
3297 int count = p.getPoints(pts, 4);
3298 REPORTER_ASSERT(reporter, count == 4);
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00003299 uint8_t verbs[6];
3300 verbs[5] = 0xff;
3301 p.getVerbs(verbs, 5);
3302 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == verbs[0]);
3303 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[1]);
3304 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[2]);
3305 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[3]);
3306 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == verbs[4]);
3307 REPORTER_ASSERT(reporter, 0xff == verbs[5]);
reed@android.com3abec1d2009-03-02 05:36:20 +00003308 bounds2.set(pts, 4);
3309 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00003310
reed@android.com3abec1d2009-03-02 05:36:20 +00003311 bounds.offset(SK_Scalar1*3, SK_Scalar1*4);
3312 p.offset(SK_Scalar1*3, SK_Scalar1*4);
reed@android.comd252db02009-04-01 18:31:44 +00003313 REPORTER_ASSERT(reporter, bounds == p.getBounds());
reed@android.com3abec1d2009-03-02 05:36:20 +00003314
reed@android.com3abec1d2009-03-02 05:36:20 +00003315 REPORTER_ASSERT(reporter, p.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00003316 bounds2.setEmpty();
reed@android.com3abec1d2009-03-02 05:36:20 +00003317 REPORTER_ASSERT(reporter, p.isRect(&bounds2));
3318 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00003319
reed@android.com3abec1d2009-03-02 05:36:20 +00003320 // now force p to not be a rect
3321 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2);
3322 p.addRect(bounds);
3323 REPORTER_ASSERT(reporter, !p.isRect(NULL));
reed@android.com3abec1d2009-03-02 05:36:20 +00003324
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003325 test_operatorEqual(reporter);
reed@google.com7e6c4d12012-05-10 14:05:43 +00003326 test_isLine(reporter);
3327 test_isRect(reporter);
caryclark@google.com56f233a2012-11-19 13:06:06 +00003328 test_isNestedRects(reporter);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003329 test_zero_length_paths(reporter);
reed@google.comcabaf1d2012-01-11 21:03:05 +00003330 test_direction(reporter);
reed@google.com04863fa2011-05-15 04:08:24 +00003331 test_convexity(reporter);
reed@google.com7c424812011-05-15 04:38:34 +00003332 test_convexity2(reporter);
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00003333 test_conservativelyContains(reporter);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00003334 test_close(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00003335 test_segment_masks(reporter);
reed@google.com53effc52011-09-21 19:05:12 +00003336 test_flattening(reporter);
3337 test_transform(reporter);
reed@google.com3563c9e2011-11-14 19:34:57 +00003338 test_bounds(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00003339 test_iter(reporter);
3340 test_raw_iter(reporter);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003341 test_circle(reporter);
3342 test_oval(reporter);
reed@google.com8b06f1a2012-05-29 12:03:46 +00003343 test_strokerec(reporter);
reed@google.com744faba2012-05-29 19:54:52 +00003344 test_addPoly(reporter);
reed@google.com0bb18bb2012-07-26 15:20:36 +00003345 test_isfinite(reporter);
tomhudson@google.comed02c4d2012-08-10 14:10:45 +00003346 test_isfinite_after_transform(reporter);
robertphillips@google.comb95eaa82012-10-18 15:26:12 +00003347 test_arb_round_rect_is_convex(reporter);
robertphillips@google.com158618e2012-10-23 16:56:56 +00003348 test_arb_zero_rad_round_rect_is_rect(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003349 test_addrect(reporter);
reed@google.coma8790de2012-10-24 21:04:04 +00003350 test_addrect_isfinite(reporter);
sugoi@google.com54f0d1b2013-02-27 19:17:41 +00003351 test_tricky_cubic();
3352 test_clipped_cubic();
3353 test_crbug_170666();
reed@google.com7a90daf2013-04-10 18:44:00 +00003354 test_bad_cubic_crbug229478();
reed@google.com3eff3592013-05-08 21:08:21 +00003355 test_bad_cubic_crbug234190();
mtklein@google.com9c9d4a72013-08-07 19:17:53 +00003356 test_android_specific_behavior(reporter);
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +00003357 test_gen_id(reporter);
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +00003358 test_path_close_issue1474(reporter);
reed@google.comb58ba892013-10-15 15:44:35 +00003359 test_path_to_region(reporter);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003360 test_rrect(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003361 test_arc(reporter);
3362 test_arcTo(reporter);
3363 test_addPath(reporter);
3364 test_conicTo_special_case(reporter);
3365 test_get_point(reporter);
3366 test_contains(reporter);
3367 PathTest_Private::TestPathTo(reporter);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003368 PathRefTest_Private::TestPathRef(reporter);
reed@android.com3abec1d2009-03-02 05:36:20 +00003369}