]> git.mxchange.org Git - flightgear.git/blob - src/Airports/gnnode.cxx
Merge branch 'next' of D:\Git_New\flightgear into next
[flightgear.git] / src / Airports / gnnode.cxx
1 #include "gnnode.hxx"
2 #include "groundnetwork.hxx"
3
4 #include <algorithm>
5 using std::sort;
6
7 /*****************************************************************************
8  * Helper function for parsing position string
9  ****************************************************************************/
10 double processPosition(const string &pos)
11 {
12   string prefix;
13   string subs;
14   string degree;
15   string decimal;
16   int sign = 1;
17   double value;
18   subs = pos;
19   prefix= subs.substr(0,1);
20   if (prefix == string("S") || (prefix == string("W")))
21     sign = -1;
22   subs    = subs.substr(1, subs.length());
23   degree  = subs.substr(0, subs.find(" ",0));
24   decimal = subs.substr(subs.find(" ",0), subs.length());
25   
26               
27   //cerr << sign << " "<< degree << " " << decimal << endl;
28   value = sign * (atof(degree.c_str()) + atof(decimal.c_str())/60.0);
29   //cerr << value <<endl;
30   //exit(1);
31   return value;
32 }
33
34 bool sortByHeadingDiff(FGTaxiSegment *a, FGTaxiSegment *b) {
35   return a->hasSmallerHeadingDiff(*b);
36 }
37
38 bool sortByLength(FGTaxiSegment *a, FGTaxiSegment *b) {
39   return a->getLength() > b->getLength();
40 }
41
42 /**************************************************************************
43  * FGTaxiNode
44  *************************************************************************/
45
46
47 void FGTaxiNode::setLatitude (double val)
48 {
49   geod.setLatitudeDeg(val);
50 }
51
52 void FGTaxiNode::setLongitude(double val)
53 {
54   geod.setLongitudeDeg(val);
55 }
56
57 void FGTaxiNode::setLatitude (const string& val)
58 {
59   geod.setLatitudeDeg(processPosition(val));
60 }
61
62 void FGTaxiNode::setLongitude(const string& val)
63 {
64   geod.setLongitudeDeg(processPosition(val));
65 }
66   
67 void FGTaxiNode::sortEndSegments(bool byLength)
68 {
69   if (byLength)
70     sort(next.begin(), next.end(), sortByLength);
71   else
72     sort(next.begin(), next.end(), sortByHeadingDiff);
73 }