Class KeyDesign

A design for octant keys.

3D coordinates are packed into a single integer to obtain a unique key. This class describes the bit allotment for each coordinate and provides methods for key packing and unpacking.

See KeyDesign.BITS for the total amount of available bits.

Hierarchy

Constructors

  • Constructs a new key design.

    Parameters

    • x: number = 8

      The amount of bits used for the X-coordinate.

    • y: number = x

      The amount of bits used for the Y-coordinate.

    • z: number = x

      The amount of bits used for the Z-coordinate.

    Returns KeyDesign

Properties

BITS: 53 = BITS

The total amount of available bits for safe integers.

JavaScript uses IEEE 754 binary64 Doubles for all numbers and, as a result, only supports 53-bit Integers natively.

BigInt is not an option due to the following reasons:

  • operations on BigInt are not constant time (unpredictable performance)
  • only supports signed integers (no >>> operator)

For more information see: http://2ality.com/2012/04/number-encoding.html

HI_BITS: 21 = HI_BITS

The amount of available bits in the high DWord (21).

In JavaScript, bit operations can only be applied to DWords (32-bit). All 53-bit keys must be split into a high and a low part for processing.

LO_BITS: 32 = LO_BITS

The amount of available bits in the low DWord (32).

In JavaScript, bit operations can only be applied to DWords (32-bit). All 53-bit keys must be split into a high and a low part for processing.

Accessors

  • get rangeX(): number
  • The amount of distinct integers that can be represented with X bits.

    Returns number

  • get rangeXY(): number
  • The amount of distinct integers that can be represented with X + Y bits.

    Returns number

  • get rangeY(): number
  • The amount of distinct integers that can be represented with Y bits.

    Returns number

  • get rangeZ(): number
  • The amount of distinct integers that can be represented with Z bits.

    Returns number

  • get x(): number
  • The amount of bits reserved for the X-coordinate.

    Returns number

  • get y(): number
  • The amount of bits reserved for the Y-coordinate.

    Returns number

  • get z(): number
  • The amount of bits reserved for the Z-coordinate.

    Returns number

Methods

  • Calculates the bounds that contain the domain of this key design.

    The center of the bounds is (0, 0, 0).

    Parameters

    • cellSize: Vector3

      The cell size.

    • target: Box3

      A box to store the result in.

    Returns Box3

    The bounds.

  • Checks if this key design equals another key design.

    Parameters

    Returns boolean

    Whether this key design equals the given one.

  • Returns a new key range iterator.

    The iterator returns all keys in the specified coordinate range, including those at min and max.

    Parameters

    • min: Vector3

      The lower key index bounds (zero-based uint coordinates).

    • max: Vector3

      The upper key index bounds (zero-based uint coordinates).

    Returns KeyIterator

    An iterator.

  • Packs key coordinates into a unique key.

    Parameters

    • x: number

      The X-coordinate (Uint).

    • y: number

      The Y-coordinate (Uint).

    • z: number

      The Z-coordinate (Uint).

    Returns number

    The key.

    Throws

    If any value is out of bounds.

  • Sets the bit distribution.

    Parameters

    • x: number

      The amount of bits used for the X-coordinate.

    • y: number

      The amount of bits used for the Y-coordinate.

    • z: number

      The amount of bits used for the Z-coordinate.

    Returns void

    Throws

    If the bit allotment is invalid.

  • Converts the information of this key design into a string.

    Returns string

    The key design as a string.

  • Extracts the 3D coordinates from a given key.

    Parameters

    • key: number

      The key.

    • target: Vector3

      A vector to store the result in.

    Returns Vector3

    The extracted key coordinates.

Events

EVENT_CHANGE: "change" = "change"

Triggers when a key design has changed.