Divide up trait implementations

This commit is contained in:
Brendan Zabarauskas 2012-12-01 14:19:21 +10:00
parent 7316fa4397
commit 10f8570441
5 changed files with 195 additions and 138 deletions

View file

@ -143,14 +143,6 @@ pub impl<T:Copy> RGB<T> {
} }
pub impl<T:Copy> RGB<T>: Dimensional<T> { pub impl<T:Copy> RGB<T>: Dimensional<T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*RGB<T>, *T>(
to_unsafe_ptr(&self)), 3) |slice| { slice[i] }
}
}
#[inline(always)] #[inline(always)]
static pure fn dim() -> uint { 3 } static pure fn dim() -> uint { 3 }
@ -165,6 +157,16 @@ pub impl<T:Copy> RGB<T>: Dimensional<T> {
} }
} }
pub impl<T:Copy> RGB<T>: Index<uint, T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*RGB<T>, *T>(
to_unsafe_ptr(&self)), 3) |slice| { slice[i] }
}
}
}
pub impl<T:Copy Num NumCast Channel Eq Ord> RGB<T>: Color<T> { pub impl<T:Copy Num NumCast Channel Eq Ord> RGB<T>: Color<T> {
#[inline(always)] #[inline(always)]
pure fn inverse(&self) -> RGB<T> { pure fn inverse(&self) -> RGB<T> {
@ -262,14 +264,6 @@ pub impl<T:Copy> RGBA<T> {
} }
pub impl<T:Copy> RGBA<T>: Dimensional<T> { pub impl<T:Copy> RGBA<T>: Dimensional<T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*RGBA<T>, *T>(
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
}
}
#[inline(always)] #[inline(always)]
static pure fn dim() -> uint { 4 } static pure fn dim() -> uint { 4 }
@ -284,6 +278,16 @@ pub impl<T:Copy> RGBA<T>: Dimensional<T> {
} }
} }
pub impl<T:Copy> RGBA<T>: Index<uint, T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*RGBA<T>, *T>(
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
}
}
}
pub impl<T:Copy Num NumCast Channel Eq Ord> RGBA<T>: Color<T> { pub impl<T:Copy Num NumCast Channel Eq Ord> RGBA<T>: Color<T> {
#[inline(always)] #[inline(always)]
pure fn inverse(&self) -> RGBA<T> { pure fn inverse(&self) -> RGBA<T> {
@ -378,14 +382,6 @@ pub impl<T:Copy> HSV<T> {
} }
pub impl<T:Copy> HSV<T>: Dimensional<T> { pub impl<T:Copy> HSV<T>: Dimensional<T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*HSV<T>, *T>(
to_unsafe_ptr(&self)), 3) |slice| { slice[i] }
}
}
#[inline(always)] #[inline(always)]
static pure fn dim() -> uint { 3 } static pure fn dim() -> uint { 3 }
@ -400,6 +396,16 @@ pub impl<T:Copy> HSV<T>: Dimensional<T> {
} }
} }
pub impl<T:Copy> HSV<T>: Index<uint, T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*HSV<T>, *T>(
to_unsafe_ptr(&self)), 3) |slice| { slice[i] }
}
}
}
pub impl<T:Copy Num NumCast Channel Eq Ord> HSV<T>: Color<T> { pub impl<T:Copy Num NumCast Channel Eq Ord> HSV<T>: Color<T> {
#[inline(always)] #[inline(always)]
pure fn inverse(&self) -> HSV<T> { pure fn inverse(&self) -> HSV<T> {
@ -473,14 +479,6 @@ pub impl<T:Copy> HSVA<T> {
} }
pub impl<T:Copy> HSVA<T>: Dimensional<T> { pub impl<T:Copy> HSVA<T>: Dimensional<T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*HSVA<T>, *T>(
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
}
}
#[inline(always)] #[inline(always)]
static pure fn dim() -> uint { 4 } static pure fn dim() -> uint { 4 }
@ -495,6 +493,16 @@ pub impl<T:Copy> HSVA<T>: Dimensional<T> {
} }
} }
pub impl<T:Copy> HSVA<T>: Index<uint, T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*HSVA<T>, *T>(
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
}
}
}
pub impl<T:Copy Num NumCast Channel Eq Ord> HSVA<T>: Color<T> { pub impl<T:Copy Num NumCast Channel Eq Ord> HSVA<T>: Color<T> {
#[inline(always)] #[inline(always)]
pure fn inverse(&self) -> HSVA<T> { pure fn inverse(&self) -> HSVA<T> {

View file

@ -165,12 +165,6 @@ pub impl<T:Copy NumCast> Mat2<T> {
} }
pub impl<T:Copy> Mat2<T>: Matrix<T, Vec2<T>, Vec2<T>> { pub impl<T:Copy> Mat2<T>: Matrix<T, Vec2<T>, Vec2<T>> {
#[inline(always)]
static pure fn dim() -> uint { 2 }
#[inline(always)]
static pure fn size_of() -> uint { size_of::<Mat2<T>>() }
#[inline(always)] #[inline(always)]
static pure fn cols() -> uint { 2 } static pure fn cols() -> uint { 2 }
@ -185,7 +179,22 @@ pub impl<T:Copy> Mat2<T>: Matrix<T, Vec2<T>, Vec2<T>> {
Vec2::new(self[0][i], Vec2::new(self[0][i],
self[1][i]) self[1][i])
} }
}
pub impl<T:Copy> Mat2<T>: Dimensional<T> {
#[inline(always)]
static pure fn dim() -> uint { 2 }
#[inline(always)]
static pure fn size_of() -> uint { size_of::<Mat2<T>>() }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
self[0].to_ptr()
}
}
pub impl<T:Copy> Mat2<T>: Index<uint, Vec2<T>> {
#[inline(always)] #[inline(always)]
pure fn index(i: uint) -> Vec2<T> { pure fn index(i: uint) -> Vec2<T> {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(
@ -193,11 +202,6 @@ pub impl<T:Copy> Mat2<T>: Matrix<T, Vec2<T>, Vec2<T>> {
to_unsafe_ptr(&self)), 2) |slice| { slice[i] } to_unsafe_ptr(&self)), 2) |slice| { slice[i] }
} }
} }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
self[0].to_ptr()
}
} }
pub impl<T:Copy DefaultEq> Mat2<T>: MatrixNxN<T, Vec2<T>> { pub impl<T:Copy DefaultEq> Mat2<T>: MatrixNxN<T, Vec2<T>> {
@ -215,11 +219,6 @@ pub impl<T:Copy Num NumCast> Mat2<T>: NumericMatrix<T, Vec2<T>, Vec2<T>> {
NumericVector::zero()) NumericVector::zero())
} }
#[inline(always)]
pure fn neg() -> Mat2<T> {
Mat2::from_cols(-self[0], -self[1])
}
#[inline(always)] #[inline(always)]
pure fn mul_t(&self, value: T) -> Mat2<T> { pure fn mul_t(&self, value: T) -> Mat2<T> {
Mat2::from_cols(self[0].mul_t(value), Mat2::from_cols(self[0].mul_t(value),
@ -245,6 +244,13 @@ pub impl<T:Copy Num NumCast> Mat2<T>: NumericMatrix<T, Vec2<T>, Vec2<T>> {
} }
} }
pub impl<T:Copy Num> Mat2<T>: Neg<Mat2<T>> {
#[inline(always)]
pure fn neg(&self) -> Mat2<T> {
Mat2::from_cols(-self[0], -self[1])
}
}
pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrixNxN<T, Vec2<T>> { pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrixNxN<T, Vec2<T>> {
#[inline(always)] #[inline(always)]
static pure fn identity() -> Mat2<T> { static pure fn identity() -> Mat2<T> {
@ -399,12 +405,6 @@ pub impl<T:Copy NumCast> Mat3<T> {
} }
pub impl<T:Copy> Mat3<T>: Matrix<T, Vec3<T>, Vec3<T>> { pub impl<T:Copy> Mat3<T>: Matrix<T, Vec3<T>, Vec3<T>> {
#[inline(always)]
static pure fn dim() -> uint { 3 }
#[inline(always)]
static pure fn size_of() -> uint { size_of::<Mat3<T>>() }
#[inline(always)] #[inline(always)]
static pure fn cols() -> uint { 3 } static pure fn cols() -> uint { 3 }
@ -420,7 +420,22 @@ pub impl<T:Copy> Mat3<T>: Matrix<T, Vec3<T>, Vec3<T>> {
self[1][i], self[1][i],
self[2][i]) self[2][i])
} }
}
pub impl<T:Copy> Mat3<T>: Dimensional<T> {
#[inline(always)]
static pure fn dim() -> uint { 3 }
#[inline(always)]
static pure fn size_of() -> uint { size_of::<Mat3<T>>() }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
self[0].to_ptr()
}
}
pub impl<T:Copy> Mat3<T>: Index<uint, Vec3<T>> {
#[inline(always)] #[inline(always)]
pure fn index(i: uint) -> Vec3<T> { pure fn index(i: uint) -> Vec3<T> {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(
@ -428,11 +443,6 @@ pub impl<T:Copy> Mat3<T>: Matrix<T, Vec3<T>, Vec3<T>> {
to_unsafe_ptr(&self)), 3) |slice| { slice[i] } to_unsafe_ptr(&self)), 3) |slice| { slice[i] }
} }
} }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
self[0].to_ptr()
}
} }
pub impl<T:Copy DefaultEq> Mat3<T>: MatrixNxN<T, Vec3<T>> { pub impl<T:Copy DefaultEq> Mat3<T>: MatrixNxN<T, Vec3<T>> {
@ -457,11 +467,6 @@ pub impl<T:Copy Num NumCast> Mat3<T>: NumericMatrix<T, Vec3<T>, Vec3<T>> {
NumericVector::zero()) NumericVector::zero())
} }
#[inline(always)]
pure fn neg() -> Mat3<T> {
Mat3::from_cols(-self[0], -self[1], -self[2])
}
#[inline(always)] #[inline(always)]
pure fn mul_t(&self, value: T) -> Mat3<T> { pure fn mul_t(&self, value: T) -> Mat3<T> {
Mat3::from_cols(self[0].mul_t(value), Mat3::from_cols(self[0].mul_t(value),
@ -491,6 +496,13 @@ pub impl<T:Copy Num NumCast> Mat3<T>: NumericMatrix<T, Vec3<T>, Vec3<T>> {
} }
} }
pub impl<T:Copy Num> Mat3<T>: Neg<Mat3<T>> {
#[inline(always)]
pure fn neg(&self) -> Mat3<T> {
Mat3::from_cols(-self[0], -self[1], -self[2])
}
}
pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrixNxN<T, Vec3<T>> { pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrixNxN<T, Vec3<T>> {
#[inline(always)] #[inline(always)]
static pure fn identity() -> Mat3<T> { static pure fn identity() -> Mat3<T> {
@ -712,12 +724,6 @@ pub impl<T:Copy NumCast> Mat4<T> {
} }
pub impl<T:Copy> Mat4<T>: Matrix<T, Vec4<T>, Vec4<T>> { pub impl<T:Copy> Mat4<T>: Matrix<T, Vec4<T>, Vec4<T>> {
#[inline(always)]
static pure fn dim() -> uint { 4 }
#[inline(always)]
static pure fn size_of() -> uint { size_of::<Mat4<T>>() }
#[inline(always)] #[inline(always)]
static pure fn cols() -> uint { 4 } static pure fn cols() -> uint { 4 }
@ -734,7 +740,22 @@ pub impl<T:Copy> Mat4<T>: Matrix<T, Vec4<T>, Vec4<T>> {
self[2][i], self[2][i],
self[3][i]) self[3][i])
} }
}
pub impl<T:Copy> Mat4<T>: Dimensional<T> {
#[inline(always)]
static pure fn dim() -> uint { 4 }
#[inline(always)]
static pure fn size_of() -> uint { size_of::<Mat4<T>>() }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
self[0].to_ptr()
}
}
pub impl<T:Copy> Mat4<T>: Index<uint, Vec4<T>> {
#[inline(always)] #[inline(always)]
pure fn index(i: uint) -> Vec4<T> { pure fn index(i: uint) -> Vec4<T> {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(
@ -742,11 +763,6 @@ pub impl<T:Copy> Mat4<T>: Matrix<T, Vec4<T>, Vec4<T>> {
to_unsafe_ptr(&self)), 4) |slice| { slice[i] } to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
} }
} }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
self[0].to_ptr()
}
} }
pub impl<T:Copy DefaultEq> Mat4<T>: MatrixNxN<T, Vec4<T>> { pub impl<T:Copy DefaultEq> Mat4<T>: MatrixNxN<T, Vec4<T>> {
@ -779,11 +795,6 @@ pub impl<T:Copy Num NumCast> Mat4<T>: NumericMatrix<T, Vec4<T>, Vec4<T>> {
NumericVector::zero()) NumericVector::zero())
} }
#[inline(always)]
pure fn neg() -> Mat4<T> {
Mat4::from_cols(-self[0], -self[1], -self[2], -self[3])
}
#[inline(always)] #[inline(always)]
pure fn mul_t(&self, value: T) -> Mat4<T> { pure fn mul_t(&self, value: T) -> Mat4<T> {
Mat4::from_cols(self[0].mul_t(value), Mat4::from_cols(self[0].mul_t(value),
@ -817,6 +828,13 @@ pub impl<T:Copy Num NumCast> Mat4<T>: NumericMatrix<T, Vec4<T>, Vec4<T>> {
} }
} }
pub impl<T:Copy Num> Mat4<T>: Neg<Mat4<T>> {
#[inline(always)]
pure fn neg(&self) -> Mat4<T> {
Mat4::from_cols(-self[0], -self[1], -self[2], -self[3])
}
}
pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec4<T>> { pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec4<T>> {
#[inline(always)] #[inline(always)]
static pure fn identity() -> Mat4<T> { static pure fn identity() -> Mat4<T> {

View file

@ -69,9 +69,12 @@ pub impl int: IntConsts {
#[inline(always)] static pure fn one() -> int { 1 } #[inline(always)] static pure fn one() -> int { 1 }
} }
pub impl f32: FloatConsts { pub impl f32: IntConsts {
#[inline(always)] static pure fn zero() -> f32 { 0f32 } #[inline(always)] static pure fn zero() -> f32 { 0f32 }
#[inline(always)] static pure fn one() -> f32 { 1f32 } #[inline(always)] static pure fn one() -> f32 { 1f32 }
}
pub impl f32: FloatConsts {
#[inline(always)] static pure fn pi() -> f32 { 3.14159265358979323846264338327950288_f32 } #[inline(always)] static pure fn pi() -> f32 { 3.14159265358979323846264338327950288_f32 }
#[inline(always)] static pure fn frac_pi_2() -> f32 { 1.57079632679489661923132169163975144_f32 } #[inline(always)] static pure fn frac_pi_2() -> f32 { 1.57079632679489661923132169163975144_f32 }
#[inline(always)] static pure fn frac_pi_4() -> f32 { 0.785398163397448309615660845819875721_f32 } #[inline(always)] static pure fn frac_pi_4() -> f32 { 0.785398163397448309615660845819875721_f32 }
@ -87,9 +90,12 @@ pub impl f32: FloatConsts {
#[inline(always)] static pure fn ln_10() -> f32 { 2.30258509299404568401799145468436421_f32 } #[inline(always)] static pure fn ln_10() -> f32 { 2.30258509299404568401799145468436421_f32 }
} }
pub impl f64: FloatConsts { pub impl f64: IntConsts {
#[inline(always)] static pure fn zero() -> f64 { 0f64 } #[inline(always)] static pure fn zero() -> f64 { 0f64 }
#[inline(always)] static pure fn one() -> f64 { 1f64 } #[inline(always)] static pure fn one() -> f64 { 1f64 }
}
pub impl f64: FloatConsts {
#[inline(always)] static pure fn pi() -> f64 { 3.14159265358979323846264338327950288_f64 } #[inline(always)] static pure fn pi() -> f64 { 3.14159265358979323846264338327950288_f64 }
#[inline(always)] static pure fn frac_pi_2() -> f64 { 1.57079632679489661923132169163975144_f64 } #[inline(always)] static pure fn frac_pi_2() -> f64 { 1.57079632679489661923132169163975144_f64 }
#[inline(always)] static pure fn frac_pi_4() -> f64 { 0.785398163397448309615660845819875721_f64 } #[inline(always)] static pure fn frac_pi_4() -> f64 { 0.785398163397448309615660845819875721_f64 }
@ -105,9 +111,12 @@ pub impl f64: FloatConsts {
#[inline(always)] static pure fn ln_10() -> f64 { 2.30258509299404568401799145468436421_f64 } #[inline(always)] static pure fn ln_10() -> f64 { 2.30258509299404568401799145468436421_f64 }
} }
pub impl float: FloatConsts { pub impl float: IntConsts {
#[inline(always)] static pure fn zero() -> float { 0f } #[inline(always)] static pure fn zero() -> float { 0f }
#[inline(always)] static pure fn one() -> float { 1f } #[inline(always)] static pure fn one() -> float { 1f }
}
pub impl float: FloatConsts {
#[inline(always)] static pure fn pi() -> float { 3.14159265358979323846264338327950288 } #[inline(always)] static pure fn pi() -> float { 3.14159265358979323846264338327950288 }
#[inline(always)] static pure fn frac_pi_2() -> float { 1.57079632679489661923132169163975144 } #[inline(always)] static pure fn frac_pi_2() -> float { 1.57079632679489661923132169163975144 }
#[inline(always)] static pure fn frac_pi_4() -> float { 0.785398163397448309615660845819875721 } #[inline(always)] static pure fn frac_pi_4() -> float { 0.785398163397448309615660845819875721 }

View file

@ -70,6 +70,29 @@ pub impl<T> Quat<T> {
} }
} }
pub impl<T:Copy> Quat<T>: Dimensional<T> {
#[inline(always)]
static pure fn dim() -> uint { 4 }
#[inline(always)]
static pure fn size_of() -> uint { size_of::<Quat<T>>() }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
to_unsafe_ptr(&self[0])
}
}
pub impl<T:Copy> Quat<T>: Index<uint, T> {
#[inline(always)]
pure fn index(i: uint) -> T {
unsafe { do buf_as_slice(
transmute::<*Quat<T>, *T>(
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
}
}
}
pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> { pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> {
#[inline(always)] #[inline(always)]
static pure fn identity() -> Quat<T> { static pure fn identity() -> Quat<T> {
@ -87,22 +110,6 @@ pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> {
NumCast::zero()) NumCast::zero())
} }
#[inline(always)]
static pure fn dim() -> uint { 4 }
#[inline(always)]
static pure fn size_of() -> uint { size_of::<Quat<T>>() }
#[inline(always)]
pure fn to_ptr() -> *T {
to_unsafe_ptr(&self[0])
}
#[inline(always)]
pure fn neg() -> Quat<T> {
Quat::from_sv(-self.s, -self.v)
}
#[inline(always)] #[inline(always)]
pure fn mul_t(&self, value: T) -> Quat<T> { pure fn mul_t(&self, value: T) -> Quat<T> {
Quat::new(self[0] * value, Quat::new(self[0] * value,
@ -252,13 +259,10 @@ pub impl<T:Copy Num NumCast Exp Extent Ord InvTrig> Quat<T>: Quaternion<T> {
} }
} }
pub impl<T:Copy> Quat<T>: Index<uint, T> { pub impl<T:Copy Num> Quat<T>: Neg<Quat<T>> {
#[inline(always)] #[inline(always)]
pure fn index(i: uint) -> T { pure fn neg(&self) -> Quat<T> {
unsafe { do buf_as_slice( Quat::new(-self[0], -self[1], -self[2], -self[3])
transmute::<*Quat<T>, *T>(
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
}
} }
} }

View file

@ -105,13 +105,22 @@ pub impl<T:Copy> Vec2<T>: Vector<T> {
static pure fn from_value(value: T) -> Vec2<T> { static pure fn from_value(value: T) -> Vec2<T> {
Vec2::new(value, value) Vec2::new(value, value)
} }
}
pub impl<T:Copy> Vec2<T>: Dimensional<T> {
#[inline(always)] #[inline(always)]
static pure fn dim() -> uint { 2 } static pure fn dim() -> uint { 2 }
#[inline(always)] #[inline(always)]
static pure fn size_of() -> uint { size_of::<Vec2<T>>() } static pure fn size_of() -> uint { size_of::<Vec2<T>>() }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
ptr::to_unsafe_ptr(&self[0])
}
}
pub impl<T:Copy> Vec2<T>: Index<uint, T> {
#[inline(always)] #[inline(always)]
pure fn index(i: uint) -> T { pure fn index(i: uint) -> T {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(
@ -119,11 +128,6 @@ pub impl<T:Copy> Vec2<T>: Vector<T> {
to_unsafe_ptr(&self)), 2) |slice| { slice[i] } to_unsafe_ptr(&self)), 2) |slice| { slice[i] }
} }
} }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
ptr::to_unsafe_ptr(&self[0])
}
} }
pub impl<T:Copy Num NumCast> Vec2<T>: NumericVector<T> { pub impl<T:Copy Num NumCast> Vec2<T>: NumericVector<T> {
@ -139,11 +143,6 @@ pub impl<T:Copy Num NumCast> Vec2<T>: NumericVector<T> {
NumCast::zero()) NumCast::zero())
} }
#[inline(always)]
pure fn neg() -> Vec2<T> {
Vec2::new(-self[0], -self[1])
}
#[inline(always)] #[inline(always)]
pure fn mul_t(&self, value: T) -> Vec2<T> { pure fn mul_t(&self, value: T) -> Vec2<T> {
Vec2::new(self[0] * value, Vec2::new(self[0] * value,
@ -174,6 +173,13 @@ pub impl<T:Copy Num NumCast> Vec2<T>: NumericVector<T> {
self[1] * other[1] self[1] * other[1]
} }
} }
pub impl<T:Copy Num> Vec2<T>: Neg<Vec2<T>> {
#[inline(always)]
pure fn neg(&self) -> Vec2<T> {
Vec2::new(-self[0], -self[1])
}
}
pub impl<T:Copy Num NumCast Exp> Vec2<T>: GeometricVector<T> { pub impl<T:Copy Num NumCast Exp> Vec2<T>: GeometricVector<T> {
#[inline(always)] #[inline(always)]
@ -259,13 +265,22 @@ pub impl<T:Copy> Vec3<T>: Vector<T> {
static pure fn from_value(value: T) -> Vec3<T> { static pure fn from_value(value: T) -> Vec3<T> {
Vec3::new(value, value, value) Vec3::new(value, value, value)
} }
}
pub impl<T:Copy> Vec3<T>: Dimensional<T> {
#[inline(always)] #[inline(always)]
static pure fn dim() -> uint { 3 } static pure fn dim() -> uint { 3 }
#[inline(always)] #[inline(always)]
static pure fn size_of() -> uint { size_of::<Vec3<T>>() } static pure fn size_of() -> uint { size_of::<Vec3<T>>() }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
to_unsafe_ptr(&self[0])
}
}
pub impl<T:Copy> Vec3<T>: Index<uint, T> {
#[inline(always)] #[inline(always)]
pure fn index(i: uint) -> T { pure fn index(i: uint) -> T {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(
@ -273,11 +288,6 @@ pub impl<T:Copy> Vec3<T>: Vector<T> {
to_unsafe_ptr(&self)), 3) |slice| { slice[i] } to_unsafe_ptr(&self)), 3) |slice| { slice[i] }
} }
} }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
to_unsafe_ptr(&self[0])
}
} }
pub impl<T:Copy Num NumCast> Vec3<T>: NumericVector<T> { pub impl<T:Copy Num NumCast> Vec3<T>: NumericVector<T> {
@ -295,11 +305,6 @@ pub impl<T:Copy Num NumCast> Vec3<T>: NumericVector<T> {
NumCast::zero()) NumCast::zero())
} }
#[inline(always)]
pure fn neg() -> Vec3<T> {
Vec3::new(-self[0], -self[1], -self[2])
}
#[inline(always)] #[inline(always)]
pure fn mul_t(&self, value: T) -> Vec3<T> { pure fn mul_t(&self, value: T) -> Vec3<T> {
Vec3::new(self[0] * value, Vec3::new(self[0] * value,
@ -336,6 +341,13 @@ pub impl<T:Copy Num NumCast> Vec3<T>: NumericVector<T> {
} }
} }
pub impl<T:Copy Num> Vec3<T>: Neg<Vec3<T>> {
#[inline(always)]
pure fn neg(&self) -> Vec3<T> {
Vec3::new(-self[0], -self[1], -self[2])
}
}
pub impl<T:Copy Num> Vec3<T>: NumericVector3<T> { pub impl<T:Copy Num> Vec3<T>: NumericVector3<T> {
#[inline(always)] #[inline(always)]
pure fn cross(&self, other: &Vec3<T>) -> Vec3<T> { pure fn cross(&self, other: &Vec3<T>) -> Vec3<T> {
@ -431,13 +443,22 @@ pub impl<T:Copy> Vec4<T>: Vector<T> {
static pure fn from_value(value: T) -> Vec4<T> { static pure fn from_value(value: T) -> Vec4<T> {
Vec4::new(value, value, value, value) Vec4::new(value, value, value, value)
} }
}
pub impl<T:Copy> Vec4<T>: Dimensional<T> {
#[inline(always)] #[inline(always)]
static pure fn dim() -> uint { 4 } static pure fn dim() -> uint { 4 }
#[inline(always)] #[inline(always)]
static pure fn size_of() -> uint { size_of::<Vec4<T>>() } static pure fn size_of() -> uint { size_of::<Vec4<T>>() }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
to_unsafe_ptr(&self[0])
}
}
pub impl<T:Copy> Vec4<T>: Index<uint, T> {
#[inline(always)] #[inline(always)]
pure fn index(i: uint) -> T { pure fn index(i: uint) -> T {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(
@ -445,11 +466,6 @@ pub impl<T:Copy> Vec4<T>: Vector<T> {
to_unsafe_ptr(&self)), 4) |slice| { slice[i] } to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
} }
} }
#[inline(always)]
pure fn to_ptr(&self) -> *T {
to_unsafe_ptr(&self[0])
}
} }
pub impl<T:Copy Num NumCast> Vec4<T>: NumericVector<T> { pub impl<T:Copy Num NumCast> Vec4<T>: NumericVector<T> {
@ -469,11 +485,6 @@ pub impl<T:Copy Num NumCast> Vec4<T>: NumericVector<T> {
NumCast::zero()) NumCast::zero())
} }
#[inline(always)]
pure fn neg() -> Vec4<T> {
Vec4::new(-self[0], -self[1], -self[2], -self[3])
}
#[inline(always)] #[inline(always)]
pure fn mul_t(&self, value: T) -> Vec4<T> { pure fn mul_t(&self, value: T) -> Vec4<T> {
Vec4::new(self[0] * value, Vec4::new(self[0] * value,
@ -515,6 +526,13 @@ pub impl<T:Copy Num NumCast> Vec4<T>: NumericVector<T> {
} }
} }
pub impl<T:Copy Num> Vec4<T>: Neg<Vec4<T>> {
#[inline(always)]
pure fn neg(&self) -> Vec4<T> {
Vec4::new(-self[0], -self[1], -self[2], -self[3])
}
}
pub impl<T:Copy Num NumCast Exp> Vec4<T>: GeometricVector<T> { pub impl<T:Copy Num NumCast Exp> Vec4<T>: GeometricVector<T> {
#[inline(always)] #[inline(always)]
pure fn length2(&self) -> T { pure fn length2(&self) -> T {