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