interface.hpp 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. // This file was modified by Oracle on 2013-2021.
  6. // Modifications copyright (c) 2013-2021 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_COVERED_BY_INTERFACE_HPP
  14. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_COVERED_BY_INTERFACE_HPP
  15. #include <boost/geometry/algorithms/detail/within/interface.hpp>
  16. #include <boost/geometry/algorithms/not_implemented.hpp>
  17. #include <boost/geometry/strategies/default_strategy.hpp>
  18. #include <boost/geometry/strategies/detail.hpp>
  19. #include <boost/geometry/strategies/relate/services.hpp>
  20. namespace boost { namespace geometry
  21. {
  22. #ifndef DOXYGEN_NO_DISPATCH
  23. namespace dispatch
  24. {
  25. template
  26. <
  27. typename Geometry1,
  28. typename Geometry2,
  29. typename Tag1 = typename tag<Geometry1>::type,
  30. typename Tag2 = typename tag<Geometry2>::type
  31. >
  32. struct covered_by
  33. : not_implemented<Tag1, Tag2>
  34. {};
  35. } // namespace dispatch
  36. #endif // DOXYGEN_NO_DISPATCH
  37. namespace resolve_strategy {
  38. template
  39. <
  40. typename Strategy,
  41. bool IsUmbrella = strategies::detail::is_umbrella_strategy<Strategy>::value
  42. >
  43. struct covered_by
  44. {
  45. template <typename Geometry1, typename Geometry2>
  46. static inline bool apply(Geometry1 const& geometry1,
  47. Geometry2 const& geometry2,
  48. Strategy const& strategy)
  49. {
  50. concepts::within::check<Geometry1, Geometry2, Strategy>();
  51. concepts::check<Geometry1 const>();
  52. concepts::check<Geometry2 const>();
  53. assert_dimension_equal<Geometry1, Geometry2>();
  54. return dispatch::covered_by
  55. <
  56. Geometry1, Geometry2
  57. >::apply(geometry1, geometry2, strategy);
  58. }
  59. };
  60. template <typename Strategy>
  61. struct covered_by<Strategy, false>
  62. {
  63. template <typename Geometry1, typename Geometry2>
  64. static inline bool apply(Geometry1 const& geometry1,
  65. Geometry2 const& geometry2,
  66. Strategy const& strategy)
  67. {
  68. using strategies::relate::services::strategy_converter;
  69. return covered_by
  70. <
  71. decltype(strategy_converter<Strategy>::get(strategy))
  72. >::apply(geometry1, geometry2,
  73. strategy_converter<Strategy>::get(strategy));
  74. }
  75. };
  76. template <>
  77. struct covered_by<default_strategy, false>
  78. {
  79. template <typename Geometry1, typename Geometry2>
  80. static inline bool apply(Geometry1 const& geometry1,
  81. Geometry2 const& geometry2,
  82. default_strategy)
  83. {
  84. typedef typename strategies::relate::services::default_strategy
  85. <
  86. Geometry1,
  87. Geometry2
  88. >::type strategy_type;
  89. return covered_by
  90. <
  91. strategy_type
  92. >::apply(geometry1, geometry2, strategy_type());
  93. }
  94. };
  95. } // namespace resolve_strategy
  96. namespace resolve_dynamic {
  97. template
  98. <
  99. typename Geometry1, typename Geometry2,
  100. typename Tag1 = typename geometry::tag<Geometry1>::type,
  101. typename Tag2 = typename geometry::tag<Geometry2>::type
  102. >
  103. struct covered_by
  104. {
  105. template <typename Strategy>
  106. static inline bool apply(Geometry1 const& geometry1,
  107. Geometry2 const& geometry2,
  108. Strategy const& strategy)
  109. {
  110. return resolve_strategy::covered_by
  111. <
  112. Strategy
  113. >::apply(geometry1, geometry2, strategy);
  114. }
  115. };
  116. template <typename Geometry1, typename Geometry2, typename Tag2>
  117. struct covered_by<Geometry1, Geometry2, dynamic_geometry_tag, Tag2>
  118. {
  119. template <typename Strategy>
  120. static inline bool apply(Geometry1 const& geometry1,
  121. Geometry2 const& geometry2,
  122. Strategy const& strategy)
  123. {
  124. bool result = false;
  125. traits::visit<Geometry1>::apply([&](auto const& g1)
  126. {
  127. result = resolve_strategy::covered_by
  128. <
  129. Strategy
  130. >::apply(g1, geometry2, strategy);
  131. }, geometry1);
  132. return result;
  133. }
  134. };
  135. template <typename Geometry1, typename Geometry2, typename Tag1>
  136. struct covered_by<Geometry1, Geometry2, Tag1, dynamic_geometry_tag>
  137. {
  138. template <typename Strategy>
  139. static inline bool apply(Geometry1 const& geometry1,
  140. Geometry2 const& geometry2,
  141. Strategy const& strategy)
  142. {
  143. bool result = false;
  144. traits::visit<Geometry2>::apply([&](auto const& g2)
  145. {
  146. result = resolve_strategy::covered_by
  147. <
  148. Strategy
  149. >::apply(geometry1, g2, strategy);
  150. }, geometry2);
  151. return result;
  152. }
  153. };
  154. template <typename Geometry1, typename Geometry2>
  155. struct covered_by<Geometry1, Geometry2, dynamic_geometry_tag, dynamic_geometry_tag>
  156. {
  157. template <typename Strategy>
  158. static inline bool apply(Geometry1 const& geometry1,
  159. Geometry2 const& geometry2,
  160. Strategy const& strategy)
  161. {
  162. bool result = false;
  163. traits::visit<Geometry1, Geometry2>::apply([&](auto const& g1, auto const& g2)
  164. {
  165. result = resolve_strategy::covered_by
  166. <
  167. Strategy
  168. >::apply(g1, g2, strategy);
  169. }, geometry1, geometry2);
  170. return result;
  171. }
  172. };
  173. } // namespace resolve_dynamic
  174. /*!
  175. \brief \brief_check12{is inside or on border}
  176. \ingroup covered_by
  177. \details \details_check12{covered_by, is inside or on border}.
  178. \tparam Geometry1 \tparam_geometry
  179. \tparam Geometry2 \tparam_geometry
  180. \param geometry1 \param_geometry which might be inside or on the border of the second geometry
  181. \param geometry2 \param_geometry which might cover the first geometry
  182. \return true if geometry1 is inside of or on the border of geometry2,
  183. else false
  184. \note The default strategy is used for covered_by detection
  185. \qbk{[include reference/algorithms/covered_by.qbk]}
  186. \qbk{
  187. [heading Examples]
  188. [covered_by]
  189. [covered_by_output]
  190. }
  191. */
  192. template<typename Geometry1, typename Geometry2>
  193. inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2)
  194. {
  195. return resolve_dynamic::covered_by
  196. <
  197. Geometry1, Geometry2
  198. >::apply(geometry1, geometry2, default_strategy());
  199. }
  200. /*!
  201. \brief \brief_check12{is inside or on border} \brief_strategy
  202. \ingroup covered_by
  203. \details \details_check12{covered_by, is inside or on border}, \brief_strategy. \details_strategy_reasons
  204. \tparam Geometry1 \tparam_geometry
  205. \tparam Geometry2 \tparam_geometry
  206. \param geometry1 \param_geometry which might be inside or on the border of the second geometry
  207. \param geometry2 \param_geometry which might cover the first geometry
  208. \param strategy strategy to be used
  209. \return true if geometry1 is inside of or on the border of geometry2,
  210. else false
  211. \qbk{distinguish,with strategy}
  212. \qbk{[include reference/algorithms/covered_by.qbk]}
  213. */
  214. template<typename Geometry1, typename Geometry2, typename Strategy>
  215. inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2,
  216. Strategy const& strategy)
  217. {
  218. return resolve_dynamic::covered_by
  219. <
  220. Geometry1, Geometry2
  221. >::apply(geometry1, geometry2, strategy);
  222. }
  223. }} // namespace boost::geometry
  224. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_COVERED_BY_INTERFACE_HPP