2 * Copyright 2011 Google Inc.
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
10 #include "SkGeometry.h"
13 #include "SkParsePath.h"
14 #include "SkPathPriv.h"
15 #include "SkPathEffect.h"
18 #include "SkReader32.h"
21 #include "SkStrokeRec.h"
22 #include "SkSurface.h"
24 #include "SkWriter32.h"
27 static void set_radii(SkVector radii[4], int index, float rad) {
28 sk_bzero(radii, sizeof(SkVector) * 4);
29 radii[index].set(rad, rad);
32 static void test_add_rrect(skiatest::Reporter* reporter, const SkRect& bounds,
33 const SkVector radii[4]) {
35 rrect.setRectRadii(bounds, radii);
36 REPORTER_ASSERT(reporter, bounds == rrect.rect());
39 // this line should not assert in the debug build (from validate)
41 REPORTER_ASSERT(reporter, bounds == path.getBounds());
44 static void test_skbug_3469(skiatest::Reporter* reporter) {
47 path.quadTo(20, 50, 80, 50);
48 path.quadTo(20, 50, 20, 80);
49 REPORTER_ASSERT(reporter, !path.isConvex());
52 static void test_skbug_3239(skiatest::Reporter* reporter) {
53 const float min = SkBits2Float(0xcb7f16c8); /* -16717512.000000 */
54 const float max = SkBits2Float(0x4b7f1c1d); /* 16718877.000000 */
55 const float big = SkBits2Float(0x4b7f1bd7); /* 16718807.000000 */
57 const float rad = 33436320;
59 const SkRect rectx = SkRect::MakeLTRB(min, min, max, big);
60 const SkRect recty = SkRect::MakeLTRB(min, min, big, max);
63 for (int i = 0; i < 4; ++i) {
64 set_radii(radii, i, rad);
65 test_add_rrect(reporter, rectx, radii);
66 test_add_rrect(reporter, recty, radii);
70 static void make_path_crbug364224(SkPath* path) {
72 path->moveTo(3.747501373f, 2.724499941f);
73 path->lineTo(3.747501373f, 3.75f);
74 path->cubicTo(3.747501373f, 3.88774991f, 3.635501385f, 4.0f, 3.497501373f, 4.0f);
75 path->lineTo(0.7475013733f, 4.0f);
76 path->cubicTo(0.6095013618f, 4.0f, 0.4975013733f, 3.88774991f, 0.4975013733f, 3.75f);
77 path->lineTo(0.4975013733f, 1.0f);
78 path->cubicTo(0.4975013733f, 0.8622499704f, 0.6095013618f, 0.75f, 0.7475013733f,0.75f);
79 path->lineTo(3.497501373f, 0.75f);
80 path->cubicTo(3.50275135f, 0.75f, 3.5070014f, 0.7527500391f, 3.513001442f, 0.753000021f);
81 path->lineTo(3.715001345f, 0.5512499809f);
82 path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
83 path->lineTo(0.7475013733f, 0.4999999702f);
84 path->cubicTo(0.4715013802f, 0.4999999702f, 0.2475013733f, 0.7239999771f, 0.2475013733f, 1.0f);
85 path->lineTo(0.2475013733f, 3.75f);
86 path->cubicTo(0.2475013733f, 4.026000023f, 0.4715013504f, 4.25f, 0.7475013733f, 4.25f);
87 path->lineTo(3.497501373f, 4.25f);
88 path->cubicTo(3.773501396f, 4.25f, 3.997501373f, 4.026000023f, 3.997501373f, 3.75f);
89 path->lineTo(3.997501373f, 2.474750042f);
90 path->lineTo(3.747501373f, 2.724499941f);
94 static void make_path_crbug364224_simplified(SkPath* path) {
95 path->moveTo(3.747501373f, 2.724499941f);
96 path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f);
100 static void test_sect_with_horizontal_needs_pinning() {
101 // Test that sect_with_horizontal in SkLineClipper.cpp needs to pin after computing the
105 path.moveTo(-540000, -720000);
106 path.lineTo(-9.10000017e-05f, 9.99999996e-13f);
109 // Without the pinning code in sect_with_horizontal(), this would assert in the lineclipper
111 SkSurface::MakeRasterN32Premul(10, 10)->getCanvas()->drawPath(path, paint);
114 static void test_path_crbug364224() {
117 auto surface(SkSurface::MakeRasterN32Premul(84, 88));
118 SkCanvas* canvas = surface->getCanvas();
120 make_path_crbug364224_simplified(&path);
121 canvas->drawPath(path, paint);
123 make_path_crbug364224(&path);
124 canvas->drawPath(path, paint);
127 // this is a unit test instead of a GM because it doesn't draw anything
128 static void test_fuzz_crbug_638223() {
129 auto surface(SkSurface::MakeRasterN32Premul(250, 250));
130 SkCanvas* canvas = surface->getCanvas();
132 path.moveTo(SkBits2Float(0x47452a00), SkBits2Float(0x43211d01)); // 50474, 161.113f
133 path.conicTo(SkBits2Float(0x401c0000), SkBits2Float(0x40680000),
134 SkBits2Float(0x02c25a81), SkBits2Float(0x981a1fa0),
135 SkBits2Float(0x6bf9abea)); // 2.4375f, 3.625f, 2.85577e-37f, -1.992e-24f, 6.03669e+26f
137 paint.setAntiAlias(true);
138 canvas->drawPath(path, paint);
141 static void test_fuzz_crbug_643933() {
142 auto surface(SkSurface::MakeRasterN32Premul(250, 250));
143 SkCanvas* canvas = surface->getCanvas();
145 paint.setAntiAlias(true);
148 path.conicTo(SkBits2Float(0x002001f2), SkBits2Float(0x4161ffff), // 2.93943e-39f, 14.125f
149 SkBits2Float(0x49f7224d), SkBits2Float(0x45eec8df), // 2.02452e+06f, 7641.11f
150 SkBits2Float(0x721aee0c)); // 3.0687e+30f
151 canvas->drawPath(path, paint);
154 path.conicTo(SkBits2Float(0x00007ff2), SkBits2Float(0x4169ffff), // 4.58981e-41f, 14.625f
155 SkBits2Float(0x43ff2261), SkBits2Float(0x41eeea04), // 510.269f, 29.8643f
156 SkBits2Float(0x5d06eff8)); // 6.07704e+17f
157 canvas->drawPath(path, paint);
161 * In debug mode, this path was causing an assertion to fail in
162 * SkPathStroker::preJoinTo() and, in Release, the use of an unitialized value.
164 static void make_path_crbugskia2820(SkPath* path, skiatest::Reporter* reporter) {
165 SkPoint orig, p1, p2, p3;
166 orig = SkPoint::Make(1.f, 1.f);
167 p1 = SkPoint::Make(1.f - SK_ScalarNearlyZero, 1.f);
168 p2 = SkPoint::Make(1.f, 1.f + SK_ScalarNearlyZero);
169 p3 = SkPoint::Make(2.f, 2.f);
173 path->cubicTo(p1, p2, p3);
177 static void test_path_crbugskia2820(skiatest::Reporter* reporter) {//GrContext* context) {
179 make_path_crbugskia2820(&path, reporter);
181 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
182 stroke.setStrokeStyle(2 * SK_Scalar1);
183 stroke.applyToPath(&path, path);
186 static void make_path0(SkPath* path) {
187 // from * https://code.google.com/p/skia/issues/detail?id=1706
189 path->moveTo(146.939f, 1012.84f);
190 path->lineTo(181.747f, 1009.18f);
191 path->lineTo(182.165f, 1013.16f);
192 path->lineTo(147.357f, 1016.82f);
193 path->lineTo(146.939f, 1012.84f);
197 static void make_path1(SkPath* path) {
198 path->addRect(SkRect::MakeXYWH(10, 10, 10, 1));
201 typedef void (*PathProc)(SkPath*);
204 * Regression test: we used to crash (overwrite internal storage) during
205 * construction of the region when the path was INVERSE. That is now fixed,
206 * so test these regions (which used to assert/crash).
208 * https://code.google.com/p/skia/issues/detail?id=1706
210 static void test_path_to_region(skiatest::Reporter* reporter) {
217 clip.setRect(0, 0, 1255, 1925);
219 for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) {
224 rgn.setPath(path, clip);
225 path.toggleInverseFillType();
226 rgn.setPath(path, clip);
230 #ifdef SK_BUILD_FOR_WIN
231 #define SUPPRESS_VISIBILITY_WARNING
233 #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden")))
236 static void test_path_close_issue1474(skiatest::Reporter* reporter) {
237 // This test checks that r{Line,Quad,Conic,Cubic}To following a close()
238 // are relative to the point we close to, not relative to the point we close from.
243 path.rLineTo(0, 100);
244 path.rLineTo(100, 0);
245 path.close(); // Returns us back to 0,0.
246 path.rLineTo(50, 50); // This should go to 50,50.
248 path.getLastPt(&last);
249 REPORTER_ASSERT(reporter, 50 == last.fX);
250 REPORTER_ASSERT(reporter, 50 == last.fY);
254 path.rLineTo(0, 100);
255 path.rLineTo(100, 0);
257 path.rQuadTo(50, 50, 75, 75);
259 path.getLastPt(&last);
260 REPORTER_ASSERT(reporter, 75 == last.fX);
261 REPORTER_ASSERT(reporter, 75 == last.fY);
265 path.rLineTo(0, 100);
266 path.rLineTo(100, 0);
268 path.rConicTo(50, 50, 85, 85, 2);
270 path.getLastPt(&last);
271 REPORTER_ASSERT(reporter, 85 == last.fX);
272 REPORTER_ASSERT(reporter, 85 == last.fY);
276 path.rLineTo(0, 100);
277 path.rLineTo(100, 0);
279 path.rCubicTo(50, 50, 85, 85, 95, 95);
281 path.getLastPt(&last);
282 REPORTER_ASSERT(reporter, 95 == last.fX);
283 REPORTER_ASSERT(reporter, 95 == last.fY);
286 static void test_gen_id(skiatest::Reporter* reporter) {
288 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
291 const uint32_t z = a.getGenerationID();
292 REPORTER_ASSERT(reporter, z != b.getGenerationID());
295 REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID());
298 const uint32_t y = a.getGenerationID();
299 REPORTER_ASSERT(reporter, z != y);
302 const uint32_t x = b.getGenerationID();
303 REPORTER_ASSERT(reporter, x != y && x != z);
306 REPORTER_ASSERT(reporter, b.getGenerationID() == y && a.getGenerationID() == x);
309 REPORTER_ASSERT(reporter, b.getGenerationID() == x);
312 REPORTER_ASSERT(reporter, c.getGenerationID() == x);
315 const uint32_t w = c.getGenerationID();
316 REPORTER_ASSERT(reporter, b.getGenerationID() == x);
317 REPORTER_ASSERT(reporter, a.getGenerationID() == x);
318 REPORTER_ASSERT(reporter, w != x);
320 #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK
321 static bool kExpectGenIDToIgnoreFill = false;
323 static bool kExpectGenIDToIgnoreFill = true;
326 c.toggleInverseFillType();
327 const uint32_t v = c.getGenerationID();
328 REPORTER_ASSERT(reporter, (v == w) == kExpectGenIDToIgnoreFill);
331 REPORTER_ASSERT(reporter, v != c.getGenerationID());
334 // This used to assert in the debug build, as the edges did not all line-up.
335 static void test_bad_cubic_crbug234190() {
337 path.moveTo(13.8509f, 3.16858f);
338 path.cubicTo(-2.35893e+08f, -4.21044e+08f,
339 -2.38991e+08f, -4.26573e+08f,
340 -2.41016e+08f, -4.30188e+08f);
343 paint.setAntiAlias(true);
344 auto surface(SkSurface::MakeRasterN32Premul(84, 88));
345 surface->getCanvas()->drawPath(path, paint);
348 static void test_bad_cubic_crbug229478() {
349 const SkPoint pts[] = {
350 { 4595.91064f, -11596.9873f },
351 { 4597.2168f, -11595.9414f },
352 { 4598.52344f, -11594.8955f },
353 { 4599.83008f, -11593.8496f },
358 path.cubicTo(pts[1], pts[2], pts[3]);
361 paint.setStyle(SkPaint::kStroke_Style);
362 paint.setStrokeWidth(20);
365 // Before the fix, this would infinite-recurse, and run out of stack
366 // because we would keep trying to subdivide a degenerate cubic segment.
367 paint.getFillPath(path, &dst, nullptr);
370 static void build_path_170666(SkPath& path) {
371 path.moveTo(17.9459f, 21.6344f);
372 path.lineTo(139.545f, -47.8105f);
373 path.lineTo(139.545f, -47.8105f);
374 path.lineTo(131.07f, -47.3888f);
375 path.lineTo(131.07f, -47.3888f);
376 path.lineTo(122.586f, -46.9532f);
377 path.lineTo(122.586f, -46.9532f);
378 path.lineTo(18076.6f, 31390.9f);
379 path.lineTo(18076.6f, 31390.9f);
380 path.lineTo(18085.1f, 31390.5f);
381 path.lineTo(18085.1f, 31390.5f);
382 path.lineTo(18076.6f, 31390.9f);
383 path.lineTo(18076.6f, 31390.9f);
384 path.lineTo(17955, 31460.3f);
385 path.lineTo(17955, 31460.3f);
386 path.lineTo(17963.5f, 31459.9f);
387 path.lineTo(17963.5f, 31459.9f);
388 path.lineTo(17971.9f, 31459.5f);
389 path.lineTo(17971.9f, 31459.5f);
390 path.lineTo(17.9551f, 21.6205f);
391 path.lineTo(17.9551f, 21.6205f);
392 path.lineTo(9.47091f, 22.0561f);
393 path.lineTo(9.47091f, 22.0561f);
394 path.lineTo(17.9459f, 21.6344f);
395 path.lineTo(17.9459f, 21.6344f);
396 path.close();path.moveTo(0.995934f, 22.4779f);
397 path.lineTo(0.986725f, 22.4918f);
398 path.lineTo(0.986725f, 22.4918f);
399 path.lineTo(17955, 31460.4f);
400 path.lineTo(17955, 31460.4f);
401 path.lineTo(17971.9f, 31459.5f);
402 path.lineTo(17971.9f, 31459.5f);
403 path.lineTo(18093.6f, 31390.1f);
404 path.lineTo(18093.6f, 31390.1f);
405 path.lineTo(18093.6f, 31390);
406 path.lineTo(18093.6f, 31390);
407 path.lineTo(139.555f, -47.8244f);
408 path.lineTo(139.555f, -47.8244f);
409 path.lineTo(122.595f, -46.9671f);
410 path.lineTo(122.595f, -46.9671f);
411 path.lineTo(0.995934f, 22.4779f);
412 path.lineTo(0.995934f, 22.4779f);
414 path.moveTo(5.43941f, 25.5223f);
415 path.lineTo(798267, -28871.1f);
416 path.lineTo(798267, -28871.1f);
417 path.lineTo(3.12512e+06f, -113102);
418 path.lineTo(3.12512e+06f, -113102);
419 path.cubicTo(5.16324e+06f, -186882, 8.15247e+06f, -295092, 1.1957e+07f, -432813);
420 path.cubicTo(1.95659e+07f, -708257, 3.04359e+07f, -1.10175e+06f, 4.34798e+07f, -1.57394e+06f);
421 path.cubicTo(6.95677e+07f, -2.51831e+06f, 1.04352e+08f, -3.77748e+06f, 1.39135e+08f, -5.03666e+06f);
422 path.cubicTo(1.73919e+08f, -6.29583e+06f, 2.08703e+08f, -7.555e+06f, 2.34791e+08f, -8.49938e+06f);
423 path.cubicTo(2.47835e+08f, -8.97157e+06f, 2.58705e+08f, -9.36506e+06f, 2.66314e+08f, -9.6405e+06f);
424 path.cubicTo(2.70118e+08f, -9.77823e+06f, 2.73108e+08f, -9.88644e+06f, 2.75146e+08f, -9.96022e+06f);
425 path.cubicTo(2.76165e+08f, -9.99711e+06f, 2.76946e+08f, -1.00254e+07f, 2.77473e+08f, -1.00444e+07f);
426 path.lineTo(2.78271e+08f, -1.00733e+07f);
427 path.lineTo(2.78271e+08f, -1.00733e+07f);
428 path.cubicTo(2.78271e+08f, -1.00733e+07f, 2.08703e+08f, -7.555e+06f, 135.238f, 23.3517f);
429 path.cubicTo(131.191f, 23.4981f, 125.995f, 23.7976f, 123.631f, 24.0206f);
430 path.cubicTo(121.267f, 24.2436f, 122.631f, 24.3056f, 126.677f, 24.1591f);
431 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
432 path.lineTo(2.77473e+08f, -1.00444e+07f);
433 path.lineTo(2.77473e+08f, -1.00444e+07f);
434 path.cubicTo(2.76946e+08f, -1.00254e+07f, 2.76165e+08f, -9.99711e+06f, 2.75146e+08f, -9.96022e+06f);
435 path.cubicTo(2.73108e+08f, -9.88644e+06f, 2.70118e+08f, -9.77823e+06f, 2.66314e+08f, -9.6405e+06f);
436 path.cubicTo(2.58705e+08f, -9.36506e+06f, 2.47835e+08f, -8.97157e+06f, 2.34791e+08f, -8.49938e+06f);
437 path.cubicTo(2.08703e+08f, -7.555e+06f, 1.73919e+08f, -6.29583e+06f, 1.39135e+08f, -5.03666e+06f);
438 path.cubicTo(1.04352e+08f, -3.77749e+06f, 6.95677e+07f, -2.51831e+06f, 4.34798e+07f, -1.57394e+06f);
439 path.cubicTo(3.04359e+07f, -1.10175e+06f, 1.95659e+07f, -708258, 1.1957e+07f, -432814);
440 path.cubicTo(8.15248e+06f, -295092, 5.16324e+06f, -186883, 3.12513e+06f, -113103);
441 path.lineTo(798284, -28872);
442 path.lineTo(798284, -28872);
443 path.lineTo(22.4044f, 24.6677f);
444 path.lineTo(22.4044f, 24.6677f);
445 path.cubicTo(22.5186f, 24.5432f, 18.8134f, 24.6337f, 14.1287f, 24.8697f);
446 path.cubicTo(9.4439f, 25.1057f, 5.55359f, 25.3978f, 5.43941f, 25.5223f);
450 static void build_path_simple_170666(SkPath& path) {
451 path.moveTo(126.677f, 24.1591f);
452 path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f);
455 // This used to assert in the SK_DEBUG build, as the clip step would fail with
456 // too-few interations in our cubic-line intersection code. That code now runs
457 // 24 interations (instead of 16).
458 static void test_crbug_170666() {
461 paint.setAntiAlias(true);
463 auto surface(SkSurface::MakeRasterN32Premul(1000, 1000));
465 build_path_simple_170666(path);
466 surface->getCanvas()->drawPath(path, paint);
468 build_path_170666(path);
469 surface->getCanvas()->drawPath(path, paint);
473 static void test_tiny_path_convexity(skiatest::Reporter* reporter, const char* pathBug,
474 SkScalar tx, SkScalar ty, SkScalar scale) {
476 SkAssertResult(SkParsePath::FromSVGString(pathBug, &smallPath));
477 bool smallConvex = smallPath.isConvex();
479 SkAssertResult(SkParsePath::FromSVGString(pathBug, &largePath));
482 matrix.preTranslate(100, 100);
483 matrix.preScale(scale, scale);
484 largePath.transform(matrix);
485 bool largeConvex = largePath.isConvex();
486 REPORTER_ASSERT(reporter, smallConvex == largeConvex);
489 static void test_crbug_493450(skiatest::Reporter* reporter) {
490 const char reducedCase[] =
497 test_tiny_path_convexity(reporter, reducedCase, 100, 100, 100000);
498 const char originalFiddleData[] =
499 "M-0.3383152268862998,-0.11217565719203619L-0.33846085183212765,-0.11212264406895281"
500 "L-0.338509393480737,-0.11210607966681395L-0.33857792286700894,-0.1121889121487573"
501 "L-0.3383866116636664,-0.11228834570924921L-0.33842087635680235,-0.11246078673250548"
502 "L-0.33809536177201055,-0.11245415228342878L-0.33797257995493996,-0.11216571641452182"
503 "L-0.33802112160354925,-0.11201996164188659L-0.33819815585141844,-0.11218559834671019Z";
504 test_tiny_path_convexity(reporter, originalFiddleData, 280081.4116670522f, 93268.04618493588f,
508 static void test_crbug_495894(skiatest::Reporter* reporter) {
509 const char originalFiddleData[] =
510 "M-0.34004273849857214,-0.11332803232216355L-0.34008271397389744,-0.11324483772714951"
511 "L-0.3401940742265893,-0.11324483772714951L-0.34017694188002134,-0.11329807920275889"
512 "L-0.3402026403998733,-0.11333468903941245L-0.34029972369709194,-0.11334134592705701"
513 "L-0.3403054344792813,-0.11344121970007795L-0.3403140006525653,-0.11351115418399343"
514 "L-0.34024261587519866,-0.11353446986281181L-0.3402197727464413,-0.11360442946144192"
515 "L-0.34013696640469604,-0.11359110237029302L-0.34009128014718143,-0.1135877707043939"
516 "L-0.3400598708451401,-0.11360776134112742L-0.34004273849857214,-0.11355112520064405"
517 "L-0.3400113291965308,-0.11355112520064405L-0.3399970522410575,-0.11359110237029302"
518 "L-0.33997135372120546,-0.11355112520064405L-0.3399627875479215,-0.11353780084493197"
519 "L-0.3399485105924481,-0.11350782354357004L-0.3400027630232468,-0.11346452910331437"
520 "L-0.3399485105924481,-0.11340126558629839L-0.33993994441916414,-0.11340126558629839"
521 "L-0.33988283659727087,-0.11331804756574679L-0.33989140277055485,-0.11324483772714951"
522 "L-0.33997991989448945,-0.11324483772714951L-0.3399856306766788,-0.11324483772714951"
523 "L-0.34002560615200417,-0.11334467443478255ZM-0.3400684370184241,-0.11338461985124307"
524 "L-0.340154098751264,-0.11341791238732665L-0.340162664924548,-0.1134378899559977"
525 "L-0.34017979727111597,-0.11340126558629839L-0.3401655203156427,-0.11338129083212668"
526 "L-0.34012268944922275,-0.11332137577529414L-0.34007414780061346,-0.11334467443478255Z"
527 "M-0.3400027630232468,-0.11290567901106024L-0.3400113291965308,-0.11298876531245433"
528 "L-0.33997991989448945,-0.11301535852306784L-0.33990282433493346,-0.11296217481488612"
529 "L-0.33993994441916414,-0.11288906492739594Z";
530 test_tiny_path_convexity(reporter, originalFiddleData, 22682.240000000005f,7819.72220766405f,
534 static void test_crbug_613918() {
536 path.conicTo(-6.62478e-08f, 4.13885e-08f, -6.36935e-08f, 3.97927e-08f, 0.729058f);
537 path.quadTo(2.28206e-09f, -1.42572e-09f, 3.91919e-09f, -2.44852e-09f);
538 path.cubicTo(-16752.2f, -26792.9f, -21.4673f, 10.9347f, -8.57322f, -7.22739f);
540 // This call could lead to an assert or uninitialized read due to a failure
541 // to check the return value from SkCubicClipper::ChopMonoAtY.
542 path.contains(-1.84817e-08f, 1.15465e-08f);
545 static void test_addrect(skiatest::Reporter* reporter) {
548 path.addRect(SkRect::MakeWH(50, 100));
549 REPORTER_ASSERT(reporter, path.isRect(nullptr));
552 path.lineTo(FLT_EPSILON, FLT_EPSILON);
553 path.addRect(SkRect::MakeWH(50, 100));
554 REPORTER_ASSERT(reporter, !path.isRect(nullptr));
557 path.quadTo(0, 0, 0, 0);
558 path.addRect(SkRect::MakeWH(50, 100));
559 REPORTER_ASSERT(reporter, !path.isRect(nullptr));
562 path.conicTo(0, 0, 0, 0, 0.5f);
563 path.addRect(SkRect::MakeWH(50, 100));
564 REPORTER_ASSERT(reporter, !path.isRect(nullptr));
567 path.cubicTo(0, 0, 0, 0, 0, 0);
568 path.addRect(SkRect::MakeWH(50, 100));
569 REPORTER_ASSERT(reporter, !path.isRect(nullptr));
572 // Make sure we stay non-finite once we get there (unless we reset or rewind).
573 static void test_addrect_isfinite(skiatest::Reporter* reporter) {
576 path.addRect(SkRect::MakeWH(50, 100));
577 REPORTER_ASSERT(reporter, path.isFinite());
580 path.lineTo(SK_ScalarInfinity, 42);
581 REPORTER_ASSERT(reporter, !path.isFinite());
583 path.addRect(SkRect::MakeWH(50, 100));
584 REPORTER_ASSERT(reporter, !path.isFinite());
587 REPORTER_ASSERT(reporter, path.isFinite());
589 path.addRect(SkRect::MakeWH(50, 100));
590 REPORTER_ASSERT(reporter, path.isFinite());
593 static void build_big_path(SkPath* path, bool reducedCase) {
595 path->moveTo(577330, 1971.72f);
596 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
598 path->moveTo(60.1631f, 7.70567f);
599 path->quadTo(60.1631f, 7.70567f, 0.99474f, 0.901199f);
600 path->lineTo(577379, 1977.77f);
601 path->quadTo(577364, 1979.57f, 577325, 1980.26f);
602 path->quadTo(577286, 1980.95f, 577245, 1980.13f);
603 path->quadTo(577205, 1979.3f, 577187, 1977.45f);
604 path->quadTo(577168, 1975.6f, 577183, 1973.8f);
605 path->quadTo(577198, 1972, 577238, 1971.31f);
606 path->quadTo(577277, 1970.62f, 577317, 1971.45f);
607 path->quadTo(577330, 1971.72f, 577341, 1972.11f);
608 path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f);
609 path->moveTo(306.718f, -32.912f);
610 path->cubicTo(30.531f, 10.0005f, 1502.47f, 13.2804f, 84.3088f, 9.99601f);
614 static void test_clipped_cubic() {
615 auto surface(SkSurface::MakeRasterN32Premul(640, 480));
617 // This path used to assert, because our cubic-chopping code incorrectly
618 // moved control points after the chop. This test should be run in SK_DEBUG
619 // mode to ensure that we no long assert.
621 for (int doReducedCase = 0; doReducedCase <= 1; ++doReducedCase) {
622 build_big_path(&path, SkToBool(doReducedCase));
625 for (int doAA = 0; doAA <= 1; ++doAA) {
626 paint.setAntiAlias(SkToBool(doAA));
627 surface->getCanvas()->drawPath(path, paint);
632 static void dump_if_ne(skiatest::Reporter* reporter, const SkRect& expected, const SkRect& bounds) {
633 if (expected != bounds) {
634 ERRORF(reporter, "path.getBounds() returned [%g %g %g %g], but expected [%g %g %g %g]",
635 bounds.left(), bounds.top(), bounds.right(), bounds.bottom(),
636 expected.left(), expected.top(), expected.right(), expected.bottom());
640 static void test_bounds_crbug_513799(skiatest::Reporter* reporter) {
643 // As written these tests were failing on LLVM 4.2 MacMini Release mysteriously, so we've
644 // rewritten them to avoid this (compiler-bug?).
645 REPORTER_ASSERT(reporter, SkRect::MakeLTRB(0, 0, 0, 0) == path.getBounds());
648 REPORTER_ASSERT(reporter, SkRect::MakeLTRB(-5, -8, -5, -8) == path.getBounds());
650 path.addRect(SkRect::MakeLTRB(1, 2, 3, 4));
651 REPORTER_ASSERT(reporter, SkRect::MakeLTRB(-5, -8, 3, 4) == path.getBounds());
654 REPORTER_ASSERT(reporter, SkRect::MakeLTRB(-5, -8, 3, 4) == path.getBounds());
656 dump_if_ne(reporter, SkRect::MakeLTRB(0, 0, 0, 0), path.getBounds());
658 path.moveTo(-5, -8); // should set the bounds
659 dump_if_ne(reporter, SkRect::MakeLTRB(-5, -8, -5, -8), path.getBounds());
661 path.addRect(SkRect::MakeLTRB(1, 2, 3, 4)); // should extend the bounds
662 dump_if_ne(reporter, SkRect::MakeLTRB(-5, -8, 3, 4), path.getBounds());
664 path.moveTo(1, 2); // don't expect this to have changed the bounds
665 dump_if_ne(reporter, SkRect::MakeLTRB(-5, -8, 3, 4), path.getBounds());
669 #include "SkSurface.h"
670 static void test_fuzz_crbug_627414(skiatest::Reporter* reporter) {
673 path.conicTo(3.58732e-43f, 2.72084f, 3.00392f, 3.00392f, 8.46e+37f);
676 paint.setAntiAlias(true);
678 auto surf = SkSurface::MakeRasterN32Premul(100, 100);
679 surf->getCanvas()->drawPath(path, paint);
682 // Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/
683 // which triggered an assert, from a tricky cubic. This test replicates that
684 // example, so we can ensure that we handle it (in SkEdge.cpp), and don't
685 // assert in the SK_DEBUG build.
686 static void test_tricky_cubic() {
687 const SkPoint pts[] = {
688 { SkDoubleToScalar(18.8943768), SkDoubleToScalar(129.121277) },
689 { SkDoubleToScalar(18.8937435), SkDoubleToScalar(129.121689) },
690 { SkDoubleToScalar(18.8950119), SkDoubleToScalar(129.120422) },
691 { SkDoubleToScalar(18.5030727), SkDoubleToScalar(129.13121) },
696 path.cubicTo(pts[1], pts[2], pts[3]);
699 paint.setAntiAlias(true);
701 SkSurface::MakeRasterN32Premul(19, 130)->getCanvas()->drawPath(path, paint);
704 // Inspired by http://code.google.com/p/chromium/issues/detail?id=141651
706 static void test_isfinite_after_transform(skiatest::Reporter* reporter) {
708 path.quadTo(157, 366, 286, 208);
709 path.arcTo(37, 442, 315, 163, 957494590897113.0f);
712 matrix.setScale(1000*1000, 1000*1000);
714 // Be sure that path::transform correctly updates isFinite and the bounds
715 // if the transformation overflows. The previous bug was that isFinite was
716 // set to true in this case, but the bounds were not set to empty (which
718 while (path.isFinite()) {
719 REPORTER_ASSERT(reporter, path.getBounds().isFinite());
720 REPORTER_ASSERT(reporter, !path.getBounds().isEmpty());
721 path.transform(matrix);
723 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
725 matrix.setTranslate(SK_Scalar1, SK_Scalar1);
726 path.transform(matrix);
727 // we need to still be non-finite
728 REPORTER_ASSERT(reporter, !path.isFinite());
729 REPORTER_ASSERT(reporter, path.getBounds().isEmpty());
732 static void add_corner_arc(SkPath* path, const SkRect& rect,
733 SkScalar xIn, SkScalar yIn,
737 SkScalar rx = SkMinScalar(rect.width(), xIn);
738 SkScalar ry = SkMinScalar(rect.height(), yIn);
741 arcRect.set(-rx, -ry, rx, ry);
742 switch (startAngle) {
744 arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom);
747 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom);
750 arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop);
753 arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop);
759 path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false);
762 static void make_arb_round_rect(SkPath* path, const SkRect& r,
763 SkScalar xCorner, SkScalar yCorner) {
764 // we are lazy here and use the same x & y for each corner
765 add_corner_arc(path, r, xCorner, yCorner, 270);
766 add_corner_arc(path, r, xCorner, yCorner, 0);
767 add_corner_arc(path, r, xCorner, yCorner, 90);
768 add_corner_arc(path, r, xCorner, yCorner, 180);
772 // Chrome creates its own round rects with each corner possibly being different.
773 // Performance will suffer if they are not convex.
774 // Note: PathBench::ArbRoundRectBench performs almost exactly
775 // the same test (but with drawing)
776 static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) {
780 for (int i = 0; i < 5000; ++i) {
782 SkScalar size = rand.nextUScalar1() * 30;
783 if (size < SK_Scalar1) {
786 r.fLeft = rand.nextUScalar1() * 300;
787 r.fTop = rand.nextUScalar1() * 300;
788 r.fRight = r.fLeft + 2 * size;
789 r.fBottom = r.fTop + 2 * size;
793 make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15);
795 REPORTER_ASSERT(reporter, temp.isConvex());
799 // Chrome will sometimes create a 0 radius round rect. The degenerate
800 // quads prevent the path from being converted to a rect
801 // Note: PathBench::ArbRoundRectBench performs almost exactly
802 // the same test (but with drawing)
803 static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) {
807 for (int i = 0; i < 5000; ++i) {
809 SkScalar size = rand.nextUScalar1() * 30;
810 if (size < SK_Scalar1) {
813 r.fLeft = rand.nextUScalar1() * 300;
814 r.fTop = rand.nextUScalar1() * 300;
815 r.fRight = r.fLeft + 2 * size;
816 r.fBottom = r.fTop + 2 * size;
820 make_arb_round_rect(&temp, r, 0, 0);
823 REPORTER_ASSERT(reporter, temp.isRect(&result));
824 REPORTER_ASSERT(reporter, r == result);
828 static void test_rect_isfinite(skiatest::Reporter* reporter) {
829 const SkScalar inf = SK_ScalarInfinity;
830 const SkScalar negInf = SK_ScalarNegativeInfinity;
831 const SkScalar nan = SK_ScalarNaN;
835 REPORTER_ASSERT(reporter, r.isFinite());
836 r.set(0, 0, inf, negInf);
837 REPORTER_ASSERT(reporter, !r.isFinite());
839 REPORTER_ASSERT(reporter, !r.isFinite());
847 bool isFine = r.setBoundsCheck(pts, 3);
848 REPORTER_ASSERT(reporter, isFine);
849 REPORTER_ASSERT(reporter, !r.isEmpty());
852 isFine = r.setBoundsCheck(pts, 3);
853 REPORTER_ASSERT(reporter, !isFine);
854 REPORTER_ASSERT(reporter, r.isEmpty());
857 isFine = r.setBoundsCheck(pts, 3);
858 REPORTER_ASSERT(reporter, !isFine);
859 REPORTER_ASSERT(reporter, r.isEmpty());
862 static void test_path_isfinite(skiatest::Reporter* reporter) {
863 const SkScalar inf = SK_ScalarInfinity;
864 const SkScalar negInf = SK_ScalarNegativeInfinity;
865 const SkScalar nan = SK_ScalarNaN;
868 REPORTER_ASSERT(reporter, path.isFinite());
871 REPORTER_ASSERT(reporter, path.isFinite());
874 path.moveTo(SK_Scalar1, 0);
875 REPORTER_ASSERT(reporter, path.isFinite());
878 path.moveTo(inf, negInf);
879 REPORTER_ASSERT(reporter, !path.isFinite());
883 REPORTER_ASSERT(reporter, !path.isFinite());
886 static void test_isfinite(skiatest::Reporter* reporter) {
887 test_rect_isfinite(reporter);
888 test_path_isfinite(reporter);
891 static void test_islastcontourclosed(skiatest::Reporter* reporter) {
893 REPORTER_ASSERT(reporter, !path.isLastContourClosed());
895 REPORTER_ASSERT(reporter, !path.isLastContourClosed());
897 REPORTER_ASSERT(reporter, path.isLastContourClosed());
898 path.lineTo(100, 100);
899 REPORTER_ASSERT(reporter, !path.isLastContourClosed());
900 path.moveTo(200, 200);
901 REPORTER_ASSERT(reporter, !path.isLastContourClosed());
903 REPORTER_ASSERT(reporter, path.isLastContourClosed());
905 REPORTER_ASSERT(reporter, !path.isLastContourClosed());
908 // assert that we always
909 // start with a moveTo
910 // only have 1 moveTo
911 // only have Lines after that
912 // end with a single close
913 // only have (at most) 1 close
915 static void test_poly(skiatest::Reporter* reporter, const SkPath& path,
916 const SkPoint srcPts[], bool expectClose) {
917 SkPath::RawIter iter(path);
920 bool firstTime = true;
921 bool foundClose = false;
923 switch (iter.next(pts)) {
924 case SkPath::kMove_Verb:
925 REPORTER_ASSERT(reporter, firstTime);
926 REPORTER_ASSERT(reporter, pts[0] == srcPts[0]);
930 case SkPath::kLine_Verb:
931 REPORTER_ASSERT(reporter, !firstTime);
932 REPORTER_ASSERT(reporter, pts[1] == srcPts[0]);
935 case SkPath::kQuad_Verb:
936 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected quad verb");
938 case SkPath::kConic_Verb:
939 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected conic verb");
941 case SkPath::kCubic_Verb:
942 REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected cubic verb");
944 case SkPath::kClose_Verb:
945 REPORTER_ASSERT(reporter, !firstTime);
946 REPORTER_ASSERT(reporter, !foundClose);
947 REPORTER_ASSERT(reporter, expectClose);
950 case SkPath::kDone_Verb:
955 REPORTER_ASSERT(reporter, foundClose == expectClose);
958 static void test_addPoly(skiatest::Reporter* reporter) {
962 for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) {
963 pts[i].fX = rand.nextSScalar1();
964 pts[i].fY = rand.nextSScalar1();
967 for (int doClose = 0; doClose <= 1; ++doClose) {
968 for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) {
970 path.addPoly(pts, SkToInt(count), SkToBool(doClose));
971 test_poly(reporter, path, pts, SkToBool(doClose));
976 static void test_strokerec(skiatest::Reporter* reporter) {
977 SkStrokeRec rec(SkStrokeRec::kFill_InitStyle);
978 REPORTER_ASSERT(reporter, rec.isFillStyle());
980 rec.setHairlineStyle();
981 REPORTER_ASSERT(reporter, rec.isHairlineStyle());
983 rec.setStrokeStyle(SK_Scalar1, false);
984 REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle());
986 rec.setStrokeStyle(SK_Scalar1, true);
987 REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle());
989 rec.setStrokeStyle(0, false);
990 REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle());
992 rec.setStrokeStyle(0, true);
993 REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle());
996 // Set this for paths that don't have a consistent direction such as a bowtie.
997 // (cheapComputeDirection is not expected to catch these.)
998 const SkPathPriv::FirstDirection kDontCheckDir = static_cast<SkPathPriv::FirstDirection>(-1);
1000 static void check_direction(skiatest::Reporter* reporter, const SkPath& path,
1001 SkPathPriv::FirstDirection expected) {
1002 if (expected == kDontCheckDir) {
1005 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
1007 SkPathPriv::FirstDirection dir;
1008 if (SkPathPriv::CheapComputeFirstDirection(copy, &dir)) {
1009 REPORTER_ASSERT(reporter, dir == expected);
1011 REPORTER_ASSERT(reporter, SkPathPriv::kUnknown_FirstDirection == expected);
1015 static void test_direction(skiatest::Reporter* reporter) {
1018 REPORTER_ASSERT(reporter, !SkPathPriv::CheapComputeFirstDirection(path, nullptr));
1019 REPORTER_ASSERT(reporter, !SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCW_FirstDirection));
1020 REPORTER_ASSERT(reporter, !SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCCW_FirstDirection));
1021 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kUnknown_FirstDirection));
1023 static const char* gDegen[] = {
1027 "M 10 10 L 10 10 L 10 10",
1028 "M 10 10 Q 10 10 10 10",
1029 "M 10 10 C 10 10 10 10 10 10",
1031 for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) {
1033 bool valid = SkParsePath::FromSVGString(gDegen[i], &path);
1034 REPORTER_ASSERT(reporter, valid);
1035 REPORTER_ASSERT(reporter, !SkPathPriv::CheapComputeFirstDirection(path, nullptr));
1038 static const char* gCW[] = {
1039 "M 10 10 L 10 10 Q 20 10 20 20",
1040 "M 10 10 C 20 10 20 20 20 20",
1041 "M 20 10 Q 20 20 30 20 L 10 20", // test double-back at y-max
1042 // rect with top two corners replaced by cubics with identical middle
1044 "M 10 10 C 10 0 10 0 20 0 L 40 0 C 50 0 50 0 50 10",
1045 "M 20 10 L 0 10 Q 10 10 20 0", // left, degenerate serif
1047 for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) {
1049 bool valid = SkParsePath::FromSVGString(gCW[i], &path);
1050 REPORTER_ASSERT(reporter, valid);
1051 check_direction(reporter, path, SkPathPriv::kCW_FirstDirection);
1054 static const char* gCCW[] = {
1055 "M 10 10 L 10 10 Q 20 10 20 -20",
1056 "M 10 10 C 20 10 20 -20 20 -20",
1057 "M 20 10 Q 20 20 10 20 L 30 20", // test double-back at y-max
1058 // rect with top two corners replaced by cubics with identical middle
1060 "M 50 10 C 50 0 50 0 40 0 L 20 0 C 10 0 10 0 10 10",
1061 "M 10 10 L 30 10 Q 20 10 10 0", // right, degenerate serif
1063 for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) {
1065 bool valid = SkParsePath::FromSVGString(gCCW[i], &path);
1066 REPORTER_ASSERT(reporter, valid);
1067 check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection);
1070 // Test two donuts, each wound a different direction. Only the outer contour
1071 // determines the cheap direction
1073 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCW_Direction);
1074 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCCW_Direction);
1075 check_direction(reporter, path, SkPathPriv::kCW_FirstDirection);
1078 path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCW_Direction);
1079 path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction);
1080 check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection);
1082 // triangle with one point really far from the origin.
1084 // the first point is roughly 1.05e10, 1.05e10
1085 path.moveTo(SkBits2Float(0x501c7652), SkBits2Float(0x501c7652));
1086 path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1);
1087 path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1);
1088 check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection);
1091 path.conicTo(20, 0, 20, 20, 0.5f);
1093 check_direction(reporter, path, SkPathPriv::kCW_FirstDirection);
1096 path.lineTo(1, 1e7f);
1097 path.lineTo(1e7f, 2e7f);
1099 REPORTER_ASSERT(reporter, SkPath::kConvex_Convexity == path.getConvexity());
1100 check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection);
1103 static void add_rect(SkPath* path, const SkRect& r) {
1104 path->moveTo(r.fLeft, r.fTop);
1105 path->lineTo(r.fRight, r.fTop);
1106 path->lineTo(r.fRight, r.fBottom);
1107 path->lineTo(r.fLeft, r.fBottom);
1111 static void test_bounds(skiatest::Reporter* reporter) {
1112 static const SkRect rects[] = {
1113 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) },
1114 { SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) },
1115 { SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) },
1116 { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) },
1119 SkPath path0, path1;
1120 for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) {
1121 path0.addRect(rects[i]);
1122 add_rect(&path1, rects[i]);
1125 REPORTER_ASSERT(reporter, path0.getBounds() == path1.getBounds());
1128 static void stroke_cubic(const SkPoint pts[4]) {
1130 path.moveTo(pts[0]);
1131 path.cubicTo(pts[1], pts[2], pts[3]);
1134 paint.setStyle(SkPaint::kStroke_Style);
1135 paint.setStrokeWidth(SK_Scalar1 * 2);
1138 paint.getFillPath(path, &fill);
1141 // just ensure this can run w/o any SkASSERTS firing in the debug build
1142 // we used to assert due to differences in how we determine a degenerate vector
1143 // but that was fixed with the introduction of SkPoint::CanNormalize
1144 static void stroke_tiny_cubic() {
1156 { 372.0007f, 92.000755f },
1157 { 371.99927f, 92.003922f },
1158 { 371.99826f, 92.003899f },
1164 static void check_close(skiatest::Reporter* reporter, const SkPath& path) {
1165 for (int i = 0; i < 2; ++i) {
1166 SkPath::Iter iter(path, SkToBool(i));
1173 while (SkPath::kDone_Verb != (v = iter.next(pts))) {
1175 case SkPath::kMove_Verb:
1179 case SkPath::kClose_Verb:
1180 REPORTER_ASSERT(reporter, mv == pts[0]);
1187 // if we force a close on the interator we should have a close
1189 REPORTER_ASSERT(reporter, !i || nMT == nCL);
1193 static void test_close(skiatest::Reporter* reporter) {
1195 closePt.moveTo(0, 0);
1197 check_close(reporter, closePt);
1200 openPt.moveTo(0, 0);
1201 check_close(reporter, openPt);
1204 check_close(reporter, empty);
1206 check_close(reporter, empty);
1209 rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1210 check_close(reporter, rect);
1212 check_close(reporter, rect);
1215 quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1216 check_close(reporter, quad);
1218 check_close(reporter, quad);
1221 quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1,
1222 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1);
1223 check_close(reporter, cubic);
1225 check_close(reporter, cubic);
1228 line.moveTo(SK_Scalar1, SK_Scalar1);
1229 line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1);
1230 check_close(reporter, line);
1232 check_close(reporter, line);
1235 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1237 rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1);
1238 check_close(reporter, rect2);
1240 check_close(reporter, rect2);
1243 oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100));
1245 oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200));
1246 check_close(reporter, oval3);
1248 check_close(reporter, oval3);
1251 moves.moveTo(SK_Scalar1, SK_Scalar1);
1252 moves.moveTo(5 * SK_Scalar1, SK_Scalar1);
1253 moves.moveTo(SK_Scalar1, 10 * SK_Scalar1);
1254 moves.moveTo(10 *SK_Scalar1, SK_Scalar1);
1255 check_close(reporter, moves);
1257 stroke_tiny_cubic();
1260 static void check_convexity(skiatest::Reporter* reporter, const SkPath& path,
1261 SkPath::Convexity expected) {
1262 SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path.
1263 SkPath::Convexity c = copy.getConvexity();
1264 REPORTER_ASSERT(reporter, c == expected);
1267 static void test_path_crbug389050(skiatest::Reporter* reporter) {
1268 SkPath tinyConvexPolygon;
1269 tinyConvexPolygon.moveTo(600.131559f, 800.112512f);
1270 tinyConvexPolygon.lineTo(600.161735f, 800.118627f);
1271 tinyConvexPolygon.lineTo(600.148962f, 800.142338f);
1272 tinyConvexPolygon.lineTo(600.134891f, 800.137724f);
1273 tinyConvexPolygon.close();
1274 tinyConvexPolygon.getConvexity();
1275 check_convexity(reporter, tinyConvexPolygon, SkPath::kConvex_Convexity);
1276 check_direction(reporter, tinyConvexPolygon, SkPathPriv::kCW_FirstDirection);
1278 SkPath platTriangle;
1279 platTriangle.moveTo(0, 0);
1280 platTriangle.lineTo(200, 0);
1281 platTriangle.lineTo(100, 0.04f);
1282 platTriangle.close();
1283 platTriangle.getConvexity();
1284 check_direction(reporter, platTriangle, SkPathPriv::kCW_FirstDirection);
1286 platTriangle.reset();
1287 platTriangle.moveTo(0, 0);
1288 platTriangle.lineTo(200, 0);
1289 platTriangle.lineTo(100, 0.03f);
1290 platTriangle.close();
1291 platTriangle.getConvexity();
1292 check_direction(reporter, platTriangle, SkPathPriv::kCW_FirstDirection);
1295 static void test_convexity2(skiatest::Reporter* reporter) {
1299 check_convexity(reporter, pt, SkPath::kConvex_Convexity);
1300 check_direction(reporter, pt, SkPathPriv::kUnknown_FirstDirection);
1303 line.moveTo(12*SK_Scalar1, 20*SK_Scalar1);
1304 line.lineTo(-12*SK_Scalar1, -20*SK_Scalar1);
1306 check_convexity(reporter, line, SkPath::kConvex_Convexity);
1307 check_direction(reporter, line, SkPathPriv::kUnknown_FirstDirection);
1310 triLeft.moveTo(0, 0);
1311 triLeft.lineTo(SK_Scalar1, 0);
1312 triLeft.lineTo(SK_Scalar1, SK_Scalar1);
1314 check_convexity(reporter, triLeft, SkPath::kConvex_Convexity);
1315 check_direction(reporter, triLeft, SkPathPriv::kCW_FirstDirection);
1318 triRight.moveTo(0, 0);
1319 triRight.lineTo(-SK_Scalar1, 0);
1320 triRight.lineTo(SK_Scalar1, SK_Scalar1);
1322 check_convexity(reporter, triRight, SkPath::kConvex_Convexity);
1323 check_direction(reporter, triRight, SkPathPriv::kCCW_FirstDirection);
1326 square.moveTo(0, 0);
1327 square.lineTo(SK_Scalar1, 0);
1328 square.lineTo(SK_Scalar1, SK_Scalar1);
1329 square.lineTo(0, SK_Scalar1);
1331 check_convexity(reporter, square, SkPath::kConvex_Convexity);
1332 check_direction(reporter, square, SkPathPriv::kCW_FirstDirection);
1334 SkPath redundantSquare;
1335 redundantSquare.moveTo(0, 0);
1336 redundantSquare.lineTo(0, 0);
1337 redundantSquare.lineTo(0, 0);
1338 redundantSquare.lineTo(SK_Scalar1, 0);
1339 redundantSquare.lineTo(SK_Scalar1, 0);
1340 redundantSquare.lineTo(SK_Scalar1, 0);
1341 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1342 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1343 redundantSquare.lineTo(SK_Scalar1, SK_Scalar1);
1344 redundantSquare.lineTo(0, SK_Scalar1);
1345 redundantSquare.lineTo(0, SK_Scalar1);
1346 redundantSquare.lineTo(0, SK_Scalar1);
1347 redundantSquare.close();
1348 check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity);
1349 check_direction(reporter, redundantSquare, SkPathPriv::kCW_FirstDirection);
1352 bowTie.moveTo(0, 0);
1353 bowTie.lineTo(0, 0);
1354 bowTie.lineTo(0, 0);
1355 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1356 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1357 bowTie.lineTo(SK_Scalar1, SK_Scalar1);
1358 bowTie.lineTo(SK_Scalar1, 0);
1359 bowTie.lineTo(SK_Scalar1, 0);
1360 bowTie.lineTo(SK_Scalar1, 0);
1361 bowTie.lineTo(0, SK_Scalar1);
1362 bowTie.lineTo(0, SK_Scalar1);
1363 bowTie.lineTo(0, SK_Scalar1);
1365 check_convexity(reporter, bowTie, SkPath::kConcave_Convexity);
1366 check_direction(reporter, bowTie, kDontCheckDir);
1369 spiral.moveTo(0, 0);
1370 spiral.lineTo(100*SK_Scalar1, 0);
1371 spiral.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1372 spiral.lineTo(0, 100*SK_Scalar1);
1373 spiral.lineTo(0, 50*SK_Scalar1);
1374 spiral.lineTo(50*SK_Scalar1, 50*SK_Scalar1);
1375 spiral.lineTo(50*SK_Scalar1, 75*SK_Scalar1);
1377 check_convexity(reporter, spiral, SkPath::kConcave_Convexity);
1378 check_direction(reporter, spiral, kDontCheckDir);
1382 dent.lineTo(100*SK_Scalar1, 100*SK_Scalar1);
1383 dent.lineTo(0, 100*SK_Scalar1);
1384 dent.lineTo(-50*SK_Scalar1, 200*SK_Scalar1);
1385 dent.lineTo(-200*SK_Scalar1, 100*SK_Scalar1);
1387 check_convexity(reporter, dent, SkPath::kConcave_Convexity);
1388 check_direction(reporter, dent, SkPathPriv::kCW_FirstDirection);
1390 // https://bug.skia.org/2235
1392 for (int i = 0; i < 2000; i++) {
1393 SkScalar x = SkIntToScalar(i) / 2;
1394 SkScalar y = 500 - (x + SkScalarSin(x / 100) * 40) / 3;
1396 strokedSin.moveTo(x, y);
1398 strokedSin.lineTo(x, y);
1401 SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle);
1402 stroke.setStrokeStyle(2 * SK_Scalar1);
1403 stroke.applyToPath(&strokedSin, strokedSin);
1404 check_convexity(reporter, strokedSin, SkPath::kConcave_Convexity);
1405 check_direction(reporter, strokedSin, kDontCheckDir);
1407 // http://crbug.com/412640
1408 SkPath degenerateConcave;
1409 degenerateConcave.moveTo(148.67912f, 191.875f);
1410 degenerateConcave.lineTo(470.37695f, 7.5f);
1411 degenerateConcave.lineTo(148.67912f, 191.875f);
1412 degenerateConcave.lineTo(41.446522f, 376.25f);
1413 degenerateConcave.lineTo(-55.971577f, 460.0f);
1414 degenerateConcave.lineTo(41.446522f, 376.25f);
1415 check_convexity(reporter, degenerateConcave, SkPath::kConcave_Convexity);
1416 check_direction(reporter, degenerateConcave, SkPathPriv::kUnknown_FirstDirection);
1418 // http://crbug.com/433683
1419 SkPath badFirstVector;
1420 badFirstVector.moveTo(501.087708f, 319.610352f);
1421 badFirstVector.lineTo(501.087708f, 319.610352f);
1422 badFirstVector.cubicTo(501.087677f, 319.610321f, 449.271606f, 258.078674f, 395.084564f, 198.711182f);
1423 badFirstVector.cubicTo(358.967072f, 159.140717f, 321.910553f, 120.650436f, 298.442322f, 101.955399f);
1424 badFirstVector.lineTo(301.557678f, 98.044601f);
1425 badFirstVector.cubicTo(325.283844f, 116.945084f, 362.615204f, 155.720825f, 398.777557f, 195.340454f);
1426 badFirstVector.cubicTo(453.031860f, 254.781662f, 504.912262f, 316.389618f, 504.912292f, 316.389648f);
1427 badFirstVector.lineTo(504.912292f, 316.389648f);
1428 badFirstVector.lineTo(501.087708f, 319.610352f);
1429 badFirstVector.close();
1430 check_convexity(reporter, badFirstVector, SkPath::kConcave_Convexity);
1433 static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p,
1434 const SkRect& bounds) {
1435 REPORTER_ASSERT(reporter, p.isConvex());
1436 REPORTER_ASSERT(reporter, p.getBounds() == bounds);
1439 REPORTER_ASSERT(reporter, p2.isConvex());
1440 REPORTER_ASSERT(reporter, p2.getBounds() == bounds);
1444 REPORTER_ASSERT(reporter, other.isConvex());
1445 REPORTER_ASSERT(reporter, other.getBounds() == bounds);
1448 static void setFromString(SkPath* path, const char str[]) {
1452 str = SkParse::FindScalar(str, &x);
1453 if (nullptr == str) {
1456 str = SkParse::FindScalar(str, &y);
1467 static void test_convexity(skiatest::Reporter* reporter) {
1470 check_convexity(reporter, path, SkPath::kConvex_Convexity);
1471 path.addCircle(0, 0, SkIntToScalar(10));
1472 check_convexity(reporter, path, SkPath::kConvex_Convexity);
1473 path.addCircle(0, 0, SkIntToScalar(10)); // 2nd circle
1474 check_convexity(reporter, path, SkPath::kConcave_Convexity);
1477 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCCW_Direction);
1478 check_convexity(reporter, path, SkPath::kConvex_Convexity);
1479 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCCW_FirstDirection));
1482 path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCW_Direction);
1483 check_convexity(reporter, path, SkPath::kConvex_Convexity);
1484 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCW_FirstDirection));
1486 static const struct {
1487 const char* fPathStr;
1488 SkPath::Convexity fExpectedConvexity;
1489 SkPathPriv::FirstDirection fExpectedDirection;
1491 { "", SkPath::kConvex_Convexity, SkPathPriv::kUnknown_FirstDirection },
1492 { "0 0", SkPath::kConvex_Convexity, SkPathPriv::kUnknown_FirstDirection },
1493 { "0 0 10 10", SkPath::kConvex_Convexity, SkPathPriv::kUnknown_FirstDirection },
1494 { "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity, SkPathPriv::kUnknown_FirstDirection },
1495 { "0 0 10 10 10 20", SkPath::kConvex_Convexity, SkPathPriv::kCW_FirstDirection },
1496 { "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPathPriv::kCCW_FirstDirection },
1497 { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir },
1498 { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity, SkPathPriv::kCW_FirstDirection },
1501 for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) {
1503 setFromString(&path, gRec[i].fPathStr);
1504 check_convexity(reporter, path, gRec[i].fExpectedConvexity);
1505 check_direction(reporter, path, gRec[i].fExpectedDirection);
1506 // check after setting the initial convex and direction
1507 if (kDontCheckDir != gRec[i].fExpectedDirection) {
1509 SkPathPriv::FirstDirection dir;
1510 bool foundDir = SkPathPriv::CheapComputeFirstDirection(copy, &dir);
1511 REPORTER_ASSERT(reporter, (gRec[i].fExpectedDirection == SkPathPriv::kUnknown_FirstDirection)
1513 REPORTER_ASSERT(reporter, !foundDir || gRec[i].fExpectedDirection == dir);
1514 check_convexity(reporter, copy, gRec[i].fExpectedConvexity);
1516 REPORTER_ASSERT(reporter, gRec[i].fExpectedConvexity == path.getConvexity());
1517 check_direction(reporter, path, gRec[i].fExpectedDirection);
1520 static const SkPoint nonFinitePts[] = {
1521 { SK_ScalarInfinity, 0 },
1522 { 0, SK_ScalarInfinity },
1523 { SK_ScalarInfinity, SK_ScalarInfinity },
1524 { SK_ScalarNegativeInfinity, 0},
1525 { 0, SK_ScalarNegativeInfinity },
1526 { SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity },
1527 { SK_ScalarNegativeInfinity, SK_ScalarInfinity },
1528 { SK_ScalarInfinity, SK_ScalarNegativeInfinity },
1529 { SK_ScalarNaN, 0 },
1530 { 0, SK_ScalarNaN },
1531 { SK_ScalarNaN, SK_ScalarNaN },
1534 const size_t nonFinitePtsCount = sizeof(nonFinitePts) / sizeof(nonFinitePts[0]);
1536 static const SkPoint finitePts[] = {
1537 { SK_ScalarMax, 0 },
1538 { 0, SK_ScalarMax },
1539 { SK_ScalarMax, SK_ScalarMax },
1540 { SK_ScalarMin, 0 },
1541 { 0, SK_ScalarMin },
1542 { SK_ScalarMin, SK_ScalarMin },
1545 const size_t finitePtsCount = sizeof(finitePts) / sizeof(finitePts[0]);
1547 for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount); ++index) {
1548 int i = (int) (index % nonFinitePtsCount);
1549 int f = (int) (index % finitePtsCount);
1550 int g = (int) ((f + 1) % finitePtsCount);
1552 switch (index % 13) {
1553 case 0: path.lineTo(nonFinitePts[i]); break;
1554 case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break;
1555 case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break;
1556 case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break;
1557 case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); break;
1558 case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); break;
1559 case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); break;
1560 case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f]); break;
1561 case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i]); break;
1562 case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i]); break;
1563 case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts[i]); break;
1564 case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]); break;
1565 case 12: path.moveTo(nonFinitePts[i]); break;
1567 check_convexity(reporter, path, SkPath::kUnknown_Convexity);
1570 for (int index = 0; index < (int) (11 * finitePtsCount); ++index) {
1571 int f = (int) (index % finitePtsCount);
1572 int g = (int) ((f + 1) % finitePtsCount);
1574 int curveSelect = index % 11;
1575 switch (curveSelect) {
1576 case 0: path.moveTo(finitePts[f]); break;
1577 case 1: path.lineTo(finitePts[f]); break;
1578 case 2: path.quadTo(finitePts[f], finitePts[f]); break;
1579 case 3: path.quadTo(finitePts[f], finitePts[g]); break;
1580 case 4: path.quadTo(finitePts[g], finitePts[f]); break;
1581 case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); break;
1582 case 6: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); break;
1583 case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); break;
1584 case 8: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); break;
1585 case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); break;
1586 case 10: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); break;
1588 check_convexity(reporter, path, curveSelect == 0 ? SkPath::kConvex_Convexity
1589 : SkPath::kUnknown_Convexity);
1594 static void test_isLine(skiatest::Reporter* reporter) {
1597 const SkScalar value = SkIntToScalar(5);
1599 REPORTER_ASSERT(reporter, !path.isLine(nullptr));
1601 // set some non-zero values
1602 pts[0].set(value, value);
1603 pts[1].set(value, value);
1604 REPORTER_ASSERT(reporter, !path.isLine(pts));
1605 // check that pts was untouched
1606 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1607 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1609 const SkScalar moveX = SkIntToScalar(1);
1610 const SkScalar moveY = SkIntToScalar(2);
1611 REPORTER_ASSERT(reporter, value != moveX && value != moveY);
1613 path.moveTo(moveX, moveY);
1614 REPORTER_ASSERT(reporter, !path.isLine(nullptr));
1615 REPORTER_ASSERT(reporter, !path.isLine(pts));
1616 // check that pts was untouched
1617 REPORTER_ASSERT(reporter, pts[0].equals(value, value));
1618 REPORTER_ASSERT(reporter, pts[1].equals(value, value));
1620 const SkScalar lineX = SkIntToScalar(2);
1621 const SkScalar lineY = SkIntToScalar(2);
1622 REPORTER_ASSERT(reporter, value != lineX && value != lineY);
1624 path.lineTo(lineX, lineY);
1625 REPORTER_ASSERT(reporter, path.isLine(nullptr));
1627 REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY));
1628 REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY));
1629 REPORTER_ASSERT(reporter, path.isLine(pts));
1630 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1631 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
1633 path.lineTo(0, 0); // too many points/verbs
1634 REPORTER_ASSERT(reporter, !path.isLine(nullptr));
1635 REPORTER_ASSERT(reporter, !path.isLine(pts));
1636 REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY));
1637 REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY));
1640 path.quadTo(1, 1, 2, 2);
1641 REPORTER_ASSERT(reporter, !path.isLine(nullptr));
1644 static void test_conservativelyContains(skiatest::Reporter* reporter) {
1647 // kBaseRect is used to construct most our test paths: a rect, a circle, and a round-rect.
1648 static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100));
1650 // A circle that bounds kBaseRect (with a significant amount of slop)
1651 SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height());
1652 circleR = SkScalarMul(circleR, 1.75f) / 2;
1653 static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()};
1656 static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)};
1658 static const struct SUPPRESS_VISIBILITY_WARNING {
1665 {kBaseRect, true, true, false, false},
1667 // rect well inside of kBaseRect
1668 {SkRect::MakeLTRB(kBaseRect.fLeft + 0.25f*kBaseRect.width(),
1669 kBaseRect.fTop + 0.25f*kBaseRect.height(),
1670 kBaseRect.fRight - 0.25f*kBaseRect.width(),
1671 kBaseRect.fBottom - 0.25f*kBaseRect.height()),
1672 true, true, true, true},
1674 // rects with edges off by one from kBaseRect's edges
1675 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1676 kBaseRect.width(), kBaseRect.height() + 1),
1677 false, true, false, false},
1678 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1679 kBaseRect.width() + 1, kBaseRect.height()),
1680 false, true, false, false},
1681 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop,
1682 kBaseRect.width() + 1, kBaseRect.height() + 1),
1683 false, true, false, false},
1684 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1685 kBaseRect.width(), kBaseRect.height()),
1686 false, true, false, false},
1687 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1688 kBaseRect.width(), kBaseRect.height()),
1689 false, true, false, false},
1690 {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop,
1691 kBaseRect.width() + 2, kBaseRect.height()),
1692 false, true, false, false},
1693 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1,
1694 kBaseRect.width() + 2, kBaseRect.height()),
1695 false, true, false, false},
1697 // zero-w/h rects at each corner of kBaseRect
1698 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, false, false},
1699 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, false, true},
1700 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true, false, true},
1701 {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true, false, true},
1704 {SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom,
1705 SkIntToScalar(10), SkIntToScalar(10)),
1706 false, false, false, false},
1708 // very large rect containing kBaseRect
1709 {SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(),
1710 kBaseRect.fTop - 5 * kBaseRect.height(),
1711 11 * kBaseRect.width(), 11 * kBaseRect.height()),
1712 false, false, false, false},
1714 // skinny rect that spans same y-range as kBaseRect
1715 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1716 SkIntToScalar(1), kBaseRect.height()),
1717 true, true, true, true},
1719 // short rect that spans same x-range as kBaseRect
1720 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(), SkScalar(1)),
1721 true, true, true, true},
1723 // skinny rect that spans slightly larger y-range than kBaseRect
1724 {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop,
1725 SkIntToScalar(1), kBaseRect.height() + 1),
1726 false, true, false, false},
1728 // short rect that spans slightly larger x-range than kBaseRect
1729 {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(),
1730 kBaseRect.width() + 1, SkScalar(1)),
1731 false, true, false, false},
1734 for (int inv = 0; inv < 4; ++inv) {
1735 for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) {
1736 SkRect qRect = kQueries[q].fQueryRect;
1738 SkTSwap(qRect.fLeft, qRect.fRight);
1741 SkTSwap(qRect.fTop, qRect.fBottom);
1743 for (int d = 0; d < 2; ++d) {
1744 SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW_Direction;
1746 path.addRect(kBaseRect, dir);
1747 REPORTER_ASSERT(reporter, kQueries[q].fInRect ==
1748 path.conservativelyContainsRect(qRect));
1751 path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir);
1752 REPORTER_ASSERT(reporter, kQueries[q].fInCircle ==
1753 path.conservativelyContainsRect(qRect));
1756 path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir);
1757 REPORTER_ASSERT(reporter, kQueries[q].fInRR ==
1758 path.conservativelyContainsRect(qRect));
1761 path.moveTo(kBaseRect.fLeft + kRRRadii[0], kBaseRect.fTop);
1762 path.cubicTo(kBaseRect.fLeft + kRRRadii[0] / 2, kBaseRect.fTop,
1763 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1] / 2,
1764 kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1]);
1765 path.lineTo(kBaseRect.fLeft, kBaseRect.fBottom);
1766 path.lineTo(kBaseRect.fRight, kBaseRect.fBottom);
1767 path.lineTo(kBaseRect.fRight, kBaseRect.fTop);
1769 REPORTER_ASSERT(reporter, kQueries[q].fInCubicRR ==
1770 path.conservativelyContainsRect(qRect));
1773 // Slightly non-convex shape, shouldn't contain any rects.
1776 path.lineTo(SkIntToScalar(50), 0.05f);
1777 path.lineTo(SkIntToScalar(100), 0);
1778 path.lineTo(SkIntToScalar(100), SkIntToScalar(100));
1779 path.lineTo(0, SkIntToScalar(100));
1781 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect));
1785 // make sure a minimal convex shape works, a right tri with edges along pos x and y axes.
1788 path.lineTo(SkIntToScalar(100), 0);
1789 path.lineTo(0, SkIntToScalar(100));
1791 // inside, on along top edge
1792 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1794 SkIntToScalar(10))));
1796 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1797 SkRect::MakeXYWH(SkIntToScalar(50),
1800 SkIntToScalar(10))));
1802 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(-10),
1805 SkIntToScalar(5))));
1807 // outside the diagonal edge
1808 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(10),
1811 SkIntToScalar(5))));
1814 // Test that multiple move commands do not cause asserts.
1816 // At the time of writing, this would not modify cached convexity. This caused an assert while
1817 // checking conservative containment again. https://bug.skia.org/1460
1818 path.moveTo(SkIntToScalar(100), SkIntToScalar(100));
1820 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1822 SkIntToScalar(10))));
1825 // Same as above path and first test but with an extra moveTo.
1827 path.moveTo(100, 100);
1829 path.lineTo(SkIntToScalar(100), 0);
1830 path.lineTo(0, SkIntToScalar(100));
1832 REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0,
1834 SkIntToScalar(10))));
1836 // Test that multiple move commands do not cause asserts and that the function
1837 // is not confused by the multiple moves.
1840 path.lineTo(SkIntToScalar(100), 0);
1841 path.lineTo(0, SkIntToScalar(100));
1842 path.moveTo(0, SkIntToScalar(200));
1843 path.lineTo(SkIntToScalar(100), SkIntToScalar(200));
1844 path.lineTo(0, SkIntToScalar(300));
1846 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(
1847 SkRect::MakeXYWH(SkIntToScalar(50), 0,
1849 SkIntToScalar(10))));
1852 path.lineTo(100, 100);
1853 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(0, 0, 1, 1)));
1856 static void test_isRect_open_close(skiatest::Reporter* reporter) {
1860 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1);
1863 REPORTER_ASSERT(reporter, path.isRect(nullptr, &isClosed, nullptr));
1864 REPORTER_ASSERT(reporter, isClosed);
1867 // Simple isRect test is inline TestPath, below.
1868 // test_isRect provides more extensive testing.
1869 static void test_isRect(skiatest::Reporter* reporter) {
1870 test_isRect_open_close(reporter);
1872 // passing tests (all moveTo / lineTo...
1873 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1874 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
1875 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
1876 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
1877 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}};
1878 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1879 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
1880 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
1881 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
1882 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}};
1883 SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, {0, 1}, {0, .5f}};
1884 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}};
1885 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}};
1886 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}};
1887 SkPoint rf[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}};
1890 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
1891 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
1892 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
1893 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
1894 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
1895 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
1896 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
1897 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
1898 SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps
1899 SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non colinear gap
1900 SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short
1902 // no close, but we should detect them as fillably the same as a rect
1903 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}};
1904 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}};
1905 SkPoint c3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 0}}; // hit the start
1907 // like c2, but we double-back on ourselves
1908 SkPoint d1[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 2}};
1909 // like c2, but we overshoot the start point
1910 SkPoint d2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}};
1911 SkPoint d3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}, {0, 0}};
1919 { r1, SK_ARRAY_COUNT(r1), true, true },
1920 { r2, SK_ARRAY_COUNT(r2), true, true },
1921 { r3, SK_ARRAY_COUNT(r3), true, true },
1922 { r4, SK_ARRAY_COUNT(r4), true, true },
1923 { r5, SK_ARRAY_COUNT(r5), true, true },
1924 { r6, SK_ARRAY_COUNT(r6), true, true },
1925 { r7, SK_ARRAY_COUNT(r7), true, true },
1926 { r8, SK_ARRAY_COUNT(r8), true, true },
1927 { r9, SK_ARRAY_COUNT(r9), true, true },
1928 { ra, SK_ARRAY_COUNT(ra), true, true },
1929 { rb, SK_ARRAY_COUNT(rb), true, true },
1930 { rc, SK_ARRAY_COUNT(rc), true, true },
1931 { rd, SK_ARRAY_COUNT(rd), true, true },
1932 { re, SK_ARRAY_COUNT(re), true, true },
1933 { rf, SK_ARRAY_COUNT(rf), true, true },
1935 { f1, SK_ARRAY_COUNT(f1), true, false },
1936 { f2, SK_ARRAY_COUNT(f2), true, false },
1937 { f3, SK_ARRAY_COUNT(f3), true, false },
1938 { f4, SK_ARRAY_COUNT(f4), true, false },
1939 { f5, SK_ARRAY_COUNT(f5), true, false },
1940 { f6, SK_ARRAY_COUNT(f6), true, false },
1941 { f7, SK_ARRAY_COUNT(f7), true, false },
1942 { f8, SK_ARRAY_COUNT(f8), true, false },
1943 { f9, SK_ARRAY_COUNT(f9), true, false },
1944 { fa, SK_ARRAY_COUNT(fa), true, false },
1945 { fb, SK_ARRAY_COUNT(fb), true, false },
1947 { c1, SK_ARRAY_COUNT(c1), false, true },
1948 { c2, SK_ARRAY_COUNT(c2), false, true },
1949 { c3, SK_ARRAY_COUNT(c3), false, true },
1951 { d1, SK_ARRAY_COUNT(d1), false, false },
1952 { d2, SK_ARRAY_COUNT(d2), false, false },
1953 { d3, SK_ARRAY_COUNT(d3), false, false },
1956 const size_t testCount = SK_ARRAY_COUNT(tests);
1958 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
1960 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
1961 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
1962 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
1964 if (tests[testIndex].fClose) {
1967 REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(nullptr));
1969 if (tests[testIndex].fIsRect) {
1970 SkRect computed, expected;
1972 SkPath::Direction direction;
1973 SkPathPriv::FirstDirection cheapDirection;
1974 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
1975 REPORTER_ASSERT(reporter, SkPathPriv::CheapComputeFirstDirection(path, &cheapDirection));
1976 REPORTER_ASSERT(reporter, path.isRect(&computed, &isClosed, &direction));
1977 REPORTER_ASSERT(reporter, expected == computed);
1978 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose);
1979 REPORTER_ASSERT(reporter, SkPathPriv::AsFirstDirection(direction) == cheapDirection);
1982 computed.set(123, 456, 789, 1011);
1983 bool isClosed = (bool)-1;
1984 SkPath::Direction direction = (SkPath::Direction) - 1;
1985 REPORTER_ASSERT(reporter, !path.isRect(&computed, &isClosed, &direction));
1986 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456);
1987 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011);
1988 REPORTER_ASSERT(reporter, isClosed == (bool) -1);
1989 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1);
1993 // fail, close then line
1995 path1.moveTo(r1[0].fX, r1[0].fY);
1996 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
1997 path1.lineTo(r1[index].fX, r1[index].fY);
2001 REPORTER_ASSERT(reporter, !path1.isRect(nullptr));
2003 // fail, move in the middle
2005 path1.moveTo(r1[0].fX, r1[0].fY);
2006 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
2008 path1.moveTo(1, .5f);
2010 path1.lineTo(r1[index].fX, r1[index].fY);
2013 REPORTER_ASSERT(reporter, !path1.isRect(nullptr));
2015 // fail, move on the edge
2017 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
2018 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
2019 path1.lineTo(r1[index].fX, r1[index].fY);
2022 REPORTER_ASSERT(reporter, !path1.isRect(nullptr));
2026 path1.moveTo(r1[0].fX, r1[0].fY);
2027 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
2029 path1.quadTo(1, .5f, 1, .5f);
2031 path1.lineTo(r1[index].fX, r1[index].fY);
2034 REPORTER_ASSERT(reporter, !path1.isRect(nullptr));
2038 path1.moveTo(r1[0].fX, r1[0].fY);
2039 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
2041 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
2043 path1.lineTo(r1[index].fX, r1[index].fY);
2046 REPORTER_ASSERT(reporter, !path1.isRect(nullptr));
2049 static void check_simple_closed_rect(skiatest::Reporter* reporter, const SkPath& path,
2050 const SkRect& rect, SkPath::Direction dir, unsigned start) {
2051 SkRect r = SkRect::MakeEmpty();
2052 SkPath::Direction d = SkPath::kCCW_Direction;
2055 REPORTER_ASSERT(reporter, SkPathPriv::IsSimpleClosedRect(path, &r, &d, &s));
2056 REPORTER_ASSERT(reporter, r == rect);
2057 REPORTER_ASSERT(reporter, d == dir);
2058 REPORTER_ASSERT(reporter, s == start);
2061 static void test_is_simple_closed_rect(skiatest::Reporter* reporter) {
2062 SkRect r = SkRect::MakeEmpty();
2063 SkPath::Direction d = SkPath::kCCW_Direction;
2066 const SkRect testRect = SkRect::MakeXYWH(10, 10, 50, 70);
2067 const SkRect emptyRect = SkRect::MakeEmpty();
2069 for (int start = 0; start < 4; ++start) {
2070 for (auto dir : {SkPath::kCCW_Direction, SkPath::kCW_Direction}) {
2072 path.addRect(testRect, dir, start);
2073 check_simple_closed_rect(reporter, path, testRect, dir, start);
2075 check_simple_closed_rect(reporter, path, testRect, dir, start);
2076 SkPath path2 = path;
2077 path2.lineTo(10, 10);
2078 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2080 path2.moveTo(10, 10);
2081 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2083 path2.addRect(testRect, dir, start);
2084 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2085 // Make the path by hand, manually closing it.
2087 SkPath::RawIter iter(path);
2090 SkPoint firstPt = {0.f, 0.f};
2091 while ((v = iter.next(verbPts)) != SkPath::kDone_Verb) {
2093 case SkPath::kMove_Verb:
2094 firstPt = verbPts[0];
2095 path2.moveTo(verbPts[0]);
2097 case SkPath::kLine_Verb:
2098 path2.lineTo(verbPts[1]);
2104 // We haven't closed it yet...
2105 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2106 // ... now we do and test again.
2107 path2.lineTo(firstPt);
2108 check_simple_closed_rect(reporter, path2, testRect, dir, start);
2109 // A redundant close shouldn't cause a failure.
2111 check_simple_closed_rect(reporter, path2, testRect, dir, start);
2112 // Degenerate point and line rects are not allowed
2114 path2.addRect(emptyRect, dir, start);
2115 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2116 SkRect degenRect = testRect;
2117 degenRect.fLeft = degenRect.fRight;
2119 path2.addRect(degenRect, dir, start);
2120 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2121 degenRect = testRect;
2122 degenRect.fTop = degenRect.fBottom;
2124 path2.addRect(degenRect, dir, start);
2125 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s));
2126 // An inverted rect makes a rect path, but changes the winding dir and start point.
2127 SkPath::Direction swapDir = (dir == SkPath::kCW_Direction)
2128 ? SkPath::kCCW_Direction
2129 : SkPath::kCW_Direction;
2130 static constexpr unsigned kXSwapStarts[] = { 1, 0, 3, 2 };
2131 static constexpr unsigned kYSwapStarts[] = { 3, 2, 1, 0 };
2132 SkRect swapRect = testRect;
2133 SkTSwap(swapRect.fLeft, swapRect.fRight);
2135 path2.addRect(swapRect, dir, start);
2136 check_simple_closed_rect(reporter, path2, testRect, swapDir, kXSwapStarts[start]);
2137 swapRect = testRect;
2138 SkTSwap(swapRect.fTop, swapRect.fBottom);
2140 path2.addRect(swapRect, dir, start);
2141 check_simple_closed_rect(reporter, path2, testRect, swapDir, kYSwapStarts[start]);
2144 // down, up, left, close
2151 SkPath::Direction dir;
2154 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path, &rect, &dir, &start));
2155 // right, left, up, close
2162 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path, &rect, &dir, &start));
2163 // parallelogram with horizontal edges
2170 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path, &rect, &dir, &start));
2171 // parallelogram with vertical edges
2178 REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path, &rect, &dir, &start));
2182 static void test_isNestedFillRects(skiatest::Reporter* reporter) {
2183 // passing tests (all moveTo / lineTo...
2184 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
2185 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}};
2186 SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}};
2187 SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}};
2188 SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW
2189 SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
2190 SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}};
2191 SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}};
2192 SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}};
2193 SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; // CCW
2194 SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, {0, 1}, {0, .5f}}; // CW
2195 SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW
2196 SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW
2197 SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW
2200 SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points
2201 SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal
2202 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps
2203 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up
2204 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots
2205 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots
2206 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots
2207 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L'
2209 // success, no close is OK
2210 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match
2211 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto
2213 struct IsNestedRectTest {
2216 SkPathPriv::FirstDirection fDirection;
2218 bool fIsNestedRect; // nests with path.addRect(-1, -1, 2, 2);
2220 { r1, SK_ARRAY_COUNT(r1), SkPathPriv::kCW_FirstDirection , true, true },
2221 { r2, SK_ARRAY_COUNT(r2), SkPathPriv::kCW_FirstDirection , true, true },
2222 { r3, SK_ARRAY_COUNT(r3), SkPathPriv::kCW_FirstDirection , true, true },
2223 { r4, SK_ARRAY_COUNT(r4), SkPathPriv::kCW_FirstDirection , true, true },
2224 { r5, SK_ARRAY_COUNT(r5), SkPathPriv::kCCW_FirstDirection, true, true },
2225 { r6, SK_ARRAY_COUNT(r6), SkPathPriv::kCCW_FirstDirection, true, true },
2226 { r7, SK_ARRAY_COUNT(r7), SkPathPriv::kCCW_FirstDirection, true, true },
2227 { r8, SK_ARRAY_COUNT(r8), SkPathPriv::kCCW_FirstDirection, true, true },
2228 { r9, SK_ARRAY_COUNT(r9), SkPathPriv::kCCW_FirstDirection, true, true },
2229 { ra, SK_ARRAY_COUNT(ra), SkPathPriv::kCCW_FirstDirection, true, true },
2230 { rb, SK_ARRAY_COUNT(rb), SkPathPriv::kCW_FirstDirection, true, true },
2231 { rc, SK_ARRAY_COUNT(rc), SkPathPriv::kCW_FirstDirection, true, true },
2232 { rd, SK_ARRAY_COUNT(rd), SkPathPriv::kCCW_FirstDirection, true, true },
2233 { re, SK_ARRAY_COUNT(re), SkPathPriv::kCW_FirstDirection, true, true },
2235 { f1, SK_ARRAY_COUNT(f1), SkPathPriv::kUnknown_FirstDirection, true, false },
2236 { f2, SK_ARRAY_COUNT(f2), SkPathPriv::kUnknown_FirstDirection, true, false },
2237 { f3, SK_ARRAY_COUNT(f3), SkPathPriv::kUnknown_FirstDirection, true, false },
2238 { f4, SK_ARRAY_COUNT(f4), SkPathPriv::kUnknown_FirstDirection, true, false },
2239 { f5, SK_ARRAY_COUNT(f5), SkPathPriv::kUnknown_FirstDirection, true, false },
2240 { f6, SK_ARRAY_COUNT(f6), SkPathPriv::kUnknown_FirstDirection, true, false },
2241 { f7, SK_ARRAY_COUNT(f7), SkPathPriv::kUnknown_FirstDirection, true, false },
2242 { f8, SK_ARRAY_COUNT(f8), SkPathPriv::kUnknown_FirstDirection, true, false },
2244 { c1, SK_ARRAY_COUNT(c1), SkPathPriv::kCW_FirstDirection, false, true },
2245 { c2, SK_ARRAY_COUNT(c2), SkPathPriv::kCW_FirstDirection, false, true },
2248 const size_t testCount = SK_ARRAY_COUNT(tests);
2250 for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) {
2251 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) {
2254 path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2256 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY);
2257 for (index = 1; index < tests[testIndex].fPointCount; ++index) {
2258 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY);
2260 if (tests[testIndex].fClose) {
2264 path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2266 REPORTER_ASSERT(reporter,
2267 tests[testIndex].fIsNestedRect == path.isNestedFillRects(nullptr));
2268 if (tests[testIndex].fIsNestedRect) {
2269 SkRect expected[2], computed[2];
2270 SkPathPriv::FirstDirection expectedDirs[2];
2271 SkPath::Direction computedDirs[2];
2273 testBounds.set(tests[testIndex].fPoints, tests[testIndex].fPointCount);
2274 expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2);
2275 expected[1] = testBounds;
2277 expectedDirs[0] = SkPathPriv::kCW_FirstDirection;
2279 expectedDirs[0] = SkPathPriv::kCCW_FirstDirection;
2281 expectedDirs[1] = tests[testIndex].fDirection;
2282 REPORTER_ASSERT(reporter, path.isNestedFillRects(computed, computedDirs));
2283 REPORTER_ASSERT(reporter, expected[0] == computed[0]);
2284 REPORTER_ASSERT(reporter, expected[1] == computed[1]);
2285 REPORTER_ASSERT(reporter, expectedDirs[0] == SkPathPriv::AsFirstDirection(computedDirs[0]));
2286 REPORTER_ASSERT(reporter, expectedDirs[1] == SkPathPriv::AsFirstDirection(computedDirs[1]));
2290 // fail, close then line
2293 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2295 path1.moveTo(r1[0].fX, r1[0].fY);
2296 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
2297 path1.lineTo(r1[index].fX, r1[index].fY);
2302 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2304 REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr));
2306 // fail, move in the middle
2309 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2311 path1.moveTo(r1[0].fX, r1[0].fY);
2312 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
2314 path1.moveTo(1, .5f);
2316 path1.lineTo(r1[index].fX, r1[index].fY);
2320 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2322 REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr));
2324 // fail, move on the edge
2327 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2329 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
2330 path1.moveTo(r1[index - 1].fX, r1[index - 1].fY);
2331 path1.lineTo(r1[index].fX, r1[index].fY);
2335 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2337 REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr));
2342 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2344 path1.moveTo(r1[0].fX, r1[0].fY);
2345 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
2347 path1.quadTo(1, .5f, 1, .5f);
2349 path1.lineTo(r1[index].fX, r1[index].fY);
2353 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2355 REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr));
2360 path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction);
2362 path1.moveTo(r1[0].fX, r1[0].fY);
2363 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) {
2365 path1.cubicTo(1, .5f, 1, .5f, 1, .5f);
2367 path1.lineTo(r1[index].fX, r1[index].fY);
2371 path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction);
2373 REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr));
2377 path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction);
2378 path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction);
2379 REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr));
2382 // pass, constructed explicitly from manually closed rects specified as moves/lines.
2386 path.lineTo(10, 10);
2394 REPORTER_ASSERT(reporter, path.isNestedFillRects(nullptr));
2396 // pass, stroke rect
2398 src.addRect(1, 1, 7, 7, SkPath::kCW_Direction);
2399 SkPaint strokePaint;
2400 strokePaint.setStyle(SkPaint::kStroke_Style);
2401 strokePaint.setStrokeWidth(2);
2402 strokePaint.getFillPath(src, &dst);
2403 REPORTER_ASSERT(reporter, dst.isNestedFillRects(nullptr));
2406 static void write_and_read_back(skiatest::Reporter* reporter,
2409 writer.writePath(p);
2410 size_t size = writer.bytesWritten();
2411 SkAutoMalloc storage(size);
2412 writer.flatten(storage.get());
2413 SkReader32 reader(storage.get(), size);
2416 REPORTER_ASSERT(reporter, readBack != p);
2417 reader.readPath(&readBack);
2418 REPORTER_ASSERT(reporter, readBack == p);
2420 REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() ==
2421 p.getConvexityOrUnknown());
2423 SkRect oval0, oval1;
2424 SkPath::Direction dir0, dir1;
2425 unsigned start0, start1;
2426 REPORTER_ASSERT(reporter, readBack.isOval(nullptr) == p.isOval(nullptr));
2427 if (p.isOval(&oval0, &dir0, &start0) && readBack.isOval(&oval1, &dir1, &start1)) {
2428 REPORTER_ASSERT(reporter, oval0 == oval1);
2429 REPORTER_ASSERT(reporter, dir0 == dir1);
2430 REPORTER_ASSERT(reporter, start0 == start1);
2432 REPORTER_ASSERT(reporter, readBack.isRRect(nullptr) == p.isRRect(nullptr));
2433 SkRRect rrect0, rrect1;
2434 if (p.isRRect(&rrect0, &dir0, &start0) && readBack.isRRect(&rrect1, &dir1, &start1)) {
2435 REPORTER_ASSERT(reporter, rrect0 == rrect1);
2436 REPORTER_ASSERT(reporter, dir0 == dir1);
2437 REPORTER_ASSERT(reporter, start0 == start1);
2439 const SkRect& origBounds = p.getBounds();
2440 const SkRect& readBackBounds = readBack.getBounds();
2442 REPORTER_ASSERT(reporter, origBounds == readBackBounds);
2445 static void test_flattening(skiatest::Reporter* reporter) {
2448 static const SkPoint pts[] = {
2450 { SkIntToScalar(10), SkIntToScalar(10) },
2451 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 },
2452 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }
2456 p.quadTo(pts[2], pts[3]);
2457 p.cubicTo(pts[4], pts[5], pts[6]);
2459 write_and_read_back(reporter, p);
2461 // create a buffer that should be much larger than the path so we don't
2462 // kill our stack if writer goes too far.
2464 size_t size1 = p.writeToMemory(nullptr);
2465 size_t size2 = p.writeToMemory(buffer);
2466 REPORTER_ASSERT(reporter, size1 == size2);
2469 size_t size3 = p2.readFromMemory(buffer, 1024);
2470 REPORTER_ASSERT(reporter, size1 == size3);
2471 REPORTER_ASSERT(reporter, p == p2);
2473 size3 = p2.readFromMemory(buffer, 0);
2474 REPORTER_ASSERT(reporter, !size3);
2477 size3 = tooShort.readFromMemory(buffer, size1 - 1);
2478 REPORTER_ASSERT(reporter, tooShort.isEmpty());
2481 size3 = p2.writeToMemory(buffer2);
2482 REPORTER_ASSERT(reporter, size1 == size3);
2483 REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);
2485 // test persistence of the oval flag & convexity
2488 SkRect rect = SkRect::MakeWH(10, 10);
2491 write_and_read_back(reporter, oval);
2495 static void test_transform(skiatest::Reporter* reporter) {
2498 #define CONIC_PERSPECTIVE_BUG_FIXED 0
2499 static const SkPoint pts[] = {
2501 { SkIntToScalar(10), SkIntToScalar(10) }, // line
2502 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, // quad
2503 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }, // cubic
2504 #if CONIC_PERSPECTIVE_BUG_FIXED
2505 { 0, 0 }, { SkIntToScalar(20), SkIntToScalar(10) }, // conic
2508 const int kPtCount = SK_ARRAY_COUNT(pts);
2512 p.quadTo(pts[2], pts[3]);
2513 p.cubicTo(pts[4], pts[5], pts[6]);
2514 #if CONIC_PERSPECTIVE_BUG_FIXED
2515 p.conicTo(pts[4], pts[5], 0.5f);
2523 p.transform(matrix, &p1);
2524 REPORTER_ASSERT(reporter, p == p1);
2530 matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3);
2532 SkPath p1; // Leave p1 non-unique (i.e., the empty path)
2534 p.transform(matrix, &p1);
2535 SkPoint pts1[kPtCount];
2536 int count = p1.getPoints(pts1, kPtCount);
2537 REPORTER_ASSERT(reporter, kPtCount == count);
2538 for (int i = 0; i < count; ++i) {
2539 SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3);
2540 REPORTER_ASSERT(reporter, newPt == pts1[i]);
2547 matrix.setPerspX(4);
2550 p1.moveTo(SkPoint::Make(0, 0));
2552 p.transform(matrix, &p1);
2553 REPORTER_ASSERT(reporter, matrix.invert(&matrix));
2554 p1.transform(matrix, nullptr);
2555 SkRect pBounds = p.getBounds();
2556 SkRect p1Bounds = p1.getBounds();
2557 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fLeft, p1Bounds.fLeft));
2558 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fTop, p1Bounds.fTop));
2559 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fRight, p1Bounds.fRight));
2560 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fBottom, p1Bounds.fBottom));
2564 p.addCircle(0, 0, 1, SkPath::kCW_Direction);
2570 p1.moveTo(SkPoint::Make(0, 0));
2572 p.transform(matrix, &p1);
2573 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p1, SkPathPriv::kCW_FirstDirection));
2580 matrix.setScaleX(-1);
2582 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
2584 p.transform(matrix, &p1);
2585 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p1, SkPathPriv::kCCW_FirstDirection));
2590 matrix.setAll(1, 1, 0, 1, 1, 0, 0, 0, 1);
2592 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path)
2594 p.transform(matrix, &p1);
2595 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p1, SkPathPriv::kUnknown_FirstDirection));
2599 static void test_zero_length_paths(skiatest::Reporter* reporter) {
2603 struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData {
2604 const char* testPath;
2605 const size_t numResultPts;
2606 const SkRect resultBound;
2607 const SkPath::Verb* resultVerbs;
2608 const size_t numResultVerbs;
2611 static const SkPath::Verb resultVerbs1[] = { SkPath::kMove_Verb };
2612 static const SkPath::Verb resultVerbs2[] = { SkPath::kMove_Verb, SkPath::kMove_Verb };
2613 static const SkPath::Verb resultVerbs3[] = { SkPath::kMove_Verb, SkPath::kClose_Verb };
2614 static const SkPath::Verb resultVerbs4[] = { SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb };
2615 static const SkPath::Verb resultVerbs5[] = { SkPath::kMove_Verb, SkPath::kLine_Verb };
2616 static const SkPath::Verb resultVerbs6[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb };
2617 static const SkPath::Verb resultVerbs7[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb };
2618 static const SkPath::Verb resultVerbs8[] = {
2619 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb
2621 static const SkPath::Verb resultVerbs9[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb };
2622 static const SkPath::Verb resultVerbs10[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb };
2623 static const SkPath::Verb resultVerbs11[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb };
2624 static const SkPath::Verb resultVerbs12[] = {
2625 SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb
2627 static const SkPath::Verb resultVerbs13[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb };
2628 static const SkPath::Verb resultVerbs14[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb };
2629 static const SkPath::Verb resultVerbs15[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb };
2630 static const SkPath::Verb resultVerbs16[] = {
2631 SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb
2633 static const struct zeroPathTestData gZeroLengthTests[] = {
2634 { "M 1 1", 1, {1, 1, 1, 1}, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2635 { "M 1 1 M 2 1", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
2636 { "M 1 1 z", 1, {1, 1, 1, 1}, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
2637 { "M 1 1 z M 2 1 z", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
2638 { "M 1 1 L 1 1", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) },
2639 { "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) },
2640 { "M 1 1 L 1 1 z", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs7, SK_ARRAY_COUNT(resultVerbs7) },
2641 { "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) },
2642 { "M 1 1 Q 1 1 1 1", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs9, SK_ARRAY_COUNT(resultVerbs9) },
2643 { "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) },
2644 { "M 1 1 Q 1 1 1 1 z", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs11, SK_ARRAY_COUNT(resultVerbs11) },
2645 { "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) },
2646 { "M 1 1 C 1 1 1 1 1 1", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs13, SK_ARRAY_COUNT(resultVerbs13) },
2647 { "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,
2648 SK_ARRAY_COUNT(resultVerbs14)
2650 { "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) },
2651 { "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,
2652 SK_ARRAY_COUNT(resultVerbs16)
2656 for (size_t i = 0; i < SK_ARRAY_COUNT(gZeroLengthTests); ++i) {
2658 bool valid = SkParsePath::FromSVGString(gZeroLengthTests[i].testPath, &p);
2659 REPORTER_ASSERT(reporter, valid);
2660 REPORTER_ASSERT(reporter, !p.isEmpty());
2661 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultPts == (size_t)p.countPoints());
2662 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultBound == p.getBounds());
2663 REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultVerbs == (size_t)p.getVerbs(verbs, SK_ARRAY_COUNT(verbs)));
2664 for (size_t j = 0; j < gZeroLengthTests[i].numResultVerbs; ++j) {
2665 REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultVerbs[j] == verbs[j]);
2670 struct SegmentInfo {
2675 #define kCurveSegmentMask (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask)
2677 static void test_segment_masks(skiatest::Reporter* reporter) {
2681 p.quadTo(100, 100, 200, 200);
2682 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == p.getSegmentMasks());
2683 REPORTER_ASSERT(reporter, !p.isEmpty());
2685 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
2686 p.cubicTo(100, 100, 200, 200, 300, 300);
2687 REPORTER_ASSERT(reporter, kCurveSegmentMask == p.getSegmentMasks());
2688 REPORTER_ASSERT(reporter, !p.isEmpty());
2690 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
2694 p.cubicTo(100, 100, 200, 200, 300, 300);
2695 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == p.getSegmentMasks());
2697 REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks());
2699 REPORTER_ASSERT(reporter, !p.isEmpty());
2702 static void test_iter(skiatest::Reporter* reporter) {
2706 // Test an iterator with no path
2707 SkPath::Iter noPathIter;
2708 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
2710 // Test that setting an empty path works
2711 noPathIter.setPath(p, false);
2712 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
2714 // Test that close path makes no difference for an empty path
2715 noPathIter.setPath(p, true);
2716 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
2718 // Test an iterator with an initial empty path
2719 SkPath::Iter iter(p, false);
2720 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2722 // Test that close path makes no difference
2723 iter.setPath(p, true);
2724 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2727 struct iterTestData {
2728 const char* testPath;
2729 const bool forceClose;
2730 const bool consumeDegenerates;
2731 const size_t* numResultPtsPerVerb;
2732 const SkPoint* resultPts;
2733 const SkPath::Verb* resultVerbs;
2734 const size_t numResultVerbs;
2737 static const SkPath::Verb resultVerbs1[] = { SkPath::kDone_Verb };
2738 static const SkPath::Verb resultVerbs2[] = {
2739 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kDone_Verb
2741 static const SkPath::Verb resultVerbs3[] = {
2742 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2744 static const SkPath::Verb resultVerbs4[] = {
2745 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2747 static const SkPath::Verb resultVerbs5[] = {
2748 SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb
2750 static const size_t resultPtsSizes1[] = { 0 };
2751 static const size_t resultPtsSizes2[] = { 1, 2, 2, 0 };
2752 static const size_t resultPtsSizes3[] = { 1, 2, 2, 2, 1, 0 };
2753 static const size_t resultPtsSizes4[] = { 1, 2, 1, 1, 0 };
2754 static const size_t resultPtsSizes5[] = { 1, 2, 1, 1, 1, 0 };
2755 static const SkPoint* resultPts1 = 0;
2756 static const SkPoint resultPts2[] = {
2757 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 }
2759 static const SkPoint resultPts3[] = {
2760 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 },
2761 { 0, SK_Scalar1 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }
2763 static const SkPoint resultPts4[] = {
2764 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
2766 static const SkPoint resultPts5[] = {
2767 { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 }
2769 static const struct iterTestData gIterTests[] = {
2770 { "M 1 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2771 { "M 1 0 M 2 0 M 3 0 M 4 0 M 5 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2772 { "M 1 0 M 1 0 M 3 0 M 4 0 M 5 0", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2773 { "z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2774 { "z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2775 { "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) },
2776 { "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) },
2777 { "M 1 0 L 1 1 L 0 1 M 0 0 z", false, true, resultPtsSizes2, resultPts2, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) },
2778 { "M 1 0 L 1 1 L 0 1 M 0 0 z", true, true, resultPtsSizes3, resultPts3, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) },
2779 { "M 1 0 L 1 0 M 0 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2780 { "M 1 0 L 1 0 M 0 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) },
2781 { "M 1 0 L 1 0 M 0 0 z", false, false, resultPtsSizes4, resultPts4, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) },
2782 { "M 1 0 L 1 0 M 0 0 z", true, false, resultPtsSizes5, resultPts5, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) }
2785 for (size_t i = 0; i < SK_ARRAY_COUNT(gIterTests); ++i) {
2787 bool valid = SkParsePath::FromSVGString(gIterTests[i].testPath, &p);
2788 REPORTER_ASSERT(reporter, valid);
2789 iter.setPath(p, gIterTests[i].forceClose);
2792 REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegenerates) == gIterTests[i].resultVerbs[j]);
2793 for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k) {
2794 REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]);
2796 } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb);
2797 REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs);
2801 iter.setPath(p, false);
2802 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2805 iter.setPath(p, false);
2806 REPORTER_ASSERT(reporter, iter.isClosedContour());
2808 iter.setPath(p, true);
2809 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2811 iter.setPath(p, true);
2812 REPORTER_ASSERT(reporter, iter.isClosedContour());
2815 iter.setPath(p, false);
2816 REPORTER_ASSERT(reporter, !iter.isClosedContour());
2818 // this checks to see if the NaN logic is executed in SkPath::autoClose(), but does not
2819 // check to see if the result is correct.
2820 for (int setNaN = 0; setNaN < 4; ++setNaN) {
2822 p.moveTo(setNaN == 0 ? SK_ScalarNaN : 0, setNaN == 1 ? SK_ScalarNaN : 0);
2823 p.lineTo(setNaN == 2 ? SK_ScalarNaN : 1, setNaN == 3 ? SK_ScalarNaN : 1);
2824 iter.setPath(p, true);
2825 iter.next(pts, false);
2826 iter.next(pts, false);
2827 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == iter.next(pts, false));
2831 p.quadTo(0, 0, 0, 0);
2832 iter.setPath(p, false);
2833 iter.next(pts, false);
2834 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == iter.next(pts, false));
2835 iter.setPath(p, false);
2836 iter.next(pts, false);
2837 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2840 p.conicTo(0, 0, 0, 0, 0.5f);
2841 iter.setPath(p, false);
2842 iter.next(pts, false);
2843 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts, false));
2844 iter.setPath(p, false);
2845 iter.next(pts, false);
2846 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2849 p.cubicTo(0, 0, 0, 0, 0, 0);
2850 iter.setPath(p, false);
2851 iter.next(pts, false);
2852 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
2853 iter.setPath(p, false);
2854 iter.next(pts, false);
2855 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2857 p.moveTo(1, 1); // add a trailing moveto
2858 iter.setPath(p, false);
2859 iter.next(pts, false);
2860 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false));
2861 iter.setPath(p, false);
2862 iter.next(pts, false);
2863 REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true));
2865 // The GM degeneratesegments.cpp test is more extensive
2867 // Test out mixed degenerate and non-degenerate geometry with Conics
2868 const SkVector radii[4] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 100, 100 } };
2869 SkRect r = SkRect::MakeWH(100, 100);
2871 rr.setRectRadii(r, radii);
2874 iter.setPath(p, false);
2875 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == iter.next(pts));
2876 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == iter.next(pts));
2877 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == iter.next(pts));
2878 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts));
2879 REPORTER_ASSERT(reporter, SK_ScalarRoot2Over2 == iter.conicWeight());
2882 static void test_raw_iter(skiatest::Reporter* reporter) {
2886 // Test an iterator with no path
2887 SkPath::RawIter noPathIter;
2888 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
2889 // Test that setting an empty path works
2890 noPathIter.setPath(p);
2891 REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb);
2893 // Test an iterator with an initial empty path
2894 SkPath::RawIter iter(p);
2895 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2897 // Test that a move-only path returns the move.
2898 p.moveTo(SK_Scalar1, 0);
2900 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2901 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2902 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2903 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2905 // No matter how many moves we add, we should get them all back
2906 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2907 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2909 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2910 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2911 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2912 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2913 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2914 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2915 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2916 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2917 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2918 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2920 // Initial close is never ever stored
2924 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2926 // Move/close sequences
2928 p.close(); // Not stored, no purpose
2929 p.moveTo(SK_Scalar1, 0);
2931 p.close(); // Not stored, no purpose
2932 p.moveTo(SK_Scalar1*2, SK_Scalar1);
2934 p.moveTo(SK_Scalar1*3, SK_Scalar1*2);
2935 p.moveTo(SK_Scalar1*4, SK_Scalar1*3);
2938 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2939 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1);
2940 REPORTER_ASSERT(reporter, pts[0].fY == 0);
2941 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2942 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2943 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2);
2944 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1);
2945 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2946 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2947 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3);
2948 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2);
2949 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb);
2950 REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4);
2951 REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3);
2952 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb);
2953 REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb);
2955 // Generate random paths and verify
2956 SkPoint randomPts[25];
2957 for (int i = 0; i < 5; ++i) {
2958 for (int j = 0; j < 5; ++j) {
2959 randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j);
2963 // Max of 10 segments, max 3 points per segment
2964 SkRandom rand(9876543);
2965 SkPoint expectedPts[31]; // May have leading moveTo
2966 SkPath::Verb expectedVerbs[22]; // May have leading moveTo
2967 SkPath::Verb nextVerb;
2969 for (int i = 0; i < 500; ++i) {
2971 bool lastWasClose = true;
2972 bool haveMoveTo = false;
2973 SkPoint lastMoveToPt = { 0, 0 };
2975 int numVerbs = (rand.nextU() >> 16) % 10;
2976 int numIterVerbs = 0;
2977 for (int j = 0; j < numVerbs; ++j) {
2979 nextVerb = static_cast<SkPath::Verb>((rand.nextU() >> 16) % SkPath::kDone_Verb);
2980 } while (lastWasClose && nextVerb == SkPath::kClose_Verb);
2982 case SkPath::kMove_Verb:
2983 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2984 p.moveTo(expectedPts[numPoints]);
2985 lastMoveToPt = expectedPts[numPoints];
2987 lastWasClose = false;
2990 case SkPath::kLine_Verb:
2992 expectedPts[numPoints++] = lastMoveToPt;
2993 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
2996 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
2997 p.lineTo(expectedPts[numPoints]);
2999 lastWasClose = false;
3001 case SkPath::kQuad_Verb:
3003 expectedPts[numPoints++] = lastMoveToPt;
3004 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
3007 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
3008 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
3009 p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]);
3011 lastWasClose = false;
3013 case SkPath::kConic_Verb:
3015 expectedPts[numPoints++] = lastMoveToPt;
3016 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
3019 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
3020 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
3021 p.conicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
3022 rand.nextUScalar1() * 4);
3024 lastWasClose = false;
3026 case SkPath::kCubic_Verb:
3028 expectedPts[numPoints++] = lastMoveToPt;
3029 expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb;
3032 expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25];
3033 expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25];
3034 expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25];
3035 p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1],
3036 expectedPts[numPoints + 2]);
3038 lastWasClose = false;
3040 case SkPath::kClose_Verb:
3043 lastWasClose = true;
3046 SkDEBUGFAIL("unexpected verb");
3048 expectedVerbs[numIterVerbs++] = nextVerb;
3052 numVerbs = numIterVerbs;
3057 lastMoveTo.set(0, 0);
3059 while ((nextVerb = iter.next(pts)) != SkPath::kDone_Verb) {
3060 REPORTER_ASSERT(reporter, nextVerb == expectedVerbs[numIterVerbs]);
3063 case SkPath::kMove_Verb:
3064 REPORTER_ASSERT(reporter, numIterPts < numPoints);
3065 REPORTER_ASSERT(reporter, pts[0] == expectedPts[numIterPts]);
3066 lastPt = lastMoveTo = pts[0];
3069 case SkPath::kLine_Verb:
3070 REPORTER_ASSERT(reporter, numIterPts < numPoints + 1);
3071 REPORTER_ASSERT(reporter, pts[0] == lastPt);
3072 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
3076 case SkPath::kQuad_Verb:
3077 case SkPath::kConic_Verb:
3078 REPORTER_ASSERT(reporter, numIterPts < numPoints + 2);
3079 REPORTER_ASSERT(reporter, pts[0] == lastPt);
3080 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
3081 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
3085 case SkPath::kCubic_Verb:
3086 REPORTER_ASSERT(reporter, numIterPts < numPoints + 3);
3087 REPORTER_ASSERT(reporter, pts[0] == lastPt);
3088 REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]);
3089 REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]);
3090 REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]);
3094 case SkPath::kClose_Verb:
3095 lastPt = lastMoveTo;
3098 SkDEBUGFAIL("unexpected verb");
3101 REPORTER_ASSERT(reporter, numIterPts == numPoints);
3102 REPORTER_ASSERT(reporter, numIterVerbs == numVerbs);
3106 static void check_for_circle(skiatest::Reporter* reporter,
3108 bool expectedCircle,
3109 SkPathPriv::FirstDirection expectedDir) {
3110 SkRect rect = SkRect::MakeEmpty();
3111 REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle);
3112 SkPath::Direction isOvalDir;
3113 unsigned isOvalStart;
3114 if (path.isOval(&rect, &isOvalDir, &isOvalStart)) {
3115 REPORTER_ASSERT(reporter, rect.height() == rect.width());
3116 REPORTER_ASSERT(reporter, SkPathPriv::AsFirstDirection(isOvalDir) == expectedDir);
3118 tmpPath.addOval(rect, isOvalDir, isOvalStart);
3119 REPORTER_ASSERT(reporter, path == tmpPath);
3121 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, expectedDir));
3124 static void test_circle_skew(skiatest::Reporter* reporter,
3126 SkPathPriv::FirstDirection dir) {
3130 m.setSkew(SkIntToScalar(3), SkIntToScalar(5));
3131 path.transform(m, &tmp);
3132 // this matrix reverses the direction.
3133 if (SkPathPriv::kCCW_FirstDirection == dir) {
3134 dir = SkPathPriv::kCW_FirstDirection;
3136 REPORTER_ASSERT(reporter, SkPathPriv::kCW_FirstDirection == dir);
3137 dir = SkPathPriv::kCCW_FirstDirection;
3139 check_for_circle(reporter, tmp, false, dir);
3142 static void test_circle_translate(skiatest::Reporter* reporter,
3144 SkPathPriv::FirstDirection dir) {
3147 // translate at small offset
3149 m.setTranslate(SkIntToScalar(15), SkIntToScalar(15));
3150 path.transform(m, &tmp);
3151 check_for_circle(reporter, tmp, true, dir);
3156 // translate at a relatively big offset
3157 m.setTranslate(SkIntToScalar(1000), SkIntToScalar(1000));
3158 path.transform(m, &tmp);
3159 check_for_circle(reporter, tmp, true, dir);
3162 static void test_circle_rotate(skiatest::Reporter* reporter,
3164 SkPathPriv::FirstDirection dir) {
3165 for (int angle = 0; angle < 360; ++angle) {
3168 m.setRotate(SkIntToScalar(angle));
3169 path.transform(m, &tmp);
3171 // TODO: a rotated circle whose rotated angle is not a multiple of 90
3172 // degrees is not an oval anymore, this can be improved. we made this
3173 // for the simplicity of our implementation.
3174 if (angle % 90 == 0) {
3175 check_for_circle(reporter, tmp, true, dir);
3177 check_for_circle(reporter, tmp, false, dir);
3182 static void test_circle_mirror_x(skiatest::Reporter* reporter,
3184 SkPathPriv::FirstDirection dir) {
3188 m.setScaleX(-SK_Scalar1);
3189 path.transform(m, &tmp);
3190 if (SkPathPriv::kCW_FirstDirection == dir) {
3191 dir = SkPathPriv::kCCW_FirstDirection;
3193 REPORTER_ASSERT(reporter, SkPathPriv::kCCW_FirstDirection == dir);
3194 dir = SkPathPriv::kCW_FirstDirection;
3196 check_for_circle(reporter, tmp, true, dir);
3199 static void test_circle_mirror_y(skiatest::Reporter* reporter,
3201 SkPathPriv::FirstDirection dir) {
3205 m.setScaleY(-SK_Scalar1);
3206 path.transform(m, &tmp);
3208 if (SkPathPriv::kCW_FirstDirection == dir) {
3209 dir = SkPathPriv::kCCW_FirstDirection;
3211 REPORTER_ASSERT(reporter, SkPathPriv::kCCW_FirstDirection == dir);
3212 dir = SkPathPriv::kCW_FirstDirection;
3215 check_for_circle(reporter, tmp, true, dir);
3218 static void test_circle_mirror_xy(skiatest::Reporter* reporter,
3220 SkPathPriv::FirstDirection dir) {
3224 m.setScaleX(-SK_Scalar1);
3225 m.setScaleY(-SK_Scalar1);
3226 path.transform(m, &tmp);
3228 check_for_circle(reporter, tmp, true, dir);
3231 static void test_circle_with_direction(skiatest::Reporter* reporter,
3232 SkPath::Direction inDir) {
3233 const SkPathPriv::FirstDirection dir = SkPathPriv::AsFirstDirection(inDir);
3237 path.addCircle(0, 0, SkIntToScalar(20), inDir);
3239 check_for_circle(reporter, path, true, dir);
3240 test_circle_rotate(reporter, path, dir);
3241 test_circle_translate(reporter, path, dir);
3242 test_circle_skew(reporter, path, dir);
3243 test_circle_mirror_x(reporter, path, dir);
3244 test_circle_mirror_y(reporter, path, dir);
3245 test_circle_mirror_xy(reporter, path, dir);
3247 // circle at an offset at (10, 10)
3249 path.addCircle(SkIntToScalar(10), SkIntToScalar(10),
3250 SkIntToScalar(20), inDir);
3252 check_for_circle(reporter, path, true, dir);
3253 test_circle_rotate(reporter, path, dir);
3254 test_circle_translate(reporter, path, dir);
3255 test_circle_skew(reporter, path, dir);
3256 test_circle_mirror_x(reporter, path, dir);
3257 test_circle_mirror_y(reporter, path, dir);
3258 test_circle_mirror_xy(reporter, path, dir);
3260 // Try different starting points for the contour.
3261 for (unsigned start = 0; start < 4; ++start) {
3263 path.addOval(SkRect::MakeXYWH(20, 10, 5, 5), inDir, start);
3264 test_circle_rotate(reporter, path, dir);
3265 test_circle_translate(reporter, path, dir);
3266 test_circle_skew(reporter, path, dir);
3267 test_circle_mirror_x(reporter, path, dir);
3268 test_circle_mirror_y(reporter, path, dir);
3269 test_circle_mirror_xy(reporter, path, dir);
3273 static void test_circle_with_add_paths(skiatest::Reporter* reporter) {
3279 const SkPath::Direction kCircleDir = SkPath::kCW_Direction;
3280 const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction;
3282 circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir);
3283 rect.addRect(SkIntToScalar(5), SkIntToScalar(5),
3284 SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction);
3287 translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12));
3289 // Although all the path concatenation related operations leave
3290 // the path a circle, most mark it as a non-circle for simplicity
3292 // empty + circle (translate)
3294 path.addPath(circle, translate);
3295 check_for_circle(reporter, path, false, SkPathPriv::AsFirstDirection(kCircleDir));
3297 // circle + empty (translate)
3299 path.addPath(empty, translate);
3301 check_for_circle(reporter, path, true, SkPathPriv::AsFirstDirection(kCircleDir));
3303 // test reverseAddPath
3305 path.reverseAddPath(rect);
3306 check_for_circle(reporter, path, false, SkPathPriv::AsFirstDirection(kCircleDirOpposite));
3309 static void test_circle(skiatest::Reporter* reporter) {
3310 test_circle_with_direction(reporter, SkPath::kCW_Direction);
3311 test_circle_with_direction(reporter, SkPath::kCCW_Direction);
3313 // multiple addCircle()
3315 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
3316 path.addCircle(0, 0, SkIntToScalar(20), SkPath::kCW_Direction);
3317 check_for_circle(reporter, path, false, SkPathPriv::kCW_FirstDirection);
3319 // some extra lineTo() would make isOval() fail
3321 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
3323 check_for_circle(reporter, path, false, SkPathPriv::kCW_FirstDirection);
3325 // not back to the original point
3327 path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction);
3328 path.setLastPt(SkIntToScalar(5), SkIntToScalar(5));
3329 check_for_circle(reporter, path, false, SkPathPriv::kCW_FirstDirection);
3331 test_circle_with_add_paths(reporter);
3333 // test negative radius
3335 path.addCircle(0, 0, -1, SkPath::kCW_Direction);
3336 REPORTER_ASSERT(reporter, path.isEmpty());
3339 static void test_oval(skiatest::Reporter* reporter) {
3344 SkPath::Direction dir = SkPath::kCCW_Direction;
3346 rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50));
3349 // Defaults to dir = CW and start = 1
3350 REPORTER_ASSERT(reporter, path.isOval(nullptr));
3352 m.setRotate(SkIntToScalar(90));
3354 path.transform(m, &tmp);
3355 // an oval rotated 90 degrees is still an oval. The start index changes from 1 to 2. Direction
3357 REPORTER_ASSERT(reporter, tmp.isOval(nullptr, &dir, &start));
3358 REPORTER_ASSERT(reporter, 2 == start);
3359 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
3362 m.setRotate(SkIntToScalar(30));
3364 path.transform(m, &tmp);
3365 // an oval rotated 30 degrees is not an oval anymore.
3366 REPORTER_ASSERT(reporter, !tmp.isOval(nullptr));
3368 // since empty path being transformed.
3372 path.transform(m, &tmp);
3373 REPORTER_ASSERT(reporter, !tmp.isOval(nullptr));
3375 // empty path is not an oval
3377 REPORTER_ASSERT(reporter, !tmp.isOval(nullptr));
3379 // only has moveTo()s
3382 tmp.moveTo(SkIntToScalar(10), SkIntToScalar(10));
3383 REPORTER_ASSERT(reporter, !tmp.isOval(nullptr));
3385 // mimic WebKit's calling convention,
3386 // call moveTo() first and then call addOval()
3390 REPORTER_ASSERT(reporter, path.isOval(nullptr));
3397 REPORTER_ASSERT(reporter, path.isOval(nullptr, &dir, &start));
3398 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
3399 REPORTER_ASSERT(reporter, 1 == start);
3402 static void test_empty(skiatest::Reporter* reporter, const SkPath& p) {
3405 REPORTER_ASSERT(reporter, p.isEmpty());
3406 REPORTER_ASSERT(reporter, 0 == p.countPoints());
3407 REPORTER_ASSERT(reporter, 0 == p.countVerbs());
3408 REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks());
3409 REPORTER_ASSERT(reporter, p.isConvex());
3410 REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType);
3411 REPORTER_ASSERT(reporter, !p.isInverseFillType());
3412 REPORTER_ASSERT(reporter, p == empty);
3413 REPORTER_ASSERT(reporter, !(p != empty));
3416 static void test_rrect_is_convex(skiatest::Reporter* reporter, SkPath* path,
3417 SkPath::Direction dir) {
3418 REPORTER_ASSERT(reporter, path->isConvex());
3419 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(*path, SkPathPriv::AsFirstDirection(dir)));
3420 path->setConvexity(SkPath::kUnknown_Convexity);
3421 REPORTER_ASSERT(reporter, path->isConvex());
3425 static void test_rrect_convexity_is_unknown(skiatest::Reporter* reporter, SkPath* path,
3426 SkPath::Direction dir) {
3427 REPORTER_ASSERT(reporter, path->isConvex());
3428 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(*path, SkPathPriv::AsFirstDirection(dir)));
3429 path->setConvexity(SkPath::kUnknown_Convexity);
3430 REPORTER_ASSERT(reporter, path->getConvexity() == SkPath::kUnknown_Convexity);
3434 static void test_rrect(skiatest::Reporter* reporter) {
3437 SkVector radii[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
3438 SkRect r = {10, 20, 30, 40};
3439 rr.setRectRadii(r, radii);
3441 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3442 p.addRRect(rr, SkPath::kCCW_Direction);
3443 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
3444 p.addRoundRect(r, &radii[0].fX);
3445 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3446 p.addRoundRect(r, &radii[0].fX, SkPath::kCCW_Direction);
3447 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
3448 p.addRoundRect(r, radii[1].fX, radii[1].fY);
3449 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3450 p.addRoundRect(r, radii[1].fX, radii[1].fY, SkPath::kCCW_Direction);
3451 test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction);
3452 for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) {
3453 SkVector save = radii[i];
3455 rr.setRectRadii(r, radii);
3457 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3460 p.addRoundRect(r, 0, 0);
3461 SkRect returnedRect;
3462 REPORTER_ASSERT(reporter, p.isRect(&returnedRect));
3463 REPORTER_ASSERT(reporter, returnedRect == r);
3464 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3465 SkVector zeroRadii[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
3466 rr.setRectRadii(r, zeroRadii);
3469 SkPath::Direction dir;
3470 REPORTER_ASSERT(reporter, p.isRect(nullptr, &closed, &dir));
3471 REPORTER_ASSERT(reporter, closed);
3472 REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir);
3473 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3474 p.addRRect(rr, SkPath::kCW_Direction);
3475 p.addRRect(rr, SkPath::kCW_Direction);
3476 REPORTER_ASSERT(reporter, !p.isConvex());
3478 p.addRRect(rr, SkPath::kCCW_Direction);
3479 p.addRRect(rr, SkPath::kCCW_Direction);
3480 REPORTER_ASSERT(reporter, !p.isConvex());
3482 SkRect emptyR = {10, 20, 10, 30};
3483 rr.setRectRadii(emptyR, radii);
3485 REPORTER_ASSERT(reporter, p.isEmpty());
3486 SkRect largeR = {0, 0, SK_ScalarMax, SK_ScalarMax};
3487 rr.setRectRadii(largeR, radii);
3489 test_rrect_convexity_is_unknown(reporter, &p, SkPath::kCW_Direction);
3491 // we check for non-finites
3492 SkRect infR = {0, 0, SK_ScalarMax, SK_ScalarInfinity};
3493 rr.setRectRadii(infR, radii);
3494 REPORTER_ASSERT(reporter, rr.isEmpty());
3496 SkRect tinyR = {0, 0, 1e-9f, 1e-9f};
3497 p.addRoundRect(tinyR, 5e-11f, 5e-11f);
3498 test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction);
3501 static void test_arc(skiatest::Reporter* reporter) {
3503 SkRect emptyOval = {10, 20, 30, 20};
3504 REPORTER_ASSERT(reporter, emptyOval.isEmpty());
3505 p.addArc(emptyOval, 1, 2);
3506 REPORTER_ASSERT(reporter, p.isEmpty());
3508 SkRect oval = {10, 20, 30, 40};
3509 p.addArc(oval, 1, 0);
3510 REPORTER_ASSERT(reporter, p.isEmpty());
3513 cwOval.addOval(oval);
3514 p.addArc(oval, 0, 360);
3515 REPORTER_ASSERT(reporter, p == cwOval);
3518 ccwOval.addOval(oval, SkPath::kCCW_Direction);
3519 p.addArc(oval, 0, -360);
3520 REPORTER_ASSERT(reporter, p == ccwOval);
3522 p.addArc(oval, 1, 180);
3523 REPORTER_ASSERT(reporter, p.isConvex());
3524 REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p, SkPathPriv::kCW_FirstDirection));
3525 p.setConvexity(SkPath::kUnknown_Convexity);
3526 REPORTER_ASSERT(reporter, p.isConvex());
3529 static inline SkScalar oval_start_index_to_angle(unsigned start) {
3544 static inline SkScalar canonical_start_angle(float angle) {
3545 while (angle < 0.f) {
3548 while (angle >= 360.f) {
3554 static void check_oval_arc(skiatest::Reporter* reporter, SkScalar start, SkScalar sweep,
3555 const SkPath& path) {
3556 SkRect r = SkRect::MakeEmpty();
3557 SkPath::Direction d = SkPath::kCCW_Direction;
3559 bool isOval = path.isOval(&r, &d, &s);
3560 REPORTER_ASSERT(reporter, isOval);
3561 SkPath recreatedPath;
3562 recreatedPath.addOval(r, d, s);
3563 REPORTER_ASSERT(reporter, path == recreatedPath);
3564 REPORTER_ASSERT(reporter, oval_start_index_to_angle(s) == canonical_start_angle(start));
3565 REPORTER_ASSERT(reporter, (SkPath::kCW_Direction == d) == (sweep > 0.f));
3568 static void test_arc_ovals(skiatest::Reporter* reporter) {
3569 SkRect oval = SkRect::MakeWH(10, 20);
3570 for (SkScalar sweep : {-720.f, -540.f, -360.f, 360.f, 432.f, 720.f}) {
3571 for (SkScalar start = -360.f; start <= 360.f; start += 1.f) {
3573 path.addArc(oval, start, sweep);
3574 // SkPath's interfaces for inserting and extracting ovals only allow contours
3575 // to start at multiples of 90 degrees.
3576 if (std::fmod(start, 90.f) == 0) {
3577 check_oval_arc(reporter, start, sweep, path);
3579 REPORTER_ASSERT(reporter, !path.isOval(nullptr));
3582 // Test start angles that are nearly at valid oval start angles.
3583 for (float start : {-180.f, -90.f, 90.f, 180.f}) {
3584 for (float delta : {-SK_ScalarNearlyZero, SK_ScalarNearlyZero}) {
3586 path.addArc(oval, start + delta, sweep);
3587 check_oval_arc(reporter, start, sweep, path);
3593 static void check_move(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3594 SkScalar x0, SkScalar y0) {
3596 SkPath::Verb v = iter->next(pts);
3597 REPORTER_ASSERT(reporter, v == SkPath::kMove_Verb);
3598 REPORTER_ASSERT(reporter, pts[0].fX == x0);
3599 REPORTER_ASSERT(reporter, pts[0].fY == y0);
3602 static void check_line(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3603 SkScalar x1, SkScalar y1) {
3605 SkPath::Verb v = iter->next(pts);
3606 REPORTER_ASSERT(reporter, v == SkPath::kLine_Verb);
3607 REPORTER_ASSERT(reporter, pts[1].fX == x1);
3608 REPORTER_ASSERT(reporter, pts[1].fY == y1);
3611 static void check_quad(skiatest::Reporter* reporter, SkPath::RawIter* iter,
3612 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3614 SkPath::Verb v = iter->next(pts);
3615 REPORTER_ASSERT(reporter, v == SkPath::kQuad_Verb);
3616 REPORTER_ASSERT(reporter, pts[1].fX == x1);
3617 REPORTER_ASSERT(reporter, pts[1].fY == y1);
3618 REPORTER_ASSERT(reporter, pts[2].fX == x2);
3619 REPORTER_ASSERT(reporter, pts[2].fY == y2);
3622 static void check_done(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
3624 SkPath::Verb v = iter->next(pts);
3625 REPORTER_ASSERT(reporter, v == SkPath::kDone_Verb);
3628 static void check_done_and_reset(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) {
3629 check_done(reporter, p, iter);
3633 static void check_path_is_move_and_reset(skiatest::Reporter* reporter, SkPath* p,
3634 SkScalar x0, SkScalar y0) {
3635 SkPath::RawIter iter(*p);
3636 check_move(reporter, &iter, x0, y0);
3637 check_done_and_reset(reporter, p, &iter);
3640 static void check_path_is_line_and_reset(skiatest::Reporter* reporter, SkPath* p,
3641 SkScalar x1, SkScalar y1) {
3642 SkPath::RawIter iter(*p);
3643 check_move(reporter, &iter, 0, 0);
3644 check_line(reporter, &iter, x1, y1);
3645 check_done_and_reset(reporter, p, &iter);
3648 static void check_path_is_line(skiatest::Reporter* reporter, SkPath* p,
3649 SkScalar x1, SkScalar y1) {
3650 SkPath::RawIter iter(*p);
3651 check_move(reporter, &iter, 0, 0);
3652 check_line(reporter, &iter, x1, y1);
3653 check_done(reporter, p, &iter);
3656 static void check_path_is_line_pair_and_reset(skiatest::Reporter* reporter, SkPath* p,
3657 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3658 SkPath::RawIter iter(*p);
3659 check_move(reporter, &iter, 0, 0);
3660 check_line(reporter, &iter, x1, y1);
3661 check_line(reporter, &iter, x2, y2);
3662 check_done_and_reset(reporter, p, &iter);
3665 static void check_path_is_quad_and_reset(skiatest::Reporter* reporter, SkPath* p,
3666 SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) {
3667 SkPath::RawIter iter(*p);
3668 check_move(reporter, &iter, 0, 0);
3669 check_quad(reporter, &iter, x1, y1, x2, y2);
3670 check_done_and_reset(reporter, p, &iter);
3673 static bool nearly_equal(const SkRect& a, const SkRect& b) {
3674 return SkScalarNearlyEqual(a.fLeft, b.fLeft) &&
3675 SkScalarNearlyEqual(a.fTop, b.fTop) &&
3676 SkScalarNearlyEqual(a.fRight, b.fRight) &&
3677 SkScalarNearlyEqual(a.fBottom, b.fBottom);
3680 static void test_arcTo(skiatest::Reporter* reporter) {
3682 p.arcTo(0, 0, 1, 2, 1);
3683 check_path_is_line_and_reset(reporter, &p, 0, 0);
3684 p.arcTo(1, 2, 1, 2, 1);
3685 check_path_is_line_and_reset(reporter, &p, 1, 2);
3686 p.arcTo(1, 2, 3, 4, 0);
3687 check_path_is_line_and_reset(reporter, &p, 1, 2);
3688 p.arcTo(1, 2, 0, 0, 1);
3689 check_path_is_line_and_reset(reporter, &p, 1, 2);
3690 p.arcTo(1, 0, 1, 1, 1);
3692 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == 1);
3694 p.arcTo(1, 0, 1, -1, 1);
3695 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == -1);
3697 SkRect oval = {1, 2, 3, 4};
3698 p.arcTo(oval, 0, 0, true);
3699 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3700 p.arcTo(oval, 0, 0, false);
3701 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3702 p.arcTo(oval, 360, 0, true);
3703 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3704 p.arcTo(oval, 360, 0, false);
3705 check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY());
3707 for (float sweep = 359, delta = 0.5f; sweep != (float) (sweep + delta); ) {
3708 p.arcTo(oval, 0, sweep, false);
3709 REPORTER_ASSERT(reporter, nearly_equal(p.getBounds(), oval));
3713 for (float sweep = 361, delta = 0.5f; sweep != (float) (sweep - delta);) {
3714 p.arcTo(oval, 0, sweep, false);
3715 REPORTER_ASSERT(reporter, nearly_equal(p.getBounds(), oval));
3719 SkRect noOvalWidth = {1, 2, 0, 3};
3721 p.arcTo(noOvalWidth, 0, 360, false);
3722 REPORTER_ASSERT(reporter, p.isEmpty());
3724 SkRect noOvalHeight = {1, 2, 3, 1};
3726 p.arcTo(noOvalHeight, 0, 360, false);
3727 REPORTER_ASSERT(reporter, p.isEmpty());
3730 static void test_addPath(skiatest::Reporter* reporter) {
3735 q.conicTo(8, 7, 6, 5, 0.5f);
3736 q.quadTo(6, 7, 8, 6);
3737 q.cubicTo(5, 6, 7, 8, 7, 5);
3739 p.addPath(q, -4, -4);
3740 SkRect expected = {0, 0, 4, 4};
3741 REPORTER_ASSERT(reporter, p.getBounds() == expected);
3743 p.reverseAddPath(q);
3744 SkRect reverseExpected = {4, 4, 8, 8};
3745 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
3748 static void test_addPathMode(skiatest::Reporter* reporter, bool explicitMoveTo, bool extend) {
3750 if (explicitMoveTo) {
3754 if (explicitMoveTo) {
3758 p.addPath(q, extend ? SkPath::kExtend_AddPathMode : SkPath::kAppend_AddPathMode);
3760 int verbcount = p.getVerbs(verbs, 4);
3761 REPORTER_ASSERT(reporter, verbcount == 4);
3762 REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
3763 REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
3764 REPORTER_ASSERT(reporter, verbs[2] == (extend ? SkPath::kLine_Verb : SkPath::kMove_Verb));
3765 REPORTER_ASSERT(reporter, verbs[3] == SkPath::kLine_Verb);
3768 static void test_extendClosedPath(skiatest::Reporter* reporter) {
3776 p.addPath(q, SkPath::kExtend_AddPathMode);
3778 int verbcount = p.getVerbs(verbs, 7);
3779 REPORTER_ASSERT(reporter, verbcount == 7);
3780 REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb);
3781 REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb);
3782 REPORTER_ASSERT(reporter, verbs[2] == SkPath::kLine_Verb);
3783 REPORTER_ASSERT(reporter, verbs[3] == SkPath::kClose_Verb);
3784 REPORTER_ASSERT(reporter, verbs[4] == SkPath::kMove_Verb);
3785 REPORTER_ASSERT(reporter, verbs[5] == SkPath::kLine_Verb);
3786 REPORTER_ASSERT(reporter, verbs[6] == SkPath::kLine_Verb);
3789 REPORTER_ASSERT(reporter, p.getLastPt(&pt));
3790 REPORTER_ASSERT(reporter, pt == SkPoint::Make(2, 3));
3791 REPORTER_ASSERT(reporter, p.getPoint(3) == SkPoint::Make(1, 1));
3794 static void test_addEmptyPath(skiatest::Reporter* reporter, SkPath::AddPathMode mode) {
3796 // case 1: dst is empty
3800 REPORTER_ASSERT(reporter, q == p);
3801 // case 2: src is empty
3803 REPORTER_ASSERT(reporter, q == p);
3804 // case 3: src and dst are empty
3807 REPORTER_ASSERT(reporter, q.isEmpty());
3810 static void test_conicTo_special_case(skiatest::Reporter* reporter) {
3812 p.conicTo(1, 2, 3, 4, -1);
3813 check_path_is_line_and_reset(reporter, &p, 3, 4);
3814 p.conicTo(1, 2, 3, 4, SK_ScalarInfinity);
3815 check_path_is_line_pair_and_reset(reporter, &p, 1, 2, 3, 4);
3816 p.conicTo(1, 2, 3, 4, 1);
3817 check_path_is_quad_and_reset(reporter, &p, 1, 2, 3, 4);
3820 static void test_get_point(skiatest::Reporter* reporter) {
3822 SkPoint pt = p.getPoint(0);
3823 REPORTER_ASSERT(reporter, pt == SkPoint::Make(0, 0));
3824 REPORTER_ASSERT(reporter, !p.getLastPt(nullptr));
3825 REPORTER_ASSERT(reporter, !p.getLastPt(&pt) && pt == SkPoint::Make(0, 0));
3826 p.setLastPt(10, 10);
3828 REPORTER_ASSERT(reporter, pt == SkPoint::Make(10, 10));
3829 REPORTER_ASSERT(reporter, p.getLastPt(nullptr));
3831 REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt == SkPoint::Make(20, 20));
3834 static void test_contains(skiatest::Reporter* reporter) {
3836 p.moveTo(SkBits2Float(0xe085e7b1), SkBits2Float(0x5f512c00)); // -7.7191e+19f, 1.50724e+19f
3837 p.conicTo(SkBits2Float(0xdfdaa221), SkBits2Float(0x5eaac338), SkBits2Float(0x60342f13), SkBits2Float(0xdf0cbb58), SkBits2Float(0x3f3504f3)); // -3.15084e+19f, 6.15237e+18f, 5.19345e+19f, -1.01408e+19f, 0.707107f
3838 p.conicTo(SkBits2Float(0x60ead799), SkBits2Float(0xdfb76c24), SkBits2Float(0x609b9872), SkBits2Float(0xdf730de8), SkBits2Float(0x3f3504f4)); // 1.35377e+20f, -2.6434e+19f, 8.96947e+19f, -1.75139e+19f, 0.707107f
3839 p.lineTo(SkBits2Float(0x609b9872), SkBits2Float(0xdf730de8)); // 8.96947e+19f, -1.75139e+19f
3840 p.conicTo(SkBits2Float(0x6018b296), SkBits2Float(0xdeee870d), SkBits2Float(0xe008cd8e), SkBits2Float(0x5ed5b2db), SkBits2Float(0x3f3504f3)); // 4.40121e+19f, -8.59386e+18f, -3.94308e+19f, 7.69931e+18f, 0.707107f
3841 p.conicTo(SkBits2Float(0xe0d526d9), SkBits2Float(0x5fa67b31), SkBits2Float(0xe085e7b2), SkBits2Float(0x5f512c01), SkBits2Float(0x3f3504f3)); // -1.22874e+20f, 2.39925e+19f, -7.7191e+19f, 1.50724e+19f, 0.707107f
3842 // this may return true or false, depending on the platform's numerics, but it should not crash
3843 (void) p.contains(-77.2027664f, 15.3066053f);
3846 p.setFillType(SkPath::kInverseWinding_FillType);
3847 REPORTER_ASSERT(reporter, p.contains(0, 0));
3848 p.setFillType(SkPath::kWinding_FillType);
3849 REPORTER_ASSERT(reporter, !p.contains(0, 0));
3854 REPORTER_ASSERT(reporter, p.contains(6, 4));
3855 REPORTER_ASSERT(reporter, p.contains(5, 6));
3856 REPORTER_ASSERT(reporter, p.contains(7, 6));
3857 // test quick reject
3858 REPORTER_ASSERT(reporter, !p.contains(4, 0));
3859 REPORTER_ASSERT(reporter, !p.contains(0, 4));
3860 REPORTER_ASSERT(reporter, !p.contains(4, 10));
3861 REPORTER_ASSERT(reporter, !p.contains(10, 4));
3862 // test various crossings in x
3863 REPORTER_ASSERT(reporter, !p.contains(5, 7));
3864 REPORTER_ASSERT(reporter, p.contains(6, 7));
3865 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3871 REPORTER_ASSERT(reporter, p.contains(4, 6));
3872 REPORTER_ASSERT(reporter, p.contains(6, 5));
3873 REPORTER_ASSERT(reporter, p.contains(6, 7));
3874 // test various crossings in y
3875 REPORTER_ASSERT(reporter, !p.contains(7, 5));
3876 REPORTER_ASSERT(reporter, p.contains(7, 6));
3877 REPORTER_ASSERT(reporter, !p.contains(7, 7));
3884 REPORTER_ASSERT(reporter, p.contains(4, 4));
3885 REPORTER_ASSERT(reporter, p.contains(8, 4));
3886 REPORTER_ASSERT(reporter, p.contains(8, 8));
3887 REPORTER_ASSERT(reporter, p.contains(4, 8));
3893 REPORTER_ASSERT(reporter, p.contains(5, 6));
3894 REPORTER_ASSERT(reporter, p.contains(4, 8));
3895 REPORTER_ASSERT(reporter, p.contains(3, 6));
3901 REPORTER_ASSERT(reporter, p.contains(2, 5));
3902 REPORTER_ASSERT(reporter, p.contains(2, 7));
3903 REPORTER_ASSERT(reporter, p.contains(4, 6));
3904 // test canceling coincident edge (a smaller triangle is coincident with a larger one)
3912 REPORTER_ASSERT(reporter, !p.contains(1, 2));
3913 REPORTER_ASSERT(reporter, !p.contains(3, 2));
3914 REPORTER_ASSERT(reporter, !p.contains(4, 0));
3915 REPORTER_ASSERT(reporter, p.contains(4, 4));
3920 p.quadTo(6, 6, 8, 8);
3921 p.quadTo(6, 8, 4, 8);
3922 p.quadTo(4, 6, 4, 4);
3923 REPORTER_ASSERT(reporter, p.contains(5, 6));
3924 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3926 REPORTER_ASSERT(reporter, p.contains(5, 5));
3927 REPORTER_ASSERT(reporter, p.contains(5, 8));
3928 REPORTER_ASSERT(reporter, p.contains(4, 5));
3929 // test quad endpoints
3930 REPORTER_ASSERT(reporter, p.contains(4, 4));
3931 REPORTER_ASSERT(reporter, p.contains(8, 8));
3932 REPORTER_ASSERT(reporter, p.contains(4, 8));
3935 const SkPoint qPts[] = {{6, 6}, {8, 8}, {6, 8}, {4, 8}, {4, 6}, {4, 4}, {6, 6}};
3937 for (int index = 1; index < (int) SK_ARRAY_COUNT(qPts); index += 2) {
3938 p.quadTo(qPts[index], qPts[index + 1]);
3940 REPORTER_ASSERT(reporter, p.contains(5, 6));
3941 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3944 for (int index = 0; index < (int) SK_ARRAY_COUNT(qPts) - 2; index += 2) {
3945 SkEvalQuadAt(&qPts[index], 0.5f, &halfway, nullptr);
3946 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3951 const SkPoint kPts[] = {{4, 4}, {6, 6}, {8, 8}, {6, 8}, {4, 8}, {4, 6}, {4, 4}};
3953 for (int index = 1; index < (int) SK_ARRAY_COUNT(kPts); index += 2) {
3954 p.conicTo(kPts[index], kPts[index + 1], 0.5f);
3956 REPORTER_ASSERT(reporter, p.contains(5, 6));
3957 REPORTER_ASSERT(reporter, !p.contains(6, 5));
3959 for (int index = 0; index < (int) SK_ARRAY_COUNT(kPts) - 2; index += 2) {
3960 SkConic conic(&kPts[index], 0.5f);
3961 halfway = conic.evalAt(0.5f);
3962 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3964 // test conic end points
3965 REPORTER_ASSERT(reporter, p.contains(4, 4));
3966 REPORTER_ASSERT(reporter, p.contains(8, 8));
3967 REPORTER_ASSERT(reporter, p.contains(4, 8));
3970 SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5, 4}, {6, 5}, {7, 6}};
3971 for (int i = 0; i < 3; ++i) {
3973 p.setFillType(SkPath::kEvenOdd_FillType);
3974 p.moveTo(pts[i].fX, pts[i].fY);
3975 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);
3976 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);
3978 REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f));
3979 REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f));
3981 SkEvalCubicAt(&pts[i], 0.5f, &halfway, nullptr, nullptr);
3982 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3983 SkEvalCubicAt(&pts[i + 3], 0.5f, &halfway, nullptr, nullptr);
3984 REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY));
3985 // test cubic end points
3986 REPORTER_ASSERT(reporter, p.contains(pts[i].fX, pts[i].fY));
3987 REPORTER_ASSERT(reporter, p.contains(pts[i + 3].fX, pts[i + 3].fY));
3988 REPORTER_ASSERT(reporter, p.contains(pts[i + 6].fX, pts[i + 6].fY));
3992 class PathRefTest_Private {
3994 static void TestPathRef(skiatest::Reporter* reporter) {
3995 static const int kRepeatCnt = 10;
3997 SkAutoTUnref<SkPathRef> pathRef(new SkPathRef);
3999 SkPathRef::Editor ed(&pathRef);
4002 ed.growForRepeatedVerb(SkPath::kMove_Verb, kRepeatCnt);
4003 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
4004 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
4005 REPORTER_ASSERT(reporter, 0 == pathRef->getSegmentMasks());
4006 for (int i = 0; i < kRepeatCnt; ++i) {
4007 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == pathRef->atVerb(i));
4009 ed.resetToSize(0, 0, 0);
4013 ed.growForRepeatedVerb(SkPath::kLine_Verb, kRepeatCnt);
4014 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
4015 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints());
4016 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == pathRef->getSegmentMasks());
4017 for (int i = 0; i < kRepeatCnt; ++i) {
4018 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == pathRef->atVerb(i));
4020 ed.resetToSize(0, 0, 0);
4024 ed.growForRepeatedVerb(SkPath::kQuad_Verb, kRepeatCnt);
4025 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
4026 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
4027 REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == pathRef->getSegmentMasks());
4028 for (int i = 0; i < kRepeatCnt; ++i) {
4029 REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == pathRef->atVerb(i));
4031 ed.resetToSize(0, 0, 0);
4035 SkScalar* weights = nullptr;
4036 ed.growForRepeatedVerb(SkPath::kConic_Verb, kRepeatCnt, &weights);
4037 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
4038 REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints());
4039 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countWeights());
4040 REPORTER_ASSERT(reporter, SkPath::kConic_SegmentMask == pathRef->getSegmentMasks());
4041 REPORTER_ASSERT(reporter, weights);
4042 for (int i = 0; i < kRepeatCnt; ++i) {
4043 REPORTER_ASSERT(reporter, SkPath::kConic_Verb == pathRef->atVerb(i));
4045 ed.resetToSize(0, 0, 0);
4049 ed.growForRepeatedVerb(SkPath::kCubic_Verb, kRepeatCnt);
4050 REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs());
4051 REPORTER_ASSERT(reporter, 3*kRepeatCnt == pathRef->countPoints());
4052 REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == pathRef->getSegmentMasks());
4053 for (int i = 0; i < kRepeatCnt; ++i) {
4054 REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == pathRef->atVerb(i));
4056 ed.resetToSize(0, 0, 0);
4061 static void test_operatorEqual(skiatest::Reporter* reporter) {
4064 REPORTER_ASSERT(reporter, a == a);
4065 REPORTER_ASSERT(reporter, a == b);
4066 a.setFillType(SkPath::kInverseWinding_FillType);
4067 REPORTER_ASSERT(reporter, a != b);
4069 REPORTER_ASSERT(reporter, a == b);
4071 REPORTER_ASSERT(reporter, a != b);
4073 REPORTER_ASSERT(reporter, a == b);
4076 REPORTER_ASSERT(reporter, a != b);
4079 REPORTER_ASSERT(reporter, a == b);
4082 static void compare_dump(skiatest::Reporter* reporter, const SkPath& path, bool force,
4083 bool dumpAsHex, const char* str) {
4084 SkDynamicMemoryWStream wStream;
4085 path.dump(&wStream, force, dumpAsHex);
4086 sk_sp<SkData> data(wStream.copyToData());
4087 REPORTER_ASSERT(reporter, data->size() == strlen(str));
4088 if (strlen(str) > 0) {
4089 REPORTER_ASSERT(reporter, !memcmp(data->data(), str, strlen(str)));
4091 REPORTER_ASSERT(reporter, data->data() == nullptr || !memcmp(data->data(), str, strlen(str)));
4095 static void test_dump(skiatest::Reporter* reporter) {
4097 compare_dump(reporter, p, false, false, "");
4098 compare_dump(reporter, p, true, false, "");
4101 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
4102 "path.lineTo(3, 4);\n");
4103 compare_dump(reporter, p, true, false, "path.moveTo(1, 2);\n"
4104 "path.lineTo(3, 4);\n"
4105 "path.lineTo(1, 2);\n"
4109 p.quadTo(3, 4, 5, 6);
4110 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
4111 "path.quadTo(3, 4, 5, 6);\n");
4114 p.conicTo(3, 4, 5, 6, 0.5f);
4115 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
4116 "path.conicTo(3, 4, 5, 6, 0.5f);\n");
4119 p.cubicTo(3, 4, 5, 6, 7, 8);
4120 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
4121 "path.cubicTo(3, 4, 5, 6, 7, 8);\n");
4125 compare_dump(reporter, p, false, true,
4126 "path.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)); // 1, 2\n"
4127 "path.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)); // 3, 4\n");
4129 p.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000));
4130 p.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000));
4131 compare_dump(reporter, p, false, false, "path.moveTo(1, 2);\n"
4132 "path.lineTo(3, 4);\n");
4137 class ChangeListener : public SkPathRef::GenIDChangeListener {
4139 ChangeListener(bool *changed) : fChanged(changed) { *fChanged = false; }
4140 virtual ~ChangeListener() {}
4141 void onChange() override {
4150 class PathTest_Private {
4152 static void TestPathTo(skiatest::Reporter* reporter) {
4156 check_path_is_line(reporter, &p, 4, 4);
4159 check_path_is_line(reporter, &p, 4, 4);
4161 q.conicTo(8, 7, 6, 5, 0.5f);
4162 q.quadTo(6, 7, 8, 6);
4163 q.cubicTo(5, 6, 7, 8, 7, 5);
4166 SkRect reverseExpected = {-4, -4, 8, 8};
4167 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected);
4170 static void TestPathrefListeners(skiatest::Reporter* reporter) {
4173 bool changed = false;
4176 // Check that listener is notified on moveTo().
4178 SkPathPriv::AddGenIDChangeListener(p, new ChangeListener(&changed));
4179 REPORTER_ASSERT(reporter, !changed);
4181 REPORTER_ASSERT(reporter, changed);
4183 // Check that listener is notified on lineTo().
4184 SkPathPriv::AddGenIDChangeListener(p, new ChangeListener(&changed));
4185 REPORTER_ASSERT(reporter, !changed);
4187 REPORTER_ASSERT(reporter, changed);
4189 // Check that listener is notified on reset().
4190 SkPathPriv::AddGenIDChangeListener(p, new ChangeListener(&changed));
4191 REPORTER_ASSERT(reporter, !changed);
4193 REPORTER_ASSERT(reporter, changed);
4197 // Check that listener is notified on rewind().
4198 SkPathPriv::AddGenIDChangeListener(p, new ChangeListener(&changed));
4199 REPORTER_ASSERT(reporter, !changed);
4201 REPORTER_ASSERT(reporter, changed);
4203 // Check that listener is notified when pathref is deleted.
4207 SkPathPriv::AddGenIDChangeListener(q, new ChangeListener(&changed));
4208 REPORTER_ASSERT(reporter, !changed);
4210 // q went out of scope.
4211 REPORTER_ASSERT(reporter, changed);
4215 static void test_crbug_629455(skiatest::Reporter* reporter) {
4218 path.cubicTo(SkBits2Float(0xcdcdcd00), SkBits2Float(0xcdcdcdcd),
4219 SkBits2Float(0xcdcdcdcd), SkBits2Float(0xcdcdcdcd),
4220 SkBits2Float(0x423fcdcd), SkBits2Float(0x40ed9341));
4221 // AKA: cubicTo(-4.31596e+08f, -4.31602e+08f, -4.31602e+08f, -4.31602e+08f, 47.951f, 7.42423f);
4224 auto surface = SkSurface::MakeRasterN32Premul(100, 100);
4226 paint.setAntiAlias(true);
4227 surface->getCanvas()->drawPath(path, paint);
4230 static void test_interp(skiatest::Reporter* reporter) {
4232 REPORTER_ASSERT(reporter, p1.isInterpolatable(p2));
4233 REPORTER_ASSERT(reporter, p1.interpolate(p2, 0, &out));
4234 REPORTER_ASSERT(reporter, p1 == out);
4235 REPORTER_ASSERT(reporter, p1.interpolate(p2, 1, &out));
4236 REPORTER_ASSERT(reporter, p1 == out);
4239 REPORTER_ASSERT(reporter, !p1.isInterpolatable(p2));
4240 REPORTER_ASSERT(reporter, !p1.interpolate(p2, 1, &out));
4243 REPORTER_ASSERT(reporter, p1.isInterpolatable(p2));
4244 REPORTER_ASSERT(reporter, p1.interpolate(p2, 0, &out));
4245 REPORTER_ASSERT(reporter, p2 == out);
4246 REPORTER_ASSERT(reporter, p1.interpolate(p2, 1, &out));
4247 REPORTER_ASSERT(reporter, p1 == out);
4248 REPORTER_ASSERT(reporter, p1.interpolate(p2, 0.5f, &out));
4249 REPORTER_ASSERT(reporter, out.getBounds() == SkRect::MakeLTRB(3, 1, 4, 2));
4252 p1.conicTo(5, 4, 5, 5, 1 / SkScalarSqrt(2));
4255 p2.conicTo(7, 2, 7, 5, 1 / SkScalarSqrt(2));
4256 REPORTER_ASSERT(reporter, p1.isInterpolatable(p2));
4257 REPORTER_ASSERT(reporter, p1.interpolate(p2, 0.5f, &out));
4258 REPORTER_ASSERT(reporter, out.getBounds() == SkRect::MakeLTRB(4, 3, 6, 5));
4261 p2.conicTo(6, 3, 6, 5, 1);
4262 REPORTER_ASSERT(reporter, !p1.isInterpolatable(p2));
4265 p2.conicTo(5, 4, 5, 5, 0.5f);
4266 REPORTER_ASSERT(reporter, !p1.isInterpolatable(p2));
4269 DEF_TEST(PathInterp, reporter) {
4270 test_interp(reporter);
4273 DEF_TEST(PathContains, reporter) {
4274 test_contains(reporter);
4277 DEF_TEST(Paths, reporter) {
4278 test_fuzz_crbug_643933();
4279 test_sect_with_horizontal_needs_pinning();
4280 test_crbug_629455(reporter);
4281 test_fuzz_crbug_627414(reporter);
4282 test_path_crbug364224();
4284 SkTSize<SkScalar>::Make(3,4);
4287 SkRect bounds, bounds2;
4288 test_empty(reporter, p);
4290 REPORTER_ASSERT(reporter, p.getBounds().isEmpty());
4292 // this triggers a code path in SkPath::operator= which is otherwise unexercised
4296 // this triggers a code path in SkPath::swap which is otherwise unexercised
4299 bounds.set(0, 0, SK_Scalar1, SK_Scalar1);
4301 p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1);
4302 check_convex_bounds(reporter, p, bounds);
4303 // we have quads or cubics
4304 REPORTER_ASSERT(reporter,
4305 p.getSegmentMasks() & (kCurveSegmentMask | SkPath::kConic_SegmentMask));
4306 REPORTER_ASSERT(reporter, !p.isEmpty());
4309 test_empty(reporter, p);
4312 check_convex_bounds(reporter, p, bounds);
4313 REPORTER_ASSERT(reporter, !p.isEmpty());
4316 test_empty(reporter, p);
4319 check_convex_bounds(reporter, p, bounds);
4320 // we have only lines
4321 REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == p.getSegmentMasks());
4322 REPORTER_ASSERT(reporter, !p.isEmpty());
4324 REPORTER_ASSERT(reporter, p != empty);
4325 REPORTER_ASSERT(reporter, !(p == empty));
4327 // do getPoints and getVerbs return the right result
4328 REPORTER_ASSERT(reporter, p.getPoints(nullptr, 0) == 4);
4329 REPORTER_ASSERT(reporter, p.getVerbs(nullptr, 0) == 5);
4331 int count = p.getPoints(pts, 4);
4332 REPORTER_ASSERT(reporter, count == 4);
4335 p.getVerbs(verbs, 5);
4336 REPORTER_ASSERT(reporter, SkPath::kMove_Verb == verbs[0]);
4337 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[1]);
4338 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[2]);
4339 REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[3]);
4340 REPORTER_ASSERT(reporter, SkPath::kClose_Verb == verbs[4]);
4341 REPORTER_ASSERT(reporter, 0xff == verbs[5]);
4342 bounds2.set(pts, 4);
4343 REPORTER_ASSERT(reporter, bounds == bounds2);
4345 bounds.offset(SK_Scalar1*3, SK_Scalar1*4);
4346 p.offset(SK_Scalar1*3, SK_Scalar1*4);
4347 REPORTER_ASSERT(reporter, bounds == p.getBounds());
4349 REPORTER_ASSERT(reporter, p.isRect(nullptr));
4351 REPORTER_ASSERT(reporter, p.isRect(&bounds2));
4352 REPORTER_ASSERT(reporter, bounds == bounds2);
4354 // now force p to not be a rect
4355 bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2);
4357 REPORTER_ASSERT(reporter, !p.isRect(nullptr));
4359 // Test an edge case w.r.t. the bound returned by isRect (i.e., the
4360 // path has a trailing moveTo. Please see crbug.com\445368)
4365 REPORTER_ASSERT(reporter, p.isRect(&r));
4366 REPORTER_ASSERT(reporter, r == bounds);
4367 // add a moveTo outside of our bounds
4368 p.moveTo(bounds.fLeft + 10, bounds.fBottom + 10);
4369 REPORTER_ASSERT(reporter, p.isRect(&r));
4370 REPORTER_ASSERT(reporter, r == bounds);
4373 test_operatorEqual(reporter);
4374 test_isLine(reporter);
4375 test_isRect(reporter);
4376 test_is_simple_closed_rect(reporter);
4377 test_isNestedFillRects(reporter);
4378 test_zero_length_paths(reporter);
4379 test_direction(reporter);
4380 test_convexity(reporter);
4381 test_convexity2(reporter);
4382 test_conservativelyContains(reporter);
4383 test_close(reporter);
4384 test_segment_masks(reporter);
4385 test_flattening(reporter);
4386 test_transform(reporter);
4387 test_bounds(reporter);
4388 test_iter(reporter);
4389 test_raw_iter(reporter);
4390 test_circle(reporter);
4391 test_oval(reporter);
4392 test_strokerec(reporter);
4393 test_addPoly(reporter);
4394 test_isfinite(reporter);
4395 test_isfinite_after_transform(reporter);
4396 test_islastcontourclosed(reporter);
4397 test_arb_round_rect_is_convex(reporter);
4398 test_arb_zero_rad_round_rect_is_rect(reporter);
4399 test_addrect(reporter);
4400 test_addrect_isfinite(reporter);
4401 test_tricky_cubic();
4402 test_clipped_cubic();
4403 test_crbug_170666();
4404 test_crbug_493450(reporter);
4405 test_crbug_495894(reporter);
4406 test_crbug_613918();
4407 test_bad_cubic_crbug229478();
4408 test_bad_cubic_crbug234190();
4409 test_gen_id(reporter);
4410 test_path_close_issue1474(reporter);
4411 test_path_to_region(reporter);
4412 test_rrect(reporter);
4414 test_arc_ovals(reporter);
4415 test_arcTo(reporter);
4416 test_addPath(reporter);
4417 test_addPathMode(reporter, false, false);
4418 test_addPathMode(reporter, true, false);
4419 test_addPathMode(reporter, false, true);
4420 test_addPathMode(reporter, true, true);
4421 test_extendClosedPath(reporter);
4422 test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode);
4423 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode);
4424 test_conicTo_special_case(reporter);
4425 test_get_point(reporter);
4426 test_contains(reporter);
4427 PathTest_Private::TestPathTo(reporter);
4428 PathRefTest_Private::TestPathRef(reporter);
4429 PathTest_Private::TestPathrefListeners(reporter);
4430 test_dump(reporter);
4431 test_path_crbug389050(reporter);
4432 test_path_crbugskia2820(reporter);
4433 test_skbug_3469(reporter);
4434 test_skbug_3239(reporter);
4435 test_bounds_crbug_513799(reporter);
4436 test_fuzz_crbug_638223();