Home Reference Source
import {KeyDesign} from 'rabbit-hole'
public class | source

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.

Static Member Summary

Static Public Members
public static get

The total amount of available bits for safe integers.

public static get

The amount of available bits in the high DWord.

public static get

The amount of available bits in the low DWord.

Constructor Summary

Public Constructor
public

Constructs a new key design.

Member Summary

Public Members
public

halfRange: Vector3

The key range divided by two.

public

The amount of distinct integers that can be represented with X bits.

public

The amount of distinct integers that can be represented with X + Y bits.

public

The amount of distinct integers that can be represented with Y bits.

public

The amount of distinct integers that can be represented with Z bits.

public

The amount of bits reserved for the X-coordinate.

public

The amount of bits reserved for the Y-coordinate.

public

The amount of bits reserved for the Z-coordinate.

Method Summary

Public Methods
public

keyRange(min: Vector3, max: Vector3): KeyIterator

Returns a new key range iterator.

public

packKey(position: Vector3): Number

Packs a 3D position into a unique key.

public

set(x: Number, y: Number, z: Number)

Sets the bit distribution.

public

Converts the information of this key design into a string.

public

unpackKey(key: Number, target: Vector3): Vector3

Extracts the 3D coordinates from a given key.

Static Public Members

public static get BITS: Number source

The total amount of available bits for safe integers.

JavaScript uses IEEE 754 binary64 Doubles for Numbers and, as a result, only supports 53-bit integers as of ES2015.

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

public static get HI_BITS: Number source

The amount of available bits in the high DWord.

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.

public static get LO_BITS: Number source

The amount of available bits in the low DWord.

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.

Public Constructors

public constructor(x: Number, y: Number, z: Number) source

Constructs a new key design.

Params:

NameTypeAttributeDescription
x Number
  • optional
  • default: Math.round(BITS * 0.4)

The amount of bits used for the X-coordinate.

y Number
  • optional
  • default: Math.round(BITS * 0.2)

The amount of bits used for the Y-coordinate.

z Number
  • optional
  • default: x

The amount of bits used for the Z-coordinate.

Public Members

public halfRange: Vector3 source

The key range divided by two.

public rangeX: Number source

The amount of distinct integers that can be represented with X bits.

public rangeXY: Number source

The amount of distinct integers that can be represented with X + Y bits.

public rangeY: Number source

The amount of distinct integers that can be represented with Y bits.

public rangeZ: Number source

The amount of distinct integers that can be represented with Z bits.

public x: Number source

The amount of bits reserved for the X-coordinate.

public y: Number source

The amount of bits reserved for the Y-coordinate.

public z: Number source

The amount of bits reserved for the Z-coordinate.

Public Methods

public keyRange(min: Vector3, max: Vector3): KeyIterator source

Returns a new key range iterator.

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

Params:

NameTypeAttributeDescription
min Vector3

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

max Vector3

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

Return:

KeyIterator

An iterator.

public packKey(position: Vector3): Number source

Packs a 3D position into a unique key.

Params:

NameTypeAttributeDescription
position Vector3

A position.

Return:

Number

The octant key.

public set(x: Number, y: Number, z: Number) source

Sets the bit distribution.

Make sure to clear your octree after changing the key design!

Params:

NameTypeAttributeDescription
x Number
  • optional

The amount of bits used for the X-coordinate.

y Number
  • optional

The amount of bits used for the Y-coordinate.

z Number
  • optional

The amount of bits used for the Z-coordinate.

public toString(): String source

Converts the information of this key design into a string.

Return:

String

The key design as a string.

public unpackKey(key: Number, target: Vector3): Vector3 source

Extracts the 3D coordinates from a given key.

Params:

NameTypeAttributeDescription
key Number

The key.

target Vector3
  • optional

A target for the extracted coordinates. If none is provided, a new vector will be created.

Return:

Vector3

The extracted coordinates.