mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-05 19:04:02 +00:00
fix(cockpit): read a rounded-north destination heading as 000
359.6 degrees was shown as 360 degrees on the destination bearing while the compass tape uses 000.
This commit is contained in:
1 parent
9d3548c27c
commit
05316bb34b
3 files changed
+20
-1
No files matched your search
@@ -6,6 +6,15 @@ export function normalizeHeading(value) {
|
|||||||
return ((value % 360) + 360) % 360;
|
return ((value % 360) + 360) % 360;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Three-digit heading readout, 000–359.
|
||||||
|
* Rounding 359.5° and above lands on north (000), not 360.
|
||||||
|
*/
|
||||||
|
export function formatHeadingReadout(degrees) {
|
||||||
|
if (!Number.isFinite(degrees)) return '---';
|
||||||
|
return String(Math.round(normalizeHeading(degrees)) % 360).padStart(3, '0');
|
||||||
|
}
|
||||||
|
|
||||||
/** Advance a displayed heading along the shortest arc without exceeding a slew rate. */
|
/** Advance a displayed heading along the shortest arc without exceeding a slew rate. */
|
||||||
export function slewHeading(current, target, maxStepDeg) {
|
export function slewHeading(current, target, maxStepDeg) {
|
||||||
const from = normalizeHeading(current);
|
const from = normalizeHeading(current);
|
||||||
|
|||||||
@@ -15,6 +15,7 @@ import {
|
|||||||
formatCockpitContextScope,
|
formatCockpitContextScope,
|
||||||
formatCockpitEmergency,
|
formatCockpitEmergency,
|
||||||
formatCompassDivision,
|
formatCompassDivision,
|
||||||
|
formatHeadingReadout,
|
||||||
formatSpeedRulerTick,
|
formatSpeedRulerTick,
|
||||||
normalizeHeading,
|
normalizeHeading,
|
||||||
relativeBearing,
|
relativeBearing,
|
||||||
@@ -155,6 +156,14 @@ test('compass labels use cardinals where exact and degrees elsewhere', () => {
|
|||||||
assert.equal(formatCompassDivision(30), '030');
|
assert.equal(formatCompassDivision(30), '030');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('a heading that rounds to north reads 000, not 360', () => {
|
||||||
|
assert.equal(formatHeadingReadout(359.6), '000');
|
||||||
|
assert.equal(formatHeadingReadout(359.4), '359');
|
||||||
|
assert.equal(formatHeadingReadout(0), '000');
|
||||||
|
assert.equal(formatHeadingReadout(10.2), '010');
|
||||||
|
assert.equal(formatHeadingReadout(Number.NaN), '---');
|
||||||
|
});
|
||||||
|
|
||||||
test('great-circle bearing resolves cardinal directions', () => {
|
test('great-circle bearing resolves cardinal directions', () => {
|
||||||
assert.ok(Math.abs(bearingBetweenCoordinates(0, 0, 1, 0) - 0) < 0.001);
|
assert.ok(Math.abs(bearingBetweenCoordinates(0, 0, 1, 0) - 0) < 0.001);
|
||||||
assert.ok(Math.abs(bearingBetweenCoordinates(0, 0, 0, 1) - 90) < 0.001);
|
assert.ok(Math.abs(bearingBetweenCoordinates(0, 0, 0, 1) - 90) < 0.001);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import {
|
|||||||
formatAltitudeRulerTick,
|
formatAltitudeRulerTick,
|
||||||
formatCompassDivision,
|
formatCompassDivision,
|
||||||
formatCockpitEmergency,
|
formatCockpitEmergency,
|
||||||
|
formatHeadingReadout,
|
||||||
formatSpeedRulerTick,
|
formatSpeedRulerTick,
|
||||||
normalizeHeading,
|
normalizeHeading,
|
||||||
relativeBearing,
|
relativeBearing,
|
||||||
@@ -238,7 +239,7 @@ export function updateRoute(info) {
|
|||||||
}
|
}
|
||||||
if (this.routeDirectionLabel) {
|
if (this.routeDirectionLabel) {
|
||||||
this.routeDirectionLabel.textContent = t('DEST {bearing}', {
|
this.routeDirectionLabel.textContent = t('DEST {bearing}', {
|
||||||
bearing: `${String(Math.round(destinationBearing)).padStart(3, '0')}°`,
|
bearing: `${formatHeadingReadout(destinationBearing)}°`,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user