diff --git a/src/mat.rs b/src/mat.rs index 8abf09d..e9f506b 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -17,7 +17,7 @@ use quat::Quat; * floating point type and have the same number of dimensions as the * number of rows and columns in the matrix. */ -pub trait Matrix: Index + Eq + Neg { +pub trait BaseMat: Index + Eq + Neg { /** * # Return value * @@ -243,7 +243,7 @@ pub trait Matrix: Index + Eq + Neg { /** * A 2 x 2 matrix */ -pub trait Matrix2: Matrix { +pub trait BaseMat2: BaseMat { fn new(c0r0: T, c0r1: T, c1r0: T, c1r1: T) -> Self; @@ -259,7 +259,7 @@ pub trait Matrix2: Matrix { /** * A 3 x 3 matrix */ -pub trait Matrix3: Matrix { +pub trait BaseMat3: BaseMat { fn new(c0r0:T, c0r1:T, c0r2:T, c1r0:T, c1r1:T, c1r2:T, c2r0:T, c2r1:T, c2r2:T) -> Self; @@ -288,7 +288,7 @@ pub trait Matrix3: Matrix { /** * A 4 x 4 matrix */ -pub trait Matrix4: Matrix { +pub trait BaseMat4: BaseMat { fn new(c0r0: T, c0r1: T, c0r2: T, c0r3: T, c1r0: T, c1r1: T, c1r2: T, c1r3: T, c2r0: T, c2r1: T, c2r2: T, c2r3: T, @@ -313,13 +313,13 @@ pub trait Matrix4: Matrix { #[deriving(Eq)] pub struct Mat2 { x: Vec2, y: Vec2 } -impl + Add + Sub + Mul + Div + Neg> Matrix> for Mat2 { +impl + Add + Sub + Mul + Div + Neg> BaseMat> for Mat2 { #[inline(always)] fn col(&self, i: uint) -> Vec2 { self[i] } #[inline(always)] fn row(&self, i: uint) -> Vec2 { - Vector2::new(self[0][i], + BaseVec2::new(self[0][i], self[1][i]) } @@ -341,8 +341,8 @@ impl + Add + Sub + Mul + */ #[inline(always)] fn from_value(value: T) -> Mat2 { - Matrix2::new(value, zero(), - zero(), value) + BaseMat2::new(value, zero(), + zero(), value) } /** @@ -358,8 +358,8 @@ impl + Add + Sub + Mul + */ #[inline(always)] fn identity() -> Mat2 { - Matrix2::new( one::(), zero::(), - zero::(), one::()) + BaseMat2::new( one::(), zero::(), + zero::(), one::()) } /** @@ -375,38 +375,38 @@ impl + Add + Sub + Mul + */ #[inline(always)] fn zero() -> Mat2 { - Matrix2::new(zero::(), zero::(), - zero::(), zero::()) + BaseMat2::new(zero::(), zero::(), + zero::(), zero::()) } #[inline(always)] fn mul_t(&self, value: T) -> Mat2 { - Matrix2::from_cols(self[0].mul_t(value), - self[1].mul_t(value)) + BaseMat2::from_cols(self[0].mul_t(value), + self[1].mul_t(value)) } #[inline(always)] fn mul_v(&self, vec: &Vec2) -> Vec2 { - Vector2::new(self.row(0).dot(vec), + BaseVec2::new(self.row(0).dot(vec), self.row(1).dot(vec)) } #[inline(always)] fn add_m(&self, other: &Mat2) -> Mat2 { - Matrix2::from_cols(self[0].add_v(&other[0]), - self[1].add_v(&other[1])) + BaseMat2::from_cols(self[0].add_v(&other[0]), + self[1].add_v(&other[1])) } #[inline(always)] fn sub_m(&self, other: &Mat2) -> Mat2 { - Matrix2::from_cols(self[0].sub_v(&other[0]), - self[1].sub_v(&other[1])) + BaseMat2::from_cols(self[0].sub_v(&other[0]), + self[1].sub_v(&other[1])) } #[inline(always)] fn mul_m(&self, other: &Mat2) -> Mat2 { - Matrix2::new(self.row(0).dot(&other.col(0)), self.row(1).dot(&other.col(0)), - self.row(0).dot(&other.col(1)), self.row(1).dot(&other.col(1))) + BaseMat2::new(self.row(0).dot(&other.col(0)), self.row(1).dot(&other.col(0)), + self.row(0).dot(&other.col(1)), self.row(1).dot(&other.col(1))) } fn dot(&self, other: &Mat2) -> T { @@ -427,15 +427,15 @@ impl + Add + Sub + Mul + if d.fuzzy_eq(&zero()) { None } else { - Some(Matrix2::new( self[1][1]/d, -self[0][1]/d, - -self[1][0]/d, self[0][0]/d)) + Some(BaseMat2::new( self[1][1]/d, -self[0][1]/d, + -self[1][0]/d, self[0][0]/d)) } } #[inline(always)] fn transpose(&self) -> Mat2 { - Matrix2::new(self[0][0], self[1][0], - self[0][1], self[1][1]) + BaseMat2::new(self[0][0], self[1][0], + self[0][1], self[1][1]) } #[inline(always)] @@ -465,12 +465,12 @@ impl + Add + Sub + Mul + #[inline(always)] fn to_identity(&mut self) { - (*self) = Matrix::identity(); + (*self) = BaseMat::identity(); } #[inline(always)] fn to_zero(&mut self) { - (*self) = Matrix::zero(); + (*self) = BaseMat::zero(); } #[inline(always)] @@ -507,7 +507,7 @@ impl + Add + Sub + Mul + #[inline(always)] fn is_identity(&self) -> bool { - self.fuzzy_eq(&Matrix::identity()) + self.fuzzy_eq(&BaseMat::identity()) } #[inline(always)] @@ -518,7 +518,7 @@ impl + Add + Sub + Mul + #[inline(always)] fn is_rotated(&self) -> bool { - !self.fuzzy_eq(&Matrix::identity()) + !self.fuzzy_eq(&BaseMat::identity()) } #[inline(always)] @@ -538,7 +538,7 @@ impl + Add + Sub + Mul + } } -impl + Add + Sub + Mul + Div + Neg> Matrix2> for Mat2 { +impl + Add + Sub + Mul + Div + Neg> BaseMat2> for Mat2 { /** * Construct a 2 x 2 matrix * @@ -559,8 +559,8 @@ impl + Add + Sub + Mul + #[inline(always)] fn new(c0r0: T, c0r1: T, c1r0: T, c1r1: T) -> Mat2 { - Matrix2::from_cols(Vector2::new::>(c0r0, c0r1), - Vector2::new::>(c1r0, c1r1)) + BaseMat2::from_cols(BaseVec2::new::>(c0r0, c0r1), + BaseVec2::new::>(c1r0, c1r1)) } /** @@ -590,8 +590,8 @@ impl + Add + Sub + Mul + let cos_theta = cos(radians); let sin_theta = sin(radians); - Matrix2::new(cos_theta, -sin_theta, - sin_theta, cos_theta) + BaseMat2::new(cos_theta, -sin_theta, + sin_theta, cos_theta) } /** @@ -609,9 +609,9 @@ impl + Add + Sub + Mul + */ #[inline(always)] fn to_mat3(&self) -> Mat3 { - Matrix3::new(self[0][0], self[0][1], zero(), - self[1][0], self[1][1], zero(), - zero(), zero(), one()) + BaseMat3::new(self[0][0], self[0][1], zero(), + self[1][0], self[1][1], zero(), + zero(), zero(), one()) } /** @@ -631,10 +631,10 @@ impl + Add + Sub + Mul + */ #[inline(always)] fn to_mat4(&self) -> Mat4 { - Matrix4::new(self[0][0], self[0][1], zero(), zero(), - self[1][0], self[1][1], zero(), zero(), - zero(), zero(), one(), zero(), - zero(), zero(), zero(), one()) + BaseMat4::new(self[0][0], self[0][1], zero(), zero(), + self[1][0], self[1][1], zero(), zero(), + zero(), zero(), one(), zero(), + zero(), zero(), zero(), one()) } } @@ -648,7 +648,7 @@ impl Index> for Mat2 { impl + Add + Sub + Mul + Div + Neg> Neg> for Mat2 { #[inline(always)] fn neg(&self) -> Mat2 { - Matrix2::from_cols(-self[0], -self[1]) + BaseMat2::from_cols(-self[0], -self[1]) } } @@ -669,15 +669,15 @@ macro_rules! mat2_type( ($name:ident <$T:ty, $V:ty>) => ( pub impl $name { #[inline(always)] fn new(c0r0: $T, c0r1: $T, c1r0: $T, c1r1: $T) - -> $name { Matrix2::new(c0r0, c0r1, c1r0, c1r1) } + -> $name { BaseMat2::new(c0r0, c0r1, c1r0, c1r1) } #[inline(always)] fn from_cols(c0: $V, c1: $V) - -> $name { Matrix2::from_cols(c0, c1) } - #[inline(always)] fn from_value(v: $T) -> $name { Matrix::from_value(v) } + -> $name { BaseMat2::from_cols(c0, c1) } + #[inline(always)] fn from_value(v: $T) -> $name { BaseMat::from_value(v) } - #[inline(always)] fn identity() -> $name { Matrix::identity() } - #[inline(always)] fn zero() -> $name { Matrix::zero() } + #[inline(always)] fn identity() -> $name { BaseMat::identity() } + #[inline(always)] fn zero() -> $name { BaseMat::zero() } - #[inline(always)] fn from_angle(radians: $T) -> $name { Matrix2::from_angle(radians) } + #[inline(always)] fn from_angle(radians: $T) -> $name { BaseMat2::from_angle(radians) } #[inline(always)] fn dim() -> uint { 2 } #[inline(always)] fn rows() -> uint { 2 } @@ -723,13 +723,13 @@ mat2_type!(Mat2f64) #[deriving(Eq)] pub struct Mat3 { x: Vec3, y: Vec3, z: Vec3 } -impl + Add + Sub + Mul + Div + Neg> Matrix> for Mat3 { +impl + Add + Sub + Mul + Div + Neg> BaseMat> for Mat3 { #[inline(always)] fn col(&self, i: uint) -> Vec3 { self[i] } #[inline(always)] fn row(&self, i: uint) -> Vec3 { - Vector3::new(self[0][i], + BaseVec3::new(self[0][i], self[1][i], self[2][i]) } @@ -754,9 +754,9 @@ impl + Add + Sub + Mul + */ #[inline(always)] fn from_value(value: T) -> Mat3 { - Matrix3::new(value, zero(), zero(), - zero(), value, zero(), - zero(), zero(), value) + BaseMat3::new(value, zero(), zero(), + zero(), value, zero(), + zero(), zero(), value) } /** @@ -774,9 +774,9 @@ impl + Add + Sub + Mul + */ #[inline(always)] fn identity() -> Mat3 { - Matrix3::new( one::(), zero::(), zero::(), - zero::(), one::(), zero::(), - zero::(), zero::(), one::()) + BaseMat3::new( one::(), zero::(), zero::(), + zero::(), one::(), zero::(), + zero::(), zero::(), one::()) } /** @@ -794,52 +794,52 @@ impl + Add + Sub + Mul + */ #[inline(always)] fn zero() -> Mat3 { - Matrix3::new(zero::(), zero::(), zero::(), - zero::(), zero::(), zero::(), - zero::(), zero::(), zero::()) + BaseMat3::new(zero::(), zero::(), zero::(), + zero::(), zero::(), zero::(), + zero::(), zero::(), zero::()) } #[inline(always)] fn mul_t(&self, value: T) -> Mat3 { - Matrix3::from_cols(self[0].mul_t(value), - self[1].mul_t(value), - self[2].mul_t(value)) + BaseMat3::from_cols(self[0].mul_t(value), + self[1].mul_t(value), + self[2].mul_t(value)) } #[inline(always)] fn mul_v(&self, vec: &Vec3) -> Vec3 { - Vector3::new(self.row(0).dot(vec), + BaseVec3::new(self.row(0).dot(vec), self.row(1).dot(vec), self.row(2).dot(vec)) } #[inline(always)] fn add_m(&self, other: &Mat3) -> Mat3 { - Matrix3::from_cols(self[0].add_v(&other[0]), - self[1].add_v(&other[1]), - self[2].add_v(&other[2])) + BaseMat3::from_cols(self[0].add_v(&other[0]), + self[1].add_v(&other[1]), + self[2].add_v(&other[2])) } #[inline(always)] fn sub_m(&self, other: &Mat3) -> Mat3 { - Matrix3::from_cols(self[0].sub_v(&other[0]), - self[1].sub_v(&other[1]), - self[2].sub_v(&other[2])) + BaseMat3::from_cols(self[0].sub_v(&other[0]), + self[1].sub_v(&other[1]), + self[2].sub_v(&other[2])) } #[inline(always)] fn mul_m(&self, other: &Mat3) -> Mat3 { - Matrix3::new(self.row(0).dot(&other.col(0)), - self.row(1).dot(&other.col(0)), - self.row(2).dot(&other.col(0)), + BaseMat3::new(self.row(0).dot(&other.col(0)), + self.row(1).dot(&other.col(0)), + self.row(2).dot(&other.col(0)), - self.row(0).dot(&other.col(1)), - self.row(1).dot(&other.col(1)), - self.row(2).dot(&other.col(1)), + self.row(0).dot(&other.col(1)), + self.row(1).dot(&other.col(1)), + self.row(2).dot(&other.col(1)), - self.row(0).dot(&other.col(2)), - self.row(1).dot(&other.col(2)), - self.row(2).dot(&other.col(2))) + self.row(0).dot(&other.col(2)), + self.row(1).dot(&other.col(2)), + self.row(2).dot(&other.col(2))) } fn dot(&self, other: &Mat3) -> T { @@ -860,18 +860,18 @@ impl + Add + Sub + Mul + if d.fuzzy_eq(&zero()) { None } else { - let m: Mat3 = Matrix3::from_cols(self[1].cross(&self[2]).div_t(d), - self[2].cross(&self[0]).div_t(d), - self[0].cross(&self[1]).div_t(d)); + let m: Mat3 = BaseMat3::from_cols(self[1].cross(&self[2]).div_t(d), + self[2].cross(&self[0]).div_t(d), + self[0].cross(&self[1]).div_t(d)); Some(m.transpose()) } } #[inline(always)] fn transpose(&self) -> Mat3 { - Matrix3::new(self[0][0], self[1][0], self[2][0], - self[0][1], self[1][1], self[2][1], - self[0][2], self[1][2], self[2][2]) + BaseMat3::new(self[0][0], self[1][0], self[2][0], + self[0][1], self[1][1], self[2][1], + self[0][2], self[1][2], self[2][2]) } #[inline(always)] @@ -903,12 +903,12 @@ impl + Add + Sub + Mul + #[inline(always)] fn to_identity(&mut self) { - (*self) = Matrix::identity(); + (*self) = BaseMat::identity(); } #[inline(always)] fn to_zero(&mut self) { - (*self) = Matrix::zero(); + (*self) = BaseMat::zero(); } #[inline(always)] @@ -954,7 +954,7 @@ impl + Add + Sub + Mul + #[inline(always)] fn is_identity(&self) -> bool { - self.fuzzy_eq(&Matrix::identity()) + self.fuzzy_eq(&BaseMat::identity()) } #[inline(always)] @@ -971,7 +971,7 @@ impl + Add + Sub + Mul + #[inline(always)] fn is_rotated(&self) -> bool { - !self.fuzzy_eq(&Matrix::identity()) + !self.fuzzy_eq(&BaseMat::identity()) } #[inline(always)] @@ -997,7 +997,7 @@ impl + Add + Sub + Mul + } } -impl + Add + Sub + Mul + Div + Neg> Matrix3> for Mat3 { +impl + Add + Sub + Mul + Div + Neg> BaseMat3> for Mat3 { /** * Construct a 3 x 3 matrix * @@ -1022,9 +1022,9 @@ impl + Add + Sub + Mul + fn new(c0r0:T, c0r1:T, c0r2:T, c1r0:T, c1r1:T, c1r2:T, c2r0:T, c2r1:T, c2r2:T) -> Mat3 { - Matrix3::from_cols(Vector3::new::>(c0r0, c0r1, c0r2), - Vector3::new::>(c1r0, c1r1, c1r2), - Vector3::new::>(c2r0, c2r1, c2r2)) + BaseMat3::from_cols(BaseVec3::new::>(c0r0, c0r1, c0r2), + BaseVec3::new::>(c1r0, c1r1, c1r2), + BaseVec3::new::>(c2r0, c2r1, c2r2)) } /** @@ -1061,9 +1061,9 @@ impl + Add + Sub + Mul + let cos_theta = cos(radians); let sin_theta = sin(radians); - Matrix3::new( one(), zero(), zero(), - zero(), cos_theta, sin_theta, - zero(), -sin_theta, cos_theta) + BaseMat3::new( one(), zero(), zero(), + zero(), cos_theta, sin_theta, + zero(), -sin_theta, cos_theta) } /** @@ -1075,9 +1075,9 @@ impl + Add + Sub + Mul + let cos_theta = cos(radians); let sin_theta = sin(radians); - Matrix3::new(cos_theta, zero(), -sin_theta, - zero(), one(), zero(), - sin_theta, zero(), cos_theta) + BaseMat3::new(cos_theta, zero(), -sin_theta, + zero(), one(), zero(), + sin_theta, zero(), cos_theta) } /** @@ -1089,9 +1089,9 @@ impl + Add + Sub + Mul + let cos_theta = cos(radians); let sin_theta = sin(radians); - Matrix3::new( cos_theta, sin_theta, zero(), - -sin_theta, cos_theta, zero(), - zero(), zero(), one()) + BaseMat3::new( cos_theta, sin_theta, zero(), + -sin_theta, cos_theta, zero(), + zero(), zero(), one()) } /** @@ -1113,9 +1113,9 @@ impl + Add + Sub + Mul + let cz = cos(radians_z); let sz = sin(radians_z); - Matrix3::new( cy*cz, cy*sz, -sy, - -cx*sz + sx*sy*cz, cx*cz + sx*sy*sz, sx*cy, - sx*sz + cx*sy*cz, -sx*cz + cx*sy*sz, cx*cy) + BaseMat3::new( cy*cz, cy*sz, -sy, + -cx*sz + sx*sy*cz, cx*cz + sx*sy*sz, sx*cy, + sx*sz + cx*sy*cz, -sx*cz + cx*sy*sz, cx*cy) } /** @@ -1131,14 +1131,14 @@ impl + Add + Sub + Mul + let y = axis.y; let z = axis.z; - Matrix3::new(_1_c*x*x + c, _1_c*x*y + s*z, _1_c*x*z - s*y, - _1_c*x*y - s*z, _1_c*y*y + c, _1_c*y*z + s*x, - _1_c*x*z + s*y, _1_c*y*z - s*x, _1_c*z*z + c) + BaseMat3::new(_1_c*x*x + c, _1_c*x*y + s*z, _1_c*x*z - s*y, + _1_c*x*y - s*z, _1_c*y*y + c, _1_c*y*z + s*x, + _1_c*x*z + s*y, _1_c*y*z - s*x, _1_c*z*z + c) } #[inline(always)] fn from_axes(x: Vec3, y: Vec3, z: Vec3) -> Mat3 { - Matrix3::from_cols(x, y, z) + BaseMat3::from_cols(x, y, z) } #[inline(always)] @@ -1147,7 +1147,7 @@ impl + Add + Sub + Mul + let side = dir_.cross(&up.normalize()); let up_ = side.cross(&dir_).normalize(); - Matrix3::from_axes(up_, side, dir_) + BaseMat3::from_axes(up_, side, dir_) } /** @@ -1167,10 +1167,10 @@ impl + Add + Sub + Mul + */ #[inline(always)] fn to_mat4(&self) -> Mat4 { - Matrix4::new(self[0][0], self[0][1], self[0][2], zero(), - self[1][0], self[1][1], self[1][2], zero(), - self[2][0], self[2][1], self[2][2], zero(), - zero(), zero(), zero(), one()) + BaseMat4::new(self[0][0], self[0][1], self[0][2], zero(), + self[1][0], self[1][1], self[1][2], zero(), + self[2][0], self[2][1], self[2][2], zero(), + zero(), zero(), zero(), one()) } /** @@ -1232,7 +1232,7 @@ impl Index> for Mat3 { impl + Add + Sub + Mul + Div + Neg> Neg> for Mat3 { #[inline(always)] fn neg(&self) -> Mat3 { - Matrix3::from_cols(-self[0], -self[1], -self[2]) + BaseMat3::from_cols(-self[0], -self[1], -self[2]) } } @@ -1254,21 +1254,21 @@ macro_rules! mat3_type( ($name:ident <$T:ty, $V:ty>) => ( pub impl $name { #[inline(always)] fn new(c0r0: $T, c0r1: $T, c0r2: $T, c1r0: $T, c1r1: $T, c1r2: $T, c2r0: $T, c2r1: $T, c2r2: $T) - -> $name { Matrix3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) } + -> $name { BaseMat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) } #[inline(always)] fn from_cols(c0: $V, c1: $V, c2: $V) - -> $name { Matrix3::from_cols(c0, c1, c2) } - #[inline(always)] fn from_value(v: $T) -> $name { Matrix::from_value(v) } + -> $name { BaseMat3::from_cols(c0, c1, c2) } + #[inline(always)] fn from_value(v: $T) -> $name { BaseMat::from_value(v) } - #[inline(always)] fn identity() -> $name { Matrix::identity() } - #[inline(always)] fn zero() -> $name { Matrix::zero() } + #[inline(always)] fn identity() -> $name { BaseMat::identity() } + #[inline(always)] fn zero() -> $name { BaseMat::zero() } - #[inline(always)] fn from_angle_x(radians: $T) -> $name { Matrix3::from_angle_x(radians) } - #[inline(always)] fn from_angle_y(radians: $T) -> $name { Matrix3::from_angle_y(radians) } - #[inline(always)] fn from_angle_z(radians: $T) -> $name { Matrix3::from_angle_z(radians) } - #[inline(always)] fn from_angle_xyz(radians_x: $T, radians_y: $T, radians_z: $T) -> $name { Matrix3::from_angle_xyz(radians_x, radians_y, radians_z) } - #[inline(always)] fn from_angle_axis(radians: $T, axis: &$V) -> $name { Matrix3::from_angle_axis(radians, axis) } - #[inline(always)] fn from_axes(x: $V, y: $V, z: $V) -> $name { Matrix3::from_axes(x, y, z) } - #[inline(always)] fn look_at(dir: &$V, up: &$V) -> $name { Matrix3::look_at(dir, up) } + #[inline(always)] fn from_angle_x(radians: $T) -> $name { BaseMat3::from_angle_x(radians) } + #[inline(always)] fn from_angle_y(radians: $T) -> $name { BaseMat3::from_angle_y(radians) } + #[inline(always)] fn from_angle_z(radians: $T) -> $name { BaseMat3::from_angle_z(radians) } + #[inline(always)] fn from_angle_xyz(radians_x: $T, radians_y: $T, radians_z: $T) -> $name { BaseMat3::from_angle_xyz(radians_x, radians_y, radians_z) } + #[inline(always)] fn from_angle_axis(radians: $T, axis: &$V) -> $name { BaseMat3::from_angle_axis(radians, axis) } + #[inline(always)] fn from_axes(x: $V, y: $V, z: $V) -> $name { BaseMat3::from_axes(x, y, z) } + #[inline(always)] fn look_at(dir: &$V, up: &$V) -> $name { BaseMat3::look_at(dir, up) } #[inline(always)] fn dim() -> uint { 3 } #[inline(always)] fn rows() -> uint { 3 } @@ -1312,13 +1312,13 @@ mat3_type!(Mat3f64) #[deriving(Eq)] pub struct Mat4 { x: Vec4, y: Vec4, z: Vec4, w: Vec4 } -impl + Add + Sub + Mul + Div + Neg> Matrix> for Mat4 { +impl + Add + Sub + Mul + Div + Neg> BaseMat> for Mat4 { #[inline(always)] fn col(&self, i: uint) -> Vec4 { self[i] } #[inline(always)] fn row(&self, i: uint) -> Vec4 { - Vector4::new(self[0][i], + BaseVec4::new(self[0][i], self[1][i], self[2][i], self[3][i]) @@ -1346,10 +1346,10 @@ impl + Add + Sub + Mul + */ #[inline(always)] fn from_value(value: T) -> Mat4 { - Matrix4::new(value, zero(), zero(), zero(), - zero(), value, zero(), zero(), - zero(), zero(), value, zero(), - zero(), zero(), zero(), value) + BaseMat4::new(value, zero(), zero(), zero(), + zero(), value, zero(), zero(), + zero(), zero(), value, zero(), + zero(), zero(), zero(), value) } /** @@ -1369,10 +1369,10 @@ impl + Add + Sub + Mul + */ #[inline(always)] fn identity() -> Mat4 { - Matrix4::new( one::(), zero::(), zero::(), zero::(), - zero::(), one::(), zero::(), zero::(), - zero::(), zero::(), one::(), zero::(), - zero::(), zero::(), zero::(), one::()) + BaseMat4::new( one::(), zero::(), zero::(), zero::(), + zero::(), one::(), zero::(), zero::(), + zero::(), zero::(), one::(), zero::(), + zero::(), zero::(), zero::(), one::()) } /** @@ -1392,65 +1392,65 @@ impl + Add + Sub + Mul + */ #[inline(always)] fn zero() -> Mat4 { - Matrix4::new(zero::(), zero::(), zero::(), zero::(), - zero::(), zero::(), zero::(), zero::(), - zero::(), zero::(), zero::(), zero::(), - zero::(), zero::(), zero::(), zero::()) + BaseMat4::new(zero::(), zero::(), zero::(), zero::(), + zero::(), zero::(), zero::(), zero::(), + zero::(), zero::(), zero::(), zero::(), + zero::(), zero::(), zero::(), zero::()) } #[inline(always)] fn mul_t(&self, value: T) -> Mat4 { - Matrix4::from_cols(self[0].mul_t(value), - self[1].mul_t(value), - self[2].mul_t(value), - self[3].mul_t(value)) + BaseMat4::from_cols(self[0].mul_t(value), + self[1].mul_t(value), + self[2].mul_t(value), + self[3].mul_t(value)) } #[inline(always)] fn mul_v(&self, vec: &Vec4) -> Vec4 { - Vector4::new(self.row(0).dot(vec), - self.row(1).dot(vec), - self.row(2).dot(vec), - self.row(3).dot(vec)) + BaseVec4::new(self.row(0).dot(vec), + self.row(1).dot(vec), + self.row(2).dot(vec), + self.row(3).dot(vec)) } #[inline(always)] fn add_m(&self, other: &Mat4) -> Mat4 { - Matrix4::from_cols(self[0].add_v(&other[0]), - self[1].add_v(&other[1]), - self[2].add_v(&other[2]), - self[3].add_v(&other[3])) + BaseMat4::from_cols(self[0].add_v(&other[0]), + self[1].add_v(&other[1]), + self[2].add_v(&other[2]), + self[3].add_v(&other[3])) } #[inline(always)] fn sub_m(&self, other: &Mat4) -> Mat4 { - Matrix4::from_cols(self[0].sub_v(&other[0]), - self[1].sub_v(&other[1]), - self[2].sub_v(&other[2]), - self[3].sub_v(&other[3])) + BaseMat4::from_cols(self[0].sub_v(&other[0]), + self[1].sub_v(&other[1]), + self[2].sub_v(&other[2]), + self[3].sub_v(&other[3])) } #[inline(always)] fn mul_m(&self, other: &Mat4) -> Mat4 { - Matrix4::new(self.row(0).dot(&other.col(0)), - self.row(1).dot(&other.col(0)), - self.row(2).dot(&other.col(0)), - self.row(3).dot(&other.col(0)), + BaseMat4::new(self.row(0).dot(&other.col(0)), + self.row(1).dot(&other.col(0)), + self.row(2).dot(&other.col(0)), + self.row(3).dot(&other.col(0)), - self.row(0).dot(&other.col(1)), - self.row(1).dot(&other.col(1)), - self.row(2).dot(&other.col(1)), - self.row(3).dot(&other.col(1)), + self.row(0).dot(&other.col(1)), + self.row(1).dot(&other.col(1)), + self.row(2).dot(&other.col(1)), + self.row(3).dot(&other.col(1)), - self.row(0).dot(&other.col(2)), - self.row(1).dot(&other.col(2)), - self.row(2).dot(&other.col(2)), - self.row(3).dot(&other.col(2)), + self.row(0).dot(&other.col(2)), + self.row(1).dot(&other.col(2)), + self.row(2).dot(&other.col(2)), + self.row(3).dot(&other.col(2)), - self.row(0).dot(&other.col(3)), - self.row(1).dot(&other.col(3)), - self.row(2).dot(&other.col(3)), - self.row(3).dot(&other.col(3))) + self.row(0).dot(&other.col(3)), + self.row(1).dot(&other.col(3)), + self.row(2).dot(&other.col(3)), + self.row(3).dot(&other.col(3))) } @@ -1459,18 +1459,18 @@ impl + Add + Sub + Mul + } fn determinant(&self) -> T { - let m0: Mat3 = Matrix3::new(self[1][1], self[2][1], self[3][1], - self[1][2], self[2][2], self[3][2], - self[1][3], self[2][3], self[3][3]); - let m1: Mat3 = Matrix3::new(self[0][1], self[2][1], self[3][1], - self[0][2], self[2][2], self[3][2], - self[0][3], self[2][3], self[3][3]); - let m2: Mat3 = Matrix3::new(self[0][1], self[1][1], self[3][1], - self[0][2], self[1][2], self[3][2], - self[0][3], self[1][3], self[3][3]); - let m3: Mat3 = Matrix3::new(self[0][1], self[1][1], self[2][1], - self[0][2], self[1][2], self[2][2], - self[0][3], self[1][3], self[2][3]); + let m0: Mat3 = BaseMat3::new(self[1][1], self[2][1], self[3][1], + self[1][2], self[2][2], self[3][2], + self[1][3], self[2][3], self[3][3]); + let m1: Mat3 = BaseMat3::new(self[0][1], self[2][1], self[3][1], + self[0][2], self[2][2], self[3][2], + self[0][3], self[2][3], self[3][3]); + let m2: Mat3 = BaseMat3::new(self[0][1], self[1][1], self[3][1], + self[0][2], self[1][2], self[3][2], + self[0][3], self[1][3], self[3][3]); + let m3: Mat3 = BaseMat3::new(self[0][1], self[1][1], self[2][1], + self[0][2], self[1][2], self[2][2], + self[0][3], self[1][3], self[2][3]); self[0][0] * m0.determinant() - self[1][0] * m1.determinant() + @@ -1493,7 +1493,7 @@ impl + Add + Sub + Mul + // and essentially reduce [A|I] let mut A = *self; - let mut I: Mat4 = Matrix::identity(); + let mut I: Mat4 = BaseMat::identity(); for uint::range(0, 4) |j| { // Find largest element in col j @@ -1530,10 +1530,10 @@ impl + Add + Sub + Mul + #[inline(always)] fn transpose(&self) -> Mat4 { - Matrix4::new(self[0][0], self[1][0], self[2][0], self[3][0], - self[0][1], self[1][1], self[2][1], self[3][1], - self[0][2], self[1][2], self[2][2], self[3][2], - self[0][3], self[1][3], self[2][3], self[3][3]) + BaseMat4::new(self[0][0], self[1][0], self[2][0], self[3][0], + self[0][1], self[1][1], self[2][1], self[3][1], + self[0][2], self[1][2], self[2][2], self[3][2], + self[0][3], self[1][3], self[2][3], self[3][3]) } #[inline(always)] @@ -1567,12 +1567,12 @@ impl + Add + Sub + Mul + #[inline(always)] fn to_identity(&mut self) { - (*self) = Matrix::identity(); + (*self) = BaseMat::identity(); } #[inline(always)] fn to_zero(&mut self) { - (*self) = Matrix::zero(); + (*self) = BaseMat::zero(); } #[inline(always)] @@ -1628,7 +1628,7 @@ impl + Add + Sub + Mul + #[inline(always)] fn is_identity(&self) -> bool { - self.fuzzy_eq(&Matrix::identity()) + self.fuzzy_eq(&BaseMat::identity()) } #[inline(always)] @@ -1652,7 +1652,7 @@ impl + Add + Sub + Mul + #[inline(always)] fn is_rotated(&self) -> bool { - !self.fuzzy_eq(&Matrix::identity()) + !self.fuzzy_eq(&BaseMat::identity()) } #[inline(always)] @@ -1685,7 +1685,7 @@ impl + Add + Sub + Mul + } } -impl + Add + Sub + Mul + Div + Neg> Matrix4> for Mat4 { +impl + Add + Sub + Mul + Div + Neg> BaseMat4> for Mat4 { /** * Construct a 4 x 4 matrix * @@ -1714,10 +1714,10 @@ impl + Add + Sub + Mul + c1r0: T, c1r1: T, c1r2: T, c1r3: T, c2r0: T, c2r1: T, c2r2: T, c2r3: T, c3r0: T, c3r1: T, c3r2: T, c3r3: T) -> Mat4 { - Matrix4::from_cols(Vector4::new::>(c0r0, c0r1, c0r2, c0r3), - Vector4::new::>(c1r0, c1r1, c1r2, c1r3), - Vector4::new::>(c2r0, c2r1, c2r2, c2r3), - Vector4::new::>(c3r0, c3r1, c3r2, c3r3)) + BaseMat4::from_cols(BaseVec4::new::>(c0r0, c0r1, c0r2, c0r3), + BaseVec4::new::>(c1r0, c1r1, c1r2, c1r3), + BaseVec4::new::>(c2r0, c2r1, c2r2, c2r3), + BaseVec4::new::>(c3r0, c3r1, c3r2, c3r3)) } /** @@ -1752,7 +1752,7 @@ impl + Add + Sub + Mul + impl + Add + Sub + Mul + Div + Neg> Neg> for Mat4 { #[inline(always)] fn neg(&self) -> Mat4 { - Matrix4::from_cols(-self[0], -self[1], -self[2], -self[3]) + BaseMat4::from_cols(-self[0], -self[1], -self[2], -self[3]) } } @@ -1782,13 +1782,13 @@ macro_rules! mat4_type( ($name:ident <$T:ty, $V:ty>) => ( pub impl $name { #[inline(always)] fn new(c0r0: $T, c0r1: $T, c0r2: $T, c0r3: $T, c1r0: $T, c1r1: $T, c1r2: $T, c1r3: $T, c2r0: $T, c2r1: $T, c2r2: $T, c2r3: $T, c3r0: $T, c3r1: $T, c3r2: $T, c3r3: $T) - -> $name { Matrix4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) } + -> $name { BaseMat4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) } #[inline(always)] fn from_cols(c0: $V, c1: $V, c2: $V, c3: $V) - -> $name { Matrix4::from_cols(c0, c1, c2, c3) } - #[inline(always)] fn from_value(v: $T) -> $name { Matrix::from_value(v) } + -> $name { BaseMat4::from_cols(c0, c1, c2, c3) } + #[inline(always)] fn from_value(v: $T) -> $name { BaseMat::from_value(v) } - #[inline(always)] fn identity() -> $name { Matrix::identity() } - #[inline(always)] fn zero() -> $name { Matrix::zero() } + #[inline(always)] fn identity() -> $name { BaseMat::identity() } + #[inline(always)] fn zero() -> $name { BaseMat::zero() } #[inline(always)] fn dim() -> uint { 4 } #[inline(always)] fn rows() -> uint { 4 } diff --git a/src/projection.rs b/src/projection.rs index a4ba05d..f05ef67 100644 --- a/src/projection.rs +++ b/src/projection.rs @@ -3,7 +3,7 @@ use numeric::*; use std::cmp::FuzzyEq; -use mat::{Mat4, Matrix4}; +use mat::{Mat4, BaseMat4}; /** * Create a perspective projection matrix @@ -51,8 +51,8 @@ pub fn frustum + Add + Sub + let c3r2 = -(_2 * far * near) / (far - near); let c3r3 = _0; - Matrix4::new(c0r0, c0r1, c0r2, c0r3, - c1r0, c1r1, c1r2, c1r3, - c2r0, c2r1, c2r2, c2r3, - c3r0, c3r1, c3r2, c3r3) + BaseMat4::new(c0r0, c0r1, c0r2, c0r3, + c1r0, c1r1, c1r2, c1r3, + c2r0, c2r1, c2r2, c2r3, + c3r0, c3r1, c3r2, c3r3) } \ No newline at end of file diff --git a/src/quat.rs b/src/quat.rs index 46a04c9..cdf76d0 100644 --- a/src/quat.rs +++ b/src/quat.rs @@ -13,9 +13,8 @@ use core::num::One::one; use std::cmp::{FuzzyEq, FUZZY_EPSILON}; use numeric::*; -use mat::{Mat3, Matrix3}; -use vec::{Vec3, Vector3, EuclideanVector}; -use vec::{NumericVector, NumericVector3}; +use mat::{Mat3, BaseMat3}; +use vec::{Vec3, BaseVec3, AffineVec, NumVec, NumVec3}; use vec::{vec3, dvec3, Vec3f, Vec3f32, Vec3f64}; /** @@ -47,7 +46,7 @@ pub impl + Add + Sub + Mul Quat { - Quat::from_sv(w, Vector3::new(xi, yj, zk)) + Quat::from_sv(w, BaseVec3::new(xi, yj, zk)) } /** @@ -122,7 +121,7 @@ pub impl + Add + Sub + Mul, y: Vec3, z: Vec3) -> Quat { - let m: Mat3 = Matrix3::from_axes(x, y, z); m.to_quat() + let m: Mat3 = BaseMat3::from_axes(x, y, z); m.to_quat() } fn get_angle_axis(&self) -> (T, Vec3) { @@ -131,7 +130,7 @@ pub impl + Add + Sub + Mul, up: &Vec3) -> Quat { - let m: Mat3 = Matrix3::look_at(dir, up); m.to_quat() + let m: Mat3 = BaseMat3::look_at(dir, up); m.to_quat() } /** @@ -365,9 +364,9 @@ pub impl + Add + Sub + Mul = Matrix::identity(); + let ident: Mat3 = BaseMat::identity(); assert!(ident.inverse().unwrap() == ident); diff --git a/src/vec.rs b/src/vec.rs index ec64337..1e3a34b 100644 --- a/src/vec.rs +++ b/src/vec.rs @@ -12,7 +12,7 @@ use numeric::*; * * `T` - The type of the components. This is intended to support boolean, * integer, unsigned integer, and floating point types. */ -pub trait Vector: Index + Eq { +pub trait BaseVec: Index + Eq { /** * Construct the vector from a single value, copying it to each component */ @@ -39,28 +39,28 @@ pub trait Vector: Index + Eq { /** * A generic 2-dimensional vector */ -pub trait Vector2: Vector { +pub trait BaseVec2: BaseVec { fn new(x: T, y: T) -> Self; } /** * A generic 3-dimensional vector */ -pub trait Vector3: Vector { +pub trait BaseVec3: BaseVec { fn new(x: T, y: T, z: T) -> Self; } /** * A generic 4-dimensional vector */ -pub trait Vector4: Vector { +pub trait BaseVec4: BaseVec { fn new(x: T, y: T, z: T, w: T) -> Self; } /** * A vector with numeric components */ -pub trait NumericVector: Vector + Neg { +pub trait NumVec: BaseVec + Neg { /** * The standard basis vector * @@ -166,7 +166,7 @@ pub trait NumericVector: Vector + Neg { /** * A 2-dimensional vector with numeric components */ -pub trait NumericVector2: NumericVector { +pub trait NumVec2: NumVec { fn unit_x() -> Self; fn unit_y() -> Self; @@ -181,7 +181,7 @@ pub trait NumericVector2: NumericVector { /** * A 3-dimensional vector with numeric components */ -pub trait NumericVector3: NumericVector { +pub trait NumVec3: NumVec { fn unit_x() -> Self; fn unit_y() -> Self; fn unit_z() -> Self; @@ -202,7 +202,7 @@ pub trait NumericVector3: NumericVector { /** * A 4-dimensional vector with numeric components */ -pub trait NumericVector4: NumericVector { +pub trait NumVec4: NumVec { fn unit_x() -> Self; fn unit_y() -> Self; fn unit_z() -> Self; @@ -223,7 +223,7 @@ pub trait ToHomogeneous { * * * `T` - The type of the components. This should be a floating point type. */ -pub trait EuclideanVector: NumericVector { +pub trait AffineVec: NumVec { /** * # Return value * @@ -310,7 +310,7 @@ pub trait EuclideanVector: NumericVector { * mentioned in Section 8.7 of the [GLSL 4.30.6 specification] * (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf). */ -pub trait OrdinalVector: Vector { +pub trait OrdVec: BaseVec { /** * Component-wise compare of `self < other` */ @@ -339,7 +339,7 @@ pub trait OrdinalVector: Vector { * mentioned in Section 8.7 of the [GLSL 4.30.6 specification] * (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf). */ -pub trait EquableVector: Vector { +pub trait EqVec: BaseVec { /** * Component-wise compare of `self == other` */ @@ -358,7 +358,7 @@ pub trait EquableVector: Vector { * mentioned in Section 8.7 of the [GLSL 4.30.6 specification] * (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf). */ -pub trait BooleanVector: Vector { +pub trait BoolVec: BaseVec { /** * # Return value * @@ -381,7 +381,7 @@ pub trait BooleanVector: Vector { fn not(&self) -> Self; } -pub trait TrigVec: Vector { +pub trait TrigVec: BaseVec { fn radians(&self) -> Self; fn degrees(&self) -> Self; @@ -405,7 +405,7 @@ pub trait TrigVec: Vector { // fn atanh() -> Self; } -pub trait ExpVec: Vector { +pub trait ExpVec: BaseVec { // Exponential functions fn pow_t(&self, n: Self) -> Self; fn pow_v(&self, n: T) -> Self; @@ -417,7 +417,7 @@ pub trait ExpVec: Vector { fn inv_sqrt(&self) -> Self; } -pub trait ApproxVec: Vector { +pub trait ApproxVec: BaseVec { // Whole-number approximation functions fn floor(&self) -> Self; fn trunc(&self) -> Self; @@ -427,7 +427,7 @@ pub trait ApproxVec: Vector { fn fract(&self) -> Self; } -pub trait SignedVec: Vector { +pub trait SignedVec: BaseVec { fn is_positive(&self) -> BV; fn is_negative(&self) -> BV; fn is_nonpositive(&self) -> BV; @@ -438,7 +438,7 @@ pub trait SignedVec: Vector { fn copysign(&self, other: Self) -> Self; } -pub trait ExtentVec: Vector { +pub trait ExtentVec: BaseVec { fn min_v(&self, other: &Self) -> Self; fn max_v(&self, other: &Self) -> Self; fn clamp_v(&self, mn: &Self, mx: &Self) -> Self; @@ -448,7 +448,7 @@ pub trait ExtentVec: Vector { fn clamp_t(&self, mn: T, mx: T) -> Self; } -pub trait MixVec: Vector { +pub trait MixVec: BaseVec { // Functions for blending numbers together fn mix(&self, other: Self, value: Self) -> Self; fn smooth_step(&self, edge0: Self, edge1: Self) -> Self; @@ -459,40 +459,40 @@ pub trait MixVec: Vector { macro_rules! zip_vec2( ($a:ident[] $method:ident $b:ident[]) => ( - Vector2::new($a[0].$method(&($b[0])), - $a[1].$method(&($b[1]))) + BaseVec2::new($a[0].$method(&($b[0])), + $a[1].$method(&($b[1]))) ); ($a:ident[] $method:ident $b:ident) => ( - Vector2::new($a[0].$method(&($b)), - $a[1].$method(&($b))) + BaseVec2::new($a[0].$method(&($b)), + $a[1].$method(&($b))) ); ) macro_rules! zip_vec3( ($a:ident[] $method:ident $b:ident[]) => ( - Vector3::new($a[0].$method(&($b[0])), - $a[1].$method(&($b[1])), - $a[2].$method(&($b[2]))) + BaseVec3::new($a[0].$method(&($b[0])), + $a[1].$method(&($b[1])), + $a[2].$method(&($b[2]))) ); ($a:ident[] $method:ident $b:ident) => ( - Vector3::new($a[0].$method(&($b)), - $a[1].$method(&($b)), - $a[2].$method(&($b))) + BaseVec3::new($a[0].$method(&($b)), + $a[1].$method(&($b)), + $a[2].$method(&($b))) ); ) macro_rules! zip_vec4( ($a:ident[] $method:ident $b:ident[]) => ( - Vector4::new($a[0].$method(&($b[0])), - $a[1].$method(&($b[1])), - $a[2].$method(&($b[2])), - $a[3].$method(&($b[3]))) + BaseVec4::new($a[0].$method(&($b[0])), + $a[1].$method(&($b[1])), + $a[2].$method(&($b[2])), + $a[3].$method(&($b[3]))) ); ($a:ident[] $method:ident $b:ident) => ( - Vector4::new($a[0].$method(&($b)), - $a[1].$method(&($b)), - $a[2].$method(&($b)), - $a[3].$method(&($b))) + BaseVec4::new($a[0].$method(&($b)), + $a[1].$method(&($b)), + $a[2].$method(&($b)), + $a[3].$method(&($b))) ); ) @@ -522,10 +522,10 @@ macro_rules! zip_assign( #[deriving(Eq)] pub struct Vec2 { x: T, y: T } -impl Vector for Vec2 { +impl BaseVec for Vec2 { #[inline(always)] fn from_value(value: T) -> Vec2 { - Vector2::new(value, value) + BaseVec2::new(value, value) } #[inline(always)] @@ -548,7 +548,7 @@ impl Vector for Vec2 { } } -impl Vector2 for Vec2 { +impl BaseVec2 for Vec2 { #[inline(always)] fn new(x: T, y: T ) -> Vec2 { Vec2 { x: x, y: y } @@ -562,15 +562,15 @@ impl Index for Vec2 { } } -impl + Sub + Mul + Div + Neg> NumericVector for Vec2 { +impl + Sub + Mul + Div + Neg> NumVec for Vec2 { #[inline(always)] fn identity() -> Vec2 { - Vector2::new(one::(), one::()) + BaseVec2::new(one::(), one::()) } #[inline(always)] fn zero() -> Vec2 { - Vector2::new(zero::(), zero::()) + BaseVec2::new(zero::(), zero::()) } #[inline(always)] @@ -655,19 +655,19 @@ impl + Sub + Mul + Div + impl + Sub + Mul + Div + Neg> Neg> for Vec2 { #[inline(always)] fn neg(&self) -> Vec2 { - Vector2::new(-self[0], -self[1]) + BaseVec2::new(-self[0], -self[1]) } } -impl + Sub + Mul + Div + Neg> NumericVector2 for Vec2 { +impl + Sub + Mul + Div + Neg> NumVec2 for Vec2 { #[inline(always)] fn unit_x() -> Vec2 { - Vector2::new(one::(), zero::()) + BaseVec2::new(one::(), zero::()) } #[inline(always)] fn unit_y() -> Vec2 { - Vector2::new(zero::(), one::()) + BaseVec2::new(zero::(), one::()) } #[inline(always)] @@ -679,11 +679,11 @@ impl + Sub + Mul + Div + impl ToHomogeneous> for Vec2 { #[inline(always)] fn to_homogeneous(&self) -> Vec3 { - Vector3::new(self.x, self.y, zero()) + BaseVec3::new(self.x, self.y, zero()) } } -impl + Sub + Mul + Div + Neg> EuclideanVector for Vec2 { +impl + Sub + Mul + Div + Neg> AffineVec for Vec2 { #[inline(always)] fn length2(&self) -> T { self.dot(self) @@ -755,7 +755,7 @@ impl> FuzzyEq for Vec2 { } } -impl OrdinalVector> for Vec2 { +impl OrdVec> for Vec2 { #[inline(always)] fn less_than(&self, other: &Vec2) -> Vec2 { zip_vec2!(self[] lt other[]) @@ -777,7 +777,7 @@ impl OrdinalVector> for Vec2 { } } -impl EquableVector> for Vec2 { +impl EqVec> for Vec2 { #[inline(always)] fn equal(&self, other: &Vec2) -> Vec2 { zip_vec2!(self[] eq other[]) @@ -789,7 +789,7 @@ impl EquableVector> for Vec2 { } } -impl BooleanVector for Vec2 { +impl BoolVec for Vec2 { #[inline(always)] fn any(&self) -> bool { self[0] || self[1] @@ -802,15 +802,15 @@ impl BooleanVector for Vec2 { #[inline(always)] fn not(&self) -> Vec2 { - Vector2::new(!self[0], !self[1]) + BaseVec2::new(!self[0], !self[1]) } } macro_rules! vec2_type( ($name:ident ) => ( pub impl $name { - #[inline(always)] fn new(x: bool, y: bool) -> $name { Vector2::new(x, y) } - #[inline(always)] fn from_value(v: bool) -> $name { Vector::from_value(v) } + #[inline(always)] fn new(x: bool, y: bool) -> $name { BaseVec2::new(x, y) } + #[inline(always)] fn from_value(v: bool) -> $name { BaseVec::from_value(v) } #[inline(always)] fn dim() -> uint { 2 } #[inline(always)] fn size_of() -> uint { sys::size_of::<$name>() } @@ -818,13 +818,13 @@ macro_rules! vec2_type( ); ($name:ident <$T:ty>) => ( pub impl $name { - #[inline(always)] fn new(x: $T, y: $T) -> $name { Vector2::new(x, y) } - #[inline(always)] fn from_value(v: $T) -> $name { Vector::from_value(v) } - #[inline(always)] fn identity() -> $name { NumericVector::identity() } - #[inline(always)] fn zero() -> $name { NumericVector::zero() } + #[inline(always)] fn new(x: $T, y: $T) -> $name { BaseVec2::new(x, y) } + #[inline(always)] fn from_value(v: $T) -> $name { BaseVec::from_value(v) } + #[inline(always)] fn identity() -> $name { NumVec::identity() } + #[inline(always)] fn zero() -> $name { NumVec::zero() } - #[inline(always)] fn unit_x() -> $name { NumericVector2::unit_x() } - #[inline(always)] fn unit_y() -> $name { NumericVector2::unit_y() } + #[inline(always)] fn unit_x() -> $name { NumVec2::unit_x() } + #[inline(always)] fn unit_y() -> $name { NumVec2::unit_y() } #[inline(always)] fn dim() -> uint { 2 } #[inline(always)] fn size_of() -> uint { sys::size_of::<$name>() } @@ -900,10 +900,10 @@ vec2_type!(Vec2b) #[deriving(Eq)] pub struct Vec3 { x: T, y: T, z: T } -impl Vector for Vec3 { +impl BaseVec for Vec3 { #[inline(always)] fn from_value(value: T) -> Vec3 { - Vector3::new(value, value, value) + BaseVec3::new(value, value, value) } #[inline(always)] @@ -927,7 +927,7 @@ impl Vector for Vec3 { } } -impl Vector3 for Vec3 { +impl BaseVec3 for Vec3 { #[inline(always)] fn new(x: T, y: T, z: T) -> Vec3 { Vec3 { x: x, y: y, z: z } @@ -941,15 +941,15 @@ impl Index for Vec3 { } } -impl + Sub + Mul + Div + Neg> NumericVector for Vec3 { +impl + Sub + Mul + Div + Neg> NumVec for Vec3 { #[inline(always)] fn identity() -> Vec3 { - Vector3::new(one::(), one::(), one::()) + BaseVec3::new(one::(), one::(), one::()) } #[inline(always)] fn zero() -> Vec3 { - Vector3::new(zero::(), zero::(), zero::()) + BaseVec3::new(zero::(), zero::(), zero::()) } #[inline(always)] @@ -1037,31 +1037,31 @@ impl + Sub + Mul + Div + impl + Sub + Mul + Div + Neg> Neg> for Vec3 { #[inline(always)] fn neg(&self) -> Vec3 { - Vector3::new(-self[0], -self[1], -self[2]) + BaseVec3::new(-self[0], -self[1], -self[2]) } } -impl + Sub + Mul + Div + Neg> NumericVector3 for Vec3 { +impl + Sub + Mul + Div + Neg> NumVec3 for Vec3 { #[inline(always)] fn unit_x() -> Vec3 { - Vector3::new(one::(), zero::(), zero::()) + BaseVec3::new(one::(), zero::(), zero::()) } #[inline(always)] fn unit_y() -> Vec3 { - Vector3::new(zero::(), one::(), zero::()) + BaseVec3::new(zero::(), one::(), zero::()) } #[inline(always)] fn unit_z() -> Vec3 { - Vector3::new(zero::(), zero::(), one::()) + BaseVec3::new(zero::(), zero::(), one::()) } #[inline(always)] fn cross(&self, other: &Vec3) -> Vec3 { - Vector3::new((self[1] * other[2]) - (self[2] * other[1]), - (self[2] * other[0]) - (self[0] * other[2]), - (self[0] * other[1]) - (self[1] * other[0])) + BaseVec3::new((self[1] * other[2]) - (self[2] * other[1]), + (self[2] * other[0]) - (self[0] * other[2]), + (self[0] * other[1]) - (self[1] * other[0])) } #[inline(always)] @@ -1073,11 +1073,11 @@ impl + Sub + Mul + Div + impl + Sub + Mul + Div + Neg> ToHomogeneous> for Vec3 { #[inline(always)] fn to_homogeneous(&self) -> Vec4 { - Vector4::new(self.x, self.y, self.z, zero()) + BaseVec4::new(self.x, self.y, self.z, zero()) } } -impl + Sub + Mul + Div + Neg> EuclideanVector for Vec3 { +impl + Sub + Mul + Div + Neg> AffineVec for Vec3 { #[inline(always)] fn length2(&self) -> T { self.dot(self) @@ -1150,7 +1150,7 @@ impl> FuzzyEq for Vec3 { } } -impl OrdinalVector> for Vec3 { +impl OrdVec> for Vec3 { #[inline(always)] fn less_than(&self, other: &Vec3) -> Vec3 { zip_vec3!(self[] lt other[]) @@ -1172,7 +1172,7 @@ impl OrdinalVector> for Vec3 { } } -impl EquableVector> for Vec3 { +impl EqVec> for Vec3 { #[inline(always)] fn equal(&self, other: &Vec3) -> Vec3 { zip_vec3!(self[] eq other[]) @@ -1184,7 +1184,7 @@ impl EquableVector> for Vec3 { } } -impl BooleanVector for Vec3 { +impl BoolVec for Vec3 { #[inline(always)] fn any(&self) -> bool { self[0] || self[1] || self[2] @@ -1197,15 +1197,15 @@ impl BooleanVector for Vec3 { #[inline(always)] fn not(&self) -> Vec3 { - Vector3::new(!self[0], !self[1], !self[2]) + BaseVec3::new(!self[0], !self[1], !self[2]) } } macro_rules! vec3_type( ($name:ident ) => ( pub impl $name { - #[inline(always)] fn new(x: bool, y: bool, z: bool) -> $name { Vector3::new(x, y, z) } - #[inline(always)] fn from_value(v: bool) -> $name { Vector::from_value(v) } + #[inline(always)] fn new(x: bool, y: bool, z: bool) -> $name { BaseVec3::new(x, y, z) } + #[inline(always)] fn from_value(v: bool) -> $name { BaseVec::from_value(v) } #[inline(always)] fn dim() -> uint { 3 } #[inline(always)] fn size_of() -> uint { sys::size_of::<$name>() } @@ -1213,14 +1213,14 @@ macro_rules! vec3_type( ); ($name:ident <$T:ty>) => ( pub impl $name { - #[inline(always)] fn new(x: $T, y: $T, z: $T) -> $name { Vector3::new(x, y, z) } - #[inline(always)] fn from_value(v: $T) -> $name { Vector::from_value(v) } - #[inline(always)] fn identity() -> $name { NumericVector::identity() } - #[inline(always)] fn zero() -> $name { NumericVector::zero() } + #[inline(always)] fn new(x: $T, y: $T, z: $T) -> $name { BaseVec3::new(x, y, z) } + #[inline(always)] fn from_value(v: $T) -> $name { BaseVec::from_value(v) } + #[inline(always)] fn identity() -> $name { NumVec::identity() } + #[inline(always)] fn zero() -> $name { NumVec::zero() } - #[inline(always)] fn unit_x() -> $name { NumericVector3::unit_x() } - #[inline(always)] fn unit_y() -> $name { NumericVector3::unit_y() } - #[inline(always)] fn unit_z() -> $name { NumericVector3::unit_z() } + #[inline(always)] fn unit_x() -> $name { NumVec3::unit_x() } + #[inline(always)] fn unit_y() -> $name { NumVec3::unit_y() } + #[inline(always)] fn unit_z() -> $name { NumVec3::unit_z() } #[inline(always)] fn dim() -> uint { 3 } #[inline(always)] fn size_of() -> uint { sys::size_of::<$name>() } @@ -1297,10 +1297,10 @@ vec3_type!(Vec3b) #[deriving(Eq)] pub struct Vec4 { x: T, y: T, z: T, w: T } -impl Vector for Vec4 { +impl BaseVec for Vec4 { #[inline(always)] fn from_value(value: T) -> Vec4 { - Vector4::new(value, value, value, value) + BaseVec4::new(value, value, value, value) } #[inline(always)] @@ -1325,7 +1325,7 @@ impl Vector for Vec4 { } } -impl Vector4 for Vec4 { +impl BaseVec4 for Vec4 { #[inline(always)] fn new(x: T, y: T, z: T, w: T) -> Vec4 { Vec4 { x: x, y: y, z: z, w: w } @@ -1339,15 +1339,15 @@ impl Index for Vec4 { } } -impl + Sub + Mul + Div + Neg> NumericVector for Vec4 { +impl + Sub + Mul + Div + Neg> NumVec for Vec4 { #[inline(always)] fn identity() -> Vec4 { - Vector4::new(one::(), one::(), one::(), one::()) + BaseVec4::new(one::(), one::(), one::(), one::()) } #[inline(always)] fn zero() -> Vec4 { - Vector4::new(zero::(), zero::(), zero::(), zero::()) + BaseVec4::new(zero::(), zero::(), zero::(), zero::()) } #[inline(always)] @@ -1438,33 +1438,33 @@ impl + Sub + Mul + Div + impl + Sub + Mul + Div + Neg> Neg> for Vec4 { #[inline(always)] fn neg(&self) -> Vec4 { - Vector4::new(-self[0], -self[1], -self[2], -self[3]) + BaseVec4::new(-self[0], -self[1], -self[2], -self[3]) } } -impl NumericVector4 for Vec4 { +impl NumVec4 for Vec4 { #[inline(always)] fn unit_x() -> Vec4 { - Vector4::new(one::(), zero::(), zero::(), zero::()) + BaseVec4::new(one::(), zero::(), zero::(), zero::()) } #[inline(always)] fn unit_y() -> Vec4 { - Vector4::new(zero::(), one::(), zero::(), zero::()) + BaseVec4::new(zero::(), one::(), zero::(), zero::()) } #[inline(always)] fn unit_z() -> Vec4 { - Vector4::new(zero::(), zero::(), one::(), zero::()) + BaseVec4::new(zero::(), zero::(), one::(), zero::()) } #[inline(always)] fn unit_w() -> Vec4 { - Vector4::new(zero::(), zero::(), zero::(), one::()) + BaseVec4::new(zero::(), zero::(), zero::(), one::()) } } -impl + Sub + Mul + Div + Neg> EuclideanVector for Vec4 { +impl + Sub + Mul + Div + Neg> AffineVec for Vec4 { #[inline(always)] fn length2(&self) -> T { self.dot(self) @@ -1538,7 +1538,7 @@ impl> FuzzyEq for Vec4 { } } -impl OrdinalVector> for Vec4 { +impl OrdVec> for Vec4 { #[inline(always)] fn less_than(&self, other: &Vec4) -> Vec4 { zip_vec4!(self[] lt other[]) @@ -1560,7 +1560,7 @@ impl OrdinalVector> for Vec4 { } } -impl EquableVector> for Vec4 { +impl EqVec> for Vec4 { #[inline(always)] fn equal(&self, other: &Vec4) -> Vec4 { zip_vec4!(self[] eq other[]) @@ -1572,7 +1572,7 @@ impl EquableVector> for Vec4 { } } -impl BooleanVector for Vec4 { +impl BoolVec for Vec4 { #[inline(always)] fn any(&self) -> bool { self[0] || self[1] || self[2] || self[3] @@ -1585,15 +1585,15 @@ impl BooleanVector for Vec4 { #[inline(always)] fn not(&self) -> Vec4 { - Vector4::new(!self[0], !self[1], !self[2], !self[3]) + BaseVec4::new(!self[0], !self[1], !self[2], !self[3]) } } macro_rules! vec4_type( ($name:ident ) => ( pub impl $name { - #[inline(always)] fn new(x: bool, y: bool, z: bool, w: bool) -> $name { Vector4::new(x, y, z, w) } - #[inline(always)] fn from_value(v: bool) -> $name { Vector::from_value(v) } + #[inline(always)] fn new(x: bool, y: bool, z: bool, w: bool) -> $name { BaseVec4::new(x, y, z, w) } + #[inline(always)] fn from_value(v: bool) -> $name { BaseVec::from_value(v) } #[inline(always)] fn dim() -> uint { 4 } #[inline(always)] fn size_of() -> uint { sys::size_of::<$name>() } @@ -1601,15 +1601,15 @@ macro_rules! vec4_type( ); ($name:ident <$T:ty>) => ( pub impl $name { - #[inline(always)] fn new(x: $T, y: $T, z: $T, w: $T) -> $name { Vector4::new(x, y, z, w) } - #[inline(always)] fn from_value(v: $T) -> $name { Vector::from_value(v) } - #[inline(always)] fn identity() -> $name { NumericVector::identity() } - #[inline(always)] fn zero() -> $name { NumericVector::zero() } + #[inline(always)] fn new(x: $T, y: $T, z: $T, w: $T) -> $name { BaseVec4::new(x, y, z, w) } + #[inline(always)] fn from_value(v: $T) -> $name { BaseVec::from_value(v) } + #[inline(always)] fn identity() -> $name { NumVec::identity() } + #[inline(always)] fn zero() -> $name { NumVec::zero() } - #[inline(always)] fn unit_x() -> $name { NumericVector4::unit_x() } - #[inline(always)] fn unit_y() -> $name { NumericVector4::unit_y() } - #[inline(always)] fn unit_z() -> $name { NumericVector4::unit_z() } - #[inline(always)] fn unit_w() -> $name { NumericVector4::unit_w() } + #[inline(always)] fn unit_x() -> $name { NumVec4::unit_x() } + #[inline(always)] fn unit_y() -> $name { NumVec4::unit_y() } + #[inline(always)] fn unit_z() -> $name { NumVec4::unit_z() } + #[inline(always)] fn unit_w() -> $name { NumVec4::unit_w() } #[inline(always)] fn dim() -> uint { 4 } #[inline(always)] fn size_of() -> uint { sys::size_of::<$name>() }