Implement operator overloads for Angle type

This commit is contained in:
Brendan Zabarauskas 2012-11-26 03:43:48 +10:00
parent 287fae7114
commit 035d9e751a

View file

@ -22,6 +22,66 @@ pub impl<T:Copy Num NumCast> Angle<T> {
}
}
pub impl<T:Copy Num> Angle<T>: Add<T,Angle<T>> {
#[inline(always)]
pure fn add(rhs: &T) -> Angle<T> {
match self {
degrees(theta) => degrees(theta + *rhs),
radians(theta) => radians(theta + *rhs)
}
}
}
pub impl<T:Copy Num> Angle<T>: Sub<T,Angle<T>> {
#[inline(always)]
pure fn sub(rhs: &T) -> Angle<T> {
match self {
degrees(theta) => degrees(theta - *rhs),
radians(theta) => radians(theta - *rhs)
}
}
}
pub impl<T:Copy Num> Angle<T>: Mul<T,Angle<T>> {
#[inline(always)]
pure fn mul(rhs: &T) -> Angle<T> {
match self {
degrees(theta) => degrees(theta * *rhs),
radians(theta) => radians(theta * *rhs)
}
}
}
pub impl<T:Copy Num> Angle<T>: Div<T,Angle<T>> {
#[inline(always)]
pure fn div(rhs: &T) -> Angle<T> {
match self {
degrees(theta) => degrees(theta / *rhs),
radians(theta) => radians(theta / *rhs)
}
}
}
pub impl<T:Copy Num> Angle<T>: Modulo<T,Angle<T>> {
#[inline(always)]
pure fn modulo(rhs: &T) -> Angle<T> {
match self {
degrees(theta) => degrees(theta % *rhs),
radians(theta) => radians(theta % *rhs)
}
}
}
pub impl<T:Copy Num> Angle<T>: Neg<Angle<T>> {
#[inline(always)]
pure fn neg() -> Angle<T> {
match self {
degrees(theta) => degrees(-theta),
radians(theta) => radians(-theta)
}
}
}
pub struct AxisRotation<T> {
axis: Vec3<T>,
theta: Angle<T>,