diff --git a/src/gltypes.rs b/src/gltypes.rs index 1e2f46f..211a54c 100644 --- a/src/gltypes.rs +++ b/src/gltypes.rs @@ -182,62 +182,110 @@ pub type dmat4x4 = Mat4; /// 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() } } diff --git a/src/mat.rs b/src/mat.rs index 1cb1f46..c5dec31 100644 --- a/src/mat.rs +++ b/src/mat.rs @@ -26,6 +26,48 @@ pub trait Matrix: Dimensional, Eq, DefaultEq { pure fn row(i: uint) -> Row; } +// /// A 2 x N matrix +// pub trait Matrix2: Matrix { +// /// 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: Matrix2 { +// /// 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: Matrix { +// /// 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: Matrix3 { +// /// 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: Matrix { +// /// 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: Matrix4 { +// /// 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: NumericMatrix_NxN> { // pub struct Mat2 { x: Vec2, y: Vec2 } -pub mod Mat2 { - +pub impl Mat2 { #[inline(always)] - pub pure fn new(c0r0: T, c0r1: T, + static pure fn new(c0r0: T, c0r1: T, c1r0: T, c1r1: T) -> Mat2 { Mat2::from_cols(Vec2::new(move c0r0, move c0r1), Vec2::new(move c1r0, move c1r1)) } #[inline(always)] - pub pure fn from_cols(c0: Vec2, c1: Vec2) -> Mat2 { + static pure fn from_cols(c0: Vec2, c1: Vec2) -> Mat2 { Mat2 { x: move c0, y: move c1 } } #[inline(always)] - pub pure fn from_value(value: T) -> Mat2 { + static pure fn from_value(value: T) -> Mat2 { let _0 = cast(0); Mat2::new(value, _0, _0, value) @@ -298,10 +339,9 @@ pub impl Mat2: DefaultEq { // pub struct Mat3 { x: Vec3, y: Vec3, z: Vec3 } -pub mod Mat3 { - +pub impl Mat3 { #[inline(always)] - pub pure fn new(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 { 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(c0: Vec3, c1: Vec3, c2: Vec3) -> Mat3 { + static pure fn from_cols(c0: Vec3, c1: Vec3, c2: Vec3) -> Mat3 { Mat3 { x: move c0, y: move c1, z: move c2 } } #[inline(always)] - pub pure fn from_value(value: T) -> Mat3 { + static pure fn from_value(value: T) -> Mat3 { 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(m: &Mat2) -> Mat3 { + static pure fn from_Mat2(m: &Mat2) -> Mat3 { let _0 = cast(0); let _1 = cast(1); Mat3::new(m[0][0], m[0][1], _0, @@ -588,10 +628,9 @@ pub impl Mat3: DefaultEq { // pub struct Mat4 { x: Vec4, y: Vec4, z: Vec4, w: Vec4 } -pub mod Mat4 { - +pub impl Mat4 { #[inline(always)] - pub pure fn new(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 { @@ -602,7 +641,7 @@ pub mod Mat4 { } #[inline(always)] - pub pure fn from_cols(c0: Vec4, c1: Vec4, c2: Vec4, c3: Vec4) -> Mat4 { + static pure fn from_cols(c0: Vec4, c1: Vec4, c2: Vec4, c3: Vec4) -> Mat4 { Mat4 { x: move c0, y: move c1, z: move c2, @@ -610,7 +649,7 @@ pub mod Mat4 { } #[inline(always)] - pub pure fn from_value(value: T) -> Mat4 { + static pure fn from_value(value: T) -> Mat4 { 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(m: &Mat2) -> Mat4 { + static pure fn from_Mat2(m: &Mat2) -> Mat4 { 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(m: &Mat3) -> Mat4 { + static pure fn from_Mat3(m: &Mat3) -> Mat4 { let _0 = cast(0); let _1 = cast(1); Mat4::new(m[0][0], m[0][1], m[0][2], _0,