linear-octree - v0.3.2
    Preparing search index...

    Class Octree<T>

    An octree that subdivides space for fast spatial searches.

    This linear implementation offers constant time access to octants at any depth level as well as octant neighbours and parent nodes.

    Type Parameters

    • T

      The type of the octant data.

    Implements

    Index

    Constructors

    • Constructs a new octree.

      Each octant can be uniquely identified by a 3D coordinate and a level. The tree depth is defined by the highest number of bits in the key design.

      If the bounds of the octree are defined directly, the cell size will depend on the bounds and the key design. Alternatively, the bounds can be calculated from a desired cell size via KeyDesign.calculateBounds.

      Type Parameters

      • T

        The type of the octant data.

      Parameters

      • bounds: Box3

        The bounds of the octree.

      • keyDesign: KeyDesign = ...

        The bit allotments for the octant coordinates.

      Returns Octree<T>

    Properties

    The root node of this octree.

    Accessors

    Methods

    • Calculates key coordinates based on a given position and level.

      Parameters

      • position: Vector3

        A position.

      • level: number

        The level.

      • result: Vector3

        A vector to store the result in.

      Returns Vector3

      The key coordinates.

    • Checks if the given point lies inside this octree's boundaries.

      Parameters

      Returns boolean

      Whether the given point lies inside this octree.

    • Removes a specific octant.

      Children and empty intermediate parent octants will be removed as well.

      Parameters

      • key: number | Vector3

        A packed key or key coordinates.

      • level: number = 0

        The level of the octant.

      Returns void

    • Fetches all nodes of a specific depth level.

      Parameters

      • level: number

        The depth level.

      Returns Node[]

      The nodes.

    • Retrieves data from a specific octant.

      Parameters

      • key: number | Vector3

        A packed key or key coordinates.

      • level: number

        The level of the octant.

      Returns T | null | undefined

      The data, or undefined if the octant doesn't exist.

    • Returns the size of the cells in the specified grid.

      Parameters

      • level: number

        The level. Must be a positive integer.

      • result: Vector3

        A vector to store the result in.

      Returns Vector3

      The cell size.

    • Calculates the center of this node.

      Parameters

      • result: Vector3

        A vector to store the result in.

      Returns Vector3

      A vector that describes the center of this node.

    • Calculates the depth of this tree.

      Returns number

      The depth.

    • Calculates the size of this node.

      Parameters

      • result: Vector3

        A vector to store the result in.

      Returns Vector3

      A vector that describes the size of this node.

    • Returns the grid of the specified level.

      Parameters

      • level: number

        The level of the grid.

      Returns Map<number, Octant<T>>

      The requested grid.

      If the given level is out of bounds.

    • Returns the amount of depth levels.

      Returns number

      The levels.

    • Retrieves an octant of a specific level that contains the given point.

      Parameters

      • point: Vector3

        A point.

      • level: number = 0

        The level.

      Returns Octant<T> | undefined

      The octant, or undefined if it doesn't exist.

    • Returns a new octree iterator.

      The octants returned by this iterator are augmented wrappers with explicit positional information.

      Parameters

      • level: number = 0

        The depth level.

      Returns OctreeIterator<T>

      An octree iterator.

    • Adds data to a specific octant.

      Missing intermediate octants will be created automatically.

      Parameters

      • key: number | Vector3

        A packed key or key coordinates.

      • level: number

        The level of the octant.

      • data: T | null

        The data.

      Returns void