rosu_pp/catch/
score_state.rs1#[derive(Clone, Debug, PartialEq, Eq)]
3pub struct CatchScoreState {
4 pub max_combo: u32,
9 pub fruits: u32,
11 pub droplets: u32,
13 pub tiny_droplets: u32,
15 pub tiny_droplet_misses: u32,
17 pub misses: u32,
19}
20
21impl CatchScoreState {
22 pub const fn new() -> Self {
24 Self {
25 max_combo: 0,
26 fruits: 0,
27 droplets: 0,
28 tiny_droplets: 0,
29 tiny_droplet_misses: 0,
30 misses: 0,
31 }
32 }
33
34 pub const fn total_hits(&self) -> u32 {
36 self.fruits + self.droplets + self.tiny_droplets + self.tiny_droplet_misses + self.misses
37 }
38
39 pub fn accuracy(&self) -> f64 {
41 let total_hits = self.total_hits();
42
43 if total_hits == 0 {
44 return 0.0;
45 }
46
47 let numerator = self.fruits + self.droplets + self.tiny_droplets;
48 let denominator = total_hits;
49
50 f64::from(numerator) / f64::from(denominator)
51 }
52}
53
54impl Default for CatchScoreState {
55 fn default() -> Self {
56 Self::new()
57 }
58}