pub trait Interpolation2d<T>where
T: Num,{
// Required methods
fn eval_extrap(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>;
fn eval_deriv_x(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>;
fn eval_deriv_y(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>;
fn eval_deriv_xx(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>;
fn eval_deriv_yy(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>;
fn eval_deriv_xy(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>;
// Provided method
fn eval(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError> { ... }
}
Expand description
Defines the required evaulation methods.
Required Methods§
Sourcefn eval_extrap(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
fn eval_extrap( &self, xa: &[T], ya: &[T], za: &[T], 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 data arrays
xa
, ya
, za
and 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 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 interp = Bilinear.build(&xa, &ya, &za)?;
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();
let z = interp.eval_extrap(&xa, &ya, &za, 3.0, 6.0, &mut xacc, &mut yacc)?;
assert_eq!(z, 9.0);
Sourcefn eval_deriv_x(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
fn eval_deriv_x( &self, xa: &[T], ya: &[T], za: &[T], 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 data arrays
xa
, ya
, za
and the Accelerators
xacc
and yacc
.
§Example
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 interp = Bilinear.build(&xa, &ya, &za)?;
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();
let dzdx = interp.eval_deriv_x(&xa, &ya, &za, 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
.
Sourcefn eval_deriv_y(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
fn eval_deriv_y( &self, xa: &[T], ya: &[T], za: &[T], 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 data arrays
xa
, ya
, za
and the Accelerators
xacc
and yacc
.
§Example
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 interp = Bilinear.build(&xa, &ya, &za)?;
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();
let dzdy = interp.eval_deriv_y(&xa, &ya, &za, 1.5, 3.0, &mut xacc, &mut yacc)?;
assert_eq!(dzdy, 6.0);
§Errors
Returns a DomainError
if x
is outside the range of xa
or y
is outside the range
of ya
.
Sourcefn eval_deriv_xx(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
fn eval_deriv_xx( &self, xa: &[T], ya: &[T], za: &[T], 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 data arrays
xa
, ya
, za
and the Accelerators
xacc
and yacc
.
§Example
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 interp = Bilinear.build(&xa, &ya, &za)?;
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();
let dzdx2 = interp.eval_deriv_xx(&xa, &ya, &za, 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
.
Sourcefn eval_deriv_yy(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
fn eval_deriv_yy( &self, xa: &[T], ya: &[T], za: &[T], 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 data arrays
xa
, ya
, za
and the Accelerators
xacc
and yacc
.
§Example
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 interp = Bilinear.build(&xa, &ya, &za)?;
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();
let dzdy2 = interp.eval_deriv_yy(&xa, &ya, &za, 1.5, 3.0, &mut xacc, &mut yacc)?;
assert_eq!(dzdy2, 0.0); // Linear Interpolation!
§Errors
Returns a DomainError
if x
is outside the range of xa
or y
is outside the range
of ya
.
Sourcefn eval_deriv_xy(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
fn eval_deriv_xy( &self, xa: &[T], ya: &[T], za: &[T], 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 data arrays
xa
, ya
, za
and the Accelerators
xacc
and yacc
.
§Example
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 interp = Bilinear.build(&xa, &ya, &za)?;
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();
let dzdxy = interp.eval_deriv_xy(&xa, &ya, &za, 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
.
Provided Methods§
Sourcefn eval(
&self,
xa: &[T],
ya: &[T],
za: &[T],
x: T,
y: T,
xacc: &mut Accelerator,
yacc: &mut Accelerator,
) -> Result<T, DomainError>
fn eval( &self, xa: &[T], ya: &[T], za: &[T], 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 data arrays
xa
, ya
, za
and the Accelerators
xacc
and yacc
.
§Note
This function only performes the bounds check, and then calls eval_extrap()
, where the
actual evaluation is implemented.
§Example
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 interp = Bilinear.build(&xa, &ya, &za)?;
let mut xacc = Accelerator::new();
let mut yacc = Accelerator::new();
let z = interp.eval(&xa, &ya, &za, 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
.