use std::f64::consts::PI as fPI;
use std::ops::{Add, Sub, Mul, Div, Rem, Neg};
use interpolation::Spatial;
pub const PI: Radians = Radians(fPI);
pub const TWO_PI: Radians = Radians(2.*fPI);
pub const ZERO: Radians = Radians(0.0);
#[derive(Default, Clone, Copy, Debug, PartialOrd, PartialEq)]
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())
}
#[inline(always)]
pub fn to_radians(&self) -> f64 {
self.0
}
#[inline(always)]
pub fn to_degrees(&self) -> f64 {
self.0.to_degrees()
}
#[inline(always)]
pub fn cos(self) -> f64 {
self.0.cos()
}
#[inline(always)]
pub fn sin(self) -> f64 {
self.0.sin()
}
#[inline(always)]
pub fn is_infinite(self) -> bool {
self.0.is_infinite()
}
#[inline(always)]
pub fn is_nan(self) -> bool {
self.0.is_infinite()
}
#[inline(always)]
pub fn signum(self) -> f64 {
self.0.signum()
}
#[inline(always)]
pub fn abs(self) -> Self {
Radians(self.0.abs())
}
}
impl Spatial for Radians {
type Scalar = f64;
#[inline(always)]
fn add(&self, other: &Self) -> Self {
*self + *other
}
#[inline(always)]
fn sub(&self, other: &Self) -> Self {
*self - *other
}
#[inline(always)]
fn scale(&self, other: &Self::Scalar) -> Self {
*self * *other
}
}
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)
}
}