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 <boost/geometry/index/detail/predicates.hpp>
15 #include <boost/geometry/index/detail/tuples.hpp>
16 
21 namespace boost { namespace geometry { namespace index {
22 
41 template <typename Geometry> inline
42 detail::predicates::spatial_predicate<Geometry, detail::predicates::contains_tag, false>
43 contains(Geometry const& g)
44 {
45  return detail::predicates::spatial_predicate
46  <
47  Geometry,
48  detail::predicates::contains_tag,
49  false
50  >(g);
51 }
52 
71 template <typename Geometry> inline
72 detail::predicates::spatial_predicate<Geometry, detail::predicates::covered_by_tag, false>
73 covered_by(Geometry const& g)
74 {
75  return detail::predicates::spatial_predicate
76  <
77  Geometry,
78  detail::predicates::covered_by_tag,
79  false
80  >(g);
81 }
82 
101 template <typename Geometry> inline
102 detail::predicates::spatial_predicate<Geometry, detail::predicates::covers_tag, false>
103 covers(Geometry const& g)
104 {
105  return detail::predicates::spatial_predicate
106  <
107  Geometry,
108  detail::predicates::covers_tag,
109  false
110  >(g);
111 }
112 
131 template <typename Geometry> inline
132 detail::predicates::spatial_predicate<Geometry, detail::predicates::disjoint_tag, false>
133 disjoint(Geometry const& g)
134 {
135  return detail::predicates::spatial_predicate
136  <
137  Geometry,
138  detail::predicates::disjoint_tag,
139  false
140  >(g);
141 }
142 
163 template <typename Geometry> inline
164 detail::predicates::spatial_predicate<Geometry, detail::predicates::intersects_tag, false>
165 intersects(Geometry const& g)
166 {
167  return detail::predicates::spatial_predicate
168  <
169  Geometry,
170  detail::predicates::intersects_tag,
171  false
172  >(g);
173 }
174 
193 template <typename Geometry> inline
194 detail::predicates::spatial_predicate<Geometry, detail::predicates::overlaps_tag, false>
195 overlaps(Geometry const& g)
196 {
197  return detail::predicates::spatial_predicate
198  <
199  Geometry,
200  detail::predicates::overlaps_tag,
201  false
202  >(g);
203 }
204 
205 #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
206 
220 template <typename Geometry> inline
221 detail::predicates::spatial_predicate<Geometry, detail::predicates::touches_tag, false>
222 touches(Geometry const& g)
223 {
224  return detail::predicates::spatial_predicate
225  <
226  Geometry,
227  detail::predicates::touches_tag,
228  false
229  >(g);
230 }
231 
232 #endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
233 
252 template <typename Geometry> inline
253 detail::predicates::spatial_predicate<Geometry, detail::predicates::within_tag, false>
254 within(Geometry const& g)
255 {
256  return detail::predicates::spatial_predicate
257  <
258  Geometry,
259  detail::predicates::within_tag,
260  false
261  >(g);
262 }
263 
297 template <typename UnaryPredicate> inline
298 detail::predicates::satisfies<UnaryPredicate, false>
299 satisfies(UnaryPredicate const& pred)
300 {
301  return detail::predicates::satisfies<UnaryPredicate, false>(pred);
302 }
303 
327 template <typename Geometry> inline
328 detail::predicates::nearest<Geometry>
329 nearest(Geometry const& geometry, unsigned k)
330 {
331  return detail::predicates::nearest<Geometry>(geometry, k);
332 }
333 
334 #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
335 
357 template <typename SegmentOrLinestring> inline
358 detail::predicates::path<SegmentOrLinestring>
359 path(SegmentOrLinestring const& linestring, unsigned k)
360 {
361  return detail::predicates::path<SegmentOrLinestring>(linestring, k);
362 }
363 
364 #endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
365 
366 namespace detail { namespace predicates {
367 
368 // operator! generators
369 
370 template <typename Fun, bool Negated> inline
371 satisfies<Fun, !Negated>
372 operator!(satisfies<Fun, Negated> const& p)
373 {
374  return satisfies<Fun, !Negated>(p);
375 }
376 
377 template <typename Geometry, typename Tag, bool Negated> inline
378 spatial_predicate<Geometry, Tag, !Negated>
379 operator!(spatial_predicate<Geometry, Tag, Negated> const& p)
380 {
381  return spatial_predicate<Geometry, Tag, !Negated>(p.geometry);
382 }
383 
384 // operator&& generators
385 
386 template <typename Pred1, typename Pred2> inline
387 boost::tuples::cons<
388  Pred1,
389  boost::tuples::cons<Pred2, boost::tuples::null_type>
390 >
391 operator&&(Pred1 const& p1, Pred2 const& p2)
392 {
393  /*typedef typename boost::mpl::if_c<is_predicate<Pred1>::value, Pred1, Pred1 const&>::type stored1;
394  typedef typename boost::mpl::if_c<is_predicate<Pred2>::value, Pred2, Pred2 const&>::type stored2;*/
395  namespace bt = boost::tuples;
396 
397  return
398  bt::cons< Pred1, bt::cons<Pred2, bt::null_type> >
399  ( p1, bt::cons<Pred2, bt::null_type>(p2, bt::null_type()) );
400 }
401 
402 template <typename Head, typename Tail, typename Pred> inline
403 typename tuples::push_back<
404  boost::tuples::cons<Head, Tail>, Pred
405 >::type
406 operator&&(boost::tuples::cons<Head, Tail> const& t, Pred const& p)
407 {
408  //typedef typename boost::mpl::if_c<is_predicate<Pred>::value, Pred, Pred const&>::type stored;
409  namespace bt = boost::tuples;
410 
411  return
412  tuples::push_back<
413  bt::cons<Head, Tail>, Pred
414  >::apply(t, p);
415 }
416 
417 }} // namespace detail::predicates
418 
419 }}} // namespace boost::geometry::index
420 
421 #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:195
detail::predicates::spatial_predicate< Geometry, detail::predicates::intersects_tag, false > intersects(Geometry const &g)
Generate intersects() predicate.
Definition: predicates.hpp:165
detail::predicates::nearest< Geometry > nearest(Geometry const &geometry, unsigned k)
Generate nearest() predicate.
Definition: predicates.hpp:329
detail::predicates::spatial_predicate< Geometry, detail::predicates::disjoint_tag, false > disjoint(Geometry const &g)
Generate disjoint() predicate.
Definition: predicates.hpp:133
detail::predicates::spatial_predicate< Geometry, detail::predicates::covered_by_tag, false > covered_by(Geometry const &g)
Generate covered_by() predicate.
Definition: predicates.hpp:73
detail::predicates::spatial_predicate< Geometry, detail::predicates::covers_tag, false > covers(Geometry const &g)
Generate covers() predicate.
Definition: predicates.hpp:103
detail::predicates::spatial_predicate< Geometry, detail::predicates::within_tag, false > within(Geometry const &g)
Generate within() predicate.
Definition: predicates.hpp:254
detail::predicates::satisfies< UnaryPredicate, false > satisfies(UnaryPredicate const &pred)
Generate satisfies() predicate.
Definition: predicates.hpp:299
detail::predicates::spatial_predicate< Geometry, detail::predicates::contains_tag, false > contains(Geometry const &g)
Generate contains() predicate.
Definition: predicates.hpp:43