Repository navigation
Backport the required-width headland generator from v3.0 - #247
Merged
Gonzalo-Mier merged 7 commits intoAug 30, 2026
Merged
Gonzalo-Mier merged 7 commits into
Gonzalo-Mier merged 7 commits into
Conversation
Port getParallelLine, filterSelfIntersections, the segment accessors and bufferOutwards/bufferInwards from v3, plus Geometry::contains they rely on.
Add the robot and track angle overloads to HeadlandGeneratorBase, with the constant headland as default, so a generator can size each border itself.
Port f2c::hg::ReqHL from v3: a border the swaths run along is only entered, a border they end on takes a whole turn. Its clean-up buffer called the static Cell::buffer through an instance, so the dilation was thrown away and only a 1e-5 erosion ran; it now dilates and erodes as intended.
The figures were regenerated with another plotting backend in c760058; the line describing them was left behind.
Member
|
Thank you for the port and the PR, @u33549 |
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.
This is
f2c::hg::ReqHLfrom thev3.0branch, brought to the 2.x line together with the ring API it needs.What it does, briefly
A headland exists so the machine can turn, and how much room a turn needs depends on the angle between the swaths and the border they meet. A border the swaths run along is only driven into and left again; a border they end on takes a whole turn.
ConstHLcannot tell the two apart, so it charges every border the second figure:which runs from
R + W/2to2R + W/2 == maxHLWidthRequired. On a 100 m square with a 3 m machine and a 5 m turning radius,ConstHLtakes 11.5 m off all four borders where two of them need 6.5 m.What came across unchanged
Taken verbatim from
origin/v3.0(the same files inpre-v3.0are byte-identical, so there was no version to choose between):include/fields2cover/headland_generator/required_headland.hsrc/fields2cover/headland_generator/required_headland.cppHeadlandGeneratorBaseadditions:generateHeadlands(cell, robot, track_ang),generateHeadlands(cells, robot, track_angs),maxHLWidthRequired, with their default bodiesLinearRing:getParallelLine(both overloads),bufferOutwards,bufferInwards,filterSelfIntersections,removePoint,getSegment,getLastSegment,segmentLength,segmentAngGeometry::contains%rename(HG_Req_gen), the namev3.0's own.ifile gives the classThe mainland is built the way
v3.0does it: take the widest headland off once, then give each border back what it does not need, so no border is cut twice; interior rings the same way with the sign reversed, so an obstacle grows into the field.What we changed, and why
1. Constness.
v3.0declares the whole headland interfaceconst; nothing in the 2.x interface is. The two new overloads are therefore non-const here. Making themconstwould have meant changingConstHL's signatures and breaking every out-of-tree generator in the 2.x line.2.
generateHeadlandSwathsreturnsstd::vector<F2CCells>, this line's signature, instead ofv3.0'sstd::vector<F2CMultiLineString>— the base class differs between the lines. The body isConstHL's, as it is inv3.0.3. The clean-up buffer now does what it says. In both
v3.0andpre-v3.0:Cell::bufferis static, so calling it through an instance ignores the instance: the second call re-buffers the originalnew_celland the dilated result of the first is discarded. What reads as a closing — dilate, then erode, to heal the hairline spurs that per-segment offsetting leaves — is in fact a plain 1e-5 erosion, applied once per ring and once per cell.Three builds compared over 200 random fields on area, cell count and ring count:
The line as written never cleans anything, it only shrinks. Here it reads
F2CCell::buffer(F2CCell::buffer(new_cell, 1e-5), -1e-5), and the same for theF2CCellsline below it. These two lines are still as they were inv3.0.4.
%feature("notabstract")for the concrete generators.ConstHLandReqHLpull the base overloads in withusing HeadlandGeneratorBase::generateHeadlands;— needed in C++, since declaring a member of that name otherwise hides every base overload, and present inv3.0too. SWIG reads that declaration as an inherited pure virtual and marks the class abstract, sof2c.HG_Const_gen()raisesAttributeError: No constructor defined - class is abstract. The.ifile now says otherwise. This affectsConstHLinv3.0as well — it looks like the bindings were never exercised there after theusingwas added.5. Dropped: the
#include "fields2cover/utils/visualizer.h" // TODO: Remove this, and the// If d>0, the result is at the right side of the curve.comment ongetParallelLine— the offset goes to the left of the segment direction (ang + 0.5 * M_PI), which is what the tests measure.6. Tests. This is the largest thing we added.
v3.0'sreq_hl_test.cpphas one test that asserts nothing at all (it builds a field and plots it, commented out) and three that exercise only the constant-width methods;bufferInwardshas a single test and the rest of the ring API has none. 320 → 337 C++ tests and 106 → 111 Python tests here, all green, no existing test touched. Each formula was mutation-tested: reverting the angle term drops 5 tests, the interior-ring sign drops the obstacle test, the2 *inmaxHLWidthRequiredand the default dispatch each drop their own.They cover the width formula at 0°, 90°, 45° and its bound; one distance per segment rather than per point; the exact mainland rectangle and its transpose; an obstacle inside the field; one track angle per cell and the documented fallback without them; and the ring API on its own — parallel lines with a uniform and a per-segment offset, buffering in both directions from either winding, self-intersection filtering on a bow tie and on a doubled-back spur.
7. Tutorial and docs.
v3.0does not documentReqHL— itsheadland_generator.rstis identical to this line's. Section 3.2 is new, in both languages, with a figure. Plus a CHANGELOG entry.8. One adjacent one-liner (
64612cc): section 3.1 said "On orange it iscellsand in green it isno_hl", which was true until the figures were regenerated with another plotting backend inc760058— they have been blue and orange since. Easy to drop from the branch if you would rather keep this PR to one subject.We did not touch the behaviour anywhere else: the fallback when the number of track angles does not match the number of cells still returns a constant headland rather than throwing, as in
v3.0. We only made it explicit in a test.Not in this PR
The headland swaths are still constant-width:
generateHeadlandSwathsbuffers by a fixed distance, as it does inv3.0, where the class carries a// TODO: Return the headland swaths. Only the mainland boundary varies with the border angle here.