diff --git a/src/math.rs b/src/math.rs index 9f3c9a4..ec19ef6 100644 --- a/src/math.rs +++ b/src/math.rs @@ -1,6 +1,11 @@ use cmp::Ord; use num::{Num, from_int}; +// TODO: move to a more appropriate module +pub trait ToPtr { + pure fn to_ptr() -> *T; +} + pub trait ExactEq { pure fn exact_eq(other: &self) -> bool; } diff --git a/src/matrix.rs b/src/matrix.rs index 952d639..36cde2a 100644 --- a/src/matrix.rs +++ b/src/matrix.rs @@ -1,6 +1,6 @@ use std::cmp::FuzzyEq; use cmp::Eq; -use math::{ExactEq, Sqrt}; +use math::{ToPtr, ExactEq, Sqrt}; use quaternion::Quat; use vector::{Vec2, Vec3, Vec4}; @@ -219,6 +219,13 @@ pub impl Mat2: FuzzyEq { } } +pub impl Mat2: ToPtr { + #[inline(always)] + pure fn to_ptr() -> *float { + self[0].to_ptr() + } +} + @@ -473,6 +480,13 @@ pub impl Mat3: FuzzyEq { } } +pub impl Mat3: ToPtr { + #[inline(always)] + pure fn to_ptr() -> *float { + self[0].to_ptr() + } +} + @@ -723,4 +737,11 @@ pub impl Mat4: FuzzyEq { self[2].fuzzy_eq(&other[2]) && self[3].fuzzy_eq(&other[3]) } +} + +pub impl Mat4: ToPtr { + #[inline(always)] + pure fn to_ptr() -> *float { + self[0].to_ptr() + } } \ No newline at end of file diff --git a/src/quaternion.rs b/src/quaternion.rs index c57bcbd..5375f0b 100644 --- a/src/quaternion.rs +++ b/src/quaternion.rs @@ -3,7 +3,7 @@ use vec::raw::buf_as_slice; use ptr::to_unsafe_ptr; use cmp::Eq; use std::cmp::FuzzyEq; -use math::{ExactEq, Sqrt}; +use math::{ToPtr, ExactEq, Sqrt}; use matrix::{Mat3, Mat4}; use vector::Vec3; @@ -203,6 +203,13 @@ pub impl Quat: FuzzyEq { } } +pub impl Quat: ToPtr { + #[inline(always)] + pure fn to_ptr() -> *float { + to_unsafe_ptr(&self[0]) + } +} + pub impl Quat: ToStr { pure fn to_str() -> ~str { fmt!("Quat[ %f, %f, %f, %f ]", self.w, self.x, self.y, self.z) diff --git a/src/vector.rs b/src/vector.rs index 9803deb..87d6efd 100644 --- a/src/vector.rs +++ b/src/vector.rs @@ -3,7 +3,7 @@ use vec::raw::buf_as_slice; use ptr::to_unsafe_ptr; use cmp::Eq; use std::cmp::FuzzyEq; -use math::{Abs, abs, ExactEq, max, min, Sqrt}; +use math::{ToPtr, Abs, abs, ExactEq, max, min, Sqrt}; // // N-dimensional Vector @@ -201,6 +201,13 @@ pub impl Vec2: FuzzyEq { } } +pub impl Vec2: ToPtr { + #[inline(always)] + pure fn to_ptr() -> *float { + to_unsafe_ptr(&self[0]) + } +} + pub impl Vec2: ToStr { pure fn to_str() -> ~str { fmt!("Vec2[ %f, %f ]", self[0], self[1]) @@ -392,6 +399,13 @@ pub impl Vec3: FuzzyEq { } } +pub impl Vec3: ToPtr { + #[inline(always)] + pure fn to_ptr() -> *float { + to_unsafe_ptr(&self[0]) + } +} + pub impl Vec3: ToStr { pure fn to_str() -> ~str { fmt!("Vec3[ %f, %f, %f ]", self[0], self[1], self[2]) @@ -589,6 +603,13 @@ pub impl Vec4: FuzzyEq { } } +pub impl Vec4: ToPtr { + #[inline(always)] + pure fn to_ptr() -> *float { + to_unsafe_ptr(&self[0]) + } +} + pub impl Vec4: ToStr { pure fn to_str() -> ~str { fmt!("Vec4[ %f, %f, %f, %f ]", self[0], self[1], self[2], self[3])