gemath 0.1.0

Type-safe game math with type-level units/spaces, typed angles, and explicit fallible ops (plus optional geometry/collision).
Documentation
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Default)]
pub struct Degrees(pub f32);
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[cfg_attr(feature = "serde", serde(transparent))]
#[derive(Copy, Clone, Debug, PartialEq, PartialOrd, Default)]
pub struct Radians(pub f32);

impl Degrees {
    pub fn to_radians(self) -> Radians {
        Radians(crate::scalar::to_radians(self.0))
    }
}
impl Radians {
    pub fn to_degrees(self) -> Degrees {
        Degrees(crate::scalar::to_degrees(self.0))
    }
}

impl From<Degrees> for Radians {
    fn from(deg: Degrees) -> Self {
        deg.to_radians()
    }
}
impl From<Radians> for Degrees {
    fn from(rad: Radians) -> Self {
        rad.to_degrees()
    }
}

impl core::fmt::Display for Degrees {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{}°", self.0)
    }
}
impl core::fmt::Display for Radians {
    fn fmt(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
        write!(f, "{} rad", self.0)
    }
}