osu & fruits: fixed catmull sliders

This commit is contained in:
MaxOhn
2021-01-28 11:06:30 +01:00
parent a50225889a
commit 704c4768e2
3 changed files with 31 additions and 25 deletions
+27 -21
View File
@@ -79,33 +79,39 @@ impl Curve {
}
let order = points.len();
let step = 2.5 / SLIDER_QUALITY;
let target = step + 1.0;
let mut resulting_points = Vec::with_capacity(4);
let mut resulting_points =
Vec::with_capacity(((order - 1) as f32 * SLIDER_QUALITY * 2.0) as usize);
for x in 0..order - 1 {
let mut t = 0.0;
for i in 0..order - 1 {
let v1 = points[i.saturating_sub(1)];
let v2 = points[i];
while t < target {
let v1 = if x >= 1 { points[x - 1] } else { points[x] };
let v2 = points[x];
let v3 = if i < order - 1 {
points[i + 1]
} else {
v2 * 2.0 - v1
};
let v3 = if x + 1 < order {
points[x + 1]
} else {
v2.add_scaled(v2.add_scaled(v1, -1.0), 1.0)
};
let v4 = if i < order - 2 {
points[i + 2]
} else {
v3 * 2.0 - v2
};
let v4 = if x + 2 < order {
points[x + 2]
} else {
v3.add_scaled(v3.add_scaled(v2, -1.0), 1.0)
};
let mut c = 0.0;
let point = Self::catmull_point(v1, v2, v3, v4, t);
resulting_points.push(point);
t += step;
while c < SLIDER_QUALITY {
resulting_points.push(Self::catmull_point(v1, v2, v3, v4, c / SLIDER_QUALITY));
resulting_points.push(Self::catmull_point(
v1,
v2,
v3,
v4,
(c + 1.0) / SLIDER_QUALITY,
));
c += 1.0;
}
}
+3 -3
View File
@@ -23,10 +23,10 @@ pub(crate) fn cpn(mut p: i32, n: i32) -> f32 {
#[inline]
pub(crate) fn catmull(p0: f32, p1: f32, p2: f32, p3: f32, t: f32) -> f32 {
0.5 * ((2.0 * p1)
0.5 * (2.0 * p1
+ (-p0 + p2) * t
+ (2.0 * p0 - 5.0 * p1 + 4.0 * p2 - p3) * t.powi(2)
+ (-p0 + 3.0 * p1 - 3.0 * p2 + p3 * t.powi(3)))
+ (2.0 * p0 - 5.0 * p1 + 4.0 * p2 - p3) * t * t
+ (-p0 + 3.0 * p1 - 3.0 * p2 + p3) * t * t * t)
}
#[inline]
+1 -1
View File
@@ -449,7 +449,7 @@ mod tests {
#[test]
// #[ignore]
fn all_included_single() {
let file = match File::open("./maps/2514909.osu") {
let file = match File::open("./maps/100.osu") {
Ok(file) => file,
Err(why) => panic!("Could not open file: {}", why),
};