utilities.hpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. // Boost.Geometry
  2. // Copyright (c) 2021-2023, Oracle and/or its affiliates.
  3. // Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
  4. // Licensed under the Boost Software License version 1.0.
  5. // http://www.boost.org/users/license.html
  6. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_POINTS_UTILITIES_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_POINTS_UTILITIES_HPP
  8. #include <boost/geometry/algorithms/detail/assign_indexed_point.hpp>
  9. #include <boost/geometry/util/algorithm.hpp>
  10. #include <boost/geometry/strategies/distance.hpp>
  11. namespace boost { namespace geometry
  12. {
  13. namespace detail { namespace closest_points
  14. {
  15. struct set_segment_from_points
  16. {
  17. template <typename Point1, typename Point2, typename Segment>
  18. static inline void apply(Point1 const& p1, Point2 const& p2, Segment& segment)
  19. {
  20. assign_point_to_index<0>(p1, segment);
  21. assign_point_to_index<1>(p2, segment);
  22. }
  23. };
  24. struct swap_segment_points
  25. {
  26. template <typename Segment>
  27. static inline void apply(Segment& segment)
  28. {
  29. geometry::detail::for_each_dimension<Segment>([&](auto index)
  30. {
  31. auto temp = get<0,index>(segment);
  32. set<0,index>(segment, get<1,index>(segment));
  33. set<1,index>(segment, temp);
  34. });
  35. }
  36. };
  37. template <typename Geometry1, typename Geometry2, typename Strategies>
  38. using distance_strategy_t = decltype(
  39. std::declval<Strategies>().distance(std::declval<Geometry1>(), std::declval<Geometry2>()));
  40. template <typename Geometry1, typename Geometry2, typename Strategies>
  41. using creturn_t = typename strategy::distance::services::return_type
  42. <
  43. typename strategy::distance::services::comparable_type
  44. <
  45. distance_strategy_t<Geometry1, Geometry2, Strategies>
  46. >::type,
  47. typename point_type<Geometry1>::type,
  48. typename point_type<Geometry2>::type
  49. >::type;
  50. }} // namespace detail::closest_points
  51. }} // namespace boost::geometry
  52. #endif //BOOST_GEOMETRY_ALGORITHMS_DETAIL_CLOSEST_POINTS_UTILITIES_HPP