QuadTree icon indicating copy to clipboard operation
QuadTree copied to clipboard

When dividing the rectangle, now its child-points will be moved to the new child-rectangles

Open uWynell opened this issue 4 years ago • 2 comments

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? image But if you add a second point, the tree will probably look like this: image 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.

uWynell avatar Feb 27 '21 11:02 uWynell

The tests need to be fixed too 😨

uWynell avatar Feb 27 '21 11:02 uWynell

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!

crhallberg avatar Mar 02 '21 15:03 crhallberg

Covered by #61.

crhallberg avatar Oct 05 '22 20:10 crhallberg