From e9df0314445c1ae5304fb311c234d16c5cfb5012 Mon Sep 17 00:00:00 2001 From: mavrick Date: Tue, 1 Dec 2026 20:06:52 -0600 Subject: [PATCH 1/2] test(render): keep polygon label blockers clear of neighbouring places --- crates/render/src/polygon_labels_tests.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/render/src/polygon_labels_tests.rs b/crates/render/src/polygon_labels_tests.rs index 94c44ae679..ae35e0ab1f 100644 --- a/crates/render/src/polygon_labels_tests.rs +++ b/crates/render/src/polygon_labels_tests.rs @@ -798,7 +798,16 @@ fn with_both_places_inside_taken_it_goes_round_its_polygon_corners_first() { (v.camera.bearing, v.camera.pitch) = (bearing, pitch); let (mut m, id) = islet(around.clone(), true); m.layer_mut(id).unwrap().labels.default.spacing = 25.0; - let taken = every_place(&mut m, &v); + let mut taken = Vec::new(); + while let Some(&here) = places(&mut m, &v).first() { + assert!(taken.len() < 24, "{taken:?}"); + taken.push(here); + block(&mut m, &v, &[here]); + // Cover this place, not its neighbours: at a tilt the inside label point can be + // close enough to the bottom edge that a normal-size blocker also hides the last + // outside place with some fonts (Segoe UI and the built-in Ubuntu Light). + m.layers.last_mut().unwrap().labels.default.size = 2.0; + } let bounds = screen_box(&v, &around); let sides: Vec<_> = taken.iter().map(|&p| side(bounds, p)).filter(|&s| s != INSIDE).collect(); assert_eq!(sides, ROUND, "turned {bearing}, tilted {pitch}: {taken:?} round {bounds:?}"); From 095ae6a2233ea1ddbb493d9bc4eea7420ebb48ee Mon Sep 17 00:00:00 2001 From: mavrick Date: Tue, 1 Dec 2026 20:46:41 -0600 Subject: [PATCH 2/2] test(render): resize the blocker by its layer id --- crates/render/src/polygon_labels_tests.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/crates/render/src/polygon_labels_tests.rs b/crates/render/src/polygon_labels_tests.rs index ae35e0ab1f..118ffdce78 100644 --- a/crates/render/src/polygon_labels_tests.rs +++ b/crates/render/src/polygon_labels_tests.rs @@ -84,13 +84,13 @@ fn depth(rings: &[Vec], p: Coord) -> f64 { if inside { best } else { -best } } -/// A point layer above the polygon with a heavier label centred at `places`, which take them. -fn block(m: &mut Map, v: &View, places: &[(f32, f32)]) { - block_at(m, &places.iter().map(|&p| at(v, p)).collect::>()); +/// Adds a heavier point-label blocker at `places`, returning its id for layer-order-independent edits. +fn block(m: &mut Map, v: &View, places: &[(f32, f32)]) -> u32 { + block_at(m, &places.iter().map(|&p| at(v, p)).collect::>()) } /// [`block`] at longitudes and latitudes. -fn block_at(m: &mut Map, places: &[Coord]) { +fn block_at(m: &mut Map, places: &[Coord]) -> u32 { let mut d = Dataset::new("blockers", GeometryType::Point, vec![Field::new("name", FieldType::Text)]); for &p in places { d.push(Some(Geometry::Point(p)), vec![Value::Text("XX".into())]); @@ -102,6 +102,7 @@ fn block_at(m: &mut Map, places: &[Coord]) { l.labels.default.placement = LabelPlacement::Center; l.labels.default.weight = 10; } + id } /// A square 44 points across in [`view`]: with [`islet`]'s spacing, narrower than its name. @@ -802,11 +803,12 @@ fn with_both_places_inside_taken_it_goes_round_its_polygon_corners_first() { while let Some(&here) = places(&mut m, &v).first() { assert!(taken.len() < 24, "{taken:?}"); taken.push(here); - block(&mut m, &v, &[here]); + let blocker = block(&mut m, &v, &[here]); // Cover this place, not its neighbours: at a tilt the inside label point can be // close enough to the bottom edge that a normal-size blocker also hides the last // outside place with some fonts (Segoe UI and the built-in Ubuntu Light). - m.layers.last_mut().unwrap().labels.default.size = 2.0; + m.layer_mut(blocker).unwrap().labels.default.size = 2.0; + assert_eq!(m.layer(id).unwrap().labels.default.size, 10.0, "the polygon label stays at its original size"); } let bounds = screen_box(&v, &around); let sides: Vec<_> = taken.iter().map(|&p| side(bounds, p)).filter(|&s| s != INSIDE).collect();