interface.hpp 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // This file was modified by Oracle on 2013, 2014, 2015, 2017.
  4. // Modifications copyright (c) 2013-2017 Oracle and/or its affiliates.
  5. // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
  6. // Use, modification and distribution is subject to the Boost Software License,
  7. // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
  8. // http://www.boost.org/LICENSE_1_0.txt)
  9. #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATION_INTERFACE_HPP
  10. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATION_INTERFACE_HPP
  11. #include <boost/geometry/algorithms/detail/relate/interface.hpp>
  12. namespace boost { namespace geometry
  13. {
  14. #ifndef DOXYGEN_NO_DETAIL
  15. namespace detail { namespace relate
  16. {
  17. template <typename Geometry1, typename Geometry2>
  18. struct result_handler_type<Geometry1, Geometry2, geometry::de9im::matrix, false>
  19. {
  20. typedef matrix_handler<geometry::de9im::matrix> type;
  21. };
  22. }} // namespace detail::relate
  23. #endif // DOXYGEN_NO_DETAIL
  24. namespace resolve_variant
  25. {
  26. template <typename Geometry1, typename Geometry2>
  27. struct relation
  28. {
  29. template <typename Matrix, typename Strategy>
  30. static inline Matrix apply(Geometry1 const& geometry1,
  31. Geometry2 const& geometry2,
  32. Strategy const& strategy)
  33. {
  34. concepts::check<Geometry1 const>();
  35. concepts::check<Geometry2 const>();
  36. assert_dimension_equal<Geometry1, Geometry2>();
  37. typename detail::relate::result_handler_type
  38. <
  39. Geometry1,
  40. Geometry2,
  41. Matrix
  42. >::type handler;
  43. resolve_strategy::relate::apply(geometry1, geometry2, handler, strategy);
  44. return handler.result();
  45. }
  46. };
  47. template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
  48. struct relation<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
  49. {
  50. template <typename Matrix, typename Strategy>
  51. struct visitor : boost::static_visitor<Matrix>
  52. {
  53. Geometry2 const& m_geometry2;
  54. Strategy const& m_strategy;
  55. visitor(Geometry2 const& geometry2, Strategy const& strategy)
  56. : m_geometry2(geometry2), m_strategy(strategy) {}
  57. template <typename Geometry1>
  58. Matrix operator()(Geometry1 const& geometry1) const
  59. {
  60. return relation<Geometry1, Geometry2>
  61. ::template apply<Matrix>(geometry1, m_geometry2, m_strategy);
  62. }
  63. };
  64. template <typename Matrix, typename Strategy>
  65. static inline Matrix
  66. apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
  67. Geometry2 const& geometry2,
  68. Strategy const& strategy)
  69. {
  70. return boost::apply_visitor(visitor<Matrix, Strategy>(geometry2, strategy), geometry1);
  71. }
  72. };
  73. template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
  74. struct relation<Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  75. {
  76. template <typename Matrix, typename Strategy>
  77. struct visitor : boost::static_visitor<Matrix>
  78. {
  79. Geometry1 const& m_geometry1;
  80. Strategy const& m_strategy;
  81. visitor(Geometry1 const& geometry1, Strategy const& strategy)
  82. : m_geometry1(geometry1), m_strategy(strategy) {}
  83. template <typename Geometry2>
  84. Matrix operator()(Geometry2 const& geometry2) const
  85. {
  86. return relation<Geometry1, Geometry2>
  87. ::template apply<Matrix>(m_geometry1, geometry2, m_strategy);
  88. }
  89. };
  90. template <typename Matrix, typename Strategy>
  91. static inline Matrix
  92. apply(Geometry1 const& geometry1,
  93. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
  94. Strategy const& strategy)
  95. {
  96. return boost::apply_visitor(visitor<Matrix, Strategy>(geometry1, strategy), geometry2);
  97. }
  98. };
  99. template
  100. <
  101. BOOST_VARIANT_ENUM_PARAMS(typename T1),
  102. BOOST_VARIANT_ENUM_PARAMS(typename T2)
  103. >
  104. struct relation
  105. <
  106. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
  107. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>
  108. >
  109. {
  110. template <typename Matrix, typename Strategy>
  111. struct visitor : boost::static_visitor<Matrix>
  112. {
  113. Strategy const& m_strategy;
  114. visitor(Strategy const& strategy)
  115. : m_strategy(strategy) {}
  116. template <typename Geometry1, typename Geometry2>
  117. Matrix operator()(Geometry1 const& geometry1,
  118. Geometry2 const& geometry2) const
  119. {
  120. return relation<Geometry1, Geometry2>
  121. ::template apply<Matrix>(geometry1, geometry2, m_strategy);
  122. }
  123. };
  124. template <typename Matrix, typename Strategy>
  125. static inline Matrix
  126. apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
  127. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
  128. Strategy const& strategy)
  129. {
  130. return boost::apply_visitor(visitor<Matrix, Strategy>(strategy), geometry1, geometry2);
  131. }
  132. };
  133. } // namespace resolve_variant
  134. /*!
  135. \brief Calculates the relation between a pair of geometries as defined in DE-9IM.
  136. \ingroup relation
  137. \tparam Geometry1 \tparam_geometry
  138. \tparam Geometry2 \tparam_geometry
  139. \tparam Strategy \tparam_strategy{Relation}
  140. \param geometry1 \param_geometry
  141. \param geometry2 \param_geometry
  142. \param strategy \param_strategy{relation}
  143. \return The DE-9IM matrix expressing the relation between geometries.
  144. \qbk{distinguish,with strategy}
  145. \qbk{[include reference/algorithms/relation.qbk]}
  146. */
  147. template <typename Geometry1, typename Geometry2, typename Strategy>
  148. inline de9im::matrix relation(Geometry1 const& geometry1,
  149. Geometry2 const& geometry2,
  150. Strategy const& strategy)
  151. {
  152. return resolve_variant::relation
  153. <
  154. Geometry1,
  155. Geometry2
  156. >::template apply<de9im::matrix>(geometry1, geometry2, strategy);
  157. }
  158. /*!
  159. \brief Calculates the relation between a pair of geometries as defined in DE-9IM.
  160. \ingroup relation
  161. \tparam Geometry1 \tparam_geometry
  162. \tparam Geometry2 \tparam_geometry
  163. \param geometry1 \param_geometry
  164. \param geometry2 \param_geometry
  165. \return The DE-9IM matrix expressing the relation between geometries.
  166. \qbk{[include reference/algorithms/relation.qbk]}
  167. */
  168. template <typename Geometry1, typename Geometry2>
  169. inline de9im::matrix relation(Geometry1 const& geometry1,
  170. Geometry2 const& geometry2)
  171. {
  172. return resolve_variant::relation
  173. <
  174. Geometry1,
  175. Geometry2
  176. >::template apply<de9im::matrix>(geometry1, geometry2, default_strategy());
  177. }
  178. }} // namespace boost::geometry
  179. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_INTERFACE_HPP