From 5fe4486df149ec865395421bd543ae5b813ac98b Mon Sep 17 00:00:00 2001 From: James Turner Date: Tue, 8 Nov 2016 09:27:52 +0100 Subject: [PATCH] =?UTF-8?q?Add=20=E2=80=98nearest=20node=20not=20on=20a=20?= =?UTF-8?q?runway=E2=80=99=20to=20ground-net?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This will be used shortly to find a better (not on the grass, ideally) start position when using multi-player but requesting a runway start. --- src/Airports/groundnetwork.cxx | 18 ++++++++++++++++++ src/Airports/groundnetwork.hxx | 2 ++ 2 files changed, 20 insertions(+) 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;