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