Implement Eq and Ord on angle types

This commit is contained in:
Brendan Zabarauskas 2012-11-26 16:23:34 +10:00
parent c3e43b9b9b
commit 7bc7565f56

View file

@ -1,3 +1,4 @@
use core::cmp::{Eq, Ord};
use core::f64::consts::pi; use core::f64::consts::pi;
use num::cast::*; use num::cast::*;
use vec::Vec3; use vec::Vec3;
@ -7,7 +8,8 @@ pub trait Angle<T>: Add<self,self>
, Mul<T,self> , Mul<T,self>
, Div<T,self> , Div<T,self>
, Modulo<T,self> , Modulo<T,self>
, Neg<self> { , Neg<self>
, Eq, Ord {
pure fn to_radians() -> Radians<T>; pure fn to_radians() -> Radians<T>;
pure fn to_degrees() -> Degrees<T>; pure fn to_degrees() -> Degrees<T>;
} }
@ -26,6 +28,18 @@ pub impl<T:Copy Num NumCast> Radians<T>: Angle<T> {
#[inline(always)] pure fn neg() -> Radians<T> { Radians(-*self) } #[inline(always)] pure fn neg() -> Radians<T> { Radians(-*self) }
} }
pub impl<T:Copy Eq> Radians<T>: Eq {
#[inline(always)] pure fn eq(other: &Radians<T>) -> bool { *self == **other }
#[inline(always)] pure fn ne(other: &Radians<T>) -> bool { *self != **other }
}
pub impl<T:Copy Ord> Radians<T>: Ord {
#[inline(always)] pure fn lt(other: &Radians<T>) -> bool { *self < **other }
#[inline(always)] pure fn le(other: &Radians<T>) -> bool { *self <= **other }
#[inline(always)] pure fn ge(other: &Radians<T>) -> bool { *self >= **other }
#[inline(always)] pure fn gt(other: &Radians<T>) -> bool { *self > **other }
}
pub enum Degrees<T> = T; pub enum Degrees<T> = T;
pub impl<T:Copy Num NumCast> Degrees<T>: Angle<T> { pub impl<T:Copy Num NumCast> Degrees<T>: Angle<T> {
@ -40,6 +54,18 @@ pub impl<T:Copy Num NumCast> Degrees<T>: Angle<T> {
#[inline(always)] pure fn neg() -> Degrees<T> { Degrees(-*self) } #[inline(always)] pure fn neg() -> Degrees<T> { Degrees(-*self) }
} }
pub impl<T:Copy Eq> Degrees<T>: Eq {
#[inline(always)] pure fn eq(other: &Degrees<T>) -> bool { *self == **other }
#[inline(always)] pure fn ne(other: &Degrees<T>) -> bool { *self != **other }
}
pub impl<T:Copy Ord> Degrees<T>: Ord {
#[inline(always)] pure fn lt(other: &Degrees<T>) -> bool { *self < **other }
#[inline(always)] pure fn le(other: &Degrees<T>) -> bool { *self <= **other }
#[inline(always)] pure fn ge(other: &Degrees<T>) -> bool { *self >= **other }
#[inline(always)] pure fn gt(other: &Degrees<T>) -> bool { *self > **other }
}
pub struct AxialRotation<T> { pub struct AxialRotation<T> {
axis: Vec3<T>, axis: Vec3<T>,
theta: Radians<T>, theta: Radians<T>,