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