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