1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2014-2017, Oracle and/or its affiliates.
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
11 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_AREAL_HPP
12 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_AREAL_HPP
14 #include <boost/range.hpp>
16 #include <boost/geometry/core/closure.hpp>
17 #include <boost/geometry/core/exterior_ring.hpp>
18 #include <boost/geometry/core/interior_rings.hpp>
19 #include <boost/geometry/core/ring_type.hpp>
20 #include <boost/geometry/core/tags.hpp>
22 #include <boost/geometry/algorithms/detail/check_iterator_range.hpp>
23 #include <boost/geometry/algorithms/detail/is_simple/failure_policy.hpp>
24 #include <boost/geometry/algorithms/detail/is_valid/has_duplicates.hpp>
26 #include <boost/geometry/algorithms/dispatch/is_simple.hpp>
29 namespace boost { namespace geometry
33 #ifndef DOXYGEN_NO_DETAIL
34 namespace detail { namespace is_simple
38 template <typename Ring>
41 template <typename Strategy>
42 static inline bool apply(Ring const& ring, Strategy const&)
47 static inline bool apply(Ring const& ring)
49 simplicity_failure_policy policy;
50 return ! boost::empty(ring)
51 && ! detail::is_valid::has_duplicates
53 Ring, geometry::closure<Ring>::value
54 >::apply(ring, policy);
59 template <typename Polygon>
60 class is_simple_polygon
63 template <typename InteriorRings>
65 bool are_simple_interior_rings(InteriorRings const& interior_rings)
68 detail::check_iterator_range
72 typename boost::range_value<InteriorRings>::type
74 >::apply(boost::begin(interior_rings),
75 boost::end(interior_rings));
79 template <typename Strategy>
80 static inline bool apply(Polygon const& polygon, Strategy const&)
82 return apply(polygon);
85 static inline bool apply(Polygon const& polygon)
90 typename ring_type<Polygon>::type
91 >::apply(exterior_ring(polygon))
93 are_simple_interior_rings(geometry::interior_rings(polygon));
98 }} // namespace detail::is_simple
99 #endif // DOXYGEN_NO_DETAIL
104 #ifndef DOXYGEN_NO_DISPATCH
109 // A Ring is a Polygon.
110 // A Polygon is always a simple geometric object provided that it is valid.
112 // Reference (for polygon validity): OGC 06-103r4 (6.1.11.1)
113 template <typename Ring>
114 struct is_simple<Ring, ring_tag>
115 : detail::is_simple::is_simple_ring<Ring>
119 // A Polygon is always a simple geometric object provided that it is valid.
121 // Reference (for validity of Polygons): OGC 06-103r4 (6.1.11.1)
122 template <typename Polygon>
123 struct is_simple<Polygon, polygon_tag>
124 : detail::is_simple::is_simple_polygon<Polygon>
128 // Not clear what the definition is.
129 // Right now we consider a MultiPolygon as simple if it is valid.
131 // Reference (for validity of MultiPolygons): OGC 06-103r4 (6.1.14)
132 template <typename MultiPolygon>
133 struct is_simple<MultiPolygon, multi_polygon_tag>
135 template <typename Strategy>
136 static inline bool apply(MultiPolygon const& multipolygon, Strategy const&)
139 detail::check_iterator_range
141 detail::is_simple::is_simple_polygon
143 typename boost::range_value<MultiPolygon>::type
145 true // allow empty multi-polygon
146 >::apply(boost::begin(multipolygon), boost::end(multipolygon));
151 } // namespace dispatch
152 #endif // DOXYGEN_NO_DISPATCH
155 }} // namespace boost::geometry
157 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_AREAL_HPP