1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2015 Barend Gehrels, Amsterdam, the Netherlands.
5 // This file was modified by Oracle on 2013, 2014, 2015, 2017.
6 // Modifications copyright (c) 2013-2017 Oracle and/or its affiliates.
8 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
10 // Use, modification and distribution is subject to the Boost Software License,
11 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
12 // http://www.boost.org/LICENSE_1_0.txt)
14 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATION_INTERFACE_HPP
15 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATION_INTERFACE_HPP
18 #include <boost/geometry/algorithms/detail/relate/interface.hpp>
21 namespace boost { namespace geometry
24 #ifndef DOXYGEN_NO_DETAIL
25 namespace detail { namespace relate
28 template <typename Geometry1, typename Geometry2>
29 struct result_handler_type<Geometry1, Geometry2, geometry::de9im::matrix, false>
31 typedef matrix_handler<geometry::de9im::matrix> type;
35 }} // namespace detail::relate
36 #endif // DOXYGEN_NO_DETAIL
38 namespace resolve_variant
41 template <typename Geometry1, typename Geometry2>
44 template <typename Matrix, typename Strategy>
45 static inline Matrix apply(Geometry1 const& geometry1,
46 Geometry2 const& geometry2,
47 Strategy const& strategy)
49 concepts::check<Geometry1 const>();
50 concepts::check<Geometry2 const>();
51 assert_dimension_equal<Geometry1, Geometry2>();
53 typename detail::relate::result_handler_type
60 resolve_strategy::relate::apply(geometry1, geometry2, handler, strategy);
62 return handler.result();
66 template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
67 struct relation<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
69 template <typename Matrix, typename Strategy>
70 struct visitor : boost::static_visitor<Matrix>
72 Geometry2 const& m_geometry2;
73 Strategy const& m_strategy;
75 visitor(Geometry2 const& geometry2, Strategy const& strategy)
76 : m_geometry2(geometry2), m_strategy(strategy) {}
78 template <typename Geometry1>
79 Matrix operator()(Geometry1 const& geometry1) const
81 return relation<Geometry1, Geometry2>
82 ::template apply<Matrix>(geometry1, m_geometry2, m_strategy);
86 template <typename Matrix, typename Strategy>
88 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
89 Geometry2 const& geometry2,
90 Strategy const& strategy)
92 return boost::apply_visitor(visitor<Matrix, Strategy>(geometry2, strategy), geometry1);
96 template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
97 struct relation<Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
99 template <typename Matrix, typename Strategy>
100 struct visitor : boost::static_visitor<Matrix>
102 Geometry1 const& m_geometry1;
103 Strategy const& m_strategy;
105 visitor(Geometry1 const& geometry1, Strategy const& strategy)
106 : m_geometry1(geometry1), m_strategy(strategy) {}
108 template <typename Geometry2>
109 Matrix operator()(Geometry2 const& geometry2) const
111 return relation<Geometry1, Geometry2>
112 ::template apply<Matrix>(m_geometry1, geometry2, m_strategy);
116 template <typename Matrix, typename Strategy>
118 apply(Geometry1 const& geometry1,
119 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
120 Strategy const& strategy)
122 return boost::apply_visitor(visitor<Matrix, Strategy>(geometry1, strategy), geometry2);
128 BOOST_VARIANT_ENUM_PARAMS(typename T1),
129 BOOST_VARIANT_ENUM_PARAMS(typename T2)
133 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
134 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>
137 template <typename Matrix, typename Strategy>
138 struct visitor : boost::static_visitor<Matrix>
140 Strategy const& m_strategy;
142 visitor(Strategy const& strategy)
143 : m_strategy(strategy) {}
145 template <typename Geometry1, typename Geometry2>
146 Matrix operator()(Geometry1 const& geometry1,
147 Geometry2 const& geometry2) const
149 return relation<Geometry1, Geometry2>
150 ::template apply<Matrix>(geometry1, geometry2, m_strategy);
154 template <typename Matrix, typename Strategy>
156 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
157 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
158 Strategy const& strategy)
160 return boost::apply_visitor(visitor<Matrix, Strategy>(strategy), geometry1, geometry2);
164 } // namespace resolve_variant
168 \brief Calculates the relation between a pair of geometries as defined in DE-9IM.
170 \tparam Geometry1 \tparam_geometry
171 \tparam Geometry2 \tparam_geometry
172 \tparam Strategy \tparam_strategy{Relation}
173 \param geometry1 \param_geometry
174 \param geometry2 \param_geometry
175 \param strategy \param_strategy{relation}
176 \return The DE-9IM matrix expressing the relation between geometries.
178 \qbk{distinguish,with strategy}
179 \qbk{[include reference/algorithms/relation.qbk]}
181 template <typename Geometry1, typename Geometry2, typename Strategy>
182 inline de9im::matrix relation(Geometry1 const& geometry1,
183 Geometry2 const& geometry2,
184 Strategy const& strategy)
186 return resolve_variant::relation
190 >::template apply<de9im::matrix>(geometry1, geometry2, strategy);
195 \brief Calculates the relation between a pair of geometries as defined in DE-9IM.
197 \tparam Geometry1 \tparam_geometry
198 \tparam Geometry2 \tparam_geometry
199 \param geometry1 \param_geometry
200 \param geometry2 \param_geometry
201 \return The DE-9IM matrix expressing the relation between geometries.
203 \qbk{[include reference/algorithms/relation.qbk]}
205 template <typename Geometry1, typename Geometry2>
206 inline de9im::matrix relation(Geometry1 const& geometry1,
207 Geometry2 const& geometry2)
209 return resolve_variant::relation
213 >::template apply<de9im::matrix>(geometry1, geometry2, default_strategy());
217 }} // namespace boost::geometry
219 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_RELATE_INTERFACE_HPP