diff --git a/doc/generated/predicates.qbk b/doc/generated/predicates.qbk index 3d01a4ace..842f6cd75 100644 --- a/doc/generated/predicates.qbk +++ b/doc/generated/predicates.qbk @@ -4,51 +4,14 @@ [heading Functions] [table [[Function][Description]] -[[[link group__predicates_1ga150fd87dc53e5472f8905bb5827428e2 `empty()`]][Generate empty predicate. ]] -[[[link group__predicates_1ga5c93efac97377136564623cbaf35d880 `value(ValuePredicate const &)`]][Generate value predicate. ]] [[[link group__predicates_1ga0a613a7f1d18ac33955bfdc2c5777c61 `covered_by(Geometry const &)`]][Generate [^[link group__predicates_1ga0a613a7f1d18ac33955bfdc2c5777c61 covered_by()]] predicate. ]] [[[link group__predicates_1ga351bb3b82e019ff45adf789385b8007d `disjoint(Geometry const &)`]][Generate [^[link group__predicates_1ga351bb3b82e019ff45adf789385b8007d disjoint()]] predicate. ]] [[[link group__predicates_1ga7301c50e0272976b9f1434536383e6d0 `intersects(Geometry const &)`]][Generate [^[link group__predicates_1ga7301c50e0272976b9f1434536383e6d0 intersects()]] predicate. ]] [[[link group__predicates_1ga5511236f56be1defcccbf11e742ccd88 `overlaps(Geometry const &)`]][Generate [^[link group__predicates_1ga5511236f56be1defcccbf11e742ccd88 overlaps()]] predicate. ]] [[[link group__predicates_1gabf9c4e76dd8a09a4c476f2f8fa8a0e4d `within(Geometry const &)`]][Generate [^[link group__predicates_1gabf9c4e76dd8a09a4c476f2f8fa8a0e4d within()]] predicate. ]] +[[[link group__predicates_1ga8acb81106fce01da72f310184ab4d9ce `value(Fun const &)`]][Generate value predicate. ]] ] -[#group__predicates_1ga150fd87dc53e5472f8905bb5827428e2] -[section empty()] -Generate empty predicate. - -[heading Synopsis] -[pre - -`detail::empty boost::geometry::index::empty``()` -] - -[endsect] - -[#group__predicates_1ga5c93efac97377136564623cbaf35d880] -[section value(ValuePredicate const &)] -Generate value predicate. - -[heading Description] -A wrapper around user-defined functor describing if Value should be returned by spatial query.[heading Synopsis] -[pre -`template<``typename ValuePredicate``>` -`detail::value boost::geometry::index::value``(``ValuePredicate const &` `vpred``)` -] - -[heading Template parameter(s)] -[table -[[Parameter] [Description]] -[[`ValuePredicate`][Functor type.]] -] - -[heading Parameter(s)] -[table -[[Type][Name][Description]] -[[`ValuePredicate const &`][ `vpred` ][The functor. ]] -] -[endsect] - [#group__predicates_1ga0a613a7f1d18ac33955bfdc2c5777c61] [section covered_by(Geometry const &)] Generate [^[link group__predicates_1ga0a613a7f1d18ac33955bfdc2c5777c61 covered_by()]] predicate. @@ -169,5 +132,29 @@ Generate a predicate defining Value and Geometry relationship. Value will be ret ] [endsect] +[#group__predicates_1ga8acb81106fce01da72f310184ab4d9ce] +[section value(Fun const &)] +Generate value predicate. + +[heading Description] +A wrapper around user-defined functor describing if Value should be returned by spatial query.[heading Synopsis] +[pre +`template<``typename Fun``>` +`detail::value boost::geometry::index::value``(``Fun const &` `fun``)` +] + +[heading Template parameter(s)] +[table +[[Parameter] [Description]] +[[`Fun`][Functor type.]] +] + +[heading Parameter(s)] +[table +[[Type][Name][Description]] +[[`Fun const &`][ `fun` ][The functor. ]] +] +[endsect] + [endsect] diff --git a/doc/generated/rtree.qbk b/doc/generated/rtree.qbk index 77217a4c9..468603b25 100644 --- a/doc/generated/rtree.qbk +++ b/doc/generated/rtree.qbk @@ -624,7 +624,7 @@ It may be generated by one of the functions listed below: * [^`! `[link group__predicates_1ga7301c50e0272976b9f1434536383e6d0 boost::geometry::index::intersects()]], * [^`! `[link group__predicates_1ga5511236f56be1defcccbf11e742ccd88 boost::geometry::index::overlaps()]], * [^`! `[link group__predicates_1gabf9c4e76dd8a09a4c476f2f8fa8a0e4d boost::geometry::index::within()]] -* [^[link group__predicates_1ga5c93efac97377136564623cbaf35d880 boost::geometry::index::value()]]. +* [^[link group__predicates_1ga8acb81106fce01da72f310184ab4d9ce boost::geometry::index::value()]]. Those predicates may be passed together in [^`std::pair`] or [^`boost::tuple`].[heading Synopsis] @@ -742,7 +742,7 @@ It may be generated by one of the functions listed below: * [^`! `[link group__predicates_1ga7301c50e0272976b9f1434536383e6d0 boost::geometry::index::intersects()]], * [^`! `[link group__predicates_1ga5511236f56be1defcccbf11e742ccd88 boost::geometry::index::overlaps()]], * [^`! `[link group__predicates_1gabf9c4e76dd8a09a4c476f2f8fa8a0e4d boost::geometry::index::within()]] -* [^[link group__predicates_1ga5c93efac97377136564623cbaf35d880 boost::geometry::index::value()]]. +* [^[link group__predicates_1ga8acb81106fce01da72f310184ab4d9ce boost::geometry::index::value()]]. Those predicates may be passed together in [^`std::pair`] or [^`boost::tuple`].[heading Synopsis] @@ -861,7 +861,7 @@ It may be generated by one of the functions listed below: * [^`! `[link group__predicates_1ga7301c50e0272976b9f1434536383e6d0 boost::geometry::index::intersects()]], * [^`! `[link group__predicates_1ga5511236f56be1defcccbf11e742ccd88 boost::geometry::index::overlaps()]], * [^`! `[link group__predicates_1gabf9c4e76dd8a09a4c476f2f8fa8a0e4d boost::geometry::index::within()]] -* [^[link group__predicates_1ga5c93efac97377136564623cbaf35d880 boost::geometry::index::value()]]. +* [^[link group__predicates_1ga8acb81106fce01da72f310184ab4d9ce boost::geometry::index::value()]]. Those predicates may be passed together in [^`std::pair`] or [^`boost::tuple`].[heading Synopsis] diff --git a/doc/html/geometry_index/r_tree/reference.html b/doc/html/geometry_index/r_tree/reference.html index d5275416f..b121a57eb 100644 --- a/doc/html/geometry_index/r_tree/reference.html +++ b/doc/html/geometry_index/r_tree/reference.html @@ -47,7 +47,7 @@ boost::geometry::index::rtree

- + The R-tree spatial index.

@@ -2659,7 +2659,7 @@ The R-tree spatial index. ! boost::geometry::index::within()
  • - boost::geometry::index::value(). + boost::geometry::index::value().
  • @@ -3042,7 +3042,7 @@ The R-tree spatial index. ! boost::geometry::index::within()

  • - boost::geometry::index::value(). + boost::geometry::index::value().
  • @@ -3460,7 +3460,7 @@ The R-tree spatial index. ! boost::geometry::index::within()

  • - boost::geometry::index::value(). + boost::geometry::index::value().
  • @@ -5902,7 +5902,7 @@ The R-tree spatial index. boost::geometry::index::linear

    - + Linear r-tree creation algorithm parameters.

    @@ -5977,7 +5977,7 @@ Linear r-tree creation algorithm parameters. boost::geometry::index::quadratic

    - + Quadratic r-tree creation algorithm parameters.

    @@ -6052,7 +6052,7 @@ Quadratic r-tree creation algorithm parameters. boost::geometry::index::rstar

    - + R*-tree creation algorithm parameters.

    @@ -6156,7 +6156,7 @@ R*-tree creation algorithm parameters. boost::geometry::index::runtime::linear

    - + Linear r-tree creation algorithm parameters.

    @@ -6292,7 +6292,7 @@ Linear r-tree creation algorithm parameters. boost::geometry::index::runtime::quadratic

    - + Quadratic r-tree creation algorithm parameters.

    @@ -6428,7 +6428,7 @@ Quadratic r-tree creation algorithm parameters. boost::geometry::index::runtime::rstar

    - + R*-tree creation algorithm parameters.

    @@ -6627,31 +6627,6 @@ R*-tree creation algorithm parameters. - -

    - empty() -

    - - -

    - Generate empty predicate. -

    - - - - -

    - value(ValuePredicate const - &) -

    - - -

    - Generate value predicate. -

    - - -

    covered_by(Geometry const @@ -6721,128 +6696,23 @@ R*-tree creation algorithm parameters.

    + + +

    + value(Fun const + &) +

    + + +

    + Generate value predicate. +

    + +
    -

    - Generate empty predicate. -

    -
    - - Synopsis -
    -
    detail::empty boost::geometry::index::empty()
    -
    -
    -
    - -

    - Generate value predicate. -

    -
    - - Description -
    -

    - A wrapper around user-defined functor describing if Value should be returned - by spatial query. -

    -
    - - Synopsis -
    -
    template<typename ValuePredicate>
    -detail::value<ValuePredicate> boost::geometry::index::value(ValuePredicate const & vpred)
    -
    -
    - - Template - parameter(s) -
    -
    ---- - - - - - - - - -
    -

    - Parameter -

    -
    -

    - Description -

    -
    -

    - ValuePredicate -

    -
    -

    - Functor type. -

    -
    -
    - - Parameter(s) -
    -
    ----- - - - - - - - - - - -
    -

    - Type -

    -
    -

    - Name -

    -
    -

    - Description -

    -
    -

    - ValuePredicate const & -

    -
    -

    - vpred -

    -
    -

    - The functor. -

    -
    -
    -
    - @@ -7371,6 +7241,111 @@ R*-tree creation algorithm parameters.
    +
    + +

    + Generate value predicate. +

    +
    + + Description +
    +

    + A wrapper around user-defined functor describing if Value should be returned + by spatial query. +

    +
    + + Synopsis +
    +
    template<typename Fun>
    +detail::value<Fun> boost::geometry::index::value(Fun const & fun)
    +
    +
    + + Template + parameter(s) +
    +
    ++++ + + + + + + + + +
    +

    + Parameter +

    +
    +

    + Description +

    +
    +

    + Fun +

    +
    +

    + Functor type. +

    +
    +
    + + Parameter(s) +
    +
    +++++ + + + + + + + + + + +
    +

    + Type +

    +
    +

    + Name +

    +
    +

    + Description +

    +
    +

    + Fun const + & +

    +
    +

    + fun +

    +
    +

    + The functor. +

    +
    +

    @@ -8760,7 +8735,7 @@ R*-tree creation algorithm parameters. boost::geometry::index::translator::def

    - + The default translator.

    @@ -8830,7 +8805,7 @@ The default translator. boost::geometry::index::translator::index

    - + The index translator.

    diff --git a/doc/html/index.html b/doc/html/index.html index d6c5fafcd..36e65ecb6 100644 --- a/doc/html/index.html +++ b/doc/html/index.html @@ -52,7 +52,7 @@ - +

    Last revised: January 19, 2013 at 02:30:02 GMT

    Last revised: January 24, 2013 at 13:47:55 GMT


    diff --git a/include/boost/geometry/index/detail/predicates.hpp b/include/boost/geometry/index/detail/predicates.hpp index 9ea3172ab..e835fd9a6 100644 --- a/include/boost/geometry/index/detail/predicates.hpp +++ b/include/boost/geometry/index/detail/predicates.hpp @@ -22,11 +22,11 @@ namespace boost { namespace geometry { namespace index { namespace detail { struct empty {}; -template +template struct value { - value(ValuePredicate const& vpred) : value_predicate(vpred) {} - ValuePredicate value_predicate; + value(Fun const& f) : fun(f) {} + Fun fun; }; template @@ -150,13 +150,13 @@ struct predicate_check } }; -template -struct predicate_check, value_tag> +template +struct predicate_check, value_tag> { template - static inline bool apply(value const& p, Value const& v, Indexable const&) + static inline bool apply(value const& p, Value const& v, Indexable const&) { - return p.value_predicate(v); + return p.fun(v); } }; @@ -304,11 +304,11 @@ struct predicate_check } }; -template -struct predicate_check, envelope_tag> +template +struct predicate_check, envelope_tag> { template - static bool apply(value const&, Value const&, Box const&) + static bool apply(value const&, Value const&, Box const&) { return true; } diff --git a/include/boost/geometry/index/predicates.hpp b/include/boost/geometry/index/predicates.hpp index c992e5a9b..4644c2003 100644 --- a/include/boost/geometry/index/predicates.hpp +++ b/include/boost/geometry/index/predicates.hpp @@ -26,34 +26,6 @@ namespace boost { namespace geometry { namespace index { -/*! -\brief Generate empty predicate. - -\ingroup predicates -*/ -inline detail::empty empty() -{ - return detail::empty(); -} - -/*! -\brief Generate value predicate. - -A wrapper around user-defined functor -describing if Value should be returned by spatial query. - -\ingroup predicates - -\tparam ValuePredicate Functor type. - -\param vpred The functor. -*/ -template -inline detail::value value(ValuePredicate const& vpred) -{ - return detail::value(vpred); -} - /*! \brief Generate \c covered_by() predicate. @@ -168,92 +140,114 @@ inline detail::within within(Geometry const& g) return detail::within(g); } -}}} // namespace boost::geometry::index +/*! +\brief Generate value predicate. + +A wrapper around user-defined functor +describing if Value should be returned by spatial query. + +\ingroup predicates + +\tparam Fun Functor type. + +\param fun The functor. +*/ +template +inline detail::value value(Fun const& fun) +{ + return detail::value(fun); +} + +namespace detail { // operator! generators template -boost::geometry::index::detail::not_covered_by -operator!(boost::geometry::index::detail::covered_by const& p) +not_covered_by +operator!(covered_by const& p) { - return boost::geometry::index::detail::not_covered_by(p.geometry); + return not_covered_by(p.geometry); } template -boost::geometry::index::detail::covered_by -operator!(boost::geometry::index::detail::not_covered_by const& p) +covered_by +operator!(not_covered_by const& p) { - return boost::geometry::index::detail::covered_by(p.geometry); + return covered_by(p.geometry); } template -boost::geometry::index::detail::not_disjoint -operator!(boost::geometry::index::detail::disjoint const& p) +not_disjoint +operator!(disjoint const& p) { - return boost::geometry::index::detail::not_disjoint(p.geometry); + return not_disjoint(p.geometry); } template -boost::geometry::index::detail::disjoint -operator!(boost::geometry::index::detail::not_disjoint const& p) +disjoint +operator!(not_disjoint const& p) { - return boost::geometry::index::detail::disjoint(p.geometry); + return disjoint(p.geometry); } template -boost::geometry::index::detail::not_intersects -operator!(boost::geometry::index::detail::intersects const& p) +not_intersects +operator!(intersects const& p) { - return boost::geometry::index::detail::not_intersects(p.geometry); + return not_intersects(p.geometry); } template -boost::geometry::index::detail::intersects -operator!(boost::geometry::index::detail::not_intersects const& p) +intersects +operator!(not_intersects const& p) { - return boost::geometry::index::detail::intersects(p.geometry); + return intersects(p.geometry); } template -boost::geometry::index::detail::not_overlaps -operator!(boost::geometry::index::detail::overlaps const& p) +not_overlaps +operator!(overlaps const& p) { - return boost::geometry::index::detail::not_overlaps(p.geometry); + return not_overlaps(p.geometry); } template -boost::geometry::index::detail::overlaps -operator!(boost::geometry::index::detail::not_overlaps const& p) +overlaps +operator!(not_overlaps const& p) { - return boost::geometry::index::detail::overlaps(p.geometry); + return overlaps(p.geometry); } //template -//boost::geometry::index::detail::not_touches -//operator!(boost::geometry::index::detail::touches const& p) +//not_touches +//operator!(touches const& p) //{ -// return boost::geometry::index::detail::not_touches(p.geometry); +// return not_touches(p.geometry); //} // //template -//boost::geometry::index::detail::touches -//operator!(boost::geometry::index::detail::not_touches const& p) +//touches +//operator!(not_touches const& p) //{ -// return boost::geometry::index::detail::touches(p.geometry); +// return touches(p.geometry); //} template -boost::geometry::index::detail::not_within -operator!(boost::geometry::index::detail::within const& p) +not_within +operator!(within const& p) { - return boost::geometry::index::detail::not_within(p.geometry); + return not_within(p.geometry); } template -boost::geometry::index::detail::within -operator!(boost::geometry::index::detail::not_within const& p) +within +operator!(not_within const& p) { - return boost::geometry::index::detail::within(p.geometry); + return within(p.geometry); } + +} // namespace detail + +}}} // namespace boost::geometry::index #endif // BOOST_GEOMETRY_INDEX_PREDICATES_HPP diff --git a/tests/additional_speed.cpp b/tests/additional_speed.cpp index 642342c13..cd6c20b7c 100644 --- a/tests/additional_speed.cpp +++ b/tests/additional_speed.cpp @@ -85,7 +85,6 @@ int main() result.reserve(100); B result_one; - // query test { tim.restart(); size_t temp = 0; @@ -101,9 +100,47 @@ int main() std::cout << time << "s - spatial_query(B) " << queries_count << " found " << temp << '\n'; } + { + tim.restart(); + size_t temp = 0; + for (size_t i = 0 ; i < queries_count / 2 ; ++i ) + { + float x1 = coords[i].first; + float y1 = coords[i].second; + float x2 = coords[i+1].first; + float y2 = coords[i+1].second; + float x3 = coords[i+2].first; + float y3 = coords[i+2].second; + result.clear(); + t.spatial_query( + boost::make_tuple( + bgi::intersects(B(P(x1 - 10, y1 - 10), P(x1 + 10, y1 + 10))), + !bgi::within(B(P(x2 - 10, y2 - 10), P(x2 + 10, y2 + 10))), + !bgi::overlaps(B(P(x3 - 10, y3 - 10), P(x3 + 10, y3 + 10))) + ), + std::back_inserter(result) + ); + temp += result.size(); + } + double time = tim.elapsed(); + std::cout << time << "s - spatial_query(i, !w, !o) " << queries_count << " found " << temp << '\n'; + } + result.clear(); - // searching test + { + tim.restart(); + size_t temp = 0; + for (size_t i = 0 ; i < queries_count / 10 ; ++i ) + { + float x = coords[i].first + 100; + float y = coords[i].second + 100; + temp += t.nearest_query(P(x, y), result_one); + } + double time = tim.elapsed(); + std::cout << time << "s - nearest_query(P) " << (queries_count / 10) << " found " << temp << '\n'; + } + { tim.restart(); size_t temp = 0; @@ -125,13 +162,21 @@ int main() { float x = coords[i].first + 100; float y = coords[i].second + 100; - temp += t.nearest_query(P(x, y), result_one); + result.clear(); + temp += t.nearest_query( + bgi::bounded( + bgi::to_nearest(P(x, y)), + bgi::to_centroid(0), + bgi::to_furthest(100000) + ), + 5, + std::back_inserter(result) + ); } double time = tim.elapsed(); - std::cout << time << "s - nearest_query(P) " << (queries_count / 10) << " found " << temp << '\n'; + std::cout << time << "s - nearest_query(bounded(n, c, f), 5) " << (queries_count / 10) << " found " << temp << '\n'; } - // inserting test { tim.restart(); for (size_t i = 0 ; i < values_count / 10 ; ++i ) @@ -145,6 +190,8 @@ int main() double time = tim.elapsed(); std::cout << time << "s - remove " << values_count / 10 << '\n'; } + + std::cout << "------------------------------------------------\n"; } return 0;