#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Biome {
Ocean,
Beach,
Desert,
Grassland,
Forest,
Taiga,
Tundra,
Snow,
Mountain,
Volcanic,
}
pub struct SplatWeights {
pub weights: [(Biome, f32); 4],
}
pub struct BiomeClassifier {
pub sea_level: f64,
}
impl Default for BiomeClassifier {
fn default() -> Self {
Self { sea_level: 0.0 }
}
}
impl BiomeClassifier {
pub fn classify(&self, elevation_m: f64, latitude_deg: f64, moisture: f64) -> Biome {
if elevation_m < self.sea_level {
return Biome::Ocean;
}
if elevation_m < self.sea_level + 10.0 {
return Biome::Beach;
}
if elevation_m > 4000.0 {
return Biome::Snow;
}
if elevation_m > 2500.0 {
return Biome::Mountain;
}
let abs_lat = latitude_deg.abs();
if abs_lat > 70.0 {
return Biome::Tundra;
}
if abs_lat > 55.0 {
return Biome::Taiga;
}
if moisture < 0.2 {
return Biome::Desert;
}
if moisture > 0.6 {
return Biome::Forest;
}
Biome::Grassland
}
pub fn splat(&self, elevation_m: f64, latitude_deg: f64, moisture: f64) -> SplatWeights {
let primary = self.classify(elevation_m, latitude_deg, moisture);
SplatWeights {
weights: [
(primary, 1.0),
(Biome::Ocean, 0.0),
(Biome::Ocean, 0.0),
(Biome::Ocean, 0.0),
],
}
}
}