aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/interpolation.rs70
1 files changed, 44 insertions, 26 deletions
diff --git a/src/interpolation.rs b/src/interpolation.rs
index d088bf8..17e4a48 100644
--- a/src/interpolation.rs
+++ b/src/interpolation.rs
@@ -104,35 +104,53 @@ impl<
sorted_keyframes: Vec<KeyFrame<ValueType>>,
time: f64,
) -> Option<(KeyFrame<ValueType>, KeyFrame<ValueType>)> {
- // TODO: maybe refactor the internals of this to be faster
- let idx = {
- let mut idx = 0;
- let mut found = false;
- for f in &sorted_keyframes {
- if f.time > time {
- found = true;
- break;
- } else {
- idx += 1;
- }
- }
- if found {
- Some(idx)
- } else {
+ let length = AnimationTrack::length((
+ *sorted_keyframes.first().unwrap(),
+ *sorted_keyframes.last().unwrap(),
+ ));
+ // This can be removed if size restrictions call for it
+ match if time > length {
+ if time > length * f64::from(self.loop_count) {
None
+ } else {
+ Some(time % length)
}
- };
- match idx {
+ } else {
+ Some(time)
+ } {
None => None,
- Some(idx) => {
- // If it's the last item, we don't have a 2nd
- if idx + 1 == sorted_keyframes.len() {
- None
- } else {
- Some((
- *sorted_keyframes.index(idx),
- *sorted_keyframes.index(idx + 1),
- ))
+ Some(time) => {
+ // TODO: maybe refactor the internals of this to be faster
+ let idx = {
+ let mut idx = 0;
+ let mut found = false;
+ for f in &sorted_keyframes {
+ if f.time > time {
+ found = true;
+ break;
+ } else {
+ idx += 1;
+ }
+ }
+ if found {
+ Some(idx)
+ } else {
+ None
+ }
+ };
+ match idx {
+ None => None,
+ Some(idx) => {
+ // If it's the last item, we don't have a 2nd
+ if idx + 1 == sorted_keyframes.len() {
+ None
+ } else {
+ Some((
+ *sorted_keyframes.index(idx),
+ *sorted_keyframes.index(idx + 1),
+ ))
+ }
+ }
}
}
}