polygon.hpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  6. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  7. // Use, modification and distribution is subject to the Boost Software License,
  8. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  9. // http://www.boost.org/LICENSE_1_0.txt)
  10. #ifndef BOOST_GEOMETRY_GEOMETRIES_POLYGON_HPP
  11. #define BOOST_GEOMETRY_GEOMETRIES_POLYGON_HPP
  12. #include <memory>
  13. #include <vector>
  14. #include <boost/concept/assert.hpp>
  15. #include <boost/geometry/core/exterior_ring.hpp>
  16. #include <boost/geometry/core/interior_rings.hpp>
  17. #include <boost/geometry/core/point_type.hpp>
  18. #include <boost/geometry/core/ring_type.hpp>
  19. #include <boost/geometry/geometries/concepts/point_concept.hpp>
  20. #include <boost/geometry/geometries/ring.hpp>
  21. namespace boost { namespace geometry
  22. {
  23. namespace model
  24. {
  25. /*!
  26. \brief The polygon contains an outer ring and zero or more inner rings.
  27. \ingroup geometries
  28. \tparam Point point type
  29. \tparam ClockWise true for clockwise direction,
  30. false for CounterClockWise direction
  31. \tparam Closed true for closed polygons (last point == first point),
  32. false open points
  33. \tparam PointList container type for points,
  34. for example std::vector, std::list, std::deque
  35. \tparam RingList container type for inner rings,
  36. for example std::vector, std::list, std::deque
  37. \tparam PointAlloc container-allocator-type, for the points
  38. \tparam RingAlloc container-allocator-type, for the rings
  39. \note The container collecting the points in the rings can be different
  40. from the container collecting the inner rings. They all default to vector.
  41. \qbk{before.synopsis,
  42. [heading Model of]
  43. [link geometry.reference.concepts.concept_polygon Polygon Concept]
  44. }
  45. */
  46. template
  47. <
  48. typename Point,
  49. bool ClockWise = true,
  50. bool Closed = true,
  51. template<typename, typename> class PointList = std::vector,
  52. template<typename, typename> class RingList = std::vector,
  53. template<typename> class PointAlloc = std::allocator,
  54. template<typename> class RingAlloc = std::allocator
  55. >
  56. class polygon
  57. {
  58. BOOST_CONCEPT_ASSERT( (concept::Point<Point>) );
  59. public:
  60. // Member types
  61. typedef Point point_type;
  62. typedef ring<Point, ClockWise, Closed, PointList, PointAlloc> ring_type;
  63. typedef RingList<ring_type , RingAlloc<ring_type > > inner_container_type;
  64. inline ring_type const& outer() const { return m_outer; }
  65. inline inner_container_type const& inners() const { return m_inners; }
  66. inline ring_type& outer() { return m_outer; }
  67. inline inner_container_type & inners() { return m_inners; }
  68. /// Utility method, clears outer and inner rings
  69. inline void clear()
  70. {
  71. m_outer.clear();
  72. m_inners.clear();
  73. }
  74. private:
  75. ring_type m_outer;
  76. inner_container_type m_inners;
  77. };
  78. } // namespace model
  79. #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  80. namespace traits
  81. {
  82. template
  83. <
  84. typename Point,
  85. bool ClockWise, bool Closed,
  86. template<typename, typename> class PointList,
  87. template<typename, typename> class RingList,
  88. template<typename> class PointAlloc,
  89. template<typename> class RingAlloc
  90. >
  91. struct tag
  92. <
  93. model::polygon
  94. <
  95. Point, ClockWise, Closed,
  96. PointList, RingList, PointAlloc, RingAlloc
  97. >
  98. >
  99. {
  100. typedef polygon_tag type;
  101. };
  102. template
  103. <
  104. typename Point,
  105. bool ClockWise, bool Closed,
  106. template<typename, typename> class PointList,
  107. template<typename, typename> class RingList,
  108. template<typename> class PointAlloc,
  109. template<typename> class RingAlloc
  110. >
  111. struct ring_const_type
  112. <
  113. model::polygon
  114. <
  115. Point, ClockWise, Closed,
  116. PointList, RingList, PointAlloc, RingAlloc
  117. >
  118. >
  119. {
  120. typedef typename model::polygon
  121. <
  122. Point, ClockWise, Closed,
  123. PointList, RingList,
  124. PointAlloc, RingAlloc
  125. >::ring_type const& type;
  126. };
  127. template
  128. <
  129. typename Point,
  130. bool ClockWise, bool Closed,
  131. template<typename, typename> class PointList,
  132. template<typename, typename> class RingList,
  133. template<typename> class PointAlloc,
  134. template<typename> class RingAlloc
  135. >
  136. struct ring_mutable_type
  137. <
  138. model::polygon
  139. <
  140. Point, ClockWise, Closed,
  141. PointList, RingList, PointAlloc, RingAlloc
  142. >
  143. >
  144. {
  145. typedef typename model::polygon
  146. <
  147. Point, ClockWise, Closed,
  148. PointList, RingList,
  149. PointAlloc, RingAlloc
  150. >::ring_type& type;
  151. };
  152. template
  153. <
  154. typename Point,
  155. bool ClockWise, bool Closed,
  156. template<typename, typename> class PointList,
  157. template<typename, typename> class RingList,
  158. template<typename> class PointAlloc,
  159. template<typename> class RingAlloc
  160. >
  161. struct interior_const_type
  162. <
  163. model::polygon
  164. <
  165. Point, ClockWise, Closed,
  166. PointList, RingList,
  167. PointAlloc, RingAlloc
  168. >
  169. >
  170. {
  171. typedef typename model::polygon
  172. <
  173. Point, ClockWise, Closed,
  174. PointList, RingList,
  175. PointAlloc, RingAlloc
  176. >::inner_container_type const& type;
  177. };
  178. template
  179. <
  180. typename Point,
  181. bool ClockWise, bool Closed,
  182. template<typename, typename> class PointList,
  183. template<typename, typename> class RingList,
  184. template<typename> class PointAlloc,
  185. template<typename> class RingAlloc
  186. >
  187. struct interior_mutable_type
  188. <
  189. model::polygon
  190. <
  191. Point, ClockWise, Closed,
  192. PointList, RingList,
  193. PointAlloc, RingAlloc
  194. >
  195. >
  196. {
  197. typedef typename model::polygon
  198. <
  199. Point, ClockWise, Closed,
  200. PointList, RingList,
  201. PointAlloc, RingAlloc
  202. >::inner_container_type& type;
  203. };
  204. template
  205. <
  206. typename Point,
  207. bool ClockWise, bool Closed,
  208. template<typename, typename> class PointList,
  209. template<typename, typename> class RingList,
  210. template<typename> class PointAlloc,
  211. template<typename> class RingAlloc
  212. >
  213. struct exterior_ring
  214. <
  215. model::polygon
  216. <
  217. Point, ClockWise, Closed,
  218. PointList, RingList, PointAlloc, RingAlloc
  219. >
  220. >
  221. {
  222. typedef model::polygon
  223. <
  224. Point, ClockWise, Closed,
  225. PointList, RingList,
  226. PointAlloc, RingAlloc
  227. > polygon_type;
  228. static inline typename polygon_type::ring_type& get(polygon_type& p)
  229. {
  230. return p.outer();
  231. }
  232. static inline typename polygon_type::ring_type const& get(
  233. polygon_type const& p)
  234. {
  235. return p.outer();
  236. }
  237. };
  238. template
  239. <
  240. typename Point,
  241. bool ClockWise, bool Closed,
  242. template<typename, typename> class PointList,
  243. template<typename, typename> class RingList,
  244. template<typename> class PointAlloc,
  245. template<typename> class RingAlloc
  246. >
  247. struct interior_rings
  248. <
  249. model::polygon
  250. <
  251. Point, ClockWise, Closed,
  252. PointList, RingList,
  253. PointAlloc, RingAlloc
  254. >
  255. >
  256. {
  257. typedef model::polygon
  258. <
  259. Point, ClockWise, Closed, PointList, RingList,
  260. PointAlloc, RingAlloc
  261. > polygon_type;
  262. static inline typename polygon_type::inner_container_type& get(
  263. polygon_type& p)
  264. {
  265. return p.inners();
  266. }
  267. static inline typename polygon_type::inner_container_type const& get(
  268. polygon_type const& p)
  269. {
  270. return p.inners();
  271. }
  272. };
  273. } // namespace traits
  274. #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
  275. }} // namespace boost::geometry
  276. #endif // BOOST_GEOMETRY_GEOMETRIES_POLYGON_HPP