blob: 44b67860195c01c4c6d4c74549489a39253f3860 [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
bsalomon1978ce22016-05-31 10:42:16 -07008#include <cmath>
reed@google.com8cae8352012-09-14 15:18:41 +00009#include "SkCanvas.h"
caryclark9aacd902015-12-14 08:38:09 -080010#include "SkGeometry.h"
reed@google.com55b5f4b2011-09-07 12:23:41 +000011#include "SkPaint.h"
reed@google.com04863fa2011-05-15 04:08:24 +000012#include "SkParse.h"
reed@google.com3e71a882012-01-10 18:44:37 +000013#include "SkParsePath.h"
reed026beb52015-06-10 14:23:15 -070014#include "SkPathPriv.h"
reed@google.com8b06f1a2012-05-29 12:03:46 +000015#include "SkPathEffect.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000016#include "SkRRect.h"
schenney@chromium.org6630d8d2012-01-04 21:05:51 +000017#include "SkRandom.h"
reed@google.com53effc52011-09-21 19:05:12 +000018#include "SkReader32.h"
reed@android.com60bc6d52010-02-11 11:09:39 +000019#include "SkSize.h"
caryclark66a5d8b2014-06-24 08:30:15 -070020#include "SkStream.h"
halcanary435657f2015-09-15 12:53:07 -070021#include "SkStrokeRec.h"
reed@google.com8cae8352012-09-14 15:18:41 +000022#include "SkSurface.h"
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000023#include "SkTypes.h"
24#include "SkWriter32.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000025#include "Test.h"
reed@google.com8cae8352012-09-14 15:18:41 +000026
reed5bcbe912014-12-15 12:28:33 -080027static void set_radii(SkVector radii[4], int index, float rad) {
28 sk_bzero(radii, sizeof(SkVector) * 4);
29 radii[index].set(rad, rad);
30}
31
32static void test_add_rrect(skiatest::Reporter* reporter, const SkRect& bounds,
33 const SkVector radii[4]) {
34 SkRRect rrect;
35 rrect.setRectRadii(bounds, radii);
36 REPORTER_ASSERT(reporter, bounds == rrect.rect());
37
38 SkPath path;
39 // this line should not assert in the debug build (from validate)
40 path.addRRect(rrect);
41 REPORTER_ASSERT(reporter, bounds == path.getBounds());
42}
43
caryclark5ccef572015-03-02 10:07:56 -080044static void test_skbug_3469(skiatest::Reporter* reporter) {
45 SkPath path;
46 path.moveTo(20, 20);
47 path.quadTo(20, 50, 80, 50);
48 path.quadTo(20, 50, 20, 80);
49 REPORTER_ASSERT(reporter, !path.isConvex());
50}
51
reed5bcbe912014-12-15 12:28:33 -080052static void test_skbug_3239(skiatest::Reporter* reporter) {
53 const float min = SkBits2Float(0xcb7f16c8); /* -16717512.000000 */
54 const float max = SkBits2Float(0x4b7f1c1d); /* 16718877.000000 */
55 const float big = SkBits2Float(0x4b7f1bd7); /* 16718807.000000 */
56
57 const float rad = 33436320;
58
59 const SkRect rectx = SkRect::MakeLTRB(min, min, max, big);
60 const SkRect recty = SkRect::MakeLTRB(min, min, big, max);
61
62 SkVector radii[4];
63 for (int i = 0; i < 4; ++i) {
64 set_radii(radii, i, rad);
65 test_add_rrect(reporter, rectx, radii);
66 test_add_rrect(reporter, recty, radii);
67 }
68}
69
commit-bot@chromium.org4e332f82014-05-05 16:04:42 +000070static void make_path_crbug364224(SkPath* path) {
71 path->reset();
72 path->moveTo(3.747501373f, 2.724499941f);
73 path->lineTo(3.747501373f, 3.75f);
74 path->cubicTo(3.747501373f, 3.88774991f, 3.635501385f, 4.0f, 3.497501373f, 4.0f);
75 path->lineTo(0.7475013733f, 4.0f);
76 path->cubicTo(0.6095013618f, 4.0f, 0.4975013733f, 3.88774991f, 0.4975013733f, 3.75f);
77 path->lineTo(0.4975013733f, 1.0f);
78 path->cubicTo(0.4975013733f, 0.8622499704f, 0.6095013618f, 0.75f, 0.7475013733f,0.75f);
79 path->lineTo(3.497501373f, 0.75f);
80 path->cubicTo(3.50275135f, 0.75f, 3.5070014f, 0.7527500391f, 3.513001442f, 0.753000021f);
81 path->lineTo(3.715001345f, 0.5512499809f);
82 path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
83 path->lineTo(0.7475013733f, 0.4999999702f);
84 path->cubicTo(0.4715013802f, 0.4999999702f, 0.2475013733f, 0.7239999771f, 0.2475013733f, 1.0f);
85 path->lineTo(0.2475013733f, 3.75f);
86 path->cubicTo(0.2475013733f, 4.026000023f, 0.4715013504f, 4.25f, 0.7475013733f, 4.25f);
87 path->lineTo(3.497501373f, 4.25f);
88 path->cubicTo(3.773501396f, 4.25f, 3.997501373f, 4.026000023f, 3.997501373f, 3.75f);
89 path->lineTo(3.997501373f, 2.474750042f);
90 path->lineTo(3.747501373f, 2.724499941f);
91 path->close();
92}
93
94static void make_path_crbug364224_simplified(SkPath* path) {
95 path->moveTo(3.747501373f, 2.724499941f);
96 path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
97 path->close();
98}
99
100static void test_path_crbug364224() {
101 SkPath path;
102 SkPaint paint;
reede8f30622016-03-23 18:59:25 -0700103 auto surface(SkSurface::MakeRasterN32Premul(84, 88));
commit-bot@chromium.org4e332f82014-05-05 16:04:42 +0000104 SkCanvas* canvas = surface->getCanvas();
105
106 make_path_crbug364224_simplified(&path);
107 canvas->drawPath(path, paint);
108
109 make_path_crbug364224(&path);
110 canvas->drawPath(path, paint);
111}
112
piotaixrfac4e0e2014-08-26 11:59:04 -0700113/**
114 * In debug mode, this path was causing an assertion to fail in
115 * SkPathStroker::preJoinTo() and, in Release, the use of an unitialized value.
116 */
117static void make_path_crbugskia2820(SkPath* path, skiatest::Reporter* reporter) {
118 SkPoint orig, p1, p2, p3;
119 orig = SkPoint::Make(1.f, 1.f);
120 p1 = SkPoint::Make(1.f - SK_ScalarNearlyZero, 1.f);
121 p2 = SkPoint::Make(1.f, 1.f + SK_ScalarNearlyZero);
122 p3 = SkPoint::Make(2.f, 2.f);
123
124 path->reset();
125 path->moveTo(orig);
126 path->cubicTo(p1, p2, p3);
127 path->close();
128}
129
130static void test_path_crbugskia2820(skiatest::Reporter* reporter) {//GrContext* context) {
131 SkPath path;
132 make_path_crbugskia2820(&path, reporter);
133
134 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
135 stroke.setStrokeStyle(2 * SK_Scalar1);
136 stroke.applyToPath(&path, path);
137}
138
reed@google.comcc8be772013-10-15 15:35:29 +0000139static void make_path0(SkPath* path) {
140 // from * https://code.google.com/p/skia/issues/detail?id=1706
141
142 path->moveTo(146.939f, 1012.84f);
143 path->lineTo(181.747f, 1009.18f);
144 path->lineTo(182.165f, 1013.16f);
145 path->lineTo(147.357f, 1016.82f);
146 path->lineTo(146.939f, 1012.84f);
147 path->close();
148}
149
150static void make_path1(SkPath* path) {
151 path->addRect(SkRect::MakeXYWH(10, 10, 10, 1));
152}
153
154typedef void (*PathProc)(SkPath*);
155
156/*
157 * Regression test: we used to crash (overwrite internal storage) during
158 * construction of the region when the path was INVERSE. That is now fixed,
159 * so test these regions (which used to assert/crash).
160 *
161 * https://code.google.com/p/skia/issues/detail?id=1706
162 */
163static void test_path_to_region(skiatest::Reporter* reporter) {
164 PathProc procs[] = {
165 make_path0,
166 make_path1,
167 };
skia.committer@gmail.com47262912013-10-16 07:02:24 +0000168
reed@google.comcc8be772013-10-15 15:35:29 +0000169 SkRegion clip;
170 clip.setRect(0, 0, 1255, 1925);
skia.committer@gmail.com47262912013-10-16 07:02:24 +0000171
reed@google.comcc8be772013-10-15 15:35:29 +0000172 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
173 SkPath path;
174 procs[i](&path);
skia.committer@gmail.com47262912013-10-16 07:02:24 +0000175
reed@google.comcc8be772013-10-15 15:35:29 +0000176 SkRegion rgn;
177 rgn.setPath(path, clip);
178 path.toggleInverseFillType();
179 rgn.setPath(path, clip);
180 }
181}
182
halcanary4dbbd042016-06-07 17:21:10 -0700183#ifdef SK_BUILD_FOR_WIN
caryclark@google.com56f233a2012-11-19 13:06:06 +0000184 #define SUPPRESS_VISIBILITY_WARNING
185#else
186 #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
187#endif
188
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +0000189static void test_path_close_issue1474(skiatest::Reporter* reporter) {
190 // This test checks that r{Line,Quad,Conic,Cubic}To following a close()
191 // are relative to the point we close to, not relative to the point we close from.
192 SkPath path;
193 SkPoint last;
194
195 // Test rLineTo().
196 path.rLineTo(0, 100);
197 path.rLineTo(100, 0);
198 path.close(); // Returns us back to 0,0.
199 path.rLineTo(50, 50); // This should go to 50,50.
200
201 path.getLastPt(&last);
202 REPORTER_ASSERT(reporter, 50 == last.fX);
203 REPORTER_ASSERT(reporter, 50 == last.fY);
204
205 // Test rQuadTo().
206 path.rewind();
207 path.rLineTo(0, 100);
208 path.rLineTo(100, 0);
209 path.close();
210 path.rQuadTo(50, 50, 75, 75);
211
212 path.getLastPt(&last);
213 REPORTER_ASSERT(reporter, 75 == last.fX);
214 REPORTER_ASSERT(reporter, 75 == last.fY);
215
216 // Test rConicTo().
217 path.rewind();
218 path.rLineTo(0, 100);
219 path.rLineTo(100, 0);
220 path.close();
221 path.rConicTo(50, 50, 85, 85, 2);
222
223 path.getLastPt(&last);
224 REPORTER_ASSERT(reporter, 85 == last.fX);
225 REPORTER_ASSERT(reporter, 85 == last.fY);
226
227 // Test rCubicTo().
228 path.rewind();
229 path.rLineTo(0, 100);
230 path.rLineTo(100, 0);
231 path.close();
232 path.rCubicTo(50, 50, 85, 85, 95, 95);
233
234 path.getLastPt(&last);
235 REPORTER_ASSERT(reporter, 95 == last.fX);
236 REPORTER_ASSERT(reporter, 95 == last.fY);
237}
238
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000239static void test_gen_id(skiatest::Reporter* reporter) {
240 SkPath a, b;
241 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
242
243 a.moveTo(0, 0);
244 const uint32_t z = a.getGenerationID();
245 REPORTER_ASSERT(reporter, z != b.getGenerationID());
246
247 a.reset();
248 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
249
250 a.moveTo(1, 1);
251 const uint32_t y = a.getGenerationID();
252 REPORTER_ASSERT(reporter, z != y);
253
254 b.moveTo(2, 2);
255 const uint32_t x = b.getGenerationID();
256 REPORTER_ASSERT(reporter, x != y && x != z);
257
258 a.swap(b);
259 REPORTER_ASSERT(reporter, b.getGenerationID() == y && a.getGenerationID() == x);
260
261 b = a;
262 REPORTER_ASSERT(reporter, b.getGenerationID() == x);
263
264 SkPath c(a);
265 REPORTER_ASSERT(reporter, c.getGenerationID() == x);
266
267 c.lineTo(3, 3);
268 const uint32_t w = c.getGenerationID();
269 REPORTER_ASSERT(reporter, b.getGenerationID() == x);
270 REPORTER_ASSERT(reporter, a.getGenerationID() == x);
271 REPORTER_ASSERT(reporter, w != x);
272
djsollen50da1d82015-02-17 09:09:53 -0800273#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000274 static bool kExpectGenIDToIgnoreFill = false;
275#else
276 static bool kExpectGenIDToIgnoreFill = true;
277#endif
278
279 c.toggleInverseFillType();
280 const uint32_t v = c.getGenerationID();
281 REPORTER_ASSERT(reporter, (v == w) == kExpectGenIDToIgnoreFill);
282
283 c.rewind();
284 REPORTER_ASSERT(reporter, v != c.getGenerationID());
285}
286
reed@google.com3eff3592013-05-08 21:08:21 +0000287// This used to assert in the debug build, as the edges did not all line-up.
288static void test_bad_cubic_crbug234190() {
289 SkPath path;
290 path.moveTo(13.8509f, 3.16858f);
291 path.cubicTo(-2.35893e+08f, -4.21044e+08f,
292 -2.38991e+08f, -4.26573e+08f,
293 -2.41016e+08f, -4.30188e+08f);
294
295 SkPaint paint;
296 paint.setAntiAlias(true);
reede8f30622016-03-23 18:59:25 -0700297 auto surface(SkSurface::MakeRasterN32Premul(84, 88));
reed@google.com3eff3592013-05-08 21:08:21 +0000298 surface->getCanvas()->drawPath(path, paint);
299}
300
reed@google.com7a90daf2013-04-10 18:44:00 +0000301static void test_bad_cubic_crbug229478() {
302 const SkPoint pts[] = {
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000303 { 4595.91064f, -11596.9873f },
304 { 4597.2168f, -11595.9414f },
305 { 4598.52344f, -11594.8955f },
306 { 4599.83008f, -11593.8496f },
reed@google.com7a90daf2013-04-10 18:44:00 +0000307 };
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000308
reed@google.com7a90daf2013-04-10 18:44:00 +0000309 SkPath path;
310 path.moveTo(pts[0]);
311 path.cubicTo(pts[1], pts[2], pts[3]);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000312
reed@google.com7a90daf2013-04-10 18:44:00 +0000313 SkPaint paint;
314 paint.setStyle(SkPaint::kStroke_Style);
315 paint.setStrokeWidth(20);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000316
reed@google.com7a90daf2013-04-10 18:44:00 +0000317 SkPath dst;
318 // Before the fix, this would infinite-recurse, and run out of stack
319 // because we would keep trying to subdivide a degenerate cubic segment.
halcanary96fcdcc2015-08-27 07:41:13 -0700320 paint.getFillPath(path, &dst, nullptr);
reed@google.com7a90daf2013-04-10 18:44:00 +0000321}
322
reed@google.com64d62952013-01-18 17:49:28 +0000323static void build_path_170666(SkPath& path) {
324 path.moveTo(17.9459f, 21.6344f);
325 path.lineTo(139.545f, -47.8105f);
326 path.lineTo(139.545f, -47.8105f);
327 path.lineTo(131.07f, -47.3888f);
328 path.lineTo(131.07f, -47.3888f);
329 path.lineTo(122.586f, -46.9532f);
330 path.lineTo(122.586f, -46.9532f);
331 path.lineTo(18076.6f, 31390.9f);
332 path.lineTo(18076.6f, 31390.9f);
333 path.lineTo(18085.1f, 31390.5f);
334 path.lineTo(18085.1f, 31390.5f);
335 path.lineTo(18076.6f, 31390.9f);
336 path.lineTo(18076.6f, 31390.9f);
337 path.lineTo(17955, 31460.3f);
338 path.lineTo(17955, 31460.3f);
339 path.lineTo(17963.5f, 31459.9f);
340 path.lineTo(17963.5f, 31459.9f);
341 path.lineTo(17971.9f, 31459.5f);
342 path.lineTo(17971.9f, 31459.5f);
343 path.lineTo(17.9551f, 21.6205f);
344 path.lineTo(17.9551f, 21.6205f);
345 path.lineTo(9.47091f, 22.0561f);
346 path.lineTo(9.47091f, 22.0561f);
347 path.lineTo(17.9459f, 21.6344f);
348 path.lineTo(17.9459f, 21.6344f);
349 path.close();path.moveTo(0.995934f, 22.4779f);
350 path.lineTo(0.986725f, 22.4918f);
351 path.lineTo(0.986725f, 22.4918f);
352 path.lineTo(17955, 31460.4f);
353 path.lineTo(17955, 31460.4f);
354 path.lineTo(17971.9f, 31459.5f);
355 path.lineTo(17971.9f, 31459.5f);
356 path.lineTo(18093.6f, 31390.1f);
357 path.lineTo(18093.6f, 31390.1f);
358 path.lineTo(18093.6f, 31390);
359 path.lineTo(18093.6f, 31390);
360 path.lineTo(139.555f, -47.8244f);
361 path.lineTo(139.555f, -47.8244f);
362 path.lineTo(122.595f, -46.9671f);
363 path.lineTo(122.595f, -46.9671f);
364 path.lineTo(0.995934f, 22.4779f);
365 path.lineTo(0.995934f, 22.4779f);
366 path.close();
367 path.moveTo(5.43941f, 25.5223f);
368 path.lineTo(798267, -28871.1f);
369 path.lineTo(798267, -28871.1f);
370 path.lineTo(3.12512e+06f, -113102);
371 path.lineTo(3.12512e+06f, -113102);
372 path.cubicTo(5.16324e+06f, -186882, 8.15247e+06f, -295092, 1.1957e+07f, -432813);
373 path.cubicTo(1.95659e+07f, -708257, 3.04359e+07f, -1.10175e+06f, 4.34798e+07f, -1.57394e+06f);
374 path.cubicTo(6.95677e+07f, -2.51831e+06f, 1.04352e+08f, -3.77748e+06f, 1.39135e+08f, -5.03666e+06f);
375 path.cubicTo(1.73919e+08f, -6.29583e+06f, 2.08703e+08f, -7.555e+06f, 2.34791e+08f, -8.49938e+06f);
376 path.cubicTo(2.47835e+08f, -8.97157e+06f, 2.58705e+08f, -9.36506e+06f, 2.66314e+08f, -9.6405e+06f);
377 path.cubicTo(2.70118e+08f, -9.77823e+06f, 2.73108e+08f, -9.88644e+06f, 2.75146e+08f, -9.96022e+06f);
378 path.cubicTo(2.76165e+08f, -9.99711e+06f, 2.76946e+08f, -1.00254e+07f, 2.77473e+08f, -1.00444e+07f);
379 path.lineTo(2.78271e+08f, -1.00733e+07f);
380 path.lineTo(2.78271e+08f, -1.00733e+07f);
381 path.cubicTo(2.78271e+08f, -1.00733e+07f, 2.08703e+08f, -7.555e+06f, 135.238f, 23.3517f);
382 path.cubicTo(131.191f, 23.4981f, 125.995f, 23.7976f, 123.631f, 24.0206f);
383 path.cubicTo(121.267f, 24.2436f, 122.631f, 24.3056f, 126.677f, 24.1591f);
384 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
385 path.lineTo(2.77473e+08f, -1.00444e+07f);
386 path.lineTo(2.77473e+08f, -1.00444e+07f);
387 path.cubicTo(2.76946e+08f, -1.00254e+07f, 2.76165e+08f, -9.99711e+06f, 2.75146e+08f, -9.96022e+06f);
388 path.cubicTo(2.73108e+08f, -9.88644e+06f, 2.70118e+08f, -9.77823e+06f, 2.66314e+08f, -9.6405e+06f);
389 path.cubicTo(2.58705e+08f, -9.36506e+06f, 2.47835e+08f, -8.97157e+06f, 2.34791e+08f, -8.49938e+06f);
390 path.cubicTo(2.08703e+08f, -7.555e+06f, 1.73919e+08f, -6.29583e+06f, 1.39135e+08f, -5.03666e+06f);
391 path.cubicTo(1.04352e+08f, -3.77749e+06f, 6.95677e+07f, -2.51831e+06f, 4.34798e+07f, -1.57394e+06f);
392 path.cubicTo(3.04359e+07f, -1.10175e+06f, 1.95659e+07f, -708258, 1.1957e+07f, -432814);
393 path.cubicTo(8.15248e+06f, -295092, 5.16324e+06f, -186883, 3.12513e+06f, -113103);
394 path.lineTo(798284, -28872);
395 path.lineTo(798284, -28872);
396 path.lineTo(22.4044f, 24.6677f);
397 path.lineTo(22.4044f, 24.6677f);
398 path.cubicTo(22.5186f, 24.5432f, 18.8134f, 24.6337f, 14.1287f, 24.8697f);
399 path.cubicTo(9.4439f, 25.1057f, 5.55359f, 25.3978f, 5.43941f, 25.5223f);
400 path.close();
401}
402
403static void build_path_simple_170666(SkPath& path) {
404 path.moveTo(126.677f, 24.1591f);
405 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
406}
407
408// This used to assert in the SK_DEBUG build, as the clip step would fail with
409// too-few interations in our cubic-line intersection code. That code now runs
410// 24 interations (instead of 16).
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000411static void test_crbug_170666() {
reed@google.com64d62952013-01-18 17:49:28 +0000412 SkPath path;
413 SkPaint paint;
414 paint.setAntiAlias(true);
415
reede8f30622016-03-23 18:59:25 -0700416 auto surface(SkSurface::MakeRasterN32Premul(1000, 1000));
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000417
reed@google.com64d62952013-01-18 17:49:28 +0000418 build_path_simple_170666(path);
419 surface->getCanvas()->drawPath(path, paint);
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000420
reed@google.com64d62952013-01-18 17:49:28 +0000421 build_path_170666(path);
422 surface->getCanvas()->drawPath(path, paint);
423}
424
caryclarke8c56662015-07-14 11:19:26 -0700425
426static void test_tiny_path_convexity(skiatest::Reporter* reporter, const char* pathBug,
427 SkScalar tx, SkScalar ty, SkScalar scale) {
428 SkPath smallPath;
429 SkAssertResult(SkParsePath::FromSVGString(pathBug, &smallPath));
430 bool smallConvex = smallPath.isConvex();
431 SkPath largePath;
432 SkAssertResult(SkParsePath::FromSVGString(pathBug, &largePath));
433 SkMatrix matrix;
434 matrix.reset();
435 matrix.preTranslate(100, 100);
436 matrix.preScale(scale, scale);
437 largePath.transform(matrix);
438 bool largeConvex = largePath.isConvex();
439 REPORTER_ASSERT(reporter, smallConvex == largeConvex);
440}
441
442static void test_crbug_493450(skiatest::Reporter* reporter) {
443 const char reducedCase[] =
444 "M0,0"
445 "L0.0002, 0"
446 "L0.0002, 0.0002"
447 "L0.0001, 0.0001"
448 "L0,0.0002"
449 "Z";
450 test_tiny_path_convexity(reporter, reducedCase, 100, 100, 100000);
451 const char originalFiddleData[] =
452 "M-0.3383152268862998,-0.11217565719203619L-0.33846085183212765,-0.11212264406895281"
453 "L-0.338509393480737,-0.11210607966681395L-0.33857792286700894,-0.1121889121487573"
454 "L-0.3383866116636664,-0.11228834570924921L-0.33842087635680235,-0.11246078673250548"
455 "L-0.33809536177201055,-0.11245415228342878L-0.33797257995493996,-0.11216571641452182"
456 "L-0.33802112160354925,-0.11201996164188659L-0.33819815585141844,-0.11218559834671019Z";
457 test_tiny_path_convexity(reporter, originalFiddleData, 280081.4116670522f, 93268.04618493588f,
458 826357.3384828606f);
459}
460
461static void test_crbug_495894(skiatest::Reporter* reporter) {
462 const char originalFiddleData[] =
463 "M-0.34004273849857214,-0.11332803232216355L-0.34008271397389744,-0.11324483772714951"
464 "L-0.3401940742265893,-0.11324483772714951L-0.34017694188002134,-0.11329807920275889"
465 "L-0.3402026403998733,-0.11333468903941245L-0.34029972369709194,-0.11334134592705701"
466 "L-0.3403054344792813,-0.11344121970007795L-0.3403140006525653,-0.11351115418399343"
467 "L-0.34024261587519866,-0.11353446986281181L-0.3402197727464413,-0.11360442946144192"
468 "L-0.34013696640469604,-0.11359110237029302L-0.34009128014718143,-0.1135877707043939"
469 "L-0.3400598708451401,-0.11360776134112742L-0.34004273849857214,-0.11355112520064405"
470 "L-0.3400113291965308,-0.11355112520064405L-0.3399970522410575,-0.11359110237029302"
471 "L-0.33997135372120546,-0.11355112520064405L-0.3399627875479215,-0.11353780084493197"
472 "L-0.3399485105924481,-0.11350782354357004L-0.3400027630232468,-0.11346452910331437"
473 "L-0.3399485105924481,-0.11340126558629839L-0.33993994441916414,-0.11340126558629839"
474 "L-0.33988283659727087,-0.11331804756574679L-0.33989140277055485,-0.11324483772714951"
475 "L-0.33997991989448945,-0.11324483772714951L-0.3399856306766788,-0.11324483772714951"
476 "L-0.34002560615200417,-0.11334467443478255ZM-0.3400684370184241,-0.11338461985124307"
477 "L-0.340154098751264,-0.11341791238732665L-0.340162664924548,-0.1134378899559977"
478 "L-0.34017979727111597,-0.11340126558629839L-0.3401655203156427,-0.11338129083212668"
479 "L-0.34012268944922275,-0.11332137577529414L-0.34007414780061346,-0.11334467443478255Z"
480 "M-0.3400027630232468,-0.11290567901106024L-0.3400113291965308,-0.11298876531245433"
481 "L-0.33997991989448945,-0.11301535852306784L-0.33990282433493346,-0.11296217481488612"
482 "L-0.33993994441916414,-0.11288906492739594Z";
483 test_tiny_path_convexity(reporter, originalFiddleData, 22682.240000000005f,7819.72220766405f,
484 65536);
485}
486
mbarbella99600d02016-06-01 15:39:47 -0700487static void test_crbug_613918() {
488 SkPath path;
489 path.conicTo(-6.62478e-08f, 4.13885e-08f, -6.36935e-08f, 3.97927e-08f, 0.729058f);
490 path.quadTo(2.28206e-09f, -1.42572e-09f, 3.91919e-09f, -2.44852e-09f);
491 path.cubicTo(-16752.2f, -26792.9f, -21.4673f, 10.9347f, -8.57322f, -7.22739f);
492
493 // This call could lead to an assert or uninitialized read due to a failure
494 // to check the return value from SkCubicClipper::ChopMonoAtY.
495 path.contains(-1.84817e-08f, 1.15465e-08f);
496}
497
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000498static void test_addrect(skiatest::Reporter* reporter) {
499 SkPath path;
500 path.lineTo(0, 0);
501 path.addRect(SkRect::MakeWH(50, 100));
halcanary96fcdcc2015-08-27 07:41:13 -0700502 REPORTER_ASSERT(reporter, path.isRect(nullptr));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000503
504 path.reset();
505 path.lineTo(FLT_EPSILON, FLT_EPSILON);
506 path.addRect(SkRect::MakeWH(50, 100));
halcanary96fcdcc2015-08-27 07:41:13 -0700507 REPORTER_ASSERT(reporter, !path.isRect(nullptr));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000508
509 path.reset();
510 path.quadTo(0, 0, 0, 0);
511 path.addRect(SkRect::MakeWH(50, 100));
halcanary96fcdcc2015-08-27 07:41:13 -0700512 REPORTER_ASSERT(reporter, !path.isRect(nullptr));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000513
514 path.reset();
515 path.conicTo(0, 0, 0, 0, 0.5f);
516 path.addRect(SkRect::MakeWH(50, 100));
halcanary96fcdcc2015-08-27 07:41:13 -0700517 REPORTER_ASSERT(reporter, !path.isRect(nullptr));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000518
519 path.reset();
520 path.cubicTo(0, 0, 0, 0, 0, 0);
521 path.addRect(SkRect::MakeWH(50, 100));
halcanary96fcdcc2015-08-27 07:41:13 -0700522 REPORTER_ASSERT(reporter, !path.isRect(nullptr));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000523}
524
reed@google.coma8790de2012-10-24 21:04:04 +0000525// Make sure we stay non-finite once we get there (unless we reset or rewind).
526static void test_addrect_isfinite(skiatest::Reporter* reporter) {
527 SkPath path;
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000528
reed@google.coma8790de2012-10-24 21:04:04 +0000529 path.addRect(SkRect::MakeWH(50, 100));
530 REPORTER_ASSERT(reporter, path.isFinite());
531
532 path.moveTo(0, 0);
533 path.lineTo(SK_ScalarInfinity, 42);
534 REPORTER_ASSERT(reporter, !path.isFinite());
535
536 path.addRect(SkRect::MakeWH(50, 100));
537 REPORTER_ASSERT(reporter, !path.isFinite());
538
539 path.reset();
540 REPORTER_ASSERT(reporter, path.isFinite());
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000541
reed@google.coma8790de2012-10-24 21:04:04 +0000542 path.addRect(SkRect::MakeWH(50, 100));
543 REPORTER_ASSERT(reporter, path.isFinite());
544}
545
reed@google.com848148e2013-01-15 15:51:59 +0000546static void build_big_path(SkPath* path, bool reducedCase) {
547 if (reducedCase) {
548 path->moveTo(577330, 1971.72f);
549 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
550 } else {
551 path->moveTo(60.1631f, 7.70567f);
552 path->quadTo(60.1631f, 7.70567f, 0.99474f, 0.901199f);
553 path->lineTo(577379, 1977.77f);
554 path->quadTo(577364, 1979.57f, 577325, 1980.26f);
555 path->quadTo(577286, 1980.95f, 577245, 1980.13f);
556 path->quadTo(577205, 1979.3f, 577187, 1977.45f);
557 path->quadTo(577168, 1975.6f, 577183, 1973.8f);
558 path->quadTo(577198, 1972, 577238, 1971.31f);
559 path->quadTo(577277, 1970.62f, 577317, 1971.45f);
560 path->quadTo(577330, 1971.72f, 577341, 1972.11f);
561 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
562 path->moveTo(306.718f, -32.912f);
563 path->cubicTo(30.531f, 10.0005f, 1502.47f, 13.2804f, 84.3088f, 9.99601f);
564 }
565}
566
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000567static void test_clipped_cubic() {
reede8f30622016-03-23 18:59:25 -0700568 auto surface(SkSurface::MakeRasterN32Premul(640, 480));
reed@google.com848148e2013-01-15 15:51:59 +0000569
570 // This path used to assert, because our cubic-chopping code incorrectly
571 // moved control points after the chop. This test should be run in SK_DEBUG
572 // mode to ensure that we no long assert.
573 SkPath path;
574 for (int doReducedCase = 0; doReducedCase <= 1; ++doReducedCase) {
575 build_big_path(&path, SkToBool(doReducedCase));
skia.committer@gmail.comff21c2e2013-01-16 07:05:56 +0000576
reed@google.com848148e2013-01-15 15:51:59 +0000577 SkPaint paint;
578 for (int doAA = 0; doAA <= 1; ++doAA) {
579 paint.setAntiAlias(SkToBool(doAA));
580 surface->getCanvas()->drawPath(path, paint);
581 }
582 }
583}
584
reed3b2fb982015-07-29 08:37:13 -0700585static void dump_if_ne(skiatest::Reporter* reporter, const SkRect& expected, const SkRect& bounds) {
586 if (expected != bounds) {
587 ERRORF(reporter, "path.getBounds() returned [%g %g %g %g], but expected [%g %g %g %g]",
588 bounds.left(), bounds.top(), bounds.right(), bounds.bottom(),
589 expected.left(), expected.top(), expected.right(), expected.bottom());
590 }
591}
592
reed91f283b2015-07-28 06:00:50 -0700593static void test_bounds_crbug_513799(skiatest::Reporter* reporter) {
594 SkPath path;
reed3b2fb982015-07-29 08:37:13 -0700595#if 0
596 // As written these tests were failing on LLVM 4.2 MacMini Release mysteriously, so we've
597 // rewritten them to avoid this (compiler-bug?).
reed91f283b2015-07-28 06:00:50 -0700598 REPORTER_ASSERT(reporter, SkRect::MakeLTRB(0, 0, 0, 0) == path.getBounds());
599
600 path.moveTo(-5, -8);
601 REPORTER_ASSERT(reporter, SkRect::MakeLTRB(-5, -8, -5, -8) == path.getBounds());
602
603 path.addRect(SkRect::MakeLTRB(1, 2, 3, 4));
604 REPORTER_ASSERT(reporter, SkRect::MakeLTRB(-5, -8, 3, 4) == path.getBounds());
605
606 path.moveTo(1, 2);
607 REPORTER_ASSERT(reporter, SkRect::MakeLTRB(-5, -8, 3, 4) == path.getBounds());
reed3b2fb982015-07-29 08:37:13 -0700608#else
609 dump_if_ne(reporter, SkRect::MakeLTRB(0, 0, 0, 0), path.getBounds());
610
611 path.moveTo(-5, -8); // should set the bounds
612 dump_if_ne(reporter, SkRect::MakeLTRB(-5, -8, -5, -8), path.getBounds());
613
614 path.addRect(SkRect::MakeLTRB(1, 2, 3, 4)); // should extend the bounds
615 dump_if_ne(reporter, SkRect::MakeLTRB(-5, -8, 3, 4), path.getBounds());
616
617 path.moveTo(1, 2); // don't expect this to have changed the bounds
618 dump_if_ne(reporter, SkRect::MakeLTRB(-5, -8, 3, 4), path.getBounds());
619#endif
reed91f283b2015-07-28 06:00:50 -0700620}
621
reedb1b12f82016-07-13 10:56:53 -0700622#include "SkSurface.h"
623static void test_fuzz_crbug_627414(skiatest::Reporter* reporter) {
624 SkPath path;
625 path.moveTo(0, 0);
626 path.conicTo(3.58732e-43f, 2.72084f, 3.00392f, 3.00392f, 8.46e+37f);
627
628 SkPaint paint;
629 paint.setAntiAlias(true);
630
631 auto surf = SkSurface::MakeRasterN32Premul(100, 100);
632 surf->getCanvas()->drawPath(path, paint);
633}
634
reed@google.com8cae8352012-09-14 15:18:41 +0000635// Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/
636// which triggered an assert, from a tricky cubic. This test replicates that
637// example, so we can ensure that we handle it (in SkEdge.cpp), and don't
638// assert in the SK_DEBUG build.
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000639static void test_tricky_cubic() {
reed@google.com8cae8352012-09-14 15:18:41 +0000640 const SkPoint pts[] = {
skia.committer@gmail.com055c7c22012-09-15 02:01:41 +0000641 { SkDoubleToScalar(18.8943768), SkDoubleToScalar(129.121277) },
642 { SkDoubleToScalar(18.8937435), SkDoubleToScalar(129.121689) },
643 { SkDoubleToScalar(18.8950119), SkDoubleToScalar(129.120422) },
644 { SkDoubleToScalar(18.5030727), SkDoubleToScalar(129.13121) },
reed@google.com8cae8352012-09-14 15:18:41 +0000645 };
646
647 SkPath path;
648 path.moveTo(pts[0]);
649 path.cubicTo(pts[1], pts[2], pts[3]);
650
651 SkPaint paint;
652 paint.setAntiAlias(true);
653
reede8f30622016-03-23 18:59:25 -0700654 SkSurface::MakeRasterN32Premul(19, 130)->getCanvas()->drawPath(path, paint);
reed@google.com8cae8352012-09-14 15:18:41 +0000655}
reed@android.com3abec1d2009-03-02 05:36:20 +0000656
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000657// Inspired by http://code.google.com/p/chromium/issues/detail?id=141651
658//
659static void test_isfinite_after_transform(skiatest::Reporter* reporter) {
660 SkPath path;
661 path.quadTo(157, 366, 286, 208);
662 path.arcTo(37, 442, 315, 163, 957494590897113.0f);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000663
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000664 SkMatrix matrix;
665 matrix.setScale(1000*1000, 1000*1000);
666
667 // Be sure that path::transform correctly updates isFinite and the bounds
668 // if the transformation overflows. The previous bug was that isFinite was
669 // set to true in this case, but the bounds were not set to empty (which
670 // they should be).
671 while (path.isFinite()) {
672 REPORTER_ASSERT(reporter, path.getBounds().isFinite());
673 REPORTER_ASSERT(reporter, !path.getBounds().isEmpty());
674 path.transform(matrix);
675 }
676 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
677
678 matrix.setTranslate(SK_Scalar1, SK_Scalar1);
679 path.transform(matrix);
680 // we need to still be non-finite
681 REPORTER_ASSERT(reporter, !path.isFinite());
682 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
683}
684
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000685static void add_corner_arc(SkPath* path, const SkRect& rect,
686 SkScalar xIn, SkScalar yIn,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000687 int startAngle)
688{
689
690 SkScalar rx = SkMinScalar(rect.width(), xIn);
691 SkScalar ry = SkMinScalar(rect.height(), yIn);
692
693 SkRect arcRect;
694 arcRect.set(-rx, -ry, rx, ry);
695 switch (startAngle) {
696 case 0:
697 arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom);
698 break;
699 case 90:
700 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom);
701 break;
702 case 180:
703 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop);
704 break;
705 case 270:
706 arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop);
707 break;
708 default:
709 break;
710 }
711
712 path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false);
713}
714
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000715static void make_arb_round_rect(SkPath* path, const SkRect& r,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000716 SkScalar xCorner, SkScalar yCorner) {
717 // we are lazy here and use the same x & y for each corner
718 add_corner_arc(path, r, xCorner, yCorner, 270);
719 add_corner_arc(path, r, xCorner, yCorner, 0);
720 add_corner_arc(path, r, xCorner, yCorner, 90);
721 add_corner_arc(path, r, xCorner, yCorner, 180);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000722 path->close();
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000723}
724
725// Chrome creates its own round rects with each corner possibly being different.
726// Performance will suffer if they are not convex.
727// Note: PathBench::ArbRoundRectBench performs almost exactly
728// the same test (but with drawing)
729static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000730 SkRandom rand;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000731 SkRect r;
732
733 for (int i = 0; i < 5000; ++i) {
734
robertphillips@google.com158618e2012-10-23 16:56:56 +0000735 SkScalar size = rand.nextUScalar1() * 30;
736 if (size < SK_Scalar1) {
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000737 continue;
738 }
739 r.fLeft = rand.nextUScalar1() * 300;
740 r.fTop = rand.nextUScalar1() * 300;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000741 r.fRight = r.fLeft + 2 * size;
742 r.fBottom = r.fTop + 2 * size;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000743
744 SkPath temp;
745
746 make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
747
748 REPORTER_ASSERT(reporter, temp.isConvex());
749 }
750}
751
robertphillips@google.com158618e2012-10-23 16:56:56 +0000752// Chrome will sometimes create a 0 radius round rect. The degenerate
753// quads prevent the path from being converted to a rect
754// Note: PathBench::ArbRoundRectBench performs almost exactly
755// the same test (but with drawing)
756static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000757 SkRandom rand;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000758 SkRect r;
759
760 for (int i = 0; i < 5000; ++i) {
761
762 SkScalar size = rand.nextUScalar1() * 30;
763 if (size < SK_Scalar1) {
764 continue;
765 }
766 r.fLeft = rand.nextUScalar1() * 300;
767 r.fTop = rand.nextUScalar1() * 300;
768 r.fRight = r.fLeft + 2 * size;
769 r.fBottom = r.fTop + 2 * size;
770
771 SkPath temp;
772
773 make_arb_round_rect(&temp, r, 0, 0);
774
robertphillips@google.com158618e2012-10-23 16:56:56 +0000775 SkRect result;
776 REPORTER_ASSERT(reporter, temp.isRect(&result));
777 REPORTER_ASSERT(reporter, r == result);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000778 }
779}
780
reed@google.com0bb18bb2012-07-26 15:20:36 +0000781static void test_rect_isfinite(skiatest::Reporter* reporter) {
782 const SkScalar inf = SK_ScalarInfinity;
caryclark@google.com7abfa492013-04-12 11:59:41 +0000783 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000784 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000785
reed@google.com0bb18bb2012-07-26 15:20:36 +0000786 SkRect r;
787 r.setEmpty();
788 REPORTER_ASSERT(reporter, r.isFinite());
caryclark@google.com7abfa492013-04-12 11:59:41 +0000789 r.set(0, 0, inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000790 REPORTER_ASSERT(reporter, !r.isFinite());
791 r.set(0, 0, nan, 0);
792 REPORTER_ASSERT(reporter, !r.isFinite());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000793
reed@google.com0bb18bb2012-07-26 15:20:36 +0000794 SkPoint pts[] = {
795 { 0, 0 },
796 { SK_Scalar1, 0 },
797 { 0, SK_Scalar1 },
798 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000799
reed@google.com0bb18bb2012-07-26 15:20:36 +0000800 bool isFine = r.setBoundsCheck(pts, 3);
801 REPORTER_ASSERT(reporter, isFine);
802 REPORTER_ASSERT(reporter, !r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000803
reed@google.com0bb18bb2012-07-26 15:20:36 +0000804 pts[1].set(inf, 0);
805 isFine = r.setBoundsCheck(pts, 3);
806 REPORTER_ASSERT(reporter, !isFine);
807 REPORTER_ASSERT(reporter, r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000808
reed@google.com0bb18bb2012-07-26 15:20:36 +0000809 pts[1].set(nan, 0);
810 isFine = r.setBoundsCheck(pts, 3);
811 REPORTER_ASSERT(reporter, !isFine);
812 REPORTER_ASSERT(reporter, r.isEmpty());
813}
814
815static void test_path_isfinite(skiatest::Reporter* reporter) {
816 const SkScalar inf = SK_ScalarInfinity;
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000817 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000818 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000819
reed@google.com0bb18bb2012-07-26 15:20:36 +0000820 SkPath path;
821 REPORTER_ASSERT(reporter, path.isFinite());
822
823 path.reset();
824 REPORTER_ASSERT(reporter, path.isFinite());
825
826 path.reset();
827 path.moveTo(SK_Scalar1, 0);
828 REPORTER_ASSERT(reporter, path.isFinite());
829
830 path.reset();
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000831 path.moveTo(inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000832 REPORTER_ASSERT(reporter, !path.isFinite());
833
834 path.reset();
835 path.moveTo(nan, 0);
836 REPORTER_ASSERT(reporter, !path.isFinite());
837}
838
839static void test_isfinite(skiatest::Reporter* reporter) {
840 test_rect_isfinite(reporter);
841 test_path_isfinite(reporter);
842}
843
fsb1475b02016-01-20 09:51:07 -0800844static void test_islastcontourclosed(skiatest::Reporter* reporter) {
845 SkPath path;
846 REPORTER_ASSERT(reporter, !path.isLastContourClosed());
847 path.moveTo(0, 0);
848 REPORTER_ASSERT(reporter, !path.isLastContourClosed());
849 path.close();
850 REPORTER_ASSERT(reporter, path.isLastContourClosed());
851 path.lineTo(100, 100);
852 REPORTER_ASSERT(reporter, !path.isLastContourClosed());
853 path.moveTo(200, 200);
854 REPORTER_ASSERT(reporter, !path.isLastContourClosed());
855 path.close();
856 REPORTER_ASSERT(reporter, path.isLastContourClosed());
857 path.moveTo(0, 0);
858 REPORTER_ASSERT(reporter, !path.isLastContourClosed());
859}
860
reed@google.com744faba2012-05-29 19:54:52 +0000861// assert that we always
862// start with a moveTo
863// only have 1 moveTo
864// only have Lines after that
865// end with a single close
866// only have (at most) 1 close
867//
868static void test_poly(skiatest::Reporter* reporter, const SkPath& path,
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000869 const SkPoint srcPts[], bool expectClose) {
reed@google.com744faba2012-05-29 19:54:52 +0000870 SkPath::RawIter iter(path);
871 SkPoint pts[4];
reed@google.com744faba2012-05-29 19:54:52 +0000872
873 bool firstTime = true;
874 bool foundClose = false;
875 for (;;) {
876 switch (iter.next(pts)) {
877 case SkPath::kMove_Verb:
878 REPORTER_ASSERT(reporter, firstTime);
879 REPORTER_ASSERT(reporter, pts[0] == srcPts[0]);
880 srcPts++;
881 firstTime = false;
882 break;
883 case SkPath::kLine_Verb:
884 REPORTER_ASSERT(reporter, !firstTime);
885 REPORTER_ASSERT(reporter, pts[1] == srcPts[0]);
886 srcPts++;
887 break;
888 case SkPath::kQuad_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000889 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected quad verb");
reed@google.com744faba2012-05-29 19:54:52 +0000890 break;
reed@google.com277c3f82013-05-31 15:17:50 +0000891 case SkPath::kConic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000892 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected conic verb");
reed@google.com277c3f82013-05-31 15:17:50 +0000893 break;
reed@google.com744faba2012-05-29 19:54:52 +0000894 case SkPath::kCubic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000895 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected cubic verb");
reed@google.com744faba2012-05-29 19:54:52 +0000896 break;
897 case SkPath::kClose_Verb:
898 REPORTER_ASSERT(reporter, !firstTime);
899 REPORTER_ASSERT(reporter, !foundClose);
900 REPORTER_ASSERT(reporter, expectClose);
901 foundClose = true;
902 break;
903 case SkPath::kDone_Verb:
904 goto DONE;
905 }
906 }
907DONE:
908 REPORTER_ASSERT(reporter, foundClose == expectClose);
909}
910
911static void test_addPoly(skiatest::Reporter* reporter) {
912 SkPoint pts[32];
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000913 SkRandom rand;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000914
reed@google.com744faba2012-05-29 19:54:52 +0000915 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
916 pts[i].fX = rand.nextSScalar1();
917 pts[i].fY = rand.nextSScalar1();
918 }
919
920 for (int doClose = 0; doClose <= 1; ++doClose) {
921 for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) {
922 SkPath path;
bsalomon98806072014-12-12 15:11:17 -0800923 path.addPoly(pts, SkToInt(count), SkToBool(doClose));
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000924 test_poly(reporter, path, pts, SkToBool(doClose));
reed@google.com744faba2012-05-29 19:54:52 +0000925 }
926 }
927}
928
reed@google.com8b06f1a2012-05-29 12:03:46 +0000929static void test_strokerec(skiatest::Reporter* reporter) {
930 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
931 REPORTER_ASSERT(reporter, rec.isFillStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000932
reed@google.com8b06f1a2012-05-29 12:03:46 +0000933 rec.setHairlineStyle();
934 REPORTER_ASSERT(reporter, rec.isHairlineStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000935
reed@google.com8b06f1a2012-05-29 12:03:46 +0000936 rec.setStrokeStyle(SK_Scalar1, false);
937 REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000938
reed@google.com8b06f1a2012-05-29 12:03:46 +0000939 rec.setStrokeStyle(SK_Scalar1, true);
940 REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000941
reed@google.com8b06f1a2012-05-29 12:03:46 +0000942 rec.setStrokeStyle(0, false);
943 REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000944
reed@google.com8b06f1a2012-05-29 12:03:46 +0000945 rec.setStrokeStyle(0, true);
946 REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle());
947}
948
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000949// Set this for paths that don't have a consistent direction such as a bowtie.
950// (cheapComputeDirection is not expected to catch these.)
reed026beb52015-06-10 14:23:15 -0700951const SkPathPriv::FirstDirection kDontCheckDir = static_cast<SkPathPriv::FirstDirection>(-1);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000952
953static void check_direction(skiatest::Reporter* reporter, const SkPath& path,
reed026beb52015-06-10 14:23:15 -0700954 SkPathPriv::FirstDirection expected) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000955 if (expected == kDontCheckDir) {
956 return;
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000957 }
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000958 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
959
reed026beb52015-06-10 14:23:15 -0700960 SkPathPriv::FirstDirection dir;
961 if (SkPathPriv::CheapComputeFirstDirection(copy, &dir)) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000962 REPORTER_ASSERT(reporter, dir == expected);
963 } else {
reed026beb52015-06-10 14:23:15 -0700964 REPORTER_ASSERT(reporter, SkPathPriv::kUnknown_FirstDirection == expected);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000965 }
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000966}
967
reed@google.com3e71a882012-01-10 18:44:37 +0000968static void test_direction(skiatest::Reporter* reporter) {
969 size_t i;
970 SkPath path;
halcanary96fcdcc2015-08-27 07:41:13 -0700971 REPORTER_ASSERT(reporter, !SkPathPriv::CheapComputeFirstDirection(path, nullptr));
reed026beb52015-06-10 14:23:15 -0700972 REPORTER_ASSERT(reporter, !SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCW_FirstDirection));
973 REPORTER_ASSERT(reporter, !SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCCW_FirstDirection));
974 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kUnknown_FirstDirection));
reed@google.com3e71a882012-01-10 18:44:37 +0000975
976 static const char* gDegen[] = {
977 "M 10 10",
978 "M 10 10 M 20 20",
979 "M 10 10 L 20 20",
980 "M 10 10 L 10 10 L 10 10",
981 "M 10 10 Q 10 10 10 10",
982 "M 10 10 C 10 10 10 10 10 10",
983 };
984 for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) {
985 path.reset();
986 bool valid = SkParsePath::FromSVGString(gDegen[i], &path);
987 REPORTER_ASSERT(reporter, valid);
halcanary96fcdcc2015-08-27 07:41:13 -0700988 REPORTER_ASSERT(reporter, !SkPathPriv::CheapComputeFirstDirection(path, nullptr));
reed@google.com3e71a882012-01-10 18:44:37 +0000989 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000990
reed@google.com3e71a882012-01-10 18:44:37 +0000991 static const char* gCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000992 "M 10 10 L 10 10 Q 20 10 20 20",
reed@google.com3e71a882012-01-10 18:44:37 +0000993 "M 10 10 C 20 10 20 20 20 20",
reed@google.comd4146662012-01-31 15:42:29 +0000994 "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 +0000995 // rect with top two corners replaced by cubics with identical middle
996 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000997 "M 10 10 C 10 0 10 0 20 0 L 40 0 C 50 0 50 0 50 10",
998 "M 20 10 L 0 10 Q 10 10 20 0", // left, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000999 };
1000 for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) {
1001 path.reset();
1002 bool valid = SkParsePath::FromSVGString(gCW[i], &path);
1003 REPORTER_ASSERT(reporter, valid);
reed026beb52015-06-10 14:23:15 -07001004 check_direction(reporter, path, SkPathPriv::kCW_FirstDirection);
reed@google.com3e71a882012-01-10 18:44:37 +00001005 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00001006
reed@google.com3e71a882012-01-10 18:44:37 +00001007 static const char* gCCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +00001008 "M 10 10 L 10 10 Q 20 10 20 -20",
reed@google.com3e71a882012-01-10 18:44:37 +00001009 "M 10 10 C 20 10 20 -20 20 -20",
reed@google.comd4146662012-01-31 15:42:29 +00001010 "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 +00001011 // rect with top two corners replaced by cubics with identical middle
1012 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +00001013 "M 50 10 C 50 0 50 0 40 0 L 20 0 C 10 0 10 0 10 10",
1014 "M 10 10 L 30 10 Q 20 10 10 0", // right, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +00001015 };
1016 for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) {
1017 path.reset();
1018 bool valid = SkParsePath::FromSVGString(gCCW[i], &path);
1019 REPORTER_ASSERT(reporter, valid);
reed026beb52015-06-10 14:23:15 -07001020 check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection);
reed@google.com3e71a882012-01-10 18:44:37 +00001021 }
reed@google.comac8543f2012-01-30 20:51:25 +00001022
1023 // Test two donuts, each wound a different direction. Only the outer contour
1024 // determines the cheap direction
1025 path.reset();
1026 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCW_Direction);
1027 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCCW_Direction);
reed026beb52015-06-10 14:23:15 -07001028 check_direction(reporter, path, SkPathPriv::kCW_FirstDirection);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +00001029
reed@google.comac8543f2012-01-30 20:51:25 +00001030 path.reset();
1031 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCW_Direction);
1032 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction);
reed026beb52015-06-10 14:23:15 -07001033 check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +00001034
1035 // triangle with one point really far from the origin.
1036 path.reset();
1037 // the first point is roughly 1.05e10, 1.05e10
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001038 path.moveTo(SkBits2Float(0x501c7652), SkBits2Float(0x501c7652));
bsalomon@google.com53aab782012-02-23 14:54:49 +00001039 path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1);
1040 path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1);
reed026beb52015-06-10 14:23:15 -07001041 check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001042
1043 path.reset();
1044 path.conicTo(20, 0, 20, 20, 0.5f);
1045 path.close();
reed026beb52015-06-10 14:23:15 -07001046 check_direction(reporter, path, SkPathPriv::kCW_FirstDirection);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001047
1048 path.reset();
1049 path.lineTo(1, 1e7f);
1050 path.lineTo(1e7f, 2e7f);
1051 path.close();
1052 REPORTER_ASSERT(reporter, SkPath::kConvex_Convexity == path.getConvexity());
reed026beb52015-06-10 14:23:15 -07001053 check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection);
reed@google.com3e71a882012-01-10 18:44:37 +00001054}
1055
reed@google.comffdb0182011-11-14 19:29:14 +00001056static void add_rect(SkPath* path, const SkRect& r) {
1057 path->moveTo(r.fLeft, r.fTop);
1058 path->lineTo(r.fRight, r.fTop);
1059 path->lineTo(r.fRight, r.fBottom);
1060 path->lineTo(r.fLeft, r.fBottom);
1061 path->close();
1062}
1063
1064static void test_bounds(skiatest::Reporter* reporter) {
1065 static const SkRect rects[] = {
reed@google.com3563c9e2011-11-14 19:34:57 +00001066 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) },
1067 { SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) },
1068 { SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) },
1069 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) },
reed@google.comffdb0182011-11-14 19:29:14 +00001070 };
1071
1072 SkPath path0, path1;
1073 for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) {
1074 path0.addRect(rects[i]);
1075 add_rect(&path1, rects[i]);
1076 }
1077
1078 REPORTER_ASSERT(reporter, path0.getBounds() == path1.getBounds());
1079}
1080
reed@google.com55b5f4b2011-09-07 12:23:41 +00001081static void stroke_cubic(const SkPoint pts[4]) {
1082 SkPath path;
1083 path.moveTo(pts[0]);
1084 path.cubicTo(pts[1], pts[2], pts[3]);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001085
reed@google.com55b5f4b2011-09-07 12:23:41 +00001086 SkPaint paint;
1087 paint.setStyle(SkPaint::kStroke_Style);
1088 paint.setStrokeWidth(SK_Scalar1 * 2);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001089
reed@google.com55b5f4b2011-09-07 12:23:41 +00001090 SkPath fill;
1091 paint.getFillPath(path, &fill);
1092}
1093
1094// just ensure this can run w/o any SkASSERTS firing in the debug build
1095// we used to assert due to differences in how we determine a degenerate vector
1096// but that was fixed with the introduction of SkPoint::CanNormalize
1097static void stroke_tiny_cubic() {
1098 SkPoint p0[] = {
1099 { 372.0f, 92.0f },
1100 { 372.0f, 92.0f },
1101 { 372.0f, 92.0f },
1102 { 372.0f, 92.0f },
1103 };
rmistry@google.comd6176b02012-08-23 18:14:13 +00001104
reed@google.com55b5f4b2011-09-07 12:23:41 +00001105 stroke_cubic(p0);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001106
reed@google.com55b5f4b2011-09-07 12:23:41 +00001107 SkPoint p1[] = {
1108 { 372.0f, 92.0f },
1109 { 372.0007f, 92.000755f },
1110 { 371.99927f, 92.003922f },
1111 { 371.99826f, 92.003899f },
1112 };
rmistry@google.comd6176b02012-08-23 18:14:13 +00001113
reed@google.com55b5f4b2011-09-07 12:23:41 +00001114 stroke_cubic(p1);
1115}
1116
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001117static void check_close(skiatest::Reporter* reporter, const SkPath& path) {
1118 for (int i = 0; i < 2; ++i) {
robertphillips@google.com09042b82012-04-06 20:01:46 +00001119 SkPath::Iter iter(path, SkToBool(i));
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001120 SkPoint mv;
1121 SkPoint pts[4];
1122 SkPath::Verb v;
1123 int nMT = 0;
1124 int nCL = 0;
tomhudson@google.com221db3c2011-07-28 21:10:29 +00001125 mv.set(0, 0);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001126 while (SkPath::kDone_Verb != (v = iter.next(pts))) {
1127 switch (v) {
1128 case SkPath::kMove_Verb:
1129 mv = pts[0];
1130 ++nMT;
1131 break;
1132 case SkPath::kClose_Verb:
1133 REPORTER_ASSERT(reporter, mv == pts[0]);
1134 ++nCL;
1135 break;
1136 default:
1137 break;
1138 }
1139 }
1140 // if we force a close on the interator we should have a close
1141 // for every moveTo
1142 REPORTER_ASSERT(reporter, !i || nMT == nCL);
1143 }
1144}
1145
1146static void test_close(skiatest::Reporter* reporter) {
1147 SkPath closePt;
1148 closePt.moveTo(0, 0);
1149 closePt.close();
1150 check_close(reporter, closePt);
1151
1152 SkPath openPt;
1153 openPt.moveTo(0, 0);
1154 check_close(reporter, openPt);
1155
1156 SkPath empty;
1157 check_close(reporter, empty);
1158 empty.close();
1159 check_close(reporter, empty);
1160
1161 SkPath rect;
1162 rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1163 check_close(reporter, rect);
1164 rect.close();
1165 check_close(reporter, rect);
1166
1167 SkPath quad;
1168 quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1169 check_close(reporter, quad);
1170 quad.close();
1171 check_close(reporter, quad);
1172
1173 SkPath cubic;
rmistry@google.comd6176b02012-08-23 18:14:13 +00001174 quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1,
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001175 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1);
1176 check_close(reporter, cubic);
1177 cubic.close();
1178 check_close(reporter, cubic);
1179
1180 SkPath line;
1181 line.moveTo(SK_Scalar1, SK_Scalar1);
1182 line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1);
1183 check_close(reporter, line);
1184 line.close();
1185 check_close(reporter, line);
1186
1187 SkPath rect2;
1188 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1189 rect2.close();
1190 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1191 check_close(reporter, rect2);
1192 rect2.close();
1193 check_close(reporter, rect2);
1194
1195 SkPath oval3;
1196 oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100));
1197 oval3.close();
1198 oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200));
1199 check_close(reporter, oval3);
1200 oval3.close();
1201 check_close(reporter, oval3);
1202
1203 SkPath moves;
1204 moves.moveTo(SK_Scalar1, SK_Scalar1);
1205 moves.moveTo(5 * SK_Scalar1, SK_Scalar1);
1206 moves.moveTo(SK_Scalar1, 10 * SK_Scalar1);
1207 moves.moveTo(10 *SK_Scalar1, SK_Scalar1);
1208 check_close(reporter, moves);
reed@google.com55b5f4b2011-09-07 12:23:41 +00001209
1210 stroke_tiny_cubic();
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001211}
1212
reed@google.com7c424812011-05-15 04:38:34 +00001213static void check_convexity(skiatest::Reporter* reporter, const SkPath& path,
1214 SkPath::Convexity expected) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001215 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
1216 SkPath::Convexity c = copy.getConvexity();
reed@google.com7c424812011-05-15 04:38:34 +00001217 REPORTER_ASSERT(reporter, c == expected);
1218}
1219
caryclarkb4216502015-03-02 13:02:34 -08001220static void test_path_crbug389050(skiatest::Reporter* reporter) {
1221 SkPath tinyConvexPolygon;
1222 tinyConvexPolygon.moveTo(600.131559f, 800.112512f);
1223 tinyConvexPolygon.lineTo(600.161735f, 800.118627f);
1224 tinyConvexPolygon.lineTo(600.148962f, 800.142338f);
1225 tinyConvexPolygon.lineTo(600.134891f, 800.137724f);
1226 tinyConvexPolygon.close();
1227 tinyConvexPolygon.getConvexity();
1228 check_convexity(reporter, tinyConvexPolygon, SkPath::kConvex_Convexity);
reed026beb52015-06-10 14:23:15 -07001229 check_direction(reporter, tinyConvexPolygon, SkPathPriv::kCW_FirstDirection);
caryclarkb4216502015-03-02 13:02:34 -08001230
1231 SkPath platTriangle;
1232 platTriangle.moveTo(0, 0);
1233 platTriangle.lineTo(200, 0);
1234 platTriangle.lineTo(100, 0.04f);
1235 platTriangle.close();
1236 platTriangle.getConvexity();
reed026beb52015-06-10 14:23:15 -07001237 check_direction(reporter, platTriangle, SkPathPriv::kCW_FirstDirection);
caryclarkb4216502015-03-02 13:02:34 -08001238
1239 platTriangle.reset();
1240 platTriangle.moveTo(0, 0);
1241 platTriangle.lineTo(200, 0);
1242 platTriangle.lineTo(100, 0.03f);
1243 platTriangle.close();
1244 platTriangle.getConvexity();
reed026beb52015-06-10 14:23:15 -07001245 check_direction(reporter, platTriangle, SkPathPriv::kCW_FirstDirection);
caryclarkb4216502015-03-02 13:02:34 -08001246}
1247
reed@google.com7c424812011-05-15 04:38:34 +00001248static void test_convexity2(skiatest::Reporter* reporter) {
1249 SkPath pt;
1250 pt.moveTo(0, 0);
1251 pt.close();
reed@google.comb54455e2011-05-16 14:16:04 +00001252 check_convexity(reporter, pt, SkPath::kConvex_Convexity);
reed026beb52015-06-10 14:23:15 -07001253 check_direction(reporter, pt, SkPathPriv::kUnknown_FirstDirection);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001254
reed@google.com7c424812011-05-15 04:38:34 +00001255 SkPath line;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001256 line.moveTo(12*SK_Scalar1, 20*SK_Scalar1);
1257 line.lineTo(-12*SK_Scalar1, -20*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001258 line.close();
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001259 check_convexity(reporter, line, SkPath::kConvex_Convexity);
reed026beb52015-06-10 14:23:15 -07001260 check_direction(reporter, line, SkPathPriv::kUnknown_FirstDirection);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001261
reed@google.com7c424812011-05-15 04:38:34 +00001262 SkPath triLeft;
1263 triLeft.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001264 triLeft.lineTo(SK_Scalar1, 0);
1265 triLeft.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001266 triLeft.close();
1267 check_convexity(reporter, triLeft, SkPath::kConvex_Convexity);
reed026beb52015-06-10 14:23:15 -07001268 check_direction(reporter, triLeft, SkPathPriv::kCW_FirstDirection);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001269
reed@google.com7c424812011-05-15 04:38:34 +00001270 SkPath triRight;
1271 triRight.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001272 triRight.lineTo(-SK_Scalar1, 0);
1273 triRight.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001274 triRight.close();
1275 check_convexity(reporter, triRight, SkPath::kConvex_Convexity);
reed026beb52015-06-10 14:23:15 -07001276 check_direction(reporter, triRight, SkPathPriv::kCCW_FirstDirection);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001277
reed@google.com7c424812011-05-15 04:38:34 +00001278 SkPath square;
1279 square.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001280 square.lineTo(SK_Scalar1, 0);
1281 square.lineTo(SK_Scalar1, SK_Scalar1);
1282 square.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001283 square.close();
1284 check_convexity(reporter, square, SkPath::kConvex_Convexity);
reed026beb52015-06-10 14:23:15 -07001285 check_direction(reporter, square, SkPathPriv::kCW_FirstDirection);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001286
reed@google.com7c424812011-05-15 04:38:34 +00001287 SkPath redundantSquare;
1288 redundantSquare.moveTo(0, 0);
1289 redundantSquare.lineTo(0, 0);
1290 redundantSquare.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001291 redundantSquare.lineTo(SK_Scalar1, 0);
1292 redundantSquare.lineTo(SK_Scalar1, 0);
1293 redundantSquare.lineTo(SK_Scalar1, 0);
1294 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1295 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1296 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1297 redundantSquare.lineTo(0, SK_Scalar1);
1298 redundantSquare.lineTo(0, SK_Scalar1);
1299 redundantSquare.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001300 redundantSquare.close();
1301 check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity);
reed026beb52015-06-10 14:23:15 -07001302 check_direction(reporter, redundantSquare, SkPathPriv::kCW_FirstDirection);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001303
reed@google.com7c424812011-05-15 04:38:34 +00001304 SkPath bowTie;
1305 bowTie.moveTo(0, 0);
1306 bowTie.lineTo(0, 0);
1307 bowTie.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001308 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1309 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1310 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1311 bowTie.lineTo(SK_Scalar1, 0);
1312 bowTie.lineTo(SK_Scalar1, 0);
1313 bowTie.lineTo(SK_Scalar1, 0);
1314 bowTie.lineTo(0, SK_Scalar1);
1315 bowTie.lineTo(0, SK_Scalar1);
1316 bowTie.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001317 bowTie.close();
1318 check_convexity(reporter, bowTie, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001319 check_direction(reporter, bowTie, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001320
reed@google.com7c424812011-05-15 04:38:34 +00001321 SkPath spiral;
1322 spiral.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001323 spiral.lineTo(100*SK_Scalar1, 0);
1324 spiral.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1325 spiral.lineTo(0, 100*SK_Scalar1);
1326 spiral.lineTo(0, 50*SK_Scalar1);
1327 spiral.lineTo(50*SK_Scalar1, 50*SK_Scalar1);
1328 spiral.lineTo(50*SK_Scalar1, 75*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001329 spiral.close();
reed@google.com85b6e392011-05-15 20:25:17 +00001330 check_convexity(reporter, spiral, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001331 check_direction(reporter, spiral, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001332
reed@google.com7c424812011-05-15 04:38:34 +00001333 SkPath dent;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001334 dent.moveTo(0, 0);
1335 dent.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1336 dent.lineTo(0, 100*SK_Scalar1);
1337 dent.lineTo(-50*SK_Scalar1, 200*SK_Scalar1);
1338 dent.lineTo(-200*SK_Scalar1, 100*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001339 dent.close();
1340 check_convexity(reporter, dent, SkPath::kConcave_Convexity);
reed026beb52015-06-10 14:23:15 -07001341 check_direction(reporter, dent, SkPathPriv::kCW_FirstDirection);
commit-bot@chromium.org8be07bb2014-05-22 14:58:53 +00001342
halcanary6950de62015-11-07 05:29:00 -08001343 // https://bug.skia.org/2235
commit-bot@chromium.org8be07bb2014-05-22 14:58:53 +00001344 SkPath strokedSin;
1345 for (int i = 0; i < 2000; i++) {
1346 SkScalar x = SkIntToScalar(i) / 2;
1347 SkScalar y = 500 - (x + SkScalarSin(x / 100) * 40) / 3;
1348 if (0 == i) {
1349 strokedSin.moveTo(x, y);
1350 } else {
1351 strokedSin.lineTo(x, y);
1352 }
1353 }
1354 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
1355 stroke.setStrokeStyle(2 * SK_Scalar1);
1356 stroke.applyToPath(&strokedSin, strokedSin);
1357 check_convexity(reporter, strokedSin, SkPath::kConcave_Convexity);
1358 check_direction(reporter, strokedSin, kDontCheckDir);
robertphillipsc506e302014-09-16 09:43:31 -07001359
1360 // http://crbug.com/412640
1361 SkPath degenerateConcave;
1362 degenerateConcave.moveTo(148.67912f, 191.875f);
1363 degenerateConcave.lineTo(470.37695f, 7.5f);
1364 degenerateConcave.lineTo(148.67912f, 191.875f);
1365 degenerateConcave.lineTo(41.446522f, 376.25f);
1366 degenerateConcave.lineTo(-55.971577f, 460.0f);
1367 degenerateConcave.lineTo(41.446522f, 376.25f);
1368 check_convexity(reporter, degenerateConcave, SkPath::kConcave_Convexity);
reed026beb52015-06-10 14:23:15 -07001369 check_direction(reporter, degenerateConcave, SkPathPriv::kUnknown_FirstDirection);
robertphillipsf52a0632014-11-17 12:11:42 -08001370
1371 // http://crbug.com/433683
1372 SkPath badFirstVector;
1373 badFirstVector.moveTo(501.087708f, 319.610352f);
1374 badFirstVector.lineTo(501.087708f, 319.610352f);
1375 badFirstVector.cubicTo(501.087677f, 319.610321f, 449.271606f, 258.078674f, 395.084564f, 198.711182f);
1376 badFirstVector.cubicTo(358.967072f, 159.140717f, 321.910553f, 120.650436f, 298.442322f, 101.955399f);
1377 badFirstVector.lineTo(301.557678f, 98.044601f);
1378 badFirstVector.cubicTo(325.283844f, 116.945084f, 362.615204f, 155.720825f, 398.777557f, 195.340454f);
1379 badFirstVector.cubicTo(453.031860f, 254.781662f, 504.912262f, 316.389618f, 504.912292f, 316.389648f);
1380 badFirstVector.lineTo(504.912292f, 316.389648f);
1381 badFirstVector.lineTo(501.087708f, 319.610352f);
1382 badFirstVector.close();
1383 check_convexity(reporter, badFirstVector, SkPath::kConcave_Convexity);
reed@google.com7c424812011-05-15 04:38:34 +00001384}
1385
reed@android.com6b82d1a2009-06-03 02:35:01 +00001386static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
1387 const SkRect& bounds) {
1388 REPORTER_ASSERT(reporter, p.isConvex());
1389 REPORTER_ASSERT(reporter, p.getBounds() == bounds);
reed@google.com62047cf2011-02-07 19:39:09 +00001390
reed@android.com6b82d1a2009-06-03 02:35:01 +00001391 SkPath p2(p);
1392 REPORTER_ASSERT(reporter, p2.isConvex());
1393 REPORTER_ASSERT(reporter, p2.getBounds() == bounds);
1394
1395 SkPath other;
1396 other.swap(p2);
1397 REPORTER_ASSERT(reporter, other.isConvex());
1398 REPORTER_ASSERT(reporter, other.getBounds() == bounds);
1399}
1400
reed@google.com04863fa2011-05-15 04:08:24 +00001401static void setFromString(SkPath* path, const char str[]) {
1402 bool first = true;
1403 while (str) {
1404 SkScalar x, y;
1405 str = SkParse::FindScalar(str, &x);
halcanary96fcdcc2015-08-27 07:41:13 -07001406 if (nullptr == str) {
reed@google.com04863fa2011-05-15 04:08:24 +00001407 break;
1408 }
1409 str = SkParse::FindScalar(str, &y);
1410 SkASSERT(str);
1411 if (first) {
1412 path->moveTo(x, y);
1413 first = false;
1414 } else {
1415 path->lineTo(x, y);
1416 }
1417 }
1418}
1419
1420static void test_convexity(skiatest::Reporter* reporter) {
reed@google.com04863fa2011-05-15 04:08:24 +00001421 SkPath path;
1422
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001423 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001424 path.addCircle(0, 0, SkIntToScalar(10));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001425 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001426 path.addCircle(0, 0, SkIntToScalar(10)); // 2nd circle
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001427 check_convexity(reporter, path, SkPath::kConcave_Convexity);
1428
reed@google.com04863fa2011-05-15 04:08:24 +00001429 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001430 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001431 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed026beb52015-06-10 14:23:15 -07001432 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCCW_FirstDirection));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001433
reed@google.com04863fa2011-05-15 04:08:24 +00001434 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001435 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001436 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed026beb52015-06-10 14:23:15 -07001437 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCW_FirstDirection));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001438
reed@google.com04863fa2011-05-15 04:08:24 +00001439 static const struct {
reed026beb52015-06-10 14:23:15 -07001440 const char* fPathStr;
1441 SkPath::Convexity fExpectedConvexity;
1442 SkPathPriv::FirstDirection fExpectedDirection;
reed@google.com04863fa2011-05-15 04:08:24 +00001443 } gRec[] = {
reed026beb52015-06-10 14:23:15 -07001444 { "", SkPath::kConvex_Convexity, SkPathPriv::kUnknown_FirstDirection },
1445 { "0 0", SkPath::kConvex_Convexity, SkPathPriv::kUnknown_FirstDirection },
1446 { "0 0 10 10", SkPath::kConvex_Convexity, SkPathPriv::kUnknown_FirstDirection },
1447 { "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity, SkPathPriv::kUnknown_FirstDirection },
1448 { "0 0 10 10 10 20", SkPath::kConvex_Convexity, SkPathPriv::kCW_FirstDirection },
1449 { "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPathPriv::kCCW_FirstDirection },
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001450 { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir },
reed026beb52015-06-10 14:23:15 -07001451 { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity, SkPathPriv::kCW_FirstDirection },
reed@google.com04863fa2011-05-15 04:08:24 +00001452 };
1453
1454 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1455 SkPath path;
1456 setFromString(&path, gRec[i].fPathStr);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001457 check_convexity(reporter, path, gRec[i].fExpectedConvexity);
1458 check_direction(reporter, path, gRec[i].fExpectedDirection);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001459 // check after setting the initial convex and direction
1460 if (kDontCheckDir != gRec[i].fExpectedDirection) {
1461 SkPath copy(path);
reed026beb52015-06-10 14:23:15 -07001462 SkPathPriv::FirstDirection dir;
1463 bool foundDir = SkPathPriv::CheapComputeFirstDirection(copy, &dir);
1464 REPORTER_ASSERT(reporter, (gRec[i].fExpectedDirection == SkPathPriv::kUnknown_FirstDirection)
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001465 ^ foundDir);
1466 REPORTER_ASSERT(reporter, !foundDir || gRec[i].fExpectedDirection == dir);
1467 check_convexity(reporter, copy, gRec[i].fExpectedConvexity);
1468 }
1469 REPORTER_ASSERT(reporter, gRec[i].fExpectedConvexity == path.getConvexity());
1470 check_direction(reporter, path, gRec[i].fExpectedDirection);
reed@google.com04863fa2011-05-15 04:08:24 +00001471 }
caryclarkd3d1a982014-12-08 04:57:38 -08001472
1473 static const SkPoint nonFinitePts[] = {
1474 { SK_ScalarInfinity, 0 },
1475 { 0, SK_ScalarInfinity },
1476 { SK_ScalarInfinity, SK_ScalarInfinity },
1477 { SK_ScalarNegativeInfinity, 0},
1478 { 0, SK_ScalarNegativeInfinity },
1479 { SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity },
1480 { SK_ScalarNegativeInfinity, SK_ScalarInfinity },
1481 { SK_ScalarInfinity, SK_ScalarNegativeInfinity },
1482 { SK_ScalarNaN, 0 },
1483 { 0, SK_ScalarNaN },
1484 { SK_ScalarNaN, SK_ScalarNaN },
1485 };
1486
1487 const size_t nonFinitePtsCount = sizeof(nonFinitePts) / sizeof(nonFinitePts[0]);
1488
1489 static const SkPoint finitePts[] = {
1490 { SK_ScalarMax, 0 },
1491 { 0, SK_ScalarMax },
1492 { SK_ScalarMax, SK_ScalarMax },
1493 { SK_ScalarMin, 0 },
1494 { 0, SK_ScalarMin },
1495 { SK_ScalarMin, SK_ScalarMin },
1496 };
1497
1498 const size_t finitePtsCount = sizeof(finitePts) / sizeof(finitePts[0]);
1499
1500 for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount); ++index) {
1501 int i = (int) (index % nonFinitePtsCount);
1502 int f = (int) (index % finitePtsCount);
1503 int g = (int) ((f + 1) % finitePtsCount);
1504 path.reset();
1505 switch (index % 13) {
1506 case 0: path.lineTo(nonFinitePts[i]); break;
1507 case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break;
1508 case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break;
1509 case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break;
1510 case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); break;
1511 case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); break;
1512 case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); break;
1513 case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f]); break;
1514 case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i]); break;
1515 case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i]); break;
1516 case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts[i]); break;
1517 case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]); break;
1518 case 12: path.moveTo(nonFinitePts[i]); break;
1519 }
1520 check_convexity(reporter, path, SkPath::kUnknown_Convexity);
1521 }
1522
1523 for (int index = 0; index < (int) (11 * finitePtsCount); ++index) {
1524 int f = (int) (index % finitePtsCount);
1525 int g = (int) ((f + 1) % finitePtsCount);
1526 path.reset();
1527 int curveSelect = index % 11;
1528 switch (curveSelect) {
1529 case 0: path.moveTo(finitePts[f]); break;
1530 case 1: path.lineTo(finitePts[f]); break;
1531 case 2: path.quadTo(finitePts[f], finitePts[f]); break;
1532 case 3: path.quadTo(finitePts[f], finitePts[g]); break;
1533 case 4: path.quadTo(finitePts[g], finitePts[f]); break;
1534 case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); break;
1535 case 6: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); break;
1536 case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); break;
1537 case 8: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); break;
1538 case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); break;
1539 case 10: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); break;
1540 }
1541 check_convexity(reporter, path, curveSelect == 0 ? SkPath::kConvex_Convexity
1542 : SkPath::kUnknown_Convexity);
1543 }
1544
reed@google.com04863fa2011-05-15 04:08:24 +00001545}
1546
reed@google.com7e6c4d12012-05-10 14:05:43 +00001547static void test_isLine(skiatest::Reporter* reporter) {
1548 SkPath path;
1549 SkPoint pts[2];
1550 const SkScalar value = SkIntToScalar(5);
1551
halcanary96fcdcc2015-08-27 07:41:13 -07001552 REPORTER_ASSERT(reporter, !path.isLine(nullptr));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001553
reed@google.com7e6c4d12012-05-10 14:05:43 +00001554 // set some non-zero values
1555 pts[0].set(value, value);
1556 pts[1].set(value, value);
1557 REPORTER_ASSERT(reporter, !path.isLine(pts));
1558 // check that pts was untouched
1559 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1560 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1561
1562 const SkScalar moveX = SkIntToScalar(1);
1563 const SkScalar moveY = SkIntToScalar(2);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001564 REPORTER_ASSERT(reporter, value != moveX && value != moveY);
reed@google.com7e6c4d12012-05-10 14:05:43 +00001565
1566 path.moveTo(moveX, moveY);
halcanary96fcdcc2015-08-27 07:41:13 -07001567 REPORTER_ASSERT(reporter, !path.isLine(nullptr));
reed@google.com7e6c4d12012-05-10 14:05:43 +00001568 REPORTER_ASSERT(reporter, !path.isLine(pts));
1569 // check that pts was untouched
1570 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1571 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1572
1573 const SkScalar lineX = SkIntToScalar(2);
1574 const SkScalar lineY = SkIntToScalar(2);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001575 REPORTER_ASSERT(reporter, value != lineX && value != lineY);
reed@google.com7e6c4d12012-05-10 14:05:43 +00001576
1577 path.lineTo(lineX, lineY);
halcanary96fcdcc2015-08-27 07:41:13 -07001578 REPORTER_ASSERT(reporter, path.isLine(nullptr));
reed@google.com7e6c4d12012-05-10 14:05:43 +00001579
1580 REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY));
1581 REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY));
1582 REPORTER_ASSERT(reporter, path.isLine(pts));
1583 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1584 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
1585
1586 path.lineTo(0, 0); // too many points/verbs
halcanary96fcdcc2015-08-27 07:41:13 -07001587 REPORTER_ASSERT(reporter, !path.isLine(nullptr));
reed@google.com7e6c4d12012-05-10 14:05:43 +00001588 REPORTER_ASSERT(reporter, !path.isLine(pts));
1589 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1590 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001591
1592 path.reset();
1593 path.quadTo(1, 1, 2, 2);
halcanary96fcdcc2015-08-27 07:41:13 -07001594 REPORTER_ASSERT(reporter, !path.isLine(nullptr));
reed@google.com7e6c4d12012-05-10 14:05:43 +00001595}
1596
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001597static void test_conservativelyContains(skiatest::Reporter* reporter) {
1598 SkPath path;
1599
1600 // kBaseRect is used to construct most our test paths: a rect, a circle, and a round-rect.
1601 static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
1602
1603 // A circle that bounds kBaseRect (with a significant amount of slop)
1604 SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height());
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001605 circleR = SkScalarMul(circleR, 1.75f) / 2;
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001606 static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()};
1607
1608 // round-rect radii
1609 static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)};
skia.committer@gmail.comcec8de62012-11-14 02:01:22 +00001610
caryclark@google.com56f233a2012-11-19 13:06:06 +00001611 static const struct SUPPRESS_VISIBILITY_WARNING {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001612 SkRect fQueryRect;
1613 bool fInRect;
1614 bool fInCircle;
1615 bool fInRR;
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001616 bool fInCubicRR;
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001617 } kQueries[] = {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001618 {kBaseRect, true, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001619
1620 // rect well inside of kBaseRect
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001621 {SkRect::MakeLTRB(kBaseRect.fLeft + 0.25f*kBaseRect.width(),
1622 kBaseRect.fTop + 0.25f*kBaseRect.height(),
1623 kBaseRect.fRight - 0.25f*kBaseRect.width(),
1624 kBaseRect.fBottom - 0.25f*kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001625 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001626
1627 // rects with edges off by one from kBaseRect's edges
1628 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1629 kBaseRect.width(), kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001630 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001631 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1632 kBaseRect.width() + 1, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001633 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001634 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1635 kBaseRect.width() + 1, kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001636 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001637 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1638 kBaseRect.width(), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001639 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001640 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1641 kBaseRect.width(), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001642 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001643 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1644 kBaseRect.width() + 2, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001645 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001646 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1647 kBaseRect.width() + 2, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001648 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001649
1650 // zero-w/h rects at each corner of kBaseRect
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001651 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, false, false},
1652 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, false, true},
1653 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true, false, true},
1654 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true, false, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001655
1656 // far away rect
1657 {SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom,
1658 SkIntToScalar(10), SkIntToScalar(10)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001659 false, false, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001660
1661 // very large rect containing kBaseRect
1662 {SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(),
1663 kBaseRect.fTop - 5 * kBaseRect.height(),
1664 11 * kBaseRect.width(), 11 * kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001665 false, false, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001666
1667 // skinny rect that spans same y-range as kBaseRect
1668 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1669 SkIntToScalar(1), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001670 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001671
1672 // short rect that spans same x-range as kBaseRect
1673 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(), SkScalar(1)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001674 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001675
1676 // skinny rect that spans slightly larger y-range than kBaseRect
1677 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1678 SkIntToScalar(1), kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001679 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001680
1681 // short rect that spans slightly larger x-range than kBaseRect
1682 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(),
1683 kBaseRect.width() + 1, SkScalar(1)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001684 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001685 };
1686
1687 for (int inv = 0; inv < 4; ++inv) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001688 for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001689 SkRect qRect = kQueries[q].fQueryRect;
1690 if (inv & 0x1) {
1691 SkTSwap(qRect.fLeft, qRect.fRight);
1692 }
1693 if (inv & 0x2) {
1694 SkTSwap(qRect.fTop, qRect.fBottom);
1695 }
1696 for (int d = 0; d < 2; ++d) {
1697 SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
1698 path.reset();
1699 path.addRect(kBaseRect, dir);
1700 REPORTER_ASSERT(reporter, kQueries[q].fInRect ==
1701 path.conservativelyContainsRect(qRect));
1702
1703 path.reset();
1704 path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir);
1705 REPORTER_ASSERT(reporter, kQueries[q].fInCircle ==
1706 path.conservativelyContainsRect(qRect));
1707
1708 path.reset();
1709 path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir);
1710 REPORTER_ASSERT(reporter, kQueries[q].fInRR ==
1711 path.conservativelyContainsRect(qRect));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001712
1713 path.reset();
1714 path.moveTo(kBaseRect.fLeft + kRRRadii[0], kBaseRect.fTop);
1715 path.cubicTo(kBaseRect.fLeft + kRRRadii[0] / 2, kBaseRect.fTop,
1716 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1] / 2,
1717 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1]);
1718 path.lineTo(kBaseRect.fLeft, kBaseRect.fBottom);
1719 path.lineTo(kBaseRect.fRight, kBaseRect.fBottom);
1720 path.lineTo(kBaseRect.fRight, kBaseRect.fTop);
1721 path.close();
1722 REPORTER_ASSERT(reporter, kQueries[q].fInCubicRR ==
1723 path.conservativelyContainsRect(qRect));
1724
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001725 }
1726 // Slightly non-convex shape, shouldn't contain any rects.
1727 path.reset();
1728 path.moveTo(0, 0);
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001729 path.lineTo(SkIntToScalar(50), 0.05f);
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001730 path.lineTo(SkIntToScalar(100), 0);
1731 path.lineTo(SkIntToScalar(100), SkIntToScalar(100));
1732 path.lineTo(0, SkIntToScalar(100));
1733 path.close();
1734 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect));
1735 }
1736 }
1737
1738 // make sure a minimal convex shape works, a right tri with edges along pos x and y axes.
1739 path.reset();
1740 path.moveTo(0, 0);
1741 path.lineTo(SkIntToScalar(100), 0);
1742 path.lineTo(0, SkIntToScalar(100));
1743
1744 // inside, on along top edge
1745 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1746 SkIntToScalar(10),
1747 SkIntToScalar(10))));
1748 // above
1749 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1750 SkRect::MakeXYWH(SkIntToScalar(50),
1751 SkIntToScalar(-10),
1752 SkIntToScalar(10),
1753 SkIntToScalar(10))));
1754 // to the left
1755 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(-10),
1756 SkIntToScalar(5),
1757 SkIntToScalar(5),
1758 SkIntToScalar(5))));
1759
1760 // outside the diagonal edge
1761 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(10),
1762 SkIntToScalar(200),
1763 SkIntToScalar(20),
1764 SkIntToScalar(5))));
commit-bot@chromium.org62df5262013-08-01 15:35:06 +00001765
bsalomonb17c1292014-08-28 14:04:55 -07001766
1767 // Test that multiple move commands do not cause asserts.
1768
1769 // At the time of writing, this would not modify cached convexity. This caused an assert while
halcanary6950de62015-11-07 05:29:00 -08001770 // checking conservative containment again. https://bug.skia.org/1460
bsalomonb17c1292014-08-28 14:04:55 -07001771 path.moveTo(SkIntToScalar(100), SkIntToScalar(100));
1772#if 0
1773 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1774 SkIntToScalar(10),
1775 SkIntToScalar(10))));
1776#endif
1777
1778 // Same as above path and first test but with an extra moveTo.
commit-bot@chromium.org62df5262013-08-01 15:35:06 +00001779 path.reset();
1780 path.moveTo(100, 100);
1781 path.moveTo(0, 0);
1782 path.lineTo(SkIntToScalar(100), 0);
1783 path.lineTo(0, SkIntToScalar(100));
1784
1785 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1786 SkIntToScalar(10),
1787 SkIntToScalar(10))));
1788
bsalomonb17c1292014-08-28 14:04:55 -07001789 // Test that multiple move commands do not cause asserts and that the function
1790 // is not confused by the multiple moves.
1791 path.reset();
1792 path.moveTo(0, 0);
1793 path.lineTo(SkIntToScalar(100), 0);
1794 path.lineTo(0, SkIntToScalar(100));
1795 path.moveTo(0, SkIntToScalar(200));
1796 path.lineTo(SkIntToScalar(100), SkIntToScalar(200));
1797 path.lineTo(0, SkIntToScalar(300));
1798
1799 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1800 SkRect::MakeXYWH(SkIntToScalar(50), 0,
1801 SkIntToScalar(10),
1802 SkIntToScalar(10))));
1803
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001804 path.reset();
1805 path.lineTo(100, 100);
1806 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(0, 0, 1, 1)));
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001807}
1808
reed@google.comf32322b2013-10-16 15:14:04 +00001809static void test_isRect_open_close(skiatest::Reporter* reporter) {
1810 SkPath path;
1811 bool isClosed;
1812
1813 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1);
reed@google.comf32322b2013-10-16 15:14:04 +00001814 path.close();
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00001815
halcanary96fcdcc2015-08-27 07:41:13 -07001816 REPORTER_ASSERT(reporter, path.isRect(nullptr, &isClosed, nullptr));
reed@google.comf32322b2013-10-16 15:14:04 +00001817 REPORTER_ASSERT(reporter, isClosed);
1818}
1819
caryclark@google.comf1316942011-07-26 19:54:45 +00001820// Simple isRect test is inline TestPath, below.
1821// test_isRect provides more extensive testing.
1822static void test_isRect(skiatest::Reporter* reporter) {
reed@google.comf32322b2013-10-16 15:14:04 +00001823 test_isRect_open_close(reporter);
1824
caryclark@google.comf1316942011-07-26 19:54:45 +00001825 // passing tests (all moveTo / lineTo...
1826 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1827 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}};
1830 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
1831 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}};
1836 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 +00001837 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}};
1838 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
1839 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}};
caryclark@google.combfe90372012-11-21 13:56:20 +00001840 SkPoint rf[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}};
rmistry@google.comd6176b02012-08-23 18:14:13 +00001841
caryclark@google.comf1316942011-07-26 19:54:45 +00001842 // failing tests
1843 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1844 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1845 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1846 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1847 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1848 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1849 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1850 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
caryclark@google.combfe90372012-11-21 13:56:20 +00001851 SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps
1852 SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non colinear gap
1853 SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short
rmistry@google.comd6176b02012-08-23 18:14:13 +00001854
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00001855 // no close, but we should detect them as fillably the same as a rect
1856 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1857 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}};
1858 SkPoint c3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 0}}; // hit the start
1859
1860 // like c2, but we double-back on ourselves
1861 SkPoint d1[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 2}};
1862 // like c2, but we overshoot the start point
1863 SkPoint d2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}};
1864 SkPoint d3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}, {0, 0}};
caryclark@google.comf1316942011-07-26 19:54:45 +00001865
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001866 struct IsRectTest {
1867 SkPoint *fPoints;
bsalomon98806072014-12-12 15:11:17 -08001868 int fPointCount;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001869 bool fClose;
1870 bool fIsRect;
1871 } tests[] = {
1872 { r1, SK_ARRAY_COUNT(r1), true, true },
1873 { r2, SK_ARRAY_COUNT(r2), true, true },
1874 { r3, SK_ARRAY_COUNT(r3), true, true },
1875 { r4, SK_ARRAY_COUNT(r4), true, true },
1876 { r5, SK_ARRAY_COUNT(r5), true, true },
1877 { r6, SK_ARRAY_COUNT(r6), true, true },
1878 { r7, SK_ARRAY_COUNT(r7), true, true },
1879 { r8, SK_ARRAY_COUNT(r8), true, true },
1880 { r9, SK_ARRAY_COUNT(r9), true, true },
1881 { ra, SK_ARRAY_COUNT(ra), true, true },
1882 { rb, SK_ARRAY_COUNT(rb), true, true },
1883 { rc, SK_ARRAY_COUNT(rc), true, true },
1884 { rd, SK_ARRAY_COUNT(rd), true, true },
1885 { re, SK_ARRAY_COUNT(re), true, true },
1886 { rf, SK_ARRAY_COUNT(rf), true, true },
1887
1888 { f1, SK_ARRAY_COUNT(f1), true, false },
1889 { f2, SK_ARRAY_COUNT(f2), true, false },
1890 { f3, SK_ARRAY_COUNT(f3), true, false },
1891 { f4, SK_ARRAY_COUNT(f4), true, false },
1892 { f5, SK_ARRAY_COUNT(f5), true, false },
1893 { f6, SK_ARRAY_COUNT(f6), true, false },
1894 { f7, SK_ARRAY_COUNT(f7), true, false },
1895 { f8, SK_ARRAY_COUNT(f8), true, false },
1896 { f9, SK_ARRAY_COUNT(f9), true, false },
1897 { fa, SK_ARRAY_COUNT(fa), true, false },
1898 { fb, SK_ARRAY_COUNT(fb), true, false },
1899
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00001900 { c1, SK_ARRAY_COUNT(c1), false, true },
1901 { c2, SK_ARRAY_COUNT(c2), false, true },
1902 { c3, SK_ARRAY_COUNT(c3), false, true },
1903
1904 { d1, SK_ARRAY_COUNT(d1), false, false },
1905 { d2, SK_ARRAY_COUNT(d2), false, false },
1906 { d3, SK_ARRAY_COUNT(d3), false, false },
caryclark@google.comf1316942011-07-26 19:54:45 +00001907 };
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001908
1909 const size_t testCount = SK_ARRAY_COUNT(tests);
bsalomon98806072014-12-12 15:11:17 -08001910 int index;
caryclark@google.comf1316942011-07-26 19:54:45 +00001911 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1912 SkPath path;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001913 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1914 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1915 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.comf1316942011-07-26 19:54:45 +00001916 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001917 if (tests[testIndex].fClose) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001918 path.close();
1919 }
halcanary96fcdcc2015-08-27 07:41:13 -07001920 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(nullptr));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001921
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001922 if (tests[testIndex].fIsRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001923 SkRect computed, expected;
caryclark@google.comf68154a2012-11-21 15:18:06 +00001924 bool isClosed;
reed026beb52015-06-10 14:23:15 -07001925 SkPath::Direction direction;
1926 SkPathPriv::FirstDirection cheapDirection;
robertphillips91b0a352015-01-05 10:13:46 -08001927 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
reed026beb52015-06-10 14:23:15 -07001928 REPORTER_ASSERT(reporter, SkPathPriv::CheapComputeFirstDirection(path, &cheapDirection));
robertphillips91b0a352015-01-05 10:13:46 -08001929 REPORTER_ASSERT(reporter, path.isRect(&computed, &isClosed, &direction));
1930 REPORTER_ASSERT(reporter, expected == computed);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001931 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose);
reed026beb52015-06-10 14:23:15 -07001932 REPORTER_ASSERT(reporter, SkPathPriv::AsFirstDirection(direction) == cheapDirection);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001933 } else {
1934 SkRect computed;
1935 computed.set(123, 456, 789, 1011);
robertphillips91b0a352015-01-05 10:13:46 -08001936 bool isClosed = (bool)-1;
1937 SkPath::Direction direction = (SkPath::Direction) - 1;
1938 REPORTER_ASSERT(reporter, !path.isRect(&computed, &isClosed, &direction));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001939 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456);
1940 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001941 REPORTER_ASSERT(reporter, isClosed == (bool) -1);
1942 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001943 }
caryclark@google.comf1316942011-07-26 19:54:45 +00001944 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00001945
caryclark@google.comf1316942011-07-26 19:54:45 +00001946 // fail, close then line
1947 SkPath path1;
1948 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001949 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001950 path1.lineTo(r1[index].fX, r1[index].fY);
1951 }
1952 path1.close();
1953 path1.lineTo(1, 0);
halcanary96fcdcc2015-08-27 07:41:13 -07001954 REPORTER_ASSERT(reporter, !path1.isRect(nullptr));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001955
caryclark@google.comf1316942011-07-26 19:54:45 +00001956 // fail, move in the middle
1957 path1.reset();
1958 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001959 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001960 if (index == 2) {
1961 path1.moveTo(1, .5f);
1962 }
1963 path1.lineTo(r1[index].fX, r1[index].fY);
1964 }
1965 path1.close();
halcanary96fcdcc2015-08-27 07:41:13 -07001966 REPORTER_ASSERT(reporter, !path1.isRect(nullptr));
caryclark@google.comf1316942011-07-26 19:54:45 +00001967
1968 // fail, move on the edge
1969 path1.reset();
bsalomon98806072014-12-12 15:11:17 -08001970 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001971 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1972 path1.lineTo(r1[index].fX, r1[index].fY);
1973 }
1974 path1.close();
halcanary96fcdcc2015-08-27 07:41:13 -07001975 REPORTER_ASSERT(reporter, !path1.isRect(nullptr));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001976
caryclark@google.comf1316942011-07-26 19:54:45 +00001977 // fail, quad
1978 path1.reset();
1979 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001980 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001981 if (index == 2) {
1982 path1.quadTo(1, .5f, 1, .5f);
1983 }
1984 path1.lineTo(r1[index].fX, r1[index].fY);
1985 }
1986 path1.close();
halcanary96fcdcc2015-08-27 07:41:13 -07001987 REPORTER_ASSERT(reporter, !path1.isRect(nullptr));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001988
caryclark@google.comf1316942011-07-26 19:54:45 +00001989 // fail, cubic
1990 path1.reset();
1991 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001992 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001993 if (index == 2) {
1994 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1995 }
1996 path1.lineTo(r1[index].fX, r1[index].fY);
1997 }
1998 path1.close();
halcanary96fcdcc2015-08-27 07:41:13 -07001999 REPORTER_ASSERT(reporter, !path1.isRect(nullptr));
caryclark@google.comf1316942011-07-26 19:54:45 +00002000}
2001
bsalomonedc743a2016-06-01 09:42:31 -07002002static void check_simple_closed_rect(skiatest::Reporter* reporter, const SkPath& path,
2003 const SkRect& rect, SkPath::Direction dir, unsigned start) {
2004 SkRect r = SkRect::MakeEmpty();
2005 SkPath::Direction d = SkPath::kCCW_Direction;
2006 unsigned s = ~0U;
2007
2008 REPORTER_ASSERT(reporter, SkPathPriv::IsSimpleClosedRect(path, &r, &d, &s));
2009 REPORTER_ASSERT(reporter, r == rect);
2010 REPORTER_ASSERT(reporter, d == dir);
2011 REPORTER_ASSERT(reporter, s == start);
2012}
2013
2014static void test_is_simple_closed_rect(skiatest::Reporter* reporter) {
2015 SkRect r = SkRect::MakeEmpty();
2016 SkPath::Direction d = SkPath::kCCW_Direction;
2017 unsigned s = ~0U;
2018
2019 const SkRect testRect = SkRect::MakeXYWH(10, 10, 50, 70);
2020 const SkRect emptyRect = SkRect::MakeEmpty();
2021 SkPath path;
2022 for (int start = 0; start < 4; ++start) {
2023 for (auto dir : {SkPath::kCCW_Direction, SkPath::kCW_Direction}) {
2024 SkPath path;
2025 path.addRect(testRect, dir, start);
2026 check_simple_closed_rect(reporter, path, testRect, dir, start);
2027 path.close();
2028 check_simple_closed_rect(reporter, path, testRect, dir, start);
2029 SkPath path2 = path;
2030 path2.lineTo(10, 10);
2031 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2032 path2 = path;
2033 path2.moveTo(10, 10);
2034 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2035 path2 = path;
2036 path2.addRect(testRect, dir, start);
2037 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2038 // Make the path by hand, manually closing it.
2039 path2.reset();
2040 SkPath::RawIter iter(path);
2041 SkPath::Verb v;
2042 SkPoint verbPts[4];
2043 SkPoint firstPt = {0.f, 0.f};
2044 while ((v = iter.next(verbPts)) != SkPath::kDone_Verb) {
2045 switch(v) {
2046 case SkPath::kMove_Verb:
2047 firstPt = verbPts[0];
2048 path2.moveTo(verbPts[0]);
2049 break;
2050 case SkPath::kLine_Verb:
2051 path2.lineTo(verbPts[1]);
2052 break;
2053 default:
2054 break;
2055 }
2056 }
2057 // We haven't closed it yet...
2058 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2059 // ... now we do and test again.
2060 path2.lineTo(firstPt);
2061 check_simple_closed_rect(reporter, path2, testRect, dir, start);
2062 // A redundant close shouldn't cause a failure.
2063 path2.close();
2064 check_simple_closed_rect(reporter, path2, testRect, dir, start);
2065 // Degenerate point and line rects are not allowed
2066 path2.reset();
2067 path2.addRect(emptyRect, dir, start);
2068 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2069 SkRect degenRect = testRect;
2070 degenRect.fLeft = degenRect.fRight;
2071 path2.reset();
2072 path2.addRect(degenRect, dir, start);
2073 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2074 degenRect = testRect;
2075 degenRect.fTop = degenRect.fBottom;
2076 path2.reset();
2077 path2.addRect(degenRect, dir, start);
2078 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2079 // An inverted rect makes a rect path, but changes the winding dir and start point.
2080 SkPath::Direction swapDir = (dir == SkPath::kCW_Direction)
2081 ? SkPath::kCCW_Direction
2082 : SkPath::kCW_Direction;
2083 static constexpr unsigned kXSwapStarts[] = { 1, 0, 3, 2 };
2084 static constexpr unsigned kYSwapStarts[] = { 3, 2, 1, 0 };
2085 SkRect swapRect = testRect;
2086 SkTSwap(swapRect.fLeft, swapRect.fRight);
2087 path2.reset();
2088 path2.addRect(swapRect, dir, start);
2089 check_simple_closed_rect(reporter, path2, testRect, swapDir, kXSwapStarts[start]);
2090 swapRect = testRect;
2091 SkTSwap(swapRect.fTop, swapRect.fBottom);
2092 path2.reset();
2093 path2.addRect(swapRect, dir, start);
2094 check_simple_closed_rect(reporter, path2, testRect, swapDir, kYSwapStarts[start]);
2095 }
2096 }
2097}
2098
caryclark95bc5f32015-04-08 08:34:15 -07002099static void test_isNestedFillRects(skiatest::Reporter* reporter) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002100 // passing tests (all moveTo / lineTo...
robertphillips@google.com83d1a682013-05-17 12:50:27 +00002101 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00002102 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
2103 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
2104 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
robertphillips@google.com83d1a682013-05-17 12:50:27 +00002105 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW
caryclark@google.com56f233a2012-11-19 13:06:06 +00002106 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
2107 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
2108 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
2109 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002110 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; // CCW
2111 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 +00002112 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW
2113 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW
2114 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00002115
2116 // failing tests
2117 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
2118 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
2119 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
2120 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
2121 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
2122 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
2123 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
2124 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
2125
caryclark95bc5f32015-04-08 08:34:15 -07002126 // success, no close is OK
caryclark@google.com56f233a2012-11-19 13:06:06 +00002127 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
2128 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
2129
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002130 struct IsNestedRectTest {
2131 SkPoint *fPoints;
bsalomon98806072014-12-12 15:11:17 -08002132 int fPointCount;
reed026beb52015-06-10 14:23:15 -07002133 SkPathPriv::FirstDirection fDirection;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002134 bool fClose;
2135 bool fIsNestedRect; // nests with path.addRect(-1, -1, 2, 2);
2136 } tests[] = {
reed026beb52015-06-10 14:23:15 -07002137 { r1, SK_ARRAY_COUNT(r1), SkPathPriv::kCW_FirstDirection , true, true },
2138 { r2, SK_ARRAY_COUNT(r2), SkPathPriv::kCW_FirstDirection , true, true },
2139 { r3, SK_ARRAY_COUNT(r3), SkPathPriv::kCW_FirstDirection , true, true },
2140 { r4, SK_ARRAY_COUNT(r4), SkPathPriv::kCW_FirstDirection , true, true },
2141 { r5, SK_ARRAY_COUNT(r5), SkPathPriv::kCCW_FirstDirection, true, true },
2142 { r6, SK_ARRAY_COUNT(r6), SkPathPriv::kCCW_FirstDirection, true, true },
2143 { r7, SK_ARRAY_COUNT(r7), SkPathPriv::kCCW_FirstDirection, true, true },
2144 { r8, SK_ARRAY_COUNT(r8), SkPathPriv::kCCW_FirstDirection, true, true },
2145 { r9, SK_ARRAY_COUNT(r9), SkPathPriv::kCCW_FirstDirection, true, true },
2146 { ra, SK_ARRAY_COUNT(ra), SkPathPriv::kCCW_FirstDirection, true, true },
2147 { rb, SK_ARRAY_COUNT(rb), SkPathPriv::kCW_FirstDirection, true, true },
2148 { rc, SK_ARRAY_COUNT(rc), SkPathPriv::kCW_FirstDirection, true, true },
2149 { rd, SK_ARRAY_COUNT(rd), SkPathPriv::kCCW_FirstDirection, true, true },
2150 { re, SK_ARRAY_COUNT(re), SkPathPriv::kCW_FirstDirection, true, true },
robertphillips@google.com83d1a682013-05-17 12:50:27 +00002151
reed026beb52015-06-10 14:23:15 -07002152 { f1, SK_ARRAY_COUNT(f1), SkPathPriv::kUnknown_FirstDirection, true, false },
2153 { f2, SK_ARRAY_COUNT(f2), SkPathPriv::kUnknown_FirstDirection, true, false },
2154 { f3, SK_ARRAY_COUNT(f3), SkPathPriv::kUnknown_FirstDirection, true, false },
2155 { f4, SK_ARRAY_COUNT(f4), SkPathPriv::kUnknown_FirstDirection, true, false },
2156 { f5, SK_ARRAY_COUNT(f5), SkPathPriv::kUnknown_FirstDirection, true, false },
2157 { f6, SK_ARRAY_COUNT(f6), SkPathPriv::kUnknown_FirstDirection, true, false },
2158 { f7, SK_ARRAY_COUNT(f7), SkPathPriv::kUnknown_FirstDirection, true, false },
2159 { f8, SK_ARRAY_COUNT(f8), SkPathPriv::kUnknown_FirstDirection, true, false },
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002160
reed026beb52015-06-10 14:23:15 -07002161 { c1, SK_ARRAY_COUNT(c1), SkPathPriv::kCW_FirstDirection, false, true },
2162 { c2, SK_ARRAY_COUNT(c2), SkPathPriv::kCW_FirstDirection, false, true },
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002163 };
2164
2165 const size_t testCount = SK_ARRAY_COUNT(tests);
bsalomon98806072014-12-12 15:11:17 -08002166 int index;
caryclark@google.com56f233a2012-11-19 13:06:06 +00002167 for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002168 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
2169 SkPath path;
2170 if (rectFirst) {
2171 path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2172 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002173 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
2174 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
2175 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.com56f233a2012-11-19 13:06:06 +00002176 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002177 if (tests[testIndex].fClose) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002178 path.close();
2179 }
2180 if (!rectFirst) {
2181 path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2182 }
caryclark95bc5f32015-04-08 08:34:15 -07002183 REPORTER_ASSERT(reporter,
halcanary96fcdcc2015-08-27 07:41:13 -07002184 tests[testIndex].fIsNestedRect == path.isNestedFillRects(nullptr));
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002185 if (tests[testIndex].fIsNestedRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002186 SkRect expected[2], computed[2];
reed026beb52015-06-10 14:23:15 -07002187 SkPathPriv::FirstDirection expectedDirs[2];
2188 SkPath::Direction computedDirs[2];
caryclark@google.com56f233a2012-11-19 13:06:06 +00002189 SkRect testBounds;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002190 testBounds.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.com56f233a2012-11-19 13:06:06 +00002191 expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2);
2192 expected[1] = testBounds;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00002193 if (rectFirst) {
reed026beb52015-06-10 14:23:15 -07002194 expectedDirs[0] = SkPathPriv::kCW_FirstDirection;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00002195 } else {
reed026beb52015-06-10 14:23:15 -07002196 expectedDirs[0] = SkPathPriv::kCCW_FirstDirection;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00002197 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002198 expectedDirs[1] = tests[testIndex].fDirection;
caryclark95bc5f32015-04-08 08:34:15 -07002199 REPORTER_ASSERT(reporter, path.isNestedFillRects(computed, computedDirs));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002200 REPORTER_ASSERT(reporter, expected[0] == computed[0]);
2201 REPORTER_ASSERT(reporter, expected[1] == computed[1]);
reed026beb52015-06-10 14:23:15 -07002202 REPORTER_ASSERT(reporter, expectedDirs[0] == SkPathPriv::AsFirstDirection(computedDirs[0]));
2203 REPORTER_ASSERT(reporter, expectedDirs[1] == SkPathPriv::AsFirstDirection(computedDirs[1]));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002204 }
caryclark@google.com56f233a2012-11-19 13:06:06 +00002205 }
2206
2207 // fail, close then line
2208 SkPath path1;
2209 if (rectFirst) {
2210 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2211 }
2212 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08002213 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002214 path1.lineTo(r1[index].fX, r1[index].fY);
2215 }
2216 path1.close();
2217 path1.lineTo(1, 0);
2218 if (!rectFirst) {
2219 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2220 }
halcanary96fcdcc2015-08-27 07:41:13 -07002221 REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002222
2223 // fail, move in the middle
2224 path1.reset();
2225 if (rectFirst) {
2226 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2227 }
2228 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08002229 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002230 if (index == 2) {
2231 path1.moveTo(1, .5f);
2232 }
2233 path1.lineTo(r1[index].fX, r1[index].fY);
2234 }
2235 path1.close();
2236 if (!rectFirst) {
2237 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2238 }
halcanary96fcdcc2015-08-27 07:41:13 -07002239 REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002240
2241 // fail, move on the edge
2242 path1.reset();
2243 if (rectFirst) {
2244 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2245 }
bsalomon98806072014-12-12 15:11:17 -08002246 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002247 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
2248 path1.lineTo(r1[index].fX, r1[index].fY);
2249 }
2250 path1.close();
2251 if (!rectFirst) {
2252 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2253 }
halcanary96fcdcc2015-08-27 07:41:13 -07002254 REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002255
2256 // fail, quad
2257 path1.reset();
2258 if (rectFirst) {
2259 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2260 }
2261 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08002262 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002263 if (index == 2) {
2264 path1.quadTo(1, .5f, 1, .5f);
2265 }
2266 path1.lineTo(r1[index].fX, r1[index].fY);
2267 }
2268 path1.close();
2269 if (!rectFirst) {
2270 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2271 }
halcanary96fcdcc2015-08-27 07:41:13 -07002272 REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002273
2274 // fail, cubic
2275 path1.reset();
2276 if (rectFirst) {
2277 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2278 }
2279 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08002280 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002281 if (index == 2) {
2282 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
2283 }
2284 path1.lineTo(r1[index].fX, r1[index].fY);
2285 }
2286 path1.close();
2287 if (!rectFirst) {
2288 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2289 }
halcanary96fcdcc2015-08-27 07:41:13 -07002290 REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr));
skia.committer@gmail.com34587162012-11-20 02:01:23 +00002291
caryclark@google.com56f233a2012-11-19 13:06:06 +00002292 // fail, not nested
2293 path1.reset();
2294 path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction);
2295 path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction);
halcanary96fcdcc2015-08-27 07:41:13 -07002296 REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002297 }
caryclark@google.combfe90372012-11-21 13:56:20 +00002298
caryclark95bc5f32015-04-08 08:34:15 -07002299 // pass, constructed explicitly from manually closed rects specified as moves/lines.
2300 SkPath path;
2301 path.moveTo(0, 0);
2302 path.lineTo(10, 0);
2303 path.lineTo(10, 10);
2304 path.lineTo(0, 10);
2305 path.lineTo(0, 0);
2306 path.moveTo(1, 1);
2307 path.lineTo(9, 1);
2308 path.lineTo(9, 9);
2309 path.lineTo(1, 9);
2310 path.lineTo(1, 1);
halcanary96fcdcc2015-08-27 07:41:13 -07002311 REPORTER_ASSERT(reporter, path.isNestedFillRects(nullptr));
caryclark95bc5f32015-04-08 08:34:15 -07002312
caryclark@google.combfe90372012-11-21 13:56:20 +00002313 // pass, stroke rect
2314 SkPath src, dst;
2315 src.addRect(1, 1, 7, 7, SkPath::kCW_Direction);
2316 SkPaint strokePaint;
2317 strokePaint.setStyle(SkPaint::kStroke_Style);
2318 strokePaint.setStrokeWidth(2);
2319 strokePaint.getFillPath(src, &dst);
halcanary96fcdcc2015-08-27 07:41:13 -07002320 REPORTER_ASSERT(reporter, dst.isNestedFillRects(nullptr));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002321}
2322
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002323static void write_and_read_back(skiatest::Reporter* reporter,
2324 const SkPath& p) {
commit-bot@chromium.org19382422014-01-14 20:51:26 +00002325 SkWriter32 writer;
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002326 writer.writePath(p);
reed@google.com44699382013-10-31 17:28:30 +00002327 size_t size = writer.bytesWritten();
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002328 SkAutoMalloc storage(size);
2329 writer.flatten(storage.get());
2330 SkReader32 reader(storage.get(), size);
2331
2332 SkPath readBack;
2333 REPORTER_ASSERT(reporter, readBack != p);
2334 reader.readPath(&readBack);
2335 REPORTER_ASSERT(reporter, readBack == p);
2336
rmistry@google.comd6176b02012-08-23 18:14:13 +00002337 REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() ==
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002338 p.getConvexityOrUnknown());
2339
bsalomon78d58d12016-05-27 09:17:04 -07002340 SkRect oval0, oval1;
2341 SkPath::Direction dir0, dir1;
2342 unsigned start0, start1;
halcanary96fcdcc2015-08-27 07:41:13 -07002343 REPORTER_ASSERT(reporter, readBack.isOval(nullptr) == p.isOval(nullptr));
bsalomon78d58d12016-05-27 09:17:04 -07002344 if (p.isOval(&oval0, &dir0, &start0) && readBack.isOval(&oval1, &dir1, &start1)) {
2345 REPORTER_ASSERT(reporter, oval0 == oval1);
2346 REPORTER_ASSERT(reporter, dir0 == dir1);
2347 REPORTER_ASSERT(reporter, start0 == start1);
2348 }
2349 REPORTER_ASSERT(reporter, readBack.isRRect(nullptr) == p.isRRect(nullptr));
2350 SkRRect rrect0, rrect1;
2351 if (p.isRRect(&rrect0, &dir0, &start0) && readBack.isRRect(&rrect1, &dir1, &start1)) {
2352 REPORTER_ASSERT(reporter, rrect0 == rrect1);
2353 REPORTER_ASSERT(reporter, dir0 == dir1);
2354 REPORTER_ASSERT(reporter, start0 == start1);
2355 }
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002356 const SkRect& origBounds = p.getBounds();
2357 const SkRect& readBackBounds = readBack.getBounds();
2358
2359 REPORTER_ASSERT(reporter, origBounds == readBackBounds);
2360}
2361
reed@google.com53effc52011-09-21 19:05:12 +00002362static void test_flattening(skiatest::Reporter* reporter) {
2363 SkPath p;
2364
2365 static const SkPoint pts[] = {
2366 { 0, 0 },
2367 { SkIntToScalar(10), SkIntToScalar(10) },
2368 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 },
2369 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }
2370 };
2371 p.moveTo(pts[0]);
2372 p.lineTo(pts[1]);
2373 p.quadTo(pts[2], pts[3]);
2374 p.cubicTo(pts[4], pts[5], pts[6]);
2375
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002376 write_and_read_back(reporter, p);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002377
2378 // create a buffer that should be much larger than the path so we don't
2379 // kill our stack if writer goes too far.
2380 char buffer[1024];
halcanary96fcdcc2015-08-27 07:41:13 -07002381 size_t size1 = p.writeToMemory(nullptr);
commit-bot@chromium.org4faa8692013-11-05 15:46:56 +00002382 size_t size2 = p.writeToMemory(buffer);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002383 REPORTER_ASSERT(reporter, size1 == size2);
2384
2385 SkPath p2;
commit-bot@chromium.org4faa8692013-11-05 15:46:56 +00002386 size_t size3 = p2.readFromMemory(buffer, 1024);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002387 REPORTER_ASSERT(reporter, size1 == size3);
2388 REPORTER_ASSERT(reporter, p == p2);
2389
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002390 size3 = p2.readFromMemory(buffer, 0);
2391 REPORTER_ASSERT(reporter, !size3);
2392
2393 SkPath tooShort;
2394 size3 = tooShort.readFromMemory(buffer, size1 - 1);
2395 REPORTER_ASSERT(reporter, tooShort.isEmpty());
2396
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002397 char buffer2[1024];
2398 size3 = p2.writeToMemory(buffer2);
2399 REPORTER_ASSERT(reporter, size1 == size3);
2400 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002401
2402 // test persistence of the oval flag & convexity
2403 {
2404 SkPath oval;
2405 SkRect rect = SkRect::MakeWH(10, 10);
2406 oval.addOval(rect);
2407
2408 write_and_read_back(reporter, oval);
2409 }
reed@google.com53effc52011-09-21 19:05:12 +00002410}
2411
2412static void test_transform(skiatest::Reporter* reporter) {
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002413 SkPath p;
rmistry@google.comd6176b02012-08-23 18:14:13 +00002414
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002415#define CONIC_PERSPECTIVE_BUG_FIXED 0
reed@google.com53effc52011-09-21 19:05:12 +00002416 static const SkPoint pts[] = {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002417 { 0, 0 }, // move
2418 { SkIntToScalar(10), SkIntToScalar(10) }, // line
2419 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, // quad
2420 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }, // cubic
2421#if CONIC_PERSPECTIVE_BUG_FIXED
2422 { 0, 0 }, { SkIntToScalar(20), SkIntToScalar(10) }, // conic
2423#endif
reed@google.com53effc52011-09-21 19:05:12 +00002424 };
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002425 const int kPtCount = SK_ARRAY_COUNT(pts);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002426
reed@google.com53effc52011-09-21 19:05:12 +00002427 p.moveTo(pts[0]);
2428 p.lineTo(pts[1]);
2429 p.quadTo(pts[2], pts[3]);
2430 p.cubicTo(pts[4], pts[5], pts[6]);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002431#if CONIC_PERSPECTIVE_BUG_FIXED
2432 p.conicTo(pts[4], pts[5], 0.5f);
2433#endif
2434 p.close();
rmistry@google.comd6176b02012-08-23 18:14:13 +00002435
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002436 {
2437 SkMatrix matrix;
2438 matrix.reset();
2439 SkPath p1;
2440 p.transform(matrix, &p1);
2441 REPORTER_ASSERT(reporter, p == p1);
reed@google.com53effc52011-09-21 19:05:12 +00002442 }
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002443
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002444
2445 {
2446 SkMatrix matrix;
2447 matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3);
2448
2449 SkPath p1; // Leave p1 non-unique (i.e., the empty path)
2450
skia.committer@gmail.com6e515d62013-12-04 07:02:26 +00002451 p.transform(matrix, &p1);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002452 SkPoint pts1[kPtCount];
skia.committer@gmail.com6e515d62013-12-04 07:02:26 +00002453 int count = p1.getPoints(pts1, kPtCount);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002454 REPORTER_ASSERT(reporter, kPtCount == count);
2455 for (int i = 0; i < count; ++i) {
2456 SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3);
2457 REPORTER_ASSERT(reporter, newPt == pts1[i]);
2458 }
2459 }
2460
2461 {
2462 SkMatrix matrix;
2463 matrix.reset();
reed3f43f8a2015-01-20 19:58:36 -08002464 matrix.setPerspX(4);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002465
2466 SkPath p1;
2467 p1.moveTo(SkPoint::Make(0, 0));
2468
2469 p.transform(matrix, &p1);
2470 REPORTER_ASSERT(reporter, matrix.invert(&matrix));
halcanary96fcdcc2015-08-27 07:41:13 -07002471 p1.transform(matrix, nullptr);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002472 SkRect pBounds = p.getBounds();
2473 SkRect p1Bounds = p1.getBounds();
2474 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fLeft, p1Bounds.fLeft));
2475 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fTop, p1Bounds.fTop));
2476 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fRight, p1Bounds.fRight));
2477 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fBottom, p1Bounds.fBottom));
2478 }
2479
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002480 p.reset();
2481 p.addCircle(0, 0, 1, SkPath::kCW_Direction);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002482
2483 {
2484 SkMatrix matrix;
2485 matrix.reset();
2486 SkPath p1;
2487 p1.moveTo(SkPoint::Make(0, 0));
2488
2489 p.transform(matrix, &p1);
reed026beb52015-06-10 14:23:15 -07002490 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p1, SkPathPriv::kCW_FirstDirection));
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002491 }
2492
2493
2494 {
2495 SkMatrix matrix;
2496 matrix.reset();
2497 matrix.setScaleX(-1);
2498 SkPath p1;
2499 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
2500
2501 p.transform(matrix, &p1);
reed026beb52015-06-10 14:23:15 -07002502 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p1, SkPathPriv::kCCW_FirstDirection));
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002503 }
2504
2505 {
2506 SkMatrix matrix;
2507 matrix.setAll(1, 1, 0, 1, 1, 0, 0, 0, 1);
2508 SkPath p1;
2509 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
2510
2511 p.transform(matrix, &p1);
reed026beb52015-06-10 14:23:15 -07002512 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p1, SkPathPriv::kUnknown_FirstDirection));
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002513 }
reed@google.com53effc52011-09-21 19:05:12 +00002514}
2515
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002516static void test_zero_length_paths(skiatest::Reporter* reporter) {
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002517 SkPath p;
schenney@chromium.org7e963602012-06-13 17:05:43 +00002518 uint8_t verbs[32];
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002519
caryclark@google.com56f233a2012-11-19 13:06:06 +00002520 struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData {
schenney@chromium.org7e963602012-06-13 17:05:43 +00002521 const char* testPath;
2522 const size_t numResultPts;
2523 const SkRect resultBound;
2524 const SkPath::Verb* resultVerbs;
2525 const size_t numResultVerbs;
2526 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002527
schenney@chromium.org7e963602012-06-13 17:05:43 +00002528 static const SkPath::Verb resultVerbs1[] = { SkPath::kMove_Verb };
2529 static const SkPath::Verb resultVerbs2[] = { SkPath::kMove_Verb, SkPath::kMove_Verb };
2530 static const SkPath::Verb resultVerbs3[] = { SkPath::kMove_Verb, SkPath::kClose_Verb };
2531 static const SkPath::Verb resultVerbs4[] = { SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb };
2532 static const SkPath::Verb resultVerbs5[] = { SkPath::kMove_Verb, SkPath::kLine_Verb };
2533 static const SkPath::Verb resultVerbs6[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb };
2534 static const SkPath::Verb resultVerbs7[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb };
2535 static const SkPath::Verb resultVerbs8[] = {
2536 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb
2537 };
2538 static const SkPath::Verb resultVerbs9[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb };
2539 static const SkPath::Verb resultVerbs10[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb };
2540 static const SkPath::Verb resultVerbs11[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb };
2541 static const SkPath::Verb resultVerbs12[] = {
2542 SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb
2543 };
2544 static const SkPath::Verb resultVerbs13[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb };
2545 static const SkPath::Verb resultVerbs14[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb };
2546 static const SkPath::Verb resultVerbs15[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb };
2547 static const SkPath::Verb resultVerbs16[] = {
2548 SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb
2549 };
2550 static const struct zeroPathTestData gZeroLengthTests[] = {
reed91f283b2015-07-28 06:00:50 -07002551 { "M 1 1", 1, {1, 1, 1, 1}, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002552 { "M 1 1 M 2 1", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
reed91f283b2015-07-28 06:00:50 -07002553 { "M 1 1 z", 1, {1, 1, 1, 1}, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002554 { "M 1 1 z M 2 1 z", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
2555 { "M 1 1 L 1 1", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) },
2556 { "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) },
2557 { "M 1 1 L 1 1 z", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs7, SK_ARRAY_COUNT(resultVerbs7) },
2558 { "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) },
2559 { "M 1 1 Q 1 1 1 1", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs9, SK_ARRAY_COUNT(resultVerbs9) },
2560 { "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) },
2561 { "M 1 1 Q 1 1 1 1 z", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs11, SK_ARRAY_COUNT(resultVerbs11) },
2562 { "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) },
2563 { "M 1 1 C 1 1 1 1 1 1", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs13, SK_ARRAY_COUNT(resultVerbs13) },
2564 { "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 +00002565 SK_ARRAY_COUNT(resultVerbs14)
2566 },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002567 { "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) },
2568 { "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 +00002569 SK_ARRAY_COUNT(resultVerbs16)
2570 }
2571 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002572
schenney@chromium.org7e963602012-06-13 17:05:43 +00002573 for (size_t i = 0; i < SK_ARRAY_COUNT(gZeroLengthTests); ++i) {
2574 p.reset();
2575 bool valid = SkParsePath::FromSVGString(gZeroLengthTests[i].testPath, &p);
2576 REPORTER_ASSERT(reporter, valid);
2577 REPORTER_ASSERT(reporter, !p.isEmpty());
2578 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultPts == (size_t)p.countPoints());
2579 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultBound == p.getBounds());
2580 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultVerbs == (size_t)p.getVerbs(verbs, SK_ARRAY_COUNT(verbs)));
2581 for (size_t j = 0; j < gZeroLengthTests[i].numResultVerbs; ++j) {
2582 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultVerbs[j] == verbs[j]);
2583 }
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002584 }
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002585}
2586
2587struct SegmentInfo {
2588 SkPath fPath;
2589 int fPointCount;
2590};
2591
reed@google.com10296cc2011-09-21 12:29:05 +00002592#define kCurveSegmentMask (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask)
2593
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002594static void test_segment_masks(skiatest::Reporter* reporter) {
reed@google.comeef938c2012-08-01 20:01:49 +00002595 SkPath p, p2;
2596
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002597 p.moveTo(0, 0);
2598 p.quadTo(100, 100, 200, 200);
2599 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == p.getSegmentMasks());
2600 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00002601 p2 = p;
2602 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002603 p.cubicTo(100, 100, 200, 200, 300, 300);
2604 REPORTER_ASSERT(reporter, kCurveSegmentMask == p.getSegmentMasks());
2605 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00002606 p2 = p;
2607 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
2608
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002609 p.reset();
2610 p.moveTo(0, 0);
2611 p.cubicTo(100, 100, 200, 200, 300, 300);
2612 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == p.getSegmentMasks());
reed@google.comeef938c2012-08-01 20:01:49 +00002613 p2 = p;
2614 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
rmistry@google.comd6176b02012-08-23 18:14:13 +00002615
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002616 REPORTER_ASSERT(reporter, !p.isEmpty());
2617}
2618
2619static void test_iter(skiatest::Reporter* reporter) {
schenney@chromium.org7e963602012-06-13 17:05:43 +00002620 SkPath p;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002621 SkPoint pts[4];
2622
2623 // Test an iterator with no path
2624 SkPath::Iter noPathIter;
2625 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002626
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002627 // Test that setting an empty path works
2628 noPathIter.setPath(p, false);
2629 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002630
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002631 // Test that close path makes no difference for an empty path
2632 noPathIter.setPath(p, true);
2633 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002634
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002635 // Test an iterator with an initial empty path
2636 SkPath::Iter iter(p, false);
2637 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2638
2639 // Test that close path makes no difference
schenney@chromium.org7e963602012-06-13 17:05:43 +00002640 iter.setPath(p, true);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002641 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2642
rmistry@google.comd6176b02012-08-23 18:14:13 +00002643
schenney@chromium.org7e963602012-06-13 17:05:43 +00002644 struct iterTestData {
2645 const char* testPath;
2646 const bool forceClose;
2647 const bool consumeDegenerates;
2648 const size_t* numResultPtsPerVerb;
2649 const SkPoint* resultPts;
2650 const SkPath::Verb* resultVerbs;
2651 const size_t numResultVerbs;
2652 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002653
schenney@chromium.org7e963602012-06-13 17:05:43 +00002654 static const SkPath::Verb resultVerbs1[] = { SkPath::kDone_Verb };
2655 static const SkPath::Verb resultVerbs2[] = {
2656 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kDone_Verb
2657 };
2658 static const SkPath::Verb resultVerbs3[] = {
2659 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2660 };
2661 static const SkPath::Verb resultVerbs4[] = {
2662 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2663 };
2664 static const SkPath::Verb resultVerbs5[] = {
2665 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2666 };
2667 static const size_t resultPtsSizes1[] = { 0 };
schenney@chromium.orgfedd09b2012-06-13 18:29:20 +00002668 static const size_t resultPtsSizes2[] = { 1, 2, 2, 0 };
2669 static const size_t resultPtsSizes3[] = { 1, 2, 2, 2, 1, 0 };
2670 static const size_t resultPtsSizes4[] = { 1, 2, 1, 1, 0 };
2671 static const size_t resultPtsSizes5[] = { 1, 2, 1, 1, 1, 0 };
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002672 static const SkPoint* resultPts1 = 0;
schenney@chromium.org7e963602012-06-13 17:05:43 +00002673 static const SkPoint resultPts2[] = {
2674 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 }
2675 };
2676 static const SkPoint resultPts3[] = {
2677 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 },
2678 { 0, SK_Scalar1 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }
2679 };
2680 static const SkPoint resultPts4[] = {
2681 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
2682 };
2683 static const SkPoint resultPts5[] = {
2684 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
2685 };
2686 static const struct iterTestData gIterTests[] = {
2687 { "M 1 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002688 { "M 1 0 M 2 0 M 3 0 M 4 0 M 5 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2689 { "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 +00002690 { "z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2691 { "z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2692 { "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) },
2693 { "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 +00002694 { "M 1 0 L 1 1 L 0 1 M 0 0 z", false, true, resultPtsSizes2, resultPts2, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
2695 { "M 1 0 L 1 1 L 0 1 M 0 0 z", true, true, resultPtsSizes3, resultPts3, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
2696 { "M 1 0 L 1 0 M 0 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2697 { "M 1 0 L 1 0 M 0 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2698 { "M 1 0 L 1 0 M 0 0 z", false, false, resultPtsSizes4, resultPts4, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
2699 { "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 +00002700 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002701
schenney@chromium.org7e963602012-06-13 17:05:43 +00002702 for (size_t i = 0; i < SK_ARRAY_COUNT(gIterTests); ++i) {
2703 p.reset();
2704 bool valid = SkParsePath::FromSVGString(gIterTests[i].testPath, &p);
2705 REPORTER_ASSERT(reporter, valid);
2706 iter.setPath(p, gIterTests[i].forceClose);
2707 int j = 0, l = 0;
2708 do {
2709 REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegenerates) == gIterTests[i].resultVerbs[j]);
2710 for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k) {
2711 REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]);
2712 }
2713 } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb);
2714 REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs);
2715 }
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002716
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002717 p.reset();
2718 iter.setPath(p, false);
2719 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2720 p.lineTo(1, 1);
2721 p.close();
2722 iter.setPath(p, false);
2723 REPORTER_ASSERT(reporter, iter.isClosedContour());
2724 p.reset();
2725 iter.setPath(p, true);
2726 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2727 p.lineTo(1, 1);
2728 iter.setPath(p, true);
2729 REPORTER_ASSERT(reporter, iter.isClosedContour());
2730 p.moveTo(0, 0);
2731 p.lineTo(2, 2);
2732 iter.setPath(p, false);
2733 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2734
2735 // this checks to see if the NaN logic is executed in SkPath::autoClose(), but does not
2736 // check to see if the result is correct.
2737 for (int setNaN = 0; setNaN < 4; ++setNaN) {
2738 p.reset();
2739 p.moveTo(setNaN == 0 ? SK_ScalarNaN : 0, setNaN == 1 ? SK_ScalarNaN : 0);
2740 p.lineTo(setNaN == 2 ? SK_ScalarNaN : 1, setNaN == 3 ? SK_ScalarNaN : 1);
2741 iter.setPath(p, true);
2742 iter.next(pts, false);
2743 iter.next(pts, false);
2744 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == iter.next(pts, false));
2745 }
2746
2747 p.reset();
2748 p.quadTo(0, 0, 0, 0);
2749 iter.setPath(p, false);
2750 iter.next(pts, false);
2751 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == iter.next(pts, false));
2752 iter.setPath(p, false);
2753 iter.next(pts, false);
2754 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2755
2756 p.reset();
2757 p.conicTo(0, 0, 0, 0, 0.5f);
2758 iter.setPath(p, false);
2759 iter.next(pts, false);
2760 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts, false));
2761 iter.setPath(p, false);
2762 iter.next(pts, false);
2763 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2764
2765 p.reset();
2766 p.cubicTo(0, 0, 0, 0, 0, 0);
2767 iter.setPath(p, false);
2768 iter.next(pts, false);
2769 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
2770 iter.setPath(p, false);
2771 iter.next(pts, false);
2772 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2773
2774 p.moveTo(1, 1); // add a trailing moveto
2775 iter.setPath(p, false);
2776 iter.next(pts, false);
2777 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
2778 iter.setPath(p, false);
2779 iter.next(pts, false);
2780 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2781
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002782 // The GM degeneratesegments.cpp test is more extensive
robertphillipsb8de1f42015-02-23 11:17:01 -08002783
2784 // Test out mixed degenerate and non-degenerate geometry with Conics
2785 const SkVector radii[4] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 100, 100 } };
2786 SkRect r = SkRect::MakeWH(100, 100);
2787 SkRRect rr;
2788 rr.setRectRadii(r, radii);
2789 p.reset();
2790 p.addRRect(rr);
2791 iter.setPath(p, false);
2792 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == iter.next(pts));
2793 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == iter.next(pts));
2794 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == iter.next(pts));
2795 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts));
2796 REPORTER_ASSERT(reporter, SK_ScalarRoot2Over2 == iter.conicWeight());
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002797}
2798
2799static void test_raw_iter(skiatest::Reporter* reporter) {
2800 SkPath p;
2801 SkPoint pts[4];
2802
2803 // Test an iterator with no path
2804 SkPath::RawIter noPathIter;
2805 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
2806 // Test that setting an empty path works
2807 noPathIter.setPath(p);
2808 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
rmistry@google.comd6176b02012-08-23 18:14:13 +00002809
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002810 // Test an iterator with an initial empty path
2811 SkPath::RawIter iter(p);
2812 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2813
2814 // Test that a move-only path returns the move.
2815 p.moveTo(SK_Scalar1, 0);
2816 iter.setPath(p);
2817 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2818 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2819 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2820 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2821
2822 // No matter how many moves we add, we should get them all back
2823 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2824 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2825 iter.setPath(p);
2826 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2827 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2828 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2829 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2830 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2831 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2832 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2833 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2834 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2835 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2836
2837 // Initial close is never ever stored
2838 p.reset();
2839 p.close();
2840 iter.setPath(p);
2841 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2842
2843 // Move/close sequences
2844 p.reset();
2845 p.close(); // Not stored, no purpose
2846 p.moveTo(SK_Scalar1, 0);
2847 p.close();
2848 p.close(); // Not stored, no purpose
2849 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2850 p.close();
2851 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2852 p.moveTo(SK_Scalar1*4, SK_Scalar1*3);
2853 p.close();
2854 iter.setPath(p);
2855 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2856 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2857 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2858 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002859 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2860 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2861 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2862 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002863 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2864 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2865 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2866 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2867 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2868 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2869 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002870 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2871
2872 // Generate random paths and verify
2873 SkPoint randomPts[25];
2874 for (int i = 0; i < 5; ++i) {
2875 for (int j = 0; j < 5; ++j) {
2876 randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j);
2877 }
2878 }
2879
2880 // Max of 10 segments, max 3 points per segment
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +00002881 SkRandom rand(9876543);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002882 SkPoint expectedPts[31]; // May have leading moveTo
reed@google.comd335d1d2012-01-12 18:17:11 +00002883 SkPath::Verb expectedVerbs[22]; // May have leading moveTo
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002884 SkPath::Verb nextVerb;
reed@google.comd335d1d2012-01-12 18:17:11 +00002885
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002886 for (int i = 0; i < 500; ++i) {
2887 p.reset();
2888 bool lastWasClose = true;
2889 bool haveMoveTo = false;
reed@google.comd335d1d2012-01-12 18:17:11 +00002890 SkPoint lastMoveToPt = { 0, 0 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002891 int numPoints = 0;
2892 int numVerbs = (rand.nextU() >> 16) % 10;
2893 int numIterVerbs = 0;
2894 for (int j = 0; j < numVerbs; ++j) {
2895 do {
2896 nextVerb = static_cast<SkPath::Verb>((rand.nextU() >> 16) % SkPath::kDone_Verb);
2897 } while (lastWasClose && nextVerb == SkPath::kClose_Verb);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002898 switch (nextVerb) {
2899 case SkPath::kMove_Verb:
2900 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2901 p.moveTo(expectedPts[numPoints]);
reed@google.comd335d1d2012-01-12 18:17:11 +00002902 lastMoveToPt = expectedPts[numPoints];
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002903 numPoints += 1;
2904 lastWasClose = false;
2905 haveMoveTo = true;
2906 break;
2907 case SkPath::kLine_Verb:
2908 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002909 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002910 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2911 haveMoveTo = true;
2912 }
2913 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2914 p.lineTo(expectedPts[numPoints]);
2915 numPoints += 1;
2916 lastWasClose = false;
2917 break;
2918 case SkPath::kQuad_Verb:
2919 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002920 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002921 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2922 haveMoveTo = true;
2923 }
2924 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2925 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2926 p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]);
2927 numPoints += 2;
2928 lastWasClose = false;
2929 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002930 case SkPath::kConic_Verb:
2931 if (!haveMoveTo) {
2932 expectedPts[numPoints++] = lastMoveToPt;
2933 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2934 haveMoveTo = true;
2935 }
2936 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2937 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2938 p.conicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2939 rand.nextUScalar1() * 4);
2940 numPoints += 2;
2941 lastWasClose = false;
2942 break;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002943 case SkPath::kCubic_Verb:
2944 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002945 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002946 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2947 haveMoveTo = true;
2948 }
2949 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2950 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2951 expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25];
2952 p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2953 expectedPts[numPoints + 2]);
2954 numPoints += 3;
2955 lastWasClose = false;
2956 break;
2957 case SkPath::kClose_Verb:
2958 p.close();
reed@google.comd335d1d2012-01-12 18:17:11 +00002959 haveMoveTo = false;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002960 lastWasClose = true;
2961 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002962 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002963 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002964 }
2965 expectedVerbs[numIterVerbs++] = nextVerb;
2966 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00002967
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002968 iter.setPath(p);
2969 numVerbs = numIterVerbs;
2970 numIterVerbs = 0;
2971 int numIterPts = 0;
2972 SkPoint lastMoveTo;
2973 SkPoint lastPt;
2974 lastMoveTo.set(0, 0);
2975 lastPt.set(0, 0);
2976 while ((nextVerb = iter.next(pts)) != SkPath::kDone_Verb) {
2977 REPORTER_ASSERT(reporter, nextVerb == expectedVerbs[numIterVerbs]);
2978 numIterVerbs++;
2979 switch (nextVerb) {
2980 case SkPath::kMove_Verb:
2981 REPORTER_ASSERT(reporter, numIterPts < numPoints);
2982 REPORTER_ASSERT(reporter, pts[0] == expectedPts[numIterPts]);
2983 lastPt = lastMoveTo = pts[0];
2984 numIterPts += 1;
2985 break;
2986 case SkPath::kLine_Verb:
2987 REPORTER_ASSERT(reporter, numIterPts < numPoints + 1);
2988 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2989 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2990 lastPt = pts[1];
2991 numIterPts += 1;
2992 break;
2993 case SkPath::kQuad_Verb:
reed@google.com277c3f82013-05-31 15:17:50 +00002994 case SkPath::kConic_Verb:
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002995 REPORTER_ASSERT(reporter, numIterPts < numPoints + 2);
2996 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2997 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2998 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2999 lastPt = pts[2];
3000 numIterPts += 2;
3001 break;
3002 case SkPath::kCubic_Verb:
3003 REPORTER_ASSERT(reporter, numIterPts < numPoints + 3);
3004 REPORTER_ASSERT(reporter, pts[0] == lastPt);
3005 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
3006 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
3007 REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]);
3008 lastPt = pts[3];
3009 numIterPts += 3;
3010 break;
3011 case SkPath::kClose_Verb:
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00003012 lastPt = lastMoveTo;
3013 break;
reed@google.com277c3f82013-05-31 15:17:50 +00003014 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00003015 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00003016 }
3017 }
3018 REPORTER_ASSERT(reporter, numIterPts == numPoints);
3019 REPORTER_ASSERT(reporter, numIterVerbs == numVerbs);
3020 }
3021}
3022
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003023static void check_for_circle(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003024 const SkPath& path,
3025 bool expectedCircle,
reed026beb52015-06-10 14:23:15 -07003026 SkPathPriv::FirstDirection expectedDir) {
robertphillips@google.com466310d2013-12-03 16:43:54 +00003027 SkRect rect = SkRect::MakeEmpty();
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003028 REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle);
bsalomon78d58d12016-05-27 09:17:04 -07003029 SkPath::Direction isOvalDir;
3030 unsigned isOvalStart;
3031 if (path.isOval(&rect, &isOvalDir, &isOvalStart)) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003032 REPORTER_ASSERT(reporter, rect.height() == rect.width());
bsalomon78d58d12016-05-27 09:17:04 -07003033 REPORTER_ASSERT(reporter, SkPathPriv::AsFirstDirection(isOvalDir) == expectedDir);
3034 SkPath tmpPath;
3035 tmpPath.addOval(rect, isOvalDir, isOvalStart);
3036 REPORTER_ASSERT(reporter, path == tmpPath);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003037 }
bsalomon78d58d12016-05-27 09:17:04 -07003038 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, expectedDir));
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003039}
3040
3041static void test_circle_skew(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003042 const SkPath& path,
reed026beb52015-06-10 14:23:15 -07003043 SkPathPriv::FirstDirection dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003044 SkPath tmp;
3045
3046 SkMatrix m;
3047 m.setSkew(SkIntToScalar(3), SkIntToScalar(5));
3048 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003049 // this matrix reverses the direction.
reed026beb52015-06-10 14:23:15 -07003050 if (SkPathPriv::kCCW_FirstDirection == dir) {
3051 dir = SkPathPriv::kCW_FirstDirection;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003052 } else {
reed026beb52015-06-10 14:23:15 -07003053 REPORTER_ASSERT(reporter, SkPathPriv::kCW_FirstDirection == dir);
3054 dir = SkPathPriv::kCCW_FirstDirection;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003055 }
3056 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003057}
3058
3059static void test_circle_translate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003060 const SkPath& path,
reed026beb52015-06-10 14:23:15 -07003061 SkPathPriv::FirstDirection dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003062 SkPath tmp;
3063
3064 // translate at small offset
3065 SkMatrix m;
3066 m.setTranslate(SkIntToScalar(15), SkIntToScalar(15));
3067 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003068 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003069
3070 tmp.reset();
3071 m.reset();
3072
3073 // translate at a relatively big offset
3074 m.setTranslate(SkIntToScalar(1000), SkIntToScalar(1000));
3075 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003076 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003077}
3078
3079static void test_circle_rotate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003080 const SkPath& path,
reed026beb52015-06-10 14:23:15 -07003081 SkPathPriv::FirstDirection dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003082 for (int angle = 0; angle < 360; ++angle) {
3083 SkPath tmp;
3084 SkMatrix m;
3085 m.setRotate(SkIntToScalar(angle));
3086 path.transform(m, &tmp);
3087
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003088 // TODO: a rotated circle whose rotated angle is not a multiple of 90
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003089 // degrees is not an oval anymore, this can be improved. we made this
3090 // for the simplicity of our implementation.
3091 if (angle % 90 == 0) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003092 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003093 } else {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003094 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003095 }
3096 }
3097}
3098
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003099static void test_circle_mirror_x(skiatest::Reporter* reporter,
3100 const SkPath& path,
reed026beb52015-06-10 14:23:15 -07003101 SkPathPriv::FirstDirection dir) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003102 SkPath tmp;
3103 SkMatrix m;
3104 m.reset();
3105 m.setScaleX(-SK_Scalar1);
3106 path.transform(m, &tmp);
reed026beb52015-06-10 14:23:15 -07003107 if (SkPathPriv::kCW_FirstDirection == dir) {
3108 dir = SkPathPriv::kCCW_FirstDirection;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003109 } else {
reed026beb52015-06-10 14:23:15 -07003110 REPORTER_ASSERT(reporter, SkPathPriv::kCCW_FirstDirection == dir);
3111 dir = SkPathPriv::kCW_FirstDirection;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003112 }
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003113 check_for_circle(reporter, tmp, true, dir);
3114}
3115
3116static void test_circle_mirror_y(skiatest::Reporter* reporter,
3117 const SkPath& path,
reed026beb52015-06-10 14:23:15 -07003118 SkPathPriv::FirstDirection dir) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003119 SkPath tmp;
3120 SkMatrix m;
3121 m.reset();
3122 m.setScaleY(-SK_Scalar1);
3123 path.transform(m, &tmp);
3124
reed026beb52015-06-10 14:23:15 -07003125 if (SkPathPriv::kCW_FirstDirection == dir) {
3126 dir = SkPathPriv::kCCW_FirstDirection;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003127 } else {
reed026beb52015-06-10 14:23:15 -07003128 REPORTER_ASSERT(reporter, SkPathPriv::kCCW_FirstDirection == dir);
3129 dir = SkPathPriv::kCW_FirstDirection;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003130 }
3131
3132 check_for_circle(reporter, tmp, true, dir);
3133}
3134
3135static void test_circle_mirror_xy(skiatest::Reporter* reporter,
3136 const SkPath& path,
reed026beb52015-06-10 14:23:15 -07003137 SkPathPriv::FirstDirection dir) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003138 SkPath tmp;
3139 SkMatrix m;
3140 m.reset();
3141 m.setScaleX(-SK_Scalar1);
3142 m.setScaleY(-SK_Scalar1);
3143 path.transform(m, &tmp);
3144
3145 check_for_circle(reporter, tmp, true, dir);
3146}
3147
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003148static void test_circle_with_direction(skiatest::Reporter* reporter,
reed026beb52015-06-10 14:23:15 -07003149 SkPath::Direction inDir) {
3150 const SkPathPriv::FirstDirection dir = SkPathPriv::AsFirstDirection(inDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003151 SkPath path;
3152
3153 // circle at origin
reed026beb52015-06-10 14:23:15 -07003154 path.addCircle(0, 0, SkIntToScalar(20), inDir);
3155
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003156 check_for_circle(reporter, path, true, dir);
3157 test_circle_rotate(reporter, path, dir);
3158 test_circle_translate(reporter, path, dir);
3159 test_circle_skew(reporter, path, dir);
bsalomon78d58d12016-05-27 09:17:04 -07003160 test_circle_mirror_x(reporter, path, dir);
3161 test_circle_mirror_y(reporter, path, dir);
3162 test_circle_mirror_xy(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003163
3164 // circle at an offset at (10, 10)
3165 path.reset();
3166 path.addCircle(SkIntToScalar(10), SkIntToScalar(10),
reed026beb52015-06-10 14:23:15 -07003167 SkIntToScalar(20), inDir);
3168
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003169 check_for_circle(reporter, path, true, dir);
3170 test_circle_rotate(reporter, path, dir);
3171 test_circle_translate(reporter, path, dir);
3172 test_circle_skew(reporter, path, dir);
3173 test_circle_mirror_x(reporter, path, dir);
3174 test_circle_mirror_y(reporter, path, dir);
3175 test_circle_mirror_xy(reporter, path, dir);
bsalomon78d58d12016-05-27 09:17:04 -07003176
3177 // Try different starting points for the contour.
3178 for (unsigned start = 0; start < 4; ++start) {
3179 path.reset();
3180 path.addOval(SkRect::MakeXYWH(20, 10, 5, 5), inDir, start);
3181 test_circle_rotate(reporter, path, dir);
3182 test_circle_translate(reporter, path, dir);
3183 test_circle_skew(reporter, path, dir);
3184 test_circle_mirror_x(reporter, path, dir);
3185 test_circle_mirror_y(reporter, path, dir);
3186 test_circle_mirror_xy(reporter, path, dir);
3187 }
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003188}
3189
3190static void test_circle_with_add_paths(skiatest::Reporter* reporter) {
3191 SkPath path;
3192 SkPath circle;
3193 SkPath rect;
3194 SkPath empty;
3195
reed026beb52015-06-10 14:23:15 -07003196 const SkPath::Direction kCircleDir = SkPath::kCW_Direction;
3197 const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00003198
3199 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003200 rect.addRect(SkIntToScalar(5), SkIntToScalar(5),
3201 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction);
3202
3203 SkMatrix translate;
3204 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12));
3205
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003206 // Although all the path concatenation related operations leave
3207 // the path a circle, most mark it as a non-circle for simplicity
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003208
3209 // empty + circle (translate)
3210 path = empty;
3211 path.addPath(circle, translate);
reed026beb52015-06-10 14:23:15 -07003212 check_for_circle(reporter, path, false, SkPathPriv::AsFirstDirection(kCircleDir));
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003213
3214 // circle + empty (translate)
3215 path = circle;
3216 path.addPath(empty, translate);
bsalomon78d58d12016-05-27 09:17:04 -07003217
reed026beb52015-06-10 14:23:15 -07003218 check_for_circle(reporter, path, true, SkPathPriv::AsFirstDirection(kCircleDir));
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003219
3220 // test reverseAddPath
3221 path = circle;
3222 path.reverseAddPath(rect);
reed026beb52015-06-10 14:23:15 -07003223 check_for_circle(reporter, path, false, SkPathPriv::AsFirstDirection(kCircleDirOpposite));
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003224}
3225
3226static void test_circle(skiatest::Reporter* reporter) {
3227 test_circle_with_direction(reporter, SkPath::kCW_Direction);
3228 test_circle_with_direction(reporter, SkPath::kCCW_Direction);
3229
3230 // multiple addCircle()
3231 SkPath path;
3232 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
3233 path.addCircle(0, 0, SkIntToScalar(20), SkPath::kCW_Direction);
reed026beb52015-06-10 14:23:15 -07003234 check_for_circle(reporter, path, false, SkPathPriv::kCW_FirstDirection);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003235
3236 // some extra lineTo() would make isOval() fail
3237 path.reset();
3238 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
3239 path.lineTo(0, 0);
reed026beb52015-06-10 14:23:15 -07003240 check_for_circle(reporter, path, false, SkPathPriv::kCW_FirstDirection);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003241
3242 // not back to the original point
3243 path.reset();
3244 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
3245 path.setLastPt(SkIntToScalar(5), SkIntToScalar(5));
reed026beb52015-06-10 14:23:15 -07003246 check_for_circle(reporter, path, false, SkPathPriv::kCW_FirstDirection);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003247
3248 test_circle_with_add_paths(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003249
3250 // test negative radius
3251 path.reset();
3252 path.addCircle(0, 0, -1, SkPath::kCW_Direction);
3253 REPORTER_ASSERT(reporter, path.isEmpty());
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003254}
3255
3256static void test_oval(skiatest::Reporter* reporter) {
3257 SkRect rect;
3258 SkMatrix m;
3259 SkPath path;
bsalomon78d58d12016-05-27 09:17:04 -07003260 unsigned start = 0;
3261 SkPath::Direction dir = SkPath::kCCW_Direction;
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003262
3263 rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50));
3264 path.addOval(rect);
3265
bsalomon78d58d12016-05-27 09:17:04 -07003266 // Defaults to dir = CW and start = 1
halcanary96fcdcc2015-08-27 07:41:13 -07003267 REPORTER_ASSERT(reporter, path.isOval(nullptr));
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003268
3269 m.setRotate(SkIntToScalar(90));
3270 SkPath tmp;
3271 path.transform(m, &tmp);
bsalomon78d58d12016-05-27 09:17:04 -07003272 // an oval rotated 90 degrees is still an oval. The start index changes from 1 to 2. Direction
3273 // is unchanged.
3274 REPORTER_ASSERT(reporter, tmp.isOval(nullptr, &dir, &start));
3275 REPORTER_ASSERT(reporter, 2 == start);
3276 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003277
3278 m.reset();
3279 m.setRotate(SkIntToScalar(30));
3280 tmp.reset();
3281 path.transform(m, &tmp);
3282 // an oval rotated 30 degrees is not an oval anymore.
halcanary96fcdcc2015-08-27 07:41:13 -07003283 REPORTER_ASSERT(reporter, !tmp.isOval(nullptr));
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003284
3285 // since empty path being transformed.
3286 path.reset();
3287 tmp.reset();
3288 m.reset();
3289 path.transform(m, &tmp);
halcanary96fcdcc2015-08-27 07:41:13 -07003290 REPORTER_ASSERT(reporter, !tmp.isOval(nullptr));
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003291
3292 // empty path is not an oval
3293 tmp.reset();
halcanary96fcdcc2015-08-27 07:41:13 -07003294 REPORTER_ASSERT(reporter, !tmp.isOval(nullptr));
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003295
3296 // only has moveTo()s
3297 tmp.reset();
3298 tmp.moveTo(0, 0);
3299 tmp.moveTo(SkIntToScalar(10), SkIntToScalar(10));
halcanary96fcdcc2015-08-27 07:41:13 -07003300 REPORTER_ASSERT(reporter, !tmp.isOval(nullptr));
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003301
3302 // mimic WebKit's calling convention,
3303 // call moveTo() first and then call addOval()
3304 path.reset();
3305 path.moveTo(0, 0);
3306 path.addOval(rect);
halcanary96fcdcc2015-08-27 07:41:13 -07003307 REPORTER_ASSERT(reporter, path.isOval(nullptr));
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003308
3309 // copy path
3310 path.reset();
3311 tmp.reset();
3312 tmp.addOval(rect);
3313 path = tmp;
bsalomon78d58d12016-05-27 09:17:04 -07003314 REPORTER_ASSERT(reporter, path.isOval(nullptr, &dir, &start));
3315 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
3316 REPORTER_ASSERT(reporter, 1 == start);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003317}
3318
bungeman@google.coma5809a32013-06-21 15:13:34 +00003319static void test_empty(skiatest::Reporter* reporter, const SkPath& p) {
3320 SkPath empty;
reed@android.com80e39a72009-04-02 16:59:40 +00003321
reed@android.com3abec1d2009-03-02 05:36:20 +00003322 REPORTER_ASSERT(reporter, p.isEmpty());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003323 REPORTER_ASSERT(reporter, 0 == p.countPoints());
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00003324 REPORTER_ASSERT(reporter, 0 == p.countVerbs());
reed@google.com10296cc2011-09-21 12:29:05 +00003325 REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks());
reed@google.comb54455e2011-05-16 14:16:04 +00003326 REPORTER_ASSERT(reporter, p.isConvex());
reed@android.com3abec1d2009-03-02 05:36:20 +00003327 REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType);
3328 REPORTER_ASSERT(reporter, !p.isInverseFillType());
bungeman@google.coma5809a32013-06-21 15:13:34 +00003329 REPORTER_ASSERT(reporter, p == empty);
3330 REPORTER_ASSERT(reporter, !(p != empty));
3331}
3332
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003333static void test_rrect_is_convex(skiatest::Reporter* reporter, SkPath* path,
3334 SkPath::Direction dir) {
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003335 REPORTER_ASSERT(reporter, path->isConvex());
reed026beb52015-06-10 14:23:15 -07003336 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(*path, SkPathPriv::AsFirstDirection(dir)));
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003337 path->setConvexity(SkPath::kUnknown_Convexity);
3338 REPORTER_ASSERT(reporter, path->isConvex());
3339 path->reset();
3340}
3341
caryclarkd3d1a982014-12-08 04:57:38 -08003342static void test_rrect_convexity_is_unknown(skiatest::Reporter* reporter, SkPath* path,
3343 SkPath::Direction dir) {
3344 REPORTER_ASSERT(reporter, path->isConvex());
reed026beb52015-06-10 14:23:15 -07003345 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(*path, SkPathPriv::AsFirstDirection(dir)));
caryclarkd3d1a982014-12-08 04:57:38 -08003346 path->setConvexity(SkPath::kUnknown_Convexity);
3347 REPORTER_ASSERT(reporter, path->getConvexity() == SkPath::kUnknown_Convexity);
3348 path->reset();
3349}
3350
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003351static void test_rrect(skiatest::Reporter* reporter) {
3352 SkPath p;
3353 SkRRect rr;
3354 SkVector radii[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
3355 SkRect r = {10, 20, 30, 40};
3356 rr.setRectRadii(r, radii);
3357 p.addRRect(rr);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003358 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003359 p.addRRect(rr, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003360 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003361 p.addRoundRect(r, &radii[0].fX);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003362 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003363 p.addRoundRect(r, &radii[0].fX, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003364 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003365 p.addRoundRect(r, radii[1].fX, radii[1].fY);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003366 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003367 p.addRoundRect(r, radii[1].fX, radii[1].fY, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003368 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
3369 for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) {
3370 SkVector save = radii[i];
3371 radii[i].set(0, 0);
3372 rr.setRectRadii(r, radii);
3373 p.addRRect(rr);
3374 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3375 radii[i] = save;
3376 }
3377 p.addRoundRect(r, 0, 0);
3378 SkRect returnedRect;
3379 REPORTER_ASSERT(reporter, p.isRect(&returnedRect));
3380 REPORTER_ASSERT(reporter, returnedRect == r);
3381 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3382 SkVector zeroRadii[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
3383 rr.setRectRadii(r, zeroRadii);
3384 p.addRRect(rr);
3385 bool closed;
3386 SkPath::Direction dir;
halcanary96fcdcc2015-08-27 07:41:13 -07003387 REPORTER_ASSERT(reporter, p.isRect(nullptr, &closed, &dir));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003388 REPORTER_ASSERT(reporter, closed);
3389 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
3390 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3391 p.addRRect(rr, SkPath::kCW_Direction);
3392 p.addRRect(rr, SkPath::kCW_Direction);
3393 REPORTER_ASSERT(reporter, !p.isConvex());
3394 p.reset();
3395 p.addRRect(rr, SkPath::kCCW_Direction);
3396 p.addRRect(rr, SkPath::kCCW_Direction);
3397 REPORTER_ASSERT(reporter, !p.isConvex());
3398 p.reset();
3399 SkRect emptyR = {10, 20, 10, 30};
3400 rr.setRectRadii(emptyR, radii);
3401 p.addRRect(rr);
3402 REPORTER_ASSERT(reporter, p.isEmpty());
3403 SkRect largeR = {0, 0, SK_ScalarMax, SK_ScalarMax};
3404 rr.setRectRadii(largeR, radii);
3405 p.addRRect(rr);
caryclarkd3d1a982014-12-08 04:57:38 -08003406 test_rrect_convexity_is_unknown(reporter, &p, SkPath::kCW_Direction);
reed454fa712015-02-10 08:46:22 -08003407
3408 // we check for non-finites
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003409 SkRect infR = {0, 0, SK_ScalarMax, SK_ScalarInfinity};
3410 rr.setRectRadii(infR, radii);
reed454fa712015-02-10 08:46:22 -08003411 REPORTER_ASSERT(reporter, rr.isEmpty());
3412
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003413 SkRect tinyR = {0, 0, 1e-9f, 1e-9f};
3414 p.addRoundRect(tinyR, 5e-11f, 5e-11f);
3415 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003416}
3417
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003418static void test_arc(skiatest::Reporter* reporter) {
3419 SkPath p;
3420 SkRect emptyOval = {10, 20, 30, 20};
3421 REPORTER_ASSERT(reporter, emptyOval.isEmpty());
3422 p.addArc(emptyOval, 1, 2);
3423 REPORTER_ASSERT(reporter, p.isEmpty());
3424 p.reset();
3425 SkRect oval = {10, 20, 30, 40};
3426 p.addArc(oval, 1, 0);
3427 REPORTER_ASSERT(reporter, p.isEmpty());
3428 p.reset();
3429 SkPath cwOval;
3430 cwOval.addOval(oval);
bsalomon1978ce22016-05-31 10:42:16 -07003431 p.addArc(oval, 0, 360);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003432 REPORTER_ASSERT(reporter, p == cwOval);
3433 p.reset();
3434 SkPath ccwOval;
3435 ccwOval.addOval(oval, SkPath::kCCW_Direction);
bsalomon1978ce22016-05-31 10:42:16 -07003436 p.addArc(oval, 0, -360);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003437 REPORTER_ASSERT(reporter, p == ccwOval);
3438 p.reset();
3439 p.addArc(oval, 1, 180);
3440 REPORTER_ASSERT(reporter, p.isConvex());
reed026beb52015-06-10 14:23:15 -07003441 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p, SkPathPriv::kCW_FirstDirection));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003442 p.setConvexity(SkPath::kUnknown_Convexity);
3443 REPORTER_ASSERT(reporter, p.isConvex());
3444}
3445
bsalomon1978ce22016-05-31 10:42:16 -07003446static inline SkScalar oval_start_index_to_angle(unsigned start) {
3447 switch (start) {
3448 case 0:
3449 return 270.f;
3450 case 1:
3451 return 0.f;
3452 case 2:
3453 return 90.f;
3454 case 3:
3455 return 180.f;
3456 default:
3457 return -1.f;
3458 }
3459}
3460
3461static inline SkScalar canonical_start_angle(float angle) {
3462 while (angle < 0.f) {
3463 angle += 360.f;
3464 }
3465 while (angle >= 360.f) {
3466 angle -= 360.f;
3467 }
3468 return angle;
3469}
3470
3471static void check_oval_arc(skiatest::Reporter* reporter, SkScalar start, SkScalar sweep,
3472 const SkPath& path) {
3473 SkRect r = SkRect::MakeEmpty();
3474 SkPath::Direction d = SkPath::kCCW_Direction;
3475 unsigned s = ~0U;
3476 bool isOval = path.isOval(&r, &d, &s);
3477 REPORTER_ASSERT(reporter, isOval);
3478 SkPath recreatedPath;
3479 recreatedPath.addOval(r, d, s);
3480 REPORTER_ASSERT(reporter, path == recreatedPath);
3481 REPORTER_ASSERT(reporter, oval_start_index_to_angle(s) == canonical_start_angle(start));
3482 REPORTER_ASSERT(reporter, (SkPath::kCW_Direction == d) == (sweep > 0.f));
3483}
3484
3485static void test_arc_ovals(skiatest::Reporter* reporter) {
3486 SkRect oval = SkRect::MakeWH(10, 20);
3487 for (SkScalar sweep : {-720.f, -540.f, -360.f, 360.f, 432.f, 720.f}) {
3488 for (SkScalar start = -360.f; start <= 360.f; start += 1.f) {
3489 SkPath path;
3490 path.addArc(oval, start, sweep);
3491 // SkPath's interfaces for inserting and extracting ovals only allow contours
3492 // to start at multiples of 90 degrees.
3493 if (std::fmod(start, 90.f) == 0) {
3494 check_oval_arc(reporter, start, sweep, path);
3495 } else {
3496 REPORTER_ASSERT(reporter, !path.isOval(nullptr));
3497 }
3498 }
3499 // Test start angles that are nearly at valid oval start angles.
3500 for (float start : {-180.f, -90.f, 90.f, 180.f}) {
3501 for (float delta : {-SK_ScalarNearlyZero, SK_ScalarNearlyZero}) {
3502 SkPath path;
3503 path.addArc(oval, start + delta, sweep);
3504 check_oval_arc(reporter, start, sweep, path);
3505 }
3506 }
3507 }
3508}
3509
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003510static void check_move(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3511 SkScalar x0, SkScalar y0) {
3512 SkPoint pts[4];
3513 SkPath::Verb v = iter->next(pts);
3514 REPORTER_ASSERT(reporter, v == SkPath::kMove_Verb);
3515 REPORTER_ASSERT(reporter, pts[0].fX == x0);
3516 REPORTER_ASSERT(reporter, pts[0].fY == y0);
3517}
3518
3519static void check_line(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3520 SkScalar x1, SkScalar y1) {
3521 SkPoint pts[4];
3522 SkPath::Verb v = iter->next(pts);
3523 REPORTER_ASSERT(reporter, v == SkPath::kLine_Verb);
3524 REPORTER_ASSERT(reporter, pts[1].fX == x1);
3525 REPORTER_ASSERT(reporter, pts[1].fY == y1);
3526}
3527
3528static void check_quad(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3529 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3530 SkPoint pts[4];
3531 SkPath::Verb v = iter->next(pts);
3532 REPORTER_ASSERT(reporter, v == SkPath::kQuad_Verb);
3533 REPORTER_ASSERT(reporter, pts[1].fX == x1);
3534 REPORTER_ASSERT(reporter, pts[1].fY == y1);
3535 REPORTER_ASSERT(reporter, pts[2].fX == x2);
3536 REPORTER_ASSERT(reporter, pts[2].fY == y2);
3537}
3538
3539static void check_done(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
3540 SkPoint pts[4];
3541 SkPath::Verb v = iter->next(pts);
3542 REPORTER_ASSERT(reporter, v == SkPath::kDone_Verb);
3543}
3544
3545static void check_done_and_reset(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
3546 check_done(reporter, p, iter);
3547 p->reset();
3548}
3549
3550static void check_path_is_move_and_reset(skiatest::Reporter* reporter, SkPath* p,
3551 SkScalar x0, SkScalar y0) {
3552 SkPath::RawIter iter(*p);
3553 check_move(reporter, &iter, x0, y0);
3554 check_done_and_reset(reporter, p, &iter);
3555}
3556
3557static void check_path_is_line_and_reset(skiatest::Reporter* reporter, SkPath* p,
3558 SkScalar x1, SkScalar y1) {
3559 SkPath::RawIter iter(*p);
3560 check_move(reporter, &iter, 0, 0);
3561 check_line(reporter, &iter, x1, y1);
3562 check_done_and_reset(reporter, p, &iter);
3563}
3564
3565static void check_path_is_line(skiatest::Reporter* reporter, SkPath* p,
3566 SkScalar x1, SkScalar y1) {
3567 SkPath::RawIter iter(*p);
3568 check_move(reporter, &iter, 0, 0);
3569 check_line(reporter, &iter, x1, y1);
3570 check_done(reporter, p, &iter);
3571}
3572
3573static void check_path_is_line_pair_and_reset(skiatest::Reporter* reporter, SkPath* p,
3574 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3575 SkPath::RawIter iter(*p);
3576 check_move(reporter, &iter, 0, 0);
3577 check_line(reporter, &iter, x1, y1);
3578 check_line(reporter, &iter, x2, y2);
3579 check_done_and_reset(reporter, p, &iter);
3580}
3581
3582static void check_path_is_quad_and_reset(skiatest::Reporter* reporter, SkPath* p,
3583 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3584 SkPath::RawIter iter(*p);
3585 check_move(reporter, &iter, 0, 0);
3586 check_quad(reporter, &iter, x1, y1, x2, y2);
3587 check_done_and_reset(reporter, p, &iter);
3588}
3589
reedd5d27d92015-02-09 13:54:43 -08003590static bool nearly_equal(const SkRect& a, const SkRect& b) {
3591 return SkScalarNearlyEqual(a.fLeft, b.fLeft) &&
3592 SkScalarNearlyEqual(a.fTop, b.fTop) &&
3593 SkScalarNearlyEqual(a.fRight, b.fRight) &&
3594 SkScalarNearlyEqual(a.fBottom, b.fBottom);
3595}
3596
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003597static void test_arcTo(skiatest::Reporter* reporter) {
3598 SkPath p;
3599 p.arcTo(0, 0, 1, 2, 1);
3600 check_path_is_line_and_reset(reporter, &p, 0, 0);
3601 p.arcTo(1, 2, 1, 2, 1);
3602 check_path_is_line_and_reset(reporter, &p, 1, 2);
3603 p.arcTo(1, 2, 3, 4, 0);
3604 check_path_is_line_and_reset(reporter, &p, 1, 2);
3605 p.arcTo(1, 2, 0, 0, 1);
3606 check_path_is_line_and_reset(reporter, &p, 1, 2);
3607 p.arcTo(1, 0, 1, 1, 1);
3608 SkPoint pt;
3609 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == 1);
3610 p.reset();
3611 p.arcTo(1, 0, 1, -1, 1);
3612 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == -1);
3613 p.reset();
3614 SkRect oval = {1, 2, 3, 4};
3615 p.arcTo(oval, 0, 0, true);
3616 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3617 p.arcTo(oval, 0, 0, false);
3618 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3619 p.arcTo(oval, 360, 0, true);
3620 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3621 p.arcTo(oval, 360, 0, false);
3622 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
reedd5d27d92015-02-09 13:54:43 -08003623
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003624 for (float sweep = 359, delta = 0.5f; sweep != (float) (sweep + delta); ) {
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00003625 p.arcTo(oval, 0, sweep, false);
reedd5d27d92015-02-09 13:54:43 -08003626 REPORTER_ASSERT(reporter, nearly_equal(p.getBounds(), oval));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003627 sweep += delta;
3628 delta /= 2;
3629 }
3630 for (float sweep = 361, delta = 0.5f; sweep != (float) (sweep - delta);) {
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00003631 p.arcTo(oval, 0, sweep, false);
reedd5d27d92015-02-09 13:54:43 -08003632 REPORTER_ASSERT(reporter, nearly_equal(p.getBounds(), oval));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003633 sweep -= delta;
3634 delta /= 2;
3635 }
3636 SkRect noOvalWidth = {1, 2, 0, 3};
3637 p.reset();
3638 p.arcTo(noOvalWidth, 0, 360, false);
3639 REPORTER_ASSERT(reporter, p.isEmpty());
3640
3641 SkRect noOvalHeight = {1, 2, 3, 1};
3642 p.reset();
3643 p.arcTo(noOvalHeight, 0, 360, false);
3644 REPORTER_ASSERT(reporter, p.isEmpty());
3645}
3646
3647static void test_addPath(skiatest::Reporter* reporter) {
3648 SkPath p, q;
3649 p.lineTo(1, 2);
3650 q.moveTo(4, 4);
3651 q.lineTo(7, 8);
3652 q.conicTo(8, 7, 6, 5, 0.5f);
3653 q.quadTo(6, 7, 8, 6);
3654 q.cubicTo(5, 6, 7, 8, 7, 5);
3655 q.close();
3656 p.addPath(q, -4, -4);
3657 SkRect expected = {0, 0, 4, 4};
3658 REPORTER_ASSERT(reporter, p.getBounds() == expected);
3659 p.reset();
3660 p.reverseAddPath(q);
3661 SkRect reverseExpected = {4, 4, 8, 8};
3662 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
3663}
3664
commit-bot@chromium.org14747e52014-02-11 21:16:29 +00003665static void test_addPathMode(skiatest::Reporter* reporter, bool explicitMoveTo, bool extend) {
3666 SkPath p, q;
3667 if (explicitMoveTo) {
3668 p.moveTo(1, 1);
3669 }
3670 p.lineTo(1, 2);
3671 if (explicitMoveTo) {
3672 q.moveTo(2, 1);
3673 }
3674 q.lineTo(2, 2);
3675 p.addPath(q, extend ? SkPath::kExtend_AddPathMode : SkPath::kAppend_AddPathMode);
3676 uint8_t verbs[4];
3677 int verbcount = p.getVerbs(verbs, 4);
3678 REPORTER_ASSERT(reporter, verbcount == 4);
3679 REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
3680 REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
3681 REPORTER_ASSERT(reporter, verbs[2] == (extend ? SkPath::kLine_Verb : SkPath::kMove_Verb));
3682 REPORTER_ASSERT(reporter, verbs[3] == SkPath::kLine_Verb);
3683}
3684
3685static void test_extendClosedPath(skiatest::Reporter* reporter) {
3686 SkPath p, q;
3687 p.moveTo(1, 1);
3688 p.lineTo(1, 2);
3689 p.lineTo(2, 2);
3690 p.close();
3691 q.moveTo(2, 1);
3692 q.lineTo(2, 3);
3693 p.addPath(q, SkPath::kExtend_AddPathMode);
3694 uint8_t verbs[7];
3695 int verbcount = p.getVerbs(verbs, 7);
3696 REPORTER_ASSERT(reporter, verbcount == 7);
3697 REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
3698 REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
3699 REPORTER_ASSERT(reporter, verbs[2] == SkPath::kLine_Verb);
3700 REPORTER_ASSERT(reporter, verbs[3] == SkPath::kClose_Verb);
3701 REPORTER_ASSERT(reporter, verbs[4] == SkPath::kMove_Verb);
3702 REPORTER_ASSERT(reporter, verbs[5] == SkPath::kLine_Verb);
3703 REPORTER_ASSERT(reporter, verbs[6] == SkPath::kLine_Verb);
3704
3705 SkPoint pt;
3706 REPORTER_ASSERT(reporter, p.getLastPt(&pt));
3707 REPORTER_ASSERT(reporter, pt == SkPoint::Make(2, 3));
3708 REPORTER_ASSERT(reporter, p.getPoint(3) == SkPoint::Make(1, 1));
3709}
3710
3711static void test_addEmptyPath(skiatest::Reporter* reporter, SkPath::AddPathMode mode) {
3712 SkPath p, q, r;
3713 // case 1: dst is empty
3714 p.moveTo(2, 1);
3715 p.lineTo(2, 3);
3716 q.addPath(p, mode);
3717 REPORTER_ASSERT(reporter, q == p);
3718 // case 2: src is empty
3719 p.addPath(r, mode);
3720 REPORTER_ASSERT(reporter, q == p);
3721 // case 3: src and dst are empty
3722 q.reset();
3723 q.addPath(r, mode);
3724 REPORTER_ASSERT(reporter, q.isEmpty());
skia.committer@gmail.com877c4492014-02-12 03:02:04 +00003725}
commit-bot@chromium.org14747e52014-02-11 21:16:29 +00003726
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003727static void test_conicTo_special_case(skiatest::Reporter* reporter) {
3728 SkPath p;
3729 p.conicTo(1, 2, 3, 4, -1);
3730 check_path_is_line_and_reset(reporter, &p, 3, 4);
3731 p.conicTo(1, 2, 3, 4, SK_ScalarInfinity);
3732 check_path_is_line_pair_and_reset(reporter, &p, 1, 2, 3, 4);
3733 p.conicTo(1, 2, 3, 4, 1);
3734 check_path_is_quad_and_reset(reporter, &p, 1, 2, 3, 4);
3735}
3736
3737static void test_get_point(skiatest::Reporter* reporter) {
3738 SkPath p;
3739 SkPoint pt = p.getPoint(0);
3740 REPORTER_ASSERT(reporter, pt == SkPoint::Make(0, 0));
halcanary96fcdcc2015-08-27 07:41:13 -07003741 REPORTER_ASSERT(reporter, !p.getLastPt(nullptr));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003742 REPORTER_ASSERT(reporter, !p.getLastPt(&pt) && pt == SkPoint::Make(0, 0));
3743 p.setLastPt(10, 10);
3744 pt = p.getPoint(0);
3745 REPORTER_ASSERT(reporter, pt == SkPoint::Make(10, 10));
halcanary96fcdcc2015-08-27 07:41:13 -07003746 REPORTER_ASSERT(reporter, p.getLastPt(nullptr));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003747 p.rMoveTo(10, 10);
3748 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt == SkPoint::Make(20, 20));
3749}
3750
3751static void test_contains(skiatest::Reporter* reporter) {
3752 SkPath p;
caryclarkdbaec732016-01-05 06:20:09 -08003753 p.moveTo(SkBits2Float(0xe085e7b1), SkBits2Float(0x5f512c00)); // -7.7191e+19f, 1.50724e+19f
3754 p.conicTo(SkBits2Float(0xdfdaa221), SkBits2Float(0x5eaac338), SkBits2Float(0x60342f13), SkBits2Float(0xdf0cbb58), SkBits2Float(0x3f3504f3)); // -3.15084e+19f, 6.15237e+18f, 5.19345e+19f, -1.01408e+19f, 0.707107f
3755 p.conicTo(SkBits2Float(0x60ead799), SkBits2Float(0xdfb76c24), SkBits2Float(0x609b9872), SkBits2Float(0xdf730de8), SkBits2Float(0x3f3504f4)); // 1.35377e+20f, -2.6434e+19f, 8.96947e+19f, -1.75139e+19f, 0.707107f
3756 p.lineTo(SkBits2Float(0x609b9872), SkBits2Float(0xdf730de8)); // 8.96947e+19f, -1.75139e+19f
3757 p.conicTo(SkBits2Float(0x6018b296), SkBits2Float(0xdeee870d), SkBits2Float(0xe008cd8e), SkBits2Float(0x5ed5b2db), SkBits2Float(0x3f3504f3)); // 4.40121e+19f, -8.59386e+18f, -3.94308e+19f, 7.69931e+18f, 0.707107f
3758 p.conicTo(SkBits2Float(0xe0d526d9), SkBits2Float(0x5fa67b31), SkBits2Float(0xe085e7b2), SkBits2Float(0x5f512c01), SkBits2Float(0x3f3504f3)); // -1.22874e+20f, 2.39925e+19f, -7.7191e+19f, 1.50724e+19f, 0.707107f
caryclarkba25ddb2016-01-05 12:36:09 -08003759 // this may return true or false, depending on the platform's numerics, but it should not crash
3760 (void) p.contains(-77.2027664f, 15.3066053f);
caryclarkdbaec732016-01-05 06:20:09 -08003761
3762 p.reset();
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003763 p.setFillType(SkPath::kInverseWinding_FillType);
3764 REPORTER_ASSERT(reporter, p.contains(0, 0));
3765 p.setFillType(SkPath::kWinding_FillType);
3766 REPORTER_ASSERT(reporter, !p.contains(0, 0));
3767 p.moveTo(4, 4);
3768 p.lineTo(6, 8);
3769 p.lineTo(8, 4);
caryclark9aacd902015-12-14 08:38:09 -08003770 // test on edge
3771 REPORTER_ASSERT(reporter, p.contains(6, 4));
3772 REPORTER_ASSERT(reporter, p.contains(5, 6));
3773 REPORTER_ASSERT(reporter, p.contains(7, 6));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003774 // test quick reject
3775 REPORTER_ASSERT(reporter, !p.contains(4, 0));
3776 REPORTER_ASSERT(reporter, !p.contains(0, 4));
3777 REPORTER_ASSERT(reporter, !p.contains(4, 10));
3778 REPORTER_ASSERT(reporter, !p.contains(10, 4));
3779 // test various crossings in x
3780 REPORTER_ASSERT(reporter, !p.contains(5, 7));
3781 REPORTER_ASSERT(reporter, p.contains(6, 7));
3782 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3783 p.reset();
3784 p.moveTo(4, 4);
3785 p.lineTo(8, 6);
3786 p.lineTo(4, 8);
caryclark9aacd902015-12-14 08:38:09 -08003787 // test on edge
3788 REPORTER_ASSERT(reporter, p.contains(4, 6));
3789 REPORTER_ASSERT(reporter, p.contains(6, 5));
3790 REPORTER_ASSERT(reporter, p.contains(6, 7));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003791 // test various crossings in y
3792 REPORTER_ASSERT(reporter, !p.contains(7, 5));
3793 REPORTER_ASSERT(reporter, p.contains(7, 6));
3794 REPORTER_ASSERT(reporter, !p.contains(7, 7));
caryclark9aacd902015-12-14 08:38:09 -08003795 p.reset();
3796 p.moveTo(4, 4);
fsc91065d2015-12-17 09:03:27 -08003797 p.lineTo(8, 4);
3798 p.lineTo(8, 8);
3799 p.lineTo(4, 8);
3800 // test on vertices
3801 REPORTER_ASSERT(reporter, p.contains(4, 4));
3802 REPORTER_ASSERT(reporter, p.contains(8, 4));
3803 REPORTER_ASSERT(reporter, p.contains(8, 8));
3804 REPORTER_ASSERT(reporter, p.contains(4, 8));
3805 p.reset();
3806 p.moveTo(4, 4);
caryclark9aacd902015-12-14 08:38:09 -08003807 p.lineTo(6, 8);
3808 p.lineTo(2, 8);
3809 // test on edge
3810 REPORTER_ASSERT(reporter, p.contains(5, 6));
3811 REPORTER_ASSERT(reporter, p.contains(4, 8));
3812 REPORTER_ASSERT(reporter, p.contains(3, 6));
3813 p.reset();
3814 p.moveTo(4, 4);
3815 p.lineTo(0, 6);
3816 p.lineTo(4, 8);
3817 // test on edge
3818 REPORTER_ASSERT(reporter, p.contains(2, 5));
3819 REPORTER_ASSERT(reporter, p.contains(2, 7));
3820 REPORTER_ASSERT(reporter, p.contains(4, 6));
3821 // test canceling coincident edge (a smaller triangle is coincident with a larger one)
3822 p.reset();
3823 p.moveTo(4, 0);
3824 p.lineTo(6, 4);
3825 p.lineTo(2, 4);
3826 p.moveTo(4, 0);
3827 p.lineTo(0, 8);
3828 p.lineTo(8, 8);
3829 REPORTER_ASSERT(reporter, !p.contains(1, 2));
3830 REPORTER_ASSERT(reporter, !p.contains(3, 2));
3831 REPORTER_ASSERT(reporter, !p.contains(4, 0));
3832 REPORTER_ASSERT(reporter, p.contains(4, 4));
3833
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003834 // test quads
3835 p.reset();
3836 p.moveTo(4, 4);
3837 p.quadTo(6, 6, 8, 8);
3838 p.quadTo(6, 8, 4, 8);
3839 p.quadTo(4, 6, 4, 4);
3840 REPORTER_ASSERT(reporter, p.contains(5, 6));
3841 REPORTER_ASSERT(reporter, !p.contains(6, 5));
caryclark9aacd902015-12-14 08:38:09 -08003842 // test quad edge
3843 REPORTER_ASSERT(reporter, p.contains(5, 5));
3844 REPORTER_ASSERT(reporter, p.contains(5, 8));
3845 REPORTER_ASSERT(reporter, p.contains(4, 5));
caryclark9cb5d752015-12-18 04:35:24 -08003846 // test quad endpoints
3847 REPORTER_ASSERT(reporter, p.contains(4, 4));
3848 REPORTER_ASSERT(reporter, p.contains(8, 8));
3849 REPORTER_ASSERT(reporter, p.contains(4, 8));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003850
3851 p.reset();
caryclark9aacd902015-12-14 08:38:09 -08003852 const SkPoint qPts[] = {{6, 6}, {8, 8}, {6, 8}, {4, 8}, {4, 6}, {4, 4}, {6, 6}};
3853 p.moveTo(qPts[0]);
3854 for (int index = 1; index < (int) SK_ARRAY_COUNT(qPts); index += 2) {
3855 p.quadTo(qPts[index], qPts[index + 1]);
3856 }
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003857 REPORTER_ASSERT(reporter, p.contains(5, 6));
3858 REPORTER_ASSERT(reporter, !p.contains(6, 5));
caryclark9aacd902015-12-14 08:38:09 -08003859 // test quad edge
3860 SkPoint halfway;
3861 for (int index = 0; index < (int) SK_ARRAY_COUNT(qPts) - 2; index += 2) {
3862 SkEvalQuadAt(&qPts[index], 0.5f, &halfway, nullptr);
3863 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3864 }
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003865
caryclark9aacd902015-12-14 08:38:09 -08003866 // test conics
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003867 p.reset();
caryclark9aacd902015-12-14 08:38:09 -08003868 const SkPoint kPts[] = {{4, 4}, {6, 6}, {8, 8}, {6, 8}, {4, 8}, {4, 6}, {4, 4}};
3869 p.moveTo(kPts[0]);
3870 for (int index = 1; index < (int) SK_ARRAY_COUNT(kPts); index += 2) {
3871 p.conicTo(kPts[index], kPts[index + 1], 0.5f);
3872 }
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003873 REPORTER_ASSERT(reporter, p.contains(5, 6));
3874 REPORTER_ASSERT(reporter, !p.contains(6, 5));
caryclark9aacd902015-12-14 08:38:09 -08003875 // test conic edge
3876 for (int index = 0; index < (int) SK_ARRAY_COUNT(kPts) - 2; index += 2) {
3877 SkConic conic(&kPts[index], 0.5f);
3878 halfway = conic.evalAt(0.5f);
3879 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3880 }
caryclark9cb5d752015-12-18 04:35:24 -08003881 // test conic end points
3882 REPORTER_ASSERT(reporter, p.contains(4, 4));
3883 REPORTER_ASSERT(reporter, p.contains(8, 8));
3884 REPORTER_ASSERT(reporter, p.contains(4, 8));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003885
3886 // test cubics
3887 SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5, 4}, {6, 5}, {7, 6}};
3888 for (int i = 0; i < 3; ++i) {
3889 p.reset();
3890 p.setFillType(SkPath::kEvenOdd_FillType);
3891 p.moveTo(pts[i].fX, pts[i].fY);
3892 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);
3893 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);
3894 p.close();
3895 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f));
3896 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f));
caryclark9aacd902015-12-14 08:38:09 -08003897 // test cubic edge
3898 SkEvalCubicAt(&pts[i], 0.5f, &halfway, nullptr, nullptr);
3899 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3900 SkEvalCubicAt(&pts[i + 3], 0.5f, &halfway, nullptr, nullptr);
3901 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
caryclark9cb5d752015-12-18 04:35:24 -08003902 // test cubic end points
3903 REPORTER_ASSERT(reporter, p.contains(pts[i].fX, pts[i].fY));
3904 REPORTER_ASSERT(reporter, p.contains(pts[i + 3].fX, pts[i + 3].fY));
3905 REPORTER_ASSERT(reporter, p.contains(pts[i + 6].fX, pts[i + 6].fY));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003906 }
3907}
3908
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003909class PathRefTest_Private {
3910public:
3911 static void TestPathRef(skiatest::Reporter* reporter) {
3912 static const int kRepeatCnt = 10;
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003913
halcanary385fe4d2015-08-26 13:07:48 -07003914 SkAutoTUnref<SkPathRef> pathRef(new SkPathRef);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003915
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003916 SkPathRef::Editor ed(&pathRef);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003917
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003918 {
3919 ed.growForRepeatedVerb(SkPath::kMove_Verb, kRepeatCnt);
3920 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3921 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
3922 REPORTER_ASSERT(reporter, 0 == pathRef->getSegmentMasks());
3923 for (int i = 0; i < kRepeatCnt; ++i) {
3924 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == pathRef->atVerb(i));
3925 }
3926 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003927 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003928
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003929 {
3930 ed.growForRepeatedVerb(SkPath::kLine_Verb, kRepeatCnt);
3931 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3932 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
3933 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == pathRef->getSegmentMasks());
3934 for (int i = 0; i < kRepeatCnt; ++i) {
3935 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == pathRef->atVerb(i));
3936 }
3937 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003938 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003939
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003940 {
3941 ed.growForRepeatedVerb(SkPath::kQuad_Verb, kRepeatCnt);
3942 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3943 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
3944 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == pathRef->getSegmentMasks());
3945 for (int i = 0; i < kRepeatCnt; ++i) {
3946 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == pathRef->atVerb(i));
3947 }
3948 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003949 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003950
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003951 {
halcanary96fcdcc2015-08-27 07:41:13 -07003952 SkScalar* weights = nullptr;
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003953 ed.growForRepeatedVerb(SkPath::kConic_Verb, kRepeatCnt, &weights);
3954 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3955 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
3956 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countWeights());
3957 REPORTER_ASSERT(reporter, SkPath::kConic_SegmentMask == pathRef->getSegmentMasks());
bsalomon49f085d2014-09-05 13:34:00 -07003958 REPORTER_ASSERT(reporter, weights);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003959 for (int i = 0; i < kRepeatCnt; ++i) {
3960 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == pathRef->atVerb(i));
3961 }
3962 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003963 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003964
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003965 {
3966 ed.growForRepeatedVerb(SkPath::kCubic_Verb, kRepeatCnt);
3967 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3968 REPORTER_ASSERT(reporter, 3*kRepeatCnt == pathRef->countPoints());
3969 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == pathRef->getSegmentMasks());
3970 for (int i = 0; i < kRepeatCnt; ++i) {
3971 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == pathRef->atVerb(i));
3972 }
3973 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003974 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003975 }
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003976};
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003977
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003978static void test_operatorEqual(skiatest::Reporter* reporter) {
3979 SkPath a;
3980 SkPath b;
3981 REPORTER_ASSERT(reporter, a == a);
3982 REPORTER_ASSERT(reporter, a == b);
3983 a.setFillType(SkPath::kInverseWinding_FillType);
3984 REPORTER_ASSERT(reporter, a != b);
3985 a.reset();
3986 REPORTER_ASSERT(reporter, a == b);
3987 a.lineTo(1, 1);
3988 REPORTER_ASSERT(reporter, a != b);
3989 a.reset();
3990 REPORTER_ASSERT(reporter, a == b);
3991 a.lineTo(1, 1);
3992 b.lineTo(1, 2);
3993 REPORTER_ASSERT(reporter, a != b);
3994 a.reset();
3995 a.lineTo(1, 2);
3996 REPORTER_ASSERT(reporter, a == b);
3997}
3998
caryclark66a5d8b2014-06-24 08:30:15 -07003999static void compare_dump(skiatest::Reporter* reporter, const SkPath& path, bool force,
caryclarke9562592014-09-15 09:26:09 -07004000 bool dumpAsHex, const char* str) {
caryclark66a5d8b2014-06-24 08:30:15 -07004001 SkDynamicMemoryWStream wStream;
caryclarke9562592014-09-15 09:26:09 -07004002 path.dump(&wStream, force, dumpAsHex);
caryclark66a5d8b2014-06-24 08:30:15 -07004003 SkAutoDataUnref data(wStream.copyToData());
4004 REPORTER_ASSERT(reporter, data->size() == strlen(str));
mtkleind4897592014-11-14 09:22:40 -08004005 if (strlen(str) > 0) {
4006 REPORTER_ASSERT(reporter, !memcmp(data->data(), str, strlen(str)));
4007 } else {
halcanary96fcdcc2015-08-27 07:41:13 -07004008 REPORTER_ASSERT(reporter, data->data() == nullptr || !memcmp(data->data(), str, strlen(str)));
mtkleind4897592014-11-14 09:22:40 -08004009 }
caryclark66a5d8b2014-06-24 08:30:15 -07004010}
4011
4012static void test_dump(skiatest::Reporter* reporter) {
4013 SkPath p;
caryclarke9562592014-09-15 09:26:09 -07004014 compare_dump(reporter, p, false, false, "");
4015 compare_dump(reporter, p, true, false, "");
caryclark66a5d8b2014-06-24 08:30:15 -07004016 p.moveTo(1, 2);
4017 p.lineTo(3, 4);
caryclarke9562592014-09-15 09:26:09 -07004018 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
4019 "path.lineTo(3, 4);\n");
4020 compare_dump(reporter, p, true, false, "path.moveTo(1, 2);\n"
4021 "path.lineTo(3, 4);\n"
4022 "path.lineTo(1, 2);\n"
4023 "path.close();\n");
caryclark66a5d8b2014-06-24 08:30:15 -07004024 p.reset();
4025 p.moveTo(1, 2);
4026 p.quadTo(3, 4, 5, 6);
caryclarke9562592014-09-15 09:26:09 -07004027 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
4028 "path.quadTo(3, 4, 5, 6);\n");
caryclark66a5d8b2014-06-24 08:30:15 -07004029 p.reset();
4030 p.moveTo(1, 2);
4031 p.conicTo(3, 4, 5, 6, 0.5f);
caryclarke9562592014-09-15 09:26:09 -07004032 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
4033 "path.conicTo(3, 4, 5, 6, 0.5f);\n");
caryclark66a5d8b2014-06-24 08:30:15 -07004034 p.reset();
4035 p.moveTo(1, 2);
4036 p.cubicTo(3, 4, 5, 6, 7, 8);
caryclarke9562592014-09-15 09:26:09 -07004037 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
4038 "path.cubicTo(3, 4, 5, 6, 7, 8);\n");
4039 p.reset();
4040 p.moveTo(1, 2);
4041 p.lineTo(3, 4);
caryclark08fa28c2014-10-23 13:08:56 -07004042 compare_dump(reporter, p, false, true,
4043 "path.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)); // 1, 2\n"
4044 "path.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)); // 3, 4\n");
caryclarke9562592014-09-15 09:26:09 -07004045 p.reset();
4046 p.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000));
4047 p.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000));
4048 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
4049 "path.lineTo(3, 4);\n");
caryclark66a5d8b2014-06-24 08:30:15 -07004050}
4051
senorblanco84cd6212015-08-04 10:01:58 -07004052namespace {
4053
4054class ChangeListener : public SkPathRef::GenIDChangeListener {
4055public:
4056 ChangeListener(bool *changed) : fChanged(changed) { *fChanged = false; }
4057 virtual ~ChangeListener() {}
4058 void onChange() override {
4059 *fChanged = true;
4060 }
4061private:
4062 bool* fChanged;
4063};
4064
4065}
4066
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00004067class PathTest_Private {
4068public:
4069 static void TestPathTo(skiatest::Reporter* reporter) {
4070 SkPath p, q;
4071 p.lineTo(4, 4);
4072 p.reversePathTo(q);
4073 check_path_is_line(reporter, &p, 4, 4);
4074 q.moveTo(-4, -4);
4075 p.reversePathTo(q);
4076 check_path_is_line(reporter, &p, 4, 4);
4077 q.lineTo(7, 8);
4078 q.conicTo(8, 7, 6, 5, 0.5f);
4079 q.quadTo(6, 7, 8, 6);
4080 q.cubicTo(5, 6, 7, 8, 7, 5);
4081 q.close();
4082 p.reversePathTo(q);
4083 SkRect reverseExpected = {-4, -4, 8, 8};
4084 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
4085 }
senorblanco84cd6212015-08-04 10:01:58 -07004086
4087 static void TestPathrefListeners(skiatest::Reporter* reporter) {
4088 SkPath p;
4089
4090 bool changed = false;
4091 p.moveTo(0, 0);
4092
4093 // Check that listener is notified on moveTo().
4094
halcanary385fe4d2015-08-26 13:07:48 -07004095 SkPathPriv::AddGenIDChangeListener(p, new ChangeListener(&changed));
senorblanco84cd6212015-08-04 10:01:58 -07004096 REPORTER_ASSERT(reporter, !changed);
4097 p.moveTo(10, 0);
4098 REPORTER_ASSERT(reporter, changed);
4099
4100 // Check that listener is notified on lineTo().
halcanary385fe4d2015-08-26 13:07:48 -07004101 SkPathPriv::AddGenIDChangeListener(p, new ChangeListener(&changed));
senorblanco84cd6212015-08-04 10:01:58 -07004102 REPORTER_ASSERT(reporter, !changed);
4103 p.lineTo(20, 0);
4104 REPORTER_ASSERT(reporter, changed);
4105
4106 // Check that listener is notified on reset().
halcanary385fe4d2015-08-26 13:07:48 -07004107 SkPathPriv::AddGenIDChangeListener(p, new ChangeListener(&changed));
senorblanco84cd6212015-08-04 10:01:58 -07004108 REPORTER_ASSERT(reporter, !changed);
4109 p.reset();
4110 REPORTER_ASSERT(reporter, changed);
4111
4112 p.moveTo(0, 0);
4113
4114 // Check that listener is notified on rewind().
halcanary385fe4d2015-08-26 13:07:48 -07004115 SkPathPriv::AddGenIDChangeListener(p, new ChangeListener(&changed));
senorblanco84cd6212015-08-04 10:01:58 -07004116 REPORTER_ASSERT(reporter, !changed);
4117 p.rewind();
4118 REPORTER_ASSERT(reporter, changed);
4119
4120 // Check that listener is notified when pathref is deleted.
4121 {
4122 SkPath q;
4123 q.moveTo(10, 10);
halcanary385fe4d2015-08-26 13:07:48 -07004124 SkPathPriv::AddGenIDChangeListener(q, new ChangeListener(&changed));
senorblanco84cd6212015-08-04 10:01:58 -07004125 REPORTER_ASSERT(reporter, !changed);
4126 }
4127 // q went out of scope.
4128 REPORTER_ASSERT(reporter, changed);
4129 }
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00004130};
4131
caryclark8e7b19d2016-02-18 04:11:48 -08004132static void test_interp(skiatest::Reporter* reporter) {
4133 SkPath p1, p2, out;
4134 REPORTER_ASSERT(reporter, p1.isInterpolatable(p2));
4135 REPORTER_ASSERT(reporter, p1.interpolate(p2, 0, &out));
4136 REPORTER_ASSERT(reporter, p1 == out);
4137 REPORTER_ASSERT(reporter, p1.interpolate(p2, 1, &out));
4138 REPORTER_ASSERT(reporter, p1 == out);
4139 p1.moveTo(0, 2);
4140 p1.lineTo(0, 4);
4141 REPORTER_ASSERT(reporter, !p1.isInterpolatable(p2));
4142 REPORTER_ASSERT(reporter, !p1.interpolate(p2, 1, &out));
4143 p2.moveTo(6, 0);
4144 p2.lineTo(8, 0);
4145 REPORTER_ASSERT(reporter, p1.isInterpolatable(p2));
4146 REPORTER_ASSERT(reporter, p1.interpolate(p2, 0, &out));
4147 REPORTER_ASSERT(reporter, p2 == out);
4148 REPORTER_ASSERT(reporter, p1.interpolate(p2, 1, &out));
4149 REPORTER_ASSERT(reporter, p1 == out);
4150 REPORTER_ASSERT(reporter, p1.interpolate(p2, 0.5f, &out));
4151 REPORTER_ASSERT(reporter, out.getBounds() == SkRect::MakeLTRB(3, 1, 4, 2));
4152 p1.reset();
4153 p1.moveTo(4, 4);
4154 p1.conicTo(5, 4, 5, 5, 1 / SkScalarSqrt(2));
4155 p2.reset();
4156 p2.moveTo(4, 2);
4157 p2.conicTo(7, 2, 7, 5, 1 / SkScalarSqrt(2));
4158 REPORTER_ASSERT(reporter, p1.isInterpolatable(p2));
4159 REPORTER_ASSERT(reporter, p1.interpolate(p2, 0.5f, &out));
4160 REPORTER_ASSERT(reporter, out.getBounds() == SkRect::MakeLTRB(4, 3, 6, 5));
4161 p2.reset();
4162 p2.moveTo(4, 2);
4163 p2.conicTo(6, 3, 6, 5, 1);
4164 REPORTER_ASSERT(reporter, !p1.isInterpolatable(p2));
4165 p2.reset();
4166 p2.moveTo(4, 4);
4167 p2.conicTo(5, 4, 5, 5, 0.5f);
4168 REPORTER_ASSERT(reporter, !p1.isInterpolatable(p2));
4169}
4170
4171DEF_TEST(PathInterp, reporter) {
4172 test_interp(reporter);
4173}
4174
caryclark9aacd902015-12-14 08:38:09 -08004175DEF_TEST(PathContains, reporter) {
4176 test_contains(reporter);
4177}
4178
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00004179DEF_TEST(Paths, reporter) {
reedb1b12f82016-07-13 10:56:53 -07004180 test_fuzz_crbug_627414(reporter);
commit-bot@chromium.org4e332f82014-05-05 16:04:42 +00004181 test_path_crbug364224();
4182
bungeman@google.coma5809a32013-06-21 15:13:34 +00004183 SkTSize<SkScalar>::Make(3,4);
4184
4185 SkPath p, empty;
4186 SkRect bounds, bounds2;
4187 test_empty(reporter, p);
reed@android.com3abec1d2009-03-02 05:36:20 +00004188
reed@android.comd252db02009-04-01 18:31:44 +00004189 REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
reed@android.com80e39a72009-04-02 16:59:40 +00004190
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00004191 // this triggers a code path in SkPath::operator= which is otherwise unexercised
4192 SkPath& self = p;
4193 p = self;
4194
4195 // this triggers a code path in SkPath::swap which is otherwise unexercised
4196 p.swap(self);
4197
reed@android.com3abec1d2009-03-02 05:36:20 +00004198 bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
reed@android.com6b82d1a2009-06-03 02:35:01 +00004199
reed@android.com6b82d1a2009-06-03 02:35:01 +00004200 p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1);
4201 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00004202 // we have quads or cubics
reed220f9262014-12-17 08:21:04 -08004203 REPORTER_ASSERT(reporter,
4204 p.getSegmentMasks() & (kCurveSegmentMask | SkPath::kConic_SegmentMask));
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00004205 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00004206
reed@android.com6b82d1a2009-06-03 02:35:01 +00004207 p.reset();
bungeman@google.coma5809a32013-06-21 15:13:34 +00004208 test_empty(reporter, p);
reed@google.com10296cc2011-09-21 12:29:05 +00004209
reed@android.com6b82d1a2009-06-03 02:35:01 +00004210 p.addOval(bounds);
4211 check_convex_bounds(reporter, p, bounds);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00004212 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00004213
bungeman@google.coma5809a32013-06-21 15:13:34 +00004214 p.rewind();
4215 test_empty(reporter, p);
4216
reed@android.com3abec1d2009-03-02 05:36:20 +00004217 p.addRect(bounds);
reed@android.com6b82d1a2009-06-03 02:35:01 +00004218 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00004219 // we have only lines
4220 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == p.getSegmentMasks());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00004221 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@android.com3abec1d2009-03-02 05:36:20 +00004222
bungeman@google.coma5809a32013-06-21 15:13:34 +00004223 REPORTER_ASSERT(reporter, p != empty);
4224 REPORTER_ASSERT(reporter, !(p == empty));
reed@android.com3abec1d2009-03-02 05:36:20 +00004225
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00004226 // do getPoints and getVerbs return the right result
halcanary96fcdcc2015-08-27 07:41:13 -07004227 REPORTER_ASSERT(reporter, p.getPoints(nullptr, 0) == 4);
4228 REPORTER_ASSERT(reporter, p.getVerbs(nullptr, 0) == 5);
reed@android.com3abec1d2009-03-02 05:36:20 +00004229 SkPoint pts[4];
4230 int count = p.getPoints(pts, 4);
4231 REPORTER_ASSERT(reporter, count == 4);
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00004232 uint8_t verbs[6];
4233 verbs[5] = 0xff;
4234 p.getVerbs(verbs, 5);
4235 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == verbs[0]);
4236 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[1]);
4237 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[2]);
4238 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[3]);
4239 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == verbs[4]);
4240 REPORTER_ASSERT(reporter, 0xff == verbs[5]);
reed@android.com3abec1d2009-03-02 05:36:20 +00004241 bounds2.set(pts, 4);
4242 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00004243
reed@android.com3abec1d2009-03-02 05:36:20 +00004244 bounds.offset(SK_Scalar1*3, SK_Scalar1*4);
4245 p.offset(SK_Scalar1*3, SK_Scalar1*4);
reed@android.comd252db02009-04-01 18:31:44 +00004246 REPORTER_ASSERT(reporter, bounds == p.getBounds());
reed@android.com3abec1d2009-03-02 05:36:20 +00004247
halcanary96fcdcc2015-08-27 07:41:13 -07004248 REPORTER_ASSERT(reporter, p.isRect(nullptr));
caryclark@google.comf1316942011-07-26 19:54:45 +00004249 bounds2.setEmpty();
reed@android.com3abec1d2009-03-02 05:36:20 +00004250 REPORTER_ASSERT(reporter, p.isRect(&bounds2));
4251 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00004252
reed@android.com3abec1d2009-03-02 05:36:20 +00004253 // now force p to not be a rect
4254 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2);
4255 p.addRect(bounds);
halcanary96fcdcc2015-08-27 07:41:13 -07004256 REPORTER_ASSERT(reporter, !p.isRect(nullptr));
reed@android.com3abec1d2009-03-02 05:36:20 +00004257
robertphillipsfe7c4272014-12-29 11:36:39 -08004258 // Test an edge case w.r.t. the bound returned by isRect (i.e., the
4259 // path has a trailing moveTo. Please see crbug.com\445368)
4260 {
4261 SkRect r;
4262 p.reset();
4263 p.addRect(bounds);
4264 REPORTER_ASSERT(reporter, p.isRect(&r));
4265 REPORTER_ASSERT(reporter, r == bounds);
4266 // add a moveTo outside of our bounds
4267 p.moveTo(bounds.fLeft + 10, bounds.fBottom + 10);
4268 REPORTER_ASSERT(reporter, p.isRect(&r));
4269 REPORTER_ASSERT(reporter, r == bounds);
4270 }
4271
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00004272 test_operatorEqual(reporter);
reed@google.com7e6c4d12012-05-10 14:05:43 +00004273 test_isLine(reporter);
4274 test_isRect(reporter);
bsalomonedc743a2016-06-01 09:42:31 -07004275 test_is_simple_closed_rect(reporter);
caryclark95bc5f32015-04-08 08:34:15 -07004276 test_isNestedFillRects(reporter);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00004277 test_zero_length_paths(reporter);
reed@google.comcabaf1d2012-01-11 21:03:05 +00004278 test_direction(reporter);
reed@google.com04863fa2011-05-15 04:08:24 +00004279 test_convexity(reporter);
reed@google.com7c424812011-05-15 04:38:34 +00004280 test_convexity2(reporter);
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00004281 test_conservativelyContains(reporter);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00004282 test_close(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00004283 test_segment_masks(reporter);
reed@google.com53effc52011-09-21 19:05:12 +00004284 test_flattening(reporter);
4285 test_transform(reporter);
reed@google.com3563c9e2011-11-14 19:34:57 +00004286 test_bounds(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00004287 test_iter(reporter);
4288 test_raw_iter(reporter);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00004289 test_circle(reporter);
4290 test_oval(reporter);
reed@google.com8b06f1a2012-05-29 12:03:46 +00004291 test_strokerec(reporter);
reed@google.com744faba2012-05-29 19:54:52 +00004292 test_addPoly(reporter);
reed@google.com0bb18bb2012-07-26 15:20:36 +00004293 test_isfinite(reporter);
tomhudson@google.comed02c4d2012-08-10 14:10:45 +00004294 test_isfinite_after_transform(reporter);
fsb1475b02016-01-20 09:51:07 -08004295 test_islastcontourclosed(reporter);
robertphillips@google.comb95eaa82012-10-18 15:26:12 +00004296 test_arb_round_rect_is_convex(reporter);
robertphillips@google.com158618e2012-10-23 16:56:56 +00004297 test_arb_zero_rad_round_rect_is_rect(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00004298 test_addrect(reporter);
reed@google.coma8790de2012-10-24 21:04:04 +00004299 test_addrect_isfinite(reporter);
sugoi@google.com54f0d1b2013-02-27 19:17:41 +00004300 test_tricky_cubic();
4301 test_clipped_cubic();
4302 test_crbug_170666();
caryclarke8c56662015-07-14 11:19:26 -07004303 test_crbug_493450(reporter);
4304 test_crbug_495894(reporter);
mbarbella99600d02016-06-01 15:39:47 -07004305 test_crbug_613918();
reed@google.com7a90daf2013-04-10 18:44:00 +00004306 test_bad_cubic_crbug229478();
reed@google.com3eff3592013-05-08 21:08:21 +00004307 test_bad_cubic_crbug234190();
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +00004308 test_gen_id(reporter);
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +00004309 test_path_close_issue1474(reporter);
reed@google.comb58ba892013-10-15 15:44:35 +00004310 test_path_to_region(reporter);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00004311 test_rrect(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00004312 test_arc(reporter);
bsalomon1978ce22016-05-31 10:42:16 -07004313 test_arc_ovals(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00004314 test_arcTo(reporter);
4315 test_addPath(reporter);
commit-bot@chromium.org14747e52014-02-11 21:16:29 +00004316 test_addPathMode(reporter, false, false);
4317 test_addPathMode(reporter, true, false);
4318 test_addPathMode(reporter, false, true);
4319 test_addPathMode(reporter, true, true);
4320 test_extendClosedPath(reporter);
4321 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode);
4322 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00004323 test_conicTo_special_case(reporter);
4324 test_get_point(reporter);
4325 test_contains(reporter);
4326 PathTest_Private::TestPathTo(reporter);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00004327 PathRefTest_Private::TestPathRef(reporter);
senorblanco84cd6212015-08-04 10:01:58 -07004328 PathTest_Private::TestPathrefListeners(reporter);
caryclark66a5d8b2014-06-24 08:30:15 -07004329 test_dump(reporter);
caryclarkb4216502015-03-02 13:02:34 -08004330 test_path_crbug389050(reporter);
piotaixrfac4e0e2014-08-26 11:59:04 -07004331 test_path_crbugskia2820(reporter);
caryclark5ccef572015-03-02 10:07:56 -08004332 test_skbug_3469(reporter);
reed5bcbe912014-12-15 12:28:33 -08004333 test_skbug_3239(reporter);
reed91f283b2015-07-28 06:00:50 -07004334 test_bounds_crbug_513799(reporter);
reed@android.com3abec1d2009-03-02 05:36:20 +00004335}