diff options
| author | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-27 11:37:41 +0100 |
|---|---|---|
| committer | Johannes Hofmann <Johannes.Hofmann@gmx.de> | 2026-10-27 11:37:41 +0100 |
| commit | 21487476293a77518e81c91ecdc0fbd4c4b74a25 (patch) | |
| tree | a73687a9ae1b1bf82af0ff367f0e3fdf26e7db52 /crates/gipfel-web/src/markers.rs | |
| parent | 574655e57a3790c08659adc87d3a9c5a45da4f0d (diff) | |
web: W2 — hill DB, metadata-driven viewpoint, markers and auto-fit
- fetch gipfel.dat.gz at startup, gunzip (flate2, pure Rust) and load
into a Panorama held in app state
- image loads now also parse the gipfel JPEG comment / EXIF and set the
viewpoint via apply_image_metadata (same path as desktop)
- markers: click a visible-peak guide dot to mark it, drag to adjust,
right-click to remove; refit (comp_params_with, distortion locked by
default) after every change once >= 4 markers
- sidebar: fit-distortion toggle, marker/zoom readout, fitted
az/pitch/roll/scale line
- canvas: guide dots for visible peaks, red crosses + shadowed labels
- serve-here.sh: dev helper (cargo build --target wasm32 + wasm-bindgen
+ gzip the DB into the static dist dir)
Verified: cargo check clean for wasm32; runtime to be confirmed in
browser against a gipfel-saved photo (W2 acceptance: fit must match
the desktop result on the same image).
Diffstat (limited to 'crates/gipfel-web/src/markers.rs')
| -rw-r--r-- | crates/gipfel-web/src/markers.rs | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/crates/gipfel-web/src/markers.rs b/crates/gipfel-web/src/markers.rs new file mode 100644 index 0000000..279c62c --- /dev/null +++ b/crates/gipfel-web/src/markers.rs @@ -0,0 +1,48 @@ +//! Markers: user observations of hills at image positions, plus the +//! refit entry point. Coordinates are center-relative image pixels, +//! matching the projection output space (same convention as the +//! desktop viewport widget). + +use gipfel_core::hill::Hill; +use gipfel_core::panorama::Panorama; + +#[derive(Clone, Debug, PartialEq)] +pub struct Marker { + /// index into `Panorama::hills` (stable: load order is preserved) + pub hill: usize, + pub x: f64, + pub y: f64, +} + +/// Refit the projection parameters to the current markers. +/// With fewer than 4 markers nothing can be fitted (same rule as desktop). +pub fn refit(pan: &mut Panorama, markers: &[Marker], fit_distortion: bool) -> Result<(), String> { + if markers.len() < 4 { + return Ok(()); + } + let mut obs: Vec<Hill> = Vec::with_capacity(markers.len()); + for m in markers { + let mut h = pan.hills[m.hill].clone(); + h.x = m.x; + h.y = m.y; + obs.push(h); + } + let known: Vec<usize> = (0..markers.len()).collect(); + pan.comp_params_with(&obs, &known, fit_distortion) +} + +/// 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<usize> { + let mut best = None; + let mut best_d = max_dist; + for &i in &pan.visible { + let h = &pan.hills[i]; + let d = (h.x - x).hypot(h.y - y); + if d < best_d { + best_d = d; + best = Some(i); + } + } + best +} |
