fix: two segments adjacent by ray number can still be metres apart

Grouping segments into an arc candidate keyed only on ray index, and that is
not the same question as whether they lie on one surface: the next ray along
can land on something several metres away.

Found in Gazebo, not in a synthesized scene. The four segments of a cradle sat
two rays away from a 6.6 m wall behind it, so the wall was absorbed into the
group; the circle fitted over all of it came out at radius 3.2 m with a 0.11 m
residual, and the real cradle was rejected because of something that was not
part of it. The regression test reproduces the same signature - radius 1.38 m,
residual 0.20 m - and passes once the gap is checked.

arc_max_point_gap is the euclidean distance between the two facing endpoints,
and it belongs at or below the extractor's max_line_gap. Set it higher and the
matcher rejoins exactly what the extractor just separated, which it separated
for a reason.
This commit is contained in:
2026-08-26 20:39:37 +07:00
parent a45694f625
commit 791c838da8
5 changed files with 56 additions and 2 deletions

View File

@@ -83,11 +83,17 @@ Detection ArcPatternMatcher::match(const std::vector<Line>& lines) const
const Line& prev = lines[groups.back().back()];
const unsigned int prev_end = prev.getIndices().back();
const unsigned int this_start = lines[i].getIndices().front();
// Khoảng cách THẬT giữa hai đầu quay vào nhau. `getStart` là tia đầu và `getEnd` là tia cuối
// của đoạn, nên đây đúng là hai đầu đối diện.
const double point_gap = std::hypot(lines[i].getStart()[0] - prev.getEnd()[0],
lines[i].getStart()[1] - prev.getEnd()[1]);
// `>=` chứ không phải `>`: khi tách theo khoảng cách, bộ trích đoạn DÙNG CHUNG điểm góc cho
// cả hai nửa, nên hai đoạn của cùng một mặt cong gặp nhau ở đúng một số tia. Đòi hơn hẳn là
// không nhóm nào được gộp, và mỗi mẩu cung 0.5 rad rớt sàn `arc_min_span` — cung thật bị bỏ
// vì lý do số học của một mảnh vụn.
if (this_start >= prev_end && this_start - prev_end <= kMaxRayGapBetweenSegments)
if (this_start >= prev_end && this_start - prev_end <= kMaxRayGapBetweenSegments &&
point_gap <= profile_.arc_max_point_gap)
{
groups.back().push_back(i);
continue;

View File

@@ -154,6 +154,11 @@ bool DockProfile::validate(std::string& error) const
error = "arc_max_rms must be finite and > 0";
return false;
}
if (!positive(arc_max_point_gap))
{
error = "arc_max_point_gap must be finite and > 0";
return false;
}
if (min_arc_points < 3)
{
error = "min_arc_points must be >= 3; three points is the minimum for a circle";