use std::{f64::consts::PI, ops::*};
#[derive(Copy, Clone, PartialEq, Default, Debug)]
pub struct Angle(f64);
impl Deref for Angle {
type Target = f64;
fn deref(&self) -> &f64 {
&self.0
}
}
impl Neg for Angle {
type Output = Angle;
fn neg(self) -> Angle {
Angle(self.0.neg())
}
}
impl Neg for &Angle {
type Output = Angle;
fn neg(self) -> Angle {
Angle(self.0.neg())
}
}
impl Add<Angle> for Angle {
type Output = Angle;
fn add(self, rhs: Angle) -> Self::Output {
Angle(self.0.add(rhs.0))
}
}
impl Add<&Angle> for Angle {
type Output = Angle;
fn add(self, rhs: &Angle) -> Self::Output {
Angle(self.0.add(rhs.0))
}
}
impl Add<Angle> for &Angle {
type Output = Angle;
fn add(self, rhs: Angle) -> Self::Output {
Angle(self.0.add(rhs.0))
}
}
impl Add<&Angle> for &Angle {
type Output = Angle;
fn add(self, rhs: &Angle) -> Self::Output {
Angle(self.0.add(rhs.0))
}
}
impl Sub<Angle> for Angle {
type Output = Angle;
fn sub(self, rhs: Angle) -> Self::Output {
Angle(self.0.sub(rhs.0))
}
}
impl Sub<&Angle> for Angle {
type Output = Angle;
fn sub(self, rhs: &Angle) -> Self::Output {
Angle(self.0.sub(rhs.0))
}
}
impl Sub<Angle> for &Angle {
type Output = Angle;
fn sub(self, rhs: Angle) -> Self::Output {
Angle(self.0.sub(rhs.0))
}
}
impl Sub<&Angle> for &Angle {
type Output = Angle;
fn sub(self, rhs: &Angle) -> Self::Output {
Angle(self.0.sub(rhs.0))
}
}
impl Mul<f64> for Angle {
type Output = Angle;
fn mul(self, rhs: f64) -> Self::Output {
Angle(self.0.mul(rhs))
}
}
impl Mul<&f64> for Angle {
type Output = Angle;
fn mul(self, rhs: &f64) -> Self::Output {
Angle(self.0.mul(rhs))
}
}
impl Mul<f64> for &Angle {
type Output = Angle;
fn mul(self, rhs: f64) -> Self::Output {
Angle(self.0.mul(rhs))
}
}
impl Mul<&f64> for &Angle {
type Output = Angle;
fn mul(self, rhs: &f64) -> Self::Output {
Angle(self.0.mul(rhs))
}
}
impl Div<f64> for Angle {
type Output = Angle;
fn div(self, rhs: f64) -> Self::Output {
Angle(self.0.div(rhs))
}
}
impl Div<&f64> for Angle {
type Output = Angle;
fn div(self, rhs: &f64) -> Self::Output {
Angle(self.0.div(rhs))
}
}
impl Div<f64> for &Angle {
type Output = Angle;
fn div(self, rhs: f64) -> Self::Output {
Angle(self.0.div(rhs))
}
}
impl Div<&f64> for &Angle {
type Output = Angle;
fn div(self, rhs: &f64) -> Self::Output {
Angle(self.0.div(rhs))
}
}
impl AddAssign<Angle> for Angle {
fn add_assign(&mut self, rhs: Angle) {
self.0.add_assign(rhs.0);
}
}
impl AddAssign<&Angle> for Angle {
fn add_assign(&mut self, rhs: &Angle) {
self.0.add_assign(rhs.0);
}
}
impl SubAssign<Angle> for Angle {
fn sub_assign(&mut self, rhs: Angle) {
self.0.sub_assign(rhs.0);
}
}
impl SubAssign<&Angle> for Angle {
fn sub_assign(&mut self, rhs: &Angle) {
self.0.sub_assign(rhs.0);
}
}
impl<T> From<T> for Angle
where
f64: From<T>,
{
fn from(angle: T) -> Self {
Self(angle.into())
}
}
pub trait Angular {
fn rad(self) -> Angle;
fn deg(self) -> Angle;
}
impl<T> Angular for T
where
T: Into<f64>,
{
fn rad(self) -> Angle {
Angle(self.into())
}
fn deg(self) -> Angle {
Angle(self.into() * PI / 180.0)
}
}