epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2011 Google Inc. |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
reed@google.com | cc8be77 | 2013-10-15 15:35:29 +0000 | [diff] [blame] | 7 | |
Hal Canary | 95e3c05 | 2017-01-11 12:44:43 -0500 | [diff] [blame] | 8 | #include "SkAutoMalloc.h" |
reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 10 | #include "SkGeometry.h" |
Cary Clark | e0b7287 | 2017-04-12 12:03:15 -0400 | [diff] [blame] | 11 | #include "SkNullCanvas.h" |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 12 | #include "SkPaint.h" |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 13 | #include "SkParse.h" |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 14 | #include "SkParsePath.h" |
Kevin Lubick | c456b73 | 2017-01-11 17:21:57 +0000 | [diff] [blame] | 15 | #include "SkPathEffect.h" |
Hal Canary | 95e3c05 | 2017-01-11 12:44:43 -0500 | [diff] [blame] | 16 | #include "SkPathPriv.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 17 | #include "SkRRect.h" |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 18 | #include "SkRandom.h" |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 19 | #include "SkReader32.h" |
reed@android.com | 60bc6d5 | 2010-02-11 11:09:39 +0000 | [diff] [blame] | 20 | #include "SkSize.h" |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 21 | #include "SkStream.h" |
halcanary | 435657f | 2015-09-15 12:53:07 -0700 | [diff] [blame] | 22 | #include "SkStrokeRec.h" |
reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 23 | #include "SkSurface.h" |
mtklein@google.com | 9c9d4a7 | 2013-08-07 19:17:53 +0000 | [diff] [blame] | 24 | #include "SkWriter32.h" |
tfarina@chromium.org | 8f6884a | 2014-01-24 20:56:26 +0000 | [diff] [blame] | 25 | #include "Test.h" |
Hal Canary | 95e3c05 | 2017-01-11 12:44:43 -0500 | [diff] [blame] | 26 | #include <cmath> |
reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 27 | |
Cary Clark | e0b7287 | 2017-04-12 12:03:15 -0400 | [diff] [blame] | 28 | |
reed | 5bcbe91 | 2014-12-15 12:28:33 -0800 | [diff] [blame] | 29 | static void set_radii(SkVector radii[4], int index, float rad) { |
| 30 | sk_bzero(radii, sizeof(SkVector) * 4); |
| 31 | radii[index].set(rad, rad); |
| 32 | } |
| 33 | |
| 34 | static void test_add_rrect(skiatest::Reporter* reporter, const SkRect& bounds, |
| 35 | const SkVector radii[4]) { |
| 36 | SkRRect rrect; |
| 37 | rrect.setRectRadii(bounds, radii); |
| 38 | REPORTER_ASSERT(reporter, bounds == rrect.rect()); |
| 39 | |
| 40 | SkPath path; |
| 41 | // this line should not assert in the debug build (from validate) |
| 42 | path.addRRect(rrect); |
| 43 | REPORTER_ASSERT(reporter, bounds == path.getBounds()); |
| 44 | } |
| 45 | |
caryclark | 5ccef57 | 2015-03-02 10:07:56 -0800 | [diff] [blame] | 46 | static void test_skbug_3469(skiatest::Reporter* reporter) { |
| 47 | SkPath path; |
| 48 | path.moveTo(20, 20); |
| 49 | path.quadTo(20, 50, 80, 50); |
| 50 | path.quadTo(20, 50, 20, 80); |
| 51 | REPORTER_ASSERT(reporter, !path.isConvex()); |
| 52 | } |
| 53 | |
reed | 5bcbe91 | 2014-12-15 12:28:33 -0800 | [diff] [blame] | 54 | static void test_skbug_3239(skiatest::Reporter* reporter) { |
| 55 | const float min = SkBits2Float(0xcb7f16c8); /* -16717512.000000 */ |
| 56 | const float max = SkBits2Float(0x4b7f1c1d); /* 16718877.000000 */ |
| 57 | const float big = SkBits2Float(0x4b7f1bd7); /* 16718807.000000 */ |
| 58 | |
| 59 | const float rad = 33436320; |
| 60 | |
| 61 | const SkRect rectx = SkRect::MakeLTRB(min, min, max, big); |
| 62 | const SkRect recty = SkRect::MakeLTRB(min, min, big, max); |
| 63 | |
| 64 | SkVector radii[4]; |
| 65 | for (int i = 0; i < 4; ++i) { |
| 66 | set_radii(radii, i, rad); |
| 67 | test_add_rrect(reporter, rectx, radii); |
| 68 | test_add_rrect(reporter, recty, radii); |
| 69 | } |
| 70 | } |
| 71 | |
commit-bot@chromium.org | 4e332f8 | 2014-05-05 16:04:42 +0000 | [diff] [blame] | 72 | static void make_path_crbug364224(SkPath* path) { |
| 73 | path->reset(); |
| 74 | path->moveTo(3.747501373f, 2.724499941f); |
| 75 | path->lineTo(3.747501373f, 3.75f); |
| 76 | path->cubicTo(3.747501373f, 3.88774991f, 3.635501385f, 4.0f, 3.497501373f, 4.0f); |
| 77 | path->lineTo(0.7475013733f, 4.0f); |
| 78 | path->cubicTo(0.6095013618f, 4.0f, 0.4975013733f, 3.88774991f, 0.4975013733f, 3.75f); |
| 79 | path->lineTo(0.4975013733f, 1.0f); |
| 80 | path->cubicTo(0.4975013733f, 0.8622499704f, 0.6095013618f, 0.75f, 0.7475013733f,0.75f); |
| 81 | path->lineTo(3.497501373f, 0.75f); |
| 82 | path->cubicTo(3.50275135f, 0.75f, 3.5070014f, 0.7527500391f, 3.513001442f, 0.753000021f); |
| 83 | path->lineTo(3.715001345f, 0.5512499809f); |
| 84 | path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f); |
| 85 | path->lineTo(0.7475013733f, 0.4999999702f); |
| 86 | path->cubicTo(0.4715013802f, 0.4999999702f, 0.2475013733f, 0.7239999771f, 0.2475013733f, 1.0f); |
| 87 | path->lineTo(0.2475013733f, 3.75f); |
| 88 | path->cubicTo(0.2475013733f, 4.026000023f, 0.4715013504f, 4.25f, 0.7475013733f, 4.25f); |
| 89 | path->lineTo(3.497501373f, 4.25f); |
| 90 | path->cubicTo(3.773501396f, 4.25f, 3.997501373f, 4.026000023f, 3.997501373f, 3.75f); |
| 91 | path->lineTo(3.997501373f, 2.474750042f); |
| 92 | path->lineTo(3.747501373f, 2.724499941f); |
| 93 | path->close(); |
| 94 | } |
| 95 | |
| 96 | static void make_path_crbug364224_simplified(SkPath* path) { |
| 97 | path->moveTo(3.747501373f, 2.724499941f); |
| 98 | path->cubicTo(3.648251295f, 0.5194999576f, 3.575501442f, 0.4999999702f, 3.497501373f, 0.4999999702f); |
| 99 | path->close(); |
| 100 | } |
| 101 | |
reed | ff863bc | 2016-08-17 07:37:57 -0700 | [diff] [blame] | 102 | static void test_sect_with_horizontal_needs_pinning() { |
| 103 | // Test that sect_with_horizontal in SkLineClipper.cpp needs to pin after computing the |
| 104 | // intersection. |
| 105 | SkPath path; |
| 106 | path.reset(); |
| 107 | path.moveTo(-540000, -720000); |
| 108 | path.lineTo(-9.10000017e-05f, 9.99999996e-13f); |
| 109 | path.lineTo(1, 1); |
| 110 | |
| 111 | // Without the pinning code in sect_with_horizontal(), this would assert in the lineclipper |
| 112 | SkPaint paint; |
| 113 | SkSurface::MakeRasterN32Premul(10, 10)->getCanvas()->drawPath(path, paint); |
| 114 | } |
| 115 | |
commit-bot@chromium.org | 4e332f8 | 2014-05-05 16:04:42 +0000 | [diff] [blame] | 116 | static void test_path_crbug364224() { |
| 117 | SkPath path; |
| 118 | SkPaint paint; |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 119 | auto surface(SkSurface::MakeRasterN32Premul(84, 88)); |
commit-bot@chromium.org | 4e332f8 | 2014-05-05 16:04:42 +0000 | [diff] [blame] | 120 | SkCanvas* canvas = surface->getCanvas(); |
| 121 | |
| 122 | make_path_crbug364224_simplified(&path); |
| 123 | canvas->drawPath(path, paint); |
| 124 | |
| 125 | make_path_crbug364224(&path); |
| 126 | canvas->drawPath(path, paint); |
| 127 | } |
| 128 | |
caryclark | 3cebe24 | 2016-08-23 09:41:00 -0700 | [diff] [blame] | 129 | // this is a unit test instead of a GM because it doesn't draw anything |
| 130 | static void test_fuzz_crbug_638223() { |
| 131 | auto surface(SkSurface::MakeRasterN32Premul(250, 250)); |
| 132 | SkCanvas* canvas = surface->getCanvas(); |
| 133 | SkPath path; |
| 134 | path.moveTo(SkBits2Float(0x47452a00), SkBits2Float(0x43211d01)); // 50474, 161.113f |
| 135 | path.conicTo(SkBits2Float(0x401c0000), SkBits2Float(0x40680000), |
| 136 | SkBits2Float(0x02c25a81), SkBits2Float(0x981a1fa0), |
| 137 | SkBits2Float(0x6bf9abea)); // 2.4375f, 3.625f, 2.85577e-37f, -1.992e-24f, 6.03669e+26f |
| 138 | SkPaint paint; |
| 139 | paint.setAntiAlias(true); |
| 140 | canvas->drawPath(path, paint); |
| 141 | } |
| 142 | |
caryclark | e97fe83 | 2016-09-06 08:54:10 -0700 | [diff] [blame] | 143 | static void test_fuzz_crbug_643933() { |
| 144 | auto surface(SkSurface::MakeRasterN32Premul(250, 250)); |
| 145 | SkCanvas* canvas = surface->getCanvas(); |
| 146 | SkPaint paint; |
| 147 | paint.setAntiAlias(true); |
| 148 | SkPath path; |
| 149 | path.moveTo(0, 0); |
| 150 | path.conicTo(SkBits2Float(0x002001f2), SkBits2Float(0x4161ffff), // 2.93943e-39f, 14.125f |
| 151 | SkBits2Float(0x49f7224d), SkBits2Float(0x45eec8df), // 2.02452e+06f, 7641.11f |
| 152 | SkBits2Float(0x721aee0c)); // 3.0687e+30f |
| 153 | canvas->drawPath(path, paint); |
| 154 | path.reset(); |
| 155 | path.moveTo(0, 0); |
| 156 | path.conicTo(SkBits2Float(0x00007ff2), SkBits2Float(0x4169ffff), // 4.58981e-41f, 14.625f |
| 157 | SkBits2Float(0x43ff2261), SkBits2Float(0x41eeea04), // 510.269f, 29.8643f |
| 158 | SkBits2Float(0x5d06eff8)); // 6.07704e+17f |
| 159 | canvas->drawPath(path, paint); |
| 160 | } |
| 161 | |
caryclark | bac1046 | 2016-09-22 10:24:59 -0700 | [diff] [blame] | 162 | static void test_fuzz_crbug_647922() { |
| 163 | auto surface(SkSurface::MakeRasterN32Premul(250, 250)); |
| 164 | SkCanvas* canvas = surface->getCanvas(); |
| 165 | SkPaint paint; |
| 166 | paint.setAntiAlias(true); |
| 167 | SkPath path; |
| 168 | path.moveTo(0, 0); |
| 169 | path.conicTo(SkBits2Float(0x00003939), SkBits2Float(0x42487fff), // 2.05276e-41f, 50.125f |
| 170 | SkBits2Float(0x48082361), SkBits2Float(0x4408e8e9), // 139406, 547.639f |
| 171 | SkBits2Float(0x4d1ade0f)); // 1.6239e+08f |
| 172 | canvas->drawPath(path, paint); |
| 173 | } |
| 174 | |
liyuqian | 041da38 | 2016-11-11 09:59:51 -0800 | [diff] [blame] | 175 | static void test_fuzz_crbug_662780() { |
| 176 | auto surface(SkSurface::MakeRasterN32Premul(250, 250)); |
| 177 | SkCanvas* canvas = surface->getCanvas(); |
| 178 | SkPaint paint; |
| 179 | paint.setAntiAlias(true); |
| 180 | SkPath path; |
| 181 | path.moveTo(SkBits2Float(0x41000000), SkBits2Float(0x431e0000)); // 8, 158 |
| 182 | path.lineTo(SkBits2Float(0x41000000), SkBits2Float(0x42f00000)); // 8, 120 |
| 183 | // 8, 8, 8.00002f, 8, 0.707107f |
| 184 | path.conicTo(SkBits2Float(0x41000000), SkBits2Float(0x41000000), |
| 185 | SkBits2Float(0x41000010), SkBits2Float(0x41000000), SkBits2Float(0x3f3504f3)); |
| 186 | path.lineTo(SkBits2Float(0x439a0000), SkBits2Float(0x41000000)); // 308, 8 |
| 187 | // 308, 8, 308, 8, 0.707107f |
| 188 | path.conicTo(SkBits2Float(0x439a0000), SkBits2Float(0x41000000), |
| 189 | SkBits2Float(0x439a0000), SkBits2Float(0x41000000), SkBits2Float(0x3f3504f3)); |
| 190 | path.lineTo(SkBits2Float(0x439a0000), SkBits2Float(0x431e0000)); // 308, 158 |
| 191 | // 308, 158, 308, 158, 0.707107f |
| 192 | path.conicTo(SkBits2Float(0x439a0000), SkBits2Float(0x431e0000), |
| 193 | SkBits2Float(0x439a0000), SkBits2Float(0x431e0000), SkBits2Float(0x3f3504f3)); |
| 194 | path.lineTo(SkBits2Float(0x41000000), SkBits2Float(0x431e0000)); // 8, 158 |
| 195 | // 8, 158, 8, 158, 0.707107f |
| 196 | path.conicTo(SkBits2Float(0x41000000), SkBits2Float(0x431e0000), |
| 197 | SkBits2Float(0x41000000), SkBits2Float(0x431e0000), SkBits2Float(0x3f3504f3)); |
| 198 | path.close(); |
| 199 | canvas->clipPath(path, true); |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 200 | canvas->drawRect(SkRect::MakeWH(250, 250), paint); |
liyuqian | 041da38 | 2016-11-11 09:59:51 -0800 | [diff] [blame] | 201 | } |
| 202 | |
Yuqian Li | 20079a9 | 2016-11-16 13:07:57 -0500 | [diff] [blame] | 203 | static void test_mask_overflow() { |
| 204 | auto surface(SkSurface::MakeRasterN32Premul(500, 500)); |
| 205 | SkCanvas* canvas = surface->getCanvas(); |
| 206 | SkPaint paint; |
| 207 | paint.setAntiAlias(true); |
| 208 | SkPath path; |
| 209 | path.moveTo(SkBits2Float(0x43e28000), SkBits2Float(0x43aa8000)); // 453, 341 |
| 210 | path.lineTo(SkBits2Float(0x43de6000), SkBits2Float(0x43aa8000)); // 444.75f, 341 |
| 211 | // 440.47f, 341, 437, 344.47f, 437, 348.75f |
| 212 | path.cubicTo(SkBits2Float(0x43dc3c29), SkBits2Float(0x43aa8000), |
| 213 | SkBits2Float(0x43da8000), SkBits2Float(0x43ac3c29), |
| 214 | SkBits2Float(0x43da8000), SkBits2Float(0x43ae6000)); |
| 215 | path.lineTo(SkBits2Float(0x43da8000), SkBits2Float(0x43b18000)); // 437, 355 |
| 216 | path.lineTo(SkBits2Float(0x43e28000), SkBits2Float(0x43b18000)); // 453, 355 |
| 217 | path.lineTo(SkBits2Float(0x43e28000), SkBits2Float(0x43aa8000)); // 453, 341 |
| 218 | canvas->drawPath(path, paint); |
| 219 | } |
| 220 | |
Yuqian Li | 79252f7 | 2016-11-29 15:02:49 -0500 | [diff] [blame] | 221 | static void test_fuzz_crbug_668907() { |
| 222 | auto surface(SkSurface::MakeRasterN32Premul(400, 500)); |
| 223 | SkCanvas* canvas = surface->getCanvas(); |
| 224 | SkPaint paint; |
| 225 | paint.setAntiAlias(true); |
| 226 | SkPath path; |
| 227 | path.moveTo(SkBits2Float(0x46313741), SkBits2Float(0x3b00e540)); // 11341.8f, 0.00196679f |
| 228 | path.quadTo(SkBits2Float(0x41410041), SkBits2Float(0xc1414141), SkBits2Float(0x41414141), |
| 229 | SkBits2Float(0x414100ff)); // 12.0626f, -12.0784f, 12.0784f, 12.0627f |
| 230 | path.lineTo(SkBits2Float(0x46313741), SkBits2Float(0x3b00e540)); // 11341.8f, 0.00196679f |
| 231 | path.close(); |
| 232 | canvas->drawPath(path, paint); |
| 233 | } |
| 234 | |
piotaixr | fac4e0e | 2014-08-26 11:59:04 -0700 | [diff] [blame] | 235 | /** |
| 236 | * In debug mode, this path was causing an assertion to fail in |
| 237 | * SkPathStroker::preJoinTo() and, in Release, the use of an unitialized value. |
| 238 | */ |
| 239 | static void make_path_crbugskia2820(SkPath* path, skiatest::Reporter* reporter) { |
| 240 | SkPoint orig, p1, p2, p3; |
| 241 | orig = SkPoint::Make(1.f, 1.f); |
| 242 | p1 = SkPoint::Make(1.f - SK_ScalarNearlyZero, 1.f); |
| 243 | p2 = SkPoint::Make(1.f, 1.f + SK_ScalarNearlyZero); |
| 244 | p3 = SkPoint::Make(2.f, 2.f); |
| 245 | |
| 246 | path->reset(); |
| 247 | path->moveTo(orig); |
| 248 | path->cubicTo(p1, p2, p3); |
| 249 | path->close(); |
| 250 | } |
| 251 | |
| 252 | static void test_path_crbugskia2820(skiatest::Reporter* reporter) {//GrContext* context) { |
| 253 | SkPath path; |
| 254 | make_path_crbugskia2820(&path, reporter); |
| 255 | |
| 256 | SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); |
| 257 | stroke.setStrokeStyle(2 * SK_Scalar1); |
| 258 | stroke.applyToPath(&path, path); |
| 259 | } |
| 260 | |
Yuqian Li | 9939bd6 | 2016-11-29 10:27:16 -0500 | [diff] [blame] | 261 | static void test_path_crbugskia5995() { |
| 262 | auto surface(SkSurface::MakeRasterN32Premul(500, 500)); |
| 263 | SkCanvas* canvas = surface->getCanvas(); |
| 264 | SkPaint paint; |
| 265 | paint.setAntiAlias(true); |
| 266 | SkPath path; |
| 267 | path.moveTo(SkBits2Float(0x40303030), SkBits2Float(0x3e303030)); // 2.75294f, 0.172059f |
| 268 | path.quadTo(SkBits2Float(0x41d63030), SkBits2Float(0x30303030), SkBits2Float(0x41013030), |
| 269 | SkBits2Float(0x00000000)); // 26.7735f, 6.40969e-10f, 8.07426f, 0 |
| 270 | path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 |
| 271 | canvas->drawPath(path, paint); |
| 272 | } |
| 273 | |
reed@google.com | cc8be77 | 2013-10-15 15:35:29 +0000 | [diff] [blame] | 274 | static void make_path0(SkPath* path) { |
| 275 | // from * https://code.google.com/p/skia/issues/detail?id=1706 |
| 276 | |
| 277 | path->moveTo(146.939f, 1012.84f); |
| 278 | path->lineTo(181.747f, 1009.18f); |
| 279 | path->lineTo(182.165f, 1013.16f); |
| 280 | path->lineTo(147.357f, 1016.82f); |
| 281 | path->lineTo(146.939f, 1012.84f); |
| 282 | path->close(); |
| 283 | } |
| 284 | |
| 285 | static void make_path1(SkPath* path) { |
| 286 | path->addRect(SkRect::MakeXYWH(10, 10, 10, 1)); |
| 287 | } |
| 288 | |
| 289 | typedef void (*PathProc)(SkPath*); |
| 290 | |
| 291 | /* |
| 292 | * Regression test: we used to crash (overwrite internal storage) during |
| 293 | * construction of the region when the path was INVERSE. That is now fixed, |
| 294 | * so test these regions (which used to assert/crash). |
| 295 | * |
| 296 | * https://code.google.com/p/skia/issues/detail?id=1706 |
| 297 | */ |
| 298 | static void test_path_to_region(skiatest::Reporter* reporter) { |
| 299 | PathProc procs[] = { |
| 300 | make_path0, |
| 301 | make_path1, |
| 302 | }; |
skia.committer@gmail.com | 4726291 | 2013-10-16 07:02:24 +0000 | [diff] [blame] | 303 | |
reed@google.com | cc8be77 | 2013-10-15 15:35:29 +0000 | [diff] [blame] | 304 | SkRegion clip; |
| 305 | clip.setRect(0, 0, 1255, 1925); |
skia.committer@gmail.com | 4726291 | 2013-10-16 07:02:24 +0000 | [diff] [blame] | 306 | |
reed@google.com | cc8be77 | 2013-10-15 15:35:29 +0000 | [diff] [blame] | 307 | for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) { |
| 308 | SkPath path; |
| 309 | procs[i](&path); |
skia.committer@gmail.com | 4726291 | 2013-10-16 07:02:24 +0000 | [diff] [blame] | 310 | |
reed@google.com | cc8be77 | 2013-10-15 15:35:29 +0000 | [diff] [blame] | 311 | SkRegion rgn; |
| 312 | rgn.setPath(path, clip); |
| 313 | path.toggleInverseFillType(); |
| 314 | rgn.setPath(path, clip); |
| 315 | } |
| 316 | } |
| 317 | |
halcanary | 4dbbd04 | 2016-06-07 17:21:10 -0700 | [diff] [blame] | 318 | #ifdef SK_BUILD_FOR_WIN |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 319 | #define SUPPRESS_VISIBILITY_WARNING |
| 320 | #else |
| 321 | #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden"))) |
| 322 | #endif |
| 323 | |
commit-bot@chromium.org | 9d54aeb | 2013-08-09 19:48:26 +0000 | [diff] [blame] | 324 | static void test_path_close_issue1474(skiatest::Reporter* reporter) { |
| 325 | // This test checks that r{Line,Quad,Conic,Cubic}To following a close() |
| 326 | // are relative to the point we close to, not relative to the point we close from. |
| 327 | SkPath path; |
| 328 | SkPoint last; |
| 329 | |
| 330 | // Test rLineTo(). |
| 331 | path.rLineTo(0, 100); |
| 332 | path.rLineTo(100, 0); |
| 333 | path.close(); // Returns us back to 0,0. |
| 334 | path.rLineTo(50, 50); // This should go to 50,50. |
| 335 | |
| 336 | path.getLastPt(&last); |
| 337 | REPORTER_ASSERT(reporter, 50 == last.fX); |
| 338 | REPORTER_ASSERT(reporter, 50 == last.fY); |
| 339 | |
| 340 | // Test rQuadTo(). |
| 341 | path.rewind(); |
| 342 | path.rLineTo(0, 100); |
| 343 | path.rLineTo(100, 0); |
| 344 | path.close(); |
| 345 | path.rQuadTo(50, 50, 75, 75); |
| 346 | |
| 347 | path.getLastPt(&last); |
| 348 | REPORTER_ASSERT(reporter, 75 == last.fX); |
| 349 | REPORTER_ASSERT(reporter, 75 == last.fY); |
| 350 | |
| 351 | // Test rConicTo(). |
| 352 | path.rewind(); |
| 353 | path.rLineTo(0, 100); |
| 354 | path.rLineTo(100, 0); |
| 355 | path.close(); |
| 356 | path.rConicTo(50, 50, 85, 85, 2); |
| 357 | |
| 358 | path.getLastPt(&last); |
| 359 | REPORTER_ASSERT(reporter, 85 == last.fX); |
| 360 | REPORTER_ASSERT(reporter, 85 == last.fY); |
| 361 | |
| 362 | // Test rCubicTo(). |
| 363 | path.rewind(); |
| 364 | path.rLineTo(0, 100); |
| 365 | path.rLineTo(100, 0); |
| 366 | path.close(); |
| 367 | path.rCubicTo(50, 50, 85, 85, 95, 95); |
| 368 | |
| 369 | path.getLastPt(&last); |
| 370 | REPORTER_ASSERT(reporter, 95 == last.fX); |
| 371 | REPORTER_ASSERT(reporter, 95 == last.fY); |
| 372 | } |
| 373 | |
commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame] | 374 | static void test_gen_id(skiatest::Reporter* reporter) { |
| 375 | SkPath a, b; |
| 376 | REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID()); |
| 377 | |
| 378 | a.moveTo(0, 0); |
| 379 | const uint32_t z = a.getGenerationID(); |
| 380 | REPORTER_ASSERT(reporter, z != b.getGenerationID()); |
| 381 | |
| 382 | a.reset(); |
| 383 | REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID()); |
| 384 | |
| 385 | a.moveTo(1, 1); |
| 386 | const uint32_t y = a.getGenerationID(); |
| 387 | REPORTER_ASSERT(reporter, z != y); |
| 388 | |
| 389 | b.moveTo(2, 2); |
| 390 | const uint32_t x = b.getGenerationID(); |
| 391 | REPORTER_ASSERT(reporter, x != y && x != z); |
| 392 | |
| 393 | a.swap(b); |
| 394 | REPORTER_ASSERT(reporter, b.getGenerationID() == y && a.getGenerationID() == x); |
| 395 | |
| 396 | b = a; |
| 397 | REPORTER_ASSERT(reporter, b.getGenerationID() == x); |
| 398 | |
| 399 | SkPath c(a); |
| 400 | REPORTER_ASSERT(reporter, c.getGenerationID() == x); |
| 401 | |
| 402 | c.lineTo(3, 3); |
| 403 | const uint32_t w = c.getGenerationID(); |
| 404 | REPORTER_ASSERT(reporter, b.getGenerationID() == x); |
| 405 | REPORTER_ASSERT(reporter, a.getGenerationID() == x); |
| 406 | REPORTER_ASSERT(reporter, w != x); |
| 407 | |
djsollen | 50da1d8 | 2015-02-17 09:09:53 -0800 | [diff] [blame] | 408 | #ifdef SK_BUILD_FOR_ANDROID_FRAMEWORK |
commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame] | 409 | static bool kExpectGenIDToIgnoreFill = false; |
| 410 | #else |
| 411 | static bool kExpectGenIDToIgnoreFill = true; |
| 412 | #endif |
| 413 | |
| 414 | c.toggleInverseFillType(); |
| 415 | const uint32_t v = c.getGenerationID(); |
| 416 | REPORTER_ASSERT(reporter, (v == w) == kExpectGenIDToIgnoreFill); |
| 417 | |
| 418 | c.rewind(); |
| 419 | REPORTER_ASSERT(reporter, v != c.getGenerationID()); |
| 420 | } |
| 421 | |
reed@google.com | 3eff359 | 2013-05-08 21:08:21 +0000 | [diff] [blame] | 422 | // This used to assert in the debug build, as the edges did not all line-up. |
| 423 | static void test_bad_cubic_crbug234190() { |
| 424 | SkPath path; |
| 425 | path.moveTo(13.8509f, 3.16858f); |
| 426 | path.cubicTo(-2.35893e+08f, -4.21044e+08f, |
| 427 | -2.38991e+08f, -4.26573e+08f, |
| 428 | -2.41016e+08f, -4.30188e+08f); |
| 429 | |
| 430 | SkPaint paint; |
| 431 | paint.setAntiAlias(true); |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 432 | auto surface(SkSurface::MakeRasterN32Premul(84, 88)); |
reed@google.com | 3eff359 | 2013-05-08 21:08:21 +0000 | [diff] [blame] | 433 | surface->getCanvas()->drawPath(path, paint); |
| 434 | } |
| 435 | |
reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 436 | static void test_bad_cubic_crbug229478() { |
| 437 | const SkPoint pts[] = { |
skia.committer@gmail.com | 391ca66 | 2013-04-11 07:01:45 +0000 | [diff] [blame] | 438 | { 4595.91064f, -11596.9873f }, |
| 439 | { 4597.2168f, -11595.9414f }, |
| 440 | { 4598.52344f, -11594.8955f }, |
| 441 | { 4599.83008f, -11593.8496f }, |
reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 442 | }; |
skia.committer@gmail.com | 391ca66 | 2013-04-11 07:01:45 +0000 | [diff] [blame] | 443 | |
reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 444 | SkPath path; |
| 445 | path.moveTo(pts[0]); |
| 446 | path.cubicTo(pts[1], pts[2], pts[3]); |
skia.committer@gmail.com | 391ca66 | 2013-04-11 07:01:45 +0000 | [diff] [blame] | 447 | |
reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 448 | SkPaint paint; |
| 449 | paint.setStyle(SkPaint::kStroke_Style); |
| 450 | paint.setStrokeWidth(20); |
skia.committer@gmail.com | 391ca66 | 2013-04-11 07:01:45 +0000 | [diff] [blame] | 451 | |
reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 452 | SkPath dst; |
| 453 | // Before the fix, this would infinite-recurse, and run out of stack |
| 454 | // because we would keep trying to subdivide a degenerate cubic segment. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 455 | paint.getFillPath(path, &dst, nullptr); |
reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 456 | } |
| 457 | |
reed@google.com | 64d6295 | 2013-01-18 17:49:28 +0000 | [diff] [blame] | 458 | static void build_path_170666(SkPath& path) { |
| 459 | path.moveTo(17.9459f, 21.6344f); |
| 460 | path.lineTo(139.545f, -47.8105f); |
| 461 | path.lineTo(139.545f, -47.8105f); |
| 462 | path.lineTo(131.07f, -47.3888f); |
| 463 | path.lineTo(131.07f, -47.3888f); |
| 464 | path.lineTo(122.586f, -46.9532f); |
| 465 | path.lineTo(122.586f, -46.9532f); |
| 466 | path.lineTo(18076.6f, 31390.9f); |
| 467 | path.lineTo(18076.6f, 31390.9f); |
| 468 | path.lineTo(18085.1f, 31390.5f); |
| 469 | path.lineTo(18085.1f, 31390.5f); |
| 470 | path.lineTo(18076.6f, 31390.9f); |
| 471 | path.lineTo(18076.6f, 31390.9f); |
| 472 | path.lineTo(17955, 31460.3f); |
| 473 | path.lineTo(17955, 31460.3f); |
| 474 | path.lineTo(17963.5f, 31459.9f); |
| 475 | path.lineTo(17963.5f, 31459.9f); |
| 476 | path.lineTo(17971.9f, 31459.5f); |
| 477 | path.lineTo(17971.9f, 31459.5f); |
| 478 | path.lineTo(17.9551f, 21.6205f); |
| 479 | path.lineTo(17.9551f, 21.6205f); |
| 480 | path.lineTo(9.47091f, 22.0561f); |
| 481 | path.lineTo(9.47091f, 22.0561f); |
| 482 | path.lineTo(17.9459f, 21.6344f); |
| 483 | path.lineTo(17.9459f, 21.6344f); |
| 484 | path.close();path.moveTo(0.995934f, 22.4779f); |
| 485 | path.lineTo(0.986725f, 22.4918f); |
| 486 | path.lineTo(0.986725f, 22.4918f); |
| 487 | path.lineTo(17955, 31460.4f); |
| 488 | path.lineTo(17955, 31460.4f); |
| 489 | path.lineTo(17971.9f, 31459.5f); |
| 490 | path.lineTo(17971.9f, 31459.5f); |
| 491 | path.lineTo(18093.6f, 31390.1f); |
| 492 | path.lineTo(18093.6f, 31390.1f); |
| 493 | path.lineTo(18093.6f, 31390); |
| 494 | path.lineTo(18093.6f, 31390); |
| 495 | path.lineTo(139.555f, -47.8244f); |
| 496 | path.lineTo(139.555f, -47.8244f); |
| 497 | path.lineTo(122.595f, -46.9671f); |
| 498 | path.lineTo(122.595f, -46.9671f); |
| 499 | path.lineTo(0.995934f, 22.4779f); |
| 500 | path.lineTo(0.995934f, 22.4779f); |
| 501 | path.close(); |
| 502 | path.moveTo(5.43941f, 25.5223f); |
| 503 | path.lineTo(798267, -28871.1f); |
| 504 | path.lineTo(798267, -28871.1f); |
| 505 | path.lineTo(3.12512e+06f, -113102); |
| 506 | path.lineTo(3.12512e+06f, -113102); |
| 507 | path.cubicTo(5.16324e+06f, -186882, 8.15247e+06f, -295092, 1.1957e+07f, -432813); |
| 508 | path.cubicTo(1.95659e+07f, -708257, 3.04359e+07f, -1.10175e+06f, 4.34798e+07f, -1.57394e+06f); |
| 509 | path.cubicTo(6.95677e+07f, -2.51831e+06f, 1.04352e+08f, -3.77748e+06f, 1.39135e+08f, -5.03666e+06f); |
| 510 | path.cubicTo(1.73919e+08f, -6.29583e+06f, 2.08703e+08f, -7.555e+06f, 2.34791e+08f, -8.49938e+06f); |
| 511 | path.cubicTo(2.47835e+08f, -8.97157e+06f, 2.58705e+08f, -9.36506e+06f, 2.66314e+08f, -9.6405e+06f); |
| 512 | path.cubicTo(2.70118e+08f, -9.77823e+06f, 2.73108e+08f, -9.88644e+06f, 2.75146e+08f, -9.96022e+06f); |
| 513 | path.cubicTo(2.76165e+08f, -9.99711e+06f, 2.76946e+08f, -1.00254e+07f, 2.77473e+08f, -1.00444e+07f); |
| 514 | path.lineTo(2.78271e+08f, -1.00733e+07f); |
| 515 | path.lineTo(2.78271e+08f, -1.00733e+07f); |
| 516 | path.cubicTo(2.78271e+08f, -1.00733e+07f, 2.08703e+08f, -7.555e+06f, 135.238f, 23.3517f); |
| 517 | path.cubicTo(131.191f, 23.4981f, 125.995f, 23.7976f, 123.631f, 24.0206f); |
| 518 | path.cubicTo(121.267f, 24.2436f, 122.631f, 24.3056f, 126.677f, 24.1591f); |
| 519 | path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f); |
| 520 | path.lineTo(2.77473e+08f, -1.00444e+07f); |
| 521 | path.lineTo(2.77473e+08f, -1.00444e+07f); |
| 522 | path.cubicTo(2.76946e+08f, -1.00254e+07f, 2.76165e+08f, -9.99711e+06f, 2.75146e+08f, -9.96022e+06f); |
| 523 | path.cubicTo(2.73108e+08f, -9.88644e+06f, 2.70118e+08f, -9.77823e+06f, 2.66314e+08f, -9.6405e+06f); |
| 524 | path.cubicTo(2.58705e+08f, -9.36506e+06f, 2.47835e+08f, -8.97157e+06f, 2.34791e+08f, -8.49938e+06f); |
| 525 | path.cubicTo(2.08703e+08f, -7.555e+06f, 1.73919e+08f, -6.29583e+06f, 1.39135e+08f, -5.03666e+06f); |
| 526 | path.cubicTo(1.04352e+08f, -3.77749e+06f, 6.95677e+07f, -2.51831e+06f, 4.34798e+07f, -1.57394e+06f); |
| 527 | path.cubicTo(3.04359e+07f, -1.10175e+06f, 1.95659e+07f, -708258, 1.1957e+07f, -432814); |
| 528 | path.cubicTo(8.15248e+06f, -295092, 5.16324e+06f, -186883, 3.12513e+06f, -113103); |
| 529 | path.lineTo(798284, -28872); |
| 530 | path.lineTo(798284, -28872); |
| 531 | path.lineTo(22.4044f, 24.6677f); |
| 532 | path.lineTo(22.4044f, 24.6677f); |
| 533 | path.cubicTo(22.5186f, 24.5432f, 18.8134f, 24.6337f, 14.1287f, 24.8697f); |
| 534 | path.cubicTo(9.4439f, 25.1057f, 5.55359f, 25.3978f, 5.43941f, 25.5223f); |
| 535 | path.close(); |
| 536 | } |
| 537 | |
| 538 | static void build_path_simple_170666(SkPath& path) { |
| 539 | path.moveTo(126.677f, 24.1591f); |
| 540 | path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f); |
| 541 | } |
| 542 | |
| 543 | // This used to assert in the SK_DEBUG build, as the clip step would fail with |
| 544 | // too-few interations in our cubic-line intersection code. That code now runs |
| 545 | // 24 interations (instead of 16). |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 546 | static void test_crbug_170666() { |
reed@google.com | 64d6295 | 2013-01-18 17:49:28 +0000 | [diff] [blame] | 547 | SkPath path; |
| 548 | SkPaint paint; |
| 549 | paint.setAntiAlias(true); |
| 550 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 551 | auto surface(SkSurface::MakeRasterN32Premul(1000, 1000)); |
skia.committer@gmail.com | 36df7ed | 2013-01-19 07:05:38 +0000 | [diff] [blame] | 552 | |
reed@google.com | 64d6295 | 2013-01-18 17:49:28 +0000 | [diff] [blame] | 553 | build_path_simple_170666(path); |
| 554 | surface->getCanvas()->drawPath(path, paint); |
skia.committer@gmail.com | 36df7ed | 2013-01-19 07:05:38 +0000 | [diff] [blame] | 555 | |
reed@google.com | 64d6295 | 2013-01-18 17:49:28 +0000 | [diff] [blame] | 556 | build_path_170666(path); |
| 557 | surface->getCanvas()->drawPath(path, paint); |
| 558 | } |
| 559 | |
caryclark | e8c5666 | 2015-07-14 11:19:26 -0700 | [diff] [blame] | 560 | |
| 561 | static void test_tiny_path_convexity(skiatest::Reporter* reporter, const char* pathBug, |
| 562 | SkScalar tx, SkScalar ty, SkScalar scale) { |
| 563 | SkPath smallPath; |
| 564 | SkAssertResult(SkParsePath::FromSVGString(pathBug, &smallPath)); |
| 565 | bool smallConvex = smallPath.isConvex(); |
| 566 | SkPath largePath; |
| 567 | SkAssertResult(SkParsePath::FromSVGString(pathBug, &largePath)); |
| 568 | SkMatrix matrix; |
| 569 | matrix.reset(); |
| 570 | matrix.preTranslate(100, 100); |
| 571 | matrix.preScale(scale, scale); |
| 572 | largePath.transform(matrix); |
| 573 | bool largeConvex = largePath.isConvex(); |
| 574 | REPORTER_ASSERT(reporter, smallConvex == largeConvex); |
| 575 | } |
| 576 | |
| 577 | static void test_crbug_493450(skiatest::Reporter* reporter) { |
| 578 | const char reducedCase[] = |
| 579 | "M0,0" |
| 580 | "L0.0002, 0" |
| 581 | "L0.0002, 0.0002" |
| 582 | "L0.0001, 0.0001" |
| 583 | "L0,0.0002" |
| 584 | "Z"; |
| 585 | test_tiny_path_convexity(reporter, reducedCase, 100, 100, 100000); |
| 586 | const char originalFiddleData[] = |
| 587 | "M-0.3383152268862998,-0.11217565719203619L-0.33846085183212765,-0.11212264406895281" |
| 588 | "L-0.338509393480737,-0.11210607966681395L-0.33857792286700894,-0.1121889121487573" |
| 589 | "L-0.3383866116636664,-0.11228834570924921L-0.33842087635680235,-0.11246078673250548" |
| 590 | "L-0.33809536177201055,-0.11245415228342878L-0.33797257995493996,-0.11216571641452182" |
| 591 | "L-0.33802112160354925,-0.11201996164188659L-0.33819815585141844,-0.11218559834671019Z"; |
| 592 | test_tiny_path_convexity(reporter, originalFiddleData, 280081.4116670522f, 93268.04618493588f, |
| 593 | 826357.3384828606f); |
| 594 | } |
| 595 | |
| 596 | static void test_crbug_495894(skiatest::Reporter* reporter) { |
| 597 | const char originalFiddleData[] = |
| 598 | "M-0.34004273849857214,-0.11332803232216355L-0.34008271397389744,-0.11324483772714951" |
| 599 | "L-0.3401940742265893,-0.11324483772714951L-0.34017694188002134,-0.11329807920275889" |
| 600 | "L-0.3402026403998733,-0.11333468903941245L-0.34029972369709194,-0.11334134592705701" |
| 601 | "L-0.3403054344792813,-0.11344121970007795L-0.3403140006525653,-0.11351115418399343" |
| 602 | "L-0.34024261587519866,-0.11353446986281181L-0.3402197727464413,-0.11360442946144192" |
| 603 | "L-0.34013696640469604,-0.11359110237029302L-0.34009128014718143,-0.1135877707043939" |
| 604 | "L-0.3400598708451401,-0.11360776134112742L-0.34004273849857214,-0.11355112520064405" |
| 605 | "L-0.3400113291965308,-0.11355112520064405L-0.3399970522410575,-0.11359110237029302" |
| 606 | "L-0.33997135372120546,-0.11355112520064405L-0.3399627875479215,-0.11353780084493197" |
| 607 | "L-0.3399485105924481,-0.11350782354357004L-0.3400027630232468,-0.11346452910331437" |
| 608 | "L-0.3399485105924481,-0.11340126558629839L-0.33993994441916414,-0.11340126558629839" |
| 609 | "L-0.33988283659727087,-0.11331804756574679L-0.33989140277055485,-0.11324483772714951" |
| 610 | "L-0.33997991989448945,-0.11324483772714951L-0.3399856306766788,-0.11324483772714951" |
| 611 | "L-0.34002560615200417,-0.11334467443478255ZM-0.3400684370184241,-0.11338461985124307" |
| 612 | "L-0.340154098751264,-0.11341791238732665L-0.340162664924548,-0.1134378899559977" |
| 613 | "L-0.34017979727111597,-0.11340126558629839L-0.3401655203156427,-0.11338129083212668" |
| 614 | "L-0.34012268944922275,-0.11332137577529414L-0.34007414780061346,-0.11334467443478255Z" |
| 615 | "M-0.3400027630232468,-0.11290567901106024L-0.3400113291965308,-0.11298876531245433" |
| 616 | "L-0.33997991989448945,-0.11301535852306784L-0.33990282433493346,-0.11296217481488612" |
| 617 | "L-0.33993994441916414,-0.11288906492739594Z"; |
| 618 | test_tiny_path_convexity(reporter, originalFiddleData, 22682.240000000005f,7819.72220766405f, |
| 619 | 65536); |
| 620 | } |
| 621 | |
mbarbella | 99600d0 | 2016-06-01 15:39:47 -0700 | [diff] [blame] | 622 | static void test_crbug_613918() { |
| 623 | SkPath path; |
| 624 | path.conicTo(-6.62478e-08f, 4.13885e-08f, -6.36935e-08f, 3.97927e-08f, 0.729058f); |
| 625 | path.quadTo(2.28206e-09f, -1.42572e-09f, 3.91919e-09f, -2.44852e-09f); |
| 626 | path.cubicTo(-16752.2f, -26792.9f, -21.4673f, 10.9347f, -8.57322f, -7.22739f); |
| 627 | |
| 628 | // This call could lead to an assert or uninitialized read due to a failure |
| 629 | // to check the return value from SkCubicClipper::ChopMonoAtY. |
| 630 | path.contains(-1.84817e-08f, 1.15465e-08f); |
| 631 | } |
| 632 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 633 | static void test_addrect(skiatest::Reporter* reporter) { |
| 634 | SkPath path; |
| 635 | path.lineTo(0, 0); |
| 636 | path.addRect(SkRect::MakeWH(50, 100)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 637 | REPORTER_ASSERT(reporter, path.isRect(nullptr)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 638 | |
| 639 | path.reset(); |
| 640 | path.lineTo(FLT_EPSILON, FLT_EPSILON); |
| 641 | path.addRect(SkRect::MakeWH(50, 100)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 642 | REPORTER_ASSERT(reporter, !path.isRect(nullptr)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 643 | |
| 644 | path.reset(); |
| 645 | path.quadTo(0, 0, 0, 0); |
| 646 | path.addRect(SkRect::MakeWH(50, 100)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 647 | REPORTER_ASSERT(reporter, !path.isRect(nullptr)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 648 | |
| 649 | path.reset(); |
| 650 | path.conicTo(0, 0, 0, 0, 0.5f); |
| 651 | path.addRect(SkRect::MakeWH(50, 100)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 652 | REPORTER_ASSERT(reporter, !path.isRect(nullptr)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 653 | |
| 654 | path.reset(); |
| 655 | path.cubicTo(0, 0, 0, 0, 0, 0); |
| 656 | path.addRect(SkRect::MakeWH(50, 100)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 657 | REPORTER_ASSERT(reporter, !path.isRect(nullptr)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 658 | } |
| 659 | |
reed@google.com | a8790de | 2012-10-24 21:04:04 +0000 | [diff] [blame] | 660 | // Make sure we stay non-finite once we get there (unless we reset or rewind). |
| 661 | static void test_addrect_isfinite(skiatest::Reporter* reporter) { |
| 662 | SkPath path; |
skia.committer@gmail.com | 8b0e234 | 2012-10-25 02:01:20 +0000 | [diff] [blame] | 663 | |
reed@google.com | a8790de | 2012-10-24 21:04:04 +0000 | [diff] [blame] | 664 | path.addRect(SkRect::MakeWH(50, 100)); |
| 665 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 666 | |
| 667 | path.moveTo(0, 0); |
| 668 | path.lineTo(SK_ScalarInfinity, 42); |
| 669 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 670 | |
| 671 | path.addRect(SkRect::MakeWH(50, 100)); |
| 672 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 673 | |
| 674 | path.reset(); |
| 675 | REPORTER_ASSERT(reporter, path.isFinite()); |
skia.committer@gmail.com | 8b0e234 | 2012-10-25 02:01:20 +0000 | [diff] [blame] | 676 | |
reed@google.com | a8790de | 2012-10-24 21:04:04 +0000 | [diff] [blame] | 677 | path.addRect(SkRect::MakeWH(50, 100)); |
| 678 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 679 | } |
| 680 | |
reed@google.com | 848148e | 2013-01-15 15:51:59 +0000 | [diff] [blame] | 681 | static void build_big_path(SkPath* path, bool reducedCase) { |
| 682 | if (reducedCase) { |
| 683 | path->moveTo(577330, 1971.72f); |
| 684 | path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f); |
| 685 | } else { |
| 686 | path->moveTo(60.1631f, 7.70567f); |
| 687 | path->quadTo(60.1631f, 7.70567f, 0.99474f, 0.901199f); |
| 688 | path->lineTo(577379, 1977.77f); |
| 689 | path->quadTo(577364, 1979.57f, 577325, 1980.26f); |
| 690 | path->quadTo(577286, 1980.95f, 577245, 1980.13f); |
| 691 | path->quadTo(577205, 1979.3f, 577187, 1977.45f); |
| 692 | path->quadTo(577168, 1975.6f, 577183, 1973.8f); |
| 693 | path->quadTo(577198, 1972, 577238, 1971.31f); |
| 694 | path->quadTo(577277, 1970.62f, 577317, 1971.45f); |
| 695 | path->quadTo(577330, 1971.72f, 577341, 1972.11f); |
| 696 | path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f); |
| 697 | path->moveTo(306.718f, -32.912f); |
| 698 | path->cubicTo(30.531f, 10.0005f, 1502.47f, 13.2804f, 84.3088f, 9.99601f); |
| 699 | } |
| 700 | } |
| 701 | |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 702 | static void test_clipped_cubic() { |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 703 | auto surface(SkSurface::MakeRasterN32Premul(640, 480)); |
reed@google.com | 848148e | 2013-01-15 15:51:59 +0000 | [diff] [blame] | 704 | |
| 705 | // This path used to assert, because our cubic-chopping code incorrectly |
| 706 | // moved control points after the chop. This test should be run in SK_DEBUG |
| 707 | // mode to ensure that we no long assert. |
| 708 | SkPath path; |
| 709 | for (int doReducedCase = 0; doReducedCase <= 1; ++doReducedCase) { |
| 710 | build_big_path(&path, SkToBool(doReducedCase)); |
skia.committer@gmail.com | ff21c2e | 2013-01-16 07:05:56 +0000 | [diff] [blame] | 711 | |
reed@google.com | 848148e | 2013-01-15 15:51:59 +0000 | [diff] [blame] | 712 | SkPaint paint; |
| 713 | for (int doAA = 0; doAA <= 1; ++doAA) { |
| 714 | paint.setAntiAlias(SkToBool(doAA)); |
| 715 | surface->getCanvas()->drawPath(path, paint); |
| 716 | } |
| 717 | } |
| 718 | } |
| 719 | |
reed | 3b2fb98 | 2015-07-29 08:37:13 -0700 | [diff] [blame] | 720 | static void dump_if_ne(skiatest::Reporter* reporter, const SkRect& expected, const SkRect& bounds) { |
| 721 | if (expected != bounds) { |
| 722 | ERRORF(reporter, "path.getBounds() returned [%g %g %g %g], but expected [%g %g %g %g]", |
| 723 | bounds.left(), bounds.top(), bounds.right(), bounds.bottom(), |
| 724 | expected.left(), expected.top(), expected.right(), expected.bottom()); |
| 725 | } |
| 726 | } |
| 727 | |
reed | 91f283b | 2015-07-28 06:00:50 -0700 | [diff] [blame] | 728 | static void test_bounds_crbug_513799(skiatest::Reporter* reporter) { |
| 729 | SkPath path; |
reed | 3b2fb98 | 2015-07-29 08:37:13 -0700 | [diff] [blame] | 730 | #if 0 |
| 731 | // As written these tests were failing on LLVM 4.2 MacMini Release mysteriously, so we've |
| 732 | // rewritten them to avoid this (compiler-bug?). |
reed | 91f283b | 2015-07-28 06:00:50 -0700 | [diff] [blame] | 733 | REPORTER_ASSERT(reporter, SkRect::MakeLTRB(0, 0, 0, 0) == path.getBounds()); |
| 734 | |
| 735 | path.moveTo(-5, -8); |
| 736 | REPORTER_ASSERT(reporter, SkRect::MakeLTRB(-5, -8, -5, -8) == path.getBounds()); |
| 737 | |
| 738 | path.addRect(SkRect::MakeLTRB(1, 2, 3, 4)); |
| 739 | REPORTER_ASSERT(reporter, SkRect::MakeLTRB(-5, -8, 3, 4) == path.getBounds()); |
| 740 | |
| 741 | path.moveTo(1, 2); |
| 742 | REPORTER_ASSERT(reporter, SkRect::MakeLTRB(-5, -8, 3, 4) == path.getBounds()); |
reed | 3b2fb98 | 2015-07-29 08:37:13 -0700 | [diff] [blame] | 743 | #else |
| 744 | dump_if_ne(reporter, SkRect::MakeLTRB(0, 0, 0, 0), path.getBounds()); |
| 745 | |
| 746 | path.moveTo(-5, -8); // should set the bounds |
| 747 | dump_if_ne(reporter, SkRect::MakeLTRB(-5, -8, -5, -8), path.getBounds()); |
| 748 | |
| 749 | path.addRect(SkRect::MakeLTRB(1, 2, 3, 4)); // should extend the bounds |
| 750 | dump_if_ne(reporter, SkRect::MakeLTRB(-5, -8, 3, 4), path.getBounds()); |
| 751 | |
| 752 | path.moveTo(1, 2); // don't expect this to have changed the bounds |
| 753 | dump_if_ne(reporter, SkRect::MakeLTRB(-5, -8, 3, 4), path.getBounds()); |
| 754 | #endif |
reed | 91f283b | 2015-07-28 06:00:50 -0700 | [diff] [blame] | 755 | } |
| 756 | |
reed | b1b12f8 | 2016-07-13 10:56:53 -0700 | [diff] [blame] | 757 | #include "SkSurface.h" |
| 758 | static void test_fuzz_crbug_627414(skiatest::Reporter* reporter) { |
| 759 | SkPath path; |
| 760 | path.moveTo(0, 0); |
| 761 | path.conicTo(3.58732e-43f, 2.72084f, 3.00392f, 3.00392f, 8.46e+37f); |
| 762 | |
| 763 | SkPaint paint; |
| 764 | paint.setAntiAlias(true); |
| 765 | |
| 766 | auto surf = SkSurface::MakeRasterN32Premul(100, 100); |
| 767 | surf->getCanvas()->drawPath(path, paint); |
| 768 | } |
| 769 | |
reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 770 | // Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/ |
| 771 | // which triggered an assert, from a tricky cubic. This test replicates that |
| 772 | // example, so we can ensure that we handle it (in SkEdge.cpp), and don't |
| 773 | // assert in the SK_DEBUG build. |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 774 | static void test_tricky_cubic() { |
reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 775 | const SkPoint pts[] = { |
skia.committer@gmail.com | 055c7c2 | 2012-09-15 02:01:41 +0000 | [diff] [blame] | 776 | { SkDoubleToScalar(18.8943768), SkDoubleToScalar(129.121277) }, |
| 777 | { SkDoubleToScalar(18.8937435), SkDoubleToScalar(129.121689) }, |
| 778 | { SkDoubleToScalar(18.8950119), SkDoubleToScalar(129.120422) }, |
| 779 | { SkDoubleToScalar(18.5030727), SkDoubleToScalar(129.13121) }, |
reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 780 | }; |
| 781 | |
| 782 | SkPath path; |
| 783 | path.moveTo(pts[0]); |
| 784 | path.cubicTo(pts[1], pts[2], pts[3]); |
| 785 | |
| 786 | SkPaint paint; |
| 787 | paint.setAntiAlias(true); |
| 788 | |
reed | e8f3062 | 2016-03-23 18:59:25 -0700 | [diff] [blame] | 789 | SkSurface::MakeRasterN32Premul(19, 130)->getCanvas()->drawPath(path, paint); |
reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 790 | } |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 791 | |
tomhudson@google.com | ed02c4d | 2012-08-10 14:10:45 +0000 | [diff] [blame] | 792 | // Inspired by http://code.google.com/p/chromium/issues/detail?id=141651 |
| 793 | // |
| 794 | static void test_isfinite_after_transform(skiatest::Reporter* reporter) { |
| 795 | SkPath path; |
| 796 | path.quadTo(157, 366, 286, 208); |
| 797 | path.arcTo(37, 442, 315, 163, 957494590897113.0f); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 798 | |
tomhudson@google.com | ed02c4d | 2012-08-10 14:10:45 +0000 | [diff] [blame] | 799 | SkMatrix matrix; |
| 800 | matrix.setScale(1000*1000, 1000*1000); |
| 801 | |
| 802 | // Be sure that path::transform correctly updates isFinite and the bounds |
| 803 | // if the transformation overflows. The previous bug was that isFinite was |
| 804 | // set to true in this case, but the bounds were not set to empty (which |
| 805 | // they should be). |
| 806 | while (path.isFinite()) { |
| 807 | REPORTER_ASSERT(reporter, path.getBounds().isFinite()); |
| 808 | REPORTER_ASSERT(reporter, !path.getBounds().isEmpty()); |
| 809 | path.transform(matrix); |
| 810 | } |
| 811 | REPORTER_ASSERT(reporter, path.getBounds().isEmpty()); |
| 812 | |
| 813 | matrix.setTranslate(SK_Scalar1, SK_Scalar1); |
| 814 | path.transform(matrix); |
| 815 | // we need to still be non-finite |
| 816 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 817 | REPORTER_ASSERT(reporter, path.getBounds().isEmpty()); |
| 818 | } |
| 819 | |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 820 | static void add_corner_arc(SkPath* path, const SkRect& rect, |
| 821 | SkScalar xIn, SkScalar yIn, |
robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 822 | int startAngle) |
| 823 | { |
| 824 | |
| 825 | SkScalar rx = SkMinScalar(rect.width(), xIn); |
| 826 | SkScalar ry = SkMinScalar(rect.height(), yIn); |
| 827 | |
| 828 | SkRect arcRect; |
| 829 | arcRect.set(-rx, -ry, rx, ry); |
| 830 | switch (startAngle) { |
| 831 | case 0: |
| 832 | arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom); |
| 833 | break; |
| 834 | case 90: |
| 835 | arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom); |
| 836 | break; |
| 837 | case 180: |
| 838 | arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop); |
| 839 | break; |
| 840 | case 270: |
| 841 | arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop); |
| 842 | break; |
| 843 | default: |
| 844 | break; |
| 845 | } |
| 846 | |
| 847 | path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false); |
| 848 | } |
| 849 | |
skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 850 | static void make_arb_round_rect(SkPath* path, const SkRect& r, |
robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 851 | SkScalar xCorner, SkScalar yCorner) { |
| 852 | // we are lazy here and use the same x & y for each corner |
| 853 | add_corner_arc(path, r, xCorner, yCorner, 270); |
| 854 | add_corner_arc(path, r, xCorner, yCorner, 0); |
| 855 | add_corner_arc(path, r, xCorner, yCorner, 90); |
| 856 | add_corner_arc(path, r, xCorner, yCorner, 180); |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 857 | path->close(); |
robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 858 | } |
| 859 | |
| 860 | // Chrome creates its own round rects with each corner possibly being different. |
| 861 | // Performance will suffer if they are not convex. |
| 862 | // Note: PathBench::ArbRoundRectBench performs almost exactly |
| 863 | // the same test (but with drawing) |
| 864 | static void test_arb_round_rect_is_convex(skiatest::Reporter* reporter) { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 865 | SkRandom rand; |
robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 866 | SkRect r; |
| 867 | |
| 868 | for (int i = 0; i < 5000; ++i) { |
| 869 | |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 870 | SkScalar size = rand.nextUScalar1() * 30; |
| 871 | if (size < SK_Scalar1) { |
robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 872 | continue; |
| 873 | } |
| 874 | r.fLeft = rand.nextUScalar1() * 300; |
| 875 | r.fTop = rand.nextUScalar1() * 300; |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 876 | r.fRight = r.fLeft + 2 * size; |
| 877 | r.fBottom = r.fTop + 2 * size; |
robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 878 | |
| 879 | SkPath temp; |
| 880 | |
| 881 | make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15); |
| 882 | |
| 883 | REPORTER_ASSERT(reporter, temp.isConvex()); |
| 884 | } |
| 885 | } |
| 886 | |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 887 | // Chrome will sometimes create a 0 radius round rect. The degenerate |
| 888 | // quads prevent the path from being converted to a rect |
| 889 | // Note: PathBench::ArbRoundRectBench performs almost exactly |
| 890 | // the same test (but with drawing) |
| 891 | static void test_arb_zero_rad_round_rect_is_rect(skiatest::Reporter* reporter) { |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 892 | SkRandom rand; |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 893 | SkRect r; |
| 894 | |
| 895 | for (int i = 0; i < 5000; ++i) { |
| 896 | |
| 897 | SkScalar size = rand.nextUScalar1() * 30; |
| 898 | if (size < SK_Scalar1) { |
| 899 | continue; |
| 900 | } |
| 901 | r.fLeft = rand.nextUScalar1() * 300; |
| 902 | r.fTop = rand.nextUScalar1() * 300; |
| 903 | r.fRight = r.fLeft + 2 * size; |
| 904 | r.fBottom = r.fTop + 2 * size; |
| 905 | |
| 906 | SkPath temp; |
| 907 | |
| 908 | make_arb_round_rect(&temp, r, 0, 0); |
| 909 | |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 910 | SkRect result; |
| 911 | REPORTER_ASSERT(reporter, temp.isRect(&result)); |
| 912 | REPORTER_ASSERT(reporter, r == result); |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 913 | } |
| 914 | } |
| 915 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 916 | static void test_rect_isfinite(skiatest::Reporter* reporter) { |
| 917 | const SkScalar inf = SK_ScalarInfinity; |
caryclark@google.com | 7abfa49 | 2013-04-12 11:59:41 +0000 | [diff] [blame] | 918 | const SkScalar negInf = SK_ScalarNegativeInfinity; |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 919 | const SkScalar nan = SK_ScalarNaN; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 920 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 921 | SkRect r; |
| 922 | r.setEmpty(); |
| 923 | REPORTER_ASSERT(reporter, r.isFinite()); |
caryclark@google.com | 7abfa49 | 2013-04-12 11:59:41 +0000 | [diff] [blame] | 924 | r.set(0, 0, inf, negInf); |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 925 | REPORTER_ASSERT(reporter, !r.isFinite()); |
| 926 | r.set(0, 0, nan, 0); |
| 927 | REPORTER_ASSERT(reporter, !r.isFinite()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 928 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 929 | SkPoint pts[] = { |
| 930 | { 0, 0 }, |
| 931 | { SK_Scalar1, 0 }, |
| 932 | { 0, SK_Scalar1 }, |
| 933 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 934 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 935 | bool isFine = r.setBoundsCheck(pts, 3); |
| 936 | REPORTER_ASSERT(reporter, isFine); |
| 937 | REPORTER_ASSERT(reporter, !r.isEmpty()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 938 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 939 | pts[1].set(inf, 0); |
| 940 | isFine = r.setBoundsCheck(pts, 3); |
| 941 | REPORTER_ASSERT(reporter, !isFine); |
| 942 | REPORTER_ASSERT(reporter, r.isEmpty()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 943 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 944 | pts[1].set(nan, 0); |
| 945 | isFine = r.setBoundsCheck(pts, 3); |
| 946 | REPORTER_ASSERT(reporter, !isFine); |
| 947 | REPORTER_ASSERT(reporter, r.isEmpty()); |
| 948 | } |
| 949 | |
| 950 | static void test_path_isfinite(skiatest::Reporter* reporter) { |
| 951 | const SkScalar inf = SK_ScalarInfinity; |
bsalomon@google.com | 50c79d8 | 2013-01-08 20:31:53 +0000 | [diff] [blame] | 952 | const SkScalar negInf = SK_ScalarNegativeInfinity; |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 953 | const SkScalar nan = SK_ScalarNaN; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 954 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 955 | SkPath path; |
| 956 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 957 | |
| 958 | path.reset(); |
| 959 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 960 | |
| 961 | path.reset(); |
| 962 | path.moveTo(SK_Scalar1, 0); |
| 963 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 964 | |
| 965 | path.reset(); |
bsalomon@google.com | 50c79d8 | 2013-01-08 20:31:53 +0000 | [diff] [blame] | 966 | path.moveTo(inf, negInf); |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 967 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 968 | |
| 969 | path.reset(); |
| 970 | path.moveTo(nan, 0); |
| 971 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 972 | } |
| 973 | |
| 974 | static void test_isfinite(skiatest::Reporter* reporter) { |
| 975 | test_rect_isfinite(reporter); |
| 976 | test_path_isfinite(reporter); |
| 977 | } |
| 978 | |
fs | b1475b0 | 2016-01-20 09:51:07 -0800 | [diff] [blame] | 979 | static void test_islastcontourclosed(skiatest::Reporter* reporter) { |
| 980 | SkPath path; |
| 981 | REPORTER_ASSERT(reporter, !path.isLastContourClosed()); |
| 982 | path.moveTo(0, 0); |
| 983 | REPORTER_ASSERT(reporter, !path.isLastContourClosed()); |
| 984 | path.close(); |
| 985 | REPORTER_ASSERT(reporter, path.isLastContourClosed()); |
| 986 | path.lineTo(100, 100); |
| 987 | REPORTER_ASSERT(reporter, !path.isLastContourClosed()); |
| 988 | path.moveTo(200, 200); |
| 989 | REPORTER_ASSERT(reporter, !path.isLastContourClosed()); |
| 990 | path.close(); |
| 991 | REPORTER_ASSERT(reporter, path.isLastContourClosed()); |
| 992 | path.moveTo(0, 0); |
| 993 | REPORTER_ASSERT(reporter, !path.isLastContourClosed()); |
| 994 | } |
| 995 | |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 996 | // assert that we always |
| 997 | // start with a moveTo |
| 998 | // only have 1 moveTo |
| 999 | // only have Lines after that |
| 1000 | // end with a single close |
| 1001 | // only have (at most) 1 close |
| 1002 | // |
| 1003 | static void test_poly(skiatest::Reporter* reporter, const SkPath& path, |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 1004 | const SkPoint srcPts[], bool expectClose) { |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 1005 | SkPath::RawIter iter(path); |
| 1006 | SkPoint pts[4]; |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 1007 | |
| 1008 | bool firstTime = true; |
| 1009 | bool foundClose = false; |
| 1010 | for (;;) { |
| 1011 | switch (iter.next(pts)) { |
| 1012 | case SkPath::kMove_Verb: |
| 1013 | REPORTER_ASSERT(reporter, firstTime); |
| 1014 | REPORTER_ASSERT(reporter, pts[0] == srcPts[0]); |
| 1015 | srcPts++; |
| 1016 | firstTime = false; |
| 1017 | break; |
| 1018 | case SkPath::kLine_Verb: |
| 1019 | REPORTER_ASSERT(reporter, !firstTime); |
| 1020 | REPORTER_ASSERT(reporter, pts[1] == srcPts[0]); |
| 1021 | srcPts++; |
| 1022 | break; |
| 1023 | case SkPath::kQuad_Verb: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 1024 | REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected quad verb"); |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 1025 | break; |
reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 1026 | case SkPath::kConic_Verb: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 1027 | REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected conic verb"); |
reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 1028 | break; |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 1029 | case SkPath::kCubic_Verb: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 1030 | REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected cubic verb"); |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 1031 | break; |
| 1032 | case SkPath::kClose_Verb: |
| 1033 | REPORTER_ASSERT(reporter, !firstTime); |
| 1034 | REPORTER_ASSERT(reporter, !foundClose); |
| 1035 | REPORTER_ASSERT(reporter, expectClose); |
| 1036 | foundClose = true; |
| 1037 | break; |
| 1038 | case SkPath::kDone_Verb: |
| 1039 | goto DONE; |
| 1040 | } |
| 1041 | } |
| 1042 | DONE: |
| 1043 | REPORTER_ASSERT(reporter, foundClose == expectClose); |
| 1044 | } |
| 1045 | |
| 1046 | static void test_addPoly(skiatest::Reporter* reporter) { |
| 1047 | SkPoint pts[32]; |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 1048 | SkRandom rand; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1049 | |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 1050 | for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) { |
| 1051 | pts[i].fX = rand.nextSScalar1(); |
| 1052 | pts[i].fY = rand.nextSScalar1(); |
| 1053 | } |
| 1054 | |
| 1055 | for (int doClose = 0; doClose <= 1; ++doClose) { |
| 1056 | for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) { |
| 1057 | SkPath path; |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 1058 | path.addPoly(pts, SkToInt(count), SkToBool(doClose)); |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 1059 | test_poly(reporter, path, pts, SkToBool(doClose)); |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 1060 | } |
| 1061 | } |
| 1062 | } |
| 1063 | |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 1064 | static void test_strokerec(skiatest::Reporter* reporter) { |
| 1065 | SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); |
| 1066 | REPORTER_ASSERT(reporter, rec.isFillStyle()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1067 | |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 1068 | rec.setHairlineStyle(); |
| 1069 | REPORTER_ASSERT(reporter, rec.isHairlineStyle()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1070 | |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 1071 | rec.setStrokeStyle(SK_Scalar1, false); |
| 1072 | REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1073 | |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 1074 | rec.setStrokeStyle(SK_Scalar1, true); |
| 1075 | REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1076 | |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 1077 | rec.setStrokeStyle(0, false); |
| 1078 | REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1079 | |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 1080 | rec.setStrokeStyle(0, true); |
| 1081 | REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle()); |
| 1082 | } |
| 1083 | |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1084 | // Set this for paths that don't have a consistent direction such as a bowtie. |
| 1085 | // (cheapComputeDirection is not expected to catch these.) |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1086 | const SkPathPriv::FirstDirection kDontCheckDir = static_cast<SkPathPriv::FirstDirection>(-1); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1087 | |
| 1088 | static void check_direction(skiatest::Reporter* reporter, const SkPath& path, |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1089 | SkPathPriv::FirstDirection expected) { |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1090 | if (expected == kDontCheckDir) { |
| 1091 | return; |
bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 1092 | } |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1093 | SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path. |
| 1094 | |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1095 | SkPathPriv::FirstDirection dir; |
| 1096 | if (SkPathPriv::CheapComputeFirstDirection(copy, &dir)) { |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1097 | REPORTER_ASSERT(reporter, dir == expected); |
| 1098 | } else { |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1099 | REPORTER_ASSERT(reporter, SkPathPriv::kUnknown_FirstDirection == expected); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1100 | } |
bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1103 | static void test_direction(skiatest::Reporter* reporter) { |
| 1104 | size_t i; |
| 1105 | SkPath path; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1106 | REPORTER_ASSERT(reporter, !SkPathPriv::CheapComputeFirstDirection(path, nullptr)); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1107 | REPORTER_ASSERT(reporter, !SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCW_FirstDirection)); |
| 1108 | REPORTER_ASSERT(reporter, !SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCCW_FirstDirection)); |
| 1109 | REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kUnknown_FirstDirection)); |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1110 | |
| 1111 | static const char* gDegen[] = { |
| 1112 | "M 10 10", |
| 1113 | "M 10 10 M 20 20", |
| 1114 | "M 10 10 L 20 20", |
| 1115 | "M 10 10 L 10 10 L 10 10", |
| 1116 | "M 10 10 Q 10 10 10 10", |
| 1117 | "M 10 10 C 10 10 10 10 10 10", |
| 1118 | }; |
| 1119 | for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) { |
| 1120 | path.reset(); |
| 1121 | bool valid = SkParsePath::FromSVGString(gDegen[i], &path); |
| 1122 | REPORTER_ASSERT(reporter, valid); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1123 | REPORTER_ASSERT(reporter, !SkPathPriv::CheapComputeFirstDirection(path, nullptr)); |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1124 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1125 | |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1126 | static const char* gCW[] = { |
reed@google.com | cabaf1d | 2012-01-11 21:03:05 +0000 | [diff] [blame] | 1127 | "M 10 10 L 10 10 Q 20 10 20 20", |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1128 | "M 10 10 C 20 10 20 20 20 20", |
reed@google.com | d414666 | 2012-01-31 15:42:29 +0000 | [diff] [blame] | 1129 | "M 20 10 Q 20 20 30 20 L 10 20", // test double-back at y-max |
bsalomon@google.com | 4eefe61 | 2012-07-10 18:28:12 +0000 | [diff] [blame] | 1130 | // rect with top two corners replaced by cubics with identical middle |
| 1131 | // control points |
reed@google.com | 20fb0c7 | 2012-11-13 13:47:39 +0000 | [diff] [blame] | 1132 | "M 10 10 C 10 0 10 0 20 0 L 40 0 C 50 0 50 0 50 10", |
| 1133 | "M 20 10 L 0 10 Q 10 10 20 0", // left, degenerate serif |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1134 | }; |
| 1135 | for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) { |
| 1136 | path.reset(); |
| 1137 | bool valid = SkParsePath::FromSVGString(gCW[i], &path); |
| 1138 | REPORTER_ASSERT(reporter, valid); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1139 | check_direction(reporter, path, SkPathPriv::kCW_FirstDirection); |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1140 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1141 | |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1142 | static const char* gCCW[] = { |
reed@google.com | cabaf1d | 2012-01-11 21:03:05 +0000 | [diff] [blame] | 1143 | "M 10 10 L 10 10 Q 20 10 20 -20", |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1144 | "M 10 10 C 20 10 20 -20 20 -20", |
reed@google.com | d414666 | 2012-01-31 15:42:29 +0000 | [diff] [blame] | 1145 | "M 20 10 Q 20 20 10 20 L 30 20", // test double-back at y-max |
bsalomon@google.com | 4eefe61 | 2012-07-10 18:28:12 +0000 | [diff] [blame] | 1146 | // rect with top two corners replaced by cubics with identical middle |
| 1147 | // control points |
reed@google.com | 20fb0c7 | 2012-11-13 13:47:39 +0000 | [diff] [blame] | 1148 | "M 50 10 C 50 0 50 0 40 0 L 20 0 C 10 0 10 0 10 10", |
| 1149 | "M 10 10 L 30 10 Q 20 10 10 0", // right, degenerate serif |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1150 | }; |
| 1151 | for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) { |
| 1152 | path.reset(); |
| 1153 | bool valid = SkParsePath::FromSVGString(gCCW[i], &path); |
| 1154 | REPORTER_ASSERT(reporter, valid); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1155 | check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection); |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1156 | } |
reed@google.com | ac8543f | 2012-01-30 20:51:25 +0000 | [diff] [blame] | 1157 | |
| 1158 | // Test two donuts, each wound a different direction. Only the outer contour |
| 1159 | // determines the cheap direction |
| 1160 | path.reset(); |
| 1161 | path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCW_Direction); |
| 1162 | path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCCW_Direction); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1163 | check_direction(reporter, path, SkPathPriv::kCW_FirstDirection); |
bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 1164 | |
reed@google.com | ac8543f | 2012-01-30 20:51:25 +0000 | [diff] [blame] | 1165 | path.reset(); |
| 1166 | path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCW_Direction); |
| 1167 | path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1168 | check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection); |
bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 1169 | |
| 1170 | // triangle with one point really far from the origin. |
| 1171 | path.reset(); |
| 1172 | // the first point is roughly 1.05e10, 1.05e10 |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 1173 | path.moveTo(SkBits2Float(0x501c7652), SkBits2Float(0x501c7652)); |
bsalomon@google.com | 53aab78 | 2012-02-23 14:54:49 +0000 | [diff] [blame] | 1174 | path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1); |
| 1175 | path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1176 | check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1177 | |
| 1178 | path.reset(); |
| 1179 | path.conicTo(20, 0, 20, 20, 0.5f); |
| 1180 | path.close(); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1181 | check_direction(reporter, path, SkPathPriv::kCW_FirstDirection); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1182 | |
| 1183 | path.reset(); |
| 1184 | path.lineTo(1, 1e7f); |
| 1185 | path.lineTo(1e7f, 2e7f); |
| 1186 | path.close(); |
| 1187 | REPORTER_ASSERT(reporter, SkPath::kConvex_Convexity == path.getConvexity()); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1188 | check_direction(reporter, path, SkPathPriv::kCCW_FirstDirection); |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1189 | } |
| 1190 | |
reed@google.com | ffdb018 | 2011-11-14 19:29:14 +0000 | [diff] [blame] | 1191 | static void add_rect(SkPath* path, const SkRect& r) { |
| 1192 | path->moveTo(r.fLeft, r.fTop); |
| 1193 | path->lineTo(r.fRight, r.fTop); |
| 1194 | path->lineTo(r.fRight, r.fBottom); |
| 1195 | path->lineTo(r.fLeft, r.fBottom); |
| 1196 | path->close(); |
| 1197 | } |
| 1198 | |
| 1199 | static void test_bounds(skiatest::Reporter* reporter) { |
| 1200 | static const SkRect rects[] = { |
reed@google.com | 3563c9e | 2011-11-14 19:34:57 +0000 | [diff] [blame] | 1201 | { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) }, |
| 1202 | { SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) }, |
| 1203 | { SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) }, |
| 1204 | { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) }, |
reed@google.com | ffdb018 | 2011-11-14 19:29:14 +0000 | [diff] [blame] | 1205 | }; |
| 1206 | |
| 1207 | SkPath path0, path1; |
| 1208 | for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) { |
| 1209 | path0.addRect(rects[i]); |
| 1210 | add_rect(&path1, rects[i]); |
| 1211 | } |
| 1212 | |
| 1213 | REPORTER_ASSERT(reporter, path0.getBounds() == path1.getBounds()); |
| 1214 | } |
| 1215 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 1216 | static void stroke_cubic(const SkPoint pts[4]) { |
| 1217 | SkPath path; |
| 1218 | path.moveTo(pts[0]); |
| 1219 | path.cubicTo(pts[1], pts[2], pts[3]); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1220 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 1221 | SkPaint paint; |
| 1222 | paint.setStyle(SkPaint::kStroke_Style); |
| 1223 | paint.setStrokeWidth(SK_Scalar1 * 2); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1224 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 1225 | SkPath fill; |
| 1226 | paint.getFillPath(path, &fill); |
| 1227 | } |
| 1228 | |
| 1229 | // just ensure this can run w/o any SkASSERTS firing in the debug build |
| 1230 | // we used to assert due to differences in how we determine a degenerate vector |
| 1231 | // but that was fixed with the introduction of SkPoint::CanNormalize |
| 1232 | static void stroke_tiny_cubic() { |
| 1233 | SkPoint p0[] = { |
| 1234 | { 372.0f, 92.0f }, |
| 1235 | { 372.0f, 92.0f }, |
| 1236 | { 372.0f, 92.0f }, |
| 1237 | { 372.0f, 92.0f }, |
| 1238 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1239 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 1240 | stroke_cubic(p0); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1241 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 1242 | SkPoint p1[] = { |
| 1243 | { 372.0f, 92.0f }, |
| 1244 | { 372.0007f, 92.000755f }, |
| 1245 | { 371.99927f, 92.003922f }, |
| 1246 | { 371.99826f, 92.003899f }, |
| 1247 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1248 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 1249 | stroke_cubic(p1); |
| 1250 | } |
| 1251 | |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 1252 | static void check_close(skiatest::Reporter* reporter, const SkPath& path) { |
| 1253 | for (int i = 0; i < 2; ++i) { |
robertphillips@google.com | 09042b8 | 2012-04-06 20:01:46 +0000 | [diff] [blame] | 1254 | SkPath::Iter iter(path, SkToBool(i)); |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 1255 | SkPoint mv; |
| 1256 | SkPoint pts[4]; |
| 1257 | SkPath::Verb v; |
| 1258 | int nMT = 0; |
| 1259 | int nCL = 0; |
tomhudson@google.com | 221db3c | 2011-07-28 21:10:29 +0000 | [diff] [blame] | 1260 | mv.set(0, 0); |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 1261 | while (SkPath::kDone_Verb != (v = iter.next(pts))) { |
| 1262 | switch (v) { |
| 1263 | case SkPath::kMove_Verb: |
| 1264 | mv = pts[0]; |
| 1265 | ++nMT; |
| 1266 | break; |
| 1267 | case SkPath::kClose_Verb: |
| 1268 | REPORTER_ASSERT(reporter, mv == pts[0]); |
| 1269 | ++nCL; |
| 1270 | break; |
| 1271 | default: |
| 1272 | break; |
| 1273 | } |
| 1274 | } |
| 1275 | // if we force a close on the interator we should have a close |
| 1276 | // for every moveTo |
| 1277 | REPORTER_ASSERT(reporter, !i || nMT == nCL); |
| 1278 | } |
| 1279 | } |
| 1280 | |
| 1281 | static void test_close(skiatest::Reporter* reporter) { |
| 1282 | SkPath closePt; |
| 1283 | closePt.moveTo(0, 0); |
| 1284 | closePt.close(); |
| 1285 | check_close(reporter, closePt); |
| 1286 | |
| 1287 | SkPath openPt; |
| 1288 | openPt.moveTo(0, 0); |
| 1289 | check_close(reporter, openPt); |
| 1290 | |
| 1291 | SkPath empty; |
| 1292 | check_close(reporter, empty); |
| 1293 | empty.close(); |
| 1294 | check_close(reporter, empty); |
| 1295 | |
| 1296 | SkPath rect; |
| 1297 | rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 1298 | check_close(reporter, rect); |
| 1299 | rect.close(); |
| 1300 | check_close(reporter, rect); |
| 1301 | |
| 1302 | SkPath quad; |
| 1303 | quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 1304 | check_close(reporter, quad); |
| 1305 | quad.close(); |
| 1306 | check_close(reporter, quad); |
| 1307 | |
| 1308 | SkPath cubic; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1309 | quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 1310 | 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1); |
| 1311 | check_close(reporter, cubic); |
| 1312 | cubic.close(); |
| 1313 | check_close(reporter, cubic); |
| 1314 | |
| 1315 | SkPath line; |
| 1316 | line.moveTo(SK_Scalar1, SK_Scalar1); |
| 1317 | line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1); |
| 1318 | check_close(reporter, line); |
| 1319 | line.close(); |
| 1320 | check_close(reporter, line); |
| 1321 | |
| 1322 | SkPath rect2; |
| 1323 | rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 1324 | rect2.close(); |
| 1325 | rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 1326 | check_close(reporter, rect2); |
| 1327 | rect2.close(); |
| 1328 | check_close(reporter, rect2); |
| 1329 | |
| 1330 | SkPath oval3; |
| 1331 | oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100)); |
| 1332 | oval3.close(); |
| 1333 | oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200)); |
| 1334 | check_close(reporter, oval3); |
| 1335 | oval3.close(); |
| 1336 | check_close(reporter, oval3); |
| 1337 | |
| 1338 | SkPath moves; |
| 1339 | moves.moveTo(SK_Scalar1, SK_Scalar1); |
| 1340 | moves.moveTo(5 * SK_Scalar1, SK_Scalar1); |
| 1341 | moves.moveTo(SK_Scalar1, 10 * SK_Scalar1); |
| 1342 | moves.moveTo(10 *SK_Scalar1, SK_Scalar1); |
| 1343 | check_close(reporter, moves); |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 1344 | |
| 1345 | stroke_tiny_cubic(); |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 1346 | } |
| 1347 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1348 | static void check_convexity(skiatest::Reporter* reporter, const SkPath& path, |
| 1349 | SkPath::Convexity expected) { |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1350 | SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path. |
| 1351 | SkPath::Convexity c = copy.getConvexity(); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1352 | REPORTER_ASSERT(reporter, c == expected); |
| 1353 | } |
| 1354 | |
caryclark | b421650 | 2015-03-02 13:02:34 -0800 | [diff] [blame] | 1355 | static void test_path_crbug389050(skiatest::Reporter* reporter) { |
| 1356 | SkPath tinyConvexPolygon; |
| 1357 | tinyConvexPolygon.moveTo(600.131559f, 800.112512f); |
| 1358 | tinyConvexPolygon.lineTo(600.161735f, 800.118627f); |
| 1359 | tinyConvexPolygon.lineTo(600.148962f, 800.142338f); |
| 1360 | tinyConvexPolygon.lineTo(600.134891f, 800.137724f); |
| 1361 | tinyConvexPolygon.close(); |
| 1362 | tinyConvexPolygon.getConvexity(); |
| 1363 | check_convexity(reporter, tinyConvexPolygon, SkPath::kConvex_Convexity); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1364 | check_direction(reporter, tinyConvexPolygon, SkPathPriv::kCW_FirstDirection); |
caryclark | b421650 | 2015-03-02 13:02:34 -0800 | [diff] [blame] | 1365 | |
| 1366 | SkPath platTriangle; |
| 1367 | platTriangle.moveTo(0, 0); |
| 1368 | platTriangle.lineTo(200, 0); |
| 1369 | platTriangle.lineTo(100, 0.04f); |
| 1370 | platTriangle.close(); |
| 1371 | platTriangle.getConvexity(); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1372 | check_direction(reporter, platTriangle, SkPathPriv::kCW_FirstDirection); |
caryclark | b421650 | 2015-03-02 13:02:34 -0800 | [diff] [blame] | 1373 | |
| 1374 | platTriangle.reset(); |
| 1375 | platTriangle.moveTo(0, 0); |
| 1376 | platTriangle.lineTo(200, 0); |
| 1377 | platTriangle.lineTo(100, 0.03f); |
| 1378 | platTriangle.close(); |
| 1379 | platTriangle.getConvexity(); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1380 | check_direction(reporter, platTriangle, SkPathPriv::kCW_FirstDirection); |
caryclark | b421650 | 2015-03-02 13:02:34 -0800 | [diff] [blame] | 1381 | } |
| 1382 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1383 | static void test_convexity2(skiatest::Reporter* reporter) { |
| 1384 | SkPath pt; |
| 1385 | pt.moveTo(0, 0); |
| 1386 | pt.close(); |
reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 1387 | check_convexity(reporter, pt, SkPath::kConvex_Convexity); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1388 | check_direction(reporter, pt, SkPathPriv::kUnknown_FirstDirection); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1389 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1390 | SkPath line; |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1391 | line.moveTo(12*SK_Scalar1, 20*SK_Scalar1); |
| 1392 | line.lineTo(-12*SK_Scalar1, -20*SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1393 | line.close(); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1394 | check_convexity(reporter, line, SkPath::kConvex_Convexity); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1395 | check_direction(reporter, line, SkPathPriv::kUnknown_FirstDirection); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1396 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1397 | SkPath triLeft; |
| 1398 | triLeft.moveTo(0, 0); |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1399 | triLeft.lineTo(SK_Scalar1, 0); |
| 1400 | triLeft.lineTo(SK_Scalar1, SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1401 | triLeft.close(); |
| 1402 | check_convexity(reporter, triLeft, SkPath::kConvex_Convexity); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1403 | check_direction(reporter, triLeft, SkPathPriv::kCW_FirstDirection); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1404 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1405 | SkPath triRight; |
| 1406 | triRight.moveTo(0, 0); |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1407 | triRight.lineTo(-SK_Scalar1, 0); |
| 1408 | triRight.lineTo(SK_Scalar1, SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1409 | triRight.close(); |
| 1410 | check_convexity(reporter, triRight, SkPath::kConvex_Convexity); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1411 | check_direction(reporter, triRight, SkPathPriv::kCCW_FirstDirection); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1412 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1413 | SkPath square; |
| 1414 | square.moveTo(0, 0); |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1415 | square.lineTo(SK_Scalar1, 0); |
| 1416 | square.lineTo(SK_Scalar1, SK_Scalar1); |
| 1417 | square.lineTo(0, SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1418 | square.close(); |
| 1419 | check_convexity(reporter, square, SkPath::kConvex_Convexity); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1420 | check_direction(reporter, square, SkPathPriv::kCW_FirstDirection); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1421 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1422 | SkPath redundantSquare; |
| 1423 | redundantSquare.moveTo(0, 0); |
| 1424 | redundantSquare.lineTo(0, 0); |
| 1425 | redundantSquare.lineTo(0, 0); |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1426 | redundantSquare.lineTo(SK_Scalar1, 0); |
| 1427 | redundantSquare.lineTo(SK_Scalar1, 0); |
| 1428 | redundantSquare.lineTo(SK_Scalar1, 0); |
| 1429 | redundantSquare.lineTo(SK_Scalar1, SK_Scalar1); |
| 1430 | redundantSquare.lineTo(SK_Scalar1, SK_Scalar1); |
| 1431 | redundantSquare.lineTo(SK_Scalar1, SK_Scalar1); |
| 1432 | redundantSquare.lineTo(0, SK_Scalar1); |
| 1433 | redundantSquare.lineTo(0, SK_Scalar1); |
| 1434 | redundantSquare.lineTo(0, SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1435 | redundantSquare.close(); |
| 1436 | check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1437 | check_direction(reporter, redundantSquare, SkPathPriv::kCW_FirstDirection); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1438 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1439 | SkPath bowTie; |
| 1440 | bowTie.moveTo(0, 0); |
| 1441 | bowTie.lineTo(0, 0); |
| 1442 | bowTie.lineTo(0, 0); |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1443 | bowTie.lineTo(SK_Scalar1, SK_Scalar1); |
| 1444 | bowTie.lineTo(SK_Scalar1, SK_Scalar1); |
| 1445 | bowTie.lineTo(SK_Scalar1, SK_Scalar1); |
| 1446 | bowTie.lineTo(SK_Scalar1, 0); |
| 1447 | bowTie.lineTo(SK_Scalar1, 0); |
| 1448 | bowTie.lineTo(SK_Scalar1, 0); |
| 1449 | bowTie.lineTo(0, SK_Scalar1); |
| 1450 | bowTie.lineTo(0, SK_Scalar1); |
| 1451 | bowTie.lineTo(0, SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1452 | bowTie.close(); |
| 1453 | check_convexity(reporter, bowTie, SkPath::kConcave_Convexity); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1454 | check_direction(reporter, bowTie, kDontCheckDir); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1455 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1456 | SkPath spiral; |
| 1457 | spiral.moveTo(0, 0); |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1458 | spiral.lineTo(100*SK_Scalar1, 0); |
| 1459 | spiral.lineTo(100*SK_Scalar1, 100*SK_Scalar1); |
| 1460 | spiral.lineTo(0, 100*SK_Scalar1); |
| 1461 | spiral.lineTo(0, 50*SK_Scalar1); |
| 1462 | spiral.lineTo(50*SK_Scalar1, 50*SK_Scalar1); |
| 1463 | spiral.lineTo(50*SK_Scalar1, 75*SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1464 | spiral.close(); |
reed@google.com | 85b6e39 | 2011-05-15 20:25:17 +0000 | [diff] [blame] | 1465 | check_convexity(reporter, spiral, SkPath::kConcave_Convexity); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1466 | check_direction(reporter, spiral, kDontCheckDir); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1467 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1468 | SkPath dent; |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1469 | dent.moveTo(0, 0); |
| 1470 | dent.lineTo(100*SK_Scalar1, 100*SK_Scalar1); |
| 1471 | dent.lineTo(0, 100*SK_Scalar1); |
| 1472 | dent.lineTo(-50*SK_Scalar1, 200*SK_Scalar1); |
| 1473 | dent.lineTo(-200*SK_Scalar1, 100*SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1474 | dent.close(); |
| 1475 | check_convexity(reporter, dent, SkPath::kConcave_Convexity); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1476 | check_direction(reporter, dent, SkPathPriv::kCW_FirstDirection); |
commit-bot@chromium.org | 8be07bb | 2014-05-22 14:58:53 +0000 | [diff] [blame] | 1477 | |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 1478 | // https://bug.skia.org/2235 |
commit-bot@chromium.org | 8be07bb | 2014-05-22 14:58:53 +0000 | [diff] [blame] | 1479 | SkPath strokedSin; |
| 1480 | for (int i = 0; i < 2000; i++) { |
| 1481 | SkScalar x = SkIntToScalar(i) / 2; |
| 1482 | SkScalar y = 500 - (x + SkScalarSin(x / 100) * 40) / 3; |
| 1483 | if (0 == i) { |
| 1484 | strokedSin.moveTo(x, y); |
| 1485 | } else { |
| 1486 | strokedSin.lineTo(x, y); |
| 1487 | } |
| 1488 | } |
| 1489 | SkStrokeRec stroke(SkStrokeRec::kFill_InitStyle); |
| 1490 | stroke.setStrokeStyle(2 * SK_Scalar1); |
| 1491 | stroke.applyToPath(&strokedSin, strokedSin); |
| 1492 | check_convexity(reporter, strokedSin, SkPath::kConcave_Convexity); |
| 1493 | check_direction(reporter, strokedSin, kDontCheckDir); |
robertphillips | c506e30 | 2014-09-16 09:43:31 -0700 | [diff] [blame] | 1494 | |
| 1495 | // http://crbug.com/412640 |
| 1496 | SkPath degenerateConcave; |
| 1497 | degenerateConcave.moveTo(148.67912f, 191.875f); |
| 1498 | degenerateConcave.lineTo(470.37695f, 7.5f); |
| 1499 | degenerateConcave.lineTo(148.67912f, 191.875f); |
| 1500 | degenerateConcave.lineTo(41.446522f, 376.25f); |
| 1501 | degenerateConcave.lineTo(-55.971577f, 460.0f); |
| 1502 | degenerateConcave.lineTo(41.446522f, 376.25f); |
| 1503 | check_convexity(reporter, degenerateConcave, SkPath::kConcave_Convexity); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1504 | check_direction(reporter, degenerateConcave, SkPathPriv::kUnknown_FirstDirection); |
robertphillips | f52a063 | 2014-11-17 12:11:42 -0800 | [diff] [blame] | 1505 | |
| 1506 | // http://crbug.com/433683 |
| 1507 | SkPath badFirstVector; |
| 1508 | badFirstVector.moveTo(501.087708f, 319.610352f); |
| 1509 | badFirstVector.lineTo(501.087708f, 319.610352f); |
| 1510 | badFirstVector.cubicTo(501.087677f, 319.610321f, 449.271606f, 258.078674f, 395.084564f, 198.711182f); |
| 1511 | badFirstVector.cubicTo(358.967072f, 159.140717f, 321.910553f, 120.650436f, 298.442322f, 101.955399f); |
| 1512 | badFirstVector.lineTo(301.557678f, 98.044601f); |
| 1513 | badFirstVector.cubicTo(325.283844f, 116.945084f, 362.615204f, 155.720825f, 398.777557f, 195.340454f); |
| 1514 | badFirstVector.cubicTo(453.031860f, 254.781662f, 504.912262f, 316.389618f, 504.912292f, 316.389648f); |
| 1515 | badFirstVector.lineTo(504.912292f, 316.389648f); |
| 1516 | badFirstVector.lineTo(501.087708f, 319.610352f); |
| 1517 | badFirstVector.close(); |
| 1518 | check_convexity(reporter, badFirstVector, SkPath::kConcave_Convexity); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1519 | } |
| 1520 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 1521 | static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p, |
| 1522 | const SkRect& bounds) { |
| 1523 | REPORTER_ASSERT(reporter, p.isConvex()); |
| 1524 | REPORTER_ASSERT(reporter, p.getBounds() == bounds); |
reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 1525 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 1526 | SkPath p2(p); |
| 1527 | REPORTER_ASSERT(reporter, p2.isConvex()); |
| 1528 | REPORTER_ASSERT(reporter, p2.getBounds() == bounds); |
| 1529 | |
| 1530 | SkPath other; |
| 1531 | other.swap(p2); |
| 1532 | REPORTER_ASSERT(reporter, other.isConvex()); |
| 1533 | REPORTER_ASSERT(reporter, other.getBounds() == bounds); |
| 1534 | } |
| 1535 | |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1536 | static void setFromString(SkPath* path, const char str[]) { |
| 1537 | bool first = true; |
| 1538 | while (str) { |
| 1539 | SkScalar x, y; |
| 1540 | str = SkParse::FindScalar(str, &x); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1541 | if (nullptr == str) { |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1542 | break; |
| 1543 | } |
| 1544 | str = SkParse::FindScalar(str, &y); |
| 1545 | SkASSERT(str); |
| 1546 | if (first) { |
| 1547 | path->moveTo(x, y); |
| 1548 | first = false; |
| 1549 | } else { |
| 1550 | path->lineTo(x, y); |
| 1551 | } |
| 1552 | } |
| 1553 | } |
| 1554 | |
| 1555 | static void test_convexity(skiatest::Reporter* reporter) { |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1556 | SkPath path; |
| 1557 | |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1558 | check_convexity(reporter, path, SkPath::kConvex_Convexity); |
reed@google.com | e354397 | 2012-01-10 18:59:22 +0000 | [diff] [blame] | 1559 | path.addCircle(0, 0, SkIntToScalar(10)); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1560 | check_convexity(reporter, path, SkPath::kConvex_Convexity); |
reed@google.com | e354397 | 2012-01-10 18:59:22 +0000 | [diff] [blame] | 1561 | path.addCircle(0, 0, SkIntToScalar(10)); // 2nd circle |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1562 | check_convexity(reporter, path, SkPath::kConcave_Convexity); |
| 1563 | |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1564 | path.reset(); |
reed@google.com | e354397 | 2012-01-10 18:59:22 +0000 | [diff] [blame] | 1565 | path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCCW_Direction); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1566 | check_convexity(reporter, path, SkPath::kConvex_Convexity); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1567 | REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCCW_FirstDirection)); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1568 | |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1569 | path.reset(); |
reed@google.com | e354397 | 2012-01-10 18:59:22 +0000 | [diff] [blame] | 1570 | path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCW_Direction); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1571 | check_convexity(reporter, path, SkPath::kConvex_Convexity); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1572 | REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, SkPathPriv::kCW_FirstDirection)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1573 | |
liyuqian | bdabcc4 | 2016-11-03 11:40:19 -0700 | [diff] [blame] | 1574 | path.reset(); |
| 1575 | path.quadTo(100, 100, 50, 50); // This is a convex path from GM:convexpaths |
| 1576 | check_convexity(reporter, path, SkPath::kConvex_Convexity); |
| 1577 | |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1578 | static const struct { |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1579 | const char* fPathStr; |
| 1580 | SkPath::Convexity fExpectedConvexity; |
| 1581 | SkPathPriv::FirstDirection fExpectedDirection; |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1582 | } gRec[] = { |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1583 | { "", SkPath::kConvex_Convexity, SkPathPriv::kUnknown_FirstDirection }, |
| 1584 | { "0 0", SkPath::kConvex_Convexity, SkPathPriv::kUnknown_FirstDirection }, |
| 1585 | { "0 0 10 10", SkPath::kConvex_Convexity, SkPathPriv::kUnknown_FirstDirection }, |
| 1586 | { "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity, SkPathPriv::kUnknown_FirstDirection }, |
| 1587 | { "0 0 10 10 10 20", SkPath::kConvex_Convexity, SkPathPriv::kCW_FirstDirection }, |
| 1588 | { "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPathPriv::kCCW_FirstDirection }, |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1589 | { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir }, |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1590 | { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity, SkPathPriv::kCW_FirstDirection }, |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1591 | }; |
| 1592 | |
| 1593 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1594 | SkPath path; |
| 1595 | setFromString(&path, gRec[i].fPathStr); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1596 | check_convexity(reporter, path, gRec[i].fExpectedConvexity); |
| 1597 | check_direction(reporter, path, gRec[i].fExpectedDirection); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1598 | // check after setting the initial convex and direction |
| 1599 | if (kDontCheckDir != gRec[i].fExpectedDirection) { |
| 1600 | SkPath copy(path); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 1601 | SkPathPriv::FirstDirection dir; |
| 1602 | bool foundDir = SkPathPriv::CheapComputeFirstDirection(copy, &dir); |
| 1603 | REPORTER_ASSERT(reporter, (gRec[i].fExpectedDirection == SkPathPriv::kUnknown_FirstDirection) |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1604 | ^ foundDir); |
| 1605 | REPORTER_ASSERT(reporter, !foundDir || gRec[i].fExpectedDirection == dir); |
| 1606 | check_convexity(reporter, copy, gRec[i].fExpectedConvexity); |
| 1607 | } |
| 1608 | REPORTER_ASSERT(reporter, gRec[i].fExpectedConvexity == path.getConvexity()); |
| 1609 | check_direction(reporter, path, gRec[i].fExpectedDirection); |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1610 | } |
caryclark | d3d1a98 | 2014-12-08 04:57:38 -0800 | [diff] [blame] | 1611 | |
| 1612 | static const SkPoint nonFinitePts[] = { |
| 1613 | { SK_ScalarInfinity, 0 }, |
| 1614 | { 0, SK_ScalarInfinity }, |
| 1615 | { SK_ScalarInfinity, SK_ScalarInfinity }, |
| 1616 | { SK_ScalarNegativeInfinity, 0}, |
| 1617 | { 0, SK_ScalarNegativeInfinity }, |
| 1618 | { SK_ScalarNegativeInfinity, SK_ScalarNegativeInfinity }, |
| 1619 | { SK_ScalarNegativeInfinity, SK_ScalarInfinity }, |
| 1620 | { SK_ScalarInfinity, SK_ScalarNegativeInfinity }, |
| 1621 | { SK_ScalarNaN, 0 }, |
| 1622 | { 0, SK_ScalarNaN }, |
| 1623 | { SK_ScalarNaN, SK_ScalarNaN }, |
| 1624 | }; |
| 1625 | |
| 1626 | const size_t nonFinitePtsCount = sizeof(nonFinitePts) / sizeof(nonFinitePts[0]); |
| 1627 | |
| 1628 | static const SkPoint finitePts[] = { |
| 1629 | { SK_ScalarMax, 0 }, |
| 1630 | { 0, SK_ScalarMax }, |
| 1631 | { SK_ScalarMax, SK_ScalarMax }, |
| 1632 | { SK_ScalarMin, 0 }, |
| 1633 | { 0, SK_ScalarMin }, |
| 1634 | { SK_ScalarMin, SK_ScalarMin }, |
| 1635 | }; |
| 1636 | |
| 1637 | const size_t finitePtsCount = sizeof(finitePts) / sizeof(finitePts[0]); |
| 1638 | |
| 1639 | for (int index = 0; index < (int) (13 * nonFinitePtsCount * finitePtsCount); ++index) { |
| 1640 | int i = (int) (index % nonFinitePtsCount); |
| 1641 | int f = (int) (index % finitePtsCount); |
| 1642 | int g = (int) ((f + 1) % finitePtsCount); |
| 1643 | path.reset(); |
| 1644 | switch (index % 13) { |
| 1645 | case 0: path.lineTo(nonFinitePts[i]); break; |
| 1646 | case 1: path.quadTo(nonFinitePts[i], nonFinitePts[i]); break; |
| 1647 | case 2: path.quadTo(nonFinitePts[i], finitePts[f]); break; |
| 1648 | case 3: path.quadTo(finitePts[f], nonFinitePts[i]); break; |
| 1649 | case 4: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[f]); break; |
| 1650 | case 5: path.cubicTo(finitePts[f], nonFinitePts[i], finitePts[f]); break; |
| 1651 | case 6: path.cubicTo(finitePts[f], finitePts[f], nonFinitePts[i]); break; |
| 1652 | case 7: path.cubicTo(nonFinitePts[i], nonFinitePts[i], finitePts[f]); break; |
| 1653 | case 8: path.cubicTo(nonFinitePts[i], finitePts[f], nonFinitePts[i]); break; |
| 1654 | case 9: path.cubicTo(finitePts[f], nonFinitePts[i], nonFinitePts[i]); break; |
| 1655 | case 10: path.cubicTo(nonFinitePts[i], nonFinitePts[i], nonFinitePts[i]); break; |
| 1656 | case 11: path.cubicTo(nonFinitePts[i], finitePts[f], finitePts[g]); break; |
| 1657 | case 12: path.moveTo(nonFinitePts[i]); break; |
| 1658 | } |
| 1659 | check_convexity(reporter, path, SkPath::kUnknown_Convexity); |
| 1660 | } |
| 1661 | |
| 1662 | for (int index = 0; index < (int) (11 * finitePtsCount); ++index) { |
| 1663 | int f = (int) (index % finitePtsCount); |
| 1664 | int g = (int) ((f + 1) % finitePtsCount); |
| 1665 | path.reset(); |
| 1666 | int curveSelect = index % 11; |
| 1667 | switch (curveSelect) { |
| 1668 | case 0: path.moveTo(finitePts[f]); break; |
| 1669 | case 1: path.lineTo(finitePts[f]); break; |
| 1670 | case 2: path.quadTo(finitePts[f], finitePts[f]); break; |
| 1671 | case 3: path.quadTo(finitePts[f], finitePts[g]); break; |
| 1672 | case 4: path.quadTo(finitePts[g], finitePts[f]); break; |
| 1673 | case 5: path.cubicTo(finitePts[f], finitePts[f], finitePts[f]); break; |
| 1674 | case 6: path.cubicTo(finitePts[f], finitePts[f], finitePts[g]); break; |
| 1675 | case 7: path.cubicTo(finitePts[f], finitePts[g], finitePts[f]); break; |
| 1676 | case 8: path.cubicTo(finitePts[f], finitePts[g], finitePts[g]); break; |
| 1677 | case 9: path.cubicTo(finitePts[g], finitePts[f], finitePts[f]); break; |
| 1678 | case 10: path.cubicTo(finitePts[g], finitePts[f], finitePts[g]); break; |
| 1679 | } |
| 1680 | check_convexity(reporter, path, curveSelect == 0 ? SkPath::kConvex_Convexity |
| 1681 | : SkPath::kUnknown_Convexity); |
| 1682 | } |
| 1683 | |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1684 | } |
| 1685 | |
reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 1686 | static void test_isLine(skiatest::Reporter* reporter) { |
| 1687 | SkPath path; |
| 1688 | SkPoint pts[2]; |
| 1689 | const SkScalar value = SkIntToScalar(5); |
| 1690 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1691 | REPORTER_ASSERT(reporter, !path.isLine(nullptr)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1692 | |
reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 1693 | // set some non-zero values |
| 1694 | pts[0].set(value, value); |
| 1695 | pts[1].set(value, value); |
| 1696 | REPORTER_ASSERT(reporter, !path.isLine(pts)); |
| 1697 | // check that pts was untouched |
| 1698 | REPORTER_ASSERT(reporter, pts[0].equals(value, value)); |
| 1699 | REPORTER_ASSERT(reporter, pts[1].equals(value, value)); |
| 1700 | |
| 1701 | const SkScalar moveX = SkIntToScalar(1); |
| 1702 | const SkScalar moveY = SkIntToScalar(2); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1703 | REPORTER_ASSERT(reporter, value != moveX && value != moveY); |
reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 1704 | |
| 1705 | path.moveTo(moveX, moveY); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1706 | REPORTER_ASSERT(reporter, !path.isLine(nullptr)); |
reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 1707 | REPORTER_ASSERT(reporter, !path.isLine(pts)); |
| 1708 | // check that pts was untouched |
| 1709 | REPORTER_ASSERT(reporter, pts[0].equals(value, value)); |
| 1710 | REPORTER_ASSERT(reporter, pts[1].equals(value, value)); |
| 1711 | |
| 1712 | const SkScalar lineX = SkIntToScalar(2); |
| 1713 | const SkScalar lineY = SkIntToScalar(2); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1714 | REPORTER_ASSERT(reporter, value != lineX && value != lineY); |
reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 1715 | |
| 1716 | path.lineTo(lineX, lineY); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1717 | REPORTER_ASSERT(reporter, path.isLine(nullptr)); |
reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 1718 | |
| 1719 | REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY)); |
| 1720 | REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY)); |
| 1721 | REPORTER_ASSERT(reporter, path.isLine(pts)); |
| 1722 | REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY)); |
| 1723 | REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY)); |
| 1724 | |
| 1725 | path.lineTo(0, 0); // too many points/verbs |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1726 | REPORTER_ASSERT(reporter, !path.isLine(nullptr)); |
reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 1727 | REPORTER_ASSERT(reporter, !path.isLine(pts)); |
| 1728 | REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY)); |
| 1729 | REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1730 | |
| 1731 | path.reset(); |
| 1732 | path.quadTo(1, 1, 2, 2); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1733 | REPORTER_ASSERT(reporter, !path.isLine(nullptr)); |
reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 1734 | } |
| 1735 | |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1736 | static void test_conservativelyContains(skiatest::Reporter* reporter) { |
| 1737 | SkPath path; |
| 1738 | |
| 1739 | // kBaseRect is used to construct most our test paths: a rect, a circle, and a round-rect. |
| 1740 | static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); |
| 1741 | |
| 1742 | // A circle that bounds kBaseRect (with a significant amount of slop) |
| 1743 | SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height()); |
Mike Reed | df85c38 | 2017-02-14 10:59:19 -0500 | [diff] [blame] | 1744 | circleR *= 1.75f / 2; |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1745 | static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()}; |
| 1746 | |
| 1747 | // round-rect radii |
| 1748 | static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)}; |
skia.committer@gmail.com | cec8de6 | 2012-11-14 02:01:22 +0000 | [diff] [blame] | 1749 | |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1750 | static const struct SUPPRESS_VISIBILITY_WARNING { |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1751 | SkRect fQueryRect; |
| 1752 | bool fInRect; |
| 1753 | bool fInCircle; |
| 1754 | bool fInRR; |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1755 | bool fInCubicRR; |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1756 | } kQueries[] = { |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1757 | {kBaseRect, true, true, false, false}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1758 | |
| 1759 | // rect well inside of kBaseRect |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 1760 | {SkRect::MakeLTRB(kBaseRect.fLeft + 0.25f*kBaseRect.width(), |
| 1761 | kBaseRect.fTop + 0.25f*kBaseRect.height(), |
| 1762 | kBaseRect.fRight - 0.25f*kBaseRect.width(), |
| 1763 | kBaseRect.fBottom - 0.25f*kBaseRect.height()), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1764 | true, true, true, true}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1765 | |
| 1766 | // rects with edges off by one from kBaseRect's edges |
| 1767 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, |
| 1768 | kBaseRect.width(), kBaseRect.height() + 1), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1769 | false, true, false, false}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1770 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, |
| 1771 | kBaseRect.width() + 1, kBaseRect.height()), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1772 | false, true, false, false}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1773 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, |
| 1774 | kBaseRect.width() + 1, kBaseRect.height() + 1), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1775 | false, true, false, false}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1776 | {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop, |
| 1777 | kBaseRect.width(), kBaseRect.height()), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1778 | false, true, false, false}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1779 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1, |
| 1780 | kBaseRect.width(), kBaseRect.height()), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1781 | false, true, false, false}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1782 | {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop, |
| 1783 | kBaseRect.width() + 2, kBaseRect.height()), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1784 | false, true, false, false}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1785 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1, |
| 1786 | kBaseRect.width() + 2, kBaseRect.height()), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1787 | false, true, false, false}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1788 | |
| 1789 | // zero-w/h rects at each corner of kBaseRect |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1790 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, false, false}, |
| 1791 | {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, false, true}, |
| 1792 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true, false, true}, |
| 1793 | {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true, false, true}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1794 | |
| 1795 | // far away rect |
| 1796 | {SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom, |
| 1797 | SkIntToScalar(10), SkIntToScalar(10)), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1798 | false, false, false, false}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1799 | |
| 1800 | // very large rect containing kBaseRect |
| 1801 | {SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(), |
| 1802 | kBaseRect.fTop - 5 * kBaseRect.height(), |
| 1803 | 11 * kBaseRect.width(), 11 * kBaseRect.height()), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1804 | false, false, false, false}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1805 | |
| 1806 | // skinny rect that spans same y-range as kBaseRect |
| 1807 | {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop, |
| 1808 | SkIntToScalar(1), kBaseRect.height()), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1809 | true, true, true, true}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1810 | |
| 1811 | // short rect that spans same x-range as kBaseRect |
| 1812 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(), SkScalar(1)), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1813 | true, true, true, true}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1814 | |
| 1815 | // skinny rect that spans slightly larger y-range than kBaseRect |
| 1816 | {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop, |
| 1817 | SkIntToScalar(1), kBaseRect.height() + 1), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1818 | false, true, false, false}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1819 | |
| 1820 | // short rect that spans slightly larger x-range than kBaseRect |
| 1821 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), |
| 1822 | kBaseRect.width() + 1, SkScalar(1)), |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1823 | false, true, false, false}, |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1824 | }; |
| 1825 | |
| 1826 | for (int inv = 0; inv < 4; ++inv) { |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1827 | for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) { |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1828 | SkRect qRect = kQueries[q].fQueryRect; |
| 1829 | if (inv & 0x1) { |
| 1830 | SkTSwap(qRect.fLeft, qRect.fRight); |
| 1831 | } |
| 1832 | if (inv & 0x2) { |
| 1833 | SkTSwap(qRect.fTop, qRect.fBottom); |
| 1834 | } |
| 1835 | for (int d = 0; d < 2; ++d) { |
| 1836 | SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW_Direction; |
| 1837 | path.reset(); |
| 1838 | path.addRect(kBaseRect, dir); |
| 1839 | REPORTER_ASSERT(reporter, kQueries[q].fInRect == |
| 1840 | path.conservativelyContainsRect(qRect)); |
| 1841 | |
| 1842 | path.reset(); |
| 1843 | path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir); |
| 1844 | REPORTER_ASSERT(reporter, kQueries[q].fInCircle == |
| 1845 | path.conservativelyContainsRect(qRect)); |
| 1846 | |
| 1847 | path.reset(); |
| 1848 | path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir); |
| 1849 | REPORTER_ASSERT(reporter, kQueries[q].fInRR == |
| 1850 | path.conservativelyContainsRect(qRect)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1851 | |
| 1852 | path.reset(); |
| 1853 | path.moveTo(kBaseRect.fLeft + kRRRadii[0], kBaseRect.fTop); |
| 1854 | path.cubicTo(kBaseRect.fLeft + kRRRadii[0] / 2, kBaseRect.fTop, |
| 1855 | kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1] / 2, |
| 1856 | kBaseRect.fLeft, kBaseRect.fTop + kRRRadii[1]); |
| 1857 | path.lineTo(kBaseRect.fLeft, kBaseRect.fBottom); |
| 1858 | path.lineTo(kBaseRect.fRight, kBaseRect.fBottom); |
| 1859 | path.lineTo(kBaseRect.fRight, kBaseRect.fTop); |
| 1860 | path.close(); |
| 1861 | REPORTER_ASSERT(reporter, kQueries[q].fInCubicRR == |
| 1862 | path.conservativelyContainsRect(qRect)); |
| 1863 | |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1864 | } |
| 1865 | // Slightly non-convex shape, shouldn't contain any rects. |
| 1866 | path.reset(); |
| 1867 | path.moveTo(0, 0); |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 1868 | path.lineTo(SkIntToScalar(50), 0.05f); |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1869 | path.lineTo(SkIntToScalar(100), 0); |
| 1870 | path.lineTo(SkIntToScalar(100), SkIntToScalar(100)); |
| 1871 | path.lineTo(0, SkIntToScalar(100)); |
| 1872 | path.close(); |
| 1873 | REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect)); |
| 1874 | } |
| 1875 | } |
| 1876 | |
| 1877 | // make sure a minimal convex shape works, a right tri with edges along pos x and y axes. |
| 1878 | path.reset(); |
| 1879 | path.moveTo(0, 0); |
| 1880 | path.lineTo(SkIntToScalar(100), 0); |
| 1881 | path.lineTo(0, SkIntToScalar(100)); |
| 1882 | |
| 1883 | // inside, on along top edge |
| 1884 | REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0, |
| 1885 | SkIntToScalar(10), |
| 1886 | SkIntToScalar(10)))); |
| 1887 | // above |
| 1888 | REPORTER_ASSERT(reporter, !path.conservativelyContainsRect( |
| 1889 | SkRect::MakeXYWH(SkIntToScalar(50), |
| 1890 | SkIntToScalar(-10), |
| 1891 | SkIntToScalar(10), |
| 1892 | SkIntToScalar(10)))); |
| 1893 | // to the left |
| 1894 | REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(-10), |
| 1895 | SkIntToScalar(5), |
| 1896 | SkIntToScalar(5), |
| 1897 | SkIntToScalar(5)))); |
| 1898 | |
| 1899 | // outside the diagonal edge |
| 1900 | REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(10), |
| 1901 | SkIntToScalar(200), |
| 1902 | SkIntToScalar(20), |
| 1903 | SkIntToScalar(5)))); |
commit-bot@chromium.org | 62df526 | 2013-08-01 15:35:06 +0000 | [diff] [blame] | 1904 | |
bsalomon | b17c129 | 2014-08-28 14:04:55 -0700 | [diff] [blame] | 1905 | |
| 1906 | // Test that multiple move commands do not cause asserts. |
| 1907 | |
| 1908 | // At the time of writing, this would not modify cached convexity. This caused an assert while |
halcanary | 6950de6 | 2015-11-07 05:29:00 -0800 | [diff] [blame] | 1909 | // checking conservative containment again. https://bug.skia.org/1460 |
bsalomon | b17c129 | 2014-08-28 14:04:55 -0700 | [diff] [blame] | 1910 | path.moveTo(SkIntToScalar(100), SkIntToScalar(100)); |
| 1911 | #if 0 |
| 1912 | REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0, |
| 1913 | SkIntToScalar(10), |
| 1914 | SkIntToScalar(10)))); |
| 1915 | #endif |
| 1916 | |
| 1917 | // Same as above path and first test but with an extra moveTo. |
commit-bot@chromium.org | 62df526 | 2013-08-01 15:35:06 +0000 | [diff] [blame] | 1918 | path.reset(); |
| 1919 | path.moveTo(100, 100); |
| 1920 | path.moveTo(0, 0); |
| 1921 | path.lineTo(SkIntToScalar(100), 0); |
| 1922 | path.lineTo(0, SkIntToScalar(100)); |
| 1923 | |
| 1924 | REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0, |
| 1925 | SkIntToScalar(10), |
| 1926 | SkIntToScalar(10)))); |
| 1927 | |
Lee Salzman | a19f024 | 2017-01-12 13:06:21 -0500 | [diff] [blame] | 1928 | // Same as above path and first test but with the extra moveTo making a degenerate sub-path |
| 1929 | // following the non-empty sub-path. Verifies that this does not trigger assertions. |
| 1930 | path.reset(); |
| 1931 | path.moveTo(0, 0); |
| 1932 | path.lineTo(SkIntToScalar(100), 0); |
| 1933 | path.lineTo(0, SkIntToScalar(100)); |
| 1934 | path.moveTo(100, 100); |
| 1935 | |
| 1936 | REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0, |
| 1937 | SkIntToScalar(10), |
| 1938 | SkIntToScalar(10)))); |
| 1939 | |
bsalomon | b17c129 | 2014-08-28 14:04:55 -0700 | [diff] [blame] | 1940 | // Test that multiple move commands do not cause asserts and that the function |
| 1941 | // is not confused by the multiple moves. |
| 1942 | path.reset(); |
| 1943 | path.moveTo(0, 0); |
| 1944 | path.lineTo(SkIntToScalar(100), 0); |
| 1945 | path.lineTo(0, SkIntToScalar(100)); |
| 1946 | path.moveTo(0, SkIntToScalar(200)); |
| 1947 | path.lineTo(SkIntToScalar(100), SkIntToScalar(200)); |
| 1948 | path.lineTo(0, SkIntToScalar(300)); |
| 1949 | |
| 1950 | REPORTER_ASSERT(reporter, !path.conservativelyContainsRect( |
| 1951 | SkRect::MakeXYWH(SkIntToScalar(50), 0, |
| 1952 | SkIntToScalar(10), |
| 1953 | SkIntToScalar(10)))); |
| 1954 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 1955 | path.reset(); |
| 1956 | path.lineTo(100, 100); |
| 1957 | REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(0, 0, 1, 1))); |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1958 | } |
| 1959 | |
reed@google.com | f32322b | 2013-10-16 15:14:04 +0000 | [diff] [blame] | 1960 | static void test_isRect_open_close(skiatest::Reporter* reporter) { |
| 1961 | SkPath path; |
| 1962 | bool isClosed; |
| 1963 | |
| 1964 | path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1); |
reed@google.com | f32322b | 2013-10-16 15:14:04 +0000 | [diff] [blame] | 1965 | path.close(); |
commit-bot@chromium.org | 05ec223 | 2014-01-15 18:00:57 +0000 | [diff] [blame] | 1966 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 1967 | REPORTER_ASSERT(reporter, path.isRect(nullptr, &isClosed, nullptr)); |
reed@google.com | f32322b | 2013-10-16 15:14:04 +0000 | [diff] [blame] | 1968 | REPORTER_ASSERT(reporter, isClosed); |
| 1969 | } |
| 1970 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1971 | // Simple isRect test is inline TestPath, below. |
| 1972 | // test_isRect provides more extensive testing. |
| 1973 | static void test_isRect(skiatest::Reporter* reporter) { |
reed@google.com | f32322b | 2013-10-16 15:14:04 +0000 | [diff] [blame] | 1974 | test_isRect_open_close(reporter); |
| 1975 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1976 | // passing tests (all moveTo / lineTo... |
| 1977 | SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; |
| 1978 | SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
| 1979 | SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}}; |
| 1980 | SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}}; |
| 1981 | SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; |
| 1982 | SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| 1983 | SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}}; |
| 1984 | SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}}; |
| 1985 | SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1986 | SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; |
| 1987 | SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, {0, 1}, {0, .5f}}; |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1988 | SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
| 1989 | SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| 1990 | SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; |
caryclark@google.com | bfe9037 | 2012-11-21 13:56:20 +0000 | [diff] [blame] | 1991 | SkPoint rf[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}}; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1992 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1993 | // failing tests |
| 1994 | SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points |
| 1995 | SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal |
| 1996 | SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps |
| 1997 | SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up |
| 1998 | SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots |
| 1999 | SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots |
| 2000 | SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots |
| 2001 | SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L' |
caryclark@google.com | bfe9037 | 2012-11-21 13:56:20 +0000 | [diff] [blame] | 2002 | SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps |
| 2003 | SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non colinear gap |
| 2004 | SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 2005 | |
commit-bot@chromium.org | 05ec223 | 2014-01-15 18:00:57 +0000 | [diff] [blame] | 2006 | // no close, but we should detect them as fillably the same as a rect |
| 2007 | SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; |
| 2008 | SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; |
| 2009 | SkPoint c3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 0}}; // hit the start |
| 2010 | |
| 2011 | // like c2, but we double-back on ourselves |
| 2012 | SkPoint d1[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 2}}; |
| 2013 | // like c2, but we overshoot the start point |
| 2014 | SkPoint d2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}}; |
| 2015 | SkPoint d3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}, {0, 0}}; |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2016 | |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2017 | struct IsRectTest { |
| 2018 | SkPoint *fPoints; |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2019 | int fPointCount; |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2020 | bool fClose; |
| 2021 | bool fIsRect; |
| 2022 | } tests[] = { |
| 2023 | { r1, SK_ARRAY_COUNT(r1), true, true }, |
| 2024 | { r2, SK_ARRAY_COUNT(r2), true, true }, |
| 2025 | { r3, SK_ARRAY_COUNT(r3), true, true }, |
| 2026 | { r4, SK_ARRAY_COUNT(r4), true, true }, |
| 2027 | { r5, SK_ARRAY_COUNT(r5), true, true }, |
| 2028 | { r6, SK_ARRAY_COUNT(r6), true, true }, |
| 2029 | { r7, SK_ARRAY_COUNT(r7), true, true }, |
| 2030 | { r8, SK_ARRAY_COUNT(r8), true, true }, |
| 2031 | { r9, SK_ARRAY_COUNT(r9), true, true }, |
| 2032 | { ra, SK_ARRAY_COUNT(ra), true, true }, |
| 2033 | { rb, SK_ARRAY_COUNT(rb), true, true }, |
| 2034 | { rc, SK_ARRAY_COUNT(rc), true, true }, |
| 2035 | { rd, SK_ARRAY_COUNT(rd), true, true }, |
| 2036 | { re, SK_ARRAY_COUNT(re), true, true }, |
| 2037 | { rf, SK_ARRAY_COUNT(rf), true, true }, |
| 2038 | |
| 2039 | { f1, SK_ARRAY_COUNT(f1), true, false }, |
| 2040 | { f2, SK_ARRAY_COUNT(f2), true, false }, |
| 2041 | { f3, SK_ARRAY_COUNT(f3), true, false }, |
| 2042 | { f4, SK_ARRAY_COUNT(f4), true, false }, |
| 2043 | { f5, SK_ARRAY_COUNT(f5), true, false }, |
| 2044 | { f6, SK_ARRAY_COUNT(f6), true, false }, |
| 2045 | { f7, SK_ARRAY_COUNT(f7), true, false }, |
| 2046 | { f8, SK_ARRAY_COUNT(f8), true, false }, |
| 2047 | { f9, SK_ARRAY_COUNT(f9), true, false }, |
| 2048 | { fa, SK_ARRAY_COUNT(fa), true, false }, |
| 2049 | { fb, SK_ARRAY_COUNT(fb), true, false }, |
| 2050 | |
commit-bot@chromium.org | 05ec223 | 2014-01-15 18:00:57 +0000 | [diff] [blame] | 2051 | { c1, SK_ARRAY_COUNT(c1), false, true }, |
| 2052 | { c2, SK_ARRAY_COUNT(c2), false, true }, |
| 2053 | { c3, SK_ARRAY_COUNT(c3), false, true }, |
| 2054 | |
| 2055 | { d1, SK_ARRAY_COUNT(d1), false, false }, |
| 2056 | { d2, SK_ARRAY_COUNT(d2), false, false }, |
| 2057 | { d3, SK_ARRAY_COUNT(d3), false, false }, |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2058 | }; |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2059 | |
| 2060 | const size_t testCount = SK_ARRAY_COUNT(tests); |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2061 | int index; |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2062 | for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { |
| 2063 | SkPath path; |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2064 | path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY); |
| 2065 | for (index = 1; index < tests[testIndex].fPointCount; ++index) { |
| 2066 | path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY); |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2067 | } |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2068 | if (tests[testIndex].fClose) { |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2069 | path.close(); |
| 2070 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2071 | REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(nullptr)); |
caryclark@google.com | f68154a | 2012-11-21 15:18:06 +0000 | [diff] [blame] | 2072 | |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2073 | if (tests[testIndex].fIsRect) { |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2074 | SkRect computed, expected; |
caryclark@google.com | f68154a | 2012-11-21 15:18:06 +0000 | [diff] [blame] | 2075 | bool isClosed; |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2076 | SkPath::Direction direction; |
| 2077 | SkPathPriv::FirstDirection cheapDirection; |
robertphillips | 91b0a35 | 2015-01-05 10:13:46 -0800 | [diff] [blame] | 2078 | expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2079 | REPORTER_ASSERT(reporter, SkPathPriv::CheapComputeFirstDirection(path, &cheapDirection)); |
robertphillips | 91b0a35 | 2015-01-05 10:13:46 -0800 | [diff] [blame] | 2080 | REPORTER_ASSERT(reporter, path.isRect(&computed, &isClosed, &direction)); |
| 2081 | REPORTER_ASSERT(reporter, expected == computed); |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2082 | REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2083 | REPORTER_ASSERT(reporter, SkPathPriv::AsFirstDirection(direction) == cheapDirection); |
caryclark@google.com | f68154a | 2012-11-21 15:18:06 +0000 | [diff] [blame] | 2084 | } else { |
| 2085 | SkRect computed; |
| 2086 | computed.set(123, 456, 789, 1011); |
robertphillips | 91b0a35 | 2015-01-05 10:13:46 -0800 | [diff] [blame] | 2087 | bool isClosed = (bool)-1; |
| 2088 | SkPath::Direction direction = (SkPath::Direction) - 1; |
| 2089 | REPORTER_ASSERT(reporter, !path.isRect(&computed, &isClosed, &direction)); |
caryclark@google.com | f68154a | 2012-11-21 15:18:06 +0000 | [diff] [blame] | 2090 | REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456); |
| 2091 | REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011); |
caryclark@google.com | f68154a | 2012-11-21 15:18:06 +0000 | [diff] [blame] | 2092 | REPORTER_ASSERT(reporter, isClosed == (bool) -1); |
| 2093 | REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1); |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2094 | } |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2095 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 2096 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2097 | // fail, close then line |
| 2098 | SkPath path1; |
| 2099 | path1.moveTo(r1[0].fX, r1[0].fY); |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2100 | for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2101 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 2102 | } |
| 2103 | path1.close(); |
| 2104 | path1.lineTo(1, 0); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2105 | REPORTER_ASSERT(reporter, !path1.isRect(nullptr)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 2106 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2107 | // fail, move in the middle |
| 2108 | path1.reset(); |
| 2109 | path1.moveTo(r1[0].fX, r1[0].fY); |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2110 | for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2111 | if (index == 2) { |
| 2112 | path1.moveTo(1, .5f); |
| 2113 | } |
| 2114 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 2115 | } |
| 2116 | path1.close(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2117 | REPORTER_ASSERT(reporter, !path1.isRect(nullptr)); |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2118 | |
| 2119 | // fail, move on the edge |
| 2120 | path1.reset(); |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2121 | for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2122 | path1.moveTo(r1[index - 1].fX, r1[index - 1].fY); |
| 2123 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 2124 | } |
| 2125 | path1.close(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2126 | REPORTER_ASSERT(reporter, !path1.isRect(nullptr)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 2127 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2128 | // fail, quad |
| 2129 | path1.reset(); |
| 2130 | path1.moveTo(r1[0].fX, r1[0].fY); |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2131 | for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2132 | if (index == 2) { |
| 2133 | path1.quadTo(1, .5f, 1, .5f); |
| 2134 | } |
| 2135 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 2136 | } |
| 2137 | path1.close(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2138 | REPORTER_ASSERT(reporter, !path1.isRect(nullptr)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 2139 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2140 | // fail, cubic |
| 2141 | path1.reset(); |
| 2142 | path1.moveTo(r1[0].fX, r1[0].fY); |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2143 | for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2144 | if (index == 2) { |
| 2145 | path1.cubicTo(1, .5f, 1, .5f, 1, .5f); |
| 2146 | } |
| 2147 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 2148 | } |
| 2149 | path1.close(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2150 | REPORTER_ASSERT(reporter, !path1.isRect(nullptr)); |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2151 | } |
| 2152 | |
bsalomon | edc743a | 2016-06-01 09:42:31 -0700 | [diff] [blame] | 2153 | static void check_simple_closed_rect(skiatest::Reporter* reporter, const SkPath& path, |
| 2154 | const SkRect& rect, SkPath::Direction dir, unsigned start) { |
| 2155 | SkRect r = SkRect::MakeEmpty(); |
| 2156 | SkPath::Direction d = SkPath::kCCW_Direction; |
| 2157 | unsigned s = ~0U; |
| 2158 | |
| 2159 | REPORTER_ASSERT(reporter, SkPathPriv::IsSimpleClosedRect(path, &r, &d, &s)); |
| 2160 | REPORTER_ASSERT(reporter, r == rect); |
| 2161 | REPORTER_ASSERT(reporter, d == dir); |
| 2162 | REPORTER_ASSERT(reporter, s == start); |
| 2163 | } |
| 2164 | |
| 2165 | static void test_is_simple_closed_rect(skiatest::Reporter* reporter) { |
| 2166 | SkRect r = SkRect::MakeEmpty(); |
| 2167 | SkPath::Direction d = SkPath::kCCW_Direction; |
| 2168 | unsigned s = ~0U; |
| 2169 | |
| 2170 | const SkRect testRect = SkRect::MakeXYWH(10, 10, 50, 70); |
| 2171 | const SkRect emptyRect = SkRect::MakeEmpty(); |
| 2172 | SkPath path; |
| 2173 | for (int start = 0; start < 4; ++start) { |
| 2174 | for (auto dir : {SkPath::kCCW_Direction, SkPath::kCW_Direction}) { |
| 2175 | SkPath path; |
| 2176 | path.addRect(testRect, dir, start); |
| 2177 | check_simple_closed_rect(reporter, path, testRect, dir, start); |
| 2178 | path.close(); |
| 2179 | check_simple_closed_rect(reporter, path, testRect, dir, start); |
| 2180 | SkPath path2 = path; |
| 2181 | path2.lineTo(10, 10); |
| 2182 | REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s)); |
| 2183 | path2 = path; |
| 2184 | path2.moveTo(10, 10); |
| 2185 | REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s)); |
| 2186 | path2 = path; |
| 2187 | path2.addRect(testRect, dir, start); |
| 2188 | REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s)); |
| 2189 | // Make the path by hand, manually closing it. |
| 2190 | path2.reset(); |
| 2191 | SkPath::RawIter iter(path); |
| 2192 | SkPath::Verb v; |
| 2193 | SkPoint verbPts[4]; |
| 2194 | SkPoint firstPt = {0.f, 0.f}; |
| 2195 | while ((v = iter.next(verbPts)) != SkPath::kDone_Verb) { |
| 2196 | switch(v) { |
| 2197 | case SkPath::kMove_Verb: |
| 2198 | firstPt = verbPts[0]; |
| 2199 | path2.moveTo(verbPts[0]); |
| 2200 | break; |
| 2201 | case SkPath::kLine_Verb: |
| 2202 | path2.lineTo(verbPts[1]); |
| 2203 | break; |
| 2204 | default: |
| 2205 | break; |
| 2206 | } |
| 2207 | } |
| 2208 | // We haven't closed it yet... |
| 2209 | REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s)); |
| 2210 | // ... now we do and test again. |
| 2211 | path2.lineTo(firstPt); |
| 2212 | check_simple_closed_rect(reporter, path2, testRect, dir, start); |
| 2213 | // A redundant close shouldn't cause a failure. |
| 2214 | path2.close(); |
| 2215 | check_simple_closed_rect(reporter, path2, testRect, dir, start); |
| 2216 | // Degenerate point and line rects are not allowed |
| 2217 | path2.reset(); |
| 2218 | path2.addRect(emptyRect, dir, start); |
| 2219 | REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s)); |
| 2220 | SkRect degenRect = testRect; |
| 2221 | degenRect.fLeft = degenRect.fRight; |
| 2222 | path2.reset(); |
| 2223 | path2.addRect(degenRect, dir, start); |
| 2224 | REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s)); |
| 2225 | degenRect = testRect; |
| 2226 | degenRect.fTop = degenRect.fBottom; |
| 2227 | path2.reset(); |
| 2228 | path2.addRect(degenRect, dir, start); |
| 2229 | REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path2, &r, &d, &s)); |
| 2230 | // An inverted rect makes a rect path, but changes the winding dir and start point. |
| 2231 | SkPath::Direction swapDir = (dir == SkPath::kCW_Direction) |
| 2232 | ? SkPath::kCCW_Direction |
| 2233 | : SkPath::kCW_Direction; |
| 2234 | static constexpr unsigned kXSwapStarts[] = { 1, 0, 3, 2 }; |
| 2235 | static constexpr unsigned kYSwapStarts[] = { 3, 2, 1, 0 }; |
| 2236 | SkRect swapRect = testRect; |
| 2237 | SkTSwap(swapRect.fLeft, swapRect.fRight); |
| 2238 | path2.reset(); |
| 2239 | path2.addRect(swapRect, dir, start); |
| 2240 | check_simple_closed_rect(reporter, path2, testRect, swapDir, kXSwapStarts[start]); |
| 2241 | swapRect = testRect; |
| 2242 | SkTSwap(swapRect.fTop, swapRect.fBottom); |
| 2243 | path2.reset(); |
| 2244 | path2.addRect(swapRect, dir, start); |
| 2245 | check_simple_closed_rect(reporter, path2, testRect, swapDir, kYSwapStarts[start]); |
| 2246 | } |
| 2247 | } |
bsalomon | 057ae8a | 2016-07-24 05:37:26 -0700 | [diff] [blame] | 2248 | // down, up, left, close |
| 2249 | path.reset(); |
| 2250 | path.moveTo(1, 1); |
| 2251 | path.lineTo(1, 2); |
| 2252 | path.lineTo(1, 1); |
| 2253 | path.lineTo(0, 1); |
| 2254 | SkRect rect; |
| 2255 | SkPath::Direction dir; |
| 2256 | unsigned start; |
| 2257 | path.close(); |
| 2258 | REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path, &rect, &dir, &start)); |
| 2259 | // right, left, up, close |
| 2260 | path.reset(); |
| 2261 | path.moveTo(1, 1); |
| 2262 | path.lineTo(2, 1); |
| 2263 | path.lineTo(1, 1); |
| 2264 | path.lineTo(1, 0); |
| 2265 | path.close(); |
| 2266 | REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path, &rect, &dir, &start)); |
| 2267 | // parallelogram with horizontal edges |
| 2268 | path.reset(); |
| 2269 | path.moveTo(1, 0); |
| 2270 | path.lineTo(3, 0); |
| 2271 | path.lineTo(2, 1); |
| 2272 | path.lineTo(0, 1); |
| 2273 | path.close(); |
| 2274 | REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path, &rect, &dir, &start)); |
| 2275 | // parallelogram with vertical edges |
| 2276 | path.reset(); |
| 2277 | path.moveTo(0, 1); |
| 2278 | path.lineTo(0, 3); |
| 2279 | path.lineTo(1, 2); |
| 2280 | path.lineTo(1, 0); |
| 2281 | path.close(); |
| 2282 | REPORTER_ASSERT(reporter, !SkPathPriv::IsSimpleClosedRect(path, &rect, &dir, &start)); |
| 2283 | |
bsalomon | edc743a | 2016-06-01 09:42:31 -0700 | [diff] [blame] | 2284 | } |
| 2285 | |
caryclark | 95bc5f3 | 2015-04-08 08:34:15 -0700 | [diff] [blame] | 2286 | static void test_isNestedFillRects(skiatest::Reporter* reporter) { |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2287 | // passing tests (all moveTo / lineTo... |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 2288 | SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2289 | SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
| 2290 | SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}}; |
| 2291 | SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}}; |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 2292 | SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2293 | SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| 2294 | SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}}; |
| 2295 | SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}}; |
| 2296 | SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2297 | SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; // CCW |
| 2298 | SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, {0, 1}, {0, .5f}}; // CW |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 2299 | SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW |
| 2300 | SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW |
| 2301 | SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2302 | |
| 2303 | // failing tests |
| 2304 | SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points |
| 2305 | SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal |
| 2306 | SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps |
| 2307 | SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up |
| 2308 | SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots |
| 2309 | SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots |
| 2310 | SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots |
| 2311 | SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L' |
| 2312 | |
caryclark | 95bc5f3 | 2015-04-08 08:34:15 -0700 | [diff] [blame] | 2313 | // success, no close is OK |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2314 | SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match |
| 2315 | SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto |
| 2316 | |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2317 | struct IsNestedRectTest { |
| 2318 | SkPoint *fPoints; |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2319 | int fPointCount; |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2320 | SkPathPriv::FirstDirection fDirection; |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2321 | bool fClose; |
| 2322 | bool fIsNestedRect; // nests with path.addRect(-1, -1, 2, 2); |
| 2323 | } tests[] = { |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2324 | { r1, SK_ARRAY_COUNT(r1), SkPathPriv::kCW_FirstDirection , true, true }, |
| 2325 | { r2, SK_ARRAY_COUNT(r2), SkPathPriv::kCW_FirstDirection , true, true }, |
| 2326 | { r3, SK_ARRAY_COUNT(r3), SkPathPriv::kCW_FirstDirection , true, true }, |
| 2327 | { r4, SK_ARRAY_COUNT(r4), SkPathPriv::kCW_FirstDirection , true, true }, |
| 2328 | { r5, SK_ARRAY_COUNT(r5), SkPathPriv::kCCW_FirstDirection, true, true }, |
| 2329 | { r6, SK_ARRAY_COUNT(r6), SkPathPriv::kCCW_FirstDirection, true, true }, |
| 2330 | { r7, SK_ARRAY_COUNT(r7), SkPathPriv::kCCW_FirstDirection, true, true }, |
| 2331 | { r8, SK_ARRAY_COUNT(r8), SkPathPriv::kCCW_FirstDirection, true, true }, |
| 2332 | { r9, SK_ARRAY_COUNT(r9), SkPathPriv::kCCW_FirstDirection, true, true }, |
| 2333 | { ra, SK_ARRAY_COUNT(ra), SkPathPriv::kCCW_FirstDirection, true, true }, |
| 2334 | { rb, SK_ARRAY_COUNT(rb), SkPathPriv::kCW_FirstDirection, true, true }, |
| 2335 | { rc, SK_ARRAY_COUNT(rc), SkPathPriv::kCW_FirstDirection, true, true }, |
| 2336 | { rd, SK_ARRAY_COUNT(rd), SkPathPriv::kCCW_FirstDirection, true, true }, |
| 2337 | { re, SK_ARRAY_COUNT(re), SkPathPriv::kCW_FirstDirection, true, true }, |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 2338 | |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2339 | { f1, SK_ARRAY_COUNT(f1), SkPathPriv::kUnknown_FirstDirection, true, false }, |
| 2340 | { f2, SK_ARRAY_COUNT(f2), SkPathPriv::kUnknown_FirstDirection, true, false }, |
| 2341 | { f3, SK_ARRAY_COUNT(f3), SkPathPriv::kUnknown_FirstDirection, true, false }, |
| 2342 | { f4, SK_ARRAY_COUNT(f4), SkPathPriv::kUnknown_FirstDirection, true, false }, |
| 2343 | { f5, SK_ARRAY_COUNT(f5), SkPathPriv::kUnknown_FirstDirection, true, false }, |
| 2344 | { f6, SK_ARRAY_COUNT(f6), SkPathPriv::kUnknown_FirstDirection, true, false }, |
| 2345 | { f7, SK_ARRAY_COUNT(f7), SkPathPriv::kUnknown_FirstDirection, true, false }, |
| 2346 | { f8, SK_ARRAY_COUNT(f8), SkPathPriv::kUnknown_FirstDirection, true, false }, |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2347 | |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2348 | { c1, SK_ARRAY_COUNT(c1), SkPathPriv::kCW_FirstDirection, false, true }, |
| 2349 | { c2, SK_ARRAY_COUNT(c2), SkPathPriv::kCW_FirstDirection, false, true }, |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2350 | }; |
| 2351 | |
| 2352 | const size_t testCount = SK_ARRAY_COUNT(tests); |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2353 | int index; |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2354 | for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) { |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2355 | for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { |
| 2356 | SkPath path; |
| 2357 | if (rectFirst) { |
| 2358 | path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); |
| 2359 | } |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2360 | path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY); |
| 2361 | for (index = 1; index < tests[testIndex].fPointCount; ++index) { |
| 2362 | path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPoints[index].fY); |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2363 | } |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2364 | if (tests[testIndex].fClose) { |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2365 | path.close(); |
| 2366 | } |
| 2367 | if (!rectFirst) { |
| 2368 | path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); |
| 2369 | } |
caryclark | 95bc5f3 | 2015-04-08 08:34:15 -0700 | [diff] [blame] | 2370 | REPORTER_ASSERT(reporter, |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2371 | tests[testIndex].fIsNestedRect == path.isNestedFillRects(nullptr)); |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2372 | if (tests[testIndex].fIsNestedRect) { |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2373 | SkRect expected[2], computed[2]; |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2374 | SkPathPriv::FirstDirection expectedDirs[2]; |
| 2375 | SkPath::Direction computedDirs[2]; |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2376 | SkRect testBounds; |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2377 | testBounds.set(tests[testIndex].fPoints, tests[testIndex].fPointCount); |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2378 | expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2); |
| 2379 | expected[1] = testBounds; |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 2380 | if (rectFirst) { |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2381 | expectedDirs[0] = SkPathPriv::kCW_FirstDirection; |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 2382 | } else { |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2383 | expectedDirs[0] = SkPathPriv::kCCW_FirstDirection; |
robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 2384 | } |
bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 2385 | expectedDirs[1] = tests[testIndex].fDirection; |
caryclark | 95bc5f3 | 2015-04-08 08:34:15 -0700 | [diff] [blame] | 2386 | REPORTER_ASSERT(reporter, path.isNestedFillRects(computed, computedDirs)); |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2387 | REPORTER_ASSERT(reporter, expected[0] == computed[0]); |
| 2388 | REPORTER_ASSERT(reporter, expected[1] == computed[1]); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2389 | REPORTER_ASSERT(reporter, expectedDirs[0] == SkPathPriv::AsFirstDirection(computedDirs[0])); |
| 2390 | REPORTER_ASSERT(reporter, expectedDirs[1] == SkPathPriv::AsFirstDirection(computedDirs[1])); |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2391 | } |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2392 | } |
| 2393 | |
| 2394 | // fail, close then line |
| 2395 | SkPath path1; |
| 2396 | if (rectFirst) { |
| 2397 | path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); |
| 2398 | } |
| 2399 | path1.moveTo(r1[0].fX, r1[0].fY); |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2400 | for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2401 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 2402 | } |
| 2403 | path1.close(); |
| 2404 | path1.lineTo(1, 0); |
| 2405 | if (!rectFirst) { |
| 2406 | path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); |
| 2407 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2408 | REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr)); |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2409 | |
| 2410 | // fail, move in the middle |
| 2411 | path1.reset(); |
| 2412 | if (rectFirst) { |
| 2413 | path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); |
| 2414 | } |
| 2415 | path1.moveTo(r1[0].fX, r1[0].fY); |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2416 | for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2417 | if (index == 2) { |
| 2418 | path1.moveTo(1, .5f); |
| 2419 | } |
| 2420 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 2421 | } |
| 2422 | path1.close(); |
| 2423 | if (!rectFirst) { |
| 2424 | path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); |
| 2425 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2426 | REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr)); |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2427 | |
| 2428 | // fail, move on the edge |
| 2429 | path1.reset(); |
| 2430 | if (rectFirst) { |
| 2431 | path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); |
| 2432 | } |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2433 | for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2434 | path1.moveTo(r1[index - 1].fX, r1[index - 1].fY); |
| 2435 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 2436 | } |
| 2437 | path1.close(); |
| 2438 | if (!rectFirst) { |
| 2439 | path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); |
| 2440 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2441 | REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr)); |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2442 | |
| 2443 | // fail, quad |
| 2444 | path1.reset(); |
| 2445 | if (rectFirst) { |
| 2446 | path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); |
| 2447 | } |
| 2448 | path1.moveTo(r1[0].fX, r1[0].fY); |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2449 | for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2450 | if (index == 2) { |
| 2451 | path1.quadTo(1, .5f, 1, .5f); |
| 2452 | } |
| 2453 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 2454 | } |
| 2455 | path1.close(); |
| 2456 | if (!rectFirst) { |
| 2457 | path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); |
| 2458 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2459 | REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr)); |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2460 | |
| 2461 | // fail, cubic |
| 2462 | path1.reset(); |
| 2463 | if (rectFirst) { |
| 2464 | path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); |
| 2465 | } |
| 2466 | path1.moveTo(r1[0].fX, r1[0].fY); |
bsalomon | 9880607 | 2014-12-12 15:11:17 -0800 | [diff] [blame] | 2467 | for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2468 | if (index == 2) { |
| 2469 | path1.cubicTo(1, .5f, 1, .5f, 1, .5f); |
| 2470 | } |
| 2471 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 2472 | } |
| 2473 | path1.close(); |
| 2474 | if (!rectFirst) { |
| 2475 | path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); |
| 2476 | } |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2477 | REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr)); |
skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 2478 | |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2479 | // fail, not nested |
| 2480 | path1.reset(); |
| 2481 | path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction); |
| 2482 | path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2483 | REPORTER_ASSERT(reporter, !path1.isNestedFillRects(nullptr)); |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2484 | } |
caryclark@google.com | bfe9037 | 2012-11-21 13:56:20 +0000 | [diff] [blame] | 2485 | |
caryclark | 95bc5f3 | 2015-04-08 08:34:15 -0700 | [diff] [blame] | 2486 | // pass, constructed explicitly from manually closed rects specified as moves/lines. |
| 2487 | SkPath path; |
| 2488 | path.moveTo(0, 0); |
| 2489 | path.lineTo(10, 0); |
| 2490 | path.lineTo(10, 10); |
| 2491 | path.lineTo(0, 10); |
| 2492 | path.lineTo(0, 0); |
| 2493 | path.moveTo(1, 1); |
| 2494 | path.lineTo(9, 1); |
| 2495 | path.lineTo(9, 9); |
| 2496 | path.lineTo(1, 9); |
| 2497 | path.lineTo(1, 1); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2498 | REPORTER_ASSERT(reporter, path.isNestedFillRects(nullptr)); |
caryclark | 95bc5f3 | 2015-04-08 08:34:15 -0700 | [diff] [blame] | 2499 | |
caryclark@google.com | bfe9037 | 2012-11-21 13:56:20 +0000 | [diff] [blame] | 2500 | // pass, stroke rect |
| 2501 | SkPath src, dst; |
| 2502 | src.addRect(1, 1, 7, 7, SkPath::kCW_Direction); |
| 2503 | SkPaint strokePaint; |
| 2504 | strokePaint.setStyle(SkPaint::kStroke_Style); |
| 2505 | strokePaint.setStrokeWidth(2); |
| 2506 | strokePaint.getFillPath(src, &dst); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2507 | REPORTER_ASSERT(reporter, dst.isNestedFillRects(nullptr)); |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2508 | } |
| 2509 | |
robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 2510 | static void write_and_read_back(skiatest::Reporter* reporter, |
| 2511 | const SkPath& p) { |
commit-bot@chromium.org | 1938242 | 2014-01-14 20:51:26 +0000 | [diff] [blame] | 2512 | SkWriter32 writer; |
robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 2513 | writer.writePath(p); |
reed@google.com | 4469938 | 2013-10-31 17:28:30 +0000 | [diff] [blame] | 2514 | size_t size = writer.bytesWritten(); |
robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 2515 | SkAutoMalloc storage(size); |
| 2516 | writer.flatten(storage.get()); |
| 2517 | SkReader32 reader(storage.get(), size); |
| 2518 | |
| 2519 | SkPath readBack; |
| 2520 | REPORTER_ASSERT(reporter, readBack != p); |
| 2521 | reader.readPath(&readBack); |
| 2522 | REPORTER_ASSERT(reporter, readBack == p); |
| 2523 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 2524 | REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() == |
robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 2525 | p.getConvexityOrUnknown()); |
| 2526 | |
bsalomon | 78d58d1 | 2016-05-27 09:17:04 -0700 | [diff] [blame] | 2527 | SkRect oval0, oval1; |
| 2528 | SkPath::Direction dir0, dir1; |
| 2529 | unsigned start0, start1; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2530 | REPORTER_ASSERT(reporter, readBack.isOval(nullptr) == p.isOval(nullptr)); |
bsalomon | 78d58d1 | 2016-05-27 09:17:04 -0700 | [diff] [blame] | 2531 | if (p.isOval(&oval0, &dir0, &start0) && readBack.isOval(&oval1, &dir1, &start1)) { |
| 2532 | REPORTER_ASSERT(reporter, oval0 == oval1); |
| 2533 | REPORTER_ASSERT(reporter, dir0 == dir1); |
| 2534 | REPORTER_ASSERT(reporter, start0 == start1); |
| 2535 | } |
| 2536 | REPORTER_ASSERT(reporter, readBack.isRRect(nullptr) == p.isRRect(nullptr)); |
| 2537 | SkRRect rrect0, rrect1; |
| 2538 | if (p.isRRect(&rrect0, &dir0, &start0) && readBack.isRRect(&rrect1, &dir1, &start1)) { |
| 2539 | REPORTER_ASSERT(reporter, rrect0 == rrect1); |
| 2540 | REPORTER_ASSERT(reporter, dir0 == dir1); |
| 2541 | REPORTER_ASSERT(reporter, start0 == start1); |
| 2542 | } |
robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 2543 | const SkRect& origBounds = p.getBounds(); |
| 2544 | const SkRect& readBackBounds = readBack.getBounds(); |
| 2545 | |
| 2546 | REPORTER_ASSERT(reporter, origBounds == readBackBounds); |
| 2547 | } |
| 2548 | |
Mike Reed | e3374d6 | 2017-01-03 13:58:21 -0500 | [diff] [blame] | 2549 | static void test_corrupt_flattening(skiatest::Reporter* reporter) { |
| 2550 | SkPath path; |
| 2551 | path.moveTo(1, 2); |
| 2552 | path.lineTo(1, 2); |
| 2553 | path.quadTo(1, 2, 3, 4); |
| 2554 | path.conicTo(1, 2, 3, 4, 0.5f); |
| 2555 | path.cubicTo(1, 2, 3, 4, 5, 6); |
| 2556 | uint8_t buffer[1024]; |
| 2557 | SkDEBUGCODE(size_t size =) path.writeToMemory(buffer); |
| 2558 | SkASSERT(size <= sizeof(buffer)); |
| 2559 | |
| 2560 | // find where the counts and verbs are stored : from the impl in SkPathRef.cpp |
| 2561 | int32_t* vCount = (int32_t*)&buffer[16]; |
| 2562 | SkASSERT(*vCount == 5); |
| 2563 | int32_t* pCount = (int32_t*)&buffer[20]; |
| 2564 | SkASSERT(*pCount == 9); |
| 2565 | int32_t* cCount = (int32_t*)&buffer[24]; |
| 2566 | SkASSERT(*cCount == 1); |
| 2567 | uint8_t* verbs = &buffer[28]; |
| 2568 | |
| 2569 | REPORTER_ASSERT(reporter, path.readFromMemory(buffer, sizeof(buffer))); |
| 2570 | |
| 2571 | // check that we detect under/over-flow of counts |
| 2572 | |
| 2573 | *vCount += 1; |
| 2574 | REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer))); |
| 2575 | *vCount -= 1; // restore |
| 2576 | |
| 2577 | *pCount += 1; |
| 2578 | REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer))); |
| 2579 | *pCount -= 2; |
| 2580 | REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer))); |
| 2581 | *pCount += 1; // restore |
| 2582 | |
| 2583 | *cCount += 1; |
| 2584 | REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer))); |
| 2585 | *cCount -= 2; |
| 2586 | REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer))); |
| 2587 | *cCount += 1; // restore |
| 2588 | |
| 2589 | // Check that we detect when the verbs indicate more or fewer pts/conics |
| 2590 | |
| 2591 | uint8_t save = verbs[0]; |
| 2592 | SkASSERT(save == SkPath::kCubic_Verb); |
| 2593 | verbs[0] = SkPath::kQuad_Verb; |
| 2594 | REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer))); |
| 2595 | verbs[0] = save; |
| 2596 | |
| 2597 | save = verbs[1]; |
| 2598 | SkASSERT(save == SkPath::kConic_Verb); |
| 2599 | verbs[1] = SkPath::kQuad_Verb; |
| 2600 | REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer))); |
| 2601 | verbs[1] = SkPath::kCubic_Verb; |
| 2602 | REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer))); |
| 2603 | verbs[1] = save; |
| 2604 | |
| 2605 | // Check that we detect invalid verbs |
| 2606 | save = verbs[1]; |
| 2607 | verbs[1] = 17; |
| 2608 | REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer))); |
| 2609 | verbs[1] = save; |
| 2610 | } |
| 2611 | |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 2612 | static void test_flattening(skiatest::Reporter* reporter) { |
| 2613 | SkPath p; |
| 2614 | |
| 2615 | static const SkPoint pts[] = { |
| 2616 | { 0, 0 }, |
| 2617 | { SkIntToScalar(10), SkIntToScalar(10) }, |
| 2618 | { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, |
| 2619 | { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) } |
| 2620 | }; |
| 2621 | p.moveTo(pts[0]); |
| 2622 | p.lineTo(pts[1]); |
| 2623 | p.quadTo(pts[2], pts[3]); |
| 2624 | p.cubicTo(pts[4], pts[5], pts[6]); |
| 2625 | |
robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 2626 | write_and_read_back(reporter, p); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 2627 | |
| 2628 | // create a buffer that should be much larger than the path so we don't |
| 2629 | // kill our stack if writer goes too far. |
| 2630 | char buffer[1024]; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2631 | size_t size1 = p.writeToMemory(nullptr); |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 2632 | size_t size2 = p.writeToMemory(buffer); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 2633 | REPORTER_ASSERT(reporter, size1 == size2); |
| 2634 | |
| 2635 | SkPath p2; |
commit-bot@chromium.org | 4faa869 | 2013-11-05 15:46:56 +0000 | [diff] [blame] | 2636 | size_t size3 = p2.readFromMemory(buffer, 1024); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 2637 | REPORTER_ASSERT(reporter, size1 == size3); |
| 2638 | REPORTER_ASSERT(reporter, p == p2); |
| 2639 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 2640 | size3 = p2.readFromMemory(buffer, 0); |
| 2641 | REPORTER_ASSERT(reporter, !size3); |
| 2642 | |
| 2643 | SkPath tooShort; |
| 2644 | size3 = tooShort.readFromMemory(buffer, size1 - 1); |
| 2645 | REPORTER_ASSERT(reporter, tooShort.isEmpty()); |
| 2646 | |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 2647 | char buffer2[1024]; |
| 2648 | size3 = p2.writeToMemory(buffer2); |
| 2649 | REPORTER_ASSERT(reporter, size1 == size3); |
| 2650 | REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0); |
robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 2651 | |
| 2652 | // test persistence of the oval flag & convexity |
| 2653 | { |
| 2654 | SkPath oval; |
| 2655 | SkRect rect = SkRect::MakeWH(10, 10); |
| 2656 | oval.addOval(rect); |
| 2657 | |
| 2658 | write_and_read_back(reporter, oval); |
| 2659 | } |
Mike Reed | e3374d6 | 2017-01-03 13:58:21 -0500 | [diff] [blame] | 2660 | |
| 2661 | test_corrupt_flattening(reporter); |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
| 2664 | static void test_transform(skiatest::Reporter* reporter) { |
robertphillips@google.com | b06e88d | 2013-12-03 17:15:36 +0000 | [diff] [blame] | 2665 | SkPath p; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 2666 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 2667 | #define CONIC_PERSPECTIVE_BUG_FIXED 0 |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 2668 | static const SkPoint pts[] = { |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 2669 | { 0, 0 }, // move |
| 2670 | { SkIntToScalar(10), SkIntToScalar(10) }, // line |
| 2671 | { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, // quad |
| 2672 | { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) }, // cubic |
| 2673 | #if CONIC_PERSPECTIVE_BUG_FIXED |
| 2674 | { 0, 0 }, { SkIntToScalar(20), SkIntToScalar(10) }, // conic |
| 2675 | #endif |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 2676 | }; |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 2677 | const int kPtCount = SK_ARRAY_COUNT(pts); |
robertphillips@google.com | b06e88d | 2013-12-03 17:15:36 +0000 | [diff] [blame] | 2678 | |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 2679 | p.moveTo(pts[0]); |
| 2680 | p.lineTo(pts[1]); |
| 2681 | p.quadTo(pts[2], pts[3]); |
| 2682 | p.cubicTo(pts[4], pts[5], pts[6]); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 2683 | #if CONIC_PERSPECTIVE_BUG_FIXED |
| 2684 | p.conicTo(pts[4], pts[5], 0.5f); |
| 2685 | #endif |
| 2686 | p.close(); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 2687 | |
robertphillips@google.com | b06e88d | 2013-12-03 17:15:36 +0000 | [diff] [blame] | 2688 | { |
| 2689 | SkMatrix matrix; |
| 2690 | matrix.reset(); |
| 2691 | SkPath p1; |
| 2692 | p.transform(matrix, &p1); |
| 2693 | REPORTER_ASSERT(reporter, p == p1); |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 2694 | } |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 2695 | |
robertphillips@google.com | b06e88d | 2013-12-03 17:15:36 +0000 | [diff] [blame] | 2696 | |
| 2697 | { |
| 2698 | SkMatrix matrix; |
| 2699 | matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3); |
| 2700 | |
| 2701 | SkPath p1; // Leave p1 non-unique (i.e., the empty path) |
| 2702 | |
skia.committer@gmail.com | 6e515d6 | 2013-12-04 07:02:26 +0000 | [diff] [blame] | 2703 | p.transform(matrix, &p1); |
robertphillips@google.com | b06e88d | 2013-12-03 17:15:36 +0000 | [diff] [blame] | 2704 | SkPoint pts1[kPtCount]; |
skia.committer@gmail.com | 6e515d6 | 2013-12-04 07:02:26 +0000 | [diff] [blame] | 2705 | int count = p1.getPoints(pts1, kPtCount); |
robertphillips@google.com | b06e88d | 2013-12-03 17:15:36 +0000 | [diff] [blame] | 2706 | REPORTER_ASSERT(reporter, kPtCount == count); |
| 2707 | for (int i = 0; i < count; ++i) { |
| 2708 | SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3); |
| 2709 | REPORTER_ASSERT(reporter, newPt == pts1[i]); |
| 2710 | } |
| 2711 | } |
| 2712 | |
| 2713 | { |
| 2714 | SkMatrix matrix; |
| 2715 | matrix.reset(); |
reed | 3f43f8a | 2015-01-20 19:58:36 -0800 | [diff] [blame] | 2716 | matrix.setPerspX(4); |
robertphillips@google.com | b06e88d | 2013-12-03 17:15:36 +0000 | [diff] [blame] | 2717 | |
| 2718 | SkPath p1; |
| 2719 | p1.moveTo(SkPoint::Make(0, 0)); |
| 2720 | |
| 2721 | p.transform(matrix, &p1); |
| 2722 | REPORTER_ASSERT(reporter, matrix.invert(&matrix)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 2723 | p1.transform(matrix, nullptr); |
robertphillips@google.com | b06e88d | 2013-12-03 17:15:36 +0000 | [diff] [blame] | 2724 | SkRect pBounds = p.getBounds(); |
| 2725 | SkRect p1Bounds = p1.getBounds(); |
| 2726 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fLeft, p1Bounds.fLeft)); |
| 2727 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fTop, p1Bounds.fTop)); |
| 2728 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fRight, p1Bounds.fRight)); |
| 2729 | REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fBottom, p1Bounds.fBottom)); |
| 2730 | } |
| 2731 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 2732 | p.reset(); |
| 2733 | p.addCircle(0, 0, 1, SkPath::kCW_Direction); |
robertphillips@google.com | b06e88d | 2013-12-03 17:15:36 +0000 | [diff] [blame] | 2734 | |
| 2735 | { |
| 2736 | SkMatrix matrix; |
| 2737 | matrix.reset(); |
| 2738 | SkPath p1; |
| 2739 | p1.moveTo(SkPoint::Make(0, 0)); |
| 2740 | |
| 2741 | p.transform(matrix, &p1); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2742 | REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p1, SkPathPriv::kCW_FirstDirection)); |
robertphillips@google.com | b06e88d | 2013-12-03 17:15:36 +0000 | [diff] [blame] | 2743 | } |
| 2744 | |
| 2745 | |
| 2746 | { |
| 2747 | SkMatrix matrix; |
| 2748 | matrix.reset(); |
| 2749 | matrix.setScaleX(-1); |
| 2750 | SkPath p1; |
| 2751 | p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path) |
| 2752 | |
| 2753 | p.transform(matrix, &p1); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2754 | REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p1, SkPathPriv::kCCW_FirstDirection)); |
robertphillips@google.com | b06e88d | 2013-12-03 17:15:36 +0000 | [diff] [blame] | 2755 | } |
| 2756 | |
| 2757 | { |
| 2758 | SkMatrix matrix; |
| 2759 | matrix.setAll(1, 1, 0, 1, 1, 0, 0, 0, 1); |
| 2760 | SkPath p1; |
| 2761 | p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path) |
| 2762 | |
| 2763 | p.transform(matrix, &p1); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 2764 | REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p1, SkPathPriv::kUnknown_FirstDirection)); |
robertphillips@google.com | b06e88d | 2013-12-03 17:15:36 +0000 | [diff] [blame] | 2765 | } |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 2766 | } |
| 2767 | |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 2768 | static void test_zero_length_paths(skiatest::Reporter* reporter) { |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2769 | SkPath p; |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2770 | uint8_t verbs[32]; |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 2771 | |
caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2772 | struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData { |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2773 | const char* testPath; |
| 2774 | const size_t numResultPts; |
| 2775 | const SkRect resultBound; |
| 2776 | const SkPath::Verb* resultVerbs; |
| 2777 | const size_t numResultVerbs; |
| 2778 | }; |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 2779 | |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2780 | static const SkPath::Verb resultVerbs1[] = { SkPath::kMove_Verb }; |
| 2781 | static const SkPath::Verb resultVerbs2[] = { SkPath::kMove_Verb, SkPath::kMove_Verb }; |
| 2782 | static const SkPath::Verb resultVerbs3[] = { SkPath::kMove_Verb, SkPath::kClose_Verb }; |
| 2783 | static const SkPath::Verb resultVerbs4[] = { SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb }; |
| 2784 | static const SkPath::Verb resultVerbs5[] = { SkPath::kMove_Verb, SkPath::kLine_Verb }; |
| 2785 | static const SkPath::Verb resultVerbs6[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb }; |
| 2786 | static const SkPath::Verb resultVerbs7[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb }; |
| 2787 | static const SkPath::Verb resultVerbs8[] = { |
| 2788 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb |
| 2789 | }; |
| 2790 | static const SkPath::Verb resultVerbs9[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb }; |
| 2791 | static const SkPath::Verb resultVerbs10[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb }; |
| 2792 | static const SkPath::Verb resultVerbs11[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb }; |
| 2793 | static const SkPath::Verb resultVerbs12[] = { |
| 2794 | SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb |
| 2795 | }; |
| 2796 | static const SkPath::Verb resultVerbs13[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb }; |
| 2797 | static const SkPath::Verb resultVerbs14[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb }; |
| 2798 | static const SkPath::Verb resultVerbs15[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb }; |
| 2799 | static const SkPath::Verb resultVerbs16[] = { |
| 2800 | SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb |
| 2801 | }; |
| 2802 | static const struct zeroPathTestData gZeroLengthTests[] = { |
reed | 91f283b | 2015-07-28 06:00:50 -0700 | [diff] [blame] | 2803 | { "M 1 1", 1, {1, 1, 1, 1}, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
schenney@chromium.org | aaf1688 | 2012-06-13 17:41:00 +0000 | [diff] [blame] | 2804 | { "M 1 1 M 2 1", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) }, |
reed | 91f283b | 2015-07-28 06:00:50 -0700 | [diff] [blame] | 2805 | { "M 1 1 z", 1, {1, 1, 1, 1}, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) }, |
schenney@chromium.org | aaf1688 | 2012-06-13 17:41:00 +0000 | [diff] [blame] | 2806 | { "M 1 1 z M 2 1 z", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) }, |
| 2807 | { "M 1 1 L 1 1", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) }, |
| 2808 | { "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) }, |
| 2809 | { "M 1 1 L 1 1 z", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs7, SK_ARRAY_COUNT(resultVerbs7) }, |
| 2810 | { "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) }, |
| 2811 | { "M 1 1 Q 1 1 1 1", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs9, SK_ARRAY_COUNT(resultVerbs9) }, |
| 2812 | { "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) }, |
| 2813 | { "M 1 1 Q 1 1 1 1 z", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs11, SK_ARRAY_COUNT(resultVerbs11) }, |
| 2814 | { "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) }, |
| 2815 | { "M 1 1 C 1 1 1 1 1 1", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs13, SK_ARRAY_COUNT(resultVerbs13) }, |
| 2816 | { "M 1 1 C 1 1 1 1 1 1 M 2 1 C 2 1 2 1 2 1", 8, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs14, |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2817 | SK_ARRAY_COUNT(resultVerbs14) |
| 2818 | }, |
schenney@chromium.org | aaf1688 | 2012-06-13 17:41:00 +0000 | [diff] [blame] | 2819 | { "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) }, |
| 2820 | { "M 1 1 C 1 1 1 1 1 1 z M 2 1 C 2 1 2 1 2 1 z", 8, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs16, |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2821 | SK_ARRAY_COUNT(resultVerbs16) |
| 2822 | } |
| 2823 | }; |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 2824 | |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2825 | for (size_t i = 0; i < SK_ARRAY_COUNT(gZeroLengthTests); ++i) { |
| 2826 | p.reset(); |
| 2827 | bool valid = SkParsePath::FromSVGString(gZeroLengthTests[i].testPath, &p); |
| 2828 | REPORTER_ASSERT(reporter, valid); |
| 2829 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
| 2830 | REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultPts == (size_t)p.countPoints()); |
| 2831 | REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultBound == p.getBounds()); |
| 2832 | REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultVerbs == (size_t)p.getVerbs(verbs, SK_ARRAY_COUNT(verbs))); |
| 2833 | for (size_t j = 0; j < gZeroLengthTests[i].numResultVerbs; ++j) { |
| 2834 | REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultVerbs[j] == verbs[j]); |
| 2835 | } |
bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 2836 | } |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 2837 | } |
| 2838 | |
| 2839 | struct SegmentInfo { |
| 2840 | SkPath fPath; |
| 2841 | int fPointCount; |
| 2842 | }; |
| 2843 | |
reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 2844 | #define kCurveSegmentMask (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask) |
| 2845 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2846 | static void test_segment_masks(skiatest::Reporter* reporter) { |
reed@google.com | eef938c | 2012-08-01 20:01:49 +0000 | [diff] [blame] | 2847 | SkPath p, p2; |
| 2848 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2849 | p.moveTo(0, 0); |
| 2850 | p.quadTo(100, 100, 200, 200); |
| 2851 | REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == p.getSegmentMasks()); |
| 2852 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
reed@google.com | eef938c | 2012-08-01 20:01:49 +0000 | [diff] [blame] | 2853 | p2 = p; |
| 2854 | REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks()); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2855 | p.cubicTo(100, 100, 200, 200, 300, 300); |
| 2856 | REPORTER_ASSERT(reporter, kCurveSegmentMask == p.getSegmentMasks()); |
| 2857 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
reed@google.com | eef938c | 2012-08-01 20:01:49 +0000 | [diff] [blame] | 2858 | p2 = p; |
| 2859 | REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks()); |
| 2860 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2861 | p.reset(); |
| 2862 | p.moveTo(0, 0); |
| 2863 | p.cubicTo(100, 100, 200, 200, 300, 300); |
| 2864 | REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == p.getSegmentMasks()); |
reed@google.com | eef938c | 2012-08-01 20:01:49 +0000 | [diff] [blame] | 2865 | p2 = p; |
| 2866 | REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 2867 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2868 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
| 2869 | } |
| 2870 | |
| 2871 | static void test_iter(skiatest::Reporter* reporter) { |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2872 | SkPath p; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2873 | SkPoint pts[4]; |
| 2874 | |
| 2875 | // Test an iterator with no path |
| 2876 | SkPath::Iter noPathIter; |
| 2877 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2878 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2879 | // Test that setting an empty path works |
| 2880 | noPathIter.setPath(p, false); |
| 2881 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2882 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2883 | // Test that close path makes no difference for an empty path |
| 2884 | noPathIter.setPath(p, true); |
| 2885 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2886 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2887 | // Test an iterator with an initial empty path |
| 2888 | SkPath::Iter iter(p, false); |
| 2889 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 2890 | |
| 2891 | // Test that close path makes no difference |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2892 | iter.setPath(p, true); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2893 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 2894 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 2895 | |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2896 | struct iterTestData { |
| 2897 | const char* testPath; |
| 2898 | const bool forceClose; |
| 2899 | const bool consumeDegenerates; |
| 2900 | const size_t* numResultPtsPerVerb; |
| 2901 | const SkPoint* resultPts; |
| 2902 | const SkPath::Verb* resultVerbs; |
| 2903 | const size_t numResultVerbs; |
| 2904 | }; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2905 | |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2906 | static const SkPath::Verb resultVerbs1[] = { SkPath::kDone_Verb }; |
| 2907 | static const SkPath::Verb resultVerbs2[] = { |
| 2908 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kDone_Verb |
| 2909 | }; |
| 2910 | static const SkPath::Verb resultVerbs3[] = { |
| 2911 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb |
| 2912 | }; |
| 2913 | static const SkPath::Verb resultVerbs4[] = { |
| 2914 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb |
| 2915 | }; |
| 2916 | static const SkPath::Verb resultVerbs5[] = { |
| 2917 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb |
| 2918 | }; |
| 2919 | static const size_t resultPtsSizes1[] = { 0 }; |
schenney@chromium.org | fedd09b | 2012-06-13 18:29:20 +0000 | [diff] [blame] | 2920 | static const size_t resultPtsSizes2[] = { 1, 2, 2, 0 }; |
| 2921 | static const size_t resultPtsSizes3[] = { 1, 2, 2, 2, 1, 0 }; |
| 2922 | static const size_t resultPtsSizes4[] = { 1, 2, 1, 1, 0 }; |
| 2923 | static const size_t resultPtsSizes5[] = { 1, 2, 1, 1, 1, 0 }; |
schenney@chromium.org | aaf1688 | 2012-06-13 17:41:00 +0000 | [diff] [blame] | 2924 | static const SkPoint* resultPts1 = 0; |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2925 | static const SkPoint resultPts2[] = { |
| 2926 | { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 } |
| 2927 | }; |
| 2928 | static const SkPoint resultPts3[] = { |
| 2929 | { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 }, |
| 2930 | { 0, SK_Scalar1 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 } |
| 2931 | }; |
| 2932 | static const SkPoint resultPts4[] = { |
| 2933 | { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 } |
| 2934 | }; |
| 2935 | static const SkPoint resultPts5[] = { |
| 2936 | { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 } |
| 2937 | }; |
| 2938 | static const struct iterTestData gIterTests[] = { |
| 2939 | { "M 1 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
schenney@chromium.org | aaf1688 | 2012-06-13 17:41:00 +0000 | [diff] [blame] | 2940 | { "M 1 0 M 2 0 M 3 0 M 4 0 M 5 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 2941 | { "M 1 0 M 1 0 M 3 0 M 4 0 M 5 0", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2942 | { "z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 2943 | { "z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 2944 | { "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) }, |
| 2945 | { "z M 1 0 z z M 2 0 z M 3 0 M 4 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
schenney@chromium.org | aaf1688 | 2012-06-13 17:41:00 +0000 | [diff] [blame] | 2946 | { "M 1 0 L 1 1 L 0 1 M 0 0 z", false, true, resultPtsSizes2, resultPts2, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) }, |
| 2947 | { "M 1 0 L 1 1 L 0 1 M 0 0 z", true, true, resultPtsSizes3, resultPts3, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) }, |
| 2948 | { "M 1 0 L 1 0 M 0 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 2949 | { "M 1 0 L 1 0 M 0 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 2950 | { "M 1 0 L 1 0 M 0 0 z", false, false, resultPtsSizes4, resultPts4, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) }, |
| 2951 | { "M 1 0 L 1 0 M 0 0 z", true, false, resultPtsSizes5, resultPts5, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) } |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2952 | }; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2953 | |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2954 | for (size_t i = 0; i < SK_ARRAY_COUNT(gIterTests); ++i) { |
| 2955 | p.reset(); |
| 2956 | bool valid = SkParsePath::FromSVGString(gIterTests[i].testPath, &p); |
| 2957 | REPORTER_ASSERT(reporter, valid); |
| 2958 | iter.setPath(p, gIterTests[i].forceClose); |
| 2959 | int j = 0, l = 0; |
| 2960 | do { |
| 2961 | REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegenerates) == gIterTests[i].resultVerbs[j]); |
| 2962 | for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k) { |
| 2963 | REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]); |
| 2964 | } |
| 2965 | } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb); |
| 2966 | REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs); |
| 2967 | } |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2968 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 2969 | p.reset(); |
| 2970 | iter.setPath(p, false); |
| 2971 | REPORTER_ASSERT(reporter, !iter.isClosedContour()); |
| 2972 | p.lineTo(1, 1); |
| 2973 | p.close(); |
| 2974 | iter.setPath(p, false); |
| 2975 | REPORTER_ASSERT(reporter, iter.isClosedContour()); |
| 2976 | p.reset(); |
| 2977 | iter.setPath(p, true); |
| 2978 | REPORTER_ASSERT(reporter, !iter.isClosedContour()); |
| 2979 | p.lineTo(1, 1); |
| 2980 | iter.setPath(p, true); |
| 2981 | REPORTER_ASSERT(reporter, iter.isClosedContour()); |
| 2982 | p.moveTo(0, 0); |
| 2983 | p.lineTo(2, 2); |
| 2984 | iter.setPath(p, false); |
| 2985 | REPORTER_ASSERT(reporter, !iter.isClosedContour()); |
| 2986 | |
| 2987 | // this checks to see if the NaN logic is executed in SkPath::autoClose(), but does not |
| 2988 | // check to see if the result is correct. |
| 2989 | for (int setNaN = 0; setNaN < 4; ++setNaN) { |
| 2990 | p.reset(); |
| 2991 | p.moveTo(setNaN == 0 ? SK_ScalarNaN : 0, setNaN == 1 ? SK_ScalarNaN : 0); |
| 2992 | p.lineTo(setNaN == 2 ? SK_ScalarNaN : 1, setNaN == 3 ? SK_ScalarNaN : 1); |
| 2993 | iter.setPath(p, true); |
| 2994 | iter.next(pts, false); |
| 2995 | iter.next(pts, false); |
| 2996 | REPORTER_ASSERT(reporter, SkPath::kClose_Verb == iter.next(pts, false)); |
| 2997 | } |
| 2998 | |
| 2999 | p.reset(); |
| 3000 | p.quadTo(0, 0, 0, 0); |
| 3001 | iter.setPath(p, false); |
| 3002 | iter.next(pts, false); |
| 3003 | REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == iter.next(pts, false)); |
| 3004 | iter.setPath(p, false); |
| 3005 | iter.next(pts, false); |
| 3006 | REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true)); |
| 3007 | |
| 3008 | p.reset(); |
| 3009 | p.conicTo(0, 0, 0, 0, 0.5f); |
| 3010 | iter.setPath(p, false); |
| 3011 | iter.next(pts, false); |
| 3012 | REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts, false)); |
| 3013 | iter.setPath(p, false); |
| 3014 | iter.next(pts, false); |
| 3015 | REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true)); |
| 3016 | |
| 3017 | p.reset(); |
| 3018 | p.cubicTo(0, 0, 0, 0, 0, 0); |
| 3019 | iter.setPath(p, false); |
| 3020 | iter.next(pts, false); |
| 3021 | REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false)); |
| 3022 | iter.setPath(p, false); |
| 3023 | iter.next(pts, false); |
| 3024 | REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true)); |
| 3025 | |
| 3026 | p.moveTo(1, 1); // add a trailing moveto |
| 3027 | iter.setPath(p, false); |
| 3028 | iter.next(pts, false); |
| 3029 | REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == iter.next(pts, false)); |
| 3030 | iter.setPath(p, false); |
| 3031 | iter.next(pts, false); |
| 3032 | REPORTER_ASSERT(reporter, SkPath::kDone_Verb == iter.next(pts, true)); |
| 3033 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3034 | // The GM degeneratesegments.cpp test is more extensive |
robertphillips | b8de1f4 | 2015-02-23 11:17:01 -0800 | [diff] [blame] | 3035 | |
| 3036 | // Test out mixed degenerate and non-degenerate geometry with Conics |
| 3037 | const SkVector radii[4] = { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 100, 100 } }; |
| 3038 | SkRect r = SkRect::MakeWH(100, 100); |
| 3039 | SkRRect rr; |
| 3040 | rr.setRectRadii(r, radii); |
| 3041 | p.reset(); |
| 3042 | p.addRRect(rr); |
| 3043 | iter.setPath(p, false); |
| 3044 | REPORTER_ASSERT(reporter, SkPath::kMove_Verb == iter.next(pts)); |
| 3045 | REPORTER_ASSERT(reporter, SkPath::kLine_Verb == iter.next(pts)); |
| 3046 | REPORTER_ASSERT(reporter, SkPath::kLine_Verb == iter.next(pts)); |
| 3047 | REPORTER_ASSERT(reporter, SkPath::kConic_Verb == iter.next(pts)); |
| 3048 | REPORTER_ASSERT(reporter, SK_ScalarRoot2Over2 == iter.conicWeight()); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3049 | } |
| 3050 | |
| 3051 | static void test_raw_iter(skiatest::Reporter* reporter) { |
| 3052 | SkPath p; |
| 3053 | SkPoint pts[4]; |
| 3054 | |
| 3055 | // Test an iterator with no path |
| 3056 | SkPath::RawIter noPathIter; |
| 3057 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
| 3058 | // Test that setting an empty path works |
| 3059 | noPathIter.setPath(p); |
| 3060 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 3061 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3062 | // Test an iterator with an initial empty path |
| 3063 | SkPath::RawIter iter(p); |
| 3064 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 3065 | |
| 3066 | // Test that a move-only path returns the move. |
| 3067 | p.moveTo(SK_Scalar1, 0); |
| 3068 | iter.setPath(p); |
| 3069 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 3070 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1); |
| 3071 | REPORTER_ASSERT(reporter, pts[0].fY == 0); |
| 3072 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 3073 | |
| 3074 | // No matter how many moves we add, we should get them all back |
| 3075 | p.moveTo(SK_Scalar1*2, SK_Scalar1); |
| 3076 | p.moveTo(SK_Scalar1*3, SK_Scalar1*2); |
| 3077 | iter.setPath(p); |
| 3078 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 3079 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1); |
| 3080 | REPORTER_ASSERT(reporter, pts[0].fY == 0); |
| 3081 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 3082 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2); |
| 3083 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1); |
| 3084 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 3085 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3); |
| 3086 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2); |
| 3087 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 3088 | |
| 3089 | // Initial close is never ever stored |
| 3090 | p.reset(); |
| 3091 | p.close(); |
| 3092 | iter.setPath(p); |
| 3093 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 3094 | |
| 3095 | // Move/close sequences |
| 3096 | p.reset(); |
| 3097 | p.close(); // Not stored, no purpose |
| 3098 | p.moveTo(SK_Scalar1, 0); |
| 3099 | p.close(); |
| 3100 | p.close(); // Not stored, no purpose |
| 3101 | p.moveTo(SK_Scalar1*2, SK_Scalar1); |
| 3102 | p.close(); |
| 3103 | p.moveTo(SK_Scalar1*3, SK_Scalar1*2); |
| 3104 | p.moveTo(SK_Scalar1*4, SK_Scalar1*3); |
| 3105 | p.close(); |
| 3106 | iter.setPath(p); |
| 3107 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 3108 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1); |
| 3109 | REPORTER_ASSERT(reporter, pts[0].fY == 0); |
| 3110 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3111 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 3112 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2); |
| 3113 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1); |
| 3114 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3115 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 3116 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3); |
| 3117 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2); |
| 3118 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 3119 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4); |
| 3120 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3); |
| 3121 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3122 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 3123 | |
| 3124 | // Generate random paths and verify |
| 3125 | SkPoint randomPts[25]; |
| 3126 | for (int i = 0; i < 5; ++i) { |
| 3127 | for (int j = 0; j < 5; ++j) { |
| 3128 | randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j); |
| 3129 | } |
| 3130 | } |
| 3131 | |
| 3132 | // Max of 10 segments, max 3 points per segment |
commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 3133 | SkRandom rand(9876543); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3134 | SkPoint expectedPts[31]; // May have leading moveTo |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 3135 | SkPath::Verb expectedVerbs[22]; // May have leading moveTo |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3136 | SkPath::Verb nextVerb; |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 3137 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3138 | for (int i = 0; i < 500; ++i) { |
| 3139 | p.reset(); |
| 3140 | bool lastWasClose = true; |
| 3141 | bool haveMoveTo = false; |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 3142 | SkPoint lastMoveToPt = { 0, 0 }; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3143 | int numPoints = 0; |
| 3144 | int numVerbs = (rand.nextU() >> 16) % 10; |
| 3145 | int numIterVerbs = 0; |
| 3146 | for (int j = 0; j < numVerbs; ++j) { |
| 3147 | do { |
| 3148 | nextVerb = static_cast<SkPath::Verb>((rand.nextU() >> 16) % SkPath::kDone_Verb); |
| 3149 | } while (lastWasClose && nextVerb == SkPath::kClose_Verb); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3150 | switch (nextVerb) { |
| 3151 | case SkPath::kMove_Verb: |
| 3152 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 3153 | p.moveTo(expectedPts[numPoints]); |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 3154 | lastMoveToPt = expectedPts[numPoints]; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3155 | numPoints += 1; |
| 3156 | lastWasClose = false; |
| 3157 | haveMoveTo = true; |
| 3158 | break; |
| 3159 | case SkPath::kLine_Verb: |
| 3160 | if (!haveMoveTo) { |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 3161 | expectedPts[numPoints++] = lastMoveToPt; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3162 | expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; |
| 3163 | haveMoveTo = true; |
| 3164 | } |
| 3165 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 3166 | p.lineTo(expectedPts[numPoints]); |
| 3167 | numPoints += 1; |
| 3168 | lastWasClose = false; |
| 3169 | break; |
| 3170 | case SkPath::kQuad_Verb: |
| 3171 | if (!haveMoveTo) { |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 3172 | expectedPts[numPoints++] = lastMoveToPt; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3173 | expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; |
| 3174 | haveMoveTo = true; |
| 3175 | } |
| 3176 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 3177 | expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25]; |
| 3178 | p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]); |
| 3179 | numPoints += 2; |
| 3180 | lastWasClose = false; |
| 3181 | break; |
reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 3182 | case SkPath::kConic_Verb: |
| 3183 | if (!haveMoveTo) { |
| 3184 | expectedPts[numPoints++] = lastMoveToPt; |
| 3185 | expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; |
| 3186 | haveMoveTo = true; |
| 3187 | } |
| 3188 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 3189 | expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25]; |
| 3190 | p.conicTo(expectedPts[numPoints], expectedPts[numPoints + 1], |
| 3191 | rand.nextUScalar1() * 4); |
| 3192 | numPoints += 2; |
| 3193 | lastWasClose = false; |
| 3194 | break; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3195 | case SkPath::kCubic_Verb: |
| 3196 | if (!haveMoveTo) { |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 3197 | expectedPts[numPoints++] = lastMoveToPt; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3198 | expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; |
| 3199 | haveMoveTo = true; |
| 3200 | } |
| 3201 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 3202 | expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25]; |
| 3203 | expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25]; |
| 3204 | p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1], |
| 3205 | expectedPts[numPoints + 2]); |
| 3206 | numPoints += 3; |
| 3207 | lastWasClose = false; |
| 3208 | break; |
| 3209 | case SkPath::kClose_Verb: |
| 3210 | p.close(); |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 3211 | haveMoveTo = false; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3212 | lastWasClose = true; |
| 3213 | break; |
reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 3214 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 3215 | SkDEBUGFAIL("unexpected verb"); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3216 | } |
| 3217 | expectedVerbs[numIterVerbs++] = nextVerb; |
| 3218 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 3219 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3220 | iter.setPath(p); |
| 3221 | numVerbs = numIterVerbs; |
| 3222 | numIterVerbs = 0; |
| 3223 | int numIterPts = 0; |
| 3224 | SkPoint lastMoveTo; |
| 3225 | SkPoint lastPt; |
| 3226 | lastMoveTo.set(0, 0); |
| 3227 | lastPt.set(0, 0); |
| 3228 | while ((nextVerb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 3229 | REPORTER_ASSERT(reporter, nextVerb == expectedVerbs[numIterVerbs]); |
| 3230 | numIterVerbs++; |
| 3231 | switch (nextVerb) { |
| 3232 | case SkPath::kMove_Verb: |
| 3233 | REPORTER_ASSERT(reporter, numIterPts < numPoints); |
| 3234 | REPORTER_ASSERT(reporter, pts[0] == expectedPts[numIterPts]); |
| 3235 | lastPt = lastMoveTo = pts[0]; |
| 3236 | numIterPts += 1; |
| 3237 | break; |
| 3238 | case SkPath::kLine_Verb: |
| 3239 | REPORTER_ASSERT(reporter, numIterPts < numPoints + 1); |
| 3240 | REPORTER_ASSERT(reporter, pts[0] == lastPt); |
| 3241 | REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]); |
| 3242 | lastPt = pts[1]; |
| 3243 | numIterPts += 1; |
| 3244 | break; |
| 3245 | case SkPath::kQuad_Verb: |
reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 3246 | case SkPath::kConic_Verb: |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3247 | REPORTER_ASSERT(reporter, numIterPts < numPoints + 2); |
| 3248 | REPORTER_ASSERT(reporter, pts[0] == lastPt); |
| 3249 | REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]); |
| 3250 | REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]); |
| 3251 | lastPt = pts[2]; |
| 3252 | numIterPts += 2; |
| 3253 | break; |
| 3254 | case SkPath::kCubic_Verb: |
| 3255 | REPORTER_ASSERT(reporter, numIterPts < numPoints + 3); |
| 3256 | REPORTER_ASSERT(reporter, pts[0] == lastPt); |
| 3257 | REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]); |
| 3258 | REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]); |
| 3259 | REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]); |
| 3260 | lastPt = pts[3]; |
| 3261 | numIterPts += 3; |
| 3262 | break; |
| 3263 | case SkPath::kClose_Verb: |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3264 | lastPt = lastMoveTo; |
| 3265 | break; |
reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 3266 | default: |
mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 3267 | SkDEBUGFAIL("unexpected verb"); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 3268 | } |
| 3269 | } |
| 3270 | REPORTER_ASSERT(reporter, numIterPts == numPoints); |
| 3271 | REPORTER_ASSERT(reporter, numIterVerbs == numVerbs); |
| 3272 | } |
| 3273 | } |
| 3274 | |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3275 | static void check_for_circle(skiatest::Reporter* reporter, |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3276 | const SkPath& path, |
| 3277 | bool expectedCircle, |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3278 | SkPathPriv::FirstDirection expectedDir) { |
robertphillips@google.com | 466310d | 2013-12-03 16:43:54 +0000 | [diff] [blame] | 3279 | SkRect rect = SkRect::MakeEmpty(); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3280 | REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle); |
bsalomon | 78d58d1 | 2016-05-27 09:17:04 -0700 | [diff] [blame] | 3281 | SkPath::Direction isOvalDir; |
| 3282 | unsigned isOvalStart; |
| 3283 | if (path.isOval(&rect, &isOvalDir, &isOvalStart)) { |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3284 | REPORTER_ASSERT(reporter, rect.height() == rect.width()); |
bsalomon | 78d58d1 | 2016-05-27 09:17:04 -0700 | [diff] [blame] | 3285 | REPORTER_ASSERT(reporter, SkPathPriv::AsFirstDirection(isOvalDir) == expectedDir); |
| 3286 | SkPath tmpPath; |
| 3287 | tmpPath.addOval(rect, isOvalDir, isOvalStart); |
| 3288 | REPORTER_ASSERT(reporter, path == tmpPath); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3289 | } |
bsalomon | 78d58d1 | 2016-05-27 09:17:04 -0700 | [diff] [blame] | 3290 | REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(path, expectedDir)); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3291 | } |
| 3292 | |
| 3293 | static void test_circle_skew(skiatest::Reporter* reporter, |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3294 | const SkPath& path, |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3295 | SkPathPriv::FirstDirection dir) { |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3296 | SkPath tmp; |
| 3297 | |
| 3298 | SkMatrix m; |
| 3299 | m.setSkew(SkIntToScalar(3), SkIntToScalar(5)); |
| 3300 | path.transform(m, &tmp); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3301 | // this matrix reverses the direction. |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3302 | if (SkPathPriv::kCCW_FirstDirection == dir) { |
| 3303 | dir = SkPathPriv::kCW_FirstDirection; |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3304 | } else { |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3305 | REPORTER_ASSERT(reporter, SkPathPriv::kCW_FirstDirection == dir); |
| 3306 | dir = SkPathPriv::kCCW_FirstDirection; |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3307 | } |
| 3308 | check_for_circle(reporter, tmp, false, dir); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3309 | } |
| 3310 | |
| 3311 | static void test_circle_translate(skiatest::Reporter* reporter, |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3312 | const SkPath& path, |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3313 | SkPathPriv::FirstDirection dir) { |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3314 | SkPath tmp; |
| 3315 | |
| 3316 | // translate at small offset |
| 3317 | SkMatrix m; |
| 3318 | m.setTranslate(SkIntToScalar(15), SkIntToScalar(15)); |
| 3319 | path.transform(m, &tmp); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3320 | check_for_circle(reporter, tmp, true, dir); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3321 | |
| 3322 | tmp.reset(); |
| 3323 | m.reset(); |
| 3324 | |
| 3325 | // translate at a relatively big offset |
| 3326 | m.setTranslate(SkIntToScalar(1000), SkIntToScalar(1000)); |
| 3327 | path.transform(m, &tmp); |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3328 | check_for_circle(reporter, tmp, true, dir); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3329 | } |
| 3330 | |
| 3331 | static void test_circle_rotate(skiatest::Reporter* reporter, |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3332 | const SkPath& path, |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3333 | SkPathPriv::FirstDirection dir) { |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3334 | for (int angle = 0; angle < 360; ++angle) { |
| 3335 | SkPath tmp; |
| 3336 | SkMatrix m; |
| 3337 | m.setRotate(SkIntToScalar(angle)); |
| 3338 | path.transform(m, &tmp); |
| 3339 | |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3340 | // TODO: a rotated circle whose rotated angle is not a multiple of 90 |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3341 | // degrees is not an oval anymore, this can be improved. we made this |
| 3342 | // for the simplicity of our implementation. |
| 3343 | if (angle % 90 == 0) { |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3344 | check_for_circle(reporter, tmp, true, dir); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3345 | } else { |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3346 | check_for_circle(reporter, tmp, false, dir); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3347 | } |
| 3348 | } |
| 3349 | } |
| 3350 | |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3351 | static void test_circle_mirror_x(skiatest::Reporter* reporter, |
| 3352 | const SkPath& path, |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3353 | SkPathPriv::FirstDirection dir) { |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3354 | SkPath tmp; |
| 3355 | SkMatrix m; |
| 3356 | m.reset(); |
| 3357 | m.setScaleX(-SK_Scalar1); |
| 3358 | path.transform(m, &tmp); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3359 | if (SkPathPriv::kCW_FirstDirection == dir) { |
| 3360 | dir = SkPathPriv::kCCW_FirstDirection; |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3361 | } else { |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3362 | REPORTER_ASSERT(reporter, SkPathPriv::kCCW_FirstDirection == dir); |
| 3363 | dir = SkPathPriv::kCW_FirstDirection; |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3364 | } |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3365 | check_for_circle(reporter, tmp, true, dir); |
| 3366 | } |
| 3367 | |
| 3368 | static void test_circle_mirror_y(skiatest::Reporter* reporter, |
| 3369 | const SkPath& path, |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3370 | SkPathPriv::FirstDirection dir) { |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3371 | SkPath tmp; |
| 3372 | SkMatrix m; |
| 3373 | m.reset(); |
| 3374 | m.setScaleY(-SK_Scalar1); |
| 3375 | path.transform(m, &tmp); |
| 3376 | |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3377 | if (SkPathPriv::kCW_FirstDirection == dir) { |
| 3378 | dir = SkPathPriv::kCCW_FirstDirection; |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3379 | } else { |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3380 | REPORTER_ASSERT(reporter, SkPathPriv::kCCW_FirstDirection == dir); |
| 3381 | dir = SkPathPriv::kCW_FirstDirection; |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3382 | } |
| 3383 | |
| 3384 | check_for_circle(reporter, tmp, true, dir); |
| 3385 | } |
| 3386 | |
| 3387 | static void test_circle_mirror_xy(skiatest::Reporter* reporter, |
| 3388 | const SkPath& path, |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3389 | SkPathPriv::FirstDirection dir) { |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3390 | SkPath tmp; |
| 3391 | SkMatrix m; |
| 3392 | m.reset(); |
| 3393 | m.setScaleX(-SK_Scalar1); |
| 3394 | m.setScaleY(-SK_Scalar1); |
| 3395 | path.transform(m, &tmp); |
| 3396 | |
| 3397 | check_for_circle(reporter, tmp, true, dir); |
| 3398 | } |
| 3399 | |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3400 | static void test_circle_with_direction(skiatest::Reporter* reporter, |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3401 | SkPath::Direction inDir) { |
| 3402 | const SkPathPriv::FirstDirection dir = SkPathPriv::AsFirstDirection(inDir); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3403 | SkPath path; |
| 3404 | |
| 3405 | // circle at origin |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3406 | path.addCircle(0, 0, SkIntToScalar(20), inDir); |
| 3407 | |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3408 | check_for_circle(reporter, path, true, dir); |
| 3409 | test_circle_rotate(reporter, path, dir); |
| 3410 | test_circle_translate(reporter, path, dir); |
| 3411 | test_circle_skew(reporter, path, dir); |
bsalomon | 78d58d1 | 2016-05-27 09:17:04 -0700 | [diff] [blame] | 3412 | test_circle_mirror_x(reporter, path, dir); |
| 3413 | test_circle_mirror_y(reporter, path, dir); |
| 3414 | test_circle_mirror_xy(reporter, path, dir); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3415 | |
| 3416 | // circle at an offset at (10, 10) |
| 3417 | path.reset(); |
| 3418 | path.addCircle(SkIntToScalar(10), SkIntToScalar(10), |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3419 | SkIntToScalar(20), inDir); |
| 3420 | |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3421 | check_for_circle(reporter, path, true, dir); |
| 3422 | test_circle_rotate(reporter, path, dir); |
| 3423 | test_circle_translate(reporter, path, dir); |
| 3424 | test_circle_skew(reporter, path, dir); |
| 3425 | test_circle_mirror_x(reporter, path, dir); |
| 3426 | test_circle_mirror_y(reporter, path, dir); |
| 3427 | test_circle_mirror_xy(reporter, path, dir); |
bsalomon | 78d58d1 | 2016-05-27 09:17:04 -0700 | [diff] [blame] | 3428 | |
| 3429 | // Try different starting points for the contour. |
| 3430 | for (unsigned start = 0; start < 4; ++start) { |
| 3431 | path.reset(); |
| 3432 | path.addOval(SkRect::MakeXYWH(20, 10, 5, 5), inDir, start); |
| 3433 | test_circle_rotate(reporter, path, dir); |
| 3434 | test_circle_translate(reporter, path, dir); |
| 3435 | test_circle_skew(reporter, path, dir); |
| 3436 | test_circle_mirror_x(reporter, path, dir); |
| 3437 | test_circle_mirror_y(reporter, path, dir); |
| 3438 | test_circle_mirror_xy(reporter, path, dir); |
| 3439 | } |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3440 | } |
| 3441 | |
| 3442 | static void test_circle_with_add_paths(skiatest::Reporter* reporter) { |
| 3443 | SkPath path; |
| 3444 | SkPath circle; |
| 3445 | SkPath rect; |
| 3446 | SkPath empty; |
| 3447 | |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3448 | const SkPath::Direction kCircleDir = SkPath::kCW_Direction; |
| 3449 | const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction; |
bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 3450 | |
| 3451 | circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3452 | rect.addRect(SkIntToScalar(5), SkIntToScalar(5), |
| 3453 | SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction); |
| 3454 | |
| 3455 | SkMatrix translate; |
| 3456 | translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12)); |
| 3457 | |
robertphillips@google.com | 0efb21b | 2013-12-13 19:36:25 +0000 | [diff] [blame] | 3458 | // Although all the path concatenation related operations leave |
| 3459 | // the path a circle, most mark it as a non-circle for simplicity |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3460 | |
| 3461 | // empty + circle (translate) |
| 3462 | path = empty; |
| 3463 | path.addPath(circle, translate); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3464 | check_for_circle(reporter, path, false, SkPathPriv::AsFirstDirection(kCircleDir)); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3465 | |
| 3466 | // circle + empty (translate) |
| 3467 | path = circle; |
| 3468 | path.addPath(empty, translate); |
bsalomon | 78d58d1 | 2016-05-27 09:17:04 -0700 | [diff] [blame] | 3469 | |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3470 | check_for_circle(reporter, path, true, SkPathPriv::AsFirstDirection(kCircleDir)); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3471 | |
| 3472 | // test reverseAddPath |
| 3473 | path = circle; |
| 3474 | path.reverseAddPath(rect); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3475 | check_for_circle(reporter, path, false, SkPathPriv::AsFirstDirection(kCircleDirOpposite)); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3476 | } |
| 3477 | |
| 3478 | static void test_circle(skiatest::Reporter* reporter) { |
| 3479 | test_circle_with_direction(reporter, SkPath::kCW_Direction); |
| 3480 | test_circle_with_direction(reporter, SkPath::kCCW_Direction); |
| 3481 | |
| 3482 | // multiple addCircle() |
| 3483 | SkPath path; |
| 3484 | path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction); |
| 3485 | path.addCircle(0, 0, SkIntToScalar(20), SkPath::kCW_Direction); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3486 | check_for_circle(reporter, path, false, SkPathPriv::kCW_FirstDirection); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3487 | |
| 3488 | // some extra lineTo() would make isOval() fail |
| 3489 | path.reset(); |
| 3490 | path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction); |
| 3491 | path.lineTo(0, 0); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3492 | check_for_circle(reporter, path, false, SkPathPriv::kCW_FirstDirection); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3493 | |
| 3494 | // not back to the original point |
| 3495 | path.reset(); |
| 3496 | path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction); |
| 3497 | path.setLastPt(SkIntToScalar(5), SkIntToScalar(5)); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3498 | check_for_circle(reporter, path, false, SkPathPriv::kCW_FirstDirection); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3499 | |
| 3500 | test_circle_with_add_paths(reporter); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3501 | |
| 3502 | // test negative radius |
| 3503 | path.reset(); |
| 3504 | path.addCircle(0, 0, -1, SkPath::kCW_Direction); |
| 3505 | REPORTER_ASSERT(reporter, path.isEmpty()); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3506 | } |
| 3507 | |
| 3508 | static void test_oval(skiatest::Reporter* reporter) { |
| 3509 | SkRect rect; |
| 3510 | SkMatrix m; |
| 3511 | SkPath path; |
bsalomon | 78d58d1 | 2016-05-27 09:17:04 -0700 | [diff] [blame] | 3512 | unsigned start = 0; |
| 3513 | SkPath::Direction dir = SkPath::kCCW_Direction; |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3514 | |
| 3515 | rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50)); |
| 3516 | path.addOval(rect); |
| 3517 | |
bsalomon | 78d58d1 | 2016-05-27 09:17:04 -0700 | [diff] [blame] | 3518 | // Defaults to dir = CW and start = 1 |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3519 | REPORTER_ASSERT(reporter, path.isOval(nullptr)); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3520 | |
| 3521 | m.setRotate(SkIntToScalar(90)); |
| 3522 | SkPath tmp; |
| 3523 | path.transform(m, &tmp); |
bsalomon | 78d58d1 | 2016-05-27 09:17:04 -0700 | [diff] [blame] | 3524 | // an oval rotated 90 degrees is still an oval. The start index changes from 1 to 2. Direction |
| 3525 | // is unchanged. |
| 3526 | REPORTER_ASSERT(reporter, tmp.isOval(nullptr, &dir, &start)); |
| 3527 | REPORTER_ASSERT(reporter, 2 == start); |
| 3528 | REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3529 | |
| 3530 | m.reset(); |
| 3531 | m.setRotate(SkIntToScalar(30)); |
| 3532 | tmp.reset(); |
| 3533 | path.transform(m, &tmp); |
| 3534 | // an oval rotated 30 degrees is not an oval anymore. |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3535 | REPORTER_ASSERT(reporter, !tmp.isOval(nullptr)); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3536 | |
| 3537 | // since empty path being transformed. |
| 3538 | path.reset(); |
| 3539 | tmp.reset(); |
| 3540 | m.reset(); |
| 3541 | path.transform(m, &tmp); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3542 | REPORTER_ASSERT(reporter, !tmp.isOval(nullptr)); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3543 | |
| 3544 | // empty path is not an oval |
| 3545 | tmp.reset(); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3546 | REPORTER_ASSERT(reporter, !tmp.isOval(nullptr)); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3547 | |
| 3548 | // only has moveTo()s |
| 3549 | tmp.reset(); |
| 3550 | tmp.moveTo(0, 0); |
| 3551 | tmp.moveTo(SkIntToScalar(10), SkIntToScalar(10)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3552 | REPORTER_ASSERT(reporter, !tmp.isOval(nullptr)); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3553 | |
| 3554 | // mimic WebKit's calling convention, |
| 3555 | // call moveTo() first and then call addOval() |
| 3556 | path.reset(); |
| 3557 | path.moveTo(0, 0); |
| 3558 | path.addOval(rect); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3559 | REPORTER_ASSERT(reporter, path.isOval(nullptr)); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3560 | |
| 3561 | // copy path |
| 3562 | path.reset(); |
| 3563 | tmp.reset(); |
| 3564 | tmp.addOval(rect); |
| 3565 | path = tmp; |
bsalomon | 78d58d1 | 2016-05-27 09:17:04 -0700 | [diff] [blame] | 3566 | REPORTER_ASSERT(reporter, path.isOval(nullptr, &dir, &start)); |
| 3567 | REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir); |
| 3568 | REPORTER_ASSERT(reporter, 1 == start); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 3569 | } |
| 3570 | |
bungeman@google.com | a5809a3 | 2013-06-21 15:13:34 +0000 | [diff] [blame] | 3571 | static void test_empty(skiatest::Reporter* reporter, const SkPath& p) { |
| 3572 | SkPath empty; |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 3573 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 3574 | REPORTER_ASSERT(reporter, p.isEmpty()); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 3575 | REPORTER_ASSERT(reporter, 0 == p.countPoints()); |
bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 3576 | REPORTER_ASSERT(reporter, 0 == p.countVerbs()); |
reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 3577 | REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks()); |
reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 3578 | REPORTER_ASSERT(reporter, p.isConvex()); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 3579 | REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType); |
| 3580 | REPORTER_ASSERT(reporter, !p.isInverseFillType()); |
bungeman@google.com | a5809a3 | 2013-06-21 15:13:34 +0000 | [diff] [blame] | 3581 | REPORTER_ASSERT(reporter, p == empty); |
| 3582 | REPORTER_ASSERT(reporter, !(p != empty)); |
| 3583 | } |
| 3584 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3585 | static void test_rrect_is_convex(skiatest::Reporter* reporter, SkPath* path, |
| 3586 | SkPath::Direction dir) { |
commit-bot@chromium.org | 42feaaf | 2013-11-08 15:51:12 +0000 | [diff] [blame] | 3587 | REPORTER_ASSERT(reporter, path->isConvex()); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3588 | REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(*path, SkPathPriv::AsFirstDirection(dir))); |
commit-bot@chromium.org | 42feaaf | 2013-11-08 15:51:12 +0000 | [diff] [blame] | 3589 | path->setConvexity(SkPath::kUnknown_Convexity); |
| 3590 | REPORTER_ASSERT(reporter, path->isConvex()); |
| 3591 | path->reset(); |
| 3592 | } |
| 3593 | |
caryclark | d3d1a98 | 2014-12-08 04:57:38 -0800 | [diff] [blame] | 3594 | static void test_rrect_convexity_is_unknown(skiatest::Reporter* reporter, SkPath* path, |
| 3595 | SkPath::Direction dir) { |
| 3596 | REPORTER_ASSERT(reporter, path->isConvex()); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3597 | REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(*path, SkPathPriv::AsFirstDirection(dir))); |
caryclark | d3d1a98 | 2014-12-08 04:57:38 -0800 | [diff] [blame] | 3598 | path->setConvexity(SkPath::kUnknown_Convexity); |
| 3599 | REPORTER_ASSERT(reporter, path->getConvexity() == SkPath::kUnknown_Convexity); |
| 3600 | path->reset(); |
| 3601 | } |
| 3602 | |
commit-bot@chromium.org | 42feaaf | 2013-11-08 15:51:12 +0000 | [diff] [blame] | 3603 | static void test_rrect(skiatest::Reporter* reporter) { |
| 3604 | SkPath p; |
| 3605 | SkRRect rr; |
| 3606 | SkVector radii[] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}}; |
| 3607 | SkRect r = {10, 20, 30, 40}; |
| 3608 | rr.setRectRadii(r, radii); |
| 3609 | p.addRRect(rr); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3610 | test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
commit-bot@chromium.org | 42feaaf | 2013-11-08 15:51:12 +0000 | [diff] [blame] | 3611 | p.addRRect(rr, SkPath::kCCW_Direction); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3612 | test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction); |
commit-bot@chromium.org | 42feaaf | 2013-11-08 15:51:12 +0000 | [diff] [blame] | 3613 | p.addRoundRect(r, &radii[0].fX); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3614 | test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
commit-bot@chromium.org | 42feaaf | 2013-11-08 15:51:12 +0000 | [diff] [blame] | 3615 | p.addRoundRect(r, &radii[0].fX, SkPath::kCCW_Direction); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3616 | test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction); |
commit-bot@chromium.org | 42feaaf | 2013-11-08 15:51:12 +0000 | [diff] [blame] | 3617 | p.addRoundRect(r, radii[1].fX, radii[1].fY); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3618 | test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
commit-bot@chromium.org | 42feaaf | 2013-11-08 15:51:12 +0000 | [diff] [blame] | 3619 | p.addRoundRect(r, radii[1].fX, radii[1].fY, SkPath::kCCW_Direction); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3620 | test_rrect_is_convex(reporter, &p, SkPath::kCCW_Direction); |
| 3621 | for (size_t i = 0; i < SK_ARRAY_COUNT(radii); ++i) { |
| 3622 | SkVector save = radii[i]; |
| 3623 | radii[i].set(0, 0); |
| 3624 | rr.setRectRadii(r, radii); |
| 3625 | p.addRRect(rr); |
| 3626 | test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
| 3627 | radii[i] = save; |
| 3628 | } |
| 3629 | p.addRoundRect(r, 0, 0); |
| 3630 | SkRect returnedRect; |
| 3631 | REPORTER_ASSERT(reporter, p.isRect(&returnedRect)); |
| 3632 | REPORTER_ASSERT(reporter, returnedRect == r); |
| 3633 | test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
| 3634 | SkVector zeroRadii[] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}}; |
| 3635 | rr.setRectRadii(r, zeroRadii); |
| 3636 | p.addRRect(rr); |
| 3637 | bool closed; |
| 3638 | SkPath::Direction dir; |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3639 | REPORTER_ASSERT(reporter, p.isRect(nullptr, &closed, &dir)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3640 | REPORTER_ASSERT(reporter, closed); |
| 3641 | REPORTER_ASSERT(reporter, SkPath::kCW_Direction == dir); |
| 3642 | test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
| 3643 | p.addRRect(rr, SkPath::kCW_Direction); |
| 3644 | p.addRRect(rr, SkPath::kCW_Direction); |
| 3645 | REPORTER_ASSERT(reporter, !p.isConvex()); |
| 3646 | p.reset(); |
| 3647 | p.addRRect(rr, SkPath::kCCW_Direction); |
| 3648 | p.addRRect(rr, SkPath::kCCW_Direction); |
| 3649 | REPORTER_ASSERT(reporter, !p.isConvex()); |
| 3650 | p.reset(); |
| 3651 | SkRect emptyR = {10, 20, 10, 30}; |
| 3652 | rr.setRectRadii(emptyR, radii); |
| 3653 | p.addRRect(rr); |
| 3654 | REPORTER_ASSERT(reporter, p.isEmpty()); |
| 3655 | SkRect largeR = {0, 0, SK_ScalarMax, SK_ScalarMax}; |
| 3656 | rr.setRectRadii(largeR, radii); |
| 3657 | p.addRRect(rr); |
caryclark | d3d1a98 | 2014-12-08 04:57:38 -0800 | [diff] [blame] | 3658 | test_rrect_convexity_is_unknown(reporter, &p, SkPath::kCW_Direction); |
reed | 454fa71 | 2015-02-10 08:46:22 -0800 | [diff] [blame] | 3659 | |
| 3660 | // we check for non-finites |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3661 | SkRect infR = {0, 0, SK_ScalarMax, SK_ScalarInfinity}; |
| 3662 | rr.setRectRadii(infR, radii); |
reed | 454fa71 | 2015-02-10 08:46:22 -0800 | [diff] [blame] | 3663 | REPORTER_ASSERT(reporter, rr.isEmpty()); |
| 3664 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3665 | SkRect tinyR = {0, 0, 1e-9f, 1e-9f}; |
| 3666 | p.addRoundRect(tinyR, 5e-11f, 5e-11f); |
| 3667 | test_rrect_is_convex(reporter, &p, SkPath::kCW_Direction); |
commit-bot@chromium.org | 42feaaf | 2013-11-08 15:51:12 +0000 | [diff] [blame] | 3668 | } |
| 3669 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3670 | static void test_arc(skiatest::Reporter* reporter) { |
| 3671 | SkPath p; |
| 3672 | SkRect emptyOval = {10, 20, 30, 20}; |
| 3673 | REPORTER_ASSERT(reporter, emptyOval.isEmpty()); |
| 3674 | p.addArc(emptyOval, 1, 2); |
| 3675 | REPORTER_ASSERT(reporter, p.isEmpty()); |
| 3676 | p.reset(); |
| 3677 | SkRect oval = {10, 20, 30, 40}; |
| 3678 | p.addArc(oval, 1, 0); |
| 3679 | REPORTER_ASSERT(reporter, p.isEmpty()); |
| 3680 | p.reset(); |
| 3681 | SkPath cwOval; |
| 3682 | cwOval.addOval(oval); |
bsalomon | 1978ce2 | 2016-05-31 10:42:16 -0700 | [diff] [blame] | 3683 | p.addArc(oval, 0, 360); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3684 | REPORTER_ASSERT(reporter, p == cwOval); |
| 3685 | p.reset(); |
| 3686 | SkPath ccwOval; |
| 3687 | ccwOval.addOval(oval, SkPath::kCCW_Direction); |
bsalomon | 1978ce2 | 2016-05-31 10:42:16 -0700 | [diff] [blame] | 3688 | p.addArc(oval, 0, -360); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3689 | REPORTER_ASSERT(reporter, p == ccwOval); |
| 3690 | p.reset(); |
| 3691 | p.addArc(oval, 1, 180); |
| 3692 | REPORTER_ASSERT(reporter, p.isConvex()); |
reed | 026beb5 | 2015-06-10 14:23:15 -0700 | [diff] [blame] | 3693 | REPORTER_ASSERT(reporter, SkPathPriv::CheapIsFirstDirection(p, SkPathPriv::kCW_FirstDirection)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3694 | p.setConvexity(SkPath::kUnknown_Convexity); |
| 3695 | REPORTER_ASSERT(reporter, p.isConvex()); |
| 3696 | } |
| 3697 | |
bsalomon | 1978ce2 | 2016-05-31 10:42:16 -0700 | [diff] [blame] | 3698 | static inline SkScalar oval_start_index_to_angle(unsigned start) { |
| 3699 | switch (start) { |
| 3700 | case 0: |
| 3701 | return 270.f; |
| 3702 | case 1: |
| 3703 | return 0.f; |
| 3704 | case 2: |
| 3705 | return 90.f; |
| 3706 | case 3: |
| 3707 | return 180.f; |
| 3708 | default: |
| 3709 | return -1.f; |
| 3710 | } |
| 3711 | } |
| 3712 | |
| 3713 | static inline SkScalar canonical_start_angle(float angle) { |
| 3714 | while (angle < 0.f) { |
| 3715 | angle += 360.f; |
| 3716 | } |
| 3717 | while (angle >= 360.f) { |
| 3718 | angle -= 360.f; |
| 3719 | } |
| 3720 | return angle; |
| 3721 | } |
| 3722 | |
| 3723 | static void check_oval_arc(skiatest::Reporter* reporter, SkScalar start, SkScalar sweep, |
| 3724 | const SkPath& path) { |
| 3725 | SkRect r = SkRect::MakeEmpty(); |
| 3726 | SkPath::Direction d = SkPath::kCCW_Direction; |
| 3727 | unsigned s = ~0U; |
| 3728 | bool isOval = path.isOval(&r, &d, &s); |
| 3729 | REPORTER_ASSERT(reporter, isOval); |
| 3730 | SkPath recreatedPath; |
| 3731 | recreatedPath.addOval(r, d, s); |
| 3732 | REPORTER_ASSERT(reporter, path == recreatedPath); |
| 3733 | REPORTER_ASSERT(reporter, oval_start_index_to_angle(s) == canonical_start_angle(start)); |
| 3734 | REPORTER_ASSERT(reporter, (SkPath::kCW_Direction == d) == (sweep > 0.f)); |
| 3735 | } |
| 3736 | |
| 3737 | static void test_arc_ovals(skiatest::Reporter* reporter) { |
| 3738 | SkRect oval = SkRect::MakeWH(10, 20); |
| 3739 | for (SkScalar sweep : {-720.f, -540.f, -360.f, 360.f, 432.f, 720.f}) { |
| 3740 | for (SkScalar start = -360.f; start <= 360.f; start += 1.f) { |
| 3741 | SkPath path; |
| 3742 | path.addArc(oval, start, sweep); |
| 3743 | // SkPath's interfaces for inserting and extracting ovals only allow contours |
| 3744 | // to start at multiples of 90 degrees. |
| 3745 | if (std::fmod(start, 90.f) == 0) { |
| 3746 | check_oval_arc(reporter, start, sweep, path); |
| 3747 | } else { |
| 3748 | REPORTER_ASSERT(reporter, !path.isOval(nullptr)); |
| 3749 | } |
| 3750 | } |
| 3751 | // Test start angles that are nearly at valid oval start angles. |
| 3752 | for (float start : {-180.f, -90.f, 90.f, 180.f}) { |
| 3753 | for (float delta : {-SK_ScalarNearlyZero, SK_ScalarNearlyZero}) { |
| 3754 | SkPath path; |
| 3755 | path.addArc(oval, start + delta, sweep); |
| 3756 | check_oval_arc(reporter, start, sweep, path); |
| 3757 | } |
| 3758 | } |
| 3759 | } |
| 3760 | } |
| 3761 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3762 | static void check_move(skiatest::Reporter* reporter, SkPath::RawIter* iter, |
| 3763 | SkScalar x0, SkScalar y0) { |
| 3764 | SkPoint pts[4]; |
| 3765 | SkPath::Verb v = iter->next(pts); |
| 3766 | REPORTER_ASSERT(reporter, v == SkPath::kMove_Verb); |
| 3767 | REPORTER_ASSERT(reporter, pts[0].fX == x0); |
| 3768 | REPORTER_ASSERT(reporter, pts[0].fY == y0); |
| 3769 | } |
| 3770 | |
| 3771 | static void check_line(skiatest::Reporter* reporter, SkPath::RawIter* iter, |
| 3772 | SkScalar x1, SkScalar y1) { |
| 3773 | SkPoint pts[4]; |
| 3774 | SkPath::Verb v = iter->next(pts); |
| 3775 | REPORTER_ASSERT(reporter, v == SkPath::kLine_Verb); |
| 3776 | REPORTER_ASSERT(reporter, pts[1].fX == x1); |
| 3777 | REPORTER_ASSERT(reporter, pts[1].fY == y1); |
| 3778 | } |
| 3779 | |
| 3780 | static void check_quad(skiatest::Reporter* reporter, SkPath::RawIter* iter, |
| 3781 | SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) { |
| 3782 | SkPoint pts[4]; |
| 3783 | SkPath::Verb v = iter->next(pts); |
| 3784 | REPORTER_ASSERT(reporter, v == SkPath::kQuad_Verb); |
| 3785 | REPORTER_ASSERT(reporter, pts[1].fX == x1); |
| 3786 | REPORTER_ASSERT(reporter, pts[1].fY == y1); |
| 3787 | REPORTER_ASSERT(reporter, pts[2].fX == x2); |
| 3788 | REPORTER_ASSERT(reporter, pts[2].fY == y2); |
| 3789 | } |
| 3790 | |
| 3791 | static void check_done(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) { |
| 3792 | SkPoint pts[4]; |
| 3793 | SkPath::Verb v = iter->next(pts); |
| 3794 | REPORTER_ASSERT(reporter, v == SkPath::kDone_Verb); |
| 3795 | } |
| 3796 | |
| 3797 | static void check_done_and_reset(skiatest::Reporter* reporter, SkPath* p, SkPath::RawIter* iter) { |
| 3798 | check_done(reporter, p, iter); |
| 3799 | p->reset(); |
| 3800 | } |
| 3801 | |
| 3802 | static void check_path_is_move_and_reset(skiatest::Reporter* reporter, SkPath* p, |
| 3803 | SkScalar x0, SkScalar y0) { |
| 3804 | SkPath::RawIter iter(*p); |
| 3805 | check_move(reporter, &iter, x0, y0); |
| 3806 | check_done_and_reset(reporter, p, &iter); |
| 3807 | } |
| 3808 | |
| 3809 | static void check_path_is_line_and_reset(skiatest::Reporter* reporter, SkPath* p, |
| 3810 | SkScalar x1, SkScalar y1) { |
| 3811 | SkPath::RawIter iter(*p); |
| 3812 | check_move(reporter, &iter, 0, 0); |
| 3813 | check_line(reporter, &iter, x1, y1); |
| 3814 | check_done_and_reset(reporter, p, &iter); |
| 3815 | } |
| 3816 | |
| 3817 | static void check_path_is_line(skiatest::Reporter* reporter, SkPath* p, |
| 3818 | SkScalar x1, SkScalar y1) { |
| 3819 | SkPath::RawIter iter(*p); |
| 3820 | check_move(reporter, &iter, 0, 0); |
| 3821 | check_line(reporter, &iter, x1, y1); |
| 3822 | check_done(reporter, p, &iter); |
| 3823 | } |
| 3824 | |
| 3825 | static void check_path_is_line_pair_and_reset(skiatest::Reporter* reporter, SkPath* p, |
| 3826 | SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) { |
| 3827 | SkPath::RawIter iter(*p); |
| 3828 | check_move(reporter, &iter, 0, 0); |
| 3829 | check_line(reporter, &iter, x1, y1); |
| 3830 | check_line(reporter, &iter, x2, y2); |
| 3831 | check_done_and_reset(reporter, p, &iter); |
| 3832 | } |
| 3833 | |
| 3834 | static void check_path_is_quad_and_reset(skiatest::Reporter* reporter, SkPath* p, |
| 3835 | SkScalar x1, SkScalar y1, SkScalar x2, SkScalar y2) { |
| 3836 | SkPath::RawIter iter(*p); |
| 3837 | check_move(reporter, &iter, 0, 0); |
| 3838 | check_quad(reporter, &iter, x1, y1, x2, y2); |
| 3839 | check_done_and_reset(reporter, p, &iter); |
| 3840 | } |
| 3841 | |
reed | d5d27d9 | 2015-02-09 13:54:43 -0800 | [diff] [blame] | 3842 | static bool nearly_equal(const SkRect& a, const SkRect& b) { |
| 3843 | return SkScalarNearlyEqual(a.fLeft, b.fLeft) && |
| 3844 | SkScalarNearlyEqual(a.fTop, b.fTop) && |
| 3845 | SkScalarNearlyEqual(a.fRight, b.fRight) && |
| 3846 | SkScalarNearlyEqual(a.fBottom, b.fBottom); |
| 3847 | } |
| 3848 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3849 | static void test_arcTo(skiatest::Reporter* reporter) { |
| 3850 | SkPath p; |
| 3851 | p.arcTo(0, 0, 1, 2, 1); |
| 3852 | check_path_is_line_and_reset(reporter, &p, 0, 0); |
| 3853 | p.arcTo(1, 2, 1, 2, 1); |
| 3854 | check_path_is_line_and_reset(reporter, &p, 1, 2); |
| 3855 | p.arcTo(1, 2, 3, 4, 0); |
| 3856 | check_path_is_line_and_reset(reporter, &p, 1, 2); |
| 3857 | p.arcTo(1, 2, 0, 0, 1); |
| 3858 | check_path_is_line_and_reset(reporter, &p, 1, 2); |
| 3859 | p.arcTo(1, 0, 1, 1, 1); |
| 3860 | SkPoint pt; |
| 3861 | REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == 1); |
| 3862 | p.reset(); |
| 3863 | p.arcTo(1, 0, 1, -1, 1); |
| 3864 | REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt.fX == 1 && pt.fY == -1); |
| 3865 | p.reset(); |
| 3866 | SkRect oval = {1, 2, 3, 4}; |
| 3867 | p.arcTo(oval, 0, 0, true); |
| 3868 | check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY()); |
| 3869 | p.arcTo(oval, 0, 0, false); |
| 3870 | check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY()); |
| 3871 | p.arcTo(oval, 360, 0, true); |
| 3872 | check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY()); |
| 3873 | p.arcTo(oval, 360, 0, false); |
| 3874 | check_path_is_move_and_reset(reporter, &p, oval.fRight, oval.centerY()); |
reed | d5d27d9 | 2015-02-09 13:54:43 -0800 | [diff] [blame] | 3875 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3876 | for (float sweep = 359, delta = 0.5f; sweep != (float) (sweep + delta); ) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 3877 | p.arcTo(oval, 0, sweep, false); |
reed | d5d27d9 | 2015-02-09 13:54:43 -0800 | [diff] [blame] | 3878 | REPORTER_ASSERT(reporter, nearly_equal(p.getBounds(), oval)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3879 | sweep += delta; |
| 3880 | delta /= 2; |
| 3881 | } |
| 3882 | for (float sweep = 361, delta = 0.5f; sweep != (float) (sweep - delta);) { |
commit-bot@chromium.org | 4b413c8 | 2013-11-25 19:44:07 +0000 | [diff] [blame] | 3883 | p.arcTo(oval, 0, sweep, false); |
reed | d5d27d9 | 2015-02-09 13:54:43 -0800 | [diff] [blame] | 3884 | REPORTER_ASSERT(reporter, nearly_equal(p.getBounds(), oval)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3885 | sweep -= delta; |
| 3886 | delta /= 2; |
| 3887 | } |
| 3888 | SkRect noOvalWidth = {1, 2, 0, 3}; |
| 3889 | p.reset(); |
| 3890 | p.arcTo(noOvalWidth, 0, 360, false); |
| 3891 | REPORTER_ASSERT(reporter, p.isEmpty()); |
| 3892 | |
| 3893 | SkRect noOvalHeight = {1, 2, 3, 1}; |
| 3894 | p.reset(); |
| 3895 | p.arcTo(noOvalHeight, 0, 360, false); |
| 3896 | REPORTER_ASSERT(reporter, p.isEmpty()); |
| 3897 | } |
| 3898 | |
| 3899 | static void test_addPath(skiatest::Reporter* reporter) { |
| 3900 | SkPath p, q; |
| 3901 | p.lineTo(1, 2); |
| 3902 | q.moveTo(4, 4); |
| 3903 | q.lineTo(7, 8); |
| 3904 | q.conicTo(8, 7, 6, 5, 0.5f); |
| 3905 | q.quadTo(6, 7, 8, 6); |
| 3906 | q.cubicTo(5, 6, 7, 8, 7, 5); |
| 3907 | q.close(); |
| 3908 | p.addPath(q, -4, -4); |
| 3909 | SkRect expected = {0, 0, 4, 4}; |
| 3910 | REPORTER_ASSERT(reporter, p.getBounds() == expected); |
| 3911 | p.reset(); |
| 3912 | p.reverseAddPath(q); |
| 3913 | SkRect reverseExpected = {4, 4, 8, 8}; |
| 3914 | REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected); |
| 3915 | } |
| 3916 | |
commit-bot@chromium.org | 14747e5 | 2014-02-11 21:16:29 +0000 | [diff] [blame] | 3917 | static void test_addPathMode(skiatest::Reporter* reporter, bool explicitMoveTo, bool extend) { |
| 3918 | SkPath p, q; |
| 3919 | if (explicitMoveTo) { |
| 3920 | p.moveTo(1, 1); |
| 3921 | } |
| 3922 | p.lineTo(1, 2); |
| 3923 | if (explicitMoveTo) { |
| 3924 | q.moveTo(2, 1); |
| 3925 | } |
| 3926 | q.lineTo(2, 2); |
| 3927 | p.addPath(q, extend ? SkPath::kExtend_AddPathMode : SkPath::kAppend_AddPathMode); |
| 3928 | uint8_t verbs[4]; |
| 3929 | int verbcount = p.getVerbs(verbs, 4); |
| 3930 | REPORTER_ASSERT(reporter, verbcount == 4); |
| 3931 | REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb); |
| 3932 | REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb); |
| 3933 | REPORTER_ASSERT(reporter, verbs[2] == (extend ? SkPath::kLine_Verb : SkPath::kMove_Verb)); |
| 3934 | REPORTER_ASSERT(reporter, verbs[3] == SkPath::kLine_Verb); |
| 3935 | } |
| 3936 | |
| 3937 | static void test_extendClosedPath(skiatest::Reporter* reporter) { |
| 3938 | SkPath p, q; |
| 3939 | p.moveTo(1, 1); |
| 3940 | p.lineTo(1, 2); |
| 3941 | p.lineTo(2, 2); |
| 3942 | p.close(); |
| 3943 | q.moveTo(2, 1); |
| 3944 | q.lineTo(2, 3); |
| 3945 | p.addPath(q, SkPath::kExtend_AddPathMode); |
| 3946 | uint8_t verbs[7]; |
| 3947 | int verbcount = p.getVerbs(verbs, 7); |
| 3948 | REPORTER_ASSERT(reporter, verbcount == 7); |
| 3949 | REPORTER_ASSERT(reporter, verbs[0] == SkPath::kMove_Verb); |
| 3950 | REPORTER_ASSERT(reporter, verbs[1] == SkPath::kLine_Verb); |
| 3951 | REPORTER_ASSERT(reporter, verbs[2] == SkPath::kLine_Verb); |
| 3952 | REPORTER_ASSERT(reporter, verbs[3] == SkPath::kClose_Verb); |
| 3953 | REPORTER_ASSERT(reporter, verbs[4] == SkPath::kMove_Verb); |
| 3954 | REPORTER_ASSERT(reporter, verbs[5] == SkPath::kLine_Verb); |
| 3955 | REPORTER_ASSERT(reporter, verbs[6] == SkPath::kLine_Verb); |
| 3956 | |
| 3957 | SkPoint pt; |
| 3958 | REPORTER_ASSERT(reporter, p.getLastPt(&pt)); |
| 3959 | REPORTER_ASSERT(reporter, pt == SkPoint::Make(2, 3)); |
| 3960 | REPORTER_ASSERT(reporter, p.getPoint(3) == SkPoint::Make(1, 1)); |
| 3961 | } |
| 3962 | |
| 3963 | static void test_addEmptyPath(skiatest::Reporter* reporter, SkPath::AddPathMode mode) { |
| 3964 | SkPath p, q, r; |
| 3965 | // case 1: dst is empty |
| 3966 | p.moveTo(2, 1); |
| 3967 | p.lineTo(2, 3); |
| 3968 | q.addPath(p, mode); |
| 3969 | REPORTER_ASSERT(reporter, q == p); |
| 3970 | // case 2: src is empty |
| 3971 | p.addPath(r, mode); |
| 3972 | REPORTER_ASSERT(reporter, q == p); |
| 3973 | // case 3: src and dst are empty |
| 3974 | q.reset(); |
| 3975 | q.addPath(r, mode); |
| 3976 | REPORTER_ASSERT(reporter, q.isEmpty()); |
skia.committer@gmail.com | 877c449 | 2014-02-12 03:02:04 +0000 | [diff] [blame] | 3977 | } |
commit-bot@chromium.org | 14747e5 | 2014-02-11 21:16:29 +0000 | [diff] [blame] | 3978 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3979 | static void test_conicTo_special_case(skiatest::Reporter* reporter) { |
| 3980 | SkPath p; |
| 3981 | p.conicTo(1, 2, 3, 4, -1); |
| 3982 | check_path_is_line_and_reset(reporter, &p, 3, 4); |
| 3983 | p.conicTo(1, 2, 3, 4, SK_ScalarInfinity); |
| 3984 | check_path_is_line_pair_and_reset(reporter, &p, 1, 2, 3, 4); |
| 3985 | p.conicTo(1, 2, 3, 4, 1); |
| 3986 | check_path_is_quad_and_reset(reporter, &p, 1, 2, 3, 4); |
| 3987 | } |
| 3988 | |
| 3989 | static void test_get_point(skiatest::Reporter* reporter) { |
| 3990 | SkPath p; |
| 3991 | SkPoint pt = p.getPoint(0); |
| 3992 | REPORTER_ASSERT(reporter, pt == SkPoint::Make(0, 0)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3993 | REPORTER_ASSERT(reporter, !p.getLastPt(nullptr)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3994 | REPORTER_ASSERT(reporter, !p.getLastPt(&pt) && pt == SkPoint::Make(0, 0)); |
| 3995 | p.setLastPt(10, 10); |
| 3996 | pt = p.getPoint(0); |
| 3997 | REPORTER_ASSERT(reporter, pt == SkPoint::Make(10, 10)); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 3998 | REPORTER_ASSERT(reporter, p.getLastPt(nullptr)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 3999 | p.rMoveTo(10, 10); |
| 4000 | REPORTER_ASSERT(reporter, p.getLastPt(&pt) && pt == SkPoint::Make(20, 20)); |
| 4001 | } |
| 4002 | |
| 4003 | static void test_contains(skiatest::Reporter* reporter) { |
| 4004 | SkPath p; |
caryclark | dbaec73 | 2016-01-05 06:20:09 -0800 | [diff] [blame] | 4005 | p.moveTo(SkBits2Float(0xe085e7b1), SkBits2Float(0x5f512c00)); // -7.7191e+19f, 1.50724e+19f |
| 4006 | 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 |
| 4007 | 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 |
| 4008 | p.lineTo(SkBits2Float(0x609b9872), SkBits2Float(0xdf730de8)); // 8.96947e+19f, -1.75139e+19f |
| 4009 | 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 |
| 4010 | 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 |
caryclark | ba25ddb | 2016-01-05 12:36:09 -0800 | [diff] [blame] | 4011 | // this may return true or false, depending on the platform's numerics, but it should not crash |
| 4012 | (void) p.contains(-77.2027664f, 15.3066053f); |
caryclark | dbaec73 | 2016-01-05 06:20:09 -0800 | [diff] [blame] | 4013 | |
| 4014 | p.reset(); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4015 | p.setFillType(SkPath::kInverseWinding_FillType); |
| 4016 | REPORTER_ASSERT(reporter, p.contains(0, 0)); |
| 4017 | p.setFillType(SkPath::kWinding_FillType); |
| 4018 | REPORTER_ASSERT(reporter, !p.contains(0, 0)); |
| 4019 | p.moveTo(4, 4); |
| 4020 | p.lineTo(6, 8); |
| 4021 | p.lineTo(8, 4); |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 4022 | // test on edge |
| 4023 | REPORTER_ASSERT(reporter, p.contains(6, 4)); |
| 4024 | REPORTER_ASSERT(reporter, p.contains(5, 6)); |
| 4025 | REPORTER_ASSERT(reporter, p.contains(7, 6)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4026 | // test quick reject |
| 4027 | REPORTER_ASSERT(reporter, !p.contains(4, 0)); |
| 4028 | REPORTER_ASSERT(reporter, !p.contains(0, 4)); |
| 4029 | REPORTER_ASSERT(reporter, !p.contains(4, 10)); |
| 4030 | REPORTER_ASSERT(reporter, !p.contains(10, 4)); |
| 4031 | // test various crossings in x |
| 4032 | REPORTER_ASSERT(reporter, !p.contains(5, 7)); |
| 4033 | REPORTER_ASSERT(reporter, p.contains(6, 7)); |
| 4034 | REPORTER_ASSERT(reporter, !p.contains(7, 7)); |
| 4035 | p.reset(); |
| 4036 | p.moveTo(4, 4); |
| 4037 | p.lineTo(8, 6); |
| 4038 | p.lineTo(4, 8); |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 4039 | // test on edge |
| 4040 | REPORTER_ASSERT(reporter, p.contains(4, 6)); |
| 4041 | REPORTER_ASSERT(reporter, p.contains(6, 5)); |
| 4042 | REPORTER_ASSERT(reporter, p.contains(6, 7)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4043 | // test various crossings in y |
| 4044 | REPORTER_ASSERT(reporter, !p.contains(7, 5)); |
| 4045 | REPORTER_ASSERT(reporter, p.contains(7, 6)); |
| 4046 | REPORTER_ASSERT(reporter, !p.contains(7, 7)); |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 4047 | p.reset(); |
| 4048 | p.moveTo(4, 4); |
fs | c91065d | 2015-12-17 09:03:27 -0800 | [diff] [blame] | 4049 | p.lineTo(8, 4); |
| 4050 | p.lineTo(8, 8); |
| 4051 | p.lineTo(4, 8); |
| 4052 | // test on vertices |
| 4053 | REPORTER_ASSERT(reporter, p.contains(4, 4)); |
| 4054 | REPORTER_ASSERT(reporter, p.contains(8, 4)); |
| 4055 | REPORTER_ASSERT(reporter, p.contains(8, 8)); |
| 4056 | REPORTER_ASSERT(reporter, p.contains(4, 8)); |
| 4057 | p.reset(); |
| 4058 | p.moveTo(4, 4); |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 4059 | p.lineTo(6, 8); |
| 4060 | p.lineTo(2, 8); |
| 4061 | // test on edge |
| 4062 | REPORTER_ASSERT(reporter, p.contains(5, 6)); |
| 4063 | REPORTER_ASSERT(reporter, p.contains(4, 8)); |
| 4064 | REPORTER_ASSERT(reporter, p.contains(3, 6)); |
| 4065 | p.reset(); |
| 4066 | p.moveTo(4, 4); |
| 4067 | p.lineTo(0, 6); |
| 4068 | p.lineTo(4, 8); |
| 4069 | // test on edge |
| 4070 | REPORTER_ASSERT(reporter, p.contains(2, 5)); |
| 4071 | REPORTER_ASSERT(reporter, p.contains(2, 7)); |
| 4072 | REPORTER_ASSERT(reporter, p.contains(4, 6)); |
| 4073 | // test canceling coincident edge (a smaller triangle is coincident with a larger one) |
| 4074 | p.reset(); |
| 4075 | p.moveTo(4, 0); |
| 4076 | p.lineTo(6, 4); |
| 4077 | p.lineTo(2, 4); |
| 4078 | p.moveTo(4, 0); |
| 4079 | p.lineTo(0, 8); |
| 4080 | p.lineTo(8, 8); |
| 4081 | REPORTER_ASSERT(reporter, !p.contains(1, 2)); |
| 4082 | REPORTER_ASSERT(reporter, !p.contains(3, 2)); |
| 4083 | REPORTER_ASSERT(reporter, !p.contains(4, 0)); |
| 4084 | REPORTER_ASSERT(reporter, p.contains(4, 4)); |
| 4085 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4086 | // test quads |
| 4087 | p.reset(); |
| 4088 | p.moveTo(4, 4); |
| 4089 | p.quadTo(6, 6, 8, 8); |
| 4090 | p.quadTo(6, 8, 4, 8); |
| 4091 | p.quadTo(4, 6, 4, 4); |
| 4092 | REPORTER_ASSERT(reporter, p.contains(5, 6)); |
| 4093 | REPORTER_ASSERT(reporter, !p.contains(6, 5)); |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 4094 | // test quad edge |
| 4095 | REPORTER_ASSERT(reporter, p.contains(5, 5)); |
| 4096 | REPORTER_ASSERT(reporter, p.contains(5, 8)); |
| 4097 | REPORTER_ASSERT(reporter, p.contains(4, 5)); |
caryclark | 9cb5d75 | 2015-12-18 04:35:24 -0800 | [diff] [blame] | 4098 | // test quad endpoints |
| 4099 | REPORTER_ASSERT(reporter, p.contains(4, 4)); |
| 4100 | REPORTER_ASSERT(reporter, p.contains(8, 8)); |
| 4101 | REPORTER_ASSERT(reporter, p.contains(4, 8)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4102 | |
| 4103 | p.reset(); |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 4104 | const SkPoint qPts[] = {{6, 6}, {8, 8}, {6, 8}, {4, 8}, {4, 6}, {4, 4}, {6, 6}}; |
| 4105 | p.moveTo(qPts[0]); |
| 4106 | for (int index = 1; index < (int) SK_ARRAY_COUNT(qPts); index += 2) { |
| 4107 | p.quadTo(qPts[index], qPts[index + 1]); |
| 4108 | } |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4109 | REPORTER_ASSERT(reporter, p.contains(5, 6)); |
| 4110 | REPORTER_ASSERT(reporter, !p.contains(6, 5)); |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 4111 | // test quad edge |
| 4112 | SkPoint halfway; |
| 4113 | for (int index = 0; index < (int) SK_ARRAY_COUNT(qPts) - 2; index += 2) { |
| 4114 | SkEvalQuadAt(&qPts[index], 0.5f, &halfway, nullptr); |
| 4115 | REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY)); |
| 4116 | } |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4117 | |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 4118 | // test conics |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4119 | p.reset(); |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 4120 | const SkPoint kPts[] = {{4, 4}, {6, 6}, {8, 8}, {6, 8}, {4, 8}, {4, 6}, {4, 4}}; |
| 4121 | p.moveTo(kPts[0]); |
| 4122 | for (int index = 1; index < (int) SK_ARRAY_COUNT(kPts); index += 2) { |
| 4123 | p.conicTo(kPts[index], kPts[index + 1], 0.5f); |
| 4124 | } |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4125 | REPORTER_ASSERT(reporter, p.contains(5, 6)); |
| 4126 | REPORTER_ASSERT(reporter, !p.contains(6, 5)); |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 4127 | // test conic edge |
| 4128 | for (int index = 0; index < (int) SK_ARRAY_COUNT(kPts) - 2; index += 2) { |
| 4129 | SkConic conic(&kPts[index], 0.5f); |
| 4130 | halfway = conic.evalAt(0.5f); |
| 4131 | REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY)); |
| 4132 | } |
caryclark | 9cb5d75 | 2015-12-18 04:35:24 -0800 | [diff] [blame] | 4133 | // test conic end points |
| 4134 | REPORTER_ASSERT(reporter, p.contains(4, 4)); |
| 4135 | REPORTER_ASSERT(reporter, p.contains(8, 8)); |
| 4136 | REPORTER_ASSERT(reporter, p.contains(4, 8)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4137 | |
| 4138 | // test cubics |
| 4139 | SkPoint pts[] = {{5, 4}, {6, 5}, {7, 6}, {6, 6}, {4, 6}, {5, 7}, {5, 5}, {5, 4}, {6, 5}, {7, 6}}; |
| 4140 | for (int i = 0; i < 3; ++i) { |
| 4141 | p.reset(); |
| 4142 | p.setFillType(SkPath::kEvenOdd_FillType); |
| 4143 | p.moveTo(pts[i].fX, pts[i].fY); |
| 4144 | 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); |
| 4145 | 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); |
| 4146 | p.close(); |
| 4147 | REPORTER_ASSERT(reporter, p.contains(5.5f, 5.5f)); |
| 4148 | REPORTER_ASSERT(reporter, !p.contains(4.5f, 5.5f)); |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 4149 | // test cubic edge |
| 4150 | SkEvalCubicAt(&pts[i], 0.5f, &halfway, nullptr, nullptr); |
| 4151 | REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY)); |
| 4152 | SkEvalCubicAt(&pts[i + 3], 0.5f, &halfway, nullptr, nullptr); |
| 4153 | REPORTER_ASSERT(reporter, p.contains(halfway.fX, halfway.fY)); |
caryclark | 9cb5d75 | 2015-12-18 04:35:24 -0800 | [diff] [blame] | 4154 | // test cubic end points |
| 4155 | REPORTER_ASSERT(reporter, p.contains(pts[i].fX, pts[i].fY)); |
| 4156 | REPORTER_ASSERT(reporter, p.contains(pts[i + 3].fX, pts[i + 3].fY)); |
| 4157 | REPORTER_ASSERT(reporter, p.contains(pts[i + 6].fX, pts[i + 6].fY)); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4158 | } |
| 4159 | } |
| 4160 | |
robertphillips@google.com | 0efb21b | 2013-12-13 19:36:25 +0000 | [diff] [blame] | 4161 | class PathRefTest_Private { |
| 4162 | public: |
| 4163 | static void TestPathRef(skiatest::Reporter* reporter) { |
| 4164 | static const int kRepeatCnt = 10; |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4165 | |
bungeman | 6bd5284 | 2016-10-27 09:30:08 -0700 | [diff] [blame] | 4166 | sk_sp<SkPathRef> pathRef(new SkPathRef); |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4167 | |
robertphillips@google.com | 0efb21b | 2013-12-13 19:36:25 +0000 | [diff] [blame] | 4168 | SkPathRef::Editor ed(&pathRef); |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4169 | |
robertphillips@google.com | 0efb21b | 2013-12-13 19:36:25 +0000 | [diff] [blame] | 4170 | { |
| 4171 | ed.growForRepeatedVerb(SkPath::kMove_Verb, kRepeatCnt); |
| 4172 | REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs()); |
| 4173 | REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints()); |
| 4174 | REPORTER_ASSERT(reporter, 0 == pathRef->getSegmentMasks()); |
| 4175 | for (int i = 0; i < kRepeatCnt; ++i) { |
| 4176 | REPORTER_ASSERT(reporter, SkPath::kMove_Verb == pathRef->atVerb(i)); |
| 4177 | } |
| 4178 | ed.resetToSize(0, 0, 0); |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4179 | } |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4180 | |
robertphillips@google.com | 0efb21b | 2013-12-13 19:36:25 +0000 | [diff] [blame] | 4181 | { |
| 4182 | ed.growForRepeatedVerb(SkPath::kLine_Verb, kRepeatCnt); |
| 4183 | REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs()); |
| 4184 | REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countPoints()); |
| 4185 | REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == pathRef->getSegmentMasks()); |
| 4186 | for (int i = 0; i < kRepeatCnt; ++i) { |
| 4187 | REPORTER_ASSERT(reporter, SkPath::kLine_Verb == pathRef->atVerb(i)); |
| 4188 | } |
| 4189 | ed.resetToSize(0, 0, 0); |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4190 | } |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4191 | |
robertphillips@google.com | 0efb21b | 2013-12-13 19:36:25 +0000 | [diff] [blame] | 4192 | { |
| 4193 | ed.growForRepeatedVerb(SkPath::kQuad_Verb, kRepeatCnt); |
| 4194 | REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs()); |
| 4195 | REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints()); |
| 4196 | REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == pathRef->getSegmentMasks()); |
| 4197 | for (int i = 0; i < kRepeatCnt; ++i) { |
| 4198 | REPORTER_ASSERT(reporter, SkPath::kQuad_Verb == pathRef->atVerb(i)); |
| 4199 | } |
| 4200 | ed.resetToSize(0, 0, 0); |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4201 | } |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4202 | |
robertphillips@google.com | 0efb21b | 2013-12-13 19:36:25 +0000 | [diff] [blame] | 4203 | { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 4204 | SkScalar* weights = nullptr; |
robertphillips@google.com | 0efb21b | 2013-12-13 19:36:25 +0000 | [diff] [blame] | 4205 | ed.growForRepeatedVerb(SkPath::kConic_Verb, kRepeatCnt, &weights); |
| 4206 | REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs()); |
| 4207 | REPORTER_ASSERT(reporter, 2*kRepeatCnt == pathRef->countPoints()); |
| 4208 | REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countWeights()); |
| 4209 | REPORTER_ASSERT(reporter, SkPath::kConic_SegmentMask == pathRef->getSegmentMasks()); |
bsalomon | 49f085d | 2014-09-05 13:34:00 -0700 | [diff] [blame] | 4210 | REPORTER_ASSERT(reporter, weights); |
robertphillips@google.com | 0efb21b | 2013-12-13 19:36:25 +0000 | [diff] [blame] | 4211 | for (int i = 0; i < kRepeatCnt; ++i) { |
| 4212 | REPORTER_ASSERT(reporter, SkPath::kConic_Verb == pathRef->atVerb(i)); |
| 4213 | } |
| 4214 | ed.resetToSize(0, 0, 0); |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4215 | } |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4216 | |
robertphillips@google.com | 0efb21b | 2013-12-13 19:36:25 +0000 | [diff] [blame] | 4217 | { |
| 4218 | ed.growForRepeatedVerb(SkPath::kCubic_Verb, kRepeatCnt); |
| 4219 | REPORTER_ASSERT(reporter, kRepeatCnt == pathRef->countVerbs()); |
| 4220 | REPORTER_ASSERT(reporter, 3*kRepeatCnt == pathRef->countPoints()); |
| 4221 | REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == pathRef->getSegmentMasks()); |
| 4222 | for (int i = 0; i < kRepeatCnt; ++i) { |
| 4223 | REPORTER_ASSERT(reporter, SkPath::kCubic_Verb == pathRef->atVerb(i)); |
| 4224 | } |
| 4225 | ed.resetToSize(0, 0, 0); |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4226 | } |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4227 | } |
robertphillips@google.com | 0efb21b | 2013-12-13 19:36:25 +0000 | [diff] [blame] | 4228 | }; |
robertphillips@google.com | 6b8dbb6 | 2013-12-12 23:03:51 +0000 | [diff] [blame] | 4229 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4230 | static void test_operatorEqual(skiatest::Reporter* reporter) { |
| 4231 | SkPath a; |
| 4232 | SkPath b; |
| 4233 | REPORTER_ASSERT(reporter, a == a); |
| 4234 | REPORTER_ASSERT(reporter, a == b); |
| 4235 | a.setFillType(SkPath::kInverseWinding_FillType); |
| 4236 | REPORTER_ASSERT(reporter, a != b); |
| 4237 | a.reset(); |
| 4238 | REPORTER_ASSERT(reporter, a == b); |
| 4239 | a.lineTo(1, 1); |
| 4240 | REPORTER_ASSERT(reporter, a != b); |
| 4241 | a.reset(); |
| 4242 | REPORTER_ASSERT(reporter, a == b); |
| 4243 | a.lineTo(1, 1); |
| 4244 | b.lineTo(1, 2); |
| 4245 | REPORTER_ASSERT(reporter, a != b); |
| 4246 | a.reset(); |
| 4247 | a.lineTo(1, 2); |
| 4248 | REPORTER_ASSERT(reporter, a == b); |
| 4249 | } |
| 4250 | |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4251 | static void compare_dump(skiatest::Reporter* reporter, const SkPath& path, bool force, |
caryclark | e956259 | 2014-09-15 09:26:09 -0700 | [diff] [blame] | 4252 | bool dumpAsHex, const char* str) { |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4253 | SkDynamicMemoryWStream wStream; |
caryclark | e956259 | 2014-09-15 09:26:09 -0700 | [diff] [blame] | 4254 | path.dump(&wStream, force, dumpAsHex); |
reed | 42943c8 | 2016-09-12 12:01:44 -0700 | [diff] [blame] | 4255 | sk_sp<SkData> data = wStream.detachAsData(); |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4256 | REPORTER_ASSERT(reporter, data->size() == strlen(str)); |
mtklein | d489759 | 2014-11-14 09:22:40 -0800 | [diff] [blame] | 4257 | if (strlen(str) > 0) { |
| 4258 | REPORTER_ASSERT(reporter, !memcmp(data->data(), str, strlen(str))); |
| 4259 | } else { |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 4260 | REPORTER_ASSERT(reporter, data->data() == nullptr || !memcmp(data->data(), str, strlen(str))); |
mtklein | d489759 | 2014-11-14 09:22:40 -0800 | [diff] [blame] | 4261 | } |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4262 | } |
| 4263 | |
| 4264 | static void test_dump(skiatest::Reporter* reporter) { |
| 4265 | SkPath p; |
Cary Clark | 9f67f04 | 2016-12-16 11:32:54 -0500 | [diff] [blame] | 4266 | compare_dump(reporter, p, false, false, "path.setFillType(SkPath::kWinding_FillType);\n"); |
| 4267 | compare_dump(reporter, p, true, false, "path.setFillType(SkPath::kWinding_FillType);\n"); |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4268 | p.moveTo(1, 2); |
| 4269 | p.lineTo(3, 4); |
Cary Clark | 9f67f04 | 2016-12-16 11:32:54 -0500 | [diff] [blame] | 4270 | compare_dump(reporter, p, false, false, "path.setFillType(SkPath::kWinding_FillType);\n" |
| 4271 | "path.moveTo(1, 2);\n" |
caryclark | e956259 | 2014-09-15 09:26:09 -0700 | [diff] [blame] | 4272 | "path.lineTo(3, 4);\n"); |
Cary Clark | 9f67f04 | 2016-12-16 11:32:54 -0500 | [diff] [blame] | 4273 | compare_dump(reporter, p, true, false, "path.setFillType(SkPath::kWinding_FillType);\n" |
| 4274 | "path.moveTo(1, 2);\n" |
caryclark | e956259 | 2014-09-15 09:26:09 -0700 | [diff] [blame] | 4275 | "path.lineTo(3, 4);\n" |
| 4276 | "path.lineTo(1, 2);\n" |
| 4277 | "path.close();\n"); |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4278 | p.reset(); |
Cary Clark | 9f67f04 | 2016-12-16 11:32:54 -0500 | [diff] [blame] | 4279 | p.setFillType(SkPath::kEvenOdd_FillType); |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4280 | p.moveTo(1, 2); |
| 4281 | p.quadTo(3, 4, 5, 6); |
Cary Clark | 9f67f04 | 2016-12-16 11:32:54 -0500 | [diff] [blame] | 4282 | compare_dump(reporter, p, false, false, "path.setFillType(SkPath::kEvenOdd_FillType);\n" |
| 4283 | "path.moveTo(1, 2);\n" |
caryclark | e956259 | 2014-09-15 09:26:09 -0700 | [diff] [blame] | 4284 | "path.quadTo(3, 4, 5, 6);\n"); |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4285 | p.reset(); |
Cary Clark | 9f67f04 | 2016-12-16 11:32:54 -0500 | [diff] [blame] | 4286 | p.setFillType(SkPath::kInverseWinding_FillType); |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4287 | p.moveTo(1, 2); |
| 4288 | p.conicTo(3, 4, 5, 6, 0.5f); |
Cary Clark | 9f67f04 | 2016-12-16 11:32:54 -0500 | [diff] [blame] | 4289 | compare_dump(reporter, p, false, false, "path.setFillType(SkPath::kInverseWinding_FillType);\n" |
| 4290 | "path.moveTo(1, 2);\n" |
caryclark | e956259 | 2014-09-15 09:26:09 -0700 | [diff] [blame] | 4291 | "path.conicTo(3, 4, 5, 6, 0.5f);\n"); |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4292 | p.reset(); |
Cary Clark | 9f67f04 | 2016-12-16 11:32:54 -0500 | [diff] [blame] | 4293 | p.setFillType(SkPath::kInverseEvenOdd_FillType); |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4294 | p.moveTo(1, 2); |
| 4295 | p.cubicTo(3, 4, 5, 6, 7, 8); |
Cary Clark | 9f67f04 | 2016-12-16 11:32:54 -0500 | [diff] [blame] | 4296 | compare_dump(reporter, p, false, false, "path.setFillType(SkPath::kInverseEvenOdd_FillType);\n" |
| 4297 | "path.moveTo(1, 2);\n" |
caryclark | e956259 | 2014-09-15 09:26:09 -0700 | [diff] [blame] | 4298 | "path.cubicTo(3, 4, 5, 6, 7, 8);\n"); |
| 4299 | p.reset(); |
Cary Clark | 9f67f04 | 2016-12-16 11:32:54 -0500 | [diff] [blame] | 4300 | p.setFillType(SkPath::kWinding_FillType); |
caryclark | e956259 | 2014-09-15 09:26:09 -0700 | [diff] [blame] | 4301 | p.moveTo(1, 2); |
| 4302 | p.lineTo(3, 4); |
caryclark | 08fa28c | 2014-10-23 13:08:56 -0700 | [diff] [blame] | 4303 | compare_dump(reporter, p, false, true, |
Cary Clark | 9f67f04 | 2016-12-16 11:32:54 -0500 | [diff] [blame] | 4304 | "path.setFillType(SkPath::kWinding_FillType);\n" |
caryclark | 08fa28c | 2014-10-23 13:08:56 -0700 | [diff] [blame] | 4305 | "path.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)); // 1, 2\n" |
| 4306 | "path.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)); // 3, 4\n"); |
caryclark | e956259 | 2014-09-15 09:26:09 -0700 | [diff] [blame] | 4307 | p.reset(); |
| 4308 | p.moveTo(SkBits2Float(0x3f800000), SkBits2Float(0x40000000)); |
| 4309 | p.lineTo(SkBits2Float(0x40400000), SkBits2Float(0x40800000)); |
Cary Clark | 9f67f04 | 2016-12-16 11:32:54 -0500 | [diff] [blame] | 4310 | compare_dump(reporter, p, false, false, "path.setFillType(SkPath::kWinding_FillType);\n" |
| 4311 | "path.moveTo(1, 2);\n" |
caryclark | e956259 | 2014-09-15 09:26:09 -0700 | [diff] [blame] | 4312 | "path.lineTo(3, 4);\n"); |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4313 | } |
| 4314 | |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 4315 | namespace { |
| 4316 | |
| 4317 | class ChangeListener : public SkPathRef::GenIDChangeListener { |
| 4318 | public: |
| 4319 | ChangeListener(bool *changed) : fChanged(changed) { *fChanged = false; } |
Brian Salomon | d3b6597 | 2017-03-22 12:05:03 -0400 | [diff] [blame] | 4320 | ~ChangeListener() override {} |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 4321 | void onChange() override { |
| 4322 | *fChanged = true; |
| 4323 | } |
| 4324 | private: |
| 4325 | bool* fChanged; |
| 4326 | }; |
| 4327 | |
| 4328 | } |
| 4329 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4330 | class PathTest_Private { |
| 4331 | public: |
| 4332 | static void TestPathTo(skiatest::Reporter* reporter) { |
| 4333 | SkPath p, q; |
| 4334 | p.lineTo(4, 4); |
| 4335 | p.reversePathTo(q); |
| 4336 | check_path_is_line(reporter, &p, 4, 4); |
| 4337 | q.moveTo(-4, -4); |
| 4338 | p.reversePathTo(q); |
| 4339 | check_path_is_line(reporter, &p, 4, 4); |
| 4340 | q.lineTo(7, 8); |
| 4341 | q.conicTo(8, 7, 6, 5, 0.5f); |
| 4342 | q.quadTo(6, 7, 8, 6); |
| 4343 | q.cubicTo(5, 6, 7, 8, 7, 5); |
| 4344 | q.close(); |
| 4345 | p.reversePathTo(q); |
| 4346 | SkRect reverseExpected = {-4, -4, 8, 8}; |
| 4347 | REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected); |
| 4348 | } |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 4349 | |
| 4350 | static void TestPathrefListeners(skiatest::Reporter* reporter) { |
| 4351 | SkPath p; |
| 4352 | |
| 4353 | bool changed = false; |
| 4354 | p.moveTo(0, 0); |
| 4355 | |
| 4356 | // Check that listener is notified on moveTo(). |
| 4357 | |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 4358 | SkPathPriv::AddGenIDChangeListener(p, new ChangeListener(&changed)); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 4359 | REPORTER_ASSERT(reporter, !changed); |
| 4360 | p.moveTo(10, 0); |
| 4361 | REPORTER_ASSERT(reporter, changed); |
| 4362 | |
| 4363 | // Check that listener is notified on lineTo(). |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 4364 | SkPathPriv::AddGenIDChangeListener(p, new ChangeListener(&changed)); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 4365 | REPORTER_ASSERT(reporter, !changed); |
| 4366 | p.lineTo(20, 0); |
| 4367 | REPORTER_ASSERT(reporter, changed); |
| 4368 | |
| 4369 | // Check that listener is notified on reset(). |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 4370 | SkPathPriv::AddGenIDChangeListener(p, new ChangeListener(&changed)); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 4371 | REPORTER_ASSERT(reporter, !changed); |
| 4372 | p.reset(); |
| 4373 | REPORTER_ASSERT(reporter, changed); |
| 4374 | |
| 4375 | p.moveTo(0, 0); |
| 4376 | |
| 4377 | // Check that listener is notified on rewind(). |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 4378 | SkPathPriv::AddGenIDChangeListener(p, new ChangeListener(&changed)); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 4379 | REPORTER_ASSERT(reporter, !changed); |
| 4380 | p.rewind(); |
| 4381 | REPORTER_ASSERT(reporter, changed); |
| 4382 | |
| 4383 | // Check that listener is notified when pathref is deleted. |
| 4384 | { |
| 4385 | SkPath q; |
| 4386 | q.moveTo(10, 10); |
halcanary | 385fe4d | 2015-08-26 13:07:48 -0700 | [diff] [blame] | 4387 | SkPathPriv::AddGenIDChangeListener(q, new ChangeListener(&changed)); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 4388 | REPORTER_ASSERT(reporter, !changed); |
| 4389 | } |
| 4390 | // q went out of scope. |
| 4391 | REPORTER_ASSERT(reporter, changed); |
| 4392 | } |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4393 | }; |
| 4394 | |
reed | 158fabb | 2016-07-20 10:06:59 -0700 | [diff] [blame] | 4395 | static void test_crbug_629455(skiatest::Reporter* reporter) { |
| 4396 | SkPath path; |
| 4397 | path.moveTo(0, 0); |
| 4398 | path.cubicTo(SkBits2Float(0xcdcdcd00), SkBits2Float(0xcdcdcdcd), |
| 4399 | SkBits2Float(0xcdcdcdcd), SkBits2Float(0xcdcdcdcd), |
| 4400 | SkBits2Float(0x423fcdcd), SkBits2Float(0x40ed9341)); |
| 4401 | // AKA: cubicTo(-4.31596e+08f, -4.31602e+08f, -4.31602e+08f, -4.31602e+08f, 47.951f, 7.42423f); |
| 4402 | path.lineTo(0, 0); |
| 4403 | |
| 4404 | auto surface = SkSurface::MakeRasterN32Premul(100, 100); |
| 4405 | SkPaint paint; |
| 4406 | paint.setAntiAlias(true); |
| 4407 | surface->getCanvas()->drawPath(path, paint); |
| 4408 | } |
| 4409 | |
liyuqian | c78eff9 | 2016-11-09 11:18:30 -0800 | [diff] [blame] | 4410 | static void test_fuzz_crbug_662952(skiatest::Reporter* reporter) { |
| 4411 | SkPath path; |
| 4412 | path.moveTo(SkBits2Float(0x4109999a), SkBits2Float(0x411c0000)); // 8.6f, 9.75f |
| 4413 | path.lineTo(SkBits2Float(0x410a6666), SkBits2Float(0x411c0000)); // 8.65f, 9.75f |
| 4414 | path.lineTo(SkBits2Float(0x410a6666), SkBits2Float(0x411e6666)); // 8.65f, 9.9f |
| 4415 | path.lineTo(SkBits2Float(0x4109999a), SkBits2Float(0x411e6666)); // 8.6f, 9.9f |
| 4416 | path.lineTo(SkBits2Float(0x4109999a), SkBits2Float(0x411c0000)); // 8.6f, 9.75f |
| 4417 | path.close(); |
| 4418 | |
| 4419 | auto surface = SkSurface::MakeRasterN32Premul(100, 100); |
| 4420 | SkPaint paint; |
| 4421 | paint.setAntiAlias(true); |
| 4422 | surface->getCanvas()->clipPath(path, true); |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 4423 | surface->getCanvas()->drawRect(SkRect::MakeWH(100, 100), paint); |
liyuqian | c78eff9 | 2016-11-09 11:18:30 -0800 | [diff] [blame] | 4424 | } |
| 4425 | |
Yuqian Li | db13a09 | 2016-11-29 10:29:22 -0500 | [diff] [blame] | 4426 | static void test_path_crbugskia6003() { |
| 4427 | auto surface(SkSurface::MakeRasterN32Premul(500, 500)); |
| 4428 | SkCanvas* canvas = surface->getCanvas(); |
| 4429 | SkPaint paint; |
| 4430 | paint.setAntiAlias(true); |
| 4431 | SkPath path; |
| 4432 | path.moveTo(SkBits2Float(0x4325e666), SkBits2Float(0x42a1999a)); // 165.9f, 80.8f |
| 4433 | path.lineTo(SkBits2Float(0x4325e666), SkBits2Float(0x42a2999a)); // 165.9f, 81.3f |
| 4434 | path.lineTo(SkBits2Float(0x4325b333), SkBits2Float(0x42a2999a)); // 165.7f, 81.3f |
| 4435 | path.lineTo(SkBits2Float(0x4325b333), SkBits2Float(0x42a16666)); // 165.7f, 80.7f |
| 4436 | path.lineTo(SkBits2Float(0x4325b333), SkBits2Float(0x429f6666)); // 165.7f, 79.7f |
| 4437 | // 165.7f, 79.7f, 165.8f, 79.7f, 165.8f, 79.7f |
| 4438 | path.cubicTo(SkBits2Float(0x4325b333), SkBits2Float(0x429f6666), SkBits2Float(0x4325cccc), |
| 4439 | SkBits2Float(0x429f6666), SkBits2Float(0x4325cccc), SkBits2Float(0x429f6666)); |
| 4440 | // 165.8f, 79.7f, 165.8f, 79.7f, 165.9f, 79.7f |
| 4441 | path.cubicTo(SkBits2Float(0x4325cccc), SkBits2Float(0x429f6666), SkBits2Float(0x4325cccc), |
| 4442 | SkBits2Float(0x429f6666), SkBits2Float(0x4325e666), SkBits2Float(0x429f6666)); |
| 4443 | path.lineTo(SkBits2Float(0x4325e666), SkBits2Float(0x42a1999a)); // 165.9f, 80.8f |
| 4444 | path.close(); |
| 4445 | canvas->clipPath(path, true); |
Mike Reed | 3661bc9 | 2017-02-22 13:21:42 -0500 | [diff] [blame] | 4446 | canvas->drawRect(SkRect::MakeWH(500, 500), paint); |
Yuqian Li | db13a09 | 2016-11-29 10:29:22 -0500 | [diff] [blame] | 4447 | } |
| 4448 | |
Yuqian Li | c4f66af | 2016-11-11 09:36:53 -0500 | [diff] [blame] | 4449 | static void test_fuzz_crbug_662730(skiatest::Reporter* reporter) { |
| 4450 | SkPath path; |
| 4451 | path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 |
| 4452 | path.lineTo(SkBits2Float(0xd5394437), SkBits2Float(0x37373737)); // -1.2731e+13f, 1.09205e-05f |
| 4453 | path.lineTo(SkBits2Float(0x37373737), SkBits2Float(0x37373737)); // 1.09205e-05f, 1.09205e-05f |
| 4454 | path.lineTo(SkBits2Float(0x37373745), SkBits2Float(0x0001b800)); // 1.09205e-05f, 1.57842e-40f |
| 4455 | path.close(); |
| 4456 | |
| 4457 | auto surface = SkSurface::MakeRasterN32Premul(100, 100); |
| 4458 | SkPaint paint; |
| 4459 | paint.setAntiAlias(true); |
| 4460 | surface->getCanvas()->drawPath(path, paint); |
| 4461 | } |
| 4462 | |
caryclark | 8e7b19d | 2016-02-18 04:11:48 -0800 | [diff] [blame] | 4463 | static void test_interp(skiatest::Reporter* reporter) { |
| 4464 | SkPath p1, p2, out; |
| 4465 | REPORTER_ASSERT(reporter, p1.isInterpolatable(p2)); |
| 4466 | REPORTER_ASSERT(reporter, p1.interpolate(p2, 0, &out)); |
| 4467 | REPORTER_ASSERT(reporter, p1 == out); |
| 4468 | REPORTER_ASSERT(reporter, p1.interpolate(p2, 1, &out)); |
| 4469 | REPORTER_ASSERT(reporter, p1 == out); |
| 4470 | p1.moveTo(0, 2); |
| 4471 | p1.lineTo(0, 4); |
| 4472 | REPORTER_ASSERT(reporter, !p1.isInterpolatable(p2)); |
| 4473 | REPORTER_ASSERT(reporter, !p1.interpolate(p2, 1, &out)); |
| 4474 | p2.moveTo(6, 0); |
| 4475 | p2.lineTo(8, 0); |
| 4476 | REPORTER_ASSERT(reporter, p1.isInterpolatable(p2)); |
| 4477 | REPORTER_ASSERT(reporter, p1.interpolate(p2, 0, &out)); |
| 4478 | REPORTER_ASSERT(reporter, p2 == out); |
| 4479 | REPORTER_ASSERT(reporter, p1.interpolate(p2, 1, &out)); |
| 4480 | REPORTER_ASSERT(reporter, p1 == out); |
| 4481 | REPORTER_ASSERT(reporter, p1.interpolate(p2, 0.5f, &out)); |
| 4482 | REPORTER_ASSERT(reporter, out.getBounds() == SkRect::MakeLTRB(3, 1, 4, 2)); |
| 4483 | p1.reset(); |
| 4484 | p1.moveTo(4, 4); |
| 4485 | p1.conicTo(5, 4, 5, 5, 1 / SkScalarSqrt(2)); |
| 4486 | p2.reset(); |
| 4487 | p2.moveTo(4, 2); |
| 4488 | p2.conicTo(7, 2, 7, 5, 1 / SkScalarSqrt(2)); |
| 4489 | REPORTER_ASSERT(reporter, p1.isInterpolatable(p2)); |
| 4490 | REPORTER_ASSERT(reporter, p1.interpolate(p2, 0.5f, &out)); |
| 4491 | REPORTER_ASSERT(reporter, out.getBounds() == SkRect::MakeLTRB(4, 3, 6, 5)); |
| 4492 | p2.reset(); |
| 4493 | p2.moveTo(4, 2); |
| 4494 | p2.conicTo(6, 3, 6, 5, 1); |
| 4495 | REPORTER_ASSERT(reporter, !p1.isInterpolatable(p2)); |
| 4496 | p2.reset(); |
| 4497 | p2.moveTo(4, 4); |
| 4498 | p2.conicTo(5, 4, 5, 5, 0.5f); |
| 4499 | REPORTER_ASSERT(reporter, !p1.isInterpolatable(p2)); |
| 4500 | } |
| 4501 | |
| 4502 | DEF_TEST(PathInterp, reporter) { |
| 4503 | test_interp(reporter); |
| 4504 | } |
| 4505 | |
Mike Reed | 0c0da2b | 2017-01-26 11:03:50 -0500 | [diff] [blame] | 4506 | #include "SkSurface.h" |
| 4507 | DEF_TEST(PathBigCubic, reporter) { |
| 4508 | SkPath path; |
| 4509 | path.moveTo(SkBits2Float(0x00000000), SkBits2Float(0x00000000)); // 0, 0 |
| 4510 | path.moveTo(SkBits2Float(0x44000000), SkBits2Float(0x373938b8)); // 512, 1.10401e-05f |
| 4511 | path.cubicTo(SkBits2Float(0x00000001), SkBits2Float(0xdf000052), SkBits2Float(0x00000100), SkBits2Float(0x00000000), SkBits2Float(0x00000100), SkBits2Float(0x00000000)); // 1.4013e-45f, -9.22346e+18f, 3.58732e-43f, 0, 3.58732e-43f, 0 |
| 4512 | path.moveTo(0, 512); |
| 4513 | |
| 4514 | // this call should not assert |
Mike Reed | c121a88 | 2017-01-27 11:59:07 -0500 | [diff] [blame] | 4515 | SkSurface::MakeRasterN32Premul(255, 255, nullptr)->getCanvas()->drawPath(path, SkPaint()); |
Mike Reed | 0c0da2b | 2017-01-26 11:03:50 -0500 | [diff] [blame] | 4516 | } |
| 4517 | |
caryclark | 9aacd90 | 2015-12-14 08:38:09 -0800 | [diff] [blame] | 4518 | DEF_TEST(PathContains, reporter) { |
| 4519 | test_contains(reporter); |
| 4520 | } |
| 4521 | |
commit-bot@chromium.org | 05ec223 | 2014-01-15 18:00:57 +0000 | [diff] [blame] | 4522 | DEF_TEST(Paths, reporter) { |
caryclark | bac1046 | 2016-09-22 10:24:59 -0700 | [diff] [blame] | 4523 | test_fuzz_crbug_647922(); |
caryclark | e97fe83 | 2016-09-06 08:54:10 -0700 | [diff] [blame] | 4524 | test_fuzz_crbug_643933(); |
reed | ff863bc | 2016-08-17 07:37:57 -0700 | [diff] [blame] | 4525 | test_sect_with_horizontal_needs_pinning(); |
reed | 158fabb | 2016-07-20 10:06:59 -0700 | [diff] [blame] | 4526 | test_crbug_629455(reporter); |
reed | b1b12f8 | 2016-07-13 10:56:53 -0700 | [diff] [blame] | 4527 | test_fuzz_crbug_627414(reporter); |
commit-bot@chromium.org | 4e332f8 | 2014-05-05 16:04:42 +0000 | [diff] [blame] | 4528 | test_path_crbug364224(); |
liyuqian | c78eff9 | 2016-11-09 11:18:30 -0800 | [diff] [blame] | 4529 | test_fuzz_crbug_662952(reporter); |
Yuqian Li | c4f66af | 2016-11-11 09:36:53 -0500 | [diff] [blame] | 4530 | test_fuzz_crbug_662730(reporter); |
liyuqian | 041da38 | 2016-11-11 09:59:51 -0800 | [diff] [blame] | 4531 | test_fuzz_crbug_662780(); |
Yuqian Li | 20079a9 | 2016-11-16 13:07:57 -0500 | [diff] [blame] | 4532 | test_mask_overflow(); |
Yuqian Li | db13a09 | 2016-11-29 10:29:22 -0500 | [diff] [blame] | 4533 | test_path_crbugskia6003(); |
Yuqian Li | 79252f7 | 2016-11-29 15:02:49 -0500 | [diff] [blame] | 4534 | test_fuzz_crbug_668907(); |
commit-bot@chromium.org | 4e332f8 | 2014-05-05 16:04:42 +0000 | [diff] [blame] | 4535 | |
Hal Canary | fafe135 | 2017-04-11 12:12:02 -0400 | [diff] [blame] | 4536 | SkSize::Make(3, 4); |
bungeman@google.com | a5809a3 | 2013-06-21 15:13:34 +0000 | [diff] [blame] | 4537 | |
| 4538 | SkPath p, empty; |
| 4539 | SkRect bounds, bounds2; |
| 4540 | test_empty(reporter, p); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4541 | |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 4542 | REPORTER_ASSERT(reporter, p.getBounds().isEmpty()); |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 4543 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4544 | // this triggers a code path in SkPath::operator= which is otherwise unexercised |
| 4545 | SkPath& self = p; |
| 4546 | p = self; |
| 4547 | |
| 4548 | // this triggers a code path in SkPath::swap which is otherwise unexercised |
| 4549 | p.swap(self); |
| 4550 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4551 | bounds.set(0, 0, SK_Scalar1, SK_Scalar1); |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 4552 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 4553 | p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1); |
| 4554 | check_convex_bounds(reporter, p, bounds); |
reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 4555 | // we have quads or cubics |
reed | 220f926 | 2014-12-17 08:21:04 -0800 | [diff] [blame] | 4556 | REPORTER_ASSERT(reporter, |
| 4557 | p.getSegmentMasks() & (kCurveSegmentMask | SkPath::kConic_SegmentMask)); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 4558 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 4559 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 4560 | p.reset(); |
bungeman@google.com | a5809a3 | 2013-06-21 15:13:34 +0000 | [diff] [blame] | 4561 | test_empty(reporter, p); |
reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 4562 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 4563 | p.addOval(bounds); |
| 4564 | check_convex_bounds(reporter, p, bounds); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 4565 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 4566 | |
bungeman@google.com | a5809a3 | 2013-06-21 15:13:34 +0000 | [diff] [blame] | 4567 | p.rewind(); |
| 4568 | test_empty(reporter, p); |
| 4569 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4570 | p.addRect(bounds); |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 4571 | check_convex_bounds(reporter, p, bounds); |
reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 4572 | // we have only lines |
| 4573 | REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == p.getSegmentMasks()); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 4574 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4575 | |
bungeman@google.com | a5809a3 | 2013-06-21 15:13:34 +0000 | [diff] [blame] | 4576 | REPORTER_ASSERT(reporter, p != empty); |
| 4577 | REPORTER_ASSERT(reporter, !(p == empty)); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4578 | |
bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 4579 | // do getPoints and getVerbs return the right result |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 4580 | REPORTER_ASSERT(reporter, p.getPoints(nullptr, 0) == 4); |
| 4581 | REPORTER_ASSERT(reporter, p.getVerbs(nullptr, 0) == 5); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4582 | SkPoint pts[4]; |
| 4583 | int count = p.getPoints(pts, 4); |
| 4584 | REPORTER_ASSERT(reporter, count == 4); |
bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 4585 | uint8_t verbs[6]; |
| 4586 | verbs[5] = 0xff; |
| 4587 | p.getVerbs(verbs, 5); |
| 4588 | REPORTER_ASSERT(reporter, SkPath::kMove_Verb == verbs[0]); |
| 4589 | REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[1]); |
| 4590 | REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[2]); |
| 4591 | REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[3]); |
| 4592 | REPORTER_ASSERT(reporter, SkPath::kClose_Verb == verbs[4]); |
| 4593 | REPORTER_ASSERT(reporter, 0xff == verbs[5]); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4594 | bounds2.set(pts, 4); |
| 4595 | REPORTER_ASSERT(reporter, bounds == bounds2); |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 4596 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4597 | bounds.offset(SK_Scalar1*3, SK_Scalar1*4); |
| 4598 | p.offset(SK_Scalar1*3, SK_Scalar1*4); |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 4599 | REPORTER_ASSERT(reporter, bounds == p.getBounds()); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4600 | |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 4601 | REPORTER_ASSERT(reporter, p.isRect(nullptr)); |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 4602 | bounds2.setEmpty(); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4603 | REPORTER_ASSERT(reporter, p.isRect(&bounds2)); |
| 4604 | REPORTER_ASSERT(reporter, bounds == bounds2); |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 4605 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4606 | // now force p to not be a rect |
| 4607 | bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2); |
| 4608 | p.addRect(bounds); |
halcanary | 96fcdcc | 2015-08-27 07:41:13 -0700 | [diff] [blame] | 4609 | REPORTER_ASSERT(reporter, !p.isRect(nullptr)); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4610 | |
robertphillips | fe7c427 | 2014-12-29 11:36:39 -0800 | [diff] [blame] | 4611 | // Test an edge case w.r.t. the bound returned by isRect (i.e., the |
| 4612 | // path has a trailing moveTo. Please see crbug.com\445368) |
| 4613 | { |
| 4614 | SkRect r; |
| 4615 | p.reset(); |
| 4616 | p.addRect(bounds); |
| 4617 | REPORTER_ASSERT(reporter, p.isRect(&r)); |
| 4618 | REPORTER_ASSERT(reporter, r == bounds); |
| 4619 | // add a moveTo outside of our bounds |
| 4620 | p.moveTo(bounds.fLeft + 10, bounds.fBottom + 10); |
| 4621 | REPORTER_ASSERT(reporter, p.isRect(&r)); |
| 4622 | REPORTER_ASSERT(reporter, r == bounds); |
| 4623 | } |
| 4624 | |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4625 | test_operatorEqual(reporter); |
reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 4626 | test_isLine(reporter); |
| 4627 | test_isRect(reporter); |
bsalomon | edc743a | 2016-06-01 09:42:31 -0700 | [diff] [blame] | 4628 | test_is_simple_closed_rect(reporter); |
caryclark | 95bc5f3 | 2015-04-08 08:34:15 -0700 | [diff] [blame] | 4629 | test_isNestedFillRects(reporter); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 4630 | test_zero_length_paths(reporter); |
reed@google.com | cabaf1d | 2012-01-11 21:03:05 +0000 | [diff] [blame] | 4631 | test_direction(reporter); |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 4632 | test_convexity(reporter); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 4633 | test_convexity2(reporter); |
bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 4634 | test_conservativelyContains(reporter); |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 4635 | test_close(reporter); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 4636 | test_segment_masks(reporter); |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 4637 | test_flattening(reporter); |
| 4638 | test_transform(reporter); |
reed@google.com | 3563c9e | 2011-11-14 19:34:57 +0000 | [diff] [blame] | 4639 | test_bounds(reporter); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 4640 | test_iter(reporter); |
| 4641 | test_raw_iter(reporter); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 4642 | test_circle(reporter); |
| 4643 | test_oval(reporter); |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 4644 | test_strokerec(reporter); |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 4645 | test_addPoly(reporter); |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 4646 | test_isfinite(reporter); |
tomhudson@google.com | ed02c4d | 2012-08-10 14:10:45 +0000 | [diff] [blame] | 4647 | test_isfinite_after_transform(reporter); |
fs | b1475b0 | 2016-01-20 09:51:07 -0800 | [diff] [blame] | 4648 | test_islastcontourclosed(reporter); |
robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 4649 | test_arb_round_rect_is_convex(reporter); |
robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 4650 | test_arb_zero_rad_round_rect_is_rect(reporter); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4651 | test_addrect(reporter); |
reed@google.com | a8790de | 2012-10-24 21:04:04 +0000 | [diff] [blame] | 4652 | test_addrect_isfinite(reporter); |
sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 4653 | test_tricky_cubic(); |
| 4654 | test_clipped_cubic(); |
| 4655 | test_crbug_170666(); |
caryclark | e8c5666 | 2015-07-14 11:19:26 -0700 | [diff] [blame] | 4656 | test_crbug_493450(reporter); |
| 4657 | test_crbug_495894(reporter); |
mbarbella | 99600d0 | 2016-06-01 15:39:47 -0700 | [diff] [blame] | 4658 | test_crbug_613918(); |
reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 4659 | test_bad_cubic_crbug229478(); |
reed@google.com | 3eff359 | 2013-05-08 21:08:21 +0000 | [diff] [blame] | 4660 | test_bad_cubic_crbug234190(); |
commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame] | 4661 | test_gen_id(reporter); |
commit-bot@chromium.org | 9d54aeb | 2013-08-09 19:48:26 +0000 | [diff] [blame] | 4662 | test_path_close_issue1474(reporter); |
reed@google.com | b58ba89 | 2013-10-15 15:44:35 +0000 | [diff] [blame] | 4663 | test_path_to_region(reporter); |
commit-bot@chromium.org | 42feaaf | 2013-11-08 15:51:12 +0000 | [diff] [blame] | 4664 | test_rrect(reporter); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4665 | test_arc(reporter); |
bsalomon | 1978ce2 | 2016-05-31 10:42:16 -0700 | [diff] [blame] | 4666 | test_arc_ovals(reporter); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4667 | test_arcTo(reporter); |
| 4668 | test_addPath(reporter); |
commit-bot@chromium.org | 14747e5 | 2014-02-11 21:16:29 +0000 | [diff] [blame] | 4669 | test_addPathMode(reporter, false, false); |
| 4670 | test_addPathMode(reporter, true, false); |
| 4671 | test_addPathMode(reporter, false, true); |
| 4672 | test_addPathMode(reporter, true, true); |
| 4673 | test_extendClosedPath(reporter); |
| 4674 | test_addEmptyPath(reporter, SkPath::kExtend_AddPathMode); |
| 4675 | test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode); |
commit-bot@chromium.org | a1a097e | 2013-11-14 16:53:22 +0000 | [diff] [blame] | 4676 | test_conicTo_special_case(reporter); |
| 4677 | test_get_point(reporter); |
| 4678 | test_contains(reporter); |
| 4679 | PathTest_Private::TestPathTo(reporter); |
robertphillips@google.com | 0efb21b | 2013-12-13 19:36:25 +0000 | [diff] [blame] | 4680 | PathRefTest_Private::TestPathRef(reporter); |
senorblanco | 84cd621 | 2015-08-04 10:01:58 -0700 | [diff] [blame] | 4681 | PathTest_Private::TestPathrefListeners(reporter); |
caryclark | 66a5d8b | 2014-06-24 08:30:15 -0700 | [diff] [blame] | 4682 | test_dump(reporter); |
caryclark | b421650 | 2015-03-02 13:02:34 -0800 | [diff] [blame] | 4683 | test_path_crbug389050(reporter); |
piotaixr | fac4e0e | 2014-08-26 11:59:04 -0700 | [diff] [blame] | 4684 | test_path_crbugskia2820(reporter); |
Yuqian Li | 9939bd6 | 2016-11-29 10:27:16 -0500 | [diff] [blame] | 4685 | test_path_crbugskia5995(); |
caryclark | 5ccef57 | 2015-03-02 10:07:56 -0800 | [diff] [blame] | 4686 | test_skbug_3469(reporter); |
reed | 5bcbe91 | 2014-12-15 12:28:33 -0800 | [diff] [blame] | 4687 | test_skbug_3239(reporter); |
reed | 91f283b | 2015-07-28 06:00:50 -0700 | [diff] [blame] | 4688 | test_bounds_crbug_513799(reporter); |
caryclark | 3cebe24 | 2016-08-23 09:41:00 -0700 | [diff] [blame] | 4689 | test_fuzz_crbug_638223(); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 4690 | } |
Mike Reed | 7717d4a | 2017-01-24 10:12:53 -0500 | [diff] [blame] | 4691 | |
| 4692 | DEF_TEST(conservatively_contains_rect, reporter) { |
| 4693 | SkPath path; |
| 4694 | |
| 4695 | path.moveTo(SkBits2Float(0x44000000), SkBits2Float(0x373938b8)); // 512, 1.10401e-05f |
| 4696 | // 1.4013e-45f, -9.22346e+18f, 3.58732e-43f, 0, 3.58732e-43f, 0 |
| 4697 | path.cubicTo(SkBits2Float(0x00000001), SkBits2Float(0xdf000052), |
| 4698 | SkBits2Float(0x00000100), SkBits2Float(0x00000000), |
| 4699 | SkBits2Float(0x00000100), SkBits2Float(0x00000000)); |
| 4700 | path.moveTo(0, 0); |
| 4701 | |
| 4702 | // this guy should not assert |
| 4703 | path.conservativelyContainsRect({ -211747, 12.1115f, -197893, 25.0321f }); |
| 4704 | } |
Mike Reed | 0d7dac8 | 2017-02-02 17:45:56 -0800 | [diff] [blame] | 4705 | |
| 4706 | /////////////////////////////////////////////////////////////////////////////////////////////////// |
| 4707 | |
| 4708 | static void rand_path(SkPath* path, SkRandom& rand, SkPath::Verb verb, int n) { |
| 4709 | for (int i = 0; i < n; ++i) { |
| 4710 | switch (verb) { |
| 4711 | case SkPath::kLine_Verb: |
| 4712 | path->lineTo(rand.nextF()*100, rand.nextF()*100); |
| 4713 | break; |
| 4714 | case SkPath::kQuad_Verb: |
| 4715 | path->quadTo(rand.nextF()*100, rand.nextF()*100, |
| 4716 | rand.nextF()*100, rand.nextF()*100); |
| 4717 | break; |
| 4718 | case SkPath::kConic_Verb: |
| 4719 | path->conicTo(rand.nextF()*100, rand.nextF()*100, |
| 4720 | rand.nextF()*100, rand.nextF()*100, rand.nextF()*10); |
| 4721 | break; |
| 4722 | case SkPath::kCubic_Verb: |
| 4723 | path->cubicTo(rand.nextF()*100, rand.nextF()*100, |
| 4724 | rand.nextF()*100, rand.nextF()*100, |
| 4725 | rand.nextF()*100, rand.nextF()*100); |
| 4726 | break; |
| 4727 | default: |
| 4728 | SkASSERT(false); |
| 4729 | } |
| 4730 | } |
| 4731 | } |
| 4732 | |
| 4733 | #include "SkPathOps.h" |
| 4734 | DEF_TEST(path_tight_bounds, reporter) { |
| 4735 | SkRandom rand; |
| 4736 | |
| 4737 | const SkPath::Verb verbs[] = { |
| 4738 | SkPath::kLine_Verb, SkPath::kQuad_Verb, SkPath::kConic_Verb, SkPath::kCubic_Verb, |
| 4739 | }; |
| 4740 | for (int i = 0; i < 1000; ++i) { |
| 4741 | for (int n = 1; n <= 10; n += 9) { |
| 4742 | for (SkPath::Verb verb : verbs) { |
| 4743 | SkPath path; |
| 4744 | rand_path(&path, rand, verb, n); |
| 4745 | SkRect bounds = path.getBounds(); |
Mike Reed | 8d3196b | 2017-02-03 11:34:13 -0500 | [diff] [blame] | 4746 | SkRect tight = path.computeTightBounds(); |
Mike Reed | 0d7dac8 | 2017-02-02 17:45:56 -0800 | [diff] [blame] | 4747 | REPORTER_ASSERT(reporter, bounds.contains(tight)); |
| 4748 | |
| 4749 | SkRect tight2; |
| 4750 | TightBounds(path, &tight2); |
| 4751 | REPORTER_ASSERT(reporter, nearly_equal(tight, tight2)); |
| 4752 | } |
| 4753 | } |
| 4754 | } |
| 4755 | } |
Cary Clark | e0b7287 | 2017-04-12 12:03:15 -0400 | [diff] [blame] | 4756 | |
| 4757 | DEF_TEST(skbug_6450, r) { |
| 4758 | SkRect ri = { 0.18554693f, 195.26283f, 0.185784385f, 752.644409f }; |
| 4759 | SkVector rdi[4] = { |
| 4760 | { 1.81159976e-09f, 7.58768801e-05f }, |
| 4761 | { 0.000118725002f, 0.000118725002f }, |
| 4762 | { 0.000118725002f, 0.000118725002f }, |
| 4763 | { 0.000118725002f, 0.486297607f } |
| 4764 | }; |
| 4765 | SkRRect irr; |
| 4766 | irr.setRectRadii(ri, rdi); |
| 4767 | SkRect ro = { 9.18354821e-39f, 2.1710848e+9f, 2.16945843e+9f, 3.47808128e+9f }; |
| 4768 | SkVector rdo[4] = { |
| 4769 | { 0, 0 }, |
| 4770 | { 0.0103298295f, 0.185887396f }, |
| 4771 | { 2.52999727e-29f, 169.001938f }, |
| 4772 | { 195.262741f, 195.161255f } |
| 4773 | }; |
| 4774 | SkRRect orr; |
| 4775 | orr.setRectRadii(ro, rdo); |
| 4776 | SkMakeNullCanvas()->drawDRRect(orr, irr, SkPaint()); |
| 4777 | } |