Skip to content

A spy satellite simulator in your browser, except the data is real. Live open source spatial intelligence on a photorealistic 3D globe.

fix(awareness): wrap north-bound bearings

Rudy Celekli63866c201af3
diff --git a/changelog.d/1390-awareness-bearing-north.md b/changelog.d/1390-awareness-bearing-north.md
new file mode 100644
index 000000000..af7fb4da3
--- /dev/null
+++ b/changelog.d/1390-awareness-bearing-north.md
@@ -0,0 +1,2 @@
+- Render awareness-overlay bearings and courses that round through north as
+ `000°`, rather than `360°` (Rudy Celekli, #1390).
diff --git a/src/layers/awareness/presentation.js b/src/layers/awareness/presentation.js
new file mode 100644
index 000000000..7439907d9
--- /dev/null
+++ b/src/layers/awareness/presentation.js
@@ -0,0 +1,10 @@
+/**
+ * Format a compass direction for the awareness overlay.
+ * @param {number} degrees
+ * @returns {string}
+ */
+export function formatAwarenessDirection(degrees) {
+ if (!Number.isFinite(degrees)) return '—';
+ const normalized = ((degrees % 360) + 360) % 360;
+ return String(Math.round(normalized) % 360).padStart(3, '0');
+}
diff --git a/src/layers/awareness/presentation.test.mjs b/src/layers/awareness/presentation.test.mjs
new file mode 100644
index 000000000..54d40765f
--- /dev/null
+++ b/src/layers/awareness/presentation.test.mjs
@@ -0,0 +1,11 @@
+import test from 'node:test';
+import assert from 'node:assert/strict';
+import { formatAwarenessDirection } from './presentation.js';
+
+test('awareness bearings that round through north read 000, not 360', () => {
+ assert.equal(formatAwarenessDirection(359.4), '359');
+ assert.equal(formatAwarenessDirection(359.6), '000');
+ assert.equal(formatAwarenessDirection(0), '000');
+ assert.equal(formatAwarenessDirection(-0.4), '000');
+ assert.equal(formatAwarenessDirection(Number.NaN), '—');
+});
diff --git a/src/layers/awareness/rendering.js b/src/layers/awareness/rendering.js
index 8fe147e46..957e0bbdd 100644
--- a/src/layers/awareness/rendering.js
+++ b/src/layers/awareness/rendering.js
@@ -11,6 +11,7 @@ import {
} from '../../data/militaryAwarenessEngine.js';
import { bearingBetweenCoordinates } from '../../cockpitMath.js';
import { AWARENESS_PAGE_SIZE, CONTEXT_RIM_HEIGHT_M } from './policy.js';
+import { formatAwarenessDirection } from './presentation.js';
export function createRendering({
state: layerState,
@@ -225,12 +226,12 @@ export function createRendering({
: null;
const bearingText = Number.isFinite(bearing)
? t('BRG {value}°', {
- value: String(Math.round(bearing)).padStart(3, '0'),
+ value: formatAwarenessDirection(bearing),
})
: t('BRG —');
const courseText = Number.isFinite(item.track)
? ` · ${t('CRS {value}°', {
- value: String(Math.round(item.track)).padStart(3, '0'),
+ value: formatAwarenessDirection(item.track),
})}`
: '';
marker._label.textContent = `${label} · ${formatAwarenessDistance(item.distanceM)}\n${bearingText}${courseText}`;