From 9cd7f71875a125f654a48245569f6c4cbb1c54de Mon Sep 17 00:00:00 2001 From: Pierre Krieger Date: Fri, 8 May 2015 16:40:22 +0200 Subject: [PATCH] Make functions in angle.rs more generic --- src/angle.rs | 49 ++++++++++++++++++++++++++----------------------- 1 file changed, 26 insertions(+), 23 deletions(-) diff --git a/src/angle.rs b/src/angle.rs index dbb0a5e..4b05b3e 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -182,30 +182,32 @@ Deg { } -impl Add for Rad { +impl>, S: BaseFloat> Add for Rad { type Output = Rad; #[inline] - fn add(self, other: Rad) -> Rad { rad(self.s + other.s) } + fn add(self, other: R) -> Rad { rad(self.s + other.into().s) } } -impl Add for Deg { + +impl>, S: BaseFloat> Add for Deg { type Output = Deg; #[inline] - fn add(self, other: Deg) -> Deg { deg(self.s + other.s) } + fn add(self, other: R) -> Deg { deg(self.s + other.into().s) } } -impl Sub for Rad { +impl>, S: BaseFloat> Sub for Rad { type Output = Rad; #[inline] - fn sub(self, other: Rad) -> Rad { rad(self.s - other.s) } + fn sub(self, other: R) -> Rad { rad(self.s - other.into().s) } } -impl Sub for Deg { + +impl>, S: BaseFloat> Sub for Deg { type Output = Deg; #[inline] - fn sub(self, other: Deg) -> Deg { deg(self.s - other.s) } + fn sub(self, other: R) -> Deg { deg(self.s - other.into().s) } } impl Neg for Rad { @@ -234,17 +236,18 @@ impl Zero for Deg { fn is_zero(&self) -> bool { *self == zero() } } -impl Mul for Rad { +impl>, S: BaseFloat> Mul for Rad { type Output = Rad; #[inline] - fn mul(self, other: Rad) -> Rad { rad(self.s * other.s) } + fn mul(self, other: R) -> Rad { rad(self.s * other.into().s) } } -impl Mul for Deg { + +impl>, S: BaseFloat> Mul for Deg { type Output = Deg; #[inline] - fn mul(self, other: Deg) -> Deg { deg(self.s * other.s) } + fn mul(self, other: R) -> Deg { deg(self.s * other.into().s) } } impl One for Rad { @@ -269,19 +272,19 @@ Angle for Deg { #[inline] fn full_turn() -> Deg { deg(cast(360i32).unwrap()) } } -#[inline] pub fn sin(theta: Rad) -> S { theta.s.sin() } -#[inline] pub fn cos(theta: Rad) -> S { theta.s.cos() } -#[inline] pub fn tan(theta: Rad) -> S { theta.s.tan() } -#[inline] pub fn sin_cos(theta: Rad) -> (S, S) { theta.s.sin_cos() } +#[inline] pub fn sin>>(theta: R) -> S { theta.into().s.sin() } +#[inline] pub fn cos>>(theta: R) -> S { theta.into().s.cos() } +#[inline] pub fn tan>>(theta: R) -> S { theta.into().s.tan() } +#[inline] pub fn sin_cos>>(theta: R) -> (S, S) { theta.into().s.sin_cos() } -#[inline] pub fn cot(theta: Rad) -> S { tan(theta).recip() } -#[inline] pub fn sec(theta: Rad) -> S { cos(theta).recip() } -#[inline] pub fn csc(theta: Rad) -> S { sin(theta).recip() } +#[inline] pub fn cot>>(theta: R) -> S { tan(theta.into()).recip() } +#[inline] pub fn sec>>(theta: R) -> S { cos(theta.into()).recip() } +#[inline] pub fn csc>>(theta: R) -> S { sin(theta.into()).recip() } -#[inline] pub fn asin(s: S) -> Rad { rad(s.asin()) } -#[inline] pub fn acos(s: S) -> Rad { rad(s.acos()) } -#[inline] pub fn atan(s: S) -> Rad { rad(s.atan()) } -#[inline] pub fn atan2(a: S, b: S) -> Rad { rad(a.atan2(b)) } +#[inline] pub fn asin>>(s: S) -> R { rad(s.asin()).into() } +#[inline] pub fn acos>>(s: S) -> R { rad(s.acos()).into() } +#[inline] pub fn atan>>(s: S) -> R { rad(s.atan()).into() } +#[inline] pub fn atan2>>(a: S, b: S) -> R { rad(a.atan2(b)).into() } impl fmt::Debug for Rad {