From eebd1bacc90c24c69262fdebf47518db0680459d Mon Sep 17 00:00:00 2001 From: giswqs Date: Mon, 30 Nov 2026 00:10:54 -0500 Subject: [PATCH 1/7] fix(render): release sweep follow-ups (render-layout) Deferred review points from the render and layout PRs: a profile's title shortened between its section names and said as cut, a stretched curved label offered places at its own spacing, a tilted band's wide strokes from past its tiles meshed, a non-finite pitch culled as flat, the drawn index bounded by the source's count, CJK font scan counting an unreadable folder once and trying sans faces first on Android. Layout commands: the publication legend box held to 60% of its frame in every path, pole-centred frames said on open and on map.projection, layer.orderClasses counting skipped values. file://localhost read as a local path in QGIS imports, the layout pan preview filled with the page colour, and doc and comment fixes. --- crates/data/src/source/shp.rs | 12 +- crates/engine/src/cmd/design/sketch.rs | 5 +- crates/engine/src/cmd/layer.rs | 10 +- crates/engine/src/cmd/layout/files.rs | 10 +- crates/engine/src/cmd/layout/profile.rs | 8 +- .../engine/src/cmd/layout/publication/mod.rs | 20 +-- .../src/cmd/layout/publication/placement.rs | 4 + crates/engine/src/cmd/layout/update.rs | 7 +- crates/engine/src/cmd/navigate.rs | 20 +++ crates/engine/src/cmd/raster.rs | 9 +- crates/engine/src/cmd/view.rs | 7 +- crates/engine/src/project.rs | 10 ++ crates/engine/src/tests.rs | 82 +++++++++++- crates/map/src/camera.rs | 2 +- crates/map/src/qgis/source.rs | 24 +++- crates/map/src/qgis/tests.rs | 2 + crates/map/src/shadow.rs | 4 +- crates/render/src/block.rs | 13 +- crates/render/src/fonts.rs | 40 +++++- crates/render/src/frame_cache.rs | 2 +- crates/render/src/layout/colorbar.rs | 27 ++-- crates/render/src/layout/losses.rs | 26 +++- crates/render/src/layout/profile.rs | 36 +++++- crates/render/src/layout/profile_tests.rs | 57 +++++++++ crates/render/src/layout/tests.rs | 6 +- crates/render/src/lib.rs | 119 +++++++++++++++++- crates/render/src/mesh.rs | 32 ++++- crates/render/src/testing.rs | 2 +- crates/ui-egui/src/layoutview.rs | 3 +- 29 files changed, 517 insertions(+), 82 deletions(-) diff --git a/crates/data/src/source/shp.rs b/crates/data/src/source/shp.rs index d063459f0b..cb85ee90f5 100644 --- a/crates/data/src/source/shp.rs +++ b/crates/data/src/source/shp.rs @@ -291,8 +291,8 @@ impl ShpSource { Narrowing { own, everywhere, by_area: req.extent.is_some() || (own.is_some() && !everywhere) } } - /// A complete visit of a request's records, or of those numbered `numbered` (from 0, in - /// order), parsed and given a chunk at a time ([`FeatureSource::visit_request_chunks`], + /// A complete visit of a request's records, or of those numbered `numbered` (from 0, in any + /// order, each once; visited in file order), parsed and given a chunk at a time ([`FeatureSource::visit_request_chunks`], /// [`FeatureSource::visit_ids_chunks`]). Only a whole read looks at the stored boxes. fn visit_with( &self, @@ -334,8 +334,7 @@ impl ShpSource { // The same directory, ordering, extent rules and read-only scan fallback as sampled // reads, with no interaction row cap. The index visits records without materializing // their directory or the complete feature collection in memory. - // Every record id fits u32. This format bound visits them all while keeping SQLite's - // LIMIT within its signed integer range on 64-bit hosts. + // Every record number fits u32 (a Shapefile's index holds fewer). crate::progress::begin(self.info.count.and_then(|n| usize::try_from(n).ok()).unwrap_or(0)); let mut each = |i: u32, place: Place| -> Result<()> { crate::progress::step(1)?; @@ -381,9 +380,8 @@ impl ShpSource { return Ok(()); } }; - // As in `read`, the shape itself is checked. - // As a read by area, its box in the file's own system included, gives no rows - // without a shape. + // As in `read`, the shape itself is checked: a read by area, its box in the file's own + // system included, gives no rows without a shape. if geometry.as_ref().map_or(by_area, |g| !g.inside) { boxed_off += u64::from(no_number == Some(true)); return Ok(()); diff --git a/crates/engine/src/cmd/design/sketch.rs b/crates/engine/src/cmd/design/sketch.rs index 0cf8281ca4..d15275030f 100644 --- a/crates/engine/src/cmd/design/sketch.rs +++ b/crates/engine/src/cmd/design/sketch.rs @@ -297,9 +297,12 @@ fn nearest_edge(s: &mut Session, from: Coord, to: Coord, px: f64, only: Option CmdResult { _ => Vec::new(), }; if !missing.is_empty() { - s.notify( - format!("No class with the value(s) {}; skipped", missing.iter().map(|v| format!("'{v}'")).collect::>().join(", ")), - false, - ); + // Counted, the first five named: a long list of values says how many, not all of them. + let mut named = missing.iter().take(5).map(|v| format!("'{v}'")).collect::>().join(", "); + if missing.len() > 5 { + named.push_str(&format!(" and {} more", missing.len() - 5)); + } + s.notify(format!("{} value(s) with no class skipped: {named}", missing.len()), false); } Ok(json!({"classes": listed, "skipped": missing})) } diff --git a/crates/engine/src/cmd/layout/files.rs b/crates/engine/src/cmd/layout/files.rs index e59841accf..3da9f284e5 100644 --- a/crates/engine/src/cmd/layout/files.rs +++ b/crates/engine/src/cmd/layout/files.rs @@ -49,7 +49,7 @@ pub(crate) fn import(s: &mut Session, text: &str) -> CmdResult { } // A frame centred where its map can't place the point (a pole on Web Mercator) is said (#2684). // One notice for them all, counted. - let unplaced: Vec<(String, Option)> = l.elements.iter().filter_map(|e| unplaced_center(s, &l, e.id)).collect(); + let unplaced: Vec<(String, Option)> = l.elements.iter().filter_map(|e| unplaced_center(&s.project.maps, &l, e.id)).collect(); if let Some(said) = unplaced_notice(&l.name, &unplaced) { s.notify(said, false); } @@ -65,11 +65,11 @@ pub(crate) fn import(s: &mut Session, text: &str) -> CmdResult { /// on Web Mercator, whose poles are at infinity): its name and the latitude it's drawn centred /// at instead, as [`rustgis_map::layout::frame_camera`] draws it (85° for a Mercator pole; /// `None` when that can't be read back) (#2684). `None` when it's drawn where it's centred, or -/// `id` isn't a frame of a map here. -pub(in crate::cmd::layout) fn unplaced_center(s: &Session, l: &Layout, id: u32) -> Option<(String, Option)> { +/// `id` isn't a frame of one of `maps`. +pub(crate) fn unplaced_center(maps: &[rustgis_map::Map], l: &Layout, id: u32) -> Option<(String, Option)> { let e = l.element(id)?; let ElementKind::MapFrame { map, center, scale, .. } = &e.kind else { return None }; - let m = s.project.maps.iter().find(|m| m.name.eq_ignore_ascii_case(map))?; + let m = maps.iter().find(|m| m.name.eq_ignore_ascii_case(map))?; if rustgis_map::layout::frame_center_placed(m, *center) { return None; } @@ -81,7 +81,7 @@ pub(in crate::cmd::layout) fn unplaced_center(s: &Session, l: &Layout, id: u32) /// One notice for the map frames of layout `layout` centred where their maps' projections can't /// show them, with where each is drawn instead ([`unplaced_center`]): counted, the first five /// named. `None` for none (#2684). -pub(in crate::cmd::layout) fn unplaced_notice(layout: &str, frames: &[(String, Option)]) -> Option { +pub(crate) fn unplaced_notice(layout: &str, frames: &[(String, Option)]) -> Option { if frames.is_empty() { return None; } diff --git a/crates/engine/src/cmd/layout/profile.rs b/crates/engine/src/cmd/layout/profile.rs index ce492a8740..52c9649a6a 100644 --- a/crates/engine/src/cmd/layout/profile.rs +++ b/crates/engine/src/cmd/layout/profile.rs @@ -32,10 +32,6 @@ const ADD_PROFILE_KEYS: &[&str] = &["layout", "kind", "frame", "background"]; /// gap and thickness ([`Profile::take_rect`]). const UPDATE_PROFILE_KEYS: &[&str] = &["layout", "element", "name", "visible", "locked", "background", "x", "y", "w", "h"]; -/// A profile's keys that null gives back their default: no fill, the samples' own ends, the dark -/// grey ink. -const PROFILE_NULL_KEYS: &[&str] = &["fill", "min", "max", "color", "background"]; - /// Whether element `id` of layout `li` is a profile. pub(in crate::cmd::layout) fn is_profile(s: &Session, li: usize, id: u32) -> bool { s.project.layouts.get(li).and_then(|l| l.element(id)).is_some_and(|e| e.kind.is_profile()) @@ -245,7 +241,9 @@ pub(in crate::cmd::layout) fn update_profile(s: &mut Session, p: &Value, li: usi let ElementKind::Profile(current) = &e.kind else { return Err(format!("element {id} isn't a profile")) }; let changes = p.as_object().is_some_and(|o| { o.iter().any(|(k, v)| { - (!v.is_null() || PROFILE_NULL_KEYS.contains(&k.as_str())) && !matches!(k.as_str(), "layout" | "element" | "locked") + // Null gives a key its default where the kind says so (no fill, the samples' own + // ends, the dark grey ink), and a background none. + (!v.is_null() || e.kind.null_resets(k) || k == "background") && !matches!(k.as_str(), "layout" | "element" | "locked") }) }); if changes && b(p, "locked") != Some(false) { diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index 14e03045f8..f48f3e0b5b 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -1344,19 +1344,19 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu let card = style == Style::Modular && column.is_some(); let (card_r, card_pad) = (3.0 * k, 2.5 * k); let bar_gap = if ch > 0.0 { 2.0 } else { 0.0 }; - // Over the map the box is never placed taller than 60% of the frame, so the title's lines - // count only up to that, less the rows of the legend beside them (a colorbar's own height, as - // before, at the least): the map isn't moved, veiled or scaled for room the box can't have, and - // each candidate's rows keep their height (the fit test and the placement below). The lines past - // it are said as cut off. + // Over the map the box is held to `LEGEND_MAX_FRAME` (60%) of the frame's height, except where + // a colorbar's floor (`COLORBAR_MM`, 15 mm) needs more beside tall rows: the title's lines + // count only up to that, less the rows of the legend beside them: the map isn't moved, veiled + // or scaled for room the box can't have, and each candidate's rows keep their height (the fit + // test and the placement below). What is past it, the floor's excess too, is said as cut off. let over_map = column.is_none(); - let cap = |rows_h: f64| (fh * 0.6 - 2.0 * pad - rows_h - bar_gap).max(COLORBAR_MM); + let cap = |rows_h: f64| (fh * LEGEND_MAX_FRAME - 2.0 * pad - rows_h - bar_gap).max(COLORBAR_MM); let bar_reserve = |rows_h: f64| if over_map { bar_measured.min(cap(rows_h)) } else { bar_measured }; let bar_part = if bar.is_some() { bar_reserve(ch) + bar_gap } else { 0.0 }; let (content_w, content_h) = (if bar.is_some() { cw.max(bar_w) } else { cw }, ch + bar_part); let legend_in_column = column.is_some(); if content_h > 0.0 && !legend_in_column { - surrounds.push((Surround::Legend, (content_w + 2.0 * pad).min(fw * 0.45), (content_h + 2.0 * pad).min(fh * 0.6))); + surrounds.push((Surround::Legend, (content_w + 2.0 * pad).min(fw * 0.45), (content_h + 2.0 * pad).min(fh * LEGEND_MAX_FRAME))); } // Its width is set once the frame's centre and scale are settled, below; nothing reads it before. // A globe seen whole has none: its scale holds at its centre only, falling to nothing at its @@ -1678,7 +1678,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu (cw, ch) = chosen[0]; let (w, h) = whole(chosen[0]); if let Some(entry) = surrounds.iter_mut().find(|x| x.0 == Surround::Legend) { - (entry.1, entry.2) = (w.min(fw * 0.45), h.min(fh * 0.6)); + (entry.1, entry.2) = (w.min(fw * 0.45), h.min(fh * LEGEND_MAX_FRAME)); } } } @@ -1817,7 +1817,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu // One column too, when the rectangle holds what the box a legend starts with cuts. if let Some(i) = fits.filter(|i| *i > 0 || whole(sizes[0]).0 > at_most_one.0 + 1e-6 || whole(sizes[0]).1 > at_most_one.1 + 1e-6) { let (w, h) = whole(sizes[i]); - let more = arranged((w.min(wide), h)); + let more = arranged((w.min(wide), h.min(fh * LEGEND_MAX_FRAME))); let new = (shown(&more.1, (w, h)), more.1.3.1); if more.1.0.is_some() && new.0 >= score.0 - 1e-6 { (legend_cols, best, score) = (i + 1, more, new); @@ -1828,7 +1828,7 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu break; } let (w, h) = whole(*size); - let more = arranged((w.min(wide), h.min(fh * 0.6))); + let more = arranged((w.min(wide), h.min(fh * LEGEND_MAX_FRAME))); let new = (shown(&more.1, (w, h)), more.1.3.1); if more.1.0.is_some() && more_columns_win(new, score) { (legend_cols, best, score) = (i + 1, more, new); diff --git a/crates/engine/src/cmd/layout/publication/placement.rs b/crates/engine/src/cmd/layout/publication/placement.rs index 4b8c4c90d2..61fd1afa40 100644 --- a/crates/engine/src/cmd/layout/publication/placement.rs +++ b/crates/engine/src/cmd/layout/publication/placement.rs @@ -144,6 +144,10 @@ pub(crate) fn veil_panel( /// its labels. pub(in crate::cmd::layout) const COLORBAR_MM: f64 = 15.0; +/// The most of its map frame's height a legend box over the map takes, as a share; a colorbar's +/// floor ([`COLORBAR_MM`]) beside tall rows may need more, and what is past it is said as cut off. +pub(in crate::cmd::layout) const LEGEND_MAX_FRAME: f64 = 0.6; + /// The height a publication gives its colorbar in a legend's box `ih` mm high inside, in mm, /// when its title needs `need` (#2493). Over the map it leaves the rows the room they were sized /// to (`rows`, with the gap above the colorbar), so a title past the box's cap is cut short diff --git a/crates/engine/src/cmd/layout/update.rs b/crates/engine/src/cmd/layout/update.rs index bbdd617ed5..08bd26467d 100644 --- a/crates/engine/src/cmd/layout/update.rs +++ b/crates/engine/src/cmd/layout/update.rs @@ -887,8 +887,11 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult { } // A centre the frame's map can't place (a pole on Web Mercator) is said (#2684). if new_center.is_some() || given(&["map"]) { - let said = - s.project.layouts.get(li).and_then(|l| unplaced_notice(&l.name, &unplaced_center(s, l, id).into_iter().collect::>())); + let said = s + .project + .layouts + .get(li) + .and_then(|l| unplaced_notice(&l.name, &unplaced_center(&s.project.maps, l, id).into_iter().collect::>())); if let Some(said) = said { s.notify(said, false); } diff --git a/crates/engine/src/cmd/navigate.rs b/crates/engine/src/cmd/navigate.rs index aa441aa2c0..a7d96d49ab 100644 --- a/crates/engine/src/cmd/navigate.rs +++ b/crates/engine/src/cmd/navigate.rs @@ -106,6 +106,26 @@ pub fn commands() -> Vec { }; m.set_projection(next); let out = json!({"projection": m.projection.code(), "label": m.projection.label()}); + // Frames on this map now centred where its projection can't show the centre (a pole + // on Web Mercator) are drawn centred elsewhere: one counted notice a layout (#2684). + let name = s.map().name.clone(); + let said: Vec = s + .project + .layouts + .iter() + .filter_map(|l| { + let unplaced: Vec<(String, Option)> = l + .elements + .iter() + .filter(|e| matches!(&e.kind, ElementKind::MapFrame { map, .. } if map.eq_ignore_ascii_case(&name))) + .filter_map(|e| super::layout::unplaced_center(&s.project.maps, l, e.id)) + .collect(); + super::layout::unplaced_notice(&l.name, &unplaced) + }) + .collect(); + for n in said { + s.notify(n, false); + } if s.auto_cache { super::workspace::fill_cache(s); } diff --git a/crates/engine/src/cmd/raster.rs b/crates/engine/src/cmd/raster.rs index 1809ce207e..01e342b0ff 100644 --- a/crates/engine/src/cmd/raster.rs +++ b/crates/engine/src/cmd/raster.rs @@ -651,13 +651,8 @@ pub fn download_page(url: &str, p: &Value, bytes: &[u8]) -> Option<(String, Opti } /// Draws a downloaded PDF's page, or reads a downloaded GRIB file, off the frame -/// ([`download_page`]), for [`crate::Session::download_landed_page`]. -#[cfg(not(target_arch = "wasm32"))] -pub fn read_download_page(name: &str, bytes: &[u8], page: Option<&str>, place: bool) -> Result { - raster::read_bytes_page(name, bytes, page, place).map_err(|e| format!("{name}: {e}")) -} - -/// Reads a download whose retry/landing state already shares its bytes, without copying a PDF. +/// ([`download_page`]), for [`crate::Session::download_landed_page`]: from bytes its retry or +/// landing state already shares, without copying a PDF. #[cfg(not(target_arch = "wasm32"))] pub fn read_download_shared_page(name: &str, bytes: std::sync::Arc>, page: Option<&str>, place: bool) -> Result { raster::read_shared_page(name, bytes, page, place).map_err(|e| format!("{name}: {e}")) diff --git a/crates/engine/src/cmd/view.rs b/crates/engine/src/cmd/view.rs index cc4aff9c8f..3f3dabc076 100644 --- a/crates/engine/src/cmd/view.rs +++ b/crates/engine/src/cmd/view.rs @@ -524,9 +524,10 @@ fn block_polygons(s: &Session, o: &serde_json::Map) -> Result Option { let (spacing, coarsened) = o.spacing(); - // Rings narrower than the spacing, with no area left once thinned (#2318). - let narrow = - (o.narrow() > 0).then(|| format!("{} ring(s) of '{layer}' narrower than {spacing:.0} m were left out of the block", o.narrow())); + // Rings narrower than the spacing, with no area left once thinned (#2318), and the holes of + // those outer rings, which go with them (counted among them). + let narrow = (o.narrow() > 0) + .then(|| format!("{} ring(s) of '{layer}' narrower than {spacing:.0} m, with their holes, were left out of the block", o.narrow())); let stray = (o.stray() > 0) .then(|| format!("{} hole(s) of '{layer}' lying outside their own polygon's outer ring were left out (not cut)", o.stray())); let merged = match o.dropped() { diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 4672136783..6cad8aa3ce 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1604,6 +1604,16 @@ impl Project { } let mut notices: Vec<(ReadPart, NoticeText)> = layout_notices(&self.name, when, layouts_dropped, &repairs).into_iter().map(|n| (ReadPart::Layouts, n.into())).collect(); + // A frame centred where its map's projection can't show the centre (a pole on Web + // Mercator) is drawn centred elsewhere: said once a layout, as `layout.import` says it + // (#2684). + for l in &self.layouts { + let unplaced: Vec<(String, Option)> = + l.elements.iter().filter_map(|e| crate::cmd::layout::unplaced_center(&self.maps, l, e.id)).collect(); + if let Some(said) = crate::cmd::layout::unplaced_notice(&l.name, &unplaced) { + notices.push((ReadPart::Layouts, said.into())); + } + } let mut done = Repaired::default(); // Files skip the commands' limits, and notebooks and presentations are found (and // notebooks trusted) by name, so names are made unique. diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 13d763f9ca..736b7ec4b3 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -12781,7 +12781,7 @@ fn layer_order_classes_keeps_the_order_given() { let r = s.run("layer.orderClasses", &json!({"layer": "Countries", "values": ["Oceania", "Atlantis", "Asia"]})).unwrap(); assert_eq!(r["skipped"], json!(["Atlantis"])); assert_eq!(r["classes"].as_array().unwrap()[..3], [json!("Oceania"), json!("Asia"), json!("Africa")]); - assert!(s.notices.iter().any(|n| n.text.contains("'Atlantis'"))); + assert!(s.notices.iter().any(|n| n.text == "1 value(s) with no class skipped: 'Atlantis'"), "{:?}", s.notices); let ordered = legend(&s); assert_eq!(ordered[..3], ["Oceania", "Asia", "Africa"]); assert_eq!(ordered.last().map(String::as_str), Some("")); @@ -12845,6 +12845,13 @@ fn layer_order_classes_that_names_no_class_is_refused() { // A value named twice is skipped once. s.run("layer.orderClasses", &json!({"layer": "Countries", "values": ["Asia", "Atlantis", "Atlantis"]})).unwrap(); assert_eq!(s.notices.last().map(|n| n.text.matches("Atlantis").count()), Some(1)); + // Past five, the rest are counted, not named. + let values: Vec = std::iter::once("Asia".to_string()).chain((1..=8).map(|i| format!("Nowhere {i}"))).collect(); + s.run("layer.orderClasses", &json!({"layer": "Countries", "values": values})).unwrap(); + assert_eq!( + s.notices.last().map(|n| n.text.as_str()), + Some("8 value(s) with no class skipped: 'Nowhere 1', 'Nowhere 2', 'Nowhere 3', 'Nowhere 4', 'Nowhere 5' and 3 more") + ); } /// A class order kept in a project or a saved style requires `unique-keep-order`, so an older @@ -17697,6 +17704,39 @@ fn a_publications_colorbar_title_stays_in_the_legends_box() { let _ = std::fs::remove_dir_all(&dir); } +/// Over the map a publication's legend box is held to 60% of its frame's height, whichever way its +/// columns are chosen, a raster's 200-character name as its colorbar's title too: the title's +/// lines past that are cut (and said), the map frame left where a short name leaves it (#2638). +#[test] +fn a_publications_legend_box_over_the_map_keeps_to_60_percent_of_the_frame() { + let dir = std::env::temp_dir().join(format!("rustgis-legend-cap-{}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + let tif = dir.join("rain.tif"); + std::fs::write(&tif, rustgis_data::raster::cog::example(256, 128)).unwrap(); + let parcels = dir.join("parcels.geojson"); + std::fs::write( + &parcels, + r#"{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Polygon","coordinates":[[[10.2,45.2],[10.8,45.2],[10.8,45.8],[10.2,45.2]]]}}]}"#, + ) + .unwrap(); + let publish = |name: &str| { + let mut s = Session::new(Project::default()); + s.run("layer.addData", &json!({"path": tif.display().to_string(), "name": name})).unwrap(); + s.run("layer.addData", &json!({"path": parcels.display().to_string()})).unwrap(); + let p = json!({"extent": [10, 45, 11, 46], "profile": "figure-1col", "author": "", "locator": "none"}); + let r = s.run("layout.publication", &p).unwrap(); + let l = s.project.layouts.last().unwrap(); + let named = |n: &str| l.elements.iter().find(|e| e.name == n).cloned().unwrap_or_else(|| panic!("no {n}: {r}")); + (named("Legend Box"), named("Map Frame"), r) + }; + let long: String = "Precipitação média mensal ".repeat(8).chars().take(200).collect(); + let (then, frame, r) = publish(&long); + assert!(then.h <= frame.h * 0.6 + 1e-6, "a box {} mm tall over a frame {} mm tall: {r}", then.h, frame.h); + let (_, short_frame, _) = publish("rain"); + assert_eq!((frame.x, frame.y, frame.w, frame.h), (short_frame.x, short_frame.y, short_frame.w, short_frame.h), "{r}"); + let _ = std::fs::remove_dir_all(&dir); +} + /// A publication's colorbar takes what its title needs, leaving the legend's rows the room they /// were sized to over the map, but never less than a colorbar's own height while the box has it: /// rows that fill the box are cut and said, not the bar (#2638). @@ -17777,6 +17817,46 @@ fn a_layout_frame_centred_on_a_pole_is_kept_and_said_where_it_cant_be_shown() { ); } +/// A frame centred on a pole is said where it can't be shown when a project holding it opens, and +/// when its map is switched to a projection that can't show it; a polar map says nothing (#2711). +#[test] +fn a_pole_centred_frame_is_said_on_open_and_on_a_projection_change() { + let layout = r#"{"name":"Polo","width":150,"height":150,"elements":[{"id":1,"name":"Mapa","x":5,"y":5,"w":140,"h":140,"visible":true, + "kind":{"MapFrame":{"map":"Mapa","center":{"x":0.0,"y":-90.0},"scale":60000000.0,"shape":"Circle","grid":null,"extent_of":null}}}], + "series":null,"next_id":2}"#; + let told = |s: &Session, mark| s.notices_since(mark).iter().filter(|n| n.text.contains("can't show")).count(); + let nanos = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0, |d| d.as_nanos()); + let dir = std::env::temp_dir().join(format!("rustgis-pole-open-{}-{nanos}", std::process::id())); + std::fs::create_dir_all(&dir).unwrap(); + // (a) Opened: said on Web Mercator, not on the South Polar Stereographic. + for (projection, said) in [(Some("EPSG:3031"), 0), (None, 1)] { + let mut s = Session::new(Project::default()); + s.run("map.new", &json!({"name": "Mapa"})).unwrap(); + if let Some(p) = projection { + s.run("map.projection", &json!({"type": p})).unwrap(); + } + s.run("layout.import", &json!({"text": layout})).unwrap(); + let path = dir.join(format!("pole-{said}.rgis")); + s.run("project.saveAs", &json!({"path": path.display().to_string()})).unwrap(); + let mut t = Session::new(Project::default()); + let mark = t.notice_mark(); + t.run("project.open", &json!({"path": path.display().to_string()})).unwrap(); + assert_eq!(told(&t, mark), said, "{projection:?}: {:?}", t.notices_since(mark)); + } + // (b) A polar map switched to Web Mercator says it once; back to polar, nothing. + let mut s = Session::new(Project::default()); + s.run("map.new", &json!({"name": "Mapa"})).unwrap(); + s.run("map.projection", &json!({"type": "EPSG:3031"})).unwrap(); + s.run("layout.import", &json!({"text": layout})).unwrap(); + let mark = s.notice_mark(); + s.run("map.projection", &json!({"type": "mercator"})).unwrap(); + assert_eq!(told(&s, mark), 1, "{:?}", s.notices_since(mark)); + let mark = s.notice_mark(); + s.run("map.projection", &json!({"type": "EPSG:3031"})).unwrap(); + assert_eq!(told(&s, mark), 0, "{:?}", s.notices_since(mark)); + let _ = std::fs::remove_dir_all(&dir); +} + /// Series page labels and dynamic text share the row-number fallback for null and blank names. #[test] fn map_series_empty_names_use_row_numbers() { diff --git a/crates/map/src/camera.rs b/crates/map/src/camera.rs index 6f371f0d63..7951659b9d 100644 --- a/crates/map/src/camera.rs +++ b/crates/map/src/camera.rs @@ -22,7 +22,7 @@ pub fn scale_between(a: f64, b: f64, t: f64) -> f64 { /// The steepest pitch (degrees from looking straight down), as MapLibre allows. pub const MAX_PITCH: f64 = 85.0; /// Pitches below this (degrees) look straight down. -const MIN_PITCH: f64 = 1e-6; +pub const MIN_PITCH: f64 = 1e-6; /// The tangent of half the vertical field of view: MapLibre's 36.87°. The horizon comes into /// view above about 71.6° of pitch. pub const TAN_HALF_FOV: f64 = 1.0 / 3.0; diff --git a/crates/map/src/qgis/source.rs b/crates/map/src/qgis/source.rs index 232ed83664..e656badff8 100644 --- a/crates/map/src/qgis/source.rs +++ b/crates/map/src/qgis/source.rs @@ -580,9 +580,13 @@ fn is_pmtiles(url: &str) -> bool { /// The path of a `file:` address: `file:///abs/x` (`file:///C:/x` on Windows) or `file:./x`. /// `None` for any other address, and for a `file://` one with a host (`file://server/share/x`, a -/// network share), which isn't a path here. +/// network share), which isn't a path here; the host `localhost` is this computer (RFC 8089). fn file_url_path(url: &str) -> Option<&str> { let path = match url.strip_prefix("file://") { + // `file://localhost/x`: this computer, its path as `file:///x`. + Some(p) if p.get(..9).is_some_and(|h| h.eq_ignore_ascii_case("localhost")) && matches!(p.as_bytes().get(9), Some(b'/') | None) => { + p.get(9..).filter(|rest| !rest.is_empty()).unwrap_or("/") + } // `file://C:/x`: a drive, written with two slashes. Some(p) if p.as_bytes().first().is_some_and(u8::is_ascii_alphabetic) && p.as_bytes().get(1) == Some(&b':') => p, Some(p) if !p.starts_with('/') => return None, @@ -1975,4 +1979,22 @@ mod tests { assert_eq!(archive_path(url, "/p"), path, "{url}"); } } + + /// `file://localhost/…` is this computer's file (RFC 8089), as `file:///…` is; another host is + /// a network share, not a path here. + #[test] + fn a_file_address_on_localhost_is_this_computers_path() { + for (url, path) in [ + ("file://localhost/maps/t.mbtiles", "/maps/t.mbtiles"), + ("file://LocalHost/C:/maps/t.mbtiles", "C:/maps/t.mbtiles"), + ("file://localhost/maps/my%20tiles.mbtiles", "/maps/my tiles.mbtiles"), + ] { + assert_eq!(archive_path(url, "/p"), path, "{url}"); + assert_eq!(file_address_path(url).as_deref(), Some(path), "{url}"); + } + assert_eq!(file_url_path("file://localhost"), Some("/")); + for url in ["file://host/share/t.mbtiles", "file://localhostess/t.mbtiles"] { + assert_eq!(file_url_path(url), None, "{url}"); + } + } } diff --git a/crates/map/src/qgis/tests.rs b/crates/map/src/qgis/tests.rs index 47550b3f57..c2ffd54111 100644 --- a/crates/map/src/qgis/tests.rs +++ b/crates/map/src/qgis/tests.rs @@ -1805,6 +1805,8 @@ fn raster_image_markers_read_a_file_address_as_the_file_it_names() { }; let cases = [ ("file:///data/my%20pin.png", "/data/my pin.png"), + // `localhost` is this computer (RFC 8089), not a network share. + ("file://localhost/data/my%20pin.png", "/data/my pin.png"), ("file:///C:/data/a.png", "C:/data/a.png"), // A drive's colon may be encoded. ("file:///C%3A/data/a.png", "C:/data/a.png"), diff --git a/crates/map/src/shadow.rs b/crates/map/src/shadow.rs index 31bcf3ad8f..19283082bf 100644 --- a/crates/map/src/shadow.rs +++ b/crates/map/src/shadow.rs @@ -32,7 +32,7 @@ pub const SOFT_EDGE_MIN: f64 = 0.5; pub const SOFT_EDGE_MAX: f64 = 15.0; /// The half disc a layer's shadow softness `setting` gives, in degrees: [`SOFT_EDGE`] with none -/// (or one that isn't a number), and within [`SOFT_EDGE_MIN`] to [`SOFT_EDGE_MAX`] whatever a +/// (or one that isn't a finite number), and within [`SOFT_EDGE_MIN`] to [`SOFT_EDGE_MAX`] whatever a /// file holds (`raster.symbology` refuses a value outside them). pub fn soft_edge(setting: Option) -> f64 { setting.filter(|v| v.is_finite()).map_or(SOFT_EDGE, |v| v.clamp(SOFT_EDGE_MIN, SOFT_EDGE_MAX)) @@ -505,7 +505,7 @@ mod tests { assert!(edges[0] < edges[1] && edges[1] < edges[2], "{edges:?}"); } - /// No setting, or one that isn't a number, is the default; a file's value outside the range + /// No setting, or one that isn't a finite number, is the default; a file's value outside the range /// traces at its nearest bound, never a disc of no size or one past the zenith. #[test] fn a_softness_outside_the_range_traces_at_its_bound() { diff --git a/crates/render/src/block.rs b/crates/render/src/block.rs index 90bd7dc22d..98c5d47575 100644 --- a/crates/render/src/block.rs +++ b/crates/render/src/block.rs @@ -216,8 +216,8 @@ fn clip_outline(m: [Coord; 3], o: &Outline) -> Vec> { // strictly inside, so a ring only touching it doesn't count), its holes wholly inside the // triangle left out (they are cut from it below). let middle = Coord::new((t[0].x + t[1].x + t[2].x) / 3.0, (t[0].y + t[1].y + t[2].y) / 3.0); - let whole = |crossing: &[u32], within: &[u32]| -> Option> { - o.inside_ring(middle, |r| !crossing.contains(&o.kind(r).0) && !within.contains(&r)).then(|| t.iter().map(|c| mark(*c, 0)).collect()) + let whole = |crossing: &[u32]| -> Option> { + o.inside_ring(middle, |r| !crossing.contains(&o.kind(r).0)).then(|| t.iter().map(|c| mark(*c, 0)).collect()) }; // How far inside edge `e` (from corner e to the next) `p` lies. let len = [0, 1, 2].map(|e| (t[(e + 1) % 3].x - t[e].x).hypot(t[(e + 1) % 3].y - t[e].y).max(1e-300)); @@ -246,7 +246,7 @@ fn clip_outline(m: [Coord; 3], o: &Outline) -> Vec> { } } if parts.is_empty() { - return whole(&[], &[]).into_iter().collect(); + return whole(&[]).into_iter().collect(); } let find = |k: usize| parts.binary_search_by_key(&k, |p| p.0).ok(); let at = |k: usize, u: f64| sides.get(k).map_or(t[0], |s| Coord::new(s.a.x + (s.z.x - s.a.x) * u, s.a.y + (s.z.y - s.a.y) * u)); @@ -320,7 +320,7 @@ fn clip_outline(m: [Coord; 3], o: &Outline) -> Vec> { holed.sort_unstable(); holed.dedup(); let crossed: Vec = crossing.iter().chain(out.iter().map(|p| &p.0)).chain(&holed).copied().collect(); - if let Some(w) = whole(&crossed, &[]) { + if let Some(w) = whole(&crossed) { out.push((u32::MAX, w)); } else { for p in holed { @@ -3446,7 +3446,12 @@ mod tests { // wall the floor lies at the bed's heights (doubled, as the level is), not the depth's // basin, and the water reaches down to it. let (m, b, g, res) = lake_over_bed(Some(5.0), dipping); + let before = crate::approximations::keep(); let water = water_runs(&m, &b, &g, res, 1.0, &Default::default()); + let said = crate::approximations::take(); + crate::approximations::restore(before); + // A bed with heights all along the water says nothing of it (Never silent, both ways). + assert!(!said.iter().any(|t| t.contains("water bed has no heights")), "{said:?}"); let [r] = &water[0][..] else { panic!("one stretch of water on the south side") }; // The shading runs to its deepest sample, about 40 m (doubled) down. assert!((r.level - 1000.0).abs() < 1e-6 && (r.depth - 80.0).abs() < 3.0, "{} {}", r.level, r.depth); diff --git a/crates/render/src/fonts.rs b/crates/render/src/fonts.rs index 49ccb90333..660596490a 100644 --- a/crates/render/src/fonts.rs +++ b/crates/render/src/fonts.rs @@ -513,7 +513,8 @@ fn in_apple_dirs(files: &[(&str, T)]) -> impl Iterator [(&'static str, u32); 3] { let index = match region { CjkRegion::Japanese => 0, @@ -521,7 +522,7 @@ fn android_cjk_files(region: CjkRegion) -> [(&'static str, u32); 3] { CjkRegion::SimplifiedChinese => 2, CjkRegion::TraditionalChinese => 3, }; - [("NotoSansCJK-Regular.ttc", index), ("NotoSerifCJK-Regular.ttc", index), ("DroidSansFallback.ttf", 0)] + [("NotoSansCJK-Regular.ttc", index), ("DroidSansFallback.ttf", 0), ("NotoSerifCJK-Regular.ttc", index)] } /// Every installed CJK font candidate for `region`, in order of preference: (path, face index). @@ -667,6 +668,9 @@ fn scan_cjk_roots_bounded(roots: &[std::path::PathBuf], max_depth: usize, max_di // without re-reading the directory or double-counting against the directory/entry/file caps. let mut seen: std::collections::HashMap)> = std::collections::HashMap::new(); let mut skipped_dirs: Vec = Vec::new(); + // Canonical folders whose listing failed: one reached again (a symlink alias, a second root) + // isn't read or counted again, so the notice's count of unreadable folders holds. + let mut unreadable: std::collections::HashSet = std::collections::HashSet::new(); let mut dirs_visited = 0usize; let mut files_seen = 0usize; let mut entries_seen = 0usize; @@ -720,10 +724,13 @@ fn scan_cjk_roots_bounded(roots: &[std::path::PathBuf], max_depth: usize, max_di } continue; } + if unreadable.contains(&canonical) { + continue; + } let entries = match std::fs::read_dir(&dir) { Ok(entries) => entries, Err(err) => { - if err.kind() != std::io::ErrorKind::NotFound { + if err.kind() != std::io::ErrorKind::NotFound && unreadable.insert(canonical) { summary.unreadable_dirs += 1; summary.sample_path.get_or_insert_with(|| dir.clone()); } @@ -1855,6 +1862,10 @@ mod tests { for dir in super::ANDROID_FONT_DIRS { assert!(paths.contains(&(PathBuf::from(dir).join("NotoSansCJK-Regular.ttc"), index)), "{region:?}"); assert!(paths.contains(&(PathBuf::from(dir).join("DroidSansFallback.ttf"), 0)), "{region:?}: legacy face"); + // The legacy sans face is tried before the serif collection, so the interface + // stays sans on a folder holding only those two. + let at = |name: &str| paths.iter().position(|(p, _)| p == &PathBuf::from(dir).join(name)); + assert!(at("DroidSansFallback.ttf") < at("NotoSerifCJK-Regular.ttc"), "{region:?}: sans before serif"); } } let korean = cjk_paths(CjkRegion::Korean); @@ -2133,6 +2144,29 @@ mod tests { assert!(err_notice.contains("3 directory entry error(s)"), "{err_notice}"); } + /// An unreadable folder reached by two routes (symlinks, a second root) is counted once. + #[cfg(unix)] + #[test] + fn scan_cjk_roots_counts_an_unreadable_folder_once_however_it_is_reached() { + use std::os::unix::fs::PermissionsExt; + + let dir = tempfile::tempdir().unwrap(); + let locked = dir.path().join("locked"); + std::fs::create_dir_all(&locked).unwrap(); + std::os::unix::fs::symlink(&locked, dir.path().join("a")).unwrap(); + std::os::unix::fs::symlink(&locked, dir.path().join("b")).unwrap(); + std::fs::set_permissions(&locked, std::fs::Permissions::from_mode(0o000)).unwrap(); + // Run as root, permissions don't bite: nothing to test. + let readable = std::fs::read_dir(&locked).is_ok(); + let scan = (!readable).then(|| super::scan_cjk_roots_bounded(&[dir.path().to_path_buf(), locked.clone()], 6, 10, 10)); + std::fs::set_permissions(&locked, std::fs::Permissions::from_mode(0o755)).unwrap(); + if let Some(scan) = scan { + assert_eq!(scan.summary.unreadable_dirs, 1, "{:?}", scan.summary); + let notice = scan.summary.notice().expect("an unreadable folder is said"); + assert!(notice.contains("1 unreadable folder(s)"), "{notice}"); + } + } + #[cfg(unix)] #[test] fn scan_cjk_roots_revisits_canonical_directory_when_reached_shallower() { diff --git a/crates/render/src/frame_cache.rs b/crates/render/src/frame_cache.rs index 5cd44d6573..250a021ddc 100644 --- a/crates/render/src/frame_cache.rs +++ b/crates/render/src/frame_cache.rs @@ -61,7 +61,7 @@ const SPRITE_PIXELS: u64 = crate::MAX_SPRITES as u64 * (2 * crate::MAX_SPRITE_RE /// The most bytes of label candidates a view keeps for its layers together, by /// [`Candidate::bytes`], what they hold beside them included (text, glyphs curved along a line, -/// places to try): about 20,000 point labels, each of 464 bytes and the places around it. A +/// places to try): about 20,000 point labels, each its `Candidate` and the places around it. A /// layer whose candidates would go past it works them out in every frame. A frame copies no more /// than this either, its layers bottom first. pub(crate) const MAX_LABEL_BYTES: usize = 16 << 20; diff --git a/crates/render/src/layout/colorbar.rs b/crates/render/src/layout/colorbar.rs index 4ed80107a1..ee9cc4df4f 100644 --- a/crates/render/src/layout/colorbar.rs +++ b/crates/render/src/layout/colorbar.rs @@ -2,6 +2,17 @@ use super::*; +/// A colorbar's label size, in points (#2638). +const LABEL_PT: f32 = 8.0; +/// A label's line height, as a multiple of its size. +const LABEL_LINE: f32 = 1.2; +/// A tick's length past the bar, in pixels at 96 dpi. +const TICK_PX: f32 = 2.5; +/// The gap between a tick and its label, in pixels at 96 dpi. +const GAP_PX: f32 = 1.5; +/// The thinnest horizontal bar drawn with its labels, in pixels at 96 dpi. +const MIN_BAR_PX: f32 = 3.0; + /// How a colorbar is laid out. pub(super) struct Bar<'a> { pub(super) title: &'a str, @@ -63,7 +74,7 @@ pub(super) struct ColorbarPlan { /// labels to stand past its ends, and each label drawn only if it clears the one before and stays /// inside the element. pub(super) fn colorbar_plan(r: Rect, scale: &ColorScale, bar: &Bar, ppp: f32) -> ColorbarPlan { - let px = 8.0 * 1.33 * ppp; + let px = LABEL_PT * 1.33 * ppp; let width = |s: &str| text::measure(s, px / 1.33, false); let (mut top, bottom) = (r.y(), r.y() + r.height()); let mut title = Vec::new(); @@ -111,8 +122,8 @@ pub(super) fn colorbar_plan(r: Rect, scale: &ColorScale, bar: &Bar, ppp: f32) -> return plan; } let labels: Vec<(f32, String)> = labels.into_iter().map(|(at, s)| (at, decimal(s, bar.comma))).collect(); - let tick = 2.5 * ppp; - let gap = 1.5 * ppp; + let tick = TICK_PX * ppp; + let gap = GAP_PX * ppp; let (bx, by, bw, bh) = if vertical { let label_w = labels.iter().map(|(_, s)| width(s)).fold(0.0f32, f32::max); let bw = (r.width() - label_w - tick - gap).clamp(2.0 * ppp, (r.width() * 0.45).max(2.0 * ppp)).min(r.width()); @@ -123,8 +134,8 @@ pub(super) fn colorbar_plan(r: Rect, scale: &ColorScale, bar: &Bar, ppp: f32) -> let ends = labels.first().map(|(_, s)| width(s)).unwrap_or(0.0).max(labels.last().map(|(_, s)| width(s)).unwrap_or(0.0)); let inset = (ends / 2.0).min(r.width() * 0.25); // Too short for its labels (left out below, and said), the bar fills the element. - let bh = match bottom - top - px * 1.2 - tick - gap { - h if h >= 3.0 * ppp => h, + let bh = match bottom - top - px * LABEL_LINE - tick - gap { + h if h >= MIN_BAR_PX * ppp => h, _ => bottom - top, }; let by = if bar.side == TickSide::Start { bottom - bh } else { top }; @@ -175,7 +186,7 @@ pub(super) fn colorbar_plan(r: Rect, scale: &ColorScale, bar: &Bar, ppp: f32) -> pub(super) fn colorbar(pm: &mut Canvas, r: Rect, scale: &ColorScale, bar: &Bar, ppp: f64) { let ppp = ppp as f32; let dark = bar.ink; - let px = 8.0 * 1.33 * ppp; + let px = LABEL_PT * 1.33 * ppp; let plan = colorbar_plan(r, scale, bar, ppp); let tpx = COLORBAR_TITLE_PT as f32 * 1.33 * ppp; for (line, y) in &plan.title { @@ -269,7 +280,7 @@ pub(super) fn colorbar_title_drawn(lines: usize, top: f32, limit: f32, px: f32) /// so its lines never leave the bar without its labels. pub(super) fn colorbar_bar_room(ppp: f32, orientation: Orientation) -> f32 { match orientation { - Orientation::Horizontal => (8.0 * 1.33 * 1.2 + 2.5 + 1.5 + 3.0) * ppp, - Orientation::Vertical => 2.0 * 8.0 * 1.33 * ppp, + Orientation::Horizontal => (LABEL_PT * 1.33 * LABEL_LINE + TICK_PX + GAP_PX + MIN_BAR_PX) * ppp, + Orientation::Vertical => 2.0 * LABEL_PT * 1.33 * ppp, } } diff --git a/crates/render/src/layout/losses.rs b/crates/render/src/layout/losses.rs index 242ab613de..a3f0d90bd8 100644 --- a/crates/render/src/layout/losses.rs +++ b/crates/render/src/layout/losses.rs @@ -27,7 +27,9 @@ pub struct TextLoss { /// text draws them. For a scale bar, its box is too small for its labels and bar /// ([`BarLayout::cramped`]): its bar drawn below it, or its end label past its side or over /// its first label. For a colorbar, also set, with no line counted, when its labels would - /// spill out of its box ([`colorbar_plan`]). + /// spill out of its box ([`colorbar_plan`]). For a profile, also set, with no line counted, + /// when its title is shortened or left out between its section's names + /// ([`profile_title_cut`]). pub below_box: bool, /// Some of them come past the 200 lines a text draws, whatever its box: only splitting the /// text draws them. @@ -127,6 +129,20 @@ pub(super) fn losses(layout: &Layout, maps: &[Map], dpi: f64, info: &PageInfo, o unit_label, }); } + // A horizontal profile's title shortened, or left out, between its section's names + // (#3316). + if let ElementKind::Profile(p) = &e.kind { + return profile_title_cut(layout, maps, p, r, ppp).then(|| TextLoss { + id: e.id, + name: e.name.clone(), + left_out: 0, + at_least: false, + below_box: true, + past_limit: false, + off_page: false, + unit_label: None, + }); + } // A colorbar's labels left out for want of height, said with its title (#2638). let mut labels_cut = false; // `fits`: how many of its lines the element draws, when it decides that itself. @@ -331,12 +347,16 @@ pub fn clipped_text_notice(layout: &Layout, clipped: &[(u32, String)]) -> Option // Colorbars alone: their titles already wrap, and a tick label isn't fixed by a line break // (#2638). let colorbars = clipped.iter().all(|(id, _)| matches!(layout.element(*id).map(|e| &e.kind), Some(ElementKind::Colorbar { .. }))); + // Profiles alone: their titles are shortened to the room between their section's names (#3316). + let profiles = clipped.iter().all(|(id, _)| matches!(layout.element(*id).map(|e| &e.kind), Some(ElementKind::Profile(_)))); let advice = if bars && clipped.len() == 1 { "move it inside the page or make its box larger, or reduce its text size" } else if bars { "move them inside the page or make their boxes larger, or reduce their text size" } else if colorbars { "make the colorbar larger or its title shorter, so its title lines and tick labels fit" + } else if profiles { + "make the profile longer or its title shorter, so its title fits between its section's names" } else if wraps.contains(&Some(false)) { "resize or move the text, reduce its size, add line breaks, or turn on Wrap to the box" } else if wraps.iter().all(|w| *w == Some(true)) { @@ -359,11 +379,11 @@ pub fn scale_bar_fit_notices(losses: &[TextLoss]) -> Vec { match (n, small) { (0, _) => None, (1, true) => Some(format!( - "Scale bar {names}: its box is too small for its labels at their size, so they or its bar run past it; make it larger or reduce its text size" + "Scale bar {names}: its box is too small for its labels at their size, so they crowd each other, run past it, or leave its bar below it; make it larger or reduce its text size" )), (1, false) => Some(format!("Scale bar {names}: a label runs off the page; move it inside the page or reduce its text size")), (_, true) => Some(format!( - "{n} scale bars ({names}): their boxes are too small for their labels at their size, so they or their bars run past them; make them larger or reduce their text size" + "{n} scale bars ({names}): their boxes are too small for their labels at their size, so they crowd each other, run past them, or leave their bars below them; make them larger or reduce their text size" )), (_, false) => { Some(format!("{n} scale bars ({names}): a label runs off the page; move them inside the page or reduce their text size")) diff --git a/crates/render/src/layout/profile.rs b/crates/render/src/layout/profile.rs index ba3a3a0d98..148bad9af4 100644 --- a/crates/render/src/layout/profile.rs +++ b/crates/render/src/layout/profile.rs @@ -496,9 +496,8 @@ pub(super) fn draw_profile(pm: &mut Canvas, r: Rect, p: &Profile, (samples, sect let cy = r.y() + head / 2.0; text::text_at(pm, &first, start + 2.0 * k, cy, name_px, colour, true, text::Align::Left, false); text::text_at(pm, &second, start + length - 2.0 * k, cy, name_px, colour, true, text::Align::Right, false); - if !p.title.trim().is_empty() { - let x = start + 2.0 * k + width(&first, name_px, true) + 4.0 * k; - text::text_at(pm, p.title.trim(), x, cy, title_px, ink, true, text::Align::Left, false); + if let (x, Some(title)) = profile_title_fit(p.title.trim(), [&first, &second], start, length, k) { + text::text_at(pm, &title, x, cy, title_px, ink, true, text::Align::Left, false); } } else { let (cx, align) = @@ -511,6 +510,37 @@ pub(super) fn draw_profile(pm: &mut Canvas, r: Rect, p: &Profile, (samples, sect } } +/// A horizontal profile's `title` as it is drawn after the first of its section's `names` (#3316), +/// the profile running `length` pixels from `start` at `k` pixels a point: where it starts, and +/// its text, shortened with an ellipsis to the room before the second name, `None` when not even +/// one character fits (or it has none). [`profile_title_cut`] says it. +pub(super) fn profile_title_fit(title: &str, [first, second]: [&str; 2], start: f32, length: f32, k: f32) -> (f32, Option) { + let (name_px, title_px) = (PROFILE_NAME_PT * 1.33 * k, PROFILE_TITLE_PT * 1.33 * k); + let width = |s: &str, px: f32| text::measure(s, px / 1.33, true); + let x = start + 2.0 * k + width(first, name_px) + 4.0 * k; + let room = start + length - 2.0 * k - width(second, name_px) - 4.0 * k - x; + let drawn = if title.is_empty() || room <= 0.0 { None } else { shortened(title, room, |t| width(t, title_px)) }; + (x, drawn) +} + +/// Whether profile `p`, drawn in `r` at `ppp` pixels a point, draws its title shortened or leaves +/// it out ([`profile_title_fit`]): a horizontal one whose title is wider than the room between its +/// section's names. A profile drawn as its placeholder, or not at all, says nothing of its title +/// (its own notice says why: [`profile_note`]). +pub(super) fn profile_title_cut(layout: &Layout, maps: &[Map], p: &Profile, r: Rect, ppp: f32) -> bool { + let title = p.title.trim(); + if title.is_empty() || !p.side.is_horizontal() { + return false; + } + let Ok((samples, section)) = profile_samples(layout, maps, p) else { return false }; + let (_, _, (_, _, plot)) = profile_strips(p, (&samples, §ion), r.height(), ppp, false); + if plot < 2.0 * ppp || samples.range().is_none() { + return false; + } + let second = format!("{}'", section.name); + profile_title_fit(title, [§ion.name, &second], r.x(), r.width(), ppp).1.as_deref() != Some(title) +} + /// The place along the frame's side (points) where the ground distance from the section's start is /// `metres`, between the samples around it; `None` past the last. fn along_at(s: &ProfileSamples, metres: f64) -> Option { diff --git a/crates/render/src/layout/profile_tests.rs b/crates/render/src/layout/profile_tests.rs index 966246b7e6..a693c907c4 100644 --- a/crates/render/src/layout/profile_tests.rs +++ b/crates/render/src/layout/profile_tests.rs @@ -461,3 +461,60 @@ fn a_profile_too_thin_for_its_axes_says_so() { let said = said(&l); assert!(said.len() == 1 && said[0].contains("not drawn") && said[0].contains("too thin"), "{said:?}"); } + +/// A horizontal profile's title too long for the room between its section's names is shortened +/// with an ellipsis, clear of the second name, and the page says it is cut; a title that fits is +/// drawn whole and says nothing (#3316). +#[test] +fn a_horizontal_profiles_long_title_stops_short_of_its_second_name() { + let title = "Perfil topográfico da Serra da Mantiqueira, do Pico das Agulhas Negras à Pedra da Mina"; + let n = 41; + let samples = ProfileSamples { + along: (0..n).map(|i| f64::from(i) * 3.0).collect(), + metres: (0..n).map(|i| f64::from(i) * 100.0).collect(), + values: (0..n).map(|i| Some(f64::from(i))).collect(), + cells: None, + }; + let section = Section::new("A".into(), SectionLine::Horizontal(CENTER)); + let ppp = 2.0; + let (w, h) = ((120.0 * ppp) as u32, (120.0 * ppp) as u32); + let drawn = |title: &str| { + let p = Profile { title: title.into(), ..Profile::new(1, "A".into(), "DEM".into(), ProfileSide::Bottom) }; + let mut pm = Canvas::new(w, h).unwrap(); + draw_profile(&mut pm, Rect::from_xywh(0.0, 0.0, w as f32, h as f32).unwrap(), &p, (&samples, §ion), false, ppp); + pm.into_pixmap() + }; + let (long, none) = (drawn(title), drawn("")); + // From the second name's start to the end, the head strip is as without a title. + let k = ppp as f32; + let second = w as f32 - 2.0 * k - text::measure("A'", PROFILE_NAME_PT * 1.33 * k / 1.33, true); + let head = (PROFILE_NAME_PT * 1.33 * k * 1.5) as u32; + for x in (second.floor() as u32).saturating_sub(1)..w { + for y in 0..head { + assert_eq!(long.pixel(x, y), none.pixel(x, y), "title ink at {x}, {y}, past the second name at {second}"); + } + } + // The title is drawn, shortened, before it. + let differs = (0..second as u32).any(|x| (0..head).any(|y| long.pixel(x, y) != none.pixel(x, y))); + assert!(differs, "the shortened title is drawn"); + let fit = profile_title_fit(title, ["A", "A'"], 0.0, w as f32, k).1.expect("some of it fits"); + assert!(fit.ends_with('…') && fit.chars().count() < title.chars().count(), "{fit}"); + // The page says it: cut on a narrow profile, whole on a wide one with a short title. + let maps = vec![utm_map(mantiqueira(|_, n| n).unwrap())]; + let (mut l, id) = page(SectionLine::Horizontal(CENTER), ProfileSide::Bottom, (0.0, 0.0)); + let info = PageInfo::default(); + if let Some(ElementKind::Profile(p)) = l.element_mut(id).map(|e| &mut e.kind) { + p.title = "Mantiqueira".into(); + } + assert!(text_losses(&l, &maps, 96.0, &info).is_empty(), "{:?}", text_losses(&l, &maps, 96.0, &info)); + if let Some(e) = l.element_mut(id) { + e.w = 40.0; + if let ElementKind::Profile(p) = &mut e.kind { + p.title = title.into(); + } + } + let losses = text_losses(&l, &maps, 96.0, &info); + assert!(losses.iter().any(|loss| loss.id == id && loss.below_box && loss.left_out == 0), "{losses:?}"); + let notice = clipped_text_notice(&l, &clipped_text(&l, &maps, 96.0, &info)).expect("said"); + assert!(notice.contains("make the profile longer or its title shorter"), "{notice}"); +} diff --git a/crates/render/src/layout/tests.rs b/crates/render/src/layout/tests.rs index 1a50e73b57..af37d6c8ac 100644 --- a/crates/render/src/layout/tests.rs +++ b/crates/render/src/layout/tests.rs @@ -3282,7 +3282,8 @@ fn a_reliefs_aerial_perspective_lightens_its_page() { fn a_reliefs_terrain_type_changes_its_frames_contrast_not_its_colour_bar() { use rustgis_data::raster::{ColorHint, Crs, GeoTransform, Raster}; let n = 300usize; - // Hills 800 m high and about 60 km across, on cells of about 740 m: slopes of a few degrees. + // Hills about 800 m up and down (1,600 m peak to peak), crests about 42 and 33 km apart on + // cells of about 740 m: slopes up to about 6°. let heights: Vec = (0..n * n).map(|i| (((i % n) as f32 / 9.0).sin() + ((i / n) as f32 / 7.0).cos()) * 400.0).collect(); let gt = GeoTransform { origin_x: -1.0, origin_y: 1.0, pixel_width: 2.0 / n as f64, pixel_height: -2.0 / n as f64 }; let dem = Raster::new("dem", n as u32, n as u32, vec![heights], gt, Crs::LonLat, None, ColorHint::Gray, "Float32").unwrap(); @@ -5064,7 +5065,8 @@ fn a_colorbars_long_title_leaves_its_bar_room_for_labels() { let scale = ColorScale::Ramp { lo: 0.0, hi: 10.0, colors: vec![Rgba::rgb(220, 30, 30), Rgba::rgb(30, 30, 220)] }; let title = "Precipitação média mensal JAXA GSMaP (mm/mês), jan–mar 2025"; let bar = Bar { title, orientation: Orientation::Horizontal, ticks: 3, side: TickSide::End, reverse: false, comma: false, ink: INK }; - // 100 × 40 px: room for two lines of title, but then only 8 px of bar, with no labels. + // 100 × 40 px: one line of title, then the bar with its labels under it; a second line would + // take their room. let mut c = Canvas::new(300, 200).unwrap(); colorbar(&mut c, Rect::from_xywh(10.0, 10.0, 100.0, 40.0).unwrap(), &scale, &bar, 1.0); let px = |x: u32, y: u32| c.pixmap().pixel(x, y); diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index 8fd38fabc5..13376fda42 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -4137,7 +4137,13 @@ fn upright_markers_with(map: &mut Map, view: &View, margin: f64, env: &Env) -> V order.sort_by_key(|i| map.layers.get(*i).map_or(0, |l| l.priority)); let (cam, h) = (view.camera, view.height); // The pitch's cosine as the camera clamps it: down the view a ground unit is `lean * k * k` px. - let lean = cam.pitch.clamp(0.0, rustgis_map::camera::MAX_PITCH).to_radians().cos(); + // A pitch the camera takes as looking straight down (too small, or not a finite number, from + // a hand-edited or old file) leans none, as `Camera::tilt` has it. + let lean = if cam.pitch.is_finite() && cam.pitch >= rustgis_map::camera::MIN_PITCH { + cam.pitch.clamp(0.0, rustgis_map::camera::MAX_PITCH).to_radians().cos() + } else { + 1.0 + }; let ground = terrain::Ground::of(map, &view.camera); let mut out = Vec::new(); for li in order { @@ -6508,7 +6514,12 @@ fn render_frame( let first = locked_at.or_else(|| fitted.as_ref().and_then(|f| f.first().copied())); if try_others { let width = line_labels::curved_len(&advances, gap); - let positions = fitted.clone().map_or_else(|| positions(width), |f| line_labels::both_sides(f, off)); + // Places offered at the class's own spacing: a stretched name + // falls back to it place by place (`Curves::place`), so the + // places near the ends a close-set one reaches stay offered. + let close_width = line_labels::curved_len(&advances, close_gap); + let positions = + fitted.clone().map_or_else(|| positions(close_width), |f| line_labels::both_sides(f, off)); // A saved slot the curve cannot take has no truthful preview either (as for a // straight line): never draw one at the anchor or the middle. if lock.as_ref().and_then(|k| k.get(&key)).is_some_and(|won| usize::from(won.place) >= positions.len()) @@ -7041,6 +7052,8 @@ fn render_frame( let mut boxes = Vec::new(); boxes.try_reserve_exact(n).ok().map(|()| boxes) }); + // As many boxes as the source said it holds, not the room reserved (which may be more). + let limit = count.unwrap_or(0); // Records the read left out: one it couldn't read this time may read on another. let mut skipped = 0usize; // The view's own read isn't needed when a wider one is read to keep: its ids let go. @@ -7075,7 +7088,7 @@ fn render_frame( && (e.is_empty() // Never more than it has room for: a source that gives more // than it said gets no index. - || (boxes.len() < boxes.capacity() + || (boxes.len() < limit && u32::try_from(row.id()).is_ok_and(|id| { boxes.push((id, f32_box(e))); true @@ -11929,6 +11942,47 @@ mod tests { assert!(!tiled(&mut m, &view), "tilted: one mesh"); } + /// A wide stroke past a tilted view's band's tiles, whose widening by depth brings it back over + /// the band's ground, is meshed for that band (one mesh), not left out with its line. + #[test] + fn a_tilted_bands_stroke_from_past_its_tiles_is_meshed_where_it_widens_over_its_ground() { + let mut m = Map::new("Map"); + m.basemap = rustgis_map::Basemap::Blank; + m.graticule = false; + let camera = Camera { center: lonlat_to_merc(Coord::new(0.0, 0.5)), res: 2000.0, bearing: 0.0, pitch: 50.0 }; + let view = View { width: 1200.0, height: 900.0, pixels_per_point: 1.0, camera, sky: false }; + let bands = view.camera.tilt_bands(view.width, view.height); + let near = band_view(&view, &bands[0]); + let mpp = near.camera.res / near.pixels_per_point; + let side = mesh_tiles::tile_side(mpp).expect("tiles"); + let area = cull_extent(&near, GPU_CULL_MARGIN); + let tiles = mesh_tiles::feature_area(&area, mpp).expect("tiles"); + let grow = view.camera.res * bands[0].depth.1 / bands[0].camera.res; + // A level line half a tile past the band's tiles, up the view (north). + let y = tiles.max_y + side / 2.0; + let line = Geometry::Line(vec![vec![ + rustgis_geom::merc_to_lonlat(Coord::new(area.min_x, y)), + rustgis_geom::merc_to_lonlat(Coord::new(area.max_x, y)), + ]]); + let mut d = Dataset::new("wide", GeometryType::Polyline, vec![]); + d.push(Some(line.clone()), vec![]); + let id = m.add_dataset(d); + // Widened at least `grow` times, it reaches well past the band's cull. + let symbol = |w: f32| Symbol { stroke_width: w, ..m.layers[0].symbol(0) }; + let reach = |w: f32| mesh::stroke_reach(&line, &symbol(w), false, near.pixels_per_point as f32, mpp); + let w = (1..40_000).map(|w| w as f32 * 0.5).find(|w| reach(*w) * grow >= (y - area.max_y) * 1.2).expect("a width"); + let wide = symbol(w); + if let Some(l) = m.layer_mut(id) { + l.renderer = rustgis_map::Renderer::Single(wide); + } + let Some(RenderOutput::Gpu(scene)) = render_backend(&mut m, &view, Backend::Gpu) else { panic!("a GPU scene") }; + let first = scene.cmds.iter().find_map(|c| match c { + gpu_scene::DrawCmd::Mesh { square, .. } => Some(square.is_none()), + _ => None, + }); + assert_eq!(first, Some(true), "the band meshes the stroke, as one mesh"); + } + /// A turned or tilted view with a layer too dense to mesh is drawn on the CPU, as the CPU /// backend draws it, and the GPU frame tried first stops at that layer: the one above it is /// never meshed (#2540). Without it, the view stays a GPU scene. @@ -12433,6 +12487,23 @@ mod tests { assert_eq!(rows(Marker::Circle, 10.0, 175.0), 0, "a small one all under the edge: nothing"); } + /// A pitch that isn't a finite number (a hand-edited or old file) looks straight down, as the + /// camera has it: a marker beyond the view's edge isn't kept for a reach grown as at 85°. + #[test] + fn an_upright_marker_under_a_pitch_that_isnt_a_number_is_kept_as_looking_straight_down() { + // 60 px under the view's bottom edge, a 10-point circle reaching some 11 px round it. + let kept = |pitch: f64| { + let camera = Camera { center: Coord::new(0.0, 0.0), res: 1000.0, bearing: 0.0, pitch }; + let view = View { width: 200.0, height: 200.0, pixels_per_point: 1.0, camera, sky: false }; + let (_, mut m) = upright_frame(&view, Coord::new(0.0, -160.0 * 1000.0), Marker::Circle, 10.0, 0.0, false); + upright_markers(&mut m, &view, 0.0).len() + }; + assert_eq!(kept(0.0), 0); + for pitch in [f64::INFINITY, f64::NAN, f64::NEG_INFINITY] { + assert_eq!(kept(pitch), 0, "{pitch}"); + } + } + /// A marker past the view's reach (the sky band, where `place` draws none) isn't kept for its /// size, however large: the GPU path draws every marker the list holds. #[test] @@ -16692,6 +16763,48 @@ mod tests { assert!((covered(torto) - line_labels::curved_len(&advances("Rio Torto"), 0.0)).abs() < 1.0, "{}", covered(torto)); } + /// A stretched name (#2262) whose line's middle is taken by another label is still offered + /// the places nearer the ends a close-set one reaches, and goes there at its own spacing, as + /// the same name without `stretch` does. + #[test] + fn a_stretched_name_whose_middle_is_taken_goes_close_set_nearer_an_end() { + let deg = |points: f64| points / (111_320.0 / 1500.0); + let mut m = Map::new("Map"); + m.basemap = rustgis_map::Basemap::Blank; + let mut d = Dataset::new("rivers", GeometryType::Polyline, vec![Field::new("name", FieldType::Text)]); + d.push( + Some(Geometry::Line(vec![vec![Coord::new(deg(-600.0), 0.0), Coord::new(deg(600.0), 0.0)]])), + vec![Value::Text("Rio Longo".into())], + ); + let river = m.add_dataset(d); + let l = m.layer_mut(river).unwrap(); + l.labels.enabled = true; + l.labels.default.field = "name".into(); + l.labels.default.size = 12.0; + l.labels.default.placement = rustgis_map::LabelPlacement::Curved; + l.labels.default.other_positions = true; + // A wide label on the line's middle, covering about 500 points of it. + let mut d = Dataset::new("towns", GeometryType::Point, vec![Field::new("name", FieldType::Text)]); + d.push(Some(Geometry::Point(Coord::new(0.0, 0.0))), vec![Value::Text("MMMMMMMMMMMM".into())]); + let town = m.add_dataset(d); + let l = m.layer_mut(town).unwrap(); + l.labels.enabled = true; + l.labels.default.field = "name".into(); + l.labels.default.size = 36.0; + let camera = Camera { center: lonlat_to_merc(Coord::new(0.0, 0.0)), res: 1500.0, bearing: 0.0, pitch: 0.0 }; + let view = View { width: 1600.0, height: 600.0, pixels_per_point: 1.0, camera, sky: false }; + let r = render(&mut m, &view).unwrap(); + let blocker = r.labels.iter().find(|l| l.text.starts_with('M')).expect("the town's label placed"); + let plain = r.labels.iter().find(|l| l.text == "Rio Longo").unwrap_or_else(|| { + panic!("placed away from the middle without stretch: {:?}", r.labels.iter().map(|l| (&l.text, l.x, l.y)).collect::>()) + }); + assert!((plain.x - blocker.x).abs() > 150.0, "{} {}", plain.x, blocker.x); + m.layer_mut(river).unwrap().labels.default.stretch = Some(0.7); + let r = render(&mut m, &view).unwrap(); + let stretched = r.labels.iter().find(|l| l.text == "Rio Longo").expect("placed with stretch too"); + assert!((stretched.x - blocker.x).abs() > 150.0, "{} {}", stretched.x, blocker.x); + } + #[test] fn a_line_mostly_off_screen_is_labelled_along_its_stretch_in_view() { // A river reaching far off to the east, its middle well out of view, and a road whose diff --git a/crates/render/src/mesh.rs b/crates/render/src/mesh.rs index af5f94f1e1..d726291e12 100644 --- a/crates/render/src/mesh.rs +++ b/crates/render/src/mesh.rs @@ -547,15 +547,34 @@ pub(crate) fn collect_layer( // backends keep the same features; the globe has none cached. let e = extents.get(row).copied().unwrap_or_else(|| g.extent()); let marker = matches!(g, Geometry::Point(_) | Geometry::MultiPoint(_)); + if rows.get(row) != Some(&true) { + continue; + } let seen = match &near { Some(near) if !marker => e.intersects(near), _ => visible(&e), }; - if rows.get(row) != Some(&true) || !seen { - continue; + // In a tilted view's band, a stroke past `near` that the shader widens back over the + // band's ground is taken too, its reach counted (the band is then one mesh, below): left + // out, the ground near the far edge would lose its widened part. + let mut symbol = None; + if !seen { + let reaches_in = !marker + && near.is_some() + && tiling.as_ref().is_some_and(|t| { + t.band.is_some() && { + let s = layer.symbol(row); + let reach = t.widened(stroke_reach(g, &s, wireframe, ppp, map_per_px)); + symbol = Some(s); + reach > 0.0 && reach.is_finite() && e.padded(0.0, reach).intersects(t.area) + } + }); + if !reaches_in { + continue; + } } ext = ext.union(&e); - let s = layer.symbol(row); + let s = symbol.unwrap_or_else(|| layer.symbol(row)); if marker { // A character or an image has no shape template: its layer draws on the CPU. if matches!(s.marker, Marker::Char(_) | Marker::Picture(_)) { @@ -584,6 +603,8 @@ pub(crate) fn collect_layer( if ext.is_empty() { return Ok(0); } + // In a band, the one mesh takes those whose stroke the shader widens over it too. + let banded = tiling.as_ref().is_some_and(|t| t.band.is_some()); let tiled = match tiling { _ if features.is_empty() => Some(Ok((Vec::new(), 0))), // A tilted view's band with a stroke reaching a tile or more past its feature is one mesh, @@ -614,7 +635,10 @@ pub(crate) fn collect_layer( // features' extent. None => { // Only those `visible` keeps: the ones past it were taken for the tiles. - let shown: Vec<&crate::mesh_tiles::Feature<'_>> = features.iter().filter(|f| visible(&f.extent)).collect(); + let shown: Vec<&crate::mesh_tiles::Feature<'_>> = features + .iter() + .filter(|f| visible(&f.extent) || (banded && f.reach.is_finite() && visible(&f.extent.padded(0.0, f.reach)))) + .collect(); let at = shown.iter().fold(marked, |e, f| e.union(&f.extent)); let origin = if at.is_empty() { [0.0, 0.0] } else { origin_for(&at, map_per_px)? }; let (mut v, mut i) = (Vec::new(), Vec::new()); diff --git a/crates/render/src/testing.rs b/crates/render/src/testing.rs index 4555c2362d..8c6704f4d8 100644 --- a/crates/render/src/testing.rs +++ b/crates/render/src/testing.rs @@ -4,7 +4,7 @@ use rustgis_data::raster::{ColorHint, Crs, GeoTransform, Raster}; use rustgis_geom::Coord; /// A one-band grid in `crs` of `cols` × `rows` square cells of `cell`, its top-left corner at -/// `(x0, y0)`, each cell `z` of its centre's x and y; why not, when it can't be made. +/// `(x0, y0)`, each cell `z` of its centre's x and y, or the reason it can't be made. pub fn grid( crs: Crs, (x0, y0): (f64, f64), diff --git a/crates/ui-egui/src/layoutview.rs b/crates/ui-egui/src/layoutview.rs index ae35f1a33c..40b64bba51 100644 --- a/crates/ui-egui/src/layoutview.rs +++ b/crates/ui-egui/src/layoutview.rs @@ -532,7 +532,8 @@ pub fn show(app: &mut RustGisApp, ui: &mut Ui) { }; let uv = Rect::from_min_max(src((e.x, e.y)), src((e.x + e.w, e.y + e.h))); let clip = painter.with_clip_rect(frame); - clip.rect_filled(frame, 0.0, Color32::WHITE); + // The page under it in its own colour (#2950), as a see-through frame shows once redrawn. + clip.rect_filled(frame, 0.0, layout.paper.map_or(Color32::WHITE, crate::theme::c32)); match &app.layout.pan_preview { // A pan: the frame's map with the overscan around it, moved with the pointer, so // what comes into view is map, not the page beside the frame. From c0db66efe0ee3963fadb4511b5cde8d61655722e Mon Sep 17 00:00:00 2001 From: giswqs Date: Mon, 30 Nov 2026 02:49:47 -0500 Subject: [PATCH 2/7] fix(engine): keep a legend that fits whole at full height (#1379) The fits path takes a legend whole in the room the map leaves free, as two publication tests assert; the 60% cap holds for boxes that don't. --- crates/engine/src/cmd/layout/publication/mod.rs | 8 +++++--- crates/engine/src/cmd/layout/publication/placement.rs | 5 +++-- crates/engine/src/tests.rs | 7 ++++--- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/crates/engine/src/cmd/layout/publication/mod.rs b/crates/engine/src/cmd/layout/publication/mod.rs index f48f3e0b5b..ecad83b984 100644 --- a/crates/engine/src/cmd/layout/publication/mod.rs +++ b/crates/engine/src/cmd/layout/publication/mod.rs @@ -1344,8 +1344,9 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu let card = style == Style::Modular && column.is_some(); let (card_r, card_pad) = (3.0 * k, 2.5 * k); let bar_gap = if ch > 0.0 { 2.0 } else { 0.0 }; - // Over the map the box is held to `LEGEND_MAX_FRAME` (60%) of the frame's height, except where - // a colorbar's floor (`COLORBAR_MM`, 15 mm) needs more beside tall rows: the title's lines + // Over the map the box starts held to `LEGEND_MAX_FRAME` (60%) of the frame's height (one that + // fits whole in the room the map leaves free may take more, below), except where a colorbar's + // floor (`COLORBAR_MM`, 15 mm) needs more beside tall rows: the title's lines // count only up to that, less the rows of the legend beside them: the map isn't moved, veiled // or scaled for room the box can't have, and each candidate's rows keep their height (the fit // test and the placement below). What is past it, the floor's excess too, is said as cut off. @@ -1817,7 +1818,8 @@ pub(in crate::cmd::layout) fn publication(s: &mut Session, p: &Value) -> CmdResu // One column too, when the rectangle holds what the box a legend starts with cuts. if let Some(i) = fits.filter(|i| *i > 0 || whole(sizes[0]).0 > at_most_one.0 + 1e-6 || whole(sizes[0]).1 > at_most_one.1 + 1e-6) { let (w, h) = whole(sizes[i]); - let more = arranged((w.min(wide), h.min(fh * LEGEND_MAX_FRAME))); + // Whole, however tall: the free rectangle holds it, over no drawn data (#1379). + let more = arranged((w.min(wide), h)); let new = (shown(&more.1, (w, h)), more.1.3.1); if more.1.0.is_some() && new.0 >= score.0 - 1e-6 { (legend_cols, best, score) = (i + 1, more, new); diff --git a/crates/engine/src/cmd/layout/publication/placement.rs b/crates/engine/src/cmd/layout/publication/placement.rs index 61fd1afa40..922350a0ce 100644 --- a/crates/engine/src/cmd/layout/publication/placement.rs +++ b/crates/engine/src/cmd/layout/publication/placement.rs @@ -144,8 +144,9 @@ pub(crate) fn veil_panel( /// its labels. pub(in crate::cmd::layout) const COLORBAR_MM: f64 = 15.0; -/// The most of its map frame's height a legend box over the map takes, as a share; a colorbar's -/// floor ([`COLORBAR_MM`]) beside tall rows may need more, and what is past it is said as cut off. +/// The most of its map frame's height a legend box over the map takes, as a share, unless it fits +/// whole in the room the map leaves free; a colorbar's floor ([`COLORBAR_MM`]) beside tall rows may +/// need more, and what is past it is said as cut off. pub(in crate::cmd::layout) const LEGEND_MAX_FRAME: f64 = 0.6; /// The height a publication gives its colorbar in a legend's box `ih` mm high inside, in mm, diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 736b7ec4b3..1177a0de8d 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -17704,9 +17704,10 @@ fn a_publications_colorbar_title_stays_in_the_legends_box() { let _ = std::fs::remove_dir_all(&dir); } -/// Over the map a publication's legend box is held to 60% of its frame's height, whichever way its -/// columns are chosen, a raster's 200-character name as its colorbar's title too: the title's -/// lines past that are cut (and said), the map frame left where a short name leaves it (#2638). +/// Over the map a publication's legend box that doesn't fit whole in the room the map leaves free +/// is held to 60% of its frame's height, a raster's 200-character name as its colorbar's title +/// too: the title's lines past that are cut (and said), the map frame left where a short name +/// leaves it (#2638). #[test] fn a_publications_legend_box_over_the_map_keeps_to_60_percent_of_the_frame() { let dir = std::env::temp_dir().join(format!("rustgis-legend-cap-{}", std::process::id())); From 77f9e5e653110eb6acefa03aa34873156fec24e0 Mon Sep 17 00:00:00 2001 From: giswqs Date: Mon, 30 Nov 2026 03:20:07 -0500 Subject: [PATCH 3/7] fix(engine): one notice for pole-centred frames across layouts Opening a project and map.projection say the frames of every layout in one counted notice, as AGENTS.md asks; a profile title in a transparent ink is not said cut; the outline notice counts holes with their rings. --- crates/engine/src/cmd/layout/files.rs | 36 ++++++++++++++++++----- crates/engine/src/cmd/layout/update.rs | 8 ++--- crates/engine/src/cmd/navigate.rs | 20 ++----------- crates/engine/src/cmd/view.rs | 10 +++++-- crates/engine/src/project.rs | 14 ++++----- crates/engine/src/tests.rs | 13 +++++++- crates/render/src/layout/profile.rs | 3 +- crates/render/src/layout/profile_tests.rs | 5 ++++ crates/render/src/mesh.rs | 3 +- 9 files changed, 68 insertions(+), 44 deletions(-) diff --git a/crates/engine/src/cmd/layout/files.rs b/crates/engine/src/cmd/layout/files.rs index 3da9f284e5..eed0d92d89 100644 --- a/crates/engine/src/cmd/layout/files.rs +++ b/crates/engine/src/cmd/layout/files.rs @@ -50,7 +50,7 @@ pub(crate) fn import(s: &mut Session, text: &str) -> CmdResult { // A frame centred where its map can't place the point (a pole on Web Mercator) is said (#2684). // One notice for them all, counted. let unplaced: Vec<(String, Option)> = l.elements.iter().filter_map(|e| unplaced_center(&s.project.maps, &l, e.id)).collect(); - if let Some(said) = unplaced_notice(&l.name, &unplaced) { + if let Some(said) = unplaced_notice(std::slice::from_ref(&l.name), &unplaced) { s.notify(said, false); } let name = l.name.clone(); @@ -78,10 +78,10 @@ pub(crate) fn unplaced_center(maps: &[rustgis_map::Map], l: &Layout, id: u32) -> Some((e.name.clone(), drawn)) } -/// One notice for the map frames of layout `layout` centred where their maps' projections can't -/// show them, with where each is drawn instead ([`unplaced_center`]): counted, the first five -/// named. `None` for none (#2684). -pub(crate) fn unplaced_notice(layout: &str, frames: &[(String, Option)]) -> Option { +/// One notice for the map frames of `layouts` centred where their maps' projections can't show +/// them, with where each is drawn instead ([`unplaced_center`]): counted, the first five frames +/// and the first five layouts named. `None` for none (#2684). +pub(crate) fn unplaced_notice(layouts: &[String], frames: &[(String, Option)]) -> Option { if frames.is_empty() { return None; } @@ -98,9 +98,31 @@ pub(crate) fn unplaced_notice(layout: &str, frames: &[(String, Option)]) -> if frames.len() > 5 { named.push_str(&format!(" and {} more", frames.len() - 5)); } + let mut owners = layouts.iter().take(5).map(|l| crate::project::short_name(l)).collect::>().join(", "); + if layouts.len() > 5 { + owners.push_str(&format!(" and {} more", layouts.len() - 5)); + } Some(format!( - "{}: {} map frame(s) are centred where their map's projection can't show the centre, and are drawn centred elsewhere: {named}", - crate::project::short_name(layout), + "{owners}: {} map frame(s) are centred where their map's projection can't show the centre, and are drawn centred elsewhere: {named}", frames.len() )) } + +/// The map frames of every layout centred where their map's projection can't show the centre, +/// those on the map named `only` alone when given, as one notice ([`unplaced_notice`]): what +/// opening a project and `map.projection` say (#2711). +pub(crate) fn unplaced_in_layouts(layouts: &[Layout], maps: &[rustgis_map::Map], only: Option<&str>) -> Option { + let (mut owners, mut frames) = (Vec::new(), Vec::new()); + for l in layouts { + let on_map = |e: &&rustgis_map::layout::Element| match (&e.kind, only) { + (ElementKind::MapFrame { map, .. }, Some(only)) => map.eq_ignore_ascii_case(only), + _ => true, + }; + let here: Vec<(String, Option)> = l.elements.iter().filter(on_map).filter_map(|e| unplaced_center(maps, l, e.id)).collect(); + if !here.is_empty() { + owners.push(l.name.clone()); + frames.extend(here); + } + } + unplaced_notice(&owners, &frames) +} diff --git a/crates/engine/src/cmd/layout/update.rs b/crates/engine/src/cmd/layout/update.rs index 08bd26467d..972e10d7b9 100644 --- a/crates/engine/src/cmd/layout/update.rs +++ b/crates/engine/src/cmd/layout/update.rs @@ -887,11 +887,9 @@ pub(in crate::cmd::layout) fn update(s: &mut Session, p: &Value) -> CmdResult { } // A centre the frame's map can't place (a pole on Web Mercator) is said (#2684). if new_center.is_some() || given(&["map"]) { - let said = s - .project - .layouts - .get(li) - .and_then(|l| unplaced_notice(&l.name, &unplaced_center(&s.project.maps, l, id).into_iter().collect::>())); + let said = s.project.layouts.get(li).and_then(|l| { + unplaced_notice(std::slice::from_ref(&l.name), &unplaced_center(&s.project.maps, l, id).into_iter().collect::>()) + }); if let Some(said) = said { s.notify(said, false); } diff --git a/crates/engine/src/cmd/navigate.rs b/crates/engine/src/cmd/navigate.rs index a7d96d49ab..26340b16cb 100644 --- a/crates/engine/src/cmd/navigate.rs +++ b/crates/engine/src/cmd/navigate.rs @@ -107,24 +107,10 @@ pub fn commands() -> Vec { m.set_projection(next); let out = json!({"projection": m.projection.code(), "label": m.projection.label()}); // Frames on this map now centred where its projection can't show the centre (a pole - // on Web Mercator) are drawn centred elsewhere: one counted notice a layout (#2684). + // on Web Mercator) are drawn centred elsewhere: one counted notice for them all (#2684). let name = s.map().name.clone(); - let said: Vec = s - .project - .layouts - .iter() - .filter_map(|l| { - let unplaced: Vec<(String, Option)> = l - .elements - .iter() - .filter(|e| matches!(&e.kind, ElementKind::MapFrame { map, .. } if map.eq_ignore_ascii_case(&name))) - .filter_map(|e| super::layout::unplaced_center(&s.project.maps, l, e.id)) - .collect(); - super::layout::unplaced_notice(&l.name, &unplaced) - }) - .collect(); - for n in said { - s.notify(n, false); + if let Some(said) = super::layout::unplaced_in_layouts(&s.project.layouts, &s.project.maps, Some(&name)) { + s.notify(said, false); } if s.auto_cache { super::workspace::fill_cache(s); diff --git a/crates/engine/src/cmd/view.rs b/crates/engine/src/cmd/view.rs index 3f3dabc076..6a8add974d 100644 --- a/crates/engine/src/cmd/view.rs +++ b/crates/engine/src/cmd/view.rs @@ -525,9 +525,13 @@ fn block_polygons(s: &Session, o: &serde_json::Map) -> Result Option { let (spacing, coarsened) = o.spacing(); // Rings narrower than the spacing, with no area left once thinned (#2318), and the holes of - // those outer rings, which go with them (counted among them). - let narrow = (o.narrow() > 0) - .then(|| format!("{} ring(s) of '{layer}' narrower than {spacing:.0} m, with their holes, were left out of the block", o.narrow())); + // those outer rings, which go with them: counted together. + let narrow = (o.narrow() > 0).then(|| { + format!( + "{} ring(s) of '{layer}' were left out of the block: those narrower than {spacing:.0} m and the holes of outer rings left out", + o.narrow() + ) + }); let stray = (o.stray() > 0) .then(|| format!("{} hole(s) of '{layer}' lying outside their own polygon's outer ring were left out (not cut)", o.stray())); let merged = match o.dropped() { diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 6cad8aa3ce..0bcfe86000 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1604,15 +1604,11 @@ impl Project { } let mut notices: Vec<(ReadPart, NoticeText)> = layout_notices(&self.name, when, layouts_dropped, &repairs).into_iter().map(|n| (ReadPart::Layouts, n.into())).collect(); - // A frame centred where its map's projection can't show the centre (a pole on Web - // Mercator) is drawn centred elsewhere: said once a layout, as `layout.import` says it - // (#2684). - for l in &self.layouts { - let unplaced: Vec<(String, Option)> = - l.elements.iter().filter_map(|e| crate::cmd::layout::unplaced_center(&self.maps, l, e.id)).collect(); - if let Some(said) = crate::cmd::layout::unplaced_notice(&l.name, &unplaced) { - notices.push((ReadPart::Layouts, said.into())); - } + // Frames centred where their map's projection can't show the centre (a pole on Web + // Mercator) are drawn centred elsewhere: one counted notice for them all, as + // `layout.import` says it (#2684). + if let Some(said) = crate::cmd::layout::unplaced_in_layouts(&self.layouts, &self.maps, None) { + notices.push((ReadPart::Layouts, said.into())); } let mut done = Repaired::default(); // Files skip the commands' limits, and notebooks and presentations are found (and diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 1177a0de8d..dd0739cd62 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -17844,14 +17844,25 @@ fn a_pole_centred_frame_is_said_on_open_and_on_a_projection_change() { t.run("project.open", &json!({"path": path.display().to_string()})).unwrap(); assert_eq!(told(&t, mark), said, "{projection:?}: {:?}", t.notices_since(mark)); } - // (b) A polar map switched to Web Mercator says it once; back to polar, nothing. + // (b) A polar map switched to Web Mercator says it once, for the frames of both its layouts + // together; back to polar, nothing. let mut s = Session::new(Project::default()); s.run("map.new", &json!({"name": "Mapa"})).unwrap(); s.run("map.projection", &json!({"type": "EPSG:3031"})).unwrap(); s.run("layout.import", &json!({"text": layout})).unwrap(); + s.run("layout.import", &json!({"text": layout.replace("\"name\":\"Polo\"", "\"name\":\"Polo 2\"")})).unwrap(); let mark = s.notice_mark(); s.run("map.projection", &json!({"type": "mercator"})).unwrap(); assert_eq!(told(&s, mark), 1, "{:?}", s.notices_since(mark)); + let said = s.notices_since(mark).iter().find(|n| n.text.contains("can't show")).map(|n| n.text.clone()).unwrap_or_default(); + assert!(said.starts_with("Polo, Polo 2: 2 map frame(s)"), "{said}"); + // Opened, the same: one notice for both layouts. + let path = dir.join("pole-two.rgis"); + s.run("project.saveAs", &json!({"path": path.display().to_string()})).unwrap(); + let mut t = Session::new(Project::default()); + let opened = t.notice_mark(); + t.run("project.open", &json!({"path": path.display().to_string()})).unwrap(); + assert_eq!(told(&t, opened), 1, "{:?}", t.notices_since(opened)); let mark = s.notice_mark(); s.run("map.projection", &json!({"type": "EPSG:3031"})).unwrap(); assert_eq!(told(&s, mark), 0, "{:?}", s.notices_since(mark)); diff --git a/crates/render/src/layout/profile.rs b/crates/render/src/layout/profile.rs index 148bad9af4..8c787f6505 100644 --- a/crates/render/src/layout/profile.rs +++ b/crates/render/src/layout/profile.rs @@ -529,7 +529,8 @@ pub(super) fn profile_title_fit(title: &str, [first, second]: [&str; 2], start: /// (its own notice says why: [`profile_note`]). pub(super) fn profile_title_cut(layout: &Layout, maps: &[Map], p: &Profile, r: Rect, ppp: f32) -> bool { let title = p.title.trim(); - if title.is_empty() || !p.side.is_horizontal() { + // A title in a transparent ink draws nothing to cut, as a text without ink. + if title.is_empty() || !p.side.is_horizontal() || p.color.unwrap_or(INK).a() == 0 { return false; } let Ok((samples, section)) = profile_samples(layout, maps, p) else { return false }; diff --git a/crates/render/src/layout/profile_tests.rs b/crates/render/src/layout/profile_tests.rs index a693c907c4..09b539cabf 100644 --- a/crates/render/src/layout/profile_tests.rs +++ b/crates/render/src/layout/profile_tests.rs @@ -517,4 +517,9 @@ fn a_horizontal_profiles_long_title_stops_short_of_its_second_name() { assert!(losses.iter().any(|loss| loss.id == id && loss.below_box && loss.left_out == 0), "{losses:?}"); let notice = clipped_text_notice(&l, &clipped_text(&l, &maps, 96.0, &info)).expect("said"); assert!(notice.contains("make the profile longer or its title shorter"), "{notice}"); + // In a transparent ink it draws nothing, and nothing is said cut. + if let Some(ElementKind::Profile(p)) = l.element_mut(id).map(|e| &mut e.kind) { + p.color = Some(Rgba::new(0, 0, 0, 0)); + } + assert!(text_losses(&l, &maps, 96.0, &info).is_empty(), "{:?}", text_losses(&l, &maps, 96.0, &info)); } diff --git a/crates/render/src/mesh.rs b/crates/render/src/mesh.rs index d726291e12..f1e38e7e93 100644 --- a/crates/render/src/mesh.rs +++ b/crates/render/src/mesh.rs @@ -634,7 +634,8 @@ pub(crate) fn collect_layer( // No tiles at this scale, or too many: one mesh, its origin the centre of the drawn // features' extent. None => { - // Only those `visible` keeps: the ones past it were taken for the tiles. + // Those `visible` keeps (in a band, also those whose stroke reaches into view): the + // ones past them were taken for the tiles. let shown: Vec<&crate::mesh_tiles::Feature<'_>> = features .iter() .filter(|f| visible(&f.extent) || (banded && f.reach.is_finite() && visible(&f.extent.padded(0.0, f.reach)))) From 3a86be0c4e7e21ae60210f7b43a7dffb89539f93 Mon Sep 17 00:00:00 2001 From: giswqs Date: Mon, 30 Nov 2026 03:44:53 -0500 Subject: [PATCH 4/7] perf(render): look for a band's widening strokes within 8 tiles only A tilted frame works out the symbol only of rows near its view, not of every row of the layer; a stroke whose widened reach is unbounded is taken as reaching that far. --- crates/render/src/mesh.rs | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/crates/render/src/mesh.rs b/crates/render/src/mesh.rs index f1e38e7e93..505a19055c 100644 --- a/crates/render/src/mesh.rs +++ b/crates/render/src/mesh.rs @@ -495,6 +495,11 @@ pub(crate) fn stroke_reach(g: &Geometry, s: &Symbol, wireframe: bool, ppp: f32, f64::from(tessellation_width(width_px, map_per_px)) / 2.0 + widest } +/// How many tiles past a band's tiles a stroke is looked for whose widening by depth brings it +/// back over the band's ground ([`collect_layer`]): farther ones aren't looked at, so a tilted +/// frame's cost follows the features near its view, not the whole layer. +const BAND_REACH_TILES: f64 = 8.0; + /// Collects one GPU-eligible layer, or one streamed batch of it, into Mesh/Points commands. /// `geoms`, `extents`, `rows` and `visible` are the render loop's own (geometries as the CPU /// draws them, their cached extents, row filter, extent cull), so the GPU draws exactly the @@ -541,6 +546,9 @@ pub(crate) fn collect_layer( let side = crate::mesh_tiles::tile_side(map_per_px); let near = tiling.as_ref().and_then(|t| crate::mesh_tiles::feature_area(t.area, map_per_px)); let mut farthest = 0f64; + // In a band: `near`, and the farthest past it a stroke is looked for ([`BAND_REACH_TILES`]). + let band_reach = + near.filter(|_| tiling.as_ref().is_some_and(|t| t.band.is_some())).zip(side).map(|(n, side)| (n, side * BAND_REACH_TILES)); for (row, g) in geoms.iter().enumerate() { let Some(g) = g else { continue }; // Culled on the extent the CPU path culls on (the full geometry's, cached), so both @@ -557,16 +565,18 @@ pub(crate) fn collect_layer( // In a tilted view's band, a stroke past `near` that the shader widens back over the // band's ground is taken too, its reach counted (the band is then one mesh, below): left // out, the ground near the far edge would lose its widened part. + // Only those within `BAND_REACH_TILES` tiles of `near` are looked at, so a tilted frame + // doesn't work out the symbol of every row of a large layer; a reach past that (or + // unbounded) counts as that far. let mut symbol = None; if !seen { let reaches_in = !marker - && near.is_some() && tiling.as_ref().is_some_and(|t| { - t.band.is_some() && { + t.band.is_some() && band_reach.is_some_and(|(near, most)| e.padded(0.0, most).intersects(&near)) && { let s = layer.symbol(row); let reach = t.widened(stroke_reach(g, &s, wireframe, ppp, map_per_px)); symbol = Some(s); - reach > 0.0 && reach.is_finite() && e.padded(0.0, reach).intersects(t.area) + reach > 0.0 && e.padded(0.0, band_reach.map_or(0.0, |(_, most)| reach.min(most))).intersects(t.area) } }); if !reaches_in { @@ -638,7 +648,10 @@ pub(crate) fn collect_layer( // ones past them were taken for the tiles. let shown: Vec<&crate::mesh_tiles::Feature<'_>> = features .iter() - .filter(|f| visible(&f.extent) || (banded && f.reach.is_finite() && visible(&f.extent.padded(0.0, f.reach)))) + .filter(|f| { + visible(&f.extent) + || (banded && f.reach > 0.0 && visible(&f.extent.padded(0.0, f.reach.min(side.unwrap_or(0.0) * BAND_REACH_TILES)))) + }) .collect(); let at = shown.iter().fold(marked, |e, f| e.union(&f.extent)); let origin = if at.is_empty() { [0.0, 0.0] } else { origin_for(&at, map_per_px)? }; From 1458f664fe330bee4d48cd2f3e972626aee3ee26 Mon Sep 17 00:00:00 2001 From: giswqs Date: Mon, 30 Nov 2026 04:26:58 -0500 Subject: [PATCH 5/7] fix(engine): say pole-centred frames after every projection change map.navigation planar and map.viewMode change the projection too: they say the frames now drawn centred elsewhere, as map.projection does. --- crates/engine/src/cmd/layout/files.rs | 10 ++++++++++ crates/engine/src/cmd/navigate.rs | 5 +---- crates/engine/src/cmd/view.rs | 7 ++++++- crates/engine/src/tests.rs | 16 ++++++++++++++++ 4 files changed, 33 insertions(+), 5 deletions(-) diff --git a/crates/engine/src/cmd/layout/files.rs b/crates/engine/src/cmd/layout/files.rs index eed0d92d89..8afbac4c67 100644 --- a/crates/engine/src/cmd/layout/files.rs +++ b/crates/engine/src/cmd/layout/files.rs @@ -108,6 +108,16 @@ pub(crate) fn unplaced_notice(layouts: &[String], frames: &[(String, Option )) } +/// Says the frames on the active map now centred where its projection can't show the centre, +/// after a command changed that projection (`map.projection`, `map.navigation`, `map.viewMode`): +/// one counted notice for them all (#2711). +pub(crate) fn say_unplaced_on_active_map(s: &mut Session) { + let name = s.map().name.clone(); + if let Some(said) = unplaced_in_layouts(&s.project.layouts, &s.project.maps, Some(&name)) { + s.notify(said, false); + } +} + /// The map frames of every layout centred where their map's projection can't show the centre, /// those on the map named `only` alone when given, as one notice ([`unplaced_notice`]): what /// opening a project and `map.projection` say (#2711). diff --git a/crates/engine/src/cmd/navigate.rs b/crates/engine/src/cmd/navigate.rs index 26340b16cb..f09143c4a7 100644 --- a/crates/engine/src/cmd/navigate.rs +++ b/crates/engine/src/cmd/navigate.rs @@ -108,10 +108,7 @@ pub fn commands() -> Vec { let out = json!({"projection": m.projection.code(), "label": m.projection.label()}); // Frames on this map now centred where its projection can't show the centre (a pole // on Web Mercator) are drawn centred elsewhere: one counted notice for them all (#2684). - let name = s.map().name.clone(); - if let Some(said) = super::layout::unplaced_in_layouts(&s.project.layouts, &s.project.maps, Some(&name)) { - s.notify(said, false); - } + super::layout::say_unplaced_on_active_map(s); if s.auto_cache { super::workspace::fill_cache(s); } diff --git a/crates/engine/src/cmd/view.rs b/crates/engine/src/cmd/view.rs index 6a8add974d..d15d531bd5 100644 --- a/crates/engine/src/cmd/view.rs +++ b/crates/engine/src/cmd/view.rs @@ -87,6 +87,8 @@ pub fn commands() -> Vec { // Planar navigation is on a flat map. if !fp && m.projection.is_globe() { m.set_projection(rustgis_map::Projection::WebMercator); + // Frames on a pole the flat map can't show are said (#2711). + super::layout::say_unplaced_on_active_map(s); } Ok(json!({"mode": if fp { "firstPerson" } else { "planar" }})) }).roles(&[]).effects(crate::policy::Effects::NONE) @@ -102,7 +104,10 @@ pub fn commands() -> Vec { }; let m = s.map_mut(); m.set_projection(next); - Ok(json!({"projection": m.projection.code(), "label": m.projection.label()})) + let out = json!({"projection": m.projection.code(), "label": m.projection.label()}); + // Frames centred where the new projection can't show the centre are said (#2711). + super::layout::say_unplaced_on_active_map(s); + Ok(out) }).roles(&[]).effects(crate::policy::Effects::NONE) .params(r#"{"mode": "global" (a globe)|"local" (a flat view centred here)}"#), C::new("map.walk", "Walk", "Home › Navigate", walk).roles(&[]).effects(crate::policy::Effects::NONE).view().params(r#"{"forward"?: steps, "right"?: steps, "up"?: steps (first-person navigation)}"#), diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index dd0739cd62..ffea91a845 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -17866,6 +17866,22 @@ fn a_pole_centred_frame_is_said_on_open_and_on_a_projection_change() { let mark = s.notice_mark(); s.run("map.projection", &json!({"type": "EPSG:3031"})).unwrap(); assert_eq!(told(&s, mark), 0, "{:?}", s.notices_since(mark)); + // (c) A globe made flat by `map.navigation` planar says it too, and so does `map.viewMode` + // local, a flat view that can't show the pole either. + s.run("map.projection", &json!({"type": "globe"})).unwrap(); + let mark = s.notice_mark(); + s.run("map.navigation", &json!({"mode": "planar"})).unwrap(); + assert_eq!(told(&s, mark), 1, "{:?}", s.notices_since(mark)); + s.run("map.projection", &json!({"type": "globe"})).unwrap(); + let mark = s.notice_mark(); + s.run("map.viewMode", &json!({"mode": "local"})).unwrap(); + let local = s.map().projection.code(); + let placed = s + .project + .layouts + .iter() + .all(|l| l.elements.iter().all(|e| crate::cmd::layout::unplaced_center(&s.project.maps, l, e.id).is_none())); + assert_eq!(told(&s, mark), usize::from(!placed), "{local}: {:?}", s.notices_since(mark)); let _ = std::fs::remove_dir_all(&dir); } From 86f1e92598d653ad2273a45d035896ef1e92305f Mon Sep 17 00:00:00 2001 From: giswqs Date: Mon, 30 Nov 2026 05:33:25 -0500 Subject: [PATCH 6/7] fix(engine): say pole-centred frames on open and on a real change only The notice moved from every project repair to opening, and the projection commands say it only when the projection changed. The band reach limit is documented where strokes past it are left out. --- crates/engine/src/cmd/navigate.rs | 6 +++++- crates/engine/src/cmd/view.rs | 8 ++++++-- crates/engine/src/project.rs | 13 +++++++------ crates/engine/src/tests.rs | 11 +++++++++++ crates/render/src/lib.rs | 2 ++ crates/render/src/mesh.rs | 7 +++++-- 6 files changed, 36 insertions(+), 11 deletions(-) diff --git a/crates/engine/src/cmd/navigate.rs b/crates/engine/src/cmd/navigate.rs index f09143c4a7..cc6569d74f 100644 --- a/crates/engine/src/cmd/navigate.rs +++ b/crates/engine/src/cmd/navigate.rs @@ -95,6 +95,7 @@ pub fn commands() -> Vec { } } let m = s.map_mut(); + let before = m.projection.code(); let next = if given.is_empty() { match ps(p, "type") { Some(t) => Projection::from_code(t)?, @@ -108,7 +109,10 @@ pub fn commands() -> Vec { let out = json!({"projection": m.projection.code(), "label": m.projection.label()}); // Frames on this map now centred where its projection can't show the centre (a pole // on Web Mercator) are drawn centred elsewhere: one counted notice for them all (#2684). - super::layout::say_unplaced_on_active_map(s); + // Said only when the projection changed: setting it again changes no frame. + if out["projection"].as_str() != Some(before.as_str()) { + super::layout::say_unplaced_on_active_map(s); + } if s.auto_cache { super::workspace::fill_cache(s); } diff --git a/crates/engine/src/cmd/view.rs b/crates/engine/src/cmd/view.rs index d15d531bd5..9741b89215 100644 --- a/crates/engine/src/cmd/view.rs +++ b/crates/engine/src/cmd/view.rs @@ -103,10 +103,14 @@ pub fn commands() -> Vec { m => return Err(format!("unknown view '{m}'")), }; let m = s.map_mut(); + let before = m.projection.code(); m.set_projection(next); let out = json!({"projection": m.projection.code(), "label": m.projection.label()}); - // Frames centred where the new projection can't show the centre are said (#2711). - super::layout::say_unplaced_on_active_map(s); + // Frames centred where the new projection can't show the centre are said (#2711), + // when it changed. + if out["projection"].as_str() != Some(before.as_str()) { + super::layout::say_unplaced_on_active_map(s); + } Ok(out) }).roles(&[]).effects(crate::policy::Effects::NONE) .params(r#"{"mode": "global" (a globe)|"local" (a flat view centred here)}"#), diff --git a/crates/engine/src/project.rs b/crates/engine/src/project.rs index 48bdabb3f6..bd0eaa0550 100644 --- a/crates/engine/src/project.rs +++ b/crates/engine/src/project.rs @@ -1562,6 +1562,13 @@ impl Project { /// with the part of the project it is about. pub(crate) fn normalize_opened(&mut self) -> Vec<(ReadPart, NoticeText)> { let mut notices = self.repair(true, "while opening the project"); + // Frames centred where their map's projection can't show the centre (a pole on Web + // Mercator) are drawn centred elsewhere: one counted notice for them all, as + // `layout.import` says it (#2684). Said as the project opens only, not on each later + // repair (a map imported, a layer file added), which leaves the layouts as they were. + if let Some(said) = crate::cmd::layout::unplaced_in_layouts(&self.layouts, &self.maps, None) { + notices.push((ReadPart::Layouts, said.into())); + } // Pages naming a map the project doesn't have are drawn over the active map (#3191). use crate::cmd::presentation::{PagesOf, pages_without_their_map}; notices.extend(pages_without_their_map(self, PagesOf::All).map(|notice| (ReadPart::Items, notice))); @@ -1606,12 +1613,6 @@ impl Project { } let mut notices: Vec<(ReadPart, NoticeText)> = layout_notices(&self.name, when, layouts_dropped, &repairs).into_iter().map(|n| (ReadPart::Layouts, n.into())).collect(); - // Frames centred where their map's projection can't show the centre (a pole on Web - // Mercator) are drawn centred elsewhere: one counted notice for them all, as - // `layout.import` says it (#2684). - if let Some(said) = crate::cmd::layout::unplaced_in_layouts(&self.layouts, &self.maps, None) { - notices.push((ReadPart::Layouts, said.into())); - } let mut done = Repaired::default(); // Files skip the commands' limits, and notebooks and presentations are found (and // notebooks trusted) by name, so names are made unique. diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 4f1163f9aa..f464dc4166 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -17958,6 +17958,17 @@ fn a_pole_centred_frame_is_said_on_open_and_on_a_projection_change() { let mark = s.notice_mark(); s.run("map.projection", &json!({"type": "mercator"})).unwrap(); assert_eq!(told(&s, mark), 1, "{:?}", s.notices_since(mark)); + // Set again, or a layer file added (a later repair), nothing new is said. + let again = s.notice_mark(); + s.run("map.projection", &json!({"type": "mercator"})).unwrap(); + let pts = dir.join("pts.geojson"); + std::fs::write( + &pts, + r#"{"type":"FeatureCollection","features":[{"type":"Feature","properties":{},"geometry":{"type":"Point","coordinates":[0,0]}}]}"#, + ) + .unwrap(); + s.run("layer.addData", &json!({"path": pts.display().to_string()})).unwrap(); + assert_eq!(told(&s, again), 0, "{:?}", s.notices_since(again)); let said = s.notices_since(mark).iter().find(|n| n.text.contains("can't show")).map(|n| n.text.clone()).unwrap_or_default(); assert!(said.starts_with("Polo, Polo 2: 2 map frame(s)"), "{said}"); assert!(said.contains("'Mapa' in 'Polo' at latitude -85") && said.contains("'Mapa' in 'Polo 2' at latitude -85"), "{said}"); diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index bbf123c6ca..fad01b84bc 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -12090,6 +12090,8 @@ mod tests { l.renderer = rustgis_map::Renderer::Single(wide); } let Some(RenderOutput::Gpu(scene)) = render_backend(&mut m, &view, Backend::Gpu) else { panic!("a GPU scene") }; + // The view is one band, so every mesh is that band's. + assert_eq!(bands.len(), 1, "{:?}", bands.iter().map(|b| b.depth).collect::>()); let first = scene.cmds.iter().find_map(|c| match c { gpu_scene::DrawCmd::Mesh { square, .. } => Some(square.is_none()), _ => None, diff --git a/crates/render/src/mesh.rs b/crates/render/src/mesh.rs index 685a0d4f4a..1bd5919607 100644 --- a/crates/render/src/mesh.rs +++ b/crates/render/src/mesh.rs @@ -497,7 +497,8 @@ pub(crate) fn stroke_reach(g: &Geometry, s: &Symbol, wireframe: bool, ppp: f32, /// How many tiles past a band's tiles a stroke is looked for whose widening by depth brings it /// back over the band's ground ([`collect_layer`]): farther ones aren't looked at, so a tilted -/// frame's cost follows the features near its view, not the whole layer. +/// frame's cost follows the features near its view, not the whole layer. A stroke farther than +/// this whose widened reach would still come back over the ground is not drawn on that band. const BAND_REACH_TILES: f64 = 8.0; /// How far any line or polygon of `layer` reaches on a tilted view's band (`tiling`), its widest @@ -605,7 +606,9 @@ pub(crate) fn collect_layer( // out, the ground near the far edge would lose its widened part. // Only those within `BAND_REACH_TILES` tiles of `near` are looked at, so a tilted frame // doesn't work out the symbol of every row of a large layer; a reach past that (or - // unbounded) counts as that far. + // unbounded) counts as that far. A stroke farther out than that whose widening would + // still reach the band's ground isn't drawn on it: a known limit, for a stroke widened + // past 8 tiles, which only a very wide stroke at a steep pitch is. let mut symbol = None; if !seen { let reaches_in = !marker From 46fb8ddb5a0ba8a140f46b462d6dab033f92cfa4 Mon Sep 17 00:00:00 2001 From: giswqs Date: Mon, 30 Nov 2026 06:30:13 -0500 Subject: [PATCH 7/7] docs(render): give the label budget's sentence its verb --- crates/render/src/frame_cache.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/crates/render/src/frame_cache.rs b/crates/render/src/frame_cache.rs index 250a021ddc..f12dcef4c7 100644 --- a/crates/render/src/frame_cache.rs +++ b/crates/render/src/frame_cache.rs @@ -61,7 +61,7 @@ const SPRITE_PIXELS: u64 = crate::MAX_SPRITES as u64 * (2 * crate::MAX_SPRITE_RE /// The most bytes of label candidates a view keeps for its layers together, by /// [`Candidate::bytes`], what they hold beside them included (text, glyphs curved along a line, -/// places to try): about 20,000 point labels, each its `Candidate` and the places around it. A +/// places to try): about 20,000 point labels, each taking its `Candidate` and the places around it. A /// layer whose candidates would go past it works them out in every frame. A frame copies no more /// than this either, its layers bottom first. pub(crate) const MAX_LABEL_BYTES: usize = 16 << 20;