Implement operator overloads for Angle type
This commit is contained in:
parent
287fae7114
commit
035d9e751a
1 changed files with 60 additions and 0 deletions
60
src/angle.rs
60
src/angle.rs
|
@ -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> {
|
pub struct AxisRotation<T> {
|
||||||
axis: Vec3<T>,
|
axis: Vec3<T>,
|
||||||
theta: Angle<T>,
|
theta: Angle<T>,
|
||||||
|
|
Loading…
Reference in a new issue