Introduce the concept of SampledWithKey.

This allows to type more correctly the output of the `*_with_key`
functions.
This commit is contained in:
Dimitri Sabadie
2021-02-27 23:38:54 +01:00
parent 469a785767
commit 395dff34ee
2 changed files with 51 additions and 22 deletions

View File

@ -1,4 +1,4 @@
use splines::{Interpolation, Key, Spline};
use splines::{spline::SampledWithKey, Interpolation, Key, Spline};
#[cfg(feature = "cgmath")]
use cgmath as cg;
@ -18,8 +18,14 @@ fn step_interpolation_f32() {
assert_eq!(spline.sample(0.9), Some(10.));
assert_eq!(spline.sample(1.), None);
assert_eq!(spline.clamped_sample(1.), Some(10.));
assert_eq!(spline.sample_with_key(0.2), Some((10., &start, Some(&end))));
assert_eq!(spline.clamped_sample_with_key(1.), Some((10., &end, None)));
assert_eq!(
spline.sample_with_key(0.2),
Some(SampledWithKey { value: 10., key: 0 })
);
assert_eq!(
spline.clamped_sample_with_key(1.),
Some(SampledWithKey { value: 10., key: 1 })
);
}
#[test]
@ -35,8 +41,14 @@ fn step_interpolation_f64() {
assert_eq!(spline.sample(0.9), Some(10.));
assert_eq!(spline.sample(1.), None);
assert_eq!(spline.clamped_sample(1.), Some(10.));
assert_eq!(spline.sample_with_key(0.2), Some((10., &start, Some(&end))));
assert_eq!(spline.clamped_sample_with_key(1.), Some((10., &end, None)));
assert_eq!(
spline.sample_with_key(0.2),
Some(SampledWithKey { value: 10., key: 0 })
);
assert_eq!(
spline.clamped_sample_with_key(1.),
Some(SampledWithKey { value: 10., key: 1 })
);
}
#[test]