0

I'm implementing an immutable Quadtree in Scala and I can't understand what happens/when to split a node. These are my main references: Article 1, Article 2 and a third one I can't find now.

I understand these 3 key points of a quadtree:

  1. A node contains an object in its subtree if the object at least intersects the area covered by the node.
  2. A Quadtree has a maximum depth D and the actual depth can be different for different branches
  3. A leaf node can contain a maximum of K objects before it splits and becomes an intermediate node.

Note: objects are not points but they are 2D shapes.

My current implementation allows for intermediate nodes to hold objects but I want to simplify it and allow objects only on the leaves, but this raises a doubt.

Let's assume K=2. What happens if a have node that already contains 2 objects that covers most of its area and I add a 3rd big one one? The node splits into 4 children (point 3 above). All the 3 objects can intersect the children, so they are all moved to the each child (point 1 above). But now each child has to split and move the object to their children as they can hold only 2 objects and so on recursively.

This cycle continues indefinitely (which is bad) or until depth=D (point 2 above).

It doesn't look like having a full-depth tree just for 3 objects is a good thing. I end up with loads of pointers on many leaves to the same 3 objects and I have to scan the whole depth to look for collisions. And also insertion looks very costly.

What's wrong with my understanding?

ColOfAbRiX
  • 1,039
  • 1
  • 13
  • 27
  • There might not be a problem with your understanding so much as your expectations. Big objects are just a pain for many spatial data structures. – Jerry Federspiel Jul 09 '15 at 16:52
  • That's reassuring then. So it becomes a tradeoff with the parameter K. The more objects I can keep in a node the less this problem appear. How bad is keeping large object into intermediate nodes as I'm doing now? This surely solve that problem. – ColOfAbRiX Jul 09 '15 at 16:58

0 Answers0