1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
5 // Use, modification and distribution is subject to the Boost Software License,
6 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
9 #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_HOLES_PROXY_HPP
10 #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_HOLES_PROXY_HPP
12 // Adapts Geometries from Boost.Polygon for usage in Boost.Geometry
13 // boost::polygon::polygon_with_holes_data -> boost::geometry::polygon
14 // pair{begin_holes, begin_holes} -> interior_proxy
16 #include <boost/polygon/polygon.hpp>
18 #include <boost/geometry/geometries/adapted/boost_polygon/hole_iterator.hpp>
19 #include <boost/geometry/geometries/adapted/boost_polygon/ring_proxy.hpp>
22 namespace boost { namespace geometry
25 namespace adapt { namespace bp
29 // Polygon should implement the boost::polygon::polygon_with_holes_concept
30 // Specify constness in the template parameter if necessary
31 template<typename Polygon>
36 typename boost::mpl::if_
38 typename boost::is_const<Polygon>,
43 typedef hole_iterator<Polygon, proxy_type> iterator_type;
45 // The next line does not work probably because coordinate_type is part of the
46 // polygon_traits, but not of the polygon_with_holes_traits
47 // typedef typename boost::polygon::polygon_traits<Polygon>::coordinate_type coordinate_type;
50 typedef typename Polygon::coordinate_type coordinate_type;
52 inline holes_proxy(Polygon& p)
62 boost::polygon::begin_holes(empty),
63 boost::polygon::end_holes(empty)
67 inline void resize(std::size_t new_size)
69 std::vector<boost::polygon::polygon_data<coordinate_type> > temporary_copy
71 boost::polygon::begin_holes(polygon),
72 boost::polygon::end_holes(polygon)
74 temporary_copy.resize(new_size);
75 polygon.set_holes(temporary_copy.begin(), temporary_copy.end());
78 template <typename Ring>
79 inline void push_back(Ring const& ring)
81 std::vector<boost::polygon::polygon_data<coordinate_type> > temporary_copy
83 boost::polygon::begin_holes(polygon),
84 boost::polygon::end_holes(polygon)
86 boost::polygon::polygon_data<coordinate_type> added;
87 boost::polygon::set_points(added, ring.begin(), ring.end());
88 temporary_copy.push_back(added);
89 polygon.set_holes(temporary_copy.begin(), temporary_copy.end());
97 // Support holes_proxy for Boost.Range ADP
100 template<typename Polygon>
101 inline typename boost::geometry::adapt::bp::holes_proxy<Polygon const>::iterator_type
102 range_begin(boost::geometry::adapt::bp::holes_proxy<Polygon const> const& proxy)
104 typename boost::geometry::adapt::bp::holes_proxy<Polygon const>::iterator_type
105 begin(proxy.polygon, boost::polygon::begin_holes(proxy.polygon));
109 template<typename Polygon>
110 inline typename boost::geometry::adapt::bp::holes_proxy<Polygon const>::iterator_type
111 range_end(boost::geometry::adapt::bp::holes_proxy<Polygon const> const& proxy)
113 typename boost::geometry::adapt::bp::holes_proxy<Polygon const>::iterator_type
114 end(proxy.polygon, boost::polygon::end_holes(proxy.polygon));
119 template<typename Polygon>
120 inline typename boost::geometry::adapt::bp::holes_proxy<Polygon>::iterator_type
121 range_begin(boost::geometry::adapt::bp::holes_proxy<Polygon>& proxy)
123 typename boost::geometry::adapt::bp::holes_proxy<Polygon>::iterator_type
124 begin(proxy.polygon, boost::polygon::begin_holes(proxy.polygon));
128 template<typename Polygon>
129 inline typename boost::geometry::adapt::bp::holes_proxy<Polygon>::iterator_type
130 range_end(boost::geometry::adapt::bp::holes_proxy<Polygon>& proxy)
132 typename boost::geometry::adapt::bp::holes_proxy<Polygon>::iterator_type
133 end(proxy.polygon, boost::polygon::end_holes(proxy.polygon));
143 template <typename Polygon>
144 struct rvalue_type<adapt::bp::holes_proxy<Polygon> >
146 typedef adapt::bp::holes_proxy<Polygon> type;
150 template <typename Polygon>
151 struct clear<adapt::bp::holes_proxy<Polygon> >
153 static inline void apply(adapt::bp::holes_proxy<Polygon> proxy)
159 template <typename Polygon>
160 struct resize<adapt::bp::holes_proxy<Polygon> >
162 static inline void apply(adapt::bp::holes_proxy<Polygon> proxy, std::size_t new_size)
164 proxy.resize(new_size);
168 template <typename Polygon>
169 struct push_back<adapt::bp::holes_proxy<Polygon> >
171 template <typename Ring>
172 static inline void apply(adapt::bp::holes_proxy<Polygon> proxy, Ring const& ring)
174 proxy.push_back(ring);
180 } // namespace traits
186 // Specialize holes_proxy for Boost.Range
189 template<typename Polygon>
190 struct range_mutable_iterator<geometry::adapt::bp::holes_proxy<Polygon> >
192 typedef typename geometry::adapt::bp::holes_proxy<Polygon>::iterator_type type;
195 template<typename Polygon>
196 struct range_const_iterator<geometry::adapt::bp::holes_proxy<Polygon> >
198 typedef typename geometry::adapt::bp::holes_proxy<Polygon const>::iterator_type type;
204 #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_HOLES_PROXY_HPP