Skip to content

Bug for points sharing the same coordinate #9

@kletzi

Description

@kletzi

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions