OLD | NEW |
1 /* | 1 /* |
2 * Copyright 2011 Google Inc. | 2 * Copyright 2011 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 "SkCanvas.h" | 9 #include "SkCanvas.h" |
10 #include "SkPaint.h" | 10 #include "SkPaint.h" |
(...skipping 1420 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1431 path.reset(); | 1431 path.reset(); |
1432 path.lineTo(100, 100); | 1432 path.lineTo(100, 100); |
1433 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(
0, 0, 1, 1))); | 1433 REPORTER_ASSERT(reporter, !path.conservativelyContainsRect(SkRect::MakeXYWH(
0, 0, 1, 1))); |
1434 } | 1434 } |
1435 | 1435 |
1436 static void test_isRect_open_close(skiatest::Reporter* reporter) { | 1436 static void test_isRect_open_close(skiatest::Reporter* reporter) { |
1437 SkPath path; | 1437 SkPath path; |
1438 bool isClosed; | 1438 bool isClosed; |
1439 | 1439 |
1440 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1); | 1440 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1); |
| 1441 path.close(); |
1441 | 1442 |
1442 if (false) { | |
1443 // I think these should pass, but isRect() doesn't behave | |
1444 // this way... yet | |
1445 REPORTER_ASSERT(reporter, path.isRect(NULL, NULL)); | |
1446 REPORTER_ASSERT(reporter, path.isRect(&isClosed, NULL)); | |
1447 REPORTER_ASSERT(reporter, !isClosed); | |
1448 } | |
1449 | |
1450 path.close(); | |
1451 REPORTER_ASSERT(reporter, path.isRect(NULL, NULL)); | 1443 REPORTER_ASSERT(reporter, path.isRect(NULL, NULL)); |
1452 REPORTER_ASSERT(reporter, path.isRect(&isClosed, NULL)); | 1444 REPORTER_ASSERT(reporter, path.isRect(&isClosed, NULL)); |
1453 REPORTER_ASSERT(reporter, isClosed); | 1445 REPORTER_ASSERT(reporter, isClosed); |
1454 } | 1446 } |
1455 | 1447 |
1456 // Simple isRect test is inline TestPath, below. | 1448 // Simple isRect test is inline TestPath, below. |
1457 // test_isRect provides more extensive testing. | 1449 // test_isRect provides more extensive testing. |
1458 static void test_isRect(skiatest::Reporter* reporter) { | 1450 static void test_isRect(skiatest::Reporter* reporter) { |
1459 test_isRect_open_close(reporter); | 1451 test_isRect_open_close(reporter); |
1460 | 1452 |
(...skipping 20 matching lines...) Expand all Loading... |
1481 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps | 1473 SkPoint f3[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 0}, {1, 0}}; // wraps |
1482 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up | 1474 SkPoint f4[] = {{0, 0}, {1, 0}, {0, 0}, {1, 0}, {1, 1}, {0, 1}}; // backs up |
1483 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots | 1475 SkPoint f5[] = {{0, 0}, {1, 0}, {1, 1}, {2, 0}}; // end overshoots |
1484 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots | 1476 SkPoint f6[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}, {0, 2}}; // end overshoots |
1485 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots | 1477 SkPoint f7[] = {{0, 0}, {1, 0}, {1, 1}, {0, 2}}; // end overshoots |
1486 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L' | 1478 SkPoint f8[] = {{0, 0}, {1, 0}, {1, 1}, {1, 0}}; // 'L' |
1487 SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps | 1479 SkPoint f9[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 0}, {2, 0}}; // overlaps |
1488 SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non co
linear gap | 1480 SkPoint fa[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, -1}, {1, -1}}; // non co
linear gap |
1489 SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short | 1481 SkPoint fb[] = {{1, 0}, {8, 0}, {8, 8}, {0, 8}, {0, 1}}; // falls short |
1490 | 1482 |
1491 // failing, no close | 1483 // no close, but we should detect them as fillably the same as a rect |
1492 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; // close doesn't match | 1484 SkPoint c1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; |
1493 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; // ditto | 1485 SkPoint c2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}}; |
| 1486 SkPoint c3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 0}}; // hit the
start |
| 1487 |
| 1488 // like c2, but we double-back on ourselves |
| 1489 SkPoint d1[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, 1}, {0, 2}}; |
| 1490 // like c2, but we overshoot the start point |
| 1491 SkPoint d2[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}}; |
| 1492 SkPoint d3[] = {{0, 0}, {1, 0}, {1, 2}, {0, 2}, {0, -1}, {0, 0}}; |
1494 | 1493 |
1495 struct IsRectTest { | 1494 struct IsRectTest { |
1496 SkPoint *fPoints; | 1495 SkPoint *fPoints; |
1497 size_t fPointCount; | 1496 size_t fPointCount; |
1498 bool fClose; | 1497 bool fClose; |
1499 bool fIsRect; | 1498 bool fIsRect; |
1500 } tests[] = { | 1499 } tests[] = { |
1501 { r1, SK_ARRAY_COUNT(r1), true, true }, | 1500 { r1, SK_ARRAY_COUNT(r1), true, true }, |
1502 { r2, SK_ARRAY_COUNT(r2), true, true }, | 1501 { r2, SK_ARRAY_COUNT(r2), true, true }, |
1503 { r3, SK_ARRAY_COUNT(r3), true, true }, | 1502 { r3, SK_ARRAY_COUNT(r3), true, true }, |
(...skipping 15 matching lines...) Expand all Loading... |
1519 { f3, SK_ARRAY_COUNT(f3), true, false }, | 1518 { f3, SK_ARRAY_COUNT(f3), true, false }, |
1520 { f4, SK_ARRAY_COUNT(f4), true, false }, | 1519 { f4, SK_ARRAY_COUNT(f4), true, false }, |
1521 { f5, SK_ARRAY_COUNT(f5), true, false }, | 1520 { f5, SK_ARRAY_COUNT(f5), true, false }, |
1522 { f6, SK_ARRAY_COUNT(f6), true, false }, | 1521 { f6, SK_ARRAY_COUNT(f6), true, false }, |
1523 { f7, SK_ARRAY_COUNT(f7), true, false }, | 1522 { f7, SK_ARRAY_COUNT(f7), true, false }, |
1524 { f8, SK_ARRAY_COUNT(f8), true, false }, | 1523 { f8, SK_ARRAY_COUNT(f8), true, false }, |
1525 { f9, SK_ARRAY_COUNT(f9), true, false }, | 1524 { f9, SK_ARRAY_COUNT(f9), true, false }, |
1526 { fa, SK_ARRAY_COUNT(fa), true, false }, | 1525 { fa, SK_ARRAY_COUNT(fa), true, false }, |
1527 { fb, SK_ARRAY_COUNT(fb), true, false }, | 1526 { fb, SK_ARRAY_COUNT(fb), true, false }, |
1528 | 1527 |
1529 { c1, SK_ARRAY_COUNT(c1), false, false }, | 1528 { c1, SK_ARRAY_COUNT(c1), false, true }, |
1530 { c2, SK_ARRAY_COUNT(c2), false, false }, | 1529 { c2, SK_ARRAY_COUNT(c2), false, true }, |
| 1530 { c3, SK_ARRAY_COUNT(c3), false, true }, |
| 1531 |
| 1532 { d1, SK_ARRAY_COUNT(d1), false, false }, |
| 1533 { d2, SK_ARRAY_COUNT(d2), false, false }, |
| 1534 { d3, SK_ARRAY_COUNT(d3), false, false }, |
1531 }; | 1535 }; |
1532 | 1536 |
1533 const size_t testCount = SK_ARRAY_COUNT(tests); | 1537 const size_t testCount = SK_ARRAY_COUNT(tests); |
1534 size_t index; | 1538 size_t index; |
1535 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { | 1539 for (size_t testIndex = 0; testIndex < testCount; ++testIndex) { |
1536 SkPath path; | 1540 SkPath path; |
1537 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].
fY); | 1541 path.moveTo(tests[testIndex].fPoints[0].fX, tests[testIndex].fPoints[0].
fY); |
1538 for (index = 1; index < tests[testIndex].fPointCount; ++index) { | 1542 for (index = 1; index < tests[testIndex].fPointCount; ++index) { |
1539 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPo
ints[index].fY); | 1543 path.lineTo(tests[testIndex].fPoints[index].fX, tests[testIndex].fPo
ints[index].fY); |
1540 } | 1544 } |
(...skipping 1698 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3239 q.conicTo(8, 7, 6, 5, 0.5f); | 3243 q.conicTo(8, 7, 6, 5, 0.5f); |
3240 q.quadTo(6, 7, 8, 6); | 3244 q.quadTo(6, 7, 8, 6); |
3241 q.cubicTo(5, 6, 7, 8, 7, 5); | 3245 q.cubicTo(5, 6, 7, 8, 7, 5); |
3242 q.close(); | 3246 q.close(); |
3243 p.reversePathTo(q); | 3247 p.reversePathTo(q); |
3244 SkRect reverseExpected = {-4, -4, 8, 8}; | 3248 SkRect reverseExpected = {-4, -4, 8, 8}; |
3245 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected); | 3249 REPORTER_ASSERT(reporter, p.getBounds() == reverseExpected); |
3246 } | 3250 } |
3247 }; | 3251 }; |
3248 | 3252 |
3249 DEF_TEST(Path, reporter) { | 3253 DEF_TEST(Paths, reporter) { |
3250 SkTSize<SkScalar>::Make(3,4); | 3254 SkTSize<SkScalar>::Make(3,4); |
3251 | 3255 |
3252 SkPath p, empty; | 3256 SkPath p, empty; |
3253 SkRect bounds, bounds2; | 3257 SkRect bounds, bounds2; |
3254 test_empty(reporter, p); | 3258 test_empty(reporter, p); |
3255 | 3259 |
3256 REPORTER_ASSERT(reporter, p.getBounds().isEmpty()); | 3260 REPORTER_ASSERT(reporter, p.getBounds().isEmpty()); |
3257 | 3261 |
3258 // this triggers a code path in SkPath::operator= which is otherwise unexerc
ised | 3262 // this triggers a code path in SkPath::operator= which is otherwise unexerc
ised |
3259 SkPath& self = p; | 3263 SkPath& self = p; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3359 test_rrect(reporter); | 3363 test_rrect(reporter); |
3360 test_arc(reporter); | 3364 test_arc(reporter); |
3361 test_arcTo(reporter); | 3365 test_arcTo(reporter); |
3362 test_addPath(reporter); | 3366 test_addPath(reporter); |
3363 test_conicTo_special_case(reporter); | 3367 test_conicTo_special_case(reporter); |
3364 test_get_point(reporter); | 3368 test_get_point(reporter); |
3365 test_contains(reporter); | 3369 test_contains(reporter); |
3366 PathTest_Private::TestPathTo(reporter); | 3370 PathTest_Private::TestPathTo(reporter); |
3367 PathRefTest_Private::TestPathRef(reporter); | 3371 PathRefTest_Private::TestPathRef(reporter); |
3368 } | 3372 } |
OLD | NEW |