Change const functions to const values
This commit is contained in:
parent
820ea22407
commit
fc83b7a17d
4 changed files with 64 additions and 66 deletions
76
src/mat.rs
76
src/mat.rs
|
@ -67,6 +67,11 @@ trait Matrix4<T:Num Ord FuzzyEq, V:Vector<T>> {
|
|||
//
|
||||
struct mat2 { data:[vec2 * 2] }
|
||||
|
||||
const mat2_zero :mat2 = mat2 { data: [ vec2_zero,
|
||||
vec2_zero ] };
|
||||
const mat2_identity :mat2 = mat2 { data: [ vec2_unit_x,
|
||||
vec2_unit_y ] };
|
||||
|
||||
//
|
||||
// Mat2 Constructor
|
||||
//
|
||||
|
@ -85,18 +90,6 @@ pure fn mat2_v(col0:vec2, col1:vec2) -> mat2 {
|
|||
mat2 { data: [ col0, col1 ] }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mat2_zero() -> mat2 {
|
||||
mat2(0f, 0f,
|
||||
0f, 0f)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mat2_identity() -> mat2 {
|
||||
mat2(1f, 0f,
|
||||
0f, 1f)
|
||||
}
|
||||
|
||||
//
|
||||
// Matrix2x2 Implementation
|
||||
//
|
||||
|
@ -193,7 +186,7 @@ impl mat2: Matrix<float, vec2> {
|
|||
|
||||
#[inline(always)]
|
||||
pure fn is_identity() -> bool {
|
||||
self.fuzzy_eq(mat2_identity())
|
||||
self.fuzzy_eq(mat2_identity)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -210,7 +203,7 @@ impl mat2: Matrix<float, vec2> {
|
|||
|
||||
#[inline(always)]
|
||||
pure fn is_rotated() -> bool {
|
||||
!self.fuzzy_eq(mat2_identity())
|
||||
!self.fuzzy_eq(mat2_identity)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -224,6 +217,13 @@ impl mat2: Matrix<float, vec2> {
|
|||
//
|
||||
struct mat3 { data:[vec3 * 3] }
|
||||
|
||||
const mat3_zero :mat3 = mat3 { data: [ vec3_zero,
|
||||
vec3_zero,
|
||||
vec3_zero ] };
|
||||
const mat3_identity :mat3 = mat3 { data: [ vec3_unit_x,
|
||||
vec3_unit_y,
|
||||
vec3_unit_z ] };
|
||||
|
||||
//
|
||||
// Mat3 Constructor
|
||||
//
|
||||
|
@ -244,20 +244,6 @@ pure fn mat3_v(col0:vec3, col1:vec3, col2:vec3) -> mat3 {
|
|||
mat3 { data: [ col0, col1, col2 ] }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mat3_zero() -> mat3 {
|
||||
mat3 (0f, 0f, 0f,
|
||||
0f, 0f, 0f,
|
||||
0f, 0f, 0f)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mat3_identity() -> mat3 {
|
||||
mat3 (1f, 0f, 0f,
|
||||
0f, 1f, 0f,
|
||||
0f, 0f, 1f)
|
||||
}
|
||||
|
||||
//
|
||||
// Matrix3x3 Implementation
|
||||
//
|
||||
|
@ -368,7 +354,7 @@ impl mat3: Matrix<float, vec3> {
|
|||
|
||||
#[inline(always)]
|
||||
pure fn is_identity() -> bool {
|
||||
self.fuzzy_eq(mat3_identity())
|
||||
self.fuzzy_eq(mat3_identity)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -397,7 +383,7 @@ impl mat3: Matrix<float, vec3> {
|
|||
|
||||
#[inline(always)]
|
||||
pure fn is_rotated() -> bool {
|
||||
!self.fuzzy_eq(mat3_identity())
|
||||
!self.fuzzy_eq(mat3_identity)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -454,7 +440,6 @@ impl mat3: Matrix3<float, vec3> {
|
|||
y = self[1][2] - self[2][1] * s;
|
||||
z = self[0][1] - self[1][0] * s;
|
||||
}
|
||||
return quat(w, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -468,6 +453,15 @@ impl mat3: Matrix3<float, vec3> {
|
|||
//
|
||||
struct mat4 { data:[vec4 * 4] }
|
||||
|
||||
const mat4_zero :mat4 = mat4 { data: [ vec4_zero,
|
||||
vec4_zero,
|
||||
vec4_zero,
|
||||
vec4_zero ] };
|
||||
const mat4_identity :mat4 = mat4 { data: [ vec4_unit_x,
|
||||
vec4_unit_y,
|
||||
vec4_unit_z,
|
||||
vec4_unit_w ] };
|
||||
|
||||
//
|
||||
// Mat4 Constructor
|
||||
//
|
||||
|
@ -490,22 +484,6 @@ pure fn mat4_v(col0:vec4, col1:vec4, col2:vec4, col3:vec4) -> mat4 {
|
|||
mat4 { data: [ col0, col1, col2, col3 ] }
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mat4_zero() -> mat4 {
|
||||
mat4 (0f, 0f, 0f, 0f,
|
||||
0f, 0f, 0f, 0f,
|
||||
0f, 0f, 0f, 0f,
|
||||
0f, 0f, 0f, 0f)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
pure fn mat4_identity() -> mat4 {
|
||||
mat4 (1f, 0f, 0f, 0f,
|
||||
0f, 1f, 0f, 0f,
|
||||
0f, 0f, 1f, 0f,
|
||||
0f, 0f, 0f, 1f)
|
||||
}
|
||||
|
||||
//
|
||||
// Matrix4x4 Implementation
|
||||
//
|
||||
|
@ -632,7 +610,7 @@ impl mat4: Matrix<float, vec4> {
|
|||
|
||||
#[inline(always)]
|
||||
pure fn is_identity() -> bool {
|
||||
self.fuzzy_eq(mat4_identity())
|
||||
self.fuzzy_eq(mat4_identity)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
|
@ -675,7 +653,7 @@ impl mat4: Matrix<float, vec4> {
|
|||
|
||||
#[inline(always)]
|
||||
pure fn is_rotated() -> bool {
|
||||
!self.fuzzy_eq(mat4_identity())
|
||||
!self.fuzzy_eq(mat4_identity)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -54,11 +54,8 @@ trait Quaternion<T:Num Ord FuzzyEq> {
|
|||
//
|
||||
struct quat { data:[float * 4] }
|
||||
|
||||
//
|
||||
// Constants
|
||||
//
|
||||
#[inline(always)] pure fn quat_zero() -> quat { quat(0f, 0f, 0f, 0f) }
|
||||
#[inline(always)] pure fn quat_identity() -> quat { quat(1f, 0f, 0f, 0f) }
|
||||
const quat_zero :quat = quat { data: [ 0f, 0f, 0f, 0f ] };
|
||||
const quat_identity :quat = quat { data: [ 1f, 0f, 0f, 0f ] };
|
||||
|
||||
//
|
||||
// Quat Constructor
|
||||
|
|
|
@ -49,10 +49,10 @@ fn test_mat2() {
|
|||
// fuzzy_eq
|
||||
// eq
|
||||
|
||||
assert mat2_identity().is_identity();
|
||||
assert mat2_identity().is_symmetric();
|
||||
assert mat2_identity().is_diagonal();
|
||||
assert !mat2_identity().is_rotated();
|
||||
assert mat2_identity.is_identity();
|
||||
assert mat2_identity.is_symmetric();
|
||||
assert mat2_identity.is_diagonal();
|
||||
assert !mat2_identity.is_rotated();
|
||||
|
||||
assert !a.is_identity();
|
||||
assert !a.is_symmetric();
|
||||
|
@ -126,10 +126,10 @@ fn test_mat3() {
|
|||
// fuzzy_eq
|
||||
// eq
|
||||
|
||||
assert mat3_identity().is_identity();
|
||||
assert mat3_identity().is_symmetric();
|
||||
assert mat3_identity().is_diagonal();
|
||||
assert !mat3_identity().is_rotated();
|
||||
assert mat3_identity.is_identity();
|
||||
assert mat3_identity.is_symmetric();
|
||||
assert mat3_identity.is_diagonal();
|
||||
assert !mat3_identity.is_rotated();
|
||||
|
||||
assert !a.is_identity();
|
||||
assert !a.is_symmetric();
|
||||
|
@ -224,10 +224,10 @@ fn test_mat4() {
|
|||
// fuzzy_eq
|
||||
// eq
|
||||
|
||||
assert mat4_identity().is_identity();
|
||||
assert mat4_identity().is_symmetric();
|
||||
assert mat4_identity().is_diagonal();
|
||||
assert !mat4_identity().is_rotated();
|
||||
assert mat4_identity.is_identity();
|
||||
assert mat4_identity.is_symmetric();
|
||||
assert mat4_identity.is_diagonal();
|
||||
assert !mat4_identity.is_rotated();
|
||||
|
||||
assert !a.is_identity();
|
||||
assert !a.is_symmetric();
|
||||
|
|
|
@ -1,6 +1,29 @@
|
|||
import om3d::mat::*;
|
||||
import om3d::quat::*;
|
||||
import om3d::vec::*;
|
||||
|
||||
// TODO
|
||||
|
||||
#[test]
|
||||
fn test_quat() {
|
||||
let a = quat { data: [ 1f, 2f, 3f, 4f ] };
|
||||
// let b = quat { data: [ 5f, 6f, 7f, 8f ] };
|
||||
// let f1 = 1.5f;
|
||||
// let f2 = 0.5f;
|
||||
|
||||
assert a == quat(1f, 2f, 3f, 4f);
|
||||
|
||||
assert quat_zero == quat(0f, 0f, 0f, 0f);
|
||||
assert quat_identity == quat(1f, 0f, 0f, 0f);
|
||||
|
||||
assert a[0] == 1f;
|
||||
assert a[1] == 2f;
|
||||
assert a[2] == 3f;
|
||||
assert a[3] == 4f;
|
||||
assert a.w() == 1f;
|
||||
assert a.x() == 2f;
|
||||
assert a.y() == 3f;
|
||||
assert a.z() == 4f;
|
||||
|
||||
// TODO
|
||||
}
|
Loading…
Reference in a new issue