Skip to main content

Class: LerpLookupTable

Defined in: src/sdk/utils/datastructures/LerpLookupTable.ts:58

A linearly interpolated N-dimensional lookup table.

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. 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 LerpLookupTable(dimensionCount): LerpLookupTable

Defined in: src/sdk/utils/datastructures/LerpLookupTable.ts:77

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.

Returns

LerpLookupTable

Deprecated

Please use the constructor that accepts an array of breakpoints.

Constructor

new LerpLookupTable(breakpoints): LerpLookupTable

Defined in: src/sdk/utils/datastructures/LerpLookupTable.ts:87

Creates a lookup table initialized with an array of breakpoints.

Parameters

ParameterTypeDescription
breakpointsreadonly readonly number[][]An array of breakpoints with which to initialize the new table. Each breakpoint should be expressed as a number array, where the first element represents the breakpoint value, 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.

Returns

LerpLookupTable

Accessors

dimensionCount

Get Signature

get dimensionCount(): number

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

The number of dimensions in this table.

Returns

number

Methods

get()

get(...key): number

Defined in: src/sdk/utils/datastructures/LerpLookupTable.ts:163

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


insertBreakpoint()

insertBreakpoint(breakpoint): this

Defined in: src/sdk/utils/datastructures/LerpLookupTable.ts:115

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 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, or the breakpoint has fewer dimensions than this table.

Deprecated

It is recommended to define all breakpoints at instantiation time.