Options
All
  • Public
  • Public/Protected
  • All
Menu

A Quadtree implementation that supports collision detection for rectangles.

param bounds

The outer bounds of the region

param [options]

Additional options which configure the Quadtree

param [options.maxObjects=20]

The maximum number of objects per node

param [options.maxDepth=4]

The maximum number of levels within the root Quadtree

param [options._depth=0]

The depth level of the sub-tree. For internal use

param [options._root]

The root of the quadtree. For internal use

Hierarchy

Index

Constructors

  • new Quadtree(bounds: any, __namedParameters?: { maxObjects: number; maxDepth: number; _depth: number; _root: any }): Quadtree
  • Parameters

    • bounds: any
    • __namedParameters: { maxObjects: number; maxDepth: number; _depth: number; _root: any } = {}
      • maxObjects: number
      • maxDepth: number
      • _depth: number
      • _root: any

    Returns Quadtree

Properties

bounds: Rectangle

The bounding rectangle of the region

maxObjects: number

The maximum number of objects allowed within this node before it must split

maxDepth: number

The maximum number of levels that the base quadtree is allowed

depth: number

The depth of this node within the root Quadtree

objects: QuadtreeObject[]

The objects contained at this level of the tree

nodes: Quadtree[]

Children of this node

root: Quadtree

The root Quadtree

INDICES: { tl: number; tr: number; bl: number; br: number } = ...

A constant that enumerates the index order of the quadtree nodes from top-left to bottom-right.

Type declaration

  • tl: number
  • tr: number
  • bl: number
  • br: number

Accessors

  • Return an array of all the objects in the Quadtree (recursive)

    Returns QuadtreeObject[]

Methods

  • Split this node into 4 sub-nodes.

    Returns Quadtree

    The split Quadtree

  • Clear the quadtree of all existing contents

    Returns Quadtree

    The cleared Quadtree

  • Add a rectangle object to the tree

    Parameters

    Returns Quadtree[]

    The Quadtree nodes the object was added to.

  • Remove an object from the quadtree

    Parameters

    • target: any

      The quadtree target being removed

    Returns Quadtree

    The Quadtree for method chaining

  • Remove an existing object from the quadtree and re-insert it with a new position

    Parameters

    Returns Quadtree[]

    The Quadtree nodes the object was added to

  • getObjects(rect: Rectangle, [options]?: { collisionTest: Function; _s: Set<any> }): Set<any>
  • Get all the objects which could collide with the provided rectangle

    Parameters

    • rect: Rectangle

      The normalized target rectangle

    • [options]: { collisionTest: Function; _s: Set<any> } = {}

      Options affecting the collision test.

      • collisionTest: Function
      • _s: Set<any>

    Returns Set<any>

    The objects in the Quadtree which represent potential collisions

  • getLeafNodes(rect: Rectangle): Quadtree[]
  • Obtain the leaf nodes to which a target rectangle belongs. This traverses the quadtree recursively obtaining the final nodes which have no children.

    Parameters

    • rect: Rectangle

      The target rectangle.

    Returns Quadtree[]

    The Quadtree nodes to which the target rectangle belongs

  • getChildNodes(rect: Rectangle): Quadtree[]
  • Obtain the child nodes within the current node which a rectangle belongs to. Note that this function is not recursive, it only returns nodes at the current or child level.

    Parameters

    • rect: Rectangle

      The target rectangle.

    Returns Quadtree[]

    The Quadtree nodes to which the target rectangle belongs

  • Identify all nodes which are adjacent to this one within the parent Quadtree.

    Returns Quadtree[]

  • visualize([objects]?: boolean): void
  • Visualize the nodes and objects in the quadtree

    Parameters

    • [objects]: boolean = {}

      Visualize the rectangular bounds of objects in the Quadtree. Default is false.

    Returns void