]> git.proxmox.com Git - ceph.git/blame - ceph/src/boost/boost/geometry/algorithms/is_empty.hpp
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / is_empty.hpp
CommitLineData
7c673cae
FG
1// Boost.Geometry (aka GGL, Generic Geometry Library)
2
1e59de90 3// Copyright (c) 2015-2021, Oracle and/or its affiliates.
7c673cae 4
1e59de90 5// Contributed and/or modified by Vissarion Fysikopoulos, on behalf of Oracle
7c673cae 6// Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
20effc67 7// Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7c673cae
FG
8
9// Licensed under the Boost Software License version 1.0.
10// http://www.boost.org/users/license.html
11
12#ifndef BOOST_GEOMETRY_ALGORITHMS_IS_EMPTY_HPP
13#define BOOST_GEOMETRY_ALGORITHMS_IS_EMPTY_HPP
14
20effc67
TL
15#include <boost/range/begin.hpp>
16#include <boost/range/empty.hpp>
17#include <boost/range/end.hpp>
7c673cae 18
1e59de90
TL
19#include <boost/geometry/algorithms/not_implemented.hpp>
20#include <boost/geometry/algorithms/detail/visit.hpp>
7c673cae
FG
21
22#include <boost/geometry/core/exterior_ring.hpp>
1e59de90 23#include <boost/geometry/core/geometry_types.hpp>
7c673cae
FG
24#include <boost/geometry/core/interior_rings.hpp>
25#include <boost/geometry/core/tag.hpp>
26#include <boost/geometry/core/tags.hpp>
1e59de90 27#include <boost/geometry/core/visit.hpp>
7c673cae 28
1e59de90 29#include <boost/geometry/geometries/adapted/boost_variant.hpp> // For backward compatibility
7c673cae
FG
30#include <boost/geometry/geometries/concepts/check.hpp>
31
1e59de90 32#include <boost/geometry/util/type_traits_std.hpp>
7c673cae
FG
33
34namespace boost { namespace geometry
35{
36
37
38#ifndef DOXYGEN_NO_DETAIL
39namespace detail { namespace is_empty
40{
41
42struct always_not_empty
43{
44 template <typename Geometry>
45 static inline bool apply(Geometry const&)
46 {
47 return false;
48 }
49};
50
51struct range_is_empty
52{
53 template <typename Range>
54 static inline bool apply(Range const& range)
55 {
56 return boost::empty(range);
57 }
58};
59
60class polygon_is_empty
61{
62 template <typename InteriorRings>
63 static inline bool check_interior_rings(InteriorRings const& interior_rings)
64 {
1e59de90
TL
65 return std::all_of(boost::begin(interior_rings), boost::end(interior_rings),
66 []( auto const& range ){ return boost::empty(range); });
7c673cae
FG
67 }
68
69public:
70 template <typename Polygon>
71 static inline bool apply(Polygon const& polygon)
72 {
73 return boost::empty(exterior_ring(polygon))
74 && check_interior_rings(interior_rings(polygon));
75 }
76};
77
78template <typename Policy = range_is_empty>
79struct multi_is_empty
80{
81 template <typename MultiGeometry>
82 static inline bool apply(MultiGeometry const& multigeometry)
83 {
1e59de90
TL
84 return std::all_of(boost::begin(multigeometry),
85 boost::end(multigeometry),
86 []( auto const& range ){ return Policy::apply(range); });
7c673cae 87 }
7c673cae
FG
88};
89
90}} // namespace detail::is_empty
91#endif // DOXYGEN_NO_DETAIL
92
93
94#ifndef DOXYGEN_NO_DISPATCH
95namespace dispatch
96{
97
98template <typename Geometry, typename Tag = typename tag<Geometry>::type>
99struct is_empty : not_implemented<Tag>
100{};
101
102template <typename Geometry>
103struct is_empty<Geometry, point_tag>
104 : detail::is_empty::always_not_empty
105{};
106
107template <typename Geometry>
108struct is_empty<Geometry, box_tag>
109 : detail::is_empty::always_not_empty
110{};
111
112template <typename Geometry>
113struct is_empty<Geometry, segment_tag>
114 : detail::is_empty::always_not_empty
115{};
116
117template <typename Geometry>
118struct is_empty<Geometry, linestring_tag>
119 : detail::is_empty::range_is_empty
120{};
121
122template <typename Geometry>
123struct is_empty<Geometry, ring_tag>
124 : detail::is_empty::range_is_empty
125{};
126
127template <typename Geometry>
128struct is_empty<Geometry, polygon_tag>
129 : detail::is_empty::polygon_is_empty
130{};
131
132template <typename Geometry>
133struct is_empty<Geometry, multi_point_tag>
134 : detail::is_empty::range_is_empty
135{};
136
137template <typename Geometry>
138struct is_empty<Geometry, multi_linestring_tag>
139 : detail::is_empty::multi_is_empty<>
140{};
141
142template <typename Geometry>
143struct is_empty<Geometry, multi_polygon_tag>
144 : detail::is_empty::multi_is_empty<detail::is_empty::polygon_is_empty>
145{};
146
147} // namespace dispatch
148#endif // DOXYGEN_NO_DISPATCH
149
150
1e59de90 151namespace resolve_dynamic
7c673cae
FG
152{
153
1e59de90 154template <typename Geometry, typename Tag = typename tag<Geometry>::type>
7c673cae
FG
155struct is_empty
156{
157 static inline bool apply(Geometry const& geometry)
158 {
159 concepts::check<Geometry const>();
160
161 return dispatch::is_empty<Geometry>::apply(geometry);
162 }
163};
164
1e59de90
TL
165template <typename Geometry>
166struct is_empty<Geometry, dynamic_geometry_tag>
7c673cae 167{
1e59de90 168 static inline bool apply(Geometry const& geometry)
7c673cae 169 {
1e59de90
TL
170 bool result = true;
171 traits::visit<Geometry>::apply([&](auto const& g)
7c673cae 172 {
1e59de90
TL
173 result = is_empty<util::remove_cref_t<decltype(g)>>::apply(g);
174 }, geometry);
175 return result;
176 }
177};
7c673cae 178
1e59de90
TL
179template <typename Geometry>
180struct is_empty<Geometry, geometry_collection_tag>
181{
182 static inline bool apply(Geometry const& geometry)
7c673cae 183 {
1e59de90
TL
184 bool result = true;
185 detail::visit_breadth_first([&](auto const& g)
186 {
187 result = is_empty<util::remove_cref_t<decltype(g)>>::apply(g);
188 return result;
189 }, geometry);
190 return result;
7c673cae
FG
191 }
192};
193
1e59de90 194} // namespace resolve_dynamic
7c673cae
FG
195
196
197/*!
198\brief \brief_check{is the empty set}
199\ingroup is_empty
200\tparam Geometry \tparam_geometry
201\param geometry \param_geometry
202\return \return_check{is the empty set}
203
204\qbk{[include reference/algorithms/is_empty.qbk]}
205*/
206template <typename Geometry>
207inline bool is_empty(Geometry const& geometry)
208{
1e59de90 209 return resolve_dynamic::is_empty<Geometry>::apply(geometry);
7c673cae
FG
210}
211
212
213}} // namespace boost::geometry
214
215
216#endif // BOOST_GEOMETRY_ALGORITHMS_IS_EMPTY_HPP