Skip to content

Commit

Permalink
[TASK] Limit waypoint distances of VFR flight plans to 300NM
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaseberle committed Jun 14, 2023
1 parent 4e05acc commit 9091711
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 9 deletions.
8 changes: 4 additions & 4 deletions src/Airac.cpp
Expand Up @@ -424,7 +424,7 @@ void Airac::addAirwaySegment(Waypoint* from, Waypoint* to, const QString& name)
*
* Unknown fixes and/or airways will be ignored.
**/
QList<Waypoint*> Airac::resolveFlightplan(QStringList plan, double lat, double lon) {
QList<Waypoint*> Airac::resolveFlightplan(QStringList plan, double lat, double lon, double maxDist) {
QList<Waypoint*> result;
Waypoint* currPoint = 0;
Airway* awy = 0;
Expand All @@ -439,8 +439,8 @@ QList<Waypoint*> Airac::resolveFlightplan(QStringList plan, double lat, double l
wantAirway = false;
// have airway - next should be a waypoint
QString endId = fpTokenToWaypoint(plan.first());
// 5500NM is the longest legitimate route part (PACOT entry-exit) that we can't resolve
Waypoint* wp = waypointNearby(endId, lat, lon, 5500.);

Waypoint* wp = waypointNearby(endId, lat, lon, maxDist);
if (wp != 0) {
if (currPoint != 0) {
auto _expand = awy->expand(currPoint->id, wp->id);
Expand All @@ -462,7 +462,7 @@ QList<Waypoint*> Airac::resolveFlightplan(QStringList plan, double lat, double l
}
}

Waypoint* wp = waypointNearby(id, lat, lon, 5500.);
Waypoint* wp = waypointNearby(id, lat, lon, maxDist);
if (wp != 0) {
result.append(wp);
currPoint = wp;
Expand Down
6 changes: 5 additions & 1 deletion src/Airac.h
Expand Up @@ -10,6 +10,10 @@ class Airac
Q_OBJECT
public:
static Airac* instance(bool createIfNoInstance = true);
// this is the longest legitimate route part that we can't resolve (yet) (PACOT entry-exit)
constexpr static const double ifrMaxWaypointInterval = 5500.;
constexpr static const double nonIfrMaxWaypointInterval = 300.;

virtual ~Airac();

Waypoint* waypoint(const QString &id, const QString &regionCode, const int &type) const;
Expand All @@ -18,7 +22,7 @@ class Airac
Airway* airway(const QString& name);
Airway* airwayNearby(const QString& name, double lat, double lon) const;

QList<Waypoint*> resolveFlightplan(QStringList plan, double lat, double lon);
QList<Waypoint*> resolveFlightplan(QStringList plan, double lat, double lon, double maxDist);

QSet<Waypoint*> allPoints;
QHash<QString, QSet<Waypoint*> > fixes;
Expand Down
8 changes: 6 additions & 2 deletions src/Pilot.cpp
Expand Up @@ -719,13 +719,17 @@ QList<Waypoint*> Pilot::routeWaypoints() {
routeWaypointsPlanDestCache = planDest;
routeWaypointsPlanRouteCache = planRoute;

const double maxDist = planFlighttype == "I"
? Airac::ifrMaxWaypointInterval
: Airac::nonIfrMaxWaypointInterval;

if (depAirport() != 0) {
routeWaypointsCache = Airac::instance()->resolveFlightplan(
waypoints(), depAirport()->lat, depAirport()->lon
waypoints(), depAirport()->lat, depAirport()->lon, maxDist
);
} else if (!qFuzzyIsNull(lat) || !qFuzzyIsNull(lon)) {
routeWaypointsCache = Airac::instance()->resolveFlightplan(
waypoints(), lat, lon
waypoints(), lat, lon, maxDist
);
} else {
routeWaypointsCache = QList<Waypoint*>();
Expand Down
2 changes: 1 addition & 1 deletion src/QuteScoop.cpp
Expand Up @@ -117,7 +117,7 @@ int main(int argc, char* argv[]) {
return 1;
}

const auto waypoints = Airac::instance()->resolveFlightplan(route, dep->lat, dep->lon);
const auto waypoints = Airac::instance()->resolveFlightplan(route, dep->lat, dep->lon, Airac::ifrMaxWaypointInterval);

QTextStream(stdout) << "\n# Waypoints:" << Qt::endl;
foreach (const auto &w, waypoints) {
Expand Down
2 changes: 1 addition & 1 deletion src/Route.cpp
Expand Up @@ -23,7 +23,7 @@ void Route::calculateWaypointsAndDistance() {
}

QStringList list = route.split(' ', Qt::SkipEmptyParts);
waypoints = Airac::instance()->resolveFlightplan(list, depAirport->lat, depAirport->lon);
waypoints = Airac::instance()->resolveFlightplan(list, depAirport->lat, depAirport->lon, Airac::ifrMaxWaypointInterval);

Waypoint* depWp = new Waypoint(depAirport->id, depAirport->lat, depAirport->lon);
waypoints.prepend(depWp);
Expand Down

0 comments on commit 9091711

Please sign in to comment.