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 "SkPathOpsLine.h" | 8 #include "SkPathOpsLine.h" |
9 #include "Test.h" | 9 #include "Test.h" |
| 10 #include "TestClassDef.h" |
10 | 11 |
11 static const SkDLine tests[] = { | 12 static const SkDLine tests[] = { |
12 {{{2, 1}, {2, 1}}}, | 13 {{{2, 1}, {2, 1}}}, |
13 {{{2, 1}, {1, 1}}}, | 14 {{{2, 1}, {1, 1}}}, |
14 {{{2, 1}, {2, 2}}}, | 15 {{{2, 1}, {2, 2}}}, |
15 {{{1, 1}, {2, 2}}}, | 16 {{{1, 1}, {2, 2}}}, |
16 {{{3, 0}, {2, 1}}}, | 17 {{{3, 0}, {2, 1}}}, |
17 {{{3, 2}, {1, 1}}}, | 18 {{{3, 2}, {1, 1}}}, |
18 }; | 19 }; |
19 | 20 |
20 static const SkDPoint left[] = { | 21 static const SkDPoint left[] = { |
21 {2, 1}, | 22 {2, 1}, |
22 {1, 0}, | 23 {1, 0}, |
23 {1, 1}, | 24 {1, 1}, |
24 {1, 2}, | 25 {1, 2}, |
25 {2, 0}, | 26 {2, 0}, |
26 {2, 1} | 27 {2, 1} |
27 }; | 28 }; |
28 | 29 |
29 static const size_t tests_count = SK_ARRAY_COUNT(tests); | 30 static const size_t tests_count = SK_ARRAY_COUNT(tests); |
30 | 31 |
31 static void PathOpsLineUtilitiesTest(skiatest::Reporter* reporter) { | 32 DEF_TEST(PathOpsLineUtilities, reporter) { |
32 for (size_t index = 0; index < tests_count; ++index) { | 33 for (size_t index = 0; index < tests_count; ++index) { |
33 const SkDLine& line = tests[index]; | 34 const SkDLine& line = tests[index]; |
34 SkASSERT(ValidLine(line)); | 35 SkASSERT(ValidLine(line)); |
35 SkDLine line2; | 36 SkDLine line2; |
36 SkPoint pts[2] = {line[0].asSkPoint(), line[1].asSkPoint()}; | 37 SkPoint pts[2] = {line[0].asSkPoint(), line[1].asSkPoint()}; |
37 line2.set(pts); | 38 line2.set(pts); |
38 REPORTER_ASSERT(reporter, line[0] == line2[0] && line[1] == line2[1]); | 39 REPORTER_ASSERT(reporter, line[0] == line2[0] && line[1] == line2[1]); |
39 const SkDPoint& pt = left[index]; | 40 const SkDPoint& pt = left[index]; |
40 SkASSERT(ValidPoint(pt)); | 41 SkASSERT(ValidPoint(pt)); |
41 double result = line.isLeft(pt); | 42 double result = line.isLeft(pt); |
42 if ((result <= 0 && index >= 1) || (result < 0 && index == 0)) { | 43 if ((result <= 0 && index >= 1) || (result < 0 && index == 0)) { |
43 SkDebugf("%s [%d] expected left\n", __FUNCTION__, index); | 44 SkDebugf("%s [%d] expected left\n", __FUNCTION__, index); |
44 REPORTER_ASSERT(reporter, 0); | 45 REPORTER_ASSERT(reporter, 0); |
45 } | 46 } |
46 line2 = line.subDivide(1, 0); | 47 line2 = line.subDivide(1, 0); |
47 REPORTER_ASSERT(reporter, line[0] == line2[1] && line[1] == line2[0]); | 48 REPORTER_ASSERT(reporter, line[0] == line2[1] && line[1] == line2[0]); |
48 line2 = SkDLine::SubDivide(pts, 1, 0); | 49 line2 = SkDLine::SubDivide(pts, 1, 0); |
49 REPORTER_ASSERT(reporter, line[0] == line2[1] && line[1] == line2[0]); | 50 REPORTER_ASSERT(reporter, line[0] == line2[1] && line[1] == line2[0]); |
50 SkDPoint mid = line.ptAtT(.5); | 51 SkDPoint mid = line.ptAtT(.5); |
51 REPORTER_ASSERT(reporter, approximately_equal((line[0].fX + line[1].fX)
/ 2, mid.fX)); | 52 REPORTER_ASSERT(reporter, approximately_equal((line[0].fX + line[1].fX)
/ 2, mid.fX)); |
52 REPORTER_ASSERT(reporter, approximately_equal((line[0].fY + line[1].fY)
/ 2, mid.fY)); | 53 REPORTER_ASSERT(reporter, approximately_equal((line[0].fY + line[1].fY)
/ 2, mid.fY)); |
53 } | 54 } |
54 } | 55 } |
55 | |
56 #include "TestClassDef.h" | |
57 DEFINE_TESTCLASS_SHORT(PathOpsLineUtilitiesTest) | |
OLD | NEW |