From 0b85e7989eacb26d3496cdb98ed3221868a4013f Mon Sep 17 00:00:00 2001 From: Johannes Hofmann Date: Tue, 27 Oct 2026 13:41:53 +0100 Subject: web: hidden-peak heuristics in the UI with Show-hidden toggle MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The core already ran both visibility heuristics (height/distance threshold via the Visibility slider, occlusion via mark_hidden with the cone-visibility slope test) — the web UI just ignored FLAG_HIDDEN. - guide dots: hidden peaks are filtered out by default; with the new Display > Show hidden peaks toggle they appear grey instead of green - hover and click hit-testing skip hidden peaks unless the toggle is on - Find Peak picker is unchanged (it lists pan.close, which always includes hidden peaks — same as desktop) --- crates/gipfel-web/src/app.rs | 41 +++++++++++++++++++++++++++++------- crates/gipfel-web/src/canvas_view.rs | 17 +++++++++------ crates/gipfel-web/src/markers.rs | 14 ++++++++++-- 3 files changed, 55 insertions(+), 17 deletions(-) (limited to 'crates/gipfel-web/src') diff --git a/crates/gipfel-web/src/app.rs b/crates/gipfel-web/src/app.rs index e4fd435..f4b0de4 100644 --- a/crates/gipfel-web/src/app.rs +++ b/crates/gipfel-web/src/app.rs @@ -5,7 +5,7 @@ use std::io::Read; use std::rc::Rc; use flate2::read::GzDecoder; -use gipfel_core::hill::{FLAG_DUPLIC, FLAG_TRACK_POINT}; +use gipfel_core::hill::{FLAG_DUPLIC, FLAG_HIDDEN, FLAG_TRACK_POINT}; use gipfel_core::metadata::{apply_image_metadata, ImageMetaData}; use gipfel_core::panorama::Panorama; use wasm_bindgen::closure::Closure; @@ -161,6 +161,7 @@ pub fn app() -> Html { let vp = use_state(UiParams::default); let img_size = use_state(|| (0u32, 0u32)); let find_peak = use_state(|| Option::::None); + let show_hidden = use_state(|| false); // force a redraw when the window is resized so the canvas backing // store tracks its CSS size (listener lives as long as the app) @@ -441,6 +442,13 @@ pub fn app() -> Html { vp.set(u); }) }; + let on_show_hidden = { + let show_hidden = show_hidden.clone(); + Callback::from(move |e: Event| { + let input: HtmlInputElement = e.target_unchecked_into(); + show_hidden.set(input.checked()); + }) + }; // compass strip: shares the image transform, drag changes azimuth let compass_data = { @@ -555,13 +563,14 @@ pub fn app() -> Html { let mark = mark_peak.clone(); let find_peak = find_peak.clone(); let img_size = img_size.clone(); + let show_hidden = show_hidden.clone(); Callback::from(move |(ix, iy): (f64, f64)| { let scale = view.scale; // unambiguous click right on a peak: mark directly // (borrow must be released before mark -> do_refit!) let near = { let p = pan.borrow(); - markers::nearest_hill(&p, ix, iy, 10.0 / scale) + markers::nearest_hill(&p, ix, iy, 10.0 / scale, *show_hidden) }; if let Some(idx) = near { find_peak.set(None); @@ -620,12 +629,14 @@ pub fn app() -> Html { let pan = pan.clone(); let view = view.clone(); let hover = hover.clone(); + let show_hidden = show_hidden.clone(); Callback::from(move |(ix, iy): (f64, f64)| { let p = pan.borrow(); - let name = markers::nearest_hill(&p, ix, iy, 20.0 / view.scale).map(|i| { - let h = &p.hills[i]; - format!("{} · {:.0} m", h.name, h.height) - }); + let name = markers::nearest_hill(&p, ix, iy, 20.0 / view.scale, *show_hidden) + .map(|i| { + let h = &p.hills[i]; + format!("{} · {:.0} m", h.name, h.height) + }); hover.set(name); }) }, @@ -647,9 +658,19 @@ pub fn app() -> Html { }) .collect() }; - let candidates: Vec<(f64, f64)> = { + let candidates: Vec<(f64, f64, bool)> = { let p = pan.borrow(); - p.visible.iter().map(|&i| (p.hills[i].x, p.hills[i].y)).collect() + p.visible + .iter() + .filter(|&&i| *show_hidden || p.hills[i].flags & FLAG_HIDDEN == 0) + .map(|&i| { + ( + p.hills[i].x, + p.hills[i].y, + p.hills[i].flags & FLAG_HIDDEN != 0, + ) + }) + .collect() }; let zoom_pct = (view.scale * 100.0).round(); @@ -695,6 +716,10 @@ pub fn app() -> Html { { "Fit distortion (needs ≥ 4 markers)" }
{ "Display" }
+ , - /// projected positions of all visible hills (small guide dots) - pub candidates: Vec<(f64, f64)>, + /// projected positions of all visible hills (guide dots) with their + /// hidden-by-occlusion flag + pub candidates: Vec<(f64, f64, bool)>, /// marker label font size, screen px pub label_font: f32, } @@ -131,10 +132,11 @@ pub fn canvas_view(props: &Props) -> Html { let sy = |y: f64| (y + hh) * view.scale + view.oy; // guide dots for all visible peaks: dark outline ring + - // bright core so they stay visible on any photo content + // bright core so they stay visible on any photo content; + // peaks hidden by nearer terrain are drawn grey #[allow(deprecated)] ctx.set_fill_style(&wasm_bindgen::JsValue::from_str("rgba(0, 0, 0, 0.85)")); - for (cx, cy) in candidates { + for (cx, cy, _hidden) in candidates { let (px, py) = (sx(*cx), sy(*cy)); if px < -6.0 || py < -6.0 || px > cw + 6.0 || py > ch + 6.0 { continue; @@ -143,13 +145,14 @@ pub fn canvas_view(props: &Props) -> Html { let _ = ctx.arc(px, py, 4.5, 0.0, std::f64::consts::TAU); ctx.fill(); } - #[allow(deprecated)] - ctx.set_fill_style(&wasm_bindgen::JsValue::from_str("rgb(110, 231, 183)")); - for (cx, cy) in candidates { + for (cx, cy, hidden) in candidates { let (px, py) = (sx(*cx), sy(*cy)); if px < -6.0 || py < -6.0 || px > cw + 6.0 || py > ch + 6.0 { continue; } + let color = if *hidden { "rgb(150, 150, 150)" } else { "rgb(110, 231, 183)" }; + #[allow(deprecated)] + ctx.set_fill_style(&wasm_bindgen::JsValue::from_str(color)); ctx.begin_path(); let _ = ctx.arc(px, py, 2.5, 0.0, std::f64::consts::TAU); ctx.fill(); diff --git a/crates/gipfel-web/src/markers.rs b/crates/gipfel-web/src/markers.rs index d1bf8cb..d024f2e 100644 --- a/crates/gipfel-web/src/markers.rs +++ b/crates/gipfel-web/src/markers.rs @@ -34,11 +34,21 @@ pub fn refit(pan: &mut Panorama, markers: &[Marker], fit_distortion: bool) -> Re } /// Nearest visible hill to image position `(x, y)`, within `max_dist` -/// image pixels. Used to resolve marker clicks. -pub fn nearest_hill(pan: &Panorama, x: f64, y: f64, max_dist: f64) -> Option { +/// image pixels. Used to resolve marker clicks. Hills hidden by the +/// occlusion heuristic are skipped unless `show_hidden`. +pub fn nearest_hill( + pan: &Panorama, + x: f64, + y: f64, + max_dist: f64, + show_hidden: bool, +) -> Option { let mut best = None; let mut best_d = max_dist; for &i in &pan.visible { + if !show_hidden && pan.hills[i].flags & gipfel_core::hill::FLAG_HIDDEN != 0 { + continue; + } let h = &pan.hills[i]; let d = (h.x - x).hypot(h.y - y); if d < best_d { -- cgit v1.2.3