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_RING_HPP
10 #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP
12 // Adapts Geometries from Boost.Polygon for usage in Boost.Geometry
13 // boost::polygon::polygon_data -> boost::geometry::ring
16 #include <boost/polygon/polygon.hpp>
18 #include <boost/geometry/core/access.hpp>
19 #include <boost/geometry/core/cs.hpp>
20 #include <boost/geometry/core/coordinate_dimension.hpp>
21 #include <boost/geometry/core/coordinate_type.hpp>
22 #include <boost/geometry/core/mutable_range.hpp>
23 #include <boost/geometry/core/tags.hpp>
26 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
28 namespace boost { namespace geometry
34 template <typename CoordinateType>
35 struct tag<boost::polygon::polygon_data<CoordinateType> >
37 typedef ring_tag type;
40 template <typename CoordinateType>
41 struct clear<boost::polygon::polygon_data<CoordinateType> >
43 static inline void apply(boost::polygon::polygon_data<CoordinateType>& data)
45 // There is no "clear" function but we can assign
46 // a newly (and therefore empty) constructed polygon
47 boost::polygon::assign(data, boost::polygon::polygon_data<CoordinateType>());
51 template <typename CoordinateType>
52 struct push_back<boost::polygon::polygon_data<CoordinateType> >
54 typedef boost::polygon::point_data<CoordinateType> point_type;
56 static inline void apply(boost::polygon::polygon_data<CoordinateType>& data,
57 point_type const& point)
59 // Boost.Polygon's polygons are not appendable. So create a temporary vector,
60 // add a record and set it to the original. Of course: this is not efficient.
61 // But there seems no other way (without using a wrapper)
62 std::vector<point_type> temporary_vector
64 boost::polygon::begin_points(data),
65 boost::polygon::end_points(data)
67 temporary_vector.push_back(point);
68 data.set(temporary_vector.begin(), temporary_vector.end());
72 template <typename CoordinateType>
73 struct resize<boost::polygon::polygon_data<CoordinateType> >
75 typedef boost::polygon::point_data<CoordinateType> point_type;
77 static inline void apply(boost::polygon::polygon_data<CoordinateType>& data,
80 // Boost.Polygon's polygons are not resizable. So create a temporary vector,
81 // resize it and set it to the original. Of course: this is not efficient.
82 // But there seems no other way (without using a wrapper)
83 std::vector<point_type> temporary_vector
85 boost::polygon::begin_points(data),
86 boost::polygon::end_points(data)
88 temporary_vector.resize(new_size);
89 data.set(temporary_vector.begin(), temporary_vector.end());
96 }} // namespace boost::geometry
99 // Adapt Boost.Polygon's polygon_data to Boost.Range
100 // This just translates to
101 // polygon_data.begin() and polygon_data.end()
104 template<typename CoordinateType>
105 struct range_mutable_iterator<boost::polygon::polygon_data<CoordinateType> >
107 typedef typename boost::polygon::polygon_traits
109 boost::polygon::polygon_data<CoordinateType>
110 >::iterator_type type;
113 template<typename CoordinateType>
114 struct range_const_iterator<boost::polygon::polygon_data<CoordinateType> >
116 typedef typename boost::polygon::polygon_traits
118 boost::polygon::polygon_data<CoordinateType>
119 >::iterator_type type;
122 template<typename CoordinateType>
123 struct range_size<boost::polygon::polygon_data<CoordinateType> >
125 typedef std::size_t type;
131 // Support Boost.Polygon's polygon_data for Boost.Range ADP
132 namespace boost { namespace polygon
135 template<typename CoordinateType>
136 inline typename polygon_traits
138 polygon_data<CoordinateType>
139 >::iterator_type range_begin(polygon_data<CoordinateType>& polygon)
141 return polygon.begin();
144 template<typename CoordinateType>
145 inline typename polygon_traits
147 polygon_data<CoordinateType>
148 >::iterator_type range_begin(polygon_data<CoordinateType> const& polygon)
150 return polygon.begin();
153 template<typename CoordinateType>
154 inline typename polygon_traits
156 polygon_data<CoordinateType>
157 >::iterator_type range_end(polygon_data<CoordinateType>& polygon)
159 return polygon.end();
162 template<typename CoordinateType>
163 inline typename polygon_traits
165 polygon_data<CoordinateType>
166 >::iterator_type range_end(polygon_data<CoordinateType> const& polygon)
168 return polygon.end();
171 template<typename CoordinateType>
172 inline std::size_t range_calculate_size(polygon_data<CoordinateType> const& polygon)
174 return polygon.size();
179 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
182 #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_RING_HPP