epoger@google.com | ec3ed6a | 2011-07-28 14:26:00 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Copyright 2011 Google Inc. |
| 4 | * |
| 5 | * Use of this source code is governed by a BSD-style license that can be |
| 6 | * found in the LICENSE file. |
| 7 | */ |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 8 | #include "Test.h" |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 9 | #include "SkPaint.h" |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 10 | #include "SkPath.h" |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 11 | #include "SkParse.h" |
reed@android.com | 60bc6d5 | 2010-02-11 11:09:39 +0000 | [diff] [blame] | 12 | #include "SkSize.h" |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 13 | |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 14 | static void stroke_cubic(const SkPoint pts[4]) { |
| 15 | SkPath path; |
| 16 | path.moveTo(pts[0]); |
| 17 | path.cubicTo(pts[1], pts[2], pts[3]); |
| 18 | |
| 19 | SkPaint paint; |
| 20 | paint.setStyle(SkPaint::kStroke_Style); |
| 21 | paint.setStrokeWidth(SK_Scalar1 * 2); |
| 22 | |
| 23 | SkPath fill; |
| 24 | paint.getFillPath(path, &fill); |
| 25 | } |
| 26 | |
| 27 | // just ensure this can run w/o any SkASSERTS firing in the debug build |
| 28 | // we used to assert due to differences in how we determine a degenerate vector |
| 29 | // but that was fixed with the introduction of SkPoint::CanNormalize |
| 30 | static void stroke_tiny_cubic() { |
| 31 | SkPoint p0[] = { |
| 32 | { 372.0f, 92.0f }, |
| 33 | { 372.0f, 92.0f }, |
| 34 | { 372.0f, 92.0f }, |
| 35 | { 372.0f, 92.0f }, |
| 36 | }; |
| 37 | |
| 38 | stroke_cubic(p0); |
| 39 | |
| 40 | SkPoint p1[] = { |
| 41 | { 372.0f, 92.0f }, |
| 42 | { 372.0007f, 92.000755f }, |
| 43 | { 371.99927f, 92.003922f }, |
| 44 | { 371.99826f, 92.003899f }, |
| 45 | }; |
| 46 | |
| 47 | stroke_cubic(p1); |
| 48 | } |
| 49 | |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 50 | static void check_close(skiatest::Reporter* reporter, const SkPath& path) { |
| 51 | for (int i = 0; i < 2; ++i) { |
| 52 | SkPath::Iter iter(path, (bool)i); |
| 53 | SkPoint mv; |
| 54 | SkPoint pts[4]; |
| 55 | SkPath::Verb v; |
| 56 | int nMT = 0; |
| 57 | int nCL = 0; |
tomhudson@google.com | 221db3c | 2011-07-28 21:10:29 +0000 | [diff] [blame] | 58 | mv.set(0, 0); |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 59 | while (SkPath::kDone_Verb != (v = iter.next(pts))) { |
| 60 | switch (v) { |
| 61 | case SkPath::kMove_Verb: |
| 62 | mv = pts[0]; |
| 63 | ++nMT; |
| 64 | break; |
| 65 | case SkPath::kClose_Verb: |
| 66 | REPORTER_ASSERT(reporter, mv == pts[0]); |
| 67 | ++nCL; |
| 68 | break; |
| 69 | default: |
| 70 | break; |
| 71 | } |
| 72 | } |
| 73 | // if we force a close on the interator we should have a close |
| 74 | // for every moveTo |
| 75 | REPORTER_ASSERT(reporter, !i || nMT == nCL); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | static void test_close(skiatest::Reporter* reporter) { |
| 80 | SkPath closePt; |
| 81 | closePt.moveTo(0, 0); |
| 82 | closePt.close(); |
| 83 | check_close(reporter, closePt); |
| 84 | |
| 85 | SkPath openPt; |
| 86 | openPt.moveTo(0, 0); |
| 87 | check_close(reporter, openPt); |
| 88 | |
| 89 | SkPath empty; |
| 90 | check_close(reporter, empty); |
| 91 | empty.close(); |
| 92 | check_close(reporter, empty); |
| 93 | |
| 94 | SkPath rect; |
| 95 | rect.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 96 | check_close(reporter, rect); |
| 97 | rect.close(); |
| 98 | check_close(reporter, rect); |
| 99 | |
| 100 | SkPath quad; |
| 101 | quad.quadTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 102 | check_close(reporter, quad); |
| 103 | quad.close(); |
| 104 | check_close(reporter, quad); |
| 105 | |
| 106 | SkPath cubic; |
| 107 | quad.cubicTo(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, |
| 108 | 10*SK_Scalar1, 20 * SK_Scalar1, 20*SK_Scalar1); |
| 109 | check_close(reporter, cubic); |
| 110 | cubic.close(); |
| 111 | check_close(reporter, cubic); |
| 112 | |
| 113 | SkPath line; |
| 114 | line.moveTo(SK_Scalar1, SK_Scalar1); |
| 115 | line.lineTo(10 * SK_Scalar1, 10*SK_Scalar1); |
| 116 | check_close(reporter, line); |
| 117 | line.close(); |
| 118 | check_close(reporter, line); |
| 119 | |
| 120 | SkPath rect2; |
| 121 | rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 122 | rect2.close(); |
| 123 | rect2.addRect(SK_Scalar1, SK_Scalar1, 10 * SK_Scalar1, 10*SK_Scalar1); |
| 124 | check_close(reporter, rect2); |
| 125 | rect2.close(); |
| 126 | check_close(reporter, rect2); |
| 127 | |
| 128 | SkPath oval3; |
| 129 | oval3.addOval(SkRect::MakeWH(SK_Scalar1*100,SK_Scalar1*100)); |
| 130 | oval3.close(); |
| 131 | oval3.addOval(SkRect::MakeWH(SK_Scalar1*200,SK_Scalar1*200)); |
| 132 | check_close(reporter, oval3); |
| 133 | oval3.close(); |
| 134 | check_close(reporter, oval3); |
| 135 | |
| 136 | SkPath moves; |
| 137 | moves.moveTo(SK_Scalar1, SK_Scalar1); |
| 138 | moves.moveTo(5 * SK_Scalar1, SK_Scalar1); |
| 139 | moves.moveTo(SK_Scalar1, 10 * SK_Scalar1); |
| 140 | moves.moveTo(10 *SK_Scalar1, SK_Scalar1); |
| 141 | check_close(reporter, moves); |
reed@google.com | 55b5f4b | 2011-09-07 12:23:41 +0000 | [diff] [blame] | 142 | |
| 143 | stroke_tiny_cubic(); |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 144 | } |
| 145 | |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 146 | static void check_convexity(skiatest::Reporter* reporter, const SkPath& path, |
| 147 | SkPath::Convexity expected) { |
| 148 | SkPath::Convexity c = SkPath::ComputeConvexity(path); |
| 149 | REPORTER_ASSERT(reporter, c == expected); |
| 150 | } |
| 151 | |
| 152 | static void test_convexity2(skiatest::Reporter* reporter) { |
| 153 | SkPath pt; |
| 154 | pt.moveTo(0, 0); |
| 155 | pt.close(); |
reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 156 | check_convexity(reporter, pt, SkPath::kConvex_Convexity); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 157 | |
| 158 | SkPath line; |
| 159 | line.moveTo(12, 20); |
| 160 | line.lineTo(-12, -20); |
| 161 | line.close(); |
reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 162 | check_convexity(reporter, pt, SkPath::kConvex_Convexity); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 163 | |
| 164 | SkPath triLeft; |
| 165 | triLeft.moveTo(0, 0); |
| 166 | triLeft.lineTo(1, 0); |
| 167 | triLeft.lineTo(1, 1); |
| 168 | triLeft.close(); |
| 169 | check_convexity(reporter, triLeft, SkPath::kConvex_Convexity); |
| 170 | |
| 171 | SkPath triRight; |
| 172 | triRight.moveTo(0, 0); |
| 173 | triRight.lineTo(-1, 0); |
| 174 | triRight.lineTo(1, 1); |
| 175 | triRight.close(); |
| 176 | check_convexity(reporter, triRight, SkPath::kConvex_Convexity); |
| 177 | |
| 178 | SkPath square; |
| 179 | square.moveTo(0, 0); |
| 180 | square.lineTo(1, 0); |
| 181 | square.lineTo(1, 1); |
| 182 | square.lineTo(0, 1); |
| 183 | square.close(); |
| 184 | check_convexity(reporter, square, SkPath::kConvex_Convexity); |
| 185 | |
| 186 | SkPath redundantSquare; |
| 187 | redundantSquare.moveTo(0, 0); |
| 188 | redundantSquare.lineTo(0, 0); |
| 189 | redundantSquare.lineTo(0, 0); |
| 190 | redundantSquare.lineTo(1, 0); |
| 191 | redundantSquare.lineTo(1, 0); |
| 192 | redundantSquare.lineTo(1, 0); |
| 193 | redundantSquare.lineTo(1, 1); |
| 194 | redundantSquare.lineTo(1, 1); |
| 195 | redundantSquare.lineTo(1, 1); |
| 196 | redundantSquare.lineTo(0, 1); |
| 197 | redundantSquare.lineTo(0, 1); |
| 198 | redundantSquare.lineTo(0, 1); |
| 199 | redundantSquare.close(); |
| 200 | check_convexity(reporter, redundantSquare, SkPath::kConvex_Convexity); |
| 201 | |
| 202 | SkPath bowTie; |
| 203 | bowTie.moveTo(0, 0); |
| 204 | bowTie.lineTo(0, 0); |
| 205 | bowTie.lineTo(0, 0); |
| 206 | bowTie.lineTo(1, 1); |
| 207 | bowTie.lineTo(1, 1); |
| 208 | bowTie.lineTo(1, 1); |
| 209 | bowTie.lineTo(1, 0); |
| 210 | bowTie.lineTo(1, 0); |
| 211 | bowTie.lineTo(1, 0); |
| 212 | bowTie.lineTo(0, 1); |
| 213 | bowTie.lineTo(0, 1); |
| 214 | bowTie.lineTo(0, 1); |
| 215 | bowTie.close(); |
| 216 | check_convexity(reporter, bowTie, SkPath::kConcave_Convexity); |
| 217 | |
| 218 | SkPath spiral; |
| 219 | spiral.moveTo(0, 0); |
epoger@google.com | 2047f00 | 2011-05-17 17:36:59 +0000 | [diff] [blame] | 220 | spiral.lineTo(100, 0); |
| 221 | spiral.lineTo(100, 100); |
| 222 | spiral.lineTo(0, 100); |
| 223 | spiral.lineTo(0, 50); |
| 224 | spiral.lineTo(50, 50); |
| 225 | spiral.lineTo(50, 75); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 226 | spiral.close(); |
reed@google.com | 85b6e39 | 2011-05-15 20:25:17 +0000 | [diff] [blame] | 227 | check_convexity(reporter, spiral, SkPath::kConcave_Convexity); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 228 | |
| 229 | SkPath dent; |
epoger@google.com | 1f75399 | 2011-05-18 20:23:30 +0000 | [diff] [blame] | 230 | dent.moveTo(SkIntToScalar(0), SkIntToScalar(0)); |
| 231 | dent.lineTo(SkIntToScalar(100), SkIntToScalar(100)); |
| 232 | dent.lineTo(SkIntToScalar(0), SkIntToScalar(100)); |
| 233 | dent.lineTo(SkIntToScalar(-50), SkIntToScalar(200)); |
| 234 | dent.lineTo(SkIntToScalar(-200), SkIntToScalar(100)); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 235 | dent.close(); |
| 236 | check_convexity(reporter, dent, SkPath::kConcave_Convexity); |
| 237 | } |
| 238 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 239 | static void check_convex_bounds(skiatest::Reporter* reporter, const SkPath& p, |
| 240 | const SkRect& bounds) { |
| 241 | REPORTER_ASSERT(reporter, p.isConvex()); |
| 242 | REPORTER_ASSERT(reporter, p.getBounds() == bounds); |
reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 243 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 244 | SkPath p2(p); |
| 245 | REPORTER_ASSERT(reporter, p2.isConvex()); |
| 246 | REPORTER_ASSERT(reporter, p2.getBounds() == bounds); |
| 247 | |
| 248 | SkPath other; |
| 249 | other.swap(p2); |
| 250 | REPORTER_ASSERT(reporter, other.isConvex()); |
| 251 | REPORTER_ASSERT(reporter, other.getBounds() == bounds); |
| 252 | } |
| 253 | |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 254 | static void setFromString(SkPath* path, const char str[]) { |
| 255 | bool first = true; |
| 256 | while (str) { |
| 257 | SkScalar x, y; |
| 258 | str = SkParse::FindScalar(str, &x); |
| 259 | if (NULL == str) { |
| 260 | break; |
| 261 | } |
| 262 | str = SkParse::FindScalar(str, &y); |
| 263 | SkASSERT(str); |
| 264 | if (first) { |
| 265 | path->moveTo(x, y); |
| 266 | first = false; |
| 267 | } else { |
| 268 | path->lineTo(x, y); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | static void test_convexity(skiatest::Reporter* reporter) { |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 274 | static const SkPath::Convexity C = SkPath::kConcave_Convexity; |
| 275 | static const SkPath::Convexity V = SkPath::kConvex_Convexity; |
| 276 | |
| 277 | SkPath path; |
| 278 | |
reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 279 | REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path)); |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 280 | path.addCircle(0, 0, 10); |
| 281 | REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path)); |
| 282 | path.addCircle(0, 0, 10); // 2nd circle |
| 283 | REPORTER_ASSERT(reporter, C == SkPath::ComputeConvexity(path)); |
| 284 | path.reset(); |
| 285 | path.addRect(0, 0, 10, 10, SkPath::kCCW_Direction); |
| 286 | REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path)); |
| 287 | path.reset(); |
| 288 | path.addRect(0, 0, 10, 10, SkPath::kCW_Direction); |
| 289 | REPORTER_ASSERT(reporter, V == SkPath::ComputeConvexity(path)); |
| 290 | |
| 291 | static const struct { |
| 292 | const char* fPathStr; |
| 293 | SkPath::Convexity fExpectedConvexity; |
| 294 | } gRec[] = { |
reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 295 | { "", SkPath::kConvex_Convexity }, |
| 296 | { "0 0", SkPath::kConvex_Convexity }, |
| 297 | { "0 0 10 10", SkPath::kConvex_Convexity }, |
reed@google.com | 85b6e39 | 2011-05-15 20:25:17 +0000 | [diff] [blame] | 298 | { "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] | 299 | { "0 0 10 10 10 20", SkPath::kConvex_Convexity }, |
| 300 | { "0 0 10 10 10 0", SkPath::kConvex_Convexity }, |
| 301 | { "0 0 10 10 10 0 0 10", SkPath::kConcave_Convexity }, |
| 302 | { "0 0 10 0 0 10 -10 -10", SkPath::kConcave_Convexity }, |
| 303 | }; |
| 304 | |
| 305 | for (size_t i = 0; i < SK_ARRAY_COUNT(gRec); ++i) { |
| 306 | SkPath path; |
| 307 | setFromString(&path, gRec[i].fPathStr); |
| 308 | SkPath::Convexity c = SkPath::ComputeConvexity(path); |
| 309 | REPORTER_ASSERT(reporter, c == gRec[i].fExpectedConvexity); |
| 310 | } |
| 311 | } |
| 312 | |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 313 | // Simple isRect test is inline TestPath, below. |
| 314 | // test_isRect provides more extensive testing. |
| 315 | static void test_isRect(skiatest::Reporter* reporter) { |
| 316 | // passing tests (all moveTo / lineTo... |
| 317 | SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; |
| 318 | SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
| 319 | SkPoint r3[] = {{1, 1}, {0, 1}, {0, 0}, {1, 0}}; |
| 320 | SkPoint r4[] = {{0, 1}, {0, 0}, {1, 0}, {1, 1}}; |
| 321 | SkPoint r5[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}}; |
| 322 | SkPoint r6[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| 323 | SkPoint r7[] = {{1, 1}, {1, 0}, {0, 0}, {0, 1}}; |
| 324 | SkPoint r8[] = {{1, 0}, {0, 0}, {0, 1}, {1, 1}}; |
| 325 | SkPoint r9[] = {{0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| 326 | SkPoint ra[] = {{0, 0}, {0, .5f}, {0, 1}, {.5f, 1}, {1, 1}, {1, .5f}, |
| 327 | {1, 0}, {.5f, 0}}; |
| 328 | SkPoint rb[] = {{0, 0}, {.5f, 0}, {1, 0}, {1, .5f}, {1, 1}, {.5f, 1}, |
| 329 | {0, 1}, {0, .5f}}; |
| 330 | SkPoint rc[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
| 331 | SkPoint rd[] = {{0, 0}, {0, 1}, {1, 1}, {1, 0}, {0, 0}}; |
| 332 | SkPoint re[] = {{0, 0}, {1, 0}, {1, 0}, {1, 1}, {0, 1}}; |
| 333 | |
| 334 | // failing tests |
| 335 | SkPoint f1[] = {{0, 0}, {1, 0}, {1, 1}}; // too few points |
| 336 | SkPoint f2[] = {{0, 0}, {1, 1}, {0, 1}, {1, 0}}; // diagonal |
| 337 | SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps |
| 338 | SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up |
| 339 | SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots |
| 340 | SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots |
| 341 | SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots |
| 342 | SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L' |
| 343 | |
| 344 | // failing, no close |
| 345 | SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match |
| 346 | SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto |
| 347 | |
| 348 | size_t testLen[] = { |
| 349 | sizeof(r1), sizeof(r2), sizeof(r3), sizeof(r4), sizeof(r5), sizeof(r6), |
| 350 | sizeof(r7), sizeof(r8), sizeof(r9), sizeof(ra), sizeof(rb), sizeof(rc), |
| 351 | sizeof(rd), sizeof(re), |
| 352 | sizeof(f1), sizeof(f2), sizeof(f3), sizeof(f4), sizeof(f5), sizeof(f6), |
| 353 | sizeof(f7), sizeof(f8), |
| 354 | sizeof(c1), sizeof(c2) |
| 355 | }; |
| 356 | SkPoint* tests[] = { |
| 357 | r1, r2, r3, r4, r5, r6, r7, r8, r9, ra, rb, rc, rd, re, |
| 358 | f1, f2, f3, f4, f5, f6, f7, f8, |
| 359 | c1, c2 |
| 360 | }; |
| 361 | SkPoint* lastPass = re; |
| 362 | SkPoint* lastClose = f8; |
| 363 | bool fail = false; |
| 364 | bool close = true; |
| 365 | const size_t testCount = sizeof(tests) / sizeof(tests[0]); |
| 366 | size_t index; |
| 367 | for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { |
| 368 | SkPath path; |
| 369 | path.moveTo(tests[testIndex][0].fX, tests[testIndex][0].fY); |
| 370 | for (index = 1; index < testLen[testIndex] / sizeof(SkPoint); ++index) { |
| 371 | path.lineTo(tests[testIndex][index].fX, tests[testIndex][index].fY); |
| 372 | } |
| 373 | if (close) { |
| 374 | path.close(); |
| 375 | } |
| 376 | REPORTER_ASSERT(reporter, fail ^ path.isRect(0)); |
| 377 | if (tests[testIndex] == lastPass) { |
| 378 | fail = true; |
| 379 | } |
| 380 | if (tests[testIndex] == lastClose) { |
| 381 | close = false; |
| 382 | } |
| 383 | } |
| 384 | |
| 385 | // fail, close then line |
| 386 | SkPath path1; |
| 387 | path1.moveTo(r1[0].fX, r1[0].fY); |
| 388 | for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 389 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 390 | } |
| 391 | path1.close(); |
| 392 | path1.lineTo(1, 0); |
| 393 | REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); |
| 394 | |
| 395 | // fail, move in the middle |
| 396 | path1.reset(); |
| 397 | path1.moveTo(r1[0].fX, r1[0].fY); |
| 398 | for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 399 | if (index == 2) { |
| 400 | path1.moveTo(1, .5f); |
| 401 | } |
| 402 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 403 | } |
| 404 | path1.close(); |
| 405 | REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); |
| 406 | |
| 407 | // fail, move on the edge |
| 408 | path1.reset(); |
| 409 | for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 410 | path1.moveTo(r1[index - 1].fX, r1[index - 1].fY); |
| 411 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 412 | } |
| 413 | path1.close(); |
| 414 | REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); |
| 415 | |
| 416 | // fail, quad |
| 417 | path1.reset(); |
| 418 | path1.moveTo(r1[0].fX, r1[0].fY); |
| 419 | for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 420 | if (index == 2) { |
| 421 | path1.quadTo(1, .5f, 1, .5f); |
| 422 | } |
| 423 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 424 | } |
| 425 | path1.close(); |
| 426 | REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); |
| 427 | |
| 428 | // fail, cubic |
| 429 | path1.reset(); |
| 430 | path1.moveTo(r1[0].fX, r1[0].fY); |
| 431 | for (index = 1; index < testLen[0] / sizeof(SkPoint); ++index) { |
| 432 | if (index == 2) { |
| 433 | path1.cubicTo(1, .5f, 1, .5f, 1, .5f); |
| 434 | } |
| 435 | path1.lineTo(r1[index].fX, r1[index].fY); |
| 436 | } |
| 437 | path1.close(); |
| 438 | REPORTER_ASSERT(reporter, fail ^ path1.isRect(0)); |
| 439 | } |
| 440 | |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 441 | void TestPath(skiatest::Reporter* reporter); |
| 442 | void TestPath(skiatest::Reporter* reporter) { |
reed@android.com | 60bc6d5 | 2010-02-11 11:09:39 +0000 | [diff] [blame] | 443 | { |
| 444 | SkSize size; |
| 445 | size.fWidth = 3.4f; |
| 446 | size.width(); |
| 447 | size = SkSize::Make(3,4); |
| 448 | SkISize isize = SkISize::Make(3,4); |
| 449 | } |
| 450 | |
| 451 | SkTSize<SkScalar>::Make(3,4); |
| 452 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 453 | SkPath p, p2; |
| 454 | SkRect bounds, bounds2; |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 455 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 456 | REPORTER_ASSERT(reporter, p.isEmpty()); |
reed@google.com | b54455e | 2011-05-16 14:16:04 +0000 | [diff] [blame] | 457 | REPORTER_ASSERT(reporter, p.isConvex()); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 458 | REPORTER_ASSERT(reporter, p.getFillType() == SkPath::kWinding_FillType); |
| 459 | REPORTER_ASSERT(reporter, !p.isInverseFillType()); |
| 460 | REPORTER_ASSERT(reporter, p == p2); |
| 461 | REPORTER_ASSERT(reporter, !(p != p2)); |
| 462 | |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 463 | REPORTER_ASSERT(reporter, p.getBounds().isEmpty()); |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 464 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 465 | bounds.set(0, 0, SK_Scalar1, SK_Scalar1); |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 466 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 467 | p.addRoundRect(bounds, SK_Scalar1, SK_Scalar1); |
| 468 | check_convex_bounds(reporter, p, bounds); |
reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 469 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 470 | p.reset(); |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 471 | p.addOval(bounds); |
| 472 | check_convex_bounds(reporter, p, bounds); |
reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 473 | |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 474 | p.reset(); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 475 | p.addRect(bounds); |
reed@android.com | 6b82d1a | 2009-06-03 02:35:01 +0000 | [diff] [blame] | 476 | check_convex_bounds(reporter, p, bounds); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 477 | |
| 478 | REPORTER_ASSERT(reporter, p != p2); |
| 479 | REPORTER_ASSERT(reporter, !(p == p2)); |
| 480 | |
| 481 | // does getPoints return the right result |
| 482 | REPORTER_ASSERT(reporter, p.getPoints(NULL, 5) == 4); |
| 483 | SkPoint pts[4]; |
| 484 | int count = p.getPoints(pts, 4); |
| 485 | REPORTER_ASSERT(reporter, count == 4); |
| 486 | bounds2.set(pts, 4); |
| 487 | REPORTER_ASSERT(reporter, bounds == bounds2); |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 488 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 489 | bounds.offset(SK_Scalar1*3, SK_Scalar1*4); |
| 490 | p.offset(SK_Scalar1*3, SK_Scalar1*4); |
reed@android.com | d252db0 | 2009-04-01 18:31:44 +0000 | [diff] [blame] | 491 | REPORTER_ASSERT(reporter, bounds == p.getBounds()); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 492 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 493 | REPORTER_ASSERT(reporter, p.isRect(NULL)); |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 494 | bounds2.setEmpty(); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 495 | REPORTER_ASSERT(reporter, p.isRect(&bounds2)); |
| 496 | REPORTER_ASSERT(reporter, bounds == bounds2); |
reed@android.com | 80e39a7 | 2009-04-02 16:59:40 +0000 | [diff] [blame] | 497 | |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 498 | // now force p to not be a rect |
| 499 | bounds.set(0, 0, SK_Scalar1/2, SK_Scalar1/2); |
| 500 | p.addRect(bounds); |
| 501 | REPORTER_ASSERT(reporter, !p.isRect(NULL)); |
caryclark@google.com | f131694 | 2011-07-26 19:54:45 +0000 | [diff] [blame] | 502 | test_isRect(reporter); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 503 | |
| 504 | SkPoint pt; |
| 505 | |
| 506 | p.moveTo(SK_Scalar1, 0); |
| 507 | p.getLastPt(&pt); |
| 508 | REPORTER_ASSERT(reporter, pt.fX == SK_Scalar1); |
reed@google.com | 62047cf | 2011-02-07 19:39:09 +0000 | [diff] [blame] | 509 | |
reed@google.com | 04863fa | 2011-05-15 04:08:24 +0000 | [diff] [blame] | 510 | test_convexity(reporter); |
reed@google.com | 7c42481 | 2011-05-15 04:38:34 +0000 | [diff] [blame] | 511 | test_convexity2(reporter); |
bsalomon@google.com | b3b8dfa | 2011-07-13 17:44:36 +0000 | [diff] [blame] | 512 | test_close(reporter); |
reed@android.com | 3abec1d | 2009-03-02 05:36:20 +0000 | [diff] [blame] | 513 | } |
| 514 | |
| 515 | #include "TestClassDef.h" |
| 516 | DEFINE_TESTCLASS("Path", PathTestClass, TestPath) |