interface.hpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  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. // This file was modified by Oracle on 2014-2022.
  6. // Modifications copyright (c) 2014-2022 Oracle and/or its affiliates.
  7. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  8. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  9. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  10. // Use, modification and distribution is subject to the Boost Software License,
  11. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  12. // http://www.boost.org/LICENSE_1_0.txt)
  13. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAPS_INTERFACE_HPP
  14. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAPS_INTERFACE_HPP
  15. #include <cstddef>
  16. #include <boost/geometry/algorithms/not_implemented.hpp>
  17. #include <boost/geometry/geometries/adapted/boost_variant.hpp>
  18. #include <boost/geometry/geometries/concepts/check.hpp>
  19. #include <boost/geometry/algorithms/detail/relate/relate_impl.hpp>
  20. #include <boost/geometry/strategies/default_strategy.hpp>
  21. #include <boost/geometry/strategies/detail.hpp>
  22. #include <boost/geometry/strategies/relate/services.hpp>
  23. namespace boost { namespace geometry
  24. {
  25. #ifndef DOXYGEN_NO_DISPATCH
  26. namespace dispatch
  27. {
  28. template
  29. <
  30. typename Geometry1,
  31. typename Geometry2,
  32. typename Tag1 = typename tag<Geometry1>::type,
  33. typename Tag2 = typename tag<Geometry2>::type
  34. >
  35. struct overlaps
  36. : detail::relate::relate_impl
  37. <
  38. detail::de9im::static_mask_overlaps_type,
  39. Geometry1,
  40. Geometry2
  41. >
  42. {};
  43. } // namespace dispatch
  44. #endif // DOXYGEN_NO_DISPATCH
  45. namespace resolve_strategy
  46. {
  47. template
  48. <
  49. typename Strategy,
  50. bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
  51. >
  52. struct overlaps
  53. {
  54. template <typename Geometry1, typename Geometry2>
  55. static inline bool apply(Geometry1 const& geometry1,
  56. Geometry2 const& geometry2,
  57. Strategy const& strategy)
  58. {
  59. return dispatch::overlaps
  60. <
  61. Geometry1, Geometry2
  62. >::apply(geometry1, geometry2, strategy);
  63. }
  64. };
  65. template <typename Strategy>
  66. struct overlaps<Strategy, false>
  67. {
  68. template <typename Geometry1, typename Geometry2>
  69. static inline bool apply(Geometry1 const& geometry1,
  70. Geometry2 const& geometry2,
  71. Strategy const& strategy)
  72. {
  73. using strategies::relate::services::strategy_converter;
  74. return dispatch::overlaps
  75. <
  76. Geometry1, Geometry2
  77. >::apply(geometry1, geometry2,
  78. strategy_converter<Strategy>::get(strategy));
  79. }
  80. };
  81. template <>
  82. struct overlaps<default_strategy, false>
  83. {
  84. template <typename Geometry1, typename Geometry2>
  85. static inline bool apply(Geometry1 const& geometry1,
  86. Geometry2 const& geometry2,
  87. default_strategy)
  88. {
  89. typedef typename strategies::relate::services::default_strategy
  90. <
  91. Geometry1, Geometry2
  92. >::type strategy_type;
  93. return dispatch::overlaps
  94. <
  95. Geometry1, Geometry2
  96. >::apply(geometry1, geometry2, strategy_type());
  97. }
  98. };
  99. } // namespace resolve_strategy
  100. namespace resolve_dynamic
  101. {
  102. template
  103. <
  104. typename Geometry1, typename Geometry2,
  105. typename Tag1 = typename geometry::tag<Geometry1>::type,
  106. typename Tag2 = typename geometry::tag<Geometry2>::type
  107. >
  108. struct overlaps
  109. {
  110. template <typename Strategy>
  111. static inline bool apply(Geometry1 const& geometry1,
  112. Geometry2 const& geometry2,
  113. Strategy const& strategy)
  114. {
  115. return resolve_strategy::overlaps
  116. <
  117. Strategy
  118. >::apply(geometry1, geometry2, strategy);
  119. }
  120. };
  121. template <typename DynamicGeometry1, typename Geometry2, typename Tag2>
  122. struct overlaps<DynamicGeometry1, Geometry2, dynamic_geometry_tag, Tag2>
  123. {
  124. template <typename Strategy>
  125. static inline bool apply(DynamicGeometry1 const& geometry1,
  126. Geometry2 const& geometry2,
  127. Strategy const& strategy)
  128. {
  129. bool result = false;
  130. traits::visit<DynamicGeometry1>::apply([&](auto const& g1)
  131. {
  132. result = resolve_strategy::overlaps
  133. <
  134. Strategy
  135. >::apply(g1, geometry2, strategy);
  136. }, geometry1);
  137. return result;
  138. }
  139. };
  140. template <typename Geometry1, typename DynamicGeometry2, typename Tag1>
  141. struct overlaps<Geometry1, DynamicGeometry2, Tag1, dynamic_geometry_tag>
  142. {
  143. template <typename Strategy>
  144. static inline bool apply(Geometry1 const& geometry1,
  145. DynamicGeometry2 const& geometry2,
  146. Strategy const& strategy)
  147. {
  148. bool result = false;
  149. traits::visit<DynamicGeometry2>::apply([&](auto const& g2)
  150. {
  151. result = resolve_strategy::overlaps
  152. <
  153. Strategy
  154. >::apply(geometry1, g2, strategy);
  155. }, geometry2);
  156. return result;
  157. }
  158. };
  159. template <typename DynamicGeometry1, typename DynamicGeometry2>
  160. struct overlaps<DynamicGeometry1, DynamicGeometry2, dynamic_geometry_tag, dynamic_geometry_tag>
  161. {
  162. template <typename Strategy>
  163. static inline bool apply(DynamicGeometry1 const& geometry1,
  164. DynamicGeometry2 const& geometry2,
  165. Strategy const& strategy)
  166. {
  167. bool result = false;
  168. traits::visit<DynamicGeometry1, DynamicGeometry2>::apply([&](auto const& g1, auto const& g2)
  169. {
  170. result = resolve_strategy::overlaps
  171. <
  172. Strategy
  173. >::apply(g1, g2, strategy);
  174. }, geometry1, geometry2);
  175. return result;
  176. }
  177. };
  178. } // namespace resolve_dynamic
  179. /*!
  180. \brief \brief_check2{overlap}
  181. \ingroup overlaps
  182. \tparam Geometry1 \tparam_geometry
  183. \tparam Geometry2 \tparam_geometry
  184. \tparam Strategy \tparam_strategy{Overlaps}
  185. \param geometry1 \param_geometry
  186. \param geometry2 \param_geometry
  187. \param strategy \param_strategy{overlaps}
  188. \return \return_check2{overlap}
  189. \qbk{distinguish,with strategy}
  190. \qbk{[include reference/algorithms/overlaps.qbk]}
  191. */
  192. template <typename Geometry1, typename Geometry2, typename Strategy>
  193. inline bool overlaps(Geometry1 const& geometry1,
  194. Geometry2 const& geometry2,
  195. Strategy const& strategy)
  196. {
  197. concepts::check<Geometry1 const>();
  198. concepts::check<Geometry2 const>();
  199. return resolve_dynamic::overlaps
  200. <
  201. Geometry1, Geometry2
  202. >::apply(geometry1, geometry2, strategy);
  203. }
  204. /*!
  205. \brief \brief_check2{overlap}
  206. \ingroup overlaps
  207. \tparam Geometry1 \tparam_geometry
  208. \tparam Geometry2 \tparam_geometry
  209. \param geometry1 \param_geometry
  210. \param geometry2 \param_geometry
  211. \return \return_check2{overlap}
  212. \qbk{[include reference/algorithms/overlaps.qbk]}
  213. \qbk{
  214. [heading Examples]
  215. [overlaps]
  216. [overlaps_output]
  217. }
  218. */
  219. template <typename Geometry1, typename Geometry2>
  220. inline bool overlaps(Geometry1 const& geometry1, Geometry2 const& geometry2)
  221. {
  222. concepts::check<Geometry1 const>();
  223. concepts::check<Geometry2 const>();
  224. return resolve_dynamic::overlaps
  225. <
  226. Geometry1, Geometry2
  227. >::apply(geometry1, geometry2, default_strategy());
  228. }
  229. }} // namespace boost::geometry
  230. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_OVERLAPS_INTERFACE_HPP