Add angle unit conversions
This commit is contained in:
parent
8a3a28481e
commit
3dc5e26126
1 changed files with 15 additions and 1 deletions
|
@ -222,3 +222,17 @@ pub impl<T: NumCast> T: Trig {
|
||||||
#[inline(always)] pure fn tanh() -> T { f64::tanh(self.cast()).cast() }
|
#[inline(always)] pure fn tanh() -> T { f64::tanh(self.cast()).cast() }
|
||||||
#[inline(always)] pure fn atan2(n: T) -> T { f64::atan2(self.cast(), move n.cast()).cast() }
|
#[inline(always)] pure fn atan2(n: T) -> T { f64::atan2(self.cast(), move n.cast()).cast() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
pub trait AngleUnits {
|
||||||
|
pure fn to_radians() -> self;
|
||||||
|
pure fn to_degrees() -> self;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline(always)] pub pure fn radians<T:AngleUnits>(degrees: T) -> T { degrees.to_radians() }
|
||||||
|
#[inline(always)] pub pure fn degrees<T:AngleUnits>(radians: T) -> T { radians.to_degrees() }
|
||||||
|
|
||||||
|
pub impl<T:Num NumCast> T: AngleUnits {
|
||||||
|
#[inline(always)] pure fn to_radians() -> T { self * cast(f64::consts::pi / 180f64) }
|
||||||
|
#[inline(always)] pure fn to_degrees() -> T { self * cast(180f64 / f64::consts::pi) }
|
||||||
|
}
|
Loading…
Reference in a new issue