comparable_distance.hpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  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. #ifndef BOOST_GEOMETRY_ALGORITHMS_COMPARABLE_DISTANCE_HPP
  11. #define BOOST_GEOMETRY_ALGORITHMS_COMPARABLE_DISTANCE_HPP
  12. #include <boost/geometry/algorithms/distance.hpp>
  13. namespace boost { namespace geometry
  14. {
  15. /*!
  16. \brief \brief_calc2{comparable distance measurement}
  17. \ingroup distance
  18. \details The free function comparable_distance does not necessarily calculate the distance,
  19. but it calculates a distance measure such that two distances are comparable to each other.
  20. For example: for the Cartesian coordinate system, Pythagoras is used but the square root
  21. is not taken, which makes it faster and the results of two point pairs can still be
  22. compared to each other.
  23. \tparam Geometry1 first geometry type
  24. \tparam Geometry2 second geometry type
  25. \param geometry1 \param_geometry
  26. \param geometry2 \param_geometry
  27. \return \return_calc{comparable distance}
  28. \qbk{[include reference/algorithms/comparable_distance.qbk]}
  29. */
  30. template <typename Geometry1, typename Geometry2>
  31. inline typename default_distance_result<Geometry1, Geometry2>::type comparable_distance(
  32. Geometry1 const& geometry1, Geometry2 const& geometry2)
  33. {
  34. concept::check<Geometry1 const>();
  35. concept::check<Geometry2 const>();
  36. typedef typename point_type<Geometry1>::type point1_type;
  37. typedef typename point_type<Geometry2>::type point2_type;
  38. // Define a point-point-distance-strategy
  39. // for either the normal case, either the reversed case
  40. typedef typename strategy::distance::services::comparable_type
  41. <
  42. typename boost::mpl::if_c
  43. <
  44. geometry::reverse_dispatch
  45. <Geometry1, Geometry2>::type::value,
  46. typename strategy::distance::services::default_strategy
  47. <point_tag, point2_type, point1_type>::type,
  48. typename strategy::distance::services::default_strategy
  49. <point_tag, point1_type, point2_type>::type
  50. >::type
  51. >::type strategy_type;
  52. return distance(geometry1, geometry2, strategy_type());
  53. }
  54. }} // namespace boost::geometry
  55. #endif // BOOST_GEOMETRY_ALGORITHMS_COMPARABLE_DISTANCE_HPP