Skip to content

fix: the raster mask form keeps a draft per map, and layer.mask finds its mask by name and kind - #3371

Merged
elpidioassinaturas merged 2 commits into
opengeos:mainfrom
elpidioassinaturas:fix/3147-mask-form-map-key
Nov 29, 2026
Merged

elpidioassinaturas merged 2 commits into
opengeos:mainfrom
elpidioassinaturas:fix/3147-mask-form-map-key

Conversation

@elpidioassinaturas

@elpidioassinaturas elpidioassinaturas commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Two small corrections to masking by a raster's values, from the review of #3360.

  • The raster mask form keeps a draft per map. The draft of the Masking menu's and Layer Properties' raster mask form was kept by layer id alone. Layer ids are a map's own, so after switching maps, a layer with the same id could open with the other map's draft (its raster, range and feather). The draft is now kept by the map's instance_id and the layer id (raster_mask_form_id).
  • layer.mask finds its mask layer by name and kind together. It took the first layer of that name and then checked its kind. Names can collide after a rename, so with a polygon layer v above a raster v, layer.mask with {"raster": "v", …} was refused with "no raster layer 'v'", though the drawing finds that raster. mask_layer now takes the first layer of that name that is a raster (or, for a polygon mask, a polygon), as the renderer does. For a raster mask it also passes over the layer itself, as the renderer's raster lookup does, so a raster masked by another raster of its own name isn't refused; a raster alone with its name still is. The planner binds the layer found, rather than the first layer of the name.

Testing

Each test was written first and failed:

  • layer_mask_finds_the_raster_past_a_polygon_of_that_name (engine): a polygon layer renamed to the DEM's name, above it; masking by the DEM was refused with "no raster layer 'dem'" and now sets the mask.

  • the_raster_mask_form_starts_again_when_the_layers_mask_changes (ui-egui) now also asserts that the same layer id on two maps has two drafts; both gave the same Id before.

  • layer_mask_takes_another_raster_of_the_layers_own_name (engine, review round 1): the first of two rasters of one name, masked by that name, was refused with "a layer can't mask itself"; it now takes the other.

  • cargo fmt --check and cargo clippy --all-targets -- -D warnings on engine and ui-egui.

  • cargo test (Windows): engine 2918 passed, with layout_report_text::a_report_measures_each_layout_page_with_its_own_page_number failing locally on other branches too (text measurement); ui-egui 1781 lib and 135 integration passed (run with RUSTGIS_LANGUAGE=en, as this machine's locale isn't English).

Size: 71 changed lines (+57 −14), after review round 1.

UI evidence

No visible UI change: the form looks and works as before; only where its draft is kept changed.

Related issue

Follow-up to #3360 (#3147).

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Raster masks now select a matching raster even when a same-named polygon appears first. A raster layer can also use a subsequent same-named raster as its mask.
    • Raster-mask editing drafts are now kept separate across maps and layers, preventing changes in one map or layer from affecting another. Same-map editing remains consistent.

…k by name and kind

Follow-up to opengeos#3360 (opengeos#3147), from its review. Each test was written first
and failed:
- the_raster_mask_form_starts_again_when_the_layers_mask_changes
  (ui-egui) asserts the same layer id on two maps keeps two drafts: the
  draft was kept by layer id alone, and layer ids are a map's own. It is
  now kept by the map's instance_id and the layer id.
- layer_mask_finds_the_raster_past_a_polygon_of_that_name (engine): a
  polygon renamed to a raster's name, above it, made layer.mask refuse
  with "no raster layer". mask_layer now takes the first layer of that
  name and kind, as the renderer does, and the planner binds it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change updates how raster mask names resolve to map layers and how raster-mask form draft state is keyed. Known mask names bind directly to a matching layer of the required kind. Form IDs now include both map and layer identity.

Changes: Raster mask behavior

Layer / File(s) Summary
Resolve and bind mask layers
crates/engine/src/cmd/effects.rs, crates/engine/src/tests/raster_mask.rs
Known mask names bind directly to a matching polygon or raster layer. Lookup skips same-name layers of the wrong kind. Raster self-masks can use a later matching raster layer. Tests cover same-name polygon and raster layers.
Scope raster-mask form state
crates/ui-egui/src/ribbon.rs
The raster-mask form draft ID includes the map instance ID and layer ID. Tests check that IDs differ when either identity differs.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Possibly related issues

