Compare commits

..

No commits in common. "8b04be187ea295895aefd102e940d0387c6739fa" and "0d797519cb0325fdc25e6a753bebd20c1c0a1f36" have entirely different histories.

39 changed files with 422 additions and 1280 deletions

View File

@ -55,8 +55,6 @@ LGAV BIBE1L SID (Cycle 2507, ID 10654)
### Instructions ### Instructions
- From preceding fix, fly along `Course` until reaching `Alt`. - From preceding fix, fly along `Course` until reaching `Alt`.
- If preceding fix was overfly, offset outbound `Course` to end of turn (tangent).
- Earliest leg terminations is at point of tangent.
### Units ### Units
@ -86,8 +84,6 @@ LGAV BIBE2F SID (Cycle 2507, ID 10657)
- From preceding fix, fly along `Course` until reaching `Distance` from the navaid identified by - From preceding fix, fly along `Course` until reaching `Distance` from the navaid identified by
`NavID`. `NavID`.
- If preceding fix was overfly, offset outbound `Course` to end of turn (tangent).
- Earliest leg terminations is at point of tangent.
### Units ### Units
@ -120,7 +116,6 @@ LGAV BIBE2F SID (Cycle 2507, ID 10657)
- From preceding fix, fly `Course` to the fix identified by (`WptID`, `WptLat`, `WptLon`) *or* - From preceding fix, fly `Course` to the fix identified by (`WptID`, `WptLat`, `WptLon`) *or*
(`NavID`, `NavLat`, `NavLon`, `NavDist`, `NavBear`). (`NavID`, `NavLat`, `NavLon`, `NavDist`, `NavBear`).
- If preceding fix was overfly, continue turn until intercept `Course`, then continue on `Course`.
### Units ### Units
@ -206,16 +201,14 @@ LGAV KOR1D SID (Cycle 2507, ID 10679)
### Instructions ### Instructions
- From present position, fly direct to fix identified by `WptID`. - From present position, fly direct to fix identified by `WptID`
- If preceding fix and fix identified by `WptId` are the same, execute 360° turn
(requires `TurnDir`).
### Units ### Units
- `IsFlyOver`: Boolean indicating if fix is a mandatory fly over. - `IsFlyOver`: Boolean indicating if fix is a mandatory fly over.
## Track from Fix to Altitude (FA) ## Fix to Altitude (FA)
### Example ### Example
@ -234,8 +227,6 @@ LGAV BIBE2F SID (Cycle 2507, ID 10657)
- From the fix identified by (`WptID`, `WptLat`, `WptLon`) *or* - From the fix identified by (`WptID`, `WptLat`, `WptLon`) *or*
(`NavID`, `NavLat`, `NavLon`, `NavDist`, `NavBear`), fly `Course` until reaching `Alt`. (`NavID`, `NavLat`, `NavLon`, `NavDist`, `NavBear`), fly `Course` until reaching `Alt`.
- If preceding fix was overfly, continue turn until intercept `Course`, then continue on `Course`.
- Earliest leg terminations is at point of intercept.
### Units ### Units
@ -270,9 +261,6 @@ LIED CAR6F SID (Cycle 2507, ID 11798)
- From the fix identified by (`WptID`, `WptLat`, `WptLon`) *or* - From the fix identified by (`WptID`, `WptLat`, `WptLon`) *or*
(`NavID`, `NavLat`, `NavLon`, `NavDist`, `NavBear`), fly `Course` until reaching `Distance`. (`NavID`, `NavLat`, `NavLon`, `NavDist`, `NavBear`), fly `Course` until reaching `Distance`.
- If preceding fix was overfly, continue turn until intercept `Course`, then continue on `Course`.
- Earliest leg terminations is at point of intercept.
### Units ### Units
@ -304,10 +292,8 @@ LGAV BIBE2T SID (Cycle 2507, ID 10659)
### Instructions ### Instructions
- From the fix identified by (`WptID`, `WptLat`, `WptLon`) *or* - From the fix identified by (`WptID`, `WptLat`, `WptLon`) *or*
(`NavID`, `NavLat`, `NavLon`, `NavDist`, `NavBear`), fly `Course` until reaching `Distance` from (`NavID`, `NavLat`, `NavLon`, `NavDist`, `NavBear`), fly `Course` until
navaid identified by `NavID`. reaching `Distance` from navaid identified by `NavID`.
- If preceding fix was overfly, continue turn until intercept `Course`, then continue on `Course`.
- Earliest leg terminations is at point of intercept.
### Units ### Units

View File

View File

@ -8,21 +8,18 @@ import L from "leaflet";
const parser = await Parser.instance(); const parser = await Parser.instance();
const terminals = [ const terminals = [10394, 10395, 10475, 10480, 10482, 10485, 10653];
10394, 10395, 10475, 10480, 10482, 10485, 10653, 10654, 10657, 10659, 10679,
11798, 11909, 12765,
];
function App() { function App() {
const [selectedTerminal, setSelectedTerminal] = useState(terminals[0]); const [selectedTerminal, setSelectedTerminal] = useState(terminals[0]);
const [procedures, setProcedures] = useState<object[]>([]); const [procedure, setProcedure] = useState<object>();
const mapRef = createRef<Leaflet.Map>(); const mapRef = createRef<Leaflet.Map>();
const layerRef = createRef<Leaflet.GeoJSON>(); const layerRef = createRef<Leaflet.GeoJSON>();
useEffect(() => { useEffect(() => {
(async () => { (async () => {
setProcedures(await parser.parse(selectedTerminal)); setProcedure(await parser.parse(selectedTerminal));
})(); })();
}, [selectedTerminal]); }, [selectedTerminal]);
@ -50,8 +47,6 @@ function App() {
attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors' attribution='&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png" url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
/> />
{procedures.map((procedure) => (
<>
<GeoJSON <GeoJSON
key={hash(procedure ?? "") + "lines"} key={hash(procedure ?? "") + "lines"}
data={procedure} data={procedure}
@ -104,15 +99,7 @@ function App() {
}} }}
filter={(feature) => feature.geometry.type === "Point"} filter={(feature) => feature.geometry.type === "Point"}
/> />
</>
))}
</MapContainer> </MapContainer>
<div
style={{
overflowY: "scroll",
width: "200px",
}}
>
<div <div
style={{ style={{
padding: "5px", padding: "5px",
@ -126,28 +113,18 @@ function App() {
key={terminal} key={terminal}
style={{ style={{
display: "flex", display: "flex",
flexDirection: "column", gap: "10px",
background: "#eeeeee", background: selectedTerminal === terminal ? "#eeeeee" : undefined,
border:
selectedTerminal === terminal
? "1px solid black"
: "1px solid #eeeeee",
padding: "5px",
}} }}
onClick={() => setSelectedTerminal(terminal)}
> >
<span style={{ whiteSpace: "nowrap" }}> <pre>ID {terminal}</pre>
{(() => { <button onClick={() => setSelectedTerminal(terminal)}>
const t = parser.terminals.find(({ ID }) => ID === terminal); Select
return `${t?.ICAO} - ${t?.FullName}`; </button>
})()}
</span>
<pre>({terminal})</pre>
</div> </div>
))} ))}
</div> </div>
</div> </div>
</div>
); );
} }

View File

