| 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 "SkIntersections.h" | 8 #include "SkIntersections.h" |
| 8 #include "SkPathOpsLine.h" | 9 #include "SkPathOpsLine.h" |
| 9 #include "Test.h" | 10 #include "Test.h" |
| 10 | 11 |
| 11 // FIXME: add tests for intersecting, non-intersecting, degenerate, coincident | 12 // FIXME: add tests for intersecting, non-intersecting, degenerate, coincident |
| 12 static const SkDLine tests[][2] = { | 13 static const SkDLine tests[][2] = { |
| 13 #if 0 // FIXME: these fail because one line is too short and appears quasi-coin
cident | 14 #if 0 // FIXME: these fail because one line is too short and appears quasi-coin
cident |
| 14 {{{{158.000000, 926.000000}, {1108.00000, 926.000000}}}, | 15 {{{{158.000000, 926.000000}, {1108.00000, 926.000000}}}, |
| 15 {{{1108.00000, 926.000000}, {1108.00000, 925.999634}}}}, | 16 {{{1108.00000, 926.000000}, {1108.00000, 925.999634}}}}, |
| 16 {{{{1108,926}, {1108,925.9996337890625}}}, {{{158,926}, {1108,926}}}}, | 17 {{{{1108,926}, {1108,925.9996337890625}}}, {{{158,926}, {1108,926}}}}, |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 if (!result1.approximatelyEqual(result2)) { | 55 if (!result1.approximatelyEqual(result2)) { |
| 55 REPORTER_ASSERT(reporter, ts.used() != 1); | 56 REPORTER_ASSERT(reporter, ts.used() != 1); |
| 56 result2 = line2.xyAtT(ts[1][i ^ 1]); | 57 result2 = line2.xyAtT(ts[1][i ^ 1]); |
| 57 REPORTER_ASSERT(reporter, result1.approximatelyEqual(result2)); | 58 REPORTER_ASSERT(reporter, result1.approximatelyEqual(result2)); |
| 58 REPORTER_ASSERT(reporter, result1.approximatelyEqual(ts.pt(i).asSkPo
int())); | 59 REPORTER_ASSERT(reporter, result1.approximatelyEqual(ts.pt(i).asSkPo
int())); |
| 59 } | 60 } |
| 60 } | 61 } |
| 61 } | 62 } |
| 62 | 63 |
| 63 static void testOne(skiatest::Reporter* reporter, const SkDLine& line1, const Sk
DLine& line2) { | 64 static void testOne(skiatest::Reporter* reporter, const SkDLine& line1, const Sk
DLine& line2) { |
| 65 SkASSERT(ValidLine(line1)); |
| 66 SkASSERT(ValidLine(line2)); |
| 64 SkIntersections i; | 67 SkIntersections i; |
| 65 int pts = i.intersect(line1, line2); | 68 int pts = i.intersect(line1, line2); |
| 66 REPORTER_ASSERT(reporter, pts); | 69 REPORTER_ASSERT(reporter, pts); |
| 67 REPORTER_ASSERT(reporter, pts == i.used()); | 70 REPORTER_ASSERT(reporter, pts == i.used()); |
| 68 check_results(reporter, line1, line2, i); | 71 check_results(reporter, line1, line2, i); |
| 69 if (line1[0] == line1[1] || line2[0] == line2[1]) { | 72 if (line1[0] == line1[1] || line2[0] == line2[1]) { |
| 70 return; | 73 return; |
| 71 } | 74 } |
| 72 if (line1[0].fY == line1[1].fY) { | 75 if (line1[0].fY == line1[1].fY) { |
| 73 double left = SkTMin(line1[0].fX, line1[1].fX); | 76 double left = SkTMin(line1[0].fX, line1[1].fX); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 94 double top = SkTMin(line2[0].fY, line2[1].fY); | 97 double top = SkTMin(line2[0].fY, line2[1].fY); |
| 95 double bottom = SkTMax(line2[0].fY, line2[1].fY); | 98 double bottom = SkTMax(line2[0].fY, line2[1].fY); |
| 96 SkIntersections ts; | 99 SkIntersections ts; |
| 97 ts.vertical(line1, top, bottom, line2[0].fX, line2[0].fY != top); | 100 ts.vertical(line1, top, bottom, line2[0].fX, line2[0].fY != top); |
| 98 check_results(reporter, line1, line2, ts); | 101 check_results(reporter, line1, line2, ts); |
| 99 } | 102 } |
| 100 } | 103 } |
| 101 | 104 |
| 102 static void testOneCoincident(skiatest::Reporter* reporter, const SkDLine& line1
, | 105 static void testOneCoincident(skiatest::Reporter* reporter, const SkDLine& line1
, |
| 103 const SkDLine& line2) { | 106 const SkDLine& line2) { |
| 107 SkASSERT(ValidLine(line1)); |
| 108 SkASSERT(ValidLine(line2)); |
| 104 SkIntersections ts2; | 109 SkIntersections ts2; |
| 105 int pts2 = ts2.intersect(line1, line2); | 110 int pts2 = ts2.intersect(line1, line2); |
| 106 REPORTER_ASSERT(reporter, pts2 == 2); | 111 REPORTER_ASSERT(reporter, pts2 == 2); |
| 107 REPORTER_ASSERT(reporter, pts2 == ts2.used()); | 112 REPORTER_ASSERT(reporter, pts2 == ts2.used()); |
| 108 check_results(reporter, line1, line2, ts2); | 113 check_results(reporter, line1, line2, ts2); |
| 109 #if 0 | 114 #if 0 |
| 110 SkIntersections ts; | 115 SkIntersections ts; |
| 111 int pts = ts.intersect(line1, line2); | 116 int pts = ts.intersect(line1, line2); |
| 112 REPORTER_ASSERT(reporter, pts == pts2); | 117 REPORTER_ASSERT(reporter, pts == pts2); |
| 113 REPORTER_ASSERT(reporter, pts == 2); | 118 REPORTER_ASSERT(reporter, pts == 2); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 const SkDLine& line2 = coincidentTests[index][1]; | 161 const SkDLine& line2 = coincidentTests[index][1]; |
| 157 testOneCoincident(reporter, line1, line2); | 162 testOneCoincident(reporter, line1, line2); |
| 158 } | 163 } |
| 159 | 164 |
| 160 #include "TestClassDef.h" | 165 #include "TestClassDef.h" |
| 161 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTest) | 166 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTest) |
| 162 | 167 |
| 163 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTestOne) | 168 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTestOne) |
| 164 | 169 |
| 165 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTestOneCoincident) | 170 DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTestOneCoincident) |
| OLD | NEW |