use std::f64::consts::PI;

#[derive(Debug, Clone, Copy, PartialEq)]
pub struct Impactor {
    pub diameter_m: f64,
    pub density_kg_m3: f64,
    pub velocity_m_s: f64,
    pub impact_angle_deg: f64,
}

impl Impactor {
    pub fn new(
        diameter_m: f64,
        density_kg_m3: f64,
        velocity_m_s: f64,
        impact_angle_deg: f64,
    ) -> Self {
        Self {
            diameter_m,
            density_kg_m3,
            velocity_m_s,
            impact_angle_deg,
        }
    }
    pub fn mass_kg(&self) -> f64 {
        let r = self.diameter_m * 0.5;
        (4.0 / 3.0) * PI * r.powi(3) * self.density_kg_m3
    }
    pub fn kinetic_energy_j(&self) -> f64 {
        0.5 * self.mass_kg() * self.velocity_m_s.powi(2)
    }
    pub fn transient_crater_diameter_m(&self) -> f64 {
        let angle_factor = self.impact_angle_deg.to_radians().sin().max(0.2);
        18.0 * self.diameter_m.powf(0.78) * (self.velocity_m_s / 1_000.0).powf(0.44) * angle_factor
    }
}

pub fn micrometeorite() -> Impactor {
    Impactor::new(0.001, 3_000.0, 20_000.0, 45.0)
}
pub fn basin_forming_impactor() -> Impactor {
    Impactor::new(30_000.0, 2_700.0, 15_000.0, 50.0)
}
