blob: 3aa24c3a11503fa3d8586cc7137d6ac378720047 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
reed@google.comcc8be772013-10-15 15:35:29 +00007
reed@android.com3abec1d2009-03-02 05:36:20 +00008#include "Test.h"
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
reed@google.comcc8be772013-10-15 15:35:29 +000022static void make_path0(SkPath* path) {
23 // from * https://code.google.com/p/skia/issues/detail?id=1706
24
25 path->moveTo(146.939f, 1012.84f);
26 path->lineTo(181.747f, 1009.18f);
27 path->lineTo(182.165f, 1013.16f);
28 path->lineTo(147.357f, 1016.82f);
29 path->lineTo(146.939f, 1012.84f);
30 path->close();
31}
32
33static void make_path1(SkPath* path) {
34 path->addRect(SkRect::MakeXYWH(10, 10, 10, 1));
35}
36
37typedef void (*PathProc)(SkPath*);
38
39/*
40 * Regression test: we used to crash (overwrite internal storage) during
41 * construction of the region when the path was INVERSE. That is now fixed,
42 * so test these regions (which used to assert/crash).
43 *
44 * https://code.google.com/p/skia/issues/detail?id=1706
45 */
46static void test_path_to_region(skiatest::Reporter* reporter) {
47 PathProc procs[] = {
48 make_path0,
49 make_path1,
50 };
51
52 SkRegion clip;
53 clip.setRect(0, 0, 1255, 1925);
54
55 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
56 SkPath path;
57 procs[i](&path);
58
59 SkRegion rgn;
60 rgn.setPath(path, clip);
61 path.toggleInverseFillType();
62 rgn.setPath(path, clip);
63 }
64}
65
caryclark@google.com56f233a2012-11-19 13:06:06 +000066#if defined(WIN32)
67 #define SUPPRESS_VISIBILITY_WARNING
68#else
69 #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
70#endif
71
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +000072static void test_path_close_issue1474(skiatest::Reporter* reporter) {
73 // This test checks that r{Line,Quad,Conic,Cubic}To following a close()
74 // are relative to the point we close to, not relative to the point we close from.
75 SkPath path;
76 SkPoint last;
77
78 // Test rLineTo().
79 path.rLineTo(0, 100);
80 path.rLineTo(100, 0);
81 path.close(); // Returns us back to 0,0.
82 path.rLineTo(50, 50); // This should go to 50,50.
83
84 path.getLastPt(&last);
85 REPORTER_ASSERT(reporter, 50 == last.fX);
86 REPORTER_ASSERT(reporter, 50 == last.fY);
87
88 // Test rQuadTo().
89 path.rewind();
90 path.rLineTo(0, 100);
91 path.rLineTo(100, 0);
92 path.close();
93 path.rQuadTo(50, 50, 75, 75);
94
95 path.getLastPt(&last);
96 REPORTER_ASSERT(reporter, 75 == last.fX);
97 REPORTER_ASSERT(reporter, 75 == last.fY);
98
99 // Test rConicTo().
100 path.rewind();
101 path.rLineTo(0, 100);
102 path.rLineTo(100, 0);
103 path.close();
104 path.rConicTo(50, 50, 85, 85, 2);
105
106 path.getLastPt(&last);
107 REPORTER_ASSERT(reporter, 85 == last.fX);
108 REPORTER_ASSERT(reporter, 85 == last.fY);
109
110 // Test rCubicTo().
111 path.rewind();
112 path.rLineTo(0, 100);
113 path.rLineTo(100, 0);
114 path.close();
115 path.rCubicTo(50, 50, 85, 85, 95, 95);
116
117 path.getLastPt(&last);
118 REPORTER_ASSERT(reporter, 95 == last.fX);
119 REPORTER_ASSERT(reporter, 95 == last.fY);
120}
121
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000122static void test_android_specific_behavior(skiatest::Reporter* reporter) {
123#ifdef SK_BUILD_FOR_ANDROID
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000124 // Make sure we treat fGenerationID and fSourcePath correctly for each of
125 // copy, assign, rewind, reset, and swap.
126 SkPath original, source, anotherSource;
127 original.setSourcePath(&source);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000128 original.moveTo(0, 0);
129 original.lineTo(1, 1);
130 REPORTER_ASSERT(reporter, original.getGenerationID() > 0);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000131 REPORTER_ASSERT(reporter, original.getSourcePath() == &source);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000132
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000133 uint32_t copyID, assignID;
134
135 // Test copy constructor. Copy generation ID, copy source path.
136 SkPath copy(original);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000137 REPORTER_ASSERT(reporter, copy.getGenerationID() == original.getGenerationID());
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000138 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath());
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000139
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000140 // Test assigment operator. Increment generation ID, copy source path.
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000141 SkPath assign;
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000142 assignID = assign.getGenerationID();
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000143 assign = original;
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000144 REPORTER_ASSERT(reporter, assign.getGenerationID() > assignID);
145 REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath());
146
147 // Test rewind. Increment generation ID, don't touch source path.
148 copyID = copy.getGenerationID();
149 copy.rewind();
150 REPORTER_ASSERT(reporter, copy.getGenerationID() > copyID);
151 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath());
152
153 // Test reset. Increment generation ID, don't touch source path.
154 assignID = assign.getGenerationID();
155 assign.reset();
156 REPORTER_ASSERT(reporter, assign.getGenerationID() > assignID);
157 REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath());
158
159 // Test swap. Increment both generation IDs, swap source paths.
160 copy.setSourcePath(&anotherSource);
161 copyID = copy.getGenerationID();
162 assignID = assign.getGenerationID();
163 copy.swap(assign);
164 REPORTER_ASSERT(reporter, copy.getGenerationID() > copyID);
165 REPORTER_ASSERT(reporter, assign.getGenerationID() > assignID);
166 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath());
167 REPORTER_ASSERT(reporter, assign.getSourcePath() == &anotherSource);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000168#endif
169}
170
reed@google.com3eff3592013-05-08 21:08:21 +0000171// This used to assert in the debug build, as the edges did not all line-up.
172static void test_bad_cubic_crbug234190() {
173 SkPath path;
174 path.moveTo(13.8509f, 3.16858f);
175 path.cubicTo(-2.35893e+08f, -4.21044e+08f,
176 -2.38991e+08f, -4.26573e+08f,
177 -2.41016e+08f, -4.30188e+08f);
178
179 SkPaint paint;
180 paint.setAntiAlias(true);
reed@google.comd28ba802013-09-20 19:33:52 +0000181 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(84, 88));
reed@google.com3eff3592013-05-08 21:08:21 +0000182 surface->getCanvas()->drawPath(path, paint);
183}
184
reed@google.com7a90daf2013-04-10 18:44:00 +0000185static void test_bad_cubic_crbug229478() {
186 const SkPoint pts[] = {
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000187 { 4595.91064f, -11596.9873f },
188 { 4597.2168f, -11595.9414f },
189 { 4598.52344f, -11594.8955f },
190 { 4599.83008f, -11593.8496f },
reed@google.com7a90daf2013-04-10 18:44:00 +0000191 };
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000192
reed@google.com7a90daf2013-04-10 18:44:00 +0000193 SkPath path;
194 path.moveTo(pts[0]);
195 path.cubicTo(pts[1], pts[2], pts[3]);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000196
reed@google.com7a90daf2013-04-10 18:44:00 +0000197 SkPaint paint;
198 paint.setStyle(SkPaint::kStroke_Style);
199 paint.setStrokeWidth(20);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000200
reed@google.com7a90daf2013-04-10 18:44:00 +0000201 SkPath dst;
202 // Before the fix, this would infinite-recurse, and run out of stack
203 // because we would keep trying to subdivide a degenerate cubic segment.
204 paint.getFillPath(path, &dst, NULL);
205}
206
reed@google.com64d62952013-01-18 17:49:28 +0000207static void build_path_170666(SkPath& path) {
208 path.moveTo(17.9459f, 21.6344f);
209 path.lineTo(139.545f, -47.8105f);
210 path.lineTo(139.545f, -47.8105f);
211 path.lineTo(131.07f, -47.3888f);
212 path.lineTo(131.07f, -47.3888f);
213 path.lineTo(122.586f, -46.9532f);
214 path.lineTo(122.586f, -46.9532f);
215 path.lineTo(18076.6f, 31390.9f);
216 path.lineTo(18076.6f, 31390.9f);
217 path.lineTo(18085.1f, 31390.5f);
218 path.lineTo(18085.1f, 31390.5f);
219 path.lineTo(18076.6f, 31390.9f);
220 path.lineTo(18076.6f, 31390.9f);
221 path.lineTo(17955, 31460.3f);
222 path.lineTo(17955, 31460.3f);
223 path.lineTo(17963.5f, 31459.9f);
224 path.lineTo(17963.5f, 31459.9f);
225 path.lineTo(17971.9f, 31459.5f);
226 path.lineTo(17971.9f, 31459.5f);
227 path.lineTo(17.9551f, 21.6205f);
228 path.lineTo(17.9551f, 21.6205f);
229 path.lineTo(9.47091f, 22.0561f);
230 path.lineTo(9.47091f, 22.0561f);
231 path.lineTo(17.9459f, 21.6344f);
232 path.lineTo(17.9459f, 21.6344f);
233 path.close();path.moveTo(0.995934f, 22.4779f);
234 path.lineTo(0.986725f, 22.4918f);
235 path.lineTo(0.986725f, 22.4918f);
236 path.lineTo(17955, 31460.4f);
237 path.lineTo(17955, 31460.4f);
238 path.lineTo(17971.9f, 31459.5f);
239 path.lineTo(17971.9f, 31459.5f);
240 path.lineTo(18093.6f, 31390.1f);
241 path.lineTo(18093.6f, 31390.1f);
242 path.lineTo(18093.6f, 31390);
243 path.lineTo(18093.6f, 31390);
244 path.lineTo(139.555f, -47.8244f);
245 path.lineTo(139.555f, -47.8244f);
246 path.lineTo(122.595f, -46.9671f);
247 path.lineTo(122.595f, -46.9671f);
248 path.lineTo(0.995934f, 22.4779f);
249 path.lineTo(0.995934f, 22.4779f);
250 path.close();
251 path.moveTo(5.43941f, 25.5223f);
252 path.lineTo(798267, -28871.1f);
253 path.lineTo(798267, -28871.1f);
254 path.lineTo(3.12512e+06f, -113102);
255 path.lineTo(3.12512e+06f, -113102);
256 path.cubicTo(5.16324e+06f, -186882, 8.15247e+06f, -295092, 1.1957e+07f, -432813);
257 path.cubicTo(1.95659e+07f, -708257, 3.04359e+07f, -1.10175e+06f, 4.34798e+07f, -1.57394e+06f);
258 path.cubicTo(6.95677e+07f, -2.51831e+06f, 1.04352e+08f, -3.77748e+06f, 1.39135e+08f, -5.03666e+06f);
259 path.cubicTo(1.73919e+08f, -6.29583e+06f, 2.08703e+08f, -7.555e+06f, 2.34791e+08f, -8.49938e+06f);
260 path.cubicTo(2.47835e+08f, -8.97157e+06f, 2.58705e+08f, -9.36506e+06f, 2.66314e+08f, -9.6405e+06f);
261 path.cubicTo(2.70118e+08f, -9.77823e+06f, 2.73108e+08f, -9.88644e+06f, 2.75146e+08f, -9.96022e+06f);
262 path.cubicTo(2.76165e+08f, -9.99711e+06f, 2.76946e+08f, -1.00254e+07f, 2.77473e+08f, -1.00444e+07f);
263 path.lineTo(2.78271e+08f, -1.00733e+07f);
264 path.lineTo(2.78271e+08f, -1.00733e+07f);
265 path.cubicTo(2.78271e+08f, -1.00733e+07f, 2.08703e+08f, -7.555e+06f, 135.238f, 23.3517f);
266 path.cubicTo(131.191f, 23.4981f, 125.995f, 23.7976f, 123.631f, 24.0206f);
267 path.cubicTo(121.267f, 24.2436f, 122.631f, 24.3056f, 126.677f, 24.1591f);
268 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
269 path.lineTo(2.77473e+08f, -1.00444e+07f);
270 path.lineTo(2.77473e+08f, -1.00444e+07f);
271 path.cubicTo(2.76946e+08f, -1.00254e+07f, 2.76165e+08f, -9.99711e+06f, 2.75146e+08f, -9.96022e+06f);
272 path.cubicTo(2.73108e+08f, -9.88644e+06f, 2.70118e+08f, -9.77823e+06f, 2.66314e+08f, -9.6405e+06f);
273 path.cubicTo(2.58705e+08f, -9.36506e+06f, 2.47835e+08f, -8.97157e+06f, 2.34791e+08f, -8.49938e+06f);
274 path.cubicTo(2.08703e+08f, -7.555e+06f, 1.73919e+08f, -6.29583e+06f, 1.39135e+08f, -5.03666e+06f);
275 path.cubicTo(1.04352e+08f, -3.77749e+06f, 6.95677e+07f, -2.51831e+06f, 4.34798e+07f, -1.57394e+06f);
276 path.cubicTo(3.04359e+07f, -1.10175e+06f, 1.95659e+07f, -708258, 1.1957e+07f, -432814);
277 path.cubicTo(8.15248e+06f, -295092, 5.16324e+06f, -186883, 3.12513e+06f, -113103);
278 path.lineTo(798284, -28872);
279 path.lineTo(798284, -28872);
280 path.lineTo(22.4044f, 24.6677f);
281 path.lineTo(22.4044f, 24.6677f);
282 path.cubicTo(22.5186f, 24.5432f, 18.8134f, 24.6337f, 14.1287f, 24.8697f);
283 path.cubicTo(9.4439f, 25.1057f, 5.55359f, 25.3978f, 5.43941f, 25.5223f);
284 path.close();
285}
286
287static void build_path_simple_170666(SkPath& path) {
288 path.moveTo(126.677f, 24.1591f);
289 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
290}
291
292// This used to assert in the SK_DEBUG build, as the clip step would fail with
293// too-few interations in our cubic-line intersection code. That code now runs
294// 24 interations (instead of 16).
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000295static void test_crbug_170666() {
reed@google.com64d62952013-01-18 17:49:28 +0000296 SkPath path;
297 SkPaint paint;
298 paint.setAntiAlias(true);
299
reed@google.comd28ba802013-09-20 19:33:52 +0000300 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(1000, 1000));
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000301
reed@google.com64d62952013-01-18 17:49:28 +0000302 build_path_simple_170666(path);
303 surface->getCanvas()->drawPath(path, paint);
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000304
reed@google.com64d62952013-01-18 17:49:28 +0000305 build_path_170666(path);
306 surface->getCanvas()->drawPath(path, paint);
307}
308
reed@google.coma8790de2012-10-24 21:04:04 +0000309// Make sure we stay non-finite once we get there (unless we reset or rewind).
310static void test_addrect_isfinite(skiatest::Reporter* reporter) {
311 SkPath path;
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000312
reed@google.coma8790de2012-10-24 21:04:04 +0000313 path.addRect(SkRect::MakeWH(50, 100));
314 REPORTER_ASSERT(reporter, path.isFinite());
315
316 path.moveTo(0, 0);
317 path.lineTo(SK_ScalarInfinity, 42);
318 REPORTER_ASSERT(reporter, !path.isFinite());
319
320 path.addRect(SkRect::MakeWH(50, 100));
321 REPORTER_ASSERT(reporter, !path.isFinite());
322
323 path.reset();
324 REPORTER_ASSERT(reporter, path.isFinite());
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000325
reed@google.coma8790de2012-10-24 21:04:04 +0000326 path.addRect(SkRect::MakeWH(50, 100));
327 REPORTER_ASSERT(reporter, path.isFinite());
328}
329
reed@google.com848148e2013-01-15 15:51:59 +0000330static void build_big_path(SkPath* path, bool reducedCase) {
331 if (reducedCase) {
332 path->moveTo(577330, 1971.72f);
333 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
334 } else {
335 path->moveTo(60.1631f, 7.70567f);
336 path->quadTo(60.1631f, 7.70567f, 0.99474f, 0.901199f);
337 path->lineTo(577379, 1977.77f);
338 path->quadTo(577364, 1979.57f, 577325, 1980.26f);
339 path->quadTo(577286, 1980.95f, 577245, 1980.13f);
340 path->quadTo(577205, 1979.3f, 577187, 1977.45f);
341 path->quadTo(577168, 1975.6f, 577183, 1973.8f);
342 path->quadTo(577198, 1972, 577238, 1971.31f);
343 path->quadTo(577277, 1970.62f, 577317, 1971.45f);
344 path->quadTo(577330, 1971.72f, 577341, 1972.11f);
345 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
346 path->moveTo(306.718f, -32.912f);
347 path->cubicTo(30.531f, 10.0005f, 1502.47f, 13.2804f, 84.3088f, 9.99601f);
348 }
349}
350
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000351static void test_clipped_cubic() {
reed@google.comd28ba802013-09-20 19:33:52 +0000352 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(640, 480));
reed@google.com848148e2013-01-15 15:51:59 +0000353
354 // This path used to assert, because our cubic-chopping code incorrectly
355 // moved control points after the chop. This test should be run in SK_DEBUG
356 // mode to ensure that we no long assert.
357 SkPath path;
358 for (int doReducedCase = 0; doReducedCase <= 1; ++doReducedCase) {
359 build_big_path(&path, SkToBool(doReducedCase));
skia.committer@gmail.comff21c2e2013-01-16 07:05:56 +0000360
reed@google.com848148e2013-01-15 15:51:59 +0000361 SkPaint paint;
362 for (int doAA = 0; doAA <= 1; ++doAA) {
363 paint.setAntiAlias(SkToBool(doAA));
364 surface->getCanvas()->drawPath(path, paint);
365 }
366 }
367}
368
reed@google.com8cae8352012-09-14 15:18:41 +0000369// Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/
370// which triggered an assert, from a tricky cubic. This test replicates that
371// example, so we can ensure that we handle it (in SkEdge.cpp), and don't
372// assert in the SK_DEBUG build.
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000373static void test_tricky_cubic() {
reed@google.com8cae8352012-09-14 15:18:41 +0000374 const SkPoint pts[] = {
skia.committer@gmail.com055c7c22012-09-15 02:01:41 +0000375 { SkDoubleToScalar(18.8943768), SkDoubleToScalar(129.121277) },
376 { SkDoubleToScalar(18.8937435), SkDoubleToScalar(129.121689) },
377 { SkDoubleToScalar(18.8950119), SkDoubleToScalar(129.120422) },
378 { SkDoubleToScalar(18.5030727), SkDoubleToScalar(129.13121) },
reed@google.com8cae8352012-09-14 15:18:41 +0000379 };
380
381 SkPath path;
382 path.moveTo(pts[0]);
383 path.cubicTo(pts[1], pts[2], pts[3]);
384
385 SkPaint paint;
386 paint.setAntiAlias(true);
387
reed@google.comd28ba802013-09-20 19:33:52 +0000388 SkSurface* surface = SkSurface::NewRasterPMColor(19, 130);
reed@google.com8cae8352012-09-14 15:18:41 +0000389 surface->getCanvas()->drawPath(path, paint);
390 surface->unref();
391}
reed@android.com3abec1d2009-03-02 05:36:20 +0000392
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000393// Inspired by http://code.google.com/p/chromium/issues/detail?id=141651
394//
395static void test_isfinite_after_transform(skiatest::Reporter* reporter) {
396 SkPath path;
397 path.quadTo(157, 366, 286, 208);
398 path.arcTo(37, 442, 315, 163, 957494590897113.0f);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000399
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000400 SkMatrix matrix;
401 matrix.setScale(1000*1000, 1000*1000);
402
403 // Be sure that path::transform correctly updates isFinite and the bounds
404 // if the transformation overflows. The previous bug was that isFinite was
405 // set to true in this case, but the bounds were not set to empty (which
406 // they should be).
407 while (path.isFinite()) {
408 REPORTER_ASSERT(reporter, path.getBounds().isFinite());
409 REPORTER_ASSERT(reporter, !path.getBounds().isEmpty());
410 path.transform(matrix);
411 }
412 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
413
414 matrix.setTranslate(SK_Scalar1, SK_Scalar1);
415 path.transform(matrix);
416 // we need to still be non-finite
417 REPORTER_ASSERT(reporter, !path.isFinite());
418 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
419}
420
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000421static void add_corner_arc(SkPath* path, const SkRect& rect,
422 SkScalar xIn, SkScalar yIn,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000423 int startAngle)
424{
425
426 SkScalar rx = SkMinScalar(rect.width(), xIn);
427 SkScalar ry = SkMinScalar(rect.height(), yIn);
428
429 SkRect arcRect;
430 arcRect.set(-rx, -ry, rx, ry);
431 switch (startAngle) {
432 case 0:
433 arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom);
434 break;
435 case 90:
436 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom);
437 break;
438 case 180:
439 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop);
440 break;
441 case 270:
442 arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop);
443 break;
444 default:
445 break;
446 }
447
448 path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false);
449}
450
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000451static void make_arb_round_rect(SkPath* path, const SkRect& r,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000452 SkScalar xCorner, SkScalar yCorner) {
453 // we are lazy here and use the same x & y for each corner
454 add_corner_arc(path, r, xCorner, yCorner, 270);
455 add_corner_arc(path, r, xCorner, yCorner, 0);
456 add_corner_arc(path, r, xCorner, yCorner, 90);
457 add_corner_arc(path, r, xCorner, yCorner, 180);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000458 path->close();
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000459}
460
461// Chrome creates its own round rects with each corner possibly being different.
462// Performance will suffer if they are not convex.
463// Note: PathBench::ArbRoundRectBench performs almost exactly
464// the same test (but with drawing)
465static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000466 SkRandom rand;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000467 SkRect r;
468
469 for (int i = 0; i < 5000; ++i) {
470
robertphillips@google.com158618e2012-10-23 16:56:56 +0000471 SkScalar size = rand.nextUScalar1() * 30;
472 if (size < SK_Scalar1) {
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000473 continue;
474 }
475 r.fLeft = rand.nextUScalar1() * 300;
476 r.fTop = rand.nextUScalar1() * 300;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000477 r.fRight = r.fLeft + 2 * size;
478 r.fBottom = r.fTop + 2 * size;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000479
480 SkPath temp;
481
482 make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
483
484 REPORTER_ASSERT(reporter, temp.isConvex());
485 }
486}
487
robertphillips@google.com158618e2012-10-23 16:56:56 +0000488// Chrome will sometimes create a 0 radius round rect. The degenerate
489// quads prevent the path from being converted to a rect
490// Note: PathBench::ArbRoundRectBench performs almost exactly
491// the same test (but with drawing)
492static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000493 SkRandom rand;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000494 SkRect r;
495
496 for (int i = 0; i < 5000; ++i) {
497
498 SkScalar size = rand.nextUScalar1() * 30;
499 if (size < SK_Scalar1) {
500 continue;
501 }
502 r.fLeft = rand.nextUScalar1() * 300;
503 r.fTop = rand.nextUScalar1() * 300;
504 r.fRight = r.fLeft + 2 * size;
505 r.fBottom = r.fTop + 2 * size;
506
507 SkPath temp;
508
509 make_arb_round_rect(&temp, r, 0, 0);
510
robertphillips@google.com158618e2012-10-23 16:56:56 +0000511 SkRect result;
512 REPORTER_ASSERT(reporter, temp.isRect(&result));
513 REPORTER_ASSERT(reporter, r == result);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000514 }
515}
516
reed@google.com0bb18bb2012-07-26 15:20:36 +0000517static void test_rect_isfinite(skiatest::Reporter* reporter) {
518 const SkScalar inf = SK_ScalarInfinity;
caryclark@google.com7abfa492013-04-12 11:59:41 +0000519 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000520 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000521
reed@google.com0bb18bb2012-07-26 15:20:36 +0000522 SkRect r;
523 r.setEmpty();
524 REPORTER_ASSERT(reporter, r.isFinite());
caryclark@google.com7abfa492013-04-12 11:59:41 +0000525 r.set(0, 0, inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000526 REPORTER_ASSERT(reporter, !r.isFinite());
527 r.set(0, 0, nan, 0);
528 REPORTER_ASSERT(reporter, !r.isFinite());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000529
reed@google.com0bb18bb2012-07-26 15:20:36 +0000530 SkPoint pts[] = {
531 { 0, 0 },
532 { SK_Scalar1, 0 },
533 { 0, SK_Scalar1 },
534 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000535
reed@google.com0bb18bb2012-07-26 15:20:36 +0000536 bool isFine = r.setBoundsCheck(pts, 3);
537 REPORTER_ASSERT(reporter, isFine);
538 REPORTER_ASSERT(reporter, !r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000539
reed@google.com0bb18bb2012-07-26 15:20:36 +0000540 pts[1].set(inf, 0);
541 isFine = r.setBoundsCheck(pts, 3);
542 REPORTER_ASSERT(reporter, !isFine);
543 REPORTER_ASSERT(reporter, r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000544
reed@google.com0bb18bb2012-07-26 15:20:36 +0000545 pts[1].set(nan, 0);
546 isFine = r.setBoundsCheck(pts, 3);
547 REPORTER_ASSERT(reporter, !isFine);
548 REPORTER_ASSERT(reporter, r.isEmpty());
549}
550
551static void test_path_isfinite(skiatest::Reporter* reporter) {
552 const SkScalar inf = SK_ScalarInfinity;
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000553 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000554 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000555
reed@google.com0bb18bb2012-07-26 15:20:36 +0000556 SkPath path;
557 REPORTER_ASSERT(reporter, path.isFinite());
558
559 path.reset();
560 REPORTER_ASSERT(reporter, path.isFinite());
561
562 path.reset();
563 path.moveTo(SK_Scalar1, 0);
564 REPORTER_ASSERT(reporter, path.isFinite());
565
566 path.reset();
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000567 path.moveTo(inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000568 REPORTER_ASSERT(reporter, !path.isFinite());
569
570 path.reset();
571 path.moveTo(nan, 0);
572 REPORTER_ASSERT(reporter, !path.isFinite());
573}
574
575static void test_isfinite(skiatest::Reporter* reporter) {
576 test_rect_isfinite(reporter);
577 test_path_isfinite(reporter);
578}
579
reed@google.com744faba2012-05-29 19:54:52 +0000580// assert that we always
581// start with a moveTo
582// only have 1 moveTo
583// only have Lines after that
584// end with a single close
585// only have (at most) 1 close
586//
587static void test_poly(skiatest::Reporter* reporter, const SkPath& path,
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000588 const SkPoint srcPts[], bool expectClose) {
reed@google.com744faba2012-05-29 19:54:52 +0000589 SkPath::RawIter iter(path);
590 SkPoint pts[4];
reed@google.com744faba2012-05-29 19:54:52 +0000591
592 bool firstTime = true;
593 bool foundClose = false;
594 for (;;) {
595 switch (iter.next(pts)) {
596 case SkPath::kMove_Verb:
597 REPORTER_ASSERT(reporter, firstTime);
598 REPORTER_ASSERT(reporter, pts[0] == srcPts[0]);
599 srcPts++;
600 firstTime = false;
601 break;
602 case SkPath::kLine_Verb:
603 REPORTER_ASSERT(reporter, !firstTime);
604 REPORTER_ASSERT(reporter, pts[1] == srcPts[0]);
605 srcPts++;
606 break;
607 case SkPath::kQuad_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000608 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected quad verb");
reed@google.com744faba2012-05-29 19:54:52 +0000609 break;
reed@google.com277c3f82013-05-31 15:17:50 +0000610 case SkPath::kConic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000611 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected conic verb");
reed@google.com277c3f82013-05-31 15:17:50 +0000612 break;
reed@google.com744faba2012-05-29 19:54:52 +0000613 case SkPath::kCubic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000614 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected cubic verb");
reed@google.com744faba2012-05-29 19:54:52 +0000615 break;
616 case SkPath::kClose_Verb:
617 REPORTER_ASSERT(reporter, !firstTime);
618 REPORTER_ASSERT(reporter, !foundClose);
619 REPORTER_ASSERT(reporter, expectClose);
620 foundClose = true;
621 break;
622 case SkPath::kDone_Verb:
623 goto DONE;
624 }
625 }
626DONE:
627 REPORTER_ASSERT(reporter, foundClose == expectClose);
628}
629
630static void test_addPoly(skiatest::Reporter* reporter) {
631 SkPoint pts[32];
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000632 SkRandom rand;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000633
reed@google.com744faba2012-05-29 19:54:52 +0000634 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
635 pts[i].fX = rand.nextSScalar1();
636 pts[i].fY = rand.nextSScalar1();
637 }
638
639 for (int doClose = 0; doClose <= 1; ++doClose) {
640 for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) {
641 SkPath path;
642 path.addPoly(pts, count, SkToBool(doClose));
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000643 test_poly(reporter, path, pts, SkToBool(doClose));
reed@google.com744faba2012-05-29 19:54:52 +0000644 }
645 }
646}
647
reed@google.com8b06f1a2012-05-29 12:03:46 +0000648static void test_strokerec(skiatest::Reporter* reporter) {
649 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
650 REPORTER_ASSERT(reporter, rec.isFillStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000651
reed@google.com8b06f1a2012-05-29 12:03:46 +0000652 rec.setHairlineStyle();
653 REPORTER_ASSERT(reporter, rec.isHairlineStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000654
reed@google.com8b06f1a2012-05-29 12:03:46 +0000655 rec.setStrokeStyle(SK_Scalar1, false);
656 REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000657
reed@google.com8b06f1a2012-05-29 12:03:46 +0000658 rec.setStrokeStyle(SK_Scalar1, true);
659 REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000660
reed@google.com8b06f1a2012-05-29 12:03:46 +0000661 rec.setStrokeStyle(0, false);
662 REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000663
reed@google.com8b06f1a2012-05-29 12:03:46 +0000664 rec.setStrokeStyle(0, true);
665 REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle());
666}
667
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000668// Set this for paths that don't have a consistent direction such as a bowtie.
669// (cheapComputeDirection is not expected to catch these.)
670static const SkPath::Direction kDontCheckDir = static_cast<SkPath::Direction>(-1);
671
672static void check_direction(skiatest::Reporter* reporter, const SkPath& path,
673 SkPath::Direction expected) {
674 if (expected == kDontCheckDir) {
675 return;
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000676 }
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000677 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
678
679 SkPath::Direction dir;
680 if (copy.cheapComputeDirection(&dir)) {
681 REPORTER_ASSERT(reporter, dir == expected);
682 } else {
683 REPORTER_ASSERT(reporter, SkPath::kUnknown_Direction == expected);
684 }
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000685}
686
reed@google.com3e71a882012-01-10 18:44:37 +0000687static void test_direction(skiatest::Reporter* reporter) {
688 size_t i;
689 SkPath path;
690 REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
691 REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCW_Direction));
692 REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCCW_Direction));
reed@google.coma8a3b3d2012-11-26 18:16:27 +0000693 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kUnknown_Direction));
reed@google.com3e71a882012-01-10 18:44:37 +0000694
695 static const char* gDegen[] = {
696 "M 10 10",
697 "M 10 10 M 20 20",
698 "M 10 10 L 20 20",
699 "M 10 10 L 10 10 L 10 10",
700 "M 10 10 Q 10 10 10 10",
701 "M 10 10 C 10 10 10 10 10 10",
702 };
703 for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) {
704 path.reset();
705 bool valid = SkParsePath::FromSVGString(gDegen[i], &path);
706 REPORTER_ASSERT(reporter, valid);
707 REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
708 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000709
reed@google.com3e71a882012-01-10 18:44:37 +0000710 static const char* gCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000711 "M 10 10 L 10 10 Q 20 10 20 20",
reed@google.com3e71a882012-01-10 18:44:37 +0000712 "M 10 10 C 20 10 20 20 20 20",
reed@google.comd4146662012-01-31 15:42:29 +0000713 "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 +0000714 // rect with top two corners replaced by cubics with identical middle
715 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000716 "M 10 10 C 10 0 10 0 20 0 L 40 0 C 50 0 50 0 50 10",
717 "M 20 10 L 0 10 Q 10 10 20 0", // left, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000718 };
719 for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) {
720 path.reset();
721 bool valid = SkParsePath::FromSVGString(gCW[i], &path);
722 REPORTER_ASSERT(reporter, valid);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000723 check_direction(reporter, path, SkPath::kCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000724 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000725
reed@google.com3e71a882012-01-10 18:44:37 +0000726 static const char* gCCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000727 "M 10 10 L 10 10 Q 20 10 20 -20",
reed@google.com3e71a882012-01-10 18:44:37 +0000728 "M 10 10 C 20 10 20 -20 20 -20",
reed@google.comd4146662012-01-31 15:42:29 +0000729 "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 +0000730 // rect with top two corners replaced by cubics with identical middle
731 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000732 "M 50 10 C 50 0 50 0 40 0 L 20 0 C 10 0 10 0 10 10",
733 "M 10 10 L 30 10 Q 20 10 10 0", // right, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000734 };
735 for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) {
736 path.reset();
737 bool valid = SkParsePath::FromSVGString(gCCW[i], &path);
738 REPORTER_ASSERT(reporter, valid);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000739 check_direction(reporter, path, SkPath::kCCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000740 }
reed@google.comac8543f2012-01-30 20:51:25 +0000741
742 // Test two donuts, each wound a different direction. Only the outer contour
743 // determines the cheap direction
744 path.reset();
745 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCW_Direction);
746 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000747 check_direction(reporter, path, SkPath::kCW_Direction);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000748
reed@google.comac8543f2012-01-30 20:51:25 +0000749 path.reset();
750 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCW_Direction);
751 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000752 check_direction(reporter, path, SkPath::kCCW_Direction);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000753
bsalomon@google.com6843ac42012-02-17 13:49:03 +0000754#ifdef SK_SCALAR_IS_FLOAT
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000755 // triangle with one point really far from the origin.
756 path.reset();
757 // the first point is roughly 1.05e10, 1.05e10
bsalomon@google.com53aab782012-02-23 14:54:49 +0000758 path.moveTo(SkFloatToScalar(SkBits2Float(0x501c7652)), SkFloatToScalar(SkBits2Float(0x501c7652)));
759 path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1);
760 path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000761 check_direction(reporter, path, SkPath::kCCW_Direction);
bsalomon@google.com53aab782012-02-23 14:54:49 +0000762#endif
reed@google.com3e71a882012-01-10 18:44:37 +0000763}
764
reed@google.comffdb0182011-11-14 19:29:14 +0000765static void add_rect(SkPath* path, const SkRect& r) {
766 path->moveTo(r.fLeft, r.fTop);
767 path->lineTo(r.fRight, r.fTop);
768 path->lineTo(r.fRight, r.fBottom);
769 path->lineTo(r.fLeft, r.fBottom);
770 path->close();
771}
772
773static void test_bounds(skiatest::Reporter* reporter) {
774 static const SkRect rects[] = {
reed@google.com3563c9e2011-11-14 19:34:57 +0000775 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) },
776 { SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) },
777 { SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) },
778 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) },
reed@google.comffdb0182011-11-14 19:29:14 +0000779 };
780
781 SkPath path0, path1;
782 for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) {
783 path0.addRect(rects[i]);
784 add_rect(&path1, rects[i]);
785 }
786
787 REPORTER_ASSERT(reporter, path0.getBounds() == path1.getBounds());
788}
789
reed@google.com55b5f4b2011-09-07 12:23:41 +0000790static void stroke_cubic(const SkPoint pts[4]) {
791 SkPath path;
792 path.moveTo(pts[0]);
793 path.cubicTo(pts[1], pts[2], pts[3]);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000794
reed@google.com55b5f4b2011-09-07 12:23:41 +0000795 SkPaint paint;
796 paint.setStyle(SkPaint::kStroke_Style);
797 paint.setStrokeWidth(SK_Scalar1 * 2);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000798
reed@google.com55b5f4b2011-09-07 12:23:41 +0000799 SkPath fill;
800 paint.getFillPath(path, &fill);
801}
802
803// just ensure this can run w/o any SkASSERTS firing in the debug build
804// we used to assert due to differences in how we determine a degenerate vector
805// but that was fixed with the introduction of SkPoint::CanNormalize
806static void stroke_tiny_cubic() {
807 SkPoint p0[] = {
808 { 372.0f, 92.0f },
809 { 372.0f, 92.0f },
810 { 372.0f, 92.0f },
811 { 372.0f, 92.0f },
812 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000813
reed@google.com55b5f4b2011-09-07 12:23:41 +0000814 stroke_cubic(p0);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000815
reed@google.com55b5f4b2011-09-07 12:23:41 +0000816 SkPoint p1[] = {
817 { 372.0f, 92.0f },
818 { 372.0007f, 92.000755f },
819 { 371.99927f, 92.003922f },
820 { 371.99826f, 92.003899f },
821 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000822
reed@google.com55b5f4b2011-09-07 12:23:41 +0000823 stroke_cubic(p1);
824}
825
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000826static void check_close(skiatest::Reporter* reporter, const SkPath& path) {
827 for (int i = 0; i < 2; ++i) {
robertphillips@google.com09042b82012-04-06 20:01:46 +0000828 SkPath::Iter iter(path, SkToBool(i));
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000829 SkPoint mv;
830 SkPoint pts[4];
831 SkPath::Verb v;
832 int nMT = 0;
833 int nCL = 0;
tomhudson@google.com221db3c2011-07-28 21:10:29 +0000834 mv.set(0, 0);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000835 while (SkPath::kDone_Verb != (v = iter.next(pts))) {
836 switch (v) {
837 case SkPath::kMove_Verb:
838 mv = pts[0];
839 ++nMT;
840 break;
841 case SkPath::kClose_Verb:
842 REPORTER_ASSERT(reporter, mv == pts[0]);
843 ++nCL;
844 break;
845 default:
846 break;
847 }
848 }
849 // if we force a close on the interator we should have a close
850 // for every moveTo
851 REPORTER_ASSERT(reporter, !i || nMT == nCL);
852 }
853}
854
855static void test_close(skiatest::Reporter* reporter) {
856 SkPath closePt;
857 closePt.moveTo(0, 0);
858 closePt.close();
859 check_close(reporter, closePt);
860
861 SkPath openPt;
862 openPt.moveTo(0, 0);
863 check_close(reporter, openPt);
864
865 SkPath empty;
866 check_close(reporter, empty);
867 empty.close();
868 check_close(reporter, empty);
869
870 SkPath rect;
871 rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
872 check_close(reporter, rect);
873 rect.close();
874 check_close(reporter, rect);
875
876 SkPath quad;
877 quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
878 check_close(reporter, quad);
879 quad.close();
880 check_close(reporter, quad);
881
882 SkPath cubic;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000883 quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1,
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000884 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1);
885 check_close(reporter, cubic);
886 cubic.close();
887 check_close(reporter, cubic);
888
889 SkPath line;
890 line.moveTo(SK_Scalar1, SK_Scalar1);
891 line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1);
892 check_close(reporter, line);
893 line.close();
894 check_close(reporter, line);
895
896 SkPath rect2;
897 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
898 rect2.close();
899 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
900 check_close(reporter, rect2);
901 rect2.close();
902 check_close(reporter, rect2);
903
904 SkPath oval3;
905 oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100));
906 oval3.close();
907 oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200));
908 check_close(reporter, oval3);
909 oval3.close();
910 check_close(reporter, oval3);
911
912 SkPath moves;
913 moves.moveTo(SK_Scalar1, SK_Scalar1);
914 moves.moveTo(5 * SK_Scalar1, SK_Scalar1);
915 moves.moveTo(SK_Scalar1, 10 * SK_Scalar1);
916 moves.moveTo(10 *SK_Scalar1, SK_Scalar1);
917 check_close(reporter, moves);
reed@google.com55b5f4b2011-09-07 12:23:41 +0000918
919 stroke_tiny_cubic();
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000920}
921
reed@google.com7c424812011-05-15 04:38:34 +0000922static void check_convexity(skiatest::Reporter* reporter, const SkPath& path,
923 SkPath::Convexity expected) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000924 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
925 SkPath::Convexity c = copy.getConvexity();
reed@google.com7c424812011-05-15 04:38:34 +0000926 REPORTER_ASSERT(reporter, c == expected);
927}
928
929static void test_convexity2(skiatest::Reporter* reporter) {
930 SkPath pt;
931 pt.moveTo(0, 0);
932 pt.close();
reed@google.comb54455e2011-05-16 14:16:04 +0000933 check_convexity(reporter, pt, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000934 check_direction(reporter, pt, SkPath::kUnknown_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000935
reed@google.com7c424812011-05-15 04:38:34 +0000936 SkPath line;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000937 line.moveTo(12*SK_Scalar1, 20*SK_Scalar1);
938 line.lineTo(-12*SK_Scalar1, -20*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000939 line.close();
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000940 check_convexity(reporter, line, SkPath::kConvex_Convexity);
941 check_direction(reporter, line, SkPath::kUnknown_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000942
reed@google.com7c424812011-05-15 04:38:34 +0000943 SkPath triLeft;
944 triLeft.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000945 triLeft.lineTo(SK_Scalar1, 0);
946 triLeft.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000947 triLeft.close();
948 check_convexity(reporter, triLeft, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000949 check_direction(reporter, triLeft, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000950
reed@google.com7c424812011-05-15 04:38:34 +0000951 SkPath triRight;
952 triRight.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000953 triRight.lineTo(-SK_Scalar1, 0);
954 triRight.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000955 triRight.close();
956 check_convexity(reporter, triRight, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000957 check_direction(reporter, triRight, SkPath::kCCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000958
reed@google.com7c424812011-05-15 04:38:34 +0000959 SkPath square;
960 square.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000961 square.lineTo(SK_Scalar1, 0);
962 square.lineTo(SK_Scalar1, SK_Scalar1);
963 square.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000964 square.close();
965 check_convexity(reporter, square, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000966 check_direction(reporter, square, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000967
reed@google.com7c424812011-05-15 04:38:34 +0000968 SkPath redundantSquare;
969 redundantSquare.moveTo(0, 0);
970 redundantSquare.lineTo(0, 0);
971 redundantSquare.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000972 redundantSquare.lineTo(SK_Scalar1, 0);
973 redundantSquare.lineTo(SK_Scalar1, 0);
974 redundantSquare.lineTo(SK_Scalar1, 0);
975 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
976 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
977 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
978 redundantSquare.lineTo(0, SK_Scalar1);
979 redundantSquare.lineTo(0, SK_Scalar1);
980 redundantSquare.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000981 redundantSquare.close();
982 check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000983 check_direction(reporter, redundantSquare, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000984
reed@google.com7c424812011-05-15 04:38:34 +0000985 SkPath bowTie;
986 bowTie.moveTo(0, 0);
987 bowTie.lineTo(0, 0);
988 bowTie.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +0000989 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
990 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
991 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
992 bowTie.lineTo(SK_Scalar1, 0);
993 bowTie.lineTo(SK_Scalar1, 0);
994 bowTie.lineTo(SK_Scalar1, 0);
995 bowTie.lineTo(0, SK_Scalar1);
996 bowTie.lineTo(0, SK_Scalar1);
997 bowTie.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +0000998 bowTie.close();
999 check_convexity(reporter, bowTie, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001000 check_direction(reporter, bowTie, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001001
reed@google.com7c424812011-05-15 04:38:34 +00001002 SkPath spiral;
1003 spiral.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001004 spiral.lineTo(100*SK_Scalar1, 0);
1005 spiral.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1006 spiral.lineTo(0, 100*SK_Scalar1);
1007 spiral.lineTo(0, 50*SK_Scalar1);
1008 spiral.lineTo(50*SK_Scalar1, 50*SK_Scalar1);
1009 spiral.lineTo(50*SK_Scalar1, 75*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001010 spiral.close();
reed@google.com85b6e392011-05-15 20:25:17 +00001011 check_convexity(reporter, spiral, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001012 check_direction(reporter, spiral, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001013
reed@google.com7c424812011-05-15 04:38:34 +00001014 SkPath dent;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001015 dent.moveTo(0, 0);
1016 dent.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1017 dent.lineTo(0, 100*SK_Scalar1);
1018 dent.lineTo(-50*SK_Scalar1, 200*SK_Scalar1);
1019 dent.lineTo(-200*SK_Scalar1, 100*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001020 dent.close();
1021 check_convexity(reporter, dent, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001022 check_direction(reporter, dent, SkPath::kCW_Direction);
reed@google.com7c424812011-05-15 04:38:34 +00001023}
1024
reed@android.com6b82d1a2009-06-03 02:35:01 +00001025static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
1026 const SkRect& bounds) {
1027 REPORTER_ASSERT(reporter, p.isConvex());
1028 REPORTER_ASSERT(reporter, p.getBounds() == bounds);
reed@google.com62047cf2011-02-07 19:39:09 +00001029
reed@android.com6b82d1a2009-06-03 02:35:01 +00001030 SkPath p2(p);
1031 REPORTER_ASSERT(reporter, p2.isConvex());
1032 REPORTER_ASSERT(reporter, p2.getBounds() == bounds);
1033
1034 SkPath other;
1035 other.swap(p2);
1036 REPORTER_ASSERT(reporter, other.isConvex());
1037 REPORTER_ASSERT(reporter, other.getBounds() == bounds);
1038}
1039
reed@google.com04863fa2011-05-15 04:08:24 +00001040static void setFromString(SkPath* path, const char str[]) {
1041 bool first = true;
1042 while (str) {
1043 SkScalar x, y;
1044 str = SkParse::FindScalar(str, &x);
1045 if (NULL == str) {
1046 break;
1047 }
1048 str = SkParse::FindScalar(str, &y);
1049 SkASSERT(str);
1050 if (first) {
1051 path->moveTo(x, y);
1052 first = false;
1053 } else {
1054 path->lineTo(x, y);
1055 }
1056 }
1057}
1058
1059static void test_convexity(skiatest::Reporter* reporter) {
reed@google.com04863fa2011-05-15 04:08:24 +00001060 SkPath path;
1061
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001062 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001063 path.addCircle(0, 0, SkIntToScalar(10));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001064 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001065 path.addCircle(0, 0, SkIntToScalar(10)); // 2nd circle
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001066 check_convexity(reporter, path, SkPath::kConcave_Convexity);
1067
reed@google.com04863fa2011-05-15 04:08:24 +00001068 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001069 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001070 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.com3e71a882012-01-10 18:44:37 +00001071 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCCW_Direction));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001072
reed@google.com04863fa2011-05-15 04:08:24 +00001073 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001074 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001075 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.com3e71a882012-01-10 18:44:37 +00001076 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCW_Direction));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001077
reed@google.com04863fa2011-05-15 04:08:24 +00001078 static const struct {
1079 const char* fPathStr;
1080 SkPath::Convexity fExpectedConvexity;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001081 SkPath::Direction fExpectedDirection;
reed@google.com04863fa2011-05-15 04:08:24 +00001082 } gRec[] = {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001083 { "", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1084 { "0 0", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1085 { "0 0 10 10", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1086 { "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity, SkPath::kUnknown_Direction },
1087 { "0 0 10 10 10 20", SkPath::kConvex_Convexity, SkPath::kCW_Direction },
1088 { "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPath::kCCW_Direction },
1089 { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir },
1090 { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity, SkPath::kCW_Direction },
reed@google.com04863fa2011-05-15 04:08:24 +00001091 };
1092
1093 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1094 SkPath path;
1095 setFromString(&path, gRec[i].fPathStr);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001096 check_convexity(reporter, path, gRec[i].fExpectedConvexity);
1097 check_direction(reporter, path, gRec[i].fExpectedDirection);
reed@google.com04863fa2011-05-15 04:08:24 +00001098 }
1099}
1100
reed@google.com7e6c4d12012-05-10 14:05:43 +00001101static void test_isLine(skiatest::Reporter* reporter) {
1102 SkPath path;
1103 SkPoint pts[2];
1104 const SkScalar value = SkIntToScalar(5);
1105
1106 REPORTER_ASSERT(reporter, !path.isLine(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001107
reed@google.com7e6c4d12012-05-10 14:05:43 +00001108 // set some non-zero values
1109 pts[0].set(value, value);
1110 pts[1].set(value, value);
1111 REPORTER_ASSERT(reporter, !path.isLine(pts));
1112 // check that pts was untouched
1113 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1114 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1115
1116 const SkScalar moveX = SkIntToScalar(1);
1117 const SkScalar moveY = SkIntToScalar(2);
1118 SkASSERT(value != moveX && value != moveY);
1119
1120 path.moveTo(moveX, moveY);
1121 REPORTER_ASSERT(reporter, !path.isLine(NULL));
1122 REPORTER_ASSERT(reporter, !path.isLine(pts));
1123 // check that pts was untouched
1124 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1125 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1126
1127 const SkScalar lineX = SkIntToScalar(2);
1128 const SkScalar lineY = SkIntToScalar(2);
1129 SkASSERT(value != lineX && value != lineY);
1130
1131 path.lineTo(lineX, lineY);
1132 REPORTER_ASSERT(reporter, path.isLine(NULL));
1133
1134 REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY));
1135 REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY));
1136 REPORTER_ASSERT(reporter, path.isLine(pts));
1137 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1138 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
1139
1140 path.lineTo(0, 0); // too many points/verbs
1141 REPORTER_ASSERT(reporter, !path.isLine(NULL));
1142 REPORTER_ASSERT(reporter, !path.isLine(pts));
1143 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1144 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
1145}
1146
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001147static void test_conservativelyContains(skiatest::Reporter* reporter) {
1148 SkPath path;
1149
1150 // kBaseRect is used to construct most our test paths: a rect, a circle, and a round-rect.
1151 static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
1152
1153 // A circle that bounds kBaseRect (with a significant amount of slop)
1154 SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height());
1155 circleR = SkScalarMul(circleR, SkFloatToScalar(1.75f)) / 2;
1156 static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()};
1157
1158 // round-rect radii
1159 static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)};
skia.committer@gmail.comcec8de62012-11-14 02:01:22 +00001160
caryclark@google.com56f233a2012-11-19 13:06:06 +00001161 static const struct SUPPRESS_VISIBILITY_WARNING {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001162 SkRect fQueryRect;
1163 bool fInRect;
1164 bool fInCircle;
1165 bool fInRR;
1166 } kQueries[] = {
1167 {kBaseRect, true, true, false},
1168
1169 // rect well inside of kBaseRect
1170 {SkRect::MakeLTRB(kBaseRect.fLeft + SkFloatToScalar(0.25f)*kBaseRect.width(),
1171 kBaseRect.fTop + SkFloatToScalar(0.25f)*kBaseRect.height(),
1172 kBaseRect.fRight - SkFloatToScalar(0.25f)*kBaseRect.width(),
1173 kBaseRect.fBottom - SkFloatToScalar(0.25f)*kBaseRect.height()),
1174 true, true, true},
1175
1176 // rects with edges off by one from kBaseRect's edges
1177 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1178 kBaseRect.width(), kBaseRect.height() + 1),
1179 false, true, false},
1180 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1181 kBaseRect.width() + 1, kBaseRect.height()),
1182 false, true, false},
1183 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1184 kBaseRect.width() + 1, kBaseRect.height() + 1),
1185 false, true, false},
1186 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1187 kBaseRect.width(), kBaseRect.height()),
1188 false, true, false},
1189 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1190 kBaseRect.width(), kBaseRect.height()),
1191 false, true, false},
1192 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1193 kBaseRect.width() + 2, kBaseRect.height()),
1194 false, true, false},
1195 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1196 kBaseRect.width() + 2, kBaseRect.height()),
1197 false, true, false},
1198
1199 // zero-w/h rects at each corner of kBaseRect
1200 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, false},
1201 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, false},
1202 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true, false},
1203 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true, false},
1204
1205 // far away rect
1206 {SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom,
1207 SkIntToScalar(10), SkIntToScalar(10)),
1208 false, false, false},
1209
1210 // very large rect containing kBaseRect
1211 {SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(),
1212 kBaseRect.fTop - 5 * kBaseRect.height(),
1213 11 * kBaseRect.width(), 11 * kBaseRect.height()),
1214 false, false, false},
1215
1216 // skinny rect that spans same y-range as kBaseRect
1217 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1218 SkIntToScalar(1), kBaseRect.height()),
1219 true, true, true},
1220
1221 // short rect that spans same x-range as kBaseRect
1222 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(), SkScalar(1)),
1223 true, true, true},
1224
1225 // skinny rect that spans slightly larger y-range than kBaseRect
1226 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1227 SkIntToScalar(1), kBaseRect.height() + 1),
1228 false, true, false},
1229
1230 // short rect that spans slightly larger x-range than kBaseRect
1231 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(),
1232 kBaseRect.width() + 1, SkScalar(1)),
1233 false, true, false},
1234 };
1235
1236 for (int inv = 0; inv < 4; ++inv) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001237 for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001238 SkRect qRect = kQueries[q].fQueryRect;
1239 if (inv & 0x1) {
1240 SkTSwap(qRect.fLeft, qRect.fRight);
1241 }
1242 if (inv & 0x2) {
1243 SkTSwap(qRect.fTop, qRect.fBottom);
1244 }
1245 for (int d = 0; d < 2; ++d) {
1246 SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
1247 path.reset();
1248 path.addRect(kBaseRect, dir);
1249 REPORTER_ASSERT(reporter, kQueries[q].fInRect ==
1250 path.conservativelyContainsRect(qRect));
1251
1252 path.reset();
1253 path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir);
1254 REPORTER_ASSERT(reporter, kQueries[q].fInCircle ==
1255 path.conservativelyContainsRect(qRect));
1256
1257 path.reset();
1258 path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir);
1259 REPORTER_ASSERT(reporter, kQueries[q].fInRR ==
1260 path.conservativelyContainsRect(qRect));
1261 }
1262 // Slightly non-convex shape, shouldn't contain any rects.
1263 path.reset();
1264 path.moveTo(0, 0);
1265 path.lineTo(SkIntToScalar(50), SkFloatToScalar(0.05f));
1266 path.lineTo(SkIntToScalar(100), 0);
1267 path.lineTo(SkIntToScalar(100), SkIntToScalar(100));
1268 path.lineTo(0, SkIntToScalar(100));
1269 path.close();
1270 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect));
1271 }
1272 }
1273
1274 // make sure a minimal convex shape works, a right tri with edges along pos x and y axes.
1275 path.reset();
1276 path.moveTo(0, 0);
1277 path.lineTo(SkIntToScalar(100), 0);
1278 path.lineTo(0, SkIntToScalar(100));
1279
1280 // inside, on along top edge
1281 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1282 SkIntToScalar(10),
1283 SkIntToScalar(10))));
1284 // above
1285 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1286 SkRect::MakeXYWH(SkIntToScalar(50),
1287 SkIntToScalar(-10),
1288 SkIntToScalar(10),
1289 SkIntToScalar(10))));
1290 // to the left
1291 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(-10),
1292 SkIntToScalar(5),
1293 SkIntToScalar(5),
1294 SkIntToScalar(5))));
1295
1296 // outside the diagonal edge
1297 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(10),
1298 SkIntToScalar(200),
1299 SkIntToScalar(20),
1300 SkIntToScalar(5))));
commit-bot@chromium.org62df5262013-08-01 15:35:06 +00001301
1302 // same as above path and first test but with an extra moveTo.
1303 path.reset();
1304 path.moveTo(100, 100);
1305 path.moveTo(0, 0);
1306 path.lineTo(SkIntToScalar(100), 0);
1307 path.lineTo(0, SkIntToScalar(100));
1308
1309 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1310 SkIntToScalar(10),
1311 SkIntToScalar(10))));
1312
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001313}
1314
caryclark@google.comf1316942011-07-26 19:54:45 +00001315// Simple isRect test is inline TestPath, below.
1316// test_isRect provides more extensive testing.
1317static void test_isRect(skiatest::Reporter* reporter) {
1318 // passing tests (all moveTo / lineTo...
1319 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1320 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1321 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1322 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
1323 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
1324 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1325 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1326 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1327 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001328 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}};
1329 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 +00001330 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}};
1331 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
1332 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}};
caryclark@google.combfe90372012-11-21 13:56:20 +00001333 SkPoint rf[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}};
rmistry@google.comd6176b02012-08-23 18:14:13 +00001334
caryclark@google.comf1316942011-07-26 19:54:45 +00001335 // failing tests
1336 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1337 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1338 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1339 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1340 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1341 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1342 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1343 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
caryclark@google.combfe90372012-11-21 13:56:20 +00001344 SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps
1345 SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non colinear gap
1346 SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short
rmistry@google.comd6176b02012-08-23 18:14:13 +00001347
caryclark@google.comf1316942011-07-26 19:54:45 +00001348 // failing, no close
1349 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
1350 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
1351
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001352 struct IsRectTest {
1353 SkPoint *fPoints;
1354 size_t fPointCount;
1355 bool fClose;
1356 bool fIsRect;
1357 } tests[] = {
1358 { r1, SK_ARRAY_COUNT(r1), true, true },
1359 { r2, SK_ARRAY_COUNT(r2), true, true },
1360 { r3, SK_ARRAY_COUNT(r3), true, true },
1361 { r4, SK_ARRAY_COUNT(r4), true, true },
1362 { r5, SK_ARRAY_COUNT(r5), true, true },
1363 { r6, SK_ARRAY_COUNT(r6), true, true },
1364 { r7, SK_ARRAY_COUNT(r7), true, true },
1365 { r8, SK_ARRAY_COUNT(r8), true, true },
1366 { r9, SK_ARRAY_COUNT(r9), true, true },
1367 { ra, SK_ARRAY_COUNT(ra), true, true },
1368 { rb, SK_ARRAY_COUNT(rb), true, true },
1369 { rc, SK_ARRAY_COUNT(rc), true, true },
1370 { rd, SK_ARRAY_COUNT(rd), true, true },
1371 { re, SK_ARRAY_COUNT(re), true, true },
1372 { rf, SK_ARRAY_COUNT(rf), true, true },
1373
1374 { f1, SK_ARRAY_COUNT(f1), true, false },
1375 { f2, SK_ARRAY_COUNT(f2), true, false },
1376 { f3, SK_ARRAY_COUNT(f3), true, false },
1377 { f4, SK_ARRAY_COUNT(f4), true, false },
1378 { f5, SK_ARRAY_COUNT(f5), true, false },
1379 { f6, SK_ARRAY_COUNT(f6), true, false },
1380 { f7, SK_ARRAY_COUNT(f7), true, false },
1381 { f8, SK_ARRAY_COUNT(f8), true, false },
1382 { f9, SK_ARRAY_COUNT(f9), true, false },
1383 { fa, SK_ARRAY_COUNT(fa), true, false },
1384 { fb, SK_ARRAY_COUNT(fb), true, false },
1385
1386 { c1, SK_ARRAY_COUNT(c1), false, false },
1387 { c2, SK_ARRAY_COUNT(c2), false, false },
caryclark@google.comf1316942011-07-26 19:54:45 +00001388 };
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001389
1390 const size_t testCount = SK_ARRAY_COUNT(tests);
caryclark@google.comf1316942011-07-26 19:54:45 +00001391 size_t index;
1392 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1393 SkPath path;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001394 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1395 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1396 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.comf1316942011-07-26 19:54:45 +00001397 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001398 if (tests[testIndex].fClose) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001399 path.close();
1400 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001401 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL));
1402 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL, NULL));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001403
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001404 if (tests[testIndex].fIsRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001405 SkRect computed, expected;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001406 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001407 REPORTER_ASSERT(reporter, path.isRect(&computed));
1408 REPORTER_ASSERT(reporter, expected == computed);
skia.committer@gmail.com1c9c0d32012-11-22 02:02:41 +00001409
caryclark@google.comf68154a2012-11-21 15:18:06 +00001410 bool isClosed;
1411 SkPath::Direction direction, cheapDirection;
1412 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection));
robertphillips@google.com8fd16032013-06-25 15:39:58 +00001413 REPORTER_ASSERT(reporter, path.isRect(&isClosed, &direction));
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001414 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001415 REPORTER_ASSERT(reporter, direction == cheapDirection);
1416 } else {
1417 SkRect computed;
1418 computed.set(123, 456, 789, 1011);
1419 REPORTER_ASSERT(reporter, !path.isRect(&computed));
1420 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456);
1421 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011);
1422
1423 bool isClosed = (bool) -1;
1424 SkPath::Direction direction = (SkPath::Direction) -1;
robertphillips@google.com8fd16032013-06-25 15:39:58 +00001425 REPORTER_ASSERT(reporter, !path.isRect(&isClosed, &direction));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001426 REPORTER_ASSERT(reporter, isClosed == (bool) -1);
1427 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001428 }
caryclark@google.comf1316942011-07-26 19:54:45 +00001429 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00001430
caryclark@google.comf1316942011-07-26 19:54:45 +00001431 // fail, close then line
1432 SkPath path1;
1433 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001434 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001435 path1.lineTo(r1[index].fX, r1[index].fY);
1436 }
1437 path1.close();
1438 path1.lineTo(1, 0);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001439 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001440
caryclark@google.comf1316942011-07-26 19:54:45 +00001441 // fail, move in the middle
1442 path1.reset();
1443 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001444 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001445 if (index == 2) {
1446 path1.moveTo(1, .5f);
1447 }
1448 path1.lineTo(r1[index].fX, r1[index].fY);
1449 }
1450 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001451 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00001452
1453 // fail, move on the edge
1454 path1.reset();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001455 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001456 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1457 path1.lineTo(r1[index].fX, r1[index].fY);
1458 }
1459 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001460 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001461
caryclark@google.comf1316942011-07-26 19:54:45 +00001462 // fail, quad
1463 path1.reset();
1464 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001465 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001466 if (index == 2) {
1467 path1.quadTo(1, .5f, 1, .5f);
1468 }
1469 path1.lineTo(r1[index].fX, r1[index].fY);
1470 }
1471 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001472 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001473
caryclark@google.comf1316942011-07-26 19:54:45 +00001474 // fail, cubic
1475 path1.reset();
1476 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001477 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001478 if (index == 2) {
1479 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1480 }
1481 path1.lineTo(r1[index].fX, r1[index].fY);
1482 }
1483 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001484 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00001485}
1486
caryclark@google.com56f233a2012-11-19 13:06:06 +00001487static void test_isNestedRects(skiatest::Reporter* reporter) {
1488 // passing tests (all moveTo / lineTo...
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001489 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001490 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1491 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1492 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001493 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001494 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1495 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1496 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1497 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001498 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; // CCW
1499 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 +00001500 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW
1501 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW
1502 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001503
1504 // failing tests
1505 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1506 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1507 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1508 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1509 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1510 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1511 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1512 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
1513
1514 // failing, no close
1515 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
1516 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
1517
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001518 struct IsNestedRectTest {
1519 SkPoint *fPoints;
1520 size_t fPointCount;
1521 SkPath::Direction fDirection;
1522 bool fClose;
1523 bool fIsNestedRect; // nests with path.addRect(-1, -1, 2, 2);
1524 } tests[] = {
1525 { r1, SK_ARRAY_COUNT(r1), SkPath::kCW_Direction , true, true },
1526 { r2, SK_ARRAY_COUNT(r2), SkPath::kCW_Direction , true, true },
1527 { r3, SK_ARRAY_COUNT(r3), SkPath::kCW_Direction , true, true },
1528 { r4, SK_ARRAY_COUNT(r4), SkPath::kCW_Direction , true, true },
1529 { r5, SK_ARRAY_COUNT(r5), SkPath::kCCW_Direction, true, true },
1530 { r6, SK_ARRAY_COUNT(r6), SkPath::kCCW_Direction, true, true },
1531 { r7, SK_ARRAY_COUNT(r7), SkPath::kCCW_Direction, true, true },
1532 { r8, SK_ARRAY_COUNT(r8), SkPath::kCCW_Direction, true, true },
1533 { r9, SK_ARRAY_COUNT(r9), SkPath::kCCW_Direction, true, true },
1534 { ra, SK_ARRAY_COUNT(ra), SkPath::kCCW_Direction, true, true },
1535 { rb, SK_ARRAY_COUNT(rb), SkPath::kCW_Direction, true, true },
1536 { rc, SK_ARRAY_COUNT(rc), SkPath::kCW_Direction, true, true },
1537 { rd, SK_ARRAY_COUNT(rd), SkPath::kCCW_Direction, true, true },
1538 { re, SK_ARRAY_COUNT(re), SkPath::kCW_Direction, true, true },
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001539
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001540 { f1, SK_ARRAY_COUNT(f1), SkPath::kUnknown_Direction, true, false },
1541 { f2, SK_ARRAY_COUNT(f2), SkPath::kUnknown_Direction, true, false },
1542 { f3, SK_ARRAY_COUNT(f3), SkPath::kUnknown_Direction, true, false },
1543 { f4, SK_ARRAY_COUNT(f4), SkPath::kUnknown_Direction, true, false },
1544 { f5, SK_ARRAY_COUNT(f5), SkPath::kUnknown_Direction, true, false },
1545 { f6, SK_ARRAY_COUNT(f6), SkPath::kUnknown_Direction, true, false },
1546 { f7, SK_ARRAY_COUNT(f7), SkPath::kUnknown_Direction, true, false },
1547 { f8, SK_ARRAY_COUNT(f8), SkPath::kUnknown_Direction, true, false },
1548
1549 { c1, SK_ARRAY_COUNT(c1), SkPath::kUnknown_Direction, false, false },
1550 { c2, SK_ARRAY_COUNT(c2), SkPath::kUnknown_Direction, false, false },
1551 };
1552
1553 const size_t testCount = SK_ARRAY_COUNT(tests);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001554 size_t index;
1555 for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001556 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1557 SkPath path;
1558 if (rectFirst) {
1559 path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1560 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001561 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1562 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1563 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001564 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001565 if (tests[testIndex].fClose) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001566 path.close();
1567 }
1568 if (!rectFirst) {
1569 path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1570 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001571 REPORTER_ASSERT(reporter, tests[testIndex].fIsNestedRect == path.isNestedRects(NULL));
1572 if (tests[testIndex].fIsNestedRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001573 SkRect expected[2], computed[2];
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001574 SkPath::Direction expectedDirs[2], computedDirs[2];
caryclark@google.com56f233a2012-11-19 13:06:06 +00001575 SkRect testBounds;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001576 testBounds.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001577 expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2);
1578 expected[1] = testBounds;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001579 if (rectFirst) {
1580 expectedDirs[0] = SkPath::kCW_Direction;
1581 } else {
1582 expectedDirs[0] = SkPath::kCCW_Direction;
1583 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001584 expectedDirs[1] = tests[testIndex].fDirection;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001585 REPORTER_ASSERT(reporter, path.isNestedRects(computed, computedDirs));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001586 REPORTER_ASSERT(reporter, expected[0] == computed[0]);
1587 REPORTER_ASSERT(reporter, expected[1] == computed[1]);
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001588 REPORTER_ASSERT(reporter, expectedDirs[0] == computedDirs[0]);
1589 REPORTER_ASSERT(reporter, expectedDirs[1] == computedDirs[1]);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001590 }
caryclark@google.com56f233a2012-11-19 13:06:06 +00001591 }
1592
1593 // fail, close then line
1594 SkPath path1;
1595 if (rectFirst) {
1596 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1597 }
1598 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001599 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001600 path1.lineTo(r1[index].fX, r1[index].fY);
1601 }
1602 path1.close();
1603 path1.lineTo(1, 0);
1604 if (!rectFirst) {
1605 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1606 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001607 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001608
1609 // fail, move in the middle
1610 path1.reset();
1611 if (rectFirst) {
1612 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1613 }
1614 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001615 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001616 if (index == 2) {
1617 path1.moveTo(1, .5f);
1618 }
1619 path1.lineTo(r1[index].fX, r1[index].fY);
1620 }
1621 path1.close();
1622 if (!rectFirst) {
1623 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1624 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001625 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001626
1627 // fail, move on the edge
1628 path1.reset();
1629 if (rectFirst) {
1630 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1631 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001632 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001633 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1634 path1.lineTo(r1[index].fX, r1[index].fY);
1635 }
1636 path1.close();
1637 if (!rectFirst) {
1638 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1639 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001640 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001641
1642 // fail, quad
1643 path1.reset();
1644 if (rectFirst) {
1645 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1646 }
1647 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001648 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001649 if (index == 2) {
1650 path1.quadTo(1, .5f, 1, .5f);
1651 }
1652 path1.lineTo(r1[index].fX, r1[index].fY);
1653 }
1654 path1.close();
1655 if (!rectFirst) {
1656 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1657 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001658 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001659
1660 // fail, cubic
1661 path1.reset();
1662 if (rectFirst) {
1663 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1664 }
1665 path1.moveTo(r1[0].fX, r1[0].fY);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001666 for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001667 if (index == 2) {
1668 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1669 }
1670 path1.lineTo(r1[index].fX, r1[index].fY);
1671 }
1672 path1.close();
1673 if (!rectFirst) {
1674 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1675 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001676 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
skia.committer@gmail.com34587162012-11-20 02:01:23 +00001677
caryclark@google.com56f233a2012-11-19 13:06:06 +00001678 // fail, not nested
1679 path1.reset();
1680 path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction);
1681 path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001682 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001683 }
caryclark@google.combfe90372012-11-21 13:56:20 +00001684
1685 // pass, stroke rect
1686 SkPath src, dst;
1687 src.addRect(1, 1, 7, 7, SkPath::kCW_Direction);
1688 SkPaint strokePaint;
1689 strokePaint.setStyle(SkPaint::kStroke_Style);
1690 strokePaint.setStrokeWidth(2);
1691 strokePaint.getFillPath(src, &dst);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001692 REPORTER_ASSERT(reporter, dst.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001693}
1694
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001695static void write_and_read_back(skiatest::Reporter* reporter,
1696 const SkPath& p) {
1697 SkWriter32 writer(100);
1698 writer.writePath(p);
1699 size_t size = writer.size();
1700 SkAutoMalloc storage(size);
1701 writer.flatten(storage.get());
1702 SkReader32 reader(storage.get(), size);
1703
1704 SkPath readBack;
1705 REPORTER_ASSERT(reporter, readBack != p);
1706 reader.readPath(&readBack);
1707 REPORTER_ASSERT(reporter, readBack == p);
1708
rmistry@google.comd6176b02012-08-23 18:14:13 +00001709 REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() ==
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001710 p.getConvexityOrUnknown());
1711
1712 REPORTER_ASSERT(reporter, readBack.isOval(NULL) == p.isOval(NULL));
1713
1714 const SkRect& origBounds = p.getBounds();
1715 const SkRect& readBackBounds = readBack.getBounds();
1716
1717 REPORTER_ASSERT(reporter, origBounds == readBackBounds);
1718}
1719
reed@google.com53effc52011-09-21 19:05:12 +00001720static void test_flattening(skiatest::Reporter* reporter) {
1721 SkPath p;
1722
1723 static const SkPoint pts[] = {
1724 { 0, 0 },
1725 { SkIntToScalar(10), SkIntToScalar(10) },
1726 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 },
1727 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }
1728 };
1729 p.moveTo(pts[0]);
1730 p.lineTo(pts[1]);
1731 p.quadTo(pts[2], pts[3]);
1732 p.cubicTo(pts[4], pts[5], pts[6]);
1733
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001734 write_and_read_back(reporter, p);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00001735
1736 // create a buffer that should be much larger than the path so we don't
1737 // kill our stack if writer goes too far.
1738 char buffer[1024];
1739 uint32_t size1 = p.writeToMemory(NULL);
1740 uint32_t size2 = p.writeToMemory(buffer);
1741 REPORTER_ASSERT(reporter, size1 == size2);
1742
1743 SkPath p2;
1744 uint32_t size3 = p2.readFromMemory(buffer);
1745 REPORTER_ASSERT(reporter, size1 == size3);
1746 REPORTER_ASSERT(reporter, p == p2);
1747
1748 char buffer2[1024];
1749 size3 = p2.writeToMemory(buffer2);
1750 REPORTER_ASSERT(reporter, size1 == size3);
1751 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
robertphillips@google.com2972bb52012-08-07 17:32:51 +00001752
1753 // test persistence of the oval flag & convexity
1754 {
1755 SkPath oval;
1756 SkRect rect = SkRect::MakeWH(10, 10);
1757 oval.addOval(rect);
1758
1759 write_and_read_back(reporter, oval);
1760 }
reed@google.com53effc52011-09-21 19:05:12 +00001761}
1762
1763static void test_transform(skiatest::Reporter* reporter) {
1764 SkPath p, p1;
rmistry@google.comd6176b02012-08-23 18:14:13 +00001765
reed@google.com53effc52011-09-21 19:05:12 +00001766 static const SkPoint pts[] = {
1767 { 0, 0 },
1768 { SkIntToScalar(10), SkIntToScalar(10) },
1769 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 },
1770 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }
1771 };
1772 p.moveTo(pts[0]);
1773 p.lineTo(pts[1]);
1774 p.quadTo(pts[2], pts[3]);
1775 p.cubicTo(pts[4], pts[5], pts[6]);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001776
reed@google.com53effc52011-09-21 19:05:12 +00001777 SkMatrix matrix;
1778 matrix.reset();
1779 p.transform(matrix, &p1);
1780 REPORTER_ASSERT(reporter, p == p1);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001781
reed@google.com53effc52011-09-21 19:05:12 +00001782 matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3);
1783 p.transform(matrix, &p1);
1784 SkPoint pts1[7];
1785 int count = p1.getPoints(pts1, 7);
1786 REPORTER_ASSERT(reporter, 7 == count);
1787 for (int i = 0; i < count; ++i) {
1788 SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3);
1789 REPORTER_ASSERT(reporter, newPt == pts1[i]);
1790 }
1791}
1792
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00001793static void test_zero_length_paths(skiatest::Reporter* reporter) {
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001794 SkPath p;
schenney@chromium.org7e963602012-06-13 17:05:43 +00001795 uint8_t verbs[32];
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00001796
caryclark@google.com56f233a2012-11-19 13:06:06 +00001797 struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData {
schenney@chromium.org7e963602012-06-13 17:05:43 +00001798 const char* testPath;
1799 const size_t numResultPts;
1800 const SkRect resultBound;
1801 const SkPath::Verb* resultVerbs;
1802 const size_t numResultVerbs;
1803 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00001804
schenney@chromium.org7e963602012-06-13 17:05:43 +00001805 static const SkPath::Verb resultVerbs1[] = { SkPath::kMove_Verb };
1806 static const SkPath::Verb resultVerbs2[] = { SkPath::kMove_Verb, SkPath::kMove_Verb };
1807 static const SkPath::Verb resultVerbs3[] = { SkPath::kMove_Verb, SkPath::kClose_Verb };
1808 static const SkPath::Verb resultVerbs4[] = { SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb };
1809 static const SkPath::Verb resultVerbs5[] = { SkPath::kMove_Verb, SkPath::kLine_Verb };
1810 static const SkPath::Verb resultVerbs6[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb };
1811 static const SkPath::Verb resultVerbs7[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb };
1812 static const SkPath::Verb resultVerbs8[] = {
1813 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb
1814 };
1815 static const SkPath::Verb resultVerbs9[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb };
1816 static const SkPath::Verb resultVerbs10[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb };
1817 static const SkPath::Verb resultVerbs11[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb };
1818 static const SkPath::Verb resultVerbs12[] = {
1819 SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb
1820 };
1821 static const SkPath::Verb resultVerbs13[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb };
1822 static const SkPath::Verb resultVerbs14[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb };
1823 static const SkPath::Verb resultVerbs15[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb };
1824 static const SkPath::Verb resultVerbs16[] = {
1825 SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb
1826 };
1827 static const struct zeroPathTestData gZeroLengthTests[] = {
1828 { "M 1 1", 1, {0, 0, 0, 0}, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00001829 { "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 +00001830 { "M 1 1 z", 1, {0, 0, 0, 0}, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00001831 { "M 1 1 z M 2 1 z", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
1832 { "M 1 1 L 1 1", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) },
1833 { "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) },
1834 { "M 1 1 L 1 1 z", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs7, SK_ARRAY_COUNT(resultVerbs7) },
1835 { "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) },
1836 { "M 1 1 Q 1 1 1 1", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs9, SK_ARRAY_COUNT(resultVerbs9) },
1837 { "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) },
1838 { "M 1 1 Q 1 1 1 1 z", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs11, SK_ARRAY_COUNT(resultVerbs11) },
1839 { "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) },
1840 { "M 1 1 C 1 1 1 1 1 1", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs13, SK_ARRAY_COUNT(resultVerbs13) },
1841 { "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 +00001842 SK_ARRAY_COUNT(resultVerbs14)
1843 },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00001844 { "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) },
1845 { "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 +00001846 SK_ARRAY_COUNT(resultVerbs16)
1847 }
1848 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00001849
schenney@chromium.org7e963602012-06-13 17:05:43 +00001850 for (size_t i = 0; i < SK_ARRAY_COUNT(gZeroLengthTests); ++i) {
1851 p.reset();
1852 bool valid = SkParsePath::FromSVGString(gZeroLengthTests[i].testPath, &p);
1853 REPORTER_ASSERT(reporter, valid);
1854 REPORTER_ASSERT(reporter, !p.isEmpty());
1855 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultPts == (size_t)p.countPoints());
1856 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultBound == p.getBounds());
1857 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultVerbs == (size_t)p.getVerbs(verbs, SK_ARRAY_COUNT(verbs)));
1858 for (size_t j = 0; j < gZeroLengthTests[i].numResultVerbs; ++j) {
1859 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultVerbs[j] == verbs[j]);
1860 }
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00001861 }
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00001862}
1863
1864struct SegmentInfo {
1865 SkPath fPath;
1866 int fPointCount;
1867};
1868
reed@google.com10296cc2011-09-21 12:29:05 +00001869#define kCurveSegmentMask (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask)
1870
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001871static void test_segment_masks(skiatest::Reporter* reporter) {
reed@google.comeef938c2012-08-01 20:01:49 +00001872 SkPath p, p2;
1873
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001874 p.moveTo(0, 0);
1875 p.quadTo(100, 100, 200, 200);
1876 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == p.getSegmentMasks());
1877 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00001878 p2 = p;
1879 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001880 p.cubicTo(100, 100, 200, 200, 300, 300);
1881 REPORTER_ASSERT(reporter, kCurveSegmentMask == p.getSegmentMasks());
1882 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00001883 p2 = p;
1884 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
1885
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001886 p.reset();
1887 p.moveTo(0, 0);
1888 p.cubicTo(100, 100, 200, 200, 300, 300);
1889 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == p.getSegmentMasks());
reed@google.comeef938c2012-08-01 20:01:49 +00001890 p2 = p;
1891 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
rmistry@google.comd6176b02012-08-23 18:14:13 +00001892
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001893 REPORTER_ASSERT(reporter, !p.isEmpty());
1894}
1895
1896static void test_iter(skiatest::Reporter* reporter) {
schenney@chromium.org7e963602012-06-13 17:05:43 +00001897 SkPath p;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001898 SkPoint pts[4];
1899
1900 // Test an iterator with no path
1901 SkPath::Iter noPathIter;
1902 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00001903
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001904 // Test that setting an empty path works
1905 noPathIter.setPath(p, false);
1906 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00001907
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001908 // Test that close path makes no difference for an empty path
1909 noPathIter.setPath(p, true);
1910 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00001911
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001912 // Test an iterator with an initial empty path
1913 SkPath::Iter iter(p, false);
1914 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
1915
1916 // Test that close path makes no difference
schenney@chromium.org7e963602012-06-13 17:05:43 +00001917 iter.setPath(p, true);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001918 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
1919
rmistry@google.comd6176b02012-08-23 18:14:13 +00001920
schenney@chromium.org7e963602012-06-13 17:05:43 +00001921 struct iterTestData {
1922 const char* testPath;
1923 const bool forceClose;
1924 const bool consumeDegenerates;
1925 const size_t* numResultPtsPerVerb;
1926 const SkPoint* resultPts;
1927 const SkPath::Verb* resultVerbs;
1928 const size_t numResultVerbs;
1929 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001930
schenney@chromium.org7e963602012-06-13 17:05:43 +00001931 static const SkPath::Verb resultVerbs1[] = { SkPath::kDone_Verb };
1932 static const SkPath::Verb resultVerbs2[] = {
1933 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kDone_Verb
1934 };
1935 static const SkPath::Verb resultVerbs3[] = {
1936 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
1937 };
1938 static const SkPath::Verb resultVerbs4[] = {
1939 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
1940 };
1941 static const SkPath::Verb resultVerbs5[] = {
1942 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
1943 };
1944 static const size_t resultPtsSizes1[] = { 0 };
schenney@chromium.orgfedd09b2012-06-13 18:29:20 +00001945 static const size_t resultPtsSizes2[] = { 1, 2, 2, 0 };
1946 static const size_t resultPtsSizes3[] = { 1, 2, 2, 2, 1, 0 };
1947 static const size_t resultPtsSizes4[] = { 1, 2, 1, 1, 0 };
1948 static const size_t resultPtsSizes5[] = { 1, 2, 1, 1, 1, 0 };
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00001949 static const SkPoint* resultPts1 = 0;
schenney@chromium.org7e963602012-06-13 17:05:43 +00001950 static const SkPoint resultPts2[] = {
1951 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 }
1952 };
1953 static const SkPoint resultPts3[] = {
1954 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 },
1955 { 0, SK_Scalar1 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }
1956 };
1957 static const SkPoint resultPts4[] = {
1958 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
1959 };
1960 static const SkPoint resultPts5[] = {
1961 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
1962 };
1963 static const struct iterTestData gIterTests[] = {
1964 { "M 1 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00001965 { "M 1 0 M 2 0 M 3 0 M 4 0 M 5 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
1966 { "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 +00001967 { "z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
1968 { "z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
1969 { "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) },
1970 { "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 +00001971 { "M 1 0 L 1 1 L 0 1 M 0 0 z", false, true, resultPtsSizes2, resultPts2, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
1972 { "M 1 0 L 1 1 L 0 1 M 0 0 z", true, true, resultPtsSizes3, resultPts3, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
1973 { "M 1 0 L 1 0 M 0 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
1974 { "M 1 0 L 1 0 M 0 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
1975 { "M 1 0 L 1 0 M 0 0 z", false, false, resultPtsSizes4, resultPts4, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
1976 { "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 +00001977 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001978
schenney@chromium.org7e963602012-06-13 17:05:43 +00001979 for (size_t i = 0; i < SK_ARRAY_COUNT(gIterTests); ++i) {
1980 p.reset();
1981 bool valid = SkParsePath::FromSVGString(gIterTests[i].testPath, &p);
1982 REPORTER_ASSERT(reporter, valid);
1983 iter.setPath(p, gIterTests[i].forceClose);
1984 int j = 0, l = 0;
1985 do {
1986 REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegenerates) == gIterTests[i].resultVerbs[j]);
1987 for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k) {
1988 REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]);
1989 }
1990 } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb);
1991 REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs);
1992 }
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00001993
1994 // The GM degeneratesegments.cpp test is more extensive
1995}
1996
1997static void test_raw_iter(skiatest::Reporter* reporter) {
1998 SkPath p;
1999 SkPoint pts[4];
2000
2001 // Test an iterator with no path
2002 SkPath::RawIter noPathIter;
2003 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
2004 // Test that setting an empty path works
2005 noPathIter.setPath(p);
2006 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
rmistry@google.comd6176b02012-08-23 18:14:13 +00002007
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002008 // Test an iterator with an initial empty path
2009 SkPath::RawIter iter(p);
2010 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2011
2012 // Test that a move-only path returns the move.
2013 p.moveTo(SK_Scalar1, 0);
2014 iter.setPath(p);
2015 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2016 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2017 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2018 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2019
2020 // No matter how many moves we add, we should get them all back
2021 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2022 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2023 iter.setPath(p);
2024 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2025 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2026 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2027 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2028 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2029 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2030 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2031 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2032 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2033 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2034
2035 // Initial close is never ever stored
2036 p.reset();
2037 p.close();
2038 iter.setPath(p);
2039 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2040
2041 // Move/close sequences
2042 p.reset();
2043 p.close(); // Not stored, no purpose
2044 p.moveTo(SK_Scalar1, 0);
2045 p.close();
2046 p.close(); // Not stored, no purpose
2047 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2048 p.close();
2049 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2050 p.moveTo(SK_Scalar1*4, SK_Scalar1*3);
2051 p.close();
2052 iter.setPath(p);
2053 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2054 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2055 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2056 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2057 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2058 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2059 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2060 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2061 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2062 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2063 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2064 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2065 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2066 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2067 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2068 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2069 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2070 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2071 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2072 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2073 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2074 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2075
2076 // Generate random paths and verify
2077 SkPoint randomPts[25];
2078 for (int i = 0; i < 5; ++i) {
2079 for (int j = 0; j < 5; ++j) {
2080 randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j);
2081 }
2082 }
2083
2084 // Max of 10 segments, max 3 points per segment
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +00002085 SkRandom rand(9876543);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002086 SkPoint expectedPts[31]; // May have leading moveTo
reed@google.comd335d1d2012-01-12 18:17:11 +00002087 SkPath::Verb expectedVerbs[22]; // May have leading moveTo
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002088 SkPath::Verb nextVerb;
reed@google.comd335d1d2012-01-12 18:17:11 +00002089
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002090 for (int i = 0; i < 500; ++i) {
2091 p.reset();
2092 bool lastWasClose = true;
2093 bool haveMoveTo = false;
reed@google.comd335d1d2012-01-12 18:17:11 +00002094 SkPoint lastMoveToPt = { 0, 0 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002095 int numPoints = 0;
2096 int numVerbs = (rand.nextU() >> 16) % 10;
2097 int numIterVerbs = 0;
2098 for (int j = 0; j < numVerbs; ++j) {
2099 do {
2100 nextVerb = static_cast<SkPath::Verb>((rand.nextU() >> 16) % SkPath::kDone_Verb);
2101 } while (lastWasClose && nextVerb == SkPath::kClose_Verb);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002102 switch (nextVerb) {
2103 case SkPath::kMove_Verb:
2104 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2105 p.moveTo(expectedPts[numPoints]);
reed@google.comd335d1d2012-01-12 18:17:11 +00002106 lastMoveToPt = expectedPts[numPoints];
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002107 numPoints += 1;
2108 lastWasClose = false;
2109 haveMoveTo = true;
2110 break;
2111 case SkPath::kLine_Verb:
2112 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002113 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002114 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2115 haveMoveTo = true;
2116 }
2117 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2118 p.lineTo(expectedPts[numPoints]);
2119 numPoints += 1;
2120 lastWasClose = false;
2121 break;
2122 case SkPath::kQuad_Verb:
2123 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002124 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002125 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2126 haveMoveTo = true;
2127 }
2128 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2129 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2130 p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]);
2131 numPoints += 2;
2132 lastWasClose = false;
2133 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002134 case SkPath::kConic_Verb:
2135 if (!haveMoveTo) {
2136 expectedPts[numPoints++] = lastMoveToPt;
2137 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2138 haveMoveTo = true;
2139 }
2140 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2141 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2142 p.conicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2143 rand.nextUScalar1() * 4);
2144 numPoints += 2;
2145 lastWasClose = false;
2146 break;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002147 case SkPath::kCubic_Verb:
2148 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002149 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002150 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2151 haveMoveTo = true;
2152 }
2153 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2154 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2155 expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25];
2156 p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2157 expectedPts[numPoints + 2]);
2158 numPoints += 3;
2159 lastWasClose = false;
2160 break;
2161 case SkPath::kClose_Verb:
2162 p.close();
reed@google.comd335d1d2012-01-12 18:17:11 +00002163 haveMoveTo = false;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002164 lastWasClose = true;
2165 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002166 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002167 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002168 }
2169 expectedVerbs[numIterVerbs++] = nextVerb;
2170 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00002171
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002172 iter.setPath(p);
2173 numVerbs = numIterVerbs;
2174 numIterVerbs = 0;
2175 int numIterPts = 0;
2176 SkPoint lastMoveTo;
2177 SkPoint lastPt;
2178 lastMoveTo.set(0, 0);
2179 lastPt.set(0, 0);
2180 while ((nextVerb = iter.next(pts)) != SkPath::kDone_Verb) {
2181 REPORTER_ASSERT(reporter, nextVerb == expectedVerbs[numIterVerbs]);
2182 numIterVerbs++;
2183 switch (nextVerb) {
2184 case SkPath::kMove_Verb:
2185 REPORTER_ASSERT(reporter, numIterPts < numPoints);
2186 REPORTER_ASSERT(reporter, pts[0] == expectedPts[numIterPts]);
2187 lastPt = lastMoveTo = pts[0];
2188 numIterPts += 1;
2189 break;
2190 case SkPath::kLine_Verb:
2191 REPORTER_ASSERT(reporter, numIterPts < numPoints + 1);
2192 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2193 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2194 lastPt = pts[1];
2195 numIterPts += 1;
2196 break;
2197 case SkPath::kQuad_Verb:
reed@google.com277c3f82013-05-31 15:17:50 +00002198 case SkPath::kConic_Verb:
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002199 REPORTER_ASSERT(reporter, numIterPts < numPoints + 2);
2200 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2201 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2202 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2203 lastPt = pts[2];
2204 numIterPts += 2;
2205 break;
2206 case SkPath::kCubic_Verb:
2207 REPORTER_ASSERT(reporter, numIterPts < numPoints + 3);
2208 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2209 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2210 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2211 REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]);
2212 lastPt = pts[3];
2213 numIterPts += 3;
2214 break;
2215 case SkPath::kClose_Verb:
2216 REPORTER_ASSERT(reporter, pts[0] == lastMoveTo);
2217 lastPt = lastMoveTo;
2218 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002219 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002220 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002221 }
2222 }
2223 REPORTER_ASSERT(reporter, numIterPts == numPoints);
2224 REPORTER_ASSERT(reporter, numIterVerbs == numVerbs);
2225 }
2226}
2227
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002228static void check_for_circle(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002229 const SkPath& path,
2230 bool expectedCircle,
2231 SkPath::Direction expectedDir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002232 SkRect rect;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002233 REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle);
2234 REPORTER_ASSERT(reporter, path.cheapIsDirection(expectedDir));
skia.committer@gmail.comfbb0ed92012-11-13 21:46:06 +00002235
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002236 if (expectedCircle) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002237 REPORTER_ASSERT(reporter, rect.height() == rect.width());
2238 }
2239}
2240
2241static void test_circle_skew(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002242 const SkPath& path,
2243 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002244 SkPath tmp;
2245
2246 SkMatrix m;
2247 m.setSkew(SkIntToScalar(3), SkIntToScalar(5));
2248 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002249 // this matrix reverses the direction.
2250 if (SkPath::kCCW_Direction == dir) {
2251 dir = SkPath::kCW_Direction;
2252 } else {
2253 SkASSERT(SkPath::kCW_Direction == dir);
2254 dir = SkPath::kCCW_Direction;
2255 }
2256 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002257}
2258
2259static void test_circle_translate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002260 const SkPath& path,
2261 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002262 SkPath tmp;
2263
2264 // translate at small offset
2265 SkMatrix m;
2266 m.setTranslate(SkIntToScalar(15), SkIntToScalar(15));
2267 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002268 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002269
2270 tmp.reset();
2271 m.reset();
2272
2273 // translate at a relatively big offset
2274 m.setTranslate(SkIntToScalar(1000), SkIntToScalar(1000));
2275 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002276 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002277}
2278
2279static void test_circle_rotate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002280 const SkPath& path,
2281 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002282 for (int angle = 0; angle < 360; ++angle) {
2283 SkPath tmp;
2284 SkMatrix m;
2285 m.setRotate(SkIntToScalar(angle));
2286 path.transform(m, &tmp);
2287
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002288 // TODO: a rotated circle whose rotated angle is not a multiple of 90
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002289 // degrees is not an oval anymore, this can be improved. we made this
2290 // for the simplicity of our implementation.
2291 if (angle % 90 == 0) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002292 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002293 } else {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002294 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002295 }
2296 }
2297}
2298
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002299static void test_circle_mirror_x(skiatest::Reporter* reporter,
2300 const SkPath& path,
2301 SkPath::Direction dir) {
2302 SkPath tmp;
2303 SkMatrix m;
2304 m.reset();
2305 m.setScaleX(-SK_Scalar1);
2306 path.transform(m, &tmp);
2307
2308 if (SkPath::kCW_Direction == dir) {
2309 dir = SkPath::kCCW_Direction;
2310 } else {
2311 SkASSERT(SkPath::kCCW_Direction == dir);
2312 dir = SkPath::kCW_Direction;
2313 }
2314
2315 check_for_circle(reporter, tmp, true, dir);
2316}
2317
2318static void test_circle_mirror_y(skiatest::Reporter* reporter,
2319 const SkPath& path,
2320 SkPath::Direction dir) {
2321 SkPath tmp;
2322 SkMatrix m;
2323 m.reset();
2324 m.setScaleY(-SK_Scalar1);
2325 path.transform(m, &tmp);
2326
2327 if (SkPath::kCW_Direction == dir) {
2328 dir = SkPath::kCCW_Direction;
2329 } else {
2330 SkASSERT(SkPath::kCCW_Direction == dir);
2331 dir = SkPath::kCW_Direction;
2332 }
2333
2334 check_for_circle(reporter, tmp, true, dir);
2335}
2336
2337static void test_circle_mirror_xy(skiatest::Reporter* reporter,
2338 const SkPath& path,
2339 SkPath::Direction dir) {
2340 SkPath tmp;
2341 SkMatrix m;
2342 m.reset();
2343 m.setScaleX(-SK_Scalar1);
2344 m.setScaleY(-SK_Scalar1);
2345 path.transform(m, &tmp);
2346
2347 check_for_circle(reporter, tmp, true, dir);
2348}
2349
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002350static void test_circle_with_direction(skiatest::Reporter* reporter,
2351 SkPath::Direction dir) {
2352 SkPath path;
2353
2354 // circle at origin
2355 path.addCircle(0, 0, SkIntToScalar(20), dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002356 check_for_circle(reporter, path, true, dir);
2357 test_circle_rotate(reporter, path, dir);
2358 test_circle_translate(reporter, path, dir);
2359 test_circle_skew(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002360
2361 // circle at an offset at (10, 10)
2362 path.reset();
2363 path.addCircle(SkIntToScalar(10), SkIntToScalar(10),
2364 SkIntToScalar(20), dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002365 check_for_circle(reporter, path, true, dir);
2366 test_circle_rotate(reporter, path, dir);
2367 test_circle_translate(reporter, path, dir);
2368 test_circle_skew(reporter, path, dir);
2369 test_circle_mirror_x(reporter, path, dir);
2370 test_circle_mirror_y(reporter, path, dir);
2371 test_circle_mirror_xy(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002372}
2373
2374static void test_circle_with_add_paths(skiatest::Reporter* reporter) {
2375 SkPath path;
2376 SkPath circle;
2377 SkPath rect;
2378 SkPath empty;
2379
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002380 static const SkPath::Direction kCircleDir = SkPath::kCW_Direction;
2381 static const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction;
2382
2383 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002384 rect.addRect(SkIntToScalar(5), SkIntToScalar(5),
2385 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction);
2386
2387 SkMatrix translate;
2388 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12));
2389
2390 // For simplicity, all the path concatenation related operations
2391 // would mark it non-circle, though in theory it's still a circle.
2392
2393 // empty + circle (translate)
2394 path = empty;
2395 path.addPath(circle, translate);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002396 check_for_circle(reporter, path, false, kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002397
2398 // circle + empty (translate)
2399 path = circle;
2400 path.addPath(empty, translate);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002401 check_for_circle(reporter, path, false, kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002402
2403 // test reverseAddPath
2404 path = circle;
2405 path.reverseAddPath(rect);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002406 check_for_circle(reporter, path, false, kCircleDirOpposite);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002407}
2408
2409static void test_circle(skiatest::Reporter* reporter) {
2410 test_circle_with_direction(reporter, SkPath::kCW_Direction);
2411 test_circle_with_direction(reporter, SkPath::kCCW_Direction);
2412
2413 // multiple addCircle()
2414 SkPath path;
2415 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2416 path.addCircle(0, 0, SkIntToScalar(20), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002417 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002418
2419 // some extra lineTo() would make isOval() fail
2420 path.reset();
2421 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2422 path.lineTo(0, 0);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002423 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002424
2425 // not back to the original point
2426 path.reset();
2427 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2428 path.setLastPt(SkIntToScalar(5), SkIntToScalar(5));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002429 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002430
2431 test_circle_with_add_paths(reporter);
2432}
2433
2434static void test_oval(skiatest::Reporter* reporter) {
2435 SkRect rect;
2436 SkMatrix m;
2437 SkPath path;
2438
2439 rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50));
2440 path.addOval(rect);
2441
2442 REPORTER_ASSERT(reporter, path.isOval(NULL));
2443
2444 m.setRotate(SkIntToScalar(90));
2445 SkPath tmp;
2446 path.transform(m, &tmp);
2447 // an oval rotated 90 degrees is still an oval.
2448 REPORTER_ASSERT(reporter, tmp.isOval(NULL));
2449
2450 m.reset();
2451 m.setRotate(SkIntToScalar(30));
2452 tmp.reset();
2453 path.transform(m, &tmp);
2454 // an oval rotated 30 degrees is not an oval anymore.
2455 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2456
2457 // since empty path being transformed.
2458 path.reset();
2459 tmp.reset();
2460 m.reset();
2461 path.transform(m, &tmp);
2462 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2463
2464 // empty path is not an oval
2465 tmp.reset();
2466 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2467
2468 // only has moveTo()s
2469 tmp.reset();
2470 tmp.moveTo(0, 0);
2471 tmp.moveTo(SkIntToScalar(10), SkIntToScalar(10));
2472 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2473
2474 // mimic WebKit's calling convention,
2475 // call moveTo() first and then call addOval()
2476 path.reset();
2477 path.moveTo(0, 0);
2478 path.addOval(rect);
2479 REPORTER_ASSERT(reporter, path.isOval(NULL));
2480
2481 // copy path
2482 path.reset();
2483 tmp.reset();
2484 tmp.addOval(rect);
2485 path = tmp;
2486 REPORTER_ASSERT(reporter, path.isOval(NULL));
2487}
2488
bungeman@google.coma5809a32013-06-21 15:13:34 +00002489static void test_empty(skiatest::Reporter* reporter, const SkPath& p) {
2490 SkPath empty;
reed@android.com80e39a72009-04-02 16:59:40 +00002491
reed@android.com3abec1d2009-03-02 05:36:20 +00002492 REPORTER_ASSERT(reporter, p.isEmpty());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002493 REPORTER_ASSERT(reporter, 0 == p.countPoints());
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002494 REPORTER_ASSERT(reporter, 0 == p.countVerbs());
reed@google.com10296cc2011-09-21 12:29:05 +00002495 REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks());
reed@google.comb54455e2011-05-16 14:16:04 +00002496 REPORTER_ASSERT(reporter, p.isConvex());
reed@android.com3abec1d2009-03-02 05:36:20 +00002497 REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType);
2498 REPORTER_ASSERT(reporter, !p.isInverseFillType());
bungeman@google.coma5809a32013-06-21 15:13:34 +00002499 REPORTER_ASSERT(reporter, p == empty);
2500 REPORTER_ASSERT(reporter, !(p != empty));
2501}
2502
2503static void TestPath(skiatest::Reporter* reporter) {
2504 SkTSize<SkScalar>::Make(3,4);
2505
2506 SkPath p, empty;
2507 SkRect bounds, bounds2;
2508 test_empty(reporter, p);
reed@android.com3abec1d2009-03-02 05:36:20 +00002509
reed@android.comd252db02009-04-01 18:31:44 +00002510 REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
reed@android.com80e39a72009-04-02 16:59:40 +00002511
reed@android.com3abec1d2009-03-02 05:36:20 +00002512 bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
reed@android.com6b82d1a2009-06-03 02:35:01 +00002513
reed@android.com6b82d1a2009-06-03 02:35:01 +00002514 p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1);
2515 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00002516 // we have quads or cubics
2517 REPORTER_ASSERT(reporter, p.getSegmentMasks() & kCurveSegmentMask);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002518 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00002519
reed@android.com6b82d1a2009-06-03 02:35:01 +00002520 p.reset();
bungeman@google.coma5809a32013-06-21 15:13:34 +00002521 test_empty(reporter, p);
reed@google.com10296cc2011-09-21 12:29:05 +00002522
reed@android.com6b82d1a2009-06-03 02:35:01 +00002523 p.addOval(bounds);
2524 check_convex_bounds(reporter, p, bounds);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002525 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00002526
bungeman@google.coma5809a32013-06-21 15:13:34 +00002527 p.rewind();
2528 test_empty(reporter, p);
2529
reed@android.com3abec1d2009-03-02 05:36:20 +00002530 p.addRect(bounds);
reed@android.com6b82d1a2009-06-03 02:35:01 +00002531 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00002532 // we have only lines
2533 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == p.getSegmentMasks());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002534 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@android.com3abec1d2009-03-02 05:36:20 +00002535
bungeman@google.coma5809a32013-06-21 15:13:34 +00002536 REPORTER_ASSERT(reporter, p != empty);
2537 REPORTER_ASSERT(reporter, !(p == empty));
reed@android.com3abec1d2009-03-02 05:36:20 +00002538
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002539 // do getPoints and getVerbs return the right result
2540 REPORTER_ASSERT(reporter, p.getPoints(NULL, 0) == 4);
2541 REPORTER_ASSERT(reporter, p.getVerbs(NULL, 0) == 5);
reed@android.com3abec1d2009-03-02 05:36:20 +00002542 SkPoint pts[4];
2543 int count = p.getPoints(pts, 4);
2544 REPORTER_ASSERT(reporter, count == 4);
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002545 uint8_t verbs[6];
2546 verbs[5] = 0xff;
2547 p.getVerbs(verbs, 5);
2548 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == verbs[0]);
2549 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[1]);
2550 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[2]);
2551 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[3]);
2552 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == verbs[4]);
2553 REPORTER_ASSERT(reporter, 0xff == verbs[5]);
reed@android.com3abec1d2009-03-02 05:36:20 +00002554 bounds2.set(pts, 4);
2555 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00002556
reed@android.com3abec1d2009-03-02 05:36:20 +00002557 bounds.offset(SK_Scalar1*3, SK_Scalar1*4);
2558 p.offset(SK_Scalar1*3, SK_Scalar1*4);
reed@android.comd252db02009-04-01 18:31:44 +00002559 REPORTER_ASSERT(reporter, bounds == p.getBounds());
reed@android.com3abec1d2009-03-02 05:36:20 +00002560
reed@android.com3abec1d2009-03-02 05:36:20 +00002561 REPORTER_ASSERT(reporter, p.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00002562 bounds2.setEmpty();
reed@android.com3abec1d2009-03-02 05:36:20 +00002563 REPORTER_ASSERT(reporter, p.isRect(&bounds2));
2564 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00002565
reed@android.com3abec1d2009-03-02 05:36:20 +00002566 // now force p to not be a rect
2567 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2);
2568 p.addRect(bounds);
2569 REPORTER_ASSERT(reporter, !p.isRect(NULL));
reed@android.com3abec1d2009-03-02 05:36:20 +00002570
reed@google.com7e6c4d12012-05-10 14:05:43 +00002571 test_isLine(reporter);
2572 test_isRect(reporter);
caryclark@google.com56f233a2012-11-19 13:06:06 +00002573 test_isNestedRects(reporter);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002574 test_zero_length_paths(reporter);
reed@google.comcabaf1d2012-01-11 21:03:05 +00002575 test_direction(reporter);
reed@google.com04863fa2011-05-15 04:08:24 +00002576 test_convexity(reporter);
reed@google.com7c424812011-05-15 04:38:34 +00002577 test_convexity2(reporter);
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00002578 test_conservativelyContains(reporter);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00002579 test_close(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002580 test_segment_masks(reporter);
reed@google.com53effc52011-09-21 19:05:12 +00002581 test_flattening(reporter);
2582 test_transform(reporter);
reed@google.com3563c9e2011-11-14 19:34:57 +00002583 test_bounds(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002584 test_iter(reporter);
2585 test_raw_iter(reporter);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002586 test_circle(reporter);
2587 test_oval(reporter);
reed@google.com8b06f1a2012-05-29 12:03:46 +00002588 test_strokerec(reporter);
reed@google.com744faba2012-05-29 19:54:52 +00002589 test_addPoly(reporter);
reed@google.com0bb18bb2012-07-26 15:20:36 +00002590 test_isfinite(reporter);
tomhudson@google.comed02c4d2012-08-10 14:10:45 +00002591 test_isfinite_after_transform(reporter);
robertphillips@google.comb95eaa82012-10-18 15:26:12 +00002592 test_arb_round_rect_is_convex(reporter);
robertphillips@google.com158618e2012-10-23 16:56:56 +00002593 test_arb_zero_rad_round_rect_is_rect(reporter);
reed@google.coma8790de2012-10-24 21:04:04 +00002594 test_addrect_isfinite(reporter);
sugoi@google.com54f0d1b2013-02-27 19:17:41 +00002595 test_tricky_cubic();
2596 test_clipped_cubic();
2597 test_crbug_170666();
reed@google.com7a90daf2013-04-10 18:44:00 +00002598 test_bad_cubic_crbug229478();
reed@google.com3eff3592013-05-08 21:08:21 +00002599 test_bad_cubic_crbug234190();
mtklein@google.com9c9d4a72013-08-07 19:17:53 +00002600 test_android_specific_behavior(reporter);
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +00002601 test_path_close_issue1474(reporter);
reed@google.comb58ba892013-10-15 15:44:35 +00002602 test_path_to_region(reporter);
reed@android.com3abec1d2009-03-02 05:36:20 +00002603}
2604
2605#include "TestClassDef.h"
2606DEFINE_TESTCLASS("Path", PathTestClass, TestPath)