Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:35:34

0001 // Boost.Geometry Index
0002 //
0003 // Spatial query predicates
0004 //
0005 // Copyright (c) 2011-2022 Adam Wulkiewicz, Lodz, Poland.
0006 //
0007 // This file was modified by Oracle on 2019-2021.
0008 // Modifications copyright (c) 2019-2021 Oracle and/or its affiliates.
0009 // Contributed and/or modified by Adam Wulkiewicz, on behalf of Oracle
0010 //
0011 // Use, modification and distribution is subject to the Boost Software License,
0012 // Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
0013 // http://www.boost.org/LICENSE_1_0.txt)
0014 
0015 #ifndef BOOST_GEOMETRY_INDEX_PREDICATES_HPP
0016 #define BOOST_GEOMETRY_INDEX_PREDICATES_HPP
0017 
0018 #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL
0019 #ifndef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_PREDICATES
0020 #define BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_PREDICATES
0021 #endif
0022 #endif
0023 
0024 #include <boost/geometry/index/detail/predicates.hpp>
0025 #include <boost/geometry/util/tuples.hpp>
0026 
0027 /*!
0028 \defgroup predicates Predicates (boost::geometry::index::)
0029 */
0030 
0031 namespace boost { namespace geometry { namespace index {
0032 
0033 /*!
0034 \brief Generate \c contains() predicate.
0035 
0036 Generate a predicate defining Value and Geometry relationship. With this
0037 predicate query returns indexed Values that contain passed Geometry.
0038 Value is returned by the query if <tt>bg::within(Geometry, Indexable)</tt>
0039 returns <tt>true</tt>.
0040 
0041 \par Example
0042 \verbatim
0043 bgi::query(spatial_index, bgi::contains(box), std::back_inserter(result));
0044 \endverbatim
0045 
0046 \ingroup predicates
0047 
0048 \tparam Geometry    The Geometry type.
0049 
0050 \param g            The Geometry object.
0051 */
0052 template <typename Geometry> inline
0053 detail::predicates::spatial_predicate<Geometry, detail::predicates::contains_tag, false>
0054 contains(Geometry const& g)
0055 {
0056     return detail::predicates::spatial_predicate
0057                 <
0058                     Geometry,
0059                     detail::predicates::contains_tag,
0060                     false
0061                 >(g);
0062 }
0063 
0064 /*!
0065 \brief Generate \c covered_by() predicate.
0066 
0067 Generate a predicate defining Value and Geometry relationship. With this
0068 predicate query returns indexed Values that are covered by passed Geometry.
0069 Value is returned by the query if <tt>bg::covered_by(Indexable, Geometry)</tt>
0070 returns <tt>true</tt>.
0071 
0072 \par Example
0073 \verbatim
0074 bgi::query(spatial_index, bgi::covered_by(box), std::back_inserter(result));
0075 \endverbatim
0076 
0077 \ingroup predicates
0078 
0079 \tparam Geometry    The Geometry type.
0080 
0081 \param g            The Geometry object.
0082 */
0083 template <typename Geometry> inline
0084 detail::predicates::spatial_predicate<Geometry, detail::predicates::covered_by_tag, false>
0085 covered_by(Geometry const& g)
0086 {
0087     return detail::predicates::spatial_predicate
0088                 <
0089                     Geometry,
0090                     detail::predicates::covered_by_tag,
0091                     false
0092                 >(g);
0093 }
0094 
0095 /*!
0096 \brief Generate \c covers() predicate.
0097 
0098 Generate a predicate defining Value and Geometry relationship. With this
0099 predicate query returns indexed Values that cover passed Geometry.
0100 Value is returned by the query if <tt>bg::covered_by(Geometry, Indexable)</tt>
0101 returns <tt>true</tt>.
0102 
0103 \par Example
0104 \verbatim
0105 bgi::query(spatial_index, bgi::covers(box), std::back_inserter(result));
0106 \endverbatim
0107 
0108 \ingroup predicates
0109 
0110 \tparam Geometry    The Geometry type.
0111 
0112 \param g            The Geometry object.
0113 */
0114 template <typename Geometry> inline
0115 detail::predicates::spatial_predicate<Geometry, detail::predicates::covers_tag, false>
0116 covers(Geometry const& g)
0117 {
0118     return detail::predicates::spatial_predicate
0119                 <
0120                     Geometry,
0121                     detail::predicates::covers_tag,
0122                     false
0123                 >(g);
0124 }
0125 
0126 /*!
0127 \brief Generate \c disjoint() predicate.
0128 
0129 Generate a predicate defining Value and Geometry relationship. With this
0130 predicate query returns indexed Values that are disjoint with passed Geometry.
0131 Value is returned by the query if <tt>bg::disjoint(Indexable, Geometry)</tt>
0132 returns <tt>true</tt>.
0133 
0134 \par Example
0135 \verbatim
0136 bgi::query(spatial_index, bgi::disjoint(box), std::back_inserter(result));
0137 \endverbatim
0138 
0139 \ingroup predicates
0140 
0141 \tparam Geometry    The Geometry type.
0142 
0143 \param g            The Geometry object.
0144 */
0145 template <typename Geometry> inline
0146 detail::predicates::spatial_predicate<Geometry, detail::predicates::disjoint_tag, false>
0147 disjoint(Geometry const& g)
0148 {
0149     return detail::predicates::spatial_predicate
0150                 <
0151                     Geometry,
0152                     detail::predicates::disjoint_tag,
0153                     false
0154                 >(g);
0155 }
0156 
0157 /*!
0158 \brief Generate \c intersects() predicate.
0159 
0160 Generate a predicate defining Value and Geometry relationship. With this
0161 predicate query returns indexed Values that intersect passed Geometry.
0162 Value is returned by the query if <tt>bg::intersects(Indexable, Geometry)</tt>
0163 returns <tt>true</tt>.
0164 
0165 \par Example
0166 \verbatim
0167 bgi::query(spatial_index, bgi::intersects(box), std::back_inserter(result));
0168 bgi::query(spatial_index, bgi::intersects(ring), std::back_inserter(result));
0169 bgi::query(spatial_index, bgi::intersects(polygon), std::back_inserter(result));
0170 \endverbatim
0171 
0172 \ingroup predicates
0173 
0174 \tparam Geometry    The Geometry type.
0175 
0176 \param g            The Geometry object.
0177 */
0178 template <typename Geometry> inline
0179 detail::predicates::spatial_predicate<Geometry, detail::predicates::intersects_tag, false>
0180 intersects(Geometry const& g)
0181 {
0182     return detail::predicates::spatial_predicate
0183                 <
0184                     Geometry,
0185                     detail::predicates::intersects_tag,
0186                     false
0187                 >(g);
0188 }
0189 
0190 /*!
0191 \brief Generate \c overlaps() predicate.
0192 
0193 Generate a predicate defining Value and Geometry relationship. With this
0194 predicate query returns indexed Values that overlap passed Geometry.
0195 Value is returned by the query if <tt>bg::overlaps(Indexable, Geometry)</tt>
0196 returns <tt>true</tt>.
0197 
0198 \par Example
0199 \verbatim
0200 bgi::query(spatial_index, bgi::overlaps(box), std::back_inserter(result));
0201 \endverbatim
0202 
0203 \ingroup predicates
0204 
0205 \tparam Geometry    The Geometry type.
0206 
0207 \param g            The Geometry object.
0208 */
0209 template <typename Geometry> inline
0210 detail::predicates::spatial_predicate<Geometry, detail::predicates::overlaps_tag, false>
0211 overlaps(Geometry const& g)
0212 {
0213     return detail::predicates::spatial_predicate
0214                 <
0215                     Geometry,
0216                     detail::predicates::overlaps_tag,
0217                     false
0218                 >(g);
0219 }
0220 
0221 #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_PREDICATES
0222 
0223 /*!
0224 \brief Generate \c touches() predicate.
0225 
0226 Generate a predicate defining Value and Geometry relationship. With this
0227 predicate query returns indexed Values that touch passed Geometry.
0228 Value is returned by the query if <tt>bg::touches(Indexable, Geometry)</tt>
0229 returns <tt>true</tt>.
0230 
0231 \ingroup predicates
0232 
0233 \tparam Geometry    The Geometry type.
0234 
0235 \param g            The Geometry object.
0236 */
0237 template <typename Geometry> inline
0238 detail::predicates::spatial_predicate<Geometry, detail::predicates::touches_tag, false>
0239 touches(Geometry const& g)
0240 {
0241     return detail::predicates::spatial_predicate
0242                 <
0243                     Geometry,
0244                     detail::predicates::touches_tag,
0245                     false
0246                 >(g);
0247 }
0248 
0249 #endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_PREDICATES
0250 
0251 /*!
0252 \brief Generate \c within() predicate.
0253 
0254 Generate a predicate defining Value and Geometry relationship. With this
0255 predicate query returns indexed Values that are within passed Geometry.
0256 Value is returned by the query if <tt>bg::within(Indexable, Geometry)</tt>
0257 returns <tt>true</tt>.
0258 
0259 \par Example
0260 \verbatim
0261 bgi::query(spatial_index, bgi::within(box), std::back_inserter(result));
0262 \endverbatim
0263 
0264 \ingroup predicates
0265 
0266 \tparam Geometry    The Geometry type.
0267 
0268 \param g            The Geometry object.
0269 */
0270 template <typename Geometry> inline
0271 detail::predicates::spatial_predicate<Geometry, detail::predicates::within_tag, false>
0272 within(Geometry const& g)
0273 {
0274     return detail::predicates::spatial_predicate
0275                 <
0276                     Geometry,
0277                     detail::predicates::within_tag,
0278                     false
0279                 >(g);
0280 }
0281 
0282 /*!
0283 \brief Generate satisfies() predicate.
0284 
0285 A wrapper around user-defined UnaryPredicate checking if Value should be returned by spatial query.
0286 
0287 \par Example
0288 \verbatim
0289 bool is_red(Value const& v) { return v.is_red(); }
0290 
0291 struct is_red_o {
0292 template <typename Value> bool operator()(Value const& v) { return v.is_red(); }
0293 }
0294 
0295 // ...
0296 
0297 rt.query(index::intersects(box) && index::satisfies(is_red),
0298 std::back_inserter(result));
0299 
0300 rt.query(index::intersects(box) && index::satisfies(is_red_o()),
0301 std::back_inserter(result));
0302 
0303 rt.query(index::intersects(box) && index::satisfies([](Value const& v) { return v.is_red(); }),
0304 std::back_inserter(result));
0305 \endverbatim
0306 
0307 \ingroup predicates
0308 
0309 \tparam UnaryPredicate  A type of unary predicate function or function object.
0310 
0311 \param pred             The unary predicate function or function object.
0312 */
0313 template <typename UnaryPredicate> inline
0314 detail::predicates::satisfies<UnaryPredicate, false>
0315 satisfies(UnaryPredicate const& pred)
0316 {
0317     return detail::predicates::satisfies<UnaryPredicate, false>(pred);
0318 }
0319 
0320 /*!
0321 \brief Generate nearest() predicate.
0322 
0323 When nearest predicate is passed to the query, k-nearest neighbour search will be performed.
0324 \c nearest() predicate takes a \c Geometry from which distances to \c Values are calculated
0325 and the maximum number of \c Values that should be returned. Internally
0326 boost::geometry::comparable_distance() is used to perform the calculation.
0327 
0328 \par Example
0329 \verbatim
0330 bgi::query(spatial_index, bgi::nearest(pt, 5), std::back_inserter(result));
0331 bgi::query(spatial_index, bgi::nearest(pt, 5) && bgi::intersects(box), std::back_inserter(result));
0332 bgi::query(spatial_index, bgi::nearest(box, 5), std::back_inserter(result));
0333 \endverbatim
0334 
0335 \warning
0336 Only one \c nearest() predicate may be used in a query.
0337 
0338 \ingroup predicates
0339 
0340 \param geometry     The geometry from which distance is calculated.
0341 \param k            The maximum number of values to return.
0342 */
0343 template <typename Geometry> inline
0344 detail::predicates::nearest<Geometry>
0345 nearest(Geometry const& geometry, std::size_t k)
0346 {
0347     return detail::predicates::nearest<Geometry>(geometry, k);
0348 }
0349 
0350 #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_PREDICATES
0351 
0352 /*!
0353 \brief Generate path() predicate.
0354 
0355 When path predicate is passed to the query, the returned values are k values along the path closest to
0356 its begin. \c path() predicate takes a \c Segment or a \c Linestring defining the path and the maximum
0357 number of \c Values that should be returned.
0358 
0359 \par Example
0360 \verbatim
0361 bgi::query(spatial_index, bgi::path(segment, 5), std::back_inserter(result));
0362 bgi::query(spatial_index, bgi::path(linestring, 5) && bgi::intersects(box), std::back_inserter(result));
0363 \endverbatim
0364 
0365 \warning
0366 Only one distance predicate (\c nearest() or \c path()) may be used in a query.
0367 
0368 \ingroup predicates
0369 
0370 \param linestring   The path along which distance is calculated.
0371 \param k            The maximum number of values to return.
0372 */
0373 template <typename SegmentOrLinestring> inline
0374 detail::predicates::path<SegmentOrLinestring>
0375 path(SegmentOrLinestring const& linestring, std::size_t k)
0376 {
0377     return detail::predicates::path<SegmentOrLinestring>(linestring, k);
0378 }
0379 
0380 #endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL_PREDICATES
0381 
0382 namespace detail { namespace predicates {
0383 
0384 // operator! generators
0385 
0386 template <typename Fun, bool Negated> inline
0387 satisfies<Fun, !Negated>
0388 operator!(satisfies<Fun, Negated> const& p)
0389 {
0390     return satisfies<Fun, !Negated>(p);
0391 }
0392 
0393 template <typename Geometry, typename Tag, bool Negated> inline
0394 spatial_predicate<Geometry, Tag, !Negated>
0395 operator!(spatial_predicate<Geometry, Tag, Negated> const& p)
0396 {
0397     return spatial_predicate<Geometry, Tag, !Negated>(p.geometry);
0398 }
0399 
0400 // operator&& generators
0401 
0402 template <typename Pred1, typename Pred2> inline
0403 std::tuple<Pred1, Pred2>
0404 operator&&(Pred1 const& p1, Pred2 const& p2)
0405 {
0406     /*typedef std::conditional_t<is_predicate<Pred1>::value, Pred1, Pred1 const&> stored1;
0407     typedef std::conditional_t<is_predicate<Pred2>::value, Pred2, Pred2 const&> stored2;*/
0408     return std::tuple<Pred1, Pred2>(p1, p2);
0409 }
0410 
0411 template <typename ...Preds, typename Pred> inline
0412 typename geometry::tuples::push_back
0413     <
0414         std::tuple<Preds...>, Pred
0415     >::type
0416 operator&&(std::tuple<Preds...> const& t, Pred const& p)
0417 {
0418     //typedef std::conditional_t<is_predicate<Pred>::value, Pred, Pred const&> stored;
0419     return geometry::tuples::push_back
0420             <
0421                 std::tuple<Preds...>, Pred
0422             >::apply(t, p);
0423 }
0424 
0425 }} // namespace detail::predicates
0426 
0427 }}} // namespace boost::geometry::index
0428 
0429 #endif // BOOST_GEOMETRY_INDEX_PREDICATES_HPP