renamed PpResult+StarResult, minor structural adjustments, documentation update
This commit is contained in:
+11
-12
@@ -11,18 +11,18 @@ use crate::{parse::HitObject, Beatmap, GameMode, Mods, Strains};
|
||||
const SECTION_LEN: f64 = 400.0;
|
||||
const STAR_SCALING_FACTOR: f64 = 0.018;
|
||||
|
||||
/// Star calculation for osu!mania maps
|
||||
/// Difficulty calculation for osu!mania maps.
|
||||
///
|
||||
/// In case of a partial play, e.g. a fail, one can specify the amount of passed objects.
|
||||
pub fn stars(
|
||||
map: &Beatmap,
|
||||
mods: impl Mods,
|
||||
passed_objects: Option<usize>,
|
||||
) -> DifficultyAttributes {
|
||||
) -> ManiaDifficultyAttributes {
|
||||
let take = passed_objects.unwrap_or_else(|| map.hit_objects.len());
|
||||
|
||||
if take < 2 {
|
||||
return DifficultyAttributes::default();
|
||||
return ManiaDifficultyAttributes::default();
|
||||
}
|
||||
|
||||
let rounded_cs = map.cs.round();
|
||||
@@ -90,10 +90,10 @@ pub fn stars(
|
||||
|
||||
let stars = strain.difficulty_value() * STAR_SCALING_FACTOR;
|
||||
|
||||
DifficultyAttributes { stars }
|
||||
ManiaDifficultyAttributes { stars }
|
||||
}
|
||||
|
||||
/// Essentially the same as the `stars` function but instead of
|
||||
/// Essentially the same as the [`stars`] function but instead of
|
||||
/// evaluating the final strains, it just returns them as is.
|
||||
///
|
||||
/// Suitable to plot the difficulty of a map over time.
|
||||
@@ -169,23 +169,22 @@ impl<'o> DifficultyHitObject<'o> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Various data created through the star calculation.
|
||||
/// This data is necessary to calculate PP.
|
||||
/// The result of a difficulty calculation on an osu!mania map.
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
pub struct DifficultyAttributes {
|
||||
pub struct ManiaDifficultyAttributes {
|
||||
pub stars: f64,
|
||||
}
|
||||
|
||||
/// Various data created through the pp calculation.
|
||||
/// The result of a performance calculation on an osu!mania map.
|
||||
#[derive(Copy, Clone, Debug, Default)]
|
||||
pub struct PerformanceAttributes {
|
||||
pub attributes: DifficultyAttributes,
|
||||
pub struct ManiaPerformanceAttributes {
|
||||
pub attributes: ManiaDifficultyAttributes,
|
||||
pub pp_acc: f64,
|
||||
pub pp_strain: f64,
|
||||
pub pp: f64,
|
||||
}
|
||||
|
||||
impl PerformanceAttributes {
|
||||
impl ManiaPerformanceAttributes {
|
||||
/// Return the star value.
|
||||
#[inline]
|
||||
pub fn stars(&self) -> f64 {
|
||||
|
||||
+12
-13
@@ -1,7 +1,7 @@
|
||||
use super::{stars, DifficultyAttributes, PerformanceAttributes};
|
||||
use crate::{Beatmap, Mods, PpResult, StarResult};
|
||||
use super::{stars, ManiaDifficultyAttributes, ManiaPerformanceAttributes};
|
||||
use crate::{Beatmap, DifficultyAttributes, Mods, PerformanceAttributes};
|
||||
|
||||
/// Calculator for pp on osu!mania maps.
|
||||
/// Performance calculator on osu!mania maps.
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
@@ -48,9 +48,7 @@ impl<'m> ManiaPP<'m> {
|
||||
}
|
||||
}
|
||||
|
||||
/// [`ManiaAttributeProvider`] is implemented by `f32`, [`StarResult`](crate::StarResult),
|
||||
/// and by [`PpResult`](crate::PpResult) meaning you can give the star rating,
|
||||
/// the result of a star calculation, or the result of a pp calculation.
|
||||
/// Provide the result of previous a difficulty or performance calculation.
|
||||
/// If you already calculated the attributes for the current map-mod combination,
|
||||
/// be sure to put them in here so that they don't have to be recalculated.
|
||||
#[inline]
|
||||
@@ -90,7 +88,7 @@ impl<'m> ManiaPP<'m> {
|
||||
}
|
||||
|
||||
/// Calculate all performance related values, including pp and stars.
|
||||
pub fn calculate(self) -> PerformanceAttributes {
|
||||
pub fn calculate(self) -> ManiaPerformanceAttributes {
|
||||
let stars = self
|
||||
.stars
|
||||
.unwrap_or_else(|| stars(self.map, self.mods, self.passed_objects).stars);
|
||||
@@ -131,8 +129,8 @@ impl<'m> ManiaPP<'m> {
|
||||
|
||||
let pp = (strain_value.powf(1.1) + acc_value.powf(1.1)).powf(1.0 / 1.1) * multiplier;
|
||||
|
||||
PerformanceAttributes {
|
||||
attributes: DifficultyAttributes { stars },
|
||||
ManiaPerformanceAttributes {
|
||||
attributes: ManiaDifficultyAttributes { stars },
|
||||
pp_acc: acc_value,
|
||||
pp_strain: strain_value,
|
||||
pp,
|
||||
@@ -169,6 +167,7 @@ impl<'m> ManiaPP<'m> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Abstract type to provide flexibility when passing difficulty attributes to a performance calculation.
|
||||
pub trait ManiaAttributeProvider {
|
||||
fn attributes(self) -> Option<f64>;
|
||||
}
|
||||
@@ -180,21 +179,21 @@ impl ManiaAttributeProvider for f64 {
|
||||
}
|
||||
}
|
||||
|
||||
impl ManiaAttributeProvider for DifficultyAttributes {
|
||||
impl ManiaAttributeProvider for ManiaDifficultyAttributes {
|
||||
#[inline]
|
||||
fn attributes(self) -> Option<f64> {
|
||||
Some(self.stars)
|
||||
}
|
||||
}
|
||||
|
||||
impl ManiaAttributeProvider for PerformanceAttributes {
|
||||
impl ManiaAttributeProvider for ManiaPerformanceAttributes {
|
||||
#[inline]
|
||||
fn attributes(self) -> Option<f64> {
|
||||
Some(self.attributes.stars)
|
||||
}
|
||||
}
|
||||
|
||||
impl ManiaAttributeProvider for StarResult {
|
||||
impl ManiaAttributeProvider for DifficultyAttributes {
|
||||
#[inline]
|
||||
fn attributes(self) -> Option<f64> {
|
||||
#[allow(irrefutable_let_patterns)]
|
||||
@@ -206,7 +205,7 @@ impl ManiaAttributeProvider for StarResult {
|
||||
}
|
||||
}
|
||||
|
||||
impl ManiaAttributeProvider for PpResult {
|
||||
impl ManiaAttributeProvider for PerformanceAttributes {
|
||||
#[inline]
|
||||
fn attributes(self) -> Option<f64> {
|
||||
#[allow(irrefutable_let_patterns)]
|
||||
|
||||
Reference in New Issue
Block a user