remove invalid curve points error variant
This commit is contained in:
@@ -11,8 +11,6 @@ pub enum ParseError {
|
|||||||
IoError(IoError),
|
IoError(IoError),
|
||||||
/// The initial data of an `.osu` file was incorrect.
|
/// The initial data of an `.osu` file was incorrect.
|
||||||
IncorrectFileHeader,
|
IncorrectFileHeader,
|
||||||
/// Line in `.osu` that contains a slider was not in the proper format.
|
|
||||||
InvalidCurvePoints,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for ParseError {
|
impl fmt::Display for ParseError {
|
||||||
@@ -22,7 +20,6 @@ impl fmt::Display for ParseError {
|
|||||||
Self::IncorrectFileHeader => {
|
Self::IncorrectFileHeader => {
|
||||||
write!(f, "expected `osu file format v` at file begin")
|
write!(f, "expected `osu file format v` at file begin")
|
||||||
}
|
}
|
||||||
Self::InvalidCurvePoints => f.write_str("invalid curve point"),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -32,7 +29,6 @@ impl StdError for ParseError {
|
|||||||
match self {
|
match self {
|
||||||
Self::IoError(inner) => Some(inner),
|
Self::IoError(inner) => Some(inner),
|
||||||
Self::IncorrectFileHeader => None,
|
Self::IncorrectFileHeader => None,
|
||||||
Self::InvalidCurvePoints => None,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-13
@@ -534,7 +534,7 @@ macro_rules! parse_hitobjects_body {
|
|||||||
&mut vertices,
|
&mut vertices,
|
||||||
);
|
);
|
||||||
|
|
||||||
if convert_res.is_err() {
|
if convert_res == ConvertStatus::Err {
|
||||||
continue 'next_line;
|
continue 'next_line;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -552,7 +552,7 @@ macro_rules! parse_hitobjects_body {
|
|||||||
&mut vertices,
|
&mut vertices,
|
||||||
);
|
);
|
||||||
|
|
||||||
if convert_res.is_err() {
|
if convert_res == ConvertStatus::Err {
|
||||||
continue 'next_line;
|
continue 'next_line;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -747,10 +747,14 @@ impl Beatmap {
|
|||||||
}
|
}
|
||||||
|
|
||||||
mod slider_parsing {
|
mod slider_parsing {
|
||||||
use crate::ParseError;
|
|
||||||
|
|
||||||
use super::{InRange, Pos2, MAX_COORDINATE_VALUE};
|
use super::{InRange, Pos2, MAX_COORDINATE_VALUE};
|
||||||
|
|
||||||
|
#[derive(PartialEq, Eq)]
|
||||||
|
pub(super) enum ConvertStatus {
|
||||||
|
Ok,
|
||||||
|
Err,
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) fn convert_points(
|
pub(super) fn convert_points(
|
||||||
points: &[&str],
|
points: &[&str],
|
||||||
end_point: Option<&str>,
|
end_point: Option<&str>,
|
||||||
@@ -758,7 +762,7 @@ mod slider_parsing {
|
|||||||
offset: Pos2,
|
offset: Pos2,
|
||||||
curve_points: &mut Vec<PathControlPoint>,
|
curve_points: &mut Vec<PathControlPoint>,
|
||||||
vertices: &mut Vec<PathControlPoint>,
|
vertices: &mut Vec<PathControlPoint>,
|
||||||
) -> Result<(), ParseError> {
|
) -> ConvertStatus {
|
||||||
let mut path_kind = PathType::from_str(points[0]);
|
let mut path_kind = PathType::from_str(points[0]);
|
||||||
|
|
||||||
let read_offset = first as usize;
|
let read_offset = first as usize;
|
||||||
@@ -773,12 +777,18 @@ mod slider_parsing {
|
|||||||
|
|
||||||
// * Parse into control points.
|
// * Parse into control points.
|
||||||
for &point in points.iter().skip(1) {
|
for &point in points.iter().skip(1) {
|
||||||
vertices.push(read_point(point, offset)?);
|
match read_point(point, offset) {
|
||||||
|
Some(point) => vertices.push(point),
|
||||||
|
None => return ConvertStatus::Err,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// * If an endpoint is given, add it to the end.
|
// * If an endpoint is given, add it to the end.
|
||||||
if let Some(end_point) = end_point {
|
if let Some(end_point) = end_point {
|
||||||
vertices.push(read_point(end_point, offset)?);
|
match read_point(end_point, offset) {
|
||||||
|
Some(point) => vertices.push(point),
|
||||||
|
None => return ConvertStatus::Err,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// * Edge-case rules (to match stable).
|
// * Edge-case rules (to match stable).
|
||||||
@@ -846,19 +856,18 @@ mod slider_parsing {
|
|||||||
curve_points.extend(&vertices[start_idx..end_idx]);
|
curve_points.extend(&vertices[start_idx..end_idx]);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
ConvertStatus::Ok
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(super) fn read_point(value: &str, start_pos: Pos2) -> Result<PathControlPoint, ParseError> {
|
pub(super) fn read_point(value: &str, start_pos: Pos2) -> Option<PathControlPoint> {
|
||||||
let mut v = value
|
let mut v = value
|
||||||
.split(':')
|
.split(':')
|
||||||
.flat_map(|s| f64::parse_in_custom_range(s, MAX_COORDINATE_VALUE as f64))
|
.flat_map(|s| f64::parse_in_custom_range(s, MAX_COORDINATE_VALUE as f64))
|
||||||
.map(|n| n as i32 as f32);
|
.map(|n| n as i32 as f32);
|
||||||
|
|
||||||
match (v.next(), v.next()) {
|
v.next()
|
||||||
(Some(x), Some(y)) => Ok(PathControlPoint::from(Pos2 { x, y } - start_pos)),
|
.zip(v.next())
|
||||||
_ => Err(ParseError::InvalidCurvePoints),
|
.map(|(x, y)| PathControlPoint::from(Pos2 { x, y } - start_pos))
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn is_linear(p0: Pos2, p1: Pos2, p2: Pos2) -> bool {
|
fn is_linear(p0: Pos2, p1: Pos2, p2: Pos2) -> bool {
|
||||||
|
|||||||
Reference in New Issue
Block a user