From de8a2e8e457b74c4daa2c55dd101cbcd1f84c281 Mon Sep 17 00:00:00 2001 From: Adam Wulkiewicz Date: Wed, 19 Jun 2013 18:00:27 +0000 Subject: [PATCH] [geometry][index]: added covers and contains spatial predicates, as experimental for now, removed experimental reversing of spatial predicates. [SVN r84838] --- .../geometry/index/detail/predicates.hpp | 313 +++++++----------- include/boost/geometry/index/predicates.hpp | 98 +++--- 2 files changed, 168 insertions(+), 243 deletions(-) diff --git a/include/boost/geometry/index/detail/predicates.hpp b/include/boost/geometry/index/detail/predicates.hpp index 276dd2a50..28ab93227 100644 --- a/include/boost/geometry/index/detail/predicates.hpp +++ b/include/boost/geometry/index/detail/predicates.hpp @@ -34,7 +34,7 @@ struct satisfies_impl Fun fun; }; -template +template struct satisfies : satisfies_impl::value> { @@ -44,26 +44,18 @@ struct satisfies satisfies(base const& b) : base(b) {} }; -template -struct not_satisfies - : satisfies_impl::value> -{ - typedef satisfies_impl::value> base; - - not_satisfies(Fun const& f) : base(f) {} - not_satisfies(base const& b) : base(b) {} -}; - // ------------------------------------------------------------------ // +struct contains_tag {}; struct covered_by_tag {}; -struct within_tag {}; +struct covers_tag {}; struct disjoint_tag {}; struct intersects_tag {}; struct overlaps_tag {}; struct touches_tag {}; +struct within_tag {}; -template +template struct spatial_predicate { spatial_predicate(Geometry const& g) : geometry(g) {} @@ -72,6 +64,13 @@ struct spatial_predicate // ------------------------------------------------------------------ // +// TODO +// may be replaced by +// nearest_predicate +// Geometry geometry +// unsigned count +// + point_tag, path_tag + template struct nearest { @@ -107,21 +106,23 @@ struct predicate_check (predicate_check)); }; +// ------------------------------------------------------------------ // + template -struct predicate_check, value_tag> +struct predicate_check, value_tag> { template - static inline bool apply(satisfies const& p, Value const& v, Indexable const&) + static inline bool apply(satisfies const& p, Value const& v, Indexable const&) { return p.fun(v); } }; template -struct predicate_check, value_tag> +struct predicate_check, value_tag> { template - static inline bool apply(not_satisfies const& p, Value const& v, Indexable const&) + static inline bool apply(satisfies const& p, Value const& v, Indexable const&) { return !p.fun(v); } @@ -135,6 +136,16 @@ struct spatial_predicate_call BOOST_MPL_ASSERT_MSG(false, NOT_IMPLEMENTED_FOR_THIS_TAG, (Tag)); }; +template <> +struct spatial_predicate_call +{ + template + static inline bool apply(G1 const& g1, G2 const& g2) + { + return geometry::within(g2, g1); + } +}; + template <> struct spatial_predicate_call { @@ -145,6 +156,16 @@ struct spatial_predicate_call } }; +template <> +struct spatial_predicate_call +{ + template + static inline bool apply(G1 const& g1, G2 const& g2) + { + return geometry::covered_by(g2, g1); + } +}; + template <> struct spatial_predicate_call { @@ -199,9 +220,9 @@ struct spatial_predicate_call // spatial predicate template -struct predicate_check, value_tag> +struct predicate_check, value_tag> { - typedef spatial_predicate Pred; + typedef spatial_predicate Pred; template static inline bool apply(Pred const& p, Value const&, Indexable const& i) @@ -212,9 +233,9 @@ struct predicate_check, value_tag // negated spatial predicate template -struct predicate_check, value_tag> +struct predicate_check, value_tag> { - typedef spatial_predicate Pred; + typedef spatial_predicate Pred; template static inline bool apply(Pred const& p, Value const&, Indexable const& i) @@ -223,32 +244,6 @@ struct predicate_check, value_tag> } }; -// reversed spatial predicate -template -struct predicate_check, value_tag> -{ - typedef spatial_predicate Pred; - - template - static inline bool apply(Pred const& p, Value const&, Indexable const& i) - { - return spatial_predicate_call::apply(p.geometry, i); - } -}; - -// negated reversed spatial predicate -template -struct predicate_check, value_tag> -{ - typedef spatial_predicate Pred; - - template - static inline bool apply(Pred const& p, Value const&, Indexable const& i) - { - return !spatial_predicate_call::apply(p.geometry, i); - } -}; - // ------------------------------------------------------------------ // template @@ -275,21 +270,11 @@ struct predicate_check, value_tag> // predicates_check for bounds // ------------------------------------------------------------------ // -template -struct predicate_check, bounds_tag> +template +struct predicate_check, bounds_tag> { template - static bool apply(satisfies const&, Value const&, Box const&) - { - return true; - } -}; - -template -struct predicate_check, bounds_tag> -{ - template - static bool apply(not_satisfies const&, Value const&, Box const&) + static bool apply(satisfies const&, Value const&, Box const&) { return true; } @@ -297,10 +282,12 @@ struct predicate_check, bounds_tag> // ------------------------------------------------------------------ // -// NOT REVERSED +// NOT NEGATED // value_tag bounds_tag // --------------------------- +// contains(I,G) contains(I,G) // covered_by(I,G) intersects(I,G) +// covers(I,G) covers(I,G) // disjoint(I,G) !covered_by(I,G) // intersects(I,G) intersects(I,G) // overlaps(I,G) intersects(I,G) - possibly change to the version without border case, e.g. intersects_without_border(0,0x1,1, 1,1x2,2) should give false @@ -309,9 +296,9 @@ struct predicate_check, bounds_tag> // spatial predicate - default template -struct predicate_check, bounds_tag> +struct predicate_check, bounds_tag> { - typedef spatial_predicate Pred; + typedef spatial_predicate Pred; template static inline bool apply(Pred const& p, Value const&, Indexable const& i) @@ -320,11 +307,37 @@ struct predicate_check, bounds_ta } }; +// spatial predicate - contains +template +struct predicate_check, bounds_tag> +{ + typedef spatial_predicate Pred; + + template + static inline bool apply(Pred const& p, Value const&, Indexable const& i) + { + return spatial_predicate_call::apply(i, p.geometry); + } +}; + +// spatial predicate - covers +template +struct predicate_check, bounds_tag> +{ + typedef spatial_predicate Pred; + + template + static inline bool apply(Pred const& p, Value const&, Indexable const& i) + { + return spatial_predicate_call::apply(i, p.geometry); + } +}; + // spatial predicate - disjoint template -struct predicate_check, bounds_tag> +struct predicate_check, bounds_tag> { - typedef spatial_predicate Pred; + typedef spatial_predicate Pred; template static inline bool apply(Pred const& p, Value const&, Indexable const& i) @@ -333,10 +346,12 @@ struct predicate_check, } }; -// NEGATED, NOT REVERSED +// NEGATED // value_tag bounds_tag // --------------------------- +// !contains(I,G) TRUE // !covered_by(I,G) !covered_by(I,G) +// !covers(I,G) TRUE // !disjoint(I,G) !disjoint(I,G) // !intersects(I,G) !covered_by(I,G) // !overlaps(I,G) TRUE @@ -345,9 +360,9 @@ struct predicate_check, // negated spatial predicate - default template -struct predicate_check, bounds_tag> +struct predicate_check, bounds_tag> { - typedef spatial_predicate Pred; + typedef spatial_predicate Pred; template static inline bool apply(Pred const& p, Value const&, Indexable const& i) @@ -356,11 +371,37 @@ struct predicate_check, bounds_tag } }; +// negated spatial predicate - contains +template +struct predicate_check, bounds_tag> +{ + typedef spatial_predicate Pred; + + template + static inline bool apply(Pred const& p, Value const&, Indexable const& i) + { + return true; + } +}; + +// negated spatial predicate - covers +template +struct predicate_check, bounds_tag> +{ + typedef spatial_predicate Pred; + + template + static inline bool apply(Pred const& p, Value const&, Indexable const& i) + { + return true; + } +}; + // negated spatial predicate - intersects template -struct predicate_check, bounds_tag> +struct predicate_check, bounds_tag> { - typedef spatial_predicate Pred; + typedef spatial_predicate Pred; template static inline bool apply(Pred const& p, Value const&, Indexable const& i) @@ -371,9 +412,9 @@ struct predicate_check, // negated spatial predicate - overlaps template -struct predicate_check, bounds_tag> +struct predicate_check, bounds_tag> { - typedef spatial_predicate Pred; + typedef spatial_predicate Pred; template static inline bool apply(Pred const& p, Value const&, Indexable const& i) @@ -384,133 +425,9 @@ struct predicate_check, b // negated spatial predicate - touches template -struct predicate_check, bounds_tag> +struct predicate_check, bounds_tag> { - typedef spatial_predicate Pred; - - template - static inline bool apply(Pred const& p, Value const&, Indexable const& i) - { - return !spatial_predicate_call::apply(i, p.geometry); - } -}; - -// REVERSED -// value_tag bounds_tag -// --------------------------- -// covered_by(G,I) covered_by(G,I) -// disjoint(G,I) !covered_by(I,G) -// intersects(G,I) intersects(I,G) -// overlaps(G,I) intersects(I,G) - possibly change to the version without border case, e.g. intersects_without_border(0,0x1,1, 1,1x2,2) should give false -// touches(G,I) intersects(I,G) -// within(G,I) within(G,I) - -// reversed spatial predicate - default -template -struct predicate_check, bounds_tag> -{ - typedef spatial_predicate Pred; - - template - static inline bool apply(Pred const& p, Value const&, Indexable const& i) - { - return spatial_predicate_call::apply(i, p.geometry); - } -}; - -// reversed spatial predicate - covered_by -template -struct predicate_check, bounds_tag> -{ - typedef spatial_predicate Pred; - - template - static inline bool apply(Pred const& p, Value const&, Indexable const& i) - { - return spatial_predicate_call::apply(p.geometry, i); - } -}; - -// reversed spatial predicate - disjoint -template -struct predicate_check, bounds_tag> -{ - typedef spatial_predicate Pred; - - template - static inline bool apply(Pred const& p, Value const&, Indexable const& i) - { - return !spatial_predicate_call::apply(i, p.geometry); - } -}; - -// reversed spatial predicate - within -template -struct predicate_check, bounds_tag> -{ - typedef spatial_predicate Pred; - - template - static inline bool apply(Pred const& p, Value const&, Indexable const& i) - { - return spatial_predicate_call::apply(p.geometry, i); - } -}; - -// NEGATED, REVERSED -// value_tag bounds_tag -// --------------------------- -// !covered_by(G,I) TRUE -// !disjoint(G,I) !disjoint(I,G) -// !intersects(G,I) !covered_by(I,G) -// !overlaps(G,I) TRUE -// !touches(G,I) !intersects(I,G) -// !within(G,I) TRUE - -// negated reversed spatial predicate - default -template -struct predicate_check, bounds_tag> -{ - typedef spatial_predicate Pred; - - template - static inline bool apply(Pred const& p, Value const&, Indexable const& i) - { - return true; - } -}; - -// negated reversed spatial predicate - disjoint -template -struct predicate_check, bounds_tag> -{ - typedef spatial_predicate Pred; - - template - static inline bool apply(Pred const& p, Value const&, Indexable const& i) - { - return !spatial_predicate_call::apply(i, p.geometry); - } -}; - -// negated reversed spatial predicate - disjoint -template -struct predicate_check, bounds_tag> -{ - typedef spatial_predicate Pred; - - template - static inline bool apply(Pred const& p, Value const&, Indexable const& i) - { - return !spatial_predicate_call::apply(i, p.geometry); - } -}; - -// negated reversed spatial predicate - touches -template -struct predicate_check, bounds_tag> -{ - typedef spatial_predicate Pred; + typedef spatial_predicate Pred; template static inline bool apply(Pred const& p, Value const&, Indexable const& i) diff --git a/include/boost/geometry/index/predicates.hpp b/include/boost/geometry/index/predicates.hpp index dbbd5cb04..5bf88df05 100644 --- a/include/boost/geometry/index/predicates.hpp +++ b/include/boost/geometry/index/predicates.hpp @@ -15,9 +15,6 @@ #include #include -// TODO: awulkiew - temporary -#include - #include #include @@ -48,10 +45,10 @@ bgi::query(spatial_index, bgi::contains(box), std::back_inserter(result)); \param g The Geometry object. */ template inline -detail::spatial_predicate +detail::spatial_predicate contains(Geometry const& g) { - return detail::spatial_predicate(g); + return detail::spatial_predicate(g); } #endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL @@ -75,12 +72,41 @@ bgi::query(spatial_index, bgi::covered_by(box), std::back_inserter(result)); \param g The Geometry object. */ template inline -detail::spatial_predicate +detail::spatial_predicate covered_by(Geometry const& g) { - return detail::spatial_predicate(g); + return detail::spatial_predicate(g); } +#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL + +/*! +\brief Generate \c covers() predicate. + +Generate a predicate defining Value and Geometry relationship. +Value will be returned by the query if bg::covered_by(Geometry, Indexable) +returns true. + +\par Example +\verbatim +bgi::query(spatial_index, bgi::covers(box), std::back_inserter(result)); +\endverbatim + +\ingroup predicates + +\tparam Geometry The Geometry type. + +\param g The Geometry object. +*/ +template inline +detail::spatial_predicate +covers(Geometry const& g) +{ + return detail::spatial_predicate(g); +} + +#endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL + /*! \brief Generate \c disjoint() predicate. @@ -100,10 +126,10 @@ bgi::query(spatial_index, bgi::disjoint(box), std::back_inserter(result)); \param g The Geometry object. */ template inline -detail::spatial_predicate +detail::spatial_predicate disjoint(Geometry const& g) { - return detail::spatial_predicate(g); + return detail::spatial_predicate(g); } /*! @@ -127,10 +153,10 @@ bgi::query(spatial_index, bgi::intersects(polygon), std::back_inserter(result)); \param g The Geometry object. */ template inline -detail::spatial_predicate +detail::spatial_predicate intersects(Geometry const& g) { - return detail::spatial_predicate(g); + return detail::spatial_predicate(g); } /*! @@ -152,10 +178,10 @@ bgi::query(spatial_index, bgi::overlaps(box), std::back_inserter(result)); \param g The Geometry object. */ template inline -detail::spatial_predicate +detail::spatial_predicate overlaps(Geometry const& g) { - return detail::spatial_predicate(g); + return detail::spatial_predicate(g); } #ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL @@ -174,10 +200,10 @@ returns true. \param g The Geometry object. */ template inline -detail::spatial_predicate +detail::spatial_predicate touches(Geometry const& g) { - return detail::spatial_predicate(g); + return detail::spatial_predicate(g); } #endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL @@ -201,10 +227,10 @@ bgi::query(spatial_index, bgi::within(box), std::back_inserter(result)); \param g The Geometry object. */ template inline -detail::spatial_predicate +detail::spatial_predicate within(Geometry const& g) { - return detail::spatial_predicate(g); + return detail::spatial_predicate(g); } /*! @@ -241,10 +267,10 @@ std::back_inserter(result)); \param pred The unary predicate function or function object. */ template inline -detail::satisfies +detail::satisfies satisfies(UnaryPredicate const& pred) { - return detail::satisfies(pred); + return detail::satisfies(pred); } /*! @@ -311,38 +337,20 @@ namespace detail { // operator! generators -template inline -not_satisfies -operator!(satisfies const& p) +template inline +satisfies +operator!(satisfies const& p) { - return not_satisfies(p); + return satisfies(p); } -template inline -satisfies -operator!(not_satisfies const& p) +template inline +spatial_predicate +operator!(spatial_predicate const& p) { - return satisfies(p); + return spatial_predicate(p.geometry); } -template inline -spatial_predicate -operator!(spatial_predicate const& p) -{ - return spatial_predicate(p.geometry); -} - -#ifdef BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL - -template inline -spatial_predicate -operator~(spatial_predicate const& p) -{ - return spatial_predicate(p.geometry); -} - -#endif // BOOST_GEOMETRY_INDEX_DETAIL_EXPERIMENTAL - // operator&& generators template inline