interface.hpp 9.3 KB

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