use std::{ops::Add, f32::consts::PI};
use num_traits::Float;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub struct Angle<N: Float> {
radians: N
}
impl<N: Float> Angle<N> {
pub fn from_radians(radians: N) -> Angle<N> {
Angle { radians }
}
pub fn get_radians(&self) -> N {
self.radians
}
}
impl Angle<f32> {
pub fn from_degrees(degrees: f32) -> Angle<f32> {
Angle {
radians: degrees * (PI/180.0f32)
}
}
pub fn get_degrees(&self) -> f32 {
self.radians * (180.0f32/PI)
}
}
impl<N: Float> Add for Angle<N> {
type Output = Self;
fn add(self, rhs: Self) -> Self::Output {
Angle {
radians: self.radians + rhs.radians
}
}
}