oxiproj-core 0.1.2

Foundation types for OxiProj: coordinates, errors, ellipsoids, datums, and units.
Documentation
//! Math constants ported from PROJ `src/proj_internal.h`.

/// pi — mirrors `M_PI` from proj.h.
pub const M_PI: f64 = core::f64::consts::PI;
/// pi/2 — mirrors `M_PI_2` from proj.h.
pub const M_PI_2: f64 = core::f64::consts::FRAC_PI_2;
/// pi/4 — mirrors `M_PI_4` from proj.h.
pub const M_PI_4: f64 = core::f64::consts::FRAC_PI_4;
/// 1/pi — mirrors `M_1_PI` from proj.h.
pub const M_1_PI: f64 = core::f64::consts::FRAC_1_PI;
/// 2/pi — mirrors `M_2_PI` from proj.h.
pub const M_2_PI: f64 = core::f64::consts::FRAC_2_PI;
/// sqrt(2) — mirrors `M_SQRT2` from proj.h.
pub const M_SQRT2: f64 = core::f64::consts::SQRT_2;
/// pi/4 — mirrors `M_FORTPI` from proj_internal.h.
pub const M_FORTPI: f64 = M_PI_4; // pi/4
/// pi/2 — mirrors `M_HALFPI` from proj_internal.h.
pub const M_HALFPI: f64 = M_PI_2; // pi/2
/// 1.5*pi — mirrors `M_PI_HALFPI` from proj_internal.h.
pub const M_PI_HALFPI: f64 = 4.712_388_980_384_69; // 1.5*pi
/// 2*pi (a full turn in radians) — mirrors `M_TWOPI` from proj_internal.h.
pub const M_TWOPI: f64 = core::f64::consts::TAU; // 2*pi
/// 2/pi — mirrors `M_TWO_D_PI` from proj_internal.h.
pub const M_TWO_D_PI: f64 = M_2_PI; // 2/pi
/// 2.5*pi — mirrors `M_TWOPI_HALFPI` from proj_internal.h.
pub const M_TWOPI_HALFPI: f64 = 7.853981633974483; // 2.5*pi
/// Conversion factor from radians to degrees (`180/pi`).
pub const RAD_TO_DEG: f64 = 57.295_779_513_082_32;
/// Conversion factor from degrees to radians (`pi/180`).
pub const DEG_TO_RAD: f64 = 0.017453292519943296;
/// Conversion factor from arc-seconds to radians (the standard PROJ value).
pub const SEC_TO_RAD: f64 = 4.84813681109535993589914102357e-6; // arcsec->rad (standard PROJ value)

#[cfg(test)]
mod tests {
    use super::*;
    use core::f64::consts::PI;

    #[test]
    fn m_pi_matches_std() {
        assert!((M_PI - PI).abs() < 1e-15);
    }

    #[test]
    fn m_pi_2_matches_half_pi() {
        assert!((M_PI_2 - PI / 2.0).abs() < 1e-15);
    }

    #[test]
    fn m_pi_4_matches_quarter_pi() {
        assert!((M_PI_4 - PI / 4.0).abs() < 1e-15);
    }

    #[test]
    fn deg_to_rad_round_trip() {
        assert!((DEG_TO_RAD * 180.0 - PI).abs() < 1e-6);
    }

    #[test]
    fn rad_to_deg_matches() {
        assert!((RAD_TO_DEG - 180.0 / PI).abs() < 1e-6);
    }

    #[test]
    fn m_twopi_matches_two_pi() {
        assert!((M_TWOPI - 2.0 * PI).abs() < 1e-15);
    }

    #[test]
    fn m_sqrt2_matches_sqrt_two() {
        assert!((M_SQRT2 - 2.0_f64.sqrt()).abs() < 1e-15);
    }
}