forked from M-Labs/nalgebra
commit
fa9dfaf2d5
@ -618,13 +618,13 @@ impl<N: ApproxEq<N>> ApproxEq<N> for DMat<N> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_eq_eps(&self, other: &DMat<N>, epsilon: &N) -> bool {
|
fn approx_eq_eps(&self, other: &DMat<N>, epsilon: &N) -> bool {
|
||||||
let zip = self.mij.iter().zip(other.mij.iter());
|
let mut zip = self.mij.iter().zip(other.mij.iter());
|
||||||
zip.all(|(a, b)| ApproxEq::approx_eq_eps(a, b, epsilon))
|
zip.all(|(a, b)| ApproxEq::approx_eq_eps(a, b, epsilon))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_eq_ulps(&self, other: &DMat<N>, ulps: u32) -> bool {
|
fn approx_eq_ulps(&self, other: &DMat<N>, ulps: u32) -> bool {
|
||||||
let zip = self.mij.iter().zip(other.mij.iter());
|
let mut zip = self.mij.iter().zip(other.mij.iter());
|
||||||
zip.all(|(a, b)| ApproxEq::approx_eq_ulps(a, b, ulps))
|
zip.all(|(a, b)| ApproxEq::approx_eq_ulps(a, b, ulps))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -106,7 +106,7 @@ macro_rules! dvec_impl(
|
|||||||
/// Builds a vector filled with random values.
|
/// Builds a vector filled with random values.
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_random(dim: usize) -> $dvec<N> {
|
pub fn new_random(dim: usize) -> $dvec<N> {
|
||||||
$dvec::from_fn(dim, |&: _| rand::random())
|
$dvec::from_fn(dim, |_| rand::random())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -319,13 +319,13 @@ macro_rules! dvec_impl(
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_eq_eps(&self, other: &$dvec<N>, epsilon: &N) -> bool {
|
fn approx_eq_eps(&self, other: &$dvec<N>, epsilon: &N) -> bool {
|
||||||
let zip = self.as_slice().iter().zip(other.as_slice().iter());
|
let mut zip = self.as_slice().iter().zip(other.as_slice().iter());
|
||||||
zip.all(|(a, b)| ApproxEq::approx_eq_eps(a, b, epsilon))
|
zip.all(|(a, b)| ApproxEq::approx_eq_eps(a, b, epsilon))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_eq_ulps(&self, other: &$dvec<N>, ulps: u32) -> bool {
|
fn approx_eq_ulps(&self, other: &$dvec<N>, ulps: u32) -> bool {
|
||||||
let zip = self.as_slice().iter().zip(other.as_slice().iter());
|
let mut zip = self.as_slice().iter().zip(other.as_slice().iter());
|
||||||
zip.all(|(a, b)| ApproxEq::approx_eq_ulps(a, b, ulps))
|
zip.all(|(a, b)| ApproxEq::approx_eq_ulps(a, b, ulps))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -646,13 +646,13 @@ macro_rules! approx_eq_impl(
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_eq_eps(&self, other: &$t<N>, epsilon: &N) -> bool {
|
fn approx_eq_eps(&self, other: &$t<N>, epsilon: &N) -> bool {
|
||||||
let zip = self.iter().zip(other.iter());
|
let mut zip = self.iter().zip(other.iter());
|
||||||
zip.all(|(a, b)| ApproxEq::approx_eq_eps(a, b, epsilon))
|
zip.all(|(a, b)| ApproxEq::approx_eq_eps(a, b, epsilon))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn approx_eq_ulps(&self, other: &$t<N>, ulps: u32) -> bool {
|
fn approx_eq_ulps(&self, other: &$t<N>, ulps: u32) -> bool {
|
||||||
let zip = self.iter().zip(other.iter());
|
let mut zip = self.iter().zip(other.iter());
|
||||||
zip.all(|(a, b)| ApproxEq::approx_eq_ulps(a, b, ulps))
|
zip.all(|(a, b)| ApproxEq::approx_eq_ulps(a, b, ulps))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
14
tests/mat.rs
14
tests/mat.rs
@ -7,7 +7,7 @@ use na::{Vec1, Vec3, Mat1, Mat2, Mat3, Mat4, Mat5, Mat6, Rot3, Persp3, PerspMat3
|
|||||||
|
|
||||||
macro_rules! test_inv_mat_impl(
|
macro_rules! test_inv_mat_impl(
|
||||||
($t: ty) => (
|
($t: ty) => (
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let randmat : $t = random();
|
let randmat : $t = random();
|
||||||
|
|
||||||
match na::inv(&randmat) {
|
match na::inv(&randmat) {
|
||||||
@ -20,7 +20,7 @@ macro_rules! test_inv_mat_impl(
|
|||||||
|
|
||||||
macro_rules! test_transpose_mat_impl(
|
macro_rules! test_transpose_mat_impl(
|
||||||
($t: ty) => (
|
($t: ty) => (
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let randmat : $t = random();
|
let randmat : $t = random();
|
||||||
|
|
||||||
assert!(na::transpose(&na::transpose(&randmat)) == randmat);
|
assert!(na::transpose(&na::transpose(&randmat)) == randmat);
|
||||||
@ -30,7 +30,7 @@ macro_rules! test_transpose_mat_impl(
|
|||||||
|
|
||||||
macro_rules! test_qr_impl(
|
macro_rules! test_qr_impl(
|
||||||
($t: ty) => (
|
($t: ty) => (
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let randmat : $t = random();
|
let randmat : $t = random();
|
||||||
|
|
||||||
let (q, r) = na::qr(&randmat);
|
let (q, r) = na::qr(&randmat);
|
||||||
@ -44,7 +44,7 @@ macro_rules! test_qr_impl(
|
|||||||
// NOTE: deactivated untile we get a better convergence rate.
|
// NOTE: deactivated untile we get a better convergence rate.
|
||||||
// macro_rules! test_eigen_qr_impl(
|
// macro_rules! test_eigen_qr_impl(
|
||||||
// ($t: ty) => {
|
// ($t: ty) => {
|
||||||
// for _ in (0us .. 10000) {
|
// for _ in (0usize .. 10000) {
|
||||||
// let randmat : $t = random();
|
// let randmat : $t = random();
|
||||||
// // Make it symetric so that we can recompose the matrix to test at the end.
|
// // Make it symetric so that we can recompose the matrix to test at the end.
|
||||||
// let randmat = na::transpose(&randmat) * randmat;
|
// let randmat = na::transpose(&randmat) * randmat;
|
||||||
@ -126,7 +126,7 @@ fn test_inv_mat6() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_rotation2() {
|
fn test_rotation2() {
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let randmat: na::Rot2<f64> = na::one();
|
let randmat: na::Rot2<f64> = na::one();
|
||||||
let ang = Vec1::new(na::abs(&random::<f64>()) % <f64 as BaseFloat>::pi());
|
let ang = Vec1::new(na::abs(&random::<f64>()) % <f64 as BaseFloat>::pi());
|
||||||
|
|
||||||
@ -143,7 +143,7 @@ fn test_index_mat2() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_inv_rotation3() {
|
fn test_inv_rotation3() {
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let randmat: Rot3<f64> = na::one();
|
let randmat: Rot3<f64> = na::one();
|
||||||
let dir: Vec3<f64> = random();
|
let dir: Vec3<f64> = random();
|
||||||
let ang = na::normalize(&dir) * (na::abs(&random::<f64>()) % <f64 as BaseFloat>::pi());
|
let ang = na::normalize(&dir) * (na::abs(&random::<f64>()) % <f64 as BaseFloat>::pi());
|
||||||
@ -251,7 +251,7 @@ fn test_dmat_from_vec() {
|
|||||||
/* FIXME: review qr decomposition to make it work with DMat.
|
/* FIXME: review qr decomposition to make it work with DMat.
|
||||||
#[test]
|
#[test]
|
||||||
fn test_qr() {
|
fn test_qr() {
|
||||||
for _ in (0us .. 10) {
|
for _ in (0usize .. 10) {
|
||||||
let dim1: usize = random();
|
let dim1: usize = random();
|
||||||
let dim2: usize = random();
|
let dim2: usize = random();
|
||||||
let rows = min(40, max(dim1, dim2));
|
let rows = min(40, max(dim1, dim2));
|
||||||
|
@ -6,7 +6,7 @@ use rand::random;
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quat_as_mat() {
|
fn test_quat_as_mat() {
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let axis_angle: Vec3<f64> = random();
|
let axis_angle: Vec3<f64> = random();
|
||||||
|
|
||||||
assert!(na::approx_eq(&UnitQuat::new(axis_angle).to_rot(), &Rot3::new(axis_angle)))
|
assert!(na::approx_eq(&UnitQuat::new(axis_angle).to_rot(), &Rot3::new(axis_angle)))
|
||||||
@ -15,7 +15,7 @@ fn test_quat_as_mat() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quat_mul_vec_or_pnt_as_mat() {
|
fn test_quat_mul_vec_or_pnt_as_mat() {
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let axis_angle: Vec3<f64> = random();
|
let axis_angle: Vec3<f64> = random();
|
||||||
let vec: Vec3<f64> = random();
|
let vec: Vec3<f64> = random();
|
||||||
let pnt: Pnt3<f64> = random();
|
let pnt: Pnt3<f64> = random();
|
||||||
@ -32,7 +32,7 @@ fn test_quat_mul_vec_or_pnt_as_mat() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quat_div_quat() {
|
fn test_quat_div_quat() {
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let axis_angle1: Vec3<f64> = random();
|
let axis_angle1: Vec3<f64> = random();
|
||||||
let axis_angle2: Vec3<f64> = random();
|
let axis_angle2: Vec3<f64> = random();
|
||||||
|
|
||||||
@ -48,7 +48,7 @@ fn test_quat_div_quat() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quat_to_axis_angle() {
|
fn test_quat_to_axis_angle() {
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let axis_angle: Vec3<f64> = random();
|
let axis_angle: Vec3<f64> = random();
|
||||||
|
|
||||||
let q = UnitQuat::new(axis_angle);
|
let q = UnitQuat::new(axis_angle);
|
||||||
@ -60,7 +60,7 @@ fn test_quat_to_axis_angle() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_quat_euler_angles() {
|
fn test_quat_euler_angles() {
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let angles: Vec3<f64> = random();
|
let angles: Vec3<f64> = random();
|
||||||
|
|
||||||
let q = UnitQuat::new_with_euler_angles(angles.x, angles.y, angles.z);
|
let q = UnitQuat::new_with_euler_angles(angles.x, angles.y, angles.z);
|
||||||
|
12
tests/vec.rs
12
tests/vec.rs
@ -6,7 +6,7 @@ use na::{Vec0, Vec1, Vec2, Vec3, Vec4, Vec5, Vec6, Mat3, Iterable, IterableMut};
|
|||||||
|
|
||||||
macro_rules! test_iterator_impl(
|
macro_rules! test_iterator_impl(
|
||||||
($t: ty, $n: ty) => (
|
($t: ty, $n: ty) => (
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let v: $t = random();
|
let v: $t = random();
|
||||||
let mut mv: $t = v.clone();
|
let mut mv: $t = v.clone();
|
||||||
let n: $n = random();
|
let n: $n = random();
|
||||||
@ -24,7 +24,7 @@ macro_rules! test_iterator_impl(
|
|||||||
|
|
||||||
macro_rules! test_commut_dot_impl(
|
macro_rules! test_commut_dot_impl(
|
||||||
($t: ty) => (
|
($t: ty) => (
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let v1 : $t = random();
|
let v1 : $t = random();
|
||||||
let v2 : $t = random();
|
let v2 : $t = random();
|
||||||
|
|
||||||
@ -35,7 +35,7 @@ macro_rules! test_commut_dot_impl(
|
|||||||
|
|
||||||
macro_rules! test_scalar_op_impl(
|
macro_rules! test_scalar_op_impl(
|
||||||
($t: ty, $n: ty) => (
|
($t: ty, $n: ty) => (
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let v1 : $t = random();
|
let v1 : $t = random();
|
||||||
let n : $n = random();
|
let n : $n = random();
|
||||||
|
|
||||||
@ -58,7 +58,7 @@ macro_rules! test_scalar_op_impl(
|
|||||||
|
|
||||||
macro_rules! test_basis_impl(
|
macro_rules! test_basis_impl(
|
||||||
($t: ty) => (
|
($t: ty) => (
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
na::canonical_basis(|e1: $t| {
|
na::canonical_basis(|e1: $t| {
|
||||||
na::canonical_basis(|e2: $t| {
|
na::canonical_basis(|e2: $t| {
|
||||||
assert!(e1 == e2 || na::approx_eq(&na::dot(&e1, &e2), &na::zero()));
|
assert!(e1 == e2 || na::approx_eq(&na::dot(&e1, &e2), &na::zero()));
|
||||||
@ -76,7 +76,7 @@ macro_rules! test_basis_impl(
|
|||||||
|
|
||||||
macro_rules! test_subspace_basis_impl(
|
macro_rules! test_subspace_basis_impl(
|
||||||
($t: ty) => (
|
($t: ty) => (
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let v : $t = random();
|
let v : $t = random();
|
||||||
let v1 = na::normalize(&v);
|
let v1 = na::normalize(&v);
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ macro_rules! test_subspace_basis_impl(
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_cross_vec3() {
|
fn test_cross_vec3() {
|
||||||
for _ in (0us .. 10000) {
|
for _ in (0usize .. 10000) {
|
||||||
let v1 : Vec3<f64> = random();
|
let v1 : Vec3<f64> = random();
|
||||||
let v2 : Vec3<f64> = random();
|
let v2 : Vec3<f64> = random();
|
||||||
let v3 : Vec3<f64> = na::cross(&v1, &v2);
|
let v3 : Vec3<f64> = na::cross(&v1, &v2);
|
||||||
|
Loading…
Reference in New Issue
Block a user