1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2011-2015 Barend Gehrels, Amsterdam, the Netherlands.
5
6 // Use, modification and distribution is subject to the Boost Software License,
7 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
8 // http://www.boost.org/LICENSE_1_0.txt)
9
10
11 #include <geometry_test_common.hpp>
12
13 #include <boost/geometry/strategies/cartesian/side_of_intersection.hpp>
14 #include <boost/geometry/geometries/point_xy.hpp>
15 #include <boost/geometry/geometries/segment.hpp>
16
17
18 namespace bg = boost::geometry;
19
test_main(int,char * [])20 int test_main(int, char* [])
21 {
22 typedef bg::model::d2::point_xy<boost::long_long_type> point;
23 typedef bg::model::segment<point> segment;
24
25 typedef bg::strategy::side::side_of_intersection side;
26
27 point no_fb(-99, -99);
28
29 segment a(point(20, 10), point(10, 20));
30
31 segment b1(point(11, 16), point(20, 14)); // IP with a: (14.857, 15.143)
32 segment b2(point(10, 16), point(20, 14)); // IP with a: (15, 15)
33
34 segment c1(point(15, 16), point(13, 8));
35 segment c2(point(15, 16), point(14, 8));
36 segment c3(point(15, 16), point(15, 8));
37
38
39 BOOST_CHECK_EQUAL( 1, side::apply(a, b1, c1, no_fb));
40 BOOST_CHECK_EQUAL(-1, side::apply(a, b1, c2, no_fb));
41 BOOST_CHECK_EQUAL(-1, side::apply(a, b1, c3, no_fb));
42
43 BOOST_CHECK_EQUAL( 1, side::apply(a, b2, c1, no_fb));
44 BOOST_CHECK_EQUAL( 1, side::apply(a, b2, c2, no_fb));
45 BOOST_CHECK_EQUAL( 0, side::apply(a, b2, c3, no_fb));
46
47 // Collinear cases
48 // 1: segments intersecting are collinear (with a fallback point):
49 {
50 point fb(5, 5);
51 segment col1(point(0, 5), point(5, 5));
52 segment col2(point(5, 5), point(10, 5)); // One IP with col1 at (5,5)
53 segment col3(point(5, 0), point(5, 5));
54 BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
55 }
56 // 2: segment of side calculation collinear with one of the segments
57 {
58 point fb(5, 5);
59 segment col1(point(0, 5), point(10, 5));
60 segment col2(point(5, 5), point(5, 12)); // IP with col1 at (5,5)
61 segment col3(point(5, 1), point(5, 5)); // collinear with col2
62 BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
63 }
64 {
65 point fb(5, 5);
66 segment col1(point(10, 5), point(0, 5));
67 segment col2(point(5, 5), point(5, 12)); // IP with col1 at (5,5)
68 segment col3(point(5, 1), point(5, 5)); // collinear with col2
69 BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
70 }
71 {
72 point fb(5, 5);
73 segment col1(point(0, 5), point(10, 5));
74 segment col2(point(5, 12), point(5, 5)); // IP with col1 at (5,5)
75 segment col3(point(5, 1), point(5, 5)); // collinear with col2
76 BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
77 }
78
79 {
80 point fb(517248, -517236);
81 segment col1(point(-172408, -517236), point(862076, -517236));
82 segment col2(point(517248, -862064), point(517248, -172408));
83 segment col3(point(517248, -172408), point(517248, -517236));
84 BOOST_CHECK_EQUAL( 0, side::apply(col1, col2, col3, fb));
85 }
86 {
87 point fb(-221647, -830336);
88 segment col1(point(-153817, -837972), point(-222457, -830244));
89 segment col2(point(-221139, -833615), point(-290654, -384388));
90 segment col3(point(-255266, -814663), point(-264389, -811197));
91 BOOST_CHECK_EQUAL(1, side::apply(col1, col2, col3, fb)); // Left of segment...
92 }
93
94
95 {
96 point fb(27671131, 30809240);
97 segment col1(point(27671116, 30809247), point(27675474, 30807351));
98 segment col2(point(27666779, 30811130), point(27671139, 30809237));
99 segment col3(point(27671122, 30809244), point(27675480, 30807348));
100 BOOST_CHECK_EQUAL(1, side::apply(col1, col2, col3, fb)); // Left of segment...
101 }
102
103 // TODO: we might add a check calculating the IP, determining the side
104 // with the normal side strategy, and verify the results are equal
105
106 return 0;
107 }
108
109