From e2013002b5c316a6fc2e5c1e043f70fc3b1c8f35 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Wed, 21 Nov 2012 18:08:08 +1000 Subject: [PATCH] Rename NumericMatrix_NxN to NumericMatrixNxN --- src/gltypes.rs | 18 ++++++++---------- src/mat.rs | 35 +++++++++++++++++------------------ src/test/test_mat.rs | 6 +++--- 3 files changed, 28 insertions(+), 31 deletions(-) diff --git a/src/gltypes.rs b/src/gltypes.rs index ec49bf9..d4bb88a 100644 --- a/src/gltypes.rs +++ b/src/gltypes.rs @@ -11,7 +11,7 @@ /// code and make debugging far easier, instead of writing: /// /// ~~~ -/// let v: Mat4 = NumericMatrix_NxN::identity(); +/// let v: Mat4 = NumericMatrixNxN::identity(); /// ~~~ /// /// `lmath::gltypes` allows you to write: @@ -20,10 +20,8 @@ /// 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 quat::{/*Quaternion, */Quat}; @@ -226,7 +224,7 @@ pub impl mat2x2 { -> 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 identity() -> mat2x2 { NumericMatrix_NxN::identity() } + #[inline(always)] static pure fn identity() -> mat2x2 { NumericMatrixNxN::identity() } #[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) } #[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 identity() -> mat3x3 { NumericMatrix_NxN::identity() } + #[inline(always)] static pure fn identity() -> mat3x3 { NumericMatrixNxN::identity() } #[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) } #[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 identity() -> mat4x4 { NumericMatrix_NxN::identity() } + #[inline(always)] static pure fn identity() -> mat4x4 { NumericMatrixNxN::identity() } #[inline(always)] static pure fn zero() -> mat4x4 { NumericMatrix::zero() } } @@ -281,7 +279,7 @@ pub impl dmat2x2 { -> 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 identity() -> dmat2x2 { NumericMatrix_NxN::identity() } + #[inline(always)] static pure fn identity() -> dmat2x2 { NumericMatrixNxN::identity() } #[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) } #[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 identity() -> dmat3x3 { NumericMatrix_NxN::identity() } + #[inline(always)] static pure fn identity() -> dmat3x3 { NumericMatrixNxN::identity() } #[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) } #[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 identity() -> dmat4x4 { NumericMatrix_NxN::identity() } + #[inline(always)] static pure fn identity() -> dmat4x4 { NumericMatrixNxN::identity() } #[inline(always)] static pure fn zero() -> dmat4x4 { NumericMatrix::zero() } } diff --git a/src/mat.rs b/src/mat.rs index 01ed8de..ec8f96c 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -83,7 +83,7 @@ pub trait NumericMatrix: Matrix, Neg { /// /// A square matrix with numeric elements /// -pub trait NumericMatrix_NxN: NumericMatrix { +pub trait NumericMatrixNxN: NumericMatrix { static pure fn identity() -> self; pure fn mul_m(other: &self) -> self; @@ -94,25 +94,24 @@ pub trait NumericMatrix_NxN: NumericMatrix { pure fn transpose() -> self; pure fn is_identity() -> bool; - pure fn is_symmetric() -> bool; pure fn is_diagonal() -> bool; pure fn is_rotated() -> bool; pure fn is_invertible() -> bool; } /// A 2 x 2 square matrix with numeric elements -pub trait NumericMatrix2x2: NumericMatrix_NxN> { +pub trait NumericMatrix2x2: NumericMatrixNxN> { pure fn to_Mat3() -> Mat3; pure fn to_Mat4() -> Mat4; } /// A 3 x 3 square matrix with numeric elements -pub trait NumericMatrix3x3: NumericMatrix_NxN> { +pub trait NumericMatrix3x3: NumericMatrixNxN> { pure fn to_Mat4() -> Mat4; } /// A 4 x 4 square matrix with numeric elements -pub trait NumericMatrix4x4: NumericMatrix_NxN> { +pub trait NumericMatrix4x4: NumericMatrixNxN> { } @@ -224,7 +223,7 @@ pub impl Mat2: NumericMatrix, Vec2> { } } -pub impl Mat2: NumericMatrix_NxN> { +pub impl Mat2: NumericMatrixNxN> { #[inline(always)] static pure fn identity() -> Mat2 { Mat2::new(NumCast::one() , NumCast::zero(), @@ -238,7 +237,7 @@ pub impl Mat2: NumericMatrix_NxN> { } 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)] @@ -248,8 +247,8 @@ pub impl Mat2: NumericMatrix_NxN> { if d.default_eq(&_0) { None } else { - Some(Mat2::new(self[1][1]/d, -self[0][1]/d, - -self[1][0]/d, self[0][0]/d)) + Some(Mat2::new( self[1][1]/d, -self[0][1]/d, + -self[1][0]/d, self[0][0]/d)) } } @@ -261,7 +260,7 @@ pub impl Mat2: NumericMatrix_NxN> { #[inline(always)] pure fn is_identity() -> bool { - self.default_eq(&NumericMatrix_NxN::identity()) + self.default_eq(&NumericMatrixNxN::identity()) } #[inline(always)] @@ -279,7 +278,7 @@ pub impl Mat2: NumericMatrix_NxN> { #[inline(always)] pure fn is_rotated() -> bool { - !self.default_eq(&NumericMatrix_NxN::identity()) + !self.default_eq(&NumericMatrixNxN::identity()) } #[inline(always)] @@ -456,7 +455,7 @@ pub impl Mat3: NumericMatrix, Vec3> { } } -pub impl Mat3: NumericMatrix_NxN> { +pub impl Mat3: NumericMatrixNxN> { #[inline(always)] static pure fn identity() -> Mat3 { Mat3::new(NumCast::one() , NumCast::zero(), NumCast::zero(), @@ -498,7 +497,7 @@ pub impl Mat3: NumericMatrix_NxN> { #[inline(always)] pure fn is_identity() -> bool { - self.default_eq(&NumericMatrix_NxN::identity()) + self.default_eq(&NumericMatrixNxN::identity()) } #[inline(always)] @@ -528,7 +527,7 @@ pub impl Mat3: NumericMatrix_NxN> { #[inline(always)] pure fn is_rotated() -> bool { - !self.default_eq(&NumericMatrix_NxN::identity()) + !self.default_eq(&NumericMatrixNxN::identity()) } #[inline(always)] @@ -766,7 +765,7 @@ pub impl Mat4: NumericMatrix, Vec4> { } } -pub impl Mat4: NumericMatrix_NxN> { +pub impl Mat4: NumericMatrixNxN> { #[inline(always)] static pure fn identity() -> Mat4 { Mat4::new(NumCast::one() , NumCast::zero(), NumCast::zero(), NumCast::zero(), @@ -811,7 +810,7 @@ pub impl Mat4: NumericMatrix_NxN = NumericMatrix_NxN::identity(); + let mut inv: Mat4 = NumericMatrixNxN::identity(); // Find largest pivot column j among rows j..3 for uint::range(0, 4) |j| { @@ -867,7 +866,7 @@ pub impl Mat4: NumericMatrix_NxN bool { - self.default_eq(&NumericMatrix_NxN::identity()) + self.default_eq(&NumericMatrixNxN::identity()) } #[inline(always)] @@ -911,7 +910,7 @@ pub impl Mat4: NumericMatrix_NxN bool { - !self.default_eq(&NumericMatrix_NxN::identity()) + !self.default_eq(&NumericMatrixNxN::identity()) } #[inline(always)] diff --git a/src/test/test_mat.rs b/src/test/test_mat.rs index 83b0fca..36b4d23 100644 --- a/src/test/test_mat.rs +++ b/src/test/test_mat.rs @@ -60,7 +60,7 @@ fn test_Mat2() { // fuzzy_eq // eq - let ident: Mat2 = NumericMatrix_NxN::identity(); + let ident: Mat2 = NumericMatrixNxN::identity(); assert ident.is_identity(); assert ident.is_symmetric(); @@ -169,7 +169,7 @@ fn test_Mat3() { 0f, 0.5f, -2f, 0f, 0f, 1f); - let ident: Mat3 = NumericMatrix_NxN::identity(); + let ident: Mat3 = NumericMatrixNxN::identity(); assert option::unwrap(ident.invert()) == ident; @@ -306,7 +306,7 @@ fn test_Mat4() { 4f, -8f, 4f, 8f, -3f, 4f, 1f, -8f).mul_t(0.125f); - let ident: Mat4 = NumericMatrix_NxN::identity(); + let ident: Mat4 = NumericMatrixNxN::identity(); assert option::unwrap(ident.invert()) == ident;