OLD | NEW |
1 | |
2 /* | 1 /* |
3 * Copyright 2011 Google Inc. | 2 * Copyright 2011 Google Inc. |
4 * | 3 * |
5 * 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 |
6 * found in the LICENSE file. | 5 * found in the LICENSE file. |
7 */ | 6 */ |
| 7 |
8 #include "Test.h" | 8 #include "Test.h" |
| 9 #include "TestClassDef.h" |
9 #include "SkGeometry.h" | 10 #include "SkGeometry.h" |
10 | 11 |
11 static bool nearly_equal(const SkPoint& a, const SkPoint& b) { | 12 static bool nearly_equal(const SkPoint& a, const SkPoint& b) { |
12 return SkScalarNearlyEqual(a.fX, b.fX) && SkScalarNearlyEqual(a.fY, b.fY); | 13 return SkScalarNearlyEqual(a.fX, b.fX) && SkScalarNearlyEqual(a.fY, b.fY); |
13 } | 14 } |
14 | 15 |
15 static void testChopCubic(skiatest::Reporter* reporter) { | 16 static void testChopCubic(skiatest::Reporter* reporter) { |
16 /* | 17 /* |
17 Inspired by this test, which used to assert that the tValues had dups | 18 Inspired by this test, which used to assert that the tValues had dups |
18 | 19 |
19 <path stroke="#202020" d="M0,0 C0,0 1,1 2190,5130 C2190,5070 2220,5010 2
205,4980" /> | 20 <path stroke="#202020" d="M0,0 C0,0 1,1 2190,5130 C2190,5070 2220,5010 2
205,4980" /> |
20 */ | 21 */ |
21 const SkPoint src[] = { | 22 const SkPoint src[] = { |
22 { SkIntToScalar(2190), SkIntToScalar(5130) }, | 23 { SkIntToScalar(2190), SkIntToScalar(5130) }, |
23 { SkIntToScalar(2190), SkIntToScalar(5070) }, | 24 { SkIntToScalar(2190), SkIntToScalar(5070) }, |
24 { SkIntToScalar(2220), SkIntToScalar(5010) }, | 25 { SkIntToScalar(2220), SkIntToScalar(5010) }, |
25 { SkIntToScalar(2205), SkIntToScalar(4980) }, | 26 { SkIntToScalar(2205), SkIntToScalar(4980) }, |
26 }; | 27 }; |
27 SkPoint dst[13]; | 28 SkPoint dst[13]; |
28 SkScalar tValues[3]; | 29 SkScalar tValues[3]; |
29 // make sure we don't assert internally | 30 // make sure we don't assert internally |
30 int count = SkChopCubicAtMaxCurvature(src, dst, tValues); | 31 int count = SkChopCubicAtMaxCurvature(src, dst, tValues); |
31 if (false) { // avoid bit rot, suppress warning | 32 if (false) { // avoid bit rot, suppress warning |
32 REPORTER_ASSERT(reporter, count); | 33 REPORTER_ASSERT(reporter, count); |
33 } | 34 } |
34 } | 35 } |
35 | 36 |
36 | 37 DEF_TEST(Geometry, reporter) { |
37 static void TestGeometry(skiatest::Reporter* reporter) { | |
38 SkPoint pts[3], dst[5]; | 38 SkPoint pts[3], dst[5]; |
39 | 39 |
40 pts[0].set(0, 0); | 40 pts[0].set(0, 0); |
41 pts[1].set(100, 50); | 41 pts[1].set(100, 50); |
42 pts[2].set(0, 100); | 42 pts[2].set(0, 100); |
43 | 43 |
44 int count = SkChopQuadAtMaxCurvature(pts, dst); | 44 int count = SkChopQuadAtMaxCurvature(pts, dst); |
45 REPORTER_ASSERT(reporter, count == 1 || count == 2); | 45 REPORTER_ASSERT(reporter, count == 1 || count == 2); |
46 | 46 |
47 pts[0].set(0, 0); | 47 pts[0].set(0, 0); |
48 pts[1].set(SkIntToScalar(3), 0); | 48 pts[1].set(SkIntToScalar(3), 0); |
49 pts[2].set(SkIntToScalar(3), SkIntToScalar(3)); | 49 pts[2].set(SkIntToScalar(3), SkIntToScalar(3)); |
50 SkConvertQuadToCubic(pts, dst); | 50 SkConvertQuadToCubic(pts, dst); |
51 const SkPoint cubic[] = { | 51 const SkPoint cubic[] = { |
52 { 0, 0, }, | 52 { 0, 0, }, |
53 { SkIntToScalar(2), 0, }, | 53 { SkIntToScalar(2), 0, }, |
54 { SkIntToScalar(3), SkIntToScalar(1), }, | 54 { SkIntToScalar(3), SkIntToScalar(1), }, |
55 { SkIntToScalar(3), SkIntToScalar(3) }, | 55 { SkIntToScalar(3), SkIntToScalar(3) }, |
56 }; | 56 }; |
57 for (int i = 0; i < 4; ++i) { | 57 for (int i = 0; i < 4; ++i) { |
58 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i])); | 58 REPORTER_ASSERT(reporter, nearly_equal(cubic[i], dst[i])); |
59 } | 59 } |
60 | 60 |
61 testChopCubic(reporter); | 61 testChopCubic(reporter); |
62 } | 62 } |
63 | |
64 #include "TestClassDef.h" | |
65 DEFINE_TESTCLASS("Geometry", GeometryTestClass, TestGeometry) | |
OLD | NEW |