use core::cmp::{Eq, Ord}; use core::f64::consts::pi; use num::cast::*; use vec::Vec3; pub trait Angle: Add , Sub , Mul , Div , Modulo , Neg , Eq, Ord { pure fn to_radians() -> Radians; pure fn to_degrees() -> Degrees; } pub enum Radians = T; pub impl Radians: Angle { #[inline(always)] pure fn to_radians() -> Radians { self } #[inline(always)] pure fn to_degrees() -> Degrees { Degrees(*self * cast(180.0 / pi)) } #[inline(always)] pure fn add(rhs: &Radians) -> Radians { Radians(*self + **rhs) } #[inline(always)] pure fn sub(rhs: &Radians) -> Radians { Radians(*self - **rhs) } #[inline(always)] pure fn mul(rhs: &T) -> Radians { Radians(*self * *rhs) } #[inline(always)] pure fn div(rhs: &T) -> Radians { Radians(*self / *rhs) } #[inline(always)] pure fn modulo(rhs: &T) -> Radians { Radians(*self % *rhs) } #[inline(always)] pure fn neg() -> Radians { Radians(-*self) } } pub impl Radians: Eq { #[inline(always)] pure fn eq(other: &Radians) -> bool { *self == **other } #[inline(always)] pure fn ne(other: &Radians) -> bool { *self != **other } } pub impl Radians: Ord { #[inline(always)] pure fn lt(other: &Radians) -> bool { *self < **other } #[inline(always)] pure fn le(other: &Radians) -> bool { *self <= **other } #[inline(always)] pure fn ge(other: &Radians) -> bool { *self >= **other } #[inline(always)] pure fn gt(other: &Radians) -> bool { *self > **other } } pub enum Degrees = T; pub impl Degrees: Angle { #[inline(always)] pure fn to_radians() -> Radians { Radians(*self * cast(pi / 180.0)) } #[inline(always)] pure fn to_degrees() -> Degrees { self } #[inline(always)] pure fn add(rhs: &Degrees) -> Degrees { Degrees(*self + **rhs) } #[inline(always)] pure fn sub(rhs: &Degrees) -> Degrees { Degrees(*self - **rhs) } #[inline(always)] pure fn mul(rhs: &T) -> Degrees { Degrees(*self * *rhs) } #[inline(always)] pure fn div(rhs: &T) -> Degrees { Degrees(*self / *rhs) } #[inline(always)] pure fn modulo(rhs: &T) -> Degrees { Degrees(*self % *rhs) } #[inline(always)] pure fn neg() -> Degrees { Degrees(-*self) } } pub impl Degrees: Eq { #[inline(always)] pure fn eq(other: &Degrees) -> bool { *self == **other } #[inline(always)] pure fn ne(other: &Degrees) -> bool { *self != **other } } pub impl Degrees: Ord { #[inline(always)] pure fn lt(other: &Degrees) -> bool { *self < **other } #[inline(always)] pure fn le(other: &Degrees) -> bool { *self <= **other } #[inline(always)] pure fn ge(other: &Degrees) -> bool { *self >= **other } #[inline(always)] pure fn gt(other: &Degrees) -> bool { *self > **other } } pub struct AxialRotation { axis: Vec3, theta: Radians, } pub struct Euler { x: Radians, // pitch y: Radians, // yaw z: Radians, // roll }