point_iterator.hpp 7.4 KB

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