Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
0004 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
0005 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
0006 // Copyright (c) 2014-2018 Adam Wulkiewicz, Lodz, Poland.
0007 
0008 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
0009 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
0010 
0011 // Use, modification and distribution is subject to the Boost Software License,
0012 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0013 // http://www.boost.org/LICENSE_1_0.txt)
0014 
0015 #ifndef BOOST_GEOMETRY_GEOMETRIES_POLYGON_HPP
0016 #define BOOST_GEOMETRY_GEOMETRIES_POLYGON_HPP
0017 
0018 #include <memory>
0019 #include <vector>
0020 
0021 #include <boost/concept/assert.hpp>
0022 
0023 #include <boost/geometry/core/exterior_ring.hpp>
0024 #include <boost/geometry/core/interior_rings.hpp>
0025 #include <boost/geometry/core/point_type.hpp>
0026 #include <boost/geometry/core/ring_type.hpp>
0027 #include <boost/geometry/geometries/concepts/point_concept.hpp>
0028 #include <boost/geometry/geometries/ring.hpp>
0029 
0030 #include <boost/config.hpp>
0031 
0032 #include <initializer_list>
0033 
0034 
0035 namespace boost { namespace geometry
0036 {
0037 
0038 namespace model
0039 {
0040 
0041 /*!
0042 \brief The polygon contains an outer ring and zero or more inner rings.
0043 \ingroup geometries
0044 \tparam Point point type
0045 \tparam ClockWise true for clockwise direction,
0046             false for CounterClockWise direction
0047 \tparam Closed true for closed polygons (last point == first point),
0048             false open points
0049 \tparam PointList container type for points,
0050             for example std::vector, std::deque
0051 \tparam RingList container type for inner rings,
0052             for example std::vector, std::deque
0053 \tparam PointAlloc container-allocator-type, for the points
0054 \tparam RingAlloc container-allocator-type, for the rings
0055 \note The container collecting the points in the rings can be different
0056     from the container collecting the inner rings. They all default to vector.
0057 
0058 \qbk{[include reference/geometries/polygon.qbk]}
0059 \qbk{before.synopsis,
0060 [heading Model of]
0061 [link geometry.reference.concepts.concept_polygon Polygon Concept]
0062 }
0063 
0064 
0065 */
0066 template
0067 <
0068     typename Point,
0069     bool ClockWise = true,
0070     bool Closed = true,
0071     template<typename, typename> class PointList = std::vector,
0072     template<typename, typename> class RingList = std::vector,
0073     template<typename> class PointAlloc = std::allocator,
0074     template<typename> class RingAlloc = std::allocator
0075 >
0076 class polygon
0077 {
0078     BOOST_CONCEPT_ASSERT( (concepts::Point<Point>) );
0079 
0080 public:
0081 
0082     // Member types
0083     typedef Point point_type;
0084     typedef ring<Point, ClockWise, Closed, PointList, PointAlloc> ring_type;
0085     typedef RingList<ring_type , RingAlloc<ring_type > > inner_container_type;
0086 
0087     inline ring_type const& outer() const { return m_outer; }
0088     inline inner_container_type const& inners() const { return m_inners; }
0089 
0090     inline ring_type& outer() { return m_outer; }
0091     inline inner_container_type & inners() { return m_inners; }
0092 
0093     // default constructor definition is required only
0094     // if the constructor taking std::initializer_list is defined
0095 
0096     /// \constructor_default{polygon}
0097     inline polygon()
0098         : m_outer()
0099         , m_inners()
0100     {}
0101 
0102     /// \constructor_initializer_list{polygon}
0103     inline polygon(std::initializer_list<ring_type> l)
0104         : m_outer(l.size() > 0 ? *l.begin() : ring_type())
0105         , m_inners(l.size() > 0 ? l.begin() + 1 : l.begin(), l.end())
0106     {}
0107 
0108 // Commented out for now in order to support Boost.Assign
0109 // Without this assignment operator first the object should be created
0110 //   from initializer list, then it shoudl be moved.
0111 //// Without this workaround in MSVC the assignment operator is ambiguous
0112 //#ifndef BOOST_MSVC
0113 //    /// \assignment_initializer_list{polygon}
0114 //    inline polygon & operator=(std::initializer_list<ring_type> l)
0115 //    {
0116 //        if ( l.size() > 0 )
0117 //        {
0118 //            m_outer = *l.begin();
0119 //            m_inners.assign(l.begin() + 1, l.end());
0120 //        }
0121 //        else
0122 //        {
0123 //            m_outer.clear();
0124 //            m_inners.clear();
0125 //        }
0126 //        return *this;
0127 //    }
0128 //#endif
0129 
0130     /// Utility method, clears outer and inner rings
0131     inline void clear()
0132     {
0133         m_outer.clear();
0134         m_inners.clear();
0135     }
0136 
0137 private:
0138 
0139     ring_type m_outer;
0140     inner_container_type m_inners;
0141 };
0142 
0143 
0144 } // namespace model
0145 
0146 
0147 #ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
0148 namespace traits
0149 {
0150 
0151 template
0152 <
0153     typename Point,
0154     bool ClockWise, bool Closed,
0155     template<typename, typename> class PointList,
0156     template<typename, typename> class RingList,
0157     template<typename> class PointAlloc,
0158     template<typename> class RingAlloc
0159 >
0160 struct tag
0161 <
0162     model::polygon
0163         <
0164             Point, ClockWise, Closed,
0165             PointList, RingList, PointAlloc, RingAlloc
0166         >
0167 >
0168 {
0169     typedef polygon_tag type;
0170 };
0171 
0172 template
0173 <
0174     typename Point,
0175     bool ClockWise, bool Closed,
0176     template<typename, typename> class PointList,
0177     template<typename, typename> class RingList,
0178     template<typename> class PointAlloc,
0179     template<typename> class RingAlloc
0180 >
0181 struct ring_const_type
0182 <
0183     model::polygon
0184         <
0185             Point, ClockWise, Closed,
0186             PointList, RingList, PointAlloc, RingAlloc
0187         >
0188 >
0189 {
0190     typedef typename model::polygon
0191         <
0192             Point, ClockWise, Closed,
0193             PointList, RingList,
0194             PointAlloc, RingAlloc
0195         >::ring_type const& type;
0196 };
0197 
0198 
0199 template
0200 <
0201     typename Point,
0202     bool ClockWise, bool Closed,
0203     template<typename, typename> class PointList,
0204     template<typename, typename> class RingList,
0205     template<typename> class PointAlloc,
0206     template<typename> class RingAlloc
0207 >
0208 struct ring_mutable_type
0209 <
0210     model::polygon
0211         <
0212             Point, ClockWise, Closed,
0213             PointList, RingList, PointAlloc, RingAlloc
0214         >
0215 >
0216 {
0217     typedef typename model::polygon
0218         <
0219             Point, ClockWise, Closed,
0220             PointList, RingList,
0221             PointAlloc, RingAlloc
0222         >::ring_type& type;
0223 };
0224 
0225 template
0226 <
0227     typename Point,
0228     bool ClockWise, bool Closed,
0229     template<typename, typename> class PointList,
0230     template<typename, typename> class RingList,
0231     template<typename> class PointAlloc,
0232     template<typename> class RingAlloc
0233 >
0234 struct interior_const_type
0235 <
0236     model::polygon
0237         <
0238             Point, ClockWise, Closed,
0239             PointList, RingList,
0240             PointAlloc, RingAlloc
0241         >
0242 >
0243 {
0244     typedef typename model::polygon
0245         <
0246             Point, ClockWise, Closed,
0247             PointList, RingList,
0248             PointAlloc, RingAlloc
0249         >::inner_container_type const& type;
0250 };
0251 
0252 
0253 template
0254 <
0255     typename Point,
0256     bool ClockWise, bool Closed,
0257     template<typename, typename> class PointList,
0258     template<typename, typename> class RingList,
0259     template<typename> class PointAlloc,
0260     template<typename> class RingAlloc
0261 >
0262 struct interior_mutable_type
0263 <
0264     model::polygon
0265         <
0266             Point, ClockWise, Closed,
0267             PointList, RingList,
0268             PointAlloc, RingAlloc
0269         >
0270 >
0271 {
0272     typedef typename model::polygon
0273         <
0274             Point, ClockWise, Closed,
0275             PointList, RingList,
0276             PointAlloc, RingAlloc
0277         >::inner_container_type& type;
0278 };
0279 
0280 
0281 template
0282 <
0283     typename Point,
0284     bool ClockWise, bool Closed,
0285     template<typename, typename> class PointList,
0286     template<typename, typename> class RingList,
0287     template<typename> class PointAlloc,
0288     template<typename> class RingAlloc
0289 >
0290 struct exterior_ring
0291 <
0292     model::polygon
0293         <
0294             Point, ClockWise, Closed,
0295             PointList, RingList, PointAlloc, RingAlloc
0296         >
0297 >
0298 {
0299     typedef model::polygon
0300         <
0301             Point, ClockWise, Closed,
0302             PointList, RingList,
0303             PointAlloc, RingAlloc
0304         > polygon_type;
0305 
0306     static inline typename polygon_type::ring_type& get(polygon_type& p)
0307     {
0308         return p.outer();
0309     }
0310 
0311     static inline typename polygon_type::ring_type const& get(
0312                     polygon_type const& p)
0313     {
0314         return p.outer();
0315     }
0316 };
0317 
0318 template
0319 <
0320     typename Point,
0321     bool ClockWise, bool Closed,
0322     template<typename, typename> class PointList,
0323     template<typename, typename> class RingList,
0324     template<typename> class PointAlloc,
0325     template<typename> class RingAlloc
0326 >
0327 struct interior_rings
0328 <
0329     model::polygon
0330         <
0331             Point, ClockWise, Closed,
0332             PointList, RingList,
0333             PointAlloc, RingAlloc
0334         >
0335 >
0336 {
0337     typedef model::polygon
0338         <
0339             Point, ClockWise, Closed, PointList, RingList,
0340             PointAlloc, RingAlloc
0341         > polygon_type;
0342 
0343     static inline typename polygon_type::inner_container_type& get(
0344                     polygon_type& p)
0345     {
0346         return p.inners();
0347     }
0348 
0349     static inline typename polygon_type::inner_container_type const& get(
0350                     polygon_type const& p)
0351     {
0352         return p.inners();
0353     }
0354 };
0355 
0356 } // namespace traits
0357 #endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS
0358 
0359 
0360 
0361 }} // namespace boost::geometry
0362 
0363 #endif // BOOST_GEOMETRY_GEOMETRIES_POLYGON_HPP