| 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 {{{{90,230}, {160,60}}}, {{{60,120}, {260,120}}}}, |
| 15 {{{{90,230}, {160,60}}}, {{{181.176468,120}, {135.294128,120}}}}, |
| 14 {{{{181.1764678955078125f, 120}, {186.3661956787109375f, 134.7042236328125f}
}}, | 16 {{{{181.1764678955078125f, 120}, {186.3661956787109375f, 134.7042236328125f}
}}, |
| 15 {{{175.8309783935546875f, 141.5211334228515625f}, {187.8782806396484375f, 1
33.7258148193359375f}}}}, | 17 {{{175.8309783935546875f, 141.5211334228515625f}, {187.8782806396484375f, 1
33.7258148193359375f}}}}, |
| 16 #if 0 // FIXME: these fail because one line is too short and appears quasi-coin
cident | 18 #if 0 // FIXME: these fail because one line is too short and appears quasi-coin
cident |
| 17 {{{{158.000000, 926.000000}, {1108.00000, 926.000000}}}, | 19 {{{{158.000000, 926.000000}, {1108.00000, 926.000000}}}, |
| 18 {{{1108.00000, 926.000000}, {1108.00000, 925.999634}}}}, | 20 {{{1108.00000, 926.000000}, {1108.00000, 925.999634}}}}, |
| 19 {{{{1108,926}, {1108,925.9996337890625}}}, {{{158,926}, {1108,926}}}}, | 21 {{{{1108,926}, {1108,925.9996337890625}}}, {{{158,926}, {1108,926}}}}, |
| 20 #endif | 22 #endif |
| 21 {{{{192, 4}, {243, 4}}}, {{{246, 4}, {189, 4}}}}, | 23 {{{{192, 4}, {243, 4}}}, {{{246, 4}, {189, 4}}}}, |
| 22 {{{{246, 4}, {189, 4}}}, {{{192, 4}, {243, 4}}}}, | 24 {{{{246, 4}, {189, 4}}}, {{{192, 4}, {243, 4}}}}, |
| 23 {{{{5, 0}, {0, 5}}}, {{{5, 4}, {1, 4}}}}, | 25 {{{{5, 0}, {0, 5}}}, {{{5, 4}, {1, 4}}}}, |
| 24 {{{{0, 0}, {1, 0}}}, {{{1, 0}, {0, 0}}}}, | 26 {{{{0, 0}, {1, 0}}}, {{{1, 0}, {0, 0}}}}, |
| 25 {{{{0, 0}, {0, 0}}}, {{{0, 0}, {1, 0}}}}, | 27 {{{{0, 0}, {0, 0}}}, {{{0, 0}, {1, 0}}}}, |
| 26 {{{{0, 1}, {0, 1}}}, {{{0, 0}, {0, 2}}}}, | 28 {{{{0, 1}, {0, 1}}}, {{{0, 0}, {0, 2}}}}, |
| 27 {{{{0, 0}, {1, 0}}}, {{{0, 0}, {2, 0}}}}, | 29 {{{{0, 0}, {1, 0}}}, {{{0, 0}, {2, 0}}}}, |
| 28 {{{{1, 1}, {2, 2}}}, {{{0, 0}, {3, 3}}}}, | 30 {{{{1, 1}, {2, 2}}}, {{{0, 0}, {3, 3}}}}, |
| 29 {{{{166.86950047022856, 112.69654129527828}, {166.86948801592692, 112.696557
41235339}}}, | 31 {{{{166.86950047022856, 112.69654129527828}, {166.86948801592692, 112.696557
41235339}}}, |
| 30 {{{166.86960700313026, 112.6965477747386}, {166.86925794355412, 112.6965647
1103423}}}} | 32 {{{166.86960700313026, 112.6965477747386}, {166.86925794355412, 112.6965647
1103423}}}} |
| 31 }; | 33 }; |
| 32 | 34 |
| 33 static const size_t tests_count = SK_ARRAY_COUNT(tests); | 35 static const size_t tests_count = SK_ARRAY_COUNT(tests); |
| 34 | 36 |
| 35 static const SkDLine noIntersect[][2] = { | 37 static const SkDLine noIntersect[][2] = { |
| 38 {{{{(double) (2 - 1e-6f),2}, {(double) (2 - 1e-6f),4}}}, |
| 39 {{{2,1}, {2,3}}}}, |
| 40 |
| 36 {{{{0, 0}, {1, 0}}}, {{{3, 0}, {2, 0}}}}, | 41 {{{{0, 0}, {1, 0}}}, {{{3, 0}, {2, 0}}}}, |
| 37 {{{{0, 0}, {0, 0}}}, {{{1, 0}, {2, 0}}}}, | 42 {{{{0, 0}, {0, 0}}}, {{{1, 0}, {2, 0}}}}, |
| 38 {{{{0, 1}, {0, 1}}}, {{{0, 3}, {0, 2}}}}, | 43 {{{{0, 1}, {0, 1}}}, {{{0, 3}, {0, 2}}}}, |
| 39 {{{{0, 0}, {1, 0}}}, {{{2, 0}, {3, 0}}}}, | 44 {{{{0, 0}, {1, 0}}}, {{{2, 0}, {3, 0}}}}, |
| 40 {{{{1, 1}, {2, 2}}}, {{{4, 4}, {3, 3}}}}, | 45 {{{{1, 1}, {2, 2}}}, {{{4, 4}, {3, 3}}}}, |
| 41 }; | 46 }; |
| 42 | 47 |
| 43 static const size_t noIntersect_count = SK_ARRAY_COUNT(noIntersect); | 48 static const size_t noIntersect_count = SK_ARRAY_COUNT(noIntersect); |
| 44 | 49 |
| 45 static const SkDLine coincidentTests[][2] = { | 50 static const SkDLine coincidentTests[][2] = { |
| 51 {{{{979.304871, 561}, {1036.69507, 291}}}, |
| 52 {{{985.681519, 531}, {982.159790, 547.568542}}}}, |
| 53 |
| 54 {{{{232.159805, 547.568542}, {235.681549, 531}}}, |
| 55 {{{286.695129,291}, {229.304855,561}}}}, |
| 56 |
| 46 {{{{186.3661956787109375f, 134.7042236328125f}, {187.8782806396484375f, 133.
7258148193359375f}}}, | 57 {{{{186.3661956787109375f, 134.7042236328125f}, {187.8782806396484375f, 133.
7258148193359375f}}}, |
| 47 {{{175.8309783935546875f, 141.5211334228515625f}, {187.8782806396484375f, 1
33.7258148193359375f}}}}, | 58 {{{175.8309783935546875f, 141.5211334228515625f}, {187.8782806396484375f, 1
33.7258148193359375f}}}}, |
| 48 | 59 |
| 49 {{{{235.681549, 531.000000}, {280.318420, 321.000000}}}, | 60 {{{{235.681549, 531.000000}, {280.318420, 321.000000}}}, |
| 50 {{{286.695129, 291.000000}, {229.304855, 561.000000}}}}, | 61 {{{286.695129, 291.000000}, {229.304855, 561.000000}}}}, |
| 51 }; | 62 }; |
| 52 | 63 |
| 53 static const size_t coincidentTests_count = SK_ARRAY_COUNT(coincidentTests); | 64 static const size_t coincidentTests_count = SK_ARRAY_COUNT(coincidentTests); |
| 54 | 65 |
| 55 static void check_results(skiatest::Reporter* reporter, const SkDLine& line1, co
nst SkDLine& line2, | 66 static void check_results(skiatest::Reporter* reporter, const SkDLine& line1, co
nst SkDLine& line2, |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 104 SkIntersections ts; | 115 SkIntersections ts; |
| 105 ts.vertical(line1, top, bottom, line2[0].fX, line2[0].fY != top); | 116 ts.vertical(line1, top, bottom, line2[0].fX, line2[0].fY != top); |
| 106 check_results(reporter, line1, line2, ts); | 117 check_results(reporter, line1, line2, ts); |
| 107 } | 118 } |
| 108 } | 119 } |
| 109 | 120 |
| 110 static void testOneCoincident(skiatest::Reporter* reporter, const SkDLine& line1
, | 121 static void testOneCoincident(skiatest::Reporter* reporter, const SkDLine& line1
, |
| 111 const SkDLine& line2) { | 122 const SkDLine& line2) { |
| 112 SkASSERT(ValidLine(line1)); | 123 SkASSERT(ValidLine(line1)); |
| 113 SkASSERT(ValidLine(line2)); | 124 SkASSERT(ValidLine(line2)); |
| 114 SkIntersections ts2; | |
| 115 int pts2 = ts2.intersect(line1, line2); | |
| 116 REPORTER_ASSERT(reporter, pts2 == 2); | |
| 117 REPORTER_ASSERT(reporter, pts2 == ts2.used()); | |
| 118 check_results(reporter, line1, line2, ts2); | |
| 119 #if 0 | |
| 120 SkIntersections ts; | 125 SkIntersections ts; |
| 121 int pts = ts.intersect(line1, line2); | 126 int pts = ts.intersect(line1, line2); |
| 122 REPORTER_ASSERT(reporter, pts == pts2); | |
| 123 REPORTER_ASSERT(reporter, pts == 2); | 127 REPORTER_ASSERT(reporter, pts == 2); |
| 124 REPORTER_ASSERT(reporter, pts == ts.used()); | 128 REPORTER_ASSERT(reporter, pts == ts.used()); |
| 125 check_results(reporter, line1, line2, ts); | 129 check_results(reporter, line1, line2, ts); |
| 126 #endif | |
| 127 } | 130 } |
| 128 | 131 |
| 129 static void PathOpsLineIntersectionTest(skiatest::Reporter* reporter) { | 132 static void PathOpsLineIntersectionTest(skiatest::Reporter* reporter) { |
| 130 size_t index; | 133 size_t index; |
| 131 for (index = 0; index < coincidentTests_count; ++index) { | 134 for (index = 0; index < coincidentTests_count; ++index) { |
| 132 const SkDLine& line1 = coincidentTests[index][0]; | 135 const SkDLine& line1 = coincidentTests[index][0]; |
| 133 const SkDLine& line2 = coincidentTests[index][1]; | 136 const SkDLine& line2 = coincidentTests[index][1]; |
| 134 testOneCoincident(reporter, line1, line2); | 137 testOneCoincident(reporter, line1, line2); |
| 135 reporter->bumpTestCount(); | 138 reporter->bumpTestCount(); |
| 136 } | 139 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 147 int pts = ts.intersect(line1, line2); | 150 int pts = ts.intersect(line1, line2); |
| 148 REPORTER_ASSERT(reporter, !pts); | 151 REPORTER_ASSERT(reporter, !pts); |
| 149 REPORTER_ASSERT(reporter, pts == ts.used()); | 152 REPORTER_ASSERT(reporter, pts == ts.used()); |
| 150 reporter->bumpTestCount(); | 153 reporter->bumpTestCount(); |
| 151 } | 154 } |
| 152 } | 155 } |
| 153 | 156 |
| 154 static void PathOpsLineIntersectionOneOffTest(skiatest::Reporter* reporter) { | 157 static void PathOpsLineIntersectionOneOffTest(skiatest::Reporter* reporter) { |
| 155 int index = 0; | 158 int index = 0; |
| 156 SkASSERT(index < (int) tests_count); | 159 SkASSERT(index < (int) tests_count); |
| 157 const SkDLine& line1 = tests[index][0]; | 160 testOne(reporter, tests[index][0], tests[index][1]); |
| 158 const SkDLine& line2 = tests[index][1]; | 161 testOne(reporter, tests[1][0], tests[1][1]); |
| 159 testOne(reporter, line1, line2); | |
| 160 } | 162 } |
| 161 | 163 |
| 162 static void PathOpsLineIntersectionOneCoincidentTest(skiatest::Reporter* reporte
r) { | 164 static void PathOpsLineIntersectionOneCoincidentTest(skiatest::Reporter* reporte
r) { |
| 163 int index = 0; | 165 int index = 0; |
| 164 SkASSERT(index < (int) coincidentTests_count); | 166 SkASSERT(index < (int) coincidentTests_count); |
| 165 const SkDLine& line1 = coincidentTests[index][0]; | 167 const SkDLine& line1 = coincidentTests[index][0]; |
| 166 const SkDLine& line2 = coincidentTests[index][1]; | 168 const SkDLine& line2 = coincidentTests[index][1]; |
| 167 testOneCoincident(reporter, line1, line2); | 169 testOneCoincident(reporter, line1, line2); |
| 168 } | 170 } |
| 169 | 171 |
| 170 #include "TestClassDef.h" | 172 #include "TestClassDef.h" |
| 171 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTest) | 173 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTest) |
| 172 | 174 |
| 173 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionOneOffTest) | 175 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionOneOffTest) |
| 174 | 176 |
| 175 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionOneCoincidentTest) | 177 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionOneCoincidentTest) |
| OLD | NEW |