Change matrix constructors to static methods
This commit is contained in:
parent
a030f4cf19
commit
525c3f9354
2 changed files with 105 additions and 18 deletions
|
@ -182,62 +182,110 @@ pub type dmat4x4 = Mat4<f64>; /// same as a `dmat4`
|
|||
//
|
||||
|
||||
pub impl mat2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f32, c0r1: f32, c1r0: f32, c1r1: f32)
|
||||
-> mat2 { mat2x2::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 identity() -> mat2 { mat2x2::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat2 { mat2x2::zero() }
|
||||
}
|
||||
|
||||
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 identity() -> mat3 { mat3x3::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat3 { mat3x3::zero() }
|
||||
}
|
||||
|
||||
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 identity() -> mat4 { mat4x4::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat4 { mat4x4::zero() }
|
||||
}
|
||||
|
||||
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 identity() -> mat2x2 { NumericMatrix_NxN::identity() }
|
||||
#[inline(always)] static pure fn zero() -> mat2x2 { NumericMatrix::zero() }
|
||||
}
|
||||
|
||||
pub impl mat3x3 {
|
||||
#[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) }
|
||||
#[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 zero() -> mat3x3 { NumericMatrix::zero() }
|
||||
}
|
||||
|
||||
pub impl mat4x4 {
|
||||
#[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) }
|
||||
#[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 zero() -> mat4x4 { NumericMatrix::zero() }
|
||||
}
|
||||
|
||||
|
||||
pub impl dmat2 {
|
||||
#[inline(always)] static pure fn new(c0r0: f64, c0r1: f64, c1r0: f64, c1r1: f64)
|
||||
-> dmat2 { dmat2x2::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 identity() -> dmat2 { dmat2x2::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat2 { NumericMatrix::zero() }
|
||||
}
|
||||
|
||||
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() }
|
||||
}
|
||||
|
||||
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() }
|
||||
}
|
||||
|
||||
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 identity() -> dmat2x2 { NumericMatrix_NxN::identity() }
|
||||
#[inline(always)] static pure fn zero() -> dmat2x2 { NumericMatrix::zero() }
|
||||
}
|
||||
|
||||
pub impl dmat3x3 {
|
||||
#[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) }
|
||||
#[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 zero() -> dmat3x3 { NumericMatrix::zero() }
|
||||
}
|
||||
|
||||
pub impl dmat4x4 {
|
||||
#[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) }
|
||||
#[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 zero() -> dmat4x4 { NumericMatrix::zero() }
|
||||
}
|
||||
|
|
75
src/mat.rs
75
src/mat.rs
|
@ -26,6 +26,48 @@ pub trait Matrix<T, Col, Row>: Dimensional<T>, Eq, DefaultEq {
|
|||
pure fn row(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 2 x 2 square matrix
|
||||
// pub trait Matrix2x2<T, ColRow>: Matrix2<T, 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 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 3 x 3 square matrix
|
||||
// pub trait Matrix3x3<T, ColRow>: Matrix3<T, 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 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 4 x 4 square matrix
|
||||
// pub trait Matrix4x4<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
|
||||
///
|
||||
|
@ -84,23 +126,22 @@ pub trait NumericMatrix4x4<T>: NumericMatrix_NxN<T, Mat4<T>> {
|
|||
//
|
||||
pub struct Mat2<T> { x: Vec2<T>, y: Vec2<T> }
|
||||
|
||||
pub mod Mat2 {
|
||||
|
||||
pub impl<T:Copy NumCast> Mat2<T> {
|
||||
#[inline(always)]
|
||||
pub pure fn new<T>(c0r0: T, c0r1: T,
|
||||
static pure fn new(c0r0: T, c0r1: T,
|
||||
c1r0: T, c1r1: T) -> Mat2<T> {
|
||||
Mat2::from_cols(Vec2::new(move c0r0, move c0r1),
|
||||
Vec2::new(move c1r0, move c1r1))
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn from_cols<T>(c0: Vec2<T>, c1: Vec2<T>) -> Mat2<T> {
|
||||
static pure fn from_cols(c0: Vec2<T>, c1: Vec2<T>) -> Mat2<T> {
|
||||
Mat2 { x: move c0,
|
||||
y: move c1 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn from_value<T:Copy NumCast>(value: T) -> Mat2<T> {
|
||||
static pure fn from_value(value: T) -> Mat2<T> {
|
||||
let _0 = cast(0);
|
||||
Mat2::new(value, _0,
|
||||
_0, value)
|
||||
|
@ -298,10 +339,9 @@ pub impl<T:Copy DefaultEq> Mat2<T>: DefaultEq {
|
|||
//
|
||||
pub struct Mat3<T> { x: Vec3<T>, y: Vec3<T>, z: Vec3<T> }
|
||||
|
||||
pub mod Mat3 {
|
||||
|
||||
pub impl<T:Copy NumCast> Mat3<T> {
|
||||
#[inline(always)]
|
||||
pub pure fn new<T>(c0r0:T, c0r1:T, c0r2:T,
|
||||
static pure fn new(c0r0:T, c0r1:T, c0r2:T,
|
||||
c1r0:T, c1r1:T, c1r2:T,
|
||||
c2r0:T, c2r1:T, c2r2:T) -> Mat3<T> {
|
||||
Mat3::from_cols(Vec3::new(move c0r0, move c0r1, move c0r2),
|
||||
|
@ -310,14 +350,14 @@ pub mod Mat3 {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn from_cols<T>(c0: Vec3<T>, c1: Vec3<T>, c2: Vec3<T>) -> Mat3<T> {
|
||||
static pure fn from_cols(c0: Vec3<T>, c1: Vec3<T>, c2: Vec3<T>) -> Mat3<T> {
|
||||
Mat3 { x: move c0,
|
||||
y: move c1,
|
||||
z: move c2 }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn from_value<T:Copy NumCast>(value: T) -> Mat3<T> {
|
||||
static pure fn from_value(value: T) -> Mat3<T> {
|
||||
let _0 = cast(0);
|
||||
Mat3::new(value, _0, _0,
|
||||
_0, value, _0,
|
||||
|
@ -325,7 +365,7 @@ pub mod Mat3 {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn from_Mat2<T:Copy NumCast>(m: &Mat2<T>) -> Mat3<T> {
|
||||
static pure fn from_Mat2(m: &Mat2<T>) -> Mat3<T> {
|
||||
let _0 = cast(0);
|
||||
let _1 = cast(1);
|
||||
Mat3::new(m[0][0], m[0][1], _0,
|
||||
|
@ -588,10 +628,9 @@ pub impl<T:Copy DefaultEq> Mat3<T>: DefaultEq {
|
|||
//
|
||||
pub struct Mat4<T> { x: Vec4<T>, y: Vec4<T>, z: Vec4<T>, w: Vec4<T> }
|
||||
|
||||
pub mod Mat4 {
|
||||
|
||||
pub impl<T:Copy NumCast> Mat4<T> {
|
||||
#[inline(always)]
|
||||
pub pure fn new<T>(c0r0: T, c0r1: T, c0r2: T, c0r3: T,
|
||||
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) -> Mat4<T> {
|
||||
|
@ -602,7 +641,7 @@ pub mod Mat4 {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn from_cols<T>(c0: Vec4<T>, c1: Vec4<T>, c2: Vec4<T>, c3: Vec4<T>) -> Mat4<T> {
|
||||
static pure fn from_cols(c0: Vec4<T>, c1: Vec4<T>, c2: Vec4<T>, c3: Vec4<T>) -> Mat4<T> {
|
||||
Mat4 { x: move c0,
|
||||
y: move c1,
|
||||
z: move c2,
|
||||
|
@ -610,7 +649,7 @@ pub mod Mat4 {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn from_value<T:Copy NumCast>(value: T) -> Mat4<T> {
|
||||
static pure fn from_value(value: T) -> Mat4<T> {
|
||||
let _0 = cast(0);
|
||||
Mat4::new(value, _0, _0, _0,
|
||||
_0, value, _0, _0,
|
||||
|
@ -619,7 +658,7 @@ pub mod Mat4 {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn from_Mat2<T:Copy NumCast>(m: &Mat2<T>) -> Mat4<T> {
|
||||
static pure fn from_Mat2(m: &Mat2<T>) -> Mat4<T> {
|
||||
let _0 = cast(0);
|
||||
let _1 = cast(1);
|
||||
Mat4::new(m[0][0], m[0][1], _0, _0,
|
||||
|
@ -629,7 +668,7 @@ pub mod Mat4 {
|
|||
}
|
||||
|
||||
#[inline(always)]
|
||||
pub pure fn from_Mat3<T:Copy NumCast>(m: &Mat3<T>) -> Mat4<T> {
|
||||
static pure fn from_Mat3(m: &Mat3<T>) -> Mat4<T> {
|
||||
let _0 = cast(0);
|
||||
let _1 = cast(1);
|
||||
Mat4::new(m[0][0], m[0][1], m[0][2], _0,
|
||||
|
|
Loading…
Reference in a new issue