use crate::rotation::IauRotationModel;
pub const EARTH: IauRotationModel = IauRotationModel {
alpha0: 0.0,
alpha1: -0.641,
delta0: 90.0,
delta1: -0.557,
w0: 190.147,
wd: 360.9856235,
};
#[cfg(test)]
mod tests {
use super::*;
use crate::epoch::{Epoch, Tdb};
use nalgebra::Vector3;
#[test]
fn earth_rotation_period_approximately_sidereal_day() {
let epoch0 = Epoch::from_gregorian(2024, 1, 1, 0, 0, 0.0).to_tdb();
let w0 = EARTH.prime_meridian_angle(&epoch0);
let sidereal_day_s = 86164.1;
let epoch1 = Epoch::<Tdb>::from_jd_tdb(epoch0.jd() + sidereal_day_s / 86400.0);
let w1 = EARTH.prime_meridian_angle(&epoch1);
let dw = (w1 - w0).to_degrees();
assert!(
(dw - 360.0).abs() < 0.5,
"Earth should rotate ~360° in one sidereal day, got {dw:.2}°"
);
}
#[test]
fn earth_pole_near_z_axis() {
let epoch = Epoch::from_gregorian(2024, 1, 1, 0, 0, 0.0).to_tdb();
let pole = EARTH.pole_direction(&epoch);
let z_axis = Vector3::new(0.0, 0.0, 1.0);
let angle = pole.angle(&z_axis).to_degrees();
assert!(
angle < 1.0,
"Earth pole should be within ~1° of ECI Z-axis, got {angle:.2}°"
);
}
#[test]
fn earth_prime_meridian_at_j2000() {
let epoch = Epoch::<Tdb>::from_jd_tdb(2451545.0); let q = EARTH.orientation(&epoch);
let x_body_eci = q * Vector3::new(1.0, 0.0, 0.0);
let ra = x_body_eci.y.atan2(x_body_eci.x).to_degrees();
let ra_pos = if ra < 0.0 { ra + 360.0 } else { ra };
let expected_ra = 280.46;
let diff = ((ra_pos - expected_ra + 180.0) % 360.0 - 180.0).abs();
assert!(
diff < 5.0,
"Earth prime meridian RA at J2000 should be ~{expected_ra}°, got {ra_pos:.2}° (diff={diff:.2}°)"
);
}
}