1 // Boost.Geometry (aka GGL, Generic Geometry Library)
4 // Copyright (c) 2014-2015, Oracle and/or its affiliates.
6 // Contributed and/or modified by Menelaos Karavelas, 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_pointlike_linear
17 #include <boost/test/included/unit_test.hpp>
19 #include "test_distance_common.hpp"
22 typedef bg::model::point
<double,2,bg::cs::cartesian
> point_type
;
23 typedef bg::model::multi_point
<point_type
> multi_point_type
;
24 typedef bg::model::segment
<point_type
> segment_type
;
25 typedef bg::model::linestring
<point_type
> linestring_type
;
26 typedef bg::model::multi_linestring
<linestring_type
> multi_linestring_type
;
28 namespace services
= bg::strategy::distance::services
;
29 typedef bg::default_distance_result
<point_type
>::type return_type
;
31 typedef bg::strategy::distance::pythagoras
<> point_point_strategy
;
32 typedef bg::strategy::distance::projected_point
<> point_segment_strategy
;
35 //===========================================================================
38 template <typename Strategy
>
39 void test_distance_point_segment(Strategy
const& strategy
)
41 #ifdef BOOST_GEOMETRY_TEST_DEBUG
42 std::cout
<< std::endl
;
43 std::cout
<< "point/segment distance tests" << std::endl
;
45 typedef test_distance_of_geometries
<point_type
, segment_type
> tester
;
47 tester::apply("point(0 0)", "segment(2 0,3 0)", 2, 4, strategy
);
48 tester::apply("point(2.5 3)", "segment(2 0,3 0)", 3, 9, strategy
);
49 tester::apply("point(2 0)", "segment(2 0,3 0)", 0, 0, strategy
);
50 tester::apply("point(3 0)", "segment(2 0,3 0)", 0, 0, strategy
);
51 tester::apply("point(2.5 0)", "segment(2 0,3 0)", 0, 0, strategy
);
54 tester::apply("POINT(4.297374e+307 8.433875e+307)",
55 "SEGMENT(26 87,13 95)",
56 0, 0, strategy
, false);
59 //===========================================================================
61 template <typename Strategy
>
62 void test_distance_point_linestring(Strategy
const& strategy
)
64 #ifdef BOOST_GEOMETRY_TEST_DEBUG
65 std::cout
<< std::endl
;
66 std::cout
<< "point/linestring distance tests" << std::endl
;
68 typedef test_distance_of_geometries
<point_type
, linestring_type
> tester
;
70 tester::apply("point(0 0)", "linestring(2 0,3 0)", 2, 4, strategy
);
71 tester::apply("point(2.5 3)", "linestring(2 0,3 0)", 3, 9, strategy
);
72 tester::apply("point(2 0)", "linestring(2 0,3 0)", 0, 0, strategy
);
73 tester::apply("point(3 0)", "linestring(2 0,3 0)", 0, 0, strategy
);
74 tester::apply("point(2.5 0)", "linestring(2 0,3 0)", 0, 0, strategy
);
76 // linestring with a single point
77 tester::apply("point(0 0)", "linestring(2 0)", 2, 4, strategy
);
80 tester::apply("POINT(4.297374e+307 8.433875e+307)",
81 "LINESTRING(26 87,13 95)",
82 0, 0, strategy
, false);
85 //===========================================================================
87 template <typename Strategy
>
88 void test_distance_point_multilinestring(Strategy
const& strategy
)
90 #ifdef BOOST_GEOMETRY_TEST_DEBUG
91 std::cout
<< std::endl
;
92 std::cout
<< "point/multilinestring distance tests" << std::endl
;
94 typedef test_distance_of_geometries
96 point_type
, multi_linestring_type
99 tester::apply("point(0 0)",
100 "multilinestring((-5 0,-3 0),(2 0,3 0))",
102 tester::apply("point(2.5 3)",
103 "multilinestring((-5 0,-3 0),(2 0,3 0))",
105 tester::apply("point(2 0)",
106 "multilinestring((-5 0,-3 0),(2 0,3 0))",
108 tester::apply("point(3 0)",
109 "multilinestring((-5 0,-3 0),(2 0,3 0))",
111 tester::apply("point(2.5 0)",
112 "multilinestring((-5 0,-3 0),(2 0,3 0))",
114 tester::apply("POINT(0 0)",
115 "MULTILINESTRING((10 10,10 0),(0.0 -0.0,0.0 -0.0))",
117 tester::apply("POINT(0 0)",
118 "MULTILINESTRING((10 10,10 0),(1 1,1 1))",
119 sqrt(2.0), 2, strategy
);
120 tester::apply("POINT(0 0)",
121 "MULTILINESTRING((10 10,10 0),(1 1,2 2))",
122 sqrt(2.0), 2, strategy
);
123 tester::apply("POINT(0 0)",
124 "MULTILINESTRING((10 10,10 0),(20 20,20 20))",
127 // multilinestrings containing an empty linestring
128 tester::apply("POINT(0 0)",
129 "MULTILINESTRING((),(10 0),(20 20,20 20))",
131 tester::apply("POINT(0 0)",
132 "MULTILINESTRING((),(10 0),(),(20 20,20 20))",
135 // multilinestrings containing a linestring with a single point
136 tester::apply("POINT(0 0)",
137 "MULTILINESTRING((10 0),(20 20,20 20))",
139 tester::apply("POINT(0 0)",
140 "MULTILINESTRING((20 20,20 20),(10 0))",
143 // multilinestring with a single-point linestring and empty linestrings
144 tester::apply("POINT(0 0)",
145 "MULTILINESTRING((),(20 20,20 20),(),(10 0))",
149 //===========================================================================
151 template <typename Strategy
>
152 void test_distance_linestring_multipoint(Strategy
const& strategy
)
154 #ifdef BOOST_GEOMETRY_TEST_DEBUG
155 std::cout
<< std::endl
;
156 std::cout
<< "linestring/multipoint distance tests" << std::endl
;
158 typedef test_distance_of_geometries
160 linestring_type
, multi_point_type
163 tester::apply("linestring(2 0,0 2,100 100)",
164 "multipoint(0 0,1 0,0 1,1 1)",
166 tester::apply("linestring(4 0,0 4,100 100)",
167 "multipoint(0 0,1 0,0 1,1 1)",
168 sqrt(2.0), 2, strategy
);
169 tester::apply("linestring(1 1,2 2,100 100)",
170 "multipoint(0 0,1 0,0 1,1 1)",
172 tester::apply("linestring(3 3,4 4,100 100)",
173 "multipoint(0 0,1 0,0 1,1 1)",
174 sqrt(8.0), 8, strategy
);
176 // linestring with a single point
177 tester::apply("linestring(1 8)",
178 "multipoint(0 0,3 0,4 -7,10 100)",
179 sqrt(65.0), 65, strategy
);
182 //===========================================================================
184 template <typename Strategy
>
185 void test_distance_multipoint_multilinestring(Strategy
const& strategy
)
187 #ifdef BOOST_GEOMETRY_TEST_DEBUG
188 std::cout
<< std::endl
;
189 std::cout
<< "multipoint/multilinestring distance tests" << std::endl
;
191 typedef test_distance_of_geometries
193 multi_point_type
, multi_linestring_type
196 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
197 "multilinestring((2 0,0 2),(2 2,3 3))",
199 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
200 "multilinestring((3 0,0 3),(4 4,5 5))",
201 0.5 * sqrt(2.0), 0.5, strategy
);
202 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
203 "multilinestring((4 4,5 5),(1 1,2 2))",
205 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
206 "multilinestring((3 3,4 4),(4 4,5 5))",
207 sqrt(8.0), 8, strategy
);
209 // multilinestring with empty linestring
210 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
211 "multilinestring((),(3 3,4 4),(4 4,5 5))",
212 sqrt(8.0), 8, strategy
);
213 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
214 "multilinestring((3 3,4 4),(),(4 4,5 5))",
215 sqrt(8.0), 8, strategy
);
217 // multilinestrings with a single-point linestrings
218 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
219 "multilinestring((3 3),(4 4,5 5))",
220 sqrt(8.0), 8, strategy
);
221 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
222 "multilinestring((4 4,5 5),(3 3))",
223 sqrt(8.0), 8, strategy
);
225 // multilinestring with a single-point linestring and empty linestring
226 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
227 "multilinestring((4 4,5 5),(),(3 3))",
228 sqrt(8.0), 8, strategy
);
230 // 21890717 - assertion failure in distance(Pt, Box)
232 multi_point_type mpt
;
233 bg::read_wkt("multipoint(1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1,1 1)", mpt
);
234 multi_linestring_type mls
;
236 point_type
pt(std::numeric_limits
<double>::quiet_NaN(), 1.0);
240 bg::distance(mpt
, mls
);
244 //===========================================================================
246 template <typename Strategy
>
247 void test_distance_multipoint_segment(Strategy
const& strategy
)
249 #ifdef BOOST_GEOMETRY_TEST_DEBUG
250 std::cout
<< std::endl
;
251 std::cout
<< "multipoint/segment distance tests" << std::endl
;
253 typedef test_distance_of_geometries
<multi_point_type
, segment_type
> tester
;
255 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
258 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
260 sqrt(2.0), 2, strategy
);
261 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
264 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
266 sqrt(8.0), 8, strategy
);
267 tester::apply("multipoint(4 4,5 5,2 2,3 3)",
269 sqrt(2.0), 2, strategy
);
272 //===========================================================================
274 template <typename Point
, typename Strategy
>
275 void test_more_empty_input_pointlike_linear(Strategy
const& strategy
)
277 #ifdef BOOST_GEOMETRY_TEST_DEBUG
278 std::cout
<< std::endl
;
279 std::cout
<< "testing on empty inputs... " << std::flush
;
281 bg::model::linestring
<Point
> line_empty
;
282 bg::model::multi_point
<Point
> multipoint_empty
;
283 bg::model::multi_linestring
<bg::model::linestring
<Point
> > multiline_empty
;
285 Point point
= from_wkt
<Point
>("point(0 0)");
286 bg::model::linestring
<Point
> line
=
287 from_wkt
<bg::model::linestring
<Point
> >("linestring(0 0,1 1)");
289 // 1st geometry is empty
290 test_empty_input(multipoint_empty
, line
, strategy
);
292 // 2nd geometry is empty
293 test_empty_input(point
, line_empty
, strategy
);
294 test_empty_input(point
, multiline_empty
, strategy
);
296 // both geometries are empty
297 test_empty_input(multipoint_empty
, line_empty
, strategy
);
298 test_empty_input(multipoint_empty
, multiline_empty
, strategy
);
300 #ifdef BOOST_GEOMETRY_TEST_DEBUG
301 std::cout
<< "done!" << std::endl
;
306 //===========================================================================
307 //===========================================================================
308 //===========================================================================
310 BOOST_AUTO_TEST_CASE( test_all_point_segment
)
312 test_distance_point_segment(point_point_strategy()); // back-compatibility
313 test_distance_point_segment(point_segment_strategy());
316 BOOST_AUTO_TEST_CASE( test_all_point_linestring
)
318 test_distance_point_linestring(point_point_strategy()); // back-compatibility
319 test_distance_point_linestring(point_segment_strategy());
322 BOOST_AUTO_TEST_CASE( test_all_point_multilinestring
)
324 test_distance_point_multilinestring(point_point_strategy()); // back-compatibility
325 test_distance_point_multilinestring(point_segment_strategy());
328 BOOST_AUTO_TEST_CASE( test_all_linestring_multipoint
)
330 test_distance_linestring_multipoint(point_point_strategy()); // back-compatibility
331 test_distance_linestring_multipoint(point_segment_strategy());
334 BOOST_AUTO_TEST_CASE( test_all_multipoint_multilinestring
)
336 test_distance_multipoint_multilinestring(point_point_strategy()); // back-compatibility
337 test_distance_multipoint_multilinestring(point_segment_strategy());
340 BOOST_AUTO_TEST_CASE( test_all_multipoint_segment
)
342 test_distance_multipoint_segment(point_segment_strategy());
345 BOOST_AUTO_TEST_CASE( test_all_empty_input_pointlike_linear
)
347 test_more_empty_input_pointlike_linear
350 >(point_segment_strategy());