interface.hpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2013-2015 Adam Wulkiewicz, Lodz, Poland.
  6. // This file was modified by Oracle on 2013-2022.
  7. // Modifications copyright (c) 2013-2022, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  10. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  11. // Use, modification and distribution is subject to the Boost Software License,
  12. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  13. // http://www.boost.org/LICENSE_1_0.txt)
  14. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_TOUCHES_INTERFACE_HPP
  15. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_TOUCHES_INTERFACE_HPP
  16. #include <deque>
  17. #include <boost/geometry/core/reverse_dispatch.hpp>
  18. #include <boost/geometry/core/tag.hpp>
  19. #include <boost/geometry/core/tag_cast.hpp>
  20. #include <boost/geometry/core/tags.hpp>
  21. #include <boost/geometry/core/visit.hpp>
  22. #include <boost/geometry/geometries/adapted/boost_variant.hpp>
  23. #include <boost/geometry/geometries/concepts/check.hpp>
  24. #include <boost/geometry/strategies/default_strategy.hpp>
  25. #include <boost/geometry/strategies/detail.hpp>
  26. #include <boost/geometry/strategies/relate/services.hpp>
  27. namespace boost { namespace geometry
  28. {
  29. #ifndef DOXYGEN_NO_DISPATCH
  30. namespace dispatch {
  31. // TODO: Since CastedTags are used is Reverse needed?
  32. template
  33. <
  34. typename Geometry1,
  35. typename Geometry2,
  36. typename Tag1 = typename tag<Geometry1>::type,
  37. typename Tag2 = typename tag<Geometry2>::type,
  38. typename CastedTag1 = typename tag_cast<Tag1, pointlike_tag, linear_tag, areal_tag>::type,
  39. typename CastedTag2 = typename tag_cast<Tag2, pointlike_tag, linear_tag, areal_tag>::type,
  40. bool Reverse = reverse_dispatch<Geometry1, Geometry2>::type::value
  41. >
  42. struct touches
  43. : not_implemented<Tag1, Tag2>
  44. {};
  45. // If reversal is needed, perform it
  46. template
  47. <
  48. typename Geometry1, typename Geometry2,
  49. typename Tag1, typename Tag2,
  50. typename CastedTag1, typename CastedTag2
  51. >
  52. struct touches<Geometry1, Geometry2, Tag1, Tag2, CastedTag1, CastedTag2, true>
  53. : touches<Geometry2, Geometry1, Tag2, Tag1, CastedTag2, CastedTag1, false>
  54. {
  55. template <typename Strategy>
  56. static inline bool apply(Geometry1 const& g1, Geometry2 const& g2, Strategy const& strategy)
  57. {
  58. return touches<Geometry2, Geometry1>::apply(g2, g1, strategy);
  59. }
  60. };
  61. } // namespace dispatch
  62. #endif // DOXYGEN_NO_DISPATCH
  63. namespace resolve_strategy
  64. {
  65. template
  66. <
  67. typename Strategy,
  68. bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
  69. >
  70. struct touches
  71. {
  72. template <typename Geometry1, typename Geometry2>
  73. static inline bool apply(Geometry1 const& geometry1,
  74. Geometry2 const& geometry2,
  75. Strategy const& strategy)
  76. {
  77. return dispatch::touches
  78. <
  79. Geometry1, Geometry2
  80. >::apply(geometry1, geometry2, strategy);
  81. }
  82. };
  83. template <typename Strategy>
  84. struct touches<Strategy, false>
  85. {
  86. template <typename Geometry1, typename Geometry2>
  87. static inline bool apply(Geometry1 const& geometry1,
  88. Geometry2 const& geometry2,
  89. Strategy const& strategy)
  90. {
  91. using strategies::relate::services::strategy_converter;
  92. return dispatch::touches
  93. <
  94. Geometry1, Geometry2
  95. >::apply(geometry1, geometry2,
  96. strategy_converter<Strategy>::get(strategy));
  97. }
  98. };
  99. template <>
  100. struct touches<default_strategy, false>
  101. {
  102. template <typename Geometry1, typename Geometry2>
  103. static inline bool apply(Geometry1 const& geometry1,
  104. Geometry2 const& geometry2,
  105. default_strategy)
  106. {
  107. typedef typename strategies::relate::services::default_strategy
  108. <
  109. Geometry1,
  110. Geometry2
  111. >::type strategy_type;
  112. return dispatch::touches
  113. <
  114. Geometry1, Geometry2
  115. >::apply(geometry1, geometry2, strategy_type());
  116. }
  117. };
  118. } // namespace resolve_strategy
  119. namespace resolve_dynamic {
  120. template
  121. <
  122. typename Geometry1, typename Geometry2,
  123. typename Tag1 = typename geometry::tag<Geometry1>::type,
  124. typename Tag2 = typename geometry::tag<Geometry2>::type
  125. >
  126. struct touches
  127. {
  128. template <typename Strategy>
  129. static bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
  130. Strategy const& strategy)
  131. {
  132. concepts::check<Geometry1 const>();
  133. concepts::check<Geometry2 const>();
  134. return resolve_strategy::touches
  135. <
  136. Strategy
  137. >::apply(geometry1, geometry2, strategy);
  138. }
  139. };
  140. template <typename Geometry1, typename Geometry2, typename Tag2>
  141. struct touches<Geometry1, Geometry2, dynamic_geometry_tag, Tag2>
  142. {
  143. template <typename Strategy>
  144. static bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
  145. Strategy const& strategy)
  146. {
  147. bool result = false;
  148. traits::visit<Geometry1>::apply([&](auto const& g1)
  149. {
  150. result = touches
  151. <
  152. util::remove_cref_t<decltype(g1)>,
  153. Geometry2
  154. >::apply(g1, geometry2, strategy);
  155. }, geometry1);
  156. return result;
  157. }
  158. };
  159. template <typename Geometry1, typename Geometry2, typename Tag1>
  160. struct touches<Geometry1, Geometry2, Tag1, dynamic_geometry_tag>
  161. {
  162. template <typename Strategy>
  163. static bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
  164. Strategy const& strategy)
  165. {
  166. bool result = false;
  167. traits::visit<Geometry2>::apply([&](auto const& g2)
  168. {
  169. result = touches
  170. <
  171. Geometry1,
  172. util::remove_cref_t<decltype(g2)>
  173. >::apply(geometry1, g2, strategy);
  174. }, geometry2);
  175. return result;
  176. }
  177. };
  178. template <typename Geometry1, typename Geometry2>
  179. struct touches<Geometry1, Geometry2, dynamic_geometry_tag, dynamic_geometry_tag>
  180. {
  181. template <typename Strategy>
  182. static bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
  183. Strategy const& strategy)
  184. {
  185. bool result = false;
  186. traits::visit<Geometry1, Geometry2>::apply([&](auto const& g1, auto const& g2)
  187. {
  188. result = touches
  189. <
  190. util::remove_cref_t<decltype(g1)>,
  191. util::remove_cref_t<decltype(g2)>
  192. >::apply(g1, g2, strategy);
  193. }, geometry1, geometry2);
  194. return result;
  195. }
  196. };
  197. template <typename Geometry, typename Tag = typename geometry::tag<Geometry>::type>
  198. struct self_touches;
  199. template <typename Geometry>
  200. struct self_touches<Geometry, dynamic_geometry_tag>
  201. {
  202. static bool apply(Geometry const& geometry)
  203. {
  204. bool result = false;
  205. traits::visit<Geometry>::apply([&](auto const& g)
  206. {
  207. result = self_touches
  208. <
  209. util::remove_cref_t<decltype(g)>
  210. >::apply(g);
  211. }, geometry);
  212. return result;
  213. }
  214. };
  215. } // namespace resolve_dynamic
  216. /*!
  217. \brief \brief_check{has at least one touching point (self-tangency)}
  218. \note This function can be called for one geometry (self-tangency) and
  219. also for two geometries (touch)
  220. \ingroup touches
  221. \tparam Geometry \tparam_geometry
  222. \param geometry \param_geometry
  223. \return \return_check{is self-touching}
  224. \qbk{distinguish,one geometry}
  225. \qbk{[def __one_parameter__]}
  226. \qbk{[include reference/algorithms/touches.qbk]}
  227. \qbk{
  228. [heading Examples]
  229. [touches_one_geometry]
  230. [touches_one_geometry_output]
  231. }
  232. */
  233. template <typename Geometry>
  234. inline bool touches(Geometry const& geometry)
  235. {
  236. return resolve_dynamic::self_touches<Geometry>::apply(geometry);
  237. }
  238. /*!
  239. \brief \brief_check2{have at least one touching point (tangent - non overlapping)}
  240. \ingroup touches
  241. \tparam Geometry1 \tparam_geometry
  242. \tparam Geometry2 \tparam_geometry
  243. \param geometry1 \param_geometry
  244. \param geometry2 \param_geometry
  245. \return \return_check2{touch each other}
  246. \qbk{distinguish,two geometries}
  247. \qbk{[include reference/algorithms/touches.qbk]}
  248. \qbk{
  249. [heading Examples]
  250. [touches_two_geometries]
  251. [touches_two_geometries_output]
  252. }
  253. */
  254. template <typename Geometry1, typename Geometry2>
  255. inline bool touches(Geometry1 const& geometry1, Geometry2 const& geometry2)
  256. {
  257. return resolve_dynamic::touches
  258. <
  259. Geometry1, Geometry2
  260. >::apply(geometry1, geometry2, default_strategy());
  261. }
  262. /*!
  263. \brief \brief_check2{have at least one touching point (tangent - non overlapping)}
  264. \ingroup touches
  265. \tparam Geometry1 \tparam_geometry
  266. \tparam Geometry2 \tparam_geometry
  267. \tparam Strategy \tparam_strategy{Touches}
  268. \param geometry1 \param_geometry
  269. \param geometry2 \param_geometry
  270. \param strategy \param_strategy{touches}
  271. \return \return_check2{touch each other}
  272. \qbk{distinguish,with strategy}
  273. \qbk{[include reference/algorithms/touches.qbk]}
  274. */
  275. template <typename Geometry1, typename Geometry2, typename Strategy>
  276. inline bool touches(Geometry1 const& geometry1,
  277. Geometry2 const& geometry2,
  278. Strategy const& strategy)
  279. {
  280. return resolve_dynamic::touches
  281. <
  282. Geometry1, Geometry2
  283. >::apply(geometry1, geometry2, strategy);
  284. }
  285. }} // namespace boost::geometry
  286. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_TOUCHES_INTERFACE_HPP