blob: d0b5731fbd6939fa9e27030e9eb4d56ac6a3eb15 [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] = {
13 {{{{0, 0}, {1, 0}}}, {{{1, 0}, {0, 0}}}},
14 {{{{0, 0}, {0, 0}}}, {{{0, 0}, {1, 0}}}},
15 {{{{0, 1}, {0, 1}}}, {{{0, 0}, {0, 2}}}},
16 {{{{0, 0}, {1, 0}}}, {{{0, 0}, {2, 0}}}},
17 {{{{1, 1}, {2, 2}}}, {{{0, 0}, {3, 3}}}},
18 {{{{166.86950047022856, 112.69654129527828}, {166.86948801592692, 112.69655741235339}}},
19 {{{166.86960700313026, 112.6965477747386}, {166.86925794355412, 112.69656471103423}}}}
20};
21
caryclark@google.comad65a3e2013-04-15 19:13:59 +000022static const size_t tests_count = SK_ARRAY_COUNT(tests);
caryclark@google.com9166dcb2013-04-08 11:50:00 +000023
24static const SkDLine noIntersect[][2] = {
25 {{{{0, 0}, {1, 0}}}, {{{3, 0}, {2, 0}}}},
26 {{{{0, 0}, {0, 0}}}, {{{1, 0}, {2, 0}}}},
27 {{{{0, 1}, {0, 1}}}, {{{0, 3}, {0, 2}}}},
28 {{{{0, 0}, {1, 0}}}, {{{2, 0}, {3, 0}}}},
29 {{{{1, 1}, {2, 2}}}, {{{4, 4}, {3, 3}}}},
30};
31
caryclark@google.comad65a3e2013-04-15 19:13:59 +000032static const size_t noIntersect_count = SK_ARRAY_COUNT(noIntersect);
caryclark@google.com9166dcb2013-04-08 11:50:00 +000033
caryclark@google.comad65a3e2013-04-15 19:13:59 +000034static void PathOpsLineIntersectionTest(skiatest::Reporter* reporter) {
caryclark@google.com9166dcb2013-04-08 11:50:00 +000035 size_t index;
36 for (index = 0; index < tests_count; ++index) {
37 const SkDLine& line1 = tests[index][0];
38 const SkDLine& line2 = tests[index][1];
39 SkIntersections ts;
40 int pts = ts.intersect(line1, line2);
41 REPORTER_ASSERT(reporter, pts);
42 for (int i = 0; i < pts; ++i) {
43 SkDPoint result1 = line1.xyAtT(ts[0][i]);
44 SkDPoint result2 = line2.xyAtT(ts[1][i]);
45 if (!result1.approximatelyEqual(result2)) {
46 REPORTER_ASSERT(reporter, pts != 1);
47 result2 = line2.xyAtT(ts[1][i ^ 1]);
48 REPORTER_ASSERT(reporter, result1.approximatelyEqual(result2));
49 }
50 }
51 }
52 for (index = 0; index < noIntersect_count; ++index) {
53 const SkDLine& line1 = noIntersect[index][0];
54 const SkDLine& line2 = noIntersect[index][1];
55 SkIntersections ts;
56 int pts = ts.intersect(line1, line2);
57 REPORTER_ASSERT(reporter, !pts); }
58}
59
60#include "TestClassDef.h"
caryclark@google.comad65a3e2013-04-15 19:13:59 +000061DEFINE_TESTCLASS_SHORT(PathOpsLineIntersectionTest)