1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
7 // This file was modified by Oracle on 2014.
8 // Modifications copyright (c) 2014, Oracle and/or its affiliates.
10 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_COMPARABLE_DISTANCE_INTERFACE_HPP
20 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_COMPARABLE_DISTANCE_INTERFACE_HPP
22 #include <boost/geometry/geometries/concepts/check.hpp>
24 #include <boost/geometry/strategies/comparable_distance_result.hpp>
25 #include <boost/geometry/strategies/default_comparable_distance_result.hpp>
26 #include <boost/geometry/strategies/distance.hpp>
28 #include <boost/geometry/algorithms/detail/distance/interface.hpp>
31 namespace boost { namespace geometry
35 namespace resolve_strategy
38 struct comparable_distance
40 template <typename Geometry1, typename Geometry2, typename Strategy>
42 typename comparable_distance_result<Geometry1, Geometry2, Strategy>::type
43 apply(Geometry1 const& geometry1,
44 Geometry2 const& geometry2,
45 Strategy const& strategy)
47 typedef typename strategy::distance::services::comparable_type
50 >::type comparable_strategy_type;
52 return dispatch::distance
54 Geometry1, Geometry2, comparable_strategy_type
57 strategy::distance::services::get_comparable
63 template <typename Geometry1, typename Geometry2>
64 static inline typename comparable_distance_result
66 Geometry1, Geometry2, default_strategy
68 apply(Geometry1 const& geometry1,
69 Geometry2 const& geometry2,
72 typedef typename strategy::distance::services::comparable_type
74 typename detail::distance::default_strategy
78 >::type comparable_strategy_type;
80 return dispatch::distance
82 Geometry1, Geometry2, comparable_strategy_type
83 >::apply(geometry1, geometry2, comparable_strategy_type());
87 } // namespace resolve_strategy
90 namespace resolve_variant
94 template <typename Geometry1, typename Geometry2>
95 struct comparable_distance
97 template <typename Strategy>
99 typename comparable_distance_result<Geometry1, Geometry2, Strategy>::type
100 apply(Geometry1 const& geometry1,
101 Geometry2 const& geometry2,
102 Strategy const& strategy)
104 return resolve_strategy::comparable_distance::apply(geometry1,
111 template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
112 struct comparable_distance
114 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
118 template <typename Strategy>
119 struct visitor: static_visitor
121 typename comparable_distance_result
123 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
129 Geometry2 const& m_geometry2;
130 Strategy const& m_strategy;
132 visitor(Geometry2 const& geometry2,
133 Strategy const& strategy)
134 : m_geometry2(geometry2),
138 template <typename Geometry1>
139 typename comparable_distance_result
141 Geometry1, Geometry2, Strategy
143 operator()(Geometry1 const& geometry1) const
145 return comparable_distance
152 >(geometry1, m_geometry2, m_strategy);
156 template <typename Strategy>
157 static inline typename comparable_distance_result
159 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
163 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
164 Geometry2 const& geometry2,
165 Strategy const& strategy)
167 return boost::apply_visitor(visitor<Strategy>(geometry2, strategy), geometry1);
172 template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
173 struct comparable_distance
176 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>
179 template <typename Strategy>
180 struct visitor: static_visitor
182 typename comparable_distance_result
185 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
190 Geometry1 const& m_geometry1;
191 Strategy const& m_strategy;
193 visitor(Geometry1 const& geometry1,
194 Strategy const& strategy)
195 : m_geometry1(geometry1),
199 template <typename Geometry2>
200 typename comparable_distance_result
202 Geometry1, Geometry2, Strategy
204 operator()(Geometry2 const& geometry2) const
206 return comparable_distance
213 >(m_geometry1, geometry2, m_strategy);
217 template <typename Strategy>
218 static inline typename comparable_distance_result
221 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>,
224 apply(Geometry1 const& geometry1,
225 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
226 Strategy const& strategy)
228 return boost::apply_visitor(visitor<Strategy>(geometry1, strategy), geometry2);
235 BOOST_VARIANT_ENUM_PARAMS(typename T1),
236 BOOST_VARIANT_ENUM_PARAMS(typename T2)
238 struct comparable_distance
240 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
241 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>
244 template <typename Strategy>
245 struct visitor: static_visitor
247 typename comparable_distance_result
249 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
250 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>,
255 Strategy const& m_strategy;
257 visitor(Strategy const& strategy)
258 : m_strategy(strategy)
261 template <typename Geometry1, typename Geometry2>
262 typename comparable_distance_result
264 Geometry1, Geometry2, Strategy
266 operator()(Geometry1 const& geometry1, Geometry2 const& geometry2) const
268 return comparable_distance
275 >(geometry1, geometry2, m_strategy);
279 template <typename Strategy>
280 static inline typename comparable_distance_result
282 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
283 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>,
286 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
287 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
288 Strategy const& strategy)
290 return boost::apply_visitor(visitor<Strategy>(strategy), geometry1, geometry2);
294 } // namespace resolve_variant
299 \brief \brief_calc2{comparable distance measurement} \brief_strategy
301 \details The free function comparable_distance does not necessarily calculate the distance,
302 but it calculates a distance measure such that two distances are comparable to each other.
303 For example: for the Cartesian coordinate system, Pythagoras is used but the square root
304 is not taken, which makes it faster and the results of two point pairs can still be
305 compared to each other.
306 \tparam Geometry1 first geometry type
307 \tparam Geometry2 second geometry type
308 \tparam Strategy \tparam_strategy{Distance}
309 \param geometry1 \param_geometry
310 \param geometry2 \param_geometry
311 \param strategy \param_strategy{distance}
312 \return \return_calc{comparable distance}
314 \qbk{distinguish,with strategy}
316 template <typename Geometry1, typename Geometry2, typename Strategy>
317 inline typename comparable_distance_result<Geometry1, Geometry2, Strategy>::type
318 comparable_distance(Geometry1 const& geometry1, Geometry2 const& geometry2,
319 Strategy const& strategy)
321 concepts::check<Geometry1 const>();
322 concepts::check<Geometry2 const>();
324 return resolve_variant::comparable_distance
328 >::apply(geometry1, geometry2, strategy);
334 \brief \brief_calc2{comparable distance measurement}
336 \details The free function comparable_distance does not necessarily calculate the distance,
337 but it calculates a distance measure such that two distances are comparable to each other.
338 For example: for the Cartesian coordinate system, Pythagoras is used but the square root
339 is not taken, which makes it faster and the results of two point pairs can still be
340 compared to each other.
341 \tparam Geometry1 first geometry type
342 \tparam Geometry2 second geometry type
343 \param geometry1 \param_geometry
344 \param geometry2 \param_geometry
345 \return \return_calc{comparable distance}
347 \qbk{[include reference/algorithms/comparable_distance.qbk]}
349 template <typename Geometry1, typename Geometry2>
350 inline typename default_comparable_distance_result<Geometry1, Geometry2>::type
351 comparable_distance(Geometry1 const& geometry1, Geometry2 const& geometry2)
353 concepts::check<Geometry1 const>();
354 concepts::check<Geometry2 const>();
356 return geometry::comparable_distance(geometry1, geometry2, default_strategy());
360 }} // namespace boost::geometry
363 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_COMPARABLE_DISTANCE_INTERFACE_HPP