+
+// Given a point and a list of stations, return the closest one to the
+// specified point.
+FGNav *FGNavList::findNavFromList( const Point3D &aircraft,
+ const nav_list_type &stations )
+{
+ FGNav *nav = NULL;
+ Point3D station;
+ double d2;
+ double min_dist = 999999999.0;
+
+ // prime the pump with info from stations[0]
+ if ( stations.size() > 0 ) {
+ nav = stations[0];
+ station = Point3D( nav->get_x(), nav->get_y(), nav->get_z());
+ min_dist = aircraft.distance3Dsquared( station );
+ }
+
+ // check if any of the remaining stations are closer
+ for ( unsigned int i = 1; i < stations.size(); ++i ) {