Return the closest match instead of the first in-range match when searching by frequency
This commit is contained in:
parent
d8000569ea
commit
e4859c1fbf
1 changed files with 20 additions and 10 deletions
|
@ -138,6 +138,8 @@ bool FGCommList::FindByFreq( double lon, double lat, double elev, double freq,
|
||||||
// double az1, az2, s;
|
// double az1, az2, s;
|
||||||
Point3D aircraft = sgGeodToCart( Point3D(lon, lat, elev) );
|
Point3D aircraft = sgGeodToCart( Point3D(lon, lat, elev) );
|
||||||
Point3D station;
|
Point3D station;
|
||||||
|
const double orig_max_d = 1e100;
|
||||||
|
double max_d = orig_max_d;
|
||||||
double d;
|
double d;
|
||||||
// TODO - at the moment this loop returns the first match found in range
|
// TODO - at the moment this loop returns the first match found in range
|
||||||
// We want to return the closest match in the event of a frequency conflict
|
// We want to return the closest match in the event of a frequency conflict
|
||||||
|
@ -150,21 +152,28 @@ bool FGCommList::FindByFreq( double lon, double lat, double elev, double freq,
|
||||||
d = aircraft.distance3Dsquared( station );
|
d = aircraft.distance3Dsquared( station );
|
||||||
|
|
||||||
//cout << " dist = " << sqrt(d)
|
//cout << " dist = " << sqrt(d)
|
||||||
// << " range = " << current->get_range() * SG_NM_TO_METER << endl;
|
// << " range = " << current->range * SG_NM_TO_METER << endl;
|
||||||
|
|
||||||
// match up to twice the published range so we can model
|
// TODO - match up to twice the published range so we can model
|
||||||
// reduced signal strength
|
// reduced signal strength
|
||||||
if ( d < (2 * current->range * SG_NM_TO_METER
|
// NOTE The below is squared since we match to distance3Dsquared (above) to avoid a sqrt.
|
||||||
* 2 * current->range * SG_NM_TO_METER ) ) {
|
if ( d < (current->range * SG_NM_TO_METER
|
||||||
//cout << "matched = " << current->get_ident() << endl;
|
* current->range * SG_NM_TO_METER ) ) {
|
||||||
|
//cout << "matched = " << current->ident << endl;
|
||||||
if((tp == INVALID) || (tp == (*current).type)) {
|
if((tp == INVALID) || (tp == (*current).type)) {
|
||||||
*ad = *current;
|
if(d < max_d) {
|
||||||
return true;
|
max_d = d;
|
||||||
|
*ad = *current;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
if(max_d < orig_max_d) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int FGCommList::FindByPos(double lon, double lat, double elev, double range, comm_list_type* stations, atc_type tp)
|
int FGCommList::FindByPos(double lon, double lat, double elev, double range, comm_list_type* stations, atc_type tp)
|
||||||
|
@ -200,8 +209,9 @@ int FGCommList::FindByPos(double lon, double lat, double elev, double range, com
|
||||||
if((current->type == tp) || (tp == INVALID)) {
|
if((current->type == tp) || (tp == INVALID)) {
|
||||||
station = Point3D(current->x, current->y, current->z);
|
station = Point3D(current->x, current->y, current->z);
|
||||||
d = aircraft.distance3Dsquared( station );
|
d = aircraft.distance3Dsquared( station );
|
||||||
if ( d < (current->range * SG_NM_TO_METER
|
// NOTE The below is squared since we match to distance3Dsquared (above) to avoid a sqrt.
|
||||||
* current->range * SG_NM_TO_METER ) ) {
|
if ( d < (current->range * SG_NM_TO_METER
|
||||||
|
* current->range * SG_NM_TO_METER ) ) {
|
||||||
stations->push_back(*current);
|
stations->push_back(*current);
|
||||||
++found;
|
++found;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue