interface.hpp 9.4 KB

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