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_GEOMETRIES_SEGMENT_HPP
|
Chris@16
|
15 #define BOOST_GEOMETRY_GEOMETRIES_SEGMENT_HPP
|
Chris@16
|
16
|
Chris@16
|
17 #include <cstddef>
|
Chris@16
|
18
|
Chris@16
|
19 #include <boost/concept/assert.hpp>
|
Chris@16
|
20 #include <boost/mpl/if.hpp>
|
Chris@16
|
21 #include <boost/type_traits/is_const.hpp>
|
Chris@16
|
22
|
Chris@16
|
23 #include <boost/geometry/geometries/concepts/point_concept.hpp>
|
Chris@16
|
24
|
Chris@16
|
25 namespace boost { namespace geometry
|
Chris@16
|
26 {
|
Chris@16
|
27
|
Chris@16
|
28 namespace model
|
Chris@16
|
29 {
|
Chris@16
|
30
|
Chris@16
|
31 /*!
|
Chris@16
|
32 \brief Class segment: small class containing two points
|
Chris@16
|
33 \ingroup geometries
|
Chris@16
|
34 \details From Wikipedia: In geometry, a line segment is a part of a line that is bounded
|
Chris@16
|
35 by two distinct end points, and contains every point on the line between its end points.
|
Chris@16
|
36 \note There is also a point-referring-segment, class referring_segment,
|
Chris@16
|
37 containing point references, where points are NOT copied
|
Chris@16
|
38 */
|
Chris@16
|
39 template<typename Point>
|
Chris@16
|
40 class segment : public std::pair<Point, Point>
|
Chris@16
|
41 {
|
Chris@16
|
42 public :
|
Chris@16
|
43 inline segment()
|
Chris@16
|
44 {}
|
Chris@16
|
45
|
Chris@16
|
46 inline segment(Point const& p1, Point const& p2)
|
Chris@16
|
47 {
|
Chris@16
|
48 this->first = p1;
|
Chris@16
|
49 this->second = p2;
|
Chris@16
|
50 }
|
Chris@16
|
51 };
|
Chris@16
|
52
|
Chris@16
|
53
|
Chris@16
|
54 /*!
|
Chris@16
|
55 \brief Class segment: small class containing two (templatized) point references
|
Chris@16
|
56 \ingroup geometries
|
Chris@16
|
57 \details From Wikipedia: In geometry, a line segment is a part of a line that is bounded
|
Chris@16
|
58 by two distinct end points, and contains every point on the line between its end points.
|
Chris@16
|
59 \note The structure is like std::pair, and can often be used interchangeable.
|
Chris@16
|
60 Difference is that it refers to points, does not have points.
|
Chris@16
|
61 \note Like std::pair, points are public available.
|
Chris@16
|
62 \note type is const or non const, so geometry::segment<P> or geometry::segment<P const>
|
Chris@16
|
63 \note We cannot derive from std::pair<P&, P&> because of
|
Chris@16
|
64 reference assignments.
|
Chris@16
|
65 \tparam ConstOrNonConstPoint point type of the segment, maybe a point or a const point
|
Chris@16
|
66 */
|
Chris@16
|
67 template<typename ConstOrNonConstPoint>
|
Chris@16
|
68 class referring_segment
|
Chris@16
|
69 {
|
Chris@16
|
70 BOOST_CONCEPT_ASSERT( (
|
Chris@16
|
71 typename boost::mpl::if_
|
Chris@16
|
72 <
|
Chris@16
|
73 boost::is_const<ConstOrNonConstPoint>,
|
Chris@16
|
74 concept::Point<ConstOrNonConstPoint>,
|
Chris@16
|
75 concept::ConstPoint<ConstOrNonConstPoint>
|
Chris@16
|
76 >
|
Chris@16
|
77 ) );
|
Chris@16
|
78
|
Chris@16
|
79 typedef ConstOrNonConstPoint point_type;
|
Chris@16
|
80
|
Chris@16
|
81 public:
|
Chris@16
|
82
|
Chris@16
|
83 point_type& first;
|
Chris@16
|
84 point_type& second;
|
Chris@16
|
85
|
Chris@16
|
86 inline referring_segment(point_type& p1, point_type& p2)
|
Chris@16
|
87 : first(p1)
|
Chris@16
|
88 , second(p2)
|
Chris@16
|
89 {}
|
Chris@16
|
90 };
|
Chris@16
|
91
|
Chris@16
|
92
|
Chris@16
|
93 } // namespace model
|
Chris@16
|
94
|
Chris@16
|
95
|
Chris@16
|
96 // Traits specializations for segment above
|
Chris@16
|
97 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
|
Chris@16
|
98 namespace traits
|
Chris@16
|
99 {
|
Chris@16
|
100
|
Chris@16
|
101 template <typename Point>
|
Chris@16
|
102 struct tag<model::segment<Point> >
|
Chris@16
|
103 {
|
Chris@16
|
104 typedef segment_tag type;
|
Chris@16
|
105 };
|
Chris@16
|
106
|
Chris@16
|
107 template <typename Point>
|
Chris@16
|
108 struct point_type<model::segment<Point> >
|
Chris@16
|
109 {
|
Chris@16
|
110 typedef Point type;
|
Chris@16
|
111 };
|
Chris@16
|
112
|
Chris@16
|
113 template <typename Point, std::size_t Dimension>
|
Chris@16
|
114 struct indexed_access<model::segment<Point>, 0, Dimension>
|
Chris@16
|
115 {
|
Chris@16
|
116 typedef model::segment<Point> segment_type;
|
Chris@16
|
117 typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
|
Chris@16
|
118
|
Chris@16
|
119 static inline coordinate_type get(segment_type const& s)
|
Chris@16
|
120 {
|
Chris@16
|
121 return geometry::get<Dimension>(s.first);
|
Chris@16
|
122 }
|
Chris@16
|
123
|
Chris@16
|
124 static inline void set(segment_type& s, coordinate_type const& value)
|
Chris@16
|
125 {
|
Chris@16
|
126 geometry::set<Dimension>(s.first, value);
|
Chris@16
|
127 }
|
Chris@16
|
128 };
|
Chris@16
|
129
|
Chris@16
|
130
|
Chris@16
|
131 template <typename Point, std::size_t Dimension>
|
Chris@16
|
132 struct indexed_access<model::segment<Point>, 1, Dimension>
|
Chris@16
|
133 {
|
Chris@16
|
134 typedef model::segment<Point> segment_type;
|
Chris@16
|
135 typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
|
Chris@16
|
136
|
Chris@16
|
137 static inline coordinate_type get(segment_type const& s)
|
Chris@16
|
138 {
|
Chris@16
|
139 return geometry::get<Dimension>(s.second);
|
Chris@16
|
140 }
|
Chris@16
|
141
|
Chris@16
|
142 static inline void set(segment_type& s, coordinate_type const& value)
|
Chris@16
|
143 {
|
Chris@16
|
144 geometry::set<Dimension>(s.second, value);
|
Chris@16
|
145 }
|
Chris@16
|
146 };
|
Chris@16
|
147
|
Chris@16
|
148
|
Chris@16
|
149 template <typename ConstOrNonConstPoint>
|
Chris@16
|
150 struct tag<model::referring_segment<ConstOrNonConstPoint> >
|
Chris@16
|
151 {
|
Chris@16
|
152 typedef segment_tag type;
|
Chris@16
|
153 };
|
Chris@16
|
154
|
Chris@16
|
155 template <typename ConstOrNonConstPoint>
|
Chris@16
|
156 struct point_type<model::referring_segment<ConstOrNonConstPoint> >
|
Chris@16
|
157 {
|
Chris@16
|
158 typedef ConstOrNonConstPoint type;
|
Chris@16
|
159 };
|
Chris@16
|
160
|
Chris@16
|
161 template <typename ConstOrNonConstPoint, std::size_t Dimension>
|
Chris@16
|
162 struct indexed_access<model::referring_segment<ConstOrNonConstPoint>, 0, Dimension>
|
Chris@16
|
163 {
|
Chris@16
|
164 typedef model::referring_segment<ConstOrNonConstPoint> segment_type;
|
Chris@16
|
165 typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
|
Chris@16
|
166
|
Chris@16
|
167 static inline coordinate_type get(segment_type const& s)
|
Chris@16
|
168 {
|
Chris@16
|
169 return geometry::get<Dimension>(s.first);
|
Chris@16
|
170 }
|
Chris@16
|
171
|
Chris@16
|
172 static inline void set(segment_type& s, coordinate_type const& value)
|
Chris@16
|
173 {
|
Chris@16
|
174 geometry::set<Dimension>(s.first, value);
|
Chris@16
|
175 }
|
Chris@16
|
176 };
|
Chris@16
|
177
|
Chris@16
|
178
|
Chris@16
|
179 template <typename ConstOrNonConstPoint, std::size_t Dimension>
|
Chris@16
|
180 struct indexed_access<model::referring_segment<ConstOrNonConstPoint>, 1, Dimension>
|
Chris@16
|
181 {
|
Chris@16
|
182 typedef model::referring_segment<ConstOrNonConstPoint> segment_type;
|
Chris@16
|
183 typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
|
Chris@16
|
184
|
Chris@16
|
185 static inline coordinate_type get(segment_type const& s)
|
Chris@16
|
186 {
|
Chris@16
|
187 return geometry::get<Dimension>(s.second);
|
Chris@16
|
188 }
|
Chris@16
|
189
|
Chris@16
|
190 static inline void set(segment_type& s, coordinate_type const& value)
|
Chris@16
|
191 {
|
Chris@16
|
192 geometry::set<Dimension>(s.second, value);
|
Chris@16
|
193 }
|
Chris@16
|
194 };
|
Chris@16
|
195
|
Chris@16
|
196
|
Chris@16
|
197
|
Chris@16
|
198 } // namespace traits
|
Chris@16
|
199 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
|
Chris@16
|
200
|
Chris@16
|
201 }} // namespace boost::geometry
|
Chris@16
|
202
|
Chris@16
|
203 #endif // BOOST_GEOMETRY_GEOMETRIES_SEGMENT_HPP
|