jupiters 0.0.3

Jupiter celestial simulation crate for the MilkyWay SolarSystem workspace
Documentation
pub struct InteriorLayerData {
    pub resolutionarcsec: f64,
    pub data: Vec<f64>,
    pub rows: usize,
    pub cols: usize,
}

impl InteriorLayerData {
    pub fn global(resolutionarcsec: f64) -> Self {
        let effectiveres = resolutionarcsec.max(600.0);
        let rows = (180.0 * 3600.0 / effectiveres) as usize;
        let cols = (360.0 * 3600.0 / effectiveres) as usize;
        let mut data = vec![0.0; rows * cols];
        for r in 0..rows {
            for c in 0..cols {
                let lat = 90.0 - (r as f64 + 0.5) * effectiveres / 3600.0;
                let lon = -180.0 + (c as f64 + 0.5) * effectiveres / 3600.0;
                let depth = interiorlayerdepthkm(lat, lon);
                data[r * cols + c] = depth;
            }
        }
        Self {
            resolutionarcsec: effectiveres,
            data,
            rows,
            cols,
        }
    }

    pub fn sample(&self, latdeg: f64, londeg: f64) -> f64 {
        let latfrac = (latdeg + 90.0) / 180.0;
        let lonfrac = (londeg + 180.0) / 360.0;
        let row =
            ((1.0 - latfrac) * (self.rows - 1) as f64).clamp(0.0, (self.rows - 1) as f64) as usize;
        let col = (lonfrac * (self.cols - 1) as f64).clamp(0.0, (self.cols - 1) as f64) as usize;
        self.data.get(row * self.cols + col).copied().unwrap_or(0.0)
    }

    pub fn ismetallichydrogen(&self, latdeg: f64, londeg: f64) -> bool {
        self.sample(latdeg, londeg) < -20000.0
    }

    pub fn interiorstats() -> InteriorStats {
        InteriorStats {
            atmospheredepthkm: 1000.0,
            metallichydrogendepthkm: 50000.0,
            coreradiuskm: 15000.0,
            totalradiuskm: 69911.0,
        }
    }
}

pub struct InteriorStats {
    pub atmospheredepthkm: f64,
    pub metallichydrogendepthkm: f64,
    pub coreradiuskm: f64,
    pub totalradiuskm: f64,
}

pub struct InteriorLayer {
    pub name: String,
    pub outerboundarykm: f64,
    pub innerboundarykm: f64,
    pub avgdensitykgm3: f64,
}

impl InteriorLayer {
    pub fn majorlayers() -> Vec<Self> {
        vec![
            Self {
                name: "Upper Atmosphere".into(),
                outerboundarykm: 71492.0,
                innerboundarykm: 71442.0,
                avgdensitykgm3: 0.16,
            },
            Self {
                name: "Molecular Hydrogen Envelope".into(),
                outerboundarykm: 71442.0,
                innerboundarykm: 60000.0,
                avgdensitykgm3: 120.0,
            },
            Self {
                name: "Metallic Hydrogen Layer".into(),
                outerboundarykm: 60000.0,
                innerboundarykm: 15000.0,
                avgdensitykgm3: 1000.0,
            },
            Self {
                name: "Rock-Ice Core".into(),
                outerboundarykm: 15000.0,
                innerboundarykm: 0.0,
                avgdensitykgm3: 20000.0,
            },
        ]
    }
}

fn interiorlayerdepthkm(lat: f64, lon: f64) -> f64 {
    let base = -20000.0;
    let latmod = 1500.0 * (2.0 * lat.to_radians()).cos();
    let lonmod = 500.0 * (3.0 * lon.to_radians()).sin();
    base + latmod + lonmod
}