From 8341ec2f10a5a3829061cda349f8f0719cf6e155 Mon Sep 17 00:00:00 2001 From: sebcrozet Date: Tue, 6 Nov 2018 18:32:20 +0100 Subject: [PATCH] Run rustfmt. --- benches/core/matrix.rs | 16 +- benches/core/vector.rs | 4 +- benches/geometry/quaternion.rs | 4 +- benches/lib.rs | 4 +- benches/linalg/bidiagonal.rs | 2 +- benches/linalg/cholesky.rs | 2 +- benches/linalg/full_piv_lu.rs | 2 +- benches/linalg/hessenberg.rs | 2 +- benches/linalg/lu.rs | 2 +- benches/linalg/mod.rs | 12 +- benches/linalg/qr.rs | 2 +- benches/linalg/schur.rs | 2 +- benches/linalg/solve.rs | 2 +- benches/linalg/svd.rs | 2 +- benches/linalg/symmetric_eigen.rs | 2 +- examples/dimensional_genericity.rs | 14 +- examples/homogeneous_coordinates.rs | 2 +- examples/identity.rs | 4 +- examples/matrix_construction.rs | 11 +- examples/transform_vector_point.rs | 2 +- nalgebra-glm/src/aliases.rs | 19 +- nalgebra-glm/src/common.rs | 61 ++-- nalgebra-glm/src/constructors.rs | 208 +++++++----- nalgebra-glm/src/exponential.rs | 17 +- nalgebra-glm/src/ext/matrix_clip_space.rs | 3 +- nalgebra-glm/src/ext/matrix_projection.rs | 58 +++- nalgebra-glm/src/ext/matrix_relationnal.rs | 62 +++- nalgebra-glm/src/ext/matrix_transform.rs | 20 +- nalgebra-glm/src/ext/mod.rs | 39 ++- nalgebra-glm/src/ext/quaternion_common.rs | 4 +- nalgebra-glm/src/ext/quaternion_geometric.rs | 2 +- nalgebra-glm/src/ext/quaternion_relational.rs | 1 - nalgebra-glm/src/ext/quaternion_transform.rs | 4 +- .../src/ext/quaternion_trigonometric.rs | 2 +- nalgebra-glm/src/ext/vector_common.rs | 36 ++- nalgebra-glm/src/ext/vector_relational.rs | 44 ++- nalgebra-glm/src/geometric.rs | 34 +- nalgebra-glm/src/gtc/epsilon.rs | 2 +- nalgebra-glm/src/gtc/matrix_access.rs | 35 +- nalgebra-glm/src/gtc/matrix_inverse.rs | 12 +- nalgebra-glm/src/gtc/mod.rs | 25 +- nalgebra-glm/src/gtc/quaternion.rs | 5 +- nalgebra-glm/src/gtc/type_ptr.rs | 45 +-- nalgebra-glm/src/gtx/component_wise.rs | 10 +- nalgebra-glm/src/gtx/exterior_product.rs | 4 +- .../src/gtx/handed_coordinate_space.rs | 2 +- nalgebra-glm/src/gtx/matrix_operation.rs | 4 +- nalgebra-glm/src/gtx/mod.rs | 38 ++- nalgebra-glm/src/gtx/norm.rs | 18 +- nalgebra-glm/src/gtx/normal.rs | 2 +- nalgebra-glm/src/gtx/normalize_dot.rs | 8 +- nalgebra-glm/src/gtx/quaternion.rs | 19 +- nalgebra-glm/src/gtx/rotate_vector.rs | 6 +- nalgebra-glm/src/gtx/transform.rs | 5 +- nalgebra-glm/src/gtx/transform2.rs | 40 +-- nalgebra-glm/src/gtx/transform2d.rs | 2 +- nalgebra-glm/src/gtx/vector_angle.rs | 5 +- nalgebra-glm/src/gtx/vector_query.rs | 20 +- nalgebra-glm/src/lib.rs | 306 +++++++++--------- nalgebra-glm/src/matrix.rs | 32 +- nalgebra-glm/src/traits.rs | 91 ++++-- nalgebra-glm/src/trigonometric.rs | 33 +- nalgebra-glm/src/vector_relational.rs | 29 +- nalgebra-lapack/benches/linalg/hessenberg.rs | 2 +- nalgebra-lapack/benches/linalg/lu.rs | 2 +- nalgebra-lapack/benches/linalg/mod.rs | 4 +- nalgebra-lapack/benches/linalg/qr.rs | 2 +- nalgebra-lapack/src/cholesky.rs | 28 +- nalgebra-lapack/src/eigen.rs | 27 +- nalgebra-lapack/src/hessenberg.rs | 25 +- nalgebra-lapack/src/lib.rs | 6 +- nalgebra-lapack/src/lu.rs | 35 +- nalgebra-lapack/src/qr.rs | 34 +- nalgebra-lapack/src/schur.rs | 24 +- nalgebra-lapack/src/svd.rs | 31 +- nalgebra-lapack/src/symmetric_eigen.rs | 27 +- nalgebra-lapack/tests/linalg/cholesky.rs | 2 +- nalgebra-lapack/tests/linalg/lu.rs | 2 +- nalgebra-lapack/tests/linalg/mod.rs | 6 +- nalgebra-lapack/tests/linalg/qr.rs | 2 +- .../tests/linalg/real_eigensystem.rs | 2 +- nalgebra-lapack/tests/linalg/real_schur.rs | 4 +- nalgebra-lapack/tests/linalg/svd.rs | 2 +- .../tests/linalg/symmetric_eigen.rs | 2 +- src/base/allocator.rs | 6 +- src/base/blas.rs | 20 +- src/base/cg.rs | 16 +- src/base/constraint.rs | 3 +- src/base/construction.rs | 94 ++---- src/base/construction_slice.rs | 18 +- src/base/default_allocator.rs | 30 +- src/base/dimension.rs | 14 +- src/base/edition.rs | 26 +- src/base/helper.rs | 4 +- src/base/matrix.rs | 64 ++-- src/base/matrix_alga.rs | 13 +- src/base/matrix_array.rs | 32 +- src/base/matrix_slice.rs | 18 +- src/base/matrix_vec.rs | 40 +-- src/base/ops.rs | 8 +- src/base/properties.rs | 3 +- src/base/storage.rs | 6 +- src/base/unit.rs | 11 +- src/debug/random_orthogonal.rs | 6 +- src/debug/random_sdp.rs | 6 +- src/geometry/isometry.rs | 33 +- src/geometry/isometry_construction.rs | 6 +- src/geometry/orthographic.rs | 18 +- src/geometry/perspective.rs | 15 +- src/geometry/point.rs | 29 +- src/geometry/point_alga.rs | 3 +- src/geometry/point_construction.rs | 10 +- src/geometry/point_ops.rs | 12 +- src/geometry/quaternion.rs | 26 +- src/geometry/quaternion_construction.rs | 37 +-- src/geometry/rotation.rs | 23 +- src/geometry/rotation_alga.rs | 24 +- src/geometry/rotation_ops.rs | 3 +- src/geometry/rotation_specialization.rs | 13 +- src/geometry/similarity.rs | 33 +- src/geometry/transform.rs | 37 +-- src/geometry/transform_construction.rs | 6 +- src/geometry/translation.rs | 34 +- src/geometry/translation_alga.rs | 24 +- src/geometry/translation_construction.rs | 6 +- src/geometry/unit_complex.rs | 3 +- src/geometry/unit_complex_alga.rs | 15 +- src/geometry/unit_complex_construction.rs | 7 +- src/geometry/unit_complex_ops.rs | 24 +- src/lib.rs | 12 +- src/linalg/balancing.rs | 8 +- src/linalg/bidiagonal.rs | 23 +- src/linalg/cholesky.rs | 24 +- src/linalg/determinant.rs | 4 +- src/linalg/full_piv_lu.rs | 38 +-- src/linalg/hessenberg.rs | 36 +-- src/linalg/householder.rs | 4 +- src/linalg/inverse.rs | 8 +- src/linalg/lu.rs | 49 +-- src/linalg/permutation_sequence.rs | 43 ++- src/linalg/qr.rs | 35 +- src/linalg/schur.rs | 33 +- src/linalg/svd.rs | 50 +-- src/linalg/symmetric_eigen.rs | 24 +- src/linalg/symmetric_tridiagonal.rs | 40 +-- src/sparse/cs_matrix.rs | 42 +-- src/sparse/cs_matrix_cholesky.rs | 9 +- src/sparse/cs_matrix_conversion.rs | 9 +- src/sparse/cs_matrix_solve.rs | 6 +- src/sparse/cs_utils.rs | 4 +- tests/geometry/isometry.rs | 207 ++++++------ tests/geometry/point.rs | 10 +- tests/geometry/quaternion.rs | 219 ++++++------- tests/geometry/similarity.rs | 203 ++++++------ tests/geometry/unit_complex.rs | 147 ++++----- 155 files changed, 1880 insertions(+), 2060 deletions(-) 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..bb78458f 100644 --- a/examples/matrix_construction.rs +++ b/examples/matrix_construction.rs @@ -48,12 +48,11 @@ 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() - .cloned(), + // 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(), ); assert_eq!(dm, dm1); 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/aliases.rs b/nalgebra-glm/src/aliases.rs index 9bb7edb6..206a8abe 100644 --- a/nalgebra-glm/src/aliases.rs +++ b/nalgebra-glm/src/aliases.rs @@ -1,9 +1,7 @@ -use na::{MatrixMN, VectorN, - Matrix2, Matrix3, Matrix4, - Matrix2x3, Matrix3x2, Matrix4x2, - Matrix2x4, Matrix3x4, Matrix4x3, - Quaternion, - U1, U2, U3, U4}; +use na::{ + Matrix2, Matrix2x3, Matrix2x4, Matrix3, Matrix3x2, Matrix3x4, Matrix4, Matrix4x2, Matrix4x3, + MatrixMN, Quaternion, VectorN, U1, U2, U3, U4, +}; /// A matrix with components of type `N`. It has `R` rows, and `C` columns. /// @@ -194,13 +192,13 @@ pub type UVec3 = TVec3; /// A 4D vector with `u32` components. pub type UVec4 = TVec4; /// A 1D vector with `f32` components. -pub type Vec1 = TVec1; +pub type Vec1 = TVec1; /// A 2D vector with `f32` components. -pub type Vec2 = TVec2; +pub type Vec2 = TVec2; /// A 3D vector with `f32` components. -pub type Vec3 = TVec3; +pub type Vec3 = TVec3; /// A 4D vector with `f32` components. -pub type Vec4 = TVec4; +pub type Vec4 = TVec4; /// A 1D vector with `u64` components. pub type U64Vec1 = TVec1; @@ -270,7 +268,6 @@ pub type I8Vec3 = TVec3; /// A 4D vector with `i8` components. pub type I8Vec4 = TVec4; - /// A 2x2 matrix with components of type `N`. pub type TMat2 = Matrix2; /// A 2x2 matrix with components of type `N`. diff --git a/nalgebra-glm/src/common.rs b/nalgebra-glm/src/common.rs index 45b94336..e6a3dc0f 100644 --- a/nalgebra-glm/src/common.rs +++ b/nalgebra-glm/src/common.rs @@ -1,9 +1,9 @@ -use std::mem; +use na::{self, DefaultAllocator, Real}; use num::FromPrimitive; -use na::{self, Real, DefaultAllocator}; +use std::mem; -use aliases::{TVec, TMat}; -use traits::{Number, Dimension, Alloc}; +use aliases::{TMat, TVec}; +use traits::{Alloc, Dimension, Number}; /// For each matrix or vector component `x` if `x >= 0`; otherwise, it returns `-x`. /// @@ -22,8 +22,8 @@ use traits::{Number, Dimension, Alloc}; /// /// * [`sign`](fn.sign.html) pub fn abs(x: &TMat) -> TMat - where DefaultAllocator: Alloc { - x.abs() +where DefaultAllocator: Alloc { + x.abs() } /// For each matrix or vector component returns a value equal to the nearest integer that is greater than or equal to `x`. @@ -44,7 +44,7 @@ pub fn abs(x: &TMat) -> TMat(x: &TVec) -> TVec - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { x.map(|x| x.ceil()) } @@ -94,7 +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)) } @@ -125,8 +125,14 @@ pub fn clamp(x: &TVec, min_val: N, max_val: N) -> /// /// * [`clamp_scalar`](fn.clamp_scalar.html) /// * [`clamp`](fn.clamp.html) -pub fn clamp_vec(x: &TVec, min_val: &TVec, max_val: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn clamp_vec( + x: &TVec, + min_val: &TVec, + max_val: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ x.zip_zip_map(min_val, max_val, |a, min, max| na::clamp(a, min, max)) } @@ -161,7 +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) } @@ -196,7 +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) } @@ -217,7 +223,7 @@ pub fn float_bits_to_uint_vec(v: &TVec) -> TVec /// * [`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()) } @@ -244,7 +250,7 @@ pub fn floor(x: &TVec) -> TVec /// * [`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()) } @@ -271,7 +277,6 @@ pub fn fract(x: &TVec) -> TVec /// * [`uint_bits_to_float_scalar`](fn.uint_bits_to_float_scalar.html) pub fn int_bits_to_float(v: i32) -> f32 { f32::from_bits(v as u32) - } /// For each components of `v`, returns a floating-point value corresponding to a signed integer encoding of a floating-point value. @@ -288,7 +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) } @@ -325,7 +330,7 @@ pub fn mix(x: N, y: N, a: N) -> N { /// /// * [`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) } @@ -357,9 +362,8 @@ 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()) - } //pub fn roundEven(x: &TVec) -> TVec @@ -382,14 +386,8 @@ pub fn round(x: &TVec) -> TVec /// * [`abs`](fn.abs.html) /// pub fn sign(x: &TVec) -> TVec - where DefaultAllocator: Alloc { - x.map(|x| { - if x.is_zero() { - N::zero() - } else { - x.signum() - } - }) +where DefaultAllocator: Alloc { + x.map(|x| if x.is_zero() { N::zero() } else { x.signum() }) } /// Returns 0.0 if `x <= edge0` and `1.0 if x >= edge1` and performs smooth Hermite interpolation between 0 and 1 when `edge0 < x < edge1`. @@ -414,13 +412,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) } @@ -441,7 +439,7 @@ pub fn step_vec(edge: &TVec, x: &TVec) -> T /// * [`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()) } @@ -460,7 +458,6 @@ pub fn trunc(x: &TVec) -> TVec /// * [`uint_bits_to_float`](fn.uint_bits_to_float.html) pub fn uint_bits_to_float_scalar(v: u32) -> f32 { f32::from_bits(v) - } /// For each component of `v`, returns a floating-point value corresponding to a unsigned integer encoding of a floating-point value. @@ -477,6 +474,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..210a10d4 100644 --- a/nalgebra-glm/src/constructors.rs +++ b/nalgebra-glm/src/constructors.rs @@ -1,7 +1,8 @@ -use na::{Scalar, Real, U2, U3, U4}; -use aliases::{TMat, Qua, TVec1, TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, - TMat4, TMat4x2, TMat4x3}; - +use aliases::{ + Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1, + TVec2, TVec3, TVec4, +}; +use na::{Real, Scalar, U2, U3, U4}; /// Creates a new 1D vector. /// @@ -32,112 +33,173 @@ pub fn vec4(x: N, y: N, z: N, w: N) -> TVec4 { TVec4::new(x, y, z, w) } - /// Create a new 2x2 matrix. pub fn mat2(m11: N, m12: N, m21: N, m22: N) -> TMat2 { - TMat::::new( - m11, m12, - m21, m22, - ) + TMat::::new(m11, m12, m21, m22) } /// Create a new 2x2 matrix. pub fn mat2x2(m11: N, m12: N, m21: N, m22: N) -> TMat2 { - TMat::::new( - m11, m12, - m21, m22, - ) + TMat::::new(m11, m12, m21, m22) } /// Create a new 2x3 matrix. pub fn mat2x3(m11: N, m12: N, m13: N, m21: N, m22: N, m23: N) -> TMat2x3 { - TMat::::new( - m11, m12, m13, - m21, m22, m23, - ) + TMat::::new(m11, m12, m13, m21, m22, m23) } /// 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 { - TMat::::new( - m11, m12, m13, m14, - m21, m22, m23, m24, - ) +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) } /// 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 { - TMat::::new( - m11, m12, m13, - m21, m22, m23, - m31, m32, m33, - ) +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, m31, m32, m33) } /// Create a new 3x2 matrix. pub fn mat3x2(m11: N, m12: N, m21: N, m22: N, m31: N, m32: N) -> TMat3x2 { - TMat::::new( - m11, m12, - m21, m22, - m31, m32, - ) + TMat::::new(m11, m12, m21, m22, m31, m32) } /// 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 { - TMat::::new( - m11, m12, m13, - m31, m32, m33, - m21, m22, m23, - ) +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, m21, m22, m23) } /// 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 { - TMat::::new( - m11, m12, m13, m14, - m21, m22, m23, m24, - m31, m32, m33, m34, - ) +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, m31, m32, m33, m34) } /// 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 { - TMat::::new( - m11, m12, - m21, m22, - m31, m32, - m41, m42, - ) +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, m31, m32, m41, m42) } /// 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 { - TMat::::new( - m11, m12, m13, - m21, m22, m23, - m31, m32, m33, - m41, m42, m43, +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, m31, m32, m33, m41, m42, m43) +} + +/// 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 +{ + TMat::::new( + m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44, ) } /// 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 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, - m31, m32, m33, m34, - m41, m42, m43, m44, - ) -} - -/// 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 { - TMat::::new( - m11, m12, m13, m14, - m21, m22, m23, m24, - m31, m32, m33, m34, - m41, m42, m43, m44, + m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, m41, m42, m43, m44, ) } diff --git a/nalgebra-glm/src/exponential.rs b/nalgebra-glm/src/exponential.rs index d73db3a8..21b716f2 100644 --- a/nalgebra-glm/src/exponential.rs +++ b/nalgebra-glm/src/exponential.rs @@ -1,5 +1,5 @@ -use na::{Real, DefaultAllocator}; use aliases::TVec; +use na::{DefaultAllocator, Real}; use traits::{Alloc, Dimension}; /// Component-wise exponential. @@ -8,7 +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()) } @@ -18,7 +18,7 @@ pub fn exp(v: &TVec) -> TVec /// /// * [`exp`](fn.exp.html) pub fn exp2(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { v.map(|x| x.exp2()) } @@ -28,9 +28,8 @@ pub fn exp2(v: &TVec) -> TVec /// /// * [`sqrt`](fn.sqrt.html) pub fn inversesqrt(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { v.map(|x| N::one() / x.sqrt()) - } /// Component-wise logarithm. @@ -39,7 +38,7 @@ pub fn inversesqrt(v: &TVec) -> TVec /// /// * [`log2`](fn.log2.html) pub fn log(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { v.map(|x| x.ln()) } @@ -49,13 +48,13 @@ pub fn log(v: &TVec) -> TVec /// /// * [`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)) } @@ -68,6 +67,6 @@ pub fn pow(base: &TVec, exponent: &TVec) -> T /// * [`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_clip_space.rs b/nalgebra-glm/src/ext/matrix_clip_space.rs index 813fe8fc..89c137ea 100644 --- a/nalgebra-glm/src/ext/matrix_clip_space.rs +++ b/nalgebra-glm/src/ext/matrix_clip_space.rs @@ -1,5 +1,5 @@ -use na::{Real, Orthographic3, Perspective3}; use aliases::TMat4; +use na::{Orthographic3, Perspective3, Real}; //pub fn frustum(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { // unimplemented!() @@ -90,7 +90,6 @@ pub fn ortho(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) - // unimplemented!() //} - /// Creates a matrix for a perspective-view frustum based on the right handedness and OpenGL near and far clip planes definition. /// /// # Important note diff --git a/nalgebra-glm/src/ext/matrix_projection.rs b/nalgebra-glm/src/ext/matrix_projection.rs index b8d2fc8d..d56103a6 100644 --- a/nalgebra-glm/src/ext/matrix_projection.rs +++ b/nalgebra-glm/src/ext/matrix_projection.rs @@ -1,6 +1,6 @@ use na::{self, Real, U3}; -use aliases::{TVec2, TVec3, TVec4, TMat4}; +use aliases::{TMat4, TVec2, TVec3, TVec4}; /// Define a picking region. /// @@ -13,11 +13,15 @@ pub fn pick_matrix(center: &TVec2, delta: &TVec2, viewport: &TVec let shift = TVec3::new( (viewport.z - (center.x - viewport.x) * na::convert(2.0)) / delta.x, (viewport.w - (center.y - viewport.y) * na::convert(2.0)) / delta.y, - N::zero() + N::zero(), ); let result = TMat4::new_translation(&shift); - result.prepend_nonuniform_scaling(&TVec3::new(viewport.z / delta.x, viewport.w / delta.y, N::one())) + result.prepend_nonuniform_scaling(&TVec3::new( + viewport.z / delta.x, + viewport.w / delta.y, + N::one(), + )) } /// Map the specified object coordinates `(obj.x, obj.y, obj.z)` into window coordinates using OpenGL near and far clip planes definition. @@ -36,7 +40,13 @@ pub fn pick_matrix(center: &TVec2, delta: &TVec2, viewport: &TVec /// * [`unproject`](fn.unproject.html) /// * [`unproject_no`](fn.unproject_no.html) /// * [`unproject_zo`](fn.unproject_zo.html) -pub fn project(obj: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { +pub fn project( + obj: &TVec3, + model: &TMat4, + proj: &TMat4, + viewport: TVec4, +) -> TVec3 +{ project_no(obj, model, proj, viewport) } @@ -58,7 +68,13 @@ pub fn project(obj: &TVec3, model: &TMat4, proj: &TMat4, viewp /// * [`unproject`](fn.unproject.html) /// * [`unproject_no`](fn.unproject_no.html) /// * [`unproject_zo`](fn.unproject_zo.html) -pub fn project_no(obj: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { +pub fn project_no( + obj: &TVec3, + model: &TMat4, + proj: &TMat4, + viewport: TVec4, +) -> 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)) } @@ -81,7 +97,13 @@ pub fn project_no(obj: &TVec3, model: &TMat4, proj: &TMat4, vi /// * [`unproject`](fn.unproject.html) /// * [`unproject_no`](fn.unproject_no.html) /// * [`unproject_zo`](fn.unproject_zo.html) -pub fn project_zo(obj: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { +pub fn project_zo( + obj: &TVec3, + model: &TMat4, + proj: &TMat4, + viewport: TVec4, +) -> TVec3 +{ let normalized = proj * model * TVec4::new(obj.x, obj.y, obj.z, N::one()); let scale = N::one() / normalized.w; @@ -108,7 +130,13 @@ pub fn project_zo(obj: &TVec3, model: &TMat4, proj: &TMat4, vi /// * [`project_zo`](fn.project_zo.html) /// * [`unproject_no`](fn.unproject_no.html) /// * [`unproject_zo`](fn.unproject_zo.html) -pub fn unproject(win: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { +pub fn unproject( + win: &TVec3, + model: &TMat4, + proj: &TMat4, + viewport: TVec4, +) -> TVec3 +{ unproject_no(win, model, proj, viewport) } @@ -130,7 +158,13 @@ pub fn unproject(win: &TVec3, model: &TMat4, proj: &TMat4, vie /// * [`project_zo`](fn.project_zo.html) /// * [`unproject`](fn.unproject.html) /// * [`unproject_zo`](fn.unproject_zo.html) -pub fn unproject_no(win: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { +pub fn unproject_no( + win: &TVec3, + model: &TMat4, + proj: &TMat4, + viewport: TVec4, +) -> TVec3 +{ let _2: N = na::convert(2.0); let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros); let pt = TVec4::new( @@ -162,7 +196,13 @@ pub fn unproject_no(win: &TVec3, model: &TMat4, proj: &TMat4, /// * [`project_zo`](fn.project_zo.html) /// * [`unproject`](fn.unproject.html) /// * [`unproject_no`](fn.unproject_no.html) -pub fn unproject_zo(win: &TVec3, model: &TMat4, proj: &TMat4, viewport: TVec4) -> TVec3 { +pub fn unproject_zo( + win: &TVec3, + model: &TMat4, + proj: &TMat4, + viewport: TVec4, +) -> 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_relationnal.rs b/nalgebra-glm/src/ext/matrix_relationnal.rs index d5f34ae8..80fb8b6f 100644 --- a/nalgebra-glm/src/ext/matrix_relationnal.rs +++ b/nalgebra-glm/src/ext/matrix_relationnal.rs @@ -1,13 +1,18 @@ use na::DefaultAllocator; -use aliases::{TVec, TMat}; -use traits::{Alloc, Number, Dimension}; +use aliases::{TMat, TVec}; +use traits::{Alloc, Dimension, Number}; /// Perform a component-wise equal-to comparison of two matrices. /// /// Return a boolean vector which components value is True if this expression is satisfied per column of the matrices. -pub fn equal_columns(x: &TMat, y: &TMat) -> TVec - where DefaultAllocator: Alloc { +pub fn equal_columns( + x: &TMat, + y: &TMat, +) -> TVec +where + DefaultAllocator: Alloc, +{ let mut res = TVec::<_, C>::repeat(false); for i in 0..C::dim() { @@ -20,16 +25,28 @@ pub fn equal_columns(x: &TMat, y /// Returns the component-wise comparison of `|x - y| < epsilon`. /// /// True if this expression is satisfied. -pub fn equal_columns_eps(x: &TMat, y: &TMat, epsilon: N) -> TVec - where DefaultAllocator: Alloc { +pub fn equal_columns_eps( + x: &TMat, + y: &TMat, + epsilon: N, +) -> TVec +where + DefaultAllocator: Alloc, +{ equal_columns_eps_vec(x, y, &TVec::<_, C>::repeat(epsilon)) } /// Returns the component-wise comparison on each matrix column `|x - y| < epsilon`. /// /// True if this expression is satisfied. -pub fn equal_columns_eps_vec(x: &TMat, y: &TMat, epsilon: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn equal_columns_eps_vec( + x: &TMat, + y: &TMat, + epsilon: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ let mut res = TVec::<_, C>::repeat(false); for i in 0..C::dim() { @@ -42,8 +59,13 @@ pub fn equal_columns_eps_vec(x: &TMat(x: &TMat, y: &TMat) -> TVec - where DefaultAllocator: Alloc { +pub fn not_equal_columns( + x: &TMat, + y: &TMat, +) -> TVec +where + DefaultAllocator: Alloc, +{ let mut res = TVec::<_, C>::repeat(false); for i in 0..C::dim() { @@ -56,16 +78,28 @@ pub fn not_equal_columns(x: &TMat(x: &TMat, y: &TMat, epsilon: N) -> TVec - where DefaultAllocator: Alloc { +pub fn not_equal_columns_eps( + x: &TMat, + y: &TMat, + epsilon: N, +) -> TVec +where + DefaultAllocator: Alloc, +{ not_equal_columns_eps_vec(x, y, &TVec::<_, C>::repeat(epsilon)) } /// Returns the component-wise comparison of `|x - y| >= epsilon`. /// /// True if this expression is not satisfied. -pub fn not_equal_columns_eps_vec(x: &TMat, y: &TMat, epsilon: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn not_equal_columns_eps_vec( + x: &TMat, + y: &TMat, + epsilon: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ let mut res = TVec::<_, C>::repeat(false); for i in 0..C::dim() { diff --git a/nalgebra-glm/src/ext/matrix_transform.rs b/nalgebra-glm/src/ext/matrix_transform.rs index af2408fd..fb23efc9 100644 --- a/nalgebra-glm/src/ext/matrix_transform.rs +++ b/nalgebra-glm/src/ext/matrix_transform.rs @@ -1,11 +1,11 @@ -use na::{DefaultAllocator, Real, Unit, Rotation3, Point3}; +use na::{DefaultAllocator, Point3, Real, Rotation3, Unit}; -use traits::{Dimension, Number, Alloc}; -use aliases::{TMat, TVec, TVec3, TMat4}; +use aliases::{TMat, TMat4, TVec, TVec3}; +use traits::{Alloc, Dimension, Number}; /// The identity matrix. pub fn identity() -> TMat - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { TMat::::identity() } @@ -38,7 +38,11 @@ pub fn look_at(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMa /// * [`look_at`](fn.look_at.html) /// * [`look_at_rh`](fn.look_at_rh.html) pub fn look_at_lh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { - TMat::look_at_lh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up) + TMat::look_at_lh( + &Point3::from_coordinates(*eye), + &Point3::from_coordinates(*center), + up, + ) } /// Build a right handed look at view matrix. @@ -54,7 +58,11 @@ pub fn look_at_lh(eye: &TVec3, center: &TVec3, up: &TVec3) -> /// * [`look_at`](fn.look_at.html) /// * [`look_at_lh`](fn.look_at_lh.html) pub fn look_at_rh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { - TMat::look_at_rh(&Point3::from_coordinates(*eye), &Point3::from_coordinates(*center), up) + TMat::look_at_rh( + &Point3::from_coordinates(*eye), + &Point3::from_coordinates(*center), + up, + ) } /// Builds a rotation 4 * 4 matrix created from an axis vector and an angle and right-multiply it to `m`. diff --git a/nalgebra-glm/src/ext/mod.rs b/nalgebra-glm/src/ext/mod.rs index 5d8e9d5c..6ad74ff6 100644 --- a/nalgebra-glm/src/ext/mod.rs +++ b/nalgebra-glm/src/ext/mod.rs @@ -1,30 +1,41 @@ //! (Reexported) Additional features not specified by GLSL specification pub use self::matrix_clip_space::{ortho, perspective}; -pub use self::matrix_projection::{pick_matrix, project, project_no, project_zo, unproject, unproject_no, unproject_zo}; -pub use self::matrix_relationnal::{equal_columns, equal_columns_eps, equal_columns_eps_vec, not_equal_columns, not_equal_columns_eps, not_equal_columns_eps_vec}; -pub use self::matrix_transform::{identity, look_at, look_at_lh, rotate, scale, look_at_rh, translate, rotate_x, rotate_y, rotate_z}; +pub use self::matrix_projection::{ + pick_matrix, project, project_no, project_zo, unproject, unproject_no, unproject_zo, +}; +pub use self::matrix_relationnal::{ + equal_columns, equal_columns_eps, equal_columns_eps_vec, not_equal_columns, + not_equal_columns_eps, not_equal_columns_eps_vec, +}; +pub use self::matrix_transform::{ + identity, look_at, look_at_lh, look_at_rh, rotate, rotate_x, rotate_y, rotate_z, scale, + translate, +}; +pub use self::quaternion_common::{quat_conjugate, quat_inverse, quat_lerp, quat_slerp}; +pub use self::quaternion_geometric::{ + quat_cross, quat_dot, quat_length, quat_magnitude, quat_normalize, +}; +pub use self::quaternion_relational::{ + quat_equal, quat_equal_eps, quat_not_equal, quat_not_equal_eps, +}; +pub use self::quaternion_transform::{quat_exp, quat_log, quat_pow, quat_rotate}; +pub use self::quaternion_trigonometric::{quat_angle, quat_angle_axis, quat_axis}; pub use self::scalar_common::{max3_scalar, max4_scalar, min3_scalar, min4_scalar}; pub use self::scalar_constants::{epsilon, pi}; pub use self::vector_common::{max, max2, max3, max4, min, min2, min3, min4}; pub use self::vector_relational::{equal_eps, equal_eps_vec, not_equal_eps, not_equal_eps_vec}; -pub use self::quaternion_common::{quat_conjugate, quat_inverse, quat_lerp, quat_slerp}; -pub use self::quaternion_geometric::{quat_cross, quat_dot, quat_length, quat_magnitude, quat_normalize}; -pub use self::quaternion_relational::{quat_equal, quat_equal_eps, quat_not_equal, quat_not_equal_eps}; -pub use self::quaternion_transform::{quat_exp, quat_log, quat_pow, quat_rotate}; -pub use self::quaternion_trigonometric::{quat_angle, quat_angle_axis, quat_axis}; - mod matrix_clip_space; mod matrix_projection; mod matrix_relationnal; mod matrix_transform; -mod scalar_common; -mod scalar_constants; -mod vector_common; -mod vector_relational; mod quaternion_common; mod quaternion_geometric; mod quaternion_relational; mod quaternion_transform; -mod quaternion_trigonometric; \ No newline at end of file +mod quaternion_trigonometric; +mod scalar_common; +mod scalar_constants; +mod vector_common; +mod vector_relational; diff --git a/nalgebra-glm/src/ext/quaternion_common.rs b/nalgebra-glm/src/ext/quaternion_common.rs index 84af997d..208601ed 100644 --- a/nalgebra-glm/src/ext/quaternion_common.rs +++ b/nalgebra-glm/src/ext/quaternion_common.rs @@ -31,5 +31,7 @@ pub fn quat_lerp(x: &Qua, y: &Qua, a: N) -> Qua { /// Interpolate spherically between `x` and `y`. pub fn quat_slerp(x: &Qua, y: &Qua, a: N) -> Qua { - Unit::new_normalize(*x).slerp(&Unit::new_normalize(*y), a).unwrap() + Unit::new_normalize(*x) + .slerp(&Unit::new_normalize(*y), a) + .unwrap() } diff --git a/nalgebra-glm/src/ext/quaternion_geometric.rs b/nalgebra-glm/src/ext/quaternion_geometric.rs index 88838f8a..a67de587 100644 --- a/nalgebra-glm/src/ext/quaternion_geometric.rs +++ b/nalgebra-glm/src/ext/quaternion_geometric.rs @@ -25,4 +25,4 @@ pub fn quat_magnitude(q: &Qua) -> N { /// Normalizes the quaternion `q`. pub fn quat_normalize(q: &Qua) -> Qua { q.normalize() -} \ No newline at end of file +} diff --git a/nalgebra-glm/src/ext/quaternion_relational.rs b/nalgebra-glm/src/ext/quaternion_relational.rs index d493defd..e459054f 100644 --- a/nalgebra-glm/src/ext/quaternion_relational.rs +++ b/nalgebra-glm/src/ext/quaternion_relational.rs @@ -1,6 +1,5 @@ use na::{Real, U4}; - use aliases::{Qua, TVec}; /// Component-wise equality comparison between two quaternions. diff --git a/nalgebra-glm/src/ext/quaternion_transform.rs b/nalgebra-glm/src/ext/quaternion_transform.rs index c2fedf36..a1459269 100644 --- a/nalgebra-glm/src/ext/quaternion_transform.rs +++ b/nalgebra-glm/src/ext/quaternion_transform.rs @@ -1,4 +1,4 @@ -use na::{Real, UnitQuaternion, Unit}; +use na::{Real, Unit, UnitQuaternion}; use aliases::{Qua, TVec3}; @@ -24,4 +24,4 @@ pub fn quat_rotate(q: &Qua, angle: N, axis: &TVec3) -> Qua { //pub fn quat_sqrt(q: &Qua) -> Qua { // unimplemented!() -//} \ No newline at end of file +//} diff --git a/nalgebra-glm/src/ext/quaternion_trigonometric.rs b/nalgebra-glm/src/ext/quaternion_trigonometric.rs index ae53eb72..6e9be030 100644 --- a/nalgebra-glm/src/ext/quaternion_trigonometric.rs +++ b/nalgebra-glm/src/ext/quaternion_trigonometric.rs @@ -19,4 +19,4 @@ pub fn quat_axis(x: &Qua) -> TVec3 { } else { TVec3::zeros() } -} \ No newline at end of file +} diff --git a/nalgebra-glm/src/ext/vector_common.rs b/nalgebra-glm/src/ext/vector_common.rs index 4c736651..c0318067 100644 --- a/nalgebra-glm/src/ext/vector_common.rs +++ b/nalgebra-glm/src/ext/vector_common.rs @@ -1,7 +1,7 @@ use na::{self, DefaultAllocator}; -use traits::{Alloc, Number, Dimension}; use aliases::TVec; +use traits::{Alloc, Dimension, Number}; /// Component-wise maximum between a vector and a scalar. /// @@ -17,7 +17,7 @@ use aliases::TVec; /// * [`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)) } @@ -35,7 +35,7 @@ pub fn max(a: &TVec, b: N) -> TVec /// * [`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) } @@ -53,7 +53,7 @@ pub fn max2(a: &TVec, b: &TVec) -> TVec(a: &TVec, b: &TVec, c: &TVec) -> TVec - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { max2(&max2(a, b), c) } @@ -70,8 +70,15 @@ pub fn max3(a: &TVec, b: &TVec, c: &TVec(a: &TVec, b: &TVec, c: &TVec, d: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn max4( + a: &TVec, + b: &TVec, + c: &TVec, + d: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ max2(&max2(a, b), &max2(c, d)) } @@ -89,7 +96,7 @@ pub fn max4(a: &TVec, b: &TVec, c: &TVec(x: &TVec, y: N) -> TVec - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { x.map(|x| na::inf(&x, &y)) } @@ -107,7 +114,7 @@ pub fn min(x: &TVec, y: N) -> TVec /// * [`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) } @@ -125,7 +132,7 @@ pub fn min2(x: &TVec, y: &TVec) -> TVec(a: &TVec, b: &TVec, c: &TVec) -> TVec - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { min2(&min2(a, b), c) } @@ -142,7 +149,14 @@ pub fn min3(a: &TVec, b: &TVec, c: &TVec(a: &TVec, b: &TVec, c: &TVec, d: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn min4( + a: &TVec, + b: &TVec, + c: &TVec, + d: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ min2(&min2(a, b), &min2(c, d)) } diff --git a/nalgebra-glm/src/ext/vector_relational.rs b/nalgebra-glm/src/ext/vector_relational.rs index cfd8649b..ee418588 100644 --- a/nalgebra-glm/src/ext/vector_relational.rs +++ b/nalgebra-glm/src/ext/vector_relational.rs @@ -1,7 +1,7 @@ -use na::{DefaultAllocator}; +use na::DefaultAllocator; -use traits::{Alloc, Number, Dimension}; use aliases::TVec; +use traits::{Alloc, Dimension, Number}; /// Component-wise approximate equality of two vectors, using a scalar epsilon. /// @@ -10,8 +10,14 @@ use aliases::TVec; /// * [`equal_eps_vec`](fn.equal_eps_vec.html) /// * [`not_equal_eps`](fn.not_equal_eps.html) /// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html) -pub fn equal_eps(x: &TVec, y: &TVec, epsilon: N) -> TVec - where DefaultAllocator: Alloc { +pub fn equal_eps( + x: &TVec, + y: &TVec, + epsilon: N, +) -> TVec +where + DefaultAllocator: Alloc, +{ x.zip_map(y, |x, y| abs_diff_eq!(x, y, epsilon = epsilon)) } @@ -22,8 +28,14 @@ pub fn equal_eps(x: &TVec, y: &TVec, epsilo /// * [`equal_eps`](fn.equal_eps.html) /// * [`not_equal_eps`](fn.not_equal_eps.html) /// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html) -pub fn equal_eps_vec(x: &TVec, y: &TVec, epsilon: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn equal_eps_vec( + x: &TVec, + y: &TVec, + epsilon: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ x.zip_zip_map(y, epsilon, |x, y, eps| abs_diff_eq!(x, y, epsilon = eps)) } @@ -34,8 +46,14 @@ pub fn equal_eps_vec(x: &TVec, y: &TVec, ep /// * [`equal_eps`](fn.equal_eps.html) /// * [`equal_eps_vec`](fn.equal_eps_vec.html) /// * [`not_equal_eps_vec`](fn.not_equal_eps_vec.html) -pub fn not_equal_eps(x: &TVec, y: &TVec, epsilon: N) -> TVec - where DefaultAllocator: Alloc { +pub fn not_equal_eps( + x: &TVec, + y: &TVec, + epsilon: N, +) -> TVec +where + DefaultAllocator: Alloc, +{ x.zip_map(y, |x, y| abs_diff_ne!(x, y, epsilon = epsilon)) } @@ -46,7 +64,13 @@ pub fn not_equal_eps(x: &TVec, y: &TVec, ep /// * [`equal_eps`](fn.equal_eps.html) /// * [`equal_eps_vec`](fn.equal_eps_vec.html) /// * [`not_equal_eps`](fn.not_equal_eps.html) -pub fn not_equal_eps_vec(x: &TVec, y: &TVec, epsilon: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn not_equal_eps_vec( + x: &TVec, + y: &TVec, + epsilon: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ x.zip_zip_map(y, epsilon, |x, y, eps| abs_diff_ne!(x, y, epsilon = eps)) } diff --git a/nalgebra-glm/src/geometric.rs b/nalgebra-glm/src/geometric.rs index 57355bbc..998709d6 100644 --- a/nalgebra-glm/src/geometric.rs +++ b/nalgebra-glm/src/geometric.rs @@ -1,7 +1,7 @@ -use na::{Real, DefaultAllocator}; +use na::{DefaultAllocator, Real}; -use traits::{Number, Alloc, Dimension}; use aliases::{TVec, TVec3}; +use traits::{Alloc, Dimension, Number}; /// The cross product of two vectors. pub fn cross(x: &TVec3, y: &TVec3) -> TVec3 { @@ -14,19 +14,25 @@ pub fn cross(x: &TVec3, y: &TVec3) -> TVec3 { /// /// * [`distance2`](fn.distance2.html) pub fn distance(p0: &TVec, p1: &TVec) -> N - where DefaultAllocator: Alloc { - (p1 - p0).norm() +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) } /// If `dot(nref, i) < 0.0`, return `n`, otherwise, return `-n`. -pub fn faceforward(n: &TVec, i: &TVec, nref: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn faceforward( + n: &TVec, + i: &TVec, + nref: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ if nref.dot(i) < N::zero() { n.clone() } else { @@ -44,7 +50,7 @@ pub fn faceforward(n: &TVec, i: &TVec, nref /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) pub fn length(x: &TVec) -> N - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { x.norm() } @@ -58,34 +64,32 @@ pub fn length(x: &TVec) -> N /// * [`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); if k < N::zero() { TVec::<_, D>::zeros() - } - else { + } else { i * eta - n * (eta * dot(n, i) + k.sqrt()) } } diff --git a/nalgebra-glm/src/gtc/epsilon.rs b/nalgebra-glm/src/gtc/epsilon.rs index 604ed3e4..4fd7138a 100644 --- a/nalgebra-glm/src/gtc/epsilon.rs +++ b/nalgebra-glm/src/gtc/epsilon.rs @@ -28,4 +28,4 @@ pub fn epsilon_not_equal(x: &TVec, y: &TVec pub fn epsilon_not_equal2>(x: N, y: N, epsilon: N) -> bool { abs_diff_ne!(x, y, epsilon = epsilon) } -*/ \ No newline at end of file +*/ diff --git a/nalgebra-glm/src/gtc/matrix_access.rs b/nalgebra-glm/src/gtc/matrix_access.rs index 2db271c1..3eabf5e2 100644 --- a/nalgebra-glm/src/gtc/matrix_access.rs +++ b/nalgebra-glm/src/gtc/matrix_access.rs @@ -1,7 +1,7 @@ -use na::{Scalar, DefaultAllocator}; +use na::{DefaultAllocator, Scalar}; +use aliases::{TMat, TVec}; use traits::{Alloc, Dimension}; -use aliases::{TVec, TMat}; /// The `index`-th column of the matrix `m`. /// @@ -10,8 +10,13 @@ use aliases::{TVec, TMat}; /// * [`row`](fn.row.html) /// * [`set_column`](fn.set_column.html) /// * [`set_row`](fn.set_row.html) -pub fn column(m: &TMat, index: usize) -> TVec - where DefaultAllocator: Alloc { +pub fn column( + m: &TMat, + index: usize, +) -> TVec +where + DefaultAllocator: Alloc, +{ m.column(index).into_owned() } @@ -22,8 +27,14 @@ pub fn column(m: &TMat, index: u /// * [`column`](fn.column.html) /// * [`row`](fn.row.html) /// * [`set_row`](fn.set_row.html) -pub fn set_column(m: &TMat, index: usize, x: &TVec) -> TMat - where DefaultAllocator: Alloc { +pub fn set_column( + m: &TMat, + index: usize, + x: &TVec, +) -> TMat +where + DefaultAllocator: Alloc, +{ let mut res = m.clone(); res.set_column(index, x); res @@ -37,7 +48,7 @@ pub fn set_column(m: &TMat, inde /// * [`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() } @@ -48,8 +59,14 @@ pub fn row(m: &TMat, index: usiz /// * [`column`](fn.column.html) /// * [`row`](fn.row.html) /// * [`set_column`](fn.set_column.html) -pub fn set_row(m: &TMat, index: usize, x: &TVec) -> TMat - where DefaultAllocator: Alloc { +pub fn set_row( + m: &TMat, + index: usize, + x: &TVec, +) -> TMat +where + DefaultAllocator: Alloc, +{ let mut res = m.clone(); res.set_row(index, &x.transpose()); res diff --git a/nalgebra-glm/src/gtc/matrix_inverse.rs b/nalgebra-glm/src/gtc/matrix_inverse.rs index 0ccfca86..4fc305e0 100644 --- a/nalgebra-glm/src/gtc/matrix_inverse.rs +++ b/nalgebra-glm/src/gtc/matrix_inverse.rs @@ -1,17 +1,19 @@ -use na::{Real, DefaultAllocator}; +use na::{DefaultAllocator, Real}; -use traits::{Alloc, Dimension}; use aliases::TMat; +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 { - m.try_inverse().unwrap_or_else(TMat::<_, D, D>::zeros).transpose() +where DefaultAllocator: Alloc { + m.try_inverse() + .unwrap_or_else(TMat::<_, D, D>::zeros) + .transpose() } diff --git a/nalgebra-glm/src/gtc/mod.rs b/nalgebra-glm/src/gtc/mod.rs index 2fd871b2..66db7b7a 100644 --- a/nalgebra-glm/src/gtc/mod.rs +++ b/nalgebra-glm/src/gtc/mod.rs @@ -1,17 +1,32 @@ //! (Reexported) Recommended features not specified by GLSL specification //pub use self::bitfield::*; -pub use self::constants::{e, two_pi, euler, four_over_pi, golden_ratio, half_pi, ln_ln_two, ln_ten, ln_two, one, one_over_pi, one_over_root_two, one_over_two_pi, quarter_pi, root_five, root_half_pi, root_ln_four, root_pi, root_three, root_two, root_two_pi, third, three_over_two_pi, two_over_pi, two_over_root_pi, two_thirds, zero}; +pub use self::constants::{ + e, euler, four_over_pi, golden_ratio, half_pi, ln_ln_two, ln_ten, ln_two, one, one_over_pi, + one_over_root_two, one_over_two_pi, quarter_pi, root_five, root_half_pi, root_ln_four, root_pi, + root_three, root_two, root_two_pi, third, three_over_two_pi, two_over_pi, two_over_root_pi, + two_pi, two_thirds, zero, +}; //pub use self::integer::*; pub use self::matrix_access::{column, row, set_column, set_row}; pub use self::matrix_inverse::{affine_inverse, inverse_transpose}; //pub use self::packing::*; //pub use self::reciprocal::*; //pub use self::round::*; -pub use self::type_ptr::{make_mat2, make_mat2x2, make_mat2x3, make_mat2x4, make_mat3, make_mat3x2, make_mat3x3, make_mat3x4, make_mat4, make_mat4x2, make_mat4x3, make_mat4x4, make_quat, make_vec1, make_vec2, make_vec3, make_vec4, value_ptr, value_ptr_mut, vec1_to_vec2, vec1_to_vec3, vec1_to_vec4, vec2_to_vec1, vec2_to_vec2, vec2_to_vec3, vec2_to_vec4, vec3_to_vec1, vec3_to_vec2, vec3_to_vec3, vec3_to_vec4, vec4_to_vec1, vec4_to_vec2, vec4_to_vec3, vec4_to_vec4, mat2_to_mat3, mat2_to_mat4, mat3_to_mat2, mat3_to_mat4, mat4_to_mat2, mat4_to_mat3}; +pub use self::type_ptr::{ + make_mat2, make_mat2x2, make_mat2x3, make_mat2x4, make_mat3, make_mat3x2, make_mat3x3, + make_mat3x4, make_mat4, make_mat4x2, make_mat4x3, make_mat4x4, make_quat, make_vec1, make_vec2, + make_vec3, make_vec4, mat2_to_mat3, mat2_to_mat4, mat3_to_mat2, mat3_to_mat4, mat4_to_mat2, + mat4_to_mat3, value_ptr, value_ptr_mut, vec1_to_vec2, vec1_to_vec3, vec1_to_vec4, vec2_to_vec1, + vec2_to_vec2, vec2_to_vec3, vec2_to_vec4, vec3_to_vec1, vec3_to_vec2, vec3_to_vec3, + vec3_to_vec4, vec4_to_vec1, vec4_to_vec2, vec4_to_vec3, vec4_to_vec4, +}; //pub use self::ulp::*; -pub use self::quaternion::{quat_cast, quat_euler_angles, quat_greater_than, quat_greater_than_equal, quat_less_than, quat_less_than_equal, quat_look_at, quat_look_at_lh, quat_look_at_rh, quat_pitch, quat_roll, quat_yaw}; - +pub use self::quaternion::{ + quat_cast, quat_euler_angles, quat_greater_than, quat_greater_than_equal, quat_less_than, + quat_less_than_equal, quat_look_at, quat_look_at_lh, quat_look_at_rh, quat_pitch, quat_roll, + quat_yaw, +}; //mod bitfield; mod constants; @@ -24,4 +39,4 @@ mod matrix_inverse; //mod round; mod type_ptr; //mod ulp; -mod quaternion; \ No newline at end of file +mod quaternion; diff --git a/nalgebra-glm/src/gtc/quaternion.rs b/nalgebra-glm/src/gtc/quaternion.rs index 15793605..fd3e22bf 100644 --- a/nalgebra-glm/src/gtc/quaternion.rs +++ b/nalgebra-glm/src/gtc/quaternion.rs @@ -1,7 +1,6 @@ -use na::{Real, U4, UnitQuaternion}; - -use aliases::{Qua, TVec, TVec3, TMat4}; +use na::{Real, UnitQuaternion, U4}; +use aliases::{Qua, TMat4, TVec, TVec3}; /// Euler angles of the quaternion `q` as (pitch, yaw, roll). pub fn quat_euler_angles(x: &Qua) -> TVec3 { diff --git a/nalgebra-glm/src/gtc/type_ptr.rs b/nalgebra-glm/src/gtc/type_ptr.rs index 96f87ef2..93a88e78 100644 --- a/nalgebra-glm/src/gtc/type_ptr.rs +++ b/nalgebra-glm/src/gtc/type_ptr.rs @@ -1,8 +1,10 @@ -use na::{Scalar, Real, DefaultAllocator, Quaternion}; +use na::{DefaultAllocator, Quaternion, Real, Scalar}; -use traits::{Number, Alloc, Dimension}; -use aliases::{Qua, TMat, TMat2, TMat3, TMat4, TVec1, TVec2, TVec3, TVec4, - TMat2x3, TMat2x4, TMat3x2, TMat3x4, TMat4x2, TMat4x3}; +use aliases::{ + Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1, + TVec2, TVec3, TVec4, +}; +use traits::{Alloc, Dimension, Number}; /// Creates a 2x2 matrix from a slice arranged in column-major order. pub fn make_mat2(ptr: &[N]) -> TMat2 { @@ -69,19 +71,12 @@ pub fn mat2_to_mat3(m: &TMat2) -> TMat3 { let _0 = N::zero(); let _1 = N::one(); - TMat3::new( - m.m11, m.m12, _0, - m.m21, m.m22, _0, - _0, _0, _1 - ) + TMat3::new(m.m11, m.m12, _0, m.m21, m.m22, _0, _0, _0, _1) } /// Converts a 3x3 matrix to a 2x2 matrix. pub fn mat3_to_mat2(m: &TMat3) -> TMat2 { - TMat2::new( - m.m11, m.m12, - m.m21, m.m22 - ) + TMat2::new(m.m11, m.m12, m.m21, m.m22) } /// Converts a 3x3 matrix to a 4x4 matrix. @@ -90,19 +85,14 @@ pub fn mat3_to_mat4(m: &TMat3) -> TMat4 { let _1 = N::one(); TMat4::new( - m.m11, m.m12, m.m13, _0, - m.m21, m.m22, m.m23, _0, - m.m31, m.m32, m.m33, _0, - _0, _0, _0, _1, + m.m11, m.m12, m.m13, _0, m.m21, m.m22, m.m23, _0, m.m31, m.m32, m.m33, _0, _0, _0, _0, _1, ) } /// Converts a 4x4 matrix to a 3x3 matrix. pub fn mat4_to_mat3(m: &TMat4) -> TMat3 { TMat3::new( - m.m11, m.m12, m.m13, - m.m21, m.m22, m.m23, - m.m31, m.m32, m.m33, + m.m11, m.m12, m.m13, m.m21, m.m22, m.m23, m.m31, m.m32, m.m33, ) } @@ -112,19 +102,13 @@ pub fn mat2_to_mat4(m: &TMat2) -> TMat4 { let _1 = N::one(); TMat4::new( - m.m11, m.m12, _0, _0, - m.m21, m.m22, _0, _0, - _0, _0, _1, _0, - _0, _0, _0, _1, + m.m11, m.m12, _0, _0, m.m21, m.m22, _0, _0, _0, _0, _1, _0, _0, _0, _0, _1, ) } /// Converts a 4x4 matrix to a 2x2 matrix. pub fn mat4_to_mat2(m: &TMat4) -> TMat2 { - TMat2::new( - m.m11, m.m12, - m.m21, m.m22, - ) + TMat2::new(m.m11, m.m12, m.m21, m.m22) } /// Creates a quaternion from a slice arranged as `[x, y, z, w]`. @@ -400,13 +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 56d4cff4..338f4380 100644 --- a/nalgebra-glm/src/gtx/component_wise.rs +++ b/nalgebra-glm/src/gtx/component_wise.rs @@ -1,7 +1,7 @@ use na::{self, DefaultAllocator}; -use traits::{Number, Alloc, Dimension}; use aliases::TMat; +use traits::{Alloc, Dimension, Number}; /// The sum of every component of the given matrix or vector. /// @@ -22,7 +22,7 @@ use aliases::TMat; /// * [`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) } @@ -49,7 +49,7 @@ pub fn comp_add(m: &TMat) -> N /// * [`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)) } @@ -76,7 +76,7 @@ pub fn comp_max(m: &TMat) -> N /// * [`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)) } @@ -99,7 +99,7 @@ pub fn comp_min(m: &TMat) -> N /// * [`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/exterior_product.rs b/nalgebra-glm/src/gtx/exterior_product.rs index 228be61e..cc58597b 100644 --- a/nalgebra-glm/src/gtx/exterior_product.rs +++ b/nalgebra-glm/src/gtx/exterior_product.rs @@ -1,7 +1,7 @@ -use traits::Number; use aliases::TVec2; +use traits::Number; /// The 2D perpendicular product between two vectors. pub fn cross2d(v: &TVec2, u: &TVec2) -> N { v.perp(u) -} \ No newline at end of file +} diff --git a/nalgebra-glm/src/gtx/handed_coordinate_space.rs b/nalgebra-glm/src/gtx/handed_coordinate_space.rs index e499207f..ee1979ad 100644 --- a/nalgebra-glm/src/gtx/handed_coordinate_space.rs +++ b/nalgebra-glm/src/gtx/handed_coordinate_space.rs @@ -1,5 +1,5 @@ -use traits::Number; use aliases::TVec3; +use traits::Number; /// Returns `true` if `{a, b, c}` forms a left-handed trihedron. /// diff --git a/nalgebra-glm/src/gtx/matrix_operation.rs b/nalgebra-glm/src/gtx/matrix_operation.rs index 17ea4bb9..954607ef 100644 --- a/nalgebra-glm/src/gtx/matrix_operation.rs +++ b/nalgebra-glm/src/gtx/matrix_operation.rs @@ -1,5 +1,7 @@ +use aliases::{ + TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec2, TVec3, TVec4, +}; use traits::Number; -use aliases::{TVec2, TVec3, TVec4, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3}; /// Builds a 2x2 diagonal matrix. /// diff --git a/nalgebra-glm/src/gtx/mod.rs b/nalgebra-glm/src/gtx/mod.rs index 7dc66bda..b06f3998 100644 --- a/nalgebra-glm/src/gtx/mod.rs +++ b/nalgebra-glm/src/gtx/mod.rs @@ -1,25 +1,37 @@ //! (Reexported) Experimental features not specified by GLSL specification. - pub use self::component_wise::{comp_add, comp_max, comp_min, comp_mul}; //pub use self::euler_angles::*; -pub use self::exterior_product::{cross2d}; +pub use self::exterior_product::cross2d; pub use self::handed_coordinate_space::{left_handed, right_handed}; pub use self::matrix_cross_product::{matrix_cross, matrix_cross3}; -pub use self::matrix_operation::{diagonal2x2, diagonal2x3, diagonal2x4, diagonal3x2, diagonal3x3, diagonal3x4, diagonal4x2, diagonal4x3, diagonal4x4}; +pub use self::matrix_operation::{ + diagonal2x2, diagonal2x3, diagonal2x4, diagonal3x2, diagonal3x3, diagonal3x4, diagonal4x2, + diagonal4x3, diagonal4x4, +}; pub use self::norm::{distance2, l1_distance, l1_norm, l2_distance, l2_norm, length2, magnitude2}; -pub use self::normal::{triangle_normal}; +pub use self::normal::triangle_normal; pub use self::normalize_dot::{fast_normalize_dot, normalize_dot}; +pub use self::quaternion::{ + mat3_to_quat, quat_cross_vec, quat_extract_real_component, quat_fast_mix, quat_identity, + quat_inv_cross_vec, quat_length2, quat_magnitude2, quat_rotate_vec, quat_rotate_vec3, + quat_rotation, quat_short_mix, quat_to_mat3, quat_to_mat4, to_quat, +}; pub use self::rotate_normalized_axis::{quat_rotate_normalized_axis, rotate_normalized_axis}; -pub use self::rotate_vector::{orientation, rotate_vec2, rotate_vec3, rotate_vec4, rotate_x_vec4, rotate_x_vec3, rotate_y_vec4, rotate_y_vec3, rotate_z_vec4, rotate_z_vec3, slerp}; -pub use self::transform::{rotation, scaling, translation, rotation2d, scaling2d, translation2d}; -pub use self::transform2::{proj, proj2d, reflect, reflect2d, scale_bias, scale_bias_matrix, shear2d_x, shear_x, shear_y, shear2d_y, shear_z}; +pub use self::rotate_vector::{ + orientation, rotate_vec2, rotate_vec3, rotate_vec4, rotate_x_vec3, rotate_x_vec4, + rotate_y_vec3, rotate_y_vec4, rotate_z_vec3, rotate_z_vec4, slerp, +}; +pub use self::transform::{rotation, rotation2d, scaling, scaling2d, translation, translation2d}; +pub use self::transform2::{ + proj, proj2d, reflect, reflect2d, scale_bias, scale_bias_matrix, shear2d_x, shear2d_y, shear_x, + shear_y, shear_z, +}; pub use self::transform2d::{rotate2d, scale2d, translate2d}; -pub use self::vector_angle::{angle}; -pub use self::vector_query::{are_collinear, are_collinear2d, are_orthogonal, is_comp_null, is_normalized, is_null}; -pub use self::quaternion::{quat_to_mat3, quat_rotate_vec, quat_cross_vec, mat3_to_quat, quat_extract_real_component, quat_fast_mix, quat_inv_cross_vec, quat_length2, quat_magnitude2, quat_identity, quat_rotate_vec3, quat_rotation, quat_short_mix, quat_to_mat4, to_quat}; - - +pub use self::vector_angle::angle; +pub use self::vector_query::{ + are_collinear, are_collinear2d, are_orthogonal, is_comp_null, is_normalized, is_null, +}; mod component_wise; //mod euler_angles; @@ -30,6 +42,7 @@ mod matrix_operation; mod norm; mod normal; mod normalize_dot; +mod quaternion; mod rotate_normalized_axis; mod rotate_vector; mod transform; @@ -37,4 +50,3 @@ mod transform2; mod transform2d; mod vector_angle; mod vector_query; -mod quaternion; \ No newline at end of file diff --git a/nalgebra-glm/src/gtx/norm.rs b/nalgebra-glm/src/gtx/norm.rs index 2a40c02a..0a287530 100644 --- a/nalgebra-glm/src/gtx/norm.rs +++ b/nalgebra-glm/src/gtx/norm.rs @@ -1,7 +1,7 @@ -use na::{Real, DefaultAllocator}; +use na::{DefaultAllocator, Real}; -use traits::{Alloc, Dimension}; use aliases::TVec; +use traits::{Alloc, Dimension}; /// The squared distance between two points. /// @@ -9,7 +9,7 @@ use aliases::TVec; /// /// * [`distance`](fn.distance.html) pub fn distance2(p0: &TVec, p1: &TVec) -> N - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { (p1 - p0).norm_squared() } @@ -21,7 +21,7 @@ pub fn distance2(p0: &TVec, p1: &TVec) -> N /// * [`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)) } @@ -36,7 +36,7 @@ pub fn l1_distance(x: &TVec, y: &TVec) -> N /// * [`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()) } @@ -55,7 +55,7 @@ pub fn l1_norm(v: &TVec) -> N /// * [`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)) } @@ -76,7 +76,7 @@ pub fn l2_distance(x: &TVec, y: &TVec) -> N /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) pub fn l2_norm(x: &TVec) -> N - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { x.norm() } @@ -92,7 +92,7 @@ pub fn l2_norm(x: &TVec) -> N /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) pub fn length2(x: &TVec) -> N - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { x.norm_squared() } @@ -108,7 +108,7 @@ pub fn length2(x: &TVec) -> N /// * [`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/normal.rs b/nalgebra-glm/src/gtx/normal.rs index 6ae70ab7..63fc9246 100644 --- a/nalgebra-glm/src/gtx/normal.rs +++ b/nalgebra-glm/src/gtx/normal.rs @@ -7,4 +7,4 @@ use aliases::TVec3; /// The normal is computed as the normalized vector `cross(p2 - p1, p3 - p1)`. pub fn triangle_normal(p1: &TVec3, p2: &TVec3, p3: &TVec3) -> TVec3 { (p2 - p1).cross(&(p3 - p1)).normalize() -} \ No newline at end of file +} diff --git a/nalgebra-glm/src/gtx/normalize_dot.rs b/nalgebra-glm/src/gtx/normalize_dot.rs index 4c67aee3..df52d2c0 100644 --- a/nalgebra-glm/src/gtx/normalize_dot.rs +++ b/nalgebra-glm/src/gtx/normalize_dot.rs @@ -1,7 +1,7 @@ -use na::{Real, DefaultAllocator}; +use na::{DefaultAllocator, Real}; -use traits::{Dimension, Alloc}; use aliases::TVec; +use traits::{Alloc, Dimension}; /// The dot product of the normalized version of `x` and `y`. /// @@ -11,7 +11,7 @@ use aliases::TVec; /// /// * [`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()) } @@ -22,7 +22,7 @@ pub fn fast_normalize_dot(x: &TVec, y: &TVec) /// /// * [`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/quaternion.rs b/nalgebra-glm/src/gtx/quaternion.rs index a490352d..5762b58d 100644 --- a/nalgebra-glm/src/gtx/quaternion.rs +++ b/nalgebra-glm/src/gtx/quaternion.rs @@ -1,4 +1,4 @@ -use na::{Real, Unit, Rotation3, UnitQuaternion, U3}; +use na::{Real, Rotation3, Unit, UnitQuaternion, U3}; use aliases::{Qua, TMat3, TMat4, TVec3, TVec4}; @@ -19,7 +19,9 @@ pub fn quat_extract_real_component(q: &Qua) -> N { /// Normalized linear interpolation between two quaternions. pub fn quat_fast_mix(x: &Qua, y: &Qua, a: N) -> Qua { - Unit::new_unchecked(*x).nlerp(&Unit::new_unchecked(*y), a).unwrap() + Unit::new_unchecked(*x) + .nlerp(&Unit::new_unchecked(*y), a) + .unwrap() } //pub fn quat_intermediate(prev: &Qua, curr: &Qua, next: &Qua) -> Qua { @@ -54,12 +56,16 @@ pub fn quat_rotate_vec(q: &Qua, v: &TVec4) -> TVec4 { /// The rotation required to align `orig` to `dest`. pub fn quat_rotation(orig: &TVec3, dest: &TVec3) -> Qua { - UnitQuaternion::rotation_between(orig, dest).unwrap_or_else(UnitQuaternion::identity).unwrap() + UnitQuaternion::rotation_between(orig, dest) + .unwrap_or_else(UnitQuaternion::identity) + .unwrap() } /// The spherical linear interpolation between two quaternions. pub fn quat_short_mix(x: &Qua, y: &Qua, a: N) -> Qua { - Unit::new_normalize(*x).slerp(&Unit::new_normalize(*y), a).unwrap() + Unit::new_normalize(*x) + .slerp(&Unit::new_normalize(*y), a) + .unwrap() } //pub fn quat_squad(q1: &Qua, q2: &Qua, s1: &Qua, s2: &Qua, h: N) -> Qua { @@ -68,7 +74,9 @@ pub fn quat_short_mix(x: &Qua, y: &Qua, a: N) -> Qua { /// Converts a quaternion to a rotation matrix. pub fn quat_to_mat3(x: &Qua) -> TMat3 { - UnitQuaternion::new_unchecked(*x).to_rotation_matrix().unwrap() + UnitQuaternion::new_unchecked(*x) + .to_rotation_matrix() + .unwrap() } /// Converts a quaternion to a rotation matrix in homogenous coordinates. @@ -87,4 +95,3 @@ pub fn to_quat(x: &TMat4) -> Qua { let rot = x.fixed_slice::(0, 0).into_owned(); mat3_to_quat(&rot) } - diff --git a/nalgebra-glm/src/gtx/rotate_vector.rs b/nalgebra-glm/src/gtx/rotate_vector.rs index 76dcdbfa..0855244d 100644 --- a/nalgebra-glm/src/gtx/rotate_vector.rs +++ b/nalgebra-glm/src/gtx/rotate_vector.rs @@ -1,6 +1,6 @@ use na::{Real, Rotation3, Unit, UnitComplex}; -use aliases::{TVec2, TVec3, TVec4, TMat4}; +use aliases::{TMat4, TVec2, TVec3, TVec4}; /// Build the rotation matrix needed to align `normal` and `up`. pub fn orientation(normal: &TVec3, up: &TVec3) -> TMat4 { @@ -58,5 +58,7 @@ pub fn rotate_z_vec4(v: &TVec4, angle: N) -> TVec4 { /// Computes a spherical linear interpolation between the vectors `x` and `y` assumed to be normalized. pub fn slerp(x: &TVec3, y: &TVec3, a: N) -> TVec3 { - Unit::new_unchecked(*x).slerp(&Unit::new_unchecked(*y), a).unwrap() + Unit::new_unchecked(*x) + .slerp(&Unit::new_unchecked(*y), a) + .unwrap() } diff --git a/nalgebra-glm/src/gtx/transform.rs b/nalgebra-glm/src/gtx/transform.rs index 3ebc958d..85554fe5 100644 --- a/nalgebra-glm/src/gtx/transform.rs +++ b/nalgebra-glm/src/gtx/transform.rs @@ -1,7 +1,7 @@ -use na::{Real, Unit, Rotation2, Rotation3}; +use na::{Real, Rotation2, Rotation3, Unit}; +use aliases::{TMat3, TMat4, TVec2, TVec3}; use traits::Number; -use aliases::{TVec3, TVec2, TMat3, TMat4}; /// A rotation 4 * 4 matrix created from an axis of 3 scalars and an angle expressed in radians. /// @@ -42,7 +42,6 @@ pub fn translation(v: &TVec3) -> TMat4 { TMat4::new_translation(v) } - /// A rotation 3 * 3 matrix created from an angle expressed in radians. /// /// # See also: diff --git a/nalgebra-glm/src/gtx/transform2.rs b/nalgebra-glm/src/gtx/transform2.rs index 0bb19e95..fa5533f7 100644 --- a/nalgebra-glm/src/gtx/transform2.rs +++ b/nalgebra-glm/src/gtx/transform2.rs @@ -1,7 +1,7 @@ use na::{U2, U3}; +use aliases::{TMat3, TMat4, TVec2, TVec3}; use traits::Number; -use aliases::{TVec2, TVec3, TMat3, TMat4}; /// Build planar projection matrix along normal axis and right-multiply it to `m`. pub fn proj2d(m: &TMat3, normal: &TVec2) -> TMat3 { @@ -57,10 +57,7 @@ pub fn scale_bias_matrix(scale: N, bias: N) -> TMat4 { let _1 = N::one(); TMat4::new( - scale, _0, _0, bias, - _0, scale, _0, bias, - _0, _0, scale, bias, - _0, _0, _0, _1, + scale, _0, _0, bias, _0, scale, _0, bias, _0, _0, scale, bias, _0, _0, _0, _1, ) } @@ -74,11 +71,7 @@ pub fn shear2d_x(m: &TMat3, y: N) -> TMat3 { let _0 = N::zero(); let _1 = N::one(); - let shear = TMat3::new( - _1, y, _0, - _0, _1, _0, - _0, _0, _1 - ); + let shear = TMat3::new(_1, y, _0, _0, _1, _0, _0, _0, _1); m * shear } @@ -86,12 +79,7 @@ pub fn shear2d_x(m: &TMat3, y: N) -> TMat3 { pub fn shear_x(m: &TMat4, y: N, z: N) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); - let shear = TMat4::new( - _1, _0, _0, _0, - y, _1, _0, _0, - z, _0, _1, _0, - _0, _0, _0, _1, - ); + let shear = TMat4::new(_1, _0, _0, _0, y, _1, _0, _0, z, _0, _1, _0, _0, _0, _0, _1); m * shear } @@ -101,11 +89,7 @@ pub fn shear2d_y(m: &TMat3, x: N) -> TMat3 { let _0 = N::zero(); let _1 = N::one(); - let shear = TMat3::new( - _1, _0, _0, - x, _1, _0, - _0, _0, _1 - ); + let shear = TMat3::new(_1, _0, _0, x, _1, _0, _0, _0, _1); m * shear } @@ -113,12 +97,7 @@ pub fn shear2d_y(m: &TMat3, x: N) -> TMat3 { pub fn shear_y(m: &TMat4, x: N, z: N) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); - let shear = TMat4::new( - _1, x, _0, _0, - _0, _1, _0, _0, - _0, z, _1, _0, - _0, _0, _0, _1, - ); + let shear = TMat4::new(_1, x, _0, _0, _0, _1, _0, _0, _0, z, _1, _0, _0, _0, _0, _1); m * shear } @@ -127,12 +106,7 @@ pub fn shear_y(m: &TMat4, x: N, z: N) -> TMat4 { pub fn shear_z(m: &TMat4, x: N, y: N) -> TMat4 { let _0 = N::zero(); let _1 = N::one(); - let shear = TMat4::new( - _1, _0, x, _0, - _0, _1, y, _0, - _0, _0, _1, _0, - _0, _0, _0, _1, - ); + let shear = TMat4::new(_1, _0, x, _0, _0, _1, y, _0, _0, _0, _1, _0, _0, _0, _0, _1); m * shear } diff --git a/nalgebra-glm/src/gtx/transform2d.rs b/nalgebra-glm/src/gtx/transform2d.rs index 92aa7709..3d401f56 100644 --- a/nalgebra-glm/src/gtx/transform2d.rs +++ b/nalgebra-glm/src/gtx/transform2d.rs @@ -1,7 +1,7 @@ use na::{Real, UnitComplex}; -use traits::Number; use aliases::{TMat3, TVec2}; +use traits::Number; /// Builds a 2D rotation matrix from an angle and right-multiply it to `m`. /// diff --git a/nalgebra-glm/src/gtx/vector_angle.rs b/nalgebra-glm/src/gtx/vector_angle.rs index 22deaaf5..1ebb39a4 100644 --- a/nalgebra-glm/src/gtx/vector_angle.rs +++ b/nalgebra-glm/src/gtx/vector_angle.rs @@ -1,12 +1,11 @@ use na::{DefaultAllocator, Real}; -use traits::{Dimension, Alloc}; use aliases::TVec; - +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 c4517803..f408a4b3 100644 --- a/nalgebra-glm/src/gtx/vector_query.rs +++ b/nalgebra-glm/src/gtx/vector_query.rs @@ -1,7 +1,7 @@ -use na::{Real, DefaultAllocator}; +use na::{DefaultAllocator, Real}; -use traits::{Number, Dimension, Alloc}; use aliases::{TVec, TVec2, TVec3}; +use traits::{Alloc, Dimension, Number}; /// Returns `true` if two vectors are collinear (up to an epsilon). /// @@ -22,8 +22,14 @@ 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 - where DefaultAllocator: Alloc { +pub fn are_orthogonal( + v0: &TVec, + v1: &TVec, + epsilon: N, +) -> bool +where + DefaultAllocator: Alloc, +{ abs_diff_eq!(v0.dot(v1), N::zero(), epsilon = epsilon) } @@ -34,18 +40,18 @@ pub fn are_orthogonal(v0: &TVec, v1: &TVec, /// 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 dc485846..495b61d9 100644 --- a/nalgebra-glm/src/lib.rs +++ b/nalgebra-glm/src/lib.rs @@ -1,114 +1,114 @@ /*! # nalgebra-glm − nalgebra in _easy mode_ - **nalgebra-glm** is a GLM-like interface for the **nalgebra** general-purpose linear algebra library. - [GLM](https://glm.g-truc.net) itself is a popular C++ linear algebra library essentially targeting computer graphics. Therefore - **nalgebra-glm** draws inspiration from GLM to define a nice and easy-to-use API for simple graphics application. + **nalgebra-glm** is a GLM-like interface for the **nalgebra** general-purpose linear algebra library. + [GLM](https://glm.g-truc.net) itself is a popular C++ linear algebra library essentially targeting computer graphics. Therefore + **nalgebra-glm** draws inspiration from GLM to define a nice and easy-to-use API for simple graphics application. - All the types of **nalgebra-glm** are aliases of types from **nalgebra**. Therefore there is a complete and - seamless inter-operability between both. + All the types of **nalgebra-glm** are aliases of types from **nalgebra**. Therefore there is a complete and + seamless inter-operability between both. - ## Getting started - First of all, you should start by taking a look at the official [GLM API documentation](http://glm.g-truc.net/0.9.9/api/index.html) - since **nalgebra-glm** implements a large subset of it. To use **nalgebra-glm** to your project, you - should add it as a dependency to your `Crates.toml`: + ## Getting started + First of all, you should start by taking a look at the official [GLM API documentation](http://glm.g-truc.net/0.9.9/api/index.html) + since **nalgebra-glm** implements a large subset of it. To use **nalgebra-glm** to your project, you + should add it as a dependency to your `Crates.toml`: - ```toml - [dependencies] - nalgebra-glm = "0.1" - ``` + ```toml + [dependencies] + nalgebra-glm = "0.1" + ``` - Then, you should add an `extern crate` statement to your `lib.rs` or `main.rs` file. It is **strongly - recommended** to add a crate alias to `glm` as well so that you will be able to call functions of - **nalgebra-glm** using the module prefix `glm::`. For example you will write `glm::rotate(...)` instead - of the more verbose `nalgebra_glm::rotate(...)`: + Then, you should add an `extern crate` statement to your `lib.rs` or `main.rs` file. It is **strongly + recommended** to add a crate alias to `glm` as well so that you will be able to call functions of + **nalgebra-glm** using the module prefix `glm::`. For example you will write `glm::rotate(...)` instead + of the more verbose `nalgebra_glm::rotate(...)`: - ```rust - extern crate nalgebra_glm as glm; - ``` + ```rust + extern crate nalgebra_glm as glm; + ``` - ## Features overview - **nalgebra-glm** supports most linear-algebra related features of the C++ GLM library. Mathematically - speaking, it supports all the common transformations like rotations, translations, scaling, shearing, - and projections but operating in homogeneous coordinates. This means all the 2D transformations are - expressed as 3x3 matrices, and all the 3D transformations as 4x4 matrices. This is less computationally-efficient - and memory-efficient than nalgebra's [transformation types](https://www.nalgebra.org/points_and_transformations/#transformations), - but this has the benefit of being simpler to use. - ### Main differences compared to GLM - While **nalgebra-glm** follows the feature line of the C++ GLM library, quite a few differences - remain and they are mostly syntactic. The main ones are: - * All function names use `snake_case`, which is the Rust convention. - * All type names use `CamelCase`, which is the Rust convention. - * All function arguments, except for scalars, are all passed by-reference. - * The most generic vector and matrix types are [`TMat`](type.TMat.html) and [`TVec`](type.TVec.html) instead of `mat` and `vec`. - * Some feature are not yet implemented and should be added in the future. In particular, no packing - functions are available. - * A few features are not implemented and will never be. This includes functions related to color - spaces, and closest points computations. Other crates should be used for those. For example, closest - points computation can be handled by the [ncollide](https://ncollide.org) project. + ## Features overview + **nalgebra-glm** supports most linear-algebra related features of the C++ GLM library. Mathematically + speaking, it supports all the common transformations like rotations, translations, scaling, shearing, + and projections but operating in homogeneous coordinates. This means all the 2D transformations are + expressed as 3x3 matrices, and all the 3D transformations as 4x4 matrices. This is less computationally-efficient + and memory-efficient than nalgebra's [transformation types](https://www.nalgebra.org/points_and_transformations/#transformations), + but this has the benefit of being simpler to use. + ### Main differences compared to GLM + While **nalgebra-glm** follows the feature line of the C++ GLM library, quite a few differences + remain and they are mostly syntactic. The main ones are: + * All function names use `snake_case`, which is the Rust convention. + * All type names use `CamelCase`, which is the Rust convention. + * All function arguments, except for scalars, are all passed by-reference. + * The most generic vector and matrix types are [`TMat`](type.TMat.html) and [`TVec`](type.TVec.html) instead of `mat` and `vec`. + * Some feature are not yet implemented and should be added in the future. In particular, no packing + functions are available. + * A few features are not implemented and will never be. This includes functions related to color + spaces, and closest points computations. Other crates should be used for those. For example, closest + points computation can be handled by the [ncollide](https://ncollide.org) project. - In addition, because Rust does not allows function overloading, all functions must be given a unique name. - Here are a few rules chosen arbitrarily for **nalgebra-glm**: - * Functions operating in 2d will usually end with the `2d` suffix, e.g., [`glm::rotate2d`](fn.rotate2d.html) is for 2D while [`glm::rotate`](fn.rotate.html) is for 3D. - * Functions operating on vectors will often end with the `_vec` suffix, possibly followed by the dimension of vector, e.g., [`glm::rotate_vec2`](fn.rotate_vec2.html). - * Every function related to quaternions start with the `quat_` prefix, e.g., [`glm::quat_dot(q1, q2)`](fn.quat_dot.html). - * All the conversion functions have unique names as described [below](#conversions). - ### Vector and matrix construction - Vectors, matrices, and quaternions can be constructed using several approaches: - * Using functions with the same name as their type in lower-case. For example [`glm::vec3(x, y, z)`](fn.vec3.html) will create a 3D vector. - * Using the `::new` constructor. For example [`Vec3::new(x, y, z)`](../nalgebra/base/type.MatrixMN.html#method.new-27) will create a 3D vector. - * Using the functions prefixed by `make_` to build a vector a matrix from a slice. For example [`glm::make_vec3(&[x, y, z])`](fn.make_vec3.html) will create a 3D vector. - Keep in mind that constructing a matrix using this type of functions require its components to be arranged in column-major order on the slice. - * Using a geometric construction function. For example [`glm::rotation(angle, axis)`](fn.rotation.html) will build a 4x4 homogeneous rotation matrix from an angle (in radians) and an axis. - * Using swizzling and conversions as described in the next sections. - ### Swizzling - Vector swizzling is a native feature of **nalgebra** itself. Therefore, you can use it with all - the vectors of **nalgebra-glm** as well. Swizzling is supported as methods and works only up to - dimension 3, i.e., you can only refer to the components `x`, `y` and `z` and can only create a - 2D or 3D vector using this technique. Here is some examples, assuming `v` is a vector with float - components here: - * `v.xx()` is equivalent to `glm::vec2(v.x, v.x)` and to `Vec2::new(v.x, v.x)`. - * `v.zx()` is equivalent to `glm::vec2(v.z, v.x)` and to `Vec2::new(v.z, v.x)`. - * `v.yxz()` is equivalent to `glm::vec3(v.y, v.x, v.z)` and to `Vec3::new(v.y, v.x, v.z)`. - * `v.zzy()` is equivalent to `glm::vec3(v.z, v.z, v.y)` and to `Vec3::new(v.z, v.z, v.y)`. + In addition, because Rust does not allows function overloading, all functions must be given a unique name. + Here are a few rules chosen arbitrarily for **nalgebra-glm**: + * Functions operating in 2d will usually end with the `2d` suffix, e.g., [`glm::rotate2d`](fn.rotate2d.html) is for 2D while [`glm::rotate`](fn.rotate.html) is for 3D. + * Functions operating on vectors will often end with the `_vec` suffix, possibly followed by the dimension of vector, e.g., [`glm::rotate_vec2`](fn.rotate_vec2.html). + * Every function related to quaternions start with the `quat_` prefix, e.g., [`glm::quat_dot(q1, q2)`](fn.quat_dot.html). + * All the conversion functions have unique names as described [below](#conversions). + ### Vector and matrix construction + Vectors, matrices, and quaternions can be constructed using several approaches: + * Using functions with the same name as their type in lower-case. For example [`glm::vec3(x, y, z)`](fn.vec3.html) will create a 3D vector. + * Using the `::new` constructor. For example [`Vec3::new(x, y, z)`](../nalgebra/base/type.MatrixMN.html#method.new-27) will create a 3D vector. + * Using the functions prefixed by `make_` to build a vector a matrix from a slice. For example [`glm::make_vec3(&[x, y, z])`](fn.make_vec3.html) will create a 3D vector. + Keep in mind that constructing a matrix using this type of functions require its components to be arranged in column-major order on the slice. + * Using a geometric construction function. For example [`glm::rotation(angle, axis)`](fn.rotation.html) will build a 4x4 homogeneous rotation matrix from an angle (in radians) and an axis. + * Using swizzling and conversions as described in the next sections. + ### Swizzling + Vector swizzling is a native feature of **nalgebra** itself. Therefore, you can use it with all + the vectors of **nalgebra-glm** as well. Swizzling is supported as methods and works only up to + dimension 3, i.e., you can only refer to the components `x`, `y` and `z` and can only create a + 2D or 3D vector using this technique. Here is some examples, assuming `v` is a vector with float + components here: + * `v.xx()` is equivalent to `glm::vec2(v.x, v.x)` and to `Vec2::new(v.x, v.x)`. + * `v.zx()` is equivalent to `glm::vec2(v.z, v.x)` and to `Vec2::new(v.z, v.x)`. + * `v.yxz()` is equivalent to `glm::vec3(v.y, v.x, v.z)` and to `Vec3::new(v.y, v.x, v.z)`. + * `v.zzy()` is equivalent to `glm::vec3(v.z, v.z, v.y)` and to `Vec3::new(v.z, v.z, v.y)`. - Any combination of two or three components picked among `x`, `y`, and `z` will work. - ### Conversions - It is often useful to convert one algebraic type to another. There are two main approaches for converting - between types in `nalgebra-glm`: - * Using function with the form `type1_to_type2` in order to convert an instance of `type1` into an instance of `type2`. - For example [`glm::mat3_to_mat4(m)`](fn.mat3_to_mat4.html) will convert the 3x3 matrix `m` to a 4x4 matrix by appending one column on the right - and one row on the left. Those now row and columns are filled with 0 except for the diagonal element which is set to 1. - * Using one of the [`convert`](fn.convert.html), [`try_convert`](fn.try_convert.html), or [`convert_unchecked`](fn.convert_unchecked.html) functions. - These functions are directly re-exported from nalgebra and are extremely versatile: - 1. The `convert` function can convert any type (especially geometric types from nalgebra like `Isometry3`) into another algebraic type which is equivalent but more general. For example, - `let sim: Similarity3<_> = na::convert(isometry)` will convert an `Isometry3` into a `Similarity3`. - In addition, `let mat: Mat4 = glm::convert(isometry)` will convert an `Isometry3` to a 4x4 matrix. This will also convert the scalar types, - therefore: `let mat: DMat4 = glm::convert(m)` where `m: Mat4` will work. However, conversion will not work the other way round: you - can't convert a `Matrix4` to an `Isometry3` using `glm::convert` because that could cause unexpected results if the matrix does - not complies to the requirements of the isometry. - 2. If you need this kind of conversions anyway, you can use `try_convert` which will test if the object being converted complies with the algebraic requirements of the target type. - This will return `None` if the requirements are not satisfied. - 3. The `convert_unchecked` will ignore those tests and always perform the conversion, even if that breaks the invariants of the target type. - This must be used with care! This is actually the recommended method to convert between homogeneous transformations generated by `nalgebra-glm` and - specific transformation types from **nalgebra** like `Isometry3`. Just be careful you know your conversions make sense. + Any combination of two or three components picked among `x`, `y`, and `z` will work. + ### Conversions + It is often useful to convert one algebraic type to another. There are two main approaches for converting + between types in `nalgebra-glm`: + * Using function with the form `type1_to_type2` in order to convert an instance of `type1` into an instance of `type2`. + For example [`glm::mat3_to_mat4(m)`](fn.mat3_to_mat4.html) will convert the 3x3 matrix `m` to a 4x4 matrix by appending one column on the right + and one row on the left. Those now row and columns are filled with 0 except for the diagonal element which is set to 1. + * Using one of the [`convert`](fn.convert.html), [`try_convert`](fn.try_convert.html), or [`convert_unchecked`](fn.convert_unchecked.html) functions. + These functions are directly re-exported from nalgebra and are extremely versatile: + 1. The `convert` function can convert any type (especially geometric types from nalgebra like `Isometry3`) into another algebraic type which is equivalent but more general. For example, + `let sim: Similarity3<_> = na::convert(isometry)` will convert an `Isometry3` into a `Similarity3`. + In addition, `let mat: Mat4 = glm::convert(isometry)` will convert an `Isometry3` to a 4x4 matrix. This will also convert the scalar types, + therefore: `let mat: DMat4 = glm::convert(m)` where `m: Mat4` will work. However, conversion will not work the other way round: you + can't convert a `Matrix4` to an `Isometry3` using `glm::convert` because that could cause unexpected results if the matrix does + not complies to the requirements of the isometry. + 2. If you need this kind of conversions anyway, you can use `try_convert` which will test if the object being converted complies with the algebraic requirements of the target type. + This will return `None` if the requirements are not satisfied. + 3. The `convert_unchecked` will ignore those tests and always perform the conversion, even if that breaks the invariants of the target type. + This must be used with care! This is actually the recommended method to convert between homogeneous transformations generated by `nalgebra-glm` and + specific transformation types from **nalgebra** like `Isometry3`. Just be careful you know your conversions make sense. - ### Should I use nalgebra or nalgebra-glm? - Well that depends on your tastes and your background. **nalgebra** is more powerful overall since it allows stronger typing, - and goes much further than simple computer graphics math. However, has a bit of a learning curve for - those not used to the abstract mathematical concepts for transformations. **nalgebra-glm** however - have more straightforward functions and benefit from the various tutorials existing on the internet - for the original C++ GLM library. + ### Should I use nalgebra or nalgebra-glm? + Well that depends on your tastes and your background. **nalgebra** is more powerful overall since it allows stronger typing, + and goes much further than simple computer graphics math. However, has a bit of a learning curve for + those not used to the abstract mathematical concepts for transformations. **nalgebra-glm** however + have more straightforward functions and benefit from the various tutorials existing on the internet + for the original C++ GLM library. - Overall, if you are already used to the C++ GLM library, or to working with homogeneous coordinates (like 4D - matrices for 3D transformations), then you will have more success with **nalgebra-glm**. If on the other - hand you prefer more rigorous treatments of transformations, with type-level restrictions, then go for **nalgebra**. - If you need dynamically-sized matrices, you should go for **nalgebra** as well. + Overall, if you are already used to the C++ GLM library, or to working with homogeneous coordinates (like 4D + matrices for 3D transformations), then you will have more success with **nalgebra-glm**. If on the other + hand you prefer more rigorous treatments of transformations, with type-level restrictions, then go for **nalgebra**. + If you need dynamically-sized matrices, you should go for **nalgebra** as well. - Keep in mind that **nalgebra-glm** is just a different API for **nalgebra**. So you can very well use both - and benefit from both their advantages: use **nalgebra-glm** when mathematical rigor is not that important, - and **nalgebra** itself when you need more expressive types, and more powerful linear algebra operations like - matrix factorizations and slicing. Just remember that all the **nalgebra-glm** types are just aliases to **nalgebra** types, - and keep in mind it is possible to convert, e.g., an `Isometry3` to a `Mat4` and vice-versa (see the [conversions section](#conversions)). - */ + Keep in mind that **nalgebra-glm** is just a different API for **nalgebra**. So you can very well use both + and benefit from both their advantages: use **nalgebra-glm** when mathematical rigor is not that important, + and **nalgebra** itself when you need more expressive types, and more powerful linear algebra operations like + matrix factorizations and slicing. Just remember that all the **nalgebra-glm** types are just aliases to **nalgebra** types, + 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")] @@ -119,68 +119,82 @@ extern crate alga; extern crate nalgebra as na; 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, 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 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, mix, modf, modf_vec, round, sign, smoothstep, step, step_scalar, step_vec, trunc, uint_bits_to_float, uint_bits_to_float_scalar}; -pub use geometric::{reflect_vec, cross, distance, dot, faceforward, length, magnitude, normalize, refract_vec}; -pub use matrix::{transpose, determinant, inverse, matrix_comp_mult, outer_product}; -pub use traits::{Dimension, Number, Alloc}; -pub use trigonometric::{acos, acosh, asin, asinh, atan, atan2, atanh, cos, cosh, degrees, radians, sin, sinh, tan, tanh}; -pub use vector_relational::{all, any, equal, greater_than, greater_than_equal, less_than, less_than_equal, not, not_equal}; pub use exponential::{exp, exp2, inversesqrt, log, log2, pow, sqrt}; +pub use geometric::{ + cross, distance, dot, faceforward, length, magnitude, normalize, reflect_vec, refract_vec, +}; +pub use matrix::{determinant, inverse, matrix_comp_mult, outer_product, transpose}; +pub use traits::{Alloc, Dimension, Number}; +pub use trigonometric::{ + acos, acosh, asin, asinh, atan, atan2, atanh, cos, cosh, degrees, radians, sin, sinh, tan, tanh, +}; +pub use vector_relational::{ + all, any, equal, greater_than, greater_than_equal, less_than, less_than_equal, not, not_equal, +}; -pub use gtx::{ - comp_add, comp_max, comp_min, comp_mul, - cross2d, - left_handed, right_handed, - matrix_cross, matrix_cross3, - diagonal2x2, diagonal2x3, diagonal2x4, diagonal3x2, diagonal3x3, diagonal3x4, diagonal4x2, diagonal4x3, diagonal4x4, - distance2, l1_distance, l1_norm, l2_distance, l2_norm, length2, magnitude2, - triangle_normal, - fast_normalize_dot, normalize_dot, - quat_rotate_normalized_axis, rotate_normalized_axis, - orientation, rotate_vec2, rotate_vec3, rotate_vec4, rotate_x_vec4, rotate_x_vec3, rotate_y_vec4, rotate_y_vec3, rotate_z_vec4, rotate_z_vec3, slerp, - rotation, scaling, translation, rotation2d, scaling2d, translation2d, - proj, proj2d, reflect, reflect2d, scale_bias, scale_bias_matrix, shear2d_x, shear_x, shear_y, shear2d_y, shear_z, - rotate2d, scale2d, translate2d, - angle, - are_collinear, are_collinear2d, are_orthogonal, is_comp_null, is_normalized, is_null, - quat_to_mat3, quat_rotate_vec, quat_cross_vec, mat3_to_quat, quat_extract_real_component, quat_fast_mix, quat_inv_cross_vec, quat_length2, quat_magnitude2, quat_identity, quat_rotate_vec3, quat_rotation, quat_short_mix, quat_to_mat4, to_quat +pub use ext::{ + epsilon, equal_columns, equal_columns_eps, equal_columns_eps_vec, equal_eps, equal_eps_vec, + identity, look_at, look_at_lh, look_at_rh, max, max2, max3, max3_scalar, max4, max4_scalar, + min, min2, min3, min3_scalar, min4, min4_scalar, not_equal_columns, not_equal_columns_eps, + not_equal_columns_eps_vec, not_equal_eps, not_equal_eps_vec, ortho, perspective, pi, + pick_matrix, project, project_no, project_zo, quat_angle, quat_angle_axis, quat_axis, + quat_conjugate, quat_cross, quat_dot, quat_equal, quat_equal_eps, quat_exp, quat_inverse, + quat_length, quat_lerp, quat_log, quat_magnitude, quat_normalize, quat_not_equal, + quat_not_equal_eps, quat_pow, quat_rotate, quat_slerp, rotate, rotate_x, rotate_y, rotate_z, + scale, translate, unproject, unproject_no, unproject_zo, }; pub use gtc::{ - e, two_pi, euler, four_over_pi, golden_ratio, half_pi, ln_ln_two, ln_ten, ln_two, one, one_over_pi, one_over_root_two, one_over_two_pi, quarter_pi, root_five, root_half_pi, root_ln_four, root_pi, root_three, root_two, root_two_pi, third, three_over_two_pi, two_over_pi, two_over_root_pi, two_thirds, zero, - column, row, set_column, set_row, - affine_inverse, inverse_transpose, - make_mat2, make_mat2x2, make_mat2x3, make_mat2x4, make_mat3, make_mat3x2, make_mat3x3, make_mat3x4, make_mat4, make_mat4x2, make_mat4x3, make_mat4x4, make_quat, make_vec1, make_vec2, make_vec3, make_vec4, value_ptr, value_ptr_mut, vec1_to_vec2, vec1_to_vec3, vec1_to_vec4, vec2_to_vec1, vec2_to_vec2, vec2_to_vec3, vec2_to_vec4, vec3_to_vec1, vec3_to_vec2, vec3_to_vec3, vec3_to_vec4, vec4_to_vec1, vec4_to_vec2, vec4_to_vec3, vec4_to_vec4, mat2_to_mat3, mat2_to_mat4, mat3_to_mat2, mat3_to_mat4, mat4_to_mat2, mat4_to_mat3, - quat_cast, quat_euler_angles, quat_greater_than, quat_greater_than_equal, quat_less_than, quat_less_than_equal, quat_look_at, quat_look_at_lh, quat_look_at_rh, quat_pitch, quat_roll, quat_yaw + affine_inverse, column, e, euler, four_over_pi, golden_ratio, half_pi, inverse_transpose, + ln_ln_two, ln_ten, ln_two, make_mat2, make_mat2x2, make_mat2x3, make_mat2x4, make_mat3, + make_mat3x2, make_mat3x3, make_mat3x4, make_mat4, make_mat4x2, make_mat4x3, make_mat4x4, + make_quat, make_vec1, make_vec2, make_vec3, make_vec4, mat2_to_mat3, mat2_to_mat4, + mat3_to_mat2, mat3_to_mat4, mat4_to_mat2, mat4_to_mat3, one, one_over_pi, one_over_root_two, + one_over_two_pi, quarter_pi, quat_cast, quat_euler_angles, quat_greater_than, + quat_greater_than_equal, quat_less_than, quat_less_than_equal, quat_look_at, quat_look_at_lh, + quat_look_at_rh, quat_pitch, quat_roll, quat_yaw, root_five, root_half_pi, root_ln_four, + root_pi, root_three, root_two, root_two_pi, row, set_column, set_row, third, three_over_two_pi, + two_over_pi, two_over_root_pi, two_pi, two_thirds, value_ptr, value_ptr_mut, vec1_to_vec2, + vec1_to_vec3, vec1_to_vec4, vec2_to_vec1, vec2_to_vec2, vec2_to_vec3, vec2_to_vec4, + vec3_to_vec1, vec3_to_vec2, vec3_to_vec3, vec3_to_vec4, vec4_to_vec1, vec4_to_vec2, + vec4_to_vec3, vec4_to_vec4, zero, }; -pub use ext::{ - ortho, perspective, - pick_matrix, project, project_no, project_zo, unproject, unproject_no, unproject_zo, - equal_columns, equal_columns_eps, equal_columns_eps_vec, not_equal_columns, not_equal_columns_eps, not_equal_columns_eps_vec, - identity, look_at, look_at_lh, rotate, scale, look_at_rh, translate, rotate_x, rotate_y, rotate_z, - max3_scalar, max4_scalar, min3_scalar, min4_scalar, - epsilon, pi, - max, max2, max3, max4, min, min2, min3, min4, - equal_eps, equal_eps_vec, not_equal_eps, not_equal_eps_vec, - quat_conjugate, quat_inverse, quat_lerp, quat_slerp, - quat_cross, quat_dot, quat_length, quat_magnitude, quat_normalize, - quat_equal, quat_equal_eps, quat_not_equal, quat_not_equal_eps, - quat_exp, quat_log, quat_pow, quat_rotate, - quat_angle, quat_angle_axis, quat_axis +pub use gtx::{ + angle, are_collinear, are_collinear2d, are_orthogonal, comp_add, comp_max, comp_min, comp_mul, + cross2d, diagonal2x2, diagonal2x3, diagonal2x4, diagonal3x2, diagonal3x3, diagonal3x4, + diagonal4x2, diagonal4x3, diagonal4x4, distance2, fast_normalize_dot, is_comp_null, + is_normalized, is_null, l1_distance, l1_norm, l2_distance, l2_norm, left_handed, length2, + magnitude2, mat3_to_quat, matrix_cross, matrix_cross3, normalize_dot, orientation, proj, + proj2d, quat_cross_vec, quat_extract_real_component, quat_fast_mix, quat_identity, + quat_inv_cross_vec, quat_length2, quat_magnitude2, quat_rotate_normalized_axis, + quat_rotate_vec, quat_rotate_vec3, quat_rotation, quat_short_mix, quat_to_mat3, quat_to_mat4, + reflect, reflect2d, right_handed, rotate2d, rotate_normalized_axis, rotate_vec2, rotate_vec3, + rotate_vec4, rotate_x_vec3, rotate_x_vec4, rotate_y_vec3, rotate_y_vec4, rotate_z_vec3, + rotate_z_vec4, rotation, rotation2d, scale2d, scale_bias, scale_bias_matrix, scaling, + scaling2d, shear2d_x, shear2d_y, shear_x, shear_y, shear_z, slerp, to_quat, translate2d, + translation, translation2d, triangle_normal, }; -pub use na::{convert, convert_ref, convert_unchecked, convert_ref_unchecked, try_convert, try_convert_ref}; -pub use na::{Scalar, Real, DefaultAllocator, U1, U2, U3, U4}; +pub use na::{ + convert, convert_ref, convert_ref_unchecked, convert_unchecked, try_convert, try_convert_ref, +}; +pub use na::{DefaultAllocator, Real, Scalar, U1, U2, U3, U4}; mod aliases; -mod constructors; mod common; -mod matrix; +mod constructors; +mod exponential; mod geometric; +mod matrix; mod traits; mod trigonometric; mod vector_relational; -mod exponential; //mod integer; //mod packing; diff --git a/nalgebra-glm/src/matrix.rs b/nalgebra-glm/src/matrix.rs index b61242c9..81212248 100644 --- a/nalgebra-glm/src/matrix.rs +++ b/nalgebra-glm/src/matrix.rs @@ -1,34 +1,46 @@ -use na::{Scalar, Real, DefaultAllocator}; +use na::{DefaultAllocator, Real, Scalar}; -use traits::{Alloc, Dimension, Number}; use aliases::{TMat, TVec}; +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 { - m.clone().try_inverse().unwrap_or_else(TMat::::zeros) +where DefaultAllocator: Alloc { + m.clone() + .try_inverse() + .unwrap_or_else(TMat::::zeros) } /// Component-wise multiplication of two matrices. -pub fn matrix_comp_mult(x: &TMat, y: &TMat) -> TMat - where DefaultAllocator: Alloc { +pub fn matrix_comp_mult( + x: &TMat, + y: &TMat, +) -> TMat +where + DefaultAllocator: Alloc, +{ x.component_mul(y) } /// Treats the first parameter `c` as a column vector and the second parameter `r` as a row vector and does a linear algebraic matrix multiply `c * r`. -pub fn outer_product(c: &TVec, r: &TVec) -> TMat - where DefaultAllocator: Alloc { +pub fn outer_product( + c: &TVec, + r: &TVec, +) -> TMat +where + DefaultAllocator: Alloc, +{ c * r.transpose() } /// 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 02e62e97..3c2033c1 100644 --- a/nalgebra-glm/src/traits.rs +++ b/nalgebra-glm/src/traits.rs @@ -1,48 +1,81 @@ -use num::{Signed, FromPrimitive, Bounded}; use approx::AbsDiffEq; +use num::{Bounded, FromPrimitive, Signed}; -use alga::general::{Ring, Lattice}; -use na::{Scalar, DimName, DimMin, U1}; +use alga::general::{Lattice, Ring}; use na::allocator::Allocator; +use na::{DimMin, DimName, Scalar, U1}; /// A type-level number representing a vector, matrix row, or matrix column, dimension. pub trait Dimension: DimName + DimMin {} impl> Dimension for D {} - /// A number that can either be an integer or a float. -pub trait Number: Scalar + Ring + Lattice + AbsDiffEq + Signed + FromPrimitive + Bounded { +pub trait Number: + Scalar + Ring + Lattice + AbsDiffEq + Signed + FromPrimitive + Bounded +{ } -impl + Signed + FromPrimitive + Bounded> Number for T { +impl + Signed + FromPrimitive + Bounded> + Number for T +{ } #[doc(hidden)] pub trait Alloc: -Allocator + Allocator + Allocator + Allocator + Allocator + Allocator + Allocator + Allocator + -Allocator + Allocator + -Allocator + Allocator + -Allocator + Allocator + -Allocator + Allocator + -Allocator + Allocator + -Allocator + Allocator + -Allocator + Allocator + -Allocator + Allocator + -Allocator<(usize, usize), R> + Allocator<(usize, usize), C> + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator<(usize, usize), R> + + Allocator<(usize, usize), C> { } -impl - Alloc for T -where T: Allocator + Allocator + Allocator + Allocator + Allocator + Allocator + Allocator + Allocator + - Allocator + Allocator + - Allocator + Allocator + - Allocator + Allocator + - Allocator + Allocator + - Allocator + Allocator + - Allocator + Allocator + - Allocator + Allocator + - Allocator + Allocator + - Allocator<(usize, usize), R> + Allocator<(usize, usize), C> +impl Alloc for T where T: Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator + + Allocator<(usize, usize), R> + + Allocator<(usize, usize), C> { -} \ No newline at end of file +} diff --git a/nalgebra-glm/src/trigonometric.rs b/nalgebra-glm/src/trigonometric.rs index e9f69ae5..cf0b2652 100644 --- a/nalgebra-glm/src/trigonometric.rs +++ b/nalgebra-glm/src/trigonometric.rs @@ -1,95 +1,94 @@ -use na::{self, Real, DefaultAllocator}; +use na::{self, DefaultAllocator, Real}; use aliases::TVec; 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 24763e06..c92f69fe 100644 --- a/nalgebra-glm/src/vector_relational.rs +++ b/nalgebra-glm/src/vector_relational.rs @@ -1,7 +1,7 @@ -use na::{DefaultAllocator}; +use na::DefaultAllocator; use aliases::TVec; -use traits::{Number, Alloc, Dimension}; +use traits::{Alloc, Dimension, Number}; /// Checks that all the vector components are `true`. /// @@ -21,7 +21,7 @@ use traits::{Number, Alloc, Dimension}; /// * [`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) } @@ -46,7 +46,7 @@ pub fn all(v: &TVec) -> bool /// * [`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) } @@ -70,7 +70,7 @@ pub fn any(v: &TVec) -> bool /// * [`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) } @@ -94,7 +94,7 @@ pub fn equal(x: &TVec, y: &TVec) -> TVec(x: &TVec, y: &TVec) -> TVec - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x > y) } @@ -117,8 +117,13 @@ pub fn greater_than(x: &TVec, y: &TVec) -> /// * [`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 - where DefaultAllocator: Alloc { +pub fn greater_than_equal( + x: &TVec, + y: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ x.zip_map(y, |x, y| x >= y) } @@ -142,7 +147,7 @@ pub fn greater_than_equal(x: &TVec, y: &TVec(x: &TVec, y: &TVec) -> TVec - where DefaultAllocator: Alloc { +where DefaultAllocator: Alloc { x.zip_map(y, |x, y| x < y) } @@ -166,7 +171,7 @@ pub fn less_than(x: &TVec, y: &TVec) -> TVe /// * [`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) } @@ -191,7 +196,7 @@ pub fn less_than_equal(x: &TVec, y: &TVec) /// * [`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) } @@ -215,6 +220,6 @@ pub fn not(v: &TVec) -> TVec /// * [`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..a213e24f 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,17 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - serialize = "DefaultAllocator: Allocator, - MatrixN: Serialize" - ) - ) + serde(bound(serialize = "DefaultAllocator: Allocator, + MatrixN: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde( - bound( - deserialize = "DefaultAllocator: Allocator, - MatrixN: Deserialize<'de>" - ) - ) + serde(bound(deserialize = "DefaultAllocator: Allocator, + MatrixN: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct Cholesky -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { l: MatrixN, } @@ -47,8 +38,7 @@ where } impl Cholesky -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Computes the cholesky decomposition of the given symmetric-definite-positive square /// matrix. @@ -124,9 +114,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..9fa40e1b 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; @@ -19,27 +19,22 @@ use lapack; #[cfg_attr( feature = "serde-serialize", serde( - bound( - serialize = "DefaultAllocator: Allocator + Allocator, + bound(serialize = "DefaultAllocator: Allocator + Allocator, VectorN: Serialize, - MatrixN: Serialize" - ) + MatrixN: Serialize") ) )] #[cfg_attr( feature = "serde-serialize", serde( - bound( - deserialize = "DefaultAllocator: Allocator + Allocator, + bound(deserialize = "DefaultAllocator: Allocator + Allocator, VectorN: Serialize, - MatrixN: Deserialize<'de>" - ) + 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, @@ -58,8 +53,7 @@ where } impl Eigen -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { /// Computes the eigenvalues and eigenvectors of the square matrix `m`. /// @@ -68,7 +62,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 +229,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..57a4b2e1 100644 --- a/nalgebra-lapack/src/hessenberg.rs +++ b/nalgebra-lapack/src/hessenberg.rs @@ -13,30 +13,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 + Allocator>, MatrixN: Serialize, - VectorN>: 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>" - ) - ) + VectorN>: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct Hessenberg> -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { h: MatrixN, tau: VectorN>, @@ -51,8 +42,7 @@ where } 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 +94,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/lib.rs b/nalgebra-lapack/src/lib.rs index a001dcc3..c343ba83 100644 --- a/nalgebra-lapack/src/lib.rs +++ b/nalgebra-lapack/src/lib.rs @@ -68,8 +68,10 @@ #![deny(unused_qualifications)] #![deny(unused_results)] #![deny(missing_docs)] -#![doc(html_favicon_url = "http://nalgebra.org/img/favicon.ico", - html_root_url = "http://nalgebra.org/rustdoc")] +#![doc( + html_favicon_url = "http://nalgebra.org/img/favicon.ico", + html_root_url = "http://nalgebra.org/rustdoc" +)] extern crate alga; extern crate lapack; diff --git a/nalgebra-lapack/src/lu.rs b/nalgebra-lapack/src/lu.rs index cab7b763..47ee912a 100644 --- a/nalgebra-lapack/src/lu.rs +++ b/nalgebra-lapack/src/lu.rs @@ -20,30 +20,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 + Allocator>, MatrixMN: Serialize, - PermutationSequence>: 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>" - ) - ) + PermutationSequence>: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct LU, C: Dim> -where - DefaultAllocator: Allocator> + Allocator, +where DefaultAllocator: Allocator> + Allocator { lu: MatrixMN, p: VectorN>, @@ -139,9 +130,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 +145,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 +233,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 +242,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..1bf55644 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,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 + Allocator>, MatrixMN: Serialize, - VectorN>: 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>" - ) - ) + VectorN>: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct QR, C: Dim> -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { qr: MatrixMN, tau: VectorN>, @@ -54,11 +45,10 @@ where } 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 +95,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 +120,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..27ce5927 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; @@ -19,27 +19,22 @@ use lapack; #[cfg_attr( feature = "serde-serialize", serde( - bound( - serialize = "DefaultAllocator: Allocator + Allocator, + bound(serialize = "DefaultAllocator: Allocator + Allocator, VectorN: Serialize, - MatrixN: Serialize" - ) + MatrixN: Serialize") ) )] #[cfg_attr( feature = "serde-serialize", serde( - bound( - deserialize = "DefaultAllocator: Allocator + Allocator, + bound(deserialize = "DefaultAllocator: Allocator + Allocator, VectorN: Serialize, - MatrixN: Deserialize<'de>" - ) + MatrixN: Deserialize<'de>") ) )] #[derive(Clone, Debug)] pub struct RealSchur -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { re: VectorN, im: VectorN, @@ -56,8 +51,7 @@ where } impl RealSchur -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { /// Computes the eigenvalues and real Schur form of the matrix `m`. /// @@ -152,9 +146,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..5883578a 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,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 + Allocator, MatrixN: Serialize, MatrixN: Serialize, - VectorN>: 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>" - ) - ) + 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> @@ -64,22 +55,20 @@ where /// 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..a06445ee 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,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 + Allocator, VectorN: Serialize, - MatrixN: 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>" - ) - ) + 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, @@ -59,8 +50,7 @@ where } impl SymmetricEigen -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { /// Computes the eigenvalues and eigenvectors of the symmetric matrix `m`. /// @@ -89,7 +79,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/src/base/allocator.rs b/src/base/allocator.rs index 5b17c183..30f08af0 100644 --- a/src/base/allocator.rs +++ b/src/base/allocator.rs @@ -79,7 +79,8 @@ where N: Scalar, DefaultAllocator: Allocator + Allocator, SameShapeC>, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, -{} +{ +} // XXX: Bad name. /// Restricts the given number of rows to be equal. @@ -100,4 +101,5 @@ where N: Scalar, DefaultAllocator: Allocator + Allocator>, ShapeConstraint: SameNumberOfRows, -{} +{ +} diff --git a/src/base/blas.rs b/src/base/blas.rs index b4a5cfbe..073f519b 100644 --- a/src/base/blas.rs +++ b/src/base/blas.rs @@ -161,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). /// @@ -324,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); @@ -336,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); @@ -576,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`. /// @@ -817,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. @@ -876,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 39509f2f..01be4e99 100644 --- a/src/base/cg.rs +++ b/src/base/cg.rs @@ -238,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; } @@ -248,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; } @@ -319,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); diff --git a/src/base/constraint.rs b/src/base/constraint.rs index d9d7aafe..3bd0540b 100644 --- a/src/base/constraint.rs +++ b/src/base/constraint.rs @@ -8,8 +8,7 @@ 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. diff --git a/src/base/construction.rs b/src/base/construction.rs index 652b3eb6..af371413 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()), @@ -177,9 +164,7 @@ where /// not have the same dimensions. #[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(); @@ -207,9 +192,7 @@ where /// columns do not have the same dimensions. #[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(); @@ -235,9 +218,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()) } @@ -248,7 +229,8 @@ where ncols: C, distribution: &mut Distr, rng: &mut G, - ) -> Self { + ) -> Self + { Self::from_fn_generic(nrows, ncols, |_, _| distribution.sample(rng)) } } @@ -261,9 +243,7 @@ where /// Creates a square matrix with its diagonal set to `diag` and all other entries set to 0. #[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); @@ -703,9 +683,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(); @@ -717,9 +695,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(); @@ -731,9 +707,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(); @@ -745,9 +719,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(); @@ -759,9 +731,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(); @@ -773,9 +743,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(); @@ -787,54 +755,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/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 d694ec39..1d79d48e 100644 --- a/src/base/dimension.rs +++ b/src/base/dimension.rs @@ -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 }) } } @@ -368,7 +364,8 @@ impl< G: Bit + Any + Debug + Copy + PartialEq + Send + Sync, > IsNotStaticOne for UInt, A>, B>, C>, D>, E>, F>, G> -{} +{ +} impl NamedDim for UInt @@ -409,4 +406,5 @@ impl IsNotStaticOne for UInt -{} +{ +} diff --git a/src/base/edition.rs b/src/base/edition.rs index 649d4cda..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()); } @@ -551,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) } @@ -562,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) } @@ -642,7 +632,8 @@ unsafe fn compress_rows( ncols: usize, i: usize, nremove: usize, -) { +) +{ let new_nrows = nrows - nremove; if new_nrows == 0 || ncols == 0 { @@ -681,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/matrix.rs b/src/base/matrix.rs index e8825121..784ae9a2 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) } } @@ -1040,7 +1019,8 @@ impl Eq for Matrix where N: Scalar + Eq, S: Storage, -{} +{ +} impl PartialEq for Matrix where @@ -1220,8 +1200,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 +1290,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 +1421,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 fc81176c..deaa9fc3 100644 --- a/src/base/matrix_array.rs +++ b/src/base/matrix_array.rs @@ -107,7 +107,8 @@ where R::Value: Mul, Prod: ArrayLength, GenericArray>: Copy, -{} +{ +} impl Clone for MatrixArray where @@ -132,7 +133,8 @@ where C: DimName, R::Value: Mul, Prod: ArrayLength, -{} +{ +} impl PartialEq for MatrixArray where @@ -182,17 +184,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) @@ -232,7 +230,8 @@ where R::Value: Mul, Prod: ArrayLength, DefaultAllocator: Allocator, -{} +{ +} unsafe impl ContiguousStorageMut for MatrixArray where @@ -242,7 +241,8 @@ where R::Value: Mul, Prod: ArrayLength, DefaultAllocator: Allocator, -{} +{ +} /* * @@ -260,9 +260,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() { @@ -283,9 +281,7 @@ where Prod: ArrayLength, { fn deserialize(deserializer: D) -> Result - where - D: Deserializer<'a>, - { + where D: Deserializer<'a> { deserializer.deserialize_seq(MatrixArrayVisitor::new()) } } @@ -330,9 +326,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..8027c49d 100644 --- a/src/base/matrix_slice.rs +++ b/src/base/matrix_slice.rs @@ -91,7 +91,8 @@ slice_storage_impl!("A mutable matrix data storage for mutable matrix slice. Onl impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Copy for SliceStorage<'a, N, R, C, RStride, CStride> -{} +{ +} impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Clone for SliceStorage<'a, N, R, C, RStride, CStride> @@ -206,7 +207,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 +805,8 @@ impl> Matrix { pub fn rows_range>( &self, rows: RowRange, - ) -> MatrixSlice { + ) -> MatrixSlice + { self.slice_range(rows, ..) } @@ -812,7 +815,8 @@ impl> Matrix { pub fn columns_range>( &self, cols: ColRange, - ) -> MatrixSlice { + ) -> MatrixSlice + { self.slice_range(.., cols) } } @@ -841,7 +845,8 @@ impl> Matrix { pub fn rows_range_mut>( &mut self, rows: RowRange, - ) -> MatrixSliceMut { + ) -> MatrixSliceMut + { self.slice_range_mut(rows, ..) } @@ -850,7 +855,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 90bdfe28..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,17 +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 { @@ -249,10 +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/ops.rs b/src/base/ops.rs index a83d5112..14ec98f0 100644 --- a/src/base/ops.rs +++ b/src/base/ops.rs @@ -724,9 +724,7 @@ impl> Matrix MatrixMN - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let mut res = self.clone_owned(); res.add_scalar_mut(rhs); res @@ -735,9 +733,7 @@ impl> Matrix, - { + where S: StorageMut { for e in self.iter_mut() { *e += rhs } 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/storage.rs b/src/base/storage.rs index bf57242e..b96f69d0 100644 --- a/src/base/storage.rs +++ b/src/base/storage.rs @@ -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. 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 94bf9abe..235049d8 100644 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -26,23 +26,18 @@ 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" - )) + Owned: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound( - deserialize = "R: Deserialize<'de>, + serde(bound(deserialize = "R: Deserialize<'de>, DefaultAllocator: Allocator, - Owned: Deserialize<'de>" - )) + Owned: Deserialize<'de>")) )] pub struct Isometry -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// The pure rotational part of this isometry. pub rotation: R, @@ -97,11 +92,11 @@ 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 { @@ -110,8 +105,7 @@ where } impl>> Isometry -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Creates a new isometry from its rotational and translational parts. #[inline] @@ -175,8 +169,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] @@ -198,7 +191,8 @@ impl Eq for Isometry where R: Rotation> + Eq, DefaultAllocator: Allocator, -{} +{ +} impl PartialEq for Isometry where @@ -248,7 +242,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_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/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 4f26d632..0530c0c4 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -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,7 +41,8 @@ impl Copy for Point where DefaultAllocator: Allocator, >::Buffer: Copy, -{} +{ +} impl Clone for Point where @@ -62,9 +62,7 @@ where >::Buffer: Serialize, { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.coords.serialize(serializer) } } @@ -76,9 +74,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)) @@ -107,8 +103,7 @@ where } impl Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Clones this point into one that owns its data. #[inline] @@ -218,7 +213,8 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool { + ) -> bool + { self.coords .relative_eq(&other.coords, epsilon, max_relative) } @@ -243,8 +239,7 @@ where impl Eq for Point where DefaultAllocator: Allocator {} impl PartialEq for Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn eq(&self, right: &Self) -> bool { @@ -253,8 +248,7 @@ where } impl PartialOrd for Point -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn partial_cmp(&self, other: &Self) -> Option { @@ -288,8 +282,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 5673d0df..42a1088a 100644 --- a/src/geometry/point_alga.rs +++ b/src/geometry/point_alga.rs @@ -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 60c21f8d..6fb70d2b 100644 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -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)) @@ -480,7 +474,8 @@ impl UnitQuaternion { other: &UnitQuaternion, t: N, epsilon: N, - ) -> Option> { + ) -> 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()))) @@ -662,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_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/rotation.rs b/src/geometry/rotation.rs index 476c045f..7dfa56f3 100644 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -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,7 +43,8 @@ impl Copy for Rotation where DefaultAllocator: Allocator, >::Buffer: Copy, -{} +{ +} impl Clone for Rotation where @@ -85,9 +85,7 @@ where Owned: Serialize, { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.matrix.serialize(serializer) } } @@ -99,9 +97,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)) @@ -109,8 +105,7 @@ where } impl Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// A reference to the underlying matrix representation of this rotation. #[inline] @@ -189,8 +184,7 @@ where impl Eq for Rotation where DefaultAllocator: Allocator {} impl PartialEq for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn eq(&self, right: &Rotation) -> bool { @@ -234,7 +228,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 b95a028b..4f02bbae 100644 --- a/src/geometry/rotation_alga.rs +++ b/src/geometry/rotation_alga.rs @@ -19,8 +19,7 @@ use geometry::{Point, Rotation}; * */ impl Identity for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn identity() -> Self { @@ -29,8 +28,7 @@ where } impl Inverse for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn inverse(&self) -> Self { @@ -44,8 +42,7 @@ where } impl AbstractMagma for Rotation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn operate(&self, rhs: &Self) -> Self { @@ -74,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 { @@ -89,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 { @@ -104,8 +99,7 @@ where } impl AffineTransformation> for Rotation -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { type Rotation = Self; type NonUniformScaling = Id; @@ -148,8 +142,7 @@ where } impl Similarity> for Rotation -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { type Scaling = Id; @@ -181,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_ops.rs b/src/geometry/rotation_ops.rs index 0e5b20b7..344d6b3f 100644 --- a/src/geometry/rotation_ops.rs +++ b/src/geometry/rotation_ops.rs @@ -31,8 +31,7 @@ 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 d01a529d..e03cd97d 100644 --- a/src/geometry/rotation_specialization.rs +++ b/src/geometry/rotation_specialization.rs @@ -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 { @@ -384,8 +380,7 @@ impl Rotation3 { } impl Distribution> for Standard -where - OpenClosed01: Distribution, +where OpenClosed01: Distribution { /// Generate a uniformly distributed random rotation. #[inline] diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index cbf26a69..6592e6ed 100644 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -25,25 +25,20 @@ 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" - )) + 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>" - )) + 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, @@ -85,11 +80,11 @@ 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 { @@ -108,7 +103,8 @@ where translation: Translation, rotation: R, scaling: N, - ) -> Similarity { + ) -> Similarity + { Similarity::from_isometry(Isometry::from_parts(translation, rotation), scaling) } @@ -246,8 +242,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] @@ -271,7 +266,8 @@ impl Eq for Similarity where R: Rotation> + Eq, DefaultAllocator: Allocator, -{} +{ +} impl PartialEq for Similarity where @@ -321,7 +317,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/transform.rs b/src/geometry/transform.rs index 4d7f8ba1..4326c915 100644 --- a/src/geometry/transform.rs +++ b/src/geometry/transform.rs @@ -155,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, @@ -175,11 +174,11 @@ 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 { @@ -194,9 +193,7 @@ where Owned, DimNameSum>: Serialize, { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.matrix.serialize(serializer) } } @@ -208,22 +205,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 { @@ -232,8 +225,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. @@ -305,9 +297,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()) } @@ -323,16 +313,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_construction.rs b/src/geometry/transform_construction.rs index 1a7beba4..0ab9e5f2 100644 --- a/src/geometry/transform_construction.rs +++ b/src/geometry/transform_construction.rs @@ -9,8 +9,7 @@ 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/translation.rs b/src/geometry/translation.rs index 33a0f349..1200d251 100644 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -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,7 +43,8 @@ impl Copy for Translation where DefaultAllocator: Allocator, Owned: Copy, -{} +{ +} impl Clone for Translation where @@ -85,9 +85,7 @@ where Owned: Serialize, { fn serialize(&self, serializer: S) -> Result - where - S: Serializer, - { + where S: Serializer { self.vector.serialize(serializer) } } @@ -99,9 +97,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)) @@ -109,8 +105,7 @@ where } impl Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { /// Creates a new translation from the given vector. #[inline] @@ -121,9 +116,7 @@ where /// Inverts `self`. #[inline] pub fn inverse(&self) -> Translation - where - N: ClosedNeg, - { + where N: ClosedNeg { Translation::from_vector(-&self.vector) } @@ -145,9 +138,7 @@ where /// Inverts `self` in-place. #[inline] pub fn inverse_mut(&mut self) - where - N: ClosedNeg, - { + where N: ClosedNeg { self.vector.neg_mut() } } @@ -155,8 +146,7 @@ where impl Eq for Translation where DefaultAllocator: Allocator {} impl PartialEq for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn eq(&self, right: &Translation) -> bool { @@ -198,7 +188,8 @@ where other: &Self, epsilon: Self::Epsilon, max_relative: Self::Epsilon, - ) -> bool { + ) -> bool + { self.vector .relative_eq(&other.vector, epsilon, max_relative) } @@ -226,8 +217,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 ce095cc5..896e7a8b 100644 --- a/src/geometry/translation_alga.rs +++ b/src/geometry/translation_alga.rs @@ -20,8 +20,7 @@ use geometry::{Point, Translation}; * */ impl Identity for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn identity() -> Self { @@ -30,8 +29,7 @@ where } impl Inverse for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn inverse(&self) -> Self { @@ -45,8 +43,7 @@ where } impl AbstractMagma for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn operate(&self, rhs: &Self) -> Self { @@ -75,8 +72,7 @@ impl_multiplicative_structures!( * */ impl Transformation> for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn transform_point(&self, pt: &Point) -> Point { @@ -90,8 +86,7 @@ where } impl ProjectiveTransformation> for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn inverse_transform_point(&self, pt: &Point) -> Point { @@ -105,8 +100,7 @@ where } impl AffineTransformation> for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Rotation = Id; type NonUniformScaling = Id; @@ -149,8 +143,7 @@ where } impl Similarity> for Translation -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Scaling = Id; @@ -181,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/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 d464ea56..59b11903 100644 --- a/src/geometry/unit_complex_alga.rs +++ b/src/geometry/unit_complex_alga.rs @@ -59,8 +59,7 @@ impl_structures!( ); impl Transformation> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn transform_point(&self, pt: &Point2) -> Point2 { @@ -74,8 +73,7 @@ where } impl ProjectiveTransformation> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn inverse_transform_point(&self, pt: &Point2) -> Point2 { @@ -91,8 +89,7 @@ where } impl AffineTransformation> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Rotation = Self; type NonUniformScaling = Id; @@ -135,8 +132,7 @@ where } impl Similarity> for UnitComplex -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type Scaling = Id; @@ -166,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 82dd2e7d..8e4f45fe 100644 --- a/src/geometry/unit_complex_construction.rs +++ b/src/geometry/unit_complex_construction.rs @@ -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 ad81c9c8..05665575 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -123,10 +123,18 @@ extern crate alloc; #[cfg(not(feature = "std"))] extern crate core as std; +#[cfg(feature = "io")] +extern crate pest; +#[macro_use] +#[cfg(feature = "io")] +extern crate pest_derive; + pub mod base; #[cfg(feature = "debug")] pub mod debug; pub mod geometry; +#[cfg(feature = "io")] +pub mod io; pub mod linalg; #[cfg(feature = "sparse")] pub mod sparse; @@ -224,9 +232,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 a5fd178d..5e2f6609 100644 --- a/src/linalg/bidiagonal.rs +++ b/src/linalg/bidiagonal.rs @@ -15,27 +15,23 @@ 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" - )) + 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>" - )) + VectorN, U1>>: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct Bidiagonal, C: Dim> @@ -64,7 +60,8 @@ where MatrixMN: Copy, VectorN>: Copy, VectorN, U1>>: Copy, -{} +{ +} impl, C: Dim> Bidiagonal where @@ -212,9 +209,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)); @@ -235,9 +230,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 9bf3cb18..b75ba33a 100644 --- a/src/linalg/cholesky.rs +++ b/src/linalg/cholesky.rs @@ -13,22 +13,17 @@ use storage::{Storage, StorageMut}; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound( - serialize = "DefaultAllocator: Allocator, - MatrixN: Serialize" - )) + serde(bound(serialize = "DefaultAllocator: Allocator, + MatrixN: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound( - deserialize = "DefaultAllocator: Allocator, - MatrixN: Deserialize<'de>" - )) + serde(bound(deserialize = "DefaultAllocator: Allocator, + MatrixN: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct Cholesky -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { chol: MatrixN, } @@ -37,11 +32,11 @@ 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`. /// @@ -147,8 +142,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 a65ab5d0..43cc20ba 100644 --- a/src/linalg/full_piv_lu.rs +++ b/src/linalg/full_piv_lu.rs @@ -15,26 +15,21 @@ 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" - )) + 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>" - )) + 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>, @@ -46,11 +41,11 @@ 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`. /// @@ -108,9 +103,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); @@ -121,9 +114,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() } @@ -150,8 +141,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(); @@ -164,8 +154,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. /// @@ -270,8 +259,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 d575a476..9a525edb 100644 --- a/src/linalg/hessenberg.rs +++ b/src/linalg/hessenberg.rs @@ -14,26 +14,21 @@ 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" - )) + VectorN>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound(deserialize = "DefaultAllocator: Allocator + Allocator>, MatrixN: Deserialize<'de>, - VectorN>: Deserialize<'de>" - )) + VectorN>: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct Hessenberg> -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { hess: MatrixN, subdiag: VectorN>, @@ -44,11 +39,11 @@ 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 { @@ -95,9 +90,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()) @@ -106,9 +99,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 @@ -123,9 +114,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); @@ -146,8 +135,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 921234d7..08cebd2a 100644 --- a/src/linalg/inverse.rs +++ b/src/linalg/inverse.rs @@ -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; diff --git a/src/linalg/lu.rs b/src/linalg/lu.rs index 2dccbc0b..d150852a 100644 --- a/src/linalg/lu.rs +++ b/src/linalg/lu.rs @@ -15,26 +15,21 @@ 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" - )) + 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>" - )) + 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>, @@ -45,7 +40,8 @@ where DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, MatrixMN: Copy, PermutationSequence>: Copy, -{} +{ +} /// Performs a LU decomposition to overwrite `out` with the inverse of `matrix`. /// @@ -88,8 +84,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 { @@ -131,9 +126,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); @@ -148,9 +141,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); @@ -161,9 +152,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); @@ -174,9 +163,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() } @@ -196,11 +183,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(); @@ -210,8 +195,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. /// @@ -382,8 +366,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/permutation_sequence.rs b/src/linalg/permutation_sequence.rs index a6f555f9..bba40b8f 100644 --- a/src/linalg/permutation_sequence.rs +++ b/src/linalg/permutation_sequence.rs @@ -15,22 +15,17 @@ use storage::StorageMut; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound( - serialize = "DefaultAllocator: Allocator<(usize, usize), D>, - VectorN<(usize, usize), D>: Serialize" - )) + 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>, - VectorN<(usize, usize), D>: Deserialize<'de>" - )) + 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>, @@ -40,11 +35,11 @@ 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] @@ -55,8 +50,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] @@ -66,8 +60,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] @@ -97,9 +90,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) } @@ -107,8 +98,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 { @@ -119,8 +112,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 487a06a4..3ec53c1d 100644 --- a/src/linalg/qr.rs +++ b/src/linalg/qr.rs @@ -15,26 +15,21 @@ 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>, MatrixMN: Serialize, - VectorN>: 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>" - )) + VectorN>: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct QR, C: Dim> -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { qr: MatrixMN, diag: VectorN>, @@ -45,11 +40,11 @@ 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 { @@ -108,9 +103,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. @@ -153,9 +146,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 { @@ -169,8 +160,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. /// @@ -302,8 +292,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 0918bee9..cb6c637f 100644 --- a/src/linalg/schur.rs +++ b/src/linalg/schur.rs @@ -19,22 +19,17 @@ use linalg::Hessenberg; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound( - serialize = "DefaultAllocator: Allocator, - MatrixN: Serialize" - )) + serde(bound(serialize = "DefaultAllocator: Allocator, + MatrixN: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound( - deserialize = "DefaultAllocator: Allocator, - MatrixN: Deserialize<'de>" - )) + serde(bound(deserialize = "DefaultAllocator: Allocator, + MatrixN: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct RealSchur -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { q: MatrixN, t: MatrixN, @@ -44,7 +39,8 @@ impl Copy for RealSchur where DefaultAllocator: Allocator, MatrixN: Copy, -{} +{ +} impl RealSchur where @@ -86,7 +82,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." @@ -290,9 +287,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; @@ -390,9 +385,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 @@ -565,9 +558,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) }; diff --git a/src/linalg/svd.rs b/src/linalg/svd.rs index 3945af9c..e3e42d5b 100644 --- a/src/linalg/svd.rs +++ b/src/linalg/svd.rs @@ -20,34 +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" - )) + 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>" - )) + 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>>, @@ -65,7 +64,8 @@ where MatrixMN>: Copy, MatrixMN, C>: Copy, VectorN>: Copy, -{} +{ +} impl, C: Dim> SVD where @@ -99,7 +99,8 @@ where compute_v: bool, eps: N, max_niter: usize, - ) -> Option { + ) -> Option + { assert!( matrix.len() != 0, "Cannot compute the SVD of an empty matrix." @@ -287,7 +288,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); @@ -342,7 +344,8 @@ where v_t: &mut Option, C>>, end: usize, eps: N, - ) -> (usize, usize) { + ) -> (usize, usize) + { let mut n = end; while n > 0 { @@ -406,7 +409,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(); @@ -440,7 +444,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(); @@ -502,9 +507,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." @@ -601,7 +604,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) } @@ -622,9 +626,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 f1e7b026..bf4ac8c2 100644 --- a/src/linalg/symmetric_eigen.rs +++ b/src/linalg/symmetric_eigen.rs @@ -18,26 +18,21 @@ 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" - )) + MatrixN: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound(deserialize = "DefaultAllocator: Allocator + Allocator, VectorN: Deserialize<'de>, - MatrixN: 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, @@ -51,11 +46,11 @@ 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. /// @@ -306,8 +301,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 37d6b194..e1ed5ba5 100644 --- a/src/linalg/symmetric_tridiagonal.rs +++ b/src/linalg/symmetric_tridiagonal.rs @@ -13,26 +13,21 @@ 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" - )) + VectorN>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound( - deserialize = "DefaultAllocator: Allocator + + serde(bound(deserialize = "DefaultAllocator: Allocator + Allocator>, MatrixN: Deserialize<'de>, - VectorN>: Deserialize<'de>" - )) + VectorN>: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct SymmetricTridiagonal> -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { tri: MatrixN, off_diagonal: VectorN>, @@ -43,11 +38,11 @@ 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`. /// @@ -100,9 +95,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(); @@ -111,9 +104,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) @@ -121,17 +112,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 } @@ -156,8 +143,7 @@ where } impl, S: Storage> SquareMatrix -where - DefaultAllocator: Allocator + Allocator>, +where DefaultAllocator: Allocator + Allocator> { /// Computes the tridiagonalization of this symmetric matrix. /// diff --git a/src/sparse/cs_matrix.rs b/src/sparse/cs_matrix.rs index 9bb03cda..a02e8613 100644 --- a/src/sparse/cs_matrix.rs +++ b/src/sparse/cs_matrix.rs @@ -81,8 +81,7 @@ pub trait CsStorageMut: #[derive(Clone, Debug, PartialEq)] pub struct CsVecStorage -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { pub(crate) shape: (R, C), pub(crate) p: VectorN, @@ -91,8 +90,7 @@ where } impl CsVecStorage -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { pub fn values(&self) -> &[N] { &self.vals @@ -108,8 +106,7 @@ where impl CsVecStorage where DefaultAllocator: Allocator {} impl<'a, N: Scalar, R: Dim, C: Dim> CsStorageIter<'a, N, R, C> for CsVecStorage -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type ColumnEntries = ColumnEntries<'a, N>; type ColumnRowIndices = iter::Cloned>; @@ -128,8 +125,7 @@ where } impl CsStorage for CsVecStorage -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { #[inline] fn shape(&self) -> (R, C) { @@ -174,8 +170,7 @@ where } impl<'a, N: Scalar, R: Dim, C: Dim> CsStorageIterMut<'a, N, R, C> for CsVecStorage -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { type ValuesMut = slice::IterMut<'a, N>; type ColumnEntriesMut = iter::Zip>, slice::IterMut<'a, N>>; @@ -195,10 +190,8 @@ where } } -impl CsStorageMut for CsVecStorage where - DefaultAllocator: Allocator -{ -} +impl CsStorageMut for CsVecStorage where DefaultAllocator: Allocator +{} /* pub struct CsSliceStorage<'a, N: Scalar, R: Dim, C: DimAdd> { @@ -223,8 +216,7 @@ pub struct CsMatrix< pub type CsVector> = CsMatrix; impl CsMatrix -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { pub fn new_uninitialized_generic(nrows: R, ncols: C, nvals: usize) -> Self { let mut i = Vec::with_capacity(nvals); @@ -303,7 +295,8 @@ impl CsMatrix { p: Vec, i: Vec, vals: Vec, - ) -> Self { + ) -> Self + { let nrows = Dynamic::new(nrows); let ncols = Dynamic::new(ncols); let p = DVector::from_data(MatrixVec::new(ncols, U1, p)); @@ -368,9 +361,7 @@ impl> CsMatrix { } pub fn transpose(&self) -> CsMatrix - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { let (nrows, ncols) = self.data.shape(); let nvals = self.len(); @@ -408,13 +399,10 @@ impl> CsMatrix { } impl CsMatrix -where - DefaultAllocator: Allocator, +where DefaultAllocator: Allocator { pub(crate) fn sort(&mut self) - where - DefaultAllocator: Allocator, - { + where DefaultAllocator: Allocator { // Size = R let nrows = self.data.shape().0; let mut workspace = unsafe { VectorN::new_uninitialized_generic(nrows, U1) }; @@ -446,9 +434,7 @@ where // Remove dupliate entries on a sorted CsMatrix. pub(crate) fn dedup(&mut self) - where - N: Zero + ClosedAdd, - { + where N: Zero + ClosedAdd { let mut curr_i = 0; for j in 0..self.ncols() { diff --git a/src/sparse/cs_matrix_cholesky.rs b/src/sparse/cs_matrix_cholesky.rs index e35d7e93..000332e7 100644 --- a/src/sparse/cs_matrix_cholesky.rs +++ b/src/sparse/cs_matrix_cholesky.rs @@ -13,8 +13,7 @@ use storage::{Storage, StorageMut}; use {DefaultAllocator, Dim, Matrix, MatrixMN, Real, Scalar, Vector, VectorN, U1}; pub struct CsCholesky -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { // Non-zero pattern of the original matrix upper-triangular part. // Unlike the original matrix, the `original_p` array does contain the last sentinel value @@ -33,8 +32,7 @@ where } impl CsCholesky -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { /// Computes the cholesky decomposition of the sparse matrix `m`. pub fn new(m: &CsMatrix) -> Self { @@ -263,7 +261,8 @@ where tree: &[usize], marks: &mut Vec, out: &mut Vec, - ) { + ) + { marks.clear(); marks.resize(tree.len(), false); diff --git a/src/sparse/cs_matrix_conversion.rs b/src/sparse/cs_matrix_conversion.rs index b764bf10..f37ef61d 100644 --- a/src/sparse/cs_matrix_conversion.rs +++ b/src/sparse/cs_matrix_conversion.rs @@ -20,14 +20,14 @@ impl<'a, N: Scalar + Zero + ClosedAdd> CsMatrix { irows: &[usize], icols: &[usize], vals: &[N], - ) -> Self { + ) -> Self + { Self::from_triplet_generic(Dynamic::new(nrows), Dynamic::new(ncols), irows, icols, vals) } } impl<'a, N: Scalar + Zero + ClosedAdd, R: Dim, C: Dim> CsMatrix -where - DefaultAllocator: Allocator + Allocator, +where DefaultAllocator: Allocator + Allocator { pub fn from_triplet_generic( nrows: R, @@ -35,7 +35,8 @@ where irows: &[usize], icols: &[usize], vals: &[N], - ) -> Self { + ) -> Self + { assert!(vals.len() == irows.len()); assert!(vals.len() == icols.len()); diff --git a/src/sparse/cs_matrix_solve.rs b/src/sparse/cs_matrix_solve.rs index 3d88455b..9cd25def 100644 --- a/src/sparse/cs_matrix_solve.rs +++ b/src/sparse/cs_matrix_solve.rs @@ -223,7 +223,8 @@ impl> CsMatrix { visited: &mut [bool], stack: &mut Vec<(usize, Range)>, xi: &mut Vec, - ) { + ) + { 'recursion: while let Some((j, rng)) = stack.pop() { visited[j] = true; @@ -260,7 +261,8 @@ impl> CsMatrix { visited: &mut [bool], stack: &mut Vec, xi: &mut Vec, - ) { + ) + { if !visited[start] { stack.clear(); stack.push(start); diff --git a/src/sparse/cs_utils.rs b/src/sparse/cs_utils.rs index a79ee4d9..3c5db43e 100644 --- a/src/sparse/cs_utils.rs +++ b/src/sparse/cs_utils.rs @@ -2,9 +2,7 @@ use allocator::Allocator; use {DefaultAllocator, Dim, VectorN}; pub fn cumsum(a: &mut VectorN, b: &mut VectorN) -> usize -where - DefaultAllocator: Allocator, -{ +where DefaultAllocator: Allocator { assert!(a.len() == b.len()); let mut sum = 0; diff --git a/tests/geometry/isometry.rs b/tests/geometry/isometry.rs index c72a2475..936f4a09 100644 --- a/tests/geometry/isometry.rs +++ b/tests/geometry/isometry.rs @@ -25,27 +25,35 @@ quickcheck!( let viewmatrix = Isometry3::look_at_rh(&eye, &target, &up); let origin = Point3::origin(); - relative_eq!(viewmatrix * eye, origin, epsilon = 1.0e-7) && - relative_eq!((viewmatrix * (target - eye)).normalize(), -Vector3::z(), epsilon = 1.0e-7) + relative_eq!(viewmatrix * eye, origin, epsilon = 1.0e-7) + && relative_eq!( + (viewmatrix * (target - eye)).normalize(), + -Vector3::z(), + epsilon = 1.0e-7 + ) } fn observer_frame_3(eye: Point3, target: Point3, up: Vector3) -> bool { let observer = Isometry3::new_observer_frame(&eye, &target, &up); let origin = Point3::origin(); - relative_eq!(observer * origin, eye, epsilon = 1.0e-7) && - relative_eq!(observer * Vector3::z(), (target - eye).normalize(), epsilon = 1.0e-7) + relative_eq!(observer * origin, eye, epsilon = 1.0e-7) + && relative_eq!( + observer * Vector3::z(), + (target - eye).normalize(), + epsilon = 1.0e-7 + ) } fn inverse_is_identity(i: Isometry3, p: Point3, v: Vector3) -> bool { let ii = i.inverse(); - relative_eq!(i * ii, Isometry3::identity(), epsilon = 1.0e-7) && - relative_eq!(ii * i, Isometry3::identity(), epsilon = 1.0e-7) && - relative_eq!((i * ii) * p, p, epsilon = 1.0e-7) && - relative_eq!((ii * i) * p, p, epsilon = 1.0e-7) && - relative_eq!((i * ii) * v, v, epsilon = 1.0e-7) && - relative_eq!((ii * i) * v, v, epsilon = 1.0e-7) + relative_eq!(i * ii, Isometry3::identity(), epsilon = 1.0e-7) + && relative_eq!(ii * i, Isometry3::identity(), epsilon = 1.0e-7) + && relative_eq!((i * ii) * p, p, epsilon = 1.0e-7) + && relative_eq!((ii * i) * p, p, epsilon = 1.0e-7) + && relative_eq!((i * ii) * v, v, epsilon = 1.0e-7) + && relative_eq!((ii * i) * v, v, epsilon = 1.0e-7) } fn inverse_is_parts_inversion(t: Translation3, r: UnitQuaternion) -> bool { @@ -54,14 +62,29 @@ quickcheck!( } fn multiply_equals_alga_transform(i: Isometry3, v: Vector3, p: Point3) -> bool { - i * v == i.transform_vector(&v) && - i * p == i.transform_point(&p) && - relative_eq!(i.inverse() * v, i.inverse_transform_vector(&v), epsilon = 1.0e-7) && - relative_eq!(i.inverse() * p, i.inverse_transform_point(&p), epsilon = 1.0e-7) + i * v == i.transform_vector(&v) + && i * p == i.transform_point(&p) + && relative_eq!( + i.inverse() * v, + i.inverse_transform_vector(&v), + epsilon = 1.0e-7 + ) + && relative_eq!( + i.inverse() * p, + i.inverse_transform_point(&p), + epsilon = 1.0e-7 + ) } - fn composition2(i: Isometry2, uc: UnitComplex, r: Rotation2, - t: Translation2, v: Vector2, p: Point2) -> bool { + fn composition2( + i: Isometry2, + uc: UnitComplex, + r: Rotation2, + t: Translation2, + v: Vector2, + p: Point2, + ) -> bool + { // (rotation × translation) * point = rotation × (translation * point) relative_eq!((uc * t) * v, uc * v, epsilon = 1.0e-7) && relative_eq!((r * t) * v, r * v, epsilon = 1.0e-7) && @@ -91,8 +114,15 @@ quickcheck!( relative_eq!((i * t) * p, i * (t * p), epsilon = 1.0e-7) } - fn composition3(i: Isometry3, uq: UnitQuaternion, r: Rotation3, - t: Translation3, v: Vector3, p: Point3) -> bool { + fn composition3( + i: Isometry3, + uq: UnitQuaternion, + r: Rotation3, + t: Translation3, + v: Vector3, + p: Point3, + ) -> bool + { // (rotation × translation) * point = rotation × (translation * point) relative_eq!((uq * t) * v, uq * v, epsilon = 1.0e-7) && relative_eq!((r * t) * v, r * v, epsilon = 1.0e-7) && @@ -122,11 +152,18 @@ quickcheck!( relative_eq!((i * t) * p, i * (t * p), epsilon = 1.0e-7) } - fn all_op_exist(i: Isometry3, uq: UnitQuaternion, t: Translation3, - v: Vector3, p: Point3, r: Rotation3) -> bool { - let iMi = i * i; + fn all_op_exist( + i: Isometry3, + uq: UnitQuaternion, + t: Translation3, + v: Vector3, + p: Point3, + r: Rotation3, + ) -> bool + { + let iMi = i * i; let iMuq = i * uq; - let iDi = i / i; + let iDi = i / i; let iDuq = i / uq; let iMp = i * p; @@ -135,13 +172,13 @@ quickcheck!( let iMt = i * t; let tMi = t * i; - let tMr = t * r; + let tMr = t * r; let tMuq = t * uq; let uqMi = uq * i; let uqDi = uq / i; - let rMt = r * t; + let rMt = r * t; let uqMt = uq * t; let mut iMt1 = i; @@ -174,75 +211,57 @@ quickcheck!( iDuq1 /= uq; iDuq2 /= &uq; - iMt == iMt1 && - iMt == iMt2 && - - iMi == iMi1 && - iMi == iMi2 && - - iMuq == iMuq1 && - iMuq == iMuq2 && - - iDi == iDi1 && - iDi == iDi2 && - - iDuq == iDuq1 && - iDuq == iDuq2 && - - iMi == &i * &i && - iMi == i * &i && - iMi == &i * i && - - iMuq == &i * &uq && - iMuq == i * &uq && - iMuq == &i * uq && - - iDi == &i / &i && - iDi == i / &i && - iDi == &i / i && - - iDuq == &i / &uq && - iDuq == i / &uq && - iDuq == &i / uq && - - iMp == &i * &p && - iMp == i * &p && - iMp == &i * p && - - iMv == &i * &v && - iMv == i * &v && - iMv == &i * v && - - iMt == &i * &t && - iMt == i * &t && - iMt == &i * t && - - tMi == &t * &i && - tMi == t * &i && - tMi == &t * i && - - tMr == &t * &r && - tMr == t * &r && - tMr == &t * r && - - tMuq == &t * &uq && - tMuq == t * &uq && - tMuq == &t * uq && - - uqMi == &uq * &i && - uqMi == uq * &i && - uqMi == &uq * i && - - uqDi == &uq / &i && - uqDi == uq / &i && - uqDi == &uq / i && - - rMt == &r * &t && - rMt == r * &t && - rMt == &r * t && - - uqMt == &uq * &t && - uqMt == uq * &t && - uqMt == &uq * t + iMt == iMt1 + && iMt == iMt2 + && iMi == iMi1 + && iMi == iMi2 + && iMuq == iMuq1 + && iMuq == iMuq2 + && iDi == iDi1 + && iDi == iDi2 + && iDuq == iDuq1 + && iDuq == iDuq2 + && iMi == &i * &i + && iMi == i * &i + && iMi == &i * i + && iMuq == &i * &uq + && iMuq == i * &uq + && iMuq == &i * uq + && iDi == &i / &i + && iDi == i / &i + && iDi == &i / i + && iDuq == &i / &uq + && iDuq == i / &uq + && iDuq == &i / uq + && iMp == &i * &p + && iMp == i * &p + && iMp == &i * p + && iMv == &i * &v + && iMv == i * &v + && iMv == &i * v + && iMt == &i * &t + && iMt == i * &t + && iMt == &i * t + && tMi == &t * &i + && tMi == t * &i + && tMi == &t * i + && tMr == &t * &r + && tMr == t * &r + && tMr == &t * r + && tMuq == &t * &uq + && tMuq == t * &uq + && tMuq == &t * uq + && uqMi == &uq * &i + && uqMi == uq * &i + && uqMi == &uq * i + && uqDi == &uq / &i + && uqDi == uq / &i + && uqDi == &uq / i + && rMt == &r * &t + && rMt == r * &t + && rMt == &r * t + && uqMt == &uq * &t + && uqMt == uq * &t + && uqMt == &uq * t } ); diff --git a/tests/geometry/point.rs b/tests/geometry/point.rs index 90c51587..ad990048 100644 --- a/tests/geometry/point.rs +++ b/tests/geometry/point.rs @@ -87,7 +87,9 @@ fn to_homogeneous() { 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/quaternion.rs b/tests/geometry/quaternion.rs index c5b91554..7d903450 100644 --- a/tests/geometry/quaternion.rs +++ b/tests/geometry/quaternion.rs @@ -10,15 +10,15 @@ quickcheck!( * */ fn from_euler_angles(r: f64, p: f64, y: f64) -> bool { - let roll = UnitQuaternion::from_euler_angles(r, 0.0, 0.0); + let roll = UnitQuaternion::from_euler_angles(r, 0.0, 0.0); let pitch = UnitQuaternion::from_euler_angles(0.0, p, 0.0); - let yaw = UnitQuaternion::from_euler_angles(0.0, 0.0, y); + let yaw = UnitQuaternion::from_euler_angles(0.0, 0.0, y); let rpy = UnitQuaternion::from_euler_angles(r, p, y); - let rroll = roll.to_rotation_matrix(); + let rroll = roll.to_rotation_matrix(); let rpitch = pitch.to_rotation_matrix(); - let ryaw = yaw.to_rotation_matrix(); + let ryaw = yaw.to_rotation_matrix(); relative_eq!(rroll[(0, 0)], 1.0, epsilon = 1.0e-7) && // rotation wrt. x axis. relative_eq!(rpitch[(1, 1)], 1.0, epsilon = 1.0e-7) && // rotation wrt. y axis. @@ -29,22 +29,24 @@ quickcheck!( fn to_euler_angles(r: f64, p: f64, y: f64) -> bool { let rpy = UnitQuaternion::from_euler_angles(r, p, y); let (roll, pitch, yaw) = rpy.to_euler_angles(); - relative_eq!(UnitQuaternion::from_euler_angles(roll, pitch, yaw), rpy, epsilon = 1.0e-7) + relative_eq!( + UnitQuaternion::from_euler_angles(roll, pitch, yaw), + rpy, + epsilon = 1.0e-7 + ) } - /* * * From/to rotation matrix. * */ fn unit_quaternion_rotation_conversion(q: UnitQuaternion) -> bool { - let r = q.to_rotation_matrix(); + let r = q.to_rotation_matrix(); let qq = UnitQuaternion::from_rotation_matrix(&r); let rr = qq.to_rotation_matrix(); - relative_eq!(q, qq, epsilon = 1.0e-7) && - relative_eq!(r, rr, epsilon = 1.0e-7) + relative_eq!(q, qq, epsilon = 1.0e-7) && relative_eq!(r, rr, epsilon = 1.0e-7) } /* @@ -52,23 +54,26 @@ quickcheck!( * Point/Vector transformation. * */ - fn unit_quaternion_transformation(q: UnitQuaternion, v: Vector3, p: Point3) -> bool { + fn unit_quaternion_transformation( + q: UnitQuaternion, + v: Vector3, + p: Point3, + ) -> bool + { let r = q.to_rotation_matrix(); let rv = r * v; let rp = r * p; - relative_eq!( q * v, rv, epsilon = 1.0e-7) && - relative_eq!( q * &v, rv, epsilon = 1.0e-7) && - relative_eq!(&q * v, rv, epsilon = 1.0e-7) && - relative_eq!(&q * &v, rv, epsilon = 1.0e-7) && - - relative_eq!( q * p, rp, epsilon = 1.0e-7) && - relative_eq!( q * &p, rp, epsilon = 1.0e-7) && - relative_eq!(&q * p, rp, epsilon = 1.0e-7) && - relative_eq!(&q * &p, rp, epsilon = 1.0e-7) + relative_eq!(q * v, rv, epsilon = 1.0e-7) + && relative_eq!(q * &v, rv, epsilon = 1.0e-7) + && relative_eq!(&q * v, rv, epsilon = 1.0e-7) + && relative_eq!(&q * &v, rv, epsilon = 1.0e-7) + && relative_eq!(q * p, rp, epsilon = 1.0e-7) + && relative_eq!(q * &p, rp, epsilon = 1.0e-7) + && relative_eq!(&q * p, rp, epsilon = 1.0e-7) + && relative_eq!(&q * &p, rp, epsilon = 1.0e-7) } - /* * * Inversion. @@ -76,15 +81,14 @@ quickcheck!( */ fn unit_quaternion_inv(q: UnitQuaternion) -> bool { let iq = q.inverse(); - relative_eq!(&iq * &q, UnitQuaternion::identity(), epsilon = 1.0e-7) && - relative_eq!( iq * &q, UnitQuaternion::identity(), epsilon = 1.0e-7) && - relative_eq!(&iq * q, UnitQuaternion::identity(), epsilon = 1.0e-7) && - relative_eq!( iq * q, UnitQuaternion::identity(), epsilon = 1.0e-7) && - - relative_eq!(&q * &iq, UnitQuaternion::identity(), epsilon = 1.0e-7) && - relative_eq!( q * &iq, UnitQuaternion::identity(), epsilon = 1.0e-7) && - relative_eq!(&q * iq, UnitQuaternion::identity(), epsilon = 1.0e-7) && - relative_eq!( q * iq, UnitQuaternion::identity(), epsilon = 1.0e-7) + relative_eq!(&iq * &q, UnitQuaternion::identity(), epsilon = 1.0e-7) + && relative_eq!(iq * &q, UnitQuaternion::identity(), epsilon = 1.0e-7) + && relative_eq!(&iq * q, UnitQuaternion::identity(), epsilon = 1.0e-7) + && relative_eq!(iq * q, UnitQuaternion::identity(), epsilon = 1.0e-7) + && relative_eq!(&q * &iq, UnitQuaternion::identity(), epsilon = 1.0e-7) + && relative_eq!(q * &iq, UnitQuaternion::identity(), epsilon = 1.0e-7) + && relative_eq!(&q * iq, UnitQuaternion::identity(), epsilon = 1.0e-7) + && relative_eq!(q * iq, UnitQuaternion::identity(), epsilon = 1.0e-7) } /* @@ -116,28 +120,34 @@ quickcheck!( // Test that all operators (incl. all combinations of references) work. // See the top comment on `geometry/quaternion_ops.rs` for details on which operations are // supported. - fn all_op_exist(q: Quaternion, uq: UnitQuaternion, - v: Vector3, p: Point3, r: Rotation3, - s: f64) -> bool { + fn all_op_exist( + q: Quaternion, + uq: UnitQuaternion, + v: Vector3, + p: Point3, + r: Rotation3, + s: f64, + ) -> bool + { let uv = Unit::new_normalize(v); let qpq = q + q; let qmq = q - q; let qMq = q * q; - let mq = -q; + let mq = -q; let qMs = q * s; let qDs = q / s; let sMq = s * q; let uqMuq = uq * uq; - let uqMr = uq * r; - let rMuq = r * uq; + let uqMr = uq * r; + let rMuq = r * uq; let uqDuq = uq / uq; - let uqDr = uq / r; - let rDuq = r / uq; + let uqDr = uq / r; + let rDuq = r / uq; - let uqMp = uq * p; - let uqMv = uq * v; + let uqMp = uq * p; + let uqMv = uq * v; let uqMuv = uq * uv; let mut qMs1 = q; @@ -186,81 +196,60 @@ quickcheck!( uqDr1 /= r; uqDr2 /= &r; - qMs1 == qMs && - - qMq1 == qMq && - qMq1 == qMq2 && - - qpq1 == qpq && - qpq1 == qpq2 && - - qmq1 == qmq && - qmq1 == qmq2 && - - uqMuq1 == uqMuq && - uqMuq1 == uqMuq2 && - - uqMr1 == uqMr && - uqMr1 == uqMr2 && - - uqDuq1 == uqDuq && - uqDuq1 == uqDuq2 && - - uqDr1 == uqDr && - uqDr1 == uqDr2 && - - qpq == &q + &q && - qpq == q + &q && - qpq == &q + q && - - qmq == &q - &q && - qmq == q - &q && - qmq == &q - q && - - qMq == &q * &q && - qMq == q * &q && - qMq == &q * q && - - mq == -&q && - - qMs == &q * s && - qDs == &q / s && - sMq == s * &q && - - uqMuq == &uq * &uq && - uqMuq == uq * &uq && - uqMuq == &uq * uq && - - uqMr == &uq * &r && - uqMr == uq * &r && - uqMr == &uq * r && - - rMuq == &r * &uq && - rMuq == r * &uq && - rMuq == &r * uq && - - uqDuq == &uq / &uq && - uqDuq == uq / &uq && - uqDuq == &uq / uq && - - uqDr == &uq / &r && - uqDr == uq / &r && - uqDr == &uq / r && - - rDuq == &r / &uq && - rDuq == r / &uq && - rDuq == &r / uq && - - uqMp == &uq * &p && - uqMp == uq * &p && - uqMp == &uq * p && - - uqMv == &uq * &v && - uqMv == uq * &v && - uqMv == &uq * v && - - uqMuv == &uq * &uv && - uqMuv == uq * &uv && - uqMuv == &uq * uv + qMs1 == qMs + && qMq1 == qMq + && qMq1 == qMq2 + && qpq1 == qpq + && qpq1 == qpq2 + && qmq1 == qmq + && qmq1 == qmq2 + && uqMuq1 == uqMuq + && uqMuq1 == uqMuq2 + && uqMr1 == uqMr + && uqMr1 == uqMr2 + && uqDuq1 == uqDuq + && uqDuq1 == uqDuq2 + && uqDr1 == uqDr + && uqDr1 == uqDr2 + && qpq == &q + &q + && qpq == q + &q + && qpq == &q + q + && qmq == &q - &q + && qmq == q - &q + && qmq == &q - q + && qMq == &q * &q + && qMq == q * &q + && qMq == &q * q + && mq == -&q + && qMs == &q * s + && qDs == &q / s + && sMq == s * &q + && uqMuq == &uq * &uq + && uqMuq == uq * &uq + && uqMuq == &uq * uq + && uqMr == &uq * &r + && uqMr == uq * &r + && uqMr == &uq * r + && rMuq == &r * &uq + && rMuq == r * &uq + && rMuq == &r * uq + && uqDuq == &uq / &uq + && uqDuq == uq / &uq + && uqDuq == &uq / uq + && uqDr == &uq / &r + && uqDr == uq / &r + && uqDr == &uq / r + && rDuq == &r / &uq + && rDuq == r / &uq + && rDuq == &r / uq + && uqMp == &uq * &p + && uqMp == uq * &p + && uqMp == &uq * p + && uqMv == &uq * &v + && uqMv == uq * &v + && uqMv == &uq * v + && uqMuv == &uq * &uv + && uqMuv == uq * &uv + && uqMuv == &uq * uv } ); diff --git a/tests/geometry/similarity.rs b/tests/geometry/similarity.rs index e9fde466..68b86943 100644 --- a/tests/geometry/similarity.rs +++ b/tests/geometry/similarity.rs @@ -8,33 +8,57 @@ quickcheck!( fn inverse_is_identity(i: Similarity3, p: Point3, v: Vector3) -> bool { let ii = i.inverse(); - relative_eq!(i * ii, Similarity3::identity(), epsilon = 1.0e-7) && - relative_eq!(ii * i, Similarity3::identity(), epsilon = 1.0e-7) && - relative_eq!((i * ii) * p, p, epsilon = 1.0e-7) && - relative_eq!((ii * i) * p, p, epsilon = 1.0e-7) && - relative_eq!((i * ii) * v, v, epsilon = 1.0e-7) && - relative_eq!((ii * i) * v, v, epsilon = 1.0e-7) + relative_eq!(i * ii, Similarity3::identity(), epsilon = 1.0e-7) + && relative_eq!(ii * i, Similarity3::identity(), epsilon = 1.0e-7) + && relative_eq!((i * ii) * p, p, epsilon = 1.0e-7) + && relative_eq!((ii * i) * p, p, epsilon = 1.0e-7) + && relative_eq!((i * ii) * v, v, epsilon = 1.0e-7) + && relative_eq!((ii * i) * v, v, epsilon = 1.0e-7) } - fn inverse_is_parts_inversion(t: Translation3, r: UnitQuaternion, scaling: f64) -> bool { + fn inverse_is_parts_inversion( + t: Translation3, + r: UnitQuaternion, + scaling: f64, + ) -> bool + { if relative_eq!(scaling, 0.0) { true - } - else { + } else { let s = Similarity3::from_isometry(t * r, scaling); s.inverse() == Similarity3::from_scaling(1.0 / scaling) * r.inverse() * t.inverse() } } - fn multiply_equals_alga_transform(s: Similarity3, v: Vector3, p: Point3) -> bool { - s * v == s.transform_vector(&v) && - s * p == s.transform_point(&p) && - relative_eq!(s.inverse() * v, s.inverse_transform_vector(&v), epsilon = 1.0e-7) && - relative_eq!(s.inverse() * p, s.inverse_transform_point(&p), epsilon = 1.0e-7) + fn multiply_equals_alga_transform( + s: Similarity3, + v: Vector3, + p: Point3, + ) -> bool + { + s * v == s.transform_vector(&v) + && s * p == s.transform_point(&p) + && relative_eq!( + s.inverse() * v, + s.inverse_transform_vector(&v), + epsilon = 1.0e-7 + ) + && relative_eq!( + s.inverse() * p, + s.inverse_transform_point(&p), + epsilon = 1.0e-7 + ) } - fn composition(i: Isometry3, uq: UnitQuaternion, - t: Translation3, v: Vector3, p: Point3, scaling: f64) -> bool { + fn composition( + i: Isometry3, + uq: UnitQuaternion, + t: Translation3, + v: Vector3, + p: Point3, + scaling: f64, + ) -> bool + { if relative_eq!(scaling, 0.0) { return true; } @@ -122,11 +146,18 @@ quickcheck!( relative_eq!((s * i * t) * p, scaling * (i * (t * p)), epsilon = 1.0e-7) } - fn all_op_exist(s: Similarity3, i: Isometry3, uq: UnitQuaternion, - t: Translation3, v: Vector3, p: Point3) -> bool { - let sMs = s * s; + fn all_op_exist( + s: Similarity3, + i: Isometry3, + uq: UnitQuaternion, + t: Translation3, + v: Vector3, + p: Point3, + ) -> bool + { + let sMs = s * s; let sMuq = s * uq; - let sDs = s / s; + let sDs = s / s; let sDuq = s / uq; let sMp = s * p; @@ -186,81 +217,61 @@ quickcheck!( sDi1 /= i; sDi2 /= &i; - sMt == sMt1 && - sMt == sMt2 && - - sMs == sMs1 && - sMs == sMs2 && - - sMuq == sMuq1 && - sMuq == sMuq2 && - - sMi == sMi1 && - sMi == sMi2 && - - sDs == sDs1 && - sDs == sDs2 && - - sDuq == sDuq1 && - sDuq == sDuq2 && - - sDi == sDi1 && - sDi == sDi2 && - - sMs == &s * &s && - sMs == s * &s && - sMs == &s * s && - - sMuq == &s * &uq && - sMuq == s * &uq && - sMuq == &s * uq && - - sDs == &s / &s && - sDs == s / &s && - sDs == &s / s && - - sDuq == &s / &uq && - sDuq == s / &uq && - sDuq == &s / uq && - - sMp == &s * &p && - sMp == s * &p && - sMp == &s * p && - - sMv == &s * &v && - sMv == s * &v && - sMv == &s * v && - - sMt == &s * &t && - sMt == s * &t && - sMt == &s * t && - - tMs == &t * &s && - tMs == t * &s && - tMs == &t * s && - - uqMs == &uq * &s && - uqMs == uq * &s && - uqMs == &uq * s && - - uqDs == &uq / &s && - uqDs == uq / &s && - uqDs == &uq / s && - - sMi == &s * &i && - sMi == s * &i && - sMi == &s * i && - - sDi == &s / &i && - sDi == s / &i && - sDi == &s / i && - - iMs == &i * &s && - iMs == i * &s && - iMs == &i * s && - - iDs == &i / &s && - iDs == i / &s && - iDs == &i / s + sMt == sMt1 + && sMt == sMt2 + && sMs == sMs1 + && sMs == sMs2 + && sMuq == sMuq1 + && sMuq == sMuq2 + && sMi == sMi1 + && sMi == sMi2 + && sDs == sDs1 + && sDs == sDs2 + && sDuq == sDuq1 + && sDuq == sDuq2 + && sDi == sDi1 + && sDi == sDi2 + && sMs == &s * &s + && sMs == s * &s + && sMs == &s * s + && sMuq == &s * &uq + && sMuq == s * &uq + && sMuq == &s * uq + && sDs == &s / &s + && sDs == s / &s + && sDs == &s / s + && sDuq == &s / &uq + && sDuq == s / &uq + && sDuq == &s / uq + && sMp == &s * &p + && sMp == s * &p + && sMp == &s * p + && sMv == &s * &v + && sMv == s * &v + && sMv == &s * v + && sMt == &s * &t + && sMt == s * &t + && sMt == &s * t + && tMs == &t * &s + && tMs == t * &s + && tMs == &t * s + && uqMs == &uq * &s + && uqMs == uq * &s + && uqMs == &uq * s + && uqDs == &uq / &s + && uqDs == uq / &s + && uqDs == &uq / s + && sMi == &s * &i + && sMi == s * &i + && sMi == &s * i + && sDi == &s / &i + && sDi == s / &i + && sDi == &s / i + && iMs == &i * &s + && iMs == i * &s + && iMs == &i * s + && iDs == &i / &s + && iDs == i / &s + && iDs == &i / s } ); diff --git a/tests/geometry/unit_complex.rs b/tests/geometry/unit_complex.rs index 7da0d20c..88988aa8 100644 --- a/tests/geometry/unit_complex.rs +++ b/tests/geometry/unit_complex.rs @@ -4,19 +4,17 @@ use na::{Point2, Rotation2, Unit, UnitComplex, Vector2}; quickcheck!( - /* * * From/to rotation matrix. * */ fn unit_complex_rotation_conversion(c: UnitComplex) -> bool { - let r = c.to_rotation_matrix(); + let r = c.to_rotation_matrix(); let cc = UnitComplex::from_rotation_matrix(&r); let rr = cc.to_rotation_matrix(); - relative_eq!(c, cc, epsilon = 1.0e-7) && - relative_eq!(r, rr, epsilon = 1.0e-7) + relative_eq!(c, cc, epsilon = 1.0e-7) && relative_eq!(r, rr, epsilon = 1.0e-7) } /* @@ -25,19 +23,18 @@ quickcheck!( * */ fn unit_complex_transformation(c: UnitComplex, v: Vector2, p: Point2) -> bool { - let r = c.to_rotation_matrix(); + let r = c.to_rotation_matrix(); let rv = r * v; let rp = r * p; - relative_eq!( c * v, rv, epsilon = 1.0e-7) && - relative_eq!( c * &v, rv, epsilon = 1.0e-7) && - relative_eq!(&c * v, rv, epsilon = 1.0e-7) && - relative_eq!(&c * &v, rv, epsilon = 1.0e-7) && - - relative_eq!( c * p, rp, epsilon = 1.0e-7) && - relative_eq!( c * &p, rp, epsilon = 1.0e-7) && - relative_eq!(&c * p, rp, epsilon = 1.0e-7) && - relative_eq!(&c * &p, rp, epsilon = 1.0e-7) + relative_eq!(c * v, rv, epsilon = 1.0e-7) + && relative_eq!(c * &v, rv, epsilon = 1.0e-7) + && relative_eq!(&c * v, rv, epsilon = 1.0e-7) + && relative_eq!(&c * &v, rv, epsilon = 1.0e-7) + && relative_eq!(c * p, rp, epsilon = 1.0e-7) + && relative_eq!(c * &p, rp, epsilon = 1.0e-7) + && relative_eq!(&c * p, rp, epsilon = 1.0e-7) + && relative_eq!(&c * &p, rp, epsilon = 1.0e-7) } /* @@ -47,15 +44,14 @@ quickcheck!( */ fn unit_complex_inv(c: UnitComplex) -> bool { let iq = c.inverse(); - relative_eq!(&iq * &c, UnitComplex::identity(), epsilon = 1.0e-7) && - relative_eq!( iq * &c, UnitComplex::identity(), epsilon = 1.0e-7) && - relative_eq!(&iq * c, UnitComplex::identity(), epsilon = 1.0e-7) && - relative_eq!( iq * c, UnitComplex::identity(), epsilon = 1.0e-7) && - - relative_eq!(&c * &iq, UnitComplex::identity(), epsilon = 1.0e-7) && - relative_eq!( c * &iq, UnitComplex::identity(), epsilon = 1.0e-7) && - relative_eq!(&c * iq, UnitComplex::identity(), epsilon = 1.0e-7) && - relative_eq!( c * iq, UnitComplex::identity(), epsilon = 1.0e-7) + relative_eq!(&iq * &c, UnitComplex::identity(), epsilon = 1.0e-7) + && relative_eq!(iq * &c, UnitComplex::identity(), epsilon = 1.0e-7) + && relative_eq!(&iq * c, UnitComplex::identity(), epsilon = 1.0e-7) + && relative_eq!(iq * c, UnitComplex::identity(), epsilon = 1.0e-7) + && relative_eq!(&c * &iq, UnitComplex::identity(), epsilon = 1.0e-7) + && relative_eq!(c * &iq, UnitComplex::identity(), epsilon = 1.0e-7) + && relative_eq!(&c * iq, UnitComplex::identity(), epsilon = 1.0e-7) + && relative_eq!(c * iq, UnitComplex::identity(), epsilon = 1.0e-7) } /* @@ -66,25 +62,30 @@ quickcheck!( fn unit_complex_mul_vector(c: UnitComplex, v: Vector2, p: Point2) -> bool { let r = c.to_rotation_matrix(); - relative_eq!(c * v, r * v, epsilon = 1.0e-7) && - relative_eq!(c * p, r * p, epsilon = 1.0e-7) + relative_eq!(c * v, r * v, epsilon = 1.0e-7) && relative_eq!(c * p, r * p, epsilon = 1.0e-7) } // Test that all operators (incl. all combinations of references) work. // See the top comment on `geometry/quaternion_ops.rs` for details on which operations are // supported. - fn all_op_exist(uc: UnitComplex, v: Vector2, p: Point2, r: Rotation2) -> bool { + fn all_op_exist( + uc: UnitComplex, + v: Vector2, + p: Point2, + r: Rotation2, + ) -> bool + { let uv = Unit::new_normalize(v); let ucMuc = uc * uc; - let ucMr = uc * r; - let rMuc = r * uc; + let ucMr = uc * r; + let rMuc = r * uc; let ucDuc = uc / uc; - let ucDr = uc / r; - let rDuc = r / uc; + let ucDr = uc / r; + let rDuc = r / uc; - let ucMp = uc * p; - let ucMv = uc * v; + let ucMp = uc * p; + let ucMv = uc * v; let ucMuv = uc * uv; let mut ucMuc1 = uc; @@ -111,52 +112,40 @@ quickcheck!( ucDr1 /= r; ucDr2 /= &r; - ucMuc1 == ucMuc && - ucMuc1 == ucMuc2 && - - ucMr1 == ucMr && - ucMr1 == ucMr2 && - - ucDuc1 == ucDuc && - ucDuc1 == ucDuc2 && - - ucDr1 == ucDr && - ucDr1 == ucDr2 && - - ucMuc == &uc * &uc && - ucMuc == uc * &uc && - ucMuc == &uc * uc && - - ucMr == &uc * &r && - ucMr == uc * &r && - ucMr == &uc * r && - - rMuc == &r * &uc && - rMuc == r * &uc && - rMuc == &r * uc && - - ucDuc == &uc / &uc && - ucDuc == uc / &uc && - ucDuc == &uc / uc && - - ucDr == &uc / &r && - ucDr == uc / &r && - ucDr == &uc / r && - - rDuc == &r / &uc && - rDuc == r / &uc && - rDuc == &r / uc && - - ucMp == &uc * &p && - ucMp == uc * &p && - ucMp == &uc * p && - - ucMv == &uc * &v && - ucMv == uc * &v && - ucMv == &uc * v && - - ucMuv == &uc * &uv && - ucMuv == uc * &uv && - ucMuv == &uc * uv + ucMuc1 == ucMuc + && ucMuc1 == ucMuc2 + && ucMr1 == ucMr + && ucMr1 == ucMr2 + && ucDuc1 == ucDuc + && ucDuc1 == ucDuc2 + && ucDr1 == ucDr + && ucDr1 == ucDr2 + && ucMuc == &uc * &uc + && ucMuc == uc * &uc + && ucMuc == &uc * uc + && ucMr == &uc * &r + && ucMr == uc * &r + && ucMr == &uc * r + && rMuc == &r * &uc + && rMuc == r * &uc + && rMuc == &r * uc + && ucDuc == &uc / &uc + && ucDuc == uc / &uc + && ucDuc == &uc / uc + && ucDr == &uc / &r + && ucDr == uc / &r + && ucDr == &uc / r + && rDuc == &r / &uc + && rDuc == r / &uc + && rDuc == &r / uc + && ucMp == &uc * &p + && ucMp == uc * &p + && ucMp == &uc * p + && ucMv == &uc * &v + && ucMv == uc * &v + && ucMv == &uc * v + && ucMuv == &uc * &uv + && ucMuv == uc * &uv + && ucMuv == &uc * uv } );