]> git.mxchange.org Git - flightgear.git/commitdiff
Experimental sorter for airports.
authorJames Turner <zakalawe@mac.com>
Sat, 26 Oct 2013 21:53:24 +0000 (22:53 +0100)
committerJames Turner <zakalawe@mac.com>
Sun, 27 Oct 2013 13:03:01 +0000 (13:03 +0000)
Sort by size (cumulative runway length).

src/Airports/airport.cxx
src/Airports/airport.hxx

index 6d463fd540ce75796003f9067b5c3a63574711e6..42d76f5ba7d18f7c390870edff068e9cc9cad59b 100644 (file)
@@ -889,6 +889,46 @@ FGAirport::commStationsOfType(FGPositioned::Type aTy) const
   return result;
 }
 
+class AirportWithSize
+{
+public:
+    AirportWithSize(FGPositionedRef pos) :
+        _pos(pos),
+        _sizeMetric(0)
+    {
+        assert(pos->type() == FGPositioned::AIRPORT);
+        FGAirport* apt = static_cast<FGAirport*>(pos.get());
+        BOOST_FOREACH(FGRunway* rwy, apt->getRunwaysWithoutReciprocals()) {
+            _sizeMetric += static_cast<int>(rwy->lengthFt());
+        }
+    }
+    
+    bool operator<(const AirportWithSize& other) const
+    {
+        return _sizeMetric < other._sizeMetric;
+    }
+    
+    FGPositionedRef pos() const
+    { return _pos; }
+private:
+    FGPositionedRef _pos;
+    unsigned int _sizeMetric;
+    
+};
+
+void FGAirport::sortBySize(FGPositionedList& airportList)
+{
+    std::vector<AirportWithSize> annotated;
+    BOOST_FOREACH(FGPositionedRef p, airportList) {
+        annotated.push_back(AirportWithSize(p));
+    }
+    std::sort(annotated.begin(), annotated.end());
+    
+    for (unsigned int i=0; i<annotated.size(); ++i) {
+        airportList[i] = annotated[i].pos();
+    }
+}
+
 // get airport elevation
 double fgGetAirportElev( const std::string& id )
 {
index fdf365755454beab6fe29562acc6d75f61ee702c..a35354075fda71c412e81cbd4c9c0bd064b98302 100644 (file)
@@ -251,7 +251,14 @@ class FGAirport : public FGPositioned
       * matches in a format suitable for use by a puaList. 
       */
      static char** searchNamesAndIdents(const std::string& aFilter);
-         
+    
+    
+    /**
+     * Sort an FGPositionedList of airports by size (number of runways + length)
+     * this is meant to prioritise more important airports.
+     */
+    static void sortBySize(FGPositionedList&);
+    
     flightgear::CommStationList commStationsOfType(FGPositioned::Type aTy) const;
     
     flightgear::CommStationList commStations() const;