~ai.tron/armagetronad/0.4-winlibs-updated

« back to all changes in this revision

Viewing changes to boost/includes/boost/geometry/index/predicates.hpp

  • Committer: Nik K.
  • Date: 2013-11-07 16:58:35 UTC
  • Revision ID: nik.karbaum@gmail.com-20131107165835-kq99jz23drfj4dkh
Forgot to add some files; here they are

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Boost.Geometry Index
 
2
//
 
3
// Spatial query predicates
 
4
//
 
5
// Copyright (c) 2011-2013 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
 
 
21
/*!
 
22
\defgroup predicates Predicates (boost::geometry::index::)
 
23
*/
 
24
 
 
25
namespace boost { namespace geometry { namespace index {
 
26
 
 
27
#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
 
28
 
 
29
/*!
 
30
\brief Generate \c contains() predicate.
 
31
 
 
32
Generate a predicate defining Value and Geometry relationship.
 
33
Value will be returned by the query if <tt>bg::within(Geometry, Indexable)</tt>
 
34
returns true.
 
35
 
 
36
\par Example
 
37
\verbatim
 
38
bgi::query(spatial_index, bgi::contains(box), std::back_inserter(result));
 
39
\endverbatim
 
40
 
 
41
\ingroup predicates
 
42
 
 
43
\tparam Geometry    The Geometry type.
 
44
 
 
45
\param g            The Geometry object.
 
46
*/
 
47
template <typename Geometry> inline
 
48
detail::spatial_predicate<Geometry, detail::contains_tag, false>
 
49
contains(Geometry const& g)
 
50
{
 
51
    return detail::spatial_predicate<Geometry, detail::contains_tag, false>(g);
 
52
}
 
53
 
 
54
#endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
 
55
 
 
56
/*!
 
57
\brief Generate \c covered_by() predicate.
 
58
 
 
59
Generate a predicate defining Value and Geometry relationship.
 
60
Value will be returned by the query if <tt>bg::covered_by(Indexable, Geometry)</tt>
 
61
returns true.
 
62
 
 
63
\par Example
 
64
\verbatim
 
65
bgi::query(spatial_index, bgi::covered_by(box), std::back_inserter(result));
 
66
\endverbatim
 
67
 
 
68
\ingroup predicates
 
69
 
 
70
\tparam Geometry    The Geometry type.
 
71
 
 
72
\param g            The Geometry object.
 
73
*/
 
74
template <typename Geometry> inline
 
75
detail::spatial_predicate<Geometry, detail::covered_by_tag, false>
 
76
covered_by(Geometry const& g)
 
77
{
 
78
    return detail::spatial_predicate<Geometry, detail::covered_by_tag, false>(g);
 
79
}
 
80
 
 
81
#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
 
82
 
 
83
/*!
 
84
\brief Generate \c covers() predicate.
 
85
 
 
86
Generate a predicate defining Value and Geometry relationship.
 
87
Value will be returned by the query if <tt>bg::covered_by(Geometry, Indexable)</tt>
 
88
returns true.
 
89
 
 
90
\par Example
 
91
\verbatim
 
92
bgi::query(spatial_index, bgi::covers(box), std::back_inserter(result));
 
93
\endverbatim
 
94
 
 
95
\ingroup predicates
 
96
 
 
97
\tparam Geometry    The Geometry type.
 
98
 
 
99
\param g            The Geometry object.
 
100
*/
 
101
template <typename Geometry> inline
 
102
detail::spatial_predicate<Geometry, detail::covers_tag, false>
 
103
covers(Geometry const& g)
 
104
{
 
105
    return detail::spatial_predicate<Geometry, detail::covers_tag, false>(g);
 
106
}
 
107
 
 
108
#endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
 
109
 
 
110
/*!
 
111
\brief Generate \c disjoint() predicate.
 
112
 
 
113
Generate a predicate defining Value and Geometry relationship.
 
114
Value will be returned by the query if <tt>bg::disjoint(Indexable, Geometry)</tt>
 
115
returns true.
 
116
 
 
117
\par Example
 
118
\verbatim
 
119
bgi::query(spatial_index, bgi::disjoint(box), std::back_inserter(result));
 
120
\endverbatim
 
121
 
 
122
\ingroup predicates
 
123
 
 
124
\tparam Geometry    The Geometry type.
 
125
 
 
126
\param g            The Geometry object.
 
127
*/
 
128
template <typename Geometry> inline
 
129
detail::spatial_predicate<Geometry, detail::disjoint_tag, false>
 
130
disjoint(Geometry const& g)
 
131
{
 
132
    return detail::spatial_predicate<Geometry, detail::disjoint_tag, false>(g);
 
133
}
 
134
 
 
135
/*!
 
136
\brief Generate \c intersects() predicate.
 
137
 
 
138
Generate a predicate defining Value and Geometry relationship.
 
139
Value will be returned by the query if <tt>bg::intersects(Indexable, Geometry)</tt>
 
140
returns true.
 
141
 
 
142
\par Example
 
143
\verbatim
 
144
bgi::query(spatial_index, bgi::intersects(box), std::back_inserter(result));
 
145
bgi::query(spatial_index, bgi::intersects(ring), std::back_inserter(result));
 
146
bgi::query(spatial_index, bgi::intersects(polygon), std::back_inserter(result));
 
147
\endverbatim
 
148
 
 
149
\ingroup predicates
 
150
 
 
151
\tparam Geometry    The Geometry type.
 
152
 
 
153
\param g            The Geometry object.
 
154
*/
 
155
template <typename Geometry> inline
 
156
detail::spatial_predicate<Geometry, detail::intersects_tag, false>
 
157
intersects(Geometry const& g)
 
158
{
 
159
    return detail::spatial_predicate<Geometry, detail::intersects_tag, false>(g);
 
160
}
 
161
 
 
162
/*!
 
163
\brief Generate \c overlaps() predicate.
 
164
 
 
165
Generate a predicate defining Value and Geometry relationship.
 
166
Value will be returned by the query if <tt>bg::overlaps(Indexable, Geometry)</tt>
 
167
returns true.
 
168
 
 
169
\par Example
 
170
\verbatim
 
171
bgi::query(spatial_index, bgi::overlaps(box), std::back_inserter(result));
 
172
\endverbatim
 
173
 
 
174
\ingroup predicates
 
175
 
 
176
\tparam Geometry    The Geometry type.
 
177
 
 
178
\param g            The Geometry object.
 
179
*/
 
180
template <typename Geometry> inline
 
181
detail::spatial_predicate<Geometry, detail::overlaps_tag, false>
 
182
overlaps(Geometry const& g)
 
183
{
 
184
    return detail::spatial_predicate<Geometry, detail::overlaps_tag, false>(g);
 
185
}
 
186
 
 
187
#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
 
188
 
 
189
/*!
 
190
\brief Generate \c touches() predicate.
 
191
 
 
192
Generate a predicate defining Value and Geometry relationship.
 
193
Value will be returned by the query if <tt>bg::touches(Indexable, Geometry)</tt>
 
194
returns true.
 
195
 
 
196
\ingroup predicates
 
197
 
 
198
\tparam Geometry    The Geometry type.
 
199
 
 
200
\param g            The Geometry object.
 
201
*/
 
202
template <typename Geometry> inline
 
203
detail::spatial_predicate<Geometry, detail::touches_tag, false>
 
204
touches(Geometry const& g)
 
205
{
 
206
    return detail::spatial_predicate<Geometry, detail::touches_tag, false>(g);
 
207
}
 
208
 
 
209
#endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
 
210
 
 
211
/*!
 
212
\brief Generate \c within() predicate.
 
213
 
 
214
Generate a predicate defining Value and Geometry relationship.
 
215
Value will be returned by the query if <tt>bg::within(Indexable, Geometry)</tt>
 
216
returns true.
 
217
 
 
218
\par Example
 
219
\verbatim
 
220
bgi::query(spatial_index, bgi::within(box), std::back_inserter(result));
 
221
\endverbatim
 
222
 
 
223
\ingroup predicates
 
224
 
 
225
\tparam Geometry    The Geometry type.
 
226
 
 
227
\param g            The Geometry object.
 
228
*/
 
229
template <typename Geometry> inline
 
230
detail::spatial_predicate<Geometry, detail::within_tag, false>
 
231
within(Geometry const& g)
 
232
{
 
233
    return detail::spatial_predicate<Geometry, detail::within_tag, false>(g);
 
234
}
 
235
 
 
236
/*!
 
237
\brief Generate satisfies() predicate.
 
238
 
 
239
A wrapper around user-defined UnaryPredicate checking if Value should be returned by spatial query.
 
240
 
 
241
\par Example
 
242
\verbatim
 
243
bool is_red(Value const& v) { return v.is_red(); }
 
244
 
 
245
struct is_red_o {
 
246
template <typename Value> bool operator()(Value const& v) { return v.is_red(); }
 
247
}
 
248
 
 
249
// ...
 
250
 
 
251
rt.query(index::intersects(box) && index::satisfies(is_red),
 
252
std::back_inserter(result));
 
253
 
 
254
rt.query(index::intersects(box) && index::satisfies(is_red_o()),
 
255
std::back_inserter(result));
 
256
 
 
257
#ifndef BOOST_NO_CXX11_LAMBDAS
 
258
rt.query(index::intersects(box) && index::satisfies([](Value const& v) { return v.is_red(); }),
 
259
std::back_inserter(result));
 
260
#endif
 
261
\endverbatim
 
262
 
 
263
\ingroup predicates
 
264
 
 
265
\tparam UnaryPredicate  A type of unary predicate function or function object.
 
266
 
 
267
\param pred             The unary predicate function or function object.
 
268
*/
 
269
template <typename UnaryPredicate> inline
 
270
detail::satisfies<UnaryPredicate, false>
 
271
satisfies(UnaryPredicate const& pred)
 
272
{
 
273
    return detail::satisfies<UnaryPredicate, false>(pred);
 
274
}
 
275
 
 
276
/*!
 
277
\brief Generate nearest() predicate.
 
278
 
 
279
When nearest predicate is passed to the query, k-nearest neighbour search will be performed.
 
280
\c nearest() predicate takes a \c Point from which distance to \c Values is calculated
 
281
and the maximum number of \c Values that should be returned.
 
282
 
 
283
\par Example
 
284
\verbatim
 
285
bgi::query(spatial_index, bgi::nearest(pt, 5), std::back_inserter(result));
 
286
bgi::query(spatial_index, bgi::nearest(pt, 5) && bgi::intersects(box), std::back_inserter(result));
 
287
\endverbatim
 
288
 
 
289
\warning
 
290
Only one \c nearest() predicate may be used in a query.
 
291
 
 
292
\ingroup predicates
 
293
 
 
294
\param point        The point from which distance is calculated.
 
295
\param k            The maximum number of values to return.
 
296
*/
 
297
template <typename Point> inline
 
298
detail::nearest<Point>
 
299
nearest(Point const& point, unsigned k)
 
300
{
 
301
    return detail::nearest<Point>(point, k);
 
302
}
 
303
 
 
304
#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
 
305
 
 
306
/*!
 
307
\brief Generate path() predicate.
 
308
 
 
309
When path predicate is passed to the query, the returned values are k values along the path closest to
 
310
its begin. \c path() predicate takes a \c Segment or a \c Linestring defining the path and the maximum
 
311
number of \c Values that should be returned.
 
312
 
 
313
\par Example
 
314
\verbatim
 
315
bgi::query(spatial_index, bgi::path(segment, 5), std::back_inserter(result));
 
316
bgi::query(spatial_index, bgi::path(linestring, 5) && bgi::intersects(box), std::back_inserter(result));
 
317
\endverbatim
 
318
 
 
319
\warning
 
320
Only one distance predicate (\c nearest() or \c path()) may be used in a query.
 
321
 
 
322
\ingroup predicates
 
323
 
 
324
\param linestring   The path along which distance is calculated.
 
325
\param k            The maximum number of values to return.
 
326
*/
 
327
template <typename SegmentOrLinestring> inline
 
328
detail::path<SegmentOrLinestring>
 
329
path(SegmentOrLinestring const& linestring, unsigned k)
 
330
{
 
331
    return detail::path<SegmentOrLinestring>(linestring, k);
 
332
}
 
333
 
 
334
#endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
 
335
 
 
336
namespace detail {
 
337
 
 
338
// operator! generators
 
339
 
 
340
template <typename Fun, bool Negated> inline
 
341
satisfies<Fun, !Negated>
 
342
operator!(satisfies<Fun, Negated> const& p)
 
343
{
 
344
    return satisfies<Fun, !Negated>(p);
 
345
}
 
346
 
 
347
template <typename Geometry, typename Tag, bool Negated> inline
 
348
spatial_predicate<Geometry, Tag, !Negated>
 
349
operator!(spatial_predicate<Geometry, Tag, Negated> const& p)
 
350
{
 
351
    return spatial_predicate<Geometry, Tag, !Negated>(p.geometry);
 
352
}
 
353
 
 
354
// operator&& generators
 
355
 
 
356
template <typename Pred1, typename Pred2> inline
 
357
boost::tuples::cons<
 
358
    Pred1,
 
359
    boost::tuples::cons<Pred2, boost::tuples::null_type>
 
360
>
 
361
operator&&(Pred1 const& p1, Pred2 const& p2)
 
362
{
 
363
    /*typedef typename boost::mpl::if_c<is_predicate<Pred1>::value, Pred1, Pred1 const&>::type stored1;
 
364
    typedef typename boost::mpl::if_c<is_predicate<Pred2>::value, Pred2, Pred2 const&>::type stored2;*/
 
365
    namespace bt = boost::tuples;
 
366
 
 
367
    return
 
368
    bt::cons< Pred1, bt::cons<Pred2, bt::null_type> >
 
369
        ( p1, bt::cons<Pred2, bt::null_type>(p2, bt::null_type()) );
 
370
}
 
371
 
 
372
template <typename Head, typename Tail, typename Pred> inline
 
373
typename tuples::push_back_impl<
 
374
    boost::tuples::cons<Head, Tail>,
 
375
    Pred,
 
376
    0,
 
377
    boost::tuples::length<boost::tuples::cons<Head, Tail> >::value
 
378
>::type
 
379
operator&&(boost::tuples::cons<Head, Tail> const& t, Pred const& p)
 
380
{
 
381
    //typedef typename boost::mpl::if_c<is_predicate<Pred>::value, Pred, Pred const&>::type stored;
 
382
    namespace bt = boost::tuples;
 
383
 
 
384
    return
 
385
    tuples::push_back_impl<
 
386
        bt::cons<Head, Tail>, Pred, 0, bt::length< bt::cons<Head, Tail> >::value
 
387
    >::apply(t, p);
 
388
}
 
389
    
 
390
} // namespace detail
 
391
 
 
392
}}} // namespace boost::geometry::index
 
393
 
 
394
#endif // BOOST_GEOMETRY_INDEX_PREDICATES_HPP