Python-KD-Tree icon indicating copy to clipboard operation
Python-KD-Tree copied to clipboard

Bug for points sharing the same coordinate

Open kletzi opened this issue 1 year ago • 0 comments

Hi, there seems to be a bug when points share the same coordinates. See the following example:

tree = KDTree([(7, 3), (5, 3), (2, 3)], 2) print(tree.get_knn((5, 3), 2, False))

I would expect to get [(5, 3), (7, 3)] as the result, but I get [(5, 3), (2, 3)].

The solution seems to be that in line 70 instead of dx * dx < -heap[0][0] it should be <= for going into the second branch (or to make sure it works well with floats: dx * dx < -heap[0][0] + 1e-6).

With this change I get the expected result.

kletzi avatar Feb 08 '24 11:02 kletzi