rosu_map/section/hit_objects/slider/
mod.rs

1use crate::util::Pos;
2
3use self::path::{PathControlPoint, SliderPath};
4
5use super::{hit_samples::HitSampleInfo, CurveBuffers};
6
7pub mod curve;
8pub mod event;
9pub mod path;
10pub mod path_type;
11
12/// A slider [`HitObject`].
13///
14/// [`HitObject`]: crate::section::hit_objects::HitObject
15#[derive(Clone, Debug, PartialEq)]
16pub struct HitObjectSlider {
17    pub pos: Pos,
18    pub new_combo: bool,
19    pub combo_offset: i32,
20    pub path: SliderPath,
21    pub node_samples: Vec<Vec<HitSampleInfo>>,
22    pub repeat_count: i32,
23    pub velocity: f64,
24}
25
26impl HitObjectSlider {
27    pub const fn span_count(&self) -> i32 {
28        self.repeat_count + 1
29    }
30
31    /// Returns the duration of the slider.
32    ///
33    /// If the curve has not yet been accessed, it needs to be calculated
34    /// first.
35    ///
36    /// In case curves of multiple slider paths are being calculated, it is
37    /// recommended to initialize [`CurveBuffers`] and pass a mutable reference
38    /// of it to [`HitObjectSlider::duration_with_bufs`] so the buffers are
39    /// re-used for all sliders.
40    pub fn duration(&mut self) -> f64 {
41        self.duration_with_bufs(&mut CurveBuffers::default())
42    }
43
44    /// Returns the duration of the slider.
45    ///
46    /// If the slider's curve has not yet been accessed, it needs to be
47    /// calculated first for which the given [`CurveBuffers`] are used.
48    pub fn duration_with_bufs(&mut self, bufs: &mut CurveBuffers) -> f64 {
49        f64::from(self.span_count()) * self.path.curve_with_bufs(bufs).dist() / self.velocity
50    }
51}