pub struct Track<T>where
T: Sample,{ /* private fields */ }Implementations§
Source§impl<T> Track<T>where
T: Sample,
impl<T> Track<T>where
T: Sample,
pub fn new( keys: Vec<Keyframe<T>>, interpolation: Interpolation, ) -> Result<Track<T>, AnimationError>
Sourcepub fn validate_keys(keys: &[Keyframe<T>]) -> Result<(), AnimationDiagnostic>
pub fn validate_keys(keys: &[Keyframe<T>]) -> Result<(), AnimationDiagnostic>
Check borrowed authoring data without allocating, sorting or consuming it.
Keys must have finite, nonnegative times and valid values. Scalar/vector
values must be finite; quaternion squared length (computed in f64)
must also exceed 1e-20, as required by Sample::valid. Times must be strictly increasing:
duplicates and descending pairs return UnorderedKeys at the latter key.
The first invalid key is reported before checking ordering, preserving
Self::new’s error precedence. A single key at time zero is valid.
Work is O(keys.len()) with constant scratch space.
use ferravex_play::animation::{Interpolation, Keyframe, ScalarTrack};
let keys = [Keyframe { time: 0.0, value: 3.0 }];
ScalarTrack::validate_keys(&keys).unwrap();
let track = ScalarTrack::new(keys.to_vec(), Interpolation::Step).unwrap();
assert_eq!(track.keys(), &keys);
assert_eq!(track.interpolation(), Interpolation::Step);Sourcepub fn keys(&self) -> &[Keyframe<T>]
pub fn keys(&self) -> &[Keyframe<T>]
Borrow the original keys in authoring order, without normalizing values.
See Self::validate_keys for an inspection example.
Sourcepub fn interpolation(&self) -> Interpolation
pub fn interpolation(&self) -> Interpolation
Inspect the interpolation selected at construction.
See Self::validate_keys for an example.
pub fn duration(&self) -> f32
pub fn sample(&self, time: f32, mode: LoopMode) -> Result<T, AnimationError>
Sourcepub fn sample_into(
&self,
times: &[f32],
mode: LoopMode,
out: &mut [T],
) -> Result<usize, AnimationError>
pub fn sample_into( &self, times: &[f32], mode: LoopMode, out: &mut [T], ) -> Result<usize, AnimationError>
Sample arbitrary times into a reusable output prefix without allocating.
Returns the number written (times.len()); any remaining output elements
are untouched. Empty input succeeds without writes. A short output returns
Capacity, before checking for nonfinite times (InvalidTime). Either
error leaves the entire output unchanged. Negative and unsorted times are
supported and each result is identical to Self::sample.
Work is O(times.len() * log(keys.len())) with constant scratch space.
use ferravex_play::animation::{Interpolation, Keyframe, LoopMode, ScalarTrack};
let track = ScalarTrack::new(vec![
Keyframe { time: 0.0, value: 0.0 },
Keyframe { time: 1.0, value: 4.0 },
], Interpolation::Linear).unwrap();
let mut out = [-1.0; 4];
let count = track.sample_into(&[0.5, 1.0, -0.25], LoopMode::Repeat, &mut out).unwrap();
assert_eq!(&out[..count], &[2.0, 0.0, 3.0]);
assert_eq!(out[3], -1.0);
assert!(track.sample_into(&[0.0, f32::NAN], LoopMode::Clamp, &mut out).is_err());
assert_eq!(out, [2.0, 0.0, 3.0, -1.0]);