blob: 675ce9d9e8ab6c54f45e434cc3809733e6f7a48f [file] [log] [blame]
caryclark@google.com9166dcb2013-04-08 11:50:00 +00001/*
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
12static const SkDLine tests[][2] = {
caryclark@google.com03610322013-04-18 15:58:21 +000013 {{{{5, 0}, {0, 5}}}, {{{5, 4}, {1, 4}}}},
caryclark@google.com9166dcb2013-04-08 11:50:00 +000014 {{{{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.comad65a3e2013-04-15 19:13:59 +000023static const size_t tests_count = SK_ARRAY_COUNT(tests);
caryclark@google.com9166dcb2013-04-08 11:50:00 +000024
25static 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.comad65a3e2013-04-15 19:13:59 +000033static const size_t noIntersect_count = SK_ARRAY_COUNT(noIntersect);
caryclark@google.com9166dcb2013-04-08 11:50:00 +000034
caryclark@google.comad65a3e2013-04-15 19:13:59 +000035static void PathOpsLineIntersectionTest(skiatest::Reporter* reporter) {
caryclark@google.com9166dcb2013-04-08 11:50:00 +000036 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.comad65a3e2013-04-15 19:13:59 +000062DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTest)