rosu_map/section/timing_points/control_points/
difficulty.rs1use std::cmp::Ordering;
2
3#[derive(Clone, Debug, PartialEq)]
5pub struct DifficultyPoint {
6 pub time: f64,
7 pub slider_velocity: f64,
8 pub generate_ticks: bool,
9}
10
11impl DifficultyPoint {
12 pub const DEFAULT_SLIDER_VELOCITY: f64 = 1.0;
13 pub const DEFAULT_GENERATE_TICKS: bool = true;
14
15 pub fn new(time: f64, beat_len: f64, speed_multiplier: f64) -> Self {
16 Self {
17 time,
18 slider_velocity: speed_multiplier.clamp(0.1, 10.0),
19 generate_ticks: !beat_len.is_nan(),
20 }
21 }
22
23 pub fn is_redundant(&self, existing: &Self) -> bool {
24 self.generate_ticks == existing.generate_ticks
25 && (self.slider_velocity - existing.slider_velocity).abs() < f64::EPSILON
26 }
27}
28
29impl Default for DifficultyPoint {
30 fn default() -> Self {
31 Self {
32 time: 0.0,
33 slider_velocity: Self::DEFAULT_SLIDER_VELOCITY,
34 generate_ticks: Self::DEFAULT_GENERATE_TICKS,
35 }
36 }
37}
38
39impl PartialOrd for DifficultyPoint {
40 fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
41 self.time.partial_cmp(&other.time)
42 }
43}