feat: mark_sf(merge = TRUE) dissolves adjacent same-fill regions - #142
Merged
Conversation
A choropleth built from many small features (counties grouped into regions) draws a border between every feature, meshing each colour block with internal seams. `merge = TRUE` dissolves each same-fill style group into one region: each feature's rings are unioned with vellum::vl_path_op() (interpreted even-odd, so holes and multipart features stay correct), producing a single winding path whose shared interior borders are gone -- one crisp outline per region, exact in PDF, no double-stroked seams. Raw coordinates are unioned and the result mapped once (the same map-once discipline as the batched emit). With fewer than two features in a group there is nothing to union, so it falls back to the ordinary emit; and it is skipped on an interactive layer, where the per-feature keys must survive. Docs: NEWS, a spatial-and-networks section, inst/examples/33-merged-regions.R, tests in test-sf-merge.R. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Wires the merged-choropleth half of WI-9:
vl_path_op()as region geometry. (The other half — clipping-as-geometry — stays a documented follow-up, as agreed; it's an architectural change to the viewport-mask pipeline and only benefits vector marks.)What
A choropleth built from many small features (counties grouped into regions) draws a border between every feature, meshing each colour block with internal seams.
mark_sf(merge = TRUE)dissolves each same-fill style group into one region.In
.emit_sf, each feature's rings become an operand (interpreted even-odd, so holes and multipart features stay correct) and are folded withvellum::vl_path_op(op = "union")into a single winding path — shared interior borders gone, one crisp outline per region, exact in PDF. Raw coordinates are unioned and the result mapped once (the same map-once discipline as the batched emit), reusing the venn.R unwrap/rewrap pattern.Boundaries
Verification (WI-0)
Rendered and looked at plain vs merged NC choropleths (internal county borders present → dissolved to one outline per region); confirmed a merged map renders to a valid PDF (
%PDF-, crisp geometry) and throughvellumwidget::as_widget();inst/examples/33-merged-regions.Rruns end to end.Deterministic tests in
test-sf-merge.R: two adjacent squares sharing an edge lose that edge when merged (border-pixel count halves), distinct fills are untouched, a single feature is a no-op, and an NC choropleth renders to PNG/PDF/scene. Full suite[ FAIL 0 | WARN 1 pre-existing | SKIP 0 | PASS 2880 ].No new exports (a
merge =argument onmark_sf()); requires the already-declared vellum >= 0.6.5.🤖 Generated with Claude Code