From 035d9e751a71390d69d91472e02c9ca7c68a4084 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Mon, 26 Nov 2012 03:43:48 +1000 Subject: [PATCH] Implement operator overloads for Angle type --- src/angle.rs | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/angle.rs b/src/angle.rs index 2353c58..c43a078 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -22,6 +22,66 @@ pub impl Angle { } } +pub impl Angle: Add> { + #[inline(always)] + pure fn add(rhs: &T) -> Angle { + match self { + degrees(theta) => degrees(theta + *rhs), + radians(theta) => radians(theta + *rhs) + } + } +} + +pub impl Angle: Sub> { + #[inline(always)] + pure fn sub(rhs: &T) -> Angle { + match self { + degrees(theta) => degrees(theta - *rhs), + radians(theta) => radians(theta - *rhs) + } + } +} + +pub impl Angle: Mul> { + #[inline(always)] + pure fn mul(rhs: &T) -> Angle { + match self { + degrees(theta) => degrees(theta * *rhs), + radians(theta) => radians(theta * *rhs) + } + } +} + +pub impl Angle: Div> { + #[inline(always)] + pure fn div(rhs: &T) -> Angle { + match self { + degrees(theta) => degrees(theta / *rhs), + radians(theta) => radians(theta / *rhs) + } + } +} + +pub impl Angle: Modulo> { + #[inline(always)] + pure fn modulo(rhs: &T) -> Angle { + match self { + degrees(theta) => degrees(theta % *rhs), + radians(theta) => radians(theta % *rhs) + } + } +} + +pub impl Angle: Neg> { + #[inline(always)] + pure fn neg() -> Angle { + match self { + degrees(theta) => degrees(-theta), + radians(theta) => radians(-theta) + } + } +} + pub struct AxisRotation { axis: Vec3, theta: Angle,