venuss 0.0.1

Venus celestial simulation crate for the MilkyWay SolarSystem workspace
Documentation
pub const UNIX_EPOCH_JD: f64 = 2440587.5;
pub const SECONDS_PER_DAY: f64 = 86400.0;

#[derive(Debug, Clone, Copy)]
pub struct VenusDate {
    pub year: i32,
    pub day_of_year: f64,
}

impl VenusDate {
    pub fn new(year: i32, day_of_year: f64) -> Self {
        Self { year, day_of_year }
    }

    pub fn ls_deg(&self) -> f64 {
        (self.day_of_year / crate::VENUS_YEAR_DAYS * 360.0) % 360.0
    }

    pub fn to_julian_date(&self) -> f64 {
        super::epoch::J2000_EPOCH
            + ((self.year as f64 - 2000.0) * crate::VENUS_YEAR_DAYS + self.day_of_year)
    }

    pub fn from_julian_date(jd: f64) -> Self {
        let days = jd - super::epoch::J2000_EPOCH;
        let venus_years = (days / crate::VENUS_YEAR_DAYS).floor();
        let year = 2000 + venus_years as i32;
        let day_of_year = days - venus_years * crate::VENUS_YEAR_DAYS;
        Self { year, day_of_year }
    }

    pub fn to_unix_timestamp(&self) -> f64 {
        (self.to_julian_date() - UNIX_EPOCH_JD) * SECONDS_PER_DAY
    }

    pub fn from_unix_timestamp(ts: f64) -> Self {
        Self::from_julian_date(ts / SECONDS_PER_DAY + UNIX_EPOCH_JD)
    }
}