blob: cd54a60054050cb0f73242b7c34f5ede50f28519 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001
2/*
3 * Copyright 2011 Google Inc.
4 *
5 * Use of this source code is governed by a BSD-style license that can be
6 * found in the LICENSE file.
7 */
reed@android.com3abec1d2009-03-02 05:36:20 +00008#include "Test.h"
reed@google.com8cae8352012-09-14 15:18:41 +00009#include "SkCanvas.h"
reed@google.com55b5f4b2011-09-07 12:23:41 +000010#include "SkPaint.h"
reed@android.com3abec1d2009-03-02 05:36:20 +000011#include "SkPath.h"
reed@google.com04863fa2011-05-15 04:08:24 +000012#include "SkParse.h"
reed@google.com3e71a882012-01-10 18:44:37 +000013#include "SkParsePath.h"
reed@google.com8b06f1a2012-05-29 12:03:46 +000014#include "SkPathEffect.h"
schenney@chromium.org6630d8d2012-01-04 21:05:51 +000015#include "SkRandom.h"
reed@google.com53effc52011-09-21 19:05:12 +000016#include "SkReader32.h"
reed@android.com60bc6d52010-02-11 11:09:39 +000017#include "SkSize.h"
reed@google.com8cae8352012-09-14 15:18:41 +000018#include "SkSurface.h"
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000019#include "SkTypes.h"
20#include "SkWriter32.h"
reed@google.com8cae8352012-09-14 15:18:41 +000021
caryclark@google.com56f233a2012-11-19 13:06:06 +000022#if defined(WIN32)
23 #define SUPPRESS_VISIBILITY_WARNING
24#else
25 #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
26#endif
27
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +000028static void test_path_close_issue1474(skiatest::Reporter* reporter) {
29 // This test checks that r{Line,Quad,Conic,Cubic}To following a close()
30 // are relative to the point we close to, not relative to the point we close from.
31 SkPath path;
32 SkPoint last;
33
34 // Test rLineTo().
35 path.rLineTo(0, 100);
36 path.rLineTo(100, 0);
37 path.close(); // Returns us back to 0,0.
38 path.rLineTo(50, 50); // This should go to 50,50.
39
40 path.getLastPt(&last);
41 REPORTER_ASSERT(reporter, 50 == last.fX);
42 REPORTER_ASSERT(reporter, 50 == last.fY);
43
44 // Test rQuadTo().
45 path.rewind();
46 path.rLineTo(0, 100);
47 path.rLineTo(100, 0);
48 path.close();
49 path.rQuadTo(50, 50, 75, 75);
50
51 path.getLastPt(&last);
52 REPORTER_ASSERT(reporter, 75 == last.fX);
53 REPORTER_ASSERT(reporter, 75 == last.fY);
54
55 // Test rConicTo().
56 path.rewind();
57 path.rLineTo(0, 100);
58 path.rLineTo(100, 0);
59 path.close();
60 path.rConicTo(50, 50, 85, 85, 2);
61
62 path.getLastPt(&last);
63 REPORTER_ASSERT(reporter, 85 == last.fX);
64 REPORTER_ASSERT(reporter, 85 == last.fY);
65
66 // Test rCubicTo().
67 path.rewind();
68 path.rLineTo(0, 100);
69 path.rLineTo(100, 0);
70 path.close();
71 path.rCubicTo(50, 50, 85, 85, 95, 95);
72
73 path.getLastPt(&last);
74 REPORTER_ASSERT(reporter, 95 == last.fX);
75 REPORTER_ASSERT(reporter, 95 == last.fY);
76}
77
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000078static void test_android_specific_behavior(skiatest::Reporter* reporter) {
79#ifdef SK_BUILD_FOR_ANDROID
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +000080 // Make sure we treat fGenerationID and fSourcePath correctly for each of
81 // copy, assign, rewind, reset, and swap.
82 SkPath original, source, anotherSource;
83 original.setSourcePath(&source);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000084 original.moveTo(0, 0);
85 original.lineTo(1, 1);
86 REPORTER_ASSERT(reporter, original.getGenerationID() > 0);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +000087 REPORTER_ASSERT(reporter, original.getSourcePath() == &source);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000088
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +000089 uint32_t copyID, assignID;
90
91 // Test copy constructor. Copy generation ID, copy source path.
92 SkPath copy(original);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000093 REPORTER_ASSERT(reporter, copy.getGenerationID() == original.getGenerationID());
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +000094 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath());
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000095
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +000096 // Test assigment operator. Increment generation ID, copy source path.
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000097 SkPath assign;
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +000098 assignID = assign.getGenerationID();
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000099 assign = original;
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000100 REPORTER_ASSERT(reporter, assign.getGenerationID() > assignID);
101 REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath());
102
103 // Test rewind. Increment generation ID, don't touch source path.
104 copyID = copy.getGenerationID();
105 copy.rewind();
106 REPORTER_ASSERT(reporter, copy.getGenerationID() > copyID);
107 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath());
108
109 // Test reset. Increment generation ID, don't touch source path.
110 assignID = assign.getGenerationID();
111 assign.reset();
112 REPORTER_ASSERT(reporter, assign.getGenerationID() > assignID);
113 REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath());
114
115 // Test swap. Increment both generation IDs, swap source paths.
116 copy.setSourcePath(&anotherSource);
117 copyID = copy.getGenerationID();
118 assignID = assign.getGenerationID();
119 copy.swap(assign);
120 REPORTER_ASSERT(reporter, copy.getGenerationID() > copyID);
121 REPORTER_ASSERT(reporter, assign.getGenerationID() > assignID);
122 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath());
123 REPORTER_ASSERT(reporter, assign.getSourcePath() == &anotherSource);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000124#endif
125}
126
reed@google.com3eff3592013-05-08 21:08:21 +0000127// This used to assert in the debug build, as the edges did not all line-up.
128static void test_bad_cubic_crbug234190() {
129 SkPath path;
130 path.moveTo(13.8509f, 3.16858f);
131 path.cubicTo(-2.35893e+08f, -4.21044e+08f,
132 -2.38991e+08f, -4.26573e+08f,
133 -2.41016e+08f, -4.30188e+08f);
134
135 SkPaint paint;
136 paint.setAntiAlias(true);
reed@google.comd28ba802013-09-20 19:33:52 +0000137 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(84, 88));
reed@google.com3eff3592013-05-08 21:08:21 +0000138 surface->getCanvas()->drawPath(path, paint);
139}
140
reed@google.com7a90daf2013-04-10 18:44:00 +0000141static void test_bad_cubic_crbug229478() {
142 const SkPoint pts[] = {
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000143 { 4595.91064f, -11596.9873f },
144 { 4597.2168f, -11595.9414f },
145 { 4598.52344f, -11594.8955f },
146 { 4599.83008f, -11593.8496f },
reed@google.com7a90daf2013-04-10 18:44:00 +0000147 };
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000148
reed@google.com7a90daf2013-04-10 18:44:00 +0000149 SkPath path;
150 path.moveTo(pts[0]);
151 path.cubicTo(pts[1], pts[2], pts[3]);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000152
reed@google.com7a90daf2013-04-10 18:44:00 +0000153 SkPaint paint;
154 paint.setStyle(SkPaint::kStroke_Style);
155 paint.setStrokeWidth(20);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000156
reed@google.com7a90daf2013-04-10 18:44:00 +0000157 SkPath dst;
158 // Before the fix, this would infinite-recurse, and run out of stack
159 // because we would keep trying to subdivide a degenerate cubic segment.
160 paint.getFillPath(path, &dst, NULL);
161}
162
reed@google.com64d62952013-01-18 17:49:28 +0000163static void build_path_170666(SkPath& path) {
164 path.moveTo(17.9459f, 21.6344f);
165 path.lineTo(139.545f, -47.8105f);
166 path.lineTo(139.545f, -47.8105f);
167 path.lineTo(131.07f, -47.3888f);
168 path.lineTo(131.07f, -47.3888f);
169 path.lineTo(122.586f, -46.9532f);
170 path.lineTo(122.586f, -46.9532f);
171 path.lineTo(18076.6f, 31390.9f);
172 path.lineTo(18076.6f, 31390.9f);
173 path.lineTo(18085.1f, 31390.5f);
174 path.lineTo(18085.1f, 31390.5f);
175 path.lineTo(18076.6f, 31390.9f);
176 path.lineTo(18076.6f, 31390.9f);
177 path.lineTo(17955, 31460.3f);
178 path.lineTo(17955, 31460.3f);
179 path.lineTo(17963.5f, 31459.9f);
180 path.lineTo(17963.5f, 31459.9f);
181 path.lineTo(17971.9f, 31459.5f);
182 path.lineTo(17971.9f, 31459.5f);
183 path.lineTo(17.9551f, 21.6205f);
184 path.lineTo(17.9551f, 21.6205f);
185 path.lineTo(9.47091f, 22.0561f);
186 path.lineTo(9.47091f, 22.0561f);
187 path.lineTo(17.9459f, 21.6344f);
188 path.lineTo(17.9459f, 21.6344f);
189 path.close();path.moveTo(0.995934f, 22.4779f);
190 path.lineTo(0.986725f, 22.4918f);
191 path.lineTo(0.986725f, 22.4918f);
192 path.lineTo(17955, 31460.4f);
193 path.lineTo(17955, 31460.4f);
194 path.lineTo(17971.9f, 31459.5f);
195 path.lineTo(17971.9f, 31459.5f);
196 path.lineTo(18093.6f, 31390.1f);
197 path.lineTo(18093.6f, 31390.1f);
198 path.lineTo(18093.6f, 31390);
199 path.lineTo(18093.6f, 31390);
200 path.lineTo(139.555f, -47.8244f);
201 path.lineTo(139.555f, -47.8244f);
202 path.lineTo(122.595f, -46.9671f);
203 path.lineTo(122.595f, -46.9671f);
204 path.lineTo(0.995934f, 22.4779f);
205 path.lineTo(0.995934f, 22.4779f);
206 path.close();
207 path.moveTo(5.43941f, 25.5223f);
208 path.lineTo(798267, -28871.1f);
209 path.lineTo(798267, -28871.1f);
210 path.lineTo(3.12512e+06f, -113102);
211 path.lineTo(3.12512e+06f, -113102);
212 path.cubicTo(5.16324e+06f, -186882, 8.15247e+06f, -295092, 1.1957e+07f, -432813);
213 path.cubicTo(1.95659e+07f, -708257, 3.04359e+07f, -1.10175e+06f, 4.34798e+07f, -1.57394e+06f);
214 path.cubicTo(6.95677e+07f, -2.51831e+06f, 1.04352e+08f, -3.77748e+06f, 1.39135e+08f, -5.03666e+06f);
215 path.cubicTo(1.73919e+08f, -6.29583e+06f, 2.08703e+08f, -7.555e+06f, 2.34791e+08f, -8.49938e+06f);
216 path.cubicTo(2.47835e+08f, -8.97157e+06f, 2.58705e+08f, -9.36506e+06f, 2.66314e+08f, -9.6405e+06f);
217 path.cubicTo(2.70118e+08f, -9.77823e+06f, 2.73108e+08f, -9.88644e+06f, 2.75146e+08f, -9.96022e+06f);
218 path.cubicTo(2.76165e+08f, -9.99711e+06f, 2.76946e+08f, -1.00254e+07f, 2.77473e+08f, -1.00444e+07f);
219 path.lineTo(2.78271e+08f, -1.00733e+07f);
220 path.lineTo(2.78271e+08f, -1.00733e+07f);
221 path.cubicTo(2.78271e+08f, -1.00733e+07f, 2.08703e+08f, -7.555e+06f, 135.238f, 23.3517f);
222 path.cubicTo(131.191f, 23.4981f, 125.995f, 23.7976f, 123.631f, 24.0206f);
223 path.cubicTo(121.267f, 24.2436f, 122.631f, 24.3056f, 126.677f, 24.1591f);
224 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
225 path.lineTo(2.77473e+08f, -1.00444e+07f);
226 path.lineTo(2.77473e+08f, -1.00444e+07f);
227 path.cubicTo(2.76946e+08f, -1.00254e+07f, 2.76165e+08f, -9.99711e+06f, 2.75146e+08f, -9.96022e+06f);
228 path.cubicTo(2.73108e+08f, -9.88644e+06f, 2.70118e+08f, -9.77823e+06f, 2.66314e+08f, -9.6405e+06f);
229 path.cubicTo(2.58705e+08f, -9.36506e+06f, 2.47835e+08f, -8.97157e+06f, 2.34791e+08f, -8.49938e+06f);
230 path.cubicTo(2.08703e+08f, -7.555e+06f, 1.73919e+08f, -6.29583e+06f, 1.39135e+08f, -5.03666e+06f);
231 path.cubicTo(1.04352e+08f, -3.77749e+06f, 6.95677e+07f, -2.51831e+06f, 4.34798e+07f, -1.57394e+06f);
232 path.cubicTo(3.04359e+07f, -1.10175e+06f, 1.95659e+07f, -708258, 1.1957e+07f, -432814);
233 path.cubicTo(8.15248e+06f, -295092, 5.16324e+06f, -186883, 3.12513e+06f, -113103);
234 path.lineTo(798284, -28872);
235 path.lineTo(798284, -28872);
236 path.lineTo(22.4044f, 24.6677f);
237 path.lineTo(22.4044f, 24.6677f);
238 path.cubicTo(22.5186f, 24.5432f, 18.8134f, 24.6337f, 14.1287f, 24.8697f);
239 path.cubicTo(9.4439f, 25.1057f, 5.55359f, 25.3978f, 5.43941f, 25.5223f);
240 path.close();
241}
242
243static void build_path_simple_170666(SkPath& path) {
244 path.moveTo(126.677f, 24.1591f);
245 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
246}
247
248// This used to assert in the SK_DEBUG build, as the clip step would fail with
249// too-few interations in our cubic-line intersection code. That code now runs
250// 24 interations (instead of 16).
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000251static void test_crbug_170666() {
reed@google.com64d62952013-01-18 17:49:28 +0000252 SkPath path;
253 SkPaint paint;
254 paint.setAntiAlias(true);
255
reed@google.comd28ba802013-09-20 19:33:52 +0000256 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(1000, 1000));
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000257
reed@google.com64d62952013-01-18 17:49:28 +0000258 build_path_simple_170666(path);
259 surface->getCanvas()->drawPath(path, paint);
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000260
reed@google.com64d62952013-01-18 17:49:28 +0000261 build_path_170666(path);
262 surface->getCanvas()->drawPath(path, paint);
263}
264
reed@google.coma8790de2012-10-24 21:04:04 +0000265// Make sure we stay non-finite once we get there (unless we reset or rewind).
266static void test_addrect_isfinite(skiatest::Reporter* reporter) {
267 SkPath path;
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000268
reed@google.coma8790de2012-10-24 21:04:04 +0000269 path.addRect(SkRect::MakeWH(50, 100));
270 REPORTER_ASSERT(reporter, path.isFinite());
271
272 path.moveTo(0, 0);
273 path.lineTo(SK_ScalarInfinity, 42);
274 REPORTER_ASSERT(reporter, !path.isFinite());
275
276 path.addRect(SkRect::MakeWH(50, 100));
277 REPORTER_ASSERT(reporter, !path.isFinite());
278
279 path.reset();
280 REPORTER_ASSERT(reporter, path.isFinite());
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000281
reed@google.coma8790de2012-10-24 21:04:04 +0000282 path.addRect(SkRect::MakeWH(50, 100));
283 REPORTER_ASSERT(reporter, path.isFinite());
284}
285
reed@google.com848148e2013-01-15 15:51:59 +0000286static void build_big_path(SkPath* path, bool reducedCase) {
287 if (reducedCase) {
288 path->moveTo(577330, 1971.72f);
289 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
290 } else {
291 path->moveTo(60.1631f, 7.70567f);
292 path->quadTo(60.1631f, 7.70567f, 0.99474f, 0.901199f);
293 path->lineTo(577379, 1977.77f);
294 path->quadTo(577364, 1979.57f, 577325, 1980.26f);
295 path->quadTo(577286, 1980.95f, 577245, 1980.13f);
296 path->quadTo(577205, 1979.3f, 577187, 1977.45f);
297 path->quadTo(577168, 1975.6f, 577183, 1973.8f);
298 path->quadTo(577198, 1972, 577238, 1971.31f);
299 path->quadTo(577277, 1970.62f, 577317, 1971.45f);
300 path->quadTo(577330, 1971.72f, 577341, 1972.11f);
301 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
302 path->moveTo(306.718f, -32.912f);
303 path->cubicTo(30.531f, 10.0005f, 1502.47f, 13.2804f, 84.3088f, 9.99601f);
304 }
305}
306
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000307static void test_clipped_cubic() {
reed@google.comd28ba802013-09-20 19:33:52 +0000308 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(640, 480));
reed@google.com848148e2013-01-15 15:51:59 +0000309
310 // This path used to assert, because our cubic-chopping code incorrectly
311 // moved control points after the chop. This test should be run in SK_DEBUG
312 // mode to ensure that we no long assert.
313 SkPath path;
314 for (int doReducedCase = 0; doReducedCase <= 1; ++doReducedCase) {
315 build_big_path(&path, SkToBool(doReducedCase));
skia.committer@gmail.comff21c2e2013-01-16 07:05:56 +0000316
reed@google.com848148e2013-01-15 15:51:59 +0000317 SkPaint paint;
318 for (int doAA = 0; doAA <= 1; ++doAA) {
319 paint.setAntiAlias(SkToBool(doAA));
320 surface->getCanvas()->drawPath(path, paint);
321 }
322 }
323}
324
reed@google.com8cae8352012-09-14 15:18:41 +0000325// Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/
326// which triggered an assert, from a tricky cubic. This test replicates that
327// example, so we can ensure that we handle it (in SkEdge.cpp), and don't
328// assert in the SK_DEBUG build.
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000329static void test_tricky_cubic() {
reed@google.com8cae8352012-09-14 15:18:41 +0000330 const SkPoint pts[] = {
skia.committer@gmail.com055c7c22012-09-15 02:01:41 +0000331 { SkDoubleToScalar(18.8943768), SkDoubleToScalar(129.121277) },
332 { SkDoubleToScalar(18.8937435), SkDoubleToScalar(129.121689) },
333 { SkDoubleToScalar(18.8950119), SkDoubleToScalar(129.120422) },
334 { SkDoubleToScalar(18.5030727), SkDoubleToScalar(129.13121) },
reed@google.com8cae8352012-09-14 15:18:41 +0000335 };
336
337 SkPath path;
338 path.moveTo(pts[0]);
339 path.cubicTo(pts[1], pts[2], pts[3]);
340
341 SkPaint paint;
342 paint.setAntiAlias(true);
343
reed@google.comd28ba802013-09-20 19:33:52 +0000344 SkSurface* surface = SkSurface::NewRasterPMColor(19, 130);
reed@google.com8cae8352012-09-14 15:18:41 +0000345 surface->getCanvas()->drawPath(path, paint);
346 surface->unref();
347}
reed@android.com3abec1d2009-03-02 05:36:20 +0000348
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000349// Inspired by http://code.google.com/p/chromium/issues/detail?id=141651
350//
351static void test_isfinite_after_transform(skiatest::Reporter* reporter) {
352 SkPath path;
353 path.quadTo(157, 366, 286, 208);
354 path.arcTo(37, 442, 315, 163, 957494590897113.0f);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000355
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000356 SkMatrix matrix;
357 matrix.setScale(1000*1000, 1000*1000);
358
359 // Be sure that path::transform correctly updates isFinite and the bounds
360 // if the transformation overflows. The previous bug was that isFinite was
361 // set to true in this case, but the bounds were not set to empty (which
362 // they should be).
363 while (path.isFinite()) {
364 REPORTER_ASSERT(reporter, path.getBounds().isFinite());
365 REPORTER_ASSERT(reporter, !path.getBounds().isEmpty());
366 path.transform(matrix);
367 }
368 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
369
370 matrix.setTranslate(SK_Scalar1, SK_Scalar1);
371 path.transform(matrix);
372 // we need to still be non-finite
373 REPORTER_ASSERT(reporter, !path.isFinite());
374 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
375}
376
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000377static void add_corner_arc(SkPath* path, const SkRect& rect,
378 SkScalar xIn, SkScalar yIn,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000379 int startAngle)
380{
381
382 SkScalar rx = SkMinScalar(rect.width(), xIn);
383 SkScalar ry = SkMinScalar(rect.height(), yIn);
384
385 SkRect arcRect;
386 arcRect.set(-rx, -ry, rx, ry);
387 switch (startAngle) {
388 case 0:
389 arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom);
390 break;
391 case 90:
392 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom);
393 break;
394 case 180:
395 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop);
396 break;
397 case 270:
398 arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop);
399 break;
400 default:
401 break;
402 }
403
404 path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false);
405}
406
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000407static void make_arb_round_rect(SkPath* path, const SkRect& r,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000408 SkScalar xCorner, SkScalar yCorner) {
409 // we are lazy here and use the same x & y for each corner
410 add_corner_arc(path, r, xCorner, yCorner, 270);
411 add_corner_arc(path, r, xCorner, yCorner, 0);
412 add_corner_arc(path, r, xCorner, yCorner, 90);
413 add_corner_arc(path, r, xCorner, yCorner, 180);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000414 path->close();
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000415}
416
417// Chrome creates its own round rects with each corner possibly being different.
418// Performance will suffer if they are not convex.
419// Note: PathBench::ArbRoundRectBench performs almost exactly
420// the same test (but with drawing)
421static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000422 SkRandom rand;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000423 SkRect r;
424
425 for (int i = 0; i < 5000; ++i) {
426
robertphillips@google.com158618e2012-10-23 16:56:56 +0000427 SkScalar size = rand.nextUScalar1() * 30;
428 if (size < SK_Scalar1) {
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000429 continue;
430 }
431 r.fLeft = rand.nextUScalar1() * 300;
432 r.fTop = rand.nextUScalar1() * 300;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000433 r.fRight = r.fLeft + 2 * size;
434 r.fBottom = r.fTop + 2 * size;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000435
436 SkPath temp;
437
438 make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
439
440 REPORTER_ASSERT(reporter, temp.isConvex());
441 }
442}
443
robertphillips@google.com158618e2012-10-23 16:56:56 +0000444// Chrome will sometimes create a 0 radius round rect. The degenerate
445// quads prevent the path from being converted to a rect
446// Note: PathBench::ArbRoundRectBench performs almost exactly
447// the same test (but with drawing)
448static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000449 SkRandom rand;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000450 SkRect r;
451
452 for (int i = 0; i < 5000; ++i) {
453
454 SkScalar size = rand.nextUScalar1() * 30;
455 if (size < SK_Scalar1) {
456 continue;
457 }
458 r.fLeft = rand.nextUScalar1() * 300;
459 r.fTop = rand.nextUScalar1() * 300;
460 r.fRight = r.fLeft + 2 * size;
461 r.fBottom = r.fTop + 2 * size;
462
463 SkPath temp;
464
465 make_arb_round_rect(&temp, r, 0, 0);
466
robertphillips@google.com158618e2012-10-23 16:56:56 +0000467 SkRect result;
468 REPORTER_ASSERT(reporter, temp.isRect(&result));
469 REPORTER_ASSERT(reporter, r == result);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000470 }
471}
472
reed@google.com0bb18bb2012-07-26 15:20:36 +0000473static void test_rect_isfinite(skiatest::Reporter* reporter) {
474 const SkScalar inf = SK_ScalarInfinity;
caryclark@google.com7abfa492013-04-12 11:59:41 +0000475 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000476 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000477
reed@google.com0bb18bb2012-07-26 15:20:36 +0000478 SkRect r;
479 r.setEmpty();
480 REPORTER_ASSERT(reporter, r.isFinite());
caryclark@google.com7abfa492013-04-12 11:59:41 +0000481 r.set(0, 0, inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000482 REPORTER_ASSERT(reporter, !r.isFinite());
483 r.set(0, 0, nan, 0);
484 REPORTER_ASSERT(reporter, !r.isFinite());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000485
reed@google.com0bb18bb2012-07-26 15:20:36 +0000486 SkPoint pts[] = {
487 { 0, 0 },
488 { SK_Scalar1, 0 },
489 { 0, SK_Scalar1 },
490 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000491
reed@google.com0bb18bb2012-07-26 15:20:36 +0000492 bool isFine = r.setBoundsCheck(pts, 3);
493 REPORTER_ASSERT(reporter, isFine);
494 REPORTER_ASSERT(reporter, !r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000495
reed@google.com0bb18bb2012-07-26 15:20:36 +0000496 pts[1].set(inf, 0);
497 isFine = r.setBoundsCheck(pts, 3);
498 REPORTER_ASSERT(reporter, !isFine);
499 REPORTER_ASSERT(reporter, r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000500
reed@google.com0bb18bb2012-07-26 15:20:36 +0000501 pts[1].set(nan, 0);
502 isFine = r.setBoundsCheck(pts, 3);
503 REPORTER_ASSERT(reporter, !isFine);
504 REPORTER_ASSERT(reporter, r.isEmpty());
505}
506
507static void test_path_isfinite(skiatest::Reporter* reporter) {
508 const SkScalar inf = SK_ScalarInfinity;
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000509 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000510 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000511
reed@google.com0bb18bb2012-07-26 15:20:36 +0000512 SkPath path;
513 REPORTER_ASSERT(reporter, path.isFinite());
514
515 path.reset();
516 REPORTER_ASSERT(reporter, path.isFinite());
517
518 path.reset();
519 path.moveTo(SK_Scalar1, 0);
520 REPORTER_ASSERT(reporter, path.isFinite());
521
522 path.reset();
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000523 path.moveTo(inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000524 REPORTER_ASSERT(reporter, !path.isFinite());
525
526 path.reset();
527 path.moveTo(nan, 0);
528 REPORTER_ASSERT(reporter, !path.isFinite());
529}
530
531static void test_isfinite(skiatest::Reporter* reporter) {
532 test_rect_isfinite(reporter);
533 test_path_isfinite(reporter);
534}
535
reed@google.com744faba2012-05-29 19:54:52 +0000536// assert that we always
537// start with a moveTo
538// only have 1 moveTo
539// only have Lines after that
540// end with a single close
541// only have (at most) 1 close
542//
543static void test_poly(skiatest::Reporter* reporter, const SkPath& path,
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000544 const SkPoint srcPts[], bool expectClose) {
reed@google.com744faba2012-05-29 19:54:52 +0000545 SkPath::RawIter iter(path);
546 SkPoint pts[4];
reed@google.com744faba2012-05-29 19:54:52 +0000547
548 bool firstTime = true;
549 bool foundClose = false;
550 for (;;) {
551 switch (iter.next(pts)) {
552 case SkPath::kMove_Verb:
553 REPORTER_ASSERT(reporter, firstTime);
554 REPORTER_ASSERT(reporter, pts[0] == srcPts[0]);
555 srcPts++;
556 firstTime = false;
557 break;
558 case SkPath::kLine_Verb:
559 REPORTER_ASSERT(reporter, !firstTime);
560 REPORTER_ASSERT(reporter, pts[1] == srcPts[0]);
561 srcPts++;
562 break;
563 case SkPath::kQuad_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000564 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected quad verb");
reed@google.com744faba2012-05-29 19:54:52 +0000565 break;
reed@google.com277c3f82013-05-31 15:17:50 +0000566 case SkPath::kConic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000567 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected conic verb");
reed@google.com277c3f82013-05-31 15:17:50 +0000568 break;
reed@google.com744faba2012-05-29 19:54:52 +0000569 case SkPath::kCubic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000570 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected cubic verb");
reed@google.com744faba2012-05-29 19:54:52 +0000571 break;
572 case SkPath::kClose_Verb:
573 REPORTER_ASSERT(reporter, !firstTime);
574 REPORTER_ASSERT(reporter, !foundClose);
575 REPORTER_ASSERT(reporter, expectClose);
576 foundClose = true;
577 break;
578 case SkPath::kDone_Verb:
579 goto DONE;
580 }
581 }
582DONE:
583 REPORTER_ASSERT(reporter, foundClose == expectClose);
584}
585
586static void test_addPoly(skiatest::Reporter* reporter) {
587 SkPoint pts[32];
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000588 SkRandom rand;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000589
reed@google.com744faba2012-05-29 19:54:52 +0000590 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
591 pts[i].fX = rand.nextSScalar1();
592 pts[i].fY = rand.nextSScalar1();
593 }
594
595 for (int doClose = 0; doClose <= 1; ++doClose) {
596 for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) {
597 SkPath path;
598 path.addPoly(pts, count, SkToBool(doClose));
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000599 test_poly(reporter, path, pts, SkToBool(doClose));
reed@google.com744faba2012-05-29 19:54:52 +0000600 }
601 }
602}
603
reed@google.com8b06f1a2012-05-29 12:03:46 +0000604static void test_strokerec(skiatest::Reporter* reporter) {
605 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
606 REPORTER_ASSERT(reporter, rec.isFillStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000607
reed@google.com8b06f1a2012-05-29 12:03:46 +0000608 rec.setHairlineStyle();
609 REPORTER_ASSERT(reporter, rec.isHairlineStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000610
reed@google.com8b06f1a2012-05-29 12:03:46 +0000611 rec.setStrokeStyle(SK_Scalar1, false);
612 REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000613
reed@google.com8b06f1a2012-05-29 12:03:46 +0000614 rec.setStrokeStyle(SK_Scalar1, true);
615 REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000616
reed@google.com8b06f1a2012-05-29 12:03:46 +0000617 rec.setStrokeStyle(0, false);
618 REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000619
reed@google.com8b06f1a2012-05-29 12:03:46 +0000620 rec.setStrokeStyle(0, true);
621 REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle());
622}
623
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000624// Set this for paths that don't have a consistent direction such as a bowtie.
625// (cheapComputeDirection is not expected to catch these.)
626static const SkPath::Direction kDontCheckDir = static_cast<SkPath::Direction>(-1);
627
628static void check_direction(skiatest::Reporter* reporter, const SkPath& path,
629 SkPath::Direction expected) {
630 if (expected == kDontCheckDir) {
631 return;
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000632 }
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000633 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
634
635 SkPath::Direction dir;
636 if (copy.cheapComputeDirection(&dir)) {
637 REPORTER_ASSERT(reporter, dir == expected);
638 } else {
639 REPORTER_ASSERT(reporter, SkPath::kUnknown_Direction == expected);
640 }
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000641}
642
reed@google.com3e71a882012-01-10 18:44:37 +0000643static void test_direction(skiatest::Reporter* reporter) {
644 size_t i;
645 SkPath path;
646 REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
647 REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCW_Direction));
648 REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCCW_Direction));
reed@google.coma8a3b3d2012-11-26 18:16:27 +0000649 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kUnknown_Direction));
reed@google.com3e71a882012-01-10 18:44:37 +0000650
651 static const char* gDegen[] = {
652 "M 10 10",
653 "M 10 10 M 20 20",
654 "M 10 10 L 20 20",
655 "M 10 10 L 10 10 L 10 10",
656 "M 10 10 Q 10 10 10 10",
657 "M 10 10 C 10 10 10 10 10 10",
658 };
659 for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) {
660 path.reset();
661 bool valid = SkParsePath::FromSVGString(gDegen[i], &path);
662 REPORTER_ASSERT(reporter, valid);
663 REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
664 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000665
reed@google.com3e71a882012-01-10 18:44:37 +0000666 static const char* gCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000667 "M 10 10 L 10 10 Q 20 10 20 20",
reed@google.com3e71a882012-01-10 18:44:37 +0000668 "M 10 10 C 20 10 20 20 20 20",
reed@google.comd4146662012-01-31 15:42:29 +0000669 "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 +0000670 // rect with top two corners replaced by cubics with identical middle
671 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000672 "M 10 10 C 10 0 10 0 20 0 L 40 0 C 50 0 50 0 50 10",
673 "M 20 10 L 0 10 Q 10 10 20 0", // left, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000674 };
675 for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) {
676 path.reset();
677 bool valid = SkParsePath::FromSVGString(gCW[i], &path);
678 REPORTER_ASSERT(reporter, valid);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000679 check_direction(reporter, path, SkPath::kCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000680 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000681
reed@google.com3e71a882012-01-10 18:44:37 +0000682 static const char* gCCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000683 "M 10 10 L 10 10 Q 20 10 20 -20",
reed@google.com3e71a882012-01-10 18:44:37 +0000684 "M 10 10 C 20 10 20 -20 20 -20",
reed@google.comd4146662012-01-31 15:42:29 +0000685 "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 +0000686 // rect with top two corners replaced by cubics with identical middle
687 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000688 "M 50 10 C 50 0 50 0 40 0 L 20 0 C 10 0 10 0 10 10",
689 "M 10 10 L 30 10 Q 20 10 10 0", // right, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000690 };
691 for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) {
692 path.reset();
693 bool valid = SkParsePath::FromSVGString(gCCW[i], &path);
694 REPORTER_ASSERT(reporter, valid);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000695 check_direction(reporter, path, SkPath::kCCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000696 }
reed@google.comac8543f2012-01-30 20:51:25 +0000697
698 // Test two donuts, each wound a different direction. Only the outer contour
699 // determines the cheap direction
700 path.reset();
701 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCW_Direction);
702 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000703 check_direction(reporter, path, SkPath::kCW_Direction);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000704
reed@google.comac8543f2012-01-30 20:51:25 +0000705 path.reset();
706 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCW_Direction);
707 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000708 check_direction(reporter, path, SkPath::kCCW_Direction);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000709
bsalomon@google.com6843ac42012-02-17 13:49:03 +0000710#ifdef SK_SCALAR_IS_FLOAT
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000711 // triangle with one point really far from the origin.
712 path.reset();
713 // the first point is roughly 1.05e10, 1.05e10
bsalomon@google.com53aab782012-02-23 14:54:49 +0000714 path.moveTo(SkFloatToScalar(SkBits2Float(0x501c7652)), SkFloatToScalar(SkBits2Float(0x501c7652)));
715 path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1);
716 path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000717 check_direction(reporter, path, SkPath::kCCW_Direction);
bsalomon@google.com53aab782012-02-23 14:54:49 +0000718#endif
reed@google.com3e71a882012-01-10 18:44:37 +0000719}
720
reed@google.comffdb0182011-11-14 19:29:14 +0000721static void add_rect(SkPath* path, const SkRect& r) {
722 path->moveTo(r.fLeft, r.fTop);
723 path->lineTo(r.fRight, r.fTop);
724 path->lineTo(r.fRight, r.fBottom);
725 path->lineTo(r.fLeft, r.fBottom);
726 path->close();
727}
728
729static void test_bounds(skiatest::Reporter* reporter) {
730 static const SkRect rects[] = {
reed@google.com3563c9e2011-11-14 19:34:57 +0000731 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) },
732 { SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) },
733 { SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) },
734 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) },
reed@google.comffdb0182011-11-14 19:29:14 +0000735 };
736
737 SkPath path0, path1;
738 for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) {
739 path0.addRect(rects[i]);
740 add_rect(&path1, rects[i]);
741 }
742
743 REPORTER_ASSERT(reporter, path0.getBounds() == path1.getBounds());
744}
745
reed@google.com55b5f4b2011-09-07 12:23:41 +0000746static void stroke_cubic(const SkPoint pts[4]) {
747 SkPath path;
748 path.moveTo(pts[0]);
749 path.cubicTo(pts[1], pts[2], pts[3]);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000750
reed@google.com55b5f4b2011-09-07 12:23:41 +0000751 SkPaint paint;
752 paint.setStyle(SkPaint::kStroke_Style);
753 paint.setStrokeWidth(SK_Scalar1 * 2);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000754
reed@google.com55b5f4b2011-09-07 12:23:41 +0000755 SkPath fill;
756 paint.getFillPath(path, &fill);
757}
758
759// just ensure this can run w/o any SkASSERTS firing in the debug build
760// we used to assert due to differences in how we determine a degenerate vector
761// but that was fixed with the introduction of SkPoint::CanNormalize
762static void stroke_tiny_cubic() {
763 SkPoint p0[] = {
764 { 372.0f, 92.0f },
765 { 372.0f, 92.0f },
766 { 372.0f, 92.0f },
767 { 372.0f, 92.0f },
768 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000769
reed@google.com55b5f4b2011-09-07 12:23:41 +0000770 stroke_cubic(p0);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000771
reed@google.com55b5f4b2011-09-07 12:23:41 +0000772 SkPoint p1[] = {
773 { 372.0f, 92.0f },
774 { 372.0007f, 92.000755f },
775 { 371.99927f, 92.003922f },
776 { 371.99826f, 92.003899f },
777 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000778
reed@google.com55b5f4b2011-09-07 12:23:41 +0000779 stroke_cubic(p1);
780}
781
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000782static void check_close(skiatest::Reporter* reporter, const SkPath& path) {
783 for (int i = 0; i < 2; ++i) {
robertphillips@google.com09042b82012-04-06 20:01:46 +0000784 SkPath::Iter iter(path, SkToBool(i));
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000785 SkPoint mv;
786 SkPoint pts[4];
787 SkPath::Verb v;
788 int nMT = 0;
789 int nCL = 0;
tomhudson@google.com221db3c2011-07-28 21:10:29 +0000790 mv.set(0, 0);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000791 while (SkPath::kDone_Verb != (v = iter.next(pts))) {
792 switch (v) {
793 case SkPath::kMove_Verb:
794 mv = pts[0];
795 ++nMT;
796 break;
797 case SkPath::kClose_Verb:
798 REPORTER_ASSERT(reporter, mv == pts[0]);
799 ++nCL;
800 break;
801 default:
802 break;
803 }
804 }
805 // if we force a close on the interator we should have a close
806 // for every moveTo
807 REPORTER_ASSERT(reporter, !i || nMT == nCL);
808 }
809}
810
811static void test_close(skiatest::Reporter* reporter) {
812 SkPath closePt;
813 closePt.moveTo(0, 0);
814 closePt.close();
815 check_close(reporter, closePt);
816
817 SkPath openPt;
818 openPt.moveTo(0, 0);
819 check_close(reporter, openPt);
820
821 SkPath empty;
822 check_close(reporter, empty);
823 empty.close();
824 check_close(reporter, empty);
825
826 SkPath rect;
827 rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
828 check_close(reporter, rect);
829 rect.close();
830 check_close(reporter, rect);
831
832 SkPath quad;
833 quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
834 check_close(reporter, quad);
835 quad.close();
836 check_close(reporter, quad);
837
838 SkPath cubic;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000839 quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1,
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000840 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1);
841 check_close(reporter, cubic);
842 cubic.close();
843 check_close(reporter, cubic);
844
845 SkPath line;
846 line.moveTo(SK_Scalar1, SK_Scalar1);
847 line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1);
848 check_close(reporter, line);
849 line.close();
850 check_close(reporter, line);
851
852 SkPath rect2;
853 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
854 rect2.close();
855 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
856 check_close(reporter, rect2);
857 rect2.close();
858 check_close(reporter, rect2);
859
860 SkPath oval3;
861 oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100));
862 oval3.close();
863 oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200));
864 check_close(reporter, oval3);
865 oval3.close();
866 check_close(reporter, oval3);
867
868 SkPath moves;
869 moves.moveTo(SK_Scalar1, SK_Scalar1);
870 moves.moveTo(5 * SK_Scalar1, SK_Scalar1);
871 moves.moveTo(SK_Scalar1, 10 * SK_Scalar1);
872 moves.moveTo(10 *SK_Scalar1, SK_Scalar1);
873 check_close(reporter, moves);
reed@google.com55b5f4b2011-09-07 12:23:41 +0000874
875 stroke_tiny_cubic();
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000876}
877
reed@google.com7c424812011-05-15 04:38:34 +0000878static void check_convexity(skiatest::Reporter* reporter, const SkPath& path,
879 SkPath::Convexity expected) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000880 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
881 SkPath::Convexity c = copy.getConvexity();
reed@google.com7c424812011-05-15 04:38:34 +0000882 REPORTER_ASSERT(reporter, c == expected);
883}
884
885static void test_convexity2(skiatest::Reporter* reporter) {
886 SkPath pt;
887 pt.moveTo(0, 0);
888 pt.close();
reed@google.comb54455e2011-05-16 14:16:04 +0000889 check_convexity(reporter, pt, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000890 check_direction(reporter, pt, SkPath::kUnknown_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000891
reed@google.com7c424812011-05-15 04:38:34 +0000892 SkPath line;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000893 line.moveTo(12*SK_Scalar1, 20*SK_Scalar1);
894 line.lineTo(-12*SK_Scalar1, -20*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000895 line.close();
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000896 check_convexity(reporter, line, SkPath::kConvex_Convexity);
897 check_direction(reporter, line, SkPath::kUnknown_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000898
reed@google.com7c424812011-05-15 04:38:34 +0000899 SkPath triLeft;
900 triLeft.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000901 triLeft.lineTo(SK_Scalar1, 0);
902 triLeft.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000903 triLeft.close();
904 check_convexity(reporter, triLeft, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000905 check_direction(reporter, triLeft, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000906
reed@google.com7c424812011-05-15 04:38:34 +0000907 SkPath triRight;
908 triRight.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000909 triRight.lineTo(-SK_Scalar1, 0);
910 triRight.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000911 triRight.close();
912 check_convexity(reporter, triRight, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000913 check_direction(reporter, triRight, SkPath::kCCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000914
reed@google.com7c424812011-05-15 04:38:34 +0000915 SkPath square;
916 square.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000917 square.lineTo(SK_Scalar1, 0);
918 square.lineTo(SK_Scalar1, SK_Scalar1);
919 square.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000920 square.close();
921 check_convexity(reporter, square, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000922 check_direction(reporter, square, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000923
reed@google.com7c424812011-05-15 04:38:34 +0000924 SkPath redundantSquare;
925 redundantSquare.moveTo(0, 0);
926 redundantSquare.lineTo(0, 0);
927 redundantSquare.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000928 redundantSquare.lineTo(SK_Scalar1, 0);
929 redundantSquare.lineTo(SK_Scalar1, 0);
930 redundantSquare.lineTo(SK_Scalar1, 0);
931 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
932 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
933 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
934 redundantSquare.lineTo(0, SK_Scalar1);
935 redundantSquare.lineTo(0, SK_Scalar1);
936 redundantSquare.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000937 redundantSquare.close();
938 check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000939 check_direction(reporter, redundantSquare, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000940
reed@google.com7c424812011-05-15 04:38:34 +0000941 SkPath bowTie;
942 bowTie.moveTo(0, 0);
943 bowTie.lineTo(0, 0);
944 bowTie.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000945 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
946 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
947 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
948 bowTie.lineTo(SK_Scalar1, 0);
949 bowTie.lineTo(SK_Scalar1, 0);
950 bowTie.lineTo(SK_Scalar1, 0);
951 bowTie.lineTo(0, SK_Scalar1);
952 bowTie.lineTo(0, SK_Scalar1);
953 bowTie.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000954 bowTie.close();
955 check_convexity(reporter, bowTie, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000956 check_direction(reporter, bowTie, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000957
reed@google.com7c424812011-05-15 04:38:34 +0000958 SkPath spiral;
959 spiral.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000960 spiral.lineTo(100*SK_Scalar1, 0);
961 spiral.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
962 spiral.lineTo(0, 100*SK_Scalar1);
963 spiral.lineTo(0, 50*SK_Scalar1);
964 spiral.lineTo(50*SK_Scalar1, 50*SK_Scalar1);
965 spiral.lineTo(50*SK_Scalar1, 75*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000966 spiral.close();
reed@google.com85b6e392011-05-15 20:25:17 +0000967 check_convexity(reporter, spiral, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000968 check_direction(reporter, spiral, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000969
reed@google.com7c424812011-05-15 04:38:34 +0000970 SkPath dent;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000971 dent.moveTo(0, 0);
972 dent.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
973 dent.lineTo(0, 100*SK_Scalar1);
974 dent.lineTo(-50*SK_Scalar1, 200*SK_Scalar1);
975 dent.lineTo(-200*SK_Scalar1, 100*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000976 dent.close();
977 check_convexity(reporter, dent, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000978 check_direction(reporter, dent, SkPath::kCW_Direction);
reed@google.com7c424812011-05-15 04:38:34 +0000979}
980
reed@android.com6b82d1a2009-06-03 02:35:01 +0000981static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
982 const SkRect& bounds) {
983 REPORTER_ASSERT(reporter, p.isConvex());
984 REPORTER_ASSERT(reporter, p.getBounds() == bounds);
reed@google.com62047cf2011-02-07 19:39:09 +0000985
reed@android.com6b82d1a2009-06-03 02:35:01 +0000986 SkPath p2(p);
987 REPORTER_ASSERT(reporter, p2.isConvex());
988 REPORTER_ASSERT(reporter, p2.getBounds() == bounds);
989
990 SkPath other;
991 other.swap(p2);
992 REPORTER_ASSERT(reporter, other.isConvex());
993 REPORTER_ASSERT(reporter, other.getBounds() == bounds);
994}
995
reed@google.com04863fa2011-05-15 04:08:24 +0000996static void setFromString(SkPath* path, const char str[]) {
997 bool first = true;
998 while (str) {
999 SkScalar x, y;
1000 str = SkParse::FindScalar(str, &x);
1001 if (NULL == str) {
1002 break;
1003 }
1004 str = SkParse::FindScalar(str, &y);
1005 SkASSERT(str);
1006 if (first) {
1007 path->moveTo(x, y);
1008 first = false;
1009 } else {
1010 path->lineTo(x, y);
1011 }
1012 }
1013}
1014
1015static void test_convexity(skiatest::Reporter* reporter) {
reed@google.com04863fa2011-05-15 04:08:24 +00001016 SkPath path;
1017
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001018 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001019 path.addCircle(0, 0, SkIntToScalar(10));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001020 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001021 path.addCircle(0, 0, SkIntToScalar(10)); // 2nd circle
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001022 check_convexity(reporter, path, SkPath::kConcave_Convexity);
1023
reed@google.com04863fa2011-05-15 04:08:24 +00001024 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001025 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001026 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.com3e71a882012-01-10 18:44:37 +00001027 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCCW_Direction));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001028
reed@google.com04863fa2011-05-15 04:08:24 +00001029 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001030 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001031 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.com3e71a882012-01-10 18:44:37 +00001032 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCW_Direction));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001033
reed@google.com04863fa2011-05-15 04:08:24 +00001034 static const struct {
1035 const char* fPathStr;
1036 SkPath::Convexity fExpectedConvexity;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001037 SkPath::Direction fExpectedDirection;
reed@google.com04863fa2011-05-15 04:08:24 +00001038 } gRec[] = {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001039 { "", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1040 { "0 0", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1041 { "0 0 10 10", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1042 { "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity, SkPath::kUnknown_Direction },
1043 { "0 0 10 10 10 20", SkPath::kConvex_Convexity, SkPath::kCW_Direction },
1044 { "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPath::kCCW_Direction },
1045 { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir },
1046 { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity, SkPath::kCW_Direction },
reed@google.com04863fa2011-05-15 04:08:24 +00001047 };
1048
1049 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1050 SkPath path;
1051 setFromString(&path, gRec[i].fPathStr);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001052 check_convexity(reporter, path, gRec[i].fExpectedConvexity);
1053 check_direction(reporter, path, gRec[i].fExpectedDirection);
reed@google.com04863fa2011-05-15 04:08:24 +00001054 }
1055}
1056
reed@google.com7e6c4d12012-05-10 14:05:43 +00001057static void test_isLine(skiatest::Reporter* reporter) {
1058 SkPath path;
1059 SkPoint pts[2];
1060 const SkScalar value = SkIntToScalar(5);
1061
1062 REPORTER_ASSERT(reporter, !path.isLine(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001063
reed@google.com7e6c4d12012-05-10 14:05:43 +00001064 // set some non-zero values
1065 pts[0].set(value, value);
1066 pts[1].set(value, value);
1067 REPORTER_ASSERT(reporter, !path.isLine(pts));
1068 // check that pts was untouched
1069 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1070 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1071
1072 const SkScalar moveX = SkIntToScalar(1);
1073 const SkScalar moveY = SkIntToScalar(2);
1074 SkASSERT(value != moveX && value != moveY);
1075
1076 path.moveTo(moveX, moveY);
1077 REPORTER_ASSERT(reporter, !path.isLine(NULL));
1078 REPORTER_ASSERT(reporter, !path.isLine(pts));
1079 // check that pts was untouched
1080 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1081 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1082
1083 const SkScalar lineX = SkIntToScalar(2);
1084 const SkScalar lineY = SkIntToScalar(2);
1085 SkASSERT(value != lineX && value != lineY);
1086
1087 path.lineTo(lineX, lineY);
1088 REPORTER_ASSERT(reporter, path.isLine(NULL));
1089
1090 REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY));
1091 REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY));
1092 REPORTER_ASSERT(reporter, path.isLine(pts));
1093 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1094 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
1095
1096 path.lineTo(0, 0); // too many points/verbs
1097 REPORTER_ASSERT(reporter, !path.isLine(NULL));
1098 REPORTER_ASSERT(reporter, !path.isLine(pts));
1099 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1100 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
1101}
1102
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001103static void test_conservativelyContains(skiatest::Reporter* reporter) {
1104 SkPath path;
1105
1106 // kBaseRect is used to construct most our test paths: a rect, a circle, and a round-rect.
1107 static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
1108
1109 // A circle that bounds kBaseRect (with a significant amount of slop)
1110 SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height());
1111 circleR = SkScalarMul(circleR, SkFloatToScalar(1.75f)) / 2;
1112 static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()};
1113
1114 // round-rect radii
1115 static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)};
skia.committer@gmail.comcec8de62012-11-14 02:01:22 +00001116
caryclark@google.com56f233a2012-11-19 13:06:06 +00001117 static const struct SUPPRESS_VISIBILITY_WARNING {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001118 SkRect fQueryRect;
1119 bool fInRect;
1120 bool fInCircle;
1121 bool fInRR;
1122 } kQueries[] = {
1123 {kBaseRect, true, true, false},
1124
1125 // rect well inside of kBaseRect
1126 {SkRect::MakeLTRB(kBaseRect.fLeft + SkFloatToScalar(0.25f)*kBaseRect.width(),
1127 kBaseRect.fTop + SkFloatToScalar(0.25f)*kBaseRect.height(),
1128 kBaseRect.fRight - SkFloatToScalar(0.25f)*kBaseRect.width(),
1129 kBaseRect.fBottom - SkFloatToScalar(0.25f)*kBaseRect.height()),
1130 true, true, true},
1131
1132 // rects with edges off by one from kBaseRect's edges
1133 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1134 kBaseRect.width(), kBaseRect.height() + 1),
1135 false, true, false},
1136 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1137 kBaseRect.width() + 1, kBaseRect.height()),
1138 false, true, false},
1139 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1140 kBaseRect.width() + 1, kBaseRect.height() + 1),
1141 false, true, false},
1142 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1143 kBaseRect.width(), kBaseRect.height()),
1144 false, true, false},
1145 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1146 kBaseRect.width(), kBaseRect.height()),
1147 false, true, false},
1148 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1149 kBaseRect.width() + 2, kBaseRect.height()),
1150 false, true, false},
1151 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1152 kBaseRect.width() + 2, kBaseRect.height()),
1153 false, true, false},
1154
1155 // zero-w/h rects at each corner of kBaseRect
1156 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, false},
1157 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, false},
1158 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true, false},
1159 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true, false},
1160
1161 // far away rect
1162 {SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom,
1163 SkIntToScalar(10), SkIntToScalar(10)),
1164 false, false, false},
1165
1166 // very large rect containing kBaseRect
1167 {SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(),
1168 kBaseRect.fTop - 5 * kBaseRect.height(),
1169 11 * kBaseRect.width(), 11 * kBaseRect.height()),
1170 false, false, false},
1171
1172 // skinny rect that spans same y-range as kBaseRect
1173 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1174 SkIntToScalar(1), kBaseRect.height()),
1175 true, true, true},
1176
1177 // short rect that spans same x-range as kBaseRect
1178 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(), SkScalar(1)),
1179 true, true, true},
1180
1181 // skinny rect that spans slightly larger y-range than kBaseRect
1182 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1183 SkIntToScalar(1), kBaseRect.height() + 1),
1184 false, true, false},
1185
1186 // short rect that spans slightly larger x-range than kBaseRect
1187 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(),
1188 kBaseRect.width() + 1, SkScalar(1)),
1189 false, true, false},
1190 };
1191
1192 for (int inv = 0; inv < 4; ++inv) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001193 for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001194 SkRect qRect = kQueries[q].fQueryRect;
1195 if (inv & 0x1) {
1196 SkTSwap(qRect.fLeft, qRect.fRight);
1197 }
1198 if (inv & 0x2) {
1199 SkTSwap(qRect.fTop, qRect.fBottom);
1200 }
1201 for (int d = 0; d < 2; ++d) {
1202 SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
1203 path.reset();
1204 path.addRect(kBaseRect, dir);
1205 REPORTER_ASSERT(reporter, kQueries[q].fInRect ==
1206 path.conservativelyContainsRect(qRect));
1207
1208 path.reset();
1209 path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir);
1210 REPORTER_ASSERT(reporter, kQueries[q].fInCircle ==
1211 path.conservativelyContainsRect(qRect));
1212
1213 path.reset();
1214 path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir);
1215 REPORTER_ASSERT(reporter, kQueries[q].fInRR ==
1216 path.conservativelyContainsRect(qRect));
1217 }
1218 // Slightly non-convex shape, shouldn't contain any rects.
1219 path.reset();
1220 path.moveTo(0, 0);
1221 path.lineTo(SkIntToScalar(50), SkFloatToScalar(0.05f));
1222 path.lineTo(SkIntToScalar(100), 0);
1223 path.lineTo(SkIntToScalar(100), SkIntToScalar(100));
1224 path.lineTo(0, SkIntToScalar(100));
1225 path.close();
1226 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect));
1227 }
1228 }
1229
1230 // make sure a minimal convex shape works, a right tri with edges along pos x and y axes.
1231 path.reset();
1232 path.moveTo(0, 0);
1233 path.lineTo(SkIntToScalar(100), 0);
1234 path.lineTo(0, SkIntToScalar(100));
1235
1236 // inside, on along top edge
1237 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1238 SkIntToScalar(10),
1239 SkIntToScalar(10))));
1240 // above
1241 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1242 SkRect::MakeXYWH(SkIntToScalar(50),
1243 SkIntToScalar(-10),
1244 SkIntToScalar(10),
1245 SkIntToScalar(10))));
1246 // to the left
1247 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(-10),
1248 SkIntToScalar(5),
1249 SkIntToScalar(5),
1250 SkIntToScalar(5))));
1251
1252 // outside the diagonal edge
1253 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(10),
1254 SkIntToScalar(200),
1255 SkIntToScalar(20),
1256 SkIntToScalar(5))));
commit-bot@chromium.org62df5262013-08-01 15:35:06 +00001257
1258 // same as above path and first test but with an extra moveTo.
1259 path.reset();
1260 path.moveTo(100, 100);
1261 path.moveTo(0, 0);
1262 path.lineTo(SkIntToScalar(100), 0);
1263 path.lineTo(0, SkIntToScalar(100));
1264
1265 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1266 SkIntToScalar(10),
1267 SkIntToScalar(10))));
1268
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001269}
1270
caryclark@google.comf1316942011-07-26 19:54:45 +00001271// Simple isRect test is inline TestPath, below.
1272// test_isRect provides more extensive testing.
1273static void test_isRect(skiatest::Reporter* reporter) {
1274 // passing tests (all moveTo / lineTo...
1275 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1276 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1277 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1278 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
1279 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
1280 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1281 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1282 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1283 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001284 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}};
1285 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 +00001286 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}};
1287 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
1288 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}};
caryclark@google.combfe90372012-11-21 13:56:20 +00001289 SkPoint rf[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}};
rmistry@google.comd6176b02012-08-23 18:14:13 +00001290
caryclark@google.comf1316942011-07-26 19:54:45 +00001291 // failing tests
1292 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1293 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1294 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1295 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1296 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1297 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1298 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1299 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
caryclark@google.combfe90372012-11-21 13:56:20 +00001300 SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps
1301 SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non colinear gap
1302 SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short
rmistry@google.comd6176b02012-08-23 18:14:13 +00001303
caryclark@google.comf1316942011-07-26 19:54:45 +00001304 // failing, no close
1305 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
1306 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
1307
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001308 struct IsRectTest {
1309 SkPoint *fPoints;
1310 size_t fPointCount;
1311 bool fClose;
1312 bool fIsRect;
1313 } tests[] = {
1314 { r1, SK_ARRAY_COUNT(r1), true, true },
1315 { r2, SK_ARRAY_COUNT(r2), true, true },
1316 { r3, SK_ARRAY_COUNT(r3), true, true },
1317 { r4, SK_ARRAY_COUNT(r4), true, true },
1318 { r5, SK_ARRAY_COUNT(r5), true, true },
1319 { r6, SK_ARRAY_COUNT(r6), true, true },
1320 { r7, SK_ARRAY_COUNT(r7), true, true },
1321 { r8, SK_ARRAY_COUNT(r8), true, true },
1322 { r9, SK_ARRAY_COUNT(r9), true, true },
1323 { ra, SK_ARRAY_COUNT(ra), true, true },
1324 { rb, SK_ARRAY_COUNT(rb), true, true },
1325 { rc, SK_ARRAY_COUNT(rc), true, true },
1326 { rd, SK_ARRAY_COUNT(rd), true, true },
1327 { re, SK_ARRAY_COUNT(re), true, true },
1328 { rf, SK_ARRAY_COUNT(rf), true, true },
1329
1330 { f1, SK_ARRAY_COUNT(f1), true, false },
1331 { f2, SK_ARRAY_COUNT(f2), true, false },
1332 { f3, SK_ARRAY_COUNT(f3), true, false },
1333 { f4, SK_ARRAY_COUNT(f4), true, false },
1334 { f5, SK_ARRAY_COUNT(f5), true, false },
1335 { f6, SK_ARRAY_COUNT(f6), true, false },
1336 { f7, SK_ARRAY_COUNT(f7), true, false },
1337 { f8, SK_ARRAY_COUNT(f8), true, false },
1338 { f9, SK_ARRAY_COUNT(f9), true, false },
1339 { fa, SK_ARRAY_COUNT(fa), true, false },
1340 { fb, SK_ARRAY_COUNT(fb), true, false },
1341
1342 { c1, SK_ARRAY_COUNT(c1), false, false },
1343 { c2, SK_ARRAY_COUNT(c2), false, false },
caryclark@google.comf1316942011-07-26 19:54:45 +00001344 };
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001345
1346 const size_t testCount = SK_ARRAY_COUNT(tests);
caryclark@google.comf1316942011-07-26 19:54:45 +00001347 size_t index;
1348 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1349 SkPath path;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001350 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1351 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1352 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.comf1316942011-07-26 19:54:45 +00001353 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001354 if (tests[testIndex].fClose) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001355 path.close();
1356 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001357 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL));
1358 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL, NULL));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001359
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001360 if (tests[testIndex].fIsRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001361 SkRect computed, expected;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001362 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001363 REPORTER_ASSERT(reporter, path.isRect(&computed));
1364 REPORTER_ASSERT(reporter, expected == computed);
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +00001365
caryclark@google.comf68154a2012-11-21 15:18:06 +00001366 bool isClosed;
1367 SkPath::Direction direction, cheapDirection;
1368 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection));
robertphillips@google.com8fd16032013-06-25 15:39:58 +00001369 REPORTER_ASSERT(reporter, path.isRect(&isClosed, &direction));
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001370 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001371 REPORTER_ASSERT(reporter, direction == cheapDirection);
1372 } else {
1373 SkRect computed;
1374 computed.set(123, 456, 789, 1011);
1375 REPORTER_ASSERT(reporter, !path.isRect(&computed));
1376 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456);
1377 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011);
1378
1379 bool isClosed = (bool) -1;
1380 SkPath::Direction direction = (SkPath::Direction) -1;
robertphillips@google.com8fd16032013-06-25 15:39:58 +00001381 REPORTER_ASSERT(reporter, !path.isRect(&isClosed, &direction));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001382 REPORTER_ASSERT(reporter, isClosed == (bool) -1);
1383 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001384 }
caryclark@google.comf1316942011-07-26 19:54:45 +00001385 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00001386
caryclark@google.comf1316942011-07-26 19:54:45 +00001387 // fail, close then line
1388 SkPath path1;
1389 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001390 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001391 path1.lineTo(r1[index].fX, r1[index].fY);
1392 }
1393 path1.close();
1394 path1.lineTo(1, 0);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001395 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001396
caryclark@google.comf1316942011-07-26 19:54:45 +00001397 // fail, move in the middle
1398 path1.reset();
1399 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001400 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001401 if (index == 2) {
1402 path1.moveTo(1, .5f);
1403 }
1404 path1.lineTo(r1[index].fX, r1[index].fY);
1405 }
1406 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001407 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00001408
1409 // fail, move on the edge
1410 path1.reset();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001411 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001412 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1413 path1.lineTo(r1[index].fX, r1[index].fY);
1414 }
1415 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001416 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001417
caryclark@google.comf1316942011-07-26 19:54:45 +00001418 // fail, quad
1419 path1.reset();
1420 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001421 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001422 if (index == 2) {
1423 path1.quadTo(1, .5f, 1, .5f);
1424 }
1425 path1.lineTo(r1[index].fX, r1[index].fY);
1426 }
1427 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001428 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001429
caryclark@google.comf1316942011-07-26 19:54:45 +00001430 // fail, cubic
1431 path1.reset();
1432 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001433 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001434 if (index == 2) {
1435 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1436 }
1437 path1.lineTo(r1[index].fX, r1[index].fY);
1438 }
1439 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001440 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00001441}
1442
caryclark@google.com56f233a2012-11-19 13:06:06 +00001443static void test_isNestedRects(skiatest::Reporter* reporter) {
1444 // passing tests (all moveTo / lineTo...
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001445 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001446 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1447 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1448 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001449 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001450 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1451 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1452 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1453 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001454 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; // CCW
1455 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 +00001456 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW
1457 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW
1458 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001459
1460 // failing tests
1461 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1462 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1463 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1464 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1465 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1466 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1467 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1468 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
1469
1470 // failing, no close
1471 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
1472 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
1473
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001474 struct IsNestedRectTest {
1475 SkPoint *fPoints;
1476 size_t fPointCount;
1477 SkPath::Direction fDirection;
1478 bool fClose;
1479 bool fIsNestedRect; // nests with path.addRect(-1, -1, 2, 2);
1480 } tests[] = {
1481 { r1, SK_ARRAY_COUNT(r1), SkPath::kCW_Direction , true, true },
1482 { r2, SK_ARRAY_COUNT(r2), SkPath::kCW_Direction , true, true },
1483 { r3, SK_ARRAY_COUNT(r3), SkPath::kCW_Direction , true, true },
1484 { r4, SK_ARRAY_COUNT(r4), SkPath::kCW_Direction , true, true },
1485 { r5, SK_ARRAY_COUNT(r5), SkPath::kCCW_Direction, true, true },
1486 { r6, SK_ARRAY_COUNT(r6), SkPath::kCCW_Direction, true, true },
1487 { r7, SK_ARRAY_COUNT(r7), SkPath::kCCW_Direction, true, true },
1488 { r8, SK_ARRAY_COUNT(r8), SkPath::kCCW_Direction, true, true },
1489 { r9, SK_ARRAY_COUNT(r9), SkPath::kCCW_Direction, true, true },
1490 { ra, SK_ARRAY_COUNT(ra), SkPath::kCCW_Direction, true, true },
1491 { rb, SK_ARRAY_COUNT(rb), SkPath::kCW_Direction, true, true },
1492 { rc, SK_ARRAY_COUNT(rc), SkPath::kCW_Direction, true, true },
1493 { rd, SK_ARRAY_COUNT(rd), SkPath::kCCW_Direction, true, true },
1494 { re, SK_ARRAY_COUNT(re), SkPath::kCW_Direction, true, true },
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001495
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001496 { f1, SK_ARRAY_COUNT(f1), SkPath::kUnknown_Direction, true, false },
1497 { f2, SK_ARRAY_COUNT(f2), SkPath::kUnknown_Direction, true, false },
1498 { f3, SK_ARRAY_COUNT(f3), SkPath::kUnknown_Direction, true, false },
1499 { f4, SK_ARRAY_COUNT(f4), SkPath::kUnknown_Direction, true, false },
1500 { f5, SK_ARRAY_COUNT(f5), SkPath::kUnknown_Direction, true, false },
1501 { f6, SK_ARRAY_COUNT(f6), SkPath::kUnknown_Direction, true, false },
1502 { f7, SK_ARRAY_COUNT(f7), SkPath::kUnknown_Direction, true, false },
1503 { f8, SK_ARRAY_COUNT(f8), SkPath::kUnknown_Direction, true, false },
1504
1505 { c1, SK_ARRAY_COUNT(c1), SkPath::kUnknown_Direction, false, false },
1506 { c2, SK_ARRAY_COUNT(c2), SkPath::kUnknown_Direction, false, false },
1507 };
1508
1509 const size_t testCount = SK_ARRAY_COUNT(tests);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001510 size_t index;
1511 for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001512 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1513 SkPath path;
1514 if (rectFirst) {
1515 path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1516 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001517 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1518 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1519 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001520 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001521 if (tests[testIndex].fClose) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001522 path.close();
1523 }
1524 if (!rectFirst) {
1525 path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1526 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001527 REPORTER_ASSERT(reporter, tests[testIndex].fIsNestedRect == path.isNestedRects(NULL));
1528 if (tests[testIndex].fIsNestedRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001529 SkRect expected[2], computed[2];
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001530 SkPath::Direction expectedDirs[2], computedDirs[2];
caryclark@google.com56f233a2012-11-19 13:06:06 +00001531 SkRect testBounds;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001532 testBounds.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001533 expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2);
1534 expected[1] = testBounds;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001535 if (rectFirst) {
1536 expectedDirs[0] = SkPath::kCW_Direction;
1537 } else {
1538 expectedDirs[0] = SkPath::kCCW_Direction;
1539 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001540 expectedDirs[1] = tests[testIndex].fDirection;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001541 REPORTER_ASSERT(reporter, path.isNestedRects(computed, computedDirs));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001542 REPORTER_ASSERT(reporter, expected[0] == computed[0]);
1543 REPORTER_ASSERT(reporter, expected[1] == computed[1]);
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001544 REPORTER_ASSERT(reporter, expectedDirs[0] == computedDirs[0]);
1545 REPORTER_ASSERT(reporter, expectedDirs[1] == computedDirs[1]);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001546 }
caryclark@google.com56f233a2012-11-19 13:06:06 +00001547 }
1548
1549 // fail, close then line
1550 SkPath path1;
1551 if (rectFirst) {
1552 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1553 }
1554 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001555 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001556 path1.lineTo(r1[index].fX, r1[index].fY);
1557 }
1558 path1.close();
1559 path1.lineTo(1, 0);
1560 if (!rectFirst) {
1561 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1562 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001563 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001564
1565 // fail, move in the middle
1566 path1.reset();
1567 if (rectFirst) {
1568 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1569 }
1570 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001571 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001572 if (index == 2) {
1573 path1.moveTo(1, .5f);
1574 }
1575 path1.lineTo(r1[index].fX, r1[index].fY);
1576 }
1577 path1.close();
1578 if (!rectFirst) {
1579 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1580 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001581 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001582
1583 // fail, move on the edge
1584 path1.reset();
1585 if (rectFirst) {
1586 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1587 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001588 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001589 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1590 path1.lineTo(r1[index].fX, r1[index].fY);
1591 }
1592 path1.close();
1593 if (!rectFirst) {
1594 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1595 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001596 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001597
1598 // fail, quad
1599 path1.reset();
1600 if (rectFirst) {
1601 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1602 }
1603 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001604 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001605 if (index == 2) {
1606 path1.quadTo(1, .5f, 1, .5f);
1607 }
1608 path1.lineTo(r1[index].fX, r1[index].fY);
1609 }
1610 path1.close();
1611 if (!rectFirst) {
1612 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1613 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001614 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001615
1616 // fail, cubic
1617 path1.reset();
1618 if (rectFirst) {
1619 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1620 }
1621 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001622 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001623 if (index == 2) {
1624 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1625 }
1626 path1.lineTo(r1[index].fX, r1[index].fY);
1627 }
1628 path1.close();
1629 if (!rectFirst) {
1630 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1631 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001632 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001633
caryclark@google.com56f233a2012-11-19 13:06:06 +00001634 // fail, not nested
1635 path1.reset();
1636 path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction);
1637 path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001638 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001639 }
caryclark@google.combfe90372012-11-21 13:56:20 +00001640
1641 // pass, stroke rect
1642 SkPath src, dst;
1643 src.addRect(1, 1, 7, 7, SkPath::kCW_Direction);
1644 SkPaint strokePaint;
1645 strokePaint.setStyle(SkPaint::kStroke_Style);
1646 strokePaint.setStrokeWidth(2);
1647 strokePaint.getFillPath(src, &dst);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001648 REPORTER_ASSERT(reporter, dst.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001649}
1650
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001651static void write_and_read_back(skiatest::Reporter* reporter,
1652 const SkPath& p) {
1653 SkWriter32 writer(100);
1654 writer.writePath(p);
1655 size_t size = writer.size();
1656 SkAutoMalloc storage(size);
1657 writer.flatten(storage.get());
1658 SkReader32 reader(storage.get(), size);
1659
1660 SkPath readBack;
1661 REPORTER_ASSERT(reporter, readBack != p);
1662 reader.readPath(&readBack);
1663 REPORTER_ASSERT(reporter, readBack == p);
1664
rmistry@google.comd6176b02012-08-23 18:14:13 +00001665 REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() ==
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001666 p.getConvexityOrUnknown());
1667
1668 REPORTER_ASSERT(reporter, readBack.isOval(NULL) == p.isOval(NULL));
1669
1670 const SkRect& origBounds = p.getBounds();
1671 const SkRect& readBackBounds = readBack.getBounds();
1672
1673 REPORTER_ASSERT(reporter, origBounds == readBackBounds);
1674}
1675
reed@google.com53effc52011-09-21 19:05:12 +00001676static void test_flattening(skiatest::Reporter* reporter) {
1677 SkPath p;
1678
1679 static const SkPoint pts[] = {
1680 { 0, 0 },
1681 { SkIntToScalar(10), SkIntToScalar(10) },
1682 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 },
1683 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }
1684 };
1685 p.moveTo(pts[0]);
1686 p.lineTo(pts[1]);
1687 p.quadTo(pts[2], pts[3]);
1688 p.cubicTo(pts[4], pts[5], pts[6]);
1689
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001690 write_and_read_back(reporter, p);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00001691
1692 // create a buffer that should be much larger than the path so we don't
1693 // kill our stack if writer goes too far.
1694 char buffer[1024];
1695 uint32_t size1 = p.writeToMemory(NULL);
1696 uint32_t size2 = p.writeToMemory(buffer);
1697 REPORTER_ASSERT(reporter, size1 == size2);
1698
1699 SkPath p2;
1700 uint32_t size3 = p2.readFromMemory(buffer);
1701 REPORTER_ASSERT(reporter, size1 == size3);
1702 REPORTER_ASSERT(reporter, p == p2);
1703
1704 char buffer2[1024];
1705 size3 = p2.writeToMemory(buffer2);
1706 REPORTER_ASSERT(reporter, size1 == size3);
1707 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001708
1709 // test persistence of the oval flag & convexity
1710 {
1711 SkPath oval;
1712 SkRect rect = SkRect::MakeWH(10, 10);
1713 oval.addOval(rect);
1714
1715 write_and_read_back(reporter, oval);
1716 }
reed@google.com53effc52011-09-21 19:05:12 +00001717}
1718
1719static void test_transform(skiatest::Reporter* reporter) {
1720 SkPath p, p1;
rmistry@google.comd6176b02012-08-23 18:14:13 +00001721
reed@google.com53effc52011-09-21 19:05:12 +00001722 static const SkPoint pts[] = {
1723 { 0, 0 },
1724 { SkIntToScalar(10), SkIntToScalar(10) },
1725 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 },
1726 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }
1727 };
1728 p.moveTo(pts[0]);
1729 p.lineTo(pts[1]);
1730 p.quadTo(pts[2], pts[3]);
1731 p.cubicTo(pts[4], pts[5], pts[6]);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001732
reed@google.com53effc52011-09-21 19:05:12 +00001733 SkMatrix matrix;
1734 matrix.reset();
1735 p.transform(matrix, &p1);
1736 REPORTER_ASSERT(reporter, p == p1);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001737
reed@google.com53effc52011-09-21 19:05:12 +00001738 matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3);
1739 p.transform(matrix, &p1);
1740 SkPoint pts1[7];
1741 int count = p1.getPoints(pts1, 7);
1742 REPORTER_ASSERT(reporter, 7 == count);
1743 for (int i = 0; i < count; ++i) {
1744 SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3);
1745 REPORTER_ASSERT(reporter, newPt == pts1[i]);
1746 }
1747}
1748
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00001749static void test_zero_length_paths(skiatest::Reporter* reporter) {
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001750 SkPath p;
schenney@chromium.org7e963602012-06-13 17:05:43 +00001751 uint8_t verbs[32];
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00001752
caryclark@google.com56f233a2012-11-19 13:06:06 +00001753 struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData {
schenney@chromium.org7e963602012-06-13 17:05:43 +00001754 const char* testPath;
1755 const size_t numResultPts;
1756 const SkRect resultBound;
1757 const SkPath::Verb* resultVerbs;
1758 const size_t numResultVerbs;
1759 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00001760
schenney@chromium.org7e963602012-06-13 17:05:43 +00001761 static const SkPath::Verb resultVerbs1[] = { SkPath::kMove_Verb };
1762 static const SkPath::Verb resultVerbs2[] = { SkPath::kMove_Verb, SkPath::kMove_Verb };
1763 static const SkPath::Verb resultVerbs3[] = { SkPath::kMove_Verb, SkPath::kClose_Verb };
1764 static const SkPath::Verb resultVerbs4[] = { SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb };
1765 static const SkPath::Verb resultVerbs5[] = { SkPath::kMove_Verb, SkPath::kLine_Verb };
1766 static const SkPath::Verb resultVerbs6[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb };
1767 static const SkPath::Verb resultVerbs7[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb };
1768 static const SkPath::Verb resultVerbs8[] = {
1769 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb
1770 };
1771 static const SkPath::Verb resultVerbs9[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb };
1772 static const SkPath::Verb resultVerbs10[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb };
1773 static const SkPath::Verb resultVerbs11[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb };
1774 static const SkPath::Verb resultVerbs12[] = {
1775 SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb
1776 };
1777 static const SkPath::Verb resultVerbs13[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb };
1778 static const SkPath::Verb resultVerbs14[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb };
1779 static const SkPath::Verb resultVerbs15[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb };
1780 static const SkPath::Verb resultVerbs16[] = {
1781 SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb
1782 };
1783 static const struct zeroPathTestData gZeroLengthTests[] = {
1784 { "M 1 1", 1, {0, 0, 0, 0}, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00001785 { "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 +00001786 { "M 1 1 z", 1, {0, 0, 0, 0}, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00001787 { "M 1 1 z M 2 1 z", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
1788 { "M 1 1 L 1 1", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) },
1789 { "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) },
1790 { "M 1 1 L 1 1 z", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs7, SK_ARRAY_COUNT(resultVerbs7) },
1791 { "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) },
1792 { "M 1 1 Q 1 1 1 1", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs9, SK_ARRAY_COUNT(resultVerbs9) },
1793 { "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) },
1794 { "M 1 1 Q 1 1 1 1 z", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs11, SK_ARRAY_COUNT(resultVerbs11) },
1795 { "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) },
1796 { "M 1 1 C 1 1 1 1 1 1", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs13, SK_ARRAY_COUNT(resultVerbs13) },
1797 { "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 +00001798 SK_ARRAY_COUNT(resultVerbs14)
1799 },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00001800 { "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) },
1801 { "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 +00001802 SK_ARRAY_COUNT(resultVerbs16)
1803 }
1804 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00001805
schenney@chromium.org7e963602012-06-13 17:05:43 +00001806 for (size_t i = 0; i < SK_ARRAY_COUNT(gZeroLengthTests); ++i) {
1807 p.reset();
1808 bool valid = SkParsePath::FromSVGString(gZeroLengthTests[i].testPath, &p);
1809 REPORTER_ASSERT(reporter, valid);
1810 REPORTER_ASSERT(reporter, !p.isEmpty());
1811 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultPts == (size_t)p.countPoints());
1812 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultBound == p.getBounds());
1813 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultVerbs == (size_t)p.getVerbs(verbs, SK_ARRAY_COUNT(verbs)));
1814 for (size_t j = 0; j < gZeroLengthTests[i].numResultVerbs; ++j) {
1815 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultVerbs[j] == verbs[j]);
1816 }
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00001817 }
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00001818}
1819
1820struct SegmentInfo {
1821 SkPath fPath;
1822 int fPointCount;
1823};
1824
reed@google.com10296cc2011-09-21 12:29:05 +00001825#define kCurveSegmentMask (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask)
1826
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001827static void test_segment_masks(skiatest::Reporter* reporter) {
reed@google.comeef938c2012-08-01 20:01:49 +00001828 SkPath p, p2;
1829
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001830 p.moveTo(0, 0);
1831 p.quadTo(100, 100, 200, 200);
1832 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == p.getSegmentMasks());
1833 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00001834 p2 = p;
1835 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001836 p.cubicTo(100, 100, 200, 200, 300, 300);
1837 REPORTER_ASSERT(reporter, kCurveSegmentMask == p.getSegmentMasks());
1838 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00001839 p2 = p;
1840 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
1841
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001842 p.reset();
1843 p.moveTo(0, 0);
1844 p.cubicTo(100, 100, 200, 200, 300, 300);
1845 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == p.getSegmentMasks());
reed@google.comeef938c2012-08-01 20:01:49 +00001846 p2 = p;
1847 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
rmistry@google.comd6176b02012-08-23 18:14:13 +00001848
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001849 REPORTER_ASSERT(reporter, !p.isEmpty());
1850}
1851
1852static void test_iter(skiatest::Reporter* reporter) {
schenney@chromium.org7e963602012-06-13 17:05:43 +00001853 SkPath p;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001854 SkPoint pts[4];
1855
1856 // Test an iterator with no path
1857 SkPath::Iter noPathIter;
1858 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00001859
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001860 // Test that setting an empty path works
1861 noPathIter.setPath(p, false);
1862 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00001863
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001864 // Test that close path makes no difference for an empty path
1865 noPathIter.setPath(p, true);
1866 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00001867
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001868 // Test an iterator with an initial empty path
1869 SkPath::Iter iter(p, false);
1870 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
1871
1872 // Test that close path makes no difference
schenney@chromium.org7e963602012-06-13 17:05:43 +00001873 iter.setPath(p, true);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001874 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
1875
rmistry@google.comd6176b02012-08-23 18:14:13 +00001876
schenney@chromium.org7e963602012-06-13 17:05:43 +00001877 struct iterTestData {
1878 const char* testPath;
1879 const bool forceClose;
1880 const bool consumeDegenerates;
1881 const size_t* numResultPtsPerVerb;
1882 const SkPoint* resultPts;
1883 const SkPath::Verb* resultVerbs;
1884 const size_t numResultVerbs;
1885 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001886
schenney@chromium.org7e963602012-06-13 17:05:43 +00001887 static const SkPath::Verb resultVerbs1[] = { SkPath::kDone_Verb };
1888 static const SkPath::Verb resultVerbs2[] = {
1889 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kDone_Verb
1890 };
1891 static const SkPath::Verb resultVerbs3[] = {
1892 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
1893 };
1894 static const SkPath::Verb resultVerbs4[] = {
1895 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
1896 };
1897 static const SkPath::Verb resultVerbs5[] = {
1898 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
1899 };
1900 static const size_t resultPtsSizes1[] = { 0 };
schenney@chromium.orgfedd09b2012-06-13 18:29:20 +00001901 static const size_t resultPtsSizes2[] = { 1, 2, 2, 0 };
1902 static const size_t resultPtsSizes3[] = { 1, 2, 2, 2, 1, 0 };
1903 static const size_t resultPtsSizes4[] = { 1, 2, 1, 1, 0 };
1904 static const size_t resultPtsSizes5[] = { 1, 2, 1, 1, 1, 0 };
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00001905 static const SkPoint* resultPts1 = 0;
schenney@chromium.org7e963602012-06-13 17:05:43 +00001906 static const SkPoint resultPts2[] = {
1907 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 }
1908 };
1909 static const SkPoint resultPts3[] = {
1910 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 },
1911 { 0, SK_Scalar1 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }
1912 };
1913 static const SkPoint resultPts4[] = {
1914 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
1915 };
1916 static const SkPoint resultPts5[] = {
1917 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
1918 };
1919 static const struct iterTestData gIterTests[] = {
1920 { "M 1 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00001921 { "M 1 0 M 2 0 M 3 0 M 4 0 M 5 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
1922 { "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 +00001923 { "z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
1924 { "z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
1925 { "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) },
1926 { "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 +00001927 { "M 1 0 L 1 1 L 0 1 M 0 0 z", false, true, resultPtsSizes2, resultPts2, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
1928 { "M 1 0 L 1 1 L 0 1 M 0 0 z", true, true, resultPtsSizes3, resultPts3, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
1929 { "M 1 0 L 1 0 M 0 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
1930 { "M 1 0 L 1 0 M 0 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
1931 { "M 1 0 L 1 0 M 0 0 z", false, false, resultPtsSizes4, resultPts4, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
1932 { "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 +00001933 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001934
schenney@chromium.org7e963602012-06-13 17:05:43 +00001935 for (size_t i = 0; i < SK_ARRAY_COUNT(gIterTests); ++i) {
1936 p.reset();
1937 bool valid = SkParsePath::FromSVGString(gIterTests[i].testPath, &p);
1938 REPORTER_ASSERT(reporter, valid);
1939 iter.setPath(p, gIterTests[i].forceClose);
1940 int j = 0, l = 0;
1941 do {
1942 REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegenerates) == gIterTests[i].resultVerbs[j]);
1943 for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k) {
1944 REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]);
1945 }
1946 } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb);
1947 REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs);
1948 }
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001949
1950 // The GM degeneratesegments.cpp test is more extensive
1951}
1952
1953static void test_raw_iter(skiatest::Reporter* reporter) {
1954 SkPath p;
1955 SkPoint pts[4];
1956
1957 // Test an iterator with no path
1958 SkPath::RawIter noPathIter;
1959 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
1960 // Test that setting an empty path works
1961 noPathIter.setPath(p);
1962 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001963
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001964 // Test an iterator with an initial empty path
1965 SkPath::RawIter iter(p);
1966 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
1967
1968 // Test that a move-only path returns the move.
1969 p.moveTo(SK_Scalar1, 0);
1970 iter.setPath(p);
1971 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
1972 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
1973 REPORTER_ASSERT(reporter, pts[0].fY == 0);
1974 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
1975
1976 // No matter how many moves we add, we should get them all back
1977 p.moveTo(SK_Scalar1*2, SK_Scalar1);
1978 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
1979 iter.setPath(p);
1980 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
1981 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
1982 REPORTER_ASSERT(reporter, pts[0].fY == 0);
1983 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
1984 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
1985 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
1986 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
1987 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
1988 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
1989 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
1990
1991 // Initial close is never ever stored
1992 p.reset();
1993 p.close();
1994 iter.setPath(p);
1995 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
1996
1997 // Move/close sequences
1998 p.reset();
1999 p.close(); // Not stored, no purpose
2000 p.moveTo(SK_Scalar1, 0);
2001 p.close();
2002 p.close(); // Not stored, no purpose
2003 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2004 p.close();
2005 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2006 p.moveTo(SK_Scalar1*4, SK_Scalar1*3);
2007 p.close();
2008 iter.setPath(p);
2009 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2010 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2011 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2012 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2013 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2014 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2015 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2016 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2017 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2018 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2019 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2020 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2021 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2022 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2023 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2024 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2025 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2026 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2027 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2028 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2029 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2030 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2031
2032 // Generate random paths and verify
2033 SkPoint randomPts[25];
2034 for (int i = 0; i < 5; ++i) {
2035 for (int j = 0; j < 5; ++j) {
2036 randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j);
2037 }
2038 }
2039
2040 // Max of 10 segments, max 3 points per segment
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +00002041 SkRandom rand(9876543);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002042 SkPoint expectedPts[31]; // May have leading moveTo
reed@google.comd335d1d2012-01-12 18:17:11 +00002043 SkPath::Verb expectedVerbs[22]; // May have leading moveTo
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002044 SkPath::Verb nextVerb;
reed@google.comd335d1d2012-01-12 18:17:11 +00002045
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002046 for (int i = 0; i < 500; ++i) {
2047 p.reset();
2048 bool lastWasClose = true;
2049 bool haveMoveTo = false;
reed@google.comd335d1d2012-01-12 18:17:11 +00002050 SkPoint lastMoveToPt = { 0, 0 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002051 int numPoints = 0;
2052 int numVerbs = (rand.nextU() >> 16) % 10;
2053 int numIterVerbs = 0;
2054 for (int j = 0; j < numVerbs; ++j) {
2055 do {
2056 nextVerb = static_cast<SkPath::Verb>((rand.nextU() >> 16) % SkPath::kDone_Verb);
2057 } while (lastWasClose && nextVerb == SkPath::kClose_Verb);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002058 switch (nextVerb) {
2059 case SkPath::kMove_Verb:
2060 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2061 p.moveTo(expectedPts[numPoints]);
reed@google.comd335d1d2012-01-12 18:17:11 +00002062 lastMoveToPt = expectedPts[numPoints];
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002063 numPoints += 1;
2064 lastWasClose = false;
2065 haveMoveTo = true;
2066 break;
2067 case SkPath::kLine_Verb:
2068 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002069 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002070 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2071 haveMoveTo = true;
2072 }
2073 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2074 p.lineTo(expectedPts[numPoints]);
2075 numPoints += 1;
2076 lastWasClose = false;
2077 break;
2078 case SkPath::kQuad_Verb:
2079 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002080 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002081 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2082 haveMoveTo = true;
2083 }
2084 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2085 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2086 p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]);
2087 numPoints += 2;
2088 lastWasClose = false;
2089 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002090 case SkPath::kConic_Verb:
2091 if (!haveMoveTo) {
2092 expectedPts[numPoints++] = lastMoveToPt;
2093 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2094 haveMoveTo = true;
2095 }
2096 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2097 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2098 p.conicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2099 rand.nextUScalar1() * 4);
2100 numPoints += 2;
2101 lastWasClose = false;
2102 break;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002103 case SkPath::kCubic_Verb:
2104 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002105 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002106 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2107 haveMoveTo = true;
2108 }
2109 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2110 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2111 expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25];
2112 p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2113 expectedPts[numPoints + 2]);
2114 numPoints += 3;
2115 lastWasClose = false;
2116 break;
2117 case SkPath::kClose_Verb:
2118 p.close();
reed@google.comd335d1d2012-01-12 18:17:11 +00002119 haveMoveTo = false;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002120 lastWasClose = true;
2121 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002122 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002123 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002124 }
2125 expectedVerbs[numIterVerbs++] = nextVerb;
2126 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00002127
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002128 iter.setPath(p);
2129 numVerbs = numIterVerbs;
2130 numIterVerbs = 0;
2131 int numIterPts = 0;
2132 SkPoint lastMoveTo;
2133 SkPoint lastPt;
2134 lastMoveTo.set(0, 0);
2135 lastPt.set(0, 0);
2136 while ((nextVerb = iter.next(pts)) != SkPath::kDone_Verb) {
2137 REPORTER_ASSERT(reporter, nextVerb == expectedVerbs[numIterVerbs]);
2138 numIterVerbs++;
2139 switch (nextVerb) {
2140 case SkPath::kMove_Verb:
2141 REPORTER_ASSERT(reporter, numIterPts < numPoints);
2142 REPORTER_ASSERT(reporter, pts[0] == expectedPts[numIterPts]);
2143 lastPt = lastMoveTo = pts[0];
2144 numIterPts += 1;
2145 break;
2146 case SkPath::kLine_Verb:
2147 REPORTER_ASSERT(reporter, numIterPts < numPoints + 1);
2148 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2149 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2150 lastPt = pts[1];
2151 numIterPts += 1;
2152 break;
2153 case SkPath::kQuad_Verb:
reed@google.com277c3f82013-05-31 15:17:50 +00002154 case SkPath::kConic_Verb:
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002155 REPORTER_ASSERT(reporter, numIterPts < numPoints + 2);
2156 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2157 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2158 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2159 lastPt = pts[2];
2160 numIterPts += 2;
2161 break;
2162 case SkPath::kCubic_Verb:
2163 REPORTER_ASSERT(reporter, numIterPts < numPoints + 3);
2164 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2165 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2166 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2167 REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]);
2168 lastPt = pts[3];
2169 numIterPts += 3;
2170 break;
2171 case SkPath::kClose_Verb:
2172 REPORTER_ASSERT(reporter, pts[0] == lastMoveTo);
2173 lastPt = lastMoveTo;
2174 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002175 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002176 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002177 }
2178 }
2179 REPORTER_ASSERT(reporter, numIterPts == numPoints);
2180 REPORTER_ASSERT(reporter, numIterVerbs == numVerbs);
2181 }
2182}
2183
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002184static void check_for_circle(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002185 const SkPath& path,
2186 bool expectedCircle,
2187 SkPath::Direction expectedDir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002188 SkRect rect;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002189 REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle);
2190 REPORTER_ASSERT(reporter, path.cheapIsDirection(expectedDir));
skia.committer@gmail.comfbb0ed92012-11-13 21:46:06 +00002191
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002192 if (expectedCircle) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002193 REPORTER_ASSERT(reporter, rect.height() == rect.width());
2194 }
2195}
2196
2197static void test_circle_skew(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002198 const SkPath& path,
2199 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002200 SkPath tmp;
2201
2202 SkMatrix m;
2203 m.setSkew(SkIntToScalar(3), SkIntToScalar(5));
2204 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002205 // this matrix reverses the direction.
2206 if (SkPath::kCCW_Direction == dir) {
2207 dir = SkPath::kCW_Direction;
2208 } else {
2209 SkASSERT(SkPath::kCW_Direction == dir);
2210 dir = SkPath::kCCW_Direction;
2211 }
2212 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002213}
2214
2215static void test_circle_translate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002216 const SkPath& path,
2217 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002218 SkPath tmp;
2219
2220 // translate at small offset
2221 SkMatrix m;
2222 m.setTranslate(SkIntToScalar(15), SkIntToScalar(15));
2223 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002224 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002225
2226 tmp.reset();
2227 m.reset();
2228
2229 // translate at a relatively big offset
2230 m.setTranslate(SkIntToScalar(1000), SkIntToScalar(1000));
2231 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002232 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002233}
2234
2235static void test_circle_rotate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002236 const SkPath& path,
2237 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002238 for (int angle = 0; angle < 360; ++angle) {
2239 SkPath tmp;
2240 SkMatrix m;
2241 m.setRotate(SkIntToScalar(angle));
2242 path.transform(m, &tmp);
2243
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002244 // TODO: a rotated circle whose rotated angle is not a multiple of 90
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002245 // degrees is not an oval anymore, this can be improved. we made this
2246 // for the simplicity of our implementation.
2247 if (angle % 90 == 0) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002248 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002249 } else {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002250 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002251 }
2252 }
2253}
2254
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002255static void test_circle_mirror_x(skiatest::Reporter* reporter,
2256 const SkPath& path,
2257 SkPath::Direction dir) {
2258 SkPath tmp;
2259 SkMatrix m;
2260 m.reset();
2261 m.setScaleX(-SK_Scalar1);
2262 path.transform(m, &tmp);
2263
2264 if (SkPath::kCW_Direction == dir) {
2265 dir = SkPath::kCCW_Direction;
2266 } else {
2267 SkASSERT(SkPath::kCCW_Direction == dir);
2268 dir = SkPath::kCW_Direction;
2269 }
2270
2271 check_for_circle(reporter, tmp, true, dir);
2272}
2273
2274static void test_circle_mirror_y(skiatest::Reporter* reporter,
2275 const SkPath& path,
2276 SkPath::Direction dir) {
2277 SkPath tmp;
2278 SkMatrix m;
2279 m.reset();
2280 m.setScaleY(-SK_Scalar1);
2281 path.transform(m, &tmp);
2282
2283 if (SkPath::kCW_Direction == dir) {
2284 dir = SkPath::kCCW_Direction;
2285 } else {
2286 SkASSERT(SkPath::kCCW_Direction == dir);
2287 dir = SkPath::kCW_Direction;
2288 }
2289
2290 check_for_circle(reporter, tmp, true, dir);
2291}
2292
2293static void test_circle_mirror_xy(skiatest::Reporter* reporter,
2294 const SkPath& path,
2295 SkPath::Direction dir) {
2296 SkPath tmp;
2297 SkMatrix m;
2298 m.reset();
2299 m.setScaleX(-SK_Scalar1);
2300 m.setScaleY(-SK_Scalar1);
2301 path.transform(m, &tmp);
2302
2303 check_for_circle(reporter, tmp, true, dir);
2304}
2305
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002306static void test_circle_with_direction(skiatest::Reporter* reporter,
2307 SkPath::Direction dir) {
2308 SkPath path;
2309
2310 // circle at origin
2311 path.addCircle(0, 0, SkIntToScalar(20), dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002312 check_for_circle(reporter, path, true, dir);
2313 test_circle_rotate(reporter, path, dir);
2314 test_circle_translate(reporter, path, dir);
2315 test_circle_skew(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002316
2317 // circle at an offset at (10, 10)
2318 path.reset();
2319 path.addCircle(SkIntToScalar(10), SkIntToScalar(10),
2320 SkIntToScalar(20), dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002321 check_for_circle(reporter, path, true, dir);
2322 test_circle_rotate(reporter, path, dir);
2323 test_circle_translate(reporter, path, dir);
2324 test_circle_skew(reporter, path, dir);
2325 test_circle_mirror_x(reporter, path, dir);
2326 test_circle_mirror_y(reporter, path, dir);
2327 test_circle_mirror_xy(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002328}
2329
2330static void test_circle_with_add_paths(skiatest::Reporter* reporter) {
2331 SkPath path;
2332 SkPath circle;
2333 SkPath rect;
2334 SkPath empty;
2335
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002336 static const SkPath::Direction kCircleDir = SkPath::kCW_Direction;
2337 static const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction;
2338
2339 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002340 rect.addRect(SkIntToScalar(5), SkIntToScalar(5),
2341 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction);
2342
2343 SkMatrix translate;
2344 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12));
2345
2346 // For simplicity, all the path concatenation related operations
2347 // would mark it non-circle, though in theory it's still a circle.
2348
2349 // empty + circle (translate)
2350 path = empty;
2351 path.addPath(circle, translate);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002352 check_for_circle(reporter, path, false, kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002353
2354 // circle + empty (translate)
2355 path = circle;
2356 path.addPath(empty, translate);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002357 check_for_circle(reporter, path, false, kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002358
2359 // test reverseAddPath
2360 path = circle;
2361 path.reverseAddPath(rect);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002362 check_for_circle(reporter, path, false, kCircleDirOpposite);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002363}
2364
2365static void test_circle(skiatest::Reporter* reporter) {
2366 test_circle_with_direction(reporter, SkPath::kCW_Direction);
2367 test_circle_with_direction(reporter, SkPath::kCCW_Direction);
2368
2369 // multiple addCircle()
2370 SkPath path;
2371 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2372 path.addCircle(0, 0, SkIntToScalar(20), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002373 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002374
2375 // some extra lineTo() would make isOval() fail
2376 path.reset();
2377 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2378 path.lineTo(0, 0);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002379 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002380
2381 // not back to the original point
2382 path.reset();
2383 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2384 path.setLastPt(SkIntToScalar(5), SkIntToScalar(5));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002385 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002386
2387 test_circle_with_add_paths(reporter);
2388}
2389
2390static void test_oval(skiatest::Reporter* reporter) {
2391 SkRect rect;
2392 SkMatrix m;
2393 SkPath path;
2394
2395 rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50));
2396 path.addOval(rect);
2397
2398 REPORTER_ASSERT(reporter, path.isOval(NULL));
2399
2400 m.setRotate(SkIntToScalar(90));
2401 SkPath tmp;
2402 path.transform(m, &tmp);
2403 // an oval rotated 90 degrees is still an oval.
2404 REPORTER_ASSERT(reporter, tmp.isOval(NULL));
2405
2406 m.reset();
2407 m.setRotate(SkIntToScalar(30));
2408 tmp.reset();
2409 path.transform(m, &tmp);
2410 // an oval rotated 30 degrees is not an oval anymore.
2411 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2412
2413 // since empty path being transformed.
2414 path.reset();
2415 tmp.reset();
2416 m.reset();
2417 path.transform(m, &tmp);
2418 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2419
2420 // empty path is not an oval
2421 tmp.reset();
2422 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2423
2424 // only has moveTo()s
2425 tmp.reset();
2426 tmp.moveTo(0, 0);
2427 tmp.moveTo(SkIntToScalar(10), SkIntToScalar(10));
2428 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2429
2430 // mimic WebKit's calling convention,
2431 // call moveTo() first and then call addOval()
2432 path.reset();
2433 path.moveTo(0, 0);
2434 path.addOval(rect);
2435 REPORTER_ASSERT(reporter, path.isOval(NULL));
2436
2437 // copy path
2438 path.reset();
2439 tmp.reset();
2440 tmp.addOval(rect);
2441 path = tmp;
2442 REPORTER_ASSERT(reporter, path.isOval(NULL));
2443}
2444
bungeman@google.coma5809a32013-06-21 15:13:34 +00002445static void test_empty(skiatest::Reporter* reporter, const SkPath& p) {
2446 SkPath empty;
reed@android.com80e39a72009-04-02 16:59:40 +00002447
reed@android.com3abec1d2009-03-02 05:36:20 +00002448 REPORTER_ASSERT(reporter, p.isEmpty());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002449 REPORTER_ASSERT(reporter, 0 == p.countPoints());
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002450 REPORTER_ASSERT(reporter, 0 == p.countVerbs());
reed@google.com10296cc2011-09-21 12:29:05 +00002451 REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks());
reed@google.comb54455e2011-05-16 14:16:04 +00002452 REPORTER_ASSERT(reporter, p.isConvex());
reed@android.com3abec1d2009-03-02 05:36:20 +00002453 REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType);
2454 REPORTER_ASSERT(reporter, !p.isInverseFillType());
bungeman@google.coma5809a32013-06-21 15:13:34 +00002455 REPORTER_ASSERT(reporter, p == empty);
2456 REPORTER_ASSERT(reporter, !(p != empty));
2457}
2458
2459static void TestPath(skiatest::Reporter* reporter) {
2460 SkTSize<SkScalar>::Make(3,4);
2461
2462 SkPath p, empty;
2463 SkRect bounds, bounds2;
2464 test_empty(reporter, p);
reed@android.com3abec1d2009-03-02 05:36:20 +00002465
reed@android.comd252db02009-04-01 18:31:44 +00002466 REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
reed@android.com80e39a72009-04-02 16:59:40 +00002467
reed@android.com3abec1d2009-03-02 05:36:20 +00002468 bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
reed@android.com6b82d1a2009-06-03 02:35:01 +00002469
reed@android.com6b82d1a2009-06-03 02:35:01 +00002470 p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1);
2471 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00002472 // we have quads or cubics
2473 REPORTER_ASSERT(reporter, p.getSegmentMasks() & kCurveSegmentMask);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002474 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00002475
reed@android.com6b82d1a2009-06-03 02:35:01 +00002476 p.reset();
bungeman@google.coma5809a32013-06-21 15:13:34 +00002477 test_empty(reporter, p);
reed@google.com10296cc2011-09-21 12:29:05 +00002478
reed@android.com6b82d1a2009-06-03 02:35:01 +00002479 p.addOval(bounds);
2480 check_convex_bounds(reporter, p, bounds);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002481 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00002482
bungeman@google.coma5809a32013-06-21 15:13:34 +00002483 p.rewind();
2484 test_empty(reporter, p);
2485
reed@android.com3abec1d2009-03-02 05:36:20 +00002486 p.addRect(bounds);
reed@android.com6b82d1a2009-06-03 02:35:01 +00002487 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00002488 // we have only lines
2489 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == p.getSegmentMasks());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002490 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@android.com3abec1d2009-03-02 05:36:20 +00002491
bungeman@google.coma5809a32013-06-21 15:13:34 +00002492 REPORTER_ASSERT(reporter, p != empty);
2493 REPORTER_ASSERT(reporter, !(p == empty));
reed@android.com3abec1d2009-03-02 05:36:20 +00002494
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002495 // do getPoints and getVerbs return the right result
2496 REPORTER_ASSERT(reporter, p.getPoints(NULL, 0) == 4);
2497 REPORTER_ASSERT(reporter, p.getVerbs(NULL, 0) == 5);
reed@android.com3abec1d2009-03-02 05:36:20 +00002498 SkPoint pts[4];
2499 int count = p.getPoints(pts, 4);
2500 REPORTER_ASSERT(reporter, count == 4);
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002501 uint8_t verbs[6];
2502 verbs[5] = 0xff;
2503 p.getVerbs(verbs, 5);
2504 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == verbs[0]);
2505 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[1]);
2506 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[2]);
2507 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[3]);
2508 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == verbs[4]);
2509 REPORTER_ASSERT(reporter, 0xff == verbs[5]);
reed@android.com3abec1d2009-03-02 05:36:20 +00002510 bounds2.set(pts, 4);
2511 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00002512
reed@android.com3abec1d2009-03-02 05:36:20 +00002513 bounds.offset(SK_Scalar1*3, SK_Scalar1*4);
2514 p.offset(SK_Scalar1*3, SK_Scalar1*4);
reed@android.comd252db02009-04-01 18:31:44 +00002515 REPORTER_ASSERT(reporter, bounds == p.getBounds());
reed@android.com3abec1d2009-03-02 05:36:20 +00002516
reed@android.com3abec1d2009-03-02 05:36:20 +00002517 REPORTER_ASSERT(reporter, p.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00002518 bounds2.setEmpty();
reed@android.com3abec1d2009-03-02 05:36:20 +00002519 REPORTER_ASSERT(reporter, p.isRect(&bounds2));
2520 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00002521
reed@android.com3abec1d2009-03-02 05:36:20 +00002522 // now force p to not be a rect
2523 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2);
2524 p.addRect(bounds);
2525 REPORTER_ASSERT(reporter, !p.isRect(NULL));
reed@android.com3abec1d2009-03-02 05:36:20 +00002526
reed@google.com7e6c4d12012-05-10 14:05:43 +00002527 test_isLine(reporter);
2528 test_isRect(reporter);
caryclark@google.com56f233a2012-11-19 13:06:06 +00002529 test_isNestedRects(reporter);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002530 test_zero_length_paths(reporter);
reed@google.comcabaf1d2012-01-11 21:03:05 +00002531 test_direction(reporter);
reed@google.com04863fa2011-05-15 04:08:24 +00002532 test_convexity(reporter);
reed@google.com7c424812011-05-15 04:38:34 +00002533 test_convexity2(reporter);
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00002534 test_conservativelyContains(reporter);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00002535 test_close(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002536 test_segment_masks(reporter);
reed@google.com53effc52011-09-21 19:05:12 +00002537 test_flattening(reporter);
2538 test_transform(reporter);
reed@google.com3563c9e2011-11-14 19:34:57 +00002539 test_bounds(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002540 test_iter(reporter);
2541 test_raw_iter(reporter);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002542 test_circle(reporter);
2543 test_oval(reporter);
reed@google.com8b06f1a2012-05-29 12:03:46 +00002544 test_strokerec(reporter);
reed@google.com744faba2012-05-29 19:54:52 +00002545 test_addPoly(reporter);
reed@google.com0bb18bb2012-07-26 15:20:36 +00002546 test_isfinite(reporter);
tomhudson@google.comed02c4d2012-08-10 14:10:45 +00002547 test_isfinite_after_transform(reporter);
robertphillips@google.comb95eaa82012-10-18 15:26:12 +00002548 test_arb_round_rect_is_convex(reporter);
robertphillips@google.com158618e2012-10-23 16:56:56 +00002549 test_arb_zero_rad_round_rect_is_rect(reporter);
reed@google.coma8790de2012-10-24 21:04:04 +00002550 test_addrect_isfinite(reporter);
sugoi@google.com54f0d1b2013-02-27 19:17:41 +00002551 test_tricky_cubic();
2552 test_clipped_cubic();
2553 test_crbug_170666();
reed@google.com7a90daf2013-04-10 18:44:00 +00002554 test_bad_cubic_crbug229478();
reed@google.com3eff3592013-05-08 21:08:21 +00002555 test_bad_cubic_crbug234190();
mtklein@google.com9c9d4a72013-08-07 19:17:53 +00002556 test_android_specific_behavior(reporter);
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +00002557 test_path_close_issue1474(reporter);
reed@android.com3abec1d2009-03-02 05:36:20 +00002558}
2559
2560#include "TestClassDef.h"
2561DEFINE_TESTCLASS("Path", PathTestClass, TestPath)