Back to home page

EIC code displayed by LXR

 
 

    


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

0001 // Boost.Geometry (aka GGL, Generic Geometry Library)
0002 
0003 // Copyright (c) 2014-2021, Oracle and/or its affiliates.
0004 
0005 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
0006 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0007 
0008 // Licensed under the Boost Software License version 1.0.
0009 // http://www.boost.org/users/license.html
0010 
0011 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_AREAL_HPP
0012 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_AREAL_HPP
0013 
0014 #include <boost/range/begin.hpp>
0015 #include <boost/range/empty.hpp>
0016 #include <boost/range/end.hpp>
0017 #include <boost/range/value_type.hpp>
0018 
0019 #include <boost/geometry/core/closure.hpp>
0020 #include <boost/geometry/core/exterior_ring.hpp>
0021 #include <boost/geometry/core/interior_rings.hpp>
0022 #include <boost/geometry/core/ring_type.hpp>
0023 #include <boost/geometry/core/tags.hpp>
0024 
0025 #include <boost/geometry/algorithms/detail/is_simple/failure_policy.hpp>
0026 #include <boost/geometry/algorithms/detail/is_valid/has_duplicates.hpp>
0027 
0028 #include <boost/geometry/algorithms/dispatch/is_simple.hpp>
0029 
0030 
0031 namespace boost { namespace geometry
0032 {
0033 
0034 
0035 #ifndef DOXYGEN_NO_DETAIL
0036 namespace detail { namespace is_simple
0037 {
0038 
0039 
0040 template <typename Ring, typename Strategy>
0041 inline bool is_simple_ring(Ring const& ring, Strategy const& strategy)
0042 {
0043     simplicity_failure_policy policy;
0044     return ! boost::empty(ring)
0045         && ! detail::is_valid::has_duplicates<Ring>::apply(ring, policy, strategy);
0046 }
0047 
0048 template <typename InteriorRings, typename Strategy>
0049 inline bool are_simple_interior_rings(InteriorRings const& interior_rings,
0050                                       Strategy const& strategy)
0051 {
0052     return std::all_of(boost::begin(interior_rings),
0053                        boost::end(interior_rings),
0054                        [&](auto const& r)
0055                        {
0056                            return is_simple_ring(r, strategy);
0057                        }); // non-simple ring not found
0058     // allow empty ring
0059 }
0060 
0061 template <typename Polygon, typename Strategy>
0062 inline bool is_simple_polygon(Polygon const& polygon, Strategy const& strategy)
0063 {
0064     return is_simple_ring(geometry::exterior_ring(polygon), strategy)
0065         && are_simple_interior_rings(geometry::interior_rings(polygon), strategy);
0066 }
0067 
0068 
0069 }} // namespace detail::is_simple
0070 #endif // DOXYGEN_NO_DETAIL
0071 
0072 
0073 
0074 
0075 #ifndef DOXYGEN_NO_DISPATCH
0076 namespace dispatch
0077 {
0078 
0079 
0080 // A Ring is a Polygon.
0081 // A Polygon is always a simple geometric object provided that it is valid.
0082 //
0083 // Reference (for polygon validity): OGC 06-103r4 (6.1.11.1)
0084 template <typename Ring>
0085 struct is_simple<Ring, ring_tag>
0086 {
0087     template <typename Strategy>
0088     static inline bool apply(Ring const& ring, Strategy const& strategy)
0089     {
0090         return detail::is_simple::is_simple_ring(ring, strategy);
0091     }
0092 };
0093 
0094 
0095 // A Polygon is always a simple geometric object provided that it is valid.
0096 //
0097 // Reference (for validity of Polygons): OGC 06-103r4 (6.1.11.1)
0098 template <typename Polygon>
0099 struct is_simple<Polygon, polygon_tag>
0100 {
0101     template <typename Strategy>
0102     static inline bool apply(Polygon const& polygon, Strategy const& strategy)
0103     {
0104         return detail::is_simple::is_simple_polygon(polygon, strategy);
0105     }
0106 };
0107 
0108 
0109 // Not clear what the definition is.
0110 // Right now we consider a MultiPolygon as simple if it is valid.
0111 //
0112 // Reference (for validity of MultiPolygons): OGC 06-103r4 (6.1.14)
0113 template <typename MultiPolygon>
0114 struct is_simple<MultiPolygon, multi_polygon_tag>
0115 {
0116     template <typename Strategy>
0117     static inline bool apply(MultiPolygon const& multipolygon, Strategy const& strategy)
0118     {
0119         return std::none_of(boost::begin(multipolygon), boost::end(multipolygon),
0120                             [&](auto const& po) {
0121                                 return ! detail::is_simple::is_simple_polygon(po, strategy);
0122                             }); // non-simple polygon not found
0123                                 // allow empty multi-polygon
0124     }
0125 };
0126 
0127 
0128 } // namespace dispatch
0129 #endif // DOXYGEN_NO_DISPATCH
0130 
0131 
0132 }} // namespace boost::geometry
0133 
0134 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_AREAL_HPP