]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/libs/geometry/test/algorithms/distance/distance_pointlike_linear.cpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / libs / geometry / test / algorithms / distance / distance_pointlike_linear.cpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2// Unit Test
3
4// Copyright (c) 2014-2015, Oracle and/or its affiliates.
5
6// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7
8// Licensed under the Boost Software License version 1.0.
9// http://www.boost.org/users/license.html
10
11#include <iostream>
12
13#ifndef BOOST_TEST_MODULE
14#define BOOST_TEST_MODULE test_distance_pointlike_linear
15#endif
16
17#include <boost/test/included/unit_test.hpp>
18
19#include "test_distance_common.hpp"
20
21
22typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
23typedef bg::model::multi_point<point_type> multi_point_type;
24typedef bg::model::segment<point_type> segment_type;
25typedef bg::model::linestring<point_type> linestring_type;
26typedef bg::model::multi_linestring<linestring_type> multi_linestring_type;
27
28namespace services = bg::strategy::distance::services;
29typedef bg::default_distance_result<point_type>::type return_type;
30
31typedef bg::strategy::distance::pythagoras<> point_point_strategy;
32typedef bg::strategy::distance::projected_point<> point_segment_strategy;
33
34
35//===========================================================================
36
37
38template <typename Strategy>
39void test_distance_point_segment(Strategy const& strategy)
40{
41#ifdef BOOST_GEOMETRY_TEST_DEBUG
42 std::cout << std::endl;
43 std::cout << "point/segment distance tests" << std::endl;
44#endif
45 typedef test_distance_of_geometries<point_type, segment_type> tester;
46
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);
52
53 // distance is a NaN
54 tester::apply("POINT(4.297374e+307 8.433875e+307)",
55 "SEGMENT(26 87,13 95)",
56 0, 0, strategy, false);
57}
58
59//===========================================================================
60
61template <typename Strategy>
62void test_distance_point_linestring(Strategy const& strategy)
63{
64#ifdef BOOST_GEOMETRY_TEST_DEBUG
65 std::cout << std::endl;
66 std::cout << "point/linestring distance tests" << std::endl;
67#endif
68 typedef test_distance_of_geometries<point_type, linestring_type> tester;
69
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);
75
76 // linestring with a single point
77 tester::apply("point(0 0)", "linestring(2 0)", 2, 4, strategy);
78
79 // distance is a NaN
80 tester::apply("POINT(4.297374e+307 8.433875e+307)",
81 "LINESTRING(26 87,13 95)",
82 0, 0, strategy, false);
83}
84
85//===========================================================================
86
87template <typename Strategy>
88void test_distance_point_multilinestring(Strategy const& strategy)
89{
90#ifdef BOOST_GEOMETRY_TEST_DEBUG
91 std::cout << std::endl;
92 std::cout << "point/multilinestring distance tests" << std::endl;
93#endif
94 typedef test_distance_of_geometries
95 <
96 point_type, multi_linestring_type
97 > tester;
98
99 tester::apply("point(0 0)",
100 "multilinestring((-5 0,-3 0),(2 0,3 0))",
101 2, 4, strategy);
102 tester::apply("point(2.5 3)",
103 "multilinestring((-5 0,-3 0),(2 0,3 0))",
104 3, 9, strategy);
105 tester::apply("point(2 0)",
106 "multilinestring((-5 0,-3 0),(2 0,3 0))",
107 0, 0, strategy);
108 tester::apply("point(3 0)",
109 "multilinestring((-5 0,-3 0),(2 0,3 0))",
110 0, 0, strategy);
111 tester::apply("point(2.5 0)",
112 "multilinestring((-5 0,-3 0),(2 0,3 0))",
113 0, 0, strategy);
114 tester::apply("POINT(0 0)",
115 "MULTILINESTRING((10 10,10 0),(0.0 -0.0,0.0 -0.0))",
116 0, 0, strategy);
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))",
125 10, 100, strategy);
126
127 // multilinestrings containing an empty linestring
128 tester::apply("POINT(0 0)",
129 "MULTILINESTRING((),(10 0),(20 20,20 20))",
130 10, 100, strategy);
131 tester::apply("POINT(0 0)",
132 "MULTILINESTRING((),(10 0),(),(20 20,20 20))",
133 10, 100, strategy);
134
135 // multilinestrings containing a linestring with a single point
136 tester::apply("POINT(0 0)",
137 "MULTILINESTRING((10 0),(20 20,20 20))",
138 10, 100, strategy);
139 tester::apply("POINT(0 0)",
140 "MULTILINESTRING((20 20,20 20),(10 0))",
141 10, 100, strategy);
142
143 // multilinestring with a single-point linestring and empty linestrings
144 tester::apply("POINT(0 0)",
145 "MULTILINESTRING((),(20 20,20 20),(),(10 0))",
146 10, 100, strategy);
147}
148
149//===========================================================================
150
151template <typename Strategy>
152void test_distance_linestring_multipoint(Strategy const& strategy)
153{
154#ifdef BOOST_GEOMETRY_TEST_DEBUG
155 std::cout << std::endl;
156 std::cout << "linestring/multipoint distance tests" << std::endl;
157#endif
158 typedef test_distance_of_geometries
159 <
160 linestring_type, multi_point_type
161 > tester;
162
163 tester::apply("linestring(2 0,0 2,100 100)",
164 "multipoint(0 0,1 0,0 1,1 1)",
165 0, 0, strategy);
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)",
171 0, 0, strategy);
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);
175
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);
180}
181
182//===========================================================================
183
184template <typename Strategy>
185void test_distance_multipoint_multilinestring(Strategy const& strategy)
186{
187#ifdef BOOST_GEOMETRY_TEST_DEBUG
188 std::cout << std::endl;
189 std::cout << "multipoint/multilinestring distance tests" << std::endl;
190#endif
191 typedef test_distance_of_geometries
192 <
193 multi_point_type, multi_linestring_type
194 > tester;
195
196 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
197 "multilinestring((2 0,0 2),(2 2,3 3))",
198 0, 0, strategy);
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))",
204 0, 0, strategy);
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);
208
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);
216
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);
224
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);
229
b32b8144
FG
230 // 21890717 - assertion failure in distance(Pt, Box)
231 {
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;
235 linestring_type ls;
236 point_type pt(std::numeric_limits<double>::quiet_NaN(), 1.0);
237 ls.push_back(pt);
238 ls.push_back(pt);
239 mls.push_back(ls);
240 bg::distance(mpt, mls);
241 }
7c673cae
FG
242}
243
244//===========================================================================
245
246template <typename Strategy>
247void test_distance_multipoint_segment(Strategy const& strategy)
248{
249#ifdef BOOST_GEOMETRY_TEST_DEBUG
250 std::cout << std::endl;
251 std::cout << "multipoint/segment distance tests" << std::endl;
252#endif
253 typedef test_distance_of_geometries<multi_point_type, segment_type> tester;
254
255 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
256 "segment(2 0,0 2)",
257 0, 0, strategy);
258 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
259 "segment(4 0,0 4)",
260 sqrt(2.0), 2, strategy);
261 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
262 "segment(1 1,2 2)",
263 0, 0, strategy);
264 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
265 "segment(3 3,4 4)",
266 sqrt(8.0), 8, strategy);
267 tester::apply("multipoint(4 4,5 5,2 2,3 3)",
268 "segment(0 0,1 1)",
269 sqrt(2.0), 2, strategy);
270}
271
272//===========================================================================
273
274template <typename Point, typename Strategy>
275void test_more_empty_input_pointlike_linear(Strategy const& strategy)
276{
277#ifdef BOOST_GEOMETRY_TEST_DEBUG
278 std::cout << std::endl;
279 std::cout << "testing on empty inputs... " << std::flush;
280#endif
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;
284
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)");
288
289 // 1st geometry is empty
290 test_empty_input(multipoint_empty, line, strategy);
291
292 // 2nd geometry is empty
293 test_empty_input(point, line_empty, strategy);
294 test_empty_input(point, multiline_empty, strategy);
295
296 // both geometries are empty
297 test_empty_input(multipoint_empty, line_empty, strategy);
298 test_empty_input(multipoint_empty, multiline_empty, strategy);
299
300#ifdef BOOST_GEOMETRY_TEST_DEBUG
301 std::cout << "done!" << std::endl;
302#endif
303}
304
305
306//===========================================================================
307//===========================================================================
308//===========================================================================
309
310BOOST_AUTO_TEST_CASE( test_all_point_segment )
311{
312 test_distance_point_segment(point_point_strategy()); // back-compatibility
313 test_distance_point_segment(point_segment_strategy());
314}
315
316BOOST_AUTO_TEST_CASE( test_all_point_linestring )
317{
318 test_distance_point_linestring(point_point_strategy()); // back-compatibility
319 test_distance_point_linestring(point_segment_strategy());
320}
321
322BOOST_AUTO_TEST_CASE( test_all_point_multilinestring )
323{
324 test_distance_point_multilinestring(point_point_strategy()); // back-compatibility
325 test_distance_point_multilinestring(point_segment_strategy());
326}
327
328BOOST_AUTO_TEST_CASE( test_all_linestring_multipoint )
329{
330 test_distance_linestring_multipoint(point_point_strategy()); // back-compatibility
331 test_distance_linestring_multipoint(point_segment_strategy());
332}
333
334BOOST_AUTO_TEST_CASE( test_all_multipoint_multilinestring )
335{
336 test_distance_multipoint_multilinestring(point_point_strategy()); // back-compatibility
337 test_distance_multipoint_multilinestring(point_segment_strategy());
338}
339
340BOOST_AUTO_TEST_CASE( test_all_multipoint_segment )
341{
342 test_distance_multipoint_segment(point_segment_strategy());
343}
344
345BOOST_AUTO_TEST_CASE( test_all_empty_input_pointlike_linear )
346{
347 test_more_empty_input_pointlike_linear
348 <
349 point_type
350 >(point_segment_strategy());
351}