This commit is contained in:
Ayzen
2026-06-13 12:07:23 +03:00
parent f0d095de80
commit e7f2d25585
20 changed files with 903 additions and 148 deletions
@@ -4,11 +4,11 @@ namespace radar::locator {
// One outbound locator observation: object position relative to the radar in metres.
// `crs` is the cross-range (X) coordinate; `dst` is the range (Z) coordinate.
// Values are kept as float because they are quantised to two decimal places before
// being serialised on the wire.
// Values use double so that, after quantisation to one decimal place (decimetres),
// they serialise to clean JSON (e.g. "12.3" rather than a float's "12.300000190734863").
struct Observation {
float crs = 0.0F;
float dst = 0.0F;
double crs = 0.0;
double dst = 0.0;
};
} // namespace radar::locator
@@ -42,10 +42,11 @@ constexpr std::uint32_t kMinTableColumns = 3U; // [x_m, z_m, score, ...]
return fallback;
}
// Quantise to two decimal places. Equivalent to Python's `round(value, 2)`
// but explicit so behaviour does not silently depend on the local C library.
[[nodiscard]] auto quantise_to_centimetres(float value) -> float {
return std::round(value * 100.0F) / 100.0F;
// Quantise to one decimal place (0.1 m = decimetres). Equivalent to Python's
// `round(value, 1)` but explicit so behaviour does not silently depend on the
// local C library.
[[nodiscard]] auto quantise_to_decimetres(double value) -> double {
return std::round(value * 10.0) / 10.0;
}
[[nodiscard]] auto passes_basic_filter(
@@ -156,8 +157,8 @@ auto observations_from_collection(
quantised.reserve(visible.size());
for (const auto& observation : visible) {
quantised.push_back({
.crs = quantise_to_centimetres(observation.crs),
.dst = quantise_to_centimetres(observation.dst),
.crs = quantise_to_decimetres(observation.crs),
.dst = quantise_to_decimetres(observation.dst),
});
}
return quantised;
@@ -172,8 +173,8 @@ auto observations_from_collection(
result.reserve(kept);
for (std::size_t index = 0; index < kept; ++index) {
result.push_back({
.crs = quantise_to_centimetres(visible[index].crs),
.dst = quantise_to_centimetres(visible[index].dst),
.crs = quantise_to_decimetres(visible[index].crs),
.dst = quantise_to_decimetres(visible[index].dst),
});
}
return result;