1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
6 // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
8 // This file was modified by Oracle on 2013-2021.
9 // Modifications copyright (c) 2013-2021, Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
13 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
14 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
16 // Use, modification and distribution is subject to the Boost Software License,
17 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
18 // http://www.boost.org/LICENSE_1_0.txt)
20 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_TOUCHES_INTERFACE_HPP
21 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_TOUCHES_INTERFACE_HPP
26 #include <boost/variant/apply_visitor.hpp>
27 #include <boost/variant/static_visitor.hpp>
28 #include <boost/variant/variant_fwd.hpp>
30 #include <boost/geometry/core/reverse_dispatch.hpp>
31 #include <boost/geometry/core/tag.hpp>
32 #include <boost/geometry/core/tag_cast.hpp>
33 #include <boost/geometry/core/tags.hpp>
35 #include <boost/geometry/geometries/concepts/check.hpp>
37 #include <boost/geometry/strategies/default_strategy.hpp>
38 #include <boost/geometry/strategies/detail.hpp>
39 #include <boost/geometry/strategies/relate/services.hpp>
42 namespace boost { namespace geometry
45 #ifndef DOXYGEN_NO_DISPATCH
48 // TODO: Since CastedTags are used is Reverse needed?
54 typename Tag1 = typename tag<Geometry1>::type,
55 typename Tag2 = typename tag<Geometry2>::type,
56 typename CastedTag1 = typename tag_cast<Tag1, pointlike_tag, linear_tag, areal_tag>::type,
57 typename CastedTag2 = typename tag_cast<Tag2, pointlike_tag, linear_tag, areal_tag>::type,
58 bool Reverse = reverse_dispatch<Geometry1, Geometry2>::type::value
61 : not_implemented<Tag1, Tag2>
64 // If reversal is needed, perform it
67 typename Geometry1, typename Geometry2,
68 typename Tag1, typename Tag2,
69 typename CastedTag1, typename CastedTag2
71 struct touches<Geometry1, Geometry2, Tag1, Tag2, CastedTag1, CastedTag2, true>
72 : touches<Geometry2, Geometry1, Tag2, Tag1, CastedTag2, CastedTag1, false>
74 template <typename Strategy>
75 static inline bool apply(Geometry1 const& g1, Geometry2 const& g2, Strategy const& strategy)
77 return touches<Geometry2, Geometry1>::apply(g2, g1, strategy);
81 } // namespace dispatch
82 #endif // DOXYGEN_NO_DISPATCH
85 namespace resolve_strategy
91 bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
95 template <typename Geometry1, typename Geometry2>
96 static inline bool apply(Geometry1 const& geometry1,
97 Geometry2 const& geometry2,
98 Strategy const& strategy)
100 return dispatch::touches
103 >::apply(geometry1, geometry2, strategy);
107 template <typename Strategy>
108 struct touches<Strategy, false>
110 template <typename Geometry1, typename Geometry2>
111 static inline bool apply(Geometry1 const& geometry1,
112 Geometry2 const& geometry2,
113 Strategy const& strategy)
115 using strategies::relate::services::strategy_converter;
117 return dispatch::touches
120 >::apply(geometry1, geometry2,
121 strategy_converter<Strategy>::get(strategy));
126 struct touches<default_strategy, false>
128 template <typename Geometry1, typename Geometry2>
129 static inline bool apply(Geometry1 const& geometry1,
130 Geometry2 const& geometry2,
133 typedef typename strategies::relate::services::default_strategy
137 >::type strategy_type;
139 return dispatch::touches
142 >::apply(geometry1, geometry2, strategy_type());
146 } // namespace resolve_strategy
149 namespace resolve_variant {
151 template <typename Geometry1, typename Geometry2>
154 template <typename Strategy>
155 static bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
157 concepts::check<Geometry1 const>();
158 concepts::check<Geometry2 const>();
160 return resolve_strategy::touches
163 >::apply(geometry1, geometry2, strategy);
167 template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
168 struct touches<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
170 template <typename Strategy>
171 struct visitor: boost::static_visitor<bool>
173 Geometry2 const& m_geometry2;
174 Strategy const& m_strategy;
176 visitor(Geometry2 const& geometry2, Strategy const& strategy)
177 : m_geometry2(geometry2)
178 , m_strategy(strategy)
181 template <typename Geometry1>
182 bool operator()(Geometry1 const& geometry1) const
184 return touches<Geometry1, Geometry2>::apply(geometry1, m_geometry2, m_strategy);
188 template <typename Strategy>
189 static inline bool apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
190 Geometry2 const& geometry2,
191 Strategy const& strategy)
193 return boost::apply_visitor(visitor<Strategy>(geometry2, strategy), geometry1);
197 template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
198 struct touches<Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
200 template <typename Strategy>
201 struct visitor: boost::static_visitor<bool>
203 Geometry1 const& m_geometry1;
204 Strategy const& m_strategy;
206 visitor(Geometry1 const& geometry1, Strategy const& strategy)
207 : m_geometry1(geometry1)
208 , m_strategy(strategy)
211 template <typename Geometry2>
212 bool operator()(Geometry2 const& geometry2) const
214 return touches<Geometry1, Geometry2>::apply(m_geometry1, geometry2, m_strategy);
218 template <typename Strategy>
219 static inline bool apply(Geometry1 const& geometry1,
220 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
221 Strategy const& strategy)
223 return boost::apply_visitor(visitor<Strategy>(geometry1, strategy), geometry2);
227 template <BOOST_VARIANT_ENUM_PARAMS(typename T1),
228 BOOST_VARIANT_ENUM_PARAMS(typename T2)>
229 struct touches<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
230 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
232 template <typename Strategy>
233 struct visitor: boost::static_visitor<bool>
235 Strategy const& m_strategy;
237 visitor(Strategy const& strategy)
238 : m_strategy(strategy)
241 template <typename Geometry1, typename Geometry2>
242 bool operator()(Geometry1 const& geometry1,
243 Geometry2 const& geometry2) const
245 return touches<Geometry1, Geometry2>::apply(geometry1, geometry2, m_strategy);
249 template <typename Strategy>
250 static inline bool apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
251 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
252 Strategy const& strategy)
254 return boost::apply_visitor(visitor<Strategy>(strategy), geometry1, geometry2);
258 template <typename Geometry>
261 template <BOOST_VARIANT_ENUM_PARAMS(typename T)>
262 struct self_touches<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
264 struct visitor: boost::static_visitor<bool>
266 template <typename Geometry>
267 bool operator()(Geometry const& geometry) const
269 return self_touches<Geometry>::apply(geometry);
274 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry)
276 return boost::apply_visitor(visitor(), geometry);
280 } // namespace resolve_variant
284 \brief \brief_check{has at least one touching point (self-tangency)}
285 \note This function can be called for one geometry (self-tangency) and
286 also for two geometries (touch)
288 \tparam Geometry \tparam_geometry
289 \param geometry \param_geometry
290 \return \return_check{is self-touching}
292 \qbk{distinguish,one geometry}
293 \qbk{[def __one_parameter__]}
294 \qbk{[include reference/algorithms/touches.qbk]}
297 [touches_one_geometry]
298 [touches_one_geometry_output]
301 template <typename Geometry>
302 inline bool touches(Geometry const& geometry)
304 return resolve_variant::self_touches<Geometry>::apply(geometry);
309 \brief \brief_check2{have at least one touching point (tangent - non overlapping)}
311 \tparam Geometry1 \tparam_geometry
312 \tparam Geometry2 \tparam_geometry
313 \param geometry1 \param_geometry
314 \param geometry2 \param_geometry
315 \return \return_check2{touch each other}
317 \qbk{distinguish,two geometries}
318 \qbk{[include reference/algorithms/touches.qbk]}
321 [touches_two_geometries]
322 [touches_two_geometries_output]
325 template <typename Geometry1, typename Geometry2>
326 inline bool touches(Geometry1 const& geometry1, Geometry2 const& geometry2)
328 return resolve_variant::touches
331 >::apply(geometry1, geometry2, default_strategy());
335 \brief \brief_check2{have at least one touching point (tangent - non overlapping)}
337 \tparam Geometry1 \tparam_geometry
338 \tparam Geometry2 \tparam_geometry
339 \tparam Strategy \tparam_strategy{Touches}
340 \param geometry1 \param_geometry
341 \param geometry2 \param_geometry
342 \param strategy \param_strategy{touches}
343 \return \return_check2{touch each other}
345 \qbk{distinguish,with strategy}
346 \qbk{[include reference/algorithms/touches.qbk]}
348 template <typename Geometry1, typename Geometry2, typename Strategy>
349 inline bool touches(Geometry1 const& geometry1,
350 Geometry2 const& geometry2,
351 Strategy const& strategy)
353 return resolve_variant::touches
356 >::apply(geometry1, geometry2, strategy);
360 }} // namespace boost::geometry
362 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_TOUCHES_INTERFACE_HPP