pub struct BilinearInterp<T, const NX: usize, const NY: usize> { /* private fields */ }Expand description
Bilinear interpolant on a rectangular grid (fixed-size, stack-allocated).
Interpolates z = f(x, y) on an NX × NY grid by linearly interpolating first in x, then in y. Out-of-bounds queries extrapolate using the nearest boundary cell.
Internal storage is column-major: zs[ix][iy] holds the value at
(xs[ix], ys[iy]). The constructor accepts row-major input (each inner
array is a row at fixed y) and transposes internally, matching the
Matrix::new() convention.
§Example
use numeris::interp::BilinearInterp;
// 3×2 grid: z = x + y
let xs = [0.0_f64, 1.0, 2.0];
let ys = [0.0, 1.0];
// Row-major input: zs_input[iy][ix]
let zs = [
[0.0, 1.0, 2.0], // y = 0
[1.0, 2.0, 3.0], // y = 1
];
let interp = BilinearInterp::new(xs, ys, zs).unwrap();
assert!((interp.eval(0.5, 0.5) - 1.0).abs() < 1e-14);Implementations§
Source§impl<T: FloatScalar, const NX: usize, const NY: usize> BilinearInterp<T, NX, NY>
impl<T: FloatScalar, const NX: usize, const NY: usize> BilinearInterp<T, NX, NY>
Sourcepub fn new(
xs: [T; NX],
ys: [T; NY],
zs_rows: [[T; NX]; NY],
) -> Result<Self, InterpError>
pub fn new( xs: [T; NX], ys: [T; NY], zs_rows: [[T; NX]; NY], ) -> Result<Self, InterpError>
Construct a bilinear interpolant from sorted grid knots.
zs_rows[j][i] is the value at (xs[i], ys[j]) — row-major input.
Each inner array is a “row” of z-values at a fixed y-coordinate.
Internally transposed to column-major storage.
Returns InterpError::TooFewPoints if NX < 2 or NY < 2,
InterpError::NotSorted if xs or ys is not strictly increasing.