fix linear perfect curves and subpaths
This commit is contained in:
+34
-8
@@ -455,15 +455,25 @@ macro_rules! parse_hitobjects_body {
|
||||
}
|
||||
}
|
||||
|
||||
if $self.version <= 6 && curve_points.len() >= 2 {
|
||||
if path_type == PathType::Linear {
|
||||
path_type = PathType::Bezier;
|
||||
} else if curve_points.len() == 2
|
||||
&& (pos == curve_points[0] || pos == curve_points[1])
|
||||
{
|
||||
path_type = PathType::Linear;
|
||||
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) {
|
||||
for i in (2..curve_points.len() - 1).rev().step_by(2) {
|
||||
curve_points.remove(i);
|
||||
}
|
||||
} else {
|
||||
path_type = PathType::Bezier;
|
||||
}
|
||||
}
|
||||
}
|
||||
PathType::PerfectCurve if curve_points.len() == 3 => {
|
||||
if is_linear(curve_points[0], curve_points[1], curve_points[2]) {
|
||||
path_type = PathType::Linear;
|
||||
}
|
||||
},
|
||||
PathType::Catmull => {},
|
||||
_ => path_type = PathType::Bezier,
|
||||
};
|
||||
|
||||
// Reduce amount of curvepoints but keep the elements evenly spaced.
|
||||
// Necessary to handle maps like XNOR (2573164) which have
|
||||
@@ -765,6 +775,22 @@ 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 {
|
||||
|
||||
+2
-7
@@ -16,12 +16,12 @@ impl Pos2 {
|
||||
|
||||
#[inline]
|
||||
pub fn length(&self) -> f32 {
|
||||
self.length_squared().sqrt()
|
||||
self.x.hypot(self.y)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn dot(&self, other: Self) -> f32 {
|
||||
self.x * other.x + self.y * other.y
|
||||
self.x.mul_add(other.x, self.y * other.y)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -29,11 +29,6 @@ impl Pos2 {
|
||||
(*self - *other).length()
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn add_scaled(self, other: Pos2, factor: f32) -> Pos2 {
|
||||
self + other * factor
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn normalize(self) -> Pos2 {
|
||||
self / self.length()
|
||||
|
||||
Reference in New Issue
Block a user