use crate::config::parameters::*;

pub fn gravitational_binding_energy(mass: f64, radius: f64) -> f64 {
    3.0 * G * mass * mass / (5.0 * radius)
}

pub fn roche_limit_fluid(r_primary: f64, rho_primary: f64, rho_secondary: f64) -> f64 {
    2.456 * r_primary * (rho_primary / rho_secondary).powf(1.0 / 3.0)
}

pub fn roche_limit_rigid(r_primary: f64, rho_primary: f64, rho_secondary: f64) -> f64 {
    1.26 * r_primary * (rho_primary / rho_secondary).powf(1.0 / 3.0)
}

pub fn tidal_force(m_central: f64, r_body: f64, distance: f64) -> f64 {
    2.0 * G * m_central * r_body / (distance * distance * distance)
}

pub fn specific_angular_momentum(semi_major: f64, ecc: f64, central_mass: f64) -> f64 {
    (G * central_mass * semi_major * (1.0 - ecc * ecc)).sqrt()
}

pub fn orbital_energy(mass_body: f64, central_mass: f64, semi_major: f64) -> f64 {
    -G * central_mass * mass_body / (2.0 * semi_major)
}

pub fn close_approach_velocity(v_infinity: f64, mass_body: f64, radius_body: f64) -> f64 {
    (v_infinity * v_infinity + 2.0 * G * mass_body / radius_body).sqrt()
}
