interface.hpp 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2014 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2014 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2014 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2013-2014 Adam Wulkiewicz, Lodz, Poland.
  6. // This file was modified by Oracle on 2013-2021.
  7. // Modifications copyright (c) 2013-2021, Oracle and/or its affiliates.
  8. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  9. // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
  10. // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
  11. // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
  12. // Use, modification and distribution is subject to the Boost Software License,
  13. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  14. // http://www.boost.org/LICENSE_1_0.txt)
  15. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_INTERFACE_HPP
  16. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_INTERFACE_HPP
  17. #include <cstddef>
  18. #include <boost/geometry/algorithms/detail/relate/interface.hpp>
  19. #include <boost/geometry/algorithms/detail/visit.hpp>
  20. #include <boost/geometry/algorithms/dispatch/disjoint.hpp>
  21. #include <boost/geometry/geometries/adapted/boost_variant.hpp> // For backward compatibility
  22. #include <boost/geometry/geometries/concepts/check.hpp>
  23. #include <boost/geometry/strategies/default_strategy.hpp>
  24. #include <boost/geometry/strategies/detail.hpp>
  25. #include <boost/geometry/strategies/relate/services.hpp>
  26. namespace boost { namespace geometry
  27. {
  28. namespace resolve_strategy
  29. {
  30. template
  31. <
  32. typename Strategy,
  33. bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
  34. >
  35. struct disjoint
  36. {
  37. template <typename Geometry1, typename Geometry2>
  38. static inline bool apply(Geometry1 const& geometry1,
  39. Geometry2 const& geometry2,
  40. Strategy const& strategy)
  41. {
  42. return dispatch::disjoint
  43. <
  44. Geometry1, Geometry2
  45. >::apply(geometry1, geometry2, strategy);
  46. }
  47. };
  48. template <typename Strategy>
  49. struct disjoint<Strategy, false>
  50. {
  51. template <typename Geometry1, typename Geometry2>
  52. static inline bool apply(Geometry1 const& geometry1,
  53. Geometry2 const& geometry2,
  54. Strategy const& strategy)
  55. {
  56. using strategies::relate::services::strategy_converter;
  57. return dispatch::disjoint
  58. <
  59. Geometry1, Geometry2
  60. >::apply(geometry1, geometry2,
  61. strategy_converter<Strategy>::get(strategy));
  62. }
  63. };
  64. template <>
  65. struct disjoint<default_strategy, false>
  66. {
  67. template <typename Geometry1, typename Geometry2>
  68. static inline bool apply(Geometry1 const& geometry1,
  69. Geometry2 const& geometry2,
  70. default_strategy)
  71. {
  72. typedef typename strategies::relate::services::default_strategy
  73. <
  74. Geometry1, Geometry2
  75. >::type strategy_type;
  76. return dispatch::disjoint
  77. <
  78. Geometry1, Geometry2
  79. >::apply(geometry1, geometry2, strategy_type());
  80. }
  81. };
  82. } // namespace resolve_strategy
  83. namespace resolve_dynamic {
  84. template
  85. <
  86. typename Geometry1, typename Geometry2,
  87. bool IsDynamic = util::is_dynamic_geometry<Geometry1>::value
  88. || util::is_dynamic_geometry<Geometry2>::value,
  89. bool IsCollection = util::is_geometry_collection<Geometry1>::value
  90. || util::is_geometry_collection<Geometry2>::value
  91. >
  92. struct disjoint
  93. {
  94. template <typename Strategy>
  95. static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
  96. Strategy const& strategy)
  97. {
  98. concepts::check_concepts_and_equal_dimensions
  99. <
  100. Geometry1 const,
  101. Geometry2 const
  102. >();
  103. return resolve_strategy::disjoint
  104. <
  105. Strategy
  106. >::apply(geometry1, geometry2, strategy);
  107. }
  108. };
  109. template <typename Geometry1, typename Geometry2>
  110. struct disjoint<Geometry1, Geometry2, true, false>
  111. {
  112. template <typename Strategy>
  113. static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
  114. Strategy const& strategy)
  115. {
  116. bool result = true;
  117. detail::visit([&](auto const& g1, auto const& g2)
  118. {
  119. result = disjoint
  120. <
  121. util::remove_cref_t<decltype(g1)>, util::remove_cref_t<decltype(g2)>
  122. >::apply(g1, g2, strategy);
  123. }, geometry1, geometry2);
  124. return result;
  125. }
  126. };
  127. // TODO: The complexity is quadratic for two GCs
  128. // Decrease e.g. with spatial index
  129. template <typename Geometry1, typename Geometry2, bool IsDynamic>
  130. struct disjoint<Geometry1, Geometry2, IsDynamic, true>
  131. {
  132. template <typename Strategy>
  133. static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2,
  134. Strategy const& strategy)
  135. {
  136. bool result = true;
  137. detail::visit_breadth_first([&](auto const& g1)
  138. {
  139. detail::visit_breadth_first([&](auto const& g2)
  140. {
  141. result = disjoint
  142. <
  143. util::remove_cref_t<decltype(g1)>, util::remove_cref_t<decltype(g2)>
  144. >::apply(g1, g2, strategy);
  145. // If any of the combination intersects then the final result is not disjoint
  146. return result;
  147. }, geometry2);
  148. return result;
  149. }, geometry1);
  150. return result;
  151. }
  152. };
  153. } // namespace resolve_dynamic
  154. /*!
  155. \brief \brief_check2{are disjoint}
  156. \ingroup disjoint
  157. \tparam Geometry1 \tparam_geometry
  158. \tparam Geometry2 \tparam_geometry
  159. \tparam Strategy \tparam_strategy{Disjoint}
  160. \param geometry1 \param_geometry
  161. \param geometry2 \param_geometry
  162. \param strategy \param_strategy{disjoint}
  163. \return \return_check2{are disjoint}
  164. \qbk{distinguish,with strategy}
  165. \qbk{[include reference/algorithms/disjoint.qbk]}
  166. */
  167. template <typename Geometry1, typename Geometry2, typename Strategy>
  168. inline bool disjoint(Geometry1 const& geometry1,
  169. Geometry2 const& geometry2,
  170. Strategy const& strategy)
  171. {
  172. return resolve_dynamic::disjoint
  173. <
  174. Geometry1, Geometry2
  175. >::apply(geometry1, geometry2, strategy);
  176. }
  177. /*!
  178. \brief \brief_check2{are disjoint}
  179. \ingroup disjoint
  180. \tparam Geometry1 \tparam_geometry
  181. \tparam Geometry2 \tparam_geometry
  182. \param geometry1 \param_geometry
  183. \param geometry2 \param_geometry
  184. \return \return_check2{are disjoint}
  185. \qbk{[include reference/algorithms/disjoint.qbk]}
  186. \qbk{
  187. [heading Examples]
  188. [disjoint]
  189. [disjoint_output]
  190. }
  191. */
  192. template <typename Geometry1, typename Geometry2>
  193. inline bool disjoint(Geometry1 const& geometry1,
  194. Geometry2 const& geometry2)
  195. {
  196. return resolve_dynamic::disjoint
  197. <
  198. Geometry1, Geometry2
  199. >::apply(geometry1, geometry2, default_strategy());
  200. }
  201. }} // namespace boost::geometry
  202. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_DISJOINT_INTERFACE_HPP