diff --git a/crates/render/src/polygon_labels_tests.rs b/crates/render/src/polygon_labels_tests.rs index 94c44ae679..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. @@ -798,7 +799,17 @@ 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); + 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.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(); assert_eq!(sides, ROUND, "turned {bearing}, tilted {pitch}: {taken:?} round {bounds:?}");