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 "SkIntersections.h" | 8 #include "SkIntersections.h" |
9 #include "SkPathOpsLine.h" | 9 #include "SkPathOpsLine.h" |
10 #include "Test.h" | 10 #include "Test.h" |
11 | 11 |
12 // FIXME: add tests for intersecting, non-intersecting, degenerate, coincident | 12 // FIXME: add tests for intersecting, non-intersecting, degenerate, coincident |
13 static const SkDLine tests[][2] = { | 13 static const SkDLine tests[][2] = { |
| 14 {{{{181.1764678955078125f, 120}, {186.3661956787109375f, 134.7042236328125f}
}}, |
| 15 {{{175.8309783935546875f, 141.5211334228515625f}, {187.8782806396484375f, 1
33.7258148193359375f}}}}, |
14 #if 0 // FIXME: these fail because one line is too short and appears quasi-coin
cident | 16 #if 0 // FIXME: these fail because one line is too short and appears quasi-coin
cident |
15 {{{{158.000000, 926.000000}, {1108.00000, 926.000000}}}, | 17 {{{{158.000000, 926.000000}, {1108.00000, 926.000000}}}, |
16 {{{1108.00000, 926.000000}, {1108.00000, 925.999634}}}}, | 18 {{{1108.00000, 926.000000}, {1108.00000, 925.999634}}}}, |
17 {{{{1108,926}, {1108,925.9996337890625}}}, {{{158,926}, {1108,926}}}}, | 19 {{{{1108,926}, {1108,925.9996337890625}}}, {{{158,926}, {1108,926}}}}, |
18 #endif | 20 #endif |
19 {{{{192, 4}, {243, 4}}}, {{{246, 4}, {189, 4}}}}, | 21 {{{{192, 4}, {243, 4}}}, {{{246, 4}, {189, 4}}}}, |
20 {{{{246, 4}, {189, 4}}}, {{{192, 4}, {243, 4}}}}, | 22 {{{{246, 4}, {189, 4}}}, {{{192, 4}, {243, 4}}}}, |
21 {{{{5, 0}, {0, 5}}}, {{{5, 4}, {1, 4}}}}, | 23 {{{{5, 0}, {0, 5}}}, {{{5, 4}, {1, 4}}}}, |
22 {{{{0, 0}, {1, 0}}}, {{{1, 0}, {0, 0}}}}, | 24 {{{{0, 0}, {1, 0}}}, {{{1, 0}, {0, 0}}}}, |
23 {{{{0, 0}, {0, 0}}}, {{{0, 0}, {1, 0}}}}, | 25 {{{{0, 0}, {0, 0}}}, {{{0, 0}, {1, 0}}}}, |
(...skipping 10 matching lines...) Expand all Loading... |
34 {{{{0, 0}, {1, 0}}}, {{{3, 0}, {2, 0}}}}, | 36 {{{{0, 0}, {1, 0}}}, {{{3, 0}, {2, 0}}}}, |
35 {{{{0, 0}, {0, 0}}}, {{{1, 0}, {2, 0}}}}, | 37 {{{{0, 0}, {0, 0}}}, {{{1, 0}, {2, 0}}}}, |
36 {{{{0, 1}, {0, 1}}}, {{{0, 3}, {0, 2}}}}, | 38 {{{{0, 1}, {0, 1}}}, {{{0, 3}, {0, 2}}}}, |
37 {{{{0, 0}, {1, 0}}}, {{{2, 0}, {3, 0}}}}, | 39 {{{{0, 0}, {1, 0}}}, {{{2, 0}, {3, 0}}}}, |
38 {{{{1, 1}, {2, 2}}}, {{{4, 4}, {3, 3}}}}, | 40 {{{{1, 1}, {2, 2}}}, {{{4, 4}, {3, 3}}}}, |
39 }; | 41 }; |
40 | 42 |
41 static const size_t noIntersect_count = SK_ARRAY_COUNT(noIntersect); | 43 static const size_t noIntersect_count = SK_ARRAY_COUNT(noIntersect); |
42 | 44 |
43 static const SkDLine coincidentTests[][2] = { | 45 static const SkDLine coincidentTests[][2] = { |
| 46 {{{{186.3661956787109375f, 134.7042236328125f}, {187.8782806396484375f, 133.
7258148193359375f}}}, |
| 47 {{{175.8309783935546875f, 141.5211334228515625f}, {187.8782806396484375f, 1
33.7258148193359375f}}}}, |
| 48 |
44 {{{{235.681549, 531.000000}, {280.318420, 321.000000}}}, | 49 {{{{235.681549, 531.000000}, {280.318420, 321.000000}}}, |
45 {{{286.695129, 291.000000}, {229.304855, 561.000000}}}}, | 50 {{{286.695129, 291.000000}, {229.304855, 561.000000}}}}, |
46 }; | 51 }; |
47 | 52 |
48 static const size_t coincidentTests_count = SK_ARRAY_COUNT(coincidentTests); | 53 static const size_t coincidentTests_count = SK_ARRAY_COUNT(coincidentTests); |
49 | 54 |
50 static void check_results(skiatest::Reporter* reporter, const SkDLine& line1, co
nst SkDLine& line2, | 55 static void check_results(skiatest::Reporter* reporter, const SkDLine& line1, co
nst SkDLine& line2, |
51 const SkIntersections& ts) { | 56 const SkIntersections& ts) { |
52 for (int i = 0; i < ts.used(); ++i) { | 57 for (int i = 0; i < ts.used(); ++i) { |
53 SkDPoint result1 = line1.xyAtT(ts[0][i]); | 58 SkDPoint result1 = line1.ptAtT(ts[0][i]); |
54 SkDPoint result2 = line2.xyAtT(ts[1][i]); | 59 SkDPoint result2 = line2.ptAtT(ts[1][i]); |
55 if (!result1.approximatelyEqual(result2)) { | 60 if (!result1.approximatelyEqual(result2)) { |
56 REPORTER_ASSERT(reporter, ts.used() != 1); | 61 REPORTER_ASSERT(reporter, ts.used() != 1); |
57 result2 = line2.xyAtT(ts[1][i ^ 1]); | 62 result2 = line2.ptAtT(ts[1][i ^ 1]); |
58 REPORTER_ASSERT(reporter, result1.approximatelyEqual(result2)); | 63 REPORTER_ASSERT(reporter, result1.approximatelyEqual(result2)); |
59 REPORTER_ASSERT(reporter, result1.approximatelyEqual(ts.pt(i).asSkPo
int())); | 64 REPORTER_ASSERT(reporter, result1.approximatelyEqual(ts.pt(i).asSkPo
int())); |
60 } | 65 } |
61 } | 66 } |
62 } | 67 } |
63 | 68 |
64 static void testOne(skiatest::Reporter* reporter, const SkDLine& line1, const Sk
DLine& line2) { | 69 static void testOne(skiatest::Reporter* reporter, const SkDLine& line1, const Sk
DLine& line2) { |
65 SkASSERT(ValidLine(line1)); | 70 SkASSERT(ValidLine(line1)); |
66 SkASSERT(ValidLine(line2)); | 71 SkASSERT(ValidLine(line2)); |
67 SkIntersections i; | 72 SkIntersections i; |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 const SkDLine& line1 = noIntersect[index][0]; | 144 const SkDLine& line1 = noIntersect[index][0]; |
140 const SkDLine& line2 = noIntersect[index][1]; | 145 const SkDLine& line2 = noIntersect[index][1]; |
141 SkIntersections ts; | 146 SkIntersections ts; |
142 int pts = ts.intersect(line1, line2); | 147 int pts = ts.intersect(line1, line2); |
143 REPORTER_ASSERT(reporter, !pts); | 148 REPORTER_ASSERT(reporter, !pts); |
144 REPORTER_ASSERT(reporter, pts == ts.used()); | 149 REPORTER_ASSERT(reporter, pts == ts.used()); |
145 reporter->bumpTestCount(); | 150 reporter->bumpTestCount(); |
146 } | 151 } |
147 } | 152 } |
148 | 153 |
149 static void PathOpsLineIntersectionTestOne(skiatest::Reporter* reporter) { | 154 static void PathOpsLineIntersectionOneOffTest(skiatest::Reporter* reporter) { |
150 int index = 0; | 155 int index = 0; |
151 SkASSERT(index < (int) tests_count); | 156 SkASSERT(index < (int) tests_count); |
152 const SkDLine& line1 = tests[index][0]; | 157 const SkDLine& line1 = tests[index][0]; |
153 const SkDLine& line2 = tests[index][1]; | 158 const SkDLine& line2 = tests[index][1]; |
154 testOne(reporter, line1, line2); | 159 testOne(reporter, line1, line2); |
155 } | 160 } |
156 | 161 |
157 static void PathOpsLineIntersectionTestOneCoincident(skiatest::Reporter* reporte
r) { | 162 static void PathOpsLineIntersectionOneCoincidentTest(skiatest::Reporter* reporte
r) { |
158 int index = 0; | 163 int index = 0; |
159 SkASSERT(index < (int) coincidentTests_count); | 164 SkASSERT(index < (int) coincidentTests_count); |
160 const SkDLine& line1 = coincidentTests[index][0]; | 165 const SkDLine& line1 = coincidentTests[index][0]; |
161 const SkDLine& line2 = coincidentTests[index][1]; | 166 const SkDLine& line2 = coincidentTests[index][1]; |
162 testOneCoincident(reporter, line1, line2); | 167 testOneCoincident(reporter, line1, line2); |
163 } | 168 } |
164 | 169 |
165 #include "TestClassDef.h" | 170 #include "TestClassDef.h" |
166 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTest) | 171 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTest) |
167 | 172 |
168 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTestOne) | 173 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionOneOffTest) |
169 | 174 |
170 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTestOneCoincident) | 175 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionOneCoincidentTest) |
OLD | NEW |