interface.hpp 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  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-2022.
  4. // Modifications copyright (c) 2013-2022 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>
  19. {
  20. typedef matrix_handler<geometry::de9im::matrix> type;
  21. };
  22. }} // namespace detail::relate
  23. #endif // DOXYGEN_NO_DETAIL
  24. namespace resolve_dynamic
  25. {
  26. template
  27. <
  28. typename Geometry1, typename Geometry2,
  29. typename Tag1 = typename geometry::tag<Geometry1>::type,
  30. typename Tag2 = typename geometry::tag<Geometry2>::type
  31. >
  32. struct relation
  33. {
  34. template <typename Matrix, typename Strategy>
  35. static inline Matrix apply(Geometry1 const& geometry1,
  36. Geometry2 const& geometry2,
  37. Strategy const& strategy)
  38. {
  39. concepts::check<Geometry1 const>();
  40. concepts::check<Geometry2 const>();
  41. assert_dimension_equal<Geometry1, Geometry2>();
  42. typename detail::relate::result_handler_type
  43. <
  44. Geometry1,
  45. Geometry2,
  46. Matrix
  47. >::type handler;
  48. resolve_strategy::relate
  49. <
  50. Strategy
  51. >::apply(geometry1, geometry2, handler, strategy);
  52. return handler.result();
  53. }
  54. };
  55. template <typename Geometry1, typename Geometry2, typename Tag2>
  56. struct relation<Geometry1, Geometry2, dynamic_geometry_tag, Tag2>
  57. {
  58. template <typename Matrix, typename Strategy>
  59. static inline Matrix apply(Geometry1 const& geometry1,
  60. Geometry2 const& geometry2,
  61. Strategy const& strategy)
  62. {
  63. Matrix result;
  64. traits::visit<Geometry1>::apply([&](auto const& g1)
  65. {
  66. result = relation
  67. <
  68. util::remove_cref_t<decltype(g1)>,
  69. Geometry2
  70. >::template apply<Matrix>(g1, geometry2, strategy);
  71. }, geometry1);
  72. return result;
  73. }
  74. };
  75. template <typename Geometry1, typename Geometry2, typename Tag1>
  76. struct relation<Geometry1, Geometry2, Tag1, dynamic_geometry_tag>
  77. {
  78. template <typename Matrix, typename Strategy>
  79. static inline Matrix apply(Geometry1 const& geometry1,
  80. Geometry2 const& geometry2,
  81. Strategy const& strategy)
  82. {
  83. Matrix result;
  84. traits::visit<Geometry2>::apply([&](auto const& g2)
  85. {
  86. result = relation
  87. <
  88. Geometry1,
  89. util::remove_cref_t<decltype(g2)>
  90. >::template apply<Matrix>(geometry1, g2, strategy);
  91. }, geometry2);
  92. return result;
  93. }
  94. };
  95. template <typename Geometry1, typename Geometry2>
  96. struct relation<Geometry1, Geometry2, dynamic_geometry_tag, dynamic_geometry_tag>
  97. {
  98. template <typename Matrix, typename Strategy>
  99. static inline Matrix apply(Geometry1 const& geometry1,
  100. Geometry2 const& geometry2,
  101. Strategy const& strategy)
  102. {
  103. Matrix result;
  104. traits::visit<Geometry1, Geometry2>::apply([&](auto const& g1, auto const& g2)
  105. {
  106. result = relation
  107. <
  108. util::remove_cref_t<decltype(g1)>,
  109. util::remove_cref_t<decltype(g2)>
  110. >::template apply<Matrix>(g1, g2, strategy);
  111. }, geometry1, geometry2);
  112. return result;
  113. }
  114. };
  115. } // namespace resolve_dynamic
  116. /*!
  117. \brief Calculates the relation between a pair of geometries as defined in DE-9IM.
  118. \ingroup relation
  119. \tparam Geometry1 \tparam_geometry
  120. \tparam Geometry2 \tparam_geometry
  121. \tparam Strategy \tparam_strategy{Relation}
  122. \param geometry1 \param_geometry
  123. \param geometry2 \param_geometry
  124. \param strategy \param_strategy{relation}
  125. \return The DE-9IM matrix expressing the relation between geometries.
  126. \qbk{distinguish,with strategy}
  127. \qbk{[include reference/algorithms/relation.qbk]}
  128. */
  129. template <typename Geometry1, typename Geometry2, typename Strategy>
  130. inline de9im::matrix relation(Geometry1 const& geometry1,
  131. Geometry2 const& geometry2,
  132. Strategy const& strategy)
  133. {
  134. return resolve_dynamic::relation
  135. <
  136. Geometry1,
  137. Geometry2
  138. >::template apply<de9im::matrix>(geometry1, geometry2, strategy);
  139. }
  140. /*!
  141. \brief Calculates the relation between a pair of geometries as defined in DE-9IM.
  142. \ingroup relation
  143. \tparam Geometry1 \tparam_geometry
  144. \tparam Geometry2 \tparam_geometry
  145. \param geometry1 \param_geometry
  146. \param geometry2 \param_geometry
  147. \return The DE-9IM matrix expressing the relation between geometries.
  148. \qbk{[include reference/algorithms/relation.qbk]}
  149. */
  150. template <typename Geometry1, typename Geometry2>
  151. inline de9im::matrix relation(Geometry1 const& geometry1,
  152. Geometry2 const& geometry2)
  153. {
  154. return resolve_dynamic::relation
  155. <
  156. Geometry1,
  157. Geometry2
  158. >::template apply<de9im::matrix>(geometry1, geometry2, default_strategy());
  159. }
  160. }} // namespace boost::geometry
  161. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_INTERFACE_HPP