Returns all items stored in the RTree as a flat array.undefined
An array containing all items currently stored in the tree.
Removes all items from the RTree, resetting it to an empty state.undefined
This RTree instance, for chaining.
Tests whether any item in the RTree intersects with the given bounding box.
Unlike search, this method stops as soon as the first intersection is found, making it more
efficient when you only need to know whether a collision exists rather than retrieving all results.
The bounding box to test against. Must have minX, minY, maxX, and maxY properties.
true if any item in the tree intersects with the bounding box, otherwise false.
Comparator function used to sort items by their minimum X boundary (left property).
Returns a negative number if a should sort before b, a positive number if after, or zero if equal.
The difference between the left values of the two items.
Comparator function used to sort items by their minimum Y boundary (top property).
Returns a negative number if a should sort before b, a positive number if after, or zero if equal.
The difference between the top values of the two items.
Inserts a single item into the RTree.
The item to insert. Must have left, top, right, and bottom properties.
This RTree instance, for chaining.
Bulk loads an array of items into the RTree.
Bulk loading is significantly more efficient than inserting items one by one when adding large datasets, as it builds an optimally structured tree in a single pass using the OMT algorithm. If the array is smaller than the minimum entry threshold, items are inserted individually instead.
An array of items to insert. Each item must have left, top, right, and bottom properties.
This RTree instance, for chaining.
Removes a single item from the RTree.
An optional equality function can be provided to compare items by value rather than by reference,
which is useful when the original item reference is not available. The function receives two items
and should return true if they are considered equal.
The item to remove.
OptionalequalsFn: Function
An optional custom equality function taking two items and returning a boolean.
This RTree instance, for chaining.
Searches the RTree for all items that intersect with the given bounding box and returns them as an array.
The bounding box to search within. Must have minX, minY, maxX, and maxY properties.
An array of all items in the tree that intersect with the given bounding box.
Converts a Phaser-style bounds object into the internal bounding box format used by the RTree.
Maps the left, top, right, and bottom properties of the input to minX, minY, maxX,
and maxY respectively, which is the format expected by the R-tree algorithms.
The object to convert. Must have left, top, right, and bottom properties.
A bounding box object with minX, minY, maxX, and maxY properties.
Returns the raw internal tree data as a JSON-compatible object.
The returned value can be passed to fromJSON to restore the tree state at a later point.undefined
The internal tree data object.
RBush is a high-performance JavaScript library for 2D spatial indexing of points and rectangles. It's based on an optimized R-tree data structure with bulk insertion support.
Spatial index is a special data structure for points and rectangles that allows you to perform queries like "all items within this bounding box" very efficiently (e.g. hundreds of times faster than looping over all items).
This version of RBush uses a fixed min/max accessor structure of
[ '.left', '.top', '.right', '.bottom' ]. This is to avoid the eval-like function creation that the original library used, which caused CSP policy violations.rbush is forked from https://github.com/mourner/rbush by Vladimir Agafonkin