use crate::property::PropertySnapshot;
#[cfg(test)]
use crate::{prelude::RawPropertySpec, property::PropertyEntry};
#[derive(Debug, Clone, PartialEq)]
pub struct Keyframe {
offset: f32,
snapshot: PropertySnapshot,
}
impl Keyframe {
#[must_use]
pub fn new(offset: f32, mut snapshot: PropertySnapshot) -> Self {
snapshot.sort_by_composition_key();
Self {
offset: normalize_offset(offset),
snapshot,
}
}
#[must_use]
pub const fn offset(&self) -> f32 {
self.offset
}
#[must_use]
pub const fn snapshot(&self) -> &PropertySnapshot {
&self.snapshot
}
pub(crate) fn merge_snapshot(&mut self, snapshot: PropertySnapshot) {
self.snapshot.merge(snapshot);
}
#[cfg(test)]
pub(crate) fn find_property(&self, property: &RawPropertySpec) -> Option<&PropertyEntry> {
self.snapshot.find_property(property)
}
}
#[must_use]
pub fn normalize_offset(offset: f32) -> f32 {
if offset.is_finite() {
offset.clamp(0.0, 1.0)
} else {
0.0
}
}