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_ALGORITHMS_ASSIGN_VALUES_HPP
|
Chris@16
|
15 #define BOOST_GEOMETRY_ALGORITHMS_ASSIGN_VALUES_HPP
|
Chris@16
|
16
|
Chris@16
|
17
|
Chris@16
|
18 #include <cstddef>
|
Chris@16
|
19
|
Chris@16
|
20 #include <boost/concept/requires.hpp>
|
Chris@16
|
21 #include <boost/concept_check.hpp>
|
Chris@16
|
22 #include <boost/mpl/assert.hpp>
|
Chris@16
|
23 #include <boost/mpl/if.hpp>
|
Chris@16
|
24 #include <boost/numeric/conversion/bounds.hpp>
|
Chris@16
|
25 #include <boost/numeric/conversion/cast.hpp>
|
Chris@16
|
26 #include <boost/type_traits.hpp>
|
Chris@16
|
27
|
Chris@16
|
28 #include <boost/geometry/arithmetic/arithmetic.hpp>
|
Chris@16
|
29 #include <boost/geometry/algorithms/append.hpp>
|
Chris@16
|
30 #include <boost/geometry/algorithms/clear.hpp>
|
Chris@16
|
31 #include <boost/geometry/core/access.hpp>
|
Chris@16
|
32 #include <boost/geometry/core/exterior_ring.hpp>
|
Chris@16
|
33 #include <boost/geometry/core/tags.hpp>
|
Chris@16
|
34
|
Chris@16
|
35 #include <boost/geometry/geometries/concepts/check.hpp>
|
Chris@16
|
36
|
Chris@16
|
37
|
Chris@16
|
38 #include <boost/geometry/util/for_each_coordinate.hpp>
|
Chris@16
|
39
|
Chris@16
|
40
|
Chris@16
|
41 namespace boost { namespace geometry
|
Chris@16
|
42 {
|
Chris@16
|
43
|
Chris@16
|
44 #ifndef DOXYGEN_NO_DETAIL
|
Chris@16
|
45 namespace detail { namespace assign
|
Chris@16
|
46 {
|
Chris@16
|
47
|
Chris@16
|
48
|
Chris@16
|
49 template <std::size_t Index, std::size_t Dimension, std::size_t DimensionCount>
|
Chris@16
|
50 struct initialize
|
Chris@16
|
51 {
|
Chris@16
|
52 template <typename Box>
|
Chris@16
|
53 static inline void apply(Box& box, typename coordinate_type<Box>::type const& value)
|
Chris@16
|
54 {
|
Chris@16
|
55 geometry::set<Index, Dimension>(box, value);
|
Chris@16
|
56 initialize<Index, Dimension + 1, DimensionCount>::apply(box, value);
|
Chris@16
|
57 }
|
Chris@16
|
58 };
|
Chris@16
|
59
|
Chris@16
|
60
|
Chris@16
|
61 template <std::size_t Index, std::size_t DimensionCount>
|
Chris@16
|
62 struct initialize<Index, DimensionCount, DimensionCount>
|
Chris@16
|
63 {
|
Chris@16
|
64 template <typename Box>
|
Chris@16
|
65 static inline void apply(Box&, typename coordinate_type<Box>::type const&)
|
Chris@16
|
66 {}
|
Chris@16
|
67 };
|
Chris@16
|
68
|
Chris@16
|
69
|
Chris@16
|
70 struct assign_zero_point
|
Chris@16
|
71 {
|
Chris@16
|
72 template <typename Point>
|
Chris@16
|
73 static inline void apply(Point& point)
|
Chris@16
|
74 {
|
Chris@16
|
75 geometry::assign_value(point, 0);
|
Chris@16
|
76 }
|
Chris@16
|
77 };
|
Chris@16
|
78
|
Chris@16
|
79
|
Chris@16
|
80 struct assign_inverse_box_or_segment
|
Chris@16
|
81 {
|
Chris@16
|
82
|
Chris@16
|
83 template <typename BoxOrSegment>
|
Chris@16
|
84 static inline void apply(BoxOrSegment& geometry)
|
Chris@16
|
85 {
|
Chris@16
|
86 typedef typename point_type<BoxOrSegment>::type point_type;
|
Chris@16
|
87 typedef typename coordinate_type<point_type>::type bound_type;
|
Chris@16
|
88
|
Chris@16
|
89 initialize<0, 0, dimension<BoxOrSegment>::type::value>::apply(
|
Chris@16
|
90 geometry, boost::numeric::bounds<bound_type>::highest()
|
Chris@16
|
91 );
|
Chris@16
|
92 initialize<1, 0, dimension<BoxOrSegment>::type::value>::apply(
|
Chris@16
|
93 geometry, boost::numeric::bounds<bound_type>::lowest()
|
Chris@16
|
94 );
|
Chris@16
|
95 }
|
Chris@16
|
96 };
|
Chris@16
|
97
|
Chris@16
|
98
|
Chris@16
|
99 struct assign_zero_box_or_segment
|
Chris@16
|
100 {
|
Chris@16
|
101 template <typename BoxOrSegment>
|
Chris@16
|
102 static inline void apply(BoxOrSegment& geometry)
|
Chris@16
|
103 {
|
Chris@16
|
104 typedef typename coordinate_type<BoxOrSegment>::type coordinate_type;
|
Chris@16
|
105
|
Chris@16
|
106 initialize<0, 0, dimension<BoxOrSegment>::type::value>::apply(
|
Chris@16
|
107 geometry, coordinate_type()
|
Chris@16
|
108 );
|
Chris@16
|
109 initialize<1, 0, dimension<BoxOrSegment>::type::value>::apply(
|
Chris@16
|
110 geometry, coordinate_type()
|
Chris@16
|
111 );
|
Chris@16
|
112 }
|
Chris@16
|
113 };
|
Chris@16
|
114
|
Chris@16
|
115
|
Chris@16
|
116 template
|
Chris@16
|
117 <
|
Chris@16
|
118 std::size_t Corner1, std::size_t Corner2,
|
Chris@16
|
119 typename Box, typename Point
|
Chris@16
|
120 >
|
Chris@16
|
121 inline void assign_box_2d_corner(Box const& box, Point& point)
|
Chris@16
|
122 {
|
Chris@16
|
123 // Be sure both are 2-Dimensional
|
Chris@16
|
124 assert_dimension<Box, 2>();
|
Chris@16
|
125 assert_dimension<Point, 2>();
|
Chris@16
|
126
|
Chris@16
|
127 // Copy coordinates
|
Chris@16
|
128 typedef typename coordinate_type<Point>::type coordinate_type;
|
Chris@16
|
129
|
Chris@16
|
130 geometry::set<0>(point, boost::numeric_cast<coordinate_type>(get<Corner1, 0>(box)));
|
Chris@16
|
131 geometry::set<1>(point, boost::numeric_cast<coordinate_type>(get<Corner2, 1>(box)));
|
Chris@16
|
132 }
|
Chris@16
|
133
|
Chris@16
|
134
|
Chris@16
|
135
|
Chris@16
|
136 template
|
Chris@16
|
137 <
|
Chris@16
|
138 typename Geometry, typename Point,
|
Chris@16
|
139 std::size_t Index,
|
Chris@16
|
140 std::size_t Dimension, std::size_t DimensionCount
|
Chris@16
|
141 >
|
Chris@16
|
142 struct assign_point_to_index
|
Chris@16
|
143 {
|
Chris@16
|
144
|
Chris@16
|
145 static inline void apply(Point const& point, Geometry& geometry)
|
Chris@16
|
146 {
|
Chris@16
|
147 geometry::set<Index, Dimension>(geometry, boost::numeric_cast
|
Chris@16
|
148 <
|
Chris@16
|
149 typename coordinate_type<Geometry>::type
|
Chris@16
|
150 >(geometry::get<Dimension>(point)));
|
Chris@16
|
151
|
Chris@16
|
152 assign_point_to_index
|
Chris@16
|
153 <
|
Chris@16
|
154 Geometry, Point, Index, Dimension + 1, DimensionCount
|
Chris@16
|
155 >::apply(point, geometry);
|
Chris@16
|
156 }
|
Chris@16
|
157 };
|
Chris@16
|
158
|
Chris@16
|
159 template
|
Chris@16
|
160 <
|
Chris@16
|
161 typename Geometry, typename Point,
|
Chris@16
|
162 std::size_t Index,
|
Chris@16
|
163 std::size_t DimensionCount
|
Chris@16
|
164 >
|
Chris@16
|
165 struct assign_point_to_index
|
Chris@16
|
166 <
|
Chris@16
|
167 Geometry, Point,
|
Chris@16
|
168 Index,
|
Chris@16
|
169 DimensionCount, DimensionCount
|
Chris@16
|
170 >
|
Chris@16
|
171 {
|
Chris@16
|
172 static inline void apply(Point const& , Geometry& )
|
Chris@16
|
173 {
|
Chris@16
|
174 }
|
Chris@16
|
175 };
|
Chris@16
|
176
|
Chris@16
|
177
|
Chris@16
|
178 template
|
Chris@16
|
179 <
|
Chris@16
|
180 typename Geometry, typename Point,
|
Chris@16
|
181 std::size_t Index,
|
Chris@16
|
182 std::size_t Dimension, std::size_t DimensionCount
|
Chris@16
|
183 >
|
Chris@16
|
184 struct assign_point_from_index
|
Chris@16
|
185 {
|
Chris@16
|
186
|
Chris@16
|
187 static inline void apply(Geometry const& geometry, Point& point)
|
Chris@16
|
188 {
|
Chris@16
|
189 geometry::set<Dimension>( point, boost::numeric_cast
|
Chris@16
|
190 <
|
Chris@16
|
191 typename coordinate_type<Point>::type
|
Chris@16
|
192 >(geometry::get<Index, Dimension>(geometry)));
|
Chris@16
|
193
|
Chris@16
|
194 assign_point_from_index
|
Chris@16
|
195 <
|
Chris@16
|
196 Geometry, Point, Index, Dimension + 1, DimensionCount
|
Chris@16
|
197 >::apply(geometry, point);
|
Chris@16
|
198 }
|
Chris@16
|
199 };
|
Chris@16
|
200
|
Chris@16
|
201 template
|
Chris@16
|
202 <
|
Chris@16
|
203 typename Geometry, typename Point,
|
Chris@16
|
204 std::size_t Index,
|
Chris@16
|
205 std::size_t DimensionCount
|
Chris@16
|
206 >
|
Chris@16
|
207 struct assign_point_from_index
|
Chris@16
|
208 <
|
Chris@16
|
209 Geometry, Point,
|
Chris@16
|
210 Index,
|
Chris@16
|
211 DimensionCount, DimensionCount
|
Chris@16
|
212 >
|
Chris@16
|
213 {
|
Chris@16
|
214 static inline void apply(Geometry const&, Point&)
|
Chris@16
|
215 {
|
Chris@16
|
216 }
|
Chris@16
|
217 };
|
Chris@16
|
218
|
Chris@16
|
219
|
Chris@16
|
220 template <typename Geometry>
|
Chris@16
|
221 struct assign_2d_box_or_segment
|
Chris@16
|
222 {
|
Chris@16
|
223 typedef typename coordinate_type<Geometry>::type coordinate_type;
|
Chris@16
|
224
|
Chris@16
|
225 // Here we assign 4 coordinates to a box of segment
|
Chris@16
|
226 // -> Most logical is: x1,y1,x2,y2
|
Chris@16
|
227 // In case the user reverses x1/x2 or y1/y2, for a box, we could reverse them (THAT IS NOT IMPLEMENTED)
|
Chris@16
|
228
|
Chris@16
|
229 template <typename Type>
|
Chris@16
|
230 static inline void apply(Geometry& geometry,
|
Chris@16
|
231 Type const& x1, Type const& y1, Type const& x2, Type const& y2)
|
Chris@16
|
232 {
|
Chris@16
|
233 geometry::set<0, 0>(geometry, boost::numeric_cast<coordinate_type>(x1));
|
Chris@16
|
234 geometry::set<0, 1>(geometry, boost::numeric_cast<coordinate_type>(y1));
|
Chris@16
|
235 geometry::set<1, 0>(geometry, boost::numeric_cast<coordinate_type>(x2));
|
Chris@16
|
236 geometry::set<1, 1>(geometry, boost::numeric_cast<coordinate_type>(y2));
|
Chris@16
|
237 }
|
Chris@16
|
238 };
|
Chris@16
|
239
|
Chris@16
|
240
|
Chris@16
|
241 }} // namespace detail::assign
|
Chris@16
|
242 #endif // DOXYGEN_NO_DETAIL
|
Chris@16
|
243
|
Chris@16
|
244 #ifndef DOXYGEN_NO_DISPATCH
|
Chris@16
|
245 namespace dispatch
|
Chris@16
|
246 {
|
Chris@16
|
247
|
Chris@16
|
248 template <typename GeometryTag, typename Geometry, std::size_t DimensionCount>
|
Chris@16
|
249 struct assign
|
Chris@16
|
250 {
|
Chris@16
|
251 BOOST_MPL_ASSERT_MSG
|
Chris@16
|
252 (
|
Chris@16
|
253 false, NOT_OR_NOT_YET_IMPLEMENTED_FOR_THIS_GEOMETRY_TYPE
|
Chris@16
|
254 , (types<Geometry>)
|
Chris@16
|
255 );
|
Chris@16
|
256 };
|
Chris@16
|
257
|
Chris@16
|
258 template <typename Point>
|
Chris@16
|
259 struct assign<point_tag, Point, 2>
|
Chris@16
|
260 {
|
Chris@16
|
261 typedef typename coordinate_type<Point>::type coordinate_type;
|
Chris@16
|
262
|
Chris@16
|
263 template <typename T>
|
Chris@16
|
264 static inline void apply(Point& point, T const& c1, T const& c2)
|
Chris@16
|
265 {
|
Chris@16
|
266 set<0>(point, boost::numeric_cast<coordinate_type>(c1));
|
Chris@16
|
267 set<1>(point, boost::numeric_cast<coordinate_type>(c2));
|
Chris@16
|
268 }
|
Chris@16
|
269 };
|
Chris@16
|
270
|
Chris@16
|
271 template <typename Point>
|
Chris@16
|
272 struct assign<point_tag, Point, 3>
|
Chris@16
|
273 {
|
Chris@16
|
274 typedef typename coordinate_type<Point>::type coordinate_type;
|
Chris@16
|
275
|
Chris@16
|
276 template <typename T>
|
Chris@16
|
277 static inline void apply(Point& point, T const& c1, T const& c2, T const& c3)
|
Chris@16
|
278 {
|
Chris@16
|
279 set<0>(point, boost::numeric_cast<coordinate_type>(c1));
|
Chris@16
|
280 set<1>(point, boost::numeric_cast<coordinate_type>(c2));
|
Chris@16
|
281 set<2>(point, boost::numeric_cast<coordinate_type>(c3));
|
Chris@16
|
282 }
|
Chris@16
|
283 };
|
Chris@16
|
284
|
Chris@16
|
285 template <typename Box>
|
Chris@16
|
286 struct assign<box_tag, Box, 2>
|
Chris@16
|
287 : detail::assign::assign_2d_box_or_segment<Box>
|
Chris@16
|
288 {};
|
Chris@16
|
289
|
Chris@16
|
290 template <typename Segment>
|
Chris@16
|
291 struct assign<segment_tag, Segment, 2>
|
Chris@16
|
292 : detail::assign::assign_2d_box_or_segment<Segment>
|
Chris@16
|
293 {};
|
Chris@16
|
294
|
Chris@16
|
295
|
Chris@16
|
296
|
Chris@16
|
297 template <typename GeometryTag, typename Geometry>
|
Chris@16
|
298 struct assign_zero {};
|
Chris@16
|
299
|
Chris@16
|
300
|
Chris@16
|
301 template <typename Point>
|
Chris@16
|
302 struct assign_zero<point_tag, Point>
|
Chris@16
|
303 : detail::assign::assign_zero_point
|
Chris@16
|
304 {};
|
Chris@16
|
305
|
Chris@16
|
306 template <typename Box>
|
Chris@16
|
307 struct assign_zero<box_tag, Box>
|
Chris@16
|
308 : detail::assign::assign_zero_box_or_segment
|
Chris@16
|
309 {};
|
Chris@16
|
310
|
Chris@16
|
311 template <typename Segment>
|
Chris@16
|
312 struct assign_zero<segment_tag, Segment>
|
Chris@16
|
313 : detail::assign::assign_zero_box_or_segment
|
Chris@16
|
314 {};
|
Chris@16
|
315
|
Chris@16
|
316
|
Chris@16
|
317 template <typename GeometryTag, typename Geometry>
|
Chris@16
|
318 struct assign_inverse {};
|
Chris@16
|
319
|
Chris@16
|
320 template <typename Box>
|
Chris@16
|
321 struct assign_inverse<box_tag, Box>
|
Chris@16
|
322 : detail::assign::assign_inverse_box_or_segment
|
Chris@16
|
323 {};
|
Chris@16
|
324
|
Chris@16
|
325 template <typename Segment>
|
Chris@16
|
326 struct assign_inverse<segment_tag, Segment>
|
Chris@16
|
327 : detail::assign::assign_inverse_box_or_segment
|
Chris@16
|
328 {};
|
Chris@16
|
329
|
Chris@16
|
330
|
Chris@16
|
331 } // namespace dispatch
|
Chris@16
|
332 #endif // DOXYGEN_NO_DISPATCH
|
Chris@16
|
333
|
Chris@16
|
334 }} // namespace boost::geometry
|
Chris@16
|
335
|
Chris@16
|
336
|
Chris@16
|
337 #endif // BOOST_GEOMETRY_ALGORITHMS_ASSIGN_VALUES_HPP
|