PokéRogue
    Preparing search index...

    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

    Index
    • Returns all items stored in the RTree as a flat array.undefined

      Returns any[]

      An array containing all items currently stored in the tree.

    • Removes all items from the RTree, resetting it to an empty state.undefined

      Returns RTree

      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.

      Parameters

      • bbox: Object

        The bounding box to test against. Must have minX, minY, maxX, and maxY properties.

      Returns boolean

      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.

      Parameters

      • a: Object

        The first item to compare.

      • b: Object

        The second item to compare.

      Returns number

      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.

      Parameters

      • a: Object

        The first item to compare.

      • b: Object

        The second item to compare.

      Returns number

      The difference between the top values of the two items.

    • Populates this RTree with data previously exported via toJSON.

      This allows a tree to be serialized and restored without re-inserting every item individually.

      Parameters

      • data: Object

        The tree data to import, as returned by toJSON.

      Returns RTree

      This RTree instance, for chaining.

    • Inserts a single item into the RTree.

      Parameters

      • item: any

        The item to insert. Must have left, top, right, and bottom properties.

      Returns RTree

      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.

      Parameters

      • data: any[]

        An array of items to insert. Each item must have left, top, right, and bottom properties.

      Returns RTree

      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.

      Parameters

      • item: any

        The item to remove.

      • OptionalequalsFn: Function

        An optional custom equality function taking two items and returning a boolean.

      Returns RTree

      This RTree instance, for chaining.

    • Searches the RTree for all items that intersect with the given bounding box and returns them as an array.

      Parameters

      • bbox: Object

        The bounding box to search within. Must have minX, minY, maxX, and maxY properties.

      Returns any[]

      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.

      Parameters

      • a: Object

        The object to convert. Must have left, top, right, and bottom properties.

      Returns Object

      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

      Returns Object

      The internal tree data object.