#[derive(Debug, Clone, Copy, PartialEq)]
pub struct LodConfig {
    pub min_level: u8,
    pub max_level: u8,
    pub switch_distance_m: f64,
}

impl Default for LodConfig {
    fn default() -> Self {
        Self {
            min_level: 2,
            max_level: 14,
            switch_distance_m: 80_000.0,
        }
    }
}

pub fn lod_level(config: LodConfig, camera_distance_m: f64) -> u8 {
    let scaled = (config.switch_distance_m / camera_distance_m.max(1.0)).log2();
    let level = config.min_level as f64 + scaled.max(0.0);
    level
        .clamp(config.min_level as f64, config.max_level as f64)
        .round() as u8
}
