[][src]Crate uniform_cubic_splines

Uniform cubic spline interpolation & inversion.

This crate supports the following types of splines:

If you come from a background of shading languages used in offline rendering this crate should feel like home.

The code is a Rust port of the resp. implementation found in the Open Shading Language C++ source.

Example

Using a combination of spline() and spline_inverse() it is possible to compute a full spline-with-nonuniform-abscissæ:

use uniform_cubic_splines::{
    spline, spline_inverse, basis::{CatmullRom, Linear}
};

// We want to evaluate the spline at knot value 0.3.
let x = 0.3;

let values = [0.0, 0.0, 1.3, 4.2, 6.4, 6.4];
let knots = [0.0, 0.0, 0.1, 0.3, 1.0, 1.0];

let v = spline_inverse::<Linear, _>(x, &knots).unwrap();
let y = spline::<CatmullRom, _, _>(v, &values);

assert!(y - 4.2 < 1e-6);

Modules

basis

Functions

is_len_ok

Returns true if a knots slice you want to feed into spline() has the correct length for the choosen Basis.

spline

As x varies from 0 to 1, this function returns the value of a cubic interpolation of uniformly spaced knots. The input value x will be clamped to the range [0, 1].

spline_inverse

Computes the inverse of the spline() function. This returns the value x for which spline(x) would return y.