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