Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 16 additions & 5 deletions crates/render/src/polygon_labels_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,13 @@ fn depth(rings: &[Vec<Coord>], 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::<Vec<_>>());
/// 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::<Vec<_>>())
}

/// [`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())]);
Expand All @@ -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.
Expand Down Expand Up @@ -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:?}");
Expand Down
Loading