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