pub struct BathymetryData {
pub resolutionarcsec: f64,
pub data: Vec<f64>,
pub rows: usize,
pub cols: usize,
}
impl BathymetryData {
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 elev = crate::terrain::heightmap::earthelevation(lat, lon);
data[r * cols + c] = if elev < 0.0 { elev } else { 0.0 };
}
}
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 isocean(&self, latdeg: f64, londeg: f64) -> bool {
self.sample(latdeg, londeg) < 0.0
}
pub fn oceanstats() -> OceanBasinStats {
OceanBasinStats {
avgdepthm: 3688.0,
maxdepthm: 10994.0,
totalvolumekm3: 1335000000.0,
surfaceareakm2: 361132000.0,
}
}
}
pub struct OceanBasinStats {
pub avgdepthm: f64,
pub maxdepthm: f64,
pub totalvolumekm3: f64,
pub surfaceareakm2: f64,
}
pub struct OceanBasin {
pub name: String,
pub avgdepthm: f64,
pub maxdepthm: f64,
pub areakm2: f64,
}
impl OceanBasin {
pub fn majorbasins() -> Vec<Self> {
vec![
Self {
name: "Pacific".into(),
avgdepthm: 4280.0,
maxdepthm: 10994.0,
areakm2: 165250000.0,
},
Self {
name: "Atlantic".into(),
avgdepthm: 3646.0,
maxdepthm: 8376.0,
areakm2: 106460000.0,
},
Self {
name: "Indian".into(),
avgdepthm: 3741.0,
maxdepthm: 7906.0,
areakm2: 70560000.0,
},
Self {
name: "Southern".into(),
avgdepthm: 3270.0,
maxdepthm: 7236.0,
areakm2: 21960000.0,
},
Self {
name: "Arctic".into(),
avgdepthm: 1205.0,
maxdepthm: 5550.0,
areakm2: 14060000.0,
},
]
}
}