Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:26

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2010-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 
0005 // This file was modified by Oracle on 2020.
0006 // Modifications copyright (c) 2020, Oracle and/or its affiliates.
0007 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0008 
0009 // Use, modification and distribution is subject to the Boost Software License,
0010 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0011 // http://www.boost.org/LICENSE_1_0.txt)
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 // Adapts Geometries from Boost.Polygon for usage in Boost.Geometry
0017 // boost::polygon::polygon_with_holes_data -> boost::geometry::polygon
0018 //   pair{begin_holes, begin_holes} -> interior_proxy
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 // Polygon should implement the boost::polygon::polygon_with_holes_concept
0034 // Specify constness in the template parameter if necessary
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     // The next line does not work probably because coordinate_type is part of the
0050     // polygon_traits, but not of the polygon_with_holes_traits
0051     // typedef typename boost::polygon::polygon_traits<Polygon>::coordinate_type coordinate_type;
0052 
0053     // So we use:
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         // Clear the holes
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 // Support holes_proxy for Boost.Range ADP
0102 
0103 // Const versions
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 // Mutable versions
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 } // namespace traits
0185 
0186 
0187 }}
0188 
0189 
0190 // Specialize holes_proxy for Boost.Range
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 } // namespace boost
0206 
0207 
0208 #endif // BOOST_GEOMETRY_GEOMETRIES_ADAPTED_BOOST_POLYGON_HOLES_PROXY_HPP