Boost.Geometry.Index
 All Classes Functions Typedefs Groups
predicates.hpp
1 // Boost.Geometry Index
2 //
3 // Spatial query predicates
4 //
5 // Copyright (c) 2011-2015 Adam Wulkiewicz, Lodz, Poland.
6 //
7 // Use, modification and distribution is subject to the Boost Software License,
8 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 
11 #ifndef BOOST_GEOMETRY_INDEX_PREDICATES_HPP
12 #define BOOST_GEOMETRY_INDEX_PREDICATES_HPP
13 
14 #include <utility>
15 #include <boost/tuple/tuple.hpp>
16 #include <boost/mpl/assert.hpp>
17 
18 #include <boost/geometry/index/detail/predicates.hpp>
19 #include <boost/geometry/index/detail/tuples.hpp>
20 
25 namespace boost { namespace geometry { namespace index {
26 
45 template <typename Geometry> inline
46 detail::predicates::spatial_predicate<Geometry, detail::predicates::contains_tag, false>
47 contains(Geometry const& g)
48 {
49  return detail::predicates::spatial_predicate
50  <
51  Geometry,
52  detail::predicates::contains_tag,
53  false
54  >(g);
55 }
56 
75 template <typename Geometry> inline
76 detail::predicates::spatial_predicate<Geometry, detail::predicates::covered_by_tag, false>
77 covered_by(Geometry const& g)
78 {
79  return detail::predicates::spatial_predicate
80  <
81  Geometry,
82  detail::predicates::covered_by_tag,
83  false
84  >(g);
85 }
86 
105 template <typename Geometry> inline
106 detail::predicates::spatial_predicate<Geometry, detail::predicates::covers_tag, false>
107 covers(Geometry const& g)
108 {
109  return detail::predicates::spatial_predicate
110  <
111  Geometry,
112  detail::predicates::covers_tag,
113  false
114  >(g);
115 }
116 
135 template <typename Geometry> inline
136 detail::predicates::spatial_predicate<Geometry, detail::predicates::disjoint_tag, false>
137 disjoint(Geometry const& g)
138 {
139  return detail::predicates::spatial_predicate
140  <
141  Geometry,
142  detail::predicates::disjoint_tag,
143  false
144  >(g);
145 }
146 
167 template <typename Geometry> inline
168 detail::predicates::spatial_predicate<Geometry, detail::predicates::intersects_tag, false>
169 intersects(Geometry const& g)
170 {
171  return detail::predicates::spatial_predicate
172  <
173  Geometry,
174  detail::predicates::intersects_tag,
175  false
176  >(g);
177 }
178 
197 template <typename Geometry> inline
198 detail::predicates::spatial_predicate<Geometry, detail::predicates::overlaps_tag, false>
199 overlaps(Geometry const& g)
200 {
201  return detail::predicates::spatial_predicate
202  <
203  Geometry,
204  detail::predicates::overlaps_tag,
205  false
206  >(g);
207 }
208 
209 #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
210 
224 template <typename Geometry> inline
225 detail::predicates::spatial_predicate<Geometry, detail::predicates::touches_tag, false>
226 touches(Geometry const& g)
227 {
228  return detail::predicates::spatial_predicate
229  <
230  Geometry,
231  detail::predicates::touches_tag,
232  false
233  >(g);
234 }
235 
236 #endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
237 
256 template <typename Geometry> inline
257 detail::predicates::spatial_predicate<Geometry, detail::predicates::within_tag, false>
258 within(Geometry const& g)
259 {
260  return detail::predicates::spatial_predicate
261  <
262  Geometry,
263  detail::predicates::within_tag,
264  false
265  >(g);
266 }
267 
301 template <typename UnaryPredicate> inline
302 detail::predicates::satisfies<UnaryPredicate, false>
303 satisfies(UnaryPredicate const& pred)
304 {
305  return detail::predicates::satisfies<UnaryPredicate, false>(pred);
306 }
307 
331 template <typename Geometry> inline
332 detail::predicates::nearest<Geometry>
333 nearest(Geometry const& geometry, unsigned k)
334 {
335  return detail::predicates::nearest<Geometry>(geometry, k);
336 }
337 
338 #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
339 
361 template <typename SegmentOrLinestring> inline
362 detail::predicates::path<SegmentOrLinestring>
363 path(SegmentOrLinestring const& linestring, unsigned k)
364 {
365  return detail::predicates::path<SegmentOrLinestring>(linestring, k);
366 }
367 
368 #endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
369 
370 namespace detail { namespace predicates {
371 
372 // operator! generators
373 
374 template <typename Fun, bool Negated> inline
375 satisfies<Fun, !Negated>
376 operator!(satisfies<Fun, Negated> const& p)
377 {
378  return satisfies<Fun, !Negated>(p);
379 }
380 
381 template <typename Geometry, typename Tag, bool Negated> inline
382 spatial_predicate<Geometry, Tag, !Negated>
383 operator!(spatial_predicate<Geometry, Tag, Negated> const& p)
384 {
385  return spatial_predicate<Geometry, Tag, !Negated>(p.geometry);
386 }
387 
388 // operator&& generators
389 
390 template <typename Pred1, typename Pred2> inline
391 boost::tuples::cons<
392  Pred1,
393  boost::tuples::cons<Pred2, boost::tuples::null_type>
394 >
395 operator&&(Pred1 const& p1, Pred2 const& p2)
396 {
397  /*typedef typename boost::mpl::if_c<is_predicate<Pred1>::value, Pred1, Pred1 const&>::type stored1;
398  typedef typename boost::mpl::if_c<is_predicate<Pred2>::value, Pred2, Pred2 const&>::type stored2;*/
399  namespace bt = boost::tuples;
400 
401  return
402  bt::cons< Pred1, bt::cons<Pred2, bt::null_type> >
403  ( p1, bt::cons<Pred2, bt::null_type>(p2, bt::null_type()) );
404 }
405 
406 template <typename Head, typename Tail, typename Pred> inline
407 typename tuples::push_back<
408  boost::tuples::cons<Head, Tail>, Pred
409 >::type
410 operator&&(boost::tuples::cons<Head, Tail> const& t, Pred const& p)
411 {
412  //typedef typename boost::mpl::if_c<is_predicate<Pred>::value, Pred, Pred const&>::type stored;
413  namespace bt = boost::tuples;
414 
415  return
416  tuples::push_back<
417  bt::cons<Head, Tail>, Pred
418  >::apply(t, p);
419 }
420 
421 }} // namespace detail::predicates
422 
423 }}} // namespace boost::geometry::index
424 
425 #endif // BOOST_GEOMETRY_INDEX_PREDICATES_HPP
detail::predicates::spatial_predicate< Geometry, detail::predicates::overlaps_tag, false > overlaps(Geometry const &g)
Generate overlaps() predicate.
Definition: predicates.hpp:199
detail::predicates::spatial_predicate< Geometry, detail::predicates::intersects_tag, false > intersects(Geometry const &g)
Generate intersects() predicate.
Definition: predicates.hpp:169
detail::predicates::nearest< Geometry > nearest(Geometry const &geometry, unsigned k)
Generate nearest() predicate.
Definition: predicates.hpp:333
detail::predicates::spatial_predicate< Geometry, detail::predicates::disjoint_tag, false > disjoint(Geometry const &g)
Generate disjoint() predicate.
Definition: predicates.hpp:137
detail::predicates::spatial_predicate< Geometry, detail::predicates::covered_by_tag, false > covered_by(Geometry const &g)
Generate covered_by() predicate.
Definition: predicates.hpp:77
detail::predicates::spatial_predicate< Geometry, detail::predicates::covers_tag, false > covers(Geometry const &g)
Generate covers() predicate.
Definition: predicates.hpp:107
detail::predicates::spatial_predicate< Geometry, detail::predicates::within_tag, false > within(Geometry const &g)
Generate within() predicate.
Definition: predicates.hpp:258
detail::predicates::satisfies< UnaryPredicate, false > satisfies(UnaryPredicate const &pred)
Generate satisfies() predicate.
Definition: predicates.hpp:303
detail::predicates::spatial_predicate< Geometry, detail::predicates::contains_tag, false > contains(Geometry const &g)
Generate contains() predicate.
Definition: predicates.hpp:47