blob: 7db65a899f24f310dc8e1232a97ff6fb7d4f7352 [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@google.com8cae8352012-09-14 15:18:41 +00008#include "SkCanvas.h"
reed@google.com55b5f4b2011-09-07 12:23:41 +00009#include "SkPaint.h"
reed@google.com04863fa2011-05-15 04:08:24 +000010#include "SkParse.h"
reed@google.com3e71a882012-01-10 18:44:37 +000011#include "SkParsePath.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000012#include "SkPath.h"
reed@google.com8b06f1a2012-05-29 12:03:46 +000013#include "SkPathEffect.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000014#include "SkRRect.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"
caryclark66a5d8b2014-06-24 08:30:15 -070018#include "SkStream.h"
reed@google.com8cae8352012-09-14 15:18:41 +000019#include "SkSurface.h"
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000020#include "SkTypes.h"
21#include "SkWriter32.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000022#include "Test.h"
reed@google.com8cae8352012-09-14 15:18:41 +000023
reed5bcbe912014-12-15 12:28:33 -080024static void set_radii(SkVector radii[4], int index, float rad) {
25 sk_bzero(radii, sizeof(SkVector) * 4);
26 radii[index].set(rad, rad);
27}
28
29static void test_add_rrect(skiatest::Reporter* reporter, const SkRect& bounds,
30 const SkVector radii[4]) {
31 SkRRect rrect;
32 rrect.setRectRadii(bounds, radii);
33 REPORTER_ASSERT(reporter, bounds == rrect.rect());
34
35 SkPath path;
36 // this line should not assert in the debug build (from validate)
37 path.addRRect(rrect);
38 REPORTER_ASSERT(reporter, bounds == path.getBounds());
39}
40
41static void test_skbug_3239(skiatest::Reporter* reporter) {
42 const float min = SkBits2Float(0xcb7f16c8); /* -16717512.000000 */
43 const float max = SkBits2Float(0x4b7f1c1d); /* 16718877.000000 */
44 const float big = SkBits2Float(0x4b7f1bd7); /* 16718807.000000 */
45
46 const float rad = 33436320;
47
48 const SkRect rectx = SkRect::MakeLTRB(min, min, max, big);
49 const SkRect recty = SkRect::MakeLTRB(min, min, big, max);
50
51 SkVector radii[4];
52 for (int i = 0; i < 4; ++i) {
53 set_radii(radii, i, rad);
54 test_add_rrect(reporter, rectx, radii);
55 test_add_rrect(reporter, recty, radii);
56 }
57}
58
commit-bot@chromium.org4e332f82014-05-05 16:04:42 +000059static void make_path_crbug364224(SkPath* path) {
60 path->reset();
61 path->moveTo(3.747501373f, 2.724499941f);
62 path->lineTo(3.747501373f, 3.75f);
63 path->cubicTo(3.747501373f, 3.88774991f, 3.635501385f, 4.0f, 3.497501373f, 4.0f);
64 path->lineTo(0.7475013733f, 4.0f);
65 path->cubicTo(0.6095013618f, 4.0f, 0.4975013733f, 3.88774991f, 0.4975013733f, 3.75f);
66 path->lineTo(0.4975013733f, 1.0f);
67 path->cubicTo(0.4975013733f, 0.8622499704f, 0.6095013618f, 0.75f, 0.7475013733f,0.75f);
68 path->lineTo(3.497501373f, 0.75f);
69 path->cubicTo(3.50275135f, 0.75f, 3.5070014f, 0.7527500391f, 3.513001442f, 0.753000021f);
70 path->lineTo(3.715001345f, 0.5512499809f);
71 path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
72 path->lineTo(0.7475013733f, 0.4999999702f);
73 path->cubicTo(0.4715013802f, 0.4999999702f, 0.2475013733f, 0.7239999771f, 0.2475013733f, 1.0f);
74 path->lineTo(0.2475013733f, 3.75f);
75 path->cubicTo(0.2475013733f, 4.026000023f, 0.4715013504f, 4.25f, 0.7475013733f, 4.25f);
76 path->lineTo(3.497501373f, 4.25f);
77 path->cubicTo(3.773501396f, 4.25f, 3.997501373f, 4.026000023f, 3.997501373f, 3.75f);
78 path->lineTo(3.997501373f, 2.474750042f);
79 path->lineTo(3.747501373f, 2.724499941f);
80 path->close();
81}
82
83static void make_path_crbug364224_simplified(SkPath* path) {
84 path->moveTo(3.747501373f, 2.724499941f);
85 path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
86 path->close();
87}
88
89static void test_path_crbug364224() {
90 SkPath path;
91 SkPaint paint;
reed3054be12014-12-10 07:24:28 -080092 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(84, 88));
commit-bot@chromium.org4e332f82014-05-05 16:04:42 +000093 SkCanvas* canvas = surface->getCanvas();
94
95 make_path_crbug364224_simplified(&path);
96 canvas->drawPath(path, paint);
97
98 make_path_crbug364224(&path);
99 canvas->drawPath(path, paint);
100}
101
piotaixrfac4e0e2014-08-26 11:59:04 -0700102/**
103 * In debug mode, this path was causing an assertion to fail in
104 * SkPathStroker::preJoinTo() and, in Release, the use of an unitialized value.
105 */
106static void make_path_crbugskia2820(SkPath* path, skiatest::Reporter* reporter) {
107 SkPoint orig, p1, p2, p3;
108 orig = SkPoint::Make(1.f, 1.f);
109 p1 = SkPoint::Make(1.f - SK_ScalarNearlyZero, 1.f);
110 p2 = SkPoint::Make(1.f, 1.f + SK_ScalarNearlyZero);
111 p3 = SkPoint::Make(2.f, 2.f);
112
113 path->reset();
114 path->moveTo(orig);
115 path->cubicTo(p1, p2, p3);
116 path->close();
117}
118
119static void test_path_crbugskia2820(skiatest::Reporter* reporter) {//GrContext* context) {
120 SkPath path;
121 make_path_crbugskia2820(&path, reporter);
122
123 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
124 stroke.setStrokeStyle(2 * SK_Scalar1);
125 stroke.applyToPath(&path, path);
126}
127
reed@google.comcc8be772013-10-15 15:35:29 +0000128static void make_path0(SkPath* path) {
129 // from * https://code.google.com/p/skia/issues/detail?id=1706
130
131 path->moveTo(146.939f, 1012.84f);
132 path->lineTo(181.747f, 1009.18f);
133 path->lineTo(182.165f, 1013.16f);
134 path->lineTo(147.357f, 1016.82f);
135 path->lineTo(146.939f, 1012.84f);
136 path->close();
137}
138
139static void make_path1(SkPath* path) {
140 path->addRect(SkRect::MakeXYWH(10, 10, 10, 1));
141}
142
143typedef void (*PathProc)(SkPath*);
144
145/*
146 * Regression test: we used to crash (overwrite internal storage) during
147 * construction of the region when the path was INVERSE. That is now fixed,
148 * so test these regions (which used to assert/crash).
149 *
150 * https://code.google.com/p/skia/issues/detail?id=1706
151 */
152static void test_path_to_region(skiatest::Reporter* reporter) {
153 PathProc procs[] = {
154 make_path0,
155 make_path1,
156 };
skia.committer@gmail.com47262912013-10-16 07:02:24 +0000157
reed@google.comcc8be772013-10-15 15:35:29 +0000158 SkRegion clip;
159 clip.setRect(0, 0, 1255, 1925);
skia.committer@gmail.com47262912013-10-16 07:02:24 +0000160
reed@google.comcc8be772013-10-15 15:35:29 +0000161 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
162 SkPath path;
163 procs[i](&path);
skia.committer@gmail.com47262912013-10-16 07:02:24 +0000164
reed@google.comcc8be772013-10-15 15:35:29 +0000165 SkRegion rgn;
166 rgn.setPath(path, clip);
167 path.toggleInverseFillType();
168 rgn.setPath(path, clip);
169 }
170}
171
caryclark@google.com56f233a2012-11-19 13:06:06 +0000172#if defined(WIN32)
173 #define SUPPRESS_VISIBILITY_WARNING
174#else
175 #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
176#endif
177
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +0000178static void test_path_close_issue1474(skiatest::Reporter* reporter) {
179 // This test checks that r{Line,Quad,Conic,Cubic}To following a close()
180 // are relative to the point we close to, not relative to the point we close from.
181 SkPath path;
182 SkPoint last;
183
184 // Test rLineTo().
185 path.rLineTo(0, 100);
186 path.rLineTo(100, 0);
187 path.close(); // Returns us back to 0,0.
188 path.rLineTo(50, 50); // This should go to 50,50.
189
190 path.getLastPt(&last);
191 REPORTER_ASSERT(reporter, 50 == last.fX);
192 REPORTER_ASSERT(reporter, 50 == last.fY);
193
194 // Test rQuadTo().
195 path.rewind();
196 path.rLineTo(0, 100);
197 path.rLineTo(100, 0);
198 path.close();
199 path.rQuadTo(50, 50, 75, 75);
200
201 path.getLastPt(&last);
202 REPORTER_ASSERT(reporter, 75 == last.fX);
203 REPORTER_ASSERT(reporter, 75 == last.fY);
204
205 // Test rConicTo().
206 path.rewind();
207 path.rLineTo(0, 100);
208 path.rLineTo(100, 0);
209 path.close();
210 path.rConicTo(50, 50, 85, 85, 2);
211
212 path.getLastPt(&last);
213 REPORTER_ASSERT(reporter, 85 == last.fX);
214 REPORTER_ASSERT(reporter, 85 == last.fY);
215
216 // Test rCubicTo().
217 path.rewind();
218 path.rLineTo(0, 100);
219 path.rLineTo(100, 0);
220 path.close();
221 path.rCubicTo(50, 50, 85, 85, 95, 95);
222
223 path.getLastPt(&last);
224 REPORTER_ASSERT(reporter, 95 == last.fX);
225 REPORTER_ASSERT(reporter, 95 == last.fY);
226}
227
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000228static void test_gen_id(skiatest::Reporter* reporter) {
229 SkPath a, b;
230 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
231
232 a.moveTo(0, 0);
233 const uint32_t z = a.getGenerationID();
234 REPORTER_ASSERT(reporter, z != b.getGenerationID());
235
236 a.reset();
237 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
238
239 a.moveTo(1, 1);
240 const uint32_t y = a.getGenerationID();
241 REPORTER_ASSERT(reporter, z != y);
242
243 b.moveTo(2, 2);
244 const uint32_t x = b.getGenerationID();
245 REPORTER_ASSERT(reporter, x != y && x != z);
246
247 a.swap(b);
248 REPORTER_ASSERT(reporter, b.getGenerationID() == y && a.getGenerationID() == x);
249
250 b = a;
251 REPORTER_ASSERT(reporter, b.getGenerationID() == x);
252
253 SkPath c(a);
254 REPORTER_ASSERT(reporter, c.getGenerationID() == x);
255
256 c.lineTo(3, 3);
257 const uint32_t w = c.getGenerationID();
258 REPORTER_ASSERT(reporter, b.getGenerationID() == x);
259 REPORTER_ASSERT(reporter, a.getGenerationID() == x);
260 REPORTER_ASSERT(reporter, w != x);
261
djsollen50da1d82015-02-17 09:09:53 -0800262#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000263 static bool kExpectGenIDToIgnoreFill = false;
264#else
265 static bool kExpectGenIDToIgnoreFill = true;
266#endif
267
268 c.toggleInverseFillType();
269 const uint32_t v = c.getGenerationID();
270 REPORTER_ASSERT(reporter, (v == w) == kExpectGenIDToIgnoreFill);
271
272 c.rewind();
273 REPORTER_ASSERT(reporter, v != c.getGenerationID());
274}
275
reed@google.com3eff3592013-05-08 21:08:21 +0000276// This used to assert in the debug build, as the edges did not all line-up.
277static void test_bad_cubic_crbug234190() {
278 SkPath path;
279 path.moveTo(13.8509f, 3.16858f);
280 path.cubicTo(-2.35893e+08f, -4.21044e+08f,
281 -2.38991e+08f, -4.26573e+08f,
282 -2.41016e+08f, -4.30188e+08f);
283
284 SkPaint paint;
285 paint.setAntiAlias(true);
reed3054be12014-12-10 07:24:28 -0800286 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(84, 88));
reed@google.com3eff3592013-05-08 21:08:21 +0000287 surface->getCanvas()->drawPath(path, paint);
288}
289
reed@google.com7a90daf2013-04-10 18:44:00 +0000290static void test_bad_cubic_crbug229478() {
291 const SkPoint pts[] = {
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000292 { 4595.91064f, -11596.9873f },
293 { 4597.2168f, -11595.9414f },
294 { 4598.52344f, -11594.8955f },
295 { 4599.83008f, -11593.8496f },
reed@google.com7a90daf2013-04-10 18:44:00 +0000296 };
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000297
reed@google.com7a90daf2013-04-10 18:44:00 +0000298 SkPath path;
299 path.moveTo(pts[0]);
300 path.cubicTo(pts[1], pts[2], pts[3]);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000301
reed@google.com7a90daf2013-04-10 18:44:00 +0000302 SkPaint paint;
303 paint.setStyle(SkPaint::kStroke_Style);
304 paint.setStrokeWidth(20);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000305
reed@google.com7a90daf2013-04-10 18:44:00 +0000306 SkPath dst;
307 // Before the fix, this would infinite-recurse, and run out of stack
308 // because we would keep trying to subdivide a degenerate cubic segment.
309 paint.getFillPath(path, &dst, NULL);
310}
311
reed@google.com64d62952013-01-18 17:49:28 +0000312static void build_path_170666(SkPath& path) {
313 path.moveTo(17.9459f, 21.6344f);
314 path.lineTo(139.545f, -47.8105f);
315 path.lineTo(139.545f, -47.8105f);
316 path.lineTo(131.07f, -47.3888f);
317 path.lineTo(131.07f, -47.3888f);
318 path.lineTo(122.586f, -46.9532f);
319 path.lineTo(122.586f, -46.9532f);
320 path.lineTo(18076.6f, 31390.9f);
321 path.lineTo(18076.6f, 31390.9f);
322 path.lineTo(18085.1f, 31390.5f);
323 path.lineTo(18085.1f, 31390.5f);
324 path.lineTo(18076.6f, 31390.9f);
325 path.lineTo(18076.6f, 31390.9f);
326 path.lineTo(17955, 31460.3f);
327 path.lineTo(17955, 31460.3f);
328 path.lineTo(17963.5f, 31459.9f);
329 path.lineTo(17963.5f, 31459.9f);
330 path.lineTo(17971.9f, 31459.5f);
331 path.lineTo(17971.9f, 31459.5f);
332 path.lineTo(17.9551f, 21.6205f);
333 path.lineTo(17.9551f, 21.6205f);
334 path.lineTo(9.47091f, 22.0561f);
335 path.lineTo(9.47091f, 22.0561f);
336 path.lineTo(17.9459f, 21.6344f);
337 path.lineTo(17.9459f, 21.6344f);
338 path.close();path.moveTo(0.995934f, 22.4779f);
339 path.lineTo(0.986725f, 22.4918f);
340 path.lineTo(0.986725f, 22.4918f);
341 path.lineTo(17955, 31460.4f);
342 path.lineTo(17955, 31460.4f);
343 path.lineTo(17971.9f, 31459.5f);
344 path.lineTo(17971.9f, 31459.5f);
345 path.lineTo(18093.6f, 31390.1f);
346 path.lineTo(18093.6f, 31390.1f);
347 path.lineTo(18093.6f, 31390);
348 path.lineTo(18093.6f, 31390);
349 path.lineTo(139.555f, -47.8244f);
350 path.lineTo(139.555f, -47.8244f);
351 path.lineTo(122.595f, -46.9671f);
352 path.lineTo(122.595f, -46.9671f);
353 path.lineTo(0.995934f, 22.4779f);
354 path.lineTo(0.995934f, 22.4779f);
355 path.close();
356 path.moveTo(5.43941f, 25.5223f);
357 path.lineTo(798267, -28871.1f);
358 path.lineTo(798267, -28871.1f);
359 path.lineTo(3.12512e+06f, -113102);
360 path.lineTo(3.12512e+06f, -113102);
361 path.cubicTo(5.16324e+06f, -186882, 8.15247e+06f, -295092, 1.1957e+07f, -432813);
362 path.cubicTo(1.95659e+07f, -708257, 3.04359e+07f, -1.10175e+06f, 4.34798e+07f, -1.57394e+06f);
363 path.cubicTo(6.95677e+07f, -2.51831e+06f, 1.04352e+08f, -3.77748e+06f, 1.39135e+08f, -5.03666e+06f);
364 path.cubicTo(1.73919e+08f, -6.29583e+06f, 2.08703e+08f, -7.555e+06f, 2.34791e+08f, -8.49938e+06f);
365 path.cubicTo(2.47835e+08f, -8.97157e+06f, 2.58705e+08f, -9.36506e+06f, 2.66314e+08f, -9.6405e+06f);
366 path.cubicTo(2.70118e+08f, -9.77823e+06f, 2.73108e+08f, -9.88644e+06f, 2.75146e+08f, -9.96022e+06f);
367 path.cubicTo(2.76165e+08f, -9.99711e+06f, 2.76946e+08f, -1.00254e+07f, 2.77473e+08f, -1.00444e+07f);
368 path.lineTo(2.78271e+08f, -1.00733e+07f);
369 path.lineTo(2.78271e+08f, -1.00733e+07f);
370 path.cubicTo(2.78271e+08f, -1.00733e+07f, 2.08703e+08f, -7.555e+06f, 135.238f, 23.3517f);
371 path.cubicTo(131.191f, 23.4981f, 125.995f, 23.7976f, 123.631f, 24.0206f);
372 path.cubicTo(121.267f, 24.2436f, 122.631f, 24.3056f, 126.677f, 24.1591f);
373 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
374 path.lineTo(2.77473e+08f, -1.00444e+07f);
375 path.lineTo(2.77473e+08f, -1.00444e+07f);
376 path.cubicTo(2.76946e+08f, -1.00254e+07f, 2.76165e+08f, -9.99711e+06f, 2.75146e+08f, -9.96022e+06f);
377 path.cubicTo(2.73108e+08f, -9.88644e+06f, 2.70118e+08f, -9.77823e+06f, 2.66314e+08f, -9.6405e+06f);
378 path.cubicTo(2.58705e+08f, -9.36506e+06f, 2.47835e+08f, -8.97157e+06f, 2.34791e+08f, -8.49938e+06f);
379 path.cubicTo(2.08703e+08f, -7.555e+06f, 1.73919e+08f, -6.29583e+06f, 1.39135e+08f, -5.03666e+06f);
380 path.cubicTo(1.04352e+08f, -3.77749e+06f, 6.95677e+07f, -2.51831e+06f, 4.34798e+07f, -1.57394e+06f);
381 path.cubicTo(3.04359e+07f, -1.10175e+06f, 1.95659e+07f, -708258, 1.1957e+07f, -432814);
382 path.cubicTo(8.15248e+06f, -295092, 5.16324e+06f, -186883, 3.12513e+06f, -113103);
383 path.lineTo(798284, -28872);
384 path.lineTo(798284, -28872);
385 path.lineTo(22.4044f, 24.6677f);
386 path.lineTo(22.4044f, 24.6677f);
387 path.cubicTo(22.5186f, 24.5432f, 18.8134f, 24.6337f, 14.1287f, 24.8697f);
388 path.cubicTo(9.4439f, 25.1057f, 5.55359f, 25.3978f, 5.43941f, 25.5223f);
389 path.close();
390}
391
392static void build_path_simple_170666(SkPath& path) {
393 path.moveTo(126.677f, 24.1591f);
394 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
395}
396
397// This used to assert in the SK_DEBUG build, as the clip step would fail with
398// too-few interations in our cubic-line intersection code. That code now runs
399// 24 interations (instead of 16).
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000400static void test_crbug_170666() {
reed@google.com64d62952013-01-18 17:49:28 +0000401 SkPath path;
402 SkPaint paint;
403 paint.setAntiAlias(true);
404
reed3054be12014-12-10 07:24:28 -0800405 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1000, 1000));
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000406
reed@google.com64d62952013-01-18 17:49:28 +0000407 build_path_simple_170666(path);
408 surface->getCanvas()->drawPath(path, paint);
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000409
reed@google.com64d62952013-01-18 17:49:28 +0000410 build_path_170666(path);
411 surface->getCanvas()->drawPath(path, paint);
412}
413
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000414static void test_addrect(skiatest::Reporter* reporter) {
415 SkPath path;
416 path.lineTo(0, 0);
417 path.addRect(SkRect::MakeWH(50, 100));
418 REPORTER_ASSERT(reporter, path.isRect(NULL));
419
420 path.reset();
421 path.lineTo(FLT_EPSILON, FLT_EPSILON);
422 path.addRect(SkRect::MakeWH(50, 100));
423 REPORTER_ASSERT(reporter, !path.isRect(NULL));
424
425 path.reset();
426 path.quadTo(0, 0, 0, 0);
427 path.addRect(SkRect::MakeWH(50, 100));
428 REPORTER_ASSERT(reporter, !path.isRect(NULL));
429
430 path.reset();
431 path.conicTo(0, 0, 0, 0, 0.5f);
432 path.addRect(SkRect::MakeWH(50, 100));
433 REPORTER_ASSERT(reporter, !path.isRect(NULL));
434
435 path.reset();
436 path.cubicTo(0, 0, 0, 0, 0, 0);
437 path.addRect(SkRect::MakeWH(50, 100));
438 REPORTER_ASSERT(reporter, !path.isRect(NULL));
439}
440
reed@google.coma8790de2012-10-24 21:04:04 +0000441// Make sure we stay non-finite once we get there (unless we reset or rewind).
442static void test_addrect_isfinite(skiatest::Reporter* reporter) {
443 SkPath path;
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000444
reed@google.coma8790de2012-10-24 21:04:04 +0000445 path.addRect(SkRect::MakeWH(50, 100));
446 REPORTER_ASSERT(reporter, path.isFinite());
447
448 path.moveTo(0, 0);
449 path.lineTo(SK_ScalarInfinity, 42);
450 REPORTER_ASSERT(reporter, !path.isFinite());
451
452 path.addRect(SkRect::MakeWH(50, 100));
453 REPORTER_ASSERT(reporter, !path.isFinite());
454
455 path.reset();
456 REPORTER_ASSERT(reporter, path.isFinite());
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000457
reed@google.coma8790de2012-10-24 21:04:04 +0000458 path.addRect(SkRect::MakeWH(50, 100));
459 REPORTER_ASSERT(reporter, path.isFinite());
460}
461
reed@google.com848148e2013-01-15 15:51:59 +0000462static void build_big_path(SkPath* path, bool reducedCase) {
463 if (reducedCase) {
464 path->moveTo(577330, 1971.72f);
465 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
466 } else {
467 path->moveTo(60.1631f, 7.70567f);
468 path->quadTo(60.1631f, 7.70567f, 0.99474f, 0.901199f);
469 path->lineTo(577379, 1977.77f);
470 path->quadTo(577364, 1979.57f, 577325, 1980.26f);
471 path->quadTo(577286, 1980.95f, 577245, 1980.13f);
472 path->quadTo(577205, 1979.3f, 577187, 1977.45f);
473 path->quadTo(577168, 1975.6f, 577183, 1973.8f);
474 path->quadTo(577198, 1972, 577238, 1971.31f);
475 path->quadTo(577277, 1970.62f, 577317, 1971.45f);
476 path->quadTo(577330, 1971.72f, 577341, 1972.11f);
477 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
478 path->moveTo(306.718f, -32.912f);
479 path->cubicTo(30.531f, 10.0005f, 1502.47f, 13.2804f, 84.3088f, 9.99601f);
480 }
481}
482
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000483static void test_clipped_cubic() {
reed3054be12014-12-10 07:24:28 -0800484 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
reed@google.com848148e2013-01-15 15:51:59 +0000485
486 // This path used to assert, because our cubic-chopping code incorrectly
487 // moved control points after the chop. This test should be run in SK_DEBUG
488 // mode to ensure that we no long assert.
489 SkPath path;
490 for (int doReducedCase = 0; doReducedCase <= 1; ++doReducedCase) {
491 build_big_path(&path, SkToBool(doReducedCase));
skia.committer@gmail.comff21c2e2013-01-16 07:05:56 +0000492
reed@google.com848148e2013-01-15 15:51:59 +0000493 SkPaint paint;
494 for (int doAA = 0; doAA <= 1; ++doAA) {
495 paint.setAntiAlias(SkToBool(doAA));
496 surface->getCanvas()->drawPath(path, paint);
497 }
498 }
499}
500
reed@google.com8cae8352012-09-14 15:18:41 +0000501// Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/
502// which triggered an assert, from a tricky cubic. This test replicates that
503// example, so we can ensure that we handle it (in SkEdge.cpp), and don't
504// assert in the SK_DEBUG build.
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000505static void test_tricky_cubic() {
reed@google.com8cae8352012-09-14 15:18:41 +0000506 const SkPoint pts[] = {
skia.committer@gmail.com055c7c22012-09-15 02:01:41 +0000507 { SkDoubleToScalar(18.8943768), SkDoubleToScalar(129.121277) },
508 { SkDoubleToScalar(18.8937435), SkDoubleToScalar(129.121689) },
509 { SkDoubleToScalar(18.8950119), SkDoubleToScalar(129.120422) },
510 { SkDoubleToScalar(18.5030727), SkDoubleToScalar(129.13121) },
reed@google.com8cae8352012-09-14 15:18:41 +0000511 };
512
513 SkPath path;
514 path.moveTo(pts[0]);
515 path.cubicTo(pts[1], pts[2], pts[3]);
516
517 SkPaint paint;
518 paint.setAntiAlias(true);
519
reed3054be12014-12-10 07:24:28 -0800520 SkSurface* surface = SkSurface::NewRasterN32Premul(19, 130);
reed@google.com8cae8352012-09-14 15:18:41 +0000521 surface->getCanvas()->drawPath(path, paint);
522 surface->unref();
523}
reed@android.com3abec1d2009-03-02 05:36:20 +0000524
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000525// Inspired by http://code.google.com/p/chromium/issues/detail?id=141651
526//
527static void test_isfinite_after_transform(skiatest::Reporter* reporter) {
528 SkPath path;
529 path.quadTo(157, 366, 286, 208);
530 path.arcTo(37, 442, 315, 163, 957494590897113.0f);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000531
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000532 SkMatrix matrix;
533 matrix.setScale(1000*1000, 1000*1000);
534
535 // Be sure that path::transform correctly updates isFinite and the bounds
536 // if the transformation overflows. The previous bug was that isFinite was
537 // set to true in this case, but the bounds were not set to empty (which
538 // they should be).
539 while (path.isFinite()) {
540 REPORTER_ASSERT(reporter, path.getBounds().isFinite());
541 REPORTER_ASSERT(reporter, !path.getBounds().isEmpty());
542 path.transform(matrix);
543 }
544 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
545
546 matrix.setTranslate(SK_Scalar1, SK_Scalar1);
547 path.transform(matrix);
548 // we need to still be non-finite
549 REPORTER_ASSERT(reporter, !path.isFinite());
550 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
551}
552
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000553static void add_corner_arc(SkPath* path, const SkRect& rect,
554 SkScalar xIn, SkScalar yIn,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000555 int startAngle)
556{
557
558 SkScalar rx = SkMinScalar(rect.width(), xIn);
559 SkScalar ry = SkMinScalar(rect.height(), yIn);
560
561 SkRect arcRect;
562 arcRect.set(-rx, -ry, rx, ry);
563 switch (startAngle) {
564 case 0:
565 arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom);
566 break;
567 case 90:
568 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom);
569 break;
570 case 180:
571 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop);
572 break;
573 case 270:
574 arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop);
575 break;
576 default:
577 break;
578 }
579
580 path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false);
581}
582
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000583static void make_arb_round_rect(SkPath* path, const SkRect& r,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000584 SkScalar xCorner, SkScalar yCorner) {
585 // we are lazy here and use the same x & y for each corner
586 add_corner_arc(path, r, xCorner, yCorner, 270);
587 add_corner_arc(path, r, xCorner, yCorner, 0);
588 add_corner_arc(path, r, xCorner, yCorner, 90);
589 add_corner_arc(path, r, xCorner, yCorner, 180);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000590 path->close();
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000591}
592
593// Chrome creates its own round rects with each corner possibly being different.
594// Performance will suffer if they are not convex.
595// Note: PathBench::ArbRoundRectBench performs almost exactly
596// the same test (but with drawing)
597static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000598 SkRandom rand;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000599 SkRect r;
600
601 for (int i = 0; i < 5000; ++i) {
602
robertphillips@google.com158618e2012-10-23 16:56:56 +0000603 SkScalar size = rand.nextUScalar1() * 30;
604 if (size < SK_Scalar1) {
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000605 continue;
606 }
607 r.fLeft = rand.nextUScalar1() * 300;
608 r.fTop = rand.nextUScalar1() * 300;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000609 r.fRight = r.fLeft + 2 * size;
610 r.fBottom = r.fTop + 2 * size;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000611
612 SkPath temp;
613
614 make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
615
616 REPORTER_ASSERT(reporter, temp.isConvex());
617 }
618}
619
robertphillips@google.com158618e2012-10-23 16:56:56 +0000620// Chrome will sometimes create a 0 radius round rect. The degenerate
621// quads prevent the path from being converted to a rect
622// Note: PathBench::ArbRoundRectBench performs almost exactly
623// the same test (but with drawing)
624static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000625 SkRandom rand;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000626 SkRect r;
627
628 for (int i = 0; i < 5000; ++i) {
629
630 SkScalar size = rand.nextUScalar1() * 30;
631 if (size < SK_Scalar1) {
632 continue;
633 }
634 r.fLeft = rand.nextUScalar1() * 300;
635 r.fTop = rand.nextUScalar1() * 300;
636 r.fRight = r.fLeft + 2 * size;
637 r.fBottom = r.fTop + 2 * size;
638
639 SkPath temp;
640
641 make_arb_round_rect(&temp, r, 0, 0);
642
robertphillips@google.com158618e2012-10-23 16:56:56 +0000643 SkRect result;
644 REPORTER_ASSERT(reporter, temp.isRect(&result));
645 REPORTER_ASSERT(reporter, r == result);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000646 }
647}
648
reed@google.com0bb18bb2012-07-26 15:20:36 +0000649static void test_rect_isfinite(skiatest::Reporter* reporter) {
650 const SkScalar inf = SK_ScalarInfinity;
caryclark@google.com7abfa492013-04-12 11:59:41 +0000651 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000652 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000653
reed@google.com0bb18bb2012-07-26 15:20:36 +0000654 SkRect r;
655 r.setEmpty();
656 REPORTER_ASSERT(reporter, r.isFinite());
caryclark@google.com7abfa492013-04-12 11:59:41 +0000657 r.set(0, 0, inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000658 REPORTER_ASSERT(reporter, !r.isFinite());
659 r.set(0, 0, nan, 0);
660 REPORTER_ASSERT(reporter, !r.isFinite());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000661
reed@google.com0bb18bb2012-07-26 15:20:36 +0000662 SkPoint pts[] = {
663 { 0, 0 },
664 { SK_Scalar1, 0 },
665 { 0, SK_Scalar1 },
666 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000667
reed@google.com0bb18bb2012-07-26 15:20:36 +0000668 bool isFine = r.setBoundsCheck(pts, 3);
669 REPORTER_ASSERT(reporter, isFine);
670 REPORTER_ASSERT(reporter, !r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000671
reed@google.com0bb18bb2012-07-26 15:20:36 +0000672 pts[1].set(inf, 0);
673 isFine = r.setBoundsCheck(pts, 3);
674 REPORTER_ASSERT(reporter, !isFine);
675 REPORTER_ASSERT(reporter, r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000676
reed@google.com0bb18bb2012-07-26 15:20:36 +0000677 pts[1].set(nan, 0);
678 isFine = r.setBoundsCheck(pts, 3);
679 REPORTER_ASSERT(reporter, !isFine);
680 REPORTER_ASSERT(reporter, r.isEmpty());
681}
682
683static void test_path_isfinite(skiatest::Reporter* reporter) {
684 const SkScalar inf = SK_ScalarInfinity;
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000685 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000686 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000687
reed@google.com0bb18bb2012-07-26 15:20:36 +0000688 SkPath path;
689 REPORTER_ASSERT(reporter, path.isFinite());
690
691 path.reset();
692 REPORTER_ASSERT(reporter, path.isFinite());
693
694 path.reset();
695 path.moveTo(SK_Scalar1, 0);
696 REPORTER_ASSERT(reporter, path.isFinite());
697
698 path.reset();
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000699 path.moveTo(inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000700 REPORTER_ASSERT(reporter, !path.isFinite());
701
702 path.reset();
703 path.moveTo(nan, 0);
704 REPORTER_ASSERT(reporter, !path.isFinite());
705}
706
707static void test_isfinite(skiatest::Reporter* reporter) {
708 test_rect_isfinite(reporter);
709 test_path_isfinite(reporter);
710}
711
reed@google.com744faba2012-05-29 19:54:52 +0000712// assert that we always
713// start with a moveTo
714// only have 1 moveTo
715// only have Lines after that
716// end with a single close
717// only have (at most) 1 close
718//
719static void test_poly(skiatest::Reporter* reporter, const SkPath& path,
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000720 const SkPoint srcPts[], bool expectClose) {
reed@google.com744faba2012-05-29 19:54:52 +0000721 SkPath::RawIter iter(path);
722 SkPoint pts[4];
reed@google.com744faba2012-05-29 19:54:52 +0000723
724 bool firstTime = true;
725 bool foundClose = false;
726 for (;;) {
727 switch (iter.next(pts)) {
728 case SkPath::kMove_Verb:
729 REPORTER_ASSERT(reporter, firstTime);
730 REPORTER_ASSERT(reporter, pts[0] == srcPts[0]);
731 srcPts++;
732 firstTime = false;
733 break;
734 case SkPath::kLine_Verb:
735 REPORTER_ASSERT(reporter, !firstTime);
736 REPORTER_ASSERT(reporter, pts[1] == srcPts[0]);
737 srcPts++;
738 break;
739 case SkPath::kQuad_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000740 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected quad verb");
reed@google.com744faba2012-05-29 19:54:52 +0000741 break;
reed@google.com277c3f82013-05-31 15:17:50 +0000742 case SkPath::kConic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000743 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected conic verb");
reed@google.com277c3f82013-05-31 15:17:50 +0000744 break;
reed@google.com744faba2012-05-29 19:54:52 +0000745 case SkPath::kCubic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000746 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected cubic verb");
reed@google.com744faba2012-05-29 19:54:52 +0000747 break;
748 case SkPath::kClose_Verb:
749 REPORTER_ASSERT(reporter, !firstTime);
750 REPORTER_ASSERT(reporter, !foundClose);
751 REPORTER_ASSERT(reporter, expectClose);
752 foundClose = true;
753 break;
754 case SkPath::kDone_Verb:
755 goto DONE;
756 }
757 }
758DONE:
759 REPORTER_ASSERT(reporter, foundClose == expectClose);
760}
761
762static void test_addPoly(skiatest::Reporter* reporter) {
763 SkPoint pts[32];
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000764 SkRandom rand;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000765
reed@google.com744faba2012-05-29 19:54:52 +0000766 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
767 pts[i].fX = rand.nextSScalar1();
768 pts[i].fY = rand.nextSScalar1();
769 }
770
771 for (int doClose = 0; doClose <= 1; ++doClose) {
772 for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) {
773 SkPath path;
bsalomon98806072014-12-12 15:11:17 -0800774 path.addPoly(pts, SkToInt(count), SkToBool(doClose));
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000775 test_poly(reporter, path, pts, SkToBool(doClose));
reed@google.com744faba2012-05-29 19:54:52 +0000776 }
777 }
778}
779
reed@google.com8b06f1a2012-05-29 12:03:46 +0000780static void test_strokerec(skiatest::Reporter* reporter) {
781 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
782 REPORTER_ASSERT(reporter, rec.isFillStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000783
reed@google.com8b06f1a2012-05-29 12:03:46 +0000784 rec.setHairlineStyle();
785 REPORTER_ASSERT(reporter, rec.isHairlineStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000786
reed@google.com8b06f1a2012-05-29 12:03:46 +0000787 rec.setStrokeStyle(SK_Scalar1, false);
788 REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000789
reed@google.com8b06f1a2012-05-29 12:03:46 +0000790 rec.setStrokeStyle(SK_Scalar1, true);
791 REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000792
reed@google.com8b06f1a2012-05-29 12:03:46 +0000793 rec.setStrokeStyle(0, false);
794 REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000795
reed@google.com8b06f1a2012-05-29 12:03:46 +0000796 rec.setStrokeStyle(0, true);
797 REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle());
798}
799
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000800// Set this for paths that don't have a consistent direction such as a bowtie.
801// (cheapComputeDirection is not expected to catch these.)
802static const SkPath::Direction kDontCheckDir = static_cast<SkPath::Direction>(-1);
803
804static void check_direction(skiatest::Reporter* reporter, const SkPath& path,
805 SkPath::Direction expected) {
806 if (expected == kDontCheckDir) {
807 return;
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000808 }
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000809 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
810
811 SkPath::Direction dir;
812 if (copy.cheapComputeDirection(&dir)) {
813 REPORTER_ASSERT(reporter, dir == expected);
814 } else {
815 REPORTER_ASSERT(reporter, SkPath::kUnknown_Direction == expected);
816 }
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000817}
818
reed@google.com3e71a882012-01-10 18:44:37 +0000819static void test_direction(skiatest::Reporter* reporter) {
820 size_t i;
821 SkPath path;
822 REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
823 REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCW_Direction));
824 REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCCW_Direction));
reed@google.coma8a3b3d2012-11-26 18:16:27 +0000825 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kUnknown_Direction));
reed@google.com3e71a882012-01-10 18:44:37 +0000826
827 static const char* gDegen[] = {
828 "M 10 10",
829 "M 10 10 M 20 20",
830 "M 10 10 L 20 20",
831 "M 10 10 L 10 10 L 10 10",
832 "M 10 10 Q 10 10 10 10",
833 "M 10 10 C 10 10 10 10 10 10",
834 };
835 for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) {
836 path.reset();
837 bool valid = SkParsePath::FromSVGString(gDegen[i], &path);
838 REPORTER_ASSERT(reporter, valid);
839 REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
840 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000841
reed@google.com3e71a882012-01-10 18:44:37 +0000842 static const char* gCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000843 "M 10 10 L 10 10 Q 20 10 20 20",
reed@google.com3e71a882012-01-10 18:44:37 +0000844 "M 10 10 C 20 10 20 20 20 20",
reed@google.comd4146662012-01-31 15:42:29 +0000845 "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 +0000846 // rect with top two corners replaced by cubics with identical middle
847 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000848 "M 10 10 C 10 0 10 0 20 0 L 40 0 C 50 0 50 0 50 10",
849 "M 20 10 L 0 10 Q 10 10 20 0", // left, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000850 };
851 for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) {
852 path.reset();
853 bool valid = SkParsePath::FromSVGString(gCW[i], &path);
854 REPORTER_ASSERT(reporter, valid);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000855 check_direction(reporter, path, SkPath::kCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000856 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000857
reed@google.com3e71a882012-01-10 18:44:37 +0000858 static const char* gCCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000859 "M 10 10 L 10 10 Q 20 10 20 -20",
reed@google.com3e71a882012-01-10 18:44:37 +0000860 "M 10 10 C 20 10 20 -20 20 -20",
reed@google.comd4146662012-01-31 15:42:29 +0000861 "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 +0000862 // rect with top two corners replaced by cubics with identical middle
863 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000864 "M 50 10 C 50 0 50 0 40 0 L 20 0 C 10 0 10 0 10 10",
865 "M 10 10 L 30 10 Q 20 10 10 0", // right, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000866 };
867 for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) {
868 path.reset();
869 bool valid = SkParsePath::FromSVGString(gCCW[i], &path);
870 REPORTER_ASSERT(reporter, valid);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000871 check_direction(reporter, path, SkPath::kCCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000872 }
reed@google.comac8543f2012-01-30 20:51:25 +0000873
874 // Test two donuts, each wound a different direction. Only the outer contour
875 // determines the cheap direction
876 path.reset();
877 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCW_Direction);
878 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000879 check_direction(reporter, path, SkPath::kCW_Direction);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000880
reed@google.comac8543f2012-01-30 20:51:25 +0000881 path.reset();
882 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCW_Direction);
883 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000884 check_direction(reporter, path, SkPath::kCCW_Direction);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000885
886 // triangle with one point really far from the origin.
887 path.reset();
888 // the first point is roughly 1.05e10, 1.05e10
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +0000889 path.moveTo(SkBits2Float(0x501c7652), SkBits2Float(0x501c7652));
bsalomon@google.com53aab782012-02-23 14:54:49 +0000890 path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1);
891 path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000892 check_direction(reporter, path, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000893
894 path.reset();
895 path.conicTo(20, 0, 20, 20, 0.5f);
896 path.close();
897 check_direction(reporter, path, SkPath::kCW_Direction);
898
899 path.reset();
900 path.lineTo(1, 1e7f);
901 path.lineTo(1e7f, 2e7f);
902 path.close();
903 REPORTER_ASSERT(reporter, SkPath::kConvex_Convexity == path.getConvexity());
904 check_direction(reporter, path, SkPath::kCCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000905}
906
reed@google.comffdb0182011-11-14 19:29:14 +0000907static void add_rect(SkPath* path, const SkRect& r) {
908 path->moveTo(r.fLeft, r.fTop);
909 path->lineTo(r.fRight, r.fTop);
910 path->lineTo(r.fRight, r.fBottom);
911 path->lineTo(r.fLeft, r.fBottom);
912 path->close();
913}
914
915static void test_bounds(skiatest::Reporter* reporter) {
916 static const SkRect rects[] = {
reed@google.com3563c9e2011-11-14 19:34:57 +0000917 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) },
918 { SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) },
919 { SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) },
920 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) },
reed@google.comffdb0182011-11-14 19:29:14 +0000921 };
922
923 SkPath path0, path1;
924 for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) {
925 path0.addRect(rects[i]);
926 add_rect(&path1, rects[i]);
927 }
928
929 REPORTER_ASSERT(reporter, path0.getBounds() == path1.getBounds());
930}
931
reed@google.com55b5f4b2011-09-07 12:23:41 +0000932static void stroke_cubic(const SkPoint pts[4]) {
933 SkPath path;
934 path.moveTo(pts[0]);
935 path.cubicTo(pts[1], pts[2], pts[3]);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000936
reed@google.com55b5f4b2011-09-07 12:23:41 +0000937 SkPaint paint;
938 paint.setStyle(SkPaint::kStroke_Style);
939 paint.setStrokeWidth(SK_Scalar1 * 2);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000940
reed@google.com55b5f4b2011-09-07 12:23:41 +0000941 SkPath fill;
942 paint.getFillPath(path, &fill);
943}
944
945// just ensure this can run w/o any SkASSERTS firing in the debug build
946// we used to assert due to differences in how we determine a degenerate vector
947// but that was fixed with the introduction of SkPoint::CanNormalize
948static void stroke_tiny_cubic() {
949 SkPoint p0[] = {
950 { 372.0f, 92.0f },
951 { 372.0f, 92.0f },
952 { 372.0f, 92.0f },
953 { 372.0f, 92.0f },
954 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000955
reed@google.com55b5f4b2011-09-07 12:23:41 +0000956 stroke_cubic(p0);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000957
reed@google.com55b5f4b2011-09-07 12:23:41 +0000958 SkPoint p1[] = {
959 { 372.0f, 92.0f },
960 { 372.0007f, 92.000755f },
961 { 371.99927f, 92.003922f },
962 { 371.99826f, 92.003899f },
963 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000964
reed@google.com55b5f4b2011-09-07 12:23:41 +0000965 stroke_cubic(p1);
966}
967
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000968static void check_close(skiatest::Reporter* reporter, const SkPath& path) {
969 for (int i = 0; i < 2; ++i) {
robertphillips@google.com09042b82012-04-06 20:01:46 +0000970 SkPath::Iter iter(path, SkToBool(i));
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000971 SkPoint mv;
972 SkPoint pts[4];
973 SkPath::Verb v;
974 int nMT = 0;
975 int nCL = 0;
tomhudson@google.com221db3c2011-07-28 21:10:29 +0000976 mv.set(0, 0);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000977 while (SkPath::kDone_Verb != (v = iter.next(pts))) {
978 switch (v) {
979 case SkPath::kMove_Verb:
980 mv = pts[0];
981 ++nMT;
982 break;
983 case SkPath::kClose_Verb:
984 REPORTER_ASSERT(reporter, mv == pts[0]);
985 ++nCL;
986 break;
987 default:
988 break;
989 }
990 }
991 // if we force a close on the interator we should have a close
992 // for every moveTo
993 REPORTER_ASSERT(reporter, !i || nMT == nCL);
994 }
995}
996
997static void test_close(skiatest::Reporter* reporter) {
998 SkPath closePt;
999 closePt.moveTo(0, 0);
1000 closePt.close();
1001 check_close(reporter, closePt);
1002
1003 SkPath openPt;
1004 openPt.moveTo(0, 0);
1005 check_close(reporter, openPt);
1006
1007 SkPath empty;
1008 check_close(reporter, empty);
1009 empty.close();
1010 check_close(reporter, empty);
1011
1012 SkPath rect;
1013 rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1014 check_close(reporter, rect);
1015 rect.close();
1016 check_close(reporter, rect);
1017
1018 SkPath quad;
1019 quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1020 check_close(reporter, quad);
1021 quad.close();
1022 check_close(reporter, quad);
1023
1024 SkPath cubic;
rmistry@google.comd6176b02012-08-23 18:14:13 +00001025 quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1,
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001026 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1);
1027 check_close(reporter, cubic);
1028 cubic.close();
1029 check_close(reporter, cubic);
1030
1031 SkPath line;
1032 line.moveTo(SK_Scalar1, SK_Scalar1);
1033 line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1);
1034 check_close(reporter, line);
1035 line.close();
1036 check_close(reporter, line);
1037
1038 SkPath rect2;
1039 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1040 rect2.close();
1041 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1042 check_close(reporter, rect2);
1043 rect2.close();
1044 check_close(reporter, rect2);
1045
1046 SkPath oval3;
1047 oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100));
1048 oval3.close();
1049 oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200));
1050 check_close(reporter, oval3);
1051 oval3.close();
1052 check_close(reporter, oval3);
1053
1054 SkPath moves;
1055 moves.moveTo(SK_Scalar1, SK_Scalar1);
1056 moves.moveTo(5 * SK_Scalar1, SK_Scalar1);
1057 moves.moveTo(SK_Scalar1, 10 * SK_Scalar1);
1058 moves.moveTo(10 *SK_Scalar1, SK_Scalar1);
1059 check_close(reporter, moves);
reed@google.com55b5f4b2011-09-07 12:23:41 +00001060
1061 stroke_tiny_cubic();
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001062}
1063
reed@google.com7c424812011-05-15 04:38:34 +00001064static void check_convexity(skiatest::Reporter* reporter, const SkPath& path,
1065 SkPath::Convexity expected) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001066 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
1067 SkPath::Convexity c = copy.getConvexity();
reed@google.com7c424812011-05-15 04:38:34 +00001068 REPORTER_ASSERT(reporter, c == expected);
1069}
1070
1071static void test_convexity2(skiatest::Reporter* reporter) {
1072 SkPath pt;
1073 pt.moveTo(0, 0);
1074 pt.close();
reed@google.comb54455e2011-05-16 14:16:04 +00001075 check_convexity(reporter, pt, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001076 check_direction(reporter, pt, SkPath::kUnknown_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001077
reed@google.com7c424812011-05-15 04:38:34 +00001078 SkPath line;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001079 line.moveTo(12*SK_Scalar1, 20*SK_Scalar1);
1080 line.lineTo(-12*SK_Scalar1, -20*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001081 line.close();
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001082 check_convexity(reporter, line, SkPath::kConvex_Convexity);
1083 check_direction(reporter, line, SkPath::kUnknown_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001084
reed@google.com7c424812011-05-15 04:38:34 +00001085 SkPath triLeft;
1086 triLeft.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001087 triLeft.lineTo(SK_Scalar1, 0);
1088 triLeft.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001089 triLeft.close();
1090 check_convexity(reporter, triLeft, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001091 check_direction(reporter, triLeft, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001092
reed@google.com7c424812011-05-15 04:38:34 +00001093 SkPath triRight;
1094 triRight.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001095 triRight.lineTo(-SK_Scalar1, 0);
1096 triRight.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001097 triRight.close();
1098 check_convexity(reporter, triRight, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001099 check_direction(reporter, triRight, SkPath::kCCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001100
reed@google.com7c424812011-05-15 04:38:34 +00001101 SkPath square;
1102 square.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001103 square.lineTo(SK_Scalar1, 0);
1104 square.lineTo(SK_Scalar1, SK_Scalar1);
1105 square.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001106 square.close();
1107 check_convexity(reporter, square, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001108 check_direction(reporter, square, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001109
reed@google.com7c424812011-05-15 04:38:34 +00001110 SkPath redundantSquare;
1111 redundantSquare.moveTo(0, 0);
1112 redundantSquare.lineTo(0, 0);
1113 redundantSquare.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001114 redundantSquare.lineTo(SK_Scalar1, 0);
1115 redundantSquare.lineTo(SK_Scalar1, 0);
1116 redundantSquare.lineTo(SK_Scalar1, 0);
1117 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1118 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1119 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1120 redundantSquare.lineTo(0, SK_Scalar1);
1121 redundantSquare.lineTo(0, SK_Scalar1);
1122 redundantSquare.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001123 redundantSquare.close();
1124 check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001125 check_direction(reporter, redundantSquare, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001126
reed@google.com7c424812011-05-15 04:38:34 +00001127 SkPath bowTie;
1128 bowTie.moveTo(0, 0);
1129 bowTie.lineTo(0, 0);
1130 bowTie.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001131 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1132 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1133 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1134 bowTie.lineTo(SK_Scalar1, 0);
1135 bowTie.lineTo(SK_Scalar1, 0);
1136 bowTie.lineTo(SK_Scalar1, 0);
1137 bowTie.lineTo(0, SK_Scalar1);
1138 bowTie.lineTo(0, SK_Scalar1);
1139 bowTie.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001140 bowTie.close();
1141 check_convexity(reporter, bowTie, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001142 check_direction(reporter, bowTie, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001143
reed@google.com7c424812011-05-15 04:38:34 +00001144 SkPath spiral;
1145 spiral.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001146 spiral.lineTo(100*SK_Scalar1, 0);
1147 spiral.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1148 spiral.lineTo(0, 100*SK_Scalar1);
1149 spiral.lineTo(0, 50*SK_Scalar1);
1150 spiral.lineTo(50*SK_Scalar1, 50*SK_Scalar1);
1151 spiral.lineTo(50*SK_Scalar1, 75*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001152 spiral.close();
reed@google.com85b6e392011-05-15 20:25:17 +00001153 check_convexity(reporter, spiral, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001154 check_direction(reporter, spiral, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001155
reed@google.com7c424812011-05-15 04:38:34 +00001156 SkPath dent;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001157 dent.moveTo(0, 0);
1158 dent.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1159 dent.lineTo(0, 100*SK_Scalar1);
1160 dent.lineTo(-50*SK_Scalar1, 200*SK_Scalar1);
1161 dent.lineTo(-200*SK_Scalar1, 100*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001162 dent.close();
1163 check_convexity(reporter, dent, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001164 check_direction(reporter, dent, SkPath::kCW_Direction);
commit-bot@chromium.org8be07bb2014-05-22 14:58:53 +00001165
1166 // http://skbug.com/2235
1167 SkPath strokedSin;
1168 for (int i = 0; i < 2000; i++) {
1169 SkScalar x = SkIntToScalar(i) / 2;
1170 SkScalar y = 500 - (x + SkScalarSin(x / 100) * 40) / 3;
1171 if (0 == i) {
1172 strokedSin.moveTo(x, y);
1173 } else {
1174 strokedSin.lineTo(x, y);
1175 }
1176 }
1177 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
1178 stroke.setStrokeStyle(2 * SK_Scalar1);
1179 stroke.applyToPath(&strokedSin, strokedSin);
1180 check_convexity(reporter, strokedSin, SkPath::kConcave_Convexity);
1181 check_direction(reporter, strokedSin, kDontCheckDir);
robertphillipsc506e302014-09-16 09:43:31 -07001182
1183 // http://crbug.com/412640
1184 SkPath degenerateConcave;
1185 degenerateConcave.moveTo(148.67912f, 191.875f);
1186 degenerateConcave.lineTo(470.37695f, 7.5f);
1187 degenerateConcave.lineTo(148.67912f, 191.875f);
1188 degenerateConcave.lineTo(41.446522f, 376.25f);
1189 degenerateConcave.lineTo(-55.971577f, 460.0f);
1190 degenerateConcave.lineTo(41.446522f, 376.25f);
1191 check_convexity(reporter, degenerateConcave, SkPath::kConcave_Convexity);
1192 check_direction(reporter, degenerateConcave, SkPath::kUnknown_Direction);
robertphillipsf52a0632014-11-17 12:11:42 -08001193
1194 // http://crbug.com/433683
1195 SkPath badFirstVector;
1196 badFirstVector.moveTo(501.087708f, 319.610352f);
1197 badFirstVector.lineTo(501.087708f, 319.610352f);
1198 badFirstVector.cubicTo(501.087677f, 319.610321f, 449.271606f, 258.078674f, 395.084564f, 198.711182f);
1199 badFirstVector.cubicTo(358.967072f, 159.140717f, 321.910553f, 120.650436f, 298.442322f, 101.955399f);
1200 badFirstVector.lineTo(301.557678f, 98.044601f);
1201 badFirstVector.cubicTo(325.283844f, 116.945084f, 362.615204f, 155.720825f, 398.777557f, 195.340454f);
1202 badFirstVector.cubicTo(453.031860f, 254.781662f, 504.912262f, 316.389618f, 504.912292f, 316.389648f);
1203 badFirstVector.lineTo(504.912292f, 316.389648f);
1204 badFirstVector.lineTo(501.087708f, 319.610352f);
1205 badFirstVector.close();
1206 check_convexity(reporter, badFirstVector, SkPath::kConcave_Convexity);
reed@google.com7c424812011-05-15 04:38:34 +00001207}
1208
reed@android.com6b82d1a2009-06-03 02:35:01 +00001209static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
1210 const SkRect& bounds) {
1211 REPORTER_ASSERT(reporter, p.isConvex());
1212 REPORTER_ASSERT(reporter, p.getBounds() == bounds);
reed@google.com62047cf2011-02-07 19:39:09 +00001213
reed@android.com6b82d1a2009-06-03 02:35:01 +00001214 SkPath p2(p);
1215 REPORTER_ASSERT(reporter, p2.isConvex());
1216 REPORTER_ASSERT(reporter, p2.getBounds() == bounds);
1217
1218 SkPath other;
1219 other.swap(p2);
1220 REPORTER_ASSERT(reporter, other.isConvex());
1221 REPORTER_ASSERT(reporter, other.getBounds() == bounds);
1222}
1223
reed@google.com04863fa2011-05-15 04:08:24 +00001224static void setFromString(SkPath* path, const char str[]) {
1225 bool first = true;
1226 while (str) {
1227 SkScalar x, y;
1228 str = SkParse::FindScalar(str, &x);
1229 if (NULL == str) {
1230 break;
1231 }
1232 str = SkParse::FindScalar(str, &y);
1233 SkASSERT(str);
1234 if (first) {
1235 path->moveTo(x, y);
1236 first = false;
1237 } else {
1238 path->lineTo(x, y);
1239 }
1240 }
1241}
1242
1243static void test_convexity(skiatest::Reporter* reporter) {
reed@google.com04863fa2011-05-15 04:08:24 +00001244 SkPath path;
1245
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001246 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001247 path.addCircle(0, 0, SkIntToScalar(10));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001248 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001249 path.addCircle(0, 0, SkIntToScalar(10)); // 2nd circle
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001250 check_convexity(reporter, path, SkPath::kConcave_Convexity);
1251
reed@google.com04863fa2011-05-15 04:08:24 +00001252 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001253 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001254 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.com3e71a882012-01-10 18:44:37 +00001255 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCCW_Direction));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001256
reed@google.com04863fa2011-05-15 04:08:24 +00001257 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001258 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001259 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.com3e71a882012-01-10 18:44:37 +00001260 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCW_Direction));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001261
reed@google.com04863fa2011-05-15 04:08:24 +00001262 static const struct {
1263 const char* fPathStr;
1264 SkPath::Convexity fExpectedConvexity;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001265 SkPath::Direction fExpectedDirection;
reed@google.com04863fa2011-05-15 04:08:24 +00001266 } gRec[] = {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001267 { "", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1268 { "0 0", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1269 { "0 0 10 10", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1270 { "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity, SkPath::kUnknown_Direction },
1271 { "0 0 10 10 10 20", SkPath::kConvex_Convexity, SkPath::kCW_Direction },
1272 { "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPath::kCCW_Direction },
1273 { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir },
1274 { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity, SkPath::kCW_Direction },
reed@google.com04863fa2011-05-15 04:08:24 +00001275 };
1276
1277 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1278 SkPath path;
1279 setFromString(&path, gRec[i].fPathStr);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001280 check_convexity(reporter, path, gRec[i].fExpectedConvexity);
1281 check_direction(reporter, path, gRec[i].fExpectedDirection);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001282 // check after setting the initial convex and direction
1283 if (kDontCheckDir != gRec[i].fExpectedDirection) {
1284 SkPath copy(path);
1285 SkPath::Direction dir;
1286 bool foundDir = copy.cheapComputeDirection(&dir);
1287 REPORTER_ASSERT(reporter, (gRec[i].fExpectedDirection == SkPath::kUnknown_Direction)
1288 ^ foundDir);
1289 REPORTER_ASSERT(reporter, !foundDir || gRec[i].fExpectedDirection == dir);
1290 check_convexity(reporter, copy, gRec[i].fExpectedConvexity);
1291 }
1292 REPORTER_ASSERT(reporter, gRec[i].fExpectedConvexity == path.getConvexity());
1293 check_direction(reporter, path, gRec[i].fExpectedDirection);
reed@google.com04863fa2011-05-15 04:08:24 +00001294 }
caryclarkd3d1a982014-12-08 04:57:38 -08001295
1296 static const SkPoint nonFinitePts[] = {
1297 { SK_ScalarInfinity, 0 },
1298 { 0, SK_ScalarInfinity },
1299 { SK_ScalarInfinity, SK_ScalarInfinity },
1300 { SK_ScalarNegativeInfinity, 0},
1301 { 0, SK_ScalarNegativeInfinity },
1302 { SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity },
1303 { SK_ScalarNegativeInfinity, SK_ScalarInfinity },
1304 { SK_ScalarInfinity, SK_ScalarNegativeInfinity },
1305 { SK_ScalarNaN, 0 },
1306 { 0, SK_ScalarNaN },
1307 { SK_ScalarNaN, SK_ScalarNaN },
1308 };
1309
1310 const size_t nonFinitePtsCount = sizeof(nonFinitePts) / sizeof(nonFinitePts[0]);
1311
1312 static const SkPoint finitePts[] = {
1313 { SK_ScalarMax, 0 },
1314 { 0, SK_ScalarMax },
1315 { SK_ScalarMax, SK_ScalarMax },
1316 { SK_ScalarMin, 0 },
1317 { 0, SK_ScalarMin },
1318 { SK_ScalarMin, SK_ScalarMin },
1319 };
1320
1321 const size_t finitePtsCount = sizeof(finitePts) / sizeof(finitePts[0]);
1322
1323 for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount); ++index) {
1324 int i = (int) (index % nonFinitePtsCount);
1325 int f = (int) (index % finitePtsCount);
1326 int g = (int) ((f + 1) % finitePtsCount);
1327 path.reset();
1328 switch (index % 13) {
1329 case 0: path.lineTo(nonFinitePts[i]); break;
1330 case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break;
1331 case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break;
1332 case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break;
1333 case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); break;
1334 case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); break;
1335 case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); break;
1336 case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f]); break;
1337 case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i]); break;
1338 case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i]); break;
1339 case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts[i]); break;
1340 case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]); break;
1341 case 12: path.moveTo(nonFinitePts[i]); break;
1342 }
1343 check_convexity(reporter, path, SkPath::kUnknown_Convexity);
1344 }
1345
1346 for (int index = 0; index < (int) (11 * finitePtsCount); ++index) {
1347 int f = (int) (index % finitePtsCount);
1348 int g = (int) ((f + 1) % finitePtsCount);
1349 path.reset();
1350 int curveSelect = index % 11;
1351 switch (curveSelect) {
1352 case 0: path.moveTo(finitePts[f]); break;
1353 case 1: path.lineTo(finitePts[f]); break;
1354 case 2: path.quadTo(finitePts[f], finitePts[f]); break;
1355 case 3: path.quadTo(finitePts[f], finitePts[g]); break;
1356 case 4: path.quadTo(finitePts[g], finitePts[f]); break;
1357 case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); break;
1358 case 6: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); break;
1359 case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); break;
1360 case 8: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); break;
1361 case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); break;
1362 case 10: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); break;
1363 }
1364 check_convexity(reporter, path, curveSelect == 0 ? SkPath::kConvex_Convexity
1365 : SkPath::kUnknown_Convexity);
1366 }
1367
reed@google.com04863fa2011-05-15 04:08:24 +00001368}
1369
reed@google.com7e6c4d12012-05-10 14:05:43 +00001370static void test_isLine(skiatest::Reporter* reporter) {
1371 SkPath path;
1372 SkPoint pts[2];
1373 const SkScalar value = SkIntToScalar(5);
1374
1375 REPORTER_ASSERT(reporter, !path.isLine(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001376
reed@google.com7e6c4d12012-05-10 14:05:43 +00001377 // set some non-zero values
1378 pts[0].set(value, value);
1379 pts[1].set(value, value);
1380 REPORTER_ASSERT(reporter, !path.isLine(pts));
1381 // check that pts was untouched
1382 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1383 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1384
1385 const SkScalar moveX = SkIntToScalar(1);
1386 const SkScalar moveY = SkIntToScalar(2);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001387 REPORTER_ASSERT(reporter, value != moveX && value != moveY);
reed@google.com7e6c4d12012-05-10 14:05:43 +00001388
1389 path.moveTo(moveX, moveY);
1390 REPORTER_ASSERT(reporter, !path.isLine(NULL));
1391 REPORTER_ASSERT(reporter, !path.isLine(pts));
1392 // check that pts was untouched
1393 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1394 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1395
1396 const SkScalar lineX = SkIntToScalar(2);
1397 const SkScalar lineY = SkIntToScalar(2);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001398 REPORTER_ASSERT(reporter, value != lineX && value != lineY);
reed@google.com7e6c4d12012-05-10 14:05:43 +00001399
1400 path.lineTo(lineX, lineY);
1401 REPORTER_ASSERT(reporter, path.isLine(NULL));
1402
1403 REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY));
1404 REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY));
1405 REPORTER_ASSERT(reporter, path.isLine(pts));
1406 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1407 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
1408
1409 path.lineTo(0, 0); // too many points/verbs
1410 REPORTER_ASSERT(reporter, !path.isLine(NULL));
1411 REPORTER_ASSERT(reporter, !path.isLine(pts));
1412 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1413 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001414
1415 path.reset();
1416 path.quadTo(1, 1, 2, 2);
1417 REPORTER_ASSERT(reporter, !path.isLine(NULL));
reed@google.com7e6c4d12012-05-10 14:05:43 +00001418}
1419
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001420static void test_conservativelyContains(skiatest::Reporter* reporter) {
1421 SkPath path;
1422
1423 // kBaseRect is used to construct most our test paths: a rect, a circle, and a round-rect.
1424 static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
1425
1426 // A circle that bounds kBaseRect (with a significant amount of slop)
1427 SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height());
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001428 circleR = SkScalarMul(circleR, 1.75f) / 2;
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001429 static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()};
1430
1431 // round-rect radii
1432 static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)};
skia.committer@gmail.comcec8de62012-11-14 02:01:22 +00001433
caryclark@google.com56f233a2012-11-19 13:06:06 +00001434 static const struct SUPPRESS_VISIBILITY_WARNING {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001435 SkRect fQueryRect;
1436 bool fInRect;
1437 bool fInCircle;
1438 bool fInRR;
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001439 bool fInCubicRR;
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001440 } kQueries[] = {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001441 {kBaseRect, true, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001442
1443 // rect well inside of kBaseRect
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001444 {SkRect::MakeLTRB(kBaseRect.fLeft + 0.25f*kBaseRect.width(),
1445 kBaseRect.fTop + 0.25f*kBaseRect.height(),
1446 kBaseRect.fRight - 0.25f*kBaseRect.width(),
1447 kBaseRect.fBottom - 0.25f*kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001448 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001449
1450 // rects with edges off by one from kBaseRect's edges
1451 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1452 kBaseRect.width(), kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001453 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001454 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1455 kBaseRect.width() + 1, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001456 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001457 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1458 kBaseRect.width() + 1, kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001459 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001460 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1461 kBaseRect.width(), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001462 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001463 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1464 kBaseRect.width(), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001465 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001466 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1467 kBaseRect.width() + 2, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001468 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001469 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1470 kBaseRect.width() + 2, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001471 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001472
1473 // zero-w/h rects at each corner of kBaseRect
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001474 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, false, false},
1475 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, false, true},
1476 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true, false, true},
1477 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true, false, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001478
1479 // far away rect
1480 {SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom,
1481 SkIntToScalar(10), SkIntToScalar(10)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001482 false, false, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001483
1484 // very large rect containing kBaseRect
1485 {SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(),
1486 kBaseRect.fTop - 5 * kBaseRect.height(),
1487 11 * kBaseRect.width(), 11 * kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001488 false, false, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001489
1490 // skinny rect that spans same y-range as kBaseRect
1491 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1492 SkIntToScalar(1), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001493 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001494
1495 // short rect that spans same x-range as kBaseRect
1496 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(), SkScalar(1)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001497 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001498
1499 // skinny rect that spans slightly larger y-range than kBaseRect
1500 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1501 SkIntToScalar(1), kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001502 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001503
1504 // short rect that spans slightly larger x-range than kBaseRect
1505 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(),
1506 kBaseRect.width() + 1, SkScalar(1)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001507 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001508 };
1509
1510 for (int inv = 0; inv < 4; ++inv) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001511 for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001512 SkRect qRect = kQueries[q].fQueryRect;
1513 if (inv & 0x1) {
1514 SkTSwap(qRect.fLeft, qRect.fRight);
1515 }
1516 if (inv & 0x2) {
1517 SkTSwap(qRect.fTop, qRect.fBottom);
1518 }
1519 for (int d = 0; d < 2; ++d) {
1520 SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
1521 path.reset();
1522 path.addRect(kBaseRect, dir);
1523 REPORTER_ASSERT(reporter, kQueries[q].fInRect ==
1524 path.conservativelyContainsRect(qRect));
1525
1526 path.reset();
1527 path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir);
1528 REPORTER_ASSERT(reporter, kQueries[q].fInCircle ==
1529 path.conservativelyContainsRect(qRect));
1530
1531 path.reset();
1532 path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir);
1533 REPORTER_ASSERT(reporter, kQueries[q].fInRR ==
1534 path.conservativelyContainsRect(qRect));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001535
1536 path.reset();
1537 path.moveTo(kBaseRect.fLeft + kRRRadii[0], kBaseRect.fTop);
1538 path.cubicTo(kBaseRect.fLeft + kRRRadii[0] / 2, kBaseRect.fTop,
1539 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1] / 2,
1540 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1]);
1541 path.lineTo(kBaseRect.fLeft, kBaseRect.fBottom);
1542 path.lineTo(kBaseRect.fRight, kBaseRect.fBottom);
1543 path.lineTo(kBaseRect.fRight, kBaseRect.fTop);
1544 path.close();
1545 REPORTER_ASSERT(reporter, kQueries[q].fInCubicRR ==
1546 path.conservativelyContainsRect(qRect));
1547
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001548 }
1549 // Slightly non-convex shape, shouldn't contain any rects.
1550 path.reset();
1551 path.moveTo(0, 0);
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001552 path.lineTo(SkIntToScalar(50), 0.05f);
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001553 path.lineTo(SkIntToScalar(100), 0);
1554 path.lineTo(SkIntToScalar(100), SkIntToScalar(100));
1555 path.lineTo(0, SkIntToScalar(100));
1556 path.close();
1557 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect));
1558 }
1559 }
1560
1561 // make sure a minimal convex shape works, a right tri with edges along pos x and y axes.
1562 path.reset();
1563 path.moveTo(0, 0);
1564 path.lineTo(SkIntToScalar(100), 0);
1565 path.lineTo(0, SkIntToScalar(100));
1566
1567 // inside, on along top edge
1568 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1569 SkIntToScalar(10),
1570 SkIntToScalar(10))));
1571 // above
1572 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1573 SkRect::MakeXYWH(SkIntToScalar(50),
1574 SkIntToScalar(-10),
1575 SkIntToScalar(10),
1576 SkIntToScalar(10))));
1577 // to the left
1578 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(-10),
1579 SkIntToScalar(5),
1580 SkIntToScalar(5),
1581 SkIntToScalar(5))));
1582
1583 // outside the diagonal edge
1584 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(10),
1585 SkIntToScalar(200),
1586 SkIntToScalar(20),
1587 SkIntToScalar(5))));
commit-bot@chromium.org62df5262013-08-01 15:35:06 +00001588
bsalomonb17c1292014-08-28 14:04:55 -07001589
1590 // Test that multiple move commands do not cause asserts.
1591
1592 // At the time of writing, this would not modify cached convexity. This caused an assert while
1593 // checking conservative containment again. http://skbug.com/1460
1594 path.moveTo(SkIntToScalar(100), SkIntToScalar(100));
1595#if 0
1596 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1597 SkIntToScalar(10),
1598 SkIntToScalar(10))));
1599#endif
1600
1601 // Same as above path and first test but with an extra moveTo.
commit-bot@chromium.org62df5262013-08-01 15:35:06 +00001602 path.reset();
1603 path.moveTo(100, 100);
1604 path.moveTo(0, 0);
1605 path.lineTo(SkIntToScalar(100), 0);
1606 path.lineTo(0, SkIntToScalar(100));
1607
1608 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1609 SkIntToScalar(10),
1610 SkIntToScalar(10))));
1611
bsalomonb17c1292014-08-28 14:04:55 -07001612 // Test that multiple move commands do not cause asserts and that the function
1613 // is not confused by the multiple moves.
1614 path.reset();
1615 path.moveTo(0, 0);
1616 path.lineTo(SkIntToScalar(100), 0);
1617 path.lineTo(0, SkIntToScalar(100));
1618 path.moveTo(0, SkIntToScalar(200));
1619 path.lineTo(SkIntToScalar(100), SkIntToScalar(200));
1620 path.lineTo(0, SkIntToScalar(300));
1621
1622 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1623 SkRect::MakeXYWH(SkIntToScalar(50), 0,
1624 SkIntToScalar(10),
1625 SkIntToScalar(10))));
1626
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001627 path.reset();
1628 path.lineTo(100, 100);
1629 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(0, 0, 1, 1)));
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001630}
1631
reed@google.comf32322b2013-10-16 15:14:04 +00001632static void test_isRect_open_close(skiatest::Reporter* reporter) {
1633 SkPath path;
1634 bool isClosed;
1635
1636 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1);
reed@google.comf32322b2013-10-16 15:14:04 +00001637 path.close();
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00001638
robertphillips91b0a352015-01-05 10:13:46 -08001639 REPORTER_ASSERT(reporter, path.isRect(NULL, &isClosed, NULL));
reed@google.comf32322b2013-10-16 15:14:04 +00001640 REPORTER_ASSERT(reporter, isClosed);
1641}
1642
caryclark@google.comf1316942011-07-26 19:54:45 +00001643// Simple isRect test is inline TestPath, below.
1644// test_isRect provides more extensive testing.
1645static void test_isRect(skiatest::Reporter* reporter) {
reed@google.comf32322b2013-10-16 15:14:04 +00001646 test_isRect_open_close(reporter);
1647
caryclark@google.comf1316942011-07-26 19:54:45 +00001648 // passing tests (all moveTo / lineTo...
1649 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1650 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1651 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1652 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
1653 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
1654 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1655 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1656 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1657 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001658 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}};
1659 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 +00001660 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}};
1661 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
1662 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}};
caryclark@google.combfe90372012-11-21 13:56:20 +00001663 SkPoint rf[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}};
rmistry@google.comd6176b02012-08-23 18:14:13 +00001664
caryclark@google.comf1316942011-07-26 19:54:45 +00001665 // failing tests
1666 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1667 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1668 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1669 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1670 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1671 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1672 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1673 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
caryclark@google.combfe90372012-11-21 13:56:20 +00001674 SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps
1675 SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non colinear gap
1676 SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short
rmistry@google.comd6176b02012-08-23 18:14:13 +00001677
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00001678 // no close, but we should detect them as fillably the same as a rect
1679 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1680 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}};
1681 SkPoint c3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 0}}; // hit the start
1682
1683 // like c2, but we double-back on ourselves
1684 SkPoint d1[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 2}};
1685 // like c2, but we overshoot the start point
1686 SkPoint d2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}};
1687 SkPoint d3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}, {0, 0}};
caryclark@google.comf1316942011-07-26 19:54:45 +00001688
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001689 struct IsRectTest {
1690 SkPoint *fPoints;
bsalomon98806072014-12-12 15:11:17 -08001691 int fPointCount;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001692 bool fClose;
1693 bool fIsRect;
1694 } tests[] = {
1695 { r1, SK_ARRAY_COUNT(r1), true, true },
1696 { r2, SK_ARRAY_COUNT(r2), true, true },
1697 { r3, SK_ARRAY_COUNT(r3), true, true },
1698 { r4, SK_ARRAY_COUNT(r4), true, true },
1699 { r5, SK_ARRAY_COUNT(r5), true, true },
1700 { r6, SK_ARRAY_COUNT(r6), true, true },
1701 { r7, SK_ARRAY_COUNT(r7), true, true },
1702 { r8, SK_ARRAY_COUNT(r8), true, true },
1703 { r9, SK_ARRAY_COUNT(r9), true, true },
1704 { ra, SK_ARRAY_COUNT(ra), true, true },
1705 { rb, SK_ARRAY_COUNT(rb), true, true },
1706 { rc, SK_ARRAY_COUNT(rc), true, true },
1707 { rd, SK_ARRAY_COUNT(rd), true, true },
1708 { re, SK_ARRAY_COUNT(re), true, true },
1709 { rf, SK_ARRAY_COUNT(rf), true, true },
1710
1711 { f1, SK_ARRAY_COUNT(f1), true, false },
1712 { f2, SK_ARRAY_COUNT(f2), true, false },
1713 { f3, SK_ARRAY_COUNT(f3), true, false },
1714 { f4, SK_ARRAY_COUNT(f4), true, false },
1715 { f5, SK_ARRAY_COUNT(f5), true, false },
1716 { f6, SK_ARRAY_COUNT(f6), true, false },
1717 { f7, SK_ARRAY_COUNT(f7), true, false },
1718 { f8, SK_ARRAY_COUNT(f8), true, false },
1719 { f9, SK_ARRAY_COUNT(f9), true, false },
1720 { fa, SK_ARRAY_COUNT(fa), true, false },
1721 { fb, SK_ARRAY_COUNT(fb), true, false },
1722
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00001723 { c1, SK_ARRAY_COUNT(c1), false, true },
1724 { c2, SK_ARRAY_COUNT(c2), false, true },
1725 { c3, SK_ARRAY_COUNT(c3), false, true },
1726
1727 { d1, SK_ARRAY_COUNT(d1), false, false },
1728 { d2, SK_ARRAY_COUNT(d2), false, false },
1729 { d3, SK_ARRAY_COUNT(d3), false, false },
caryclark@google.comf1316942011-07-26 19:54:45 +00001730 };
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001731
1732 const size_t testCount = SK_ARRAY_COUNT(tests);
bsalomon98806072014-12-12 15:11:17 -08001733 int index;
caryclark@google.comf1316942011-07-26 19:54:45 +00001734 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1735 SkPath path;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001736 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1737 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1738 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.comf1316942011-07-26 19:54:45 +00001739 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001740 if (tests[testIndex].fClose) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001741 path.close();
1742 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001743 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001744
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001745 if (tests[testIndex].fIsRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001746 SkRect computed, expected;
caryclark@google.comf68154a2012-11-21 15:18:06 +00001747 bool isClosed;
1748 SkPath::Direction direction, cheapDirection;
robertphillips91b0a352015-01-05 10:13:46 -08001749 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001750 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection));
robertphillips91b0a352015-01-05 10:13:46 -08001751 REPORTER_ASSERT(reporter, path.isRect(&computed, &isClosed, &direction));
1752 REPORTER_ASSERT(reporter, expected == computed);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001753 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001754 REPORTER_ASSERT(reporter, direction == cheapDirection);
1755 } else {
1756 SkRect computed;
1757 computed.set(123, 456, 789, 1011);
robertphillips91b0a352015-01-05 10:13:46 -08001758 bool isClosed = (bool)-1;
1759 SkPath::Direction direction = (SkPath::Direction) - 1;
1760 REPORTER_ASSERT(reporter, !path.isRect(&computed, &isClosed, &direction));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001761 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456);
1762 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001763 REPORTER_ASSERT(reporter, isClosed == (bool) -1);
1764 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001765 }
caryclark@google.comf1316942011-07-26 19:54:45 +00001766 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00001767
caryclark@google.comf1316942011-07-26 19:54:45 +00001768 // fail, close then line
1769 SkPath path1;
1770 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001771 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001772 path1.lineTo(r1[index].fX, r1[index].fY);
1773 }
1774 path1.close();
1775 path1.lineTo(1, 0);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001776 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001777
caryclark@google.comf1316942011-07-26 19:54:45 +00001778 // fail, move in the middle
1779 path1.reset();
1780 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001781 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001782 if (index == 2) {
1783 path1.moveTo(1, .5f);
1784 }
1785 path1.lineTo(r1[index].fX, r1[index].fY);
1786 }
1787 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001788 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00001789
1790 // fail, move on the edge
1791 path1.reset();
bsalomon98806072014-12-12 15:11:17 -08001792 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001793 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1794 path1.lineTo(r1[index].fX, r1[index].fY);
1795 }
1796 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001797 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001798
caryclark@google.comf1316942011-07-26 19:54:45 +00001799 // fail, quad
1800 path1.reset();
1801 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001802 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001803 if (index == 2) {
1804 path1.quadTo(1, .5f, 1, .5f);
1805 }
1806 path1.lineTo(r1[index].fX, r1[index].fY);
1807 }
1808 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001809 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001810
caryclark@google.comf1316942011-07-26 19:54:45 +00001811 // fail, cubic
1812 path1.reset();
1813 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001814 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001815 if (index == 2) {
1816 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1817 }
1818 path1.lineTo(r1[index].fX, r1[index].fY);
1819 }
1820 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001821 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00001822}
1823
caryclark@google.com56f233a2012-11-19 13:06:06 +00001824static void test_isNestedRects(skiatest::Reporter* reporter) {
1825 // passing tests (all moveTo / lineTo...
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001826 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001827 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1828 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1829 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001830 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001831 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1832 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1833 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1834 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001835 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; // CCW
1836 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 +00001837 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW
1838 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW
1839 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001840
1841 // failing tests
1842 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1843 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1844 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1845 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1846 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1847 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1848 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1849 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
1850
1851 // failing, no close
1852 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
1853 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
1854
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001855 struct IsNestedRectTest {
1856 SkPoint *fPoints;
bsalomon98806072014-12-12 15:11:17 -08001857 int fPointCount;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001858 SkPath::Direction fDirection;
1859 bool fClose;
1860 bool fIsNestedRect; // nests with path.addRect(-1, -1, 2, 2);
1861 } tests[] = {
1862 { r1, SK_ARRAY_COUNT(r1), SkPath::kCW_Direction , true, true },
1863 { r2, SK_ARRAY_COUNT(r2), SkPath::kCW_Direction , true, true },
1864 { r3, SK_ARRAY_COUNT(r3), SkPath::kCW_Direction , true, true },
1865 { r4, SK_ARRAY_COUNT(r4), SkPath::kCW_Direction , true, true },
1866 { r5, SK_ARRAY_COUNT(r5), SkPath::kCCW_Direction, true, true },
1867 { r6, SK_ARRAY_COUNT(r6), SkPath::kCCW_Direction, true, true },
1868 { r7, SK_ARRAY_COUNT(r7), SkPath::kCCW_Direction, true, true },
1869 { r8, SK_ARRAY_COUNT(r8), SkPath::kCCW_Direction, true, true },
1870 { r9, SK_ARRAY_COUNT(r9), SkPath::kCCW_Direction, true, true },
1871 { ra, SK_ARRAY_COUNT(ra), SkPath::kCCW_Direction, true, true },
1872 { rb, SK_ARRAY_COUNT(rb), SkPath::kCW_Direction, true, true },
1873 { rc, SK_ARRAY_COUNT(rc), SkPath::kCW_Direction, true, true },
1874 { rd, SK_ARRAY_COUNT(rd), SkPath::kCCW_Direction, true, true },
1875 { re, SK_ARRAY_COUNT(re), SkPath::kCW_Direction, true, true },
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001876
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001877 { f1, SK_ARRAY_COUNT(f1), SkPath::kUnknown_Direction, true, false },
1878 { f2, SK_ARRAY_COUNT(f2), SkPath::kUnknown_Direction, true, false },
1879 { f3, SK_ARRAY_COUNT(f3), SkPath::kUnknown_Direction, true, false },
1880 { f4, SK_ARRAY_COUNT(f4), SkPath::kUnknown_Direction, true, false },
1881 { f5, SK_ARRAY_COUNT(f5), SkPath::kUnknown_Direction, true, false },
1882 { f6, SK_ARRAY_COUNT(f6), SkPath::kUnknown_Direction, true, false },
1883 { f7, SK_ARRAY_COUNT(f7), SkPath::kUnknown_Direction, true, false },
1884 { f8, SK_ARRAY_COUNT(f8), SkPath::kUnknown_Direction, true, false },
1885
1886 { c1, SK_ARRAY_COUNT(c1), SkPath::kUnknown_Direction, false, false },
1887 { c2, SK_ARRAY_COUNT(c2), SkPath::kUnknown_Direction, false, false },
1888 };
1889
1890 const size_t testCount = SK_ARRAY_COUNT(tests);
bsalomon98806072014-12-12 15:11:17 -08001891 int index;
caryclark@google.com56f233a2012-11-19 13:06:06 +00001892 for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001893 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1894 SkPath path;
1895 if (rectFirst) {
1896 path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1897 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001898 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1899 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1900 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001901 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001902 if (tests[testIndex].fClose) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001903 path.close();
1904 }
1905 if (!rectFirst) {
1906 path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1907 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001908 REPORTER_ASSERT(reporter, tests[testIndex].fIsNestedRect == path.isNestedRects(NULL));
1909 if (tests[testIndex].fIsNestedRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001910 SkRect expected[2], computed[2];
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001911 SkPath::Direction expectedDirs[2], computedDirs[2];
caryclark@google.com56f233a2012-11-19 13:06:06 +00001912 SkRect testBounds;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001913 testBounds.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001914 expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2);
1915 expected[1] = testBounds;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001916 if (rectFirst) {
1917 expectedDirs[0] = SkPath::kCW_Direction;
1918 } else {
1919 expectedDirs[0] = SkPath::kCCW_Direction;
1920 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001921 expectedDirs[1] = tests[testIndex].fDirection;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001922 REPORTER_ASSERT(reporter, path.isNestedRects(computed, computedDirs));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001923 REPORTER_ASSERT(reporter, expected[0] == computed[0]);
1924 REPORTER_ASSERT(reporter, expected[1] == computed[1]);
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001925 REPORTER_ASSERT(reporter, expectedDirs[0] == computedDirs[0]);
1926 REPORTER_ASSERT(reporter, expectedDirs[1] == computedDirs[1]);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001927 }
caryclark@google.com56f233a2012-11-19 13:06:06 +00001928 }
1929
1930 // fail, close then line
1931 SkPath path1;
1932 if (rectFirst) {
1933 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1934 }
1935 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001936 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001937 path1.lineTo(r1[index].fX, r1[index].fY);
1938 }
1939 path1.close();
1940 path1.lineTo(1, 0);
1941 if (!rectFirst) {
1942 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1943 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001944 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001945
1946 // fail, move in the middle
1947 path1.reset();
1948 if (rectFirst) {
1949 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1950 }
1951 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001952 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001953 if (index == 2) {
1954 path1.moveTo(1, .5f);
1955 }
1956 path1.lineTo(r1[index].fX, r1[index].fY);
1957 }
1958 path1.close();
1959 if (!rectFirst) {
1960 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1961 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001962 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001963
1964 // fail, move on the edge
1965 path1.reset();
1966 if (rectFirst) {
1967 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1968 }
bsalomon98806072014-12-12 15:11:17 -08001969 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001970 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1971 path1.lineTo(r1[index].fX, r1[index].fY);
1972 }
1973 path1.close();
1974 if (!rectFirst) {
1975 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1976 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001977 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001978
1979 // fail, quad
1980 path1.reset();
1981 if (rectFirst) {
1982 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1983 }
1984 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001985 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001986 if (index == 2) {
1987 path1.quadTo(1, .5f, 1, .5f);
1988 }
1989 path1.lineTo(r1[index].fX, r1[index].fY);
1990 }
1991 path1.close();
1992 if (!rectFirst) {
1993 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1994 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001995 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001996
1997 // fail, cubic
1998 path1.reset();
1999 if (rectFirst) {
2000 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2001 }
2002 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08002003 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002004 if (index == 2) {
2005 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
2006 }
2007 path1.lineTo(r1[index].fX, r1[index].fY);
2008 }
2009 path1.close();
2010 if (!rectFirst) {
2011 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2012 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002013 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
skia.committer@gmail.com34587162012-11-20 02:01:23 +00002014
caryclark@google.com56f233a2012-11-19 13:06:06 +00002015 // fail, not nested
2016 path1.reset();
2017 path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction);
2018 path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002019 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002020 }
caryclark@google.combfe90372012-11-21 13:56:20 +00002021
2022 // pass, stroke rect
2023 SkPath src, dst;
2024 src.addRect(1, 1, 7, 7, SkPath::kCW_Direction);
2025 SkPaint strokePaint;
2026 strokePaint.setStyle(SkPaint::kStroke_Style);
2027 strokePaint.setStrokeWidth(2);
2028 strokePaint.getFillPath(src, &dst);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002029 REPORTER_ASSERT(reporter, dst.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002030}
2031
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002032static void write_and_read_back(skiatest::Reporter* reporter,
2033 const SkPath& p) {
commit-bot@chromium.org19382422014-01-14 20:51:26 +00002034 SkWriter32 writer;
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002035 writer.writePath(p);
reed@google.com44699382013-10-31 17:28:30 +00002036 size_t size = writer.bytesWritten();
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002037 SkAutoMalloc storage(size);
2038 writer.flatten(storage.get());
2039 SkReader32 reader(storage.get(), size);
2040
2041 SkPath readBack;
2042 REPORTER_ASSERT(reporter, readBack != p);
2043 reader.readPath(&readBack);
2044 REPORTER_ASSERT(reporter, readBack == p);
2045
rmistry@google.comd6176b02012-08-23 18:14:13 +00002046 REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() ==
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002047 p.getConvexityOrUnknown());
2048
2049 REPORTER_ASSERT(reporter, readBack.isOval(NULL) == p.isOval(NULL));
2050
2051 const SkRect& origBounds = p.getBounds();
2052 const SkRect& readBackBounds = readBack.getBounds();
2053
2054 REPORTER_ASSERT(reporter, origBounds == readBackBounds);
2055}
2056
reed@google.com53effc52011-09-21 19:05:12 +00002057static void test_flattening(skiatest::Reporter* reporter) {
2058 SkPath p;
2059
2060 static const SkPoint pts[] = {
2061 { 0, 0 },
2062 { SkIntToScalar(10), SkIntToScalar(10) },
2063 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 },
2064 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }
2065 };
2066 p.moveTo(pts[0]);
2067 p.lineTo(pts[1]);
2068 p.quadTo(pts[2], pts[3]);
2069 p.cubicTo(pts[4], pts[5], pts[6]);
2070
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002071 write_and_read_back(reporter, p);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002072
2073 // create a buffer that should be much larger than the path so we don't
2074 // kill our stack if writer goes too far.
2075 char buffer[1024];
commit-bot@chromium.org4faa8692013-11-05 15:46:56 +00002076 size_t size1 = p.writeToMemory(NULL);
2077 size_t size2 = p.writeToMemory(buffer);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002078 REPORTER_ASSERT(reporter, size1 == size2);
2079
2080 SkPath p2;
commit-bot@chromium.org4faa8692013-11-05 15:46:56 +00002081 size_t size3 = p2.readFromMemory(buffer, 1024);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002082 REPORTER_ASSERT(reporter, size1 == size3);
2083 REPORTER_ASSERT(reporter, p == p2);
2084
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002085 size3 = p2.readFromMemory(buffer, 0);
2086 REPORTER_ASSERT(reporter, !size3);
2087
2088 SkPath tooShort;
2089 size3 = tooShort.readFromMemory(buffer, size1 - 1);
2090 REPORTER_ASSERT(reporter, tooShort.isEmpty());
2091
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002092 char buffer2[1024];
2093 size3 = p2.writeToMemory(buffer2);
2094 REPORTER_ASSERT(reporter, size1 == size3);
2095 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002096
2097 // test persistence of the oval flag & convexity
2098 {
2099 SkPath oval;
2100 SkRect rect = SkRect::MakeWH(10, 10);
2101 oval.addOval(rect);
2102
2103 write_and_read_back(reporter, oval);
2104 }
reed@google.com53effc52011-09-21 19:05:12 +00002105}
2106
2107static void test_transform(skiatest::Reporter* reporter) {
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002108 SkPath p;
rmistry@google.comd6176b02012-08-23 18:14:13 +00002109
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002110#define CONIC_PERSPECTIVE_BUG_FIXED 0
reed@google.com53effc52011-09-21 19:05:12 +00002111 static const SkPoint pts[] = {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002112 { 0, 0 }, // move
2113 { SkIntToScalar(10), SkIntToScalar(10) }, // line
2114 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, // quad
2115 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }, // cubic
2116#if CONIC_PERSPECTIVE_BUG_FIXED
2117 { 0, 0 }, { SkIntToScalar(20), SkIntToScalar(10) }, // conic
2118#endif
reed@google.com53effc52011-09-21 19:05:12 +00002119 };
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002120 const int kPtCount = SK_ARRAY_COUNT(pts);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002121
reed@google.com53effc52011-09-21 19:05:12 +00002122 p.moveTo(pts[0]);
2123 p.lineTo(pts[1]);
2124 p.quadTo(pts[2], pts[3]);
2125 p.cubicTo(pts[4], pts[5], pts[6]);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002126#if CONIC_PERSPECTIVE_BUG_FIXED
2127 p.conicTo(pts[4], pts[5], 0.5f);
2128#endif
2129 p.close();
rmistry@google.comd6176b02012-08-23 18:14:13 +00002130
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002131 {
2132 SkMatrix matrix;
2133 matrix.reset();
2134 SkPath p1;
2135 p.transform(matrix, &p1);
2136 REPORTER_ASSERT(reporter, p == p1);
reed@google.com53effc52011-09-21 19:05:12 +00002137 }
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002138
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002139
2140 {
2141 SkMatrix matrix;
2142 matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3);
2143
2144 SkPath p1; // Leave p1 non-unique (i.e., the empty path)
2145
skia.committer@gmail.com6e515d62013-12-04 07:02:26 +00002146 p.transform(matrix, &p1);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002147 SkPoint pts1[kPtCount];
skia.committer@gmail.com6e515d62013-12-04 07:02:26 +00002148 int count = p1.getPoints(pts1, kPtCount);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002149 REPORTER_ASSERT(reporter, kPtCount == count);
2150 for (int i = 0; i < count; ++i) {
2151 SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3);
2152 REPORTER_ASSERT(reporter, newPt == pts1[i]);
2153 }
2154 }
2155
2156 {
2157 SkMatrix matrix;
2158 matrix.reset();
reed3f43f8a2015-01-20 19:58:36 -08002159 matrix.setPerspX(4);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002160
2161 SkPath p1;
2162 p1.moveTo(SkPoint::Make(0, 0));
2163
2164 p.transform(matrix, &p1);
2165 REPORTER_ASSERT(reporter, matrix.invert(&matrix));
2166 p1.transform(matrix, NULL);
2167 SkRect pBounds = p.getBounds();
2168 SkRect p1Bounds = p1.getBounds();
2169 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fLeft, p1Bounds.fLeft));
2170 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fTop, p1Bounds.fTop));
2171 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fRight, p1Bounds.fRight));
2172 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fBottom, p1Bounds.fBottom));
2173 }
2174
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002175 p.reset();
2176 p.addCircle(0, 0, 1, SkPath::kCW_Direction);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002177
2178 {
2179 SkMatrix matrix;
2180 matrix.reset();
2181 SkPath p1;
2182 p1.moveTo(SkPoint::Make(0, 0));
2183
2184 p.transform(matrix, &p1);
2185 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCW_Direction));
2186 }
2187
2188
2189 {
2190 SkMatrix matrix;
2191 matrix.reset();
2192 matrix.setScaleX(-1);
2193 SkPath p1;
2194 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
2195
2196 p.transform(matrix, &p1);
2197 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCCW_Direction));
2198 }
2199
2200 {
2201 SkMatrix matrix;
2202 matrix.setAll(1, 1, 0, 1, 1, 0, 0, 0, 1);
2203 SkPath p1;
2204 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
2205
2206 p.transform(matrix, &p1);
2207 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kUnknown_Direction));
2208 }
reed@google.com53effc52011-09-21 19:05:12 +00002209}
2210
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002211static void test_zero_length_paths(skiatest::Reporter* reporter) {
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002212 SkPath p;
schenney@chromium.org7e963602012-06-13 17:05:43 +00002213 uint8_t verbs[32];
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002214
caryclark@google.com56f233a2012-11-19 13:06:06 +00002215 struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData {
schenney@chromium.org7e963602012-06-13 17:05:43 +00002216 const char* testPath;
2217 const size_t numResultPts;
2218 const SkRect resultBound;
2219 const SkPath::Verb* resultVerbs;
2220 const size_t numResultVerbs;
2221 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002222
schenney@chromium.org7e963602012-06-13 17:05:43 +00002223 static const SkPath::Verb resultVerbs1[] = { SkPath::kMove_Verb };
2224 static const SkPath::Verb resultVerbs2[] = { SkPath::kMove_Verb, SkPath::kMove_Verb };
2225 static const SkPath::Verb resultVerbs3[] = { SkPath::kMove_Verb, SkPath::kClose_Verb };
2226 static const SkPath::Verb resultVerbs4[] = { SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb };
2227 static const SkPath::Verb resultVerbs5[] = { SkPath::kMove_Verb, SkPath::kLine_Verb };
2228 static const SkPath::Verb resultVerbs6[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb };
2229 static const SkPath::Verb resultVerbs7[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb };
2230 static const SkPath::Verb resultVerbs8[] = {
2231 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb
2232 };
2233 static const SkPath::Verb resultVerbs9[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb };
2234 static const SkPath::Verb resultVerbs10[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb };
2235 static const SkPath::Verb resultVerbs11[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb };
2236 static const SkPath::Verb resultVerbs12[] = {
2237 SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb
2238 };
2239 static const SkPath::Verb resultVerbs13[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb };
2240 static const SkPath::Verb resultVerbs14[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb };
2241 static const SkPath::Verb resultVerbs15[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb };
2242 static const SkPath::Verb resultVerbs16[] = {
2243 SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb
2244 };
2245 static const struct zeroPathTestData gZeroLengthTests[] = {
2246 { "M 1 1", 1, {0, 0, 0, 0}, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002247 { "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 +00002248 { "M 1 1 z", 1, {0, 0, 0, 0}, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002249 { "M 1 1 z M 2 1 z", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
2250 { "M 1 1 L 1 1", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) },
2251 { "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) },
2252 { "M 1 1 L 1 1 z", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs7, SK_ARRAY_COUNT(resultVerbs7) },
2253 { "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) },
2254 { "M 1 1 Q 1 1 1 1", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs9, SK_ARRAY_COUNT(resultVerbs9) },
2255 { "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) },
2256 { "M 1 1 Q 1 1 1 1 z", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs11, SK_ARRAY_COUNT(resultVerbs11) },
2257 { "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) },
2258 { "M 1 1 C 1 1 1 1 1 1", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs13, SK_ARRAY_COUNT(resultVerbs13) },
2259 { "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 +00002260 SK_ARRAY_COUNT(resultVerbs14)
2261 },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002262 { "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) },
2263 { "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 +00002264 SK_ARRAY_COUNT(resultVerbs16)
2265 }
2266 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002267
schenney@chromium.org7e963602012-06-13 17:05:43 +00002268 for (size_t i = 0; i < SK_ARRAY_COUNT(gZeroLengthTests); ++i) {
2269 p.reset();
2270 bool valid = SkParsePath::FromSVGString(gZeroLengthTests[i].testPath, &p);
2271 REPORTER_ASSERT(reporter, valid);
2272 REPORTER_ASSERT(reporter, !p.isEmpty());
2273 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultPts == (size_t)p.countPoints());
2274 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultBound == p.getBounds());
2275 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultVerbs == (size_t)p.getVerbs(verbs, SK_ARRAY_COUNT(verbs)));
2276 for (size_t j = 0; j < gZeroLengthTests[i].numResultVerbs; ++j) {
2277 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultVerbs[j] == verbs[j]);
2278 }
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002279 }
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002280}
2281
2282struct SegmentInfo {
2283 SkPath fPath;
2284 int fPointCount;
2285};
2286
reed@google.com10296cc2011-09-21 12:29:05 +00002287#define kCurveSegmentMask (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask)
2288
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002289static void test_segment_masks(skiatest::Reporter* reporter) {
reed@google.comeef938c2012-08-01 20:01:49 +00002290 SkPath p, p2;
2291
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002292 p.moveTo(0, 0);
2293 p.quadTo(100, 100, 200, 200);
2294 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == p.getSegmentMasks());
2295 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00002296 p2 = p;
2297 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002298 p.cubicTo(100, 100, 200, 200, 300, 300);
2299 REPORTER_ASSERT(reporter, kCurveSegmentMask == p.getSegmentMasks());
2300 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00002301 p2 = p;
2302 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
2303
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002304 p.reset();
2305 p.moveTo(0, 0);
2306 p.cubicTo(100, 100, 200, 200, 300, 300);
2307 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == p.getSegmentMasks());
reed@google.comeef938c2012-08-01 20:01:49 +00002308 p2 = p;
2309 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
rmistry@google.comd6176b02012-08-23 18:14:13 +00002310
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002311 REPORTER_ASSERT(reporter, !p.isEmpty());
2312}
2313
2314static void test_iter(skiatest::Reporter* reporter) {
schenney@chromium.org7e963602012-06-13 17:05:43 +00002315 SkPath p;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002316 SkPoint pts[4];
2317
2318 // Test an iterator with no path
2319 SkPath::Iter noPathIter;
2320 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002321
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002322 // Test that setting an empty path works
2323 noPathIter.setPath(p, false);
2324 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002325
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002326 // Test that close path makes no difference for an empty path
2327 noPathIter.setPath(p, true);
2328 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002329
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002330 // Test an iterator with an initial empty path
2331 SkPath::Iter iter(p, false);
2332 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2333
2334 // Test that close path makes no difference
schenney@chromium.org7e963602012-06-13 17:05:43 +00002335 iter.setPath(p, true);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002336 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2337
rmistry@google.comd6176b02012-08-23 18:14:13 +00002338
schenney@chromium.org7e963602012-06-13 17:05:43 +00002339 struct iterTestData {
2340 const char* testPath;
2341 const bool forceClose;
2342 const bool consumeDegenerates;
2343 const size_t* numResultPtsPerVerb;
2344 const SkPoint* resultPts;
2345 const SkPath::Verb* resultVerbs;
2346 const size_t numResultVerbs;
2347 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002348
schenney@chromium.org7e963602012-06-13 17:05:43 +00002349 static const SkPath::Verb resultVerbs1[] = { SkPath::kDone_Verb };
2350 static const SkPath::Verb resultVerbs2[] = {
2351 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kDone_Verb
2352 };
2353 static const SkPath::Verb resultVerbs3[] = {
2354 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2355 };
2356 static const SkPath::Verb resultVerbs4[] = {
2357 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2358 };
2359 static const SkPath::Verb resultVerbs5[] = {
2360 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2361 };
2362 static const size_t resultPtsSizes1[] = { 0 };
schenney@chromium.orgfedd09b2012-06-13 18:29:20 +00002363 static const size_t resultPtsSizes2[] = { 1, 2, 2, 0 };
2364 static const size_t resultPtsSizes3[] = { 1, 2, 2, 2, 1, 0 };
2365 static const size_t resultPtsSizes4[] = { 1, 2, 1, 1, 0 };
2366 static const size_t resultPtsSizes5[] = { 1, 2, 1, 1, 1, 0 };
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002367 static const SkPoint* resultPts1 = 0;
schenney@chromium.org7e963602012-06-13 17:05:43 +00002368 static const SkPoint resultPts2[] = {
2369 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 }
2370 };
2371 static const SkPoint resultPts3[] = {
2372 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 },
2373 { 0, SK_Scalar1 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }
2374 };
2375 static const SkPoint resultPts4[] = {
2376 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
2377 };
2378 static const SkPoint resultPts5[] = {
2379 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
2380 };
2381 static const struct iterTestData gIterTests[] = {
2382 { "M 1 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002383 { "M 1 0 M 2 0 M 3 0 M 4 0 M 5 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2384 { "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 +00002385 { "z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2386 { "z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2387 { "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) },
2388 { "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 +00002389 { "M 1 0 L 1 1 L 0 1 M 0 0 z", false, true, resultPtsSizes2, resultPts2, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
2390 { "M 1 0 L 1 1 L 0 1 M 0 0 z", true, true, resultPtsSizes3, resultPts3, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
2391 { "M 1 0 L 1 0 M 0 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2392 { "M 1 0 L 1 0 M 0 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2393 { "M 1 0 L 1 0 M 0 0 z", false, false, resultPtsSizes4, resultPts4, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
2394 { "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 +00002395 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002396
schenney@chromium.org7e963602012-06-13 17:05:43 +00002397 for (size_t i = 0; i < SK_ARRAY_COUNT(gIterTests); ++i) {
2398 p.reset();
2399 bool valid = SkParsePath::FromSVGString(gIterTests[i].testPath, &p);
2400 REPORTER_ASSERT(reporter, valid);
2401 iter.setPath(p, gIterTests[i].forceClose);
2402 int j = 0, l = 0;
2403 do {
2404 REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegenerates) == gIterTests[i].resultVerbs[j]);
2405 for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k) {
2406 REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]);
2407 }
2408 } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb);
2409 REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs);
2410 }
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002411
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002412 p.reset();
2413 iter.setPath(p, false);
2414 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2415 p.lineTo(1, 1);
2416 p.close();
2417 iter.setPath(p, false);
2418 REPORTER_ASSERT(reporter, iter.isClosedContour());
2419 p.reset();
2420 iter.setPath(p, true);
2421 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2422 p.lineTo(1, 1);
2423 iter.setPath(p, true);
2424 REPORTER_ASSERT(reporter, iter.isClosedContour());
2425 p.moveTo(0, 0);
2426 p.lineTo(2, 2);
2427 iter.setPath(p, false);
2428 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2429
2430 // this checks to see if the NaN logic is executed in SkPath::autoClose(), but does not
2431 // check to see if the result is correct.
2432 for (int setNaN = 0; setNaN < 4; ++setNaN) {
2433 p.reset();
2434 p.moveTo(setNaN == 0 ? SK_ScalarNaN : 0, setNaN == 1 ? SK_ScalarNaN : 0);
2435 p.lineTo(setNaN == 2 ? SK_ScalarNaN : 1, setNaN == 3 ? SK_ScalarNaN : 1);
2436 iter.setPath(p, true);
2437 iter.next(pts, false);
2438 iter.next(pts, false);
2439 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == iter.next(pts, false));
2440 }
2441
2442 p.reset();
2443 p.quadTo(0, 0, 0, 0);
2444 iter.setPath(p, false);
2445 iter.next(pts, false);
2446 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == iter.next(pts, false));
2447 iter.setPath(p, false);
2448 iter.next(pts, false);
2449 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2450
2451 p.reset();
2452 p.conicTo(0, 0, 0, 0, 0.5f);
2453 iter.setPath(p, false);
2454 iter.next(pts, false);
2455 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts, false));
2456 iter.setPath(p, false);
2457 iter.next(pts, false);
2458 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2459
2460 p.reset();
2461 p.cubicTo(0, 0, 0, 0, 0, 0);
2462 iter.setPath(p, false);
2463 iter.next(pts, false);
2464 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
2465 iter.setPath(p, false);
2466 iter.next(pts, false);
2467 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2468
2469 p.moveTo(1, 1); // add a trailing moveto
2470 iter.setPath(p, false);
2471 iter.next(pts, false);
2472 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
2473 iter.setPath(p, false);
2474 iter.next(pts, false);
2475 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2476
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002477 // The GM degeneratesegments.cpp test is more extensive
2478}
2479
2480static void test_raw_iter(skiatest::Reporter* reporter) {
2481 SkPath p;
2482 SkPoint pts[4];
2483
2484 // Test an iterator with no path
2485 SkPath::RawIter noPathIter;
2486 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
2487 // Test that setting an empty path works
2488 noPathIter.setPath(p);
2489 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
rmistry@google.comd6176b02012-08-23 18:14:13 +00002490
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002491 // Test an iterator with an initial empty path
2492 SkPath::RawIter iter(p);
2493 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2494
2495 // Test that a move-only path returns the move.
2496 p.moveTo(SK_Scalar1, 0);
2497 iter.setPath(p);
2498 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2499 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2500 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2501 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2502
2503 // No matter how many moves we add, we should get them all back
2504 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2505 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2506 iter.setPath(p);
2507 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2508 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2509 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2510 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2511 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2512 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2513 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2514 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2515 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2516 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2517
2518 // Initial close is never ever stored
2519 p.reset();
2520 p.close();
2521 iter.setPath(p);
2522 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2523
2524 // Move/close sequences
2525 p.reset();
2526 p.close(); // Not stored, no purpose
2527 p.moveTo(SK_Scalar1, 0);
2528 p.close();
2529 p.close(); // Not stored, no purpose
2530 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2531 p.close();
2532 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2533 p.moveTo(SK_Scalar1*4, SK_Scalar1*3);
2534 p.close();
2535 iter.setPath(p);
2536 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2537 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2538 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2539 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2540 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2541 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2542 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2543 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2544 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2545 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2546 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2547 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2548 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2549 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2550 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2551 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2552 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2553 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2554 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2555 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2556 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2557 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2558
2559 // Generate random paths and verify
2560 SkPoint randomPts[25];
2561 for (int i = 0; i < 5; ++i) {
2562 for (int j = 0; j < 5; ++j) {
2563 randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j);
2564 }
2565 }
2566
2567 // Max of 10 segments, max 3 points per segment
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +00002568 SkRandom rand(9876543);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002569 SkPoint expectedPts[31]; // May have leading moveTo
reed@google.comd335d1d2012-01-12 18:17:11 +00002570 SkPath::Verb expectedVerbs[22]; // May have leading moveTo
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002571 SkPath::Verb nextVerb;
reed@google.comd335d1d2012-01-12 18:17:11 +00002572
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002573 for (int i = 0; i < 500; ++i) {
2574 p.reset();
2575 bool lastWasClose = true;
2576 bool haveMoveTo = false;
reed@google.comd335d1d2012-01-12 18:17:11 +00002577 SkPoint lastMoveToPt = { 0, 0 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002578 int numPoints = 0;
2579 int numVerbs = (rand.nextU() >> 16) % 10;
2580 int numIterVerbs = 0;
2581 for (int j = 0; j < numVerbs; ++j) {
2582 do {
2583 nextVerb = static_cast<SkPath::Verb>((rand.nextU() >> 16) % SkPath::kDone_Verb);
2584 } while (lastWasClose && nextVerb == SkPath::kClose_Verb);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002585 switch (nextVerb) {
2586 case SkPath::kMove_Verb:
2587 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2588 p.moveTo(expectedPts[numPoints]);
reed@google.comd335d1d2012-01-12 18:17:11 +00002589 lastMoveToPt = expectedPts[numPoints];
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002590 numPoints += 1;
2591 lastWasClose = false;
2592 haveMoveTo = true;
2593 break;
2594 case SkPath::kLine_Verb:
2595 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002596 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002597 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2598 haveMoveTo = true;
2599 }
2600 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2601 p.lineTo(expectedPts[numPoints]);
2602 numPoints += 1;
2603 lastWasClose = false;
2604 break;
2605 case SkPath::kQuad_Verb:
2606 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002607 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002608 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2609 haveMoveTo = true;
2610 }
2611 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2612 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2613 p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]);
2614 numPoints += 2;
2615 lastWasClose = false;
2616 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002617 case SkPath::kConic_Verb:
2618 if (!haveMoveTo) {
2619 expectedPts[numPoints++] = lastMoveToPt;
2620 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2621 haveMoveTo = true;
2622 }
2623 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2624 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2625 p.conicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2626 rand.nextUScalar1() * 4);
2627 numPoints += 2;
2628 lastWasClose = false;
2629 break;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002630 case SkPath::kCubic_Verb:
2631 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002632 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002633 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2634 haveMoveTo = true;
2635 }
2636 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2637 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2638 expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25];
2639 p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2640 expectedPts[numPoints + 2]);
2641 numPoints += 3;
2642 lastWasClose = false;
2643 break;
2644 case SkPath::kClose_Verb:
2645 p.close();
reed@google.comd335d1d2012-01-12 18:17:11 +00002646 haveMoveTo = false;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002647 lastWasClose = true;
2648 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002649 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002650 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002651 }
2652 expectedVerbs[numIterVerbs++] = nextVerb;
2653 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00002654
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002655 iter.setPath(p);
2656 numVerbs = numIterVerbs;
2657 numIterVerbs = 0;
2658 int numIterPts = 0;
2659 SkPoint lastMoveTo;
2660 SkPoint lastPt;
2661 lastMoveTo.set(0, 0);
2662 lastPt.set(0, 0);
2663 while ((nextVerb = iter.next(pts)) != SkPath::kDone_Verb) {
2664 REPORTER_ASSERT(reporter, nextVerb == expectedVerbs[numIterVerbs]);
2665 numIterVerbs++;
2666 switch (nextVerb) {
2667 case SkPath::kMove_Verb:
2668 REPORTER_ASSERT(reporter, numIterPts < numPoints);
2669 REPORTER_ASSERT(reporter, pts[0] == expectedPts[numIterPts]);
2670 lastPt = lastMoveTo = pts[0];
2671 numIterPts += 1;
2672 break;
2673 case SkPath::kLine_Verb:
2674 REPORTER_ASSERT(reporter, numIterPts < numPoints + 1);
2675 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2676 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2677 lastPt = pts[1];
2678 numIterPts += 1;
2679 break;
2680 case SkPath::kQuad_Verb:
reed@google.com277c3f82013-05-31 15:17:50 +00002681 case SkPath::kConic_Verb:
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002682 REPORTER_ASSERT(reporter, numIterPts < numPoints + 2);
2683 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2684 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2685 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2686 lastPt = pts[2];
2687 numIterPts += 2;
2688 break;
2689 case SkPath::kCubic_Verb:
2690 REPORTER_ASSERT(reporter, numIterPts < numPoints + 3);
2691 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2692 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2693 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2694 REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]);
2695 lastPt = pts[3];
2696 numIterPts += 3;
2697 break;
2698 case SkPath::kClose_Verb:
2699 REPORTER_ASSERT(reporter, pts[0] == lastMoveTo);
2700 lastPt = lastMoveTo;
2701 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002702 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002703 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002704 }
2705 }
2706 REPORTER_ASSERT(reporter, numIterPts == numPoints);
2707 REPORTER_ASSERT(reporter, numIterVerbs == numVerbs);
2708 }
2709}
2710
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002711static void check_for_circle(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002712 const SkPath& path,
2713 bool expectedCircle,
2714 SkPath::Direction expectedDir) {
robertphillips@google.com466310d2013-12-03 16:43:54 +00002715 SkRect rect = SkRect::MakeEmpty();
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002716 REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle);
2717 REPORTER_ASSERT(reporter, path.cheapIsDirection(expectedDir));
skia.committer@gmail.comfbb0ed92012-11-13 21:46:06 +00002718
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002719 if (expectedCircle) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002720 REPORTER_ASSERT(reporter, rect.height() == rect.width());
2721 }
2722}
2723
2724static void test_circle_skew(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002725 const SkPath& path,
2726 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002727 SkPath tmp;
2728
2729 SkMatrix m;
2730 m.setSkew(SkIntToScalar(3), SkIntToScalar(5));
2731 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002732 // this matrix reverses the direction.
2733 if (SkPath::kCCW_Direction == dir) {
2734 dir = SkPath::kCW_Direction;
2735 } else {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002736 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002737 dir = SkPath::kCCW_Direction;
2738 }
2739 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002740}
2741
2742static void test_circle_translate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002743 const SkPath& path,
2744 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002745 SkPath tmp;
2746
2747 // translate at small offset
2748 SkMatrix m;
2749 m.setTranslate(SkIntToScalar(15), SkIntToScalar(15));
2750 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002751 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002752
2753 tmp.reset();
2754 m.reset();
2755
2756 // translate at a relatively big offset
2757 m.setTranslate(SkIntToScalar(1000), SkIntToScalar(1000));
2758 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002759 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002760}
2761
2762static void test_circle_rotate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002763 const SkPath& path,
2764 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002765 for (int angle = 0; angle < 360; ++angle) {
2766 SkPath tmp;
2767 SkMatrix m;
2768 m.setRotate(SkIntToScalar(angle));
2769 path.transform(m, &tmp);
2770
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002771 // TODO: a rotated circle whose rotated angle is not a multiple of 90
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002772 // degrees is not an oval anymore, this can be improved. we made this
2773 // for the simplicity of our implementation.
2774 if (angle % 90 == 0) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002775 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002776 } else {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002777 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002778 }
2779 }
2780}
2781
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002782static void test_circle_mirror_x(skiatest::Reporter* reporter,
2783 const SkPath& path,
2784 SkPath::Direction dir) {
2785 SkPath tmp;
2786 SkMatrix m;
2787 m.reset();
2788 m.setScaleX(-SK_Scalar1);
2789 path.transform(m, &tmp);
2790
2791 if (SkPath::kCW_Direction == dir) {
2792 dir = SkPath::kCCW_Direction;
2793 } else {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002794 REPORTER_ASSERT(reporter, SkPath::kCCW_Direction == dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002795 dir = SkPath::kCW_Direction;
2796 }
2797
2798 check_for_circle(reporter, tmp, true, dir);
2799}
2800
2801static void test_circle_mirror_y(skiatest::Reporter* reporter,
2802 const SkPath& path,
2803 SkPath::Direction dir) {
2804 SkPath tmp;
2805 SkMatrix m;
2806 m.reset();
2807 m.setScaleY(-SK_Scalar1);
2808 path.transform(m, &tmp);
2809
2810 if (SkPath::kCW_Direction == dir) {
2811 dir = SkPath::kCCW_Direction;
2812 } else {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002813 REPORTER_ASSERT(reporter, SkPath::kCCW_Direction == dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002814 dir = SkPath::kCW_Direction;
2815 }
2816
2817 check_for_circle(reporter, tmp, true, dir);
2818}
2819
2820static void test_circle_mirror_xy(skiatest::Reporter* reporter,
2821 const SkPath& path,
2822 SkPath::Direction dir) {
2823 SkPath tmp;
2824 SkMatrix m;
2825 m.reset();
2826 m.setScaleX(-SK_Scalar1);
2827 m.setScaleY(-SK_Scalar1);
2828 path.transform(m, &tmp);
2829
2830 check_for_circle(reporter, tmp, true, dir);
2831}
2832
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002833static void test_circle_with_direction(skiatest::Reporter* reporter,
2834 SkPath::Direction dir) {
2835 SkPath path;
2836
2837 // circle at origin
2838 path.addCircle(0, 0, SkIntToScalar(20), dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002839 check_for_circle(reporter, path, true, dir);
2840 test_circle_rotate(reporter, path, dir);
2841 test_circle_translate(reporter, path, dir);
2842 test_circle_skew(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002843
2844 // circle at an offset at (10, 10)
2845 path.reset();
2846 path.addCircle(SkIntToScalar(10), SkIntToScalar(10),
2847 SkIntToScalar(20), dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002848 check_for_circle(reporter, path, true, dir);
2849 test_circle_rotate(reporter, path, dir);
2850 test_circle_translate(reporter, path, dir);
2851 test_circle_skew(reporter, path, dir);
2852 test_circle_mirror_x(reporter, path, dir);
2853 test_circle_mirror_y(reporter, path, dir);
2854 test_circle_mirror_xy(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002855}
2856
2857static void test_circle_with_add_paths(skiatest::Reporter* reporter) {
2858 SkPath path;
2859 SkPath circle;
2860 SkPath rect;
2861 SkPath empty;
2862
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002863 static const SkPath::Direction kCircleDir = SkPath::kCW_Direction;
2864 static const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction;
2865
2866 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002867 rect.addRect(SkIntToScalar(5), SkIntToScalar(5),
2868 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction);
2869
2870 SkMatrix translate;
2871 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12));
2872
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00002873 // Although all the path concatenation related operations leave
2874 // the path a circle, most mark it as a non-circle for simplicity
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002875
2876 // empty + circle (translate)
2877 path = empty;
2878 path.addPath(circle, translate);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002879 check_for_circle(reporter, path, false, kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002880
2881 // circle + empty (translate)
2882 path = circle;
2883 path.addPath(empty, translate);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00002884 check_for_circle(reporter, path, true, kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002885
2886 // test reverseAddPath
2887 path = circle;
2888 path.reverseAddPath(rect);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002889 check_for_circle(reporter, path, false, kCircleDirOpposite);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002890}
2891
2892static void test_circle(skiatest::Reporter* reporter) {
2893 test_circle_with_direction(reporter, SkPath::kCW_Direction);
2894 test_circle_with_direction(reporter, SkPath::kCCW_Direction);
2895
2896 // multiple addCircle()
2897 SkPath path;
2898 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2899 path.addCircle(0, 0, SkIntToScalar(20), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002900 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002901
2902 // some extra lineTo() would make isOval() fail
2903 path.reset();
2904 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2905 path.lineTo(0, 0);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002906 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002907
2908 // not back to the original point
2909 path.reset();
2910 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2911 path.setLastPt(SkIntToScalar(5), SkIntToScalar(5));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002912 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002913
2914 test_circle_with_add_paths(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002915
2916 // test negative radius
2917 path.reset();
2918 path.addCircle(0, 0, -1, SkPath::kCW_Direction);
2919 REPORTER_ASSERT(reporter, path.isEmpty());
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002920}
2921
2922static void test_oval(skiatest::Reporter* reporter) {
2923 SkRect rect;
2924 SkMatrix m;
2925 SkPath path;
2926
2927 rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50));
2928 path.addOval(rect);
2929
2930 REPORTER_ASSERT(reporter, path.isOval(NULL));
2931
2932 m.setRotate(SkIntToScalar(90));
2933 SkPath tmp;
2934 path.transform(m, &tmp);
2935 // an oval rotated 90 degrees is still an oval.
2936 REPORTER_ASSERT(reporter, tmp.isOval(NULL));
2937
2938 m.reset();
2939 m.setRotate(SkIntToScalar(30));
2940 tmp.reset();
2941 path.transform(m, &tmp);
2942 // an oval rotated 30 degrees is not an oval anymore.
2943 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2944
2945 // since empty path being transformed.
2946 path.reset();
2947 tmp.reset();
2948 m.reset();
2949 path.transform(m, &tmp);
2950 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2951
2952 // empty path is not an oval
2953 tmp.reset();
2954 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2955
2956 // only has moveTo()s
2957 tmp.reset();
2958 tmp.moveTo(0, 0);
2959 tmp.moveTo(SkIntToScalar(10), SkIntToScalar(10));
2960 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2961
2962 // mimic WebKit's calling convention,
2963 // call moveTo() first and then call addOval()
2964 path.reset();
2965 path.moveTo(0, 0);
2966 path.addOval(rect);
2967 REPORTER_ASSERT(reporter, path.isOval(NULL));
2968
2969 // copy path
2970 path.reset();
2971 tmp.reset();
2972 tmp.addOval(rect);
2973 path = tmp;
2974 REPORTER_ASSERT(reporter, path.isOval(NULL));
2975}
2976
bungeman@google.coma5809a32013-06-21 15:13:34 +00002977static void test_empty(skiatest::Reporter* reporter, const SkPath& p) {
2978 SkPath empty;
reed@android.com80e39a72009-04-02 16:59:40 +00002979
reed@android.com3abec1d2009-03-02 05:36:20 +00002980 REPORTER_ASSERT(reporter, p.isEmpty());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002981 REPORTER_ASSERT(reporter, 0 == p.countPoints());
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002982 REPORTER_ASSERT(reporter, 0 == p.countVerbs());
reed@google.com10296cc2011-09-21 12:29:05 +00002983 REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks());
reed@google.comb54455e2011-05-16 14:16:04 +00002984 REPORTER_ASSERT(reporter, p.isConvex());
reed@android.com3abec1d2009-03-02 05:36:20 +00002985 REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType);
2986 REPORTER_ASSERT(reporter, !p.isInverseFillType());
bungeman@google.coma5809a32013-06-21 15:13:34 +00002987 REPORTER_ASSERT(reporter, p == empty);
2988 REPORTER_ASSERT(reporter, !(p != empty));
2989}
2990
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002991static void test_rrect_is_convex(skiatest::Reporter* reporter, SkPath* path,
2992 SkPath::Direction dir) {
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00002993 REPORTER_ASSERT(reporter, path->isConvex());
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002994 REPORTER_ASSERT(reporter, path->cheapIsDirection(dir));
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00002995 path->setConvexity(SkPath::kUnknown_Convexity);
2996 REPORTER_ASSERT(reporter, path->isConvex());
2997 path->reset();
2998}
2999
caryclarkd3d1a982014-12-08 04:57:38 -08003000static void test_rrect_convexity_is_unknown(skiatest::Reporter* reporter, SkPath* path,
3001 SkPath::Direction dir) {
3002 REPORTER_ASSERT(reporter, path->isConvex());
3003 REPORTER_ASSERT(reporter, path->cheapIsDirection(dir));
3004 path->setConvexity(SkPath::kUnknown_Convexity);
3005 REPORTER_ASSERT(reporter, path->getConvexity() == SkPath::kUnknown_Convexity);
3006 path->reset();
3007}
3008
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003009static void test_rrect(skiatest::Reporter* reporter) {
3010 SkPath p;
3011 SkRRect rr;
3012 SkVector radii[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
3013 SkRect r = {10, 20, 30, 40};
3014 rr.setRectRadii(r, radii);
3015 p.addRRect(rr);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003016 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003017 p.addRRect(rr, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003018 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003019 p.addRoundRect(r, &radii[0].fX);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003020 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003021 p.addRoundRect(r, &radii[0].fX, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003022 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003023 p.addRoundRect(r, radii[1].fX, radii[1].fY);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003024 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003025 p.addRoundRect(r, radii[1].fX, radii[1].fY, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003026 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
3027 for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) {
3028 SkVector save = radii[i];
3029 radii[i].set(0, 0);
3030 rr.setRectRadii(r, radii);
3031 p.addRRect(rr);
3032 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3033 radii[i] = save;
3034 }
3035 p.addRoundRect(r, 0, 0);
3036 SkRect returnedRect;
3037 REPORTER_ASSERT(reporter, p.isRect(&returnedRect));
3038 REPORTER_ASSERT(reporter, returnedRect == r);
3039 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3040 SkVector zeroRadii[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
3041 rr.setRectRadii(r, zeroRadii);
3042 p.addRRect(rr);
3043 bool closed;
3044 SkPath::Direction dir;
robertphillips91b0a352015-01-05 10:13:46 -08003045 REPORTER_ASSERT(reporter, p.isRect(NULL, &closed, &dir));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003046 REPORTER_ASSERT(reporter, closed);
3047 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
3048 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3049 p.addRRect(rr, SkPath::kCW_Direction);
3050 p.addRRect(rr, SkPath::kCW_Direction);
3051 REPORTER_ASSERT(reporter, !p.isConvex());
3052 p.reset();
3053 p.addRRect(rr, SkPath::kCCW_Direction);
3054 p.addRRect(rr, SkPath::kCCW_Direction);
3055 REPORTER_ASSERT(reporter, !p.isConvex());
3056 p.reset();
3057 SkRect emptyR = {10, 20, 10, 30};
3058 rr.setRectRadii(emptyR, radii);
3059 p.addRRect(rr);
3060 REPORTER_ASSERT(reporter, p.isEmpty());
3061 SkRect largeR = {0, 0, SK_ScalarMax, SK_ScalarMax};
3062 rr.setRectRadii(largeR, radii);
3063 p.addRRect(rr);
caryclarkd3d1a982014-12-08 04:57:38 -08003064 test_rrect_convexity_is_unknown(reporter, &p, SkPath::kCW_Direction);
reed454fa712015-02-10 08:46:22 -08003065
3066 // we check for non-finites
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003067 SkRect infR = {0, 0, SK_ScalarMax, SK_ScalarInfinity};
3068 rr.setRectRadii(infR, radii);
reed454fa712015-02-10 08:46:22 -08003069 REPORTER_ASSERT(reporter, rr.isEmpty());
3070
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003071 SkRect tinyR = {0, 0, 1e-9f, 1e-9f};
3072 p.addRoundRect(tinyR, 5e-11f, 5e-11f);
3073 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003074}
3075
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003076static void test_arc(skiatest::Reporter* reporter) {
3077 SkPath p;
3078 SkRect emptyOval = {10, 20, 30, 20};
3079 REPORTER_ASSERT(reporter, emptyOval.isEmpty());
3080 p.addArc(emptyOval, 1, 2);
3081 REPORTER_ASSERT(reporter, p.isEmpty());
3082 p.reset();
3083 SkRect oval = {10, 20, 30, 40};
3084 p.addArc(oval, 1, 0);
3085 REPORTER_ASSERT(reporter, p.isEmpty());
3086 p.reset();
3087 SkPath cwOval;
3088 cwOval.addOval(oval);
3089 p.addArc(oval, 1, 360);
3090 REPORTER_ASSERT(reporter, p == cwOval);
3091 p.reset();
3092 SkPath ccwOval;
3093 ccwOval.addOval(oval, SkPath::kCCW_Direction);
3094 p.addArc(oval, 1, -360);
3095 REPORTER_ASSERT(reporter, p == ccwOval);
3096 p.reset();
3097 p.addArc(oval, 1, 180);
3098 REPORTER_ASSERT(reporter, p.isConvex());
3099 REPORTER_ASSERT(reporter, p.cheapIsDirection(SkPath::kCW_Direction));
3100 p.setConvexity(SkPath::kUnknown_Convexity);
3101 REPORTER_ASSERT(reporter, p.isConvex());
3102}
3103
3104static void check_move(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3105 SkScalar x0, SkScalar y0) {
3106 SkPoint pts[4];
3107 SkPath::Verb v = iter->next(pts);
3108 REPORTER_ASSERT(reporter, v == SkPath::kMove_Verb);
3109 REPORTER_ASSERT(reporter, pts[0].fX == x0);
3110 REPORTER_ASSERT(reporter, pts[0].fY == y0);
3111}
3112
3113static void check_line(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3114 SkScalar x1, SkScalar y1) {
3115 SkPoint pts[4];
3116 SkPath::Verb v = iter->next(pts);
3117 REPORTER_ASSERT(reporter, v == SkPath::kLine_Verb);
3118 REPORTER_ASSERT(reporter, pts[1].fX == x1);
3119 REPORTER_ASSERT(reporter, pts[1].fY == y1);
3120}
3121
3122static void check_quad(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3123 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3124 SkPoint pts[4];
3125 SkPath::Verb v = iter->next(pts);
3126 REPORTER_ASSERT(reporter, v == SkPath::kQuad_Verb);
3127 REPORTER_ASSERT(reporter, pts[1].fX == x1);
3128 REPORTER_ASSERT(reporter, pts[1].fY == y1);
3129 REPORTER_ASSERT(reporter, pts[2].fX == x2);
3130 REPORTER_ASSERT(reporter, pts[2].fY == y2);
3131}
3132
3133static void check_done(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
3134 SkPoint pts[4];
3135 SkPath::Verb v = iter->next(pts);
3136 REPORTER_ASSERT(reporter, v == SkPath::kDone_Verb);
3137}
3138
3139static void check_done_and_reset(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
3140 check_done(reporter, p, iter);
3141 p->reset();
3142}
3143
3144static void check_path_is_move_and_reset(skiatest::Reporter* reporter, SkPath* p,
3145 SkScalar x0, SkScalar y0) {
3146 SkPath::RawIter iter(*p);
3147 check_move(reporter, &iter, x0, y0);
3148 check_done_and_reset(reporter, p, &iter);
3149}
3150
3151static void check_path_is_line_and_reset(skiatest::Reporter* reporter, SkPath* p,
3152 SkScalar x1, SkScalar y1) {
3153 SkPath::RawIter iter(*p);
3154 check_move(reporter, &iter, 0, 0);
3155 check_line(reporter, &iter, x1, y1);
3156 check_done_and_reset(reporter, p, &iter);
3157}
3158
3159static void check_path_is_line(skiatest::Reporter* reporter, SkPath* p,
3160 SkScalar x1, SkScalar y1) {
3161 SkPath::RawIter iter(*p);
3162 check_move(reporter, &iter, 0, 0);
3163 check_line(reporter, &iter, x1, y1);
3164 check_done(reporter, p, &iter);
3165}
3166
3167static void check_path_is_line_pair_and_reset(skiatest::Reporter* reporter, SkPath* p,
3168 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3169 SkPath::RawIter iter(*p);
3170 check_move(reporter, &iter, 0, 0);
3171 check_line(reporter, &iter, x1, y1);
3172 check_line(reporter, &iter, x2, y2);
3173 check_done_and_reset(reporter, p, &iter);
3174}
3175
3176static void check_path_is_quad_and_reset(skiatest::Reporter* reporter, SkPath* p,
3177 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3178 SkPath::RawIter iter(*p);
3179 check_move(reporter, &iter, 0, 0);
3180 check_quad(reporter, &iter, x1, y1, x2, y2);
3181 check_done_and_reset(reporter, p, &iter);
3182}
3183
reedd5d27d92015-02-09 13:54:43 -08003184static bool nearly_equal(const SkRect& a, const SkRect& b) {
3185 return SkScalarNearlyEqual(a.fLeft, b.fLeft) &&
3186 SkScalarNearlyEqual(a.fTop, b.fTop) &&
3187 SkScalarNearlyEqual(a.fRight, b.fRight) &&
3188 SkScalarNearlyEqual(a.fBottom, b.fBottom);
3189}
3190
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003191static void test_arcTo(skiatest::Reporter* reporter) {
3192 SkPath p;
3193 p.arcTo(0, 0, 1, 2, 1);
3194 check_path_is_line_and_reset(reporter, &p, 0, 0);
3195 p.arcTo(1, 2, 1, 2, 1);
3196 check_path_is_line_and_reset(reporter, &p, 1, 2);
3197 p.arcTo(1, 2, 3, 4, 0);
3198 check_path_is_line_and_reset(reporter, &p, 1, 2);
3199 p.arcTo(1, 2, 0, 0, 1);
3200 check_path_is_line_and_reset(reporter, &p, 1, 2);
3201 p.arcTo(1, 0, 1, 1, 1);
3202 SkPoint pt;
3203 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == 1);
3204 p.reset();
3205 p.arcTo(1, 0, 1, -1, 1);
3206 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == -1);
3207 p.reset();
3208 SkRect oval = {1, 2, 3, 4};
3209 p.arcTo(oval, 0, 0, true);
3210 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3211 p.arcTo(oval, 0, 0, false);
3212 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3213 p.arcTo(oval, 360, 0, true);
3214 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3215 p.arcTo(oval, 360, 0, false);
3216 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
reedd5d27d92015-02-09 13:54:43 -08003217
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003218 for (float sweep = 359, delta = 0.5f; sweep != (float) (sweep + delta); ) {
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00003219 p.arcTo(oval, 0, sweep, false);
reedd5d27d92015-02-09 13:54:43 -08003220 REPORTER_ASSERT(reporter, nearly_equal(p.getBounds(), oval));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003221 sweep += delta;
3222 delta /= 2;
3223 }
3224 for (float sweep = 361, delta = 0.5f; sweep != (float) (sweep - delta);) {
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00003225 p.arcTo(oval, 0, sweep, false);
reedd5d27d92015-02-09 13:54:43 -08003226 REPORTER_ASSERT(reporter, nearly_equal(p.getBounds(), oval));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003227 sweep -= delta;
3228 delta /= 2;
3229 }
3230 SkRect noOvalWidth = {1, 2, 0, 3};
3231 p.reset();
3232 p.arcTo(noOvalWidth, 0, 360, false);
3233 REPORTER_ASSERT(reporter, p.isEmpty());
3234
3235 SkRect noOvalHeight = {1, 2, 3, 1};
3236 p.reset();
3237 p.arcTo(noOvalHeight, 0, 360, false);
3238 REPORTER_ASSERT(reporter, p.isEmpty());
3239}
3240
3241static void test_addPath(skiatest::Reporter* reporter) {
3242 SkPath p, q;
3243 p.lineTo(1, 2);
3244 q.moveTo(4, 4);
3245 q.lineTo(7, 8);
3246 q.conicTo(8, 7, 6, 5, 0.5f);
3247 q.quadTo(6, 7, 8, 6);
3248 q.cubicTo(5, 6, 7, 8, 7, 5);
3249 q.close();
3250 p.addPath(q, -4, -4);
3251 SkRect expected = {0, 0, 4, 4};
3252 REPORTER_ASSERT(reporter, p.getBounds() == expected);
3253 p.reset();
3254 p.reverseAddPath(q);
3255 SkRect reverseExpected = {4, 4, 8, 8};
3256 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
3257}
3258
commit-bot@chromium.org14747e52014-02-11 21:16:29 +00003259static void test_addPathMode(skiatest::Reporter* reporter, bool explicitMoveTo, bool extend) {
3260 SkPath p, q;
3261 if (explicitMoveTo) {
3262 p.moveTo(1, 1);
3263 }
3264 p.lineTo(1, 2);
3265 if (explicitMoveTo) {
3266 q.moveTo(2, 1);
3267 }
3268 q.lineTo(2, 2);
3269 p.addPath(q, extend ? SkPath::kExtend_AddPathMode : SkPath::kAppend_AddPathMode);
3270 uint8_t verbs[4];
3271 int verbcount = p.getVerbs(verbs, 4);
3272 REPORTER_ASSERT(reporter, verbcount == 4);
3273 REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
3274 REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
3275 REPORTER_ASSERT(reporter, verbs[2] == (extend ? SkPath::kLine_Verb : SkPath::kMove_Verb));
3276 REPORTER_ASSERT(reporter, verbs[3] == SkPath::kLine_Verb);
3277}
3278
3279static void test_extendClosedPath(skiatest::Reporter* reporter) {
3280 SkPath p, q;
3281 p.moveTo(1, 1);
3282 p.lineTo(1, 2);
3283 p.lineTo(2, 2);
3284 p.close();
3285 q.moveTo(2, 1);
3286 q.lineTo(2, 3);
3287 p.addPath(q, SkPath::kExtend_AddPathMode);
3288 uint8_t verbs[7];
3289 int verbcount = p.getVerbs(verbs, 7);
3290 REPORTER_ASSERT(reporter, verbcount == 7);
3291 REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
3292 REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
3293 REPORTER_ASSERT(reporter, verbs[2] == SkPath::kLine_Verb);
3294 REPORTER_ASSERT(reporter, verbs[3] == SkPath::kClose_Verb);
3295 REPORTER_ASSERT(reporter, verbs[4] == SkPath::kMove_Verb);
3296 REPORTER_ASSERT(reporter, verbs[5] == SkPath::kLine_Verb);
3297 REPORTER_ASSERT(reporter, verbs[6] == SkPath::kLine_Verb);
3298
3299 SkPoint pt;
3300 REPORTER_ASSERT(reporter, p.getLastPt(&pt));
3301 REPORTER_ASSERT(reporter, pt == SkPoint::Make(2, 3));
3302 REPORTER_ASSERT(reporter, p.getPoint(3) == SkPoint::Make(1, 1));
3303}
3304
3305static void test_addEmptyPath(skiatest::Reporter* reporter, SkPath::AddPathMode mode) {
3306 SkPath p, q, r;
3307 // case 1: dst is empty
3308 p.moveTo(2, 1);
3309 p.lineTo(2, 3);
3310 q.addPath(p, mode);
3311 REPORTER_ASSERT(reporter, q == p);
3312 // case 2: src is empty
3313 p.addPath(r, mode);
3314 REPORTER_ASSERT(reporter, q == p);
3315 // case 3: src and dst are empty
3316 q.reset();
3317 q.addPath(r, mode);
3318 REPORTER_ASSERT(reporter, q.isEmpty());
skia.committer@gmail.com877c4492014-02-12 03:02:04 +00003319}
commit-bot@chromium.org14747e52014-02-11 21:16:29 +00003320
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003321static void test_conicTo_special_case(skiatest::Reporter* reporter) {
3322 SkPath p;
3323 p.conicTo(1, 2, 3, 4, -1);
3324 check_path_is_line_and_reset(reporter, &p, 3, 4);
3325 p.conicTo(1, 2, 3, 4, SK_ScalarInfinity);
3326 check_path_is_line_pair_and_reset(reporter, &p, 1, 2, 3, 4);
3327 p.conicTo(1, 2, 3, 4, 1);
3328 check_path_is_quad_and_reset(reporter, &p, 1, 2, 3, 4);
3329}
3330
3331static void test_get_point(skiatest::Reporter* reporter) {
3332 SkPath p;
3333 SkPoint pt = p.getPoint(0);
3334 REPORTER_ASSERT(reporter, pt == SkPoint::Make(0, 0));
3335 REPORTER_ASSERT(reporter, !p.getLastPt(NULL));
3336 REPORTER_ASSERT(reporter, !p.getLastPt(&pt) && pt == SkPoint::Make(0, 0));
3337 p.setLastPt(10, 10);
3338 pt = p.getPoint(0);
3339 REPORTER_ASSERT(reporter, pt == SkPoint::Make(10, 10));
3340 REPORTER_ASSERT(reporter, p.getLastPt(NULL));
3341 p.rMoveTo(10, 10);
3342 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt == SkPoint::Make(20, 20));
3343}
3344
3345static void test_contains(skiatest::Reporter* reporter) {
3346 SkPath p;
3347 p.setFillType(SkPath::kInverseWinding_FillType);
3348 REPORTER_ASSERT(reporter, p.contains(0, 0));
3349 p.setFillType(SkPath::kWinding_FillType);
3350 REPORTER_ASSERT(reporter, !p.contains(0, 0));
3351 p.moveTo(4, 4);
3352 p.lineTo(6, 8);
3353 p.lineTo(8, 4);
3354 // test quick reject
3355 REPORTER_ASSERT(reporter, !p.contains(4, 0));
3356 REPORTER_ASSERT(reporter, !p.contains(0, 4));
3357 REPORTER_ASSERT(reporter, !p.contains(4, 10));
3358 REPORTER_ASSERT(reporter, !p.contains(10, 4));
3359 // test various crossings in x
3360 REPORTER_ASSERT(reporter, !p.contains(5, 7));
3361 REPORTER_ASSERT(reporter, p.contains(6, 7));
3362 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3363 p.reset();
3364 p.moveTo(4, 4);
3365 p.lineTo(8, 6);
3366 p.lineTo(4, 8);
3367 // test various crossings in y
3368 REPORTER_ASSERT(reporter, !p.contains(7, 5));
3369 REPORTER_ASSERT(reporter, p.contains(7, 6));
3370 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3371 // test quads
3372 p.reset();
3373 p.moveTo(4, 4);
3374 p.quadTo(6, 6, 8, 8);
3375 p.quadTo(6, 8, 4, 8);
3376 p.quadTo(4, 6, 4, 4);
3377 REPORTER_ASSERT(reporter, p.contains(5, 6));
3378 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3379
3380 p.reset();
3381 p.moveTo(6, 6);
3382 p.quadTo(8, 8, 6, 8);
3383 p.quadTo(4, 8, 4, 6);
3384 p.quadTo(4, 4, 6, 6);
3385 REPORTER_ASSERT(reporter, p.contains(5, 6));
3386 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3387
3388#define CONIC_CONTAINS_BUG_FIXED 0
3389#if CONIC_CONTAINS_BUG_FIXED
3390 p.reset();
3391 p.moveTo(4, 4);
3392 p.conicTo(6, 6, 8, 8, 0.5f);
3393 p.conicTo(6, 8, 4, 8, 0.5f);
3394 p.conicTo(4, 6, 4, 4, 0.5f);
3395 REPORTER_ASSERT(reporter, p.contains(5, 6));
3396 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3397#endif
3398
3399 // test cubics
3400 SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5, 4}, {6, 5}, {7, 6}};
3401 for (int i = 0; i < 3; ++i) {
3402 p.reset();
3403 p.setFillType(SkPath::kEvenOdd_FillType);
3404 p.moveTo(pts[i].fX, pts[i].fY);
3405 p.cubicTo(pts[i + 1].fX, pts[i + 1].fY, pts[i + 2].fX, pts[i + 2].fY, pts[i + 3].fX, pts[i + 3].fY);
3406 p.cubicTo(pts[i + 4].fX, pts[i + 4].fY, pts[i + 5].fX, pts[i + 5].fY, pts[i + 6].fX, pts[i + 6].fY);
3407 p.close();
3408 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f));
3409 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f));
3410 }
3411}
3412
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003413class PathRefTest_Private {
3414public:
3415 static void TestPathRef(skiatest::Reporter* reporter) {
3416 static const int kRepeatCnt = 10;
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003417
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003418 SkAutoTUnref<SkPathRef> pathRef(SkNEW(SkPathRef));
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003419
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003420 SkPathRef::Editor ed(&pathRef);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003421
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003422 {
3423 ed.growForRepeatedVerb(SkPath::kMove_Verb, kRepeatCnt);
3424 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3425 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
3426 REPORTER_ASSERT(reporter, 0 == pathRef->getSegmentMasks());
3427 for (int i = 0; i < kRepeatCnt; ++i) {
3428 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == pathRef->atVerb(i));
3429 }
3430 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003431 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003432
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003433 {
3434 ed.growForRepeatedVerb(SkPath::kLine_Verb, kRepeatCnt);
3435 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3436 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
3437 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == pathRef->getSegmentMasks());
3438 for (int i = 0; i < kRepeatCnt; ++i) {
3439 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == pathRef->atVerb(i));
3440 }
3441 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003442 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003443
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003444 {
3445 ed.growForRepeatedVerb(SkPath::kQuad_Verb, kRepeatCnt);
3446 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3447 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
3448 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == pathRef->getSegmentMasks());
3449 for (int i = 0; i < kRepeatCnt; ++i) {
3450 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == pathRef->atVerb(i));
3451 }
3452 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003453 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003454
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003455 {
3456 SkScalar* weights = NULL;
3457 ed.growForRepeatedVerb(SkPath::kConic_Verb, kRepeatCnt, &weights);
3458 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3459 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
3460 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countWeights());
3461 REPORTER_ASSERT(reporter, SkPath::kConic_SegmentMask == pathRef->getSegmentMasks());
bsalomon49f085d2014-09-05 13:34:00 -07003462 REPORTER_ASSERT(reporter, weights);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003463 for (int i = 0; i < kRepeatCnt; ++i) {
3464 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == pathRef->atVerb(i));
3465 }
3466 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003467 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003468
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003469 {
3470 ed.growForRepeatedVerb(SkPath::kCubic_Verb, kRepeatCnt);
3471 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3472 REPORTER_ASSERT(reporter, 3*kRepeatCnt == pathRef->countPoints());
3473 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == pathRef->getSegmentMasks());
3474 for (int i = 0; i < kRepeatCnt; ++i) {
3475 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == pathRef->atVerb(i));
3476 }
3477 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003478 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003479 }
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003480};
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003481
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003482static void test_operatorEqual(skiatest::Reporter* reporter) {
3483 SkPath a;
3484 SkPath b;
3485 REPORTER_ASSERT(reporter, a == a);
3486 REPORTER_ASSERT(reporter, a == b);
3487 a.setFillType(SkPath::kInverseWinding_FillType);
3488 REPORTER_ASSERT(reporter, a != b);
3489 a.reset();
3490 REPORTER_ASSERT(reporter, a == b);
3491 a.lineTo(1, 1);
3492 REPORTER_ASSERT(reporter, a != b);
3493 a.reset();
3494 REPORTER_ASSERT(reporter, a == b);
3495 a.lineTo(1, 1);
3496 b.lineTo(1, 2);
3497 REPORTER_ASSERT(reporter, a != b);
3498 a.reset();
3499 a.lineTo(1, 2);
3500 REPORTER_ASSERT(reporter, a == b);
3501}
3502
caryclark66a5d8b2014-06-24 08:30:15 -07003503static void compare_dump(skiatest::Reporter* reporter, const SkPath& path, bool force,
caryclarke9562592014-09-15 09:26:09 -07003504 bool dumpAsHex, const char* str) {
caryclark66a5d8b2014-06-24 08:30:15 -07003505 SkDynamicMemoryWStream wStream;
caryclarke9562592014-09-15 09:26:09 -07003506 path.dump(&wStream, force, dumpAsHex);
caryclark66a5d8b2014-06-24 08:30:15 -07003507 SkAutoDataUnref data(wStream.copyToData());
3508 REPORTER_ASSERT(reporter, data->size() == strlen(str));
mtkleind4897592014-11-14 09:22:40 -08003509 if (strlen(str) > 0) {
3510 REPORTER_ASSERT(reporter, !memcmp(data->data(), str, strlen(str)));
3511 } else {
3512 REPORTER_ASSERT(reporter, data->data() == NULL || !memcmp(data->data(), str, strlen(str)));
3513 }
caryclark66a5d8b2014-06-24 08:30:15 -07003514}
3515
3516static void test_dump(skiatest::Reporter* reporter) {
3517 SkPath p;
caryclarke9562592014-09-15 09:26:09 -07003518 compare_dump(reporter, p, false, false, "");
3519 compare_dump(reporter, p, true, false, "");
caryclark66a5d8b2014-06-24 08:30:15 -07003520 p.moveTo(1, 2);
3521 p.lineTo(3, 4);
caryclarke9562592014-09-15 09:26:09 -07003522 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3523 "path.lineTo(3, 4);\n");
3524 compare_dump(reporter, p, true, false, "path.moveTo(1, 2);\n"
3525 "path.lineTo(3, 4);\n"
3526 "path.lineTo(1, 2);\n"
3527 "path.close();\n");
caryclark66a5d8b2014-06-24 08:30:15 -07003528 p.reset();
3529 p.moveTo(1, 2);
3530 p.quadTo(3, 4, 5, 6);
caryclarke9562592014-09-15 09:26:09 -07003531 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3532 "path.quadTo(3, 4, 5, 6);\n");
caryclark66a5d8b2014-06-24 08:30:15 -07003533 p.reset();
3534 p.moveTo(1, 2);
3535 p.conicTo(3, 4, 5, 6, 0.5f);
caryclarke9562592014-09-15 09:26:09 -07003536 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3537 "path.conicTo(3, 4, 5, 6, 0.5f);\n");
caryclark66a5d8b2014-06-24 08:30:15 -07003538 p.reset();
3539 p.moveTo(1, 2);
3540 p.cubicTo(3, 4, 5, 6, 7, 8);
caryclarke9562592014-09-15 09:26:09 -07003541 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3542 "path.cubicTo(3, 4, 5, 6, 7, 8);\n");
3543 p.reset();
3544 p.moveTo(1, 2);
3545 p.lineTo(3, 4);
caryclark08fa28c2014-10-23 13:08:56 -07003546 compare_dump(reporter, p, false, true,
3547 "path.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)); // 1, 2\n"
3548 "path.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)); // 3, 4\n");
caryclarke9562592014-09-15 09:26:09 -07003549 p.reset();
3550 p.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000));
3551 p.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000));
3552 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3553 "path.lineTo(3, 4);\n");
caryclark66a5d8b2014-06-24 08:30:15 -07003554}
3555
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003556class PathTest_Private {
3557public:
3558 static void TestPathTo(skiatest::Reporter* reporter) {
3559 SkPath p, q;
3560 p.lineTo(4, 4);
3561 p.reversePathTo(q);
3562 check_path_is_line(reporter, &p, 4, 4);
3563 q.moveTo(-4, -4);
3564 p.reversePathTo(q);
3565 check_path_is_line(reporter, &p, 4, 4);
3566 q.lineTo(7, 8);
3567 q.conicTo(8, 7, 6, 5, 0.5f);
3568 q.quadTo(6, 7, 8, 6);
3569 q.cubicTo(5, 6, 7, 8, 7, 5);
3570 q.close();
3571 p.reversePathTo(q);
3572 SkRect reverseExpected = {-4, -4, 8, 8};
3573 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
3574 }
3575};
3576
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00003577DEF_TEST(Paths, reporter) {
commit-bot@chromium.org4e332f82014-05-05 16:04:42 +00003578 test_path_crbug364224();
3579
bungeman@google.coma5809a32013-06-21 15:13:34 +00003580 SkTSize<SkScalar>::Make(3,4);
3581
3582 SkPath p, empty;
3583 SkRect bounds, bounds2;
3584 test_empty(reporter, p);
reed@android.com3abec1d2009-03-02 05:36:20 +00003585
reed@android.comd252db02009-04-01 18:31:44 +00003586 REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
reed@android.com80e39a72009-04-02 16:59:40 +00003587
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003588 // this triggers a code path in SkPath::operator= which is otherwise unexercised
3589 SkPath& self = p;
3590 p = self;
3591
3592 // this triggers a code path in SkPath::swap which is otherwise unexercised
3593 p.swap(self);
3594
reed@android.com3abec1d2009-03-02 05:36:20 +00003595 bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
reed@android.com6b82d1a2009-06-03 02:35:01 +00003596
reed@android.com6b82d1a2009-06-03 02:35:01 +00003597 p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1);
3598 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00003599 // we have quads or cubics
reed220f9262014-12-17 08:21:04 -08003600 REPORTER_ASSERT(reporter,
3601 p.getSegmentMasks() & (kCurveSegmentMask | SkPath::kConic_SegmentMask));
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003602 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00003603
reed@android.com6b82d1a2009-06-03 02:35:01 +00003604 p.reset();
bungeman@google.coma5809a32013-06-21 15:13:34 +00003605 test_empty(reporter, p);
reed@google.com10296cc2011-09-21 12:29:05 +00003606
reed@android.com6b82d1a2009-06-03 02:35:01 +00003607 p.addOval(bounds);
3608 check_convex_bounds(reporter, p, bounds);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003609 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00003610
bungeman@google.coma5809a32013-06-21 15:13:34 +00003611 p.rewind();
3612 test_empty(reporter, p);
3613
reed@android.com3abec1d2009-03-02 05:36:20 +00003614 p.addRect(bounds);
reed@android.com6b82d1a2009-06-03 02:35:01 +00003615 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00003616 // we have only lines
3617 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == p.getSegmentMasks());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003618 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@android.com3abec1d2009-03-02 05:36:20 +00003619
bungeman@google.coma5809a32013-06-21 15:13:34 +00003620 REPORTER_ASSERT(reporter, p != empty);
3621 REPORTER_ASSERT(reporter, !(p == empty));
reed@android.com3abec1d2009-03-02 05:36:20 +00003622
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00003623 // do getPoints and getVerbs return the right result
3624 REPORTER_ASSERT(reporter, p.getPoints(NULL, 0) == 4);
3625 REPORTER_ASSERT(reporter, p.getVerbs(NULL, 0) == 5);
reed@android.com3abec1d2009-03-02 05:36:20 +00003626 SkPoint pts[4];
3627 int count = p.getPoints(pts, 4);
3628 REPORTER_ASSERT(reporter, count == 4);
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00003629 uint8_t verbs[6];
3630 verbs[5] = 0xff;
3631 p.getVerbs(verbs, 5);
3632 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == verbs[0]);
3633 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[1]);
3634 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[2]);
3635 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[3]);
3636 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == verbs[4]);
3637 REPORTER_ASSERT(reporter, 0xff == verbs[5]);
reed@android.com3abec1d2009-03-02 05:36:20 +00003638 bounds2.set(pts, 4);
3639 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00003640
reed@android.com3abec1d2009-03-02 05:36:20 +00003641 bounds.offset(SK_Scalar1*3, SK_Scalar1*4);
3642 p.offset(SK_Scalar1*3, SK_Scalar1*4);
reed@android.comd252db02009-04-01 18:31:44 +00003643 REPORTER_ASSERT(reporter, bounds == p.getBounds());
reed@android.com3abec1d2009-03-02 05:36:20 +00003644
reed@android.com3abec1d2009-03-02 05:36:20 +00003645 REPORTER_ASSERT(reporter, p.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00003646 bounds2.setEmpty();
reed@android.com3abec1d2009-03-02 05:36:20 +00003647 REPORTER_ASSERT(reporter, p.isRect(&bounds2));
3648 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00003649
reed@android.com3abec1d2009-03-02 05:36:20 +00003650 // now force p to not be a rect
3651 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2);
3652 p.addRect(bounds);
3653 REPORTER_ASSERT(reporter, !p.isRect(NULL));
reed@android.com3abec1d2009-03-02 05:36:20 +00003654
robertphillipsfe7c4272014-12-29 11:36:39 -08003655 // Test an edge case w.r.t. the bound returned by isRect (i.e., the
3656 // path has a trailing moveTo. Please see crbug.com\445368)
3657 {
3658 SkRect r;
3659 p.reset();
3660 p.addRect(bounds);
3661 REPORTER_ASSERT(reporter, p.isRect(&r));
3662 REPORTER_ASSERT(reporter, r == bounds);
3663 // add a moveTo outside of our bounds
3664 p.moveTo(bounds.fLeft + 10, bounds.fBottom + 10);
3665 REPORTER_ASSERT(reporter, p.isRect(&r));
3666 REPORTER_ASSERT(reporter, r == bounds);
3667 }
3668
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003669 test_operatorEqual(reporter);
reed@google.com7e6c4d12012-05-10 14:05:43 +00003670 test_isLine(reporter);
3671 test_isRect(reporter);
caryclark@google.com56f233a2012-11-19 13:06:06 +00003672 test_isNestedRects(reporter);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003673 test_zero_length_paths(reporter);
reed@google.comcabaf1d2012-01-11 21:03:05 +00003674 test_direction(reporter);
reed@google.com04863fa2011-05-15 04:08:24 +00003675 test_convexity(reporter);
reed@google.com7c424812011-05-15 04:38:34 +00003676 test_convexity2(reporter);
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00003677 test_conservativelyContains(reporter);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00003678 test_close(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00003679 test_segment_masks(reporter);
reed@google.com53effc52011-09-21 19:05:12 +00003680 test_flattening(reporter);
3681 test_transform(reporter);
reed@google.com3563c9e2011-11-14 19:34:57 +00003682 test_bounds(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00003683 test_iter(reporter);
3684 test_raw_iter(reporter);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003685 test_circle(reporter);
3686 test_oval(reporter);
reed@google.com8b06f1a2012-05-29 12:03:46 +00003687 test_strokerec(reporter);
reed@google.com744faba2012-05-29 19:54:52 +00003688 test_addPoly(reporter);
reed@google.com0bb18bb2012-07-26 15:20:36 +00003689 test_isfinite(reporter);
tomhudson@google.comed02c4d2012-08-10 14:10:45 +00003690 test_isfinite_after_transform(reporter);
robertphillips@google.comb95eaa82012-10-18 15:26:12 +00003691 test_arb_round_rect_is_convex(reporter);
robertphillips@google.com158618e2012-10-23 16:56:56 +00003692 test_arb_zero_rad_round_rect_is_rect(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003693 test_addrect(reporter);
reed@google.coma8790de2012-10-24 21:04:04 +00003694 test_addrect_isfinite(reporter);
sugoi@google.com54f0d1b2013-02-27 19:17:41 +00003695 test_tricky_cubic();
3696 test_clipped_cubic();
3697 test_crbug_170666();
reed@google.com7a90daf2013-04-10 18:44:00 +00003698 test_bad_cubic_crbug229478();
reed@google.com3eff3592013-05-08 21:08:21 +00003699 test_bad_cubic_crbug234190();
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +00003700 test_gen_id(reporter);
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +00003701 test_path_close_issue1474(reporter);
reed@google.comb58ba892013-10-15 15:44:35 +00003702 test_path_to_region(reporter);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003703 test_rrect(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003704 test_arc(reporter);
3705 test_arcTo(reporter);
3706 test_addPath(reporter);
commit-bot@chromium.org14747e52014-02-11 21:16:29 +00003707 test_addPathMode(reporter, false, false);
3708 test_addPathMode(reporter, true, false);
3709 test_addPathMode(reporter, false, true);
3710 test_addPathMode(reporter, true, true);
3711 test_extendClosedPath(reporter);
3712 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode);
3713 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003714 test_conicTo_special_case(reporter);
3715 test_get_point(reporter);
3716 test_contains(reporter);
3717 PathTest_Private::TestPathTo(reporter);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003718 PathRefTest_Private::TestPathRef(reporter);
caryclark66a5d8b2014-06-24 08:30:15 -07003719 test_dump(reporter);
piotaixrfac4e0e2014-08-26 11:59:04 -07003720 test_path_crbugskia2820(reporter);
reed5bcbe912014-12-15 12:28:33 -08003721 test_skbug_3239(reporter);
reed@android.com3abec1d2009-03-02 05:36:20 +00003722}