Update to new impl Trait for Type syntax.

This commit is contained in:
Luqman Aden 2013-02-17 03:16:41 -05:00
parent 5929ba09cb
commit 97acf34dbb
7 changed files with 79 additions and 79 deletions

View file

@ -46,7 +46,7 @@ use mat::{
#[deriving_eq] #[deriving_eq]
pub struct Mat2<T> { x: Vec2<T>, y: Vec2<T> } pub struct Mat2<T> { x: Vec2<T>, y: Vec2<T> }
pub impl<T:Copy Float FuzzyEq<T>> Mat2<T>: Matrix<T, Vec2<T>> { pub impl<T:Copy Float FuzzyEq<T>> Matrix<T, Vec2<T>> for Mat2<T> {
#[inline(always)] #[inline(always)]
pure fn col(&self, i: uint) -> Vec2<T> { self[i] } pure fn col(&self, i: uint) -> Vec2<T> { self[i] }
@ -208,7 +208,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Mat2<T>: Matrix<T, Vec2<T>> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Mat2<T>: MutableMatrix<T, Vec2<T>> { pub impl<T:Copy Float FuzzyEq<T>> MutableMatrix<T, Vec2<T>> for Mat2<T> {
#[inline(always)] #[inline(always)]
fn col_mut(&mut self, i: uint) -> &self/mut Vec2<T> { fn col_mut(&mut self, i: uint) -> &self/mut Vec2<T> {
match i { match i {
@ -278,7 +278,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Mat2<T>: MutableMatrix<T, Vec2<T>> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Mat2<T>: Matrix2<T, Vec2<T>> { pub impl<T:Copy Float FuzzyEq<T>> Matrix2<T, Vec2<T>> for Mat2<T> {
/** /**
* Construct a 2 x 2 matrix * Construct a 2 x 2 matrix
* *
@ -379,7 +379,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Mat2<T>: Matrix2<T, Vec2<T>> {
} }
} }
pub impl<T:Copy> Mat2<T>: Index<uint, Vec2<T>> { pub impl<T:Copy> Index<uint, Vec2<T>> for Mat2<T> {
#[inline(always)] #[inline(always)]
pure fn index(&self, i: uint) -> Vec2<T> { pure fn index(&self, i: uint) -> Vec2<T> {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(
@ -389,14 +389,14 @@ pub impl<T:Copy> Mat2<T>: Index<uint, Vec2<T>> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Mat2<T>: Neg<Mat2<T>> { pub impl<T:Copy Float FuzzyEq<T>> Neg<Mat2<T>> for Mat2<T> {
#[inline(always)] #[inline(always)]
pure fn neg(&self) -> Mat2<T> { pure fn neg(&self) -> Mat2<T> {
Matrix2::from_cols(-self[0], -self[1]) Matrix2::from_cols(-self[0], -self[1])
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Mat2<T>: FuzzyEq<T> { pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Mat2<T> {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(&self, other: &Mat2<T>) -> bool { pure fn fuzzy_eq(&self, other: &Mat2<T>) -> bool {
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON)) self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
@ -421,7 +421,7 @@ pub impl mat2 {
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c1r0: f32, c1r1: f32) #[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c1r0: f32, c1r1: f32)
-> mat2 { Matrix2::new(c0r0, c0r1, c1r0, c1r1) } -> mat2 { Matrix2::new(c0r0, c0r1, c1r0, c1r1) }
#[inline(always)] static pure fn from_cols(c0: vec2, c1: vec2) #[inline(always)] static pure fn from_cols(c0: vec2, c1: vec2)
-> mat2 { Matrix2::from_cols(move c0, move c1) } -> mat2 { Matrix2::from_cols(c0, c1) }
#[inline(always)] static pure fn from_value(v: f32) -> mat2 { Matrix::from_value(v) } #[inline(always)] static pure fn from_value(v: f32) -> mat2 { Matrix::from_value(v) }
#[inline(always)] static pure fn identity() -> mat2 { Matrix::identity() } #[inline(always)] static pure fn identity() -> mat2 { Matrix::identity() }
@ -439,7 +439,7 @@ pub impl dmat2 {
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c1r0: f64, c1r1: f64) #[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c1r0: f64, c1r1: f64)
-> dmat2 { Matrix2::new(c0r0, c0r1, c1r0, c1r1) } -> dmat2 { Matrix2::new(c0r0, c0r1, c1r0, c1r1) }
#[inline(always)] static pure fn from_cols(c0: dvec2, c1: dvec2) #[inline(always)] static pure fn from_cols(c0: dvec2, c1: dvec2)
-> dmat2 { Matrix2::from_cols(move c0, move c1) } -> dmat2 { Matrix2::from_cols(c0, c1) }
#[inline(always)] static pure fn from_value(v: f64) -> dmat2 { Matrix::from_value(v) } #[inline(always)] static pure fn from_value(v: f64) -> dmat2 { Matrix::from_value(v) }
#[inline(always)] static pure fn identity() -> dmat2 { Matrix::identity() } #[inline(always)] static pure fn identity() -> dmat2 { Matrix::identity() }

View file

@ -48,7 +48,7 @@ use mat::{
#[deriving_eq] #[deriving_eq]
pub struct Mat3<T> { x: Vec3<T>, y: Vec3<T>, z: Vec3<T> } pub struct Mat3<T> { x: Vec3<T>, y: Vec3<T>, z: Vec3<T> }
pub impl<T:Copy Float FuzzyEq<T>> Mat3<T>: Matrix<T, Vec3<T>> { pub impl<T:Copy Float FuzzyEq<T>> Matrix<T, Vec3<T>> for Mat3<T> {
#[inline(always)] #[inline(always)]
pure fn col(&self, i: uint) -> Vec3<T> { self[i] } pure fn col(&self, i: uint) -> Vec3<T> { self[i] }
@ -248,7 +248,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Mat3<T>: Matrix<T, Vec3<T>> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Mat3<T>: Matrix3<T, Vec3<T>> { pub impl<T:Copy Float FuzzyEq<T>> Matrix3<T, Vec3<T>> for Mat3<T> {
/** /**
* Construct a 3 x 3 matrix * Construct a 3 x 3 matrix
* *
@ -475,7 +475,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Mat3<T>: Matrix3<T, Vec3<T>> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Mat3<T>: MutableMatrix<T, Vec3<T>> { pub impl<T:Copy Float FuzzyEq<T>> MutableMatrix<T, Vec3<T>> for Mat3<T> {
#[inline(always)] #[inline(always)]
fn col_mut(&mut self, i: uint) -> &self/mut Vec3<T> { fn col_mut(&mut self, i: uint) -> &self/mut Vec3<T> {
match i { match i {
@ -556,7 +556,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Mat3<T>: MutableMatrix<T, Vec3<T>> {
} }
} }
pub impl<T:Copy> Mat3<T>: Index<uint, Vec3<T>> { pub impl<T:Copy> Index<uint, Vec3<T>> for Mat3<T> {
#[inline(always)] #[inline(always)]
pure fn index(&self, i: uint) -> Vec3<T> { pure fn index(&self, i: uint) -> Vec3<T> {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(
@ -566,14 +566,14 @@ pub impl<T:Copy> Mat3<T>: Index<uint, Vec3<T>> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Mat3<T>: Neg<Mat3<T>> { pub impl<T:Copy Float FuzzyEq<T>> Neg<Mat3<T>> for Mat3<T> {
#[inline(always)] #[inline(always)]
pure fn neg(&self) -> Mat3<T> { pure fn neg(&self) -> Mat3<T> {
Matrix3::from_cols(-self[0], -self[1], -self[2]) Matrix3::from_cols(-self[0], -self[1], -self[2])
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Mat3<T>: FuzzyEq<T> { pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Mat3<T> {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(&self, other: &Mat3<T>) -> bool { pure fn fuzzy_eq(&self, other: &Mat3<T>) -> bool {
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON)) self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
@ -599,7 +599,7 @@ pub impl mat3 {
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c1r0: f32, c1r1: f32, c1r2: f32, c2r0: f32, c2r1: f32, c2r2: f32) #[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c1r0: f32, c1r1: f32, c1r2: f32, c2r0: f32, c2r1: f32, c2r2: f32)
-> mat3 { Matrix3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) } -> mat3 { Matrix3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
#[inline(always)] static pure fn from_cols(c0: vec3, c1: vec3, c2: vec3) #[inline(always)] static pure fn from_cols(c0: vec3, c1: vec3, c2: vec3)
-> mat3 { Matrix3::from_cols(move c0, move c1, move c2) } -> mat3 { Matrix3::from_cols(c0, c1, c2) }
#[inline(always)] static pure fn from_value(v: f32) -> mat3 { Matrix::from_value(v) } #[inline(always)] static pure fn from_value(v: f32) -> mat3 { Matrix::from_value(v) }
#[inline(always)] static pure fn identity() -> mat3 { Matrix::identity() } #[inline(always)] static pure fn identity() -> mat3 { Matrix::identity() }
@ -624,7 +624,7 @@ pub impl dmat3 {
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c1r0: f64, c1r1: f64, c1r2: f64, c2r0: f64, c2r1: f64, c2r2: f64) #[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c1r0: f64, c1r1: f64, c1r2: f64, c2r0: f64, c2r1: f64, c2r2: f64)
-> dmat3 { Matrix3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) } -> dmat3 { Matrix3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
#[inline(always)] static pure fn from_cols(c0: dvec3, c1: dvec3, c2: dvec3) #[inline(always)] static pure fn from_cols(c0: dvec3, c1: dvec3, c2: dvec3)
-> dmat3 { Matrix3::from_cols(move c0, move c1, move c2) } -> dmat3 { Matrix3::from_cols(c0, c1, c2) }
#[inline(always)] static pure fn from_value(v: f64) -> dmat3 { Matrix::from_value(v) } #[inline(always)] static pure fn from_value(v: f64) -> dmat3 { Matrix::from_value(v) }
#[inline(always)] static pure fn identity() -> dmat3 { Matrix::identity() } #[inline(always)] static pure fn identity() -> dmat3 { Matrix::identity() }

View file

@ -45,7 +45,7 @@ use mat::{
#[deriving_eq] #[deriving_eq]
pub struct Mat4<T> { x: Vec4<T>, y: Vec4<T>, z: Vec4<T>, w: Vec4<T> } pub struct Mat4<T> { x: Vec4<T>, y: Vec4<T>, z: Vec4<T>, w: Vec4<T> }
pub impl<T:Copy Float FuzzyEq<T>> Mat4<T>: Matrix<T, Vec4<T>> { pub impl<T:Copy Float FuzzyEq<T>> Matrix<T, Vec4<T>> for Mat4<T> {
#[inline(always)] #[inline(always)]
pure fn col(&self, i: uint) -> Vec4<T> { self[i] } pure fn col(&self, i: uint) -> Vec4<T> { self[i] }
@ -332,7 +332,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Mat4<T>: Matrix<T, Vec4<T>> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Mat4<T>: Matrix4<T, Vec4<T>> { pub impl<T:Copy Float FuzzyEq<T>> Matrix4<T, Vec4<T>> for Mat4<T> {
/** /**
* Construct a 4 x 4 matrix * Construct a 4 x 4 matrix
* *
@ -399,7 +399,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Mat4<T>: Matrix4<T, Vec4<T>> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Mat4<T>: MutableMatrix<T, Vec4<T>> { pub impl<T:Copy Float FuzzyEq<T>> MutableMatrix<T, Vec4<T>> for Mat4<T> {
#[inline(always)] #[inline(always)]
fn col_mut(&mut self, i: uint) -> &self/mut Vec4<T> { fn col_mut(&mut self, i: uint) -> &self/mut Vec4<T> {
match i { match i {
@ -492,14 +492,14 @@ pub impl<T:Copy Float FuzzyEq<T>> Mat4<T>: MutableMatrix<T, Vec4<T>> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Mat4<T>: Neg<Mat4<T>> { pub impl<T:Copy Float FuzzyEq<T>> Neg<Mat4<T>> for Mat4<T> {
#[inline(always)] #[inline(always)]
pure fn neg(&self) -> Mat4<T> { pure fn neg(&self) -> Mat4<T> {
Matrix4::from_cols(-self[0], -self[1], -self[2], -self[3]) Matrix4::from_cols(-self[0], -self[1], -self[2], -self[3])
} }
} }
pub impl<T:Copy> Mat4<T>: Index<uint, Vec4<T>> { pub impl<T:Copy> Index<uint, Vec4<T>> for Mat4<T> {
#[inline(always)] #[inline(always)]
pure fn index(&self, i: uint) -> Vec4<T> { pure fn index(&self, i: uint) -> Vec4<T> {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(
@ -509,7 +509,7 @@ pub impl<T:Copy> Mat4<T>: Index<uint, Vec4<T>> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Mat4<T>: FuzzyEq<T> { pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Mat4<T> {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(&self, other: &Mat4<T>) -> bool { pure fn fuzzy_eq(&self, other: &Mat4<T>) -> bool {
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON)) self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
@ -536,7 +536,7 @@ pub impl mat4 {
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c0r3: f32, c1r0: f32, c1r1: f32, c1r2: f32, c1r3: f32, c2r0: f32, c2r1: f32, c2r2: f32, c2r3: f32, c3r0: f32, c3r1: f32, c3r2: f32, c3r3: f32) #[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c0r3: f32, c1r0: f32, c1r1: f32, c1r2: f32, c1r3: f32, c2r0: f32, c2r1: f32, c2r2: f32, c2r3: f32, c3r0: f32, c3r1: f32, c3r2: f32, c3r3: f32)
-> mat4 { Matrix4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) } -> mat4 { Matrix4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
#[inline(always)] static pure fn from_cols(c0: vec4, c1: vec4, c2: vec4, c3: vec4) #[inline(always)] static pure fn from_cols(c0: vec4, c1: vec4, c2: vec4, c3: vec4)
-> mat4 { Matrix4::from_cols(move c0, move c1, move c2, move c3) } -> mat4 { Matrix4::from_cols(c0, c1, c2, c3) }
#[inline(always)] static pure fn from_value(v: f32) -> mat4 { Matrix::from_value(v) } #[inline(always)] static pure fn from_value(v: f32) -> mat4 { Matrix::from_value(v) }
#[inline(always)] static pure fn identity() -> mat4 { Matrix::identity() } #[inline(always)] static pure fn identity() -> mat4 { Matrix::identity() }
@ -552,7 +552,7 @@ pub impl dmat4 {
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c0r3: f64, c1r0: f64, c1r1: f64, c1r2: f64, c1r3: f64, c2r0: f64, c2r1: f64, c2r2: f64, c2r3: f64, c3r0: f64, c3r1: f64, c3r2: f64, c3r3: f64) #[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c0r3: f64, c1r0: f64, c1r1: f64, c1r2: f64, c1r3: f64, c2r0: f64, c2r1: f64, c2r2: f64, c2r3: f64, c3r0: f64, c3r1: f64, c3r2: f64, c3r3: f64)
-> dmat4 { Matrix4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) } -> dmat4 { Matrix4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
#[inline(always)] static pure fn from_cols(c0: dvec4, c1: dvec4, c2: dvec4, c3: dvec4) #[inline(always)] static pure fn from_cols(c0: dvec4, c1: dvec4, c2: dvec4, c3: dvec4)
-> dmat4 { Matrix4::from_cols(move c0, move c1, move c2, move c3) } -> dmat4 { Matrix4::from_cols(c0, c1, c2, c3) }
#[inline(always)] static pure fn from_value(v: f64) -> dmat4 { Matrix::from_value(v) } #[inline(always)] static pure fn from_value(v: f64) -> dmat4 { Matrix::from_value(v) }
#[inline(always)] static pure fn identity() -> dmat4 { Matrix::identity() } #[inline(always)] static pure fn identity() -> dmat4 { Matrix::identity() }

View file

@ -390,7 +390,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Quat<T> {
} }
} }
pub impl<T:Copy> Quat<T>: Index<uint, T> { pub impl<T:Copy> Index<uint, T> for Quat<T> {
#[inline(always)] #[inline(always)]
pure fn index(&self, i: uint) -> T { pure fn index(&self, i: uint) -> T {
unsafe { do buf_as_slice( unsafe { do buf_as_slice(
@ -400,14 +400,14 @@ pub impl<T:Copy> Quat<T>: Index<uint, T> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Quat<T>: Neg<Quat<T>> { pub impl<T:Copy Float FuzzyEq<T>> Neg<Quat<T>> for Quat<T> {
#[inline(always)] #[inline(always)]
pure fn neg(&self) -> Quat<T> { pure fn neg(&self) -> Quat<T> {
Quat::new(-self[0], -self[1], -self[2], -self[3]) Quat::new(-self[0], -self[1], -self[2], -self[3])
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Quat<T>: FuzzyEq<T> { pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Quat<T> {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(&self, other: &Quat<T>) -> bool { pure fn fuzzy_eq(&self, other: &Quat<T>) -> bool {
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON)) self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))

View file

@ -43,7 +43,7 @@ use vec::{
#[deriving_eq] #[deriving_eq]
pub struct Vec2<T> { x: T, y: T } pub struct Vec2<T> { x: T, y: T }
pub impl<T:Copy Eq> Vec2<T>: Vector<T> { pub impl<T:Copy Eq> Vector<T> for Vec2<T> {
#[inline(always)] #[inline(always)]
static pure fn from_value(value: T) -> Vec2<T> { static pure fn from_value(value: T) -> Vec2<T> {
Vector2::new(value, value) Vector2::new(value, value)
@ -59,21 +59,21 @@ pub impl<T:Copy Eq> Vec2<T>: Vector<T> {
} }
} }
pub impl<T> Vec2<T>: Vector2<T> { pub impl<T> Vector2<T> for Vec2<T> {
#[inline(always)] #[inline(always)]
static pure fn new(x: T, y: T ) -> Vec2<T> { static pure fn new(x: T, y: T ) -> Vec2<T> {
Vec2 { x: x, y: y } Vec2 { x: x, y: y }
} }
} }
pub impl<T:Copy Eq> Vec2<T>: Index<uint, T> { pub impl<T:Copy Eq> Index<uint, T> for Vec2<T> {
#[inline(always)] #[inline(always)]
pure fn index(&self, i: uint) -> T { pure fn index(&self, i: uint) -> T {
unsafe { do buf_as_slice(self.to_ptr(), 2) |slice| { slice[i] } } unsafe { do buf_as_slice(self.to_ptr(), 2) |slice| { slice[i] } }
} }
} }
pub impl<T:Copy> Vec2<T>: MutableVector<T> { pub impl<T:Copy> MutableVector<T> for Vec2<T> {
#[inline(always)] #[inline(always)]
fn index_mut(&mut self, i: uint) -> &self/mut T { fn index_mut(&mut self, i: uint) -> &self/mut T {
match i { match i {
@ -90,7 +90,7 @@ pub impl<T:Copy> Vec2<T>: MutableVector<T> {
} }
} }
pub impl<T:Copy Number> Vec2<T>: NumericVector<T> { pub impl<T:Copy Number> NumericVector<T> for Vec2<T> {
#[inline(always)] #[inline(always)]
static pure fn identity() -> Vec2<T> { static pure fn identity() -> Vec2<T> {
Vector2::new(one::<T>(), one::<T>()) Vector2::new(one::<T>(), one::<T>())
@ -150,14 +150,14 @@ pub impl<T:Copy Number> Vec2<T>: NumericVector<T> {
} }
} }
pub impl<T:Copy Number> Vec2<T>: Neg<Vec2<T>> { pub impl<T:Copy Number> Neg<Vec2<T>> for Vec2<T> {
#[inline(always)] #[inline(always)]
pure fn neg(&self) -> Vec2<T> { pure fn neg(&self) -> Vec2<T> {
Vector2::new(-self[0], -self[1]) Vector2::new(-self[0], -self[1])
} }
} }
pub impl<T:Copy Number> Vec2<T>: NumericVector2<T> { pub impl<T:Copy Number> NumericVector2<T> for Vec2<T> {
#[inline(always)] #[inline(always)]
static pure fn unit_x() -> Vec2<T> { static pure fn unit_x() -> Vec2<T> {
Vector2::new(one::<T>(), zero::<T>()) Vector2::new(one::<T>(), zero::<T>())
@ -174,7 +174,7 @@ pub impl<T:Copy Number> Vec2<T>: NumericVector2<T> {
} }
} }
pub impl<T:Copy Number> Vec2<T>: MutableNumericVector<&self/T> { pub impl<T:Copy Number> MutableNumericVector<&self/T> for Vec2<T> {
#[inline(always)] #[inline(always)]
fn neg_self(&mut self) { fn neg_self(&mut self) {
*self.index_mut(0) = -*self.index_mut(0); *self.index_mut(0) = -*self.index_mut(0);
@ -218,14 +218,14 @@ pub impl<T:Copy Number> Vec2<T>: MutableNumericVector<&self/T> {
} }
} }
pub impl<T:Copy Number> Vec2<T>: ToHomogeneous<Vec3<T>> { pub impl<T:Copy Number> ToHomogeneous<Vec3<T>> for Vec2<T> {
#[inline(always)] #[inline(always)]
pure fn to_homogeneous(&self) -> Vec3<T> { pure fn to_homogeneous(&self) -> Vec3<T> {
Vector3::new(self.x, self.y, zero()) Vector3::new(self.x, self.y, zero())
} }
} }
pub impl<T:Copy Float> Vec2<T>: EuclideanVector<T> { pub impl<T:Copy Float> EuclideanVector<T> for Vec2<T> {
#[inline(always)] #[inline(always)]
pure fn length2(&self) -> T { pure fn length2(&self) -> T {
self.dot(self) self.dot(self)
@ -267,7 +267,7 @@ pub impl<T:Copy Float> Vec2<T>: EuclideanVector<T> {
} }
} }
pub impl<T:Copy Float> Vec2<T>: MutableEuclideanVector<&self/T> { pub impl<T:Copy Float> MutableEuclideanVector<&self/T> for Vec2<T> {
#[inline(always)] #[inline(always)]
fn normalize_self(&mut self) { fn normalize_self(&mut self) {
let n = one::<T>() / self.length(); let n = one::<T>() / self.length();
@ -285,7 +285,7 @@ pub impl<T:Copy Float> Vec2<T>: MutableEuclideanVector<&self/T> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Vec2<T>: FuzzyEq<T> { pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Vec2<T> {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(&self, other: &Vec2<T>) -> bool { pure fn fuzzy_eq(&self, other: &Vec2<T>) -> bool {
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON)) self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
@ -298,7 +298,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Vec2<T>: FuzzyEq<T> {
} }
} }
pub impl<T:Copy Ord Eq> Vec2<T>: OrdinalVector<T, Vec2<bool>> { pub impl<T:Copy Ord Eq> OrdinalVector<T, Vec2<bool>> for Vec2<T> {
#[inline(always)] #[inline(always)]
pure fn less_than(&self, other: &Vec2<T>) -> Vec2<bool> { pure fn less_than(&self, other: &Vec2<T>) -> Vec2<bool> {
Vector2::new(self[0] < other[0], Vector2::new(self[0] < other[0],
@ -324,7 +324,7 @@ pub impl<T:Copy Ord Eq> Vec2<T>: OrdinalVector<T, Vec2<bool>> {
} }
} }
pub impl<T:Copy Eq> Vec2<T>: EquableVector<T, Vec2<bool>> { pub impl<T:Copy Eq> EquableVector<T, Vec2<bool>> for Vec2<T> {
#[inline(always)] #[inline(always)]
pure fn equal(&self, other: &Vec2<T>) -> Vec2<bool> { pure fn equal(&self, other: &Vec2<T>) -> Vec2<bool> {
Vector2::new(self[0] == other[0], Vector2::new(self[0] == other[0],
@ -338,7 +338,7 @@ pub impl<T:Copy Eq> Vec2<T>: EquableVector<T, Vec2<bool>> {
} }
} }
pub impl Vec2<bool>: BooleanVector { pub impl BooleanVector for Vec2<bool> {
#[inline(always)] #[inline(always)]
pure fn any(&self) -> bool { pure fn any(&self) -> bool {
self[0] || self[1] self[0] || self[1]

View file

@ -45,7 +45,7 @@ use vec::{
#[deriving_eq] #[deriving_eq]
pub struct Vec3<T> { x: T, y: T, z: T } pub struct Vec3<T> { x: T, y: T, z: T }
pub impl<T:Copy Eq> Vec3<T>: Vector<T> { pub impl<T:Copy Eq> Vector<T> for Vec3<T> {
#[inline(always)] #[inline(always)]
static pure fn from_value(value: T) -> Vec3<T> { static pure fn from_value(value: T) -> Vec3<T> {
Vector3::new(value, value, value) Vector3::new(value, value, value)
@ -61,21 +61,21 @@ pub impl<T:Copy Eq> Vec3<T>: Vector<T> {
} }
} }
pub impl<T> Vec3<T>: Vector3<T> { pub impl<T> Vector3<T> for Vec3<T> {
#[inline(always)] #[inline(always)]
static pure fn new(x: T, y: T, z: T) -> Vec3<T> { static pure fn new(x: T, y: T, z: T) -> Vec3<T> {
Vec3 { x: x, y: y, z: z } Vec3 { x: x, y: y, z: z }
} }
} }
pub impl<T:Copy Eq> Vec3<T>: Index<uint, T> { pub impl<T:Copy Eq> Index<uint, T> for Vec3<T> {
#[inline(always)] #[inline(always)]
pure fn index(&self, i: uint) -> T { pure fn index(&self, i: uint) -> T {
unsafe { do buf_as_slice(self.to_ptr(), 3) |slice| { slice[i] } } unsafe { do buf_as_slice(self.to_ptr(), 3) |slice| { slice[i] } }
} }
} }
pub impl<T:Copy> Vec3<T>: MutableVector<T> { pub impl<T:Copy> MutableVector<T> for Vec3<T> {
#[inline(always)] #[inline(always)]
fn index_mut(&mut self, i: uint) -> &self/mut T { fn index_mut(&mut self, i: uint) -> &self/mut T {
match i { match i {
@ -93,7 +93,7 @@ pub impl<T:Copy> Vec3<T>: MutableVector<T> {
} }
} }
pub impl<T:Copy Number> Vec3<T>: NumericVector<T> { pub impl<T:Copy Number> NumericVector<T> for Vec3<T> {
#[inline(always)] #[inline(always)]
static pure fn identity() -> Vec3<T> { static pure fn identity() -> Vec3<T> {
Vector3::new(one::<T>(), one::<T>(), one::<T>()) Vector3::new(one::<T>(), one::<T>(), one::<T>())
@ -161,14 +161,14 @@ pub impl<T:Copy Number> Vec3<T>: NumericVector<T> {
} }
} }
pub impl<T:Copy Number> Vec3<T>: Neg<Vec3<T>> { pub impl<T:Copy Number> Neg<Vec3<T>> for Vec3<T> {
#[inline(always)] #[inline(always)]
pure fn neg(&self) -> Vec3<T> { pure fn neg(&self) -> Vec3<T> {
Vector3::new(-self[0], -self[1], -self[2]) Vector3::new(-self[0], -self[1], -self[2])
} }
} }
pub impl<T:Copy Number> Vec3<T>: NumericVector3<T> { pub impl<T:Copy Number> NumericVector3<T> for Vec3<T> {
#[inline(always)] #[inline(always)]
static pure fn unit_x() -> Vec3<T> { static pure fn unit_x() -> Vec3<T> {
Vector3::new(one::<T>(), zero::<T>(), zero::<T>()) Vector3::new(one::<T>(), zero::<T>(), zero::<T>())
@ -192,7 +192,7 @@ pub impl<T:Copy Number> Vec3<T>: NumericVector3<T> {
} }
} }
pub impl<T:Copy Number> Vec3<T>: MutableNumericVector<&self/T> { pub impl<T:Copy Number> MutableNumericVector<&self/T> for Vec3<T> {
#[inline(always)] #[inline(always)]
fn neg_self(&mut self) { fn neg_self(&mut self) {
*self.index_mut(0) = -*self.index_mut(0); *self.index_mut(0) = -*self.index_mut(0);
@ -243,21 +243,21 @@ pub impl<T:Copy Number> Vec3<T>: MutableNumericVector<&self/T> {
} }
} }
pub impl<T:Copy Number> Vec3<T>: MutableNumericVector3<&self/T> { pub impl<T:Copy Number> MutableNumericVector3<&self/T> for Vec3<T> {
#[inline(always)] #[inline(always)]
fn cross_self(&mut self, other: &Vec3<T>) { fn cross_self(&mut self, other: &Vec3<T>) {
*self = self.cross(other); *self = self.cross(other);
} }
} }
pub impl<T:Copy Number> Vec3<T>: ToHomogeneous<Vec4<T>> { pub impl<T:Copy Number> ToHomogeneous<Vec4<T>> for Vec3<T> {
#[inline(always)] #[inline(always)]
pure fn to_homogeneous(&self) -> Vec4<T> { pure fn to_homogeneous(&self) -> Vec4<T> {
Vector4::new(self.x, self.y, self.z, zero()) Vector4::new(self.x, self.y, self.z, zero())
} }
} }
pub impl<T:Copy Float> Vec3<T>: EuclideanVector<T> { pub impl<T:Copy Float> EuclideanVector<T> for Vec3<T> {
#[inline(always)] #[inline(always)]
pure fn length2(&self) -> T { pure fn length2(&self) -> T {
self.dot(self) self.dot(self)
@ -299,7 +299,7 @@ pub impl<T:Copy Float> Vec3<T>: EuclideanVector<T> {
} }
} }
pub impl<T:Copy Float> Vec3<T>: MutableEuclideanVector<&self/T> { pub impl<T:Copy Float> MutableEuclideanVector<&self/T> for Vec3<T> {
#[inline(always)] #[inline(always)]
fn normalize_self(&mut self) { fn normalize_self(&mut self) {
let n = one::<T>() / self.length(); let n = one::<T>() / self.length();
@ -317,7 +317,7 @@ pub impl<T:Copy Float> Vec3<T>: MutableEuclideanVector<&self/T> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Vec3<T>: FuzzyEq<T> { pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Vec3<T> {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(&self, other: &Vec3<T>) -> bool { pure fn fuzzy_eq(&self, other: &Vec3<T>) -> bool {
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON)) self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
@ -331,7 +331,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Vec3<T>: FuzzyEq<T> {
} }
} }
pub impl<T:Copy Ord Eq> Vec3<T>: OrdinalVector<T, Vec3<bool>> { pub impl<T:Copy Ord Eq> OrdinalVector<T, Vec3<bool>> for Vec3<T> {
#[inline(always)] #[inline(always)]
pure fn less_than(&self, other: &Vec3<T>) -> Vec3<bool> { pure fn less_than(&self, other: &Vec3<T>) -> Vec3<bool> {
Vector3::new(self[0] < other[0], Vector3::new(self[0] < other[0],
@ -361,7 +361,7 @@ pub impl<T:Copy Ord Eq> Vec3<T>: OrdinalVector<T, Vec3<bool>> {
} }
} }
pub impl<T:Copy Eq> Vec3<T>: EquableVector<T, Vec3<bool>> { pub impl<T:Copy Eq> EquableVector<T, Vec3<bool>> for Vec3<T> {
#[inline(always)] #[inline(always)]
pure fn equal(&self, other: &Vec3<T>) -> Vec3<bool> { pure fn equal(&self, other: &Vec3<T>) -> Vec3<bool> {
Vector3::new(self[0] == other[0], Vector3::new(self[0] == other[0],
@ -377,7 +377,7 @@ pub impl<T:Copy Eq> Vec3<T>: EquableVector<T, Vec3<bool>> {
} }
} }
pub impl Vec3<bool>: BooleanVector { pub impl BooleanVector for Vec3<bool> {
#[inline(always)] #[inline(always)]
pure fn any(&self) -> bool { pure fn any(&self) -> bool {
self[0] || self[1] || self[2] self[0] || self[1] || self[2]

View file

@ -43,7 +43,7 @@ use vec::{
#[deriving_eq] #[deriving_eq]
pub struct Vec4<T> { x: T, y: T, z: T, w: T } pub struct Vec4<T> { x: T, y: T, z: T, w: T }
pub impl<T:Copy Eq> Vec4<T>: Vector<T> { pub impl<T:Copy Eq> Vector<T> for Vec4<T> {
#[inline(always)] #[inline(always)]
static pure fn from_value(value: T) -> Vec4<T> { static pure fn from_value(value: T) -> Vec4<T> {
Vector4::new(value, value, value, value) Vector4::new(value, value, value, value)
@ -59,21 +59,21 @@ pub impl<T:Copy Eq> Vec4<T>: Vector<T> {
} }
} }
pub impl<T> Vec4<T>: Vector4<T> { pub impl<T> Vector4<T> for Vec4<T> {
#[inline(always)] #[inline(always)]
static pure fn new(x: T, y: T, z: T, w: T) -> Vec4<T> { static pure fn new(x: T, y: T, z: T, w: T) -> Vec4<T> {
Vec4 { x: x, y: y, z: z, w: w } Vec4 { x: x, y: y, z: z, w: w }
} }
} }
pub impl<T:Copy Eq> Vec4<T>: Index<uint, T> { pub impl<T:Copy Eq> Index<uint, T> for Vec4<T> {
#[inline(always)] #[inline(always)]
pure fn index(&self, i: uint) -> T { pure fn index(&self, i: uint) -> T {
unsafe { do buf_as_slice(self.to_ptr(), 4) |slice| { slice[i] } } unsafe { do buf_as_slice(self.to_ptr(), 4) |slice| { slice[i] } }
} }
} }
pub impl<T:Copy> Vec4<T>: MutableVector<T> { pub impl<T:Copy> MutableVector<T> for Vec4<T> {
#[inline(always)] #[inline(always)]
fn index_mut(&mut self, i: uint) -> &self/mut T { fn index_mut(&mut self, i: uint) -> &self/mut T {
match i { match i {
@ -92,7 +92,7 @@ pub impl<T:Copy> Vec4<T>: MutableVector<T> {
} }
} }
pub impl<T:Copy Number> Vec4<T>: NumericVector<T> { pub impl<T:Copy Number> NumericVector<T> for Vec4<T> {
#[inline(always)] #[inline(always)]
static pure fn identity() -> Vec4<T> { static pure fn identity() -> Vec4<T> {
Vector4::new(one::<T>(), one::<T>(), one::<T>(), one::<T>()) Vector4::new(one::<T>(), one::<T>(), one::<T>(), one::<T>())
@ -168,14 +168,14 @@ pub impl<T:Copy Number> Vec4<T>: NumericVector<T> {
} }
} }
pub impl<T:Copy Number> Vec4<T>: Neg<Vec4<T>> { pub impl<T:Copy Number> Neg<Vec4<T>> for Vec4<T> {
#[inline(always)] #[inline(always)]
pure fn neg(&self) -> Vec4<T> { pure fn neg(&self) -> Vec4<T> {
Vector4::new(-self[0], -self[1], -self[2], -self[3]) Vector4::new(-self[0], -self[1], -self[2], -self[3])
} }
} }
pub impl<T:Copy Number> Vec4<T>: NumericVector4<T> { pub impl<T:Copy Number> NumericVector4<T> for Vec4<T> {
#[inline(always)] #[inline(always)]
static pure fn unit_x() -> Vec4<T> { static pure fn unit_x() -> Vec4<T> {
Vector4::new(one::<T>(), zero::<T>(), zero::<T>(), zero::<T>()) Vector4::new(one::<T>(), zero::<T>(), zero::<T>(), zero::<T>())
@ -197,7 +197,7 @@ pub impl<T:Copy Number> Vec4<T>: NumericVector4<T> {
} }
} }
pub impl<T:Copy Number> Vec4<T>: MutableNumericVector<&self/T> { pub impl<T:Copy Number> MutableNumericVector<&self/T> for Vec4<T> {
#[inline(always)] #[inline(always)]
fn neg_self(&mut self) { fn neg_self(&mut self) {
*self.index_mut(0) = -*self.index_mut(0); *self.index_mut(0) = -*self.index_mut(0);
@ -255,7 +255,7 @@ pub impl<T:Copy Number> Vec4<T>: MutableNumericVector<&self/T> {
} }
} }
pub impl<T:Copy Float> Vec4<T>: EuclideanVector<T> { pub impl<T:Copy Float> EuclideanVector<T> for Vec4<T> {
#[inline(always)] #[inline(always)]
pure fn length2(&self) -> T { pure fn length2(&self) -> T {
self.dot(self) self.dot(self)
@ -297,7 +297,7 @@ pub impl<T:Copy Float> Vec4<T>: EuclideanVector<T> {
} }
} }
pub impl<T:Copy Float> Vec4<T>: MutableEuclideanVector<&self/T> { pub impl<T:Copy Float> MutableEuclideanVector<&self/T> for Vec4<T> {
#[inline(always)] #[inline(always)]
fn normalize_self(&mut self) { fn normalize_self(&mut self) {
let n = one::<T>() / self.length(); let n = one::<T>() / self.length();
@ -315,7 +315,7 @@ pub impl<T:Copy Float> Vec4<T>: MutableEuclideanVector<&self/T> {
} }
} }
pub impl<T:Copy Float FuzzyEq<T>> Vec4<T>: FuzzyEq<T> { pub impl<T:Copy Float FuzzyEq<T>> FuzzyEq<T> for Vec4<T> {
#[inline(always)] #[inline(always)]
pure fn fuzzy_eq(&self, other: &Vec4<T>) -> bool { pure fn fuzzy_eq(&self, other: &Vec4<T>) -> bool {
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON)) self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
@ -330,7 +330,7 @@ pub impl<T:Copy Float FuzzyEq<T>> Vec4<T>: FuzzyEq<T> {
} }
} }
pub impl<T:Copy Ord Eq> Vec4<T>: OrdinalVector<T, Vec4<bool>> { pub impl<T:Copy Ord Eq> OrdinalVector<T, Vec4<bool>> for Vec4<T> {
#[inline(always)] #[inline(always)]
pure fn less_than(&self, other: &Vec4<T>) -> Vec4<bool> { pure fn less_than(&self, other: &Vec4<T>) -> Vec4<bool> {
Vector4::new(self[0] < other[0], Vector4::new(self[0] < other[0],
@ -364,7 +364,7 @@ pub impl<T:Copy Ord Eq> Vec4<T>: OrdinalVector<T, Vec4<bool>> {
} }
} }
pub impl<T:Copy Eq> Vec4<T>: EquableVector<T, Vec4<bool>> { pub impl<T:Copy Eq> EquableVector<T, Vec4<bool>> for Vec4<T> {
#[inline(always)] #[inline(always)]
pure fn equal(&self, other: &Vec4<T>) -> Vec4<bool> { pure fn equal(&self, other: &Vec4<T>) -> Vec4<bool> {
Vector4::new(self[0] == other[0], Vector4::new(self[0] == other[0],
@ -382,7 +382,7 @@ pub impl<T:Copy Eq> Vec4<T>: EquableVector<T, Vec4<bool>> {
} }
} }
pub impl Vec4<bool>: BooleanVector { pub impl BooleanVector for Vec4<bool> {
#[inline(always)] #[inline(always)]
pure fn any(&self) -> bool { pure fn any(&self) -> bool {
self[0] || self[1] || self[2] || self[3] self[0] || self[1] || self[2] || self[3]