use geometry_cs::Spheroid;
#[derive(Debug, Clone, Copy)]
pub(crate) struct SpheroidCalc {
pub(crate) a: f64,
#[allow(dead_code, reason = "consumed by Vincenty / Thomas in T44+")]
pub(crate) b: f64,
pub(crate) f: f64,
#[allow(dead_code, reason = "consumed by Vincenty / Thomas in T44+")]
pub(crate) e2: f64,
}
impl SpheroidCalc {
pub(crate) fn from(s: Spheroid) -> Self {
Self {
a: s.equatorial_radius,
b: s.polar_radius(),
f: s.flattening,
e2: s.eccentricity_squared(),
}
}
#[allow(dead_code, reason = "consumed by distance strategies landing in T43+")]
pub(crate) fn second_eccentricity_squared(&self) -> f64 {
self.e2 / (1.0 - self.e2)
}
}
#[cfg(test)]
mod tests {
use super::SpheroidCalc;
use geometry_cs::Spheroid;
#[test]
fn wgs84_derived_constants() {
let c = SpheroidCalc::from(Spheroid::WGS84);
assert!((c.b - 6_356_752.314_245).abs() < 1e-3);
assert!((c.e2 - 0.006_694_379_990_141_316).abs() < 1e-15);
}
#[test]
fn second_eccentricity_matches_its_definition() {
let calc = SpheroidCalc::from(Spheroid::WGS84);
let expected = calc.e2 / (1.0 - calc.e2);
assert!((calc.second_eccentricity_squared() - expected).abs() < f64::EPSILON);
}
}