Repository navigation
Fix Cells::splitByLine throwing on a pinched split - #249
Merged
Gonzalo-Mier merged 4 commits intoSep 3, 2026
Merged
Gonzalo-Mier merged 4 commits into
Gonzalo-Mier merged 4 commits into
Conversation
A split can leave a piece touching itself at a single point. The piece was reinflated through Cell::buffer, which only accepts a single polygon back; a positive buffer on a pinched piece can separate it into two, and Cell(const OGRGeometry*) throws std::invalid_argument on the resulting MultiPolygon instead of decomposing the field. The reinflate step turns out to have never run: it reassigned the by-value loop variable of a range-for, never writing back into the result. Removing it fixes the crash and changes nothing for pieces that were never pinched, since the step was already a no-op for them. data/ee_field_130.wkt is a real field that reproduces the crash with BoustrophedonDecomp at several split angles (58, 60, 131, 142, 144, 147, 148, 152, 155, 160, 162 and 168 degrees, out of a 0-179 sweep).
Cells::splitByLine's reinflate loop looked fine but never ran: writing through a range-for's loop variable only reaches the container for the few types Iterator::update() whitelists. A comment at that whitelist says which containers do not write back, so the next person who hits this does not lose an afternoon to it.
There was a problem hiding this comment.
Pull request overview
This PR addresses a crash in Cells::splitByLine when splitting produces a “pinched” piece that can buffer into a MultiPolygon, causing Cell(const OGRGeometry*) to throw. The fix removes an ineffective “reinflate” loop (which previously didn’t write back to the Cells container), and adds a regression test + fixture WKT to cover the pinched-split scenario.
Changes:
- Simplify
Cells::splitByLine(const LineString&)to return the split result directly (removing the no-op reinflation loop). - Add a regression test that reproduces the pinched-split case using a real field WKT fixture.
- Document the iterator “range-for writes back only for some geometry types” pitfall and add a changelog entry.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| tests/cpp/decomposition/boustrophedon_decomp_test.cpp | Adds regression test loading a WKT fixture and asserting decomposition doesn’t throw for a pinch case. |
| src/fields2cover/types/Cells.cpp | Removes ineffective reinflation loop from Cells::splitByLine. |
| include/fields2cover/types/Geometries_impl.hpp | Adds clarifying comment about iterator write-back behavior for certain geometry types. |
| data/ee_field_130.wkt | Adds real-world WKT fixture used by the new regression test. |
| CHANGELOG.md | Documents the bugfix behavior change in the Unreleased “Fixed” section. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
loadWktCell used a raw OGRGeometry* with no null check: a missing file or a WKT parse failure would reach Cell(const OGRGeometry*) as a null pointer and segfault instead of failing the test. importFromWkt reads into an already-valid Cell, so there is no pointer to check; a failed read now leaves the cell empty and an explicit assertion catches it before the test can silently pass on a field that never loaded.
Gonzalo-Mier
reviewed
Sep 3, 2026
The reinflate step conserves each piece's size against the 1e-8-wide strip the cut itself removes -- necessary, not dead code as assumed. Restored it through Cells::buffer, which unlike Cell::buffer tolerates a piece coming out pinched into two. Chaining reinflate after every line in a MultiLineString split let GEOS collapse the next cut into a no-op, so every line is now buffered and cut together in one pass.
Member
|
Nice, thanks @u33549 for finding this bug! |
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.
A split can leave a piece touching itself at a single point (a pinch).
Cells::splitByLinereinflated each split piece throughCell::buffer, which only accepts a single polygon back; a positive buffer on a pinched piece can separate it into two, andCell(const OGRGeometry*)throwsstd::invalid_argumenton the resultingMultiPolygoninstead of decomposing the field.Reproduction
data/ee_field_130.wktis a real field. Decomposing it withBoustrophedonDecompthrows at 12 of 180 swept split angles (58, 60, 131, 142, 144, 147, 148, 152, 155, 160, 162, 168 degrees). Added asfields2cover_decomp_boustrophedon.doesNotThrowOnAPinchedSplit, using angle 58.The fix
The reinflate step turns out to have never run:
cis the range-for's by-value loop variable; assigning to it never writes back intocells. Verified directly — the container's WKT is byte-identical before and after this loop runs. So removing it fixes the crash and changes nothing for pieces that were never pinched, since the step already had no effect on them. The existingfields2cover_decomp_boustrophedon.decomposetest (an unrelated shape, no pinch involved) passes unchanged.