From ce326af751f10892da16c94c13ba74571f8e3f1c Mon Sep 17 00:00:00 2001 From: Jose Gregorio Rincon Albarracin Date: Tue, 17 Nov 2026 12:32:39 -0500 Subject: [PATCH 1/8] fix(layout): size and centre a globe locator so it fits its circle near a pole (#2348) --- crates/engine/src/cmd/layout.rs | 15 +++++++++----- crates/engine/src/tests.rs | 35 +++++++++++++++++++++++++++++++++ docs/user-guide/layouts.md | 4 +++- 3 files changed, 48 insertions(+), 6 deletions(-) diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index 5cad2c770..94b3ffd7f 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -1944,7 +1944,12 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { m.graticule = src.graticule; m.body = src.body.clone(); m.set_projection(rustgis_map::Projection::Globe); - let globe = globe_scale(&m, center, side * 0.92); + // Sized on the equator and centred as near the area as the camera draws a globe that + // small, as the whole globe's frame is (#2337): at the area's own latitude near a pole + // the camera stops at its coarsest resolution, and the disc came out larger than its + // circle, clipped. Further from the pole, the area is still on the disc and outlined. + let globe = globe_scale(&m, Coord::new(center.x, 0.0), side * 0.92); + let at = drawable_globe_center(&m, center, globe); // Each polygon simplified to a tenth of a millimetre on the disc (its scale in metres), // so the project keeps a sketch of the layers for it, not a second full copy of them. let tolerance_m = globe * 1e-4; @@ -2031,9 +2036,9 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { } None => s.project.maps.push(m), } - Some((name, globe, FrameShape::Circle)) + Some((name, globe, FrameShape::Circle, at)) } - Locator::Inset => Some((s.map().name.clone(), round_scale(scale * fw / side * 4.0), FrameShape::Rectangle)), + Locator::Inset => Some((s.map().name.clone(), round_scale(scale * fw / side * 4.0), FrameShape::Rectangle, center)), }; // The legend lists what the frame draws: its map synced to the frame's view first, as an // export does, so a streamed layer has its features there. (This changes the session's map, @@ -2704,7 +2709,7 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { let card = style == Style::Modular && column.is_some(); let (card_r, card_pad) = (3.0 * k, 2.5 * k); let surround_box = |fill: Rgba| if style.cards() { pub_card(fill, clear, 0.0, 2.0 * k) } else { pub_box(fill, clear, 0.0) }; - if let (Some((map, locator_scale, shape)), Some(r)) = (&locator_map, locator_rect) { + if let (Some((map, locator_scale, shape, locator_center)), Some(r)) = (&locator_map, locator_rect) { if let (true, Some(c)) = (card, column) { l.add( "Locator Card", @@ -2717,7 +2722,7 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { r, ElementKind::MapFrame { map: map.clone(), - center, + center: *locator_center, scale: *locator_scale, shape: shape.clone(), grid: None, diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index cc9930508..d82f40c29 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -10350,6 +10350,41 @@ fn a_publication_of_the_whole_globe_fills_its_frame() { assert!(!warnings.contains("the whole globe"), "{warnings}"); } +/// A publication's globe locator near a pole shows the globe whole in its circle (#2337): sized on +/// the equator and centred as near the area as the camera draws it, not at the area's latitude, +/// where the camera stops at its coarsest resolution and the disc came out larger than the circle. +/// On a flat map with an Arctic extent, and on the globe seen whole with a locator asked for. +#[test] +fn a_globe_locator_near_a_pole_fits_its_circle() { + use rustgis_map::layout::{ElementKind, PT_PER_MM, frame_camera}; + let mut s = world(); + let fits = |s: &Session, case: &str| { + let l = s.project.layouts.last().unwrap(); + let locator = l.elements.iter().find(|e| e.name == "Locator").unwrap_or_else(|| panic!("{case}: no locator")); + let ElementKind::MapFrame { map, center, scale, .. } = &locator.kind else { panic!() }; + let m = s.project.maps.iter().find(|m| &m.name == map).unwrap(); + let cam = frame_camera(m, *center, *scale, 0.0, 0.0); + assert!(cam.res < rustgis_map::camera::MAX_RES, "{case}: the camera at its coarsest, 1:{scale} at {center:?}"); + let across = 2.0 * rustgis_map::globe::Globe::new(&cam, locator.w * PT_PER_MM, locator.h * PT_PER_MM).disc_radius() / PT_PER_MM; + assert!(across <= locator.w.min(locator.h), "{case}: a disc {across:.0} mm across in a {:.0} mm circle", locator.w); + }; + s.run("layout.publication", &json!({"profile": "a4-portrait", "extent": [10.0, 76.0, 30.0, 81.0]})).unwrap(); + fits(&s, "Svalbard on a flat map"); + s.run("map.projection", &json!({"type": "globe"})).unwrap(); + s.run("map.goToXY", &json!({"lon": 20.0, "lat": 84.0})).unwrap(); + s.run("layout.publication", &json!({"profile": "a4-portrait", "locator": "globe"})).unwrap(); + fits(&s, "the whole globe at 84° N"); + // Away from the poles the locator stays centred on the area, as before. + s.run("layout.publication", &json!({"profile": "a4-portrait", "extent": [-46.8, -11.6, -38.5, -2.2]})).unwrap(); + fits(&s, "north-east Brazil"); + let l = s.project.layouts.last().unwrap(); + let centre = |n: &str| match l.elements.iter().find(|e| e.name == n).map(|e| &e.kind) { + Some(ElementKind::MapFrame { center, .. }) => *center, + _ => panic!("no {n}"), + }; + assert_eq!(centre("Locator"), centre("Map Frame")); +} + /// Arrangements of a publication layout's surrounds (#1379): by name, corner by corner, the /// favourite (`layout.arrangement`, kept by the app) and `best`, the default, which keeps the /// favourite unless another keeps more surrounds in their own corners. Bad ones are refused before diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index ba0f0919b..862de7726 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -149,7 +149,9 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu layers held in the project. Streamed layers, rasters, points, lines and labels are left out. What simplifying changes or leaves alone there (a vertex past a pole taken to the pole, a polygon left as it was for a missing coordinate, or too intricate to simplify whole) is said - in the layout's warnings; one kept as it was because its ring would collapse is not. + in the layout's warnings; one kept as it was because its ring would collapse is not. The + globe is whole in its circle: near a pole, where it can't be drawn that small at the area's + latitude, it is centred as near the area as fits, the area still outlined on it. It uses the map's basemap, not its web tiles, in a round frame, the globe nearly filling it and the area outlined in red; `"inset"` shows the surrounding region (about four times the area across) on the map itself, outlined the same way; `"none"` (a figure's From a25ed77d26c1011c00cb882da81826d78dd0bd0c Mon Sep 17 00:00:00 2001 From: Jose Gregorio Rincon Albarracin Date: Tue, 17 Nov 2026 15:47:39 -0500 Subject: [PATCH 2/8] fix(layout): a globe locator says where it is centred, keeps a too-small one on the area, and outlines the area through the globe (#2348) --- crates/engine/src/cmd/layout.rs | 14 +++++++- crates/engine/src/tests.rs | 28 ++++++++++++--- crates/render/src/layout.rs | 64 +++++++++++++++++++++++++++++++-- docs/user-guide/layouts.md | 4 ++- 4 files changed, 100 insertions(+), 10 deletions(-) diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index 94b3ffd7f..8d1efea28 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -1948,8 +1948,20 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { // small, as the whole globe's frame is (#2337): at the area's own latitude near a pole // the camera stops at its coarsest resolution, and the disc came out larger than its // circle, clipped. Further from the pole, the area is still on the disc and outlined. + // A locator too small for the globe to fit even on the equator (a figure's, under + // about 30 mm) keeps the area in the middle, as the disc is clipped wherever it is. let globe = globe_scale(&m, Coord::new(center.x, 0.0), side * 0.92); - let at = drawable_globe_center(&m, center, globe); + let fits = |at: Coord| rustgis_map::layout::frame_camera(&m, at, globe, 0.0, 0.0).res < rustgis_map::camera::MAX_RES; + let at = if fits(Coord::new(center.x, 0.0)) { drawable_globe_center(&m, center, globe) } else { center }; + if at != center { + warnings.push(format!( + "the globe locator is centred at {:.1}° rather than the area's {:.1}° of latitude: nearer the pole, it can't draw the globe small enough to fit", + at.y, center.y + )); + } + if !fits(at) { + warnings.push("the globe locator is too small to show the whole globe: its circle clips it".into()); + } // Each polygon simplified to a tenth of a millimetre on the disc (its scale in metres), // so the project keeps a sketch of the layers for it, not a second full copy of them. let tolerance_m = globe * 1e-4; diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index d82f40c29..4e2bbb9bb 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -10368,15 +10368,32 @@ fn a_globe_locator_near_a_pole_fits_its_circle() { let across = 2.0 * rustgis_map::globe::Globe::new(&cam, locator.w * PT_PER_MM, locator.h * PT_PER_MM).disc_radius() / PT_PER_MM; assert!(across <= locator.w.min(locator.h), "{case}: a disc {across:.0} mm across in a {:.0} mm circle", locator.w); }; - s.run("layout.publication", &json!({"profile": "a4-portrait", "extent": [10.0, 76.0, 30.0, 81.0]})).unwrap(); + let said = |r: &Value, start: &str| r["warnings"].as_array().unwrap().iter().filter_map(Value::as_str).any(|w| w.starts_with(start)); + const MOVED: &str = "the globe locator is centred at"; + const CLIPPED: &str = "the globe locator is too small"; + let r = s.run("layout.publication", &json!({"profile": "a4-portrait", "extent": [10.0, 76.0, 30.0, 81.0]})).unwrap(); fits(&s, "Svalbard on a flat map"); + assert!(said(&r, MOVED) && !said(&r, CLIPPED), "Svalbard: {}", r["warnings"]); + // A figure's locator, too small for the globe even on the equator: clipped wherever it is, it + // keeps the area in the middle and says so. + let r = + s.run("layout.publication", &json!({"profile": "figure-1col", "extent": [10.0, 83.0, 30.0, 84.0], "locator": "globe"})).unwrap(); + assert!(said(&r, CLIPPED) && !said(&r, MOVED), "a figure's locator: {}", r["warnings"]); + let l = s.project.layouts.last().unwrap(); + let centre = |n: &str| match l.elements.iter().find(|e| e.name == n).map(|e| &e.kind) { + Some(ElementKind::MapFrame { center, .. }) => *center, + _ => panic!("no {n}"), + }; + assert_eq!(centre("Locator"), centre("Map Frame")); s.run("map.projection", &json!({"type": "globe"})).unwrap(); s.run("map.goToXY", &json!({"lon": 20.0, "lat": 84.0})).unwrap(); - s.run("layout.publication", &json!({"profile": "a4-portrait", "locator": "globe"})).unwrap(); + let r = s.run("layout.publication", &json!({"profile": "a4-portrait", "locator": "globe"})).unwrap(); fits(&s, "the whole globe at 84° N"); - // Away from the poles the locator stays centred on the area, as before. - s.run("layout.publication", &json!({"profile": "a4-portrait", "extent": [-46.8, -11.6, -38.5, -2.2]})).unwrap(); + assert!(said(&r, MOVED) && !said(&r, CLIPPED), "the whole globe: {}", r["warnings"]); + // Away from the poles the locator stays centred on the area, as before, and says nothing. + let r = s.run("layout.publication", &json!({"profile": "a4-portrait", "extent": [-46.8, -11.6, -38.5, -2.2]})).unwrap(); fits(&s, "north-east Brazil"); + assert!(!said(&r, MOVED) && !said(&r, CLIPPED), "north-east Brazil: {}", r["warnings"]); let l = s.project.layouts.last().unwrap(); let centre = |n: &str| match l.elements.iter().find(|e| e.name == n).map(|e| &e.kind) { Some(ElementKind::MapFrame { center, .. }) => *center, @@ -51649,7 +51666,8 @@ fn a_globe_locator_says_what_simplifying_did() { .unwrap() .iter() .filter_map(|w| w.as_str()) - .filter(|w| w.starts_with("the globe locator")) + // What simplifying did, not where the locator is centred (#2348). + .filter(|w| w.starts_with("the globe locator, simplifying")) .map(String::from) .collect::>() }; diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index 5d044a52c..3c0903b3d 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -1157,12 +1157,21 @@ fn frame_viewport( /// frame's extent, as an extent indicator shows it. fn outline_lonlat(pm: &mut Canvas, map: &Map, view: &View, ring: &[Coord], color: Rgba, width: f32) { let ppp = view.pixels_per_point as f32; + // On a globe, through the globe as the frame draws it, breaking behind its horizon (#2348): + // through the flat camera the outline lands off the area once it is away from the centre. + let globe = map.projection.is_globe().then(|| rustgis_map::globe::Globe::new(&view.camera, view.width, view.height)); let mut pb = PathBuilder::new(); let mut first = true; for c in ring { - let Some(m) = map.to_map(*c) else { continue }; - // A tilted frame's outline breaks where it passes behind the eye. - let Some((x, y)) = view.camera.try_to_screen(m, view.width, view.height) else { + let at = match &globe { + Some(g) => g.forward(*c), + None => match map.to_map(*c) { + // A tilted frame's outline breaks where it passes behind the eye. + Some(m) => view.camera.try_to_screen(m, view.width, view.height), + None => continue, + }, + }; + let Some((x, y)) = at else { first = true; continue; }; @@ -5256,6 +5265,55 @@ Elaboração: RustGIS", assert!(t > 0 && w > 3 * t, "a wider outline covers more: {t} at 1 pt, {w} at 6 pt"); } + /// On a globe, the extent indicator is drawn where the globe shows the area, also away from + /// the disc's centre (#2348): through the flat camera, Svalbard 18° north of the centre came out + /// half as far again up, nearly 5 mm off on a 50 mm locator. + #[test] + fn an_extent_indicator_on_a_globe_lands_on_the_area() { + use rustgis_map::layout::{INDICATOR_COLOR, INDICATOR_WIDTH, frame_camera}; + let (area, at, scale) = (Coord::new(20.0, 78.0), Coord::new(20.0, 60.0), 2e8); + let mut globe = Map::new("g"); + globe.set_projection(rustgis_map::Projection::Globe); + let maps = || [Map::new("m"), globe.clone()]; + let frame = |map: &str, center, scale, extent_of| ElementKind::MapFrame { + map: map.into(), + center, + scale, + shape: FrameShape::Rectangle, + grid: None, + extent_of, + extent_color: INDICATOR_COLOR, + extent_width: INDICATOR_WIDTH, + bearing: 0.0, + pitch: 0.0, + }; + let mut l = Layout::new("Layout", 100.0, 100.0); + let main = l.add("Main", (60.0, 60.0, 30.0, 30.0), frame("m", area, 2e7, None)); + l.add("Locator", (5.0, 5.0, 50.0, 50.0), frame("g", at, scale, Some(main))); + let pm = render(&l, &mut maps(), 96.0, &PageInfo::default()).unwrap(); + // Where the globe draws the area, in pixels on the page. + let side = 50.0 * PT_PER_MM; + let g = rustgis_map::globe::Globe::new(&frame_camera(&globe, at, scale, 0.0, 0.0), side, side); + let (x, y) = g.forward(area).unwrap(); + // At 96 dpi a layout point is a pixel. + let expected = (5.0 * PT_PER_MM + x, 5.0 * PT_PER_MM + y); + // The red pixels' middle, inside the locator. + let px_mm = PT_PER_MM; + let red: Vec<(f64, f64)> = ((5.0 * px_mm) as u32..(55.0 * px_mm) as u32) + .flat_map(|y| ((5.0 * px_mm) as u32..(55.0 * px_mm) as u32).map(move |x| (x, y))) + .filter(|&(x, y)| { + let (r, g, b) = rgb(&pm, x, y); + r > 180 && g < 90 && b < 90 + }) + .map(|(x, y)| (f64::from(x), f64::from(y))) + .collect(); + assert!(!red.is_empty(), "no extent indicator on the globe"); + let n = red.len() as f64; + let mid = (red.iter().map(|p| p.0).sum::() / n, red.iter().map(|p| p.1).sum::() / n); + let off = ((mid.0 - expected.0).powi(2) + (mid.1 - expected.1).powi(2)).sqrt() / px_mm; + assert!(off < 1.5, "the indicator's middle {mid:?} is {off:.1} mm from the area at {expected:?}"); + } + fn rgb(pm: &Pixmap, x: u32, y: u32) -> (u8, u8, u8) { pm.pixel(x, y).map(|p| (p.red(), p.green(), p.blue())).unwrap_or((255, 255, 255)) } diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 862de7726..9a4e3f86a 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -151,7 +151,9 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu polygon left as it was for a missing coordinate, or too intricate to simplify whole) is said in the layout's warnings; one kept as it was because its ring would collapse is not. The globe is whole in its circle: near a pole, where it can't be drawn that small at the area's - latitude, it is centred as near the area as fits, the area still outlined on it. + latitude, it is centred as near the area as fits, the area still outlined on it, and the + warnings say so. A locator too small for the whole globe anywhere (a figure's, under about + 30 mm) stays centred on the area, its circle clipping the globe, which the warnings also say. It uses the map's basemap, not its web tiles, in a round frame, the globe nearly filling it and the area outlined in red; `"inset"` shows the surrounding region (about four times the area across) on the map itself, outlined the same way; `"none"` (a figure's From 1571314e42e8aed02cd9e661df95e2f2bbf79421 Mon Sep 17 00:00:00 2001 From: Jose Gregorio Rincon Albarracin Date: Tue, 17 Nov 2026 17:30:58 -0500 Subject: [PATCH 3/8] fix(layout): read a frame on the globe through the globe when outlining it on another (#2348) --- crates/render/src/layout.rs | 61 ++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index 3c0903b3d..f573b4e06 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -887,10 +887,17 @@ fn frame_outline_lonlat(map: &Map, cam: &rustgis_map::Camera, w: f64, h: f64) -> 2 => ((1.0 - t) * w, h), _ => (0.0, (1.0 - t) * h), }; + // A frame on the globe is read through the globe as it draws it (#2348), its edges off the + // disc left out: one that shows the globe whole has no edge on it, and no outline. + let globe = map.projection.is_globe().then(|| rustgis_map::globe::Globe::new(cam, w, h)); for side in 0..4 { for i in 0..n { let (sx, sy) = edge(i as f64 / n as f64, side); - if let Some(c) = map.to_lonlat(cam.to_map(sx, sy, w, h)) { + let at = match &globe { + Some(g) => g.inverse(sx, sy), + None => map.to_lonlat(cam.to_map(sx, sy, w, h)), + }; + if let Some(c) = at { ring.push(c); } } @@ -5314,6 +5321,58 @@ Elaboração: RustGIS", assert!(off < 1.5, "the indicator's middle {mid:?} is {off:.1} mm from the area at {expected:?}"); } + /// A frame on the globe is outlined by what it shows of the globe (#2348): zoomed in on Iceland, + /// around Iceland on a globe locator; seen whole, with no edge on the disc, not at all (through + /// the flat camera its edges were read as a flat world, a line drawn across the locator). + #[test] + fn a_frame_on_the_globe_is_outlined_by_what_it_shows() { + use rustgis_map::layout::{INDICATOR_COLOR, INDICATOR_WIDTH, frame_camera}; + let mut globe = Map::new("g"); + globe.set_projection(rustgis_map::Projection::Globe); + let frame = |center, scale, extent_of| ElementKind::MapFrame { + map: "g".into(), + center, + scale, + shape: FrameShape::Rectangle, + grid: None, + extent_of, + extent_color: INDICATOR_COLOR, + extent_width: INDICATOR_WIDTH, + bearing: 0.0, + pitch: 0.0, + }; + let (at, scale) = (Coord::new(-20.0, 55.0), 2e8); + // The red pixels inside the locator (5–55 mm), with the source frame on `center` at 1:`main`. + let red = |center: Coord, main: f64| { + let mut l = Layout::new("Layout", 100.0, 100.0); + // 40 mm across: near the equator, wider than the smallest globe the camera draws there. + let source = l.add("Main", (58.0, 58.0, 40.0, 40.0), frame(center, main, None)); + l.add("Locator", (5.0, 5.0, 50.0, 50.0), frame(at, scale, Some(source))); + let pm = render(&l, &mut [globe.clone()], 96.0, &PageInfo::default()).unwrap(); + let k = PT_PER_MM; + ((5.0 * k) as u32..(55.0 * k) as u32) + .flat_map(|y| ((5.0 * k) as u32..(55.0 * k) as u32).map(move |x| (x, y))) + .filter(|&(x, y)| { + let (r, g, b) = rgb(&pm, x, y); + r > 180 && g < 90 && b < 90 + }) + .map(|(x, y)| (f64::from(x), f64::from(y))) + .collect::>() + }; + let iceland = red(Coord::new(-19.0, 65.0), 2e7); + assert!(!iceland.is_empty(), "no outline of the zoomed-in frame"); + let n = iceland.len() as f64; + let mid = (iceland.iter().map(|p| p.0).sum::() / n, iceland.iter().map(|p| p.1).sum::() / n); + let side = 50.0 * PT_PER_MM; + let g = rustgis_map::globe::Globe::new(&frame_camera(&globe, at, scale, 0.0, 0.0), side, side); + let (x, y) = g.forward(Coord::new(-19.0, 65.0)).unwrap(); + let expected = (5.0 * PT_PER_MM + x, 5.0 * PT_PER_MM + y); + let off = ((mid.0 - expected.0).powi(2) + (mid.1 - expected.1).powi(2)).sqrt() / PT_PER_MM; + assert!(off < 1.5, "the outline's middle {mid:?} is {off:.1} mm from Iceland at {expected:?}"); + let whole = red(Coord::new(-20.0, 10.0), 4e8); + assert!(whole.is_empty(), "the globe seen whole outlined by {} red pixels", whole.len()); + } + fn rgb(pm: &Pixmap, x: u32, y: u32) -> (u8, u8, u8) { pm.pixel(x, y).map(|p| (p.red(), p.green(), p.blue())).unwrap_or((255, 255, 255)) } From a8de872d38b1f9e61c506a8b2b71de27b162a20a Mon Sep 17 00:00:00 2001 From: Jose Gregorio Rincon Albarracin Date: Tue, 17 Nov 2026 17:35:18 -0500 Subject: [PATCH 4/8] test(layout): match the whole-globe notices exactly and write the locator centre check once (#2348) --- crates/engine/src/tests.rs | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 4e2bbb9bb..8be5da9e0 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -10347,7 +10347,8 @@ fn a_publication_of_the_whole_globe_fills_its_frame() { let l = s.project.layouts.last().unwrap(); assert!(r["locator"].is_string() && l.elements.iter().any(|e| e.name == "Scale Bar")); let warnings = r["warnings"].to_string(); - assert!(!warnings.contains("the whole globe"), "{warnings}"); + // Neither whole-globe notice (no scale bar, no locator). + assert!(!warnings.contains("the map shows the whole globe"), "{warnings}"); } /// A publication's globe locator near a pole shows the globe whole in its circle (#2337): sized on @@ -10369,6 +10370,15 @@ fn a_globe_locator_near_a_pole_fits_its_circle() { assert!(across <= locator.w.min(locator.h), "{case}: a disc {across:.0} mm across in a {:.0} mm circle", locator.w); }; let said = |r: &Value, start: &str| r["warnings"].as_array().unwrap().iter().filter_map(Value::as_str).any(|w| w.starts_with(start)); + // The locator centred where the map frame is. + let centred_with_the_map = |s: &Session, case: &str| { + let l = s.project.layouts.last().unwrap(); + let centre = |n: &str| match l.elements.iter().find(|e| e.name == n).map(|e| &e.kind) { + Some(ElementKind::MapFrame { center, .. }) => *center, + _ => panic!("{case}: no {n}"), + }; + assert_eq!(centre("Locator"), centre("Map Frame"), "{case}"); + }; const MOVED: &str = "the globe locator is centred at"; const CLIPPED: &str = "the globe locator is too small"; let r = s.run("layout.publication", &json!({"profile": "a4-portrait", "extent": [10.0, 76.0, 30.0, 81.0]})).unwrap(); @@ -10379,12 +10389,7 @@ fn a_globe_locator_near_a_pole_fits_its_circle() { let r = s.run("layout.publication", &json!({"profile": "figure-1col", "extent": [10.0, 83.0, 30.0, 84.0], "locator": "globe"})).unwrap(); assert!(said(&r, CLIPPED) && !said(&r, MOVED), "a figure's locator: {}", r["warnings"]); - let l = s.project.layouts.last().unwrap(); - let centre = |n: &str| match l.elements.iter().find(|e| e.name == n).map(|e| &e.kind) { - Some(ElementKind::MapFrame { center, .. }) => *center, - _ => panic!("no {n}"), - }; - assert_eq!(centre("Locator"), centre("Map Frame")); + centred_with_the_map(&s, "a figure's locator"); s.run("map.projection", &json!({"type": "globe"})).unwrap(); s.run("map.goToXY", &json!({"lon": 20.0, "lat": 84.0})).unwrap(); let r = s.run("layout.publication", &json!({"profile": "a4-portrait", "locator": "globe"})).unwrap(); @@ -10394,12 +10399,7 @@ fn a_globe_locator_near_a_pole_fits_its_circle() { let r = s.run("layout.publication", &json!({"profile": "a4-portrait", "extent": [-46.8, -11.6, -38.5, -2.2]})).unwrap(); fits(&s, "north-east Brazil"); assert!(!said(&r, MOVED) && !said(&r, CLIPPED), "north-east Brazil: {}", r["warnings"]); - let l = s.project.layouts.last().unwrap(); - let centre = |n: &str| match l.elements.iter().find(|e| e.name == n).map(|e| &e.kind) { - Some(ElementKind::MapFrame { center, .. }) => *center, - _ => panic!("no {n}"), - }; - assert_eq!(centre("Locator"), centre("Map Frame")); + centred_with_the_map(&s, "north-east Brazil"); } /// Arrangements of a publication layout's surrounds (#1379): by name, corner by corner, the From f03d9c5d0e35a6eb5fdb4e2d3d37c7d03811ade4 Mon Sep 17 00:00:00 2001 From: Jose Gregorio Rincon Albarracin Date: Tue, 17 Nov 2026 18:05:34 -0500 Subject: [PATCH 5/8] fix(layout): break a globe frame's outline where its edges leave the disc (#2348) --- crates/render/src/layout.rs | 82 +++++++++++++++++++++++++++++++------ 1 file changed, 70 insertions(+), 12 deletions(-) diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index f573b4e06..1fd48e944 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -877,8 +877,9 @@ fn shape_path(shape: &FrameShape, r: Rect) -> Option { } } -/// The lon/lat outline of what a frame shows. -fn frame_outline_lonlat(map: &Map, cam: &rustgis_map::Camera, w: f64, h: f64) -> Vec { +/// The lon/lat outline of what a frame shows, `None` where an edge of a frame on the globe is off +/// the disc: the outline breaks there rather than cutting across the globe. +fn frame_outline_lonlat(map: &Map, cam: &rustgis_map::Camera, w: f64, h: f64) -> Vec> { let mut ring = Vec::new(); let n = 16; let edge = |t: f64, side: usize| match side { @@ -887,18 +888,19 @@ fn frame_outline_lonlat(map: &Map, cam: &rustgis_map::Camera, w: f64, h: f64) -> 2 => ((1.0 - t) * w, h), _ => (0.0, (1.0 - t) * h), }; - // A frame on the globe is read through the globe as it draws it (#2348), its edges off the - // disc left out: one that shows the globe whole has no edge on it, and no outline. + // A frame on the globe is read through the globe as it draws it (#2348), with a gap where an + // edge runs off the disc: one that shows the globe whole has no edge on it, and no outline. let globe = map.projection.is_globe().then(|| rustgis_map::globe::Globe::new(cam, w, h)); for side in 0..4 { for i in 0..n { let (sx, sy) = edge(i as f64 / n as f64, side); - let at = match &globe { - Some(g) => g.inverse(sx, sy), - None => map.to_lonlat(cam.to_map(sx, sy, w, h)), - }; - if let Some(c) = at { - ring.push(c); + match &globe { + Some(g) => ring.push(g.inverse(sx, sy)), + None => { + if let Some(c) = map.to_lonlat(cam.to_map(sx, sy, w, h)) { + ring.push(Some(c)); + } + } } } } @@ -1161,8 +1163,8 @@ fn frame_viewport( } /// Strokes the ring `ring` (longitude, latitude) on a frame's map `width` points wide: another -/// frame's extent, as an extent indicator shows it. -fn outline_lonlat(pm: &mut Canvas, map: &Map, view: &View, ring: &[Coord], color: Rgba, width: f32) { +/// frame's extent, as an extent indicator shows it, broken at each `None`. +fn outline_lonlat(pm: &mut Canvas, map: &Map, view: &View, ring: &[Option], color: Rgba, width: f32) { let ppp = view.pixels_per_point as f32; // On a globe, through the globe as the frame draws it, breaking behind its horizon (#2348): // through the flat camera the outline lands off the area once it is away from the centre. @@ -1170,6 +1172,10 @@ fn outline_lonlat(pm: &mut Canvas, map: &Map, view: &View, ring: &[Coord], color let mut pb = PathBuilder::new(); let mut first = true; for c in ring { + let Some(c) = c else { + first = true; + continue; + }; let at = match &globe { Some(g) => g.forward(*c), None => match map.to_map(*c) { @@ -5373,6 +5379,58 @@ Elaboração: RustGIS", assert!(whole.is_empty(), "the globe seen whole outlined by {} red pixels", whole.len()); } + /// A frame on the globe whose sides run off the disc is outlined by its top and bottom edges + /// only, broken where they leave the disc, not joined by a line across the globe (#2348). + #[test] + fn a_frame_partly_off_the_globe_is_outlined_without_a_chord() { + use rustgis_map::layout::{INDICATOR_COLOR, INDICATOR_WIDTH, frame_camera}; + let mut globe = Map::new("g"); + globe.set_projection(rustgis_map::Projection::Globe); + let frame = |center, scale, extent_of| ElementKind::MapFrame { + map: "g".into(), + center, + scale, + shape: FrameShape::Rectangle, + grid: None, + extent_of, + extent_color: INDICATOR_COLOR, + extent_width: INDICATOR_WIDTH, + bearing: 0.0, + pitch: 0.0, + }; + let center = Coord::new(-20.0, 0.0); + // The source frame, 40 × 20 mm: a scale whose disc is taller than the frame, its sides in + // the sky beside the disc, and its corners too. + let (sw, sh) = (40.0, 20.0); + let disc = |scale: f64| { + let cam = frame_camera(&globe, center, scale, 0.0, 0.0); + rustgis_map::globe::Globe::new(&cam, sw * PT_PER_MM, sh * PT_PER_MM).disc_radius() / PT_PER_MM + }; + let source_scale = (1..400).map(|i| f64::from(i) * 1e6).find(|&s| disc(s) < 0.5 * sw - 3.0).unwrap(); + assert!(disc(source_scale) > 0.5 * sh + 2.0, "a disc {:.1} mm across", 2.0 * disc(source_scale)); + let (at, scale) = (center, 2.0 * source_scale); + let mut l = Layout::new("Layout", 100.0, 100.0); + let source = l.add("Main", (55.0, 70.0, sw, sh), frame(center, source_scale, None)); + l.add("Locator", (5.0, 5.0, 50.0, 50.0), frame(at, scale, Some(source))); + let pm = render(&l, &mut [globe.clone()], 96.0, &PageInfo::default()).unwrap(); + let red = |x: u32, y: u32| { + let (r, g, b) = rgb(&pm, x, y); + r > 180 && g < 90 && b < 90 + }; + let k = PT_PER_MM; + let (x0, x1) = ((5.0 * k) as u32, (55.0 * k) as u32); + let inked = (x0..x1).flat_map(|y| (x0..x1).map(move |x| (x, y))).filter(|&(x, y)| red(x, y)).count(); + assert!(inked > 0, "no outline of the frame"); + // The row through the source frame's centre, between its top and bottom edges: crossed only + // by a chord. + let side = 50.0 * k; + let g = rustgis_map::globe::Globe::new(&frame_camera(&globe, at, scale, 0.0, 0.0), side, side); + let (_, cy) = g.forward(center).unwrap(); + let row = (5.0 * k + cy).round() as u32; + let crossed: Vec = (row - 2..=row + 2).flat_map(|y| (x0..x1).filter(move |&x| red(x, y))).collect(); + assert!(crossed.is_empty(), "the outline crosses the middle of the globe at {crossed:?}"); + } + fn rgb(pm: &Pixmap, x: u32, y: u32) -> (u8, u8, u8) { pm.pixel(x, y).map(|p| (p.red(), p.green(), p.blue())).unwrap_or((255, 255, 255)) } From 2aaa54d6c5bf55a67c167718be598880e5a73d7e Mon Sep 17 00:00:00 2001 From: Jose Gregorio Rincon Albarracin Date: Wed, 18 Nov 2026 03:40:49 -0500 Subject: [PATCH 6/8] fix(layout): a globe locator keeps its area off the rim, and its outline is continuous across the antimeridian (#2348) --- crates/engine/src/cmd/layout.rs | 24 ++++++++++---- crates/engine/src/tests.rs | 28 ++++++++++++++++ crates/render/src/layout.rs | 58 +++++++++++++++++++++++++++++++-- docs/user-guide/layouts.md | 3 +- 4 files changed, 104 insertions(+), 9 deletions(-) diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index 8d1efea28..4d62cf498 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -1948,18 +1948,15 @@ fn publication(s: &mut Session, p: &Value) -> CmdResult { // small, as the whole globe's frame is (#2337): at the area's own latitude near a pole // the camera stops at its coarsest resolution, and the disc came out larger than its // circle, clipped. Further from the pole, the area is still on the disc and outlined. - // A locator too small for the globe to fit even on the equator (a figure's, under - // about 30 mm) keeps the area in the middle, as the disc is clipped wherever it is. let globe = globe_scale(&m, Coord::new(center.x, 0.0), side * 0.92); - let fits = |at: Coord| rustgis_map::layout::frame_camera(&m, at, globe, 0.0, 0.0).res < rustgis_map::camera::MAX_RES; - let at = if fits(Coord::new(center.x, 0.0)) { drawable_globe_center(&m, center, globe) } else { center }; + let (at, whole) = globe_locator_center(&m, center, globe, side); if at != center { warnings.push(format!( - "the globe locator is centred at {:.1}° rather than the area's {:.1}° of latitude: nearer the pole, it can't draw the globe small enough to fit", + "the globe locator is centred at {:.1}° rather than the map frame's {:.1}° of latitude: nearer the pole, it can't draw the globe small enough to fit", at.y, center.y )); } - if !fits(at) { + if !whole { warnings.push("the globe locator is too small to show the whole globe: its circle clips it".into()); } // Each polygon simplified to a tenth of a millimetre on the disc (its scale in metres), @@ -5775,6 +5772,21 @@ fn drawable_globe_center(map: &Map, view: Coord, scale: f64) -> Coord { Coord::new(view.x, fit.copysign(view.y)) } +/// Where a globe locator `side_mm` across at 1:`scale` centres the globe, and whether it shows it +/// whole: as near `area` as the camera draws a globe that small ([`drawable_globe_center`]), the +/// area still on the disc. A locator too small for the globe to fit even on the equator (under +/// about 20 mm), or one whose nearest centre leaves the area behind the globe's rim, keeps the area +/// in the middle, its circle clipping the globe (#2348). +pub(crate) fn globe_locator_center(map: &Map, area: Coord, scale: f64, side_mm: f64) -> (Coord, bool) { + let cam = |at: Coord| rustgis_map::layout::frame_camera(map, at, scale, 0.0, 0.0); + if cam(Coord::new(area.x, 0.0)).res >= rustgis_map::camera::MAX_RES { + return (area, false); + } + let at = drawable_globe_center(map, area, scale); + let side = side_mm * rustgis_map::layout::PT_PER_MM; + if rustgis_map::globe::Globe::new(&cam(at), side, side).forward(area).is_some() { (at, true) } else { (area, false) } +} + /// Parses the publication's locator choice with its default: a globe on a sheet, none on a figure /// or where the map is itself the globe seen whole (it would only show it again, smaller). fn publication_locator(p: &Value, sheet: bool, whole_globe: bool) -> Result { diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 8be5da9e0..89ab85ea2 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -10351,6 +10351,34 @@ fn a_publication_of_the_whole_globe_fills_its_frame() { assert!(!warnings.contains("the map shows the whole globe"), "{warnings}"); } +/// A globe locator moved off a polar area keeps the area on the disc (#2348): at the sizes where +/// the nearest centre the camera draws would leave it behind the rim (a locator just large enough +/// for the globe on the equator), it keeps the area in the middle, clipped, instead. +#[test] +fn a_globe_locator_never_hides_its_area_behind_the_rim() { + use rustgis_geom::Coord; + use rustgis_map::layout::{PT_PER_MM, frame_camera}; + let mut m = rustgis_map::Map::new("Locator"); + m.set_projection(rustgis_map::Projection::Globe); + let (area, side) = (Coord::new(20.0, 89.0), 40.0); + let (mut moved, mut hidden) = (0, 0); + // Steps of 0.2 %: the sizes that would hide it span about 1 % of the scale. + for i in 0..4000 { + let scale = 1e8 * 1.002f64.powi(i); + let (at, whole) = crate::cmd::layout::globe_locator_center(&m, area, scale, side); + let equator = frame_camera(&m, Coord::new(area.x, 0.0), scale, 0.0, 0.0).res < rustgis_map::camera::MAX_RES; + if whole { + let g = rustgis_map::globe::Globe::new(&frame_camera(&m, at, scale, 0.0, 0.0), side * PT_PER_MM, side * PT_PER_MM); + assert!(g.forward(area).is_some(), "1:{scale:.0}: the area behind the rim from {at:?}"); + moved += usize::from(at != area); + } else { + assert_eq!(at, area, "1:{scale:.0}: a clipped locator keeps the area in the middle"); + hidden += usize::from(equator); + } + } + assert!(moved > 0 && hidden > 0, "{moved} moved, {hidden} kept on the area though the equator fits"); +} + /// A publication's globe locator near a pole shows the globe whole in its circle (#2337): sized on /// the equator and centred as near the area as the camera draws it, not at the area's latitude, /// where the camera stops at its coarsest resolution and the disc came out larger than the circle. diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index 1fd48e944..957b2236b 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -891,11 +891,24 @@ fn frame_outline_lonlat(map: &Map, cam: &rustgis_map::Camera, w: f64, h: f64) -> // A frame on the globe is read through the globe as it draws it (#2348), with a gap where an // edge runs off the disc: one that shows the globe whole has no edge on it, and no outline. let globe = map.projection.is_globe().then(|| rustgis_map::globe::Globe::new(cam, w, h)); + // Its longitudes kept continuous, a turn added or taken where they cross ±180°, so on a flat + // frame the outline doesn't jump across the map there. + let mut last: Option = None; + let near = |c: Coord, last: Option| match last { + Some(p) => Coord::new(c.x + 360.0 * ((p - c.x) / 360.0).round(), c.y), + None => c, + }; for side in 0..4 { for i in 0..n { let (sx, sy) = edge(i as f64 / n as f64, side); match &globe { - Some(g) => ring.push(g.inverse(sx, sy)), + Some(g) => { + let c = g.inverse(sx, sy).map(|c| near(c, last)); + if let Some(c) = c { + last = Some(c.x); + } + ring.push(c); + } None => { if let Some(c) = map.to_lonlat(cam.to_map(sx, sy, w, h)) { ring.push(Some(c)); @@ -905,7 +918,7 @@ fn frame_outline_lonlat(map: &Map, cam: &rustgis_map::Camera, w: f64, h: f64) -> } } if let Some(f) = ring.first().copied() { - ring.push(f); + ring.push(f.map(|c| near(c, last))); } ring } @@ -5431,6 +5444,47 @@ Elaboração: RustGIS", assert!(crossed.is_empty(), "the outline crosses the middle of the globe at {crossed:?}"); } + /// A frame on the globe across the antimeridian, outlined on a flat frame, stays one small box + /// around 180° (#2348): its edge's longitudes kept continuous, not jumping from 179.5° to + /// -179.5° and drawing a line across the flat map. + #[test] + fn a_globe_frame_across_the_antimeridian_is_outlined_in_one_piece() { + use rustgis_map::layout::{INDICATOR_COLOR, INDICATOR_WIDTH}; + let mut globe = Map::new("g"); + globe.set_projection(rustgis_map::Projection::Globe); + let frame = |map: &str, center, scale, extent_of| ElementKind::MapFrame { + map: map.into(), + center, + scale, + shape: FrameShape::Rectangle, + grid: None, + extent_of, + extent_color: INDICATOR_COLOR, + extent_width: INDICATOR_WIDTH, + bearing: 0.0, + pitch: 0.0, + }; + let at = Coord::new(180.0, 0.0); + let mut l = Layout::new("Layout", 100.0, 100.0); + // 40 mm at 1:20M, about 800 km across: 4 mm on the locator at 1:200M. + let source = l.add("Main", (58.0, 58.0, 40.0, 40.0), frame("g", at, 2e7, None)); + l.add("Locator", (5.0, 5.0, 50.0, 50.0), frame("m", at, 2e8, Some(source))); + let pm = render(&l, &mut [globe, Map::new("m")], 96.0, &PageInfo::default()).unwrap(); + let k = PT_PER_MM; + let (x0, x1) = ((5.0 * k) as u32, (55.0 * k) as u32); + let red: Vec<(u32, u32)> = (x0..x1) + .flat_map(|y| (x0..x1).map(move |x| (x, y))) + .filter(|&(x, y)| { + let (r, g, b) = rgb(&pm, x, y); + r > 180 && g < 90 && b < 90 + }) + .collect(); + assert!(!red.is_empty(), "no outline of the frame"); + let middle = 30.0 * k; + let far = red.iter().filter(|&&(x, y)| (f64::from(x) - middle).abs() > 6.0 * k || (f64::from(y) - middle).abs() > 6.0 * k).count(); + assert_eq!(far, 0, "{far} of {} red pixels more than 6 mm from the locator's middle", red.len()); + } + fn rgb(pm: &Pixmap, x: u32, y: u32) -> (u8, u8, u8) { pm.pixel(x, y).map(|p| (p.red(), p.green(), p.blue())).unwrap_or((255, 255, 255)) } diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 9a4e3f86a..87d6959ba 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -153,7 +153,8 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu globe is whole in its circle: near a pole, where it can't be drawn that small at the area's latitude, it is centred as near the area as fits, the area still outlined on it, and the warnings say so. A locator too small for the whole globe anywhere (a figure's, under about - 30 mm) stays centred on the area, its circle clipping the globe, which the warnings also say. + 20 mm), or one that would have to move so far that the area went behind the globe's rim, + stays centred on the area, its circle clipping the globe, which the warnings also say. It uses the map's basemap, not its web tiles, in a round frame, the globe nearly filling it and the area outlined in red; `"inset"` shows the surrounding region (about four times the area across) on the map itself, outlined the same way; `"none"` (a figure's From b60a24c90f1a34c228ce4aea9dc1b7ac8e0948c2 Mon Sep 17 00:00:00 2001 From: Jose Gregorio Rincon Albarracin Date: Wed, 18 Nov 2026 03:58:53 -0500 Subject: [PATCH 7/8] fix(layout): bring a globe frame's outline to a flat frame's side of the antimeridian (#2348) --- crates/render/src/layout.rs | 56 ++++++++++++++++++++++--------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index 957b2236b..4d4808f9d 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -1182,6 +1182,13 @@ fn outline_lonlat(pm: &mut Canvas, map: &Map, view: &View, ring: &[Option // On a globe, through the globe as the frame draws it, breaking behind its horizon (#2348): // through the flat camera the outline lands off the area once it is away from the centre. let globe = map.projection.is_globe().then(|| rustgis_map::globe::Globe::new(&view.camera, view.width, view.height)); + // On a flat map, which doesn't wrap, the whole ring a turn east or west if that brings it + // nearer the frame's centre: its longitudes run on from its first point (#2348), which can be + // on the other side of ±180° from it. One shift for all keeps the ring in one piece. + let shift = match (&globe, ring.iter().flatten().next(), map.to_lonlat(view.camera.center)) { + (None, Some(c), Some(mid)) => 360.0 * ((mid.x - c.x) / 360.0).round(), + _ => 0.0, + }; let mut pb = PathBuilder::new(); let mut first = true; for c in ring { @@ -1191,7 +1198,7 @@ fn outline_lonlat(pm: &mut Canvas, map: &Map, view: &View, ring: &[Option }; let at = match &globe { Some(g) => g.forward(*c), - None => match map.to_map(*c) { + None => match map.to_map(Coord::new(c.x + shift, c.y)) { // A tilted frame's outline breaks where it passes behind the eye. Some(m) => view.camera.try_to_screen(m, view.width, view.height), None => continue, @@ -5445,8 +5452,9 @@ Elaboração: RustGIS", } /// A frame on the globe across the antimeridian, outlined on a flat frame, stays one small box - /// around 180° (#2348): its edge's longitudes kept continuous, not jumping from 179.5° to - /// -179.5° and drawing a line across the flat map. + /// near the flat frame's centre (#2348): its edge's longitudes kept continuous, not jumping from + /// 179.5° to -179.5° and drawing a line across the flat map, and brought to the flat frame's side + /// of ±180° when they start on the other. #[test] fn a_globe_frame_across_the_antimeridian_is_outlined_in_one_piece() { use rustgis_map::layout::{INDICATOR_COLOR, INDICATOR_WIDTH}; @@ -5464,25 +5472,29 @@ Elaboração: RustGIS", bearing: 0.0, pitch: 0.0, }; - let at = Coord::new(180.0, 0.0); - let mut l = Layout::new("Layout", 100.0, 100.0); - // 40 mm at 1:20M, about 800 km across: 4 mm on the locator at 1:200M. - let source = l.add("Main", (58.0, 58.0, 40.0, 40.0), frame("g", at, 2e7, None)); - l.add("Locator", (5.0, 5.0, 50.0, 50.0), frame("m", at, 2e8, Some(source))); - let pm = render(&l, &mut [globe, Map::new("m")], 96.0, &PageInfo::default()).unwrap(); - let k = PT_PER_MM; - let (x0, x1) = ((5.0 * k) as u32, (55.0 * k) as u32); - let red: Vec<(u32, u32)> = (x0..x1) - .flat_map(|y| (x0..x1).map(move |x| (x, y))) - .filter(|&(x, y)| { - let (r, g, b) = rgb(&pm, x, y); - r > 180 && g < 90 && b < 90 - }) - .collect(); - assert!(!red.is_empty(), "no outline of the frame"); - let middle = 30.0 * k; - let far = red.iter().filter(|&&(x, y)| (f64::from(x) - middle).abs() > 6.0 * k || (f64::from(y) - middle).abs() > 6.0 * k).count(); - assert_eq!(far, 0, "{far} of {} red pixels more than 6 mm from the locator's middle", red.len()); + // The globe frame's centre and the flat locator's: on 180°, and a frame on -179° whose + // first point (its top-left corner) is on the +180° side, on a locator on -175°. + for (source_at, locator_at) in [(180.0, 180.0), (-179.0, -175.0)] { + let mut l = Layout::new("Layout", 100.0, 100.0); + // 40 mm at 1:20M, about 800 km across: 4 mm on the locator at 1:200M. + let source = l.add("Main", (58.0, 58.0, 40.0, 40.0), frame("g", Coord::new(source_at, 0.0), 2e7, None)); + l.add("Locator", (5.0, 5.0, 50.0, 50.0), frame("m", Coord::new(locator_at, 0.0), 2e8, Some(source))); + let pm = render(&l, &mut [globe.clone(), Map::new("m")], 96.0, &PageInfo::default()).unwrap(); + let k = PT_PER_MM; + let (x0, x1) = ((5.0 * k) as u32, (55.0 * k) as u32); + let red: Vec<(u32, u32)> = (x0..x1) + .flat_map(|y| (x0..x1).map(move |x| (x, y))) + .filter(|&(x, y)| { + let (r, g, b) = rgb(&pm, x, y); + r > 180 && g < 90 && b < 90 + }) + .collect(); + assert!(!red.is_empty(), "{source_at}° on {locator_at}°: no outline of the frame"); + let middle = 30.0 * k; + let far = + red.iter().filter(|&&(x, y)| (f64::from(x) - middle).abs() > 6.0 * k || (f64::from(y) - middle).abs() > 6.0 * k).count(); + assert_eq!(far, 0, "{source_at}° on {locator_at}°: {far} of {} red pixels more than 6 mm from the middle", red.len()); + } } fn rgb(pm: &Pixmap, x: u32, y: u32) -> (u8, u8, u8) { From 820e7d2e3ddeefca266f0f1349038e914c37e129 Mon Sep 17 00:00:00 2001 From: Jose Gregorio Rincon Albarracin Date: Wed, 18 Nov 2026 04:43:59 -0500 Subject: [PATCH 8/8] fix(layout): a globe locator is whole when its disc fits, and only a globe frame's outline is moved across the antimeridian (#2348) --- crates/engine/src/cmd/layout.rs | 19 ++++++----- crates/engine/src/tests.rs | 22 +++++++++++++ crates/render/src/layout.rs | 57 ++++++++++++++++++++++++++++----- 3 files changed, 80 insertions(+), 18 deletions(-) diff --git a/crates/engine/src/cmd/layout.rs b/crates/engine/src/cmd/layout.rs index 4d62cf498..9054a1ca1 100644 --- a/crates/engine/src/cmd/layout.rs +++ b/crates/engine/src/cmd/layout.rs @@ -5773,18 +5773,17 @@ fn drawable_globe_center(map: &Map, view: Coord, scale: f64) -> Coord { } /// Where a globe locator `side_mm` across at 1:`scale` centres the globe, and whether it shows it -/// whole: as near `area` as the camera draws a globe that small ([`drawable_globe_center`]), the -/// area still on the disc. A locator too small for the globe to fit even on the equator (under -/// about 20 mm), or one whose nearest centre leaves the area behind the globe's rim, keeps the area -/// in the middle, its circle clipping the globe (#2348). +/// whole: as near `area` as the camera draws a globe that small ([`drawable_globe_center`], the +/// equator when it draws it that small nowhere), the disc within the circle and the area on it. +/// A locator too small for the globe even on the equator (under about 20 mm), or one whose nearest +/// centre leaves the area behind the globe's rim, keeps the area in the middle, its circle +/// clipping the globe (#2348). Whether it is whole is measured on the disc drawn, not on the +/// camera's limit: a circle a little over the smallest globe holds it at that limit. pub(crate) fn globe_locator_center(map: &Map, area: Coord, scale: f64, side_mm: f64) -> (Coord, bool) { - let cam = |at: Coord| rustgis_map::layout::frame_camera(map, at, scale, 0.0, 0.0); - if cam(Coord::new(area.x, 0.0)).res >= rustgis_map::camera::MAX_RES { - return (area, false); - } - let at = drawable_globe_center(map, area, scale); let side = side_mm * rustgis_map::layout::PT_PER_MM; - if rustgis_map::globe::Globe::new(&cam(at), side, side).forward(area).is_some() { (at, true) } else { (area, false) } + let at = drawable_globe_center(map, area, scale); + let g = rustgis_map::globe::Globe::new(&rustgis_map::layout::frame_camera(map, at, scale, 0.0, 0.0), side, side); + if 2.0 * g.disc_radius() <= side && g.forward(area).is_some() { (at, true) } else { (area, false) } } /// Parses the publication's locator choice with its default: a globe on a sheet, none on a figure diff --git a/crates/engine/src/tests.rs b/crates/engine/src/tests.rs index 89ab85ea2..ededc3d6d 100644 --- a/crates/engine/src/tests.rs +++ b/crates/engine/src/tests.rs @@ -10379,6 +10379,28 @@ fn a_globe_locator_never_hides_its_area_behind_the_rim() { assert!(moved > 0 && hidden > 0, "{moved} moved, {hidden} kept on the area though the equator fits"); } +/// A globe locator a little over the smallest globe the camera draws holds it whole at that limit, +/// on the equator, and says nothing is clipped; one under it is clipped (#2348). +#[test] +fn a_globe_locator_at_the_camera_limit_is_whole_when_its_disc_fits() { + use rustgis_geom::Coord; + use rustgis_map::layout::{PT_PER_MM, frame_camera}; + let mut m = rustgis_map::Map::new("Locator"); + m.set_projection(rustgis_map::Projection::Globe); + // A scale past the camera's coarsest everywhere: the smallest globe it draws, on the equator. + let (area, scale) = (Coord::new(20.0, 30.0), 1e11); + let equator = Coord::new(area.x, 0.0); + let smallest = |side: f64| { + let cam = frame_camera(&m, equator, scale, 0.0, 0.0); + assert!(cam.res >= rustgis_map::camera::MAX_RES); + 2.0 * rustgis_map::globe::Globe::new(&cam, side * PT_PER_MM, side * PT_PER_MM).disc_radius() / PT_PER_MM + }; + let over = smallest(19.0) + 0.5; + assert_eq!(crate::cmd::layout::globe_locator_center(&m, area, scale, over), (equator, true), "a {over:.1} mm locator"); + let under = smallest(19.0) - 0.5; + assert_eq!(crate::cmd::layout::globe_locator_center(&m, area, scale, under), (area, false), "a {under:.1} mm locator"); +} + /// A publication's globe locator near a pole shows the globe whole in its circle (#2337): sized on /// the equator and centred as near the area as the camera draws it, not at the area's latitude, /// where the camera stops at its coarsest resolution and the disc came out larger than the circle. diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index 4d4808f9d..5f9d17aed 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -411,7 +411,8 @@ fn draw_page( { let ring = frame_outline_lonlat(om, &other.2, other.3, other.4); if let Some(map) = maps.get(mi) { - outline_lonlat(&mut frame_pm, map, &view, &ring, *extent_color, *extent_width as f32); + let from_globe = om.projection.is_globe(); + outline_lonlat(&mut frame_pm, map, &view, &ring, from_globe, *extent_color, *extent_width as f32); } } // Whole pixels, so the clipped image and its outline line up. @@ -1176,17 +1177,21 @@ fn frame_viewport( } /// Strokes the ring `ring` (longitude, latitude) on a frame's map `width` points wide: another -/// frame's extent, as an extent indicator shows it, broken at each `None`. -fn outline_lonlat(pm: &mut Canvas, map: &Map, view: &View, ring: &[Option], color: Rgba, width: f32) { +/// frame's extent, as an extent indicator shows it, broken at each `None`. `from_globe`: the ring +/// is a frame on the globe's, its longitudes run on across ±180° rather than kept in a world. +fn outline_lonlat(pm: &mut Canvas, map: &Map, view: &View, ring: &[Option], from_globe: bool, color: Rgba, width: f32) { let ppp = view.pixels_per_point as f32; // On a globe, through the globe as the frame draws it, breaking behind its horizon (#2348): // through the flat camera the outline lands off the area once it is away from the centre. let globe = map.projection.is_globe().then(|| rustgis_map::globe::Globe::new(&view.camera, view.width, view.height)); - // On a flat map, which doesn't wrap, the whole ring a turn east or west if that brings it - // nearer the frame's centre: its longitudes run on from its first point (#2348), which can be - // on the other side of ±180° from it. One shift for all keeps the ring in one piece. - let shift = match (&globe, ring.iter().flatten().next(), map.to_lonlat(view.camera.center)) { - (None, Some(c), Some(mid)) => 360.0 * ((mid.x - c.x) / 360.0).round(), + // A frame on the globe's ring on a flat map, which doesn't wrap: the whole ring a turn east or + // west if that brings the middle of its longitudes nearer the frame's centre, as they run on + // from its first point (#2348), which can be on the other side of ±180° from it. One shift for + // all keeps it in one piece. A flat frame's ring is drawn where it is. Not handled: a globe + // frame around a pole, whose ring spans a whole turn, so a stretch of it stays off the world. + let (west, east) = ring.iter().flatten().fold((f64::INFINITY, f64::NEG_INFINITY), |(w, e), c| (w.min(c.x), e.max(c.x))); + let shift = match (from_globe && globe.is_none() && west <= east, map.to_lonlat(view.camera.center)) { + (true, Some(mid)) => 360.0 * ((mid.x - (west + east) / 2.0) / 360.0).round(), _ => 0.0, }; let mut pb = PathBuilder::new(); @@ -5497,6 +5502,42 @@ Elaboração: RustGIS", } } + /// A flat frame wider than the world, outlined on another flat frame, is drawn where it is + /// (#2348): its first point past -180° doesn't move it a turn east, so both its sides show. + #[test] + fn a_flat_frame_wider_than_the_world_is_outlined_where_it_is() { + use rustgis_map::layout::{INDICATOR_COLOR, INDICATOR_WIDTH}; + let frame = |center, scale, extent_of| ElementKind::MapFrame { + map: "m".into(), + center, + scale, + shape: FrameShape::Rectangle, + grid: None, + extent_of, + extent_color: INDICATOR_COLOR, + extent_width: INDICATOR_WIDTH, + bearing: 0.0, + pitch: 0.0, + }; + let at = Coord::new(0.0, 0.0); + let mut l = Layout::new("Layout", 200.0, 120.0); + // 80 mm at 1:529M on the equator: about 380° of longitude, -190° to 190°. + let source = l.add("Main", (5.0, 5.0, 80.0, 20.0), frame(at, 5.29e8, None)); + // 90 mm at 1:593M: about 480°, so both of the source's sides are in it. + l.add("Locator", (100.0, 5.0, 90.0, 60.0), frame(at, 5.93e8, Some(source))); + let pm = render(&l, &mut [Map::new("m")], 96.0, &PageInfo::default()).unwrap(); + let k = PT_PER_MM; + let red = |x: u32, y: u32| { + let (r, g, b) = rgb(&pm, x, y); + r > 180 && g < 90 && b < 90 + }; + let (top, bottom) = ((5.0 * k) as u32, (65.0 * k) as u32); + let middle = 145.0 * k; + let side = |xs: std::ops::Range| xs.flat_map(|x| (top..bottom).map(move |y| (x, y))).filter(|&(x, y)| red(x, y)).count(); + let (west, east) = (side((100.0 * k) as u32..(middle - 10.0 * k) as u32), side((middle + 10.0 * k) as u32..(190.0 * k) as u32)); + assert!(west > 0 && east > 0, "the outline's sides: {west} red pixels west of the middle, {east} east"); + } + fn rgb(pm: &Pixmap, x: u32, y: u32) -> (u8, u8, u8) { pm.pixel(x, y).map(|p| (p.red(), p.green(), p.blue())).unwrap_or((255, 255, 255)) }