fix cubic_hermite coefficients & powers

This commit is contained in:
Hokwang Choi 2022-06-07 12:01:25 -04:00
parent ace0f4ec50
commit bdeaefd9f9
2 changed files with 14 additions and 6 deletions

View File

@ -127,15 +127,16 @@ macro_rules! impl_Interpolate {
let three_t = t * 3.;
let t2 = t * t;
let t3 = t2 * t;
let two_t3 = t3 * two_t;
let three_t2 = t2 * three_t;
let two_t3 = t2 * two_t;
let two_t2 = t * two_t;
let three_t2 = t * three_t;
// tangents
let m0 = (b.1 - x.1) / (b.0 - x.0);
let m1 = (y.1 - a.1) / (y.0 - a.0);
a.1 * (two_t3 - three_t2 + 1.)
+ m0 * (t3 - t2 * two_t + t)
+ m0 * (t3 - two_t2 + t)
+ b.1 * (three_t2 - two_t3)
+ m1 * (t3 - t2)
}
@ -192,15 +193,16 @@ macro_rules! impl_InterpolateT {
let three_t = t * 3.;
let t2 = t * t;
let t3 = t2 * t;
let two_t3 = t3 * two_t;
let three_t2 = t2 * three_t;
let two_t3 = t2 * two_t;
let two_t2 = t * two_t;
let three_t2 = t * three_t;
// tangents
let m0 = (b.1 - x.1) / (Self::from(b.0 - x.0));
let m1 = (y.1 - a.1) / (Self::from(y.0 - a.0));
a.1 * (two_t3 - three_t2 + 1.)
+ m0 * (t3 - t2 * two_t + t)
+ m0 * (t3 - two_t2 + t)
+ b.1 * (three_t2 - two_t3)
+ m1 * (t3 - t2)
}

View File

@ -131,6 +131,12 @@ fn linear_interpolation_several_keys() {
assert_eq!(spline.clamped_sample(11.), Some(4.));
}
#[test]
fn cubic_interpolation() {
let start = Key::new(0., 0., Interpolation::CatmullRom);
let end = Key::new(1., 10., Interpolation::default());
}
#[test]
fn several_interpolations_several_keys() {
let start = Key::new(0., 0., Interpolation::Step(0.5));