fix: keep a segment whose least-squares refinement did not converge

extract() dropped any run whose weighted fit ran out of iterations. That was
too harsh: a failed refinement loses only the covariance, while the angle,
radius, endpoints and support all remain those of the endpoint fit and stay
usable.

Measured on a V dock plate at 2 m with 34 rays on the plate: both wings split
correctly with 17-18 points each and lengths correct to a few millimetres, yet
one of the two vanished on roughly half of the noise realizations because its
fit hit the 50-iteration cap. Everything downstream then saw one line where
there were two, and the corner disappeared. End-to-end V detection rate was
48%; keeping the segment takes it to 100% across 0-5 mm tape protrusion at
both 2 m and 3 m.

Line now reports hasCovariance(), false when the fit did not converge, and
mergeLines() refuses to merge such a segment - merging decides by comparing
line parameters against their own covariance, so a meaningless covariance must
not be allowed to make that decision.

TheLeastSquaresLoopIsBounded keeps guarding the iteration cap itself; the new
ALineThatFailedToRefineIsStillReturned guards against dropping the segment,
and fails if extract() goes back to discarding it.
This commit is contained in:
2026-08-26 15:55:32 +07:00
parent 1d38e77afa
commit d8f11d2df6
6 changed files with 107 additions and 16 deletions

View File

@@ -291,7 +291,7 @@ TEST(LineExtractor, AMergedLineReportsItsRealSupport)
TEST(LineExtractor, TheLeastSquaresLoopIsBounded)
{
// Ngưỡng hội tụ đặt cực nhỏ so với độ chính xác của double: bản gốc lặp vô hạn ở đây, tức treo
// luôn control thread. Bản này bỏ đoạn không hội tụ và ĐI TIẾP.
// luôn control thread. Bản này dừng ở trần lặp và ĐI TIẾP.
LineExtractionParams params = tightParams();
params.least_sq_angle_thresh = 1e-300;
params.least_sq_radius_thresh = 1e-300;
@@ -301,10 +301,39 @@ TEST(LineExtractor, TheLeastSquaresLoopIsBounded)
const ScanGeometry g = geometry(180, -0.6, 0.6);
ASSERT_TRUE(rig.run(g, wallScan(g, 2.0))) << rig.error_;
// Trả về được là đã đủ: test này chết bằng cách TREO, không phải bằng cách fail.
// Trả về được đã là một nửa: test này chết bằng cách TREO, không phải bằng cách fail.
SUCCEED();
}
TEST(LineExtractor, ALineThatFailedToRefineIsStillReturned)
{
// Không hội tụ KHÔNG phải lý do vứt đoạn. Đây là bản vá cho một hồi quy có thật: bản trước bỏ
// luôn đoạn nào không hội tụ, nên trên tấm chữ V ở 2 m — 34 tia, hai cánh tách đúng, mỗi cánh 17
// điểm, dài đúng tới vài milimet — MỘT trong hai cánh biến mất ở khoảng nửa số lượt, tuỳ nhiễu.
// Bộ dò chữ V nhìn thấy một đường ở chỗ đáng ra có hai, và tỉ lệ dò tụt còn 48%.
//
// Khớp qua hai đầu mút vẫn còn nguyên và vẫn dùng được; thứ duy nhất mất là hiệp phương sai.
LineExtractionParams params = tightParams();
params.least_sq_angle_thresh = 1e-300;
params.least_sq_radius_thresh = 1e-300;
Rig rig(params);
ASSERT_TRUE(rig.ok_) << rig.error_;
const ScanGeometry g = geometry(180, -0.6, 0.6);
ASSERT_TRUE(rig.run(g, wallScan(g, 2.0))) << rig.error_;
ASSERT_EQ(rig.lines_.size(), 1u) << "đoạn bị vứt vì tinh chỉnh không hội tụ";
const Line& line = rig.lines_.front();
// Hình học vẫn đúng, dù chỉ là khớp qua hai đầu mút.
EXPECT_NEAR(line.getRadius(), 2.0, 0.02);
EXPECT_NEAR(line.getAngle(), 0.0, 0.02);
// Và nó tự khai là không có hiệp phương sai, để bước gộp không quyết định dựa vào rác.
EXPECT_FALSE(line.hasCovariance());
}
// ================================================================================================
// 3. Đầu vào rác
// ================================================================================================