lineic - Flexible linear interpolator for Rust
lineic - Flexible linear interpolator for Rust
This library provides a simple way to interpolate between values across a range. It supports N-dimensional values, mixed types, and interpolation across any number of data sets.
Inverted ranges work fine, and out of range values are clamped to the provided range.
The library is designed to be simple to use, and as flexible as possible;
For use with non-standard types, the library provides a Numeric trait that can be implemented.
Usage:
use ;
// The simplest possible use of the library is mapping one range to another
// Here we can map values in the range 0.0..=10.0 to the range 30.0..=35.0
let interpolator = new;
assert_eq!;
// The target does not have to be a single value - here we interpolate across a pair of RGB values
// The result is a smooth gradient from red to green for values in the range 0.0..=10.0
let interpolator =
new;
assert_eq!;
// The library can also interpolate smoothly across multiple buckets
// This example forms a sort of traffic light sequence, interpolating between red, yellow, and green
// The range is reversed here to demonstrate that the library can handle that
let interpolator = new;
assert_eq!;
assert_eq!;
// The types for the range and values do not need to the same
// Here a f64 range is used to interpolate between u8 values
let interpolator: =
new;
assert_eq!;
assert_eq!;