summaryrefslogtreecommitdiff
path: root/crates
diff options
context:
space:
mode:
Diffstat (limited to 'crates')
-rw-r--r--crates/gipfel-cli/src/main.rs15
-rw-r--r--crates/gipfel-core/src/panorama.rs49
2 files changed, 58 insertions, 6 deletions
diff --git a/crates/gipfel-cli/src/main.rs b/crates/gipfel-cli/src/main.rs
index f0690a8..06b1447 100644
--- a/crates/gipfel-cli/src/main.rs
+++ b/crates/gipfel-cli/src/main.rs
@@ -12,7 +12,7 @@ fn usage() {
\n\
commands:\n\
\x20 export-position <img> print position CSV line\n\
- \x20 export-hills <img> [-d <data>] [-e <hills>] export hill positions\n\
+ \x20 export-hills <img> [-d <data>] [-e <hills>] [-V <r>] export hill positions\n\
\x20 info <img> show parsed metadata\n\
\x20 stitch [-t out.tif [-4]] [-j out.jpg] [-w N]\n\
\x20 [-h N] [-r from,to] [-b] img... cylindrical panorama\n\
@@ -45,7 +45,7 @@ fn fmt_f(v: f64) -> String {
}
}
-fn export_hills(img: &str, data: &str, export_file: Option<&str>) -> i32 {
+fn export_hills(img: &str, data: &str, export_file: Option<&str>, vis: f64) -> i32 {
let Some((w, h)) = image_dimensions(img) else {
eprintln!("could not read image {}", img);
return 1;
@@ -61,7 +61,7 @@ fn export_hills(img: &str, data: &str, export_file: Option<&str>) -> i32 {
eprintln!("Could not load datafile {}: {}", data, e);
return 1;
}
- pan.set_height_dist_ratio(0.07); // C default "visibility"
+ pan.set_height_dist_ratio(vis); // "visibility" threshold, C default 0.07
if !have_info {
eprintln!("No gipfel info available for {}.", img);
@@ -328,9 +328,16 @@ fn main() {
let img = &args[2];
let mut data = "gipfel.dat".to_string();
let mut export_file: Option<String> = None;
+ let mut vis = 0.07;
let mut i = 3;
while i < args.len() {
match args[i].as_str() {
+ "-V" => {
+ if i + 1 < args.len() {
+ vis = args[i + 1].trim().parse().unwrap_or(0.07);
+ i += 1;
+ }
+ }
"-d" => {
if i + 1 < args.len() {
data = args[i + 1].clone();
@@ -347,7 +354,7 @@ fn main() {
}
i += 1;
}
- export_hills(img, &data, export_file.as_deref())
+ export_hills(img, &data, export_file.as_deref(), vis)
}
}
"info" => {
diff --git a/crates/gipfel-core/src/panorama.rs b/crates/gipfel-core/src/panorama.rs
index 9216037..b8ce342 100644
--- a/crates/gipfel-core/src/panorama.rs
+++ b/crates/gipfel-core/src/panorama.rs
@@ -404,7 +404,17 @@ impl Panorama {
}
pub fn is_visible(&self, alph: f64) -> bool {
- let mut center_dist = (alph - self.parms.a_center).abs();
+ // NaN or infinite azimuths (from user input or a diverged fit) must
+ // never count as visible; a NaN center used to make everything so.
+ if !alph.is_finite() || !self.parms.a_center.is_finite() {
+ return false;
+ }
+ // Wrap into [0, 2pi) before the fold: a_center may lie outside
+ // [-pi, pi] (user enters "400 deg", or a fit leaves it unnormalized).
+ // Without this, |alph - a_center| > 2pi turned the single fold below
+ // into a NEGATIVE distance, which passed every comparison and made
+ // hills behind the camera visible (GipfelFind.lean Finding 1).
+ let mut center_dist = (alph - self.parms.a_center).abs() % (2.0 * PI);
if center_dist > PI {
center_dist = 2.0 * PI - center_dist;
}
@@ -458,8 +468,13 @@ impl Panorama {
let mut rows = Vec::new();
for &i in &self.visible {
let m = &self.hills[i];
+ // restricted mode (-e, a curated list such as the photo
+ // index): export every listed entry inside the field of
+ // view. The prominence/occlusion heuristics are meant to
+ // thin out the full 21k peak database, not to second-guess
+ // an explicit list.
if m.flags & crate::hill::FLAG_DUPLIC != 0
- || m.flags & crate::hill::FLAG_HIDDEN != 0
+ || (!require_export && m.flags & crate::hill::FLAG_HIDDEN != 0)
|| (require_export && m.flags & crate::hill::FLAG_EXPORT == 0)
{
continue;
@@ -509,4 +524,34 @@ mod tests {
pan.max_view_angle = 80f64.to_radians();
assert!(!pan.is_visible(a70));
}
+
+ #[test]
+ fn out_of_range_center_angle_stays_safe() {
+ // GipfelFind.lean Finding 1: with |alph - a_center| > 2pi the single
+ // fold produced a negative "distance" that passed every comparison.
+ // Hill azimuths come from atan2, so alph is always in [-pi, pi].
+ let mut raw = Panorama::new();
+ raw.parms.a_center = 400f64.to_radians(); // e.g. left by a fit
+ assert!(!raw.is_visible(-std::f64::consts::PI)); // 220 deg off, behind
+
+ // the setter must agree with the equivalent in-range azimuth
+ let mut pan400 = Panorama::new();
+ pan400.set_center_angle(400.0); // "bearing + full turn" input slip
+ let mut pan40 = Panorama::new();
+ pan40.set_center_angle(40.0);
+ for d in -180..=180 {
+ let a = (d as f64).to_radians();
+ assert_eq!(pan400.is_visible(a), pan40.is_visible(a), "az {d}");
+ }
+
+ // NaN / infinite azimuths are not visible (Finding 1b)
+ assert!(!pan40.is_visible(f64::NAN));
+ assert!(!pan40.is_visible(f64::INFINITY));
+ assert!(!pan40.is_visible(f64::NEG_INFINITY));
+
+ // a NaN camera azimuth hides everything (was: everything visible)
+ let mut bad = Panorama::new();
+ bad.parms.a_center = f64::NAN;
+ assert!(!bad.is_visible(0.0));
+ }
}