Skip to main content

BilinearInterp

Struct BilinearInterp 

Source
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>

Source

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.

Source

pub fn eval(&self, x: T, y: T) -> T

Evaluate the interpolant at (x, y).

Source

pub fn xs(&self) -> &[T; NX]

The grid x-knots.

Source

pub fn ys(&self) -> &[T; NY]

The grid y-knots.

Trait Implementations§

Source§

impl<T: Clone, const NX: usize, const NY: usize> Clone for BilinearInterp<T, NX, NY>

Source§

fn clone(&self) -> BilinearInterp<T, NX, NY>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug, const NX: usize, const NY: usize> Debug for BilinearInterp<T, NX, NY>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T, const NX: usize, const NY: usize> Freeze for BilinearInterp<T, NX, NY>
where T: Freeze,

§

impl<T, const NX: usize, const NY: usize> RefUnwindSafe for BilinearInterp<T, NX, NY>
where T: RefUnwindSafe,

§

impl<T, const NX: usize, const NY: usize> Send for BilinearInterp<T, NX, NY>
where T: Send,

§

impl<T, const NX: usize, const NY: usize> Sync for BilinearInterp<T, NX, NY>
where T: Sync,

§

impl<T, const NX: usize, const NY: usize> Unpin for BilinearInterp<T, NX, NY>
where T: Unpin,

§

impl<T, const NX: usize, const NY: usize> UnsafeUnpin for BilinearInterp<T, NX, NY>
where T: UnsafeUnpin,

§

impl<T, const NX: usize, const NY: usize> UnwindSafe for BilinearInterp<T, NX, NY>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.