pub struct KeyframeCurve { /* private fields */ }Expand description
A sorted, validated list of (t, v) pairs plus an interpolation mode.
Invariants (enforced at construction):
- At least 2 keys.
keys[0].t == 0.0,keys.last().t == 1.0.- All
ts are strictly ascending and finite. - All
vs are finite.
Implementations§
Source§impl KeyframeCurve
impl KeyframeCurve
Sourcepub fn new(
keys: Vec<Keyframe>,
interp: KeyframeInterp,
) -> Result<Self, CurveError>
pub fn new( keys: Vec<Keyframe>, interp: KeyframeInterp, ) -> Result<Self, CurveError>
Construct from an explicit list of keys.
pub fn interpolation(&self) -> KeyframeInterp
Sourcepub fn from_curve_fn<F>(
f: F,
samples: u32,
interp: KeyframeInterp,
) -> Result<Self, CurveError>
pub fn from_curve_fn<F>( f: F, samples: u32, interp: KeyframeInterp, ) -> Result<Self, CurveError>
Build a curve by sampling a plain normalized function
f(t) -> v at samples evenly-spaced points in [0, 1]. Both
endpoints (t = 0 and t = 1) are always sampled.
The callable is invoked only during this call and dropped before returning; the resulting curve is pure data.
Rejects sample counts outside [MIN_SAMPLES, MAX_SAMPLES] and any
sample that is non-finite or outside [-VALUE_CLAMP, VALUE_CLAMP].
Sourcepub fn from_motion_fn<F>(
f: F,
ctx: &MotionContext,
samples: u32,
interp: KeyframeInterp,
) -> Result<Self, CurveError>
pub fn from_motion_fn<F>( f: F, ctx: &MotionContext, samples: u32, interp: KeyframeInterp, ) -> Result<Self, CurveError>
Build a curve by sampling a motion-aware function
f(&ctx, t) -> v. The callable receives the movement metadata
(origin, target, distance, duration, user-supplied params) so it
can shape the curve procedurally (spring, gravity, physics …).
Same constraints and drop semantics as Self::from_curve_fn.