1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
use std::cmp::Ordering;

#[derive(Clone, Debug, PartialEq)]
/// Effect-related info about this control point.
pub struct EffectPoint {
    pub time: f64,
    pub kiai: bool,
    pub scroll_speed: f64,
}

impl EffectPoint {
    pub const DEFAULT_KIAI: bool = false;
    pub const DEFAULT_SCROLL_SPEED: f64 = 1.0;

    pub const fn new(time: f64, kiai: bool) -> Self {
        Self {
            time,
            kiai,
            scroll_speed: Self::DEFAULT_SCROLL_SPEED,
        }
    }

    pub fn is_redundant(&self, existing: &Self) -> bool {
        self.kiai == existing.kiai
            && (self.scroll_speed - existing.scroll_speed).abs() < f64::EPSILON
    }
}

impl Default for EffectPoint {
    fn default() -> Self {
        Self {
            time: 0.0,
            kiai: Self::DEFAULT_KIAI,
            scroll_speed: Self::DEFAULT_SCROLL_SPEED,
        }
    }
}

impl PartialOrd for EffectPoint {
    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
        self.time.partial_cmp(&other.time)
    }
}