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