crosses.hpp 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2014 Samuel Debionne, Grenoble, France.
  6. // This file was modified by Oracle on 2014-2020.
  7. // Modifications copyright (c) 2014-2020 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_CROSSES_HPP
  15. #define BOOST_GEOMETRY_ALGORITHMS_CROSSES_HPP
  16. #include <cstddef>
  17. #include <boost/variant/apply_visitor.hpp>
  18. #include <boost/variant/static_visitor.hpp>
  19. #include <boost/variant/variant_fwd.hpp>
  20. #include <boost/geometry/algorithms/relate.hpp>
  21. #include <boost/geometry/algorithms/detail/relate/relate_impl.hpp>
  22. #include <boost/geometry/core/access.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. {
  32. template
  33. <
  34. typename Geometry1,
  35. typename Geometry2,
  36. typename Tag1 = typename tag<Geometry1>::type,
  37. typename Tag2 = typename tag<Geometry2>::type
  38. >
  39. struct crosses
  40. : detail::relate::relate_impl
  41. <
  42. detail::de9im::static_mask_crosses_type,
  43. Geometry1,
  44. Geometry2
  45. >
  46. {};
  47. } // namespace dispatch
  48. #endif // DOXYGEN_NO_DISPATCH
  49. namespace resolve_strategy
  50. {
  51. template
  52. <
  53. typename Strategy,
  54. bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
  55. >
  56. struct crosses
  57. {
  58. template <typename Geometry1, typename Geometry2>
  59. static inline bool apply(Geometry1 const& geometry1,
  60. Geometry2 const& geometry2,
  61. Strategy const& strategy)
  62. {
  63. concepts::check<Geometry1 const>();
  64. concepts::check<Geometry2 const>();
  65. return dispatch::crosses
  66. <
  67. Geometry1, Geometry2
  68. >::apply(geometry1, geometry2, strategy);
  69. }
  70. };
  71. template <typename Strategy>
  72. struct crosses<Strategy, false>
  73. {
  74. template <typename Geometry1, typename Geometry2>
  75. static inline bool apply(Geometry1 const& geometry1,
  76. Geometry2 const& geometry2,
  77. Strategy const& strategy)
  78. {
  79. //using strategies::crosses::services::strategy_converter;
  80. using strategies::relate::services::strategy_converter;
  81. return crosses
  82. <
  83. decltype(strategy_converter<Strategy>::get(strategy))
  84. >::apply(geometry1, geometry2,
  85. strategy_converter<Strategy>::get(strategy));
  86. }
  87. };
  88. template <>
  89. struct crosses<default_strategy, false>
  90. {
  91. template <typename Geometry1, typename Geometry2>
  92. static inline bool apply(Geometry1 const& geometry1,
  93. Geometry2 const& geometry2,
  94. default_strategy)
  95. {
  96. //typedef typename strategies::crosses::services::default_strategy
  97. typedef typename strategies::relate::services::default_strategy
  98. <
  99. Geometry1,
  100. Geometry2
  101. >::type strategy_type;
  102. return crosses
  103. <
  104. strategy_type
  105. >::apply(geometry1, geometry2, strategy_type());
  106. }
  107. };
  108. } // namespace resolve_strategy
  109. namespace resolve_variant
  110. {
  111. template <typename Geometry1, typename Geometry2>
  112. struct crosses
  113. {
  114. template <typename Strategy>
  115. static inline bool apply(Geometry1 const& geometry1,
  116. Geometry2 const& geometry2,
  117. Strategy const& strategy)
  118. {
  119. return resolve_strategy::crosses
  120. <
  121. Strategy
  122. >::apply(geometry1, geometry2, strategy);
  123. }
  124. };
  125. template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
  126. struct crosses<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
  127. {
  128. template <typename Strategy>
  129. struct visitor: static_visitor<bool>
  130. {
  131. Geometry2 const& m_geometry2;
  132. Strategy const& m_strategy;
  133. visitor(Geometry2 const& geometry2, Strategy const& strategy)
  134. : m_geometry2(geometry2)
  135. , m_strategy(strategy)
  136. {}
  137. template <typename Geometry1>
  138. result_type operator()(Geometry1 const& geometry1) const
  139. {
  140. return crosses
  141. <
  142. Geometry1,
  143. Geometry2
  144. >::apply(geometry1, m_geometry2, m_strategy);
  145. }
  146. };
  147. template <typename Strategy>
  148. static inline bool apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
  149. Geometry2 const& geometry2,
  150. Strategy const& strategy)
  151. {
  152. return boost::apply_visitor(visitor<Strategy>(geometry2, strategy), geometry1);
  153. }
  154. };
  155. template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
  156. struct crosses<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  157. {
  158. template <typename Strategy>
  159. struct visitor: static_visitor<bool>
  160. {
  161. Geometry1 const& m_geometry1;
  162. Strategy const& m_strategy;
  163. visitor(Geometry1 const& geometry1, Strategy const& strategy)
  164. : m_geometry1(geometry1)
  165. , m_strategy(strategy)
  166. {}
  167. template <typename Geometry2>
  168. result_type operator()(Geometry2 const& geometry2) const
  169. {
  170. return crosses
  171. <
  172. Geometry1,
  173. Geometry2
  174. >::apply(m_geometry1, geometry2, m_strategy);
  175. }
  176. };
  177. template <typename Strategy>
  178. static inline bool apply(Geometry1 const& geometry1,
  179. variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
  180. Strategy const& strategy)
  181. {
  182. return boost::apply_visitor(visitor<Strategy>(geometry1, strategy), geometry2);
  183. }
  184. };
  185. template <BOOST_VARIANT_ENUM_PARAMS(typename T1), BOOST_VARIANT_ENUM_PARAMS(typename T2)>
  186. struct crosses<variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
  187. {
  188. template <typename Strategy>
  189. struct visitor: static_visitor<bool>
  190. {
  191. Strategy const& m_strategy;
  192. visitor(Strategy const& strategy)
  193. : m_strategy(strategy)
  194. {}
  195. template <typename Geometry1, typename Geometry2>
  196. result_type operator()(Geometry1 const& geometry1,
  197. Geometry2 const& geometry2) const
  198. {
  199. return crosses
  200. <
  201. Geometry1,
  202. Geometry2
  203. >::apply(geometry1, geometry2, m_strategy);
  204. }
  205. };
  206. template <typename Strategy>
  207. static inline bool apply(variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
  208. variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
  209. Strategy const& strategy)
  210. {
  211. return boost::apply_visitor(visitor<Strategy>(strategy), geometry1, geometry2);
  212. }
  213. };
  214. } // namespace resolve_variant
  215. /*!
  216. \brief \brief_check2{crosses}
  217. \ingroup crosses
  218. \tparam Geometry1 \tparam_geometry
  219. \tparam Geometry2 \tparam_geometry
  220. \tparam Strategy \tparam_strategy{Crosses}
  221. \param geometry1 \param_geometry
  222. \param geometry2 \param_geometry
  223. \param strategy \param_strategy{crosses}
  224. \return \return_check2{crosses}
  225. \qbk{distinguish,with strategy}
  226. \qbk{[include reference/algorithms/crosses.qbk]}
  227. */
  228. template <typename Geometry1, typename Geometry2, typename Strategy>
  229. inline bool crosses(Geometry1 const& geometry1,
  230. Geometry2 const& geometry2,
  231. Strategy const& strategy)
  232. {
  233. return resolve_variant::crosses
  234. <
  235. Geometry1, Geometry2
  236. >::apply(geometry1, geometry2, strategy);
  237. }
  238. /*!
  239. \brief \brief_check2{crosses}
  240. \ingroup crosses
  241. \tparam Geometry1 \tparam_geometry
  242. \tparam Geometry2 \tparam_geometry
  243. \param geometry1 \param_geometry
  244. \param geometry2 \param_geometry
  245. \return \return_check2{crosses}
  246. \qbk{[include reference/algorithms/crosses.qbk]}
  247. \qbk{
  248. [heading Examples]
  249. [crosses]
  250. [crosses_output]
  251. }
  252. */
  253. template <typename Geometry1, typename Geometry2>
  254. inline bool crosses(Geometry1 const& geometry1, Geometry2 const& geometry2)
  255. {
  256. return resolve_variant::crosses
  257. <
  258. Geometry1, Geometry2
  259. >::apply(geometry1, geometry2, default_strategy());
  260. }
  261. }} // namespace boost::geometry
  262. #endif // BOOST_GEOMETRY_ALGORITHMS_CROSSES_HPP