Skip to content

Commit

Permalink
Enable non-linear easing (#32)
Browse files Browse the repository at this point in the history
Fix for #31 based on linebender/velato#42. 

One difference is that I had to enable `mint_types` feature for
`keyframe` crate dependency that pulls in `mint`. As far as I can tell
the project is still `#![no_std]`.
  • Loading branch information
atoktoto authored Nov 12, 2024
1 parent 1d25355 commit 399922b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 18 deletions.
2 changes: 1 addition & 1 deletion .typos.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

# Match Identifier - Case Sensitive
[default.extend-identifiers]
t1_iy = "t1_iy"
t0_iy = "t0_iy"

# Match Inside a Word - Case Insensitive
[default.extend-words]
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ vello = ["dep:vello"]

[dependencies]
hashbrown = "0.15.0"
keyframe = { version = "1.1.1", default-features = false }
keyframe = { version = "1.1.1", default-features = false, features = ["mint_types"] }
kurbo = { version = "0.11", default-features = false }
peniko = { version = "0.1.1", default-features = false }
vello = { version = "0.2.0", default-features = false, optional = true }
Expand Down
28 changes: 12 additions & 16 deletions src/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,10 @@ impl Time {
let t0 = times[ix0];
let t1 = times[ix1];
let (t0_ox, t0_oy) = t0.out_tangent.map(|o| (o.x, o.y)).unwrap_or((0.0, 0.0));
let (t1_ix, t1_iy) = t1.in_tangent.map(|i| (i.x, i.y)).unwrap_or((1.0, 1.0));
let (t0_ix, t0_iy) = t0.in_tangent.map(|i| (i.x, i.y)).unwrap_or((1.0, 1.0));
let easing = Easing {
o: EasingHandle { x: t0_ox, y: t0_oy },
i: EasingHandle { x: t1_ix, y: t1_iy },
i: EasingHandle { x: t0_ix, y: t0_iy },
};
let hold = t0.hold;
let t = (frame - t0.frame) / (t1.frame - t0.frame);
Expand Down Expand Up @@ -161,20 +161,16 @@ pub trait Tween: Clone + Default {
}

impl Tween for f64 {
fn tween(&self, other: &Self, t: f64, _easing: &Easing) -> Self {
// TODO: We are enforcing linear interpolation for now, but a decent amount of work is done for easings.
keyframe::ease(keyframe::functions::Linear, *self, *other, t)

// FIXME: Hopefully we can finish this up one day!
//keyframe::ease(
// keyframe::functions::BezierCurve::from(
// keyframe::mint::Vector2::from_slice(&[easing.o.x, easing.o.y]),
// keyframe::mint::Vector2::from_slice(&[easing.i.x, easing.i.y]),
// ),
// *self,
// *other,
// t,
//)
fn tween(&self, other: &Self, t: f64, easing: &Easing) -> Self {
keyframe::ease(
keyframe::functions::BezierCurve::from(
keyframe::mint::Vector2::from_slice(&[easing.o.x, easing.o.y]),
keyframe::mint::Vector2::from_slice(&[easing.i.x, easing.i.y]),
),
*self,
*other,
t,
)
}
}

Expand Down

0 comments on commit 399922b

Please # to comment.