]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/geometry/algorithms/detail/is_valid/interface.hpp
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / boost / boost / geometry / algorithms / detail / is_valid / interface.hpp
1 // Boost.Geometry
2
3 // Copyright (c) 2014-2021, Oracle and/or its affiliates.
4
5 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
6 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
7
8 // Licensed under the Boost Software License version 1.0.
9 // http://www.boost.org/users/license.html
10
11 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_INTERFACE_HPP
12 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_INTERFACE_HPP
13
14 #include <sstream>
15 #include <string>
16
17 #include <boost/geometry/algorithms/detail/visit.hpp>
18 #include <boost/geometry/algorithms/dispatch/is_valid.hpp>
19 #include <boost/geometry/core/cs.hpp>
20 #include <boost/geometry/core/visit.hpp>
21 #include <boost/geometry/geometries/adapted/boost_variant.hpp> // For backward compatibility
22 #include <boost/geometry/geometries/concepts/check.hpp>
23 #include <boost/geometry/policies/is_valid/default_policy.hpp>
24 #include <boost/geometry/policies/is_valid/failing_reason_policy.hpp>
25 #include <boost/geometry/policies/is_valid/failure_type_policy.hpp>
26 #include <boost/geometry/strategies/default_strategy.hpp>
27 #include <boost/geometry/strategies/detail.hpp>
28 #include <boost/geometry/strategies/relate/services.hpp>
29
30
31 namespace boost { namespace geometry
32 {
33
34 namespace resolve_strategy
35 {
36
37 template
38 <
39 typename Strategy,
40 bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
41 >
42 struct is_valid
43 {
44 template <typename Geometry, typename VisitPolicy>
45 static inline bool apply(Geometry const& geometry,
46 VisitPolicy& visitor,
47 Strategy const& strategy)
48 {
49 return dispatch::is_valid<Geometry>::apply(geometry, visitor, strategy);
50 }
51
52 };
53
54 template <typename Strategy>
55 struct is_valid<Strategy, false>
56 {
57 template <typename Geometry, typename VisitPolicy>
58 static inline bool apply(Geometry const& geometry,
59 VisitPolicy& visitor,
60 Strategy const& strategy)
61 {
62 using strategies::relate::services::strategy_converter;
63 return dispatch::is_valid
64 <
65 Geometry
66 >::apply(geometry, visitor,
67 strategy_converter<Strategy>::get(strategy));
68 }
69 };
70
71 template <>
72 struct is_valid<default_strategy, false>
73 {
74 template <typename Geometry, typename VisitPolicy>
75 static inline bool apply(Geometry const& geometry,
76 VisitPolicy& visitor,
77 default_strategy)
78 {
79 // NOTE: Currently the strategy is only used for Areal geometries
80 typedef typename strategies::relate::services::default_strategy
81 <
82 Geometry, Geometry
83 >::type strategy_type;
84
85 return dispatch::is_valid<Geometry>::apply(geometry, visitor,
86 strategy_type());
87 }
88 };
89
90 } // namespace resolve_strategy
91
92 namespace resolve_dynamic
93 {
94
95 template <typename Geometry, typename Tag = typename tag<Geometry>::type>
96 struct is_valid
97 {
98 template <typename VisitPolicy, typename Strategy>
99 static inline bool apply(Geometry const& geometry,
100 VisitPolicy& visitor,
101 Strategy const& strategy)
102 {
103 concepts::check<Geometry const>();
104
105 return resolve_strategy::is_valid
106 <
107 Strategy
108 >::apply(geometry, visitor, strategy);
109 }
110 };
111
112 template <typename Geometry>
113 struct is_valid<Geometry, dynamic_geometry_tag>
114 {
115 template <typename VisitPolicy, typename Strategy>
116 static inline bool apply(Geometry const& geometry,
117 VisitPolicy& policy_visitor,
118 Strategy const& strategy)
119 {
120 bool result = true;
121 traits::visit<Geometry>::apply([&](auto const& g)
122 {
123 result = is_valid<util::remove_cref_t<decltype(g)>>::apply(g, policy_visitor, strategy);
124 }, geometry);
125 return result;
126 }
127 };
128
129 template <typename Geometry>
130 struct is_valid<Geometry, geometry_collection_tag>
131 {
132 template <typename VisitPolicy, typename Strategy>
133 static inline bool apply(Geometry const& geometry,
134 VisitPolicy& policy_visitor,
135 Strategy const& strategy)
136 {
137 bool result = true;
138 detail::visit_breadth_first([&](auto const& g)
139 {
140 result = is_valid<util::remove_cref_t<decltype(g)>>::apply(g, policy_visitor, strategy);
141 return result;
142 }, geometry);
143 return result;
144 }
145 };
146
147 } // namespace resolve_dynamic
148
149
150 // Undocumented for now
151 template <typename Geometry, typename VisitPolicy, typename Strategy>
152 inline bool is_valid(Geometry const& geometry,
153 VisitPolicy& visitor,
154 Strategy const& strategy)
155 {
156 return resolve_dynamic::is_valid<Geometry>::apply(geometry, visitor, strategy);
157 }
158
159
160 /*!
161 \brief \brief_check{is valid (in the OGC sense)}
162 \ingroup is_valid
163 \tparam Geometry \tparam_geometry
164 \tparam Strategy \tparam_strategy{Is_valid}
165 \param geometry \param_geometry
166 \param strategy \param_strategy{is_valid}
167 \return \return_check{is valid (in the OGC sense);
168 furthermore, the following geometries are considered valid:
169 multi-geometries with no elements,
170 linear geometries containing spikes,
171 areal geometries with duplicate (consecutive) points}
172
173 \qbk{distinguish,with strategy}
174 \qbk{[include reference/algorithms/is_valid.qbk]}
175 */
176 template <typename Geometry, typename Strategy>
177 inline bool is_valid(Geometry const& geometry, Strategy const& strategy)
178 {
179 is_valid_default_policy<> visitor;
180 return resolve_dynamic::is_valid<Geometry>::apply(geometry, visitor, strategy);
181 }
182
183 /*!
184 \brief \brief_check{is valid (in the OGC sense)}
185 \ingroup is_valid
186 \tparam Geometry \tparam_geometry
187 \param geometry \param_geometry
188 \return \return_check{is valid (in the OGC sense);
189 furthermore, the following geometries are considered valid:
190 multi-geometries with no elements,
191 linear geometries containing spikes,
192 areal geometries with duplicate (consecutive) points}
193
194 \qbk{[include reference/algorithms/is_valid.qbk]}
195 */
196 template <typename Geometry>
197 inline bool is_valid(Geometry const& geometry)
198 {
199 return is_valid(geometry, default_strategy());
200 }
201
202
203 /*!
204 \brief \brief_check{is valid (in the OGC sense)}
205 \ingroup is_valid
206 \tparam Geometry \tparam_geometry
207 \tparam Strategy \tparam_strategy{Is_valid}
208 \param geometry \param_geometry
209 \param failure An enumeration value indicating that the geometry is
210 valid or not, and if not valid indicating the reason why
211 \param strategy \param_strategy{is_valid}
212 \return \return_check{is valid (in the OGC sense);
213 furthermore, the following geometries are considered valid:
214 multi-geometries with no elements,
215 linear geometries containing spikes,
216 areal geometries with duplicate (consecutive) points}
217
218 \qbk{distinguish,with failure value and strategy}
219 \qbk{[include reference/algorithms/is_valid_with_failure.qbk]}
220 */
221 template <typename Geometry, typename Strategy>
222 inline bool is_valid(Geometry const& geometry, validity_failure_type& failure, Strategy const& strategy)
223 {
224 failure_type_policy<> visitor;
225 bool result = resolve_dynamic::is_valid<Geometry>::apply(geometry, visitor, strategy);
226 failure = visitor.failure();
227 return result;
228 }
229
230 /*!
231 \brief \brief_check{is valid (in the OGC sense)}
232 \ingroup is_valid
233 \tparam Geometry \tparam_geometry
234 \param geometry \param_geometry
235 \param failure An enumeration value indicating that the geometry is
236 valid or not, and if not valid indicating the reason why
237 \return \return_check{is valid (in the OGC sense);
238 furthermore, the following geometries are considered valid:
239 multi-geometries with no elements,
240 linear geometries containing spikes,
241 areal geometries with duplicate (consecutive) points}
242
243 \qbk{distinguish,with failure value}
244 \qbk{[include reference/algorithms/is_valid_with_failure.qbk]}
245 */
246 template <typename Geometry>
247 inline bool is_valid(Geometry const& geometry, validity_failure_type& failure)
248 {
249 return is_valid(geometry, failure, default_strategy());
250 }
251
252
253 /*!
254 \brief \brief_check{is valid (in the OGC sense)}
255 \ingroup is_valid
256 \tparam Geometry \tparam_geometry
257 \tparam Strategy \tparam_strategy{Is_valid}
258 \param geometry \param_geometry
259 \param message A string containing a message stating if the geometry
260 is valid or not, and if not valid a reason why
261 \param strategy \param_strategy{is_valid}
262 \return \return_check{is valid (in the OGC sense);
263 furthermore, the following geometries are considered valid:
264 multi-geometries with no elements,
265 linear geometries containing spikes,
266 areal geometries with duplicate (consecutive) points}
267
268 \qbk{distinguish,with message and strategy}
269 \qbk{[include reference/algorithms/is_valid_with_message.qbk]}
270 */
271 template <typename Geometry, typename Strategy>
272 inline bool is_valid(Geometry const& geometry, std::string& message, Strategy const& strategy)
273 {
274 std::ostringstream stream;
275 failing_reason_policy<> visitor(stream);
276 bool result = resolve_dynamic::is_valid<Geometry>::apply(geometry, visitor, strategy);
277 message = stream.str();
278 return result;
279 }
280
281 /*!
282 \brief \brief_check{is valid (in the OGC sense)}
283 \ingroup is_valid
284 \tparam Geometry \tparam_geometry
285 \param geometry \param_geometry
286 \param message A string containing a message stating if the geometry
287 is valid or not, and if not valid a reason why
288 \return \return_check{is valid (in the OGC sense);
289 furthermore, the following geometries are considered valid:
290 multi-geometries with no elements,
291 linear geometries containing spikes,
292 areal geometries with duplicate (consecutive) points}
293
294 \qbk{distinguish,with message}
295 \qbk{[include reference/algorithms/is_valid_with_message.qbk]}
296 */
297 template <typename Geometry>
298 inline bool is_valid(Geometry const& geometry, std::string& message)
299 {
300 return is_valid(geometry, message, default_strategy());
301 }
302
303
304 }} // namespace boost::geometry
305
306 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_IS_VALID_INTERFACE_HPP