QuadTree
QuadTree copied to clipboard
When dividing the rectangle, now its child-points will be moved to the new child-rectangles
I may be wrong and would like to hear objective criticism about this pull request
Why?
Reason number 1
Imagine a QuadTree with a capacity of 1.
When you insert a point, everything's fine, right?
But if you add a second point, the tree will probably look like this:
Because the red point is counted as a child of the top-right rectangle, while the black point is still counted as a child of the big main rectangle. So that's you would visually see these two points in the same rectangle. Remember that the capacity of this tree is 1. For me, it looks pretty wrong.
Reason number 2
Now in the query() function, the loop runs only on the smallest squares (that are not divided), I believe this increases the searching performance.
The tests need to be fixed too 😨
Hey! Thank you for the contribution! We had some discussion about this a few years but never really reached a conclusion.
The basic points are:
- We need to account for an edge case where adding points in identical or near identical positions can cause an infinite loop.
- Whether or not the added complexity means this repository is less useful as a teaching tool, which is its primary function.
Either way I think your implementation is clean and easy to understand! While you're figuring out the issues with the tests, I'd recommend expanding this line to match the code style and be a little less of a magic one-liner. Thank you!
Covered by #61.