use crate::{EARTH_GM, EARTH_J2, EARTH_RADIUS_EQUATORIAL, SPEED_OF_LIGHT};
use core::ops::Div;
use deep_causality_num::{FromPrimitive, Real};
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct CentralBody<R: Real + Div<Output = R>> {
pub gm: R,
pub equatorial_radius_m: R,
pub j2: R,
}
impl CentralBody<f64> {
pub const EARTH_JGM3: Self = Self {
gm: EARTH_GM,
equatorial_radius_m: EARTH_RADIUS_EQUATORIAL,
j2: EARTH_J2,
};
}
impl<R: Real + Div<Output = R>> CentralBody<R> {
#[inline]
pub fn new(gm: R, equatorial_radius_m: R, j2: R) -> Self {
Self {
gm,
equatorial_radius_m,
j2,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub struct SpaceTimeCoordinate<R: Real + Div<Output = R>> {
pub timestamp: u64,
pub sat_id: u32,
pub r_m: R,
pub v_ms: R,
pub clock_bias_s: R,
pub position: [R; 3],
pub velocity: [R; 3],
pub clock_drift_rate: R,
}
impl<R: Real + Div<Output = R> + FromPrimitive> SpaceTimeCoordinate<R> {
pub fn get_total_bias(&self) -> R {
let dot_rv = self.position[0] * self.velocity[0]
+ self.position[1] * self.velocity[1]
+ self.position[2] * self.velocity[2];
let c_sq = R::from_f64(SPEED_OF_LIGHT * SPEED_OF_LIGHT).unwrap();
let two = R::from_f64(2.0).unwrap();
let rel_correction = -two * dot_rv / c_sq;
self.clock_bias_s + rel_correction
}
}