1
0
Fork 0

Switch ATCmgr comm station search to filter by range in cartesian, not geodetic, space, to avoid numerical instability with extremely distant stations.

This commit is contained in:
James Turner 2011-09-28 09:06:31 +01:00
parent ab238a1161
commit dbda2fb95d
3 changed files with 39 additions and 10 deletions

View file

@ -6,5 +6,12 @@ set(SOURCES
trafficcontrol.cxx
CommStation.cxx
)
flightgear_component(ATC "${SOURCES}")
set(HEADERS
atc_mgr.hxx
atcdialog.hxx
trafficcontrol.hxx
CommStation.hxx
)
flightgear_component(ATC "${SOURCES}" "${HEADERS}")

View file

@ -253,16 +253,26 @@ void FGATCMgr::FreqSearch(const string navcomm, const int unit) {
class RangeFilter : public CommStation::Filter {
public:
RangeFilter( const SGGeod & pos ) : CommStation::Filter(), _pos(pos) {}
virtual bool pass(FGPositioned* aPos) const {
RangeFilter( const SGGeod & pos ) :
CommStation::Filter(),
_cart(SGVec3d::fromGeod(pos)),
_pos(pos)
{}
virtual bool pass(FGPositioned* aPos) const
{
flightgear::CommStation * stn = dynamic_cast<flightgear::CommStation*>(aPos);
if( NULL == stn ) return false;
double dist = SGGeodesy::distanceNm( stn->geod(), _pos );
// if range is not configured, assume at least 10NM range
// TODO: maybe ramp down range with proximity to ground?
return dist <= SGMiscd::max( stn->rangeNm(), 10.0 );
// do the range check in cartesian space, since the distances are potentially
// large enough that the geodetic functions become unstable
// (eg, station on opposite side of the planet)
double rangeM = SGMiscd::max( stn->rangeNm(), 10.0 ) * SG_NM_TO_METER;
double d2 = distSqr( aPos->cart(), _cart);
return d2 <= (rangeM * rangeM);
}
private:
SGVec3d _cart;
SGGeod _pos;
};

View file

@ -9,5 +9,17 @@ set(SOURCES
ATCutils.cxx
ATCProjection.cxx
)
flightgear_component(ATCDCL "${SOURCES}")
set(HEADERS
ATC.hxx
atis.hxx
ATCDialogOld.hxx
ATCVoice.hxx
ATCmgr.hxx
ATCutils.hxx
ATCProjection.hxx
atis_lexicon.hxx
atis_remap.hxx
)
flightgear_component(ATCDCL "${SOURCES}" "${HEADERS}")