From 83c4388e6412724bc5bb96394b50a5a2a6ca387c Mon Sep 17 00:00:00 2001 From: Aditya <205600203+Rohilalala@users.noreply.github.com> Date: Tue, 27 Oct 2026 15:55:30 +0530 Subject: [PATCH] fix(awareness): show a 999.6 m contact marker as 1.0 km, not 1000 m The on-globe Contacts markers picked metres before rounding, so a contact 999.5 m or more away read "1000 m" while the Contacts panel read "1.0 km". The marker label now rounds first, as the panel does. --- docs/CURRENT-STATE.md | 5 +++-- src/data/militaryAwarenessEngine.js | 6 ++++-- src/data/militaryAwarenessEngine.test.mjs | 6 ++++++ 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/docs/CURRENT-STATE.md b/docs/CURRENT-STATE.md index 0cb46940c..71803280c 100644 --- a/docs/CURRENT-STATE.md +++ b/docs/CURRENT-STATE.md @@ -4461,8 +4461,9 @@ silent for five minutes are removed. Credits appear when the feed is used. coordinator, but it is not a user-visible Data Layers entry. Its visible entry point is the right-side `CONTEXT` chooser's `CONTACTS` mode. -Contacts distance labels select metres or kilometres after rounding to the -nearest metre, so a 999.5-metre contact displays as `1.0 km`, not `1000 m`. +Contacts distance labels, in the panel and on the globe's contact markers, +select metres or kilometres after rounding to the nearest metre, so a +999.5-metre contact displays as `1.0 km`, not `1000 m`. At global scale, ambient Radio cluster badges are hard-opacity shared-host entries: count/category updates and identity replacement do not run keyhole or diff --git a/src/data/militaryAwarenessEngine.js b/src/data/militaryAwarenessEngine.js index 0f889d53f..059d6d437 100644 --- a/src/data/militaryAwarenessEngine.js +++ b/src/data/militaryAwarenessEngine.js @@ -47,8 +47,10 @@ export function findByDoublingRadius( /** @param {number} meters @returns {string} */ export function formatAwarenessDistance(meters) { if (!Number.isFinite(meters) || meters < 0) return '—'; - return meters < 1000 - ? `${Math.round(meters)} m` + // Round before the kilometre cut. 999.6 m was printed as "1000 m". + const wholeMeters = Math.round(meters); + return wholeMeters < 1000 + ? `${wholeMeters} m` : `${(meters / 1000).toFixed(meters < 10000 ? 1 : 0)} km`; } diff --git a/src/data/militaryAwarenessEngine.test.mjs b/src/data/militaryAwarenessEngine.test.mjs index 3415fd5d7..2fc57d0f6 100644 --- a/src/data/militaryAwarenessEngine.test.mjs +++ b/src/data/militaryAwarenessEngine.test.mjs @@ -24,6 +24,12 @@ test('awareness formatters preserve valid zeroes and replace missing or invalid assert.equal(formatAwarenessLabel(undefined), '—'); }); +test('a contact marker moves a distance that rounds to 1,000 m into kilometres', () => { + assert.equal(formatAwarenessDistance(999.4), '999 m'); + assert.equal(formatAwarenessDistance(999.6), '1.0 km'); + assert.equal(formatAwarenessDistance(4600), '4.6 km'); +}); + test('awareness cohorts sort nearest-first and do not turn empty data into out of range', () => { const result = summarizeAwarenessCohort([{ id: 'far', distance: 9000 }, { id: 'near', distanceM: 1000 }]); assert.equal(result.relationship, 'NEARBY');