asteroidsfactory 0.0.3

Asteroid factory — classify, build and catalogue asteroids of any type: near-Earth, main belt, trojan, centaur, binary, rubble pile, metallic, and potentially hazardous.
Documentation
use crate::config::parameters::PI;

pub fn degrees_to_radians(deg: f64) -> f64 {
    deg * PI / 180.0
}

pub fn radians_to_degrees(rad: f64) -> f64 {
    rad * 180.0 / PI
}

pub fn clamp_positive(x: f64) -> f64 {
    if x > 0.0 { x } else { 0.0 }
}

pub fn log10_safe(x: f64) -> f64 {
    if x > 0.0 {
        x.log10()
    } else {
        f64::NEG_INFINITY
    }
}

pub fn lerp(a: f64, b: f64, t: f64) -> f64 {
    a + (b - a) * t
}

pub fn spherical_to_cartesian(r: f64, theta: f64, phi: f64) -> (f64, f64, f64) {
    let x = r * theta.sin() * phi.cos();
    let y = r * theta.sin() * phi.sin();
    let z = r * theta.cos();
    (x, y, z)
}