From dbda2fb95d6e18a3e25d07a6c4114e0c32442c73 Mon Sep 17 00:00:00 2001 From: James Turner Date: Wed, 28 Sep 2011 09:06:31 +0100 Subject: [PATCH] Switch ATCmgr comm station search to filter by range in cartesian, not geodetic, space, to avoid numerical instability with extremely distant stations. --- src/ATC/CMakeLists.txt | 11 +++++++++-- src/ATCDCL/ATCmgr.cxx | 22 ++++++++++++++++------ src/ATCDCL/CMakeLists.txt | 16 ++++++++++++++-- 3 files changed, 39 insertions(+), 10 deletions(-) diff --git a/src/ATC/CMakeLists.txt b/src/ATC/CMakeLists.txt index e055ec6dd..f7dd1f2df 100644 --- a/src/ATC/CMakeLists.txt +++ b/src/ATC/CMakeLists.txt @@ -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}") diff --git a/src/ATCDCL/ATCmgr.cxx b/src/ATCDCL/ATCmgr.cxx index 7a3da5969..dc0901153 100644 --- a/src/ATCDCL/ATCmgr.cxx +++ b/src/ATCDCL/ATCmgr.cxx @@ -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(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; }; diff --git a/src/ATCDCL/CMakeLists.txt b/src/ATCDCL/CMakeLists.txt index d0dde266a..8f0363135 100644 --- a/src/ATCDCL/CMakeLists.txt +++ b/src/ATCDCL/CMakeLists.txt @@ -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}") -- 2.39.5