Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r83975 - trunk/boost/geometry/index/detail/rtree/visitors
From: adam.wulkiewicz_at_[hidden]
Date: 2013-04-19 21:52:26


Author: awulkiew
Date: 2013-04-19 21:52:26 EDT (Fri, 19 Apr 2013)
New Revision: 83975
URL: http://svn.boost.org/trac/boost/changeset/83975

Log:
geometry.index.rtree: added condition in nearest query iterative visitor for safety reasons.
Text files modified:
   trunk/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp | 9 +++++----
   1 files changed, 5 insertions(+), 4 deletions(-)

Modified: trunk/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp
==============================================================================
--- trunk/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp (original)
+++ trunk/boost/geometry/index/detail/rtree/visitors/nearest_query.hpp 2013-04-19 21:52:26 EDT (Fri, 19 Apr 2013)
@@ -420,7 +420,7 @@
                 active_branch_list.pop_front();
                 rtree::apply_visitor(*this, *(active_branch.second));
 
- // remove further nodes
+ // remove nodes further than the furthest neighbour - not really needed
                 BOOST_ASSERT_MSG(neighbors.size() <= max_count(), "unexpected neighbours count");
                 if ( max_count() <= neighbors.size() )
                 {
@@ -491,7 +491,8 @@
         elements_type const& elements = rtree::elements(n);
 
         // store distance to the furthest neighbour
- value_distance_type greatest_distance = max_count() <= neighbors.size() ? neighbors.back().first : std::numeric_limits<value_distance_type>::max();
+ bool not_enough_neighbors = neighbors.size() < max_count();
+ value_distance_type greatest_distance = !not_enough_neighbors ? neighbors.back().first : std::numeric_limits<value_distance_type>::max();
         
         // search leaf for closest value meeting predicates
         for ( typename elements_type::const_iterator it = elements.begin() ; it != elements.end() ; ++it)
@@ -512,8 +513,8 @@
                     value_distance_type dist = index::detail::cdist_value<value_distances_type>
                                                 ::template get<point_relation_tag>(distances);
 
- // if there is not enough values or current value is further than currently furthest neighbour
- if ( dist < greatest_distance )
+ // if there is not enough values or current value is closer than furthest neighbour
+ if ( not_enough_neighbors || dist < greatest_distance )
                     {
                         neighbors.push_back(std::make_pair(dist, boost::addressof(*it)));
                     }


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk