Repository navigation
Fix ReqHL producing a mainland smaller or larger than it should - #250
Gonzalo-Mier merged 5 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
The new regression test can throw via flatten().at(0) when no swaths are returned, which would crash the test instead of failing it cleanly.
Once you've addressed the issues Copilot identified, you can request another Copilot review.
Pull request overview
This PR fixes cases where ReqHL::generateHeadlands could violate its invariant bounds (collapsing the mainland almost to nothing or expanding it beyond the source field) on real, digitized field boundaries by making per-segment offsetting more numerically robust and by delegating self-intersection cleanup to GEOS buffering.
Changes:
- Harden
Point::intersectionOfLinesagainst near-parallel/collinear numeric overflow by using a scale-aware determinant tolerance. - Remove implicit self-intersection filtering from
LinearRing::getParallelLineand instead cleanReqHL’s per-segment offsets via GEOS buffering, allowing legitimate splits into multiple mainland polygons. - Add regression tests (including a real WKT fixture) and document the fixes in the changelog.
File summaries
| File | Description |
|---|---|
| tests/cpp/types/Point_test.cpp | Adds a regression test for near-parallel line intersection behavior. |
| tests/cpp/types/LinearRing_test.cpp | Adds a regression test ensuring buffering past a redundant vertex doesn’t explode coordinates. |
| tests/cpp/headland_generator/req_hl_test.cpp | Adds a real-world regression test ensuring ReqHL doesn’t collapse or exceed the field area. |
| src/fields2cover/types/Point.cpp | Updates intersection logic to treat near-parallel lines as parallel using a scaled tolerance. |
| src/fields2cover/types/LinearRing.cpp | Stops auto-calling filterSelfIntersections() inside getParallelLine. |
| src/fields2cover/headland_generator/required_headland.cpp | Refactors ReqHL headland generation to offset the exterior, subtract buffered obstacles, and clean via GEOS buffer. |
| data/ee_field_103.wkt | Adds a digitized real-world field boundary fixture for regression testing. |
| CHANGELOG.md | Documents the two fixes in the “Fixed” section. |
Review details
- Files reviewed: 8/8 changed files
- Comments generated: 1
- Review effort level: Lite
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
|
i found new bugs on there i will fix them |
|
Added a third fix on top of the other two: On real, digitized field boundaries this sent Verified against an independent sweep of 350 real field boundaries: 15 of 17 previously-escaping runs (8 of 9 fields) are fixed. The ninth traces back to a decomposition issue upstream of both headland generators, not this join, and is being tracked separately. |
|
It's done rn |
|
A new great PR! Thanks @u33549 |
The parallel check compared the determinant to exactly 0. Two real-world collinear borders -- a redundant vertex on an otherwise straight, digitized field edge -- produce a determinant that is 0 only up to rounding, and dividing by that sends the result arbitrarily far from either line instead of near where they meet. Fixes the overflow class of ReqHL::generateHeadlands producing a mainland larger than its input field. A second, distinct failure mode (area collapsing towards 0 on densely digitized cells) survives this fix and is still open.
Offsetting hundreds of segments by widely different amounts crosses the resulting ring many times over. Cleaning that up fell to LinearRing::filterSelfIntersections, which resolves one crossing at a time and drops every point between the two segments involved -- most of a real border, if that crossing is a distant one. A 274-vertex field collapsed from 6875 m2 to 1 m2 this way. The exterior ring's offset is cleaned up with a GEOS buffer instead, which handles the same self-intersections properly and can come back as more than one mainland cell where the ring legitimately splits -- something a method built to return a single LinearRing never could. filterSelfIntersections() itself is untouched; getParallelLine() no longer calls it, since the one caller that needs cleanup now does its own.
LinearRing::getParallelLine joined each corner with the plain line-line miter intersection, which has no bound on how far it can land as the corner sharpens or the two sides' offsets diverge. On real fields this sent ReqHL's mainland up to 273 m outside the field it came from, occasionally taking a coverage swath with it. Past 4 times the larger of the two offsets, bevel instead.
3bafe0b to
ae11ea0
Compare
|
Force-pushed while tidying up my fork. The only difference is in CHANGELOG.md: the three entries were accidentally placed under the released [2.1.0] heading and are now under [Unreleased]. No source or test changes. |
|
Thank you @u33549 for the PR |
ReqHL::generateHeadlandshas an invariant:ConstHL(worst case) <= ReqHL <= field. On real, digitized field boundaries it broke both directions -- a mainland collapsing to near nothing, or growing past the field it came from. Both traced back to the same operation: offsetting a ring by a different distance per segment (LinearRing::bufferOutwards, used only byReqHL).Overflow:
Point::intersectionOfLineson near-parallel linesEach new vertex is the intersection of two offset segments' lines. The parallel check compared the determinant to exactly 0, but a redundant vertex on an otherwise straight, digitized edge gives two collinear segments whose determinant is 0 only up to rounding -- dividing by that sent the vertex arbitrarily far from either line.
One real field's mainland came out larger than the field it was cut from --
bufferOutwardssent a single vertex tens of metres from the rest of the ring.Collapse:
LinearRing::filterSelfIntersectionson a heavily digitized borderOffsetting hundreds of segments by widely different amounts crosses the resulting ring many times over. Cleaning that up fell to
filterSelfIntersections, which resolves one crossing at a time and drops every point between the two segments involved -- most of a real border, if that crossing is a distant one. A 274-vertex field collapsed from 6875 m2 to 1 m2 this way.The fix moves cleanup out of the offsetting step and into a GEOS buffer, which resolves the same self-intersections properly and can come back as more than one mainland cell where the ring legitimately splits -- something a method built to return a single
LinearRingnever could:getParallelLineno longer callsfilterSelfIntersectionsitself; the one caller that needed cleanup now does its own.filterSelfIntersectionsis untouched and still does what its own tests ask of it.