fix(awareness): show a 999.6 m contact as 1.0 km, not 1000 m

The Contacts panel checked the raw meters against 1000 but printed them rounded, so 999.5 m or more read "1000 m". Compare the rounded meters so the distance moves to kilometres.
This commit is contained in:
Rudy Celekli committed 2026-10-25 11:32:19 -04:00
1 parent abd81155f9
commit 6c225605c4
3 files changed
+16 -3

No files matched your search

@@ -0,0 +1,3 @@
- Show a Contacts entry 999.5 m or more away as 1.0 km. The panel kept meters
below 1000, then rounded 999.6 m up to "1000 m"
(Rudy Celekli, @rudycelekli, #1387).
+10 -1
View File
@@ -42,7 +42,10 @@ import {
formatAwarenessLabel,
getAwarenessNavigationTargets,
} from './militaryAwarenessEngine.js';
import { formatAwarenessCount } from '../layers/awareness/panel.js';
import {
formatAwarenessCount,
presentAwarenessDistance,
} from '../layers/awareness/panel.js';
import { NAVIGATION_AUTHORITY_EVENT } from '../navigationPolicy.js';
const militaryAwarenessSource = readLayerSource(
@@ -69,6 +72,12 @@ test('Contacts labels a capped cohort as a lower bound', () => {
assert.equal(formatAwarenessCount({ count: null }), '?');
});
test('Contacts moves a distance that rounds to 1,000 m into kilometres', () => {
assert.equal(presentAwarenessDistance(999.4), '999\u00a0m');
assert.equal(presentAwarenessDistance(999.6), '1.0\u00a0km');
assert.equal(presentAwarenessDistance(4600), '4.6\u00a0km');
});
function installAwarenessRuntime({
isEnabled = () => true,
isEffectivelyEnabled = isEnabled,
+3 -2
View File
@@ -25,9 +25,10 @@ function presentAwarenessCount(summary = {}) {
}
/** A distance as the panel shows it: 850 m, 4.6 km, 120 km, in the UI language. */
function presentAwarenessDistance(meters) {
export function presentAwarenessDistance(meters) {
if (!Number.isFinite(meters) || meters < 0) return '—';
if (meters < 1000) return formatQuantity(Math.round(meters), 'm');
const wholeMeters = Math.round(meters);
if (wholeMeters < 1000) return formatQuantity(wholeMeters, 'm');
const digits = meters < 10000 ? 1 : 0;
return formatQuantity(meters / 1000, 'km', {
minimumFractionDigits: digits,