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