diff --git a/benches/common/macros.rs b/benches/common/macros.rs index 55d6ba3c..758336a8 100644 --- a/benches/common/macros.rs +++ b/benches/common/macros.rs @@ -4,7 +4,8 @@ macro_rules! bench_binop( ($name: ident, $t1: ty, $t2: ty, $binop: ident) => { #[bench] fn $name(bh: &mut Bencher) { - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); let a = rng.gen::<$t1>(); let b = rng.gen::<$t2>(); @@ -19,7 +20,8 @@ macro_rules! bench_binop_ref( ($name: ident, $t1: ty, $t2: ty, $binop: ident) => { #[bench] fn $name(bh: &mut Bencher) { - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); let a = rng.gen::<$t1>(); let b = rng.gen::<$t2>(); @@ -34,7 +36,8 @@ macro_rules! bench_binop_fn( ($name: ident, $t1: ty, $t2: ty, $binop: path) => { #[bench] fn $name(bh: &mut Bencher) { - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); let a = rng.gen::<$t1>(); let b = rng.gen::<$t2>(); @@ -51,7 +54,8 @@ macro_rules! bench_unop_na( fn $name(bh: &mut Bencher) { const LEN: usize = 1 << 13; - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); let elems: Vec<$t> = (0usize .. LEN).map(|_| rng.gen::<$t>()).collect(); let mut i = 0; @@ -73,7 +77,8 @@ macro_rules! bench_unop( fn $name(bh: &mut Bencher) { const LEN: usize = 1 << 13; - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); let mut elems: Vec<$t> = (0usize .. LEN).map(|_| rng.gen::<$t>()).collect(); let mut i = 0; @@ -95,7 +100,8 @@ macro_rules! bench_construction( fn $name(bh: &mut Bencher) { const LEN: usize = 1 << 13; - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); $(let $args: Vec<$types> = (0usize .. LEN).map(|_| rng.gen::<$types>()).collect();)* let mut i = 0; diff --git a/benches/core/vector.rs b/benches/core/vector.rs index 35e25e2d..837eb7ca 100644 --- a/benches/core/vector.rs +++ b/benches/core/vector.rs @@ -50,7 +50,8 @@ bench_binop_ref!(vec10000_dot_f32, VectorN, VectorN, d #[bench] fn vec10000_axpy_f64(bh: &mut Bencher) { - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); let mut a = DVector::new_random(10000); let b = DVector::new_random(10000); let n = rng.gen::(); @@ -60,7 +61,8 @@ fn vec10000_axpy_f64(bh: &mut Bencher) { #[bench] fn vec10000_axpy_beta_f64(bh: &mut Bencher) { - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); let mut a = DVector::new_random(10000); let b = DVector::new_random(10000); let n = rng.gen::(); @@ -71,7 +73,8 @@ fn vec10000_axpy_beta_f64(bh: &mut Bencher) { #[bench] fn vec10000_axpy_f64_slice(bh: &mut Bencher) { - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); let mut a = DVector::new_random(10000); let b = DVector::new_random(10000); let n = rng.gen::(); @@ -86,7 +89,8 @@ fn vec10000_axpy_f64_slice(bh: &mut Bencher) { #[bench] fn vec10000_axpy_f64_static(bh: &mut Bencher) { - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); let mut a = VectorN::::new_random(); let b = VectorN::::new_random(); let n = rng.gen::(); @@ -97,7 +101,8 @@ fn vec10000_axpy_f64_static(bh: &mut Bencher) { #[bench] fn vec10000_axpy_f32(bh: &mut Bencher) { - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); let mut a = DVector::new_random(10000); let b = DVector::new_random(10000); let n = rng.gen::(); @@ -107,7 +112,8 @@ fn vec10000_axpy_f32(bh: &mut Bencher) { #[bench] fn vec10000_axpy_beta_f32(bh: &mut Bencher) { - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); let mut a = DVector::new_random(10000); let b = DVector::new_random(10000); let n = rng.gen::(); diff --git a/benches/lib.rs b/benches/lib.rs index 1ad3a2be..f788c998 100644 --- a/benches/lib.rs +++ b/benches/lib.rs @@ -14,6 +14,7 @@ mod geometry; mod linalg; fn reproductible_dmatrix(nrows: usize, ncols: usize) -> DMatrix { - let mut rng = IsaacRng::new_unseeded(); + use rand::SeedableRng; + let mut rng = IsaacRng::seed_from_u64(0); DMatrix::::from_fn(nrows, ncols, |_, _| rng.gen()) } diff --git a/examples/transform_matrix4.rs b/examples/transform_matrix4.rs index c877206e..a9e6cd6e 100644 --- a/examples/transform_matrix4.rs +++ b/examples/transform_matrix4.rs @@ -3,7 +3,6 @@ extern crate alga; extern crate approx; extern crate nalgebra as na; -use alga::linear::Transformation; use na::{Matrix4, Point3, Vector3}; fn main() { diff --git a/examples/transform_vector_point3.rs b/examples/transform_vector_point3.rs index cd36cad1..57a189cc 100644 --- a/examples/transform_vector_point3.rs +++ b/examples/transform_vector_point3.rs @@ -1,7 +1,6 @@ extern crate alga; extern crate nalgebra as na; -use alga::linear::Transformation; use na::{Matrix4, Point3, Vector3, Vector4}; fn main() { diff --git a/nalgebra-glm/src/ext/matrix_clip_space.rs b/nalgebra-glm/src/ext/matrix_clip_space.rs index 15395787..02179759 100644 --- a/nalgebra-glm/src/ext/matrix_clip_space.rs +++ b/nalgebra-glm/src/ext/matrix_clip_space.rs @@ -282,7 +282,6 @@ pub fn perspective_fov_lh_no(fov: N, width: N, height: N, near: N, far: "The fov must be greater than zero" ); - let zero = N::zero(); let mut mat = TMat4::zeros(); let rad = fov; @@ -522,7 +521,6 @@ pub fn perspective_lh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4< "The apsect ratio must not be zero." ); - let zero = N::zero(); let one = N::one(); let two: N = ::convert( 2.0); let mut mat : TMat4 = TMat4::zeros(); @@ -559,7 +557,6 @@ pub fn perspective_lh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4< "The apsect ratio must not be zero." ); - let zero = N::zero(); let one = N::one(); let two: N = ::convert( 2.0); let mut mat: TMat4 = TMat4::zeros(); @@ -664,7 +661,6 @@ pub fn perspective_rh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4< ); let negone = -N::one(); - let zero = N::zero(); let one = N::one(); let two = ::convert( 2.0); let mut mat = TMat4::zeros(); diff --git a/nalgebra-glm/src/ext/quaternion_common.rs b/nalgebra-glm/src/ext/quaternion_common.rs index 208601ed..3a91d0c7 100644 --- a/nalgebra-glm/src/ext/quaternion_common.rs +++ b/nalgebra-glm/src/ext/quaternion_common.rs @@ -33,5 +33,5 @@ pub fn quat_lerp(x: &Qua, y: &Qua, a: N) -> Qua { pub fn quat_slerp(x: &Qua, y: &Qua, a: N) -> Qua { Unit::new_normalize(*x) .slerp(&Unit::new_normalize(*y), a) - .unwrap() + .into_inner() } diff --git a/nalgebra-glm/src/ext/quaternion_transform.rs b/nalgebra-glm/src/ext/quaternion_transform.rs index a1459269..a4a60210 100644 --- a/nalgebra-glm/src/ext/quaternion_transform.rs +++ b/nalgebra-glm/src/ext/quaternion_transform.rs @@ -19,7 +19,7 @@ pub fn quat_pow(q: &Qua, y: N) -> Qua { /// Builds a quaternion from an axis and an angle, and right-multiply it to the quaternion `q`. pub fn quat_rotate(q: &Qua, angle: N, axis: &TVec3) -> Qua { - q * UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap() + q * UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).into_inner() } //pub fn quat_sqrt(q: &Qua) -> Qua { diff --git a/nalgebra-glm/src/ext/quaternion_trigonometric.rs b/nalgebra-glm/src/ext/quaternion_trigonometric.rs index 6e9be030..762bd9e9 100644 --- a/nalgebra-glm/src/ext/quaternion_trigonometric.rs +++ b/nalgebra-glm/src/ext/quaternion_trigonometric.rs @@ -9,13 +9,13 @@ pub fn quat_angle(x: &Qua) -> N { /// Creates a quaternion from an axis and an angle. pub fn quat_angle_axis(angle: N, axis: &TVec3) -> Qua { - UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).unwrap() + UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).into_inner() } /// The rotation axis of a quaternion assumed to be normalized. pub fn quat_axis(x: &Qua) -> TVec3 { if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() { - a.unwrap() + a.into_inner() } else { TVec3::zeros() } diff --git a/nalgebra-glm/src/gtc/quaternion.rs b/nalgebra-glm/src/gtc/quaternion.rs index 61501776..d31a0bcb 100644 --- a/nalgebra-glm/src/gtc/quaternion.rs +++ b/nalgebra-glm/src/gtc/quaternion.rs @@ -47,12 +47,12 @@ pub fn quat_look_at(direction: &TVec3, up: &TVec3) -> Qua { /// Computes a left-handed look-at quaternion (equivalent to a left-handed look-at matrix). pub fn quat_look_at_lh(direction: &TVec3, up: &TVec3) -> Qua { - UnitQuaternion::look_at_lh(direction, up).unwrap() + UnitQuaternion::look_at_lh(direction, up).into_inner() } /// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix). pub fn quat_look_at_rh(direction: &TVec3, up: &TVec3) -> Qua { - UnitQuaternion::look_at_rh(direction, up).unwrap() + UnitQuaternion::look_at_rh(direction, up).into_inner() } /// The "roll" Euler angle of the quaternion `x` assumed to be normalized. diff --git a/nalgebra-glm/src/gtx/quaternion.rs b/nalgebra-glm/src/gtx/quaternion.rs index 5762b58d..70005ca8 100644 --- a/nalgebra-glm/src/gtx/quaternion.rs +++ b/nalgebra-glm/src/gtx/quaternion.rs @@ -21,7 +21,7 @@ pub fn quat_extract_real_component(q: &Qua) -> N { pub fn quat_fast_mix(x: &Qua, y: &Qua, a: N) -> Qua { Unit::new_unchecked(*x) .nlerp(&Unit::new_unchecked(*y), a) - .unwrap() + .into_inner() } //pub fn quat_intermediate(prev: &Qua, curr: &Qua, next: &Qua) -> Qua { @@ -40,7 +40,7 @@ pub fn quat_magnitude2(q: &Qua) -> N { /// The quaternion representing the identity rotation. pub fn quat_identity() -> Qua { - UnitQuaternion::identity().unwrap() + UnitQuaternion::identity().into_inner() } /// Rotates a vector by a quaternion assumed to be normalized. @@ -58,14 +58,14 @@ pub fn quat_rotate_vec(q: &Qua, v: &TVec4) -> TVec4 { pub fn quat_rotation(orig: &TVec3, dest: &TVec3) -> Qua { UnitQuaternion::rotation_between(orig, dest) .unwrap_or_else(UnitQuaternion::identity) - .unwrap() + .into_inner() } /// The spherical linear interpolation between two quaternions. pub fn quat_short_mix(x: &Qua, y: &Qua, a: N) -> Qua { Unit::new_normalize(*x) .slerp(&Unit::new_normalize(*y), a) - .unwrap() + .into_inner() } //pub fn quat_squad(q1: &Qua, q2: &Qua, s1: &Qua, s2: &Qua, h: N) -> Qua { @@ -76,7 +76,7 @@ pub fn quat_short_mix(x: &Qua, y: &Qua, a: N) -> Qua { pub fn quat_to_mat3(x: &Qua) -> TMat3 { UnitQuaternion::new_unchecked(*x) .to_rotation_matrix() - .unwrap() + .into_inner() } /// Converts a quaternion to a rotation matrix in homogenous coordinates. @@ -87,7 +87,7 @@ pub fn quat_to_mat4(x: &Qua) -> TMat4 { /// Converts a rotation matrix to a quaternion. pub fn mat3_to_quat(x: &TMat3) -> Qua { let r = Rotation3::from_matrix_unchecked(*x); - UnitQuaternion::from_rotation_matrix(&r).unwrap() + UnitQuaternion::from_rotation_matrix(&r).into_inner() } /// Converts a rotation matrix in homogeneous coordinates to a quaternion. diff --git a/nalgebra-glm/src/gtx/rotate_normalized_axis.rs b/nalgebra-glm/src/gtx/rotate_normalized_axis.rs index 1ac9a7dc..224d7bfe 100644 --- a/nalgebra-glm/src/gtx/rotate_normalized_axis.rs +++ b/nalgebra-glm/src/gtx/rotate_normalized_axis.rs @@ -21,5 +21,5 @@ pub fn rotate_normalized_axis(m: &TMat4, angle: N, axis: &TVec3) /// * `angle` - Angle expressed in radians. /// * `axis` - Normalized axis of the rotation, must be normalized. pub fn quat_rotate_normalized_axis(q: &Qua, angle: N, axis: &TVec3) -> Qua { - q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).unwrap() + q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).into_inner() } diff --git a/nalgebra-glm/src/gtx/rotate_vector.rs b/nalgebra-glm/src/gtx/rotate_vector.rs index 0855244d..64ce7244 100644 --- a/nalgebra-glm/src/gtx/rotate_vector.rs +++ b/nalgebra-glm/src/gtx/rotate_vector.rs @@ -60,5 +60,5 @@ pub fn rotate_z_vec4(v: &TVec4, angle: N) -> TVec4 { pub fn slerp(x: &TVec3, y: &TVec3, a: N) -> TVec3 { Unit::new_unchecked(*x) .slerp(&Unit::new_unchecked(*y), a) - .unwrap() + .into_inner() } diff --git a/nalgebra-glm/tests/lib.rs b/nalgebra-glm/tests/lib.rs index 88ec1a44..0e76300c 100644 --- a/nalgebra-glm/tests/lib.rs +++ b/nalgebra-glm/tests/lib.rs @@ -9,7 +9,7 @@ use glm::Vec4; #[test] pub fn orthographic_glm_nalgebra_same() { - let na_mat : Mat4 = Orthographic3::new(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32).unwrap(); + let na_mat : Mat4 = Orthographic3::new(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32).into_inner(); let gl_mat : Mat4 = glm::ortho(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32); assert_eq!(na_mat, gl_mat); @@ -18,7 +18,7 @@ pub fn orthographic_glm_nalgebra_same() #[test] pub fn perspective_glm_nalgebra_same() { - let na_mat : Mat4 = Perspective3::new(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32).unwrap(); + let na_mat : Mat4 = Perspective3::new(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32).into_inner(); let gl_mat : Mat4 = glm::perspective(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32); assert_eq!(na_mat, gl_mat); @@ -29,7 +29,7 @@ pub fn orthographic_glm_nalgebra_project_same() { let point = Vec4::new(1.0,0.0,-20.0,1.0); - let na_mat : Mat4 = Orthographic3::new(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32).unwrap(); + let na_mat : Mat4 = Orthographic3::new(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32).into_inner(); let gl_mat : Mat4 = glm::ortho(-100.0f32,100.0f32, -50.0f32, 50.0f32, 0.1f32, 100.0f32); let na_pt = na_mat * point; @@ -44,7 +44,7 @@ pub fn perspective_glm_nalgebra_project_same() { let point = Vec4::new(1.0,0.0,-20.0,1.0); - let na_mat : Mat4 = Perspective3::new(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32).unwrap(); + let na_mat : Mat4 = Perspective3::new(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32).into_inner(); let gl_mat : Mat4 = glm::perspective(16.0f32/9.0f32, 3.14f32/2.0f32, 0.1f32, 100.0f32); let na_pt = na_mat * point; diff --git a/src/geometry/unit_complex_construction.rs b/src/geometry/unit_complex_construction.rs index d8917e41..fa4a0451 100644 --- a/src/geometry/unit_complex_construction.rs +++ b/src/geometry/unit_complex_construction.rs @@ -7,10 +7,9 @@ use rand::distributions::{Distribution, OpenClosed01, Standard}; use rand::Rng; use alga::general::Real; -use base::allocator::Allocator; use base::dimension::{U1, U2}; use base::storage::Storage; -use base::{DefaultAllocator, Unit, Vector}; +use base::{Unit, Vector}; use geometry::{Rotation2, UnitComplex}; impl UnitComplex { diff --git a/tests/geometry/quaternion.rs b/tests/geometry/quaternion.rs index c5b91554..4dd3da62 100644 --- a/tests/geometry/quaternion.rs +++ b/tests/geometry/quaternion.rs @@ -26,9 +26,9 @@ quickcheck!( relative_eq!(yaw * pitch * roll, rpy, epsilon = 1.0e-7) } - fn to_euler_angles(r: f64, p: f64, y: f64) -> bool { + fn euler_angles(r: f64, p: f64, y: f64) -> bool { let rpy = UnitQuaternion::from_euler_angles(r, p, y); - let (roll, pitch, yaw) = rpy.to_euler_angles(); + let (roll, pitch, yaw) = rpy.euler_angles(); relative_eq!(UnitQuaternion::from_euler_angles(roll, pitch, yaw), rpy, epsilon = 1.0e-7) } diff --git a/tests/geometry/rotation.rs b/tests/geometry/rotation.rs index 57aac964..e4b1f9d7 100644 --- a/tests/geometry/rotation.rs +++ b/tests/geometry/rotation.rs @@ -17,7 +17,7 @@ fn angle_3() { } #[test] -fn quaternion_to_euler_angles_issue_494() { +fn quaternion_euler_angles_issue_494() { let quat = UnitQuaternion::from_quaternion(Quaternion::new( -0.10405792, -0.6993922f32, @@ -55,17 +55,17 @@ mod quickcheck_tests { yaw * pitch * roll == rpy } - fn to_euler_angles(r: f64, p: f64, y: f64) -> bool { + fn euler_angles(r: f64, p: f64, y: f64) -> bool { let rpy = Rotation3::from_euler_angles(r, p, y); - let (roll, pitch, yaw) = rpy.to_euler_angles(); + let (roll, pitch, yaw) = rpy.euler_angles(); relative_eq!(Rotation3::from_euler_angles(roll, pitch, yaw), rpy, epsilon = 1.0e-7) } - fn to_euler_angles_gimble_lock(r: f64, y: f64) -> bool { + fn euler_angles_gimble_lock(r: f64, y: f64) -> bool { let pos = Rotation3::from_euler_angles(r, f64::frac_pi_2(), y); let neg = Rotation3::from_euler_angles(r, -f64::frac_pi_2(), y); - let (pos_r, pos_p, pos_y) = pos.to_euler_angles(); - let (neg_r, neg_p, neg_y) = neg.to_euler_angles(); + let (pos_r, pos_p, pos_y) = pos.euler_angles(); + let (neg_r, neg_p, neg_y) = neg.euler_angles(); relative_eq!(Rotation3::from_euler_angles(pos_r, pos_p, pos_y), pos, epsilon = 1.0e-7) && relative_eq!(Rotation3::from_euler_angles(neg_r, neg_p, neg_y), neg, epsilon = 1.0e-7) }