Merge matrix traits, simplify gltypes, remove relational functions
Let's try to simplify this thing!
This commit is contained in:
parent
9595449b71
commit
668186a2e2
6 changed files with 318 additions and 910 deletions
|
@ -1,218 +0,0 @@
|
|||
/**
|
||||
* Vector Relational Functions
|
||||
*
|
||||
* This module corresponds to Section 8.7 of the [GLSL 4.30.6 specification]
|
||||
* (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf).
|
||||
*/
|
||||
|
||||
use core::cmp::{Eq, Ord};
|
||||
use vec::{Vector, Vec2, Vec3, Vec4};
|
||||
|
||||
pub trait RelVector<BVec> {
|
||||
pure fn less_than(&self, other: &self) -> BVec;
|
||||
pure fn less_than_equal(&self, other: &self) -> BVec;
|
||||
pure fn greater_than(&self, other: &self) -> BVec;
|
||||
pure fn greater_than_equal(&self, other: &self) -> BVec;
|
||||
pure fn equal(&self, other: &self) -> BVec;
|
||||
pure fn not_equal(&self, other: &self) -> BVec;
|
||||
}
|
||||
|
||||
#[inline(always)] pub pure fn less_than <T:RelVector<BV>, BV>(x: &T, y: &T) -> BV { x.less_than(y) }
|
||||
#[inline(always)] pub pure fn less_than_equal <T:RelVector<BV>, BV>(x: &T, y: &T) -> BV { x.less_than_equal(y) }
|
||||
#[inline(always)] pub pure fn greater_than <T:RelVector<BV>, BV>(x: &T, y: &T) -> BV { x.greater_than(y) }
|
||||
#[inline(always)] pub pure fn greater_than_equal<T:RelVector<BV>, BV>(x: &T, y: &T) -> BV { x.greater_than_equal(y) }
|
||||
#[inline(always)] pub pure fn equal <T:RelVector<BV>, BV>(x: &T, y: &T) -> BV { x.equal(y) }
|
||||
#[inline(always)] pub pure fn not_equal <T:RelVector<BV>, BV>(x: &T, y: &T) -> BV { x.not_equal(y) }
|
||||
|
||||
pub impl<T:Copy Ord Eq> Vec2<T>: RelVector<Vec2<bool>> {
|
||||
#[inline(always)]
|
||||
pure fn less_than(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] < other[0],
|
||||
self[1] < other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn less_than_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] <= other[0],
|
||||
self[1] <= other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] > other[0],
|
||||
self[1] > other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] >= other[0],
|
||||
self[1] >= other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] == other[0],
|
||||
self[1] == other[1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not_equal(&self, other: &Vec2<T>) -> Vec2<bool> {
|
||||
Vec2::new(self[0] != other[0],
|
||||
self[1] != other[1])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Ord Eq> Vec3<T>: RelVector<Vec3<bool>> {
|
||||
#[inline(always)]
|
||||
pure fn less_than(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::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> {
|
||||
Vec3::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> {
|
||||
Vec3::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> {
|
||||
Vec3::new(self[0] >= other[0],
|
||||
self[1] >= other[1],
|
||||
self[2] >= other[2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn equal(&self, other: &Vec3<T>) -> Vec3<bool> {
|
||||
Vec3::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> {
|
||||
Vec3::new(self[0] != other[0],
|
||||
self[1] != other[1],
|
||||
self[2] != other[2])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Ord Eq> Vec4<T>: RelVector<Vec4<bool>> {
|
||||
#[inline(always)]
|
||||
pure fn less_than(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] < other[0],
|
||||
self[1] < other[1],
|
||||
self[2] < other[2],
|
||||
self[3] < other[3])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn less_than_equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] <= other[0],
|
||||
self[1] <= other[1],
|
||||
self[2] <= other[2],
|
||||
self[3] <= other[3])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] > other[0],
|
||||
self[1] > other[1],
|
||||
self[2] > other[2],
|
||||
self[3] > other[3])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn greater_than_equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] >= other[0],
|
||||
self[1] >= other[1],
|
||||
self[2] >= other[2],
|
||||
self[3] >= other[3])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] == other[0],
|
||||
self[1] == other[1],
|
||||
self[2] == other[2],
|
||||
self[3] == other[3])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not_equal(&self, other: &Vec4<T>) -> Vec4<bool> {
|
||||
Vec4::new(self[0] != other[0],
|
||||
self[1] != other[1],
|
||||
self[2] != other[2],
|
||||
self[3] != other[3])
|
||||
}
|
||||
}
|
||||
|
||||
pub trait BooleanVector: Vector<bool> {
|
||||
pure fn any(&self) -> bool;
|
||||
pure fn all(&self) -> bool;
|
||||
pure fn not(&self) -> self;
|
||||
}
|
||||
|
||||
#[inline(always)] pub pure fn any<T:BooleanVector>(x: &T) -> bool { x.any() }
|
||||
#[inline(always)] pub pure fn all<T:BooleanVector>(x: &T) -> bool { x.all() }
|
||||
#[inline(always)] pub pure fn not<T:BooleanVector>(x: &T) -> T { x.not() }
|
||||
|
||||
pub impl Vec2<bool>: BooleanVector {
|
||||
#[inline(always)]
|
||||
pure fn any(&self) -> bool {
|
||||
self[0] || self[1]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn all(&self) -> bool {
|
||||
self[0] && self[1]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not(&self) -> Vec2<bool> {
|
||||
Vec2::new(!self[0], !self[1])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Vec3<bool>: BooleanVector {
|
||||
#[inline(always)]
|
||||
pure fn any(&self) -> bool {
|
||||
self[0] || self[1] || self[2]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn all(&self) -> bool {
|
||||
self[0] && self[1] && self[2]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not(&self) -> Vec3<bool> {
|
||||
Vec3::new(!self[0], !self[1], !self[2])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl Vec4<bool>: BooleanVector {
|
||||
#[inline(always)]
|
||||
pure fn any(&self) -> bool {
|
||||
self[0] || self[1] || self[2] || self[3]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn all(&self) -> bool {
|
||||
self[0] && self[1] && self[2] && self[3]
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn not(&self) -> Vec4<bool> {
|
||||
Vec4::new(!self[0], !self[1], !self[2], !self[3])
|
||||
}
|
||||
}
|
|
@ -1,72 +0,0 @@
|
|||
use vec::*;
|
||||
use relational::*;
|
||||
|
||||
#[test]
|
||||
fn test_boolv2() {
|
||||
let tf = Vec2::new(true, false);
|
||||
let ff = Vec2::new(false, false);
|
||||
let tt = Vec2::new(true, true);
|
||||
|
||||
assert tf.any() == true;
|
||||
assert tf.all() == false;
|
||||
assert tf.not() == Vec2::new(false, true);
|
||||
|
||||
assert ff.any() == false;
|
||||
assert ff.all() == false;
|
||||
assert ff.not() == Vec2::new(true, true);
|
||||
|
||||
assert tt.any() == true;
|
||||
assert tt.all() == true;
|
||||
assert tt.not() == Vec2::new(false, false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_boolv3() {
|
||||
let tft = Vec3::new(true, false, true);
|
||||
let fff = Vec3::new(false, false, false);
|
||||
let ttt = Vec3::new(true, true, true);
|
||||
|
||||
assert tft.any() == true;
|
||||
assert tft.all() == false;
|
||||
assert tft.not() == Vec3::new(false, true, false);
|
||||
|
||||
assert fff.any() == false;
|
||||
assert fff.all() == false;
|
||||
assert fff.not() == Vec3::new(true, true, true);
|
||||
|
||||
assert ttt.any() == true;
|
||||
assert ttt.all() == true;
|
||||
assert ttt.not() == Vec3::new(false, false, false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_boolv4() {
|
||||
let tftf = Vec4::new(true, false, true, false);
|
||||
let ffff = Vec4::new(false, false, false, false);
|
||||
let tttt = Vec4::new(true, true, true, true);
|
||||
|
||||
assert tftf.any() == true;
|
||||
assert tftf.all() == false;
|
||||
assert tftf.not() == Vec4::new(false, true, false, true);
|
||||
|
||||
assert ffff.any() == false;
|
||||
assert ffff.all() == false;
|
||||
assert ffff.not() == Vec4::new(true, true, true, true);
|
||||
|
||||
assert tttt.any() == true;
|
||||
assert tttt.all() == true;
|
||||
assert tttt.not() == Vec4::new(false, false, false, false);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_boolv_fns() {
|
||||
// let tf = Vec2::new(true, false);
|
||||
// let ftf = Vec3::new(false, true, false);
|
||||
// let tftf = Vec4::new(true, false, true, false);
|
||||
|
||||
// FIXME: These tests won't compile! D:
|
||||
|
||||
// assert any(&tf) == true;
|
||||
// assert all(&ftf) == false;
|
||||
// assert not(&tftf) == Vec4::new(false, true, false, true);
|
||||
}
|
259
src/gltypes.rs
259
src/gltypes.rs
|
@ -24,7 +24,7 @@ use core::sys::size_of;
|
|||
|
||||
use angle::{Angle, Radians, Degrees, Rotation, Euler};
|
||||
use color::color::{RGB, RGBA, HSV, HSVA};
|
||||
use mat::{NumericMatrix, NumericMatrixNxN, Mat2, Mat3, Mat4};
|
||||
use mat::{Matrix, Mat2, Mat3, Mat4};
|
||||
use vec::{Vector, NumericVector, Vec2, Vec3, Vec4};
|
||||
use quat::{/*Quaternion, */Quat};
|
||||
|
||||
|
@ -40,10 +40,6 @@ pub type dvec2 = Vec2<f64>; /// a two-component double-precision flo
|
|||
pub type dvec3 = Vec3<f64>; /// a three-component double-precision floating-point vector
|
||||
pub type dvec4 = Vec4<f64>; /// a four-component double-precision floating-point vector
|
||||
|
||||
pub type bvec2 = Vec2<bool>; /// a two-component Boolean vector
|
||||
pub type bvec3 = Vec3<bool>; /// a three-component Boolean vector
|
||||
pub type bvec4 = Vec4<bool>; /// a four-component Boolean vector
|
||||
|
||||
pub type ivec2 = Vec2<i32>; /// a two-component signed integer vector
|
||||
pub type ivec3 = Vec3<i32>; /// a three-component signed integer vector
|
||||
pub type ivec4 = Vec4<i32>; /// a four-component signed integer vector
|
||||
|
@ -117,37 +113,6 @@ pub impl dvec4 {
|
|||
}
|
||||
|
||||
|
||||
pub impl bvec2 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool) -> bvec2 { Vec2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: bool) -> bvec2 { Vector::from_value(v) }
|
||||
// #[inline(always)] static pure fn identity() -> bvec2 { NumericVector::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> bvec2 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 2 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<bvec2>() }
|
||||
}
|
||||
|
||||
pub impl bvec3 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool, z: bool) -> bvec3 { Vec3::new(x, y, z) }
|
||||
#[inline(always)] static pure fn from_value(v: bool) -> bvec3 { Vector::from_value(v) }
|
||||
// #[inline(always)] static pure fn identity() -> bvec3 { NumericVector::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> bvec3 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 3 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<bvec3>() }
|
||||
}
|
||||
|
||||
pub impl bvec4 {
|
||||
#[inline(always)] static pure fn new(x: bool, y: bool, z: bool, w: bool) -> bvec4 { Vec4::new(x, y, z, w) }
|
||||
#[inline(always)] static pure fn from_value(v: bool) -> bvec4 { Vector::from_value(v) }
|
||||
// #[inline(always)] static pure fn identity() -> bvec4 { NumericVector::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> bvec4 { NumericVector::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { 4 }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<bvec4>() }
|
||||
}
|
||||
|
||||
|
||||
pub impl ivec2 {
|
||||
#[inline(always)] static pure fn new(x: i32, y: i32) -> ivec2 { Vec2::new(x, y) }
|
||||
#[inline(always)] static pure fn from_value(v: i32) -> ivec2 { Vector::from_value(v) }
|
||||
|
@ -213,248 +178,142 @@ pub impl uvec4 {
|
|||
// Matrix aliases, corresponding to Section 4.1.6 of the [GLSL 4.30.6 specification]
|
||||
// (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf).
|
||||
|
||||
pub type mat2 = mat2x2; /// a 2×2 single-precision floating-point matrix
|
||||
pub type mat3 = mat3x3; /// a 3×3 single-precision floating-point matrix
|
||||
pub type mat4 = mat4x4; /// a 4×4 single-precision floating-point matrix
|
||||
pub type mat2x2 = Mat2<f32>; /// same as a `mat2`
|
||||
// pub type mat2x3 = /// a single-precision floating-point matrix with 2 columns and 3 rows
|
||||
// pub type mat2x4 = /// a single-precision floating-point matrix with 2 columns and 4 rows
|
||||
// pub type mat3x2 = /// a single-precision floating-point matrix with 3 columns and 2 rows
|
||||
pub type mat3x3 = Mat3<f32>; /// same as a `mat3`
|
||||
// pub type mat3x4 = /// a single-precision floating-point matrix with 3 columns and 4 rows
|
||||
// pub type mat4x2 = /// a single-precision floating-point matrix with 4 columns and 2 rows
|
||||
// pub type mat4x3 = /// a single-precision floating-point matrix with 4 columns and 3 rows
|
||||
pub type mat4x4 = Mat4<f32>; /// same as a `mat4`
|
||||
pub type mat2 = Mat2<f32>; /// a 2×2 single-precision floating-point matrix
|
||||
pub type mat3 = Mat3<f32>; /// a 3×3 single-precision floating-point matrix
|
||||
pub type mat4 = Mat4<f32>; /// a 4×4 single-precision floating-point matrix
|
||||
|
||||
pub type dmat2 = dmat2x2; /// a 2×2 double-precision floating-point matrix
|
||||
pub type dmat3 = dmat3x3; /// a 3×3 double-precision floating-point matrix
|
||||
pub type dmat4 = dmat4x4; /// a 4×4 double-precision floating-point matrix
|
||||
pub type dmat2x2 = Mat2<f64>; /// same as a `dmat2`
|
||||
// pub type dmat2x3 = /// a double-precision floating-point matrix with 2 columns and 3 rows
|
||||
// pub type dmat2x4 = /// a double-precision floating-point matrix with 2 columns and 4 rows
|
||||
// pub type dmat3x2 = /// a double-precision floating-point matrix with 3 columns and 2 rows
|
||||
pub type dmat3x3 = Mat3<f64>; /// same as a `dmat3`
|
||||
// pub type dmat3x4 = /// a double-precision floating-point matrix with 3 columns and 4 rows
|
||||
// pub type dmat4x2 = /// a double-precision floating-point matrix with 4 columns and 2 rows
|
||||
// pub type dmat4x3 = /// a double-precision floating-point matrix with 4 columns and 3 rows
|
||||
pub type dmat4x4 = Mat4<f64>; /// same as a `dmat4`
|
||||
pub type dmat2 = Mat2<f64>; /// a 2×2 double-precision floating-point matrix
|
||||
pub type dmat3 = Mat3<f64>; /// a 3×3 double-precision floating-point matrix
|
||||
pub type dmat4 = Mat4<f64>; /// a 4×4 double-precision floating-point matrix
|
||||
|
||||
|
||||
// Matrix method wrappers
|
||||
|
||||
pub impl mat2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c1r0: f32, c1r1: f32)
|
||||
-> mat2 { mat2x2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
-> mat2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec2, c1: vec2)
|
||||
-> mat2 { mat2x2::from_cols(move c0, move c1) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat2 { mat2x2::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> mat2 { mat2x2::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat2 { mat2x2::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { mat2x2::dim() }
|
||||
#[inline(always)] static pure fn rows() -> uint { mat2x2::rows() }
|
||||
#[inline(always)] static pure fn cols() -> uint { mat2x2::cols() }
|
||||
#[inline(always)] static pure fn size_of() -> uint { mat2x2::size_of() }
|
||||
}
|
||||
|
||||
pub impl mat3 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c1r0: f32, c1r1: f32, c1r2: f32, c2r0: f32, c2r1: f32, c2r2: f32)
|
||||
-> mat3 { mat3x3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec3, c1: vec3, c2: vec3)
|
||||
-> mat3 { mat3x3::from_cols(move c0, move c1, move c2) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat3 { mat3x3::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> mat3 { mat3x3::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat3 { mat3x3::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { mat3x3::dim() }
|
||||
#[inline(always)] static pure fn rows() -> uint { mat3x3::rows() }
|
||||
#[inline(always)] static pure fn cols() -> uint { mat3x3::cols() }
|
||||
#[inline(always)] static pure fn size_of() -> uint { mat3x3::size_of() }
|
||||
}
|
||||
|
||||
pub impl mat4 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c0r3: f32, c1r0: f32, c1r1: f32, c1r2: f32, c1r3: f32, c2r0: f32, c2r1: f32, c2r2: f32, c2r3: f32, c3r0: f32, c3r1: f32, c3r2: f32, c3r3: f32)
|
||||
-> mat4 { mat4x4::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)
|
||||
-> mat4 { mat4x4::from_cols(move c0, move c1, move c2, move c3) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat4 { mat4x4::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> mat4 { mat4x4::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat4 { mat4x4::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { mat4x4::dim() }
|
||||
#[inline(always)] static pure fn rows() -> uint { mat4x4::rows() }
|
||||
#[inline(always)] static pure fn cols() -> uint { mat4x4::cols() }
|
||||
#[inline(always)] static pure fn size_of() -> uint { mat4x4::size_of() }
|
||||
}
|
||||
|
||||
pub impl mat2x2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c1r0: f32, c1r1: f32)
|
||||
-> mat2x2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec2, c1: vec2)
|
||||
-> mat2x2 { Mat2::from_cols(move c0, move c1) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat2x2 { Mat2::from_value(v) }
|
||||
-> mat2 { Mat2::from_cols(move c0, move c1) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat2 { Mat2::from_value(v) }
|
||||
|
||||
// FIXME: there's something wrong with static functions here!
|
||||
// #[inline(always)] static pure fn identity() -> mat2x2 { NumericMatrixNxN::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> mat2x2 { NumericMatrix::zero() }
|
||||
// #[inline(always)] static pure fn identity() -> mat2 { NumericMatrixNxN::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> mat2 { NumericMatrix::zero() }
|
||||
|
||||
// FIXME: An interim solution to the issues with static functions
|
||||
#[inline(always)] static pure fn identity() -> mat2x2 { Mat2::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat2x2 { Mat2::zero() }
|
||||
#[inline(always)] static pure fn identity() -> mat2 { Mat2::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat2 { Mat2::zero() }
|
||||
|
||||
#[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::<mat2x2>() }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat2>() }
|
||||
}
|
||||
|
||||
pub impl mat3x3 {
|
||||
pub impl mat3 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c1r0: f32, c1r1: f32, c1r2: f32, c2r0: f32, c2r1: f32, c2r2: f32)
|
||||
-> mat3x3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
-> mat3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
#[inline(always)] static pure fn from_cols(c0: vec3, c1: vec3, c2: vec3)
|
||||
-> mat3x3 { Mat3::from_cols(move c0, move c1, move c2) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat3x3 { Mat3::from_value(v) }
|
||||
-> mat3 { Mat3::from_cols(move c0, move c1, move c2) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat3 { Mat3::from_value(v) }
|
||||
|
||||
// FIXME: there's something wrong with static functions here!
|
||||
// #[inline(always)] static pure fn identity() -> mat3x3 { NumericMatrixNxN::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> mat3x3 { NumericMatrix::zero() }
|
||||
// #[inline(always)] static pure fn identity() -> mat3 { NumericMatrixNxN::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> mat3 { NumericMatrix::zero() }
|
||||
|
||||
// FIXME: An interim solution to the issues with static functions
|
||||
#[inline(always)] static pure fn identity() -> mat3x3 { Mat3::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat3x3 { Mat3::zero() }
|
||||
#[inline(always)] static pure fn identity() -> mat3 { Mat3::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat3 { Mat3::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::<mat3x3>() }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat3>() }
|
||||
}
|
||||
|
||||
pub impl mat4x4 {
|
||||
pub impl mat4 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c0r2: f32, c0r3: f32, c1r0: f32, c1r1: f32, c1r2: f32, c1r3: f32, c2r0: f32, c2r1: f32, c2r2: f32, c2r3: f32, c3r0: f32, c3r1: f32, c3r2: f32, c3r3: f32)
|
||||
-> mat4x4 { Mat4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
||||
-> mat4 { Mat4::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)
|
||||
-> mat4x4 { Mat4::from_cols(move c0, move c1, move c2, move c3) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat4x4 { Mat4::from_value(v) }
|
||||
-> mat4 { Mat4::from_cols(move c0, move c1, move c2, move c3) }
|
||||
#[inline(always)] static pure fn from_value(v: f32) -> mat4 { Mat4::from_value(v) }
|
||||
|
||||
// FIXME: there's something wrong with static functions here!
|
||||
// #[inline(always)] static pure fn identity() -> mat4x4 { NumericMatrixNxN::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> mat4x4 { NumericMatrix::zero() }
|
||||
// #[inline(always)] static pure fn identity() -> mat4 { NumericMatrixNxN::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> mat4 { NumericMatrix::zero() }
|
||||
|
||||
// FIXME: An interim solution to the issues with static functions
|
||||
#[inline(always)] static pure fn identity() -> mat4x4 { Mat4::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat4x4 { Mat4::zero() }
|
||||
#[inline(always)] static pure fn identity() -> mat4 { Mat4::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat4 { Mat4::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::<mat4x4>() }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<mat4>() }
|
||||
}
|
||||
|
||||
|
||||
pub impl dmat2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c1r0: f64, c1r1: f64)
|
||||
-> dmat2 { dmat2x2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
-> dmat2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec2, c1: dvec2)
|
||||
-> dmat2 { dmat2x2::from_cols(move c0, move c1) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat2 { dmat2x2::from_value(v) }
|
||||
#[inline(always)] static pure fn identity() -> dmat2 { dmat2x2::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat2 { dmat2x2::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { dmat2x2::dim() }
|
||||
#[inline(always)] static pure fn rows() -> uint { dmat2x2::rows() }
|
||||
#[inline(always)] static pure fn cols() -> uint { dmat2x2::cols() }
|
||||
#[inline(always)] static pure fn size_of() -> uint { dmat2x2::size_of() }
|
||||
}
|
||||
|
||||
pub impl dmat3 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c1r0: f64, c1r1: f64, c1r2: f64, c2r0: f64, c2r1: f64, c2r2: f64)
|
||||
-> dmat3 { dmat3x3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec3, c1: dvec3, c2: dvec3)
|
||||
-> dmat3 { dmat3x3::from_cols(move c0, move c1, move c2) }
|
||||
#[inline(always)] static pure fn identity() -> dmat3 { dmat3x3::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat3 { dmat3x3::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { dmat3x3::dim() }
|
||||
#[inline(always)] static pure fn rows() -> uint { dmat3x3::rows() }
|
||||
#[inline(always)] static pure fn cols() -> uint { dmat3x3::cols() }
|
||||
#[inline(always)] static pure fn size_of() -> uint { dmat3x3::size_of() }
|
||||
}
|
||||
|
||||
pub impl dmat4 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c0r3: f64, c1r0: f64, c1r1: f64, c1r2: f64, c1r3: f64, c2r0: f64, c2r1: f64, c2r2: f64, c2r3: f64, c3r0: f64, c3r1: f64, c3r2: f64, c3r3: f64)
|
||||
-> dmat4 { dmat4x4::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)
|
||||
-> dmat4 { dmat4x4::from_cols(move c0, move c1, move c2, move c3) }
|
||||
#[inline(always)] static pure fn identity() -> dmat4 { dmat4x4::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat4 { dmat4x4::zero() }
|
||||
|
||||
#[inline(always)] static pure fn dim() -> uint { dmat4x4::dim() }
|
||||
#[inline(always)] static pure fn rows() -> uint { dmat4x4::rows() }
|
||||
#[inline(always)] static pure fn cols() -> uint { dmat4x4::cols() }
|
||||
#[inline(always)] static pure fn size_of() -> uint { dmat4x4::size_of() }
|
||||
}
|
||||
|
||||
pub impl dmat2x2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c1r0: f64, c1r1: f64)
|
||||
-> dmat2x2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec2, c1: dvec2)
|
||||
-> dmat2x2 { Mat2::from_cols(move c0, move c1) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat2x2 { Mat2::from_value(v) }
|
||||
-> dmat2 { Mat2::from_cols(move c0, move c1) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat2 { Mat2::from_value(v) }
|
||||
|
||||
// FIXME: there's something wrong with static functions here!
|
||||
// #[inline(always)] static pure fn identity() -> dmat2x2 { NumericMatrixNxN::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> dmat2x2 { NumericMatrix::zero() }
|
||||
// #[inline(always)] static pure fn identity() -> dmat2 { NumericMatrixNxN::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> dmat2 { NumericMatrix::zero() }
|
||||
|
||||
// FIXME: An interim solution to the issues with static functions
|
||||
#[inline(always)] static pure fn identity() -> dmat2x2 { Mat2::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat2x2 { Mat2::zero() }
|
||||
#[inline(always)] static pure fn identity() -> dmat2 { Mat2::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat2 { Mat2::zero() }
|
||||
|
||||
#[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::<dmat2x2>() }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat2>() }
|
||||
}
|
||||
|
||||
pub impl dmat3x3 {
|
||||
pub impl dmat3 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c1r0: f64, c1r1: f64, c1r2: f64, c2r0: f64, c2r1: f64, c2r2: f64)
|
||||
-> dmat3x3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
-> dmat3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||
#[inline(always)] static pure fn from_cols(c0: dvec3, c1: dvec3, c2: dvec3)
|
||||
-> dmat3x3 { Mat3::from_cols(move c0, move c1, move c2) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat3x3 { Mat3::from_value(v) }
|
||||
-> dmat3 { Mat3::from_cols(move c0, move c1, move c2) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat3 { Mat3::from_value(v) }
|
||||
|
||||
// FIXME: there's something wrong with static functions here!
|
||||
// #[inline(always)] static pure fn identity() -> dmat3x3 { NumericMatrixNxN::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> dmat3x3 { NumericMatrix::zero() }
|
||||
// #[inline(always)] static pure fn identity() -> dmat3 { NumericMatrixNxN::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> dmat3 { NumericMatrix::zero() }
|
||||
|
||||
// FIXME: An interim solution to the issues with static functions
|
||||
#[inline(always)] static pure fn identity() -> dmat3x3 { Mat3::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat3x3 { Mat3::zero() }
|
||||
#[inline(always)] static pure fn identity() -> dmat3 { Mat3::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat3 { Mat3::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::<dmat3x3>() }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat3>() }
|
||||
}
|
||||
|
||||
pub impl dmat4x4 {
|
||||
pub impl dmat4 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c0r2: f64, c0r3: f64, c1r0: f64, c1r1: f64, c1r2: f64, c1r3: f64, c2r0: f64, c2r1: f64, c2r2: f64, c2r3: f64, c3r0: f64, c3r1: f64, c3r2: f64, c3r3: f64)
|
||||
-> dmat4x4 { Mat4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
||||
-> dmat4 { Mat4::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)
|
||||
-> dmat4x4 { Mat4::from_cols(move c0, move c1, move c2, move c3) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat4x4 { Mat4::from_value(v) }
|
||||
-> dmat4 { Mat4::from_cols(move c0, move c1, move c2, move c3) }
|
||||
#[inline(always)] static pure fn from_value(v: f64) -> dmat4 { Mat4::from_value(v) }
|
||||
|
||||
// FIXME: there's something wrong with static functions here!
|
||||
// #[inline(always)] static pure fn identity() -> dmat4x4 { NumericMatrixNxN::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> dmat4x4 { NumericMatrix::zero() }
|
||||
// #[inline(always)] static pure fn identity() -> dmat4 { NumericMatrixNxN::identity() }
|
||||
// #[inline(always)] static pure fn zero() -> dmat4 { NumericMatrix::zero() }
|
||||
|
||||
// FIXME: An interim solution to the issues with static functions
|
||||
#[inline(always)] static pure fn identity() -> dmat4x4 { Mat4::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat4x4 { Mat4::zero() }
|
||||
#[inline(always)] static pure fn identity() -> dmat4 { Mat4::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat4 { Mat4::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::<dmat4x4>() }
|
||||
#[inline(always)] static pure fn size_of() -> uint { size_of::<dmat4>() }
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -53,8 +53,6 @@ pub mod funs {
|
|||
pub mod exponential;
|
||||
#[path = "funs/projection.rs"]
|
||||
pub mod projection;
|
||||
#[path = "funs/relational.rs"]
|
||||
pub mod relational;
|
||||
#[path = "funs/triganomic.rs"]
|
||||
pub mod triganomic;
|
||||
|
||||
|
@ -62,8 +60,6 @@ pub mod funs {
|
|||
mod test {
|
||||
#[path = "funs/test/test_common.rs"]
|
||||
mod test_common;
|
||||
#[path = "funs/test/test_relational.rs"]
|
||||
mod test_relational;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
469
src/mat.rs
469
src/mat.rs
|
@ -14,89 +14,20 @@ use num::default_eq::DefaultEq;
|
|||
use quat::{Quat, ToQuat};
|
||||
use vec::{NumericVector, Vec2, Vec3, Vec4};
|
||||
|
||||
///
|
||||
/// The base Matrix trait
|
||||
///
|
||||
pub trait Matrix<T, Col, Row>: Dimensional<Col>, ToPtr<T>, Eq, DefaultEq {
|
||||
static pure fn rows() -> uint;
|
||||
static pure fn cols() -> uint;
|
||||
/**
|
||||
* An N x N Matrix
|
||||
*/
|
||||
pub trait Matrix<T,V>: Dimensional<V>, ToPtr<T>, Eq, DefaultEq, Neg<self> {
|
||||
pure fn col(&self, i: uint) -> V;
|
||||
pure fn row(&self, i: uint) -> V;
|
||||
|
||||
pure fn col(&self, i: uint) -> Col;
|
||||
pure fn row(&self, i: uint) -> Row;
|
||||
}
|
||||
|
||||
/// A 2 x N matrix
|
||||
pub trait Matrix2<T, Col, Row>: Matrix<T, Col, Row> {
|
||||
// /// Construct the matrix from two column vectors
|
||||
// static pure fn from_cols(c0: Col, c1: Col) -> self;
|
||||
}
|
||||
|
||||
/// A 3 x N matrix
|
||||
pub trait Matrix3<T, Col, Row>: Matrix<T, Col, Row> {
|
||||
// /// Construct the matrix from three column vectors
|
||||
// static pure fn from_cols(c0: Col, c1: Col, c2: Col) -> self;
|
||||
}
|
||||
|
||||
/// A 4 x N matrix
|
||||
pub trait Matrix4<T, Col, Row>: Matrix<T, Col, Row> {
|
||||
// /// Construct the matrix from four column vectors
|
||||
// static pure fn from_cols(c0: Col, c1: Col, c2: Col, c3: Col) -> self;
|
||||
}
|
||||
|
||||
///
|
||||
/// A square matrix
|
||||
///
|
||||
pub trait MatrixNxN<T, ColRow>: Matrix<T, ColRow, ColRow> {
|
||||
pure fn is_symmetric(&self) -> bool;
|
||||
}
|
||||
|
||||
/// A 2 x 2 square matrix
|
||||
pub trait Matrix2x2<T, ColRow>: MatrixNxN<T, ColRow>,
|
||||
Matrix2<T, ColRow, ColRow> {
|
||||
// /// Construct the matrix from a column major series of elements
|
||||
// static pure fn new(c0r0: T, c0r1: T,
|
||||
// c1r0: T, c1r1: T) -> self;
|
||||
}
|
||||
|
||||
/// A 3 x 3 square matrix
|
||||
pub trait Matrix3x3<T, ColRow>: MatrixNxN<T, ColRow>,
|
||||
Matrix3<T, ColRow, ColRow> {
|
||||
// /// Construct the matrix from a column major series of elements
|
||||
// static pure fn new(c0r0: T, c0r1: T, c0r2: T,
|
||||
// c1r0: T, c1r1: T, c1r2: T,
|
||||
// c2r0: T, c2r1: T, c2r2: T) -> self;
|
||||
}
|
||||
|
||||
/// A 4 x 4 square matrix
|
||||
pub trait Matrix4x4<T, ColRow>: MatrixNxN<T, ColRow>,
|
||||
Matrix4<T, ColRow, ColRow> {
|
||||
// /// Construct the matrix from a column major series of elements
|
||||
// static pure 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;
|
||||
}
|
||||
|
||||
///
|
||||
/// A matrix with numeric elements
|
||||
///
|
||||
pub trait NumericMatrix<T, Col, Row>: Matrix<T, Col, Row>, Neg<self> {
|
||||
static pure fn identity() -> self;
|
||||
static pure fn zero() -> self;
|
||||
|
||||
pure fn mul_t(&self, value: T) -> self;
|
||||
pure fn mul_v(&self, other: &Col) -> Col;
|
||||
pure fn mul_v(&self, other: &V) -> V;
|
||||
pure fn add_m(&self, other: &self) -> self;
|
||||
pure fn sub_m(&self, other: &self) -> self;
|
||||
}
|
||||
|
||||
///
|
||||
/// A square matrix with numeric elements
|
||||
///
|
||||
pub trait NumericMatrixNxN<T, ColRow>: MatrixNxN<T, ColRow>,
|
||||
NumericMatrix<T, ColRow, ColRow> {
|
||||
static pure fn identity() -> self;
|
||||
|
||||
// static pure fn from_value(value: T) -> self;
|
||||
|
||||
pure fn mul_m(&self, other: &self) -> self;
|
||||
pure fn dot(&self, other: &self) -> T;
|
||||
|
@ -110,26 +41,23 @@ pub trait NumericMatrixNxN<T, ColRow>: MatrixNxN<T, ColRow>,
|
|||
pure fn is_identity(&self) -> bool;
|
||||
pure fn is_diagonal(&self) -> bool;
|
||||
pure fn is_rotated(&self) -> bool;
|
||||
pure fn is_symmetric(&self) -> bool;
|
||||
pure fn is_invertible(&self) -> bool;
|
||||
}
|
||||
|
||||
/// A 2 x 2 square matrix with numeric elements
|
||||
pub trait NumericMatrix2x2<T, ColRow2>: Matrix2x2<T, ColRow2>,
|
||||
NumericMatrixNxN<T, ColRow2> {
|
||||
|
||||
pub trait Matrix2<T,V>: Matrix<T,V> {
|
||||
pure fn to_mat3(&self) -> Mat3<T>;
|
||||
pure fn to_mat4(&self) -> Mat4<T>;
|
||||
}
|
||||
|
||||
/// A 3 x 3 square matrix with numeric elements
|
||||
pub trait NumericMatrix3x3<T, ColRow3>: Matrix3x3<T, ColRow3>,
|
||||
NumericMatrixNxN<T, ColRow3> {
|
||||
pub trait Matrix3<T,V>: Matrix<T,V> {
|
||||
pure fn to_mat4(&self) -> Mat4<T>;
|
||||
}
|
||||
|
||||
/// A 4 x 4 square matrix with numeric elements
|
||||
pub trait NumericMatrix4x4<T, ColRow4>: Matrix4x4<T, ColRow4>,
|
||||
NumericMatrixNxN<T, ColRow4> {
|
||||
pub trait Matrix4<T,V>: Matrix<T,V> {
|
||||
}
|
||||
|
||||
|
||||
|
@ -137,9 +65,9 @@ pub trait NumericMatrix4x4<T, ColRow4>: Matrix4x4<T, ColRow4>,
|
|||
|
||||
|
||||
|
||||
//
|
||||
// Mat2: A 2x2, column major matrix
|
||||
//
|
||||
/**
|
||||
* A 2 x 2 column major matrix
|
||||
*/
|
||||
pub struct Mat2<T> { x: Vec2<T>, y: Vec2<T> }
|
||||
|
||||
pub impl<T:Copy NumCast> Mat2<T> {
|
||||
|
@ -181,13 +109,7 @@ pub impl<T:Copy NumCast> Mat2<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat2<T>: Matrix<T, Vec2<T>, Vec2<T>> {
|
||||
#[inline(always)]
|
||||
static pure fn cols() -> uint { 2 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn rows() -> uint { 2 }
|
||||
|
||||
pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: Matrix<T, Vec2<T>> {
|
||||
#[inline(always)]
|
||||
pure fn col(&self, i: uint) -> Vec2<T> { self[i] }
|
||||
|
||||
|
@ -196,42 +118,15 @@ pub impl<T:Copy> Mat2<T>: Matrix<T, Vec2<T>, Vec2<T>> {
|
|||
Vec2::new(self[0][i],
|
||||
self[1][i])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat2<T>: Dimensional<Vec2<T>> {
|
||||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 2 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Mat2<T>>() }
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat2<T>: Index<uint, Vec2<T>> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> Vec2<T> {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Mat2<T>, *Vec2<T>>(
|
||||
to_unsafe_ptr(&self)), 2) |slice| { slice[i] }
|
||||
}
|
||||
static pure fn identity() -> Mat2<T> {
|
||||
let _0 = cast(0);
|
||||
let _1 = cast(1);
|
||||
Mat2::new(_1, _0,
|
||||
_0, _1)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat2<T>: ToPtr<T> {
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
self[0].to_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy DefaultEq> Mat2<T>: MatrixNxN<T, Vec2<T>> {
|
||||
#[inline(always)]
|
||||
pure fn is_symmetric(&self) -> bool {
|
||||
self[0][1].default_eq(&self[1][0]) &&
|
||||
self[1][0].default_eq(&self[0][1])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrix<T, Vec2<T>, Vec2<T>> {
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Mat2<T> {
|
||||
let _0 = cast(0);
|
||||
|
@ -262,23 +157,6 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrix<T, Vec2<T>, Vec2<T
|
|||
Mat2::from_cols(self[0].sub_v(&other[0]),
|
||||
self[1].sub_v(&other[1]))
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast> Mat2<T>: Neg<Mat2<T>> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Mat2<T> {
|
||||
Mat2::from_cols(-self[0], -self[1])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrixNxN<T, Vec2<T>> {
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Mat2<T> {
|
||||
let _0 = cast(0);
|
||||
let _1 = cast(1);
|
||||
Mat2::new(_1, _0,
|
||||
_0, _1)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_m(&self, other: &Mat2<T>) -> Mat2<T> {
|
||||
|
@ -318,7 +196,7 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrixNxN<T, Vec2<T>> {
|
|||
|
||||
#[inline(always)]
|
||||
pure fn is_identity(&self) -> bool {
|
||||
// self.default_eq(&NumericMatrixNxN::identity()) // FIXME: there's something wrong with static functions here!
|
||||
// self.default_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here!
|
||||
self.default_eq(&Mat2::identity())
|
||||
}
|
||||
|
||||
|
@ -331,9 +209,15 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrixNxN<T, Vec2<T>> {
|
|||
|
||||
#[inline(always)]
|
||||
pure fn is_rotated(&self) -> bool {
|
||||
// !self.default_eq(&NumericMatrixNxN::identity()) // FIXME: there's something wrong with static functions here!
|
||||
// !self.default_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here!
|
||||
!self.default_eq(&Mat2::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_symmetric(&self) -> bool {
|
||||
self[0][1].default_eq(&self[1][0]) &&
|
||||
self[1][0].default_eq(&self[0][1])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_invertible(&self) -> bool {
|
||||
|
@ -342,7 +226,7 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrixNxN<T, Vec2<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy NumCast> Mat2<T>: NumericMatrix2x2<T, Vec2<T>> {
|
||||
pub impl<T:Copy NumCast> Mat2<T>: Matrix2<T, Vec2<T>> {
|
||||
#[inline(always)]
|
||||
pure fn to_mat3(&self) -> Mat3<T> {
|
||||
Mat3::from_Mat2(self)
|
||||
|
@ -354,6 +238,38 @@ pub impl<T:Copy NumCast> Mat2<T>: NumericMatrix2x2<T, Vec2<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat2<T>: Dimensional<Vec2<T>> {
|
||||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 2 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Mat2<T>>() }
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat2<T>: Index<uint, Vec2<T>> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> Vec2<T> {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Mat2<T>, *Vec2<T>>(
|
||||
to_unsafe_ptr(&self)), 2) |slice| { slice[i] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat2<T>: ToPtr<T> {
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
self[0].to_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast> Mat2<T>: Neg<Mat2<T>> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Mat2<T> {
|
||||
Mat2::from_cols(-self[0], -self[1])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy DefaultEq> Mat2<T>: Eq {
|
||||
#[inline(always)]
|
||||
pure fn eq(&self, other: &Mat2<T>) -> bool {
|
||||
|
@ -388,9 +304,9 @@ pub impl<T:Copy DefaultEq> Mat2<T>: DefaultEq {
|
|||
|
||||
|
||||
|
||||
//
|
||||
// Mat3: A 3x3, column major matrix
|
||||
//
|
||||
/**
|
||||
* A 3 x 3 column major matrix
|
||||
*/
|
||||
pub struct Mat3<T> { x: Vec3<T>, y: Vec3<T>, z: Vec3<T> }
|
||||
|
||||
pub impl<T:Copy NumCast> Mat3<T> {
|
||||
|
@ -447,13 +363,7 @@ pub impl<T:Copy NumCast> Mat3<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat3<T>: Matrix<T, Vec3<T>, Vec3<T>> {
|
||||
#[inline(always)]
|
||||
static pure fn cols() -> uint { 3 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn rows() -> uint { 3 }
|
||||
|
||||
pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: Matrix<T, Vec3<T>> {
|
||||
#[inline(always)]
|
||||
pure fn col(&self, i: uint) -> Vec3<T> { self[i] }
|
||||
|
||||
|
@ -463,48 +373,16 @@ pub impl<T:Copy> Mat3<T>: Matrix<T, Vec3<T>, Vec3<T>> {
|
|||
self[1][i],
|
||||
self[2][i])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat3<T>: Dimensional<Vec3<T>> {
|
||||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 3 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Mat3<T>>() }
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat3<T>: Index<uint, Vec3<T>> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> Vec3<T> {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Mat3<T>, *Vec3<T>>(
|
||||
to_unsafe_ptr(&self)), 3) |slice| { slice[i] }
|
||||
}
|
||||
static pure fn identity() -> Mat3<T> {
|
||||
let _0 = cast(0);
|
||||
let _1 = cast(1);
|
||||
Mat3::new(_1, _0, _0,
|
||||
_0, _1, _0,
|
||||
_0, _0, _1)
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat3<T>: ToPtr<T> {
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
self[0].to_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy DefaultEq> Mat3<T>: MatrixNxN<T, Vec3<T>> {
|
||||
#[inline(always)]
|
||||
pure fn is_symmetric(&self) -> bool {
|
||||
self[0][1].default_eq(&self[1][0]) &&
|
||||
self[0][2].default_eq(&self[2][0]) &&
|
||||
|
||||
self[1][0].default_eq(&self[0][1]) &&
|
||||
self[1][2].default_eq(&self[2][1]) &&
|
||||
|
||||
self[2][0].default_eq(&self[0][2]) &&
|
||||
self[2][1].default_eq(&self[1][2])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrix<T, Vec3<T>, Vec3<T>> {
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Mat3<T> {
|
||||
let _0 = cast(0);
|
||||
|
@ -540,24 +418,6 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrix<T, Vec3<T>, Vec3<T
|
|||
self[1].sub_v(&other[1]),
|
||||
self[2].sub_v(&other[2]))
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast> Mat3<T>: Neg<Mat3<T>> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Mat3<T> {
|
||||
Mat3::from_cols(-self[0], -self[1], -self[2])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrixNxN<T, Vec3<T>> {
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Mat3<T> {
|
||||
let _0 = cast(0);
|
||||
let _1 = cast(1);
|
||||
Mat3::new(_1, _0, _0,
|
||||
_0, _1, _0,
|
||||
_0, _0, _1)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mul_m(&self, other: &Mat3<T>) -> Mat3<T> {
|
||||
|
@ -601,7 +461,7 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrixNxN<T, Vec3<T>> {
|
|||
|
||||
#[inline(always)]
|
||||
pure fn is_identity(&self) -> bool {
|
||||
// self.default_eq(&NumericMatrixNxN::identity()) // FIXME: there's something wrong with static functions here!
|
||||
// self.default_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here!
|
||||
self.default_eq(&Mat3::identity())
|
||||
}
|
||||
|
||||
|
@ -620,9 +480,21 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrixNxN<T, Vec3<T>> {
|
|||
|
||||
#[inline(always)]
|
||||
pure fn is_rotated(&self) -> bool {
|
||||
// !self.default_eq(&NumericMatrixNxN::identity()) // FIXME: there's something wrong with static functions here!
|
||||
// !self.default_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here!
|
||||
!self.default_eq(&Mat3::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_symmetric(&self) -> bool {
|
||||
self[0][1].default_eq(&self[1][0]) &&
|
||||
self[0][2].default_eq(&self[2][0]) &&
|
||||
|
||||
self[1][0].default_eq(&self[0][1]) &&
|
||||
self[1][2].default_eq(&self[2][1]) &&
|
||||
|
||||
self[2][0].default_eq(&self[0][2]) &&
|
||||
self[2][1].default_eq(&self[1][2])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_invertible(&self) -> bool {
|
||||
|
@ -631,7 +503,7 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrixNxN<T, Vec3<T>> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy NumCast> Mat3<T>: NumericMatrix3x3<T, Vec3<T>> {
|
||||
pub impl<T:Copy NumCast> Mat3<T>: Matrix3<T, Vec3<T>> {
|
||||
#[inline(always)]
|
||||
pure fn to_mat4(&self) -> Mat4<T> {
|
||||
Mat4::from_Mat3(self)
|
||||
|
@ -681,6 +553,38 @@ pub impl<T:Copy Num NumCast Ord DefaultEq> Mat3<T>: ToQuat<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat3<T>: Dimensional<Vec3<T>> {
|
||||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 3 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Mat3<T>>() }
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat3<T>: Index<uint, Vec3<T>> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> Vec3<T> {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Mat3<T>, *Vec3<T>>(
|
||||
to_unsafe_ptr(&self)), 3) |slice| { slice[i] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat3<T>: ToPtr<T> {
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
self[0].to_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast> Mat3<T>: Neg<Mat3<T>> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Mat3<T> {
|
||||
Mat3::from_cols(-self[0], -self[1], -self[2])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy DefaultEq> Mat3<T>: Eq {
|
||||
#[inline(always)]
|
||||
pure fn eq(&self, other: &Mat3<T>) -> bool {
|
||||
|
@ -718,9 +622,9 @@ pub impl<T:Copy DefaultEq> Mat3<T>: DefaultEq {
|
|||
|
||||
|
||||
|
||||
//
|
||||
// Mat4: A 4x4, column major matrix
|
||||
//
|
||||
/**
|
||||
* A 4 x 4 column major matrix
|
||||
*/
|
||||
pub struct Mat4<T> { x: Vec4<T>, y: Vec4<T>, z: Vec4<T>, w: Vec4<T> }
|
||||
|
||||
pub impl<T:Copy NumCast> Mat4<T> {
|
||||
|
@ -794,13 +698,7 @@ pub impl<T:Copy NumCast> Mat4<T> {
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat4<T>: Matrix<T, Vec4<T>, Vec4<T>> {
|
||||
#[inline(always)]
|
||||
static pure fn cols() -> uint { 4 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn rows() -> uint { 4 }
|
||||
|
||||
pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: Matrix<T, Vec4<T>> {
|
||||
#[inline(always)]
|
||||
pure fn col(&self, i: uint) -> Vec4<T> { self[i] }
|
||||
|
||||
|
@ -811,55 +709,7 @@ pub impl<T:Copy> Mat4<T>: Matrix<T, Vec4<T>, Vec4<T>> {
|
|||
self[2][i],
|
||||
self[3][i])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T> Mat4<T>: Dimensional<Vec4<T>> {
|
||||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 4 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Mat4<T>>() }
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat4<T>: Index<uint, Vec4<T>> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> Vec4<T> {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Mat4<T>, *Vec4<T>>(
|
||||
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat4<T>: ToPtr<T> {
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
self[0].to_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy DefaultEq> Mat4<T>: MatrixNxN<T, Vec4<T>> {
|
||||
#[inline(always)]
|
||||
pure fn is_symmetric(&self) -> bool {
|
||||
self[0][1].default_eq(&self[1][0]) &&
|
||||
self[0][2].default_eq(&self[2][0]) &&
|
||||
self[0][3].default_eq(&self[3][0]) &&
|
||||
|
||||
self[1][0].default_eq(&self[0][1]) &&
|
||||
self[1][2].default_eq(&self[2][1]) &&
|
||||
self[1][3].default_eq(&self[3][1]) &&
|
||||
|
||||
self[2][0].default_eq(&self[0][2]) &&
|
||||
self[2][1].default_eq(&self[1][2]) &&
|
||||
self[2][3].default_eq(&self[3][2]) &&
|
||||
|
||||
self[3][0].default_eq(&self[0][3]) &&
|
||||
self[3][1].default_eq(&self[1][3]) &&
|
||||
self[3][2].default_eq(&self[2][3])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast DefaultEq> Mat4<T>: NumericMatrix<T, Vec4<T>, Vec4<T>> {
|
||||
#[inline(always)]
|
||||
static pure fn zero() -> Mat4<T> {
|
||||
let _0 = cast(0);
|
||||
|
@ -900,16 +750,7 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat4<T>: NumericMatrix<T, Vec4<T>, Vec4<T
|
|||
self[2].sub_v(&other[2]),
|
||||
self[3].sub_v(&other[3]))
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast> Mat4<T>: Neg<Mat4<T>> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Mat4<T> {
|
||||
Mat4::from_cols(-self[0], -self[1], -self[2], -self[3])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec4<T>> {
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn identity() -> Mat4<T> {
|
||||
let _0 = cast(0);
|
||||
|
@ -964,7 +805,7 @@ pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec
|
|||
// Gauss Jordan Elimination with partial pivoting
|
||||
|
||||
let mut a = *self;
|
||||
// let mut inv: Mat4<T> = NumericMatrixNxN::identity(); // FIXME: there's something wrong with static functions here!
|
||||
// let mut inv: Mat4<T> = Matrix::identity(); // FIXME: there's something wrong with static functions here!
|
||||
let mut inv = Mat4::identity();
|
||||
|
||||
// Find largest pivot column j among rows j..3
|
||||
|
@ -1021,7 +862,7 @@ pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec
|
|||
|
||||
#[inline(always)]
|
||||
pure fn is_identity(&self) -> bool {
|
||||
// self.default_eq(&NumericMatrixNxN::identity()) // FIXME: there's something wrong with static functions here!
|
||||
// self.default_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here!
|
||||
self.default_eq(&Mat4::identity())
|
||||
}
|
||||
|
||||
|
@ -1047,9 +888,28 @@ pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec
|
|||
|
||||
#[inline(always)]
|
||||
pure fn is_rotated(&self) -> bool {
|
||||
// !self.default_eq(&NumericMatrixNxN::identity()) // FIXME: there's something wrong with static functions here!
|
||||
// !self.default_eq(&Matrix::identity()) // FIXME: there's something wrong with static functions here!
|
||||
!self.default_eq(&Mat4::identity())
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_symmetric(&self) -> bool {
|
||||
self[0][1].default_eq(&self[1][0]) &&
|
||||
self[0][2].default_eq(&self[2][0]) &&
|
||||
self[0][3].default_eq(&self[3][0]) &&
|
||||
|
||||
self[1][0].default_eq(&self[0][1]) &&
|
||||
self[1][2].default_eq(&self[2][1]) &&
|
||||
self[1][3].default_eq(&self[3][1]) &&
|
||||
|
||||
self[2][0].default_eq(&self[0][2]) &&
|
||||
self[2][1].default_eq(&self[1][2]) &&
|
||||
self[2][3].default_eq(&self[3][2]) &&
|
||||
|
||||
self[3][0].default_eq(&self[0][3]) &&
|
||||
self[3][1].default_eq(&self[1][3]) &&
|
||||
self[3][2].default_eq(&self[2][3])
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn is_invertible(&self) -> bool {
|
||||
|
@ -1058,8 +918,39 @@ pub impl<T:Copy Num NumCast DefaultEq Sign Ord> Mat4<T>: NumericMatrixNxN<T, Vec
|
|||
}
|
||||
}
|
||||
|
||||
pub impl<T> Mat4<T>: NumericMatrix4x4<T, Vec4<T>> {
|
||||
pub impl<T> Mat4<T>: Matrix4<T, Vec4<T>> {
|
||||
}
|
||||
|
||||
pub impl<T:Copy Num NumCast> Mat4<T>: Neg<Mat4<T>> {
|
||||
#[inline(always)]
|
||||
pure fn neg(&self) -> Mat4<T> {
|
||||
Mat4::from_cols(-self[0], -self[1], -self[2], -self[3])
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T> Mat4<T>: Dimensional<Vec4<T>> {
|
||||
#[inline(always)]
|
||||
static pure fn dim() -> uint { 4 }
|
||||
|
||||
#[inline(always)]
|
||||
static pure fn size_of() -> uint { size_of::<Mat4<T>>() }
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat4<T>: Index<uint, Vec4<T>> {
|
||||
#[inline(always)]
|
||||
pure fn index(i: uint) -> Vec4<T> {
|
||||
unsafe { do buf_as_slice(
|
||||
transmute::<*Mat4<T>, *Vec4<T>>(
|
||||
to_unsafe_ptr(&self)), 4) |slice| { slice[i] }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy> Mat4<T>: ToPtr<T> {
|
||||
#[inline(always)]
|
||||
pure fn to_ptr(&self) -> *T {
|
||||
self[0].to_ptr()
|
||||
}
|
||||
}
|
||||
|
||||
pub impl<T:Copy DefaultEq> Mat4<T>: Eq {
|
||||
|
|
|
@ -34,13 +34,6 @@ fn test_vec() {
|
|||
assert dvec3::size_of() == dvec3::dim() * 8;
|
||||
assert dvec4::size_of() == dvec4::dim() * 8;
|
||||
|
||||
assert bvec2::dim() == 2;
|
||||
assert bvec3::dim() == 3;
|
||||
assert bvec4::dim() == 4;
|
||||
assert bvec2::size_of() == bvec2::dim() * 1;
|
||||
assert bvec3::size_of() == bvec3::dim() * 1;
|
||||
assert bvec4::size_of() == bvec4::dim() * 1;
|
||||
|
||||
assert ivec2::identity() == ivec2::from_value(1i32);
|
||||
assert ivec3::identity() == ivec3::from_value(1i32);
|
||||
assert ivec4::identity() == ivec4::from_value(1i32);
|
||||
|
@ -97,127 +90,86 @@ fn test_vec() {
|
|||
}
|
||||
|
||||
#[test]
|
||||
fn test_mat_nxn() {
|
||||
assert mat2x2::identity() == mat2x2::new(1f32, 0f32,
|
||||
0f32, 1f32);
|
||||
assert mat2x2::identity() == mat2x2::from_cols(vec2::new(1f32, 0f32),
|
||||
vec2::new(0f32, 1f32));
|
||||
assert mat3x3::identity() == mat3x3::new(1f32, 0f32, 0f32,
|
||||
0f32, 1f32, 0f32,
|
||||
0f32, 0f32, 1f32);
|
||||
assert mat3x3::identity() == mat3x3::from_cols(vec3::new(1f32, 0f32, 0f32),
|
||||
vec3::new(0f32, 1f32, 0f32),
|
||||
vec3::new(0f32, 0f32, 1f32));
|
||||
assert mat4x4::identity() == mat4x4::new(1f32, 0f32, 0f32, 0f32,
|
||||
0f32, 1f32, 0f32, 0f32,
|
||||
0f32, 0f32, 1f32, 0f32,
|
||||
0f32, 0f32, 0f32, 1f32);
|
||||
assert mat4x4::identity() == mat4x4::from_cols(vec4::new(1f32, 0f32, 0f32, 0f32),
|
||||
vec4::new(0f32, 1f32, 0f32, 0f32),
|
||||
vec4::new(0f32, 0f32, 1f32, 0f32),
|
||||
vec4::new(0f32, 0f32, 0f32, 1f32));
|
||||
assert mat2x2::zero() == mat2x2::from_cols(vec2::zero(),
|
||||
vec2::zero());
|
||||
assert mat3x3::zero() == mat3x3::from_cols(vec3::zero(),
|
||||
vec3::zero(),
|
||||
vec3::zero());
|
||||
assert mat4x4::zero() == mat4x4::from_cols(vec4::zero(),
|
||||
vec4::zero(),
|
||||
vec4::zero(),
|
||||
vec4::zero());
|
||||
assert mat2x2::dim() == 2;
|
||||
assert mat3x3::dim() == 3;
|
||||
assert mat4x4::dim() == 4;
|
||||
assert mat2x2::rows() == 2;
|
||||
assert mat3x3::rows() == 3;
|
||||
assert mat4x4::rows() == 4;
|
||||
assert mat2x2::cols() == 2;
|
||||
assert mat3x3::cols() == 3;
|
||||
assert mat4x4::cols() == 4;
|
||||
assert mat2x2::size_of() == mat2x2::rows() * mat2x2::cols() * 4;
|
||||
assert mat3x3::size_of() == mat3x3::rows() * mat3x3::cols() * 4;
|
||||
assert mat4x4::size_of() == mat4x4::rows() * mat4x4::cols() * 4;
|
||||
fn test_mat() {
|
||||
assert mat2::identity() == mat2::new(1f32, 0f32,
|
||||
0f32, 1f32);
|
||||
assert mat2::identity() == mat2::from_cols(vec2::new(1f32, 0f32),
|
||||
vec2::new(0f32, 1f32));
|
||||
assert mat3::identity() == mat3::new(1f32, 0f32, 0f32,
|
||||
0f32, 1f32, 0f32,
|
||||
0f32, 0f32, 1f32);
|
||||
assert mat3::identity() == mat3::from_cols(vec3::new(1f32, 0f32, 0f32),
|
||||
vec3::new(0f32, 1f32, 0f32),
|
||||
vec3::new(0f32, 0f32, 1f32));
|
||||
assert mat4::identity() == mat4::new(1f32, 0f32, 0f32, 0f32,
|
||||
0f32, 1f32, 0f32, 0f32,
|
||||
0f32, 0f32, 1f32, 0f32,
|
||||
0f32, 0f32, 0f32, 1f32);
|
||||
assert mat4::identity() == mat4::from_cols(vec4::new(1f32, 0f32, 0f32, 0f32),
|
||||
vec4::new(0f32, 1f32, 0f32, 0f32),
|
||||
vec4::new(0f32, 0f32, 1f32, 0f32),
|
||||
vec4::new(0f32, 0f32, 0f32, 1f32));
|
||||
assert mat2::zero() == mat2::from_cols(vec2::zero(),
|
||||
vec2::zero());
|
||||
assert mat3::zero() == mat3::from_cols(vec3::zero(),
|
||||
vec3::zero(),
|
||||
vec3::zero());
|
||||
assert mat4::zero() == mat4::from_cols(vec4::zero(),
|
||||
vec4::zero(),
|
||||
vec4::zero(),
|
||||
vec4::zero());
|
||||
assert mat2::dim() == 2;
|
||||
assert mat3::dim() == 3;
|
||||
assert mat4::dim() == 4;
|
||||
assert mat2::rows() == 2;
|
||||
assert mat3::rows() == 3;
|
||||
assert mat4::rows() == 4;
|
||||
assert mat2::cols() == 2;
|
||||
assert mat3::cols() == 3;
|
||||
assert mat4::cols() == 4;
|
||||
assert mat2::size_of() == mat2::rows() * mat2::cols() * 4;
|
||||
assert mat3::size_of() == mat3::rows() * mat3::cols() * 4;
|
||||
assert mat4::size_of() == mat4::rows() * mat4::cols() * 4;
|
||||
|
||||
assert dmat2x2::identity() == dmat2x2::new(1f64, 0f64,
|
||||
0f64, 1f64);
|
||||
assert dmat2x2::identity() == dmat2x2::from_cols(dvec2::new(1f64, 0f64),
|
||||
dvec2::new(0f64, 1f64));
|
||||
assert dmat3x3::identity() == dmat3x3::new(1f64, 0f64, 0f64,
|
||||
0f64, 1f64, 0f64,
|
||||
0f64, 0f64, 1f64);
|
||||
assert dmat3x3::identity() == dmat3x3::from_cols(dvec3::new(1f64, 0f64, 0f64),
|
||||
dvec3::new(0f64, 1f64, 0f64),
|
||||
dvec3::new(0f64, 0f64, 1f64));
|
||||
assert dmat4x4::identity() == dmat4x4::new(1f64, 0f64, 0f64, 0f64,
|
||||
0f64, 1f64, 0f64, 0f64,
|
||||
0f64, 0f64, 1f64, 0f64,
|
||||
0f64, 0f64, 0f64, 1f64);
|
||||
assert dmat4x4::identity() == dmat4x4::from_cols(dvec4::new(1f64, 0f64, 0f64, 0f64),
|
||||
dvec4::new(0f64, 1f64, 0f64, 0f64),
|
||||
dvec4::new(0f64, 0f64, 1f64, 0f64),
|
||||
dvec4::new(0f64, 0f64, 0f64, 1f64));
|
||||
assert dmat2x2::zero() == dmat2x2::from_cols(dvec2::zero(),
|
||||
dvec2::zero());
|
||||
assert dmat3x3::zero() == dmat3x3::from_cols(dvec3::zero(),
|
||||
dvec3::zero(),
|
||||
dvec3::zero());
|
||||
assert dmat4x4::zero() == dmat4x4::from_cols(dvec4::zero(),
|
||||
dvec4::zero(),
|
||||
dvec4::zero(),
|
||||
dvec4::zero());
|
||||
assert dmat2x2::dim() == 2;
|
||||
assert dmat3x3::dim() == 3;
|
||||
assert dmat4x4::dim() == 4;
|
||||
assert dmat2x2::rows() == 2;
|
||||
assert dmat3x3::rows() == 3;
|
||||
assert dmat4x4::rows() == 4;
|
||||
assert dmat2x2::cols() == 2;
|
||||
assert dmat3x3::cols() == 3;
|
||||
assert dmat4x4::cols() == 4;
|
||||
assert dmat2x2::size_of() == dmat2x2::rows() * dmat2x2::cols() * 8;
|
||||
assert dmat3x3::size_of() == dmat3x3::rows() * dmat3x3::cols() * 8;
|
||||
assert dmat4x4::size_of() == dmat4x4::rows() * dmat4x4::cols() * 8;
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_mat_n() {
|
||||
assert mat2::identity() == mat2x2::identity();
|
||||
assert mat3::identity() == mat3x3::identity();
|
||||
assert mat4::identity() == mat4x4::identity();
|
||||
assert mat2::zero() == mat2x2::zero();
|
||||
assert mat3::zero() == mat3x3::zero();
|
||||
assert mat4::zero() == mat4x4::zero();
|
||||
assert mat2::dim() == 2;
|
||||
assert mat3::dim() == 3;
|
||||
assert mat4::dim() == 4;
|
||||
assert mat2::rows() == 2;
|
||||
assert mat3::rows() == 3;
|
||||
assert mat4::rows() == 4;
|
||||
assert mat2::cols() == 2;
|
||||
assert mat3::cols() == 3;
|
||||
assert mat4::cols() == 4;
|
||||
assert mat2::size_of() == mat2::rows() * mat2::cols() * 4;
|
||||
assert mat3::size_of() == mat3::rows() * mat3::cols() * 4;
|
||||
assert mat4::size_of() == mat4::rows() * mat4::cols() * 4;
|
||||
|
||||
assert dmat2::identity() == dmat2x2::identity();
|
||||
assert dmat3::identity() == dmat3x3::identity();
|
||||
assert dmat4::identity() == dmat4x4::identity();
|
||||
assert dmat2::zero() == dmat2x2::zero();
|
||||
assert dmat3::zero() == dmat3x3::zero();
|
||||
assert dmat4::zero() == dmat4x4::zero();
|
||||
assert dmat2::dim() == 2;
|
||||
assert dmat3::dim() == 3;
|
||||
assert dmat4::dim() == 4;
|
||||
assert dmat2::rows() == 2;
|
||||
assert dmat3::rows() == 3;
|
||||
assert dmat4::rows() == 4;
|
||||
assert dmat2::cols() == 2;
|
||||
assert dmat3::cols() == 3;
|
||||
assert dmat4::cols() == 4;
|
||||
assert dmat2::size_of() == dmat2::rows() * dmat2::cols() * 8;
|
||||
assert dmat3::size_of() == dmat3::rows() * dmat3::cols() * 8;
|
||||
assert dmat4::size_of() == dmat4::rows() * dmat4::cols() * 8;
|
||||
assert dmat2::identity() == dmat2::new(1f64, 0f64,
|
||||
0f64, 1f64);
|
||||
assert dmat2::identity() == dmat2::from_cols(dvec2::new(1f64, 0f64),
|
||||
dvec2::new(0f64, 1f64));
|
||||
assert dmat3::identity() == dmat3::new(1f64, 0f64, 0f64,
|
||||
0f64, 1f64, 0f64,
|
||||
0f64, 0f64, 1f64);
|
||||
assert dmat3::identity() == dmat3::from_cols(dvec3::new(1f64, 0f64, 0f64),
|
||||
dvec3::new(0f64, 1f64, 0f64),
|
||||
dvec3::new(0f64, 0f64, 1f64));
|
||||
assert dmat4::identity() == dmat4::new(1f64, 0f64, 0f64, 0f64,
|
||||
0f64, 1f64, 0f64, 0f64,
|
||||
0f64, 0f64, 1f64, 0f64,
|
||||
0f64, 0f64, 0f64, 1f64);
|
||||
assert dmat4::identity() == dmat4::from_cols(dvec4::new(1f64, 0f64, 0f64, 0f64),
|
||||
dvec4::new(0f64, 1f64, 0f64, 0f64),
|
||||
dvec4::new(0f64, 0f64, 1f64, 0f64),
|
||||
dvec4::new(0f64, 0f64, 0f64, 1f64));
|
||||
assert dmat2::zero() == dmat2::from_cols(dvec2::zero(),
|
||||
dvec2::zero());
|
||||
assert dmat3::zero() == dmat3::from_cols(dvec3::zero(),
|
||||
dvec3::zero(),
|
||||
dvec3::zero());
|
||||
assert dmat4::zero() == dmat4::from_cols(dvec4::zero(),
|
||||
dvec4::zero(),
|
||||
dvec4::zero(),
|
||||
dvec4::zero());
|
||||
assert dmat2::dim() == 2;
|
||||
assert dmat3::dim() == 3;
|
||||
assert dmat4::dim() == 4;
|
||||
assert dmat2::rows() == 2;
|
||||
assert dmat3::rows() == 3;
|
||||
assert dmat4::rows() == 4;
|
||||
assert dmat2::cols() == 2;
|
||||
assert dmat3::cols() == 3;
|
||||
assert dmat4::cols() == 4;
|
||||
assert dmat2::size_of() == dmat2::rows() * dmat2::cols() * 8;
|
||||
assert dmat3::size_of() == dmat3::rows() * dmat3::cols() * 8;
|
||||
assert dmat4::size_of() == dmat4::rows() * dmat4::cols() * 8;
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
Loading…
Reference in a new issue