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