Add angle constants
This commit is contained in:
parent
4600d80ce3
commit
d7d1c786fb
2 changed files with 44 additions and 1 deletions
15
src/angle.rs
15
src/angle.rs
|
@ -16,6 +16,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;
|
||||
|
||||
pure fn to_radians() -> Radians<T>;
|
||||
pure fn to_degrees() -> Degrees<T>;
|
||||
}
|
||||
|
@ -23,6 +28,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)] pure fn to_radians() -> Radians<T> { self }
|
||||
#[inline(always)] pure fn to_degrees() -> Degrees<T> { Degrees(*self * cast(180.0 / pi)) }
|
||||
|
||||
|
@ -49,6 +59,11 @@ pub impl<T:Copy Ord> Radians<T>: Ord {
|
|||
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)] pure fn to_radians() -> Radians<T> { Radians(*self * cast(pi / 180.0)) }
|
||||
#[inline(always)] pure fn to_degrees() -> Degrees<T> { self }
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
use core::sys::size_of;
|
||||
|
||||
use angle::{Radians, Degrees, Rotation, Euler};
|
||||
use angle::{Angle, Radians, Degrees, Rotation, Euler};
|
||||
use mat::{NumericMatrix, NumericMatrixNxN, Mat2, Mat3, Mat4};
|
||||
use vec::{Vector, NumericVector, Vec2, Vec3, Vec4};
|
||||
use quat::{/*Quaternion, */Quat};
|
||||
|
@ -438,6 +438,34 @@ pub fn dradians(theta: f64) -> dradians { Radians(theta) }
|
|||
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() }
|
||||
}
|
||||
|
||||
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() }
|
||||
}
|
||||
|
||||
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() }
|
||||
}
|
||||
|
||||
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() }
|
||||
}
|
||||
|
||||
|
||||
// Axis rotation aliases. These are not present in the GLSL specification, but
|
||||
// they follow roughly the same nomenclature.
|
||||
|
|
Loading…
Reference in a new issue