1 // Boost.Geometry (aka GGL, Generic Geometry Library)
2 // Unit Test
3
4 // Copyright (c) 2014-2018, Oracle and/or its affiliates.
5
6 // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
7 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
8
9 // Licensed under the Boost Software License version 1.0.
10 // http://www.boost.org/users/license.html
11
12 #include <iostream>
13
14 #ifndef BOOST_TEST_MODULE
15 #define BOOST_TEST_MODULE test_distance_cartesian_pointlike_pointlike
16 #endif
17
18 #include <boost/test/included/unit_test.hpp>
19
20 #include "test_distance_common.hpp"
21 #include "test_empty_geometry.hpp"
22
23
24 typedef bg::model::point<double,2,bg::cs::cartesian> point_type;
25 typedef bg::model::multi_point<point_type> multi_point_type;
26
27 namespace services = bg::strategy::distance::services;
28 typedef bg::default_distance_result<point_type>::type return_type;
29
30 typedef bg::strategy::distance::pythagoras<> point_point_strategy;
31
32 //===========================================================================
33
34 template <typename Strategy>
test_distance_point_point(Strategy const & strategy)35 void test_distance_point_point(Strategy const& strategy)
36 {
37 #ifdef BOOST_GEOMETRY_TEST_DEBUG
38 std::cout << std::endl;
39 std::cout << "point/point distance tests" << std::endl;
40 #endif
41 typedef test_distance_of_geometries<point_type, point_type> tester;
42
43 tester::apply("point(1 1)",
44 "point(0 0)",
45 sqrt(2.0), 2, strategy);
46 tester::apply("point(1 1)",
47 "point(1 1)",
48 0, 0, strategy);
49
50 // distance overflows
51 tester::apply("point(0 0)",
52 "point(4.297374e+307 8.433875e+307)",
53 0, 0, strategy, false);
54 }
55
56 //===========================================================================
57
58 template <typename Strategy>
test_distance_point_multipoint(Strategy const & strategy)59 void test_distance_point_multipoint(Strategy const& strategy)
60 {
61 #ifdef BOOST_GEOMETRY_TEST_DEBUG
62 std::cout << std::endl;
63 std::cout << "point/multipoint distance tests" << std::endl;
64 #endif
65 typedef test_distance_of_geometries<point_type, multi_point_type> tester;
66
67 tester::apply("point(1 1)",
68 "multipoint(1 1,2 1,2 2,1 2)",
69 0, 0, strategy);
70 tester::apply("point(1 1)",
71 "multipoint(2 2,2 3,3 2,3 3)",
72 sqrt(2.0), 2, strategy);
73 tester::apply("point(3 0)",
74 "multipoint(2 2,2 4,4 2,4 4)",
75 sqrt(5.0), 5, strategy);
76 }
77
78 //===========================================================================
79
80 template <typename Strategy>
test_distance_multipoint_multipoint(Strategy const & strategy)81 void test_distance_multipoint_multipoint(Strategy const& strategy)
82 {
83 #ifdef BOOST_GEOMETRY_TEST_DEBUG
84 std::cout << std::endl;
85 std::cout << "multipoint/multipoint distance tests" << std::endl;
86 #endif
87 typedef test_distance_of_geometries
88 <
89 multi_point_type, multi_point_type
90 > tester;
91
92 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
93 "multipoint(1 1,2 1,2 2,1 2)",
94 0, 0, strategy);
95 tester::apply("multipoint(0 0,1 0,0 1,1 1)",
96 "multipoint(2 2,2 3,3 2,3 3)",
97 sqrt(2.0), 2, strategy);
98 }
99
100 //===========================================================================
101
BOOST_AUTO_TEST_CASE(test_all_point_point)102 BOOST_AUTO_TEST_CASE( test_all_point_point )
103 {
104 test_distance_point_point(point_point_strategy());
105 }
106
BOOST_AUTO_TEST_CASE(test_all_point_multipoint)107 BOOST_AUTO_TEST_CASE( test_all_point_multipoint )
108 {
109 test_distance_point_multipoint(point_point_strategy());
110 }
111
BOOST_AUTO_TEST_CASE(test_all_multipoint_multipoint)112 BOOST_AUTO_TEST_CASE( test_all_multipoint_multipoint )
113 {
114 test_distance_multipoint_multipoint(point_point_strategy());
115 }
116
BOOST_AUTO_TEST_CASE(test_all_empty_input_pointlike_pointlike)117 BOOST_AUTO_TEST_CASE( test_all_empty_input_pointlike_pointlike )
118 {
119 test_more_empty_input_pointlike_pointlike
120 <
121 point_type
122 >(point_point_strategy());
123 }
124