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