lerpLookupMap

fun lerpLookupMap(source: List<Double>, target: List<Double>, queries: List<Double>): List<Double>

Performs linear interpolation lookup for a list of query values.

Given sorted source and target lists of equal length, and a sorted list of queries, this function returns a list of interpolated values from target corresponding to each query in queries. For each query:

  • If the query is less than the smallest value in source, the first value in target is returned.

  • If the query is greater than the largest value in source, the last value in target is returned.

  • Otherwise, linear interpolation is performed between the two nearest values in source and their corresponding values in target.

Preconditions:

  • source and target must be sorted in ascending order and have the same length.

  • queries must be sorted in ascending order.

Return

List of interpolated values from target for each query.

Parameters

source

Sorted list of source values.

target

Sorted list of target values.

queries

Sorted list of query values.

Throws

if source and target have different sizes or if source is empty.