blender_armature/action/bone_keyframes/
sorted_keyframes.rs1use crate::BoneKeyframe;
2use std::cmp::Ordering;
3use std::ops::Deref;
4use std::slice::IterMut;
5
6mod deserialize;
7
8#[derive(Debug, PartialEq, Serialize, Default, Clone)]
10pub struct SortedKeyframes(Vec<BoneKeyframe>);
11
12impl SortedKeyframes {
13 pub fn new(keyframes: Vec<BoneKeyframe>) -> Self {
17 let mut keys = SortedKeyframes(keyframes);
18
19 keys.sort_ascending();
20
21 keys
22 }
23
24 fn sort_ascending(&mut self) {
25 self.0.sort_by(|a, b| a.frame().cmp(&b.frame()));
26 }
27}
28
29impl SortedKeyframes {
30 pub(crate) fn iter_mut(&mut self) -> IterMut<'_, BoneKeyframe> {
31 self.0.iter_mut()
32 }
33
34 pub(crate) fn push(&mut self, bone_keyframe: BoneKeyframe) {
35 self.0.push(bone_keyframe)
36 }
37
38 pub(crate) fn sort_by<F>(&mut self, compare: F)
39 where
40 F: FnMut(&BoneKeyframe, &BoneKeyframe) -> Ordering,
41 {
42 self.0.sort_by(compare);
43 }
44}
45
46impl Deref for SortedKeyframes {
47 type Target = Vec<BoneKeyframe>;
48
49 fn deref(&self) -> &Self::Target {
50 &self.0
51 }
52}