mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-24 10:09:01 -06:00
Merge PR #2409: Drop non-finite elevation values in the GPX parser
This commit is contained in:
+13
-1
@@ -147,7 +147,7 @@ pub fn parse_gpx(s: &str) -> Result<Tracklog, GpxError> {
|
||||
match name.as_slice() {
|
||||
b"ele" if parent == Some(b"trkpt") => {
|
||||
if let Some(p) = pt.as_mut() {
|
||||
p.ele = text.trim().parse().ok();
|
||||
p.ele = text.trim().parse().ok().filter(|v: &f64| v.is_finite());
|
||||
}
|
||||
}
|
||||
b"time" if parent == Some(b"trkpt") => {
|
||||
@@ -351,6 +351,18 @@ mod tests {
|
||||
assert_eq!(log.points[1].time - log.points[0].time, 60.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn non_finite_elevation_is_dropped() {
|
||||
for ele in ["inf", "-inf", "NaN", "infinity"] {
|
||||
let s = format!(
|
||||
r#"<gpx><trk><trkseg><trkpt lat="45" lon="7"><ele>{ele}</ele><time>2026-01-01T00:00:00Z</time></trkpt></trkseg></trk></gpx>"#
|
||||
);
|
||||
let log = parse_gpx(&s).unwrap();
|
||||
assert_eq!(log.points.len(), 1, "{ele}");
|
||||
assert_eq!(log.points[0].elevation, None, "{ele}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn interpolation_across_the_antimeridian() {
|
||||
let a = TrackPoint { time: 0.0, latitude: 0.0, longitude: 179.0, elevation: None, segment: 0 };
|
||||
|
||||
Reference in New Issue
Block a user