Repository navigation
Carve a corridor between decomposed cells, and fix three silent failures - #243
Conversation
f7c2fa9 to
b203259
Compare
|
Hi @u33549, please, tell me when this is ready to review/merge |
|
Hi @Gonzalo-Mier, i think it's ready but I was quite confused while developing, there may be parts I missed. |
|
Hi @u33549, Wow. I'm seriously out of words. Awesome job!!! Just a few things.
Thank you again @u33549 |
|
With the second one you mentioned, you really did find a bug, but I have a solution in mind—I'll try it out and send it to you. |
|
Thank you for the PR, @u33549! We have a new planner |



Decomposing a field and then covering it currently forces a choice between two bad
options, and the tutorial itself takes the worse one. This PR adds the missing operation
and fixes two crashes/silent skips found while building it.
The problem, in the project's own words
docs/source/tutorials/decomposition.rstexplains the decomposition + route plannerworkflow like this:
That third step is the problem.
ConstHL::generateHeadlandsshrinks every border, sorunning it a second time takes another headland off the outer boundary that already has
one. The cells do get separated — but the whole field also loses a second ring it never
needed to lose.
What is missing is an operation that opens a corridor only where two cells meet.
What this adds
For each border edge, the part a neighbour actually touches is intersected and cut. Two
details matter:
corridor. Testing whole edges (endpoints + midpoint) misses that case entirely.
each side notches both cells, and a notched cell costs the swath generator a pass — the
narrow arm gives way, the large band keeps its rectangle.
The decomposition tutorial now uses it instead of the second headland.
Numbers
Full pipeline — headland → decompose → swaths → route → path (
DubinsCurvesCC),F2CRobot(2.1, 2.5),minTurningRadius = 0.4,maxDiffCurv = 2.0.The outer headland is equal on both sides (6.00 m, measured, not assumed), so the only
difference left is the method.
Ais today's double-headland flow,Bis the corridor.efficiency = swath length / total path length — how much of the driving does work.
gap = measured clearance between neighbouring cells; outer = measured clearance from the
field boundary.
Across four fields: workable area +2…8%, connection distance −7…−74 m,
efficiency +1.0…+3.3pp. The gain scales with headland width — measured on
comb, anouter headland of 2.5 m gives 0%, 6.0 m gives 3%, 10.0 m gives 6%.
Pictures
Each pair is drawn in the same window, so the two can be laid over each other.
In
crossthe middle band keeps its rectangle instead of being notched where the armsmeet it. In
holedthe headland around the obstacle is preserved and corridors open onlyon the cell borders.
Three bugs found while building it
All three are reachable without the new API, and each one fails silently or crashes.
1.
Cellsaccessors dereference a null polygon.An empty polygon has no exterior ring, and
getGeometryRef()returns a null entry for anout-of-range index — which
OGRMultiPolygon::getGeometryRefthen dereferences. Neitherwas checked.
getCellBorder,getInteriorRingandaddRingnow check the index beforeasking OGR, and throw
std::out_of_rangelikegetGeometryalready does. TheGeometryconstructors also accept a null pointer as "empty geometry" instead of calling
clone()on it. Confirmed under ASan.2.
generateBestSwathscan return an angle that covers nothing.The objectives score an angle from the cell border alone, without checking whether any
swath is produced. On a cell left with a hairline spur by a boolean operation:
The cell was skipped without a word.
generateBestSwathsnow falls back to an angle thatactually covers the cell. The check sits where the swaths are already generated, so the
common path costs nothing measurable (0.7414s vs 0.7366s over 480 calls).
3.
NSwathModified::computeCostreads the wrong neighbouring point.iis asize_t, so ati = 0the subtraction wraps toSIZE_MAXand the modulo landson an arbitrary vertex rather than the previous one — index
0for a 5-point ring,3for a 6-point ring,
1for a 7-point ring. The first edge is therefore weighed against anunrelated point.
It shows up as the cost of a polygon depending on which vertex its ring happens to start
from: for one 5-sided polygon written five different ways, the cost ranged from 10.5 to
15.0. Fixed by
(i + ring.size() - 1) % ring.size(); no existing test moved.