Struct Track

Source
pub struct Track<T>
where T: Sample,
{ /* private fields */ }

Implementations§

Source§

impl<T> Track<T>
where T: Sample,

Source

pub fn new( keys: Vec<Keyframe<T>>, interpolation: Interpolation, ) -> Result<Track<T>, AnimationError>

Source

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);
Source

pub fn keys(&self) -> &[Keyframe<T>]

Borrow the original keys in authoring order, without normalizing values. See Self::validate_keys for an inspection example.

Source

pub fn interpolation(&self) -> Interpolation

Inspect the interpolation selected at construction. See Self::validate_keys for an example.

Source

pub fn duration(&self) -> f32

Source

pub fn sample(&self, time: f32, mode: LoopMode) -> Result<T, AnimationError>

Source

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]);

Trait Implementations§

Source§

impl<T> Clone for Track<T>
where T: Clone + Sample,

Source§

fn clone(&self) -> Track<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T> Debug for Track<T>
where T: Debug + Sample,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Track<T>

§

impl<T> RefUnwindSafe for Track<T>
where T: RefUnwindSafe,

§

impl<T> Send for Track<T>
where T: Send,

§

impl<T> Sync for Track<T>
where T: Sync,

§

impl<T> Unpin for Track<T>
where T: Unpin,

§

impl<T> UnwindSafe for Track<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.