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