point_iterator.hpp 7.5 KB

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