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