Skip to main content

Class: FullGridLerpVectorLookupTable

Defined in: src/sdk/utils/datastructures/FullGridLerpVectorLookupTable.ts:27

A linearly interpolated N-dimensional lookup table of vectors optimized for full-grid breakpoints.

The table linearly interpolates values using a set of defined breakpoints. Each breakpoint has one numeric key for each table dimension (the ordered N-tuple of all dimension keys forms the full key for the breakpoint), as well as one vector value. The full key of a breakpoint determines its position in N-dimensional space, and the value of a breakpoint determines the value that is output by the table for a query point at the breakpoint's position. For query points that lie "between" breakpoints, the output is interpolated. Each component of the output vector is interpolated independently of the others.

The table does not support extrapolation. When asked to get a value for which two surrounding breakpoints along a dimension cannot be found, the value of the nearest breakpoint along that dimension will be selected.

The table supports breakpoints that are irregularly spaced along each dimension. However, only full-grid breakpoints are supported for tables with more than one dimension. Breakpoints form a full grid if and only if the following condition is satisfied: for any two table dimensions m and n, if there exists any breakpoint X with keys a and b in dimensions m and n, respectively, and at least one other breakpoint Y with key c != a in dimension m, then there must exist a breakpoint with key c in dimension m and b in dimension n (which may or may not be Y).

The ordering of dimensions does not affect the output of the table for any query point.

Constructors

Constructor

new FullGridLerpVectorLookupTable(values, ...keys): FullGridLerpVectorLookupTable

Defined in: src/sdk/utils/datastructures/FullGridLerpVectorLookupTable.ts:82

Creates a new instance of FullGridLerpVectorLookupTable.

Parameters

ParameterTypeDescription
valuesreadonly Readonly<Omit<Float64Array<ArrayBufferLike>, "set" | "sort" | "copyWithin">>[]The values of the breakpoints for the new table. The values should be ordered such that the value for the breakpoint with full key [k_1, k_2, ..., k_n] is positioned at index k_1 * product(2) + k_2 * product(3) + ... + k_n-1 * product(n) + k_n, where product(x) = count(x) * count(x + 1) * ... * count(n) and count(x) is the number of keys in dimension x. If not all breakpoint vector values are of the same length, then the length of the shortest vector will be used as the length of the vectors output by the table.
...keysreadonly number[][]The keys of the breakpoints for the new table. The keys should be organized into one array for each table dimension, with each array containing the keys along its associated dimension.

Returns

FullGridLerpVectorLookupTable

Throws

Error if any dimension has zero breakpoint keys or if the provided number of values does not match the product of the number of keys in each dimension.

Example

// Creates a 2D table with the following breakpoints:
//
// Dimension 2
// 0 1
// |----------------
// 0 | [0, 0] [1, 1]
// Dimension 1 1 | [2, 2] [3, 3]
// 2 | [4, 4] [5, 5]
//
new FullGridLerpLookupTable(
[
new Float64Array([0, 0]),
new Float64Array([1, 1]),
new Float64Array([2, 2]),
new Float64Array([3, 3]),
new Float64Array([4, 4]),
new Float64Array([5, 5]),
],
[0, 1, 2],
[0, 1]
);

Properties

dimensionCount

readonly dimensionCount: number

Defined in: src/sdk/utils/datastructures/FullGridLerpVectorLookupTable.ts:40

The number of dimensions in this table.


vectorLength

readonly vectorLength: number

Defined in: src/sdk/utils/datastructures/FullGridLerpVectorLookupTable.ts:43

The length of the vectors in this table.

Methods

get()

get(out, ...key): Float64Array

Defined in: src/sdk/utils/datastructures/FullGridLerpVectorLookupTable.ts:236

Looks up a vector in this table using a specified key. The returned vector will be linearly interpolated from surrounding breakpoints if the key is not an exact match for any of the table's breakpoints.

Parameters

ParameterTypeDescription
outFloat64ArrayThe vector to which to write the result.
...keynumber[]The lookup key, as an ordered N-tuple of numbers.

Returns

Float64Array

The vector corresponding to the specified key.

Throws

Error if this table has zero dimensions or the key has fewer dimensions than this table.