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.
8 // Modifications copyright (c) 2013, 2014 Oracle and/or its affiliates.
10 // Parts of Boost.Geometry are redesigned from Geodan's Geographic Library
11 // (geolib/GGL), copyright (c) 1995-2010 Geodan, Amsterdam, the Netherlands.
13 // Use, modification and distribution is subject to the Boost Software License,
14 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
15 // http://www.boost.org/LICENSE_1_0.txt)
17 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
19 #ifndef BOOST_GEOMETRY_ALGORITHMS_COVERED_BY_HPP
20 #define BOOST_GEOMETRY_ALGORITHMS_COVERED_BY_HPP
25 #include <boost/variant/apply_visitor.hpp>
26 #include <boost/variant/static_visitor.hpp>
27 #include <boost/variant/variant_fwd.hpp>
29 #include <boost/geometry/algorithms/not_implemented.hpp>
30 #include <boost/geometry/algorithms/within.hpp>
32 #include <boost/geometry/strategies/cartesian/point_in_box.hpp>
33 #include <boost/geometry/strategies/cartesian/box_in_box.hpp>
34 #include <boost/geometry/strategies/default_strategy.hpp>
36 namespace boost { namespace geometry
39 #ifndef DOXYGEN_NO_DETAIL
40 namespace detail { namespace covered_by {
42 struct use_point_in_geometry
44 template <typename Geometry1, typename Geometry2, typename Strategy>
45 static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2, Strategy const& strategy)
47 return detail::within::point_in_geometry(geometry1, geometry2, strategy) >= 0;
53 template <typename Geometry1, typename Geometry2, typename Strategy>
54 static inline bool apply(Geometry1 const& geometry1, Geometry2 const& geometry2, Strategy const& /*strategy*/)
56 return Strategy::apply(geometry1, geometry2);
60 }} // namespace detail::covered_by
61 #endif // DOXYGEN_NO_DETAIL
63 #ifndef DOXYGEN_NO_DISPATCH
71 typename Tag1 = typename tag<Geometry1>::type,
72 typename Tag2 = typename tag<Geometry2>::type
75 : not_implemented<Tag1, Tag2>
79 template <typename Point, typename Box>
80 struct covered_by<Point, Box, point_tag, box_tag>
82 template <typename Strategy>
83 static inline bool apply(Point const& point, Box const& box, Strategy const& strategy)
85 ::boost::ignore_unused_variable_warning(strategy);
86 return strategy.apply(point, box);
90 template <typename Box1, typename Box2>
91 struct covered_by<Box1, Box2, box_tag, box_tag>
93 template <typename Strategy>
94 static inline bool apply(Box1 const& box1, Box2 const& box2, Strategy const& strategy)
96 assert_dimension_equal<Box1, Box2>();
97 ::boost::ignore_unused_variable_warning(strategy);
98 return strategy.apply(box1, box2);
105 template <typename Point1, typename Point2>
106 struct covered_by<Point1, Point2, point_tag, point_tag>
107 : public detail::covered_by::use_point_in_geometry
110 template <typename Point, typename MultiPoint>
111 struct covered_by<Point, MultiPoint, point_tag, multi_point_tag>
112 : public detail::covered_by::use_point_in_geometry
117 template <typename Point, typename Segment>
118 struct covered_by<Point, Segment, point_tag, segment_tag>
119 : public detail::covered_by::use_point_in_geometry
122 template <typename Point, typename Linestring>
123 struct covered_by<Point, Linestring, point_tag, linestring_tag>
124 : public detail::covered_by::use_point_in_geometry
127 template <typename Point, typename MultiLinestring>
128 struct covered_by<Point, MultiLinestring, point_tag, multi_linestring_tag>
129 : public detail::covered_by::use_point_in_geometry
134 template <typename Point, typename Ring>
135 struct covered_by<Point, Ring, point_tag, ring_tag>
136 : public detail::covered_by::use_point_in_geometry
139 template <typename Point, typename Polygon>
140 struct covered_by<Point, Polygon, point_tag, polygon_tag>
141 : public detail::covered_by::use_point_in_geometry
144 template <typename Point, typename MultiPolygon>
145 struct covered_by<Point, MultiPolygon, point_tag, multi_polygon_tag>
146 : public detail::covered_by::use_point_in_geometry
151 template <typename Linestring1, typename Linestring2>
152 struct covered_by<Linestring1, Linestring2, linestring_tag, linestring_tag>
153 : public detail::covered_by::use_relate
156 template <typename Linestring, typename MultiLinestring>
157 struct covered_by<Linestring, MultiLinestring, linestring_tag, multi_linestring_tag>
158 : public detail::covered_by::use_relate
161 template <typename MultiLinestring, typename Linestring>
162 struct covered_by<MultiLinestring, Linestring, multi_linestring_tag, linestring_tag>
163 : public detail::covered_by::use_relate
166 template <typename MultiLinestring1, typename MultiLinestring2>
167 struct covered_by<MultiLinestring1, MultiLinestring2, multi_linestring_tag, multi_linestring_tag>
168 : public detail::covered_by::use_relate
173 template <typename Linestring, typename Ring>
174 struct covered_by<Linestring, Ring, linestring_tag, ring_tag>
175 : public detail::covered_by::use_relate
178 template <typename MultiLinestring, typename Ring>
179 struct covered_by<MultiLinestring, Ring, multi_linestring_tag, ring_tag>
180 : public detail::covered_by::use_relate
183 template <typename Linestring, typename Polygon>
184 struct covered_by<Linestring, Polygon, linestring_tag, polygon_tag>
185 : public detail::covered_by::use_relate
188 template <typename MultiLinestring, typename Polygon>
189 struct covered_by<MultiLinestring, Polygon, multi_linestring_tag, polygon_tag>
190 : public detail::covered_by::use_relate
193 template <typename Linestring, typename MultiPolygon>
194 struct covered_by<Linestring, MultiPolygon, linestring_tag, multi_polygon_tag>
195 : public detail::covered_by::use_relate
198 template <typename MultiLinestring, typename MultiPolygon>
199 struct covered_by<MultiLinestring, MultiPolygon, multi_linestring_tag, multi_polygon_tag>
200 : public detail::covered_by::use_relate
205 template <typename Ring1, typename Ring2>
206 struct covered_by<Ring1, Ring2, ring_tag, ring_tag>
207 : public detail::covered_by::use_relate
210 template <typename Ring, typename Polygon>
211 struct covered_by<Ring, Polygon, ring_tag, polygon_tag>
212 : public detail::covered_by::use_relate
215 template <typename Polygon, typename Ring>
216 struct covered_by<Polygon, Ring, polygon_tag, ring_tag>
217 : public detail::covered_by::use_relate
220 template <typename Polygon1, typename Polygon2>
221 struct covered_by<Polygon1, Polygon2, polygon_tag, polygon_tag>
222 : public detail::covered_by::use_relate
225 template <typename Ring, typename MultiPolygon>
226 struct covered_by<Ring, MultiPolygon, ring_tag, multi_polygon_tag>
227 : public detail::covered_by::use_relate
230 template <typename MultiPolygon, typename Ring>
231 struct covered_by<MultiPolygon, Ring, multi_polygon_tag, ring_tag>
232 : public detail::covered_by::use_relate
235 template <typename Polygon, typename MultiPolygon>
236 struct covered_by<Polygon, MultiPolygon, polygon_tag, multi_polygon_tag>
237 : public detail::covered_by::use_relate
240 template <typename MultiPolygon, typename Polygon>
241 struct covered_by<MultiPolygon, Polygon, multi_polygon_tag, polygon_tag>
242 : public detail::covered_by::use_relate
245 template <typename MultiPolygon1, typename MultiPolygon2>
246 struct covered_by<MultiPolygon1, MultiPolygon2, multi_polygon_tag, multi_polygon_tag>
247 : public detail::covered_by::use_relate
250 } // namespace dispatch
251 #endif // DOXYGEN_NO_DISPATCH
254 namespace resolve_strategy {
258 template <typename Geometry1, typename Geometry2, typename Strategy>
259 static inline bool apply(Geometry1 const& geometry1,
260 Geometry2 const& geometry2,
261 Strategy const& strategy)
263 concepts::within::check
265 typename tag<Geometry1>::type,
266 typename tag<Geometry2>::type,
267 typename tag_cast<typename tag<Geometry2>::type, areal_tag>::type,
270 concepts::check<Geometry1 const>();
271 concepts::check<Geometry2 const>();
272 assert_dimension_equal<Geometry1, Geometry2>();
274 return dispatch::covered_by<Geometry1, Geometry2>::apply(geometry1,
279 template <typename Geometry1, typename Geometry2>
280 static inline bool apply(Geometry1 const& geometry1,
281 Geometry2 const& geometry2,
284 typedef typename point_type<Geometry1>::type point_type1;
285 typedef typename point_type<Geometry2>::type point_type2;
287 typedef typename strategy::covered_by::services::default_strategy
289 typename tag<Geometry1>::type,
290 typename tag<Geometry2>::type,
291 typename tag<Geometry1>::type,
292 typename tag_cast<typename tag<Geometry2>::type, areal_tag>::type,
295 typename cs_tag<point_type1>::type, spherical_tag
299 typename cs_tag<point_type2>::type, spherical_tag
303 >::type strategy_type;
305 return covered_by::apply(geometry1, geometry2, strategy_type());
309 } // namespace resolve_strategy
312 namespace resolve_variant {
314 template <typename Geometry1, typename Geometry2>
317 template <typename Strategy>
318 static inline bool apply(Geometry1 const& geometry1,
319 Geometry2 const& geometry2,
320 Strategy const& strategy)
322 return resolve_strategy::covered_by
323 ::apply(geometry1, geometry2, strategy);
327 template <BOOST_VARIANT_ENUM_PARAMS(typename T), typename Geometry2>
328 struct covered_by<boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)>, Geometry2>
330 template <typename Strategy>
331 struct visitor: boost::static_visitor<bool>
333 Geometry2 const& m_geometry2;
334 Strategy const& m_strategy;
336 visitor(Geometry2 const& geometry2, Strategy const& strategy)
337 : m_geometry2(geometry2), m_strategy(strategy) {}
339 template <typename Geometry1>
340 bool operator()(Geometry1 const& geometry1) const
342 return covered_by<Geometry1, Geometry2>
343 ::apply(geometry1, m_geometry2, m_strategy);
347 template <typename Strategy>
349 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry1,
350 Geometry2 const& geometry2,
351 Strategy const& strategy)
353 return boost::apply_visitor(visitor<Strategy>(geometry2, strategy), geometry1);
357 template <typename Geometry1, BOOST_VARIANT_ENUM_PARAMS(typename T)>
358 struct covered_by<Geometry1, boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> >
360 template <typename Strategy>
361 struct visitor: boost::static_visitor<bool>
363 Geometry1 const& m_geometry1;
364 Strategy const& m_strategy;
366 visitor(Geometry1 const& geometry1, Strategy const& strategy)
367 : m_geometry1(geometry1), m_strategy(strategy) {}
369 template <typename Geometry2>
370 bool operator()(Geometry2 const& geometry2) const
372 return covered_by<Geometry1, Geometry2>
373 ::apply(m_geometry1, geometry2, m_strategy);
377 template <typename Strategy>
379 apply(Geometry1 const& geometry1,
380 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T)> const& geometry2,
381 Strategy const& strategy)
383 return boost::apply_visitor(visitor<Strategy>(geometry1, strategy), geometry2);
388 BOOST_VARIANT_ENUM_PARAMS(typename T1),
389 BOOST_VARIANT_ENUM_PARAMS(typename T2)
392 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)>,
393 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)>
396 template <typename Strategy>
397 struct visitor: boost::static_visitor<bool>
399 Strategy const& m_strategy;
401 visitor(Strategy const& strategy): m_strategy(strategy) {}
403 template <typename Geometry1, typename Geometry2>
404 bool operator()(Geometry1 const& geometry1,
405 Geometry2 const& geometry2) const
407 return covered_by<Geometry1, Geometry2>
408 ::apply(geometry1, geometry2, m_strategy);
412 template <typename Strategy>
414 apply(boost::variant<BOOST_VARIANT_ENUM_PARAMS(T1)> const& geometry1,
415 boost::variant<BOOST_VARIANT_ENUM_PARAMS(T2)> const& geometry2,
416 Strategy const& strategy)
418 return boost::apply_visitor(visitor<Strategy>(strategy), geometry1, geometry2);
422 } // namespace resolve_variant
426 \brief \brief_check12{is inside or on border}
428 \details \details_check12{covered_by, is inside or on border}.
429 \tparam Geometry1 \tparam_geometry
430 \tparam Geometry2 \tparam_geometry
431 \param geometry1 \param_geometry which might be inside or on the border of the second geometry
432 \param geometry2 \param_geometry which might cover the first geometry
433 \return true if geometry1 is inside of or on the border of geometry2,
435 \note The default strategy is used for covered_by detection
437 \qbk{[include reference/algorithms/covered_by.qbk]}
440 template<typename Geometry1, typename Geometry2>
441 inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2)
443 return resolve_variant::covered_by<Geometry1, Geometry2>
444 ::apply(geometry1, geometry2, default_strategy());
448 \brief \brief_check12{is inside or on border} \brief_strategy
450 \details \details_check12{covered_by, is inside or on border}, \brief_strategy. \details_strategy_reasons
451 \tparam Geometry1 \tparam_geometry
452 \tparam Geometry2 \tparam_geometry
453 \param geometry1 \param_geometry which might be inside or on the border of the second geometry
454 \param geometry2 \param_geometry which might cover the first geometry
455 \param strategy strategy to be used
456 \return true if geometry1 is inside of or on the border of geometry2,
459 \qbk{distinguish,with strategy}
460 \qbk{[include reference/algorithms/covered_by.qbk]}
463 template<typename Geometry1, typename Geometry2, typename Strategy>
464 inline bool covered_by(Geometry1 const& geometry1, Geometry2 const& geometry2,
465 Strategy const& strategy)
467 return resolve_variant::covered_by<Geometry1, Geometry2>
468 ::apply(geometry1, geometry2, strategy);
471 }} // namespace boost::geometry
473 #endif // BOOST_GEOMETRY_ALGORITHMS_COVERED_BY_HPP