Compare commits
4 Commits
0d797519cb
...
8b04be187e
| Author | SHA1 | Date | |
|---|---|---|---|
| 8b04be187e | |||
| e41d002cef | |||
| d90ba6c5e3 | |||
| 49788eddab |
22
README.md
22
README.md
@ -55,6 +55,8 @@ LGAV BIBE1L SID (Cycle 2507, ID 10654)
|
||||
### Instructions
|
||||
|
||||
- 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
|
||||
|
||||
@ -84,6 +86,8 @@ LGAV BIBE2F SID (Cycle 2507, ID 10657)
|
||||
|
||||
- From preceding fix, fly along `Course` until reaching `Distance` from the navaid identified by
|
||||
`NavID`.
|
||||
- If preceding fix was overfly, offset outbound `Course` to end of turn (tangent).
|
||||
- Earliest leg terminations is at point of tangent.
|
||||
|
||||
### Units
|
||||
|
||||
@ -116,6 +120,7 @@ LGAV BIBE2F SID (Cycle 2507, ID 10657)
|
||||
|
||||
- From preceding fix, fly `Course` to the fix identified by (`WptID`, `WptLat`, `WptLon`) *or*
|
||||
(`NavID`, `NavLat`, `NavLon`, `NavDist`, `NavBear`).
|
||||
- If preceding fix was overfly, continue turn until intercept `Course`, then continue on `Course`.
|
||||
|
||||
### Units
|
||||
|
||||
@ -201,14 +206,16 @@ LGAV KOR1D SID (Cycle 2507, ID 10679)
|
||||
|
||||
### 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
|
||||
|
||||
- `IsFlyOver`: Boolean indicating if fix is a mandatory fly over.
|
||||
|
||||
|
||||
## Fix to Altitude (FA)
|
||||
## Track from Fix to Altitude (FA)
|
||||
|
||||
### Example
|
||||
|
||||
@ -227,6 +234,8 @@ LGAV BIBE2F SID (Cycle 2507, ID 10657)
|
||||
|
||||
- From the fix identified by (`WptID`, `WptLat`, `WptLon`) *or*
|
||||
(`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
|
||||
|
||||
@ -261,6 +270,9 @@ LIED CAR6F SID (Cycle 2507, ID 11798)
|
||||
|
||||
- From the fix identified by (`WptID`, `WptLat`, `WptLon`) *or*
|
||||
(`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
|
||||
|
||||
@ -292,8 +304,10 @@ LGAV BIBE2T SID (Cycle 2507, ID 10659)
|
||||
### Instructions
|
||||
|
||||
- From the fix identified by (`WptID`, `WptLat`, `WptLon`) *or*
|
||||
(`NavID`, `NavLat`, `NavLon`, `NavDist`, `NavBear`), fly `Course` until
|
||||
reaching `Distance` from navaid identified by `NavID`.
|
||||
(`NavID`, `NavLat`, `NavLon`, `NavDist`, `NavBear`), fly `Course` until 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
|
||||
|
||||
|
||||
@ -8,18 +8,21 @@ import L from "leaflet";
|
||||
|
||||
const parser = await Parser.instance();
|
||||
|
||||
const terminals = [10394, 10395, 10475, 10480, 10482, 10485, 10653];
|
||||
const terminals = [
|
||||
10394, 10395, 10475, 10480, 10482, 10485, 10653, 10654, 10657, 10659, 10679,
|
||||
11798, 11909, 12765,
|
||||
];
|
||||
|
||||
function App() {
|
||||
const [selectedTerminal, setSelectedTerminal] = useState(terminals[0]);
|
||||
const [procedure, setProcedure] = useState<object>();
|
||||
const [procedures, setProcedures] = useState<object[]>([]);
|
||||
|
||||
const mapRef = createRef<Leaflet.Map>();
|
||||
const layerRef = createRef<Leaflet.GeoJSON>();
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
setProcedure(await parser.parse(selectedTerminal));
|
||||
setProcedures(await parser.parse(selectedTerminal));
|
||||
})();
|
||||
}, [selectedTerminal]);
|
||||
|
||||
@ -47,82 +50,102 @@ function App() {
|
||||
attribution='© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
||||
url="https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png"
|
||||
/>
|
||||
<GeoJSON
|
||||
key={hash(procedure ?? "") + "lines"}
|
||||
data={procedure}
|
||||
style={({ properties }) => ({
|
||||
color: "#ff00ff",
|
||||
stroke: true,
|
||||
weight: 5,
|
||||
opacity: 1,
|
||||
dashArray: properties.isManual ? "20, 20" : undefined,
|
||||
})}
|
||||
filter={(feature) => feature.geometry.type !== "Point"}
|
||||
ref={layerRef}
|
||||
/>
|
||||
<GeoJSON
|
||||
key={hash(procedure ?? "") + "points"}
|
||||
data={procedure}
|
||||
style={{
|
||||
color: "black",
|
||||
fill: true,
|
||||
fillColor: "transparent",
|
||||
stroke: true,
|
||||
weight: 3,
|
||||
}}
|
||||
pointToLayer={({ properties }, latlng) => {
|
||||
if (properties.isFlyOver)
|
||||
return L.shapeMarker(latlng, {
|
||||
shape: "triangle",
|
||||
radius: 6,
|
||||
});
|
||||
if (properties.isIntersection)
|
||||
return L.circleMarker(latlng, { radius: 6 });
|
||||
{procedures.map((procedure) => (
|
||||
<>
|
||||
<GeoJSON
|
||||
key={hash(procedure ?? "") + "lines"}
|
||||
data={procedure}
|
||||
style={({ properties }) => ({
|
||||
color: "#ff00ff",
|
||||
stroke: true,
|
||||
weight: 5,
|
||||
opacity: 1,
|
||||
dashArray: properties.isManual ? "20, 20" : undefined,
|
||||
})}
|
||||
filter={(feature) => feature.geometry.type !== "Point"}
|
||||
ref={layerRef}
|
||||
/>
|
||||
<GeoJSON
|
||||
key={hash(procedure ?? "") + "points"}
|
||||
data={procedure}
|
||||
style={{
|
||||
color: "black",
|
||||
fill: true,
|
||||
fillColor: "transparent",
|
||||
stroke: true,
|
||||
weight: 3,
|
||||
}}
|
||||
pointToLayer={({ properties }, latlng) => {
|
||||
if (properties.isFlyOver)
|
||||
return L.shapeMarker(latlng, {
|
||||
shape: "triangle",
|
||||
radius: 6,
|
||||
});
|
||||
if (properties.isIntersection)
|
||||
return L.circleMarker(latlng, { radius: 6 });
|
||||
|
||||
return L.shapeMarker(latlng, {
|
||||
shape: "star-4",
|
||||
radius: 10,
|
||||
rotation: 45,
|
||||
});
|
||||
}}
|
||||
onEachFeature={({ geometry, properties }, layer) => {
|
||||
if (geometry.type === "Point") {
|
||||
layer.bindPopup(
|
||||
`${properties.name}<br>
|
||||
return L.shapeMarker(latlng, {
|
||||
shape: "star-4",
|
||||
radius: 10,
|
||||
rotation: 45,
|
||||
});
|
||||
}}
|
||||
onEachFeature={({ geometry, properties }, layer) => {
|
||||
if (geometry.type === "Point") {
|
||||
layer.bindPopup(
|
||||
`${properties.name}<br>
|
||||
${properties.altitude} ft<br>
|
||||
${properties.speed} kts<br>
|
||||
CNSTR:
|
||||
${properties.altitudeConstraint ?? ""}
|
||||
${properties.speedConstraint ?? ""}<br>`
|
||||
);
|
||||
}
|
||||
}}
|
||||
filter={(feature) => feature.geometry.type === "Point"}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}}
|
||||
filter={(feature) => feature.geometry.type === "Point"}
|
||||
/>
|
||||
</>
|
||||
))}
|
||||
</MapContainer>
|
||||
<div
|
||||
style={{
|
||||
padding: "5px",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "10px",
|
||||
overflowY: "scroll",
|
||||
width: "200px",
|
||||
}}
|
||||
>
|
||||
{terminals.map((terminal) => (
|
||||
<div
|
||||
key={terminal}
|
||||
style={{
|
||||
display: "flex",
|
||||
gap: "10px",
|
||||
background: selectedTerminal === terminal ? "#eeeeee" : undefined,
|
||||
}}
|
||||
>
|
||||
<pre>ID {terminal}</pre>
|
||||
<button onClick={() => setSelectedTerminal(terminal)}>
|
||||
Select
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
<div
|
||||
style={{
|
||||
padding: "5px",
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
gap: "10px",
|
||||
}}
|
||||
>
|
||||
{terminals.map((terminal) => (
|
||||
<div
|
||||
key={terminal}
|
||||
style={{
|
||||
display: "flex",
|
||||
flexDirection: "column",
|
||||
background: "#eeeeee",
|
||||
border:
|
||||
selectedTerminal === terminal
|
||||
? "1px solid black"
|
||||
: "1px solid #eeeeee",
|
||||
padding: "5px",
|
||||
}}
|
||||
onClick={() => setSelectedTerminal(terminal)}
|
||||
>
|
||||
<span style={{ whiteSpace: "nowrap" }}>
|
||||
{(() => {
|
||||
const t = parser.terminals.find(({ ID }) => ID === terminal);
|
||||
return `${t?.ICAO} - ${t?.FullName}`;
|
||||
})()}
|
||||
</span>
|
||||
<pre>({terminal})</pre>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
@ -14,4 +14,4 @@ fetch = async (path: string) => {
|
||||
|
||||
const parser = await Parser.instance();
|
||||
|
||||
console.log(JSON.stringify(await parser.parse(10480)));
|
||||
console.log(JSON.stringify(await parser.parse(12765)));
|
||||
|
||||
@ -12,25 +12,40 @@ import { TerminatorsTF } from "./terminators/TF.ts";
|
||||
import { TerminatorsVI } from "./terminators/VI.ts";
|
||||
import { TerminatorsVD } from "./terminators/VD.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 {
|
||||
private static _instance: Parser;
|
||||
|
||||
private waypoints: Waypoint[];
|
||||
private runways: Runway[];
|
||||
private terminals: Terminal[];
|
||||
private _waypoints: Waypoint[];
|
||||
private _runways: Runway[];
|
||||
private _terminals: Terminal[];
|
||||
|
||||
public static AC_SPEED = 250;
|
||||
public static AC_VS = 1500;
|
||||
public static AC_BANK = 30;
|
||||
public static AC_VS = 1400;
|
||||
|
||||
private constructor(
|
||||
waypoints: Waypoint[],
|
||||
runways: Runway[],
|
||||
terminals: Terminal[]
|
||||
) {
|
||||
this.waypoints = waypoints;
|
||||
this.runways = runways;
|
||||
this.terminals = terminals;
|
||||
this._waypoints = waypoints;
|
||||
this._runways = runways;
|
||||
this._terminals = terminals;
|
||||
}
|
||||
|
||||
public static instance = async () => {
|
||||
@ -45,233 +60,297 @@ class Parser {
|
||||
return Parser._instance;
|
||||
};
|
||||
|
||||
public parse = async (terminalID: number) => {
|
||||
// Private functions
|
||||
/**
|
||||
* @param line Line segments
|
||||
*/
|
||||
const updateLastCourse = (line: LineSegment[]) => {
|
||||
lastCourse = geolib.getGreatCircleBearing(
|
||||
{
|
||||
latitude: line.at(-2)![1],
|
||||
longitude: line.at(-2)![0],
|
||||
},
|
||||
{
|
||||
latitude: line.at(-1)![1],
|
||||
longitude: line.at(-1)![0],
|
||||
}
|
||||
);
|
||||
};
|
||||
public get terminals() {
|
||||
return this._terminals;
|
||||
}
|
||||
public get waypoints() {
|
||||
return this._waypoints;
|
||||
}
|
||||
public get runways() {
|
||||
return this._runways;
|
||||
}
|
||||
|
||||
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
|
||||
const runway = this.runways.find(({ ID }) => ID === terminal.RwyID);
|
||||
if (!runway) throw new Error("Procedure links to non existent Runway");
|
||||
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 procedure = (await (
|
||||
const procedures = (await (
|
||||
await fetch(`NavData/TermID_${terminalID}.json`)
|
||||
).json()) as TerminalEntry[];
|
||||
// Split into transitions
|
||||
const transitions = new Set(procedures.map((proc) => proc.Transition));
|
||||
|
||||
// Output variables
|
||||
const navFixes: NavFix[] = [];
|
||||
const lineSegments: { line: LineSegment[]; [x: string]: unknown }[] = [];
|
||||
|
||||
// Initials
|
||||
navFixes.push({
|
||||
latitude: runway.Latitude,
|
||||
longitude: runway.Longitude,
|
||||
altitude: runway.Elevation,
|
||||
speed: 0,
|
||||
name: runway.Ident,
|
||||
});
|
||||
let lastCourse = runway.TrueHeading;
|
||||
const output: object[] = [];
|
||||
|
||||
// Main
|
||||
for (let index = 0; index < procedure.length; index++) {
|
||||
const leg = procedure[index];
|
||||
const previousFix = navFixes.at(-1)!;
|
||||
const waypoint = this.waypoints.filter(({ ID }) => ID === leg.WptID)[0];
|
||||
transitions.forEach((transition) => {
|
||||
// Private functions
|
||||
/**
|
||||
* @param line Line segments
|
||||
*/
|
||||
const updateLastCourse = (line: LineSegment[]) => {
|
||||
lastCourse = geolib.getGreatCircleBearing(
|
||||
{
|
||||
latitude: line.at(-2)![1],
|
||||
longitude: line.at(-2)![0],
|
||||
},
|
||||
{
|
||||
latitude: line.at(-1)![1],
|
||||
longitude: line.at(-1)![0],
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
switch (leg.TrackCode) {
|
||||
case "AF": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsAF(
|
||||
leg as AFTerminalEntry,
|
||||
previousFix,
|
||||
waypoint
|
||||
);
|
||||
if (fixToAdd) navFixes.push(fixToAdd);
|
||||
if (lineToAdd) {
|
||||
lineSegments.push({ line: lineToAdd });
|
||||
updateLastCourse(lineToAdd);
|
||||
}
|
||||
break;
|
||||
/**
|
||||
* @param fix New fix
|
||||
* @param line New line
|
||||
* @param options Options for line rendering
|
||||
*/
|
||||
const update = (
|
||||
fix?: NavFix,
|
||||
line?: LineSegment[],
|
||||
options?: Record<string, unknown>
|
||||
) => {
|
||||
if (fix) navFixes.push(fix);
|
||||
if (line) {
|
||||
lineSegments.push({ line, ...options });
|
||||
updateLastCourse(line);
|
||||
}
|
||||
case "CA":
|
||||
case "CD":
|
||||
console.error("Unknown TrackCode", leg.TrackCode);
|
||||
break;
|
||||
case "CF": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsCF(
|
||||
leg as CFTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse,
|
||||
waypoint
|
||||
);
|
||||
if (fixToAdd) navFixes.push(fixToAdd);
|
||||
if (lineToAdd) {
|
||||
lineSegments.push({ line: lineToAdd });
|
||||
updateLastCourse(lineToAdd);
|
||||
};
|
||||
|
||||
// Output variables
|
||||
const navFixes: NavFix[] = [];
|
||||
const lineSegments: { line: LineSegment[]; [x: string]: unknown }[] = [];
|
||||
|
||||
// Initials
|
||||
navFixes.push({
|
||||
latitude: runway.Latitude,
|
||||
longitude: runway.Longitude,
|
||||
altitude: runway.Elevation,
|
||||
speed: 0,
|
||||
name: runway.Ident,
|
||||
});
|
||||
let lastCourse = runway.TrueHeading;
|
||||
|
||||
const procedure = procedures.filter(
|
||||
(proc) => proc.Transition === transition
|
||||
);
|
||||
for (let index = 0; index < procedure.length; index++) {
|
||||
const leg = procedure[index];
|
||||
const previousFix = navFixes.at(-1)!;
|
||||
const waypoint = this.waypoints.filter(({ ID }) => ID === leg.WptID)[0];
|
||||
|
||||
switch (leg.TrackCode) {
|
||||
case "AF": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsAF(
|
||||
leg as AFTerminalEntry,
|
||||
previousFix,
|
||||
waypoint
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "CI": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsCI(
|
||||
leg as CITerminalEntry,
|
||||
procedure[index + 1],
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
if (fixToAdd) navFixes.push(fixToAdd);
|
||||
if (lineToAdd) {
|
||||
lineSegments.push({ line: lineToAdd });
|
||||
updateLastCourse(lineToAdd);
|
||||
case "CA": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsCA(
|
||||
leg as CATerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "CR": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsCR(
|
||||
leg as CRTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
if (fixToAdd) navFixes.push(fixToAdd);
|
||||
if (lineToAdd) {
|
||||
lineSegments.push({ line: lineToAdd });
|
||||
updateLastCourse(lineToAdd);
|
||||
case "CD": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsCD(
|
||||
leg as CDTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "DF":
|
||||
case "FA":
|
||||
case "FC":
|
||||
case "FD":
|
||||
console.error("Unknown TrackCode", leg.TrackCode);
|
||||
break;
|
||||
case "FM": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsFM(
|
||||
leg as FMTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
if (fixToAdd) navFixes.push(fixToAdd);
|
||||
if (lineToAdd) {
|
||||
lineSegments.push({ line: lineToAdd, isManual: true });
|
||||
updateLastCourse(lineToAdd);
|
||||
case "CF": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsCF(
|
||||
leg as CFTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse,
|
||||
waypoint
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "HA":
|
||||
case "HF":
|
||||
case "HM":
|
||||
case "IF":
|
||||
case "PI":
|
||||
console.error("Unknown TrackCode", leg.TrackCode);
|
||||
break;
|
||||
case "RF": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsRF(
|
||||
leg as RFTerminalEntry,
|
||||
procedure[index + 1],
|
||||
previousFix,
|
||||
lastCourse,
|
||||
waypoint
|
||||
);
|
||||
if (fixToAdd) navFixes.push(fixToAdd);
|
||||
if (lineToAdd) {
|
||||
lineSegments.push({ line: lineToAdd });
|
||||
updateLastCourse(lineToAdd);
|
||||
case "CI": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsCI(
|
||||
leg as CITerminalEntry,
|
||||
procedure[index + 1],
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "TF": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsTF(
|
||||
leg as TFTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse,
|
||||
waypoint
|
||||
);
|
||||
if (fixToAdd) navFixes.push(fixToAdd);
|
||||
if (lineToAdd) {
|
||||
lineSegments.push({ line: lineToAdd });
|
||||
updateLastCourse(lineToAdd);
|
||||
case "CR": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsCR(
|
||||
leg as CRTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "VA": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsVA(
|
||||
leg as VATerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
if (fixToAdd) navFixes.push(fixToAdd);
|
||||
if (lineToAdd) {
|
||||
lineSegments.push({ line: lineToAdd });
|
||||
updateLastCourse(lineToAdd);
|
||||
case "DF": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsDF(
|
||||
leg as DFTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse,
|
||||
waypoint
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "VD": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsVD(
|
||||
leg as VDTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
if (fixToAdd) navFixes.push(fixToAdd);
|
||||
if (lineToAdd) {
|
||||
lineSegments.push({ line: lineToAdd });
|
||||
updateLastCourse(lineToAdd);
|
||||
case "FA": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsFA(
|
||||
leg as FATerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "VI": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsVI(
|
||||
leg as VITerminalEntry,
|
||||
procedure[index + 1],
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
if (fixToAdd) navFixes.push(fixToAdd);
|
||||
if (lineToAdd) {
|
||||
lineSegments.push({ line: lineToAdd });
|
||||
updateLastCourse(lineToAdd);
|
||||
case "FC": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsFC(
|
||||
leg as FCTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case "VM": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsVM(
|
||||
leg as VMTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
if (fixToAdd) navFixes.push(fixToAdd);
|
||||
if (lineToAdd) {
|
||||
lineSegments.push({ line: lineToAdd, isManual: true });
|
||||
updateLastCourse(lineToAdd);
|
||||
case "FD": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsFD(
|
||||
leg as FDTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case "FM": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsFM(
|
||||
leg as FMTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd, { isManual: true });
|
||||
break;
|
||||
}
|
||||
case "HA":
|
||||
case "HF":
|
||||
case "HM":
|
||||
console.error("Unknown TrackCode", leg.TrackCode);
|
||||
break;
|
||||
case "IF": {
|
||||
const fixToAdd = TerminatorsIF(leg as RFTerminalEntry, waypoint);
|
||||
navFixes.length = 0;
|
||||
navFixes.push(fixToAdd);
|
||||
break;
|
||||
}
|
||||
case "PI":
|
||||
console.error("Unknown TrackCode", leg.TrackCode);
|
||||
break;
|
||||
case "RF": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsRF(
|
||||
leg as RFTerminalEntry,
|
||||
procedure[index + 1],
|
||||
previousFix,
|
||||
lastCourse,
|
||||
waypoint
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
case "TF": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsTF(
|
||||
leg as TFTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse,
|
||||
waypoint
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
case "VA": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsVA(
|
||||
leg as VATerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
case "VD": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsVD(
|
||||
leg as VDTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
case "VI": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsVI(
|
||||
leg as VITerminalEntry,
|
||||
procedure[index + 1],
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
case "VM": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsVM(
|
||||
leg as VMTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd, { isManual: true });
|
||||
break;
|
||||
}
|
||||
case "VR": {
|
||||
const [fixToAdd, lineToAdd] = TerminatorsVR(
|
||||
leg as VRTerminalEntry,
|
||||
previousFix,
|
||||
lastCourse
|
||||
);
|
||||
update(fixToAdd, lineToAdd);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
console.error("Unknown TrackCode", leg.TrackCode);
|
||||
break;
|
||||
}
|
||||
case "VR":
|
||||
default:
|
||||
console.error("Unknown TrackCode", leg.TrackCode);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return geojson.parse([...navFixes, ...lineSegments], {
|
||||
LineString: "line",
|
||||
Point: ["latitude", "longitude"],
|
||||
output.push(
|
||||
geojson.parse([...navFixes, ...lineSegments], {
|
||||
LineString: "line",
|
||||
Point: ["latitude", "longitude"],
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
return output;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@ -1,23 +1,31 @@
|
||||
import * as geolib from "geolib";
|
||||
import Parser from "../parser.ts";
|
||||
import { computeTurnRate } from "../utils/computeTurnRate.ts";
|
||||
|
||||
/**
|
||||
* @param crsIntoEndpoint Course into arc endpoint
|
||||
* @param crsFromOrigin Course from arc origin point
|
||||
* @param start Arc origin point
|
||||
* @param speed Speed within arc
|
||||
* @param turnDir Turn direction
|
||||
* @param force360 If true, force a 360° turn
|
||||
* @returns Line segments
|
||||
*/
|
||||
export const generatePerformanceArc = (
|
||||
crsIntoEndpoint: number,
|
||||
crsFromOrigin: number,
|
||||
start: NavFix,
|
||||
turnDir?: TurnDirection
|
||||
speed: number,
|
||||
turnDir?: TurnDirection,
|
||||
force360?: boolean
|
||||
) => {
|
||||
const turnRate = computeTurnRate(speed, Parser.AC_BANK);
|
||||
const originalCrsFromOrigin = crsFromOrigin;
|
||||
|
||||
const line: LineSegment[] = [[start.longitude, start.latitude]];
|
||||
|
||||
// Check if there even is an arc
|
||||
if (crsIntoEndpoint !== crsFromOrigin) {
|
||||
if (force360 || !crsFromOrigin.equal(crsIntoEndpoint)) {
|
||||
// Turn Dir
|
||||
if (!turnDir || turnDir === "E") {
|
||||
let prov = crsFromOrigin - crsIntoEndpoint;
|
||||
@ -26,15 +34,18 @@ export const generatePerformanceArc = (
|
||||
}
|
||||
|
||||
// Generate arc
|
||||
while (crsFromOrigin !== crsIntoEndpoint) {
|
||||
while (!crsFromOrigin.equal(crsIntoEndpoint)) {
|
||||
let time = 0;
|
||||
if (turnDir === "R") {
|
||||
const delta = (crsIntoEndpoint - crsFromOrigin).normaliseDegrees();
|
||||
crsFromOrigin += delta < 1 ? delta : 1;
|
||||
crsFromOrigin = crsFromOrigin.normaliseDegrees();
|
||||
const increment = delta < 1 ? delta : 1;
|
||||
crsFromOrigin = (crsFromOrigin + increment).normaliseDegrees();
|
||||
time = increment / turnRate;
|
||||
} else {
|
||||
const delta = (crsFromOrigin - crsIntoEndpoint).normaliseDegrees();
|
||||
crsFromOrigin -= delta < 1 ? delta : 1;
|
||||
crsFromOrigin = crsFromOrigin.normaliseDegrees();
|
||||
const increment = delta < 1 ? delta : 1;
|
||||
crsFromOrigin = (crsFromOrigin - increment).normaliseDegrees();
|
||||
time = increment / turnRate;
|
||||
}
|
||||
|
||||
const arcFix = geolib.computeDestinationPoint(
|
||||
@ -42,12 +53,45 @@ export const generatePerformanceArc = (
|
||||
latitude: line.at(-1)![1],
|
||||
longitude: line.at(-1)![0],
|
||||
},
|
||||
(Parser.AC_SPEED / 3600).toMetre(),
|
||||
((speed / 3600) * time).toMetre(),
|
||||
crsFromOrigin
|
||||
);
|
||||
|
||||
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;
|
||||
|
||||
@ -19,7 +19,7 @@ export const generateTangentArc = (
|
||||
const line: LineSegment[] = [[start.longitude, start.latitude]];
|
||||
|
||||
// Check if there even is an arc
|
||||
if (crsFromOrigin !== crsIntoEndpoint) {
|
||||
if (!crsFromOrigin.equal(crsIntoEndpoint)) {
|
||||
// Course to the end of the arc
|
||||
let crsFromStartToEnd;
|
||||
if (!turnDir || turnDir === "E") {
|
||||
@ -75,7 +75,7 @@ export const generateTangentArc = (
|
||||
crsOrthogonalOnOrigin < 1 ? crsOrthogonalOnOrigin : 1;
|
||||
}
|
||||
|
||||
while (crsOrthogonalOnOrigin !== crsOrthogonalOnEndpoint) {
|
||||
while (!crsOrthogonalOnOrigin.equal(crsOrthogonalOnEndpoint)) {
|
||||
if (turnDir === "R") {
|
||||
const delta = (
|
||||
crsOrthogonalOnEndpoint - crsOrthogonalOnOrigin
|
||||
@ -89,7 +89,6 @@ export const generateTangentArc = (
|
||||
crsOrthogonalOnOrigin -= delta < 1 ? delta : 1;
|
||||
crsOrthogonalOnOrigin = crsOrthogonalOnOrigin.normaliseDegrees();
|
||||
}
|
||||
if (crsOrthogonalOnOrigin === crsOrthogonalOnEndpoint) break;
|
||||
|
||||
const arcFix = geolib.computeDestinationPoint(
|
||||
arcCenter,
|
||||
|
||||
@ -8,6 +8,7 @@ import { generatePerformanceArc } from "./generatePerformanceArc.ts";
|
||||
* @param crsFromOrigin Course from arc origin point
|
||||
* @param start Waypoint where leg starts
|
||||
* @param end Waypoint where leg ends
|
||||
* @param speed Speed for performance arc
|
||||
* @param turnDir Turn direction
|
||||
* @returns Line segments from `start` to `end`
|
||||
*/
|
||||
@ -17,6 +18,7 @@ export const handleTurnAtFix = (
|
||||
crsFromOrigin: number,
|
||||
start: NavFix,
|
||||
end: NavFix,
|
||||
speed: number,
|
||||
turnDir?: TurnDirection
|
||||
) => {
|
||||
const line: LineSegment[] = [];
|
||||
@ -35,6 +37,7 @@ export const handleTurnAtFix = (
|
||||
crsIntoIntercept,
|
||||
crsFromOrigin,
|
||||
start,
|
||||
speed,
|
||||
turnDir
|
||||
);
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import * as geolib from "geolib";
|
||||
import { generateAFArc } from "../pathGenerators/generateAFArc.ts";
|
||||
import Parser from "../parser.ts";
|
||||
import { computeSpeed } from "../utils/computeSpeed.ts";
|
||||
|
||||
export const TerminatorsAF = (
|
||||
leg: AFTerminalEntry,
|
||||
@ -13,13 +13,7 @@ export const TerminatorsAF = (
|
||||
name: waypoint?.Ident ?? undefined,
|
||||
isFlyOver: leg.IsFlyOver,
|
||||
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
|
||||
speed: leg.SpeedLimit
|
||||
? leg.SpeedLimit > Parser.AC_SPEED
|
||||
? Parser.AC_SPEED
|
||||
: leg.SpeedLimit
|
||||
: previousFix.speed
|
||||
? previousFix.speed
|
||||
: Parser.AC_SPEED,
|
||||
speed: computeSpeed(leg, previousFix),
|
||||
speedConstraint: leg.SpeedLimit,
|
||||
altitudeConstraint: leg.Alt,
|
||||
};
|
||||
@ -34,6 +28,7 @@ export const TerminatorsAF = (
|
||||
longitude: leg.WptLon,
|
||||
}
|
||||
);
|
||||
|
||||
const line = generateAFArc(
|
||||
arcEndCrs,
|
||||
leg.Course.toTrue({ latitude: leg.NavLat, longitude: leg.NavLon }),
|
||||
|
||||
60
browser/src/parser/terminators/CA.ts
Normal file
60
browser/src/parser/terminators/CA.ts
Normal file
@ -0,0 +1,60 @@
|
||||
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];
|
||||
};
|
||||
70
browser/src/parser/terminators/CD.ts
Normal file
70
browser/src/parser/terminators/CD.ts
Normal file
@ -0,0 +1,70 @@
|
||||
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];
|
||||
};
|
||||
@ -1,5 +1,5 @@
|
||||
import Parser from "../parser.ts";
|
||||
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
|
||||
import { computeSpeed } from "../utils/computeSpeed.ts";
|
||||
|
||||
export const TerminatorsCF = (
|
||||
leg: CFTerminalEntry,
|
||||
@ -7,19 +7,15 @@ export const TerminatorsCF = (
|
||||
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: leg.SpeedLimit
|
||||
? leg.SpeedLimit > Parser.AC_SPEED
|
||||
? Parser.AC_SPEED
|
||||
: leg.SpeedLimit
|
||||
: previousFix.speed
|
||||
? previousFix.speed
|
||||
: Parser.AC_SPEED,
|
||||
speed: speed,
|
||||
speedConstraint: leg.SpeedLimit,
|
||||
altitudeConstraint: leg.Alt,
|
||||
};
|
||||
@ -30,6 +26,7 @@ export const TerminatorsCF = (
|
||||
lastCourse,
|
||||
previousFix,
|
||||
targetFix,
|
||||
speed,
|
||||
leg.TurnDir
|
||||
);
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import Parser from "../parser.ts";
|
||||
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
|
||||
import { computeIntersection } from "../utils/computeIntersection.ts";
|
||||
import { computeSpeed } from "../utils/computeSpeed.ts";
|
||||
import { getCourseAndFixForIntercepts } from "../utils/getCourseAndFixForIntercepts.ts";
|
||||
|
||||
export const TerminatorsCI = (
|
||||
@ -10,6 +10,7 @@ export const TerminatorsCI = (
|
||||
lastCourse: number
|
||||
): [NavFix?, LineSegment[]?] => {
|
||||
const [crs, nextFix] = getCourseAndFixForIntercepts(nextLeg, previousFix);
|
||||
const speed = computeSpeed(leg, previousFix);
|
||||
|
||||
// Compute INTC
|
||||
const interceptFix: NavFix = {
|
||||
@ -21,13 +22,7 @@ export const TerminatorsCI = (
|
||||
)!,
|
||||
isFlyOver: leg.IsFlyOver,
|
||||
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
|
||||
speed: leg.SpeedLimit
|
||||
? leg.SpeedLimit > Parser.AC_SPEED
|
||||
? Parser.AC_SPEED
|
||||
: leg.SpeedLimit
|
||||
: previousFix.speed
|
||||
? previousFix.speed
|
||||
: Parser.AC_SPEED,
|
||||
speed: speed,
|
||||
speedConstraint: leg.SpeedLimit,
|
||||
altitudeConstraint: leg.Alt,
|
||||
};
|
||||
@ -38,6 +33,7 @@ export const TerminatorsCI = (
|
||||
lastCourse,
|
||||
previousFix,
|
||||
interceptFix,
|
||||
speed,
|
||||
leg.TurnDir
|
||||
);
|
||||
|
||||
|
||||
@ -1,42 +1,56 @@
|
||||
import * as geolib from "geolib";
|
||||
import { computeIntersection } from "../utils/computeIntersection.ts";
|
||||
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
|
||||
import Parser from "../parser.ts";
|
||||
import { computeSpeed } from "../utils/computeSpeed.ts";
|
||||
import { generatePerformanceArc } from "../pathGenerators/generatePerformanceArc.ts";
|
||||
|
||||
export const TerminatorsCR = (
|
||||
leg: CRTerminalEntry,
|
||||
previousFix: NavFix,
|
||||
lastCourse: number
|
||||
): [NavFix?, LineSegment[]?] => {
|
||||
const crsIntoEndpoint = leg.Course.toTrue(previousFix);
|
||||
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(
|
||||
previousFix,
|
||||
crsIntoEndpoint,
|
||||
{ latitude: leg.NavLat, longitude: leg.NavLon },
|
||||
leg.NavBear.toTrue({ latitude: leg.NavLat, longitude: leg.NavLon })
|
||||
)!,
|
||||
...computeIntersection(arcEnd, crsFromEndpoint, navaid, crsIntoEndpoint)!,
|
||||
isFlyOver: leg.IsFlyOver,
|
||||
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
|
||||
speed: leg.SpeedLimit
|
||||
? leg.SpeedLimit > Parser.AC_SPEED
|
||||
? Parser.AC_SPEED
|
||||
: leg.SpeedLimit
|
||||
: previousFix.speed
|
||||
? previousFix.speed
|
||||
: Parser.AC_SPEED,
|
||||
speed: speed,
|
||||
speedConstraint: leg.SpeedLimit,
|
||||
altitudeConstraint: leg.Alt,
|
||||
};
|
||||
|
||||
const line = handleTurnAtFix(
|
||||
crsIntoEndpoint,
|
||||
leg.Course.toTrue(previousFix),
|
||||
lastCourse,
|
||||
previousFix,
|
||||
interceptFix,
|
||||
leg.TurnDir
|
||||
);
|
||||
line.push([interceptFix.longitude, interceptFix.latitude]);
|
||||
|
||||
return [interceptFix, line];
|
||||
};
|
||||
|
||||
48
browser/src/parser/terminators/DF.ts
Normal file
48
browser/src/parser/terminators/DF.ts
Normal file
@ -0,0 +1,48 @@
|
||||
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];
|
||||
};
|
||||
64
browser/src/parser/terminators/FA.ts
Normal file
64
browser/src/parser/terminators/FA.ts
Normal file
@ -0,0 +1,64 @@
|
||||
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];
|
||||
};
|
||||
98
browser/src/parser/terminators/FC.ts
Normal file
98
browser/src/parser/terminators/FC.ts
Normal file
@ -0,0 +1,98 @@
|
||||
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];
|
||||
};
|
||||
74
browser/src/parser/terminators/FD.ts
Normal file
74
browser/src/parser/terminators/FD.ts
Normal file
@ -0,0 +1,74 @@
|
||||
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];
|
||||
};
|
||||
@ -1,11 +1,14 @@
|
||||
import * as geolib from "geolib";
|
||||
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
|
||||
import { computeSpeed } from "../utils/computeSpeed.ts";
|
||||
|
||||
export const TerminatorsFM = (
|
||||
leg: FMTerminalEntry,
|
||||
previousFix: NavFix,
|
||||
lastCourse: number
|
||||
): [NavFix?, LineSegment[]?] => {
|
||||
const speed = computeSpeed(leg, previousFix);
|
||||
|
||||
const endpoint = geolib.computeDestinationPoint(
|
||||
previousFix,
|
||||
(10).toMetre(),
|
||||
@ -18,6 +21,7 @@ export const TerminatorsFM = (
|
||||
lastCourse,
|
||||
previousFix,
|
||||
endpoint,
|
||||
speed,
|
||||
leg.TurnDir
|
||||
);
|
||||
|
||||
|
||||
19
browser/src/parser/terminators/IF.ts
Normal file
19
browser/src/parser/terminators/IF.ts
Normal file
@ -0,0 +1,19 @@
|
||||
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;
|
||||
};
|
||||
@ -1,6 +1,6 @@
|
||||
import Parser from "../parser.ts";
|
||||
import { getCourseAndFixForIntercepts } from "../utils/getCourseAndFixForIntercepts.ts";
|
||||
import { generateRFArc } from "../pathGenerators/generateRFArc.ts";
|
||||
import { computeSpeed } from "../utils/computeSpeed.ts";
|
||||
|
||||
export const TerminatorsRF = (
|
||||
leg: RFTerminalEntry,
|
||||
@ -15,13 +15,7 @@ export const TerminatorsRF = (
|
||||
name: waypoint?.Ident ?? undefined,
|
||||
isFlyOver: leg.IsFlyOver,
|
||||
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
|
||||
speed: leg.SpeedLimit
|
||||
? leg.SpeedLimit > Parser.AC_SPEED
|
||||
? Parser.AC_SPEED
|
||||
: leg.SpeedLimit
|
||||
: previousFix.speed
|
||||
? previousFix.speed
|
||||
: Parser.AC_SPEED,
|
||||
speed: computeSpeed(leg, previousFix),
|
||||
speedConstraint: leg.SpeedLimit,
|
||||
altitudeConstraint: leg.Alt,
|
||||
};
|
||||
@ -35,6 +29,7 @@ export const TerminatorsRF = (
|
||||
{ latitude: leg.CenterLat, longitude: leg.CenterLon },
|
||||
leg.TurnDir
|
||||
);
|
||||
|
||||
line.push([targetFix.longitude, targetFix.latitude]);
|
||||
|
||||
return [targetFix, line];
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
import * as geolib from "geolib";
|
||||
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
|
||||
import { computeSpeed } from "../utils/computeSpeed.ts";
|
||||
import Parser from "../parser.ts";
|
||||
|
||||
export const TerminatorsTF = (
|
||||
@ -14,26 +14,68 @@ export const TerminatorsTF = (
|
||||
name: waypoint?.Ident ?? undefined,
|
||||
isFlyOver: leg.IsFlyOver,
|
||||
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
|
||||
speed: leg.SpeedLimit
|
||||
? leg.SpeedLimit > Parser.AC_SPEED
|
||||
? Parser.AC_SPEED
|
||||
: leg.SpeedLimit
|
||||
: previousFix.speed
|
||||
? previousFix.speed
|
||||
: Parser.AC_SPEED,
|
||||
speed: computeSpeed(leg, previousFix),
|
||||
speedConstraint: leg.SpeedLimit,
|
||||
altitudeConstraint: leg.Alt,
|
||||
};
|
||||
|
||||
const crs = geolib.getGreatCircleBearing(previousFix, targetFix);
|
||||
const line = handleTurnAtFix(
|
||||
crs,
|
||||
crs,
|
||||
lastCourse,
|
||||
const line: LineSegment[] = [[previousFix.longitude, previousFix.latitude]];
|
||||
|
||||
const trackIntoEndpoint = geolib.getGreatCircleBearing(
|
||||
previousFix,
|
||||
targetFix,
|
||||
leg.TurnDir
|
||||
targetFix
|
||||
);
|
||||
|
||||
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];
|
||||
};
|
||||
|
||||
@ -1,6 +1,7 @@
|
||||
import * as geolib from "geolib";
|
||||
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.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
|
||||
export const TerminatorsVA = (
|
||||
@ -8,38 +9,53 @@ export const TerminatorsVA = (
|
||||
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(
|
||||
previousFix,
|
||||
arcEnd,
|
||||
(
|
||||
((leg.Alt.parseAltitude() - (previousFix.altitude ?? 0)) /
|
||||
Parser.AC_VS) *
|
||||
(Parser.AC_SPEED / 60)
|
||||
((previousFix.speed ? previousFix.speed : Parser.AC_SPEED) / 60)
|
||||
).toMetre(),
|
||||
leg.Course.toTrue(previousFix)
|
||||
crsIntoEndpoint
|
||||
),
|
||||
name: leg.Alt,
|
||||
isFlyOver: true,
|
||||
altitude: leg.Alt.parseAltitude(),
|
||||
speed: leg.SpeedLimit
|
||||
? leg.SpeedLimit > Parser.AC_SPEED
|
||||
? Parser.AC_SPEED
|
||||
: leg.SpeedLimit
|
||||
: previousFix.speed
|
||||
? previousFix.speed
|
||||
: Parser.AC_SPEED,
|
||||
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
|
||||
speed: speed,
|
||||
speedConstraint: leg.SpeedLimit,
|
||||
altitudeConstraint: leg.Alt,
|
||||
};
|
||||
|
||||
const line = handleTurnAtFix(
|
||||
leg.Course.toTrue(previousFix),
|
||||
leg.Course.toTrue(previousFix),
|
||||
lastCourse,
|
||||
previousFix,
|
||||
targetFix,
|
||||
leg.TurnDir
|
||||
);
|
||||
line.push([targetFix.longitude, targetFix.latitude]);
|
||||
|
||||
return [targetFix, line];
|
||||
};
|
||||
|
||||
@ -1,41 +1,71 @@
|
||||
import * as geolib from "geolib";
|
||||
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.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: Distance not adjusted for altitude in this demo
|
||||
export const TerminatorsVD = (
|
||||
leg: VDTerminalEntry,
|
||||
previousFix: NavFix,
|
||||
lastCourse: number
|
||||
): [NavFix?, LineSegment[]?] => {
|
||||
const targetFix: NavFix = {
|
||||
...geolib.computeDestinationPoint(
|
||||
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,
|
||||
leg.Distance.toMetre(),
|
||||
leg.Course.toTrue(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: leg.SpeedLimit
|
||||
? leg.SpeedLimit > Parser.AC_SPEED
|
||||
? Parser.AC_SPEED
|
||||
: leg.SpeedLimit
|
||||
: previousFix.speed
|
||||
? previousFix.speed
|
||||
: Parser.AC_SPEED,
|
||||
speed: speed,
|
||||
speedConstraint: leg.SpeedLimit,
|
||||
altitudeConstraint: leg.Alt,
|
||||
};
|
||||
|
||||
const line = handleTurnAtFix(
|
||||
leg.Course.toTrue(previousFix),
|
||||
leg.Course.toTrue(previousFix),
|
||||
lastCourse,
|
||||
previousFix,
|
||||
targetFix,
|
||||
leg.TurnDir
|
||||
);
|
||||
line.push([targetFix.longitude, targetFix.latitude]);
|
||||
|
||||
return [targetFix, line];
|
||||
};
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
import Parser from "../parser.ts";
|
||||
import { handleTurnAtFix } from "../pathGenerators/handleTurnAtFix.ts";
|
||||
import { computeIntersection } from "../utils/computeIntersection.ts";
|
||||
import { computeSpeed } from "../utils/computeSpeed.ts";
|
||||
import { getCourseAndFixForIntercepts } from "../utils/getCourseAndFixForIntercepts.ts";
|
||||
|
||||
// NOTE: No wind adjustments to be made, no clue how *that* would draw
|
||||
@ -11,6 +11,7 @@ export const TerminatorsVI = (
|
||||
lastCourse: number
|
||||
): [NavFix?, LineSegment[]?] => {
|
||||
const [crs, nextFix] = getCourseAndFixForIntercepts(nextLeg, previousFix);
|
||||
const speed = computeSpeed(leg, previousFix);
|
||||
|
||||
// Compute INTC
|
||||
const interceptFix: NavFix = {
|
||||
@ -22,13 +23,7 @@ export const TerminatorsVI = (
|
||||
)!,
|
||||
isFlyOver: leg.IsFlyOver,
|
||||
altitude: leg.Alt ? leg.Alt.parseAltitude() : previousFix.altitude,
|
||||
speed: leg.SpeedLimit
|
||||
? leg.SpeedLimit > Parser.AC_SPEED
|
||||
? Parser.AC_SPEED
|
||||
: leg.SpeedLimit
|
||||
: previousFix.speed
|
||||
? previousFix.speed
|
||||
: Parser.AC_SPEED,
|
||||
speed: speed,
|
||||
speedConstraint: leg.SpeedLimit,
|
||||
altitudeConstraint: leg.Alt,
|
||||
};
|
||||
@ -39,6 +34,7 @@ export const TerminatorsVI = (
|
||||
lastCourse,
|
||||
previousFix,
|
||||
interceptFix,
|
||||
speed,
|
||||
leg.TurnDir
|
||||
);
|
||||
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
import * as geolib from "geolib";
|
||||
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
|
||||
export const TerminatorsVM = (
|
||||
@ -7,6 +8,8 @@ export const TerminatorsVM = (
|
||||
previousFix: NavFix,
|
||||
lastCourse: number
|
||||
): [NavFix?, LineSegment[]?] => {
|
||||
const speed = computeSpeed(leg, previousFix);
|
||||
|
||||
const endpoint = geolib.computeDestinationPoint(
|
||||
previousFix,
|
||||
(10).toMetre(),
|
||||
@ -19,6 +22,7 @@ export const TerminatorsVM = (
|
||||
lastCourse,
|
||||
previousFix,
|
||||
endpoint,
|
||||
speed,
|
||||
leg.TurnDir
|
||||
);
|
||||
|
||||
|
||||
57
browser/src/parser/terminators/VR.ts
Normal file
57
browser/src/parser/terminators/VR.ts
Normal file
@ -0,0 +1,57 @@
|
||||
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];
|
||||
};
|
||||
12
browser/src/parser/utils/computeSpeed.ts
Normal file
12
browser/src/parser/utils/computeSpeed.ts
Normal file
@ -0,0 +1,12 @@
|
||||
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;
|
||||
};
|
||||
3
browser/src/parser/utils/computeTurnRate.ts
Normal file
3
browser/src/parser/utils/computeTurnRate.ts
Normal file
@ -0,0 +1,3 @@
|
||||
export const computeTurnRate = (speed: number, bank: number) => {
|
||||
return (1091 * Math.tan(bank.toRadians())) / speed;
|
||||
};
|
||||
@ -25,7 +25,22 @@ Number.prototype.toTrue = function (fix) {
|
||||
Number.prototype.toMetre = function () {
|
||||
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 () {
|
||||
return Number.parseInt(this.substring(0, 5));
|
||||
switch (this.length) {
|
||||
case 5:
|
||||
return Number.parseInt(this as string);
|
||||
case 6:
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
4
browser/src/types/extensions.d.ts
vendored
4
browser/src/types/extensions.d.ts
vendored
@ -25,6 +25,10 @@ export declare global {
|
||||
* @returns Value converted from nmi to metres
|
||||
*/
|
||||
toMetre: () => number;
|
||||
/**
|
||||
* @returns True if delta is less than 0.1
|
||||
*/
|
||||
equal: (other: number) => boolean;
|
||||
}
|
||||
|
||||
interface String {
|
||||
|
||||
4
browser/src/types/terminators/CA.d.ts
vendored
Normal file
4
browser/src/types/terminators/CA.d.ts
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
export declare global {
|
||||
type CATerminalEntry = Required<Pick<TerminalEntry, "Course" | "Alt">> &
|
||||
TerminalEntry;
|
||||
}
|
||||
6
browser/src/types/terminators/CD.d.ts
vendored
Normal file
6
browser/src/types/terminators/CD.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export declare global {
|
||||
type CDTerminalEntry = Required<
|
||||
Pick<TerminalEntry, "NavID" | "NavLat" | "NavLon" | "Course" | "Distance">
|
||||
> &
|
||||
TerminalEntry;
|
||||
}
|
||||
6
browser/src/types/terminators/DF.d.ts
vendored
Normal file
6
browser/src/types/terminators/DF.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export declare global {
|
||||
type DFTerminalEntry = Required<
|
||||
Pick<TerminalEntry, "WptID" | "WptLat" | "WptLon" | "IsFlyOver">
|
||||
> &
|
||||
TerminalEntry;
|
||||
}
|
||||
18
browser/src/types/terminators/FA.d.ts
vendored
Normal file
18
browser/src/types/terminators/FA.d.ts
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
export declare global {
|
||||
type FATerminalEntry = Required<
|
||||
Pick<
|
||||
TerminalEntry,
|
||||
| "WptID"
|
||||
| "WptLat"
|
||||
| "WptLon"
|
||||
| "NavID"
|
||||
| "NavLat"
|
||||
| "NavLon"
|
||||
| "NavBear"
|
||||
| "NavDist"
|
||||
| "Course"
|
||||
| "Alt"
|
||||
>
|
||||
> &
|
||||
TerminalEntry;
|
||||
}
|
||||
19
browser/src/types/terminators/FC.d.ts
vendored
Normal file
19
browser/src/types/terminators/FC.d.ts
vendored
Normal file
@ -0,0 +1,19 @@
|
||||
export declare global {
|
||||
type FCTerminalEntry = Required<
|
||||
Pick<
|
||||
TerminalEntry,
|
||||
| "WptID"
|
||||
| "WptLat"
|
||||
| "WptLon"
|
||||
| "IsFlyOver"
|
||||
| "NavID"
|
||||
| "NavLat"
|
||||
| "NavLon"
|
||||
| "NavBear"
|
||||
| "NavDist"
|
||||
| "Course"
|
||||
| "Distance"
|
||||
>
|
||||
> &
|
||||
TerminalEntry;
|
||||
}
|
||||
18
browser/src/types/terminators/FD.d.ts
vendored
Normal file
18
browser/src/types/terminators/FD.d.ts
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
export declare global {
|
||||
type FDTerminalEntry = Required<
|
||||
Pick<
|
||||
TerminalEntry,
|
||||
| "WptID"
|
||||
| "WptLat"
|
||||
| "WptLon"
|
||||
| "NavID"
|
||||
| "NavLat"
|
||||
| "NavLon"
|
||||
| "NavBear"
|
||||
| "NavDist"
|
||||
| "Course"
|
||||
| "Distance"
|
||||
>
|
||||
> &
|
||||
TerminalEntry;
|
||||
}
|
||||
6
browser/src/types/terminators/IF.d.ts
vendored
Normal file
6
browser/src/types/terminators/IF.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export declare global {
|
||||
type IFTerminalEntry = Required<
|
||||
Pick<TerminalEntry, "WptID" | "WptLat" | "WptLon">
|
||||
> &
|
||||
TerminalEntry;
|
||||
}
|
||||
6
browser/src/types/terminators/VR.d.ts
vendored
Normal file
6
browser/src/types/terminators/VR.d.ts
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
export declare global {
|
||||
type VRTerminalEntry = Required<
|
||||
Pick<TerminalEntry, "NavID" | "NavLat" | "NavLon" | "NavBear" | "Course">
|
||||
> &
|
||||
TerminalEntry;
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user