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 | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 9 | #include "SkPaint.h" |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 10 | #include "SkPath.h" |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 11 | #include "SkParse.h" |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 12 | #include "SkParsePath.h" |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 13 | #include "SkPathEffect.h" |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 14 | #include "SkRandom.h" |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 15 | #include "SkReader32.h" |
reed@android.com | 60bc6d5 | 2010-02-11 11:09:39 +0000 | [diff] [blame] | 16 | #include "SkSize.h" |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 17 | #include "SkWriter32.h" |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 18 | |
tomhudson@google.com | ed02c4d | 2012-08-10 14:10:45 +0000 | [diff] [blame] | 19 | // Inspired by http://code.google.com/p/chromium/issues/detail?id=141651 |
| 20 | // |
| 21 | static void test_isfinite_after_transform(skiatest::Reporter* reporter) { |
| 22 | SkPath path; |
| 23 | path.quadTo(157, 366, 286, 208); |
| 24 | path.arcTo(37, 442, 315, 163, 957494590897113.0f); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 25 | |
tomhudson@google.com | ed02c4d | 2012-08-10 14:10:45 +0000 | [diff] [blame] | 26 | SkMatrix matrix; |
| 27 | matrix.setScale(1000*1000, 1000*1000); |
| 28 | |
| 29 | // Be sure that path::transform correctly updates isFinite and the bounds |
| 30 | // if the transformation overflows. The previous bug was that isFinite was |
| 31 | // set to true in this case, but the bounds were not set to empty (which |
| 32 | // they should be). |
| 33 | while (path.isFinite()) { |
| 34 | REPORTER_ASSERT(reporter, path.getBounds().isFinite()); |
| 35 | REPORTER_ASSERT(reporter, !path.getBounds().isEmpty()); |
| 36 | path.transform(matrix); |
| 37 | } |
| 38 | REPORTER_ASSERT(reporter, path.getBounds().isEmpty()); |
| 39 | |
| 40 | matrix.setTranslate(SK_Scalar1, SK_Scalar1); |
| 41 | path.transform(matrix); |
| 42 | // we need to still be non-finite |
| 43 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 44 | REPORTER_ASSERT(reporter, path.getBounds().isEmpty()); |
| 45 | } |
| 46 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 47 | static void test_rect_isfinite(skiatest::Reporter* reporter) { |
| 48 | const SkScalar inf = SK_ScalarInfinity; |
| 49 | const SkScalar nan = SK_ScalarNaN; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 50 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 51 | SkRect r; |
| 52 | r.setEmpty(); |
| 53 | REPORTER_ASSERT(reporter, r.isFinite()); |
| 54 | r.set(0, 0, inf, -inf); |
| 55 | REPORTER_ASSERT(reporter, !r.isFinite()); |
| 56 | r.set(0, 0, nan, 0); |
| 57 | REPORTER_ASSERT(reporter, !r.isFinite()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 58 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 59 | SkPoint pts[] = { |
| 60 | { 0, 0 }, |
| 61 | { SK_Scalar1, 0 }, |
| 62 | { 0, SK_Scalar1 }, |
| 63 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 64 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 65 | bool isFine = r.setBoundsCheck(pts, 3); |
| 66 | REPORTER_ASSERT(reporter, isFine); |
| 67 | REPORTER_ASSERT(reporter, !r.isEmpty()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 68 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 69 | pts[1].set(inf, 0); |
| 70 | isFine = r.setBoundsCheck(pts, 3); |
| 71 | REPORTER_ASSERT(reporter, !isFine); |
| 72 | REPORTER_ASSERT(reporter, r.isEmpty()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 73 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 74 | pts[1].set(nan, 0); |
| 75 | isFine = r.setBoundsCheck(pts, 3); |
| 76 | REPORTER_ASSERT(reporter, !isFine); |
| 77 | REPORTER_ASSERT(reporter, r.isEmpty()); |
| 78 | } |
| 79 | |
| 80 | static void test_path_isfinite(skiatest::Reporter* reporter) { |
| 81 | const SkScalar inf = SK_ScalarInfinity; |
| 82 | const SkScalar nan = SK_ScalarNaN; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 83 | |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 84 | SkPath path; |
| 85 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 86 | |
| 87 | path.reset(); |
| 88 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 89 | |
| 90 | path.reset(); |
| 91 | path.moveTo(SK_Scalar1, 0); |
| 92 | REPORTER_ASSERT(reporter, path.isFinite()); |
| 93 | |
| 94 | path.reset(); |
| 95 | path.moveTo(inf, -inf); |
| 96 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 97 | |
| 98 | path.reset(); |
| 99 | path.moveTo(nan, 0); |
| 100 | REPORTER_ASSERT(reporter, !path.isFinite()); |
| 101 | } |
| 102 | |
| 103 | static void test_isfinite(skiatest::Reporter* reporter) { |
| 104 | test_rect_isfinite(reporter); |
| 105 | test_path_isfinite(reporter); |
| 106 | } |
| 107 | |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 108 | // assert that we always |
| 109 | // start with a moveTo |
| 110 | // only have 1 moveTo |
| 111 | // only have Lines after that |
| 112 | // end with a single close |
| 113 | // only have (at most) 1 close |
| 114 | // |
| 115 | static void test_poly(skiatest::Reporter* reporter, const SkPath& path, |
| 116 | const SkPoint srcPts[], int count, bool expectClose) { |
| 117 | SkPath::RawIter iter(path); |
| 118 | SkPoint pts[4]; |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 119 | |
| 120 | bool firstTime = true; |
| 121 | bool foundClose = false; |
| 122 | for (;;) { |
| 123 | switch (iter.next(pts)) { |
| 124 | case SkPath::kMove_Verb: |
| 125 | REPORTER_ASSERT(reporter, firstTime); |
| 126 | REPORTER_ASSERT(reporter, pts[0] == srcPts[0]); |
| 127 | srcPts++; |
| 128 | firstTime = false; |
| 129 | break; |
| 130 | case SkPath::kLine_Verb: |
| 131 | REPORTER_ASSERT(reporter, !firstTime); |
| 132 | REPORTER_ASSERT(reporter, pts[1] == srcPts[0]); |
| 133 | srcPts++; |
| 134 | break; |
| 135 | case SkPath::kQuad_Verb: |
| 136 | REPORTER_ASSERT(reporter, !"unexpected quad verb"); |
| 137 | break; |
| 138 | case SkPath::kCubic_Verb: |
| 139 | REPORTER_ASSERT(reporter, !"unexpected cubic verb"); |
| 140 | break; |
| 141 | case SkPath::kClose_Verb: |
| 142 | REPORTER_ASSERT(reporter, !firstTime); |
| 143 | REPORTER_ASSERT(reporter, !foundClose); |
| 144 | REPORTER_ASSERT(reporter, expectClose); |
| 145 | foundClose = true; |
| 146 | break; |
| 147 | case SkPath::kDone_Verb: |
| 148 | goto DONE; |
| 149 | } |
| 150 | } |
| 151 | DONE: |
| 152 | REPORTER_ASSERT(reporter, foundClose == expectClose); |
| 153 | } |
| 154 | |
| 155 | static void test_addPoly(skiatest::Reporter* reporter) { |
| 156 | SkPoint pts[32]; |
| 157 | SkRandom rand; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 158 | |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 159 | for (size_t i = 0; i < SK_ARRAY_COUNT(pts); ++i) { |
| 160 | pts[i].fX = rand.nextSScalar1(); |
| 161 | pts[i].fY = rand.nextSScalar1(); |
| 162 | } |
| 163 | |
| 164 | for (int doClose = 0; doClose <= 1; ++doClose) { |
| 165 | for (size_t count = 1; count <= SK_ARRAY_COUNT(pts); ++count) { |
| 166 | SkPath path; |
| 167 | path.addPoly(pts, count, SkToBool(doClose)); |
| 168 | test_poly(reporter, path, pts, count, SkToBool(doClose)); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 173 | static void test_strokerec(skiatest::Reporter* reporter) { |
| 174 | SkStrokeRec rec(SkStrokeRec::kFill_InitStyle); |
| 175 | REPORTER_ASSERT(reporter, rec.isFillStyle()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 176 | |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 177 | rec.setHairlineStyle(); |
| 178 | REPORTER_ASSERT(reporter, rec.isHairlineStyle()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 179 | |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 180 | rec.setStrokeStyle(SK_Scalar1, false); |
| 181 | REPORTER_ASSERT(reporter, SkStrokeRec::kStroke_Style == rec.getStyle()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 182 | |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 183 | rec.setStrokeStyle(SK_Scalar1, true); |
| 184 | REPORTER_ASSERT(reporter, SkStrokeRec::kStrokeAndFill_Style == rec.getStyle()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 185 | |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 186 | rec.setStrokeStyle(0, false); |
| 187 | REPORTER_ASSERT(reporter, SkStrokeRec::kHairline_Style == rec.getStyle()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 188 | |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 189 | rec.setStrokeStyle(0, true); |
| 190 | REPORTER_ASSERT(reporter, SkStrokeRec::kFill_Style == rec.getStyle()); |
| 191 | } |
| 192 | |
bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 193 | /** |
| 194 | * cheapIsDirection can take a shortcut when a path is marked convex. |
| 195 | * This function ensures that we always test cheapIsDirection when the path |
| 196 | * is flagged with unknown convexity status. |
| 197 | */ |
| 198 | static void check_direction(SkPath* path, |
| 199 | SkPath::Direction expectedDir, |
| 200 | skiatest::Reporter* reporter) { |
| 201 | if (SkPath::kConvex_Convexity == path->getConvexity()) { |
| 202 | REPORTER_ASSERT(reporter, path->cheapIsDirection(expectedDir)); |
| 203 | path->setConvexity(SkPath::kUnknown_Convexity); |
| 204 | } |
| 205 | REPORTER_ASSERT(reporter, path->cheapIsDirection(expectedDir)); |
| 206 | } |
| 207 | |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 208 | static void test_direction(skiatest::Reporter* reporter) { |
| 209 | size_t i; |
| 210 | SkPath path; |
| 211 | REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL)); |
| 212 | REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCW_Direction)); |
| 213 | REPORTER_ASSERT(reporter, !path.cheapIsDirection(SkPath::kCCW_Direction)); |
| 214 | |
| 215 | static const char* gDegen[] = { |
| 216 | "M 10 10", |
| 217 | "M 10 10 M 20 20", |
| 218 | "M 10 10 L 20 20", |
| 219 | "M 10 10 L 10 10 L 10 10", |
| 220 | "M 10 10 Q 10 10 10 10", |
| 221 | "M 10 10 C 10 10 10 10 10 10", |
| 222 | }; |
| 223 | for (i = 0; i < SK_ARRAY_COUNT(gDegen); ++i) { |
| 224 | path.reset(); |
| 225 | bool valid = SkParsePath::FromSVGString(gDegen[i], &path); |
| 226 | REPORTER_ASSERT(reporter, valid); |
| 227 | REPORTER_ASSERT(reporter, !path.cheapComputeDirection(NULL)); |
| 228 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 229 | |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 230 | static const char* gCW[] = { |
reed@google.com | cabaf1d | 2012-01-11 21:03:05 +0000 | [diff] [blame] | 231 | "M 10 10 L 10 10 Q 20 10 20 20", |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 232 | "M 10 10 C 20 10 20 20 20 20", |
reed@google.com | d414666 | 2012-01-31 15:42:29 +0000 | [diff] [blame] | 233 | "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] | 234 | // rect with top two corners replaced by cubics with identical middle |
| 235 | // control points |
| 236 | "M 10 10 C 10 0 10 0 20 0 L 40 0 C 50 0 50 0 50 10" |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 237 | }; |
| 238 | for (i = 0; i < SK_ARRAY_COUNT(gCW); ++i) { |
| 239 | path.reset(); |
| 240 | bool valid = SkParsePath::FromSVGString(gCW[i], &path); |
| 241 | REPORTER_ASSERT(reporter, valid); |
bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 242 | check_direction(&path, SkPath::kCW_Direction, reporter); |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 243 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 244 | |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 245 | static const char* gCCW[] = { |
reed@google.com | cabaf1d | 2012-01-11 21:03:05 +0000 | [diff] [blame] | 246 | "M 10 10 L 10 10 Q 20 10 20 -20", |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 247 | "M 10 10 C 20 10 20 -20 20 -20", |
reed@google.com | d414666 | 2012-01-31 15:42:29 +0000 | [diff] [blame] | 248 | "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] | 249 | // rect with top two corners replaced by cubics with identical middle |
| 250 | // control points |
| 251 | "M 50 10 C 50 0 50 0 40 0 L 20 0 C 10 0 10 0 10 10" |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 252 | }; |
| 253 | for (i = 0; i < SK_ARRAY_COUNT(gCCW); ++i) { |
| 254 | path.reset(); |
| 255 | bool valid = SkParsePath::FromSVGString(gCCW[i], &path); |
| 256 | REPORTER_ASSERT(reporter, valid); |
bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 257 | check_direction(&path, SkPath::kCCW_Direction, reporter); |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 258 | } |
reed@google.com | ac8543f | 2012-01-30 20:51:25 +0000 | [diff] [blame] | 259 | |
| 260 | // Test two donuts, each wound a different direction. Only the outer contour |
| 261 | // determines the cheap direction |
| 262 | path.reset(); |
| 263 | path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCW_Direction); |
| 264 | path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCCW_Direction); |
bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 265 | check_direction(&path, SkPath::kCW_Direction, reporter); |
| 266 | |
reed@google.com | ac8543f | 2012-01-30 20:51:25 +0000 | [diff] [blame] | 267 | path.reset(); |
| 268 | path.addCircle(0, 0, SkIntToScalar(1), SkPath::kCW_Direction); |
| 269 | path.addCircle(0, 0, SkIntToScalar(2), SkPath::kCCW_Direction); |
bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 270 | check_direction(&path, SkPath::kCCW_Direction, reporter); |
| 271 | |
bsalomon@google.com | 6843ac4 | 2012-02-17 13:49:03 +0000 | [diff] [blame] | 272 | #ifdef SK_SCALAR_IS_FLOAT |
bsalomon@google.com | f0ed80a | 2012-02-17 13:38:26 +0000 | [diff] [blame] | 273 | // triangle with one point really far from the origin. |
| 274 | path.reset(); |
| 275 | // the first point is roughly 1.05e10, 1.05e10 |
bsalomon@google.com | 53aab78 | 2012-02-23 14:54:49 +0000 | [diff] [blame] | 276 | path.moveTo(SkFloatToScalar(SkBits2Float(0x501c7652)), SkFloatToScalar(SkBits2Float(0x501c7652))); |
| 277 | path.lineTo(110 * SK_Scalar1, -10 * SK_Scalar1); |
| 278 | path.lineTo(-10 * SK_Scalar1, 60 * SK_Scalar1); |
| 279 | check_direction(&path, SkPath::kCCW_Direction, reporter); |
| 280 | #endif |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 281 | } |
| 282 | |
reed@google.com | ffdb018 | 2011-11-14 19:29:14 +0000 | [diff] [blame] | 283 | static void add_rect(SkPath* path, const SkRect& r) { |
| 284 | path->moveTo(r.fLeft, r.fTop); |
| 285 | path->lineTo(r.fRight, r.fTop); |
| 286 | path->lineTo(r.fRight, r.fBottom); |
| 287 | path->lineTo(r.fLeft, r.fBottom); |
| 288 | path->close(); |
| 289 | } |
| 290 | |
| 291 | static void test_bounds(skiatest::Reporter* reporter) { |
| 292 | static const SkRect rects[] = { |
reed@google.com | 3563c9e | 2011-11-14 19:34:57 +0000 | [diff] [blame] | 293 | { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(160) }, |
| 294 | { SkIntToScalar(610), SkIntToScalar(160), SkIntToScalar(610), SkIntToScalar(199) }, |
| 295 | { SkIntToScalar(10), SkIntToScalar(198), SkIntToScalar(610), SkIntToScalar(199) }, |
| 296 | { SkIntToScalar(10), SkIntToScalar(160), SkIntToScalar(10), SkIntToScalar(199) }, |
reed@google.com | ffdb018 | 2011-11-14 19:29:14 +0000 | [diff] [blame] | 297 | }; |
| 298 | |
| 299 | SkPath path0, path1; |
| 300 | for (size_t i = 0; i < SK_ARRAY_COUNT(rects); ++i) { |
| 301 | path0.addRect(rects[i]); |
| 302 | add_rect(&path1, rects[i]); |
| 303 | } |
| 304 | |
| 305 | REPORTER_ASSERT(reporter, path0.getBounds() == path1.getBounds()); |
| 306 | } |
| 307 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 308 | static void stroke_cubic(const SkPoint pts[4]) { |
| 309 | SkPath path; |
| 310 | path.moveTo(pts[0]); |
| 311 | path.cubicTo(pts[1], pts[2], pts[3]); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 312 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 313 | SkPaint paint; |
| 314 | paint.setStyle(SkPaint::kStroke_Style); |
| 315 | paint.setStrokeWidth(SK_Scalar1 * 2); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 316 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 317 | SkPath fill; |
| 318 | paint.getFillPath(path, &fill); |
| 319 | } |
| 320 | |
| 321 | // just ensure this can run w/o any SkASSERTS firing in the debug build |
| 322 | // we used to assert due to differences in how we determine a degenerate vector |
| 323 | // but that was fixed with the introduction of SkPoint::CanNormalize |
| 324 | static void stroke_tiny_cubic() { |
| 325 | SkPoint p0[] = { |
| 326 | { 372.0f, 92.0f }, |
| 327 | { 372.0f, 92.0f }, |
| 328 | { 372.0f, 92.0f }, |
| 329 | { 372.0f, 92.0f }, |
| 330 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 331 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 332 | stroke_cubic(p0); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 333 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 334 | SkPoint p1[] = { |
| 335 | { 372.0f, 92.0f }, |
| 336 | { 372.0007f, 92.000755f }, |
| 337 | { 371.99927f, 92.003922f }, |
| 338 | { 371.99826f, 92.003899f }, |
| 339 | }; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 340 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 341 | stroke_cubic(p1); |
| 342 | } |
| 343 | |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 344 | static void check_close(skiatest::Reporter* reporter, const SkPath& path) { |
| 345 | for (int i = 0; i < 2; ++i) { |
robertphillips@google.com | 09042b8 | 2012-04-06 20:01:46 +0000 | [diff] [blame] | 346 | SkPath::Iter iter(path, SkToBool(i)); |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 347 | SkPoint mv; |
| 348 | SkPoint pts[4]; |
| 349 | SkPath::Verb v; |
| 350 | int nMT = 0; |
| 351 | int nCL = 0; |
tomhudson@google.com | 221db3c | 2011-07-28 21:10:29 +0000 | [diff] [blame] | 352 | mv.set(0, 0); |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 353 | while (SkPath::kDone_Verb != (v = iter.next(pts))) { |
| 354 | switch (v) { |
| 355 | case SkPath::kMove_Verb: |
| 356 | mv = pts[0]; |
| 357 | ++nMT; |
| 358 | break; |
| 359 | case SkPath::kClose_Verb: |
| 360 | REPORTER_ASSERT(reporter, mv == pts[0]); |
| 361 | ++nCL; |
| 362 | break; |
| 363 | default: |
| 364 | break; |
| 365 | } |
| 366 | } |
| 367 | // if we force a close on the interator we should have a close |
| 368 | // for every moveTo |
| 369 | REPORTER_ASSERT(reporter, !i || nMT == nCL); |
| 370 | } |
| 371 | } |
| 372 | |
| 373 | static void test_close(skiatest::Reporter* reporter) { |
| 374 | SkPath closePt; |
| 375 | closePt.moveTo(0, 0); |
| 376 | closePt.close(); |
| 377 | check_close(reporter, closePt); |
| 378 | |
| 379 | SkPath openPt; |
| 380 | openPt.moveTo(0, 0); |
| 381 | check_close(reporter, openPt); |
| 382 | |
| 383 | SkPath empty; |
| 384 | check_close(reporter, empty); |
| 385 | empty.close(); |
| 386 | check_close(reporter, empty); |
| 387 | |
| 388 | SkPath rect; |
| 389 | rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 390 | check_close(reporter, rect); |
| 391 | rect.close(); |
| 392 | check_close(reporter, rect); |
| 393 | |
| 394 | SkPath quad; |
| 395 | quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 396 | check_close(reporter, quad); |
| 397 | quad.close(); |
| 398 | check_close(reporter, quad); |
| 399 | |
| 400 | SkPath cubic; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 401 | quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 402 | 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1); |
| 403 | check_close(reporter, cubic); |
| 404 | cubic.close(); |
| 405 | check_close(reporter, cubic); |
| 406 | |
| 407 | SkPath line; |
| 408 | line.moveTo(SK_Scalar1, SK_Scalar1); |
| 409 | line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1); |
| 410 | check_close(reporter, line); |
| 411 | line.close(); |
| 412 | check_close(reporter, line); |
| 413 | |
| 414 | SkPath rect2; |
| 415 | rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 416 | rect2.close(); |
| 417 | rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 418 | check_close(reporter, rect2); |
| 419 | rect2.close(); |
| 420 | check_close(reporter, rect2); |
| 421 | |
| 422 | SkPath oval3; |
| 423 | oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100)); |
| 424 | oval3.close(); |
| 425 | oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200)); |
| 426 | check_close(reporter, oval3); |
| 427 | oval3.close(); |
| 428 | check_close(reporter, oval3); |
| 429 | |
| 430 | SkPath moves; |
| 431 | moves.moveTo(SK_Scalar1, SK_Scalar1); |
| 432 | moves.moveTo(5 * SK_Scalar1, SK_Scalar1); |
| 433 | moves.moveTo(SK_Scalar1, 10 * SK_Scalar1); |
| 434 | moves.moveTo(10 *SK_Scalar1, SK_Scalar1); |
| 435 | check_close(reporter, moves); |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 436 | |
| 437 | stroke_tiny_cubic(); |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 438 | } |
| 439 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 440 | static void check_convexity(skiatest::Reporter* reporter, const SkPath& path, |
| 441 | SkPath::Convexity expected) { |
| 442 | SkPath::Convexity c = SkPath::ComputeConvexity(path); |
| 443 | REPORTER_ASSERT(reporter, c == expected); |
| 444 | } |
| 445 | |
| 446 | static void test_convexity2(skiatest::Reporter* reporter) { |
| 447 | SkPath pt; |
| 448 | pt.moveTo(0, 0); |
| 449 | pt.close(); |
reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 450 | check_convexity(reporter, pt, SkPath::kConvex_Convexity); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 451 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 452 | SkPath line; |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 453 | line.moveTo(12*SK_Scalar1, 20*SK_Scalar1); |
| 454 | line.lineTo(-12*SK_Scalar1, -20*SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 455 | line.close(); |
reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 456 | check_convexity(reporter, pt, SkPath::kConvex_Convexity); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 457 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 458 | SkPath triLeft; |
| 459 | triLeft.moveTo(0, 0); |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 460 | triLeft.lineTo(SK_Scalar1, 0); |
| 461 | triLeft.lineTo(SK_Scalar1, SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 462 | triLeft.close(); |
| 463 | check_convexity(reporter, triLeft, SkPath::kConvex_Convexity); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 464 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 465 | SkPath triRight; |
| 466 | triRight.moveTo(0, 0); |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 467 | triRight.lineTo(-SK_Scalar1, 0); |
| 468 | triRight.lineTo(SK_Scalar1, SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 469 | triRight.close(); |
| 470 | check_convexity(reporter, triRight, SkPath::kConvex_Convexity); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 471 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 472 | SkPath square; |
| 473 | square.moveTo(0, 0); |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 474 | square.lineTo(SK_Scalar1, 0); |
| 475 | square.lineTo(SK_Scalar1, SK_Scalar1); |
| 476 | square.lineTo(0, SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 477 | square.close(); |
| 478 | check_convexity(reporter, square, SkPath::kConvex_Convexity); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 479 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 480 | SkPath redundantSquare; |
| 481 | redundantSquare.moveTo(0, 0); |
| 482 | redundantSquare.lineTo(0, 0); |
| 483 | redundantSquare.lineTo(0, 0); |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 484 | redundantSquare.lineTo(SK_Scalar1, 0); |
| 485 | redundantSquare.lineTo(SK_Scalar1, 0); |
| 486 | redundantSquare.lineTo(SK_Scalar1, 0); |
| 487 | redundantSquare.lineTo(SK_Scalar1, SK_Scalar1); |
| 488 | redundantSquare.lineTo(SK_Scalar1, SK_Scalar1); |
| 489 | redundantSquare.lineTo(SK_Scalar1, SK_Scalar1); |
| 490 | redundantSquare.lineTo(0, SK_Scalar1); |
| 491 | redundantSquare.lineTo(0, SK_Scalar1); |
| 492 | redundantSquare.lineTo(0, SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 493 | redundantSquare.close(); |
| 494 | check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 495 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 496 | SkPath bowTie; |
| 497 | bowTie.moveTo(0, 0); |
| 498 | bowTie.lineTo(0, 0); |
| 499 | bowTie.lineTo(0, 0); |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 500 | bowTie.lineTo(SK_Scalar1, SK_Scalar1); |
| 501 | bowTie.lineTo(SK_Scalar1, SK_Scalar1); |
| 502 | bowTie.lineTo(SK_Scalar1, SK_Scalar1); |
| 503 | bowTie.lineTo(SK_Scalar1, 0); |
| 504 | bowTie.lineTo(SK_Scalar1, 0); |
| 505 | bowTie.lineTo(SK_Scalar1, 0); |
| 506 | bowTie.lineTo(0, SK_Scalar1); |
| 507 | bowTie.lineTo(0, SK_Scalar1); |
| 508 | bowTie.lineTo(0, SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 509 | bowTie.close(); |
| 510 | check_convexity(reporter, bowTie, SkPath::kConcave_Convexity); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 511 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 512 | SkPath spiral; |
| 513 | spiral.moveTo(0, 0); |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 514 | spiral.lineTo(100*SK_Scalar1, 0); |
| 515 | spiral.lineTo(100*SK_Scalar1, 100*SK_Scalar1); |
| 516 | spiral.lineTo(0, 100*SK_Scalar1); |
| 517 | spiral.lineTo(0, 50*SK_Scalar1); |
| 518 | spiral.lineTo(50*SK_Scalar1, 50*SK_Scalar1); |
| 519 | spiral.lineTo(50*SK_Scalar1, 75*SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 520 | spiral.close(); |
reed@google.com | 85b6e39 | 2011-05-15 20:25:17 +0000 | [diff] [blame] | 521 | check_convexity(reporter, spiral, SkPath::kConcave_Convexity); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 522 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 523 | SkPath dent; |
schenney@chromium.org | 6c31d9d | 2011-12-20 16:33:30 +0000 | [diff] [blame] | 524 | dent.moveTo(0, 0); |
| 525 | dent.lineTo(100*SK_Scalar1, 100*SK_Scalar1); |
| 526 | dent.lineTo(0, 100*SK_Scalar1); |
| 527 | dent.lineTo(-50*SK_Scalar1, 200*SK_Scalar1); |
| 528 | dent.lineTo(-200*SK_Scalar1, 100*SK_Scalar1); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 529 | dent.close(); |
| 530 | check_convexity(reporter, dent, SkPath::kConcave_Convexity); |
| 531 | } |
| 532 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 533 | static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p, |
| 534 | const SkRect& bounds) { |
| 535 | REPORTER_ASSERT(reporter, p.isConvex()); |
| 536 | REPORTER_ASSERT(reporter, p.getBounds() == bounds); |
reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 537 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 538 | SkPath p2(p); |
| 539 | REPORTER_ASSERT(reporter, p2.isConvex()); |
| 540 | REPORTER_ASSERT(reporter, p2.getBounds() == bounds); |
| 541 | |
| 542 | SkPath other; |
| 543 | other.swap(p2); |
| 544 | REPORTER_ASSERT(reporter, other.isConvex()); |
| 545 | REPORTER_ASSERT(reporter, other.getBounds() == bounds); |
| 546 | } |
| 547 | |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 548 | static void setFromString(SkPath* path, const char str[]) { |
| 549 | bool first = true; |
| 550 | while (str) { |
| 551 | SkScalar x, y; |
| 552 | str = SkParse::FindScalar(str, &x); |
| 553 | if (NULL == str) { |
| 554 | break; |
| 555 | } |
| 556 | str = SkParse::FindScalar(str, &y); |
| 557 | SkASSERT(str); |
| 558 | if (first) { |
| 559 | path->moveTo(x, y); |
| 560 | first = false; |
| 561 | } else { |
| 562 | path->lineTo(x, y); |
| 563 | } |
| 564 | } |
| 565 | } |
| 566 | |
| 567 | static void test_convexity(skiatest::Reporter* reporter) { |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 568 | static const SkPath::Convexity C = SkPath::kConcave_Convexity; |
| 569 | static const SkPath::Convexity V = SkPath::kConvex_Convexity; |
| 570 | |
| 571 | SkPath path; |
| 572 | |
reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 573 | REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path)); |
reed@google.com | e354397 | 2012-01-10 18:59:22 +0000 | [diff] [blame] | 574 | path.addCircle(0, 0, SkIntToScalar(10)); |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 575 | REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path)); |
reed@google.com | e354397 | 2012-01-10 18:59:22 +0000 | [diff] [blame] | 576 | path.addCircle(0, 0, SkIntToScalar(10)); // 2nd circle |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 577 | REPORTER_ASSERT(reporter, C == SkPath::ComputeConvexity(path)); |
| 578 | path.reset(); |
reed@google.com | e354397 | 2012-01-10 18:59:22 +0000 | [diff] [blame] | 579 | path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCCW_Direction); |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 580 | REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path)); |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 581 | REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCCW_Direction)); |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 582 | path.reset(); |
reed@google.com | e354397 | 2012-01-10 18:59:22 +0000 | [diff] [blame] | 583 | path.addRect(0, 0, SkIntToScalar(10), SkIntToScalar(10), SkPath::kCW_Direction); |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 584 | REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path)); |
reed@google.com | 3e71a88 | 2012-01-10 18:44:37 +0000 | [diff] [blame] | 585 | REPORTER_ASSERT(reporter, path.cheapIsDirection(SkPath::kCW_Direction)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 586 | |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 587 | static const struct { |
| 588 | const char* fPathStr; |
| 589 | SkPath::Convexity fExpectedConvexity; |
| 590 | } gRec[] = { |
reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 591 | { "", SkPath::kConvex_Convexity }, |
| 592 | { "0 0", SkPath::kConvex_Convexity }, |
| 593 | { "0 0 10 10", SkPath::kConvex_Convexity }, |
reed@google.com | 85b6e39 | 2011-05-15 20:25:17 +0000 | [diff] [blame] | 594 | { "0 0 10 10 20 20 0 0 10 10", SkPath::kConcave_Convexity }, |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 595 | { "0 0 10 10 10 20", SkPath::kConvex_Convexity }, |
| 596 | { "0 0 10 10 10 0", SkPath::kConvex_Convexity }, |
| 597 | { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity }, |
| 598 | { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity }, |
| 599 | }; |
| 600 | |
| 601 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 602 | SkPath path; |
| 603 | setFromString(&path, gRec[i].fPathStr); |
| 604 | SkPath::Convexity c = SkPath::ComputeConvexity(path); |
| 605 | REPORTER_ASSERT(reporter, c == gRec[i].fExpectedConvexity); |
| 606 | } |
| 607 | } |
| 608 | |
reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 609 | static void test_isLine(skiatest::Reporter* reporter) { |
| 610 | SkPath path; |
| 611 | SkPoint pts[2]; |
| 612 | const SkScalar value = SkIntToScalar(5); |
| 613 | |
| 614 | REPORTER_ASSERT(reporter, !path.isLine(NULL)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 615 | |
reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 616 | // set some non-zero values |
| 617 | pts[0].set(value, value); |
| 618 | pts[1].set(value, value); |
| 619 | REPORTER_ASSERT(reporter, !path.isLine(pts)); |
| 620 | // check that pts was untouched |
| 621 | REPORTER_ASSERT(reporter, pts[0].equals(value, value)); |
| 622 | REPORTER_ASSERT(reporter, pts[1].equals(value, value)); |
| 623 | |
| 624 | const SkScalar moveX = SkIntToScalar(1); |
| 625 | const SkScalar moveY = SkIntToScalar(2); |
| 626 | SkASSERT(value != moveX && value != moveY); |
| 627 | |
| 628 | path.moveTo(moveX, moveY); |
| 629 | REPORTER_ASSERT(reporter, !path.isLine(NULL)); |
| 630 | REPORTER_ASSERT(reporter, !path.isLine(pts)); |
| 631 | // check that pts was untouched |
| 632 | REPORTER_ASSERT(reporter, pts[0].equals(value, value)); |
| 633 | REPORTER_ASSERT(reporter, pts[1].equals(value, value)); |
| 634 | |
| 635 | const SkScalar lineX = SkIntToScalar(2); |
| 636 | const SkScalar lineY = SkIntToScalar(2); |
| 637 | SkASSERT(value != lineX && value != lineY); |
| 638 | |
| 639 | path.lineTo(lineX, lineY); |
| 640 | REPORTER_ASSERT(reporter, path.isLine(NULL)); |
| 641 | |
| 642 | REPORTER_ASSERT(reporter, !pts[0].equals(moveX, moveY)); |
| 643 | REPORTER_ASSERT(reporter, !pts[1].equals(lineX, lineY)); |
| 644 | REPORTER_ASSERT(reporter, path.isLine(pts)); |
| 645 | REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY)); |
| 646 | REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY)); |
| 647 | |
| 648 | path.lineTo(0, 0); // too many points/verbs |
| 649 | REPORTER_ASSERT(reporter, !path.isLine(NULL)); |
| 650 | REPORTER_ASSERT(reporter, !path.isLine(pts)); |
| 651 | REPORTER_ASSERT(reporter, pts[0].equals(moveX, moveY)); |
| 652 | REPORTER_ASSERT(reporter, pts[1].equals(lineX, lineY)); |
| 653 | } |
| 654 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 655 | // Simple isRect test is inline TestPath, below. |
| 656 | // test_isRect provides more extensive testing. |
| 657 | static void test_isRect(skiatest::Reporter* reporter) { |
| 658 | // passing tests (all moveTo / lineTo... |
| 659 | SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; |
| 660 | SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
| 661 | SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}}; |
| 662 | SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}}; |
| 663 | SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; |
| 664 | SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| 665 | SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}}; |
| 666 | SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}}; |
| 667 | SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| 668 | SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, |
| 669 | {1, 0}, {.5f, 0}}; |
| 670 | SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, |
| 671 | {0, 1}, {0, .5f}}; |
| 672 | SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
| 673 | SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| 674 | SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 675 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 676 | // failing tests |
| 677 | SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points |
| 678 | SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal |
| 679 | SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps |
| 680 | SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up |
| 681 | SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots |
| 682 | SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots |
| 683 | SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots |
| 684 | SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L' |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 685 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 686 | // failing, no close |
| 687 | SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match |
| 688 | SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto |
| 689 | |
| 690 | size_t testLen[] = { |
| 691 | sizeof(r1), sizeof(r2), sizeof(r3), sizeof(r4), sizeof(r5), sizeof(r6), |
| 692 | sizeof(r7), sizeof(r8), sizeof(r9), sizeof(ra), sizeof(rb), sizeof(rc), |
| 693 | sizeof(rd), sizeof(re), |
| 694 | sizeof(f1), sizeof(f2), sizeof(f3), sizeof(f4), sizeof(f5), sizeof(f6), |
| 695 | sizeof(f7), sizeof(f8), |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 696 | sizeof(c1), sizeof(c2) |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 697 | }; |
| 698 | SkPoint* tests[] = { |
| 699 | r1, r2, r3, r4, r5, r6, r7, r8, r9, ra, rb, rc, rd, re, |
| 700 | f1, f2, f3, f4, f5, f6, f7, f8, |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 701 | c1, c2 |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 702 | }; |
| 703 | SkPoint* lastPass = re; |
| 704 | SkPoint* lastClose = f8; |
| 705 | bool fail = false; |
| 706 | bool close = true; |
| 707 | const size_t testCount = sizeof(tests) / sizeof(tests[0]); |
| 708 | size_t index; |
| 709 | for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { |
| 710 | SkPath path; |
| 711 | path.moveTo(tests[testIndex][0].fX, tests[testIndex][0].fY); |
| 712 | for (index = 1; index < testLen[testIndex] / sizeof(SkPoint); ++index) { |
| 713 | path.lineTo(tests[testIndex][index].fX, tests[testIndex][index].fY); |
| 714 | } |
| 715 | if (close) { |
| 716 | path.close(); |
| 717 | } |
| 718 | REPORTER_ASSERT(reporter, fail ^ path.isRect(0)); |
| 719 | if (tests[testIndex] == lastPass) { |
| 720 | fail = true; |
| 721 | } |
| 722 | if (tests[testIndex] == lastClose) { |
| 723 | close = false; |
| 724 | } |
| 725 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 726 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 727 | // fail, close then line |
| 728 | SkPath path1; |
| 729 | path1.moveTo(r1[0].fX, r1[0].fY); |
| 730 | for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 731 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 732 | } |
| 733 | path1.close(); |
| 734 | path1.lineTo(1, 0); |
| 735 | REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 736 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 737 | // fail, move in the middle |
| 738 | path1.reset(); |
| 739 | path1.moveTo(r1[0].fX, r1[0].fY); |
| 740 | for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 741 | if (index == 2) { |
| 742 | path1.moveTo(1, .5f); |
| 743 | } |
| 744 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 745 | } |
| 746 | path1.close(); |
| 747 | REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); |
| 748 | |
| 749 | // fail, move on the edge |
| 750 | path1.reset(); |
| 751 | for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 752 | path1.moveTo(r1[index - 1].fX, r1[index - 1].fY); |
| 753 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 754 | } |
| 755 | path1.close(); |
| 756 | REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 757 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 758 | // fail, quad |
| 759 | path1.reset(); |
| 760 | path1.moveTo(r1[0].fX, r1[0].fY); |
| 761 | for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 762 | if (index == 2) { |
| 763 | path1.quadTo(1, .5f, 1, .5f); |
| 764 | } |
| 765 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 766 | } |
| 767 | path1.close(); |
| 768 | REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 769 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 770 | // fail, cubic |
| 771 | path1.reset(); |
| 772 | path1.moveTo(r1[0].fX, r1[0].fY); |
| 773 | for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 774 | if (index == 2) { |
| 775 | path1.cubicTo(1, .5f, 1, .5f, 1, .5f); |
| 776 | } |
| 777 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 778 | } |
| 779 | path1.close(); |
| 780 | REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); |
| 781 | } |
| 782 | |
robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 783 | static void write_and_read_back(skiatest::Reporter* reporter, |
| 784 | const SkPath& p) { |
| 785 | SkWriter32 writer(100); |
| 786 | writer.writePath(p); |
| 787 | size_t size = writer.size(); |
| 788 | SkAutoMalloc storage(size); |
| 789 | writer.flatten(storage.get()); |
| 790 | SkReader32 reader(storage.get(), size); |
| 791 | |
| 792 | SkPath readBack; |
| 793 | REPORTER_ASSERT(reporter, readBack != p); |
| 794 | reader.readPath(&readBack); |
| 795 | REPORTER_ASSERT(reporter, readBack == p); |
| 796 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 797 | REPORTER_ASSERT(reporter, readBack.getConvexityOrUnknown() == |
robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 798 | p.getConvexityOrUnknown()); |
| 799 | |
| 800 | REPORTER_ASSERT(reporter, readBack.isOval(NULL) == p.isOval(NULL)); |
| 801 | |
| 802 | const SkRect& origBounds = p.getBounds(); |
| 803 | const SkRect& readBackBounds = readBack.getBounds(); |
| 804 | |
| 805 | REPORTER_ASSERT(reporter, origBounds == readBackBounds); |
| 806 | } |
| 807 | |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 808 | static void test_flattening(skiatest::Reporter* reporter) { |
| 809 | SkPath p; |
| 810 | |
| 811 | static const SkPoint pts[] = { |
| 812 | { 0, 0 }, |
| 813 | { SkIntToScalar(10), SkIntToScalar(10) }, |
| 814 | { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, |
| 815 | { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) } |
| 816 | }; |
| 817 | p.moveTo(pts[0]); |
| 818 | p.lineTo(pts[1]); |
| 819 | p.quadTo(pts[2], pts[3]); |
| 820 | p.cubicTo(pts[4], pts[5], pts[6]); |
| 821 | |
robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 822 | write_and_read_back(reporter, p); |
djsollen@google.com | 94e75ee | 2012-06-08 18:30:46 +0000 | [diff] [blame] | 823 | |
| 824 | // create a buffer that should be much larger than the path so we don't |
| 825 | // kill our stack if writer goes too far. |
| 826 | char buffer[1024]; |
| 827 | uint32_t size1 = p.writeToMemory(NULL); |
| 828 | uint32_t size2 = p.writeToMemory(buffer); |
| 829 | REPORTER_ASSERT(reporter, size1 == size2); |
| 830 | |
| 831 | SkPath p2; |
| 832 | uint32_t size3 = p2.readFromMemory(buffer); |
| 833 | REPORTER_ASSERT(reporter, size1 == size3); |
| 834 | REPORTER_ASSERT(reporter, p == p2); |
| 835 | |
| 836 | char buffer2[1024]; |
| 837 | size3 = p2.writeToMemory(buffer2); |
| 838 | REPORTER_ASSERT(reporter, size1 == size3); |
| 839 | REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0); |
robertphillips@google.com | 2972bb5 | 2012-08-07 17:32:51 +0000 | [diff] [blame] | 840 | |
| 841 | // test persistence of the oval flag & convexity |
| 842 | { |
| 843 | SkPath oval; |
| 844 | SkRect rect = SkRect::MakeWH(10, 10); |
| 845 | oval.addOval(rect); |
| 846 | |
| 847 | write_and_read_back(reporter, oval); |
| 848 | } |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static void test_transform(skiatest::Reporter* reporter) { |
| 852 | SkPath p, p1; |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 853 | |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 854 | static const SkPoint pts[] = { |
| 855 | { 0, 0 }, |
| 856 | { SkIntToScalar(10), SkIntToScalar(10) }, |
| 857 | { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, |
| 858 | { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10) } |
| 859 | }; |
| 860 | p.moveTo(pts[0]); |
| 861 | p.lineTo(pts[1]); |
| 862 | p.quadTo(pts[2], pts[3]); |
| 863 | p.cubicTo(pts[4], pts[5], pts[6]); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 864 | |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 865 | SkMatrix matrix; |
| 866 | matrix.reset(); |
| 867 | p.transform(matrix, &p1); |
| 868 | REPORTER_ASSERT(reporter, p == p1); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 869 | |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 870 | matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3); |
| 871 | p.transform(matrix, &p1); |
| 872 | SkPoint pts1[7]; |
| 873 | int count = p1.getPoints(pts1, 7); |
| 874 | REPORTER_ASSERT(reporter, 7 == count); |
| 875 | for (int i = 0; i < count; ++i) { |
| 876 | SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3); |
| 877 | REPORTER_ASSERT(reporter, newPt == pts1[i]); |
| 878 | } |
| 879 | } |
| 880 | |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 881 | static void test_zero_length_paths(skiatest::Reporter* reporter) { |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 882 | SkPath p; |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 883 | uint8_t verbs[32]; |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 884 | |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 885 | struct zeroPathTestData { |
| 886 | const char* testPath; |
| 887 | const size_t numResultPts; |
| 888 | const SkRect resultBound; |
| 889 | const SkPath::Verb* resultVerbs; |
| 890 | const size_t numResultVerbs; |
| 891 | }; |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 892 | |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 893 | static const SkPath::Verb resultVerbs1[] = { SkPath::kMove_Verb }; |
| 894 | static const SkPath::Verb resultVerbs2[] = { SkPath::kMove_Verb, SkPath::kMove_Verb }; |
| 895 | static const SkPath::Verb resultVerbs3[] = { SkPath::kMove_Verb, SkPath::kClose_Verb }; |
| 896 | static const SkPath::Verb resultVerbs4[] = { SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb }; |
| 897 | static const SkPath::Verb resultVerbs5[] = { SkPath::kMove_Verb, SkPath::kLine_Verb }; |
| 898 | static const SkPath::Verb resultVerbs6[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb }; |
| 899 | static const SkPath::Verb resultVerbs7[] = { SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb }; |
| 900 | static const SkPath::Verb resultVerbs8[] = { |
| 901 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb |
| 902 | }; |
| 903 | static const SkPath::Verb resultVerbs9[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb }; |
| 904 | static const SkPath::Verb resultVerbs10[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb }; |
| 905 | static const SkPath::Verb resultVerbs11[] = { SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb }; |
| 906 | static const SkPath::Verb resultVerbs12[] = { |
| 907 | SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kQuad_Verb, SkPath::kClose_Verb |
| 908 | }; |
| 909 | static const SkPath::Verb resultVerbs13[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb }; |
| 910 | static const SkPath::Verb resultVerbs14[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb }; |
| 911 | static const SkPath::Verb resultVerbs15[] = { SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb }; |
| 912 | static const SkPath::Verb resultVerbs16[] = { |
| 913 | SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kCubic_Verb, SkPath::kClose_Verb |
| 914 | }; |
| 915 | static const struct zeroPathTestData gZeroLengthTests[] = { |
| 916 | { "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] | 917 | { "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] | 918 | { "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] | 919 | { "M 1 1 z M 2 1 z", 2, {SK_Scalar1, SK_Scalar1, 2*SK_Scalar1, SK_Scalar1}, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) }, |
| 920 | { "M 1 1 L 1 1", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs5, SK_ARRAY_COUNT(resultVerbs5) }, |
| 921 | { "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) }, |
| 922 | { "M 1 1 L 1 1 z", 2, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs7, SK_ARRAY_COUNT(resultVerbs7) }, |
| 923 | { "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) }, |
| 924 | { "M 1 1 Q 1 1 1 1", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs9, SK_ARRAY_COUNT(resultVerbs9) }, |
| 925 | { "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) }, |
| 926 | { "M 1 1 Q 1 1 1 1 z", 3, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs11, SK_ARRAY_COUNT(resultVerbs11) }, |
| 927 | { "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) }, |
| 928 | { "M 1 1 C 1 1 1 1 1 1", 4, {SK_Scalar1, SK_Scalar1, SK_Scalar1, SK_Scalar1}, resultVerbs13, SK_ARRAY_COUNT(resultVerbs13) }, |
| 929 | { "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] | 930 | SK_ARRAY_COUNT(resultVerbs14) |
| 931 | }, |
schenney@chromium.org | aaf1688 | 2012-06-13 17:41:00 +0000 | [diff] [blame] | 932 | { "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) }, |
| 933 | { "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] | 934 | SK_ARRAY_COUNT(resultVerbs16) |
| 935 | } |
| 936 | }; |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 937 | |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 938 | for (size_t i = 0; i < SK_ARRAY_COUNT(gZeroLengthTests); ++i) { |
| 939 | p.reset(); |
| 940 | bool valid = SkParsePath::FromSVGString(gZeroLengthTests[i].testPath, &p); |
| 941 | REPORTER_ASSERT(reporter, valid); |
| 942 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
| 943 | REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultPts == (size_t)p.countPoints()); |
| 944 | REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultBound == p.getBounds()); |
| 945 | REPORTER_ASSERT(reporter, gZeroLengthTests[i].numResultVerbs == (size_t)p.getVerbs(verbs, SK_ARRAY_COUNT(verbs))); |
| 946 | for (size_t j = 0; j < gZeroLengthTests[i].numResultVerbs; ++j) { |
| 947 | REPORTER_ASSERT(reporter, gZeroLengthTests[i].resultVerbs[j] == verbs[j]); |
| 948 | } |
bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 949 | } |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 950 | } |
| 951 | |
| 952 | struct SegmentInfo { |
| 953 | SkPath fPath; |
| 954 | int fPointCount; |
| 955 | }; |
| 956 | |
reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 957 | #define kCurveSegmentMask (SkPath::kQuad_SegmentMask | SkPath::kCubic_SegmentMask) |
| 958 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 959 | static void test_segment_masks(skiatest::Reporter* reporter) { |
reed@google.com | eef938c | 2012-08-01 20:01:49 +0000 | [diff] [blame] | 960 | SkPath p, p2; |
| 961 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 962 | p.moveTo(0, 0); |
| 963 | p.quadTo(100, 100, 200, 200); |
| 964 | REPORTER_ASSERT(reporter, SkPath::kQuad_SegmentMask == p.getSegmentMasks()); |
| 965 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
reed@google.com | eef938c | 2012-08-01 20:01:49 +0000 | [diff] [blame] | 966 | p2 = p; |
| 967 | REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks()); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 968 | p.cubicTo(100, 100, 200, 200, 300, 300); |
| 969 | REPORTER_ASSERT(reporter, kCurveSegmentMask == p.getSegmentMasks()); |
| 970 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
reed@google.com | eef938c | 2012-08-01 20:01:49 +0000 | [diff] [blame] | 971 | p2 = p; |
| 972 | REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks()); |
| 973 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 974 | p.reset(); |
| 975 | p.moveTo(0, 0); |
| 976 | p.cubicTo(100, 100, 200, 200, 300, 300); |
| 977 | REPORTER_ASSERT(reporter, SkPath::kCubic_SegmentMask == p.getSegmentMasks()); |
reed@google.com | eef938c | 2012-08-01 20:01:49 +0000 | [diff] [blame] | 978 | p2 = p; |
| 979 | REPORTER_ASSERT(reporter, p2.getSegmentMasks() == p.getSegmentMasks()); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 980 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 981 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
| 982 | } |
| 983 | |
| 984 | static void test_iter(skiatest::Reporter* reporter) { |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 985 | SkPath p; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 986 | SkPoint pts[4]; |
| 987 | |
| 988 | // Test an iterator with no path |
| 989 | SkPath::Iter noPathIter; |
| 990 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 991 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 992 | // Test that setting an empty path works |
| 993 | noPathIter.setPath(p, false); |
| 994 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 995 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 996 | // Test that close path makes no difference for an empty path |
| 997 | noPathIter.setPath(p, true); |
| 998 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 999 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1000 | // Test an iterator with an initial empty path |
| 1001 | SkPath::Iter iter(p, false); |
| 1002 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 1003 | |
| 1004 | // Test that close path makes no difference |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1005 | iter.setPath(p, true); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1006 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 1007 | |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1008 | |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1009 | struct iterTestData { |
| 1010 | const char* testPath; |
| 1011 | const bool forceClose; |
| 1012 | const bool consumeDegenerates; |
| 1013 | const size_t* numResultPtsPerVerb; |
| 1014 | const SkPoint* resultPts; |
| 1015 | const SkPath::Verb* resultVerbs; |
| 1016 | const size_t numResultVerbs; |
| 1017 | }; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1018 | |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1019 | static const SkPath::Verb resultVerbs1[] = { SkPath::kDone_Verb }; |
| 1020 | static const SkPath::Verb resultVerbs2[] = { |
| 1021 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kDone_Verb |
| 1022 | }; |
| 1023 | static const SkPath::Verb resultVerbs3[] = { |
| 1024 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb |
| 1025 | }; |
| 1026 | static const SkPath::Verb resultVerbs4[] = { |
| 1027 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb |
| 1028 | }; |
| 1029 | static const SkPath::Verb resultVerbs5[] = { |
| 1030 | SkPath::kMove_Verb, SkPath::kLine_Verb, SkPath::kClose_Verb, SkPath::kMove_Verb, SkPath::kClose_Verb, SkPath::kDone_Verb |
| 1031 | }; |
| 1032 | static const size_t resultPtsSizes1[] = { 0 }; |
schenney@chromium.org | fedd09b | 2012-06-13 18:29:20 +0000 | [diff] [blame] | 1033 | static const size_t resultPtsSizes2[] = { 1, 2, 2, 0 }; |
| 1034 | static const size_t resultPtsSizes3[] = { 1, 2, 2, 2, 1, 0 }; |
| 1035 | static const size_t resultPtsSizes4[] = { 1, 2, 1, 1, 0 }; |
| 1036 | static const size_t resultPtsSizes5[] = { 1, 2, 1, 1, 1, 0 }; |
schenney@chromium.org | aaf1688 | 2012-06-13 17:41:00 +0000 | [diff] [blame] | 1037 | static const SkPoint* resultPts1 = 0; |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1038 | static const SkPoint resultPts2[] = { |
| 1039 | { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 } |
| 1040 | }; |
| 1041 | static const SkPoint resultPts3[] = { |
| 1042 | { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, SK_Scalar1 }, { SK_Scalar1, SK_Scalar1 }, { 0, SK_Scalar1 }, |
| 1043 | { 0, SK_Scalar1 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 } |
| 1044 | }; |
| 1045 | static const SkPoint resultPts4[] = { |
| 1046 | { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 } |
| 1047 | }; |
| 1048 | static const SkPoint resultPts5[] = { |
| 1049 | { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { SK_Scalar1, 0 }, { 0, 0 }, { 0, 0 } |
| 1050 | }; |
| 1051 | static const struct iterTestData gIterTests[] = { |
| 1052 | { "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] | 1053 | { "M 1 0 M 2 0 M 3 0 M 4 0 M 5 0", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 1054 | { "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] | 1055 | { "z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 1056 | { "z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 1057 | { "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) }, |
| 1058 | { "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] | 1059 | { "M 1 0 L 1 1 L 0 1 M 0 0 z", false, true, resultPtsSizes2, resultPts2, resultVerbs2, SK_ARRAY_COUNT(resultVerbs2) }, |
| 1060 | { "M 1 0 L 1 1 L 0 1 M 0 0 z", true, true, resultPtsSizes3, resultPts3, resultVerbs3, SK_ARRAY_COUNT(resultVerbs3) }, |
| 1061 | { "M 1 0 L 1 0 M 0 0 z", false, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 1062 | { "M 1 0 L 1 0 M 0 0 z", true, true, resultPtsSizes1, resultPts1, resultVerbs1, SK_ARRAY_COUNT(resultVerbs1) }, |
| 1063 | { "M 1 0 L 1 0 M 0 0 z", false, false, resultPtsSizes4, resultPts4, resultVerbs4, SK_ARRAY_COUNT(resultVerbs4) }, |
| 1064 | { "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] | 1065 | }; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1066 | |
schenney@chromium.org | 7e96360 | 2012-06-13 17:05:43 +0000 | [diff] [blame] | 1067 | for (size_t i = 0; i < SK_ARRAY_COUNT(gIterTests); ++i) { |
| 1068 | p.reset(); |
| 1069 | bool valid = SkParsePath::FromSVGString(gIterTests[i].testPath, &p); |
| 1070 | REPORTER_ASSERT(reporter, valid); |
| 1071 | iter.setPath(p, gIterTests[i].forceClose); |
| 1072 | int j = 0, l = 0; |
| 1073 | do { |
| 1074 | REPORTER_ASSERT(reporter, iter.next(pts, gIterTests[i].consumeDegenerates) == gIterTests[i].resultVerbs[j]); |
| 1075 | for (int k = 0; k < (int)gIterTests[i].numResultPtsPerVerb[j]; ++k) { |
| 1076 | REPORTER_ASSERT(reporter, pts[k] == gIterTests[i].resultPts[l++]); |
| 1077 | } |
| 1078 | } while (gIterTests[i].resultVerbs[j++] != SkPath::kDone_Verb); |
| 1079 | REPORTER_ASSERT(reporter, j == (int)gIterTests[i].numResultVerbs); |
| 1080 | } |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1081 | |
| 1082 | // The GM degeneratesegments.cpp test is more extensive |
| 1083 | } |
| 1084 | |
| 1085 | static void test_raw_iter(skiatest::Reporter* reporter) { |
| 1086 | SkPath p; |
| 1087 | SkPoint pts[4]; |
| 1088 | |
| 1089 | // Test an iterator with no path |
| 1090 | SkPath::RawIter noPathIter; |
| 1091 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
| 1092 | // Test that setting an empty path works |
| 1093 | noPathIter.setPath(p); |
| 1094 | REPORTER_ASSERT(reporter, noPathIter.next(pts) == SkPath::kDone_Verb); |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1095 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1096 | // Test an iterator with an initial empty path |
| 1097 | SkPath::RawIter iter(p); |
| 1098 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 1099 | |
| 1100 | // Test that a move-only path returns the move. |
| 1101 | p.moveTo(SK_Scalar1, 0); |
| 1102 | iter.setPath(p); |
| 1103 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 1104 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1); |
| 1105 | REPORTER_ASSERT(reporter, pts[0].fY == 0); |
| 1106 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 1107 | |
| 1108 | // No matter how many moves we add, we should get them all back |
| 1109 | p.moveTo(SK_Scalar1*2, SK_Scalar1); |
| 1110 | p.moveTo(SK_Scalar1*3, SK_Scalar1*2); |
| 1111 | iter.setPath(p); |
| 1112 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 1113 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1); |
| 1114 | REPORTER_ASSERT(reporter, pts[0].fY == 0); |
| 1115 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 1116 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2); |
| 1117 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1); |
| 1118 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 1119 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3); |
| 1120 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2); |
| 1121 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 1122 | |
| 1123 | // Initial close is never ever stored |
| 1124 | p.reset(); |
| 1125 | p.close(); |
| 1126 | iter.setPath(p); |
| 1127 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 1128 | |
| 1129 | // Move/close sequences |
| 1130 | p.reset(); |
| 1131 | p.close(); // Not stored, no purpose |
| 1132 | p.moveTo(SK_Scalar1, 0); |
| 1133 | p.close(); |
| 1134 | p.close(); // Not stored, no purpose |
| 1135 | p.moveTo(SK_Scalar1*2, SK_Scalar1); |
| 1136 | p.close(); |
| 1137 | p.moveTo(SK_Scalar1*3, SK_Scalar1*2); |
| 1138 | p.moveTo(SK_Scalar1*4, SK_Scalar1*3); |
| 1139 | p.close(); |
| 1140 | iter.setPath(p); |
| 1141 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 1142 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1); |
| 1143 | REPORTER_ASSERT(reporter, pts[0].fY == 0); |
| 1144 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb); |
| 1145 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1); |
| 1146 | REPORTER_ASSERT(reporter, pts[0].fY == 0); |
| 1147 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 1148 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2); |
| 1149 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1); |
| 1150 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb); |
| 1151 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*2); |
| 1152 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1); |
| 1153 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 1154 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*3); |
| 1155 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*2); |
| 1156 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kMove_Verb); |
| 1157 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4); |
| 1158 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3); |
| 1159 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kClose_Verb); |
| 1160 | REPORTER_ASSERT(reporter, pts[0].fX == SK_Scalar1*4); |
| 1161 | REPORTER_ASSERT(reporter, pts[0].fY == SK_Scalar1*3); |
| 1162 | REPORTER_ASSERT(reporter, iter.next(pts) == SkPath::kDone_Verb); |
| 1163 | |
| 1164 | // Generate random paths and verify |
| 1165 | SkPoint randomPts[25]; |
| 1166 | for (int i = 0; i < 5; ++i) { |
| 1167 | for (int j = 0; j < 5; ++j) { |
| 1168 | randomPts[i*5+j].set(SK_Scalar1*i, SK_Scalar1*j); |
| 1169 | } |
| 1170 | } |
| 1171 | |
| 1172 | // Max of 10 segments, max 3 points per segment |
| 1173 | SkRandom rand(9876543); |
| 1174 | SkPoint expectedPts[31]; // May have leading moveTo |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 1175 | SkPath::Verb expectedVerbs[22]; // May have leading moveTo |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1176 | SkPath::Verb nextVerb; |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 1177 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1178 | for (int i = 0; i < 500; ++i) { |
| 1179 | p.reset(); |
| 1180 | bool lastWasClose = true; |
| 1181 | bool haveMoveTo = false; |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 1182 | SkPoint lastMoveToPt = { 0, 0 }; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1183 | int numPoints = 0; |
| 1184 | int numVerbs = (rand.nextU() >> 16) % 10; |
| 1185 | int numIterVerbs = 0; |
| 1186 | for (int j = 0; j < numVerbs; ++j) { |
| 1187 | do { |
| 1188 | nextVerb = static_cast<SkPath::Verb>((rand.nextU() >> 16) % SkPath::kDone_Verb); |
| 1189 | } while (lastWasClose && nextVerb == SkPath::kClose_Verb); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1190 | switch (nextVerb) { |
| 1191 | case SkPath::kMove_Verb: |
| 1192 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 1193 | p.moveTo(expectedPts[numPoints]); |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 1194 | lastMoveToPt = expectedPts[numPoints]; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1195 | numPoints += 1; |
| 1196 | lastWasClose = false; |
| 1197 | haveMoveTo = true; |
| 1198 | break; |
| 1199 | case SkPath::kLine_Verb: |
| 1200 | if (!haveMoveTo) { |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 1201 | expectedPts[numPoints++] = lastMoveToPt; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1202 | expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; |
| 1203 | haveMoveTo = true; |
| 1204 | } |
| 1205 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 1206 | p.lineTo(expectedPts[numPoints]); |
| 1207 | numPoints += 1; |
| 1208 | lastWasClose = false; |
| 1209 | break; |
| 1210 | case SkPath::kQuad_Verb: |
| 1211 | if (!haveMoveTo) { |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 1212 | expectedPts[numPoints++] = lastMoveToPt; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1213 | expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; |
| 1214 | haveMoveTo = true; |
| 1215 | } |
| 1216 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 1217 | expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25]; |
| 1218 | p.quadTo(expectedPts[numPoints], expectedPts[numPoints + 1]); |
| 1219 | numPoints += 2; |
| 1220 | lastWasClose = false; |
| 1221 | break; |
| 1222 | case SkPath::kCubic_Verb: |
| 1223 | if (!haveMoveTo) { |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 1224 | expectedPts[numPoints++] = lastMoveToPt; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1225 | expectedVerbs[numIterVerbs++] = SkPath::kMove_Verb; |
| 1226 | haveMoveTo = true; |
| 1227 | } |
| 1228 | expectedPts[numPoints] = randomPts[(rand.nextU() >> 16) % 25]; |
| 1229 | expectedPts[numPoints + 1] = randomPts[(rand.nextU() >> 16) % 25]; |
| 1230 | expectedPts[numPoints + 2] = randomPts[(rand.nextU() >> 16) % 25]; |
| 1231 | p.cubicTo(expectedPts[numPoints], expectedPts[numPoints + 1], |
| 1232 | expectedPts[numPoints + 2]); |
| 1233 | numPoints += 3; |
| 1234 | lastWasClose = false; |
| 1235 | break; |
| 1236 | case SkPath::kClose_Verb: |
| 1237 | p.close(); |
reed@google.com | d335d1d | 2012-01-12 18:17:11 +0000 | [diff] [blame] | 1238 | haveMoveTo = false; |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1239 | lastWasClose = true; |
| 1240 | break; |
| 1241 | default:; |
| 1242 | } |
| 1243 | expectedVerbs[numIterVerbs++] = nextVerb; |
| 1244 | } |
rmistry@google.com | d6176b0 | 2012-08-23 18:14:13 +0000 | [diff] [blame] | 1245 | |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1246 | iter.setPath(p); |
| 1247 | numVerbs = numIterVerbs; |
| 1248 | numIterVerbs = 0; |
| 1249 | int numIterPts = 0; |
| 1250 | SkPoint lastMoveTo; |
| 1251 | SkPoint lastPt; |
| 1252 | lastMoveTo.set(0, 0); |
| 1253 | lastPt.set(0, 0); |
| 1254 | while ((nextVerb = iter.next(pts)) != SkPath::kDone_Verb) { |
| 1255 | REPORTER_ASSERT(reporter, nextVerb == expectedVerbs[numIterVerbs]); |
| 1256 | numIterVerbs++; |
| 1257 | switch (nextVerb) { |
| 1258 | case SkPath::kMove_Verb: |
| 1259 | REPORTER_ASSERT(reporter, numIterPts < numPoints); |
| 1260 | REPORTER_ASSERT(reporter, pts[0] == expectedPts[numIterPts]); |
| 1261 | lastPt = lastMoveTo = pts[0]; |
| 1262 | numIterPts += 1; |
| 1263 | break; |
| 1264 | case SkPath::kLine_Verb: |
| 1265 | REPORTER_ASSERT(reporter, numIterPts < numPoints + 1); |
| 1266 | REPORTER_ASSERT(reporter, pts[0] == lastPt); |
| 1267 | REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]); |
| 1268 | lastPt = pts[1]; |
| 1269 | numIterPts += 1; |
| 1270 | break; |
| 1271 | case SkPath::kQuad_Verb: |
| 1272 | REPORTER_ASSERT(reporter, numIterPts < numPoints + 2); |
| 1273 | REPORTER_ASSERT(reporter, pts[0] == lastPt); |
| 1274 | REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]); |
| 1275 | REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]); |
| 1276 | lastPt = pts[2]; |
| 1277 | numIterPts += 2; |
| 1278 | break; |
| 1279 | case SkPath::kCubic_Verb: |
| 1280 | REPORTER_ASSERT(reporter, numIterPts < numPoints + 3); |
| 1281 | REPORTER_ASSERT(reporter, pts[0] == lastPt); |
| 1282 | REPORTER_ASSERT(reporter, pts[1] == expectedPts[numIterPts]); |
| 1283 | REPORTER_ASSERT(reporter, pts[2] == expectedPts[numIterPts + 1]); |
| 1284 | REPORTER_ASSERT(reporter, pts[3] == expectedPts[numIterPts + 2]); |
| 1285 | lastPt = pts[3]; |
| 1286 | numIterPts += 3; |
| 1287 | break; |
| 1288 | case SkPath::kClose_Verb: |
| 1289 | REPORTER_ASSERT(reporter, pts[0] == lastMoveTo); |
| 1290 | lastPt = lastMoveTo; |
| 1291 | break; |
| 1292 | default:; |
| 1293 | } |
| 1294 | } |
| 1295 | REPORTER_ASSERT(reporter, numIterPts == numPoints); |
| 1296 | REPORTER_ASSERT(reporter, numIterVerbs == numVerbs); |
| 1297 | } |
| 1298 | } |
| 1299 | |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 1300 | static void check_for_circle(skiatest::Reporter* reporter, |
| 1301 | const SkPath& path, bool expected) { |
| 1302 | SkRect rect; |
| 1303 | REPORTER_ASSERT(reporter, path.isOval(&rect) == expected); |
| 1304 | if (expected) { |
| 1305 | REPORTER_ASSERT(reporter, rect.height() == rect.width()); |
| 1306 | } |
| 1307 | } |
| 1308 | |
| 1309 | static void test_circle_skew(skiatest::Reporter* reporter, |
| 1310 | const SkPath& path) { |
| 1311 | SkPath tmp; |
| 1312 | |
| 1313 | SkMatrix m; |
| 1314 | m.setSkew(SkIntToScalar(3), SkIntToScalar(5)); |
| 1315 | path.transform(m, &tmp); |
| 1316 | check_for_circle(reporter, tmp, false); |
| 1317 | } |
| 1318 | |
| 1319 | static void test_circle_translate(skiatest::Reporter* reporter, |
| 1320 | const SkPath& path) { |
| 1321 | SkPath tmp; |
| 1322 | |
| 1323 | // translate at small offset |
| 1324 | SkMatrix m; |
| 1325 | m.setTranslate(SkIntToScalar(15), SkIntToScalar(15)); |
| 1326 | path.transform(m, &tmp); |
| 1327 | check_for_circle(reporter, tmp, true); |
| 1328 | |
| 1329 | tmp.reset(); |
| 1330 | m.reset(); |
| 1331 | |
| 1332 | // translate at a relatively big offset |
| 1333 | m.setTranslate(SkIntToScalar(1000), SkIntToScalar(1000)); |
| 1334 | path.transform(m, &tmp); |
| 1335 | check_for_circle(reporter, tmp, true); |
| 1336 | } |
| 1337 | |
| 1338 | static void test_circle_rotate(skiatest::Reporter* reporter, |
| 1339 | const SkPath& path) { |
| 1340 | for (int angle = 0; angle < 360; ++angle) { |
| 1341 | SkPath tmp; |
| 1342 | SkMatrix m; |
| 1343 | m.setRotate(SkIntToScalar(angle)); |
| 1344 | path.transform(m, &tmp); |
| 1345 | |
| 1346 | // TODO: a rotated circle whose rotated angle is not a mutiple of 90 |
| 1347 | // degrees is not an oval anymore, this can be improved. we made this |
| 1348 | // for the simplicity of our implementation. |
| 1349 | if (angle % 90 == 0) { |
| 1350 | check_for_circle(reporter, tmp, true); |
| 1351 | } else { |
| 1352 | check_for_circle(reporter, tmp, false); |
| 1353 | } |
| 1354 | } |
| 1355 | } |
| 1356 | |
| 1357 | static void test_circle_with_direction(skiatest::Reporter* reporter, |
| 1358 | SkPath::Direction dir) { |
| 1359 | SkPath path; |
| 1360 | |
| 1361 | // circle at origin |
| 1362 | path.addCircle(0, 0, SkIntToScalar(20), dir); |
| 1363 | check_for_circle(reporter, path, true); |
| 1364 | test_circle_rotate(reporter, path); |
| 1365 | test_circle_translate(reporter, path); |
| 1366 | test_circle_skew(reporter, path); |
| 1367 | |
| 1368 | // circle at an offset at (10, 10) |
| 1369 | path.reset(); |
| 1370 | path.addCircle(SkIntToScalar(10), SkIntToScalar(10), |
| 1371 | SkIntToScalar(20), dir); |
| 1372 | check_for_circle(reporter, path, true); |
| 1373 | test_circle_rotate(reporter, path); |
| 1374 | test_circle_translate(reporter, path); |
| 1375 | test_circle_skew(reporter, path); |
| 1376 | } |
| 1377 | |
| 1378 | static void test_circle_with_add_paths(skiatest::Reporter* reporter) { |
| 1379 | SkPath path; |
| 1380 | SkPath circle; |
| 1381 | SkPath rect; |
| 1382 | SkPath empty; |
| 1383 | |
| 1384 | circle.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction); |
| 1385 | rect.addRect(SkIntToScalar(5), SkIntToScalar(5), |
| 1386 | SkIntToScalar(20), SkIntToScalar(20), SkPath::kCW_Direction); |
| 1387 | |
| 1388 | SkMatrix translate; |
| 1389 | translate.setTranslate(SkIntToScalar(12), SkIntToScalar(12)); |
| 1390 | |
| 1391 | // For simplicity, all the path concatenation related operations |
| 1392 | // would mark it non-circle, though in theory it's still a circle. |
| 1393 | |
| 1394 | // empty + circle (translate) |
| 1395 | path = empty; |
| 1396 | path.addPath(circle, translate); |
| 1397 | check_for_circle(reporter, path, false); |
| 1398 | |
| 1399 | // circle + empty (translate) |
| 1400 | path = circle; |
| 1401 | path.addPath(empty, translate); |
| 1402 | check_for_circle(reporter, path, false); |
| 1403 | |
| 1404 | // test reverseAddPath |
| 1405 | path = circle; |
| 1406 | path.reverseAddPath(rect); |
| 1407 | check_for_circle(reporter, path, false); |
| 1408 | } |
| 1409 | |
| 1410 | static void test_circle(skiatest::Reporter* reporter) { |
| 1411 | test_circle_with_direction(reporter, SkPath::kCW_Direction); |
| 1412 | test_circle_with_direction(reporter, SkPath::kCCW_Direction); |
| 1413 | |
| 1414 | // multiple addCircle() |
| 1415 | SkPath path; |
| 1416 | path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction); |
| 1417 | path.addCircle(0, 0, SkIntToScalar(20), SkPath::kCW_Direction); |
| 1418 | check_for_circle(reporter, path, false); |
| 1419 | |
| 1420 | // some extra lineTo() would make isOval() fail |
| 1421 | path.reset(); |
| 1422 | path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction); |
| 1423 | path.lineTo(0, 0); |
| 1424 | check_for_circle(reporter, path, false); |
| 1425 | |
| 1426 | // not back to the original point |
| 1427 | path.reset(); |
| 1428 | path.addCircle(0, 0, SkIntToScalar(10), SkPath::kCW_Direction); |
| 1429 | path.setLastPt(SkIntToScalar(5), SkIntToScalar(5)); |
| 1430 | check_for_circle(reporter, path, false); |
| 1431 | |
| 1432 | test_circle_with_add_paths(reporter); |
| 1433 | } |
| 1434 | |
| 1435 | static void test_oval(skiatest::Reporter* reporter) { |
| 1436 | SkRect rect; |
| 1437 | SkMatrix m; |
| 1438 | SkPath path; |
| 1439 | |
| 1440 | rect = SkRect::MakeWH(SkIntToScalar(30), SkIntToScalar(50)); |
| 1441 | path.addOval(rect); |
| 1442 | |
| 1443 | REPORTER_ASSERT(reporter, path.isOval(NULL)); |
| 1444 | |
| 1445 | m.setRotate(SkIntToScalar(90)); |
| 1446 | SkPath tmp; |
| 1447 | path.transform(m, &tmp); |
| 1448 | // an oval rotated 90 degrees is still an oval. |
| 1449 | REPORTER_ASSERT(reporter, tmp.isOval(NULL)); |
| 1450 | |
| 1451 | m.reset(); |
| 1452 | m.setRotate(SkIntToScalar(30)); |
| 1453 | tmp.reset(); |
| 1454 | path.transform(m, &tmp); |
| 1455 | // an oval rotated 30 degrees is not an oval anymore. |
| 1456 | REPORTER_ASSERT(reporter, !tmp.isOval(NULL)); |
| 1457 | |
| 1458 | // since empty path being transformed. |
| 1459 | path.reset(); |
| 1460 | tmp.reset(); |
| 1461 | m.reset(); |
| 1462 | path.transform(m, &tmp); |
| 1463 | REPORTER_ASSERT(reporter, !tmp.isOval(NULL)); |
| 1464 | |
| 1465 | // empty path is not an oval |
| 1466 | tmp.reset(); |
| 1467 | REPORTER_ASSERT(reporter, !tmp.isOval(NULL)); |
| 1468 | |
| 1469 | // only has moveTo()s |
| 1470 | tmp.reset(); |
| 1471 | tmp.moveTo(0, 0); |
| 1472 | tmp.moveTo(SkIntToScalar(10), SkIntToScalar(10)); |
| 1473 | REPORTER_ASSERT(reporter, !tmp.isOval(NULL)); |
| 1474 | |
| 1475 | // mimic WebKit's calling convention, |
| 1476 | // call moveTo() first and then call addOval() |
| 1477 | path.reset(); |
| 1478 | path.moveTo(0, 0); |
| 1479 | path.addOval(rect); |
| 1480 | REPORTER_ASSERT(reporter, path.isOval(NULL)); |
| 1481 | |
| 1482 | // copy path |
| 1483 | path.reset(); |
| 1484 | tmp.reset(); |
| 1485 | tmp.addOval(rect); |
| 1486 | path = tmp; |
| 1487 | REPORTER_ASSERT(reporter, path.isOval(NULL)); |
| 1488 | } |
| 1489 | |
caryclark@google.com | 42639cd | 2012-06-06 12:03:39 +0000 | [diff] [blame] | 1490 | static void TestPath(skiatest::Reporter* reporter) { |
reed@android.com | 60bc6d5 | 2010-02-11 11:09:39 +0000 | [diff] [blame] | 1491 | { |
| 1492 | SkSize size; |
| 1493 | size.fWidth = 3.4f; |
| 1494 | size.width(); |
| 1495 | size = SkSize::Make(3,4); |
| 1496 | SkISize isize = SkISize::Make(3,4); |
| 1497 | } |
| 1498 | |
| 1499 | SkTSize<SkScalar>::Make(3,4); |
| 1500 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1501 | SkPath p, p2; |
| 1502 | SkRect bounds, bounds2; |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 1503 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1504 | REPORTER_ASSERT(reporter, p.isEmpty()); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 1505 | REPORTER_ASSERT(reporter, 0 == p.countPoints()); |
bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 1506 | REPORTER_ASSERT(reporter, 0 == p.countVerbs()); |
reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 1507 | REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks()); |
reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 1508 | REPORTER_ASSERT(reporter, p.isConvex()); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1509 | REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType); |
| 1510 | REPORTER_ASSERT(reporter, !p.isInverseFillType()); |
| 1511 | REPORTER_ASSERT(reporter, p == p2); |
| 1512 | REPORTER_ASSERT(reporter, !(p != p2)); |
| 1513 | |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 1514 | REPORTER_ASSERT(reporter, p.getBounds().isEmpty()); |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 1515 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1516 | bounds.set(0, 0, SK_Scalar1, SK_Scalar1); |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 1517 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 1518 | p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1); |
| 1519 | check_convex_bounds(reporter, p, bounds); |
reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 1520 | // we have quads or cubics |
| 1521 | REPORTER_ASSERT(reporter, p.getSegmentMasks() & kCurveSegmentMask); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 1522 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 1523 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 1524 | p.reset(); |
reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 1525 | REPORTER_ASSERT(reporter, 0 == p.getSegmentMasks()); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 1526 | REPORTER_ASSERT(reporter, p.isEmpty()); |
reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 1527 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 1528 | p.addOval(bounds); |
| 1529 | check_convex_bounds(reporter, p, bounds); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 1530 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 1531 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 1532 | p.reset(); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1533 | p.addRect(bounds); |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 1534 | check_convex_bounds(reporter, p, bounds); |
reed@google.com | 10296cc | 2011-09-21 12:29:05 +0000 | [diff] [blame] | 1535 | // we have only lines |
| 1536 | REPORTER_ASSERT(reporter, SkPath::kLine_SegmentMask == p.getSegmentMasks()); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 1537 | REPORTER_ASSERT(reporter, !p.isEmpty()); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1538 | |
| 1539 | REPORTER_ASSERT(reporter, p != p2); |
| 1540 | REPORTER_ASSERT(reporter, !(p == p2)); |
| 1541 | |
bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 1542 | // do getPoints and getVerbs return the right result |
| 1543 | REPORTER_ASSERT(reporter, p.getPoints(NULL, 0) == 4); |
| 1544 | REPORTER_ASSERT(reporter, p.getVerbs(NULL, 0) == 5); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1545 | SkPoint pts[4]; |
| 1546 | int count = p.getPoints(pts, 4); |
| 1547 | REPORTER_ASSERT(reporter, count == 4); |
bsalomon@google.com | df9d656 | 2012-06-07 21:43:15 +0000 | [diff] [blame] | 1548 | uint8_t verbs[6]; |
| 1549 | verbs[5] = 0xff; |
| 1550 | p.getVerbs(verbs, 5); |
| 1551 | REPORTER_ASSERT(reporter, SkPath::kMove_Verb == verbs[0]); |
| 1552 | REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[1]); |
| 1553 | REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[2]); |
| 1554 | REPORTER_ASSERT(reporter, SkPath::kLine_Verb == verbs[3]); |
| 1555 | REPORTER_ASSERT(reporter, SkPath::kClose_Verb == verbs[4]); |
| 1556 | REPORTER_ASSERT(reporter, 0xff == verbs[5]); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1557 | bounds2.set(pts, 4); |
| 1558 | REPORTER_ASSERT(reporter, bounds == bounds2); |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 1559 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1560 | bounds.offset(SK_Scalar1*3, SK_Scalar1*4); |
| 1561 | p.offset(SK_Scalar1*3, SK_Scalar1*4); |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 1562 | REPORTER_ASSERT(reporter, bounds == p.getBounds()); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1563 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1564 | REPORTER_ASSERT(reporter, p.isRect(NULL)); |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 1565 | bounds2.setEmpty(); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1566 | REPORTER_ASSERT(reporter, p.isRect(&bounds2)); |
| 1567 | REPORTER_ASSERT(reporter, bounds == bounds2); |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 1568 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1569 | // now force p to not be a rect |
| 1570 | bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2); |
| 1571 | p.addRect(bounds); |
| 1572 | REPORTER_ASSERT(reporter, !p.isRect(NULL)); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1573 | |
reed@google.com | 7e6c4d1 | 2012-05-10 14:05:43 +0000 | [diff] [blame] | 1574 | test_isLine(reporter); |
| 1575 | test_isRect(reporter); |
schenney@chromium.org | 4da06ab | 2011-12-20 15:14:18 +0000 | [diff] [blame] | 1576 | test_zero_length_paths(reporter); |
reed@google.com | cabaf1d | 2012-01-11 21:03:05 +0000 | [diff] [blame] | 1577 | test_direction(reporter); |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 1578 | test_convexity(reporter); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 1579 | test_convexity2(reporter); |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 1580 | test_close(reporter); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1581 | test_segment_masks(reporter); |
reed@google.com | 53effc5 | 2011-09-21 19:05:12 +0000 | [diff] [blame] | 1582 | test_flattening(reporter); |
| 1583 | test_transform(reporter); |
reed@google.com | 3563c9e | 2011-11-14 19:34:57 +0000 | [diff] [blame] | 1584 | test_bounds(reporter); |
schenney@chromium.org | 6630d8d | 2012-01-04 21:05:51 +0000 | [diff] [blame] | 1585 | test_iter(reporter); |
| 1586 | test_raw_iter(reporter); |
bsalomon@google.com | 6aa2965 | 2012-04-18 13:29:52 +0000 | [diff] [blame] | 1587 | test_circle(reporter); |
| 1588 | test_oval(reporter); |
reed@google.com | 8b06f1a | 2012-05-29 12:03:46 +0000 | [diff] [blame] | 1589 | test_strokerec(reporter); |
reed@google.com | 744faba | 2012-05-29 19:54:52 +0000 | [diff] [blame] | 1590 | test_addPoly(reporter); |
reed@google.com | 0bb18bb | 2012-07-26 15:20:36 +0000 | [diff] [blame] | 1591 | test_isfinite(reporter); |
tomhudson@google.com | ed02c4d | 2012-08-10 14:10:45 +0000 | [diff] [blame] | 1592 | test_isfinite_after_transform(reporter); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | #include "TestClassDef.h" |
| 1596 | DEFINE_TESTCLASS("Path", PathTestClass, TestPath) |