mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 10:53:59 +00:00
Merge PR #1390 contribution for review
This commit is contained in:
commit
d987149f17
4 files changed
+26
-2
No files matched your search
@@ -0,0 +1,2 @@
|
|||||||
|
- Render awareness-overlay bearings and courses that round through north as
|
||||||
|
`000°`, rather than `360°` (Rudy Celekli, #1390).
|
||||||
@@ -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');
|
||||||
|
}
|
||||||
@@ -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), '—');
|
||||||
|
});
|
||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
} from '../../data/militaryAwarenessEngine.js';
|
} from '../../data/militaryAwarenessEngine.js';
|
||||||
import { bearingBetweenCoordinates } from '../../cockpitMath.js';
|
import { bearingBetweenCoordinates } from '../../cockpitMath.js';
|
||||||
import { AWARENESS_PAGE_SIZE, CONTEXT_RIM_HEIGHT_M } from './policy.js';
|
import { AWARENESS_PAGE_SIZE, CONTEXT_RIM_HEIGHT_M } from './policy.js';
|
||||||
|
import { formatAwarenessDirection } from './presentation.js';
|
||||||
|
|
||||||
export function createRendering({
|
export function createRendering({
|
||||||
state: layerState,
|
state: layerState,
|
||||||
@@ -225,12 +226,12 @@ export function createRendering({
|
|||||||
: null;
|
: null;
|
||||||
const bearingText = Number.isFinite(bearing)
|
const bearingText = Number.isFinite(bearing)
|
||||||
? t('BRG {value}°', {
|
? t('BRG {value}°', {
|
||||||
value: String(Math.round(bearing)).padStart(3, '0'),
|
value: formatAwarenessDirection(bearing),
|
||||||
})
|
})
|
||||||
: t('BRG —');
|
: t('BRG —');
|
||||||
const courseText = Number.isFinite(item.track)
|
const courseText = Number.isFinite(item.track)
|
||||||
? ` · ${t('CRS {value}°', {
|
? ` · ${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}`;
|
marker._label.textContent = `${label} · ${formatAwarenessDistance(item.distanceM)}\n${bearingText}${courseText}`;
|
||||||
|
|||||||
Reference in new issue
Block a user