interface.hpp 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. // Boost.Geometry (aka GGL, Generic Geometry Library)
  2. // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
  3. // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
  4. // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
  5. // Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland.
  6. // This file was modified by Oracle on 2014, 2015, 2016, 2017, 2019.
  7. // Modifications copyright (c) 2014-2019 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_EQUALS_INTERFACE_HPP
  16. #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_EQUALS_INTERFACE_HPP
  17. #include <cstddef>
  18. #include <boost/variant/apply_visitor.hpp>
  19. #include <boost/variant/static_visitor.hpp>
  20. #include <boost/variant/variant_fwd.hpp>
  21. #include <boost/geometry/core/coordinate_dimension.hpp>
  22. #include <boost/geometry/core/reverse_dispatch.hpp>
  23. #include <boost/geometry/geometries/concepts/check.hpp>
  24. #include <boost/geometry/algorithms/not_implemented.hpp>
  25. #include <boost/geometry/strategies/default_strategy.hpp>
  26. #include <boost/geometry/strategies/relate.hpp>
  27. namespace boost { namespace geometry
  28. {
  29. #ifndef DOXYGEN_NO_DISPATCH
  30. namespace dispatch
  31. {
  32. template
  33. <
  34. typename Geometry1,
  35. typename Geometry2,
  36. typename Tag1 = typename tag<Geometry1>::type,
  37. typename Tag2 = typename tag<Geometry2>::type,
  38. typename CastedTag1 = typename tag_cast<Tag1, pointlike_tag, linear_tag, areal_tag>::type,
  39. typename CastedTag2 = typename tag_cast<Tag2, pointlike_tag, linear_tag, areal_tag>::type,
  40. std::size_t DimensionCount = dimension<Geometry1>::type::value,
  41. bool Reverse = reverse_dispatch<Geometry1, Geometry2>::type::value
  42. >
  43. struct equals: not_implemented<Tag1, Tag2>
  44. {};
  45. // If reversal is needed, perform it
  46. template
  47. <
  48. typename Geometry1, typename Geometry2,
  49. typename Tag1, typename Tag2,
  50. typename CastedTag1, typename CastedTag2,
  51. std::size_t DimensionCount
  52. >
  53. struct equals<Geometry1, Geometry2, Tag1, Tag2, CastedTag1, CastedTag2, DimensionCount, true>
  54. : equals<Geometry2, Geometry1, Tag2, Tag1, CastedTag2, CastedTag1, DimensionCount, false>
  55. {
  56. template <typename Strategy>
  57. static inline bool apply(Geometry1 const& g1, Geometry2 const& g2, Strategy const& strategy)
  58. {
  59. return equals
  60. <
  61. Geometry2, Geometry1,
  62. Tag2, Tag1,
  63. CastedTag2, CastedTag1,
  64. DimensionCount,
  65. false
  66. >::apply(g2, g1, strategy);
  67. }
  68. };
  69. } // namespace dispatch
  70. #endif // DOXYGEN_NO_DISPATCH
  71. namespace resolve_strategy
  72. {
  73. struct equals
  74. {
  75. template <typename Geometry1, typename Geometry2, typename Strategy>
  76. static inline bool apply(Geometry1 const& geometry1,
  77. Geometry2 const& geometry2,
  78. Strategy const& strategy)
  79. {
  80. return dispatch::equals
  81. <
  82. Geometry1, Geometry2
  83. >::apply(geometry1, geometry2, strategy);
  84. }
  85. template <typename Geometry1, typename Geometry2>
  86. static inline bool apply(Geometry1 const& geometry1,
  87. Geometry2 const& geometry2,
  88. default_strategy)
  89. {
  90. typedef typename strategy::relate::services::default_strategy
  91. <
  92. Geometry1,
  93. Geometry2
  94. >::type strategy_type;
  95. return dispatch::equals
  96. <
  97. Geometry1, Geometry2
  98. >::apply(geometry1, geometry2, strategy_type());
  99. }
  100. };
  101. } // namespace resolve_strategy
  102. namespace resolve_variant {
  103. template <typename Geometry1, typename Geometry2>
  104. struct equals
  105. {
  106. template <typename Strategy>
  107. static inline bool apply(Geometry1 const& geometry1,
  108. Geometry2 const& geometry2,
  109. Strategy const& strategy)
  110. {
  111. concepts::check_concepts_and_equal_dimensions
  112. <
  113. Geometry1 const,
  114. Geometry2 const
  115. >();
  116. return resolve_strategy::equals
  117. ::apply(geometry1, geometry2, strategy);
  118. }
  119. };
  120. template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
  121. struct equals<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
  122. {
  123. template <typename Strategy>
  124. struct visitor: static_visitor<bool>
  125. {
  126. Geometry2 const& m_geometry2;
  127. Strategy const& m_strategy;
  128. visitor(Geometry2 const& geometry2, Strategy const& strategy)
  129. : m_geometry2(geometry2)
  130. , m_strategy(strategy)
  131. {}
  132. template <typename Geometry1>
  133. inline bool operator()(Geometry1 const& geometry1) const
  134. {
  135. return equals<Geometry1, Geometry2>
  136. ::apply(geometry1, m_geometry2, m_strategy);
  137. }
  138. };
  139. template <typename Strategy>
  140. static inline bool apply(
  141. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
  142. Geometry2 const& geometry2,
  143. Strategy const& strategy
  144. )
  145. {
  146. return boost::apply_visitor(visitor<Strategy>(geometry2, strategy), geometry1);
  147. }
  148. };
  149. template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
  150. struct equals<Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
  151. {
  152. template <typename Strategy>
  153. struct visitor: static_visitor<bool>
  154. {
  155. Geometry1 const& m_geometry1;
  156. Strategy const& m_strategy;
  157. visitor(Geometry1 const& geometry1, Strategy const& strategy)
  158. : m_geometry1(geometry1)
  159. , m_strategy(strategy)
  160. {}
  161. template <typename Geometry2>
  162. inline bool operator()(Geometry2 const& geometry2) const
  163. {
  164. return equals<Geometry1, Geometry2>
  165. ::apply(m_geometry1, geometry2, m_strategy);
  166. }
  167. };
  168. template <typename Strategy>
  169. static inline bool apply(
  170. Geometry1 const& geometry1,
  171. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
  172. Strategy const& strategy
  173. )
  174. {
  175. return boost::apply_visitor(visitor<Strategy>(geometry1, strategy), geometry2);
  176. }
  177. };
  178. template <
  179. BOOST_VARIANT_ENUM_PARAMS(typename T1),
  180. BOOST_VARIANT_ENUM_PARAMS(typename T2)
  181. >
  182. struct equals<
  183. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
  184. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>
  185. >
  186. {
  187. template <typename Strategy>
  188. struct visitor: static_visitor<bool>
  189. {
  190. Strategy const& m_strategy;
  191. visitor(Strategy const& strategy)
  192. : m_strategy(strategy)
  193. {}
  194. template <typename Geometry1, typename Geometry2>
  195. inline bool operator()(Geometry1 const& geometry1,
  196. Geometry2 const& geometry2) const
  197. {
  198. return equals<Geometry1, Geometry2>
  199. ::apply(geometry1, geometry2, m_strategy);
  200. }
  201. };
  202. template <typename Strategy>
  203. static inline bool apply(
  204. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
  205. boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
  206. Strategy const& strategy
  207. )
  208. {
  209. return boost::apply_visitor(visitor<Strategy>(strategy), geometry1, geometry2);
  210. }
  211. };
  212. } // namespace resolve_variant
  213. /*!
  214. \brief \brief_check{are spatially equal}
  215. \details \details_check12{equals, is spatially equal}. Spatially equal means
  216. that the same point set is included. A box can therefore be spatially equal
  217. to a ring or a polygon, or a linestring can be spatially equal to a
  218. multi-linestring or a segment. This only works theoretically, not all
  219. combinations are implemented yet.
  220. \ingroup equals
  221. \tparam Geometry1 \tparam_geometry
  222. \tparam Geometry2 \tparam_geometry
  223. \tparam Strategy \tparam_strategy{Equals}
  224. \param geometry1 \param_geometry
  225. \param geometry2 \param_geometry
  226. \param strategy \param_strategy{equals}
  227. \return \return_check2{are spatially equal}
  228. \qbk{distinguish,with strategy}
  229. \qbk{[include reference/algorithms/equals.qbk]}
  230. */
  231. template <typename Geometry1, typename Geometry2, typename Strategy>
  232. inline bool equals(Geometry1 const& geometry1,
  233. Geometry2 const& geometry2,
  234. Strategy const& strategy)
  235. {
  236. return resolve_variant::equals
  237. <
  238. Geometry1, Geometry2
  239. >::apply(geometry1, geometry2, strategy);
  240. }
  241. /*!
  242. \brief \brief_check{are spatially equal}
  243. \details \details_check12{equals, is spatially equal}. Spatially equal means
  244. that the same point set is included. A box can therefore be spatially equal
  245. to a ring or a polygon, or a linestring can be spatially equal to a
  246. multi-linestring or a segment. This only works theoretically, not all
  247. combinations are implemented yet.
  248. \ingroup equals
  249. \tparam Geometry1 \tparam_geometry
  250. \tparam Geometry2 \tparam_geometry
  251. \param geometry1 \param_geometry
  252. \param geometry2 \param_geometry
  253. \return \return_check2{are spatially equal}
  254. \qbk{[include reference/algorithms/equals.qbk]}
  255. */
  256. template <typename Geometry1, typename Geometry2>
  257. inline bool equals(Geometry1 const& geometry1, Geometry2 const& geometry2)
  258. {
  259. return resolve_variant::equals<Geometry1, Geometry2>
  260. ::apply(geometry1, geometry2, default_strategy());
  261. }
  262. }} // namespace boost::geometry
  263. #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_EQUALS_INTERFACE_HPP