OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2012 Google Inc. | 2 * Copyright 2012 Google Inc. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license that can be | 4 * Use of this source code is governed by a BSD-style license that can be |
5 * found in the LICENSE file. | 5 * found in the LICENSE file. |
6 */ | 6 */ |
7 | 7 |
8 #include "Test.h" | 8 #include "Test.h" |
9 #include "SkRRect.h" | 9 #include "SkRRect.h" |
10 | 10 |
(...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
310 rr2.setRectXY(rect, -10, -20); | 310 rr2.setRectXY(rect, -10, -20); |
311 | 311 |
312 REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr2.type()); | 312 REPORTER_ASSERT(reporter, SkRRect::kRect_Type == rr2.type()); |
313 | 313 |
314 const SkPoint& p2 = rr2.radii(SkRRect::kUpperLeft_Corner); | 314 const SkPoint& p2 = rr2.radii(SkRRect::kUpperLeft_Corner); |
315 | 315 |
316 REPORTER_ASSERT(reporter, 0.0f == p2.fX); | 316 REPORTER_ASSERT(reporter, 0.0f == p2.fX); |
317 REPORTER_ASSERT(reporter, 0.0f == p2.fY); | 317 REPORTER_ASSERT(reporter, 0.0f == p2.fY); |
318 } | 318 } |
319 | 319 |
| 320 // Move a small box from the start position by (stepX, stepY) 'numSteps' times |
| 321 // testing for containment in 'rr' at each step. |
| 322 static void test_direction(skiatest::Reporter* reporter, const SkRRect &rr, |
| 323 SkScalar initX, int stepX, SkScalar initY, int stepY,
|
| 324 int numSteps, const bool* contains) { |
| 325 SkScalar x = initX, y = initY; |
| 326 for (int i = 0; i < numSteps; ++i) { |
| 327 SkRect test = SkRect::MakeXYWH(x, y, |
| 328 stepX ? SkIntToScalar(stepX) : SK_Scalar1
, |
| 329 stepY ? SkIntToScalar(stepY) : SK_Scalar1
); |
| 330 test.sort(); |
| 331 |
| 332 REPORTER_ASSERT(reporter, contains[i] == rr.contains(test)); |
| 333 |
| 334 x += stepX; |
| 335 y += stepY; |
| 336 } |
| 337 } |
| 338 |
| 339 // Exercise the RR's contains rect method |
| 340 static void test_round_rect_contains_rect(skiatest::Reporter* reporter) { |
| 341 |
| 342 static const int kNumRRects = 4; |
| 343 static const SkVector gRadii[kNumRRects][4] = { |
| 344 { { 0, 0 }, { 0, 0 }, { 0, 0 }, { 0, 0 } }, // rect |
| 345 { { 20, 20 }, { 20, 20 }, { 20, 20 }, { 20, 20 } }, // circle |
| 346 { { 10, 10 }, { 10, 10 }, { 10, 10 }, { 10, 10 } }, // simple |
| 347 { { 0, 0 }, { 20, 20 }, { 10, 10 }, { 30, 30 } } // complex |
| 348 }; |
| 349 |
| 350 SkRRect rrects[kNumRRects]; |
| 351 for (int i = 0; i < kNumRRects; ++i) { |
| 352 rrects[i].setRectRadii(SkRect::MakeWH(40, 40), gRadii[i]); |
| 353 } |
| 354 |
| 355 // First test easy outs - boxes that are obviously out on |
| 356 // each corner and edge |
| 357 static const SkRect easyOuts[] = { |
| 358 { -5, -5, 5, 5 }, // NW |
| 359 { 15, -5, 20, 5 }, // N |
| 360 { 35, -5, 45, 5 }, // NE |
| 361 { 35, 15, 45, 20 }, // E |
| 362 { 35, 45, 35, 45 }, // SE |
| 363 { 15, 35, 20, 45 }, // S |
| 364 { -5, 35, 5, 45 }, // SW |
| 365 { -5, 15, 5, 20 } // W |
| 366 }; |
| 367 |
| 368 for (int i = 0; i < kNumRRects; ++i) { |
| 369 for (size_t j = 0; j < SK_ARRAY_COUNT(easyOuts); ++j) { |
| 370 REPORTER_ASSERT(reporter, !rrects[i].contains(easyOuts[j])); |
| 371 } |
| 372 } |
| 373 |
| 374 // Now test non-trivial containment. For each compass |
| 375 // point walk a 1x1 rect in from the edge of the bounding |
| 376 // rect |
| 377 static const int kNumSteps = 15; |
| 378 bool answers[kNumRRects][8][kNumSteps] = { |
| 379 // all the test rects are inside the degenerate rrect |
| 380 { |
| 381 // rect |
| 382 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 383 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 384 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 385 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 386 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 387 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 388 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 389 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 390 }, |
| 391 // for the circle we expect 6 blocks to be out on the |
| 392 // corners (then the rest in) and only the first block |
| 393 // out on the vertical and horizontal axes (then |
| 394 // the rest in) |
| 395 { |
| 396 // circle |
| 397 { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 398 { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 399 { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 400 { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 401 { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 402 { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 403 { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 404 { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 405 }, |
| 406 // for the simple round rect we expect 3 out on |
| 407 // the corners (then the rest in) and no blocks out |
| 408 // on the vertical and horizontal axes |
| 409 { |
| 410 // simple RR |
| 411 { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 412 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 413 { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 414 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 415 { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 416 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 417 { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 418 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 419 }, |
| 420 // for the complex case the answer is different for each direction |
| 421 { |
| 422 // complex RR |
| 423 // all in for NW (rect) corner (same as rect case) |
| 424 { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 425 // only first block out for N (same as circle case) |
| 426 { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 427 // first 6 blocks out for NE (same as circle case) |
| 428 { 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 429 // only first block out for E (same as circle case) |
| 430 { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 431 // first 3 blocks out for SE (same as simple case) |
| 432 { 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 433 // first two blocks out for S |
| 434 { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 435 // first 9 blocks out for SW |
| 436 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1 }, |
| 437 // first two blocks out for W (same as S) |
| 438 { 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }, |
| 439 } |
| 440 }; |
| 441 |
| 442 for (int i = 0; i < kNumRRects; ++i) { |
| 443 test_direction(reporter, rrects[i], 0, 1, 0, 1, kNumSteps, ans
wers[i][0]); // NW |
| 444 test_direction(reporter, rrects[i], 19.5f, 0, 0, 1, kNumSteps, ans
wers[i][1]); // N |
| 445 test_direction(reporter, rrects[i], 40, -1, 0, 1, kNumSteps, ans
wers[i][2]); // NE |
| 446 test_direction(reporter, rrects[i], 40, -1, 19.5f, 0, kNumSteps, ans
wers[i][3]); // E |
| 447 test_direction(reporter, rrects[i], 40, -1, 40, -1, kNumSteps, ans
wers[i][4]); // SE |
| 448 test_direction(reporter, rrects[i], 19.5f, 0, 40, -1, kNumSteps, ans
wers[i][5]); // S |
| 449 test_direction(reporter, rrects[i], 0, 1, 40, -1, kNumSteps, ans
wers[i][6]); // SW |
| 450 test_direction(reporter, rrects[i], 0, 1, 19.5f, 0, kNumSteps, ans
wers[i][7]); // W |
| 451 } |
| 452 } |
| 453 |
320 static void TestRoundRect(skiatest::Reporter* reporter) { | 454 static void TestRoundRect(skiatest::Reporter* reporter) { |
321 test_round_rect_basic(reporter); | 455 test_round_rect_basic(reporter); |
322 test_round_rect_rects(reporter); | 456 test_round_rect_rects(reporter); |
323 test_round_rect_ovals(reporter); | 457 test_round_rect_ovals(reporter); |
324 test_round_rect_general(reporter); | 458 test_round_rect_general(reporter); |
325 test_round_rect_iffy_parameters(reporter); | 459 test_round_rect_iffy_parameters(reporter); |
326 test_inset(reporter); | 460 test_inset(reporter); |
| 461 test_round_rect_contains_rect(reporter); |
327 } | 462 } |
328 | 463 |
329 #include "TestClassDef.h" | 464 #include "TestClassDef.h" |
330 DEFINE_TESTCLASS("RoundRect", TestRoundRectClass, TestRoundRect) | 465 DEFINE_TESTCLASS("RoundRect", TestRoundRectClass, TestRoundRect) |
OLD | NEW |