File indexing completed on 2025-01-18 09:35:26
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_HOLES_PROXY_HPP
0014 #define BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_HOLES_PROXY_HPP
0015
0016
0017
0018
0019
0020 #include <boost/polygon/polygon.hpp>
0021
0022 #include <boost/geometry/geometries/adapted/boost_polygon/hole_iterator.hpp>
0023 #include <boost/geometry/geometries/adapted/boost_polygon/ring_proxy.hpp>
0024
0025
0026 namespace boost { namespace geometry
0027 {
0028
0029 namespace adapt { namespace bp
0030 {
0031
0032
0033
0034
0035 template<typename Polygon>
0036 struct holes_proxy
0037 {
0038 typedef ring_proxy
0039 <
0040 std::conditional_t
0041 <
0042 std::is_const<Polygon>::value,
0043 Polygon const,
0044 Polygon
0045 >
0046 > proxy_type;
0047 typedef hole_iterator<Polygon, proxy_type> iterator_type;
0048
0049
0050
0051
0052
0053
0054 typedef typename Polygon::coordinate_type coordinate_type;
0055
0056 inline holes_proxy(Polygon& p)
0057 : polygon(p)
0058 {}
0059
0060 inline void clear()
0061 {
0062 Polygon empty;
0063
0064 polygon.set_holes
0065 (
0066 boost::polygon::begin_holes(empty),
0067 boost::polygon::end_holes(empty)
0068 );
0069 }
0070
0071 inline void resize(std::size_t new_size)
0072 {
0073 std::vector<boost::polygon::polygon_data<coordinate_type> > temporary_copy
0074 (
0075 boost::polygon::begin_holes(polygon),
0076 boost::polygon::end_holes(polygon)
0077 );
0078 temporary_copy.resize(new_size);
0079 polygon.set_holes(temporary_copy.begin(), temporary_copy.end());
0080 }
0081
0082 template <typename Ring>
0083 inline void push_back(Ring const& ring)
0084 {
0085 std::vector<boost::polygon::polygon_data<coordinate_type> > temporary_copy
0086 (
0087 boost::polygon::begin_holes(polygon),
0088 boost::polygon::end_holes(polygon)
0089 );
0090 boost::polygon::polygon_data<coordinate_type> added;
0091 boost::polygon::set_points(added, ring.begin(), ring.end());
0092 temporary_copy.push_back(added);
0093 polygon.set_holes(temporary_copy.begin(), temporary_copy.end());
0094 }
0095
0096
0097 Polygon& polygon;
0098 };
0099
0100
0101
0102
0103
0104 template<typename Polygon>
0105 inline typename boost::geometry::adapt::bp::holes_proxy<Polygon const>::iterator_type
0106 range_begin(boost::geometry::adapt::bp::holes_proxy<Polygon const> const& proxy)
0107 {
0108 typename boost::geometry::adapt::bp::holes_proxy<Polygon const>::iterator_type
0109 begin(proxy.polygon, boost::polygon::begin_holes(proxy.polygon));
0110 return begin;
0111 }
0112
0113 template<typename Polygon>
0114 inline typename boost::geometry::adapt::bp::holes_proxy<Polygon const>::iterator_type
0115 range_end(boost::geometry::adapt::bp::holes_proxy<Polygon const> const& proxy)
0116 {
0117 typename boost::geometry::adapt::bp::holes_proxy<Polygon const>::iterator_type
0118 end(proxy.polygon, boost::polygon::end_holes(proxy.polygon));
0119 return end;
0120 }
0121
0122
0123 template<typename Polygon>
0124 inline typename boost::geometry::adapt::bp::holes_proxy<Polygon>::iterator_type
0125 range_begin(boost::geometry::adapt::bp::holes_proxy<Polygon>& proxy)
0126 {
0127 typename boost::geometry::adapt::bp::holes_proxy<Polygon>::iterator_type
0128 begin(proxy.polygon, boost::polygon::begin_holes(proxy.polygon));
0129 return begin;
0130 }
0131
0132 template<typename Polygon>
0133 inline typename boost::geometry::adapt::bp::holes_proxy<Polygon>::iterator_type
0134 range_end(boost::geometry::adapt::bp::holes_proxy<Polygon>& proxy)
0135 {
0136 typename boost::geometry::adapt::bp::holes_proxy<Polygon>::iterator_type
0137 end(proxy.polygon, boost::polygon::end_holes(proxy.polygon));
0138 return end;
0139 }
0140
0141
0142 }}
0143
0144 namespace traits
0145 {
0146
0147 template <typename Polygon>
0148 struct rvalue_type<adapt::bp::holes_proxy<Polygon> >
0149 {
0150 typedef adapt::bp::holes_proxy<Polygon> type;
0151 };
0152
0153
0154 template <typename Polygon>
0155 struct clear<adapt::bp::holes_proxy<Polygon> >
0156 {
0157 static inline void apply(adapt::bp::holes_proxy<Polygon> proxy)
0158 {
0159 proxy.clear();
0160 }
0161 };
0162
0163 template <typename Polygon>
0164 struct resize<adapt::bp::holes_proxy<Polygon> >
0165 {
0166 static inline void apply(adapt::bp::holes_proxy<Polygon> proxy, std::size_t new_size)
0167 {
0168 proxy.resize(new_size);
0169 }
0170 };
0171
0172 template <typename Polygon>
0173 struct push_back<adapt::bp::holes_proxy<Polygon> >
0174 {
0175 template <typename Ring>
0176 static inline void apply(adapt::bp::holes_proxy<Polygon> proxy, Ring const& ring)
0177 {
0178 proxy.push_back(ring);
0179 }
0180 };
0181
0182
0183
0184 }
0185
0186
0187 }}
0188
0189
0190
0191 namespace boost
0192 {
0193 template<typename Polygon>
0194 struct range_mutable_iterator<geometry::adapt::bp::holes_proxy<Polygon> >
0195 {
0196 typedef typename geometry::adapt::bp::holes_proxy<Polygon>::iterator_type type;
0197 };
0198
0199 template<typename Polygon>
0200 struct range_const_iterator<geometry::adapt::bp::holes_proxy<Polygon> >
0201 {
0202 typedef typename geometry::adapt::bp::holes_proxy<Polygon const>::iterator_type type;
0203 };
0204
0205 }
0206
0207
0208 #endif