Interp2D

Struct Interp2D 

Source
pub struct Interp2D<C1, C2, Z, S>
where S: Data<Elem = Z>,
{ /* private fields */ }
Expand description

Two dimensional bilinear interpolator for data on an irregular grid.

  • C1: Coordinate type of first axis.
  • C2: Coordinate type of second axis.
  • Z: Value type.
  • S: Array representation of Z values.

Implementations§

Source§

impl<C1, C2, Z, S> Interp2D<C1, C2, Z, S>
where S: Data<Elem = Z>,

Source

pub fn new(x: Vec<C1>, y: Vec<C2>, z: ArrayBase<S, Ix2>) -> Self
where C1: PartialOrd, C2: PartialOrd,

Create a new interpolation engine.

Interpolates values which are sampled on a rectangular grid.

§Parameters
  • x: The x-coordinates. Must be monotonic.
  • y: The y-coordinates. Must be monotonic.
  • z: The values z(x, y) for each grid point defined by the x and y coordinates.
§Panics

Panics when

  • dimensions of x/y axis and z-values don’t match.
  • one axis is empty.
  • x and y values are not monotonic.
Source

pub fn bounds(&self) -> ((C1, C1), (C2, C2))
where C1: Copy, C2: Copy,

Get the boundaries of the sample range as ((x0, x1), (y0, y1)) tuple.

Source

pub fn is_within_bounds(&self, (x, y): (C1, C2)) -> bool
where C1: PartialOrd + Copy, C2: PartialOrd + Copy,

Check if the (x, y) coordinate lies within the defined sample range.

Source

pub fn xs(&self) -> &Vec<C1>

Get the x-coordinate values.

Source

pub fn ys(&self) -> &Vec<C2>

Get the y-coordinate values.

Source

pub fn z(&self) -> &ArrayBase<S, Ix2>

Get the raw z values.

Source

pub fn map_values<Z2>( &self, f: impl Fn(&Z) -> Z2, ) -> Interp2D<C1, C2, Z2, OwnedRepr<Z2>>
where C1: PartialOrd + Clone, C2: PartialOrd + Clone,

Create a new interpolated table by applying a function elementwise to the values.

Source

pub fn map_x_axis<Xnew>( self, f: impl Fn(C1) -> Xnew, ) -> Interp2D<Xnew, C2, Z, S>
where Xnew: PartialOrd,

Apply the function f to each x coordinate. Panics if the ordering of the coordinates is not monotonic after applyint f.

Source

pub fn map_y_axis<Ynew>( self, f: impl Fn(C2) -> Ynew, ) -> Interp2D<C1, Ynew, Z, S>
where Ynew: PartialOrd,

Apply the function f to each y coordinate. Panics if the ordering of the coordinates is not monotonic after applyint f.

Source§

impl<C1, C2, Z, S> Interp2D<C1, C2, Z, S>
where C1: Copy + Sub<Output = C1> + Div + PartialOrd, C2: Copy + Sub<Output = C2> + Div<Output = <C1 as Div>::Output> + PartialOrd, Z: Copy + Mul<<C1 as Div>::Output, Output = Z> + Add<Output = Z> + Sub<Output = Z>, <C1 as Div>::Output: Copy + Add<Output = <C1 as Div>::Output> + Sub<Output = <C1 as Div>::Output>, S: Data<Elem = Z> + Clone,

Source

pub fn eval(&self, (x, y): (C1, C2)) -> Z

Evaluate the sampled function by interpolation at (x, y).

If (x, y) lies out of the sampled range then the function is silently extrapolated. The boundaries of the sample range can be queried with bounds().

Source

pub fn eval_no_extrapolation(&self, xy: (C1, C2)) -> Option<Z>

Returns the same value as eval() as long as (x, y) is within the range of the samples. Otherwise None is returned instead of an extrapolation.

Source§

impl<C1, C2, Z, S> Interp2D<C1, C2, Z, S>
where Z: Clone, S: Data<Elem = Z> + Clone, OwnedRepr<Z>: Data<Elem = Z>,

Source

pub fn swap_variables(self) -> Interp2D<C2, C1, Z, OwnedRepr<Z>>

Swap the input variables.

Trait Implementations§

Source§

impl<C1, C2, Z, S> Clone for Interp2D<C1, C2, Z, S>
where C1: Clone, C2: Clone, S: Data<Elem = Z>, ArrayBase<S, Ix2>: Clone,

Source§

fn clone(&self) -> Self

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<C1: Debug, C2: Debug, Z: Debug, S> Debug for Interp2D<C1, C2, Z, S>
where S: Data<Elem = Z> + Debug,

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<C1, C2, Z, S> Freeze for Interp2D<C1, C2, Z, S>
where S: Freeze,

§

impl<C1, C2, Z, S> RefUnwindSafe for Interp2D<C1, C2, Z, S>

§

impl<C1, C2, Z, S> Send for Interp2D<C1, C2, Z, S>
where S: Send, C1: Send, C2: Send,

§

impl<C1, C2, Z, S> Sync for Interp2D<C1, C2, Z, S>
where S: Sync, C1: Sync, C2: Sync,

§

impl<C1, C2, Z, S> Unpin for Interp2D<C1, C2, Z, S>
where S: Unpin, C1: Unpin, C2: Unpin,

§

impl<C1, C2, Z, S> UnwindSafe for Interp2D<C1, C2, Z, S>

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.