pub enum Value {
Uniform(Data),
Animated(AnimatedData),
}Expand description
A value that can be either uniform or animated over time.
A Value contains either a single Data value that remains constant
(uniform) or AnimatedData that changes over time with interpolation.
Variants§
Uniform(Data)
A constant value that does not change over time.
Animated(AnimatedData)
A value that changes over time with keyframe interpolation.
Implementations§
Source§impl Value
impl Value
Sourcepub fn uniform<V: Into<Data>>(value: V) -> Self
pub fn uniform<V: Into<Data>>(value: V) -> Self
Create a uniform value that does not change over time.
Sourcepub fn animated<I, V>(samples: I) -> Result<Self>
pub fn animated<I, V>(samples: I) -> Result<Self>
Create an animated value from time-value pairs.
All samples must have the same data type. Vector samples are padded to match the length of the longest vector in the set.
Sourcepub fn add_sample<V: Into<Data>>(&mut self, time: Time, val: V) -> Result<()>
pub fn add_sample<V: Into<Data>>(&mut self, time: Time, val: V) -> Result<()>
Add a sample at a specific time, checking length constraints
Sourcepub fn remove_sample(&mut self, time: &Time) -> Option<Data>
pub fn remove_sample(&mut self, time: &Time) -> Option<Data>
Remove a sample at a specific time.
Returns the removed value if it existed. For uniform values, this is a
no-op and returns None. If the last sample is removed from an
animated value, the value remains animated but empty.
Sourcepub fn sample_at(&self, time: Time) -> Option<Data>
pub fn sample_at(&self, time: Time) -> Option<Data>
Sample value at exact time without interpolation.
Returns the exact value if it exists at the given time, or None if
no sample exists at that time for animated values.
Sourcepub fn sample_at_or_before(&self, time: Time) -> Option<Data>
pub fn sample_at_or_before(&self, time: Time) -> Option<Data>
Get the value at or before the given time
Sourcepub fn sample_at_or_after(&self, time: Time) -> Option<Data>
pub fn sample_at_or_after(&self, time: Time) -> Option<Data>
Get the value at or after the given time
Sourcepub fn interpolate(&self, time: Time) -> Data
pub fn interpolate(&self, time: Time) -> Data
Interpolate value at the given time.
For uniform values, returns the constant value. For animated values, interpolates between surrounding keyframes using appropriate interpolation methods (linear, quadratic, or hermite).
Sourcepub fn sample_surrounding<const N: usize>(
&self,
time: Time,
) -> SmallVec<[(Time, Data); N]>
pub fn sample_surrounding<const N: usize>( &self, time: Time, ) -> SmallVec<[(Time, Data); N]>
Get surrounding samples for interpolation.
Sourcepub fn sample_bracket(
&self,
time: Time,
) -> (Option<(Time, Data)>, Option<(Time, Data)>)
pub fn sample_bracket( &self, time: Time, ) -> (Option<(Time, Data)>, Option<(Time, Data)>)
Get the two samples surrounding a time for linear interpolation
Sourcepub fn is_animated(&self) -> bool
pub fn is_animated(&self) -> bool
Check if the value is animated.
Sourcepub fn sample_count(&self) -> usize
pub fn sample_count(&self) -> usize
Get the number of time samples.
Sourcepub fn merge_with<F>(&self, other: &Value, combiner: F) -> Result<Value>
pub fn merge_with<F>(&self, other: &Value, combiner: F) -> Result<Value>
Merge this value with another using a combiner function.
For uniform values, applies the combiner once. For animated values, samples both at the union of all keyframe times and applies the combiner at each time.
§Example
// Multiply two matrices
let result = matrix1.merge_with(&matrix2, |a, b| {
match (a, b) {
(Data::Matrix3(m1), Data::Matrix3(m2)) => {
Data::Matrix3(Matrix3(m1.0 * m2.0))
}
_ => a, // fallback
}
})?;Source§impl Value
impl Value
Sourcepub fn hash_with_shutter<H: Hasher>(&self, state: &mut H, shutter: &Shutter)
pub fn hash_with_shutter<H: Hasher>(&self, state: &mut H, shutter: &Shutter)
Hash the value with shutter context for animation-aware caching.
For animated values, this samples at standardized points within the shutter range and hashes the interpolated values rather than raw keyframes. This provides better cache coherency for animations with different absolute times but identical interpolated values.
Trait Implementations§
Source§impl DataTypeOps for Value
impl DataTypeOps for Value
Source§impl Sample<Color> for Value
impl Sample<Color> for Value
Source§fn sample(
&self,
shutter: &Shutter,
samples: NonZeroU16,
) -> Result<Vec<(Color, SampleWeight)>>
fn sample( &self, shutter: &Shutter, samples: NonZeroU16, ) -> Result<Vec<(Color, SampleWeight)>>
Source§impl Sample<Integer> for Value
impl Sample<Integer> for Value
Source§fn sample(
&self,
shutter: &Shutter,
samples: NonZeroU16,
) -> Result<Vec<(Integer, SampleWeight)>>
fn sample( &self, shutter: &Shutter, samples: NonZeroU16, ) -> Result<Vec<(Integer, SampleWeight)>>
Source§impl Sample<Matrix3> for Value
impl Sample<Matrix3> for Value
Source§fn sample(
&self,
shutter: &Shutter,
samples: NonZeroU16,
) -> Result<Vec<(Matrix3, SampleWeight)>>
fn sample( &self, shutter: &Shutter, samples: NonZeroU16, ) -> Result<Vec<(Matrix3, SampleWeight)>>
Source§impl Sample<Real> for Value
impl Sample<Real> for Value
Source§fn sample(
&self,
shutter: &Shutter,
samples: NonZeroU16,
) -> Result<Vec<(Real, SampleWeight)>>
fn sample( &self, shutter: &Shutter, samples: NonZeroU16, ) -> Result<Vec<(Real, SampleWeight)>>
Source§impl Sample<Vector2> for Value
impl Sample<Vector2> for Value
Source§fn sample(
&self,
shutter: &Shutter,
samples: NonZeroU16,
) -> Result<Vec<(Vector2, SampleWeight)>>
fn sample( &self, shutter: &Shutter, samples: NonZeroU16, ) -> Result<Vec<(Vector2, SampleWeight)>>
Source§impl TryFrom<&Value> for BooleanVec
impl TryFrom<&Value> for BooleanVec
Source§impl TryFrom<&Value> for IntegerVec
impl TryFrom<&Value> for IntegerVec
Source§impl TryFrom<&Value> for Matrix3Vec
impl TryFrom<&Value> for Matrix3Vec
Source§impl TryFrom<&Value> for Vector2Vec
impl TryFrom<&Value> for Vector2Vec
Source§impl TryFrom<Value> for BooleanVec
impl TryFrom<Value> for BooleanVec
Source§impl TryFrom<Value> for IntegerVec
impl TryFrom<Value> for IntegerVec
Source§impl TryFrom<Value> for Matrix3Vec
impl TryFrom<Value> for Matrix3Vec
Source§impl TryFrom<Value> for Vector2Vec
impl TryFrom<Value> for Vector2Vec
impl Eq for Value
impl StructuralPartialEq for Value
Auto Trait Implementations§
impl Freeze for Value
impl RefUnwindSafe for Value
impl Send for Value
impl Sync for Value
impl Unpin for Value
impl UnwindSafe for Value
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.