use crate::{Float, Numeric, Primitive}; pub trait Angular: From> + From> { fn degree(&self) -> T; fn radiant(&self) -> T; } #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] #[repr(transparent)] pub struct Degree { value: T, } impl Degree { pub fn new(value: T) -> Self { Self { value } } } impl From> for Degree { fn from(source: Radiant) -> Self { Degree::new(source.value * T::pi() / unsafe { T::whole(180) }) } } impl Angular for Degree { fn degree(&self) -> T { self.value } fn radiant(&self) -> T { Radiant::from(*self).value } } #[derive(Debug, Copy, Clone, PartialEq, PartialOrd)] #[repr(transparent)] pub struct Radiant { value: T, } impl Radiant { pub fn new(value: T) -> Self { Self { value } } } impl From> for Radiant { fn from(source: Degree) -> Self { Radiant::new(source.value * unsafe { T::whole(180) } / T::pi()) } } impl Angular for Radiant { fn degree(&self) -> T { Degree::from(*self).value } fn radiant(&self) -> T { self.value } }