Skip to content
Merged
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions crates/engine/src/cmd/labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ pub fn commands() -> Vec<C> {
.inputs(super::Inputs::single_layer)
.when(need_feature_layer)
.params(
r#"{"layer"?, "class"?: name (none: the Default class, by whatever name it has), "position"?: "auto"|"center"|"above"|"below"|"left"|"right"|"aboveRight"|"aboveLeft"|"belowRight"|"belowLeft"|"parallel" (along a line, straight)|"curved" (along a line, following its bends)|"perpendicular" (a point's, square to the nearest line of `to`, starting at the point; none that near: as auto) (required without offset, repeat, lineOffset, otherPositions, showAll, weight, clearance, removeDuplicates, callout, to, side, fit, abbreviations or guide), "to"?: {"layer": a line or polygon layer's name, "within"?: points (1 to 500; 20)} | null, "side"?: "away" (the side of the line the point isn't on; the default)|"left"|"right" (as the line runs), "offset"?: [right, down] points (-200 to 200 each) the label moves from where its position puts it ([0, 0]: none; perpendicular: [out along the normal, down as the text reads]; a label along a line isn't moved), "repeat"?: points (10 to 10000) between a line's labels, spaced out from the one at its middle, at most 32 a line (0 or null: the one at its middle; parallel and curved only), "lineOffset"?: points (-200 to 200) between a line and its label's nearest edge, above the line as the text reads, negative below it (0 or null: on the line; parallel and curved only), "otherPositions"?: bool (a label whose place is taken tries others: a point's round the point, corners first; a line's along the line, nearest its middle first, placed parallel or curved without a repeat; a polygon's goes first where its shape fits best inside it, then where it goes without this; true is refused for any other line label, and on polygons for a curved label or one along a guide), "fit"?: "auto"|"off" (curved along a line: "auto" abbreviates a name that can't follow the line, sets one longer than a third of it on its straightest stretch, and spreads one over labels.style's stretch of a line more than three times its length; "off" or null: as placed), "abbreviations"?: {word: abbreviation} (whole words a fitted label puts short, ignoring case, over the built-in English, Portuguese and Spanish list, as {"Creek": "Cr.", "Córrego": "Cór."}; null or {}: the built-in list alone), "showAll"?: bool (every label drawn, over the others where they crowd), "weight"?: 0 to 10 (where labels compete for a place, the heavier class's wins, whatever its layer's place; equal weights: the layer above, then the class listed first; a fraction rounded; null: 5), "clearance"?: points (0 to 100: the room the class's labels keep free of other labels, two labels keeping both their clearances apart; null: 2), "removeDuplicates"?: points (1 to 2000: a label is left out within this distance of one placed before it for another feature of its layer and class with the same text; a label moved by hand always shows; false or null: off), "callout"?: true|false|points (5 to 500: a label crowded off its spot moves to a free one nearby, a line drawn back to its feature at most this long; true keeps its length, or 40; false, 0 or null: none; not labels along a line or with an icon), "guide"?: {"layer": a line layer's name (as ridge or valley lines; not drawn by this), "field"?: a field both layers have} | null (points and polygons, not perpendicular ones: each label curved along its guide line, the one with the feature's value in field, else the longest in view under the label inside its polygon, or the nearest to its point within the text's width; a feature with none its text fits along is labelled as without a guide; null: none)}"#,
r#"{"layer"?, "class"?: name (none: the Default class, by whatever name it has), "position"?: "auto"|"center"|"above"|"below"|"left"|"right"|"aboveRight"|"aboveLeft"|"belowRight"|"belowLeft"|"parallel" (along a line, straight)|"curved" (along a line, following its bends)|"perpendicular" (a point's, square to the nearest line of `to`, starting at the point; none that near: as auto) (required without offset, repeat, lineOffset, otherPositions, showAll, weight, clearance, removeDuplicates, callout, to, side, fit, abbreviations or guide), "to"?: {"layer": a line or polygon layer's name, "within"?: points (1 to 500; 20)} | null, "side"?: "away" (the side of the line the point isn't on; the default)|"left"|"right" (as the line runs), "offset"?: [right, down] points (-200 to 200 each) the label moves from where its position puts it ([0, 0]: none; perpendicular: [out along the normal, down as the text reads]; a label along a line isn't moved), "repeat"?: points (10 to 10000) between a line's labels, spaced out from the one at its middle, at most 32 a line (0 or null: the one at its middle; parallel and curved only), "lineOffset"?: points (-200 to 200) between a line and its label's nearest edge, above the line as the text reads, negative below it (0 or null: on the line; parallel and curved only), "otherPositions"?: bool (a label whose place is taken tries others: a point's round the point, corners first; a line's along the line, nearest its middle first, placed parallel or curved without a repeat; a polygon's goes first where its shape fits best inside it, then where it goes without this, then, if its text is wider or taller than the box of the polygon on the screen, round that box, corners first; true is refused for any other line label, and on polygons for a curved label or one along a guide), "fit"?: "auto"|"off" (curved along a line: "auto" abbreviates a name that can't follow the line, sets one longer than a third of it on its straightest stretch, and spreads one over labels.style's stretch of a line more than three times its length; "off" or null: as placed), "abbreviations"?: {word: abbreviation} (whole words a fitted label puts short, ignoring case, over the built-in English, Portuguese and Spanish list, as {"Creek": "Cr.", "Córrego": "Cór."}; null or {}: the built-in list alone), "showAll"?: bool (every label drawn, over the others where they crowd), "weight"?: 0 to 10 (where labels compete for a place, the heavier class's wins, whatever its layer's place; equal weights: the layer above, then the class listed first; a fraction rounded; null: 5), "clearance"?: points (0 to 100: the room the class's labels keep free of other labels, two labels keeping both their clearances apart; null: 2), "removeDuplicates"?: points (1 to 2000: a label is left out within this distance of one placed before it for another feature of its layer and class with the same text; a label moved by hand always shows; false or null: off), "callout"?: true|false|points (5 to 500: a label crowded off its spot moves to a free one nearby, a line drawn back to its feature at most this long; true keeps its length, or 40; false, 0 or null: none; not labels along a line or with an icon), "guide"?: {"layer": a line layer's name (as ridge or valley lines; not drawn by this), "field"?: a field both layers have} | null (points and polygons, not perpendicular ones: each label curved along its guide line, the one with the feature's value in field, else the longest in view under the label inside its polygon, or the nearest to its point within the text's width; a feature with none its text fits along is labelled as without a guide; null: none)}"#,
),
// Labels moved by hand (the Move Label tool, as QGIS's): kept by their feature's id.
C::new("labels.move", "Move Label", "Labeling › Label Placement", |s, p| {
Expand Down Expand Up @@ -687,7 +687,7 @@ fn label_guide(s: &Session, p: &Value, labelled: &Layer) -> Result<Option<Option

/// Whether a class on a layer holding these (points, lines, polygons) has other places to try when
/// its label's own is taken: round a point at any position (#1011), along a line for a label at its
/// middle (#1187), or inside a polygon for a label neither curved nor along a guide (#3268). Each
/// middle (#1187), or in and round a polygon for a label neither curved nor along a guide (#3268). Each
/// repeat is already a place of its own, so repeats get none.
fn tries_other_places((points, lines, polygons): (bool, bool, bool), c: &LabelClass) -> bool {
points || (lines && c.placement.along_line() && c.repeat.is_none()) || (polygons && c.places_inside_polygons())
Expand Down
4 changes: 2 additions & 2 deletions crates/map/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2309,8 +2309,8 @@ pub struct Map {
/// drawn while the lock holds, there, wherever the map moves. Filled by the renderer.
#[serde(skip)]
pub label_lock: Option<Vec<(LabelKey, LockedPlace)>>,
/// Geographic anchors of locked non-repeated line labels, and of polygon labels trying places
/// inside. Render cache only, never saved.
/// Geographic anchors of locked non-repeated line labels, and of polygon labels trying other
/// places, inside or round their polygon. Render cache only, never saved.
#[serde(skip)]
pub label_lock_line_anchors: std::collections::HashMap<LabelKey, Coord>,
/// Relationships, snapping, topology rules and edit settings.
Expand Down
3 changes: 2 additions & 1 deletion crates/map/src/symbology.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3013,7 +3013,8 @@ pub struct LabelClass {
pub placement: LabelPlacement,
/// A label taken by another tries nearby positions before it is left out (#1011):
/// round a point ([`LabelPlacement::alternatives`]), or along a non-repeated line. A polygon's
/// goes first where its shape fits best inside it (#3268).
/// goes first where its shape fits best inside it (#3268), and last,
/// if its text doesn't fit the polygon's box, round it (#3484).
/// Off by default: placed
/// elsewhere, a label may take the place another has today.
#[serde(default, deserialize_with = "de_flag", skip_serializing_if = "std::ops::Not::not")]
Expand Down
51 changes: 37 additions & 14 deletions crates/render/src/area_labels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,18 +374,39 @@ fn globe_outline(globe: &rustgis_map::Globe, mut ring: Vec<Coord>) -> Vec<(f32,
/// for no polygon, one with no area near the view (or this side of the horizon) or one with a
/// place behind the camera.
///
/// With `clip` (#3276), the rings are first cut to that view, so the place is in the polygon's
/// part in view and the view's edges count as its own: a name that fits in that part is whole on
/// the screen.
/// `rings` are [`shown_rings`]' of the label part. Cut to the view there (#3276), the place is in
/// the polygon's part in view and the view's edges count as its own: a name that fits in that part
/// is whole on the screen.
pub(super) fn pole(
ctx: &super::Ctx<'_>,
g: &rustgis_data::Geometry,
mut rings: Vec<Vec<(f32, f32)>>,
aspect: f32,
shown: Option<&super::View>,
clip: bool,
) -> Option<((f32, f32), (f32, f32))> {
#[cfg(test)]
SEARCHES.with(|n| n.set(n.get() + 1));
let here = ctx.view;
// A text of no measurable shape counts as square; a very long or tall one as 20 to 1.
let aspect = if aspect.is_finite() && aspect > 0.0 { aspect.clamp(0.05, 20.0) } else { 1.0 };
rings.iter_mut().flatten().for_each(|p| p.0 /= aspect);
let (x, y) = rustgis_tiles::symbols::pole_of_inaccessibility(&rings, 1.0)?;
let there = (x * aspect, y);
let Some(to) = shown else { return Some((there, there)) };
let m = to.camera.try_to_map(f64::from(there.0), f64::from(there.1), to.width, to.height)?;
let (x, y) = here.to_screen(m);
Some(((x as f32, y as f32), there))
}

/// The rings of `g`'s label part as [`pole`] searches them, in the points of the view the frame is
/// `shown` in (none: the frame's own), cut to the frame and that view with `clip`.
pub(super) fn shown_rings(
ctx: &super::Ctx<'_>,
g: &rustgis_data::Geometry,
shown: Option<&super::View>,
clip: bool,
) -> Option<Vec<Vec<(f32, f32)>>> {
#[cfg(test)]
THINNED.with(|n| n.set(n.get() + 1));
let mut rings = screen_rings(ctx, std::slice::from_ref(g.label_part()?))?;
let here = ctx.view;
// Cut to the frame before a tilted view is projected to: a vertex far outside the frame may be
Expand All @@ -403,15 +424,15 @@ pub(super) fn pole(
if let Some(to) = shown.filter(|_| clip) {
rings = clipped(&rings, to)?;
}
// A text of no measurable shape counts as square; a very long or tall one as 20 to 1.
let aspect = if aspect.is_finite() && aspect > 0.0 { aspect.clamp(0.05, 20.0) } else { 1.0 };
rings.iter_mut().flatten().for_each(|p| p.0 /= aspect);
let (x, y) = rustgis_tiles::symbols::pole_of_inaccessibility(&rings, 1.0)?;
let there = (x * aspect, y);
let Some(to) = shown else { return Some((there, there)) };
let m = to.camera.try_to_map(f64::from(there.0), f64::from(there.1), to.width, to.height)?;
let (x, y) = here.to_screen(m);
Some(((x as f32, y as f32), there))
Some(rings)
}

/// The box round [`shown_rings`], as left, top, right and bottom: what a label goes round when its
/// places inside are taken (#3484).
pub(super) fn around(rings: &[Vec<(f32, f32)>]) -> Option<(f32, f32, f32, f32)> {
let none = (f32::INFINITY, f32::INFINITY, f32::NEG_INFINITY, f32::NEG_INFINITY);
let (l, t, r, b) = rings.iter().flatten().fold(none, |(l, t, r, b), &(x, y)| (l.min(x), t.min(y), r.max(x), b.max(y)));
(l <= r && t <= b).then_some((l, t, r, b))
}

/// The parts of `rings` (an outer ring first) inside `view`'s box, in its points; `None` with none
Expand All @@ -434,6 +455,8 @@ fn clipped(rings: &[Vec<(f32, f32)>], view: &super::View) -> Option<Vec<Vec<(f32
thread_local! {
/// The [`pole`] searches made on this thread.
pub(super) static SEARCHES: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
/// The times [`shown_rings`] thinned a label's rings on this thread.
pub(super) static THINNED: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
}

/// [`glyphs`]' characters `advances` wide and `height` tall, as [`Line::curved`] takes them.
Expand Down
Loading
Loading