Make trait names more succinct

This commit is contained in:
Brendan Zabarauskas 2013-04-02 16:12:13 +11:00
parent 4614930ad3
commit 9116917607
5 changed files with 334 additions and 335 deletions

View file

@ -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<T,V>: Index<uint, V> + Eq + Neg<Self> {
pub trait BaseMat<T,V>: Index<uint, V> + Eq + Neg<Self> {
/**
* # Return value
*
@ -243,7 +243,7 @@ pub trait Matrix<T,V>: Index<uint, V> + Eq + Neg<Self> {
/**
* A 2 x 2 matrix
*/
pub trait Matrix2<T,V>: Matrix<T,V> {
pub trait BaseMat2<T,V>: BaseMat<T,V> {
fn new(c0r0: T, c0r1: T,
c1r0: T, c1r1: T) -> Self;
@ -259,7 +259,7 @@ pub trait Matrix2<T,V>: Matrix<T,V> {
/**
* A 3 x 3 matrix
*/
pub trait Matrix3<T,V>: Matrix<T,V> {
pub trait BaseMat3<T,V>: BaseMat<T,V> {
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<T,V>: Matrix<T,V> {
/**
* A 4 x 4 matrix
*/
pub trait Matrix4<T,V>: Matrix<T,V> {
pub trait BaseMat4<T,V>: BaseMat<T,V> {
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<T,V>: Matrix<T,V> {
#[deriving(Eq)]
pub struct Mat2<T> { x: Vec2<T>, y: Vec2<T> }
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec2<T>> for Mat2<T> {
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> BaseMat<T, Vec2<T>> for Mat2<T> {
#[inline(always)]
fn col(&self, i: uint) -> Vec2<T> { self[i] }
#[inline(always)]
fn row(&self, i: uint) -> Vec2<T> {
Vector2::new(self[0][i],
BaseVec2::new(self[0][i],
self[1][i])
}
@ -341,8 +341,8 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
*/
#[inline(always)]
fn from_value(value: T) -> Mat2<T> {
Matrix2::new(value, zero(),
zero(), value)
BaseMat2::new(value, zero(),
zero(), value)
}
/**
@ -358,8 +358,8 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
*/
#[inline(always)]
fn identity() -> Mat2<T> {
Matrix2::new( one::<T>(), zero::<T>(),
zero::<T>(), one::<T>())
BaseMat2::new( one::<T>(), zero::<T>(),
zero::<T>(), one::<T>())
}
/**
@ -375,38 +375,38 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
*/
#[inline(always)]
fn zero() -> Mat2<T> {
Matrix2::new(zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>())
BaseMat2::new(zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>())
}
#[inline(always)]
fn mul_t(&self, value: T) -> Mat2<T> {
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<T>) -> Vec2<T> {
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<T>) -> Mat2<T> {
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<T>) -> Mat2<T> {
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<T>) -> Mat2<T> {
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>) -> T {
@ -427,15 +427,15 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
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<T> {
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
#[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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
#[inline(always)]
fn is_identity(&self) -> bool {
self.fuzzy_eq(&Matrix::identity())
self.fuzzy_eq(&BaseMat::identity())
}
#[inline(always)]
@ -518,7 +518,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
#[inline(always)]
fn is_rotated(&self) -> bool {
!self.fuzzy_eq(&Matrix::identity())
!self.fuzzy_eq(&BaseMat::identity())
}
#[inline(always)]
@ -538,7 +538,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix2<T, Vec2<T>> for Mat2<T> {
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> BaseMat2<T, Vec2<T>> for Mat2<T> {
/**
* Construct a 2 x 2 matrix
*
@ -559,8 +559,8 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
#[inline(always)]
fn new(c0r0: T, c0r1: T,
c1r0: T, c1r1: T) -> Mat2<T> {
Matrix2::from_cols(Vector2::new::<T,Vec2<T>>(c0r0, c0r1),
Vector2::new::<T,Vec2<T>>(c1r0, c1r1))
BaseMat2::from_cols(BaseVec2::new::<T,Vec2<T>>(c0r0, c0r1),
BaseVec2::new::<T,Vec2<T>>(c1r0, c1r1))
}
/**
@ -590,8 +590,8 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
*/
#[inline(always)]
fn to_mat3(&self) -> Mat3<T> {
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
*/
#[inline(always)]
fn to_mat4(&self) -> Mat4<T> {
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<T:Copy> Index<uint, Vec2<T>> for Mat2<T> {
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat2<T>> for Mat2<T> {
#[inline(always)]
fn neg(&self) -> Mat2<T> {
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<f64,Vec2f64>)
#[deriving(Eq)]
pub struct Mat3<T> { x: Vec3<T>, y: Vec3<T>, z: Vec3<T> }
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec3<T>> for Mat3<T> {
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> BaseMat<T, Vec3<T>> for Mat3<T> {
#[inline(always)]
fn col(&self, i: uint) -> Vec3<T> { self[i] }
#[inline(always)]
fn row(&self, i: uint) -> Vec3<T> {
Vector3::new(self[0][i],
BaseVec3::new(self[0][i],
self[1][i],
self[2][i])
}
@ -754,9 +754,9 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
*/
#[inline(always)]
fn from_value(value: T) -> Mat3<T> {
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
*/
#[inline(always)]
fn identity() -> Mat3<T> {
Matrix3::new( one::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), one::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), one::<T>())
BaseMat3::new( one::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), one::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), one::<T>())
}
/**
@ -794,52 +794,52 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
*/
#[inline(always)]
fn zero() -> Mat3<T> {
Matrix3::new(zero::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), zero::<T>())
BaseMat3::new(zero::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), zero::<T>())
}
#[inline(always)]
fn mul_t(&self, value: T) -> Mat3<T> {
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<T>) -> Vec3<T> {
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<T>) -> Mat3<T> {
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<T>) -> Mat3<T> {
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<T>) -> Mat3<T> {
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>) -> T {
@ -860,18 +860,18 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
if d.fuzzy_eq(&zero()) {
None
} else {
let m: Mat3<T> = 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<T> = 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<T> {
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
#[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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
#[inline(always)]
fn is_identity(&self) -> bool {
self.fuzzy_eq(&Matrix::identity())
self.fuzzy_eq(&BaseMat::identity())
}
#[inline(always)]
@ -971,7 +971,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
#[inline(always)]
fn is_rotated(&self) -> bool {
!self.fuzzy_eq(&Matrix::identity())
!self.fuzzy_eq(&BaseMat::identity())
}
#[inline(always)]
@ -997,7 +997,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix3<T, Vec3<T>> for Mat3<T> {
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> BaseMat3<T, Vec3<T>> for Mat3<T> {
/**
* Construct a 3 x 3 matrix
*
@ -1022,9 +1022,9 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
fn new(c0r0:T, c0r1:T, c0r2:T,
c1r0:T, c1r1:T, c1r2:T,
c2r0:T, c2r1:T, c2r2:T) -> Mat3<T> {
Matrix3::from_cols(Vector3::new::<T,Vec3<T>>(c0r0, c0r1, c0r2),
Vector3::new::<T,Vec3<T>>(c1r0, c1r1, c1r2),
Vector3::new::<T,Vec3<T>>(c2r0, c2r1, c2r2))
BaseMat3::from_cols(BaseVec3::new::<T,Vec3<T>>(c0r0, c0r1, c0r2),
BaseVec3::new::<T,Vec3<T>>(c1r0, c1r1, c1r2),
BaseVec3::new::<T,Vec3<T>>(c2r0, c2r1, c2r2))
}
/**
@ -1061,9 +1061,9 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
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<T>, y: Vec3<T>, z: Vec3<T>) -> Mat3<T> {
Matrix3::from_cols(x, y, z)
BaseMat3::from_cols(x, y, z)
}
#[inline(always)]
@ -1147,7 +1147,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
*/
#[inline(always)]
fn to_mat4(&self) -> Mat4<T> {
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<T:Copy> Index<uint, Vec3<T>> for Mat3<T> {
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat3<T>> for Mat3<T> {
#[inline(always)]
fn neg(&self) -> Mat3<T> {
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<f64,Vec3f64>)
#[deriving(Eq)]
pub struct Mat4<T> { x: Vec4<T>, y: Vec4<T>, z: Vec4<T>, w: Vec4<T> }
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec4<T>> for Mat4<T> {
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> BaseMat<T, Vec4<T>> for Mat4<T> {
#[inline(always)]
fn col(&self, i: uint) -> Vec4<T> { self[i] }
#[inline(always)]
fn row(&self, i: uint) -> Vec4<T> {
Vector4::new(self[0][i],
BaseVec4::new(self[0][i],
self[1][i],
self[2][i],
self[3][i])
@ -1346,10 +1346,10 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
*/
#[inline(always)]
fn from_value(value: T) -> Mat4<T> {
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
*/
#[inline(always)]
fn identity() -> Mat4<T> {
Matrix4::new( one::<T>(), zero::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), one::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), one::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), zero::<T>(), one::<T>())
BaseMat4::new( one::<T>(), zero::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), one::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), one::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), zero::<T>(), one::<T>())
}
/**
@ -1392,65 +1392,65 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
*/
#[inline(always)]
fn zero() -> Mat4<T> {
Matrix4::new(zero::<T>(), zero::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), zero::<T>(), zero::<T>())
BaseMat4::new(zero::<T>(), zero::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), zero::<T>(), zero::<T>(),
zero::<T>(), zero::<T>(), zero::<T>(), zero::<T>())
}
#[inline(always)]
fn mul_t(&self, value: T) -> Mat4<T> {
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<T>) -> Vec4<T> {
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<T>) -> Mat4<T> {
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<T>) -> Mat4<T> {
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<T>) -> Mat4<T> {
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
}
fn determinant(&self) -> T {
let m0: Mat3<T> = 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<T> = 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<T> = 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<T> = 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<T> = 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<T> = 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<T> = 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<T> = 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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
// and essentially reduce [A|I]
let mut A = *self;
let mut I: Mat4<T> = Matrix::identity();
let mut I: Mat4<T> = BaseMat::identity();
for uint::range(0, 4) |j| {
// Find largest element in col j
@ -1530,10 +1530,10 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
#[inline(always)]
fn transpose(&self) -> Mat4<T> {
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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
#[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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
#[inline(always)]
fn is_identity(&self) -> bool {
self.fuzzy_eq(&Matrix::identity())
self.fuzzy_eq(&BaseMat::identity())
}
#[inline(always)]
@ -1652,7 +1652,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
#[inline(always)]
fn is_rotated(&self) -> bool {
!self.fuzzy_eq(&Matrix::identity())
!self.fuzzy_eq(&BaseMat::identity())
}
#[inline(always)]
@ -1685,7 +1685,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
}
}
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix4<T, Vec4<T>> for Mat4<T> {
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> BaseMat4<T, Vec4<T>> for Mat4<T> {
/**
* Construct a 4 x 4 matrix
*
@ -1714,10 +1714,10 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,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) -> Mat4<T> {
Matrix4::from_cols(Vector4::new::<T,Vec4<T>>(c0r0, c0r1, c0r2, c0r3),
Vector4::new::<T,Vec4<T>>(c1r0, c1r1, c1r2, c1r3),
Vector4::new::<T,Vec4<T>>(c2r0, c2r1, c2r2, c2r3),
Vector4::new::<T,Vec4<T>>(c3r0, c3r1, c3r2, c3r3))
BaseMat4::from_cols(BaseVec4::new::<T,Vec4<T>>(c0r0, c0r1, c0r2, c0r3),
BaseVec4::new::<T,Vec4<T>>(c1r0, c1r1, c1r2, c1r3),
BaseVec4::new::<T,Vec4<T>>(c2r0, c2r1, c2r2, c2r3),
BaseVec4::new::<T,Vec4<T>>(c3r0, c3r1, c3r2, c3r3))
}
/**
@ -1752,7 +1752,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> +
impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat4<T>> for Mat4<T> {
#[inline(always)]
fn neg(&self) -> Mat4<T> {
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 }

View file

@ -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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> +
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)
}

View file

@ -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<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,
*/
#[inline(always)]
fn new(w: T, xi: T, yj: T, zk: T) -> Quat<T> {
Quat::from_sv(w, Vector3::new(xi, yj, zk))
Quat::from_sv(w, BaseVec3::new(xi, yj, zk))
}
/**
@ -122,7 +121,7 @@ pub impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,
#[inline(always)]
fn from_axes(x: Vec3<T>, y: Vec3<T>, z: Vec3<T>) -> Quat<T> {
let m: Mat3<T> = Matrix3::from_axes(x, y, z); m.to_quat()
let m: Mat3<T> = BaseMat3::from_axes(x, y, z); m.to_quat()
}
fn get_angle_axis(&self) -> (T, Vec3<T>) {
@ -131,7 +130,7 @@ pub impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,
#[inline(always)]
fn look_at(dir: &Vec3<T>, up: &Vec3<T>) -> Quat<T> {
let m: Mat3<T> = Matrix3::look_at(dir, up); m.to_quat()
let m: Mat3<T> = BaseMat3::look_at(dir, up); m.to_quat()
}
/**
@ -365,9 +364,9 @@ pub impl<T:Copy + Float + Zero + One + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,
let _1: T = one();
Matrix3::new(_1 - yy2 - zz2, xy2 + sz2, xz2 - sy2,
xy2 - sz2, _1 - xx2 - zz2, yz2 + sx2,
xz2 + sy2, yz2 - sx2, _1 - xx2 - yy2)
BaseMat3::new(_1 - yy2 - zz2, xy2 + sz2, xz2 - sy2,
xy2 - sz2, _1 - xx2 - zz2, yz2 + sx2,
xz2 + sy2, yz2 - sx2, _1 - xx2 - yy2)
}
}

View file

@ -238,7 +238,7 @@ fn test_mat3() {
0.0, 0.5, -2.0,
0.0, 0.0, 1.0));
let ident: Mat3<float> = Matrix::identity();
let ident: Mat3<float> = BaseMat::identity();
assert!(ident.inverse().unwrap() == ident);

View file

@ -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<T>: Index<uint,T> + Eq {
pub trait BaseVec<T>: Index<uint,T> + Eq {
/**
* Construct the vector from a single value, copying it to each component
*/
@ -39,28 +39,28 @@ pub trait Vector<T>: Index<uint,T> + Eq {
/**
* A generic 2-dimensional vector
*/
pub trait Vector2<T>: Vector<T> {
pub trait BaseVec2<T>: BaseVec<T> {
fn new(x: T, y: T) -> Self;
}
/**
* A generic 3-dimensional vector
*/
pub trait Vector3<T>: Vector<T> {
pub trait BaseVec3<T>: BaseVec<T> {
fn new(x: T, y: T, z: T) -> Self;
}
/**
* A generic 4-dimensional vector
*/
pub trait Vector4<T>: Vector<T> {
pub trait BaseVec4<T>: BaseVec<T> {
fn new(x: T, y: T, z: T, w: T) -> Self;
}
/**
* A vector with numeric components
*/
pub trait NumericVector<T>: Vector<T> + Neg<Self> {
pub trait NumVec<T>: BaseVec<T> + Neg<Self> {
/**
* The standard basis vector
*
@ -166,7 +166,7 @@ pub trait NumericVector<T>: Vector<T> + Neg<Self> {
/**
* A 2-dimensional vector with numeric components
*/
pub trait NumericVector2<T>: NumericVector<T> {
pub trait NumVec2<T>: NumVec<T> {
fn unit_x() -> Self;
fn unit_y() -> Self;
@ -181,7 +181,7 @@ pub trait NumericVector2<T>: NumericVector<T> {
/**
* A 3-dimensional vector with numeric components
*/
pub trait NumericVector3<T>: NumericVector<T> {
pub trait NumVec3<T>: NumVec<T> {
fn unit_x() -> Self;
fn unit_y() -> Self;
fn unit_z() -> Self;
@ -202,7 +202,7 @@ pub trait NumericVector3<T>: NumericVector<T> {
/**
* A 4-dimensional vector with numeric components
*/
pub trait NumericVector4<T>: NumericVector<T> {
pub trait NumVec4<T>: NumVec<T> {
fn unit_x() -> Self;
fn unit_y() -> Self;
fn unit_z() -> Self;
@ -223,7 +223,7 @@ pub trait ToHomogeneous<H> {
*
* * `T` - The type of the components. This should be a floating point type.
*/
pub trait EuclideanVector<T>: NumericVector<T> {
pub trait AffineVec<T>: NumVec<T> {
/**
* # Return value
*
@ -310,7 +310,7 @@ pub trait EuclideanVector<T>: NumericVector<T> {
* 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<T, BoolVec>: Vector<T> {
pub trait OrdVec<T, BoolVec>: BaseVec<T> {
/**
* Component-wise compare of `self < other`
*/
@ -339,7 +339,7 @@ pub trait OrdinalVector<T, BoolVec>: Vector<T> {
* 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<T, BoolVec>: Vector<T> {
pub trait EqVec<T, BoolVec>: BaseVec<T> {
/**
* Component-wise compare of `self == other`
*/
@ -358,7 +358,7 @@ pub trait EquableVector<T, BoolVec>: Vector<T> {
* 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<bool> {
pub trait BoolVec: BaseVec<bool> {
/**
* # Return value
*
@ -381,7 +381,7 @@ pub trait BooleanVector: Vector<bool> {
fn not(&self) -> Self;
}
pub trait TrigVec<T>: Vector<T> {
pub trait TrigVec<T>: BaseVec<T> {
fn radians(&self) -> Self;
fn degrees(&self) -> Self;
@ -405,7 +405,7 @@ pub trait TrigVec<T>: Vector<T> {
// fn atanh() -> Self;
}
pub trait ExpVec<T>: Vector<T> {
pub trait ExpVec<T>: BaseVec<T> {
// Exponential functions
fn pow_t(&self, n: Self) -> Self;
fn pow_v(&self, n: T) -> Self;
@ -417,7 +417,7 @@ pub trait ExpVec<T>: Vector<T> {
fn inv_sqrt(&self) -> Self;
}
pub trait ApproxVec<T>: Vector<T> {
pub trait ApproxVec<T>: BaseVec<T> {
// Whole-number approximation functions
fn floor(&self) -> Self;
fn trunc(&self) -> Self;
@ -427,7 +427,7 @@ pub trait ApproxVec<T>: Vector<T> {
fn fract(&self) -> Self;
}
pub trait SignedVec<T,BV>: Vector<T> {
pub trait SignedVec<T,BV>: BaseVec<T> {
fn is_positive(&self) -> BV;
fn is_negative(&self) -> BV;
fn is_nonpositive(&self) -> BV;
@ -438,7 +438,7 @@ pub trait SignedVec<T,BV>: Vector<T> {
fn copysign(&self, other: Self) -> Self;
}
pub trait ExtentVec<T>: Vector<T> {
pub trait ExtentVec<T>: BaseVec<T> {
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<T>: Vector<T> {
fn clamp_t(&self, mn: T, mx: T) -> Self;
}
pub trait MixVec<T>: Vector<T> {
pub trait MixVec<T>: BaseVec<T> {
// 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<T>: Vector<T> {
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<T> { x: T, y: T }
impl<T:Copy + Eq> Vector<T> for Vec2<T> {
impl<T:Copy + Eq> BaseVec<T> for Vec2<T> {
#[inline(always)]
fn from_value(value: T) -> Vec2<T> {
Vector2::new(value, value)
BaseVec2::new(value, value)
}
#[inline(always)]
@ -548,7 +548,7 @@ impl<T:Copy + Eq> Vector<T> for Vec2<T> {
}
}
impl<T> Vector2<T> for Vec2<T> {
impl<T> BaseVec2<T> for Vec2<T> {
#[inline(always)]
fn new(x: T, y: T ) -> Vec2<T> {
Vec2 { x: x, y: y }
@ -562,15 +562,15 @@ impl<T:Copy + Eq> Index<uint, T> for Vec2<T> {
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec2<T> {
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumVec<T> for Vec2<T> {
#[inline(always)]
fn identity() -> Vec2<T> {
Vector2::new(one::<T>(), one::<T>())
BaseVec2::new(one::<T>(), one::<T>())
}
#[inline(always)]
fn zero() -> Vec2<T> {
Vector2::new(zero::<T>(), zero::<T>())
BaseVec2::new(zero::<T>(), zero::<T>())
}
#[inline(always)]
@ -655,19 +655,19 @@ impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> +
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec2<T>> for Vec2<T> {
#[inline(always)]
fn neg(&self) -> Vec2<T> {
Vector2::new(-self[0], -self[1])
BaseVec2::new(-self[0], -self[1])
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector2<T> for Vec2<T> {
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumVec2<T> for Vec2<T> {
#[inline(always)]
fn unit_x() -> Vec2<T> {
Vector2::new(one::<T>(), zero::<T>())
BaseVec2::new(one::<T>(), zero::<T>())
}
#[inline(always)]
fn unit_y() -> Vec2<T> {
Vector2::new(zero::<T>(), one::<T>())
BaseVec2::new(zero::<T>(), one::<T>())
}
#[inline(always)]
@ -679,11 +679,11 @@ impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> +
impl<T:Copy + Number + Zero> ToHomogeneous<Vec3<T>> for Vec2<T> {
#[inline(always)]
fn to_homogeneous(&self) -> Vec3<T> {
Vector3::new(self.x, self.y, zero())
BaseVec3::new(self.x, self.y, zero())
}
}
impl<T:Copy + Float + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec2<T> {
impl<T:Copy + Float + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> AffineVec<T> for Vec2<T> {
#[inline(always)]
fn length2(&self) -> T {
self.dot(self)
@ -755,7 +755,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Vec2<T> {
}
}
impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec2<bool>> for Vec2<T> {
impl<T:Copy + Ord + Eq> OrdVec<T, Vec2<bool>> for Vec2<T> {
#[inline(always)]
fn less_than(&self, other: &Vec2<T>) -> Vec2<bool> {
zip_vec2!(self[] lt other[])
@ -777,7 +777,7 @@ impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec2<bool>> for Vec2<T> {
}
}
impl<T:Copy + Eq> EquableVector<T, Vec2<bool>> for Vec2<T> {
impl<T:Copy + Eq> EqVec<T, Vec2<bool>> for Vec2<T> {
#[inline(always)]
fn equal(&self, other: &Vec2<T>) -> Vec2<bool> {
zip_vec2!(self[] eq other[])
@ -789,7 +789,7 @@ impl<T:Copy + Eq> EquableVector<T, Vec2<bool>> for Vec2<T> {
}
}
impl BooleanVector for Vec2<bool> {
impl BoolVec for Vec2<bool> {
#[inline(always)]
fn any(&self) -> bool {
self[0] || self[1]
@ -802,15 +802,15 @@ impl BooleanVector for Vec2<bool> {
#[inline(always)]
fn not(&self) -> Vec2<bool> {
Vector2::new(!self[0], !self[1])
BaseVec2::new(!self[0], !self[1])
}
}
macro_rules! vec2_type(
($name:ident <bool>) => (
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<bool>)
#[deriving(Eq)]
pub struct Vec3<T> { x: T, y: T, z: T }
impl<T:Copy + Eq> Vector<T> for Vec3<T> {
impl<T:Copy + Eq> BaseVec<T> for Vec3<T> {
#[inline(always)]
fn from_value(value: T) -> Vec3<T> {
Vector3::new(value, value, value)
BaseVec3::new(value, value, value)
}
#[inline(always)]
@ -927,7 +927,7 @@ impl<T:Copy + Eq> Vector<T> for Vec3<T> {
}
}
impl<T> Vector3<T> for Vec3<T> {
impl<T> BaseVec3<T> for Vec3<T> {
#[inline(always)]
fn new(x: T, y: T, z: T) -> Vec3<T> {
Vec3 { x: x, y: y, z: z }
@ -941,15 +941,15 @@ impl<T:Copy + Eq> Index<uint, T> for Vec3<T> {
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec3<T> {
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumVec<T> for Vec3<T> {
#[inline(always)]
fn identity() -> Vec3<T> {
Vector3::new(one::<T>(), one::<T>(), one::<T>())
BaseVec3::new(one::<T>(), one::<T>(), one::<T>())
}
#[inline(always)]
fn zero() -> Vec3<T> {
Vector3::new(zero::<T>(), zero::<T>(), zero::<T>())
BaseVec3::new(zero::<T>(), zero::<T>(), zero::<T>())
}
#[inline(always)]
@ -1037,31 +1037,31 @@ impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> +
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec3<T>> for Vec3<T> {
#[inline(always)]
fn neg(&self) -> Vec3<T> {
Vector3::new(-self[0], -self[1], -self[2])
BaseVec3::new(-self[0], -self[1], -self[2])
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector3<T> for Vec3<T> {
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumVec3<T> for Vec3<T> {
#[inline(always)]
fn unit_x() -> Vec3<T> {
Vector3::new(one::<T>(), zero::<T>(), zero::<T>())
BaseVec3::new(one::<T>(), zero::<T>(), zero::<T>())
}
#[inline(always)]
fn unit_y() -> Vec3<T> {
Vector3::new(zero::<T>(), one::<T>(), zero::<T>())
BaseVec3::new(zero::<T>(), one::<T>(), zero::<T>())
}
#[inline(always)]
fn unit_z() -> Vec3<T> {
Vector3::new(zero::<T>(), zero::<T>(), one::<T>())
BaseVec3::new(zero::<T>(), zero::<T>(), one::<T>())
}
#[inline(always)]
fn cross(&self, other: &Vec3<T>) -> Vec3<T> {
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<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> +
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> ToHomogeneous<Vec4<T>> for Vec3<T> {
#[inline(always)]
fn to_homogeneous(&self) -> Vec4<T> {
Vector4::new(self.x, self.y, self.z, zero())
BaseVec4::new(self.x, self.y, self.z, zero())
}
}
impl<T:Copy + Float + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec3<T> {
impl<T:Copy + Float + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> AffineVec<T> for Vec3<T> {
#[inline(always)]
fn length2(&self) -> T {
self.dot(self)
@ -1150,7 +1150,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Vec3<T> {
}
}
impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec3<bool>> for Vec3<T> {
impl<T:Copy + Ord + Eq> OrdVec<T, Vec3<bool>> for Vec3<T> {
#[inline(always)]
fn less_than(&self, other: &Vec3<T>) -> Vec3<bool> {
zip_vec3!(self[] lt other[])
@ -1172,7 +1172,7 @@ impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec3<bool>> for Vec3<T> {
}
}
impl<T:Copy + Eq> EquableVector<T, Vec3<bool>> for Vec3<T> {
impl<T:Copy + Eq> EqVec<T, Vec3<bool>> for Vec3<T> {
#[inline(always)]
fn equal(&self, other: &Vec3<T>) -> Vec3<bool> {
zip_vec3!(self[] eq other[])
@ -1184,7 +1184,7 @@ impl<T:Copy + Eq> EquableVector<T, Vec3<bool>> for Vec3<T> {
}
}
impl BooleanVector for Vec3<bool> {
impl BoolVec for Vec3<bool> {
#[inline(always)]
fn any(&self) -> bool {
self[0] || self[1] || self[2]
@ -1197,15 +1197,15 @@ impl BooleanVector for Vec3<bool> {
#[inline(always)]
fn not(&self) -> Vec3<bool> {
Vector3::new(!self[0], !self[1], !self[2])
BaseVec3::new(!self[0], !self[1], !self[2])
}
}
macro_rules! vec3_type(
($name:ident <bool>) => (
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<bool>)
#[deriving(Eq)]
pub struct Vec4<T> { x: T, y: T, z: T, w: T }
impl<T:Copy + Eq> Vector<T> for Vec4<T> {
impl<T:Copy + Eq> BaseVec<T> for Vec4<T> {
#[inline(always)]
fn from_value(value: T) -> Vec4<T> {
Vector4::new(value, value, value, value)
BaseVec4::new(value, value, value, value)
}
#[inline(always)]
@ -1325,7 +1325,7 @@ impl<T:Copy + Eq> Vector<T> for Vec4<T> {
}
}
impl<T> Vector4<T> for Vec4<T> {
impl<T> BaseVec4<T> for Vec4<T> {
#[inline(always)]
fn new(x: T, y: T, z: T, w: T) -> Vec4<T> {
Vec4 { x: x, y: y, z: z, w: w }
@ -1339,15 +1339,15 @@ impl<T:Copy + Eq> Index<uint, T> for Vec4<T> {
}
}
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec4<T> {
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumVec<T> for Vec4<T> {
#[inline(always)]
fn identity() -> Vec4<T> {
Vector4::new(one::<T>(), one::<T>(), one::<T>(), one::<T>())
BaseVec4::new(one::<T>(), one::<T>(), one::<T>(), one::<T>())
}
#[inline(always)]
fn zero() -> Vec4<T> {
Vector4::new(zero::<T>(), zero::<T>(), zero::<T>(), zero::<T>())
BaseVec4::new(zero::<T>(), zero::<T>(), zero::<T>(), zero::<T>())
}
#[inline(always)]
@ -1438,33 +1438,33 @@ impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> +
impl<T:Copy + Number + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec4<T>> for Vec4<T> {
#[inline(always)]
fn neg(&self) -> Vec4<T> {
Vector4::new(-self[0], -self[1], -self[2], -self[3])
BaseVec4::new(-self[0], -self[1], -self[2], -self[3])
}
}
impl<T:Copy + Number + Zero + One> NumericVector4<T> for Vec4<T> {
impl<T:Copy + Number + Zero + One> NumVec4<T> for Vec4<T> {
#[inline(always)]
fn unit_x() -> Vec4<T> {
Vector4::new(one::<T>(), zero::<T>(), zero::<T>(), zero::<T>())
BaseVec4::new(one::<T>(), zero::<T>(), zero::<T>(), zero::<T>())
}
#[inline(always)]
fn unit_y() -> Vec4<T> {
Vector4::new(zero::<T>(), one::<T>(), zero::<T>(), zero::<T>())
BaseVec4::new(zero::<T>(), one::<T>(), zero::<T>(), zero::<T>())
}
#[inline(always)]
fn unit_z() -> Vec4<T> {
Vector4::new(zero::<T>(), zero::<T>(), one::<T>(), zero::<T>())
BaseVec4::new(zero::<T>(), zero::<T>(), one::<T>(), zero::<T>())
}
#[inline(always)]
fn unit_w() -> Vec4<T> {
Vector4::new(zero::<T>(), zero::<T>(), zero::<T>(), one::<T>())
BaseVec4::new(zero::<T>(), zero::<T>(), zero::<T>(), one::<T>())
}
}
impl<T:Copy + Float + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec4<T> {
impl<T:Copy + Float + Zero + One + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> AffineVec<T> for Vec4<T> {
#[inline(always)]
fn length2(&self) -> T {
self.dot(self)
@ -1538,7 +1538,7 @@ impl<T:Copy + Float + Zero + One + FuzzyEq<T>> FuzzyEq<T> for Vec4<T> {
}
}
impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec4<bool>> for Vec4<T> {
impl<T:Copy + Ord + Eq> OrdVec<T, Vec4<bool>> for Vec4<T> {
#[inline(always)]
fn less_than(&self, other: &Vec4<T>) -> Vec4<bool> {
zip_vec4!(self[] lt other[])
@ -1560,7 +1560,7 @@ impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec4<bool>> for Vec4<T> {
}
}
impl<T:Copy + Eq> EquableVector<T, Vec4<bool>> for Vec4<T> {
impl<T:Copy + Eq> EqVec<T, Vec4<bool>> for Vec4<T> {
#[inline(always)]
fn equal(&self, other: &Vec4<T>) -> Vec4<bool> {
zip_vec4!(self[] eq other[])
@ -1572,7 +1572,7 @@ impl<T:Copy + Eq> EquableVector<T, Vec4<bool>> for Vec4<T> {
}
}
impl BooleanVector for Vec4<bool> {
impl BoolVec for Vec4<bool> {
#[inline(always)]
fn any(&self) -> bool {
self[0] || self[1] || self[2] || self[3]
@ -1585,15 +1585,15 @@ impl BooleanVector for Vec4<bool> {
#[inline(always)]
fn not(&self) -> Vec4<bool> {
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 <bool>) => (
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>() }