1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2014-2015, Oracle and/or its affiliates.
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
7 // Licensed under the Boost Software License version 1.0.
8 // http://www.boost.org/users/license.html
10 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_AREAL_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_AREAL_HPP
13 #include <boost/range.hpp>
15 #include <boost/geometry/core/closure.hpp>
16 #include <boost/geometry/core/exterior_ring.hpp>
17 #include <boost/geometry/core/interior_rings.hpp>
18 #include <boost/geometry/core/ring_type.hpp>
19 #include <boost/geometry/core/tags.hpp>
21 #include <boost/geometry/algorithms/detail/check_iterator_range.hpp>
22 #include <boost/geometry/algorithms/detail/is_simple/failure_policy.hpp>
23 #include <boost/geometry/algorithms/detail/is_valid/has_duplicates.hpp>
25 #include <boost/geometry/algorithms/dispatch/is_simple.hpp>
28 namespace boost { namespace geometry
32 #ifndef DOXYGEN_NO_DETAIL
33 namespace detail { namespace is_simple
37 template <typename Ring>
40 static inline bool apply(Ring const& ring)
42 simplicity_failure_policy policy;
43 return ! boost::empty(ring)
44 && ! detail::is_valid::has_duplicates
46 Ring, geometry::closure<Ring>::value
47 >::apply(ring, policy);
52 template <typename Polygon>
53 class is_simple_polygon
56 template <typename InteriorRings>
58 bool are_simple_interior_rings(InteriorRings const& interior_rings)
61 detail::check_iterator_range
65 typename boost::range_value<InteriorRings>::type
67 >::apply(boost::begin(interior_rings),
68 boost::end(interior_rings));
72 static inline bool apply(Polygon const& polygon)
77 typename ring_type<Polygon>::type
78 >::apply(exterior_ring(polygon))
80 are_simple_interior_rings(geometry::interior_rings(polygon));
85 }} // namespace detail::is_simple
86 #endif // DOXYGEN_NO_DETAIL
91 #ifndef DOXYGEN_NO_DISPATCH
96 // A Ring is a Polygon.
97 // A Polygon is always a simple geometric object provided that it is valid.
99 // Reference (for polygon validity): OGC 06-103r4 (6.1.11.1)
100 template <typename Ring>
101 struct is_simple<Ring, ring_tag>
102 : detail::is_simple::is_simple_ring<Ring>
106 // A Polygon is always a simple geometric object provided that it is valid.
108 // Reference (for validity of Polygons): OGC 06-103r4 (6.1.11.1)
109 template <typename Polygon>
110 struct is_simple<Polygon, polygon_tag>
111 : detail::is_simple::is_simple_polygon<Polygon>
115 // Not clear what the definition is.
116 // Right now we consider a MultiPolygon as simple if it is valid.
118 // Reference (for validity of MultiPolygons): OGC 06-103r4 (6.1.14)
119 template <typename MultiPolygon>
120 struct is_simple<MultiPolygon, multi_polygon_tag>
122 static inline bool apply(MultiPolygon const& multipolygon)
125 detail::check_iterator_range
127 detail::is_simple::is_simple_polygon
129 typename boost::range_value<MultiPolygon>::type
131 true // allow empty multi-polygon
132 >::apply(boost::begin(multipolygon), boost::end(multipolygon));
137 } // namespace dispatch
138 #endif // DOXYGEN_NO_DISPATCH
141 }} // namespace boost::geometry
143 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_SIMPLE_AREAL_HPP