feat: added convenience methods

This commit is contained in:
MaxOhn
2023-12-29 11:31:35 +01:00
parent f2854dbde5
commit f3c39c7891
10 changed files with 164 additions and 57 deletions
+6
View File
@@ -595,6 +595,12 @@ impl OsuDifficultyAttributes {
pub fn n_objects(&self) -> usize {
self.n_circles + self.n_sliders + self.n_spinners
}
/// Returns a builder for performance calculation.
#[inline]
pub fn pp(self) -> OsuPP<'static> {
OsuPP::from(self)
}
}
/// The result of a performance calculation on an osu!standard map.
+28 -14
View File
@@ -437,20 +437,7 @@ impl<'map> OsuPP<'map> {
/// attributes for catch e.g. if it's [`DifficultyAttributes::Taiko`].
#[inline]
pub fn try_from_attributes(attributes: impl OsuAttributeProvider) -> Option<Self> {
attributes.attributes().map(|attrs| Self {
map_or_attrs: MapOrElse::Else(attrs),
mods: 0,
acc: None,
combo: None,
n300: None,
n100: None,
n50: None,
n_misses: None,
passed_objects: None,
clock_rate: None,
hitresult_priority: None,
})
attributes.attributes().map(Self::from)
}
}
@@ -782,6 +769,33 @@ fn accuracy(n300: usize, n100: usize, n50: usize, n_misses: usize) -> f64 {
numerator as f64 / denominator as f64
}
impl From<OsuDifficultyAttributes> for OsuPP<'_> {
#[inline]
fn from(attrs: OsuDifficultyAttributes) -> Self {
Self {
map_or_attrs: MapOrElse::Else(attrs),
mods: 0,
acc: None,
combo: None,
n300: None,
n100: None,
n50: None,
n_misses: None,
passed_objects: None,
clock_rate: None,
hitresult_priority: None,
}
}
}
impl From<OsuPerformanceAttributes> for OsuPP<'_> {
#[inline]
fn from(attrs: OsuPerformanceAttributes) -> Self {
attrs.difficulty.into()
}
}
/// Abstract type to provide flexibility when passing difficulty attributes to a performance calculation.
pub trait OsuAttributeProvider {
/// Provide the actual difficulty attributes.