-
-// Return the runway number of the runway closest to a given heading
-string FGRunwayList::search( const string& aptid, const int tgt_hdg ) {
- FGRunway r;
- FGRunway tmp_r;
- string rn;
- double found_dir = 0.0;
-
- if ( !search( aptid, &tmp_r ) ) {
- SG_LOG( SG_GENERAL, SG_ALERT,
- "Failed to find " << aptid << " in database." );
- return "NN";
- }
-
- double diff;
- double min_diff = 360.0;
-
- while ( tmp_r.id == aptid ) {
- r = tmp_r;
-
- // forward direction
- diff = tgt_hdg - r.heading;
- while ( diff < -180.0 ) { diff += 360.0; }
- while ( diff > 180.0 ) { diff -= 360.0; }
- diff = fabs(diff);
- // SG_LOG( SG_GENERAL, SG_INFO,
- // "Runway " << r.rwy_no << " heading = " << r.heading <<
- // " diff = " << diff );
- if ( diff < min_diff ) {
- min_diff = diff;
- rn = r.rwy_no;
- found_dir = 0;
- }
-
- // reverse direction
- diff = tgt_hdg - r.heading - 180.0;
- while ( diff < -180.0 ) { diff += 360.0; }
- while ( diff > 180.0 ) { diff -= 360.0; }
- diff = fabs(diff);
- // SG_LOG( SG_GENERAL, SG_INFO,
- // "Runway -" << r.rwy_no << " heading = " <<
- // r.heading + 180.0 <<
- // " diff = " << diff );
- if ( diff < min_diff ) {
- min_diff = diff;
- rn = r.rwy_no;
- found_dir = 180.0;
- }
-
- next( &tmp_r );
- }
-
- // SG_LOG( SG_GENERAL, SG_INFO, "closest runway = " << r.rwy_no
- // << " + " << found_dir );
- rn = r.rwy_no;
- // cout << "In search, rn = " << rn << endl;
- if ( found_dir == 180 ) {
- rn = GetReverseRunwayNo(rn);
- //cout << "New rn = " << rn << '\n';
- }
-
- return rn;
+void FGRunway::processThreshold(SGPropertyNode* aThreshold)
+{
+ assert(ident() == aThreshold->getStringValue("rwy"));
+
+ double lon = aThreshold->getDoubleValue("lon"),
+ lat = aThreshold->getDoubleValue("lat");
+ SGGeod newThreshold(SGGeod::fromDegM(lon, lat, mPosition.getElevationM()));
+
+ _heading = aThreshold->getDoubleValue("hdg-deg");
+ _displ_thresh = aThreshold->getDoubleValue("displ-m") * SG_METER_TO_FEET;
+ _stopway = aThreshold->getDoubleValue("stopw-m") * SG_METER_TO_FEET;
+
+ // compute the new runway center, based on the threshold lat/lon and length,
+ double offsetFt = (0.5 * _length);
+ SGGeod newCenter;
+ double dummy;
+ SGGeodesy::direct(newThreshold, _heading, offsetFt * SG_FEET_TO_METER, newCenter, dummy);
+ mPosition = newCenter;
+}
+
+void FGRunway::setReciprocalRunway(FGRunway* other)
+{
+ assert(_reciprocal==NULL);
+ assert((other->_reciprocal == NULL) || (other->_reciprocal == this));
+
+ _reciprocal = other;