rosu_pp/model/control_point/
effect.rs1use crate::util::float_ext::FloatExt;
2
3#[derive(Copy, Clone, Debug, PartialEq)]
5pub struct EffectPoint {
6 pub time: f64,
7 pub kiai: bool,
8 pub scroll_speed: f64,
9}
10
11impl EffectPoint {
12 pub const DEFAULT_KIAI: bool = rosu_map::section::timing_points::EffectPoint::DEFAULT_KIAI;
13 pub const DEFAULT_SCROLL_SPEED: f64 =
14 rosu_map::section::timing_points::EffectPoint::DEFAULT_SCROLL_SPEED;
15
16 pub const fn new(time: f64, kiai: bool) -> Self {
17 Self {
18 time,
19 kiai,
20 scroll_speed: Self::DEFAULT_SCROLL_SPEED,
21 }
22 }
23
24 pub fn is_redundant(&self, existing: &Self) -> bool {
25 self.kiai == existing.kiai && FloatExt::eq(self.scroll_speed, existing.scroll_speed)
26 }
27}
28
29impl Default for EffectPoint {
30 fn default() -> Self {
31 Self {
32 time: 0.0,
33 kiai: Self::DEFAULT_KIAI,
34 scroll_speed: Self::DEFAULT_SCROLL_SPEED,
35 }
36 }
37}
38
39pub fn effect_point_at(points: &[EffectPoint], time: f64) -> Option<&EffectPoint> {
40 points
41 .binary_search_by(|probe| probe.time.total_cmp(&time))
42 .map_or_else(|i| i.checked_sub(1), Some)
43 .map(|i| &points[i])
44}