1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2015 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2015 Mateusz Loskot, London, UK.
6 // Copyright (c) 2014-2015 Adam Wulkiewicz, Lodz, Poland.
8 // This file was modified by Oracle on 2014, 2015, 2016, 2017, 2019.
9 // Modifications copyright (c) 2014-2019 Oracle and/or its affiliates.
11 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Contributed and/or modified by Menelaos Karavelas, on behalf of Oracle
14 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
15 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
17 // Use, modification and distribution is subject to the Boost Software License,
18 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
19 // http://www.boost.org/LICENSE_1_0.txt)
21 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_EQUALS_INTERFACE_HPP
22 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_EQUALS_INTERFACE_HPP
27 #include <boost/variant/apply_visitor.hpp>
28 #include <boost/variant/static_visitor.hpp>
29 #include <boost/variant/variant_fwd.hpp>
31 #include <boost/geometry/core/coordinate_dimension.hpp>
32 #include <boost/geometry/core/reverse_dispatch.hpp>
34 #include <boost/geometry/geometries/concepts/check.hpp>
36 #include <boost/geometry/algorithms/not_implemented.hpp>
38 #include <boost/geometry/strategies/default_strategy.hpp>
39 #include <boost/geometry/strategies/relate.hpp>
42 namespace boost { namespace geometry
45 #ifndef DOXYGEN_NO_DISPATCH
53 typename Tag1 = typename tag<Geometry1>::type,
54 typename Tag2 = typename tag<Geometry2>::type,
55 typename CastedTag1 = typename tag_cast<Tag1, pointlike_tag, linear_tag, areal_tag>::type,
56 typename CastedTag2 = typename tag_cast<Tag2, pointlike_tag, linear_tag, areal_tag>::type,
57 std::size_t DimensionCount = dimension<Geometry1>::type::value,
58 bool Reverse = reverse_dispatch<Geometry1, Geometry2>::type::value
60 struct equals: not_implemented<Tag1, Tag2>
64 // If reversal is needed, perform it
67 typename Geometry1, typename Geometry2,
68 typename Tag1, typename Tag2,
69 typename CastedTag1, typename CastedTag2,
70 std::size_t DimensionCount
72 struct equals<Geometry1, Geometry2, Tag1, Tag2, CastedTag1, CastedTag2, DimensionCount, true>
73 : equals<Geometry2, Geometry1, Tag2, Tag1, CastedTag2, CastedTag1, DimensionCount, false>
75 template <typename Strategy>
76 static inline bool apply(Geometry1 const& g1, Geometry2 const& g2, Strategy const& strategy)
82 CastedTag2, CastedTag1,
85 >::apply(g2, g1, strategy);
90 } // namespace dispatch
91 #endif // DOXYGEN_NO_DISPATCH
94 namespace resolve_strategy
99 template <typename Geometry1, typename Geometry2, typename Strategy>
100 static inline bool apply(Geometry1 const& geometry1,
101 Geometry2 const& geometry2,
102 Strategy const& strategy)
104 return dispatch::equals
107 >::apply(geometry1, geometry2, strategy);
110 template <typename Geometry1, typename Geometry2>
111 static inline bool apply(Geometry1 const& geometry1,
112 Geometry2 const& geometry2,
115 typedef typename strategy::relate::services::default_strategy
119 >::type strategy_type;
121 return dispatch::equals
124 >::apply(geometry1, geometry2, strategy_type());
128 } // namespace resolve_strategy
131 namespace resolve_variant {
133 template <typename Geometry1, typename Geometry2>
136 template <typename Strategy>
137 static inline bool apply(Geometry1 const& geometry1,
138 Geometry2 const& geometry2,
139 Strategy const& strategy)
141 concepts::check_concepts_and_equal_dimensions
147 return resolve_strategy::equals
148 ::apply(geometry1, geometry2, strategy);
152 template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
153 struct equals<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
155 template <typename Strategy>
156 struct visitor: static_visitor<bool>
158 Geometry2 const& m_geometry2;
159 Strategy const& m_strategy;
161 visitor(Geometry2 const& geometry2, Strategy const& strategy)
162 : m_geometry2(geometry2)
163 , m_strategy(strategy)
166 template <typename Geometry1>
167 inline bool operator()(Geometry1 const& geometry1) const
169 return equals<Geometry1, Geometry2>
170 ::apply(geometry1, m_geometry2, m_strategy);
175 template <typename Strategy>
176 static inline bool apply(
177 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
178 Geometry2 const& geometry2,
179 Strategy const& strategy
182 return boost::apply_visitor(visitor<Strategy>(geometry2, strategy), geometry1);
186 template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
187 struct equals<Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
189 template <typename Strategy>
190 struct visitor: static_visitor<bool>
192 Geometry1 const& m_geometry1;
193 Strategy const& m_strategy;
195 visitor(Geometry1 const& geometry1, Strategy const& strategy)
196 : m_geometry1(geometry1)
197 , m_strategy(strategy)
200 template <typename Geometry2>
201 inline bool operator()(Geometry2 const& geometry2) const
203 return equals<Geometry1, Geometry2>
204 ::apply(m_geometry1, geometry2, m_strategy);
209 template <typename Strategy>
210 static inline bool apply(
211 Geometry1 const& geometry1,
212 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
213 Strategy const& strategy
216 return boost::apply_visitor(visitor<Strategy>(geometry1, strategy), geometry2);
221 BOOST_VARIANT_ENUM_PARAMS(typename T1),
222 BOOST_VARIANT_ENUM_PARAMS(typename T2)
225 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
226 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>
229 template <typename Strategy>
230 struct visitor: static_visitor<bool>
232 Strategy const& m_strategy;
234 visitor(Strategy const& strategy)
235 : m_strategy(strategy)
238 template <typename Geometry1, typename Geometry2>
239 inline bool operator()(Geometry1 const& geometry1,
240 Geometry2 const& geometry2) const
242 return equals<Geometry1, Geometry2>
243 ::apply(geometry1, geometry2, m_strategy);
248 template <typename Strategy>
249 static inline bool apply(
250 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
251 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
252 Strategy const& strategy
255 return boost::apply_visitor(visitor<Strategy>(strategy), geometry1, geometry2);
259 } // namespace resolve_variant
263 \brief \brief_check{are spatially equal}
264 \details \details_check12{equals, is spatially equal}. Spatially equal means
265 that the same point set is included. A box can therefore be spatially equal
266 to a ring or a polygon, or a linestring can be spatially equal to a
267 multi-linestring or a segment. This only works theoretically, not all
268 combinations are implemented yet.
270 \tparam Geometry1 \tparam_geometry
271 \tparam Geometry2 \tparam_geometry
272 \tparam Strategy \tparam_strategy{Equals}
273 \param geometry1 \param_geometry
274 \param geometry2 \param_geometry
275 \param strategy \param_strategy{equals}
276 \return \return_check2{are spatially equal}
278 \qbk{distinguish,with strategy}
279 \qbk{[include reference/algorithms/equals.qbk]}
281 template <typename Geometry1, typename Geometry2, typename Strategy>
282 inline bool equals(Geometry1 const& geometry1,
283 Geometry2 const& geometry2,
284 Strategy const& strategy)
286 return resolve_variant::equals
289 >::apply(geometry1, geometry2, strategy);
294 \brief \brief_check{are spatially equal}
295 \details \details_check12{equals, is spatially equal}. Spatially equal means
296 that the same point set is included. A box can therefore be spatially equal
297 to a ring or a polygon, or a linestring can be spatially equal to a
298 multi-linestring or a segment. This only works theoretically, not all
299 combinations are implemented yet.
301 \tparam Geometry1 \tparam_geometry
302 \tparam Geometry2 \tparam_geometry
303 \param geometry1 \param_geometry
304 \param geometry2 \param_geometry
305 \return \return_check2{are spatially equal}
307 \qbk{[include reference/algorithms/equals.qbk]}
309 template <typename Geometry1, typename Geometry2>
310 inline bool equals(Geometry1 const& geometry1, Geometry2 const& geometry2)
312 return resolve_variant::equals<Geometry1, Geometry2>
313 ::apply(geometry1, geometry2, default_strategy());
317 }} // namespace boost::geometry
320 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_EQUALS_INTERFACE_HPP