segment_as_subrange.hpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2019-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_OVERLAY_SEGMENT_AS_SUBRANGE_HPP
  7. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_SEGMENT_AS_SUBRANGE_HPP
  8. #include <cstddef>
  9. #include <map>
  10. #include <boost/geometry/core/access.hpp>
  11. namespace boost { namespace geometry
  12. {
  13. #ifndef DOXYGEN_NO_DETAIL
  14. namespace detail
  15. {
  16. template <typename Segment>
  17. struct segment_as_subrange
  18. {
  19. segment_as_subrange(Segment const& s)
  20. : m_segment(s)
  21. {
  22. geometry::set<0>(m_p1, geometry::get<0, 0>(m_segment));
  23. geometry::set<1>(m_p1, geometry::get<0, 1>(m_segment));
  24. geometry::set<0>(m_p2, geometry::get<1, 0>(m_segment));
  25. geometry::set<1>(m_p2, geometry::get<1, 1>(m_segment));
  26. }
  27. typedef typename geometry::point_type<Segment>::type point_type;
  28. point_type const& at(std::size_t index) const
  29. {
  30. return index == 0 ? m_p1 : m_p2;
  31. }
  32. static inline bool is_last_segment()
  33. {
  34. return true;
  35. }
  36. point_type m_p1, m_p2;
  37. Segment const& m_segment;
  38. };
  39. } // namespace detail
  40. #endif // DOXYGEN_NO_DETAIL
  41. }} // namespace boost::geometry
  42. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAY_SEGMENT_AS_SUBRANGE_HPP