Repository navigation
fix(analysis): no gap between masks or zones that share an edge - #3518
Conversation
…ghbours leave no gap
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
| // even one polygon: collapsed rings have no filled area. Keep the original bounds too: | ||
| // rounding an edge must not hide a line the boolean overlay clips to it. | ||
| let valid = geo::CoordsIter::coords_count(&m) <= KEEP_WHOLE_COORDS | ||
| && crate::validity::check(Some(&in_plane(&m)), crate::validity::MAX_WORK).problems.is_empty(); |
There was a problem hiding this comment.
This check runs in the mask phase, inside try_map_on, which sizes its threads from largest_mask.saturating_mul(2) (line 2348). For a mask of up to KEEP_WHOLE_COORDS (10,000) coordinates, in_plane(&m) makes a full copy of its coordinates (about 160 KB at 16 bytes each), and validity::check holds about 100 bytes per coordinate (the doc on KEEP_WHOLE_COORDS, around line 2031), so roughly 1 MB per thread. That transient isn't in the budget this phase is sized from. The feature-level check at line 2482 is sized the same way, so this is the same gap in a second place. Suggest either adding the check's per-coordinate cost to largest_mask for this phase, or lowering the limit used here, and noting the measured peak in the PR (cargo xtask memory).
Category: performance
There was a problem hiding this comment.
Done in 2e2e080: this phase's share for a thread now has the copy in the plane and the check's state, about 116 bytes a coordinate, for a mask up to KEEP_WHOLE_COORDS.
Code reviewScope: Prior review threads: none on this PR, so there were no earlier concerns to leave alone. Bugs
Security
Performance
Quality
AGENTS.md
Change sizeCompared: the whole PR against main (merge base 21e9aa5 to PR head 1e3fdcf).
|
📖 Docs preview
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 |
|
On the Claude review of 1e3fdcf, in 2e2e080:
|
| // rounding an edge must not hide a line the boolean overlay clips to it. | ||
| let valid = geo::CoordsIter::coords_count(&m) <= KEEP_WHOLE_COORDS | ||
| && crate::validity::check(Some(&in_plane(&m)), crate::validity::MAX_WORK).problems.is_empty(); | ||
| let mask = if valid { m.orient(Direction::Default) } else { union_all(m.0.iter()) }; |
There was a problem hiding this comment.
Clip now keeps a valid multi-part mask as it is, but the other overlay tools still union one. mask_of (line 2599) unions any zone feature with more than one polygon, and Erase, Intersect, Identity, Union, Split and Update all go through it (callers at 2657, 2940, 7376, 8239–8240). So a multi-part zone still gets the rounded edges this PR removes from Clip, and the same input now gives different results in Clip and Intersect. The reason mask_of gives ("parts of one feature may overlap") is what validity::check now rules out through PartsOverlap, so the same gate could apply there. The PR's "as in the other overlay tools" holds only for one polygon. I checked the single-polygon branch and the other mask_of callers. Confidence: medium (about 65%): the gap for multi-part zones in those tools is the same defect this PR fixes for Clip.
Category: bug
There was a problem hiding this comment.
Confirmed, and what I said of these tools before was wrong: of 3,000 random pairs of two-part zones that share an edge, Erase left a sliver of 644, up to 3.5 mm wide, and of none of one part each. Fixed in 1ea4b68: zone_of keeps the edges of parts that are valid together. mask_of still unions the polygons of several features that Union's second pass and Tabulate Intersection gather, which touch each other as a rule.
| // Each mask is checked, and unioned unless it is valid: Cancel is looked at, and progress counted, | ||
| // before each. A thread holds a mask's polygons and their union, and for one small enough to be | ||
| // checked, a copy in the plane and about 100 bytes a coordinate ([`KEEP_WHOLE_COORDS`]). | ||
| let checked = largest_mask.min(KEEP_WHOLE_COORDS * std::mem::size_of::<Coord>()).saturating_mul(8); |
There was a problem hiding this comment.
The * 8 is a bare factor. The reply on the earlier thread says about 116 bytes a coordinate (16 for the copy in the plane, about 100 for the check), and * 8 on a 16-byte coordinate gives 128, which covers that. But nothing here says so, and checked names what the sum is used for, not what it measures. Name the factor, or put the per-coordinate figure in the comment above it.
Category: quality
There was a problem hiding this comment.
Named in 1ea4b68: edges_check_bytes, whose comment has the two figures.
|
|
||
| /// [`clip`] on `threads` threads (by the number of items in each step, and the memory each | ||
| /// takes, when `None`): the masks are unioned, and each input feature clipped, on their own | ||
| /// takes, when `None`): the masks are checked, those that aren't valid unioned, and each input feature clipped, on their own |
There was a problem hiding this comment.
The doc comment for clip_on is hard to read after this change. The first line is about 130 characters, and "the masks are checked, those that aren't valid unioned" is spliced into the middle of a sentence. The same applies to the added text at 2318 ("and what checking one takes"). Reflow the paragraph to the file's usual width.
Category: quality
Code reviewScope: Clip's mask handling in Bugs
Security
Performance
Quality
AGENTS.md
Change sizeCompared with
|
… too, so neighbours leave no gap
…veral features' gathered
Code reviewI found no blocking bugs, security issues or AGENTS.md breaks. I could not build or run the tests (no shell here), so everything below comes from reading the diff and the code it calls. I posted no inline comments, because none of the points below is specific enough to a line to justify one. Bugs
Security
Performance
Quality
AGENTS.md
Earlier concerns left alone: 4 (all in the existing threads). Change sizeCompared with the base branch: the whole PR, main (21e9aa5) to PR head (1ea4b68).
|
Summary
Clip unioned every mask on its own before use, which rounds each to a grid of its own. An edge two masks share could land on two places a fraction of a millimetre apart, and a feature across it came out in two parts where there is one (#2573; 0.24 mm in the reported case). A point on a mask's corner could be left out the same way.
A valid mask is now only oriented, so its edges stay where they are, as in the other overlay tools for one polygon. One that isn't valid, or has more than
KEEP_WHOLE_COORDScoordinates, is unioned as before, so a hole outside its own mask still can't cut a neighbour.Erase, Intersect, Identity, Union, Symmetrical Difference, Split and Update had the same gap between zones of several parts, which they unioned one by one: of 3,000 random pairs sharing an edge, Erase left a sliver of 644, up to 3.5 mm wide, and of none of one part each. A zone's parts that are valid together now keep their edges too.
Edges shared only in part on a slant still round apart, as before, and so do masks and zones of more than 10,000 coordinates.
Testing
knownmark is gone, so the check on pull requests holds it. Unioning every mask again fails four tests, and every zone of several parts another, of 100 of the random pairs.mainhits it in 3 and this in none.Real layers, release builds, three runs each (Hennepin one): CPU, and what came out
On Utrecht's property by neighbourhoods, Union takes 20.7 s of CPU for 19.3 s (the check of the neighbourhoods), Erase 22.8 s for 24.1 s, Intersect and Identity the same; on Oregon's blocks by flood zones, Erase takes 228 s for 234 s. Their areas are the same, but for Union's, by 0.2 m² in 41,546 km².
Peak memory is level or lower for Clip, and within 5% for the others. Areas differ by more than a millionth and 1e-3 m² in 34 of Oregon's 14,784 features, where the error against GEOS falls from 75.6 to 59.9 m² in total, in none of Utrecht's property and in one of Hennepin's 448,126. Utrecht's zoning has three fewer features, slivers that only the rounding made.
The desktop, the browser, the command line, Python, the Assistant and MCP, and the phone run the same tool. No command, parameter or saved file changes.
UI evidence
No visible UI change.
Related issue
Fixes #2573.
Summary by CodeRabbit