Expand description

Uniform cubic spline interpolation & inversion.

This crate supports the following types of splines:

The crate uses generics to allow interpolation of any type for which certain traits are defined.

I.e. you can use this crate to interpolate splines in 1D, 2D, 3D, etc.

Cargo Features

  • monotonic_check – The spline_inverse() code will check if the knot vector is monotonic. This check can be made a lot faster if the unstable feature is enabled.
  • unstable – The monotonic_check feature will be faster but requite a nightly toolchain.
  • use_std – The monotonic_check accelleration will be detected at runtime.

The crate does not depend on the standard library (i.e. is marked no_std).


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

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

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

// The first and last points are never interpolated.
let knot_spacing = [0.0, 0.0, 0.1, 0.3, 1.0, 1.0];
let knots = [0.0, 0.0, 1.3, 4.2, 3.2, 3.2];

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

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


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

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



  • Returns true if a knots slice you want to feed into spline() has the correct length for the choosen Basis.
  • 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].
  • Computes the inverse of the spline() function. This returns the value x for which spline(x) would return y.