From d7d1c786fbe75d444383106ae2b1cd57ee625d18 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Tue, 27 Nov 2012 12:34:15 +1000 Subject: [PATCH] Add angle constants --- src/angle.rs | 15 +++++++++++++++ src/gltypes.rs | 30 +++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/src/angle.rs b/src/angle.rs index ed1b78a..514be8a 100644 --- a/src/angle.rs +++ b/src/angle.rs @@ -16,6 +16,11 @@ pub trait Angle: Add , Modulo , Neg , 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; pure fn to_degrees() -> Degrees; } @@ -23,6 +28,11 @@ pub trait Angle: Add pub enum Radians = T; pub impl Radians: Angle { + #[inline(always)] static pure fn full_rotation() -> Radians { Radians(move cast(2.0 * pi)) } + #[inline(always)] static pure fn half_rotation() -> Radians { Radians(move cast(pi)) } + #[inline(always)] static pure fn quarter_rotation() -> Radians { Radians(move cast(pi / 2.0)) } + #[inline(always)] static pure fn eighth_rotation() -> Radians { Radians(move cast(pi / 4.0)) } + #[inline(always)] pure fn to_radians() -> Radians { self } #[inline(always)] pure fn to_degrees() -> Degrees { Degrees(*self * cast(180.0 / pi)) } @@ -49,6 +59,11 @@ pub impl Radians: Ord { pub enum Degrees = T; pub impl Degrees: Angle { + #[inline(always)] static pure fn full_rotation() -> Degrees { Degrees(move cast(360.0)) } + #[inline(always)] static pure fn half_rotation() -> Degrees { Degrees(move cast(180.0)) } + #[inline(always)] static pure fn quarter_rotation() -> Degrees { Degrees(move cast(90.0)) } + #[inline(always)] static pure fn eighth_rotation() -> Degrees { Degrees(move cast(45.0)) } + #[inline(always)] pure fn to_radians() -> Radians { Radians(*self * cast(pi / 180.0)) } #[inline(always)] pure fn to_degrees() -> Degrees { self } diff --git a/src/gltypes.rs b/src/gltypes.rs index 99e4e47..e11bbd7 100644 --- a/src/gltypes.rs +++ b/src/gltypes.rs @@ -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.