use crate::RotationModel;
use astrodyn_planet::PlanetShape;
use astrodyn_quantities::dims::GravParam;
use astrodyn_quantities::ext::F64Ext;
use astrodyn_quantities::frame::SelfPlanet;
use uom::si::f64::{AngularVelocity, Length};
#[derive(Debug, Clone, Copy)]
pub struct PlanetConfig {
pub shape: PlanetShape,
pub rotation_model: RotationModel,
pub omega: f64,
pub shadow_radius: f64,
}
impl PlanetConfig {
#[inline]
pub fn mu_typed(&self) -> GravParam<SelfPlanet> {
self.shape.mu_typed()
}
#[inline]
pub fn omega_typed(&self) -> AngularVelocity {
self.omega.rad_per_s()
}
#[inline]
pub fn shadow_radius_typed(&self) -> Length {
use uom::si::length::meter;
Length::new::<meter>(self.shadow_radius)
}
}
pub const EARTH: PlanetConfig = PlanetConfig {
shape: astrodyn_planet::presets::EARTH,
rotation_model: RotationModel::EarthRNP,
omega: 7.292_115_146_706_388e-5,
shadow_radius: 6_378_137.0,
};
pub const MOON: PlanetConfig = PlanetConfig {
shape: astrodyn_planet::presets::MOON,
rotation_model: RotationModel::MoonIAU,
omega: 0.0,
shadow_radius: 1_738_140.0,
};
pub const SUN: PlanetConfig = PlanetConfig {
shape: astrodyn_planet::presets::SUN,
rotation_model: RotationModel::None,
omega: 0.0,
shadow_radius: 696_000_000.0,
};
pub const MARS: PlanetConfig = PlanetConfig {
shape: astrodyn_planet::presets::MARS,
rotation_model: RotationModel::MarsIAU,
omega: 7.088_218e-5,
shadow_radius: 3_396_000.0,
};
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn earth_shadow_radius_matches_r_eq() {
assert_eq!(EARTH.shadow_radius, EARTH.shape.r_eq);
}
#[test]
fn sun_no_rotation() {
assert_eq!(SUN.rotation_model, RotationModel::None);
}
#[test]
fn all_configs_positive_radii() {
for config in [EARTH, MOON, SUN, MARS] {
assert!(
config.shadow_radius > 0.0,
"{}: shadow_radius must be positive",
config.shape.name
);
assert!(
config.omega >= 0.0,
"{}: omega must be non-negative",
config.shape.name
);
}
}
}