diff --git a/include/boost/geometry/extensions/index/rtree/visitors/insert.hpp b/include/boost/geometry/extensions/index/rtree/visitors/insert.hpp index 06d15f042..639e171e9 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/insert.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/insert.hpp @@ -23,11 +23,12 @@ namespace detail { // Default choose_next_node template -struct choose_next_node; +class choose_next_node; template -struct choose_next_node +class choose_next_node { +public: typedef typename Options::parameters_type parameters_type; typedef typename rtree::node::type node; @@ -345,13 +346,14 @@ protected: // Insert visitor forward declaration template -struct insert; +class insert; // Default insert visitor used for nodes elements template -struct insert +class insert : public detail::insert { +public: typedef detail::insert base; typedef typename base::node node; typedef typename base::internal_node internal_node; @@ -398,9 +400,10 @@ struct insert -struct insert +class insert : public detail::insert { +public: typedef detail::insert base; typedef typename base::node node; typedef typename base::internal_node internal_node; diff --git a/include/boost/geometry/extensions/index/rtree/visitors/nearest.hpp b/include/boost/geometry/extensions/index/rtree/visitors/nearest.hpp index c85bfaf74..f11d64f4b 100644 --- a/include/boost/geometry/extensions/index/rtree/visitors/nearest.hpp +++ b/include/boost/geometry/extensions/index/rtree/visitors/nearest.hpp @@ -112,7 +112,11 @@ public: inline distance_type comparable_distance() const { - return m_neighbors.size() < 0 + // smallest distance is in the first neighbor only + // if there is at least m_count values found + // this is just for safety reasons since is_comparable_distance_valid() is checked earlier + // TODO - may be replaced by ASSERT + return m_neighbors.size() < m_count ? (std::numeric_limits::max)() : m_neighbors.front().first; } diff --git a/test/rtree/test_rtree.hpp b/test/rtree/test_rtree.hpp index 4d4a01965..72b0a1c7d 100644 --- a/test/rtree/test_rtree.hpp +++ b/test/rtree/test_rtree.hpp @@ -21,6 +21,32 @@ #include #include +// Set point's coordinates + +template +struct generate_outside_point +{}; + +template +struct generate_outside_point< bg::model::point > +{ + typedef bg::model::point P; + static P apply() + { + return P(13, 26); + } +}; + +template +struct generate_outside_point< bg::model::point > +{ + typedef bg::model::point P; + static P apply() + { + return P(13, 26, 13); + } +}; + // Values, input and rtree generation template @@ -480,6 +506,21 @@ void test_nearest_k(Rtree const& rtree, std::vector const& input, Point c } } +// rtree nearest not found + +template +void test_nearest_not_found(Rtree const& rtree, Point const& pt, CoordinateType max_distance_1, CoordinateType max_distance_k) +{ + typename Rtree::value_type output; + size_t n_res = rtree.nearest(bgi::max_bounded(pt, max_distance_1), output); + BOOST_CHECK(0 == n_res); + + std::vector output_v; + n_res = rtree.nearest(bgi::max_bounded(pt, max_distance_k), 5, std::back_inserter(output_v)); + BOOST_CHECK(output_v.size() == n_res); + BOOST_CHECK(n_res < 5); +} + // rtree copying and moving template @@ -580,6 +621,7 @@ void test_rtree_by_value(Parameters const& parameters) test_nearest(tree, input, pt); test_nearest_k(tree, input, pt, 10); + test_nearest_not_found(tree, generate_outside_point

::apply(), 1, 3); test_copy_assignment_move(tree, qbox);