1 // runways.cxx -- a simple class to manage airport runway info
3 // Written by Curtis Olson, started August 2000.
5 // Copyright (C) 2000 Curtis L. Olson - http://www.flightgear.org/~curt
7 // This program is free software; you can redistribute it and/or
8 // modify it under the terms of the GNU General Public License as
9 // published by the Free Software Foundation; either version 2 of the
10 // License, or (at your option) any later version.
12 // This program is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
28 #include <cmath> // fabs()
29 #include <cstdio> // sprintf()
30 #include <cstdlib> // atoi()
32 #include <simgear/compiler.h>
33 #include <simgear/debug/logstream.hxx>
34 #include <Main/fg_props.hxx>
39 #include "runways.hxx"
53 * 7 - concrete helipad
59 static FGPositioned::Type runwayTypeFromNumber(const std::string& aRwyNo)
61 return (aRwyNo[0] == 'x') ? FGPositioned::TAXIWAY : FGPositioned::RUNWAY;
64 static std::string cleanRunwayNo(const std::string& aRwyNo)
66 if (aRwyNo[0] == 'x') {
67 return std::string(); // no ident for taxiways
70 string result(aRwyNo);
71 // canonicalise runway ident
72 if ((aRwyNo.size() == 1) || !isdigit(aRwyNo[1])) {
73 result = "0" + aRwyNo;
76 // trim off trailing garbage
77 if (result.size() > 2) {
78 char suffix = toupper(result[2]);
80 result = result.substr(0, 2);
87 FGRunway::FGRunway(FGAirport* aAirport, const string& rwy_no,
89 const double heading, const double length,
91 const double displ_thresh,
93 const int surface_code,
95 FGPositioned(runwayTypeFromNumber(rwy_no), cleanRunwayNo(rwy_no), aGeod,
96 (runwayTypeFromNumber(rwy_no) == FGPositioned::RUNWAY)),
98 _reciprocal(reciprocal)
103 _displ_thresh = displ_thresh;
106 _surface_code = surface_code;
109 string FGRunway::reverseIdent(const string& aRunwayIdent)
111 // Helipads don't have a seperate number per end
112 if (aRunwayIdent.size() && (aRunwayIdent[0] == 'H' || aRunwayIdent[0] == 'h' || aRunwayIdent[0] == 'x')) {
116 std::string ident(aRunwayIdent);
119 int rn = atoi(ident.substr(0,2).c_str());
125 sprintf(buf, "%02i", rn);
126 if(ident.size() == 3) {
127 char suffix = toupper(ident[2]);
130 } else if (suffix == 'R') {
133 // something else, just copy
143 double FGRunway::score(double aLengthWt, double aWidthWt, double aSurfaceWt) const
146 if (_surface_code == 12 || _surface_code == 5) // dry lakebed & gravel
148 else if (_surface_code == 1 || _surface_code == 2) // asphalt & concrete
151 return _length * aLengthWt + _width * aWidthWt + surface * aSurfaceWt + 1e-20;
154 bool FGRunway::isTaxiway() const
156 return (type() == TAXIWAY);
159 SGGeod FGRunway::threshold() const
161 return pointOnCenterline(0.0);
164 SGGeod FGRunway::reverseThreshold() const
166 return pointOnCenterline(lengthM());
169 SGGeod FGRunway::displacedThreshold() const
171 return pointOnCenterline(_displ_thresh * SG_FEET_TO_METER);
174 SGGeod FGRunway::pointOnCenterline(double aOffset) const
178 double halfLengthMetres = lengthM() * 0.5;
180 SGGeodesy::direct(mPosition, _heading,
181 aOffset - halfLengthMetres,
186 bool FGRunway::isHardSurface() const
188 return ((_surface_code == 1) || (_surface_code == 2));