caryclark@google.com | 9166dcb | 2013-04-08 11:50:00 +0000 | [diff] [blame] | 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 "SkIntersections.h" |
| 8 | #include "SkPathOpsLine.h" |
| 9 | #include "Test.h" |
| 10 | |
| 11 | // FIXME: add tests for intersecting, non-intersecting, degenerate, coincident |
| 12 | static const SkDLine tests[][2] = { |
caryclark@google.com | 0361032 | 2013-04-18 15:58:21 +0000 | [diff] [blame] | 13 | {{{{5, 0}, {0, 5}}}, {{{5, 4}, {1, 4}}}}, |
caryclark@google.com | 9166dcb | 2013-04-08 11:50:00 +0000 | [diff] [blame] | 14 | {{{{0, 0}, {1, 0}}}, {{{1, 0}, {0, 0}}}}, |
| 15 | {{{{0, 0}, {0, 0}}}, {{{0, 0}, {1, 0}}}}, |
| 16 | {{{{0, 1}, {0, 1}}}, {{{0, 0}, {0, 2}}}}, |
| 17 | {{{{0, 0}, {1, 0}}}, {{{0, 0}, {2, 0}}}}, |
| 18 | {{{{1, 1}, {2, 2}}}, {{{0, 0}, {3, 3}}}}, |
| 19 | {{{{166.86950047022856, 112.69654129527828}, {166.86948801592692, 112.69655741235339}}}, |
| 20 | {{{166.86960700313026, 112.6965477747386}, {166.86925794355412, 112.69656471103423}}}} |
| 21 | }; |
| 22 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 23 | static const size_t tests_count = SK_ARRAY_COUNT(tests); |
caryclark@google.com | 9166dcb | 2013-04-08 11:50:00 +0000 | [diff] [blame] | 24 | |
| 25 | static const SkDLine noIntersect[][2] = { |
| 26 | {{{{0, 0}, {1, 0}}}, {{{3, 0}, {2, 0}}}}, |
| 27 | {{{{0, 0}, {0, 0}}}, {{{1, 0}, {2, 0}}}}, |
| 28 | {{{{0, 1}, {0, 1}}}, {{{0, 3}, {0, 2}}}}, |
| 29 | {{{{0, 0}, {1, 0}}}, {{{2, 0}, {3, 0}}}}, |
| 30 | {{{{1, 1}, {2, 2}}}, {{{4, 4}, {3, 3}}}}, |
| 31 | }; |
| 32 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 33 | static const size_t noIntersect_count = SK_ARRAY_COUNT(noIntersect); |
caryclark@google.com | 9166dcb | 2013-04-08 11:50:00 +0000 | [diff] [blame] | 34 | |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 35 | static void PathOpsLineIntersectionTest(skiatest::Reporter* reporter) { |
caryclark@google.com | 9166dcb | 2013-04-08 11:50:00 +0000 | [diff] [blame] | 36 | size_t index; |
| 37 | for (index = 0; index < tests_count; ++index) { |
| 38 | const SkDLine& line1 = tests[index][0]; |
| 39 | const SkDLine& line2 = tests[index][1]; |
| 40 | SkIntersections ts; |
| 41 | int pts = ts.intersect(line1, line2); |
| 42 | REPORTER_ASSERT(reporter, pts); |
| 43 | for (int i = 0; i < pts; ++i) { |
| 44 | SkDPoint result1 = line1.xyAtT(ts[0][i]); |
| 45 | SkDPoint result2 = line2.xyAtT(ts[1][i]); |
| 46 | if (!result1.approximatelyEqual(result2)) { |
| 47 | REPORTER_ASSERT(reporter, pts != 1); |
| 48 | result2 = line2.xyAtT(ts[1][i ^ 1]); |
| 49 | REPORTER_ASSERT(reporter, result1.approximatelyEqual(result2)); |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 | for (index = 0; index < noIntersect_count; ++index) { |
| 54 | const SkDLine& line1 = noIntersect[index][0]; |
| 55 | const SkDLine& line2 = noIntersect[index][1]; |
| 56 | SkIntersections ts; |
| 57 | int pts = ts.intersect(line1, line2); |
| 58 | REPORTER_ASSERT(reporter, !pts); } |
| 59 | } |
| 60 | |
| 61 | #include "TestClassDef.h" |
caryclark@google.com | ad65a3e | 2013-04-15 19:13:59 +0000 | [diff] [blame] | 62 | DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTest) |