the physic world this QuadTree belongs to
bounds of the node
Optionalmax_objects: number = 4max objects a node can hold before splitting into 4 subnodes
Optionalmax_levels: number = 4total max levels inside root Quadtree
Optionallevel: number = 0deepth level, required for subnodes
return true if the node has any children
true if the node has any children
Insert the given object into the node. If the node exceeds the capacity, it will split and add all objects to their corresponding subnodes.
object to be added
Insert the given object container into the node.
group of objects to be added
return true if the node is prunable
true if the node is prunable
Remove the given item from the quadtree. (this function won't recalculate the impacted node)
object to be removed
true if the item was found and removed.
Recursively remove the given container and its descendants from
the quadtree. Mirrors insertContainer so the broadphase can be
kept in sync when a subtree is detached via
Container.removeChildNow between two world.update() rebuilds
(pointer events fire async in that window and would otherwise
hit destroyed renderables).
group of objects to be removed
Return all objects that could collide with the given object.
Re-entrancy contract: when called with no explicit result
argument, this method reuses a single root-level scratch array to
avoid per-frame allocations. The returned reference is therefore
not safe to retain past the next retrieve() call, AND it is
not safe to issue another scratch-mode retrieve() while iterating
the previous result — the second call clears the scratch and
refills it, corrupting the outer iteration. In-engine callers
(pointerevent.ts, detector.js) iterate synchronously and never
recurse into retrieve(), so they're fine. User-facing portable
APIs (adapter.queryAABB, adapter.raycast) pass their own array
via the result parameter, which bypasses the scratch entirely
and is safe to call from inside collision handlers.
object to be checked against
Optionalfn: objecta sorting function for the returned array
Optionalresult: object[]optional caller-supplied result array. Pass an explicit (typically empty) array to sidestep the shared scratch — required for re-entrancy safety.
array with all detected objects
a QuadTree implementation in JavaScript, a 2d spatial subdivision algorithm.
See
game.world.broadphase