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