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.
The library also provides a no_std feature for use in embedded systems.
Warning: The no_std feature disables the LinearInterpolator struct which enables interpolation across >2 data sets
Examples
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
use F32InterpolationBucket;
let interpolator = new;
assert_eq!;
lineic::interpolators::F32InterpolationBucket here is a type alias for lineic::InterpolationBucket<1, f32, f32>
The interpolators module defines a set of type aliases for common same-type numeric interpolators.
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
use F32InterpolationBucket;
let interpolator = new;
assert_eq!;
The library can also interpolate smoothly across multiple pairs of values
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
use F32LinearInterpolator;
;
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 across u8 values
use LinearInterpolator;
let interpolator: =
new;
assert_eq!;
assert_eq!;
By default, you can interpolate across the following types:
f32f64i8i16i32i64i128isizeu8u16u32u64u128usize
For other types, you can implement the Numeric trait.
See examples/custom_types.rs for an example of how to do this.