use bone_types::Length;
use uom::si::length::millimeter;

#[derive(Copy, Clone, Debug, PartialEq, PartialOrd)]
pub struct Curvature(f64);

impl Curvature {
    pub const ZERO: Self = Self(0.0);

    #[must_use]
    pub fn from_radius(radius: Length) -> Self {
        Self(1.0 / radius.get::<millimeter>())
    }

    #[must_use]
    pub const fn value_per_mm(self) -> f64 {
        self.0
    }

    #[must_use]
    pub fn with_sign(self, sign: f64) -> Self {
        Self(self.0 * sign.signum())
    }
}

impl core::fmt::Display for Curvature {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "k={}/mm", self.0)
    }
}
