Skip to content

Commit

Permalink
cleaning up
Browse files Browse the repository at this point in the history
  • Loading branch information
RafiKueng committed Dec 29, 2011
2 parents 04c17b3 + 7c97913 commit 4e44d5d
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions kdtree/kdtree.py
Expand Up @@ -392,27 +392,26 @@ def search_nn(self, point, best=None):
return best


def search_nn_dist(self, point, distance, best=None):
@require_axis
def search_nn_dist(self, point, distance, best=[]):
"""
Search the n nearest nodes of the given point which are within given distance
point must be a location, not a node. A list containing the n nearest nodes to
the point within the distance is returned.
"""
Search the n nearest nodes of the given point which are within given
distance
if best is None:
best = []
point must be a location, not a node. A list containing the n nearest
nodes to the point within the distance will be returned.
"""

# consider the current node
if self.dist(point) < distance: #best.dist(point):
if self.dist(point) < distance:
best.append(self)

# sort the children, nearer one first
# sort the children, nearer one first (is this really necessairy?)
children = sorted(self.children, key=lambda (c, p): c.dist(point))

for child, p in children:
# check if node needs to be recursed
if self.axis_dist(point, self.axis) < distance: #best.dist(point):
# check if child node needs to be recursed
if self.axis_dist(point, self.axis) < distance:
child.search_nn_dist(point, distance, best)

return best
Expand Down

0 comments on commit 4e44d5d

Please sign in to comment.