Repository navigation
fix(layout): a map frame can be centred on a pole in a polar projection (#2684) #2707
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,9 @@ pub const PAPER_M_PER_PT: f64 = 0.0254 / 96.0; | |
| pub const MIN_FRAME_SCALE: f64 = 0.5; | ||
| /// The smallest: the whole world many times over. | ||
| pub const MAX_FRAME_SCALE: f64 = 1e10; | ||
| /// The farthest north or south a map frame's centre may be (degrees): a pole is a place in a polar | ||
| /// projection (#2684). A map that can't show it has the centre moved ([`Layout::keep_centres_placeable`]). | ||
| pub const MAX_CENTER_LAT: f64 = 90.0; | ||
|
|
||
| /// The tokens a layout's text expands besides the map's ([`crate::graphics::TOKENS`], from its | ||
| /// first map frame), with what each shows. | ||
|
|
@@ -2527,7 +2530,7 @@ impl Layout { | |
| *center = Coord::new(0.0, 0.0); | ||
| } | ||
| center.x = center.x.clamp(-540.0, 540.0); | ||
| center.y = center.y.clamp(-85.0, 85.0); | ||
| center.y = center.y.clamp(-MAX_CENTER_LAT, MAX_CENTER_LAT); | ||
| if let FrameShape::Polygon(p) = shape { | ||
| let points = p.len(); | ||
| p.retain(|(u, v)| u.is_finite() && v.is_finite()); | ||
|
|
@@ -2658,8 +2661,33 @@ impl Layout { | |
| page_adjusted: usize::from(page_adjusted), | ||
| series_removed: usize::from(series_removed), | ||
| mgrs_off, | ||
| frames_moved: 0, | ||
| } | ||
| } | ||
|
|
||
| /// Moves the centre of each map frame past [`rustgis_geom::MAX_LAT`] whose map can't show it | ||
| /// to that limit, as a map drawn in Web Mercator (the globe too) does, and counts them. | ||
| /// [`Layout::clamp`] knows no map, so it keeps a pole, which a polar projection places; one | ||
| /// that can't place the centre but can place the limit at its longitude (World Mercator, | ||
| /// EPSG:3395) moves it, and a map that places the pole is left alone. A frame of a map not in | ||
| /// `maps` is left too. | ||
| pub fn keep_centres_placeable(&mut self, maps: &[Map]) -> usize { | ||
| let mut moved = 0usize; | ||
| for e in &mut self.elements { | ||
| if let ElementKind::MapFrame { map, center, .. } = &mut e.kind | ||
| && center.y.abs() > rustgis_geom::MAX_LAT | ||
| && let Some(m) = maps.iter().find(|m| m.name.eq_ignore_ascii_case(map)) | ||
| { | ||
| let limit = Coord::new(center.x, rustgis_geom::MAX_LAT.copysign(center.y)); | ||
| let mercator = matches!(m.flat(), crate::projection::Flat::Mercator); | ||
| if mercator || (m.to_map(*center).is_none() && m.to_map(limit).is_some()) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. World Mercator (EPSG:3395) frames centred between 85.05° and about 89.8° are neither moved nor said. The second branch only fires when A rule that matches the docs: move when the map places neither pole (cylindrical, like 3395), and leave polar maps alone, which place a pole. Add a test at 88° on EPSG:3395. Category: bug |
||
| center.y = limit.y; | ||
| moved = moved.saturating_add(1); | ||
| } | ||
| } | ||
| } | ||
| moved | ||
| } | ||
| } | ||
|
|
||
| /// What [`Layout::clamp`] changed in a layout. | ||
|
|
@@ -2679,6 +2707,9 @@ pub struct LayoutRepairs { | |
| /// Map frames whose grid had MGRS labels on a graticule or over a system other than a WGS 84 | ||
| /// UTM zone, turned off. | ||
| pub mgrs_off: usize, | ||
| /// Map frames whose map can't show their centre, past 85.05° latitude, moved to that limit | ||
| /// ([`Layout::keep_centres_placeable`], which the caller runs, as it knows the maps). | ||
| pub frames_moved: usize, | ||
| } | ||
|
|
||
| impl LayoutRepairs { | ||
|
|
@@ -3660,6 +3691,84 @@ mod tests { | |
| assert_eq!(serde_json::from_str::<Layout>(&saved).unwrap(), big); | ||
| } | ||
|
|
||
| /// The centre of the first map frame. | ||
| fn first_centre(l: &Layout) -> Coord { | ||
| match l.elements.first().map(|e| &e.kind) { | ||
| Some(ElementKind::MapFrame { center, .. }) => *center, | ||
| _ => panic!("frame expected"), | ||
| } | ||
| } | ||
|
|
||
| fn frames_at(lats: &[f64]) -> Layout { | ||
| let frames: Vec<String> = lats | ||
| .iter() | ||
| .enumerate() | ||
| .map(|(i, y)| { | ||
| format!( | ||
| r#"{{"id":{},"name":"f","x":0,"y":0,"w":50,"h":50,"kind":{{"MapFrame":{{"map":"M","center":{{"x":0,"y":{y}}},"scale":1e7}}}}}}"#, | ||
| i + 1 | ||
| ) | ||
| }) | ||
| .collect(); | ||
| serde_json::from_str(&format!(r#"{{"name":"x","width":100,"height":100,"elements":[{}]}}"#, frames.join(","))).unwrap() | ||
| } | ||
|
|
||
| #[test] | ||
| fn a_frame_centre_keeps_a_pole() { | ||
| // A pole is a place in a polar projection (#2684): kept, and no repair. | ||
| let mut l = frames_at(&[-90.0, 90.0, 200.0]); | ||
| let repairs = l.clamp(); | ||
| let lat = |i: usize| match l.elements.get(i).map(|e| &e.kind) { | ||
| Some(ElementKind::MapFrame { center, .. }) => center.y, | ||
| _ => panic!("frame expected"), | ||
| }; | ||
| assert_eq!((lat(0), lat(1), lat(2)), (-90.0, 90.0, 90.0)); | ||
| assert_eq!(repairs.elements_adjusted, 1, "only the centre past a pole is repaired: {repairs:?}"); | ||
| let mut l = frames_at(&[-90.0, 90.0]); | ||
| assert!(l.clamp().is_empty()); | ||
| // Not a number: back to 0, 0. | ||
| if let Some(ElementKind::MapFrame { center, .. }) = l.elements.first_mut().map(|e| &mut e.kind) { | ||
| *center = Coord::new(f64::INFINITY, f64::NAN); | ||
| } | ||
| assert_eq!(l.clamp().elements_adjusted, 1); | ||
| assert_eq!(first_centre(&l), Coord::new(0.0, 0.0)); | ||
| } | ||
|
|
||
| #[test] | ||
| fn mercator_frames_stop_at_its_limit() { | ||
| // Web Mercator ends at 85.05°: a frame in a map drawn in it is moved there and counted; | ||
| // one within it, one in no map of the project, and a frame on another map are not. | ||
| let maps = [Map::new("M")]; | ||
| let mut l = frames_at(&[-90.0, 90.0, 85.0, -85.0511, 12.0]); | ||
| l.clamp(); | ||
| assert_eq!(l.keep_centres_placeable(&maps), 2); | ||
| let lats: Vec<f64> = l | ||
| .elements | ||
| .iter() | ||
| .filter_map(|e| match &e.kind { | ||
| ElementKind::MapFrame { center, .. } => Some(center.y), | ||
| _ => None, | ||
| }) | ||
| .collect(); | ||
| assert_eq!(lats, [-rustgis_geom::MAX_LAT, rustgis_geom::MAX_LAT, 85.0, -85.0511, 12.0]); | ||
| assert_eq!(l.keep_centres_placeable(&maps), 0, "moved once"); | ||
| let mut l = frames_at(&[90.0]); | ||
| assert_eq!(l.keep_centres_placeable(&[Map::new("Other")]), 0, "its map isn't here"); | ||
| assert_eq!(first_centre(&l).y, 90.0); | ||
| // A polar projection places the pole: left. World Mercator can't: moved to its limit. | ||
| let map_in = |code: &str| { | ||
| let mut m = Map::new("M"); | ||
| m.set_projection(crate::Projection::Custom(code.into())); | ||
| m | ||
| }; | ||
| let mut l = frames_at(&[-90.0]); | ||
| assert_eq!(l.keep_centres_placeable(&[map_in("EPSG:3031")]), 0); | ||
| assert_eq!(first_centre(&l).y, -90.0); | ||
| let mut l = frames_at(&[-90.0, 80.0]); | ||
| assert_eq!(l.keep_centres_placeable(&[map_in("EPSG:3395")]), 1); | ||
| assert_eq!(first_centre(&l).y, -rustgis_geom::MAX_LAT); | ||
| } | ||
|
|
||
| #[test] | ||
| fn scale_bar_and_grid_label_sizes_default_and_are_kept_in_range() { | ||
| let page = |grid: &str, bar: &str| { | ||
|
|
@@ -3714,7 +3823,15 @@ mod tests { | |
| let repairs = l.clamp(); | ||
| assert_eq!( | ||
| repairs, | ||
| LayoutRepairs { elements_adjusted: 2, elements_cut: 0, elements_removed: 1, page_adjusted: 1, series_removed: 1, mgrs_off: 0 }, | ||
| LayoutRepairs { | ||
| elements_adjusted: 2, | ||
| elements_cut: 0, | ||
| elements_removed: 1, | ||
| page_adjusted: 1, | ||
| series_removed: 1, | ||
| mgrs_off: 0, | ||
| frames_moved: 0 | ||
| }, | ||
| "what changed is counted" | ||
| ); | ||
| assert!(l.clamp().is_empty(), "a repaired layout needs nothing more"); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -198,7 +198,12 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu | |
| from the whole world down to site plans at 1:20, finds at 1:1 and 2:1 (a scale of 1:0.5). | ||
| A frame can be turned and tilted like the map view: a new frame, or one matched to the view, | ||
| takes the view's bearing and pitch, and **Bearing** and **Pitch** in its properties (or | ||
| `layout.update` with `bearing` and `pitch`) set them. Its north arrows turn with it. **Grid** draws a labelled graticule over a frame; **Extent Indicator** outlines another frame's | ||
| `layout.update` with `bearing` and `pitch`) set them. Its north arrows turn with it. A frame's centre may be a pole (`layout.update` with | ||
| `center`, latitude -90 to 90): in a polar projection (EPSG:3031, 3413, 3995) a pole is an ordinary | ||
| point, and a frame centred on it keeps it at its middle. Web Mercator, the globe and World Mercator | ||
|
Comment on lines
+202
to
+203
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identify the supported pole for each projection. EPSG:3031 centres on the South Pole; EPSG:3413 centres on the North Pole. The opposite pole is outside the respective polar projection’s supported domain. Specify the pole for each example so readers do not expect either pole to work in every listed projection. (applications.pgc.umn.edu)
|
||
| (EPSG:3395) can't show one: a frame centred past 85.05° on a map in one of them, read from a layout | ||
| file or a project, is moved to that limit and a notice says so. | ||
|
Comment on lines
+204
to
+205
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Qualify the World Mercator repair condition. An EPSG:3395 centre at 86° can be projected, so
|
||
| **Grid** draws a labelled graticule over a frame; **Extent Indicator** outlines another frame's | ||
| extent (an overview map). | ||
| - **Frame borders**: the **Border** section of a frame's properties sets the line drawn round it, | ||
| along its shape for a round or polygon frame: its **Color** and **Line width** (dark grey and | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| { | ||
| "format": 2, | ||
| "name": "Frame centred on a pole", | ||
| "active_map": 0, | ||
| "maps": [ | ||
| { | ||
| "name": "Map", | ||
| "layers": [], | ||
| "basemap": "Paper", | ||
| "projection": {"Custom": "EPSG:3031"}, | ||
| "camera": {"center": {"x": 0, "y": 0}, "res": 30000} | ||
| } | ||
| ], | ||
| "layouts": [ | ||
| { | ||
| "name": "Polo", | ||
| "width": 150, | ||
| "height": 150, | ||
| "elements": [ | ||
| {"id": 1, "name": "Mapa", "x": 5, "y": 5, "w": 140, "h": 140, "kind": {"MapFrame": {"map": "Map", "center": {"x": 0, "y": -90}, "scale": 60000000, "shape": "Circle"}}} | ||
| ] | ||
| } | ||
| ] | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Require a capability for pole-centred layout frames.
A layout frame centred beyond ±85° of latitude is saved without a
requiresentry. Readers from before this change clamp that centre to ±85° and save the altered value, and the project then opens with no refusal. The repository's "Never silent" rule forbids saving a file again without the values the older version cannot read. The existing layout capabilities, such aslayout-frame-border, use the same mechanism for this case: an older reader refuses the project.Add a capability for saved layouts whose map frame centre lies beyond ±85° of latitude, following the pattern in
required_capabilities. Apply the same capability to saved commands that set such a centre, if an older reader would replay them with the clamp. Update the assertion atcrates/engine/src/project_capabilities.rs:1565so it expects the new capability, and add a test for the older-reader case. The current comment about reading "as it is written" does not cover older readers and should be revised.