Improve constant names

This commit is contained in:
Brendan Zabarauskas 2012-11-29 18:29:08 +10:00
parent 9b05325a31
commit 126c5f4501
2 changed files with 35 additions and 28 deletions

View file

@ -17,10 +17,11 @@ pub trait Angle<T>: Add<self,self>
, Modulo<T,self>
, Neg<self>
, Eq, Ord {
static pure fn full_rotation() -> self;
static pure fn half_rotation() -> self;
static pure fn quarter_rotation() -> self;
static pure fn eighth_rotation() -> self;
static pure fn full_turn() -> self;
static pure fn half_turn() -> self;
static pure fn quadrant() -> self;
static pure fn sextant() -> self;
static pure fn octant() -> self;
pure fn to_radians() -> Radians<T>;
pure fn to_degrees() -> Degrees<T>;
@ -34,10 +35,11 @@ pub trait Angle<T>: Add<self,self>
pub enum Radians<T> = T;
pub impl<T:Copy Num NumCast> Radians<T>: Angle<T> {
#[inline(always)] static pure fn full_rotation() -> Radians<T> { Radians(move cast(2.0 * pi)) }
#[inline(always)] static pure fn half_rotation() -> Radians<T> { Radians(move cast(pi)) }
#[inline(always)] static pure fn quarter_rotation() -> Radians<T> { Radians(move cast(pi / 2.0)) }
#[inline(always)] static pure fn eighth_rotation() -> Radians<T> { Radians(move cast(pi / 4.0)) }
#[inline(always)] static pure fn full_turn() -> Radians<T> { Radians(move cast(2.0 * pi)) } // TODO: calculate absolute values
#[inline(always)] static pure fn half_turn() -> Radians<T> { Radians(move cast(pi)) }
#[inline(always)] static pure fn quadrant() -> Radians<T> { Radians(move cast(pi / 2.0)) }
#[inline(always)] static pure fn sextant() -> Radians<T> { Radians(move cast(pi / 3.0)) }
#[inline(always)] static pure fn octant() -> Radians<T> { Radians(move cast(pi / 4.0)) }
#[inline(always)] pure fn to_radians() -> Radians<T> { self }
#[inline(always)] pure fn to_degrees() -> Degrees<T> { Degrees(*self * cast(180.0 / pi)) }
@ -112,10 +114,11 @@ pub impl<T> Radians<T>: ToStr {
pub enum Degrees<T> = T;
pub impl<T:Copy Num NumCast> Degrees<T>: Angle<T> {
#[inline(always)] static pure fn full_rotation() -> Degrees<T> { Degrees(move cast(360.0)) }
#[inline(always)] static pure fn half_rotation() -> Degrees<T> { Degrees(move cast(180.0)) }
#[inline(always)] static pure fn quarter_rotation() -> Degrees<T> { Degrees(move cast(90.0)) }
#[inline(always)] static pure fn eighth_rotation() -> Degrees<T> { Degrees(move cast(45.0)) }
#[inline(always)] static pure fn full_turn() -> Degrees<T> { Degrees(move cast(360.0)) }
#[inline(always)] static pure fn half_turn() -> Degrees<T> { Degrees(move cast(180.0)) }
#[inline(always)] static pure fn quadrant() -> Degrees<T> { Degrees(move cast(90.0)) }
#[inline(always)] static pure fn sextant() -> Degrees<T> { Degrees(move cast(60.0)) }
#[inline(always)] static pure fn octant() -> Degrees<T> { Degrees(move cast(45.0)) }
#[inline(always)] pure fn to_radians() -> Radians<T> { Radians(*self * cast(pi / 180.0)) }
#[inline(always)] pure fn to_degrees() -> Degrees<T> { self }

View file

@ -439,31 +439,35 @@ pub fn degrees(theta: f32) -> degrees { Degrees(theta) }
pub fn ddegrees(theta: f64) -> ddegrees { Degrees(theta) }
pub impl radians {
#[inline(always)] static pure fn full_rotation() -> radians { Angle::full_rotation() }
#[inline(always)] static pure fn half_rotation() -> radians { Angle::half_rotation() }
#[inline(always)] static pure fn quarter_rotation() -> radians { Angle::quarter_rotation() }
#[inline(always)] static pure fn eighth_rotation() -> radians { Angle::eighth_rotation() }
#[inline(always)] static pure fn full_turn() -> radians { Angle::full_turn() }
#[inline(always)] static pure fn half_turn() -> radians { Angle::half_turn() }
#[inline(always)] static pure fn quadrant() -> radians { Angle::quadrant() }
#[inline(always)] static pure fn sextant() -> radians { Angle::sextant() }
#[inline(always)] static pure fn octant() -> radians { Angle::octant() }
}
pub impl dradians {
#[inline(always)] static pure fn full_rotation() -> dradians { Angle::full_rotation() }
#[inline(always)] static pure fn half_rotation() -> dradians { Angle::half_rotation() }
#[inline(always)] static pure fn quarter_rotation() -> dradians { Angle::quarter_rotation() }
#[inline(always)] static pure fn eighth_rotation() -> dradians { Angle::eighth_rotation() }
#[inline(always)] static pure fn full_turn() -> dradians { Angle::full_turn() }
#[inline(always)] static pure fn half_turn() -> dradians { Angle::half_turn() }
#[inline(always)] static pure fn quadrant() -> dradians { Angle::quadrant() }
#[inline(always)] static pure fn sextant() -> dradians { Angle::sextant() }
#[inline(always)] static pure fn octant() -> dradians { Angle::octant() }
}
pub impl degrees {
#[inline(always)] static pure fn full_rotation() -> degrees { Angle::full_rotation() }
#[inline(always)] static pure fn half_rotation() -> degrees { Angle::half_rotation() }
#[inline(always)] static pure fn quarter_rotation() -> degrees { Angle::quarter_rotation() }
#[inline(always)] static pure fn eighth_rotation() -> degrees { Angle::eighth_rotation() }
#[inline(always)] static pure fn full_turn() -> degrees { Angle::full_turn() }
#[inline(always)] static pure fn half_turn() -> degrees { Angle::half_turn() }
#[inline(always)] static pure fn quadrant() -> degrees { Angle::quadrant() }
#[inline(always)] static pure fn sextant() -> degrees { Angle::sextant() }
#[inline(always)] static pure fn octant() -> degrees { Angle::octant() }
}
pub impl ddegrees {
#[inline(always)] static pure fn full_rotation() -> ddegrees { Angle::full_rotation() }
#[inline(always)] static pure fn half_rotation() -> ddegrees { Angle::half_rotation() }
#[inline(always)] static pure fn quarter_rotation() -> ddegrees { Angle::quarter_rotation() }
#[inline(always)] static pure fn eighth_rotation() -> ddegrees { Angle::eighth_rotation() }
#[inline(always)] static pure fn full_turn() -> ddegrees { Angle::full_turn() }
#[inline(always)] static pure fn half_turn() -> ddegrees { Angle::half_turn() }
#[inline(always)] static pure fn quadrant() -> ddegrees { Angle::quadrant() }
#[inline(always)] static pure fn sextant() -> ddegrees { Angle::sextant() }
#[inline(always)] static pure fn octant() -> ddegrees { Angle::octant() }
}