This is a genuine R-tree — the same insertion and split rules used by PostGIS and other spatial databases, not a scripted animation. Every object is wrapped in a minimum bounding rectangle (MBR), and MBRs nest inside larger parent MBRs up to the root.
- Insert — at each level, the child whose MBR needs the least area enlargement to contain the new rectangle is chosen, so the tree stays tight.
- Split — when a node overflows (more than 4 entries here), a quadratic-cost split picks the two entries that would waste the most area if kept together as seeds, then distributes the rest to whichever growing group needs them least.
- Range query — starting at the root, only children whose MBR overlaps the query rectangle are visited; any branch that doesn't overlap is skipped entirely, along with every object nested inside it.
That pruning is the whole point: a well-tuned R-tree over millions of objects can answer "what's near here?" by touching only a few dozen bounding rectangles instead of scanning everything.