1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 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_IS_EMPTY_HPP
11 #define BOOST_GEOMETRY_ALGORITHMS_IS_EMPTY_HPP
13 #include <boost/range.hpp>
15 #include <boost/variant/apply_visitor.hpp>
16 #include <boost/variant/static_visitor.hpp>
17 #include <boost/variant/variant_fwd.hpp>
19 #include <boost/geometry/core/exterior_ring.hpp>
20 #include <boost/geometry/core/interior_rings.hpp>
21 #include <boost/geometry/core/tag.hpp>
22 #include <boost/geometry/core/tags.hpp>
24 #include <boost/geometry/algorithms/not_implemented.hpp>
26 #include <boost/geometry/algorithms/detail/check_iterator_range.hpp>
28 #include <boost/geometry/geometries/concepts/check.hpp>
31 namespace boost { namespace geometry
35 #ifndef DOXYGEN_NO_DETAIL
36 namespace detail { namespace is_empty
39 struct always_not_empty
41 template <typename Geometry>
42 static inline bool apply(Geometry const&)
50 template <typename Range>
51 static inline bool apply(Range const& range)
53 return boost::empty(range);
57 class polygon_is_empty
59 template <typename InteriorRings>
60 static inline bool check_interior_rings(InteriorRings const& interior_rings)
62 return check_iterator_range
64 range_is_empty, true // allow empty range
65 >::apply(boost::begin(interior_rings), boost::end(interior_rings));
69 template <typename Polygon>
70 static inline bool apply(Polygon const& polygon)
72 return boost::empty(exterior_ring(polygon))
73 && check_interior_rings(interior_rings(polygon));
77 template <typename Policy = range_is_empty>
80 template <typename MultiGeometry>
81 static inline bool apply(MultiGeometry const& multigeometry)
83 return check_iterator_range
85 Policy, true // allow empty range
86 >::apply(boost::begin(multigeometry), boost::end(multigeometry));
91 }} // namespace detail::is_empty
92 #endif // DOXYGEN_NO_DETAIL
95 #ifndef DOXYGEN_NO_DISPATCH
99 template <typename Geometry, typename Tag = typename tag<Geometry>::type>
100 struct is_empty : not_implemented<Tag>
103 template <typename Geometry>
104 struct is_empty<Geometry, point_tag>
105 : detail::is_empty::always_not_empty
108 template <typename Geometry>
109 struct is_empty<Geometry, box_tag>
110 : detail::is_empty::always_not_empty
113 template <typename Geometry>
114 struct is_empty<Geometry, segment_tag>
115 : detail::is_empty::always_not_empty
118 template <typename Geometry>
119 struct is_empty<Geometry, linestring_tag>
120 : detail::is_empty::range_is_empty
123 template <typename Geometry>
124 struct is_empty<Geometry, ring_tag>
125 : detail::is_empty::range_is_empty
128 template <typename Geometry>
129 struct is_empty<Geometry, polygon_tag>
130 : detail::is_empty::polygon_is_empty
133 template <typename Geometry>
134 struct is_empty<Geometry, multi_point_tag>
135 : detail::is_empty::range_is_empty
138 template <typename Geometry>
139 struct is_empty<Geometry, multi_linestring_tag>
140 : detail::is_empty::multi_is_empty<>
143 template <typename Geometry>
144 struct is_empty<Geometry, multi_polygon_tag>
145 : detail::is_empty::multi_is_empty<detail::is_empty::polygon_is_empty>
148 } // namespace dispatch
149 #endif // DOXYGEN_NO_DISPATCH
152 namespace resolve_variant
155 template <typename Geometry>
158 static inline bool apply(Geometry const& geometry)
160 concepts::check<Geometry const>();
162 return dispatch::is_empty<Geometry>::apply(geometry);
166 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
167 struct is_empty<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
169 struct visitor : boost::static_visitor<bool>
171 template <typename Geometry>
172 inline bool operator()(Geometry const& geometry) const
174 return is_empty<Geometry>::apply(geometry);
179 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry)
181 return boost::apply_visitor(visitor(), geometry);
185 } // namespace resolve_variant
189 \brief \brief_check{is the empty set}
191 \tparam Geometry \tparam_geometry
192 \param geometry \param_geometry
193 \return \return_check{is the empty set}
195 \qbk{[include reference/algorithms/is_empty.qbk]}
197 template <typename Geometry>
198 inline bool is_empty(Geometry const& geometry)
200 return resolve_variant::is_empty<Geometry>::apply(geometry);
204 }} // namespace boost::geometry
207 #endif // BOOST_GEOMETRY_ALGORITHMS_IS_EMPTY_HPP