Maintenance: groundnetwork
parameter 'seg' changed to const*. ++prefix for complex types. SPDX tags.
This commit is contained in:
parent
6b40b1474e
commit
f69d069175
2 changed files with 118 additions and 141 deletions
|
@ -1,56 +1,40 @@
|
|||
// groundnet.cxx - Implimentation of the FlightGear airport ground handling code
|
||||
//
|
||||
// Written by Durk Talsma, started June 2005.
|
||||
//
|
||||
// Copyright (C) 2004 Durk Talsma.
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU General Public License as
|
||||
// published by the Free Software Foundation; either version 2 of the
|
||||
// License, or (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful, but
|
||||
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
//
|
||||
// $Id$
|
||||
/*
|
||||
* SPDX-FileName: groundnet.cxx
|
||||
* SPDX-FileComment: Implementation of the FlightGear airport ground handling code
|
||||
* SPDX-FileCopyrightText: Copyright (C) 2004 Durk Talsma
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "groundnetwork.hxx"
|
||||
|
||||
#include <cmath>
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/scene/util/OsgMath.hxx>
|
||||
#include <simgear/structure/exception.hxx>
|
||||
#include <simgear/timing/timestamp.hxx>
|
||||
#include <simgear/math/SGLineSegment.hxx>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <simgear/math/SGGeometryFwd.hxx>
|
||||
#include <simgear/math/SGIntersect.hxx>
|
||||
#include <simgear/math/SGLineSegment.hxx>
|
||||
#include <simgear/structure/exception.hxx>
|
||||
#include <simgear/timing/timestamp.hxx>
|
||||
|
||||
#include <Airports/airport.hxx>
|
||||
#include <Airports/runways.hxx>
|
||||
|
||||
#include <Scenery/scenery.hxx>
|
||||
|
||||
#include "groundnetwork.hxx"
|
||||
|
||||
using std::string;
|
||||
|
||||
|
||||
/***************************************************************************
|
||||
* FGTaxiSegment
|
||||
**************************************************************************/
|
||||
|
||||
FGTaxiSegment::FGTaxiSegment(FGTaxiNode* aStart, FGTaxiNode* aEnd) :
|
||||
startNode(aStart),
|
||||
FGTaxiSegment::FGTaxiSegment(FGTaxiNode* aStart, FGTaxiNode* aEnd) : startNode(aStart),
|
||||
endNode(aEnd),
|
||||
isActive(0),
|
||||
index(0),
|
||||
|
@ -63,7 +47,7 @@ FGTaxiSegment::FGTaxiSegment(FGTaxiNode* aStart, FGTaxiNode* aEnd) :
|
|||
|
||||
SGGeod FGTaxiSegment::getCenter() const
|
||||
{
|
||||
FGTaxiNode* start(getStart()), *end(getEnd());
|
||||
FGTaxiNode *start(getStart()), *end(getEnd());
|
||||
double heading, length, az2;
|
||||
SGGeodesy::inverse(start->geod(), end->geod(), heading, az2, length);
|
||||
return SGGeodesy::direct(start->geod(), heading, length * 0.5);
|
||||
|
@ -89,7 +73,6 @@ double FGTaxiSegment::getHeading() const
|
|||
return SGGeodesy::courseDeg(getStart()->geod(), getEnd()->geod());
|
||||
}
|
||||
|
||||
|
||||
void FGTaxiSegment::block(int id, time_t blockTime, time_t now)
|
||||
{
|
||||
BlockListIterator i = blockTimes.begin();
|
||||
|
@ -160,12 +143,12 @@ bool FGTaxiRoute::next(FGTaxiNodeRef& node, int* rte)
|
|||
}
|
||||
|
||||
*rte = *(currRoute);
|
||||
currRoute++;
|
||||
++currRoute;
|
||||
} else {
|
||||
// Handle special case for the first node.
|
||||
*rte = -1 * *(currRoute);
|
||||
}
|
||||
currNode++;
|
||||
++currNode;
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -173,8 +156,7 @@ bool FGTaxiRoute::next(FGTaxiNodeRef& node, int* rte)
|
|||
* FGGroundNetwork()
|
||||
**************************************************************************/
|
||||
|
||||
FGGroundNetwork::FGGroundNetwork(FGAirport* airport) :
|
||||
parent(airport)
|
||||
FGGroundNetwork::FGGroundNetwork(FGAirport* airport) : parent(airport)
|
||||
{
|
||||
hasNetwork = false;
|
||||
version = 0;
|
||||
|
@ -183,7 +165,6 @@ FGGroundNetwork::FGGroundNetwork(FGAirport* airport) :
|
|||
|
||||
FGGroundNetwork::~FGGroundNetwork()
|
||||
{
|
||||
|
||||
for (auto seg : segments) {
|
||||
delete seg;
|
||||
}
|
||||
|
@ -221,7 +202,7 @@ void FGGroundNetwork::init()
|
|||
networkInitialized = true;
|
||||
}
|
||||
|
||||
FGTaxiNodeRef FGGroundNetwork::findNearestNode(const SGGeod & aGeod) const
|
||||
FGTaxiNodeRef FGGroundNetwork::findNearestNode(const SGGeod& aGeod) const
|
||||
{
|
||||
double d = DBL_MAX;
|
||||
SGVec3d cartPos = SGVec3d::fromGeod(aGeod);
|
||||
|
@ -247,8 +228,7 @@ FGTaxiNodeRef FGGroundNetwork::findNearestNodeOffRunway(const SGGeod& aGeod, FGR
|
|||
const SGVec3d cartPos = SGVec3d::fromGeod(aGeod);
|
||||
|
||||
std::copy_if(m_nodes.begin(), m_nodes.end(), std::back_inserter(nodes),
|
||||
[runwayLine, cartPos, marginMSqr] (const FGTaxiNodeRef& a)
|
||||
{
|
||||
[runwayLine, cartPos, marginMSqr](const FGTaxiNodeRef& a) {
|
||||
if (a->getIsOnRunway()) return false;
|
||||
|
||||
// exclude parking positions from consideration. This helps to
|
||||
|
@ -261,11 +241,9 @@ FGTaxiNodeRef FGGroundNetwork::findNearestNodeOffRunway(const SGGeod& aGeod, FGR
|
|||
});
|
||||
|
||||
|
||||
|
||||
// find closest of matching nodes
|
||||
auto node = std::min_element(nodes.begin(), nodes.end(),
|
||||
[cartPos](const FGTaxiNodeRef& a, const FGTaxiNodeRef& b)
|
||||
{ return distSqr(cartPos, a->cart()) < distSqr(cartPos, b->cart()); });
|
||||
[cartPos](const FGTaxiNodeRef& a, const FGTaxiNodeRef& b) { return distSqr(cartPos, a->cart()) < distSqr(cartPos, b->cart()); });
|
||||
|
||||
if (node == nodes.end()) {
|
||||
return FGTaxiNodeRef();
|
||||
|
@ -274,7 +252,7 @@ FGTaxiNodeRef FGGroundNetwork::findNearestNodeOffRunway(const SGGeod& aGeod, FGR
|
|||
return *node;
|
||||
}
|
||||
|
||||
FGTaxiNodeRef FGGroundNetwork::findNearestNodeOnRunwayEntry(const SGGeod & aGeod) const
|
||||
FGTaxiNodeRef FGGroundNetwork::findNearestNodeOnRunwayEntry(const SGGeod& aGeod) const
|
||||
{
|
||||
double d = DBL_MAX;
|
||||
SGVec3d cartPos = SGVec3d::fromGeod(aGeod);
|
||||
|
@ -293,14 +271,14 @@ FGTaxiNodeRef FGGroundNetwork::findNearestNodeOnRunwayEntry(const SGGeod & aGeod
|
|||
return result;
|
||||
}
|
||||
|
||||
FGTaxiNodeRef FGGroundNetwork::findNearestNodeOnRunwayExit(const SGGeod & aGeod, FGRunway* aRunway) const
|
||||
FGTaxiNodeRef FGGroundNetwork::findNearestNodeOnRunwayExit(const SGGeod& aGeod, FGRunway* aRunway) const
|
||||
{
|
||||
double d = DBL_MAX;
|
||||
SGVec3d cartPos = SGVec3d::fromGeod(aGeod);
|
||||
FGTaxiNodeRef result = 0;
|
||||
FGTaxiNodeVector::const_iterator it;
|
||||
if (aRunway) {
|
||||
SG_LOG(SG_AI, SG_BULK, "findNearestNodeOnRunwayExit " << aRunway->ident() << " " << aRunway->headingDeg() );
|
||||
SG_LOG(SG_AI, SG_BULK, "findNearestNodeOnRunwayExit " << aRunway->ident() << " " << aRunway->headingDeg());
|
||||
for (it = m_nodes.begin(); it != m_nodes.end(); ++it) {
|
||||
if (!(*it)->getIsOnRunway())
|
||||
continue;
|
||||
|
@ -314,13 +292,13 @@ FGTaxiNodeRef FGGroundNetwork::findNearestNodeOnRunwayExit(const SGGeod & aGeod,
|
|||
}
|
||||
FGTaxiNodeVector exitSegments = findSegmentsFrom((*it));
|
||||
// Some kind of star
|
||||
if (exitSegments.size() > 2 ) {
|
||||
if (exitSegments.size() > 2) {
|
||||
continue;
|
||||
}
|
||||
// two segments and next points are on runway, too. Must be a segment before end
|
||||
// single runway point not at end is ok
|
||||
if (exitSegments.size() == 2 &&
|
||||
((*exitSegments.at(0)).getIsOnRunway() || (*exitSegments.at(0)).getIsOnRunway() )) {
|
||||
((*exitSegments.at(0)).getIsOnRunway() || (*exitSegments.at(0)).getIsOnRunway())) {
|
||||
continue;
|
||||
}
|
||||
double exitHeading = SGGeodesy::courseDeg((*it)->geod(),
|
||||
|
@ -340,7 +318,7 @@ FGTaxiNodeRef FGGroundNetwork::findNearestNodeOnRunwayExit(const SGGeod & aGeod,
|
|||
} else {
|
||||
SG_LOG(SG_AI, SG_BULK, "No Runway findNearestNodeOnRunwayExit");
|
||||
}
|
||||
if(result) {
|
||||
if (result) {
|
||||
SG_LOG(SG_AI, SG_BULK, "findNearestNodeOnRunwayExit found :" << result->getIndex());
|
||||
return result;
|
||||
}
|
||||
|
@ -365,7 +343,7 @@ FGTaxiNodeRef FGGroundNetwork::findNearestNodeOnRunwayExit(const SGGeod & aGeod,
|
|||
result = *it;
|
||||
}
|
||||
}
|
||||
if(result) {
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
// Ok then fallback only exits
|
||||
|
@ -379,7 +357,7 @@ FGTaxiNodeRef FGGroundNetwork::findNearestNodeOnRunwayExit(const SGGeod & aGeod,
|
|||
result = *it;
|
||||
}
|
||||
}
|
||||
if(result) {
|
||||
if (result) {
|
||||
return result;
|
||||
} else {
|
||||
SG_LOG(SG_AI, SG_WARN, "No runway exit found " << aRunway->airport()->getId() << "/" << aRunway->name());
|
||||
|
@ -387,7 +365,7 @@ FGTaxiNodeRef FGGroundNetwork::findNearestNodeOnRunwayExit(const SGGeod & aGeod,
|
|||
}
|
||||
}
|
||||
|
||||
FGTaxiSegment *FGGroundNetwork::findOppositeSegment(unsigned int index) const
|
||||
FGTaxiSegment* FGGroundNetwork::findOppositeSegment(unsigned int index) const
|
||||
{
|
||||
FGTaxiSegment* seg = findSegment(index);
|
||||
if (!seg)
|
||||
|
@ -395,12 +373,12 @@ FGTaxiSegment *FGGroundNetwork::findOppositeSegment(unsigned int index) const
|
|||
return seg->opposite();
|
||||
}
|
||||
|
||||
const FGParkingList &FGGroundNetwork::allParkings() const
|
||||
const FGParkingList& FGGroundNetwork::allParkings() const
|
||||
{
|
||||
return m_parkings;
|
||||
}
|
||||
|
||||
FGTaxiSegment *FGGroundNetwork::findSegment(unsigned idx) const
|
||||
FGTaxiSegment* FGGroundNetwork::findSegment(unsigned idx) const
|
||||
{
|
||||
if ((idx > 0) && (idx <= segments.size()))
|
||||
return segments[idx - 1];
|
||||
|
@ -440,9 +418,9 @@ static int edgePenalty(FGTaxiNode* tn)
|
|||
class ShortestPathData
|
||||
{
|
||||
public:
|
||||
ShortestPathData() :
|
||||
score(HUGE_VAL)
|
||||
{}
|
||||
ShortestPathData() : score(HUGE_VAL)
|
||||
{
|
||||
}
|
||||
|
||||
double score;
|
||||
FGTaxiNodeRef previousNode;
|
||||
|
@ -453,8 +431,8 @@ FGTaxiRoute FGGroundNetwork::findShortestRoute(FGTaxiNode* start, FGTaxiNode* en
|
|||
if (!start || !end) {
|
||||
throw sg_exception("Bad arguments to findShortestRoute");
|
||||
}
|
||||
//implements Dijkstra's algorithm to find shortest distance route from start to end
|
||||
//taken from http://en.wikipedia.org/wiki/Dijkstra's_algorithm
|
||||
//implements Dijkstra's algorithm to find shortest distance route from start to end
|
||||
//taken from http://en.wikipedia.org/wiki/Dijkstra's_algorithm
|
||||
FGTaxiNodeVector unvisited(m_nodes);
|
||||
std::map<FGTaxiNode*, ShortestPathData> searchData;
|
||||
|
||||
|
@ -502,15 +480,14 @@ FGTaxiRoute FGGroundNetwork::findShortestRoute(FGTaxiNode* start, FGTaxiNode* en
|
|||
// assemble route from backtrace information
|
||||
FGTaxiNodeVector nodes;
|
||||
intVec routes;
|
||||
FGTaxiNode *bt = end;
|
||||
FGTaxiNode* bt = end;
|
||||
|
||||
while (searchData[bt].previousNode != 0) {
|
||||
nodes.push_back(bt);
|
||||
FGTaxiSegment *segment = findSegment(searchData[bt].previousNode, bt);
|
||||
FGTaxiSegment* segment = findSegment(searchData[bt].previousNode, bt);
|
||||
int idx = segment->getIndex();
|
||||
routes.push_back(idx);
|
||||
bt = searchData[bt].previousNode;
|
||||
|
||||
}
|
||||
nodes.push_back(start);
|
||||
reverse(nodes.begin(), nodes.end());
|
||||
|
@ -525,7 +502,7 @@ void FGGroundNetwork::unblockAllSegments(time_t now)
|
|||
}
|
||||
}
|
||||
|
||||
void FGGroundNetwork::blockSegmentsEndingAt(FGTaxiSegment *seg, int blockId, time_t blockTime, time_t now)
|
||||
void FGGroundNetwork::blockSegmentsEndingAt(const FGTaxiSegment* seg, int blockId, time_t blockTime, time_t now)
|
||||
{
|
||||
if (!seg)
|
||||
throw sg_exception("Passed invalid segment");
|
||||
|
@ -562,7 +539,7 @@ FGParkingRef FGGroundNetwork::getParkingByIndex(unsigned int index) const
|
|||
return FGParkingRef(static_cast<FGParking*>(tn.ptr()));
|
||||
}
|
||||
|
||||
FGParkingRef FGGroundNetwork::findParkingByName(const string &name) const
|
||||
FGParkingRef FGGroundNetwork::findParkingByName(const string& name) const
|
||||
{
|
||||
auto it = std::find_if(m_parkings.begin(), m_parkings.end(), [name](const FGParkingRef& p) {
|
||||
return p->ident() == name;
|
||||
|
@ -574,7 +551,7 @@ FGParkingRef FGGroundNetwork::findParkingByName(const string &name) const
|
|||
return *it;
|
||||
}
|
||||
|
||||
void FGGroundNetwork::addSegment(const FGTaxiNodeRef &from, const FGTaxiNodeRef &to)
|
||||
void FGGroundNetwork::addSegment(const FGTaxiNodeRef& from, const FGTaxiNodeRef& to)
|
||||
{
|
||||
FGTaxiSegment* seg = new FGTaxiSegment(from, to);
|
||||
segments.push_back(seg);
|
||||
|
@ -590,7 +567,7 @@ void FGGroundNetwork::addSegment(const FGTaxiNodeRef &from, const FGTaxiNodeRef
|
|||
}
|
||||
}
|
||||
|
||||
void FGGroundNetwork::addParking(const FGParkingRef &park)
|
||||
void FGGroundNetwork::addParking(const FGParkingRef& park)
|
||||
{
|
||||
m_parkings.push_back(park);
|
||||
|
||||
|
@ -601,7 +578,7 @@ void FGGroundNetwork::addParking(const FGParkingRef &park)
|
|||
}
|
||||
}
|
||||
|
||||
FGTaxiNodeVector FGGroundNetwork::findSegmentsFrom(const FGTaxiNodeRef &from) const
|
||||
FGTaxiNodeVector FGGroundNetwork::findSegmentsFrom(const FGTaxiNodeRef& from) const
|
||||
{
|
||||
FGTaxiNodeVector result;
|
||||
FGTaxiSegmentVector::const_iterator it;
|
||||
|
@ -614,7 +591,8 @@ FGTaxiNodeVector FGGroundNetwork::findSegmentsFrom(const FGTaxiNodeRef &from) co
|
|||
return result;
|
||||
}
|
||||
|
||||
FGTaxiSegment* FGGroundNetwork::findSegmentByHeading(const FGTaxiNode* from, const double heading) const {
|
||||
FGTaxiSegment* FGGroundNetwork::findSegmentByHeading(const FGTaxiNode* from, const double heading) const
|
||||
{
|
||||
if (from == 0) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -628,7 +606,7 @@ FGTaxiSegment* FGGroundNetwork::findSegmentByHeading(const FGTaxiNode* from, con
|
|||
continue;
|
||||
}
|
||||
|
||||
if( !best || fabs(best->getHeading()-heading) > fabs(seg->getHeading()-heading)) {
|
||||
if (!best || fabs(best->getHeading() - heading) > fabs(seg->getHeading() - heading)) {
|
||||
best = seg;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public:
|
|||
id = i;
|
||||
}
|
||||
|
||||
~Block(){}
|
||||
~Block() {}
|
||||
|
||||
int getId() { return id; }
|
||||
|
||||
|
@ -146,7 +146,7 @@ public:
|
|||
routes(copy.routes),
|
||||
distance(copy.distance),
|
||||
currNode(nodes.begin()),
|
||||
currRoute(routes.begin()){}
|
||||
currRoute(routes.begin()) {}
|
||||
|
||||
bool operator<(const FGTaxiRoute& other) const
|
||||
{
|
||||
|
@ -295,8 +295,7 @@ public:
|
|||
FGTaxiRoute findShortestRoute(FGTaxiNode* start, FGTaxiNode* end, bool fullSearch = true);
|
||||
|
||||
|
||||
void blockSegmentsEndingAt(FGTaxiSegment* seg, int blockId,
|
||||
time_t blockTime, time_t now);
|
||||
void blockSegmentsEndingAt(const FGTaxiSegment* seg, int blockId, time_t blockTime, time_t now);
|
||||
|
||||
void addVersion(int v) { version = v; };
|
||||
void unblockAllSegments(time_t now);
|
||||
|
|
Loading…
Reference in a new issue