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_pointlike
15 #endif
16 
17 #include <boost/test/included/unit_test.hpp>
18 
19 #include "test_distance_common.hpp"
20 
21 
22 typedef bg::model::point<double,2,bg::cs::cartesian>  point_type;
23 typedef bg::model::multi_point<point_type>            multi_point_type;
24 
25 namespace services = bg::strategy::distance::services;
26 typedef bg::default_distance_result<point_type>::type return_type;
27 
28 typedef bg::strategy::distance::pythagoras<> point_point_strategy;
29 
30 //===========================================================================
31 
32 template <typename Strategy>
test_distance_point_point(Strategy const & strategy)33 void test_distance_point_point(Strategy const& strategy)
34 {
35 #ifdef BOOST_GEOMETRY_TEST_DEBUG
36     std::cout << std::endl;
37     std::cout << "point/point distance tests" << std::endl;
38 #endif
39     typedef test_distance_of_geometries<point_type, point_type> tester;
40 
41     tester::apply("point(1 1)",
42                   "point(0 0)",
43                   sqrt(2.0), 2, strategy);
44     tester::apply("point(1 1)",
45                   "point(1 1)",
46                   0, 0, strategy);
47 
48     // distance overflows
49     tester::apply("point(0 0)",
50                   "point(4.297374e+307 8.433875e+307)",
51                   0, 0, strategy, false);
52 }
53 
54 //===========================================================================
55 
56 template <typename Strategy>
test_distance_point_multipoint(Strategy const & strategy)57 void test_distance_point_multipoint(Strategy const& strategy)
58 {
59 #ifdef BOOST_GEOMETRY_TEST_DEBUG
60     std::cout << std::endl;
61     std::cout << "point/multipoint distance tests" << std::endl;
62 #endif
63     typedef test_distance_of_geometries<point_type, multi_point_type> tester;
64 
65     tester::apply("point(1 1)",
66                   "multipoint(1 1,2 1,2 2,1 2)",
67                   0, 0, strategy);
68     tester::apply("point(1 1)",
69                   "multipoint(2 2,2 3,3 2,3 3)",
70                   sqrt(2.0), 2, strategy);
71     tester::apply("point(3 0)",
72                   "multipoint(2 2,2 4,4 2,4 4)",
73                   sqrt(5.0), 5, strategy);
74 }
75 
76 //===========================================================================
77 
78 template <typename Strategy>
test_distance_multipoint_multipoint(Strategy const & strategy)79 void test_distance_multipoint_multipoint(Strategy const& strategy)
80 {
81 #ifdef BOOST_GEOMETRY_TEST_DEBUG
82     std::cout << std::endl;
83     std::cout << "multipoint/multipoint distance tests" << std::endl;
84 #endif
85     typedef test_distance_of_geometries
86         <
87             multi_point_type, multi_point_type
88         > tester;
89 
90     tester::apply("multipoint(0 0,1 0,0 1,1 1)",
91                   "multipoint(1 1,2 1,2 2,1 2)",
92                   0, 0, strategy);
93     tester::apply("multipoint(0 0,1 0,0 1,1 1)",
94                   "multipoint(2 2,2 3,3 2,3 3)",
95                   sqrt(2.0), 2, strategy);
96 }
97 
98 //===========================================================================
99 
100 template <typename Point, typename Strategy>
test_more_empty_input_pointlike_pointlike(Strategy const & strategy)101 void test_more_empty_input_pointlike_pointlike(Strategy const& strategy)
102 {
103 #ifdef BOOST_GEOMETRY_TEST_DEBUG
104     std::cout << std::endl;
105     std::cout << "testing on empty inputs... " << std::flush;
106 #endif
107     bg::model::multi_point<Point> multipoint_empty;
108 
109     Point point = from_wkt<Point>("point(0 0)");
110 
111     // 1st geometry is empty
112     test_empty_input(multipoint_empty, point, strategy);
113 
114     // 2nd geometry is empty
115     test_empty_input(point, multipoint_empty, strategy);
116 
117     // both geometries are empty
118     test_empty_input(multipoint_empty, multipoint_empty, strategy);
119 
120 #ifdef BOOST_GEOMETRY_TEST_DEBUG
121     std::cout << "done!" << std::endl;
122 #endif
123 }
124 
125 //===========================================================================
126 
BOOST_AUTO_TEST_CASE(test_all_point_point)127 BOOST_AUTO_TEST_CASE( test_all_point_point )
128 {
129     test_distance_point_point(point_point_strategy());
130 }
131 
BOOST_AUTO_TEST_CASE(test_all_point_multipoint)132 BOOST_AUTO_TEST_CASE( test_all_point_multipoint )
133 {
134     test_distance_point_multipoint(point_point_strategy());
135 }
136 
BOOST_AUTO_TEST_CASE(test_all_multipoint_multipoint)137 BOOST_AUTO_TEST_CASE( test_all_multipoint_multipoint )
138 {
139     test_distance_multipoint_multipoint(point_point_strategy());
140 }
141 
BOOST_AUTO_TEST_CASE(test_all_empty_input_pointlike_pointlike)142 BOOST_AUTO_TEST_CASE( test_all_empty_input_pointlike_pointlike )
143 {
144     test_more_empty_input_pointlike_pointlike
145         <
146             point_type
147         >(point_point_strategy());
148 }
149