Possibly related PRs

  • opengeos/RustGIS#3327: This PR changes layer selection and planner binding for the raster-mask command introduced there.
  • opengeos/RustGIS#3360: This PR changes the draft-state key used by the raster-mask form added there.

Suggested reviewers: mavrick-f, giswqs

Merge Risk: Minimal · up to 014c7

This change makes raster masks resolve to the correct layer when names collide and keeps raster-mask form drafts separate between maps. No actionable merge risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names both changes in the PR: the raster mask form draft is kept per map, and layer.mask finds its mask by name and kind. The raw summary confirms the engine mask_layer change and the ui-egu…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Description check Passed The description has the Summary and Testing sections filled in with specific detail: a per-map draft keyed by instance_id and layer id, a fix to layer.mask name-and-kind lookup, and new tests with the…
Full details: Title check

Explanation

The title names both changes in the PR: the raster mask form draft is kept per map, and layer.mask finds its mask by name and kind. The raw summary confirms the engine mask_layer change and the ui-egui form-ID change, so the title is accurate. It is long (95 characters, 19 words) and joins two fixes with a comma, which makes it heavier than ideal but still clear.

Full details: Description check

Explanation

The description has the Summary and Testing sections filled in with specific detail: a per-map draft keyed by instance_id and layer id, a fix to layer.mask name-and-kind lookup, and new tests with their results. The UI evidence section states no visible UI change, which the template allows. The Related issue section cites #3360 and #3147 as a follow-up. The template comment asks for the issue reference in the form 'Closes #' or 'Part of #', and the author wrote 'Follow-up to #3360 (#3147)'. That is a minor formatting difference and the reference is clear. Overall the description is substantially complete.

Finishing Touches

Generate unit tests (beta)

  • Create a new PR
  • 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

A rabbit checks the layer names at dawn,
It finds the right mask and hops along.
Map and layer IDs keep drafts apart,
Two tidy keys for each form’s start.
The burrow hums; the masks align,
And carrots wait beside the line.

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: e6ac4fa2-a723-44e5-87d1-c438356cf171
Commits

Reviewing files that changed from the base of the PR and between 30b4042 and 014c75d.

Files selected for processing: 3

  • crates/engine/src/cmd/effects.rs
  • crates/engine/src/tests/raster_mask.rs
  • crates/ui-egui/src/ribbon.rs

Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 5 remain after this review.

Comment thread crates/ui-egui/src/ribbon.rs Resolved
Comment thread crates/engine/src/cmd/effects.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Scope: 3 files, +37/−9 lines. prior-reviews.json has no threads, so nothing was skipped as already raised.

Bugs

  • Refusal of a valid raster mask when the target is itself a same-named raster (crates/engine/src/cmd/effects.rs:408). The doc says mask_layer finds the layer "as the renderer finds it", but the renderer's raster lookup (render/src/lib.rs:7612) skips the target layer before matching. This lookup doesn't, so the command refuses with "a layer can't mask itself" where the drawing would use the other raster. No wrong picture is drawn. Confidence: medium-low, not run.

Security

  • None found.

Performance

  • None found. The lookups are linear scans over the layer list, as before.

Quality

  • No nits posted separately.

AGENTS.md

  • assert_eq! with identical sides (crates/ui-egui/src/ribbon.rs:5990). assert_eq!(super::raster_mask_form_id(1, 7), super::raster_mask_form_id(1, 7)) has the same tokens on both sides, which cargo xtask test-hygiene refuses, so CI fails. The suggestion binds one call to a name. Confidence: high.

Checked and not raised

  • mask_inputs binding: the live branch now binds the kind-matched layer by instance, where before Inputs::named bound the first layer of that name. The executor still resolves by name, as before. No regression found.
  • Twins: the polygon mask lookup in render/src/lib.rs:7512 already matches name and kind and is consistent. The raster lookup at render/src/lib.rs:7612 is the self-skipping case above. layer_copy.rs:342 holds names only and is unchanged. The ui-egui draft key uses Map::instance_id, which snapshots preserve, so undo doesn't reset drafts. No #[cfg(wasm32)] or layer.add*/project.open* branches changed.
  • egui::Id::unique is deterministic in this codebase (used as a stable focus id), so the id tests are valid.

