use cmp methods

This commit is contained in:
MaxOhn
2024-02-26 18:07:16 +01:00
parent c2c617ec01
commit e81c0e890f
15 changed files with 76 additions and 48 deletions
+3 -1
View File
@@ -1,3 +1,5 @@
use std::cmp;
use crate::{
any::difficulty::skills::Skill,
catch::{
@@ -131,7 +133,7 @@ impl Iterator for CatchGradualDifficulty {
fn nth(&mut self, n: usize) -> Option<Self::Item> {
let skip_iter = self.diff_objects.iter().skip(self.idx.saturating_sub(1));
let mut take = n.min(self.len().saturating_sub(1));
let mut take = cmp::min(n, self.len().saturating_sub(1));
// The first palpable object has no difficulty object
if self.idx == 0 && take > 0 {
+14 -7
View File
@@ -168,7 +168,7 @@ impl<'map> CatchPerformance<'map> {
let misses = self
.misses
.map_or(0, |n| n.min(attrs.n_fruits + attrs.n_droplets));
.map_or(0, |n| cmp::min(n, attrs.n_fruits + attrs.n_droplets));
let max_combo = self.combo.unwrap_or_else(|| attrs.max_combo() - misses);
@@ -185,13 +185,19 @@ impl<'map> CatchPerformance<'map> {
let n_remaining = (attrs.n_fruits + attrs.n_droplets)
.saturating_sub(n_fruits + n_droplets + misses);
let new_droplets = n_remaining.min(attrs.n_droplets.saturating_sub(n_droplets));
let new_droplets =
cmp::min(n_remaining, attrs.n_droplets.saturating_sub(n_droplets));
n_droplets += new_droplets;
n_fruits += n_remaining - new_droplets;
n_fruits = n_fruits
.min((attrs.n_fruits + attrs.n_droplets).saturating_sub(n_droplets + misses));
n_droplets = n_droplets.min(attrs.n_fruits + attrs.n_droplets - n_fruits - misses);
n_fruits = cmp::min(
n_fruits,
(attrs.n_fruits + attrs.n_droplets).saturating_sub(n_droplets + misses),
);
n_droplets = cmp::min(
n_droplets,
attrs.n_fruits + attrs.n_droplets - n_fruits - misses,
);
(n_fruits, n_droplets)
}
@@ -276,14 +282,15 @@ impl<'map> CatchPerformance<'map> {
}
},
(Some(n_tiny_droplets), None) => {
best_state.n_tiny_droplets = attrs.n_tiny_droplets.min(n_tiny_droplets);
best_state.n_tiny_droplets = cmp::min(attrs.n_tiny_droplets, n_tiny_droplets);
best_state.n_tiny_droplet_misses =
attrs.n_tiny_droplets.saturating_sub(n_tiny_droplets);
}
(None, Some(n_tiny_droplet_misses)) => {
best_state.n_tiny_droplets =
attrs.n_tiny_droplets.saturating_sub(n_tiny_droplet_misses);
best_state.n_tiny_droplet_misses = attrs.n_tiny_droplets.min(n_tiny_droplet_misses);
best_state.n_tiny_droplet_misses =
cmp::min(attrs.n_tiny_droplets, n_tiny_droplet_misses);
}
(None, None) => match self.acc {
Some(acc) => find_best_tiny_droplets(acc),
@@ -1,3 +1,5 @@
use std::cmp;
use rosu_map::section::hit_objects::{hit_samples::HitSoundType, BorrowedCurve};
use crate::{
@@ -188,7 +190,7 @@ impl<'h> DistanceObjectPatternGenerator<'h> {
self.inner.total_columns - random_start - self.prev_pattern.column_with_objs();
let mut next_column = self.inner.get_random_column(None, None);
for _ in 0..usable_columns.min(note_count) {
for _ in 0..cmp::min(usable_columns, note_count) {
// * Find available column
next_column =
self.find_available_column(next_column, None, &[&pattern, self.prev_pattern]);
@@ -384,7 +386,7 @@ impl<'h> DistanceObjectPatternGenerator<'h> {
// * □ ■ - -
// * ■ - - -
let column_repeat = self.span_count.min(self.inner.total_columns) as usize;
let column_repeat = cmp::min(self.span_count, self.inner.total_columns) as usize;
// * Due to integer rounding, this is not guaranteed to be the same as EndTime (the class-level variable).
let end_time = start_time + self.segment_duration * self.span_count;
@@ -457,7 +459,7 @@ impl<'h> DistanceObjectPatternGenerator<'h> {
0
};
note_count = note_count.min(self.inner.total_columns - 1);
note_count = cmp::min(note_count, self.inner.total_columns - 1);
let sample = self.sample_info_list_at(start_time);
let ignore_head =
@@ -1,3 +1,5 @@
use std::cmp;
use rosu_map::section::hit_objects::hit_samples::HitSoundType;
use crate::{
@@ -239,10 +241,12 @@ impl<'h> HitObjectPatternGenerator<'h> {
let allow_stacking = !self.convert_type.contains(PatternType::FORCE_NOT_STACK);
if !allow_stacking {
note_count = (self.inner.total_columns
- self.inner.random_start()
- self.prev_pattern.column_with_objs())
.min(note_count);
note_count = cmp::min(
self.inner.total_columns
- self.inner.random_start()
- self.prev_pattern.column_with_objs(),
note_count,
);
}
let mut next_column = self.inner.get_column(Some(true));
+3 -1
View File
@@ -1,3 +1,5 @@
use std::cmp;
use crate::{
any::difficulty::skills::Skill,
mania::{object::ObjectParams, ManiaBeatmap},
@@ -159,7 +161,7 @@ impl Iterator for ManiaGradualDifficulty {
.zip(self.objects_is_circle.iter().skip(1))
.skip(self.idx.saturating_sub(1));
let mut take = n.min(self.len().saturating_sub(1));
let mut take = cmp::min(n, self.len().saturating_sub(1));
// The first note has no difficulty object
if self.idx == 0 && take > 0 {
+6 -3
View File
@@ -1,3 +1,5 @@
use std::cmp;
use crate::{
any::difficulty::{mode::ModeDifficulty, skills::Skill},
mania::{
@@ -19,9 +21,10 @@ pub fn difficulty(
difficulty: &ModeDifficulty,
converted: &ManiaBeatmap<'_>,
) -> ManiaDifficultyAttributes {
let n_objects = difficulty
.get_passed_objects()
.min(converted.map.hit_objects.len()) as u32;
let n_objects = cmp::min(
difficulty.get_passed_objects(),
converted.map.hit_objects.len(),
) as u32;
let values = DifficultyValues::calculate(difficulty, converted);
+14 -14
View File
@@ -256,8 +256,8 @@ impl<'map> ManiaPerformance<'map> {
let (min_n3x0, max_n3x0) = match (self.n320, self.n300) {
(Some(_), Some(_)) => (n320 + n300, n320 + n300),
(Some(_), None) => (min_n3x0.max(n320), max_n3x0.max(n320)),
(None, Some(_)) => (min_n3x0.max(n300), max_n3x0.max(n300)),
(Some(_), None) => (cmp::max(min_n3x0, n320), cmp::max(max_n3x0, n320)),
(None, Some(_)) => (cmp::max(min_n3x0, n300), cmp::max(max_n3x0, n300)),
(None, None) => (min_n3x0, max_n3x0),
};
@@ -301,8 +301,8 @@ impl<'map> ManiaPerformance<'map> {
let (min_n3x0, max_n3x0) = match (self.n320, self.n300) {
(Some(_), Some(_)) => (n320 + n300, n320 + n300),
(Some(_), None) => (min_n3x0.max(n320), max_n3x0.max(n320)),
(None, Some(_)) => (min_n3x0.max(n300), max_n3x0.max(n300)),
(Some(_), None) => (cmp::max(min_n3x0, n320), cmp::max(max_n3x0, n320)),
(None, Some(_)) => (cmp::max(min_n3x0, n300), cmp::max(max_n3x0, n300)),
(None, None) => (min_n3x0, max_n3x0),
};
@@ -346,8 +346,8 @@ impl<'map> ManiaPerformance<'map> {
let (min_n3x0, max_n3x0) = match (self.n320, self.n300) {
(Some(_), Some(_)) => (n320 + n300, n320 + n300),
(Some(_), None) => (min_n3x0.max(n320), max_n3x0.max(n320)),
(None, Some(_)) => (min_n3x0.max(n300), max_n3x0.max(n300)),
(Some(_), None) => (cmp::max(min_n3x0, n320), cmp::max(max_n3x0, n320)),
(None, Some(_)) => (cmp::max(min_n3x0, n300), cmp::max(max_n3x0, n300)),
(None, None) => (min_n3x0, max_n3x0),
};
@@ -394,8 +394,8 @@ impl<'map> ManiaPerformance<'map> {
cmp::min(n_remaining, n320 + n300),
cmp::min(n_remaining, n320 + n300),
),
(Some(_), None) => (min_n3x0.max(n320), max_n3x0.max(n320)),
(None, Some(_)) => (min_n3x0.max(n300), max_n3x0.max(n300)),
(Some(_), None) => (cmp::max(min_n3x0, n320), cmp::max(max_n3x0, n320)),
(None, Some(_)) => (cmp::max(min_n3x0, n300), cmp::max(max_n3x0, n300)),
(None, None) => (min_n3x0, max_n3x0),
};
@@ -457,8 +457,8 @@ impl<'map> ManiaPerformance<'map> {
cmp::min(n_remaining, n320 + n300),
cmp::min(n_remaining, n320 + n300),
),
(Some(_), None) => (min_n3x0.max(n320), max_n3x0.max(n320)),
(None, Some(_)) => (min_n3x0.max(n300), max_n3x0.max(n300)),
(Some(_), None) => (cmp::max(min_n3x0, n320), cmp::max(max_n3x0, n320)),
(None, Some(_)) => (cmp::max(min_n3x0, n300), cmp::max(max_n3x0, n300)),
(None, None) => (min_n3x0, max_n3x0),
};
@@ -520,8 +520,8 @@ impl<'map> ManiaPerformance<'map> {
cmp::min(n_remaining, n320 + n300),
cmp::min(n_remaining, n320 + n300),
),
(Some(_), None) => (min_n3x0.max(n320), max_n3x0.max(n320)),
(None, Some(_)) => (min_n3x0.max(n300), max_n3x0.max(n300)),
(Some(_), None) => (cmp::max(min_n3x0, n320), cmp::max(max_n3x0, n320)),
(None, Some(_)) => (cmp::max(min_n3x0, n300), cmp::max(max_n3x0, n300)),
(None, None) => (min_n3x0, max_n3x0),
};
@@ -595,8 +595,8 @@ impl<'map> ManiaPerformance<'map> {
cmp::min(n_remaining, n320 + n300),
cmp::min(n_remaining, n320 + n300),
),
(Some(_), None) => (min_n3x0.max(n320), max_n3x0.max(n320)),
(None, Some(_)) => (min_n3x0.max(n300), max_n3x0.max(n300)),
(Some(_), None) => (cmp::max(min_n3x0, n320), cmp::max(max_n3x0, n320)),
(None, Some(_)) => (cmp::max(min_n3x0, n300), cmp::max(max_n3x0, n300)),
(None, None) => (min_n3x0, max_n3x0),
};
+2 -2
View File
@@ -1,4 +1,4 @@
use std::mem;
use std::{cmp, mem};
use crate::{
any::difficulty::skills::Skill,
@@ -201,7 +201,7 @@ impl Iterator for OsuGradualDifficulty {
fn nth(&mut self, n: usize) -> Option<Self::Item> {
let skip_iter = self.diff_objects.iter().skip(self.idx.saturating_sub(1));
let mut take = n.min(self.len().saturating_sub(1));
let mut take = cmp::min(n, self.len().saturating_sub(1));
// The first note has no difficulty object
if self.idx == 0 && take > 0 {
+3 -1
View File
@@ -1,3 +1,5 @@
use std::cmp;
use crate::{
any::difficulty::{
object::IDifficultyObject,
@@ -155,7 +157,7 @@ impl FlashlightEvaluator {
let mut angle_repeat_count = 0.0;
// * This is iterating backwards in time from the current object.
for i in 0..curr.idx.min(10) {
for i in 0..cmp::min(curr.idx, 10) {
let Some(curr_obj) = curr.previous(i, diff_objects) else {
break;
};
+2 -2
View File
@@ -1,4 +1,4 @@
use std::f64::consts::PI;
use std::{cmp, f64::consts::PI};
use crate::{
any::difficulty::{
@@ -217,7 +217,7 @@ impl RhythmEvaluator {
let mut first_delta_switch = false;
let historical_note_count = curr.idx.min(32);
let historical_note_count = cmp::min(curr.idx, 32);
let mut rhythm_start = 0;
+2 -2
View File
@@ -1,4 +1,4 @@
use std::borrow::Cow;
use std::{borrow::Cow, cmp};
use rosu_map::{
section::{general::GameMode, hit_objects::CurveBuffers},
@@ -54,7 +54,7 @@ fn convert(map: &mut Beatmap) {
let mut i = 0;
let mut j = obj.start_time;
let edge_sound_count = slider.node_sounds.len().max(1);
let edge_sound_count = cmp::max(slider.node_sounds.len(), 1);
while j
<= obj.start_time + f64::from(params.duration) + params.tick_spacing / 8.0
+2 -2
View File
@@ -1,4 +1,4 @@
use std::{mem, slice::Iter};
use std::{cmp, mem, slice::Iter};
use crate::{
model::{beatmap::HitWindows, hit_object::HitObject},
@@ -192,7 +192,7 @@ impl Iterator for TaikoGradualDifficulty {
}
fn nth(&mut self, n: usize) -> Option<Self::Item> {
let mut take = n.min(self.len().saturating_sub(1));
let mut take = cmp::min(n, self.len().saturating_sub(1));
// The first two notes have no difficulty object but might add to combo
match (take, self.idx) {
+6 -4
View File
@@ -1,3 +1,5 @@
use std::cmp;
use crate::{
any::difficulty::skills::Skill,
taiko::difficulty::object::{TaikoDifficultyObject, TaikoDifficultyObjects},
@@ -51,10 +53,10 @@ impl Peaks {
let rhythm_peaks = self.rhythm.get_curr_strain_peaks();
let stamina_peaks = self.stamina.get_curr_strain_peaks();
let cap = color_peaks
.len()
.min(rhythm_peaks.len())
.min(stamina_peaks.len());
let cap = cmp::min(
cmp::min(color_peaks.len(), rhythm_peaks.len()),
stamina_peaks.len(),
);
let mut peaks = Vec::with_capacity(cap);
let zip = color_peaks
+3 -1
View File
@@ -1,3 +1,5 @@
use std::cmp;
use crate::{
any::difficulty::{
object::IDifficultyObject,
@@ -36,7 +38,7 @@ impl Rhythm {
.push(RhythmHistoryElement::new(hit_object));
for most_recent_patterns_to_compare in
2..=(RHYTHM_HISTORY_MAX_LEN / 2).min(self.rhythm_history.len())
2..=cmp::min(RHYTHM_HISTORY_MAX_LEN / 2, self.rhythm_history.len())
{
for start in (0..self.rhythm_history.len() - most_recent_patterns_to_compare).rev() {
if !self.same_pattern(start, most_recent_patterns_to_compare) {
+3 -1
View File
@@ -157,6 +157,8 @@ impl<T, const N: usize> Index<usize> for LimitedQueue<T, N> {
#[cfg(test)]
mod test {
use std::cmp;
use super::LimitedQueue;
#[test]
@@ -185,7 +187,7 @@ mod test {
for i in 1..=5 {
queue.push(i as u8);
assert_eq!(i.min(4), queue.len());
assert_eq!(cmp::min(i, 4), queue.len());
}
assert_eq!(queue.last(), Some(&5));