From 752031dc280e53ef70e423880415e5188badce0c Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 30 Nov 2026 11:19:47 -0300 Subject: [PATCH 1/4] feat(ui): a Generalise field in a Shaded Relief's style pane, and the user guide (#3145, part 4) The style pane of a Shaded Relief gets a Generalise field, in metres from 0 to 10 km, which sends raster.symbology's "generalize": the light, fill light, rock, cast shadows and sky are worked out from the heights smoothed with a Gaussian of that size. The user guide says what it does, how to choose a size, and what a GeoTIFF read in place and a file out of range do. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/panes.rs | 65 +++++++++++++++++++++++++++++++++++-- docs/user-guide/data.md | 13 ++++++++ 2 files changed, 75 insertions(+), 3 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index 70c0418312..2dbe258d72 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -9,7 +9,7 @@ use rustgis_engine::analysis::{ParamKind, tools}; use rustgis_engine::cmd::layer::hidden_fill_opacity; use rustgis_engine::data::GeometryType; use rustgis_engine::map::fills::FillLayer; -use rustgis_engine::map::raster::{Flats, Normalizer, RasterLegend, RasterStyle, Rock, relief_ambient}; +use rustgis_engine::map::raster::{Flats, GENERALIZE_MAX, Normalizer, RasterLegend, RasterStyle, Rock, relief_ambient}; use rustgis_engine::map::symbology::{ ClassRef, ClassStyle, Dash, LegendEntry, LineCap, LineJoin, LineMark, LineMarkers, LineStroke, MAX_EXPRESSION_CLASSES, MAX_LABEL, MAX_LINE_MARKER_SIZE, MAX_MARKER_INTERVAL, MAX_STROKE_OFFSET, MAX_STROKE_WIDTH, MAX_STROKES, MIN_MARKER_INTERVAL, OPEN_ABOVE, @@ -7734,8 +7734,7 @@ fn raster_symbology(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tokens) { aerial, terrain_type, flats, - // Its pane field comes with #3145's last part. - generalize: _, + generalize, } => { use rustgis_engine::map::shadow::{SOFT_EDGE_MAX, SOFT_EDGE_MIN, soft_edge}; let (az, alt, zf, sh, sk, fl) = (*azimuth, *altitude, *z_factor, *shadow, *sky, *fill); @@ -7769,6 +7768,7 @@ fn raster_symbology(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tokens) { ("Aerial perspective", ae, 0.0..=1.0, 0.01, 8), ("Terrain type", tt, -1.0..=1.0, 0.01, 9), ("Flat-area detail", flats.map_or(0.0, |f| f.amount), 0.0..=1.0, 0.01, 10), + ("Generalise", *generalize, 0.0..=GENERALIZE_MAX, 1.0, 12), ]; // Its neighbourhood, once it is on. if let Some(f) = flats { @@ -7804,6 +7804,9 @@ fn raster_symbology(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tokens) { "Levees, terraces and shallow channels on ground flatter than 4°, lit by their height above the ground around them, from 0 (none) to 1" )), 11 => r.on_hover_text(tl!("How many cells around each cell its height is compared with, from 1 to 32")), + 12 => r.on_hover_text(tl!( + "Lights the relief from its heights smoothed over this many metres, so gullies fade and valleys and ranges stay; the colours keep each cell's height. 0 (none) to 10 000" + )), _ => r, }; if drag.settled(ui, &r, &mut x) && x != v { @@ -7824,6 +7827,7 @@ fn raster_symbology(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tokens) { 9 => p["terrain"] = json!(x), 10 => p["flats"] = if x > 0.0 { json!({"amount": x}) } else { json!(false) }, 11 => p["flats"] = json!({"size": x.round()}), + 12 => p["generalize"] = json!(x), _ => {} } let _ = app.run("raster.symbology", p); @@ -10751,6 +10755,61 @@ pub(crate) mod tests { assert_eq!(h.state().dialogs.text, "Rivers"); } + /// A Shaded Relief's style pane sets its generalisation (#3145), in metres: a size smooths the + /// heights its light reads, 0 turns it off again, and the field goes no further than the + /// command takes. + #[test] + fn the_relief_pane_sets_its_generalisation() { + use egui::accesskit::{Action, ActionData, ActionRequest, Role}; + use egui_kittest::kittest::{NodeT, Queryable}; + use rustgis_engine::data::raster::{ColorHint, Crs, GeoTransform, Raster}; + let mut app = RustGisApp::with_sample(); + let gt = GeoTransform { origin_x: 0.0, origin_y: 1.0, pixel_width: 0.5, pixel_height: -0.5 }; + let r = Raster::new("dem", 2, 2, vec![vec![0.0, 1.0, 2.0, 3.0]], gt, Crs::LonLat, None, ColorHint::Gray, "Float32").unwrap(); + let id = app.session.map_mut().add_raster("dem", rustgis_engine::map::RasterLayer::from_path(r, "dem.tif")); + app.session.active_layer = Some(id); + app.run("raster.symbology", json!({"layer": id, "type": "shadedRelief"})).unwrap(); + let mut fonts = false; + let mut h = egui_kittest::Harness::builder().with_size(vec2(420.0, 900.0)).build_ui_state( + move |ui, app: &mut RustGisApp| { + if !fonts { + crate::theme::install_fonts(ui.ctx(), &[], None); + fonts = true; + return; + } + let layer = app.session.map().layer(id).unwrap().clone(); + raster_symbology(app, ui, &layer, &Tokens::light()); + }, + app, + ); + h.run_steps(3); + let generalize = |h: &egui_kittest::Harness<'_, RustGisApp>| match h.state().session.map().layer(id).and_then(|l| l.raster.as_ref()) + { + Some(rl) => match rl.style.renderer { + RasterRenderer::ShadedRelief { generalize, .. } => generalize, + ref other => panic!("{other:?}"), + }, + None => panic!("no raster"), + }; + let set = |h: &mut egui_kittest::Harness<'_, RustGisApp>, value: f64| { + let (node, tree) = h.get_by_role_and_label(Role::SpinButton, "Generalise").accesskit_node().locate(); + h.event(egui::Event::AccessKitActionRequest(ActionRequest { + action: Action::SetValue, + target_tree: tree, + target_node: node, + data: Some(ActionData::NumericValue(value)), + })); + h.run_steps(3); + }; + assert_eq!(generalize(&h), 0.0); + set(&mut h, 120.0); + assert_eq!(generalize(&h), 120.0); + set(&mut h, 25_000.0); + assert_eq!(generalize(&h), rustgis_engine::map::raster::GENERALIZE_MAX, "no further than the command takes"); + set(&mut h, 0.0); + assert_eq!(generalize(&h), 0.0); + } + /// A Shaded Relief's style pane sets its flat-area detail (#3143): an amount turns it on, with /// the default size, and shows its size, which is set in whole cells; 0 turns it off again. #[test] diff --git a/docs/user-guide/data.md b/docs/user-guide/data.md index 627106eb86..b9043e15fa 100644 --- a/docs/user-guide/data.md +++ b/docs/user-guide/data.md @@ -1881,6 +1881,19 @@ fields, roads and embankments are heights too and show up as relief. In a script and 6), and `false`, `null` or an amount of 0 removes it; an amount outside 0 to 1 or a size that isn't a whole number from 1 to 32 is refused. It is saved with the project only when set. +**Generalise**, on a Shaded Relief layer (`raster.symbology` `"generalize"`, in metres, 0 to +10 000), generalises the relief for a smaller scale without a filtered copy of the DEM: the light, +the fill light, rock, cast shadows and the sky are worked out from the heights smoothed with a +Gaussian of that size, so gullies fade and the valleys and ranges stay. The colour ramp keeps each +cell's own height, so hypsometric tints don't move. About two to four cells' worth suits a map at +1:100,000 of a 30 m DEM (60 to 120 m); 0, the default, lights every landform as before. The size is +on the ground, so it means the same at any cell size and zoom. A GeoTIFF read in place reads past +the view as far as the smoothing reaches; when that is more than can be read at the resolution the +view needs (a fine DEM at a large size), the view's edges are smoothed from fewer cells and that is +said, and an export refuses it: a smaller size or view draws it whole. A value outside 0 to 10 000 +in a file written by hand is set to the nearest and said as it opens. In a script, +`"generalize": 90` sets it, and `null` or 0 removes it. + With **Resampling** set to bilinear, a Shaded Relief layer's light (its hillshade, cast shadows, sky visibility and fill light) and its rock tint are blended between the cells' centres, as its values are, so a cell drawn over many pixels shades smoothly instead of in squares; nearest keeps From 954e691f2375361456b557fe8afeeabc6692258d Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 30 Nov 2026 12:10:06 -0300 Subject: [PATCH 2/4] fix(ui): a Shaded Relief's Generalise row comes after flat ground's detail and its size (#3145, part 4) From review: with flat ground's detail on, its size row was pushed after the list, so Generalise sat between the detail and its size. Generalise is now pushed after the size. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/panes.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index 2dbe258d72..61970c7e82 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -7768,12 +7768,12 @@ fn raster_symbology(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tokens) { ("Aerial perspective", ae, 0.0..=1.0, 0.01, 8), ("Terrain type", tt, -1.0..=1.0, 0.01, 9), ("Flat-area detail", flats.map_or(0.0, |f| f.amount), 0.0..=1.0, 0.01, 10), - ("Generalise", *generalize, 0.0..=GENERALIZE_MAX, 1.0, 12), ]; - // Its neighbourhood, once it is on. + // Its neighbourhood, once it is on, right below it. if let Some(f) = flats { rows.push(("Flat-area size", f64::from(f.size), 1.0..=f64::from(Flats::MAX_SIZE), 1.0, 11)); } + rows.push(("Generalise", *generalize, 0.0..=GENERALIZE_MAX, 1.0, 12)); for (label, v, range, speed, which) in rows { let input_label = ui.label(tl!(label)); let mut x = v; @@ -10757,7 +10757,8 @@ pub(crate) mod tests { /// A Shaded Relief's style pane sets its generalisation (#3145), in metres: a size smooths the /// heights its light reads, 0 turns it off again, and the field goes no further than the - /// command takes. + /// command takes. It comes after flat ground's detail and its size, which stay together + /// (#3456 review). #[test] fn the_relief_pane_sets_its_generalisation() { use egui::accesskit::{Action, ActionData, ActionRequest, Role}; @@ -10791,8 +10792,8 @@ pub(crate) mod tests { }, None => panic!("no raster"), }; - let set = |h: &mut egui_kittest::Harness<'_, RustGisApp>, value: f64| { - let (node, tree) = h.get_by_role_and_label(Role::SpinButton, "Generalise").accesskit_node().locate(); + let set_field = |h: &mut egui_kittest::Harness<'_, RustGisApp>, label: &str, value: f64| { + let (node, tree) = h.get_by_role_and_label(Role::SpinButton, label).accesskit_node().locate(); h.event(egui::Event::AccessKitActionRequest(ActionRequest { action: Action::SetValue, target_tree: tree, @@ -10801,6 +10802,7 @@ pub(crate) mod tests { })); h.run_steps(3); }; + let set = |h: &mut egui_kittest::Harness<'_, RustGisApp>, value: f64| set_field(h, "Generalise", value); assert_eq!(generalize(&h), 0.0); set(&mut h, 120.0); assert_eq!(generalize(&h), 120.0); @@ -10808,6 +10810,11 @@ pub(crate) mod tests { assert_eq!(generalize(&h), rustgis_engine::map::raster::GENERALIZE_MAX, "no further than the command takes"); set(&mut h, 0.0); assert_eq!(generalize(&h), 0.0); + // Flat ground's detail turned on shows its size right below it, then Generalise. + set_field(&mut h, "Flat-area detail", 0.5); + let top = |h: &egui_kittest::Harness<'_, RustGisApp>, label: &str| h.get_by_role_and_label(Role::SpinButton, label).rect().min.y; + let (detail, size, generalise) = (top(&h, "Flat-area detail"), top(&h, "Flat-area size"), top(&h, "Generalise")); + assert!(detail < size && size < generalise, "{detail} {size} {generalise}"); } /// A Shaded Relief's style pane sets its flat-area detail (#3143): an amount turns it on, with From 65cccdcbe73efa68a932a1ecc68c6d1148a62525 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 30 Nov 2026 12:14:51 -0300 Subject: [PATCH 3/4] docs(ui): the Generalise pane test's doc drops its review reference (#3145, part 4) Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/panes.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index 61970c7e82..adf059b9a7 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -10757,8 +10757,7 @@ pub(crate) mod tests { /// A Shaded Relief's style pane sets its generalisation (#3145), in metres: a size smooths the /// heights its light reads, 0 turns it off again, and the field goes no further than the - /// command takes. It comes after flat ground's detail and its size, which stay together - /// (#3456 review). + /// command takes. It comes after flat ground's detail and its size, which stay together. #[test] fn the_relief_pane_sets_its_generalisation() { use egui::accesskit::{Action, ActionData, ActionRequest, Role}; From 01df629aa5bdfd71ed5f1dee0e4f494767c61bb4 Mon Sep 17 00:00:00 2001 From: elpidioassinaturas Date: Mon, 30 Nov 2026 12:30:55 -0300 Subject: [PATCH 4/4] fix(ui): an arrow key's step past a relief field's end sends the end (#3145, part 4) From review: egui's DragValue clamps to its range before it adds an arrow key's step (and rounds to it), so Generalise at 0.2 less a metre asked for -1, which raster.symbology refuses, and the field stayed at 0.2. The relief fields' value is now kept in its range before it is sent, which covers the other fields of the same loop too. Co-Authored-By: Claude Opus 5.5 --- crates/ui-egui/src/panes.rs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/crates/ui-egui/src/panes.rs b/crates/ui-egui/src/panes.rs index adf059b9a7..f4597a52e8 100644 --- a/crates/ui-egui/src/panes.rs +++ b/crates/ui-egui/src/panes.rs @@ -7780,7 +7780,7 @@ fn raster_symbology(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tokens) { // Kept across a drag until it is let go (#607). let drag = Dragged::lend(ui, egui::Id::unique(("relief_drag", l.id, which)), &mut x); let r = ui - .add(egui::DragValue::new(&mut x).update_while_editing(false).range(range).speed(speed).max_decimals(3)) + .add(egui::DragValue::new(&mut x).update_while_editing(false).range(range.clone()).speed(speed).max_decimals(3)) .labelled_by(input_label.id); let r = match which { 3 => r.on_hover_text(tl!("How dark the shadows the terrain casts are, from 0 (none) to 1, for the sun set above")), @@ -7809,7 +7809,11 @@ fn raster_symbology(app: &mut RustGisApp, ui: &mut Ui, l: &Layer, t: &Tokens) { )), _ => r, }; - if drag.settled(ui, &r, &mut x) && x != v { + let settled = drag.settled(ui, &r, &mut x); + // egui adds an arrow key's step after it clamps to the range: kept in it here, + // so a step past an end sends the end, not a value the command refuses. + let x = x.clamp(*range.start(), *range.end()); + if settled && x != v { let (a, b, c, d) = match which { 0 => (x, alt, zf, sh), 1 => (az, x, zf, sh), @@ -10809,6 +10813,23 @@ pub(crate) mod tests { assert_eq!(generalize(&h), rustgis_engine::map::raster::GENERALIZE_MAX, "no further than the command takes"); set(&mut h, 0.0); assert_eq!(generalize(&h), 0.0); + // A step of the arrow keys stays in the range: egui clamps before it adds the step (and + // rounds to it), so 0.2 less a metre would ask for -1, which the command refuses. + let step = |h: &mut egui_kittest::Harness<'_, RustGisApp>, action: Action| { + let (node, tree) = h.get_by_role_and_label(Role::SpinButton, "Generalise").accesskit_node().locate(); + h.event(egui::Event::AccessKitActionRequest(ActionRequest { action, target_tree: tree, target_node: node, data: None })); + h.run_steps(3); + }; + for (from, action, to) in [ + (0.2, Action::Decrement, 0.0), + (rustgis_engine::map::raster::GENERALIZE_MAX - 0.4, Action::Increment, rustgis_engine::map::raster::GENERALIZE_MAX), + ] { + set(&mut h, from); + assert_eq!(generalize(&h), from); + step(&mut h, action); + assert_eq!(generalize(&h), to, "{action:?} from {from}"); + } + set(&mut h, 0.0); // Flat ground's detail turned on shows its size right below it, then Generalise. set_field(&mut h, "Flat-area detail", 0.5); let top = |h: &egui_kittest::Harness<'_, RustGisApp>, label: &str| h.get_by_role_and_label(Role::SpinButton, label).rect().min.y;