diff --git a/src/color/color.rs b/src/color/color.rs index 311d1af..f098342 100644 --- a/src/color/color.rs +++ b/src/color/color.rs @@ -6,12 +6,12 @@ use core::vec::raw::buf_as_slice; use angle::Degrees; use channel::Channel; -use dim::Dimensional; +use dim::{Dimensional, ToPtr}; use funs::common::Sign; use num::cast::{cast, NumCast}; -pub trait Color: Dimensional, Eq { +pub trait Color: Dimensional, ToPtr, Eq { pure fn inverse(&self) -> self; pure fn to_rgb_u8(&self) -> RGB; @@ -142,7 +142,7 @@ pub impl RGB { } } -pub impl RGB: Dimensional { +pub impl RGB: Dimensional { #[inline(always)] static pure fn dim() -> uint { 3 } @@ -150,11 +150,6 @@ pub impl RGB: Dimensional { static pure fn size_of() -> uint { size_of::>() } - - #[inline(always)] - pure fn to_ptr(&self) -> *T { - ptr::to_unsafe_ptr(&self[0]) - } } pub impl RGB: Index { @@ -167,6 +162,13 @@ pub impl RGB: Index { } } +pub impl RGB: ToPtr { + #[inline(always)] + pure fn to_ptr(&self) -> *T { + ptr::to_unsafe_ptr(&self[0]) + } +} + pub impl RGB: Color { #[inline(always)] pure fn inverse(&self) -> RGB { @@ -263,7 +265,7 @@ pub impl RGBA { } } -pub impl RGBA: Dimensional { +pub impl RGBA: Dimensional { #[inline(always)] static pure fn dim() -> uint { 4 } @@ -271,11 +273,6 @@ pub impl RGBA: Dimensional { static pure fn size_of() -> uint { size_of::>() } - - #[inline(always)] - pure fn to_ptr(&self) -> *T { - ptr::to_unsafe_ptr(&self[0]) - } } pub impl RGBA: Index { @@ -288,6 +285,13 @@ pub impl RGBA: Index { } } +pub impl RGBA: ToPtr { + #[inline(always)] + pure fn to_ptr(&self) -> *T { + ptr::to_unsafe_ptr(&self[0]) + } +} + pub impl RGBA: Color { #[inline(always)] pure fn inverse(&self) -> RGBA { @@ -381,7 +385,7 @@ pub impl HSV { } } -pub impl HSV: Dimensional { +pub impl HSV: Dimensional { #[inline(always)] static pure fn dim() -> uint { 3 } @@ -389,11 +393,6 @@ pub impl HSV: Dimensional { static pure fn size_of() -> uint { size_of::>() } - - #[inline(always)] - pure fn to_ptr(&self) -> *T { - ptr::to_unsafe_ptr(&self[0]) - } } pub impl HSV: Index { @@ -406,6 +405,13 @@ pub impl HSV: Index { } } +pub impl HSV: ToPtr { + #[inline(always)] + pure fn to_ptr(&self) -> *T { + ptr::to_unsafe_ptr(&self[0]) + } +} + pub impl HSV: Color { #[inline(always)] pure fn inverse(&self) -> HSV { @@ -478,7 +484,7 @@ pub impl HSVA { } } -pub impl HSVA: Dimensional { +pub impl HSVA: Dimensional { #[inline(always)] static pure fn dim() -> uint { 4 } @@ -486,11 +492,6 @@ pub impl HSVA: Dimensional { static pure fn size_of() -> uint { size_of::>() } - - #[inline(always)] - pure fn to_ptr(&self) -> *T { - ptr::to_unsafe_ptr(&self[0]) - } } pub impl HSVA: Index { @@ -503,6 +504,13 @@ pub impl HSVA: Index { } } +pub impl HSVA: ToPtr { + #[inline(always)] + pure fn to_ptr(&self) -> *T { + ptr::to_unsafe_ptr(&self[0]) + } +} + pub impl HSVA: Color { #[inline(always)] pure fn inverse(&self) -> HSVA { diff --git a/src/dim.rs b/src/dim.rs index a4d315f..c1b1dc9 100644 --- a/src/dim.rs +++ b/src/dim.rs @@ -1,5 +1,8 @@ pub trait Dimensional: Index { static pure fn dim() -> uint; // dim and size_of are pretty useless at the moment due to static pure fn size_of() -> uint; // how Rust's static methods are currently implemented +} + +pub trait ToPtr { pure fn to_ptr(&self) -> *T; } \ No newline at end of file diff --git a/src/mat.rs b/src/mat.rs index 54043d8..06996e0 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -6,7 +6,7 @@ use core::vec::raw::buf_as_slice; use std::cmp::FuzzyEq; -use dim::Dimensional; +use dim::{Dimensional, ToPtr}; use funs::common::*; use funs::exponential::*; use num::cast::*; @@ -17,7 +17,7 @@ use vec::{NumericVector, Vec2, Vec3, Vec4}; /// /// The base Matrix trait /// -pub trait Matrix: Dimensional, Eq, DefaultEq { +pub trait Matrix: Dimensional, ToPtr, Eq, DefaultEq { static pure fn rows() -> uint; static pure fn cols() -> uint; @@ -181,17 +181,12 @@ pub impl Mat2: Matrix, Vec2> { } } -pub impl Mat2: Dimensional { +pub impl Mat2: Dimensional> { #[inline(always)] static pure fn dim() -> uint { 2 } #[inline(always)] static pure fn size_of() -> uint { size_of::>() } - - #[inline(always)] - pure fn to_ptr(&self) -> *T { - self[0].to_ptr() - } } pub impl Mat2: Index> { @@ -204,6 +199,13 @@ pub impl Mat2: Index> { } } +pub impl Mat2: ToPtr { + #[inline(always)] + pure fn to_ptr(&self) -> *T { + self[0].to_ptr() + } +} + pub impl Mat2: MatrixNxN> { #[inline(always)] pure fn is_symmetric(&self) -> bool { @@ -212,7 +214,7 @@ pub impl Mat2: MatrixNxN> { } } -pub impl Mat2: NumericMatrix, Vec2> { +pub impl Mat2: NumericMatrix, Vec2> { #[inline(always)] static pure fn zero() -> Mat2 { Mat2::from_cols(NumericVector::zero(), @@ -244,7 +246,7 @@ pub impl Mat2: NumericMatrix, Vec2> { } } -pub impl Mat2: Neg> { +pub impl Mat2: Neg> { #[inline(always)] pure fn neg(&self) -> Mat2 { Mat2::from_cols(-self[0], -self[1]) @@ -422,17 +424,12 @@ pub impl Mat3: Matrix, Vec3> { } } -pub impl Mat3: Dimensional { +pub impl Mat3: Dimensional> { #[inline(always)] static pure fn dim() -> uint { 3 } #[inline(always)] static pure fn size_of() -> uint { size_of::>() } - - #[inline(always)] - pure fn to_ptr(&self) -> *T { - self[0].to_ptr() - } } pub impl Mat3: Index> { @@ -445,6 +442,13 @@ pub impl Mat3: Index> { } } +pub impl Mat3: ToPtr { + #[inline(always)] + pure fn to_ptr(&self) -> *T { + self[0].to_ptr() + } +} + pub impl Mat3: MatrixNxN> { #[inline(always)] pure fn is_symmetric(&self) -> bool { @@ -459,7 +463,7 @@ pub impl Mat3: MatrixNxN> { } } -pub impl Mat3: NumericMatrix, Vec3> { +pub impl Mat3: NumericMatrix, Vec3> { #[inline(always)] static pure fn zero() -> Mat3 { Mat3::from_cols(NumericVector::zero(), @@ -496,7 +500,7 @@ pub impl Mat3: NumericMatrix, Vec3> { } } -pub impl Mat3: Neg> { +pub impl Mat3: Neg> { #[inline(always)] pure fn neg(&self) -> Mat3 { Mat3::from_cols(-self[0], -self[1], -self[2]) @@ -742,17 +746,12 @@ pub impl Mat4: Matrix, Vec4> { } } -pub impl Mat4: Dimensional { +pub impl Mat4: Dimensional> { #[inline(always)] static pure fn dim() -> uint { 4 } #[inline(always)] static pure fn size_of() -> uint { size_of::>() } - - #[inline(always)] - pure fn to_ptr(&self) -> *T { - self[0].to_ptr() - } } pub impl Mat4: Index> { @@ -765,6 +764,13 @@ pub impl Mat4: Index> { } } +pub impl Mat4: ToPtr { + #[inline(always)] + pure fn to_ptr(&self) -> *T { + self[0].to_ptr() + } +} + pub impl Mat4: MatrixNxN> { #[inline(always)] pure fn is_symmetric(&self) -> bool { @@ -786,7 +792,7 @@ pub impl Mat4: MatrixNxN> { } } -pub impl Mat4: NumericMatrix, Vec4> { +pub impl Mat4: NumericMatrix, Vec4> { #[inline(always)] static pure fn zero() -> Mat4 { Mat4::from_cols(NumericVector::zero(), @@ -828,7 +834,7 @@ pub impl Mat4: NumericMatrix, Vec4> { } } -pub impl Mat4: Neg> { +pub impl Mat4: Neg> { #[inline(always)] pure fn neg(&self) -> Mat4 { Mat4::from_cols(-self[0], -self[1], -self[2], -self[3]) diff --git a/src/quat.rs b/src/quat.rs index 2256cfe..dd8099e 100644 --- a/src/quat.rs +++ b/src/quat.rs @@ -6,7 +6,7 @@ use core::vec::raw::buf_as_slice; use std::cmp::FuzzyEq; -use dim::Dimensional; +use dim::{Dimensional, ToPtr}; use funs::common::*; use funs::exponential::*; use funs::triganomic::*; @@ -19,7 +19,7 @@ use vec::Vec3; /// /// The base quaternion trait /// -pub trait Quaternion: Dimensional, Eq, DefaultEq, Neg { +pub trait Quaternion: Dimensional, ToPtr, Eq, DefaultEq, Neg { static pure fn identity() -> self; static pure fn zero() -> self; @@ -70,17 +70,12 @@ pub impl Quat { } } -pub impl Quat: Dimensional { +pub impl Quat: Dimensional { #[inline(always)] static pure fn dim() -> uint { 4 } #[inline(always)] static pure fn size_of() -> uint { size_of::>() } - - #[inline(always)] - pure fn to_ptr(&self) -> *T { - to_unsafe_ptr(&self[0]) - } } pub impl Quat: Index { @@ -93,6 +88,13 @@ pub impl Quat: Index { } } +pub impl Quat: ToPtr { + #[inline(always)] + pure fn to_ptr(&self) -> *T { + to_unsafe_ptr(&self[0]) + } +} + pub impl Quat: Quaternion { #[inline(always)] static pure fn identity() -> Quat { diff --git a/src/vec.rs b/src/vec.rs index 11775c8..5dbf0b3 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -6,7 +6,7 @@ use core::vec::raw::buf_as_slice; use std::cmp::FuzzyEq; -use dim::Dimensional; +use dim::{Dimensional, ToPtr}; use funs::exponential::Exp; use num::cast::*; use num::default_eq::DefaultEq; @@ -14,7 +14,7 @@ use num::default_eq::DefaultEq; /// /// The base vector trait /// -pub trait Vector: Dimensional, Eq, DefaultEq { +pub trait Vector: Dimensional, ToPtr, Eq, DefaultEq { /// Construct the vector from a single value, copying it to each component static pure fn from_value(value: T) -> self; } @@ -107,17 +107,12 @@ pub impl Vec2: Vector { } } -pub impl Vec2: Dimensional { +pub impl Vec2: Dimensional { #[inline(always)] static pure fn dim() -> uint { 2 } #[inline(always)] static pure fn size_of() -> uint { size_of::>() } - - #[inline(always)] - pure fn to_ptr(&self) -> *T { - ptr::to_unsafe_ptr(&self[0]) - } } pub impl Vec2: Index { @@ -129,6 +124,13 @@ pub impl Vec2: Index { } } } + +pub impl Vec2: ToPtr { + #[inline(always)] + pure fn to_ptr(&self) -> *T { + ptr::to_unsafe_ptr(&self[0]) + } +} pub impl Vec2: NumericVector { #[inline(always)] @@ -267,17 +269,12 @@ pub impl Vec3: Vector { } } -pub impl Vec3: Dimensional { +pub impl Vec3: Dimensional { #[inline(always)] static pure fn dim() -> uint { 3 } #[inline(always)] static pure fn size_of() -> uint { size_of::>() } - - #[inline(always)] - pure fn to_ptr(&self) -> *T { - to_unsafe_ptr(&self[0]) - } } pub impl Vec3: Index { @@ -290,6 +287,13 @@ pub impl Vec3: Index { } } +pub impl Vec3: ToPtr { + #[inline(always)] + pure fn to_ptr(&self) -> *T { + ptr::to_unsafe_ptr(&self[0]) + } +} + pub impl Vec3: NumericVector { #[inline(always)] static pure fn identity() -> Vec3 { @@ -445,17 +449,12 @@ pub impl Vec4: Vector { } } -pub impl Vec4: Dimensional { +pub impl Vec4: Dimensional { #[inline(always)] static pure fn dim() -> uint { 4 } #[inline(always)] static pure fn size_of() -> uint { size_of::>() } - - #[inline(always)] - pure fn to_ptr(&self) -> *T { - to_unsafe_ptr(&self[0]) - } } pub impl Vec4: Index { @@ -468,6 +467,13 @@ pub impl Vec4: Index { } } +pub impl Vec4: ToPtr { + #[inline(always)] + pure fn to_ptr(&self) -> *T { + ptr::to_unsafe_ptr(&self[0]) + } +} + pub impl Vec4: NumericVector { #[inline(always)] static pure fn identity() -> Vec4 {