Skip to content

Report which cell gives each corridor, and let callers ask for a fair split - #248

Merged
Gonzalo-Mier merged 7 commits into
Fields2Cover:mainfrom
u33549:dev/umutc/v2.1.0-devel/corridor-shares
Sep 3, 2026
Merged

Gonzalo-Mier merged 7 commits into
Fields2Cover:mainfrom
u33549:dev/umutc/v2.1.0-devel/corridor-shares

Conversation

@u33549

@u33549 u33549 commented Aug 30, 2026

Copy link
Copy Markdown
Contributor

CorridorHL::generateHeadlands decides, for every pair of cells that share a border, which one gives up the corridor and how much — but that decision was made and used in the same breath, inside the carving loop. Nothing outside the carved geometry could see it. This PR pulls the rule out into its own method, fixes a real bug the pull surfaced, and adds a second rule to compare the first one against.

corridorShares, the rule on its own

namespace f2c::hg {
struct CorridorShare {
  size_t cell_i, cell_k;
  double perimeter_i, perimeter_k;
  bool same_size;
  double share;           // part of the corridor cell_i gives up: 0, 0.5 or 1
  double shared_length;
  F2CMultiLineString shared_border;
};

std::vector<CorridorShare> CorridorHL::corridorShares(
    const F2CCells& field, CorridorShareMode mode = CorridorShareMode::ASYMMETRIC) const;
}

generateHeadlands now calls this and applies what it returns — same output as before, just no longer the only way to find out. A caller that needs the decision itself (a report, a test, a figure) doesn't have to re-derive the rule from the carved shape and risk it drifting from what the generator actually does.

A bug the pull surfaced

Finding the shared border buffers the neighbour cell by a tolerance and intersects it with each edge. That tolerance turns a single shared corner into a few millimetres of "border" on every edge that reaches it. It's invisible with two cells, but five cells meeting at one point were all reported as neighbours of every other, and the corridor carved a disc out of the middle instead of five separate cuts. Fixed by giving the length filter its own, much looser threshold (kMinBorder = 1e-2) than the buffer tolerance (kTol = 1e-3) — a border under a centimetre is a corner, not a border. Covered by sharesTreatACornerAsNoBorder, a five-slice pie test.

CorridorShareMode: a second rule to compare against

corridorShares always gave the whole corridor to the smaller cell (by perimeter), splitting evenly only when the two were within tolerance of the same size. There was no way to ask for the even split on purpose, which is exactly what's needed to measure the asymmetric rule's effect — the two only differ in which cell gives up how much, not in how much corridor opens overall.

enum class CorridorShareMode { ASYMMETRIC, SYMMETRIC };

std::vector<CorridorShare> corridorShares(const F2CCells&, CorridorShareMode) const;
void setShareMode(CorridorShareMode);        // what generateHeadlands() uses
CorridorShareMode getShareMode() const;

ASYMMETRIC stays the default, so nothing that already calls generateHeadlands or the no-mode corridorShares overload changes behaviour.

Tutorial

Tutorial 7.2 had grown a corridorShares demo into the same figure as the route, at the same zoom as every other headland tutorial — three different concepts drawn on top of each other, indistinguishable at a glance. Removed. In its place, Tutorial 3.3 gives CorridorHL its own section: one L-shaped field, decomposed once, headlanded three different ways (double headland, ASYMMETRIC corridor, SYMMETRIC corridor), each with its own route and path (DubinsCurvesCC) so the cost difference is visible, not just the leftover area.

u33549 added 4 commits August 30, 2026 23:16
The rule that picks the cell was decided inside the carving loop and only
its geometry came out, so it could be checked only through the shape it
left behind. corridorShares() now holds the rule and generateHeadlands()
applies what it returns.
Buffering a neighbour to find the shared border turns a single shared
corner into a few millimetres of border on every edge that reaches it.
Five cells meeting at one point were all neighbours of each other, and a
disc came out of the middle. A border shorter than a centimetre is a
corner.
CorridorHL always gave the whole corridor to the smaller cell, splitting
evenly only when the two were the same size. corridorShares() now takes a
CorridorShareMode, and SYMMETRIC always splits evenly regardless of size,
so the two rules can be compared against each other. setShareMode() and
getShareMode() pick which one generateHeadlands() applies; ASYMMETRIC
stays the default, so existing behaviour is unchanged.
Tutorial 7.2 folded corridorShares into the same figure as ConstHL,
ReqHL and CorridorHL, so double headland, asymmetric corridor and
symmetric corridor all looked alike. Tutorial 3.3 now shows the three
side by side on the same L-shaped field, with the route each one leaves
so the difference in cost is visible, not just the area.
Copilot AI lite review requested due to automatic review settings August 30, 2026 20:31

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

File-scope constexpr doubles hid them from anyone reading the class
in the header. No behavior change.
@u33549

u33549 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

CorridorHL currently creates corridors that are wider than they should be; this will be fixed in the next update.

@u33549

u33549 commented Sep 3, 2026

Copy link
Copy Markdown
Contributor Author

@Gonzalo-Mier I think you forgot to close this PR, so I wanted to remind you.

@Gonzalo-Mier
Gonzalo-Mier merged commit ed34e28 into Fields2Cover:main Sep 3, 2026
70 checks passed
@Gonzalo-Mier

Copy link
Copy Markdown
Member

Thank you for the notice and the PR @u33549

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants