crosses.hpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  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, 2017.
  7. // Modifications copyright (c) 2014-2017 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. namespace boost { namespace geometry
  26. {
  27. #ifndef DOXYGEN_NO_DISPATCH
  28. namespace dispatch
  29. {
  30. template
  31. <
  32. typename Geometry1,
  33. typename Geometry2,
  34. typename Tag1 = typename tag<Geometry1>::type,
  35. typename Tag2 = typename tag<Geometry2>::type
  36. >
  37. struct crosses
  38. : detail::relate::relate_impl
  39. <
  40. detail::de9im::static_mask_crosses_type,
  41. Geometry1,
  42. Geometry2
  43. >
  44. {};
  45. } // namespace dispatch
  46. #endif // DOXYGEN_NO_DISPATCH
  47. namespace resolve_strategy
  48. {
  49. struct crosses
  50. {
  51. template <typename Geometry1, typename Geometry2, typename Strategy>
  52. static inline bool apply(Geometry1 const& geometry1,
  53. Geometry2 const& geometry2,
  54. Strategy const& strategy)
  55. {
  56. concepts::check<Geometry1 const>();
  57. concepts::check<Geometry2 const>();
  58. return dispatch::crosses<Geometry1, Geometry2>::apply(geometry1, geometry2, strategy);
  59. }
  60. template <typename Geometry1, typename Geometry2>
  61. static inline bool apply(Geometry1 const& geometry1,
  62. Geometry2 const& geometry2,
  63. default_strategy)
  64. {
  65. typedef typename strategy::relate::services::default_strategy
  66. <
  67. Geometry1,
  68. Geometry2
  69. >::type strategy_type;
  70. return apply(geometry1, geometry2, strategy_type());
  71. }
  72. };
  73. } // namespace resolve_strategy
  74. namespace resolve_variant
  75. {
  76. template <typename Geometry1, typename Geometry2>
  77. struct crosses
  78. {
  79. template <typename Strategy>
  80. static inline bool apply(Geometry1 const& geometry1,
  81. Geometry2 const& geometry2,
  82. Strategy const& strategy)
  83. {
  84. return resolve_strategy::crosses::apply(geometry1, geometry2, strategy);
  85. }
  86. };
  87. template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
  88. struct crosses<variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
  89. {
  90. template <typename Strategy>
  91. struct visitor: static_visitor<bool>
  92. {
  93. Geometry2 const& m_geometry2;
  94. Strategy const& m_strategy;
  95. visitor(Geometry2 const& geometry2, Strategy const& strategy)
  96. : m_geometry2(geometry2)
  97. , m_strategy(strategy)
  98. {}
  99. template <typename Geometry1>
  100. result_type operator()(Geometry1 const& geometry1) const
  101. {
  102. return crosses
  103. <
  104. Geometry1,
  105. Geometry2
  106. >::apply(geometry1, m_geometry2, m_strategy);
  107. }
  108. };
  109. template <typename Strategy>
  110. static inline bool apply(variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
  111. Geometry2 const& geometry2,
  112. Strategy const& strategy)
  113. {
  114. return boost::apply_visitor(visitor<Strategy>(geometry2, strategy), geometry1);
  115. }
  116. };
  117. template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
  118. struct crosses<Geometry1, variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  119. {
  120. template <typename Strategy>
  121. struct visitor: static_visitor<bool>
  122. {
  123. Geometry1 const& m_geometry1;
  124. Strategy const& m_strategy;
  125. visitor(Geometry1 const& geometry1, Strategy const& strategy)
  126. : m_geometry1(geometry1)
  127. , m_strategy(strategy)
  128. {}
  129. template <typename Geometry2>
  130. result_type operator()(Geometry2 const& geometry2) const
  131. {
  132. return crosses
  133. <
  134. Geometry1,
  135. Geometry2
  136. >::apply(m_geometry1, geometry2, m_strategy);
  137. }
  138. };
  139. template <typename Strategy>
  140. static inline bool apply(Geometry1 const& geometry1,
  141. variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
  142. Strategy const& strategy)
  143. {
  144. return boost::apply_visitor(visitor<Strategy>(geometry1, strategy), geometry2);
  145. }
  146. };
  147. template <BOOST_VARIANT_ENUM_PARAMS(typename T1), BOOST_VARIANT_ENUM_PARAMS(typename T2)>
  148. struct crosses<variant<BOOST_VARIANT_ENUM_PARAMS(T1)>, variant<BOOST_VARIANT_ENUM_PARAMS(T2)> >
  149. {
  150. template <typename Strategy>
  151. struct visitor: static_visitor<bool>
  152. {
  153. Strategy const& m_strategy;
  154. visitor(Strategy const& strategy)
  155. : m_strategy(strategy)
  156. {}
  157. template <typename Geometry1, typename Geometry2>
  158. result_type operator()(Geometry1 const& geometry1,
  159. Geometry2 const& geometry2) const
  160. {
  161. return crosses
  162. <
  163. Geometry1,
  164. Geometry2
  165. >::apply(geometry1, geometry2, m_strategy);
  166. }
  167. };
  168. template <typename Strategy>
  169. static inline bool apply(variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
  170. variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
  171. Strategy const& strategy)
  172. {
  173. return boost::apply_visitor(visitor<Strategy>(strategy), geometry1, geometry2);
  174. }
  175. };
  176. } // namespace resolve_variant
  177. /*!
  178. \brief \brief_check2{crosses}
  179. \ingroup crosses
  180. \tparam Geometry1 \tparam_geometry
  181. \tparam Geometry2 \tparam_geometry
  182. \tparam Strategy \tparam_strategy{Crosses}
  183. \param geometry1 \param_geometry
  184. \param geometry2 \param_geometry
  185. \param strategy \param_strategy{crosses}
  186. \return \return_check2{crosses}
  187. \qbk{distinguish,with strategy}
  188. \qbk{[include reference/algorithms/crosses.qbk]}
  189. */
  190. template <typename Geometry1, typename Geometry2, typename Strategy>
  191. inline bool crosses(Geometry1 const& geometry1,
  192. Geometry2 const& geometry2,
  193. Strategy const& strategy)
  194. {
  195. return resolve_variant::crosses
  196. <
  197. Geometry1, Geometry2
  198. >::apply(geometry1, geometry2, strategy);
  199. }
  200. /*!
  201. \brief \brief_check2{crosses}
  202. \ingroup crosses
  203. \tparam Geometry1 \tparam_geometry
  204. \tparam Geometry2 \tparam_geometry
  205. \param geometry1 \param_geometry
  206. \param geometry2 \param_geometry
  207. \return \return_check2{crosses}
  208. \qbk{[include reference/algorithms/crosses.qbk]}
  209. */
  210. template <typename Geometry1, typename Geometry2>
  211. inline bool crosses(Geometry1 const& geometry1, Geometry2 const& geometry2)
  212. {
  213. return resolve_variant::crosses
  214. <
  215. Geometry1, Geometry2
  216. >::apply(geometry1, geometry2, default_strategy());
  217. }
  218. }} // namespace boost::geometry
  219. #endif // BOOST_GEOMETRY_ALGORITHMS_CROSSES_HPP