Spline2d

Struct Spline2d 

Source
pub struct Spline2d<I, T>
where I: Interp2dType<T> + Send + Sync + 'static,
{ pub interp: I::Interpolation2d, pub xa: Box<[T]>, pub ya: Box<[T]>, pub za: Box<[T]>, /* private fields */ }
Expand description

2D Higher level interface.

A 2D Spline owns the data it is constructed with, and provides the same evaluation methods as the lower-level Interpolator object, without needing to provide the data arrays in every call.

§Example

let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();

let xa = [0.0, 1.0, 2.0, 3.0];
let ya = [0.0, 2.0, 4.0, 6.0];
// z = x + y, in column-major order
let za = [
    0.0, 1.0, 2.0, 3.0,
    2.0, 3.0, 4.0, 5.0,
    4.0, 5.0, 6.0, 7.0,
    6.0, 7.0, 8.0, 9.0,
];

let interp = Bicubic.build(&xa, &ya, &za)?;

let typ = Bicubic;
let spline = Spline2d::new(typ, &xa, &ya, &za)?;

let (x, y) = (2.5, 4.1);
let y_interp = interp.eval(&xa, &ya, &za, x, y, &mut xacc, &mut yacc)?;
let y_spline = spline.eval(x, y, &mut xacc, &mut yacc)?;

assert_eq!(y_interp, y_spline);

Fields§

§interp: I::Interpolation2d

The lower-level 2D Interpolator.

§xa: Box<[T]>

The owned x data.

§ya: Box<[T]>

The owned y data.

§za: Box<[T]>

The owned z data.

Implementations§

Source§

impl<I, T> Spline2d<I, T>
where I: Interp2dType<T> + Send + Sync + 'static,

Source

pub fn new( typ: I, xa: &[T], ya: &[T], za: &[T], ) -> Result<Self, InterpolationError>
where T: Clone,

Constructs a 2D Spline of a 2D Interpolation type typ from the data arrays xa, ya and za.

§Example
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();

let xa = [0.0, 1.0, 2.0, 3.0];
let ya = [0.0, 2.0, 4.0, 6.0];
// z = x + y, in column-major order
let za = [
    0.0, 1.0, 2.0, 3.0,
    2.0, 3.0, 4.0, 5.0,
    4.0, 5.0, 6.0, 7.0,
    6.0, 7.0, 8.0, 9.0,
];

let typ = Bicubic;
let spline = Spline2d::new(typ, &xa, &ya, &za)?;
Source

pub fn eval( &self, x: T, y: T, xacc: &mut Accelerator, yacc: &mut Accelerator, ) -> Result<T, DomainError>
where T: Num,

Returns the interpolated value of z for a given point (x, y), using the Accelerators xacc and yacc.

§Example
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();

let xa = [0.0, 1.0, 2.0];
let ya = [0.0, 2.0, 4.0];
// z = x + y
let za = [
    0.0, 1.0, 2.0,
    2.0, 3.0, 4.0,
    4.0, 5.0, 6.0,
];

let typ = Bilinear;
let spline = Spline2d::new(typ, &xa, &ya, &za)?;

let z = spline.eval(1.5, 3.0, &mut xacc, &mut yacc)?;

assert_eq!(z, 4.5);
§Errors

Returns a DomainError if x is outside the range of xa or y is outside the range of ya.

Source

pub fn eval_extrap( &self, x: T, y: T, xacc: &mut Accelerator, yacc: &mut Accelerator, ) -> Result<T, DomainError>

