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