The ninterp
crate provides multivariate interpolation over a regular, sorted, nonrepeating grid of any dimensionality. A variety of interpolation strategies are implemented, however more are likely to be added. Extrapolation beyond the range of the supplied coordinates is supported for 1-D linear interpolators, using the slope of the nearby points.
There are hard-coded interpolators for lower dimensionalities (up to N = 3) for better runtime performance.
serde
: support for serde
A prelude module has been defined: use ninterp::prelude::*
.
This exposes the types necessary for usage: Interpolator
, Strategy
, Extrapolate
, and the trait InterpMethods
.
All interpolation is handled through instances of the Interpolator
enum.
Interpolation is executed by calling Interpolator::interpolate
.
The length of the supplied point slice must be equal to the interpolator dimensionality.
The interpolator dimensionality can be retrieved by calling Interpolator::ndim
.
For interpolators of dimensionality N ≥ 1:
- Instantiation is done via the Interpolator enum's
new_*
methods (new_1d
,new_2d
,new_3d
,new_nd
). These methods run a validation step that catches any potential errors early, preventing runtime panics.- To set or get field values, use the corresponding named methods (
x
,set_x
, etc.).
- To set or get field values, use the corresponding named methods (
- An interpolation
Strategy
(e.g. linear, left-nearest, etc.) must be specified. Not all interpolation strategies are implemented for every dimensionality.Strategy::Linear
is implemented for all dimensionalities. - An
Extrapolate
setting must be specified. This controls what happens when a point is beyond the range of supplied coordinates. If you are unsure which variant to choose,Extrapolate::Error
is likely what you want.
For 0-D (constant-value) interpolators, instantiate directly, e.g. Interpolator::Interp0D(0.5)