@ -14,4 +14,4 @@ fetch = async (path: string) => {
const parser = await Parser.instance(); const parser = await Parser.instance();
console.log(JSON.stringify(await parser.parse(12765))); console.log(JSON.stringify(await parser.parse(10480)));

View File

@ -12,40 +12,25 @@ import { TerminatorsTF } from "./terminators/TF.ts";
import { TerminatorsVI } from "./terminators/VI.ts"; import { TerminatorsVI } from "./terminators/VI.ts";
import { TerminatorsVD } from "./terminators/VD.ts"; import { TerminatorsVD } from "./terminators/VD.ts";
import { TerminatorsRF } from "./terminators/RF.ts"; import { TerminatorsRF } from "./terminators/RF.ts";
import { TerminatorsCA } from "./terminators/CA.ts";
import { TerminatorsDF } from "./terminators/DF.ts";
import { TerminatorsFD } from "./terminators/FD.ts";
import { TerminatorsFA } from "./terminators/FA.ts";
import { TerminatorsCD } from "./terminators/CD.ts";
import { TerminatorsVR } from "./terminators/VR.ts";
import { TerminatorsIF } from "./terminators/IF.ts";
import { TerminatorsFC } from "./terminators/FC.ts";
/*
Runway IDs for LIED
26156 - 34L
26157 - 34R
*/
class Parser { class Parser {
private static _instance: Parser; private static _instance: Parser;
private _waypoints: Waypoint[]; private waypoints: Waypoint[];
private _runways: Runway[]; private runways: Runway[];
private _terminals: Terminal[]; private terminals: Terminal[];
public static AC_SPEED = 250; public static AC_SPEED = 250;
public static AC_BANK = 30; public static AC_VS = 1500;
public static AC_VS = 1400;
private constructor( private constructor(
waypoints: Waypoint[], waypoints: Waypoint[],
runways: Runway[], runways: Runway[],
terminals: Terminal[] terminals: Terminal[]
) { ) {
this._waypoints = waypoints; this.waypoints = waypoints;
this._runways = runways; this.runways = runways;
this._terminals = terminals; this.terminals = terminals;
} }
public static instance = async () => { public static instance = async () => {
@ -60,42 +45,7 @@ class Parser {
return Parser._instance; return Parser._instance;
}; };
public get terminals() {
return this._terminals;
}
public get waypoints() {
return this._waypoints;
}
public get runways() {
return this._runways;
}
public parse = async (terminalID: number) => { public parse = async (terminalID: number) => {
// Get Procedure main
const terminal = this.terminals.find(({ ID }) => ID === terminalID);
if (!terminal) throw new Error("Procedure does not exists");
// Get runway this procedure is for
let runway = this.runways.find(({ ID }) => ID === terminal.RwyID);
if (!runway) {
let id = 26156;
if (typeof prompt !== "undefined")
// throw new Error("Prompt not defined, cannot continue");
id = Number.parseInt(prompt("Runway ID") ?? "");
runway = this.runways.find(({ ID }) => ID === id);
if (!runway) throw new Error("Procedure links to non existent Runway");
}
// Load procedure
const procedures = (await (
await fetch(`NavData/TermID_${terminalID}.json`)
).json()) as TerminalEntry[];
// Split into transitions
const transitions = new Set(procedures.map((proc) => proc.Transition));
const output: object[] = [];
// Main
transitions.forEach((transition) => {
// Private functions // Private functions
/** /**
* @param line Line segments * @param line Line segments
@ -113,22 +63,16 @@ class Parser {
); );
}; };
/** // Get Procedure main
* @param fix New fix const terminal = this.terminals.find(({ ID }) => ID === terminalID);
* @param line New line if (!terminal) throw new Error("Procedure does not exists");
* @param options Options for line rendering // Get runway this procedure is for
*/ const runway = this.runways.find(({ ID }) => ID === terminal.RwyID);
const update = ( if (!runway) throw new Error("Procedure links to non existent Runway");
fix?: NavFix, // Load procedure
line?: LineSegment[], const procedure = (await (
options?: Record<string, unknown> await fetch(`NavData/TermID_${terminalID}.json`)
) => { ).json()) as TerminalEntry[];
if (fix) navFixes.push(fix);
if (line) {
lineSegments.push({ line, ...options });
updateLastCourse(line);
}
};
// Output variables // Output variables
const navFixes: NavFix[] = []; const navFixes: NavFix[] = [];
@ -144,9 +88,7 @@ class Parser {
}); });
let lastCourse = runway.TrueHeading; let lastCourse = runway.TrueHeading;
const procedure = procedures.filter( // Main
(proc) => proc.Transition === transition
);
for (let index = 0; index < procedure.length; index++) { for (let index = 0; index < procedure.length; index++) {
const leg = procedure[index]; const leg = procedure[index];
const previousFix = navFixes.at(-1)!; const previousFix = navFixes.at(-1)!;
@ -159,27 +101,17 @@ class Parser {
previousFix, previousFix,
waypoint waypoint
); );
update(fixToAdd, lineToAdd); if (fixToAdd) navFixes.push(fixToAdd);
if (lineToAdd) {
lineSegments.push({ line: lineToAdd });
updateLastCourse(lineToAdd);
}
break; break;
} }
case "CA": { case "CA":
const [fixToAdd, lineToAdd] = TerminatorsCA( case "CD":
leg as CATerminalEntry, console.error("Unknown TrackCode", leg.TrackCode);
previousFix,
lastCourse
);
update(fixToAdd, lineToAdd);
break; break;
}
case "CD": {
const [fixToAdd, lineToAdd] = TerminatorsCD(
leg as CDTerminalEntry,
previousFix,
lastCourse
);
update(fixToAdd, lineToAdd);
break;
}
case "CF": { case "CF": {
const [fixToAdd, lineToAdd] = TerminatorsCF( const [fixToAdd, lineToAdd] = TerminatorsCF(
leg as CFTerminalEntry, leg as CFTerminalEntry,
@ -187,7 +119,11 @@ class Parser {
lastCourse, lastCourse,
waypoint waypoint
); );
update(fixToAdd, lineToAdd); if (fixToAdd) navFixes.push(fixToAdd);
if (lineToAdd) {
lineSegments.push({ line: lineToAdd });
updateLastCourse(lineToAdd);
}
break; break;
} }
case "CI": { case "CI": {
@ -197,7 +133,11 @@ class Parser {
previousFix, previousFix,
lastCourse lastCourse
); );
update(fixToAdd, lineToAdd); if (fixToAdd) navFixes.push(fixToAdd);
if (lineToAdd) {
lineSegments.push({ line: lineToAdd });
updateLastCourse(lineToAdd);
}
break; break;
} }
case "CR": { case "CR": {
@ -206,66 +146,36 @@ class Parser {
previousFix, previousFix,
lastCourse lastCourse
); );
update(fixToAdd, lineToAdd); if (fixToAdd) navFixes.push(fixToAdd);
if (lineToAdd) {
lineSegments.push({ line: lineToAdd });
updateLastCourse(lineToAdd);
}
break; break;
} }
case "DF": { case "DF":
const [fixToAdd, lineToAdd] = TerminatorsDF( case "FA":
leg as DFTerminalEntry, case "FC":
previousFix, case "FD":
lastCourse, console.error("Unknown TrackCode", leg.TrackCode);
waypoint
);
update(fixToAdd, lineToAdd);
break; break;
}
case "FA": {
const [fixToAdd, lineToAdd] = TerminatorsFA(
leg as FATerminalEntry,
previousFix,
lastCourse
);
update(fixToAdd, lineToAdd);
break;
}
case "FC": {
const [fixToAdd, lineToAdd] = TerminatorsFC(
leg as FCTerminalEntry,
previousFix,
lastCourse
);
update(fixToAdd, lineToAdd);
break;
}
case "FD": {
const [fixToAdd, lineToAdd] = TerminatorsFD(
leg as FDTerminalEntry,
previousFix,
lastCourse
);
update(fixToAdd, lineToAdd);
break;
}
case "FM": { case "FM": {
const [fixToAdd, lineToAdd] = TerminatorsFM( const [fixToAdd, lineToAdd] = TerminatorsFM(
leg as FMTerminalEntry, leg as FMTerminalEntry,
previousFix, previousFix,
lastCourse lastCourse
); );
update(fixToAdd, lineToAdd, { isManual: true }); if (fixToAdd) navFixes.push(fixToAdd);
if (lineToAdd) {
lineSegments.push({ line: lineToAdd, isManual: true });
updateLastCourse(lineToAdd);
}
break; break;
} }
case "HA": case "HA":
case "HF": case "HF":
case "HM": case "HM":
console.error("Unknown TrackCode", leg.TrackCode); case "IF":
break;
case "IF": {
const fixToAdd = TerminatorsIF(leg as RFTerminalEntry, waypoint);
navFixes.length = 0;
navFixes.push(fixToAdd);
break;
}
case "PI": case "PI":
console.error("Unknown TrackCode", leg.TrackCode); console.error("Unknown TrackCode", leg.TrackCode);
break; break;
@ -277,7 +187,11 @@ class Parser {
lastCourse, lastCourse,
waypoint waypoint
); );
update(fixToAdd, lineToAdd); if (fixToAdd) navFixes.push(fixToAdd);
if (lineToAdd) {
lineSegments.push({ line: lineToAdd });
updateLastCourse(lineToAdd);
}
break; break;
} }
case "TF": { case "TF": {
@ -287,7 +201,11 @@ class Parser {
lastCourse, lastCourse,
waypoint waypoint
); );
update(fixToAdd, lineToAdd); if (fixToAdd) navFixes.push(fixToAdd);
if (lineToAdd) {
lineSegments.push({ line: lineToAdd });
updateLastCourse(lineToAdd);
}
break; break;
} }
case "VA": { case "VA": {
@ -296,7 +214,11 @@ class Parser {
previousFix, previousFix,
lastCourse lastCourse
); );
update(fixToAdd, lineToAdd); if (fixToAdd) navFixes.push(fixToAdd);
if (lineToAdd) {
lineSegments.push({ line: lineToAdd });
updateLastCourse(lineToAdd);
}
break; break;
} }
case "VD": { case "VD": {
@ -305,7 +227,11 @@ class Parser {
previousFix, previousFix,
lastCourse lastCourse
); );
update(fixToAdd, lineToAdd); if (fixToAdd) navFixes.push(fixToAdd);
if (lineToAdd) {
lineSegments.push({ line: lineToAdd });
updateLastCourse(lineToAdd);
}
break; break;
} }
case "VI": { case "VI": {
@ -315,7 +241,11 @@ class Parser {
previousFix, previousFix,
lastCourse lastCourse
); );
update(fixToAdd, lineToAdd); if (fixToAdd) navFixes.push(fixToAdd);
if (lineToAdd) {
lineSegments.push({ line: lineToAdd });
updateLastCourse(lineToAdd);
}
break; break;
} }
case "VM": { case "VM": {
@ -324,33 +254,24 @@ class Parser {
previousFix, previousFix,
lastCourse lastCourse
); );
update(fixToAdd, lineToAdd, { isManual: true }); if (fixToAdd) navFixes.push(fixToAdd);
break; if (lineToAdd) {
} lineSegments.push({ line: lineToAdd, isManual: true });
case "VR": { updateLastCourse(lineToAdd);
const [fixToAdd, lineToAdd] = TerminatorsVR( }
leg as VRTerminalEntry,
previousFix,
lastCourse
);
update(fixToAdd, lineToAdd);
break; break;
} }
case "VR":
default: default:
console.error("Unknown TrackCode", leg.TrackCode); console.error("Unknown TrackCode", leg.TrackCode);
break; break;
} }
} }
output.push( return geojson.parse([...navFixes, ...lineSegments], {
geojson.parse([...navFixes, ...lineSegments], {
LineString: "line", LineString: "line",
Point: ["latitude", "longitude"], Point: ["latitude", "longitude"],
})
);
}); });
return output;
}; };
} }

