Skip to content

Commit

Permalink
chore: made clippy happy
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxOhn committed Oct 11, 2024
1 parent 915d07e commit 25d8d29
Show file tree
Hide file tree
Showing 10 changed files with 50 additions and 29 deletions.
8 changes: 6 additions & 2 deletions src/mania/convert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ fn target_columns(map: &Beatmap) -> f32 {

// * In osu!stable, this division appears as if it happens on floats, but due to release-mode
// * optimisations, it actually ends up happening on doubles.
let percent_slider_or_spinner = f64::from(count_slider_or_spinner as f64 / len as f64);
let percent_slider_or_spinner = count_slider_or_spinner as f64 / len as f64;

if percent_slider_or_spinner < 0.2 {
return 7.0;
Expand All @@ -211,7 +211,11 @@ fn target_columns(map: &Beatmap) -> f32 {
}
}

((rounded_od as i32) + 1).min(7).max(4) as f32
// Keeping it in-sync with lazer
#[allow(clippy::manual_clamp)]
{
((rounded_od as i32) + 1).min(7).max(4) as f32
}
}

#[cfg(test)]
Expand Down
27 changes: 17 additions & 10 deletions src/model/beatmap/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ impl<M> From<&Converted<'_, M>> for BeatmapAttributesBuilder {
}
}

