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 #include "PathOpsTestCommon.h" | 7 #include "PathOpsTestCommon.h" |
8 #include "SkPathOpsPoint.h" | 8 #include "SkPathOpsPoint.h" |
9 #include "Test.h" | 9 #include "Test.h" |
| 10 #include "TestClassDef.h" |
10 | 11 |
11 static const SkDPoint tests[] = { | 12 static const SkDPoint tests[] = { |
12 {0, 0}, | 13 {0, 0}, |
13 {1, 0}, | 14 {1, 0}, |
14 {0, 1}, | 15 {0, 1}, |
15 {2, 1}, | 16 {2, 1}, |
16 {1, 2}, | 17 {1, 2}, |
17 {1, 1}, | 18 {1, 1}, |
18 {2, 2} | 19 {2, 2} |
19 }; | 20 }; |
20 | 21 |
21 static const size_t tests_count = SK_ARRAY_COUNT(tests); | 22 static const size_t tests_count = SK_ARRAY_COUNT(tests); |
22 | 23 |
23 static void PathOpsDPointTest(skiatest::Reporter* reporter) { | 24 DEF_TEST(PathOpsDPoint, reporter) { |
24 for (size_t index = 0; index < tests_count; ++index) { | 25 for (size_t index = 0; index < tests_count; ++index) { |
25 const SkDPoint& pt = tests[index]; | 26 const SkDPoint& pt = tests[index]; |
26 SkASSERT(ValidPoint(pt)); | 27 SkASSERT(ValidPoint(pt)); |
27 SkDPoint p = pt; | 28 SkDPoint p = pt; |
28 REPORTER_ASSERT(reporter, p == pt); | 29 REPORTER_ASSERT(reporter, p == pt); |
29 REPORTER_ASSERT(reporter, !(pt != pt)); | 30 REPORTER_ASSERT(reporter, !(pt != pt)); |
30 SkDVector v = p - pt; | 31 SkDVector v = p - pt; |
31 p += v; | 32 p += v; |
32 REPORTER_ASSERT(reporter, p == pt); | 33 REPORTER_ASSERT(reporter, p == pt); |
33 p -= v; | 34 p -= v; |
34 REPORTER_ASSERT(reporter, p == pt); | 35 REPORTER_ASSERT(reporter, p == pt); |
35 REPORTER_ASSERT(reporter, p.approximatelyEqual(pt)); | 36 REPORTER_ASSERT(reporter, p.approximatelyEqual(pt)); |
36 SkPoint sPt = pt.asSkPoint(); | 37 SkPoint sPt = pt.asSkPoint(); |
37 p.set(sPt); | 38 p.set(sPt); |
38 REPORTER_ASSERT(reporter, p == pt); | 39 REPORTER_ASSERT(reporter, p == pt); |
39 REPORTER_ASSERT(reporter, p.approximatelyEqual(sPt)); | 40 REPORTER_ASSERT(reporter, p.approximatelyEqual(sPt)); |
40 REPORTER_ASSERT(reporter, p.roughlyEqual(pt)); | 41 REPORTER_ASSERT(reporter, p.roughlyEqual(pt)); |
41 REPORTER_ASSERT(reporter, p.moreRoughlyEqual(pt)); | 42 REPORTER_ASSERT(reporter, p.moreRoughlyEqual(pt)); |
42 p.fX = p.fY = 0; | 43 p.fX = p.fY = 0; |
43 REPORTER_ASSERT(reporter, p.fX == 0 && p.fY == 0); | 44 REPORTER_ASSERT(reporter, p.fX == 0 && p.fY == 0); |
44 REPORTER_ASSERT(reporter, p.approximatelyZero()); | 45 REPORTER_ASSERT(reporter, p.approximatelyZero()); |
45 REPORTER_ASSERT(reporter, pt.distanceSquared(p) == pt.fX * pt.fX + pt.fY
* pt.fY); | 46 REPORTER_ASSERT(reporter, pt.distanceSquared(p) == pt.fX * pt.fX + pt.fY
* pt.fY); |
46 REPORTER_ASSERT(reporter, approximately_equal(pt.distance(p), | 47 REPORTER_ASSERT(reporter, approximately_equal(pt.distance(p), |
47 sqrt(pt.fX * pt.fX + pt.fY * pt.fY))); | 48 sqrt(pt.fX * pt.fX + pt.fY * pt.fY))); |
48 } | 49 } |
49 } | 50 } |
50 | |
51 #include "TestClassDef.h" | |
52 DEFINE_TESTCLASS_SHORT(PathOpsDPointTest) | |
OLD | NEW |