Remove instances of 'pure'
This commit is contained in:
parent
8b94369a38
commit
27603dd6bd
13 changed files with 607 additions and 607 deletions
78
src/mat.rs
78
src/mat.rs
|
@ -24,89 +24,89 @@ pub trait Matrix<T,V>: Index<uint, V> + Eq + Neg<Self> {
|
|||
*
|
||||
* The column vector at `i`
|
||||
*/
|
||||
pure fn col(&self, i: uint) -> V;
|
||||
fn col(&self, i: uint) -> V;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The row vector at `i`
|
||||
*/
|
||||
pure fn row(&self, i: uint) -> V;
|
||||
fn row(&self, i: uint) -> V;
|
||||
|
||||
/**
|
||||
* Construct a diagonal matrix with the major diagonal set to `value`
|
||||
*/
|
||||
static pure fn from_value(value: T) -> Self;
|
||||
static fn from_value(value: T) -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The identity matrix
|
||||
*/
|
||||
static pure fn identity() -> Self;
|
||||
static fn identity() -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* A matrix with all elements set to zero
|
||||
*/
|
||||
static pure fn zero() -> Self;
|
||||
static fn zero() -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The scalar multiplication of this matrix and `value`
|
||||
*/
|
||||
pure fn mul_t(&self, value: T) -> Self;
|
||||
fn mul_t(&self, value: T) -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The matrix vector product of the matrix and `vec`
|
||||
*/
|
||||
pure fn mul_v(&self, vec: &V) -> V;
|
||||
fn mul_v(&self, vec: &V) -> V;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The matrix addition of the matrix and `other`
|
||||
*/
|
||||
pure fn add_m(&self, other: &Self) -> Self;
|
||||
fn add_m(&self, other: &Self) -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The difference between the matrix and `other`
|
||||
*/
|
||||
pure fn sub_m(&self, other: &Self) -> Self;
|
||||
fn sub_m(&self, other: &Self) -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The matrix product of the matrix and `other`
|
||||
*/
|
||||
pure fn mul_m(&self, other: &Self) -> Self;
|
||||
fn mul_m(&self, other: &Self) -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The matrix dot product of the matrix and `other`
|
||||
*/
|
||||
pure fn dot(&self, other: &Self) -> T;
|
||||
fn dot(&self, other: &Self) -> T;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The determinant of the matrix
|
||||
*/
|
||||
pure fn determinant(&self) -> T;
|
||||
fn determinant(&self) -> T;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The sum of the main diagonal of the matrix
|
||||
*/
|
||||
pure fn trace(&self) -> T;
|
||||
fn trace(&self) -> T;
|
||||
|
||||
/**
|
||||
* Returns the inverse of the matrix
|
||||
|
@ -116,14 +116,14 @@ pub trait Matrix<T,V>: Index<uint, V> + Eq + Neg<Self> {
|
|||
* * `Some(m)` - if the inversion was successful, where `m` is the inverted matrix
|
||||
* * `None` - if the inversion was unsuccessful (because the matrix was not invertable)
|
||||
*/
|
||||
pure fn inverse(&self) -> Option<Self>;
|
||||
fn inverse(&self) -> Option<Self>;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The transposed matrix
|
||||
*/
|
||||
pure fn transpose(&self) -> Self;
|
||||
fn transpose(&self) -> Self;
|
||||
|
||||
/**
|
||||
* Check to see if the matrix is an identity matrix
|
||||
|
@ -132,7 +132,7 @@ pub trait Matrix<T,V>: Index<uint, V> + Eq + Neg<Self> {
|
|||
*
|
||||
* `true` if the matrix is approximately equal to the identity matrix
|
||||
*/
|
||||
pure fn is_identity(&self) -> bool;
|
||||
fn is_identity(&self) -> bool;
|
||||
|
||||
/**
|
||||
* Check to see if the matrix is diagonal
|
||||
|
@ -142,7 +142,7 @@ pub trait Matrix<T,V>: Index<uint, V> + Eq + Neg<Self> {
|
|||
* `true` all the elements outside the main diagonal are approximately
|
||||
* equal to zero.
|
||||
*/
|
||||
pure fn is_diagonal(&self) -> bool;
|
||||
fn is_diagonal(&self) -> bool;
|
||||
|
||||
/**
|
||||
* Check to see if the matrix is rotated
|
||||
|
@ -151,7 +151,7 @@ pub trait Matrix<T,V>: Index<uint, V> + Eq + Neg<Self> {
|
|||
*
|
||||
* `true` if the matrix is not approximately equal to the identity matrix.
|
||||
*/
|
||||
pure fn is_rotated(&self) -> bool;
|
||||
fn is_rotated(&self) -> bool;
|
||||
|
||||
/**
|
||||
* Check to see if the matrix is symmetric
|
||||
|
@ -160,7 +160,7 @@ pub trait Matrix<T,V>: Index<uint, V> + Eq + Neg<Self> {
|
|||
*
|
||||
* `true` if the matrix is approximately equal to its transpose).
|
||||
*/
|
||||
pure fn is_symmetric(&self) -> bool;
|
||||
fn is_symmetric(&self) -> bool;
|
||||
|
||||
/**
|
||||
* Check to see if the matrix is invertable
|
||||
|
@ -169,71 +169,71 @@ pub trait Matrix<T,V>: Index<uint, V> + Eq + Neg<Self> {
|
|||
*
|
||||
* `true` if the matrix is invertable
|
||||
*/
|
||||
pure fn is_invertible(&self) -> bool;
|
||||
fn is_invertible(&self) -> bool;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* A pointer to the first element of the matrix
|
||||
*/
|
||||
pure fn to_ptr(&self) -> *T;
|
||||
fn to_ptr(&self) -> *T;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 2 x 2 matrix
|
||||
*/
|
||||
pub trait Matrix2<T,V>: Matrix<T,V> {
|
||||
static pure fn new(c0r0: T, c0r1: T,
|
||||
static fn new(c0r0: T, c0r1: T,
|
||||
c1r0: T, c1r1: T) -> Self;
|
||||
|
||||
static pure fn from_cols(c0: V, c1: V) -> Self;
|
||||
static fn from_cols(c0: V, c1: V) -> Self;
|
||||
|
||||
static pure fn from_angle(radians: T) -> Self;
|
||||
static fn from_angle(radians: T) -> Self;
|
||||
|
||||
pure fn to_mat3(&self) -> Mat3<T>;
|
||||
fn to_mat3(&self) -> Mat3<T>;
|
||||
|
||||
pure fn to_mat4(&self) -> Mat4<T>;
|
||||
fn to_mat4(&self) -> Mat4<T>;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 3 x 3 matrix
|
||||
*/
|
||||
pub trait Matrix3<T,V>: Matrix<T,V> {
|
||||
static pure fn new(c0r0:T, c0r1:T, c0r2:T,
|
||||
static fn new(c0r0:T, c0r1:T, c0r2:T,
|
||||
c1r0:T, c1r1:T, c1r2:T,
|
||||
c2r0:T, c2r1:T, c2r2:T) -> Self;
|
||||
|
||||
static pure fn from_cols(c0: V, c1: V, c2: V) -> Self;
|
||||
static fn from_cols(c0: V, c1: V, c2: V) -> Self;
|
||||
|
||||
static pure fn from_angle_x(radians: T) -> Self;
|
||||
static fn from_angle_x(radians: T) -> Self;
|
||||
|
||||
static pure fn from_angle_y(radians: T) -> Self;
|
||||
static fn from_angle_y(radians: T) -> Self;
|
||||
|
||||
static pure fn from_angle_z(radians: T) -> Self;
|
||||
static fn from_angle_z(radians: T) -> Self;
|
||||
|
||||
static pure fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> Self;
|
||||
static fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> Self;
|
||||
|
||||
static pure fn from_angle_axis(radians: T, axis: &Vec3<T>) -> Self;
|
||||
static fn from_angle_axis(radians: T, axis: &Vec3<T>) -> Self;
|
||||
|
||||
static pure fn from_axes(x: V, y: V, z: V) -> Self;
|
||||
static fn from_axes(x: V, y: V, z: V) -> Self;
|
||||
|
||||
static pure fn look_at(dir: &Vec3<T>, up: &Vec3<T>) -> Self;
|
||||
static fn look_at(dir: &Vec3<T>, up: &Vec3<T>) -> Self;
|
||||
|
||||
pure fn to_mat4(&self) -> Mat4<T>;
|
||||
fn to_mat4(&self) -> Mat4<T>;
|
||||
|
||||
pure fn to_quat(&self) -> Quat<T>;
|
||||
fn to_quat(&self) -> Quat<T>;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 4 x 4 matrix
|
||||
*/
|
||||
pub trait Matrix4<T,V>: Matrix<T,V> {
|
||||
static pure fn new(c0r0: T, c0r1: T, c0r2: T, c0r3: T,
|
||||
static 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) -> Self;
|
||||
|
||||
static pure fn from_cols(c0: V, c1: V, c2: V, c3: V) -> Self;
|
||||
static fn from_cols(c0: V, c1: V, c2: V, c3: V) -> Self;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
100
src/mat2.rs
100
src/mat2.rs
|
@ -48,10 +48,10 @@ pub struct Mat2<T> { x: Vec2<T>, y: Vec2<T> }
|
|||
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec2<T>> for Mat2<T> {
|
||||
#[inline(always)]
|
||||
pure fn col(&self, i: uint) -> Vec2<T> { self[i] }
|
||||
fn col(&self, i: uint) -> Vec2<T> { self[i] }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn row(&self, i: uint) -> Vec2<T> {
|
||||
fn row(&self, i: uint) -> Vec2<T> {
|
||||
Vector2::new(self[0][i],
|
||||
self[1][i])
|
||||
}
|
||||
|
@ -73,7 +73,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn from_value(value: T) -> Mat2<T> {
|
||||
static fn from_value(value: T) -> Mat2<T> {
|
||||
Matrix2::new(value, zero(),
|
||||
zero(), value)
|
||||
}
|
||||
|
@ -90,7 +90,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Mat2<T> {
|
||||
static fn identity() -> Mat2<T> {
|
||||
Matrix2::new( one::<T>(), zero::<T>(),
|
||||
zero::<T>(), one::<T>())
|
||||
}
|
||||
|
@ -107,55 +107,55 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Mat2<T> {
|
||||
static fn zero() -> Mat2<T> {
|
||||
Matrix2::new(zero::<T>(), zero::<T>(),
|
||||
zero::<T>(), zero::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(&self, value: T) -> Mat2<T> {
|
||||
fn mul_t(&self, value: T) -> Mat2<T> {
|
||||
Matrix2::from_cols(self[0].mul_t(value),
|
||||
self[1].mul_t(value))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_v(&self, vec: &Vec2<T>) -> Vec2<T> {
|
||||
fn mul_v(&self, vec: &Vec2<T>) -> Vec2<T> {
|
||||
Vector2::new(self.row(0).dot(vec),
|
||||
self.row(1).dot(vec))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_m(&self, other: &Mat2<T>) -> Mat2<T> {
|
||||
fn add_m(&self, other: &Mat2<T>) -> Mat2<T> {
|
||||
Matrix2::from_cols(self[0].add_v(&other[0]),
|
||||
self[1].add_v(&other[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_m(&self, other: &Mat2<T>) -> Mat2<T> {
|
||||
fn sub_m(&self, other: &Mat2<T>) -> Mat2<T> {
|
||||
Matrix2::from_cols(self[0].sub_v(&other[0]),
|
||||
self[1].sub_v(&other[1]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_m(&self, other: &Mat2<T>) -> Mat2<T> {
|
||||
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)))
|
||||
}
|
||||
|
||||
pure fn dot(&self, other: &Mat2<T>) -> T {
|
||||
fn dot(&self, other: &Mat2<T>) -> T {
|
||||
other.transpose().mul_m(self).trace()
|
||||
}
|
||||
|
||||
pure fn determinant(&self) -> T {
|
||||
fn determinant(&self) -> T {
|
||||
self[0][0] * self[1][1] - self[1][0] * self[0][1]
|
||||
}
|
||||
|
||||
pure fn trace(&self) -> T {
|
||||
fn trace(&self) -> T {
|
||||
self[0][0] + self[1][1]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn inverse(&self) -> Option<Mat2<T>> {
|
||||
fn inverse(&self) -> Option<Mat2<T>> {
|
||||
let d = self.determinant();
|
||||
if d.fuzzy_eq(&zero()) {
|
||||
None
|
||||
|
@ -166,40 +166,40 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn transpose(&self) -> Mat2<T> {
|
||||
fn transpose(&self) -> Mat2<T> {
|
||||
Matrix2::new(self[0][0], self[1][0],
|
||||
self[0][1], self[1][1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_identity(&self) -> bool {
|
||||
fn is_identity(&self) -> bool {
|
||||
self.fuzzy_eq(&Matrix::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_diagonal(&self) -> bool {
|
||||
fn is_diagonal(&self) -> bool {
|
||||
self[0][1].fuzzy_eq(&zero()) &&
|
||||
self[1][0].fuzzy_eq(&zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_rotated(&self) -> bool {
|
||||
fn is_rotated(&self) -> bool {
|
||||
!self.fuzzy_eq(&Matrix::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_symmetric(&self) -> bool {
|
||||
fn is_symmetric(&self) -> bool {
|
||||
self[0][1].fuzzy_eq(&self[1][0]) &&
|
||||
self[1][0].fuzzy_eq(&self[0][1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_invertible(&self) -> bool {
|
||||
fn is_invertible(&self) -> bool {
|
||||
!self.determinant().fuzzy_eq(&zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
fn to_ptr(&self) -> *T {
|
||||
unsafe {
|
||||
transmute::<*Mat2<T>, *T>(
|
||||
to_unsafe_ptr(self)
|
||||
|
@ -296,7 +296,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn new(c0r0: T, c0r1: T,
|
||||
static 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))
|
||||
|
@ -320,13 +320,13 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn from_cols(c0: Vec2<T>,
|
||||
static fn from_cols(c0: Vec2<T>,
|
||||
c1: Vec2<T>) -> Mat2<T> {
|
||||
Mat2 { x: c0, y: c1 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn from_angle(radians: T) -> Mat2<T> {
|
||||
static fn from_angle(radians: T) -> Mat2<T> {
|
||||
let cos_theta = cos(radians);
|
||||
let sin_theta = sin(radians);
|
||||
|
||||
|
@ -348,7 +348,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn to_mat3(&self) -> Mat3<T> {
|
||||
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())
|
||||
|
@ -370,7 +370,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn to_mat4(&self) -> Mat4<T> {
|
||||
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(),
|
||||
|
@ -380,7 +380,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
|
||||
impl<T:Copy> Index<uint, Vec2<T>> for Mat2<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> Vec2<T> {
|
||||
fn index(&self, i: uint) -> Vec2<T> {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Mat2<T>, *Vec2<T>>(
|
||||
to_unsafe_ptr(self)), 2) |slice| { slice[i] }
|
||||
|
@ -390,19 +390,19 @@ impl<T:Copy> Index<uint, Vec2<T>> for Mat2<T> {
|
|||
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat2<T>> for Mat2<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Mat2<T> {
|
||||
fn neg(&self) -> Mat2<T> {
|
||||
Matrix2::from_cols(-self[0], -self[1])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Mat2<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Mat2<T>) -> bool {
|
||||
fn fuzzy_eq(&self, other: &Mat2<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq_eps(&self, other: &Mat2<T>, epsilon: &T) -> bool {
|
||||
fn fuzzy_eq_eps(&self, other: &Mat2<T>, epsilon: &T) -> bool {
|
||||
self[0].fuzzy_eq_eps(&other[0], epsilon) &&
|
||||
self[1].fuzzy_eq_eps(&other[1], epsilon)
|
||||
}
|
||||
|
@ -417,37 +417,37 @@ pub type dmat2 = Mat2<f64>; // a 2×2 double-precision floating-point matrix
|
|||
// Static method wrappers for GLSL-style types
|
||||
|
||||
impl mat2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c1r0: f32, c1r1: f32)
|
||||
#[inline(always)] static fn new(c0r0: f32, c0r1: f32, c1r0: f32, c1r1: f32)
|
||||
-> mat2 { Matrix2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec2, c1: vec2)
|
||||
#[inline(always)] static fn from_cols(c0: vec2, c1: vec2)
|
||||
-> mat2 { Matrix2::from_cols(c0, c1) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat2 { Matrix::from_value(v) }
|
||||
#[inline(always)] static fn from_value(v: f32) -> mat2 { Matrix::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> mat2 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat2 { Matrix::zero() }
|
||||
#[inline(always)] static fn identity() -> mat2 { Matrix::identity() }
|
||||
#[inline(always)] static fn zero() -> mat2 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn from_angle(radians: f32) -> mat2 { Matrix2::from_angle(radians) }
|
||||
#[inline(always)] static fn from_angle(radians: f32) -> mat2 { Matrix2::from_angle(radians) }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 2 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat2>() }
|
||||
#[inline(always)] static fn dim() -> uint { 2 }
|
||||
#[inline(always)] static fn rows() -> uint { 2 }
|
||||
#[inline(always)] static fn cols() -> uint { 2 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<mat2>() }
|
||||
}
|
||||
|
||||
impl dmat2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c1r0: f64, c1r1: f64)
|
||||
#[inline(always)] static fn new(c0r0: f64, c0r1: f64, c1r0: f64, c1r1: f64)
|
||||
-> dmat2 { Matrix2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec2, c1: dvec2)
|
||||
#[inline(always)] static fn from_cols(c0: dvec2, c1: dvec2)
|
||||
-> dmat2 { Matrix2::from_cols(c0, c1) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat2 { Matrix::from_value(v) }
|
||||
#[inline(always)] static fn from_value(v: f64) -> dmat2 { Matrix::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> dmat2 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat2 { Matrix::zero() }
|
||||
#[inline(always)] static fn identity() -> dmat2 { Matrix::identity() }
|
||||
#[inline(always)] static fn zero() -> dmat2 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn from_angle(radians: f64) -> dmat2 { Matrix2::from_angle(radians) }
|
||||
#[inline(always)] static fn from_angle(radians: f64) -> dmat2 { Matrix2::from_angle(radians) }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 2 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat2>() }
|
||||
#[inline(always)] static fn dim() -> uint { 2 }
|
||||
#[inline(always)] static fn rows() -> uint { 2 }
|
||||
#[inline(always)] static fn cols() -> uint { 2 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<dmat2>() }
|
||||
}
|
||||
|
|
122
src/mat3.rs
122
src/mat3.rs
|
@ -50,10 +50,10 @@ pub struct Mat3<T> { x: Vec3<T>, y: Vec3<T>, z: Vec3<T> }
|
|||
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec3<T>> for Mat3<T> {
|
||||
#[inline(always)]
|
||||
pure fn col(&self, i: uint) -> Vec3<T> { self[i] }
|
||||
fn col(&self, i: uint) -> Vec3<T> { self[i] }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn row(&self, i: uint) -> Vec3<T> {
|
||||
fn row(&self, i: uint) -> Vec3<T> {
|
||||
Vector3::new(self[0][i],
|
||||
self[1][i],
|
||||
self[2][i])
|
||||
|
@ -78,7 +78,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn from_value(value: T) -> Mat3<T> {
|
||||
static fn from_value(value: T) -> Mat3<T> {
|
||||
Matrix3::new(value, zero(), zero(),
|
||||
zero(), value, zero(),
|
||||
zero(), zero(), value)
|
||||
|
@ -98,7 +98,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Mat3<T> {
|
||||
static fn identity() -> Mat3<T> {
|
||||
Matrix3::new( one::<T>(), zero::<T>(), zero::<T>(),
|
||||
zero::<T>(), one::<T>(), zero::<T>(),
|
||||
zero::<T>(), zero::<T>(), one::<T>())
|
||||
|
@ -118,42 +118,42 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Mat3<T> {
|
||||
static fn zero() -> Mat3<T> {
|
||||
Matrix3::new(zero::<T>(), zero::<T>(), zero::<T>(),
|
||||
zero::<T>(), zero::<T>(), zero::<T>(),
|
||||
zero::<T>(), zero::<T>(), zero::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(&self, value: T) -> Mat3<T> {
|
||||
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))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_v(&self, vec: &Vec3<T>) -> Vec3<T> {
|
||||
fn mul_v(&self, vec: &Vec3<T>) -> Vec3<T> {
|
||||
Vector3::new(self.row(0).dot(vec),
|
||||
self.row(1).dot(vec),
|
||||
self.row(2).dot(vec))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_m(&self, other: &Mat3<T>) -> Mat3<T> {
|
||||
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]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_m(&self, other: &Mat3<T>) -> Mat3<T> {
|
||||
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]))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_m(&self, other: &Mat3<T>) -> Mat3<T> {
|
||||
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)),
|
||||
|
@ -167,20 +167,20 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
self.row(2).dot(&other.col(2)))
|
||||
}
|
||||
|
||||
pure fn dot(&self, other: &Mat3<T>) -> T {
|
||||
fn dot(&self, other: &Mat3<T>) -> T {
|
||||
other.transpose().mul_m(self).trace()
|
||||
}
|
||||
|
||||
pure fn determinant(&self) -> T {
|
||||
fn determinant(&self) -> T {
|
||||
self.col(0).dot(&self.col(1).cross(&self.col(2)))
|
||||
}
|
||||
|
||||
pure fn trace(&self) -> T {
|
||||
fn trace(&self) -> T {
|
||||
self[0][0] + self[1][1] + self[2][2]
|
||||
}
|
||||
|
||||
// #[inline(always)]
|
||||
pure fn inverse(&self) -> Option<Mat3<T>> {
|
||||
fn inverse(&self) -> Option<Mat3<T>> {
|
||||
let d = self.determinant();
|
||||
if d.fuzzy_eq(&zero()) {
|
||||
None
|
||||
|
@ -193,19 +193,19 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn transpose(&self) -> Mat3<T> {
|
||||
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])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_identity(&self) -> bool {
|
||||
fn is_identity(&self) -> bool {
|
||||
self.fuzzy_eq(&Matrix::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_diagonal(&self) -> bool {
|
||||
fn is_diagonal(&self) -> bool {
|
||||
self[0][1].fuzzy_eq(&zero()) &&
|
||||
self[0][2].fuzzy_eq(&zero()) &&
|
||||
|
||||
|
@ -217,12 +217,12 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_rotated(&self) -> bool {
|
||||
fn is_rotated(&self) -> bool {
|
||||
!self.fuzzy_eq(&Matrix::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_symmetric(&self) -> bool {
|
||||
fn is_symmetric(&self) -> bool {
|
||||
self[0][1].fuzzy_eq(&self[1][0]) &&
|
||||
self[0][2].fuzzy_eq(&self[2][0]) &&
|
||||
|
||||
|
@ -234,12 +234,12 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_invertible(&self) -> bool {
|
||||
fn is_invertible(&self) -> bool {
|
||||
!self.determinant().fuzzy_eq(&zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
fn to_ptr(&self) -> *T {
|
||||
unsafe {
|
||||
transmute::<*Mat3<T>, *T>(
|
||||
to_unsafe_ptr(self)
|
||||
|
@ -270,7 +270,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn new(c0r0:T, c0r1:T, c0r2:T,
|
||||
static 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),
|
||||
|
@ -299,7 +299,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn from_cols(c0: Vec3<T>,
|
||||
static fn from_cols(c0: Vec3<T>,
|
||||
c1: Vec3<T>,
|
||||
c2: Vec3<T>) -> Mat3<T> {
|
||||
Mat3 { x: c0, y: c1, z: c2 }
|
||||
|
@ -309,7 +309,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* Construct a matrix from an angular rotation around the `x` axis
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn from_angle_x(radians: T) -> Mat3<T> {
|
||||
static fn from_angle_x(radians: T) -> Mat3<T> {
|
||||
// http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
|
||||
let cos_theta = cos(radians);
|
||||
let sin_theta = sin(radians);
|
||||
|
@ -323,7 +323,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* Construct a matrix from an angular rotation around the `y` axis
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn from_angle_y(radians: T) -> Mat3<T> {
|
||||
static fn from_angle_y(radians: T) -> Mat3<T> {
|
||||
// http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
|
||||
let cos_theta = cos(radians);
|
||||
let sin_theta = sin(radians);
|
||||
|
@ -337,7 +337,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* Construct a matrix from an angular rotation around the `z` axis
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn from_angle_z(radians: T) -> Mat3<T> {
|
||||
static fn from_angle_z(radians: T) -> Mat3<T> {
|
||||
// http://en.wikipedia.org/wiki/Rotation_matrix#Basic_rotations
|
||||
let cos_theta = cos(radians);
|
||||
let sin_theta = sin(radians);
|
||||
|
@ -357,7 +357,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* * `theta_z` - the angular rotation around the `z` axis (roll)
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> Mat3<T> {
|
||||
static fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> Mat3<T> {
|
||||
// http://en.wikipedia.org/wiki/Rotation_matrix#General_rotations
|
||||
let cx = cos(radians_x);
|
||||
let sx = sin(radians_x);
|
||||
|
@ -375,7 +375,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* Construct a matrix from an axis and an angular rotation
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn from_angle_axis(radians: T, axis: &Vec3<T>) -> Mat3<T> {
|
||||
static fn from_angle_axis(radians: T, axis: &Vec3<T>) -> Mat3<T> {
|
||||
let c = cos(radians);
|
||||
let s = sin(radians);
|
||||
let _1_c = one::<T>() - c;
|
||||
|
@ -390,12 +390,12 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn from_axes(x: Vec3<T>, y: Vec3<T>, z: Vec3<T>) -> Mat3<T> {
|
||||
static fn from_axes(x: Vec3<T>, y: Vec3<T>, z: Vec3<T>) -> Mat3<T> {
|
||||
Matrix3::from_cols(x, y, z)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn look_at(dir: &Vec3<T>, up: &Vec3<T>) -> Mat3<T> {
|
||||
static fn look_at(dir: &Vec3<T>, up: &Vec3<T>) -> Mat3<T> {
|
||||
let dir_ = dir.normalize();
|
||||
let side = dir_.cross(&up.normalize());
|
||||
let up_ = side.cross(&dir_).normalize();
|
||||
|
@ -419,7 +419,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn to_mat4(&self) -> Mat4<T> {
|
||||
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(),
|
||||
|
@ -430,7 +430,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* Convert the matrix to a quaternion
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn to_quat(&self) -> Quat<T> {
|
||||
fn to_quat(&self) -> Quat<T> {
|
||||
// Implemented using a mix of ideas from jMonkeyEngine and Ken Shoemake's
|
||||
// paper on Quaternions: http://www.cs.ucr.edu/~vbz/resources/Quatut.pdf
|
||||
|
||||
|
@ -558,7 +558,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
|
||||
impl<T:Copy> Index<uint, Vec3<T>> for Mat3<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> Vec3<T> {
|
||||
fn index(&self, i: uint) -> Vec3<T> {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Mat3<T>, *Vec3<T>>(
|
||||
to_unsafe_ptr(self)), 3) |slice| { slice[i] }
|
||||
|
@ -568,19 +568,19 @@ impl<T:Copy> Index<uint, Vec3<T>> for Mat3<T> {
|
|||
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat3<T>> for Mat3<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Mat3<T> {
|
||||
fn neg(&self) -> Mat3<T> {
|
||||
Matrix3::from_cols(-self[0], -self[1], -self[2])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> FuzzyEq<T> for Mat3<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Mat3<T>) -> bool {
|
||||
fn fuzzy_eq(&self, other: &Mat3<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq_eps(&self, other: &Mat3<T>, epsilon: &T) -> bool {
|
||||
fn fuzzy_eq_eps(&self, other: &Mat3<T>, epsilon: &T) -> bool {
|
||||
self[0].fuzzy_eq_eps(&other[0], epsilon) &&
|
||||
self[1].fuzzy_eq_eps(&other[1], epsilon) &&
|
||||
self[2].fuzzy_eq_eps(&other[2], epsilon)
|
||||
|
@ -596,42 +596,42 @@ pub type dmat3 = Mat3<f64>; // a 3×3 double-precision floating-point matrix
|
|||
// Static method wrappers for GLSL-style types
|
||||
|
||||
impl mat3 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c1r0: f32, c1r1: f32, c1r2: f32, c2r0: f32, c2r1: f32, c2r2: f32)
|
||||
#[inline(always)] static fn new(c0r0: f32, c0r1: f32, c0r2: f32, c1r0: f32, c1r1: f32, c1r2: f32, c2r0: f32, c2r1: f32, c2r2: f32)
|
||||
-> mat3 { Matrix3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec3, c1: vec3, c2: vec3)
|
||||
#[inline(always)] static fn from_cols(c0: vec3, c1: vec3, c2: vec3)
|
||||
-> mat3 { Matrix3::from_cols(c0, c1, c2) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat3 { Matrix::from_value(v) }
|
||||
#[inline(always)] static fn from_value(v: f32) -> mat3 { Matrix::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> mat3 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat3 { Matrix::zero() }
|
||||
#[inline(always)] static fn identity() -> mat3 { Matrix::identity() }
|
||||
#[inline(always)] static fn zero() -> mat3 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn from_angle_x(radians: f32) -> mat3 { Matrix3::from_angle_x(radians) }
|
||||
#[inline(always)] static pure fn from_angle_y(radians: f32) -> mat3 { Matrix3::from_angle_y(radians) }
|
||||
#[inline(always)] static pure fn from_angle_z(radians: f32) -> mat3 { Matrix3::from_angle_z(radians) }
|
||||
#[inline(always)] static pure fn from_angle_xyz(radians_x: f32, radians_y: f32, radians_z: f32) -> mat3 { Matrix3::from_angle_xyz(radians_x, radians_y, radians_z) }
|
||||
#[inline(always)] static pure fn from_angle_axis(radians: f32, axis: &vec3) -> mat3 { Matrix3::from_angle_axis(radians, axis) }
|
||||
#[inline(always)] static pure fn from_axes(x: vec3, y: vec3, z: vec3) -> mat3 { Matrix3::from_axes(x, y, z) }
|
||||
#[inline(always)] static pure fn look_at(dir: &vec3, up: &vec3) -> mat3 { Matrix3::look_at(dir, up) }
|
||||
#[inline(always)] static fn from_angle_x(radians: f32) -> mat3 { Matrix3::from_angle_x(radians) }
|
||||
#[inline(always)] static fn from_angle_y(radians: f32) -> mat3 { Matrix3::from_angle_y(radians) }
|
||||
#[inline(always)] static fn from_angle_z(radians: f32) -> mat3 { Matrix3::from_angle_z(radians) }
|
||||
#[inline(always)] static fn from_angle_xyz(radians_x: f32, radians_y: f32, radians_z: f32) -> mat3 { Matrix3::from_angle_xyz(radians_x, radians_y, radians_z) }
|
||||
#[inline(always)] static fn from_angle_axis(radians: f32, axis: &vec3) -> mat3 { Matrix3::from_angle_axis(radians, axis) }
|
||||
#[inline(always)] static fn from_axes(x: vec3, y: vec3, z: vec3) -> mat3 { Matrix3::from_axes(x, y, z) }
|
||||
#[inline(always)] static fn look_at(dir: &vec3, up: &vec3) -> mat3 { Matrix3::look_at(dir, up) }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 3 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat3>() }
|
||||
#[inline(always)] static fn dim() -> uint { 3 }
|
||||
#[inline(always)] static fn rows() -> uint { 3 }
|
||||
#[inline(always)] static fn cols() -> uint { 3 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<mat3>() }
|
||||
}
|
||||
|
||||
|
||||
impl dmat3 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c1r0: f64, c1r1: f64, c1r2: f64, c2r0: f64, c2r1: f64, c2r2: f64)
|
||||
#[inline(always)] static fn new(c0r0: f64, c0r1: f64, c0r2: f64, c1r0: f64, c1r1: f64, c1r2: f64, c2r0: f64, c2r1: f64, c2r2: f64)
|
||||
-> dmat3 { Matrix3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec3, c1: dvec3, c2: dvec3)
|
||||
#[inline(always)] static fn from_cols(c0: dvec3, c1: dvec3, c2: dvec3)
|
||||
-> dmat3 { Matrix3::from_cols(c0, c1, c2) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat3 { Matrix::from_value(v) }
|
||||
#[inline(always)] static fn from_value(v: f64) -> dmat3 { Matrix::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> dmat3 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat3 { Matrix::zero() }
|
||||
#[inline(always)] static fn identity() -> dmat3 { Matrix::identity() }
|
||||
#[inline(always)] static fn zero() -> dmat3 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 3 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat3>() }
|
||||
#[inline(always)] static fn dim() -> uint { 3 }
|
||||
#[inline(always)] static fn rows() -> uint { 3 }
|
||||
#[inline(always)] static fn cols() -> uint { 3 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<dmat3>() }
|
||||
}
|
||||
|
|
90
src/mat4.rs
90
src/mat4.rs
|
@ -47,10 +47,10 @@ pub struct Mat4<T> { x: Vec4<T>, y: Vec4<T>, z: Vec4<T>, w: Vec4<T> }
|
|||
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Matrix<T, Vec4<T>> for Mat4<T> {
|
||||
#[inline(always)]
|
||||
pure fn col(&self, i: uint) -> Vec4<T> { self[i] }
|
||||
fn col(&self, i: uint) -> Vec4<T> { self[i] }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn row(&self, i: uint) -> Vec4<T> {
|
||||
fn row(&self, i: uint) -> Vec4<T> {
|
||||
Vector4::new(self[0][i],
|
||||
self[1][i],
|
||||
self[2][i],
|
||||
|
@ -78,7 +78,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn from_value(value: T) -> Mat4<T> {
|
||||
static fn from_value(value: T) -> Mat4<T> {
|
||||
Matrix4::new(value, zero(), zero(), zero(),
|
||||
zero(), value, zero(), zero(),
|
||||
zero(), zero(), value, zero(),
|
||||
|
@ -101,7 +101,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Mat4<T> {
|
||||
static 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>(),
|
||||
|
@ -124,7 +124,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Mat4<T> {
|
||||
static 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>(),
|
||||
|
@ -132,7 +132,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(&self, value: T) -> Mat4<T> {
|
||||
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),
|
||||
|
@ -140,7 +140,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_v(&self, vec: &Vec4<T>) -> Vec4<T> {
|
||||
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),
|
||||
|
@ -148,7 +148,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_m(&self, other: &Mat4<T>) -> Mat4<T> {
|
||||
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]),
|
||||
|
@ -156,7 +156,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_m(&self, other: &Mat4<T>) -> Mat4<T> {
|
||||
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]),
|
||||
|
@ -164,7 +164,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_m(&self, other: &Mat4<T>) -> Mat4<T> {
|
||||
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)),
|
||||
|
@ -187,11 +187,11 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
|
||||
}
|
||||
|
||||
pure fn dot(&self, other: &Mat4<T>) -> T {
|
||||
fn dot(&self, other: &Mat4<T>) -> T {
|
||||
other.transpose().mul_m(self).trace()
|
||||
}
|
||||
|
||||
pure fn determinant(&self) -> 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]);
|
||||
|
@ -211,11 +211,11 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
self[3][0] * m3.determinant()
|
||||
}
|
||||
|
||||
pure fn trace(&self) -> T {
|
||||
fn trace(&self) -> T {
|
||||
self[0][0] + self[1][1] + self[2][2] + self[3][3]
|
||||
}
|
||||
|
||||
pure fn inverse(&self) -> Option<Mat4<T>> {
|
||||
fn inverse(&self) -> Option<Mat4<T>> {
|
||||
let d = self.determinant();
|
||||
if d.fuzzy_eq(&zero()) {
|
||||
None
|
||||
|
@ -262,7 +262,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn transpose(&self) -> Mat4<T> {
|
||||
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],
|
||||
|
@ -270,12 +270,12 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_identity(&self) -> bool {
|
||||
fn is_identity(&self) -> bool {
|
||||
self.fuzzy_eq(&Matrix::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_diagonal(&self) -> bool {
|
||||
fn is_diagonal(&self) -> bool {
|
||||
self[0][1].fuzzy_eq(&zero()) &&
|
||||
self[0][2].fuzzy_eq(&zero()) &&
|
||||
self[0][3].fuzzy_eq(&zero()) &&
|
||||
|
@ -294,12 +294,12 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_rotated(&self) -> bool {
|
||||
fn is_rotated(&self) -> bool {
|
||||
!self.fuzzy_eq(&Matrix::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_symmetric(&self) -> bool {
|
||||
fn is_symmetric(&self) -> bool {
|
||||
self[0][1].fuzzy_eq(&self[1][0]) &&
|
||||
self[0][2].fuzzy_eq(&self[2][0]) &&
|
||||
self[0][3].fuzzy_eq(&self[3][0]) &&
|
||||
|
@ -318,12 +318,12 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_invertible(&self) -> bool {
|
||||
fn is_invertible(&self) -> bool {
|
||||
!self.determinant().fuzzy_eq(&zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
fn to_ptr(&self) -> *T {
|
||||
unsafe {
|
||||
transmute::<*Mat4<T>, *T>(
|
||||
to_unsafe_ptr(self)
|
||||
|
@ -357,7 +357,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn new(c0r0: T, c0r1: T, c0r2: T, c0r3: T,
|
||||
static 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) -> Mat4<T> {
|
||||
|
@ -391,7 +391,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* ~~~
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn from_cols(c0: Vec4<T>,
|
||||
static fn from_cols(c0: Vec4<T>,
|
||||
c1: Vec4<T>,
|
||||
c2: Vec4<T>,
|
||||
c3: Vec4<T>) -> Mat4<T> {
|
||||
|
@ -494,14 +494,14 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Mat4<T>> for Mat4<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Mat4<T> {
|
||||
fn neg(&self) -> Mat4<T> {
|
||||
Matrix4::from_cols(-self[0], -self[1], -self[2], -self[3])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy> Index<uint, Vec4<T>> for Mat4<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> Vec4<T> {
|
||||
fn index(&self, i: uint) -> Vec4<T> {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Mat4<T>, *Vec4<T>>(
|
||||
to_unsafe_ptr(self)), 4) |slice| { slice[i] }
|
||||
|
@ -511,12 +511,12 @@ impl<T:Copy> Index<uint, Vec4<T>> for Mat4<T> {
|
|||
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Mat4<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Mat4<T>) -> bool {
|
||||
fn fuzzy_eq(&self, other: &Mat4<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq_eps(&self, other: &Mat4<T>, epsilon: &T) -> bool {
|
||||
fn fuzzy_eq_eps(&self, other: &Mat4<T>, epsilon: &T) -> bool {
|
||||
self[0].fuzzy_eq_eps(&other[0], epsilon) &&
|
||||
self[1].fuzzy_eq_eps(&other[1], epsilon) &&
|
||||
self[2].fuzzy_eq_eps(&other[2], epsilon) &&
|
||||
|
@ -533,33 +533,33 @@ pub type dmat4 = Mat4<f64>; // a 4×4 double-precision floating-point matrix
|
|||
// Static method wrappers for GLSL-style types
|
||||
|
||||
impl mat4 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c0r3: f32, c1r0: f32, c1r1: f32, c1r2: f32, c1r3: f32, c2r0: f32, c2r1: f32, c2r2: f32, c2r3: f32, c3r0: f32, c3r1: f32, c3r2: f32, c3r3: f32)
|
||||
#[inline(always)] static fn new(c0r0: f32, c0r1: f32, c0r2: f32, c0r3: f32, c1r0: f32, c1r1: f32, c1r2: f32, c1r3: f32, c2r0: f32, c2r1: f32, c2r2: f32, c2r3: f32, c3r0: f32, c3r1: f32, c3r2: f32, c3r3: f32)
|
||||
-> mat4 { Matrix4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec4, c1: vec4, c2: vec4, c3: vec4)
|
||||
#[inline(always)] static fn from_cols(c0: vec4, c1: vec4, c2: vec4, c3: vec4)
|
||||
-> mat4 { Matrix4::from_cols(c0, c1, c2, c3) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat4 { Matrix::from_value(v) }
|
||||
#[inline(always)] static fn from_value(v: f32) -> mat4 { Matrix::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> mat4 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat4 { Matrix::zero() }
|
||||
#[inline(always)] static fn identity() -> mat4 { Matrix::identity() }
|
||||
#[inline(always)] static fn zero() -> mat4 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 4 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat4>() }
|
||||
#[inline(always)] static fn dim() -> uint { 4 }
|
||||
#[inline(always)] static fn rows() -> uint { 4 }
|
||||
#[inline(always)] static fn cols() -> uint { 4 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<mat4>() }
|
||||
}
|
||||
|
||||
impl dmat4 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c0r3: f64, c1r0: f64, c1r1: f64, c1r2: f64, c1r3: f64, c2r0: f64, c2r1: f64, c2r2: f64, c2r3: f64, c3r0: f64, c3r1: f64, c3r2: f64, c3r3: f64)
|
||||
#[inline(always)] static fn new(c0r0: f64, c0r1: f64, c0r2: f64, c0r3: f64, c1r0: f64, c1r1: f64, c1r2: f64, c1r3: f64, c2r0: f64, c2r1: f64, c2r2: f64, c2r3: f64, c3r0: f64, c3r1: f64, c3r2: f64, c3r3: f64)
|
||||
-> dmat4 { Matrix4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec4, c1: dvec4, c2: dvec4, c3: dvec4)
|
||||
#[inline(always)] static fn from_cols(c0: dvec4, c1: dvec4, c2: dvec4, c3: dvec4)
|
||||
-> dmat4 { Matrix4::from_cols(c0, c1, c2, c3) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat4 { Matrix::from_value(v) }
|
||||
#[inline(always)] static fn from_value(v: f64) -> dmat4 { Matrix::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn identity() -> dmat4 { Matrix::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat4 { Matrix::zero() }
|
||||
#[inline(always)] static fn identity() -> dmat4 { Matrix::identity() }
|
||||
#[inline(always)] static fn zero() -> dmat4 { Matrix::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn rows() -> uint { 4 }
|
||||
#[inline(always)] static pure fn cols() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat4>() }
|
||||
#[inline(always)] static fn dim() -> uint { 4 }
|
||||
#[inline(always)] static fn rows() -> uint { 4 }
|
||||
#[inline(always)] static fn cols() -> uint { 4 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<dmat4>() }
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use mat::{Mat4, Matrix4};
|
|||
* can be found [here](http://www.opengl.org/wiki/GluPerspective_code).
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub pure fn perspective<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>(fovy: T, aspectRatio: T, near: T, far: T) -> Mat4<T> {
|
||||
pub fn perspective<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>(fovy: T, aspectRatio: T, near: T, far: T) -> Mat4<T> {
|
||||
let ymax = near * tan(radians(fovy));
|
||||
let xmax = ymax * aspectRatio;
|
||||
|
||||
|
@ -26,7 +26,7 @@ pub pure fn perspective<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<
|
|||
* (http://www.opengl.org/sdk/docs/man2/xhtml/glFrustum.xml) function.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pub pure fn frustum<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> Mat4<T> {
|
||||
pub fn frustum<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>>(left: T, right: T, bottom: T, top: T, near: T, far: T) -> Mat4<T> {
|
||||
let _0: T = Number::from(0);
|
||||
let _1: T = Number::from(1);
|
||||
let _2: T = Number::from(2);
|
||||
|
|
108
src/quat.rs
108
src/quat.rs
|
@ -61,7 +61,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* * `zk` - the third imaginary component
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn new(w: T, xi: T, yj: T, zk: T) -> Quat<T> {
|
||||
static fn new(w: T, xi: T, yj: T, zk: T) -> Quat<T> {
|
||||
Quat::from_sv(w, Vector3::new(xi, yj, zk))
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* * `v` - a vector containing the three imaginary components
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn from_sv(s: T, v: Vec3<T>) -> Quat<T> {
|
||||
static fn from_sv(s: T, v: Vec3<T>) -> Quat<T> {
|
||||
Quat { s: s, v: v }
|
||||
}
|
||||
|
||||
|
@ -84,7 +84,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The multiplicative identity, ie: `q = 1 + 0i + 0j + 0i`
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Quat<T> {
|
||||
static fn identity() -> Quat<T> {
|
||||
Quat::new(one(), zero(), zero(), zero())
|
||||
}
|
||||
|
||||
|
@ -94,30 +94,30 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The additive identity, ie: `q = 0 + 0i + 0j + 0i`
|
||||
*/
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Quat<T> {
|
||||
static fn zero() -> Quat<T> {
|
||||
Quat::new(zero(), zero(), zero(), zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn from_angle_x(radians: T) -> Quat<T> {
|
||||
static fn from_angle_x(radians: T) -> Quat<T> {
|
||||
let _2 = Number::from(2);
|
||||
Quat::new(cos(radians / _2), sin(radians), zero(), zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn from_angle_y(radians: T) -> Quat<T> {
|
||||
static fn from_angle_y(radians: T) -> Quat<T> {
|
||||
let _2 = Number::from(2);
|
||||
Quat::new(cos(radians / _2), zero(), sin(radians), zero())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn from_angle_z(radians: T) -> Quat<T> {
|
||||
static fn from_angle_z(radians: T) -> Quat<T> {
|
||||
let _2 = Number::from(2);
|
||||
Quat::new(cos(radians / _2), zero(), zero(), sin(radians))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> Quat<T> {
|
||||
static fn from_angle_xyz(radians_x: T, radians_y: T, radians_z: T) -> Quat<T> {
|
||||
// http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles#Conversion
|
||||
let _2 = Number::from(2);
|
||||
let xdiv2 = radians_x / _2;
|
||||
|
@ -130,22 +130,22 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn from_angle_axis(radians: T, axis: &Vec3<T>) -> Quat<T> {
|
||||
static fn from_angle_axis(radians: T, axis: &Vec3<T>) -> Quat<T> {
|
||||
let half = radians / Number::from(2);
|
||||
Quat::from_sv(cos(half), axis.mul_t(sin(half)))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn from_axes(x: Vec3<T>, y: Vec3<T>, z: Vec3<T>) -> Quat<T> {
|
||||
static 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()
|
||||
}
|
||||
|
||||
pure fn get_angle_axis(&self) -> (T, Vec3<T>) {
|
||||
fn get_angle_axis(&self) -> (T, Vec3<T>) {
|
||||
fail!(~"Not yet implemented.")
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn look_at(dir: &Vec3<T>, up: &Vec3<T>) -> Quat<T> {
|
||||
static fn look_at(dir: &Vec3<T>, up: &Vec3<T>) -> Quat<T> {
|
||||
let m: Mat3<T> = Matrix3::look_at(dir, up); m.to_quat()
|
||||
}
|
||||
|
||||
|
@ -155,7 +155,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The result of multiplying the quaternion a scalar
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn mul_t(&self, value: T) -> Quat<T> {
|
||||
fn mul_t(&self, value: T) -> Quat<T> {
|
||||
Quat::new(self[0] * value,
|
||||
self[1] * value,
|
||||
self[2] * value,
|
||||
|
@ -168,7 +168,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The result of dividing the quaternion a scalar
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn div_t(&self, value: T) -> Quat<T> {
|
||||
fn div_t(&self, value: T) -> Quat<T> {
|
||||
Quat::new(self[0] / value,
|
||||
self[1] / value,
|
||||
self[2] / value,
|
||||
|
@ -181,7 +181,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The result of multiplying the quaternion by a vector
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn mul_v(&self, vec: &Vec3<T>) -> Vec3<T> {
|
||||
fn mul_v(&self, vec: &Vec3<T>) -> Vec3<T> {
|
||||
let tmp = self.v.cross(vec).add_v(&vec.mul_t(self.s));
|
||||
self.v.cross(&tmp).mul_t(Number::from(2)).add_v(vec)
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The sum of this quaternion and `other`
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn add_q(&self, other: &Quat<T>) -> Quat<T> {
|
||||
fn add_q(&self, other: &Quat<T>) -> Quat<T> {
|
||||
Quat::new(self[0] + other[0],
|
||||
self[1] + other[1],
|
||||
self[2] + other[2],
|
||||
|
@ -205,7 +205,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The sum of this quaternion and `other`
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn sub_q(&self, other: &Quat<T>) -> Quat<T> {
|
||||
fn sub_q(&self, other: &Quat<T>) -> Quat<T> {
|
||||
Quat::new(self[0] - other[0],
|
||||
self[1] - other[1],
|
||||
self[2] - other[2],
|
||||
|
@ -218,7 +218,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The the result of multipliplying the quaternion by `other`
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn mul_q(&self, other: &Quat<T>) -> Quat<T> {
|
||||
fn mul_q(&self, other: &Quat<T>) -> Quat<T> {
|
||||
Quat::new(self.s * other.s - self.v.x * other.v.x - self.v.y * other.v.y - self.v.z * other.v.z,
|
||||
self.s * other.v.x + self.v.x * other.s + self.v.y * other.v.z - self.v.z * other.v.y,
|
||||
self.s * other.v.y + self.v.y * other.s + self.v.z * other.v.x - self.v.x * other.v.z,
|
||||
|
@ -231,7 +231,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The dot product of the quaternion and `other`
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn dot(&self, other: &Quat<T>) -> T {
|
||||
fn dot(&self, other: &Quat<T>) -> T {
|
||||
self.s * other.s + self.v.dot(&other.v)
|
||||
}
|
||||
|
||||
|
@ -241,7 +241,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The conjugate of the quaternion
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn conjugate(&self) -> Quat<T> {
|
||||
fn conjugate(&self) -> Quat<T> {
|
||||
Quat::from_sv(self.s, -self.v)
|
||||
}
|
||||
|
||||
|
@ -251,7 +251,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The multiplicative inverse of the quaternion
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn inverse(&self) -> Quat<T> {
|
||||
fn inverse(&self) -> Quat<T> {
|
||||
self.conjugate().div_t(self.magnitude2())
|
||||
}
|
||||
|
||||
|
@ -263,7 +263,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* calculated.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn magnitude2(&self) -> T {
|
||||
fn magnitude2(&self) -> T {
|
||||
self.s * self.s + self.v.length2()
|
||||
}
|
||||
|
||||
|
@ -279,7 +279,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* it is advisable to use the `magnitude2` method instead.
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn magnitude(&self) -> T {
|
||||
fn magnitude(&self) -> T {
|
||||
self.magnitude2().sqrt()
|
||||
}
|
||||
|
||||
|
@ -289,7 +289,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The normalized quaternion
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn normalize(&self) -> Quat<T> {
|
||||
fn normalize(&self) -> Quat<T> {
|
||||
self.mul_t(one::<T>()/self.magnitude())
|
||||
}
|
||||
|
||||
|
@ -301,7 +301,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* The intoperlated quaternion
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn nlerp(&self, other: &Quat<T>, amount: T) -> Quat<T> {
|
||||
fn nlerp(&self, other: &Quat<T>, amount: T) -> Quat<T> {
|
||||
self.mul_t(one::<T>() - amount).add_q(&other.mul_t(amount)).normalize()
|
||||
}
|
||||
|
||||
|
@ -327,7 +327,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* (http://www.arcsynthesis.org/gltut/Positioning/Tut08%20Interpolation.html)
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn slerp(&self, other: &Quat<T>, amount: T) -> Quat<T> {
|
||||
fn slerp(&self, other: &Quat<T>, amount: T) -> Quat<T> {
|
||||
let dot = self.dot(other);
|
||||
|
||||
let dot_threshold = Number::from(0.9995);
|
||||
|
@ -353,7 +353,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* A pointer to the first component of the quaternion
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
fn to_ptr(&self) -> *T {
|
||||
unsafe {
|
||||
transmute::<*Quat<T>, *T>(
|
||||
to_unsafe_ptr(self)
|
||||
|
@ -365,7 +365,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
* Convert the quaternion to a 3 x 3 rotation matrix
|
||||
*/
|
||||
#[inline(always)]
|
||||
pure fn to_mat3(&self) -> Mat3<T> {
|
||||
fn to_mat3(&self) -> Mat3<T> {
|
||||
let x2 = self.v.x + self.v.x;
|
||||
let y2 = self.v.y + self.v.y;
|
||||
let z2 = self.v.z + self.v.z;
|
||||
|
@ -392,7 +392,7 @@ impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + N
|
|||
|
||||
impl<T:Copy> Index<uint, T> for Quat<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> T {
|
||||
fn index(&self, i: uint) -> T {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Quat<T>, *T>(
|
||||
to_unsafe_ptr(self)), 4) |slice| { slice[i] }
|
||||
|
@ -402,19 +402,19 @@ impl<T:Copy> Index<uint, T> for Quat<T> {
|
|||
|
||||
impl<T:Copy + Float + FuzzyEq<T> + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Quat<T>> for Quat<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Quat<T> {
|
||||
fn neg(&self) -> Quat<T> {
|
||||
Quat::new(-self[0], -self[1], -self[2], -self[3])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Quat<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Quat<T>) -> bool {
|
||||
fn fuzzy_eq(&self, other: &Quat<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq_eps(&self, other: &Quat<T>, epsilon: &T) -> bool {
|
||||
fn fuzzy_eq_eps(&self, other: &Quat<T>, epsilon: &T) -> bool {
|
||||
self[0].fuzzy_eq_eps(&other[0], epsilon) &&
|
||||
self[1].fuzzy_eq_eps(&other[1], epsilon) &&
|
||||
self[2].fuzzy_eq_eps(&other[2], epsilon) &&
|
||||
|
@ -431,33 +431,33 @@ pub type dquat = Quat<f64>; /// a double-precision floating-point qu
|
|||
// Static method wrappers for GLSL-style types
|
||||
|
||||
impl quat {
|
||||
#[inline(always)] static pure fn new(w: f32, xi: f32, yj: f32, zk: f32) -> quat { Quat::new(w, xi, yj, zk) }
|
||||
#[inline(always)] static pure fn from_sv(s: f32, v: vec3) -> quat { Quat::from_sv(s, v) }
|
||||
#[inline(always)] static pure fn identity() -> quat { Quat::identity() }
|
||||
#[inline(always)] static pure fn zero() -> quat { Quat::zero() }
|
||||
#[inline(always)] static fn new(w: f32, xi: f32, yj: f32, zk: f32) -> quat { Quat::new(w, xi, yj, zk) }
|
||||
#[inline(always)] static fn from_sv(s: f32, v: vec3) -> quat { Quat::from_sv(s, v) }
|
||||
#[inline(always)] static fn identity() -> quat { Quat::identity() }
|
||||
#[inline(always)] static fn zero() -> quat { Quat::zero() }
|
||||
|
||||
#[inline(always)] static pure fn from_angle_x(radians: f32) -> quat { Quat::from_angle_x(radians) }
|
||||
#[inline(always)] static pure fn from_angle_y(radians: f32) -> quat { Quat::from_angle_y(radians) }
|
||||
#[inline(always)] static pure fn from_angle_z(radians: f32) -> quat { Quat::from_angle_z(radians) }
|
||||
#[inline(always)] static pure fn from_angle_xyz(radians_x: f32, radians_y: f32, radians_z: f32)
|
||||
#[inline(always)] static fn from_angle_x(radians: f32) -> quat { Quat::from_angle_x(radians) }
|
||||
#[inline(always)] static fn from_angle_y(radians: f32) -> quat { Quat::from_angle_y(radians) }
|
||||
#[inline(always)] static fn from_angle_z(radians: f32) -> quat { Quat::from_angle_z(radians) }
|
||||
#[inline(always)] static fn from_angle_xyz(radians_x: f32, radians_y: f32, radians_z: f32)
|
||||
-> quat { Quat::from_angle_xyz(radians_x, radians_y, radians_z) }
|
||||
#[inline(always)] static pure fn from_angle_axis(radians: f32, axis: &vec3) -> quat { Quat::from_angle_axis(radians, axis) }
|
||||
#[inline(always)] static pure fn from_axes(x: vec3, y: vec3, z: vec3) -> quat { Quat::from_axes(x, y, z) }
|
||||
#[inline(always)] static pure fn look_at(dir: &vec3, up: &vec3) -> quat { Quat::look_at(dir, up) }
|
||||
#[inline(always)] static fn from_angle_axis(radians: f32, axis: &vec3) -> quat { Quat::from_angle_axis(radians, axis) }
|
||||
#[inline(always)] static fn from_axes(x: vec3, y: vec3, z: vec3) -> quat { Quat::from_axes(x, y, z) }
|
||||
#[inline(always)] static fn look_at(dir: &vec3, up: &vec3) -> quat { Quat::look_at(dir, up) }
|
||||
}
|
||||
|
||||
impl dquat {
|
||||
#[inline(always)] static pure fn new(w: f64, xi: f64, yj: f64, zk: f64) -> dquat { Quat::new(w, xi, yj, zk) }
|
||||
#[inline(always)] static pure fn from_sv(s: f64, v: dvec3) -> dquat { Quat::from_sv(s, v) }
|
||||
#[inline(always)] static pure fn identity() -> dquat { Quat::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dquat { Quat::zero() }
|
||||
#[inline(always)] static fn new(w: f64, xi: f64, yj: f64, zk: f64) -> dquat { Quat::new(w, xi, yj, zk) }
|
||||
#[inline(always)] static fn from_sv(s: f64, v: dvec3) -> dquat { Quat::from_sv(s, v) }
|
||||
#[inline(always)] static fn identity() -> dquat { Quat::identity() }
|
||||
#[inline(always)] static fn zero() -> dquat { Quat::zero() }
|
||||
|
||||
#[inline(always)] static pure fn from_angle_x(radians: f64) -> dquat { Quat::from_angle_x(radians) }
|
||||
#[inline(always)] static pure fn from_angle_y(radians: f64) -> dquat { Quat::from_angle_y(radians) }
|
||||
#[inline(always)] static pure fn from_angle_z(radians: f64) -> dquat { Quat::from_angle_z(radians) }
|
||||
#[inline(always)] static pure fn from_angle_xyz(radians_x: f64, radians_y: f64, radians_z: f64)
|
||||
#[inline(always)] static fn from_angle_x(radians: f64) -> dquat { Quat::from_angle_x(radians) }
|
||||
#[inline(always)] static fn from_angle_y(radians: f64) -> dquat { Quat::from_angle_y(radians) }
|
||||
#[inline(always)] static fn from_angle_z(radians: f64) -> dquat { Quat::from_angle_z(radians) }
|
||||
#[inline(always)] static fn from_angle_xyz(radians_x: f64, radians_y: f64, radians_z: f64)
|
||||
-> dquat { Quat::from_angle_xyz(radians_x, radians_y, radians_z) }
|
||||
#[inline(always)] static pure fn from_angle_axis(radians: f64, axis: &dvec3) -> dquat { Quat::from_angle_axis(radians, axis) }
|
||||
#[inline(always)] static pure fn from_axes(x: dvec3, y: dvec3, z: dvec3) -> dquat { Quat::from_axes(x, y, z) }
|
||||
#[inline(always)] static pure fn look_at(dir: &dvec3, up: &dvec3) -> dquat { Quat::look_at(dir, up) }
|
||||
#[inline(always)] static fn from_angle_axis(radians: f64, axis: &dvec3) -> dquat { Quat::from_angle_axis(radians, axis) }
|
||||
#[inline(always)] static fn from_axes(x: dvec3, y: dvec3, z: dvec3) -> dquat { Quat::from_axes(x, y, z) }
|
||||
#[inline(always)] static fn look_at(dir: &dvec3, up: &dvec3) -> dquat { Quat::look_at(dir, up) }
|
||||
}
|
||||
|
|
|
@ -79,14 +79,14 @@ pub struct Vec4 { x: float, y: float, z: float, w: float }
|
|||
|
||||
mod Vec4 {
|
||||
#[inline(always)]
|
||||
pub pure fn new(x: float, y: float, z: float, w: float) -> Vec4 {
|
||||
pub fn new(x: float, y: float, z: float, w: float) -> Vec4 {
|
||||
Vec4 { x: move x, y: move y, z: move z, w: move w }
|
||||
}
|
||||
}
|
||||
|
||||
impl Vec4 {
|
||||
#[inline(always)]
|
||||
pure fn dot(other: &Vec4) -> float {
|
||||
fn dot(other: &Vec4) -> float {
|
||||
self[0] * other[0] +
|
||||
self[1] * other[1] +
|
||||
self[2] * other[2] +
|
||||
|
@ -96,7 +96,7 @@ impl Vec4 {
|
|||
|
||||
pub impl Vec4: Index<uint, float> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> float {
|
||||
fn index(i: uint) -> float {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Vec4, *float>(
|
||||
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
|
||||
|
@ -106,7 +106,7 @@ pub impl Vec4: Index<uint, float> {
|
|||
|
||||
pub impl Vec4: Eq {
|
||||
#[inline(always)]
|
||||
pure fn eq(other: &Vec4) -> bool {
|
||||
fn eq(other: &Vec4) -> bool {
|
||||
self[0] == other [0] &&
|
||||
self[1] == other [1] &&
|
||||
self[2] == other [2] &&
|
||||
|
@ -114,7 +114,7 @@ pub impl Vec4: Eq {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn ne(other: &Vec4) -> bool {
|
||||
fn ne(other: &Vec4) -> bool {
|
||||
!(self == *other)
|
||||
}
|
||||
}
|
||||
|
@ -125,7 +125,7 @@ pub struct Mat4 { x: Vec4, y: Vec4, z: Vec4, w: Vec4 }
|
|||
|
||||
mod Mat4 {
|
||||
#[inline(always)]
|
||||
pub pure fn new(c0r0: float, c0r1: float, c0r2: float, c0r3: float,
|
||||
pub fn new(c0r0: float, c0r1: float, c0r2: float, c0r3: float,
|
||||
c1r0: float, c1r1: float, c1r2: float, c1r3: float,
|
||||
c2r0: float, c2r1: float, c2r2: float, c2r3: float,
|
||||
c3r0: float, c3r1: float, c3r2: float, c3r3: float) -> Mat4 {
|
||||
|
@ -136,7 +136,7 @@ mod Mat4 {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn from_cols(c0: Vec4, c1: Vec4, c2: Vec4, c3: Vec4) -> Mat4 {
|
||||
pub fn from_cols(c0: Vec4, c1: Vec4, c2: Vec4, c3: Vec4) -> Mat4 {
|
||||
Mat4 { x: move c0,
|
||||
y: move c1,
|
||||
z: move c2,
|
||||
|
@ -146,17 +146,17 @@ mod Mat4 {
|
|||
|
||||
impl Mat4 {
|
||||
#[inline(always)]
|
||||
pure fn col(i: uint) -> Vec4 { self[i] }
|
||||
fn col(i: uint) -> Vec4 { self[i] }
|
||||
|
||||
#[inline(always)]
|
||||
pure fn row(i: uint) -> Vec4 {
|
||||
fn row(i: uint) -> Vec4 {
|
||||
Vec4::new(self[0][i],
|
||||
self[1][i],
|
||||
self[2][i],
|
||||
self[3][i])
|
||||
}
|
||||
|
||||
pure fn mul_matrix_expanded(other: &Mat4) -> Mat4 {
|
||||
fn mul_matrix_expanded(other: &Mat4) -> Mat4 {
|
||||
Mat4::new(self[0][0] * other[0][0] + self[1][0] * other[0][1] + self[2][0] * other[0][2] + self[3][0] * other[0][3],
|
||||
self[0][1] * other[0][0] + self[1][1] * other[0][1] + self[2][1] * other[0][2] + self[3][1] * other[0][3],
|
||||
self[0][2] * other[0][0] + self[1][2] * other[0][1] + self[2][2] * other[0][2] + self[3][2] * other[0][3],
|
||||
|
@ -178,7 +178,7 @@ impl Mat4 {
|
|||
self[0][3] * other[3][0] + self[1][3] * other[3][1] + self[2][3] * other[3][2] + self[3][3] * other[3][3])
|
||||
}
|
||||
|
||||
pure fn mul_matrix_dot_product(other: &Mat4) -> Mat4 {
|
||||
fn mul_matrix_dot_product(other: &Mat4) -> Mat4 {
|
||||
Mat4::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(2)), self.row(1).dot(&other.col(2)), self.row(2).dot(&other.col(2)), self.row(3).dot(&other.col(2)),
|
||||
|
@ -188,7 +188,7 @@ impl Mat4 {
|
|||
|
||||
pub impl Mat4: Index<uint, Vec4> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> Vec4 {
|
||||
fn index(i: uint) -> Vec4 {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Mat4, *Vec4>(
|
||||
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
|
||||
|
@ -198,7 +198,7 @@ pub impl Mat4: Index<uint, Vec4> {
|
|||
|
||||
pub impl Mat4: Eq {
|
||||
#[inline(always)]
|
||||
pure fn eq(other: &Mat4) -> bool {
|
||||
fn eq(other: &Mat4) -> bool {
|
||||
self[0] == other [0] &&
|
||||
self[1] == other [1] &&
|
||||
self[2] == other [2] &&
|
||||
|
@ -206,7 +206,7 @@ pub impl Mat4: Eq {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn ne(other: &Mat4) -> bool {
|
||||
fn ne(other: &Mat4) -> bool {
|
||||
!(self == *other)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ pub struct VecMatch { x: float, y: float, z: float, w: float }
|
|||
|
||||
pub impl VecMatch: Index<uint, float> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> float {
|
||||
fn index(i: uint) -> float {
|
||||
match i {
|
||||
0 => self.x,
|
||||
1 => self.y,
|
||||
|
@ -30,7 +30,7 @@ pub struct VecReinterpret { x: float, y: float, z: float, w: float }
|
|||
|
||||
pub impl VecReinterpret: Index<uint, float> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> float unsafe {
|
||||
fn index(i: uint) -> float unsafe {
|
||||
(reinterpret_cast::<VecReinterpret, [float * 4]>(&self))[i]
|
||||
}
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ pub struct VecTransmute { x: float, y: float, z: float, w: float }
|
|||
|
||||
pub impl VecTransmute: Index<uint, float> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> float unsafe {
|
||||
fn index(i: uint) -> float unsafe {
|
||||
(transmute::<VecTransmute, [float * 4]>(self))[i]
|
||||
}
|
||||
}
|
||||
|
@ -48,7 +48,7 @@ pub struct VecBufSlice { x: float, y: float, z: float, w: float }
|
|||
|
||||
pub impl VecBufSlice: Index<uint, float> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> float unsafe {
|
||||
fn index(i: uint) -> float unsafe {
|
||||
do vec::raw::buf_as_slice(
|
||||
transmute::<*VecBufSlice, *float>(
|
||||
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
|
||||
|
|
|
@ -18,14 +18,14 @@ pub struct Vec4<T> { x: T, y: T, z: T, w: T }
|
|||
|
||||
pub mod Vec4 {
|
||||
#[inline(always)]
|
||||
pub pure fn new<T>(x: T, y: T, z: T, w: T) -> Vec4<T> {
|
||||
pub fn new<T>(x: T, y: T, z: T, w: T) -> Vec4<T> {
|
||||
Vec4 { x: move x, y: move y, z: move z, w: move w }
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num> Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> T {
|
||||
fn index(i: uint) -> T {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Vec4<T>, *T>(
|
||||
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
|
||||
|
@ -35,7 +35,7 @@ pub impl<T:Copy Num> Vec4<T> {
|
|||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[inline(always)]
|
||||
pure fn map(f: fn&(a: &T) -> T) -> Vec4<T> {
|
||||
fn map(f: fn&(a: &T) -> T) -> Vec4<T> {
|
||||
Vec4::new(f(&self[0]),
|
||||
f(&self[1]),
|
||||
f(&self[2]),
|
||||
|
@ -43,24 +43,24 @@ pub impl<T:Copy Num> Vec4<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn map2(other: &Vec4<T>, f: fn&(a: &T, b: &T) -> T) -> Vec4<T> {
|
||||
fn map2(other: &Vec4<T>, f: fn&(a: &T, b: &T) -> T) -> Vec4<T> {
|
||||
Vec4::new(f(&self[0], &other[0]),
|
||||
f(&self[1], &other[1]),
|
||||
f(&self[2], &other[2]),
|
||||
f(&self[3], &other[3]))
|
||||
}
|
||||
|
||||
pure fn foldl<U: Copy>(z: U, p: &fn(t: T, u: &U) -> U) -> U {
|
||||
fn foldl<U: Copy>(z: U, p: &fn(t: T, u: &U) -> U) -> U {
|
||||
p(self[3], &p(self[2], &p(self[1], &p(self[0], &z))))
|
||||
}
|
||||
pure fn foldr<U: Copy>(z: U, p: &fn(t: &T, u: U) -> U) -> U {
|
||||
fn foldr<U: Copy>(z: U, p: &fn(t: &T, u: U) -> U) -> U {
|
||||
p(&self[0], p(&self[1], p(&self[2], p(&self[3], z))))
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(value: T) -> Vec4<T> {
|
||||
fn mul_t(value: T) -> Vec4<T> {
|
||||
Vec4::new(self[0] * value,
|
||||
self[1] * value,
|
||||
self[2] * value,
|
||||
|
@ -68,12 +68,12 @@ pub impl<T:Copy Num> Vec4<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t_map(value: T) -> Vec4<T> {
|
||||
fn mul_t_map(value: T) -> Vec4<T> {
|
||||
do self.map |a| { a * value }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_v(other: &Vec4<T>) -> Vec4<T> {
|
||||
fn add_v(other: &Vec4<T>) -> Vec4<T> {
|
||||
Vec4::new(self[0] + other[0],
|
||||
self[1] + other[1],
|
||||
self[2] + other[2],
|
||||
|
@ -81,12 +81,12 @@ pub impl<T:Copy Num> Vec4<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_v_map2(other: &Vec4<T>) -> Vec4<T> {
|
||||
fn add_v_map2(other: &Vec4<T>) -> Vec4<T> {
|
||||
do self.map2(other) |a, b| { a + *b }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn dot(other: &Vec4<T>) -> T {
|
||||
fn dot(other: &Vec4<T>) -> T {
|
||||
self[0] * other[0] +
|
||||
self[1] * other[1] +
|
||||
self[2] * other[2] +
|
||||
|
@ -94,7 +94,7 @@ pub impl<T:Copy Num> Vec4<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn dot_foldl(other: &Vec4<T>) -> T {
|
||||
fn dot_foldl(other: &Vec4<T>) -> T {
|
||||
self.map2(other, |a, b| { a * *b })
|
||||
.foldl(from_int(0), |t, u| { t + *u })
|
||||
}
|
||||
|
@ -102,7 +102,7 @@ pub impl<T:Copy Num> Vec4<T> {
|
|||
|
||||
pub impl<T:Copy Num Eq> Vec4<T>: Eq {
|
||||
#[inline(always)]
|
||||
pure fn eq(other: &Vec4<T>) -> bool {
|
||||
fn eq(other: &Vec4<T>) -> bool {
|
||||
self[0] == other[0] &&
|
||||
self[1] == other[1] &&
|
||||
self[2] == other[2] &&
|
||||
|
@ -110,7 +110,7 @@ pub impl<T:Copy Num Eq> Vec4<T>: Eq {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn ne(other: &Vec4<T>) -> bool {
|
||||
fn ne(other: &Vec4<T>) -> bool {
|
||||
!(self == *other)
|
||||
}
|
||||
}
|
||||
|
|
178
src/vec.rs
178
src/vec.rs
|
@ -21,14 +21,14 @@ pub trait Vector<T>: Index<uint, T> + Eq {
|
|||
/**
|
||||
* Construct the vector from a single value, copying it to each component
|
||||
*/
|
||||
static pure fn from_value(value: T) -> Self;
|
||||
static fn from_value(value: T) -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* A pointer to the first component of the vector
|
||||
*/
|
||||
pure fn to_ptr(&self) -> *T;
|
||||
fn to_ptr(&self) -> *T;
|
||||
}
|
||||
|
||||
pub trait MutableVector<T>: Vector<T> {
|
||||
|
@ -47,21 +47,21 @@ pub trait MutableVector<T>: Vector<T> {
|
|||
* A generic 2-dimensional vector
|
||||
*/
|
||||
pub trait Vector2<T>: Vector<T> {
|
||||
static pure fn new(x: T, y: T) -> Self;
|
||||
static fn new(x: T, y: T) -> Self;
|
||||
}
|
||||
|
||||
/**
|
||||
* A generic 3-dimensional vector
|
||||
*/
|
||||
pub trait Vector3<T>: Vector<T> {
|
||||
static pure fn new(x: T, y: T, z: T) -> Self;
|
||||
static fn new(x: T, y: T, z: T) -> Self;
|
||||
}
|
||||
|
||||
/**
|
||||
* A generic 4-dimensional vector
|
||||
*/
|
||||
pub trait Vector4<T>: Vector<T> {
|
||||
static pure fn new(x: T, y: T, z: T, w: T) -> Self;
|
||||
static fn new(x: T, y: T, z: T, w: T) -> Self;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -75,7 +75,7 @@ pub trait NumericVector<T>: Vector<T> + Neg<Self> {
|
|||
*
|
||||
* A vector with each component set to one
|
||||
*/
|
||||
static pure fn identity() -> Self;
|
||||
static fn identity() -> Self;
|
||||
|
||||
/**
|
||||
* The null vector
|
||||
|
@ -84,96 +84,96 @@ pub trait NumericVector<T>: Vector<T> + Neg<Self> {
|
|||
*
|
||||
* A vector with each component set to zero
|
||||
*/
|
||||
static pure fn zero() -> Self;
|
||||
static fn zero() -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* True if the vector is equal to zero
|
||||
*/
|
||||
pure fn is_zero(&self) -> bool;
|
||||
fn is_zero(&self) -> bool;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The scalar multiplication of the vector and `value`
|
||||
*/
|
||||
pure fn mul_t(&self, value: T) -> Self;
|
||||
fn mul_t(&self, value: T) -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The scalar division of the vector and `value`
|
||||
*/
|
||||
pure fn div_t(&self, value: T) -> Self;
|
||||
fn div_t(&self, value: T) -> Self;
|
||||
|
||||
/**
|
||||
* Component-wise vector addition
|
||||
*/
|
||||
pure fn add_v(&self, other: &Self) -> Self;
|
||||
fn add_v(&self, other: &Self) -> Self;
|
||||
|
||||
/**
|
||||
* Component-wise vector subtraction
|
||||
*/
|
||||
pure fn sub_v(&self, other: &Self) -> Self;
|
||||
fn sub_v(&self, other: &Self) -> Self;
|
||||
|
||||
/**
|
||||
* Component-wise vector multiplication
|
||||
*/
|
||||
pure fn mul_v(&self, other: &Self) -> Self;
|
||||
fn mul_v(&self, other: &Self) -> Self;
|
||||
|
||||
/**
|
||||
* Component-wise vector division
|
||||
*/
|
||||
pure fn div_v(&self, other: &Self) -> Self;
|
||||
fn div_v(&self, other: &Self) -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The dot product of the vector and `other`
|
||||
*/
|
||||
pure fn dot(&self, other: &Self) -> T;
|
||||
fn dot(&self, other: &Self) -> T;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 2-dimensional vector with numeric components
|
||||
*/
|
||||
pub trait NumericVector2<T>: NumericVector<T> {
|
||||
static pure fn unit_x() -> Self;
|
||||
static pure fn unit_y() -> Self;
|
||||
static fn unit_x() -> Self;
|
||||
static fn unit_y() -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The perp dot product of the vector and `other`
|
||||
*/
|
||||
pure fn perp_dot(&self, other: &Self) -> T;
|
||||
fn perp_dot(&self, other: &Self) -> T;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 3-dimensional vector with numeric components
|
||||
*/
|
||||
pub trait NumericVector3<T>: NumericVector<T> {
|
||||
static pure fn unit_x() -> Self;
|
||||
static pure fn unit_y() -> Self;
|
||||
static pure fn unit_z() -> Self;
|
||||
static fn unit_x() -> Self;
|
||||
static fn unit_y() -> Self;
|
||||
static fn unit_z() -> Self;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The cross product of the vector and `other`
|
||||
*/
|
||||
pure fn cross(&self, other: &Self) -> Self;
|
||||
fn cross(&self, other: &Self) -> Self;
|
||||
}
|
||||
|
||||
/**
|
||||
* A 4-dimensional vector with numeric components
|
||||
*/
|
||||
pub trait NumericVector4<T>: NumericVector<T> {
|
||||
static pure fn unit_x() -> Self;
|
||||
static pure fn unit_y() -> Self;
|
||||
static pure fn unit_z() -> Self;
|
||||
static pure fn unit_w() -> Self;
|
||||
static fn unit_x() -> Self;
|
||||
static fn unit_y() -> Self;
|
||||
static fn unit_z() -> Self;
|
||||
static fn unit_w() -> Self;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -231,7 +231,7 @@ pub trait ToHomogeneous<H> {
|
|||
/**
|
||||
* Convert to a homogenous coordinate
|
||||
*/
|
||||
pure fn to_homogeneous(&self) -> H;
|
||||
fn to_homogeneous(&self) -> H;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -248,7 +248,7 @@ pub trait EuclideanVector<T>: NumericVector<T> {
|
|||
* The squared length of the vector. This is useful for comparisons where
|
||||
* the exact length does not need to be calculated.
|
||||
*/
|
||||
pure fn length2(&self) -> T;
|
||||
fn length2(&self) -> T;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
|
@ -261,40 +261,40 @@ pub trait EuclideanVector<T>: NumericVector<T> {
|
|||
* known, for example for quaternion-quaternion length comparisons,
|
||||
* it is advisable to use the `length2` method instead.
|
||||
*/
|
||||
pure fn length(&self) -> T;
|
||||
fn length(&self) -> T;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The squared distance between the vector and `other`.
|
||||
*/
|
||||
pure fn distance2(&self, other: &Self) -> T;
|
||||
fn distance2(&self, other: &Self) -> T;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The distance between the vector and `other`
|
||||
*/
|
||||
pure fn distance(&self, other: &Self) -> T;
|
||||
fn distance(&self, other: &Self) -> T;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The angle between the vector and `other` in radians
|
||||
*/
|
||||
pure fn angle(&self, other: &Self) -> T;
|
||||
fn angle(&self, other: &Self) -> T;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* The normalized vector
|
||||
*/
|
||||
pure fn normalize(&self) -> Self;
|
||||
fn normalize(&self) -> Self;
|
||||
|
||||
/**
|
||||
* Set the length of the vector whilst preserving the direction
|
||||
*/
|
||||
pure fn normalize_to(&self, length: T) -> Self;
|
||||
fn normalize_to(&self, length: T) -> Self;
|
||||
|
||||
/**
|
||||
* Linearly intoperlate between the vector and `other`
|
||||
|
@ -303,7 +303,7 @@ pub trait EuclideanVector<T>: NumericVector<T> {
|
|||
*
|
||||
* The intoperlated vector
|
||||
*/
|
||||
pure fn lerp(&self, other: &Self, amount: T) -> Self;
|
||||
fn lerp(&self, other: &Self, amount: T) -> Self;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -342,22 +342,22 @@ pub trait OrdinalVector<T, BoolVec>: Vector<T> {
|
|||
/**
|
||||
* Component-wise compare of `self < other`
|
||||
*/
|
||||
pure fn less_than(&self, other: &Self) -> BoolVec;
|
||||
fn less_than(&self, other: &Self) -> BoolVec;
|
||||
|
||||
/**
|
||||
* Component-wise compare of `self <= other`
|
||||
*/
|
||||
pure fn less_than_equal(&self, other: &Self) -> BoolVec;
|
||||
fn less_than_equal(&self, other: &Self) -> BoolVec;
|
||||
|
||||
/**
|
||||
* Component-wise compare of `self > other`
|
||||
*/
|
||||
pure fn greater_than(&self, other: &Self) -> BoolVec;
|
||||
fn greater_than(&self, other: &Self) -> BoolVec;
|
||||
|
||||
/**
|
||||
* Component-wise compare of `self >= other`
|
||||
*/
|
||||
pure fn greater_than_equal(&self, other: &Self) -> BoolVec;
|
||||
fn greater_than_equal(&self, other: &Self) -> BoolVec;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -371,12 +371,12 @@ pub trait EquableVector<T, BoolVec>: Vector<T> {
|
|||
/**
|
||||
* Component-wise compare of `self == other`
|
||||
*/
|
||||
pure fn equal(&self, other: &Self) -> BoolVec;
|
||||
fn equal(&self, other: &Self) -> BoolVec;
|
||||
|
||||
/**
|
||||
* Component-wise compare of `self != other`
|
||||
*/
|
||||
pure fn not_equal(&self, other: &Self) -> BoolVec;
|
||||
fn not_equal(&self, other: &Self) -> BoolVec;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -392,93 +392,93 @@ pub trait BooleanVector: Vector<bool> {
|
|||
*
|
||||
* `true` if of any component is `true`
|
||||
*/
|
||||
pure fn any(&self) -> bool;
|
||||
fn any(&self) -> bool;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* `true` only if all components are `true`
|
||||
*/
|
||||
pure fn all(&self) -> bool;
|
||||
fn all(&self) -> bool;
|
||||
|
||||
/**
|
||||
* # Return value
|
||||
*
|
||||
* the component-wise logical complement
|
||||
*/
|
||||
pure fn not(&self) -> Self;
|
||||
fn not(&self) -> Self;
|
||||
}
|
||||
|
||||
pub trait TrigVec<T>: Vector<T> {
|
||||
pure fn radians(&self) -> Self;
|
||||
pure fn degrees(&self) -> Self;
|
||||
fn radians(&self) -> Self;
|
||||
fn degrees(&self) -> Self;
|
||||
|
||||
// Triganometric functions
|
||||
pure fn sin(&self) -> Self;
|
||||
pure fn cos(&self) -> Self;
|
||||
pure fn tan(&self) -> Self;
|
||||
fn sin(&self) -> Self;
|
||||
fn cos(&self) -> Self;
|
||||
fn tan(&self) -> Self;
|
||||
|
||||
// Inverse triganometric functions
|
||||
pure fn asin(&self) -> Self;
|
||||
pure fn acos(&self) -> Self;
|
||||
pure fn atan(&self) -> Self;
|
||||
pure fn atan2(&self, other: Self) -> Self;
|
||||
fn asin(&self) -> Self;
|
||||
fn acos(&self) -> Self;
|
||||
fn atan(&self) -> Self;
|
||||
fn atan2(&self, other: Self) -> Self;
|
||||
|
||||
// Hyperbolic triganometric functions
|
||||
pure fn sinh(&self) -> Self;
|
||||
pure fn cosh(&self) -> Self;
|
||||
pure fn tanh(&self) -> Self;
|
||||
// pure fn asinh() -> Self;
|
||||
// pure fn acosh() -> Self;
|
||||
// pure fn atanh() -> Self;
|
||||
fn sinh(&self) -> Self;
|
||||
fn cosh(&self) -> Self;
|
||||
fn tanh(&self) -> Self;
|
||||
// fn asinh() -> Self;
|
||||
// fn acosh() -> Self;
|
||||
// fn atanh() -> Self;
|
||||
}
|
||||
|
||||
pub trait ExpVec<T>: Vector<T> {
|
||||
// Exponential functions
|
||||
pure fn pow_t(&self, n: Self) -> Self;
|
||||
pure fn pow_v(&self, n: T) -> Self;
|
||||
pure fn exp(&self) -> Self;
|
||||
pure fn exp2(&self) -> Self;
|
||||
pure fn ln(&self) -> Self;
|
||||
pure fn ln2(&self) -> Self;
|
||||
pure fn sqrt(&self) -> Self;
|
||||
pure fn inv_sqrt(&self) -> Self;
|
||||
fn pow_t(&self, n: Self) -> Self;
|
||||
fn pow_v(&self, n: T) -> Self;
|
||||
fn exp(&self) -> Self;
|
||||
fn exp2(&self) -> Self;
|
||||
fn ln(&self) -> Self;
|
||||
fn ln2(&self) -> Self;
|
||||
fn sqrt(&self) -> Self;
|
||||
fn inv_sqrt(&self) -> Self;
|
||||
}
|
||||
|
||||
pub trait ApproxVec<T>: Vector<T> {
|
||||
// Whole-number approximation functions
|
||||
pure fn floor(&self) -> Self;
|
||||
pure fn trunc(&self) -> Self;
|
||||
pure fn round(&self) -> Self;
|
||||
// pure fn round_even(&self) -> Self;
|
||||
pure fn ceil(&self) -> Self;
|
||||
pure fn fract(&self) -> Self;
|
||||
fn floor(&self) -> Self;
|
||||
fn trunc(&self) -> Self;
|
||||
fn round(&self) -> Self;
|
||||
// fn round_even(&self) -> Self;
|
||||
fn ceil(&self) -> Self;
|
||||
fn fract(&self) -> Self;
|
||||
}
|
||||
|
||||
pub trait SignedVec<T,BV>: Vector<T> {
|
||||
pure fn is_positive(&self) -> BV;
|
||||
pure fn is_negative(&self) -> BV;
|
||||
pure fn is_nonpositive(&self) -> BV;
|
||||
pure fn is_nonnegative(&self) -> BV;
|
||||
fn is_positive(&self) -> BV;
|
||||
fn is_negative(&self) -> BV;
|
||||
fn is_nonpositive(&self) -> BV;
|
||||
fn is_nonnegative(&self) -> BV;
|
||||
|
||||
pure fn abs(&self) -> Self;
|
||||
pure fn sign(&self) -> Self;
|
||||
pure fn copysign(&self, other: Self) -> Self;
|
||||
fn abs(&self) -> Self;
|
||||
fn sign(&self) -> Self;
|
||||
fn copysign(&self, other: Self) -> Self;
|
||||
}
|
||||
|
||||
pub trait ExtentVec<T>: Vector<T> {
|
||||
pure fn min_v(&self, other: &Self) -> Self;
|
||||
pure fn max_v(&self, other: &Self) -> Self;
|
||||
pure fn clamp_v(&self, mn: &Self, mx: &Self) -> Self;
|
||||
fn min_v(&self, other: &Self) -> Self;
|
||||
fn max_v(&self, other: &Self) -> Self;
|
||||
fn clamp_v(&self, mn: &Self, mx: &Self) -> Self;
|
||||
|
||||
pure fn min_t(&self, other: T) -> Self;
|
||||
pure fn max_t(&self, other: T) -> Self;
|
||||
pure fn clamp_t(&self, mn: T, mx: T) -> Self;
|
||||
fn min_t(&self, other: T) -> Self;
|
||||
fn max_t(&self, other: T) -> Self;
|
||||
fn clamp_t(&self, mn: T, mx: T) -> Self;
|
||||
}
|
||||
|
||||
pub trait MixVec<T>: Vector<T> {
|
||||
// Functions for blending numbers together
|
||||
pure fn mix(&self, other: Self, value: Self) -> Self;
|
||||
pure fn smooth_step(&self, edge0: Self, edge1: Self) -> Self;
|
||||
pure fn step(&self, edge: Self) -> Self;
|
||||
fn mix(&self, other: Self, value: Self) -> Self;
|
||||
fn smooth_step(&self, edge0: Self, edge1: Self) -> Self;
|
||||
fn step(&self, edge: Self) -> Self;
|
||||
}
|
148
src/vec2.rs
148
src/vec2.rs
|
@ -45,12 +45,12 @@ pub struct Vec2<T> { x: T, y: T }
|
|||
|
||||
impl<T:Copy + Eq> Vector<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
static pure fn from_value(value: T) -> Vec2<T> {
|
||||
static fn from_value(value: T) -> Vec2<T> {
|
||||
Vector2::new(value, value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
fn to_ptr(&self) -> *T {
|
||||
unsafe {
|
||||
transmute::<*Vec2<T>, *T>(
|
||||
to_unsafe_ptr(self)
|
||||
|
@ -61,14 +61,14 @@ impl<T:Copy + Eq> Vector<T> for Vec2<T> {
|
|||
|
||||
impl<T> Vector2<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
static pure fn new(x: T, y: T ) -> Vec2<T> {
|
||||
static fn new(x: T, y: T ) -> Vec2<T> {
|
||||
Vec2 { x: x, y: y }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Eq> Index<uint, T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> T {
|
||||
fn index(&self, i: uint) -> T {
|
||||
unsafe { do buf_as_slice(self.to_ptr(), 2) |slice| { slice[i] } }
|
||||
}
|
||||
}
|
||||
|
@ -92,59 +92,59 @@ impl<T:Copy> MutableVector<T> for Vec2<T> {
|
|||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Vec2<T> {
|
||||
static fn identity() -> Vec2<T> {
|
||||
Vector2::new(one::<T>(), one::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Vec2<T> {
|
||||
static fn zero() -> Vec2<T> {
|
||||
Vector2::new(zero::<T>(), zero::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_zero(&self) -> bool {
|
||||
fn is_zero(&self) -> bool {
|
||||
self[0] == zero() &&
|
||||
self[1] == zero()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(&self, value: T) -> Vec2<T> {
|
||||
fn mul_t(&self, value: T) -> Vec2<T> {
|
||||
Vector2::new(self[0] * value,
|
||||
self[1] * value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn div_t(&self, value: T) -> Vec2<T> {
|
||||
fn div_t(&self, value: T) -> Vec2<T> {
|
||||
Vector2::new(self[0] / value,
|
||||
self[1] / value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_v(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
fn add_v(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
Vector2::new(self[0] + other[0],
|
||||
self[1] + other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_v(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
fn sub_v(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
Vector2::new(self[0] - other[0],
|
||||
self[1] - other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_v(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
fn mul_v(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
Vector2::new(self[0] * other[0],
|
||||
self[1] * other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn div_v(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
fn div_v(&self, other: &Vec2<T>) -> Vec2<T> {
|
||||
Vector2::new(self[0] / other[0],
|
||||
self[1] / other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn dot(&self, other: &Vec2<T>) -> T {
|
||||
fn dot(&self, other: &Vec2<T>) -> T {
|
||||
self[0] * other[0] +
|
||||
self[1] * other[1]
|
||||
}
|
||||
|
@ -152,24 +152,24 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec2<T>> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Vec2<T> {
|
||||
fn neg(&self) -> Vec2<T> {
|
||||
Vector2::new(-self[0], -self[1])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector2<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
static pure fn unit_x() -> Vec2<T> {
|
||||
static fn unit_x() -> Vec2<T> {
|
||||
Vector2::new(one::<T>(), zero::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn unit_y() -> Vec2<T> {
|
||||
static fn unit_y() -> Vec2<T> {
|
||||
Vector2::new(zero::<T>(), one::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn perp_dot(&self, other: &Vec2<T>) ->T {
|
||||
fn perp_dot(&self, other: &Vec2<T>) ->T {
|
||||
(self[0] * other[1]) - (self[1] * other[0])
|
||||
}
|
||||
}
|
||||
|
@ -220,49 +220,49 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Mutab
|
|||
|
||||
impl<T:Copy + Number> ToHomogeneous<Vec3<T>> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn to_homogeneous(&self) -> Vec3<T> {
|
||||
fn to_homogeneous(&self) -> Vec3<T> {
|
||||
Vector3::new(self.x, self.y, zero())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn length2(&self) -> T {
|
||||
fn length2(&self) -> T {
|
||||
self.dot(self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn length(&self) -> T {
|
||||
fn length(&self) -> T {
|
||||
self.length2().sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn distance2(&self, other: &Vec2<T>) -> T {
|
||||
fn distance2(&self, other: &Vec2<T>) -> T {
|
||||
other.sub_v(self).length2()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn distance(&self, other: &Vec2<T>) -> T {
|
||||
fn distance(&self, other: &Vec2<T>) -> T {
|
||||
other.distance2(self).sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn angle(&self, other: &Vec2<T>) -> T {
|
||||
fn angle(&self, other: &Vec2<T>) -> T {
|
||||
atan2(self.perp_dot(other), self.dot(other))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize(&self) -> Vec2<T> {
|
||||
fn normalize(&self) -> Vec2<T> {
|
||||
self.mul_t(one::<T>()/self.length())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize_to(&self, length: T) -> Vec2<T> {
|
||||
fn normalize_to(&self, length: T) -> Vec2<T> {
|
||||
self.mul_t(length / self.length())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn lerp(&self, other: &Vec2<T>, amount: T) -> Vec2<T> {
|
||||
fn lerp(&self, other: &Vec2<T>, amount: T) -> Vec2<T> {
|
||||
self.add_v(&other.sub_v(self).mul_t(amount))
|
||||
}
|
||||
}
|
||||
|
@ -287,12 +287,12 @@ impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Mutabl
|
|||
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Vec2<T>) -> bool {
|
||||
fn fuzzy_eq(&self, other: &Vec2<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq_eps(&self, other: &Vec2<T>, epsilon: &T) -> bool {
|
||||
fn fuzzy_eq_eps(&self, other: &Vec2<T>, epsilon: &T) -> bool {
|
||||
self[0].fuzzy_eq_eps(&other[0], epsilon) &&
|
||||
self[1].fuzzy_eq_eps(&other[1], epsilon)
|
||||
}
|
||||
|
@ -300,25 +300,25 @@ impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec2<T> {
|
|||
|
||||
impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec2<bool>> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn less_than(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
fn less_than(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vector2::new(self[0] < other[0],
|
||||
self[1] < other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn less_than_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
fn less_than_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vector2::new(self[0] <= other[0],
|
||||
self[1] <= other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
fn greater_than(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vector2::new(self[0] > other[0],
|
||||
self[1] > other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
fn greater_than_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vector2::new(self[0] >= other[0],
|
||||
self[1] >= other[1])
|
||||
}
|
||||
|
@ -326,13 +326,13 @@ impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec2<bool>> for Vec2<T> {
|
|||
|
||||
impl<T:Copy + Eq> EquableVector<T, Vec2<bool>> for Vec2<T> {
|
||||
#[inline(always)]
|
||||
pure fn equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
fn equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vector2::new(self[0] == other[0],
|
||||
self[1] == other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
fn not_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vector2::new(self[0] != other[0],
|
||||
self[1] != other[1])
|
||||
}
|
||||
|
@ -340,17 +340,17 @@ impl<T:Copy + Eq> EquableVector<T, Vec2<bool>> for Vec2<T> {
|
|||
|
||||
impl BooleanVector for Vec2<bool> {
|
||||
#[inline(always)]
|
||||
pure fn any(&self) -> bool {
|
||||
fn any(&self) -> bool {
|
||||
self[0] || self[1]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn all(&self) -> bool {
|
||||
fn all(&self) -> bool {
|
||||
self[0] && self[1]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not(&self) -> Vec2<bool> {
|
||||
fn not(&self) -> Vec2<bool> {
|
||||
Vector2::new(!self[0], !self[1])
|
||||
}
|
||||
}
|
||||
|
@ -367,63 +367,63 @@ pub type uvec2 = Vec2<u32>; // a two-component unsigned integer vector
|
|||
// Static method wrappers for GLSL-style types
|
||||
|
||||
impl vec2 {
|
||||
#[inline(always)] static pure fn new(x: f32, y: f32) -> vec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> vec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> vec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> vec2 { NumericVector::zero() }
|
||||
#[inline(always)] static fn new(x: f32, y: f32) -> vec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static fn from_value(v: f32) -> vec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn identity() -> vec2 { NumericVector::identity() }
|
||||
#[inline(always)] static fn zero() -> vec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> vec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> vec2 { NumericVector2::unit_y() }
|
||||
#[inline(always)] static fn unit_x() -> vec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static fn unit_y() -> vec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec2>() }
|
||||
#[inline(always)] static fn dim() -> uint { 2 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<vec2>() }
|
||||
}
|
||||
|
||||
impl dvec2 {
|
||||
#[inline(always)] static pure fn new(x: f64, y: f64) -> dvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dvec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dvec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dvec2 { NumericVector::zero() }
|
||||
#[inline(always)] static fn new(x: f64, y: f64) -> dvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static fn from_value(v: f64) -> dvec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn identity() -> dvec2 { NumericVector::identity() }
|
||||
#[inline(always)] static fn zero() -> dvec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> dvec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> dvec2 { NumericVector2::unit_y() }
|
||||
#[inline(always)] static fn unit_x() -> dvec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static fn unit_y() -> dvec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec2>() }
|
||||
#[inline(always)] static fn dim() -> uint { 2 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<dvec2>() }
|
||||
}
|
||||
|
||||
impl bvec2 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool) -> bvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: bool) -> bvec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn new(x: bool, y: bool) -> bvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static fn from_value(v: bool) -> bvec2 { Vector::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<bvec2>() }
|
||||
#[inline(always)] static fn dim() -> uint { 2 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<bvec2>() }
|
||||
}
|
||||
|
||||
impl ivec2 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32) -> ivec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> ivec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> ivec2 { NumericVector::zero() }
|
||||
#[inline(always)] static fn new(x: i32, y: i32) -> ivec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static fn from_value(v: i32) -> ivec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn identity() -> ivec2 { NumericVector::identity() }
|
||||
#[inline(always)] static fn zero() -> ivec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> ivec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> ivec2 { NumericVector2::unit_y() }
|
||||
#[inline(always)] static fn unit_x() -> ivec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static fn unit_y() -> ivec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec2>() }
|
||||
#[inline(always)] static fn dim() -> uint { 2 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<ivec2>() }
|
||||
}
|
||||
|
||||
impl uvec2 {
|
||||
#[inline(always)] static pure fn new(x: u32, y: u32) -> uvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: u32) -> uvec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> uvec2 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> uvec2 { NumericVector::zero() }
|
||||
#[inline(always)] static fn new(x: u32, y: u32) -> uvec2 { Vector2::new(x, y) }
|
||||
#[inline(always)] static fn from_value(v: u32) -> uvec2 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn identity() -> uvec2 { NumericVector::identity() }
|
||||
#[inline(always)] static fn zero() -> uvec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> uvec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> uvec2 { NumericVector2::unit_y() }
|
||||
#[inline(always)] static fn unit_x() -> uvec2 { NumericVector2::unit_x() }
|
||||
#[inline(always)] static fn unit_y() -> uvec2 { NumericVector2::unit_y() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec2>() }
|
||||
#[inline(always)] static fn dim() -> uint { 2 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<uvec2>() }
|
||||
}
|
||||
|
||||
// Type aliases named in a more 'Rustic' style
|
||||
|
|
158
src/vec3.rs
158
src/vec3.rs
|
@ -47,12 +47,12 @@ pub struct Vec3<T> { x: T, y: T, z: T }
|
|||
|
||||
impl<T:Copy + Eq> Vector<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
static pure fn from_value(value: T) -> Vec3<T> {
|
||||
static fn from_value(value: T) -> Vec3<T> {
|
||||
Vector3::new(value, value, value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
fn to_ptr(&self) -> *T {
|
||||
unsafe {
|
||||
transmute::<*Vec3<T>, *T>(
|
||||
to_unsafe_ptr(self)
|
||||
|
@ -63,14 +63,14 @@ impl<T:Copy + Eq> Vector<T> for Vec3<T> {
|
|||
|
||||
impl<T> Vector3<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
static pure fn new(x: T, y: T, z: T) -> Vec3<T> {
|
||||
static fn new(x: T, y: T, z: T) -> Vec3<T> {
|
||||
Vec3 { x: x, y: y, z: z }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Eq> Index<uint, T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> T {
|
||||
fn index(&self, i: uint) -> T {
|
||||
unsafe { do buf_as_slice(self.to_ptr(), 3) |slice| { slice[i] } }
|
||||
}
|
||||
}
|
||||
|
@ -95,66 +95,66 @@ impl<T:Copy> MutableVector<T> for Vec3<T> {
|
|||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Vec3<T> {
|
||||
static fn identity() -> Vec3<T> {
|
||||
Vector3::new(one::<T>(), one::<T>(), one::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Vec3<T> {
|
||||
static fn zero() -> Vec3<T> {
|
||||
Vector3::new(zero::<T>(), zero::<T>(), zero::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_zero(&self) -> bool {
|
||||
fn is_zero(&self) -> bool {
|
||||
self[0] == zero() &&
|
||||
self[1] == zero() &&
|
||||
self[2] == zero()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(&self, value: T) -> Vec3<T> {
|
||||
fn mul_t(&self, value: T) -> Vec3<T> {
|
||||
Vector3::new(self[0] * value,
|
||||
self[1] * value,
|
||||
self[2] * value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn div_t(&self, value: T) -> Vec3<T> {
|
||||
fn div_t(&self, value: T) -> Vec3<T> {
|
||||
Vector3::new(self[0] / value,
|
||||
self[1] / value,
|
||||
self[2] / value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_v(&self, other: &Vec3<T>) -> Vec3<T>{
|
||||
fn add_v(&self, other: &Vec3<T>) -> Vec3<T>{
|
||||
Vector3::new(self[0] + other[0],
|
||||
self[1] + other[1],
|
||||
self[2] + other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_v(&self, other: &Vec3<T>) -> Vec3<T>{
|
||||
fn sub_v(&self, other: &Vec3<T>) -> Vec3<T>{
|
||||
Vector3::new(self[0] - other[0],
|
||||
self[1] - other[1],
|
||||
self[2] - other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_v(&self, other: &Vec3<T>) -> Vec3<T>{
|
||||
fn mul_v(&self, other: &Vec3<T>) -> Vec3<T>{
|
||||
Vector3::new(self[0] * other[0],
|
||||
self[1] * other[1],
|
||||
self[2] * other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn div_v(&self, other: &Vec3<T>) -> Vec3<T>{
|
||||
fn div_v(&self, other: &Vec3<T>) -> Vec3<T>{
|
||||
Vector3::new(self[0] / other[0],
|
||||
self[1] / other[1],
|
||||
self[2] / other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn dot(&self, other: &Vec3<T>) -> T {
|
||||
fn dot(&self, other: &Vec3<T>) -> T {
|
||||
self[0] * other[0] +
|
||||
self[1] * other[1] +
|
||||
self[2] * other[2]
|
||||
|
@ -163,29 +163,29 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec3<T>> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Vec3<T> {
|
||||
fn neg(&self) -> Vec3<T> {
|
||||
Vector3::new(-self[0], -self[1], -self[2])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector3<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
static pure fn unit_x() -> Vec3<T> {
|
||||
static fn unit_x() -> Vec3<T> {
|
||||
Vector3::new(one::<T>(), zero::<T>(), zero::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn unit_y() -> Vec3<T> {
|
||||
static fn unit_y() -> Vec3<T> {
|
||||
Vector3::new(zero::<T>(), one::<T>(), zero::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn unit_z() -> Vec3<T> {
|
||||
static fn unit_z() -> Vec3<T> {
|
||||
Vector3::new(zero::<T>(), zero::<T>(), one::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn cross(&self, other: &Vec3<T>) -> Vec3<T> {
|
||||
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]))
|
||||
|
@ -252,49 +252,49 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Mutab
|
|||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> ToHomogeneous<Vec4<T>> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn to_homogeneous(&self) -> Vec4<T> {
|
||||
fn to_homogeneous(&self) -> Vec4<T> {
|
||||
Vector4::new(self.x, self.y, self.z, zero())
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn length2(&self) -> T {
|
||||
fn length2(&self) -> T {
|
||||
self.dot(self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn length(&self) -> T {
|
||||
fn length(&self) -> T {
|
||||
self.length2().sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn distance2(&self, other: &Vec3<T>) -> T {
|
||||
fn distance2(&self, other: &Vec3<T>) -> T {
|
||||
other.sub_v(self).length2()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn distance(&self, other: &Vec3<T>) -> T {
|
||||
fn distance(&self, other: &Vec3<T>) -> T {
|
||||
other.distance2(self).sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn angle(&self, other: &Vec3<T>) -> T {
|
||||
fn angle(&self, other: &Vec3<T>) -> T {
|
||||
atan2(self.cross(other).length(), self.dot(other))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize(&self) -> Vec3<T> {
|
||||
fn normalize(&self) -> Vec3<T> {
|
||||
self.mul_t(one::<T>()/self.length())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize_to(&self, length: T) -> Vec3<T> {
|
||||
fn normalize_to(&self, length: T) -> Vec3<T> {
|
||||
self.mul_t(length / self.length())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn lerp(&self, other: &Vec3<T>, amount: T) -> Vec3<T> {
|
||||
fn lerp(&self, other: &Vec3<T>, amount: T) -> Vec3<T> {
|
||||
self.add_v(&other.sub_v(self).mul_t(amount))
|
||||
}
|
||||
}
|
||||
|
@ -319,12 +319,12 @@ impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Mutabl
|
|||
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Vec3<T>) -> bool {
|
||||
fn fuzzy_eq(&self, other: &Vec3<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq_eps(&self, other: &Vec3<T>, epsilon: &T) -> bool {
|
||||
fn fuzzy_eq_eps(&self, other: &Vec3<T>, epsilon: &T) -> bool {
|
||||
self[0].fuzzy_eq_eps(&other[0], epsilon) &&
|
||||
self[1].fuzzy_eq_eps(&other[1], epsilon) &&
|
||||
self[2].fuzzy_eq_eps(&other[2], epsilon)
|
||||
|
@ -333,28 +333,28 @@ impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec3<T> {
|
|||
|
||||
impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec3<bool>> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn less_than(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
fn less_than(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vector3::new(self[0] < other[0],
|
||||
self[1] < other[1],
|
||||
self[2] < other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn less_than_equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
fn less_than_equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vector3::new(self[0] <= other[0],
|
||||
self[1] <= other[1],
|
||||
self[2] <= other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
fn greater_than(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vector3::new(self[0] > other[0],
|
||||
self[1] > other[1],
|
||||
self[2] > other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than_equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
fn greater_than_equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vector3::new(self[0] >= other[0],
|
||||
self[1] >= other[1],
|
||||
self[2] >= other[2])
|
||||
|
@ -363,14 +363,14 @@ impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec3<bool>> for Vec3<T> {
|
|||
|
||||
impl<T:Copy + Eq> EquableVector<T, Vec3<bool>> for Vec3<T> {
|
||||
#[inline(always)]
|
||||
pure fn equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
fn equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vector3::new(self[0] == other[0],
|
||||
self[1] == other[1],
|
||||
self[2] == other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not_equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
fn not_equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vector3::new(self[0] != other[0],
|
||||
self[1] != other[1],
|
||||
self[2] != other[2])
|
||||
|
@ -379,17 +379,17 @@ impl<T:Copy + Eq> EquableVector<T, Vec3<bool>> for Vec3<T> {
|
|||
|
||||
impl BooleanVector for Vec3<bool> {
|
||||
#[inline(always)]
|
||||
pure fn any(&self) -> bool {
|
||||
fn any(&self) -> bool {
|
||||
self[0] || self[1] || self[2]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn all(&self) -> bool {
|
||||
fn all(&self) -> bool {
|
||||
self[0] && self[1] && self[2]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not(&self) -> Vec3<bool> {
|
||||
fn not(&self) -> Vec3<bool> {
|
||||
Vector3::new(!self[0], !self[1], !self[2])
|
||||
}
|
||||
}
|
||||
|
@ -406,65 +406,65 @@ pub type uvec3 = Vec3<u32>; // a three-component unsigned integer vector
|
|||
// Static method wrappers for GLSL-style types
|
||||
|
||||
impl vec3 {
|
||||
#[inline(always)] static pure fn new(x: f32, y: f32, z: f32) -> vec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> vec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> vec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> vec3 { NumericVector::zero() }
|
||||
#[inline(always)] static fn new(x: f32, y: f32, z: f32) -> vec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static fn from_value(v: f32) -> vec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn identity() -> vec3 { NumericVector::identity() }
|
||||
#[inline(always)] static fn zero() -> vec3 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> vec3 { NumericVector3::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> vec3 { NumericVector3::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> vec3 { NumericVector3::unit_z() }
|
||||
#[inline(always)] static fn unit_x() -> vec3 { NumericVector3::unit_x() }
|
||||
#[inline(always)] static fn unit_y() -> vec3 { NumericVector3::unit_y() }
|
||||
#[inline(always)] static fn unit_z() -> vec3 { NumericVector3::unit_z() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec3>() }
|
||||
#[inline(always)] static fn dim() -> uint { 3 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<vec3>() }
|
||||
}
|
||||
|
||||
impl dvec3 {
|
||||
#[inline(always)] static pure fn new(x: f64, y: f64, z: f64) -> dvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dvec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dvec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dvec3 { NumericVector::zero() }
|
||||
#[inline(always)] static fn new(x: f64, y: f64, z: f64) -> dvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static fn from_value(v: f64) -> dvec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn identity() -> dvec3 { NumericVector::identity() }
|
||||
#[inline(always)] static fn zero() -> dvec3 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> dvec3 { NumericVector3::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> dvec3 { NumericVector3::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> dvec3 { NumericVector3::unit_z() }
|
||||
#[inline(always)] static fn unit_x() -> dvec3 { NumericVector3::unit_x() }
|
||||
#[inline(always)] static fn unit_y() -> dvec3 { NumericVector3::unit_y() }
|
||||
#[inline(always)] static fn unit_z() -> dvec3 { NumericVector3::unit_z() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec3>() }
|
||||
#[inline(always)] static fn dim() -> uint { 3 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<dvec3>() }
|
||||
}
|
||||
|
||||
impl bvec3 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool, z: bool) -> bvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: bool) -> bvec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn new(x: bool, y: bool, z: bool) -> bvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static fn from_value(v: bool) -> bvec3 { Vector::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<bvec3>() }
|
||||
#[inline(always)] static fn dim() -> uint { 3 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<bvec3>() }
|
||||
}
|
||||
|
||||
impl ivec3 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32, z: i32) -> ivec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> ivec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> ivec3 { NumericVector::zero() }
|
||||
#[inline(always)] static fn new(x: i32, y: i32, z: i32) -> ivec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static fn from_value(v: i32) -> ivec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn identity() -> ivec3 { NumericVector::identity() }
|
||||
#[inline(always)] static fn zero() -> ivec3 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> ivec3 { NumericVector3::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> ivec3 { NumericVector3::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> ivec3 { NumericVector3::unit_z() }
|
||||
#[inline(always)] static fn unit_x() -> ivec3 { NumericVector3::unit_x() }
|
||||
#[inline(always)] static fn unit_y() -> ivec3 { NumericVector3::unit_y() }
|
||||
#[inline(always)] static fn unit_z() -> ivec3 { NumericVector3::unit_z() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec3>() }
|
||||
#[inline(always)] static fn dim() -> uint { 3 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<ivec3>() }
|
||||
}
|
||||
|
||||
impl uvec3 {
|
||||
#[inline(always)] static pure fn new(x: u32, y: u32, z: u32) -> uvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: u32) -> uvec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> uvec3 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> uvec3 { NumericVector::zero() }
|
||||
#[inline(always)] static fn new(x: u32, y: u32, z: u32) -> uvec3 { Vector3::new(x, y, z) }
|
||||
#[inline(always)] static fn from_value(v: u32) -> uvec3 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn identity() -> uvec3 { NumericVector::identity() }
|
||||
#[inline(always)] static fn zero() -> uvec3 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> uvec3 { NumericVector3::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> uvec3 { NumericVector3::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> uvec3 { NumericVector3::unit_z() }
|
||||
#[inline(always)] static fn unit_x() -> uvec3 { NumericVector3::unit_x() }
|
||||
#[inline(always)] static fn unit_y() -> uvec3 { NumericVector3::unit_y() }
|
||||
#[inline(always)] static fn unit_z() -> uvec3 { NumericVector3::unit_z() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec3>() }
|
||||
#[inline(always)] static fn dim() -> uint { 3 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<uvec3>() }
|
||||
}
|
||||
|
|
164
src/vec4.rs
164
src/vec4.rs
|
@ -45,12 +45,12 @@ pub struct Vec4<T> { x: T, y: T, z: T, w: T }
|
|||
|
||||
impl<T:Copy + Eq> Vector<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
static pure fn from_value(value: T) -> Vec4<T> {
|
||||
static fn from_value(value: T) -> Vec4<T> {
|
||||
Vector4::new(value, value, value, value)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
fn to_ptr(&self) -> *T {
|
||||
unsafe {
|
||||
transmute::<*Vec4<T>, *T>(
|
||||
to_unsafe_ptr(self)
|
||||
|
@ -61,14 +61,14 @@ impl<T:Copy + Eq> Vector<T> for Vec4<T> {
|
|||
|
||||
impl<T> Vector4<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
static pure fn new(x: T, y: T, z: T, w: T) -> Vec4<T> {
|
||||
static fn new(x: T, y: T, z: T, w: T) -> Vec4<T> {
|
||||
Vec4 { x: x, y: y, z: z, w: w }
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Eq> Index<uint, T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn index(&self, i: uint) -> T {
|
||||
fn index(&self, i: uint) -> T {
|
||||
unsafe { do buf_as_slice(self.to_ptr(), 4) |slice| { slice[i] } }
|
||||
}
|
||||
}
|
||||
|
@ -94,17 +94,17 @@ impl<T:Copy> MutableVector<T> for Vec4<T> {
|
|||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> NumericVector<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Vec4<T> {
|
||||
static fn identity() -> Vec4<T> {
|
||||
Vector4::new(one::<T>(), one::<T>(), one::<T>(), one::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Vec4<T> {
|
||||
static fn zero() -> Vec4<T> {
|
||||
Vector4::new(zero::<T>(), zero::<T>(), zero::<T>(), zero::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_zero(&self) -> bool {
|
||||
fn is_zero(&self) -> bool {
|
||||
self[0] == zero() &&
|
||||
self[1] == zero() &&
|
||||
self[2] == zero() &&
|
||||
|
@ -112,7 +112,7 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_t(&self, value: T) -> Vec4<T> {
|
||||
fn mul_t(&self, value: T) -> Vec4<T> {
|
||||
Vector4::new(self[0] * value,
|
||||
self[1] * value,
|
||||
self[2] * value,
|
||||
|
@ -120,7 +120,7 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn div_t(&self, value: T) -> Vec4<T> {
|
||||
fn div_t(&self, value: T) -> Vec4<T> {
|
||||
Vector4::new(self[0] / value,
|
||||
self[1] / value,
|
||||
self[2] / value,
|
||||
|
@ -128,7 +128,7 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn add_v(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
fn add_v(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
Vector4::new(self[0] + other[0],
|
||||
self[1] + other[1],
|
||||
self[2] + other[2],
|
||||
|
@ -136,7 +136,7 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn sub_v(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
fn sub_v(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
Vector4::new(self[0] - other[0],
|
||||
self[1] - other[1],
|
||||
self[2] - other[2],
|
||||
|
@ -144,7 +144,7 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_v(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
fn mul_v(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
Vector4::new(self[0] * other[0],
|
||||
self[1] * other[1],
|
||||
self[2] * other[2],
|
||||
|
@ -152,7 +152,7 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn div_v(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
fn div_v(&self, other: &Vec4<T>) -> Vec4<T> {
|
||||
Vector4::new(self[0] / other[0],
|
||||
self[1] / other[1],
|
||||
self[2] / other[2],
|
||||
|
@ -160,7 +160,7 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn dot(&self, other: &Vec4<T>) -> T {
|
||||
fn dot(&self, other: &Vec4<T>) -> T {
|
||||
self[0] * other[0] +
|
||||
self[1] * other[1] +
|
||||
self[2] * other[2] +
|
||||
|
@ -170,29 +170,29 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Numer
|
|||
|
||||
impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Neg<Vec4<T>> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Vec4<T> {
|
||||
fn neg(&self) -> Vec4<T> {
|
||||
Vector4::new(-self[0], -self[1], -self[2], -self[3])
|
||||
}
|
||||
}
|
||||
|
||||
impl<T:Copy + Number> NumericVector4<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
static pure fn unit_x() -> Vec4<T> {
|
||||
static fn unit_x() -> Vec4<T> {
|
||||
Vector4::new(one::<T>(), zero::<T>(), zero::<T>(), zero::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn unit_y() -> Vec4<T> {
|
||||
static fn unit_y() -> Vec4<T> {
|
||||
Vector4::new(zero::<T>(), one::<T>(), zero::<T>(), zero::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn unit_z() -> Vec4<T> {
|
||||
static fn unit_z() -> Vec4<T> {
|
||||
Vector4::new(zero::<T>(), zero::<T>(), one::<T>(), zero::<T>())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn unit_w() -> Vec4<T> {
|
||||
static fn unit_w() -> Vec4<T> {
|
||||
Vector4::new(zero::<T>(), zero::<T>(), zero::<T>(), one::<T>())
|
||||
}
|
||||
}
|
||||
|
@ -257,42 +257,42 @@ impl<T:Copy + Number + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Mutab
|
|||
|
||||
impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> EuclideanVector<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn length2(&self) -> T {
|
||||
fn length2(&self) -> T {
|
||||
self.dot(self)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn length(&self) -> T {
|
||||
fn length(&self) -> T {
|
||||
self.length2().sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn distance2(&self, other: &Vec4<T>) -> T {
|
||||
fn distance2(&self, other: &Vec4<T>) -> T {
|
||||
other.sub_v(self).length2()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn distance(&self, other: &Vec4<T>) -> T {
|
||||
fn distance(&self, other: &Vec4<T>) -> T {
|
||||
other.distance2(self).sqrt()
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn angle(&self, other: &Vec4<T>) -> T {
|
||||
fn angle(&self, other: &Vec4<T>) -> T {
|
||||
acos(self.dot(other) / (self.length() * other.length()))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize(&self) -> Vec4<T> {
|
||||
fn normalize(&self) -> Vec4<T> {
|
||||
self.mul_t(one::<T>()/self.length())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn normalize_to(&self, length: T) -> Vec4<T> {
|
||||
fn normalize_to(&self, length: T) -> Vec4<T> {
|
||||
self.mul_t(length / self.length())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn lerp(&self, other: &Vec4<T>, amount: T) -> Vec4<T> {
|
||||
fn lerp(&self, other: &Vec4<T>, amount: T) -> Vec4<T> {
|
||||
self.add_v(&other.sub_v(self).mul_t(amount))
|
||||
}
|
||||
}
|
||||
|
@ -317,12 +317,12 @@ impl<T:Copy + Float + Add<T,T> + Sub<T,T> + Mul<T,T> + Div<T,T> + Neg<T>> Mutabl
|
|||
|
||||
impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq(&self, other: &Vec4<T>) -> bool {
|
||||
fn fuzzy_eq(&self, other: &Vec4<T>) -> bool {
|
||||
self.fuzzy_eq_eps(other, &Number::from(FUZZY_EPSILON))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn fuzzy_eq_eps(&self, other: &Vec4<T>, epsilon: &T) -> bool {
|
||||
fn fuzzy_eq_eps(&self, other: &Vec4<T>, epsilon: &T) -> bool {
|
||||
self[0].fuzzy_eq_eps(&other[0], epsilon) &&
|
||||
self[1].fuzzy_eq_eps(&other[1], epsilon) &&
|
||||
self[2].fuzzy_eq_eps(&other[2], epsilon) &&
|
||||
|
@ -332,7 +332,7 @@ impl<T:Copy + Float + FuzzyEq<T>> FuzzyEq<T> for Vec4<T> {
|
|||
|
||||
impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec4<bool>> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn less_than(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
fn less_than(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vector4::new(self[0] < other[0],
|
||||
self[1] < other[1],
|
||||
self[2] < other[2],
|
||||
|
@ -340,7 +340,7 @@ impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec4<bool>> for Vec4<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn less_than_equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
fn less_than_equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vector4::new(self[0] <= other[0],
|
||||
self[1] <= other[1],
|
||||
self[2] <= other[2],
|
||||
|
@ -348,7 +348,7 @@ impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec4<bool>> for Vec4<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
fn greater_than(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vector4::new(self[0] > other[0],
|
||||
self[1] > other[1],
|
||||
self[2] > other[2],
|
||||
|
@ -356,7 +356,7 @@ impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec4<bool>> for Vec4<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than_equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
fn greater_than_equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vector4::new(self[0] >= other[0],
|
||||
self[1] >= other[1],
|
||||
self[2] >= other[2],
|
||||
|
@ -366,7 +366,7 @@ impl<T:Copy + Ord + Eq> OrdinalVector<T, Vec4<bool>> for Vec4<T> {
|
|||
|
||||
impl<T:Copy + Eq> EquableVector<T, Vec4<bool>> for Vec4<T> {
|
||||
#[inline(always)]
|
||||
pure fn equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
fn equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vector4::new(self[0] == other[0],
|
||||
self[1] == other[1],
|
||||
self[2] == other[2],
|
||||
|
@ -374,7 +374,7 @@ impl<T:Copy + Eq> EquableVector<T, Vec4<bool>> for Vec4<T> {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not_equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
fn not_equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vector4::new(self[0] != other[0],
|
||||
self[1] != other[1],
|
||||
self[2] != other[2],
|
||||
|
@ -384,17 +384,17 @@ impl<T:Copy + Eq> EquableVector<T, Vec4<bool>> for Vec4<T> {
|
|||
|
||||
impl BooleanVector for Vec4<bool> {
|
||||
#[inline(always)]
|
||||
pure fn any(&self) -> bool {
|
||||
fn any(&self) -> bool {
|
||||
self[0] || self[1] || self[2] || self[3]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn all(&self) -> bool {
|
||||
fn all(&self) -> bool {
|
||||
self[0] && self[1] && self[2] && self[3]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not(&self) -> Vec4<bool> {
|
||||
fn not(&self) -> Vec4<bool> {
|
||||
Vector4::new(!self[0], !self[1], !self[2], !self[3])
|
||||
}
|
||||
}
|
||||
|
@ -411,70 +411,70 @@ pub type uvec4 = Vec4<u32>; // a four-component unsigned integer vector
|
|||
// Static method wrappers for GLSL-style types
|
||||
|
||||
impl vec4 {
|
||||
#[inline(always)] static pure fn new(x: f32, y: f32, z: f32, w: f32) -> vec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> vec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> vec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> vec4 { NumericVector::zero() }
|
||||
#[inline(always)] static fn new(x: f32, y: f32, z: f32, w: f32) -> vec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static fn from_value(v: f32) -> vec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn identity() -> vec4 { NumericVector::identity() }
|
||||
#[inline(always)] static fn zero() -> vec4 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> vec4 { NumericVector4::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> vec4 { NumericVector4::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> vec4 { NumericVector4::unit_z() }
|
||||
#[inline(always)] static pure fn unit_w() -> vec4 { NumericVector4::unit_w() }
|
||||
#[inline(always)] static fn unit_x() -> vec4 { NumericVector4::unit_x() }
|
||||
#[inline(always)] static fn unit_y() -> vec4 { NumericVector4::unit_y() }
|
||||
#[inline(always)] static fn unit_z() -> vec4 { NumericVector4::unit_z() }
|
||||
#[inline(always)] static fn unit_w() -> vec4 { NumericVector4::unit_w() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<vec4>() }
|
||||
#[inline(always)] static fn dim() -> uint { 4 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<vec4>() }
|
||||
}
|
||||
|
||||
impl dvec4 {
|
||||
#[inline(always)] static pure fn new(x: f64, y: f64, z: f64, w: f64) -> dvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dvec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dvec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dvec4 { NumericVector::zero() }
|
||||
#[inline(always)] static fn new(x: f64, y: f64, z: f64, w: f64) -> dvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static fn from_value(v: f64) -> dvec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn identity() -> dvec4 { NumericVector::identity() }
|
||||
#[inline(always)] static fn zero() -> dvec4 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> dvec4 { NumericVector4::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> dvec4 { NumericVector4::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> dvec4 { NumericVector4::unit_z() }
|
||||
#[inline(always)] static pure fn unit_w() -> dvec4 { NumericVector4::unit_w() }
|
||||
#[inline(always)] static fn unit_x() -> dvec4 { NumericVector4::unit_x() }
|
||||
#[inline(always)] static fn unit_y() -> dvec4 { NumericVector4::unit_y() }
|
||||
#[inline(always)] static fn unit_z() -> dvec4 { NumericVector4::unit_z() }
|
||||
#[inline(always)] static fn unit_w() -> dvec4 { NumericVector4::unit_w() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dvec4>() }
|
||||
#[inline(always)] static fn dim() -> uint { 4 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<dvec4>() }
|
||||
}
|
||||
|
||||
|
||||
impl bvec4 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool, z: bool, w: bool) -> bvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: bool) -> bvec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn new(x: bool, y: bool, z: bool, w: bool) -> bvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static fn from_value(v: bool) -> bvec4 { Vector::from_value(v) }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<bvec4>() }
|
||||
#[inline(always)] static fn dim() -> uint { 4 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<bvec4>() }
|
||||
}
|
||||
|
||||
impl ivec4 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32, z: i32, w: i32) -> ivec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> ivec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> ivec4 { NumericVector::zero() }
|
||||
#[inline(always)] static fn new(x: i32, y: i32, z: i32, w: i32) -> ivec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static fn from_value(v: i32) -> ivec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn identity() -> ivec4 { NumericVector::identity() }
|
||||
#[inline(always)] static fn zero() -> ivec4 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> ivec4 { NumericVector4::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> ivec4 { NumericVector4::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> ivec4 { NumericVector4::unit_z() }
|
||||
#[inline(always)] static pure fn unit_w() -> ivec4 { NumericVector4::unit_w() }
|
||||
#[inline(always)] static fn unit_x() -> ivec4 { NumericVector4::unit_x() }
|
||||
#[inline(always)] static fn unit_y() -> ivec4 { NumericVector4::unit_y() }
|
||||
#[inline(always)] static fn unit_z() -> ivec4 { NumericVector4::unit_z() }
|
||||
#[inline(always)] static fn unit_w() -> ivec4 { NumericVector4::unit_w() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<ivec4>() }
|
||||
#[inline(always)] static fn dim() -> uint { 4 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<ivec4>() }
|
||||
}
|
||||
|
||||
impl uvec4 {
|
||||
#[inline(always)] static pure fn new(x: u32, y: u32, z: u32, w: u32) -> uvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: u32) -> uvec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> uvec4 { NumericVector::identity() }
|
||||
#[inline(always)] static pure fn zero() -> uvec4 { NumericVector::zero() }
|
||||
#[inline(always)] static fn new(x: u32, y: u32, z: u32, w: u32) -> uvec4 { Vector4::new(x, y, z, w) }
|
||||
#[inline(always)] static fn from_value(v: u32) -> uvec4 { Vector::from_value(v) }
|
||||
#[inline(always)] static fn identity() -> uvec4 { NumericVector::identity() }
|
||||
#[inline(always)] static fn zero() -> uvec4 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn unit_x() -> uvec4 { NumericVector4::unit_x() }
|
||||
#[inline(always)] static pure fn unit_y() -> uvec4 { NumericVector4::unit_y() }
|
||||
#[inline(always)] static pure fn unit_z() -> uvec4 { NumericVector4::unit_z() }
|
||||
#[inline(always)] static pure fn unit_w() -> uvec4 { NumericVector4::unit_w() }
|
||||
#[inline(always)] static fn unit_x() -> uvec4 { NumericVector4::unit_x() }
|
||||
#[inline(always)] static fn unit_y() -> uvec4 { NumericVector4::unit_y() }
|
||||
#[inline(always)] static fn unit_z() -> uvec4 { NumericVector4::unit_z() }
|
||||
#[inline(always)] static fn unit_w() -> uvec4 { NumericVector4::unit_w() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<uvec4>() }
|
||||
#[inline(always)] static fn dim() -> uint { 4 }
|
||||
#[inline(always)] static fn size_of() -> uint { size_of::<uvec4>() }
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue