1 // Boost.Geometry
2
3 // Copyright (c) 2018 Yaghyavardhan Singh Khangarot, Hyderabad, India.
4
5 // Contributed and/or modified by Yaghyavardhan Singh Khangarot, as part of Google Summer of Code 2018 program.
6
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10
11 #ifndef BOOST_GEOMETRY_TEST_FRECHET_DISTANCE_HPP
12 #define BOOST_GEOMETRY_TEST_FRECHET_DISTANCE_HPP
13
14 #include <geometry_test_common.hpp>
15 #include <boost/geometry/algorithms/discrete_frechet_distance.hpp>
16 #include <boost/geometry/io/wkt/wkt.hpp>
17 #include <boost/geometry/strategies/strategies.hpp>
18 #include <boost/variant/variant.hpp>
19
20 template <typename Geometry1,typename Geometry2>
test_frechet_distance(Geometry1 const & geometry1,Geometry2 const & geometry2,typename bg::distance_result<typename bg::point_type<Geometry1>::type,typename bg::point_type<Geometry2>::type>::type expected_frechet_distance)21 void test_frechet_distance(Geometry1 const& geometry1,Geometry2 const& geometry2,
22 typename bg::distance_result
23 <
24 typename bg::point_type<Geometry1>::type,
25 typename bg::point_type<Geometry2>::type
26 >::type expected_frechet_distance )
27 {
28 using namespace bg;
29 typedef typename distance_result
30 <
31 typename point_type<Geometry1>::type,
32 typename point_type<Geometry2>::type
33 >::type result_type;
34 result_type h_distance = bg::discrete_frechet_distance(geometry1,geometry2);
35
36 #ifdef BOOST_GEOMETRY_TEST_DEBUG
37 std::ostringstream out;
38 out << typeid(typename bg::coordinate_type<Geometry1>::type).name()
39 << std::endl
40 << typeid(typename bg::coordinate_type<Geometry2>::type).name()
41 << std::endl
42 << typeid(h_distance).name()
43 << std::endl
44 << "frechet_distance : " << bg::discrete_frechet_distance(geometry1,geometry2)
45 << std::endl;
46 std::cout << out.str();
47 #endif
48
49 BOOST_CHECK_CLOSE(h_distance, expected_frechet_distance, 0.001);
50 }
51
52
53
54 template <typename Geometry1,typename Geometry2>
test_geometry(std::string const & wkt1,std::string const & wkt2,typename bg::distance_result<typename bg::point_type<Geometry1>::type,typename bg::point_type<Geometry2>::type>::type expected_frechet_distance)55 void test_geometry(std::string const& wkt1,std::string const& wkt2,
56 typename bg::distance_result
57 <
58 typename bg::point_type<Geometry1>::type,
59 typename bg::point_type<Geometry2>::type
60 >::type expected_frechet_distance)
61 {
62 Geometry1 geometry1;
63 bg::read_wkt(wkt1, geometry1);
64 Geometry2 geometry2;
65 bg::read_wkt(wkt2, geometry2);
66 test_frechet_distance(geometry1,geometry2,expected_frechet_distance);
67 #if defined(BOOST_GEOMETRY_TEST_DEBUG)
68 test_frechet_distance(boost::variant<Geometry1>(geometry1),boost::variant<Geometry2>(geometry2), expected_frechet_distance);
69 #endif
70 }
71
72 template <typename Geometry1,typename Geometry2 ,typename Strategy>
test_frechet_distance(Geometry1 const & geometry1,Geometry2 const & geometry2,Strategy strategy,typename bg::distance_result<typename bg::point_type<Geometry1>::type,typename bg::point_type<Geometry2>::type,Strategy>::type expected_frechet_distance)73 void test_frechet_distance(Geometry1 const& geometry1,Geometry2 const& geometry2,Strategy strategy,
74 typename bg::distance_result
75 <
76 typename bg::point_type<Geometry1>::type,
77 typename bg::point_type<Geometry2>::type,
78 Strategy
79 >::type expected_frechet_distance )
80 {
81 using namespace bg;
82 typedef typename distance_result
83 <
84 typename point_type<Geometry1>::type,
85 typename point_type<Geometry2>::type,
86 Strategy
87 >::type result_type;
88 result_type h_distance = bg::discrete_frechet_distance(geometry1,geometry2,strategy);
89
90 #ifdef BOOST_GEOMETRY_TEST_DEBUG
91 std::ostringstream out;
92 out << typeid(typename bg::coordinate_type<Geometry1>::type).name()
93 << std::endl
94 << typeid(typename bg::coordinate_type<Geometry2>::type).name()
95 << std::endl
96 << typeid(h_distance).name()
97 << std::endl
98 << "frechet_distance : " << bg::discrete_frechet_distance(geometry1,geometry2,strategy)
99 << std::endl;
100 std::cout << out.str();
101 #endif
102
103 BOOST_CHECK_CLOSE(h_distance, expected_frechet_distance, 0.001);
104 }
105
106
107
108 template <typename Geometry1,typename Geometry2,typename Strategy>
test_geometry(std::string const & wkt1,std::string const & wkt2,Strategy strategy,typename bg::distance_result<typename bg::point_type<Geometry1>::type,typename bg::point_type<Geometry2>::type,Strategy>::type expected_frechet_distance)109 void test_geometry(std::string const& wkt1,std::string const& wkt2,Strategy strategy,
110 typename bg::distance_result
111 <
112 typename bg::point_type<Geometry1>::type,
113 typename bg::point_type<Geometry2>::type,
114 Strategy
115 >::type expected_frechet_distance)
116 {
117 Geometry1 geometry1;
118 bg::read_wkt(wkt1, geometry1);
119 Geometry2 geometry2;
120 bg::read_wkt(wkt2, geometry2);
121 test_frechet_distance(geometry1,geometry2,strategy,expected_frechet_distance);
122 #if defined(BOOST_GEOMETRY_TEST_DEBUG)
123 test_frechet_distance(boost::variant<Geometry1>(geometry1),boost::variant<Geometry2>(geometry2),strategy, expected_frechet_distance);
124 #endif
125 }
126
127
128 template <typename Geometry1,typename Geometry2>
test_empty_input(Geometry1 const & geometry1,Geometry2 const & geometry2)129 void test_empty_input(Geometry1 const& geometry1,Geometry2 const& geometry2)
130 {
131 try
132 {
133 bg::discrete_frechet_distance(geometry1,geometry2);
134 }
135 catch(bg::empty_input_exception const& )
136 {
137 return;
138 }
139 BOOST_CHECK_MESSAGE(false, "A empty_input_exception should have been thrown" );
140 }
141
142
143 #endif
144
145