Skip to content

Drop border detail the machine cannot act on before decomposing - #253

Merged
Gonzalo-Mier merged 6 commits into
Fields2Cover:developfrom
u33549:dev/umutc/v2.1.0-devel/decomp-simplify
Sep 22, 2026
Merged

Gonzalo-Mier merged 6 commits into
Fields2Cover:developfrom
u33549:dev/umutc/v2.1.0-devel/decomp-simplify

Conversation

@u33549

@u33549 u33549 commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

A decomposition splits a field wherever its border turns back on itself. A
digitised border does that on details of a few centimetres -- far below
anything the machine can act on -- so the field comes back cut into pieces that
exist only in the survey, each one paying for a headland it does not need.

f2c::decomp::simplifyForDecomposition(cells, robot) removes border detail
below 0.6 of the robot's coverage width before the field is decomposed.
ee_field_130 goes from sixteen cells to twelve.

Measured over 305 real fields x two robot profiles (2.5 m and 6 m coverage,
610 field/robot pairs):

  • 2425 -> 1787 cells out of the decomposition (-26%)
  • no piece of any field lands outside the field it came from, at any threshold
    up to 1.6 of the coverage width

On a 50-field subset with the full coverage metric (59 pairs, mainland minus
the area a turn overruns): the constant-width headland gains +15,646 m² and
the classic 2R + w/2 headland +9,364 m². The gain is largest for the
simplest method, which is what you would expect if it is removing work nobody
should have been doing.

The threshold is measured rather than assumed. Below it noise survives; well
above it the splits the shape genuinely asks for start merging -- at 1.2 of the
coverage width a nine-cell field collapses to one.

decompose() is untouched. It still returns cells whose area equals its input,
so nothing changes for callers that do not ask for the simplification.

One deliberate limitation: the result is not clipped to the input.
Simplifying moves the border both ways, so a point can land outside; the
function expects ground that is already inside the field -- a mainland from a
headland generator, not the raw boundary -- and says so in its doc comment.
Clipping would guarantee containment but costs most of the benefit: on the same
50 fields the cell reduction drops from 33% to 13% and the area loss grows
tenfold.

A decomposition splits a field wherever its border turns back on itself. A
digitised border does that on details of a few centimetres, so the field
comes back cut into pieces that exist only in the survey -- ee_field_130
gives sixteen where four of them are noise, and each one pays for a
headland it does not need.

The function added here hands the cells straight back, so the test is red
on the count. The first expectation, that the raw border gives sixteen,
already passes and has to keep passing.
Simplify the border to 0.6 of the coverage width first, so the split lines
follow the shape of the field rather than the noise on it. ee_field_130
goes from sixteen cells to twelve.

The share is measured, not assumed: over 305 fields and two robots it is
where the decomposition returns 30% fewer cells, no piece lands outside the
field it came from, and the area moves by less than a tenth of a percent.
Below it noise survives; well above it splits the shape genuinely asks for
start merging.
The doc comment said the same thing twice; the measured numbers live in the
changelog and in the source, not in the header.
Copilot AI lite review requested due to automatic review settings September 19, 2026 10:01

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 review overview

🟢 Approval recommended

Only minor documentation percentage corrections remain; no blocking issues were identified.

Review effort: Lite
Findings: None

What changed in this PR

Adds robot-aware border simplification before decomposition to remove insignificant survey detail while preserving existing behavior.

Changes:

  • Adds simplifyForDecomposition to C++ and Python APIs.
  • Adds C++ and Python regression tests.
  • Documents the API and non-clipping behavior.
File Summary
tests/​python/​decomposition/​decomposition_base_test.py Tests Python API behavior and area preservation.
tests/​cpp/​decomposition/​boustrophedon_decomp_test.cpp Tests reduced decomposition splits.
src/​fields2cover/​decomposition/​decomposition_base.cpp Implements threshold-based border simplification.
include/​fields2cover/​decomposition/​decomposition_base.h Declares and documents the public API.
CHANGELOG.md Documents the new feature.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

// the field it came from, and the area moves by less than a tenth of a
// percent. Taking less leaves noise behind; taking much more starts merging
// splits the shape of the field genuinely asks for.
constexpr double kBorderDetailShare = 0.6;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This value should be part of the class or argument of the function used. You can add it as last argument and give it a default value if you want, but never here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Actually, I chose this value based on the results I obtained by calculating it for 300 scenarios using approximately 20 different values (for a total of 6,000 scenarios), but it makes sense to make it optional.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I understand the way you picked the value, but I dont like having random constants in the cpp files.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done in c5ad294 — the constant is gone from the .cpp. It is now the last argument, double detail_share = 0.6, and the measurement behind the default moved into the parameter's doc comment in the header.

Gonzalo-Mier and others added 3 commits September 22, 2026 15:20
It was a constant inside the function. The measured 0.6 stays the
default, so a two-argument call gives the same cells as before.
Removed extra comments about testing in the documentation
@Gonzalo-Mier
Gonzalo-Mier merged commit bbec6a7 into Fields2Cover:develop Sep 22, 2026
69 of 70 checks passed
@Gonzalo-Mier

Copy link
Copy Markdown
Member

Thank you @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