diff --git a/benches/core/matrix.rs b/benches/core/matrix.rs index 1103858a..c323cd6e 100644 --- a/benches/core/matrix.rs +++ b/benches/core/matrix.rs @@ -1,7 +1,7 @@ +use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, MatrixN, Vector2, Vector3, Vector4, U10}; use rand::{IsaacRng, Rng}; -use test::{self, Bencher}; -use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, MatrixN, U10, Vector2, Vector3, Vector4}; use std::ops::{Add, Div, Mul, Sub}; +use test::{self, Bencher}; #[path = "../common/macros.rs"] mod macros; @@ -189,18 +189,10 @@ fn mat_mul_mat(bench: &mut Bencher) { #[bench] fn mat100_from_fn(bench: &mut Bencher) { - bench.iter(|| { - DMatrix::from_fn(100, 100, |a, b| { - a + b - }) - }) + bench.iter(|| DMatrix::from_fn(100, 100, |a, b| a + b)) } #[bench] fn mat500_from_fn(bench: &mut Bencher) { - bench.iter(|| { - DMatrix::from_fn(500, 500, |a, b| { - a + b - }) - }) + bench.iter(|| DMatrix::from_fn(500, 500, |a, b| a + b)) } diff --git a/benches/core/vector.rs b/benches/core/vector.rs index afcc05ae..35e25e2d 100644 --- a/benches/core/vector.rs +++ b/benches/core/vector.rs @@ -1,8 +1,8 @@ +use na::{DVector, Vector2, Vector3, Vector4, VectorN}; use rand::{IsaacRng, Rng}; +use std::ops::{Add, Div, Mul, Sub}; use test::{self, Bencher}; use typenum::U10000; -use na::{DVector, Vector2, Vector3, Vector4, VectorN}; -use std::ops::{Add, Div, Mul, Sub}; #[path = "../common/macros.rs"] mod macros; diff --git a/benches/geometry/quaternion.rs b/benches/geometry/quaternion.rs index c04698c7..bc94c054 100644 --- a/benches/geometry/quaternion.rs +++ b/benches/geometry/quaternion.rs @@ -1,7 +1,7 @@ -use rand::{IsaacRng, Rng}; -use test::{self, Bencher}; use na::{Quaternion, UnitQuaternion, Vector3}; +use rand::{IsaacRng, Rng}; use std::ops::{Add, Div, Mul, Sub}; +use test::{self, Bencher}; #[path = "../common/macros.rs"] mod macros; diff --git a/benches/lib.rs b/benches/lib.rs index cb77c4cc..1ad3a2be 100644 --- a/benches/lib.rs +++ b/benches/lib.rs @@ -6,12 +6,12 @@ extern crate rand; extern crate test; extern crate typenum; -use rand::{IsaacRng, Rng}; use na::DMatrix; +use rand::{IsaacRng, Rng}; mod core; -mod linalg; mod geometry; +mod linalg; fn reproductible_dmatrix(nrows: usize, ncols: usize) -> DMatrix { let mut rng = IsaacRng::new_unseeded(); diff --git a/benches/linalg/bidiagonal.rs b/benches/linalg/bidiagonal.rs index c3c7f060..9e5a723e 100644 --- a/benches/linalg/bidiagonal.rs +++ b/benches/linalg/bidiagonal.rs @@ -1,5 +1,5 @@ -use test::{self, Bencher}; use na::{Bidiagonal, DMatrix, Matrix4}; +use test::{self, Bencher}; #[path = "../common/macros.rs"] mod macros; diff --git a/benches/linalg/cholesky.rs b/benches/linalg/cholesky.rs index e9d2646c..73c028cb 100644 --- a/benches/linalg/cholesky.rs +++ b/benches/linalg/cholesky.rs @@ -1,5 +1,5 @@ -use test::{self, Bencher}; use na::{Cholesky, DMatrix, DVector}; +use test::{self, Bencher}; #[bench] fn cholesky_100x100(bh: &mut Bencher) { diff --git a/benches/linalg/full_piv_lu.rs b/benches/linalg/full_piv_lu.rs index 1e0a307e..ad82b069 100644 --- a/benches/linalg/full_piv_lu.rs +++ b/benches/linalg/full_piv_lu.rs @@ -1,5 +1,5 @@ -use test::{self, Bencher}; use na::{DMatrix, DVector, FullPivLU}; +use test::{self, Bencher}; // Without unpack. #[bench] diff --git a/benches/linalg/hessenberg.rs b/benches/linalg/hessenberg.rs index c12c6a46..427aa1fe 100644 --- a/benches/linalg/hessenberg.rs +++ b/benches/linalg/hessenberg.rs @@ -1,5 +1,5 @@ -use test::{self, Bencher}; use na::{DMatrix, Hessenberg, Matrix4}; +use test::{self, Bencher}; #[path = "../common/macros.rs"] mod macros; diff --git a/benches/linalg/lu.rs b/benches/linalg/lu.rs index 2f83d351..2428cf9c 100644 --- a/benches/linalg/lu.rs +++ b/benches/linalg/lu.rs @@ -1,5 +1,5 @@ -use test::{self, Bencher}; use na::{DMatrix, DVector, LU}; +use test::{self, Bencher}; // Without unpack. #[bench] diff --git a/benches/linalg/mod.rs b/benches/linalg/mod.rs index c2cc4ade..526b32ea 100644 --- a/benches/linalg/mod.rs +++ b/benches/linalg/mod.rs @@ -1,11 +1,11 @@ -mod solve; -mod cholesky; -mod qr; -mod hessenberg; mod bidiagonal; -mod lu; +mod cholesky; mod full_piv_lu; -mod svd; +mod hessenberg; +mod lu; +mod qr; mod schur; +mod solve; +mod svd; mod symmetric_eigen; // mod eigen; diff --git a/benches/linalg/qr.rs b/benches/linalg/qr.rs index 1a182259..41a814ff 100644 --- a/benches/linalg/qr.rs +++ b/benches/linalg/qr.rs @@ -1,5 +1,5 @@ -use test::{self, Bencher}; use na::{DMatrix, DVector, Matrix4, QR}; +use test::{self, Bencher}; #[path = "../common/macros.rs"] mod macros; diff --git a/benches/linalg/schur.rs b/benches/linalg/schur.rs index e62035e8..e0e588ac 100644 --- a/benches/linalg/schur.rs +++ b/benches/linalg/schur.rs @@ -1,5 +1,5 @@ -use test::{self, Bencher}; use na::{Matrix4, RealSchur}; +use test::{self, Bencher}; #[bench] fn schur_decompose_4x4(bh: &mut Bencher) { diff --git a/benches/linalg/solve.rs b/benches/linalg/solve.rs index 3362549a..03ec71e5 100644 --- a/benches/linalg/solve.rs +++ b/benches/linalg/solve.rs @@ -1,5 +1,5 @@ -use test::Bencher; use na::{DMatrix, DVector}; +use test::Bencher; #[bench] fn solve_l_triangular_100x100(bh: &mut Bencher) { diff --git a/benches/linalg/svd.rs b/benches/linalg/svd.rs index 62a29d3a..47023804 100644 --- a/benches/linalg/svd.rs +++ b/benches/linalg/svd.rs @@ -1,5 +1,5 @@ -use test::{self, Bencher}; use na::{Matrix4, SVD}; +use test::{self, Bencher}; #[bench] fn svd_decompose_4x4(bh: &mut Bencher) { diff --git a/benches/linalg/symmetric_eigen.rs b/benches/linalg/symmetric_eigen.rs index 6d2056d2..2a9058da 100644 --- a/benches/linalg/symmetric_eigen.rs +++ b/benches/linalg/symmetric_eigen.rs @@ -1,5 +1,5 @@ -use test::{self, Bencher}; use na::{Matrix4, SymmetricEigen}; +use test::{self, Bencher}; #[bench] fn symmetric_eigen_decompose_4x4(bh: &mut Bencher) { diff --git a/examples/dimensional_genericity.rs b/examples/dimensional_genericity.rs index 2650cc64..ca653d57 100644 --- a/examples/dimensional_genericity.rs +++ b/examples/dimensional_genericity.rs @@ -2,15 +2,13 @@ extern crate alga; extern crate nalgebra as na; use alga::linear::FiniteDimInnerSpace; -use na::{DefaultAllocator, Real, Unit, Vector2, Vector3, VectorN}; use na::allocator::Allocator; use na::dimension::Dim; +use na::{DefaultAllocator, Real, Unit, Vector2, Vector3, VectorN}; /// Reflects a vector wrt. the hyperplane with normal `plane_normal`. fn reflect_wrt_hyperplane_with_algebraic_genericity(plane_normal: &Unit, vector: &V) -> V -where - V: FiniteDimInnerSpace + Copy, -{ +where V: FiniteDimInnerSpace + Copy { let n = plane_normal.as_ref(); // Get the underlying vector of type `V`. *vector - *n * (n.dot(vector) * na::convert(2.0)) } @@ -31,9 +29,7 @@ where /// Reflects a 2D vector wrt. the 2D line with normal `plane_normal`. fn reflect_wrt_hyperplane2(plane_normal: &Unit>, vector: &Vector2) -> Vector2 -where - N: Real, -{ +where N: Real { let n = plane_normal.as_ref(); // Get the underlying Vector2 vector - n * (n.dot(vector) * na::convert(2.0)) } @@ -41,9 +37,7 @@ where /// Reflects a 3D vector wrt. the 3D plane with normal `plane_normal`. /// /!\ This is an exact replicate of `reflect_wrt_hyperplane2, but for 3D. fn reflect_wrt_hyperplane3(plane_normal: &Unit>, vector: &Vector3) -> Vector3 -where - N: Real, -{ +where N: Real { let n = plane_normal.as_ref(); // Get the underlying Vector3 vector - n * (n.dot(vector) * na::convert(2.0)) } diff --git a/examples/homogeneous_coordinates.rs b/examples/homogeneous_coordinates.rs index f2d30d5a..e0660032 100644 --- a/examples/homogeneous_coordinates.rs +++ b/examples/homogeneous_coordinates.rs @@ -2,8 +2,8 @@ extern crate approx; extern crate nalgebra as na; -use std::f32; use na::{Isometry2, Point2, Vector2}; +use std::f32; fn use_dedicated_types() { let iso = Isometry2::new(Vector2::new(1.0, 1.0), f32::consts::PI); diff --git a/examples/identity.rs b/examples/identity.rs index d97bed98..06d69f70 100644 --- a/examples/identity.rs +++ b/examples/identity.rs @@ -9,9 +9,7 @@ use na::{Id, Isometry3, Point3, Vector3}; * intermediate value. */ fn complicated_algorithm(v: &Vector3, t: &T, n: usize) -> Vector3 -where - T: Transformation>, -{ +where T: Transformation> { let mut result = *v; // Do lots of operations involving t. diff --git a/examples/matrix_construction.rs b/examples/matrix_construction.rs index 304228cb..ddcb25c3 100644 --- a/examples/matrix_construction.rs +++ b/examples/matrix_construction.rs @@ -48,11 +48,10 @@ fn main() { 4, 3, [ - // Components listed column-by-column. - 1.0, 0.0, 0.0, 0.0, - 0.0, 1.0, 0.0, 0.0, - 0.0, 0.0, 1.0, 0.0 - ].iter() + // Components listed column-by-column. + 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 0.0, + ] + .iter() .cloned(), ); diff --git a/examples/transform_vector_point.rs b/examples/transform_vector_point.rs index f9a2e575..a6ec2fff 100644 --- a/examples/transform_vector_point.rs +++ b/examples/transform_vector_point.rs @@ -2,8 +2,8 @@ extern crate approx; extern crate nalgebra as na; -use std::f32; use na::{Isometry2, Point2, Vector2}; +use std::f32; fn main() { let t = Isometry2::new(Vector2::new(1.0, 1.0), f32::consts::PI); diff --git a/nalgebra-glm/src/common.rs b/nalgebra-glm/src/common.rs index a21681ba..021ac3ef 100644 --- a/nalgebra-glm/src/common.rs +++ b/nalgebra-glm/src/common.rs @@ -22,9 +22,7 @@ use traits::{Alloc, Dimension, Number}; /// /// * [`sign`](fn.sign.html) pub fn abs(x: &TMat) -> TMat -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.abs() } @@ -46,9 +44,7 @@ where /// * [`round`](fn.round.html) /// * [`trunc`](fn.trunc.html) pub fn ceil(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|x| x.ceil()) } @@ -98,9 +94,7 @@ pub fn clamp_scalar(x: N, min_val: N, max_val: N) -> N { /// * [`clamp_scalar`](fn.clamp_scalar.html) /// * [`clamp_vec`](fn.clamp_vec.html) pub fn clamp(x: &TVec, min_val: N, max_val: N) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|x| na::clamp(x, min_val, max_val)) } @@ -173,9 +167,7 @@ pub fn float_bits_to_int(v: f32) -> i32 { /// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) /// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn float_bits_to_int_vec(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.map(float_bits_to_int) } @@ -210,9 +202,7 @@ pub fn float_bits_to_uint(v: f32) -> u32 { /// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) /// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn float_bits_to_uint_vec(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.map(float_bits_to_uint) } @@ -233,9 +223,7 @@ where /// * [`round`](fn.round.html) /// * [`trunc`](fn.trunc.html) pub fn floor(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|x| x.floor()) } @@ -262,9 +250,7 @@ where /// * [`round`](fn.round.html) /// * [`trunc`](fn.trunc.html) pub fn fract(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|x| x.fract()) } @@ -307,9 +293,7 @@ pub fn int_bits_to_float(v: i32) -> f32 { /// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) /// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn int_bits_to_float_vec(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.map(int_bits_to_float) } @@ -368,9 +352,7 @@ pub fn mix_scalar(x: N, y: N, a: N) -> N { /// * [`mix_scalar`](fn.mix_scalar.html) /// * [`mix_vec`](fn.mix_vec.html) pub fn mix(x: &TVec, y: &TVec, a: N) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x * (N::one() - a) + y * a } @@ -443,9 +425,7 @@ pub fn lerp_scalar(x: N, y: N, a: N) -> N { /// * [`lerp_scalar`](fn.lerp_scalar.html) /// * [`lerp_vec`](fn.lerp_vec.html) pub fn lerp(x: &TVec, y: &TVec, a: N) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { mix(x, y, a) } @@ -488,9 +468,7 @@ where /// /// * [`modf`](fn.modf.html) pub fn modf_vec(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x % y) } @@ -522,9 +500,7 @@ pub fn modf(x: N, i: N) -> N { /// * [`fract`](fn.fract.html) /// * [`trunc`](fn.trunc.html) pub fn round(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|x| x.round()) } @@ -548,9 +524,7 @@ where /// * [`abs`](fn.abs.html) /// pub fn sign(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|x| if x.is_zero() { N::zero() } else { x.signum() }) } @@ -576,17 +550,13 @@ pub fn step_scalar(edge: N, x: N) -> N { /// Returns 0.0 if `x[i] < edge`, otherwise it returns 1.0. pub fn step(edge: N, x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|x| step_scalar(edge, x)) } /// Returns 0.0 if `x[i] < edge[i]`, otherwise it returns 1.0. pub fn step_vec(edge: &TVec, x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { edge.zip_map(x, step_scalar) } @@ -607,9 +577,7 @@ where /// * [`fract`](fn.fract.html) /// * [`round`](fn.round.html) pub fn trunc(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|x| x.trunc()) } @@ -644,8 +612,6 @@ pub fn uint_bits_to_float_scalar(v: u32) -> f32 { /// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html) /// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn uint_bits_to_float(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.map(uint_bits_to_float_scalar) } diff --git a/nalgebra-glm/src/constructors.rs b/nalgebra-glm/src/constructors.rs index f19ae534..1651dd20 100644 --- a/nalgebra-glm/src/constructors.rs +++ b/nalgebra-glm/src/constructors.rs @@ -1,3 +1,5 @@ +#![cfg_attr(rustfmt, rustfmt_skip)] + use na::{Scalar, Real, U2, U3, U4}; use aliases::{TMat, Qua, TVec1, TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3}; @@ -34,7 +36,8 @@ pub fn vec4(x: N, y: N, z: N, w: N) -> TVec4 { /// Create a new 2x2 matrix. -pub fn mat2(m11: N, m12: N, m21: N, m22: N) -> TMat2 { +pub fn mat2(m11: N, m12: N, + m21: N, m22: N) -> TMat2 { TMat::::new( m11, m12, m21, m22, @@ -42,7 +45,8 @@ pub fn mat2(m11: N, m12: N, m21: N, m22: N) -> TMat2 { } /// Create a new 2x2 matrix. -pub fn mat2x2(m11: N, m12: N, m21: N, m22: N) -> TMat2 { +pub fn mat2x2(m11: N, m12: N, + m21: N, m22: N) -> TMat2 { TMat::::new( m11, m12, m21, m22, @@ -50,7 +54,8 @@ pub fn mat2x2(m11: N, m12: N, m21: N, m22: N) -> TMat2 { } /// Create a new 2x3 matrix. -pub fn mat2x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat2x3 { +pub fn mat2x3(m11: N, m12: N, m13: N, + m21: N, m22: N, m23: N) -> TMat2x3 { TMat::::new( m11, m12, m13, m21, m22, m23, @@ -58,7 +63,8 @@ pub fn mat2x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat } /// Create a new 2x4 matrix. -pub fn mat2x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N) -> TMat2x4 { +pub fn mat2x4(m11: N, m12: N, m13: N, m14: N, + m21: N, m22: N, m23: N, m24: N) -> TMat2x4 { TMat::::new( m11, m12, m13, m14, m21, m22, m23, m24, @@ -66,7 +72,9 @@ pub fn mat2x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, } /// Create a new 3x3 matrix. -pub fn mat3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> TMat3 { +pub fn mat3(m11: N, m12: N, m13: N, + m21: N, m22: N, m23: N, + m31: N, m32: N, m33: N) -> TMat3 { TMat::::new( m11, m12, m13, m21, m22, m23, @@ -75,7 +83,9 @@ pub fn mat3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m } /// Create a new 3x2 matrix. -pub fn mat3x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat3x2 { +pub fn mat3x2(m11: N, m12: N, + m21: N, m22: N, + m31: N, m32: N) -> TMat3x2 { TMat::::new( m11, m12, m21, m22, @@ -84,7 +94,9 @@ pub fn mat3x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat } /// Create a new 3x3 matrix. -pub fn mat3x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N) -> TMat3 { +pub fn mat3x3(m11: N, m12: N, m13: N, + m21: N, m22: N, m23: N, + m31: N, m32: N, m33: N) -> TMat3 { TMat::::new( m11, m12, m13, m31, m32, m33, @@ -93,7 +105,9 @@ pub fn mat3x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, } /// Create a new 3x4 matrix. -pub fn mat3x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, m24: N, m31: N, m32: N, m33: N, m34: N) -> TMat3x4 { +pub fn mat3x4(m11: N, m12: N, m13: N, m14: N, + m21: N, m22: N, m23: N, m24: N, + m31: N, m32: N, m33: N, m34: N) -> TMat3x4 { TMat::::new( m11, m12, m13, m14, m21, m22, m23, m24, @@ -102,7 +116,10 @@ pub fn mat3x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, } /// Create a new 4x2 matrix. -pub fn mat4x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N, m42: N) -> TMat4x2 { +pub fn mat4x2(m11: N, m12: N, + m21: N, m22: N, + m31: N, m32: N, + m41: N, m42: N) -> TMat4x2 { TMat::::new( m11, m12, m21, m22, @@ -112,7 +129,10 @@ pub fn mat4x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N, m41: N, } /// Create a new 4x3 matrix. -pub fn mat4x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, m32: N, m33: N, m41: N, m42: N, m43: N) -> TMat4x3 { +pub fn mat4x3(m11: N, m12: N, m13: N, + m21: N, m22: N, m23: N, + m31: N, m32: N, m33: N, + m41: N, m42: N, m43: N) -> TMat4x3 { TMat::::new( m11, m12, m13, m21, m22, m23, @@ -122,7 +142,10 @@ pub fn mat4x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N, m31: N, } /// Create a new 4x4 matrix. -pub fn mat4x4(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) -> TMat4 { +pub fn mat4x4(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) -> TMat4 { TMat::::new( m11, m12, m13, m14, m21, m22, m23, m24, @@ -132,7 +155,10 @@ pub fn mat4x4(m11: N, m12: N, m13: N, m14: N, m21: N, m22: N, m23: N, } /// Create a new 4x4 matrix. -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) -> TMat4 { +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) -> TMat4 { TMat::::new( m11, m12, m13, m14, m21, m22, m23, m24, diff --git a/nalgebra-glm/src/exponential.rs b/nalgebra-glm/src/exponential.rs index a913dbc8..21b716f2 100644 --- a/nalgebra-glm/src/exponential.rs +++ b/nalgebra-glm/src/exponential.rs @@ -8,9 +8,7 @@ use traits::{Alloc, Dimension}; /// /// * [`exp2`](fn.exp2.html) pub fn exp(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.map(|x| x.exp()) } @@ -20,9 +18,7 @@ where /// /// * [`exp`](fn.exp.html) pub fn exp2(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.map(|x| x.exp2()) } @@ -32,9 +28,7 @@ where /// /// * [`sqrt`](fn.sqrt.html) pub fn inversesqrt(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.map(|x| N::one() / x.sqrt()) } @@ -44,9 +38,7 @@ where /// /// * [`log2`](fn.log2.html) pub fn log(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.map(|x| x.ln()) } @@ -56,17 +48,13 @@ where /// /// * [`log`](fn.log.html) pub fn log2(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.map(|x| x.log2()) } /// Component-wise power. pub fn pow(base: &TVec, exponent: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { base.zip_map(exponent, |b, e| b.powf(e)) } @@ -79,8 +67,6 @@ where /// * [`inversesqrt`](fn.inversesqrt.html) /// * [`pow`](fn.pow.html) pub fn sqrt(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.map(|x| x.sqrt()) } diff --git a/nalgebra-glm/src/ext/matrix_projection.rs b/nalgebra-glm/src/ext/matrix_projection.rs index 7f07d3a4..d56103a6 100644 --- a/nalgebra-glm/src/ext/matrix_projection.rs +++ b/nalgebra-glm/src/ext/matrix_projection.rs @@ -45,7 +45,8 @@ pub fn project( model: &TMat4, proj: &TMat4, viewport: TVec4, -) -> TVec3 { +) -> TVec3 +{ project_no(obj, model, proj, viewport) } @@ -72,7 +73,8 @@ pub fn project_no( model: &TMat4, proj: &TMat4, viewport: TVec4, -) -> TVec3 { +) -> TVec3 +{ let proj = project_zo(obj, model, proj, viewport); TVec3::new(proj.x, proj.y, proj.z * na::convert(0.5) + na::convert(0.5)) } @@ -100,7 +102,8 @@ pub fn project_zo( model: &TMat4, proj: &TMat4, viewport: TVec4, -) -> TVec3 { +) -> TVec3 +{ let normalized = proj * model * TVec4::new(obj.x, obj.y, obj.z, N::one()); let scale = N::one() / normalized.w; @@ -132,7 +135,8 @@ pub fn unproject( model: &TMat4, proj: &TMat4, viewport: TVec4, -) -> TVec3 { +) -> TVec3 +{ unproject_no(win, model, proj, viewport) } @@ -159,7 +163,8 @@ pub fn unproject_no( model: &TMat4, proj: &TMat4, viewport: TVec4, -) -> TVec3 { +) -> TVec3 +{ let _2: N = na::convert(2.0); let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros); let pt = TVec4::new( @@ -196,7 +201,8 @@ pub fn unproject_zo( model: &TMat4, proj: &TMat4, viewport: TVec4, -) -> TVec3 { +) -> TVec3 +{ let _2: N = na::convert(2.0); let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros); let pt = TVec4::new( diff --git a/nalgebra-glm/src/ext/matrix_transform.rs b/nalgebra-glm/src/ext/matrix_transform.rs index 613a4beb..fb23efc9 100644 --- a/nalgebra-glm/src/ext/matrix_transform.rs +++ b/nalgebra-glm/src/ext/matrix_transform.rs @@ -5,9 +5,7 @@ use traits::{Alloc, Dimension, Number}; /// The identity matrix. pub fn identity() -> TMat -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { TMat::::identity() } diff --git a/nalgebra-glm/src/ext/vector_common.rs b/nalgebra-glm/src/ext/vector_common.rs index f1b76724..c0318067 100644 --- a/nalgebra-glm/src/ext/vector_common.rs +++ b/nalgebra-glm/src/ext/vector_common.rs @@ -17,9 +17,7 @@ use traits::{Alloc, Dimension, Number}; /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) pub fn max(a: &TVec, b: N) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { a.map(|a| na::sup(&a, &b)) } @@ -37,9 +35,7 @@ where /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) pub fn max2(a: &TVec, b: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { na::sup(a, b) } @@ -57,9 +53,7 @@ where /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) pub fn max3(a: &TVec, b: &TVec, c: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { max2(&max2(a, b), c) } @@ -102,9 +96,7 @@ where /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) pub fn min(x: &TVec, y: N) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|x| na::inf(&x, &y)) } @@ -122,9 +114,7 @@ where /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) pub fn min2(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { na::inf(x, y) } @@ -142,9 +132,7 @@ where /// * [`min2`](fn.min2.html) /// * [`min4`](fn.min4.html) pub fn min3(a: &TVec, b: &TVec, c: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { min2(&min2(a, b), c) } diff --git a/nalgebra-glm/src/geometric.rs b/nalgebra-glm/src/geometric.rs index c9352a47..998709d6 100644 --- a/nalgebra-glm/src/geometric.rs +++ b/nalgebra-glm/src/geometric.rs @@ -14,17 +14,13 @@ pub fn cross(x: &TVec3, y: &TVec3) -> TVec3 { /// /// * [`distance2`](fn.distance2.html) pub fn distance(p0: &TVec, p1: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { (p1 - p0).norm() } /// The dot product of two vectors. pub fn dot(x: &TVec, y: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.dot(y) } @@ -54,9 +50,7 @@ where /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) pub fn length(x: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.norm() } @@ -70,34 +64,26 @@ where /// * [`magnitude2`](fn.magnitude2.html) /// * [`nalgebra::norm`](../nalgebra/fn.norm.html) pub fn magnitude(x: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.norm() } /// Normalizes a vector. pub fn normalize(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.normalize() } /// For the incident vector `i` and surface orientation `n`, returns the reflection direction : `result = i - 2.0 * dot(n, i) * n`. pub fn reflect_vec(i: &TVec, n: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { let _2 = N::one() + N::one(); i - n * (n.dot(i) * _2) } /// For the incident vector `i` and surface normal `n`, and the ratio of indices of refraction `eta`, return the refraction vector. pub fn refract_vec(i: &TVec, n: &TVec, eta: N) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { let ni = n.dot(i); let k = N::one() - eta * eta * (N::one() - ni * ni); diff --git a/nalgebra-glm/src/gtc/matrix_access.rs b/nalgebra-glm/src/gtc/matrix_access.rs index eea2658b..3eabf5e2 100644 --- a/nalgebra-glm/src/gtc/matrix_access.rs +++ b/nalgebra-glm/src/gtc/matrix_access.rs @@ -10,7 +10,10 @@ use traits::{Alloc, Dimension}; /// * [`row`](fn.row.html) /// * [`set_column`](fn.set_column.html) /// * [`set_row`](fn.set_row.html) -pub fn column(m: &TMat, index: usize) -> TVec +pub fn column( + m: &TMat, + index: usize, +) -> TVec where DefaultAllocator: Alloc, { @@ -45,9 +48,7 @@ where /// * [`set_column`](fn.set_column.html) /// * [`set_row`](fn.set_row.html) pub fn row(m: &TMat, index: usize) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { m.row(index).into_owned().transpose() } diff --git a/nalgebra-glm/src/gtc/matrix_inverse.rs b/nalgebra-glm/src/gtc/matrix_inverse.rs index 9f7bd159..4fc305e0 100644 --- a/nalgebra-glm/src/gtc/matrix_inverse.rs +++ b/nalgebra-glm/src/gtc/matrix_inverse.rs @@ -5,18 +5,14 @@ use traits::{Alloc, Dimension}; /// Fast matrix inverse for affine matrix. pub fn affine_inverse(m: TMat) -> TMat -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { // FIXME: this should be optimized. m.try_inverse().unwrap_or_else(TMat::<_, D, D>::zeros) } /// Compute the transpose of the inverse of a matrix. pub fn inverse_transpose(m: TMat) -> TMat -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { m.try_inverse() .unwrap_or_else(TMat::<_, D, D>::zeros) .transpose() diff --git a/nalgebra-glm/src/gtc/type_ptr.rs b/nalgebra-glm/src/gtc/type_ptr.rs index 1bde6951..93a88e78 100644 --- a/nalgebra-glm/src/gtc/type_ptr.rs +++ b/nalgebra-glm/src/gtc/type_ptr.rs @@ -384,16 +384,12 @@ pub fn make_vec4(ptr: &[N]) -> TVec4 { /// Converts a matrix or vector to a slice arranged in column-major order. pub fn value_ptr(x: &TMat) -> &[N] -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.as_slice() } /// Converts a matrix or vector to a mutable slice arranged in column-major order. pub fn value_ptr_mut(x: &mut TMat) -> &mut [N] -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.as_mut_slice() } diff --git a/nalgebra-glm/src/gtx/component_wise.rs b/nalgebra-glm/src/gtx/component_wise.rs index bcc14a8c..338f4380 100644 --- a/nalgebra-glm/src/gtx/component_wise.rs +++ b/nalgebra-glm/src/gtx/component_wise.rs @@ -22,9 +22,7 @@ use traits::{Alloc, Dimension, Number}; /// * [`comp_min`](fn.comp_min.html) /// * [`comp_mul`](fn.comp_mul.html) pub fn comp_add(m: &TMat) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { m.iter().fold(N::zero(), |x, y| x + *y) } @@ -51,9 +49,7 @@ where /// * [`max3`](fn.max3.html) /// * [`max4`](fn.max4.html) pub fn comp_max(m: &TMat) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { m.iter().fold(N::min_value(), |x, y| na::sup(&x, y)) } @@ -80,9 +76,7 @@ where /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) pub fn comp_min(m: &TMat) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { m.iter().fold(N::max_value(), |x, y| na::inf(&x, y)) } @@ -105,9 +99,7 @@ where /// * [`comp_max`](fn.comp_max.html) /// * [`comp_min`](fn.comp_min.html) pub fn comp_mul(m: &TMat) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { m.iter().fold(N::one(), |x, y| x * *y) } diff --git a/nalgebra-glm/src/gtx/norm.rs b/nalgebra-glm/src/gtx/norm.rs index aef2a818..0a287530 100644 --- a/nalgebra-glm/src/gtx/norm.rs +++ b/nalgebra-glm/src/gtx/norm.rs @@ -9,9 +9,7 @@ use traits::{Alloc, Dimension}; /// /// * [`distance`](fn.distance.html) pub fn distance2(p0: &TVec, p1: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { (p1 - p0).norm_squared() } @@ -23,9 +21,7 @@ where /// * [`l2_distance`](fn.l2_distance.html) /// * [`l2_norm`](fn.l2_norm.html) pub fn l1_distance(x: &TVec, y: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { l1_norm(&(y - x)) } @@ -40,9 +36,7 @@ where /// * [`l2_distance`](fn.l2_distance.html) /// * [`l2_norm`](fn.l2_norm.html) pub fn l1_norm(v: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { ::comp_add(&v.abs()) } @@ -61,9 +55,7 @@ where /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) pub fn l2_distance(x: &TVec, y: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { l2_norm(&(y - x)) } @@ -84,9 +76,7 @@ where /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) pub fn l2_norm(x: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.norm() } @@ -102,9 +92,7 @@ where /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) pub fn length2(x: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.norm_squared() } @@ -120,9 +108,7 @@ where /// * [`magnitude`](fn.magnitude.html) /// * [`nalgebra::norm_squared`](../nalgebra/fn.norm_squared.html) pub fn magnitude2(x: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.norm_squared() } diff --git a/nalgebra-glm/src/gtx/normalize_dot.rs b/nalgebra-glm/src/gtx/normalize_dot.rs index 34fc5665..df52d2c0 100644 --- a/nalgebra-glm/src/gtx/normalize_dot.rs +++ b/nalgebra-glm/src/gtx/normalize_dot.rs @@ -11,9 +11,7 @@ use traits::{Alloc, Dimension}; /// /// * [`normalize_dot`](fn.normalize_dot.html`) pub fn fast_normalize_dot(x: &TVec, y: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { // XXX: improve those. x.normalize().dot(&y.normalize()) } @@ -24,9 +22,7 @@ where /// /// * [`fast_normalize_dot`](fn.fast_normalize_dot.html`) pub fn normalize_dot(x: &TVec, y: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { // XXX: improve those. x.normalize().dot(&y.normalize()) } diff --git a/nalgebra-glm/src/gtx/vector_angle.rs b/nalgebra-glm/src/gtx/vector_angle.rs index 048a132d..1ebb39a4 100644 --- a/nalgebra-glm/src/gtx/vector_angle.rs +++ b/nalgebra-glm/src/gtx/vector_angle.rs @@ -5,9 +5,7 @@ use traits::{Alloc, Dimension}; /// The angle between two vectors. pub fn angle(x: &TVec, y: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.angle(y) } diff --git a/nalgebra-glm/src/gtx/vector_query.rs b/nalgebra-glm/src/gtx/vector_query.rs index 05114a5b..f408a4b3 100644 --- a/nalgebra-glm/src/gtx/vector_query.rs +++ b/nalgebra-glm/src/gtx/vector_query.rs @@ -22,7 +22,11 @@ pub fn are_collinear2d(v0: &TVec2, v1: &TVec2, epsilon: N) -> b } /// Returns `true` if two vectors are orthogonal (up to an epsilon). -pub fn are_orthogonal(v0: &TVec, v1: &TVec, epsilon: N) -> bool +pub fn are_orthogonal( + v0: &TVec, + v1: &TVec, + epsilon: N, +) -> bool where DefaultAllocator: Alloc, { @@ -36,24 +40,18 @@ where /// Returns `true` if all the components of `v` are zero (up to an epsilon). pub fn is_comp_null(v: &TVec, epsilon: N) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.map(|x| abs_diff_eq!(x, N::zero(), epsilon = epsilon)) } /// Returns `true` if `v` has a magnitude of 1 (up to an epsilon). pub fn is_normalized(v: &TVec, epsilon: N) -> bool -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { abs_diff_eq!(v.norm_squared(), N::one(), epsilon = epsilon * epsilon) } /// Returns `true` if `v` is zero (up to an epsilon). pub fn is_null(v: &TVec, epsilon: N) -> bool -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { abs_diff_eq!(*v, TVec::::zeros(), epsilon = epsilon) } diff --git a/nalgebra-glm/src/lib.rs b/nalgebra-glm/src/lib.rs index cb931f6c..63f97891 100644 --- a/nalgebra-glm/src/lib.rs +++ b/nalgebra-glm/src/lib.rs @@ -110,8 +110,6 @@ and keep in mind it is possible to convert, e.g., an `Isometry3` to a `Mat4` and vice-versa (see the [conversions section](#conversions)). */ -#![doc(html_favicon_url = "http://nalgebra.org/img/favicon.ico")] - extern crate num_traits as num; #[macro_use] extern crate approx; @@ -122,9 +120,8 @@ pub use aliases::*; pub use common::{ abs, ceil, clamp, clamp_scalar, clamp_vec, float_bits_to_int, float_bits_to_int_vec, float_bits_to_uint, float_bits_to_uint_vec, floor, fract, int_bits_to_float, - int_bits_to_float_vec, lerp, lerp_scalar, lerp_vec, mix, mix_scalar, mix_vec, modf, modf_vec, - round, sign, smoothstep, step, step_scalar, step_vec, trunc, uint_bits_to_float, - uint_bits_to_float_scalar, + int_bits_to_float_vec, mix, modf, modf_vec, round, sign, smoothstep, step, step_scalar, + step_vec, trunc, uint_bits_to_float, uint_bits_to_float_scalar, }; pub use constructors::*; pub use exponential::{exp, exp2, inversesqrt, log, log2, pow, sqrt}; diff --git a/nalgebra-glm/src/matrix.rs b/nalgebra-glm/src/matrix.rs index 34ad5826..81212248 100644 --- a/nalgebra-glm/src/matrix.rs +++ b/nalgebra-glm/src/matrix.rs @@ -5,17 +5,13 @@ use traits::{Alloc, Dimension, Number}; /// The determinant of the matrix `m`. pub fn determinant(m: &TMat) -> N -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { m.determinant() } /// The inverse of the matrix `m`. pub fn inverse(m: &TMat) -> TMat -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { m.clone() .try_inverse() .unwrap_or_else(TMat::::zeros) @@ -45,8 +41,6 @@ where /// The transpose of the matrix `m`. pub fn transpose(x: &TMat) -> TMat -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.transpose() } diff --git a/nalgebra-glm/src/traits.rs b/nalgebra-glm/src/traits.rs index f4d47dfd..d338539d 100644 --- a/nalgebra-glm/src/traits.rs +++ b/nalgebra-glm/src/traits.rs @@ -50,8 +50,7 @@ pub trait Alloc: { } -impl Alloc for T where - T: Allocator +impl Alloc for T where T: Allocator + Allocator + Allocator + Allocator diff --git a/nalgebra-glm/src/trigonometric.rs b/nalgebra-glm/src/trigonometric.rs index ae376bcd..cf0b2652 100644 --- a/nalgebra-glm/src/trigonometric.rs +++ b/nalgebra-glm/src/trigonometric.rs @@ -5,120 +5,90 @@ use traits::{Alloc, Dimension}; /// Component-wise arc-cosinus. pub fn acos(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|e| e.acos()) } /// Component-wise hyperbolic arc-cosinus. pub fn acosh(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|e| e.acosh()) } /// Component-wise arc-sinus. pub fn asin(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|e| e.asin()) } /// Component-wise hyperbolic arc-sinus. pub fn asinh(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|e| e.asinh()) } /// Component-wise arc-tangent of `y / x`. pub fn atan2(y: &TVec, x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { y.zip_map(x, |y, x| y.atan2(x)) } /// Component-wise arc-tangent. pub fn atan(y_over_x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { y_over_x.map(|e| e.atan()) } /// Component-wise hyperbolic arc-tangent. pub fn atanh(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.map(|e| e.atanh()) } /// Component-wise cosinus. pub fn cos(angle: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { angle.map(|e| e.cos()) } /// Component-wise hyperbolic cosinus. pub fn cosh(angle: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { angle.map(|e| e.cosh()) } /// Component-wise conversion from radians to degrees. pub fn degrees(radians: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { radians.map(|e| e * na::convert(180.0) / N::pi()) } /// Component-wise conversion fro degrees to radians. pub fn radians(degrees: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { degrees.map(|e| e * N::pi() / na::convert(180.0)) } /// Component-wise sinus. pub fn sin(angle: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { angle.map(|e| e.sin()) } /// Component-wise hyperbolic sinus. pub fn sinh(angle: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { angle.map(|e| e.sinh()) } /// Component-wise tangent. pub fn tan(angle: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { angle.map(|e| e.tan()) } /// Component-wise hyperbolic tangent. pub fn tanh(angle: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { angle.map(|e| e.tanh()) } diff --git a/nalgebra-glm/src/vector_relational.rs b/nalgebra-glm/src/vector_relational.rs index 494b6f9f..c92f69fe 100644 --- a/nalgebra-glm/src/vector_relational.rs +++ b/nalgebra-glm/src/vector_relational.rs @@ -21,9 +21,7 @@ use traits::{Alloc, Dimension, Number}; /// * [`any`](fn.any.html) /// * [`not`](fn.not.html) pub fn all(v: &TVec) -> bool -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.iter().all(|x| *x) } @@ -48,9 +46,7 @@ where /// * [`all`](fn.all.html) /// * [`not`](fn.not.html) pub fn any(v: &TVec) -> bool -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.iter().any(|x| *x) } @@ -74,9 +70,7 @@ where /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn equal(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x == y) } @@ -100,9 +94,7 @@ where /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn greater_than(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x > y) } @@ -125,7 +117,10 @@ where /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) -pub fn greater_than_equal(x: &TVec, y: &TVec) -> TVec +pub fn greater_than_equal( + x: &TVec, + y: &TVec, +) -> TVec where DefaultAllocator: Alloc, { @@ -152,9 +147,7 @@ where /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn less_than(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x < y) } @@ -178,9 +171,7 @@ where /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) pub fn less_than_equal(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x <= y) } @@ -205,9 +196,7 @@ where /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not_equal`](fn.not_equal.html) pub fn not(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { v.map(|x| !x) } @@ -231,8 +220,6 @@ where /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) pub fn not_equal(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x != y) } diff --git a/nalgebra-lapack/benches/linalg/hessenberg.rs b/nalgebra-lapack/benches/linalg/hessenberg.rs index 90c97b8b..d62c221c 100644 --- a/nalgebra-lapack/benches/linalg/hessenberg.rs +++ b/nalgebra-lapack/benches/linalg/hessenberg.rs @@ -1,6 +1,6 @@ -use test::{self, Bencher}; use na::{DMatrix, Matrix4}; use nl::Hessenberg; +use test::{self, Bencher}; #[bench] fn hessenberg_decompose_100x100(bh: &mut Bencher) { diff --git a/nalgebra-lapack/benches/linalg/lu.rs b/nalgebra-lapack/benches/linalg/lu.rs index 95010978..4afd9003 100644 --- a/nalgebra-lapack/benches/linalg/lu.rs +++ b/nalgebra-lapack/benches/linalg/lu.rs @@ -1,6 +1,6 @@ -use test::{self, Bencher}; use na::{DMatrix, Matrix4}; use nl::LU; +use test::{self, Bencher}; #[bench] fn lu_decompose_100x100(bh: &mut Bencher) { diff --git a/nalgebra-lapack/benches/linalg/mod.rs b/nalgebra-lapack/benches/linalg/mod.rs index f42ec321..e07bd361 100644 --- a/nalgebra-lapack/benches/linalg/mod.rs +++ b/nalgebra-lapack/benches/linalg/mod.rs @@ -1,3 +1,3 @@ -mod qr; -mod lu; mod hessenberg; +mod lu; +mod qr; diff --git a/nalgebra-lapack/benches/linalg/qr.rs b/nalgebra-lapack/benches/linalg/qr.rs index 07b830d9..c473e6f5 100644 --- a/nalgebra-lapack/benches/linalg/qr.rs +++ b/nalgebra-lapack/benches/linalg/qr.rs @@ -1,6 +1,6 @@ -use test::{self, Bencher}; use na::{DMatrix, Matrix4}; use nl::QR; +use test::{self, Bencher}; #[bench] fn qr_decompose_100x100(bh: &mut Bencher) { diff --git a/nalgebra-lapack/src/cholesky.rs b/nalgebra-lapack/src/cholesky.rs index 26d2ef92..7615a899 100644 --- a/nalgebra-lapack/src/cholesky.rs +++ b/nalgebra-lapack/src/cholesky.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use num::Zero; use num_complex::Complex; @@ -15,26 +15,21 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator, + serde(bound( + serialize = "DefaultAllocator: Allocator, MatrixN: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator, + serde(bound( + deserialize = "DefaultAllocator: Allocator, MatrixN: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct Cholesky -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { l: MatrixN, } @@ -43,12 +38,10 @@ impl Copy for Cholesky where DefaultAllocator: Allocator, MatrixN: Copy, -{ -} +{} impl Cholesky -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Computes the cholesky decomposition of the given symmetric-definite-positive square /// matrix. @@ -124,9 +117,7 @@ where /// Solves in-place the symmetric-definite-positive linear system `self * x = b`, where `x` is /// the unknown to be determined. pub fn solve_mut(&self, b: &mut MatrixMN) -> bool - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let dim = self.l.nrows(); assert!( diff --git a/nalgebra-lapack/src/eigen.rs b/nalgebra-lapack/src/eigen.rs index e1c71075..d95219cb 100644 --- a/nalgebra-lapack/src/eigen.rs +++ b/nalgebra-lapack/src/eigen.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use num::Zero; use num_complex::Complex; @@ -18,28 +18,23 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator + Allocator, + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator, VectorN: Serialize, MatrixN: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator + Allocator, + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator, VectorN: Serialize, MatrixN: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct Eigen -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { /// The eigenvalues of the decomposed matrix. pub eigenvalues: VectorN, @@ -54,12 +49,10 @@ where DefaultAllocator: Allocator + Allocator, VectorN: Copy, MatrixN: Copy, -{ -} +{} impl Eigen -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { /// Computes the eigenvalues and eigenvectors of the square matrix `m`. /// @@ -68,7 +61,8 @@ where mut m: MatrixN, left_eigenvectors: bool, eigenvectors: bool, - ) -> Option> { + ) -> Option> + { assert!( m.is_square(), "Unable to compute the eigenvalue decomposition of a non-square matrix." @@ -234,9 +228,7 @@ where /// /// Panics if the eigenvalue computation does not converge. pub fn complex_eigenvalues(mut m: MatrixN) -> VectorN, D> - where - DefaultAllocator: Allocator, D>, - { + where DefaultAllocator: Allocator, D> { assert!( m.is_square(), "Unable to compute the eigenvalue decomposition of a non-square matrix." diff --git a/nalgebra-lapack/src/hessenberg.rs b/nalgebra-lapack/src/hessenberg.rs index c42e349b..6bfa673b 100644 --- a/nalgebra-lapack/src/hessenberg.rs +++ b/nalgebra-lapack/src/hessenberg.rs @@ -13,30 +13,25 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator + + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator>, MatrixN: Serialize, VectorN>: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator>, MatrixN: Deserialize<'de>, VectorN>: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct Hessenberg> -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { h: MatrixN, tau: VectorN>, @@ -47,12 +42,10 @@ where DefaultAllocator: Allocator + Allocator>, MatrixN: Copy, VectorN>: Copy, -{ -} +{} impl> Hessenberg -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { /// Computes the hessenberg decomposition of the matrix `m`. pub fn new(mut m: MatrixN) -> Hessenberg { @@ -104,8 +97,7 @@ where } impl> Hessenberg -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { /// Computes the matrices `(Q, H)` of this decomposition. #[inline] diff --git a/nalgebra-lapack/src/lu.rs b/nalgebra-lapack/src/lu.rs index cab7b763..c9b1167c 100644 --- a/nalgebra-lapack/src/lu.rs +++ b/nalgebra-lapack/src/lu.rs @@ -20,30 +20,25 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator + + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator>, MatrixMN: Serialize, PermutationSequence>: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator>, MatrixMN: Deserialize<'de>, PermutationSequence>: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct LU, C: Dim> -where - DefaultAllocator: Allocator> + Allocator, +where DefaultAllocator: Allocator> + Allocator { lu: MatrixMN, p: VectorN>, @@ -54,8 +49,7 @@ where DefaultAllocator: Allocator + Allocator>, MatrixMN: Copy, VectorN>: Copy, -{ -} +{} impl LU where @@ -139,9 +133,7 @@ where /// Applies the permutation matrix to a given matrix or vector in-place. #[inline] pub fn permute(&self, rhs: &mut MatrixMN) - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let (nrows, ncols) = rhs.shape(); N::xlaswp( @@ -156,9 +148,7 @@ where } fn generic_solve_mut(&self, trans: u8, b: &mut MatrixMN) -> bool - where - DefaultAllocator: Allocator + Allocator, - { + where DefaultAllocator: Allocator + Allocator { let dim = self.lu.nrows(); assert!( @@ -246,9 +236,7 @@ where /// /// Returns `false` if no solution was found (the decomposed matrix is singular). pub fn solve_mut(&self, b: &mut MatrixMN) -> bool - where - DefaultAllocator: Allocator + Allocator, - { + where DefaultAllocator: Allocator + Allocator { self.generic_solve_mut(b'N', b) } @@ -257,9 +245,7 @@ where /// /// Returns `false` if no solution was found (the decomposed matrix is singular). pub fn solve_transpose_mut(&self, b: &mut MatrixMN) -> bool - where - DefaultAllocator: Allocator + Allocator, - { + where DefaultAllocator: Allocator + Allocator { self.generic_solve_mut(b'T', b) } diff --git a/nalgebra-lapack/src/qr.rs b/nalgebra-lapack/src/qr.rs index f41cb7ce..66220e49 100644 --- a/nalgebra-lapack/src/qr.rs +++ b/nalgebra-lapack/src/qr.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use num::Zero; use num_complex::Complex; @@ -16,30 +16,25 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator + + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator>, MatrixMN: Serialize, VectorN>: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator>, MatrixMN: Deserialize<'de>, VectorN>: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct QR, C: Dim> -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { qr: MatrixMN, tau: VectorN>, @@ -50,15 +45,13 @@ where DefaultAllocator: Allocator + Allocator>, MatrixMN: Copy, VectorN>: Copy, -{ -} +{} impl, C: Dim> QR -where - DefaultAllocator: Allocator +where DefaultAllocator: Allocator + Allocator> + Allocator, C> - + Allocator>, + + Allocator> { /// Computes the QR decomposition of the matrix `m`. pub fn new(mut m: MatrixMN) -> QR { @@ -105,11 +98,10 @@ where } impl, C: Dim> QR -where - DefaultAllocator: Allocator +where DefaultAllocator: Allocator + Allocator> + Allocator, C> - + Allocator>, + + Allocator> { /// Retrieves the matrices `(Q, R)` of this decompositions. pub fn unpack( @@ -131,7 +123,8 @@ where return MatrixMN::from_element_generic(nrows, min_nrows_ncols, N::zero()); } - let mut q = self.qr + let mut q = self + .qr .generic_slice((0, 0), (nrows, min_nrows_ncols)) .into_owned(); diff --git a/nalgebra-lapack/src/schur.rs b/nalgebra-lapack/src/schur.rs index b26e464b..a09b31ff 100644 --- a/nalgebra-lapack/src/schur.rs +++ b/nalgebra-lapack/src/schur.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use num::Zero; use num_complex::Complex; @@ -18,28 +18,23 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator + Allocator, + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator, VectorN: Serialize, MatrixN: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator + Allocator, + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator, VectorN: Serialize, MatrixN: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct RealSchur -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { re: VectorN, im: VectorN, @@ -52,12 +47,10 @@ where DefaultAllocator: Allocator + Allocator, MatrixN: Copy, VectorN: Copy, -{ -} +{} impl RealSchur -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { /// Computes the eigenvalues and real Schur form of the matrix `m`. /// @@ -152,9 +145,7 @@ where /// Computes the complex eigenvalues of the decomposed matrix. pub fn complex_eigenvalues(&self) -> VectorN, D> - where - DefaultAllocator: Allocator, D>, - { + where DefaultAllocator: Allocator, D> { let mut out = unsafe { VectorN::new_uninitialized_generic(self.t.data.shape().0, U1) }; for i in 0..out.len() { diff --git a/nalgebra-lapack/src/svd.rs b/nalgebra-lapack/src/svd.rs index 347f5b9e..2d048bf3 100644 --- a/nalgebra-lapack/src/svd.rs +++ b/nalgebra-lapack/src/svd.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use num::Signed; use std::cmp; @@ -15,34 +15,29 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator> + + serde(bound( + serialize = "DefaultAllocator: Allocator> + Allocator + Allocator, MatrixN: Serialize, MatrixN: Serialize, VectorN>: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator> + + serde(bound( + serialize = "DefaultAllocator: Allocator> + Allocator + Allocator, MatrixN: Deserialize<'de>, MatrixN: Deserialize<'de>, VectorN>: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct SVD, C: Dim> -where - DefaultAllocator: Allocator + Allocator> + Allocator, +where DefaultAllocator: Allocator + Allocator> + Allocator { /// The left-singular vectors `U` of this SVD. pub u: MatrixN, // FIXME: should be MatrixMN> @@ -58,28 +53,25 @@ where MatrixMN: Copy, MatrixMN: Copy, VectorN>: Copy, -{ -} +{} /// Trait implemented by floats (`f32`, `f64`) and complex floats (`Complex`, `Complex`) /// supported by the Singular Value Decompotition. pub trait SVDScalar, C: Dim>: Scalar -where - DefaultAllocator: Allocator +where DefaultAllocator: Allocator + Allocator + Allocator> - + Allocator, + + Allocator { /// Computes the SVD decomposition of `m`. fn compute(m: MatrixMN) -> Option>; } impl, R: DimMin, C: Dim> SVD -where - DefaultAllocator: Allocator +where DefaultAllocator: Allocator + Allocator + Allocator> - + Allocator, + + Allocator { /// Computes the Singular Value Decomposition of `matrix`. pub fn new(m: MatrixMN) -> Option { diff --git a/nalgebra-lapack/src/symmetric_eigen.rs b/nalgebra-lapack/src/symmetric_eigen.rs index 6ec7e1e9..e7d5bd0f 100644 --- a/nalgebra-lapack/src/symmetric_eigen.rs +++ b/nalgebra-lapack/src/symmetric_eigen.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use num::Zero; use std::ops::MulAssign; @@ -18,30 +18,25 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator + + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator, VectorN: Serialize, MatrixN: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator, VectorN: Deserialize<'de>, MatrixN: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct SymmetricEigen -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { /// The eigenvectors of the decomposed matrix. pub eigenvectors: MatrixN, @@ -55,12 +50,10 @@ where DefaultAllocator: Allocator + Allocator, MatrixN: Copy, VectorN: Copy, -{ -} +{} impl SymmetricEigen -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { /// Computes the eigenvalues and eigenvectors of the symmetric matrix `m`. /// @@ -89,7 +82,8 @@ where fn do_decompose( mut m: MatrixN, eigenvectors: bool, - ) -> Option<(VectorN, Option>)> { + ) -> Option<(VectorN, Option>)> + { assert!( m.is_square(), "Unable to compute the eigenvalue decomposition of a non-square matrix." diff --git a/nalgebra-lapack/tests/linalg/cholesky.rs b/nalgebra-lapack/tests/linalg/cholesky.rs index 5f011bce..01561532 100644 --- a/nalgebra-lapack/tests/linalg/cholesky.rs +++ b/nalgebra-lapack/tests/linalg/cholesky.rs @@ -1,7 +1,7 @@ use std::cmp; -use nl::Cholesky; use na::{DMatrix, DVector, Matrix3, Matrix4, Matrix4x3, Vector4}; +use nl::Cholesky; quickcheck!{ fn cholesky(m: DMatrix) -> bool { diff --git a/nalgebra-lapack/tests/linalg/lu.rs b/nalgebra-lapack/tests/linalg/lu.rs index c601a897..652d1032 100644 --- a/nalgebra-lapack/tests/linalg/lu.rs +++ b/nalgebra-lapack/tests/linalg/lu.rs @@ -1,7 +1,7 @@ use std::cmp; -use nl::LU; use na::{DMatrix, DVector, Matrix3x4, Matrix4, Matrix4x3, Vector4}; +use nl::LU; quickcheck!{ fn lup(m: DMatrix) -> bool { diff --git a/nalgebra-lapack/tests/linalg/mod.rs b/nalgebra-lapack/tests/linalg/mod.rs index f692fa88..ba228308 100644 --- a/nalgebra-lapack/tests/linalg/mod.rs +++ b/nalgebra-lapack/tests/linalg/mod.rs @@ -1,7 +1,7 @@ -mod real_eigensystem; -mod symmetric_eigen; mod cholesky; mod lu; mod qr; -mod svd; +mod real_eigensystem; mod real_schur; +mod svd; +mod symmetric_eigen; diff --git a/nalgebra-lapack/tests/linalg/qr.rs b/nalgebra-lapack/tests/linalg/qr.rs index baac445b..ebdb9b34 100644 --- a/nalgebra-lapack/tests/linalg/qr.rs +++ b/nalgebra-lapack/tests/linalg/qr.rs @@ -1,5 +1,5 @@ -use nl::QR; use na::{DMatrix, Matrix4x3}; +use nl::QR; quickcheck!{ fn qr(m: DMatrix) -> bool { diff --git a/nalgebra-lapack/tests/linalg/real_eigensystem.rs b/nalgebra-lapack/tests/linalg/real_eigensystem.rs index 70a3d787..f3130a54 100644 --- a/nalgebra-lapack/tests/linalg/real_eigensystem.rs +++ b/nalgebra-lapack/tests/linalg/real_eigensystem.rs @@ -1,7 +1,7 @@ use std::cmp; -use nl::Eigen; use na::{DMatrix, Matrix4}; +use nl::Eigen; quickcheck!{ fn eigensystem(n: usize) -> bool { diff --git a/nalgebra-lapack/tests/linalg/real_schur.rs b/nalgebra-lapack/tests/linalg/real_schur.rs index ad6fbb3c..127107dd 100644 --- a/nalgebra-lapack/tests/linalg/real_schur.rs +++ b/nalgebra-lapack/tests/linalg/real_schur.rs @@ -1,6 +1,6 @@ -use std::cmp; -use nl::RealSchur; use na::{DMatrix, Matrix4}; +use nl::RealSchur; +use std::cmp; quickcheck! { fn schur(n: usize) -> bool { diff --git a/nalgebra-lapack/tests/linalg/svd.rs b/nalgebra-lapack/tests/linalg/svd.rs index 9ab7a99e..9f15b83a 100644 --- a/nalgebra-lapack/tests/linalg/svd.rs +++ b/nalgebra-lapack/tests/linalg/svd.rs @@ -1,5 +1,5 @@ -use nl::SVD; use na::{DMatrix, Matrix3x4}; +use nl::SVD; quickcheck!{ fn svd(m: DMatrix) -> bool { diff --git a/nalgebra-lapack/tests/linalg/symmetric_eigen.rs b/nalgebra-lapack/tests/linalg/symmetric_eigen.rs index a1ebdfa2..42074ada 100644 --- a/nalgebra-lapack/tests/linalg/symmetric_eigen.rs +++ b/nalgebra-lapack/tests/linalg/symmetric_eigen.rs @@ -1,7 +1,7 @@ use std::cmp; -use nl::SymmetricEigen; use na::{DMatrix, Matrix4}; +use nl::SymmetricEigen; quickcheck!{ fn symmetric_eigen(n: usize) -> bool { diff --git a/rustfmt.toml b/rustfmt.toml new file mode 100644 index 00000000..dff7375b --- /dev/null +++ b/rustfmt.toml @@ -0,0 +1,3 @@ +unstable_features = true +indent_style = "Block" +where_single_line = true diff --git a/src/base/alias_slice.rs b/src/base/alias_slice.rs index 14519344..1b368c8e 100644 --- a/src/base/alias_slice.rs +++ b/src/base/alias_slice.rs @@ -1,6 +1,6 @@ -use base::Matrix; use base::dimension::{Dynamic, U1, U2, U3, U4, U5, U6}; use base::matrix_slice::{SliceStorage, SliceStorageMut}; +use base::Matrix; /* * diff --git a/src/base/allocator.rs b/src/base/allocator.rs index 61dd71eb..5b17c183 100644 --- a/src/base/allocator.rs +++ b/src/base/allocator.rs @@ -2,10 +2,10 @@ use std::any::Any; -use base::{DefaultAllocator, Scalar}; use base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; use base::dimension::{Dim, U1}; use base::storage::ContiguousStorageMut; +use base::{DefaultAllocator, Scalar}; /// A matrix allocator of a memory buffer that may contain `R::to_usize() * C::to_usize()` /// elements of type `N`. @@ -33,8 +33,9 @@ pub trait Allocator: Any + Sized { /// A matrix reallocator. Changes the size of the memory buffer that initially contains (RFrom × /// CFrom) elements to a smaller or larger size (RTo, CTo). -pub trait Reallocator - : Allocator + Allocator { +pub trait Reallocator: + Allocator + Allocator +{ /// Reallocates a buffer of shape `(RTo, CTo)`, possibly reusing a previously allocated buffer /// `buf`. Data stored by `buf` are linearly copied to the output: /// @@ -57,8 +58,8 @@ pub type SameShapeC = >:: // FIXME: Bad name. /// Restricts the given number of rows and columns to be respectively the same. -pub trait SameShapeAllocator - : Allocator + Allocator, SameShapeC> +pub trait SameShapeAllocator: + Allocator + Allocator, SameShapeC> where R1: Dim, R2: Dim, @@ -78,13 +79,12 @@ where N: Scalar, DefaultAllocator: Allocator + Allocator, SameShapeC>, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, -{ -} +{} // XXX: Bad name. /// Restricts the given number of rows to be equal. -pub trait SameShapeVectorAllocator - : Allocator + Allocator> + SameShapeAllocator +pub trait SameShapeVectorAllocator: + Allocator + Allocator> + SameShapeAllocator where R1: Dim, R2: Dim, @@ -100,5 +100,4 @@ where N: Scalar, DefaultAllocator: Allocator + Allocator>, ShapeConstraint: SameNumberOfRows, -{ -} +{} diff --git a/src/base/blas.rs b/src/base/blas.rs index 49797519..073f519b 100644 --- a/src/base/blas.rs +++ b/src/base/blas.rs @@ -14,7 +14,6 @@ use base::storage::{Storage, StorageMut}; use base::{DefaultAllocator, Matrix, Scalar, SquareMatrix, Vector}; impl> Vector { - /// Computes the index of the vector component with the largest value. /// /// # Examples: @@ -162,8 +161,7 @@ impl> Matri } impl> Matrix -where - N: Scalar + Zero + ClosedAdd + ClosedMul, +where N: Scalar + Zero + ClosedAdd + ClosedMul { /// The dot product between two vectors or matrices (seen as vectors). /// @@ -325,9 +323,7 @@ where } fn array_axpy(y: &mut [N], a: N, x: &[N], beta: N, stride1: usize, stride2: usize, len: usize) -where - N: Scalar + Zero + ClosedAdd + ClosedMul, -{ +where N: Scalar + Zero + ClosedAdd + ClosedMul { for i in 0..len { unsafe { let y = y.get_unchecked_mut(i * stride1); @@ -337,9 +333,7 @@ where } fn array_ax(y: &mut [N], a: N, x: &[N], stride1: usize, stride2: usize, len: usize) -where - N: Scalar + Zero + ClosedAdd + ClosedMul, -{ +where N: Scalar + Zero + ClosedAdd + ClosedMul { for i in 0..len { unsafe { *y.get_unchecked_mut(i * stride1) = a * *x.get_unchecked(i * stride2); @@ -577,8 +571,7 @@ where } impl> Matrix -where - N: Scalar + Zero + ClosedAdd + ClosedMul, +where N: Scalar + Zero + ClosedAdd + ClosedMul { /// Computes `self = alpha * x * y.transpose() + beta * self`. /// @@ -685,13 +678,19 @@ where // We could use matrixmultiply for large statically-sized matrices but the performance // threshold to activate it would be different from SMALL_DIM because our code optimizes // better for statically-sized matrices. - let is_dynamic = R1::is::() || C1::is::() || R2::is::() - || C2::is::() || R3::is::() + let is_dynamic = R1::is::() + || C1::is::() + || R2::is::() + || C2::is::() + || R3::is::() || C3::is::(); // Threshold determined empirically. const SMALL_DIM: usize = 5; - if is_dynamic && nrows1 > SMALL_DIM && ncols1 > SMALL_DIM && nrows2 > SMALL_DIM + if is_dynamic + && nrows1 > SMALL_DIM + && ncols1 > SMALL_DIM + && nrows2 > SMALL_DIM && ncols2 > SMALL_DIM { if N::is::() { @@ -812,8 +811,7 @@ where } impl> Matrix -where - N: Scalar + Zero + ClosedAdd + ClosedMul, +where N: Scalar + Zero + ClosedAdd + ClosedMul { /// Computes `self = alpha * x * y.transpose() + beta * self`, where `self` is a **symmetric** /// matrix. @@ -871,8 +869,7 @@ where } impl> SquareMatrix -where - N: Scalar + Zero + One + ClosedAdd + ClosedMul, +where N: Scalar + Zero + One + ClosedAdd + ClosedMul { /// Computes the quadratic form `self = alpha * lhs * mid * lhs.transpose() + beta * self`. /// diff --git a/src/base/cg.rs b/src/base/cg.rs index 84fff1a5..01be4e99 100644 --- a/src/base/cg.rs +++ b/src/base/cg.rs @@ -7,15 +7,18 @@ use num::One; -use base::{DefaultAllocator, Matrix3, Matrix4, MatrixN, Scalar, SquareMatrix, Unit, Vector, - Vector3, VectorN}; +use base::allocator::Allocator; use base::dimension::{DimName, DimNameDiff, DimNameSub, U1}; use base::storage::{Storage, StorageMut}; -use base::allocator::Allocator; -use geometry::{Isometry, IsometryMatrix3, Orthographic3, Perspective3, Point, Point3, Rotation2, - Rotation3}; +use base::{ + DefaultAllocator, Matrix3, Matrix4, MatrixN, Scalar, SquareMatrix, Unit, Vector, Vector3, + VectorN, +}; +use geometry::{ + Isometry, IsometryMatrix3, Orthographic3, Perspective3, Point, Point3, Rotation2, Rotation3, +}; -use alga::general::{Ring, Real}; +use alga::general::{Real, Ring}; use alga::linear::Transformation; impl MatrixN @@ -235,9 +238,7 @@ impl> SquareMatrix /// Computes in-place the transformation equal to `self` followed by an uniform scaling factor. #[inline] pub fn append_scaling_mut(&mut self, scaling: N) - where - D: DimNameSub, - { + where D: DimNameSub { let mut to_scale = self.fixed_rows_mut::>(0); to_scale *= scaling; } @@ -245,9 +246,7 @@ impl> SquareMatrix /// Computes in-place the transformation equal to an uniform scaling factor followed by `self`. #[inline] pub fn prepend_scaling_mut(&mut self, scaling: N) - where - D: DimNameSub, - { + where D: DimNameSub { let mut to_scale = self.fixed_columns_mut::>(0); to_scale *= scaling; } @@ -302,7 +301,8 @@ impl> SquareMatrix SB: Storage>, DefaultAllocator: Allocator>, { - let scale = self.fixed_slice::>(D::dim() - 1, 0) + let scale = self + .fixed_slice::>(D::dim() - 1, 0) .tr_dot(&shift); let post_translation = self.fixed_slice::, DimNameDiff>(0, 0) * shift; @@ -315,16 +315,16 @@ impl> SquareMatrix } impl> Transformation>> for MatrixN -where - DefaultAllocator: Allocator +where DefaultAllocator: Allocator + Allocator> - + Allocator, DimNameDiff>, + + Allocator, DimNameDiff> { #[inline] fn transform_vector( &self, v: &VectorN>, - ) -> VectorN> { + ) -> VectorN> + { let transform = self.fixed_slice::, DimNameDiff>(0, 0); let normalizer = self.fixed_slice::>(D::dim() - 1, 0); let n = normalizer.tr_dot(&v); @@ -341,9 +341,8 @@ where let transform = self.fixed_slice::, DimNameDiff>(0, 0); let translation = self.fixed_slice::, U1>(0, D::dim() - 1); let normalizer = self.fixed_slice::>(D::dim() - 1, 0); - let n = normalizer.tr_dot(&pt.coords) + unsafe { - *self.get_unchecked(D::dim() - 1, D::dim() - 1) - }; + let n = normalizer.tr_dot(&pt.coords) + + unsafe { *self.get_unchecked(D::dim() - 1, D::dim() - 1) }; if !n.is_zero() { return transform * (pt / n) + translation; diff --git a/src/base/constraint.rs b/src/base/constraint.rs index 369841b5..3bd0540b 100644 --- a/src/base/constraint.rs +++ b/src/base/constraint.rs @@ -8,11 +8,8 @@ pub struct ShapeConstraint; /// Constraints `C1` and `R2` to be equivalent. pub trait AreMultipliable: DimEq {} -impl AreMultipliable for ShapeConstraint -where - ShapeConstraint: DimEq, -{ -} +impl AreMultipliable for ShapeConstraint where ShapeConstraint: DimEq +{} /// Constraints `D1` and `D2` to be equivalent. pub trait DimEq { @@ -70,8 +67,9 @@ equality_trait_decl!( /// Constraints D1 and D2 to be equivalent, where they both designate dimensions of algebraic /// entities (e.g. square matrices). -pub trait SameDimension - : SameNumberOfRows + SameNumberOfColumns { +pub trait SameDimension: + SameNumberOfRows + SameNumberOfColumns +{ /// This is either equal to `D1` or `D2`, always choosing the one (if any) which is a type-level /// constant. type Representative: Dim; diff --git a/src/base/construction.rs b/src/base/construction.rs index 81e5f935..c198cf65 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -26,8 +26,7 @@ use base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, Unit, Vector, Ve * */ impl MatrixMN -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Creates a new uninitialized matrix. If the matrix has a compile-time dimension, this panics /// if `nrows != R::to_usize()` or `ncols != C::to_usize()`. @@ -55,18 +54,14 @@ where /// Creates a matrix with all its elements set to 0. #[inline] pub fn zeros_generic(nrows: R, ncols: C) -> Self - where - N: Zero, - { + where N: Zero { Self::from_element_generic(nrows, ncols, N::zero()) } /// Creates a matrix with all its elements filled by an iterator. #[inline] pub fn from_iterator_generic(nrows: R, ncols: C, iter: I) -> Self - where - I: IntoIterator, - { + where I: IntoIterator { Self::from_data(DefaultAllocator::allocate_from_iterator(nrows, ncols, iter)) } @@ -105,9 +100,7 @@ where /// coordinates. #[inline] pub fn from_fn_generic(nrows: R, ncols: C, mut f: F) -> Self - where - F: FnMut(usize, usize) -> N, - { + where F: FnMut(usize, usize) -> N { let mut res = unsafe { Self::new_uninitialized_generic(nrows, ncols) }; for j in 0..ncols.value() { @@ -125,9 +118,7 @@ where /// to the identity matrix. All other entries are set to zero. #[inline] pub fn identity_generic(nrows: R, ncols: C) -> Self - where - N: Zero + One, - { + where N: Zero + One { Self::from_diagonal_element_generic(nrows, ncols, N::one()) } @@ -137,9 +128,7 @@ where /// to the identity matrix. All other entries are set to zero. #[inline] pub fn from_diagonal_element_generic(nrows: R, ncols: C, elt: N) -> Self - where - N: Zero + One, - { + where N: Zero + One { let mut res = Self::zeros_generic(nrows, ncols); for i in 0..::min(nrows.value(), ncols.value()) { @@ -155,9 +144,7 @@ where /// Panics if `elts.len()` is larger than the minimum among `nrows` and `ncols`. #[inline] pub fn from_partial_diagonal_generic(nrows: R, ncols: C, elts: &[N]) -> Self - where - N: Zero, - { + where N: Zero { let mut res = Self::zeros_generic(nrows, ncols); assert!( elts.len() <= ::min(nrows.value(), ncols.value()), @@ -189,9 +176,7 @@ where /// ``` #[inline] pub fn from_rows(rows: &[Matrix]) -> Self - where - SB: Storage, - { + where SB: Storage { assert!(rows.len() > 0, "At least one row must be given."); let nrows = R::try_to_usize().unwrap_or(rows.len()); let ncols = rows[0].len(); @@ -231,9 +216,7 @@ where /// ``` #[inline] pub fn from_columns(columns: &[Vector]) -> Self - where - SB: Storage, - { + where SB: Storage { assert!(columns.len() > 0, "At least one column must be given."); let ncols = C::try_to_usize().unwrap_or(columns.len()); let nrows = columns[0].len(); @@ -259,9 +242,7 @@ where #[inline] #[cfg(feature = "std")] pub fn new_random_generic(nrows: R, ncols: C) -> Self - where - Standard: Distribution, - { + where Standard: Distribution { Self::from_fn_generic(nrows, ncols, |_, _| rand::random()) } @@ -272,7 +253,8 @@ where ncols: C, distribution: &mut Distr, rng: &mut G, - ) -> Self { + ) -> Self + { Self::from_fn_generic(nrows, ncols, |_, _| distribution.sample(rng)) } } @@ -302,9 +284,7 @@ where /// ``` #[inline] pub fn from_diagonal>(diag: &Vector) -> Self - where - N: Zero, - { + where N: Zero { let (dim, _) = diag.data.shape(); let mut res = Self::zeros_generic(dim, dim); @@ -929,9 +909,7 @@ where /// The column vector with a 1 as its first component, and zero elsewhere. #[inline] pub fn x() -> Self - where - R::Value: Cmp, - { + where R::Value: Cmp { let mut res = Self::zeros(); unsafe { *res.vget_unchecked_mut(0) = N::one(); @@ -943,9 +921,7 @@ where /// The column vector with a 1 as its second component, and zero elsewhere. #[inline] pub fn y() -> Self - where - R::Value: Cmp, - { + where R::Value: Cmp { let mut res = Self::zeros(); unsafe { *res.vget_unchecked_mut(1) = N::one(); @@ -957,9 +933,7 @@ where /// The column vector with a 1 as its third component, and zero elsewhere. #[inline] pub fn z() -> Self - where - R::Value: Cmp, - { + where R::Value: Cmp { let mut res = Self::zeros(); unsafe { *res.vget_unchecked_mut(2) = N::one(); @@ -971,9 +945,7 @@ where /// The column vector with a 1 as its fourth component, and zero elsewhere. #[inline] pub fn w() -> Self - where - R::Value: Cmp, - { + where R::Value: Cmp { let mut res = Self::zeros(); unsafe { *res.vget_unchecked_mut(3) = N::one(); @@ -985,9 +957,7 @@ where /// The column vector with a 1 as its fifth component, and zero elsewhere. #[inline] pub fn a() -> Self - where - R::Value: Cmp, - { + where R::Value: Cmp { let mut res = Self::zeros(); unsafe { *res.vget_unchecked_mut(4) = N::one(); @@ -999,9 +969,7 @@ where /// The column vector with a 1 as its sixth component, and zero elsewhere. #[inline] pub fn b() -> Self - where - R::Value: Cmp, - { + where R::Value: Cmp { let mut res = Self::zeros(); unsafe { *res.vget_unchecked_mut(5) = N::one(); @@ -1013,54 +981,42 @@ where /// The unit column vector with a 1 as its first component, and zero elsewhere. #[inline] pub fn x_axis() -> Unit - where - R::Value: Cmp, - { + where R::Value: Cmp { Unit::new_unchecked(Self::x()) } /// The unit column vector with a 1 as its second component, and zero elsewhere. #[inline] pub fn y_axis() -> Unit - where - R::Value: Cmp, - { + where R::Value: Cmp { Unit::new_unchecked(Self::y()) } /// The unit column vector with a 1 as its third component, and zero elsewhere. #[inline] pub fn z_axis() -> Unit - where - R::Value: Cmp, - { + where R::Value: Cmp { Unit::new_unchecked(Self::z()) } /// The unit column vector with a 1 as its fourth component, and zero elsewhere. #[inline] pub fn w_axis() -> Unit - where - R::Value: Cmp, - { + where R::Value: Cmp { Unit::new_unchecked(Self::w()) } /// The unit column vector with a 1 as its fifth component, and zero elsewhere. #[inline] pub fn a_axis() -> Unit - where - R::Value: Cmp, - { + where R::Value: Cmp { Unit::new_unchecked(Self::a()) } /// The unit column vector with a 1 as its sixth component, and zero elsewhere. #[inline] pub fn b_axis() -> Unit - where - R::Value: Cmp, - { + where R::Value: Cmp { Unit::new_unchecked(Self::b()) } } diff --git a/src/base/construction_slice.rs b/src/base/construction_slice.rs index d7d2d159..419720bf 100644 --- a/src/base/construction_slice.rs +++ b/src/base/construction_slice.rs @@ -22,7 +22,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ncols: C, rstride: RStride, cstride: CStride, - ) -> Self { + ) -> Self + { let data = SliceStorage::from_raw_parts( data.as_ptr().offset(start as isize), (nrows, ncols), @@ -42,7 +43,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ncols: C, rstride: RStride, cstride: CStride, - ) -> Self { + ) -> Self + { // NOTE: The assertion implements the following formula, but without subtractions to avoid // underflow panics: // len >= (ncols - 1) * cstride + (nrows - 1) * rstride + 1 @@ -73,7 +75,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ncols: C, rstride: RStride, cstride: CStride, - ) -> Self { + ) -> Self + { let data = SliceStorageMut::from_raw_parts( data.as_mut_ptr().offset(start as isize), (nrows, ncols), @@ -93,7 +96,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> ncols: C, rstride: RStride, cstride: CStride, - ) -> Self { + ) -> Self + { // NOTE: The assertion implements the following formula, but without subtractions to avoid // underflow panics: // len >= (ncols - 1) * cstride + (nrows - 1) * rstride + 1 @@ -120,7 +124,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMN<'a, N, R, C> { start: usize, nrows: R, ncols: C, - ) -> Self { + ) -> Self + { Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows) } @@ -145,7 +150,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMutMN<'a, N, R, C> { start: usize, nrows: R, ncols: C, - ) -> Self { + ) -> Self + { Self::from_slice_with_strides_generic_unchecked(data, start, nrows, ncols, U1, nrows) } diff --git a/src/base/coordinates.rs b/src/base/coordinates.rs index e092763e..986b8e9d 100644 --- a/src/base/coordinates.rs +++ b/src/base/coordinates.rs @@ -7,9 +7,9 @@ use std::mem; use std::ops::{Deref, DerefMut}; -use base::{Matrix, Scalar}; use base::dimension::{U1, U2, U3, U4, U5, U6}; use base::storage::{ContiguousStorage, ContiguousStorageMut}; +use base::{Matrix, Scalar}; /* * diff --git a/src/base/default_allocator.rs b/src/base/default_allocator.rs index e097f3a2..6bdbd30d 100644 --- a/src/base/default_allocator.rs +++ b/src/base/default_allocator.rs @@ -54,7 +54,8 @@ where nrows: R, ncols: C, iter: I, - ) -> Self::Buffer { + ) -> Self::Buffer + { let mut res = unsafe { Self::allocate_uninitialized(nrows, ncols) }; let mut count = 0; @@ -93,7 +94,8 @@ impl Allocator for DefaultAllocator { nrows: Dynamic, ncols: C, iter: I, - ) -> Self::Buffer { + ) -> Self::Buffer + { let it = iter.into_iter(); let res: Vec = it.collect(); assert!(res.len() == nrows.value() * ncols.value(), @@ -123,7 +125,8 @@ impl Allocator for DefaultAllocator { nrows: R, ncols: Dynamic, iter: I, - ) -> Self::Buffer { + ) -> Self::Buffer + { let it = iter.into_iter(); let res: Vec = it.collect(); assert!(res.len() == nrows.value() * ncols.value(), @@ -154,7 +157,8 @@ where rto: RTo, cto: CTo, buf: >::Buffer, - ) -> MatrixArray { + ) -> MatrixArray + { let mut res = >::allocate_uninitialized(rto, cto); let (rfrom, cfrom) = buf.shape(); @@ -182,7 +186,8 @@ where rto: Dynamic, cto: CTo, buf: MatrixArray, - ) -> MatrixVec { + ) -> MatrixVec + { let mut res = >::allocate_uninitialized(rto, cto); let (rfrom, cfrom) = buf.shape(); @@ -210,7 +215,8 @@ where rto: RTo, cto: Dynamic, buf: MatrixArray, - ) -> MatrixVec { + ) -> MatrixVec + { let mut res = >::allocate_uninitialized(rto, cto); let (rfrom, cfrom) = buf.shape(); @@ -233,7 +239,8 @@ impl Reallocator, - ) -> MatrixVec { + ) -> MatrixVec + { let new_buf = buf.resize(rto.value() * cto.value()); MatrixVec::new(rto, cto, new_buf) } @@ -248,7 +255,8 @@ impl Reallocator, - ) -> MatrixVec { + ) -> MatrixVec + { let new_buf = buf.resize(rto.value() * cto.value()); MatrixVec::new(rto, cto, new_buf) } @@ -263,7 +271,8 @@ impl Reallocator, - ) -> MatrixVec { + ) -> MatrixVec + { let new_buf = buf.resize(rto.value() * cto.value()); MatrixVec::new(rto, cto, new_buf) } @@ -278,7 +287,8 @@ impl Reallocator, - ) -> MatrixVec { + ) -> MatrixVec + { let new_buf = buf.resize(rto.value() * cto.value()); MatrixVec::new(rto, cto, new_buf) } diff --git a/src/base/dimension.rs b/src/base/dimension.rs index c660c5a4..50d1e5d5 100644 --- a/src/base/dimension.rs +++ b/src/base/dimension.rs @@ -7,7 +7,7 @@ use std::cmp; use std::fmt::Debug; use std::ops::{Add, Div, Mul, Sub}; use typenum::{ - self, B1, Bit, Diff, Max, Maximum, Min, Minimum, Prod, Quot, Sum, UInt, UTerm, Unsigned, + self, Bit, Diff, Max, Maximum, Min, Minimum, Prod, Quot, Sum, UInt, UTerm, Unsigned, B1, }; #[cfg(feature = "serde-serialize")] @@ -30,9 +30,7 @@ impl Dynamic { #[cfg(feature = "serde-serialize")] impl Serialize for Dynamic { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.value.serialize(serializer) } } @@ -40,9 +38,7 @@ impl Serialize for Dynamic { #[cfg(feature = "serde-serialize")] impl<'de> Deserialize<'de> for Dynamic { fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { + where D: Deserializer<'de> { usize::deserialize(deserializer).map(|x| Dynamic { value: x }) } } diff --git a/src/base/edition.rs b/src/base/edition.rs index 58517614..0ae9c35f 100644 --- a/src/base/edition.rs +++ b/src/base/edition.rs @@ -16,9 +16,7 @@ impl> Matrix { /// Extracts the upper triangular part of this matrix (including the diagonal). #[inline] pub fn upper_triangle(&self) -> MatrixMN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let mut res = self.clone_owned(); res.fill_lower_triangle(N::zero(), 1); @@ -28,9 +26,7 @@ impl> Matrix { /// Extracts the upper triangular part of this matrix (including the diagonal). #[inline] pub fn lower_triangle(&self) -> MatrixMN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let mut res = self.clone_owned(); res.fill_upper_triangle(N::zero(), 1); @@ -50,9 +46,7 @@ impl> Matrix { /// Fills `self` with the identity matrix. #[inline] pub fn fill_with_identity(&mut self) - where - N: Zero + One, - { + where N: Zero + One { self.fill(N::zero()); self.fill_diagonal(N::one()); } @@ -285,7 +279,8 @@ impl> Matrix { let copied_value_start = i + nremove.value(); unsafe { - let ptr_in = m.data + let ptr_in = m + .data .ptr() .offset((copied_value_start * nrows.value()) as isize); let ptr_out = m.data.ptr_mut().offset((i * nrows.value()) as isize); @@ -448,7 +443,8 @@ impl> Matrix { if ninsert.value() != 0 && i != ncols.value() { let ptr_in = res.data.ptr().offset((i * nrows.value()) as isize); - let ptr_out = res.data + let ptr_out = res + .data .ptr_mut() .offset(((i + ninsert.value()) * nrows.value()) as isize); @@ -549,9 +545,7 @@ impl> Matrix { /// rows and/or columns than `self`, then the extra rows or columns are filled with `val`. #[cfg(any(feature = "std", feature = "alloc"))] pub fn resize(self, new_nrows: usize, new_ncols: usize, val: N) -> DMatrix - where - DefaultAllocator: Reallocator, - { + where DefaultAllocator: Reallocator { self.resize_generic(Dynamic::new(new_nrows), Dynamic::new(new_ncols), val) } @@ -560,9 +554,7 @@ impl> Matrix { /// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more /// rows and/or columns than `self`, then the extra rows or columns are filled with `val`. pub fn fixed_resize(self, val: N) -> MatrixMN - where - DefaultAllocator: Reallocator, - { + where DefaultAllocator: Reallocator { self.resize_generic(R2::name(), C2::name(), val) } @@ -640,7 +632,8 @@ unsafe fn compress_rows( ncols: usize, i: usize, nremove: usize, -) { +) +{ let new_nrows = nrows - nremove; if new_nrows == 0 || ncols == 0 { @@ -679,7 +672,8 @@ unsafe fn extend_rows( ncols: usize, i: usize, ninsert: usize, -) { +) +{ let new_nrows = nrows + ninsert; if new_nrows == 0 || ncols == 0 { diff --git a/src/base/helper.rs b/src/base/helper.rs index de601fb6..ef85a477 100644 --- a/src/base/helper.rs +++ b/src/base/helper.rs @@ -18,9 +18,7 @@ pub fn reject bool, T: Arbitrary>(g: &mut G, f: F) -> T #[doc(hidden)] #[inline] pub fn reject_rand bool, T>(g: &mut G, f: F) -> T -where - Standard: Distribution, -{ +where Standard: Distribution { use std::iter; iter::repeat(()).map(|_| g.gen()).find(f).unwrap() } diff --git a/src/base/iter.rs b/src/base/iter.rs index 52d492da..fe8fd4f6 100644 --- a/src/base/iter.rs +++ b/src/base/iter.rs @@ -3,21 +3,20 @@ use std::marker::PhantomData; use std::mem; -use base::Scalar; use base::dimension::Dim; use base::storage::{Storage, StorageMut}; +use base::Scalar; macro_rules! iterator { (struct $Name:ident for $Storage:ident.$ptr: ident -> $Ptr:ty, $Ref:ty, $SRef: ty) => { - /// An iterator through a dense matrix with arbitrary strides matrix. pub struct $Name<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage> { - ptr: $Ptr, + ptr: $Ptr, inner_ptr: $Ptr, inner_end: $Ptr, - size: usize, // We can't use an end pointer here because a stride might be zero. - strides: (S::RStride, S::CStride), - _phantoms: PhantomData<($Ref, R, C, S)> + size: usize, // We can't use an end pointer here because a stride might be zero. + strides: (S::RStride, S::CStride), + _phantoms: PhantomData<($Ref, R, C, S)>, } // FIXME: we need to specialize for the case where the matrix storage is owned (in which @@ -25,23 +24,25 @@ macro_rules! iterator { impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage> $Name<'a, N, R, C, S> { /// Creates a new iterator for the given matrix storage. pub fn new(storage: $SRef) -> $Name<'a, N, R, C, S> { - let shape = storage.shape(); + let shape = storage.shape(); let strides = storage.strides(); let inner_offset = shape.0.value() * strides.0.value(); let ptr = storage.$ptr(); $Name { - ptr: ptr, + ptr: ptr, inner_ptr: ptr, inner_end: unsafe { ptr.offset(inner_offset as isize) }, - size: shape.0.value() * shape.1.value(), - strides: strides, - _phantoms: PhantomData + size: shape.0.value() * shape.1.value(), + strides: strides, + _phantoms: PhantomData, } } } - impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage> Iterator for $Name<'a, N, R, C, S> { + impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage> Iterator + for $Name<'a, N, R, C, S> + { type Item = $Ref; #[inline] @@ -82,13 +83,15 @@ macro_rules! iterator { } } - impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage> ExactSizeIterator for $Name<'a, N, R, C, S> { + impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage> ExactSizeIterator + for $Name<'a, N, R, C, S> + { #[inline] fn len(&self) -> usize { self.size } } - } + }; } iterator!(struct MatrixIter for Storage.ptr -> *const N, &'a N, &'a S); diff --git a/src/base/matrix.rs b/src/base/matrix.rs index e8825121..a52b18e4 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -99,9 +99,7 @@ where S: Serialize, { fn serialize(&self, serializer: T) -> Result - where - T: Serializer, - { + where T: Serializer { self.data.serialize(serializer) } } @@ -115,9 +113,7 @@ where S: Deserialize<'de>, { fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { + where D: Deserializer<'de> { S::deserialize(deserializer).map(|x| Matrix { data: x, _phantoms: PhantomData, @@ -319,9 +315,7 @@ impl> Matrix { /// Moves this matrix into one that owns its data. #[inline] pub fn into_owned(self) -> MatrixMN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { Matrix::from_data(self.data.into_owned()) } @@ -355,9 +349,7 @@ impl> Matrix { /// Clones this matrix to one that owns its data. #[inline] pub fn clone_owned(&self) -> MatrixMN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { Matrix::from_data(self.data.clone_owned()) } @@ -393,9 +385,7 @@ impl> Matrix { /// Returns a matrix containing the result of `f` applied to each of its entries. #[inline] pub fn map N2>(&self, mut f: F) -> MatrixMN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let (nrows, ncols) = self.data.shape(); let mut res = unsafe { MatrixMN::new_uninitialized_generic(nrows, ncols) }; @@ -541,9 +531,7 @@ impl> Matrix { /// Transposes `self`. #[inline] pub fn transpose(&self) -> MatrixMN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let (nrows, ncols) = self.data.shape(); unsafe { @@ -666,9 +654,7 @@ impl> Matrix { /// Replaces each component of `self` by the result of a closure `f` applied on it. #[inline] pub fn apply N>(&mut self, mut f: F) - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let (nrows, ncols) = self.shape(); for j in 0..ncols { @@ -765,9 +751,7 @@ impl, R, C>> Matrix, R /// The conjugate transposition of `self`. #[inline] pub fn conjugate_transpose(&self) -> MatrixMN, C, R> - where - DefaultAllocator: Allocator, C, R>, - { + where DefaultAllocator: Allocator, C, R> { let (nrows, ncols) = self.data.shape(); unsafe { @@ -808,9 +792,7 @@ impl> SquareMatrix { /// Creates a square matrix with its diagonal set to `diag` and all other entries set to 0. #[inline] pub fn diagonal(&self) -> VectorN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { assert!( self.is_square(), "Unable to get the diagonal of a non-square matrix." @@ -831,9 +813,7 @@ impl> SquareMatrix { /// Computes a trace of a square matrix, i.e., the sum of its diagonal elements. #[inline] pub fn trace(&self) -> N - where - N: Ring, - { + where N: Ring { assert!( self.is_square(), "Cannot compute the trace of non-square matrix." @@ -855,9 +835,7 @@ impl, S: Storage> Vector { /// coordinates. #[inline] pub fn to_homogeneous(&self) -> VectorN> - where - DefaultAllocator: Allocator>, - { + where DefaultAllocator: Allocator> { let len = self.len(); let hnrows = DimSum::::from_usize(len + 1); let mut res = unsafe { VectorN::::new_uninitialized_generic(hnrows, U1) }; @@ -923,7 +901,8 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool { + ) -> bool + { self.relative_eq(other, epsilon, max_relative) } } @@ -1220,8 +1199,7 @@ impl> Matrix { } impl> Vector -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Computes the matrix `M` such that for all vector `v` we have `M * v == self.cross(&v)`. #[inline] @@ -1311,18 +1289,14 @@ impl> Matrix { /// Returns a normalized version of this matrix. #[inline] pub fn normalize(&self) -> MatrixMN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { self / self.norm() } /// Returns a normalized version of this matrix unless its norm as smaller or equal to `eps`. #[inline] pub fn try_normalize(&self, min_norm: N) -> Option> - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let n = self.norm(); if n <= min_norm { @@ -1446,7 +1420,8 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool { + ) -> bool + { self.as_ref() .relative_eq(other.as_ref(), epsilon, max_relative) } diff --git a/src/base/matrix_alga.rs b/src/base/matrix_alga.rs index 8593474e..7c454986 100644 --- a/src/base/matrix_alga.rs +++ b/src/base/matrix_alga.rs @@ -146,8 +146,7 @@ where } impl NormedSpace for MatrixMN -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn norm_squared(&self) -> N { @@ -181,8 +180,7 @@ where } impl InnerSpace for MatrixMN -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Real = N; @@ -202,8 +200,7 @@ where // − use `x()` instead of `::canonical_basis_element` // − use `::new(x, y, z)` instead of `::from_slice` impl FiniteDimInnerSpace for MatrixMN -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn orthonormalize(vs: &mut [MatrixMN]) -> usize { @@ -236,9 +233,7 @@ where #[inline] fn orthonormal_subspace_basis(vs: &[Self], mut f: F) - where - F: FnMut(&Self) -> bool, - { + where F: FnMut(&Self) -> bool { // FIXME: is this necessary? assert!( vs.len() <= Self::dimension(), diff --git a/src/base/matrix_array.rs b/src/base/matrix_array.rs index 023c7c7b..384b3ae5 100644 --- a/src/base/matrix_array.rs +++ b/src/base/matrix_array.rs @@ -107,8 +107,7 @@ where R::Value: Mul, Prod: ArrayLength, GenericArray>: Copy, -{ -} +{} impl Clone for MatrixArray where @@ -133,8 +132,7 @@ where C: DimName, R::Value: Mul, Prod: ArrayLength, -{ -} +{} impl PartialEq for MatrixArray where @@ -184,17 +182,13 @@ where #[inline] fn into_owned(self) -> Owned - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { self } #[inline] fn clone_owned(&self) -> Owned - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let it = self.iter().cloned(); DefaultAllocator::allocate_from_iterator(self.shape().0, self.shape().1, it) @@ -234,8 +228,7 @@ where R::Value: Mul, Prod: ArrayLength, DefaultAllocator: Allocator, -{ -} +{} unsafe impl ContiguousStorageMut for MatrixArray where @@ -245,8 +238,7 @@ where R::Value: Mul, Prod: ArrayLength, DefaultAllocator: Allocator, -{ -} +{} /* * @@ -264,9 +256,7 @@ where Prod: ArrayLength, { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { let mut serializer = serializer.serialize_seq(Some(R::dim() * C::dim()))?; for e in self.iter() { @@ -287,9 +277,7 @@ where Prod: ArrayLength, { fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'a>, - { + where D: Deserializer<'a> { deserializer.deserialize_seq(MatrixArrayVisitor::new()) } } @@ -334,9 +322,7 @@ where #[inline] fn visit_seq(self, mut visitor: V) -> Result, V::Error> - where - V: SeqAccess<'a>, - { + where V: SeqAccess<'a> { let mut out: Self::Value = unsafe { mem::uninitialized() }; let mut curr = 0; diff --git a/src/base/matrix_slice.rs b/src/base/matrix_slice.rs index 6ab3c6b6..a217332e 100644 --- a/src/base/matrix_slice.rs +++ b/src/base/matrix_slice.rs @@ -206,7 +206,8 @@ impl> Matrix { start: (usize, usize), shape: (usize, usize), steps: (usize, usize), - ) { + ) + { let my_shape = self.shape(); // NOTE: we don't do any subtraction to avoid underflow for zero-sized matrices. // @@ -803,7 +804,8 @@ impl> Matrix { pub fn rows_range>( &self, rows: RowRange, - ) -> MatrixSlice { + ) -> MatrixSlice + { self.slice_range(rows, ..) } @@ -812,7 +814,8 @@ impl> Matrix { pub fn columns_range>( &self, cols: ColRange, - ) -> MatrixSlice { + ) -> MatrixSlice + { self.slice_range(.., cols) } } @@ -841,7 +844,8 @@ impl> Matrix { pub fn rows_range_mut>( &mut self, rows: RowRange, - ) -> MatrixSliceMut { + ) -> MatrixSliceMut + { self.slice_range_mut(rows, ..) } @@ -850,7 +854,8 @@ impl> Matrix { pub fn columns_range_mut>( &mut self, cols: ColRange, - ) -> MatrixSliceMut { + ) -> MatrixSliceMut + { self.slice_range_mut(.., cols) } } diff --git a/src/base/matrix_vec.rs b/src/base/matrix_vec.rs index 8a28b26c..73b77609 100644 --- a/src/base/matrix_vec.rs +++ b/src/base/matrix_vec.rs @@ -94,8 +94,7 @@ impl Deref for MatrixVec { * */ unsafe impl Storage for MatrixVec -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type RStride = U1; type CStride = Dynamic; @@ -122,17 +121,13 @@ where #[inline] fn into_owned(self) -> Owned - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { self } #[inline] fn clone_owned(&self) -> Owned - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { self.clone() } @@ -143,8 +138,7 @@ where } unsafe impl Storage for MatrixVec -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type RStride = U1; type CStride = R; @@ -171,17 +165,13 @@ where #[inline] fn into_owned(self) -> Owned - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { self } #[inline] fn clone_owned(&self) -> Owned - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { self.clone() } @@ -197,8 +187,7 @@ where * */ unsafe impl StorageMut for MatrixVec -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn ptr_mut(&mut self) -> *mut N { @@ -211,21 +200,14 @@ where } } -unsafe impl ContiguousStorage for MatrixVec -where - DefaultAllocator: Allocator, -{ -} +unsafe impl ContiguousStorage for MatrixVec where DefaultAllocator: Allocator +{} -unsafe impl ContiguousStorageMut for MatrixVec -where - DefaultAllocator: Allocator, -{ -} +unsafe impl ContiguousStorageMut for MatrixVec where DefaultAllocator: Allocator +{} unsafe impl StorageMut for MatrixVec -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn ptr_mut(&mut self) -> *mut N { @@ -253,14 +235,8 @@ impl Abomonation for MatrixVec { } } -unsafe impl ContiguousStorage for MatrixVec -where - DefaultAllocator: Allocator, -{ -} +unsafe impl ContiguousStorage for MatrixVec where DefaultAllocator: Allocator +{} -unsafe impl ContiguousStorageMut for MatrixVec -where - DefaultAllocator: Allocator, -{ -} +unsafe impl ContiguousStorageMut for MatrixVec where DefaultAllocator: Allocator +{} diff --git a/src/base/mod.rs b/src/base/mod.rs index 7197b004..2f573025 100644 --- a/src/base/mod.rs +++ b/src/base/mod.rs @@ -12,7 +12,6 @@ pub mod storage; mod alias; mod alias_slice; -mod swizzle; mod cg; mod componentwise; mod construction; @@ -27,6 +26,7 @@ mod matrix_slice; mod matrix_vec; mod properties; mod scalar; +mod swizzle; mod unit; #[doc(hidden)] diff --git a/src/base/ops.rs b/src/base/ops.rs index 217ed194..14ec98f0 100644 --- a/src/base/ops.rs +++ b/src/base/ops.rs @@ -1,17 +1,19 @@ -use std::iter; -use std::ops::{Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, - SubAssign}; -use std::cmp::PartialOrd; use num::{One, Signed, Zero}; +use std::cmp::PartialOrd; +use std::iter; +use std::ops::{ + Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign, +}; use alga::general::{ClosedAdd, ClosedDiv, ClosedMul, ClosedNeg, ClosedSub}; -use base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, MatrixSum, Scalar}; -use base::dimension::{Dim, DimMul, DimName, DimProd}; -use base::constraint::{AreMultipliable, DimEq, SameNumberOfColumns, SameNumberOfRows, - ShapeConstraint}; -use base::storage::{ContiguousStorageMut, Storage, StorageMut}; use base::allocator::{Allocator, SameShapeAllocator, SameShapeC, SameShapeR}; +use base::constraint::{ + AreMultipliable, DimEq, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint, +}; +use base::dimension::{Dim, DimMul, DimName, DimProd}; +use base::storage::{ContiguousStorageMut, Storage, StorageMut}; +use base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, MatrixSum, Scalar}; /* * @@ -722,9 +724,7 @@ impl> Matrix MatrixMN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let mut res = self.clone_owned(); res.add_scalar_mut(rhs); res @@ -733,9 +733,7 @@ impl> Matrix, - { + where S: StorageMut { for e in self.iter_mut() { *e += rhs } @@ -783,7 +781,8 @@ impl> Matri #[inline] pub fn amin(&self) -> N { let mut it = self.iter(); - let mut min = it.next() + let mut min = it + .next() .expect("amin: empty matrices not supported.") .abs(); diff --git a/src/base/properties.rs b/src/base/properties.rs index 266d22b0..7e501575 100644 --- a/src/base/properties.rs +++ b/src/base/properties.rs @@ -100,8 +100,7 @@ impl> Matrix { } impl> SquareMatrix -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Checks that this matrix is orthogonal and has a determinant equal to 1. #[inline] diff --git a/src/base/scalar.rs b/src/base/scalar.rs index ca6da510..47e3019c 100644 --- a/src/base/scalar.rs +++ b/src/base/scalar.rs @@ -1,6 +1,6 @@ +use std::any::Any; use std::any::TypeId; use std::fmt::Debug; -use std::any::Any; /// The basic scalar type for all structures of `nalgebra`. /// diff --git a/src/base/storage.rs b/src/base/storage.rs index 63d10bcb..b96f69d0 100644 --- a/src/base/storage.rs +++ b/src/base/storage.rs @@ -3,10 +3,10 @@ use std::fmt::Debug; use std::mem; -use base::Scalar; +use base::allocator::{Allocator, SameShapeC, SameShapeR}; use base::default_allocator::DefaultAllocator; use base::dimension::{Dim, U1}; -use base::allocator::{Allocator, SameShapeC, SameShapeR}; +use base::Scalar; /* * Aliases for allocation results. @@ -105,13 +105,11 @@ pub unsafe trait Storage: Debug + Sized { /// Builds a matrix data storage that does not contain any reference. fn into_owned(self) -> Owned - where - DefaultAllocator: Allocator; + where DefaultAllocator: Allocator; /// Clones this data storage to one that does not contain any reference. fn clone_owned(&self) -> Owned - where - DefaultAllocator: Allocator; + where DefaultAllocator: Allocator; } /// Trait implemented by matrix data storage that can provide a mutable access to its elements. @@ -177,8 +175,9 @@ pub unsafe trait StorageMut: Storage { /// The storage requirement means that for any value of `i` in `[0, nrows * ncols[`, the value /// `.get_unchecked_linear` returns one of the matrix component. This trait is unsafe because /// failing to comply to this may cause Undefined Behaviors. -pub unsafe trait ContiguousStorage - : Storage { +pub unsafe trait ContiguousStorage: + Storage +{ } /// A mutable matrix storage that is stored contiguously in memory. @@ -186,6 +185,7 @@ pub unsafe trait ContiguousStorage /// The storage requirement means that for any value of `i` in `[0, nrows * ncols[`, the value /// `.get_unchecked_linear` returns one of the matrix component. This trait is unsafe because /// failing to comply to this may cause Undefined Behaviors. -pub unsafe trait ContiguousStorageMut - : ContiguousStorage + StorageMut { +pub unsafe trait ContiguousStorageMut: + ContiguousStorage + StorageMut +{ } diff --git a/src/base/swizzle.rs b/src/base/swizzle.rs index e4ae9c9c..e1908e35 100644 --- a/src/base/swizzle.rs +++ b/src/base/swizzle.rs @@ -1,8 +1,7 @@ -use base::{Scalar, Vector, DimName, Vector2, Vector3}; +use base::{DimName, Scalar, Vector, Vector2, Vector3}; use storage::Storage; use typenum::{self, Cmp, Greater}; - macro_rules! impl_swizzle { ($(where $BaseDim: ident: $name: ident() -> $Result: ident[$($i: expr),*]);*) => { $( @@ -64,4 +63,4 @@ impl_swizzle!( where U2: zzx() -> Vector3[2, 2, 0]; where U2: zzy() -> Vector3[2, 2, 1]; where U2: zzz() -> Vector3[2, 2, 2] -); \ No newline at end of file +); diff --git a/src/base/unit.rs b/src/base/unit.rs index 2b466c04..1c2fa1e2 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -25,9 +25,7 @@ pub struct Unit { #[cfg(feature = "serde-serialize")] impl Serialize for Unit { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.value.serialize(serializer) } } @@ -35,9 +33,7 @@ impl Serialize for Unit { #[cfg(feature = "serde-serialize")] impl<'de, T: Deserialize<'de>> Deserialize<'de> for Unit { fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'de>, - { + where D: Deserializer<'de> { T::deserialize(deserializer).map(|x| Unit { value: x }) } } @@ -143,8 +139,7 @@ impl AsRef for Unit { * */ impl SubsetOf for Unit -where - T::Field: RelativeEq, +where T::Field: RelativeEq { #[inline] fn to_superset(&self) -> T { diff --git a/src/debug/random_orthogonal.rs b/src/debug/random_orthogonal.rs index a699d867..da06805b 100644 --- a/src/debug/random_orthogonal.rs +++ b/src/debug/random_orthogonal.rs @@ -13,15 +13,13 @@ use num_complex::Complex; /// A random orthogonal matrix. #[derive(Clone, Debug)] pub struct RandomOrthogonal -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { m: MatrixN, } impl RandomOrthogonal -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Retrieve the generated matrix. pub fn unwrap(self) -> MatrixN { diff --git a/src/debug/random_sdp.rs b/src/debug/random_sdp.rs index a49f7b80..c78d1fd1 100644 --- a/src/debug/random_sdp.rs +++ b/src/debug/random_sdp.rs @@ -13,15 +13,13 @@ use debug::RandomOrthogonal; /// A random, well-conditioned, symmetric definite-positive matrix. #[derive(Clone, Debug)] pub struct RandomSDP -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { m: MatrixN, } impl RandomSDP -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Retrieve the generated matrix. pub fn unwrap(self) -> MatrixN { diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index 435585f7..34b4cff2 100644 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -6,7 +6,7 @@ use std::io::{Result as IOResult, Write}; use std::marker::PhantomData; #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; @@ -26,27 +26,22 @@ use geometry::{Point, Translation}; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "R: Serialize, + serde(bound( + serialize = "R: Serialize, DefaultAllocator: Allocator, Owned: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "R: Deserialize<'de>, + serde(bound( + deserialize = "R: Deserialize<'de>, DefaultAllocator: Allocator, Owned: Deserialize<'de>" - ) - ) + )) )] pub struct Isometry -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// The pure rotational part of this isometry. pub rotation: R, @@ -54,7 +49,10 @@ where pub translation: Translation, // One dummy private field just to prevent explicit construction. - #[cfg_attr(feature = "serde-serialize", serde(skip_serializing, skip_deserializing))] + #[cfg_attr( + feature = "serde-serialize", + serde(skip_serializing, skip_deserializing) + )] _noconstruct: PhantomData, } @@ -98,12 +96,10 @@ impl> + Copy> Copy for Isome where DefaultAllocator: Allocator, Owned: Copy, -{ -} +{} impl> + Clone> Clone for Isometry -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn clone(&self) -> Self { @@ -112,8 +108,7 @@ where } impl>> Isometry -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Creates a new isometry from its rotational and translational parts. #[inline] @@ -177,8 +172,7 @@ where // This is OK since all constructors of the isometry enforce the Rotation bound already (and // explicit struct construction is prevented by the dummy ZST field). impl Isometry -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Converts this isometry into its equivalent homogeneous transformation matrix. #[inline] @@ -200,8 +194,7 @@ impl Eq for Isometry where R: Rotation> + Eq, DefaultAllocator: Allocator, -{ -} +{} impl PartialEq for Isometry where @@ -251,7 +244,8 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool { + ) -> bool + { self.translation .relative_eq(&other.translation, epsilon, max_relative) && self diff --git a/src/geometry/isometry_alga.rs b/src/geometry/isometry_alga.rs index 58ddc692..6a144550 100644 --- a/src/geometry/isometry_alga.rs +++ b/src/geometry/isometry_alga.rs @@ -1,9 +1,12 @@ -use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, - AbstractQuasigroup, AbstractSemigroup, Id, Identity, Inverse, Multiplicative, - Real}; +use alga::general::{ + AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, + AbstractSemigroup, Id, Identity, Inverse, Multiplicative, Real, +}; use alga::linear::Isometry as AlgaIsometry; -use alga::linear::{AffineTransformation, DirectIsometry, ProjectiveTransformation, Rotation, - Similarity, Transformation}; +use alga::linear::{ + AffineTransformation, DirectIsometry, ProjectiveTransformation, Rotation, Similarity, + Transformation, +}; use base::allocator::Allocator; use base::dimension::DimName; diff --git a/src/geometry/isometry_construction.rs b/src/geometry/isometry_construction.rs index 9d6c88b7..a5299688 100644 --- a/src/geometry/isometry_construction.rs +++ b/src/geometry/isometry_construction.rs @@ -20,8 +20,7 @@ use geometry::{ }; impl>> Isometry -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Creates a new identity isometry. #[inline] @@ -39,8 +38,7 @@ where } impl>> One for Isometry -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Creates a new identity isometry. #[inline] diff --git a/src/geometry/mod.rs b/src/geometry/mod.rs index f125f9ed..af712461 100644 --- a/src/geometry/mod.rs +++ b/src/geometry/mod.rs @@ -4,61 +4,61 @@ mod op_macros; mod point; -mod point_construction; -mod point_alias; -mod point_ops; mod point_alga; +mod point_alias; +mod point_construction; mod point_conversion; mod point_coordinates; +mod point_ops; mod rotation; -mod rotation_construction; -mod rotation_ops; mod rotation_alga; // FIXME: implement Rotation methods. -mod rotation_conversion; mod rotation_alias; +mod rotation_construction; +mod rotation_conversion; +mod rotation_ops; mod rotation_specialization; mod quaternion; -mod quaternion_construction; -mod quaternion_ops; mod quaternion_alga; +mod quaternion_construction; mod quaternion_conversion; mod quaternion_coordinates; +mod quaternion_ops; mod unit_complex; -mod unit_complex_construction; -mod unit_complex_ops; mod unit_complex_alga; +mod unit_complex_construction; mod unit_complex_conversion; +mod unit_complex_ops; mod translation; -mod translation_construction; -mod translation_ops; mod translation_alga; -mod translation_conversion; mod translation_alias; +mod translation_construction; +mod translation_conversion; +mod translation_ops; mod isometry; -mod isometry_construction; -mod isometry_ops; mod isometry_alga; -mod isometry_conversion; mod isometry_alias; +mod isometry_construction; +mod isometry_conversion; +mod isometry_ops; mod similarity; -mod similarity_construction; -mod similarity_ops; mod similarity_alga; -mod similarity_conversion; mod similarity_alias; +mod similarity_construction; +mod similarity_conversion; +mod similarity_ops; mod transform; -mod transform_construction; -mod transform_ops; mod transform_alga; -mod transform_conversion; mod transform_alias; +mod transform_construction; +mod transform_conversion; +mod transform_ops; mod reflection; diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index d76e8c5a..d7e519cc 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -46,9 +46,7 @@ impl PartialEq for Orthographic3 { #[cfg(feature = "serde-serialize")] impl Serialize for Orthographic3 { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.matrix.serialize(serializer) } } @@ -56,9 +54,7 @@ impl Serialize for Orthographic3 { #[cfg(feature = "serde-serialize")] impl<'a, N: Real + Deserialize<'a>> Deserialize<'a> for Orthographic3 { fn deserialize(deserializer: Des) -> Result - where - Des: Deserializer<'a>, - { + where Des: Deserializer<'a> { let matrix = Matrix4::::deserialize(deserializer)?; Ok(Orthographic3::from_matrix_unchecked(matrix)) @@ -238,9 +234,7 @@ impl Orthographic3 { /// Projects a vector. Faster than matrix multiplication. #[inline] pub fn project_vector(&self, p: &Vector) -> Vector3 - where - SB: Storage, - { + where SB: Storage { Vector3::new( self.matrix[(0, 0)] * p[0], self.matrix[(1, 1)] * p[1], @@ -325,8 +319,7 @@ impl Orthographic3 { } impl Distribution> for Standard -where - Standard: Distribution, +where Standard: Distribution { fn sample(&self, r: &mut R) -> Orthographic3 { let left = r.gen(); @@ -342,8 +335,7 @@ where #[cfg(feature = "arbitrary")] impl Arbitrary for Orthographic3 -where - Matrix4: Send, +where Matrix4: Send { fn arbitrary(g: &mut G) -> Self { let left = Arbitrary::arbitrary(g); diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index 1537b327..77642554 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -47,9 +47,7 @@ impl PartialEq for Perspective3 { #[cfg(feature = "serde-serialize")] impl Serialize for Perspective3 { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.matrix.serialize(serializer) } } @@ -57,9 +55,7 @@ impl Serialize for Perspective3 { #[cfg(feature = "serde-serialize")] impl<'a, N: Real + Deserialize<'a>> Deserialize<'a> for Perspective3 { fn deserialize(deserializer: Des) -> Result - where - Des: Deserializer<'a>, - { + where Des: Deserializer<'a> { let matrix = Matrix4::::deserialize(deserializer)?; Ok(Perspective3::from_matrix_unchecked(matrix)) @@ -207,9 +203,7 @@ impl Perspective3 { /// Projects a vector. Faster than matrix multiplication. #[inline] pub fn project_vector(&self, p: &Vector) -> Vector3 - where - SB: Storage, - { + where SB: Storage { let inverse_denom = -N::one() / p[2]; Vector3::new( self.matrix[(0, 0)] * p[0] * inverse_denom, @@ -260,8 +254,7 @@ impl Perspective3 { } impl Distribution> for Standard -where - Standard: Distribution, +where Standard: Distribution { fn sample<'a, R: Rng + ?Sized>(&self, r: &'a mut R) -> Perspective3 { let znear = r.gen(); diff --git a/src/geometry/point.rs b/src/geometry/point.rs index 6b3e4d2d..d24b2cd4 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -7,7 +7,7 @@ use std::hash; use std::io::{Result as IOResult, Write}; #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize, Serializer, Deserializer}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; @@ -21,8 +21,7 @@ use base::{DefaultAllocator, Scalar, VectorN}; #[repr(C)] #[derive(Debug)] pub struct Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// The coordinates of this point, i.e., the shift from the origin. pub coords: VectorN, @@ -42,8 +41,7 @@ impl Copy for Point where DefaultAllocator: Allocator, >::Buffer: Copy, -{ -} +{} impl Clone for Point where @@ -63,9 +61,7 @@ where >::Buffer: Serialize, { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.coords.serialize(serializer) } } @@ -77,9 +73,7 @@ where >::Buffer: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result - where - Des: Deserializer<'a>, - { + where Des: Deserializer<'a> { let coords = VectorN::::deserialize(deserializer)?; Ok(Point::from_coordinates(coords)) @@ -108,8 +102,7 @@ where } impl Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Clones this point into one that owns its data. #[inline] @@ -219,7 +212,8 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool { + ) -> bool + { self.coords .relative_eq(&other.coords, epsilon, max_relative) } @@ -241,15 +235,10 @@ where } } -impl Eq for Point -where - DefaultAllocator: Allocator, -{ -} +impl Eq for Point where DefaultAllocator: Allocator {} impl PartialEq for Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn eq(&self, right: &Self) -> bool { @@ -258,8 +247,7 @@ where } impl PartialOrd for Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn partial_cmp(&self, other: &Self) -> Option { @@ -293,8 +281,7 @@ where * */ impl fmt::Display for Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { try!(write!(f, "{{")); diff --git a/src/geometry/point_alga.rs b/src/geometry/point_alga.rs index e3bb32e0..42a1088a 100644 --- a/src/geometry/point_alga.rs +++ b/src/geometry/point_alga.rs @@ -1,9 +1,9 @@ use alga::general::{Field, JoinSemilattice, Lattice, MeetSemilattice, Real}; use alga::linear::{AffineSpace, EuclideanSpace}; -use base::{DefaultAllocator, Scalar, VectorN}; -use base::dimension::DimName; use base::allocator::Allocator; +use base::dimension::DimName; +use base::{DefaultAllocator, Scalar, VectorN}; use geometry::Point; @@ -16,8 +16,7 @@ where } impl EuclideanSpace for Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Coordinates = VectorN; type Real = N; diff --git a/src/geometry/point_construction.rs b/src/geometry/point_construction.rs index 9d6497b8..c4f6bfc1 100644 --- a/src/geometry/point_construction.rs +++ b/src/geometry/point_construction.rs @@ -13,8 +13,7 @@ use base::{DefaultAllocator, Scalar, VectorN}; use geometry::Point; impl Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Creates a new point with uninitialized coordinates. #[inline] @@ -25,9 +24,7 @@ where /// Creates a new point with all coordinates equal to zero. #[inline] pub fn origin() -> Self - where - N: Zero, - { + where N: Zero { Self::from_coordinates(VectorN::from_element(N::zero())) } @@ -63,8 +60,7 @@ where * */ impl Bounded for Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn max_value() -> Self { diff --git a/src/geometry/point_ops.rs b/src/geometry/point_ops.rs index 1ea8413a..03b07c39 100644 --- a/src/geometry/point_ops.rs +++ b/src/geometry/point_ops.rs @@ -19,8 +19,7 @@ use geometry::Point; * */ impl Index for Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Output = N; @@ -31,8 +30,7 @@ where } impl IndexMut for Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn index_mut(&mut self, i: usize) -> &mut Self::Output { @@ -46,8 +44,7 @@ where * */ impl Neg for Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Output = Point; @@ -58,8 +55,7 @@ where } impl<'a, N: Scalar + ClosedNeg, D: DimName> Neg for &'a Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Output = Point; diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index ccfd6af0..6fb70d2b 100644 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -8,7 +8,7 @@ use std::io::{Result as IOResult, Write}; #[cfg(feature = "serde-serialize")] use base::storage::Owned; #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize, Serializer, Deserializer}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; @@ -32,8 +32,7 @@ pub struct Quaternion { #[cfg(feature = "abomonation-serialize")] impl Abomonation for Quaternion -where - Vector4: Abomonation, +where Vector4: Abomonation { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.coords.entomb(writer) @@ -75,26 +74,20 @@ impl Clone for Quaternion { #[cfg(feature = "serde-serialize")] impl Serialize for Quaternion -where - Owned: Serialize, +where Owned: Serialize { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.coords.serialize(serializer) } } #[cfg(feature = "serde-serialize")] impl<'a, N: Real> Deserialize<'a> for Quaternion -where - Owned: Deserialize<'a>, +where Owned: Deserialize<'a> { fn deserialize(deserializer: Des) -> Result - where - Des: Deserializer<'a>, - { + where Des: Deserializer<'a> { let coords = Vector4::::deserialize(deserializer)?; Ok(Quaternion::from_vector(coords)) @@ -337,7 +330,8 @@ impl> RelativeEq for Quaternion { other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool { + ) -> bool + { self.as_vector().relative_eq(other.as_vector(), epsilon, max_relative) || // Account for the double-covering of S², i.e. q = -q self.as_vector().iter().zip(other.as_vector().iter()).all(|(a, b)| a.relative_eq(&-*b, epsilon, max_relative)) @@ -457,9 +451,11 @@ impl UnitQuaternion { /// is not well-defined). #[inline] pub fn slerp(&self, other: &UnitQuaternion, t: N) -> UnitQuaternion { - Unit::new_unchecked( - Quaternion::from_vector(Unit::new_unchecked(self.coords).slerp(&Unit::new_unchecked(other.coords), t).unwrap()) - ) + Unit::new_unchecked(Quaternion::from_vector( + Unit::new_unchecked(self.coords) + .slerp(&Unit::new_unchecked(other.coords), t) + .unwrap(), + )) } /// Computes the spherical linear interpolation between two unit quaternions or returns `None` @@ -478,8 +474,10 @@ impl UnitQuaternion { other: &UnitQuaternion, t: N, epsilon: N, - ) -> Option> { - Unit::new_unchecked(self.coords).try_slerp(&Unit::new_unchecked(other.coords), t, epsilon) + ) -> Option> + { + Unit::new_unchecked(self.coords) + .try_slerp(&Unit::new_unchecked(other.coords), t, epsilon) .map(|q| Unit::new_unchecked(Quaternion::from_vector(q.unwrap()))) } @@ -659,7 +657,8 @@ impl> RelativeEq for UnitQuaternion { other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool { + ) -> bool + { self.as_ref() .relative_eq(other.as_ref(), epsilon, max_relative) } diff --git a/src/geometry/quaternion_alga.rs b/src/geometry/quaternion_alga.rs index 44fa5143..4b926560 100644 --- a/src/geometry/quaternion_alga.rs +++ b/src/geometry/quaternion_alga.rs @@ -1,11 +1,15 @@ use num::Zero; -use alga::general::{AbstractGroup, AbstractGroupAbelian, AbstractLoop, AbstractMagma, - AbstractModule, AbstractMonoid, AbstractQuasigroup, AbstractSemigroup, - Additive, Id, Identity, Inverse, Module, Multiplicative, Real}; -use alga::linear::{AffineTransformation, DirectIsometry, FiniteDimVectorSpace, Isometry, - NormedSpace, OrthogonalTransformation, ProjectiveTransformation, Rotation, - Similarity, Transformation, VectorSpace}; +use alga::general::{ + AbstractGroup, AbstractGroupAbelian, AbstractLoop, AbstractMagma, AbstractModule, + AbstractMonoid, AbstractQuasigroup, AbstractSemigroup, Additive, Id, Identity, Inverse, Module, + Multiplicative, Real, +}; +use alga::linear::{ + AffineTransformation, DirectIsometry, FiniteDimVectorSpace, Isometry, NormedSpace, + OrthogonalTransformation, ProjectiveTransformation, Rotation, Similarity, Transformation, + VectorSpace, +}; use base::{Vector3, Vector4}; use geometry::{Point3, Quaternion, UnitQuaternion}; diff --git a/src/geometry/quaternion_construction.rs b/src/geometry/quaternion_construction.rs index be2c64c7..5daa0a3f 100644 --- a/src/geometry/quaternion_construction.rs +++ b/src/geometry/quaternion_construction.rs @@ -44,9 +44,7 @@ impl Quaternion { #[inline] // FIXME: take a reference to `vector`? pub fn from_parts(scalar: N, vector: Vector) -> Self - where - SB: Storage, - { + where SB: Storage { Self::new(scalar, vector[0], vector[1], vector[2]) } @@ -55,9 +53,7 @@ impl Quaternion { /// Note that `axis` is assumed to be a unit vector. // FIXME: take a reference to `axis`? pub fn from_polar_decomposition(scale: N, theta: N, axis: Unit>) -> Self - where - SB: Storage, - { + where SB: Storage { let rot = UnitQuaternion::::from_axis_angle(&axis, theta * ::convert(2.0f64)); rot.unwrap() * scale @@ -90,8 +86,7 @@ impl Zero for Quaternion { } impl Distribution> for Standard -where - Standard: Distribution, +where Standard: Distribution { #[inline] fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> Quaternion { @@ -101,8 +96,7 @@ where #[cfg(feature = "arbitrary")] impl Arbitrary for Quaternion -where - Owned: Send, +where Owned: Send { #[inline] fn arbitrary(g: &mut G) -> Self { @@ -126,9 +120,7 @@ impl UnitQuaternion { /// (the rotation angle). #[inline] pub fn from_axis_angle(axis: &Unit>, angle: N) -> Self - where - SB: Storage, - { + where SB: Storage { let (sang, cang) = (angle / ::convert(2.0f64)).sin_cos(); let q = Quaternion::from_parts(cang, axis.as_ref() * sang); @@ -360,9 +352,7 @@ impl UnitQuaternion { /// If `axisangle` has a magnitude smaller than `N::default_epsilon()`, this returns the identity rotation. #[inline] pub fn new(axisangle: Vector) -> Self - where - SB: Storage, - { + where SB: Storage { let two: N = ::convert(2.0f64); let q = Quaternion::::from_parts(N::zero(), axisangle / two).exp(); Self::new_unchecked(q) @@ -373,9 +363,7 @@ impl UnitQuaternion { /// If `axisangle` has a magnitude smaller than `eps`, this returns the identity rotation. #[inline] pub fn new_eps(axisangle: Vector, eps: N) -> Self - where - SB: Storage, - { + where SB: Storage { let two: N = ::convert(2.0f64); let q = Quaternion::::from_parts(N::zero(), axisangle / two).exp_eps(eps); Self::new_unchecked(q) @@ -387,9 +375,7 @@ impl UnitQuaternion { /// Same as `Self::new(axisangle)`. #[inline] pub fn from_scaled_axis(axisangle: Vector) -> Self - where - SB: Storage, - { + where SB: Storage { Self::new(axisangle) } @@ -399,9 +385,7 @@ impl UnitQuaternion { /// Same as `Self::new(axisangle)`. #[inline] pub fn from_scaled_axis_eps(axisangle: Vector, eps: N) -> Self - where - SB: Storage, - { + where SB: Storage { Self::new_eps(axisangle, eps) } } @@ -414,8 +398,7 @@ impl One for UnitQuaternion { } impl Distribution> for Standard -where - OpenClosed01: Distribution, +where OpenClosed01: Distribution { /// Generate a uniformly distributed random rotation quaternion. #[inline] diff --git a/src/geometry/quaternion_ops.rs b/src/geometry/quaternion_ops.rs index b6144226..498a0def 100644 --- a/src/geometry/quaternion_ops.rs +++ b/src/geometry/quaternion_ops.rs @@ -50,15 +50,16 @@ * */ -use std::ops::{Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, - SubAssign}; +use std::ops::{ + Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign, +}; use alga::general::Real; -use base::{DefaultAllocator, Unit, Vector, Vector3}; -use base::storage::Storage; use base::allocator::Allocator; use base::dimension::{U1, U3, U4}; +use base::storage::Storage; +use base::{DefaultAllocator, Unit, Vector, Vector3}; use geometry::{Point3, Quaternion, Rotation, UnitQuaternion}; diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index 0ceaa73b..72bbe3c5 100644 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -6,7 +6,7 @@ use std::hash; use std::io::{Result as IOResult, Write}; #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize, Serializer, Deserializer}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[cfg(feature = "serde-serialize")] use base::storage::Owned; @@ -24,8 +24,7 @@ use base::{DefaultAllocator, MatrixN, Scalar}; #[repr(C)] #[derive(Debug)] pub struct Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { matrix: MatrixN, } @@ -44,8 +43,7 @@ impl Copy for Rotation where DefaultAllocator: Allocator, >::Buffer: Copy, -{ -} +{} impl Clone for Rotation where @@ -86,9 +84,7 @@ where Owned: Serialize, { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.matrix.serialize(serializer) } } @@ -100,9 +96,7 @@ where Owned: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result - where - Des: Deserializer<'a>, - { + where Des: Deserializer<'a> { let matrix = MatrixN::::deserialize(deserializer)?; Ok(Rotation::from_matrix_unchecked(matrix)) @@ -110,8 +104,7 @@ where } impl Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// A reference to the underlying matrix representation of this rotation. #[inline] @@ -187,15 +180,10 @@ where } } -impl Eq for Rotation -where - DefaultAllocator: Allocator, -{ -} +impl Eq for Rotation where DefaultAllocator: Allocator {} impl PartialEq for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn eq(&self, right: &Rotation) -> bool { @@ -239,7 +227,8 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool { + ) -> bool + { self.matrix .relative_eq(&other.matrix, epsilon, max_relative) } diff --git a/src/geometry/rotation_alga.rs b/src/geometry/rotation_alga.rs index 17e92bbf..4f02bbae 100644 --- a/src/geometry/rotation_alga.rs +++ b/src/geometry/rotation_alga.rs @@ -1,12 +1,15 @@ -use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, - AbstractQuasigroup, AbstractSemigroup, Id, Identity, Inverse, Multiplicative, - Real}; -use alga::linear::{self, AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation, - ProjectiveTransformation, Similarity, Transformation}; +use alga::general::{ + AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, + AbstractSemigroup, Id, Identity, Inverse, Multiplicative, Real, +}; +use alga::linear::{ + self, AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation, + ProjectiveTransformation, Similarity, Transformation, +}; -use base::{DefaultAllocator, VectorN}; -use base::dimension::DimName; use base::allocator::Allocator; +use base::dimension::DimName; +use base::{DefaultAllocator, VectorN}; use geometry::{Point, Rotation}; @@ -16,8 +19,7 @@ use geometry::{Point, Rotation}; * */ impl Identity for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn identity() -> Self { @@ -26,8 +28,7 @@ where } impl Inverse for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn inverse(&self) -> Self { @@ -41,8 +42,7 @@ where } impl AbstractMagma for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn operate(&self, rhs: &Self) -> Self { @@ -71,8 +71,7 @@ impl_multiplicative_structures!( * */ impl Transformation> for Rotation -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { #[inline] fn transform_point(&self, pt: &Point) -> Point { @@ -86,8 +85,7 @@ where } impl ProjectiveTransformation> for Rotation -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { #[inline] fn inverse_transform_point(&self, pt: &Point) -> Point { @@ -101,8 +99,7 @@ where } impl AffineTransformation> for Rotation -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { type Rotation = Self; type NonUniformScaling = Id; @@ -145,8 +142,7 @@ where } impl Similarity> for Rotation -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { type Scaling = Id; @@ -178,8 +174,7 @@ marker_impl!(Isometry, DirectIsometry, OrthogonalTransformation); /// Subgroups of the n-dimensional rotation group `SO(n)`. impl linear::Rotation> for Rotation -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { #[inline] fn powf(&self, _: N) -> Option { diff --git a/src/geometry/rotation_construction.rs b/src/geometry/rotation_construction.rs index 14fa28b3..54cfc3c7 100644 --- a/src/geometry/rotation_construction.rs +++ b/src/geometry/rotation_construction.rs @@ -2,9 +2,9 @@ use num::{One, Zero}; use alga::general::{ClosedAdd, ClosedMul}; -use base::{DefaultAllocator, MatrixN, Scalar}; -use base::dimension::DimName; use base::allocator::Allocator; +use base::dimension::DimName; +use base::{DefaultAllocator, MatrixN, Scalar}; use geometry::Rotation; diff --git a/src/geometry/rotation_ops.rs b/src/geometry/rotation_ops.rs index 419830f2..344d6b3f 100644 --- a/src/geometry/rotation_ops.rs +++ b/src/geometry/rotation_ops.rs @@ -17,22 +17,21 @@ * Matrix ×= Rotation */ -use std::ops::{Div, DivAssign, Index, Mul, MulAssign}; use num::{One, Zero}; +use std::ops::{Div, DivAssign, Index, Mul, MulAssign}; use alga::general::{ClosedAdd, ClosedMul}; -use base::{DefaultAllocator, Matrix, MatrixMN, Scalar, Unit, Vector, VectorN}; -use base::dimension::{Dim, DimName, U1}; -use base::constraint::{AreMultipliable, ShapeConstraint}; -use base::storage::Storage; use base::allocator::Allocator; +use base::constraint::{AreMultipliable, ShapeConstraint}; +use base::dimension::{Dim, DimName, U1}; +use base::storage::Storage; +use base::{DefaultAllocator, Matrix, MatrixMN, Scalar, Unit, Vector, VectorN}; use geometry::{Point, Rotation}; impl Index<(usize, usize)> for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Output = N; diff --git a/src/geometry/rotation_specialization.rs b/src/geometry/rotation_specialization.rs index bdd8212f..e4e97ac4 100644 --- a/src/geometry/rotation_specialization.rs +++ b/src/geometry/rotation_specialization.rs @@ -5,7 +5,7 @@ use quickcheck::{Arbitrary, Gen}; use alga::general::Real; use num::Zero; -use rand::distributions::{Distribution, Standard, OpenClosed01}; +use rand::distributions::{Distribution, OpenClosed01, Standard}; use rand::Rng; use std::ops::Neg; @@ -99,8 +99,7 @@ impl Rotation2 { } impl Distribution> for Standard -where - OpenClosed01: Distribution, +where OpenClosed01: Distribution { /// Generate a uniformly distributed random rotation. #[inline] @@ -111,8 +110,7 @@ where #[cfg(feature = "arbitrary")] impl Arbitrary for Rotation2 -where - Owned: Send, +where Owned: Send { #[inline] fn arbitrary(g: &mut G) -> Self { @@ -144,9 +142,7 @@ impl Rotation3 { /// Builds a 3D rotation matrix from an axis and a rotation angle. pub fn from_axis_angle(axis: &Unit>, angle: N) -> Self - where - SB: Storage, - { + where SB: Storage { if angle.is_zero() { Self::identity() } else { @@ -327,7 +323,7 @@ impl Rotation3 { pub fn angle(&self) -> N { ((self.matrix()[(0, 0)] + self.matrix()[(1, 1)] + self.matrix()[(2, 2)] - N::one()) / ::convert(2.0)) - .acos() + .acos() } /// The rotation axis. Returns `None` if the rotation angle is zero or PI. @@ -382,8 +378,7 @@ impl Rotation3 { } impl Distribution> for Standard -where - OpenClosed01: Distribution, +where OpenClosed01: Distribution { /// Generate a uniformly distributed random rotation. #[inline] @@ -396,9 +391,15 @@ where let theta = N::two_pi() * rng.sample(OpenClosed01); let (ts, tc) = theta.sin_cos(); let a = MatrixN::::new( - tc, ts, N::zero(), - -ts, tc, N::zero(), - N::zero(), N::zero(), N::one() + tc, + ts, + N::zero(), + -ts, + tc, + N::zero(), + N::zero(), + N::zero(), + N::one(), ); // Compute a random rotation *of* Z diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index c29a0209..bb04b43e 100644 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -5,7 +5,7 @@ use std::hash; use std::io::{Result as IOResult, Write}; #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; @@ -25,29 +25,24 @@ use geometry::{Isometry, Point, Translation}; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "N: Serialize, + serde(bound( + serialize = "N: Serialize, R: Serialize, DefaultAllocator: Allocator, Owned: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "N: Deserialize<'de>, + serde(bound( + deserialize = "N: Deserialize<'de>, R: Deserialize<'de>, DefaultAllocator: Allocator, Owned: Deserialize<'de>" - ) - ) + )) )] pub struct Similarity -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// The part of this similarity that does not include the scaling factor. pub isometry: Isometry, @@ -89,12 +84,10 @@ impl> + Copy> Copy for Simil where DefaultAllocator: Allocator, Owned: Copy, -{ -} +{} impl> + Clone> Clone for Similarity -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn clone(&self) -> Self { @@ -113,7 +106,8 @@ where translation: Translation, rotation: R, scaling: N, - ) -> Similarity { + ) -> Similarity + { Similarity::from_isometry(Isometry::from_parts(translation, rotation), scaling) } @@ -251,8 +245,7 @@ where // This is OK since all constructors of the isometry enforce the Rotation bound already (and // explicit struct construction is prevented by the private scaling factor). impl Similarity -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Converts this similarity into its equivalent homogeneous transformation matrix. #[inline] @@ -276,8 +269,7 @@ impl Eq for Similarity where R: Rotation> + Eq, DefaultAllocator: Allocator, -{ -} +{} impl PartialEq for Similarity where @@ -327,7 +319,8 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool { + ) -> bool + { self.isometry .relative_eq(&other.isometry, epsilon, max_relative) && self diff --git a/src/geometry/similarity_alga.rs b/src/geometry/similarity_alga.rs index 8ad0e674..c416cad8 100644 --- a/src/geometry/similarity_alga.rs +++ b/src/geometry/similarity_alga.rs @@ -1,11 +1,13 @@ -use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, - AbstractQuasigroup, AbstractSemigroup, Identity, Inverse, Multiplicative, Real}; -use alga::linear::{AffineTransformation, ProjectiveTransformation, Rotation, Transformation}; +use alga::general::{ + AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, + AbstractSemigroup, Identity, Inverse, Multiplicative, Real, +}; use alga::linear::Similarity as AlgaSimilarity; +use alga::linear::{AffineTransformation, ProjectiveTransformation, Rotation, Transformation}; -use base::{DefaultAllocator, VectorN}; -use base::dimension::DimName; use base::allocator::Allocator; +use base::dimension::DimName; +use base::{DefaultAllocator, VectorN}; use geometry::{Point, Similarity, Translation}; diff --git a/src/geometry/similarity_ops.rs b/src/geometry/similarity_ops.rs index 92e77d08..7469c4cd 100644 --- a/src/geometry/similarity_ops.rs +++ b/src/geometry/similarity_ops.rs @@ -3,9 +3,9 @@ use std::ops::{Div, DivAssign, Mul, MulAssign}; use alga::general::Real; use alga::linear::Rotation as AlgaRotation; -use base::{DefaultAllocator, VectorN}; -use base::dimension::{DimName, U1, U3, U4}; use base::allocator::Allocator; +use base::dimension::{DimName, U1, U3, U4}; +use base::{DefaultAllocator, VectorN}; use geometry::{Isometry, Point, Rotation, Similarity, Translation, UnitQuaternion}; diff --git a/src/geometry/transform.rs b/src/geometry/transform.rs index 78a53829..f62e0f24 100644 --- a/src/geometry/transform.rs +++ b/src/geometry/transform.rs @@ -3,14 +3,14 @@ use std::fmt::Debug; use std::marker::PhantomData; #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize, Serializer, Deserializer}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; use alga::general::Real; -use base::{DefaultAllocator, MatrixN}; +use base::allocator::Allocator; use base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; use base::storage::Owned; -use base::allocator::Allocator; +use base::{DefaultAllocator, MatrixN}; /// Trait implemented by phantom types identifying the projective transformation type. /// @@ -56,18 +56,15 @@ where /// Tag representing the most general (not necessarily inversible) `Transform` type. #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum TGeneral { -} +pub enum TGeneral {} /// Tag representing the most general inversible `Transform` type. #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum TProjective { -} +pub enum TProjective {} /// Tag representing an affine `Transform`. Its bottom-row is equal to `(0, 0 ... 0, 1)`. #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub enum TAffine { -} +pub enum TAffine {} impl TCategory for TGeneral { #[inline] @@ -104,7 +101,8 @@ impl TCategory for TAffine { DefaultAllocator: Allocator, { let last = D::dim() - 1; - mat.is_invertible() && mat[(last, last)] == N::one() + mat.is_invertible() + && mat[(last, last)] == N::one() && (0..last).all(|i| mat[(last, i)].is_zero()) } } @@ -157,8 +155,7 @@ super_tcategory_impl!( #[repr(C)] #[derive(Debug)] pub struct Transform, C: TCategory> -where - DefaultAllocator: Allocator, DimNameSum>, +where DefaultAllocator: Allocator, DimNameSum> { matrix: MatrixN>, _phantom: PhantomData, @@ -177,12 +174,10 @@ impl + Copy, C: TCategory> Copy for Transform, DimNameSum>, Owned, DimNameSum>: Copy, -{ -} +{} impl, C: TCategory> Clone for Transform -where - DefaultAllocator: Allocator, DimNameSum>, +where DefaultAllocator: Allocator, DimNameSum> { #[inline] fn clone(&self) -> Self { @@ -197,9 +192,7 @@ where Owned, DimNameSum>: Serialize, { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.matrix.serialize(serializer) } } @@ -211,24 +204,18 @@ where Owned, DimNameSum>: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result - where - Des: Deserializer<'a>, - { + where Des: Deserializer<'a> { let matrix = MatrixN::>::deserialize(deserializer)?; Ok(Transform::from_matrix_unchecked(matrix)) } } -impl, C: TCategory> Eq for Transform -where - DefaultAllocator: Allocator, DimNameSum>, -{ -} +impl, C: TCategory> Eq for Transform where DefaultAllocator: Allocator, DimNameSum> +{} impl, C: TCategory> PartialEq for Transform -where - DefaultAllocator: Allocator, DimNameSum>, +where DefaultAllocator: Allocator, DimNameSum> { #[inline] fn eq(&self, right: &Self) -> bool { @@ -237,8 +224,7 @@ where } impl, C: TCategory> Transform -where - DefaultAllocator: Allocator, DimNameSum>, +where DefaultAllocator: Allocator, DimNameSum> { /// Creates a new transformation from the given homogeneous matrix. The transformation category /// of `Self` is not checked to be verified by the given matrix. @@ -310,9 +296,7 @@ where /// category (it may not be invertible). #[inline] pub fn inverse(self) -> Transform - where - C: SubTCategoryOf, - { + where C: SubTCategoryOf { // FIXME: specialize for TAffine? Transform::from_matrix_unchecked(self.matrix.try_inverse().unwrap()) } @@ -328,16 +312,13 @@ where /// `TGeneral` category (it may not be invertible). #[inline] pub fn inverse_mut(&mut self) - where - C: SubTCategoryOf, - { + where C: SubTCategoryOf { let _ = self.matrix.try_inverse_mut(); } } impl> Transform -where - DefaultAllocator: Allocator, DimNameSum>, +where DefaultAllocator: Allocator, DimNameSum> { /// A mutable reference to underlying matrix. Use `.matrix_mut_unchecked` instead if this /// transformation category is not `TGeneral`. diff --git a/src/geometry/transform_alga.rs b/src/geometry/transform_alga.rs index d01e61bf..652da373 100644 --- a/src/geometry/transform_alga.rs +++ b/src/geometry/transform_alga.rs @@ -1,10 +1,12 @@ -use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, - AbstractQuasigroup, AbstractSemigroup, Identity, Inverse, Multiplicative, Real}; +use alga::general::{ + AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, + AbstractSemigroup, Identity, Inverse, Multiplicative, Real, +}; use alga::linear::{ProjectiveTransformation, Transformation}; -use base::{DefaultAllocator, VectorN}; -use base::dimension::{DimNameAdd, DimNameSum, U1}; use base::allocator::Allocator; +use base::dimension::{DimNameAdd, DimNameSum, U1}; +use base::{DefaultAllocator, VectorN}; use geometry::{Point, SubTCategoryOf, TCategory, TProjective, Transform}; diff --git a/src/geometry/transform_construction.rs b/src/geometry/transform_construction.rs index 6d5bb135..0ab9e5f2 100644 --- a/src/geometry/transform_construction.rs +++ b/src/geometry/transform_construction.rs @@ -2,15 +2,14 @@ use num::One; use alga::general::Real; -use base::{DefaultAllocator, MatrixN}; -use base::dimension::{DimNameAdd, DimNameSum, U1}; use base::allocator::Allocator; +use base::dimension::{DimNameAdd, DimNameSum, U1}; +use base::{DefaultAllocator, MatrixN}; use geometry::{TCategory, Transform}; impl, C: TCategory> Transform -where - DefaultAllocator: Allocator, DimNameSum>, +where DefaultAllocator: Allocator, DimNameSum> { /// Creates a new identity transform. #[inline] @@ -20,8 +19,7 @@ where } impl, C: TCategory> One for Transform -where - DefaultAllocator: Allocator, DimNameSum>, +where DefaultAllocator: Allocator, DimNameSum> { /// Creates a new identity transform. #[inline] diff --git a/src/geometry/transform_ops.rs b/src/geometry/transform_ops.rs index 0e2b4826..6fc4ec32 100644 --- a/src/geometry/transform_ops.rs +++ b/src/geometry/transform_ops.rs @@ -3,13 +3,14 @@ use std::ops::{Div, DivAssign, Index, IndexMut, Mul, MulAssign}; use alga::general::{ClosedAdd, ClosedMul, Real, SubsetOf}; -use base::{DefaultAllocator, MatrixN, Scalar, VectorN}; use base::allocator::Allocator; use base::dimension::{DimName, DimNameAdd, DimNameSum, U1, U3, U4}; +use base::{DefaultAllocator, MatrixN, Scalar, VectorN}; -use geometry::{Isometry, Point, Rotation, Similarity, SubTCategoryOf, SuperTCategoryOf, TAffine, - TCategory, TCategoryMul, TGeneral, TProjective, Transform, Translation, - UnitQuaternion}; +use geometry::{ + Isometry, Point, Rotation, Similarity, SubTCategoryOf, SuperTCategoryOf, TAffine, TCategory, + TCategoryMul, TGeneral, TProjective, Transform, Translation, UnitQuaternion, +}; /* * diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index ddf7651c..e7821cca 100644 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -6,7 +6,7 @@ use std::hash; use std::io::{Result as IOResult, Write}; #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize, Serializer, Deserializer}; +use serde::{Deserialize, Deserializer, Serialize, Serializer}; #[cfg(feature = "abomonation-serialize")] use abomonation::Abomonation; @@ -22,8 +22,7 @@ use base::{DefaultAllocator, MatrixN, Scalar, VectorN}; #[repr(C)] #[derive(Debug)] pub struct Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// The translation coordinates, i.e., how much is added to a point's coordinates when it is /// translated. @@ -44,8 +43,7 @@ impl Copy for Translation where DefaultAllocator: Allocator, Owned: Copy, -{ -} +{} impl Clone for Translation where @@ -86,9 +84,7 @@ where Owned: Serialize, { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.vector.serialize(serializer) } } @@ -100,9 +96,7 @@ where Owned: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result - where - Des: Deserializer<'a>, - { + where Des: Deserializer<'a> { let matrix = VectorN::::deserialize(deserializer)?; Ok(Translation::from_vector(matrix)) @@ -110,8 +104,7 @@ where } impl Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Creates a new translation from the given vector. #[inline] @@ -122,9 +115,7 @@ where /// Inverts `self`. #[inline] pub fn inverse(&self) -> Translation - where - N: ClosedNeg, - { + where N: ClosedNeg { Translation::from_vector(-&self.vector) } @@ -146,22 +137,15 @@ where /// Inverts `self` in-place. #[inline] pub fn inverse_mut(&mut self) - where - N: ClosedNeg, - { + where N: ClosedNeg { self.vector.neg_mut() } } -impl Eq for Translation -where - DefaultAllocator: Allocator, -{ -} +impl Eq for Translation where DefaultAllocator: Allocator {} impl PartialEq for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn eq(&self, right: &Translation) -> bool { @@ -203,7 +187,8 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool { + ) -> bool + { self.vector .relative_eq(&other.vector, epsilon, max_relative) } @@ -231,8 +216,7 @@ where * */ impl fmt::Display for Translation -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let precision = f.precision().unwrap_or(3); diff --git a/src/geometry/translation_alga.rs b/src/geometry/translation_alga.rs index 296d6e17..896e7a8b 100644 --- a/src/geometry/translation_alga.rs +++ b/src/geometry/translation_alga.rs @@ -1,13 +1,16 @@ -use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, - AbstractQuasigroup, AbstractSemigroup, Id, Identity, Inverse, Multiplicative, - Real}; -use alga::linear::{AffineTransformation, DirectIsometry, Isometry, ProjectiveTransformation, - Similarity, Transformation}; +use alga::general::{ + AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, + AbstractSemigroup, Id, Identity, Inverse, Multiplicative, Real, +}; use alga::linear::Translation as AlgaTranslation; +use alga::linear::{ + AffineTransformation, DirectIsometry, Isometry, ProjectiveTransformation, Similarity, + Transformation, +}; -use base::{DefaultAllocator, VectorN}; -use base::dimension::DimName; use base::allocator::Allocator; +use base::dimension::DimName; +use base::{DefaultAllocator, VectorN}; use geometry::{Point, Translation}; @@ -17,8 +20,7 @@ use geometry::{Point, Translation}; * */ impl Identity for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn identity() -> Self { @@ -27,8 +29,7 @@ where } impl Inverse for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn inverse(&self) -> Self { @@ -42,8 +43,7 @@ where } impl AbstractMagma for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn operate(&self, rhs: &Self) -> Self { @@ -72,8 +72,7 @@ impl_multiplicative_structures!( * */ impl Transformation> for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn transform_point(&self, pt: &Point) -> Point { @@ -87,8 +86,7 @@ where } impl ProjectiveTransformation> for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn inverse_transform_point(&self, pt: &Point) -> Point { @@ -102,8 +100,7 @@ where } impl AffineTransformation> for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Rotation = Id; type NonUniformScaling = Id; @@ -146,8 +143,7 @@ where } impl Similarity> for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Scaling = Id; @@ -178,8 +174,7 @@ marker_impl!(Isometry, DirectIsometry); /// Subgroups of the n-dimensional translation group `T(n)`. impl AlgaTranslation> for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn to_vector(&self) -> VectorN { diff --git a/src/geometry/translation_construction.rs b/src/geometry/translation_construction.rs index df97872a..cc67507d 100644 --- a/src/geometry/translation_construction.rs +++ b/src/geometry/translation_construction.rs @@ -16,8 +16,7 @@ use base::{DefaultAllocator, Scalar, VectorN}; use geometry::Translation; impl Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Creates a new square identity rotation of the given `dimension`. #[inline] @@ -27,8 +26,7 @@ where } impl One for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn one() -> Self { diff --git a/src/geometry/translation_ops.rs b/src/geometry/translation_ops.rs index 639affdd..d124c763 100644 --- a/src/geometry/translation_ops.rs +++ b/src/geometry/translation_ops.rs @@ -2,10 +2,10 @@ use std::ops::{Div, DivAssign, Mul, MulAssign}; use alga::general::{ClosedAdd, ClosedSub}; -use base::{DefaultAllocator, Scalar}; -use base::dimension::{DimName, U1}; -use base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; use base::allocator::{Allocator, SameShapeAllocator}; +use base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; +use base::dimension::{DimName, U1}; +use base::{DefaultAllocator, Scalar}; use geometry::{Point, Translation}; diff --git a/src/geometry/unit_complex.rs b/src/geometry/unit_complex.rs index 9e91b1f1..63ddf80f 100644 --- a/src/geometry/unit_complex.rs +++ b/src/geometry/unit_complex.rs @@ -155,7 +155,8 @@ impl RelativeEq for UnitComplex { other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool { + ) -> bool + { self.re.relative_eq(&other.re, epsilon, max_relative) && self.im.relative_eq(&other.im, epsilon, max_relative) } diff --git a/src/geometry/unit_complex_alga.rs b/src/geometry/unit_complex_alga.rs index bfc99202..59b11903 100644 --- a/src/geometry/unit_complex_alga.rs +++ b/src/geometry/unit_complex_alga.rs @@ -1,12 +1,15 @@ -use alga::general::{AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, - AbstractQuasigroup, AbstractSemigroup, Id, Identity, Inverse, Multiplicative, - Real}; -use alga::linear::{AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation, - ProjectiveTransformation, Rotation, Similarity, Transformation}; +use alga::general::{ + AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup, + AbstractSemigroup, Id, Identity, Inverse, Multiplicative, Real, +}; +use alga::linear::{ + AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation, + ProjectiveTransformation, Rotation, Similarity, Transformation, +}; -use base::{DefaultAllocator, Vector2}; use base::allocator::Allocator; use base::dimension::U2; +use base::{DefaultAllocator, Vector2}; use geometry::{Point2, UnitComplex}; /* @@ -56,8 +59,7 @@ impl_structures!( ); impl Transformation> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn transform_point(&self, pt: &Point2) -> Point2 { @@ -71,8 +73,7 @@ where } impl ProjectiveTransformation> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn inverse_transform_point(&self, pt: &Point2) -> Point2 { @@ -88,8 +89,7 @@ where } impl AffineTransformation> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Rotation = Self; type NonUniformScaling = Id; @@ -132,8 +132,7 @@ where } impl Similarity> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Scaling = Id; @@ -163,8 +162,7 @@ macro_rules! marker_impl( marker_impl!(Isometry, DirectIsometry, OrthogonalTransformation); impl Rotation> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn powf(&self, n: N) -> Option { diff --git a/src/geometry/unit_complex_construction.rs b/src/geometry/unit_complex_construction.rs index 4b020789..8e4f45fe 100644 --- a/src/geometry/unit_complex_construction.rs +++ b/src/geometry/unit_complex_construction.rs @@ -3,7 +3,7 @@ use quickcheck::{Arbitrary, Gen}; use num::One; use num_complex::Complex; -use rand::distributions::{Distribution, Standard, OpenClosed01}; +use rand::distributions::{Distribution, OpenClosed01, Standard}; use rand::Rng; use alga::general::Real; @@ -71,9 +71,7 @@ impl UnitComplex { /// Builds the unit complex number from the corresponding 2D rotation matrix. #[inline] pub fn from_rotation_matrix(rotmat: &Rotation) -> Self - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { Self::new_unchecked(Complex::new(rotmat[(0, 0)], rotmat[(1, 0)])) } @@ -152,8 +150,7 @@ impl One for UnitComplex { } impl Distribution> for Standard -where - OpenClosed01: Distribution, +where OpenClosed01: Distribution { /// Generate a uniformly distributed random `UnitComplex`. #[inline] diff --git a/src/geometry/unit_complex_ops.rs b/src/geometry/unit_complex_ops.rs index 3d737f75..6456733c 100644 --- a/src/geometry/unit_complex_ops.rs +++ b/src/geometry/unit_complex_ops.rs @@ -332,8 +332,7 @@ impl<'b, N: Real> DivAssign<&'b UnitComplex> for UnitComplex { // UnitComplex ×= Rotation impl MulAssign> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn mul_assign(&mut self, rhs: Rotation) { @@ -342,8 +341,7 @@ where } impl<'b, N: Real> MulAssign<&'b Rotation> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn mul_assign(&mut self, rhs: &'b Rotation) { @@ -353,8 +351,7 @@ where // UnitComplex ÷= Rotation impl DivAssign> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn div_assign(&mut self, rhs: Rotation) { @@ -363,8 +360,7 @@ where } impl<'b, N: Real> DivAssign<&'b Rotation> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn div_assign(&mut self, rhs: &'b Rotation) { @@ -374,8 +370,7 @@ where // Rotation ×= UnitComplex impl MulAssign> for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn mul_assign(&mut self, rhs: UnitComplex) { @@ -384,8 +379,7 @@ where } impl<'b, N: Real> MulAssign<&'b UnitComplex> for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn mul_assign(&mut self, rhs: &'b UnitComplex) { @@ -395,8 +389,7 @@ where // Rotation ÷= UnitComplex impl DivAssign> for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn div_assign(&mut self, rhs: UnitComplex) { @@ -405,8 +398,7 @@ where } impl<'b, N: Real> DivAssign<&'b UnitComplex> for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn div_assign(&mut self, rhs: &'b UnitComplex) { diff --git a/src/lib.rs b/src/lib.rs index b46e2dd6..b8b807a8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -218,9 +218,7 @@ pub fn dimension() -> usize { /// The range must not be empty. #[inline] pub fn wrap(mut val: T, min: T, max: T) -> T -where - T: Copy + PartialOrd + AdditiveGroup, -{ +where T: Copy + PartialOrd + AdditiveGroup { assert!(min < max, "Invalid wrapping bounds."); let width = max - min; diff --git a/src/linalg/balancing.rs b/src/linalg/balancing.rs index 54c325cf..5db113ba 100644 --- a/src/linalg/balancing.rs +++ b/src/linalg/balancing.rs @@ -13,9 +13,7 @@ use base::{DefaultAllocator, MatrixN, VectorN}; /// /// See https://arxiv.org/pdf/1401.5766.pdf pub fn balance_parlett_reinsch(m: &mut MatrixN) -> VectorN -where - DefaultAllocator: Allocator + Allocator, -{ +where DefaultAllocator: Allocator + Allocator { assert!(m.is_square(), "Unable to balance a non-square matrix."); let dim = m.data.shape().0; @@ -67,9 +65,7 @@ where /// Computes in-place `D * m * D.inverse()`, where `D` is the matrix with diagonal `d`. pub fn unbalance(m: &mut MatrixN, d: &VectorN) -where - DefaultAllocator: Allocator + Allocator, -{ +where DefaultAllocator: Allocator + Allocator { assert!(m.is_square(), "Unable to unbalance a non-square matrix."); assert_eq!(m.nrows(), d.len(), "Unbalancing: mismatched dimensions."); diff --git a/src/linalg/bidiagonal.rs b/src/linalg/bidiagonal.rs index db340a9c..3e73c40f 100644 --- a/src/linalg/bidiagonal.rs +++ b/src/linalg/bidiagonal.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use alga::general::Real; use allocator::Allocator; @@ -15,31 +15,27 @@ use linalg::householder; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DimMinimum: DimSub, + serde(bound( + serialize = "DimMinimum: DimSub, DefaultAllocator: Allocator + Allocator> + Allocator, U1>>, MatrixMN: Serialize, VectorN>: Serialize, VectorN, U1>>: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DimMinimum: DimSub, + serde(bound( + deserialize = "DimMinimum: DimSub, DefaultAllocator: Allocator + Allocator> + Allocator, U1>>, MatrixMN: Deserialize<'de>, VectorN>: Deserialize<'de>, VectorN, U1>>: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct Bidiagonal, C: Dim> @@ -68,8 +64,7 @@ where MatrixMN: Copy, VectorN>: Copy, VectorN, U1>>: Copy, -{ -} +{} impl, C: Dim> Bidiagonal where @@ -217,9 +212,7 @@ where // FIXME: code duplication with householder::assemble_q. // Except that we are returning a rectangular matrix here. pub fn u(&self) -> MatrixMN> - where - DefaultAllocator: Allocator>, - { + where DefaultAllocator: Allocator> { let (nrows, ncols) = self.uv.data.shape(); let mut res = Matrix::identity_generic(nrows, nrows.min(ncols)); @@ -240,9 +233,7 @@ where /// Computes the orthogonal matrix `V` of this `U * D * V` decomposition. pub fn v_t(&self) -> MatrixMN, C> - where - DefaultAllocator: Allocator, C>, - { + where DefaultAllocator: Allocator, C> { let (nrows, ncols) = self.uv.data.shape(); let min_nrows_ncols = nrows.min(ncols); diff --git a/src/linalg/cholesky.rs b/src/linalg/cholesky.rs index e6592227..c0868c1a 100644 --- a/src/linalg/cholesky.rs +++ b/src/linalg/cholesky.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use alga::general::Real; @@ -13,26 +13,21 @@ use storage::{Storage, StorageMut}; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator, + serde(bound( + serialize = "DefaultAllocator: Allocator, MatrixN: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator, + serde(bound( + deserialize = "DefaultAllocator: Allocator, MatrixN: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct Cholesky -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { chol: MatrixN, } @@ -41,12 +36,10 @@ impl Copy for Cholesky where DefaultAllocator: Allocator, MatrixN: Copy, -{ -} +{} impl> Cholesky -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Attempts to compute the Cholesky decomposition of `matrix`. /// @@ -152,8 +145,7 @@ where } impl, S: Storage> SquareMatrix -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Attempts to compute the Cholesky decomposition of this matrix. /// diff --git a/src/linalg/determinant.rs b/src/linalg/determinant.rs index 56a21c38..100a21e7 100644 --- a/src/linalg/determinant.rs +++ b/src/linalg/determinant.rs @@ -13,9 +13,7 @@ impl, S: Storage> SquareMatrix N - where - DefaultAllocator: Allocator + Allocator<(usize, usize), D>, - { + where DefaultAllocator: Allocator + Allocator<(usize, usize), D> { assert!( self.is_square(), "Unable to compute the determinant of a non-square matrix." diff --git a/src/linalg/full_piv_lu.rs b/src/linalg/full_piv_lu.rs index 85079b17..9bab4ee9 100644 --- a/src/linalg/full_piv_lu.rs +++ b/src/linalg/full_piv_lu.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use alga::general::Real; use allocator::Allocator; @@ -15,30 +15,25 @@ use linalg::PermutationSequence; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator + + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, MatrixMN: Serialize, PermutationSequence>: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, MatrixMN: Deserialize<'de>, PermutationSequence>: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct FullPivLU, C: Dim> -where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, +where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> { lu: MatrixMN, p: PermutationSequence>, @@ -50,12 +45,10 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, MatrixMN: Copy, PermutationSequence>: Copy, -{ -} +{} impl, C: Dim> FullPivLU -where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, +where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> { /// Computes the LU decomposition with full pivoting of `matrix`. /// @@ -113,9 +106,7 @@ where /// The lower triangular matrix of this decomposition. #[inline] pub fn l(&self) -> MatrixMN> - where - DefaultAllocator: Allocator>, - { + where DefaultAllocator: Allocator> { let (nrows, ncols) = self.lu.data.shape(); let mut m = self.lu.columns_generic(0, nrows.min(ncols)).into_owned(); m.fill_upper_triangle(N::zero(), 1); @@ -126,9 +117,7 @@ where /// The upper triangular matrix of this decomposition. #[inline] pub fn u(&self) -> MatrixMN, C> - where - DefaultAllocator: Allocator, C>, - { + where DefaultAllocator: Allocator, C> { let (nrows, ncols) = self.lu.data.shape(); self.lu.rows_generic(0, nrows.min(ncols)).upper_triangle() } @@ -155,8 +144,7 @@ where MatrixMN, C>, PermutationSequence>, ) - where - DefaultAllocator: Allocator> + Allocator, C>, + where DefaultAllocator: Allocator> + Allocator, C> { // Use reallocation for either l or u. let l = self.l(); @@ -169,8 +157,7 @@ where } impl> FullPivLU -where - DefaultAllocator: Allocator + Allocator<(usize, usize), D>, +where DefaultAllocator: Allocator + Allocator<(usize, usize), D> { /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. /// @@ -275,8 +262,7 @@ where } impl, C: Dim, S: Storage> Matrix -where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, +where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> { /// Computes the LU decomposition with full pivoting of `matrix`. /// diff --git a/src/linalg/hessenberg.rs b/src/linalg/hessenberg.rs index a831cc2e..783055a3 100644 --- a/src/linalg/hessenberg.rs +++ b/src/linalg/hessenberg.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use alga::general::Real; use allocator::Allocator; @@ -14,30 +14,25 @@ use linalg::householder; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator + + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator>, MatrixN: Serialize, VectorN>: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator>, MatrixN: Deserialize<'de>, VectorN>: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct Hessenberg> -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { hess: MatrixN, subdiag: VectorN>, @@ -48,12 +43,10 @@ where DefaultAllocator: Allocator + Allocator>, MatrixN: Copy, VectorN>: Copy, -{ -} +{} impl> Hessenberg -where - DefaultAllocator: Allocator + Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator + Allocator> { /// Computes the Hessenberg decomposition using householder reflections. pub fn new(hess: MatrixN) -> Self { @@ -100,9 +93,7 @@ where /// hessenberg matrix. #[inline] pub fn unpack(self) -> (MatrixN, MatrixN) - where - ShapeConstraint: DimEq>, - { + where ShapeConstraint: DimEq> { let q = self.q(); (q, self.unpack_h()) @@ -111,9 +102,7 @@ where /// Retrieves the upper trapezoidal submatrix `H` of this decomposition. #[inline] pub fn unpack_h(mut self) -> MatrixN - where - ShapeConstraint: DimEq>, - { + where ShapeConstraint: DimEq> { let dim = self.hess.nrows(); self.hess.fill_lower_triangle(N::zero(), 2); self.hess @@ -128,9 +117,7 @@ where /// This is less efficient than `.unpack_h()` as it allocates a new matrix. #[inline] pub fn h(&self) -> MatrixN - where - ShapeConstraint: DimEq>, - { + where ShapeConstraint: DimEq> { let dim = self.hess.nrows(); let mut res = self.hess.clone(); res.fill_lower_triangle(N::zero(), 2); @@ -151,8 +138,7 @@ where } impl, S: Storage> SquareMatrix -where - DefaultAllocator: Allocator + Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator + Allocator> { /// Computes the Hessenberg decomposition of this matrix using householder reflections. pub fn hessenberg(self) -> Hessenberg { diff --git a/src/linalg/householder.rs b/src/linalg/householder.rs index 22799adb..09c23091 100644 --- a/src/linalg/householder.rs +++ b/src/linalg/householder.rs @@ -105,9 +105,7 @@ pub fn clear_row_unchecked( /// matrices. #[doc(hidden)] pub fn assemble_q(m: &MatrixN) -> MatrixN -where - DefaultAllocator: Allocator, -{ +where DefaultAllocator: Allocator { assert!(m.is_square()); let dim = m.data.shape().0; diff --git a/src/linalg/inverse.rs b/src/linalg/inverse.rs index e00f4b8b..08cebd2a 100644 --- a/src/linalg/inverse.rs +++ b/src/linalg/inverse.rs @@ -1,9 +1,9 @@ use alga::general::Real; -use base::{DefaultAllocator, MatrixN, SquareMatrix}; +use base::allocator::Allocator; use base::dimension::Dim; use base::storage::{Storage, StorageMut}; -use base::allocator::Allocator; +use base::{DefaultAllocator, MatrixN, SquareMatrix}; use linalg::lu; @@ -11,9 +11,7 @@ impl> SquareMatrix { /// Attempts to invert this matrix. #[inline] pub fn try_inverse(self) -> Option> - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let mut me = self.into_owned(); if me.try_inverse_mut() { Some(me) @@ -28,9 +26,7 @@ impl> SquareMatrix { /// inversion fails. #[inline] pub fn try_inverse_mut(&mut self) -> bool - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { assert!(self.is_square(), "Unable to invert a non-square matrix."); let dim = self.shape().0; @@ -129,52 +125,84 @@ where let m = m.data.as_slice(); out[(0, 0)] = m[5] * m[10] * m[15] - m[5] * m[11] * m[14] - m[9] * m[6] * m[15] - + m[9] * m[7] * m[14] + m[13] * m[6] * m[11] - m[13] * m[7] * m[10]; + + m[9] * m[7] * m[14] + + m[13] * m[6] * m[11] + - m[13] * m[7] * m[10]; out[(1, 0)] = -m[1] * m[10] * m[15] + m[1] * m[11] * m[14] + m[9] * m[2] * m[15] - - m[9] * m[3] * m[14] - m[13] * m[2] * m[11] + m[13] * m[3] * m[10]; + - m[9] * m[3] * m[14] + - m[13] * m[2] * m[11] + + m[13] * m[3] * m[10]; out[(2, 0)] = m[1] * m[6] * m[15] - m[1] * m[7] * m[14] - m[5] * m[2] * m[15] - + m[5] * m[3] * m[14] + m[13] * m[2] * m[7] - m[13] * m[3] * m[6]; + + m[5] * m[3] * m[14] + + m[13] * m[2] * m[7] + - m[13] * m[3] * m[6]; out[(3, 0)] = -m[1] * m[6] * m[11] + m[1] * m[7] * m[10] + m[5] * m[2] * m[11] - - m[5] * m[3] * m[10] - m[9] * m[2] * m[7] + m[9] * m[3] * m[6]; + - m[5] * m[3] * m[10] + - m[9] * m[2] * m[7] + + m[9] * m[3] * m[6]; out[(0, 1)] = -m[4] * m[10] * m[15] + m[4] * m[11] * m[14] + m[8] * m[6] * m[15] - - m[8] * m[7] * m[14] - m[12] * m[6] * m[11] + m[12] * m[7] * m[10]; + - m[8] * m[7] * m[14] + - m[12] * m[6] * m[11] + + m[12] * m[7] * m[10]; out[(1, 1)] = m[0] * m[10] * m[15] - m[0] * m[11] * m[14] - m[8] * m[2] * m[15] - + m[8] * m[3] * m[14] + m[12] * m[2] * m[11] - m[12] * m[3] * m[10]; + + m[8] * m[3] * m[14] + + m[12] * m[2] * m[11] + - m[12] * m[3] * m[10]; out[(2, 1)] = -m[0] * m[6] * m[15] + m[0] * m[7] * m[14] + m[4] * m[2] * m[15] - - m[4] * m[3] * m[14] - m[12] * m[2] * m[7] + m[12] * m[3] * m[6]; + - m[4] * m[3] * m[14] + - m[12] * m[2] * m[7] + + m[12] * m[3] * m[6]; out[(3, 1)] = m[0] * m[6] * m[11] - m[0] * m[7] * m[10] - m[4] * m[2] * m[11] - + m[4] * m[3] * m[10] + m[8] * m[2] * m[7] - m[8] * m[3] * m[6]; + + m[4] * m[3] * m[10] + + m[8] * m[2] * m[7] + - m[8] * m[3] * m[6]; out[(0, 2)] = m[4] * m[9] * m[15] - m[4] * m[11] * m[13] - m[8] * m[5] * m[15] - + m[8] * m[7] * m[13] + m[12] * m[5] * m[11] - m[12] * m[7] * m[9]; + + m[8] * m[7] * m[13] + + m[12] * m[5] * m[11] + - m[12] * m[7] * m[9]; out[(1, 2)] = -m[0] * m[9] * m[15] + m[0] * m[11] * m[13] + m[8] * m[1] * m[15] - - m[8] * m[3] * m[13] - m[12] * m[1] * m[11] + m[12] * m[3] * m[9]; + - m[8] * m[3] * m[13] + - m[12] * m[1] * m[11] + + m[12] * m[3] * m[9]; out[(2, 2)] = m[0] * m[5] * m[15] - m[0] * m[7] * m[13] - m[4] * m[1] * m[15] - + m[4] * m[3] * m[13] + m[12] * m[1] * m[7] - m[12] * m[3] * m[5]; + + m[4] * m[3] * m[13] + + m[12] * m[1] * m[7] + - m[12] * m[3] * m[5]; out[(0, 3)] = -m[4] * m[9] * m[14] + m[4] * m[10] * m[13] + m[8] * m[5] * m[14] - - m[8] * m[6] * m[13] - m[12] * m[5] * m[10] + m[12] * m[6] * m[9]; + - m[8] * m[6] * m[13] + - m[12] * m[5] * m[10] + + m[12] * m[6] * m[9]; out[(3, 2)] = -m[0] * m[5] * m[11] + m[0] * m[7] * m[9] + m[4] * m[1] * m[11] - - m[4] * m[3] * m[9] - m[8] * m[1] * m[7] + m[8] * m[3] * m[5]; + - m[4] * m[3] * m[9] + - m[8] * m[1] * m[7] + + m[8] * m[3] * m[5]; out[(1, 3)] = m[0] * m[9] * m[14] - m[0] * m[10] * m[13] - m[8] * m[1] * m[14] - + m[8] * m[2] * m[13] + m[12] * m[1] * m[10] - m[12] * m[2] * m[9]; + + m[8] * m[2] * m[13] + + m[12] * m[1] * m[10] + - m[12] * m[2] * m[9]; out[(2, 3)] = -m[0] * m[5] * m[14] + m[0] * m[6] * m[13] + m[4] * m[1] * m[14] - - m[4] * m[2] * m[13] - m[12] * m[1] * m[6] + m[12] * m[2] * m[5]; + - m[4] * m[2] * m[13] + - m[12] * m[1] * m[6] + + m[12] * m[2] * m[5]; out[(3, 3)] = m[0] * m[5] * m[10] - m[0] * m[6] * m[9] - m[4] * m[1] * m[10] - + m[4] * m[2] * m[9] + m[8] * m[1] * m[6] - m[8] * m[2] * m[5]; + + m[4] * m[2] * m[9] + + m[8] * m[1] * m[6] + - m[8] * m[2] * m[5]; let det = m[0] * out[(0, 0)] + m[1] * out[(0, 1)] + m[2] * out[(0, 2)] + m[3] * out[(0, 3)]; diff --git a/src/linalg/lu.rs b/src/linalg/lu.rs index 7707242b..66c2743e 100644 --- a/src/linalg/lu.rs +++ b/src/linalg/lu.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use alga::general::{Field, Real}; use allocator::{Allocator, Reallocator}; @@ -15,30 +15,25 @@ use linalg::PermutationSequence; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator + + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, MatrixMN: Serialize, PermutationSequence>: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, MatrixMN: Deserialize<'de>, PermutationSequence>: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct LU, C: Dim> -where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, +where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> { lu: MatrixMN, p: PermutationSequence>, @@ -49,8 +44,7 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, MatrixMN: Copy, PermutationSequence>: Copy, -{ -} +{} /// Performs a LU decomposition to overwrite `out` with the inverse of `matrix`. /// @@ -93,8 +87,7 @@ where } impl, C: Dim> LU -where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, +where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> { /// Computes the LU decomposition with partial (row) pivoting of `matrix`. pub fn new(mut matrix: MatrixMN) -> Self { @@ -136,9 +129,7 @@ where /// The lower triangular matrix of this decomposition. #[inline] pub fn l(&self) -> MatrixMN> - where - DefaultAllocator: Allocator>, - { + where DefaultAllocator: Allocator> { let (nrows, ncols) = self.lu.data.shape(); let mut m = self.lu.columns_generic(0, nrows.min(ncols)).into_owned(); m.fill_upper_triangle(N::zero(), 1); @@ -153,9 +144,7 @@ where MatrixMN>, PermutationSequence>, ) - where - DefaultAllocator: Reallocator>, - { + where DefaultAllocator: Reallocator> { let (nrows, ncols) = self.lu.data.shape(); let mut m = self.lu.resize_generic(nrows, nrows.min(ncols), N::zero()); m.fill_upper_triangle(N::zero(), 1); @@ -166,9 +155,7 @@ where /// The lower triangular matrix of this decomposition. #[inline] pub fn l_unpack(self) -> MatrixMN> - where - DefaultAllocator: Reallocator>, - { + where DefaultAllocator: Reallocator> { let (nrows, ncols) = self.lu.data.shape(); let mut m = self.lu.resize_generic(nrows, nrows.min(ncols), N::zero()); m.fill_upper_triangle(N::zero(), 1); @@ -179,9 +166,7 @@ where /// The upper triangular matrix of this decomposition. #[inline] pub fn u(&self) -> MatrixMN, C> - where - DefaultAllocator: Allocator, C>, - { + where DefaultAllocator: Allocator, C> { let (nrows, ncols) = self.lu.data.shape(); self.lu.rows_generic(0, nrows.min(ncols)).upper_triangle() } @@ -201,11 +186,9 @@ where MatrixMN>, MatrixMN, C>, ) - where - DefaultAllocator: Allocator> + where DefaultAllocator: Allocator> + Allocator, C> - + Reallocator>, - { + + Reallocator> { // Use reallocation for either l or u. let u = self.u(); let (l, p) = self.l_unpack_with_p(); @@ -215,8 +198,7 @@ where } impl> LU -where - DefaultAllocator: Allocator + Allocator<(usize, usize), D>, +where DefaultAllocator: Allocator + Allocator<(usize, usize), D> { /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. /// @@ -387,8 +369,7 @@ pub fn gauss_step_swap( } impl, C: Dim, S: Storage> Matrix -where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, +where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> { /// Computes the LU decomposition with partial (row) pivoting of `matrix`. pub fn lu(self) -> LU { diff --git a/src/linalg/mod.rs b/src/linalg/mod.rs index 04f7e3f8..4418b283 100644 --- a/src/linalg/mod.rs +++ b/src/linalg/mod.rs @@ -1,35 +1,35 @@ //! [Reexported at the root of this crate.] Factorization of real matrices. -mod solve; -mod determinant; -mod inverse; -pub mod householder; -pub mod givens; pub mod balancing; +mod bidiagonal; +mod cholesky; +mod determinant; +mod full_piv_lu; +pub mod givens; +mod hessenberg; +pub mod householder; +mod inverse; +mod lu; mod permutation_sequence; mod qr; -mod hessenberg; -mod bidiagonal; -mod symmetric_tridiagonal; -mod cholesky; -mod lu; -mod full_piv_lu; mod schur; +mod solve; mod svd; mod symmetric_eigen; +mod symmetric_tridiagonal; //// FIXME: Not complete enough for publishing. //// This handles only cases where each eigenvalue has multiplicity one. // mod eigen; -pub use self::permutation_sequence::*; -pub use self::qr::*; -pub use self::hessenberg::*; pub use self::bidiagonal::*; pub use self::cholesky::*; -pub use self::lu::*; pub use self::full_piv_lu::*; +pub use self::hessenberg::*; +pub use self::lu::*; +pub use self::permutation_sequence::*; +pub use self::qr::*; pub use self::schur::*; pub use self::svd::*; -pub use self::symmetric_tridiagonal::*; pub use self::symmetric_eigen::*; +pub use self::symmetric_tridiagonal::*; diff --git a/src/linalg/permutation_sequence.rs b/src/linalg/permutation_sequence.rs index b6818751..ac58d857 100644 --- a/src/linalg/permutation_sequence.rs +++ b/src/linalg/permutation_sequence.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use alga::general::ClosedNeg; use num::One; @@ -15,26 +15,21 @@ use storage::StorageMut; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator<(usize, usize), D>, + serde(bound( + serialize = "DefaultAllocator: Allocator<(usize, usize), D>, VectorN<(usize, usize), D>: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator<(usize, usize), D>, + serde(bound( + deserialize = "DefaultAllocator: Allocator<(usize, usize), D>, VectorN<(usize, usize), D>: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct PermutationSequence -where - DefaultAllocator: Allocator<(usize, usize), D>, +where DefaultAllocator: Allocator<(usize, usize), D> { len: usize, ipiv: VectorN<(usize, usize), D>, @@ -44,12 +39,10 @@ impl Copy for PermutationSequence where DefaultAllocator: Allocator<(usize, usize), D>, VectorN<(usize, usize), D>: Copy, -{ -} +{} impl PermutationSequence -where - DefaultAllocator: Allocator<(usize, usize), D>, +where DefaultAllocator: Allocator<(usize, usize), D> { /// Creates a new statically-allocated sequence of `D` identity permutations. #[inline] @@ -60,8 +53,7 @@ where #[cfg(any(feature = "std", feature = "alloc"))] impl PermutationSequence -where - DefaultAllocator: Allocator<(usize, usize), Dynamic>, +where DefaultAllocator: Allocator<(usize, usize), Dynamic> { /// Creates a new dynamically-allocated sequence of `n` identity permutations. #[inline] @@ -71,8 +63,7 @@ where } impl PermutationSequence -where - DefaultAllocator: Allocator<(usize, usize), D>, +where DefaultAllocator: Allocator<(usize, usize), D> { /// Creates a new sequence of D identity permutations. #[inline] @@ -102,9 +93,7 @@ where /// Applies this sequence of permutations to the rows of `rhs`. #[inline] pub fn permute_rows(&self, rhs: &mut Matrix) - where - S2: StorageMut, - { + where S2: StorageMut { for i in self.ipiv.rows_range(..self.len).iter() { rhs.swap_rows(i.0, i.1) } @@ -112,8 +101,10 @@ where /// Applies this sequence of permutations in reverse to the rows of `rhs`. #[inline] - pub fn inv_permute_rows(&self, rhs: &mut Matrix) - where + pub fn inv_permute_rows( + &self, + rhs: &mut Matrix, + ) where S2: StorageMut, { for i in 0..self.len { @@ -124,8 +115,10 @@ where /// Applies this sequence of permutations to the columns of `rhs`. #[inline] - pub fn permute_columns(&self, rhs: &mut Matrix) - where + pub fn permute_columns( + &self, + rhs: &mut Matrix, + ) where S2: StorageMut, { for i in self.ipiv.rows_range(..self.len).iter() { diff --git a/src/linalg/qr.rs b/src/linalg/qr.rs index 0dea31a7..81f72269 100644 --- a/src/linalg/qr.rs +++ b/src/linalg/qr.rs @@ -1,32 +1,39 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use alga::general::Real; +use allocator::{Allocator, Reallocator}; use base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Unit, VectorN}; +use constraint::{SameNumberOfRows, ShapeConstraint}; use dimension::{Dim, DimMin, DimMinimum, U1}; use storage::{Storage, StorageMut}; -use allocator::{Allocator, Reallocator}; -use constraint::{SameNumberOfRows, ShapeConstraint}; -use linalg::householder; use geometry::Reflection; +use linalg::householder; /// The QR decomposition of a general matrix. #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] -#[cfg_attr(feature = "serde-serialize", - serde(bound(serialize = "DefaultAllocator: Allocator + +#[cfg_attr( + feature = "serde-serialize", + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator>, MatrixMN: Serialize, - VectorN>: Serialize")))] -#[cfg_attr(feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator + + VectorN>: Serialize" + )) +)] +#[cfg_attr( + feature = "serde-serialize", + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator>, MatrixMN: Deserialize<'de>, - VectorN>: Deserialize<'de>")))] + VectorN>: Deserialize<'de>" + )) +)] #[derive(Clone, Debug)] pub struct QR, C: Dim> -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { qr: MatrixMN, diag: VectorN>, @@ -37,12 +44,10 @@ where DefaultAllocator: Allocator + Allocator>, MatrixMN: Copy, VectorN>: Copy, -{ -} +{} impl, C: Dim> QR -where - DefaultAllocator: Allocator + Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator + Allocator> { /// Computes the QR decomposition using householder reflections. pub fn new(mut matrix: MatrixMN) -> Self { @@ -101,9 +106,7 @@ where /// Computes the orthogonal matrix `Q` of this decomposition. pub fn q(&self) -> MatrixMN> - where - DefaultAllocator: Allocator>, - { + where DefaultAllocator: Allocator> { let (nrows, ncols) = self.qr.data.shape(); // NOTE: we could build the identity matrix and call q_mul on it. @@ -132,8 +135,8 @@ where ) where DimMinimum: DimMin>, - DefaultAllocator: Allocator> - + Reallocator, C>, + DefaultAllocator: + Allocator> + Reallocator, C>, { (self.q(), self.unpack_r()) } @@ -146,9 +149,7 @@ where /// Multiplies the provided matrix by the transpose of the `Q` matrix of this decomposition. pub fn q_tr_mul(&self, rhs: &mut Matrix) // FIXME: do we need a static constraint on the number of rows of rhs? - where - S2: StorageMut, - { + where S2: StorageMut { let dim = self.diag.len(); for i in 0..dim { @@ -162,8 +163,7 @@ where } impl> QR -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. /// @@ -295,8 +295,7 @@ where } impl, C: Dim, S: Storage> Matrix -where - DefaultAllocator: Allocator + Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator + Allocator> { /// Computes the QR decomposition of this matrix. pub fn qr(self) -> QR { diff --git a/src/linalg/schur.rs b/src/linalg/schur.rs index fd385512..a3bd5404 100644 --- a/src/linalg/schur.rs +++ b/src/linalg/schur.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use alga::general::Real; use num_complex::Complex; @@ -19,26 +19,21 @@ use linalg::Hessenberg; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator, + serde(bound( + serialize = "DefaultAllocator: Allocator, MatrixN: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator, + serde(bound( + deserialize = "DefaultAllocator: Allocator, MatrixN: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct RealSchur -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { q: MatrixN, t: MatrixN, @@ -48,8 +43,7 @@ impl Copy for RealSchur where DefaultAllocator: Allocator, MatrixN: Copy, -{ -} +{} impl RealSchur where @@ -91,7 +85,8 @@ where eps: N, max_niter: usize, compute_q: bool, - ) -> Option<(Option>, MatrixN)> { + ) -> Option<(Option>, MatrixN)> + { assert!( m.is_square(), "Unable to compute the eigenvectors and eigenvalues of a non-square matrix." @@ -180,10 +175,10 @@ where { let krows = cmp::min(k + 4, end + 1); let mut work = work.rows_mut(0, krows); - refl.reflect(&mut t.generic_slice_mut( - (k, k), - (U3, Dynamic::new(dim.value() - k)), - )); + refl.reflect( + &mut t + .generic_slice_mut((k, k), (U3, Dynamic::new(dim.value() - k))), + ); refl.reflect_rows( &mut t.generic_slice_mut((0, k), (Dynamic::new(krows), U3)), &mut work, @@ -214,10 +209,9 @@ where { let mut work = work.rows_mut(0, end + 1); - refl.reflect(&mut t.generic_slice_mut( - (m, m), - (U2, Dynamic::new(dim.value() - m)), - )); + refl.reflect( + &mut t.generic_slice_mut((m, m), (U2, Dynamic::new(dim.value() - m))), + ); refl.reflect_rows( &mut t.generic_slice_mut((0, m), (Dynamic::new(end + 1), U2)), &mut work, @@ -236,10 +230,9 @@ where (start, start), (U2, Dynamic::new(dim.value() - start)), )); - rot.rotate_rows(&mut t.generic_slice_mut( - (0, start), - (Dynamic::new(end + 1), U2), - )); + rot.rotate_rows( + &mut t.generic_slice_mut((0, start), (Dynamic::new(end + 1), U2)), + ); t[(end, start)] = N::zero(); if let Some(ref mut q) = q { @@ -297,9 +290,7 @@ where /// Computes the complex eigenvalues of the decomposed matrix. fn do_complex_eigenvalues(t: &MatrixN, out: &mut VectorN, D>) - where - DefaultAllocator: Allocator, D>, - { + where DefaultAllocator: Allocator, D> { let dim = t.nrows(); let mut m = 0; @@ -397,9 +388,7 @@ where /// Computes the complex eigenvalues of the decomposed matrix. pub fn complex_eigenvalues(&self) -> VectorN, D> - where - DefaultAllocator: Allocator, D>, - { + where DefaultAllocator: Allocator, D> { let mut out = unsafe { VectorN::new_uninitialized_generic(self.t.data.shape().0, U1) }; Self::do_complex_eigenvalues(&self.t, &mut out); out @@ -433,9 +422,11 @@ where )); } } - None => if compute_q { - q = Some(MatrixN::identity_generic(dim, dim)); - }, + None => { + if compute_q { + q = Some(MatrixN::identity_generic(dim, dim)); + } + } }; Some((q, m)) @@ -558,7 +549,8 @@ where N::default_epsilon(), 0, false, - ).unwrap(); + ) + .unwrap(); if RealSchur::do_eigenvalues(&schur.1, &mut work) { Some(work) } else { @@ -569,9 +561,7 @@ where /// Computes the eigenvalues of this matrix. pub fn complex_eigenvalues(&self) -> VectorN, D> // FIXME: add balancing? - where - DefaultAllocator: Allocator, D>, - { + where DefaultAllocator: Allocator, D> { let dim = self.data.shape().0; let mut work = unsafe { VectorN::new_uninitialized_generic(dim, U1) }; @@ -581,7 +571,8 @@ where N::default_epsilon(), 0, false, - ).unwrap(); + ) + .unwrap(); let mut eig = unsafe { VectorN::new_uninitialized_generic(dim, U1) }; RealSchur::do_complex_eigenvalues(&schur.1, &mut eig); eig diff --git a/src/linalg/svd.rs b/src/linalg/svd.rs index 43e2946e..88752891 100644 --- a/src/linalg/svd.rs +++ b/src/linalg/svd.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use num_complex::Complex; use std::ops::MulAssign; @@ -20,38 +20,33 @@ use linalg::Bidiagonal; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator + + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator> + Allocator, C> + Allocator>, MatrixMN>: Serialize, MatrixMN, C>: Serialize, VectorN>: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator> + Allocator, C> + Allocator>, MatrixMN>: Deserialize<'de>, MatrixMN, C>: Deserialize<'de>, VectorN>: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct SVD, C: Dim> -where - DefaultAllocator: Allocator, C> +where DefaultAllocator: Allocator, C> + Allocator> - + Allocator>, + + Allocator> { /// The left-singular vectors `U` of this SVD. pub u: Option>>, @@ -69,8 +64,7 @@ where MatrixMN>: Copy, MatrixMN, C>: Copy, VectorN>: Copy, -{ -} +{} impl, C: Dim> SVD where @@ -104,7 +98,8 @@ where compute_v: bool, eps: N, max_niter: usize, - ) -> Option { + ) -> Option + { assert!( matrix.len() != 0, "Cannot compute the SVD of an empty matrix." @@ -292,7 +287,8 @@ where m22: N, compute_u: bool, compute_v: bool, - ) -> (Option>, Vector2, Option>) { + ) -> (Option>, Vector2, Option>) + { let two: N = ::convert(2.0f64); let half: N = ::convert(0.5f64); @@ -347,7 +343,8 @@ where v_t: &mut Option, C>>, end: usize, eps: N, - ) -> (usize, usize) { + ) -> (usize, usize) + { let mut n = end; while n > 0 { @@ -411,7 +408,8 @@ where v_t: &mut Option, C>>, i: usize, end: usize, - ) { + ) + { let mut v = Vector2::new(b.off_diagonal[i], b.diagonal[i + 1]); b.off_diagonal[i] = N::zero(); @@ -445,7 +443,8 @@ where u: &mut Option>>, v_t: &mut Option, C>>, i: usize, - ) { + ) + { let mut v = Vector2::new(b.diagonal[i], b.off_diagonal[i]); b.off_diagonal[i] = N::zero(); @@ -489,7 +488,8 @@ where /// right- and left- singular vectors have not been computed at construction-time. pub fn recompose(self) -> MatrixMN { let mut u = self.u.expect("SVD recomposition: U has not been computed."); - let v_t = self.v_t + let v_t = self + .v_t .expect("SVD recomposition: V^t has not been computed."); for i in 0..self.singular_values.len() { @@ -506,9 +506,7 @@ where /// Panics if the right- and left- singular vectors have not been computed at /// construction-time. pub fn pseudo_inverse(mut self, eps: N) -> MatrixMN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { assert!( eps >= N::zero(), "SVD pseudo inverse: the epsilon must be non-negative." @@ -545,10 +543,12 @@ where eps >= N::zero(), "SVD solve: the epsilon must be non-negative." ); - let u = self.u + let u = self + .u .as_ref() .expect("SVD solve: U has not been computed."); - let v_t = self.v_t + let v_t = self + .v_t .as_ref() .expect("SVD solve: V^t has not been computed."); @@ -603,7 +603,8 @@ where compute_v: bool, eps: N, max_niter: usize, - ) -> Option> { + ) -> Option> + { SVD::try_new(self.into_owned(), compute_u, compute_v, eps, max_niter) } @@ -624,9 +625,7 @@ where /// /// All singular values below `eps` are considered equal to 0. pub fn pseudo_inverse(self, eps: N) -> MatrixMN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { SVD::new(self.clone_owned(), true, true).pseudo_inverse(eps) } } diff --git a/src/linalg/symmetric_eigen.rs b/src/linalg/symmetric_eigen.rs index 1628f4ba..cd455b7c 100644 --- a/src/linalg/symmetric_eigen.rs +++ b/src/linalg/symmetric_eigen.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use num_complex::Complex; use std::ops::MulAssign; @@ -18,30 +18,25 @@ use linalg::SymmetricTridiagonal; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator + + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator, VectorN: Serialize, MatrixN: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator, VectorN: Deserialize<'de>, MatrixN: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct SymmetricEigen -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { /// The eigenvectors of the decomposed matrix. pub eigenvectors: MatrixN, @@ -55,12 +50,10 @@ where DefaultAllocator: Allocator + Allocator, MatrixN: Copy, VectorN: Copy, -{ -} +{} impl SymmetricEigen -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { /// Computes the eigendecomposition of the given symmetric matrix. /// @@ -311,8 +304,7 @@ pub fn wilkinson_shift(tmm: N, tnn: N, tmn: N) -> N { * */ impl, S: Storage> SquareMatrix -where - DefaultAllocator: Allocator + Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator + Allocator> { /// Computes the eigendecomposition of this symmetric matrix. /// diff --git a/src/linalg/symmetric_tridiagonal.rs b/src/linalg/symmetric_tridiagonal.rs index a1af96d0..5ac75b47 100644 --- a/src/linalg/symmetric_tridiagonal.rs +++ b/src/linalg/symmetric_tridiagonal.rs @@ -1,5 +1,5 @@ #[cfg(feature = "serde-serialize")] -use serde::{Serialize, Deserialize}; +use serde::{Deserialize, Serialize}; use alga::general::Real; use allocator::Allocator; @@ -13,30 +13,25 @@ use linalg::householder; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator + + serde(bound( + serialize = "DefaultAllocator: Allocator + Allocator>, MatrixN: Serialize, VectorN>: Serialize" - ) - ) + )) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound( + deserialize = "DefaultAllocator: Allocator + Allocator>, MatrixN: Deserialize<'de>, VectorN>: Deserialize<'de>" - ) - ) + )) )] #[derive(Clone, Debug)] pub struct SymmetricTridiagonal> -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { tri: MatrixN, off_diagonal: VectorN>, @@ -47,12 +42,10 @@ where DefaultAllocator: Allocator + Allocator>, MatrixN: Copy, VectorN>: Copy, -{ -} +{} impl> SymmetricTridiagonal -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { /// Computes the tridiagonalization of the symmetric matrix `m`. /// @@ -105,9 +98,7 @@ where /// Retrieve the orthogonal transformation, diagonal, and off diagonal elements of this /// decomposition. pub fn unpack(self) -> (MatrixN, VectorN, VectorN>) - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let diag = self.diagonal(); let q = self.q(); @@ -116,9 +107,7 @@ where /// Retrieve the diagonal, and off diagonal elements of this decomposition. pub fn unpack_tridiagonal(self) -> (VectorN, VectorN>) - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let diag = self.diagonal(); (diag, self.off_diagonal) @@ -126,17 +115,13 @@ where /// The diagonal components of this decomposition. pub fn diagonal(&self) -> VectorN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { self.tri.diagonal() } /// The off-diagonal components of this decomposition. pub fn off_diagonal(&self) -> &VectorN> - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { &self.off_diagonal } @@ -161,8 +146,7 @@ where } impl, S: Storage> SquareMatrix -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { /// Computes the tridiagonalization of this symmetric matrix. /// diff --git a/tests/core/abomonation.rs b/tests/core/abomonation.rs index ac53716b..be3952cd 100644 --- a/tests/core/abomonation.rs +++ b/tests/core/abomonation.rs @@ -1,9 +1,9 @@ -use rand::random; -use abomonation::{Abomonation, encode, decode}; +use abomonation::{decode, encode, Abomonation}; use na::{ - DMatrix, Matrix3x4, Point3, Translation3, Rotation3, Isometry3, Quaternion, - IsometryMatrix3, Similarity3, SimilarityMatrix3 + DMatrix, Isometry3, IsometryMatrix3, Matrix3x4, Point3, Quaternion, Rotation3, Similarity3, + SimilarityMatrix3, Translation3, }; +use rand::random; #[test] fn abomonate_dmatrix() { @@ -39,7 +39,9 @@ fn assert_encode_and_decode(original_data: T // Encode let mut bytes = Vec::new(); - unsafe { encode(&original_data, &mut bytes); } + unsafe { + encode(&original_data, &mut bytes); + } // Drop the original, so that dangling pointers are revealed by the test drop(original_data); diff --git a/tests/core/blas.rs b/tests/core/blas.rs index e37cb049..00eac3a3 100644 --- a/tests/core/blas.rs +++ b/tests/core/blas.rs @@ -1,7 +1,7 @@ #![cfg(feature = "arbitrary")] +use na::{DMatrix, DVector}; use std::cmp; -use na::{DVector, DMatrix}; quickcheck! { /* diff --git a/tests/core/conversion.rs b/tests/core/conversion.rs index 175c6f2b..f8be8588 100644 --- a/tests/core/conversion.rs +++ b/tests/core/conversion.rs @@ -1,18 +1,13 @@ #![cfg(feature = "arbitrary")] use alga::linear::Transformation; use na::{ - self, + self, Affine3, Isometry3, Matrix2, Matrix2x3, Matrix2x4, Matrix2x5, Matrix2x6, Matrix3, + Matrix3x2, Matrix3x4, Matrix3x5, Matrix3x6, Matrix4, Matrix4x2, Matrix4x3, Matrix4x5, + Matrix4x6, Matrix5, Matrix5x2, Matrix5x3, Matrix5x4, Matrix5x6, Matrix6, Matrix6x2, Matrix6x3, + Matrix6x4, Matrix6x5, Point3, Projective3, Rotation3, RowVector1, RowVector2, RowVector3, + RowVector4, RowVector5, RowVector6, Similarity3, Transform3, Translation3, UnitQuaternion, Vector1, Vector2, Vector3, Vector4, Vector5, Vector6, - RowVector1, RowVector2, RowVector3, RowVector4, RowVector5, RowVector6, - Matrix2, Matrix3, Matrix4, Matrix5, Matrix6, - Matrix2x3, Matrix2x4, Matrix2x5, Matrix2x6, - Matrix3x2, Matrix3x4, Matrix3x5, Matrix3x6, - Matrix4x2, Matrix4x3, Matrix4x5, Matrix4x6, - Matrix5x2, Matrix5x3, Matrix5x4, Matrix5x6, - Matrix6x2, Matrix6x3, Matrix6x4, Matrix6x5, - Point3, Translation3, Isometry3, Similarity3, Affine3, - Projective3, Transform3, Rotation3, UnitQuaternion}; - +}; quickcheck!{ fn translation_conversion(t: Translation3, v: Vector3, p: Point3) -> bool { diff --git a/tests/core/mod.rs b/tests/core/mod.rs index e8bac456..7e1f8591 100644 --- a/tests/core/mod.rs +++ b/tests/core/mod.rs @@ -1,10 +1,10 @@ +#[cfg(feature = "abomonation-serialize")] +mod abomonation; +mod blas; mod conversion; mod edition; mod matrix; mod matrix_slice; -mod blas; -mod serde; -#[cfg(feature = "abomonation-serialize")] -mod abomonation; #[cfg(feature = "mint")] mod mint; +mod serde; diff --git a/tests/core/serde.rs b/tests/core/serde.rs index 14456eac..a65ca8b3 100644 --- a/tests/core/serde.rs +++ b/tests/core/serde.rs @@ -1,20 +1,11 @@ #![cfg(feature = "serde-serialize")] -use serde_json; -use rand; use na::{ - DMatrix, - Matrix3x4, - Point3, - Translation3, - Rotation3, - Isometry3, - IsometryMatrix3, - Similarity3, - SimilarityMatrix3, - Quaternion, - Unit, + DMatrix, Isometry3, IsometryMatrix3, Matrix3x4, Point3, Quaternion, Rotation3, Similarity3, + SimilarityMatrix3, Translation3, Unit, }; +use rand; +use serde_json; macro_rules! test_serde( ($($test: ident, $ty: ident);* $(;)*) => {$( diff --git a/tests/geometry/isometry.rs b/tests/geometry/isometry.rs index f7226bbf..c72a2475 100644 --- a/tests/geometry/isometry.rs +++ b/tests/geometry/isometry.rs @@ -1,10 +1,10 @@ #![cfg(feature = "arbitrary")] #![allow(non_snake_case)] -use alga::linear::{Transformation, ProjectiveTransformation}; +use alga::linear::{ProjectiveTransformation, Transformation}; use na::{ - Vector3, Point3, Rotation3, Isometry3, Translation3, UnitQuaternion, - Vector2, Point2, Rotation2, Isometry2, Translation2, UnitComplex + Isometry2, Isometry3, Point2, Point3, Rotation2, Rotation3, Translation2, Translation3, + UnitComplex, UnitQuaternion, Vector2, Vector3, }; quickcheck!( diff --git a/tests/geometry/point.rs b/tests/geometry/point.rs index 1b673f92..90c51587 100644 --- a/tests/geometry/point.rs +++ b/tests/geometry/point.rs @@ -1,6 +1,6 @@ #![cfg(feature = "arbitrary")] -use num::Zero; use na::{Point3, Vector3, Vector4}; +use num::Zero; #[test] fn point_ops() { @@ -8,20 +8,20 @@ fn point_ops() { let b = Point3::new(1.0, 2.0, 3.0); let c = Vector3::new(1.0, 2.0, 3.0); - assert_eq!( a - b, Vector3::zero()); + assert_eq!(a - b, Vector3::zero()); assert_eq!(&a - &b, Vector3::zero()); - assert_eq!( a - &b, Vector3::zero()); - assert_eq!(&a - b, Vector3::zero()); + assert_eq!(a - &b, Vector3::zero()); + assert_eq!(&a - b, Vector3::zero()); - assert_eq!( b - c, Point3::origin()); + assert_eq!(b - c, Point3::origin()); assert_eq!(&b - &c, Point3::origin()); - assert_eq!( b - &c, Point3::origin()); - assert_eq!(&b - c, Point3::origin()); + assert_eq!(b - &c, Point3::origin()); + assert_eq!(&b - c, Point3::origin()); - assert_eq!( b + c, 2.0 * a); + assert_eq!(b + c, 2.0 * a); assert_eq!(&b + &c, 2.0 * a); - assert_eq!( b + &c, 2.0 * a); - assert_eq!(&b + c, 2.0 * a); + assert_eq!(b + &c, 2.0 * a); + assert_eq!(&b + c, 2.0 * a); let mut a1 = a; let mut a2 = a; @@ -58,20 +58,19 @@ fn point_coordinates() { #[test] fn point_scale() { - let pt = Point3::new(1, 2, 3); + let pt = Point3::new(1, 2, 3); let expected = Point3::new(10, 20, 30); assert_eq!(pt * 10, expected); assert_eq!(&pt * 10, expected); assert_eq!(10 * pt, expected); assert_eq!(10 * &pt, expected); - } #[test] fn point_vector_sum() { - let pt = Point3::new(1, 2, 3); - let vec = Vector3::new(10, 20, 30); + let pt = Point3::new(1, 2, 3); + let vec = Vector3::new(10, 20, 30); let expected = Point3::new(11, 22, 33); assert_eq!(&pt + &vec, expected); @@ -82,15 +81,13 @@ fn point_vector_sum() { #[test] fn to_homogeneous() { - let a = Point3::new(1.0, 2.0, 3.0); + let a = Point3::new(1.0, 2.0, 3.0); let expected = Vector4::new(1.0, 2.0, 3.0, 1.0); assert_eq!(a.to_homogeneous(), expected); } -quickcheck!( - fn point_sub(pt1: Point3, pt2: Point3) -> bool { - let dpt = &pt2 - &pt1; - relative_eq!(pt2, pt1 + dpt, epsilon = 1.0e-7) - } -); +quickcheck!(fn point_sub(pt1: Point3, pt2: Point3) -> bool { + let dpt = &pt2 - &pt1; + relative_eq!(pt2, pt1 + dpt, epsilon = 1.0e-7) +}); diff --git a/tests/geometry/projection.rs b/tests/geometry/projection.rs index 7be0d49d..17d04a13 100644 --- a/tests/geometry/projection.rs +++ b/tests/geometry/projection.rs @@ -1,9 +1,9 @@ -use na::{Perspective3, Orthographic3}; +use na::{Orthographic3, Perspective3}; #[test] fn perspective_inverse() { let proj = Perspective3::new(800.0 / 600.0, 3.14 / 2.0, 1.0, 1000.0); - let inv = proj.inverse(); + let inv = proj.inverse(); let id = inv * proj.unwrap(); @@ -13,17 +13,16 @@ fn perspective_inverse() { #[test] fn orthographic_inverse() { let proj = Orthographic3::new(1.0, 2.0, -3.0, -2.5, 10.0, 900.0); - let inv = proj.inverse(); + let inv = proj.inverse(); let id = inv * proj.unwrap(); assert!(id.is_identity(1.0e-7)); } - #[cfg(feature = "arbitrary")] mod quickcheck_tests { - use na::{Point3, Perspective3, Orthographic3}; + use na::{Orthographic3, Perspective3, Point3}; quickcheck!{ fn perspective_project_unproject(pt: Point3) -> bool { diff --git a/tests/geometry/quaternion.rs b/tests/geometry/quaternion.rs index 927835e2..c5b91554 100644 --- a/tests/geometry/quaternion.rs +++ b/tests/geometry/quaternion.rs @@ -1,8 +1,7 @@ #![cfg(feature = "arbitrary")] #![allow(non_snake_case)] -use na::{Unit, UnitQuaternion, Quaternion, Vector3, Point3, Rotation3}; - +use na::{Point3, Quaternion, Rotation3, Unit, UnitQuaternion, Vector3}; quickcheck!( /* diff --git a/tests/geometry/rotation.rs b/tests/geometry/rotation.rs index a2e91dec..9bd3e590 100644 --- a/tests/geometry/rotation.rs +++ b/tests/geometry/rotation.rs @@ -18,9 +18,9 @@ fn angle_3() { #[cfg(feature = "arbitrary")] mod quickcheck_tests { - use std::f64; use alga::general::Real; - use na::{self, Vector2, Vector3, Rotation2, Rotation3, Unit}; + use na::{self, Rotation2, Rotation3, Unit, Vector2, Vector3}; + use std::f64; quickcheck! { /* diff --git a/tests/geometry/similarity.rs b/tests/geometry/similarity.rs index feb8ba1b..e9fde466 100644 --- a/tests/geometry/similarity.rs +++ b/tests/geometry/similarity.rs @@ -1,8 +1,8 @@ #![cfg(feature = "arbitrary")] #![allow(non_snake_case)] -use alga::linear::{Transformation, ProjectiveTransformation}; -use na::{Vector3, Point3, Similarity3, Translation3, Isometry3, UnitQuaternion}; +use alga::linear::{ProjectiveTransformation, Transformation}; +use na::{Isometry3, Point3, Similarity3, Translation3, UnitQuaternion, Vector3}; quickcheck!( fn inverse_is_identity(i: Similarity3, p: Point3, v: Vector3) -> bool { diff --git a/tests/geometry/unit_complex.rs b/tests/geometry/unit_complex.rs index 65837d8b..7da0d20c 100644 --- a/tests/geometry/unit_complex.rs +++ b/tests/geometry/unit_complex.rs @@ -1,7 +1,7 @@ #![cfg(feature = "arbitrary")] #![allow(non_snake_case)] -use na::{Unit, UnitComplex, Vector2, Point2, Rotation2}; +use na::{Point2, Rotation2, Unit, UnitComplex, Vector2}; quickcheck!( diff --git a/tests/lib.rs b/tests/lib.rs index a2238f1e..bfe95a5e 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -14,5 +14,5 @@ extern crate rand; extern crate serde_json; mod core; -mod linalg; mod geometry; +mod linalg; diff --git a/tests/linalg/balancing.rs b/tests/linalg/balancing.rs index 73fd8230..401f672a 100644 --- a/tests/linalg/balancing.rs +++ b/tests/linalg/balancing.rs @@ -2,8 +2,8 @@ use std::cmp; -use na::{DMatrix, Matrix4}; use na::balancing; +use na::{DMatrix, Matrix4}; quickcheck! { fn balancing_parlett_reinsch(n: usize) -> bool { diff --git a/tests/linalg/bidiagonal.rs b/tests/linalg/bidiagonal.rs index a96ce47c..a7d5952f 100644 --- a/tests/linalg/bidiagonal.rs +++ b/tests/linalg/bidiagonal.rs @@ -1,6 +1,6 @@ #![cfg(feature = "arbitrary")] -use na::{DMatrix, Matrix2, Matrix4, Matrix5x3, Matrix3x5}; +use na::{DMatrix, Matrix2, Matrix3x5, Matrix4, Matrix5x3}; quickcheck! { fn bidiagonal(m: DMatrix) -> bool { diff --git a/tests/linalg/cholesky.rs b/tests/linalg/cholesky.rs index df213ad4..9fe086ff 100644 --- a/tests/linalg/cholesky.rs +++ b/tests/linalg/cholesky.rs @@ -1,9 +1,9 @@ #![cfg(all(feature = "arbitrary", feature = "debug"))] -use std::cmp; -use na::{DMatrix, Matrix4x3, DVector, Vector4}; -use na::dimension::U4; use na::debug::RandomSDP; +use na::dimension::U4; +use na::{DMatrix, DVector, Matrix4x3, Vector4}; +use std::cmp; quickcheck! { fn cholesky(m: RandomSDP) -> bool { diff --git a/tests/linalg/eigen.rs b/tests/linalg/eigen.rs index ceb44bdf..3f9ac097 100644 --- a/tests/linalg/eigen.rs +++ b/tests/linalg/eigen.rs @@ -1,9 +1,10 @@ +t use na::DMatrix; #[cfg(feature = "arbitrary")] mod quickcheck_tests { - use std::cmp; use na::{DMatrix, Matrix2, Matrix3, Matrix4}; + use std::cmp; quickcheck! { fn symmetric_eigen(n: usize) -> bool { @@ -62,39 +63,47 @@ mod quickcheck_tests { // Test proposed on the issue #176 of rulinalg. #[test] fn symmetric_eigen_singular_24x24() { - let m = DMatrix::from_row_slice(24, 24, &[ - 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.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, - -1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.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, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.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, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.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, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 1.0, - 0.0, -4.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, -4.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, -4.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, -4.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, -4.0, 4.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, 4.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, 4.0, 0.0, -4.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, -4.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, -4.0, 0.0, 0.0, 4.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, 4.0, 0.0, 0.0, 0.0, -4.0, 0.0, 0.0, 4.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, -4.0, 4.0, 0.0, 0.0, 0.0, -4.0, 0.0, 0.0, 4.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, -4.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, -4.0, 0.0, 4.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, -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, 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, 4.0, 0.0, 0.0, 0.0, 0.0, -4.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, -4.0, 4.0, 0.0, 0.0, 0.0, 0.0, -4.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, -4.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, -4.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, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, -4.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, -4.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, -4.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, -4.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, 0.0, 0.0, - 0.0, 0.0, 0.0, 0.0, 0.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, 0.0, 0.0]); + let m = DMatrix::from_row_slice( + 24, + 24, + &[ + 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 0.0, 1.0, 1.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, + -1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.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, -1.0, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.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, -1.0, -1.0, -1.0, 0.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.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, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, -1.0, 0.0, 1.0, 1.0, 1.0, + 0.0, -4.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, -4.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, -4.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, -4.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, -4.0, 4.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, 4.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, 4.0, 0.0, -4.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, -4.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, -4.0, 0.0, 0.0, 4.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, 4.0, 0.0, 0.0, 0.0, -4.0, 0.0, 0.0, 4.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, -4.0, 4.0, 0.0, 0.0, 0.0, -4.0, 0.0, 0.0, 4.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, -4.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, -4.0, 0.0, 4.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, -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, 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, 4.0, 0.0, 0.0, 0.0, 0.0, -4.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, -4.0, 4.0, 0.0, 0.0, 0.0, 0.0, -4.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, -4.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, -4.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, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, -4.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, -4.0, 4.0, 0.0, 0.0, 0.0, 0.0, 0.0, -4.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, -4.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, 0.0, 0.0, + 0.0, 0.0, 0.0, 0.0, 0.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, 0.0, 0.0 + ], + ); let eig = m.clone().symmetric_eigen(); let recomp = eig.recompose(); - assert!(relative_eq!(m.lower_triangle(), recomp.lower_triangle(), epsilon = 1.0e-5)); + assert!(relative_eq!( + m.lower_triangle(), + recomp.lower_triangle(), + epsilon = 1.0e-5 + )); } - // #[cfg(feature = "arbitrary")] // quickcheck! { // FIXME: full eigendecomposition is not implemented yet because of its complexity when some @@ -167,16 +176,16 @@ fn symmetric_eigen_singular_24x24() { // MatrixN: Display, // VectorN: Display { // let mv = &m * &eig.eigenvectors; -// +// // println!("eigenvalues: {}eigenvectors: {}", eig.eigenvalues, eig.eigenvectors); -// +// // let dim = m.nrows(); // for i in 0 .. dim { // let mut col = eig.eigenvectors.column_mut(i); // col *= eig.eigenvalues[i]; // } -// +// // println!("{}{:.5}{:.5}", m, mv, eig.eigenvectors); -// +// // relative_eq!(eig.eigenvectors, mv, epsilon = 1.0e-5) // } diff --git a/tests/linalg/hessenberg.rs b/tests/linalg/hessenberg.rs index 67206487..22d62fbf 100644 --- a/tests/linalg/hessenberg.rs +++ b/tests/linalg/hessenberg.rs @@ -1,12 +1,11 @@ #![cfg(feature = "arbitrary")] -use std::cmp; use na::{DMatrix, Matrix2, Matrix4}; +use std::cmp; #[test] fn hessenberg_simple() { - let m = Matrix2::new(1.0, 0.0, - 1.0, 3.0); + let m = Matrix2::new(1.0, 0.0, 1.0, 3.0); let hess = m.hessenberg(); let (p, h) = hess.unpack(); assert!(relative_eq!(m, p * h * p.transpose(), epsilon = 1.0e-7)) diff --git a/tests/linalg/mod.rs b/tests/linalg/mod.rs index 6ce28085..74a5e03c 100644 --- a/tests/linalg/mod.rs +++ b/tests/linalg/mod.rs @@ -1,13 +1,13 @@ -mod inverse; -mod solve; -mod qr; -mod cholesky; -mod hessenberg; -mod lu; -mod full_piv_lu; -mod bidiagonal; -mod real_schur; -mod svd; mod balancing; -mod tridiagonal; +mod bidiagonal; +mod cholesky; mod eigen; +mod full_piv_lu; +mod hessenberg; +mod inverse; +mod lu; +mod qr; +mod real_schur; +mod solve; +mod svd; +mod tridiagonal; diff --git a/tests/linalg/qr.rs b/tests/linalg/qr.rs index 394a8b42..d7211623 100644 --- a/tests/linalg/qr.rs +++ b/tests/linalg/qr.rs @@ -1,8 +1,7 @@ #![cfg(feature = "arbitrary")] +use na::{DMatrix, DVector, Matrix3x5, Matrix4, Matrix4x3, Matrix5x3, Vector4}; use std::cmp; -use na::{DMatrix, Matrix4, Matrix4x3, Matrix5x3, Matrix3x5, - DVector, Vector4}; quickcheck! { fn qr(m: DMatrix) -> bool { diff --git a/tests/linalg/solve.rs b/tests/linalg/solve.rs index f960fb0a..76dc05b5 100644 --- a/tests/linalg/solve.rs +++ b/tests/linalg/solve.rs @@ -3,7 +3,7 @@ use na::{Matrix4, Matrix4x5}; fn unzero_diagonal(a: &mut Matrix4) { - for i in 0 .. 4 { + for i in 0..4 { if a[(i, i)] < 1.0e-7 { a[(i, i)] = 1.0; } diff --git a/tests/linalg/svd.rs b/tests/linalg/svd.rs index 5b09c7c8..fdde3776 100644 --- a/tests/linalg/svd.rs +++ b/tests/linalg/svd.rs @@ -1,3 +1,4 @@ +#![cfg_attr(rustfmt, rustfmt_skip)] use na::{DMatrix, Matrix6}; #[cfg(feature = "arbitrary")] @@ -318,12 +319,12 @@ fn svd_with_delimited_subproblem() { #[test] fn svd_fail() { let m = Matrix6::new( - 0.9299319121545955, 0.9955870335651049, 0.8824725266413644, 0.28966880207132295, 0.06102723649846409, 0.9311880746048009, - 0.5938395242304351, 0.8398522876024204, 0.06672831951963198, 0.9941213119963099, 0.9431846038057834, 0.8159885168706427, - 0.9121962883152357, 0.6471119669367571, 0.4823309702814407, 0.6420516076705516, 0.7731203925207113, 0.7424069470756647, + 0.9299319121545955, 0.9955870335651049, 0.8824725266413644, 0.28966880207132295, 0.06102723649846409, 0.9311880746048009, + 0.5938395242304351, 0.8398522876024204, 0.06672831951963198, 0.9941213119963099, 0.9431846038057834, 0.8159885168706427, + 0.9121962883152357, 0.6471119669367571, 0.4823309702814407, 0.6420516076705516, 0.7731203925207113, 0.7424069470756647, 0.07311092531259344, 0.5579247949052946, 0.14518764691585773, 0.03502980663114896, 0.7991329455957719, 0.4929930019965745, 0.12293810556077789, 0.6617084679545999, 0.9002240700227326, 0.027153062135304884, 0.3630189466989524, 0.18207502727558866, - 0.843196731466686, 0.08951878746549924, 0.7533450877576973, 0.009558876499740077, 0.9429679490873482, 0.9355764454129878); + 0.843196731466686, 0.08951878746549924, 0.7533450877576973, 0.009558876499740077, 0.9429679490873482, 0.9355764454129878); let svd = m.clone().svd(true, true); println!("Singular values: {}", svd.singular_values); println!("u: {:.5}", svd.u.unwrap());