mirror of
https://github.com/bilawalsidhu/gods-eye-view.git
synced 2026-11-04 18:34:02 +00:00
The transit, ALPR, vessel, CCTV and flight/military context fixes each wrapped 359.5° to north with an inline Math.round(x) % 360. They now call roundHeadingDegrees in src/data/headingDegrees.js, which also wraps negative and multi-turn bearings. normalizeHeading moves there with it, and cockpitMath re-exports it so existing imports keep working. It now adds a turn only to a negative remainder, so a bearing just under half a degree keeps its precision. The awareness, Local ADS-B, cockpit wind, cockpit heading and Street Level readouts use the same helper. The Cockpit's TRACK ACQUIRED signal rounded without wrapping and could read COURSE 360°; it now uses formatHeadingReadout, which shows --- for a track that is not finite.
20 lines
793 B
JavaScript
20 lines
793 B
JavaScript
/** Normalize a heading into the [0, 360) range; 0 when it is not finite. */
|
||
export function normalizeHeading(value) {
|
||
if (!Number.isFinite(value)) return 0;
|
||
// Only a negative remainder takes the extra turn, so a positive bearing
|
||
// keeps its precision (0.49999999999999 must not become 360.5).
|
||
const remainder = value % 360;
|
||
const wrapped = remainder < 0 ? remainder + 360 : remainder;
|
||
return wrapped === 360 ? 0 : wrapped;
|
||
}
|
||
|
||
/**
|
||
* Whole degrees for display, 0–359. 359.5° and above rounds to north (0),
|
||
* and negative or multi-turn values wrap. Null when the value is not finite,
|
||
* so each caller keeps its own placeholder.
|
||
*/
|
||
export function roundHeadingDegrees(value) {
|
||
if (!Number.isFinite(value)) return null;
|
||
return Math.round(normalizeHeading(value)) % 360;
|
||
}
|