diff --git a/crates/engine/src/cmd/search.rs b/crates/engine/src/cmd/search.rs index 777ad4f5bf..cf838e4181 100644 --- a/crates/engine/src/cmd/search.rs +++ b/crates/engine/src/cmd/search.rs @@ -721,6 +721,9 @@ mod tests { ("38Z 444141 3684706", GridError::Polar), ("38ZMB4414084706", GridError::Polar), ("99X 1 2", GridError::Zone), + // A bad zone is judged before a polar or unknown band. + ("0AAA", GridError::Zone), + ("61AVE", GridError::Zone), ("33U 1000000 5523456", GridError::OutsideZone), ] { assert_eq!(read_grid_reference(q), Err(why), "{q}"); diff --git a/crates/engine/src/cmd/share.rs b/crates/engine/src/cmd/share.rs index 85be749aa3..805d33a484 100644 --- a/crates/engine/src/cmd/share.rs +++ b/crates/engine/src/cmd/share.rs @@ -327,9 +327,14 @@ pub fn map_pdf(s: &mut Session, dpi: f64) -> Result, String> { let (w, h) = (mm(view.width), mm(view.height)); let page = if drawing.overflowed() { // Too large for vectors: the map as one picture, as it is drawn on screen. - super::layout::pictured_notices(s, &[], &[1]); let png = rustgis_render::render_png(s.map_mut(), &view)?; let pm = rustgis_render::decode_png(&png).ok_or("could not draw the map")?; + // Said once the picture is drawn. The budget counts the drawing's pictures (rasters, + // tiles) as well as its shapes. + let (mb, items) = (rustgis_render::vector::MAX_COST >> 20, rustgis_render::vector::MAX_ITEMS / 1_000_000); + s.warn(format!( + "The map is drawn as one picture, not vectors: kept as vectors, it would pass the drawing limit ({mb} MB or {items} million items)" + )); rustgis_render::pdf::Page::new(&pm, w, h) } else { rustgis_render::pdf::Page::drawing(drawing, w, h) diff --git a/crates/engine/src/cmd/stac.rs b/crates/engine/src/cmd/stac.rs index a8b1edc58e..8481224ece 100644 --- a/crates/engine/src/cmd/stac.rs +++ b/crates/engine/src/cmd/stac.rs @@ -250,6 +250,9 @@ fn add_asset(s: &mut Session, p: &Value) -> CmdResult { let p = bound.as_ref(); let i = item(p)?; let (key, href) = i.asset_href(ps(p, "asset"))?; + // Codes for a failed retrieval (JAXA Earth's `dn.error`), which a data cube skips but a + // single file draws as values: of the asset `asset_href` picked, by the same selector. + let codes = i.pick(ps(p, "asset")).ok().map(|a| (a.invalid.clone(), a.codes_unread)).unwrap_or_default(); let name = ps(p, "name").map(str::trim).filter(|n| !n.is_empty()).map(str::to_string).unwrap_or_else(|| format!("{} {key}", i.id)); // A Planetary Computer asset is read with its storage container's token. #[cfg(not(target_arch = "wasm32"))] @@ -258,7 +261,27 @@ fn add_asset(s: &mut Session, p: &Value) -> CmdResult { if let Some(connection) = p.get("connection") { add["connection"] = connection.clone(); } - super::layer::add_url(s, &add) + let added = super::layer::add_url(s, &add)?; + match codes { + (_, true) => s.warn(format!( + "{name}: its metadata's codes for a failed retrieval (je:rasters dn.error) couldn't be read whole (not a list of numbers, or too many), so the map draws any such codes in the file as values" + )), + (invalid, false) if !invalid.is_empty() => { + // The first few, large ones (a float's lowest, -3.4e38) in exponent form. + const SHOWN: usize = 5; + let code = |v: &f64| if v.abs() >= 1e6 { format!("{v:e}") } else { v.to_string() }; + let mut listed = invalid.iter().take(SHOWN).map(code).collect::>().join(", "); + if invalid.len() > SHOWN { + listed.push_str(&format!(" and {} more", invalid.len() - SHOWN)); + } + s.warn(format!( + "{name}: its metadata marks failed retrievals with {} code(s) ({listed}), which the map draws as values", + invalid.len() + )); + } + _ => {} + } + Ok(added) } /// The most items a data cube on the time slider takes (its search is paged up to this). diff --git a/crates/engine/src/service_logins.rs b/crates/engine/src/service_logins.rs index 6a86ede41f..5301a7172c 100644 --- a/crates/engine/src/service_logins.rs +++ b/crates/engine/src/service_logins.rs @@ -46,6 +46,8 @@ pub const NOT_THIS_SESSION: &str = "This request's login does not belong to this pub const CHOOSE_CONNECTION: &str = "Several saved connections match this address. Choose a connection explicitly."; /// A `connection` that is not a saved web-service connection's id. pub const NO_SUCH_CONNECTION: &str = "No saved web-service connection with this id."; +/// A request's `connection` that isn't text. +pub const CONNECTION_TEXT: &str = "connection must be a saved web-service connection id (text)"; /// The commands that add layers from a service, and so may record the connection they came from /// (their `connection` parameter, or the connection whose login their address is read with). pub const ADD_COMMANDS: &[&str] = &[ @@ -364,7 +366,7 @@ pub fn request_params<'a>(s: &mut Session, p: &'a Value) -> Result None, Some(Value::String(id)) if id.trim().is_empty() => None, Some(Value::String(id)) => Some(id.as_str()), - Some(_) => return Err("connection is a saved web-service connection id.".into()), + Some(_) => return Err(CONNECTION_TEXT.into()), }; if id.is_none() && (s.web_logins.anonymous || p.get("anonymous").and_then(Value::as_bool) == Some(true)) { // An address bound to a login is no authority for it here either. @@ -801,16 +803,10 @@ fn named(s: &Session, params: &Value) -> Result, String> { None | Some(Value::Null) => Ok(None), Some(Value::String(id)) if id.trim().is_empty() => Ok(None), Some(Value::String(id)) => { - let c = s - .connections - .connections - .iter() - .find(|c| &c.id == id) - .filter(|c| is_service(c)) - .ok_or("connection is the id of a saved web-service connection (connection.list)")?; + let c = s.connections.connections.iter().find(|c| &c.id == id).filter(|c| is_service(c)).ok_or(NO_SUCH_CONNECTION)?; Ok(Some(c.clone())) } - Some(_) => Err("connection is the id of a saved web-service connection (connection.list)".into()), + Some(_) => Err(CONNECTION_TEXT.into()), } } diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index cd31710330..bf8309f290 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -15961,6 +15961,62 @@ fn stac_search_and_assets() { assert!(s.run("stac.addAsset", &json!({"item": {"type": "Feature", "id": "x", "assets": {}}})).is_err()); } +/// A single STAC asset whose metadata names codes for a failed retrieval (JAXA Earth's +/// `je:rasters` `dn.error`) draws them as values, and says so; an asset without them says nothing. +#[test] +fn a_stac_asset_with_retrieval_codes_says_they_draw_as_values() { + let item = |id: &str, extra: &str| { + format!( + r#"{{"type": "Feature", "id": "{id}", "collection": "c", "bbox": [7, 46, 8, 47], "geometry": null, + "properties": {{"datetime": "2024-06-02T10:30:00Z"}}, + "assets": {{"places": {{"href": "{{base}}/data/places.geojson", "type": "application/geo+json", "roles": ["data"]{extra}}}}}}}"# + ) + }; + let geojson = r#"{"type": "FeatureCollection", "features": [{"type": "Feature", "properties": {"n": 1}, "geometry": {"type": "Point", "coordinates": [7.5, 46.5]}}]}"#; + let base = serve_routes( + vec![ + ("/items/clean", item("clean", "")), + ("/items/coded", item("coded", r#", "je:rasters": {"dn": {"error": [5.0, 7.0]}}"#)), + ("/items/unread", item("unread", r#", "je:rasters": {"dn": {"error": [5.0, "x"]}}"#)), + ("/data/places.geojson", geojson.to_string()), + ], + 6, + ); + let mut s = Session::new(Project::default()); + let mark = s.notice_mark(); + s.run("stac.addAsset", &json!({"url": format!("{base}/items/clean"), "name": "Clean"})).unwrap(); + let said: Vec = s.notices_since(mark).iter().map(|n| n.text.clone()).collect(); + assert!(!said.iter().any(|t| t.contains("failed retrieval")), "clean input tells nothing: {said:?}"); + let mark = s.notice_mark(); + s.run("stac.addAsset", &json!({"url": format!("{base}/items/coded"), "name": "Coded"})).unwrap(); + let said: Vec = s.notices_since(mark).iter().map(|n| n.text.clone()).collect(); + assert!(said.iter().any(|t| t.contains("Coded: its metadata marks failed retrievals with 2 code(s) (5, 7)")), "{said:?}"); + // Codes that can't be read whole (a word among them) say so. + let mark = s.notice_mark(); + s.run("stac.addAsset", &json!({"url": format!("{base}/items/unread"), "name": "Unread"})).unwrap(); + let said: Vec = s.notices_since(mark).iter().map(|n| n.text.clone()).collect(); + assert!( + said.iter().any(|t| t.contains("Unread: its metadata's codes for a failed retrieval (je:rasters dn.error) couldn't be read whole")), + "{said:?}" + ); +} + +/// The Print Map PDF keeps a map within the vector budget as vectors and says nothing, a +/// colour-vision view too (exports don't simulate it, so it needn't be a picture). +#[test] +fn the_map_pdf_keeps_vectors_and_says_nothing_with_or_without_colour_vision() { + let mut s = Session::new(crate::sample::world_project()); + for mode in ["normal", "deuteranopia"] { + s.run("map.colorVision", &json!({"mode": mode})).unwrap(); + let mark = s.notice_mark(); + let pdf = crate::cmd::share::map_pdf(&mut s, 96.0).unwrap(); + let said: Vec = s.notices_since(mark).iter().map(|n| n.text.clone()).collect(); + assert!(!said.iter().any(|t| t.contains("one picture")), "{mode}: {said:?}"); + let text = String::from_utf8_lossy(&pdf); + assert!(!text.contains("/Subtype /Image"), "{mode}: the map as vectors, not a picture"); + } +} + /// Directions through a routing server of one's own (a local Valhalla answer here): the route /// and its steps as layers; the app's answer can be passed in instead, and nothing is fetched. #[test] diff --git a/crates/geom/src/lib.rs b/crates/geom/src/lib.rs index 5dc15faa19..11587ed871 100644 --- a/crates/geom/src/lib.rs +++ b/crates/geom/src/lib.rs @@ -36,8 +36,9 @@ pub const MERCATOR_R: f64 = 6_378_137.0; /// Latitude limit of Web Mercator. pub const MAX_LAT: f64 = 85.051_128_78; /// How near ±90° (degrees) a latitude counts as the pole: about a centimeter, more than geometry -/// operations' rounding moves a pole vertex (around 1e-8°). For the polar edits and the features -/// meeting at a pole that build on this (#1033); here only the tests use it. +/// operations' rounding moves a pole vertex (around 1e-8°). The engine's polar edits +/// (`cmd/design.rs`) and analysis's topology, conversion and network code use it to find the +/// features meeting at a pole (#1033). pub const POLE_TOLERANCE: f64 = 1e-7; /// Screen pixel size assumed when converting resolution to a map scale (0.28 mm, OGC). pub const PIXEL_M: f64 = 0.000_28; diff --git a/crates/geom/src/utm.rs b/crates/geom/src/utm.rs index 36bc4dac40..7633884da8 100644 --- a/crates/geom/src/utm.rs +++ b/crates/geom/src/utm.rs @@ -585,6 +585,10 @@ pub fn parse_mgrs(text: &str) -> Result { } _ => return Err(GridError::Digits), }; + // The zone first, as `parse_utm` does: `0AAA` names a bad zone, not a polar reference. + if !(1..=60).contains(&zone) { + return Err(GridError::Zone); + } let band = band_letter(band)?; let [column, row] = letters; let digit = |s: &str| if s.is_empty() { Ok(0) } else { s.parse::().map_err(|_| GridError::Digits) }; @@ -976,6 +980,8 @@ mod tests { ("123SMB", GridError::Syntax), ("0SMB", GridError::Zone), ("61SMB", GridError::Zone), + ("0AAA", GridError::Zone), + ("61AVE", GridError::Zone), // The zone is judged once the text is written as a reference: a number past 60 // before a word is ordinary text. ("75 Main St", GridError::Syntax), diff --git a/crates/map/src/projection.rs b/crates/map/src/projection.rs index 8e18326b5d..cb236e3c48 100644 --- a/crates/map/src/projection.rs +++ b/crates/map/src/projection.rs @@ -1228,8 +1228,9 @@ mod tests { assert!(e.contains("labrd"), "{e}"); // proj4rs 0.3 added Cassini, the polyconic, Equal Earth and the oblique Mercator: their // codes are accepted (EPSG:5880's polyconic, whose refusal was #208), and draw where PROJ - // does: 54°W 10°S lands at (5 000 000, 8 894 145.167) in pyproj 3.8.0's EPSG:5880, its - // false easting less a million-odd metres. + // does: 54°W 10°S lands at (5 000 000, 8 894 145.167) in pyproj 3.8.0's EPSG:5880. On the + // central meridian x is the false easting itself; y is the false northing (10 000 000) + // less a million-odd metres. for ok in ["EPSG:5880", "EPSG:2057", "EPSG:3068", "EPSG:8858"] { crate::Projection::from_code(ok).unwrap_or_else(|e| panic!("{ok}: {e}")); } diff --git a/crates/render/src/canvas.rs b/crates/render/src/canvas.rs index 0d22ee871b..9e2a75be57 100644 --- a/crates/render/src/canvas.rs +++ b/crates/render/src/canvas.rs @@ -241,7 +241,16 @@ impl Canvas { pub fn place(&mut self, child: Canvas, transform: Transform, opacity: f32, blend: Blend, clip: Option) { if self.rec.is_none() || !child.is_recording() { let paint = PixmapPaint { opacity, blend_mode: crate::blend_mode(blend), quality: tiny_skia::FilterQuality::Bilinear }; - self.pixels().draw_pixmap(0, 0, child.pm.as_ref(), &paint, transform, None); + // Cut to `clip` as the recording is: a mask the size of these pixels. + let mask = match &clip { + Some(c) => { + let Some(mut m) = Mask::new(self.pm.width(), self.pm.height()) else { return }; + m.fill_path(&c.path, c.rule, true, c.transform); + Some(m) + } + None => None, + }; + self.pixels().draw_pixmap(0, 0, child.pm.as_ref(), &paint, transform, mask.as_ref()); return; } let Some(drawing) = child.into_drawing() else { return }; @@ -394,6 +403,41 @@ mod tests { assert!(stroke.width == 2.0 && path.segments().filter(|s| matches!(s, tiny_skia::PathSegment::MoveTo(_))).count() == 10); } + #[test] + fn placing_pixels_keeps_inside_the_clip() { + let mut c = Canvas::new(40, 20).unwrap(); + let mut child = c.sub(40, 20).unwrap(); + child.pixels().fill(Color::from_rgba8(200, 0, 0, 255)); + let clip = Clip { + path: PathBuilder::from_rect(Rect::from_xywh(0.0, 0.0, 20.0, 20.0).unwrap()), + rule: FillRule::Winding, + transform: Transform::identity(), + }; + c.place(child, Transform::identity(), 1.0, Blend::Normal, Some(clip)); + let pm = c.into_pixmap(); + assert_eq!(pm.pixel(5, 10).map(|p| p.alpha()), Some(255), "inside the clip"); + assert_eq!(pm.pixel(30, 10).map(|p| p.alpha()), Some(0), "outside the clip"); + } + + #[test] + fn placing_pixels_cuts_to_the_clip_where_its_own_transform_puts_it() { + let mut c = Canvas::new(40, 20).unwrap(); + let mut child = c.sub(10, 20).unwrap(); + child.pixels().fill(Color::from_rgba8(200, 0, 0, 255)); + // The clip covers x 20 to 30, the child x 15 to 25: only 20 to 25 is drawn. + let clip = Clip { + path: PathBuilder::from_rect(Rect::from_xywh(0.0, 0.0, 10.0, 20.0).unwrap()), + rule: FillRule::Winding, + transform: Transform::from_translate(20.0, 0.0), + }; + c.place(child, Transform::from_translate(15.0, 0.0), 1.0, Blend::Normal, Some(clip)); + let pm = c.into_pixmap(); + let alpha = |x| pm.pixel(x, 10).map(|p| p.alpha()); + assert_eq!(alpha(22), Some(255), "the child inside the clip"); + assert_eq!(alpha(17), Some(0), "the child outside the clip"); + assert_eq!(alpha(27), Some(0), "the clip past the child"); + } + #[test] fn a_label_keeps_its_halo_as_a_shape_and_its_text_once() { let label = crate::PlacedLabel { diff --git a/crates/render/src/lib.rs b/crates/render/src/lib.rs index a9059418e5..109411dde1 100644 --- a/crates/render/src/lib.rs +++ b/crates/render/src/lib.rs @@ -3159,9 +3159,14 @@ fn render_frame( record: bool, ) -> Option { let (w, h) = view.pixel_size(); - // Kept as vectors (`record`) on the CPU, for a flat frame without view effects (a pixel - // filter over the whole frame); anything else draws its pixels. - let record = record && !backend.is_gpu() && !map.projection.is_globe() && map.view.effects.is_none(); + // Kept as vectors (`record`) on the CPU, for a flat frame without view effects or a + // colour-vision simulation it applies (pixel filters over the whole frame; an export, + // `full_res_rasters`, never simulates colour vision); anything else draws its pixels. + let record = record + && !backend.is_gpu() + && !map.projection.is_globe() + && map.view.effects.is_none() + && (full_res_rasters || map.view.color_vision == rustgis_map::view::ColorVision::Normal); let mut pm = if record { Canvas::recording(w, h)? } else { Canvas::new(w, h)? }; // Streamed layers read the view: in the background for the screen, in place for an export // (the full-resolution render), which waits for them; only the layers drawn at the view's diff --git a/crates/ui-egui/src/connectionui.rs b/crates/ui-egui/src/connectionui.rs index e7f169ceeb..9fa77895e8 100644 --- a/crates/ui-egui/src/connectionui.rs +++ b/crates/ui-egui/src/connectionui.rs @@ -89,6 +89,7 @@ pub(crate) fn translated(e: &str) -> String { web::NOT_THIS_SESSION => tl!("This request's login does not belong to this session."), web::CHOOSE_CONNECTION => tl!("Several saved connections match this address. Choose a connection explicitly."), web::NO_SUCH_CONNECTION => tl!("No saved web-service connection with this id."), + web::CONNECTION_TEXT => tl!("connection must be a saved web-service connection id (text)"), other => other, } .to_string()