interface.hpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  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, 2014, 2017, 2018.
  6. // Modifications copyright (c) 2013-2018 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/variant/apply_visitor.hpp>
  16. #include <boost/variant/static_visitor.hpp>
  17. #include <boost/variant/variant_fwd.hpp>
  18. #include <boost/geometry/algorithms/detail/within/interface.hpp>
  19. #include <boost/geometry/algorithms/not_implemented.hpp>
  20. #include <boost/geometry/strategies/cartesian/point_in_box.hpp>
  21. #include <boost/geometry/strategies/cartesian/box_in_box.hpp>
  22. #include <boost/geometry/strategies/default_strategy.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 covered_by
  36. : not_implemented<Tag1, Tag2>
  37. {};
  38. } // namespace dispatch
  39. #endif // DOXYGEN_NO_DISPATCH
  40. namespace resolve_strategy {
  41. struct covered_by
  42. {
  43. template <typename Geometry1, typename Geometry2, typename Strategy>
  44. static inline bool apply(Geometry1 const& geometry1,
  45. Geometry2 const& geometry2,
  46. Strategy const& strategy)
  47. {
  48. concepts::within::check<Geometry1, Geometry2, Strategy>();
  49. concepts::check<Geometry1 const>();
  50. concepts::check<Geometry2 const>();
  51. assert_dimension_equal<Geometry1, Geometry2>();
  52. return dispatch::covered_by<Geometry1, Geometry2>::apply(geometry1,
  53. geometry2,
  54. strategy);
  55. }
  56. template <typename Geometry1, typename Geometry2>
  57. static inline bool apply(Geometry1 const& geometry1,
  58. Geometry2 const& geometry2,
  59. default_strategy)
  60. {
  61. typedef typename strategy::covered_by::services::default_strategy
  62. <
  63. Geometry1,
  64. Geometry2
  65. >::type strategy_type;
  66. return covered_by::apply(geometry1, geometry2, strategy_type());
  67. }
  68. };
  69. } // namespace resolve_strategy
  70. namespace resolve_variant {
  71. template <typename Geometry1, typename Geometry2>
  72. struct covered_by
  73. {
  74. template <typename Strategy>
  75. static inline bool apply(Geometry1 const& geometry1,
  76. Geometry2 const& geometry2,
  77. Strategy const& strategy)
  78. {
  79. return resolve_strategy::covered_by
  80. ::apply(geometry1, geometry2, strategy);
  81. }
  82. };
  83. template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
  84. struct covered_by<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
  85. {
  86. template <typename Strategy>
  87. struct visitor: boost::static_visitor<bool>
  88. {
  89. Geometry2 const& m_geometry2;
  90. Strategy const& m_strategy;
  91. visitor(Geometry2 const& geometry2, Strategy const& strategy)
  92. : m_geometry2(geometry2), m_strategy(strategy) {}
  93. template <typename Geometry1>
  94. bool operator()(Geometry1 const& geometry1) const
  95. {
  96. return covered_by<Geometry1, Geometry2>
  97. ::apply(geometry1, m_geometry2, m_strategy);
  98. }
  99. };
  100. template <typename Strategy>
  101. static inline bool
  102. apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
  103. Geometry2 const& geometry2,
  104. Strategy const& strategy)
  105. {
  106. return boost::apply_visitor(visitor<Strategy>(geometry2, strategy), geometry1);
  107. }
  108. };
  109. template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
  110. struct covered_by<Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  111. {
  112. template <typename Strategy>
  113. struct visitor: boost::static_visitor<bool>
  114. {
  115. Geometry1 const& m_geometry1;
  116. Strategy const& m_strategy;
  117. visitor(Geometry1 const& geometry1, Strategy const& strategy)
  118. : m_geometry1(geometry1), m_strategy(strategy) {}
  119. template <typename Geometry2>
  120. bool operator()(Geometry2 const& geometry2) const
  121. {
  122. return covered_by<Geometry1, Geometry2>
  123. ::apply(m_geometry1, geometry2, m_strategy);
  124. }
  125. };
  126. template <typename Strategy>
  127. static inline bool
  128. apply(Geometry1 const& geometry1,
  129. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
  130. Strategy const& strategy)
  131. {
  132. return boost::apply_visitor(visitor<Strategy>(geometry1, strategy), geometry2);
  133. }
  134. };
  135. template <
  136. BOOST_VARIANT_ENUM_PARAMS(typename T1),
  137. BOOST_VARIANT_ENUM_PARAMS(typename T2)
  138. >
  139. struct covered_by<
  140. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
  141. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>
  142. >
  143. {
  144. template <typename Strategy>
  145. struct visitor: boost::static_visitor<bool>
  146. {
  147. Strategy const& m_strategy;
  148. visitor(Strategy const& strategy): m_strategy(strategy) {}
  149. template <typename Geometry1, typename Geometry2>
  150. bool operator()(Geometry1 const& geometry1,
  151. Geometry2 const& geometry2) const
  152. {
  153. return covered_by<Geometry1, Geometry2>
  154. ::apply(geometry1, geometry2, m_strategy);
  155. }
  156. };
  157. template <typename Strategy>
  158. static inline bool
  159. apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
  160. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
  161. Strategy const& strategy)
  162. {
  163. return boost::apply_visitor(visitor<Strategy>(strategy), geometry1, geometry2);
  164. }
  165. };
  166. } // namespace resolve_variant
  167. /*!
  168. \brief \brief_check12{is inside or on border}
  169. \ingroup covered_by
  170. \details \details_check12{covered_by, is inside or on border}.
  171. \tparam Geometry1 \tparam_geometry
  172. \tparam Geometry2 \tparam_geometry
  173. \param geometry1 \param_geometry which might be inside or on the border of the second geometry
  174. \param geometry2 \param_geometry which might cover the first geometry
  175. \return true if geometry1 is inside of or on the border of geometry2,
  176. else false
  177. \note The default strategy is used for covered_by detection
  178. \qbk{[include reference/algorithms/covered_by.qbk]}
  179. */
  180. template<typename Geometry1, typename Geometry2>
  181. inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2)
  182. {
  183. return resolve_variant::covered_by<Geometry1, Geometry2>
  184. ::apply(geometry1, geometry2, default_strategy());
  185. }
  186. /*!
  187. \brief \brief_check12{is inside or on border} \brief_strategy
  188. \ingroup covered_by
  189. \details \details_check12{covered_by, is inside or on border}, \brief_strategy. \details_strategy_reasons
  190. \tparam Geometry1 \tparam_geometry
  191. \tparam Geometry2 \tparam_geometry
  192. \param geometry1 \param_geometry which might be inside or on the border of the second geometry
  193. \param geometry2 \param_geometry which might cover the first geometry
  194. \param strategy strategy to be used
  195. \return true if geometry1 is inside of or on the border of geometry2,
  196. else false
  197. \qbk{distinguish,with strategy}
  198. \qbk{[include reference/algorithms/covered_by.qbk]}
  199. */
  200. template<typename Geometry1, typename Geometry2, typename Strategy>
  201. inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2,
  202. Strategy const& strategy)
  203. {
  204. return resolve_variant::covered_by<Geometry1, Geometry2>
  205. ::apply(geometry1, geometry2, strategy);
  206. }
  207. }} // namespace boost::geometry
  208. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_COVERED_BY_INTERFACE_HPP