1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
6 // Copyright (c) 2014 Adam Wulkiewicz, Lodz, Poland.
8 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
9 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
11 // Use, modification and distribution is subject to the Boost Software License,
12 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
13 // http://www.boost.org/LICENSE_1_0.txt)
15 #ifndef BOOST_GEOMETRY_GEOMETRIES_POLYGON_HPP
16 #define BOOST_GEOMETRY_GEOMETRIES_POLYGON_HPP
21 #include <boost/concept/assert.hpp>
23 #include <boost/geometry/core/exterior_ring.hpp>
24 #include <boost/geometry/core/interior_rings.hpp>
25 #include <boost/geometry/core/point_type.hpp>
26 #include <boost/geometry/core/ring_type.hpp>
27 #include <boost/geometry/geometries/concepts/point_concept.hpp>
28 #include <boost/geometry/geometries/ring.hpp>
30 #include <boost/config.hpp>
31 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
32 #include <initializer_list>
35 namespace boost { namespace geometry
42 \brief The polygon contains an outer ring and zero or more inner rings.
44 \tparam Point point type
45 \tparam ClockWise true for clockwise direction,
46 false for CounterClockWise direction
47 \tparam Closed true for closed polygons (last point == first point),
49 \tparam PointList container type for points,
50 for example std::vector, std::list, std::deque
51 \tparam RingList container type for inner rings,
52 for example std::vector, std::list, std::deque
53 \tparam PointAlloc container-allocator-type, for the points
54 \tparam RingAlloc container-allocator-type, for the rings
55 \note The container collecting the points in the rings can be different
56 from the container collecting the inner rings. They all default to vector.
58 \qbk{[include reference/geometries/polygon.qbk]}
61 [link geometry.reference.concepts.concept_polygon Polygon Concept]
69 bool ClockWise = true,
71 template<typename, typename> class PointList = std::vector,
72 template<typename, typename> class RingList = std::vector,
73 template<typename> class PointAlloc = std::allocator,
74 template<typename> class RingAlloc = std::allocator
78 BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
83 typedef Point point_type;
84 typedef ring<Point, ClockWise, Closed, PointList, PointAlloc> ring_type;
85 typedef RingList<ring_type , RingAlloc<ring_type > > inner_container_type;
87 inline ring_type const& outer() const { return m_outer; }
88 inline inner_container_type const& inners() const { return m_inners; }
90 inline ring_type& outer() { return m_outer; }
91 inline inner_container_type & inners() { return m_inners; }
93 #ifndef BOOST_NO_CXX11_HDR_INITIALIZER_LIST
95 // default constructor definition is required only
96 // if the constructor taking std::initializer_list is defined
98 /// \constructor_default{polygon}
104 /// \constructor_initializer_list{polygon}
105 inline polygon(std::initializer_list<ring_type> l)
106 : m_outer(l.size() > 0 ? *l.begin() : ring_type())
107 , m_inners(l.size() > 0 ? l.begin() + 1 : l.begin(), l.end())
110 // Commented out for now in order to support Boost.Assign
111 // Without this assignment operator first the object should be created
112 // from initializer list, then it shoudl be moved.
113 //// Without this workaround in MSVC the assignment operator is ambiguous
115 // /// \assignment_initializer_list{polygon}
116 // inline polygon & operator=(std::initializer_list<ring_type> l)
118 // if ( l.size() > 0 )
120 // m_outer = *l.begin();
121 // m_inners.assign(l.begin() + 1, l.end());
134 /// Utility method, clears outer and inner rings
144 inner_container_type m_inners;
151 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
158 bool ClockWise, bool Closed,
159 template<typename, typename> class PointList,
160 template<typename, typename> class RingList,
161 template<typename> class PointAlloc,
162 template<typename> class RingAlloc
168 Point, ClockWise, Closed,
169 PointList, RingList, PointAlloc, RingAlloc
173 typedef polygon_tag type;
179 bool ClockWise, bool Closed,
180 template<typename, typename> class PointList,
181 template<typename, typename> class RingList,
182 template<typename> class PointAlloc,
183 template<typename> class RingAlloc
185 struct ring_const_type
189 Point, ClockWise, Closed,
190 PointList, RingList, PointAlloc, RingAlloc
194 typedef typename model::polygon
196 Point, ClockWise, Closed,
198 PointAlloc, RingAlloc
199 >::ring_type const& type;
206 bool ClockWise, bool Closed,
207 template<typename, typename> class PointList,
208 template<typename, typename> class RingList,
209 template<typename> class PointAlloc,
210 template<typename> class RingAlloc
212 struct ring_mutable_type
216 Point, ClockWise, Closed,
217 PointList, RingList, PointAlloc, RingAlloc
221 typedef typename model::polygon
223 Point, ClockWise, Closed,
225 PointAlloc, RingAlloc
232 bool ClockWise, bool Closed,
233 template<typename, typename> class PointList,
234 template<typename, typename> class RingList,
235 template<typename> class PointAlloc,
236 template<typename> class RingAlloc
238 struct interior_const_type
242 Point, ClockWise, Closed,
244 PointAlloc, RingAlloc
248 typedef typename model::polygon
250 Point, ClockWise, Closed,
252 PointAlloc, RingAlloc
253 >::inner_container_type const& type;
260 bool ClockWise, bool Closed,
261 template<typename, typename> class PointList,
262 template<typename, typename> class RingList,
263 template<typename> class PointAlloc,
264 template<typename> class RingAlloc
266 struct interior_mutable_type
270 Point, ClockWise, Closed,
272 PointAlloc, RingAlloc
276 typedef typename model::polygon
278 Point, ClockWise, Closed,
280 PointAlloc, RingAlloc
281 >::inner_container_type& type;
288 bool ClockWise, bool Closed,
289 template<typename, typename> class PointList,
290 template<typename, typename> class RingList,
291 template<typename> class PointAlloc,
292 template<typename> class RingAlloc
298 Point, ClockWise, Closed,
299 PointList, RingList, PointAlloc, RingAlloc
303 typedef model::polygon
305 Point, ClockWise, Closed,
307 PointAlloc, RingAlloc
310 static inline typename polygon_type::ring_type& get(polygon_type& p)
315 static inline typename polygon_type::ring_type const& get(
316 polygon_type const& p)
325 bool ClockWise, bool Closed,
326 template<typename, typename> class PointList,
327 template<typename, typename> class RingList,
328 template<typename> class PointAlloc,
329 template<typename> class RingAlloc
331 struct interior_rings
335 Point, ClockWise, Closed,
337 PointAlloc, RingAlloc
341 typedef model::polygon
343 Point, ClockWise, Closed, PointList, RingList,
344 PointAlloc, RingAlloc
347 static inline typename polygon_type::inner_container_type& get(
353 static inline typename polygon_type::inner_container_type const& get(
354 polygon_type const& p)
360 } // namespace traits
361 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
365 }} // namespace boost::geometry
367 #endif // BOOST_GEOMETRY_GEOMETRIES_POLYGON_HPP