From 96b9cfabe0e456c0d3ac88a6c9dcb3f25033c165 Mon Sep 17 00:00:00 2001 From: portree_kid Date: Thu, 12 Aug 2021 22:05:05 +0200 Subject: [PATCH] Improved searching of Runway exits --- src/Airports/groundnetwork.cxx | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Airports/groundnetwork.cxx b/src/Airports/groundnetwork.cxx index 62ebe1bf1..b5de65855 100644 --- a/src/Airports/groundnetwork.cxx +++ b/src/Airports/groundnetwork.cxx @@ -285,8 +285,27 @@ FGTaxiNodeRef FGGroundNetwork::findNearestNodeOnRunway(const SGGeod & aGeod, FGR for (it = m_nodes.begin(); it != m_nodes.end(); ++it) { if (!(*it)->getIsOnRunway()) continue; - double localDistanceSqr = distSqr(cartPos, (*it)->cart()); + if (aRunway) { + double headingTowardsExit = SGGeodesy::courseDeg(aGeod, (*it)->geod()); + double diff = fabs(aRunway->headingDeg() - headingTowardsExit); + if (diff > 10) { + // Only ahead + continue; + } + FGTaxiNodeVector exitSegments = findSegmentsFrom((*it)); + // Only ends + if (exitSegments.size() != 1) { + continue; + } + double exitHeading = SGGeodesy::courseDeg((*it)->geod(), + (exitSegments.back())->geod()); + diff = fabs(aRunway->headingDeg() - exitHeading); + if (diff > 10) { + // Only exits going in our direction + continue; + } + } if (localDistanceSqr < d) { d = localDistanceSqr; result = *it;