use std::f64::consts::PI as fPI;
use std::ops::{Add, Div, Mul, Neg, Rem, Sub};
use serde::{Serialize, Deserialize};
use interpolation::Lerp;
pub const PI: Radians = Radians(fPI);
pub const TWO_PI: Radians = Radians(2. * fPI);
#[cfg_attr(any(feature = "test", test), allow(dead_code))]
pub const ZERO: Radians = Radians(0.0);
#[derive(Default, Clone, Copy, Debug, PartialOrd, PartialEq, Serialize, Deserialize)]
pub struct Radians(f64);
impl Radians {
pub fn from_radians_value(radians: f64) -> Radians {
Radians(radians)
}
pub fn from_degrees_value(degrees: f64) -> Radians {
Radians(degrees.to_radians())
}
pub fn to_radians(self) -> f64 {
self.0
}
pub fn to_degrees(self) -> f64 {
self.0.to_degrees()
}
pub fn cos(self) -> f64 {
self.0.cos()
}
pub fn sin(self) -> f64 {
self.0.sin()
}
pub fn is_normal(self) -> bool {
self.0.is_normal()
}
pub fn is_nan(self) -> bool {
self.0.is_nan()
}
pub fn signum(self) -> f64 {
self.0.signum()
}
pub fn abs(self) -> Self {
Radians(self.0.abs())
}
pub fn floor(self) -> Self {
Radians(self.0.floor())
}
}
impl Lerp for Radians {
type Scalar = f64;
#[inline(always)]
fn lerp(&self, other: &Self, scalar: &Self::Scalar) -> Self {
Radians(self.0.lerp(&other.0, &scalar))
}
}
impl Add for Radians {
type Output = Self;
fn add(self, other: Self) -> Self {
Radians(self.0 + other.0)
}
}
impl Sub for Radians {
type Output = Self;
fn sub(self, other: Self) -> Self {
Radians(self.0 - other.0)
}
}
impl Mul for Radians {
type Output = Self;
fn mul(self, other: Self) -> Self {
Radians(self.0 * other.0)
}
}
impl Mul<f64> for Radians {
type Output = Self;
fn mul(self, other: f64) -> Self {
Radians(self.0 * other)
}
}
impl Mul<Radians> for f64 {
type Output = Radians;
fn mul(self, other: Radians) -> Radians {
Radians(self * other.0)
}
}
impl Div for Radians {
type Output = Self;
fn div(self, other: Self) -> Self {
Radians(self.0 / other.0)
}
}
impl Div<f64> for Radians {
type Output = Self;
fn div(self, other: f64) -> Self {
Radians(self.0 / other)
}
}
impl Rem for Radians {
type Output = Self;
fn rem(self, other: Self) -> Self {
Radians(self.0 % other.0)
}
}
impl Neg for Radians {
type Output = Self;
fn neg(self) -> Self {
Radians(-self.0)
}
}