crvs / KDTree

Simple C++ KD-Tree implementation
BSD 3-Clause "New" or "Revised" License
197 stars 71 forks source link

how can i get k-nearest points #10

Closed long-senpai closed 5 months ago

long-senpai commented 7 months ago

Hi, thank you so much for the cool work. I wonder is there anyway to get the list of K nearest points?

crvs commented 6 months ago

Uh, sorry for the late reply, there is currently no way of doing so, but it should be fairly straightforward to add by just keeping a list as we iterate through the tree

crvs commented 6 months ago

Working on the implementation in this branch https://github.com/crvs/KDTree/tree/knn

slocked commented 5 months ago

Hi there, thank you so much for the cool work. I want to report a bug in your knn branch. It seems master branch supports 2D points, but knn branch does not support 2D points.

crvs commented 5 months ago

thanks for reporting, as of yet the branch is not fit for use, I will try to debug that as well.

crvs commented 5 months ago

@slocked can you provide a minimal example reproducing the error? The error_test.cpp seems to work fine for me when I substitute the point size to 2.

slocked commented 5 months ago
  1. First I build up a solution composed of {KDTree.hpp(master branch), KDTree.cpp(master branch), error_test.cpp(master branch)}.
  2. Running error_test.cpp with DIM=2 and DIM=3 works fine.
  3. Substitute the solution file to {KDTree.hpp(knn branch), KDTree.cpp(knn branch), error_test.cpp(knn branch)}.
  4. Running error_test.cpp with DIM=2 and DIM=3 works fine.
  5. Rebuild the solution and run, then I get an error promt saying that "cannot dereference end list iterator" when calling the function nearest_point.
  6. Substitute error_test.cpp to knn_error_test.cpp and run will get the same error.
crvs commented 5 months ago

Are you sure you tested that in the latest commit to the KNN branch (as of yesterday)? because there was indeed an error in the commit before that (from May 10 I think) where the "nearest" query had a segfault.

crvs commented 5 months ago

also, the newest patch should have finally fixed the KNN query.

crvs commented 5 months ago

v2.0 introduces this feature