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 "SkCanvas.h" | 8 #include "SkCanvas.h" |
9 #include "SkPaint.h" | 9 #include "SkPaint.h" |
10 #include "SkParse.h" | 10 #include "SkParse.h" |
(...skipping 1671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1682 | 1682 |
1683 static void test_isRect_open_close(skiatest::Reporter* reporter) { | 1683 static void test_isRect_open_close(skiatest::Reporter* reporter) { |
1684 SkPath path; | 1684 SkPath path; |
1685 bool isClosed; | 1685 bool isClosed; |
1686 | 1686 |
1687 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1); | 1687 path.moveTo(0, 0); path.lineTo(1, 0); path.lineTo(1, 1); path.lineTo(0, 1); |
1688 path.close(); | 1688 path.close(); |
1689 | 1689 |
1690 REPORTER_ASSERT(reporter, path.isRect(NULL, &isClosed, NULL)); | 1690 REPORTER_ASSERT(reporter, path.isRect(NULL, &isClosed, NULL)); |
1691 REPORTER_ASSERT(reporter, isClosed); | 1691 REPORTER_ASSERT(reporter, isClosed); |
1692 REPORTER_ASSERT(reporter, SkPath::kStroke_PathAsRect == path.asRect(NULL)); | |
1693 } | 1692 } |
1694 | 1693 |
1695 // Simple isRect test is inline TestPath, below. | 1694 // Simple isRect test is inline TestPath, below. |
1696 // test_isRect provides more extensive testing. | 1695 // test_isRect provides more extensive testing. |
1697 static void test_isRect(skiatest::Reporter* reporter) { | 1696 static void test_isRect(skiatest::Reporter* reporter) { |
1698 test_isRect_open_close(reporter); | 1697 test_isRect_open_close(reporter); |
1699 | 1698 |
1700 // passing tests (all moveTo / lineTo... | 1699 // passing tests (all moveTo / lineTo... |
1701 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; | 1700 SkPoint r1[] = {{0, 0}, {1, 0}, {1, 1}, {0, 1}}; |
1702 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; | 1701 SkPoint r2[] = {{1, 0}, {1, 1}, {0, 1}, {0, 0}}; |
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1797 if (tests[testIndex].fIsRect) { | 1796 if (tests[testIndex].fIsRect) { |
1798 SkRect computed, expected; | 1797 SkRect computed, expected; |
1799 bool isClosed; | 1798 bool isClosed; |
1800 SkPath::Direction direction, cheapDirection; | 1799 SkPath::Direction direction, cheapDirection; |
1801 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount)
; | 1800 expected.set(tests[testIndex].fPoints, tests[testIndex].fPointCount)
; |
1802 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection
)); | 1801 REPORTER_ASSERT(reporter, path.cheapComputeDirection(&cheapDirection
)); |
1803 REPORTER_ASSERT(reporter, path.isRect(&computed, &isClosed, &directi
on)); | 1802 REPORTER_ASSERT(reporter, path.isRect(&computed, &isClosed, &directi
on)); |
1804 REPORTER_ASSERT(reporter, expected == computed); | 1803 REPORTER_ASSERT(reporter, expected == computed); |
1805 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose); | 1804 REPORTER_ASSERT(reporter, isClosed == tests[testIndex].fClose); |
1806 REPORTER_ASSERT(reporter, direction == cheapDirection); | 1805 REPORTER_ASSERT(reporter, direction == cheapDirection); |
1807 direction = (SkPath::Direction) -1; | |
1808 if (!tests[testIndex].fClose) { | |
1809 REPORTER_ASSERT(reporter, SkPath::kFill_PathAsRect == path.asRec
t()); | |
1810 REPORTER_ASSERT(reporter, SkPath::kFill_PathAsRect == path.asRec
t(&direction)); | |
1811 } else { | |
1812 REPORTER_ASSERT(reporter, SkPath::kStroke_PathAsRect == path.asR
ect()); | |
1813 REPORTER_ASSERT(reporter, SkPath::kStroke_PathAsRect == path.asR
ect(&direction)); | |
1814 } | |
1815 REPORTER_ASSERT(reporter, direction == cheapDirection); | |
1816 } else { | 1806 } else { |
1817 SkRect computed; | 1807 SkRect computed; |
1818 computed.set(123, 456, 789, 1011); | 1808 computed.set(123, 456, 789, 1011); |
1819 bool isClosed = (bool)-1; | 1809 bool isClosed = (bool)-1; |
1820 SkPath::Direction direction = (SkPath::Direction) - 1; | 1810 SkPath::Direction direction = (SkPath::Direction) - 1; |
1821 REPORTER_ASSERT(reporter, !path.isRect(&computed, &isClosed, &direct
ion)); | 1811 REPORTER_ASSERT(reporter, !path.isRect(&computed, &isClosed, &direct
ion)); |
1822 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop ==
456); | 1812 REPORTER_ASSERT(reporter, computed.fLeft == 123 && computed.fTop ==
456); |
1823 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom
== 1011); | 1813 REPORTER_ASSERT(reporter, computed.fRight == 789 && computed.fBottom
== 1011); |
1824 REPORTER_ASSERT(reporter, isClosed == (bool) -1); | 1814 REPORTER_ASSERT(reporter, isClosed == (bool) -1); |
1825 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1); | 1815 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1); |
1826 REPORTER_ASSERT(reporter, SkPath::kNone_PathAsRect == path.asRect())
; | |
1827 REPORTER_ASSERT(reporter, SkPath::kNone_PathAsRect == path.asRect(&d
irection)); | |
1828 REPORTER_ASSERT(reporter, direction == (SkPath::Direction) -1); | |
1829 } | 1816 } |
1830 } | 1817 } |
1831 | 1818 |
1832 // fail, close then line | 1819 // fail, close then line |
1833 SkPath path1; | 1820 SkPath path1; |
1834 path1.moveTo(r1[0].fX, r1[0].fY); | 1821 path1.moveTo(r1[0].fX, r1[0].fY); |
1835 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { | 1822 for (index = 1; index < SkToInt(SK_ARRAY_COUNT(r1)); ++index) { |
1836 path1.lineTo(r1[index].fX, r1[index].fY); | 1823 path1.lineTo(r1[index].fX, r1[index].fY); |
1837 } | 1824 } |
1838 path1.close(); | 1825 path1.close(); |
(...skipping 1929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3768 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode); | 3755 test_addEmptyPath(reporter, SkPath::kAppend_AddPathMode); |
3769 test_conicTo_special_case(reporter); | 3756 test_conicTo_special_case(reporter); |
3770 test_get_point(reporter); | 3757 test_get_point(reporter); |
3771 test_contains(reporter); | 3758 test_contains(reporter); |
3772 PathTest_Private::TestPathTo(reporter); | 3759 PathTest_Private::TestPathTo(reporter); |
3773 PathRefTest_Private::TestPathRef(reporter); | 3760 PathRefTest_Private::TestPathRef(reporter); |
3774 test_dump(reporter); | 3761 test_dump(reporter); |
3775 test_path_crbugskia2820(reporter); | 3762 test_path_crbugskia2820(reporter); |
3776 test_skbug_3239(reporter); | 3763 test_skbug_3239(reporter); |
3777 } | 3764 } |
OLD | NEW |