From 563aa9495ec73833b833b2d0f84863d07cf85993 Mon Sep 17 00:00:00 2001 From: Brendan Zabarauskas Date: Fri, 14 Dec 2012 18:37:02 +1000 Subject: [PATCH] Remove from_mat constructors We already have the to_mat conversion methods, so these are redundant --- src/mat.rs | 51 ++++++++++++++++++++++++++++++++++++++++++-- src/mat2.rs | 13 +++++++++-- src/mat3.rs | 16 ++++++-------- src/mat4.rs | 20 ----------------- src/test/test_mat.rs | 22 ------------------- 5 files changed, 66 insertions(+), 56 deletions(-) diff --git a/src/mat.rs b/src/mat.rs index c5df360..e404412 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -249,7 +249,36 @@ pub trait MutableMatrix: Matrix { * A 2 x 2 matrix */ pub trait Matrix2: Matrix { + /** + * Returns the the matrix with an extra row and column added + * ~~~ + * c0 c1 c0 c1 c2 + * +----+----+ +----+----+----+ + * r0 | a | b | r0 | a | b | 0 | + * +----+----+ +----+----+----+ + * r1 | c | d | => r1 | c | d | 0 | + * +----+----+ +----+----+----+ + * r2 | 0 | 0 | 1 | + * +----+----+----+ + * ~~~ + */ pure fn to_mat3(&self) -> Mat3; + + /** + * Returns the the matrix with an extra two rows and columns added + * ~~~ + * c0 c1 c0 c1 c2 c3 + * +----+----+ +----+----+----+----+ + * r0 | a | b | r0 | a | b | 0 | 0 | + * +----+----+ +----+----+----+----+ + * r1 | c | d | => r1 | c | d | 0 | 0 | + * +----+----+ +----+----+----+----+ + * r2 | 0 | 0 | 1 | 0 | + * +----+----+----+----+ + * r3 | 0 | 0 | 0 | 1 | + * +----+----+----+----+ + * ~~~ + */ pure fn to_mat4(&self) -> Mat4; } @@ -257,7 +286,26 @@ pub trait Matrix2: Matrix { * A 3 x 3 matrix */ pub trait Matrix3: Matrix { + /** + * Construct a matrix from an axis and an + */ static pure fn from_axis_angle>(axis: &V, theta: A) -> Mat3; + + /** + * Returns the the matrix with an extra row and column added + * ~~~ + * c0 c1 c2 c0 c1 c2 c3 + * +----+----+----+ +----+----+----+----+ + * r0 | a | b | c | r0 | a | b | c | 0 | + * +----+----+----+ +----+----+----+----+ + * r1 | d | e | f | => r1 | d | e | f | 0 | + * +----+----+----+ +----+----+----+----+ + * r2 | g | h | i | r2 | g | h | i | 0 | + * +----+----+----+ +----+----+----+----+ + * r3 | 0 | 0 | 0 | 1 | + * +----+----+----+----+ + * ~~~ + */ pure fn to_mat4(&self) -> Mat4; /** @@ -269,5 +317,4 @@ pub trait Matrix3: Matrix { /** * A 4 x 4 matrix */ -pub trait Matrix4: Matrix { -} \ No newline at end of file +pub trait Matrix4: Matrix {} \ No newline at end of file diff --git a/src/mat2.rs b/src/mat2.rs index 6a7732d..9523bbd 100644 --- a/src/mat2.rs +++ b/src/mat2.rs @@ -333,12 +333,21 @@ pub impl Mat2: MutableMatrix> { pub impl Mat2: Matrix2> { #[inline(always)] pure fn to_mat3(&self) -> Mat3 { - Mat3::from_Mat2(self) + let _0 = Number::from(0); + let _1 = Number::from(1); + Mat3::new(self[0][0], self[0][1], _0, + self[1][0], self[1][1], _0, + _0, _0, _1) } #[inline(always)] pure fn to_mat4(&self) -> Mat4 { - Mat4::from_Mat2(self) + let _0 = Number::from(0); + let _1 = Number::from(1); + Mat4::new(self[0][0], self[0][1], _0, _0, + self[1][0], self[1][1], _0, _0, + _0, _0, _1, _0, + _0, _0, _0, _1) } } diff --git a/src/mat3.rs b/src/mat3.rs index 0df68ca..fb09ed6 100644 --- a/src/mat3.rs +++ b/src/mat3.rs @@ -111,15 +111,6 @@ pub impl Mat3 { _0, _0, value) } - #[inline(always)] - static pure fn from_Mat2(m: &Mat2) -> Mat3 { - let _0 = Number::from(0); - let _1 = Number::from(1); - Mat3::new(m[0][0], m[0][1], _0, - m[1][0], m[1][1], _0, - _0, _0, _1) - } - // FIXME: An interim solution to the issues with static functions #[inline(always)] static pure fn identity() -> Mat3 { @@ -413,7 +404,12 @@ pub impl Mat3: Matrix3> { #[inline(always)] pure fn to_mat4(&self) -> Mat4 { - Mat4::from_Mat3(self) + let _0 = Number::from(0); + let _1 = Number::from(1); + Mat4::new(self[0][0], self[0][1], self[0][2], _0, + self[1][0], self[1][1], self[1][2], _0, + self[2][0], self[2][1], self[2][2], _0, + _0, _0, _0, _1) } pure fn to_Quat() -> Quat { diff --git a/src/mat4.rs b/src/mat4.rs index 151ec96..59dc689 100644 --- a/src/mat4.rs +++ b/src/mat4.rs @@ -122,26 +122,6 @@ pub impl Mat4 { _0, _0, _0, value) } - #[inline(always)] - static pure fn from_Mat2(m: &Mat2) -> Mat4 { - let _0 = Number::from(0); - let _1 = Number::from(1); - Mat4::new(m[0][0], m[0][1], _0, _0, - m[1][0], m[1][1], _0, _0, - _0, _0, _1, _0, - _0, _0, _0, _1) - } - - #[inline(always)] - static pure fn from_Mat3(m: &Mat3) -> Mat4 { - let _0 = Number::from(0); - let _1 = Number::from(1); - Mat4::new(m[0][0], m[0][1], m[0][2], _0, - m[1][0], m[1][1], m[1][2], _0, - m[2][0], m[2][1], m[2][2], _0, - _0, _0, _0, _1) - } - // FIXME: An interim solution to the issues with static functions #[inline(always)] static pure fn identity() -> Mat4 { diff --git a/src/test/test_mat.rs b/src/test/test_mat.rs index 904b0f3..b8f6163 100644 --- a/src/test/test_mat.rs +++ b/src/test/test_mat.rs @@ -177,15 +177,6 @@ fn test_Mat3() { Vec3::new(2f, 5f, 8f), Vec3::new(3f, 6f, 9f)); - assert Mat3::from_value(4f64) == Mat3::new(4f64, 0f64, 0f64, - 0f64, 4f64, 0f64, - 0f64, 0f64, 4f64); - - assert Mat3::from_Mat2(&Mat2::new(1f32, 3f32, - 2f32, 4f32)) == Mat3::new(1f32, 3f32, 0f32, - 2f32, 4f32, 0f32, - 0f32, 0f32, 1f32); - assert a[0] == Vec3::new(1f, 4f, 7f); assert a[1] == Vec3::new(2f, 5f, 8f); assert a[2] == Vec3::new(3f, 6f, 9f); @@ -385,19 +376,6 @@ fn test_Mat4() { 0f64, 0f64, 4f64, 0f64, 0f64, 0f64, 0f64, 4f64); - assert Mat4::from_Mat2(&Mat2::new(1f, 3f, - 2f, 4f)) == Mat4::new(1f, 3f, 0f, 0f, - 2f, 4f, 0f, 0f, - 0f, 0f, 1f, 0f, - 0f, 0f, 0f, 1f); - - assert Mat4::from_Mat3(&Mat3::new(1f32, 4f32, 7f32, - 2f32, 5f32, 8f32, - 3f32, 6f32, 9f32)) == Mat4::new(1f32, 4f32, 7f32, 0f32, - 2f32, 5f32, 8f32, 0f32, - 3f32, 6f32, 9f32, 0f32, - 0f32, 0f32, 0f32, 1f32); - assert a[0] == Vec4::new(1f, 5f, 9f, 13f); assert a[1] == Vec4::new(2f, 6f, 10f, 14f); assert a[2] == Vec4::new(3f, 7f, 11f, 15f);