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