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