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