OLD | NEW |
---|---|
(Empty) | |
1 /* | |
2 * Copyright 2012 Google Inc. | |
3 * | |
4 * Use of this source code is governed by a BSD-style license that can be | |
5 * found in the LICENSE file. | |
6 */ | |
7 #include "SkPathOpsLine.h" | |
8 #include "Test.h" | |
9 | |
10 const SkDLine tests[] = { | |
reed1
2013/03/22 19:00:37
'static' const SkDLine tests[] = { ?
caryclark
2013/03/22 19:38:51
Done.
| |
11 {{{2, 1}, {2, 1}}}, | |
12 {{{2, 1}, {1, 1}}}, | |
13 {{{2, 1}, {2, 2}}}, | |
14 {{{1, 1}, {2, 2}}}, | |
15 {{{3, 0}, {2, 1}}}, | |
16 {{{3, 2}, {1, 1}}}, | |
17 }; | |
18 | |
19 const SkDPoint left[] = { | |
20 {2, 1}, | |
21 {1, 0}, | |
22 {1, 1}, | |
23 {1, 2}, | |
24 {2, 0}, | |
25 {2, 1} | |
26 }; | |
27 | |
28 const size_t tests_count = sizeof(tests) / sizeof(tests[0]); | |
29 static size_t firstDLineTest = 0; | |
30 | |
31 void DLineTest(skiatest::Reporter* reporter) { | |
32 for (size_t index = firstDLineTest; index < tests_count; ++index) { | |
33 const SkDLine& line = tests[index]; | |
34 SkDLine line2; | |
35 SkPoint pts[2] = {line[0].asSkPoint(), line[1].asSkPoint()}; | |
36 line2.set(pts); | |
37 REPORTER_ASSERT(reporter, line[0] == line2[0] && line[1] == line2[1]); | |
38 const SkDPoint& pt = left[index]; | |
39 int result = line.isLeft(pt); | |
40 if ((result <= 0 && index >= 1) || (result < 0 && index == 0)) { | |
41 SkDebugf("%s [%d] expected left\n", __FUNCTION__, index); | |
42 REPORTER_ASSERT(reporter, 0); | |
43 } | |
44 line2 = line.subDivide(1, 0); | |
45 REPORTER_ASSERT(reporter, line[0] == line2[1] && line[1] == line2[0]); | |
46 line2 = SkDLine::SubDivide(pts, 1, 0); | |
47 REPORTER_ASSERT(reporter, line[0] == line2[1] && line[1] == line2[0]); | |
48 SkDPoint mid = line.xyAtT(.5); | |
49 REPORTER_ASSERT(reporter, approximately_equal((line[0].fX + line[1].fX) / 2, mid.fX)); | |
50 REPORTER_ASSERT(reporter, approximately_equal((line[0].fY + line[1].fY) / 2, mid.fY)); | |
51 } | |
52 } | |
53 | |
54 #include "TestClassDef.h" | |
55 DEFINE_TESTCLASS("PathOpsLineUtilities", PathOpsLineUtilitiesClass, DLineTest) | |
OLD | NEW |