blob: 964b7e130c3f22d0495e4632fc1cdb129e13cbf0 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
reed@google.comcc8be772013-10-15 15:35:29 +00007
reed@google.com8cae8352012-09-14 15:18:41 +00008#include "SkCanvas.h"
reed@google.com55b5f4b2011-09-07 12:23:41 +00009#include "SkPaint.h"
reed@google.com04863fa2011-05-15 04:08:24 +000010#include "SkParse.h"
reed@google.com3e71a882012-01-10 18:44:37 +000011#include "SkParsePath.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000012#include "SkPath.h"
reed@google.com8b06f1a2012-05-29 12:03:46 +000013#include "SkPathEffect.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000014#include "SkRRect.h"
schenney@chromium.org6630d8d2012-01-04 21:05:51 +000015#include "SkRandom.h"
reed@google.com53effc52011-09-21 19:05:12 +000016#include "SkReader32.h"
reed@android.com60bc6d52010-02-11 11:09:39 +000017#include "SkSize.h"
caryclark66a5d8b2014-06-24 08:30:15 -070018#include "SkStream.h"
reed@google.com8cae8352012-09-14 15:18:41 +000019#include "SkSurface.h"
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000020#include "SkTypes.h"
21#include "SkWriter32.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000022#include "Test.h"
reed@google.com8cae8352012-09-14 15:18:41 +000023
reed5bcbe912014-12-15 12:28:33 -080024static void set_radii(SkVector radii[4], int index, float rad) {
25 sk_bzero(radii, sizeof(SkVector) * 4);
26 radii[index].set(rad, rad);
27}
28
29static void test_add_rrect(skiatest::Reporter* reporter, const SkRect& bounds,
30 const SkVector radii[4]) {
31 SkRRect rrect;
32 rrect.setRectRadii(bounds, radii);
33 REPORTER_ASSERT(reporter, bounds == rrect.rect());
34
35 SkPath path;
36 // this line should not assert in the debug build (from validate)
37 path.addRRect(rrect);
38 REPORTER_ASSERT(reporter, bounds == path.getBounds());
39}
40
caryclark5ccef572015-03-02 10:07:56 -080041static void test_skbug_3469(skiatest::Reporter* reporter) {
42 SkPath path;
43 path.moveTo(20, 20);
44 path.quadTo(20, 50, 80, 50);
45 path.quadTo(20, 50, 20, 80);
46 REPORTER_ASSERT(reporter, !path.isConvex());
47}
48
reed5bcbe912014-12-15 12:28:33 -080049static void test_skbug_3239(skiatest::Reporter* reporter) {
50 const float min = SkBits2Float(0xcb7f16c8); /* -16717512.000000 */
51 const float max = SkBits2Float(0x4b7f1c1d); /* 16718877.000000 */
52 const float big = SkBits2Float(0x4b7f1bd7); /* 16718807.000000 */
53
54 const float rad = 33436320;
55
56 const SkRect rectx = SkRect::MakeLTRB(min, min, max, big);
57 const SkRect recty = SkRect::MakeLTRB(min, min, big, max);
58
59 SkVector radii[4];
60 for (int i = 0; i < 4; ++i) {
61 set_radii(radii, i, rad);
62 test_add_rrect(reporter, rectx, radii);
63 test_add_rrect(reporter, recty, radii);
64 }
65}
66
commit-bot@chromium.org4e332f82014-05-05 16:04:42 +000067static void make_path_crbug364224(SkPath* path) {
68 path->reset();
69 path->moveTo(3.747501373f, 2.724499941f);
70 path->lineTo(3.747501373f, 3.75f);
71 path->cubicTo(3.747501373f, 3.88774991f, 3.635501385f, 4.0f, 3.497501373f, 4.0f);
72 path->lineTo(0.7475013733f, 4.0f);
73 path->cubicTo(0.6095013618f, 4.0f, 0.4975013733f, 3.88774991f, 0.4975013733f, 3.75f);
74 path->lineTo(0.4975013733f, 1.0f);
75 path->cubicTo(0.4975013733f, 0.8622499704f, 0.6095013618f, 0.75f, 0.7475013733f,0.75f);
76 path->lineTo(3.497501373f, 0.75f);
77 path->cubicTo(3.50275135f, 0.75f, 3.5070014f, 0.7527500391f, 3.513001442f, 0.753000021f);
78 path->lineTo(3.715001345f, 0.5512499809f);
79 path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
80 path->lineTo(0.7475013733f, 0.4999999702f);
81 path->cubicTo(0.4715013802f, 0.4999999702f, 0.2475013733f, 0.7239999771f, 0.2475013733f, 1.0f);
82 path->lineTo(0.2475013733f, 3.75f);
83 path->cubicTo(0.2475013733f, 4.026000023f, 0.4715013504f, 4.25f, 0.7475013733f, 4.25f);
84 path->lineTo(3.497501373f, 4.25f);
85 path->cubicTo(3.773501396f, 4.25f, 3.997501373f, 4.026000023f, 3.997501373f, 3.75f);
86 path->lineTo(3.997501373f, 2.474750042f);
87 path->lineTo(3.747501373f, 2.724499941f);
88 path->close();
89}
90
91static void make_path_crbug364224_simplified(SkPath* path) {
92 path->moveTo(3.747501373f, 2.724499941f);
93 path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
94 path->close();
95}
96
97static void test_path_crbug364224() {
98 SkPath path;
99 SkPaint paint;
reed3054be12014-12-10 07:24:28 -0800100 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(84, 88));
commit-bot@chromium.org4e332f82014-05-05 16:04:42 +0000101 SkCanvas* canvas = surface->getCanvas();
102
103 make_path_crbug364224_simplified(&path);
104 canvas->drawPath(path, paint);
105
106 make_path_crbug364224(&path);
107 canvas->drawPath(path, paint);
108}
109
piotaixrfac4e0e2014-08-26 11:59:04 -0700110/**
111 * In debug mode, this path was causing an assertion to fail in
112 * SkPathStroker::preJoinTo() and, in Release, the use of an unitialized value.
113 */
114static void make_path_crbugskia2820(SkPath* path, skiatest::Reporter* reporter) {
115 SkPoint orig, p1, p2, p3;
116 orig = SkPoint::Make(1.f, 1.f);
117 p1 = SkPoint::Make(1.f - SK_ScalarNearlyZero, 1.f);
118 p2 = SkPoint::Make(1.f, 1.f + SK_ScalarNearlyZero);
119 p3 = SkPoint::Make(2.f, 2.f);
120
121 path->reset();
122 path->moveTo(orig);
123 path->cubicTo(p1, p2, p3);
124 path->close();
125}
126
127static void test_path_crbugskia2820(skiatest::Reporter* reporter) {//GrContext* context) {
128 SkPath path;
129 make_path_crbugskia2820(&path, reporter);
130
131 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
132 stroke.setStrokeStyle(2 * SK_Scalar1);
133 stroke.applyToPath(&path, path);
134}
135
reed@google.comcc8be772013-10-15 15:35:29 +0000136static void make_path0(SkPath* path) {
137 // from * https://code.google.com/p/skia/issues/detail?id=1706
138
139 path->moveTo(146.939f, 1012.84f);
140 path->lineTo(181.747f, 1009.18f);
141 path->lineTo(182.165f, 1013.16f);
142 path->lineTo(147.357f, 1016.82f);
143 path->lineTo(146.939f, 1012.84f);
144 path->close();
145}
146
147static void make_path1(SkPath* path) {
148 path->addRect(SkRect::MakeXYWH(10, 10, 10, 1));
149}
150
151typedef void (*PathProc)(SkPath*);
152
153/*
154 * Regression test: we used to crash (overwrite internal storage) during
155 * construction of the region when the path was INVERSE. That is now fixed,
156 * so test these regions (which used to assert/crash).
157 *
158 * https://code.google.com/p/skia/issues/detail?id=1706
159 */
160static void test_path_to_region(skiatest::Reporter* reporter) {
161 PathProc procs[] = {
162 make_path0,
163 make_path1,
164 };
skia.committer@gmail.com47262912013-10-16 07:02:24 +0000165
reed@google.comcc8be772013-10-15 15:35:29 +0000166 SkRegion clip;
167 clip.setRect(0, 0, 1255, 1925);
skia.committer@gmail.com47262912013-10-16 07:02:24 +0000168
reed@google.comcc8be772013-10-15 15:35:29 +0000169 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
170 SkPath path;
171 procs[i](&path);
skia.committer@gmail.com47262912013-10-16 07:02:24 +0000172
reed@google.comcc8be772013-10-15 15:35:29 +0000173 SkRegion rgn;
174 rgn.setPath(path, clip);
175 path.toggleInverseFillType();
176 rgn.setPath(path, clip);
177 }
178}
179
caryclark@google.com56f233a2012-11-19 13:06:06 +0000180#if defined(WIN32)
181 #define SUPPRESS_VISIBILITY_WARNING
182#else
183 #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
184#endif
185
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +0000186static void test_path_close_issue1474(skiatest::Reporter* reporter) {
187 // This test checks that r{Line,Quad,Conic,Cubic}To following a close()
188 // are relative to the point we close to, not relative to the point we close from.
189 SkPath path;
190 SkPoint last;
191
192 // Test rLineTo().
193 path.rLineTo(0, 100);
194 path.rLineTo(100, 0);
195 path.close(); // Returns us back to 0,0.
196 path.rLineTo(50, 50); // This should go to 50,50.
197
198 path.getLastPt(&last);
199 REPORTER_ASSERT(reporter, 50 == last.fX);
200 REPORTER_ASSERT(reporter, 50 == last.fY);
201
202 // Test rQuadTo().
203 path.rewind();
204 path.rLineTo(0, 100);
205 path.rLineTo(100, 0);
206 path.close();
207 path.rQuadTo(50, 50, 75, 75);
208
209 path.getLastPt(&last);
210 REPORTER_ASSERT(reporter, 75 == last.fX);
211 REPORTER_ASSERT(reporter, 75 == last.fY);
212
213 // Test rConicTo().
214 path.rewind();
215 path.rLineTo(0, 100);
216 path.rLineTo(100, 0);
217 path.close();
218 path.rConicTo(50, 50, 85, 85, 2);
219
220 path.getLastPt(&last);
221 REPORTER_ASSERT(reporter, 85 == last.fX);
222 REPORTER_ASSERT(reporter, 85 == last.fY);
223
224 // Test rCubicTo().
225 path.rewind();
226 path.rLineTo(0, 100);
227 path.rLineTo(100, 0);
228 path.close();
229 path.rCubicTo(50, 50, 85, 85, 95, 95);
230
231 path.getLastPt(&last);
232 REPORTER_ASSERT(reporter, 95 == last.fX);
233 REPORTER_ASSERT(reporter, 95 == last.fY);
234}
235
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000236static void test_gen_id(skiatest::Reporter* reporter) {
237 SkPath a, b;
238 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
239
240 a.moveTo(0, 0);
241 const uint32_t z = a.getGenerationID();
242 REPORTER_ASSERT(reporter, z != b.getGenerationID());
243
244 a.reset();
245 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
246
247 a.moveTo(1, 1);
248 const uint32_t y = a.getGenerationID();
249 REPORTER_ASSERT(reporter, z != y);
250
251 b.moveTo(2, 2);
252 const uint32_t x = b.getGenerationID();
253 REPORTER_ASSERT(reporter, x != y && x != z);
254
255 a.swap(b);
256 REPORTER_ASSERT(reporter, b.getGenerationID() == y && a.getGenerationID() == x);
257
258 b = a;
259 REPORTER_ASSERT(reporter, b.getGenerationID() == x);
260
261 SkPath c(a);
262 REPORTER_ASSERT(reporter, c.getGenerationID() == x);
263
264 c.lineTo(3, 3);
265 const uint32_t w = c.getGenerationID();
266 REPORTER_ASSERT(reporter, b.getGenerationID() == x);
267 REPORTER_ASSERT(reporter, a.getGenerationID() == x);
268 REPORTER_ASSERT(reporter, w != x);
269
djsollen50da1d82015-02-17 09:09:53 -0800270#ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000271 static bool kExpectGenIDToIgnoreFill = false;
272#else
273 static bool kExpectGenIDToIgnoreFill = true;
274#endif
275
276 c.toggleInverseFillType();
277 const uint32_t v = c.getGenerationID();
278 REPORTER_ASSERT(reporter, (v == w) == kExpectGenIDToIgnoreFill);
279
280 c.rewind();
281 REPORTER_ASSERT(reporter, v != c.getGenerationID());
282}
283
reed@google.com3eff3592013-05-08 21:08:21 +0000284// This used to assert in the debug build, as the edges did not all line-up.
285static void test_bad_cubic_crbug234190() {
286 SkPath path;
287 path.moveTo(13.8509f, 3.16858f);
288 path.cubicTo(-2.35893e+08f, -4.21044e+08f,
289 -2.38991e+08f, -4.26573e+08f,
290 -2.41016e+08f, -4.30188e+08f);
291
292 SkPaint paint;
293 paint.setAntiAlias(true);
reed3054be12014-12-10 07:24:28 -0800294 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(84, 88));
reed@google.com3eff3592013-05-08 21:08:21 +0000295 surface->getCanvas()->drawPath(path, paint);
296}
297
reed@google.com7a90daf2013-04-10 18:44:00 +0000298static void test_bad_cubic_crbug229478() {
299 const SkPoint pts[] = {
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000300 { 4595.91064f, -11596.9873f },
301 { 4597.2168f, -11595.9414f },
302 { 4598.52344f, -11594.8955f },
303 { 4599.83008f, -11593.8496f },
reed@google.com7a90daf2013-04-10 18:44:00 +0000304 };
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000305
reed@google.com7a90daf2013-04-10 18:44:00 +0000306 SkPath path;
307 path.moveTo(pts[0]);
308 path.cubicTo(pts[1], pts[2], pts[3]);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000309
reed@google.com7a90daf2013-04-10 18:44:00 +0000310 SkPaint paint;
311 paint.setStyle(SkPaint::kStroke_Style);
312 paint.setStrokeWidth(20);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000313
reed@google.com7a90daf2013-04-10 18:44:00 +0000314 SkPath dst;
315 // Before the fix, this would infinite-recurse, and run out of stack
316 // because we would keep trying to subdivide a degenerate cubic segment.
317 paint.getFillPath(path, &dst, NULL);
318}
319
reed@google.com64d62952013-01-18 17:49:28 +0000320static void build_path_170666(SkPath& path) {
321 path.moveTo(17.9459f, 21.6344f);
322 path.lineTo(139.545f, -47.8105f);
323 path.lineTo(139.545f, -47.8105f);
324 path.lineTo(131.07f, -47.3888f);
325 path.lineTo(131.07f, -47.3888f);
326 path.lineTo(122.586f, -46.9532f);
327 path.lineTo(122.586f, -46.9532f);
328 path.lineTo(18076.6f, 31390.9f);
329 path.lineTo(18076.6f, 31390.9f);
330 path.lineTo(18085.1f, 31390.5f);
331 path.lineTo(18085.1f, 31390.5f);
332 path.lineTo(18076.6f, 31390.9f);
333 path.lineTo(18076.6f, 31390.9f);
334 path.lineTo(17955, 31460.3f);
335 path.lineTo(17955, 31460.3f);
336 path.lineTo(17963.5f, 31459.9f);
337 path.lineTo(17963.5f, 31459.9f);
338 path.lineTo(17971.9f, 31459.5f);
339 path.lineTo(17971.9f, 31459.5f);
340 path.lineTo(17.9551f, 21.6205f);
341 path.lineTo(17.9551f, 21.6205f);
342 path.lineTo(9.47091f, 22.0561f);
343 path.lineTo(9.47091f, 22.0561f);
344 path.lineTo(17.9459f, 21.6344f);
345 path.lineTo(17.9459f, 21.6344f);
346 path.close();path.moveTo(0.995934f, 22.4779f);
347 path.lineTo(0.986725f, 22.4918f);
348 path.lineTo(0.986725f, 22.4918f);
349 path.lineTo(17955, 31460.4f);
350 path.lineTo(17955, 31460.4f);
351 path.lineTo(17971.9f, 31459.5f);
352 path.lineTo(17971.9f, 31459.5f);
353 path.lineTo(18093.6f, 31390.1f);
354 path.lineTo(18093.6f, 31390.1f);
355 path.lineTo(18093.6f, 31390);
356 path.lineTo(18093.6f, 31390);
357 path.lineTo(139.555f, -47.8244f);
358 path.lineTo(139.555f, -47.8244f);
359 path.lineTo(122.595f, -46.9671f);
360 path.lineTo(122.595f, -46.9671f);
361 path.lineTo(0.995934f, 22.4779f);
362 path.lineTo(0.995934f, 22.4779f);
363 path.close();
364 path.moveTo(5.43941f, 25.5223f);
365 path.lineTo(798267, -28871.1f);
366 path.lineTo(798267, -28871.1f);
367 path.lineTo(3.12512e+06f, -113102);
368 path.lineTo(3.12512e+06f, -113102);
369 path.cubicTo(5.16324e+06f, -186882, 8.15247e+06f, -295092, 1.1957e+07f, -432813);
370 path.cubicTo(1.95659e+07f, -708257, 3.04359e+07f, -1.10175e+06f, 4.34798e+07f, -1.57394e+06f);
371 path.cubicTo(6.95677e+07f, -2.51831e+06f, 1.04352e+08f, -3.77748e+06f, 1.39135e+08f, -5.03666e+06f);
372 path.cubicTo(1.73919e+08f, -6.29583e+06f, 2.08703e+08f, -7.555e+06f, 2.34791e+08f, -8.49938e+06f);
373 path.cubicTo(2.47835e+08f, -8.97157e+06f, 2.58705e+08f, -9.36506e+06f, 2.66314e+08f, -9.6405e+06f);
374 path.cubicTo(2.70118e+08f, -9.77823e+06f, 2.73108e+08f, -9.88644e+06f, 2.75146e+08f, -9.96022e+06f);
375 path.cubicTo(2.76165e+08f, -9.99711e+06f, 2.76946e+08f, -1.00254e+07f, 2.77473e+08f, -1.00444e+07f);
376 path.lineTo(2.78271e+08f, -1.00733e+07f);
377 path.lineTo(2.78271e+08f, -1.00733e+07f);
378 path.cubicTo(2.78271e+08f, -1.00733e+07f, 2.08703e+08f, -7.555e+06f, 135.238f, 23.3517f);
379 path.cubicTo(131.191f, 23.4981f, 125.995f, 23.7976f, 123.631f, 24.0206f);
380 path.cubicTo(121.267f, 24.2436f, 122.631f, 24.3056f, 126.677f, 24.1591f);
381 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
382 path.lineTo(2.77473e+08f, -1.00444e+07f);
383 path.lineTo(2.77473e+08f, -1.00444e+07f);
384 path.cubicTo(2.76946e+08f, -1.00254e+07f, 2.76165e+08f, -9.99711e+06f, 2.75146e+08f, -9.96022e+06f);
385 path.cubicTo(2.73108e+08f, -9.88644e+06f, 2.70118e+08f, -9.77823e+06f, 2.66314e+08f, -9.6405e+06f);
386 path.cubicTo(2.58705e+08f, -9.36506e+06f, 2.47835e+08f, -8.97157e+06f, 2.34791e+08f, -8.49938e+06f);
387 path.cubicTo(2.08703e+08f, -7.555e+06f, 1.73919e+08f, -6.29583e+06f, 1.39135e+08f, -5.03666e+06f);
388 path.cubicTo(1.04352e+08f, -3.77749e+06f, 6.95677e+07f, -2.51831e+06f, 4.34798e+07f, -1.57394e+06f);
389 path.cubicTo(3.04359e+07f, -1.10175e+06f, 1.95659e+07f, -708258, 1.1957e+07f, -432814);
390 path.cubicTo(8.15248e+06f, -295092, 5.16324e+06f, -186883, 3.12513e+06f, -113103);
391 path.lineTo(798284, -28872);
392 path.lineTo(798284, -28872);
393 path.lineTo(22.4044f, 24.6677f);
394 path.lineTo(22.4044f, 24.6677f);
395 path.cubicTo(22.5186f, 24.5432f, 18.8134f, 24.6337f, 14.1287f, 24.8697f);
396 path.cubicTo(9.4439f, 25.1057f, 5.55359f, 25.3978f, 5.43941f, 25.5223f);
397 path.close();
398}
399
400static void build_path_simple_170666(SkPath& path) {
401 path.moveTo(126.677f, 24.1591f);
402 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
403}
404
405// This used to assert in the SK_DEBUG build, as the clip step would fail with
406// too-few interations in our cubic-line intersection code. That code now runs
407// 24 interations (instead of 16).
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000408static void test_crbug_170666() {
reed@google.com64d62952013-01-18 17:49:28 +0000409 SkPath path;
410 SkPaint paint;
411 paint.setAntiAlias(true);
412
reed3054be12014-12-10 07:24:28 -0800413 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1000, 1000));
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000414
reed@google.com64d62952013-01-18 17:49:28 +0000415 build_path_simple_170666(path);
416 surface->getCanvas()->drawPath(path, paint);
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000417
reed@google.com64d62952013-01-18 17:49:28 +0000418 build_path_170666(path);
419 surface->getCanvas()->drawPath(path, paint);
420}
421
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000422static void test_addrect(skiatest::Reporter* reporter) {
423 SkPath path;
424 path.lineTo(0, 0);
425 path.addRect(SkRect::MakeWH(50, 100));
426 REPORTER_ASSERT(reporter, path.isRect(NULL));
427
428 path.reset();
429 path.lineTo(FLT_EPSILON, FLT_EPSILON);
430 path.addRect(SkRect::MakeWH(50, 100));
431 REPORTER_ASSERT(reporter, !path.isRect(NULL));
432
433 path.reset();
434 path.quadTo(0, 0, 0, 0);
435 path.addRect(SkRect::MakeWH(50, 100));
436 REPORTER_ASSERT(reporter, !path.isRect(NULL));
437
438 path.reset();
439 path.conicTo(0, 0, 0, 0, 0.5f);
440 path.addRect(SkRect::MakeWH(50, 100));
441 REPORTER_ASSERT(reporter, !path.isRect(NULL));
442
443 path.reset();
444 path.cubicTo(0, 0, 0, 0, 0, 0);
445 path.addRect(SkRect::MakeWH(50, 100));
446 REPORTER_ASSERT(reporter, !path.isRect(NULL));
447}
448
reed@google.coma8790de2012-10-24 21:04:04 +0000449// Make sure we stay non-finite once we get there (unless we reset or rewind).
450static void test_addrect_isfinite(skiatest::Reporter* reporter) {
451 SkPath path;
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000452
reed@google.coma8790de2012-10-24 21:04:04 +0000453 path.addRect(SkRect::MakeWH(50, 100));
454 REPORTER_ASSERT(reporter, path.isFinite());
455
456 path.moveTo(0, 0);
457 path.lineTo(SK_ScalarInfinity, 42);
458 REPORTER_ASSERT(reporter, !path.isFinite());
459
460 path.addRect(SkRect::MakeWH(50, 100));
461 REPORTER_ASSERT(reporter, !path.isFinite());
462
463 path.reset();
464 REPORTER_ASSERT(reporter, path.isFinite());
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000465
reed@google.coma8790de2012-10-24 21:04:04 +0000466 path.addRect(SkRect::MakeWH(50, 100));
467 REPORTER_ASSERT(reporter, path.isFinite());
468}
469
reed@google.com848148e2013-01-15 15:51:59 +0000470static void build_big_path(SkPath* path, bool reducedCase) {
471 if (reducedCase) {
472 path->moveTo(577330, 1971.72f);
473 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
474 } else {
475 path->moveTo(60.1631f, 7.70567f);
476 path->quadTo(60.1631f, 7.70567f, 0.99474f, 0.901199f);
477 path->lineTo(577379, 1977.77f);
478 path->quadTo(577364, 1979.57f, 577325, 1980.26f);
479 path->quadTo(577286, 1980.95f, 577245, 1980.13f);
480 path->quadTo(577205, 1979.3f, 577187, 1977.45f);
481 path->quadTo(577168, 1975.6f, 577183, 1973.8f);
482 path->quadTo(577198, 1972, 577238, 1971.31f);
483 path->quadTo(577277, 1970.62f, 577317, 1971.45f);
484 path->quadTo(577330, 1971.72f, 577341, 1972.11f);
485 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
486 path->moveTo(306.718f, -32.912f);
487 path->cubicTo(30.531f, 10.0005f, 1502.47f, 13.2804f, 84.3088f, 9.99601f);
488 }
489}
490
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000491static void test_clipped_cubic() {
reed3054be12014-12-10 07:24:28 -0800492 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
reed@google.com848148e2013-01-15 15:51:59 +0000493
494 // This path used to assert, because our cubic-chopping code incorrectly
495 // moved control points after the chop. This test should be run in SK_DEBUG
496 // mode to ensure that we no long assert.
497 SkPath path;
498 for (int doReducedCase = 0; doReducedCase <= 1; ++doReducedCase) {
499 build_big_path(&path, SkToBool(doReducedCase));
skia.committer@gmail.comff21c2e2013-01-16 07:05:56 +0000500
reed@google.com848148e2013-01-15 15:51:59 +0000501 SkPaint paint;
502 for (int doAA = 0; doAA <= 1; ++doAA) {
503 paint.setAntiAlias(SkToBool(doAA));
504 surface->getCanvas()->drawPath(path, paint);
505 }
506 }
507}
508
reed@google.com8cae8352012-09-14 15:18:41 +0000509// Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/
510// which triggered an assert, from a tricky cubic. This test replicates that
511// example, so we can ensure that we handle it (in SkEdge.cpp), and don't
512// assert in the SK_DEBUG build.
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000513static void test_tricky_cubic() {
reed@google.com8cae8352012-09-14 15:18:41 +0000514 const SkPoint pts[] = {
skia.committer@gmail.com055c7c22012-09-15 02:01:41 +0000515 { SkDoubleToScalar(18.8943768), SkDoubleToScalar(129.121277) },
516 { SkDoubleToScalar(18.8937435), SkDoubleToScalar(129.121689) },
517 { SkDoubleToScalar(18.8950119), SkDoubleToScalar(129.120422) },
518 { SkDoubleToScalar(18.5030727), SkDoubleToScalar(129.13121) },
reed@google.com8cae8352012-09-14 15:18:41 +0000519 };
520
521 SkPath path;
522 path.moveTo(pts[0]);
523 path.cubicTo(pts[1], pts[2], pts[3]);
524
525 SkPaint paint;
526 paint.setAntiAlias(true);
527
reed3054be12014-12-10 07:24:28 -0800528 SkSurface* surface = SkSurface::NewRasterN32Premul(19, 130);
reed@google.com8cae8352012-09-14 15:18:41 +0000529 surface->getCanvas()->drawPath(path, paint);
530 surface->unref();
531}
reed@android.com3abec1d2009-03-02 05:36:20 +0000532
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000533// Inspired by http://code.google.com/p/chromium/issues/detail?id=141651
534//
535static void test_isfinite_after_transform(skiatest::Reporter* reporter) {
536 SkPath path;
537 path.quadTo(157, 366, 286, 208);
538 path.arcTo(37, 442, 315, 163, 957494590897113.0f);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000539
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000540 SkMatrix matrix;
541 matrix.setScale(1000*1000, 1000*1000);
542
543 // Be sure that path::transform correctly updates isFinite and the bounds
544 // if the transformation overflows. The previous bug was that isFinite was
545 // set to true in this case, but the bounds were not set to empty (which
546 // they should be).
547 while (path.isFinite()) {
548 REPORTER_ASSERT(reporter, path.getBounds().isFinite());
549 REPORTER_ASSERT(reporter, !path.getBounds().isEmpty());
550 path.transform(matrix);
551 }
552 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
553
554 matrix.setTranslate(SK_Scalar1, SK_Scalar1);
555 path.transform(matrix);
556 // we need to still be non-finite
557 REPORTER_ASSERT(reporter, !path.isFinite());
558 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
559}
560
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000561static void add_corner_arc(SkPath* path, const SkRect& rect,
562 SkScalar xIn, SkScalar yIn,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000563 int startAngle)
564{
565
566 SkScalar rx = SkMinScalar(rect.width(), xIn);
567 SkScalar ry = SkMinScalar(rect.height(), yIn);
568
569 SkRect arcRect;
570 arcRect.set(-rx, -ry, rx, ry);
571 switch (startAngle) {
572 case 0:
573 arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom);
574 break;
575 case 90:
576 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom);
577 break;
578 case 180:
579 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop);
580 break;
581 case 270:
582 arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop);
583 break;
584 default:
585 break;
586 }
587
588 path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false);
589}
590
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000591static void make_arb_round_rect(SkPath* path, const SkRect& r,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000592 SkScalar xCorner, SkScalar yCorner) {
593 // we are lazy here and use the same x & y for each corner
594 add_corner_arc(path, r, xCorner, yCorner, 270);
595 add_corner_arc(path, r, xCorner, yCorner, 0);
596 add_corner_arc(path, r, xCorner, yCorner, 90);
597 add_corner_arc(path, r, xCorner, yCorner, 180);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000598 path->close();
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000599}
600
601// Chrome creates its own round rects with each corner possibly being different.
602// Performance will suffer if they are not convex.
603// Note: PathBench::ArbRoundRectBench performs almost exactly
604// the same test (but with drawing)
605static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000606 SkRandom rand;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000607 SkRect r;
608
609 for (int i = 0; i < 5000; ++i) {
610
robertphillips@google.com158618e2012-10-23 16:56:56 +0000611 SkScalar size = rand.nextUScalar1() * 30;
612 if (size < SK_Scalar1) {
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000613 continue;
614 }
615 r.fLeft = rand.nextUScalar1() * 300;
616 r.fTop = rand.nextUScalar1() * 300;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000617 r.fRight = r.fLeft + 2 * size;
618 r.fBottom = r.fTop + 2 * size;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000619
620 SkPath temp;
621
622 make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
623
624 REPORTER_ASSERT(reporter, temp.isConvex());
625 }
626}
627
robertphillips@google.com158618e2012-10-23 16:56:56 +0000628// Chrome will sometimes create a 0 radius round rect. The degenerate
629// quads prevent the path from being converted to a rect
630// Note: PathBench::ArbRoundRectBench performs almost exactly
631// the same test (but with drawing)
632static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000633 SkRandom rand;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000634 SkRect r;
635
636 for (int i = 0; i < 5000; ++i) {
637
638 SkScalar size = rand.nextUScalar1() * 30;
639 if (size < SK_Scalar1) {
640 continue;
641 }
642 r.fLeft = rand.nextUScalar1() * 300;
643 r.fTop = rand.nextUScalar1() * 300;
644 r.fRight = r.fLeft + 2 * size;
645 r.fBottom = r.fTop + 2 * size;
646
647 SkPath temp;
648
649 make_arb_round_rect(&temp, r, 0, 0);
650
robertphillips@google.com158618e2012-10-23 16:56:56 +0000651 SkRect result;
652 REPORTER_ASSERT(reporter, temp.isRect(&result));
653 REPORTER_ASSERT(reporter, r == result);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000654 }
655}
656
reed@google.com0bb18bb2012-07-26 15:20:36 +0000657static void test_rect_isfinite(skiatest::Reporter* reporter) {
658 const SkScalar inf = SK_ScalarInfinity;
caryclark@google.com7abfa492013-04-12 11:59:41 +0000659 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000660 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000661
reed@google.com0bb18bb2012-07-26 15:20:36 +0000662 SkRect r;
663 r.setEmpty();
664 REPORTER_ASSERT(reporter, r.isFinite());
caryclark@google.com7abfa492013-04-12 11:59:41 +0000665 r.set(0, 0, inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000666 REPORTER_ASSERT(reporter, !r.isFinite());
667 r.set(0, 0, nan, 0);
668 REPORTER_ASSERT(reporter, !r.isFinite());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000669
reed@google.com0bb18bb2012-07-26 15:20:36 +0000670 SkPoint pts[] = {
671 { 0, 0 },
672 { SK_Scalar1, 0 },
673 { 0, SK_Scalar1 },
674 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000675
reed@google.com0bb18bb2012-07-26 15:20:36 +0000676 bool isFine = r.setBoundsCheck(pts, 3);
677 REPORTER_ASSERT(reporter, isFine);
678 REPORTER_ASSERT(reporter, !r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000679
reed@google.com0bb18bb2012-07-26 15:20:36 +0000680 pts[1].set(inf, 0);
681 isFine = r.setBoundsCheck(pts, 3);
682 REPORTER_ASSERT(reporter, !isFine);
683 REPORTER_ASSERT(reporter, r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000684
reed@google.com0bb18bb2012-07-26 15:20:36 +0000685 pts[1].set(nan, 0);
686 isFine = r.setBoundsCheck(pts, 3);
687 REPORTER_ASSERT(reporter, !isFine);
688 REPORTER_ASSERT(reporter, r.isEmpty());
689}
690
691static void test_path_isfinite(skiatest::Reporter* reporter) {
692 const SkScalar inf = SK_ScalarInfinity;
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000693 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000694 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000695
reed@google.com0bb18bb2012-07-26 15:20:36 +0000696 SkPath path;
697 REPORTER_ASSERT(reporter, path.isFinite());
698
699 path.reset();
700 REPORTER_ASSERT(reporter, path.isFinite());
701
702 path.reset();
703 path.moveTo(SK_Scalar1, 0);
704 REPORTER_ASSERT(reporter, path.isFinite());
705
706 path.reset();
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000707 path.moveTo(inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000708 REPORTER_ASSERT(reporter, !path.isFinite());
709
710 path.reset();
711 path.moveTo(nan, 0);
712 REPORTER_ASSERT(reporter, !path.isFinite());
713}
714
715static void test_isfinite(skiatest::Reporter* reporter) {
716 test_rect_isfinite(reporter);
717 test_path_isfinite(reporter);
718}
719
reed@google.com744faba2012-05-29 19:54:52 +0000720// assert that we always
721// start with a moveTo
722// only have 1 moveTo
723// only have Lines after that
724// end with a single close
725// only have (at most) 1 close
726//
727static void test_poly(skiatest::Reporter* reporter, const SkPath& path,
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000728 const SkPoint srcPts[], bool expectClose) {
reed@google.com744faba2012-05-29 19:54:52 +0000729 SkPath::RawIter iter(path);
730 SkPoint pts[4];
reed@google.com744faba2012-05-29 19:54:52 +0000731
732 bool firstTime = true;
733 bool foundClose = false;
734 for (;;) {
735 switch (iter.next(pts)) {
736 case SkPath::kMove_Verb:
737 REPORTER_ASSERT(reporter, firstTime);
738 REPORTER_ASSERT(reporter, pts[0] == srcPts[0]);
739 srcPts++;
740 firstTime = false;
741 break;
742 case SkPath::kLine_Verb:
743 REPORTER_ASSERT(reporter, !firstTime);
744 REPORTER_ASSERT(reporter, pts[1] == srcPts[0]);
745 srcPts++;
746 break;
747 case SkPath::kQuad_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000748 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected quad verb");
reed@google.com744faba2012-05-29 19:54:52 +0000749 break;
reed@google.com277c3f82013-05-31 15:17:50 +0000750 case SkPath::kConic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000751 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected conic verb");
reed@google.com277c3f82013-05-31 15:17:50 +0000752 break;
reed@google.com744faba2012-05-29 19:54:52 +0000753 case SkPath::kCubic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000754 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected cubic verb");
reed@google.com744faba2012-05-29 19:54:52 +0000755 break;
756 case SkPath::kClose_Verb:
757 REPORTER_ASSERT(reporter, !firstTime);
758 REPORTER_ASSERT(reporter, !foundClose);
759 REPORTER_ASSERT(reporter, expectClose);
760 foundClose = true;
761 break;
762 case SkPath::kDone_Verb:
763 goto DONE;
764 }
765 }
766DONE:
767 REPORTER_ASSERT(reporter, foundClose == expectClose);
768}
769
770static void test_addPoly(skiatest::Reporter* reporter) {
771 SkPoint pts[32];
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000772 SkRandom rand;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000773
reed@google.com744faba2012-05-29 19:54:52 +0000774 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
775 pts[i].fX = rand.nextSScalar1();
776 pts[i].fY = rand.nextSScalar1();
777 }
778
779 for (int doClose = 0; doClose <= 1; ++doClose) {
780 for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) {
781 SkPath path;
bsalomon98806072014-12-12 15:11:17 -0800782 path.addPoly(pts, SkToInt(count), SkToBool(doClose));
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000783 test_poly(reporter, path, pts, SkToBool(doClose));
reed@google.com744faba2012-05-29 19:54:52 +0000784 }
785 }
786}
787
reed@google.com8b06f1a2012-05-29 12:03:46 +0000788static void test_strokerec(skiatest::Reporter* reporter) {
789 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
790 REPORTER_ASSERT(reporter, rec.isFillStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000791
reed@google.com8b06f1a2012-05-29 12:03:46 +0000792 rec.setHairlineStyle();
793 REPORTER_ASSERT(reporter, rec.isHairlineStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000794
reed@google.com8b06f1a2012-05-29 12:03:46 +0000795 rec.setStrokeStyle(SK_Scalar1, false);
796 REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000797
reed@google.com8b06f1a2012-05-29 12:03:46 +0000798 rec.setStrokeStyle(SK_Scalar1, true);
799 REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000800
reed@google.com8b06f1a2012-05-29 12:03:46 +0000801 rec.setStrokeStyle(0, false);
802 REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000803
reed@google.com8b06f1a2012-05-29 12:03:46 +0000804 rec.setStrokeStyle(0, true);
805 REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle());
806}
807
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000808// Set this for paths that don't have a consistent direction such as a bowtie.
809// (cheapComputeDirection is not expected to catch these.)
810static const SkPath::Direction kDontCheckDir = static_cast<SkPath::Direction>(-1);
811
812static void check_direction(skiatest::Reporter* reporter, const SkPath& path,
813 SkPath::Direction expected) {
814 if (expected == kDontCheckDir) {
815 return;
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000816 }
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000817 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
818
819 SkPath::Direction dir;
820 if (copy.cheapComputeDirection(&dir)) {
821 REPORTER_ASSERT(reporter, dir == expected);
822 } else {
823 REPORTER_ASSERT(reporter, SkPath::kUnknown_Direction == expected);
824 }
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000825}
826
reed@google.com3e71a882012-01-10 18:44:37 +0000827static void test_direction(skiatest::Reporter* reporter) {
828 size_t i;
829 SkPath path;
830 REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
831 REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCW_Direction));
832 REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCCW_Direction));
reed@google.coma8a3b3d2012-11-26 18:16:27 +0000833 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kUnknown_Direction));
reed@google.com3e71a882012-01-10 18:44:37 +0000834
835 static const char* gDegen[] = {
836 "M 10 10",
837 "M 10 10 M 20 20",
838 "M 10 10 L 20 20",
839 "M 10 10 L 10 10 L 10 10",
840 "M 10 10 Q 10 10 10 10",
841 "M 10 10 C 10 10 10 10 10 10",
842 };
843 for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) {
844 path.reset();
845 bool valid = SkParsePath::FromSVGString(gDegen[i], &path);
846 REPORTER_ASSERT(reporter, valid);
847 REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
848 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000849
reed@google.com3e71a882012-01-10 18:44:37 +0000850 static const char* gCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000851 "M 10 10 L 10 10 Q 20 10 20 20",
reed@google.com3e71a882012-01-10 18:44:37 +0000852 "M 10 10 C 20 10 20 20 20 20",
reed@google.comd4146662012-01-31 15:42:29 +0000853 "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 +0000854 // rect with top two corners replaced by cubics with identical middle
855 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000856 "M 10 10 C 10 0 10 0 20 0 L 40 0 C 50 0 50 0 50 10",
857 "M 20 10 L 0 10 Q 10 10 20 0", // left, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000858 };
859 for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) {
860 path.reset();
861 bool valid = SkParsePath::FromSVGString(gCW[i], &path);
862 REPORTER_ASSERT(reporter, valid);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000863 check_direction(reporter, path, SkPath::kCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000864 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000865
reed@google.com3e71a882012-01-10 18:44:37 +0000866 static const char* gCCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000867 "M 10 10 L 10 10 Q 20 10 20 -20",
reed@google.com3e71a882012-01-10 18:44:37 +0000868 "M 10 10 C 20 10 20 -20 20 -20",
reed@google.comd4146662012-01-31 15:42:29 +0000869 "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 +0000870 // rect with top two corners replaced by cubics with identical middle
871 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000872 "M 50 10 C 50 0 50 0 40 0 L 20 0 C 10 0 10 0 10 10",
873 "M 10 10 L 30 10 Q 20 10 10 0", // right, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000874 };
875 for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) {
876 path.reset();
877 bool valid = SkParsePath::FromSVGString(gCCW[i], &path);
878 REPORTER_ASSERT(reporter, valid);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000879 check_direction(reporter, path, SkPath::kCCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000880 }
reed@google.comac8543f2012-01-30 20:51:25 +0000881
882 // Test two donuts, each wound a different direction. Only the outer contour
883 // determines the cheap direction
884 path.reset();
885 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCW_Direction);
886 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000887 check_direction(reporter, path, SkPath::kCW_Direction);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000888
reed@google.comac8543f2012-01-30 20:51:25 +0000889 path.reset();
890 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCW_Direction);
891 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000892 check_direction(reporter, path, SkPath::kCCW_Direction);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000893
894 // triangle with one point really far from the origin.
895 path.reset();
896 // the first point is roughly 1.05e10, 1.05e10
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +0000897 path.moveTo(SkBits2Float(0x501c7652), SkBits2Float(0x501c7652));
bsalomon@google.com53aab782012-02-23 14:54:49 +0000898 path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1);
899 path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000900 check_direction(reporter, path, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000901
902 path.reset();
903 path.conicTo(20, 0, 20, 20, 0.5f);
904 path.close();
905 check_direction(reporter, path, SkPath::kCW_Direction);
906
907 path.reset();
908 path.lineTo(1, 1e7f);
909 path.lineTo(1e7f, 2e7f);
910 path.close();
911 REPORTER_ASSERT(reporter, SkPath::kConvex_Convexity == path.getConvexity());
912 check_direction(reporter, path, SkPath::kCCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000913}
914
reed@google.comffdb0182011-11-14 19:29:14 +0000915static void add_rect(SkPath* path, const SkRect& r) {
916 path->moveTo(r.fLeft, r.fTop);
917 path->lineTo(r.fRight, r.fTop);
918 path->lineTo(r.fRight, r.fBottom);
919 path->lineTo(r.fLeft, r.fBottom);
920 path->close();
921}
922
923static void test_bounds(skiatest::Reporter* reporter) {
924 static const SkRect rects[] = {
reed@google.com3563c9e2011-11-14 19:34:57 +0000925 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) },
926 { SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) },
927 { SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) },
928 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) },
reed@google.comffdb0182011-11-14 19:29:14 +0000929 };
930
931 SkPath path0, path1;
932 for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) {
933 path0.addRect(rects[i]);
934 add_rect(&path1, rects[i]);
935 }
936
937 REPORTER_ASSERT(reporter, path0.getBounds() == path1.getBounds());
938}
939
reed@google.com55b5f4b2011-09-07 12:23:41 +0000940static void stroke_cubic(const SkPoint pts[4]) {
941 SkPath path;
942 path.moveTo(pts[0]);
943 path.cubicTo(pts[1], pts[2], pts[3]);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000944
reed@google.com55b5f4b2011-09-07 12:23:41 +0000945 SkPaint paint;
946 paint.setStyle(SkPaint::kStroke_Style);
947 paint.setStrokeWidth(SK_Scalar1 * 2);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000948
reed@google.com55b5f4b2011-09-07 12:23:41 +0000949 SkPath fill;
950 paint.getFillPath(path, &fill);
951}
952
953// just ensure this can run w/o any SkASSERTS firing in the debug build
954// we used to assert due to differences in how we determine a degenerate vector
955// but that was fixed with the introduction of SkPoint::CanNormalize
956static void stroke_tiny_cubic() {
957 SkPoint p0[] = {
958 { 372.0f, 92.0f },
959 { 372.0f, 92.0f },
960 { 372.0f, 92.0f },
961 { 372.0f, 92.0f },
962 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000963
reed@google.com55b5f4b2011-09-07 12:23:41 +0000964 stroke_cubic(p0);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000965
reed@google.com55b5f4b2011-09-07 12:23:41 +0000966 SkPoint p1[] = {
967 { 372.0f, 92.0f },
968 { 372.0007f, 92.000755f },
969 { 371.99927f, 92.003922f },
970 { 371.99826f, 92.003899f },
971 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000972
reed@google.com55b5f4b2011-09-07 12:23:41 +0000973 stroke_cubic(p1);
974}
975
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000976static void check_close(skiatest::Reporter* reporter, const SkPath& path) {
977 for (int i = 0; i < 2; ++i) {
robertphillips@google.com09042b82012-04-06 20:01:46 +0000978 SkPath::Iter iter(path, SkToBool(i));
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000979 SkPoint mv;
980 SkPoint pts[4];
981 SkPath::Verb v;
982 int nMT = 0;
983 int nCL = 0;
tomhudson@google.com221db3c2011-07-28 21:10:29 +0000984 mv.set(0, 0);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +0000985 while (SkPath::kDone_Verb != (v = iter.next(pts))) {
986 switch (v) {
987 case SkPath::kMove_Verb:
988 mv = pts[0];
989 ++nMT;
990 break;
991 case SkPath::kClose_Verb:
992 REPORTER_ASSERT(reporter, mv == pts[0]);
993 ++nCL;
994 break;
995 default:
996 break;
997 }
998 }
999 // if we force a close on the interator we should have a close
1000 // for every moveTo
1001 REPORTER_ASSERT(reporter, !i || nMT == nCL);
1002 }
1003}
1004
1005static void test_close(skiatest::Reporter* reporter) {
1006 SkPath closePt;
1007 closePt.moveTo(0, 0);
1008 closePt.close();
1009 check_close(reporter, closePt);
1010
1011 SkPath openPt;
1012 openPt.moveTo(0, 0);
1013 check_close(reporter, openPt);
1014
1015 SkPath empty;
1016 check_close(reporter, empty);
1017 empty.close();
1018 check_close(reporter, empty);
1019
1020 SkPath rect;
1021 rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1022 check_close(reporter, rect);
1023 rect.close();
1024 check_close(reporter, rect);
1025
1026 SkPath quad;
1027 quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1028 check_close(reporter, quad);
1029 quad.close();
1030 check_close(reporter, quad);
1031
1032 SkPath cubic;
rmistry@google.comd6176b02012-08-23 18:14:13 +00001033 quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1,
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001034 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1);
1035 check_close(reporter, cubic);
1036 cubic.close();
1037 check_close(reporter, cubic);
1038
1039 SkPath line;
1040 line.moveTo(SK_Scalar1, SK_Scalar1);
1041 line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1);
1042 check_close(reporter, line);
1043 line.close();
1044 check_close(reporter, line);
1045
1046 SkPath rect2;
1047 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1048 rect2.close();
1049 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1050 check_close(reporter, rect2);
1051 rect2.close();
1052 check_close(reporter, rect2);
1053
1054 SkPath oval3;
1055 oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100));
1056 oval3.close();
1057 oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200));
1058 check_close(reporter, oval3);
1059 oval3.close();
1060 check_close(reporter, oval3);
1061
1062 SkPath moves;
1063 moves.moveTo(SK_Scalar1, SK_Scalar1);
1064 moves.moveTo(5 * SK_Scalar1, SK_Scalar1);
1065 moves.moveTo(SK_Scalar1, 10 * SK_Scalar1);
1066 moves.moveTo(10 *SK_Scalar1, SK_Scalar1);
1067 check_close(reporter, moves);
reed@google.com55b5f4b2011-09-07 12:23:41 +00001068
1069 stroke_tiny_cubic();
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001070}
1071
reed@google.com7c424812011-05-15 04:38:34 +00001072static void check_convexity(skiatest::Reporter* reporter, const SkPath& path,
1073 SkPath::Convexity expected) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001074 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
1075 SkPath::Convexity c = copy.getConvexity();
reed@google.com7c424812011-05-15 04:38:34 +00001076 REPORTER_ASSERT(reporter, c == expected);
1077}
1078
caryclarkb4216502015-03-02 13:02:34 -08001079static void test_path_crbug389050(skiatest::Reporter* reporter) {
1080 SkPath tinyConvexPolygon;
1081 tinyConvexPolygon.moveTo(600.131559f, 800.112512f);
1082 tinyConvexPolygon.lineTo(600.161735f, 800.118627f);
1083 tinyConvexPolygon.lineTo(600.148962f, 800.142338f);
1084 tinyConvexPolygon.lineTo(600.134891f, 800.137724f);
1085 tinyConvexPolygon.close();
1086 tinyConvexPolygon.getConvexity();
1087 check_convexity(reporter, tinyConvexPolygon, SkPath::kConvex_Convexity);
1088 check_direction(reporter, tinyConvexPolygon, SkPath::kCW_Direction);
1089
1090 SkPath platTriangle;
1091 platTriangle.moveTo(0, 0);
1092 platTriangle.lineTo(200, 0);
1093 platTriangle.lineTo(100, 0.04f);
1094 platTriangle.close();
1095 platTriangle.getConvexity();
1096 check_direction(reporter, platTriangle, SkPath::kCW_Direction);
1097
1098 platTriangle.reset();
1099 platTriangle.moveTo(0, 0);
1100 platTriangle.lineTo(200, 0);
1101 platTriangle.lineTo(100, 0.03f);
1102 platTriangle.close();
1103 platTriangle.getConvexity();
1104 check_direction(reporter, platTriangle, SkPath::kCW_Direction);
1105}
1106
reed@google.com7c424812011-05-15 04:38:34 +00001107static void test_convexity2(skiatest::Reporter* reporter) {
1108 SkPath pt;
1109 pt.moveTo(0, 0);
1110 pt.close();
reed@google.comb54455e2011-05-16 14:16:04 +00001111 check_convexity(reporter, pt, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001112 check_direction(reporter, pt, SkPath::kUnknown_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001113
reed@google.com7c424812011-05-15 04:38:34 +00001114 SkPath line;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001115 line.moveTo(12*SK_Scalar1, 20*SK_Scalar1);
1116 line.lineTo(-12*SK_Scalar1, -20*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001117 line.close();
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001118 check_convexity(reporter, line, SkPath::kConvex_Convexity);
1119 check_direction(reporter, line, SkPath::kUnknown_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001120
reed@google.com7c424812011-05-15 04:38:34 +00001121 SkPath triLeft;
1122 triLeft.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001123 triLeft.lineTo(SK_Scalar1, 0);
1124 triLeft.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001125 triLeft.close();
1126 check_convexity(reporter, triLeft, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001127 check_direction(reporter, triLeft, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001128
reed@google.com7c424812011-05-15 04:38:34 +00001129 SkPath triRight;
1130 triRight.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001131 triRight.lineTo(-SK_Scalar1, 0);
1132 triRight.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001133 triRight.close();
1134 check_convexity(reporter, triRight, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001135 check_direction(reporter, triRight, SkPath::kCCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001136
reed@google.com7c424812011-05-15 04:38:34 +00001137 SkPath square;
1138 square.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001139 square.lineTo(SK_Scalar1, 0);
1140 square.lineTo(SK_Scalar1, SK_Scalar1);
1141 square.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001142 square.close();
1143 check_convexity(reporter, square, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001144 check_direction(reporter, square, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001145
reed@google.com7c424812011-05-15 04:38:34 +00001146 SkPath redundantSquare;
1147 redundantSquare.moveTo(0, 0);
1148 redundantSquare.lineTo(0, 0);
1149 redundantSquare.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001150 redundantSquare.lineTo(SK_Scalar1, 0);
1151 redundantSquare.lineTo(SK_Scalar1, 0);
1152 redundantSquare.lineTo(SK_Scalar1, 0);
1153 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1154 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1155 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1156 redundantSquare.lineTo(0, SK_Scalar1);
1157 redundantSquare.lineTo(0, SK_Scalar1);
1158 redundantSquare.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001159 redundantSquare.close();
1160 check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001161 check_direction(reporter, redundantSquare, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001162
reed@google.com7c424812011-05-15 04:38:34 +00001163 SkPath bowTie;
1164 bowTie.moveTo(0, 0);
1165 bowTie.lineTo(0, 0);
1166 bowTie.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001167 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1168 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1169 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1170 bowTie.lineTo(SK_Scalar1, 0);
1171 bowTie.lineTo(SK_Scalar1, 0);
1172 bowTie.lineTo(SK_Scalar1, 0);
1173 bowTie.lineTo(0, SK_Scalar1);
1174 bowTie.lineTo(0, SK_Scalar1);
1175 bowTie.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001176 bowTie.close();
1177 check_convexity(reporter, bowTie, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001178 check_direction(reporter, bowTie, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001179
reed@google.com7c424812011-05-15 04:38:34 +00001180 SkPath spiral;
1181 spiral.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001182 spiral.lineTo(100*SK_Scalar1, 0);
1183 spiral.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1184 spiral.lineTo(0, 100*SK_Scalar1);
1185 spiral.lineTo(0, 50*SK_Scalar1);
1186 spiral.lineTo(50*SK_Scalar1, 50*SK_Scalar1);
1187 spiral.lineTo(50*SK_Scalar1, 75*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001188 spiral.close();
reed@google.com85b6e392011-05-15 20:25:17 +00001189 check_convexity(reporter, spiral, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001190 check_direction(reporter, spiral, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001191
reed@google.com7c424812011-05-15 04:38:34 +00001192 SkPath dent;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001193 dent.moveTo(0, 0);
1194 dent.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1195 dent.lineTo(0, 100*SK_Scalar1);
1196 dent.lineTo(-50*SK_Scalar1, 200*SK_Scalar1);
1197 dent.lineTo(-200*SK_Scalar1, 100*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001198 dent.close();
1199 check_convexity(reporter, dent, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001200 check_direction(reporter, dent, SkPath::kCW_Direction);
commit-bot@chromium.org8be07bb2014-05-22 14:58:53 +00001201
1202 // http://skbug.com/2235
1203 SkPath strokedSin;
1204 for (int i = 0; i < 2000; i++) {
1205 SkScalar x = SkIntToScalar(i) / 2;
1206 SkScalar y = 500 - (x + SkScalarSin(x / 100) * 40) / 3;
1207 if (0 == i) {
1208 strokedSin.moveTo(x, y);
1209 } else {
1210 strokedSin.lineTo(x, y);
1211 }
1212 }
1213 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
1214 stroke.setStrokeStyle(2 * SK_Scalar1);
1215 stroke.applyToPath(&strokedSin, strokedSin);
1216 check_convexity(reporter, strokedSin, SkPath::kConcave_Convexity);
1217 check_direction(reporter, strokedSin, kDontCheckDir);
robertphillipsc506e302014-09-16 09:43:31 -07001218
1219 // http://crbug.com/412640
1220 SkPath degenerateConcave;
1221 degenerateConcave.moveTo(148.67912f, 191.875f);
1222 degenerateConcave.lineTo(470.37695f, 7.5f);
1223 degenerateConcave.lineTo(148.67912f, 191.875f);
1224 degenerateConcave.lineTo(41.446522f, 376.25f);
1225 degenerateConcave.lineTo(-55.971577f, 460.0f);
1226 degenerateConcave.lineTo(41.446522f, 376.25f);
1227 check_convexity(reporter, degenerateConcave, SkPath::kConcave_Convexity);
1228 check_direction(reporter, degenerateConcave, SkPath::kUnknown_Direction);
robertphillipsf52a0632014-11-17 12:11:42 -08001229
1230 // http://crbug.com/433683
1231 SkPath badFirstVector;
1232 badFirstVector.moveTo(501.087708f, 319.610352f);
1233 badFirstVector.lineTo(501.087708f, 319.610352f);
1234 badFirstVector.cubicTo(501.087677f, 319.610321f, 449.271606f, 258.078674f, 395.084564f, 198.711182f);
1235 badFirstVector.cubicTo(358.967072f, 159.140717f, 321.910553f, 120.650436f, 298.442322f, 101.955399f);
1236 badFirstVector.lineTo(301.557678f, 98.044601f);
1237 badFirstVector.cubicTo(325.283844f, 116.945084f, 362.615204f, 155.720825f, 398.777557f, 195.340454f);
1238 badFirstVector.cubicTo(453.031860f, 254.781662f, 504.912262f, 316.389618f, 504.912292f, 316.389648f);
1239 badFirstVector.lineTo(504.912292f, 316.389648f);
1240 badFirstVector.lineTo(501.087708f, 319.610352f);
1241 badFirstVector.close();
1242 check_convexity(reporter, badFirstVector, SkPath::kConcave_Convexity);
reed@google.com7c424812011-05-15 04:38:34 +00001243}
1244
reed@android.com6b82d1a2009-06-03 02:35:01 +00001245static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
1246 const SkRect& bounds) {
1247 REPORTER_ASSERT(reporter, p.isConvex());
1248 REPORTER_ASSERT(reporter, p.getBounds() == bounds);
reed@google.com62047cf2011-02-07 19:39:09 +00001249
reed@android.com6b82d1a2009-06-03 02:35:01 +00001250 SkPath p2(p);
1251 REPORTER_ASSERT(reporter, p2.isConvex());
1252 REPORTER_ASSERT(reporter, p2.getBounds() == bounds);
1253
1254 SkPath other;
1255 other.swap(p2);
1256 REPORTER_ASSERT(reporter, other.isConvex());
1257 REPORTER_ASSERT(reporter, other.getBounds() == bounds);
1258}
1259
reed@google.com04863fa2011-05-15 04:08:24 +00001260static void setFromString(SkPath* path, const char str[]) {
1261 bool first = true;
1262 while (str) {
1263 SkScalar x, y;
1264 str = SkParse::FindScalar(str, &x);
1265 if (NULL == str) {
1266 break;
1267 }
1268 str = SkParse::FindScalar(str, &y);
1269 SkASSERT(str);
1270 if (first) {
1271 path->moveTo(x, y);
1272 first = false;
1273 } else {
1274 path->lineTo(x, y);
1275 }
1276 }
1277}
1278
1279static void test_convexity(skiatest::Reporter* reporter) {
reed@google.com04863fa2011-05-15 04:08:24 +00001280 SkPath path;
1281
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001282 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001283 path.addCircle(0, 0, SkIntToScalar(10));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001284 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001285 path.addCircle(0, 0, SkIntToScalar(10)); // 2nd circle
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001286 check_convexity(reporter, path, SkPath::kConcave_Convexity);
1287
reed@google.com04863fa2011-05-15 04:08:24 +00001288 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001289 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001290 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.com3e71a882012-01-10 18:44:37 +00001291 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCCW_Direction));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001292
reed@google.com04863fa2011-05-15 04:08:24 +00001293 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001294 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001295 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.com3e71a882012-01-10 18:44:37 +00001296 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCW_Direction));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001297
reed@google.com04863fa2011-05-15 04:08:24 +00001298 static const struct {
1299 const char* fPathStr;
1300 SkPath::Convexity fExpectedConvexity;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001301 SkPath::Direction fExpectedDirection;
reed@google.com04863fa2011-05-15 04:08:24 +00001302 } gRec[] = {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001303 { "", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1304 { "0 0", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1305 { "0 0 10 10", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1306 { "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity, SkPath::kUnknown_Direction },
1307 { "0 0 10 10 10 20", SkPath::kConvex_Convexity, SkPath::kCW_Direction },
1308 { "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPath::kCCW_Direction },
1309 { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir },
1310 { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity, SkPath::kCW_Direction },
reed@google.com04863fa2011-05-15 04:08:24 +00001311 };
1312
1313 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1314 SkPath path;
1315 setFromString(&path, gRec[i].fPathStr);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001316 check_convexity(reporter, path, gRec[i].fExpectedConvexity);
1317 check_direction(reporter, path, gRec[i].fExpectedDirection);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001318 // check after setting the initial convex and direction
1319 if (kDontCheckDir != gRec[i].fExpectedDirection) {
1320 SkPath copy(path);
1321 SkPath::Direction dir;
1322 bool foundDir = copy.cheapComputeDirection(&dir);
1323 REPORTER_ASSERT(reporter, (gRec[i].fExpectedDirection == SkPath::kUnknown_Direction)
1324 ^ foundDir);
1325 REPORTER_ASSERT(reporter, !foundDir || gRec[i].fExpectedDirection == dir);
1326 check_convexity(reporter, copy, gRec[i].fExpectedConvexity);
1327 }
1328 REPORTER_ASSERT(reporter, gRec[i].fExpectedConvexity == path.getConvexity());
1329 check_direction(reporter, path, gRec[i].fExpectedDirection);
reed@google.com04863fa2011-05-15 04:08:24 +00001330 }
caryclarkd3d1a982014-12-08 04:57:38 -08001331
1332 static const SkPoint nonFinitePts[] = {
1333 { SK_ScalarInfinity, 0 },
1334 { 0, SK_ScalarInfinity },
1335 { SK_ScalarInfinity, SK_ScalarInfinity },
1336 { SK_ScalarNegativeInfinity, 0},
1337 { 0, SK_ScalarNegativeInfinity },
1338 { SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity },
1339 { SK_ScalarNegativeInfinity, SK_ScalarInfinity },
1340 { SK_ScalarInfinity, SK_ScalarNegativeInfinity },
1341 { SK_ScalarNaN, 0 },
1342 { 0, SK_ScalarNaN },
1343 { SK_ScalarNaN, SK_ScalarNaN },
1344 };
1345
1346 const size_t nonFinitePtsCount = sizeof(nonFinitePts) / sizeof(nonFinitePts[0]);
1347
1348 static const SkPoint finitePts[] = {
1349 { SK_ScalarMax, 0 },
1350 { 0, SK_ScalarMax },
1351 { SK_ScalarMax, SK_ScalarMax },
1352 { SK_ScalarMin, 0 },
1353 { 0, SK_ScalarMin },
1354 { SK_ScalarMin, SK_ScalarMin },
1355 };
1356
1357 const size_t finitePtsCount = sizeof(finitePts) / sizeof(finitePts[0]);
1358
1359 for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount); ++index) {
1360 int i = (int) (index % nonFinitePtsCount);
1361 int f = (int) (index % finitePtsCount);
1362 int g = (int) ((f + 1) % finitePtsCount);
1363 path.reset();
1364 switch (index % 13) {
1365 case 0: path.lineTo(nonFinitePts[i]); break;
1366 case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break;
1367 case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break;
1368 case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break;
1369 case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); break;
1370 case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); break;
1371 case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); break;
1372 case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f]); break;
1373 case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i]); break;
1374 case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i]); break;
1375 case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts[i]); break;
1376 case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]); break;
1377 case 12: path.moveTo(nonFinitePts[i]); break;
1378 }
1379 check_convexity(reporter, path, SkPath::kUnknown_Convexity);
1380 }
1381
1382 for (int index = 0; index < (int) (11 * finitePtsCount); ++index) {
1383 int f = (int) (index % finitePtsCount);
1384 int g = (int) ((f + 1) % finitePtsCount);
1385 path.reset();
1386 int curveSelect = index % 11;
1387 switch (curveSelect) {
1388 case 0: path.moveTo(finitePts[f]); break;
1389 case 1: path.lineTo(finitePts[f]); break;
1390 case 2: path.quadTo(finitePts[f], finitePts[f]); break;
1391 case 3: path.quadTo(finitePts[f], finitePts[g]); break;
1392 case 4: path.quadTo(finitePts[g], finitePts[f]); break;
1393 case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); break;
1394 case 6: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); break;
1395 case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); break;
1396 case 8: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); break;
1397 case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); break;
1398 case 10: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); break;
1399 }
1400 check_convexity(reporter, path, curveSelect == 0 ? SkPath::kConvex_Convexity
1401 : SkPath::kUnknown_Convexity);
1402 }
1403
reed@google.com04863fa2011-05-15 04:08:24 +00001404}
1405
reed@google.com7e6c4d12012-05-10 14:05:43 +00001406static void test_isLine(skiatest::Reporter* reporter) {
1407 SkPath path;
1408 SkPoint pts[2];
1409 const SkScalar value = SkIntToScalar(5);
1410
1411 REPORTER_ASSERT(reporter, !path.isLine(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001412
reed@google.com7e6c4d12012-05-10 14:05:43 +00001413 // set some non-zero values
1414 pts[0].set(value, value);
1415 pts[1].set(value, value);
1416 REPORTER_ASSERT(reporter, !path.isLine(pts));
1417 // check that pts was untouched
1418 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1419 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1420
1421 const SkScalar moveX = SkIntToScalar(1);
1422 const SkScalar moveY = SkIntToScalar(2);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001423 REPORTER_ASSERT(reporter, value != moveX && value != moveY);
reed@google.com7e6c4d12012-05-10 14:05:43 +00001424
1425 path.moveTo(moveX, moveY);
1426 REPORTER_ASSERT(reporter, !path.isLine(NULL));
1427 REPORTER_ASSERT(reporter, !path.isLine(pts));
1428 // check that pts was untouched
1429 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1430 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1431
1432 const SkScalar lineX = SkIntToScalar(2);
1433 const SkScalar lineY = SkIntToScalar(2);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001434 REPORTER_ASSERT(reporter, value != lineX && value != lineY);
reed@google.com7e6c4d12012-05-10 14:05:43 +00001435
1436 path.lineTo(lineX, lineY);
1437 REPORTER_ASSERT(reporter, path.isLine(NULL));
1438
1439 REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY));
1440 REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY));
1441 REPORTER_ASSERT(reporter, path.isLine(pts));
1442 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1443 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
1444
1445 path.lineTo(0, 0); // too many points/verbs
1446 REPORTER_ASSERT(reporter, !path.isLine(NULL));
1447 REPORTER_ASSERT(reporter, !path.isLine(pts));
1448 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1449 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001450
1451 path.reset();
1452 path.quadTo(1, 1, 2, 2);
1453 REPORTER_ASSERT(reporter, !path.isLine(NULL));
reed@google.com7e6c4d12012-05-10 14:05:43 +00001454}
1455
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001456static void test_conservativelyContains(skiatest::Reporter* reporter) {
1457 SkPath path;
1458
1459 // kBaseRect is used to construct most our test paths: a rect, a circle, and a round-rect.
1460 static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
1461
1462 // A circle that bounds kBaseRect (with a significant amount of slop)
1463 SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height());
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001464 circleR = SkScalarMul(circleR, 1.75f) / 2;
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001465 static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()};
1466
1467 // round-rect radii
1468 static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)};
skia.committer@gmail.comcec8de62012-11-14 02:01:22 +00001469
caryclark@google.com56f233a2012-11-19 13:06:06 +00001470 static const struct SUPPRESS_VISIBILITY_WARNING {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001471 SkRect fQueryRect;
1472 bool fInRect;
1473 bool fInCircle;
1474 bool fInRR;
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001475 bool fInCubicRR;
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001476 } kQueries[] = {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001477 {kBaseRect, true, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001478
1479 // rect well inside of kBaseRect
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001480 {SkRect::MakeLTRB(kBaseRect.fLeft + 0.25f*kBaseRect.width(),
1481 kBaseRect.fTop + 0.25f*kBaseRect.height(),
1482 kBaseRect.fRight - 0.25f*kBaseRect.width(),
1483 kBaseRect.fBottom - 0.25f*kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001484 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001485
1486 // rects with edges off by one from kBaseRect's edges
1487 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1488 kBaseRect.width(), kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001489 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001490 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1491 kBaseRect.width() + 1, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001492 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001493 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1494 kBaseRect.width() + 1, kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001495 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001496 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1497 kBaseRect.width(), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001498 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001499 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1500 kBaseRect.width(), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001501 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001502 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1503 kBaseRect.width() + 2, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001504 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001505 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1506 kBaseRect.width() + 2, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001507 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001508
1509 // zero-w/h rects at each corner of kBaseRect
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001510 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, false, false},
1511 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, false, true},
1512 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true, false, true},
1513 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true, false, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001514
1515 // far away rect
1516 {SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom,
1517 SkIntToScalar(10), SkIntToScalar(10)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001518 false, false, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001519
1520 // very large rect containing kBaseRect
1521 {SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(),
1522 kBaseRect.fTop - 5 * kBaseRect.height(),
1523 11 * kBaseRect.width(), 11 * kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001524 false, false, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001525
1526 // skinny rect that spans same y-range as kBaseRect
1527 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1528 SkIntToScalar(1), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001529 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001530
1531 // short rect that spans same x-range as kBaseRect
1532 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(), SkScalar(1)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001533 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001534
1535 // skinny rect that spans slightly larger y-range than kBaseRect
1536 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1537 SkIntToScalar(1), kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001538 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001539
1540 // short rect that spans slightly larger x-range than kBaseRect
1541 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(),
1542 kBaseRect.width() + 1, SkScalar(1)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001543 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001544 };
1545
1546 for (int inv = 0; inv < 4; ++inv) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001547 for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001548 SkRect qRect = kQueries[q].fQueryRect;
1549 if (inv & 0x1) {
1550 SkTSwap(qRect.fLeft, qRect.fRight);
1551 }
1552 if (inv & 0x2) {
1553 SkTSwap(qRect.fTop, qRect.fBottom);
1554 }
1555 for (int d = 0; d < 2; ++d) {
1556 SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
1557 path.reset();
1558 path.addRect(kBaseRect, dir);
1559 REPORTER_ASSERT(reporter, kQueries[q].fInRect ==
1560 path.conservativelyContainsRect(qRect));
1561
1562 path.reset();
1563 path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir);
1564 REPORTER_ASSERT(reporter, kQueries[q].fInCircle ==
1565 path.conservativelyContainsRect(qRect));
1566
1567 path.reset();
1568 path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir);
1569 REPORTER_ASSERT(reporter, kQueries[q].fInRR ==
1570 path.conservativelyContainsRect(qRect));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001571
1572 path.reset();
1573 path.moveTo(kBaseRect.fLeft + kRRRadii[0], kBaseRect.fTop);
1574 path.cubicTo(kBaseRect.fLeft + kRRRadii[0] / 2, kBaseRect.fTop,
1575 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1] / 2,
1576 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1]);
1577 path.lineTo(kBaseRect.fLeft, kBaseRect.fBottom);
1578 path.lineTo(kBaseRect.fRight, kBaseRect.fBottom);
1579 path.lineTo(kBaseRect.fRight, kBaseRect.fTop);
1580 path.close();
1581 REPORTER_ASSERT(reporter, kQueries[q].fInCubicRR ==
1582 path.conservativelyContainsRect(qRect));
1583
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001584 }
1585 // Slightly non-convex shape, shouldn't contain any rects.
1586 path.reset();
1587 path.moveTo(0, 0);
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001588 path.lineTo(SkIntToScalar(50), 0.05f);
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001589 path.lineTo(SkIntToScalar(100), 0);
1590 path.lineTo(SkIntToScalar(100), SkIntToScalar(100));
1591 path.lineTo(0, SkIntToScalar(100));
1592 path.close();
1593 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect));
1594 }
1595 }
1596
1597 // make sure a minimal convex shape works, a right tri with edges along pos x and y axes.
1598 path.reset();
1599 path.moveTo(0, 0);
1600 path.lineTo(SkIntToScalar(100), 0);
1601 path.lineTo(0, SkIntToScalar(100));
1602
1603 // inside, on along top edge
1604 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1605 SkIntToScalar(10),
1606 SkIntToScalar(10))));
1607 // above
1608 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1609 SkRect::MakeXYWH(SkIntToScalar(50),
1610 SkIntToScalar(-10),
1611 SkIntToScalar(10),
1612 SkIntToScalar(10))));
1613 // to the left
1614 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(-10),
1615 SkIntToScalar(5),
1616 SkIntToScalar(5),
1617 SkIntToScalar(5))));
1618
1619 // outside the diagonal edge
1620 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(10),
1621 SkIntToScalar(200),
1622 SkIntToScalar(20),
1623 SkIntToScalar(5))));
commit-bot@chromium.org62df5262013-08-01 15:35:06 +00001624
bsalomonb17c1292014-08-28 14:04:55 -07001625
1626 // Test that multiple move commands do not cause asserts.
1627
1628 // At the time of writing, this would not modify cached convexity. This caused an assert while
1629 // checking conservative containment again. http://skbug.com/1460
1630 path.moveTo(SkIntToScalar(100), SkIntToScalar(100));
1631#if 0
1632 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1633 SkIntToScalar(10),
1634 SkIntToScalar(10))));
1635#endif
1636
1637 // Same as above path and first test but with an extra moveTo.
commit-bot@chromium.org62df5262013-08-01 15:35:06 +00001638 path.reset();
1639 path.moveTo(100, 100);
1640 path.moveTo(0, 0);
1641 path.lineTo(SkIntToScalar(100), 0);
1642 path.lineTo(0, SkIntToScalar(100));
1643
1644 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1645 SkIntToScalar(10),
1646 SkIntToScalar(10))));
1647
bsalomonb17c1292014-08-28 14:04:55 -07001648 // Test that multiple move commands do not cause asserts and that the function
1649 // is not confused by the multiple moves.
1650 path.reset();
1651 path.moveTo(0, 0);
1652 path.lineTo(SkIntToScalar(100), 0);
1653 path.lineTo(0, SkIntToScalar(100));
1654 path.moveTo(0, SkIntToScalar(200));
1655 path.lineTo(SkIntToScalar(100), SkIntToScalar(200));
1656 path.lineTo(0, SkIntToScalar(300));
1657
1658 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1659 SkRect::MakeXYWH(SkIntToScalar(50), 0,
1660 SkIntToScalar(10),
1661 SkIntToScalar(10))));
1662
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001663 path.reset();
1664 path.lineTo(100, 100);
1665 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(0, 0, 1, 1)));
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001666}
1667
reed@google.comf32322b2013-10-16 15:14:04 +00001668static void test_isRect_open_close(skiatest::Reporter* reporter) {
1669 SkPath path;
1670 bool isClosed;
1671
1672 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1);
reed@google.comf32322b2013-10-16 15:14:04 +00001673 path.close();
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00001674
robertphillips91b0a352015-01-05 10:13:46 -08001675 REPORTER_ASSERT(reporter, path.isRect(NULL, &isClosed, NULL));
reed@google.comf32322b2013-10-16 15:14:04 +00001676 REPORTER_ASSERT(reporter, isClosed);
1677}
1678
caryclark@google.comf1316942011-07-26 19:54:45 +00001679// Simple isRect test is inline TestPath, below.
1680// test_isRect provides more extensive testing.
1681static void test_isRect(skiatest::Reporter* reporter) {
reed@google.comf32322b2013-10-16 15:14:04 +00001682 test_isRect_open_close(reporter);
1683
caryclark@google.comf1316942011-07-26 19:54:45 +00001684 // passing tests (all moveTo / lineTo...
1685 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1686 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1687 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1688 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
1689 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
1690 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1691 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1692 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1693 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001694 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}};
1695 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 +00001696 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}};
1697 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
1698 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}};
caryclark@google.combfe90372012-11-21 13:56:20 +00001699 SkPoint rf[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}};
rmistry@google.comd6176b02012-08-23 18:14:13 +00001700
caryclark@google.comf1316942011-07-26 19:54:45 +00001701 // failing tests
1702 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1703 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1704 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1705 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1706 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1707 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1708 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1709 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
caryclark@google.combfe90372012-11-21 13:56:20 +00001710 SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps
1711 SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non colinear gap
1712 SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short
rmistry@google.comd6176b02012-08-23 18:14:13 +00001713
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00001714 // no close, but we should detect them as fillably the same as a rect
1715 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1716 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}};
1717 SkPoint c3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 0}}; // hit the start
1718
1719 // like c2, but we double-back on ourselves
1720 SkPoint d1[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 2}};
1721 // like c2, but we overshoot the start point
1722 SkPoint d2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}};
1723 SkPoint d3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}, {0, 0}};
caryclark@google.comf1316942011-07-26 19:54:45 +00001724
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001725 struct IsRectTest {
1726 SkPoint *fPoints;
bsalomon98806072014-12-12 15:11:17 -08001727 int fPointCount;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001728 bool fClose;
1729 bool fIsRect;
1730 } tests[] = {
1731 { r1, SK_ARRAY_COUNT(r1), true, true },
1732 { r2, SK_ARRAY_COUNT(r2), true, true },
1733 { r3, SK_ARRAY_COUNT(r3), true, true },
1734 { r4, SK_ARRAY_COUNT(r4), true, true },
1735 { r5, SK_ARRAY_COUNT(r5), true, true },
1736 { r6, SK_ARRAY_COUNT(r6), true, true },
1737 { r7, SK_ARRAY_COUNT(r7), true, true },
1738 { r8, SK_ARRAY_COUNT(r8), true, true },
1739 { r9, SK_ARRAY_COUNT(r9), true, true },
1740 { ra, SK_ARRAY_COUNT(ra), true, true },
1741 { rb, SK_ARRAY_COUNT(rb), true, true },
1742 { rc, SK_ARRAY_COUNT(rc), true, true },
1743 { rd, SK_ARRAY_COUNT(rd), true, true },
1744 { re, SK_ARRAY_COUNT(re), true, true },
1745 { rf, SK_ARRAY_COUNT(rf), true, true },
1746
1747 { f1, SK_ARRAY_COUNT(f1), true, false },
1748 { f2, SK_ARRAY_COUNT(f2), true, false },
1749 { f3, SK_ARRAY_COUNT(f3), true, false },
1750 { f4, SK_ARRAY_COUNT(f4), true, false },
1751 { f5, SK_ARRAY_COUNT(f5), true, false },
1752 { f6, SK_ARRAY_COUNT(f6), true, false },
1753 { f7, SK_ARRAY_COUNT(f7), true, false },
1754 { f8, SK_ARRAY_COUNT(f8), true, false },
1755 { f9, SK_ARRAY_COUNT(f9), true, false },
1756 { fa, SK_ARRAY_COUNT(fa), true, false },
1757 { fb, SK_ARRAY_COUNT(fb), true, false },
1758
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00001759 { c1, SK_ARRAY_COUNT(c1), false, true },
1760 { c2, SK_ARRAY_COUNT(c2), false, true },
1761 { c3, SK_ARRAY_COUNT(c3), false, true },
1762
1763 { d1, SK_ARRAY_COUNT(d1), false, false },
1764 { d2, SK_ARRAY_COUNT(d2), false, false },
1765 { d3, SK_ARRAY_COUNT(d3), false, false },
caryclark@google.comf1316942011-07-26 19:54:45 +00001766 };
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001767
1768 const size_t testCount = SK_ARRAY_COUNT(tests);
bsalomon98806072014-12-12 15:11:17 -08001769 int index;
caryclark@google.comf1316942011-07-26 19:54:45 +00001770 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1771 SkPath path;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001772 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1773 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1774 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.comf1316942011-07-26 19:54:45 +00001775 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001776 if (tests[testIndex].fClose) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001777 path.close();
1778 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001779 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001780
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001781 if (tests[testIndex].fIsRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001782 SkRect computed, expected;
caryclark@google.comf68154a2012-11-21 15:18:06 +00001783 bool isClosed;
1784 SkPath::Direction direction, cheapDirection;
robertphillips91b0a352015-01-05 10:13:46 -08001785 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001786 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection));
robertphillips91b0a352015-01-05 10:13:46 -08001787 REPORTER_ASSERT(reporter, path.isRect(&computed, &isClosed, &direction));
1788 REPORTER_ASSERT(reporter, expected == computed);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001789 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001790 REPORTER_ASSERT(reporter, direction == cheapDirection);
1791 } else {
1792 SkRect computed;
1793 computed.set(123, 456, 789, 1011);
robertphillips91b0a352015-01-05 10:13:46 -08001794 bool isClosed = (bool)-1;
1795 SkPath::Direction direction = (SkPath::Direction) - 1;
1796 REPORTER_ASSERT(reporter, !path.isRect(&computed, &isClosed, &direction));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001797 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456);
1798 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001799 REPORTER_ASSERT(reporter, isClosed == (bool) -1);
1800 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001801 }
caryclark@google.comf1316942011-07-26 19:54:45 +00001802 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00001803
caryclark@google.comf1316942011-07-26 19:54:45 +00001804 // fail, close then line
1805 SkPath path1;
1806 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001807 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001808 path1.lineTo(r1[index].fX, r1[index].fY);
1809 }
1810 path1.close();
1811 path1.lineTo(1, 0);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001812 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001813
caryclark@google.comf1316942011-07-26 19:54:45 +00001814 // fail, move in the middle
1815 path1.reset();
1816 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001817 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001818 if (index == 2) {
1819 path1.moveTo(1, .5f);
1820 }
1821 path1.lineTo(r1[index].fX, r1[index].fY);
1822 }
1823 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001824 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00001825
1826 // fail, move on the edge
1827 path1.reset();
bsalomon98806072014-12-12 15:11:17 -08001828 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001829 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1830 path1.lineTo(r1[index].fX, r1[index].fY);
1831 }
1832 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001833 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001834
caryclark@google.comf1316942011-07-26 19:54:45 +00001835 // fail, quad
1836 path1.reset();
1837 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001838 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001839 if (index == 2) {
1840 path1.quadTo(1, .5f, 1, .5f);
1841 }
1842 path1.lineTo(r1[index].fX, r1[index].fY);
1843 }
1844 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001845 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001846
caryclark@google.comf1316942011-07-26 19:54:45 +00001847 // fail, cubic
1848 path1.reset();
1849 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001850 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001851 if (index == 2) {
1852 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1853 }
1854 path1.lineTo(r1[index].fX, r1[index].fY);
1855 }
1856 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001857 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00001858}
1859
caryclark@google.com56f233a2012-11-19 13:06:06 +00001860static void test_isNestedRects(skiatest::Reporter* reporter) {
1861 // passing tests (all moveTo / lineTo...
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001862 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001863 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1864 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1865 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001866 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001867 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1868 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1869 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1870 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001871 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; // CCW
1872 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 +00001873 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW
1874 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW
1875 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001876
1877 // failing tests
1878 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1879 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1880 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1881 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1882 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1883 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1884 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1885 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
1886
1887 // failing, no close
1888 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
1889 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
1890
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001891 struct IsNestedRectTest {
1892 SkPoint *fPoints;
bsalomon98806072014-12-12 15:11:17 -08001893 int fPointCount;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001894 SkPath::Direction fDirection;
1895 bool fClose;
1896 bool fIsNestedRect; // nests with path.addRect(-1, -1, 2, 2);
1897 } tests[] = {
1898 { r1, SK_ARRAY_COUNT(r1), SkPath::kCW_Direction , true, true },
1899 { r2, SK_ARRAY_COUNT(r2), SkPath::kCW_Direction , true, true },
1900 { r3, SK_ARRAY_COUNT(r3), SkPath::kCW_Direction , true, true },
1901 { r4, SK_ARRAY_COUNT(r4), SkPath::kCW_Direction , true, true },
1902 { r5, SK_ARRAY_COUNT(r5), SkPath::kCCW_Direction, true, true },
1903 { r6, SK_ARRAY_COUNT(r6), SkPath::kCCW_Direction, true, true },
1904 { r7, SK_ARRAY_COUNT(r7), SkPath::kCCW_Direction, true, true },
1905 { r8, SK_ARRAY_COUNT(r8), SkPath::kCCW_Direction, true, true },
1906 { r9, SK_ARRAY_COUNT(r9), SkPath::kCCW_Direction, true, true },
1907 { ra, SK_ARRAY_COUNT(ra), SkPath::kCCW_Direction, true, true },
1908 { rb, SK_ARRAY_COUNT(rb), SkPath::kCW_Direction, true, true },
1909 { rc, SK_ARRAY_COUNT(rc), SkPath::kCW_Direction, true, true },
1910 { rd, SK_ARRAY_COUNT(rd), SkPath::kCCW_Direction, true, true },
1911 { re, SK_ARRAY_COUNT(re), SkPath::kCW_Direction, true, true },
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001912
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001913 { f1, SK_ARRAY_COUNT(f1), SkPath::kUnknown_Direction, true, false },
1914 { f2, SK_ARRAY_COUNT(f2), SkPath::kUnknown_Direction, true, false },
1915 { f3, SK_ARRAY_COUNT(f3), SkPath::kUnknown_Direction, true, false },
1916 { f4, SK_ARRAY_COUNT(f4), SkPath::kUnknown_Direction, true, false },
1917 { f5, SK_ARRAY_COUNT(f5), SkPath::kUnknown_Direction, true, false },
1918 { f6, SK_ARRAY_COUNT(f6), SkPath::kUnknown_Direction, true, false },
1919 { f7, SK_ARRAY_COUNT(f7), SkPath::kUnknown_Direction, true, false },
1920 { f8, SK_ARRAY_COUNT(f8), SkPath::kUnknown_Direction, true, false },
1921
1922 { c1, SK_ARRAY_COUNT(c1), SkPath::kUnknown_Direction, false, false },
1923 { c2, SK_ARRAY_COUNT(c2), SkPath::kUnknown_Direction, false, false },
1924 };
1925
1926 const size_t testCount = SK_ARRAY_COUNT(tests);
bsalomon98806072014-12-12 15:11:17 -08001927 int index;
caryclark@google.com56f233a2012-11-19 13:06:06 +00001928 for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001929 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1930 SkPath path;
1931 if (rectFirst) {
1932 path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1933 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001934 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1935 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1936 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001937 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001938 if (tests[testIndex].fClose) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001939 path.close();
1940 }
1941 if (!rectFirst) {
1942 path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1943 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001944 REPORTER_ASSERT(reporter, tests[testIndex].fIsNestedRect == path.isNestedRects(NULL));
1945 if (tests[testIndex].fIsNestedRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001946 SkRect expected[2], computed[2];
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001947 SkPath::Direction expectedDirs[2], computedDirs[2];
caryclark@google.com56f233a2012-11-19 13:06:06 +00001948 SkRect testBounds;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001949 testBounds.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001950 expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2);
1951 expected[1] = testBounds;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001952 if (rectFirst) {
1953 expectedDirs[0] = SkPath::kCW_Direction;
1954 } else {
1955 expectedDirs[0] = SkPath::kCCW_Direction;
1956 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001957 expectedDirs[1] = tests[testIndex].fDirection;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001958 REPORTER_ASSERT(reporter, path.isNestedRects(computed, computedDirs));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001959 REPORTER_ASSERT(reporter, expected[0] == computed[0]);
1960 REPORTER_ASSERT(reporter, expected[1] == computed[1]);
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001961 REPORTER_ASSERT(reporter, expectedDirs[0] == computedDirs[0]);
1962 REPORTER_ASSERT(reporter, expectedDirs[1] == computedDirs[1]);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001963 }
caryclark@google.com56f233a2012-11-19 13:06:06 +00001964 }
1965
1966 // fail, close then line
1967 SkPath path1;
1968 if (rectFirst) {
1969 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1970 }
1971 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001972 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001973 path1.lineTo(r1[index].fX, r1[index].fY);
1974 }
1975 path1.close();
1976 path1.lineTo(1, 0);
1977 if (!rectFirst) {
1978 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1979 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001980 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001981
1982 // fail, move in the middle
1983 path1.reset();
1984 if (rectFirst) {
1985 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1986 }
1987 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001988 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001989 if (index == 2) {
1990 path1.moveTo(1, .5f);
1991 }
1992 path1.lineTo(r1[index].fX, r1[index].fY);
1993 }
1994 path1.close();
1995 if (!rectFirst) {
1996 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1997 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001998 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001999
2000 // fail, move on the edge
2001 path1.reset();
2002 if (rectFirst) {
2003 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2004 }
bsalomon98806072014-12-12 15:11:17 -08002005 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002006 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
2007 path1.lineTo(r1[index].fX, r1[index].fY);
2008 }
2009 path1.close();
2010 if (!rectFirst) {
2011 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2012 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002013 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002014
2015 // fail, quad
2016 path1.reset();
2017 if (rectFirst) {
2018 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2019 }
2020 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08002021 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002022 if (index == 2) {
2023 path1.quadTo(1, .5f, 1, .5f);
2024 }
2025 path1.lineTo(r1[index].fX, r1[index].fY);
2026 }
2027 path1.close();
2028 if (!rectFirst) {
2029 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2030 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002031 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002032
2033 // fail, cubic
2034 path1.reset();
2035 if (rectFirst) {
2036 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2037 }
2038 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08002039 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002040 if (index == 2) {
2041 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
2042 }
2043 path1.lineTo(r1[index].fX, r1[index].fY);
2044 }
2045 path1.close();
2046 if (!rectFirst) {
2047 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2048 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002049 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
skia.committer@gmail.com34587162012-11-20 02:01:23 +00002050
caryclark@google.com56f233a2012-11-19 13:06:06 +00002051 // fail, not nested
2052 path1.reset();
2053 path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction);
2054 path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002055 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002056 }
caryclark@google.combfe90372012-11-21 13:56:20 +00002057
2058 // pass, stroke rect
2059 SkPath src, dst;
2060 src.addRect(1, 1, 7, 7, SkPath::kCW_Direction);
2061 SkPaint strokePaint;
2062 strokePaint.setStyle(SkPaint::kStroke_Style);
2063 strokePaint.setStrokeWidth(2);
2064 strokePaint.getFillPath(src, &dst);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002065 REPORTER_ASSERT(reporter, dst.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002066}
2067
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002068static void write_and_read_back(skiatest::Reporter* reporter,
2069 const SkPath& p) {
commit-bot@chromium.org19382422014-01-14 20:51:26 +00002070 SkWriter32 writer;
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002071 writer.writePath(p);
reed@google.com44699382013-10-31 17:28:30 +00002072 size_t size = writer.bytesWritten();
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002073 SkAutoMalloc storage(size);
2074 writer.flatten(storage.get());
2075 SkReader32 reader(storage.get(), size);
2076
2077 SkPath readBack;
2078 REPORTER_ASSERT(reporter, readBack != p);
2079 reader.readPath(&readBack);
2080 REPORTER_ASSERT(reporter, readBack == p);
2081
rmistry@google.comd6176b02012-08-23 18:14:13 +00002082 REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() ==
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002083 p.getConvexityOrUnknown());
2084
2085 REPORTER_ASSERT(reporter, readBack.isOval(NULL) == p.isOval(NULL));
2086
2087 const SkRect& origBounds = p.getBounds();
2088 const SkRect& readBackBounds = readBack.getBounds();
2089
2090 REPORTER_ASSERT(reporter, origBounds == readBackBounds);
2091}
2092
reed@google.com53effc52011-09-21 19:05:12 +00002093static void test_flattening(skiatest::Reporter* reporter) {
2094 SkPath p;
2095
2096 static const SkPoint pts[] = {
2097 { 0, 0 },
2098 { SkIntToScalar(10), SkIntToScalar(10) },
2099 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 },
2100 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }
2101 };
2102 p.moveTo(pts[0]);
2103 p.lineTo(pts[1]);
2104 p.quadTo(pts[2], pts[3]);
2105 p.cubicTo(pts[4], pts[5], pts[6]);
2106
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002107 write_and_read_back(reporter, p);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002108
2109 // create a buffer that should be much larger than the path so we don't
2110 // kill our stack if writer goes too far.
2111 char buffer[1024];
commit-bot@chromium.org4faa8692013-11-05 15:46:56 +00002112 size_t size1 = p.writeToMemory(NULL);
2113 size_t size2 = p.writeToMemory(buffer);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002114 REPORTER_ASSERT(reporter, size1 == size2);
2115
2116 SkPath p2;
commit-bot@chromium.org4faa8692013-11-05 15:46:56 +00002117 size_t size3 = p2.readFromMemory(buffer, 1024);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002118 REPORTER_ASSERT(reporter, size1 == size3);
2119 REPORTER_ASSERT(reporter, p == p2);
2120
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002121 size3 = p2.readFromMemory(buffer, 0);
2122 REPORTER_ASSERT(reporter, !size3);
2123
2124 SkPath tooShort;
2125 size3 = tooShort.readFromMemory(buffer, size1 - 1);
2126 REPORTER_ASSERT(reporter, tooShort.isEmpty());
2127
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002128 char buffer2[1024];
2129 size3 = p2.writeToMemory(buffer2);
2130 REPORTER_ASSERT(reporter, size1 == size3);
2131 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002132
2133 // test persistence of the oval flag & convexity
2134 {
2135 SkPath oval;
2136 SkRect rect = SkRect::MakeWH(10, 10);
2137 oval.addOval(rect);
2138
2139 write_and_read_back(reporter, oval);
2140 }
reed@google.com53effc52011-09-21 19:05:12 +00002141}
2142
2143static void test_transform(skiatest::Reporter* reporter) {
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002144 SkPath p;
rmistry@google.comd6176b02012-08-23 18:14:13 +00002145
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002146#define CONIC_PERSPECTIVE_BUG_FIXED 0
reed@google.com53effc52011-09-21 19:05:12 +00002147 static const SkPoint pts[] = {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002148 { 0, 0 }, // move
2149 { SkIntToScalar(10), SkIntToScalar(10) }, // line
2150 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, // quad
2151 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }, // cubic
2152#if CONIC_PERSPECTIVE_BUG_FIXED
2153 { 0, 0 }, { SkIntToScalar(20), SkIntToScalar(10) }, // conic
2154#endif
reed@google.com53effc52011-09-21 19:05:12 +00002155 };
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002156 const int kPtCount = SK_ARRAY_COUNT(pts);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002157
reed@google.com53effc52011-09-21 19:05:12 +00002158 p.moveTo(pts[0]);
2159 p.lineTo(pts[1]);
2160 p.quadTo(pts[2], pts[3]);
2161 p.cubicTo(pts[4], pts[5], pts[6]);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002162#if CONIC_PERSPECTIVE_BUG_FIXED
2163 p.conicTo(pts[4], pts[5], 0.5f);
2164#endif
2165 p.close();
rmistry@google.comd6176b02012-08-23 18:14:13 +00002166
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002167 {
2168 SkMatrix matrix;
2169 matrix.reset();
2170 SkPath p1;
2171 p.transform(matrix, &p1);
2172 REPORTER_ASSERT(reporter, p == p1);
reed@google.com53effc52011-09-21 19:05:12 +00002173 }
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002174
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002175
2176 {
2177 SkMatrix matrix;
2178 matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3);
2179
2180 SkPath p1; // Leave p1 non-unique (i.e., the empty path)
2181
skia.committer@gmail.com6e515d62013-12-04 07:02:26 +00002182 p.transform(matrix, &p1);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002183 SkPoint pts1[kPtCount];
skia.committer@gmail.com6e515d62013-12-04 07:02:26 +00002184 int count = p1.getPoints(pts1, kPtCount);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002185 REPORTER_ASSERT(reporter, kPtCount == count);
2186 for (int i = 0; i < count; ++i) {
2187 SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3);
2188 REPORTER_ASSERT(reporter, newPt == pts1[i]);
2189 }
2190 }
2191
2192 {
2193 SkMatrix matrix;
2194 matrix.reset();
reed3f43f8a2015-01-20 19:58:36 -08002195 matrix.setPerspX(4);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002196
2197 SkPath p1;
2198 p1.moveTo(SkPoint::Make(0, 0));
2199
2200 p.transform(matrix, &p1);
2201 REPORTER_ASSERT(reporter, matrix.invert(&matrix));
2202 p1.transform(matrix, NULL);
2203 SkRect pBounds = p.getBounds();
2204 SkRect p1Bounds = p1.getBounds();
2205 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fLeft, p1Bounds.fLeft));
2206 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fTop, p1Bounds.fTop));
2207 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fRight, p1Bounds.fRight));
2208 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fBottom, p1Bounds.fBottom));
2209 }
2210
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002211 p.reset();
2212 p.addCircle(0, 0, 1, SkPath::kCW_Direction);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002213
2214 {
2215 SkMatrix matrix;
2216 matrix.reset();
2217 SkPath p1;
2218 p1.moveTo(SkPoint::Make(0, 0));
2219
2220 p.transform(matrix, &p1);
2221 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCW_Direction));
2222 }
2223
2224
2225 {
2226 SkMatrix matrix;
2227 matrix.reset();
2228 matrix.setScaleX(-1);
2229 SkPath p1;
2230 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
2231
2232 p.transform(matrix, &p1);
2233 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCCW_Direction));
2234 }
2235
2236 {
2237 SkMatrix matrix;
2238 matrix.setAll(1, 1, 0, 1, 1, 0, 0, 0, 1);
2239 SkPath p1;
2240 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
2241
2242 p.transform(matrix, &p1);
2243 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kUnknown_Direction));
2244 }
reed@google.com53effc52011-09-21 19:05:12 +00002245}
2246
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002247static void test_zero_length_paths(skiatest::Reporter* reporter) {
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002248 SkPath p;
schenney@chromium.org7e963602012-06-13 17:05:43 +00002249 uint8_t verbs[32];
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002250
caryclark@google.com56f233a2012-11-19 13:06:06 +00002251 struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData {
schenney@chromium.org7e963602012-06-13 17:05:43 +00002252 const char* testPath;
2253 const size_t numResultPts;
2254 const SkRect resultBound;
2255 const SkPath::Verb* resultVerbs;
2256 const size_t numResultVerbs;
2257 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002258
schenney@chromium.org7e963602012-06-13 17:05:43 +00002259 static const SkPath::Verb resultVerbs1[] = { SkPath::kMove_Verb };
2260 static const SkPath::Verb resultVerbs2[] = { SkPath::kMove_Verb, SkPath::kMove_Verb };
2261 static const SkPath::Verb resultVerbs3[] = { SkPath::kMove_Verb, SkPath::kClose_Verb };
2262 static const SkPath::Verb resultVerbs4[] = { SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb };
2263 static const SkPath::Verb resultVerbs5[] = { SkPath::kMove_Verb, SkPath::kLine_Verb };
2264 static const SkPath::Verb resultVerbs6[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb };
2265 static const SkPath::Verb resultVerbs7[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb };
2266 static const SkPath::Verb resultVerbs8[] = {
2267 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb
2268 };
2269 static const SkPath::Verb resultVerbs9[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb };
2270 static const SkPath::Verb resultVerbs10[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb };
2271 static const SkPath::Verb resultVerbs11[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb };
2272 static const SkPath::Verb resultVerbs12[] = {
2273 SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb
2274 };
2275 static const SkPath::Verb resultVerbs13[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb };
2276 static const SkPath::Verb resultVerbs14[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb };
2277 static const SkPath::Verb resultVerbs15[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb };
2278 static const SkPath::Verb resultVerbs16[] = {
2279 SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb
2280 };
2281 static const struct zeroPathTestData gZeroLengthTests[] = {
2282 { "M 1 1", 1, {0, 0, 0, 0}, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002283 { "M 1 1 M 2 1", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
schenney@chromium.org7e963602012-06-13 17:05:43 +00002284 { "M 1 1 z", 1, {0, 0, 0, 0}, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002285 { "M 1 1 z M 2 1 z", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
2286 { "M 1 1 L 1 1", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) },
2287 { "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) },
2288 { "M 1 1 L 1 1 z", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs7, SK_ARRAY_COUNT(resultVerbs7) },
2289 { "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) },
2290 { "M 1 1 Q 1 1 1 1", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs9, SK_ARRAY_COUNT(resultVerbs9) },
2291 { "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) },
2292 { "M 1 1 Q 1 1 1 1 z", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs11, SK_ARRAY_COUNT(resultVerbs11) },
2293 { "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) },
2294 { "M 1 1 C 1 1 1 1 1 1", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs13, SK_ARRAY_COUNT(resultVerbs13) },
2295 { "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 +00002296 SK_ARRAY_COUNT(resultVerbs14)
2297 },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002298 { "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) },
2299 { "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 +00002300 SK_ARRAY_COUNT(resultVerbs16)
2301 }
2302 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002303
schenney@chromium.org7e963602012-06-13 17:05:43 +00002304 for (size_t i = 0; i < SK_ARRAY_COUNT(gZeroLengthTests); ++i) {
2305 p.reset();
2306 bool valid = SkParsePath::FromSVGString(gZeroLengthTests[i].testPath, &p);
2307 REPORTER_ASSERT(reporter, valid);
2308 REPORTER_ASSERT(reporter, !p.isEmpty());
2309 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultPts == (size_t)p.countPoints());
2310 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultBound == p.getBounds());
2311 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultVerbs == (size_t)p.getVerbs(verbs, SK_ARRAY_COUNT(verbs)));
2312 for (size_t j = 0; j < gZeroLengthTests[i].numResultVerbs; ++j) {
2313 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultVerbs[j] == verbs[j]);
2314 }
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002315 }
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002316}
2317
2318struct SegmentInfo {
2319 SkPath fPath;
2320 int fPointCount;
2321};
2322
reed@google.com10296cc2011-09-21 12:29:05 +00002323#define kCurveSegmentMask (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask)
2324
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002325static void test_segment_masks(skiatest::Reporter* reporter) {
reed@google.comeef938c2012-08-01 20:01:49 +00002326 SkPath p, p2;
2327
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002328 p.moveTo(0, 0);
2329 p.quadTo(100, 100, 200, 200);
2330 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == p.getSegmentMasks());
2331 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00002332 p2 = p;
2333 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002334 p.cubicTo(100, 100, 200, 200, 300, 300);
2335 REPORTER_ASSERT(reporter, kCurveSegmentMask == p.getSegmentMasks());
2336 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00002337 p2 = p;
2338 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
2339
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002340 p.reset();
2341 p.moveTo(0, 0);
2342 p.cubicTo(100, 100, 200, 200, 300, 300);
2343 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == p.getSegmentMasks());
reed@google.comeef938c2012-08-01 20:01:49 +00002344 p2 = p;
2345 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
rmistry@google.comd6176b02012-08-23 18:14:13 +00002346
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002347 REPORTER_ASSERT(reporter, !p.isEmpty());
2348}
2349
2350static void test_iter(skiatest::Reporter* reporter) {
schenney@chromium.org7e963602012-06-13 17:05:43 +00002351 SkPath p;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002352 SkPoint pts[4];
2353
2354 // Test an iterator with no path
2355 SkPath::Iter noPathIter;
2356 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002357
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002358 // Test that setting an empty path works
2359 noPathIter.setPath(p, false);
2360 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002361
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002362 // Test that close path makes no difference for an empty path
2363 noPathIter.setPath(p, true);
2364 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002365
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002366 // Test an iterator with an initial empty path
2367 SkPath::Iter iter(p, false);
2368 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2369
2370 // Test that close path makes no difference
schenney@chromium.org7e963602012-06-13 17:05:43 +00002371 iter.setPath(p, true);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002372 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2373
rmistry@google.comd6176b02012-08-23 18:14:13 +00002374
schenney@chromium.org7e963602012-06-13 17:05:43 +00002375 struct iterTestData {
2376 const char* testPath;
2377 const bool forceClose;
2378 const bool consumeDegenerates;
2379 const size_t* numResultPtsPerVerb;
2380 const SkPoint* resultPts;
2381 const SkPath::Verb* resultVerbs;
2382 const size_t numResultVerbs;
2383 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002384
schenney@chromium.org7e963602012-06-13 17:05:43 +00002385 static const SkPath::Verb resultVerbs1[] = { SkPath::kDone_Verb };
2386 static const SkPath::Verb resultVerbs2[] = {
2387 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kDone_Verb
2388 };
2389 static const SkPath::Verb resultVerbs3[] = {
2390 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2391 };
2392 static const SkPath::Verb resultVerbs4[] = {
2393 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2394 };
2395 static const SkPath::Verb resultVerbs5[] = {
2396 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2397 };
2398 static const size_t resultPtsSizes1[] = { 0 };
schenney@chromium.orgfedd09b2012-06-13 18:29:20 +00002399 static const size_t resultPtsSizes2[] = { 1, 2, 2, 0 };
2400 static const size_t resultPtsSizes3[] = { 1, 2, 2, 2, 1, 0 };
2401 static const size_t resultPtsSizes4[] = { 1, 2, 1, 1, 0 };
2402 static const size_t resultPtsSizes5[] = { 1, 2, 1, 1, 1, 0 };
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002403 static const SkPoint* resultPts1 = 0;
schenney@chromium.org7e963602012-06-13 17:05:43 +00002404 static const SkPoint resultPts2[] = {
2405 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 }
2406 };
2407 static const SkPoint resultPts3[] = {
2408 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 },
2409 { 0, SK_Scalar1 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }
2410 };
2411 static const SkPoint resultPts4[] = {
2412 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
2413 };
2414 static const SkPoint resultPts5[] = {
2415 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
2416 };
2417 static const struct iterTestData gIterTests[] = {
2418 { "M 1 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002419 { "M 1 0 M 2 0 M 3 0 M 4 0 M 5 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2420 { "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 +00002421 { "z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2422 { "z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2423 { "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) },
2424 { "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 +00002425 { "M 1 0 L 1 1 L 0 1 M 0 0 z", false, true, resultPtsSizes2, resultPts2, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
2426 { "M 1 0 L 1 1 L 0 1 M 0 0 z", true, true, resultPtsSizes3, resultPts3, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
2427 { "M 1 0 L 1 0 M 0 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2428 { "M 1 0 L 1 0 M 0 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2429 { "M 1 0 L 1 0 M 0 0 z", false, false, resultPtsSizes4, resultPts4, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
2430 { "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 +00002431 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002432
schenney@chromium.org7e963602012-06-13 17:05:43 +00002433 for (size_t i = 0; i < SK_ARRAY_COUNT(gIterTests); ++i) {
2434 p.reset();
2435 bool valid = SkParsePath::FromSVGString(gIterTests[i].testPath, &p);
2436 REPORTER_ASSERT(reporter, valid);
2437 iter.setPath(p, gIterTests[i].forceClose);
2438 int j = 0, l = 0;
2439 do {
2440 REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegenerates) == gIterTests[i].resultVerbs[j]);
2441 for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k) {
2442 REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]);
2443 }
2444 } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb);
2445 REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs);
2446 }
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002447
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002448 p.reset();
2449 iter.setPath(p, false);
2450 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2451 p.lineTo(1, 1);
2452 p.close();
2453 iter.setPath(p, false);
2454 REPORTER_ASSERT(reporter, iter.isClosedContour());
2455 p.reset();
2456 iter.setPath(p, true);
2457 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2458 p.lineTo(1, 1);
2459 iter.setPath(p, true);
2460 REPORTER_ASSERT(reporter, iter.isClosedContour());
2461 p.moveTo(0, 0);
2462 p.lineTo(2, 2);
2463 iter.setPath(p, false);
2464 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2465
2466 // this checks to see if the NaN logic is executed in SkPath::autoClose(), but does not
2467 // check to see if the result is correct.
2468 for (int setNaN = 0; setNaN < 4; ++setNaN) {
2469 p.reset();
2470 p.moveTo(setNaN == 0 ? SK_ScalarNaN : 0, setNaN == 1 ? SK_ScalarNaN : 0);
2471 p.lineTo(setNaN == 2 ? SK_ScalarNaN : 1, setNaN == 3 ? SK_ScalarNaN : 1);
2472 iter.setPath(p, true);
2473 iter.next(pts, false);
2474 iter.next(pts, false);
2475 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == iter.next(pts, false));
2476 }
2477
2478 p.reset();
2479 p.quadTo(0, 0, 0, 0);
2480 iter.setPath(p, false);
2481 iter.next(pts, false);
2482 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == iter.next(pts, false));
2483 iter.setPath(p, false);
2484 iter.next(pts, false);
2485 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2486
2487 p.reset();
2488 p.conicTo(0, 0, 0, 0, 0.5f);
2489 iter.setPath(p, false);
2490 iter.next(pts, false);
2491 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts, false));
2492 iter.setPath(p, false);
2493 iter.next(pts, false);
2494 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2495
2496 p.reset();
2497 p.cubicTo(0, 0, 0, 0, 0, 0);
2498 iter.setPath(p, false);
2499 iter.next(pts, false);
2500 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
2501 iter.setPath(p, false);
2502 iter.next(pts, false);
2503 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2504
2505 p.moveTo(1, 1); // add a trailing moveto
2506 iter.setPath(p, false);
2507 iter.next(pts, false);
2508 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
2509 iter.setPath(p, false);
2510 iter.next(pts, false);
2511 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2512
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002513 // The GM degeneratesegments.cpp test is more extensive
robertphillipsb8de1f42015-02-23 11:17:01 -08002514
2515 // Test out mixed degenerate and non-degenerate geometry with Conics
2516 const SkVector radii[4] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 100, 100 } };
2517 SkRect r = SkRect::MakeWH(100, 100);
2518 SkRRect rr;
2519 rr.setRectRadii(r, radii);
2520 p.reset();
2521 p.addRRect(rr);
2522 iter.setPath(p, false);
2523 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == iter.next(pts));
2524 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == iter.next(pts));
2525 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == iter.next(pts));
2526 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts));
2527 REPORTER_ASSERT(reporter, SK_ScalarRoot2Over2 == iter.conicWeight());
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002528}
2529
2530static void test_raw_iter(skiatest::Reporter* reporter) {
2531 SkPath p;
2532 SkPoint pts[4];
2533
2534 // Test an iterator with no path
2535 SkPath::RawIter noPathIter;
2536 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
2537 // Test that setting an empty path works
2538 noPathIter.setPath(p);
2539 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
rmistry@google.comd6176b02012-08-23 18:14:13 +00002540
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002541 // Test an iterator with an initial empty path
2542 SkPath::RawIter iter(p);
2543 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2544
2545 // Test that a move-only path returns the move.
2546 p.moveTo(SK_Scalar1, 0);
2547 iter.setPath(p);
2548 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2549 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2550 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2551 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2552
2553 // No matter how many moves we add, we should get them all back
2554 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2555 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2556 iter.setPath(p);
2557 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2558 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2559 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2560 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2561 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2562 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2563 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2564 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2565 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2566 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2567
2568 // Initial close is never ever stored
2569 p.reset();
2570 p.close();
2571 iter.setPath(p);
2572 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2573
2574 // Move/close sequences
2575 p.reset();
2576 p.close(); // Not stored, no purpose
2577 p.moveTo(SK_Scalar1, 0);
2578 p.close();
2579 p.close(); // Not stored, no purpose
2580 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2581 p.close();
2582 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2583 p.moveTo(SK_Scalar1*4, SK_Scalar1*3);
2584 p.close();
2585 iter.setPath(p);
2586 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2587 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2588 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2589 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2590 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2591 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2592 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2593 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2594 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2595 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2596 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2597 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2598 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2599 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2600 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2601 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2602 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2603 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2604 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2605 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2606 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2607 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2608
2609 // Generate random paths and verify
2610 SkPoint randomPts[25];
2611 for (int i = 0; i < 5; ++i) {
2612 for (int j = 0; j < 5; ++j) {
2613 randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j);
2614 }
2615 }
2616
2617 // Max of 10 segments, max 3 points per segment
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +00002618 SkRandom rand(9876543);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002619 SkPoint expectedPts[31]; // May have leading moveTo
reed@google.comd335d1d2012-01-12 18:17:11 +00002620 SkPath::Verb expectedVerbs[22]; // May have leading moveTo
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002621 SkPath::Verb nextVerb;
reed@google.comd335d1d2012-01-12 18:17:11 +00002622
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002623 for (int i = 0; i < 500; ++i) {
2624 p.reset();
2625 bool lastWasClose = true;
2626 bool haveMoveTo = false;
reed@google.comd335d1d2012-01-12 18:17:11 +00002627 SkPoint lastMoveToPt = { 0, 0 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002628 int numPoints = 0;
2629 int numVerbs = (rand.nextU() >> 16) % 10;
2630 int numIterVerbs = 0;
2631 for (int j = 0; j < numVerbs; ++j) {
2632 do {
2633 nextVerb = static_cast<SkPath::Verb>((rand.nextU() >> 16) % SkPath::kDone_Verb);
2634 } while (lastWasClose && nextVerb == SkPath::kClose_Verb);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002635 switch (nextVerb) {
2636 case SkPath::kMove_Verb:
2637 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2638 p.moveTo(expectedPts[numPoints]);
reed@google.comd335d1d2012-01-12 18:17:11 +00002639 lastMoveToPt = expectedPts[numPoints];
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002640 numPoints += 1;
2641 lastWasClose = false;
2642 haveMoveTo = true;
2643 break;
2644 case SkPath::kLine_Verb:
2645 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002646 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002647 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2648 haveMoveTo = true;
2649 }
2650 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2651 p.lineTo(expectedPts[numPoints]);
2652 numPoints += 1;
2653 lastWasClose = false;
2654 break;
2655 case SkPath::kQuad_Verb:
2656 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002657 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002658 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2659 haveMoveTo = true;
2660 }
2661 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2662 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2663 p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]);
2664 numPoints += 2;
2665 lastWasClose = false;
2666 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002667 case SkPath::kConic_Verb:
2668 if (!haveMoveTo) {
2669 expectedPts[numPoints++] = lastMoveToPt;
2670 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2671 haveMoveTo = true;
2672 }
2673 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2674 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2675 p.conicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2676 rand.nextUScalar1() * 4);
2677 numPoints += 2;
2678 lastWasClose = false;
2679 break;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002680 case SkPath::kCubic_Verb:
2681 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002682 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002683 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2684 haveMoveTo = true;
2685 }
2686 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2687 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2688 expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25];
2689 p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2690 expectedPts[numPoints + 2]);
2691 numPoints += 3;
2692 lastWasClose = false;
2693 break;
2694 case SkPath::kClose_Verb:
2695 p.close();
reed@google.comd335d1d2012-01-12 18:17:11 +00002696 haveMoveTo = false;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002697 lastWasClose = true;
2698 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002699 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002700 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002701 }
2702 expectedVerbs[numIterVerbs++] = nextVerb;
2703 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00002704
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002705 iter.setPath(p);
2706 numVerbs = numIterVerbs;
2707 numIterVerbs = 0;
2708 int numIterPts = 0;
2709 SkPoint lastMoveTo;
2710 SkPoint lastPt;
2711 lastMoveTo.set(0, 0);
2712 lastPt.set(0, 0);
2713 while ((nextVerb = iter.next(pts)) != SkPath::kDone_Verb) {
2714 REPORTER_ASSERT(reporter, nextVerb == expectedVerbs[numIterVerbs]);
2715 numIterVerbs++;
2716 switch (nextVerb) {
2717 case SkPath::kMove_Verb:
2718 REPORTER_ASSERT(reporter, numIterPts < numPoints);
2719 REPORTER_ASSERT(reporter, pts[0] == expectedPts[numIterPts]);
2720 lastPt = lastMoveTo = pts[0];
2721 numIterPts += 1;
2722 break;
2723 case SkPath::kLine_Verb:
2724 REPORTER_ASSERT(reporter, numIterPts < numPoints + 1);
2725 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2726 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2727 lastPt = pts[1];
2728 numIterPts += 1;
2729 break;
2730 case SkPath::kQuad_Verb:
reed@google.com277c3f82013-05-31 15:17:50 +00002731 case SkPath::kConic_Verb:
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002732 REPORTER_ASSERT(reporter, numIterPts < numPoints + 2);
2733 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2734 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2735 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2736 lastPt = pts[2];
2737 numIterPts += 2;
2738 break;
2739 case SkPath::kCubic_Verb:
2740 REPORTER_ASSERT(reporter, numIterPts < numPoints + 3);
2741 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2742 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2743 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2744 REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]);
2745 lastPt = pts[3];
2746 numIterPts += 3;
2747 break;
2748 case SkPath::kClose_Verb:
2749 REPORTER_ASSERT(reporter, pts[0] == lastMoveTo);
2750 lastPt = lastMoveTo;
2751 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002752 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002753 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002754 }
2755 }
2756 REPORTER_ASSERT(reporter, numIterPts == numPoints);
2757 REPORTER_ASSERT(reporter, numIterVerbs == numVerbs);
2758 }
2759}
2760
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002761static void check_for_circle(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002762 const SkPath& path,
2763 bool expectedCircle,
2764 SkPath::Direction expectedDir) {
robertphillips@google.com466310d2013-12-03 16:43:54 +00002765 SkRect rect = SkRect::MakeEmpty();
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002766 REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle);
2767 REPORTER_ASSERT(reporter, path.cheapIsDirection(expectedDir));
skia.committer@gmail.comfbb0ed92012-11-13 21:46:06 +00002768
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002769 if (expectedCircle) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002770 REPORTER_ASSERT(reporter, rect.height() == rect.width());
2771 }
2772}
2773
2774static void test_circle_skew(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002775 const SkPath& path,
2776 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002777 SkPath tmp;
2778
2779 SkMatrix m;
2780 m.setSkew(SkIntToScalar(3), SkIntToScalar(5));
2781 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002782 // this matrix reverses the direction.
2783 if (SkPath::kCCW_Direction == dir) {
2784 dir = SkPath::kCW_Direction;
2785 } else {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002786 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002787 dir = SkPath::kCCW_Direction;
2788 }
2789 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002790}
2791
2792static void test_circle_translate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002793 const SkPath& path,
2794 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002795 SkPath tmp;
2796
2797 // translate at small offset
2798 SkMatrix m;
2799 m.setTranslate(SkIntToScalar(15), SkIntToScalar(15));
2800 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002801 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002802
2803 tmp.reset();
2804 m.reset();
2805
2806 // translate at a relatively big offset
2807 m.setTranslate(SkIntToScalar(1000), SkIntToScalar(1000));
2808 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002809 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002810}
2811
2812static void test_circle_rotate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002813 const SkPath& path,
2814 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002815 for (int angle = 0; angle < 360; ++angle) {
2816 SkPath tmp;
2817 SkMatrix m;
2818 m.setRotate(SkIntToScalar(angle));
2819 path.transform(m, &tmp);
2820
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002821 // TODO: a rotated circle whose rotated angle is not a multiple of 90
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002822 // degrees is not an oval anymore, this can be improved. we made this
2823 // for the simplicity of our implementation.
2824 if (angle % 90 == 0) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002825 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002826 } else {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002827 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002828 }
2829 }
2830}
2831
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002832static void test_circle_mirror_x(skiatest::Reporter* reporter,
2833 const SkPath& path,
2834 SkPath::Direction dir) {
2835 SkPath tmp;
2836 SkMatrix m;
2837 m.reset();
2838 m.setScaleX(-SK_Scalar1);
2839 path.transform(m, &tmp);
2840
2841 if (SkPath::kCW_Direction == dir) {
2842 dir = SkPath::kCCW_Direction;
2843 } else {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002844 REPORTER_ASSERT(reporter, SkPath::kCCW_Direction == dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002845 dir = SkPath::kCW_Direction;
2846 }
2847
2848 check_for_circle(reporter, tmp, true, dir);
2849}
2850
2851static void test_circle_mirror_y(skiatest::Reporter* reporter,
2852 const SkPath& path,
2853 SkPath::Direction dir) {
2854 SkPath tmp;
2855 SkMatrix m;
2856 m.reset();
2857 m.setScaleY(-SK_Scalar1);
2858 path.transform(m, &tmp);
2859
2860 if (SkPath::kCW_Direction == dir) {
2861 dir = SkPath::kCCW_Direction;
2862 } else {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002863 REPORTER_ASSERT(reporter, SkPath::kCCW_Direction == dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002864 dir = SkPath::kCW_Direction;
2865 }
2866
2867 check_for_circle(reporter, tmp, true, dir);
2868}
2869
2870static void test_circle_mirror_xy(skiatest::Reporter* reporter,
2871 const SkPath& path,
2872 SkPath::Direction dir) {
2873 SkPath tmp;
2874 SkMatrix m;
2875 m.reset();
2876 m.setScaleX(-SK_Scalar1);
2877 m.setScaleY(-SK_Scalar1);
2878 path.transform(m, &tmp);
2879
2880 check_for_circle(reporter, tmp, true, dir);
2881}
2882
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002883static void test_circle_with_direction(skiatest::Reporter* reporter,
2884 SkPath::Direction dir) {
2885 SkPath path;
2886
2887 // circle at origin
2888 path.addCircle(0, 0, SkIntToScalar(20), dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002889 check_for_circle(reporter, path, true, dir);
2890 test_circle_rotate(reporter, path, dir);
2891 test_circle_translate(reporter, path, dir);
2892 test_circle_skew(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002893
2894 // circle at an offset at (10, 10)
2895 path.reset();
2896 path.addCircle(SkIntToScalar(10), SkIntToScalar(10),
2897 SkIntToScalar(20), dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002898 check_for_circle(reporter, path, true, dir);
2899 test_circle_rotate(reporter, path, dir);
2900 test_circle_translate(reporter, path, dir);
2901 test_circle_skew(reporter, path, dir);
2902 test_circle_mirror_x(reporter, path, dir);
2903 test_circle_mirror_y(reporter, path, dir);
2904 test_circle_mirror_xy(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002905}
2906
2907static void test_circle_with_add_paths(skiatest::Reporter* reporter) {
2908 SkPath path;
2909 SkPath circle;
2910 SkPath rect;
2911 SkPath empty;
2912
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002913 static const SkPath::Direction kCircleDir = SkPath::kCW_Direction;
2914 static const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction;
2915
2916 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002917 rect.addRect(SkIntToScalar(5), SkIntToScalar(5),
2918 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction);
2919
2920 SkMatrix translate;
2921 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12));
2922
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00002923 // Although all the path concatenation related operations leave
2924 // the path a circle, most mark it as a non-circle for simplicity
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002925
2926 // empty + circle (translate)
2927 path = empty;
2928 path.addPath(circle, translate);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002929 check_for_circle(reporter, path, false, kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002930
2931 // circle + empty (translate)
2932 path = circle;
2933 path.addPath(empty, translate);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00002934 check_for_circle(reporter, path, true, kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002935
2936 // test reverseAddPath
2937 path = circle;
2938 path.reverseAddPath(rect);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002939 check_for_circle(reporter, path, false, kCircleDirOpposite);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002940}
2941
2942static void test_circle(skiatest::Reporter* reporter) {
2943 test_circle_with_direction(reporter, SkPath::kCW_Direction);
2944 test_circle_with_direction(reporter, SkPath::kCCW_Direction);
2945
2946 // multiple addCircle()
2947 SkPath path;
2948 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2949 path.addCircle(0, 0, SkIntToScalar(20), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002950 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002951
2952 // some extra lineTo() would make isOval() fail
2953 path.reset();
2954 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2955 path.lineTo(0, 0);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002956 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002957
2958 // not back to the original point
2959 path.reset();
2960 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2961 path.setLastPt(SkIntToScalar(5), SkIntToScalar(5));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002962 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002963
2964 test_circle_with_add_paths(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002965
2966 // test negative radius
2967 path.reset();
2968 path.addCircle(0, 0, -1, SkPath::kCW_Direction);
2969 REPORTER_ASSERT(reporter, path.isEmpty());
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002970}
2971
2972static void test_oval(skiatest::Reporter* reporter) {
2973 SkRect rect;
2974 SkMatrix m;
2975 SkPath path;
2976
2977 rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50));
2978 path.addOval(rect);
2979
2980 REPORTER_ASSERT(reporter, path.isOval(NULL));
2981
2982 m.setRotate(SkIntToScalar(90));
2983 SkPath tmp;
2984 path.transform(m, &tmp);
2985 // an oval rotated 90 degrees is still an oval.
2986 REPORTER_ASSERT(reporter, tmp.isOval(NULL));
2987
2988 m.reset();
2989 m.setRotate(SkIntToScalar(30));
2990 tmp.reset();
2991 path.transform(m, &tmp);
2992 // an oval rotated 30 degrees is not an oval anymore.
2993 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2994
2995 // since empty path being transformed.
2996 path.reset();
2997 tmp.reset();
2998 m.reset();
2999 path.transform(m, &tmp);
3000 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
3001
3002 // empty path is not an oval
3003 tmp.reset();
3004 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
3005
3006 // only has moveTo()s
3007 tmp.reset();
3008 tmp.moveTo(0, 0);
3009 tmp.moveTo(SkIntToScalar(10), SkIntToScalar(10));
3010 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
3011
3012 // mimic WebKit's calling convention,
3013 // call moveTo() first and then call addOval()
3014 path.reset();
3015 path.moveTo(0, 0);
3016 path.addOval(rect);
3017 REPORTER_ASSERT(reporter, path.isOval(NULL));
3018
3019 // copy path
3020 path.reset();
3021 tmp.reset();
3022 tmp.addOval(rect);
3023 path = tmp;
3024 REPORTER_ASSERT(reporter, path.isOval(NULL));
3025}
3026
bungeman@google.coma5809a32013-06-21 15:13:34 +00003027static void test_empty(skiatest::Reporter* reporter, const SkPath& p) {
3028 SkPath empty;
reed@android.com80e39a72009-04-02 16:59:40 +00003029
reed@android.com3abec1d2009-03-02 05:36:20 +00003030 REPORTER_ASSERT(reporter, p.isEmpty());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003031 REPORTER_ASSERT(reporter, 0 == p.countPoints());
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00003032 REPORTER_ASSERT(reporter, 0 == p.countVerbs());
reed@google.com10296cc2011-09-21 12:29:05 +00003033 REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks());
reed@google.comb54455e2011-05-16 14:16:04 +00003034 REPORTER_ASSERT(reporter, p.isConvex());
reed@android.com3abec1d2009-03-02 05:36:20 +00003035 REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType);
3036 REPORTER_ASSERT(reporter, !p.isInverseFillType());
bungeman@google.coma5809a32013-06-21 15:13:34 +00003037 REPORTER_ASSERT(reporter, p == empty);
3038 REPORTER_ASSERT(reporter, !(p != empty));
3039}
3040
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003041static void test_rrect_is_convex(skiatest::Reporter* reporter, SkPath* path,
3042 SkPath::Direction dir) {
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003043 REPORTER_ASSERT(reporter, path->isConvex());
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003044 REPORTER_ASSERT(reporter, path->cheapIsDirection(dir));
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003045 path->setConvexity(SkPath::kUnknown_Convexity);
3046 REPORTER_ASSERT(reporter, path->isConvex());
3047 path->reset();
3048}
3049
caryclarkd3d1a982014-12-08 04:57:38 -08003050static void test_rrect_convexity_is_unknown(skiatest::Reporter* reporter, SkPath* path,
3051 SkPath::Direction dir) {
3052 REPORTER_ASSERT(reporter, path->isConvex());
3053 REPORTER_ASSERT(reporter, path->cheapIsDirection(dir));
3054 path->setConvexity(SkPath::kUnknown_Convexity);
3055 REPORTER_ASSERT(reporter, path->getConvexity() == SkPath::kUnknown_Convexity);
3056 path->reset();
3057}
3058
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003059static void test_rrect(skiatest::Reporter* reporter) {
3060 SkPath p;
3061 SkRRect rr;
3062 SkVector radii[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
3063 SkRect r = {10, 20, 30, 40};
3064 rr.setRectRadii(r, radii);
3065 p.addRRect(rr);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003066 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003067 p.addRRect(rr, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003068 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003069 p.addRoundRect(r, &radii[0].fX);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003070 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003071 p.addRoundRect(r, &radii[0].fX, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003072 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003073 p.addRoundRect(r, radii[1].fX, radii[1].fY);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003074 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003075 p.addRoundRect(r, radii[1].fX, radii[1].fY, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003076 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
3077 for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) {
3078 SkVector save = radii[i];
3079 radii[i].set(0, 0);
3080 rr.setRectRadii(r, radii);
3081 p.addRRect(rr);
3082 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3083 radii[i] = save;
3084 }
3085 p.addRoundRect(r, 0, 0);
3086 SkRect returnedRect;
3087 REPORTER_ASSERT(reporter, p.isRect(&returnedRect));
3088 REPORTER_ASSERT(reporter, returnedRect == r);
3089 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3090 SkVector zeroRadii[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
3091 rr.setRectRadii(r, zeroRadii);
3092 p.addRRect(rr);
3093 bool closed;
3094 SkPath::Direction dir;
robertphillips91b0a352015-01-05 10:13:46 -08003095 REPORTER_ASSERT(reporter, p.isRect(NULL, &closed, &dir));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003096 REPORTER_ASSERT(reporter, closed);
3097 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
3098 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3099 p.addRRect(rr, SkPath::kCW_Direction);
3100 p.addRRect(rr, SkPath::kCW_Direction);
3101 REPORTER_ASSERT(reporter, !p.isConvex());
3102 p.reset();
3103 p.addRRect(rr, SkPath::kCCW_Direction);
3104 p.addRRect(rr, SkPath::kCCW_Direction);
3105 REPORTER_ASSERT(reporter, !p.isConvex());
3106 p.reset();
3107 SkRect emptyR = {10, 20, 10, 30};
3108 rr.setRectRadii(emptyR, radii);
3109 p.addRRect(rr);
3110 REPORTER_ASSERT(reporter, p.isEmpty());
3111 SkRect largeR = {0, 0, SK_ScalarMax, SK_ScalarMax};
3112 rr.setRectRadii(largeR, radii);
3113 p.addRRect(rr);
caryclarkd3d1a982014-12-08 04:57:38 -08003114 test_rrect_convexity_is_unknown(reporter, &p, SkPath::kCW_Direction);
reed454fa712015-02-10 08:46:22 -08003115
3116 // we check for non-finites
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003117 SkRect infR = {0, 0, SK_ScalarMax, SK_ScalarInfinity};
3118 rr.setRectRadii(infR, radii);
reed454fa712015-02-10 08:46:22 -08003119 REPORTER_ASSERT(reporter, rr.isEmpty());
3120
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003121 SkRect tinyR = {0, 0, 1e-9f, 1e-9f};
3122 p.addRoundRect(tinyR, 5e-11f, 5e-11f);
3123 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003124}
3125
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003126static void test_arc(skiatest::Reporter* reporter) {
3127 SkPath p;
3128 SkRect emptyOval = {10, 20, 30, 20};
3129 REPORTER_ASSERT(reporter, emptyOval.isEmpty());
3130 p.addArc(emptyOval, 1, 2);
3131 REPORTER_ASSERT(reporter, p.isEmpty());
3132 p.reset();
3133 SkRect oval = {10, 20, 30, 40};
3134 p.addArc(oval, 1, 0);
3135 REPORTER_ASSERT(reporter, p.isEmpty());
3136 p.reset();
3137 SkPath cwOval;
3138 cwOval.addOval(oval);
3139 p.addArc(oval, 1, 360);
3140 REPORTER_ASSERT(reporter, p == cwOval);
3141 p.reset();
3142 SkPath ccwOval;
3143 ccwOval.addOval(oval, SkPath::kCCW_Direction);
3144 p.addArc(oval, 1, -360);
3145 REPORTER_ASSERT(reporter, p == ccwOval);
3146 p.reset();
3147 p.addArc(oval, 1, 180);
3148 REPORTER_ASSERT(reporter, p.isConvex());
3149 REPORTER_ASSERT(reporter, p.cheapIsDirection(SkPath::kCW_Direction));
3150 p.setConvexity(SkPath::kUnknown_Convexity);
3151 REPORTER_ASSERT(reporter, p.isConvex());
3152}
3153
3154static void check_move(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3155 SkScalar x0, SkScalar y0) {
3156 SkPoint pts[4];
3157 SkPath::Verb v = iter->next(pts);
3158 REPORTER_ASSERT(reporter, v == SkPath::kMove_Verb);
3159 REPORTER_ASSERT(reporter, pts[0].fX == x0);
3160 REPORTER_ASSERT(reporter, pts[0].fY == y0);
3161}
3162
3163static void check_line(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3164 SkScalar x1, SkScalar y1) {
3165 SkPoint pts[4];
3166 SkPath::Verb v = iter->next(pts);
3167 REPORTER_ASSERT(reporter, v == SkPath::kLine_Verb);
3168 REPORTER_ASSERT(reporter, pts[1].fX == x1);
3169 REPORTER_ASSERT(reporter, pts[1].fY == y1);
3170}
3171
3172static void check_quad(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3173 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3174 SkPoint pts[4];
3175 SkPath::Verb v = iter->next(pts);
3176 REPORTER_ASSERT(reporter, v == SkPath::kQuad_Verb);
3177 REPORTER_ASSERT(reporter, pts[1].fX == x1);
3178 REPORTER_ASSERT(reporter, pts[1].fY == y1);
3179 REPORTER_ASSERT(reporter, pts[2].fX == x2);
3180 REPORTER_ASSERT(reporter, pts[2].fY == y2);
3181}
3182
3183static void check_done(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
3184 SkPoint pts[4];
3185 SkPath::Verb v = iter->next(pts);
3186 REPORTER_ASSERT(reporter, v == SkPath::kDone_Verb);
3187}
3188
3189static void check_done_and_reset(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
3190 check_done(reporter, p, iter);
3191 p->reset();
3192}
3193
3194static void check_path_is_move_and_reset(skiatest::Reporter* reporter, SkPath* p,
3195 SkScalar x0, SkScalar y0) {
3196 SkPath::RawIter iter(*p);
3197 check_move(reporter, &iter, x0, y0);
3198 check_done_and_reset(reporter, p, &iter);
3199}
3200
3201static void check_path_is_line_and_reset(skiatest::Reporter* reporter, SkPath* p,
3202 SkScalar x1, SkScalar y1) {
3203 SkPath::RawIter iter(*p);
3204 check_move(reporter, &iter, 0, 0);
3205 check_line(reporter, &iter, x1, y1);
3206 check_done_and_reset(reporter, p, &iter);
3207}
3208
3209static void check_path_is_line(skiatest::Reporter* reporter, SkPath* p,
3210 SkScalar x1, SkScalar y1) {
3211 SkPath::RawIter iter(*p);
3212 check_move(reporter, &iter, 0, 0);
3213 check_line(reporter, &iter, x1, y1);
3214 check_done(reporter, p, &iter);
3215}
3216
3217static void check_path_is_line_pair_and_reset(skiatest::Reporter* reporter, SkPath* p,
3218 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3219 SkPath::RawIter iter(*p);
3220 check_move(reporter, &iter, 0, 0);
3221 check_line(reporter, &iter, x1, y1);
3222 check_line(reporter, &iter, x2, y2);
3223 check_done_and_reset(reporter, p, &iter);
3224}
3225
3226static void check_path_is_quad_and_reset(skiatest::Reporter* reporter, SkPath* p,
3227 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3228 SkPath::RawIter iter(*p);
3229 check_move(reporter, &iter, 0, 0);
3230 check_quad(reporter, &iter, x1, y1, x2, y2);
3231 check_done_and_reset(reporter, p, &iter);
3232}
3233
reedd5d27d92015-02-09 13:54:43 -08003234static bool nearly_equal(const SkRect& a, const SkRect& b) {
3235 return SkScalarNearlyEqual(a.fLeft, b.fLeft) &&
3236 SkScalarNearlyEqual(a.fTop, b.fTop) &&
3237 SkScalarNearlyEqual(a.fRight, b.fRight) &&
3238 SkScalarNearlyEqual(a.fBottom, b.fBottom);
3239}
3240
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003241static void test_arcTo(skiatest::Reporter* reporter) {
3242 SkPath p;
3243 p.arcTo(0, 0, 1, 2, 1);
3244 check_path_is_line_and_reset(reporter, &p, 0, 0);
3245 p.arcTo(1, 2, 1, 2, 1);
3246 check_path_is_line_and_reset(reporter, &p, 1, 2);
3247 p.arcTo(1, 2, 3, 4, 0);
3248 check_path_is_line_and_reset(reporter, &p, 1, 2);
3249 p.arcTo(1, 2, 0, 0, 1);
3250 check_path_is_line_and_reset(reporter, &p, 1, 2);
3251 p.arcTo(1, 0, 1, 1, 1);
3252 SkPoint pt;
3253 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == 1);
3254 p.reset();
3255 p.arcTo(1, 0, 1, -1, 1);
3256 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == -1);
3257 p.reset();
3258 SkRect oval = {1, 2, 3, 4};
3259 p.arcTo(oval, 0, 0, true);
3260 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3261 p.arcTo(oval, 0, 0, false);
3262 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3263 p.arcTo(oval, 360, 0, true);
3264 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3265 p.arcTo(oval, 360, 0, false);
3266 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
reedd5d27d92015-02-09 13:54:43 -08003267
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003268 for (float sweep = 359, delta = 0.5f; sweep != (float) (sweep + delta); ) {
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00003269 p.arcTo(oval, 0, sweep, false);
reedd5d27d92015-02-09 13:54:43 -08003270 REPORTER_ASSERT(reporter, nearly_equal(p.getBounds(), oval));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003271 sweep += delta;
3272 delta /= 2;
3273 }
3274 for (float sweep = 361, delta = 0.5f; sweep != (float) (sweep - delta);) {
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00003275 p.arcTo(oval, 0, sweep, false);
reedd5d27d92015-02-09 13:54:43 -08003276 REPORTER_ASSERT(reporter, nearly_equal(p.getBounds(), oval));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003277 sweep -= delta;
3278 delta /= 2;
3279 }
3280 SkRect noOvalWidth = {1, 2, 0, 3};
3281 p.reset();
3282 p.arcTo(noOvalWidth, 0, 360, false);
3283 REPORTER_ASSERT(reporter, p.isEmpty());
3284
3285 SkRect noOvalHeight = {1, 2, 3, 1};
3286 p.reset();
3287 p.arcTo(noOvalHeight, 0, 360, false);
3288 REPORTER_ASSERT(reporter, p.isEmpty());
3289}
3290
3291static void test_addPath(skiatest::Reporter* reporter) {
3292 SkPath p, q;
3293 p.lineTo(1, 2);
3294 q.moveTo(4, 4);
3295 q.lineTo(7, 8);
3296 q.conicTo(8, 7, 6, 5, 0.5f);
3297 q.quadTo(6, 7, 8, 6);
3298 q.cubicTo(5, 6, 7, 8, 7, 5);
3299 q.close();
3300 p.addPath(q, -4, -4);
3301 SkRect expected = {0, 0, 4, 4};
3302 REPORTER_ASSERT(reporter, p.getBounds() == expected);
3303 p.reset();
3304 p.reverseAddPath(q);
3305 SkRect reverseExpected = {4, 4, 8, 8};
3306 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
3307}
3308
commit-bot@chromium.org14747e52014-02-11 21:16:29 +00003309static void test_addPathMode(skiatest::Reporter* reporter, bool explicitMoveTo, bool extend) {
3310 SkPath p, q;
3311 if (explicitMoveTo) {
3312 p.moveTo(1, 1);
3313 }
3314 p.lineTo(1, 2);
3315 if (explicitMoveTo) {
3316 q.moveTo(2, 1);
3317 }
3318 q.lineTo(2, 2);
3319 p.addPath(q, extend ? SkPath::kExtend_AddPathMode : SkPath::kAppend_AddPathMode);
3320 uint8_t verbs[4];
3321 int verbcount = p.getVerbs(verbs, 4);
3322 REPORTER_ASSERT(reporter, verbcount == 4);
3323 REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
3324 REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
3325 REPORTER_ASSERT(reporter, verbs[2] == (extend ? SkPath::kLine_Verb : SkPath::kMove_Verb));
3326 REPORTER_ASSERT(reporter, verbs[3] == SkPath::kLine_Verb);
3327}
3328
3329static void test_extendClosedPath(skiatest::Reporter* reporter) {
3330 SkPath p, q;
3331 p.moveTo(1, 1);
3332 p.lineTo(1, 2);
3333 p.lineTo(2, 2);
3334 p.close();
3335 q.moveTo(2, 1);
3336 q.lineTo(2, 3);
3337 p.addPath(q, SkPath::kExtend_AddPathMode);
3338 uint8_t verbs[7];
3339 int verbcount = p.getVerbs(verbs, 7);
3340 REPORTER_ASSERT(reporter, verbcount == 7);
3341 REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
3342 REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
3343 REPORTER_ASSERT(reporter, verbs[2] == SkPath::kLine_Verb);
3344 REPORTER_ASSERT(reporter, verbs[3] == SkPath::kClose_Verb);
3345 REPORTER_ASSERT(reporter, verbs[4] == SkPath::kMove_Verb);
3346 REPORTER_ASSERT(reporter, verbs[5] == SkPath::kLine_Verb);
3347 REPORTER_ASSERT(reporter, verbs[6] == SkPath::kLine_Verb);
3348
3349 SkPoint pt;
3350 REPORTER_ASSERT(reporter, p.getLastPt(&pt));
3351 REPORTER_ASSERT(reporter, pt == SkPoint::Make(2, 3));
3352 REPORTER_ASSERT(reporter, p.getPoint(3) == SkPoint::Make(1, 1));
3353}
3354
3355static void test_addEmptyPath(skiatest::Reporter* reporter, SkPath::AddPathMode mode) {
3356 SkPath p, q, r;
3357 // case 1: dst is empty
3358 p.moveTo(2, 1);
3359 p.lineTo(2, 3);
3360 q.addPath(p, mode);
3361 REPORTER_ASSERT(reporter, q == p);
3362 // case 2: src is empty
3363 p.addPath(r, mode);
3364 REPORTER_ASSERT(reporter, q == p);
3365 // case 3: src and dst are empty
3366 q.reset();
3367 q.addPath(r, mode);
3368 REPORTER_ASSERT(reporter, q.isEmpty());
skia.committer@gmail.com877c4492014-02-12 03:02:04 +00003369}
commit-bot@chromium.org14747e52014-02-11 21:16:29 +00003370
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003371static void test_conicTo_special_case(skiatest::Reporter* reporter) {
3372 SkPath p;
3373 p.conicTo(1, 2, 3, 4, -1);
3374 check_path_is_line_and_reset(reporter, &p, 3, 4);
3375 p.conicTo(1, 2, 3, 4, SK_ScalarInfinity);
3376 check_path_is_line_pair_and_reset(reporter, &p, 1, 2, 3, 4);
3377 p.conicTo(1, 2, 3, 4, 1);
3378 check_path_is_quad_and_reset(reporter, &p, 1, 2, 3, 4);
3379}
3380
3381static void test_get_point(skiatest::Reporter* reporter) {
3382 SkPath p;
3383 SkPoint pt = p.getPoint(0);
3384 REPORTER_ASSERT(reporter, pt == SkPoint::Make(0, 0));
3385 REPORTER_ASSERT(reporter, !p.getLastPt(NULL));
3386 REPORTER_ASSERT(reporter, !p.getLastPt(&pt) && pt == SkPoint::Make(0, 0));
3387 p.setLastPt(10, 10);
3388 pt = p.getPoint(0);
3389 REPORTER_ASSERT(reporter, pt == SkPoint::Make(10, 10));
3390 REPORTER_ASSERT(reporter, p.getLastPt(NULL));
3391 p.rMoveTo(10, 10);
3392 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt == SkPoint::Make(20, 20));
3393}
3394
3395static void test_contains(skiatest::Reporter* reporter) {
3396 SkPath p;
3397 p.setFillType(SkPath::kInverseWinding_FillType);
3398 REPORTER_ASSERT(reporter, p.contains(0, 0));
3399 p.setFillType(SkPath::kWinding_FillType);
3400 REPORTER_ASSERT(reporter, !p.contains(0, 0));
3401 p.moveTo(4, 4);
3402 p.lineTo(6, 8);
3403 p.lineTo(8, 4);
3404 // test quick reject
3405 REPORTER_ASSERT(reporter, !p.contains(4, 0));
3406 REPORTER_ASSERT(reporter, !p.contains(0, 4));
3407 REPORTER_ASSERT(reporter, !p.contains(4, 10));
3408 REPORTER_ASSERT(reporter, !p.contains(10, 4));
3409 // test various crossings in x
3410 REPORTER_ASSERT(reporter, !p.contains(5, 7));
3411 REPORTER_ASSERT(reporter, p.contains(6, 7));
3412 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3413 p.reset();
3414 p.moveTo(4, 4);
3415 p.lineTo(8, 6);
3416 p.lineTo(4, 8);
3417 // test various crossings in y
3418 REPORTER_ASSERT(reporter, !p.contains(7, 5));
3419 REPORTER_ASSERT(reporter, p.contains(7, 6));
3420 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3421 // test quads
3422 p.reset();
3423 p.moveTo(4, 4);
3424 p.quadTo(6, 6, 8, 8);
3425 p.quadTo(6, 8, 4, 8);
3426 p.quadTo(4, 6, 4, 4);
3427 REPORTER_ASSERT(reporter, p.contains(5, 6));
3428 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3429
3430 p.reset();
3431 p.moveTo(6, 6);
3432 p.quadTo(8, 8, 6, 8);
3433 p.quadTo(4, 8, 4, 6);
3434 p.quadTo(4, 4, 6, 6);
3435 REPORTER_ASSERT(reporter, p.contains(5, 6));
3436 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3437
3438#define CONIC_CONTAINS_BUG_FIXED 0
3439#if CONIC_CONTAINS_BUG_FIXED
3440 p.reset();
3441 p.moveTo(4, 4);
3442 p.conicTo(6, 6, 8, 8, 0.5f);
3443 p.conicTo(6, 8, 4, 8, 0.5f);
3444 p.conicTo(4, 6, 4, 4, 0.5f);
3445 REPORTER_ASSERT(reporter, p.contains(5, 6));
3446 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3447#endif
3448
3449 // test cubics
3450 SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5, 4}, {6, 5}, {7, 6}};
3451 for (int i = 0; i < 3; ++i) {
3452 p.reset();
3453 p.setFillType(SkPath::kEvenOdd_FillType);
3454 p.moveTo(pts[i].fX, pts[i].fY);
3455 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);
3456 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);
3457 p.close();
3458 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f));
3459 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f));
3460 }
3461}
3462
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003463class PathRefTest_Private {
3464public:
3465 static void TestPathRef(skiatest::Reporter* reporter) {
3466 static const int kRepeatCnt = 10;
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003467
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003468 SkAutoTUnref<SkPathRef> pathRef(SkNEW(SkPathRef));
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003469
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003470 SkPathRef::Editor ed(&pathRef);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003471
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003472 {
3473 ed.growForRepeatedVerb(SkPath::kMove_Verb, kRepeatCnt);
3474 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3475 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
3476 REPORTER_ASSERT(reporter, 0 == pathRef->getSegmentMasks());
3477 for (int i = 0; i < kRepeatCnt; ++i) {
3478 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == pathRef->atVerb(i));
3479 }
3480 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003481 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003482
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003483 {
3484 ed.growForRepeatedVerb(SkPath::kLine_Verb, kRepeatCnt);
3485 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3486 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
3487 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == pathRef->getSegmentMasks());
3488 for (int i = 0; i < kRepeatCnt; ++i) {
3489 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == pathRef->atVerb(i));
3490 }
3491 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003492 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003493
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003494 {
3495 ed.growForRepeatedVerb(SkPath::kQuad_Verb, kRepeatCnt);
3496 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3497 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
3498 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == pathRef->getSegmentMasks());
3499 for (int i = 0; i < kRepeatCnt; ++i) {
3500 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == pathRef->atVerb(i));
3501 }
3502 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003503 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003504
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003505 {
3506 SkScalar* weights = NULL;
3507 ed.growForRepeatedVerb(SkPath::kConic_Verb, kRepeatCnt, &weights);
3508 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3509 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
3510 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countWeights());
3511 REPORTER_ASSERT(reporter, SkPath::kConic_SegmentMask == pathRef->getSegmentMasks());
bsalomon49f085d2014-09-05 13:34:00 -07003512 REPORTER_ASSERT(reporter, weights);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003513 for (int i = 0; i < kRepeatCnt; ++i) {
3514 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == pathRef->atVerb(i));
3515 }
3516 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003517 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003518
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003519 {
3520 ed.growForRepeatedVerb(SkPath::kCubic_Verb, kRepeatCnt);
3521 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3522 REPORTER_ASSERT(reporter, 3*kRepeatCnt == pathRef->countPoints());
3523 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == pathRef->getSegmentMasks());
3524 for (int i = 0; i < kRepeatCnt; ++i) {
3525 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == pathRef->atVerb(i));
3526 }
3527 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003528 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003529 }
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003530};
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003531
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003532static void test_operatorEqual(skiatest::Reporter* reporter) {
3533 SkPath a;
3534 SkPath b;
3535 REPORTER_ASSERT(reporter, a == a);
3536 REPORTER_ASSERT(reporter, a == b);
3537 a.setFillType(SkPath::kInverseWinding_FillType);
3538 REPORTER_ASSERT(reporter, a != b);
3539 a.reset();
3540 REPORTER_ASSERT(reporter, a == b);
3541 a.lineTo(1, 1);
3542 REPORTER_ASSERT(reporter, a != b);
3543 a.reset();
3544 REPORTER_ASSERT(reporter, a == b);
3545 a.lineTo(1, 1);
3546 b.lineTo(1, 2);
3547 REPORTER_ASSERT(reporter, a != b);
3548 a.reset();
3549 a.lineTo(1, 2);
3550 REPORTER_ASSERT(reporter, a == b);
3551}
3552
caryclark66a5d8b2014-06-24 08:30:15 -07003553static void compare_dump(skiatest::Reporter* reporter, const SkPath& path, bool force,
caryclarke9562592014-09-15 09:26:09 -07003554 bool dumpAsHex, const char* str) {
caryclark66a5d8b2014-06-24 08:30:15 -07003555 SkDynamicMemoryWStream wStream;
caryclarke9562592014-09-15 09:26:09 -07003556 path.dump(&wStream, force, dumpAsHex);
caryclark66a5d8b2014-06-24 08:30:15 -07003557 SkAutoDataUnref data(wStream.copyToData());
3558 REPORTER_ASSERT(reporter, data->size() == strlen(str));
mtkleind4897592014-11-14 09:22:40 -08003559 if (strlen(str) > 0) {
3560 REPORTER_ASSERT(reporter, !memcmp(data->data(), str, strlen(str)));
3561 } else {
3562 REPORTER_ASSERT(reporter, data->data() == NULL || !memcmp(data->data(), str, strlen(str)));
3563 }
caryclark66a5d8b2014-06-24 08:30:15 -07003564}
3565
3566static void test_dump(skiatest::Reporter* reporter) {
3567 SkPath p;
caryclarke9562592014-09-15 09:26:09 -07003568 compare_dump(reporter, p, false, false, "");
3569 compare_dump(reporter, p, true, false, "");
caryclark66a5d8b2014-06-24 08:30:15 -07003570 p.moveTo(1, 2);
3571 p.lineTo(3, 4);
caryclarke9562592014-09-15 09:26:09 -07003572 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3573 "path.lineTo(3, 4);\n");
3574 compare_dump(reporter, p, true, false, "path.moveTo(1, 2);\n"
3575 "path.lineTo(3, 4);\n"
3576 "path.lineTo(1, 2);\n"
3577 "path.close();\n");
caryclark66a5d8b2014-06-24 08:30:15 -07003578 p.reset();
3579 p.moveTo(1, 2);
3580 p.quadTo(3, 4, 5, 6);
caryclarke9562592014-09-15 09:26:09 -07003581 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3582 "path.quadTo(3, 4, 5, 6);\n");
caryclark66a5d8b2014-06-24 08:30:15 -07003583 p.reset();
3584 p.moveTo(1, 2);
3585 p.conicTo(3, 4, 5, 6, 0.5f);
caryclarke9562592014-09-15 09:26:09 -07003586 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3587 "path.conicTo(3, 4, 5, 6, 0.5f);\n");
caryclark66a5d8b2014-06-24 08:30:15 -07003588 p.reset();
3589 p.moveTo(1, 2);
3590 p.cubicTo(3, 4, 5, 6, 7, 8);
caryclarke9562592014-09-15 09:26:09 -07003591 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3592 "path.cubicTo(3, 4, 5, 6, 7, 8);\n");
3593 p.reset();
3594 p.moveTo(1, 2);
3595 p.lineTo(3, 4);
caryclark08fa28c2014-10-23 13:08:56 -07003596 compare_dump(reporter, p, false, true,
3597 "path.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)); // 1, 2\n"
3598 "path.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)); // 3, 4\n");
caryclarke9562592014-09-15 09:26:09 -07003599 p.reset();
3600 p.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000));
3601 p.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000));
3602 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3603 "path.lineTo(3, 4);\n");
caryclark66a5d8b2014-06-24 08:30:15 -07003604}
3605
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003606class PathTest_Private {
3607public:
3608 static void TestPathTo(skiatest::Reporter* reporter) {
3609 SkPath p, q;
3610 p.lineTo(4, 4);
3611 p.reversePathTo(q);
3612 check_path_is_line(reporter, &p, 4, 4);
3613 q.moveTo(-4, -4);
3614 p.reversePathTo(q);
3615 check_path_is_line(reporter, &p, 4, 4);
3616 q.lineTo(7, 8);
3617 q.conicTo(8, 7, 6, 5, 0.5f);
3618 q.quadTo(6, 7, 8, 6);
3619 q.cubicTo(5, 6, 7, 8, 7, 5);
3620 q.close();
3621 p.reversePathTo(q);
3622 SkRect reverseExpected = {-4, -4, 8, 8};
3623 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
3624 }
3625};
3626
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00003627DEF_TEST(Paths, reporter) {
commit-bot@chromium.org4e332f82014-05-05 16:04:42 +00003628 test_path_crbug364224();
3629
bungeman@google.coma5809a32013-06-21 15:13:34 +00003630 SkTSize<SkScalar>::Make(3,4);
3631
3632 SkPath p, empty;
3633 SkRect bounds, bounds2;
3634 test_empty(reporter, p);
reed@android.com3abec1d2009-03-02 05:36:20 +00003635
reed@android.comd252db02009-04-01 18:31:44 +00003636 REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
reed@android.com80e39a72009-04-02 16:59:40 +00003637
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003638 // this triggers a code path in SkPath::operator= which is otherwise unexercised
3639 SkPath& self = p;
3640 p = self;
3641
3642 // this triggers a code path in SkPath::swap which is otherwise unexercised
3643 p.swap(self);
3644
reed@android.com3abec1d2009-03-02 05:36:20 +00003645 bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
reed@android.com6b82d1a2009-06-03 02:35:01 +00003646
reed@android.com6b82d1a2009-06-03 02:35:01 +00003647 p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1);
3648 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00003649 // we have quads or cubics
reed220f9262014-12-17 08:21:04 -08003650 REPORTER_ASSERT(reporter,
3651 p.getSegmentMasks() & (kCurveSegmentMask | SkPath::kConic_SegmentMask));
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003652 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00003653
reed@android.com6b82d1a2009-06-03 02:35:01 +00003654 p.reset();
bungeman@google.coma5809a32013-06-21 15:13:34 +00003655 test_empty(reporter, p);
reed@google.com10296cc2011-09-21 12:29:05 +00003656
reed@android.com6b82d1a2009-06-03 02:35:01 +00003657 p.addOval(bounds);
3658 check_convex_bounds(reporter, p, bounds);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003659 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00003660
bungeman@google.coma5809a32013-06-21 15:13:34 +00003661 p.rewind();
3662 test_empty(reporter, p);
3663
reed@android.com3abec1d2009-03-02 05:36:20 +00003664 p.addRect(bounds);
reed@android.com6b82d1a2009-06-03 02:35:01 +00003665 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00003666 // we have only lines
3667 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == p.getSegmentMasks());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003668 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@android.com3abec1d2009-03-02 05:36:20 +00003669
bungeman@google.coma5809a32013-06-21 15:13:34 +00003670 REPORTER_ASSERT(reporter, p != empty);
3671 REPORTER_ASSERT(reporter, !(p == empty));
reed@android.com3abec1d2009-03-02 05:36:20 +00003672
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00003673 // do getPoints and getVerbs return the right result
3674 REPORTER_ASSERT(reporter, p.getPoints(NULL, 0) == 4);
3675 REPORTER_ASSERT(reporter, p.getVerbs(NULL, 0) == 5);
reed@android.com3abec1d2009-03-02 05:36:20 +00003676 SkPoint pts[4];
3677 int count = p.getPoints(pts, 4);
3678 REPORTER_ASSERT(reporter, count == 4);
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00003679 uint8_t verbs[6];
3680 verbs[5] = 0xff;
3681 p.getVerbs(verbs, 5);
3682 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == verbs[0]);
3683 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[1]);
3684 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[2]);
3685 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[3]);
3686 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == verbs[4]);
3687 REPORTER_ASSERT(reporter, 0xff == verbs[5]);
reed@android.com3abec1d2009-03-02 05:36:20 +00003688 bounds2.set(pts, 4);
3689 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00003690
reed@android.com3abec1d2009-03-02 05:36:20 +00003691 bounds.offset(SK_Scalar1*3, SK_Scalar1*4);
3692 p.offset(SK_Scalar1*3, SK_Scalar1*4);
reed@android.comd252db02009-04-01 18:31:44 +00003693 REPORTER_ASSERT(reporter, bounds == p.getBounds());
reed@android.com3abec1d2009-03-02 05:36:20 +00003694
reed@android.com3abec1d2009-03-02 05:36:20 +00003695 REPORTER_ASSERT(reporter, p.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00003696 bounds2.setEmpty();
reed@android.com3abec1d2009-03-02 05:36:20 +00003697 REPORTER_ASSERT(reporter, p.isRect(&bounds2));
3698 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00003699
reed@android.com3abec1d2009-03-02 05:36:20 +00003700 // now force p to not be a rect
3701 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2);
3702 p.addRect(bounds);
3703 REPORTER_ASSERT(reporter, !p.isRect(NULL));
reed@android.com3abec1d2009-03-02 05:36:20 +00003704
robertphillipsfe7c4272014-12-29 11:36:39 -08003705 // Test an edge case w.r.t. the bound returned by isRect (i.e., the
3706 // path has a trailing moveTo. Please see crbug.com\445368)
3707 {
3708 SkRect r;
3709 p.reset();
3710 p.addRect(bounds);
3711 REPORTER_ASSERT(reporter, p.isRect(&r));
3712 REPORTER_ASSERT(reporter, r == bounds);
3713 // add a moveTo outside of our bounds
3714 p.moveTo(bounds.fLeft + 10, bounds.fBottom + 10);
3715 REPORTER_ASSERT(reporter, p.isRect(&r));
3716 REPORTER_ASSERT(reporter, r == bounds);
3717 }
3718
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003719 test_operatorEqual(reporter);
reed@google.com7e6c4d12012-05-10 14:05:43 +00003720 test_isLine(reporter);
3721 test_isRect(reporter);
caryclark@google.com56f233a2012-11-19 13:06:06 +00003722 test_isNestedRects(reporter);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003723 test_zero_length_paths(reporter);
reed@google.comcabaf1d2012-01-11 21:03:05 +00003724 test_direction(reporter);
reed@google.com04863fa2011-05-15 04:08:24 +00003725 test_convexity(reporter);
reed@google.com7c424812011-05-15 04:38:34 +00003726 test_convexity2(reporter);
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00003727 test_conservativelyContains(reporter);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00003728 test_close(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00003729 test_segment_masks(reporter);
reed@google.com53effc52011-09-21 19:05:12 +00003730 test_flattening(reporter);
3731 test_transform(reporter);
reed@google.com3563c9e2011-11-14 19:34:57 +00003732 test_bounds(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00003733 test_iter(reporter);
3734 test_raw_iter(reporter);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003735 test_circle(reporter);
3736 test_oval(reporter);
reed@google.com8b06f1a2012-05-29 12:03:46 +00003737 test_strokerec(reporter);
reed@google.com744faba2012-05-29 19:54:52 +00003738 test_addPoly(reporter);
reed@google.com0bb18bb2012-07-26 15:20:36 +00003739 test_isfinite(reporter);
tomhudson@google.comed02c4d2012-08-10 14:10:45 +00003740 test_isfinite_after_transform(reporter);
robertphillips@google.comb95eaa82012-10-18 15:26:12 +00003741 test_arb_round_rect_is_convex(reporter);
robertphillips@google.com158618e2012-10-23 16:56:56 +00003742 test_arb_zero_rad_round_rect_is_rect(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003743 test_addrect(reporter);
reed@google.coma8790de2012-10-24 21:04:04 +00003744 test_addrect_isfinite(reporter);
sugoi@google.com54f0d1b2013-02-27 19:17:41 +00003745 test_tricky_cubic();
3746 test_clipped_cubic();
3747 test_crbug_170666();
reed@google.com7a90daf2013-04-10 18:44:00 +00003748 test_bad_cubic_crbug229478();
reed@google.com3eff3592013-05-08 21:08:21 +00003749 test_bad_cubic_crbug234190();
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +00003750 test_gen_id(reporter);
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +00003751 test_path_close_issue1474(reporter);
reed@google.comb58ba892013-10-15 15:44:35 +00003752 test_path_to_region(reporter);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003753 test_rrect(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003754 test_arc(reporter);
3755 test_arcTo(reporter);
3756 test_addPath(reporter);
commit-bot@chromium.org14747e52014-02-11 21:16:29 +00003757 test_addPathMode(reporter, false, false);
3758 test_addPathMode(reporter, true, false);
3759 test_addPathMode(reporter, false, true);
3760 test_addPathMode(reporter, true, true);
3761 test_extendClosedPath(reporter);
3762 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode);
3763 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003764 test_conicTo_special_case(reporter);
3765 test_get_point(reporter);
3766 test_contains(reporter);
3767 PathTest_Private::TestPathTo(reporter);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003768 PathRefTest_Private::TestPathRef(reporter);
caryclark66a5d8b2014-06-24 08:30:15 -07003769 test_dump(reporter);
caryclarkb4216502015-03-02 13:02:34 -08003770 test_path_crbug389050(reporter);
piotaixrfac4e0e2014-08-26 11:59:04 -07003771 test_path_crbugskia2820(reporter);
caryclark5ccef572015-03-02 10:07:56 -08003772 test_skbug_3469(reporter);
reed5bcbe912014-12-15 12:28:33 -08003773 test_skbug_3239(reporter);
reed@android.com3abec1d2009-03-02 05:36:20 +00003774}