From edf17b566715f66c742eeb2c0f40f97c072a0770 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Tue, 8 Oct 2013 01:22:56 +0200 Subject: [PATCH] Update to the last Rust. Also use free-functions on tests. --- README.md | 10 ++-- src/bench/mat.rs | 2 +- src/bench/vec.rs | 5 +- src/lib.rs | 11 +++-- src/na.rs | 101 ++++++++++++++++++++++++++++++++++++++ src/structs/dmat.rs | 10 ++-- src/structs/iso_macros.rs | 4 +- src/structs/mat_macros.rs | 2 +- src/structs/rot.rs | 6 +-- src/structs/rot_macros.rs | 2 +- src/structs/spec/mat.rs | 8 +-- src/structs/vec_macros.rs | 2 +- src/tests/mat.rs | 58 +++++++++++----------- src/tests/vec.rs | 69 +++++++++++++------------- 14 files changed, 196 insertions(+), 94 deletions(-) diff --git a/README.md b/README.md index 9da1f02a..51bd2192 100644 --- a/README.md +++ b/README.md @@ -29,15 +29,15 @@ use nalgebra::traits::*; ```.rust use nalgebra::structs::*; ``` -Of course, you can still import `nalgebra::na` alone, and get anything you want using the `na` -prefix. +Of course, you can still import `nalgebra::na` alone, and get anything you want using the prefix +`na`. ## Features **nalgebra** is meant to be a general-purpose linear algebra library (but is very far from that…), and keeps an optimized set of tools for computational graphics and physics. Those features include: -* Vectors with static sizes: `Vec0`, `Vec1`, `Vec2`, ..., `Vec6`. -* Square matrices with static sizes: `Mat1`, `Mat2`, ..., `Mat6 `. +* Vectors with static sizes: `Vec0`, `Vec1`, `Vec2`, `Vec3`, `Vec4`, `Vec5`, `Vec6`. +* Square matrices with static sizes: `Mat1`, `Mat2`, `Mat3`, `Mat4`, `Mat5`, `Mat6 `. * Rotation matrices: `Rot2`, `Rot3`, `Rot4`. * Isometries: `Iso2`, `Iso3`, `Iso4`. * Dynamically sized vector: `DVec`. @@ -46,7 +46,7 @@ and keeps an optimized set of tools for computational graphics and physics. Thos * Almost one trait per functionality: useful for generic programming. * Operator overloading using the double trait dispatch [trick](http://smallcultfollowing.com/babysteps/blog/2012/10/04/refining-traits-slash-impls/). - For example, the following work: + For example, the following works: ```rust extern mod nalgebra; diff --git a/src/bench/mat.rs b/src/bench/mat.rs index 46ba61f7..3b14cde7 100644 --- a/src/bench/mat.rs +++ b/src/bench/mat.rs @@ -1,6 +1,6 @@ use std::rand::random; use extra::test::BenchHarness; -use na::*; +use na::{Vec2, Vec3, Vec4, Vec5, Vec6, DVec, Mat2, Mat3, Mat4, Mat5, Mat6, DMat}; macro_rules! bench_mul_mat( ($bh: expr, $t: ty) => { diff --git a/src/bench/vec.rs b/src/bench/vec.rs index 5692d440..4948afd5 100644 --- a/src/bench/vec.rs +++ b/src/bench/vec.rs @@ -1,6 +1,7 @@ use std::rand::random; use extra::test::BenchHarness; -use na::*; +use na::{Vec2, Vec3, Vec4, Vec5, Vec6}; +use na; macro_rules! bench_dot_vec( ($bh: expr, $t: ty) => { @@ -11,7 +12,7 @@ macro_rules! bench_dot_vec( do $bh.iter { do 1000.times { - d = d + a.dot(&b); + d = d + na::dot(&a, &b); } } } diff --git a/src/lib.rs b/src/lib.rs index 88c20d1f..d1c301b0 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -30,15 +30,15 @@ use nalgebra::traits::*; ```.rust use nalgebra::structs::*; ``` -Of course, you can still import `nalgebra::na` alone, and get anything you want using the `na` -prefix. +Of course, you can still import `nalgebra::na` alone, and get anything you want using the prefix +`na`. ## Features **nalgebra** is meant to be a general-purpose linear algebra library (but is very far from that…), and keeps an optimized set of tools for computational graphics and physics. Those features include: -* Vectors with static sizes: `Vec0`, `Vec1`, `Vec2`, ..., `Vec6`. -* Square matrices with static sizes: `Mat1`, `Mat2`, ..., `Mat6 `. +* Vectors with static sizes: `Vec0`, `Vec1`, `Vec2`, `Vec3`, `Vec4`, `Vec5`, `Vec6`. +* Square matrices with static sizes: `Mat1`, `Mat2`, `Mat3`, `Mat4`, `Mat5`, `Mat6 `. * Rotation matrices: `Rot2`, `Rot3`, `Rot4`. * Isometries: `Iso2`, `Iso3`, `Iso4`. * Dynamically sized vector: `DVec`. @@ -47,7 +47,7 @@ and keeps an optimized set of tools for computational graphics and physics. Thos * Almost one trait per functionality: useful for generic programming. * Operator overloading using the double trait dispatch [trick](http://smallcultfollowing.com/babysteps/blog/2012/10/04/refining-traits-slash-impls/). - For example, the following work: + For example, the following works: ```rust extern mod nalgebra; @@ -98,6 +98,7 @@ Feel free to add your project to this list if you happen to use **nalgebra**! #[deny(non_uppercase_statics)]; #[deny(unnecessary_qualification)]; #[deny(missing_doc)]; +#[feature(macro_rules)]; extern mod std; extern mod extra; diff --git a/src/na.rs b/src/na.rs index 8d471f98..d4c2604b 100644 --- a/src/na.rs +++ b/src/na.rs @@ -1,5 +1,6 @@ //! **nalgebra** prelude. +pub use std::num::{Zero, One}; pub use traits::{ Absolute, AbsoluteRotate, @@ -46,6 +47,106 @@ pub use structs::{ Vec0, Vec1, Vec2, Vec3, Vec4, Vec5, Vec6 }; +// +// +// Constructors +// +// +/// Create a zero-valued value. +/// +/// This is the same as `std::num::Zero::zero()`. +#[inline(always)] +pub fn zero() -> T { + Zero::zero() +} + +/// Create a one-valued value. +/// +/// This is the same as `std::num::One::one()`. +#[inline(always)] +pub fn one() -> T { + One::one() +} + +/// Creates a new 1d vector. +/// +/// This is the same as `Vec1::new(x)`. +#[inline(always)] +pub fn vec1(x: N) -> Vec1 { + Vec1::new(x) +} + +/// Creates a new 2d vector. +/// +/// This is the same as `Vec2::new(x, y)`. +#[inline(always)] +pub fn vec2(x: N, y: N) -> Vec2 { + Vec2::new(x, y) +} + +/// Creates a new 3d vector. +/// +/// This is the same as `Vec3::new(x, y, z)`. +#[inline(always)] +pub fn vec3(x: N, y: N, z: N) -> Vec3 { + Vec3::new(x, y, z) +} + +/// Creates a new 4d vector. +/// +/// This is the same as `Vec4::new(x, y, z, w)`. +#[inline(always)] +pub fn vec4(x: N, y: N, z: N, w: N) -> Vec4 { + Vec4::new(x, y, z, w) +} + +/// Creates a new 1d matrix. +/// +/// This is the same as `Mat1::new(...)`. +#[inline(always)] +pub fn mat1(m11: N) -> Mat1 { + Mat1::new(m11) +} + +/// Creates a new 2d matrix. +/// +/// This is the same as `Mat2::new(...)`. +#[inline(always)] +pub fn mat2(m11: N, m12: N, + m21: N, m22: N) -> Mat2 { + Mat2::new( + m11, m12, + m21, m22) +} + +/// Creates a new 3d matrix. +/// +/// This is the same as `Mat3::new(...)`. +#[inline(always)] +pub fn mat3(m11: N, m12: N, m13: N, + m21: N, m22: N, m23: N, + m31: N, m32: N, m33: N) -> Mat3 { + Mat3::new( + m11, m12, m13, + m21, m22, m23, + m31, m32, m33) +} + +/// Creates a new 4d matrix. +/// +/// This is the same as `Mat4::new(...)`. +#[inline(always)] +pub fn mat4(m11: N, m12: N, m13: N, m14: N, + m21: N, m22: N, m23: N, m24: N, + m31: N, m32: N, m33: N, m34: N, + m41: N, m42: N, m43: N, m44: N) -> Mat4 { + Mat4::new( + m11, m12, m13, m14, + m21, m22, m23, m24, + m31, m32, m33, m34, + m41, m42, m43, m44) +} + // // // Geometry diff --git a/src/structs/dmat.rs b/src/structs/dmat.rs index 0346b5cf..33d66141 100644 --- a/src/structs/dmat.rs +++ b/src/structs/dmat.rs @@ -4,7 +4,7 @@ use std::rand::Rand; use std::rand; -use std::num::{One, Zero}; +use std::num::{One, Zero, from_f32, from_uint}; use std::vec; use std::cmp::ApproxEq; use std::util; @@ -409,10 +409,10 @@ impl Transpose for DMat { } } -impl Mean> for DMat { +impl Mean> for DMat { fn mean(&self) -> DVec { let mut res: DVec = DVec::new_zeros(self.ncols); - let normalizer: N = NumCast::from(1.0f64 / NumCast::from(self.nrows)); + let normalizer: N = from_f32(1.0f32 / from_uint(self.nrows).unwrap()).unwrap(); for i in range(0u, self.nrows) { for j in range(0u, self.ncols) { @@ -427,7 +427,7 @@ impl Mean> for DMat { } } -impl> + ToStr > Cov> for DMat { +impl> + ToStr > Cov> for DMat { // FIXME: this could be heavily optimized, removing all temporaries by merging loops. fn cov(&self) -> DMat { assert!(self.nrows > 1); @@ -445,7 +445,7 @@ impl> + ToStr > Cov> fo } // FIXME: return a triangular matrix? - let normalizer: N = NumCast::from(self.nrows() - 1); + let normalizer: N = from_uint(self.nrows() - 1).unwrap(); // FIXME: this will do 2 allocations for temporaries! (centered.transposed() * centered) / normalizer } diff --git a/src/structs/iso_macros.rs b/src/structs/iso_macros.rs index b8bf31cf..4f26e158 100644 --- a/src/structs/iso_macros.rs +++ b/src/structs/iso_macros.rs @@ -17,7 +17,7 @@ macro_rules! iso_impl( macro_rules! rotation_matrix_impl( ($t: ident, $trot: ident, $tlv: ident, $tav: ident) => ( - impl + impl RotationMatrix<$tlv, $tav, $trot> for $t { #[inline] fn to_rot_mat(&self) -> $trot { @@ -132,7 +132,7 @@ macro_rules! translate_impl( macro_rules! rotation_impl( ($t: ident, $trot: ident, $tav: ident) => ( - impl Rotation<$tav> for $t { + impl Rotation<$tav> for $t { #[inline] fn rotation(&self) -> $tav { self.rotation.rotation() diff --git a/src/structs/mat_macros.rs b/src/structs/mat_macros.rs index 28700a18..439b142e 100644 --- a/src/structs/mat_macros.rs +++ b/src/structs/mat_macros.rs @@ -37,7 +37,7 @@ macro_rules! mat_cast_impl( impl MatCast<$t> for $t { #[inline] fn from(m: $t) -> $t { - $t::new(NumCast::from(m.$comp0.clone()) $(, NumCast::from(m.$compN.clone()) )*) + $t::new(NumCast::from(m.$comp0.clone()).unwrap() $(, NumCast::from(m.$compN.clone()).unwrap() )*) } } ) diff --git a/src/structs/rot.rs b/src/structs/rot.rs index 43244323..cb3d0bc5 100644 --- a/src/structs/rot.rs +++ b/src/structs/rot.rs @@ -2,7 +2,7 @@ #[allow(missing_doc)]; -use std::num::{Zero, One}; +use std::num::{Zero, One, from_f32}; use std::rand::{Rand, Rng}; use traits::geometry::{Rotate, Rotation, AbsoluteRotate, RotationMatrix, Transform, ToHomogeneous, Norm, Cross}; @@ -168,11 +168,11 @@ impl Rot3 { } } -impl +impl Rotation> for Rot3 { #[inline] fn rotation(&self) -> Vec3 { - let angle = ((self.submat.m11 + self.submat.m22 + self.submat.m33 - One::one()) / NumCast::from(2.0)).acos(); + let angle = ((self.submat.m11 + self.submat.m22 + self.submat.m33 - One::one()) / from_f32(2.0).unwrap()).acos(); if angle != angle { // FIXME: handle that correctly diff --git a/src/structs/rot_macros.rs b/src/structs/rot_macros.rs index 23326c52..348a9afa 100644 --- a/src/structs/rot_macros.rs +++ b/src/structs/rot_macros.rs @@ -56,7 +56,7 @@ macro_rules! dim_impl( macro_rules! rotation_matrix_impl( ($t: ident, $tlv: ident, $tav: ident) => ( - impl + impl RotationMatrix<$tlv, $tav, $t> for $t { #[inline] fn to_rot_mat(&self) -> $t { diff --git a/src/structs/spec/mat.rs b/src/structs/spec/mat.rs index 4174791b..cf00845e 100644 --- a/src/structs/spec/mat.rs +++ b/src/structs/spec/mat.rs @@ -1,4 +1,4 @@ -use std::num::{Zero, One}; +use std::num::{Zero, One, from_f32}; use structs::vec::{Vec2, Vec3, Vec2MulRhs, Vec3MulRhs}; use structs::mat::{Mat1, Mat2, Mat3, Mat3MulRhs, Mat2MulRhs}; use structs::mat; @@ -266,17 +266,17 @@ impl + Add> Mat2MulRhs> for Vec2 { } // FIXME: move this to another file? -impl mat::Mat4 { +impl mat::Mat4 { /// Computes a projection matrix given the frustrum near plane width, height, the field of /// view, and the distance to the clipping planes (`znear` and `zfar`). pub fn new_perspective(width: N, height: N, fov: N, znear: N, zfar: N) -> mat::Mat4 { let aspect = width / height; let _1: N = One::one(); - let sy = _1 / (fov * NumCast::from(0.5)).tan(); + let sy = _1 / (fov * from_f32(0.5).unwrap()).tan(); let sx = -sy / aspect; let sz = -(zfar + znear) / (znear - zfar); - let tz = zfar * znear * NumCast::from(2.0) / (znear - zfar); + let tz = zfar * znear * from_f32(2.0).unwrap() / (znear - zfar); mat::Mat4::new( sx, Zero::zero(), Zero::zero(), Zero::zero(), diff --git a/src/structs/vec_macros.rs b/src/structs/vec_macros.rs index 5e3ad163..357e48c0 100644 --- a/src/structs/vec_macros.rs +++ b/src/structs/vec_macros.rs @@ -115,7 +115,7 @@ macro_rules! vec_cast_impl( impl VecCast<$t> for $t { #[inline] fn from(v: $t) -> $t { - $t::new(NumCast::from(v.$comp0.clone()) $(, NumCast::from(v.$compN.clone()))*) + $t::new(NumCast::from(v.$comp0.clone()).unwrap() $(, NumCast::from(v.$compN.clone()).unwrap())*) } } ) diff --git a/src/tests/mat.rs b/src/tests/mat.rs index ad1b73f5..4d13d628 100644 --- a/src/tests/mat.rs +++ b/src/tests/mat.rs @@ -1,14 +1,16 @@ -use std::num::{Real, One, abs}; +use std::num::{Real, abs}; use std::rand::random; use std::cmp::ApproxEq; -use na::*; +use na::{DMat, DVec}; +use na::Indexable; // FIXME: get rid of that +use na; macro_rules! test_inv_mat_impl( ($t: ty) => ( do 10000.times { let randmat : $t = random(); - assert!((randmat.inverted().unwrap() * randmat).approx_eq(&One::one())); + assert!((na::inverted(&randmat).unwrap() * randmat).approx_eq(&na::one())); } ); ) @@ -18,97 +20,97 @@ macro_rules! test_transpose_mat_impl( do 10000.times { let randmat : $t = random(); - assert!(randmat.transposed().transposed().eq(&randmat)); + assert!(na::transposed(&na::transposed(&randmat)) == randmat); } ); ) #[test] fn test_transpose_mat1() { - test_transpose_mat_impl!(Mat1); + test_transpose_mat_impl!(na::Mat1); } #[test] fn test_transpose_mat2() { - test_transpose_mat_impl!(Mat2); + test_transpose_mat_impl!(na::Mat2); } #[test] fn test_transpose_mat3() { - test_transpose_mat_impl!(Mat3); + test_transpose_mat_impl!(na::Mat3); } #[test] fn test_transpose_mat4() { - test_transpose_mat_impl!(Mat4); + test_transpose_mat_impl!(na::Mat4); } #[test] fn test_transpose_mat5() { - test_transpose_mat_impl!(Mat5); + test_transpose_mat_impl!(na::Mat5); } #[test] fn test_transpose_mat6() { - test_transpose_mat_impl!(Mat6); + test_transpose_mat_impl!(na::Mat6); } #[test] fn test_inv_mat1() { - test_inv_mat_impl!(Mat1); + test_inv_mat_impl!(na::Mat1); } #[test] fn test_inv_mat2() { - test_inv_mat_impl!(Mat2); + test_inv_mat_impl!(na::Mat2); } #[test] fn test_inv_mat3() { - test_inv_mat_impl!(Mat3); + test_inv_mat_impl!(na::Mat3); } #[test] fn test_inv_mat4() { - test_inv_mat_impl!(Mat4); + test_inv_mat_impl!(na::Mat4); } #[test] fn test_inv_mat5() { - test_inv_mat_impl!(Mat5); + test_inv_mat_impl!(na::Mat5); } #[test] fn test_inv_mat6() { - test_inv_mat_impl!(Mat6); + test_inv_mat_impl!(na::Mat6); } #[test] fn test_rotation2() { do 10000.times { - let randmat: Rot2 = One::one(); - let ang = &Vec1::new(abs::(random()) % Real::pi()); + let randmat: na::Rot2 = na::one(); + let ang = na::vec1(abs::(random()) % Real::pi()); - assert!(randmat.rotated(ang).rotation().approx_eq(ang)); + assert!(na::rotation(&na::rotated(&randmat, &ang)).approx_eq(&ang)); } } #[test] fn test_index_mat2() { - let mat: Mat2 = random(); + let mat: na::Mat2 = random(); - assert!(mat.at((0, 1)) == mat.transposed().at((1, 0))); + assert!(mat.at((0, 1)) == na::transposed(&mat).at((1, 0))); } #[test] fn test_inv_rotation3() { do 10000.times { - let randmat: Rot3 = One::one(); - let dir: Vec3 = random(); - let ang = &(dir.normalized() * (abs::(random()) % Real::pi())); - let rot = randmat.rotated(ang); + let randmat: na::Rot3 = na::one(); + let dir: na::Vec3 = random(); + let ang = na::normalized(&dir) * (abs::(random()) % Real::pi()); + let rot = na::rotated(&randmat, &ang); - assert!((rot.transposed() * rot).approx_eq(&One::one())); + assert!((na::transposed(&rot) * rot).approx_eq(&na::one())); } } @@ -124,7 +126,7 @@ fn test_mean_dmat() { ] ); - assert!(mat.mean().approx_eq(&DVec::from_vec(3, [4.0f64, 5.0, 6.0]))); + assert!(na::mean(&mat).approx_eq(&DVec::from_vec(3, [4.0f64, 5.0, 6.0]))); } #[test] @@ -151,5 +153,5 @@ fn test_cov_dmat() { ] ); - assert!(mat.cov().approx_eq(&expected)); + assert!(na::cov(&mat).approx_eq(&expected)); } diff --git a/src/tests/vec.rs b/src/tests/vec.rs index aa25841e..e2bffd8e 100644 --- a/src/tests/vec.rs +++ b/src/tests/vec.rs @@ -1,7 +1,8 @@ -use std::num::{Zero, One}; use std::rand::{random}; use std::cmp::ApproxEq; -use na::*; +use na::{Vec0, Vec1, Vec2, Vec3, Vec4, Vec5, Vec6}; +use na::{Iterable, IterableMut}; // FIXME: get rid of that +use na; macro_rules! test_iterator_impl( ($t: ty, $n: ty) => ( @@ -27,7 +28,7 @@ macro_rules! test_commut_dot_impl( let v1 : $t = random(); let v2 : $t = random(); - assert!(v1.dot(&v2).approx_eq(&v2.dot(&v1))); + assert!(na::dot(&v1, &v2).approx_eq(&na::dot(&v2, &v1))); } ); ) @@ -58,14 +59,14 @@ macro_rules! test_scalar_op_impl( macro_rules! test_basis_impl( ($t: ty) => ( do 10000.times { - do Basis::canonical_basis |e1: $t| { - do Basis::canonical_basis |e2: $t| { - assert!(e1 == e2 || e1.dot(&e2).approx_eq(&Zero::zero())); + do na::canonical_basis |e1: $t| { + do na::canonical_basis |e2: $t| { + assert!(e1 == e2 || na::dot(&e1, &e2).approx_eq(&na::zero())); true } - assert!(e1.norm().approx_eq(&One::one())); + assert!(na::norm(&e1).approx_eq(&na::one())); true } @@ -77,16 +78,16 @@ macro_rules! test_subspace_basis_impl( ($t: ty) => ( do 10000.times { let v : $t = random(); - let v1 = v.normalized(); + let v1 = na::normalized(&v); - do v1.orthonormal_subspace_basis() |e1| { + do na::orthonormal_subspace_basis(&v1) |e1| { // check vectors are orthogonal to v1 - assert!(v1.dot(&e1).approx_eq(&Zero::zero())); + assert!(na::dot(&v1, &e1).approx_eq(&na::zero())); // check vectors form an orthonormal basis - assert!(e1.norm().approx_eq(&One::one())); + assert!(na::norm(&e1).approx_eq(&na::one())); // check vectors form an ortogonal basis - do v1.orthonormal_subspace_basis() |e2| { - assert!(e1 == e2 || e1.dot(&e2).approx_eq(&Zero::zero())); + do na::orthonormal_subspace_basis(&v1) |e2| { + assert!(e1 == e2 || na::dot(&e1, &e2).approx_eq(&na::zero())); true } @@ -102,10 +103,10 @@ fn test_cross_vec3() { do 10000.times { let v1 : Vec3 = random(); let v2 : Vec3 = random(); - let v3 : Vec3 = v1.cross(&v2); + let v3 : Vec3 = na::cross(&v1, &v2); - assert!(v3.dot(&v2).approx_eq(&Zero::zero())); - assert!(v3.dot(&v1).approx_eq(&Zero::zero())); + assert!(na::dot(&v3, &v2).approx_eq(&na::zero())); + assert!(na::dot(&v3, &v1).approx_eq(&na::zero())); } } @@ -287,39 +288,35 @@ fn test_iterator_vec6() { #[test] fn test_ord_vec3() { // equality - assert!(Vec3::new(0.5, 0.5, 0.5) == Vec3::new(0.5, 0.5, 0.5)); - assert!(!(Vec3::new(1.5, 0.5, 0.5) == Vec3::new(0.5, 0.5, 0.5))); - assert!(Vec3::new(1.5, 0.5, 0.5) != Vec3::new(0.5, 0.5, 0.5)); + assert!(na::vec3(0.5, 0.5, 0.5) == na::vec3(0.5, 0.5, 0.5)); + assert!(!(na::vec3(1.5, 0.5, 0.5) == na::vec3(0.5, 0.5, 0.5))); + assert!(na::vec3(1.5, 0.5, 0.5) != na::vec3(0.5, 0.5, 0.5)); // comparable - assert!(Vec3::new(0.5, 0.3, 0.3) < Vec3::new(1.0, 2.0, 1.0)); - assert!(Vec3::new(0.5, 0.3, 0.3) <= Vec3::new(1.0, 2.0, 1.0)); - assert!(Vec3::new(2.0, 4.0, 2.0) > Vec3::new(1.0, 2.0, 1.0)); - assert!(Vec3::new(2.0, 4.0, 2.0) >= Vec3::new(1.0, 2.0, 1.0)); + assert!(na::vec3(0.5, 0.3, 0.3) < na::vec3(1.0, 2.0, 1.0)); + assert!(na::vec3(0.5, 0.3, 0.3) <= na::vec3(1.0, 2.0, 1.0)); + assert!(na::vec3(2.0, 4.0, 2.0) > na::vec3(1.0, 2.0, 1.0)); + assert!(na::vec3(2.0, 4.0, 2.0) >= na::vec3(1.0, 2.0, 1.0)); // not comparable - assert!(!(Vec3::new(0.0, 3.0, 0.0) < Vec3::new(1.0, 2.0, 1.0))); - assert!(!(Vec3::new(0.0, 3.0, 0.0) > Vec3::new(1.0, 2.0, 1.0))); - assert!(!(Vec3::new(0.0, 3.0, 0.0) <= Vec3::new(1.0, 2.0, 1.0))); - assert!(!(Vec3::new(0.0, 3.0, 0.0) >= Vec3::new(1.0, 2.0, 1.0))); + assert!(!(na::vec3(0.0, 3.0, 0.0) < na::vec3(1.0, 2.0, 1.0))); + assert!(!(na::vec3(0.0, 3.0, 0.0) > na::vec3(1.0, 2.0, 1.0))); + assert!(!(na::vec3(0.0, 3.0, 0.0) <= na::vec3(1.0, 2.0, 1.0))); + assert!(!(na::vec3(0.0, 3.0, 0.0) >= na::vec3(1.0, 2.0, 1.0))); } #[test] fn test_min_max_vec3() { - assert_eq!(Vec3::new(1, 2, 3).max(&Vec3::new(3, 2, 1)), Vec3::new(3, 2, 3)); - assert_eq!(Vec3::new(1, 2, 3).min(&Vec3::new(3, 2, 1)), Vec3::new(1, 2, 1)); - assert_eq!( - Vec3::new(0, 2, 4).clamp( - &Vec3::new(1, 1, 1), &Vec3::new(3, 3, 3) - ), Vec3::new(1, 2, 3) - ); + assert_eq!(na::vec3(1, 2, 3).max(&na::vec3(3, 2, 1)), na::vec3(3, 2, 3)); + assert_eq!(na::vec3(1, 2, 3).min(&na::vec3(3, 2, 1)), na::vec3(1, 2, 1)); + assert_eq!(na::vec3(0, 2, 4).clamp(&na::vec3(1, 1, 1), &na::vec3(3, 3, 3)), na::vec3(1, 2, 3)); } #[test] fn test_outer_vec3() { assert_eq!( - Vec3::new(1, 2, 3).outer(&Vec3::new(4, 5, 6)), - Mat3::new( + na::outer(&na::vec3(1, 2, 3), &na::vec3(4, 5, 6)), + na::mat3( 4, 5, 6, 8, 10, 12, 12, 15, 18));