diff --git a/src/v_pattern_matcher.cpp b/src/v_pattern_matcher.cpp index f40b697..e873c50 100644 --- a/src/v_pattern_matcher.cpp +++ b/src/v_pattern_matcher.cpp @@ -11,6 +11,7 @@ #include #include #include +#include namespace dock_pattern_detector { @@ -122,6 +123,12 @@ Detection VPatternMatcher::match(const std::vector& lines) const std::size_t rejected_confidence = 0; std::size_t accepted = 0; + // Ứng viên GẦN ĐÚNG NHẤT bị cổng tìm kiếm loại. Chỉ đếm số lượng thì không trả lời được câu duy + // nhất đáng hỏi lúc đó: nới quạt ra, hay xoay robot lại? Cần biết nó nằm ở đâu. + bool have_gated = false; + Point gated_apex; + double gated_dist = 0.0; + for (std::size_t i = 0; i + 1 < lines.size(); ++i) { for (std::size_t j = i + 1; j < lines.size(); ++j) @@ -213,12 +220,25 @@ Detection VPatternMatcher::match(const std::vector& lines) const if (d > profile_.search_radius) { ++rejected_prior; + if (!have_gated || d < gated_dist) + { + have_gated = true; + gated_apex = apex; + gated_dist = d; + } continue; } } if (profile_.search_fov > 0.0 && std::fabs(std::atan2(apex.y, apex.x)) > profile_.search_fov) { ++rejected_prior; + const double bearing = std::fabs(std::atan2(apex.y, apex.x)); + if (!have_gated || bearing < gated_dist) + { + have_gated = true; + gated_apex = apex; + gated_dist = bearing; + } continue; } @@ -271,8 +291,29 @@ Detection VPatternMatcher::match(const std::vector& lines) const // "thấy nhưng méo" đòi hai cách xử trí ngược nhau, mà một dòng "detection failed" thì không. if (rejected_prior > 0) { - best.reason = std::to_string(rejected_prior) + - " candidate(s) matched the shape but fell outside the search gate"; + // Kèm VỊ TRÍ và HƯỚNG của ứng viên gần nhất bị loại. Chỉ có con số thì không biết nên nới + // quạt hay xoay robot — mà đó đúng là câu duy nhất cần trả lời lúc này. + char detail[192] = { 0 }; + if (have_gated) + { + std::snprintf(detail, sizeof(detail), + " (nearest at (%.2f, %.2f) m, bearing %.2f rad = %.0f deg, range %.2f m;" + " gate search_fov=%.2f rad", + gated_apex.x, gated_apex.y, std::atan2(gated_apex.y, gated_apex.x), + std::atan2(gated_apex.y, gated_apex.x) * 180.0 / M_PI, + std::hypot(gated_apex.x, gated_apex.y), profile_.search_fov); + std::string tail = profile_.has_prior + ? ", search_radius=" + std::to_string(profile_.search_radius) + " m)" + : ")"; + best.reason = std::to_string(rejected_prior) + + " candidate(s) matched the shape but fell outside the search gate" + detail + + tail; + } + else + { + best.reason = std::to_string(rejected_prior) + + " candidate(s) matched the shape but fell outside the search gate"; + } } else if (rejected_confidence > 0) {