| 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@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 8 | #include "Test.h" |
| reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 9 | #include "SkCanvas.h" |
| reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 10 | #include "SkPaint.h" |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 11 | #include "SkPath.h" |
| reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 12 | #include "SkParse.h" |
| reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 13 | #include "SkParsePath.h" |
| reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 14 | #include "SkPathEffect.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" |
| reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 18 | #include "SkSurface.h" |
| mtklein@google.com | 9c9d4a7 | 2013-08-07 19:17:53 +0000 | [diff] [blame] | 19 | #include "SkTypes.h" |
| 20 | #include "SkWriter32.h" |
| reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 21 | |
| reed@google.com | cc8be77 | 2013-10-15 15:35:29 +0000 | [diff] [blame] | 22 | static void make_path0(SkPath* path) { |
| 23 | // from * https://code.google.com/p/skia/issues/detail?id=1706 |
| 24 | |
| 25 | path->moveTo(146.939f, 1012.84f); |
| 26 | path->lineTo(181.747f, 1009.18f); |
| 27 | path->lineTo(182.165f, 1013.16f); |
| 28 | path->lineTo(147.357f, 1016.82f); |
| 29 | path->lineTo(146.939f, 1012.84f); |
| 30 | path->close(); |
| 31 | } |
| 32 | |
| 33 | static void make_path1(SkPath* path) { |
| 34 | path->addRect(SkRect::MakeXYWH(10, 10, 10, 1)); |
| 35 | } |
| 36 | |
| 37 | typedef void (*PathProc)(SkPath*); |
| 38 | |
| 39 | /* |
| 40 | * Regression test: we used to crash (overwrite internal storage) during |
| 41 | * construction of the region when the path was INVERSE. That is now fixed, |
| 42 | * so test these regions (which used to assert/crash). |
| 43 | * |
| 44 | * https://code.google.com/p/skia/issues/detail?id=1706 |
| 45 | */ |
| 46 | static void test_path_to_region(skiatest::Reporter* reporter) { |
| 47 | PathProc procs[] = { |
| 48 | make_path0, |
| 49 | make_path1, |
| 50 | }; |
| skia.committer@gmail.com | 4726291 | 2013-10-16 07:02:24 +0000 | [diff] [blame] | 51 | |
| reed@google.com | cc8be77 | 2013-10-15 15:35:29 +0000 | [diff] [blame] | 52 | SkRegion clip; |
| 53 | clip.setRect(0, 0, 1255, 1925); |
| skia.committer@gmail.com | 4726291 | 2013-10-16 07:02:24 +0000 | [diff] [blame] | 54 | |
| reed@google.com | cc8be77 | 2013-10-15 15:35:29 +0000 | [diff] [blame] | 55 | for (size_t i = 0; i < SK_ARRAY_COUNT(procs); ++i) { |
| 56 | SkPath path; |
| 57 | procs[i](&path); |
| skia.committer@gmail.com | 4726291 | 2013-10-16 07:02:24 +0000 | [diff] [blame] | 58 | |
| reed@google.com | cc8be77 | 2013-10-15 15:35:29 +0000 | [diff] [blame] | 59 | SkRegion rgn; |
| 60 | rgn.setPath(path, clip); |
| 61 | path.toggleInverseFillType(); |
| 62 | rgn.setPath(path, clip); |
| 63 | } |
| 64 | } |
| 65 | |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 66 | #if defined(WIN32) |
| 67 | #define SUPPRESS_VISIBILITY_WARNING |
| 68 | #else |
| 69 | #define SUPPRESS_VISIBILITY_WARNING __attribute__((visibility("hidden"))) |
| 70 | #endif |
| 71 | |
| commit-bot@chromium.org | 9d54aeb | 2013-08-09 19:48:26 +0000 | [diff] [blame] | 72 | static void test_path_close_issue1474(skiatest::Reporter* reporter) { |
| 73 | // This test checks that r{Line,Quad,Conic,Cubic}To following a close() |
| 74 | // are relative to the point we close to, not relative to the point we close from. |
| 75 | SkPath path; |
| 76 | SkPoint last; |
| 77 | |
| 78 | // Test rLineTo(). |
| 79 | path.rLineTo(0, 100); |
| 80 | path.rLineTo(100, 0); |
| 81 | path.close(); // Returns us back to 0,0. |
| 82 | path.rLineTo(50, 50); // This should go to 50,50. |
| 83 | |
| 84 | path.getLastPt(&last); |
| 85 | REPORTER_ASSERT(reporter, 50 == last.fX); |
| 86 | REPORTER_ASSERT(reporter, 50 == last.fY); |
| 87 | |
| 88 | // Test rQuadTo(). |
| 89 | path.rewind(); |
| 90 | path.rLineTo(0, 100); |
| 91 | path.rLineTo(100, 0); |
| 92 | path.close(); |
| 93 | path.rQuadTo(50, 50, 75, 75); |
| 94 | |
| 95 | path.getLastPt(&last); |
| 96 | REPORTER_ASSERT(reporter, 75 == last.fX); |
| 97 | REPORTER_ASSERT(reporter, 75 == last.fY); |
| 98 | |
| 99 | // Test rConicTo(). |
| 100 | path.rewind(); |
| 101 | path.rLineTo(0, 100); |
| 102 | path.rLineTo(100, 0); |
| 103 | path.close(); |
| 104 | path.rConicTo(50, 50, 85, 85, 2); |
| 105 | |
| 106 | path.getLastPt(&last); |
| 107 | REPORTER_ASSERT(reporter, 85 == last.fX); |
| 108 | REPORTER_ASSERT(reporter, 85 == last.fY); |
| 109 | |
| 110 | // Test rCubicTo(). |
| 111 | path.rewind(); |
| 112 | path.rLineTo(0, 100); |
| 113 | path.rLineTo(100, 0); |
| 114 | path.close(); |
| 115 | path.rCubicTo(50, 50, 85, 85, 95, 95); |
| 116 | |
| 117 | path.getLastPt(&last); |
| 118 | REPORTER_ASSERT(reporter, 95 == last.fX); |
| 119 | REPORTER_ASSERT(reporter, 95 == last.fY); |
| 120 | } |
| 121 | |
| mtklein@google.com | 9c9d4a7 | 2013-08-07 19:17:53 +0000 | [diff] [blame] | 122 | static void test_android_specific_behavior(skiatest::Reporter* reporter) { |
| 123 | #ifdef SK_BUILD_FOR_ANDROID |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 124 | // Make sure we treat fGenerationID and fSourcePath correctly for each of |
| 125 | // copy, assign, rewind, reset, and swap. |
| 126 | SkPath original, source, anotherSource; |
| 127 | original.setSourcePath(&source); |
| mtklein@google.com | 9c9d4a7 | 2013-08-07 19:17:53 +0000 | [diff] [blame] | 128 | original.moveTo(0, 0); |
| 129 | original.lineTo(1, 1); |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 130 | REPORTER_ASSERT(reporter, original.getSourcePath() == &source); |
| mtklein@google.com | 9c9d4a7 | 2013-08-07 19:17:53 +0000 | [diff] [blame] | 131 | |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 132 | uint32_t copyID, assignID; |
| 133 | |
| 134 | // Test copy constructor. Copy generation ID, copy source path. |
| 135 | SkPath copy(original); |
| mtklein@google.com | 9c9d4a7 | 2013-08-07 19:17:53 +0000 | [diff] [blame] | 136 | REPORTER_ASSERT(reporter, copy.getGenerationID() == original.getGenerationID()); |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 137 | REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath()); |
| mtklein@google.com | 9c9d4a7 | 2013-08-07 19:17:53 +0000 | [diff] [blame] | 138 | |
| commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame^] | 139 | // Test assigment operator. Change generation ID, copy source path. |
| mtklein@google.com | 9c9d4a7 | 2013-08-07 19:17:53 +0000 | [diff] [blame] | 140 | SkPath assign; |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 141 | assignID = assign.getGenerationID(); |
| mtklein@google.com | 9c9d4a7 | 2013-08-07 19:17:53 +0000 | [diff] [blame] | 142 | assign = original; |
| commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame^] | 143 | REPORTER_ASSERT(reporter, assign.getGenerationID() != assignID); |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 144 | REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath()); |
| 145 | |
| commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame^] | 146 | // Test rewind. Change generation ID, don't touch source path. |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 147 | copyID = copy.getGenerationID(); |
| 148 | copy.rewind(); |
| commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame^] | 149 | REPORTER_ASSERT(reporter, copy.getGenerationID() != copyID); |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 150 | REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath()); |
| 151 | |
| commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame^] | 152 | // Test reset. Change generation ID, don't touch source path. |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 153 | assignID = assign.getGenerationID(); |
| 154 | assign.reset(); |
| commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame^] | 155 | REPORTER_ASSERT(reporter, assign.getGenerationID() != assignID); |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 156 | REPORTER_ASSERT(reporter, assign.getSourcePath() == original.getSourcePath()); |
| 157 | |
| commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame^] | 158 | // Test swap. Swap the generation IDs, swap source paths. |
| 159 | copy.reset(); |
| 160 | copy.moveTo(2, 2); |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 161 | copy.setSourcePath(&anotherSource); |
| 162 | copyID = copy.getGenerationID(); |
| commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame^] | 163 | assign.moveTo(3, 3); |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 164 | assignID = assign.getGenerationID(); |
| 165 | copy.swap(assign); |
| commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame^] | 166 | REPORTER_ASSERT(reporter, copy.getGenerationID() != copyID); |
| 167 | REPORTER_ASSERT(reporter, assign.getGenerationID() != assignID); |
| mtklein@google.com | cb8b0ee | 2013-08-15 21:14:51 +0000 | [diff] [blame] | 168 | REPORTER_ASSERT(reporter, copy.getSourcePath() == original.getSourcePath()); |
| 169 | REPORTER_ASSERT(reporter, assign.getSourcePath() == &anotherSource); |
| mtklein@google.com | 9c9d4a7 | 2013-08-07 19:17:53 +0000 | [diff] [blame] | 170 | #endif |
| 171 | } |
| 172 | |
| commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame^] | 173 | static void test_gen_id(skiatest::Reporter* reporter) { |
| 174 | SkPath a, b; |
| 175 | REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID()); |
| 176 | |
| 177 | a.moveTo(0, 0); |
| 178 | const uint32_t z = a.getGenerationID(); |
| 179 | REPORTER_ASSERT(reporter, z != b.getGenerationID()); |
| 180 | |
| 181 | a.reset(); |
| 182 | REPORTER_ASSERT(reporter, a.getGenerationID() == b.getGenerationID()); |
| 183 | |
| 184 | a.moveTo(1, 1); |
| 185 | const uint32_t y = a.getGenerationID(); |
| 186 | REPORTER_ASSERT(reporter, z != y); |
| 187 | |
| 188 | b.moveTo(2, 2); |
| 189 | const uint32_t x = b.getGenerationID(); |
| 190 | REPORTER_ASSERT(reporter, x != y && x != z); |
| 191 | |
| 192 | a.swap(b); |
| 193 | REPORTER_ASSERT(reporter, b.getGenerationID() == y && a.getGenerationID() == x); |
| 194 | |
| 195 | b = a; |
| 196 | REPORTER_ASSERT(reporter, b.getGenerationID() == x); |
| 197 | |
| 198 | SkPath c(a); |
| 199 | REPORTER_ASSERT(reporter, c.getGenerationID() == x); |
| 200 | |
| 201 | c.lineTo(3, 3); |
| 202 | const uint32_t w = c.getGenerationID(); |
| 203 | REPORTER_ASSERT(reporter, b.getGenerationID() == x); |
| 204 | REPORTER_ASSERT(reporter, a.getGenerationID() == x); |
| 205 | REPORTER_ASSERT(reporter, w != x); |
| 206 | |
| 207 | #ifdef SK_BUILD_FOR_ANDROID |
| 208 | static bool kExpectGenIDToIgnoreFill = false; |
| 209 | #else |
| 210 | static bool kExpectGenIDToIgnoreFill = true; |
| 211 | #endif |
| 212 | |
| 213 | c.toggleInverseFillType(); |
| 214 | const uint32_t v = c.getGenerationID(); |
| 215 | REPORTER_ASSERT(reporter, (v == w) == kExpectGenIDToIgnoreFill); |
| 216 | |
| 217 | c.rewind(); |
| 218 | REPORTER_ASSERT(reporter, v != c.getGenerationID()); |
| 219 | } |
| 220 | |
| reed@google.com | 3eff359 | 2013-05-08 21:08:21 +0000 | [diff] [blame] | 221 | // This used to assert in the debug build, as the edges did not all line-up. |
| 222 | static void test_bad_cubic_crbug234190() { |
| 223 | SkPath path; |
| 224 | path.moveTo(13.8509f, 3.16858f); |
| 225 | path.cubicTo(-2.35893e+08f, -4.21044e+08f, |
| 226 | -2.38991e+08f, -4.26573e+08f, |
| 227 | -2.41016e+08f, -4.30188e+08f); |
| 228 | |
| 229 | SkPaint paint; |
| 230 | paint.setAntiAlias(true); |
| reed@google.com | d28ba80 | 2013-09-20 19:33:52 +0000 | [diff] [blame] | 231 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(84, 88)); |
| reed@google.com | 3eff359 | 2013-05-08 21:08:21 +0000 | [diff] [blame] | 232 | surface->getCanvas()->drawPath(path, paint); |
| 233 | } |
| 234 | |
| reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 235 | static void test_bad_cubic_crbug229478() { |
| 236 | const SkPoint pts[] = { |
| skia.committer@gmail.com | 391ca66 | 2013-04-11 07:01:45 +0000 | [diff] [blame] | 237 | { 4595.91064f, -11596.9873f }, |
| 238 | { 4597.2168f, -11595.9414f }, |
| 239 | { 4598.52344f, -11594.8955f }, |
| 240 | { 4599.83008f, -11593.8496f }, |
| reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 241 | }; |
| skia.committer@gmail.com | 391ca66 | 2013-04-11 07:01:45 +0000 | [diff] [blame] | 242 | |
| reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 243 | SkPath path; |
| 244 | path.moveTo(pts[0]); |
| 245 | path.cubicTo(pts[1], pts[2], pts[3]); |
| skia.committer@gmail.com | 391ca66 | 2013-04-11 07:01:45 +0000 | [diff] [blame] | 246 | |
| reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 247 | SkPaint paint; |
| 248 | paint.setStyle(SkPaint::kStroke_Style); |
| 249 | paint.setStrokeWidth(20); |
| skia.committer@gmail.com | 391ca66 | 2013-04-11 07:01:45 +0000 | [diff] [blame] | 250 | |
| reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 251 | SkPath dst; |
| 252 | // Before the fix, this would infinite-recurse, and run out of stack |
| 253 | // because we would keep trying to subdivide a degenerate cubic segment. |
| 254 | paint.getFillPath(path, &dst, NULL); |
| 255 | } |
| 256 | |
| reed@google.com | 64d6295 | 2013-01-18 17:49:28 +0000 | [diff] [blame] | 257 | static void build_path_170666(SkPath& path) { |
| 258 | path.moveTo(17.9459f, 21.6344f); |
| 259 | path.lineTo(139.545f, -47.8105f); |
| 260 | path.lineTo(139.545f, -47.8105f); |
| 261 | path.lineTo(131.07f, -47.3888f); |
| 262 | path.lineTo(131.07f, -47.3888f); |
| 263 | path.lineTo(122.586f, -46.9532f); |
| 264 | path.lineTo(122.586f, -46.9532f); |
| 265 | path.lineTo(18076.6f, 31390.9f); |
| 266 | path.lineTo(18076.6f, 31390.9f); |
| 267 | path.lineTo(18085.1f, 31390.5f); |
| 268 | path.lineTo(18085.1f, 31390.5f); |
| 269 | path.lineTo(18076.6f, 31390.9f); |
| 270 | path.lineTo(18076.6f, 31390.9f); |
| 271 | path.lineTo(17955, 31460.3f); |
| 272 | path.lineTo(17955, 31460.3f); |
| 273 | path.lineTo(17963.5f, 31459.9f); |
| 274 | path.lineTo(17963.5f, 31459.9f); |
| 275 | path.lineTo(17971.9f, 31459.5f); |
| 276 | path.lineTo(17971.9f, 31459.5f); |
| 277 | path.lineTo(17.9551f, 21.6205f); |
| 278 | path.lineTo(17.9551f, 21.6205f); |
| 279 | path.lineTo(9.47091f, 22.0561f); |
| 280 | path.lineTo(9.47091f, 22.0561f); |
| 281 | path.lineTo(17.9459f, 21.6344f); |
| 282 | path.lineTo(17.9459f, 21.6344f); |
| 283 | path.close();path.moveTo(0.995934f, 22.4779f); |
| 284 | path.lineTo(0.986725f, 22.4918f); |
| 285 | path.lineTo(0.986725f, 22.4918f); |
| 286 | path.lineTo(17955, 31460.4f); |
| 287 | path.lineTo(17955, 31460.4f); |
| 288 | path.lineTo(17971.9f, 31459.5f); |
| 289 | path.lineTo(17971.9f, 31459.5f); |
| 290 | path.lineTo(18093.6f, 31390.1f); |
| 291 | path.lineTo(18093.6f, 31390.1f); |
| 292 | path.lineTo(18093.6f, 31390); |
| 293 | path.lineTo(18093.6f, 31390); |
| 294 | path.lineTo(139.555f, -47.8244f); |
| 295 | path.lineTo(139.555f, -47.8244f); |
| 296 | path.lineTo(122.595f, -46.9671f); |
| 297 | path.lineTo(122.595f, -46.9671f); |
| 298 | path.lineTo(0.995934f, 22.4779f); |
| 299 | path.lineTo(0.995934f, 22.4779f); |
| 300 | path.close(); |
| 301 | path.moveTo(5.43941f, 25.5223f); |
| 302 | path.lineTo(798267, -28871.1f); |
| 303 | path.lineTo(798267, -28871.1f); |
| 304 | path.lineTo(3.12512e+06f, -113102); |
| 305 | path.lineTo(3.12512e+06f, -113102); |
| 306 | path.cubicTo(5.16324e+06f, -186882, 8.15247e+06f, -295092, 1.1957e+07f, -432813); |
| 307 | path.cubicTo(1.95659e+07f, -708257, 3.04359e+07f, -1.10175e+06f, 4.34798e+07f, -1.57394e+06f); |
| 308 | path.cubicTo(6.95677e+07f, -2.51831e+06f, 1.04352e+08f, -3.77748e+06f, 1.39135e+08f, -5.03666e+06f); |
| 309 | path.cubicTo(1.73919e+08f, -6.29583e+06f, 2.08703e+08f, -7.555e+06f, 2.34791e+08f, -8.49938e+06f); |
| 310 | path.cubicTo(2.47835e+08f, -8.97157e+06f, 2.58705e+08f, -9.36506e+06f, 2.66314e+08f, -9.6405e+06f); |
| 311 | path.cubicTo(2.70118e+08f, -9.77823e+06f, 2.73108e+08f, -9.88644e+06f, 2.75146e+08f, -9.96022e+06f); |
| 312 | path.cubicTo(2.76165e+08f, -9.99711e+06f, 2.76946e+08f, -1.00254e+07f, 2.77473e+08f, -1.00444e+07f); |
| 313 | path.lineTo(2.78271e+08f, -1.00733e+07f); |
| 314 | path.lineTo(2.78271e+08f, -1.00733e+07f); |
| 315 | path.cubicTo(2.78271e+08f, -1.00733e+07f, 2.08703e+08f, -7.555e+06f, 135.238f, 23.3517f); |
| 316 | path.cubicTo(131.191f, 23.4981f, 125.995f, 23.7976f, 123.631f, 24.0206f); |
| 317 | path.cubicTo(121.267f, 24.2436f, 122.631f, 24.3056f, 126.677f, 24.1591f); |
| 318 | path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f); |
| 319 | path.lineTo(2.77473e+08f, -1.00444e+07f); |
| 320 | path.lineTo(2.77473e+08f, -1.00444e+07f); |
| 321 | path.cubicTo(2.76946e+08f, -1.00254e+07f, 2.76165e+08f, -9.99711e+06f, 2.75146e+08f, -9.96022e+06f); |
| 322 | path.cubicTo(2.73108e+08f, -9.88644e+06f, 2.70118e+08f, -9.77823e+06f, 2.66314e+08f, -9.6405e+06f); |
| 323 | path.cubicTo(2.58705e+08f, -9.36506e+06f, 2.47835e+08f, -8.97157e+06f, 2.34791e+08f, -8.49938e+06f); |
| 324 | path.cubicTo(2.08703e+08f, -7.555e+06f, 1.73919e+08f, -6.29583e+06f, 1.39135e+08f, -5.03666e+06f); |
| 325 | path.cubicTo(1.04352e+08f, -3.77749e+06f, 6.95677e+07f, -2.51831e+06f, 4.34798e+07f, -1.57394e+06f); |
| 326 | path.cubicTo(3.04359e+07f, -1.10175e+06f, 1.95659e+07f, -708258, 1.1957e+07f, -432814); |
| 327 | path.cubicTo(8.15248e+06f, -295092, 5.16324e+06f, -186883, 3.12513e+06f, -113103); |
| 328 | path.lineTo(798284, -28872); |
| 329 | path.lineTo(798284, -28872); |
| 330 | path.lineTo(22.4044f, 24.6677f); |
| 331 | path.lineTo(22.4044f, 24.6677f); |
| 332 | path.cubicTo(22.5186f, 24.5432f, 18.8134f, 24.6337f, 14.1287f, 24.8697f); |
| 333 | path.cubicTo(9.4439f, 25.1057f, 5.55359f, 25.3978f, 5.43941f, 25.5223f); |
| 334 | path.close(); |
| 335 | } |
| 336 | |
| 337 | static void build_path_simple_170666(SkPath& path) { |
| 338 | path.moveTo(126.677f, 24.1591f); |
| 339 | path.cubicTo(2.08703e+08f, -7.555e+06f, 2.78271e+08f, -1.00733e+07f, 2.78271e+08f, -1.00733e+07f); |
| 340 | } |
| 341 | |
| 342 | // This used to assert in the SK_DEBUG build, as the clip step would fail with |
| 343 | // too-few interations in our cubic-line intersection code. That code now runs |
| 344 | // 24 interations (instead of 16). |
| sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 345 | static void test_crbug_170666() { |
| reed@google.com | 64d6295 | 2013-01-18 17:49:28 +0000 | [diff] [blame] | 346 | SkPath path; |
| 347 | SkPaint paint; |
| 348 | paint.setAntiAlias(true); |
| 349 | |
| reed@google.com | d28ba80 | 2013-09-20 19:33:52 +0000 | [diff] [blame] | 350 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(1000, 1000)); |
| skia.committer@gmail.com | 36df7ed | 2013-01-19 07:05:38 +0000 | [diff] [blame] | 351 | |
| reed@google.com | 64d6295 | 2013-01-18 17:49:28 +0000 | [diff] [blame] | 352 | build_path_simple_170666(path); |
| 353 | surface->getCanvas()->drawPath(path, paint); |
| skia.committer@gmail.com | 36df7ed | 2013-01-19 07:05:38 +0000 | [diff] [blame] | 354 | |
| reed@google.com | 64d6295 | 2013-01-18 17:49:28 +0000 | [diff] [blame] | 355 | build_path_170666(path); |
| 356 | surface->getCanvas()->drawPath(path, paint); |
| 357 | } |
| 358 | |
| reed@google.com | a8790de | 2012-10-24 21:04:04 +0000 | [diff] [blame] | 359 | // Make sure we stay non-finite once we get there (unless we reset or rewind). |
| 360 | static void test_addrect_isfinite(skiatest::Reporter* reporter) { |
| 361 | SkPath path; |
| skia.committer@gmail.com | 8b0e234 | 2012-10-25 02:01:20 +0000 | [diff] [blame] | 362 | |
| reed@google.com | a8790de | 2012-10-24 21:04:04 +0000 | [diff] [blame] | 363 | path.addRect(SkRect::MakeWH(50, 100)); |
| 364 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 365 | |
| 366 | path.moveTo(0, 0); |
| 367 | path.lineTo(SK_ScalarInfinity, 42); |
| 368 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 369 | |
| 370 | path.addRect(SkRect::MakeWH(50, 100)); |
| 371 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 372 | |
| 373 | path.reset(); |
| 374 | REPORTER_ASSERT(reporter, path.isFinite()); |
| skia.committer@gmail.com | 8b0e234 | 2012-10-25 02:01:20 +0000 | [diff] [blame] | 375 | |
| reed@google.com | a8790de | 2012-10-24 21:04:04 +0000 | [diff] [blame] | 376 | path.addRect(SkRect::MakeWH(50, 100)); |
| 377 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 378 | } |
| 379 | |
| reed@google.com | 848148e | 2013-01-15 15:51:59 +0000 | [diff] [blame] | 380 | static void build_big_path(SkPath* path, bool reducedCase) { |
| 381 | if (reducedCase) { |
| 382 | path->moveTo(577330, 1971.72f); |
| 383 | path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f); |
| 384 | } else { |
| 385 | path->moveTo(60.1631f, 7.70567f); |
| 386 | path->quadTo(60.1631f, 7.70567f, 0.99474f, 0.901199f); |
| 387 | path->lineTo(577379, 1977.77f); |
| 388 | path->quadTo(577364, 1979.57f, 577325, 1980.26f); |
| 389 | path->quadTo(577286, 1980.95f, 577245, 1980.13f); |
| 390 | path->quadTo(577205, 1979.3f, 577187, 1977.45f); |
| 391 | path->quadTo(577168, 1975.6f, 577183, 1973.8f); |
| 392 | path->quadTo(577198, 1972, 577238, 1971.31f); |
| 393 | path->quadTo(577277, 1970.62f, 577317, 1971.45f); |
| 394 | path->quadTo(577330, 1971.72f, 577341, 1972.11f); |
| 395 | path->cubicTo(10.7082f, -116.596f, 262.057f, 45.6468f, 294.694f, 1.96237f); |
| 396 | path->moveTo(306.718f, -32.912f); |
| 397 | path->cubicTo(30.531f, 10.0005f, 1502.47f, 13.2804f, 84.3088f, 9.99601f); |
| 398 | } |
| 399 | } |
| 400 | |
| sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 401 | static void test_clipped_cubic() { |
| reed@google.com | d28ba80 | 2013-09-20 19:33:52 +0000 | [diff] [blame] | 402 | SkAutoTUnref<SkSurface> surface(SkSurface::NewRasterPMColor(640, 480)); |
| reed@google.com | 848148e | 2013-01-15 15:51:59 +0000 | [diff] [blame] | 403 | |
| 404 | // This path used to assert, because our cubic-chopping code incorrectly |
| 405 | // moved control points after the chop. This test should be run in SK_DEBUG |
| 406 | // mode to ensure that we no long assert. |
| 407 | SkPath path; |
| 408 | for (int doReducedCase = 0; doReducedCase <= 1; ++doReducedCase) { |
| 409 | build_big_path(&path, SkToBool(doReducedCase)); |
| skia.committer@gmail.com | ff21c2e | 2013-01-16 07:05:56 +0000 | [diff] [blame] | 410 | |
| reed@google.com | 848148e | 2013-01-15 15:51:59 +0000 | [diff] [blame] | 411 | SkPaint paint; |
| 412 | for (int doAA = 0; doAA <= 1; ++doAA) { |
| 413 | paint.setAntiAlias(SkToBool(doAA)); |
| 414 | surface->getCanvas()->drawPath(path, paint); |
| 415 | } |
| 416 | } |
| 417 | } |
| 418 | |
| reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 419 | // Inspired by http://ie.microsoft.com/testdrive/Performance/Chalkboard/ |
| 420 | // which triggered an assert, from a tricky cubic. This test replicates that |
| 421 | // example, so we can ensure that we handle it (in SkEdge.cpp), and don't |
| 422 | // assert in the SK_DEBUG build. |
| sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 423 | static void test_tricky_cubic() { |
| reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 424 | const SkPoint pts[] = { |
| skia.committer@gmail.com | 055c7c2 | 2012-09-15 02:01:41 +0000 | [diff] [blame] | 425 | { SkDoubleToScalar(18.8943768), SkDoubleToScalar(129.121277) }, |
| 426 | { SkDoubleToScalar(18.8937435), SkDoubleToScalar(129.121689) }, |
| 427 | { SkDoubleToScalar(18.8950119), SkDoubleToScalar(129.120422) }, |
| 428 | { SkDoubleToScalar(18.5030727), SkDoubleToScalar(129.13121) }, |
| reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 429 | }; |
| 430 | |
| 431 | SkPath path; |
| 432 | path.moveTo(pts[0]); |
| 433 | path.cubicTo(pts[1], pts[2], pts[3]); |
| 434 | |
| 435 | SkPaint paint; |
| 436 | paint.setAntiAlias(true); |
| 437 | |
| reed@google.com | d28ba80 | 2013-09-20 19:33:52 +0000 | [diff] [blame] | 438 | SkSurface* surface = SkSurface::NewRasterPMColor(19, 130); |
| reed@google.com | 8cae835 | 2012-09-14 15:18:41 +0000 | [diff] [blame] | 439 | surface->getCanvas()->drawPath(path, paint); |
| 440 | surface->unref(); |
| 441 | } |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 442 | |
| tomhudson@google.com | ed02c4d | 2012-08-10 14:10:45 +0000 | [diff] [blame] | 443 | // Inspired by http://code.google.com/p/chromium/issues/detail?id=141651 |
| 444 | // |
| 445 | static void test_isfinite_after_transform(skiatest::Reporter* reporter) { |
| 446 | SkPath path; |
| 447 | path.quadTo(157, 366, 286, 208); |
| 448 | path.arcTo(37, 442, 315, 163, 957494590897113.0f); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 449 | |
| tomhudson@google.com | ed02c4d | 2012-08-10 14:10:45 +0000 | [diff] [blame] | 450 | SkMatrix matrix; |
| 451 | matrix.setScale(1000*1000, 1000*1000); |
| 452 | |
| 453 | // Be sure that path::transform correctly updates isFinite and the bounds |
| 454 | // if the transformation overflows. The previous bug was that isFinite was |
| 455 | // set to true in this case, but the bounds were not set to empty (which |
| 456 | // they should be). |
| 457 | while (path.isFinite()) { |
| 458 | REPORTER_ASSERT(reporter, path.getBounds().isFinite()); |
| 459 | REPORTER_ASSERT(reporter, !path.getBounds().isEmpty()); |
| 460 | path.transform(matrix); |
| 461 | } |
| 462 | REPORTER_ASSERT(reporter, path.getBounds().isEmpty()); |
| 463 | |
| 464 | matrix.setTranslate(SK_Scalar1, SK_Scalar1); |
| 465 | path.transform(matrix); |
| 466 | // we need to still be non-finite |
| 467 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 468 | REPORTER_ASSERT(reporter, path.getBounds().isEmpty()); |
| 469 | } |
| 470 | |
| skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 471 | static void add_corner_arc(SkPath* path, const SkRect& rect, |
| 472 | SkScalar xIn, SkScalar yIn, |
| robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 473 | int startAngle) |
| 474 | { |
| 475 | |
| 476 | SkScalar rx = SkMinScalar(rect.width(), xIn); |
| 477 | SkScalar ry = SkMinScalar(rect.height(), yIn); |
| 478 | |
| 479 | SkRect arcRect; |
| 480 | arcRect.set(-rx, -ry, rx, ry); |
| 481 | switch (startAngle) { |
| 482 | case 0: |
| 483 | arcRect.offset(rect.fRight - arcRect.fRight, rect.fBottom - arcRect.fBottom); |
| 484 | break; |
| 485 | case 90: |
| 486 | arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fBottom - arcRect.fBottom); |
| 487 | break; |
| 488 | case 180: |
| 489 | arcRect.offset(rect.fLeft - arcRect.fLeft, rect.fTop - arcRect.fTop); |
| 490 | break; |
| 491 | case 270: |
| 492 | arcRect.offset(rect.fRight - arcRect.fRight, rect.fTop - arcRect.fTop); |
| 493 | break; |
| 494 | default: |
| 495 | break; |
| 496 | } |
| 497 | |
| 498 | path->arcTo(arcRect, SkIntToScalar(startAngle), SkIntToScalar(90), false); |
| 499 | } |
| 500 | |
| skia.committer@gmail.com | 6a748ad | 2012-10-19 02:01:19 +0000 | [diff] [blame] | 501 | static void make_arb_round_rect(SkPath* path, const SkRect& r, |
| robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 502 | SkScalar xCorner, SkScalar yCorner) { |
| 503 | // we are lazy here and use the same x & y for each corner |
| 504 | add_corner_arc(path, r, xCorner, yCorner, 270); |
| 505 | add_corner_arc(path, r, xCorner, yCorner, 0); |
| 506 | add_corner_arc(path, r, xCorner, yCorner, 90); |
| 507 | add_corner_arc(path, r, xCorner, yCorner, 180); |
| robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 508 | path->close(); |
| robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | // Chrome creates its own round rects with each corner possibly being different. |
| 512 | // Performance will suffer if they are not convex. |
| 513 | // Note: PathBench::ArbRoundRectBench performs almost exactly |
| 514 | // the same test (but with drawing) |
| 515 | 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] | 516 | SkRandom rand; |
| robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 517 | SkRect r; |
| 518 | |
| 519 | for (int i = 0; i < 5000; ++i) { |
| 520 | |
| robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 521 | SkScalar size = rand.nextUScalar1() * 30; |
| 522 | if (size < SK_Scalar1) { |
| robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 523 | continue; |
| 524 | } |
| 525 | r.fLeft = rand.nextUScalar1() * 300; |
| 526 | r.fTop = rand.nextUScalar1() * 300; |
| robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 527 | r.fRight = r.fLeft + 2 * size; |
| 528 | r.fBottom = r.fTop + 2 * size; |
| robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 529 | |
| 530 | SkPath temp; |
| 531 | |
| 532 | make_arb_round_rect(&temp, r, r.width() / 10, r.height() / 15); |
| 533 | |
| 534 | REPORTER_ASSERT(reporter, temp.isConvex()); |
| 535 | } |
| 536 | } |
| 537 | |
| robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 538 | // Chrome will sometimes create a 0 radius round rect. The degenerate |
| 539 | // quads prevent the path from being converted to a rect |
| 540 | // Note: PathBench::ArbRoundRectBench performs almost exactly |
| 541 | // the same test (but with drawing) |
| 542 | 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] | 543 | SkRandom rand; |
| robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 544 | SkRect r; |
| 545 | |
| 546 | for (int i = 0; i < 5000; ++i) { |
| 547 | |
| 548 | SkScalar size = rand.nextUScalar1() * 30; |
| 549 | if (size < SK_Scalar1) { |
| 550 | continue; |
| 551 | } |
| 552 | r.fLeft = rand.nextUScalar1() * 300; |
| 553 | r.fTop = rand.nextUScalar1() * 300; |
| 554 | r.fRight = r.fLeft + 2 * size; |
| 555 | r.fBottom = r.fTop + 2 * size; |
| 556 | |
| 557 | SkPath temp; |
| 558 | |
| 559 | make_arb_round_rect(&temp, r, 0, 0); |
| 560 | |
| robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 561 | SkRect result; |
| 562 | REPORTER_ASSERT(reporter, temp.isRect(&result)); |
| 563 | REPORTER_ASSERT(reporter, r == result); |
| robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 564 | } |
| 565 | } |
| 566 | |
| reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 567 | static void test_rect_isfinite(skiatest::Reporter* reporter) { |
| 568 | const SkScalar inf = SK_ScalarInfinity; |
| caryclark@google.com | 7abfa49 | 2013-04-12 11:59:41 +0000 | [diff] [blame] | 569 | const SkScalar negInf = SK_ScalarNegativeInfinity; |
| reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 570 | const SkScalar nan = SK_ScalarNaN; |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 571 | |
| reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 572 | SkRect r; |
| 573 | r.setEmpty(); |
| 574 | REPORTER_ASSERT(reporter, r.isFinite()); |
| caryclark@google.com | 7abfa49 | 2013-04-12 11:59:41 +0000 | [diff] [blame] | 575 | r.set(0, 0, inf, negInf); |
| reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 576 | REPORTER_ASSERT(reporter, !r.isFinite()); |
| 577 | r.set(0, 0, nan, 0); |
| 578 | REPORTER_ASSERT(reporter, !r.isFinite()); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 579 | |
| reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 580 | SkPoint pts[] = { |
| 581 | { 0, 0 }, |
| 582 | { SK_Scalar1, 0 }, |
| 583 | { 0, SK_Scalar1 }, |
| 584 | }; |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 585 | |
| reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 586 | bool isFine = r.setBoundsCheck(pts, 3); |
| 587 | REPORTER_ASSERT(reporter, isFine); |
| 588 | REPORTER_ASSERT(reporter, !r.isEmpty()); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 589 | |
| reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 590 | pts[1].set(inf, 0); |
| 591 | isFine = r.setBoundsCheck(pts, 3); |
| 592 | REPORTER_ASSERT(reporter, !isFine); |
| 593 | REPORTER_ASSERT(reporter, r.isEmpty()); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 594 | |
| reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 595 | pts[1].set(nan, 0); |
| 596 | isFine = r.setBoundsCheck(pts, 3); |
| 597 | REPORTER_ASSERT(reporter, !isFine); |
| 598 | REPORTER_ASSERT(reporter, r.isEmpty()); |
| 599 | } |
| 600 | |
| 601 | static void test_path_isfinite(skiatest::Reporter* reporter) { |
| 602 | const SkScalar inf = SK_ScalarInfinity; |
| bsalomon@google.com | 50c79d8 | 2013-01-08 20:31:53 +0000 | [diff] [blame] | 603 | const SkScalar negInf = SK_ScalarNegativeInfinity; |
| reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 604 | const SkScalar nan = SK_ScalarNaN; |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 605 | |
| reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 606 | SkPath path; |
| 607 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 608 | |
| 609 | path.reset(); |
| 610 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 611 | |
| 612 | path.reset(); |
| 613 | path.moveTo(SK_Scalar1, 0); |
| 614 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 615 | |
| 616 | path.reset(); |
| bsalomon@google.com | 50c79d8 | 2013-01-08 20:31:53 +0000 | [diff] [blame] | 617 | path.moveTo(inf, negInf); |
| reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 618 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 619 | |
| 620 | path.reset(); |
| 621 | path.moveTo(nan, 0); |
| 622 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 623 | } |
| 624 | |
| 625 | static void test_isfinite(skiatest::Reporter* reporter) { |
| 626 | test_rect_isfinite(reporter); |
| 627 | test_path_isfinite(reporter); |
| 628 | } |
| 629 | |
| reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 630 | // assert that we always |
| 631 | // start with a moveTo |
| 632 | // only have 1 moveTo |
| 633 | // only have Lines after that |
| 634 | // end with a single close |
| 635 | // only have (at most) 1 close |
| 636 | // |
| 637 | static void test_poly(skiatest::Reporter* reporter, const SkPath& path, |
| sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 638 | const SkPoint srcPts[], bool expectClose) { |
| reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 639 | SkPath::RawIter iter(path); |
| 640 | SkPoint pts[4]; |
| reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 641 | |
| 642 | bool firstTime = true; |
| 643 | bool foundClose = false; |
| 644 | for (;;) { |
| 645 | switch (iter.next(pts)) { |
| 646 | case SkPath::kMove_Verb: |
| 647 | REPORTER_ASSERT(reporter, firstTime); |
| 648 | REPORTER_ASSERT(reporter, pts[0] == srcPts[0]); |
| 649 | srcPts++; |
| 650 | firstTime = false; |
| 651 | break; |
| 652 | case SkPath::kLine_Verb: |
| 653 | REPORTER_ASSERT(reporter, !firstTime); |
| 654 | REPORTER_ASSERT(reporter, pts[1] == srcPts[0]); |
| 655 | srcPts++; |
| 656 | break; |
| 657 | case SkPath::kQuad_Verb: |
| mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 658 | REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected quad verb"); |
| reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 659 | break; |
| reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 660 | case SkPath::kConic_Verb: |
| mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 661 | REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected conic verb"); |
| reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 662 | break; |
| reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 663 | case SkPath::kCubic_Verb: |
| mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 664 | REPORTER_ASSERT_MESSAGE(reporter, false, "unexpected cubic verb"); |
| reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 665 | break; |
| 666 | case SkPath::kClose_Verb: |
| 667 | REPORTER_ASSERT(reporter, !firstTime); |
| 668 | REPORTER_ASSERT(reporter, !foundClose); |
| 669 | REPORTER_ASSERT(reporter, expectClose); |
| 670 | foundClose = true; |
| 671 | break; |
| 672 | case SkPath::kDone_Verb: |
| 673 | goto DONE; |
| 674 | } |
| 675 | } |
| 676 | DONE: |
| 677 | REPORTER_ASSERT(reporter, foundClose == expectClose); |
| 678 | } |
| 679 | |
| 680 | static void test_addPoly(skiatest::Reporter* reporter) { |
| 681 | SkPoint pts[32]; |
| commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 682 | SkRandom rand; |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 683 | |
| reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 684 | for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) { |
| 685 | pts[i].fX = rand.nextSScalar1(); |
| 686 | pts[i].fY = rand.nextSScalar1(); |
| 687 | } |
| 688 | |
| 689 | for (int doClose = 0; doClose <= 1; ++doClose) { |
| 690 | for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) { |
| 691 | SkPath path; |
| 692 | path.addPoly(pts, count, SkToBool(doClose)); |
| sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 693 | test_poly(reporter, path, pts, SkToBool(doClose)); |
| reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 694 | } |
| 695 | } |
| 696 | } |
| 697 | |
| reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 698 | static void test_strokerec(skiatest::Reporter* reporter) { |
| 699 | SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); |
| 700 | REPORTER_ASSERT(reporter, rec.isFillStyle()); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 701 | |
| reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 702 | rec.setHairlineStyle(); |
| 703 | REPORTER_ASSERT(reporter, rec.isHairlineStyle()); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 704 | |
| reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 705 | rec.setStrokeStyle(SK_Scalar1, false); |
| 706 | REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle()); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 707 | |
| reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 708 | rec.setStrokeStyle(SK_Scalar1, true); |
| 709 | REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle()); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 710 | |
| reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 711 | rec.setStrokeStyle(0, false); |
| 712 | REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle()); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 713 | |
| reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 714 | rec.setStrokeStyle(0, true); |
| 715 | REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle()); |
| 716 | } |
| 717 | |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 718 | // Set this for paths that don't have a consistent direction such as a bowtie. |
| 719 | // (cheapComputeDirection is not expected to catch these.) |
| 720 | static const SkPath::Direction kDontCheckDir = static_cast<SkPath::Direction>(-1); |
| 721 | |
| 722 | static void check_direction(skiatest::Reporter* reporter, const SkPath& path, |
| 723 | SkPath::Direction expected) { |
| 724 | if (expected == kDontCheckDir) { |
| 725 | return; |
| bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 726 | } |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 727 | SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path. |
| 728 | |
| 729 | SkPath::Direction dir; |
| 730 | if (copy.cheapComputeDirection(&dir)) { |
| 731 | REPORTER_ASSERT(reporter, dir == expected); |
| 732 | } else { |
| 733 | REPORTER_ASSERT(reporter, SkPath::kUnknown_Direction == expected); |
| 734 | } |
| bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 735 | } |
| 736 | |
| reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 737 | static void test_direction(skiatest::Reporter* reporter) { |
| 738 | size_t i; |
| 739 | SkPath path; |
| 740 | REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL)); |
| 741 | REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCW_Direction)); |
| 742 | REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCCW_Direction)); |
| reed@google.com | a8a3b3d | 2012-11-26 18:16:27 +0000 | [diff] [blame] | 743 | REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kUnknown_Direction)); |
| reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 744 | |
| 745 | static const char* gDegen[] = { |
| 746 | "M 10 10", |
| 747 | "M 10 10 M 20 20", |
| 748 | "M 10 10 L 20 20", |
| 749 | "M 10 10 L 10 10 L 10 10", |
| 750 | "M 10 10 Q 10 10 10 10", |
| 751 | "M 10 10 C 10 10 10 10 10 10", |
| 752 | }; |
| 753 | for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) { |
| 754 | path.reset(); |
| 755 | bool valid = SkParsePath::FromSVGString(gDegen[i], &path); |
| 756 | REPORTER_ASSERT(reporter, valid); |
| 757 | REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL)); |
| 758 | } |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 759 | |
| reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 760 | static const char* gCW[] = { |
| reed@google.com | cabaf1d | 2012-01-11 21:03:05 +0000 | [diff] [blame] | 761 | "M 10 10 L 10 10 Q 20 10 20 20", |
| reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 762 | "M 10 10 C 20 10 20 20 20 20", |
| reed@google.com | d414666 | 2012-01-31 15:42:29 +0000 | [diff] [blame] | 763 | "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] | 764 | // rect with top two corners replaced by cubics with identical middle |
| 765 | // control points |
| reed@google.com | 20fb0c7 | 2012-11-13 13:47:39 +0000 | [diff] [blame] | 766 | "M 10 10 C 10 0 10 0 20 0 L 40 0 C 50 0 50 0 50 10", |
| 767 | "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] | 768 | }; |
| 769 | for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) { |
| 770 | path.reset(); |
| 771 | bool valid = SkParsePath::FromSVGString(gCW[i], &path); |
| 772 | REPORTER_ASSERT(reporter, valid); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 773 | check_direction(reporter, path, SkPath::kCW_Direction); |
| reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 774 | } |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 775 | |
| reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 776 | static const char* gCCW[] = { |
| reed@google.com | cabaf1d | 2012-01-11 21:03:05 +0000 | [diff] [blame] | 777 | "M 10 10 L 10 10 Q 20 10 20 -20", |
| reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 778 | "M 10 10 C 20 10 20 -20 20 -20", |
| reed@google.com | d414666 | 2012-01-31 15:42:29 +0000 | [diff] [blame] | 779 | "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] | 780 | // rect with top two corners replaced by cubics with identical middle |
| 781 | // control points |
| reed@google.com | 20fb0c7 | 2012-11-13 13:47:39 +0000 | [diff] [blame] | 782 | "M 50 10 C 50 0 50 0 40 0 L 20 0 C 10 0 10 0 10 10", |
| 783 | "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] | 784 | }; |
| 785 | for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) { |
| 786 | path.reset(); |
| 787 | bool valid = SkParsePath::FromSVGString(gCCW[i], &path); |
| 788 | REPORTER_ASSERT(reporter, valid); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 789 | check_direction(reporter, path, SkPath::kCCW_Direction); |
| reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 790 | } |
| reed@google.com | ac8543f | 2012-01-30 20:51:25 +0000 | [diff] [blame] | 791 | |
| 792 | // Test two donuts, each wound a different direction. Only the outer contour |
| 793 | // determines the cheap direction |
| 794 | path.reset(); |
| 795 | path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCW_Direction); |
| 796 | path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCCW_Direction); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 797 | check_direction(reporter, path, SkPath::kCW_Direction); |
| bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 798 | |
| reed@google.com | ac8543f | 2012-01-30 20:51:25 +0000 | [diff] [blame] | 799 | path.reset(); |
| 800 | path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCW_Direction); |
| 801 | path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 802 | check_direction(reporter, path, SkPath::kCCW_Direction); |
| bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 803 | |
| bsalomon@google.com | 6843ac4 | 2012-02-17 13:49:03 +0000 | [diff] [blame] | 804 | #ifdef SK_SCALAR_IS_FLOAT |
| bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 805 | // triangle with one point really far from the origin. |
| 806 | path.reset(); |
| 807 | // the first point is roughly 1.05e10, 1.05e10 |
| bsalomon@google.com | 53aab78 | 2012-02-23 14:54:49 +0000 | [diff] [blame] | 808 | path.moveTo(SkFloatToScalar(SkBits2Float(0x501c7652)), SkFloatToScalar(SkBits2Float(0x501c7652))); |
| 809 | path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1); |
| 810 | path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 811 | check_direction(reporter, path, SkPath::kCCW_Direction); |
| bsalomon@google.com | 53aab78 | 2012-02-23 14:54:49 +0000 | [diff] [blame] | 812 | #endif |
| reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 813 | } |
| 814 | |
| reed@google.com | ffdb018 | 2011-11-14 19:29:14 +0000 | [diff] [blame] | 815 | static void add_rect(SkPath* path, const SkRect& r) { |
| 816 | path->moveTo(r.fLeft, r.fTop); |
| 817 | path->lineTo(r.fRight, r.fTop); |
| 818 | path->lineTo(r.fRight, r.fBottom); |
| 819 | path->lineTo(r.fLeft, r.fBottom); |
| 820 | path->close(); |
| 821 | } |
| 822 | |
| 823 | static void test_bounds(skiatest::Reporter* reporter) { |
| 824 | static const SkRect rects[] = { |
| reed@google.com | 3563c9e | 2011-11-14 19:34:57 +0000 | [diff] [blame] | 825 | { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) }, |
| 826 | { SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) }, |
| 827 | { SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) }, |
| 828 | { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) }, |
| reed@google.com | ffdb018 | 2011-11-14 19:29:14 +0000 | [diff] [blame] | 829 | }; |
| 830 | |
| 831 | SkPath path0, path1; |
| 832 | for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) { |
| 833 | path0.addRect(rects[i]); |
| 834 | add_rect(&path1, rects[i]); |
| 835 | } |
| 836 | |
| 837 | REPORTER_ASSERT(reporter, path0.getBounds() == path1.getBounds()); |
| 838 | } |
| 839 | |
| reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 840 | static void stroke_cubic(const SkPoint pts[4]) { |
| 841 | SkPath path; |
| 842 | path.moveTo(pts[0]); |
| 843 | path.cubicTo(pts[1], pts[2], pts[3]); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 844 | |
| reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 845 | SkPaint paint; |
| 846 | paint.setStyle(SkPaint::kStroke_Style); |
| 847 | paint.setStrokeWidth(SK_Scalar1 * 2); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 848 | |
| reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 849 | SkPath fill; |
| 850 | paint.getFillPath(path, &fill); |
| 851 | } |
| 852 | |
| 853 | // just ensure this can run w/o any SkASSERTS firing in the debug build |
| 854 | // we used to assert due to differences in how we determine a degenerate vector |
| 855 | // but that was fixed with the introduction of SkPoint::CanNormalize |
| 856 | static void stroke_tiny_cubic() { |
| 857 | SkPoint p0[] = { |
| 858 | { 372.0f, 92.0f }, |
| 859 | { 372.0f, 92.0f }, |
| 860 | { 372.0f, 92.0f }, |
| 861 | { 372.0f, 92.0f }, |
| 862 | }; |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 863 | |
| reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 864 | stroke_cubic(p0); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 865 | |
| reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 866 | SkPoint p1[] = { |
| 867 | { 372.0f, 92.0f }, |
| 868 | { 372.0007f, 92.000755f }, |
| 869 | { 371.99927f, 92.003922f }, |
| 870 | { 371.99826f, 92.003899f }, |
| 871 | }; |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 872 | |
| reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 873 | stroke_cubic(p1); |
| 874 | } |
| 875 | |
| bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 876 | static void check_close(skiatest::Reporter* reporter, const SkPath& path) { |
| 877 | for (int i = 0; i < 2; ++i) { |
| robertphillips@google.com | 09042b8 | 2012-04-06 20:01:46 +0000 | [diff] [blame] | 878 | SkPath::Iter iter(path, SkToBool(i)); |
| bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 879 | SkPoint mv; |
| 880 | SkPoint pts[4]; |
| 881 | SkPath::Verb v; |
| 882 | int nMT = 0; |
| 883 | int nCL = 0; |
| tomhudson@google.com | 221db3c | 2011-07-28 21:10:29 +0000 | [diff] [blame] | 884 | mv.set(0, 0); |
| bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 885 | while (SkPath::kDone_Verb != (v = iter.next(pts))) { |
| 886 | switch (v) { |
| 887 | case SkPath::kMove_Verb: |
| 888 | mv = pts[0]; |
| 889 | ++nMT; |
| 890 | break; |
| 891 | case SkPath::kClose_Verb: |
| 892 | REPORTER_ASSERT(reporter, mv == pts[0]); |
| 893 | ++nCL; |
| 894 | break; |
| 895 | default: |
| 896 | break; |
| 897 | } |
| 898 | } |
| 899 | // if we force a close on the interator we should have a close |
| 900 | // for every moveTo |
| 901 | REPORTER_ASSERT(reporter, !i || nMT == nCL); |
| 902 | } |
| 903 | } |
| 904 | |
| 905 | static void test_close(skiatest::Reporter* reporter) { |
| 906 | SkPath closePt; |
| 907 | closePt.moveTo(0, 0); |
| 908 | closePt.close(); |
| 909 | check_close(reporter, closePt); |
| 910 | |
| 911 | SkPath openPt; |
| 912 | openPt.moveTo(0, 0); |
| 913 | check_close(reporter, openPt); |
| 914 | |
| 915 | SkPath empty; |
| 916 | check_close(reporter, empty); |
| 917 | empty.close(); |
| 918 | check_close(reporter, empty); |
| 919 | |
| 920 | SkPath rect; |
| 921 | rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 922 | check_close(reporter, rect); |
| 923 | rect.close(); |
| 924 | check_close(reporter, rect); |
| 925 | |
| 926 | SkPath quad; |
| 927 | quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 928 | check_close(reporter, quad); |
| 929 | quad.close(); |
| 930 | check_close(reporter, quad); |
| 931 | |
| 932 | SkPath cubic; |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 933 | quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, |
| bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 934 | 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1); |
| 935 | check_close(reporter, cubic); |
| 936 | cubic.close(); |
| 937 | check_close(reporter, cubic); |
| 938 | |
| 939 | SkPath line; |
| 940 | line.moveTo(SK_Scalar1, SK_Scalar1); |
| 941 | line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1); |
| 942 | check_close(reporter, line); |
| 943 | line.close(); |
| 944 | check_close(reporter, line); |
| 945 | |
| 946 | SkPath rect2; |
| 947 | rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 948 | rect2.close(); |
| 949 | rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 950 | check_close(reporter, rect2); |
| 951 | rect2.close(); |
| 952 | check_close(reporter, rect2); |
| 953 | |
| 954 | SkPath oval3; |
| 955 | oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100)); |
| 956 | oval3.close(); |
| 957 | oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200)); |
| 958 | check_close(reporter, oval3); |
| 959 | oval3.close(); |
| 960 | check_close(reporter, oval3); |
| 961 | |
| 962 | SkPath moves; |
| 963 | moves.moveTo(SK_Scalar1, SK_Scalar1); |
| 964 | moves.moveTo(5 * SK_Scalar1, SK_Scalar1); |
| 965 | moves.moveTo(SK_Scalar1, 10 * SK_Scalar1); |
| 966 | moves.moveTo(10 *SK_Scalar1, SK_Scalar1); |
| 967 | check_close(reporter, moves); |
| reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 968 | |
| 969 | stroke_tiny_cubic(); |
| bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 970 | } |
| 971 | |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 972 | static void check_convexity(skiatest::Reporter* reporter, const SkPath& path, |
| 973 | SkPath::Convexity expected) { |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 974 | SkPath copy(path); // we make a copy so that we don't cache the result on the passed in path. |
| 975 | SkPath::Convexity c = copy.getConvexity(); |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 976 | REPORTER_ASSERT(reporter, c == expected); |
| 977 | } |
| 978 | |
| 979 | static void test_convexity2(skiatest::Reporter* reporter) { |
| 980 | SkPath pt; |
| 981 | pt.moveTo(0, 0); |
| 982 | pt.close(); |
| reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 983 | check_convexity(reporter, pt, SkPath::kConvex_Convexity); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 984 | check_direction(reporter, pt, SkPath::kUnknown_Direction); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 985 | |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 986 | SkPath line; |
| schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 987 | line.moveTo(12*SK_Scalar1, 20*SK_Scalar1); |
| 988 | line.lineTo(-12*SK_Scalar1, -20*SK_Scalar1); |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 989 | line.close(); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 990 | check_convexity(reporter, line, SkPath::kConvex_Convexity); |
| 991 | check_direction(reporter, line, SkPath::kUnknown_Direction); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 992 | |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 993 | SkPath triLeft; |
| 994 | triLeft.moveTo(0, 0); |
| schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 995 | triLeft.lineTo(SK_Scalar1, 0); |
| 996 | triLeft.lineTo(SK_Scalar1, SK_Scalar1); |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 997 | triLeft.close(); |
| 998 | check_convexity(reporter, triLeft, SkPath::kConvex_Convexity); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 999 | check_direction(reporter, triLeft, SkPath::kCW_Direction); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1000 | |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1001 | SkPath triRight; |
| 1002 | triRight.moveTo(0, 0); |
| schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1003 | triRight.lineTo(-SK_Scalar1, 0); |
| 1004 | triRight.lineTo(SK_Scalar1, SK_Scalar1); |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1005 | triRight.close(); |
| 1006 | check_convexity(reporter, triRight, SkPath::kConvex_Convexity); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1007 | check_direction(reporter, triRight, SkPath::kCCW_Direction); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1008 | |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1009 | SkPath square; |
| 1010 | square.moveTo(0, 0); |
| schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1011 | square.lineTo(SK_Scalar1, 0); |
| 1012 | square.lineTo(SK_Scalar1, SK_Scalar1); |
| 1013 | square.lineTo(0, SK_Scalar1); |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1014 | square.close(); |
| 1015 | check_convexity(reporter, square, SkPath::kConvex_Convexity); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1016 | check_direction(reporter, square, SkPath::kCW_Direction); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1017 | |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1018 | SkPath redundantSquare; |
| 1019 | redundantSquare.moveTo(0, 0); |
| 1020 | redundantSquare.lineTo(0, 0); |
| 1021 | redundantSquare.lineTo(0, 0); |
| schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1022 | redundantSquare.lineTo(SK_Scalar1, 0); |
| 1023 | redundantSquare.lineTo(SK_Scalar1, 0); |
| 1024 | redundantSquare.lineTo(SK_Scalar1, 0); |
| 1025 | redundantSquare.lineTo(SK_Scalar1, SK_Scalar1); |
| 1026 | redundantSquare.lineTo(SK_Scalar1, SK_Scalar1); |
| 1027 | redundantSquare.lineTo(SK_Scalar1, SK_Scalar1); |
| 1028 | redundantSquare.lineTo(0, SK_Scalar1); |
| 1029 | redundantSquare.lineTo(0, SK_Scalar1); |
| 1030 | redundantSquare.lineTo(0, SK_Scalar1); |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1031 | redundantSquare.close(); |
| 1032 | check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1033 | check_direction(reporter, redundantSquare, SkPath::kCW_Direction); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1034 | |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1035 | SkPath bowTie; |
| 1036 | bowTie.moveTo(0, 0); |
| 1037 | bowTie.lineTo(0, 0); |
| 1038 | bowTie.lineTo(0, 0); |
| schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1039 | bowTie.lineTo(SK_Scalar1, SK_Scalar1); |
| 1040 | bowTie.lineTo(SK_Scalar1, SK_Scalar1); |
| 1041 | bowTie.lineTo(SK_Scalar1, SK_Scalar1); |
| 1042 | bowTie.lineTo(SK_Scalar1, 0); |
| 1043 | bowTie.lineTo(SK_Scalar1, 0); |
| 1044 | bowTie.lineTo(SK_Scalar1, 0); |
| 1045 | bowTie.lineTo(0, SK_Scalar1); |
| 1046 | bowTie.lineTo(0, SK_Scalar1); |
| 1047 | bowTie.lineTo(0, SK_Scalar1); |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1048 | bowTie.close(); |
| 1049 | check_convexity(reporter, bowTie, SkPath::kConcave_Convexity); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1050 | check_direction(reporter, bowTie, kDontCheckDir); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1051 | |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1052 | SkPath spiral; |
| 1053 | spiral.moveTo(0, 0); |
| schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1054 | spiral.lineTo(100*SK_Scalar1, 0); |
| 1055 | spiral.lineTo(100*SK_Scalar1, 100*SK_Scalar1); |
| 1056 | spiral.lineTo(0, 100*SK_Scalar1); |
| 1057 | spiral.lineTo(0, 50*SK_Scalar1); |
| 1058 | spiral.lineTo(50*SK_Scalar1, 50*SK_Scalar1); |
| 1059 | spiral.lineTo(50*SK_Scalar1, 75*SK_Scalar1); |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1060 | spiral.close(); |
| reed@google.com | 85b6e39 | 2011-05-15 20:25:17 +0000 | [diff] [blame] | 1061 | check_convexity(reporter, spiral, SkPath::kConcave_Convexity); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1062 | check_direction(reporter, spiral, kDontCheckDir); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1063 | |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1064 | SkPath dent; |
| schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 1065 | dent.moveTo(0, 0); |
| 1066 | dent.lineTo(100*SK_Scalar1, 100*SK_Scalar1); |
| 1067 | dent.lineTo(0, 100*SK_Scalar1); |
| 1068 | dent.lineTo(-50*SK_Scalar1, 200*SK_Scalar1); |
| 1069 | dent.lineTo(-200*SK_Scalar1, 100*SK_Scalar1); |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1070 | dent.close(); |
| 1071 | check_convexity(reporter, dent, SkPath::kConcave_Convexity); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1072 | check_direction(reporter, dent, SkPath::kCW_Direction); |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1073 | } |
| 1074 | |
| reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 1075 | static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p, |
| 1076 | const SkRect& bounds) { |
| 1077 | REPORTER_ASSERT(reporter, p.isConvex()); |
| 1078 | REPORTER_ASSERT(reporter, p.getBounds() == bounds); |
| reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 1079 | |
| reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 1080 | SkPath p2(p); |
| 1081 | REPORTER_ASSERT(reporter, p2.isConvex()); |
| 1082 | REPORTER_ASSERT(reporter, p2.getBounds() == bounds); |
| 1083 | |
| 1084 | SkPath other; |
| 1085 | other.swap(p2); |
| 1086 | REPORTER_ASSERT(reporter, other.isConvex()); |
| 1087 | REPORTER_ASSERT(reporter, other.getBounds() == bounds); |
| 1088 | } |
| 1089 | |
| reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1090 | static void setFromString(SkPath* path, const char str[]) { |
| 1091 | bool first = true; |
| 1092 | while (str) { |
| 1093 | SkScalar x, y; |
| 1094 | str = SkParse::FindScalar(str, &x); |
| 1095 | if (NULL == str) { |
| 1096 | break; |
| 1097 | } |
| 1098 | str = SkParse::FindScalar(str, &y); |
| 1099 | SkASSERT(str); |
| 1100 | if (first) { |
| 1101 | path->moveTo(x, y); |
| 1102 | first = false; |
| 1103 | } else { |
| 1104 | path->lineTo(x, y); |
| 1105 | } |
| 1106 | } |
| 1107 | } |
| 1108 | |
| 1109 | static void test_convexity(skiatest::Reporter* reporter) { |
| reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1110 | SkPath path; |
| 1111 | |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1112 | check_convexity(reporter, path, SkPath::kConvex_Convexity); |
| reed@google.com | e354397 | 2012-01-10 18:59:22 +0000 | [diff] [blame] | 1113 | path.addCircle(0, 0, SkIntToScalar(10)); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1114 | check_convexity(reporter, path, SkPath::kConvex_Convexity); |
| reed@google.com | e354397 | 2012-01-10 18:59:22 +0000 | [diff] [blame] | 1115 | path.addCircle(0, 0, SkIntToScalar(10)); // 2nd circle |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1116 | check_convexity(reporter, path, SkPath::kConcave_Convexity); |
| 1117 | |
| reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1118 | path.reset(); |
| reed@google.com | e354397 | 2012-01-10 18:59:22 +0000 | [diff] [blame] | 1119 | path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCCW_Direction); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1120 | check_convexity(reporter, path, SkPath::kConvex_Convexity); |
| reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1121 | REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCCW_Direction)); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1122 | |
| reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1123 | path.reset(); |
| reed@google.com | e354397 | 2012-01-10 18:59:22 +0000 | [diff] [blame] | 1124 | path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCW_Direction); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1125 | check_convexity(reporter, path, SkPath::kConvex_Convexity); |
| reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 1126 | REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCW_Direction)); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1127 | |
| reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1128 | static const struct { |
| 1129 | const char* fPathStr; |
| 1130 | SkPath::Convexity fExpectedConvexity; |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1131 | SkPath::Direction fExpectedDirection; |
| reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1132 | } gRec[] = { |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1133 | { "", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction }, |
| 1134 | { "0 0", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction }, |
| 1135 | { "0 0 10 10", SkPath::kConvex_Convexity, SkPath::kUnknown_Direction }, |
| 1136 | { "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity, SkPath::kUnknown_Direction }, |
| 1137 | { "0 0 10 10 10 20", SkPath::kConvex_Convexity, SkPath::kCW_Direction }, |
| 1138 | { "0 0 10 10 10 0", SkPath::kConvex_Convexity, SkPath::kCCW_Direction }, |
| 1139 | { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity, kDontCheckDir }, |
| 1140 | { "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] | 1141 | }; |
| 1142 | |
| 1143 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 1144 | SkPath path; |
| 1145 | setFromString(&path, gRec[i].fPathStr); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 1146 | check_convexity(reporter, path, gRec[i].fExpectedConvexity); |
| 1147 | check_direction(reporter, path, gRec[i].fExpectedDirection); |
| reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1148 | } |
| 1149 | } |
| 1150 | |
| reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 1151 | static void test_isLine(skiatest::Reporter* reporter) { |
| 1152 | SkPath path; |
| 1153 | SkPoint pts[2]; |
| 1154 | const SkScalar value = SkIntToScalar(5); |
| 1155 | |
| 1156 | REPORTER_ASSERT(reporter, !path.isLine(NULL)); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1157 | |
| reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 1158 | // set some non-zero values |
| 1159 | pts[0].set(value, value); |
| 1160 | pts[1].set(value, value); |
| 1161 | REPORTER_ASSERT(reporter, !path.isLine(pts)); |
| 1162 | // check that pts was untouched |
| 1163 | REPORTER_ASSERT(reporter, pts[0].equals(value, value)); |
| 1164 | REPORTER_ASSERT(reporter, pts[1].equals(value, value)); |
| 1165 | |
| 1166 | const SkScalar moveX = SkIntToScalar(1); |
| 1167 | const SkScalar moveY = SkIntToScalar(2); |
| 1168 | SkASSERT(value != moveX && value != moveY); |
| 1169 | |
| 1170 | path.moveTo(moveX, moveY); |
| 1171 | REPORTER_ASSERT(reporter, !path.isLine(NULL)); |
| 1172 | REPORTER_ASSERT(reporter, !path.isLine(pts)); |
| 1173 | // check that pts was untouched |
| 1174 | REPORTER_ASSERT(reporter, pts[0].equals(value, value)); |
| 1175 | REPORTER_ASSERT(reporter, pts[1].equals(value, value)); |
| 1176 | |
| 1177 | const SkScalar lineX = SkIntToScalar(2); |
| 1178 | const SkScalar lineY = SkIntToScalar(2); |
| 1179 | SkASSERT(value != lineX && value != lineY); |
| 1180 | |
| 1181 | path.lineTo(lineX, lineY); |
| 1182 | REPORTER_ASSERT(reporter, path.isLine(NULL)); |
| 1183 | |
| 1184 | REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY)); |
| 1185 | REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY)); |
| 1186 | REPORTER_ASSERT(reporter, path.isLine(pts)); |
| 1187 | REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY)); |
| 1188 | REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY)); |
| 1189 | |
| 1190 | path.lineTo(0, 0); // too many points/verbs |
| 1191 | REPORTER_ASSERT(reporter, !path.isLine(NULL)); |
| 1192 | REPORTER_ASSERT(reporter, !path.isLine(pts)); |
| 1193 | REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY)); |
| 1194 | REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY)); |
| 1195 | } |
| 1196 | |
| bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1197 | static void test_conservativelyContains(skiatest::Reporter* reporter) { |
| 1198 | SkPath path; |
| 1199 | |
| 1200 | // kBaseRect is used to construct most our test paths: a rect, a circle, and a round-rect. |
| 1201 | static const SkRect kBaseRect = SkRect::MakeWH(SkIntToScalar(100), SkIntToScalar(100)); |
| 1202 | |
| 1203 | // A circle that bounds kBaseRect (with a significant amount of slop) |
| 1204 | SkScalar circleR = SkMaxScalar(kBaseRect.width(), kBaseRect.height()); |
| 1205 | circleR = SkScalarMul(circleR, SkFloatToScalar(1.75f)) / 2; |
| 1206 | static const SkPoint kCircleC = {kBaseRect.centerX(), kBaseRect.centerY()}; |
| 1207 | |
| 1208 | // round-rect radii |
| 1209 | static const SkScalar kRRRadii[] = {SkIntToScalar(5), SkIntToScalar(3)}; |
| skia.committer@gmail.com | cec8de6 | 2012-11-14 02:01:22 +0000 | [diff] [blame] | 1210 | |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1211 | static const struct SUPPRESS_VISIBILITY_WARNING { |
| bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1212 | SkRect fQueryRect; |
| 1213 | bool fInRect; |
| 1214 | bool fInCircle; |
| 1215 | bool fInRR; |
| 1216 | } kQueries[] = { |
| 1217 | {kBaseRect, true, true, false}, |
| 1218 | |
| 1219 | // rect well inside of kBaseRect |
| 1220 | {SkRect::MakeLTRB(kBaseRect.fLeft + SkFloatToScalar(0.25f)*kBaseRect.width(), |
| 1221 | kBaseRect.fTop + SkFloatToScalar(0.25f)*kBaseRect.height(), |
| 1222 | kBaseRect.fRight - SkFloatToScalar(0.25f)*kBaseRect.width(), |
| 1223 | kBaseRect.fBottom - SkFloatToScalar(0.25f)*kBaseRect.height()), |
| 1224 | true, true, true}, |
| 1225 | |
| 1226 | // rects with edges off by one from kBaseRect's edges |
| 1227 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, |
| 1228 | kBaseRect.width(), kBaseRect.height() + 1), |
| 1229 | false, true, false}, |
| 1230 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, |
| 1231 | kBaseRect.width() + 1, kBaseRect.height()), |
| 1232 | false, true, false}, |
| 1233 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, |
| 1234 | kBaseRect.width() + 1, kBaseRect.height() + 1), |
| 1235 | false, true, false}, |
| 1236 | {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop, |
| 1237 | kBaseRect.width(), kBaseRect.height()), |
| 1238 | false, true, false}, |
| 1239 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1, |
| 1240 | kBaseRect.width(), kBaseRect.height()), |
| 1241 | false, true, false}, |
| 1242 | {SkRect::MakeXYWH(kBaseRect.fLeft - 1, kBaseRect.fTop, |
| 1243 | kBaseRect.width() + 2, kBaseRect.height()), |
| 1244 | false, true, false}, |
| 1245 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop - 1, |
| 1246 | kBaseRect.width() + 2, kBaseRect.height()), |
| 1247 | false, true, false}, |
| 1248 | |
| 1249 | // zero-w/h rects at each corner of kBaseRect |
| 1250 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fTop, 0, 0), true, true, false}, |
| 1251 | {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fTop, 0, 0), true, true, false}, |
| 1252 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.fBottom, 0, 0), true, true, false}, |
| 1253 | {SkRect::MakeXYWH(kBaseRect.fRight, kBaseRect.fBottom, 0, 0), true, true, false}, |
| 1254 | |
| 1255 | // far away rect |
| 1256 | {SkRect::MakeXYWH(10 * kBaseRect.fRight, 10 * kBaseRect.fBottom, |
| 1257 | SkIntToScalar(10), SkIntToScalar(10)), |
| 1258 | false, false, false}, |
| 1259 | |
| 1260 | // very large rect containing kBaseRect |
| 1261 | {SkRect::MakeXYWH(kBaseRect.fLeft - 5 * kBaseRect.width(), |
| 1262 | kBaseRect.fTop - 5 * kBaseRect.height(), |
| 1263 | 11 * kBaseRect.width(), 11 * kBaseRect.height()), |
| 1264 | false, false, false}, |
| 1265 | |
| 1266 | // skinny rect that spans same y-range as kBaseRect |
| 1267 | {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop, |
| 1268 | SkIntToScalar(1), kBaseRect.height()), |
| 1269 | true, true, true}, |
| 1270 | |
| 1271 | // short rect that spans same x-range as kBaseRect |
| 1272 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), kBaseRect.width(), SkScalar(1)), |
| 1273 | true, true, true}, |
| 1274 | |
| 1275 | // skinny rect that spans slightly larger y-range than kBaseRect |
| 1276 | {SkRect::MakeXYWH(kBaseRect.centerX(), kBaseRect.fTop, |
| 1277 | SkIntToScalar(1), kBaseRect.height() + 1), |
| 1278 | false, true, false}, |
| 1279 | |
| 1280 | // short rect that spans slightly larger x-range than kBaseRect |
| 1281 | {SkRect::MakeXYWH(kBaseRect.fLeft, kBaseRect.centerY(), |
| 1282 | kBaseRect.width() + 1, SkScalar(1)), |
| 1283 | false, true, false}, |
| 1284 | }; |
| 1285 | |
| 1286 | for (int inv = 0; inv < 4; ++inv) { |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1287 | for (size_t q = 0; q < SK_ARRAY_COUNT(kQueries); ++q) { |
| bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1288 | SkRect qRect = kQueries[q].fQueryRect; |
| 1289 | if (inv & 0x1) { |
| 1290 | SkTSwap(qRect.fLeft, qRect.fRight); |
| 1291 | } |
| 1292 | if (inv & 0x2) { |
| 1293 | SkTSwap(qRect.fTop, qRect.fBottom); |
| 1294 | } |
| 1295 | for (int d = 0; d < 2; ++d) { |
| 1296 | SkPath::Direction dir = d ? SkPath::kCCW_Direction : SkPath::kCW_Direction; |
| 1297 | path.reset(); |
| 1298 | path.addRect(kBaseRect, dir); |
| 1299 | REPORTER_ASSERT(reporter, kQueries[q].fInRect == |
| 1300 | path.conservativelyContainsRect(qRect)); |
| 1301 | |
| 1302 | path.reset(); |
| 1303 | path.addCircle(kCircleC.fX, kCircleC.fY, circleR, dir); |
| 1304 | REPORTER_ASSERT(reporter, kQueries[q].fInCircle == |
| 1305 | path.conservativelyContainsRect(qRect)); |
| 1306 | |
| 1307 | path.reset(); |
| 1308 | path.addRoundRect(kBaseRect, kRRRadii[0], kRRRadii[1], dir); |
| 1309 | REPORTER_ASSERT(reporter, kQueries[q].fInRR == |
| 1310 | path.conservativelyContainsRect(qRect)); |
| 1311 | } |
| 1312 | // Slightly non-convex shape, shouldn't contain any rects. |
| 1313 | path.reset(); |
| 1314 | path.moveTo(0, 0); |
| 1315 | path.lineTo(SkIntToScalar(50), SkFloatToScalar(0.05f)); |
| 1316 | path.lineTo(SkIntToScalar(100), 0); |
| 1317 | path.lineTo(SkIntToScalar(100), SkIntToScalar(100)); |
| 1318 | path.lineTo(0, SkIntToScalar(100)); |
| 1319 | path.close(); |
| 1320 | REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(qRect)); |
| 1321 | } |
| 1322 | } |
| 1323 | |
| 1324 | // make sure a minimal convex shape works, a right tri with edges along pos x and y axes. |
| 1325 | path.reset(); |
| 1326 | path.moveTo(0, 0); |
| 1327 | path.lineTo(SkIntToScalar(100), 0); |
| 1328 | path.lineTo(0, SkIntToScalar(100)); |
| 1329 | |
| 1330 | // inside, on along top edge |
| 1331 | REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0, |
| 1332 | SkIntToScalar(10), |
| 1333 | SkIntToScalar(10)))); |
| 1334 | // above |
| 1335 | REPORTER_ASSERT(reporter, !path.conservativelyContainsRect( |
| 1336 | SkRect::MakeXYWH(SkIntToScalar(50), |
| 1337 | SkIntToScalar(-10), |
| 1338 | SkIntToScalar(10), |
| 1339 | SkIntToScalar(10)))); |
| 1340 | // to the left |
| 1341 | REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(-10), |
| 1342 | SkIntToScalar(5), |
| 1343 | SkIntToScalar(5), |
| 1344 | SkIntToScalar(5)))); |
| 1345 | |
| 1346 | // outside the diagonal edge |
| 1347 | REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(10), |
| 1348 | SkIntToScalar(200), |
| 1349 | SkIntToScalar(20), |
| 1350 | SkIntToScalar(5)))); |
| commit-bot@chromium.org | 62df526 | 2013-08-01 15:35:06 +0000 | [diff] [blame] | 1351 | |
| 1352 | // same as above path and first test but with an extra moveTo. |
| 1353 | path.reset(); |
| 1354 | path.moveTo(100, 100); |
| 1355 | path.moveTo(0, 0); |
| 1356 | path.lineTo(SkIntToScalar(100), 0); |
| 1357 | path.lineTo(0, SkIntToScalar(100)); |
| 1358 | |
| 1359 | REPORTER_ASSERT(reporter, path.conservativelyContainsRect(SkRect::MakeXYWH(SkIntToScalar(50), 0, |
| 1360 | SkIntToScalar(10), |
| 1361 | SkIntToScalar(10)))); |
| 1362 | |
| bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 1363 | } |
| 1364 | |
| reed@google.com | f32322b | 2013-10-16 15:14:04 +0000 | [diff] [blame] | 1365 | static void test_isRect_open_close(skiatest::Reporter* reporter) { |
| 1366 | SkPath path; |
| 1367 | bool isClosed; |
| 1368 | |
| 1369 | path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1); |
| 1370 | |
| 1371 | if (false) { |
| 1372 | // I think these should pass, but isRect() doesn't behave |
| 1373 | // this way... yet |
| 1374 | REPORTER_ASSERT(reporter, path.isRect(NULL, NULL)); |
| 1375 | REPORTER_ASSERT(reporter, path.isRect(&isClosed, NULL)); |
| 1376 | REPORTER_ASSERT(reporter, !isClosed); |
| 1377 | } |
| 1378 | |
| 1379 | path.close(); |
| 1380 | REPORTER_ASSERT(reporter, path.isRect(NULL, NULL)); |
| 1381 | REPORTER_ASSERT(reporter, path.isRect(&isClosed, NULL)); |
| 1382 | REPORTER_ASSERT(reporter, isClosed); |
| 1383 | } |
| 1384 | |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1385 | // Simple isRect test is inline TestPath, below. |
| 1386 | // test_isRect provides more extensive testing. |
| 1387 | static void test_isRect(skiatest::Reporter* reporter) { |
| reed@google.com | f32322b | 2013-10-16 15:14:04 +0000 | [diff] [blame] | 1388 | test_isRect_open_close(reporter); |
| 1389 | |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1390 | // passing tests (all moveTo / lineTo... |
| 1391 | SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; |
| 1392 | SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
| 1393 | SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}}; |
| 1394 | SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}}; |
| 1395 | SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; |
| 1396 | SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| 1397 | SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}}; |
| 1398 | SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}}; |
| 1399 | SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1400 | SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; |
| 1401 | 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] | 1402 | SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
| 1403 | SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| 1404 | 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] | 1405 | 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] | 1406 | |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1407 | // failing tests |
| 1408 | SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points |
| 1409 | SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal |
| 1410 | SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps |
| 1411 | SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up |
| 1412 | SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots |
| 1413 | SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots |
| 1414 | SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots |
| 1415 | SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L' |
| caryclark@google.com | bfe9037 | 2012-11-21 13:56:20 +0000 | [diff] [blame] | 1416 | SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps |
| 1417 | SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non colinear gap |
| 1418 | 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] | 1419 | |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1420 | // failing, no close |
| 1421 | SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match |
| 1422 | SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto |
| 1423 | |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1424 | struct IsRectTest { |
| 1425 | SkPoint *fPoints; |
| 1426 | size_t fPointCount; |
| 1427 | bool fClose; |
| 1428 | bool fIsRect; |
| 1429 | } tests[] = { |
| 1430 | { r1, SK_ARRAY_COUNT(r1), true, true }, |
| 1431 | { r2, SK_ARRAY_COUNT(r2), true, true }, |
| 1432 | { r3, SK_ARRAY_COUNT(r3), true, true }, |
| 1433 | { r4, SK_ARRAY_COUNT(r4), true, true }, |
| 1434 | { r5, SK_ARRAY_COUNT(r5), true, true }, |
| 1435 | { r6, SK_ARRAY_COUNT(r6), true, true }, |
| 1436 | { r7, SK_ARRAY_COUNT(r7), true, true }, |
| 1437 | { r8, SK_ARRAY_COUNT(r8), true, true }, |
| 1438 | { r9, SK_ARRAY_COUNT(r9), true, true }, |
| 1439 | { ra, SK_ARRAY_COUNT(ra), true, true }, |
| 1440 | { rb, SK_ARRAY_COUNT(rb), true, true }, |
| 1441 | { rc, SK_ARRAY_COUNT(rc), true, true }, |
| 1442 | { rd, SK_ARRAY_COUNT(rd), true, true }, |
| 1443 | { re, SK_ARRAY_COUNT(re), true, true }, |
| 1444 | { rf, SK_ARRAY_COUNT(rf), true, true }, |
| 1445 | |
| 1446 | { f1, SK_ARRAY_COUNT(f1), true, false }, |
| 1447 | { f2, SK_ARRAY_COUNT(f2), true, false }, |
| 1448 | { f3, SK_ARRAY_COUNT(f3), true, false }, |
| 1449 | { f4, SK_ARRAY_COUNT(f4), true, false }, |
| 1450 | { f5, SK_ARRAY_COUNT(f5), true, false }, |
| 1451 | { f6, SK_ARRAY_COUNT(f6), true, false }, |
| 1452 | { f7, SK_ARRAY_COUNT(f7), true, false }, |
| 1453 | { f8, SK_ARRAY_COUNT(f8), true, false }, |
| 1454 | { f9, SK_ARRAY_COUNT(f9), true, false }, |
| 1455 | { fa, SK_ARRAY_COUNT(fa), true, false }, |
| 1456 | { fb, SK_ARRAY_COUNT(fb), true, false }, |
| 1457 | |
| 1458 | { c1, SK_ARRAY_COUNT(c1), false, false }, |
| 1459 | { c2, SK_ARRAY_COUNT(c2), false, false }, |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1460 | }; |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1461 | |
| 1462 | const size_t testCount = SK_ARRAY_COUNT(tests); |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1463 | size_t index; |
| 1464 | for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { |
| 1465 | SkPath path; |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1466 | path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY); |
| 1467 | for (index = 1; index < tests[testIndex].fPointCount; ++index) { |
| 1468 | 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] | 1469 | } |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1470 | if (tests[testIndex].fClose) { |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1471 | path.close(); |
| 1472 | } |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1473 | REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL)); |
| 1474 | REPORTER_ASSERT(reporter, tests[testIndex].fIsRect == path.isRect(NULL, NULL)); |
| caryclark@google.com | f68154a | 2012-11-21 15:18:06 +0000 | [diff] [blame] | 1475 | |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1476 | if (tests[testIndex].fIsRect) { |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1477 | SkRect computed, expected; |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1478 | expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1479 | REPORTER_ASSERT(reporter, path.isRect(&computed)); |
| 1480 | REPORTER_ASSERT(reporter, expected == computed); |
| skia.committer@gmail.com | 1c9c0d3 | 2012-11-22 02:02:41 +0000 | [diff] [blame] | 1481 | |
| caryclark@google.com | f68154a | 2012-11-21 15:18:06 +0000 | [diff] [blame] | 1482 | bool isClosed; |
| 1483 | SkPath::Direction direction, cheapDirection; |
| 1484 | REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection)); |
| robertphillips@google.com | 8fd1603 | 2013-06-25 15:39:58 +0000 | [diff] [blame] | 1485 | REPORTER_ASSERT(reporter, path.isRect(&isClosed, &direction)); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1486 | REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose); |
| caryclark@google.com | f68154a | 2012-11-21 15:18:06 +0000 | [diff] [blame] | 1487 | REPORTER_ASSERT(reporter, direction == cheapDirection); |
| 1488 | } else { |
| 1489 | SkRect computed; |
| 1490 | computed.set(123, 456, 789, 1011); |
| 1491 | REPORTER_ASSERT(reporter, !path.isRect(&computed)); |
| 1492 | REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop == 456); |
| 1493 | REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom == 1011); |
| 1494 | |
| 1495 | bool isClosed = (bool) -1; |
| 1496 | SkPath::Direction direction = (SkPath::Direction) -1; |
| robertphillips@google.com | 8fd1603 | 2013-06-25 15:39:58 +0000 | [diff] [blame] | 1497 | REPORTER_ASSERT(reporter, !path.isRect(&isClosed, &direction)); |
| caryclark@google.com | f68154a | 2012-11-21 15:18:06 +0000 | [diff] [blame] | 1498 | REPORTER_ASSERT(reporter, isClosed == (bool) -1); |
| 1499 | REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1500 | } |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1501 | } |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1502 | |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1503 | // fail, close then line |
| 1504 | SkPath path1; |
| 1505 | path1.moveTo(r1[0].fX, r1[0].fY); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1506 | for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) { |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1507 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 1508 | } |
| 1509 | path1.close(); |
| 1510 | path1.lineTo(1, 0); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1511 | REPORTER_ASSERT(reporter, !path1.isRect(NULL)); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1512 | |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1513 | // fail, move in the middle |
| 1514 | path1.reset(); |
| 1515 | path1.moveTo(r1[0].fX, r1[0].fY); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1516 | for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) { |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1517 | if (index == 2) { |
| 1518 | path1.moveTo(1, .5f); |
| 1519 | } |
| 1520 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 1521 | } |
| 1522 | path1.close(); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1523 | REPORTER_ASSERT(reporter, !path1.isRect(NULL)); |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1524 | |
| 1525 | // fail, move on the edge |
| 1526 | path1.reset(); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1527 | for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) { |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1528 | path1.moveTo(r1[index - 1].fX, r1[index - 1].fY); |
| 1529 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 1530 | } |
| 1531 | path1.close(); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1532 | REPORTER_ASSERT(reporter, !path1.isRect(NULL)); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1533 | |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1534 | // fail, quad |
| 1535 | path1.reset(); |
| 1536 | path1.moveTo(r1[0].fX, r1[0].fY); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1537 | for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) { |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1538 | if (index == 2) { |
| 1539 | path1.quadTo(1, .5f, 1, .5f); |
| 1540 | } |
| 1541 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 1542 | } |
| 1543 | path1.close(); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1544 | REPORTER_ASSERT(reporter, !path1.isRect(NULL)); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1545 | |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1546 | // fail, cubic |
| 1547 | path1.reset(); |
| 1548 | path1.moveTo(r1[0].fX, r1[0].fY); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1549 | for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) { |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1550 | if (index == 2) { |
| 1551 | path1.cubicTo(1, .5f, 1, .5f, 1, .5f); |
| 1552 | } |
| 1553 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 1554 | } |
| 1555 | path1.close(); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1556 | REPORTER_ASSERT(reporter, !path1.isRect(NULL)); |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1557 | } |
| 1558 | |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1559 | static void test_isNestedRects(skiatest::Reporter* reporter) { |
| 1560 | // passing tests (all moveTo / lineTo... |
| robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1561 | SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // CW |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1562 | SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
| 1563 | SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}}; |
| 1564 | SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}}; |
| robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1565 | SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; // CCW |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1566 | SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| 1567 | SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}}; |
| 1568 | SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}}; |
| 1569 | SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1570 | SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, {1, 0}, {.5f, 0}}; // CCW |
| 1571 | 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] | 1572 | SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; // CW |
| 1573 | SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; // CCW |
| 1574 | 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] | 1575 | |
| 1576 | // failing tests |
| 1577 | SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points |
| 1578 | SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal |
| 1579 | SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps |
| 1580 | SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up |
| 1581 | SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots |
| 1582 | SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots |
| 1583 | SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots |
| 1584 | SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L' |
| 1585 | |
| 1586 | // failing, no close |
| 1587 | SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match |
| 1588 | SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto |
| 1589 | |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1590 | struct IsNestedRectTest { |
| 1591 | SkPoint *fPoints; |
| 1592 | size_t fPointCount; |
| 1593 | SkPath::Direction fDirection; |
| 1594 | bool fClose; |
| 1595 | bool fIsNestedRect; // nests with path.addRect(-1, -1, 2, 2); |
| 1596 | } tests[] = { |
| 1597 | { r1, SK_ARRAY_COUNT(r1), SkPath::kCW_Direction , true, true }, |
| 1598 | { r2, SK_ARRAY_COUNT(r2), SkPath::kCW_Direction , true, true }, |
| 1599 | { r3, SK_ARRAY_COUNT(r3), SkPath::kCW_Direction , true, true }, |
| 1600 | { r4, SK_ARRAY_COUNT(r4), SkPath::kCW_Direction , true, true }, |
| 1601 | { r5, SK_ARRAY_COUNT(r5), SkPath::kCCW_Direction, true, true }, |
| 1602 | { r6, SK_ARRAY_COUNT(r6), SkPath::kCCW_Direction, true, true }, |
| 1603 | { r7, SK_ARRAY_COUNT(r7), SkPath::kCCW_Direction, true, true }, |
| 1604 | { r8, SK_ARRAY_COUNT(r8), SkPath::kCCW_Direction, true, true }, |
| 1605 | { r9, SK_ARRAY_COUNT(r9), SkPath::kCCW_Direction, true, true }, |
| 1606 | { ra, SK_ARRAY_COUNT(ra), SkPath::kCCW_Direction, true, true }, |
| 1607 | { rb, SK_ARRAY_COUNT(rb), SkPath::kCW_Direction, true, true }, |
| 1608 | { rc, SK_ARRAY_COUNT(rc), SkPath::kCW_Direction, true, true }, |
| 1609 | { rd, SK_ARRAY_COUNT(rd), SkPath::kCCW_Direction, true, true }, |
| 1610 | { re, SK_ARRAY_COUNT(re), SkPath::kCW_Direction, true, true }, |
| robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1611 | |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1612 | { f1, SK_ARRAY_COUNT(f1), SkPath::kUnknown_Direction, true, false }, |
| 1613 | { f2, SK_ARRAY_COUNT(f2), SkPath::kUnknown_Direction, true, false }, |
| 1614 | { f3, SK_ARRAY_COUNT(f3), SkPath::kUnknown_Direction, true, false }, |
| 1615 | { f4, SK_ARRAY_COUNT(f4), SkPath::kUnknown_Direction, true, false }, |
| 1616 | { f5, SK_ARRAY_COUNT(f5), SkPath::kUnknown_Direction, true, false }, |
| 1617 | { f6, SK_ARRAY_COUNT(f6), SkPath::kUnknown_Direction, true, false }, |
| 1618 | { f7, SK_ARRAY_COUNT(f7), SkPath::kUnknown_Direction, true, false }, |
| 1619 | { f8, SK_ARRAY_COUNT(f8), SkPath::kUnknown_Direction, true, false }, |
| 1620 | |
| 1621 | { c1, SK_ARRAY_COUNT(c1), SkPath::kUnknown_Direction, false, false }, |
| 1622 | { c2, SK_ARRAY_COUNT(c2), SkPath::kUnknown_Direction, false, false }, |
| 1623 | }; |
| 1624 | |
| 1625 | const size_t testCount = SK_ARRAY_COUNT(tests); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1626 | size_t index; |
| 1627 | for (int rectFirst = 0; rectFirst <= 1; ++rectFirst) { |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1628 | for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { |
| 1629 | SkPath path; |
| 1630 | if (rectFirst) { |
| 1631 | path.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); |
| 1632 | } |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1633 | path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].fY); |
| 1634 | for (index = 1; index < tests[testIndex].fPointCount; ++index) { |
| 1635 | 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] | 1636 | } |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1637 | if (tests[testIndex].fClose) { |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1638 | path.close(); |
| 1639 | } |
| 1640 | if (!rectFirst) { |
| 1641 | path.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); |
| 1642 | } |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1643 | REPORTER_ASSERT(reporter, tests[testIndex].fIsNestedRect == path.isNestedRects(NULL)); |
| 1644 | if (tests[testIndex].fIsNestedRect) { |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1645 | SkRect expected[2], computed[2]; |
| robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1646 | SkPath::Direction expectedDirs[2], computedDirs[2]; |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1647 | SkRect testBounds; |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1648 | testBounds.set(tests[testIndex].fPoints, tests[testIndex].fPointCount); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1649 | expected[0] = SkRect::MakeLTRB(-1, -1, 2, 2); |
| 1650 | expected[1] = testBounds; |
| robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1651 | if (rectFirst) { |
| 1652 | expectedDirs[0] = SkPath::kCW_Direction; |
| 1653 | } else { |
| 1654 | expectedDirs[0] = SkPath::kCCW_Direction; |
| 1655 | } |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1656 | expectedDirs[1] = tests[testIndex].fDirection; |
| robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1657 | REPORTER_ASSERT(reporter, path.isNestedRects(computed, computedDirs)); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1658 | REPORTER_ASSERT(reporter, expected[0] == computed[0]); |
| 1659 | REPORTER_ASSERT(reporter, expected[1] == computed[1]); |
| robertphillips@google.com | 83d1a68 | 2013-05-17 12:50:27 +0000 | [diff] [blame] | 1660 | REPORTER_ASSERT(reporter, expectedDirs[0] == computedDirs[0]); |
| 1661 | REPORTER_ASSERT(reporter, expectedDirs[1] == computedDirs[1]); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1662 | } |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1663 | } |
| 1664 | |
| 1665 | // fail, close then line |
| 1666 | SkPath path1; |
| 1667 | if (rectFirst) { |
| 1668 | path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); |
| 1669 | } |
| 1670 | path1.moveTo(r1[0].fX, r1[0].fY); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1671 | for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) { |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1672 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 1673 | } |
| 1674 | path1.close(); |
| 1675 | path1.lineTo(1, 0); |
| 1676 | if (!rectFirst) { |
| 1677 | path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); |
| 1678 | } |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1679 | REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL)); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1680 | |
| 1681 | // fail, move in the middle |
| 1682 | path1.reset(); |
| 1683 | if (rectFirst) { |
| 1684 | path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); |
| 1685 | } |
| 1686 | path1.moveTo(r1[0].fX, r1[0].fY); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1687 | for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) { |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1688 | if (index == 2) { |
| 1689 | path1.moveTo(1, .5f); |
| 1690 | } |
| 1691 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 1692 | } |
| 1693 | path1.close(); |
| 1694 | if (!rectFirst) { |
| 1695 | path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); |
| 1696 | } |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1697 | REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL)); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1698 | |
| 1699 | // fail, move on the edge |
| 1700 | path1.reset(); |
| 1701 | if (rectFirst) { |
| 1702 | path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); |
| 1703 | } |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1704 | for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) { |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1705 | path1.moveTo(r1[index - 1].fX, r1[index - 1].fY); |
| 1706 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 1707 | } |
| 1708 | path1.close(); |
| 1709 | if (!rectFirst) { |
| 1710 | path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); |
| 1711 | } |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1712 | REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL)); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1713 | |
| 1714 | // fail, quad |
| 1715 | path1.reset(); |
| 1716 | if (rectFirst) { |
| 1717 | path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); |
| 1718 | } |
| 1719 | path1.moveTo(r1[0].fX, r1[0].fY); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1720 | for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) { |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1721 | if (index == 2) { |
| 1722 | path1.quadTo(1, .5f, 1, .5f); |
| 1723 | } |
| 1724 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 1725 | } |
| 1726 | path1.close(); |
| 1727 | if (!rectFirst) { |
| 1728 | path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); |
| 1729 | } |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1730 | REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL)); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1731 | |
| 1732 | // fail, cubic |
| 1733 | path1.reset(); |
| 1734 | if (rectFirst) { |
| 1735 | path1.addRect(-1, -1, 2, 2, SkPath::kCW_Direction); |
| 1736 | } |
| 1737 | path1.moveTo(r1[0].fX, r1[0].fY); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1738 | for (index = 1; index < SK_ARRAY_COUNT(r1); ++index) { |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1739 | if (index == 2) { |
| 1740 | path1.cubicTo(1, .5f, 1, .5f, 1, .5f); |
| 1741 | } |
| 1742 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 1743 | } |
| 1744 | path1.close(); |
| 1745 | if (!rectFirst) { |
| 1746 | path1.addRect(-1, -1, 2, 2, SkPath::kCCW_Direction); |
| 1747 | } |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1748 | REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL)); |
| skia.committer@gmail.com | 3458716 | 2012-11-20 02:01:23 +0000 | [diff] [blame] | 1749 | |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1750 | // fail, not nested |
| 1751 | path1.reset(); |
| 1752 | path1.addRect(1, 1, 3, 3, SkPath::kCW_Direction); |
| 1753 | path1.addRect(2, 2, 4, 4, SkPath::kCW_Direction); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1754 | REPORTER_ASSERT(reporter, !path1.isNestedRects(NULL)); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1755 | } |
| caryclark@google.com | bfe9037 | 2012-11-21 13:56:20 +0000 | [diff] [blame] | 1756 | |
| 1757 | // pass, stroke rect |
| 1758 | SkPath src, dst; |
| 1759 | src.addRect(1, 1, 7, 7, SkPath::kCW_Direction); |
| 1760 | SkPaint strokePaint; |
| 1761 | strokePaint.setStyle(SkPaint::kStroke_Style); |
| 1762 | strokePaint.setStrokeWidth(2); |
| 1763 | strokePaint.getFillPath(src, &dst); |
| bungeman@google.com | b8d9d5b | 2013-09-25 18:21:39 +0000 | [diff] [blame] | 1764 | REPORTER_ASSERT(reporter, dst.isNestedRects(NULL)); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1765 | } |
| 1766 | |
| robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 1767 | static void write_and_read_back(skiatest::Reporter* reporter, |
| 1768 | const SkPath& p) { |
| 1769 | SkWriter32 writer(100); |
| 1770 | writer.writePath(p); |
| 1771 | size_t size = writer.size(); |
| 1772 | SkAutoMalloc storage(size); |
| 1773 | writer.flatten(storage.get()); |
| 1774 | SkReader32 reader(storage.get(), size); |
| 1775 | |
| 1776 | SkPath readBack; |
| 1777 | REPORTER_ASSERT(reporter, readBack != p); |
| 1778 | reader.readPath(&readBack); |
| 1779 | REPORTER_ASSERT(reporter, readBack == p); |
| 1780 | |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1781 | REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() == |
| robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 1782 | p.getConvexityOrUnknown()); |
| 1783 | |
| 1784 | REPORTER_ASSERT(reporter, readBack.isOval(NULL) == p.isOval(NULL)); |
| 1785 | |
| 1786 | const SkRect& origBounds = p.getBounds(); |
| 1787 | const SkRect& readBackBounds = readBack.getBounds(); |
| 1788 | |
| 1789 | REPORTER_ASSERT(reporter, origBounds == readBackBounds); |
| 1790 | } |
| 1791 | |
| reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 1792 | static void test_flattening(skiatest::Reporter* reporter) { |
| 1793 | SkPath p; |
| 1794 | |
| 1795 | static const SkPoint pts[] = { |
| 1796 | { 0, 0 }, |
| 1797 | { SkIntToScalar(10), SkIntToScalar(10) }, |
| 1798 | { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, |
| 1799 | { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) } |
| 1800 | }; |
| 1801 | p.moveTo(pts[0]); |
| 1802 | p.lineTo(pts[1]); |
| 1803 | p.quadTo(pts[2], pts[3]); |
| 1804 | p.cubicTo(pts[4], pts[5], pts[6]); |
| 1805 | |
| robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 1806 | write_and_read_back(reporter, p); |
| djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 1807 | |
| 1808 | // create a buffer that should be much larger than the path so we don't |
| 1809 | // kill our stack if writer goes too far. |
| 1810 | char buffer[1024]; |
| 1811 | uint32_t size1 = p.writeToMemory(NULL); |
| 1812 | uint32_t size2 = p.writeToMemory(buffer); |
| 1813 | REPORTER_ASSERT(reporter, size1 == size2); |
| 1814 | |
| 1815 | SkPath p2; |
| 1816 | uint32_t size3 = p2.readFromMemory(buffer); |
| 1817 | REPORTER_ASSERT(reporter, size1 == size3); |
| 1818 | REPORTER_ASSERT(reporter, p == p2); |
| 1819 | |
| 1820 | char buffer2[1024]; |
| 1821 | size3 = p2.writeToMemory(buffer2); |
| 1822 | REPORTER_ASSERT(reporter, size1 == size3); |
| 1823 | REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0); |
| robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 1824 | |
| 1825 | // test persistence of the oval flag & convexity |
| 1826 | { |
| 1827 | SkPath oval; |
| 1828 | SkRect rect = SkRect::MakeWH(10, 10); |
| 1829 | oval.addOval(rect); |
| 1830 | |
| 1831 | write_and_read_back(reporter, oval); |
| 1832 | } |
| reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 1833 | } |
| 1834 | |
| 1835 | static void test_transform(skiatest::Reporter* reporter) { |
| 1836 | SkPath p, p1; |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1837 | |
| reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 1838 | static const SkPoint pts[] = { |
| 1839 | { 0, 0 }, |
| 1840 | { SkIntToScalar(10), SkIntToScalar(10) }, |
| 1841 | { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, |
| 1842 | { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) } |
| 1843 | }; |
| 1844 | p.moveTo(pts[0]); |
| 1845 | p.lineTo(pts[1]); |
| 1846 | p.quadTo(pts[2], pts[3]); |
| 1847 | p.cubicTo(pts[4], pts[5], pts[6]); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1848 | |
| reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 1849 | SkMatrix matrix; |
| 1850 | matrix.reset(); |
| 1851 | p.transform(matrix, &p1); |
| 1852 | REPORTER_ASSERT(reporter, p == p1); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1853 | |
| reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 1854 | matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3); |
| 1855 | p.transform(matrix, &p1); |
| 1856 | SkPoint pts1[7]; |
| 1857 | int count = p1.getPoints(pts1, 7); |
| 1858 | REPORTER_ASSERT(reporter, 7 == count); |
| 1859 | for (int i = 0; i < count; ++i) { |
| 1860 | SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3); |
| 1861 | REPORTER_ASSERT(reporter, newPt == pts1[i]); |
| 1862 | } |
| 1863 | } |
| 1864 | |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 1865 | static void test_zero_length_paths(skiatest::Reporter* reporter) { |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1866 | SkPath p; |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1867 | uint8_t verbs[32]; |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 1868 | |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 1869 | struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData { |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1870 | const char* testPath; |
| 1871 | const size_t numResultPts; |
| 1872 | const SkRect resultBound; |
| 1873 | const SkPath::Verb* resultVerbs; |
| 1874 | const size_t numResultVerbs; |
| 1875 | }; |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 1876 | |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1877 | static const SkPath::Verb resultVerbs1[] = { SkPath::kMove_Verb }; |
| 1878 | static const SkPath::Verb resultVerbs2[] = { SkPath::kMove_Verb, SkPath::kMove_Verb }; |
| 1879 | static const SkPath::Verb resultVerbs3[] = { SkPath::kMove_Verb, SkPath::kClose_Verb }; |
| 1880 | static const SkPath::Verb resultVerbs4[] = { SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb }; |
| 1881 | static const SkPath::Verb resultVerbs5[] = { SkPath::kMove_Verb, SkPath::kLine_Verb }; |
| 1882 | static const SkPath::Verb resultVerbs6[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb }; |
| 1883 | static const SkPath::Verb resultVerbs7[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb }; |
| 1884 | static const SkPath::Verb resultVerbs8[] = { |
| 1885 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb |
| 1886 | }; |
| 1887 | static const SkPath::Verb resultVerbs9[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb }; |
| 1888 | static const SkPath::Verb resultVerbs10[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb }; |
| 1889 | static const SkPath::Verb resultVerbs11[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb }; |
| 1890 | static const SkPath::Verb resultVerbs12[] = { |
| 1891 | SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb |
| 1892 | }; |
| 1893 | static const SkPath::Verb resultVerbs13[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb }; |
| 1894 | static const SkPath::Verb resultVerbs14[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb }; |
| 1895 | static const SkPath::Verb resultVerbs15[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb }; |
| 1896 | static const SkPath::Verb resultVerbs16[] = { |
| 1897 | SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb |
| 1898 | }; |
| 1899 | static const struct zeroPathTestData gZeroLengthTests[] = { |
| 1900 | { "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] | 1901 | { "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] | 1902 | { "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] | 1903 | { "M 1 1 z M 2 1 z", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) }, |
| 1904 | { "M 1 1 L 1 1", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) }, |
| 1905 | { "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) }, |
| 1906 | { "M 1 1 L 1 1 z", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs7, SK_ARRAY_COUNT(resultVerbs7) }, |
| 1907 | { "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) }, |
| 1908 | { "M 1 1 Q 1 1 1 1", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs9, SK_ARRAY_COUNT(resultVerbs9) }, |
| 1909 | { "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) }, |
| 1910 | { "M 1 1 Q 1 1 1 1 z", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs11, SK_ARRAY_COUNT(resultVerbs11) }, |
| 1911 | { "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) }, |
| 1912 | { "M 1 1 C 1 1 1 1 1 1", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs13, SK_ARRAY_COUNT(resultVerbs13) }, |
| 1913 | { "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] | 1914 | SK_ARRAY_COUNT(resultVerbs14) |
| 1915 | }, |
| schenney@chromium.org | aaf1688 | 2012-06-13 17:41:00 +0000 | [diff] [blame] | 1916 | { "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) }, |
| 1917 | { "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] | 1918 | SK_ARRAY_COUNT(resultVerbs16) |
| 1919 | } |
| 1920 | }; |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 1921 | |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1922 | for (size_t i = 0; i < SK_ARRAY_COUNT(gZeroLengthTests); ++i) { |
| 1923 | p.reset(); |
| 1924 | bool valid = SkParsePath::FromSVGString(gZeroLengthTests[i].testPath, &p); |
| 1925 | REPORTER_ASSERT(reporter, valid); |
| 1926 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
| 1927 | REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultPts == (size_t)p.countPoints()); |
| 1928 | REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultBound == p.getBounds()); |
| 1929 | REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultVerbs == (size_t)p.getVerbs(verbs, SK_ARRAY_COUNT(verbs))); |
| 1930 | for (size_t j = 0; j < gZeroLengthTests[i].numResultVerbs; ++j) { |
| 1931 | REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultVerbs[j] == verbs[j]); |
| 1932 | } |
| bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 1933 | } |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | struct SegmentInfo { |
| 1937 | SkPath fPath; |
| 1938 | int fPointCount; |
| 1939 | }; |
| 1940 | |
| reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 1941 | #define kCurveSegmentMask (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask) |
| 1942 | |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1943 | static void test_segment_masks(skiatest::Reporter* reporter) { |
| reed@google.com | eef938c | 2012-08-01 20:01:49 +0000 | [diff] [blame] | 1944 | SkPath p, p2; |
| 1945 | |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1946 | p.moveTo(0, 0); |
| 1947 | p.quadTo(100, 100, 200, 200); |
| 1948 | REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == p.getSegmentMasks()); |
| 1949 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
| reed@google.com | eef938c | 2012-08-01 20:01:49 +0000 | [diff] [blame] | 1950 | p2 = p; |
| 1951 | REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks()); |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1952 | p.cubicTo(100, 100, 200, 200, 300, 300); |
| 1953 | REPORTER_ASSERT(reporter, kCurveSegmentMask == p.getSegmentMasks()); |
| 1954 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
| reed@google.com | eef938c | 2012-08-01 20:01:49 +0000 | [diff] [blame] | 1955 | p2 = p; |
| 1956 | REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks()); |
| 1957 | |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1958 | p.reset(); |
| 1959 | p.moveTo(0, 0); |
| 1960 | p.cubicTo(100, 100, 200, 200, 300, 300); |
| 1961 | REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == p.getSegmentMasks()); |
| reed@google.com | eef938c | 2012-08-01 20:01:49 +0000 | [diff] [blame] | 1962 | p2 = p; |
| 1963 | REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks()); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1964 | |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1965 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
| 1966 | } |
| 1967 | |
| 1968 | static void test_iter(skiatest::Reporter* reporter) { |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1969 | SkPath p; |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1970 | SkPoint pts[4]; |
| 1971 | |
| 1972 | // Test an iterator with no path |
| 1973 | SkPath::Iter noPathIter; |
| 1974 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1975 | |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1976 | // Test that setting an empty path works |
| 1977 | noPathIter.setPath(p, false); |
| 1978 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1979 | |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1980 | // Test that close path makes no difference for an empty path |
| 1981 | noPathIter.setPath(p, true); |
| 1982 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1983 | |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1984 | // Test an iterator with an initial empty path |
| 1985 | SkPath::Iter iter(p, false); |
| 1986 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 1987 | |
| 1988 | // Test that close path makes no difference |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1989 | iter.setPath(p, true); |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1990 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 1991 | |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1992 | |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1993 | struct iterTestData { |
| 1994 | const char* testPath; |
| 1995 | const bool forceClose; |
| 1996 | const bool consumeDegenerates; |
| 1997 | const size_t* numResultPtsPerVerb; |
| 1998 | const SkPoint* resultPts; |
| 1999 | const SkPath::Verb* resultVerbs; |
| 2000 | const size_t numResultVerbs; |
| 2001 | }; |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2002 | |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2003 | static const SkPath::Verb resultVerbs1[] = { SkPath::kDone_Verb }; |
| 2004 | static const SkPath::Verb resultVerbs2[] = { |
| 2005 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kDone_Verb |
| 2006 | }; |
| 2007 | static const SkPath::Verb resultVerbs3[] = { |
| 2008 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb |
| 2009 | }; |
| 2010 | static const SkPath::Verb resultVerbs4[] = { |
| 2011 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb |
| 2012 | }; |
| 2013 | static const SkPath::Verb resultVerbs5[] = { |
| 2014 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb |
| 2015 | }; |
| 2016 | static const size_t resultPtsSizes1[] = { 0 }; |
| schenney@chromium.org | fedd09b | 2012-06-13 18:29:20 +0000 | [diff] [blame] | 2017 | static const size_t resultPtsSizes2[] = { 1, 2, 2, 0 }; |
| 2018 | static const size_t resultPtsSizes3[] = { 1, 2, 2, 2, 1, 0 }; |
| 2019 | static const size_t resultPtsSizes4[] = { 1, 2, 1, 1, 0 }; |
| 2020 | static const size_t resultPtsSizes5[] = { 1, 2, 1, 1, 1, 0 }; |
| schenney@chromium.org | aaf1688 | 2012-06-13 17:41:00 +0000 | [diff] [blame] | 2021 | static const SkPoint* resultPts1 = 0; |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2022 | static const SkPoint resultPts2[] = { |
| 2023 | { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 } |
| 2024 | }; |
| 2025 | static const SkPoint resultPts3[] = { |
| 2026 | { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 }, |
| 2027 | { 0, SK_Scalar1 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 } |
| 2028 | }; |
| 2029 | static const SkPoint resultPts4[] = { |
| 2030 | { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 } |
| 2031 | }; |
| 2032 | static const SkPoint resultPts5[] = { |
| 2033 | { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 } |
| 2034 | }; |
| 2035 | static const struct iterTestData gIterTests[] = { |
| 2036 | { "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] | 2037 | { "M 1 0 M 2 0 M 3 0 M 4 0 M 5 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 2038 | { "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] | 2039 | { "z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 2040 | { "z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 2041 | { "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) }, |
| 2042 | { "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] | 2043 | { "M 1 0 L 1 1 L 0 1 M 0 0 z", false, true, resultPtsSizes2, resultPts2, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) }, |
| 2044 | { "M 1 0 L 1 1 L 0 1 M 0 0 z", true, true, resultPtsSizes3, resultPts3, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) }, |
| 2045 | { "M 1 0 L 1 0 M 0 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 2046 | { "M 1 0 L 1 0 M 0 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 2047 | { "M 1 0 L 1 0 M 0 0 z", false, false, resultPtsSizes4, resultPts4, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) }, |
| 2048 | { "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] | 2049 | }; |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2050 | |
| schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 2051 | for (size_t i = 0; i < SK_ARRAY_COUNT(gIterTests); ++i) { |
| 2052 | p.reset(); |
| 2053 | bool valid = SkParsePath::FromSVGString(gIterTests[i].testPath, &p); |
| 2054 | REPORTER_ASSERT(reporter, valid); |
| 2055 | iter.setPath(p, gIterTests[i].forceClose); |
| 2056 | int j = 0, l = 0; |
| 2057 | do { |
| 2058 | REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegenerates) == gIterTests[i].resultVerbs[j]); |
| 2059 | for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k) { |
| 2060 | REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]); |
| 2061 | } |
| 2062 | } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb); |
| 2063 | REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs); |
| 2064 | } |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2065 | |
| 2066 | // The GM degeneratesegments.cpp test is more extensive |
| 2067 | } |
| 2068 | |
| 2069 | static void test_raw_iter(skiatest::Reporter* reporter) { |
| 2070 | SkPath p; |
| 2071 | SkPoint pts[4]; |
| 2072 | |
| 2073 | // Test an iterator with no path |
| 2074 | SkPath::RawIter noPathIter; |
| 2075 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
| 2076 | // Test that setting an empty path works |
| 2077 | noPathIter.setPath(p); |
| 2078 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 2079 | |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2080 | // Test an iterator with an initial empty path |
| 2081 | SkPath::RawIter iter(p); |
| 2082 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 2083 | |
| 2084 | // Test that a move-only path returns the move. |
| 2085 | p.moveTo(SK_Scalar1, 0); |
| 2086 | iter.setPath(p); |
| 2087 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 2088 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1); |
| 2089 | REPORTER_ASSERT(reporter, pts[0].fY == 0); |
| 2090 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 2091 | |
| 2092 | // No matter how many moves we add, we should get them all back |
| 2093 | p.moveTo(SK_Scalar1*2, SK_Scalar1); |
| 2094 | p.moveTo(SK_Scalar1*3, SK_Scalar1*2); |
| 2095 | iter.setPath(p); |
| 2096 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 2097 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1); |
| 2098 | REPORTER_ASSERT(reporter, pts[0].fY == 0); |
| 2099 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 2100 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2); |
| 2101 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1); |
| 2102 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 2103 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3); |
| 2104 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2); |
| 2105 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 2106 | |
| 2107 | // Initial close is never ever stored |
| 2108 | p.reset(); |
| 2109 | p.close(); |
| 2110 | iter.setPath(p); |
| 2111 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 2112 | |
| 2113 | // Move/close sequences |
| 2114 | p.reset(); |
| 2115 | p.close(); // Not stored, no purpose |
| 2116 | p.moveTo(SK_Scalar1, 0); |
| 2117 | p.close(); |
| 2118 | p.close(); // Not stored, no purpose |
| 2119 | p.moveTo(SK_Scalar1*2, SK_Scalar1); |
| 2120 | p.close(); |
| 2121 | p.moveTo(SK_Scalar1*3, SK_Scalar1*2); |
| 2122 | p.moveTo(SK_Scalar1*4, SK_Scalar1*3); |
| 2123 | p.close(); |
| 2124 | iter.setPath(p); |
| 2125 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 2126 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1); |
| 2127 | REPORTER_ASSERT(reporter, pts[0].fY == 0); |
| 2128 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb); |
| 2129 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1); |
| 2130 | REPORTER_ASSERT(reporter, pts[0].fY == 0); |
| 2131 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 2132 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2); |
| 2133 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1); |
| 2134 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb); |
| 2135 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2); |
| 2136 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1); |
| 2137 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 2138 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3); |
| 2139 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2); |
| 2140 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 2141 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4); |
| 2142 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3); |
| 2143 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb); |
| 2144 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4); |
| 2145 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3); |
| 2146 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 2147 | |
| 2148 | // Generate random paths and verify |
| 2149 | SkPoint randomPts[25]; |
| 2150 | for (int i = 0; i < 5; ++i) { |
| 2151 | for (int j = 0; j < 5; ++j) { |
| 2152 | randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j); |
| 2153 | } |
| 2154 | } |
| 2155 | |
| 2156 | // Max of 10 segments, max 3 points per segment |
| commit-bot@chromium.org | e0e7cfe | 2013-09-09 20:09:12 +0000 | [diff] [blame] | 2157 | SkRandom rand(9876543); |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2158 | SkPoint expectedPts[31]; // May have leading moveTo |
| reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 2159 | SkPath::Verb expectedVerbs[22]; // May have leading moveTo |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2160 | SkPath::Verb nextVerb; |
| reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 2161 | |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2162 | for (int i = 0; i < 500; ++i) { |
| 2163 | p.reset(); |
| 2164 | bool lastWasClose = true; |
| 2165 | bool haveMoveTo = false; |
| reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 2166 | SkPoint lastMoveToPt = { 0, 0 }; |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2167 | int numPoints = 0; |
| 2168 | int numVerbs = (rand.nextU() >> 16) % 10; |
| 2169 | int numIterVerbs = 0; |
| 2170 | for (int j = 0; j < numVerbs; ++j) { |
| 2171 | do { |
| 2172 | nextVerb = static_cast<SkPath::Verb>((rand.nextU() >> 16) % SkPath::kDone_Verb); |
| 2173 | } while (lastWasClose && nextVerb == SkPath::kClose_Verb); |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2174 | switch (nextVerb) { |
| 2175 | case SkPath::kMove_Verb: |
| 2176 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 2177 | p.moveTo(expectedPts[numPoints]); |
| reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 2178 | lastMoveToPt = expectedPts[numPoints]; |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2179 | numPoints += 1; |
| 2180 | lastWasClose = false; |
| 2181 | haveMoveTo = true; |
| 2182 | break; |
| 2183 | case SkPath::kLine_Verb: |
| 2184 | if (!haveMoveTo) { |
| reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 2185 | expectedPts[numPoints++] = lastMoveToPt; |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2186 | expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; |
| 2187 | haveMoveTo = true; |
| 2188 | } |
| 2189 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 2190 | p.lineTo(expectedPts[numPoints]); |
| 2191 | numPoints += 1; |
| 2192 | lastWasClose = false; |
| 2193 | break; |
| 2194 | case SkPath::kQuad_Verb: |
| 2195 | if (!haveMoveTo) { |
| reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 2196 | expectedPts[numPoints++] = lastMoveToPt; |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2197 | expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; |
| 2198 | haveMoveTo = true; |
| 2199 | } |
| 2200 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 2201 | expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25]; |
| 2202 | p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]); |
| 2203 | numPoints += 2; |
| 2204 | lastWasClose = false; |
| 2205 | break; |
| reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 2206 | case SkPath::kConic_Verb: |
| 2207 | if (!haveMoveTo) { |
| 2208 | expectedPts[numPoints++] = lastMoveToPt; |
| 2209 | expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; |
| 2210 | haveMoveTo = true; |
| 2211 | } |
| 2212 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 2213 | expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25]; |
| 2214 | p.conicTo(expectedPts[numPoints], expectedPts[numPoints + 1], |
| 2215 | rand.nextUScalar1() * 4); |
| 2216 | numPoints += 2; |
| 2217 | lastWasClose = false; |
| 2218 | break; |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2219 | case SkPath::kCubic_Verb: |
| 2220 | if (!haveMoveTo) { |
| reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 2221 | expectedPts[numPoints++] = lastMoveToPt; |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2222 | expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; |
| 2223 | haveMoveTo = true; |
| 2224 | } |
| 2225 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 2226 | expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25]; |
| 2227 | expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25]; |
| 2228 | p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1], |
| 2229 | expectedPts[numPoints + 2]); |
| 2230 | numPoints += 3; |
| 2231 | lastWasClose = false; |
| 2232 | break; |
| 2233 | case SkPath::kClose_Verb: |
| 2234 | p.close(); |
| reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 2235 | haveMoveTo = false; |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2236 | lastWasClose = true; |
| 2237 | break; |
| reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 2238 | default: |
| mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 2239 | SkDEBUGFAIL("unexpected verb"); |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2240 | } |
| 2241 | expectedVerbs[numIterVerbs++] = nextVerb; |
| 2242 | } |
| rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 2243 | |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2244 | iter.setPath(p); |
| 2245 | numVerbs = numIterVerbs; |
| 2246 | numIterVerbs = 0; |
| 2247 | int numIterPts = 0; |
| 2248 | SkPoint lastMoveTo; |
| 2249 | SkPoint lastPt; |
| 2250 | lastMoveTo.set(0, 0); |
| 2251 | lastPt.set(0, 0); |
| 2252 | while ((nextVerb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 2253 | REPORTER_ASSERT(reporter, nextVerb == expectedVerbs[numIterVerbs]); |
| 2254 | numIterVerbs++; |
| 2255 | switch (nextVerb) { |
| 2256 | case SkPath::kMove_Verb: |
| 2257 | REPORTER_ASSERT(reporter, numIterPts < numPoints); |
| 2258 | REPORTER_ASSERT(reporter, pts[0] == expectedPts[numIterPts]); |
| 2259 | lastPt = lastMoveTo = pts[0]; |
| 2260 | numIterPts += 1; |
| 2261 | break; |
| 2262 | case SkPath::kLine_Verb: |
| 2263 | REPORTER_ASSERT(reporter, numIterPts < numPoints + 1); |
| 2264 | REPORTER_ASSERT(reporter, pts[0] == lastPt); |
| 2265 | REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]); |
| 2266 | lastPt = pts[1]; |
| 2267 | numIterPts += 1; |
| 2268 | break; |
| 2269 | case SkPath::kQuad_Verb: |
| reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 2270 | case SkPath::kConic_Verb: |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2271 | REPORTER_ASSERT(reporter, numIterPts < numPoints + 2); |
| 2272 | REPORTER_ASSERT(reporter, pts[0] == lastPt); |
| 2273 | REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]); |
| 2274 | REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]); |
| 2275 | lastPt = pts[2]; |
| 2276 | numIterPts += 2; |
| 2277 | break; |
| 2278 | case SkPath::kCubic_Verb: |
| 2279 | REPORTER_ASSERT(reporter, numIterPts < numPoints + 3); |
| 2280 | REPORTER_ASSERT(reporter, pts[0] == lastPt); |
| 2281 | REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]); |
| 2282 | REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]); |
| 2283 | REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]); |
| 2284 | lastPt = pts[3]; |
| 2285 | numIterPts += 3; |
| 2286 | break; |
| 2287 | case SkPath::kClose_Verb: |
| 2288 | REPORTER_ASSERT(reporter, pts[0] == lastMoveTo); |
| 2289 | lastPt = lastMoveTo; |
| 2290 | break; |
| reed@google.com | 277c3f8 | 2013-05-31 15:17:50 +0000 | [diff] [blame] | 2291 | default: |
| mtklein@google.com | 330313a | 2013-08-22 15:37:26 +0000 | [diff] [blame] | 2292 | SkDEBUGFAIL("unexpected verb"); |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2293 | } |
| 2294 | } |
| 2295 | REPORTER_ASSERT(reporter, numIterPts == numPoints); |
| 2296 | REPORTER_ASSERT(reporter, numIterVerbs == numVerbs); |
| 2297 | } |
| 2298 | } |
| 2299 | |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2300 | static void check_for_circle(skiatest::Reporter* reporter, |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2301 | const SkPath& path, |
| 2302 | bool expectedCircle, |
| 2303 | SkPath::Direction expectedDir) { |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2304 | SkRect rect; |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2305 | REPORTER_ASSERT(reporter, path.isOval(&rect) == expectedCircle); |
| 2306 | REPORTER_ASSERT(reporter, path.cheapIsDirection(expectedDir)); |
| skia.committer@gmail.com | fbb0ed9 | 2012-11-13 21:46:06 +0000 | [diff] [blame] | 2307 | |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2308 | if (expectedCircle) { |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2309 | REPORTER_ASSERT(reporter, rect.height() == rect.width()); |
| 2310 | } |
| 2311 | } |
| 2312 | |
| 2313 | static void test_circle_skew(skiatest::Reporter* reporter, |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2314 | const SkPath& path, |
| 2315 | SkPath::Direction dir) { |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2316 | SkPath tmp; |
| 2317 | |
| 2318 | SkMatrix m; |
| 2319 | m.setSkew(SkIntToScalar(3), SkIntToScalar(5)); |
| 2320 | path.transform(m, &tmp); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2321 | // this matrix reverses the direction. |
| 2322 | if (SkPath::kCCW_Direction == dir) { |
| 2323 | dir = SkPath::kCW_Direction; |
| 2324 | } else { |
| 2325 | SkASSERT(SkPath::kCW_Direction == dir); |
| 2326 | dir = SkPath::kCCW_Direction; |
| 2327 | } |
| 2328 | check_for_circle(reporter, tmp, false, dir); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2329 | } |
| 2330 | |
| 2331 | static void test_circle_translate(skiatest::Reporter* reporter, |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2332 | const SkPath& path, |
| 2333 | SkPath::Direction dir) { |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2334 | SkPath tmp; |
| 2335 | |
| 2336 | // translate at small offset |
| 2337 | SkMatrix m; |
| 2338 | m.setTranslate(SkIntToScalar(15), SkIntToScalar(15)); |
| 2339 | path.transform(m, &tmp); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2340 | check_for_circle(reporter, tmp, true, dir); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2341 | |
| 2342 | tmp.reset(); |
| 2343 | m.reset(); |
| 2344 | |
| 2345 | // translate at a relatively big offset |
| 2346 | m.setTranslate(SkIntToScalar(1000), SkIntToScalar(1000)); |
| 2347 | path.transform(m, &tmp); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2348 | check_for_circle(reporter, tmp, true, dir); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
| 2351 | static void test_circle_rotate(skiatest::Reporter* reporter, |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2352 | const SkPath& path, |
| 2353 | SkPath::Direction dir) { |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2354 | for (int angle = 0; angle < 360; ++angle) { |
| 2355 | SkPath tmp; |
| 2356 | SkMatrix m; |
| 2357 | m.setRotate(SkIntToScalar(angle)); |
| 2358 | path.transform(m, &tmp); |
| 2359 | |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2360 | // 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] | 2361 | // degrees is not an oval anymore, this can be improved. we made this |
| 2362 | // for the simplicity of our implementation. |
| 2363 | if (angle % 90 == 0) { |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2364 | check_for_circle(reporter, tmp, true, dir); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2365 | } else { |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2366 | check_for_circle(reporter, tmp, false, dir); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2367 | } |
| 2368 | } |
| 2369 | } |
| 2370 | |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2371 | static void test_circle_mirror_x(skiatest::Reporter* reporter, |
| 2372 | const SkPath& path, |
| 2373 | SkPath::Direction dir) { |
| 2374 | SkPath tmp; |
| 2375 | SkMatrix m; |
| 2376 | m.reset(); |
| 2377 | m.setScaleX(-SK_Scalar1); |
| 2378 | path.transform(m, &tmp); |
| 2379 | |
| 2380 | if (SkPath::kCW_Direction == dir) { |
| 2381 | dir = SkPath::kCCW_Direction; |
| 2382 | } else { |
| 2383 | SkASSERT(SkPath::kCCW_Direction == dir); |
| 2384 | dir = SkPath::kCW_Direction; |
| 2385 | } |
| 2386 | |
| 2387 | check_for_circle(reporter, tmp, true, dir); |
| 2388 | } |
| 2389 | |
| 2390 | static void test_circle_mirror_y(skiatest::Reporter* reporter, |
| 2391 | const SkPath& path, |
| 2392 | SkPath::Direction dir) { |
| 2393 | SkPath tmp; |
| 2394 | SkMatrix m; |
| 2395 | m.reset(); |
| 2396 | m.setScaleY(-SK_Scalar1); |
| 2397 | path.transform(m, &tmp); |
| 2398 | |
| 2399 | if (SkPath::kCW_Direction == dir) { |
| 2400 | dir = SkPath::kCCW_Direction; |
| 2401 | } else { |
| 2402 | SkASSERT(SkPath::kCCW_Direction == dir); |
| 2403 | dir = SkPath::kCW_Direction; |
| 2404 | } |
| 2405 | |
| 2406 | check_for_circle(reporter, tmp, true, dir); |
| 2407 | } |
| 2408 | |
| 2409 | static void test_circle_mirror_xy(skiatest::Reporter* reporter, |
| 2410 | const SkPath& path, |
| 2411 | SkPath::Direction dir) { |
| 2412 | SkPath tmp; |
| 2413 | SkMatrix m; |
| 2414 | m.reset(); |
| 2415 | m.setScaleX(-SK_Scalar1); |
| 2416 | m.setScaleY(-SK_Scalar1); |
| 2417 | path.transform(m, &tmp); |
| 2418 | |
| 2419 | check_for_circle(reporter, tmp, true, dir); |
| 2420 | } |
| 2421 | |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2422 | static void test_circle_with_direction(skiatest::Reporter* reporter, |
| 2423 | SkPath::Direction dir) { |
| 2424 | SkPath path; |
| 2425 | |
| 2426 | // circle at origin |
| 2427 | path.addCircle(0, 0, SkIntToScalar(20), dir); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2428 | check_for_circle(reporter, path, true, dir); |
| 2429 | test_circle_rotate(reporter, path, dir); |
| 2430 | test_circle_translate(reporter, path, dir); |
| 2431 | test_circle_skew(reporter, path, dir); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2432 | |
| 2433 | // circle at an offset at (10, 10) |
| 2434 | path.reset(); |
| 2435 | path.addCircle(SkIntToScalar(10), SkIntToScalar(10), |
| 2436 | SkIntToScalar(20), dir); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2437 | check_for_circle(reporter, path, true, dir); |
| 2438 | test_circle_rotate(reporter, path, dir); |
| 2439 | test_circle_translate(reporter, path, dir); |
| 2440 | test_circle_skew(reporter, path, dir); |
| 2441 | test_circle_mirror_x(reporter, path, dir); |
| 2442 | test_circle_mirror_y(reporter, path, dir); |
| 2443 | test_circle_mirror_xy(reporter, path, dir); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2444 | } |
| 2445 | |
| 2446 | static void test_circle_with_add_paths(skiatest::Reporter* reporter) { |
| 2447 | SkPath path; |
| 2448 | SkPath circle; |
| 2449 | SkPath rect; |
| 2450 | SkPath empty; |
| 2451 | |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2452 | static const SkPath::Direction kCircleDir = SkPath::kCW_Direction; |
| 2453 | static const SkPath::Direction kCircleDirOpposite = SkPath::kCCW_Direction; |
| 2454 | |
| 2455 | circle.addCircle(0, 0, SkIntToScalar(10), kCircleDir); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2456 | rect.addRect(SkIntToScalar(5), SkIntToScalar(5), |
| 2457 | SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction); |
| 2458 | |
| 2459 | SkMatrix translate; |
| 2460 | translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12)); |
| 2461 | |
| 2462 | // For simplicity, all the path concatenation related operations |
| 2463 | // would mark it non-circle, though in theory it's still a circle. |
| 2464 | |
| 2465 | // empty + circle (translate) |
| 2466 | path = empty; |
| 2467 | path.addPath(circle, translate); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2468 | check_for_circle(reporter, path, false, kCircleDir); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2469 | |
| 2470 | // circle + empty (translate) |
| 2471 | path = circle; |
| 2472 | path.addPath(empty, translate); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2473 | check_for_circle(reporter, path, false, kCircleDir); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2474 | |
| 2475 | // test reverseAddPath |
| 2476 | path = circle; |
| 2477 | path.reverseAddPath(rect); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2478 | check_for_circle(reporter, path, false, kCircleDirOpposite); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2479 | } |
| 2480 | |
| 2481 | static void test_circle(skiatest::Reporter* reporter) { |
| 2482 | test_circle_with_direction(reporter, SkPath::kCW_Direction); |
| 2483 | test_circle_with_direction(reporter, SkPath::kCCW_Direction); |
| 2484 | |
| 2485 | // multiple addCircle() |
| 2486 | SkPath path; |
| 2487 | path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction); |
| 2488 | path.addCircle(0, 0, SkIntToScalar(20), SkPath::kCW_Direction); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2489 | check_for_circle(reporter, path, false, SkPath::kCW_Direction); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2490 | |
| 2491 | // some extra lineTo() would make isOval() fail |
| 2492 | path.reset(); |
| 2493 | path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction); |
| 2494 | path.lineTo(0, 0); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2495 | check_for_circle(reporter, path, false, SkPath::kCW_Direction); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2496 | |
| 2497 | // not back to the original point |
| 2498 | path.reset(); |
| 2499 | path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction); |
| 2500 | path.setLastPt(SkIntToScalar(5), SkIntToScalar(5)); |
| bsalomon@google.com | 30c174b | 2012-11-13 14:36:42 +0000 | [diff] [blame] | 2501 | check_for_circle(reporter, path, false, SkPath::kCW_Direction); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2502 | |
| 2503 | test_circle_with_add_paths(reporter); |
| 2504 | } |
| 2505 | |
| 2506 | static void test_oval(skiatest::Reporter* reporter) { |
| 2507 | SkRect rect; |
| 2508 | SkMatrix m; |
| 2509 | SkPath path; |
| 2510 | |
| 2511 | rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50)); |
| 2512 | path.addOval(rect); |
| 2513 | |
| 2514 | REPORTER_ASSERT(reporter, path.isOval(NULL)); |
| 2515 | |
| 2516 | m.setRotate(SkIntToScalar(90)); |
| 2517 | SkPath tmp; |
| 2518 | path.transform(m, &tmp); |
| 2519 | // an oval rotated 90 degrees is still an oval. |
| 2520 | REPORTER_ASSERT(reporter, tmp.isOval(NULL)); |
| 2521 | |
| 2522 | m.reset(); |
| 2523 | m.setRotate(SkIntToScalar(30)); |
| 2524 | tmp.reset(); |
| 2525 | path.transform(m, &tmp); |
| 2526 | // an oval rotated 30 degrees is not an oval anymore. |
| 2527 | REPORTER_ASSERT(reporter, !tmp.isOval(NULL)); |
| 2528 | |
| 2529 | // since empty path being transformed. |
| 2530 | path.reset(); |
| 2531 | tmp.reset(); |
| 2532 | m.reset(); |
| 2533 | path.transform(m, &tmp); |
| 2534 | REPORTER_ASSERT(reporter, !tmp.isOval(NULL)); |
| 2535 | |
| 2536 | // empty path is not an oval |
| 2537 | tmp.reset(); |
| 2538 | REPORTER_ASSERT(reporter, !tmp.isOval(NULL)); |
| 2539 | |
| 2540 | // only has moveTo()s |
| 2541 | tmp.reset(); |
| 2542 | tmp.moveTo(0, 0); |
| 2543 | tmp.moveTo(SkIntToScalar(10), SkIntToScalar(10)); |
| 2544 | REPORTER_ASSERT(reporter, !tmp.isOval(NULL)); |
| 2545 | |
| 2546 | // mimic WebKit's calling convention, |
| 2547 | // call moveTo() first and then call addOval() |
| 2548 | path.reset(); |
| 2549 | path.moveTo(0, 0); |
| 2550 | path.addOval(rect); |
| 2551 | REPORTER_ASSERT(reporter, path.isOval(NULL)); |
| 2552 | |
| 2553 | // copy path |
| 2554 | path.reset(); |
| 2555 | tmp.reset(); |
| 2556 | tmp.addOval(rect); |
| 2557 | path = tmp; |
| 2558 | REPORTER_ASSERT(reporter, path.isOval(NULL)); |
| 2559 | } |
| 2560 | |
| bungeman@google.com | a5809a3 | 2013-06-21 15:13:34 +0000 | [diff] [blame] | 2561 | static void test_empty(skiatest::Reporter* reporter, const SkPath& p) { |
| 2562 | SkPath empty; |
| reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 2563 | |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2564 | REPORTER_ASSERT(reporter, p.isEmpty()); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 2565 | REPORTER_ASSERT(reporter, 0 == p.countPoints()); |
| bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 2566 | REPORTER_ASSERT(reporter, 0 == p.countVerbs()); |
| reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 2567 | REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks()); |
| reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 2568 | REPORTER_ASSERT(reporter, p.isConvex()); |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2569 | REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType); |
| 2570 | REPORTER_ASSERT(reporter, !p.isInverseFillType()); |
| bungeman@google.com | a5809a3 | 2013-06-21 15:13:34 +0000 | [diff] [blame] | 2571 | REPORTER_ASSERT(reporter, p == empty); |
| 2572 | REPORTER_ASSERT(reporter, !(p != empty)); |
| 2573 | } |
| 2574 | |
| 2575 | static void TestPath(skiatest::Reporter* reporter) { |
| 2576 | SkTSize<SkScalar>::Make(3,4); |
| 2577 | |
| 2578 | SkPath p, empty; |
| 2579 | SkRect bounds, bounds2; |
| 2580 | test_empty(reporter, p); |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2581 | |
| reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 2582 | REPORTER_ASSERT(reporter, p.getBounds().isEmpty()); |
| reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 2583 | |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2584 | bounds.set(0, 0, SK_Scalar1, SK_Scalar1); |
| reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 2585 | |
| reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 2586 | p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1); |
| 2587 | check_convex_bounds(reporter, p, bounds); |
| reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 2588 | // we have quads or cubics |
| 2589 | REPORTER_ASSERT(reporter, p.getSegmentMasks() & kCurveSegmentMask); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 2590 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
| reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 2591 | |
| reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 2592 | p.reset(); |
| bungeman@google.com | a5809a3 | 2013-06-21 15:13:34 +0000 | [diff] [blame] | 2593 | test_empty(reporter, p); |
| reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 2594 | |
| reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 2595 | p.addOval(bounds); |
| 2596 | check_convex_bounds(reporter, p, bounds); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 2597 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
| reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 2598 | |
| bungeman@google.com | a5809a3 | 2013-06-21 15:13:34 +0000 | [diff] [blame] | 2599 | p.rewind(); |
| 2600 | test_empty(reporter, p); |
| 2601 | |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2602 | p.addRect(bounds); |
| reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 2603 | check_convex_bounds(reporter, p, bounds); |
| reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 2604 | // we have only lines |
| 2605 | REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == p.getSegmentMasks()); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 2606 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2607 | |
| bungeman@google.com | a5809a3 | 2013-06-21 15:13:34 +0000 | [diff] [blame] | 2608 | REPORTER_ASSERT(reporter, p != empty); |
| 2609 | REPORTER_ASSERT(reporter, !(p == empty)); |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2610 | |
| bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 2611 | // do getPoints and getVerbs return the right result |
| 2612 | REPORTER_ASSERT(reporter, p.getPoints(NULL, 0) == 4); |
| 2613 | REPORTER_ASSERT(reporter, p.getVerbs(NULL, 0) == 5); |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2614 | SkPoint pts[4]; |
| 2615 | int count = p.getPoints(pts, 4); |
| 2616 | REPORTER_ASSERT(reporter, count == 4); |
| bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 2617 | uint8_t verbs[6]; |
| 2618 | verbs[5] = 0xff; |
| 2619 | p.getVerbs(verbs, 5); |
| 2620 | REPORTER_ASSERT(reporter, SkPath::kMove_Verb == verbs[0]); |
| 2621 | REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[1]); |
| 2622 | REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[2]); |
| 2623 | REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[3]); |
| 2624 | REPORTER_ASSERT(reporter, SkPath::kClose_Verb == verbs[4]); |
| 2625 | REPORTER_ASSERT(reporter, 0xff == verbs[5]); |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2626 | bounds2.set(pts, 4); |
| 2627 | REPORTER_ASSERT(reporter, bounds == bounds2); |
| reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 2628 | |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2629 | bounds.offset(SK_Scalar1*3, SK_Scalar1*4); |
| 2630 | p.offset(SK_Scalar1*3, SK_Scalar1*4); |
| reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 2631 | REPORTER_ASSERT(reporter, bounds == p.getBounds()); |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2632 | |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2633 | REPORTER_ASSERT(reporter, p.isRect(NULL)); |
| caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 2634 | bounds2.setEmpty(); |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2635 | REPORTER_ASSERT(reporter, p.isRect(&bounds2)); |
| 2636 | REPORTER_ASSERT(reporter, bounds == bounds2); |
| reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 2637 | |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2638 | // now force p to not be a rect |
| 2639 | bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2); |
| 2640 | p.addRect(bounds); |
| 2641 | REPORTER_ASSERT(reporter, !p.isRect(NULL)); |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2642 | |
| reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 2643 | test_isLine(reporter); |
| 2644 | test_isRect(reporter); |
| caryclark@google.com | 56f233a | 2012-11-19 13:06:06 +0000 | [diff] [blame] | 2645 | test_isNestedRects(reporter); |
| schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 2646 | test_zero_length_paths(reporter); |
| reed@google.com | cabaf1d | 2012-01-11 21:03:05 +0000 | [diff] [blame] | 2647 | test_direction(reporter); |
| reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 2648 | test_convexity(reporter); |
| reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 2649 | test_convexity2(reporter); |
| bsalomon@google.com | 9bee33a | 2012-11-13 21:51:38 +0000 | [diff] [blame] | 2650 | test_conservativelyContains(reporter); |
| bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 2651 | test_close(reporter); |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2652 | test_segment_masks(reporter); |
| reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 2653 | test_flattening(reporter); |
| 2654 | test_transform(reporter); |
| reed@google.com | 3563c9e | 2011-11-14 19:34:57 +0000 | [diff] [blame] | 2655 | test_bounds(reporter); |
| schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 2656 | test_iter(reporter); |
| 2657 | test_raw_iter(reporter); |
| bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 2658 | test_circle(reporter); |
| 2659 | test_oval(reporter); |
| reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 2660 | test_strokerec(reporter); |
| reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 2661 | test_addPoly(reporter); |
| reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 2662 | test_isfinite(reporter); |
| tomhudson@google.com | ed02c4d | 2012-08-10 14:10:45 +0000 | [diff] [blame] | 2663 | test_isfinite_after_transform(reporter); |
| robertphillips@google.com | b95eaa8 | 2012-10-18 15:26:12 +0000 | [diff] [blame] | 2664 | test_arb_round_rect_is_convex(reporter); |
| robertphillips@google.com | 158618e | 2012-10-23 16:56:56 +0000 | [diff] [blame] | 2665 | test_arb_zero_rad_round_rect_is_rect(reporter); |
| reed@google.com | a8790de | 2012-10-24 21:04:04 +0000 | [diff] [blame] | 2666 | test_addrect_isfinite(reporter); |
| sugoi@google.com | 54f0d1b | 2013-02-27 19:17:41 +0000 | [diff] [blame] | 2667 | test_tricky_cubic(); |
| 2668 | test_clipped_cubic(); |
| 2669 | test_crbug_170666(); |
| reed@google.com | 7a90daf | 2013-04-10 18:44:00 +0000 | [diff] [blame] | 2670 | test_bad_cubic_crbug229478(); |
| reed@google.com | 3eff359 | 2013-05-08 21:08:21 +0000 | [diff] [blame] | 2671 | test_bad_cubic_crbug234190(); |
| mtklein@google.com | 9c9d4a7 | 2013-08-07 19:17:53 +0000 | [diff] [blame] | 2672 | test_android_specific_behavior(reporter); |
| commit-bot@chromium.org | 1ab9f73 | 2013-10-30 18:57:55 +0000 | [diff] [blame^] | 2673 | test_gen_id(reporter); |
| commit-bot@chromium.org | 9d54aeb | 2013-08-09 19:48:26 +0000 | [diff] [blame] | 2674 | test_path_close_issue1474(reporter); |
| reed@google.com | b58ba89 | 2013-10-15 15:44:35 +0000 | [diff] [blame] | 2675 | test_path_to_region(reporter); |
| reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 2676 | } |
| 2677 | |
| 2678 | #include "TestClassDef.h" |
| 2679 | DEFINE_TESTCLASS("Path", PathTestClass, TestPath) |