comparable_distance_far.hpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. // Boost.Geometry Index
  2. //
  3. // squared distance between point and furthest point of the box or point
  4. //
  5. // Copyright (c) 2011-2014 Adam Wulkiewicz, Lodz, Poland.
  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. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP
  11. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP
  12. #include <boost/geometry/index/detail/algorithms/diff_abs.hpp>
  13. #include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
  14. namespace boost { namespace geometry { namespace index { namespace detail {
  15. // minmaxdist component
  16. struct comparable_distance_far_tag {};
  17. template <
  18. typename Point,
  19. typename BoxIndexable,
  20. size_t DimensionIndex>
  21. struct sum_for_indexable_dimension<Point, BoxIndexable, box_tag, comparable_distance_far_tag, DimensionIndex>
  22. {
  23. typedef typename geometry::default_comparable_distance_result<Point, BoxIndexable>::type result_type;
  24. inline static result_type apply(Point const& pt, BoxIndexable const& i)
  25. {
  26. typedef typename coordinate_type<Point>::type point_coord_t;
  27. typedef typename coordinate_type<BoxIndexable>::type indexable_coord_t;
  28. point_coord_t pt_c = geometry::get<DimensionIndex>(pt);
  29. indexable_coord_t ind_c_min = geometry::get<geometry::min_corner, DimensionIndex>(i);
  30. indexable_coord_t ind_c_max = geometry::get<geometry::max_corner, DimensionIndex>(i);
  31. result_type further_diff = 0;
  32. if ( (ind_c_min + ind_c_max) / 2 <= pt_c )
  33. further_diff = pt_c - ind_c_min;
  34. else
  35. further_diff = detail::diff_abs(pt_c, ind_c_max); // unsigned values protection
  36. return further_diff * further_diff;
  37. }
  38. };
  39. template <typename Point, typename Indexable>
  40. typename geometry::default_comparable_distance_result<Point, Indexable>::type
  41. comparable_distance_far(Point const& pt, Indexable const& i)
  42. {
  43. return detail::sum_for_indexable<
  44. Point,
  45. Indexable,
  46. typename tag<Indexable>::type,
  47. detail::comparable_distance_far_tag,
  48. dimension<Indexable>::value
  49. >::apply(pt, i);
  50. }
  51. }}}} // namespace boost::geometry::index::detail
  52. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP