Skip to main content

Class: FullGridLerpLookupTable

Defined in: src/sdk/utils/datastructures/FullGridLerpLookupTable.ts:25

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

The table linearly interpolates numeric 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 numeric 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.

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 FullGridLerpLookupTable(values, ...keys): FullGridLerpLookupTable

Defined in: src/sdk/utils/datastructures/FullGridLerpLookupTable.ts:63

Creates a new instance of FullGridLerpLookupTable.

Parameters

ParameterTypeDescription
valuesreadonly number[]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.
...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

FullGridLerpLookupTable

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 1
// Dimension 1 1 | 2 3
// 2 | 4 5
//
new FullGridLerpLookupTable([0, 1, 2, 3, 4, 5], [0, 1, 2], [0, 1]);

Properties

dimensionCount

readonly dimensionCount: number

Defined in: src/sdk/utils/datastructures/FullGridLerpLookupTable.ts:38

The number of dimensions in this table.

Methods

get()

get(...key): number

Defined in: src/sdk/utils/datastructures/FullGridLerpLookupTable.ts:206

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

Parameters

ParameterTypeDescription
...keynumber[]The lookup key, as an ordered N-tuple of numbers.

Returns

number

The value corresponding to the specified key.

Throws

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