Broken KdNode equals and compareTo causes the KdTree not to return all valid results#159
Open
maraswrona wants to merge 2 commits intophishman3579:masterfrom
Open
Broken KdNode equals and compareTo causes the KdTree not to return all valid results#159maraswrona wants to merge 2 commits intophishman3579:masterfrom
maraswrona wants to merge 2 commits intophishman3579:masterfrom
Conversation
added 2 commits
April 22, 2021 15:09
…ent 3D points to be interpreted as equal (and hence the tree not returning all valid results)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
By submitting this pull request I confirm I've read and complied with the below requirements.
Added {Algorithm/DS name} [{Language}], notUpdate README.mdorAdded new code.I haven't done the above, so won't mark the checklist as the CONTRIBUTING.md file DOES NOT EXIST.
TL;DR; Calling
kdTree.nearestNeighbourSearch(K, point)where K >= the size of the tree should return all the tree elements - but sometimes it doesn't (whether it works or not depends on the points coordinates). This PR fixes it. For more details, read below.So first of all, thank you very much for this repository and all the implementations. I have been looking closely at the KdTree implementation to build my own and after extensive testing I noticed that this implementation is broken. Here is why:
examinedHashSet so we don't visit an already visited branch.Set.containsmethod from java relies heavily on equals and hashcode implementations - objects equality must be checked carefully.Which is already incorrect as those could be two completely different points
I have added a test case demonstrating this behavior + this small PR fixing it. I'm only fixing the compareTo method of the KdNode, but frankly also the hashCode implementations should be changed.