1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2018 Oracle and/or its affiliates.
6 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
13 #ifndef BOOST_TEST_MODULE
14 #define BOOST_TEST_MODULE test_distance_geographic_linear_linear
17 #include <boost/range.hpp>
18 #include <boost/type_traits/is_same.hpp>
20 #include <boost/test/included/unit_test.hpp>
21 #include <boost/geometry/util/condition.hpp>
22 #include <boost/geometry/strategies/strategies.hpp>
24 #include "test_distance_geo_common.hpp"
25 #include "test_empty_geometry.hpp"
27 //===========================================================================
29 template <typename Point
, typename Strategy
>
30 void test_distance_segment_segment(Strategy
const& strategy_ps
)
33 #ifdef BOOST_GEOMETRY_TEST_DEBUG
34 std::cout
<< std::endl
;
35 std::cout
<< "segment/segment distance tests" << std::endl
;
38 typedef bg::model::segment
<Point
> segment_type
;
40 typedef test_distance_of_geometries
<segment_type
, segment_type
> tester
;
42 tester::apply("s-s-01",
45 ps_distance
<Point
>("POINT(2 0)",
46 "SEGMENT(0 0,1 1)", strategy_ps
),
47 strategy_ps
, true, true, false);
48 tester::apply("s-s-02",
51 ps_distance
<Point
>("POINT(2 0)",
52 "SEGMENT(2 1,3 1)", strategy_ps
),
53 strategy_ps
, true, true, false);
54 tester::apply("s-s-03",
55 "SEGMENT(2.5 1,3.5 1)",
57 ps_distance
<Point
>("POINT(2.5 0)",
58 "SEGMENT(2.5 1,3.5 1)", strategy_ps
),
59 strategy_ps
, true, true, false);
60 tester::apply("s-s-04",
61 "SEGMENT(2.5 1,3.5 1)",
63 ps_distance
<Point
>("POINT(3 2)",
64 "SEGMENT(2.5 1,3.5 1)", strategy_ps
),
65 strategy_ps
, true, true, false);
66 tester::apply("s-s-05",
67 "SEGMENT(2.5 2.1,3.5 1)",
69 0, strategy_ps
, true, true, false);
70 tester::apply("s-s-06",
71 "SEGMENT(2.5 2.1,3.5 1)",
73 0, strategy_ps
, true, true, false);
76 //===========================================================================
78 template <typename Point
, typename Strategy
>
79 void test_distance_segment_linestring(Strategy
const& strategy_ps
)
81 #ifdef BOOST_GEOMETRY_TEST_DEBUG
82 std::cout
<< std::endl
;
83 std::cout
<< "segment/linestring distance tests" << std::endl
;
86 typedef bg::model::segment
<Point
> segment_type
;
87 typedef bg::model::linestring
<Point
> linestring_type
;
89 typedef test_distance_of_geometries
<segment_type
, linestring_type
> tester
;
91 tester::apply("s-l-01",
93 "LINESTRING(2 0,3 0)",
94 ps_distance
<Point
>("POINT(2 0)",
95 "SEGMENT(0 0,1 1)", strategy_ps
),
96 strategy_ps
, true, true, false);
97 tester::apply("s-l-02",
99 "LINESTRING(2 0,3 0,2 2,0.5 0.7)",
100 ps_distance
<Point
>("POINT(1 1)",
101 "SEGMENT(0.5 0.7,2 2)", strategy_ps
),
102 strategy_ps
, true, true, false);
103 tester::apply("s-l-03",
105 "LINESTRING(2 0,3 0,2 2,0.5 0.7)",
106 0, strategy_ps
, true, true, false);
109 //===========================================================================
111 template <typename Point
, typename Strategy
>
112 void test_distance_linestring_linestring(Strategy
const& strategy_ps
)
114 #ifdef BOOST_GEOMETRY_TEST_DEBUG
115 std::cout
<< std::endl
;
116 std::cout
<< "linestring/linestring distance tests" << std::endl
;
119 typedef bg::model::linestring
<Point
> linestring_type
;
121 typedef test_distance_of_geometries
123 linestring_type
, linestring_type
126 tester::apply("l-l-01",
127 "LINESTRING(0 0,1 1)",
128 "LINESTRING(2 0,3 0)",
129 ps_distance
<Point
>("POINT(2 0)",
130 "SEGMENT(0 0,1 1)", strategy_ps
),
131 strategy_ps
, true, true, false);
132 tester::apply("l-l-02",
133 "LINESTRING(0 0,1 1,2 2)",
134 "LINESTRING(2 0,3 0,4 1)",
135 ps_distance
<Point
>("POINT(2 0)",
136 "SEGMENT(1 1,2 2)", strategy_ps
),
137 strategy_ps
, true, true, false);
138 tester::apply("l-l-03",
139 "LINESTRING(0 0,1 1,2 2)",
141 ps_distance
<Point
>("POINT(2 0)",
142 "SEGMENT(1 1,2 2)", strategy_ps
),
143 strategy_ps
, true, true, false);
144 tester::apply("l-l-04",
145 "LINESTRING(0 0,1 1,2 2)",
146 "LINESTRING(3 3,1 1)",
147 0, strategy_ps
, true, true, false);
150 //===========================================================================
152 template <typename Point
, typename Strategy
>
153 void test_distance_segment_multilinestring(Strategy
const& strategy_ps
)
155 #ifdef BOOST_GEOMETRY_TEST_DEBUG
156 std::cout
<< std::endl
;
157 std::cout
<< "segment/multilinestring distance tests" << std::endl
;
160 typedef bg::model::segment
<Point
> segment_type
;
161 typedef bg::model::linestring
<Point
> linestring_type
;
162 typedef bg::model::multi_linestring
<linestring_type
> multi_linestring_type
;
164 typedef test_distance_of_geometries
166 segment_type
, multi_linestring_type
169 tester::apply("s-ml-01",
171 "MULTILINESTRING((2 0,3 0)(2 5, 5 5, 2 -1))",
172 ps_distance
<Point
>("POINT(2 0)",
173 "SEGMENT(0 0,1 1)", strategy_ps
),
174 strategy_ps
, true, true, false);
175 tester::apply("s-ml-02",
177 "MULTILINESTRING((2 0,3 0))",
178 ps_distance
<Point
>("POINT(2 0)",
179 "SEGMENT(0 0,1 1)", strategy_ps
),
180 strategy_ps
, true, true, false);
181 tester::apply("s-ml-03",
183 "MULTILINESTRING((2 0,3 0)(2 5, 5 5, 2 -1))",
184 0, strategy_ps
, true, true, false);
187 //===========================================================================
189 template <typename Point
, typename Strategy
>
190 void test_distance_linestring_multilinestring(Strategy
const& strategy_ps
)
192 #ifdef BOOST_GEOMETRY_TEST_DEBUG
193 std::cout
<< std::endl
;
194 std::cout
<< "linestring/multilinestring distance tests" << std::endl
;
197 typedef bg::model::linestring
<Point
> linestring_type
;
198 typedef bg::model::multi_linestring
<linestring_type
> multi_linestring_type
;
200 typedef test_distance_of_geometries
202 linestring_type
, multi_linestring_type
205 tester::apply("l-ml-01",
206 "LINESTRING(0 0,1 1,2 2,3 3,4 4,6 6)",
207 "MULTILINESTRING((2 0,3 0)(2 1, 5 5))",
208 ps_distance
<Point
>("POINT(5 5)",
209 "SEGMENT(4 4,6 6)", strategy_ps
),
210 strategy_ps
, true, true, false);
211 tester::apply("l-ml-02",
212 "LINESTRING(0 0,1 1,2 2,3 3,4 4,6 6)",
213 "MULTILINESTRING((2 0,3 0)(2 5, 5 5))",
215 strategy_ps
, true, true, false);
219 //===========================================================================
221 template <typename Point
, typename Strategy
>
222 void test_distance_multilinestring_multilinestring(Strategy
const& strategy_ps
)
224 #ifdef BOOST_GEOMETRY_TEST_DEBUG
225 std::cout
<< std::endl
;
226 std::cout
<< "multilinestring/multilinestring distance tests" << std::endl
;
229 typedef bg::model::linestring
<Point
> linestring_type
;
230 typedef bg::model::multi_linestring
<linestring_type
> multi_linestring_type
;
232 typedef test_distance_of_geometries
234 multi_linestring_type
, multi_linestring_type
237 tester::apply("s-ml-01",
238 "MULTILINESTRING((0 0,1 1)(-1 0, -1 -1))",
239 "MULTILINESTRING((2 0,3 0)(2 5, 5 5))",
240 ps_distance
<Point
>("POINT(2 0)",
241 "SEGMENT(0 0,1 1)", strategy_ps
),
242 strategy_ps
, true, true, false);
243 tester::apply("s-ml-02",
244 "MULTILINESTRING((0 0,1 1)(-1 0, -1 -1)(5 0, 5 6))",
245 "MULTILINESTRING((2 0,3 0)(2 5, 5 5))",
247 strategy_ps
, true, true, false);
250 //===========================================================================
251 //===========================================================================
252 //===========================================================================
254 template <typename Point
, typename Strategy
>
255 void test_all_l_l(Strategy ps_strategy
)
257 test_distance_segment_segment
<Point
>(ps_strategy
);
258 test_distance_segment_linestring
<Point
>(ps_strategy
);
259 test_distance_linestring_linestring
<Point
>(ps_strategy
);
260 test_distance_segment_multilinestring
<Point
>(ps_strategy
);
261 test_distance_linestring_multilinestring
<Point
>(ps_strategy
);
262 test_distance_multilinestring_multilinestring
<Point
>(ps_strategy
);
264 test_more_empty_input_linear_linear
<Point
>(ps_strategy
);
267 BOOST_AUTO_TEST_CASE( test_all_linear_linear
)
269 typedef bg::model::point
272 bg::cs::spherical_equatorial
<bg::degree
>
275 test_all_l_l
<sph_point
>(spherical_ps());
277 typedef bg::model::point
280 bg::cs::geographic
<bg::degree
>
283 test_all_l_l
<geo_point
>(vincenty_ps());
284 test_all_l_l
<geo_point
>(thomas_ps());
285 test_all_l_l
<geo_point
>(andoyer_ps());