Change size

Compared with the base branch (merge base 6ab826a to PR head 30b4042), the whole PR.

Measure Value
Files changed 3 (0 added, 3 modified, 0 removed, 0 renamed)
Size before 346.2 KB
Size after 347.8 KB
Total size change +1.6 KB
Path Before After Change
crates/engine/src/tests/raster_mask.rs 8.8 KB 9.5 KB +756 B
crates/ui-egui/src/ribbon.rs 318.5 KB 319.0 KB +567 B
crates/engine/src/cmd/effects.rs 18.9 KB 19.3 KB +321 B

@github-actions

github-actions Bot commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

📖 Docs preview

Item Value
Preview https://preview.rustgis.app/pr-3371/
Web app https://preview.rustgis.app/pr-3371/app/
Commit 014c75d

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).

…aster of its name (opengeos#3371 review)

mask_layer now passes over the target for a raster mask, as the
renderer's raster lookup does, and still refuses a raster that is the
only one of its name. Test first:
layer_mask_takes_another_raster_of_the_layers_own_name (refused with "a
layer can't mask itself" before).

The form-id test compares two layers on one map instead of a call with
itself, which cargo xtask test-hygiene refuses.

Follow-up to opengeos#3360 (opengeos#3147).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comment thread crates/ui-egui/src/ribbon.rs Resolved
@github-actions

Copy link
Copy Markdown
Contributor

Code review

Overall: no bugs or security issues found. The core fix matches the renderer, and the earlier review threads are addressed. The findings below are quality points and one PR-description gap.

Bugs

  • None found. I checked mask_layer (crates/engine/src/cmd/effects.rs:404) against the renderer's raster lookup (crates/render/src/lib.rs:7612). Both take the first layer of the name and kind in list order (insert_on_top puts the top layer at index 0) and skip only the target. Confidence: high.

Security

  • None found.

Performance

  • None found.

Quality

  • Draft key uses the reusable map-local layer id (crates/ui-egui/src/ribbon.rs:4579, inline comment posted). Layer::instance_id() is the stable key the codebase uses for owners. Confidence: medium.
  • Widget ids are still salted by layer id alone in the same class of bug the PR fixes: layerprops.rs:483, panes.rs:7918, panes.rs:7958 and ribbon.rs:4612. The effect is UI-only (collapsing and combo state shared across maps with the same layer id). Confidence: medium.
  • layer_mask_takes_another_raster_of_the_layers_own_name (crates/engine/src/tests/raster_mask.rs:79-89) asserts only that the mask is accepted. Both rasters have the same name, so the assertion can't show which one was chosen. Confidence: high that the assertion is weak.

AGENTS.md

  • The PR body doesn't say which surfaces the change reaches. The rule asks for this before calling a change done (desktop, CLI, Python, Assistant/MCP, undo). The engine change reaches these through the shared command, but the body should say so. Confidence: medium.

Earlier concerns

I left two earlier concerns alone. Both were already raised, answered and resolved: the assert_eq! token-match hygiene issue (fixed in 014c75d) and the raster self-mask refusal (fixed in 014c75d). I re-checked both fixes against the code and they hold.

Not checked

I had no shell, so I did not run the tests or cargo xtask. I also did not verify that egui::Id::unique is hash-based rather than a counter. That call predates this PR.

Change size

Compared with the base branch (main, merge base 6ab826a to PR head 014c75d). This covers the whole PR, not only the latest push.

Measure Value
Files changed 3 (0 added, 3 modified, 0 removed, 0 renamed)
Size before 346.2 KB
Size after 348.8 KB
Total size change +2.6 KB
File Before After Change
crates/engine/src/tests/raster_mask.rs 8.8 KB 10.3 KB +1.5 KB
crates/ui-egui/src/ribbon.rs 318.5 KB 319.0 KB +567 B
crates/engine/src/cmd/effects.rs 19.0 KB 19.4 KB +463 B

@elpidioassinaturas
elpidioassinaturas added this pull request to the merge queue Nov 29, 2026
Merged via the queue into opengeos:main with commit acefad7 Nov 29, 2026
30 checks passed
@elpidioassinaturas
elpidioassinaturas deleted the fix/3147-mask-form-map-key branch November 29, 2026 20:40
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.

2 participants