taiko: micro optimizations
This commit is contained in:
+8
-18
@@ -1,3 +1,9 @@
|
||||
#[cfg(any(
|
||||
feature = "fruits",
|
||||
all(feature = "osu", not(feature = "no_sliders_no_leniency"))
|
||||
))]
|
||||
use crate::math_util;
|
||||
|
||||
mod attributes;
|
||||
mod control_point;
|
||||
mod error;
|
||||
@@ -458,7 +464,7 @@ macro_rules! parse_hitobjects_body {
|
||||
match path_type {
|
||||
PathType::Linear if curve_points.len() % 2 == 0 => {
|
||||
// Assert that the points are of the form A|B|B|C|C|E
|
||||
if valid_linear(&curve_points) {
|
||||
if math_util::valid_linear(&curve_points) {
|
||||
for i in (2..curve_points.len() - 1).rev().step_by(2) {
|
||||
curve_points.remove(i);
|
||||
}
|
||||
@@ -467,7 +473,7 @@ macro_rules! parse_hitobjects_body {
|
||||
}
|
||||
}
|
||||
PathType::PerfectCurve if curve_points.len() == 3 => {
|
||||
if is_linear(curve_points[0], curve_points[1], curve_points[2]) {
|
||||
if math_util::is_linear(curve_points[0], curve_points[1], curve_points[2]) {
|
||||
path_type = PathType::Linear;
|
||||
}
|
||||
},
|
||||
@@ -775,22 +781,6 @@ fn split_colon(line: &str) -> Option<(&str, &str)> {
|
||||
Some((split.next()?, split.next()?.trim()))
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn valid_linear(points: &[Pos2]) -> bool {
|
||||
for i in (1..points.len() - 1).step_by(2) {
|
||||
if points[i] != points[i + 1] {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn is_linear(p0: Pos2, p1: Pos2, p2: Pos2) -> bool {
|
||||
((p1.y - p0.y) * (p2.x - p0.x) - (p1.x - p0.x) * (p2.y - p0.y)).abs() <= f32::EPSILON
|
||||
}
|
||||
|
||||
/// The type of curve of a slider.
|
||||
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
|
||||
pub enum PathType {
|
||||
|
||||
Reference in New Issue
Block a user