Skip to content

feat(labels): a clearance per label class keeps the room round its labels free of other labels (#2828) - #2833

Draft
jgregoriorincon wants to merge 2 commits into
opengeos:mainfrom
jgregoriorincon:feat/2828-label-clearance
Draft

jgregoriorincon wants to merge 2 commits into
opengeos:mainfrom
jgregoriorincon:feat/2828-label-clearance

Conversation

@jgregoriorincon

Copy link
Copy Markdown
Contributor

Summary

Step 3b of #995: a clearance on each label class, the room its labels keep free of other labels. Until now every layer label kept the same 2 points clear of the others (Collide::default().text_padding), and nothing let a class change it: a map couldn't keep its river or district names well apart from the rest, nor pack small labels tighter where room is short.

  • Clearance. Each label class has a clearance from 0 to 100 points, 2 by default (the room every label kept before). The placement already grew each label's text box by its padding (label_boxes, crates/render/src/lib.rs); a layer's label now takes its class's clearance as that padding instead of the fixed 2. So two labels keep both their clearances apart, as before: 10 and 2 keep their texts at least 12 points apart (beyond their halos). Turned and curved labels' boxes grow by it as a straight one's do, and a callout looks for a spot clear of it. No new mechanism: the padding was already there.
  • Command. labels.placement takes "clearance": a number of points from 0 to 100; a fraction is kept; a number past 0 or 100 is brought to it, with a notice; null is 2; text that isn't a number is refused.
  • Pane. Labeling pane › Position shows a Clearance row under Weight, for the chosen class, in points. As the Weight row, a drag is one step, run when it is let go; the drag is kept to its layer and class, so choosing another layer mid-drag drops it.
  • Saved. LabelClass::clearance is read with #[serde(default)] and left out at 2, so existing projects draw and save as before. A project, map file or layer file with another clearance requires the new label-clearance capability, so an older RustGIS refuses it rather than dropping the clearances (docs/maintaining.md; fixture schema/fixtures/label_clearance.rgis). A clearance in a file that isn't a number from 0 to 100 is read held to that range (or as 2 when it isn't a number), with one notice on opening. A saved style with such a class, and a saved labels.placement step with a clearance other than 2 (in a task, a model or a script), require label-clearance too, since an older reader would apply the style, or run the step, without it.
  • Named clearance, not buffer: in the label styles the importer reads, "buffer" is the text's halo.
  • What gets worse: with a larger clearance, labels that fitted before can be left out or move to their other places (that is the point). A project with any clearance other than 2 doesn't open in an older RustGIS.
  • Unchanged: with every class at 2 the same labels are placed in the same places as before. Vector tile labels keep their style's text-padding; graphics' text and grid labels keep 2. Icons keep their own padding. A clearance change keeps a lock.
  • Docs: the user guide's label section has a Clearance entry; docs/maintaining.md lists the capability.

Not in this PR:

Testing

  • cargo fmt --all -- --check, cargo clippy on the four crates with --all-targets -- -D warnings, cargo nextest run --workspace (9306 passed; the local DuckDB tests left out), cargo test --workspace --doc, cargo xtask layers, cargo xtask schema --check (60 fixture projects open): all pass. command-surface.txt lists the new key.
  • New tests, written first, each seen failing for its reason before the code:
    • a_label_class_keeps_its_clearance_free_of_other_labels (render): two point layers 6 points apart between their halos keep both labels at 2 + 2; 5 on either one (5 + 2 > 6) leaves the lower one out; 3.9 (a fraction) keeps both; a point apart, 2 + 2 keep one out and 0 + 0 let both in; a label moved by hand keeps its class's clearance. Seen failing with the padding still fixed at 2.
    • a_label_class_takes_a_clearance (engine): the command, a fraction and a number in text kept, 500 and -3 held with their notices, refusals with their message, null, a named class, undo, a lock kept, requires, nothing written at 2, the fixture, and a damaged clearance in a file said once.
    • saved_label_clearances_are_required_by_name (engine): a task step with 8, 0, "8", 2.5 or 500 requires label-clearance; 2, null or no clearance don't; in a script; a saved style.
    • a_label_clearance_is_set_in_the_pane (desktop): the class's clearance shown, a typed 9.5 set, a slow drag in one undo step, and another layer chosen mid-drag leaving both layers' clearances and the undo history as they were.
  • hostile_params_never_panic covers the new key through the command's description.

UI evidence

The World Atlas sample over central Europe, the Cities labels on. Before (left, every class at 2): Bern, Budapest, Sarajevo and Belgium's name are drawn. After (right, Cities at 12): those labels are left out where a city's 12 points would reach them. With Cities back at 2 the map is the same, pixel for pixel, as before the change.

2828-before-after.png

The new Clearance row in Labeling pane › Position, under Weight:

2828-clearance-row.png

Reach every surface

  • Desktop, browser, command line, Python and phone: placement is in rustgis-render, which all of them draw labels with; the setting goes through labels.placement, which the pane, scripts, the command line, Python, the Assistant and MCP call.
  • Ribbon, shortcuts, command search, Assistant and MCP, plugins: no command is added; labels.placement's description lists the new key, so command search, the Assistant, MCP and plugins see it.
  • The way back: labels.placement with a clearance undoes in one step; null puts the default back.

New strings (Clearance and its hover text) wait for the release translation pass.

Related issue

Closes #2828 (part of #995).

@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Comment thread crates/render/src/lib.rs Resolved
Comment thread crates/render/src/lib.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Bugs

  • Callout leaders stop short of the text when a class has a clearance (crates/render/src/lib.rs, inline comment posted). The leader is measured to the clearance-padded box, not the glyphs. A clearance of 12 leaves a gap of about 12 points plus halo, and the reach check counts the padding too. Confidence: high. Visible at any clearance above 2. No test covers it.
  • The Move Label hit-test uses the padded box (crates/ui-egui/src/mapview.rs:2184, not in this PR's diff, so I could not post it inline). label_extent now includes the clearance, so label_at_where can pick a neighbouring label, and the drag outline grows. Confidence: medium-high. A click near a clearance-100 label can grab the wrong label. Suggested fix: pass unpadded boxes to label_extent, and add a test where a clearance-100 label sits beside a clearance-2 label.

Security

  • None found.

Performance

  • Placement cost rises with the clearance for vector layers (crates/render/src/lib.rs:8306, inline comment posted). Before this PR only tile labels could pad by up to 100. Now a clearance-100 label covers about 63 grid cells instead of 1 to 4, and a curved label adds one square per glyph. Confidence: medium. Nothing in the PR measures it. The PR should report timings for a dense layer at clearance 2 and at 100, or cap the padding used for the grid.

Quality

  • The pane drag test asserts a loose range, (2.5..4.0), which weakens the check that one drag is one step. Minor; the release quality pass can take it.

AGENTS.md

  • No rule breaks found. The label-clearance capability, the schema enum, the fixture, command-surface.txt, and the docs all match the rules. Label notices are counted per kind, and both directions are tested.

Checked and left alone: there were no prior review threads, so nothing was skipped. I confirmed that the load-time notices cover layers and styles, that the lenient parse matches the audit's adjusted check, and that the Collide default is 2, so "2 as before" holds.

Change size

Compared with the base branch: merge base 463133b to PR head 74e97c4.

Measure Value
Files changed 14 (1 added, 13 modified, 0 removed, 0 renamed)
Size before 5.17 MB
Size after 5.19 MB
Total size change +25.3 KB
Path Before After Change
crates/engine/src/tests.rs 3.47 MB 3.47 MB +6.95 KB
crates/ui-egui/src/labelpane.rs 127.2 KB 131.9 KB +4.65 KB
crates/render/src/lib.rs 825.0 KB 829.2 KB +4.24 KB
schema/fixtures/label_clearance.rgis 0 B 2.93 KB +2.93 KB
crates/engine/src/cmd/labels.rs 64.9 KB 66.6 KB +1.62 KB
crates/engine/src/project_capabilities.rs 108.5 KB 110.0 KB +1.56 KB
crates/map/src/symbology.rs 258.4 KB 259.7 KB +1.30 KB
crates/engine/src/project_label_losses.rs 24.0 KB 25.0 KB +836 B
docs/user-guide/cartography.md 72.0 KB 72.7 KB +724 B
docs/maintaining.md 18.0 KB 18.4 KB +322 B
crates/map/src/qgis/labels.rs 30.6 KB 30.7 KB +61 B
schema/project.schema.json 36.7 KB 36.8 KB +51 B
crates/engine/src/project.rs 151.0 KB 151.0 KB +23 B
crates/engine/command-surface.txt 25.2 KB 25.2 KB +11 B

@github-actions

github-actions Bot commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-2833/
Web app https://preview.rustgis.app/pr-2833/app/
Commit 1ddd1d9

GitHub Pages takes a minute or two to publish a new commit. Newer commits from the fork aren't published until a maintainer adds the preview label (once per commit).

@jgregoriorincon

Copy link
Copy Markdown
Contributor Author
  • Move Label hit-test (mapview.rs:2184): fixed in 1ddd1d9 by the same text_edges. label_extent now measures the text, not its clearance, so the pick and the drag outline are what they were at 2. The same test covers it (label_extent at 12 equals at 2), and it was seen failing first.
  • Drag test range: kept. egui takes the first few points of a drag to start it, so a float drag of 40 points at 0.1 a point lands near 3.3, not 3.0. The test's point is that every frame's part counts and that the drag is one undo step; the range says that, and the step count is asserted exactly.

@github-actions

Copy link
Copy Markdown
Contributor

Code review

I found no bugs, security problems, or AGENTS.md breaks in this PR. I read the full diff and the surrounding code, but did not build or run the tests.

Bugs

  • None found. I checked the clearance wiring end to end:
    • Every LabelClass literal sets the new field, and text_edges is used in all four callout and pick sites, so the earlier callout-leader thread is fixed in this head.
    • The loss counter (adjusted_clearance) agrees with lenient: a string clearance reads as 2 and is flagged.
    • The capability check mirrors the existing weight check.
    • Out-of-range and junk values are clamped or refused, and label_clearance maps non-finite input to the default, so no panic path.
    • Confidence: high.

Security

  • None found. Confidence: high.

Performance

  • Nit, low confidence: text_edges (crates/render/src/lib.rs:7990) clones the whole PlacedLabel, including its text and glyph vectors, on every call. label_extent runs per candidate in the Move Label pick (crates/ui-egui/src/mapview.rs:2184), which already clones each candidate, so the pick path roughly doubles its clone cost. The callout path is bounded by MAX_CALLOUT_SEARCHES. Passing the padding into label_boxes would avoid the clone. Impact is small.
  • The grid-cost concern in the earlier thread is already answered by the author. I did not raise it again.

Quality

  • Nit, cosmetic: the Clearance DragValue shows one decimal (max_decimals(1)), but the engine keeps the fraction, so a drag can store 3.07 and display 3.1. Harmless, and the pane otherwise mirrors the Weight row. Confidence: medium.

AGENTS.md

  • None found. The PR meets the rules I checked:
    • command-surface.txt is updated.
    • schema/project.schema.json is updated with the capability.
    • A fixture is added.
    • Both notice paths are tested, for lossy and clean input.
    • tl! wraps the new UI strings.
    • Surfaces are covered in the PR body.
    • The #[expect(clippy::too_many_arguments)] is needed, since callout_spot now takes eight parameters.

Earlier concerns left alone: 2. Both threads on crates/render/src/lib.rs (the placement-cost concern and the callout-leader concern) are already answered; the callout one is fixed in this head and I verified the fix.

No inline comments were posted, since nothing here rises above a nit.

Change size

Compared with main (merge base 463133b to PR head 1ddd1d9).

Measure Value
Files changed 14 (1 added, 13 modified, 0 removed, 0 renamed)
Size before 5.17 MB
Size after 5.20 MB
Total size change +28.4 KB
Path Before After Change
crates/render/src/lib.rs 825.0 KB 832.4 KB +7.4 KB
crates/engine/src/tests.rs 3.47 MB 3.47 MB +6.9 KB
crates/ui-egui/src/labelpane.rs 127.3 KB 131.9 KB +4.7 KB
schema/fixtures/label_clearance.rgis 0 B 2.9 KB +2.9 KB
crates/engine/src/cmd/labels.rs 64.9 KB 66.6 KB +1.6 KB
crates/engine/src/project_capabilities.rs 108.4 KB 110.0 KB +1.6 KB
crates/map/src/symbology.rs 258.4 KB 259.7 KB +1.3 KB
crates/engine/src/project_label_losses.rs 24.1 KB 24.9 KB +0.8 KB
docs/user-guide/cartography.md 72.0 KB 72.7 KB +0.7 KB
docs/maintaining.md 18.0 KB 18.4 KB +0.3 KB
crates/map/src/qgis/labels.rs 30.6 KB 30.7 KB +62 B
schema/project.schema.json 36.7 KB 36.8 KB +52 B
crates/engine/src/project.rs 151.0 KB 151.1 KB +23 B
crates/engine/command-surface.txt 25.2 KB 25.2 KB +11 B

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(labels): a clearance per label class: the room kept free of other labels round its labels (#995 step 3b)

1 participant