-
-
Notifications
You must be signed in to change notification settings - Fork 4.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
KdTree: handle 0 or negative k for nearestKSearch #4430
KdTree: handle 0 or negative k for nearestKSearch #4430
Conversation
bbddb3c
to
b752b90
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please split this PR in 2 commits at the very least: 1 with ws changes and one with logic change and one for just logic changes
std::vector<float> &k_distances) const | ||
{ | ||
assert (point_representation_->isValid (point) && "Invalid (NaN, Inf) point coordinates given to nearestKSearch!"); | ||
assert ((k >= 0) && "Invalid number of neighbors"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just accept unsigned int as input? See #4350 (only the changes in octree module)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call. Done.
b752b90
to
127c6bb
Compare
more trailing whitespace
on second thought, k is better unsigned more unsigned int ks
a984ed7
to
8713422
Compare
I switched to unsigned ints, and separated the whitespace changes from the actual changes. Let me know if you have any more suggestions. |
Why did you choose |
I think that's a good choice because |
Seems like |
Yes, I chose I did make |
I think this is ready to go. It passed CI. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would probably make sense to change k
from int
to unsigned int
in all nearestKSearch
functions (search module) in the future.
I use this function to find nearest point with radius, kdtree.radiusSearch (searchPoint, radius, pointIdxRadiusSearch, pointRadiusSquaredDistance). However this function return error with one of these coordinate < 0 like the third row in above example. Can anyone know how to fix it |
While working on #4414 I mistakenly searched for 0 nearest neighbors, and the method segfaulted. This handles that situation better, as well as if a negative k is passed (the argument is a signed integer). Also, my editor automatically removes trailing whitespace, so that's in here too. I could revert all those changes if desired.