pub trait Ut1Offset {
fn dut1(&self, utc_mjd: f64) -> f64;
}
pub trait PolarMotion {
fn x_pole(&self, utc_mjd: f64) -> f64;
fn y_pole(&self, utc_mjd: f64) -> f64;
}
pub trait NutationCorrections {
fn dx(&self, utc_mjd: f64) -> f64;
fn dy(&self, utc_mjd: f64) -> f64;
}
pub trait LengthOfDay {
fn lod(&self, utc_mjd: f64) -> f64;
}
pub trait FullEopProvider: Ut1Offset + PolarMotion + NutationCorrections + LengthOfDay {}
impl<T> FullEopProvider for T where T: Ut1Offset + PolarMotion + NutationCorrections + LengthOfDay {}
#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub struct NullEop;
pub mod entry;
#[cfg(feature = "alloc")]
pub mod error;
#[cfg(feature = "alloc")]
pub mod finals2000a;
#[cfg(feature = "alloc")]
pub mod table;
pub use entry::EopEntry;
#[cfg(feature = "alloc")]
pub use error::{EopLookupError, EopParseError};
#[cfg(feature = "alloc")]
pub use finals2000a::Finals2000A;
#[cfg(feature = "alloc")]
pub use table::EopTable;
#[cfg(test)]
mod tests {
use super::*;
struct MockEop {
dut1: f64,
xp: f64,
yp: f64,
dx: f64,
dy: f64,
lod: f64,
}
impl Ut1Offset for MockEop {
fn dut1(&self, _utc_mjd: f64) -> f64 {
self.dut1
}
}
impl PolarMotion for MockEop {
fn x_pole(&self, _utc_mjd: f64) -> f64 {
self.xp
}
fn y_pole(&self, _utc_mjd: f64) -> f64 {
self.yp
}
}
impl NutationCorrections for MockEop {
fn dx(&self, _utc_mjd: f64) -> f64 {
self.dx
}
fn dy(&self, _utc_mjd: f64) -> f64 {
self.dy
}
}
impl LengthOfDay for MockEop {
fn lod(&self, _utc_mjd: f64) -> f64 {
self.lod
}
}
fn mock() -> MockEop {
MockEop {
dut1: -0.123,
xp: 0.05,
yp: 0.38,
dx: 0.12,
dy: 0.34,
lod: 0.0015,
}
}
#[test]
fn mock_implements_all_eop_traits() {
let m = mock();
assert_eq!(<MockEop as Ut1Offset>::dut1(&m, 60000.0), -0.123);
assert_eq!(<MockEop as PolarMotion>::x_pole(&m, 60000.0), 0.05);
assert_eq!(<MockEop as PolarMotion>::y_pole(&m, 60000.0), 0.38);
assert_eq!(<MockEop as NutationCorrections>::dx(&m, 60000.0), 0.12);
assert_eq!(<MockEop as NutationCorrections>::dy(&m, 60000.0), 0.34);
assert_eq!(<MockEop as LengthOfDay>::lod(&m, 60000.0), 0.0015);
}
#[test]
fn full_eop_provider_blanket_impl_fires_for_mock() {
fn expects_full<P: FullEopProvider>(p: &P) -> f64 {
p.dut1(60000.0) + p.x_pole(60000.0) + p.dy(60000.0) + p.lod(60000.0)
}
let m = mock();
let sum = expects_full(&m);
assert!((sum - (-0.123 + 0.05 + 0.34 + 0.0015)).abs() < 1e-12);
}
#[test]
fn partial_provider_only_satisfies_its_subset() {
struct Dut1Only;
impl Ut1Offset for Dut1Only {
fn dut1(&self, _: f64) -> f64 {
-0.5
}
}
fn expects_ut1<P: Ut1Offset>(p: &P) -> f64 {
p.dut1(0.0)
}
assert_eq!(expects_ut1(&Dut1Only), -0.5);
}
#[test]
fn null_eop_constructs() {
let _n = NullEop;
let _n2 = NullEop::default();
}
}