1 // Boost.Geometry (aka GGL, Generic Geometry Library)
3 // Copyright (c) 2007-2012 Barend Gehrels, Amsterdam, the Netherlands.
4 // Copyright (c) 2008-2012 Bruno Lalande, Paris, France.
5 // Copyright (c) 2009-2012 Mateusz Loskot, London, UK.
7 // This file was modified by Oracle on 2013, 2014, 2017.
8 // Modifications copyright (c) 2013-2017 Oracle and/or its affiliates.
10 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
12 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
13 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
15 // Use, modification and distribution is subject to the Boost Software License,
16 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
17 // http://www.boost.org/LICENSE_1_0.txt)
19 #ifndef BOOST_GEOMETRY_ALGORITHMS_DETAIL_COVERED_BY_INTERFACE_HPP
20 #define BOOST_GEOMETRY_ALGORITHMS_DETAIL_COVERED_BY_INTERFACE_HPP
23 #include <boost/variant/apply_visitor.hpp>
24 #include <boost/variant/static_visitor.hpp>
25 #include <boost/variant/variant_fwd.hpp>
27 #include <boost/geometry/algorithms/detail/within/interface.hpp>
28 #include <boost/geometry/algorithms/not_implemented.hpp>
30 #include <boost/geometry/strategies/cartesian/point_in_box.hpp>
31 #include <boost/geometry/strategies/cartesian/box_in_box.hpp>
32 #include <boost/geometry/strategies/default_strategy.hpp>
35 namespace boost { namespace geometry
38 #ifndef DOXYGEN_NO_DISPATCH
46 typename Tag1 = typename tag<Geometry1>::type,
47 typename Tag2 = typename tag<Geometry2>::type
50 : not_implemented<Tag1, Tag2>
53 } // namespace dispatch
54 #endif // DOXYGEN_NO_DISPATCH
57 namespace resolve_strategy {
61 template <typename Geometry1, typename Geometry2, typename Strategy>
62 static inline bool apply(Geometry1 const& geometry1,
63 Geometry2 const& geometry2,
64 Strategy const& strategy)
66 concepts::within::check
68 typename tag<Geometry1>::type,
69 typename tag<Geometry2>::type,
70 typename tag_cast<typename tag<Geometry2>::type, areal_tag>::type,
73 concepts::check<Geometry1 const>();
74 concepts::check<Geometry2 const>();
75 assert_dimension_equal<Geometry1, Geometry2>();
77 return dispatch::covered_by<Geometry1, Geometry2>::apply(geometry1,
82 template <typename Geometry1, typename Geometry2>
83 static inline bool apply(Geometry1 const& geometry1,
84 Geometry2 const& geometry2,
87 typedef typename strategy::covered_by::services::default_strategy
91 >::type strategy_type;
93 return covered_by::apply(geometry1, geometry2, strategy_type());
97 } // namespace resolve_strategy
100 namespace resolve_variant {
102 template <typename Geometry1, typename Geometry2>
105 template <typename Strategy>
106 static inline bool apply(Geometry1 const& geometry1,
107 Geometry2 const& geometry2,
108 Strategy const& strategy)
110 return resolve_strategy::covered_by
111 ::apply(geometry1, geometry2, strategy);
115 template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
116 struct covered_by<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
118 template <typename Strategy>
119 struct visitor: boost::static_visitor<bool>
121 Geometry2 const& m_geometry2;
122 Strategy const& m_strategy;
124 visitor(Geometry2 const& geometry2, Strategy const& strategy)
125 : m_geometry2(geometry2), m_strategy(strategy) {}
127 template <typename Geometry1>
128 bool operator()(Geometry1 const& geometry1) const
130 return covered_by<Geometry1, Geometry2>
131 ::apply(geometry1, m_geometry2, m_strategy);
135 template <typename Strategy>
137 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
138 Geometry2 const& geometry2,
139 Strategy const& strategy)
141 return boost::apply_visitor(visitor<Strategy>(geometry2, strategy), geometry1);
145 template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
146 struct covered_by<Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
148 template <typename Strategy>
149 struct visitor: boost::static_visitor<bool>
151 Geometry1 const& m_geometry1;
152 Strategy const& m_strategy;
154 visitor(Geometry1 const& geometry1, Strategy const& strategy)
155 : m_geometry1(geometry1), m_strategy(strategy) {}
157 template <typename Geometry2>
158 bool operator()(Geometry2 const& geometry2) const
160 return covered_by<Geometry1, Geometry2>
161 ::apply(m_geometry1, geometry2, m_strategy);
165 template <typename Strategy>
167 apply(Geometry1 const& geometry1,
168 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
169 Strategy const& strategy)
171 return boost::apply_visitor(visitor<Strategy>(geometry1, strategy), geometry2);
176 BOOST_VARIANT_ENUM_PARAMS(typename T1),
177 BOOST_VARIANT_ENUM_PARAMS(typename T2)
180 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
181 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>
184 template <typename Strategy>
185 struct visitor: boost::static_visitor<bool>
187 Strategy const& m_strategy;
189 visitor(Strategy const& strategy): m_strategy(strategy) {}
191 template <typename Geometry1, typename Geometry2>
192 bool operator()(Geometry1 const& geometry1,
193 Geometry2 const& geometry2) const
195 return covered_by<Geometry1, Geometry2>
196 ::apply(geometry1, geometry2, m_strategy);
200 template <typename Strategy>
202 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
203 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
204 Strategy const& strategy)
206 return boost::apply_visitor(visitor<Strategy>(strategy), geometry1, geometry2);
210 } // namespace resolve_variant
214 \brief \brief_check12{is inside or on border}
216 \details \details_check12{covered_by, is inside or on border}.
217 \tparam Geometry1 \tparam_geometry
218 \tparam Geometry2 \tparam_geometry
219 \param geometry1 \param_geometry which might be inside or on the border of the second geometry
220 \param geometry2 \param_geometry which might cover the first geometry
221 \return true if geometry1 is inside of or on the border of geometry2,
223 \note The default strategy is used for covered_by detection
225 \qbk{[include reference/algorithms/covered_by.qbk]}
228 template<typename Geometry1, typename Geometry2>
229 inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2)
231 return resolve_variant::covered_by<Geometry1, Geometry2>
232 ::apply(geometry1, geometry2, default_strategy());
236 \brief \brief_check12{is inside or on border} \brief_strategy
238 \details \details_check12{covered_by, is inside or on border}, \brief_strategy. \details_strategy_reasons
239 \tparam Geometry1 \tparam_geometry
240 \tparam Geometry2 \tparam_geometry
241 \param geometry1 \param_geometry which might be inside or on the border of the second geometry
242 \param geometry2 \param_geometry which might cover the first geometry
243 \param strategy strategy to be used
244 \return true if geometry1 is inside of or on the border of geometry2,
247 \qbk{distinguish,with strategy}
248 \qbk{[include reference/algorithms/covered_by.qbk]}
251 template<typename Geometry1, typename Geometry2, typename Strategy>
252 inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2,
253 Strategy const& strategy)
255 return resolve_variant::covered_by<Geometry1, Geometry2>
256 ::apply(geometry1, geometry2, strategy);
259 }} // namespace boost::geometry
261 #endif // BOOST_GEOMETRY_ALGORITHMS_DETAIL_COVERED_BY_INTERFACE_HPP