diff options
| author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-11-18 21:53:16 +0100 |
|---|---|---|
| committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-11-18 21:53:16 +0100 |
| commit | 236b1c56546378327ec014c68cebde37a7d2c725 (patch) | |
| tree | 8bcbd46d3f437491cae4c35ce35e095299e83077 /crates | |
| parent | 73ad3eccad74754c1e74ff3025f4d4581f6178cb (diff) | |
core: a metadata-less image must not poison the viewpoint with NaN
apply_image_metadata guarded direction/pitch/roll/focal against NaN
but set view lat/lon/height unconditionally. Loading a PNG or any
image without GPS after a geotagged one set view_phi/lam to NaN,
which makes every hill azimuth NaN - the entire database vanished
and the lat/lon fields showed NaN, with no recovery until manual
re-entry.
NaN now falls back to the neutral 0 (same defaults as Panorama::new),
matching the existing guards for the other fields. Regression test
loads an all-NaN metadata set over a previously-set viewpoint and
asserts every resulting view parameter stays finite.
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/gipfel-core/src/metadata.rs | 30 |
1 files changed, 27 insertions, 3 deletions
diff --git a/crates/gipfel-core/src/metadata.rs b/crates/gipfel-core/src/metadata.rs index d9c98f9..084e28e 100644 --- a/crates/gipfel-core/src/metadata.rs +++ b/crates/gipfel-core/src/metadata.rs @@ -540,9 +540,12 @@ pub fn apply_image_metadata( let mut have_info = true; - pan.set_view_long(md.longitude); - pan.set_view_lat(md.latitude); - pan.set_view_height(md.height); + // NaN guards: an image without GPS must not poison the viewpoint + // (a NaN view_phi/lam makes every hill azimuth NaN and hides the + // whole database). Neutral 0 matches Panorama::new defaults. + pan.set_view_long(if md.longitude.is_nan() { 0.0 } else { md.longitude }); + pan.set_view_lat(if md.latitude.is_nan() { 0.0 } else { md.latitude }); + pan.set_view_height(if md.height.is_nan() { 0.0 } else { md.height }); pan.set_projection(match md.projection_type { 1 => ProjectionType::Cylindrical, @@ -767,6 +770,27 @@ mod tests { apply_image_metadata(&mut pan, &md, 1000, 800); assert!((pan.get_scale() - 50.0 * 1000.0 / 35.0).abs() < 1e-9); } + + #[test] + fn metadataless_image_does_not_poison_viewpoint() { + // an image with no EXIF/comment at all (every field NaN) must + // leave a finite, neutral viewpoint - even after a previous + // image had set one (NaN view lat/lon would NaN every hill + // azimuth and hide the whole database) + let mut pan = crate::panorama::Panorama::new(); + pan.set_view_lat(47.0); + pan.set_view_long(10.5); + pan.set_view_height(2993.0); + let md = ImageMetaData::new(); // all NaN + let have = apply_image_metadata(&mut pan, &md, 1000, 800); + assert!(!have); + assert!(pan.get_view_lat().is_finite()); + assert!(pan.get_view_long().is_finite()); + assert!(pan.get_view_height().is_finite()); + assert!(pan.get_pitch_angle().is_finite()); + assert!(pan.get_roll_angle().is_finite()); + assert!(pan.get_scale().is_finite()); + } } #[cfg(test)] |
