Fix constructors, tests now pass (YAYAY!)
YAYYYYYYYYAYAYAYAYAYAYAY *jumps for joy*
This commit is contained in:
parent
36039228b6
commit
a485920354
6 changed files with 793 additions and 381 deletions
137
src/mat.rs
137
src/mat.rs
|
@ -688,6 +688,47 @@ impl<T:Copy + Float + NumAssign> ApproxEq<T> for Mat2<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! mat2_type(
|
||||||
|
($name:ident <$T:ty, $V:ty>) => (
|
||||||
|
pub mod $name {
|
||||||
|
use vec::*;
|
||||||
|
use super::*;
|
||||||
|
#[inline(always)] pub fn new(c0r0: $T, c0r1: $T, c1r0: $T, c1r1: $T)
|
||||||
|
-> $name { BaseMat2::new(c0r0, c0r1, c1r0, c1r1) }
|
||||||
|
#[inline(always)] pub fn from_cols(c0: $V, c1: $V)
|
||||||
|
-> $name { BaseMat2::from_cols(c0, c1) }
|
||||||
|
#[inline(always)] pub fn from_value(v: $T) -> $name { BaseMat::from_value(v) }
|
||||||
|
#[inline(always)] pub fn identity() -> $name { BaseMat::identity() }
|
||||||
|
#[inline(always)] pub fn zero() -> $name { BaseMat::zero() }
|
||||||
|
#[inline(always)] pub fn from_angle(radians: $T) -> $name { BaseMat2::from_angle(radians) }
|
||||||
|
#[inline(always)] pub fn dim() -> uint { 2 }
|
||||||
|
#[inline(always)] pub fn rows() -> uint { 2 }
|
||||||
|
#[inline(always)] pub fn cols() -> uint { 2 }
|
||||||
|
#[inline(always)] pub fn size_of() -> uint { sys::size_of::<$name>() }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
// GLSL-style type aliases, corresponding to Section 4.1.6 of the [GLSL 4.30.6 specification]
|
||||||
|
// (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf).
|
||||||
|
|
||||||
|
// a 2×2 single-precision floating-point matrix
|
||||||
|
pub type mat2 = Mat2<f32>;
|
||||||
|
// a 2×2 double-precision floating-point matrix
|
||||||
|
pub type dmat2 = Mat2<f64>;
|
||||||
|
|
||||||
|
mat2_type!(mat2<f32,vec2>)
|
||||||
|
mat2_type!(dmat2<f64,dvec2>)
|
||||||
|
|
||||||
|
// Rust-style type aliases
|
||||||
|
pub type Mat2f = Mat2<float>;
|
||||||
|
pub type Mat2f32 = Mat2<f32>;
|
||||||
|
pub type Mat2f64 = Mat2<f64>;
|
||||||
|
|
||||||
|
mat2_type!(Mat2f<float,Vec2f>)
|
||||||
|
mat2_type!(Mat2f32<f32,Vec2f32>)
|
||||||
|
mat2_type!(Mat2f64<f64,Vec2f64>)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A 3 x 3 column major matrix
|
* A 3 x 3 column major matrix
|
||||||
*
|
*
|
||||||
|
@ -1254,6 +1295,55 @@ impl<T:Copy + Float + NumAssign> ApproxEq<T> for Mat3<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! mat3_type(
|
||||||
|
($name:ident <$T:ty, $V:ty>) => (
|
||||||
|
pub mod $name {
|
||||||
|
use vec::*;
|
||||||
|
use super::*;
|
||||||
|
#[inline(always)] pub fn new(c0r0: $T, c0r1: $T, c0r2: $T,
|
||||||
|
c1r0: $T, c1r1: $T, c1r2: $T,
|
||||||
|
c2r0: $T, c2r1: $T, c2r2: $T) -> $name {
|
||||||
|
BaseMat3::new(c0r0, c0r1, c0r2,
|
||||||
|
c1r0, c1r1, c1r2,
|
||||||
|
c2r0, c2r1, c2r2)
|
||||||
|
}
|
||||||
|
#[inline(always)] pub fn from_cols(c0: $V, c1: $V, c2: $V)
|
||||||
|
-> $name { BaseMat3::from_cols(c0, c1, c2) }
|
||||||
|
#[inline(always)] pub fn from_value(v: $T) -> $name { BaseMat::from_value(v) }
|
||||||
|
#[inline(always)] pub fn identity() -> $name { BaseMat::identity() }
|
||||||
|
#[inline(always)] pub fn zero() -> $name { BaseMat::zero() }
|
||||||
|
#[inline(always)] pub fn from_angle_x(radians: $T) -> $name { BaseMat3::from_angle_x(radians) }
|
||||||
|
#[inline(always)] pub fn from_angle_y(radians: $T) -> $name { BaseMat3::from_angle_y(radians) }
|
||||||
|
#[inline(always)] pub fn from_angle_z(radians: $T) -> $name { BaseMat3::from_angle_z(radians) }
|
||||||
|
#[inline(always)] pub fn from_angle_xyz(radians_x: $T, radians_y: $T, radians_z: $T) -> $name { BaseMat3::from_angle_xyz(radians_x, radians_y, radians_z) }
|
||||||
|
#[inline(always)] pub fn from_angle_axis(radians: $T, axis: &$V) -> $name { BaseMat3::from_angle_axis(radians, axis) }
|
||||||
|
#[inline(always)] pub fn from_axes(x: $V, y: $V, z: $V) -> $name { BaseMat3::from_axes(x, y, z) }
|
||||||
|
#[inline(always)] pub fn look_at(dir: &$V, up: &$V) -> $name { BaseMat3::look_at(dir, up) }
|
||||||
|
#[inline(always)] pub fn dim() -> uint { 3 }
|
||||||
|
#[inline(always)] pub fn rows() -> uint { 3 }
|
||||||
|
#[inline(always)] pub fn cols() -> uint { 3 }
|
||||||
|
#[inline(always)] pub fn size_of() -> uint { sys::size_of::<$name>() }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
// a 3×3 single-precision floating-point matrix
|
||||||
|
pub type mat3 = Mat3<f32>;
|
||||||
|
// a 3×3 double-precision floating-point matrix
|
||||||
|
pub type dmat3 = Mat3<f64>;
|
||||||
|
|
||||||
|
mat3_type!(mat3<f32,vec3>)
|
||||||
|
mat3_type!(dmat3<f64,dvec3>)
|
||||||
|
|
||||||
|
// Rust-style type aliases
|
||||||
|
pub type Mat3f = Mat3<float>;
|
||||||
|
pub type Mat3f32 = Mat3<f32>;
|
||||||
|
pub type Mat3f64 = Mat3<f64>;
|
||||||
|
|
||||||
|
mat3_type!(Mat3f<float,Vec3f>)
|
||||||
|
mat3_type!(Mat3f32<f32,Vec3f32>)
|
||||||
|
mat3_type!(Mat3f64<f64,Vec3f64>)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A 4 x 4 column major matrix
|
* A 4 x 4 column major matrix
|
||||||
*
|
*
|
||||||
|
@ -1759,3 +1849,50 @@ impl<T:Copy + Float + NumAssign> ApproxEq<T> for Mat4<T> {
|
||||||
self.col(3).approx_eq_eps(other.col(3), epsilon)
|
self.col(3).approx_eq_eps(other.col(3), epsilon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! mat4_type(
|
||||||
|
($name:ident <$T:ty, $V:ty>) => (
|
||||||
|
pub mod $name {
|
||||||
|
use vec::*;
|
||||||
|
use super::*;
|
||||||
|
#[inline(always)] pub 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) -> $name {
|
||||||
|
BaseMat4::new(c0r0, c0r1, c0r2, c0r3,
|
||||||
|
c1r0, c1r1, c1r2, c1r3,
|
||||||
|
c2r0, c2r1, c2r2, c2r3,
|
||||||
|
c3r0, c3r1, c3r2, c3r3)
|
||||||
|
}
|
||||||
|
#[inline(always)] pub fn from_cols(c0: $V, c1: $V, c2: $V, c3: $V)
|
||||||
|
-> $name { BaseMat4::from_cols(c0, c1, c2, c3) }
|
||||||
|
#[inline(always)] pub fn from_value(v: $T) -> $name { BaseMat::from_value(v) }
|
||||||
|
#[inline(always)] pub fn identity() -> $name { BaseMat::identity() }
|
||||||
|
#[inline(always)] pub fn zero() -> $name { BaseMat::zero() }
|
||||||
|
#[inline(always)] pub fn dim() -> uint { 4 }
|
||||||
|
#[inline(always)] pub fn rows() -> uint { 4 }
|
||||||
|
#[inline(always)] pub fn cols() -> uint { 4 }
|
||||||
|
#[inline(always)] pub fn size_of() -> uint { sys::size_of::<$name>() }
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
// GLSL-style type aliases, corresponding to Section 4.1.6 of the [GLSL 4.30.6 specification]
|
||||||
|
// (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf).
|
||||||
|
|
||||||
|
// a 4×4 single-precision floating-point matrix
|
||||||
|
pub type mat4 = Mat4<f32>;
|
||||||
|
// a 4×4 double-precision floating-point matrix
|
||||||
|
pub type dmat4 = Mat4<f64>;
|
||||||
|
|
||||||
|
mat4_type!(mat4<f32,vec4>)
|
||||||
|
mat4_type!(dmat4<f64,dvec4>)
|
||||||
|
|
||||||
|
// Rust-style type aliases
|
||||||
|
pub type Mat4f = Mat4<float>;
|
||||||
|
pub type Mat4f32 = Mat4<f32>;
|
||||||
|
pub type Mat4f64 = Mat4<f64>;
|
||||||
|
|
||||||
|
mat4_type!(Mat4f<float,Vec4f>)
|
||||||
|
mat4_type!(Mat4f32<f32,Vec4f32>)
|
||||||
|
mat4_type!(Mat4f64<f64,Vec4f64>)
|
||||||
|
|
43
src/quat.rs
43
src/quat.rs
|
@ -431,3 +431,46 @@ impl<T:Copy + Eq + Float + NumAssign> ApproxEq<T> for Quat<T> {
|
||||||
self.index(3).approx_eq_eps(other.index(3), epsilon)
|
self.index(3).approx_eq_eps(other.index(3), epsilon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! quat_type(
|
||||||
|
($name:ident <$T:ty, $V:ty>) => (
|
||||||
|
pub mod $name {
|
||||||
|
use vec::*;
|
||||||
|
use super::*;
|
||||||
|
#[inline(always)] pub fn new(w: $T, xi: $T, yj: $T, zk: $T) -> $name { Quat::new(w, xi, yj, zk) }
|
||||||
|
#[inline(always)] pub fn from_sv(s: $T, v: $V) -> $name { Quat::from_sv(s, v) }
|
||||||
|
#[inline(always)] pub fn identity() -> $name { Quat::identity() }
|
||||||
|
#[inline(always)] pub fn zero() -> $name { Quat::zero() }
|
||||||
|
#[inline(always)] pub fn from_angle_x(radians: $T) -> $name { Quat::from_angle_x(radians) }
|
||||||
|
#[inline(always)] pub fn from_angle_y(radians: $T) -> $name { Quat::from_angle_y(radians) }
|
||||||
|
#[inline(always)] pub fn from_angle_z(radians: $T) -> $name { Quat::from_angle_z(radians) }
|
||||||
|
#[inline(always)] pub fn from_angle_xyz(radians_x: $T, radians_y: $T, radians_z: $T)
|
||||||
|
-> $name { Quat::from_angle_xyz(radians_x, radians_y, radians_z) }
|
||||||
|
#[inline(always)] pub fn from_angle_axis(radians: $T, axis: &$V) -> $name { Quat::from_angle_axis(radians, axis) }
|
||||||
|
#[inline(always)] pub fn from_axes(x: $V, y: $V, z: $V) -> $name { Quat::from_axes(x, y, z) }
|
||||||
|
#[inline(always)] pub fn look_at(dir: &$V, up: &$V) -> $name { Quat::look_at(dir, up) }
|
||||||
|
#[inline(always)] pub fn dim() -> uint { 4 }
|
||||||
|
#[inline(always)] pub fn size_of() -> uint { sys::size_of::<$name>() }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
)
|
||||||
|
|
||||||
|
// GLSL-style type aliases for quaternions. These are not present in the GLSL
|
||||||
|
// specification, but they roughly follow the same nomenclature.
|
||||||
|
|
||||||
|
/// a single-precision floating-point quaternion
|
||||||
|
type quat = Quat<f32>;
|
||||||
|
/// a double-precision floating-point quaternion
|
||||||
|
type dquat = Quat<f64>;
|
||||||
|
|
||||||
|
quat_type!(quat<f32,vec3>)
|
||||||
|
quat_type!(dquat<f64,dvec3>)
|
||||||
|
|
||||||
|
// Rust-style type aliases
|
||||||
|
type Quatf = Quat<float>;
|
||||||
|
type Quatf32 = Quat<f32>;
|
||||||
|
type Quatf64 = Quat<f64>;
|
||||||
|
|
||||||
|
quat_type!(Quatf<float,Vec3f>)
|
||||||
|
quat_type!(Quatf32<f32,Vec3f32>)
|
||||||
|
quat_type!(Quatf64<f64,Vec3f64>)
|
||||||
|
|
|
@ -28,54 +28,54 @@ fn test_mat2() {
|
||||||
let v1 = vec2::new(1.0, 2.0);
|
let v1 = vec2::new(1.0, 2.0);
|
||||||
let f1 = 0.5;
|
let f1 = 0.5;
|
||||||
|
|
||||||
assert!(a == mat2::new(1.0, 3.0,
|
assert_eq!(a, mat2::new(1.0, 3.0,
|
||||||
2.0, 4.0));
|
2.0, 4.0));
|
||||||
|
|
||||||
assert!(a == mat2::from_cols(vec2::new(1.0, 3.0),
|
assert_eq!(a, mat2::from_cols(vec2::new(1.0, 3.0),
|
||||||
vec2::new(2.0, 4.0)));
|
vec2::new(2.0, 4.0)));
|
||||||
|
|
||||||
assert!(mat2::from_value(4.0) == mat2::new(4.0, 0.0,
|
assert_eq!(mat2::from_value(4.0), mat2::new(4.0, 0.0,
|
||||||
0.0, 4.0));
|
0.0, 4.0));
|
||||||
|
|
||||||
assert!(*a.col(0) == vec2::new(1.0, 3.0));
|
assert_eq!(*a.col(0), vec2::new(1.0, 3.0));
|
||||||
assert!(*a.col(1) == vec2::new(2.0, 4.0));
|
assert_eq!(*a.col(1), vec2::new(2.0, 4.0));
|
||||||
|
|
||||||
assert!(a.row(0) == vec2::new(1.0, 2.0));
|
assert_eq!(a.row(0), vec2::new(1.0, 2.0));
|
||||||
assert!(a.row(1) == vec2::new(3.0, 4.0));
|
assert_eq!(a.row(1), vec2::new(3.0, 4.0));
|
||||||
|
|
||||||
assert!(a.col(0) == vec2::new(1.0, 3.0));
|
assert_eq!(*a.col(0), vec2::new(1.0, 3.0));
|
||||||
assert!(a.col(1) == vec2::new(2.0, 4.0));
|
assert_eq!(*a.col(1), vec2::new(2.0, 4.0));
|
||||||
|
|
||||||
assert!(mat2::identity() == mat2::new(1.0, 0.0,
|
assert_eq!(mat2::identity(), mat2::new(1.0, 0.0,
|
||||||
0.0, 1.0));
|
0.0, 1.0));
|
||||||
|
|
||||||
assert!(mat2::zero() == mat2::new(0.0, 0.0,
|
assert_eq!(mat2::zero(), mat2::new(0.0, 0.0,
|
||||||
0.0, 0.0));
|
0.0, 0.0));
|
||||||
|
|
||||||
assert!(a.determinant() == -2.0);
|
assert_eq!(a.determinant(), -2.0);
|
||||||
assert!(a.trace() == 5.0);
|
assert_eq!(a.trace(), 5.0);
|
||||||
|
|
||||||
assert!(a.neg() == mat2::new(-1.0, -3.0,
|
assert_eq!(a.neg(), mat2::new(-1.0, -3.0,
|
||||||
-2.0, -4.0));
|
-2.0, -4.0));
|
||||||
assert!(-a == a.neg());
|
assert_eq!(-a, a.neg());
|
||||||
|
|
||||||
assert!(a.mul_t(f1) == mat2::new(0.5, 1.5,
|
assert_eq!(a.mul_t(f1), mat2::new(0.5, 1.5,
|
||||||
1.0, 2.0));
|
1.0, 2.0));
|
||||||
assert!(a.mul_v(&v1) == vec2::new(5.0, 11.0));
|
assert_eq!(a.mul_v(&v1), vec2::new(5.0, 11.0));
|
||||||
|
|
||||||
assert!(a.add_m(&b) == mat2::new(3.0, 7.0,
|
assert_eq!(a.add_m(&b), mat2::new(3.0, 7.0,
|
||||||
5.0, 9.0));
|
5.0, 9.0));
|
||||||
assert!(a.sub_m(&b) == mat2::new(-1.0, -1.0,
|
assert_eq!(a.sub_m(&b), mat2::new(-1.0, -1.0,
|
||||||
-1.0, -1.0));
|
-1.0, -1.0));
|
||||||
assert!(a.mul_m(&b) == mat2::new(10.0, 22.0,
|
assert_eq!(a.mul_m(&b), mat2::new(10.0, 22.0,
|
||||||
13.0, 29.0));
|
13.0, 29.0));
|
||||||
assert!(a.dot(&b) == 40.0);
|
assert_eq!(a.dot(&b), 40.0);
|
||||||
|
|
||||||
assert!(a.transpose() == mat2::new(1.0, 2.0,
|
assert_eq!(a.transpose(), mat2::new(1.0, 2.0,
|
||||||
3.0, 4.0));
|
3.0, 4.0));
|
||||||
|
|
||||||
assert!(a.inverse().unwrap() == mat2::new(-2.0, 1.5,
|
assert_eq!(a.inverse().unwrap(), mat2::new(-2.0, 1.5,
|
||||||
1.0, -0.5));
|
1.0, -0.5));
|
||||||
|
|
||||||
assert!(mat2::new(0.0, 2.0,
|
assert!(mat2::new(0.0, 2.0,
|
||||||
0.0, 5.0).inverse().is_none());
|
0.0, 5.0).inverse().is_none());
|
||||||
|
@ -104,14 +104,14 @@ fn test_mat2() {
|
||||||
|
|
||||||
assert!(mat2::from_value(6.0).is_diagonal());
|
assert!(mat2::from_value(6.0).is_diagonal());
|
||||||
|
|
||||||
assert!(a.to_mat3() == mat3::new(1.0, 3.0, 0.0,
|
assert_eq!(a.to_mat3(), mat3::new(1.0, 3.0, 0.0,
|
||||||
2.0, 4.0, 0.0,
|
2.0, 4.0, 0.0,
|
||||||
0.0, 0.0, 1.0));
|
0.0, 0.0, 1.0));
|
||||||
|
|
||||||
assert!(a.to_mat4() == mat4::new(1.0, 3.0, 0.0, 0.0,
|
assert_eq!(a.to_mat4(), mat4::new(1.0, 3.0, 0.0, 0.0,
|
||||||
2.0, 4.0, 0.0, 0.0,
|
2.0, 4.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 1.0, 0.0,
|
0.0, 0.0, 1.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 1.0));
|
0.0, 0.0, 0.0, 1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_mat2_mut() {
|
fn test_mat2_mut() {
|
||||||
|
@ -125,17 +125,17 @@ fn test_mat2_mut() {
|
||||||
let mut mut_a: mat2 = a;
|
let mut mut_a: mat2 = a;
|
||||||
|
|
||||||
mut_a.swap_cols(0, 1);
|
mut_a.swap_cols(0, 1);
|
||||||
assert!(mut_a.col(0) == a.col(1));
|
assert_eq!(mut_a.col(0), a.col(1));
|
||||||
assert!(mut_a.col(1) == a.col(0));
|
assert_eq!(mut_a.col(1), a.col(0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap_rows(0, 1);
|
mut_a.swap_rows(0, 1);
|
||||||
assert!(mut_a.row(0) == a.row(1));
|
assert_eq!(mut_a.row(0), a.row(1));
|
||||||
assert!(mut_a.row(1) == a.row(0));
|
assert_eq!(mut_a.row(1), a.row(0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.set(&b);
|
mut_a.set(&b);
|
||||||
assert!(mut_a == b);
|
assert_eq!(mut_a, b);
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.to_identity();
|
mut_a.to_identity();
|
||||||
|
@ -143,27 +143,27 @@ fn test_mat2_mut() {
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.to_zero();
|
mut_a.to_zero();
|
||||||
assert!(mut_a == mat2::zero());
|
assert_eq!(mut_a, mat2::zero());
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.mul_self_t(f1);
|
mut_a.mul_self_t(f1);
|
||||||
assert!(mut_a == a.mul_t(f1));
|
assert_eq!(mut_a, a.mul_t(f1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.add_self_m(&b);
|
mut_a.add_self_m(&b);
|
||||||
assert!(mut_a == a.add_m(&b));
|
assert_eq!(mut_a, a.add_m(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.sub_self_m(&b);
|
mut_a.sub_self_m(&b);
|
||||||
assert!(mut_a == a.sub_m(&b));
|
assert_eq!(mut_a, a.sub_m(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.invert_self();
|
mut_a.invert_self();
|
||||||
assert!(mut_a == a.inverse().unwrap());
|
assert_eq!(mut_a, a.inverse().unwrap());
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.transpose_self();
|
mut_a.transpose_self();
|
||||||
assert!(mut_a == a.transpose());
|
assert_eq!(mut_a, a.transpose());
|
||||||
// mut_a = a;
|
// mut_a = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -187,74 +187,74 @@ fn test_mat3() {
|
||||||
let v1 = vec3::new(1.0, 2.0, 3.0);
|
let v1 = vec3::new(1.0, 2.0, 3.0);
|
||||||
let f1 = 0.5;
|
let f1 = 0.5;
|
||||||
|
|
||||||
assert!(a == mat3::new(1.0, 4.0, 7.0,
|
assert_eq!(a, mat3::new(1.0, 4.0, 7.0,
|
||||||
2.0, 5.0, 8.0,
|
2.0, 5.0, 8.0,
|
||||||
3.0, 6.0, 9.0));
|
3.0, 6.0, 9.0));
|
||||||
|
|
||||||
assert!(a == mat3::from_cols(vec3::new(1.0, 4.0, 7.0),
|
assert_eq!(a, mat3::from_cols(vec3::new(1.0, 4.0, 7.0),
|
||||||
vec3::new(2.0, 5.0, 8.0),
|
vec3::new(2.0, 5.0, 8.0),
|
||||||
vec3::new(3.0, 6.0, 9.0)));
|
vec3::new(3.0, 6.0, 9.0)));
|
||||||
|
|
||||||
assert!(*a.col(0) == vec3::new(1.0, 4.0, 7.0));
|
assert_eq!(*a.col(0), vec3::new(1.0, 4.0, 7.0));
|
||||||
assert!(*a.col(1) == vec3::new(2.0, 5.0, 8.0));
|
assert_eq!(*a.col(1), vec3::new(2.0, 5.0, 8.0));
|
||||||
assert!(*a.col(2) == vec3::new(3.0, 6.0, 9.0));
|
assert_eq!(*a.col(2), vec3::new(3.0, 6.0, 9.0));
|
||||||
|
|
||||||
assert!(a.row(0) == vec3::new(1.0, 2.0, 3.0));
|
assert_eq!(a.row(0), vec3::new(1.0, 2.0, 3.0));
|
||||||
assert!(a.row(1) == vec3::new(4.0, 5.0, 6.0));
|
assert_eq!(a.row(1), vec3::new(4.0, 5.0, 6.0));
|
||||||
assert!(a.row(2) == vec3::new(7.0, 8.0, 9.0));
|
assert_eq!(a.row(2), vec3::new(7.0, 8.0, 9.0));
|
||||||
|
|
||||||
assert!(a.col(0) == vec3::new(1.0, 4.0, 7.0));
|
assert_eq!(*a.col(0), vec3::new(1.0, 4.0, 7.0));
|
||||||
assert!(a.col(1) == vec3::new(2.0, 5.0, 8.0));
|
assert_eq!(*a.col(1), vec3::new(2.0, 5.0, 8.0));
|
||||||
assert!(a.col(2) == vec3::new(3.0, 6.0, 9.0));
|
assert_eq!(*a.col(2), vec3::new(3.0, 6.0, 9.0));
|
||||||
|
|
||||||
assert!(mat3::identity() == mat3::new(1.0, 0.0, 0.0,
|
assert_eq!(mat3::identity(), mat3::new(1.0, 0.0, 0.0,
|
||||||
0.0, 1.0, 0.0,
|
0.0, 1.0, 0.0,
|
||||||
0.0, 0.0, 1.0));
|
0.0, 0.0, 1.0));
|
||||||
|
|
||||||
assert!(mat3::zero() == mat3::new(0.0, 0.0, 0.0,
|
assert_eq!(mat3::zero(), mat3::new(0.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 0.0,
|
0.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 0.0));
|
0.0, 0.0, 0.0));
|
||||||
|
|
||||||
assert!(a.determinant() == 0.0);
|
assert_eq!(a.determinant(), 0.0);
|
||||||
assert!(a.trace() == 15.0);
|
assert_eq!(a.trace(), 15.0);
|
||||||
|
|
||||||
assert!(a.neg() == mat3::new(-1.0, -4.0, -7.0,
|
assert_eq!(a.neg(), mat3::new(-1.0, -4.0, -7.0,
|
||||||
-2.0, -5.0, -8.0,
|
-2.0, -5.0, -8.0,
|
||||||
-3.0, -6.0, -9.0));
|
-3.0, -6.0, -9.0));
|
||||||
assert!(-a == a.neg());
|
assert_eq!(-a, a.neg());
|
||||||
|
|
||||||
assert!(a.mul_t(f1) == mat3::new(0.5, 2.0, 3.5,
|
assert_eq!(a.mul_t(f1), mat3::new(0.5, 2.0, 3.5,
|
||||||
1.0, 2.5, 4.0,
|
1.0, 2.5, 4.0,
|
||||||
1.5, 3.0, 4.5));
|
1.5, 3.0, 4.5));
|
||||||
assert!(a.mul_v(&v1) == vec3::new(14.0, 32.0, 50.0));
|
assert_eq!(a.mul_v(&v1), vec3::new(14.0, 32.0, 50.0));
|
||||||
|
|
||||||
assert!(a.add_m(&b) == mat3::new(3.0, 9.0, 15.0,
|
assert_eq!(a.add_m(&b), mat3::new(3.0, 9.0, 15.0,
|
||||||
5.0, 11.0, 17.0,
|
5.0, 11.0, 17.0,
|
||||||
7.0, 13.0, 19.0));
|
7.0, 13.0, 19.0));
|
||||||
assert!(a.sub_m(&b) == mat3::new(-1.0, -1.0, -1.0,
|
assert_eq!(a.sub_m(&b), mat3::new(-1.0, -1.0, -1.0,
|
||||||
-1.0, -1.0, -1.0,
|
-1.0, -1.0, -1.0,
|
||||||
-1.0, -1.0, -1.0));
|
-1.0, -1.0, -1.0));
|
||||||
assert!(a.mul_m(&b) == mat3::new(36.0, 81.0, 126.0,
|
assert_eq!(a.mul_m(&b), mat3::new(36.0, 81.0, 126.0,
|
||||||
42.0, 96.0, 150.0,
|
42.0, 96.0, 150.0,
|
||||||
48.0, 111.0, 174.0));
|
48.0, 111.0, 174.0));
|
||||||
assert!(a.dot(&b) == 330.0);
|
assert_eq!(a.dot(&b), 330.0);
|
||||||
|
|
||||||
assert!(a.transpose() == mat3::new(1.0, 2.0, 3.0,
|
assert_eq!(a.transpose(), mat3::new(1.0, 2.0, 3.0,
|
||||||
4.0, 5.0, 6.0,
|
4.0, 5.0, 6.0,
|
||||||
7.0, 8.0, 9.0));
|
7.0, 8.0, 9.0));
|
||||||
|
|
||||||
assert!(a.inverse().is_none());
|
assert!(a.inverse().is_none());
|
||||||
|
|
||||||
assert!(mat3::new(2.0, 4.0, 6.0,
|
assert_eq!(mat3::new(2.0, 4.0, 6.0,
|
||||||
0.0, 2.0, 4.0,
|
0.0, 2.0, 4.0,
|
||||||
0.0, 0.0, 1.0).inverse().unwrap()
|
0.0, 0.0, 1.0).inverse().unwrap(),
|
||||||
== mat3::new(0.5, -1.0, 1.0,
|
mat3::new(0.5, -1.0, 1.0,
|
||||||
0.0, 0.5, -2.0,
|
0.0, 0.5, -2.0,
|
||||||
0.0, 0.0, 1.0));
|
0.0, 0.0, 1.0));
|
||||||
|
|
||||||
let ident: Mat3<float> = BaseMat::identity();
|
let ident: Mat3<float> = BaseMat::identity();
|
||||||
|
|
||||||
assert!(ident.inverse().unwrap() == ident);
|
assert_eq!(ident.inverse().unwrap(), ident);
|
||||||
|
|
||||||
assert!(ident.is_identity());
|
assert!(ident.is_identity());
|
||||||
assert!(ident.is_symmetric());
|
assert!(ident.is_symmetric());
|
||||||
|
@ -279,10 +279,10 @@ fn test_mat3() {
|
||||||
|
|
||||||
assert!(mat3::from_value(6.0).is_diagonal());
|
assert!(mat3::from_value(6.0).is_diagonal());
|
||||||
|
|
||||||
assert!(a.to_mat4() == mat4::new(1.0, 4.0, 7.0, 0.0,
|
assert_eq!(a.to_mat4(), mat4::new(1.0, 4.0, 7.0, 0.0,
|
||||||
2.0, 5.0, 8.0, 0.0,
|
2.0, 5.0, 8.0, 0.0,
|
||||||
3.0, 6.0, 9.0, 0.0,
|
3.0, 6.0, 9.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 1.0));
|
0.0, 0.0, 0.0, 1.0));
|
||||||
|
|
||||||
// to_Quaternion
|
// to_Quaternion
|
||||||
}
|
}
|
||||||
|
@ -304,27 +304,27 @@ fn test_mat3_mut() {
|
||||||
let mut mut_c: mat3 = c;
|
let mut mut_c: mat3 = c;
|
||||||
|
|
||||||
mut_a.swap_cols(0, 2);
|
mut_a.swap_cols(0, 2);
|
||||||
assert!(mut_a.col(0) == a.col(2));
|
assert_eq!(mut_a.col(0), a.col(2));
|
||||||
assert!(mut_a.col(2) == a.col(0));
|
assert_eq!(mut_a.col(2), a.col(0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap_cols(1, 2);
|
mut_a.swap_cols(1, 2);
|
||||||
assert!(mut_a.col(1) == a.col(2));
|
assert_eq!(mut_a.col(1), a.col(2));
|
||||||
assert!(mut_a.col(2) == a.col(1));
|
assert_eq!(mut_a.col(2), a.col(1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap_rows(0, 2);
|
mut_a.swap_rows(0, 2);
|
||||||
assert!(mut_a.row(0) == a.row(2));
|
assert_eq!(mut_a.row(0), a.row(2));
|
||||||
assert!(mut_a.row(2) == a.row(0));
|
assert_eq!(mut_a.row(2), a.row(0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap_rows(1, 2);
|
mut_a.swap_rows(1, 2);
|
||||||
assert!(mut_a.row(1) == a.row(2));
|
assert_eq!(mut_a.row(1), a.row(2));
|
||||||
assert!(mut_a.row(2) == a.row(1));
|
assert_eq!(mut_a.row(2), a.row(1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.set(&b);
|
mut_a.set(&b);
|
||||||
assert!(mut_a == b);
|
assert_eq!(mut_a, b);
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.to_identity();
|
mut_a.to_identity();
|
||||||
|
@ -332,27 +332,27 @@ fn test_mat3_mut() {
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.to_zero();
|
mut_a.to_zero();
|
||||||
assert!(mut_a == mat3::zero());
|
assert_eq!(mut_a, mat3::zero());
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.mul_self_t(f1);
|
mut_a.mul_self_t(f1);
|
||||||
assert!(mut_a == a.mul_t(f1));
|
assert_eq!(mut_a, a.mul_t(f1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.add_self_m(&b);
|
mut_a.add_self_m(&b);
|
||||||
assert!(mut_a == a.add_m(&b));
|
assert_eq!(mut_a, a.add_m(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.sub_self_m(&b);
|
mut_a.sub_self_m(&b);
|
||||||
assert!(mut_a == a.sub_m(&b));
|
assert_eq!(mut_a, a.sub_m(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_c.invert_self();
|
mut_c.invert_self();
|
||||||
assert!(mut_c == c.inverse().unwrap());
|
assert_eq!(mut_c, c.inverse().unwrap());
|
||||||
// mut_c = c;
|
// mut_c = c;
|
||||||
|
|
||||||
mut_a.transpose_self();
|
mut_a.transpose_self();
|
||||||
assert!(mut_a == a.transpose());
|
assert_eq!(mut_a, a.transpose());
|
||||||
// mut_a = a;
|
// mut_a = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -384,89 +384,90 @@ fn test_mat4() {
|
||||||
let v1 = vec4::new(1.0, 2.0, 3.0, 4.0);
|
let v1 = vec4::new(1.0, 2.0, 3.0, 4.0);
|
||||||
let f1 = 0.5;
|
let f1 = 0.5;
|
||||||
|
|
||||||
assert!(a == mat4::new(1.0, 5.0, 9.0, 13.0,
|
assert_eq!(a, mat4::new(1.0, 5.0, 9.0, 13.0,
|
||||||
2.0, 6.0, 10.0, 14.0,
|
2.0, 6.0, 10.0, 14.0,
|
||||||
3.0, 7.0, 11.0, 15.0,
|
3.0, 7.0, 11.0, 15.0,
|
||||||
4.0, 8.0, 12.0, 16.0));
|
4.0, 8.0, 12.0, 16.0));
|
||||||
|
|
||||||
assert!(a == mat4::from_cols(vec4::new(1.0, 5.0, 9.0, 13.0),
|
assert_eq!(a, mat4::from_cols(vec4::new(1.0, 5.0, 9.0, 13.0),
|
||||||
vec4::new(2.0, 6.0, 10.0, 14.0),
|
vec4::new(2.0, 6.0, 10.0, 14.0),
|
||||||
vec4::new(3.0, 7.0, 11.0, 15.0),
|
vec4::new(3.0, 7.0, 11.0, 15.0),
|
||||||
vec4::new(4.0, 8.0, 12.0, 16.0)));
|
vec4::new(4.0, 8.0, 12.0, 16.0)));
|
||||||
|
|
||||||
assert!(mat4::from_value(4.0) == mat4::new(4.0, 0.0, 0.0, 0.0,
|
assert_eq!(mat4::from_value(4.0), mat4::new(4.0, 0.0, 0.0, 0.0,
|
||||||
0.0, 4.0, 0.0, 0.0,
|
0.0, 4.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 4.0, 0.0,
|
0.0, 0.0, 4.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 4.0));
|
0.0, 0.0, 0.0, 4.0));
|
||||||
|
|
||||||
assert!(*a.col(0) == vec4::new(1.0, 5.0, 9.0, 13.0));
|
assert_eq!(*a.col(0), vec4::new(1.0, 5.0, 9.0, 13.0));
|
||||||
assert!(*a.col(1) == vec4::new(2.0, 6.0, 10.0, 14.0));
|
assert_eq!(*a.col(1), vec4::new(2.0, 6.0, 10.0, 14.0));
|
||||||
assert!(*a.col(2) == vec4::new(3.0, 7.0, 11.0, 15.0));
|
assert_eq!(*a.col(2), vec4::new(3.0, 7.0, 11.0, 15.0));
|
||||||
assert!(*a.col(3) == vec4::new(4.0, 8.0, 12.0, 16.0));
|
assert_eq!(*a.col(3), vec4::new(4.0, 8.0, 12.0, 16.0));
|
||||||
|
|
||||||
assert!(a.row(0) == vec4::new( 1.0, 2.0, 3.0, 4.0));
|
assert_eq!(a.row(0), vec4::new( 1.0, 2.0, 3.0, 4.0));
|
||||||
assert!(a.row(1) == vec4::new( 5.0, 6.0, 7.0, 8.0));
|
assert_eq!(a.row(1), vec4::new( 5.0, 6.0, 7.0, 8.0));
|
||||||
assert!(a.row(2) == vec4::new( 9.0, 10.0, 11.0, 12.0));
|
assert_eq!(a.row(2), vec4::new( 9.0, 10.0, 11.0, 12.0));
|
||||||
assert!(a.row(3) == vec4::new(13.0, 14.0, 15.0, 16.0));
|
assert_eq!(a.row(3), vec4::new(13.0, 14.0, 15.0, 16.0));
|
||||||
|
|
||||||
assert!(a.col(0) == vec4::new(1.0, 5.0, 9.0, 13.0));
|
assert_eq!(*a.col(0), vec4::new(1.0, 5.0, 9.0, 13.0));
|
||||||
assert!(a.col(1) == vec4::new(2.0, 6.0, 10.0, 14.0));
|
assert_eq!(*a.col(1), vec4::new(2.0, 6.0, 10.0, 14.0));
|
||||||
assert!(a.col(2) == vec4::new(3.0, 7.0, 11.0, 15.0));
|
assert_eq!(*a.col(2), vec4::new(3.0, 7.0, 11.0, 15.0));
|
||||||
assert!(a.col(3) == vec4::new(4.0, 8.0, 12.0, 16.0));
|
assert_eq!(*a.col(3), vec4::new(4.0, 8.0, 12.0, 16.0));
|
||||||
|
|
||||||
assert!(mat4::identity() == mat4::new(1.0, 0.0, 0.0, 0.0,
|
assert_eq!(mat4::identity(), mat4::new(1.0, 0.0, 0.0, 0.0,
|
||||||
0.0, 1.0, 0.0, 0.0,
|
0.0, 1.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 1.0, 0.0,
|
0.0, 0.0, 1.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 1.0));
|
0.0, 0.0, 0.0, 1.0));
|
||||||
|
|
||||||
assert!(mat4::zero() == mat4::new(0.0, 0.0, 0.0, 0.0,
|
assert_eq!(mat4::zero(), mat4::new(0.0, 0.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 0.0,
|
0.0, 0.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 0.0,
|
0.0, 0.0, 0.0, 0.0,
|
||||||
0.0, 0.0, 0.0, 0.0));
|
0.0, 0.0, 0.0, 0.0));
|
||||||
|
|
||||||
assert!(a.determinant() == 0.0);
|
assert_eq!(a.determinant(), 0.0);
|
||||||
assert!(a.trace() == 34.0);
|
assert_eq!(a.trace(), 34.0);
|
||||||
|
|
||||||
assert!(a.neg() == mat4::new(-1.0, -5.0, -9.0, -13.0,
|
assert_eq!(a.neg(), mat4::new(-1.0, -5.0, -9.0, -13.0,
|
||||||
-2.0, -6.0, -10.0, -14.0,
|
-2.0, -6.0, -10.0, -14.0,
|
||||||
-3.0, -7.0, -11.0, -15.0,
|
-3.0, -7.0, -11.0, -15.0,
|
||||||
-4.0, -8.0, -12.0, -16.0));
|
-4.0, -8.0, -12.0, -16.0));
|
||||||
assert!(-a == a.neg());
|
assert_eq!(-a, a.neg());
|
||||||
|
|
||||||
assert!(a.mul_t(f1) == mat4::new(0.5, 2.5, 4.5, 6.5,
|
assert_eq!(a.mul_t(f1), mat4::new(0.5, 2.5, 4.5, 6.5,
|
||||||
1.0, 3.0, 5.0, 7.0,
|
1.0, 3.0, 5.0, 7.0,
|
||||||
1.5, 3.5, 5.5, 7.5,
|
1.5, 3.5, 5.5, 7.5,
|
||||||
2.0, 4.0, 6.0, 8.0));
|
2.0, 4.0, 6.0, 8.0));
|
||||||
assert!(a.mul_v(&v1) == vec4::new(30.0, 70.0, 110.0, 150.0));
|
assert_eq!(a.mul_v(&v1), vec4::new(30.0, 70.0, 110.0, 150.0));
|
||||||
|
|
||||||
assert!(a.add_m(&b) == mat4::new(3.0, 11.0, 19.0, 27.0,
|
assert_eq!(a.add_m(&b), mat4::new(3.0, 11.0, 19.0, 27.0,
|
||||||
5.0, 13.0, 21.0, 29.0,
|
5.0, 13.0, 21.0, 29.0,
|
||||||
7.0, 15.0, 23.0, 31.0,
|
7.0, 15.0, 23.0, 31.0,
|
||||||
9.0, 17.0, 25.0, 33.0));
|
9.0, 17.0, 25.0, 33.0));
|
||||||
assert!(a.sub_m(&b) == mat4::new(-1.0, -1.0, -1.0, -1.0,
|
assert_eq!(a.sub_m(&b), mat4::new(-1.0, -1.0, -1.0, -1.0,
|
||||||
-1.0, -1.0, -1.0, -1.0,
|
-1.0, -1.0, -1.0, -1.0,
|
||||||
-1.0, -1.0, -1.0, -1.0,
|
-1.0, -1.0, -1.0, -1.0,
|
||||||
-1.0, -1.0, -1.0, -1.0));
|
-1.0, -1.0, -1.0, -1.0));
|
||||||
assert!(a.mul_m(&b) == mat4::new(100.0, 228.0, 356.0, 484.0,
|
assert_eq!(a.mul_m(&b), mat4::new(100.0, 228.0, 356.0, 484.0,
|
||||||
110.0, 254.0, 398.0, 542.0,
|
110.0, 254.0, 398.0, 542.0,
|
||||||
120.0, 280.0, 440.0, 600.0,
|
120.0, 280.0, 440.0, 600.0,
|
||||||
130.0, 306.0, 482.0, 658.0));
|
130.0, 306.0, 482.0, 658.0));
|
||||||
assert!(a.dot(&b) == 1632.0);
|
assert_eq!(a.dot(&b), 1632.0);
|
||||||
|
|
||||||
assert!(a.transpose() == mat4::new( 1.0, 2.0, 3.0, 4.0,
|
assert_eq!(a.transpose(), mat4::new( 1.0, 2.0, 3.0, 4.0,
|
||||||
5.0, 6.0, 7.0, 8.0,
|
5.0, 6.0, 7.0, 8.0,
|
||||||
9.0, 10.0, 11.0, 12.0,
|
9.0, 10.0, 11.0, 12.0,
|
||||||
13.0, 14.0, 15.0, 16.0));
|
13.0, 14.0, 15.0, 16.0));
|
||||||
|
|
||||||
assert!(c.inverse().unwrap()
|
assert!(c.inverse().unwrap().approx_eq(
|
||||||
.approx_eq(&mat4::new( 5.0, -4.0, 1.0, 0.0,
|
&mat4::new( 5.0, -4.0, 1.0, 0.0,
|
||||||
-4.0, 8.0, -4.0, 0.0,
|
-4.0, 8.0, -4.0, 0.0,
|
||||||
4.0, -8.0, 4.0, 8.0,
|
4.0, -8.0, 4.0, 8.0,
|
||||||
-3.0, 4.0, 1.0, -8.0).mul_t(0.125)));
|
-3.0, 4.0, 1.0, -8.0).mul_t(0.125))
|
||||||
|
);
|
||||||
|
|
||||||
let ident = mat4::identity();
|
let ident = mat4::identity();
|
||||||
|
|
||||||
assert!(ident.inverse().unwrap() == ident);
|
assert_eq!(ident.inverse().unwrap(), ident);
|
||||||
|
|
||||||
assert!(ident.is_identity());
|
assert!(ident.is_identity());
|
||||||
assert!(ident.is_symmetric());
|
assert!(ident.is_symmetric());
|
||||||
|
@ -513,27 +514,27 @@ fn test_mat4_mut() {
|
||||||
let mut mut_c: mat4 = c;
|
let mut mut_c: mat4 = c;
|
||||||
|
|
||||||
mut_a.swap_cols(0, 3);
|
mut_a.swap_cols(0, 3);
|
||||||
assert!(mut_a.col(0) == a.col(3));
|
assert_eq!(mut_a.col(0), a.col(3));
|
||||||
assert!(mut_a.col(3) == a.col(0));
|
assert_eq!(mut_a.col(3), a.col(0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap_cols(1, 2);
|
mut_a.swap_cols(1, 2);
|
||||||
assert!(mut_a.col(1) == a.col(2));
|
assert_eq!(mut_a.col(1), a.col(2));
|
||||||
assert!(mut_a.col(2) == a.col(1));
|
assert_eq!(mut_a.col(2), a.col(1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap_rows(0, 3);
|
mut_a.swap_rows(0, 3);
|
||||||
assert!(mut_a.row(0) == a.row(3));
|
assert_eq!(mut_a.row(0), a.row(3));
|
||||||
assert!(mut_a.row(3) == a.row(0));
|
assert_eq!(mut_a.row(3), a.row(0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap_rows(1, 2);
|
mut_a.swap_rows(1, 2);
|
||||||
assert!(mut_a.row(1) == a.row(2));
|
assert_eq!(mut_a.row(1), a.row(2));
|
||||||
assert!(mut_a.row(2) == a.row(1));
|
assert_eq!(mut_a.row(2), a.row(1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.set(&b);
|
mut_a.set(&b);
|
||||||
assert!(mut_a == b);
|
assert_eq!(mut_a, b);
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.to_identity();
|
mut_a.to_identity();
|
||||||
|
@ -541,27 +542,27 @@ fn test_mat4_mut() {
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.to_zero();
|
mut_a.to_zero();
|
||||||
assert!(mut_a == mat4::zero());
|
assert_eq!(mut_a, mat4::zero());
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.mul_self_t(f1);
|
mut_a.mul_self_t(f1);
|
||||||
assert!(mut_a == a.mul_t(f1));
|
assert_eq!(mut_a, a.mul_t(f1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.add_self_m(&b);
|
mut_a.add_self_m(&b);
|
||||||
assert!(mut_a == a.add_m(&b));
|
assert_eq!(mut_a, a.add_m(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.sub_self_m(&b);
|
mut_a.sub_self_m(&b);
|
||||||
assert!(mut_a == a.sub_m(&b));
|
assert_eq!(mut_a, a.sub_m(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_c.invert_self();
|
mut_c.invert_self();
|
||||||
assert!(mut_c == c.inverse().unwrap());
|
assert_eq!(mut_c, c.inverse().unwrap());
|
||||||
// mut_c = c;
|
// mut_c = c;
|
||||||
|
|
||||||
mut_a.transpose_self();
|
mut_a.transpose_self();
|
||||||
assert!(mut_a == a.transpose());
|
assert_eq!(mut_a, a.transpose());
|
||||||
// mut_a = a;
|
// mut_a = a;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,20 +23,20 @@ use vec::*;
|
||||||
fn test_quat() {
|
fn test_quat() {
|
||||||
let a = Quat { s: 1.0, v: Vec3 { x: 2.0, y: 3.0, z: 4.0 } };
|
let a = Quat { s: 1.0, v: Vec3 { x: 2.0, y: 3.0, z: 4.0 } };
|
||||||
|
|
||||||
assert!(a == quat::from_sv(1.0, vec3::new(2.0, 3.0, 4.0)));
|
assert_eq!(a, quat::from_sv(1.0, vec3::new(2.0, 3.0, 4.0)));
|
||||||
assert!(a == quat::new(1.0, 2.0, 3.0, 4.0));
|
assert_eq!(a, quat::new(1.0, 2.0, 3.0, 4.0));
|
||||||
|
|
||||||
assert!(quat::zero() == quat::new(0.0, 0.0, 0.0, 0.0));
|
assert_eq!(quat::zero(), quat::new(0.0, 0.0, 0.0, 0.0));
|
||||||
assert!(quat::identity() == quat::new(1.0, 0.0, 0.0, 0.0));
|
assert_eq!(quat::identity(), quat::new(1.0, 0.0, 0.0, 0.0));
|
||||||
|
|
||||||
assert!(a.s == 1.0);
|
assert_eq!(a.s, 1.0);
|
||||||
assert!(a.v.x == 2.0);
|
assert_eq!(a.v.x, 2.0);
|
||||||
assert!(a.v.y == 3.0);
|
assert_eq!(a.v.y, 3.0);
|
||||||
assert!(a.v.z == 4.0);
|
assert_eq!(a.v.z, 4.0);
|
||||||
assert!(*a.index(0) == 1.0);
|
assert_eq!(*a.index(0), 1.0);
|
||||||
assert!(*a.index(1) == 2.0);
|
assert_eq!(*a.index(1), 2.0);
|
||||||
assert!(*a.index(2) == 3.0);
|
assert_eq!(*a.index(2), 3.0);
|
||||||
assert!(*a.index(3) == 4.0);
|
assert_eq!(*a.index(3), 4.0);
|
||||||
// TODO
|
// TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,14 +44,14 @@ fn test_quat() {
|
||||||
fn test_quat_2() {
|
fn test_quat_2() {
|
||||||
let v = vec3::new(1f32, 0f32, 0f32);
|
let v = vec3::new(1f32, 0f32, 0f32);
|
||||||
|
|
||||||
let q = quat::from_angle_axis((-45f32).radians(), &vec3::new(0f32, 0f32, -1f32));
|
let q = quat::from_angle_axis((-45f32).to_radians(), &vec3::new(0f32, 0f32, -1f32));
|
||||||
|
|
||||||
// http://www.wolframalpha.com/input/?i={1,0}+rotate+-45+degrees
|
// http://www.wolframalpha.com/input/?i={1,0}+rotate+-45+degrees
|
||||||
assert!(q.mul_v(&v).approx_eq(&vec3::new(1f32/2f32.sqrt(), 1f32/2f32.sqrt(), 0f32)));
|
assert_approx_eq!(q.mul_v(&v), vec3::new(1f32/2f32.sqrt(), 1f32/2f32.sqrt(), 0f32));
|
||||||
assert!(q.mul_v(&v).length() == v.length());
|
assert_eq!(q.mul_v(&v).length(), v.length());
|
||||||
assert!(q.to_mat3().approx_eq(&mat3::new(1f32/2f32.sqrt(), 1f32/2f32.sqrt(), 0f32,
|
assert_approx_eq!(q.to_mat3(), mat3::new(1f32/2f32.sqrt(), 1f32/2f32.sqrt(), 0f32,
|
||||||
-1f32/2f32.sqrt(), 1f32/2f32.sqrt(), 0f32,
|
-1f32/2f32.sqrt(), 1f32/2f32.sqrt(), 0f32,
|
||||||
0f32, 0f32, 1f32)));
|
0f32, 0f32, 1f32));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
@ -19,7 +19,7 @@ use vec::*;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vec2() {
|
fn test_vec2() {
|
||||||
// assert!(vec2::dim == 2);
|
// assert_eq!(vec2::dim, 2);
|
||||||
|
|
||||||
let a = Vec2 { x: 1.0, y: 2.0 };
|
let a = Vec2 { x: 1.0, y: 2.0 };
|
||||||
let b = Vec2 { x: 3.0, y: 4.0 };
|
let b = Vec2 { x: 3.0, y: 4.0 };
|
||||||
|
@ -28,74 +28,74 @@ fn test_vec2() {
|
||||||
|
|
||||||
let mut mut_a = a;
|
let mut mut_a = a;
|
||||||
|
|
||||||
assert!(vec2::new(1.0, 2.0) == a);
|
assert_eq!(vec2::new(1.0, 2.0), a);
|
||||||
assert!(vec2::from_value(1.0) == vec2::new(1.0, 1.0));
|
assert_eq!(vec2::from_value(1.0), vec2::new(1.0, 1.0));
|
||||||
|
|
||||||
assert!(vec2::zero() == vec2::new(0.0, 0.0));
|
assert_eq!(vec2::zero(), vec2::new(0.0, 0.0));
|
||||||
assert!(vec2::unit_x() == vec2::new(1.0, 0.0));
|
assert_eq!(vec2::unit_x(), vec2::new(1.0, 0.0));
|
||||||
assert!(vec2::unit_y() == vec2::new(0.0, 1.0));
|
assert_eq!(vec2::unit_y(), vec2::new(0.0, 1.0));
|
||||||
assert!(vec2::identity() == vec2::new(1.0, 1.0));
|
assert_eq!(vec2::identity(), vec2::new(1.0, 1.0));
|
||||||
|
|
||||||
*mut_a.index_mut(0) = 42.0;
|
*mut_a.index_mut(0) = 42.0;
|
||||||
*mut_a.index_mut(1) = 43.0;
|
*mut_a.index_mut(1) = 43.0;
|
||||||
assert!(mut_a == vec2::new(42.0, 43.0));
|
assert_eq!(mut_a, vec2::new(42.0, 43.0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap(0, 1);
|
mut_a.swap(0, 1);
|
||||||
assert!(*mut_a.index(0) == *a.index(1));
|
assert_eq!(*mut_a.index(0), *a.index(1));
|
||||||
assert!(*mut_a.index(1) == *a.index(0));
|
assert_eq!(*mut_a.index(1), *a.index(0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
assert!(a.x == 1.0);
|
assert_eq!(a.x, 1.0);
|
||||||
assert!(a.y == 2.0);
|
assert_eq!(a.y, 2.0);
|
||||||
assert!(*a.index(0) == 1.0);
|
assert_eq!(*a.index(0), 1.0);
|
||||||
assert!(*a.index(1) == 2.0);
|
assert_eq!(*a.index(1), 2.0);
|
||||||
|
|
||||||
assert!(-a == vec2::new(-1.0, -2.0));
|
assert_eq!(-a, vec2::new(-1.0, -2.0));
|
||||||
assert!(a.neg() == vec2::new(-1.0, -2.0));
|
assert_eq!(a.neg(), vec2::new(-1.0, -2.0));
|
||||||
|
|
||||||
assert!(vec2::new(0.0, 0.0).is_zero());
|
assert!(vec2::new(0.0, 0.0).is_zero());
|
||||||
assert!(!vec2::new(1.0, 1.0).is_zero());
|
assert!(!vec2::new(1.0, 1.0).is_zero());
|
||||||
|
|
||||||
assert!(a.mul_t(f1) == vec2::new( 1.5, 3.0));
|
assert_eq!(a.mul_t(f1), vec2::new( 1.5, 3.0));
|
||||||
assert!(a.div_t(f2) == vec2::new( 2.0, 4.0));
|
assert_eq!(a.div_t(f2), vec2::new( 2.0, 4.0));
|
||||||
|
|
||||||
assert!(a.add_v(&b) == vec2::new( 4.0, 6.0));
|
assert_eq!(a.add_v(&b), vec2::new( 4.0, 6.0));
|
||||||
assert!(a.sub_v(&b) == vec2::new( -2.0, -2.0));
|
assert_eq!(a.sub_v(&b), vec2::new( -2.0, -2.0));
|
||||||
assert!(a.mul_v(&b) == vec2::new( 3.0, 8.0));
|
assert_eq!(a.mul_v(&b), vec2::new( 3.0, 8.0));
|
||||||
assert!(a.div_v(&b) == vec2::new(1.0/3.0, 2.0/4.0));
|
assert_eq!(a.div_v(&b), vec2::new(1.0/3.0, 2.0/4.0));
|
||||||
|
|
||||||
mut_a.neg_self();
|
mut_a.neg_self();
|
||||||
assert!(mut_a == -a);
|
assert_eq!(mut_a, -a);
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.mul_self_t(f1);
|
mut_a.mul_self_t(f1);
|
||||||
assert!(mut_a == a.mul_t(f1));
|
assert_eq!(mut_a, a.mul_t(f1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.div_self_t(f2);
|
mut_a.div_self_t(f2);
|
||||||
assert!(mut_a == a.div_t(f2));
|
assert_eq!(mut_a, a.div_t(f2));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.add_self_v(&b);
|
mut_a.add_self_v(&b);
|
||||||
assert!(mut_a == a.add_v(&b));
|
assert_eq!(mut_a, a.add_v(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.sub_self_v(&b);
|
mut_a.sub_self_v(&b);
|
||||||
assert!(mut_a == a.sub_v(&b));
|
assert_eq!(mut_a, a.sub_v(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.mul_self_v(&b);
|
mut_a.mul_self_v(&b);
|
||||||
assert!(mut_a == a.mul_v(&b));
|
assert_eq!(mut_a, a.mul_v(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.div_self_v(&b);
|
mut_a.div_self_v(&b);
|
||||||
assert!(mut_a == a.div_v(&b));
|
assert_eq!(mut_a, a.div_v(&b));
|
||||||
// mut_a = a;
|
// mut_a = a;
|
||||||
|
|
||||||
// assert!(c.abs() == vec2::new( 2.0, 1.0));
|
// assert_eq!(c.abs(), vec2::new( 2.0, 1.0));
|
||||||
// assert!(c.min(&d) == vec2::new(-2.0, -1.0));
|
// assert_eq!(c.min(&d), vec2::new(-2.0, -1.0));
|
||||||
// assert!(c.max(&d) == vec2::new( 1.0, 0.0));
|
// assert_eq!(c.max(&d), vec2::new( 1.0, 0.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -110,18 +110,18 @@ fn test_vec2_euclidean() {
|
||||||
let b0 = vec2::new(3.0, 4.0); // (3, 4, 5) Pythagorean triple
|
let b0 = vec2::new(3.0, 4.0); // (3, 4, 5) Pythagorean triple
|
||||||
let b = a.add_v(&b0);
|
let b = a.add_v(&b0);
|
||||||
|
|
||||||
assert!(a.length() == 13.0);
|
assert_eq!(a.length(), 13.0);
|
||||||
assert!(a.length2() == 13.0 * 13.0);
|
assert_eq!(a.length2(), 13.0 * 13.0);
|
||||||
|
|
||||||
assert!(b0.length() == 5.0);
|
assert_eq!(b0.length(), 5.0);
|
||||||
assert!(b0.length2() == 5.0 * 5.0);
|
assert_eq!(b0.length2(), 5.0 * 5.0);
|
||||||
|
|
||||||
assert!(a.distance(&b) == 5.0);
|
assert_eq!(a.distance(&b), 5.0);
|
||||||
assert!(a.distance2(&b) == 5.0 * 5.0);
|
assert_eq!(a.distance2(&b), 5.0 * 5.0);
|
||||||
|
|
||||||
assert!(vec2::new(1.0, 0.0).angle(&vec2::new(0.0, 1.0)).approx_eq(&Real::frac_pi_2()));
|
assert!(vec2::new(1.0, 0.0).angle(&vec2::new(0.0, 1.0)).approx_eq(&Real::frac_pi_2()));
|
||||||
assert!(vec2::new(10.0, 0.0).angle(&vec2::new(0.0, 5.0)).approx_eq(&Real::frac_pi_2()));
|
assert!(vec2::new(10.0, 0.0).angle(&vec2::new(0.0, 5.0)).approx_eq(&Real::frac_pi_2()));
|
||||||
assert!(vec2::new(-1.0, 0.0).angle(&vec2::new(0.0, 1.0)).approx_eq(&-frac_pi_2::<f32>()));
|
assert!(vec2::new(-1.0, 0.0).angle(&vec2::new(0.0, 1.0)).approx_eq(&-Real::frac_pi_2::<f32>()));
|
||||||
|
|
||||||
assert!(vec2::new(3.0, 4.0).normalize().approx_eq(&vec2::new(3.0/5.0, 4.0/5.0)));
|
assert!(vec2::new(3.0, 4.0).normalize().approx_eq(&vec2::new(3.0/5.0, 4.0/5.0)));
|
||||||
// TODO: test normalize_to, normalize_self, and normalize_self_to
|
// TODO: test normalize_to, normalize_self, and normalize_self_to
|
||||||
|
@ -129,11 +129,11 @@ fn test_vec2_euclidean() {
|
||||||
let c = vec2::new(-2.0, -1.0);
|
let c = vec2::new(-2.0, -1.0);
|
||||||
let d = vec2::new( 1.0, 0.0);
|
let d = vec2::new( 1.0, 0.0);
|
||||||
|
|
||||||
assert!(c.lerp(&d, 0.75) == vec2::new(0.250, -0.250));
|
assert_eq!(c.lerp(&d, 0.75), vec2::new(0.250, -0.250));
|
||||||
|
|
||||||
let mut mut_c = c;
|
let mut mut_c = c;
|
||||||
mut_c.lerp_self(&d, 0.75);
|
mut_c.lerp_self(&d, 0.75);
|
||||||
assert!(mut_c == c.lerp(&d, 0.75));
|
assert_eq!(mut_c, c.lerp(&d, 0.75));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -142,22 +142,22 @@ fn test_vec2_boolean() {
|
||||||
let ff = bvec2::new(false, false);
|
let ff = bvec2::new(false, false);
|
||||||
let tt = bvec2::new(true, true);
|
let tt = bvec2::new(true, true);
|
||||||
|
|
||||||
assert!(tf.any() == true);
|
assert_eq!(tf.any(), true);
|
||||||
assert!(tf.all() == false);
|
assert_eq!(tf.all(), false);
|
||||||
assert!(tf.not() == bvec2::new(false, true));
|
assert_eq!(tf.not(), bvec2::new(false, true));
|
||||||
|
|
||||||
assert!(ff.any() == false);
|
assert_eq!(ff.any(), false);
|
||||||
assert!(ff.all() == false);
|
assert_eq!(ff.all(), false);
|
||||||
assert!(ff.not() == bvec2::new(true, true));
|
assert_eq!(ff.not(), bvec2::new(true, true));
|
||||||
|
|
||||||
assert!(tt.any() == true);
|
assert_eq!(tt.any(), true);
|
||||||
assert!(tt.all() == true);
|
assert_eq!(tt.all(), true);
|
||||||
assert!(tt.not() == bvec2::new(false, false));
|
assert_eq!(tt.not(), bvec2::new(false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vec3() {
|
fn test_vec3() {
|
||||||
// assert!(Vec3::dim == 3);
|
// assert_eq!(Vec3::dim, 3);
|
||||||
|
|
||||||
let a = Vec3 { x: 1.0, y: 2.0, z: 3.0 };
|
let a = Vec3 { x: 1.0, y: 2.0, z: 3.0 };
|
||||||
let b = Vec3 { x: 4.0, y: 5.0, z: 6.0 };
|
let b = Vec3 { x: 4.0, y: 5.0, z: 6.0 };
|
||||||
|
@ -166,93 +166,93 @@ fn test_vec3() {
|
||||||
|
|
||||||
let mut mut_a = a;
|
let mut mut_a = a;
|
||||||
|
|
||||||
assert!(vec3::new(1.0, 2.0, 3.0) == a);
|
assert_eq!(vec3::new(1.0, 2.0, 3.0), a);
|
||||||
assert!(vec3::from_value(1.0) == vec3::new(1.0, 1.0, 1.0));
|
assert_eq!(vec3::from_value(1.0), vec3::new(1.0, 1.0, 1.0));
|
||||||
|
|
||||||
assert!(vec3::zero() == vec3::new(0.0, 0.0, 0.0));
|
assert_eq!(vec3::zero(), vec3::new(0.0, 0.0, 0.0));
|
||||||
assert!(vec3::unit_x() == vec3::new(1.0, 0.0, 0.0));
|
assert_eq!(vec3::unit_x(), vec3::new(1.0, 0.0, 0.0));
|
||||||
assert!(vec3::unit_y() == vec3::new(0.0, 1.0, 0.0));
|
assert_eq!(vec3::unit_y(), vec3::new(0.0, 1.0, 0.0));
|
||||||
assert!(vec3::unit_z() == vec3::new(0.0, 0.0, 1.0));
|
assert_eq!(vec3::unit_z(), vec3::new(0.0, 0.0, 1.0));
|
||||||
assert!(vec3::identity() == vec3::new(1.0, 1.0, 1.0));
|
assert_eq!(vec3::identity(), vec3::new(1.0, 1.0, 1.0));
|
||||||
|
|
||||||
*mut_a.index_mut(0) = 42.0;
|
*mut_a.index_mut(0) = 42.0;
|
||||||
*mut_a.index_mut(1) = 43.0;
|
*mut_a.index_mut(1) = 43.0;
|
||||||
*mut_a.index_mut(2) = 44.0;
|
*mut_a.index_mut(2) = 44.0;
|
||||||
assert!(mut_a == vec3::new(42.0, 43.0, 44.0));
|
assert_eq!(mut_a, vec3::new(42.0, 43.0, 44.0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap(0, 2);
|
mut_a.swap(0, 2);
|
||||||
assert!(*mut_a.index(0) == *a.index(2));
|
assert_eq!(*mut_a.index(0), *a.index(2));
|
||||||
assert!(*mut_a.index(2) == *a.index(0));
|
assert_eq!(*mut_a.index(2), *a.index(0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap(1, 2);
|
mut_a.swap(1, 2);
|
||||||
assert!(*mut_a.index(1) == *a.index(2));
|
assert_eq!(*mut_a.index(1), *a.index(2));
|
||||||
assert!(*mut_a.index(2) == *a.index(1));
|
assert_eq!(*mut_a.index(2), *a.index(1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
assert!(a.x == 1.0);
|
assert_eq!(a.x, 1.0);
|
||||||
assert!(a.y == 2.0);
|
assert_eq!(a.y, 2.0);
|
||||||
assert!(a.z == 3.0);
|
assert_eq!(a.z, 3.0);
|
||||||
assert!(*a.index(0) == 1.0);
|
assert_eq!(*a.index(0), 1.0);
|
||||||
assert!(*a.index(1) == 2.0);
|
assert_eq!(*a.index(1), 2.0);
|
||||||
assert!(*a.index(2) == 3.0);
|
assert_eq!(*a.index(2), 3.0);
|
||||||
|
|
||||||
assert!(a.cross(&b) == vec3::new(-3.0, 6.0, -3.0));
|
assert_eq!(a.cross(&b), vec3::new(-3.0, 6.0, -3.0));
|
||||||
|
|
||||||
mut_a.cross_self(&b);
|
mut_a.cross_self(&b);
|
||||||
assert!(mut_a == a.cross(&b));
|
assert_eq!(mut_a, a.cross(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
assert!(-a == vec3::new(-1.0, -2.0, -3.0));
|
assert_eq!(-a, vec3::new(-1.0, -2.0, -3.0));
|
||||||
assert!(a.neg() == vec3::new(-1.0, -2.0, -3.0));
|
assert_eq!(a.neg(), vec3::new(-1.0, -2.0, -3.0));
|
||||||
|
|
||||||
assert!(vec3::new(0.0, 0.0, 0.0).is_zero());
|
assert!(vec3::new(0.0, 0.0, 0.0).is_zero());
|
||||||
assert!(!vec3::new(1.0, 1.0, 1.0).is_zero());
|
assert!(!vec3::new(1.0, 1.0, 1.0).is_zero());
|
||||||
|
|
||||||
assert!(a.mul_t(f1) == vec3::new( 1.5, 3.0, 4.5));
|
assert_eq!(a.mul_t(f1), vec3::new( 1.5, 3.0, 4.5));
|
||||||
assert!(a.div_t(f2) == vec3::new( 2.0, 4.0, 6.0));
|
assert_eq!(a.div_t(f2), vec3::new( 2.0, 4.0, 6.0));
|
||||||
|
|
||||||
assert!(a.add_v(&b) == vec3::new( 5.0, 7.0, 9.0));
|
assert_eq!(a.add_v(&b), vec3::new( 5.0, 7.0, 9.0));
|
||||||
assert!(a.sub_v(&b) == vec3::new( -3.0, -3.0, -3.0));
|
assert_eq!(a.sub_v(&b), vec3::new( -3.0, -3.0, -3.0));
|
||||||
assert!(a.mul_v(&b) == vec3::new( 4.0, 10.0, 18.0));
|
assert_eq!(a.mul_v(&b), vec3::new( 4.0, 10.0, 18.0));
|
||||||
assert!(a.div_v(&b) == vec3::new(1.0/4.0, 2.0/5.0, 3.0/6.0));
|
assert_eq!(a.div_v(&b), vec3::new(1.0/4.0, 2.0/5.0, 3.0/6.0));
|
||||||
|
|
||||||
mut_a.neg_self();
|
mut_a.neg_self();
|
||||||
assert!(mut_a == -a);
|
assert_eq!(mut_a, -a);
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.mul_self_t(f1);
|
mut_a.mul_self_t(f1);
|
||||||
assert!(mut_a == a.mul_t(f1));
|
assert_eq!(mut_a, a.mul_t(f1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.div_self_t(f2);
|
mut_a.div_self_t(f2);
|
||||||
assert!(mut_a == a.div_t(f2));
|
assert_eq!(mut_a, a.div_t(f2));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.add_self_v(&b);
|
mut_a.add_self_v(&b);
|
||||||
assert!(mut_a == a.add_v(&b));
|
assert_eq!(mut_a, a.add_v(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.sub_self_v(&b);
|
mut_a.sub_self_v(&b);
|
||||||
assert!(mut_a == a.sub_v(&b));
|
assert_eq!(mut_a, a.sub_v(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.mul_self_v(&b);
|
mut_a.mul_self_v(&b);
|
||||||
assert!(mut_a == a.mul_v(&b));
|
assert_eq!(mut_a, a.mul_v(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.div_self_v(&b);
|
mut_a.div_self_v(&b);
|
||||||
assert!(mut_a == a.div_v(&b));
|
assert_eq!(mut_a, a.div_v(&b));
|
||||||
// mut_a = a;
|
// mut_a = a;
|
||||||
|
|
||||||
// exact_eq
|
// exact_eq
|
||||||
// approx_eq
|
// approx_eq
|
||||||
// eq
|
// eq
|
||||||
|
|
||||||
// assert!(c.abs() == vec3::new( 2.0, 1.0, 1.0));
|
// assert_eq!(c.abs(), vec3::new( 2.0, 1.0, 1.0));
|
||||||
// assert!(c.min(&d) == vec3::new(-2.0, -1.0, 0.5));
|
// assert_eq!(c.min(&d), vec3::new(-2.0, -1.0, 0.5));
|
||||||
// assert!(c.max(&d) == vec3::new( 1.0, 0.0, 1.0));
|
// assert_eq!(c.max(&d), vec3::new( 1.0, 0.0, 1.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -267,14 +267,14 @@ fn test_vec3_euclidean() {
|
||||||
let b0 = vec3::new(1.0, 4.0, 8.0); // (1, 4, 8, 9) Pythagorean quadruple
|
let b0 = vec3::new(1.0, 4.0, 8.0); // (1, 4, 8, 9) Pythagorean quadruple
|
||||||
let b = a.add_v(&b0);
|
let b = a.add_v(&b0);
|
||||||
|
|
||||||
assert!(a.length() == 7.0);
|
assert_eq!(a.length(), 7.0);
|
||||||
assert!(a.length2() == 7.0 * 7.0);
|
assert_eq!(a.length2(), 7.0 * 7.0);
|
||||||
|
|
||||||
assert!(b0.length() == 9.0);
|
assert_eq!(b0.length(), 9.0);
|
||||||
assert!(b0.length2() == 9.0 * 9.0);
|
assert_eq!(b0.length2(), 9.0 * 9.0);
|
||||||
|
|
||||||
assert!(a.distance(&b) == 9.0);
|
assert_eq!(a.distance(&b), 9.0);
|
||||||
assert!(a.distance2(&b) == 9.0 * 9.0);
|
assert_eq!(a.distance2(&b), 9.0 * 9.0);
|
||||||
|
|
||||||
assert!(vec3::new(1.0, 0.0, 1.0).angle(&vec3::new(1.0, 1.0, 0.0)).approx_eq(&Real::frac_pi_3()));
|
assert!(vec3::new(1.0, 0.0, 1.0).angle(&vec3::new(1.0, 1.0, 0.0)).approx_eq(&Real::frac_pi_3()));
|
||||||
assert!(vec3::new(10.0, 0.0, 10.0).angle(&vec3::new(5.0, 5.0, 0.0)).approx_eq(&Real::frac_pi_3()));
|
assert!(vec3::new(10.0, 0.0, 10.0).angle(&vec3::new(5.0, 5.0, 0.0)).approx_eq(&Real::frac_pi_3()));
|
||||||
|
@ -286,11 +286,11 @@ fn test_vec3_euclidean() {
|
||||||
let c = vec3::new(-2.0, -1.0, 1.0);
|
let c = vec3::new(-2.0, -1.0, 1.0);
|
||||||
let d = vec3::new( 1.0, 0.0, 0.5);
|
let d = vec3::new( 1.0, 0.0, 0.5);
|
||||||
|
|
||||||
assert!(c.lerp(&d, 0.75) == vec3::new(0.250, -0.250, 0.625));
|
assert_eq!(c.lerp(&d, 0.75), vec3::new(0.250, -0.250, 0.625));
|
||||||
|
|
||||||
let mut mut_c = c;
|
let mut mut_c = c;
|
||||||
mut_c.lerp_self(&d, 0.75);
|
mut_c.lerp_self(&d, 0.75);
|
||||||
assert!(mut_c == c.lerp(&d, 0.75));
|
assert_eq!(mut_c, c.lerp(&d, 0.75));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -299,22 +299,22 @@ fn test_vec3_boolean() {
|
||||||
let fff = bvec3::new(false, false, false);
|
let fff = bvec3::new(false, false, false);
|
||||||
let ttt = bvec3::new(true, true, true);
|
let ttt = bvec3::new(true, true, true);
|
||||||
|
|
||||||
assert!(tft.any() == true);
|
assert_eq!(tft.any(), true);
|
||||||
assert!(tft.all() == false);
|
assert_eq!(tft.all(), false);
|
||||||
assert!(tft.not() == bvec3::new(false, true, false));
|
assert_eq!(tft.not(), bvec3::new(false, true, false));
|
||||||
|
|
||||||
assert!(fff.any() == false);
|
assert_eq!(fff.any(), false);
|
||||||
assert!(fff.all() == false);
|
assert_eq!(fff.all(), false);
|
||||||
assert!(fff.not() == bvec3::new(true, true, true));
|
assert_eq!(fff.not(), bvec3::new(true, true, true));
|
||||||
|
|
||||||
assert!(ttt.any() == true);
|
assert_eq!(ttt.any(), true);
|
||||||
assert!(ttt.all() == true);
|
assert_eq!(ttt.all(), true);
|
||||||
assert!(ttt.not() == bvec3::new(false, false, false));
|
assert_eq!(ttt.not(), bvec3::new(false, false, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_vec4() {
|
fn test_vec4() {
|
||||||
// assert!(Vec4::dim == 4);
|
// assert_eq!(Vec4::dim, 4);
|
||||||
|
|
||||||
let a = Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 };
|
let a = Vec4 { x: 1.0, y: 2.0, z: 3.0, w: 4.0 };
|
||||||
let b = Vec4 { x: 5.0, y: 6.0, z: 7.0, w: 8.0 };
|
let b = Vec4 { x: 5.0, y: 6.0, z: 7.0, w: 8.0 };
|
||||||
|
@ -323,89 +323,89 @@ fn test_vec4() {
|
||||||
|
|
||||||
let mut mut_a = a;
|
let mut mut_a = a;
|
||||||
|
|
||||||
assert!(vec4::new(1.0, 2.0, 3.0, 4.0) == a);
|
assert_eq!(vec4::new(1.0, 2.0, 3.0, 4.0), a);
|
||||||
assert!(vec4::from_value(1.0) == vec4::new(1.0, 1.0, 1.0, 1.0));
|
assert_eq!(vec4::from_value(1.0), vec4::new(1.0, 1.0, 1.0, 1.0));
|
||||||
|
|
||||||
*mut_a.index_mut(0) = 42.0;
|
*mut_a.index_mut(0) = 42.0;
|
||||||
*mut_a.index_mut(1) = 43.0;
|
*mut_a.index_mut(1) = 43.0;
|
||||||
*mut_a.index_mut(2) = 44.0;
|
*mut_a.index_mut(2) = 44.0;
|
||||||
*mut_a.index_mut(3) = 45.0;
|
*mut_a.index_mut(3) = 45.0;
|
||||||
assert!(mut_a == vec4::new(42.0, 43.0, 44.0, 45.0));
|
assert_eq!(mut_a, vec4::new(42.0, 43.0, 44.0, 45.0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap(0, 3);
|
mut_a.swap(0, 3);
|
||||||
assert!(*mut_a.index(0) == *a.index(3));
|
assert_eq!(*mut_a.index(0), *a.index(3));
|
||||||
assert!(*mut_a.index(3) == *a.index(0));
|
assert_eq!(*mut_a.index(3), *a.index(0));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.swap(1, 2);
|
mut_a.swap(1, 2);
|
||||||
assert!(*mut_a.index(1) == *a.index(2));
|
assert_eq!(*mut_a.index(1), *a.index(2));
|
||||||
assert!(*mut_a.index(2) == *a.index(1));
|
assert_eq!(*mut_a.index(2), *a.index(1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
assert!(vec4::zero() == vec4::new(0.0, 0.0, 0.0, 0.0));
|
assert_eq!(vec4::zero(), vec4::new(0.0, 0.0, 0.0, 0.0));
|
||||||
assert!(vec4::unit_x() == vec4::new(1.0, 0.0, 0.0, 0.0));
|
assert_eq!(vec4::unit_x(), vec4::new(1.0, 0.0, 0.0, 0.0));
|
||||||
assert!(vec4::unit_y() == vec4::new(0.0, 1.0, 0.0, 0.0));
|
assert_eq!(vec4::unit_y(), vec4::new(0.0, 1.0, 0.0, 0.0));
|
||||||
assert!(vec4::unit_z() == vec4::new(0.0, 0.0, 1.0, 0.0));
|
assert_eq!(vec4::unit_z(), vec4::new(0.0, 0.0, 1.0, 0.0));
|
||||||
assert!(vec4::unit_w() == vec4::new(0.0, 0.0, 0.0, 1.0));
|
assert_eq!(vec4::unit_w(), vec4::new(0.0, 0.0, 0.0, 1.0));
|
||||||
assert!(vec4::identity() == vec4::new(1.0, 1.0, 1.0, 1.0));
|
assert_eq!(vec4::identity(), vec4::new(1.0, 1.0, 1.0, 1.0));
|
||||||
|
|
||||||
assert!(a.x == 1.0);
|
assert_eq!(a.x, 1.0);
|
||||||
assert!(a.y == 2.0);
|
assert_eq!(a.y, 2.0);
|
||||||
assert!(a.z == 3.0);
|
assert_eq!(a.z, 3.0);
|
||||||
assert!(a.w == 4.0);
|
assert_eq!(a.w, 4.0);
|
||||||
assert!(*a.index(0) == 1.0);
|
assert_eq!(*a.index(0), 1.0);
|
||||||
assert!(*a.index(1) == 2.0);
|
assert_eq!(*a.index(1), 2.0);
|
||||||
assert!(*a.index(2) == 3.0);
|
assert_eq!(*a.index(2), 3.0);
|
||||||
assert!(*a.index(3) == 4.0);
|
assert_eq!(*a.index(3), 4.0);
|
||||||
|
|
||||||
assert!(-a == vec4::new(-1.0, -2.0, -3.0, -4.0));
|
assert_eq!(-a, vec4::new(-1.0, -2.0, -3.0, -4.0));
|
||||||
assert!(a.neg() == vec4::new(-1.0, -2.0, -3.0, -4.0));
|
assert_eq!(a.neg(), vec4::new(-1.0, -2.0, -3.0, -4.0));
|
||||||
|
|
||||||
assert!(vec4::new(0.0, 0.0, 0.0, 0.0).is_zero());
|
assert!(vec4::new(0.0, 0.0, 0.0, 0.0).is_zero());
|
||||||
assert!(!vec4::new(1.0, 1.0, 1.0, 1.0).is_zero());
|
assert!(!vec4::new(1.0, 1.0, 1.0, 1.0).is_zero());
|
||||||
|
|
||||||
assert!(a.mul_t(f1) == vec4::new( 1.5, 3.0, 4.5, 6.0));
|
assert_eq!(a.mul_t(f1), vec4::new( 1.5, 3.0, 4.5, 6.0));
|
||||||
assert!(a.div_t(f2) == vec4::new( 2.0, 4.0, 6.0, 8.0));
|
assert_eq!(a.div_t(f2), vec4::new( 2.0, 4.0, 6.0, 8.0));
|
||||||
|
|
||||||
assert!(a.add_v(&b) == vec4::new( 6.0, 8.0, 10.0, 12.0));
|
assert_eq!(a.add_v(&b), vec4::new( 6.0, 8.0, 10.0, 12.0));
|
||||||
assert!(a.sub_v(&b) == vec4::new( -4.0, -4.0, -4.0, -4.0));
|
assert_eq!(a.sub_v(&b), vec4::new( -4.0, -4.0, -4.0, -4.0));
|
||||||
assert!(a.mul_v(&b) == vec4::new( 5.0, 12.0, 21.0, 32.0));
|
assert_eq!(a.mul_v(&b), vec4::new( 5.0, 12.0, 21.0, 32.0));
|
||||||
assert!(a.div_v(&b) == vec4::new(1.0/5.0, 2.0/6.0, 3.0/7.0, 4.0/8.0));
|
assert_eq!(a.div_v(&b), vec4::new(1.0/5.0, 2.0/6.0, 3.0/7.0, 4.0/8.0));
|
||||||
|
|
||||||
assert!(a.dot(&b) == 70.0);
|
assert_eq!(a.dot(&b), 70.0);
|
||||||
|
|
||||||
mut_a.neg_self();
|
mut_a.neg_self();
|
||||||
assert!(mut_a == -a);
|
assert_eq!(mut_a, -a);
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.mul_self_t(f1);
|
mut_a.mul_self_t(f1);
|
||||||
assert!(mut_a == a.mul_t(f1));
|
assert_eq!(mut_a, a.mul_t(f1));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.div_self_t(f2);
|
mut_a.div_self_t(f2);
|
||||||
assert!(mut_a == a.div_t(f2));
|
assert_eq!(mut_a, a.div_t(f2));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.add_self_v(&b);
|
mut_a.add_self_v(&b);
|
||||||
assert!(mut_a == a.add_v(&b));
|
assert_eq!(mut_a, a.add_v(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.sub_self_v(&b);
|
mut_a.sub_self_v(&b);
|
||||||
assert!(mut_a == a.sub_v(&b));
|
assert_eq!(mut_a, a.sub_v(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.mul_self_v(&b);
|
mut_a.mul_self_v(&b);
|
||||||
assert!(mut_a == a.mul_v(&b));
|
assert_eq!(mut_a, a.mul_v(&b));
|
||||||
mut_a = a;
|
mut_a = a;
|
||||||
|
|
||||||
mut_a.div_self_v(&b);
|
mut_a.div_self_v(&b);
|
||||||
assert!(mut_a == a.div_v(&b));
|
assert_eq!(mut_a, a.div_v(&b));
|
||||||
// mut_a = a;
|
// mut_a = a;
|
||||||
|
|
||||||
// assert!(c.abs() == vec4::new( 2.0, 1.0, 1.0, 2.0));
|
// assert_eq!(c.abs(), vec4::new( 2.0, 1.0, 1.0, 2.0));
|
||||||
// assert!(c.min(&d) == vec4::new(-2.0, -1.0, 0.5, 1.0));
|
// assert_eq!(c.min(&d), vec4::new(-2.0, -1.0, 0.5, 1.0));
|
||||||
// assert!(c.max(&d) == vec4::new( 1.0, 0.0, 1.0, 2.0));
|
// assert_eq!(c.max(&d), vec4::new( 1.0, 0.0, 1.0, 2.0));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -420,14 +420,14 @@ fn test_vec4_euclidean() {
|
||||||
let b0 = vec4::new(1.0, 2.0, 8.0, 10.0); // (1, 2, 8, 10, 13) Pythagorean quintuple
|
let b0 = vec4::new(1.0, 2.0, 8.0, 10.0); // (1, 2, 8, 10, 13) Pythagorean quintuple
|
||||||
let b = a.add_v(&b0);
|
let b = a.add_v(&b0);
|
||||||
|
|
||||||
assert!(a.length() == 11.0);
|
assert_eq!(a.length(), 11.0);
|
||||||
assert!(a.length2() == 11.0 * 11.0);
|
assert_eq!(a.length2(), 11.0 * 11.0);
|
||||||
|
|
||||||
assert!(b0.length() == 13.0);
|
assert_eq!(b0.length(), 13.0);
|
||||||
assert!(b0.length2() == 13.0 * 13.0);
|
assert_eq!(b0.length2(), 13.0 * 13.0);
|
||||||
|
|
||||||
assert!(a.distance(&b) == 13.0);
|
assert_eq!(a.distance(&b), 13.0);
|
||||||
assert!(a.distance2(&b) == 13.0 * 13.0);
|
assert_eq!(a.distance2(&b), 13.0 * 13.0);
|
||||||
|
|
||||||
assert!(vec4::new(1.0, 0.0, 1.0, 0.0).angle(&vec4::new(0.0, 1.0, 0.0, 1.0)).approx_eq(&Real::frac_pi_2()));
|
assert!(vec4::new(1.0, 0.0, 1.0, 0.0).angle(&vec4::new(0.0, 1.0, 0.0, 1.0)).approx_eq(&Real::frac_pi_2()));
|
||||||
assert!(vec4::new(10.0, 0.0, 10.0, 0.0).angle(&vec4::new(0.0, 5.0, 0.0, 5.0)).approx_eq(&Real::frac_pi_2()));
|
assert!(vec4::new(10.0, 0.0, 10.0, 0.0).angle(&vec4::new(0.0, 5.0, 0.0, 5.0)).approx_eq(&Real::frac_pi_2()));
|
||||||
|
@ -439,11 +439,11 @@ fn test_vec4_euclidean() {
|
||||||
let c = vec4::new(-2.0, -1.0, 1.0, 2.0);
|
let c = vec4::new(-2.0, -1.0, 1.0, 2.0);
|
||||||
let d = vec4::new( 1.0, 0.0, 0.5, 1.0);
|
let d = vec4::new( 1.0, 0.0, 0.5, 1.0);
|
||||||
|
|
||||||
assert!(c.lerp(&d, 0.75) == vec4::new(0.250, -0.250, 0.625, 1.250));
|
assert_eq!(c.lerp(&d, 0.75), vec4::new(0.250, -0.250, 0.625, 1.250));
|
||||||
|
|
||||||
let mut mut_c = c;
|
let mut mut_c = c;
|
||||||
mut_c.lerp_self(&d, 0.75);
|
mut_c.lerp_self(&d, 0.75);
|
||||||
assert!(mut_c == c.lerp(&d, 0.75));
|
assert_eq!(mut_c, c.lerp(&d, 0.75));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
@ -452,15 +452,15 @@ fn test_vec4_boolean() {
|
||||||
let ffff = bvec4::new(false, false, false, false);
|
let ffff = bvec4::new(false, false, false, false);
|
||||||
let tttt = bvec4::new(true, true, true, true);
|
let tttt = bvec4::new(true, true, true, true);
|
||||||
|
|
||||||
assert!(tftf.any() == true);
|
assert_eq!(tftf.any(), true);
|
||||||
assert!(tftf.all() == false);
|
assert_eq!(tftf.all(), false);
|
||||||
assert!(tftf.not() == bvec4::new(false, true, false, true));
|
assert_eq!(tftf.not(), bvec4::new(false, true, false, true));
|
||||||
|
|
||||||
assert!(ffff.any() == false);
|
assert_eq!(ffff.any(), false);
|
||||||
assert!(ffff.all() == false);
|
assert_eq!(ffff.all(), false);
|
||||||
assert!(ffff.not() == bvec4::new(true, true, true, true));
|
assert_eq!(ffff.not(), bvec4::new(true, true, true, true));
|
||||||
|
|
||||||
assert!(tttt.any() == true);
|
assert_eq!(tttt.any(), true);
|
||||||
assert!(tttt.all() == true);
|
assert_eq!(tttt.all(), true);
|
||||||
assert!(tttt.not() == bvec4::new(false, false, false, false));
|
assert_eq!(tttt.not(), bvec4::new(false, false, false, false));
|
||||||
}
|
}
|
231
src/vec.rs
231
src/vec.rs
|
@ -828,6 +828,82 @@ impl BoolVec for Vec2<bool> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! vec2_type(
|
||||||
|
($name:ident <bool>) => (
|
||||||
|
pub mod $name {
|
||||||
|
use super::*;
|
||||||
|
#[inline(always)] pub fn new(x: bool, y: bool) -> $name { BaseVec2::new(x, y) }
|
||||||
|
#[inline(always)] pub fn from_value(v: bool) -> $name { BaseVec::from_value(v) }
|
||||||
|
#[inline(always)] pub fn dim() -> uint { 2 }
|
||||||
|
#[inline(always)] pub fn size_of() -> uint { sys::size_of::<$name>() }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
($name:ident <$T:ty>) => (
|
||||||
|
pub mod $name {
|
||||||
|
use super::*;
|
||||||
|
#[inline(always)] pub fn new(x: $T, y: $T) -> $name { BaseVec2::new(x, y) }
|
||||||
|
#[inline(always)] pub fn from_value(v: $T) -> $name { BaseVec::from_value(v) }
|
||||||
|
#[inline(always)] pub fn identity() -> $name { NumVec::identity() }
|
||||||
|
#[inline(always)] pub fn zero() -> $name { NumVec::zero() }
|
||||||
|
#[inline(always)] pub fn unit_x() -> $name { NumVec2::unit_x() }
|
||||||
|
#[inline(always)] pub fn unit_y() -> $name { NumVec2::unit_y() }
|
||||||
|
#[inline(always)] pub fn dim() -> uint { 2 }
|
||||||
|
#[inline(always)] pub fn size_of() -> uint { sys::size_of::<$name>() }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
)
|
||||||
|
|
||||||
|
// GLSL-style type aliases, corresponding to Section 4.1.5 of the [GLSL 4.30.6 specification]
|
||||||
|
// (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf).
|
||||||
|
|
||||||
|
// a two-component single-precision floating-point vector
|
||||||
|
pub type vec2 = Vec2<f32>;
|
||||||
|
// a two-component double-precision floating-point vector
|
||||||
|
pub type dvec2 = Vec2<f64>;
|
||||||
|
// a two-component Boolean vector
|
||||||
|
pub type bvec2 = Vec2<bool>;
|
||||||
|
// a two-component signed integer vector
|
||||||
|
pub type ivec2 = Vec2<i32>;
|
||||||
|
// a two-component unsigned integer vector
|
||||||
|
pub type uvec2 = Vec2<u32>;
|
||||||
|
|
||||||
|
vec2_type!(vec2<f32>)
|
||||||
|
vec2_type!(dvec2<f64>)
|
||||||
|
vec2_type!(bvec2<bool>)
|
||||||
|
vec2_type!(ivec2<i32>)
|
||||||
|
vec2_type!(uvec2<u32>)
|
||||||
|
|
||||||
|
// Rust-style type aliases
|
||||||
|
pub type Vec2f = Vec2<float>;
|
||||||
|
pub type Vec2f32 = Vec2<f32>;
|
||||||
|
pub type Vec2f64 = Vec2<f64>;
|
||||||
|
pub type Vec2i = Vec2<int>;
|
||||||
|
pub type Vec2i8 = Vec2<i8>;
|
||||||
|
pub type Vec2i16 = Vec2<i16>;
|
||||||
|
pub type Vec2i32 = Vec2<i32>;
|
||||||
|
pub type Vec2i64 = Vec2<i64>;
|
||||||
|
pub type Vec2u = Vec2<uint>;
|
||||||
|
pub type Vec2u8 = Vec2<u8>;
|
||||||
|
pub type Vec2u16 = Vec2<u16>;
|
||||||
|
pub type Vec2u32 = Vec2<u32>;
|
||||||
|
pub type Vec2u64 = Vec2<u64>;
|
||||||
|
pub type Vec2b = Vec2<bool>;
|
||||||
|
|
||||||
|
vec2_type!(Vec2f<float>)
|
||||||
|
vec2_type!(Vec2f32<f32>)
|
||||||
|
vec2_type!(Vec2f64<f64>)
|
||||||
|
vec2_type!(Vec2i<int>)
|
||||||
|
vec2_type!(Vec2i8<i8>)
|
||||||
|
vec2_type!(Vec2i16<i16>)
|
||||||
|
vec2_type!(Vec2i32<i32>)
|
||||||
|
vec2_type!(Vec2i64<i64>)
|
||||||
|
vec2_type!(Vec2u<uint>)
|
||||||
|
vec2_type!(Vec2u8<u8>)
|
||||||
|
vec2_type!(Vec2u16<u16>)
|
||||||
|
vec2_type!(Vec2u32<u32>)
|
||||||
|
vec2_type!(Vec2u64<u64>)
|
||||||
|
vec2_type!(Vec2b<bool>)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A 3-dimensional vector
|
* A 3-dimensional vector
|
||||||
*
|
*
|
||||||
|
@ -1156,6 +1232,83 @@ impl BoolVec for Vec3<bool> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! vec3_type(
|
||||||
|
($name:ident <bool>) => (
|
||||||
|
pub mod $name {
|
||||||
|
use super::*;
|
||||||
|
#[inline(always)] pub fn new(x: bool, y: bool, z: bool) -> $name { BaseVec3::new(x, y, z) }
|
||||||
|
#[inline(always)] pub fn from_value(v: bool) -> $name { BaseVec::from_value(v) }
|
||||||
|
#[inline(always)] pub fn dim() -> uint { 3 }
|
||||||
|
#[inline(always)] pub fn size_of() -> uint { sys::size_of::<$name>() }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
($name:ident <$T:ty>) => (
|
||||||
|
pub mod $name {
|
||||||
|
use super::*;
|
||||||
|
#[inline(always)] pub fn new(x: $T, y: $T, z: $T) -> $name { BaseVec3::new(x, y, z) }
|
||||||
|
#[inline(always)] pub fn from_value(v: $T) -> $name { BaseVec::from_value(v) }
|
||||||
|
#[inline(always)] pub fn identity() -> $name { NumVec::identity() }
|
||||||
|
#[inline(always)] pub fn zero() -> $name { NumVec::zero() }
|
||||||
|
#[inline(always)] pub fn unit_x() -> $name { NumVec3::unit_x() }
|
||||||
|
#[inline(always)] pub fn unit_y() -> $name { NumVec3::unit_y() }
|
||||||
|
#[inline(always)] pub fn unit_z() -> $name { NumVec3::unit_z() }
|
||||||
|
#[inline(always)] pub fn dim() -> uint { 3 }
|
||||||
|
#[inline(always)] pub fn size_of() -> uint { sys::size_of::<$name>() }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
)
|
||||||
|
|
||||||
|
// GLSL-style type aliases, corresponding to Section 4.1.5 of the [GLSL 4.30.6 specification]
|
||||||
|
// (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf).
|
||||||
|
|
||||||
|
// a three-component single-precision floating-point vector
|
||||||
|
pub type vec3 = Vec3<f32>;
|
||||||
|
// a three-component double-precision floating-point vector
|
||||||
|
pub type dvec3 = Vec3<f64>;
|
||||||
|
// a three-component Boolean vector
|
||||||
|
pub type bvec3 = Vec3<bool>;
|
||||||
|
// a three-component signed integer vector
|
||||||
|
pub type ivec3 = Vec3<i32>;
|
||||||
|
// a three-component unsigned integer vector
|
||||||
|
pub type uvec3 = Vec3<u32>;
|
||||||
|
|
||||||
|
vec3_type!(vec3<f32>)
|
||||||
|
vec3_type!(dvec3<f64>)
|
||||||
|
vec3_type!(bvec3<bool>)
|
||||||
|
vec3_type!(ivec3<i32>)
|
||||||
|
vec3_type!(uvec3<u32>)
|
||||||
|
|
||||||
|
// Rust-style type aliases
|
||||||
|
pub type Vec3f = Vec3<float>;
|
||||||
|
pub type Vec3f32 = Vec3<f32>;
|
||||||
|
pub type Vec3f64 = Vec3<f64>;
|
||||||
|
pub type Vec3i = Vec3<int>;
|
||||||
|
pub type Vec3i8 = Vec3<i8>;
|
||||||
|
pub type Vec3i16 = Vec3<i16>;
|
||||||
|
pub type Vec3i32 = Vec3<i32>;
|
||||||
|
pub type Vec3i64 = Vec3<i64>;
|
||||||
|
pub type Vec3u = Vec3<uint>;
|
||||||
|
pub type Vec3u8 = Vec3<u8>;
|
||||||
|
pub type Vec3u16 = Vec3<u16>;
|
||||||
|
pub type Vec3u32 = Vec3<u32>;
|
||||||
|
pub type Vec3u64 = Vec3<u64>;
|
||||||
|
pub type Vec3b = Vec3<bool>;
|
||||||
|
|
||||||
|
vec3_type!(Vec3f<float>)
|
||||||
|
vec3_type!(Vec3f32<f32>)
|
||||||
|
vec3_type!(Vec3f64<f64>)
|
||||||
|
vec3_type!(Vec3i<int>)
|
||||||
|
vec3_type!(Vec3i8<i8>)
|
||||||
|
vec3_type!(Vec3i16<i16>)
|
||||||
|
vec3_type!(Vec3i32<i32>)
|
||||||
|
vec3_type!(Vec3i64<i64>)
|
||||||
|
vec3_type!(Vec3u<uint>)
|
||||||
|
vec3_type!(Vec3u8<u8>)
|
||||||
|
vec3_type!(Vec3u16<u16>)
|
||||||
|
vec3_type!(Vec3u32<u32>)
|
||||||
|
vec3_type!(Vec3u64<u64>)
|
||||||
|
vec3_type!(Vec3b<bool>)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A 4-dimensional vector
|
* A 4-dimensional vector
|
||||||
*
|
*
|
||||||
|
@ -1482,3 +1635,81 @@ impl BoolVec for Vec4<bool> {
|
||||||
BaseVec4::new(!*self.index(0), !*self.index(1), !*self.index(2), !*self.index(3))
|
BaseVec4::new(!*self.index(0), !*self.index(1), !*self.index(2), !*self.index(3))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
macro_rules! vec4_type(
|
||||||
|
($name:ident <bool>) => (
|
||||||
|
pub mod $name {
|
||||||
|
use super::*;
|
||||||
|
#[inline(always)] pub fn new(x: bool, y: bool, z: bool, w: bool) -> $name { BaseVec4::new(x, y, z, w) }
|
||||||
|
#[inline(always)] pub fn from_value(v: bool) -> $name { BaseVec::from_value(v) }
|
||||||
|
#[inline(always)] pub fn dim() -> uint { 4 }
|
||||||
|
#[inline(always)] pub fn size_of() -> uint { sys::size_of::<$name>() }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
($name:ident <$T:ty>) => (
|
||||||
|
pub mod $name {
|
||||||
|
use super::*;
|
||||||
|
#[inline(always)] pub fn new(x: $T, y: $T, z: $T, w: $T) -> $name { BaseVec4::new(x, y, z, w) }
|
||||||
|
#[inline(always)] pub fn from_value(v: $T) -> $name { BaseVec::from_value(v) }
|
||||||
|
#[inline(always)] pub fn identity() -> $name { NumVec::identity() }
|
||||||
|
#[inline(always)] pub fn zero() -> $name { NumVec::zero() }
|
||||||
|
#[inline(always)] pub fn unit_x() -> $name { NumVec4::unit_x() }
|
||||||
|
#[inline(always)] pub fn unit_y() -> $name { NumVec4::unit_y() }
|
||||||
|
#[inline(always)] pub fn unit_z() -> $name { NumVec4::unit_z() }
|
||||||
|
#[inline(always)] pub fn unit_w() -> $name { NumVec4::unit_w() }
|
||||||
|
#[inline(always)] pub fn dim() -> uint { 4 }
|
||||||
|
#[inline(always)] pub fn size_of() -> uint { sys::size_of::<$name>() }
|
||||||
|
}
|
||||||
|
);
|
||||||
|
)
|
||||||
|
|
||||||
|
// GLSL-style type aliases, corresponding to Section 4.1.5 of the [GLSL 4.30.6 specification]
|
||||||
|
// (http://www.opengl.org/registry/doc/GLSLangSpec.4.30.6.pdf).
|
||||||
|
|
||||||
|
// a four-component single-precision floating-point vector
|
||||||
|
pub type vec4 = Vec4<f32>;
|
||||||
|
// a four-component double-precision floating-point vector
|
||||||
|
pub type dvec4 = Vec4<f64>;
|
||||||
|
// a four-component Boolean vector
|
||||||
|
pub type bvec4 = Vec4<bool>;
|
||||||
|
// a four-component signed integer vector
|
||||||
|
pub type ivec4 = Vec4<i32>;
|
||||||
|
// a four-component unsigned integer vector
|
||||||
|
pub type uvec4 = Vec4<u32>;
|
||||||
|
|
||||||
|
vec4_type!(vec4<f32>)
|
||||||
|
vec4_type!(dvec4<f64>)
|
||||||
|
vec4_type!(bvec4<bool>)
|
||||||
|
vec4_type!(ivec4<i32>)
|
||||||
|
vec4_type!(uvec4<u32>)
|
||||||
|
|
||||||
|
// Rust-style type aliases
|
||||||
|
pub type Vec4f = Vec4<float>;
|
||||||
|
pub type Vec4f32 = Vec4<f32>;
|
||||||
|
pub type Vec4f64 = Vec4<f64>;
|
||||||
|
pub type Vec4i = Vec4<int>;
|
||||||
|
pub type Vec4i8 = Vec4<i8>;
|
||||||
|
pub type Vec4i16 = Vec4<i16>;
|
||||||
|
pub type Vec4i32 = Vec4<i32>;
|
||||||
|
pub type Vec4i64 = Vec4<i64>;
|
||||||
|
pub type Vec4u = Vec4<uint>;
|
||||||
|
pub type Vec4u8 = Vec4<u8>;
|
||||||
|
pub type Vec4u16 = Vec4<u16>;
|
||||||
|
pub type Vec4u32 = Vec4<u32>;
|
||||||
|
pub type Vec4u64 = Vec4<u64>;
|
||||||
|
pub type Vec4b = Vec4<bool>;
|
||||||
|
|
||||||
|
vec4_type!(Vec4f<float>)
|
||||||
|
vec4_type!(Vec4f32<f32>)
|
||||||
|
vec4_type!(Vec4f64<f64>)
|
||||||
|
vec4_type!(Vec4i<int>)
|
||||||
|
vec4_type!(Vec4i8<i8>)
|
||||||
|
vec4_type!(Vec4i16<i16>)
|
||||||
|
vec4_type!(Vec4i32<i32>)
|
||||||
|
vec4_type!(Vec4i64<i64>)
|
||||||
|
vec4_type!(Vec4u<uint>)
|
||||||
|
vec4_type!(Vec4u8<u8>)
|
||||||
|
vec4_type!(Vec4u16<u16>)
|
||||||
|
vec4_type!(Vec4u32<u32>)
|
||||||
|
vec4_type!(Vec4u64<u64>)
|
||||||
|
vec4_type!(Vec4b<bool>)
|
||||||
|
|
Loading…
Reference in a new issue