Skip to content

Latest commit

 

History

History
51 lines (32 loc) · 1.73 KB

transducers.interpolate.md

File metadata and controls

51 lines (32 loc) · 1.73 KB

Home > @thi.ng/transducers > interpolate

interpolate() function

Higher order interpolation transducer. The resulting transducer forms a sliding window and calls fn (the given interpolation function) n times with the current window and a normalized time value to produce the requested number of interpolated values per interval.

Signature:

export declare function interpolate<T>(fn: Fn2<T[], number, T>, window: number, n: number): Transducer<number, number>;

Parameters

Parameter Type Description
fn Fn2<T[], number, T>
window number
n number

Returns:

Transducer<number, number>

Remarks

If the optional src iterable is given, interpolate returns an iterator of interpolated values. No values will be produced if the number of inputs is less than given window size.

Note: The *very last* input value can never be fully reached and might need to be explicitly duplicated in the input, e.g. via the extendSides() iterator...

See also: - interpolateHermite() - interpolateLinear() - extendSides()

Example

[...interpolate(
  ([a, b], t) => a + (b - a) * t,
  2,
  8,
  [0, 1, 0, 2]
)]

// [ 0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875,
//  1, 0.875, 0.75, 0.625, 0.5, 0.375, 0.25, 0.125,
//  0, 0.25, 0.5, 0.75, 1, 1.25, 1.5, 1.75 ]