segment_view.hpp 2.5 KB

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