Skip to main content

Class: LerpVectorLookupTable

Defined in: src/sdk/utils/datastructures/LerpVectorLookupTable.ts:66

A linearly interpolated N-dimensional lookup table of vectors.

The table linearly interpolates values using a set of defined breakpoints. Each breakpoint has one numeric key for 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. Sparse-grid breakpoints are supported for tables with more than one dimension. Breakpoints form a sparse grid if and only if the following condition is not 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).

For non-sparse-grid (full-grid) breakpoints, the table outputs values consistent with standard linear, bilinear, trilinear, etc., interpolation. In this case the ordering of dimensions does not affect the output.

For sparse-grid breakpoints, the ordering of dimensions does affect the output. The algorithm for interpolating a value in the sparse-grid case is as follows. Breakpoints are grouped into a series of nested buckets, with one level per table dimension. The first level of buckets groups all breakpoints by their keys in dimension 1 (all breakpoints with key a in dimension 1 are grouped into bucket a, breakpoints with key b are grouped into bucket b, etc.). The second level of buckets groups all breakpoints within each first-level bucket by their keys in dimension 2, and so on. When a value lookup is requested for a query point with keys i, j, k... in dimensions 1, 2, 3..., we start the interpolation process with the first bucket level. The two buckets with keys most closely surrounding the query point in dimension 1 are selected. If a bucket has a key exactly equal to the query point's position, then only that one bucket is selected. If the query point lies outside of the minimum and maximum keys in dimension 1, then the one bucket corresponding to the closest key to the query point is selected. Then, for each selected bucket, the bucket selection process repeats for the next level of buckets, then the next level, until the last level is reached. When the last level is reached, each selected bucket represents a single breakpoint in the table, and the selected breakpoints are used to interpolate a value along the last dimension. These interpolated values are passed back up the selection tree and are used to interpolate values along the second-to-last dimension, which are in turn used to interpolate values along the third-to-last-dimension, and so on all the way back to the first dimension. At the first dimension, a single value is interpolated and this becomes the final interpolated value that the table outputs for the query point.

Constructors

Constructor

new LerpVectorLookupTable(dimensionCount, vectorLength): LerpVectorLookupTable

Defined in: src/sdk/utils/datastructures/LerpVectorLookupTable.ts:96

Creates a lookup table of a specified dimension.

Parameters

ParameterTypeDescription
dimensionCountnumberThe number of dimensions in the new table. Values less than 0 will be clamped to 0.
vectorLengthnumberThe length of the interpolated vectors (i.e. the number of components in each vector) in the new table. Values less than 0 will be clamped to 0.

Returns

LerpVectorLookupTable

Deprecated

Please use the constructor that accepts an array of breakpoints.

Constructor

new LerpVectorLookupTable(breakpoints): LerpVectorLookupTable

Defined in: src/sdk/utils/datastructures/LerpVectorLookupTable.ts:107

Creates a lookup table initialized with an array of breakpoints.

Parameters

ParameterTypeDescription
breakpointsreadonly readonly [Readonly<Omit<Float64Array<ArrayBufferLike>, "set" | "sort" | "copyWithin">>, number][]An array of breakpoints with which to initialize the new table. Each breakpoint should be expressed as an array, where the first element represents the breakpoint vector, and the next N elements represent the breakpoint key in each dimension. If not all breakpoint arrays have the same length, the dimension of the table will be set equal to L - 1, where L is the length of the shortest array. For arrays with length greater than L, all keys after index L - 1 will be ignored. If the table ends up with zero dimensions, it will be initialized to an empty table. Additionally, the table's vector length will be set to the length of the shortest breakpoint vector.

Returns

LerpVectorLookupTable

Accessors

dimensionCount

Get Signature

get dimensionCount(): number

Defined in: src/sdk/utils/datastructures/LerpVectorLookupTable.ts:74

The number of dimensions in this table.

Returns

number


vectorLength

Get Signature

get vectorLength(): number

Defined in: src/sdk/utils/datastructures/LerpVectorLookupTable.ts:81

The length of the vectors in this table.

Returns

number

Methods

get()

get(out, ...key): Float64Array

Defined in: src/sdk/utils/datastructures/LerpVectorLookupTable.ts:199

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, the key has fewer dimensions than this table, or a vector could not be retrieved.


insertBreakpoint()

insertBreakpoint(breakpoint): this

Defined in: src/sdk/utils/datastructures/LerpVectorLookupTable.ts:146

Inserts a breakpoint into this table. If the breakpoint has more dimensions than this table, only the first N keys of the breakpoint will be used, where N is the dimension count of this table.

Parameters

ParameterTypeDescription
breakpointreadonly [Readonly<Omit<Float64Array<ArrayBufferLike>, "set" | "sort" | "copyWithin">>, number]A breakpoint, as a number array with the value at index 0 followed by the keys for each dimension.

Returns

this

This table, after the breakpoint has been inserted.

Throws

Error if this table has zero dimensions, the breakpoint has fewer dimensions than this table, or the the length of the breakpoint vector is less than this table's vector length property.

Deprecated

It is recommended to define all breakpoints at instantiation time.