Remove from_mat constructors

We already have the to_mat conversion methods, so these are redundant
This commit is contained in:
Brendan Zabarauskas 2012-12-14 18:37:02 +10:00
parent 9820436633
commit 563aa9495e
5 changed files with 66 additions and 56 deletions

View file

@ -249,7 +249,36 @@ pub trait MutableMatrix<T,V>: Matrix<T,V> {
* A 2 x 2 matrix
*/
pub trait Matrix2<T,V>: Matrix<T,V> {
/**
* 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<T>;
/**
* 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<T>;
}
@ -257,7 +286,26 @@ pub trait Matrix2<T,V>: Matrix<T,V> {
* A 3 x 3 matrix
*/
pub trait Matrix3<T,V>: Matrix<T,V> {
/**
* Construct a matrix from an axis and an
*/
static pure fn from_axis_angle<A:Angle<T>>(axis: &V, theta: A) -> Mat3<T>;
/**
* 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<T>;
/**
@ -269,5 +317,4 @@ pub trait Matrix3<T,V>: Matrix<T,V> {
/**
* A 4 x 4 matrix
*/
pub trait Matrix4<T,V>: Matrix<T,V> {
}
pub trait Matrix4<T,V>: Matrix<T,V> {}

View file

@ -333,12 +333,21 @@ pub impl<T:Copy Float Sign> Mat2<T>: MutableMatrix<T, Vec2<T>> {
pub impl<T:Copy Float> Mat2<T>: Matrix2<T, Vec2<T>> {
#[inline(always)]
pure fn to_mat3(&self) -> Mat3<T> {
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<T> {
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)
}
}

View file

@ -111,15 +111,6 @@ pub impl<T:Copy Float> Mat3<T> {
_0, _0, value)
}
#[inline(always)]
static pure fn from_Mat2(m: &Mat2<T>) -> Mat3<T> {
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<T> {
@ -413,7 +404,12 @@ pub impl<T:Copy Float Exp> Mat3<T>: Matrix3<T, Vec3<T>> {
#[inline(always)]
pure fn to_mat4(&self) -> Mat4<T> {
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<T> {

View file

@ -122,26 +122,6 @@ pub impl<T:Copy Float> Mat4<T> {
_0, _0, _0, value)
}
#[inline(always)]
static pure fn from_Mat2(m: &Mat2<T>) -> Mat4<T> {
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<T>) -> Mat4<T> {
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<T> {

View file

@ -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);