#spline #spline-interpolation #interpolation #generic #context #derivative #assume

generic_spline

Library of generic implementation of spline which does not assume that spline is used in graphics context

1 unstable release

0.1.0 Feb 5, 2025

#852 in Algorithms

Download history 157/week @ 2025-02-05

157 downloads per month

MIT/Apache

62KB
1K SLoC

generic_spline

Generic implementation of spline interpolation and extrapolation in Rust. It does not assume that spline is used in graphics context. Spline is constructed over knots that can have constraints on required continuity and/or derivatives values. This implies that each spline interval (segment) can be polynomial of different order.

Usage

Here we create spline with constraints on first derivative values on edge knots and C2 continuity on internal knots. After creating spline funcion value can be interpolated or extrapolated for given x.

use generic_spline::{Knot, Spline};

let knots = vec![
    Knot::fix1(0.0, 1.0, 0.0),
    Knot::c2(2.0, 0.0),
    Knot::c2(5.0, 1.0),
    Knot::fix1(6.0, 1.0, -1.0)
];

let spline = Spline::new(knots).unwrap();

let result1 = spline.interpolate(3.5).unwrap();
let result2 = spline.interpolate(4.0).unwrap();
let result3 = spline.extrapolate(8.0);

lib.rs:

Library of generic implementation of spline interpolation and extrapolation. It does not assume that spline is used in graphics context.

Example

use generic_spline::{Knot, Spline};
use assert_approx_eq::assert_approx_eq;

let knots = vec![
    Knot::fix1(0.0, 3.0, -3.0),
    Knot::c2(1.0, 1.0),
    Knot::fix1(2.0, 4.0, -2.0)
];
let spline = Spline::new(knots).unwrap();

assert_approx_eq!(2.344, spline.interpolate(0.2).unwrap(), 1e-6);
assert_approx_eq!(3.0, spline.interpolate(1.5).unwrap(), 1e-6);

Dependencies

~3MB
~57K SLoC