From 0e58e07fac0ea1b1028b6897b7c08c337978ae87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 17:38:13 -0500 Subject: [PATCH 01/10] fix(layout): extent indicators with one centre are numbered side by side (#3528) --- crates/render/src/layout.rs | 14 ++++- crates/render/src/layout/extent_tests.rs | 76 +++++++++++++++++++++++- crates/render/src/layout/frame.rs | 25 ++++++++ docs/user-guide/layouts.md | 7 ++- 4 files changed, 114 insertions(+), 8 deletions(-) diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index c7177a609e..4624a41a37 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -538,8 +538,18 @@ fn draw_page( // colour draws none, as it draws no outline, rather than a halo alone. let (cw, ch) = (frame_pm.width(), frame_pm.height()); let size = EXTENT_NUMBER_SIZE * 1.33 * fppp as f32; - for (n, color, (nx, ny)) in numbers { - if color.a() > 0 && on_frame(mask.as_ref(), (cw, ch), (nx, ny)) { + // Numbers that would fall on one another (outlines with one centre) are set apart + // in a row there, so each outline keeps one that can be told apart (#3528). A clear + // outline has none to set apart; a number the row would push off the frame stays + // where it was, as it would without the row. + let drawn: Vec<_> = numbers.into_iter().filter(|(_, color, _)| color.a() > 0).collect(); + let apart = set_apart(&drawn.iter().map(|n| n.2).collect::>(), size); + for ((n, color, was), moved) in drawn.into_iter().zip(apart) { + // Its middle is on the frame (inside its shape) for it to have a number at all. + let at = [moved, was].into_iter().find(|&at| on_frame(mask.as_ref(), (cw, ch), at)); + if on_frame(mask.as_ref(), (cw, ch), was) + && let Some((nx, ny)) = at + { text::text_at(&mut frame_pm, &n.to_string(), nx, ny, size, color, true, text::Align::Center, true); } } diff --git a/crates/render/src/layout/extent_tests.rs b/crates/render/src/layout/extent_tests.rs index 5edf576c24..c44e9af399 100644 --- a/crates/render/src/layout/extent_tests.rs +++ b/crates/render/src/layout/extent_tests.rs @@ -13,11 +13,16 @@ const SCALE: f64 = 2e8; /// A page with an overview of the map "Over" outlining one frame of the map "m" per centre in /// `centers` (longitude, latitude), numbered when `numbered`; only the overview is drawn. fn page(centers: &[(f64, f64)], numbered: bool, colors: &[[u8; 4]]) -> Layout { + page_at(¢ers.iter().map(|&c| (c, 100_000_000.0)).collect::>(), numbered, colors) +} + +/// [`page`] with each outlined frame's scale given too. +fn page_at(frames: &[((f64, f64), f64)], numbered: bool, colors: &[[u8; 4]]) -> Layout { let mut l = Layout::new("Layout", 100.0, 100.0); - let of: Vec = centers + let of: Vec = frames .iter() - .map(|&(x, y)| { - let kind = json!({"MapFrame": {"map": "m", "center": {"x": x, "y": y}, "scale": 100_000_000}}); + .map(|&((x, y), scale)| { + let kind = json!({"MapFrame": {"map": "m", "center": {"x": x, "y": y}, "scale": scale}}); let id = l.add("Detail", (60.0, 75.0, 30.0, 20.0), serde_json::from_value(kind).unwrap()); l.elements.iter_mut().filter(|e| e.id == id).for_each(|e| e.visible = false); id @@ -293,3 +298,68 @@ fn a_globe_overview_numbers_the_outline_where_the_globe_shows_it() { let centre = ((x * PT_PER_MM + at.0) as f32, (y * PT_PER_MM + at.1) as f32); assert!(changed.iter().all(|&p| centred(p, centre, 14.0)), "{changed:?}, expected about {centre:?}"); } + +/// Numbers on one point (outlines with one centre) are set apart in a row centred there, in list +/// order, each in its outline's colour, so every outline keeps a number that can be told apart +/// (#3528). +#[test] +fn outlines_with_one_centre_are_numbered_side_by_side() { + let l = page_at(&[((0.0, 0.0), 2e7), ((0.0, 0.0), 5e7)], true, &COLORS); + let drawn = written(&l, Map::new("Over"), &COLORS); + assert_eq!(said(&drawn), [("1", COLORS[0]), ("2", COLORS[1])]); + let (a, b) = (drawn[0].2, drawn[1].2); + assert!(b.0 - a.0 >= 10.0 && b.0 - a.0 <= 30.0 && (a.1 - b.1).abs() < 0.5, "{a:?} {b:?}"); + let middle = ((a.0 + b.0) / 2.0, (a.1 + b.1) / 2.0); + assert!(centred(middle, on_page(0.0, 0.0), 8.0), "the row is centred on {:?}, not {middle:?}", on_page(0.0, 0.0)); +} + +#[test] +fn three_outlines_with_one_centre_are_three_numbers_in_a_row() { + let l = page_at(&[((0.0, 0.0), 2e7), ((0.0, 0.0), 5e7), ((0.0, 0.0), 8e7)], true, &COLORS); + let drawn = written(&l, Map::new("Over"), &COLORS); + assert_eq!(said(&drawn), [("1", COLORS[0]), ("2", COLORS[1]), ("3", COLORS[2])]); + let step = drawn[1].2.0 - drawn[0].2.0; + assert!(step >= 10.0 && (drawn[2].2.0 - drawn[1].2.0 - step).abs() < 0.5, "{drawn:?}"); + assert!(centred(drawn[1].2, on_page(0.0, 0.0), 8.0), "{drawn:?}"); +} + +/// Outlines of the same size and centre are one outline twice: their numbers are apart too. +#[test] +fn outlines_the_same_size_with_one_centre_are_numbered_apart() { + let l = page_at(&[((0.0, 0.0), 5e7), ((0.0, 0.0), 5e7)], true, &COLORS); + let drawn = written(&l, Map::new("Over"), &COLORS); + assert_eq!(said(&drawn), [("1", COLORS[0]), ("2", COLORS[1])]); + assert!(drawn[1].2.0 - drawn[0].2.0 >= 10.0, "{drawn:?}"); +} + +/// Only the numbers that fall on one another move: another outline keeps its own centre. +#[test] +fn an_outline_away_from_a_shared_centre_keeps_its_number_where_it_was() { + let l = page_at(&[((0.0, 0.0), 2e7), ((0.0, 0.0), 5e7), ((35.0, -10.0), 1e8)], true, &COLORS); + let drawn = written(&l, Map::new("Over"), &COLORS); + assert_eq!(said(&drawn), [("1", COLORS[0]), ("2", COLORS[1]), ("3", COLORS[2])]); + assert!(centred(drawn[2].2, on_page(35.0, -10.0), 8.0), "{drawn:?}"); +} + +/// A clear outline draws no number, so it takes no place in the row either. +#[test] +fn a_clear_outline_with_the_same_centre_takes_no_place_in_the_row() { + let colors = [COLORS[0], [0, 0, 0, 0], COLORS[2]]; + let l = page_at(&[((0.0, 0.0), 2e7), ((0.0, 0.0), 5e7), ((0.0, 0.0), 8e7)], true, &colors); + let drawn = written(&l, Map::new("Over"), &colors); + assert_eq!(said(&drawn), [("1", colors[0]), ("3", colors[2])]); + let middle = (drawn[0].2.0 + drawn[1].2.0) / 2.0; + assert!(drawn[1].2.0 - drawn[0].2.0 >= 10.0 && (middle - on_page(0.0, 0.0).0).abs() < 8.0, "{drawn:?}"); +} + +/// A row never costs a number its place: one the row would push off the frame stays at its centre. +#[test] +fn a_number_the_row_would_push_off_the_frame_stays_at_its_centre() { + // A frame narrower than the row: each number's own centre is on it, the row's places are not. + let mut l = page_at(&[((0.0, 0.0), 2e7), ((0.0, 0.0), 5e7)], true, &COLORS); + let overview = l.elements.last_mut().unwrap(); + overview.w = 3.0; + let drawn = written(&l, Map::new("Over"), &COLORS); + assert_eq!(said(&drawn), [("1", COLORS[0]), ("2", COLORS[1])]); + assert_eq!(drawn[0].2, drawn[1].2, "both stay at the one centre: {drawn:?}"); +} diff --git a/crates/render/src/layout/frame.rs b/crates/render/src/layout/frame.rs index 9984999954..50d653b225 100644 --- a/crates/render/src/layout/frame.rs +++ b/crates/render/src/layout/frame.rs @@ -692,6 +692,31 @@ pub fn extent_number_mm( ((0.0..w).contains(&x) && (0.0..h).contains(&y)).then_some((x, y)) } +/// The places of numbers of `size` pixels (their font size), with the ones that fall on one +/// another (within `size` of the first of them, each way) spread in a row across that point, in +/// list order, 1.3 × `size` apart (room for two digits, as many as 16 outlines need), centred +/// where they fall. Numbers nowhere near another keep their place (#3528). +pub(super) fn set_apart(places: &[(f32, f32)], size: f32) -> Vec<(f32, f32)> { + let mut out = places.to_vec(); + let mut placed = vec![false; places.len()]; + for first in 0..places.len() { + if placed[first] { + continue; + } + let (fx, fy) = places[first]; + let on_it: Vec = + (first..places.len()).filter(|&i| !placed[i] && (places[i].0 - fx).abs() < size && (places[i].1 - fy).abs() < size).collect(); + let middle = on_it.iter().map(|&i| places[i].0).sum::() / on_it.len() as f32; + for (k, &i) in on_it.iter().enumerate() { + placed[i] = true; + if on_it.len() > 1 { + out[i].0 = middle + (k as f32 - (on_it.len() - 1) as f32 / 2.0) * size * 1.3; + } + } + } + out +} + /// Where a frame's map shows `c` (longitude, latitude), the middle of the frame outlined by /// `ring`, in pixels of its drawing: moved and cut as [`outline_lonlat`] moves and cuts that ring, /// so it falls with the outline, on the piece holding it. `None` where the map can't show it. diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index d943b2ab51..fa55e460f0 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -346,9 +346,10 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu `layout.update` with `"extentIndicator": {"color": "#555555", "width": 1}`. With several indicators, `of` says which: `{"of": 3, "width": 1}`, or `{"of": 3, "remove": true}`; `false` removes them all. **Number them**, in the same section, draws 1, 2, 3… in their order at the - centre of each outline, in its colour, so a key map points to numbered detail maps; removing one - renumbers the rest, and an outline centred off the frame has no number (`layout.update` with - `"extentNumbers": true`). The frame keeps the setting when all its indicators are removed, so + centre of each outline, in its colour, so a key map points to numbered detail maps; the numbers of + outlines with one centre go side by side in a row there. Removing one renumbers the rest, and an + outline centred off the frame has no number (`layout.update` with `"extentNumbers": true`). The + frame keeps the setting when all its indicators are removed, so the next one added is numbered. An outline breaks where the other frame's edge leaves the Earth (off a globe's disc, or past the edge of its projection's world) and runs up to it there, and where the overview's own projection can't show From b97fea383f7f4ac0252482ea13b593cfa49d9e0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 18:19:11 -0500 Subject: [PATCH 02/10] fix(layout): a row of extent numbers is used whole or not at all, and groups by chains of near places (#3528) --- crates/render/src/layout.rs | 15 ++++----- crates/render/src/layout/extent_tests.rs | 25 ++++++++++++++ crates/render/src/layout/frame.rs | 43 +++++++++++++++++------- docs/user-guide/layouts.md | 7 ++-- 4 files changed, 65 insertions(+), 25 deletions(-) diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index 4624a41a37..0aadb6f1b1 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -539,17 +539,14 @@ fn draw_page( let (cw, ch) = (frame_pm.width(), frame_pm.height()); let size = EXTENT_NUMBER_SIZE * 1.33 * fppp as f32; // Numbers that would fall on one another (outlines with one centre) are set apart - // in a row there, so each outline keeps one that can be told apart (#3528). A clear - // outline has none to set apart; a number the row would push off the frame stays - // where it was, as it would without the row. + // in a row there, so each outline keeps one that can be told apart (#3528); a row + // the frame can't hold whole isn't used, and a clear outline has no place in one. let drawn: Vec<_> = numbers.into_iter().filter(|(_, color, _)| color.a() > 0).collect(); - let apart = set_apart(&drawn.iter().map(|n| n.2).collect::>(), size); - for ((n, color, was), moved) in drawn.into_iter().zip(apart) { + let on = |at| on_frame(mask.as_ref(), (cw, ch), at); + let apart = set_apart(&drawn.iter().map(|n| n.2).collect::>(), size, on); + for ((n, color, was), (nx, ny)) in drawn.into_iter().zip(apart) { // Its middle is on the frame (inside its shape) for it to have a number at all. - let at = [moved, was].into_iter().find(|&at| on_frame(mask.as_ref(), (cw, ch), at)); - if on_frame(mask.as_ref(), (cw, ch), was) - && let Some((nx, ny)) = at - { + if on(was) { text::text_at(&mut frame_pm, &n.to_string(), nx, ny, size, color, true, text::Align::Center, true); } } diff --git a/crates/render/src/layout/extent_tests.rs b/crates/render/src/layout/extent_tests.rs index c44e9af399..a3b19c54e4 100644 --- a/crates/render/src/layout/extent_tests.rs +++ b/crates/render/src/layout/extent_tests.rs @@ -363,3 +363,28 @@ fn a_number_the_row_would_push_off_the_frame_stays_at_its_centre() { assert_eq!(said(&drawn), [("1", COLORS[0]), ("2", COLORS[1])]); assert_eq!(drawn[0].2, drawn[1].2, "both stay at the one centre: {drawn:?}"); } + +/// A row that doesn't fit the frame whole isn't used: three outlines with one centre on a frame too +/// narrow for it keep one place, not a middle number in the row's middle with the others on it. +#[test] +fn a_row_too_wide_for_the_frame_is_not_used_by_halves() { + let mut l = page_at(&[((0.0, 0.0), 2e7), ((0.0, 0.0), 5e7), ((0.0, 0.0), 8e7)], true, &COLORS); + l.elements.last_mut().unwrap().w = 3.0; + let drawn = written(&l, Map::new("Over"), &COLORS); + assert_eq!(drawn.len(), 3, "{drawn:?}"); + assert!(drawn.iter().all(|d| d.2 == drawn[0].2), "all at the one centre, as without the row: {drawn:?}"); +} + +/// Numbers linked by a chain of near pairs are one row, not the ones near the first alone. +#[test] +fn numbers_in_a_chain_of_near_places_are_one_row() { + let size = 13.3; + let chain = [(100.0, 50.0), (100.0 + 0.9 * size, 50.0), (100.0 + 1.8 * size, 50.0)]; + let apart = set_apart(&chain, size, |_| true); + assert!(apart.windows(2).all(|w| w[1].0 - w[0].0 >= size), "{apart:?}"); + // Places far from one another keep theirs. + let far = [(10.0, 10.0), (200.0, 10.0)]; + assert_eq!(set_apart(&far, size, |_| true), far); + // A row that doesn't fit leaves the group where it was. + assert_eq!(set_apart(&chain, size, |at| at.0 >= 100.0 && at.0 <= 101.0), chain); +} diff --git a/crates/render/src/layout/frame.rs b/crates/render/src/layout/frame.rs index 50d653b225..97f3e6af64 100644 --- a/crates/render/src/layout/frame.rs +++ b/crates/render/src/layout/frame.rs @@ -693,24 +693,43 @@ pub fn extent_number_mm( } /// The places of numbers of `size` pixels (their font size), with the ones that fall on one -/// another (within `size` of the first of them, each way) spread in a row across that point, in -/// list order, 1.3 × `size` apart (room for two digits, as many as 16 outlines need), centred -/// where they fall. Numbers nowhere near another keep their place (#3528). -pub(super) fn set_apart(places: &[(f32, f32)], size: f32) -> Vec<(f32, f32)> { +/// another (within `size` each way, linked to the first by a chain of such pairs) spread in a row +/// across their middle, in list order, 1.3 × `size` apart (room for two-digit numbers), where +/// `fits` says every place of the row is usable; else they keep their places, as without a row. Numbers +/// nowhere near another keep theirs (#3528). +pub(super) fn set_apart(places: &[(f32, f32)], size: f32, fits: impl Fn((f32, f32)) -> bool) -> Vec<(f32, f32)> { + let near = |a: (f32, f32), b: (f32, f32)| (a.0 - b.0).abs() < size && (a.1 - b.1).abs() < size; let mut out = places.to_vec(); let mut placed = vec![false; places.len()]; for first in 0..places.len() { if placed[first] { continue; } - let (fx, fy) = places[first]; - let on_it: Vec = - (first..places.len()).filter(|&i| !placed[i] && (places[i].0 - fx).abs() < size && (places[i].1 - fy).abs() < size).collect(); - let middle = on_it.iter().map(|&i| places[i].0).sum::() / on_it.len() as f32; - for (k, &i) in on_it.iter().enumerate() { - placed[i] = true; - if on_it.len() > 1 { - out[i].0 = middle + (k as f32 - (on_it.len() - 1) as f32 / 2.0) * size * 1.3; + placed[first] = true; + let mut group = vec![first]; + let mut at = 0; + while at < group.len() { + for other in 0..places.len() { + if !placed[other] && near(places[group[at]], places[other]) { + placed[other] = true; + group.push(other); + } + } + at += 1; + } + if group.len() < 2 { + continue; + } + group.sort_unstable(); + let middle = group.iter().map(|&i| places[i].0).sum::() / group.len() as f32; + let row: Vec<(f32, f32)> = group + .iter() + .enumerate() + .map(|(k, &i)| (middle + (k as f32 - (group.len() - 1) as f32 / 2.0) * size * 1.3, places[i].1)) + .collect(); + if row.iter().all(|&at| fits(at)) { + for (&i, at) in group.iter().zip(row) { + out[i] = at; } } } diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index fa55e460f0..df9779aae9 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -349,10 +349,9 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu centre of each outline, in its colour, so a key map points to numbered detail maps; the numbers of outlines with one centre go side by side in a row there. Removing one renumbers the rest, and an outline centred off the frame has no number (`layout.update` with `"extentNumbers": true`). The - frame keeps the setting when all its indicators are removed, so - the next one added is numbered. An outline breaks - where the other frame's edge leaves the Earth (off a globe's disc, or past the edge of its - projection's world) and runs up to it there, and where the overview's own projection can't show + frame keeps the setting when all its indicators are removed, so the next one added is numbered. + An outline breaks where the other frame's edge leaves the Earth (off a globe's disc, or past the + edge of its projection's world) and runs up to it there, and where the overview's own projection can't show the place. An outline across the overview map's edge (on a world projection, the meridian opposite its central one) is cut there, each piece on its side of the map, and so is a frame on the globe around a pole outlined on Web Mercator, at ±180°. From ba58da3bce05db583423509bdc680ccc5e2c8303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 18:30:53 -0500 Subject: [PATCH 03/10] fix(layout): extent numbers' row ignores numbers off the frame and doesn't land on ones outside its group (#3528) --- crates/render/src/layout.rs | 12 +++++------- crates/render/src/layout/extent_tests.rs | 24 ++++++++++++++++++++++++ crates/render/src/layout/frame.rs | 6 ++++-- 3 files changed, 33 insertions(+), 9 deletions(-) diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index 0aadb6f1b1..eaebf0b29c 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -540,15 +540,13 @@ fn draw_page( let size = EXTENT_NUMBER_SIZE * 1.33 * fppp as f32; // Numbers that would fall on one another (outlines with one centre) are set apart // in a row there, so each outline keeps one that can be told apart (#3528); a row - // the frame can't hold whole isn't used, and a clear outline has no place in one. - let drawn: Vec<_> = numbers.into_iter().filter(|(_, color, _)| color.a() > 0).collect(); + // the frame can't hold whole isn't used. A clear outline, or one whose middle is + // off the frame (inside its shape), has no number and no place in a row. let on = |at| on_frame(mask.as_ref(), (cw, ch), at); + let drawn: Vec<_> = numbers.into_iter().filter(|&(_, color, was)| color.a() > 0 && on(was)).collect(); let apart = set_apart(&drawn.iter().map(|n| n.2).collect::>(), size, on); - for ((n, color, was), (nx, ny)) in drawn.into_iter().zip(apart) { - // Its middle is on the frame (inside its shape) for it to have a number at all. - if on(was) { - text::text_at(&mut frame_pm, &n.to_string(), nx, ny, size, color, true, text::Align::Center, true); - } + for ((n, color, _), (nx, ny)) in drawn.into_iter().zip(apart) { + text::text_at(&mut frame_pm, &n.to_string(), nx, ny, size, color, true, text::Align::Center, true); } if !frame_pm.is_recording() && let Some(m) = &mask diff --git a/crates/render/src/layout/extent_tests.rs b/crates/render/src/layout/extent_tests.rs index a3b19c54e4..a865094205 100644 --- a/crates/render/src/layout/extent_tests.rs +++ b/crates/render/src/layout/extent_tests.rs @@ -388,3 +388,27 @@ fn numbers_in_a_chain_of_near_places_are_one_row() { // A row that doesn't fit leaves the group where it was. assert_eq!(set_apart(&chain, size, |at| at.0 >= 100.0 && at.0 <= 101.0), chain); } + +/// A row that would land on a number outside its group isn't used: the group keeps its places. +#[test] +fn a_row_is_not_laid_on_a_number_outside_its_group() { + let size = 13.3; + // Two on one place, a third 1.2 sizes away: not near them, but where the row's right place falls. + let places = [(100.0, 50.0), (100.0, 50.0), (100.0 + 1.2 * size, 50.0)]; + assert_eq!(set_apart(&places, size, |_| true), places); + // The same two with the third well away still get their row. + let away = [(100.0, 50.0), (100.0, 50.0), (300.0, 50.0)]; + let apart = set_apart(&away, size, |_| true); + assert!(apart[1].0 - apart[0].0 >= size && apart[2] == away[2], "{apart:?}"); +} + +/// A number whose own centre is off the frame takes no place in the row of the others. +#[test] +fn a_number_with_its_centre_off_the_frame_takes_no_place_in_the_row() { + // The overview shows about 72° either side; the third outline's centre (80°) is off it. + let l = page_at(&[((0.0, 0.0), 2e7), ((0.0, 0.0), 5e7), ((80.0, 0.0), 8e7)], true, &COLORS); + let drawn = written(&l, Map::new("Over"), &COLORS); + assert_eq!(said(&drawn), [("1", COLORS[0]), ("2", COLORS[1])]); + let middle = (drawn[0].2.0 + drawn[1].2.0) / 2.0; + assert!(drawn[1].2.0 - drawn[0].2.0 >= 10.0 && (middle - on_page(0.0, 0.0).0).abs() < 8.0, "{drawn:?}"); +} diff --git a/crates/render/src/layout/frame.rs b/crates/render/src/layout/frame.rs index 97f3e6af64..63ee02965a 100644 --- a/crates/render/src/layout/frame.rs +++ b/crates/render/src/layout/frame.rs @@ -695,7 +695,7 @@ pub fn extent_number_mm( /// The places of numbers of `size` pixels (their font size), with the ones that fall on one /// another (within `size` each way, linked to the first by a chain of such pairs) spread in a row /// across their middle, in list order, 1.3 × `size` apart (room for two-digit numbers), where -/// `fits` says every place of the row is usable; else they keep their places, as without a row. Numbers +/// `fits` says every place of the row is usable and it is near no number outside the group; else they keep their places, as without a row. Numbers /// nowhere near another keep theirs (#3528). pub(super) fn set_apart(places: &[(f32, f32)], size: f32, fits: impl Fn((f32, f32)) -> bool) -> Vec<(f32, f32)> { let near = |a: (f32, f32), b: (f32, f32)| (a.0 - b.0).abs() < size && (a.1 - b.1).abs() < size; @@ -727,7 +727,9 @@ pub(super) fn set_apart(places: &[(f32, f32)], size: f32, fits: impl Fn((f32, f3 .enumerate() .map(|(k, &i)| (middle + (k as f32 - (group.len() - 1) as f32 / 2.0) * size * 1.3, places[i].1)) .collect(); - if row.iter().all(|&at| fits(at)) { + // A row on a number outside the group would only move the overlap there. + let clear = places.iter().enumerate().all(|(i, &p)| group.contains(&i) || row.iter().all(|&at| !near(at, p))); + if clear && row.iter().all(|&at| fits(at)) { for (&i, at) in group.iter().zip(row) { out[i] = at; } From b9036e0a7326f070a1bfdb4d7c9cee3f38f1bc85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 18:42:20 -0500 Subject: [PATCH 04/10] fix(layout): a row of extent numbers isn't laid on a row laid before it (#3528) --- crates/render/src/layout/extent_tests.rs | 13 +++++++++++++ crates/render/src/layout/frame.rs | 2 +- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/render/src/layout/extent_tests.rs b/crates/render/src/layout/extent_tests.rs index a865094205..e82f832228 100644 --- a/crates/render/src/layout/extent_tests.rs +++ b/crates/render/src/layout/extent_tests.rs @@ -412,3 +412,16 @@ fn a_number_with_its_centre_off_the_frame_takes_no_place_in_the_row() { let middle = (drawn[0].2.0 + drawn[1].2.0) / 2.0; assert!(drawn[1].2.0 - drawn[0].2.0 >= 10.0 && (middle - on_page(0.0, 0.0).0).abs() < 8.0, "{drawn:?}"); } + +/// A row isn't laid on a row laid before it: two pairs 2 sizes apart would meet at 1.35 sizes. The +/// first pair is spread; the second, which would land on it, keeps its place, as before the rows. +#[test] +fn a_row_is_not_laid_on_another_row() { + let size = 13.3; + let places = [(100.0, 50.0), (100.0, 50.0), (100.0 + 2.0 * size, 50.0), (100.0 + 2.0 * size, 50.0)]; + let apart = set_apart(&places, size, |_| true); + assert!(apart[1].0 - apart[0].0 >= size, "the first pair is a row: {apart:?}"); + for (a, b) in [(0, 2), (0, 3), (1, 2), (1, 3)] { + assert!((apart[a].0 - apart[b].0).abs() >= size, "numbers of two groups within a size of each other: {apart:?}"); + } +} diff --git a/crates/render/src/layout/frame.rs b/crates/render/src/layout/frame.rs index 63ee02965a..eb3ea1fdcc 100644 --- a/crates/render/src/layout/frame.rs +++ b/crates/render/src/layout/frame.rs @@ -728,7 +728,7 @@ pub(super) fn set_apart(places: &[(f32, f32)], size: f32, fits: impl Fn((f32, f3 .map(|(k, &i)| (middle + (k as f32 - (group.len() - 1) as f32 / 2.0) * size * 1.3, places[i].1)) .collect(); // A row on a number outside the group would only move the overlap there. - let clear = places.iter().enumerate().all(|(i, &p)| group.contains(&i) || row.iter().all(|&at| !near(at, p))); + let clear = out.iter().enumerate().all(|(i, &p)| group.contains(&i) || row.iter().all(|&at| !near(at, p))); if clear && row.iter().all(|&at| fits(at)) { for (&i, at) in group.iter().zip(row) { out[i] = at; From bde642832662964547124cedfa00eaab25629971 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 18:50:33 -0500 Subject: [PATCH 05/10] test(layout): name the narrow-frame test for what it checks now (#3528) --- crates/render/src/layout/extent_tests.rs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/crates/render/src/layout/extent_tests.rs b/crates/render/src/layout/extent_tests.rs index e82f832228..387fe7f01b 100644 --- a/crates/render/src/layout/extent_tests.rs +++ b/crates/render/src/layout/extent_tests.rs @@ -352,9 +352,10 @@ fn a_clear_outline_with_the_same_centre_takes_no_place_in_the_row() { assert!(drawn[1].2.0 - drawn[0].2.0 >= 10.0 && (middle - on_page(0.0, 0.0).0).abs() < 8.0, "{drawn:?}"); } -/// A row never costs a number its place: one the row would push off the frame stays at its centre. +/// A row never costs a number its place: on a frame too narrow for the row, the group keeps its +/// places and each number is drawn at the one centre. #[test] -fn a_number_the_row_would_push_off_the_frame_stays_at_its_centre() { +fn a_row_too_wide_for_the_frame_keeps_each_number_at_its_centre() { // A frame narrower than the row: each number's own centre is on it, the row's places are not. let mut l = page_at(&[((0.0, 0.0), 2e7), ((0.0, 0.0), 5e7)], true, &COLORS); let overview = l.elements.last_mut().unwrap(); From 65d24942de127910636a9200d34e88f558126450 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 18:54:50 -0500 Subject: [PATCH 06/10] docs(layout): the numbers of close outlines go in a row too (#3528) --- crates/render/src/layout/frame.rs | 9 +++++---- docs/user-guide/layouts.md | 11 ++++++----- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/crates/render/src/layout/frame.rs b/crates/render/src/layout/frame.rs index eb3ea1fdcc..ce731ba7eb 100644 --- a/crates/render/src/layout/frame.rs +++ b/crates/render/src/layout/frame.rs @@ -693,10 +693,11 @@ pub fn extent_number_mm( } /// The places of numbers of `size` pixels (their font size), with the ones that fall on one -/// another (within `size` each way, linked to the first by a chain of such pairs) spread in a row -/// across their middle, in list order, 1.3 × `size` apart (room for two-digit numbers), where -/// `fits` says every place of the row is usable and it is near no number outside the group; else they keep their places, as without a row. Numbers -/// nowhere near another keep theirs (#3528). +/// another (outlines with one centre, or close ones: within `size` each way, linked to the first +/// by a chain of such pairs) spread in a row across their middle, in list order, 1.3 × `size` +/// apart (room for two-digit numbers). A row is used only where `fits` says every place of it is +/// usable and it is near no number outside the group nor a row laid before; else the group keeps +/// its places, as without a row. Numbers nowhere near another keep theirs (#3528). pub(super) fn set_apart(places: &[(f32, f32)], size: f32, fits: impl Fn((f32, f32)) -> bool) -> Vec<(f32, f32)> { let near = |a: (f32, f32), b: (f32, f32)| (a.0 - b.0).abs() < size && (a.1 - b.1).abs() < size; let mut out = places.to_vec(); diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index df9779aae9..9fe5725169 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -347,11 +347,12 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu indicators, `of` says which: `{"of": 3, "width": 1}`, or `{"of": 3, "remove": true}`; `false` removes them all. **Number them**, in the same section, draws 1, 2, 3… in their order at the centre of each outline, in its colour, so a key map points to numbered detail maps; the numbers of - outlines with one centre go side by side in a row there. Removing one renumbers the rest, and an - outline centred off the frame has no number (`layout.update` with `"extentNumbers": true`). The - frame keeps the setting when all its indicators are removed, so the next one added is numbered. - An outline breaks where the other frame's edge leaves the Earth (off a globe's disc, or past the - edge of its projection's world) and runs up to it there, and where the overview's own projection can't show + outlines that would fall on one another (one centre, or close ones) go side by side in a row + there. Removing one renumbers the rest, and an outline centred off the frame has no number + (`layout.update` with `"extentNumbers": true`). The frame keeps the setting when all its + indicators are removed, so the next one added is numbered. An outline breaks where the other + frame's edge leaves the Earth (off a globe's disc, or past the edge of its projection's world) + and runs up to it there, and where the overview's own projection can't show the place. An outline across the overview map's edge (on a world projection, the meridian opposite its central one) is cut there, each piece on its side of the map, and so is a frame on the globe around a pole outlined on Web Mercator, at ±180°. From 0e4e4847bc12cdcfb1c0900d0f0ba985773e8615 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 18:59:25 -0500 Subject: [PATCH 07/10] docs(layout): say the row of extent numbers is used where it fits whole, each keeping its height (#3528) --- crates/render/src/layout/frame.rs | 2 +- docs/user-guide/layouts.md | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/crates/render/src/layout/frame.rs b/crates/render/src/layout/frame.rs index ce731ba7eb..c91115942a 100644 --- a/crates/render/src/layout/frame.rs +++ b/crates/render/src/layout/frame.rs @@ -695,7 +695,7 @@ pub fn extent_number_mm( /// The places of numbers of `size` pixels (their font size), with the ones that fall on one /// another (outlines with one centre, or close ones: within `size` each way, linked to the first /// by a chain of such pairs) spread in a row across their middle, in list order, 1.3 × `size` -/// apart (room for two-digit numbers). A row is used only where `fits` says every place of it is +/// apart (room for two-digit numbers), each keeping its own height. A row is used only where `fits` says every place of it is /// usable and it is near no number outside the group nor a row laid before; else the group keeps /// its places, as without a row. Numbers nowhere near another keep theirs (#3528). pub(super) fn set_apart(places: &[(f32, f32)], size: f32, fits: impl Fn((f32, f32)) -> bool) -> Vec<(f32, f32)> { diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 9fe5725169..8b8f42e6c0 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -348,9 +348,10 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu removes them all. **Number them**, in the same section, draws 1, 2, 3… in their order at the centre of each outline, in its colour, so a key map points to numbered detail maps; the numbers of outlines that would fall on one another (one centre, or close ones) go side by side in a row - there. Removing one renumbers the rest, and an outline centred off the frame has no number - (`layout.update` with `"extentNumbers": true`). The frame keeps the setting when all its - indicators are removed, so the next one added is numbered. An outline breaks where the other + there (where the whole row fits the frame; otherwise they stay on one point). Removing one + renumbers the rest, and an outline centred off the frame has no number (`layout.update` with + `"extentNumbers": true`). The frame keeps the setting when all its indicators are removed, so + the next one added is numbered. An outline breaks where the other frame's edge leaves the Earth (off a globe's disc, or past the edge of its projection's world) and runs up to it there, and where the overview's own projection can't show the place. An outline across the overview map's edge (on a world projection, the meridian From bb2500123f68af5a77035814026fc19363f14689 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 19:04:49 -0500 Subject: [PATCH 08/10] docs(layout): the row of extent numbers also keeps its places when it would land on other numbers (#3528) --- crates/render/src/layout/frame.rs | 7 ++++--- docs/user-guide/layouts.md | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/crates/render/src/layout/frame.rs b/crates/render/src/layout/frame.rs index c91115942a..686e24b022 100644 --- a/crates/render/src/layout/frame.rs +++ b/crates/render/src/layout/frame.rs @@ -695,9 +695,10 @@ pub fn extent_number_mm( /// The places of numbers of `size` pixels (their font size), with the ones that fall on one /// another (outlines with one centre, or close ones: within `size` each way, linked to the first /// by a chain of such pairs) spread in a row across their middle, in list order, 1.3 × `size` -/// apart (room for two-digit numbers), each keeping its own height. A row is used only where `fits` says every place of it is -/// usable and it is near no number outside the group nor a row laid before; else the group keeps -/// its places, as without a row. Numbers nowhere near another keep theirs (#3528). +/// apart (room for two-digit numbers), each keeping its own height. A row is used only where +/// `fits` says every place of it is usable and it is near no number outside the group nor a row +/// laid before; else the group keeps its places, as without a row. Numbers nowhere near another +/// keep theirs (#3528). pub(super) fn set_apart(places: &[(f32, f32)], size: f32, fits: impl Fn((f32, f32)) -> bool) -> Vec<(f32, f32)> { let near = |a: (f32, f32), b: (f32, f32)| (a.0 - b.0).abs() < size && (a.1 - b.1).abs() < size; let mut out = places.to_vec(); diff --git a/docs/user-guide/layouts.md b/docs/user-guide/layouts.md index 8b8f42e6c0..f22fb5f946 100644 --- a/docs/user-guide/layouts.md +++ b/docs/user-guide/layouts.md @@ -348,10 +348,10 @@ Layouts open as tabs next to the maps; while one is open, its groups lead the Pu removes them all. **Number them**, in the same section, draws 1, 2, 3… in their order at the centre of each outline, in its colour, so a key map points to numbered detail maps; the numbers of outlines that would fall on one another (one centre, or close ones) go side by side in a row - there (where the whole row fits the frame; otherwise they stay on one point). Removing one - renumbers the rest, and an outline centred off the frame has no number (`layout.update` with - `"extentNumbers": true`). The frame keeps the setting when all its indicators are removed, so - the next one added is numbered. An outline breaks where the other + there (where the whole row fits the frame and clears the other numbers; otherwise they keep + their places). Removing one renumbers the rest, and an outline centred off the frame has no + number (`layout.update` with `"extentNumbers": true`). The frame keeps the setting when all its + indicators are removed, so the next one added is numbered. An outline breaks where the other frame's edge leaves the Earth (off a globe's disc, or past the edge of its projection's world) and runs up to it there, and where the overview's own projection can't show the place. An outline across the overview map's edge (on a world projection, the meridian From 94cd6b6296d2d05cb17954407068e67de8f091a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 19:10:41 -0500 Subject: [PATCH 09/10] test(layout): a row of extent numbers is checked against a shaped frame's edge (#3528) --- crates/render/src/layout/extent_tests.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/crates/render/src/layout/extent_tests.rs b/crates/render/src/layout/extent_tests.rs index 387fe7f01b..db1ef76e2c 100644 --- a/crates/render/src/layout/extent_tests.rs +++ b/crates/render/src/layout/extent_tests.rs @@ -426,3 +426,19 @@ fn a_row_is_not_laid_on_another_row() { assert!((apart[a].0 - apart[b].0).abs() >= size, "numbers of two groups within a size of each other: {apart:?}"); } } + +/// The row is checked against a shaped frame's mask: two outlines with one centre a little inside a +/// circle's edge would have their row's outer place outside it, so the group keeps its place. +#[test] +fn a_row_reaching_past_a_shaped_frames_edge_is_not_used() { + // The circle's edge is at about 30 mm: 52° east is some 29 mm out, and a row is 4 mm wide. + let mut l = page_at(&[((52.0, 0.0), 2e7), ((52.0, 0.0), 5e7)], true, &COLORS); + let drawn = written(&l, Map::new("Over"), &COLORS); + assert!(drawn[1].2.0 - drawn[0].2.0 >= 10.0, "on the rectangle the row is used: {drawn:?}"); + if let Some(ElementKind::MapFrame { shape, .. }) = l.elements.last_mut().map(|e| &mut e.kind) { + *shape = FrameShape::Circle; + } + let drawn = written(&l, Map::new("Over"), &COLORS); + assert_eq!(said(&drawn), [("1", COLORS[0]), ("2", COLORS[1])]); + assert_eq!(drawn[0].2, drawn[1].2, "on the circle the row doesn't fit: {drawn:?}"); +} From 34d2281f87015833b3bc65818dba48446fb899a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jorge=20Gregorio=20Rinc=C3=B3n?= Date: Tue, 1 Dec 2026 20:50:09 -0500 Subject: [PATCH 10/10] fix(layout): extent numbers' row takes in numbers it would land on and is checked with their width (#3528) --- crates/render/src/layout.rs | 4 ++- crates/render/src/layout/extent_tests.rs | 33 ++++++++++++++---- crates/render/src/layout/frame.rs | 43 +++++++++++++++--------- 3 files changed, 57 insertions(+), 23 deletions(-) diff --git a/crates/render/src/layout.rs b/crates/render/src/layout.rs index eaebf0b29c..ccfaaa6b06 100644 --- a/crates/render/src/layout.rs +++ b/crates/render/src/layout.rs @@ -544,7 +544,9 @@ fn draw_page( // off the frame (inside its shape), has no number and no place in a row. let on = |at| on_frame(mask.as_ref(), (cw, ch), at); let drawn: Vec<_> = numbers.into_iter().filter(|&(_, color, was)| color.a() > 0 && on(was)).collect(); - let apart = set_apart(&drawn.iter().map(|n| n.2).collect::>(), size, on); + // A row place fits where the number's whole width is on the frame, not only its centre. + let fits = |(x, y): (f32, f32)| on((x, y)) && on((x - 0.6 * size, y)) && on((x + 0.6 * size, y)); + let apart = set_apart(&drawn.iter().map(|n| n.2).collect::>(), size, fits); for ((n, color, _), (nx, ny)) in drawn.into_iter().zip(apart) { text::text_at(&mut frame_pm, &n.to_string(), nx, ny, size, color, true, text::Align::Center, true); } diff --git a/crates/render/src/layout/extent_tests.rs b/crates/render/src/layout/extent_tests.rs index db1ef76e2c..cc3b501fa7 100644 --- a/crates/render/src/layout/extent_tests.rs +++ b/crates/render/src/layout/extent_tests.rs @@ -390,14 +390,10 @@ fn numbers_in_a_chain_of_near_places_are_one_row() { assert_eq!(set_apart(&chain, size, |at| at.0 >= 100.0 && at.0 <= 101.0), chain); } -/// A row that would land on a number outside its group isn't used: the group keeps its places. +/// A number well away from a group keeps its place beside the group's row. #[test] -fn a_row_is_not_laid_on_a_number_outside_its_group() { +fn a_number_far_from_a_group_keeps_its_place_beside_its_row() { let size = 13.3; - // Two on one place, a third 1.2 sizes away: not near them, but where the row's right place falls. - let places = [(100.0, 50.0), (100.0, 50.0), (100.0 + 1.2 * size, 50.0)]; - assert_eq!(set_apart(&places, size, |_| true), places); - // The same two with the third well away still get their row. let away = [(100.0, 50.0), (100.0, 50.0), (300.0, 50.0)]; let apart = set_apart(&away, size, |_| true); assert!(apart[1].0 - apart[0].0 >= size && apart[2] == away[2], "{apart:?}"); @@ -442,3 +438,28 @@ fn a_row_reaching_past_a_shaped_frames_edge_is_not_used() { assert_eq!(said(&drawn), [("1", COLORS[0]), ("2", COLORS[1])]); assert_eq!(drawn[0].2, drawn[1].2, "on the circle the row doesn't fit: {drawn:?}"); } + +/// A number a row would land on joins the row instead of stopping it: two coincident outlines and a +/// third about one size away are three numbers in a row. +#[test] +fn a_number_near_a_group_joins_its_row() { + let size = 13.3; + let places = [(100.0, 50.0), (100.0, 50.0), (100.0 + size, 50.0)]; + let apart = set_apart(&places, size, |_| true); + let mut xs: Vec = apart.iter().map(|p| p.0).collect(); + xs.sort_by(f32::total_cmp); + assert!(xs.windows(2).all(|w| w[1] - w[0] >= size), "{apart:?}"); + // A row that then doesn't fit leaves all three where they were. + assert_eq!(set_apart(&places, size, |at| at.0 < 100.0 + size), places); +} + +/// A row is checked with its numbers' width: one whose centre is on the frame with its glyphs past +/// the edge isn't used, the numbers staying at the one centre. +#[test] +fn a_row_whose_numbers_would_be_clipped_at_the_frames_edge_is_not_used() { + // 67° west is about 10 px from the overview's left edge: the two centres of a row are 1 and 19. + let l = page_at(&[((-67.0, 0.0), 2e7), ((-67.0, 0.0), 5e7)], true, &COLORS); + let drawn = written(&l, Map::new("Over"), &COLORS); + assert_eq!(said(&drawn), [("1", COLORS[0]), ("2", COLORS[1])]); + assert_eq!(drawn[0].2, drawn[1].2, "both stay at the one centre: {drawn:?}"); +} diff --git a/crates/render/src/layout/frame.rs b/crates/render/src/layout/frame.rs index 686e24b022..05c71b6a55 100644 --- a/crates/render/src/layout/frame.rs +++ b/crates/render/src/layout/frame.rs @@ -695,10 +695,10 @@ pub fn extent_number_mm( /// The places of numbers of `size` pixels (their font size), with the ones that fall on one /// another (outlines with one centre, or close ones: within `size` each way, linked to the first /// by a chain of such pairs) spread in a row across their middle, in list order, 1.3 × `size` -/// apart (room for two-digit numbers), each keeping its own height. A row is used only where -/// `fits` says every place of it is usable and it is near no number outside the group nor a row -/// laid before; else the group keeps its places, as without a row. Numbers nowhere near another -/// keep theirs (#3528). +/// apart (room for two-digit numbers), each keeping its own height. A number the row would land +/// on joins it. A row is used only where `fits` says every place of it is usable and it is near +/// no number laid before; else the group keeps its places, as without a row. Numbers nowhere near +/// another keep theirs (#3528). pub(super) fn set_apart(places: &[(f32, f32)], size: f32, fits: impl Fn((f32, f32)) -> bool) -> Vec<(f32, f32)> { let near = |a: (f32, f32), b: (f32, f32)| (a.0 - b.0).abs() < size && (a.1 - b.1).abs() < size; let mut out = places.to_vec(); @@ -722,18 +722,29 @@ pub(super) fn set_apart(places: &[(f32, f32)], size: f32, fits: impl Fn((f32, f3 if group.len() < 2 { continue; } - group.sort_unstable(); - let middle = group.iter().map(|&i| places[i].0).sum::() / group.len() as f32; - let row: Vec<(f32, f32)> = group - .iter() - .enumerate() - .map(|(k, &i)| (middle + (k as f32 - (group.len() - 1) as f32 / 2.0) * size * 1.3, places[i].1)) - .collect(); - // A row on a number outside the group would only move the overlap there. - let clear = out.iter().enumerate().all(|(i, &p)| group.contains(&i) || row.iter().all(|&at| !near(at, p))); - if clear && row.iter().all(|&at| fits(at)) { - for (&i, at) in group.iter().zip(row) { - out[i] = at; + loop { + group.sort_unstable(); + let middle = group.iter().map(|&i| places[i].0).sum::() / group.len() as f32; + let row: Vec<(f32, f32)> = group + .iter() + .enumerate() + .map(|(k, &i)| (middle + (k as f32 - (group.len() - 1) as f32 / 2.0) * size * 1.3, places[i].1)) + .collect(); + // A number not yet placed that the row would land on joins it, and the row is laid again. + let joining: Vec = (0..places.len()).filter(|&i| !placed[i] && row.iter().any(|&p| near(p, places[i]))).collect(); + if joining.is_empty() { + // A row on a number outside the group (one already laid) would only move the overlap there. + let clear = out.iter().enumerate().all(|(i, &p)| group.contains(&i) || row.iter().all(|&at| !near(at, p))); + if clear && row.iter().all(|&at| fits(at)) { + for (&i, at) in group.iter().zip(row) { + out[i] = at; + } + } + break; + } + for i in joining { + placed[i] = true; + group.push(i); } } }