comparable_distance_far.hpp 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. // This file was modified by Oracle on 2021.
  8. // Modifications copyright (c) 2021 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. #ifndef BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP
  15. #define BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP
  16. #include <boost/geometry/algorithms/detail/comparable_distance/interface.hpp>
  17. #include <boost/geometry/core/access.hpp>
  18. #include <boost/geometry/index/detail/algorithms/diff_abs.hpp>
  19. #include <boost/geometry/index/detail/algorithms/sum_for_indexable.hpp>
  20. namespace boost { namespace geometry { namespace index { namespace detail {
  21. // minmaxdist component
  22. struct comparable_distance_far_tag {};
  23. template <
  24. typename Point,
  25. typename BoxIndexable,
  26. size_t DimensionIndex>
  27. struct sum_for_indexable_dimension<Point, BoxIndexable, box_tag, comparable_distance_far_tag, DimensionIndex>
  28. {
  29. typedef typename geometry::default_comparable_distance_result<Point, BoxIndexable>::type result_type;
  30. inline static result_type apply(Point const& pt, BoxIndexable const& i)
  31. {
  32. typedef typename coordinate_type<Point>::type point_coord_t;
  33. typedef typename coordinate_type<BoxIndexable>::type indexable_coord_t;
  34. point_coord_t pt_c = geometry::get<DimensionIndex>(pt);
  35. indexable_coord_t ind_c_min = geometry::get<geometry::min_corner, DimensionIndex>(i);
  36. indexable_coord_t ind_c_max = geometry::get<geometry::max_corner, DimensionIndex>(i);
  37. result_type further_diff = 0;
  38. if ( (ind_c_min + ind_c_max) / 2 <= pt_c )
  39. further_diff = pt_c - ind_c_min;
  40. else
  41. further_diff = detail::diff_abs(pt_c, ind_c_max); // unsigned values protection
  42. return further_diff * further_diff;
  43. }
  44. };
  45. template <typename Point, typename Indexable>
  46. typename geometry::default_comparable_distance_result<Point, Indexable>::type
  47. comparable_distance_far(Point const& pt, Indexable const& i)
  48. {
  49. return detail::sum_for_indexable<
  50. Point,
  51. Indexable,
  52. typename tag<Indexable>::type,
  53. detail::comparable_distance_far_tag,
  54. dimension<Indexable>::value
  55. >::apply(pt, i);
  56. }
  57. }}}} // namespace boost::geometry::index::detail
  58. #endif // BOOST_GEOMETRY_INDEX_DETAIL_ALGORITHMS_COMPARABLE_DISTANCE_FAR_HPP