Returns the interpolated value of z for a given point (x, y), using the Accelerators xaccandyacc`.

§Note

This function performs no bound checking, so when x is outside the range of xa or y is outside the range of ya, extrapolation is performed.

§Example
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();

let xa = [0.0, 1.0, 2.0];
let ya = [0.0, 2.0, 4.0];
// z = x + y
let za = [
    0.0, 1.0, 2.0,
    2.0, 3.0, 4.0,
    4.0, 5.0, 6.0,
];

let typ = Bilinear;
let spline = Spline2d::new(typ, &xa, &ya, &za)?;

let z = spline.eval_extrap(3.0, 6.0, &mut xacc, &mut yacc)?;

assert_eq!(z, 9.0);
§Errors

Returns a DomainError if x is outside the range of xa or y is outside the range of ya.

Source

pub fn eval_deriv_x( &self, x: T, y: T, xacc: &mut Accelerator, yacc: &mut Accelerator, ) -> Result<T, DomainError>

Returns the interpolated value d = ∂z/∂x for a given point (x, y), using the Accelerators xacc and yacc.

§Example
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();

let xa = [0.0, 1.0, 2.0];
let ya = [0.0, 2.0, 4.0];
// z = x² + y²
let za = [
     0.0,  1.0,  4.0,
     4.0,  5.0,  8.0,
    16.0, 17.0, 20.0,
];

let typ = Bilinear;
let spline = Spline2d::new(typ, &xa, &ya, &za)?;

let dzdx = spline.eval_deriv_x(1.5, 3.0, &mut xacc, &mut yacc)?;

assert_eq!(dzdx, 3.0);
§Errors

Returns a DomainError if x is outside the range of xa or y is outside the range of ya.

Source

pub fn eval_deriv_y( &self, x: T, y: T, xacc: &mut Accelerator, yacc: &mut Accelerator, ) -> Result<T, DomainError>

Returns the interpolated value d = ∂z/∂y for a given point (x, y), using the Accelerators xacc and yacc.

§Example
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();

let xa = [0.0, 1.0, 2.0];
let ya = [0.0, 2.0, 4.0];
// z = x² + y²
let za = [
     0.0,  1.0,  4.0,
     4.0,  5.0,  8.0,
    16.0, 17.0, 20.0,
];

let typ = Bilinear;
let spline = Spline2d::new(typ, &xa, &ya, &za)?;

let dzdx = spline.eval_deriv_y(1.5, 3.0, &mut xacc, &mut yacc)?;

assert_eq!(dzdx, 6.0);
§Errors

Returns a DomainError if x is outside the range of xa or y is outside the range of ya.

Source

pub fn eval_deriv_xx( &self, x: T, y: T, xacc: &mut Accelerator, yacc: &mut Accelerator, ) -> Result<T, DomainError>

Returns the interpolated value d = 𝜕²z/𝜕x² for a given point (x, y), using the Accelerators xacc and yacc.

§Example
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();

let xa = [0.0, 1.0, 2.0];
let ya = [0.0, 2.0, 4.0];
// z = x² + y²
let za = [
     0.0,  1.0,  4.0,
     4.0,  5.0,  8.0,
    16.0, 17.0, 20.0,
];

let typ = Bilinear;
let spline = Spline2d::new(typ, &xa, &ya, &za)?;

let dzdx2 = spline.eval_deriv_xx(1.5, 3.0, &mut xacc, &mut yacc)?;

assert_eq!(dzdx2, 0.0); // Linear Interpolation!
§Errors

Returns a DomainError if x is outside the range of xa or y is outside the range of ya.

Source

pub fn eval_deriv_yy( &self, x: T, y: T, xacc: &mut Accelerator, yacc: &mut Accelerator, ) -> Result<T, DomainError>

Returns the interpolated value d = 𝜕²z/𝜕x² for a given point (x, y), using the Accelerators xacc and yacc.

§Example
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();

let xa = [0.0, 1.0, 2.0];
let ya = [0.0, 2.0, 4.0];
// z = x² + y²
let za = [

     0.0,  1.0,  4.0,
     4.0,  5.0,  8.0,
    16.0, 17.0, 20.0,
];
let typ = Bilinear;
let spline = Spline2d::new(typ, &xa, &ya, &za)?;

let dzdx2 = spline.eval_deriv_yy(1.5, 3.0, &mut xacc, &mut yacc)?;

assert_eq!(dzdx2, 0.0); // Linear Interpolation!
§Errors

Returns a DomainError if x is outside the range of xa or y is outside the range of ya.

Source

pub fn eval_deriv_xy( &self, x: T, y: T, xacc: &mut Accelerator, yacc: &mut Accelerator, ) -> Result<T, DomainError>

Returns the interpolated value d = 𝜕²z/𝜕x𝜕y for a given point (x, y), using the Accelerators xacc and yacc.

§Example
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();

let xa = [0.0, 1.0, 2.0];
let ya = [0.0, 2.0, 4.0];
// z = x² + y²
let za = [
     0.0,  1.0,  4.0,
     4.0,  5.0,  8.0,
    16.0, 17.0, 20.0,
];

let typ = Bilinear;
let spline = Spline2d::new(typ, &xa, &ya, &za)?;

let dzdxy = spline.eval_deriv_xy(1.5, 3.0, &mut xacc, &mut yacc)?;

assert_eq!(dzdxy, 0.0);
§Errors

Returns a DomainError if x is outside the range of xa or y is outside the range of ya.

Source

pub fn name(&self) -> &str

Returns the name of the Interpolator.

Source

pub fn min_size(&self) -> usize

Returns the minimum number of points required by the Interpolator.

Source§

impl<T> Spline2d<DynInterp2dType<T>, T>

Source

pub fn new_dyn<I>( typ: I, xa: &[T], ya: &[T], za: &[T], ) -> Result<Self, InterpolationError>
where T: Clone, I: Interp2dType<T> + Send + Sync + 'static, I::Interpolation2d: Send + Sync + 'static,

Constructs a 2d Spline of a dynamic 2d Interpolation type typ from the data arrays xa, ya and za.

§Example
let xa = [0.0, 1.0, 2.0, 3.0];
let ya = [0.0, 2.0, 4.0, 6.0];
// z = x + y, in column-major order
let za = [
    0.0, 1.0, 2.0, 3.0,
    2.0, 3.0, 4.0, 5.0,
    4.0, 5.0, 6.0, 7.0,
    6.0, 7.0, 8.0, 9.0,
];
let typ = "bicubic";

let spline = match typ {
    "bilinear" => Spline2d::new_dyn(Bilinear, &xa, &ya, &za)?,
    "bicubic" => Spline2d::new_dyn(Bicubic, &xa, &ya, &za)?,
    _ => unreachable!()
};

Auto Trait Implementations§

§

impl<I, T> Freeze for Spline2d<I, T>

§

impl<I, T> RefUnwindSafe for Spline2d<I, T>

§

impl<I, T> Send for Spline2d<I, T>
where T: Send,

§

impl<I, T> Sync for Spline2d<I, T>
where T: Sync,

§

impl<I, T> Unpin for Spline2d<I, T>

§

impl<I, T> UnwindSafe for Spline2d<I, T>

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> 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, 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V