Skip to main content

lib_jsl_interpolation/
three_d.rs

1//! Three-dimensional interpolation.
2//!
3//! See the book entry [Interpolation on grids](https://jwkunz.github.io/lib_jsl/book/interpolation/grids.html).
4//!
5//! Gridded interpolators take axes `x`, `y`, `z` and a value array of shape `(nx, ny, nz)` with
6//! `v[[i, j, k]] = f(x[i], y[j], z[k])`.
7
8use lib_jsl_core::*;
9use ndarray::Array3;
10
11/// Evaluation interface shared by the 3D interpolators.
12pub trait Interpolation3D {
13    /// Interpolated value at `(x, y, z)`.
14    fn interpolate_at(&self, x: f64, y: f64, z: f64) -> Result<f64, ErrorsJSL>;
15}
16
17/// Checks that axes are strictly increasing, long enough, and match the value array.
18pub(crate) fn validate_grid_3d(axes: [VR1D; 3], v: &Array3<f64>, min_points: usize) -> Result<(), ErrorsJSL> {
19    if v.dim() != (axes[0].len(), axes[1].len(), axes[2].len()) {
20        return Err(ErrorsJSL::IncompatibleArraySizes((v.dim().0, axes[0].len())));
21    }
22    for axis in axes {
23        if axis.len() < min_points {
24            return Err(ErrorsJSL::InvalidInputRange("not enough grid points along an axis"));
25        }
26        if axis.iter().zip(axis.iter().skip(1)).any(|(a, b)| b <= a) {
27            return Err(ErrorsJSL::InvalidInputRange("axes must be strictly increasing"));
28        }
29    }
30    Ok(())
31}
32
33pub mod nearest;
34pub mod trilinear;
35pub mod b_spline;
36pub mod cubic_lagrangian;
37pub mod fourier_3d;
38pub mod shepards;