InterpolatingMap
A navigable map that supports flexible interpolation between values.
InterpolatingMap is a wrapper around a TreeMap<Double, T> that queries a custom interpolation strategy to approximate values between stored keys. Exact matches return stored values; intermediate keys are interpolated using the configured strategy.
Interpolation Strategies
Two interpolation paradigms are supported:
Local Interpolation: Uses an (T, T, Double) -> T function operating on two adjacent control points and a blend parameter \(t \in 0.0, 1.0\). Efficient and suitable for linear, polynomial, and other pointwise methods.
Global Interpolation: Uses a (NavigableMap<Double, T>).(Double) -> T lambda with access to all control points. Enables spline interpolation and methods requiring multi-point context.
Usage Examples
Linear interpolation (local):
val map = InterpolatingMap.linear()
map[0.0] = 0.0
map[1.0] = 1.0
map[2.0] = 4.0
println(map[0.5]) // 0.5 (linearly interpolated)Catmull-Rom spline interpolation (local):
val map = InterpolatingMap.spline()
map[0.0] = 0.0
map[1.0] = 1.0
map[2.0] = 0.5
println(map[1.5]) // Smooth spline-interpolated valueType Parameters
the value type stored in the map
Throws
if keys and values lists have differing lengths