fn update_position(&mut self, lat_long: (f64, f64)) -> bool {
        if let [Some(odd), Some(even)] = self.altitudes {
            let test_position = cpr::get_position((&odd, &even));

            // Check kilometer range from receiver
            if let Some(test_position) = test_position {
                let kilo_distance = Self::haversine_distance(
                    lat_long,
                    (test_position.latitude, test_position.longitude),
                );
                if kilo_distance > MAX_RECEIVER_DISTANCE {
                    warn!("range: {kilo_distance} -  old: {lat_long:?} new: {test_position:?}");
                    return false;
                }
                self.kilo_distance = Some(kilo_distance);
                debug!("range: {kilo_distance}");
            }

            // if previous position, check against for range. This is a non-great way of doing
            // this, but maybe in the future we can check against the speed of the aircraft
            if let (Some(current_position), Some(test_position)) = (self.position, test_position) {
                let distance = Self::haversine_distance_position(current_position, test_position);
                if distance > MAX_AIRCRAFT_DISTANCE {
                    warn!("distance: {distance} old: {current_position:?}, invalid: {test_position:?}");
                    return false;
                }
                debug!("distance: {distance}");
            }

            // Good new position!
            self.position = test_position;
            debug!("update_position: odd: (lat: {}, long: {}), even: (lat: {}, long: {}), position: {:?}",
                odd.lat_cpr,
                odd.lon_cpr,
                even.lat_cpr,
                even.lat_cpr,
                self.position);
            self.last_time = Some(SystemTime::now());
        }
        true
    }
/// After checking the range of the new lat / long, new position from last position, update the
/// position of an aircraft
After checking the range of the new lat / long, new position from last position, update the
position of an aircraft
After checking the range of the new lat / long new position from last position update the position of an aircraft
fn update_position(&mut self, lat_long: (f64, f64)) -> bool {
        if let [Some(odd), Some(even)] = self.altitudes {
            let test_position = cpr::get_position((&odd, &even));
            // Check kilometer range from receiver
            if let Some(test_position) = test_position {
                let kilo_distance = Self::haversine_distance(
                    lat_long,
                    (test_position.latitude, test_position.longitude),
                );
                if kilo_distance > MAX_RECEIVER_DISTANCE {
                    warn!("range: {kilo_distance} -  old: {lat_long:?} new: {test_position:?}");
                    return false;
                }
                self.kilo_distance = Some(kilo_distance);
                debug!("range: {kilo_distance}");
            }
            // if previous position, check against for range. This is a non-great way of doing
            // this, but maybe in the future we can check against the speed of the aircraft
            if let (Some(current_position), Some(test_position)) = (self.position, test_position) {
                let distance = Self::haversine_distance_position(current_position, test_position);
                if distance > MAX_AIRCRAFT_DISTANCE {
                    warn!("distance: {distance} old: {current_position:?}, invalid: {test_position:?}");
                    return false;
                }
                debug!("distance: {distance}");
            }
            // Good new position!
            self.position = test_position;
            debug!("update_position: odd: (lat: {}, long: {}), even: (lat: {}, long: {}), position: {:?}",
                odd.lat_cpr,
                odd.lon_cpr,
                even.lat_cpr,
                even.lat_cpr,
                self.position);
            self.last_time = Some(SystemTime::now());
        }
        true
    }
fn update_position ( & mut self , lat_long : ( f64 , f64 ) ) -> bool { if let [ Some ( odd ) , Some ( even ) ] = self . altitudes { let test_position = cpr :: get_position ( ( & odd , & even ) ) ; // Check kilometer range from receiver if let Some ( test_position ) = test_position { let kilo_distance = Self :: haversine_distance ( lat_long , ( test_position . latitude , test_position . longitude ) , ) ; if kilo_distance > MAX_RECEIVER_DISTANCE { warn ! ( " " ) ; return false ; } self . kilo_distance = Some ( kilo_distance ) ; debug ! ( " " ) ; } // if previous position, check against for range. This is a non-great way of doing // this, but maybe in the future we can check against the speed of the aircraft if let ( Some ( current_position ) , Some ( test_position ) ) = ( self . position , test_position ) { let distance = Self :: haversine_distance_position ( current_position , test_position ) ; if distance > MAX_AIRCRAFT_DISTANCE { warn ! ( " " ) ; return false ; } debug ! ( " " ) ; } // Good new position! self . position = test_position ; debug ! ( " " odd lat_cpr odd lon_cpr even lat_cpr even lat_cpr self position ) ; self . last_time = Some ( SystemTime :: now ( ) ) ; } true }
After checking the range of the new lat / long, new position from last position, update the
position of an aircraft
After checking the range of the new lat / long new position from last position update the position of an aircraft
&mut self
lat_long
(f64, f64)
&mut self
lat_long
(f64, f64)