feat: compact strains (#32)
* store zero strains compactly * added docs * added proptest * add feature to store strains compactly * update ci * rename CompactZerosVec to StrainsVec * add size_hint for iter * rename iter * minor adjustments * more minor adjustments
This commit is contained in:
@@ -6,7 +6,7 @@ use crate::{
|
||||
skills::{strain_decay, ISkill, Skill},
|
||||
},
|
||||
osu::difficulty::object::OsuDifficultyObject,
|
||||
util::float_ext::FloatExt,
|
||||
util::{float_ext::FloatExt, strains_vec::StrainsVec},
|
||||
};
|
||||
|
||||
use super::strain::OsuStrainSkill;
|
||||
@@ -30,7 +30,7 @@ impl Aim {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_curr_strain_peaks(self) -> Vec<f64> {
|
||||
pub fn get_curr_strain_peaks(self) -> StrainsVec {
|
||||
self.inner.get_curr_strain_peaks()
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ use crate::{
|
||||
skills::{strain_decay, ISkill, Skill, StrainSkill},
|
||||
},
|
||||
osu::{difficulty::object::OsuDifficultyObject, object::OsuObjectKind},
|
||||
util::mods::Mods,
|
||||
util::{mods::Mods, strains_vec::StrainsVec},
|
||||
};
|
||||
|
||||
use super::strain::OsuStrainSkill;
|
||||
@@ -33,7 +33,7 @@ impl Flashlight {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_curr_strain_peaks(self) -> Vec<f64> {
|
||||
pub fn get_curr_strain_peaks(self) -> StrainsVec {
|
||||
self.inner.get_curr_strain_peaks()
|
||||
}
|
||||
|
||||
@@ -48,8 +48,7 @@ impl Flashlight {
|
||||
}
|
||||
|
||||
fn static_difficulty_value(skill: StrainSkill) -> f64 {
|
||||
skill.get_curr_strain_peaks().into_iter().sum::<f64>()
|
||||
* OsuStrainSkill::DIFFICULTY_MULTIPLER
|
||||
skill.get_curr_strain_peaks().sum() * OsuStrainSkill::DIFFICULTY_MULTIPLER
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::{
|
||||
skills::{strain_decay, ISkill, Skill},
|
||||
},
|
||||
osu::difficulty::object::OsuDifficultyObject,
|
||||
util::strains_vec::StrainsVec,
|
||||
};
|
||||
|
||||
use super::strain::OsuStrainSkill;
|
||||
@@ -37,7 +38,7 @@ impl Speed {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_curr_strain_peaks(self) -> Vec<f64> {
|
||||
pub fn get_curr_strain_peaks(self) -> StrainsVec {
|
||||
self.inner.get_curr_strain_peaks()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use crate::any::difficulty::skills::StrainSkill;
|
||||
use crate::{any::difficulty::skills::StrainSkill, util::strains_vec::StrainsVec};
|
||||
|
||||
#[derive(Clone, Default)]
|
||||
pub struct OsuStrainSkill {
|
||||
@@ -21,7 +21,7 @@ impl OsuStrainSkill {
|
||||
self.inner.start_new_section_from(initial_strain);
|
||||
}
|
||||
|
||||
pub fn get_curr_strain_peaks(self) -> Vec<f64> {
|
||||
pub fn get_curr_strain_peaks(self) -> StrainsVec {
|
||||
self.inner.get_curr_strain_peaks()
|
||||
}
|
||||
|
||||
@@ -36,10 +36,8 @@ impl OsuStrainSkill {
|
||||
let mut weight = 1.0;
|
||||
|
||||
let mut peaks = self.get_curr_strain_peaks();
|
||||
peaks.retain(|&strain| strain > 0.0);
|
||||
peaks.sort_by(|a, b| b.total_cmp(a));
|
||||
|
||||
let peaks_iter = peaks.iter_mut().take(reduced_section_count);
|
||||
let peaks_iter = peaks.sorted_non_zero_iter_mut().take(reduced_section_count);
|
||||
|
||||
for (i, strain) in peaks_iter.enumerate() {
|
||||
let clamped = f64::from((i as f32 / reduced_section_count as f32).clamp(0.0, 1.0));
|
||||
@@ -47,9 +45,9 @@ impl OsuStrainSkill {
|
||||
*strain *= lerp(reduced_strain_baseline, 1.0, scale);
|
||||
}
|
||||
|
||||
peaks.sort_by(|a, b| b.total_cmp(a));
|
||||
peaks.sort_desc();
|
||||
|
||||
for strain in peaks {
|
||||
for strain in peaks.iter() {
|
||||
difficulty += strain * weight;
|
||||
weight *= decay_weight;
|
||||
}
|
||||
|
||||
+4
-4
@@ -38,9 +38,9 @@ pub fn strains(difficulty: &Difficulty, converted: &OsuBeatmap<'_>) -> OsuStrain
|
||||
} = DifficultyValues::calculate(difficulty, converted);
|
||||
|
||||
OsuStrains {
|
||||
aim: aim.get_curr_strain_peaks(),
|
||||
aim_no_sliders: aim_no_sliders.get_curr_strain_peaks(),
|
||||
speed: speed.get_curr_strain_peaks(),
|
||||
flashlight: flashlight.get_curr_strain_peaks(),
|
||||
aim: aim.get_curr_strain_peaks().into_vec(),
|
||||
aim_no_sliders: aim_no_sliders.get_curr_strain_peaks().into_vec(),
|
||||
speed: speed.get_curr_strain_peaks().into_vec(),
|
||||
flashlight: flashlight.get_curr_strain_peaks().into_vec(),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user