feat: adjusted lint restrictions (#31)

This commit is contained in:
Badewanne3
2023-12-31 09:19:41 +01:00
committed by GitHub
parent aeb65ab3a4
commit ecf1b2c7f4
59 changed files with 427 additions and 374 deletions
+4 -4
View File
@@ -20,7 +20,7 @@ pub struct CatchObject {
impl CatchObject {
#[inline]
pub(crate) fn new((pos, time): (Pos2, f64)) -> Self {
pub(crate) const fn new((pos, time): (Pos2, f64)) -> Self {
Self {
pos: pos.x,
time,
@@ -70,7 +70,7 @@ impl CatchObject {
let next_x = next.pos;
let curr_x = self.pos;
let this_direction = (next_x > curr_x) as i8 * 2 - 1;
let this_direction = i8::from(next_x > curr_x) * 2 - 1;
let time_to_next = next.time - self.time - 1000.0 / 60.0 / 4.0;
let sub = if *last_direction == this_direction {
@@ -79,7 +79,7 @@ impl CatchObject {
half_catcher_width
};
let dist_to_next = (next_x - curr_x).abs() as f64 - sub;
let dist_to_next = f64::from((next_x - curr_x).abs()) - sub;
let hyper_dist = (time_to_next * BASE_SPEED - dist_to_next) as f32;
if hyper_dist < 0.0 {
@@ -87,7 +87,7 @@ impl CatchObject {
*last_excess = half_catcher_width;
} else {
self.hyper_dist = hyper_dist;
*last_excess = (hyper_dist as f64).clamp(0.0, half_catcher_width);
*last_excess = f64::from(hyper_dist).clamp(0.0, half_catcher_width);
}
*last_direction = this_direction;
+3 -3
View File
@@ -121,7 +121,7 @@ impl FruitOrJuice {
slider_objects.extend(&params.ticks);
for span_idx in 1..=*repeats {
let progress = (span_idx % 2 == 1) as u8 as f64;
let progress = f64::from(u8::from(span_idx % 2 == 1));
let pos = h.pos + curve.position_at(progress);
let time_offset = span_duration * span_idx as f64;
@@ -153,11 +153,11 @@ impl FruitOrJuice {
}
// Slider tail
let progress = (*repeats % 2 == 0) as u8 as f64;
let progress = f64::from(u8::from(*repeats % 2 == 0));
let pos = h.pos + curve.position_at(progress);
slider_objects.push((pos, h.start_time + total_duration));
let new_fruits = 2 + (tick_dist > 0.0) as usize * *repeats;
let new_fruits = 2 + usize::from(tick_dist > 0.0) * *repeats;
params.attributes.n_fruits += new_fruits;
params.attributes.n_droplets += slider_objects.len() - new_fruits;
+3 -3
View File
@@ -62,7 +62,7 @@ impl<'map> CatchGradualDifficulty<'map> {
Self { map, inner }
}
pub(crate) fn idx(&self) -> usize {
pub(crate) const fn idx(&self) -> usize {
self.inner.idx
}
}
@@ -96,7 +96,7 @@ impl CatchOwnedGradualDifficulty {
}
#[allow(unused)]
pub(crate) fn idx(&self) -> usize {
pub(crate) const fn idx(&self) -> usize {
self.inner.idx
}
}
@@ -181,7 +181,7 @@ impl CatchGradualDifficultyInner {
let hit_objects = CatchObjectIter::new(mods, attributes);
let half_catcher_width =
(calculate_catch_width(map_attributes.cs as f32) / 2.0 / ALLOWED_CATCH_RANGE) as f64;
f64::from(calculate_catch_width(map_attributes.cs as f32) / 2.0 / ALLOWED_CATCH_RANGE);
let last_direction = 0;
let last_excess = half_catcher_width;
+12 -10
View File
@@ -50,6 +50,7 @@ const CATCHER_SIZE: f32 = 106.75;
/// println!("Stars: {}", difficulty_attrs.stars);
/// ```
#[derive(Clone, Debug)]
#[must_use]
pub struct CatchStars<'map> {
map: &'map Beatmap,
mods: u32,
@@ -60,7 +61,7 @@ pub struct CatchStars<'map> {
impl<'map> CatchStars<'map> {
/// Create a new difficulty calculator for osu!catch maps.
#[inline]
pub fn new(map: &'map Beatmap) -> Self {
pub const fn new(map: &'map Beatmap) -> Self {
Self {
map,
mods: 0,
@@ -73,7 +74,7 @@ impl<'map> CatchStars<'map> {
///
/// See [https://github.com/ppy/osu-api/wiki#mods](https://github.com/ppy/osu-api/wiki#mods)
#[inline]
pub fn mods(mut self, mods: u32) -> Self {
pub const fn mods(mut self, mods: u32) -> Self {
self.mods = mods;
self
@@ -88,7 +89,7 @@ impl<'map> CatchStars<'map> {
[`CatchGradualDifficultyAttributes`](crate::catch::CatchGradualDifficulty)."
)]
#[inline]
pub fn passed_objects(mut self, passed_objects: usize) -> Self {
pub const fn passed_objects(mut self, passed_objects: usize) -> Self {
self.passed_objects = Some(passed_objects);
self
@@ -98,7 +99,7 @@ impl<'map> CatchStars<'map> {
/// If none is specified, it will take the clock rate based on the mods
/// i.e. 1.5 for DT, 0.75 for HT and 1.0 otherwise.
#[inline]
pub fn clock_rate(mut self, clock_rate: f64) -> Self {
pub const fn clock_rate(mut self, clock_rate: f64) -> Self {
self.clock_rate = Some(clock_rate);
self
@@ -147,6 +148,7 @@ impl CatchStrains {
}
}
#[allow(clippy::needless_pass_by_value)]
fn calculate_movement(params: CatchStars<'_>) -> (Movement, CatchDifficultyAttributes) {
let CatchStars {
map,
@@ -183,7 +185,7 @@ fn calculate_movement(params: CatchStars<'_>) -> (Movement, CatchDifficultyAttri
// Hyper dash business
let half_catcher_width =
(calculate_catch_width(map_attributes.cs as f32) / 2.0 / ALLOWED_CATCH_RANGE) as f64;
f64::from(calculate_catch_width(map_attributes.cs as f32) / 2.0 / ALLOWED_CATCH_RANGE);
let mut last_direction = 0;
let mut last_excess = half_catcher_width;
@@ -192,7 +194,7 @@ fn calculate_movement(params: CatchStars<'_>) -> (Movement, CatchDifficultyAttri
let (mut prev, curr) = match (hit_objects.next(), hit_objects.next()) {
(Some(prev), Some(curr)) => (prev, curr),
(Some(_), None) | (None, None) => return (movement, params.attributes),
(_, None) => return (movement, params.attributes),
(None, Some(_)) => unreachable!(),
};
@@ -274,7 +276,7 @@ pub struct CatchDifficultyAttributes {
impl CatchDifficultyAttributes {
/// Return the maximum combo.
#[inline]
pub fn max_combo(&self) -> usize {
pub const fn max_combo(&self) -> usize {
self.n_fruits + self.n_droplets
}
@@ -297,19 +299,19 @@ pub struct CatchPerformanceAttributes {
impl CatchPerformanceAttributes {
/// Return the star value.
#[inline]
pub fn stars(&self) -> f64 {
pub const fn stars(&self) -> f64 {
self.difficulty.stars
}
/// Return the performance point value.
#[inline]
pub fn pp(&self) -> f64 {
pub const fn pp(&self) -> f64 {
self.pp
}
/// Return the maximum combo of the map.
#[inline]
pub fn max_combo(&self) -> usize {
pub const fn max_combo(&self) -> usize {
self.difficulty.max_combo()
}
}
+9 -7
View File
@@ -90,15 +90,15 @@ impl Movement {
let dist_moved = pos - last_player_pos;
let weighted_strain_time = current.strain_time + 13.0 + (3.0 / current.clock_rate);
let mut dist_addition = (dist_moved.abs().powf(1.3) / 510.0) as f64;
let mut dist_addition = f64::from(dist_moved.abs().powf(1.3) / 510.0);
if dist_moved.abs() > 0.1 {
if self.last_distance_moved.abs() > 0.1
&& dist_moved.signum() != self.last_distance_moved.signum()
{
let bonus_factor = (dist_moved.abs().min(50.0) / 50.0) as f64;
let bonus_factor = f64::from(dist_moved.abs().min(50.0) / 50.0);
let anti_flow_factor =
(self.last_distance_moved.abs().min(70.0) / 70.0).max(0.38) as f64;
f64::from((self.last_distance_moved.abs().min(70.0) / 70.0).max(0.38));
dist_addition += DIRECTION_CHANGE_BONUS / (self.last_strain_time + 16.0).sqrt()
* bonus_factor
@@ -106,14 +106,16 @@ impl Movement {
* (1.0 - (weighted_strain_time / 1000.0).powi(3)).max(0.0);
}
dist_addition += (12.5 * dist_moved.abs().min(NORMALIZED_HITOBJECT_RADIUS * 2.0)
/ (NORMALIZED_HITOBJECT_RADIUS * 6.0)) as f64
/ weighted_strain_time.sqrt();
dist_addition += f64::from(
12.5 * dist_moved.abs().min(NORMALIZED_HITOBJECT_RADIUS * 2.0)
/ (NORMALIZED_HITOBJECT_RADIUS * 6.0),
) / weighted_strain_time.sqrt();
}
let mut edge_dash_bonus = 0.0;
if current.last.hyper_dist <= 20.0 {
#[allow(clippy::if_not_else)]
if !current.last.hyper_dash {
edge_dash_bonus += 5.7;
} else {
@@ -122,7 +124,7 @@ impl Movement {
dist_addition *= 1.0
+ edge_dash_bonus
* ((20.0 - current.last.hyper_dist) / 20.0) as f64
* f64::from((20.0 - current.last.hyper_dist) / 20.0)
* ((current.strain_time * current.clock_rate).min(265.0) / 265.0).powf(1.5);
}
+19 -15
View File
@@ -36,6 +36,7 @@ use std::cmp::Ordering;
/// ```
#[derive(Clone, Debug)]
#[allow(clippy::upper_case_acronyms)]
#[must_use]
pub struct CatchPP<'map> {
pub(crate) map_or_attrs: MapOrElse<MapRef<'map>, CatchDifficultyAttributes>,
pub(crate) mods: u32,
@@ -87,7 +88,7 @@ impl<'map> CatchPP<'map> {
///
/// See [https://github.com/ppy/osu-api/wiki#mods](https://github.com/ppy/osu-api/wiki#mods)
#[inline]
pub fn mods(mut self, mods: u32) -> Self {
pub const fn mods(mut self, mods: u32) -> Self {
self.mods = mods;
self
@@ -95,7 +96,7 @@ impl<'map> CatchPP<'map> {
/// Specify the max combo of the play.
#[inline]
pub fn combo(mut self, combo: usize) -> Self {
pub const fn combo(mut self, combo: usize) -> Self {
self.combo = Some(combo);
self
@@ -103,7 +104,7 @@ impl<'map> CatchPP<'map> {
/// Specify the amount of fruits of a play i.e. n300.
#[inline]
pub fn fruits(mut self, n_fruits: usize) -> Self {
pub const fn fruits(mut self, n_fruits: usize) -> Self {
self.n_fruits = Some(n_fruits);
self
@@ -111,7 +112,7 @@ impl<'map> CatchPP<'map> {
/// Specify the amount of droplets of a play i.e. n100.
#[inline]
pub fn droplets(mut self, n_droplets: usize) -> Self {
pub const fn droplets(mut self, n_droplets: usize) -> Self {
self.n_droplets = Some(n_droplets);
self
@@ -119,15 +120,15 @@ impl<'map> CatchPP<'map> {
/// Specify the amount of tiny droplets of a play i.e. n50.
#[inline]
pub fn tiny_droplets(mut self, n_tiny_droplets: usize) -> Self {
pub const fn tiny_droplets(mut self, n_tiny_droplets: usize) -> Self {
self.n_tiny_droplets = Some(n_tiny_droplets);
self
}
/// Specify the amount of tiny droplet misses of a play i.e. n_katu.
/// Specify the amount of tiny droplet misses of a play i.e. `n_katu`.
#[inline]
pub fn tiny_droplet_misses(mut self, n_tiny_droplet_misses: usize) -> Self {
pub const fn tiny_droplet_misses(mut self, n_tiny_droplet_misses: usize) -> Self {
self.n_tiny_droplet_misses = Some(n_tiny_droplet_misses);
self
@@ -135,7 +136,7 @@ impl<'map> CatchPP<'map> {
/// Specify the amount of fruit / droplet misses of the play.
#[inline]
pub fn misses(mut self, n_misses: usize) -> Self {
pub const fn misses(mut self, n_misses: usize) -> Self {
self.n_misses = Some(n_misses);
self
@@ -150,7 +151,7 @@ impl<'map> CatchPP<'map> {
[`CatchGradualPerformanceAttributes`](crate::catch::CatchGradualPerformance)."
)]
#[inline]
pub fn passed_objects(mut self, passed_objects: usize) -> Self {
pub const fn passed_objects(mut self, passed_objects: usize) -> Self {
self.passed_objects = Some(passed_objects);
self
@@ -160,7 +161,7 @@ impl<'map> CatchPP<'map> {
/// If none is specified, it will take the clock rate based on the mods
/// i.e. 1.5 for DT, 0.75 for HT and 1.0 otherwise.
#[inline]
pub fn clock_rate(mut self, clock_rate: f64) -> Self {
pub const fn clock_rate(mut self, clock_rate: f64) -> Self {
self.clock_rate = Some(clock_rate);
self
@@ -168,7 +169,8 @@ impl<'map> CatchPP<'map> {
/// Provide parameters through an [`CatchScoreState`].
#[inline]
pub fn state(mut self, state: CatchScoreState) -> Self {
#[allow(clippy::needless_pass_by_value)]
pub const fn state(mut self, state: CatchScoreState) -> Self {
let CatchScoreState {
max_combo,
n_fruits,
@@ -198,6 +200,7 @@ impl<'map> CatchPP<'map> {
}
/// Create the [`CatchScoreState`] that will be used for performance calculation.
#[allow(clippy::too_many_lines)]
pub fn generate_state(&mut self) -> CatchScoreState {
let attrs = match self.map_or_attrs {
MapOrElse::Map(ref map) => {
@@ -297,6 +300,7 @@ impl<'map> CatchPP<'map> {
}
};
#[allow(clippy::single_match_else)]
match (self.n_tiny_droplets, self.n_tiny_droplet_misses) {
(Some(n_tiny_droplets), Some(n_tiny_droplet_misses)) => match self.acc {
Some(acc) => {
@@ -376,7 +380,7 @@ impl<'map> CatchPP<'map> {
///
/// [`OsuDifficultyAttributes`]: crate::osu::OsuDifficultyAttributes
#[inline]
pub fn try_from_osu(osu: OsuPP<'map>) -> Option<Self> {
pub const fn try_from_osu(osu: OsuPP<'map>) -> Option<Self> {
let OsuPP {
map_or_attrs,
mods,
@@ -449,7 +453,7 @@ impl CatchPPInner {
// Longer maps are worth more
let len_bonus = 0.95
+ 0.3 * (combo_hits as f64 / 2500.0).min(1.0)
+ (combo_hits > 2500) as u8 as f64 * (combo_hits as f64 / 2500.0).log10() * 0.475;
+ f64::from(u8::from(combo_hits > 2500)) * (combo_hits as f64 / 2500.0).log10() * 0.475;
pp *= len_bonus;
@@ -467,7 +471,7 @@ impl CatchPPInner {
let ar = attributes.ar;
let mut ar_factor = 1.0;
if ar > 9.0 {
ar_factor += 0.1 * (ar - 9.0) + (ar > 10.0) as u8 as f64 * 0.1 * (ar - 10.0);
ar_factor += 0.1 * (ar - 9.0) + f64::from(u8::from(ar > 10.0)) * 0.1 * (ar - 10.0);
} else if ar < 8.0 {
ar_factor += 0.025 * (8.0 - ar);
}
@@ -501,7 +505,7 @@ impl CatchPPInner {
}
}
fn combo_hits(&self) -> usize {
const fn combo_hits(&self) -> usize {
self.state.n_fruits + self.state.n_droplets + self.state.n_misses
}
}
+1 -1
View File
@@ -27,7 +27,7 @@ impl CatchScoreState {
/// Return the total amount of hits by adding everything up.
#[inline]
pub fn total_hits(&self) -> usize {
pub const fn total_hits(&self) -> usize {
self.n_fruits
+ self.n_droplets
+ self.n_tiny_droplets