Skip to content
15 changes: 7 additions & 8 deletions crates/data/src/source/shp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,9 +292,10 @@ 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`],
/// [`FeatureSource::visit_ids_chunks`]). Only a whole read looks at the stored boxes.
/// A complete visit of a request's records, or of those numbered `numbered` (from 0, given
/// in any order and each visited once, 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,
req: &Request,
Expand Down Expand Up @@ -335,8 +336,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)?;
Expand Down Expand Up @@ -382,9 +382,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(());
Expand Down
5 changes: 4 additions & 1 deletion crates/engine/src/cmd/design/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,12 @@ fn nearest_edge(s: &mut Session, from: Coord, to: Coord, px: f64, only: Option<u
let id = l.id;
let drawn = l.drawn_rows(scale);
l.projected_in(&flat, &key);
// The boxes `projected_in` keeps, row for row: no walk over every shape's vertices on
// each pointer move.
let boxes = l.projected_extents();
for (row, g) in l.projected_cache().iter().enumerate() {
let Some(g) = g.as_ref().filter(|_| drawn.get(row) == Some(&true)) else { continue };
let e = g.extent().padded(0.0, tol);
let e = boxes.get(row).copied().unwrap_or_else(|| g.extent()).padded(0.0, tol);
if !e.contains(a) || !e.contains(b) {
continue;
}
Expand Down
10 changes: 6 additions & 4 deletions crates/engine/src/cmd/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8634,10 +8634,12 @@ fn order_classes(s: &mut Session, p: &Value) -> CmdResult {
_ => Vec::new(),
};
if !missing.is_empty() {
s.notify(
format!("No class with the value(s) {}; skipped", missing.iter().map(|v| format!("'{v}'")).collect::<Vec<_>>().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::<Vec<_>>().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}))
}
Expand Down
67 changes: 55 additions & 12 deletions crates/engine/src/cmd/layout/files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ 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<f64>)> = l.elements.iter().filter_map(|e| unplaced_center(s, &l, e.id)).collect();
if let Some(said) = unplaced_notice(&l.name, &unplaced) {
let unplaced: Vec<(Option<String>, String, Option<f64>)> =
l.elements.iter().filter_map(|e| unplaced_center(&s.project.maps, &l, e.id)).map(|(name, lat)| (None, name, lat)).collect();
if let Some(said) = unplaced_notice(std::slice::from_ref(&l.name), &unplaced) {
s.notify(said, false);
}
let name = l.name.clone();
Expand All @@ -65,11 +66,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<f64>)> {
/// `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<f64>)> {
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;
}
Expand All @@ -78,10 +79,13 @@ pub(in crate::cmd::layout) fn unplaced_center(s: &Session, 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(in crate::cmd::layout) fn unplaced_notice(layout: &str, frames: &[(String, Option<f64>)]) -> Option<String> {
/// 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).
///
/// Each frame is `(its layout, when named with it, its name, latitude)`: frames of several layouts
/// say which layout each is in.
pub(crate) fn unplaced_notice(layouts: &[String], frames: &[(Option<String>, String, Option<f64>)]) -> Option<String> {
if frames.is_empty() {
return None;
}
Expand All @@ -92,15 +96,54 @@ pub(in crate::cmd::layout) fn unplaced_notice(layout: &str, frames: &[(String, O
let mut named = frames
.iter()
.take(5)
.map(|(name, lat)| format!("'{}' at {}", crate::project::short_name(name), at(lat)))
.map(|(layout, name, lat)| match layout {
Some(l) => format!("'{}' in '{}' at {}", crate::project::short_name(name), crate::project::short_name(l), at(lat)),
None => format!("'{}' at {}", crate::project::short_name(name), at(lat)),
})
.collect::<Vec<_>>()
.join(", ");
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::<Vec<_>>().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()
))
}

/// 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).
pub(crate) fn unplaced_in_layouts(layouts: &[Layout], maps: &[rustgis_map::Map], only: Option<&str>) -> Option<String> {
let (mut owners, mut frames): (Vec<String>, Vec<(Option<String>, String, Option<f64>)>) = (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<f64>)> = 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.into_iter().map(|(name, lat)| (Some(l.name.clone()), name, lat)));
}
}
// One layout's frames need no layout beside each.
if owners.len() == 1 {
frames.iter_mut().for_each(|f| f.0 = None);
}
unplaced_notice(&owners, &frames)
}
8 changes: 3 additions & 5 deletions crates/engine/src/cmd/layout/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down Expand Up @@ -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) {
Expand Down
20 changes: 11 additions & 9 deletions crates/engine/src/cmd/layout/publication/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1344,19 +1344,20 @@ 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 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.
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);
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
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
Expand Down Expand Up @@ -1678,7 +1679,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));
}
}
}
Expand Down Expand Up @@ -1817,6 +1818,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]);
// 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 {
Expand All @@ -1828,7 +1830,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);
Expand Down
5 changes: 5 additions & 0 deletions crates/engine/src/cmd/layout/publication/placement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,11 @@ 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, 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,
/// 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
Expand Down
8 changes: 6 additions & 2 deletions crates/engine/src/cmd/layout/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -927,8 +927,12 @@ 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::<Vec<_>>()));
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).map(|(n, lat)| (None, n, lat)).into_iter().collect::<Vec<_>>(),
)
});
if let Some(said) = said {
s.notify(said, false);
}
Expand Down
7 changes: 7 additions & 0 deletions crates/engine/src/cmd/navigate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ pub fn commands() -> Vec<C> {
}
}
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)?,
Expand All @@ -106,6 +107,12 @@ pub fn commands() -> Vec<C> {
};
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 for them all (#2684).
// 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);
}
Expand Down
9 changes: 2 additions & 7 deletions crates/engine/src/cmd/raster.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, String> {
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<Vec<u8>>, page: Option<&str>, place: bool) -> Result<Raster, String> {
raster::read_shared_page(name, bytes, page, place).map_err(|e| format!("{name}: {e}"))
Expand Down
Loading
Loading