]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // Boost.Geometry (aka GGL, Generic Geometry Library) |
2 | ||
3 | // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands. | |
4 | // Copyright (c) 2008-2012 Bruno Lalande, Paris, France. | |
5 | // Copyright (c) 2009-2012 Mateusz Loskot, London, UK. | |
6 | ||
1e59de90 TL |
7 | // This file was modified by Oracle on 2013-2021. |
8 | // Modifications copyright (c) 2013-2021 Oracle and/or its affiliates. | |
b32b8144 | 9 | // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle |
7c673cae FG |
10 | |
11 | // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library | |
12 | // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands. | |
13 | ||
14 | // Use, modification and distribution is subject to the Boost Software License, | |
15 | // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at | |
16 | // http://www.boost.org/LICENSE_1_0.txt) | |
17 | ||
b32b8144 FG |
18 | #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_COVERED_BY_INTERFACE_HPP |
19 | #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_COVERED_BY_INTERFACE_HPP | |
7c673cae FG |
20 | |
21 | ||
7c673cae FG |
22 | #include <boost/variant/apply_visitor.hpp> |
23 | #include <boost/variant/static_visitor.hpp> | |
24 | #include <boost/variant/variant_fwd.hpp> | |
25 | ||
b32b8144 | 26 | #include <boost/geometry/algorithms/detail/within/interface.hpp> |
7c673cae | 27 | #include <boost/geometry/algorithms/not_implemented.hpp> |
7c673cae | 28 | |
7c673cae | 29 | #include <boost/geometry/strategies/default_strategy.hpp> |
1e59de90 TL |
30 | #include <boost/geometry/strategies/detail.hpp> |
31 | #include <boost/geometry/strategies/relate/services.hpp> | |
7c673cae | 32 | |
7c673cae | 33 | |
b32b8144 | 34 | namespace boost { namespace geometry |
7c673cae | 35 | { |
7c673cae FG |
36 | |
37 | #ifndef DOXYGEN_NO_DISPATCH | |
38 | namespace dispatch | |
39 | { | |
40 | ||
41 | template | |
42 | < | |
43 | typename Geometry1, | |
44 | typename Geometry2, | |
45 | typename Tag1 = typename tag<Geometry1>::type, | |
46 | typename Tag2 = typename tag<Geometry2>::type | |
47 | > | |
48 | struct covered_by | |
49 | : not_implemented<Tag1, Tag2> | |
50 | {}; | |
51 | ||
7c673cae FG |
52 | } // namespace dispatch |
53 | #endif // DOXYGEN_NO_DISPATCH | |
54 | ||
55 | ||
56 | namespace resolve_strategy { | |
57 | ||
1e59de90 TL |
58 | template |
59 | < | |
60 | typename Strategy, | |
61 | bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value | |
62 | > | |
7c673cae FG |
63 | struct covered_by |
64 | { | |
1e59de90 | 65 | template <typename Geometry1, typename Geometry2> |
7c673cae FG |
66 | static inline bool apply(Geometry1 const& geometry1, |
67 | Geometry2 const& geometry2, | |
68 | Strategy const& strategy) | |
69 | { | |
92f5a8d4 | 70 | concepts::within::check<Geometry1, Geometry2, Strategy>(); |
7c673cae FG |
71 | concepts::check<Geometry1 const>(); |
72 | concepts::check<Geometry2 const>(); | |
73 | assert_dimension_equal<Geometry1, Geometry2>(); | |
74 | ||
1e59de90 TL |
75 | return dispatch::covered_by |
76 | < | |
77 | Geometry1, Geometry2 | |
78 | >::apply(geometry1, geometry2, strategy); | |
79 | } | |
80 | }; | |
81 | ||
82 | template <typename Strategy> | |
83 | struct covered_by<Strategy, false> | |
84 | { | |
85 | template <typename Geometry1, typename Geometry2> | |
86 | static inline bool apply(Geometry1 const& geometry1, | |
87 | Geometry2 const& geometry2, | |
88 | Strategy const& strategy) | |
89 | { | |
90 | using strategies::relate::services::strategy_converter; | |
91 | ||
92 | return covered_by | |
93 | < | |
94 | decltype(strategy_converter<Strategy>::get(strategy)) | |
95 | >::apply(geometry1, geometry2, | |
96 | strategy_converter<Strategy>::get(strategy)); | |
7c673cae | 97 | } |
1e59de90 | 98 | }; |
7c673cae | 99 | |
1e59de90 TL |
100 | template <> |
101 | struct covered_by<default_strategy, false> | |
102 | { | |
7c673cae FG |
103 | template <typename Geometry1, typename Geometry2> |
104 | static inline bool apply(Geometry1 const& geometry1, | |
105 | Geometry2 const& geometry2, | |
106 | default_strategy) | |
107 | { | |
1e59de90 | 108 | typedef typename strategies::relate::services::default_strategy |
7c673cae | 109 | < |
7c673cae FG |
110 | Geometry1, |
111 | Geometry2 | |
112 | >::type strategy_type; | |
113 | ||
1e59de90 TL |
114 | return covered_by |
115 | < | |
116 | strategy_type | |
117 | >::apply(geometry1, geometry2, strategy_type()); | |
7c673cae FG |
118 | } |
119 | }; | |
120 | ||
121 | } // namespace resolve_strategy | |
122 | ||
123 | ||
124 | namespace resolve_variant { | |
125 | ||
126 | template <typename Geometry1, typename Geometry2> | |
127 | struct covered_by | |
128 | { | |
129 | template <typename Strategy> | |
130 | static inline bool apply(Geometry1 const& geometry1, | |
131 | Geometry2 const& geometry2, | |
132 | Strategy const& strategy) | |
133 | { | |
1e59de90 | 134 | return resolve_strategy::covered_by<Strategy> |
7c673cae FG |
135 | ::apply(geometry1, geometry2, strategy); |
136 | } | |
137 | }; | |
138 | ||
139 | template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2> | |
140 | struct covered_by<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2> | |
141 | { | |
142 | template <typename Strategy> | |
143 | struct visitor: boost::static_visitor<bool> | |
144 | { | |
145 | Geometry2 const& m_geometry2; | |
146 | Strategy const& m_strategy; | |
147 | ||
148 | visitor(Geometry2 const& geometry2, Strategy const& strategy) | |
149 | : m_geometry2(geometry2), m_strategy(strategy) {} | |
150 | ||
151 | template <typename Geometry1> | |
152 | bool operator()(Geometry1 const& geometry1) const | |
153 | { | |
154 | return covered_by<Geometry1, Geometry2> | |
155 | ::apply(geometry1, m_geometry2, m_strategy); | |
156 | } | |
157 | }; | |
158 | ||
159 | template <typename Strategy> | |
160 | static inline bool | |
161 | apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1, | |
162 | Geometry2 const& geometry2, | |
163 | Strategy const& strategy) | |
164 | { | |
165 | return boost::apply_visitor(visitor<Strategy>(geometry2, strategy), geometry1); | |
166 | } | |
167 | }; | |
168 | ||
169 | template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)> | |
170 | struct covered_by<Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> > | |
171 | { | |
172 | template <typename Strategy> | |
173 | struct visitor: boost::static_visitor<bool> | |
174 | { | |
175 | Geometry1 const& m_geometry1; | |
176 | Strategy const& m_strategy; | |
177 | ||
178 | visitor(Geometry1 const& geometry1, Strategy const& strategy) | |
179 | : m_geometry1(geometry1), m_strategy(strategy) {} | |
180 | ||
181 | template <typename Geometry2> | |
182 | bool operator()(Geometry2 const& geometry2) const | |
183 | { | |
184 | return covered_by<Geometry1, Geometry2> | |
185 | ::apply(m_geometry1, geometry2, m_strategy); | |
186 | } | |
187 | }; | |
188 | ||
189 | template <typename Strategy> | |
190 | static inline bool | |
191 | apply(Geometry1 const& geometry1, | |
192 | boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2, | |
193 | Strategy const& strategy) | |
194 | { | |
195 | return boost::apply_visitor(visitor<Strategy>(geometry1, strategy), geometry2); | |
196 | } | |
197 | }; | |
198 | ||
199 | template < | |
200 | BOOST_VARIANT_ENUM_PARAMS(typename T1), | |
201 | BOOST_VARIANT_ENUM_PARAMS(typename T2) | |
202 | > | |
203 | struct covered_by< | |
204 | boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, | |
205 | boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> | |
206 | > | |
207 | { | |
208 | template <typename Strategy> | |
209 | struct visitor: boost::static_visitor<bool> | |
210 | { | |
211 | Strategy const& m_strategy; | |
212 | ||
213 | visitor(Strategy const& strategy): m_strategy(strategy) {} | |
214 | ||
215 | template <typename Geometry1, typename Geometry2> | |
216 | bool operator()(Geometry1 const& geometry1, | |
217 | Geometry2 const& geometry2) const | |
218 | { | |
219 | return covered_by<Geometry1, Geometry2> | |
220 | ::apply(geometry1, geometry2, m_strategy); | |
221 | } | |
222 | }; | |
223 | ||
224 | template <typename Strategy> | |
225 | static inline bool | |
226 | apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1, | |
227 | boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2, | |
228 | Strategy const& strategy) | |
229 | { | |
230 | return boost::apply_visitor(visitor<Strategy>(strategy), geometry1, geometry2); | |
231 | } | |
232 | }; | |
233 | ||
234 | } // namespace resolve_variant | |
235 | ||
236 | ||
237 | /*! | |
238 | \brief \brief_check12{is inside or on border} | |
239 | \ingroup covered_by | |
240 | \details \details_check12{covered_by, is inside or on border}. | |
241 | \tparam Geometry1 \tparam_geometry | |
242 | \tparam Geometry2 \tparam_geometry | |
243 | \param geometry1 \param_geometry which might be inside or on the border of the second geometry | |
244 | \param geometry2 \param_geometry which might cover the first geometry | |
245 | \return true if geometry1 is inside of or on the border of geometry2, | |
246 | else false | |
247 | \note The default strategy is used for covered_by detection | |
248 | ||
249 | \qbk{[include reference/algorithms/covered_by.qbk]} | |
f67539c2 TL |
250 | \qbk{ |
251 | [heading Examples] | |
252 | [covered_by] | |
253 | [covered_by_output] | |
254 | } | |
7c673cae FG |
255 | */ |
256 | template<typename Geometry1, typename Geometry2> | |
257 | inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2) | |
258 | { | |
259 | return resolve_variant::covered_by<Geometry1, Geometry2> | |
260 | ::apply(geometry1, geometry2, default_strategy()); | |
261 | } | |
262 | ||
263 | /*! | |
264 | \brief \brief_check12{is inside or on border} \brief_strategy | |
265 | \ingroup covered_by | |
266 | \details \details_check12{covered_by, is inside or on border}, \brief_strategy. \details_strategy_reasons | |
267 | \tparam Geometry1 \tparam_geometry | |
268 | \tparam Geometry2 \tparam_geometry | |
269 | \param geometry1 \param_geometry which might be inside or on the border of the second geometry | |
270 | \param geometry2 \param_geometry which might cover the first geometry | |
271 | \param strategy strategy to be used | |
272 | \return true if geometry1 is inside of or on the border of geometry2, | |
273 | else false | |
274 | ||
275 | \qbk{distinguish,with strategy} | |
276 | \qbk{[include reference/algorithms/covered_by.qbk]} | |
277 | ||
278 | */ | |
279 | template<typename Geometry1, typename Geometry2, typename Strategy> | |
280 | inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2, | |
281 | Strategy const& strategy) | |
282 | { | |
283 | return resolve_variant::covered_by<Geometry1, Geometry2> | |
284 | ::apply(geometry1, geometry2, strategy); | |
285 | } | |
286 | ||
287 | }} // namespace boost::geometry | |
288 | ||
b32b8144 | 289 | #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_COVERED_BY_INTERFACE_HPP |