blob: a274694b71d00dedb085ce8217768041e270ab67 [file] [log] [blame]
epoger@google.comec3ed6a2011-07-28 14:26:00 +00001/*
2 * Copyright 2011 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
reed@google.comcc8be772013-10-15 15:35:29 +00007
reed@google.com8cae8352012-09-14 15:18:41 +00008#include "SkCanvas.h"
reed@google.com55b5f4b2011-09-07 12:23:41 +00009#include "SkPaint.h"
reed@google.com04863fa2011-05-15 04:08:24 +000010#include "SkParse.h"
reed@google.com3e71a882012-01-10 18:44:37 +000011#include "SkParsePath.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000012#include "SkPath.h"
reed@google.com8b06f1a2012-05-29 12:03:46 +000013#include "SkPathEffect.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000014#include "SkRRect.h"
schenney@chromium.org6630d8d2012-01-04 21:05:51 +000015#include "SkRandom.h"
reed@google.com53effc52011-09-21 19:05:12 +000016#include "SkReader32.h"
reed@android.com60bc6d52010-02-11 11:09:39 +000017#include "SkSize.h"
caryclark66a5d8b2014-06-24 08:30:15 -070018#include "SkStream.h"
reed@google.com8cae8352012-09-14 15:18:41 +000019#include "SkSurface.h"
mtklein@google.com9c9d4a72013-08-07 19:17:53 +000020#include "SkTypes.h"
21#include "SkWriter32.h"
tfarina@chromium.org8f6884a2014-01-24 20:56:26 +000022#include "Test.h"
reed@google.com8cae8352012-09-14 15:18:41 +000023
reed5bcbe912014-12-15 12:28:33 -080024static void set_radii(SkVector radii[4], int index, float rad) {
25 sk_bzero(radii, sizeof(SkVector) * 4);
26 radii[index].set(rad, rad);
27}
28
29static void test_add_rrect(skiatest::Reporter* reporter, const SkRect& bounds,
30 const SkVector radii[4]) {
31 SkRRect rrect;
32 rrect.setRectRadii(bounds, radii);
33 REPORTER_ASSERT(reporter, bounds == rrect.rect());
34
35 SkPath path;
36 // this line should not assert in the debug build (from validate)
37 path.addRRect(rrect);
38 REPORTER_ASSERT(reporter, bounds == path.getBounds());
39}
40
41static void test_skbug_3239(skiatest::Reporter* reporter) {
42 const float min = SkBits2Float(0xcb7f16c8); /* -16717512.000000 */
43 const float max = SkBits2Float(0x4b7f1c1d); /* 16718877.000000 */
44 const float big = SkBits2Float(0x4b7f1bd7); /* 16718807.000000 */
45
46 const float rad = 33436320;
47
48 const SkRect rectx = SkRect::MakeLTRB(min, min, max, big);
49 const SkRect recty = SkRect::MakeLTRB(min, min, big, max);
50
51 SkVector radii[4];
52 for (int i = 0; i < 4; ++i) {
53 set_radii(radii, i, rad);
54 test_add_rrect(reporter, rectx, radii);
55 test_add_rrect(reporter, recty, radii);
56 }
57}
58
commit-bot@chromium.org4e332f82014-05-05 16:04:42 +000059static void make_path_crbug364224(SkPath* path) {
60 path->reset();
61 path->moveTo(3.747501373f, 2.724499941f);
62 path->lineTo(3.747501373f, 3.75f);
63 path->cubicTo(3.747501373f, 3.88774991f, 3.635501385f, 4.0f, 3.497501373f, 4.0f);
64 path->lineTo(0.7475013733f, 4.0f);
65 path->cubicTo(0.6095013618f, 4.0f, 0.4975013733f, 3.88774991f, 0.4975013733f, 3.75f);
66 path->lineTo(0.4975013733f, 1.0f);
67 path->cubicTo(0.4975013733f, 0.8622499704f, 0.6095013618f, 0.75f, 0.7475013733f,0.75f);
68 path->lineTo(3.497501373f, 0.75f);
69 path->cubicTo(3.50275135f, 0.75f, 3.5070014f, 0.7527500391f, 3.513001442f, 0.753000021f);
70 path->lineTo(3.715001345f, 0.5512499809f);
71 path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
72 path->lineTo(0.7475013733f, 0.4999999702f);
73 path->cubicTo(0.4715013802f, 0.4999999702f, 0.2475013733f, 0.7239999771f, 0.2475013733f, 1.0f);
74 path->lineTo(0.2475013733f, 3.75f);
75 path->cubicTo(0.2475013733f, 4.026000023f, 0.4715013504f, 4.25f, 0.7475013733f, 4.25f);
76 path->lineTo(3.497501373f, 4.25f);
77 path->cubicTo(3.773501396f, 4.25f, 3.997501373f, 4.026000023f, 3.997501373f, 3.75f);
78 path->lineTo(3.997501373f, 2.474750042f);
79 path->lineTo(3.747501373f, 2.724499941f);
80 path->close();
81}
82
83static void make_path_crbug364224_simplified(SkPath* path) {
84 path->moveTo(3.747501373f, 2.724499941f);
85 path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
86 path->close();
87}
88
89static void test_path_crbug364224() {
90 SkPath path;
91 SkPaint paint;
reed3054be12014-12-10 07:24:28 -080092 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(84, 88));
commit-bot@chromium.org4e332f82014-05-05 16:04:42 +000093 SkCanvas* canvas = surface->getCanvas();
94
95 make_path_crbug364224_simplified(&path);
96 canvas->drawPath(path, paint);
97
98 make_path_crbug364224(&path);
99 canvas->drawPath(path, paint);
100}
101
piotaixrfac4e0e2014-08-26 11:59:04 -0700102/**
103 * In debug mode, this path was causing an assertion to fail in
104 * SkPathStroker::preJoinTo() and, in Release, the use of an unitialized value.
105 */
106static void make_path_crbugskia2820(SkPath* path, skiatest::Reporter* reporter) {
107 SkPoint orig, p1, p2, p3;
108 orig = SkPoint::Make(1.f, 1.f);
109 p1 = SkPoint::Make(1.f - SK_ScalarNearlyZero, 1.f);
110 p2 = SkPoint::Make(1.f, 1.f + SK_ScalarNearlyZero);
111 p3 = SkPoint::Make(2.f, 2.f);
112
113 path->reset();
114 path->moveTo(orig);
115 path->cubicTo(p1, p2, p3);
116 path->close();
117}
118
119static void test_path_crbugskia2820(skiatest::Reporter* reporter) {//GrContext* context) {
120 SkPath path;
121 make_path_crbugskia2820(&path, reporter);
122
123 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
124 stroke.setStrokeStyle(2 * SK_Scalar1);
125 stroke.applyToPath(&path, path);
126}
127
reed@google.comcc8be772013-10-15 15:35:29 +0000128static void make_path0(SkPath* path) {
129 // from * https://code.google.com/p/skia/issues/detail?id=1706
130
131 path->moveTo(146.939f, 1012.84f);
132 path->lineTo(181.747f, 1009.18f);
133 path->lineTo(182.165f, 1013.16f);
134 path->lineTo(147.357f, 1016.82f);
135 path->lineTo(146.939f, 1012.84f);
136 path->close();
137}
138
139static void make_path1(SkPath* path) {
140 path->addRect(SkRect::MakeXYWH(10, 10, 10, 1));
141}
142
143typedef void (*PathProc)(SkPath*);
144
145/*
146 * Regression test: we used to crash (overwrite internal storage) during
147 * construction of the region when the path was INVERSE. That is now fixed,
148 * so test these regions (which used to assert/crash).
149 *
150 * https://code.google.com/p/skia/issues/detail?id=1706
151 */
152static void test_path_to_region(skiatest::Reporter* reporter) {
153 PathProc procs[] = {
154 make_path0,
155 make_path1,
156 };
skia.committer@gmail.com47262912013-10-16 07:02:24 +0000157
reed@google.comcc8be772013-10-15 15:35:29 +0000158 SkRegion clip;
159 clip.setRect(0, 0, 1255, 1925);
skia.committer@gmail.com47262912013-10-16 07:02:24 +0000160
reed@google.comcc8be772013-10-15 15:35:29 +0000161 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
162 SkPath path;
163 procs[i](&path);
skia.committer@gmail.com47262912013-10-16 07:02:24 +0000164
reed@google.comcc8be772013-10-15 15:35:29 +0000165 SkRegion rgn;
166 rgn.setPath(path, clip);
167 path.toggleInverseFillType();
168 rgn.setPath(path, clip);
169 }
170}
171
caryclark@google.com56f233a2012-11-19 13:06:06 +0000172#if defined(WIN32)
173 #define SUPPRESS_VISIBILITY_WARNING
174#else
175 #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
176#endif
177
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +0000178static void test_path_close_issue1474(skiatest::Reporter* reporter) {
179 // This test checks that r{Line,Quad,Conic,Cubic}To following a close()
180 // are relative to the point we close to, not relative to the point we close from.
181 SkPath path;
182 SkPoint last;
183
184 // Test rLineTo().
185 path.rLineTo(0, 100);
186 path.rLineTo(100, 0);
187 path.close(); // Returns us back to 0,0.
188 path.rLineTo(50, 50); // This should go to 50,50.
189
190 path.getLastPt(&last);
191 REPORTER_ASSERT(reporter, 50 == last.fX);
192 REPORTER_ASSERT(reporter, 50 == last.fY);
193
194 // Test rQuadTo().
195 path.rewind();
196 path.rLineTo(0, 100);
197 path.rLineTo(100, 0);
198 path.close();
199 path.rQuadTo(50, 50, 75, 75);
200
201 path.getLastPt(&last);
202 REPORTER_ASSERT(reporter, 75 == last.fX);
203 REPORTER_ASSERT(reporter, 75 == last.fY);
204
205 // Test rConicTo().
206 path.rewind();
207 path.rLineTo(0, 100);
208 path.rLineTo(100, 0);
209 path.close();
210 path.rConicTo(50, 50, 85, 85, 2);
211
212 path.getLastPt(&last);
213 REPORTER_ASSERT(reporter, 85 == last.fX);
214 REPORTER_ASSERT(reporter, 85 == last.fY);
215
216 // Test rCubicTo().
217 path.rewind();
218 path.rLineTo(0, 100);
219 path.rLineTo(100, 0);
220 path.close();
221 path.rCubicTo(50, 50, 85, 85, 95, 95);
222
223 path.getLastPt(&last);
224 REPORTER_ASSERT(reporter, 95 == last.fX);
225 REPORTER_ASSERT(reporter, 95 == last.fY);
226}
227
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000228static void test_android_specific_behavior(skiatest::Reporter* reporter) {
229#ifdef SK_BUILD_FOR_ANDROID
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000230 // Make sure we treat fGenerationID and fSourcePath correctly for each of
231 // copy, assign, rewind, reset, and swap.
232 SkPath original, source, anotherSource;
233 original.setSourcePath(&source);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000234 original.moveTo(0, 0);
235 original.lineTo(1, 1);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000236 REPORTER_ASSERT(reporter, original.getSourcePath() == &source);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000237
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000238 uint32_t copyID, assignID;
239
240 // Test copy constructor. Copy generation ID, copy source path.
241 SkPath copy(original);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000242 REPORTER_ASSERT(reporter, copy.getGenerationID() == original.getGenerationID());
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000243 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath());
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000244
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000245 // Test assigment operator. Change generation ID, copy source path.
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000246 SkPath assign;
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000247 assignID = assign.getGenerationID();
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000248 assign = original;
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000249 REPORTER_ASSERT(reporter, assign.getGenerationID() != assignID);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000250 REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath());
251
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000252 // Test rewind. Change generation ID, don't touch source path.
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000253 copyID = copy.getGenerationID();
254 copy.rewind();
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000255 REPORTER_ASSERT(reporter, copy.getGenerationID() != copyID);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000256 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath());
257
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000258 // Test reset. Change generation ID, don't touch source path.
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000259 assignID = assign.getGenerationID();
260 assign.reset();
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000261 REPORTER_ASSERT(reporter, assign.getGenerationID() != assignID);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000262 REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath());
263
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000264 // Test swap. Swap the generation IDs, swap source paths.
265 copy.reset();
266 copy.moveTo(2, 2);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000267 copy.setSourcePath(&anotherSource);
268 copyID = copy.getGenerationID();
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000269 assign.moveTo(3, 3);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000270 assignID = assign.getGenerationID();
271 copy.swap(assign);
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000272 REPORTER_ASSERT(reporter, copy.getGenerationID() != copyID);
273 REPORTER_ASSERT(reporter, assign.getGenerationID() != assignID);
mtklein@google.comcb8b0ee2013-08-15 21:14:51 +0000274 REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath());
275 REPORTER_ASSERT(reporter, assign.getSourcePath() == &anotherSource);
mtklein@google.com9c9d4a72013-08-07 19:17:53 +0000276#endif
277}
278
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +0000279static void test_gen_id(skiatest::Reporter* reporter) {
280 SkPath a, b;
281 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
282
283 a.moveTo(0, 0);
284 const uint32_t z = a.getGenerationID();
285 REPORTER_ASSERT(reporter, z != b.getGenerationID());
286
287 a.reset();
288 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
289
290 a.moveTo(1, 1);
291 const uint32_t y = a.getGenerationID();
292 REPORTER_ASSERT(reporter, z != y);
293
294 b.moveTo(2, 2);
295 const uint32_t x = b.getGenerationID();
296 REPORTER_ASSERT(reporter, x != y && x != z);
297
298 a.swap(b);
299 REPORTER_ASSERT(reporter, b.getGenerationID() == y && a.getGenerationID() == x);
300
301 b = a;
302 REPORTER_ASSERT(reporter, b.getGenerationID() == x);
303
304 SkPath c(a);
305 REPORTER_ASSERT(reporter, c.getGenerationID() == x);
306
307 c.lineTo(3, 3);
308 const uint32_t w = c.getGenerationID();
309 REPORTER_ASSERT(reporter, b.getGenerationID() == x);
310 REPORTER_ASSERT(reporter, a.getGenerationID() == x);
311 REPORTER_ASSERT(reporter, w != x);
312
313#ifdef SK_BUILD_FOR_ANDROID
314 static bool kExpectGenIDToIgnoreFill = false;
315#else
316 static bool kExpectGenIDToIgnoreFill = true;
317#endif
318
319 c.toggleInverseFillType();
320 const uint32_t v = c.getGenerationID();
321 REPORTER_ASSERT(reporter, (v == w) == kExpectGenIDToIgnoreFill);
322
323 c.rewind();
324 REPORTER_ASSERT(reporter, v != c.getGenerationID());
325}
326
reed@google.com3eff3592013-05-08 21:08:21 +0000327// This used to assert in the debug build, as the edges did not all line-up.
328static void test_bad_cubic_crbug234190() {
329 SkPath path;
330 path.moveTo(13.8509f, 3.16858f);
331 path.cubicTo(-2.35893e+08f, -4.21044e+08f,
332 -2.38991e+08f, -4.26573e+08f,
333 -2.41016e+08f, -4.30188e+08f);
334
335 SkPaint paint;
336 paint.setAntiAlias(true);
reed3054be12014-12-10 07:24:28 -0800337 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(84, 88));
reed@google.com3eff3592013-05-08 21:08:21 +0000338 surface->getCanvas()->drawPath(path, paint);
339}
340
reed@google.com7a90daf2013-04-10 18:44:00 +0000341static void test_bad_cubic_crbug229478() {
342 const SkPoint pts[] = {
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000343 { 4595.91064f, -11596.9873f },
344 { 4597.2168f, -11595.9414f },
345 { 4598.52344f, -11594.8955f },
346 { 4599.83008f, -11593.8496f },
reed@google.com7a90daf2013-04-10 18:44:00 +0000347 };
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000348
reed@google.com7a90daf2013-04-10 18:44:00 +0000349 SkPath path;
350 path.moveTo(pts[0]);
351 path.cubicTo(pts[1], pts[2], pts[3]);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000352
reed@google.com7a90daf2013-04-10 18:44:00 +0000353 SkPaint paint;
354 paint.setStyle(SkPaint::kStroke_Style);
355 paint.setStrokeWidth(20);
skia.committer@gmail.com391ca662013-04-11 07:01:45 +0000356
reed@google.com7a90daf2013-04-10 18:44:00 +0000357 SkPath dst;
358 // Before the fix, this would infinite-recurse, and run out of stack
359 // because we would keep trying to subdivide a degenerate cubic segment.
360 paint.getFillPath(path, &dst, NULL);
361}
362
reed@google.com64d62952013-01-18 17:49:28 +0000363static void build_path_170666(SkPath& path) {
364 path.moveTo(17.9459f, 21.6344f);
365 path.lineTo(139.545f, -47.8105f);
366 path.lineTo(139.545f, -47.8105f);
367 path.lineTo(131.07f, -47.3888f);
368 path.lineTo(131.07f, -47.3888f);
369 path.lineTo(122.586f, -46.9532f);
370 path.lineTo(122.586f, -46.9532f);
371 path.lineTo(18076.6f, 31390.9f);
372 path.lineTo(18076.6f, 31390.9f);
373 path.lineTo(18085.1f, 31390.5f);
374 path.lineTo(18085.1f, 31390.5f);
375 path.lineTo(18076.6f, 31390.9f);
376 path.lineTo(18076.6f, 31390.9f);
377 path.lineTo(17955, 31460.3f);
378 path.lineTo(17955, 31460.3f);
379 path.lineTo(17963.5f, 31459.9f);
380 path.lineTo(17963.5f, 31459.9f);
381 path.lineTo(17971.9f, 31459.5f);
382 path.lineTo(17971.9f, 31459.5f);
383 path.lineTo(17.9551f, 21.6205f);
384 path.lineTo(17.9551f, 21.6205f);
385 path.lineTo(9.47091f, 22.0561f);
386 path.lineTo(9.47091f, 22.0561f);
387 path.lineTo(17.9459f, 21.6344f);
388 path.lineTo(17.9459f, 21.6344f);
389 path.close();path.moveTo(0.995934f, 22.4779f);
390 path.lineTo(0.986725f, 22.4918f);
391 path.lineTo(0.986725f, 22.4918f);
392 path.lineTo(17955, 31460.4f);
393 path.lineTo(17955, 31460.4f);
394 path.lineTo(17971.9f, 31459.5f);
395 path.lineTo(17971.9f, 31459.5f);
396 path.lineTo(18093.6f, 31390.1f);
397 path.lineTo(18093.6f, 31390.1f);
398 path.lineTo(18093.6f, 31390);
399 path.lineTo(18093.6f, 31390);
400 path.lineTo(139.555f, -47.8244f);
401 path.lineTo(139.555f, -47.8244f);
402 path.lineTo(122.595f, -46.9671f);
403 path.lineTo(122.595f, -46.9671f);
404 path.lineTo(0.995934f, 22.4779f);
405 path.lineTo(0.995934f, 22.4779f);
406 path.close();
407 path.moveTo(5.43941f, 25.5223f);
408 path.lineTo(798267, -28871.1f);
409 path.lineTo(798267, -28871.1f);
410 path.lineTo(3.12512e+06f, -113102);
411 path.lineTo(3.12512e+06f, -113102);
412 path.cubicTo(5.16324e+06f, -186882, 8.15247e+06f, -295092, 1.1957e+07f, -432813);
413 path.cubicTo(1.95659e+07f, -708257, 3.04359e+07f, -1.10175e+06f, 4.34798e+07f, -1.57394e+06f);
414 path.cubicTo(6.95677e+07f, -2.51831e+06f, 1.04352e+08f, -3.77748e+06f, 1.39135e+08f, -5.03666e+06f);
415 path.cubicTo(1.73919e+08f, -6.29583e+06f, 2.08703e+08f, -7.555e+06f, 2.34791e+08f, -8.49938e+06f);
416 path.cubicTo(2.47835e+08f, -8.97157e+06f, 2.58705e+08f, -9.36506e+06f, 2.66314e+08f, -9.6405e+06f);
417 path.cubicTo(2.70118e+08f, -9.77823e+06f, 2.73108e+08f, -9.88644e+06f, 2.75146e+08f, -9.96022e+06f);
418 path.cubicTo(2.76165e+08f, -9.99711e+06f, 2.76946e+08f, -1.00254e+07f, 2.77473e+08f, -1.00444e+07f);
419 path.lineTo(2.78271e+08f, -1.00733e+07f);
420 path.lineTo(2.78271e+08f, -1.00733e+07f);
421 path.cubicTo(2.78271e+08f, -1.00733e+07f, 2.08703e+08f, -7.555e+06f, 135.238f, 23.3517f);
422 path.cubicTo(131.191f, 23.4981f, 125.995f, 23.7976f, 123.631f, 24.0206f);
423 path.cubicTo(121.267f, 24.2436f, 122.631f, 24.3056f, 126.677f, 24.1591f);
424 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
425 path.lineTo(2.77473e+08f, -1.00444e+07f);
426 path.lineTo(2.77473e+08f, -1.00444e+07f);
427 path.cubicTo(2.76946e+08f, -1.00254e+07f, 2.76165e+08f, -9.99711e+06f, 2.75146e+08f, -9.96022e+06f);
428 path.cubicTo(2.73108e+08f, -9.88644e+06f, 2.70118e+08f, -9.77823e+06f, 2.66314e+08f, -9.6405e+06f);
429 path.cubicTo(2.58705e+08f, -9.36506e+06f, 2.47835e+08f, -8.97157e+06f, 2.34791e+08f, -8.49938e+06f);
430 path.cubicTo(2.08703e+08f, -7.555e+06f, 1.73919e+08f, -6.29583e+06f, 1.39135e+08f, -5.03666e+06f);
431 path.cubicTo(1.04352e+08f, -3.77749e+06f, 6.95677e+07f, -2.51831e+06f, 4.34798e+07f, -1.57394e+06f);
432 path.cubicTo(3.04359e+07f, -1.10175e+06f, 1.95659e+07f, -708258, 1.1957e+07f, -432814);
433 path.cubicTo(8.15248e+06f, -295092, 5.16324e+06f, -186883, 3.12513e+06f, -113103);
434 path.lineTo(798284, -28872);
435 path.lineTo(798284, -28872);
436 path.lineTo(22.4044f, 24.6677f);
437 path.lineTo(22.4044f, 24.6677f);
438 path.cubicTo(22.5186f, 24.5432f, 18.8134f, 24.6337f, 14.1287f, 24.8697f);
439 path.cubicTo(9.4439f, 25.1057f, 5.55359f, 25.3978f, 5.43941f, 25.5223f);
440 path.close();
441}
442
443static void build_path_simple_170666(SkPath& path) {
444 path.moveTo(126.677f, 24.1591f);
445 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
446}
447
448// This used to assert in the SK_DEBUG build, as the clip step would fail with
449// too-few interations in our cubic-line intersection code. That code now runs
450// 24 interations (instead of 16).
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000451static void test_crbug_170666() {
reed@google.com64d62952013-01-18 17:49:28 +0000452 SkPath path;
453 SkPaint paint;
454 paint.setAntiAlias(true);
455
reed3054be12014-12-10 07:24:28 -0800456 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(1000, 1000));
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000457
reed@google.com64d62952013-01-18 17:49:28 +0000458 build_path_simple_170666(path);
459 surface->getCanvas()->drawPath(path, paint);
skia.committer@gmail.com36df7ed2013-01-19 07:05:38 +0000460
reed@google.com64d62952013-01-18 17:49:28 +0000461 build_path_170666(path);
462 surface->getCanvas()->drawPath(path, paint);
463}
464
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000465static void test_addrect(skiatest::Reporter* reporter) {
466 SkPath path;
467 path.lineTo(0, 0);
468 path.addRect(SkRect::MakeWH(50, 100));
469 REPORTER_ASSERT(reporter, path.isRect(NULL));
470
471 path.reset();
472 path.lineTo(FLT_EPSILON, FLT_EPSILON);
473 path.addRect(SkRect::MakeWH(50, 100));
474 REPORTER_ASSERT(reporter, !path.isRect(NULL));
475
476 path.reset();
477 path.quadTo(0, 0, 0, 0);
478 path.addRect(SkRect::MakeWH(50, 100));
479 REPORTER_ASSERT(reporter, !path.isRect(NULL));
480
481 path.reset();
482 path.conicTo(0, 0, 0, 0, 0.5f);
483 path.addRect(SkRect::MakeWH(50, 100));
484 REPORTER_ASSERT(reporter, !path.isRect(NULL));
485
486 path.reset();
487 path.cubicTo(0, 0, 0, 0, 0, 0);
488 path.addRect(SkRect::MakeWH(50, 100));
489 REPORTER_ASSERT(reporter, !path.isRect(NULL));
490}
491
reed@google.coma8790de2012-10-24 21:04:04 +0000492// Make sure we stay non-finite once we get there (unless we reset or rewind).
493static void test_addrect_isfinite(skiatest::Reporter* reporter) {
494 SkPath path;
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000495
reed@google.coma8790de2012-10-24 21:04:04 +0000496 path.addRect(SkRect::MakeWH(50, 100));
497 REPORTER_ASSERT(reporter, path.isFinite());
498
499 path.moveTo(0, 0);
500 path.lineTo(SK_ScalarInfinity, 42);
501 REPORTER_ASSERT(reporter, !path.isFinite());
502
503 path.addRect(SkRect::MakeWH(50, 100));
504 REPORTER_ASSERT(reporter, !path.isFinite());
505
506 path.reset();
507 REPORTER_ASSERT(reporter, path.isFinite());
skia.committer@gmail.com8b0e2342012-10-25 02:01:20 +0000508
reed@google.coma8790de2012-10-24 21:04:04 +0000509 path.addRect(SkRect::MakeWH(50, 100));
510 REPORTER_ASSERT(reporter, path.isFinite());
511}
512
reed@google.com848148e2013-01-15 15:51:59 +0000513static void build_big_path(SkPath* path, bool reducedCase) {
514 if (reducedCase) {
515 path->moveTo(577330, 1971.72f);
516 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
517 } else {
518 path->moveTo(60.1631f, 7.70567f);
519 path->quadTo(60.1631f, 7.70567f, 0.99474f, 0.901199f);
520 path->lineTo(577379, 1977.77f);
521 path->quadTo(577364, 1979.57f, 577325, 1980.26f);
522 path->quadTo(577286, 1980.95f, 577245, 1980.13f);
523 path->quadTo(577205, 1979.3f, 577187, 1977.45f);
524 path->quadTo(577168, 1975.6f, 577183, 1973.8f);
525 path->quadTo(577198, 1972, 577238, 1971.31f);
526 path->quadTo(577277, 1970.62f, 577317, 1971.45f);
527 path->quadTo(577330, 1971.72f, 577341, 1972.11f);
528 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
529 path->moveTo(306.718f, -32.912f);
530 path->cubicTo(30.531f, 10.0005f, 1502.47f, 13.2804f, 84.3088f, 9.99601f);
531 }
532}
533
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000534static void test_clipped_cubic() {
reed3054be12014-12-10 07:24:28 -0800535 SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterN32Premul(640, 480));
reed@google.com848148e2013-01-15 15:51:59 +0000536
537 // This path used to assert, because our cubic-chopping code incorrectly
538 // moved control points after the chop. This test should be run in SK_DEBUG
539 // mode to ensure that we no long assert.
540 SkPath path;
541 for (int doReducedCase = 0; doReducedCase <= 1; ++doReducedCase) {
542 build_big_path(&path, SkToBool(doReducedCase));
skia.committer@gmail.comff21c2e2013-01-16 07:05:56 +0000543
reed@google.com848148e2013-01-15 15:51:59 +0000544 SkPaint paint;
545 for (int doAA = 0; doAA <= 1; ++doAA) {
546 paint.setAntiAlias(SkToBool(doAA));
547 surface->getCanvas()->drawPath(path, paint);
548 }
549 }
550}
551
reed@google.com8cae8352012-09-14 15:18:41 +0000552// Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/
553// which triggered an assert, from a tricky cubic. This test replicates that
554// example, so we can ensure that we handle it (in SkEdge.cpp), and don't
555// assert in the SK_DEBUG build.
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000556static void test_tricky_cubic() {
reed@google.com8cae8352012-09-14 15:18:41 +0000557 const SkPoint pts[] = {
skia.committer@gmail.com055c7c22012-09-15 02:01:41 +0000558 { SkDoubleToScalar(18.8943768), SkDoubleToScalar(129.121277) },
559 { SkDoubleToScalar(18.8937435), SkDoubleToScalar(129.121689) },
560 { SkDoubleToScalar(18.8950119), SkDoubleToScalar(129.120422) },
561 { SkDoubleToScalar(18.5030727), SkDoubleToScalar(129.13121) },
reed@google.com8cae8352012-09-14 15:18:41 +0000562 };
563
564 SkPath path;
565 path.moveTo(pts[0]);
566 path.cubicTo(pts[1], pts[2], pts[3]);
567
568 SkPaint paint;
569 paint.setAntiAlias(true);
570
reed3054be12014-12-10 07:24:28 -0800571 SkSurface* surface = SkSurface::NewRasterN32Premul(19, 130);
reed@google.com8cae8352012-09-14 15:18:41 +0000572 surface->getCanvas()->drawPath(path, paint);
573 surface->unref();
574}
reed@android.com3abec1d2009-03-02 05:36:20 +0000575
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000576// Inspired by http://code.google.com/p/chromium/issues/detail?id=141651
577//
578static void test_isfinite_after_transform(skiatest::Reporter* reporter) {
579 SkPath path;
580 path.quadTo(157, 366, 286, 208);
581 path.arcTo(37, 442, 315, 163, 957494590897113.0f);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000582
tomhudson@google.comed02c4d2012-08-10 14:10:45 +0000583 SkMatrix matrix;
584 matrix.setScale(1000*1000, 1000*1000);
585
586 // Be sure that path::transform correctly updates isFinite and the bounds
587 // if the transformation overflows. The previous bug was that isFinite was
588 // set to true in this case, but the bounds were not set to empty (which
589 // they should be).
590 while (path.isFinite()) {
591 REPORTER_ASSERT(reporter, path.getBounds().isFinite());
592 REPORTER_ASSERT(reporter, !path.getBounds().isEmpty());
593 path.transform(matrix);
594 }
595 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
596
597 matrix.setTranslate(SK_Scalar1, SK_Scalar1);
598 path.transform(matrix);
599 // we need to still be non-finite
600 REPORTER_ASSERT(reporter, !path.isFinite());
601 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
602}
603
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000604static void add_corner_arc(SkPath* path, const SkRect& rect,
605 SkScalar xIn, SkScalar yIn,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000606 int startAngle)
607{
608
609 SkScalar rx = SkMinScalar(rect.width(), xIn);
610 SkScalar ry = SkMinScalar(rect.height(), yIn);
611
612 SkRect arcRect;
613 arcRect.set(-rx, -ry, rx, ry);
614 switch (startAngle) {
615 case 0:
616 arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom);
617 break;
618 case 90:
619 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom);
620 break;
621 case 180:
622 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop);
623 break;
624 case 270:
625 arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop);
626 break;
627 default:
628 break;
629 }
630
631 path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false);
632}
633
skia.committer@gmail.com6a748ad2012-10-19 02:01:19 +0000634static void make_arb_round_rect(SkPath* path, const SkRect& r,
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000635 SkScalar xCorner, SkScalar yCorner) {
636 // we are lazy here and use the same x & y for each corner
637 add_corner_arc(path, r, xCorner, yCorner, 270);
638 add_corner_arc(path, r, xCorner, yCorner, 0);
639 add_corner_arc(path, r, xCorner, yCorner, 90);
640 add_corner_arc(path, r, xCorner, yCorner, 180);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000641 path->close();
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000642}
643
644// Chrome creates its own round rects with each corner possibly being different.
645// Performance will suffer if they are not convex.
646// Note: PathBench::ArbRoundRectBench performs almost exactly
647// the same test (but with drawing)
648static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000649 SkRandom rand;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000650 SkRect r;
651
652 for (int i = 0; i < 5000; ++i) {
653
robertphillips@google.com158618e2012-10-23 16:56:56 +0000654 SkScalar size = rand.nextUScalar1() * 30;
655 if (size < SK_Scalar1) {
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000656 continue;
657 }
658 r.fLeft = rand.nextUScalar1() * 300;
659 r.fTop = rand.nextUScalar1() * 300;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000660 r.fRight = r.fLeft + 2 * size;
661 r.fBottom = r.fTop + 2 * size;
robertphillips@google.comb95eaa82012-10-18 15:26:12 +0000662
663 SkPath temp;
664
665 make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
666
667 REPORTER_ASSERT(reporter, temp.isConvex());
668 }
669}
670
robertphillips@google.com158618e2012-10-23 16:56:56 +0000671// Chrome will sometimes create a 0 radius round rect. The degenerate
672// quads prevent the path from being converted to a rect
673// Note: PathBench::ArbRoundRectBench performs almost exactly
674// the same test (but with drawing)
675static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) {
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000676 SkRandom rand;
robertphillips@google.com158618e2012-10-23 16:56:56 +0000677 SkRect r;
678
679 for (int i = 0; i < 5000; ++i) {
680
681 SkScalar size = rand.nextUScalar1() * 30;
682 if (size < SK_Scalar1) {
683 continue;
684 }
685 r.fLeft = rand.nextUScalar1() * 300;
686 r.fTop = rand.nextUScalar1() * 300;
687 r.fRight = r.fLeft + 2 * size;
688 r.fBottom = r.fTop + 2 * size;
689
690 SkPath temp;
691
692 make_arb_round_rect(&temp, r, 0, 0);
693
robertphillips@google.com158618e2012-10-23 16:56:56 +0000694 SkRect result;
695 REPORTER_ASSERT(reporter, temp.isRect(&result));
696 REPORTER_ASSERT(reporter, r == result);
robertphillips@google.com158618e2012-10-23 16:56:56 +0000697 }
698}
699
reed@google.com0bb18bb2012-07-26 15:20:36 +0000700static void test_rect_isfinite(skiatest::Reporter* reporter) {
701 const SkScalar inf = SK_ScalarInfinity;
caryclark@google.com7abfa492013-04-12 11:59:41 +0000702 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000703 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000704
reed@google.com0bb18bb2012-07-26 15:20:36 +0000705 SkRect r;
706 r.setEmpty();
707 REPORTER_ASSERT(reporter, r.isFinite());
caryclark@google.com7abfa492013-04-12 11:59:41 +0000708 r.set(0, 0, inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000709 REPORTER_ASSERT(reporter, !r.isFinite());
710 r.set(0, 0, nan, 0);
711 REPORTER_ASSERT(reporter, !r.isFinite());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000712
reed@google.com0bb18bb2012-07-26 15:20:36 +0000713 SkPoint pts[] = {
714 { 0, 0 },
715 { SK_Scalar1, 0 },
716 { 0, SK_Scalar1 },
717 };
rmistry@google.comd6176b02012-08-23 18:14:13 +0000718
reed@google.com0bb18bb2012-07-26 15:20:36 +0000719 bool isFine = r.setBoundsCheck(pts, 3);
720 REPORTER_ASSERT(reporter, isFine);
721 REPORTER_ASSERT(reporter, !r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000722
reed@google.com0bb18bb2012-07-26 15:20:36 +0000723 pts[1].set(inf, 0);
724 isFine = r.setBoundsCheck(pts, 3);
725 REPORTER_ASSERT(reporter, !isFine);
726 REPORTER_ASSERT(reporter, r.isEmpty());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000727
reed@google.com0bb18bb2012-07-26 15:20:36 +0000728 pts[1].set(nan, 0);
729 isFine = r.setBoundsCheck(pts, 3);
730 REPORTER_ASSERT(reporter, !isFine);
731 REPORTER_ASSERT(reporter, r.isEmpty());
732}
733
734static void test_path_isfinite(skiatest::Reporter* reporter) {
735 const SkScalar inf = SK_ScalarInfinity;
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000736 const SkScalar negInf = SK_ScalarNegativeInfinity;
reed@google.com0bb18bb2012-07-26 15:20:36 +0000737 const SkScalar nan = SK_ScalarNaN;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000738
reed@google.com0bb18bb2012-07-26 15:20:36 +0000739 SkPath path;
740 REPORTER_ASSERT(reporter, path.isFinite());
741
742 path.reset();
743 REPORTER_ASSERT(reporter, path.isFinite());
744
745 path.reset();
746 path.moveTo(SK_Scalar1, 0);
747 REPORTER_ASSERT(reporter, path.isFinite());
748
749 path.reset();
bsalomon@google.com50c79d82013-01-08 20:31:53 +0000750 path.moveTo(inf, negInf);
reed@google.com0bb18bb2012-07-26 15:20:36 +0000751 REPORTER_ASSERT(reporter, !path.isFinite());
752
753 path.reset();
754 path.moveTo(nan, 0);
755 REPORTER_ASSERT(reporter, !path.isFinite());
756}
757
758static void test_isfinite(skiatest::Reporter* reporter) {
759 test_rect_isfinite(reporter);
760 test_path_isfinite(reporter);
761}
762
reed@google.com744faba2012-05-29 19:54:52 +0000763// assert that we always
764// start with a moveTo
765// only have 1 moveTo
766// only have Lines after that
767// end with a single close
768// only have (at most) 1 close
769//
770static void test_poly(skiatest::Reporter* reporter, const SkPath& path,
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000771 const SkPoint srcPts[], bool expectClose) {
reed@google.com744faba2012-05-29 19:54:52 +0000772 SkPath::RawIter iter(path);
773 SkPoint pts[4];
reed@google.com744faba2012-05-29 19:54:52 +0000774
775 bool firstTime = true;
776 bool foundClose = false;
777 for (;;) {
778 switch (iter.next(pts)) {
779 case SkPath::kMove_Verb:
780 REPORTER_ASSERT(reporter, firstTime);
781 REPORTER_ASSERT(reporter, pts[0] == srcPts[0]);
782 srcPts++;
783 firstTime = false;
784 break;
785 case SkPath::kLine_Verb:
786 REPORTER_ASSERT(reporter, !firstTime);
787 REPORTER_ASSERT(reporter, pts[1] == srcPts[0]);
788 srcPts++;
789 break;
790 case SkPath::kQuad_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000791 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected quad verb");
reed@google.com744faba2012-05-29 19:54:52 +0000792 break;
reed@google.com277c3f82013-05-31 15:17:50 +0000793 case SkPath::kConic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000794 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected conic verb");
reed@google.com277c3f82013-05-31 15:17:50 +0000795 break;
reed@google.com744faba2012-05-29 19:54:52 +0000796 case SkPath::kCubic_Verb:
mtklein@google.com330313a2013-08-22 15:37:26 +0000797 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected cubic verb");
reed@google.com744faba2012-05-29 19:54:52 +0000798 break;
799 case SkPath::kClose_Verb:
800 REPORTER_ASSERT(reporter, !firstTime);
801 REPORTER_ASSERT(reporter, !foundClose);
802 REPORTER_ASSERT(reporter, expectClose);
803 foundClose = true;
804 break;
805 case SkPath::kDone_Verb:
806 goto DONE;
807 }
808 }
809DONE:
810 REPORTER_ASSERT(reporter, foundClose == expectClose);
811}
812
813static void test_addPoly(skiatest::Reporter* reporter) {
814 SkPoint pts[32];
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +0000815 SkRandom rand;
rmistry@google.comd6176b02012-08-23 18:14:13 +0000816
reed@google.com744faba2012-05-29 19:54:52 +0000817 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
818 pts[i].fX = rand.nextSScalar1();
819 pts[i].fY = rand.nextSScalar1();
820 }
821
822 for (int doClose = 0; doClose <= 1; ++doClose) {
823 for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) {
824 SkPath path;
bsalomon98806072014-12-12 15:11:17 -0800825 path.addPoly(pts, SkToInt(count), SkToBool(doClose));
sugoi@google.com54f0d1b2013-02-27 19:17:41 +0000826 test_poly(reporter, path, pts, SkToBool(doClose));
reed@google.com744faba2012-05-29 19:54:52 +0000827 }
828 }
829}
830
reed@google.com8b06f1a2012-05-29 12:03:46 +0000831static void test_strokerec(skiatest::Reporter* reporter) {
832 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
833 REPORTER_ASSERT(reporter, rec.isFillStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000834
reed@google.com8b06f1a2012-05-29 12:03:46 +0000835 rec.setHairlineStyle();
836 REPORTER_ASSERT(reporter, rec.isHairlineStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000837
reed@google.com8b06f1a2012-05-29 12:03:46 +0000838 rec.setStrokeStyle(SK_Scalar1, false);
839 REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000840
reed@google.com8b06f1a2012-05-29 12:03:46 +0000841 rec.setStrokeStyle(SK_Scalar1, true);
842 REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000843
reed@google.com8b06f1a2012-05-29 12:03:46 +0000844 rec.setStrokeStyle(0, false);
845 REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle());
rmistry@google.comd6176b02012-08-23 18:14:13 +0000846
reed@google.com8b06f1a2012-05-29 12:03:46 +0000847 rec.setStrokeStyle(0, true);
848 REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle());
849}
850
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000851// Set this for paths that don't have a consistent direction such as a bowtie.
852// (cheapComputeDirection is not expected to catch these.)
853static const SkPath::Direction kDontCheckDir = static_cast<SkPath::Direction>(-1);
854
855static void check_direction(skiatest::Reporter* reporter, const SkPath& path,
856 SkPath::Direction expected) {
857 if (expected == kDontCheckDir) {
858 return;
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000859 }
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000860 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
861
862 SkPath::Direction dir;
863 if (copy.cheapComputeDirection(&dir)) {
864 REPORTER_ASSERT(reporter, dir == expected);
865 } else {
866 REPORTER_ASSERT(reporter, SkPath::kUnknown_Direction == expected);
867 }
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000868}
869
reed@google.com3e71a882012-01-10 18:44:37 +0000870static void test_direction(skiatest::Reporter* reporter) {
871 size_t i;
872 SkPath path;
873 REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
874 REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCW_Direction));
875 REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCCW_Direction));
reed@google.coma8a3b3d2012-11-26 18:16:27 +0000876 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kUnknown_Direction));
reed@google.com3e71a882012-01-10 18:44:37 +0000877
878 static const char* gDegen[] = {
879 "M 10 10",
880 "M 10 10 M 20 20",
881 "M 10 10 L 20 20",
882 "M 10 10 L 10 10 L 10 10",
883 "M 10 10 Q 10 10 10 10",
884 "M 10 10 C 10 10 10 10 10 10",
885 };
886 for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) {
887 path.reset();
888 bool valid = SkParsePath::FromSVGString(gDegen[i], &path);
889 REPORTER_ASSERT(reporter, valid);
890 REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL));
891 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000892
reed@google.com3e71a882012-01-10 18:44:37 +0000893 static const char* gCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000894 "M 10 10 L 10 10 Q 20 10 20 20",
reed@google.com3e71a882012-01-10 18:44:37 +0000895 "M 10 10 C 20 10 20 20 20 20",
reed@google.comd4146662012-01-31 15:42:29 +0000896 "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 +0000897 // rect with top two corners replaced by cubics with identical middle
898 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000899 "M 10 10 C 10 0 10 0 20 0 L 40 0 C 50 0 50 0 50 10",
900 "M 20 10 L 0 10 Q 10 10 20 0", // left, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000901 };
902 for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) {
903 path.reset();
904 bool valid = SkParsePath::FromSVGString(gCW[i], &path);
905 REPORTER_ASSERT(reporter, valid);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000906 check_direction(reporter, path, SkPath::kCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000907 }
rmistry@google.comd6176b02012-08-23 18:14:13 +0000908
reed@google.com3e71a882012-01-10 18:44:37 +0000909 static const char* gCCW[] = {
reed@google.comcabaf1d2012-01-11 21:03:05 +0000910 "M 10 10 L 10 10 Q 20 10 20 -20",
reed@google.com3e71a882012-01-10 18:44:37 +0000911 "M 10 10 C 20 10 20 -20 20 -20",
reed@google.comd4146662012-01-31 15:42:29 +0000912 "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 +0000913 // rect with top two corners replaced by cubics with identical middle
914 // control points
reed@google.com20fb0c72012-11-13 13:47:39 +0000915 "M 50 10 C 50 0 50 0 40 0 L 20 0 C 10 0 10 0 10 10",
916 "M 10 10 L 30 10 Q 20 10 10 0", // right, degenerate serif
reed@google.com3e71a882012-01-10 18:44:37 +0000917 };
918 for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) {
919 path.reset();
920 bool valid = SkParsePath::FromSVGString(gCCW[i], &path);
921 REPORTER_ASSERT(reporter, valid);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000922 check_direction(reporter, path, SkPath::kCCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000923 }
reed@google.comac8543f2012-01-30 20:51:25 +0000924
925 // Test two donuts, each wound a different direction. Only the outer contour
926 // determines the cheap direction
927 path.reset();
928 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCW_Direction);
929 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000930 check_direction(reporter, path, SkPath::kCW_Direction);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000931
reed@google.comac8543f2012-01-30 20:51:25 +0000932 path.reset();
933 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCW_Direction);
934 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000935 check_direction(reporter, path, SkPath::kCCW_Direction);
bsalomon@google.comf0ed80a2012-02-17 13:38:26 +0000936
937 // triangle with one point really far from the origin.
938 path.reset();
939 // the first point is roughly 1.05e10, 1.05e10
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +0000940 path.moveTo(SkBits2Float(0x501c7652), SkBits2Float(0x501c7652));
bsalomon@google.com53aab782012-02-23 14:54:49 +0000941 path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1);
942 path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1);
bsalomon@google.com30c174b2012-11-13 14:36:42 +0000943 check_direction(reporter, path, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +0000944
945 path.reset();
946 path.conicTo(20, 0, 20, 20, 0.5f);
947 path.close();
948 check_direction(reporter, path, SkPath::kCW_Direction);
949
950 path.reset();
951 path.lineTo(1, 1e7f);
952 path.lineTo(1e7f, 2e7f);
953 path.close();
954 REPORTER_ASSERT(reporter, SkPath::kConvex_Convexity == path.getConvexity());
955 check_direction(reporter, path, SkPath::kCCW_Direction);
reed@google.com3e71a882012-01-10 18:44:37 +0000956}
957
reed@google.comffdb0182011-11-14 19:29:14 +0000958static void add_rect(SkPath* path, const SkRect& r) {
959 path->moveTo(r.fLeft, r.fTop);
960 path->lineTo(r.fRight, r.fTop);
961 path->lineTo(r.fRight, r.fBottom);
962 path->lineTo(r.fLeft, r.fBottom);
963 path->close();
964}
965
966static void test_bounds(skiatest::Reporter* reporter) {
967 static const SkRect rects[] = {
reed@google.com3563c9e2011-11-14 19:34:57 +0000968 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) },
969 { SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) },
970 { SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) },
971 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) },
reed@google.comffdb0182011-11-14 19:29:14 +0000972 };
973
974 SkPath path0, path1;
975 for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) {
976 path0.addRect(rects[i]);
977 add_rect(&path1, rects[i]);
978 }
979
980 REPORTER_ASSERT(reporter, path0.getBounds() == path1.getBounds());
981}
982
reed@google.com55b5f4b2011-09-07 12:23:41 +0000983static void stroke_cubic(const SkPoint pts[4]) {
984 SkPath path;
985 path.moveTo(pts[0]);
986 path.cubicTo(pts[1], pts[2], pts[3]);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000987
reed@google.com55b5f4b2011-09-07 12:23:41 +0000988 SkPaint paint;
989 paint.setStyle(SkPaint::kStroke_Style);
990 paint.setStrokeWidth(SK_Scalar1 * 2);
rmistry@google.comd6176b02012-08-23 18:14:13 +0000991
reed@google.com55b5f4b2011-09-07 12:23:41 +0000992 SkPath fill;
993 paint.getFillPath(path, &fill);
994}
995
996// just ensure this can run w/o any SkASSERTS firing in the debug build
997// we used to assert due to differences in how we determine a degenerate vector
998// but that was fixed with the introduction of SkPoint::CanNormalize
999static void stroke_tiny_cubic() {
1000 SkPoint p0[] = {
1001 { 372.0f, 92.0f },
1002 { 372.0f, 92.0f },
1003 { 372.0f, 92.0f },
1004 { 372.0f, 92.0f },
1005 };
rmistry@google.comd6176b02012-08-23 18:14:13 +00001006
reed@google.com55b5f4b2011-09-07 12:23:41 +00001007 stroke_cubic(p0);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001008
reed@google.com55b5f4b2011-09-07 12:23:41 +00001009 SkPoint p1[] = {
1010 { 372.0f, 92.0f },
1011 { 372.0007f, 92.000755f },
1012 { 371.99927f, 92.003922f },
1013 { 371.99826f, 92.003899f },
1014 };
rmistry@google.comd6176b02012-08-23 18:14:13 +00001015
reed@google.com55b5f4b2011-09-07 12:23:41 +00001016 stroke_cubic(p1);
1017}
1018
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001019static void check_close(skiatest::Reporter* reporter, const SkPath& path) {
1020 for (int i = 0; i < 2; ++i) {
robertphillips@google.com09042b82012-04-06 20:01:46 +00001021 SkPath::Iter iter(path, SkToBool(i));
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001022 SkPoint mv;
1023 SkPoint pts[4];
1024 SkPath::Verb v;
1025 int nMT = 0;
1026 int nCL = 0;
tomhudson@google.com221db3c2011-07-28 21:10:29 +00001027 mv.set(0, 0);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001028 while (SkPath::kDone_Verb != (v = iter.next(pts))) {
1029 switch (v) {
1030 case SkPath::kMove_Verb:
1031 mv = pts[0];
1032 ++nMT;
1033 break;
1034 case SkPath::kClose_Verb:
1035 REPORTER_ASSERT(reporter, mv == pts[0]);
1036 ++nCL;
1037 break;
1038 default:
1039 break;
1040 }
1041 }
1042 // if we force a close on the interator we should have a close
1043 // for every moveTo
1044 REPORTER_ASSERT(reporter, !i || nMT == nCL);
1045 }
1046}
1047
1048static void test_close(skiatest::Reporter* reporter) {
1049 SkPath closePt;
1050 closePt.moveTo(0, 0);
1051 closePt.close();
1052 check_close(reporter, closePt);
1053
1054 SkPath openPt;
1055 openPt.moveTo(0, 0);
1056 check_close(reporter, openPt);
1057
1058 SkPath empty;
1059 check_close(reporter, empty);
1060 empty.close();
1061 check_close(reporter, empty);
1062
1063 SkPath rect;
1064 rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1065 check_close(reporter, rect);
1066 rect.close();
1067 check_close(reporter, rect);
1068
1069 SkPath quad;
1070 quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1071 check_close(reporter, quad);
1072 quad.close();
1073 check_close(reporter, quad);
1074
1075 SkPath cubic;
rmistry@google.comd6176b02012-08-23 18:14:13 +00001076 quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1,
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001077 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1);
1078 check_close(reporter, cubic);
1079 cubic.close();
1080 check_close(reporter, cubic);
1081
1082 SkPath line;
1083 line.moveTo(SK_Scalar1, SK_Scalar1);
1084 line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1);
1085 check_close(reporter, line);
1086 line.close();
1087 check_close(reporter, line);
1088
1089 SkPath rect2;
1090 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1091 rect2.close();
1092 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1093 check_close(reporter, rect2);
1094 rect2.close();
1095 check_close(reporter, rect2);
1096
1097 SkPath oval3;
1098 oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100));
1099 oval3.close();
1100 oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200));
1101 check_close(reporter, oval3);
1102 oval3.close();
1103 check_close(reporter, oval3);
1104
1105 SkPath moves;
1106 moves.moveTo(SK_Scalar1, SK_Scalar1);
1107 moves.moveTo(5 * SK_Scalar1, SK_Scalar1);
1108 moves.moveTo(SK_Scalar1, 10 * SK_Scalar1);
1109 moves.moveTo(10 *SK_Scalar1, SK_Scalar1);
1110 check_close(reporter, moves);
reed@google.com55b5f4b2011-09-07 12:23:41 +00001111
1112 stroke_tiny_cubic();
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00001113}
1114
reed@google.com7c424812011-05-15 04:38:34 +00001115static void check_convexity(skiatest::Reporter* reporter, const SkPath& path,
1116 SkPath::Convexity expected) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001117 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
1118 SkPath::Convexity c = copy.getConvexity();
reed@google.com7c424812011-05-15 04:38:34 +00001119 REPORTER_ASSERT(reporter, c == expected);
1120}
1121
1122static void test_convexity2(skiatest::Reporter* reporter) {
1123 SkPath pt;
1124 pt.moveTo(0, 0);
1125 pt.close();
reed@google.comb54455e2011-05-16 14:16:04 +00001126 check_convexity(reporter, pt, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001127 check_direction(reporter, pt, SkPath::kUnknown_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001128
reed@google.com7c424812011-05-15 04:38:34 +00001129 SkPath line;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001130 line.moveTo(12*SK_Scalar1, 20*SK_Scalar1);
1131 line.lineTo(-12*SK_Scalar1, -20*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001132 line.close();
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001133 check_convexity(reporter, line, SkPath::kConvex_Convexity);
1134 check_direction(reporter, line, SkPath::kUnknown_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001135
reed@google.com7c424812011-05-15 04:38:34 +00001136 SkPath triLeft;
1137 triLeft.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001138 triLeft.lineTo(SK_Scalar1, 0);
1139 triLeft.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001140 triLeft.close();
1141 check_convexity(reporter, triLeft, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001142 check_direction(reporter, triLeft, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001143
reed@google.com7c424812011-05-15 04:38:34 +00001144 SkPath triRight;
1145 triRight.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001146 triRight.lineTo(-SK_Scalar1, 0);
1147 triRight.lineTo(SK_Scalar1, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001148 triRight.close();
1149 check_convexity(reporter, triRight, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001150 check_direction(reporter, triRight, SkPath::kCCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001151
reed@google.com7c424812011-05-15 04:38:34 +00001152 SkPath square;
1153 square.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001154 square.lineTo(SK_Scalar1, 0);
1155 square.lineTo(SK_Scalar1, SK_Scalar1);
1156 square.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001157 square.close();
1158 check_convexity(reporter, square, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001159 check_direction(reporter, square, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001160
reed@google.com7c424812011-05-15 04:38:34 +00001161 SkPath redundantSquare;
1162 redundantSquare.moveTo(0, 0);
1163 redundantSquare.lineTo(0, 0);
1164 redundantSquare.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001165 redundantSquare.lineTo(SK_Scalar1, 0);
1166 redundantSquare.lineTo(SK_Scalar1, 0);
1167 redundantSquare.lineTo(SK_Scalar1, 0);
1168 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1169 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1170 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1171 redundantSquare.lineTo(0, SK_Scalar1);
1172 redundantSquare.lineTo(0, SK_Scalar1);
1173 redundantSquare.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001174 redundantSquare.close();
1175 check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001176 check_direction(reporter, redundantSquare, SkPath::kCW_Direction);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001177
reed@google.com7c424812011-05-15 04:38:34 +00001178 SkPath bowTie;
1179 bowTie.moveTo(0, 0);
1180 bowTie.lineTo(0, 0);
1181 bowTie.lineTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001182 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1183 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1184 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1185 bowTie.lineTo(SK_Scalar1, 0);
1186 bowTie.lineTo(SK_Scalar1, 0);
1187 bowTie.lineTo(SK_Scalar1, 0);
1188 bowTie.lineTo(0, SK_Scalar1);
1189 bowTie.lineTo(0, SK_Scalar1);
1190 bowTie.lineTo(0, SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001191 bowTie.close();
1192 check_convexity(reporter, bowTie, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001193 check_direction(reporter, bowTie, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001194
reed@google.com7c424812011-05-15 04:38:34 +00001195 SkPath spiral;
1196 spiral.moveTo(0, 0);
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001197 spiral.lineTo(100*SK_Scalar1, 0);
1198 spiral.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1199 spiral.lineTo(0, 100*SK_Scalar1);
1200 spiral.lineTo(0, 50*SK_Scalar1);
1201 spiral.lineTo(50*SK_Scalar1, 50*SK_Scalar1);
1202 spiral.lineTo(50*SK_Scalar1, 75*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001203 spiral.close();
reed@google.com85b6e392011-05-15 20:25:17 +00001204 check_convexity(reporter, spiral, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001205 check_direction(reporter, spiral, kDontCheckDir);
rmistry@google.comd6176b02012-08-23 18:14:13 +00001206
reed@google.com7c424812011-05-15 04:38:34 +00001207 SkPath dent;
schenney@chromium.org6c31d9d2011-12-20 16:33:30 +00001208 dent.moveTo(0, 0);
1209 dent.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1210 dent.lineTo(0, 100*SK_Scalar1);
1211 dent.lineTo(-50*SK_Scalar1, 200*SK_Scalar1);
1212 dent.lineTo(-200*SK_Scalar1, 100*SK_Scalar1);
reed@google.com7c424812011-05-15 04:38:34 +00001213 dent.close();
1214 check_convexity(reporter, dent, SkPath::kConcave_Convexity);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001215 check_direction(reporter, dent, SkPath::kCW_Direction);
commit-bot@chromium.org8be07bb2014-05-22 14:58:53 +00001216
1217 // http://skbug.com/2235
1218 SkPath strokedSin;
1219 for (int i = 0; i < 2000; i++) {
1220 SkScalar x = SkIntToScalar(i) / 2;
1221 SkScalar y = 500 - (x + SkScalarSin(x / 100) * 40) / 3;
1222 if (0 == i) {
1223 strokedSin.moveTo(x, y);
1224 } else {
1225 strokedSin.lineTo(x, y);
1226 }
1227 }
1228 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
1229 stroke.setStrokeStyle(2 * SK_Scalar1);
1230 stroke.applyToPath(&strokedSin, strokedSin);
1231 check_convexity(reporter, strokedSin, SkPath::kConcave_Convexity);
1232 check_direction(reporter, strokedSin, kDontCheckDir);
robertphillipsc506e302014-09-16 09:43:31 -07001233
1234 // http://crbug.com/412640
1235 SkPath degenerateConcave;
1236 degenerateConcave.moveTo(148.67912f, 191.875f);
1237 degenerateConcave.lineTo(470.37695f, 7.5f);
1238 degenerateConcave.lineTo(148.67912f, 191.875f);
1239 degenerateConcave.lineTo(41.446522f, 376.25f);
1240 degenerateConcave.lineTo(-55.971577f, 460.0f);
1241 degenerateConcave.lineTo(41.446522f, 376.25f);
1242 check_convexity(reporter, degenerateConcave, SkPath::kConcave_Convexity);
1243 check_direction(reporter, degenerateConcave, SkPath::kUnknown_Direction);
robertphillipsf52a0632014-11-17 12:11:42 -08001244
1245 // http://crbug.com/433683
1246 SkPath badFirstVector;
1247 badFirstVector.moveTo(501.087708f, 319.610352f);
1248 badFirstVector.lineTo(501.087708f, 319.610352f);
1249 badFirstVector.cubicTo(501.087677f, 319.610321f, 449.271606f, 258.078674f, 395.084564f, 198.711182f);
1250 badFirstVector.cubicTo(358.967072f, 159.140717f, 321.910553f, 120.650436f, 298.442322f, 101.955399f);
1251 badFirstVector.lineTo(301.557678f, 98.044601f);
1252 badFirstVector.cubicTo(325.283844f, 116.945084f, 362.615204f, 155.720825f, 398.777557f, 195.340454f);
1253 badFirstVector.cubicTo(453.031860f, 254.781662f, 504.912262f, 316.389618f, 504.912292f, 316.389648f);
1254 badFirstVector.lineTo(504.912292f, 316.389648f);
1255 badFirstVector.lineTo(501.087708f, 319.610352f);
1256 badFirstVector.close();
1257 check_convexity(reporter, badFirstVector, SkPath::kConcave_Convexity);
reed@google.com7c424812011-05-15 04:38:34 +00001258}
1259
reed@android.com6b82d1a2009-06-03 02:35:01 +00001260static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
1261 const SkRect& bounds) {
1262 REPORTER_ASSERT(reporter, p.isConvex());
1263 REPORTER_ASSERT(reporter, p.getBounds() == bounds);
reed@google.com62047cf2011-02-07 19:39:09 +00001264
reed@android.com6b82d1a2009-06-03 02:35:01 +00001265 SkPath p2(p);
1266 REPORTER_ASSERT(reporter, p2.isConvex());
1267 REPORTER_ASSERT(reporter, p2.getBounds() == bounds);
1268
1269 SkPath other;
1270 other.swap(p2);
1271 REPORTER_ASSERT(reporter, other.isConvex());
1272 REPORTER_ASSERT(reporter, other.getBounds() == bounds);
1273}
1274
reed@google.com04863fa2011-05-15 04:08:24 +00001275static void setFromString(SkPath* path, const char str[]) {
1276 bool first = true;
1277 while (str) {
1278 SkScalar x, y;
1279 str = SkParse::FindScalar(str, &x);
1280 if (NULL == str) {
1281 break;
1282 }
1283 str = SkParse::FindScalar(str, &y);
1284 SkASSERT(str);
1285 if (first) {
1286 path->moveTo(x, y);
1287 first = false;
1288 } else {
1289 path->lineTo(x, y);
1290 }
1291 }
1292}
1293
1294static void test_convexity(skiatest::Reporter* reporter) {
reed@google.com04863fa2011-05-15 04:08:24 +00001295 SkPath path;
1296
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001297 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001298 path.addCircle(0, 0, SkIntToScalar(10));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001299 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.come3543972012-01-10 18:59:22 +00001300 path.addCircle(0, 0, SkIntToScalar(10)); // 2nd circle
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001301 check_convexity(reporter, path, SkPath::kConcave_Convexity);
1302
reed@google.com04863fa2011-05-15 04:08:24 +00001303 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001304 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001305 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.com3e71a882012-01-10 18:44:37 +00001306 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCCW_Direction));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001307
reed@google.com04863fa2011-05-15 04:08:24 +00001308 path.reset();
reed@google.come3543972012-01-10 18:59:22 +00001309 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001310 check_convexity(reporter, path, SkPath::kConvex_Convexity);
reed@google.com3e71a882012-01-10 18:44:37 +00001311 REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCW_Direction));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001312
reed@google.com04863fa2011-05-15 04:08:24 +00001313 static const struct {
1314 const char* fPathStr;
1315 SkPath::Convexity fExpectedConvexity;
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001316 SkPath::Direction fExpectedDirection;
reed@google.com04863fa2011-05-15 04:08:24 +00001317 } gRec[] = {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001318 { "", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1319 { "0 0", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1320 { "0 0 10 10", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction },
1321 { "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity, SkPath::kUnknown_Direction },
1322 { "0 0 10 10 10 20", SkPath::kConvex_Convexity, SkPath::kCW_Direction },
1323 { "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPath::kCCW_Direction },
1324 { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir },
1325 { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity, SkPath::kCW_Direction },
reed@google.com04863fa2011-05-15 04:08:24 +00001326 };
1327
1328 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1329 SkPath path;
1330 setFromString(&path, gRec[i].fPathStr);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00001331 check_convexity(reporter, path, gRec[i].fExpectedConvexity);
1332 check_direction(reporter, path, gRec[i].fExpectedDirection);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001333 // check after setting the initial convex and direction
1334 if (kDontCheckDir != gRec[i].fExpectedDirection) {
1335 SkPath copy(path);
1336 SkPath::Direction dir;
1337 bool foundDir = copy.cheapComputeDirection(&dir);
1338 REPORTER_ASSERT(reporter, (gRec[i].fExpectedDirection == SkPath::kUnknown_Direction)
1339 ^ foundDir);
1340 REPORTER_ASSERT(reporter, !foundDir || gRec[i].fExpectedDirection == dir);
1341 check_convexity(reporter, copy, gRec[i].fExpectedConvexity);
1342 }
1343 REPORTER_ASSERT(reporter, gRec[i].fExpectedConvexity == path.getConvexity());
1344 check_direction(reporter, path, gRec[i].fExpectedDirection);
reed@google.com04863fa2011-05-15 04:08:24 +00001345 }
caryclarkd3d1a982014-12-08 04:57:38 -08001346
1347 static const SkPoint nonFinitePts[] = {
1348 { SK_ScalarInfinity, 0 },
1349 { 0, SK_ScalarInfinity },
1350 { SK_ScalarInfinity, SK_ScalarInfinity },
1351 { SK_ScalarNegativeInfinity, 0},
1352 { 0, SK_ScalarNegativeInfinity },
1353 { SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity },
1354 { SK_ScalarNegativeInfinity, SK_ScalarInfinity },
1355 { SK_ScalarInfinity, SK_ScalarNegativeInfinity },
1356 { SK_ScalarNaN, 0 },
1357 { 0, SK_ScalarNaN },
1358 { SK_ScalarNaN, SK_ScalarNaN },
1359 };
1360
1361 const size_t nonFinitePtsCount = sizeof(nonFinitePts) / sizeof(nonFinitePts[0]);
1362
1363 static const SkPoint finitePts[] = {
1364 { SK_ScalarMax, 0 },
1365 { 0, SK_ScalarMax },
1366 { SK_ScalarMax, SK_ScalarMax },
1367 { SK_ScalarMin, 0 },
1368 { 0, SK_ScalarMin },
1369 { SK_ScalarMin, SK_ScalarMin },
1370 };
1371
1372 const size_t finitePtsCount = sizeof(finitePts) / sizeof(finitePts[0]);
1373
1374 for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount); ++index) {
1375 int i = (int) (index % nonFinitePtsCount);
1376 int f = (int) (index % finitePtsCount);
1377 int g = (int) ((f + 1) % finitePtsCount);
1378 path.reset();
1379 switch (index % 13) {
1380 case 0: path.lineTo(nonFinitePts[i]); break;
1381 case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break;
1382 case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break;
1383 case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break;
1384 case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); break;
1385 case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); break;
1386 case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); break;
1387 case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f]); break;
1388 case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i]); break;
1389 case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i]); break;
1390 case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts[i]); break;
1391 case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]); break;
1392 case 12: path.moveTo(nonFinitePts[i]); break;
1393 }
1394 check_convexity(reporter, path, SkPath::kUnknown_Convexity);
1395 }
1396
1397 for (int index = 0; index < (int) (11 * finitePtsCount); ++index) {
1398 int f = (int) (index % finitePtsCount);
1399 int g = (int) ((f + 1) % finitePtsCount);
1400 path.reset();
1401 int curveSelect = index % 11;
1402 switch (curveSelect) {
1403 case 0: path.moveTo(finitePts[f]); break;
1404 case 1: path.lineTo(finitePts[f]); break;
1405 case 2: path.quadTo(finitePts[f], finitePts[f]); break;
1406 case 3: path.quadTo(finitePts[f], finitePts[g]); break;
1407 case 4: path.quadTo(finitePts[g], finitePts[f]); break;
1408 case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); break;
1409 case 6: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); break;
1410 case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); break;
1411 case 8: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); break;
1412 case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); break;
1413 case 10: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); break;
1414 }
1415 check_convexity(reporter, path, curveSelect == 0 ? SkPath::kConvex_Convexity
1416 : SkPath::kUnknown_Convexity);
1417 }
1418
reed@google.com04863fa2011-05-15 04:08:24 +00001419}
1420
reed@google.com7e6c4d12012-05-10 14:05:43 +00001421static void test_isLine(skiatest::Reporter* reporter) {
1422 SkPath path;
1423 SkPoint pts[2];
1424 const SkScalar value = SkIntToScalar(5);
1425
1426 REPORTER_ASSERT(reporter, !path.isLine(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001427
reed@google.com7e6c4d12012-05-10 14:05:43 +00001428 // set some non-zero values
1429 pts[0].set(value, value);
1430 pts[1].set(value, value);
1431 REPORTER_ASSERT(reporter, !path.isLine(pts));
1432 // check that pts was untouched
1433 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1434 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1435
1436 const SkScalar moveX = SkIntToScalar(1);
1437 const SkScalar moveY = SkIntToScalar(2);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001438 REPORTER_ASSERT(reporter, value != moveX && value != moveY);
reed@google.com7e6c4d12012-05-10 14:05:43 +00001439
1440 path.moveTo(moveX, moveY);
1441 REPORTER_ASSERT(reporter, !path.isLine(NULL));
1442 REPORTER_ASSERT(reporter, !path.isLine(pts));
1443 // check that pts was untouched
1444 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1445 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1446
1447 const SkScalar lineX = SkIntToScalar(2);
1448 const SkScalar lineY = SkIntToScalar(2);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001449 REPORTER_ASSERT(reporter, value != lineX && value != lineY);
reed@google.com7e6c4d12012-05-10 14:05:43 +00001450
1451 path.lineTo(lineX, lineY);
1452 REPORTER_ASSERT(reporter, path.isLine(NULL));
1453
1454 REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY));
1455 REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY));
1456 REPORTER_ASSERT(reporter, path.isLine(pts));
1457 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1458 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
1459
1460 path.lineTo(0, 0); // too many points/verbs
1461 REPORTER_ASSERT(reporter, !path.isLine(NULL));
1462 REPORTER_ASSERT(reporter, !path.isLine(pts));
1463 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1464 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001465
1466 path.reset();
1467 path.quadTo(1, 1, 2, 2);
1468 REPORTER_ASSERT(reporter, !path.isLine(NULL));
reed@google.com7e6c4d12012-05-10 14:05:43 +00001469}
1470
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001471static void test_conservativelyContains(skiatest::Reporter* reporter) {
1472 SkPath path;
1473
1474 // kBaseRect is used to construct most our test paths: a rect, a circle, and a round-rect.
1475 static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
1476
1477 // A circle that bounds kBaseRect (with a significant amount of slop)
1478 SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height());
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001479 circleR = SkScalarMul(circleR, 1.75f) / 2;
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001480 static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()};
1481
1482 // round-rect radii
1483 static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)};
skia.committer@gmail.comcec8de62012-11-14 02:01:22 +00001484
caryclark@google.com56f233a2012-11-19 13:06:06 +00001485 static const struct SUPPRESS_VISIBILITY_WARNING {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001486 SkRect fQueryRect;
1487 bool fInRect;
1488 bool fInCircle;
1489 bool fInRR;
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001490 bool fInCubicRR;
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001491 } kQueries[] = {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001492 {kBaseRect, true, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001493
1494 // rect well inside of kBaseRect
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001495 {SkRect::MakeLTRB(kBaseRect.fLeft + 0.25f*kBaseRect.width(),
1496 kBaseRect.fTop + 0.25f*kBaseRect.height(),
1497 kBaseRect.fRight - 0.25f*kBaseRect.width(),
1498 kBaseRect.fBottom - 0.25f*kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001499 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001500
1501 // rects with edges off by one from kBaseRect's edges
1502 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1503 kBaseRect.width(), kBaseRect.height() + 1),
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,
1506 kBaseRect.width() + 1, 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 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1509 kBaseRect.width() + 1, kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001510 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001511 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1512 kBaseRect.width(), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001513 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001514 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1515 kBaseRect.width(), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001516 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001517 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1518 kBaseRect.width() + 2, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001519 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001520 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1521 kBaseRect.width() + 2, kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001522 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001523
1524 // zero-w/h rects at each corner of kBaseRect
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001525 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, false, false},
1526 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, false, true},
1527 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true, false, true},
1528 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true, false, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001529
1530 // far away rect
1531 {SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom,
1532 SkIntToScalar(10), SkIntToScalar(10)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001533 false, false, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001534
1535 // very large rect containing kBaseRect
1536 {SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(),
1537 kBaseRect.fTop - 5 * kBaseRect.height(),
1538 11 * kBaseRect.width(), 11 * kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001539 false, false, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001540
1541 // skinny rect that spans same y-range as kBaseRect
1542 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1543 SkIntToScalar(1), kBaseRect.height()),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001544 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001545
1546 // short rect that spans same x-range as kBaseRect
1547 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(), SkScalar(1)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001548 true, true, true, true},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001549
1550 // skinny rect that spans slightly larger y-range than kBaseRect
1551 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1552 SkIntToScalar(1), kBaseRect.height() + 1),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001553 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001554
1555 // short rect that spans slightly larger x-range than kBaseRect
1556 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(),
1557 kBaseRect.width() + 1, SkScalar(1)),
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001558 false, true, false, false},
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001559 };
1560
1561 for (int inv = 0; inv < 4; ++inv) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001562 for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) {
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001563 SkRect qRect = kQueries[q].fQueryRect;
1564 if (inv & 0x1) {
1565 SkTSwap(qRect.fLeft, qRect.fRight);
1566 }
1567 if (inv & 0x2) {
1568 SkTSwap(qRect.fTop, qRect.fBottom);
1569 }
1570 for (int d = 0; d < 2; ++d) {
1571 SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
1572 path.reset();
1573 path.addRect(kBaseRect, dir);
1574 REPORTER_ASSERT(reporter, kQueries[q].fInRect ==
1575 path.conservativelyContainsRect(qRect));
1576
1577 path.reset();
1578 path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir);
1579 REPORTER_ASSERT(reporter, kQueries[q].fInCircle ==
1580 path.conservativelyContainsRect(qRect));
1581
1582 path.reset();
1583 path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir);
1584 REPORTER_ASSERT(reporter, kQueries[q].fInRR ==
1585 path.conservativelyContainsRect(qRect));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001586
1587 path.reset();
1588 path.moveTo(kBaseRect.fLeft + kRRRadii[0], kBaseRect.fTop);
1589 path.cubicTo(kBaseRect.fLeft + kRRRadii[0] / 2, kBaseRect.fTop,
1590 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1] / 2,
1591 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1]);
1592 path.lineTo(kBaseRect.fLeft, kBaseRect.fBottom);
1593 path.lineTo(kBaseRect.fRight, kBaseRect.fBottom);
1594 path.lineTo(kBaseRect.fRight, kBaseRect.fTop);
1595 path.close();
1596 REPORTER_ASSERT(reporter, kQueries[q].fInCubicRR ==
1597 path.conservativelyContainsRect(qRect));
1598
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001599 }
1600 // Slightly non-convex shape, shouldn't contain any rects.
1601 path.reset();
1602 path.moveTo(0, 0);
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00001603 path.lineTo(SkIntToScalar(50), 0.05f);
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001604 path.lineTo(SkIntToScalar(100), 0);
1605 path.lineTo(SkIntToScalar(100), SkIntToScalar(100));
1606 path.lineTo(0, SkIntToScalar(100));
1607 path.close();
1608 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect));
1609 }
1610 }
1611
1612 // make sure a minimal convex shape works, a right tri with edges along pos x and y axes.
1613 path.reset();
1614 path.moveTo(0, 0);
1615 path.lineTo(SkIntToScalar(100), 0);
1616 path.lineTo(0, SkIntToScalar(100));
1617
1618 // inside, on along top edge
1619 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1620 SkIntToScalar(10),
1621 SkIntToScalar(10))));
1622 // above
1623 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1624 SkRect::MakeXYWH(SkIntToScalar(50),
1625 SkIntToScalar(-10),
1626 SkIntToScalar(10),
1627 SkIntToScalar(10))));
1628 // to the left
1629 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(-10),
1630 SkIntToScalar(5),
1631 SkIntToScalar(5),
1632 SkIntToScalar(5))));
1633
1634 // outside the diagonal edge
1635 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(10),
1636 SkIntToScalar(200),
1637 SkIntToScalar(20),
1638 SkIntToScalar(5))));
commit-bot@chromium.org62df5262013-08-01 15:35:06 +00001639
bsalomonb17c1292014-08-28 14:04:55 -07001640
1641 // Test that multiple move commands do not cause asserts.
1642
1643 // At the time of writing, this would not modify cached convexity. This caused an assert while
1644 // checking conservative containment again. http://skbug.com/1460
1645 path.moveTo(SkIntToScalar(100), SkIntToScalar(100));
1646#if 0
1647 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1648 SkIntToScalar(10),
1649 SkIntToScalar(10))));
1650#endif
1651
1652 // Same as above path and first test but with an extra moveTo.
commit-bot@chromium.org62df5262013-08-01 15:35:06 +00001653 path.reset();
1654 path.moveTo(100, 100);
1655 path.moveTo(0, 0);
1656 path.lineTo(SkIntToScalar(100), 0);
1657 path.lineTo(0, SkIntToScalar(100));
1658
1659 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1660 SkIntToScalar(10),
1661 SkIntToScalar(10))));
1662
bsalomonb17c1292014-08-28 14:04:55 -07001663 // Test that multiple move commands do not cause asserts and that the function
1664 // is not confused by the multiple moves.
1665 path.reset();
1666 path.moveTo(0, 0);
1667 path.lineTo(SkIntToScalar(100), 0);
1668 path.lineTo(0, SkIntToScalar(100));
1669 path.moveTo(0, SkIntToScalar(200));
1670 path.lineTo(SkIntToScalar(100), SkIntToScalar(200));
1671 path.lineTo(0, SkIntToScalar(300));
1672
1673 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1674 SkRect::MakeXYWH(SkIntToScalar(50), 0,
1675 SkIntToScalar(10),
1676 SkIntToScalar(10))));
1677
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00001678 path.reset();
1679 path.lineTo(100, 100);
1680 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(0, 0, 1, 1)));
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00001681}
1682
reed@google.comf32322b2013-10-16 15:14:04 +00001683static void test_isRect_open_close(skiatest::Reporter* reporter) {
1684 SkPath path;
1685 bool isClosed;
1686
1687 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1);
reed@google.comf32322b2013-10-16 15:14:04 +00001688 path.close();
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00001689
robertphillips91b0a352015-01-05 10:13:46 -08001690 REPORTER_ASSERT(reporter, path.isRect(NULL, &isClosed, NULL));
reed@google.comf32322b2013-10-16 15:14:04 +00001691 REPORTER_ASSERT(reporter, isClosed);
1692}
1693
caryclark@google.comf1316942011-07-26 19:54:45 +00001694// Simple isRect test is inline TestPath, below.
1695// test_isRect provides more extensive testing.
1696static void test_isRect(skiatest::Reporter* reporter) {
reed@google.comf32322b2013-10-16 15:14:04 +00001697 test_isRect_open_close(reporter);
1698
caryclark@google.comf1316942011-07-26 19:54:45 +00001699 // passing tests (all moveTo / lineTo...
1700 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1701 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1702 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1703 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
1704 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
1705 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1706 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1707 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1708 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001709 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}};
1710 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 +00001711 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}};
1712 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
1713 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}};
caryclark@google.combfe90372012-11-21 13:56:20 +00001714 SkPoint rf[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}};
rmistry@google.comd6176b02012-08-23 18:14:13 +00001715
caryclark@google.comf1316942011-07-26 19:54:45 +00001716 // failing tests
1717 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1718 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1719 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1720 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1721 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1722 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1723 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1724 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
caryclark@google.combfe90372012-11-21 13:56:20 +00001725 SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps
1726 SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non colinear gap
1727 SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short
rmistry@google.comd6176b02012-08-23 18:14:13 +00001728
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00001729 // no close, but we should detect them as fillably the same as a rect
1730 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1731 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}};
1732 SkPoint c3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 0}}; // hit the start
1733
1734 // like c2, but we double-back on ourselves
1735 SkPoint d1[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 2}};
1736 // like c2, but we overshoot the start point
1737 SkPoint d2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}};
1738 SkPoint d3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}, {0, 0}};
caryclark@google.comf1316942011-07-26 19:54:45 +00001739
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001740 struct IsRectTest {
1741 SkPoint *fPoints;
bsalomon98806072014-12-12 15:11:17 -08001742 int fPointCount;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001743 bool fClose;
1744 bool fIsRect;
1745 } tests[] = {
1746 { r1, SK_ARRAY_COUNT(r1), true, true },
1747 { r2, SK_ARRAY_COUNT(r2), true, true },
1748 { r3, SK_ARRAY_COUNT(r3), true, true },
1749 { r4, SK_ARRAY_COUNT(r4), true, true },
1750 { r5, SK_ARRAY_COUNT(r5), true, true },
1751 { r6, SK_ARRAY_COUNT(r6), true, true },
1752 { r7, SK_ARRAY_COUNT(r7), true, true },
1753 { r8, SK_ARRAY_COUNT(r8), true, true },
1754 { r9, SK_ARRAY_COUNT(r9), true, true },
1755 { ra, SK_ARRAY_COUNT(ra), true, true },
1756 { rb, SK_ARRAY_COUNT(rb), true, true },
1757 { rc, SK_ARRAY_COUNT(rc), true, true },
1758 { rd, SK_ARRAY_COUNT(rd), true, true },
1759 { re, SK_ARRAY_COUNT(re), true, true },
1760 { rf, SK_ARRAY_COUNT(rf), true, true },
1761
1762 { f1, SK_ARRAY_COUNT(f1), true, false },
1763 { f2, SK_ARRAY_COUNT(f2), true, false },
1764 { f3, SK_ARRAY_COUNT(f3), true, false },
1765 { f4, SK_ARRAY_COUNT(f4), true, false },
1766 { f5, SK_ARRAY_COUNT(f5), true, false },
1767 { f6, SK_ARRAY_COUNT(f6), true, false },
1768 { f7, SK_ARRAY_COUNT(f7), true, false },
1769 { f8, SK_ARRAY_COUNT(f8), true, false },
1770 { f9, SK_ARRAY_COUNT(f9), true, false },
1771 { fa, SK_ARRAY_COUNT(fa), true, false },
1772 { fb, SK_ARRAY_COUNT(fb), true, false },
1773
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00001774 { c1, SK_ARRAY_COUNT(c1), false, true },
1775 { c2, SK_ARRAY_COUNT(c2), false, true },
1776 { c3, SK_ARRAY_COUNT(c3), false, true },
1777
1778 { d1, SK_ARRAY_COUNT(d1), false, false },
1779 { d2, SK_ARRAY_COUNT(d2), false, false },
1780 { d3, SK_ARRAY_COUNT(d3), false, false },
caryclark@google.comf1316942011-07-26 19:54:45 +00001781 };
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001782
1783 const size_t testCount = SK_ARRAY_COUNT(tests);
bsalomon98806072014-12-12 15:11:17 -08001784 int index;
caryclark@google.comf1316942011-07-26 19:54:45 +00001785 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1786 SkPath path;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001787 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1788 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1789 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.comf1316942011-07-26 19:54:45 +00001790 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001791 if (tests[testIndex].fClose) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001792 path.close();
1793 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001794 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001795
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001796 if (tests[testIndex].fIsRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001797 SkRect computed, expected;
caryclark@google.comf68154a2012-11-21 15:18:06 +00001798 bool isClosed;
1799 SkPath::Direction direction, cheapDirection;
robertphillips91b0a352015-01-05 10:13:46 -08001800 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001801 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection));
robertphillips91b0a352015-01-05 10:13:46 -08001802 REPORTER_ASSERT(reporter, path.isRect(&computed, &isClosed, &direction));
1803 REPORTER_ASSERT(reporter, expected == computed);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001804 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001805 REPORTER_ASSERT(reporter, direction == cheapDirection);
1806 } else {
1807 SkRect computed;
1808 computed.set(123, 456, 789, 1011);
robertphillips91b0a352015-01-05 10:13:46 -08001809 bool isClosed = (bool)-1;
1810 SkPath::Direction direction = (SkPath::Direction) - 1;
1811 REPORTER_ASSERT(reporter, !path.isRect(&computed, &isClosed, &direction));
caryclark@google.comf68154a2012-11-21 15:18:06 +00001812 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456);
1813 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011);
caryclark@google.comf68154a2012-11-21 15:18:06 +00001814 REPORTER_ASSERT(reporter, isClosed == (bool) -1);
1815 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001816 }
caryclark@google.comf1316942011-07-26 19:54:45 +00001817 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00001818
caryclark@google.comf1316942011-07-26 19:54:45 +00001819 // fail, close then line
1820 SkPath path1;
1821 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001822 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001823 path1.lineTo(r1[index].fX, r1[index].fY);
1824 }
1825 path1.close();
1826 path1.lineTo(1, 0);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001827 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001828
caryclark@google.comf1316942011-07-26 19:54:45 +00001829 // fail, move in the middle
1830 path1.reset();
1831 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001832 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001833 if (index == 2) {
1834 path1.moveTo(1, .5f);
1835 }
1836 path1.lineTo(r1[index].fX, r1[index].fY);
1837 }
1838 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001839 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00001840
1841 // fail, move on the edge
1842 path1.reset();
bsalomon98806072014-12-12 15:11:17 -08001843 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001844 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
1845 path1.lineTo(r1[index].fX, r1[index].fY);
1846 }
1847 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001848 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001849
caryclark@google.comf1316942011-07-26 19:54:45 +00001850 // fail, quad
1851 path1.reset();
1852 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001853 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001854 if (index == 2) {
1855 path1.quadTo(1, .5f, 1, .5f);
1856 }
1857 path1.lineTo(r1[index].fX, r1[index].fY);
1858 }
1859 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001860 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
rmistry@google.comd6176b02012-08-23 18:14:13 +00001861
caryclark@google.comf1316942011-07-26 19:54:45 +00001862 // fail, cubic
1863 path1.reset();
1864 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001865 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.comf1316942011-07-26 19:54:45 +00001866 if (index == 2) {
1867 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
1868 }
1869 path1.lineTo(r1[index].fX, r1[index].fY);
1870 }
1871 path1.close();
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001872 REPORTER_ASSERT(reporter, !path1.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00001873}
1874
caryclark@google.com56f233a2012-11-19 13:06:06 +00001875static void test_isNestedRects(skiatest::Reporter* reporter) {
1876 // passing tests (all moveTo / lineTo...
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001877 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001878 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1879 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1880 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001881 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001882 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1883 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1884 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1885 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001886 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; // CCW
1887 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 +00001888 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW
1889 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW
1890 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
caryclark@google.com56f233a2012-11-19 13:06:06 +00001891
1892 // failing tests
1893 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1894 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1895 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1896 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1897 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1898 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1899 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1900 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
1901
1902 // failing, no close
1903 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
1904 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
1905
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001906 struct IsNestedRectTest {
1907 SkPoint *fPoints;
bsalomon98806072014-12-12 15:11:17 -08001908 int fPointCount;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001909 SkPath::Direction fDirection;
1910 bool fClose;
1911 bool fIsNestedRect; // nests with path.addRect(-1, -1, 2, 2);
1912 } tests[] = {
1913 { r1, SK_ARRAY_COUNT(r1), SkPath::kCW_Direction , true, true },
1914 { r2, SK_ARRAY_COUNT(r2), SkPath::kCW_Direction , true, true },
1915 { r3, SK_ARRAY_COUNT(r3), SkPath::kCW_Direction , true, true },
1916 { r4, SK_ARRAY_COUNT(r4), SkPath::kCW_Direction , true, true },
1917 { r5, SK_ARRAY_COUNT(r5), SkPath::kCCW_Direction, true, true },
1918 { r6, SK_ARRAY_COUNT(r6), SkPath::kCCW_Direction, true, true },
1919 { r7, SK_ARRAY_COUNT(r7), SkPath::kCCW_Direction, true, true },
1920 { r8, SK_ARRAY_COUNT(r8), SkPath::kCCW_Direction, true, true },
1921 { r9, SK_ARRAY_COUNT(r9), SkPath::kCCW_Direction, true, true },
1922 { ra, SK_ARRAY_COUNT(ra), SkPath::kCCW_Direction, true, true },
1923 { rb, SK_ARRAY_COUNT(rb), SkPath::kCW_Direction, true, true },
1924 { rc, SK_ARRAY_COUNT(rc), SkPath::kCW_Direction, true, true },
1925 { rd, SK_ARRAY_COUNT(rd), SkPath::kCCW_Direction, true, true },
1926 { re, SK_ARRAY_COUNT(re), SkPath::kCW_Direction, true, true },
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001927
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001928 { f1, SK_ARRAY_COUNT(f1), SkPath::kUnknown_Direction, true, false },
1929 { f2, SK_ARRAY_COUNT(f2), SkPath::kUnknown_Direction, true, false },
1930 { f3, SK_ARRAY_COUNT(f3), SkPath::kUnknown_Direction, true, false },
1931 { f4, SK_ARRAY_COUNT(f4), SkPath::kUnknown_Direction, true, false },
1932 { f5, SK_ARRAY_COUNT(f5), SkPath::kUnknown_Direction, true, false },
1933 { f6, SK_ARRAY_COUNT(f6), SkPath::kUnknown_Direction, true, false },
1934 { f7, SK_ARRAY_COUNT(f7), SkPath::kUnknown_Direction, true, false },
1935 { f8, SK_ARRAY_COUNT(f8), SkPath::kUnknown_Direction, true, false },
1936
1937 { c1, SK_ARRAY_COUNT(c1), SkPath::kUnknown_Direction, false, false },
1938 { c2, SK_ARRAY_COUNT(c2), SkPath::kUnknown_Direction, false, false },
1939 };
1940
1941 const size_t testCount = SK_ARRAY_COUNT(tests);
bsalomon98806072014-12-12 15:11:17 -08001942 int index;
caryclark@google.com56f233a2012-11-19 13:06:06 +00001943 for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001944 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1945 SkPath path;
1946 if (rectFirst) {
1947 path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1948 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001949 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1950 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1951 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001952 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001953 if (tests[testIndex].fClose) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001954 path.close();
1955 }
1956 if (!rectFirst) {
1957 path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1958 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001959 REPORTER_ASSERT(reporter, tests[testIndex].fIsNestedRect == path.isNestedRects(NULL));
1960 if (tests[testIndex].fIsNestedRect) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001961 SkRect expected[2], computed[2];
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001962 SkPath::Direction expectedDirs[2], computedDirs[2];
caryclark@google.com56f233a2012-11-19 13:06:06 +00001963 SkRect testBounds;
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001964 testBounds.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001965 expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2);
1966 expected[1] = testBounds;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001967 if (rectFirst) {
1968 expectedDirs[0] = SkPath::kCW_Direction;
1969 } else {
1970 expectedDirs[0] = SkPath::kCCW_Direction;
1971 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001972 expectedDirs[1] = tests[testIndex].fDirection;
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001973 REPORTER_ASSERT(reporter, path.isNestedRects(computed, computedDirs));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001974 REPORTER_ASSERT(reporter, expected[0] == computed[0]);
1975 REPORTER_ASSERT(reporter, expected[1] == computed[1]);
robertphillips@google.com83d1a682013-05-17 12:50:27 +00001976 REPORTER_ASSERT(reporter, expectedDirs[0] == computedDirs[0]);
1977 REPORTER_ASSERT(reporter, expectedDirs[1] == computedDirs[1]);
caryclark@google.com56f233a2012-11-19 13:06:06 +00001978 }
caryclark@google.com56f233a2012-11-19 13:06:06 +00001979 }
1980
1981 // fail, close then line
1982 SkPath path1;
1983 if (rectFirst) {
1984 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
1985 }
1986 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08001987 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00001988 path1.lineTo(r1[index].fX, r1[index].fY);
1989 }
1990 path1.close();
1991 path1.lineTo(1, 0);
1992 if (!rectFirst) {
1993 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
1994 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00001995 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00001996
1997 // fail, move in the middle
1998 path1.reset();
1999 if (rectFirst) {
2000 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2001 }
2002 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08002003 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002004 if (index == 2) {
2005 path1.moveTo(1, .5f);
2006 }
2007 path1.lineTo(r1[index].fX, r1[index].fY);
2008 }
2009 path1.close();
2010 if (!rectFirst) {
2011 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2012 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002013 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002014
2015 // fail, move on the edge
2016 path1.reset();
2017 if (rectFirst) {
2018 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2019 }
bsalomon98806072014-12-12 15:11:17 -08002020 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002021 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
2022 path1.lineTo(r1[index].fX, r1[index].fY);
2023 }
2024 path1.close();
2025 if (!rectFirst) {
2026 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2027 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002028 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002029
2030 // fail, quad
2031 path1.reset();
2032 if (rectFirst) {
2033 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2034 }
2035 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08002036 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002037 if (index == 2) {
2038 path1.quadTo(1, .5f, 1, .5f);
2039 }
2040 path1.lineTo(r1[index].fX, r1[index].fY);
2041 }
2042 path1.close();
2043 if (!rectFirst) {
2044 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2045 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002046 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002047
2048 // fail, cubic
2049 path1.reset();
2050 if (rectFirst) {
2051 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2052 }
2053 path1.moveTo(r1[0].fX, r1[0].fY);
bsalomon98806072014-12-12 15:11:17 -08002054 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
caryclark@google.com56f233a2012-11-19 13:06:06 +00002055 if (index == 2) {
2056 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
2057 }
2058 path1.lineTo(r1[index].fX, r1[index].fY);
2059 }
2060 path1.close();
2061 if (!rectFirst) {
2062 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2063 }
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002064 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
skia.committer@gmail.com34587162012-11-20 02:01:23 +00002065
caryclark@google.com56f233a2012-11-19 13:06:06 +00002066 // fail, not nested
2067 path1.reset();
2068 path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction);
2069 path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002070 REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002071 }
caryclark@google.combfe90372012-11-21 13:56:20 +00002072
2073 // pass, stroke rect
2074 SkPath src, dst;
2075 src.addRect(1, 1, 7, 7, SkPath::kCW_Direction);
2076 SkPaint strokePaint;
2077 strokePaint.setStyle(SkPaint::kStroke_Style);
2078 strokePaint.setStrokeWidth(2);
2079 strokePaint.getFillPath(src, &dst);
bungeman@google.comb8d9d5b2013-09-25 18:21:39 +00002080 REPORTER_ASSERT(reporter, dst.isNestedRects(NULL));
caryclark@google.com56f233a2012-11-19 13:06:06 +00002081}
2082
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002083static void write_and_read_back(skiatest::Reporter* reporter,
2084 const SkPath& p) {
commit-bot@chromium.org19382422014-01-14 20:51:26 +00002085 SkWriter32 writer;
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002086 writer.writePath(p);
reed@google.com44699382013-10-31 17:28:30 +00002087 size_t size = writer.bytesWritten();
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002088 SkAutoMalloc storage(size);
2089 writer.flatten(storage.get());
2090 SkReader32 reader(storage.get(), size);
2091
2092 SkPath readBack;
2093 REPORTER_ASSERT(reporter, readBack != p);
2094 reader.readPath(&readBack);
2095 REPORTER_ASSERT(reporter, readBack == p);
2096
rmistry@google.comd6176b02012-08-23 18:14:13 +00002097 REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() ==
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002098 p.getConvexityOrUnknown());
2099
2100 REPORTER_ASSERT(reporter, readBack.isOval(NULL) == p.isOval(NULL));
2101
2102 const SkRect& origBounds = p.getBounds();
2103 const SkRect& readBackBounds = readBack.getBounds();
2104
2105 REPORTER_ASSERT(reporter, origBounds == readBackBounds);
2106}
2107
reed@google.com53effc52011-09-21 19:05:12 +00002108static void test_flattening(skiatest::Reporter* reporter) {
2109 SkPath p;
2110
2111 static const SkPoint pts[] = {
2112 { 0, 0 },
2113 { SkIntToScalar(10), SkIntToScalar(10) },
2114 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 },
2115 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }
2116 };
2117 p.moveTo(pts[0]);
2118 p.lineTo(pts[1]);
2119 p.quadTo(pts[2], pts[3]);
2120 p.cubicTo(pts[4], pts[5], pts[6]);
2121
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002122 write_and_read_back(reporter, p);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002123
2124 // create a buffer that should be much larger than the path so we don't
2125 // kill our stack if writer goes too far.
2126 char buffer[1024];
commit-bot@chromium.org4faa8692013-11-05 15:46:56 +00002127 size_t size1 = p.writeToMemory(NULL);
2128 size_t size2 = p.writeToMemory(buffer);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002129 REPORTER_ASSERT(reporter, size1 == size2);
2130
2131 SkPath p2;
commit-bot@chromium.org4faa8692013-11-05 15:46:56 +00002132 size_t size3 = p2.readFromMemory(buffer, 1024);
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002133 REPORTER_ASSERT(reporter, size1 == size3);
2134 REPORTER_ASSERT(reporter, p == p2);
2135
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002136 size3 = p2.readFromMemory(buffer, 0);
2137 REPORTER_ASSERT(reporter, !size3);
2138
2139 SkPath tooShort;
2140 size3 = tooShort.readFromMemory(buffer, size1 - 1);
2141 REPORTER_ASSERT(reporter, tooShort.isEmpty());
2142
djsollen@google.com94e75ee2012-06-08 18:30:46 +00002143 char buffer2[1024];
2144 size3 = p2.writeToMemory(buffer2);
2145 REPORTER_ASSERT(reporter, size1 == size3);
2146 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
robertphillips@google.com2972bb52012-08-07 17:32:51 +00002147
2148 // test persistence of the oval flag & convexity
2149 {
2150 SkPath oval;
2151 SkRect rect = SkRect::MakeWH(10, 10);
2152 oval.addOval(rect);
2153
2154 write_and_read_back(reporter, oval);
2155 }
reed@google.com53effc52011-09-21 19:05:12 +00002156}
2157
2158static void test_transform(skiatest::Reporter* reporter) {
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002159 SkPath p;
rmistry@google.comd6176b02012-08-23 18:14:13 +00002160
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002161#define CONIC_PERSPECTIVE_BUG_FIXED 0
reed@google.com53effc52011-09-21 19:05:12 +00002162 static const SkPoint pts[] = {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002163 { 0, 0 }, // move
2164 { SkIntToScalar(10), SkIntToScalar(10) }, // line
2165 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, // quad
2166 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }, // cubic
2167#if CONIC_PERSPECTIVE_BUG_FIXED
2168 { 0, 0 }, { SkIntToScalar(20), SkIntToScalar(10) }, // conic
2169#endif
reed@google.com53effc52011-09-21 19:05:12 +00002170 };
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002171 const int kPtCount = SK_ARRAY_COUNT(pts);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002172
reed@google.com53effc52011-09-21 19:05:12 +00002173 p.moveTo(pts[0]);
2174 p.lineTo(pts[1]);
2175 p.quadTo(pts[2], pts[3]);
2176 p.cubicTo(pts[4], pts[5], pts[6]);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002177#if CONIC_PERSPECTIVE_BUG_FIXED
2178 p.conicTo(pts[4], pts[5], 0.5f);
2179#endif
2180 p.close();
rmistry@google.comd6176b02012-08-23 18:14:13 +00002181
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002182 {
2183 SkMatrix matrix;
2184 matrix.reset();
2185 SkPath p1;
2186 p.transform(matrix, &p1);
2187 REPORTER_ASSERT(reporter, p == p1);
reed@google.com53effc52011-09-21 19:05:12 +00002188 }
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002189
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002190
2191 {
2192 SkMatrix matrix;
2193 matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3);
2194
2195 SkPath p1; // Leave p1 non-unique (i.e., the empty path)
2196
skia.committer@gmail.com6e515d62013-12-04 07:02:26 +00002197 p.transform(matrix, &p1);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002198 SkPoint pts1[kPtCount];
skia.committer@gmail.com6e515d62013-12-04 07:02:26 +00002199 int count = p1.getPoints(pts1, kPtCount);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002200 REPORTER_ASSERT(reporter, kPtCount == count);
2201 for (int i = 0; i < count; ++i) {
2202 SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3);
2203 REPORTER_ASSERT(reporter, newPt == pts1[i]);
2204 }
2205 }
2206
2207 {
2208 SkMatrix matrix;
2209 matrix.reset();
2210 matrix.setPerspX(SkScalarToPersp(4));
2211
2212 SkPath p1;
2213 p1.moveTo(SkPoint::Make(0, 0));
2214
2215 p.transform(matrix, &p1);
2216 REPORTER_ASSERT(reporter, matrix.invert(&matrix));
2217 p1.transform(matrix, NULL);
2218 SkRect pBounds = p.getBounds();
2219 SkRect p1Bounds = p1.getBounds();
2220 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fLeft, p1Bounds.fLeft));
2221 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fTop, p1Bounds.fTop));
2222 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fRight, p1Bounds.fRight));
2223 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fBottom, p1Bounds.fBottom));
2224 }
2225
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002226 p.reset();
2227 p.addCircle(0, 0, 1, SkPath::kCW_Direction);
robertphillips@google.comb06e88d2013-12-03 17:15:36 +00002228
2229 {
2230 SkMatrix matrix;
2231 matrix.reset();
2232 SkPath p1;
2233 p1.moveTo(SkPoint::Make(0, 0));
2234
2235 p.transform(matrix, &p1);
2236 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCW_Direction));
2237 }
2238
2239
2240 {
2241 SkMatrix matrix;
2242 matrix.reset();
2243 matrix.setScaleX(-1);
2244 SkPath p1;
2245 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
2246
2247 p.transform(matrix, &p1);
2248 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCCW_Direction));
2249 }
2250
2251 {
2252 SkMatrix matrix;
2253 matrix.setAll(1, 1, 0, 1, 1, 0, 0, 0, 1);
2254 SkPath p1;
2255 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
2256
2257 p.transform(matrix, &p1);
2258 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kUnknown_Direction));
2259 }
reed@google.com53effc52011-09-21 19:05:12 +00002260}
2261
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002262static void test_zero_length_paths(skiatest::Reporter* reporter) {
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002263 SkPath p;
schenney@chromium.org7e963602012-06-13 17:05:43 +00002264 uint8_t verbs[32];
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002265
caryclark@google.com56f233a2012-11-19 13:06:06 +00002266 struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData {
schenney@chromium.org7e963602012-06-13 17:05:43 +00002267 const char* testPath;
2268 const size_t numResultPts;
2269 const SkRect resultBound;
2270 const SkPath::Verb* resultVerbs;
2271 const size_t numResultVerbs;
2272 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002273
schenney@chromium.org7e963602012-06-13 17:05:43 +00002274 static const SkPath::Verb resultVerbs1[] = { SkPath::kMove_Verb };
2275 static const SkPath::Verb resultVerbs2[] = { SkPath::kMove_Verb, SkPath::kMove_Verb };
2276 static const SkPath::Verb resultVerbs3[] = { SkPath::kMove_Verb, SkPath::kClose_Verb };
2277 static const SkPath::Verb resultVerbs4[] = { SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb };
2278 static const SkPath::Verb resultVerbs5[] = { SkPath::kMove_Verb, SkPath::kLine_Verb };
2279 static const SkPath::Verb resultVerbs6[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb };
2280 static const SkPath::Verb resultVerbs7[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb };
2281 static const SkPath::Verb resultVerbs8[] = {
2282 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb
2283 };
2284 static const SkPath::Verb resultVerbs9[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb };
2285 static const SkPath::Verb resultVerbs10[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb };
2286 static const SkPath::Verb resultVerbs11[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb };
2287 static const SkPath::Verb resultVerbs12[] = {
2288 SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb
2289 };
2290 static const SkPath::Verb resultVerbs13[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb };
2291 static const SkPath::Verb resultVerbs14[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb };
2292 static const SkPath::Verb resultVerbs15[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb };
2293 static const SkPath::Verb resultVerbs16[] = {
2294 SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb
2295 };
2296 static const struct zeroPathTestData gZeroLengthTests[] = {
2297 { "M 1 1", 1, {0, 0, 0, 0}, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002298 { "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 +00002299 { "M 1 1 z", 1, {0, 0, 0, 0}, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002300 { "M 1 1 z M 2 1 z", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
2301 { "M 1 1 L 1 1", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) },
2302 { "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) },
2303 { "M 1 1 L 1 1 z", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs7, SK_ARRAY_COUNT(resultVerbs7) },
2304 { "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) },
2305 { "M 1 1 Q 1 1 1 1", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs9, SK_ARRAY_COUNT(resultVerbs9) },
2306 { "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) },
2307 { "M 1 1 Q 1 1 1 1 z", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs11, SK_ARRAY_COUNT(resultVerbs11) },
2308 { "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) },
2309 { "M 1 1 C 1 1 1 1 1 1", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs13, SK_ARRAY_COUNT(resultVerbs13) },
2310 { "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 +00002311 SK_ARRAY_COUNT(resultVerbs14)
2312 },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002313 { "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) },
2314 { "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 +00002315 SK_ARRAY_COUNT(resultVerbs16)
2316 }
2317 };
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002318
schenney@chromium.org7e963602012-06-13 17:05:43 +00002319 for (size_t i = 0; i < SK_ARRAY_COUNT(gZeroLengthTests); ++i) {
2320 p.reset();
2321 bool valid = SkParsePath::FromSVGString(gZeroLengthTests[i].testPath, &p);
2322 REPORTER_ASSERT(reporter, valid);
2323 REPORTER_ASSERT(reporter, !p.isEmpty());
2324 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultPts == (size_t)p.countPoints());
2325 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultBound == p.getBounds());
2326 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultVerbs == (size_t)p.getVerbs(verbs, SK_ARRAY_COUNT(verbs)));
2327 for (size_t j = 0; j < gZeroLengthTests[i].numResultVerbs; ++j) {
2328 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultVerbs[j] == verbs[j]);
2329 }
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00002330 }
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00002331}
2332
2333struct SegmentInfo {
2334 SkPath fPath;
2335 int fPointCount;
2336};
2337
reed@google.com10296cc2011-09-21 12:29:05 +00002338#define kCurveSegmentMask (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask)
2339
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002340static void test_segment_masks(skiatest::Reporter* reporter) {
reed@google.comeef938c2012-08-01 20:01:49 +00002341 SkPath p, p2;
2342
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002343 p.moveTo(0, 0);
2344 p.quadTo(100, 100, 200, 200);
2345 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == p.getSegmentMasks());
2346 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00002347 p2 = p;
2348 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002349 p.cubicTo(100, 100, 200, 200, 300, 300);
2350 REPORTER_ASSERT(reporter, kCurveSegmentMask == p.getSegmentMasks());
2351 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.comeef938c2012-08-01 20:01:49 +00002352 p2 = p;
2353 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
2354
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002355 p.reset();
2356 p.moveTo(0, 0);
2357 p.cubicTo(100, 100, 200, 200, 300, 300);
2358 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == p.getSegmentMasks());
reed@google.comeef938c2012-08-01 20:01:49 +00002359 p2 = p;
2360 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
rmistry@google.comd6176b02012-08-23 18:14:13 +00002361
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002362 REPORTER_ASSERT(reporter, !p.isEmpty());
2363}
2364
2365static void test_iter(skiatest::Reporter* reporter) {
schenney@chromium.org7e963602012-06-13 17:05:43 +00002366 SkPath p;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002367 SkPoint pts[4];
2368
2369 // Test an iterator with no path
2370 SkPath::Iter noPathIter;
2371 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002372
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002373 // Test that setting an empty path works
2374 noPathIter.setPath(p, false);
2375 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002376
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002377 // Test that close path makes no difference for an empty path
2378 noPathIter.setPath(p, true);
2379 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
schenney@chromium.org7e963602012-06-13 17:05:43 +00002380
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002381 // Test an iterator with an initial empty path
2382 SkPath::Iter iter(p, false);
2383 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2384
2385 // Test that close path makes no difference
schenney@chromium.org7e963602012-06-13 17:05:43 +00002386 iter.setPath(p, true);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002387 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2388
rmistry@google.comd6176b02012-08-23 18:14:13 +00002389
schenney@chromium.org7e963602012-06-13 17:05:43 +00002390 struct iterTestData {
2391 const char* testPath;
2392 const bool forceClose;
2393 const bool consumeDegenerates;
2394 const size_t* numResultPtsPerVerb;
2395 const SkPoint* resultPts;
2396 const SkPath::Verb* resultVerbs;
2397 const size_t numResultVerbs;
2398 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002399
schenney@chromium.org7e963602012-06-13 17:05:43 +00002400 static const SkPath::Verb resultVerbs1[] = { SkPath::kDone_Verb };
2401 static const SkPath::Verb resultVerbs2[] = {
2402 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kDone_Verb
2403 };
2404 static const SkPath::Verb resultVerbs3[] = {
2405 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2406 };
2407 static const SkPath::Verb resultVerbs4[] = {
2408 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2409 };
2410 static const SkPath::Verb resultVerbs5[] = {
2411 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2412 };
2413 static const size_t resultPtsSizes1[] = { 0 };
schenney@chromium.orgfedd09b2012-06-13 18:29:20 +00002414 static const size_t resultPtsSizes2[] = { 1, 2, 2, 0 };
2415 static const size_t resultPtsSizes3[] = { 1, 2, 2, 2, 1, 0 };
2416 static const size_t resultPtsSizes4[] = { 1, 2, 1, 1, 0 };
2417 static const size_t resultPtsSizes5[] = { 1, 2, 1, 1, 1, 0 };
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002418 static const SkPoint* resultPts1 = 0;
schenney@chromium.org7e963602012-06-13 17:05:43 +00002419 static const SkPoint resultPts2[] = {
2420 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 }
2421 };
2422 static const SkPoint resultPts3[] = {
2423 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 },
2424 { 0, SK_Scalar1 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }
2425 };
2426 static const SkPoint resultPts4[] = {
2427 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
2428 };
2429 static const SkPoint resultPts5[] = {
2430 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
2431 };
2432 static const struct iterTestData gIterTests[] = {
2433 { "M 1 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
schenney@chromium.orgaaf16882012-06-13 17:41:00 +00002434 { "M 1 0 M 2 0 M 3 0 M 4 0 M 5 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2435 { "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 +00002436 { "z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2437 { "z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2438 { "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) },
2439 { "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 +00002440 { "M 1 0 L 1 1 L 0 1 M 0 0 z", false, true, resultPtsSizes2, resultPts2, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
2441 { "M 1 0 L 1 1 L 0 1 M 0 0 z", true, true, resultPtsSizes3, resultPts3, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
2442 { "M 1 0 L 1 0 M 0 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2443 { "M 1 0 L 1 0 M 0 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2444 { "M 1 0 L 1 0 M 0 0 z", false, false, resultPtsSizes4, resultPts4, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
2445 { "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 +00002446 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002447
schenney@chromium.org7e963602012-06-13 17:05:43 +00002448 for (size_t i = 0; i < SK_ARRAY_COUNT(gIterTests); ++i) {
2449 p.reset();
2450 bool valid = SkParsePath::FromSVGString(gIterTests[i].testPath, &p);
2451 REPORTER_ASSERT(reporter, valid);
2452 iter.setPath(p, gIterTests[i].forceClose);
2453 int j = 0, l = 0;
2454 do {
2455 REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegenerates) == gIterTests[i].resultVerbs[j]);
2456 for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k) {
2457 REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]);
2458 }
2459 } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb);
2460 REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs);
2461 }
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002462
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002463 p.reset();
2464 iter.setPath(p, false);
2465 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2466 p.lineTo(1, 1);
2467 p.close();
2468 iter.setPath(p, false);
2469 REPORTER_ASSERT(reporter, iter.isClosedContour());
2470 p.reset();
2471 iter.setPath(p, true);
2472 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2473 p.lineTo(1, 1);
2474 iter.setPath(p, true);
2475 REPORTER_ASSERT(reporter, iter.isClosedContour());
2476 p.moveTo(0, 0);
2477 p.lineTo(2, 2);
2478 iter.setPath(p, false);
2479 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2480
2481 // this checks to see if the NaN logic is executed in SkPath::autoClose(), but does not
2482 // check to see if the result is correct.
2483 for (int setNaN = 0; setNaN < 4; ++setNaN) {
2484 p.reset();
2485 p.moveTo(setNaN == 0 ? SK_ScalarNaN : 0, setNaN == 1 ? SK_ScalarNaN : 0);
2486 p.lineTo(setNaN == 2 ? SK_ScalarNaN : 1, setNaN == 3 ? SK_ScalarNaN : 1);
2487 iter.setPath(p, true);
2488 iter.next(pts, false);
2489 iter.next(pts, false);
2490 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == iter.next(pts, false));
2491 }
2492
2493 p.reset();
2494 p.quadTo(0, 0, 0, 0);
2495 iter.setPath(p, false);
2496 iter.next(pts, false);
2497 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == iter.next(pts, false));
2498 iter.setPath(p, false);
2499 iter.next(pts, false);
2500 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2501
2502 p.reset();
2503 p.conicTo(0, 0, 0, 0, 0.5f);
2504 iter.setPath(p, false);
2505 iter.next(pts, false);
2506 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts, false));
2507 iter.setPath(p, false);
2508 iter.next(pts, false);
2509 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2510
2511 p.reset();
2512 p.cubicTo(0, 0, 0, 0, 0, 0);
2513 iter.setPath(p, false);
2514 iter.next(pts, false);
2515 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
2516 iter.setPath(p, false);
2517 iter.next(pts, false);
2518 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2519
2520 p.moveTo(1, 1); // add a trailing moveto
2521 iter.setPath(p, false);
2522 iter.next(pts, false);
2523 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
2524 iter.setPath(p, false);
2525 iter.next(pts, false);
2526 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2527
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002528 // The GM degeneratesegments.cpp test is more extensive
2529}
2530
2531static void test_raw_iter(skiatest::Reporter* reporter) {
2532 SkPath p;
2533 SkPoint pts[4];
2534
2535 // Test an iterator with no path
2536 SkPath::RawIter noPathIter;
2537 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
2538 // Test that setting an empty path works
2539 noPathIter.setPath(p);
2540 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
rmistry@google.comd6176b02012-08-23 18:14:13 +00002541
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002542 // Test an iterator with an initial empty path
2543 SkPath::RawIter iter(p);
2544 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2545
2546 // Test that a move-only path returns the move.
2547 p.moveTo(SK_Scalar1, 0);
2548 iter.setPath(p);
2549 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2550 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2551 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2552 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2553
2554 // No matter how many moves we add, we should get them all back
2555 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2556 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2557 iter.setPath(p);
2558 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2559 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2560 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2561 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2562 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2563 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2564 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2565 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2566 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2567 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2568
2569 // Initial close is never ever stored
2570 p.reset();
2571 p.close();
2572 iter.setPath(p);
2573 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2574
2575 // Move/close sequences
2576 p.reset();
2577 p.close(); // Not stored, no purpose
2578 p.moveTo(SK_Scalar1, 0);
2579 p.close();
2580 p.close(); // Not stored, no purpose
2581 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2582 p.close();
2583 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2584 p.moveTo(SK_Scalar1*4, SK_Scalar1*3);
2585 p.close();
2586 iter.setPath(p);
2587 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2588 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2589 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2590 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2591 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2592 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2593 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2594 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2595 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2596 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2597 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2598 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2599 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2600 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2601 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2602 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2603 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2604 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2605 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2606 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2607 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2608 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2609
2610 // Generate random paths and verify
2611 SkPoint randomPts[25];
2612 for (int i = 0; i < 5; ++i) {
2613 for (int j = 0; j < 5; ++j) {
2614 randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j);
2615 }
2616 }
2617
2618 // Max of 10 segments, max 3 points per segment
commit-bot@chromium.orge0e7cfe2013-09-09 20:09:12 +00002619 SkRandom rand(9876543);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002620 SkPoint expectedPts[31]; // May have leading moveTo
reed@google.comd335d1d2012-01-12 18:17:11 +00002621 SkPath::Verb expectedVerbs[22]; // May have leading moveTo
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002622 SkPath::Verb nextVerb;
reed@google.comd335d1d2012-01-12 18:17:11 +00002623
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002624 for (int i = 0; i < 500; ++i) {
2625 p.reset();
2626 bool lastWasClose = true;
2627 bool haveMoveTo = false;
reed@google.comd335d1d2012-01-12 18:17:11 +00002628 SkPoint lastMoveToPt = { 0, 0 };
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002629 int numPoints = 0;
2630 int numVerbs = (rand.nextU() >> 16) % 10;
2631 int numIterVerbs = 0;
2632 for (int j = 0; j < numVerbs; ++j) {
2633 do {
2634 nextVerb = static_cast<SkPath::Verb>((rand.nextU() >> 16) % SkPath::kDone_Verb);
2635 } while (lastWasClose && nextVerb == SkPath::kClose_Verb);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002636 switch (nextVerb) {
2637 case SkPath::kMove_Verb:
2638 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2639 p.moveTo(expectedPts[numPoints]);
reed@google.comd335d1d2012-01-12 18:17:11 +00002640 lastMoveToPt = expectedPts[numPoints];
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002641 numPoints += 1;
2642 lastWasClose = false;
2643 haveMoveTo = true;
2644 break;
2645 case SkPath::kLine_Verb:
2646 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002647 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002648 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2649 haveMoveTo = true;
2650 }
2651 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2652 p.lineTo(expectedPts[numPoints]);
2653 numPoints += 1;
2654 lastWasClose = false;
2655 break;
2656 case SkPath::kQuad_Verb:
2657 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002658 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002659 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2660 haveMoveTo = true;
2661 }
2662 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2663 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2664 p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]);
2665 numPoints += 2;
2666 lastWasClose = false;
2667 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002668 case SkPath::kConic_Verb:
2669 if (!haveMoveTo) {
2670 expectedPts[numPoints++] = lastMoveToPt;
2671 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2672 haveMoveTo = true;
2673 }
2674 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2675 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2676 p.conicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2677 rand.nextUScalar1() * 4);
2678 numPoints += 2;
2679 lastWasClose = false;
2680 break;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002681 case SkPath::kCubic_Verb:
2682 if (!haveMoveTo) {
reed@google.comd335d1d2012-01-12 18:17:11 +00002683 expectedPts[numPoints++] = lastMoveToPt;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002684 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2685 haveMoveTo = true;
2686 }
2687 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2688 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
2689 expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25];
2690 p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
2691 expectedPts[numPoints + 2]);
2692 numPoints += 3;
2693 lastWasClose = false;
2694 break;
2695 case SkPath::kClose_Verb:
2696 p.close();
reed@google.comd335d1d2012-01-12 18:17:11 +00002697 haveMoveTo = false;
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002698 lastWasClose = true;
2699 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002700 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002701 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002702 }
2703 expectedVerbs[numIterVerbs++] = nextVerb;
2704 }
rmistry@google.comd6176b02012-08-23 18:14:13 +00002705
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002706 iter.setPath(p);
2707 numVerbs = numIterVerbs;
2708 numIterVerbs = 0;
2709 int numIterPts = 0;
2710 SkPoint lastMoveTo;
2711 SkPoint lastPt;
2712 lastMoveTo.set(0, 0);
2713 lastPt.set(0, 0);
2714 while ((nextVerb = iter.next(pts)) != SkPath::kDone_Verb) {
2715 REPORTER_ASSERT(reporter, nextVerb == expectedVerbs[numIterVerbs]);
2716 numIterVerbs++;
2717 switch (nextVerb) {
2718 case SkPath::kMove_Verb:
2719 REPORTER_ASSERT(reporter, numIterPts < numPoints);
2720 REPORTER_ASSERT(reporter, pts[0] == expectedPts[numIterPts]);
2721 lastPt = lastMoveTo = pts[0];
2722 numIterPts += 1;
2723 break;
2724 case SkPath::kLine_Verb:
2725 REPORTER_ASSERT(reporter, numIterPts < numPoints + 1);
2726 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2727 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2728 lastPt = pts[1];
2729 numIterPts += 1;
2730 break;
2731 case SkPath::kQuad_Verb:
reed@google.com277c3f82013-05-31 15:17:50 +00002732 case SkPath::kConic_Verb:
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002733 REPORTER_ASSERT(reporter, numIterPts < numPoints + 2);
2734 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2735 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2736 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2737 lastPt = pts[2];
2738 numIterPts += 2;
2739 break;
2740 case SkPath::kCubic_Verb:
2741 REPORTER_ASSERT(reporter, numIterPts < numPoints + 3);
2742 REPORTER_ASSERT(reporter, pts[0] == lastPt);
2743 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
2744 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
2745 REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]);
2746 lastPt = pts[3];
2747 numIterPts += 3;
2748 break;
2749 case SkPath::kClose_Verb:
2750 REPORTER_ASSERT(reporter, pts[0] == lastMoveTo);
2751 lastPt = lastMoveTo;
2752 break;
reed@google.com277c3f82013-05-31 15:17:50 +00002753 default:
mtklein@google.com330313a2013-08-22 15:37:26 +00002754 SkDEBUGFAIL("unexpected verb");
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00002755 }
2756 }
2757 REPORTER_ASSERT(reporter, numIterPts == numPoints);
2758 REPORTER_ASSERT(reporter, numIterVerbs == numVerbs);
2759 }
2760}
2761
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002762static void check_for_circle(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002763 const SkPath& path,
2764 bool expectedCircle,
2765 SkPath::Direction expectedDir) {
robertphillips@google.com466310d2013-12-03 16:43:54 +00002766 SkRect rect = SkRect::MakeEmpty();
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002767 REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle);
2768 REPORTER_ASSERT(reporter, path.cheapIsDirection(expectedDir));
skia.committer@gmail.comfbb0ed92012-11-13 21:46:06 +00002769
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002770 if (expectedCircle) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002771 REPORTER_ASSERT(reporter, rect.height() == rect.width());
2772 }
2773}
2774
2775static void test_circle_skew(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002776 const SkPath& path,
2777 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002778 SkPath tmp;
2779
2780 SkMatrix m;
2781 m.setSkew(SkIntToScalar(3), SkIntToScalar(5));
2782 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002783 // this matrix reverses the direction.
2784 if (SkPath::kCCW_Direction == dir) {
2785 dir = SkPath::kCW_Direction;
2786 } else {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002787 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002788 dir = SkPath::kCCW_Direction;
2789 }
2790 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002791}
2792
2793static void test_circle_translate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002794 const SkPath& path,
2795 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002796 SkPath tmp;
2797
2798 // translate at small offset
2799 SkMatrix m;
2800 m.setTranslate(SkIntToScalar(15), SkIntToScalar(15));
2801 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002802 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002803
2804 tmp.reset();
2805 m.reset();
2806
2807 // translate at a relatively big offset
2808 m.setTranslate(SkIntToScalar(1000), SkIntToScalar(1000));
2809 path.transform(m, &tmp);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002810 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002811}
2812
2813static void test_circle_rotate(skiatest::Reporter* reporter,
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002814 const SkPath& path,
2815 SkPath::Direction dir) {
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002816 for (int angle = 0; angle < 360; ++angle) {
2817 SkPath tmp;
2818 SkMatrix m;
2819 m.setRotate(SkIntToScalar(angle));
2820 path.transform(m, &tmp);
2821
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002822 // TODO: a rotated circle whose rotated angle is not a multiple of 90
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002823 // degrees is not an oval anymore, this can be improved. we made this
2824 // for the simplicity of our implementation.
2825 if (angle % 90 == 0) {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002826 check_for_circle(reporter, tmp, true, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002827 } else {
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002828 check_for_circle(reporter, tmp, false, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002829 }
2830 }
2831}
2832
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002833static void test_circle_mirror_x(skiatest::Reporter* reporter,
2834 const SkPath& path,
2835 SkPath::Direction dir) {
2836 SkPath tmp;
2837 SkMatrix m;
2838 m.reset();
2839 m.setScaleX(-SK_Scalar1);
2840 path.transform(m, &tmp);
2841
2842 if (SkPath::kCW_Direction == dir) {
2843 dir = SkPath::kCCW_Direction;
2844 } else {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002845 REPORTER_ASSERT(reporter, SkPath::kCCW_Direction == dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002846 dir = SkPath::kCW_Direction;
2847 }
2848
2849 check_for_circle(reporter, tmp, true, dir);
2850}
2851
2852static void test_circle_mirror_y(skiatest::Reporter* reporter,
2853 const SkPath& path,
2854 SkPath::Direction dir) {
2855 SkPath tmp;
2856 SkMatrix m;
2857 m.reset();
2858 m.setScaleY(-SK_Scalar1);
2859 path.transform(m, &tmp);
2860
2861 if (SkPath::kCW_Direction == dir) {
2862 dir = SkPath::kCCW_Direction;
2863 } else {
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002864 REPORTER_ASSERT(reporter, SkPath::kCCW_Direction == dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002865 dir = SkPath::kCW_Direction;
2866 }
2867
2868 check_for_circle(reporter, tmp, true, dir);
2869}
2870
2871static void test_circle_mirror_xy(skiatest::Reporter* reporter,
2872 const SkPath& path,
2873 SkPath::Direction dir) {
2874 SkPath tmp;
2875 SkMatrix m;
2876 m.reset();
2877 m.setScaleX(-SK_Scalar1);
2878 m.setScaleY(-SK_Scalar1);
2879 path.transform(m, &tmp);
2880
2881 check_for_circle(reporter, tmp, true, dir);
2882}
2883
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002884static void test_circle_with_direction(skiatest::Reporter* reporter,
2885 SkPath::Direction dir) {
2886 SkPath path;
2887
2888 // circle at origin
2889 path.addCircle(0, 0, SkIntToScalar(20), dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002890 check_for_circle(reporter, path, true, dir);
2891 test_circle_rotate(reporter, path, dir);
2892 test_circle_translate(reporter, path, dir);
2893 test_circle_skew(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002894
2895 // circle at an offset at (10, 10)
2896 path.reset();
2897 path.addCircle(SkIntToScalar(10), SkIntToScalar(10),
2898 SkIntToScalar(20), dir);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002899 check_for_circle(reporter, path, true, dir);
2900 test_circle_rotate(reporter, path, dir);
2901 test_circle_translate(reporter, path, dir);
2902 test_circle_skew(reporter, path, dir);
2903 test_circle_mirror_x(reporter, path, dir);
2904 test_circle_mirror_y(reporter, path, dir);
2905 test_circle_mirror_xy(reporter, path, dir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002906}
2907
2908static void test_circle_with_add_paths(skiatest::Reporter* reporter) {
2909 SkPath path;
2910 SkPath circle;
2911 SkPath rect;
2912 SkPath empty;
2913
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002914 static const SkPath::Direction kCircleDir = SkPath::kCW_Direction;
2915 static const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction;
2916
2917 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002918 rect.addRect(SkIntToScalar(5), SkIntToScalar(5),
2919 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction);
2920
2921 SkMatrix translate;
2922 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12));
2923
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00002924 // Although all the path concatenation related operations leave
2925 // the path a circle, most mark it as a non-circle for simplicity
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002926
2927 // empty + circle (translate)
2928 path = empty;
2929 path.addPath(circle, translate);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002930 check_for_circle(reporter, path, false, kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002931
2932 // circle + empty (translate)
2933 path = circle;
2934 path.addPath(empty, translate);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00002935 check_for_circle(reporter, path, true, kCircleDir);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002936
2937 // test reverseAddPath
2938 path = circle;
2939 path.reverseAddPath(rect);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002940 check_for_circle(reporter, path, false, kCircleDirOpposite);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002941}
2942
2943static void test_circle(skiatest::Reporter* reporter) {
2944 test_circle_with_direction(reporter, SkPath::kCW_Direction);
2945 test_circle_with_direction(reporter, SkPath::kCCW_Direction);
2946
2947 // multiple addCircle()
2948 SkPath path;
2949 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2950 path.addCircle(0, 0, SkIntToScalar(20), SkPath::kCW_Direction);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002951 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002952
2953 // some extra lineTo() would make isOval() fail
2954 path.reset();
2955 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2956 path.lineTo(0, 0);
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002957 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002958
2959 // not back to the original point
2960 path.reset();
2961 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
2962 path.setLastPt(SkIntToScalar(5), SkIntToScalar(5));
bsalomon@google.com30c174b2012-11-13 14:36:42 +00002963 check_for_circle(reporter, path, false, SkPath::kCW_Direction);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002964
2965 test_circle_with_add_paths(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00002966
2967 // test negative radius
2968 path.reset();
2969 path.addCircle(0, 0, -1, SkPath::kCW_Direction);
2970 REPORTER_ASSERT(reporter, path.isEmpty());
bsalomon@google.com6aa29652012-04-18 13:29:52 +00002971}
2972
2973static void test_oval(skiatest::Reporter* reporter) {
2974 SkRect rect;
2975 SkMatrix m;
2976 SkPath path;
2977
2978 rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50));
2979 path.addOval(rect);
2980
2981 REPORTER_ASSERT(reporter, path.isOval(NULL));
2982
2983 m.setRotate(SkIntToScalar(90));
2984 SkPath tmp;
2985 path.transform(m, &tmp);
2986 // an oval rotated 90 degrees is still an oval.
2987 REPORTER_ASSERT(reporter, tmp.isOval(NULL));
2988
2989 m.reset();
2990 m.setRotate(SkIntToScalar(30));
2991 tmp.reset();
2992 path.transform(m, &tmp);
2993 // an oval rotated 30 degrees is not an oval anymore.
2994 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
2995
2996 // since empty path being transformed.
2997 path.reset();
2998 tmp.reset();
2999 m.reset();
3000 path.transform(m, &tmp);
3001 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
3002
3003 // empty path is not an oval
3004 tmp.reset();
3005 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
3006
3007 // only has moveTo()s
3008 tmp.reset();
3009 tmp.moveTo(0, 0);
3010 tmp.moveTo(SkIntToScalar(10), SkIntToScalar(10));
3011 REPORTER_ASSERT(reporter, !tmp.isOval(NULL));
3012
3013 // mimic WebKit's calling convention,
3014 // call moveTo() first and then call addOval()
3015 path.reset();
3016 path.moveTo(0, 0);
3017 path.addOval(rect);
3018 REPORTER_ASSERT(reporter, path.isOval(NULL));
3019
3020 // copy path
3021 path.reset();
3022 tmp.reset();
3023 tmp.addOval(rect);
3024 path = tmp;
3025 REPORTER_ASSERT(reporter, path.isOval(NULL));
3026}
3027
bungeman@google.coma5809a32013-06-21 15:13:34 +00003028static void test_empty(skiatest::Reporter* reporter, const SkPath& p) {
3029 SkPath empty;
reed@android.com80e39a72009-04-02 16:59:40 +00003030
reed@android.com3abec1d2009-03-02 05:36:20 +00003031 REPORTER_ASSERT(reporter, p.isEmpty());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003032 REPORTER_ASSERT(reporter, 0 == p.countPoints());
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00003033 REPORTER_ASSERT(reporter, 0 == p.countVerbs());
reed@google.com10296cc2011-09-21 12:29:05 +00003034 REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks());
reed@google.comb54455e2011-05-16 14:16:04 +00003035 REPORTER_ASSERT(reporter, p.isConvex());
reed@android.com3abec1d2009-03-02 05:36:20 +00003036 REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType);
3037 REPORTER_ASSERT(reporter, !p.isInverseFillType());
bungeman@google.coma5809a32013-06-21 15:13:34 +00003038 REPORTER_ASSERT(reporter, p == empty);
3039 REPORTER_ASSERT(reporter, !(p != empty));
3040}
3041
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003042static void test_rrect_is_convex(skiatest::Reporter* reporter, SkPath* path,
3043 SkPath::Direction dir) {
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003044 REPORTER_ASSERT(reporter, path->isConvex());
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003045 REPORTER_ASSERT(reporter, path->cheapIsDirection(dir));
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003046 path->setConvexity(SkPath::kUnknown_Convexity);
3047 REPORTER_ASSERT(reporter, path->isConvex());
3048 path->reset();
3049}
3050
caryclarkd3d1a982014-12-08 04:57:38 -08003051static void test_rrect_convexity_is_unknown(skiatest::Reporter* reporter, SkPath* path,
3052 SkPath::Direction dir) {
3053 REPORTER_ASSERT(reporter, path->isConvex());
3054 REPORTER_ASSERT(reporter, path->cheapIsDirection(dir));
3055 path->setConvexity(SkPath::kUnknown_Convexity);
3056 REPORTER_ASSERT(reporter, path->getConvexity() == SkPath::kUnknown_Convexity);
3057 path->reset();
3058}
3059
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003060static void test_rrect(skiatest::Reporter* reporter) {
3061 SkPath p;
3062 SkRRect rr;
3063 SkVector radii[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
3064 SkRect r = {10, 20, 30, 40};
3065 rr.setRectRadii(r, radii);
3066 p.addRRect(rr);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003067 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003068 p.addRRect(rr, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003069 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003070 p.addRoundRect(r, &radii[0].fX);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003071 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003072 p.addRoundRect(r, &radii[0].fX, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003073 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003074 p.addRoundRect(r, radii[1].fX, radii[1].fY);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003075 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003076 p.addRoundRect(r, radii[1].fX, radii[1].fY, SkPath::kCCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003077 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
3078 for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) {
3079 SkVector save = radii[i];
3080 radii[i].set(0, 0);
3081 rr.setRectRadii(r, radii);
3082 p.addRRect(rr);
3083 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3084 radii[i] = save;
3085 }
3086 p.addRoundRect(r, 0, 0);
3087 SkRect returnedRect;
3088 REPORTER_ASSERT(reporter, p.isRect(&returnedRect));
3089 REPORTER_ASSERT(reporter, returnedRect == r);
3090 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3091 SkVector zeroRadii[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
3092 rr.setRectRadii(r, zeroRadii);
3093 p.addRRect(rr);
3094 bool closed;
3095 SkPath::Direction dir;
robertphillips91b0a352015-01-05 10:13:46 -08003096 REPORTER_ASSERT(reporter, p.isRect(NULL, &closed, &dir));
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003097 REPORTER_ASSERT(reporter, closed);
3098 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
3099 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3100 p.addRRect(rr, SkPath::kCW_Direction);
3101 p.addRRect(rr, SkPath::kCW_Direction);
3102 REPORTER_ASSERT(reporter, !p.isConvex());
3103 p.reset();
3104 p.addRRect(rr, SkPath::kCCW_Direction);
3105 p.addRRect(rr, SkPath::kCCW_Direction);
3106 REPORTER_ASSERT(reporter, !p.isConvex());
3107 p.reset();
3108 SkRect emptyR = {10, 20, 10, 30};
3109 rr.setRectRadii(emptyR, radii);
3110 p.addRRect(rr);
3111 REPORTER_ASSERT(reporter, p.isEmpty());
3112 SkRect largeR = {0, 0, SK_ScalarMax, SK_ScalarMax};
3113 rr.setRectRadii(largeR, radii);
3114 p.addRRect(rr);
caryclarkd3d1a982014-12-08 04:57:38 -08003115 test_rrect_convexity_is_unknown(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003116 SkRect infR = {0, 0, SK_ScalarMax, SK_ScalarInfinity};
3117 rr.setRectRadii(infR, radii);
3118 p.addRRect(rr);
caryclarkd3d1a982014-12-08 04:57:38 -08003119 test_rrect_convexity_is_unknown(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003120 SkRect tinyR = {0, 0, 1e-9f, 1e-9f};
3121 p.addRoundRect(tinyR, 5e-11f, 5e-11f);
3122 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003123}
3124
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003125static void test_arc(skiatest::Reporter* reporter) {
3126 SkPath p;
3127 SkRect emptyOval = {10, 20, 30, 20};
3128 REPORTER_ASSERT(reporter, emptyOval.isEmpty());
3129 p.addArc(emptyOval, 1, 2);
3130 REPORTER_ASSERT(reporter, p.isEmpty());
3131 p.reset();
3132 SkRect oval = {10, 20, 30, 40};
3133 p.addArc(oval, 1, 0);
3134 REPORTER_ASSERT(reporter, p.isEmpty());
3135 p.reset();
3136 SkPath cwOval;
3137 cwOval.addOval(oval);
3138 p.addArc(oval, 1, 360);
3139 REPORTER_ASSERT(reporter, p == cwOval);
3140 p.reset();
3141 SkPath ccwOval;
3142 ccwOval.addOval(oval, SkPath::kCCW_Direction);
3143 p.addArc(oval, 1, -360);
3144 REPORTER_ASSERT(reporter, p == ccwOval);
3145 p.reset();
3146 p.addArc(oval, 1, 180);
3147 REPORTER_ASSERT(reporter, p.isConvex());
3148 REPORTER_ASSERT(reporter, p.cheapIsDirection(SkPath::kCW_Direction));
3149 p.setConvexity(SkPath::kUnknown_Convexity);
3150 REPORTER_ASSERT(reporter, p.isConvex());
3151}
3152
3153static void check_move(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3154 SkScalar x0, SkScalar y0) {
3155 SkPoint pts[4];
3156 SkPath::Verb v = iter->next(pts);
3157 REPORTER_ASSERT(reporter, v == SkPath::kMove_Verb);
3158 REPORTER_ASSERT(reporter, pts[0].fX == x0);
3159 REPORTER_ASSERT(reporter, pts[0].fY == y0);
3160}
3161
3162static void check_line(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3163 SkScalar x1, SkScalar y1) {
3164 SkPoint pts[4];
3165 SkPath::Verb v = iter->next(pts);
3166 REPORTER_ASSERT(reporter, v == SkPath::kLine_Verb);
3167 REPORTER_ASSERT(reporter, pts[1].fX == x1);
3168 REPORTER_ASSERT(reporter, pts[1].fY == y1);
3169}
3170
3171static void check_quad(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3172 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3173 SkPoint pts[4];
3174 SkPath::Verb v = iter->next(pts);
3175 REPORTER_ASSERT(reporter, v == SkPath::kQuad_Verb);
3176 REPORTER_ASSERT(reporter, pts[1].fX == x1);
3177 REPORTER_ASSERT(reporter, pts[1].fY == y1);
3178 REPORTER_ASSERT(reporter, pts[2].fX == x2);
3179 REPORTER_ASSERT(reporter, pts[2].fY == y2);
3180}
3181
3182static void check_done(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
3183 SkPoint pts[4];
3184 SkPath::Verb v = iter->next(pts);
3185 REPORTER_ASSERT(reporter, v == SkPath::kDone_Verb);
3186}
3187
3188static void check_done_and_reset(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
3189 check_done(reporter, p, iter);
3190 p->reset();
3191}
3192
3193static void check_path_is_move_and_reset(skiatest::Reporter* reporter, SkPath* p,
3194 SkScalar x0, SkScalar y0) {
3195 SkPath::RawIter iter(*p);
3196 check_move(reporter, &iter, x0, y0);
3197 check_done_and_reset(reporter, p, &iter);
3198}
3199
3200static void check_path_is_line_and_reset(skiatest::Reporter* reporter, SkPath* p,
3201 SkScalar x1, SkScalar y1) {
3202 SkPath::RawIter iter(*p);
3203 check_move(reporter, &iter, 0, 0);
3204 check_line(reporter, &iter, x1, y1);
3205 check_done_and_reset(reporter, p, &iter);
3206}
3207
3208static void check_path_is_line(skiatest::Reporter* reporter, SkPath* p,
3209 SkScalar x1, SkScalar y1) {
3210 SkPath::RawIter iter(*p);
3211 check_move(reporter, &iter, 0, 0);
3212 check_line(reporter, &iter, x1, y1);
3213 check_done(reporter, p, &iter);
3214}
3215
3216static void check_path_is_line_pair_and_reset(skiatest::Reporter* reporter, SkPath* p,
3217 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3218 SkPath::RawIter iter(*p);
3219 check_move(reporter, &iter, 0, 0);
3220 check_line(reporter, &iter, x1, y1);
3221 check_line(reporter, &iter, x2, y2);
3222 check_done_and_reset(reporter, p, &iter);
3223}
3224
3225static void check_path_is_quad_and_reset(skiatest::Reporter* reporter, SkPath* p,
3226 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3227 SkPath::RawIter iter(*p);
3228 check_move(reporter, &iter, 0, 0);
3229 check_quad(reporter, &iter, x1, y1, x2, y2);
3230 check_done_and_reset(reporter, p, &iter);
3231}
3232
3233static void test_arcTo(skiatest::Reporter* reporter) {
3234 SkPath p;
3235 p.arcTo(0, 0, 1, 2, 1);
3236 check_path_is_line_and_reset(reporter, &p, 0, 0);
3237 p.arcTo(1, 2, 1, 2, 1);
3238 check_path_is_line_and_reset(reporter, &p, 1, 2);
3239 p.arcTo(1, 2, 3, 4, 0);
3240 check_path_is_line_and_reset(reporter, &p, 1, 2);
3241 p.arcTo(1, 2, 0, 0, 1);
3242 check_path_is_line_and_reset(reporter, &p, 1, 2);
3243 p.arcTo(1, 0, 1, 1, 1);
3244 SkPoint pt;
3245 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == 1);
3246 p.reset();
3247 p.arcTo(1, 0, 1, -1, 1);
3248 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == -1);
3249 p.reset();
3250 SkRect oval = {1, 2, 3, 4};
3251 p.arcTo(oval, 0, 0, true);
3252 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3253 p.arcTo(oval, 0, 0, false);
3254 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3255 p.arcTo(oval, 360, 0, true);
3256 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3257 p.arcTo(oval, 360, 0, false);
3258 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3259 for (float sweep = 359, delta = 0.5f; sweep != (float) (sweep + delta); ) {
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00003260 p.arcTo(oval, 0, sweep, false);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003261 REPORTER_ASSERT(reporter, p.getBounds() == oval);
3262 sweep += delta;
3263 delta /= 2;
3264 }
3265 for (float sweep = 361, delta = 0.5f; sweep != (float) (sweep - delta);) {
commit-bot@chromium.org4b413c82013-11-25 19:44:07 +00003266 p.arcTo(oval, 0, sweep, false);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003267 REPORTER_ASSERT(reporter, p.getBounds() == oval);
3268 sweep -= delta;
3269 delta /= 2;
3270 }
3271 SkRect noOvalWidth = {1, 2, 0, 3};
3272 p.reset();
3273 p.arcTo(noOvalWidth, 0, 360, false);
3274 REPORTER_ASSERT(reporter, p.isEmpty());
3275
3276 SkRect noOvalHeight = {1, 2, 3, 1};
3277 p.reset();
3278 p.arcTo(noOvalHeight, 0, 360, false);
3279 REPORTER_ASSERT(reporter, p.isEmpty());
3280}
3281
3282static void test_addPath(skiatest::Reporter* reporter) {
3283 SkPath p, q;
3284 p.lineTo(1, 2);
3285 q.moveTo(4, 4);
3286 q.lineTo(7, 8);
3287 q.conicTo(8, 7, 6, 5, 0.5f);
3288 q.quadTo(6, 7, 8, 6);
3289 q.cubicTo(5, 6, 7, 8, 7, 5);
3290 q.close();
3291 p.addPath(q, -4, -4);
3292 SkRect expected = {0, 0, 4, 4};
3293 REPORTER_ASSERT(reporter, p.getBounds() == expected);
3294 p.reset();
3295 p.reverseAddPath(q);
3296 SkRect reverseExpected = {4, 4, 8, 8};
3297 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
3298}
3299
commit-bot@chromium.org14747e52014-02-11 21:16:29 +00003300static void test_addPathMode(skiatest::Reporter* reporter, bool explicitMoveTo, bool extend) {
3301 SkPath p, q;
3302 if (explicitMoveTo) {
3303 p.moveTo(1, 1);
3304 }
3305 p.lineTo(1, 2);
3306 if (explicitMoveTo) {
3307 q.moveTo(2, 1);
3308 }
3309 q.lineTo(2, 2);
3310 p.addPath(q, extend ? SkPath::kExtend_AddPathMode : SkPath::kAppend_AddPathMode);
3311 uint8_t verbs[4];
3312 int verbcount = p.getVerbs(verbs, 4);
3313 REPORTER_ASSERT(reporter, verbcount == 4);
3314 REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
3315 REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
3316 REPORTER_ASSERT(reporter, verbs[2] == (extend ? SkPath::kLine_Verb : SkPath::kMove_Verb));
3317 REPORTER_ASSERT(reporter, verbs[3] == SkPath::kLine_Verb);
3318}
3319
3320static void test_extendClosedPath(skiatest::Reporter* reporter) {
3321 SkPath p, q;
3322 p.moveTo(1, 1);
3323 p.lineTo(1, 2);
3324 p.lineTo(2, 2);
3325 p.close();
3326 q.moveTo(2, 1);
3327 q.lineTo(2, 3);
3328 p.addPath(q, SkPath::kExtend_AddPathMode);
3329 uint8_t verbs[7];
3330 int verbcount = p.getVerbs(verbs, 7);
3331 REPORTER_ASSERT(reporter, verbcount == 7);
3332 REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
3333 REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
3334 REPORTER_ASSERT(reporter, verbs[2] == SkPath::kLine_Verb);
3335 REPORTER_ASSERT(reporter, verbs[3] == SkPath::kClose_Verb);
3336 REPORTER_ASSERT(reporter, verbs[4] == SkPath::kMove_Verb);
3337 REPORTER_ASSERT(reporter, verbs[5] == SkPath::kLine_Verb);
3338 REPORTER_ASSERT(reporter, verbs[6] == SkPath::kLine_Verb);
3339
3340 SkPoint pt;
3341 REPORTER_ASSERT(reporter, p.getLastPt(&pt));
3342 REPORTER_ASSERT(reporter, pt == SkPoint::Make(2, 3));
3343 REPORTER_ASSERT(reporter, p.getPoint(3) == SkPoint::Make(1, 1));
3344}
3345
3346static void test_addEmptyPath(skiatest::Reporter* reporter, SkPath::AddPathMode mode) {
3347 SkPath p, q, r;
3348 // case 1: dst is empty
3349 p.moveTo(2, 1);
3350 p.lineTo(2, 3);
3351 q.addPath(p, mode);
3352 REPORTER_ASSERT(reporter, q == p);
3353 // case 2: src is empty
3354 p.addPath(r, mode);
3355 REPORTER_ASSERT(reporter, q == p);
3356 // case 3: src and dst are empty
3357 q.reset();
3358 q.addPath(r, mode);
3359 REPORTER_ASSERT(reporter, q.isEmpty());
skia.committer@gmail.com877c4492014-02-12 03:02:04 +00003360}
commit-bot@chromium.org14747e52014-02-11 21:16:29 +00003361
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003362static void test_conicTo_special_case(skiatest::Reporter* reporter) {
3363 SkPath p;
3364 p.conicTo(1, 2, 3, 4, -1);
3365 check_path_is_line_and_reset(reporter, &p, 3, 4);
3366 p.conicTo(1, 2, 3, 4, SK_ScalarInfinity);
3367 check_path_is_line_pair_and_reset(reporter, &p, 1, 2, 3, 4);
3368 p.conicTo(1, 2, 3, 4, 1);
3369 check_path_is_quad_and_reset(reporter, &p, 1, 2, 3, 4);
3370}
3371
3372static void test_get_point(skiatest::Reporter* reporter) {
3373 SkPath p;
3374 SkPoint pt = p.getPoint(0);
3375 REPORTER_ASSERT(reporter, pt == SkPoint::Make(0, 0));
3376 REPORTER_ASSERT(reporter, !p.getLastPt(NULL));
3377 REPORTER_ASSERT(reporter, !p.getLastPt(&pt) && pt == SkPoint::Make(0, 0));
3378 p.setLastPt(10, 10);
3379 pt = p.getPoint(0);
3380 REPORTER_ASSERT(reporter, pt == SkPoint::Make(10, 10));
3381 REPORTER_ASSERT(reporter, p.getLastPt(NULL));
3382 p.rMoveTo(10, 10);
3383 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt == SkPoint::Make(20, 20));
3384}
3385
3386static void test_contains(skiatest::Reporter* reporter) {
3387 SkPath p;
3388 p.setFillType(SkPath::kInverseWinding_FillType);
3389 REPORTER_ASSERT(reporter, p.contains(0, 0));
3390 p.setFillType(SkPath::kWinding_FillType);
3391 REPORTER_ASSERT(reporter, !p.contains(0, 0));
3392 p.moveTo(4, 4);
3393 p.lineTo(6, 8);
3394 p.lineTo(8, 4);
3395 // test quick reject
3396 REPORTER_ASSERT(reporter, !p.contains(4, 0));
3397 REPORTER_ASSERT(reporter, !p.contains(0, 4));
3398 REPORTER_ASSERT(reporter, !p.contains(4, 10));
3399 REPORTER_ASSERT(reporter, !p.contains(10, 4));
3400 // test various crossings in x
3401 REPORTER_ASSERT(reporter, !p.contains(5, 7));
3402 REPORTER_ASSERT(reporter, p.contains(6, 7));
3403 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3404 p.reset();
3405 p.moveTo(4, 4);
3406 p.lineTo(8, 6);
3407 p.lineTo(4, 8);
3408 // test various crossings in y
3409 REPORTER_ASSERT(reporter, !p.contains(7, 5));
3410 REPORTER_ASSERT(reporter, p.contains(7, 6));
3411 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3412 // test quads
3413 p.reset();
3414 p.moveTo(4, 4);
3415 p.quadTo(6, 6, 8, 8);
3416 p.quadTo(6, 8, 4, 8);
3417 p.quadTo(4, 6, 4, 4);
3418 REPORTER_ASSERT(reporter, p.contains(5, 6));
3419 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3420
3421 p.reset();
3422 p.moveTo(6, 6);
3423 p.quadTo(8, 8, 6, 8);
3424 p.quadTo(4, 8, 4, 6);
3425 p.quadTo(4, 4, 6, 6);
3426 REPORTER_ASSERT(reporter, p.contains(5, 6));
3427 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3428
3429#define CONIC_CONTAINS_BUG_FIXED 0
3430#if CONIC_CONTAINS_BUG_FIXED
3431 p.reset();
3432 p.moveTo(4, 4);
3433 p.conicTo(6, 6, 8, 8, 0.5f);
3434 p.conicTo(6, 8, 4, 8, 0.5f);
3435 p.conicTo(4, 6, 4, 4, 0.5f);
3436 REPORTER_ASSERT(reporter, p.contains(5, 6));
3437 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3438#endif
3439
3440 // test cubics
3441 SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5, 4}, {6, 5}, {7, 6}};
3442 for (int i = 0; i < 3; ++i) {
3443 p.reset();
3444 p.setFillType(SkPath::kEvenOdd_FillType);
3445 p.moveTo(pts[i].fX, pts[i].fY);
3446 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);
3447 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);
3448 p.close();
3449 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f));
3450 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f));
3451 }
3452}
3453
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003454class PathRefTest_Private {
3455public:
3456 static void TestPathRef(skiatest::Reporter* reporter) {
3457 static const int kRepeatCnt = 10;
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003458
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003459 SkAutoTUnref<SkPathRef> pathRef(SkNEW(SkPathRef));
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003460
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003461 SkPathRef::Editor ed(&pathRef);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003462
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003463 {
3464 ed.growForRepeatedVerb(SkPath::kMove_Verb, kRepeatCnt);
3465 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3466 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
3467 REPORTER_ASSERT(reporter, 0 == pathRef->getSegmentMasks());
3468 for (int i = 0; i < kRepeatCnt; ++i) {
3469 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == pathRef->atVerb(i));
3470 }
3471 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003472 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003473
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003474 {
3475 ed.growForRepeatedVerb(SkPath::kLine_Verb, kRepeatCnt);
3476 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3477 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
3478 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == pathRef->getSegmentMasks());
3479 for (int i = 0; i < kRepeatCnt; ++i) {
3480 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == pathRef->atVerb(i));
3481 }
3482 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003483 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003484
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003485 {
3486 ed.growForRepeatedVerb(SkPath::kQuad_Verb, kRepeatCnt);
3487 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3488 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
3489 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == pathRef->getSegmentMasks());
3490 for (int i = 0; i < kRepeatCnt; ++i) {
3491 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == pathRef->atVerb(i));
3492 }
3493 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003494 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003495
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003496 {
3497 SkScalar* weights = NULL;
3498 ed.growForRepeatedVerb(SkPath::kConic_Verb, kRepeatCnt, &weights);
3499 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3500 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
3501 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countWeights());
3502 REPORTER_ASSERT(reporter, SkPath::kConic_SegmentMask == pathRef->getSegmentMasks());
bsalomon49f085d2014-09-05 13:34:00 -07003503 REPORTER_ASSERT(reporter, weights);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003504 for (int i = 0; i < kRepeatCnt; ++i) {
3505 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == pathRef->atVerb(i));
3506 }
3507 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003508 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003509
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003510 {
3511 ed.growForRepeatedVerb(SkPath::kCubic_Verb, kRepeatCnt);
3512 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
3513 REPORTER_ASSERT(reporter, 3*kRepeatCnt == pathRef->countPoints());
3514 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == pathRef->getSegmentMasks());
3515 for (int i = 0; i < kRepeatCnt; ++i) {
3516 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == pathRef->atVerb(i));
3517 }
3518 ed.resetToSize(0, 0, 0);
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003519 }
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003520 }
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003521};
robertphillips@google.com6b8dbb62013-12-12 23:03:51 +00003522
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003523static void test_operatorEqual(skiatest::Reporter* reporter) {
3524 SkPath a;
3525 SkPath b;
3526 REPORTER_ASSERT(reporter, a == a);
3527 REPORTER_ASSERT(reporter, a == b);
3528 a.setFillType(SkPath::kInverseWinding_FillType);
3529 REPORTER_ASSERT(reporter, a != b);
3530 a.reset();
3531 REPORTER_ASSERT(reporter, a == b);
3532 a.lineTo(1, 1);
3533 REPORTER_ASSERT(reporter, a != b);
3534 a.reset();
3535 REPORTER_ASSERT(reporter, a == b);
3536 a.lineTo(1, 1);
3537 b.lineTo(1, 2);
3538 REPORTER_ASSERT(reporter, a != b);
3539 a.reset();
3540 a.lineTo(1, 2);
3541 REPORTER_ASSERT(reporter, a == b);
3542}
3543
caryclark66a5d8b2014-06-24 08:30:15 -07003544static void compare_dump(skiatest::Reporter* reporter, const SkPath& path, bool force,
caryclarke9562592014-09-15 09:26:09 -07003545 bool dumpAsHex, const char* str) {
caryclark66a5d8b2014-06-24 08:30:15 -07003546 SkDynamicMemoryWStream wStream;
caryclarke9562592014-09-15 09:26:09 -07003547 path.dump(&wStream, force, dumpAsHex);
caryclark66a5d8b2014-06-24 08:30:15 -07003548 SkAutoDataUnref data(wStream.copyToData());
3549 REPORTER_ASSERT(reporter, data->size() == strlen(str));
mtkleind4897592014-11-14 09:22:40 -08003550 if (strlen(str) > 0) {
3551 REPORTER_ASSERT(reporter, !memcmp(data->data(), str, strlen(str)));
3552 } else {
3553 REPORTER_ASSERT(reporter, data->data() == NULL || !memcmp(data->data(), str, strlen(str)));
3554 }
caryclark66a5d8b2014-06-24 08:30:15 -07003555}
3556
3557static void test_dump(skiatest::Reporter* reporter) {
3558 SkPath p;
caryclarke9562592014-09-15 09:26:09 -07003559 compare_dump(reporter, p, false, false, "");
3560 compare_dump(reporter, p, true, false, "");
caryclark66a5d8b2014-06-24 08:30:15 -07003561 p.moveTo(1, 2);
3562 p.lineTo(3, 4);
caryclarke9562592014-09-15 09:26:09 -07003563 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3564 "path.lineTo(3, 4);\n");
3565 compare_dump(reporter, p, true, false, "path.moveTo(1, 2);\n"
3566 "path.lineTo(3, 4);\n"
3567 "path.lineTo(1, 2);\n"
3568 "path.close();\n");
caryclark66a5d8b2014-06-24 08:30:15 -07003569 p.reset();
3570 p.moveTo(1, 2);
3571 p.quadTo(3, 4, 5, 6);
caryclarke9562592014-09-15 09:26:09 -07003572 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3573 "path.quadTo(3, 4, 5, 6);\n");
caryclark66a5d8b2014-06-24 08:30:15 -07003574 p.reset();
3575 p.moveTo(1, 2);
3576 p.conicTo(3, 4, 5, 6, 0.5f);
caryclarke9562592014-09-15 09:26:09 -07003577 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3578 "path.conicTo(3, 4, 5, 6, 0.5f);\n");
caryclark66a5d8b2014-06-24 08:30:15 -07003579 p.reset();
3580 p.moveTo(1, 2);
3581 p.cubicTo(3, 4, 5, 6, 7, 8);
caryclarke9562592014-09-15 09:26:09 -07003582 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3583 "path.cubicTo(3, 4, 5, 6, 7, 8);\n");
3584 p.reset();
3585 p.moveTo(1, 2);
3586 p.lineTo(3, 4);
caryclark08fa28c2014-10-23 13:08:56 -07003587 compare_dump(reporter, p, false, true,
3588 "path.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)); // 1, 2\n"
3589 "path.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)); // 3, 4\n");
caryclarke9562592014-09-15 09:26:09 -07003590 p.reset();
3591 p.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000));
3592 p.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000));
3593 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
3594 "path.lineTo(3, 4);\n");
caryclark66a5d8b2014-06-24 08:30:15 -07003595}
3596
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003597class PathTest_Private {
3598public:
3599 static void TestPathTo(skiatest::Reporter* reporter) {
3600 SkPath p, q;
3601 p.lineTo(4, 4);
3602 p.reversePathTo(q);
3603 check_path_is_line(reporter, &p, 4, 4);
3604 q.moveTo(-4, -4);
3605 p.reversePathTo(q);
3606 check_path_is_line(reporter, &p, 4, 4);
3607 q.lineTo(7, 8);
3608 q.conicTo(8, 7, 6, 5, 0.5f);
3609 q.quadTo(6, 7, 8, 6);
3610 q.cubicTo(5, 6, 7, 8, 7, 5);
3611 q.close();
3612 p.reversePathTo(q);
3613 SkRect reverseExpected = {-4, -4, 8, 8};
3614 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
3615 }
3616};
3617
commit-bot@chromium.org05ec2232014-01-15 18:00:57 +00003618DEF_TEST(Paths, reporter) {
commit-bot@chromium.org4e332f82014-05-05 16:04:42 +00003619 test_path_crbug364224();
3620
bungeman@google.coma5809a32013-06-21 15:13:34 +00003621 SkTSize<SkScalar>::Make(3,4);
3622
3623 SkPath p, empty;
3624 SkRect bounds, bounds2;
3625 test_empty(reporter, p);
reed@android.com3abec1d2009-03-02 05:36:20 +00003626
reed@android.comd252db02009-04-01 18:31:44 +00003627 REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
reed@android.com80e39a72009-04-02 16:59:40 +00003628
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003629 // this triggers a code path in SkPath::operator= which is otherwise unexercised
3630 SkPath& self = p;
3631 p = self;
3632
3633 // this triggers a code path in SkPath::swap which is otherwise unexercised
3634 p.swap(self);
3635
reed@android.com3abec1d2009-03-02 05:36:20 +00003636 bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
reed@android.com6b82d1a2009-06-03 02:35:01 +00003637
reed@android.com6b82d1a2009-06-03 02:35:01 +00003638 p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1);
3639 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00003640 // we have quads or cubics
reed220f9262014-12-17 08:21:04 -08003641 REPORTER_ASSERT(reporter,
3642 p.getSegmentMasks() & (kCurveSegmentMask | SkPath::kConic_SegmentMask));
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003643 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00003644
reed@android.com6b82d1a2009-06-03 02:35:01 +00003645 p.reset();
bungeman@google.coma5809a32013-06-21 15:13:34 +00003646 test_empty(reporter, p);
reed@google.com10296cc2011-09-21 12:29:05 +00003647
reed@android.com6b82d1a2009-06-03 02:35:01 +00003648 p.addOval(bounds);
3649 check_convex_bounds(reporter, p, bounds);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003650 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@google.com62047cf2011-02-07 19:39:09 +00003651
bungeman@google.coma5809a32013-06-21 15:13:34 +00003652 p.rewind();
3653 test_empty(reporter, p);
3654
reed@android.com3abec1d2009-03-02 05:36:20 +00003655 p.addRect(bounds);
reed@android.com6b82d1a2009-06-03 02:35:01 +00003656 check_convex_bounds(reporter, p, bounds);
reed@google.com10296cc2011-09-21 12:29:05 +00003657 // we have only lines
3658 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == p.getSegmentMasks());
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003659 REPORTER_ASSERT(reporter, !p.isEmpty());
reed@android.com3abec1d2009-03-02 05:36:20 +00003660
bungeman@google.coma5809a32013-06-21 15:13:34 +00003661 REPORTER_ASSERT(reporter, p != empty);
3662 REPORTER_ASSERT(reporter, !(p == empty));
reed@android.com3abec1d2009-03-02 05:36:20 +00003663
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00003664 // do getPoints and getVerbs return the right result
3665 REPORTER_ASSERT(reporter, p.getPoints(NULL, 0) == 4);
3666 REPORTER_ASSERT(reporter, p.getVerbs(NULL, 0) == 5);
reed@android.com3abec1d2009-03-02 05:36:20 +00003667 SkPoint pts[4];
3668 int count = p.getPoints(pts, 4);
3669 REPORTER_ASSERT(reporter, count == 4);
bsalomon@google.comdf9d6562012-06-07 21:43:15 +00003670 uint8_t verbs[6];
3671 verbs[5] = 0xff;
3672 p.getVerbs(verbs, 5);
3673 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == verbs[0]);
3674 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[1]);
3675 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[2]);
3676 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[3]);
3677 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == verbs[4]);
3678 REPORTER_ASSERT(reporter, 0xff == verbs[5]);
reed@android.com3abec1d2009-03-02 05:36:20 +00003679 bounds2.set(pts, 4);
3680 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00003681
reed@android.com3abec1d2009-03-02 05:36:20 +00003682 bounds.offset(SK_Scalar1*3, SK_Scalar1*4);
3683 p.offset(SK_Scalar1*3, SK_Scalar1*4);
reed@android.comd252db02009-04-01 18:31:44 +00003684 REPORTER_ASSERT(reporter, bounds == p.getBounds());
reed@android.com3abec1d2009-03-02 05:36:20 +00003685
reed@android.com3abec1d2009-03-02 05:36:20 +00003686 REPORTER_ASSERT(reporter, p.isRect(NULL));
caryclark@google.comf1316942011-07-26 19:54:45 +00003687 bounds2.setEmpty();
reed@android.com3abec1d2009-03-02 05:36:20 +00003688 REPORTER_ASSERT(reporter, p.isRect(&bounds2));
3689 REPORTER_ASSERT(reporter, bounds == bounds2);
reed@android.com80e39a72009-04-02 16:59:40 +00003690
reed@android.com3abec1d2009-03-02 05:36:20 +00003691 // now force p to not be a rect
3692 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2);
3693 p.addRect(bounds);
3694 REPORTER_ASSERT(reporter, !p.isRect(NULL));
reed@android.com3abec1d2009-03-02 05:36:20 +00003695
robertphillipsfe7c4272014-12-29 11:36:39 -08003696 // Test an edge case w.r.t. the bound returned by isRect (i.e., the
3697 // path has a trailing moveTo. Please see crbug.com\445368)
3698 {
3699 SkRect r;
3700 p.reset();
3701 p.addRect(bounds);
3702 REPORTER_ASSERT(reporter, p.isRect(&r));
3703 REPORTER_ASSERT(reporter, r == bounds);
3704 // add a moveTo outside of our bounds
3705 p.moveTo(bounds.fLeft + 10, bounds.fBottom + 10);
3706 REPORTER_ASSERT(reporter, p.isRect(&r));
3707 REPORTER_ASSERT(reporter, r == bounds);
3708 }
3709
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003710 test_operatorEqual(reporter);
reed@google.com7e6c4d12012-05-10 14:05:43 +00003711 test_isLine(reporter);
3712 test_isRect(reporter);
caryclark@google.com56f233a2012-11-19 13:06:06 +00003713 test_isNestedRects(reporter);
schenney@chromium.org4da06ab2011-12-20 15:14:18 +00003714 test_zero_length_paths(reporter);
reed@google.comcabaf1d2012-01-11 21:03:05 +00003715 test_direction(reporter);
reed@google.com04863fa2011-05-15 04:08:24 +00003716 test_convexity(reporter);
reed@google.com7c424812011-05-15 04:38:34 +00003717 test_convexity2(reporter);
bsalomon@google.com9bee33a2012-11-13 21:51:38 +00003718 test_conservativelyContains(reporter);
bsalomon@google.comb3b8dfa2011-07-13 17:44:36 +00003719 test_close(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00003720 test_segment_masks(reporter);
reed@google.com53effc52011-09-21 19:05:12 +00003721 test_flattening(reporter);
3722 test_transform(reporter);
reed@google.com3563c9e2011-11-14 19:34:57 +00003723 test_bounds(reporter);
schenney@chromium.org6630d8d2012-01-04 21:05:51 +00003724 test_iter(reporter);
3725 test_raw_iter(reporter);
bsalomon@google.com6aa29652012-04-18 13:29:52 +00003726 test_circle(reporter);
3727 test_oval(reporter);
reed@google.com8b06f1a2012-05-29 12:03:46 +00003728 test_strokerec(reporter);
reed@google.com744faba2012-05-29 19:54:52 +00003729 test_addPoly(reporter);
reed@google.com0bb18bb2012-07-26 15:20:36 +00003730 test_isfinite(reporter);
tomhudson@google.comed02c4d2012-08-10 14:10:45 +00003731 test_isfinite_after_transform(reporter);
robertphillips@google.comb95eaa82012-10-18 15:26:12 +00003732 test_arb_round_rect_is_convex(reporter);
robertphillips@google.com158618e2012-10-23 16:56:56 +00003733 test_arb_zero_rad_round_rect_is_rect(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003734 test_addrect(reporter);
reed@google.coma8790de2012-10-24 21:04:04 +00003735 test_addrect_isfinite(reporter);
sugoi@google.com54f0d1b2013-02-27 19:17:41 +00003736 test_tricky_cubic();
3737 test_clipped_cubic();
3738 test_crbug_170666();
reed@google.com7a90daf2013-04-10 18:44:00 +00003739 test_bad_cubic_crbug229478();
reed@google.com3eff3592013-05-08 21:08:21 +00003740 test_bad_cubic_crbug234190();
mtklein@google.com9c9d4a72013-08-07 19:17:53 +00003741 test_android_specific_behavior(reporter);
commit-bot@chromium.org1ab9f732013-10-30 18:57:55 +00003742 test_gen_id(reporter);
commit-bot@chromium.org9d54aeb2013-08-09 19:48:26 +00003743 test_path_close_issue1474(reporter);
reed@google.comb58ba892013-10-15 15:44:35 +00003744 test_path_to_region(reporter);
commit-bot@chromium.org42feaaf2013-11-08 15:51:12 +00003745 test_rrect(reporter);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003746 test_arc(reporter);
3747 test_arcTo(reporter);
3748 test_addPath(reporter);
commit-bot@chromium.org14747e52014-02-11 21:16:29 +00003749 test_addPathMode(reporter, false, false);
3750 test_addPathMode(reporter, true, false);
3751 test_addPathMode(reporter, false, true);
3752 test_addPathMode(reporter, true, true);
3753 test_extendClosedPath(reporter);
3754 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode);
3755 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode);
commit-bot@chromium.orga1a097e2013-11-14 16:53:22 +00003756 test_conicTo_special_case(reporter);
3757 test_get_point(reporter);
3758 test_contains(reporter);
3759 PathTest_Private::TestPathTo(reporter);
robertphillips@google.com0efb21b2013-12-13 19:36:25 +00003760 PathRefTest_Private::TestPathRef(reporter);
caryclark66a5d8b2014-06-24 08:30:15 -07003761 test_dump(reporter);
piotaixrfac4e0e2014-08-26 11:59:04 -07003762 test_path_crbugskia2820(reporter);
reed5bcbe912014-12-15 12:28:33 -08003763 test_skbug_3239(reporter);
reed@android.com3abec1d2009-03-02 05:36:20 +00003764}