Rename NumericMatrix_NxN to NumericMatrixNxN
This commit is contained in:
parent
e892f4db37
commit
e2013002b5
3 changed files with 28 additions and 31 deletions
|
@ -11,7 +11,7 @@
|
||||||
/// code and make debugging far easier, instead of writing:
|
/// code and make debugging far easier, instead of writing:
|
||||||
///
|
///
|
||||||
/// ~~~
|
/// ~~~
|
||||||
/// let v: Mat4<f64> = NumericMatrix_NxN::identity();
|
/// let v: Mat4<f64> = NumericMatrixNxN::identity();
|
||||||
/// ~~~
|
/// ~~~
|
||||||
///
|
///
|
||||||
/// `lmath::gltypes` allows you to write:
|
/// `lmath::gltypes` allows you to write:
|
||||||
|
@ -20,10 +20,8 @@
|
||||||
/// let v = dmat4::identity();
|
/// let v = dmat4::identity();
|
||||||
/// ~~~
|
/// ~~~
|
||||||
///
|
///
|
||||||
/// Isn't that a *huge* step forward in terms of clarity and type safety?
|
|
||||||
///
|
|
||||||
|
|
||||||
use mat::{NumericMatrix, NumericMatrix_NxN, Mat2, Mat3, Mat4};
|
use mat::{NumericMatrix, NumericMatrixNxN, Mat2, Mat3, Mat4};
|
||||||
use vec::{Vector, NumericVector, Vec2, Vec3, Vec4};
|
use vec::{Vector, NumericVector, Vec2, Vec3, Vec4};
|
||||||
use quat::{/*Quaternion, */Quat};
|
use quat::{/*Quaternion, */Quat};
|
||||||
|
|
||||||
|
@ -226,7 +224,7 @@ pub impl mat2x2 {
|
||||||
-> mat2x2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
-> mat2x2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||||
#[inline(always)] static pure fn from_cols(c0: vec2, c1: vec2)
|
#[inline(always)] static pure fn from_cols(c0: vec2, c1: vec2)
|
||||||
-> mat2x2 { Mat2::from_cols(move c0, move c1) }
|
-> mat2x2 { Mat2::from_cols(move c0, move c1) }
|
||||||
#[inline(always)] static pure fn identity() -> mat2x2 { NumericMatrix_NxN::identity() }
|
#[inline(always)] static pure fn identity() -> mat2x2 { NumericMatrixNxN::identity() }
|
||||||
#[inline(always)] static pure fn zero() -> mat2x2 { NumericMatrix::zero() }
|
#[inline(always)] static pure fn zero() -> mat2x2 { NumericMatrix::zero() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -235,7 +233,7 @@ pub impl mat3x3 {
|
||||||
-> mat3x3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
-> mat3x3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||||
#[inline(always)] static pure fn from_cols(c0: vec3, c1: vec3, c2: vec3)
|
#[inline(always)] static pure fn from_cols(c0: vec3, c1: vec3, c2: vec3)
|
||||||
-> mat3x3 { Mat3::from_cols(move c0, move c1, move c2) }
|
-> mat3x3 { Mat3::from_cols(move c0, move c1, move c2) }
|
||||||
#[inline(always)] static pure fn identity() -> mat3x3 { NumericMatrix_NxN::identity() }
|
#[inline(always)] static pure fn identity() -> mat3x3 { NumericMatrixNxN::identity() }
|
||||||
#[inline(always)] static pure fn zero() -> mat3x3 { NumericMatrix::zero() }
|
#[inline(always)] static pure fn zero() -> mat3x3 { NumericMatrix::zero() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -244,7 +242,7 @@ pub impl mat4x4 {
|
||||||
-> mat4x4 { Mat4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
-> mat4x4 { 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)
|
#[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) }
|
-> mat4x4 { Mat4::from_cols(move c0, move c1, move c2, move c3) }
|
||||||
#[inline(always)] static pure fn identity() -> mat4x4 { NumericMatrix_NxN::identity() }
|
#[inline(always)] static pure fn identity() -> mat4x4 { NumericMatrixNxN::identity() }
|
||||||
#[inline(always)] static pure fn zero() -> mat4x4 { NumericMatrix::zero() }
|
#[inline(always)] static pure fn zero() -> mat4x4 { NumericMatrix::zero() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,7 +279,7 @@ pub impl dmat2x2 {
|
||||||
-> dmat2x2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
-> dmat2x2 { Mat2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||||
#[inline(always)] static pure fn from_cols(c0: dvec2, c1: dvec2)
|
#[inline(always)] static pure fn from_cols(c0: dvec2, c1: dvec2)
|
||||||
-> dmat2x2 { Mat2::from_cols(move c0, move c1) }
|
-> dmat2x2 { Mat2::from_cols(move c0, move c1) }
|
||||||
#[inline(always)] static pure fn identity() -> dmat2x2 { NumericMatrix_NxN::identity() }
|
#[inline(always)] static pure fn identity() -> dmat2x2 { NumericMatrixNxN::identity() }
|
||||||
#[inline(always)] static pure fn zero() -> dmat2x2 { NumericMatrix::zero() }
|
#[inline(always)] static pure fn zero() -> dmat2x2 { NumericMatrix::zero() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -290,7 +288,7 @@ pub impl dmat3x3 {
|
||||||
-> dmat3x3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
-> dmat3x3 { Mat3::new(c0r0, c0r1, c0r2, c1r0, c1r1, c1r2, c2r0, c2r1, c2r2) }
|
||||||
#[inline(always)] static pure fn from_cols(c0: dvec3, c1: dvec3, c2: dvec3)
|
#[inline(always)] static pure fn from_cols(c0: dvec3, c1: dvec3, c2: dvec3)
|
||||||
-> dmat3x3 { Mat3::from_cols(move c0, move c1, move c2) }
|
-> dmat3x3 { Mat3::from_cols(move c0, move c1, move c2) }
|
||||||
#[inline(always)] static pure fn identity() -> dmat3x3 { NumericMatrix_NxN::identity() }
|
#[inline(always)] static pure fn identity() -> dmat3x3 { NumericMatrixNxN::identity() }
|
||||||
#[inline(always)] static pure fn zero() -> dmat3x3 { NumericMatrix::zero() }
|
#[inline(always)] static pure fn zero() -> dmat3x3 { NumericMatrix::zero() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -299,7 +297,7 @@ pub impl dmat4x4 {
|
||||||
-> dmat4x4 { Mat4::new(c0r0, c0r1, c0r2, c0r3, c1r0, c1r1, c1r2, c1r3, c2r0, c2r1, c2r2, c2r3, c3r0, c3r1, c3r2, c3r3) }
|
-> dmat4x4 { 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)
|
#[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) }
|
-> dmat4x4 { Mat4::from_cols(move c0, move c1, move c2, move c3) }
|
||||||
#[inline(always)] static pure fn identity() -> dmat4x4 { NumericMatrix_NxN::identity() }
|
#[inline(always)] static pure fn identity() -> dmat4x4 { NumericMatrixNxN::identity() }
|
||||||
#[inline(always)] static pure fn zero() -> dmat4x4 { NumericMatrix::zero() }
|
#[inline(always)] static pure fn zero() -> dmat4x4 { NumericMatrix::zero() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
35
src/mat.rs
35
src/mat.rs
|
@ -83,7 +83,7 @@ pub trait NumericMatrix<T, Col, Row>: Matrix<T, Col, Row>, Neg<self> {
|
||||||
///
|
///
|
||||||
/// A square matrix with numeric elements
|
/// A square matrix with numeric elements
|
||||||
///
|
///
|
||||||
pub trait NumericMatrix_NxN<T, ColRow>: NumericMatrix<T, ColRow, ColRow> {
|
pub trait NumericMatrixNxN<T, ColRow>: NumericMatrix<T, ColRow, ColRow> {
|
||||||
static pure fn identity() -> self;
|
static pure fn identity() -> self;
|
||||||
|
|
||||||
pure fn mul_m(other: &self) -> self;
|
pure fn mul_m(other: &self) -> self;
|
||||||
|
@ -94,25 +94,24 @@ pub trait NumericMatrix_NxN<T, ColRow>: NumericMatrix<T, ColRow, ColRow> {
|
||||||
pure fn transpose() -> self;
|
pure fn transpose() -> self;
|
||||||
|
|
||||||
pure fn is_identity() -> bool;
|
pure fn is_identity() -> bool;
|
||||||
pure fn is_symmetric() -> bool;
|
|
||||||
pure fn is_diagonal() -> bool;
|
pure fn is_diagonal() -> bool;
|
||||||
pure fn is_rotated() -> bool;
|
pure fn is_rotated() -> bool;
|
||||||
pure fn is_invertible() -> bool;
|
pure fn is_invertible() -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A 2 x 2 square matrix with numeric elements
|
/// A 2 x 2 square matrix with numeric elements
|
||||||
pub trait NumericMatrix2x2<T>: NumericMatrix_NxN<T, Mat2<T>> {
|
pub trait NumericMatrix2x2<T>: NumericMatrixNxN<T, Mat2<T>> {
|
||||||
pure fn to_Mat3() -> Mat3<T>;
|
pure fn to_Mat3() -> Mat3<T>;
|
||||||
pure fn to_Mat4() -> Mat4<T>;
|
pure fn to_Mat4() -> Mat4<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A 3 x 3 square matrix with numeric elements
|
/// A 3 x 3 square matrix with numeric elements
|
||||||
pub trait NumericMatrix3x3<T>: NumericMatrix_NxN<T, Mat3<T>> {
|
pub trait NumericMatrix3x3<T>: NumericMatrixNxN<T, Mat3<T>> {
|
||||||
pure fn to_Mat4() -> Mat4<T>;
|
pure fn to_Mat4() -> Mat4<T>;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// A 4 x 4 square matrix with numeric elements
|
/// A 4 x 4 square matrix with numeric elements
|
||||||
pub trait NumericMatrix4x4<T>: NumericMatrix_NxN<T, Mat4<T>> {
|
pub trait NumericMatrix4x4<T>: NumericMatrixNxN<T, Mat4<T>> {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -224,7 +223,7 @@ pub impl<T:Copy Num NumCast> Mat2<T>: NumericMatrix<T, Vec2<T>, Vec2<T>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrix_NxN<T, Vec2<T>> {
|
pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrixNxN<T, Vec2<T>> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
static pure fn identity() -> Mat2<T> {
|
static pure fn identity() -> Mat2<T> {
|
||||||
Mat2::new(NumCast::one() , NumCast::zero(),
|
Mat2::new(NumCast::one() , NumCast::zero(),
|
||||||
|
@ -238,7 +237,7 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrix_NxN<T, Vec2<T>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
pure fn det() -> T {
|
pure fn det() -> T {
|
||||||
self[0][0]*self[1][1] - self[1][0]*self[0][1]
|
self[0][0] * self[1][1] - self[1][0] * self[0][1]
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -248,8 +247,8 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrix_NxN<T, Vec2<T>> {
|
||||||
if d.default_eq(&_0) {
|
if d.default_eq(&_0) {
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
Some(Mat2::new(self[1][1]/d, -self[0][1]/d,
|
Some(Mat2::new( self[1][1]/d, -self[0][1]/d,
|
||||||
-self[1][0]/d, self[0][0]/d))
|
-self[1][0]/d, self[0][0]/d))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -261,7 +260,7 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrix_NxN<T, Vec2<T>> {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_identity() -> bool {
|
pure fn is_identity() -> bool {
|
||||||
self.default_eq(&NumericMatrix_NxN::identity())
|
self.default_eq(&NumericMatrixNxN::identity())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -279,7 +278,7 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat2<T>: NumericMatrix_NxN<T, Vec2<T>> {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_rotated() -> bool {
|
pure fn is_rotated() -> bool {
|
||||||
!self.default_eq(&NumericMatrix_NxN::identity())
|
!self.default_eq(&NumericMatrixNxN::identity())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -456,7 +455,7 @@ pub impl<T:Copy Num NumCast> Mat3<T>: NumericMatrix<T, Vec3<T>, Vec3<T>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrix_NxN<T, Vec3<T>> {
|
pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrixNxN<T, Vec3<T>> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
static pure fn identity() -> Mat3<T> {
|
static pure fn identity() -> Mat3<T> {
|
||||||
Mat3::new(NumCast::one() , NumCast::zero(), NumCast::zero(),
|
Mat3::new(NumCast::one() , NumCast::zero(), NumCast::zero(),
|
||||||
|
@ -498,7 +497,7 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrix_NxN<T, Vec3<T>> {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_identity() -> bool {
|
pure fn is_identity() -> bool {
|
||||||
self.default_eq(&NumericMatrix_NxN::identity())
|
self.default_eq(&NumericMatrixNxN::identity())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -528,7 +527,7 @@ pub impl<T:Copy Num NumCast DefaultEq> Mat3<T>: NumericMatrix_NxN<T, Vec3<T>> {
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_rotated() -> bool {
|
pure fn is_rotated() -> bool {
|
||||||
!self.default_eq(&NumericMatrix_NxN::identity())
|
!self.default_eq(&NumericMatrixNxN::identity())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -766,7 +765,7 @@ pub impl<T:Copy Num NumCast> Mat4<T>: NumericMatrix<T, Vec4<T>, Vec4<T>> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub impl<T:Copy Num NumCast DefaultEq Signed Ord> Mat4<T>: NumericMatrix_NxN<T, Vec4<T>> {
|
pub impl<T:Copy Num NumCast DefaultEq Signed Ord> Mat4<T>: NumericMatrixNxN<T, Vec4<T>> {
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
static pure fn identity() -> Mat4<T> {
|
static pure fn identity() -> Mat4<T> {
|
||||||
Mat4::new(NumCast::one() , NumCast::zero(), NumCast::zero(), NumCast::zero(),
|
Mat4::new(NumCast::one() , NumCast::zero(), NumCast::zero(), NumCast::zero(),
|
||||||
|
@ -811,7 +810,7 @@ pub impl<T:Copy Num NumCast DefaultEq Signed Ord> Mat4<T>: NumericMatrix_NxN<T,
|
||||||
// Gauss Jordan Elimination with partial pivoting
|
// Gauss Jordan Elimination with partial pivoting
|
||||||
|
|
||||||
let mut a = self.transpose();
|
let mut a = self.transpose();
|
||||||
let mut inv: Mat4<T> = NumericMatrix_NxN::identity();
|
let mut inv: Mat4<T> = NumericMatrixNxN::identity();
|
||||||
|
|
||||||
// Find largest pivot column j among rows j..3
|
// Find largest pivot column j among rows j..3
|
||||||
for uint::range(0, 4) |j| {
|
for uint::range(0, 4) |j| {
|
||||||
|
@ -867,7 +866,7 @@ pub impl<T:Copy Num NumCast DefaultEq Signed Ord> Mat4<T>: NumericMatrix_NxN<T,
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_identity() -> bool {
|
pure fn is_identity() -> bool {
|
||||||
self.default_eq(&NumericMatrix_NxN::identity())
|
self.default_eq(&NumericMatrixNxN::identity())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -911,7 +910,7 @@ pub impl<T:Copy Num NumCast DefaultEq Signed Ord> Mat4<T>: NumericMatrix_NxN<T,
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pure fn is_rotated() -> bool {
|
pure fn is_rotated() -> bool {
|
||||||
!self.default_eq(&NumericMatrix_NxN::identity())
|
!self.default_eq(&NumericMatrixNxN::identity())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
|
|
@ -60,7 +60,7 @@ fn test_Mat2() {
|
||||||
// fuzzy_eq
|
// fuzzy_eq
|
||||||
// eq
|
// eq
|
||||||
|
|
||||||
let ident: Mat2<float> = NumericMatrix_NxN::identity();
|
let ident: Mat2<float> = NumericMatrixNxN::identity();
|
||||||
|
|
||||||
assert ident.is_identity();
|
assert ident.is_identity();
|
||||||
assert ident.is_symmetric();
|
assert ident.is_symmetric();
|
||||||
|
@ -169,7 +169,7 @@ fn test_Mat3() {
|
||||||
0f, 0.5f, -2f,
|
0f, 0.5f, -2f,
|
||||||
0f, 0f, 1f);
|
0f, 0f, 1f);
|
||||||
|
|
||||||
let ident: Mat3<float> = NumericMatrix_NxN::identity();
|
let ident: Mat3<float> = NumericMatrixNxN::identity();
|
||||||
|
|
||||||
assert option::unwrap(ident.invert()) == ident;
|
assert option::unwrap(ident.invert()) == ident;
|
||||||
|
|
||||||
|
@ -306,7 +306,7 @@ fn test_Mat4() {
|
||||||
4f, -8f, 4f, 8f,
|
4f, -8f, 4f, 8f,
|
||||||
-3f, 4f, 1f, -8f).mul_t(0.125f);
|
-3f, 4f, 1f, -8f).mul_t(0.125f);
|
||||||
|
|
||||||
let ident: Mat4<float> = NumericMatrix_NxN::identity();
|
let ident: Mat4<float> = NumericMatrixNxN::identity();
|
||||||
|
|
||||||
assert option::unwrap(ident.invert()) == ident;
|
assert option::unwrap(ident.invert()) == ident;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue