pub struct Spline2d<I, T> {
pub interp: I,
pub xa: Vec<T>,
pub ya: Vec<T>,
pub za: Vec<T>,
/* private fields */
}
Expand description
2D Higher level interface.
A 2D Spline owns the data it is constructed with, and provides the same evalulation 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::build(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
The lower-level 2D Interpolator
.
xa: Vec<T>
The owned x data.
ya: Vec<T>
The owned y data.
za: Vec<T>
The owned z data.
Implementations§
Source§impl<I, T> Spline2d<I, T>
impl<I, T> Spline2d<I, T>
Sourcepub fn build(
typ: impl Interp2dType<T, Interpolator2d = I>,
xa: &[T],
ya: &[T],
za: &[T],
) -> Result<Self, InterpolationError>
pub fn build( typ: impl Interp2dType<T, Interpolator2d = I>, xa: &[T], ya: &[T], za: &[T], ) -> Result<Self, InterpolationError>
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::build(typ, &xa, &ya, &za)?;
Sourcepub fn eval(
&self,
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
pub fn eval( &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
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::build(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
.
Sourcepub fn eval_extrap(
&self,
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
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
xaccand
yacc`.
§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::build(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
.
Sourcepub fn eval_deriv_x(
&self,
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
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::build(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
.
Sourcepub fn eval_deriv_y(
&self,
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
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::build(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
.
Sourcepub fn eval_deriv_xx(
&self,
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
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::build(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
.
Sourcepub fn eval_deriv_yy(
&self,
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
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::build(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
.
Sourcepub fn eval_deriv_xy(
&self,
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
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::build(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
.