Skip to content

Commit

Permalink
minor doc and test tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
kylecarow committed Jan 23, 2025
1 parent bd88ead commit 51d4237
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,18 +67,22 @@ fn find_nearest_index(arr: &[f64], target: f64) -> usize {
///
/// Interpolation is executed by calling [`Interpolator::interpolate`].
/// The length of the supplied point slice must be equal to the intepolator dimensionality.
/// The interpolator dimensionality can be retrieved by calling [`Interpolator::ndim`].
///
/// # Note
/// With interpolators of dimensionality N ≥ 1:
/// - By design, instantiation must be done via the interpolator structs `new` method.
/// This ensures that a validation check is performed to catch any potential errors early.
/// - To set or get field values, use the corresponding named methods.
/// For interpolators of dimensionality N ≥ 1:
/// - By design, instantiation must be done via the Interpolator enum's `new_*` methods (`new_1d`, `new_2d`, `new_3d`, `new_nd`).
/// These run a validation step that catches any potential errors early.
/// - To set or get field values, use the corresponding named methods (`x`, `set_x`, etc.).
/// - An interpolation [`Strategy`] (e.g. linear, left-nearest, etc.) must be specified.
/// Not all interpolation strategies are implemented for every dimensionality.
/// [`Strategy::Linear`] is implemented for all dimensionalities.
/// - An [`Extrapolate`] setting must be specified.
/// This controls what happens when a point is beyond the range of supplied coordinates.
/// If you are unsure which variant to choose, [`Extrapolate::Error`] is likely what you want.
///
/// For 0D (constant-value) interpolators, instantiate directly, e.g. `Interpolator::Interp0D(0.5)`
///
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "serde", derive(Deserialize, Serialize))]
pub enum Interpolator {
Expand Down
10 changes: 6 additions & 4 deletions src/two.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,8 @@ mod tests {
Extrapolate::Error,
)
.unwrap();
assert_eq!(interp.interpolate(&[x[2], y[1]]).unwrap(), 7.);
assert_eq!(interp.interpolate(&[x[2], y[1]]).unwrap(), 7.);
assert_eq!(interp.interpolate(&[x[2], y[1]]).unwrap(), f_xy[2][1]);
assert_eq!(interp.interpolate(&[0.075, 0.25]).unwrap(), 3.);
}

#[test]
Expand All @@ -124,8 +124,10 @@ mod tests {
Extrapolate::Error,
)
.unwrap();
let interp_res = interp.interpolate(&[0.25, 0.65]).unwrap();
assert_eq!(interp_res, 1.1500000000000001) // 1.15
assert_eq!(
interp.interpolate(&[0.25, 0.65]).unwrap(),
1.1500000000000001 // 1.15
)
}

#[test]
Expand Down

0 comments on commit 51d4237

Please sign in to comment.