Removed branching

This commit is contained in:
MaxOhn
2021-01-08 12:26:59 +01:00
parent 0d72f28fc7
commit 238e33c660
9 changed files with 21 additions and 42 deletions
+2 -5
View File
@@ -71,6 +71,7 @@ pub(crate) fn point_at_distance(array: &[Pos2], distance: f32) -> Pos2 {
let mut current_distance = 0.0;
let mut new_distance = 0.0;
// TODO: Optimize
while i < array.len() - 2 {
new_distance = (array[i] - array[i + 1]).length();
current_distance += new_distance;
@@ -90,11 +91,7 @@ pub(crate) fn point_at_distance(array: &[Pos2], distance: f32) -> Pos2 {
let angle = angle_from_points(array[i], array[i + 1]);
let cart = cart_from_pol(distance - current_distance, angle);
if array[i].x > array[i + 1].x {
array[i] - cart
} else {
array[i] + cart
}
array[i] + cart * ((array[i].x <= array[i + 1].x) as i8 * 2 - 1) as f32
}
}
-17
View File
@@ -129,21 +129,4 @@ mod tests {
);
}
}
#[test]
fn wack_map() {
let file = match File::open("E:/Games/osu!/beatmaps/1443309.osu") {
Ok(file) => file,
Err(why) => panic!("Could not open file: {}", why),
};
let map = match Beatmap::parse(file) {
Ok(map) => map,
Err(why) => panic!("Error while parsing map: {}", why),
};
let stars = stars(&map, 0);
println!("Stars: {}", stars);
}
}
+1
View File
@@ -43,6 +43,7 @@ impl Strain {
#[inline]
pub(crate) fn save_current_peak(&mut self) {
// TODO: Remove branching
if self.prev_time.is_some() {
self.strain_peaks.push(self.current_section_peak);
}
+1
View File
@@ -112,6 +112,7 @@ mod tests {
let margin = 0.005;
#[rustfmt::skip]
// TODO: More mods
let data = vec![
(1851299, 1 << 8, 4.23514130038547), // HT
(1851299, 0, 5.356786475158158), // NM
+1 -5
View File
@@ -90,11 +90,7 @@ pub(crate) fn point_at_distance(array: &[Pos2], distance: f32) -> Pos2 {
let angle = angle_from_points(array[i], array[i + 1]);
let cart = cart_from_pol(distance - current_distance, angle);
if array[i].x > array[i + 1].x {
array[i] - cart
} else {
array[i] + cart
}
array[i] + cart * ((array[i].x <= array[i + 1].x) as i8 * 2 - 1) as f32
}
}
+5 -4
View File
@@ -1,3 +1,5 @@
#![allow(unused)]
use super::curve::Curve;
use parse::{Beatmap, BeatmapAttributes, HitObject, HitObjectKind, PathType, Pos2};
@@ -315,10 +317,9 @@ impl SliderTick {
}
}
use std::fmt;
impl fmt::Debug for SliderTick {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// TODO: Remove
impl std::fmt::Debug for SliderTick {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
write!(f, "{{pos={:?} | time={}}}", self.pos, self.time)
}
}
+8 -11
View File
@@ -58,18 +58,15 @@ impl<T: PartialOrd> LimitedQueue<T> {
pub(crate) fn min(&self) -> Option<&T> {
let mut iter = self.queue.iter();
if let Some(first) = iter.next() {
let min = iter.fold(first, |min, next| match min.partial_cmp(next) {
Some(Ordering::Less) => min,
Some(Ordering::Equal) => min,
Some(Ordering::Greater) => next,
None => min,
});
let first = iter.next()?;
let min = iter.fold(first, |min, next| match min.partial_cmp(next) {
Some(Ordering::Less) => min,
Some(Ordering::Equal) => min,
Some(Ordering::Greater) => next,
None => min,
});
Some(min)
} else {
None
}
Some(min)
}
}
+2
View File
@@ -69,6 +69,7 @@ impl Skill {
#[inline]
fn skill_multiplier(&self) -> f32 {
// TODO: Use constants
match self.kind {
SkillKind::Color { .. } => 1.0,
SkillKind::Rhythm { .. } => 10.0,
@@ -78,6 +79,7 @@ impl Skill {
#[inline]
fn strain_decay_base(&self) -> f32 {
// TODO: Use constants
match self.kind {
SkillKind::Color { .. } => 0.4,
SkillKind::Rhythm { .. } => 0.0,
+1
View File
@@ -12,6 +12,7 @@ pub(crate) trait StaminaCheeseDetector {
}
impl StaminaCheeseDetector for Beatmap {
// TODO: Optimize
fn find_cheese(&self) -> Vec<bool> {
let mut cheese = vec![false; self.hit_objects.len()];