]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
1e59de90 | 3 | // Copyright (c) 2014-2021, Oracle and/or its affiliates. |
7c673cae | 4 | // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle |
20effc67 | 5 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle |
7c673cae FG |
6 | |
7 | // Licensed under the Boost Software License version 1.0. | |
8 | // http://www.boost.org/users/license.html | |
9 | ||
10 | #ifndef BOOST_GEOMETRY_ITERATORS_POINT_ITERATOR_HPP | |
11 | #define BOOST_GEOMETRY_ITERATORS_POINT_ITERATOR_HPP | |
12 | ||
20effc67 TL |
13 | |
14 | #include <type_traits> | |
15 | ||
7c673cae | 16 | #include <boost/iterator/iterator_adaptor.hpp> |
20effc67 TL |
17 | #include <boost/range/begin.hpp> |
18 | #include <boost/range/end.hpp> | |
7c673cae FG |
19 | |
20 | #include <boost/geometry/core/exterior_ring.hpp> | |
21 | #include <boost/geometry/core/interior_rings.hpp> | |
22 | #include <boost/geometry/core/tags.hpp> | |
23 | ||
24 | #include <boost/geometry/iterators/dispatch/point_iterator.hpp> | |
25 | #include <boost/geometry/iterators/detail/point_iterator/iterator_type.hpp> | |
26 | ||
27 | ||
28 | namespace boost { namespace geometry | |
29 | { | |
30 | ||
31 | ||
32 | #ifndef DOXYGEN_NO_DISPATCH | |
33 | namespace dispatch | |
34 | { | |
35 | ||
36 | ||
37 | // specializations for points_begin | |
38 | ||
39 | ||
40 | template <typename Linestring> | |
41 | struct points_begin<Linestring, linestring_tag> | |
42 | { | |
43 | static inline typename detail::point_iterator::iterator_type | |
44 | < | |
45 | Linestring | |
46 | >::type | |
47 | apply(Linestring& linestring) | |
48 | { | |
49 | return boost::begin(linestring); | |
50 | } | |
51 | }; | |
52 | ||
53 | ||
54 | template <typename Ring> | |
55 | struct points_begin<Ring, ring_tag> | |
56 | { | |
57 | static inline typename detail::point_iterator::iterator_type<Ring>::type | |
58 | apply(Ring& ring) | |
59 | { | |
60 | return boost::begin(ring); | |
61 | } | |
62 | }; | |
63 | ||
64 | ||
65 | template <typename Polygon> | |
66 | struct points_begin<Polygon, polygon_tag> | |
67 | { | |
68 | typedef typename detail::point_iterator::iterator_type | |
69 | < | |
70 | Polygon | |
71 | >::type return_type; | |
72 | ||
73 | static inline return_type apply(Polygon& polygon) | |
74 | { | |
75 | typedef typename return_type::second_iterator_type flatten_iterator; | |
76 | ||
77 | return return_type | |
78 | (boost::begin(geometry::exterior_ring(polygon)), | |
79 | boost::end(geometry::exterior_ring(polygon)), | |
80 | flatten_iterator(boost::begin(geometry::interior_rings(polygon)), | |
81 | boost::end(geometry::interior_rings(polygon)) | |
82 | ), | |
83 | flatten_iterator(boost::begin(geometry::interior_rings(polygon)), | |
84 | boost::end(geometry::interior_rings(polygon)) | |
85 | ) | |
86 | ); | |
87 | } | |
88 | }; | |
89 | ||
90 | ||
91 | template <typename MultiPoint> | |
92 | struct points_begin<MultiPoint, multi_point_tag> | |
93 | { | |
94 | static inline typename detail::point_iterator::iterator_type | |
95 | < | |
96 | MultiPoint | |
97 | >::type | |
98 | apply(MultiPoint& multipoint) | |
99 | { | |
100 | return boost::begin(multipoint); | |
101 | } | |
102 | }; | |
103 | ||
104 | ||
105 | template <typename MultiLinestring> | |
106 | struct points_begin<MultiLinestring, multi_linestring_tag> | |
107 | { | |
108 | typedef typename detail::point_iterator::iterator_type | |
109 | < | |
110 | MultiLinestring | |
111 | >::type return_type; | |
112 | ||
113 | static inline return_type apply(MultiLinestring& multilinestring) | |
114 | { | |
115 | return return_type(boost::begin(multilinestring), | |
116 | boost::end(multilinestring)); | |
117 | } | |
118 | }; | |
119 | ||
120 | ||
121 | template <typename MultiPolygon> | |
122 | struct points_begin<MultiPolygon, multi_polygon_tag> | |
123 | { | |
124 | typedef typename detail::point_iterator::iterator_type | |
125 | < | |
126 | MultiPolygon | |
127 | >::type return_type; | |
128 | ||
129 | static inline return_type apply(MultiPolygon& multipolygon) | |
130 | { | |
131 | return return_type(boost::begin(multipolygon), | |
132 | boost::end(multipolygon)); | |
133 | } | |
134 | }; | |
135 | ||
136 | } // namespace dispatch | |
137 | #endif // DOXYGEN_NO_DISPATCH | |
138 | ||
139 | ||
140 | ||
141 | ||
142 | ||
143 | #ifndef DOXYGEN_NO_DISPATCH | |
144 | namespace dispatch | |
145 | { | |
146 | ||
147 | ||
148 | // specializations for points_end | |
149 | ||
150 | ||
151 | template <typename Linestring> | |
152 | struct points_end<Linestring, linestring_tag> | |
153 | { | |
154 | static inline typename detail::point_iterator::iterator_type | |
155 | < | |
156 | Linestring | |
157 | >::type | |
158 | apply(Linestring& linestring) | |
159 | { | |
160 | return boost::end(linestring); | |
161 | } | |
162 | }; | |
163 | ||
164 | ||
165 | template <typename Ring> | |
166 | struct points_end<Ring, ring_tag> | |
167 | { | |
168 | static inline typename detail::point_iterator::iterator_type<Ring>::type | |
169 | apply(Ring& ring) | |
170 | { | |
171 | return boost::end(ring); | |
172 | } | |
173 | }; | |
174 | ||
175 | ||
176 | template <typename Polygon> | |
177 | struct points_end<Polygon, polygon_tag> | |
178 | { | |
179 | typedef typename detail::point_iterator::iterator_type | |
180 | < | |
181 | Polygon | |
182 | >::type return_type; | |
183 | ||
184 | static inline return_type apply(Polygon& polygon) | |
185 | { | |
186 | typedef typename return_type::second_iterator_type flatten_iterator; | |
187 | ||
188 | return return_type | |
189 | (boost::end(geometry::exterior_ring(polygon)), | |
190 | flatten_iterator(boost::begin(geometry::interior_rings(polygon)), | |
191 | boost::end(geometry::interior_rings(polygon)) | |
192 | ), | |
193 | flatten_iterator( boost::end(geometry::interior_rings(polygon)) ) | |
194 | ); | |
195 | } | |
196 | }; | |
197 | ||
198 | ||
199 | template <typename MultiPoint> | |
200 | struct points_end<MultiPoint, multi_point_tag> | |
201 | { | |
202 | static inline typename detail::point_iterator::iterator_type | |
203 | < | |
204 | MultiPoint | |
205 | >::type | |
206 | apply(MultiPoint& multipoint) | |
207 | { | |
208 | return boost::end(multipoint); | |
209 | } | |
210 | }; | |
211 | ||
212 | ||
213 | template <typename MultiLinestring> | |
214 | struct points_end<MultiLinestring, multi_linestring_tag> | |
215 | { | |
216 | typedef typename detail::point_iterator::iterator_type | |
217 | < | |
218 | MultiLinestring | |
219 | >::type return_type; | |
220 | ||
221 | static inline return_type apply(MultiLinestring& multilinestring) | |
222 | { | |
223 | return return_type(boost::end(multilinestring)); | |
224 | } | |
225 | }; | |
226 | ||
227 | ||
228 | template <typename MultiPolygon> | |
229 | struct points_end<MultiPolygon, multi_polygon_tag> | |
230 | { | |
231 | typedef typename detail::point_iterator::iterator_type | |
232 | < | |
233 | MultiPolygon | |
234 | >::type return_type; | |
235 | ||
236 | static inline return_type apply(MultiPolygon& multipolygon) | |
237 | { | |
238 | return return_type(boost::end(multipolygon)); | |
239 | } | |
240 | }; | |
241 | ||
242 | ||
243 | } // namespace dispatch | |
244 | #endif // DOXYGEN_NO_DISPATCH | |
245 | ||
246 | ||
247 | // MK:: need to add doc here | |
248 | template <typename Geometry> | |
249 | class point_iterator | |
250 | : public boost::iterator_adaptor | |
251 | < | |
252 | point_iterator<Geometry>, | |
253 | typename detail::point_iterator::iterator_type<Geometry>::type | |
254 | > | |
255 | { | |
256 | private: | |
257 | template <typename OtherGeometry> friend class point_iterator; | |
258 | template <typename G> friend inline point_iterator<G> points_begin(G&); | |
259 | template <typename G> friend inline point_iterator<G> points_end(G&); | |
260 | ||
261 | inline point_iterator(typename point_iterator::base_type const& base_it) | |
262 | : point_iterator::iterator_adaptor_(base_it) {} | |
263 | ||
264 | public: | |
1e59de90 TL |
265 | inline point_iterator() = default; |
266 | ||
267 | template | |
268 | < | |
269 | typename OtherGeometry, | |
270 | std::enable_if_t | |
271 | < | |
272 | std::is_convertible | |
273 | < | |
274 | typename detail::point_iterator::iterator_type<OtherGeometry>::type, | |
275 | typename detail::point_iterator::iterator_type<Geometry>::type | |
276 | >::value, | |
277 | int | |
278 | > = 0 | |
279 | > | |
7c673cae FG |
280 | inline point_iterator(point_iterator<OtherGeometry> const& other) |
281 | : point_iterator::iterator_adaptor_(other.base()) | |
1e59de90 | 282 | {} |
7c673cae FG |
283 | }; |
284 | ||
285 | ||
286 | // MK:: need to add doc here | |
287 | template <typename Geometry> | |
288 | inline point_iterator<Geometry> | |
289 | points_begin(Geometry& geometry) | |
290 | { | |
291 | return dispatch::points_begin<Geometry>::apply(geometry); | |
292 | } | |
293 | ||
294 | ||
295 | // MK:: need to add doc here | |
296 | template <typename Geometry> | |
297 | inline point_iterator<Geometry> | |
298 | points_end(Geometry& geometry) | |
299 | { | |
300 | return dispatch::points_end<Geometry>::apply(geometry); | |
301 | } | |
302 | ||
303 | ||
304 | }} // namespace boost::geometry | |
305 | ||
306 | #endif // BOOST_GEOMETRY_ITERATORS_POINT_ITERATOR_HPP |