segment_view.hpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // This file was modified by Oracle on 2020.
  6. // Modifications copyright (c) 2020 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_VIEWS_SEGMENT_VIEW_HPP
  14. #define BOOST_GEOMETRY_VIEWS_SEGMENT_VIEW_HPP
  15. #include <boost/geometry/core/point_type.hpp>
  16. #include <boost/geometry/views/detail/points_view.hpp>
  17. #include <boost/geometry/algorithms/assign.hpp>
  18. namespace boost { namespace geometry
  19. {
  20. /*!
  21. \brief Makes a segment behave like a linestring or a range
  22. \details Adapts a segment to the Boost.Range concept, enabling the user to
  23. iterate the two segment points. The segment_view is registered as a LineString Concept
  24. \tparam Segment \tparam_geometry{Segment}
  25. \ingroup views
  26. \qbk{before.synopsis,
  27. [heading Model of]
  28. [link geometry.reference.concepts.concept_linestring LineString Concept]
  29. }
  30. \qbk{[include reference/views/segment_view.qbk]}
  31. */
  32. template <typename Segment>
  33. struct segment_view
  34. : public detail::points_view
  35. <
  36. typename geometry::point_type<Segment>::type,
  37. 2
  38. >
  39. {
  40. typedef typename geometry::point_type<Segment>::type point_type;
  41. /// Constructor accepting the segment to adapt
  42. explicit segment_view(Segment const& segment)
  43. : detail::points_view<point_type, 2>(copy_policy(segment))
  44. {}
  45. private :
  46. class copy_policy
  47. {
  48. public :
  49. inline copy_policy(Segment const& segment)
  50. : m_segment(segment)
  51. {}
  52. inline void apply(point_type* points) const
  53. {
  54. geometry::detail::assign_point_from_index<0>(m_segment, points[0]);
  55. geometry::detail::assign_point_from_index<1>(m_segment, points[1]);
  56. }
  57. private :
  58. Segment const& m_segment;
  59. };
  60. };
  61. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  62. // All segment ranges can be handled as linestrings
  63. namespace traits
  64. {
  65. template<typename Segment>
  66. struct tag<segment_view<Segment> >
  67. {
  68. typedef linestring_tag type;
  69. };
  70. }
  71. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  72. }} // namespace boost::geometry
  73. #endif // BOOST_GEOMETRY_VIEWS_SEGMENT_VIEW_HPP