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 1895 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1906 { | 1906 { |
1907 SkPath oval; | 1907 SkPath oval; |
1908 SkRect rect = SkRect::MakeWH(10, 10); | 1908 SkRect rect = SkRect::MakeWH(10, 10); |
1909 oval.addOval(rect); | 1909 oval.addOval(rect); |
1910 | 1910 |
1911 write_and_read_back(reporter, oval); | 1911 write_and_read_back(reporter, oval); |
1912 } | 1912 } |
1913 } | 1913 } |
1914 | 1914 |
1915 static void test_transform(skiatest::Reporter* reporter) { | 1915 static void test_transform(skiatest::Reporter* reporter) { |
1916 SkPath p, p1; | 1916 SkPath p; |
1917 | 1917 |
1918 #define CONIC_PERSPECTIVE_BUG_FIXED 0 | 1918 #define CONIC_PERSPECTIVE_BUG_FIXED 0 |
1919 static const SkPoint pts[] = { | 1919 static const SkPoint pts[] = { |
1920 { 0, 0 }, // move | 1920 { 0, 0 }, // move |
1921 { SkIntToScalar(10), SkIntToScalar(10) }, // line | 1921 { SkIntToScalar(10), SkIntToScalar(10) }, // line |
1922 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, //
quad | 1922 { SkIntToScalar(20), SkIntToScalar(10) }, { SkIntToScalar(20), 0 }, //
quad |
1923 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10
) }, // cubic | 1923 { 0, 0 }, { 0, SkIntToScalar(10) }, { SkIntToScalar(1), SkIntToScalar(10
) }, // cubic |
1924 #if CONIC_PERSPECTIVE_BUG_FIXED | 1924 #if CONIC_PERSPECTIVE_BUG_FIXED |
1925 { 0, 0 }, { SkIntToScalar(20), SkIntToScalar(10) }, // conic | 1925 { 0, 0 }, { SkIntToScalar(20), SkIntToScalar(10) }, // conic |
1926 #endif | 1926 #endif |
1927 }; | 1927 }; |
1928 const int kPtCount = SK_ARRAY_COUNT(pts); | 1928 const int kPtCount = SK_ARRAY_COUNT(pts); |
| 1929 |
1929 p.moveTo(pts[0]); | 1930 p.moveTo(pts[0]); |
1930 p.lineTo(pts[1]); | 1931 p.lineTo(pts[1]); |
1931 p.quadTo(pts[2], pts[3]); | 1932 p.quadTo(pts[2], pts[3]); |
1932 p.cubicTo(pts[4], pts[5], pts[6]); | 1933 p.cubicTo(pts[4], pts[5], pts[6]); |
1933 #if CONIC_PERSPECTIVE_BUG_FIXED | 1934 #if CONIC_PERSPECTIVE_BUG_FIXED |
1934 p.conicTo(pts[4], pts[5], 0.5f); | 1935 p.conicTo(pts[4], pts[5], 0.5f); |
1935 #endif | 1936 #endif |
1936 p.close(); | 1937 p.close(); |
1937 SkMatrix matrix; | |
1938 matrix.reset(); | |
1939 p.transform(matrix, &p1); | |
1940 REPORTER_ASSERT(reporter, p == p1); | |
1941 | 1938 |
1942 matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3); | 1939 { |
1943 p.transform(matrix, &p1); | 1940 SkMatrix matrix; |
1944 SkPoint pts1[kPtCount]; | 1941 matrix.reset(); |
1945 int count = p1.getPoints(pts1, kPtCount); | 1942 SkPath p1; |
1946 REPORTER_ASSERT(reporter, kPtCount == count); | 1943 p.transform(matrix, &p1); |
1947 for (int i = 0; i < count; ++i) { | 1944 REPORTER_ASSERT(reporter, p == p1); |
1948 SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3); | |
1949 REPORTER_ASSERT(reporter, newPt == pts1[i]); | |
1950 } | 1945 } |
1951 matrix.reset(); | |
1952 matrix.setPerspX(SkScalarToPersp(4)); | |
1953 p.transform(matrix, &p1); | |
1954 REPORTER_ASSERT(reporter, matrix.invert(&matrix)); | |
1955 p1.transform(matrix, NULL); | |
1956 SkRect pBounds = p.getBounds(); | |
1957 SkRect p1Bounds = p1.getBounds(); | |
1958 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fLeft, p1Bounds.fLeft)
); | |
1959 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fTop, p1Bounds.fTop)); | |
1960 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fRight, p1Bounds.fRigh
t)); | |
1961 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fBottom, p1Bounds.fBot
tom)); | |
1962 | 1946 |
1963 matrix.reset(); | 1947 |
| 1948 { |
| 1949 SkMatrix matrix; |
| 1950 matrix.setScale(SK_Scalar1 * 2, SK_Scalar1 * 3); |
| 1951 |
| 1952 SkPath p1; // Leave p1 non-unique (i.e., the empty path) |
| 1953 |
| 1954 p.transform(matrix, &p1); |
| 1955 SkPoint pts1[kPtCount]; |
| 1956 int count = p1.getPoints(pts1, kPtCount); |
| 1957 REPORTER_ASSERT(reporter, kPtCount == count); |
| 1958 for (int i = 0; i < count; ++i) { |
| 1959 SkPoint newPt = SkPoint::Make(pts[i].fX * 2, pts[i].fY * 3); |
| 1960 REPORTER_ASSERT(reporter, newPt == pts1[i]); |
| 1961 } |
| 1962 } |
| 1963 |
| 1964 { |
| 1965 SkMatrix matrix; |
| 1966 matrix.reset(); |
| 1967 matrix.setPerspX(SkScalarToPersp(4)); |
| 1968 |
| 1969 SkPath p1; |
| 1970 p1.moveTo(SkPoint::Make(0, 0)); |
| 1971 |
| 1972 p.transform(matrix, &p1); |
| 1973 REPORTER_ASSERT(reporter, matrix.invert(&matrix)); |
| 1974 p1.transform(matrix, NULL); |
| 1975 SkRect pBounds = p.getBounds(); |
| 1976 SkRect p1Bounds = p1.getBounds(); |
| 1977 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fLeft, p1Bounds.fL
eft)); |
| 1978 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fTop, p1Bounds.fTo
p)); |
| 1979 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fRight, p1Bounds.f
Right)); |
| 1980 REPORTER_ASSERT(reporter, SkScalarNearlyEqual(pBounds.fBottom, p1Bounds.
fBottom)); |
| 1981 } |
| 1982 |
1964 p.reset(); | 1983 p.reset(); |
1965 p.addCircle(0, 0, 1, SkPath::kCW_Direction); | 1984 p.addCircle(0, 0, 1, SkPath::kCW_Direction); |
1966 p.transform(matrix, &p1); | 1985 |
1967 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCW_Direction)); | 1986 { |
1968 matrix.setScaleX(-1); | 1987 SkMatrix matrix; |
1969 p.transform(matrix, &p1); | 1988 matrix.reset(); |
1970 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCCW_Direction)); | 1989 SkPath p1; |
1971 matrix.setAll(1, 1, 0, 1, 1, 0, 0, 0, 1); | 1990 p1.moveTo(SkPoint::Make(0, 0)); |
1972 p.transform(matrix, &p1); | 1991 |
1973 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kUnknown_Direction)); | 1992 p.transform(matrix, &p1); |
| 1993 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCW_Direction)); |
| 1994 } |
| 1995 |
| 1996 |
| 1997 { |
| 1998 SkMatrix matrix; |
| 1999 matrix.reset(); |
| 2000 matrix.setScaleX(-1); |
| 2001 SkPath p1; |
| 2002 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path) |
| 2003 |
| 2004 p.transform(matrix, &p1); |
| 2005 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kCCW_Direction)); |
| 2006 } |
| 2007 |
| 2008 { |
| 2009 SkMatrix matrix; |
| 2010 matrix.setAll(1, 1, 0, 1, 1, 0, 0, 0, 1); |
| 2011 SkPath p1; |
| 2012 p1.moveTo(SkPoint::Make(0, 0)); // Make p1 unique (i.e., not empty path) |
| 2013 |
| 2014 p.transform(matrix, &p1); |
| 2015 REPORTER_ASSERT(reporter, p1.cheapIsDirection(SkPath::kUnknown_Direction
)); |
| 2016 } |
1974 } | 2017 } |
1975 | 2018 |
1976 static void test_zero_length_paths(skiatest::Reporter* reporter) { | 2019 static void test_zero_length_paths(skiatest::Reporter* reporter) { |
1977 SkPath p; | 2020 SkPath p; |
1978 uint8_t verbs[32]; | 2021 uint8_t verbs[32]; |
1979 | 2022 |
1980 struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData { | 2023 struct SUPPRESS_VISIBILITY_WARNING zeroPathTestData { |
1981 const char* testPath; | 2024 const char* testPath; |
1982 const size_t numResultPts; | 2025 const size_t numResultPts; |
1983 const SkRect resultBound; | 2026 const SkRect resultBound; |
(...skipping 1267 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3251 test_arcTo(reporter); | 3294 test_arcTo(reporter); |
3252 test_addPath(reporter); | 3295 test_addPath(reporter); |
3253 test_conicTo_special_case(reporter); | 3296 test_conicTo_special_case(reporter); |
3254 test_get_point(reporter); | 3297 test_get_point(reporter); |
3255 test_contains(reporter); | 3298 test_contains(reporter); |
3256 PathTest_Private::TestPathTo(reporter); | 3299 PathTest_Private::TestPathTo(reporter); |
3257 } | 3300 } |
3258 | 3301 |
3259 #include "TestClassDef.h" | 3302 #include "TestClassDef.h" |
3260 DEFINE_TESTCLASS("Path", PathTestClass, TestPath) | 3303 DEFINE_TESTCLASS("Path", PathTestClass, TestPath) |
OLD | NEW |