buffer_box.hpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2018-2019 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Use, modification and distribution is subject to the Boost Software License,
  4. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  5. // http://www.boost.org/LICENSE_1_0.txt)
  6. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_BUFFER_BOX_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_BUFFER_BOX_HPP
  8. #include <cstddef>
  9. #include <boost/geometry/core/coordinate_dimension.hpp>
  10. #include <boost/geometry/core/coordinate_type.hpp>
  11. #include <boost/geometry/core/access.hpp>
  12. namespace boost { namespace geometry
  13. {
  14. #ifndef DOXYGEN_NO_DETAIL
  15. namespace detail { namespace buffer
  16. {
  17. template <typename BoxIn, typename BoxOut, typename T, std::size_t C, std::size_t D, std::size_t N>
  18. struct box_loop
  19. {
  20. typedef typename coordinate_type<BoxOut>::type coordinate_type;
  21. static inline void apply(BoxIn const& box_in, T const& distance, BoxOut& box_out)
  22. {
  23. coordinate_type d = distance;
  24. set<C, D>(box_out, get<C, D>(box_in) + d);
  25. box_loop<BoxIn, BoxOut, T, C, D + 1, N>::apply(box_in, distance, box_out);
  26. }
  27. };
  28. template <typename BoxIn, typename BoxOut, typename T, std::size_t C, std::size_t N>
  29. struct box_loop<BoxIn, BoxOut, T, C, N, N>
  30. {
  31. static inline void apply(BoxIn const&, T const&, BoxOut&) {}
  32. };
  33. // Extends a box with the same amount in all directions
  34. template<typename BoxIn, typename BoxOut, typename T>
  35. inline void buffer_box(BoxIn const& box_in, T const& distance, BoxOut& box_out)
  36. {
  37. assert_dimension_equal<BoxIn, BoxOut>();
  38. static const std::size_t N = dimension<BoxIn>::value;
  39. box_loop<BoxIn, BoxOut, T, min_corner, 0, N>::apply(box_in, -distance, box_out);
  40. box_loop<BoxIn, BoxOut, T, max_corner, 0, N>::apply(box_in, distance, box_out);
  41. }
  42. }} // namespace detail::buffer
  43. #endif // DOXYGEN_NO_DETAIL
  44. }} // namespace boost::geometry
  45. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_BUFFER_BUFFER_BOX_HPP