stefankoegl / kdtree

A Python implementation of a kd-tree
ISC License
365 stars 118 forks source link

Inconsistency between API docs and API implementations #40

Open betterenvi opened 6 years ago

betterenvi commented 6 years ago

In search_knn and search_nn, the APIs have an arg named dist, and the API docs say

dist is a distance function, expecting two points and returning distance value. Distance values can be any comparable type.

But in the implementations of the two APIs, only squared Euclidean distance is considered.

stefankoegl commented 6 years ago

search_knn will use Euclidean distance as a default if no own dist function is provided, see

https://github.com/stefankoegl/kdtree/blob/587edc7056d7735177ad56a84ad5abccdea91693/kdtree.py#L417-L420

search_nn calls search_knn and passes along its dist parameter.

Maybe I'm missing something here. Can you please elaborate?

betterenvi commented 6 years ago

If no own dist function is provided, everything is fine. The API will break if dist function is provided and is not squared Euclidean distance, because the implementation uses this distance.

https://github.com/stefankoegl/kdtree/blob/587edc7056d7735177ad56a84ad5abccdea91693/kdtree.py#L453-L454

stefankoegl commented 6 years ago

I have implemented a fix in #43, which should address this issue. Please let me know if this works for you.