diff --git a/src/Airports/groundnetwork.cxx b/src/Airports/groundnetwork.cxx index 0d036937e..a4bed9497 100644 --- a/src/Airports/groundnetwork.cxx +++ b/src/Airports/groundnetwork.cxx @@ -222,6 +222,24 @@ FGTaxiNodeRef FGGroundNetwork::findNearestNode(const SGGeod & aGeod) const return result; } +FGTaxiNodeRef FGGroundNetwork::findNearestNodeOffRunway(const SGGeod& aGeod) const +{ + SGVec3d cartPos = SGVec3d::fromGeod(aGeod); + auto node = std::min_element(m_nodes.begin(), m_nodes.end(), + [cartPos](const FGTaxiNodeRef& a, const FGTaxiNodeRef& b) + { + double aDist = a->getIsOnRunway() ? DBL_MAX : distSqr(cartPos, a->cart()); + double bDist = b->getIsOnRunway() ? DBL_MAX : distSqr(cartPos, b->cart()); + return aDist < bDist; + }); + + if (node == m_nodes.end()) { + return FGTaxiNodeRef(); + } + + return *node; +} + FGTaxiNodeRef FGGroundNetwork::findNearestNodeOnRunway(const SGGeod & aGeod, FGRunway* aRunway) const { SG_UNUSED(aRunway); diff --git a/src/Airports/groundnetwork.hxx b/src/Airports/groundnetwork.hxx index a134f5947..aa65636f4 100644 --- a/src/Airports/groundnetwork.hxx +++ b/src/Airports/groundnetwork.hxx @@ -249,6 +249,8 @@ public: FGTaxiNodeRef findNearestNode(const SGGeod& aGeod) const; FGTaxiNodeRef findNearestNodeOnRunway(const SGGeod& aGeod, FGRunway* aRunway = NULL) const; + FGTaxiNodeRef findNearestNodeOffRunway(const SGGeod& aGeod) const; + FGTaxiSegment *findSegment(unsigned int idx) const; FGTaxiSegment* findOppositeSegment(unsigned int index) const;