From 6d16999d29ece715f679c5d1d41cd767e1f12d63 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 4 Sep 2013 15:52:44 +1000 Subject: [PATCH] The trigonometric functions don't have to be methods! --- src/cgmath/angle.rs | 32 ++++++++------------------------ 1 file changed, 8 insertions(+), 24 deletions(-) diff --git a/src/cgmath/angle.rs b/src/cgmath/angle.rs index 1667442..2e10f45 100644 --- a/src/cgmath/angle.rs +++ b/src/cgmath/angle.rs @@ -86,18 +86,8 @@ pub trait Angle #[inline] fn mul_self_s(&mut self, s: S) { *self.mut_s() = *self.s() * s } #[inline] fn div_self_s(&mut self, s: S) { *self.mut_s() = *self.s() / s } #[inline] fn rem_self_s(&mut self, s: S) { *self.mut_s() = *self.s() % s } - - #[inline] fn sin(&self) -> S { self.s().sin() } - #[inline] fn cos(&self) -> S { self.s().cos() } - #[inline] fn tan(&self) -> S { self.s().tan() } - #[inline] fn sin_cos(&self) -> (S, S) { self.s().sin_cos() } } -#[inline] pub fn sin>(theta: A) -> S { theta.sin() } -#[inline] pub fn cos>(theta: A) -> S { theta.cos() } -#[inline] pub fn tan>(theta: A) -> S { theta.tan() } -#[inline] pub fn sin_cos>(theta: A) -> (S, S) { theta.sin_cos() } - impl Angle for Rad { #[inline] fn from>(theta: A) -> Rad { theta.to_rad() } } @@ -106,21 +96,15 @@ impl Angle for Deg { #[inline] fn from>(theta: A) -> Deg { theta.to_deg() } } -pub trait ScalarTrig: Clone + Float { - // These need underscores so that they don't conflict with the methods - // defined in the `std::num::Trigonometric` trait. - #[inline] fn asin_>(&self) -> A { Angle::from(rad(self.asin())) } - #[inline] fn acos_>(&self) -> A { Angle::from(rad(self.acos())) } - #[inline] fn atan_>(&self) -> A { Angle::from(rad(self.atan())) } - #[inline] fn atan2_>(&self, other: &Self) -> A { Angle::from(rad(self.atan2(other))) } -} +#[inline] pub fn sin>(theta: A) -> S { theta.to_rad().s.sin() } +#[inline] pub fn cos>(theta: A) -> S { theta.to_rad().s.cos() } +#[inline] pub fn tan>(theta: A) -> S { theta.to_rad().s.tan() } +#[inline] pub fn sin_cos>(theta: A) -> (S, S) { theta.to_rad().s.sin_cos() } -#[inline] pub fn asin>(s: S) -> A { s.asin_() } -#[inline] pub fn acos>(s: S) -> A { s.acos_() } -#[inline] pub fn atan>(s: S) -> A { s.atan_() } -#[inline] pub fn atan2>(a: S, b: S) -> A { a.atan2_(&b) } - -impl ScalarTrig for S; +#[inline] pub fn asin>(s: S) -> A { Angle::from(rad(s.asin())) } +#[inline] pub fn acos>(s: S) -> A { Angle::from(rad(s.acos())) } +#[inline] pub fn atan>(s: S) -> A { Angle::from(rad(s.atan())) } +#[inline] pub fn atan2>(a: S, b: S) -> A { Angle::from(rad(a.atan2(&b))) } impl ToStr for Rad { fn to_str(&self) -> ~str { fmt!("%? rad", self.s) } } impl ToStr for Deg { fn to_str(&self) -> ~str { fmt!("%?°", self.s) } }