View File

@ -1,31 +1,23 @@
import * as geolib from "geolib"; import * as geolib from "geolib";
import Parser from "../parser.ts"; import Parser from "../parser.ts";
import { computeTurnRate } from "../utils/computeTurnRate.ts";
/** /**
* @param crsIntoEndpoint Course into arc endpoint * @param crsIntoEndpoint Course into arc endpoint
* @param crsFromOrigin Course from arc origin point * @param crsFromOrigin Course from arc origin point
* @param start Arc origin point * @param start Arc origin point
* @param speed Speed within arc
* @param turnDir Turn direction * @param turnDir Turn direction
* @param force360 If true, force a 360° turn
* @returns Line segments * @returns Line segments
*/ */
export const generatePerformanceArc = ( export const generatePerformanceArc = (
crsIntoEndpoint: number, crsIntoEndpoint: number,
crsFromOrigin: number, crsFromOrigin: number,
start: NavFix, start: NavFix,
speed: number, turnDir?: TurnDirection
turnDir?: TurnDirection,
force360?: boolean
) => { ) => {
const turnRate = computeTurnRate(speed, Parser.AC_BANK);
const originalCrsFromOrigin = crsFromOrigin;
const line: LineSegment[] = [[start.longitude, start.latitude]]; const line: LineSegment[] = [[start.longitude, start.latitude]];
// Check if there even is an arc // Check if there even is an arc
if (force360 || !crsFromOrigin.equal(crsIntoEndpoint)) { if (crsIntoEndpoint !== crsFromOrigin) {
// Turn Dir // Turn Dir
if (!turnDir || turnDir === "E") { if (!turnDir || turnDir === "E") {
let prov = crsFromOrigin - crsIntoEndpoint; let prov = crsFromOrigin - crsIntoEndpoint;
@ -34,18 +26,15 @@ export const generatePerformanceArc = (
} }
// Generate arc // Generate arc
while (!crsFromOrigin.equal(crsIntoEndpoint)) { while (crsFromOrigin !== crsIntoEndpoint) {
let time = 0;
if (turnDir === "R") { if (turnDir === "R") {
const delta = (crsIntoEndpoint - crsFromOrigin).normaliseDegrees(); const delta = (crsIntoEndpoint - crsFromOrigin).normaliseDegrees();
const increment = delta < 1 ? delta : 1; crsFromOrigin += delta < 1 ? delta : 1;
crsFromOrigin = (crsFromOrigin + increment).normaliseDegrees(); crsFromOrigin = crsFromOrigin.normaliseDegrees();
time = increment / turnRate;
} else { } else {
const delta = (crsFromOrigin - crsIntoEndpoint).normaliseDegrees(); const delta = (crsFromOrigin - crsIntoEndpoint).normaliseDegrees();
const increment = delta < 1 ? delta : 1; crsFromOrigin -= delta < 1 ? delta : 1;
crsFromOrigin = (crsFromOrigin - increment).normaliseDegrees(); crsFromOrigin = crsFromOrigin.normaliseDegrees();
time = increment / turnRate;
} }
const arcFix = geolib.computeDestinationPoint( const arcFix = geolib.computeDestinationPoint(
@ -53,45 +42,12 @@ export const generatePerformanceArc = (
latitude: line.at(-1)![1], latitude: line.at(-1)![1],
longitude: line.at(-1)![0], longitude: line.at(-1)![0],
}, },
((speed / 3600) * time).toMetre(), (Parser.AC_SPEED / 3600).toMetre(),
crsFromOrigin crsFromOrigin
); );
line.push([arcFix.longitude, arcFix.latitude]); line.push([arcFix.longitude, arcFix.latitude]);
} }
// Second half
if (force360) {
const temp = crsIntoEndpoint;
crsIntoEndpoint = originalCrsFromOrigin;
crsFromOrigin = temp;
while (!crsFromOrigin.equal(crsIntoEndpoint)) {
let time = 0;
if (turnDir === "R") {
const delta = (crsIntoEndpoint - crsFromOrigin).normaliseDegrees();
const increment = delta < 1 ? delta : 1;
crsFromOrigin = (crsFromOrigin + increment).normaliseDegrees();
time = increment / turnRate;
} else {
const delta = (crsFromOrigin - crsIntoEndpoint).normaliseDegrees();
const increment = delta < 1 ? delta : 1;
crsFromOrigin = (crsFromOrigin - increment).normaliseDegrees();
time = increment / turnRate;
}
const arcFix = geolib.computeDestinationPoint(
{
latitude: line.at(-1)![1],
longitude: line.at(-1)![0],
},
((speed / 3600) * time).toMetre(),
crsFromOrigin
);
line.push([arcFix.longitude, arcFix.latitude]);
}
}
} }
return line; return line;

View File

@ -19,7 +19,7 @@ export const generateTangentArc = (
const line: LineSegment[] = [[start.longitude, start.latitude]]; const line: LineSegment[] = [[start.longitude, start.latitude]];
// Check if there even is an arc // Check if there even is an arc
if (!crsFromOrigin.equal(crsIntoEndpoint)) { if (crsFromOrigin !== crsIntoEndpoint) {
// Course to the end of the arc // Course to the end of the arc
let crsFromStartToEnd; let crsFromStartToEnd;
if (!turnDir || turnDir === "E") { if (!turnDir || turnDir === "E") {
@ -75,7 +75,7 @@ export const generateTangentArc = (
crsOrthogonalOnOrigin < 1 ? crsOrthogonalOnOrigin : 1; crsOrthogonalOnOrigin < 1 ? crsOrthogonalOnOrigin : 1;
} }
while (!crsOrthogonalOnOrigin.equal(crsOrthogonalOnEndpoint)) { while (crsOrthogonalOnOrigin !== crsOrthogonalOnEndpoint) {
if (turnDir === "R") { if (turnDir === "R") {
const delta = ( const delta = (
crsOrthogonalOnEndpoint - crsOrthogonalOnOrigin crsOrthogonalOnEndpoint - crsOrthogonalOnOrigin
@ -89,6 +89,7 @@ export const generateTangentArc = (
crsOrthogonalOnOrigin -= delta < 1 ? delta : 1; crsOrthogonalOnOrigin -= delta < 1 ? delta : 1;
crsOrthogonalOnOrigin = crsOrthogonalOnOrigin.normaliseDegrees(); crsOrthogonalOnOrigin = crsOrthogonalOnOrigin.normaliseDegrees();
} }
if (crsOrthogonalOnOrigin === crsOrthogonalOnEndpoint) break;
const arcFix = geolib.computeDestinationPoint( const arcFix = geolib.computeDestinationPoint(
arcCenter, arcCenter,

View File

@ -8,7 +8,6 @@ import { generatePerformanceArc } from "./generatePerformanceArc.ts";
* @param crsFromOrigin Course from arc origin point * @param crsFromOrigin Course from arc origin point
* @param start Waypoint where leg starts * @param start Waypoint where leg starts
* @param end Waypoint where leg ends * @param end Waypoint where leg ends
* @param speed Speed for performance arc
* @param turnDir Turn direction * @param turnDir Turn direction
* @returns Line segments from `start` to `end` * @returns Line segments from `start` to `end`
*/ */
@ -18,7 +17,6 @@ export const handleTurnAtFix = (
crsFromOrigin: number, crsFromOrigin: number,
start: NavFix, start: NavFix,
end: NavFix, end: NavFix,
speed: number,
turnDir?: TurnDirection turnDir?: TurnDirection
) => { ) => {
const line: LineSegment[] = []; const line: LineSegment[] = [];
@ -37,7 +35,6 @@ export const handleTurnAtFix = (
crsIntoIntercept, crsIntoIntercept,
crsFromOrigin, crsFromOrigin,
start, start,
speed,
turnDir turnDir
); );

View File

@ -1,6 +1,6 @@
import * as geolib from "geolib"; import * as geolib from "geolib";
import { generateAFArc } from "../pathGenerators/generateAFArc.ts"; import { generateAFArc } from "../pathGenerators/generateAFArc.ts";
import { computeSpeed } from "../utils/computeSpeed.ts"; import Parser from "../parser.ts";
export const TerminatorsAF = ( export const TerminatorsAF = (
leg: AFTerminalEntry, leg: AFTerminalEntry,
@ -13,7 +13,13 @@ export const TerminatorsAF = (
name: waypoint?.Ident ?? undefined, name: waypoint?.Ident ?? undefined,
isFlyOver: leg.IsFlyOver, isFlyOver: leg.IsFlyOver,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude, altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: computeSpeed(leg, previousFix), speed: leg.SpeedLimit
? leg.SpeedLimit > Parser.AC_SPEED
? Parser.AC_SPEED
: leg.SpeedLimit
: previousFix.speed
? previousFix.speed
: Parser.AC_SPEED,
speedConstraint: leg.SpeedLimit, speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt, altitudeConstraint: leg.Alt,
}; };
@ -28,7 +34,6 @@ export const TerminatorsAF = (
longitude: leg.WptLon, longitude: leg.WptLon,
} }
); );
const line = generateAFArc( const line = generateAFArc(
arcEndCrs, arcEndCrs,
leg.Course.toTrue({ latitude: leg.NavLat, longitude: leg.NavLon }), leg.Course.toTrue({ latitude: leg.NavLat, longitude: leg.NavLon }),

View File

@ -1,60 +0,0 @@
import * as geolib from "geolib";
import Parser from "../parser.ts";
import { computeSpeed } from "../utils/computeSpeed.ts";
import { generatePerformanceArc } from "../pathGenerators/generatePerformanceArc.ts";
export const TerminatorsCA = (
leg: CATerminalEntry,
previousFix: NavFix,
lastCourse: number
): [NavFix?, LineSegment[]?] => {
const speed = computeSpeed(leg, previousFix);
const crsIntoEndpoint = leg.Course.toTrue(previousFix);
let line: LineSegment[] = [];
if (previousFix.isFlyOver) {
line = generatePerformanceArc(
crsIntoEndpoint,
lastCourse,
previousFix,
speed,
leg.TurnDir
);
} else {
line.push([previousFix.longitude, previousFix.latitude]);
}
const arcEnd = { latitude: line.at(-1)![1], longitude: line.at(-1)![0] };
if (line.length > 1) {
lastCourse = geolib.getGreatCircleBearing(
{
latitude: line.at(-2)![1],
longitude: line.at(-2)![0],
},
arcEnd
);
}
const targetFix: NavFix = {
...geolib.computeDestinationPoint(
arcEnd,
(
((leg.Alt.parseAltitude() - (previousFix.altitude ?? 0)) /
Parser.AC_VS) *
((previousFix.speed ? previousFix.speed : Parser.AC_SPEED) / 60)
).toMetre(),
crsIntoEndpoint
),
name: leg.Alt,
isFlyOver: true,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: speed,
speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt,
};
line.push([targetFix.longitude, targetFix.latitude]);
return [targetFix, line];
};

View File

@ -1,70 +0,0 @@
import * as geolib from "geolib";
import { computeSpeed } from "../utils/computeSpeed.ts";
import { generatePerformanceArc } from "../pathGenerators/generatePerformanceArc.ts";
// NOTE: Distance not adjusted for altitude in this demo
export const TerminatorsCD = (
leg: CDTerminalEntry,
previousFix: NavFix,
lastCourse: number
): [NavFix?, LineSegment[]?] => {
const navaid = {
latitude: leg.NavLat,
longitude: leg.NavLon,
};
const speed = computeSpeed(leg, previousFix);
let line: LineSegment[] = [];
if (previousFix.isFlyOver) {
const crsIntoEndpoint = leg.Course.toTrue(previousFix);
line = generatePerformanceArc(
crsIntoEndpoint,
lastCourse,
previousFix,
speed,
leg.TurnDir
);
} else {
line.push([previousFix.longitude, previousFix.latitude]);
}
const arcEnd = { latitude: line.at(-1)![1], longitude: line.at(-1)![0] };
if (line.length > 1) {
lastCourse = geolib.getGreatCircleBearing(
{
latitude: line.at(-2)![1],
longitude: line.at(-2)![0],
},
arcEnd
);
}
const crsToNavaid = geolib.getGreatCircleBearing(arcEnd, navaid);
const distToNavaid = geolib.getDistance(arcEnd, navaid);
let remainingDistance = leg.Distance.toMetre();
// Navaid behind us
if (Math.abs(crsToNavaid - lastCourse) > 90) {
remainingDistance -= distToNavaid;
}
// Navaid in front of us
else {
// Navaid will not be passed before distance is hit
if (distToNavaid > remainingDistance)
remainingDistance = distToNavaid - remainingDistance;
}
const targetFix: NavFix = {
...geolib.computeDestinationPoint(arcEnd, remainingDistance, lastCourse),
name: leg.Distance.toString(),
isFlyOver: true,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: speed,
speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt,
};
line.push([targetFix.longitude, targetFix.latitude]);
return [targetFix, line];
};

View File

@ -1,5 +1,5 @@
import Parser from "../parser.ts";
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts"; import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
import { computeSpeed } from "../utils/computeSpeed.ts";
export const TerminatorsCF = ( export const TerminatorsCF = (
leg: CFTerminalEntry, leg: CFTerminalEntry,
@ -7,15 +7,19 @@ export const TerminatorsCF = (
lastCourse: number, lastCourse: number,
waypoint?: Waypoint waypoint?: Waypoint
): [NavFix?, LineSegment[]?] => { ): [NavFix?, LineSegment[]?] => {
const speed = computeSpeed(leg, previousFix);
const targetFix: NavFix = { const targetFix: NavFix = {
latitude: leg.WptLat, latitude: leg.WptLat,
longitude: leg.WptLon, longitude: leg.WptLon,
name: waypoint?.Ident ?? undefined, name: waypoint?.Ident ?? undefined,
isFlyOver: leg.IsFlyOver, isFlyOver: leg.IsFlyOver,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude, altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: speed, speed: leg.SpeedLimit
? leg.SpeedLimit > Parser.AC_SPEED
? Parser.AC_SPEED
: leg.SpeedLimit
: previousFix.speed
? previousFix.speed
: Parser.AC_SPEED,
speedConstraint: leg.SpeedLimit, speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt, altitudeConstraint: leg.Alt,
}; };
@ -26,7 +30,6 @@ export const TerminatorsCF = (
lastCourse, lastCourse,
previousFix, previousFix,
targetFix, targetFix,
speed,
leg.TurnDir leg.TurnDir
); );

View File

@ -1,6 +1,6 @@
import Parser from "../parser.ts";
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts"; import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
import { computeIntersection } from "../utils/computeIntersection.ts"; import { computeIntersection } from "../utils/computeIntersection.ts";
import { computeSpeed } from "../utils/computeSpeed.ts";
import { getCourseAndFixForIntercepts } from "../utils/getCourseAndFixForIntercepts.ts"; import { getCourseAndFixForIntercepts } from "../utils/getCourseAndFixForIntercepts.ts";
export const TerminatorsCI = ( export const TerminatorsCI = (
@ -10,7 +10,6 @@ export const TerminatorsCI = (
lastCourse: number lastCourse: number
): [NavFix?, LineSegment[]?] => { ): [NavFix?, LineSegment[]?] => {
const [crs, nextFix] = getCourseAndFixForIntercepts(nextLeg, previousFix); const [crs, nextFix] = getCourseAndFixForIntercepts(nextLeg, previousFix);
const speed = computeSpeed(leg, previousFix);
// Compute INTC // Compute INTC
const interceptFix: NavFix = { const interceptFix: NavFix = {
@ -22,7 +21,13 @@ export const TerminatorsCI = (
)!, )!,
isFlyOver: leg.IsFlyOver, isFlyOver: leg.IsFlyOver,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude, altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: speed, speed: leg.SpeedLimit
? leg.SpeedLimit > Parser.AC_SPEED
? Parser.AC_SPEED
: leg.SpeedLimit
: previousFix.speed
? previousFix.speed
: Parser.AC_SPEED,
speedConstraint: leg.SpeedLimit, speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt, altitudeConstraint: leg.Alt,
}; };
@ -33,7 +38,6 @@ export const TerminatorsCI = (
lastCourse, lastCourse,
previousFix, previousFix,
interceptFix, interceptFix,
speed,
leg.TurnDir leg.TurnDir
); );

View File

@ -1,56 +1,42 @@
import * as geolib from "geolib";
import { computeIntersection } from "../utils/computeIntersection.ts"; import { computeIntersection } from "../utils/computeIntersection.ts";
import { computeSpeed } from "../utils/computeSpeed.ts"; import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
import { generatePerformanceArc } from "../pathGenerators/generatePerformanceArc.ts"; import Parser from "../parser.ts";
export const TerminatorsCR = ( export const TerminatorsCR = (
leg: CRTerminalEntry, leg: CRTerminalEntry,
previousFix: NavFix, previousFix: NavFix,
lastCourse: number lastCourse: number
): [NavFix?, LineSegment[]?] => { ): [NavFix?, LineSegment[]?] => {
const navaid = { const crsIntoEndpoint = leg.Course.toTrue(previousFix);
latitude: leg.NavLat,
longitude: leg.NavLon,
};
const crsFromEndpoint = leg.Course.toTrue(previousFix);
const crsIntoEndpoint = leg.NavBear.toTrue(navaid);
const speed = computeSpeed(leg, previousFix);
let line: LineSegment[] = [];
if (previousFix.isFlyOver) {
line = generatePerformanceArc(
crsFromEndpoint,
lastCourse,
previousFix,
speed,
leg.TurnDir
);
} else {
line.push([previousFix.longitude, previousFix.latitude]);
}
const arcEnd = { latitude: line.at(-1)![1], longitude: line.at(-1)![0] };
if (line.length > 1) {
lastCourse = geolib.getGreatCircleBearing(
{
latitude: line.at(-2)![1],
longitude: line.at(-2)![0],
},
arcEnd
);
}
const interceptFix: NavFix = { const interceptFix: NavFix = {
...computeIntersection(arcEnd, crsFromEndpoint, navaid, crsIntoEndpoint)!, ...computeIntersection(
previousFix,
crsIntoEndpoint,
{ latitude: leg.NavLat, longitude: leg.NavLon },
leg.NavBear.toTrue({ latitude: leg.NavLat, longitude: leg.NavLon })
)!,
isFlyOver: leg.IsFlyOver, isFlyOver: leg.IsFlyOver,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude, altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: speed, speed: leg.SpeedLimit
? leg.SpeedLimit > Parser.AC_SPEED
? Parser.AC_SPEED
: leg.SpeedLimit
: previousFix.speed
? previousFix.speed
: Parser.AC_SPEED,
speedConstraint: leg.SpeedLimit, speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt, altitudeConstraint: leg.Alt,
}; };
line.push([interceptFix.longitude, interceptFix.latitude]); const line = handleTurnAtFix(
crsIntoEndpoint,
leg.Course.toTrue(previousFix),
lastCourse,
previousFix,
interceptFix,
leg.TurnDir
);
return [interceptFix, line]; return [interceptFix, line];
}; };

View File

@ -1,48 +0,0 @@
import * as geolib from "geolib";
import { computeSpeed } from "../utils/computeSpeed.ts";
import { generatePerformanceArc } from "../pathGenerators/generatePerformanceArc.ts";
export const TerminatorsDF = (
leg: DFTerminalEntry,
previousFix: NavFix,
lastCourse: number,
waypoint?: Waypoint
): [NavFix?, LineSegment[]?] => {
const speed = computeSpeed(leg, previousFix);
const targetFix: NavFix = {
latitude: leg.WptLat,
longitude: leg.WptLon,
name: waypoint?.Ident ?? undefined,
isFlyOver: leg.IsFlyOver,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: speed,
speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt,
};
let line: LineSegment[] = [];
if (previousFix.isFlyOver) {
const crsIntoEndpoint = geolib.getGreatCircleBearing(
previousFix,
targetFix
);
line = generatePerformanceArc(
crsIntoEndpoint,
lastCourse,
previousFix,
speed,
leg.TurnDir,
previousFix.latitude.equal(targetFix.latitude) &&
previousFix.longitude.equal(targetFix.longitude)
);
} else {
line.push([previousFix.longitude, previousFix.latitude]);
}
line.push([targetFix.longitude, targetFix.latitude]);
return [targetFix, line];
};

View File

@ -1,64 +0,0 @@
import * as geolib from "geolib";
import { computeSpeed } from "../utils/computeSpeed.ts";
import Parser from "../parser.ts";
import { generatePerformanceArc } from "../pathGenerators/generatePerformanceArc.ts";
export const TerminatorsFA = (
leg: FATerminalEntry,
previousFix: NavFix,
lastCourse: number
): [NavFix?, LineSegment[]?] => {
const refFix = {
latitude: leg.WptLat,
longitude: leg.WptLon,
};
const speed = computeSpeed(leg, previousFix);
const crsIntoEndpoint = leg.Course.toTrue(refFix);
let line: LineSegment[] = [];
if (previousFix.isFlyOver) {
line = generatePerformanceArc(
crsIntoEndpoint,
lastCourse,
previousFix,
speed,
leg.TurnDir
);
} else {
line.push([previousFix.longitude, previousFix.latitude]);
}
const arcEnd = { latitude: line.at(-1)![1], longitude: line.at(-1)![0] };
if (line.length > 1) {
lastCourse = geolib.getGreatCircleBearing(
{
latitude: line.at(-2)![1],
longitude: line.at(-2)![0],
},
arcEnd
);
}
const targetFix: NavFix = {
...geolib.computeDestinationPoint(
arcEnd,
(
((leg.Alt.parseAltitude() - (previousFix.altitude ?? 0)) /
Parser.AC_VS) *
((previousFix.speed ? previousFix.speed : Parser.AC_SPEED) / 60)
).toMetre(),
crsIntoEndpoint
),
name: leg.Alt,
isFlyOver: true,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: speed,
speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt,
};
line.push([targetFix.longitude, targetFix.latitude]);
return [targetFix, line];
};

View File

@ -1,98 +0,0 @@
import * as geolib from "geolib";
import { computeSpeed } from "../utils/computeSpeed.ts";
import Parser from "../parser.ts";
import { computeTurnRate } from "../utils/computeTurnRate.ts";
// NOTE: Distance not adjusted for altitude in this demo
export const TerminatorsFC = (
leg: FCTerminalEntry,
previousFix: NavFix,
lastCourse: number
): [NavFix?, LineSegment[]?] => {
const refFix = {
latitude: leg.WptLat,
longitude: leg.WptLon,
};
const speed = computeSpeed(leg, previousFix);
const turnRate = computeTurnRate(speed, Parser.AC_BANK);
const trackIntoEndpoint = leg.Course.toTrue(refFix);
const line: LineSegment[] = [[previousFix.longitude, previousFix.latitude]];
if (previousFix.isFlyOver) {
let crsIntoEndpoint = trackIntoEndpoint;
// Check if there even is an arc
if (!crsIntoEndpoint.equal(lastCourse)) {
// Turn Dir
if (!leg.TurnDir || leg.TurnDir === "E") {
let prov = lastCourse - crsIntoEndpoint;
prov = prov > 180 ? prov - 360 : prov <= -180 ? prov + 360 : prov;
leg.TurnDir = prov > 0 ? "L" : "R";
}
// Generate arc
let condition = false;
do {
let time = 0;
if (leg.TurnDir === "R") {
const delta = (crsIntoEndpoint - lastCourse).normaliseDegrees();
const increment = delta < 1 ? delta : 1;
lastCourse = (lastCourse + increment).normaliseDegrees();
time = increment / turnRate;
} else {
const delta = (lastCourse - crsIntoEndpoint).normaliseDegrees();
const increment = delta < 1 ? delta : 1;
lastCourse = (lastCourse - increment).normaliseDegrees();
time = increment / turnRate;
}
const arcFix = geolib.computeDestinationPoint(
{
latitude: line.at(-1)![1],
longitude: line.at(-1)![0],
},
((speed * time) / 3600).toMetre(),
lastCourse
);
line.push([arcFix.longitude, arcFix.latitude]);
if (leg.TurnDir === "R") {
condition = lastCourse > trackIntoEndpoint;
} else {
condition = lastCourse < trackIntoEndpoint;
}
} while (condition);
}
}
const arcEnd = { latitude: line.at(-1)![1], longitude: line.at(-1)![0] };
if (line.length > 1) {
lastCourse = geolib.getGreatCircleBearing(
{
latitude: line.at(-2)![1],
longitude: line.at(-2)![0],
},
arcEnd
);
}
const targetFix: NavFix = {
...geolib.computeDestinationPoint(
arcEnd,
leg.Distance.toMetre(),
lastCourse
),
name: leg.Distance.toString(),
isFlyOver: true,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: speed,
speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt,
};
line.push([targetFix.longitude, targetFix.latitude]);
return [targetFix, line];
};

View File

@ -1,74 +0,0 @@
import * as geolib from "geolib";
import { computeSpeed } from "../utils/computeSpeed.ts";
import { generatePerformanceArc } from "../pathGenerators/generatePerformanceArc.ts";
// NOTE: Distance not adjusted for altitude in this demo
export const TerminatorsFD = (
leg: FDTerminalEntry,
previousFix: NavFix,
lastCourse: number
): [NavFix?, LineSegment[]?] => {
const refFix = {
latitude: leg.WptLat,
longitude: leg.WptLon,
};
const navaid = {
latitude: leg.NavLat,
longitude: leg.NavLon,
};
const speed = computeSpeed(leg, previousFix);
let line: LineSegment[] = [];
if (previousFix.isFlyOver) {
const crsIntoEndpoint = leg.Course.toTrue(refFix);
line = generatePerformanceArc(
crsIntoEndpoint,
lastCourse,
previousFix,
speed,
leg.TurnDir
);
} else {
line.push([previousFix.longitude, previousFix.latitude]);
}
const arcEnd = { latitude: line.at(-1)![1], longitude: line.at(-1)![0] };
if (line.length > 1) {
lastCourse = geolib.getGreatCircleBearing(
{
latitude: line.at(-2)![1],
longitude: line.at(-2)![0],
},
arcEnd
);
}
const crsToNavaid = geolib.getGreatCircleBearing(arcEnd, navaid);
const distToNavaid = geolib.getDistance(arcEnd, navaid);
let remainingDistance = leg.Distance.toMetre();
// Navaid behind us
if (Math.abs(crsToNavaid - lastCourse) > 90) {
remainingDistance -= distToNavaid;
}
// Navaid in front of us
else {
// Navaid will not be passed before distance is hit
if (distToNavaid > remainingDistance)
remainingDistance = distToNavaid - remainingDistance;
}
const targetFix: NavFix = {
...geolib.computeDestinationPoint(arcEnd, remainingDistance, lastCourse),
name: leg.Distance.toString(),
isFlyOver: true,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: speed,
speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt,
};
line.push([targetFix.longitude, targetFix.latitude]);
return [targetFix, line];
};

View File

@ -1,14 +1,11 @@
import * as geolib from "geolib"; import * as geolib from "geolib";
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts"; import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
import { computeSpeed } from "../utils/computeSpeed.ts";
export const TerminatorsFM = ( export const TerminatorsFM = (
leg: FMTerminalEntry, leg: FMTerminalEntry,
previousFix: NavFix, previousFix: NavFix,
lastCourse: number lastCourse: number
): [NavFix?, LineSegment[]?] => { ): [NavFix?, LineSegment[]?] => {
const speed = computeSpeed(leg, previousFix);
const endpoint = geolib.computeDestinationPoint( const endpoint = geolib.computeDestinationPoint(
previousFix, previousFix,
(10).toMetre(), (10).toMetre(),
@ -21,7 +18,6 @@ export const TerminatorsFM = (
lastCourse, lastCourse,
previousFix, previousFix,
endpoint, endpoint,
speed,
leg.TurnDir leg.TurnDir
); );

View File

@ -1,19 +0,0 @@
import Parser from "../parser.ts";
export const TerminatorsIF = (
leg: IFTerminalEntry,
waypoint?: Waypoint
): NavFix => {
const targetFix: NavFix = {
latitude: leg.WptLat,
longitude: leg.WptLon,
name: waypoint?.Ident ?? undefined,
isFlyOver: leg.IsFlyOver,
altitude: leg.Alt ? leg.Alt.parseAltitude() : 0,
speed: leg.SpeedLimit ? leg.SpeedLimit : Parser.AC_SPEED,
speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt,
};
return targetFix;
};

View File

@ -1,6 +1,6 @@
import Parser from "../parser.ts";
import { getCourseAndFixForIntercepts } from "../utils/getCourseAndFixForIntercepts.ts"; import { getCourseAndFixForIntercepts } from "../utils/getCourseAndFixForIntercepts.ts";
import { generateRFArc } from "../pathGenerators/generateRFArc.ts"; import { generateRFArc } from "../pathGenerators/generateRFArc.ts";
import { computeSpeed } from "../utils/computeSpeed.ts";
export const TerminatorsRF = ( export const TerminatorsRF = (
leg: RFTerminalEntry, leg: RFTerminalEntry,
@ -15,7 +15,13 @@ export const TerminatorsRF = (
name: waypoint?.Ident ?? undefined, name: waypoint?.Ident ?? undefined,
isFlyOver: leg.IsFlyOver, isFlyOver: leg.IsFlyOver,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude, altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: computeSpeed(leg, previousFix), speed: leg.SpeedLimit
? leg.SpeedLimit > Parser.AC_SPEED
? Parser.AC_SPEED
: leg.SpeedLimit
: previousFix.speed
? previousFix.speed
: Parser.AC_SPEED,
speedConstraint: leg.SpeedLimit, speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt, altitudeConstraint: leg.Alt,
}; };
@ -29,7 +35,6 @@ export const TerminatorsRF = (
{ latitude: leg.CenterLat, longitude: leg.CenterLon }, { latitude: leg.CenterLat, longitude: leg.CenterLon },
leg.TurnDir leg.TurnDir
); );
line.push([targetFix.longitude, targetFix.latitude]); line.push([targetFix.longitude, targetFix.latitude]);
return [targetFix, line]; return [targetFix, line];

View File

@ -1,5 +1,5 @@
import * as geolib from "geolib"; import * as geolib from "geolib";
import { computeSpeed } from "../utils/computeSpeed.ts"; import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
import Parser from "../parser.ts"; import Parser from "../parser.ts";
export const TerminatorsTF = ( export const TerminatorsTF = (
@ -14,68 +14,26 @@ export const TerminatorsTF = (
name: waypoint?.Ident ?? undefined, name: waypoint?.Ident ?? undefined,
isFlyOver: leg.IsFlyOver, isFlyOver: leg.IsFlyOver,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude, altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: computeSpeed(leg, previousFix), speed: leg.SpeedLimit
? leg.SpeedLimit > Parser.AC_SPEED
? Parser.AC_SPEED
: leg.SpeedLimit
: previousFix.speed
? previousFix.speed
: Parser.AC_SPEED,
speedConstraint: leg.SpeedLimit, speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt, altitudeConstraint: leg.Alt,
}; };
const line: LineSegment[] = [[previousFix.longitude, previousFix.latitude]]; const crs = geolib.getGreatCircleBearing(previousFix, targetFix);
const line = handleTurnAtFix(
const trackIntoEndpoint = geolib.getGreatCircleBearing( crs,
crs,
lastCourse,
previousFix, previousFix,
targetFix targetFix,
leg.TurnDir
); );
if (previousFix.isFlyOver) {
let crsIntoEndpoint = trackIntoEndpoint;
// Check if there even is an arc
if (crsIntoEndpoint !== lastCourse) {
// Turn Dir
if (!leg.TurnDir || leg.TurnDir === "E") {
let prov = lastCourse - crsIntoEndpoint;
prov = prov > 180 ? prov - 360 : prov <= -180 ? prov + 360 : prov;
leg.TurnDir = prov > 0 ? "L" : "R";
}
// Generate arc
let condition = false;
do {
if (leg.TurnDir === "R") {
const delta = (crsIntoEndpoint - lastCourse).normaliseDegrees();
lastCourse += delta < 1 ? delta : 1;
lastCourse = lastCourse.normaliseDegrees();
} else {
const delta = (lastCourse - crsIntoEndpoint).normaliseDegrees();
lastCourse -= delta < 1 ? delta : 1;
lastCourse = lastCourse.normaliseDegrees();
}
const arcFix = geolib.computeDestinationPoint(
{
latitude: line.at(-1)![1],
longitude: line.at(-1)![0],
},
(
(previousFix.speed ? previousFix.speed : Parser.AC_SPEED) / 3600
).toMetre(),
lastCourse
);
line.push([arcFix.longitude, arcFix.latitude]);
crsIntoEndpoint = geolib.getGreatCircleBearing(arcFix, targetFix);
if (leg.TurnDir === "R") {
condition = crsIntoEndpoint > trackIntoEndpoint;
} else {
condition = crsIntoEndpoint < trackIntoEndpoint;
}
} while (condition);
}
}
line.push([targetFix.longitude, targetFix.latitude]);
return [targetFix, line]; return [targetFix, line];
}; };

View File

@ -1,7 +1,6 @@
import * as geolib from "geolib"; import * as geolib from "geolib";
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
import Parser from "../parser.ts"; import Parser from "../parser.ts";
import { computeSpeed } from "../utils/computeSpeed.ts";
import { generatePerformanceArc } from "../pathGenerators/generatePerformanceArc.ts";
// NOTE: No wind adjustments to be made, no clue how *that* would draw // NOTE: No wind adjustments to be made, no clue how *that* would draw
export const TerminatorsVA = ( export const TerminatorsVA = (
@ -9,53 +8,38 @@ export const TerminatorsVA = (
previousFix: NavFix, previousFix: NavFix,
lastCourse: number lastCourse: number
): [NavFix?, LineSegment[]?] => { ): [NavFix?, LineSegment[]?] => {
const speed = computeSpeed(leg, previousFix);
const crsIntoEndpoint = leg.Course.toTrue(previousFix);
let line: LineSegment[] = [];
if (previousFix.isFlyOver) {
line = generatePerformanceArc(
crsIntoEndpoint,
lastCourse,
previousFix,
speed,
leg.TurnDir
);
} else {
line.push([previousFix.longitude, previousFix.latitude]);
}
const arcEnd = { latitude: line.at(-1)![1], longitude: line.at(-1)![0] };
if (line.length > 1) {
lastCourse = geolib.getGreatCircleBearing(
{
latitude: line.at(-2)![1],
longitude: line.at(-2)![0],
},
arcEnd
);
}
const targetFix: NavFix = { const targetFix: NavFix = {
...geolib.computeDestinationPoint( ...geolib.computeDestinationPoint(
arcEnd, previousFix,
( (
((leg.Alt.parseAltitude() - (previousFix.altitude ?? 0)) / ((leg.Alt.parseAltitude() - (previousFix.altitude ?? 0)) /
Parser.AC_VS) * Parser.AC_VS) *
((previousFix.speed ? previousFix.speed : Parser.AC_SPEED) / 60) (Parser.AC_SPEED / 60)
).toMetre(), ).toMetre(),
crsIntoEndpoint leg.Course.toTrue(previousFix)
), ),
name: leg.Alt, name: leg.Alt,
isFlyOver: true, isFlyOver: true,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude, altitude: leg.Alt.parseAltitude(),
speed: speed, speed: leg.SpeedLimit
? leg.SpeedLimit > Parser.AC_SPEED
? Parser.AC_SPEED
: leg.SpeedLimit
: previousFix.speed
? previousFix.speed
: Parser.AC_SPEED,
speedConstraint: leg.SpeedLimit, speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt, altitudeConstraint: leg.Alt,
}; };
line.push([targetFix.longitude, targetFix.latitude]); const line = handleTurnAtFix(
leg.Course.toTrue(previousFix),
leg.Course.toTrue(previousFix),
lastCourse,
previousFix,
targetFix,
leg.TurnDir
);
return [targetFix, line]; return [targetFix, line];
}; };

View File

@ -1,71 +1,41 @@
import * as geolib from "geolib"; import * as geolib from "geolib";
import { computeSpeed } from "../utils/computeSpeed.ts"; import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
import { generatePerformanceArc } from "../pathGenerators/generatePerformanceArc.ts"; import Parser from "../parser.ts";
// NOTE: No wind adjustments to be made, no clue how *that* would draw // NOTE: No wind adjustments to be made, no clue how *that* would draw
// NOTE: Distance not adjusted for altitude in this demo
export const TerminatorsVD = ( export const TerminatorsVD = (
leg: VDTerminalEntry, leg: VDTerminalEntry,
previousFix: NavFix, previousFix: NavFix,
lastCourse: number lastCourse: number
): [NavFix?, LineSegment[]?] => { ): [NavFix?, LineSegment[]?] => {
const navaid = {
latitude: leg.NavLat,
longitude: leg.NavLon,
};
const speed = computeSpeed(leg, previousFix);
let line: LineSegment[] = [];
if (previousFix.isFlyOver) {
const crsIntoEndpoint = leg.Course.toTrue(previousFix);
line = generatePerformanceArc(
crsIntoEndpoint,
lastCourse,
previousFix,
speed,
leg.TurnDir
);
} else {
line.push([previousFix.longitude, previousFix.latitude]);
}
const arcEnd = { latitude: line.at(-1)![1], longitude: line.at(-1)![0] };
if (line.length > 1) {
lastCourse = geolib.getGreatCircleBearing(
{
latitude: line.at(-2)![1],
longitude: line.at(-2)![0],
},
arcEnd
);
}
const crsToNavaid = geolib.getGreatCircleBearing(arcEnd, navaid);
const distToNavaid = geolib.getDistance(arcEnd, navaid);
let remainingDistance = leg.Distance.toMetre();
// Navaid behind us
if (Math.abs(crsToNavaid - lastCourse) > 90) {
remainingDistance -= distToNavaid;
}
// Navaid in front of us
else {
// Navaid will not be passed before distance is hit
if (distToNavaid > remainingDistance)
remainingDistance = distToNavaid - remainingDistance;
}
const targetFix: NavFix = { const targetFix: NavFix = {
...geolib.computeDestinationPoint(arcEnd, remainingDistance, lastCourse), ...geolib.computeDestinationPoint(
previousFix,
leg.Distance.toMetre(),
leg.Course.toTrue(previousFix)
),
name: leg.Distance.toString(), name: leg.Distance.toString(),
isFlyOver: true, isFlyOver: true,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude, altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: speed, speed: leg.SpeedLimit
? leg.SpeedLimit > Parser.AC_SPEED
? Parser.AC_SPEED
: leg.SpeedLimit
: previousFix.speed
? previousFix.speed
: Parser.AC_SPEED,
speedConstraint: leg.SpeedLimit, speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt, altitudeConstraint: leg.Alt,
}; };
line.push([targetFix.longitude, targetFix.latitude]); const line = handleTurnAtFix(
leg.Course.toTrue(previousFix),
leg.Course.toTrue(previousFix),
lastCourse,
previousFix,
targetFix,
leg.TurnDir
);
return [targetFix, line]; return [targetFix, line];
}; };

View File

@ -1,6 +1,6 @@
import Parser from "../parser.ts";
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts"; import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
import { computeIntersection } from "../utils/computeIntersection.ts"; import { computeIntersection } from "../utils/computeIntersection.ts";
import { computeSpeed } from "../utils/computeSpeed.ts";
import { getCourseAndFixForIntercepts } from "../utils/getCourseAndFixForIntercepts.ts"; import { getCourseAndFixForIntercepts } from "../utils/getCourseAndFixForIntercepts.ts";
// NOTE: No wind adjustments to be made, no clue how *that* would draw // NOTE: No wind adjustments to be made, no clue how *that* would draw
@ -11,7 +11,6 @@ export const TerminatorsVI = (
lastCourse: number lastCourse: number
): [NavFix?, LineSegment[]?] => { ): [NavFix?, LineSegment[]?] => {
const [crs, nextFix] = getCourseAndFixForIntercepts(nextLeg, previousFix); const [crs, nextFix] = getCourseAndFixForIntercepts(nextLeg, previousFix);
const speed = computeSpeed(leg, previousFix);
// Compute INTC // Compute INTC
const interceptFix: NavFix = { const interceptFix: NavFix = {
@ -23,7 +22,13 @@ export const TerminatorsVI = (
)!, )!,
isFlyOver: leg.IsFlyOver, isFlyOver: leg.IsFlyOver,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude, altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: speed, speed: leg.SpeedLimit
? leg.SpeedLimit > Parser.AC_SPEED
? Parser.AC_SPEED
: leg.SpeedLimit
: previousFix.speed
? previousFix.speed
: Parser.AC_SPEED,
speedConstraint: leg.SpeedLimit, speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt, altitudeConstraint: leg.Alt,
}; };
@ -34,7 +39,6 @@ export const TerminatorsVI = (
lastCourse, lastCourse,
previousFix, previousFix,
interceptFix, interceptFix,
speed,
leg.TurnDir leg.TurnDir
); );

View File

@ -1,6 +1,5 @@
import * as geolib from "geolib"; import * as geolib from "geolib";
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts"; import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
import { computeSpeed } from "../utils/computeSpeed.ts";
// NOTE: No wind adjustments to be made, no clue how *that* would draw // NOTE: No wind adjustments to be made, no clue how *that* would draw
export const TerminatorsVM = ( export const TerminatorsVM = (
@ -8,8 +7,6 @@ export const TerminatorsVM = (
previousFix: NavFix, previousFix: NavFix,
lastCourse: number lastCourse: number
): [NavFix?, LineSegment[]?] => { ): [NavFix?, LineSegment[]?] => {
const speed = computeSpeed(leg, previousFix);
const endpoint = geolib.computeDestinationPoint( const endpoint = geolib.computeDestinationPoint(
previousFix, previousFix,
(10).toMetre(), (10).toMetre(),
@ -22,7 +19,6 @@ export const TerminatorsVM = (
lastCourse, lastCourse,
previousFix, previousFix,
endpoint, endpoint,
speed,
leg.TurnDir leg.TurnDir
); );

View File

@ -1,57 +0,0 @@
import * as geolib from "geolib";
import { computeIntersection } from "../utils/computeIntersection.ts";
import { computeSpeed } from "../utils/computeSpeed.ts";
import { generatePerformanceArc } from "../pathGenerators/generatePerformanceArc.ts";
// NOTE: No wind adjustments to be made, no clue how *that* would draw
export const TerminatorsVR = (
leg: VRTerminalEntry,
previousFix: NavFix,
lastCourse: number
): [NavFix?, LineSegment[]?] => {
const navaid = {
latitude: leg.NavLat,
longitude: leg.NavLon,
};
const crsFromEndpoint = leg.Course.toTrue(previousFix);
const crsIntoEndpoint = leg.NavBear.toTrue(navaid);
const speed = computeSpeed(leg, previousFix);
let line: LineSegment[] = [];
if (previousFix.isFlyOver) {
line = generatePerformanceArc(
crsFromEndpoint,
lastCourse,
previousFix,
speed,
leg.TurnDir
);
} else {
line.push([previousFix.longitude, previousFix.latitude]);
}
const arcEnd = { latitude: line.at(-1)![1], longitude: line.at(-1)![0] };
if (line.length > 1) {
lastCourse = geolib.getGreatCircleBearing(
{
latitude: line.at(-2)![1],
longitude: line.at(-2)![0],
},
arcEnd
);
}
const interceptFix: NavFix = {
...computeIntersection(arcEnd, crsFromEndpoint, navaid, crsIntoEndpoint)!,
isFlyOver: leg.IsFlyOver,
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
speed: speed,
speedConstraint: leg.SpeedLimit,
altitudeConstraint: leg.Alt,
};
line.push([interceptFix.longitude, interceptFix.latitude]);
return [interceptFix, line];
};

View File

@ -1,12 +0,0 @@
import Parser from "../parser.ts";
export const computeSpeed = (leg: TerminalEntry, previousFix: NavFix) => {
if (leg.SpeedLimit) return leg.SpeedLimit;
if (previousFix.speed) {
if (previousFix.speed < Parser.AC_SPEED) return Parser.AC_SPEED;
return previousFix.speed;
}
return Parser.AC_SPEED;
};

View File

@ -1,3 +0,0 @@
export const computeTurnRate = (speed: number, bank: number) => {
return (1091 * Math.tan(bank.toRadians())) / speed;
};

View File

@ -25,22 +25,7 @@ Number.prototype.toTrue = function (fix) {
Number.prototype.toMetre = function () { Number.prototype.toMetre = function () {
return (this as number) * 1852.0; return (this as number) * 1852.0;
}; };
Number.prototype.equal = function (other: number) {
return Math.abs((this as number) - other) < 0.1;
};
String.prototype.parseAltitude = function () { String.prototype.parseAltitude = function () {
switch (this.length) {
case 5:
return Number.parseInt(this as string);
case 6:
return Number.parseInt(this.substring(0, 5)); return Number.parseInt(this.substring(0, 5));
case 12: {
const upper = Number.parseInt(this.substring(0, 5));
const lower = Number.parseInt(this.substring(6, 12));
return lower + (upper - lower) / 2;
}
default:
return -1;
}
}; };

View File

@ -25,10 +25,6 @@ export declare global {
* @returns Value converted from nmi to metres * @returns Value converted from nmi to metres
*/ */
toMetre: () => number; toMetre: () => number;
/**
* @returns True if delta is less than 0.1
*/
equal: (other: number) => boolean;
} }
interface String { interface String {

View File

@ -1,4 +0,0 @@
export declare global {
type CATerminalEntry = Required<Pick<TerminalEntry, "Course" | "Alt">> &
TerminalEntry;
}

View File

@ -1,6 +0,0 @@
export declare global {
type CDTerminalEntry = Required<
Pick<TerminalEntry, "NavID" | "NavLat" | "NavLon" | "Course" | "Distance">
> &
TerminalEntry;
}

View File

@ -1,6 +0,0 @@
export declare global {
type DFTerminalEntry = Required<
Pick<TerminalEntry, "WptID" | "WptLat" | "WptLon" | "IsFlyOver">
> &
TerminalEntry;
}

View File

@ -1,18 +0,0 @@
export declare global {
type FATerminalEntry = Required<
Pick<
TerminalEntry,
| "WptID"
| "WptLat"
| "WptLon"
| "NavID"
| "NavLat"
| "NavLon"
| "NavBear"
| "NavDist"
| "Course"
| "Alt"
>
> &
TerminalEntry;
}

View File

@ -1,19 +0,0 @@
export declare global {
type FCTerminalEntry = Required<
Pick<
TerminalEntry,
| "WptID"
| "WptLat"
| "WptLon"
| "IsFlyOver"
| "NavID"
| "NavLat"
| "NavLon"
| "NavBear"
| "NavDist"
| "Course"
| "Distance"
>
> &
TerminalEntry;
}

View File

@ -1,18 +0,0 @@
export declare global {
type FDTerminalEntry = Required<
Pick<
TerminalEntry,
| "WptID"
| "WptLat"
| "WptLon"
| "NavID"
| "NavLat"
| "NavLon"
| "NavBear"
| "NavDist"
| "Course"
| "Distance"
>
> &
TerminalEntry;
}

View File

@ -1,6 +0,0 @@
export declare global {
type IFTerminalEntry = Required<
Pick<TerminalEntry, "WptID" | "WptLat" | "WptLon">
> &
TerminalEntry;
}

View File

@ -1,6 +0,0 @@
export declare global {
type VRTerminalEntry = Required<
Pick<TerminalEntry, "NavID" | "NavLat" | "NavLon" | "NavBear" | "Course">
> &
TerminalEntry;
}