-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reorganize
validate
and interpolate
into InterpMethods
impl for…
… `Interpolator` enum
- Loading branch information
Showing
2 changed files
with
160 additions
and
155 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
use super::*; | ||
|
||
/// Methods applicable to all interpolators | ||
pub trait InterpMethods { | ||
/// Validate data stored in [Self]. By design, [Self] can be instantiatated | ||
/// only via the `new` method, which calls `validate`. | ||
fn validate(&self) -> Result<(), ValidationError>; | ||
/// Interpolate at given point | ||
fn interpolate(&self, point: &[f64]) -> Result<f64, InterpolationError>; | ||
} | ||
|
||
/// Linear interpolation: <https://en.wikipedia.org/wiki/Linear_interpolation> | ||
pub trait Linear { | ||
fn linear(&self, point: &[f64]) -> Result<f64, InterpolationError>; | ||
} | ||
|
||
/// Left-nearest (previous value) interpolation: <https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation> | ||
pub trait LeftNearest { | ||
fn left_nearest(&self, point: &[f64]) -> Result<f64, InterpolationError>; | ||
} | ||
|
||
/// Right-nearest (next value) interpolation: <https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation> | ||
pub trait RightNearest { | ||
fn right_nearest(&self, point: &[f64]) -> Result<f64, InterpolationError>; | ||
} | ||
|
||
/// Nearest value (left or right, whichever nearest) interpolation: <https://en.wikipedia.org/wiki/Nearest-neighbor_interpolation> | ||
pub trait Nearest { | ||
fn nearest(&self, point: &[f64]) -> Result<f64, InterpolationError>; | ||
} |