// False positive? Value looks consumed to me...
#[allow(clippy::needless_pass_by_value)]
fn difficulty_range(difficulty: f64, windows: GameModeHitWindows) -> f64 {
let GameModeHitWindows { min, avg: mid, max } = windows;

Expand Down Expand Up @@ -425,13 +427,18 @@ impl ModsDependentKind {

#[cfg(test)]
mod tests {
use rosu_mods::{generated_mods::DifficultyAdjustOsu, GameMod, GameMods};
#![allow(clippy::float_cmp)]

use rosu_mods::{
generated_mods::{DifficultyAdjustOsu, DoubleTimeCatch, DoubleTimeOsu, HiddenOsu},
GameMod, GameMods,
};

use super::*;

#[test]
fn default_ar() {
let gamemod = GameMod::HiddenOsu(Default::default());
let gamemod = GameMod::HiddenOsu(HiddenOsu::default());
let diff = Difficulty::new().mods(GameMods::from(gamemod));
let attrs = BeatmapAttributesBuilder::new().difficulty(&diff).build();

Expand All @@ -440,7 +447,7 @@ mod tests {

#[test]
fn custom_ar_without_mods() {
let gamemod = GameMod::DoubleTimeOsu(Default::default());
let gamemod = GameMod::DoubleTimeOsu(DoubleTimeOsu::default());
let diff = Difficulty::new().mods(GameMods::from(gamemod));
let attrs = BeatmapAttributesBuilder::new()
.ar(8.5, false)
Expand All @@ -452,7 +459,7 @@ mod tests {

#[test]
fn custom_ar_with_mods() {
let gamemod = GameMod::DoubleTimeOsu(Default::default());
let gamemod = GameMod::DoubleTimeOsu(DoubleTimeOsu::default());
let diff = Difficulty::new().mods(GameMods::from(gamemod));
let attrs = BeatmapAttributesBuilder::new()
.ar(8.5, true)
Expand All @@ -465,10 +472,10 @@ mod tests {
#[test]
fn custom_mods_ar() {
let mut mods = GameMods::new();
mods.insert(GameMod::DoubleTimeCatch(Default::default()));
mods.insert(GameMod::DoubleTimeCatch(DoubleTimeCatch::default()));
mods.insert(GameMod::DifficultyAdjustOsu(DifficultyAdjustOsu {
approach_rate: Some(7.0),
..Default::default()
..DifficultyAdjustOsu::default()
}));
let diff = Difficulty::new().mods(mods);
let attrs = BeatmapAttributesBuilder::new().difficulty(&diff).build();
Expand All @@ -479,10 +486,10 @@ mod tests {
#[test]
fn custom_ar_custom_mods_ar_without_mods() {
let mut mods = GameMods::new();
mods.insert(GameMod::DoubleTimeCatch(Default::default()));
mods.insert(GameMod::DoubleTimeCatch(DoubleTimeCatch::default()));
mods.insert(GameMod::DifficultyAdjustOsu(DifficultyAdjustOsu {
approach_rate: Some(9.0),
..Default::default()
..DifficultyAdjustOsu::default()
}));

let diff = Difficulty::new().mods(mods).ar(8.5, false);
Expand All @@ -494,10 +501,10 @@ mod tests {
#[test]
fn custom_ar_custom_mods_ar_with_mods() {
let mut mods = GameMods::new();
mods.insert(GameMod::DoubleTimeCatch(Default::default()));
mods.insert(GameMod::DoubleTimeCatch(DoubleTimeCatch::default()));
mods.insert(GameMod::DifficultyAdjustOsu(DifficultyAdjustOsu {
approach_rate: Some(9.0),
..Default::default()
..DifficultyAdjustOsu::default()
}));

let diff = Difficulty::new().mods(mods).ar(8.5, true);
Expand Down
6 changes: 3 additions & 3 deletions src/osu/difficulty/gradual.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ impl Iterator for OsuGradualDifficulty {
DifficultyValues::eval(
&mut attrs,
self.difficulty.get_mods(),
aim_difficulty_value,
aim_no_sliders_difficulty_value,
speed_difficulty_value,
&aim_difficulty_value,
&aim_no_sliders_difficulty_value,
&speed_difficulty_value,
speed_relevant_note_count,
flashlight_difficulty_value,
);
Expand Down
12 changes: 6 additions & 6 deletions src/osu/difficulty/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ pub fn difficulty(difficulty: &Difficulty, converted: &OsuBeatmap<'_>) -> OsuDif
DifficultyValues::eval(
&mut attrs,
mods,
aim_difficulty_value,
aim_no_sliders_difficulty_value,
speed_difficulty_value,
&aim_difficulty_value,
&aim_no_sliders_difficulty_value,
&speed_difficulty_value,
speed_relevant_note_count,
flashlight_difficulty_value,
);
Expand Down Expand Up @@ -151,9 +151,9 @@ impl DifficultyValues {
pub fn eval(
attrs: &mut OsuDifficultyAttributes,
mods: &GameMods,
aim: UsedOsuStrainSkills<DifficultyValue>,
aim_no_sliders: UsedOsuStrainSkills<DifficultyValue>,
speed: UsedOsuStrainSkills<DifficultyValue>,
aim: &UsedOsuStrainSkills<DifficultyValue>,
aim_no_sliders: &UsedOsuStrainSkills<DifficultyValue>,
speed: &UsedOsuStrainSkills<DifficultyValue>,
speed_relevant_note_count: f64,
flashlight_difficulty_value: f64,
) {
Expand Down
5 changes: 3 additions & 2 deletions src/osu/difficulty/skills/speed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ impl RhythmEvaluator {
const RHYTHM_OVERALL_MULTIPLIER: f64 = 0.95;
const RHYTHM_RATIO_MULTIPLIER: f64 = 12.0;

#[allow(clippy::too_many_lines)]
fn evaluate_diff_of<'a>(
curr: &'a OsuDifficultyObject<'a>,
diff_objects: &'a [OsuDifficultyObject<'a>],
Expand Down Expand Up @@ -409,7 +410,7 @@ const _: [(); 0 - !{ MIN_DELTA_TIME - OsuDifficultyObject::MIN_DELTA_TIME as i32
[];

impl RhythmIsland {
fn new(delta_difference_eps: f64) -> Self {
const fn new(delta_difference_eps: f64) -> Self {
Self {
delta_difference_eps,
delta: 0,
Expand All @@ -433,7 +434,7 @@ impl RhythmIsland {
self.delta_count += 1;
}

fn is_similar_polarity(&self, other: &Self) -> bool {
const fn is_similar_polarity(&self, other: &Self) -> bool {
// * TODO: consider islands to be of similar polarity only if they're having the same average delta (we don't want to consider 3 singletaps similar to a triple)
// * naively adding delta check here breaks _a lot_ of maps because of the flawed ratio calculation
self.delta_count % 2 == other.delta_count % 2
Expand Down
4 changes: 2 additions & 2 deletions src/osu/difficulty/skills/strain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ impl Default for OsuStrainSkill {
Self {
// mean=406.72 | median=307
object_strains: Vec::with_capacity(256),
inner: Default::default(),
inner: StrainSkill::default(),
}
}
}
Expand Down Expand Up @@ -90,7 +90,7 @@ pub struct UsedOsuStrainSkills<T> {
}

impl UsedOsuStrainSkills<DifficultyValue> {
pub fn difficulty_value(&self) -> f64 {
pub const fn difficulty_value(&self) -> f64 {
self.value.0
}

Expand Down
6 changes: 3 additions & 3 deletions src/osu/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ impl OsuPerformanceInner<'_> {
aim_value *= len_bonus;

if self.effective_miss_count > 0.0 {
aim_value *= self.calculate_miss_penalty(
aim_value *= Self::calculate_miss_penalty(
self.effective_miss_count,
self.attrs.aim_difficult_strain_count,
);
Expand Down Expand Up @@ -714,7 +714,7 @@ impl OsuPerformanceInner<'_> {
speed_value *= len_bonus;

if self.effective_miss_count > 0.0 {
speed_value *= self.calculate_miss_penalty(
speed_value *= Self::calculate_miss_penalty(
self.effective_miss_count,
self.attrs.speed_difficult_strain_count,
);
Expand Down Expand Up @@ -857,7 +857,7 @@ impl OsuPerformanceInner<'_> {
// * Miss penalty assumes that a player will miss on the hardest parts of a map,
// * so we use the amount of relatively difficult sections to adjust miss penalty
// * to make it more punishing on maps with lower amount of hard sections.
fn calculate_miss_penalty(&self, miss_count: f64, diff_strain_count: f64) -> f64 {
fn calculate_miss_penalty(miss_count: f64, diff_strain_count: f64) -> f64 {
0.96 / ((miss_count / (4.0 * diff_strain_count.ln().powf(0.94))) + 1.0)
}

Expand Down
2 changes: 1 addition & 1 deletion src/taiko/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ struct SliderParams<'c> {
}

impl<'c> SliderParams<'c> {
fn new(start_time: f64, slider: &'c Slider) -> Self {
const fn new(start_time: f64, slider: &'c Slider) -> Self {
Self {
slider,
start_time,
Expand Down
1 change: 1 addition & 0 deletions src/taiko/performance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,7 @@ impl TaikoPerformanceInner<'_> {
let h100 = self.attrs.ok_hit_window;
let n = self.total_hits();

#[allow(clippy::items_after_statements, clippy::unreadable_literal)]
// * 99% critical value for the normal distribution (one-tailed).
const Z: f64 = 2.32634787404;

Expand Down
8 changes: 8 additions & 0 deletions src/util/special_functions.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
#![allow(
clippy::excessive_precision,
clippy::too_many_lines,
clippy::unreadable_literal,
clippy::many_single_char_names
)]

#[rustfmt::skip]
mod consts {
pub const ERF_IMP_AN: &[f64] = &[ 0.00337916709551257388990745, -0.00073695653048167948530905, -0.374732337392919607868241, 0.0817442448733587196071743, -0.0421089319936548595203468, 0.0070165709512095756344528, -0.00495091255982435110337458, 0.000871646599037922480317225 ];
Expand Down Expand Up @@ -45,6 +52,7 @@ mod consts {
pub const ERV_INV_IMP_GD: &[f64] = &[ 1.0, 0.0845746234001899436914, 0.00282092984726264681981, 0.468292921940894236786e-4, 0.399968812193862100054e-6, 0.161809290887904476097e-8, 0.231558608310259605225e-11 ];
}

#[allow(clippy::wildcard_imports)]
use consts::*;

pub fn erf(x: f64) -> f64 {
Expand Down

0 comments on commit 25d8d29

Please sign in to comment.