From 24d546d3b61a8f4df20f1eae7bfc643065ab914e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crozet=20S=C3=A9bastien?= Date: Sun, 11 Apr 2021 11:00:38 +0200 Subject: [PATCH] Rename generic parameter N -> T --- Cargo.toml | 2 +- benches/core/matrix.rs | 6 +- benches/core/vector.rs | 12 +- examples/dimensional_genericity.rs | 22 +- examples/matrixcompare.rs | 14 +- examples/scalar_genericity.rs | 6 +- nalgebra-glm/src/aliases.rs | 80 +-- nalgebra-glm/src/common.rs | 173 ++---- nalgebra-glm/src/constructors.rs | 108 ++-- nalgebra-glm/src/exponential.rs | 40 +- nalgebra-glm/src/ext/matrix_clip_space.rs | 302 +++++----- nalgebra-glm/src/ext/matrix_projection.rs | 118 ++-- nalgebra-glm/src/ext/matrix_relationnal.rs | 86 ++- nalgebra-glm/src/ext/matrix_transform.rs | 29 +- nalgebra-glm/src/ext/quaternion_common.rs | 16 +- nalgebra-glm/src/ext/quaternion_geometric.rs | 10 +- nalgebra-glm/src/ext/quaternion_relational.rs | 10 +- nalgebra-glm/src/ext/quaternion_transform.rs | 10 +- .../src/ext/quaternion_trigonometric.rs | 6 +- nalgebra-glm/src/ext/scalar_common.rs | 12 +- nalgebra-glm/src/ext/scalar_constants.rs | 8 +- nalgebra-glm/src/ext/vector_common.rs | 72 +-- nalgebra-glm/src/ext/vector_relational.rs | 56 +- nalgebra-glm/src/geometric.rs | 66 +-- nalgebra-glm/src/gtc/bitfield.rs | 26 +- nalgebra-glm/src/gtc/constants.rs | 96 +-- nalgebra-glm/src/gtc/epsilon.rs | 12 +- nalgebra-glm/src/gtc/integer.rs | 10 +- nalgebra-glm/src/gtc/matrix_access.rs | 41 +- nalgebra-glm/src/gtc/matrix_inverse.rs | 13 +- nalgebra-glm/src/gtc/packing.rs | 41 +- nalgebra-glm/src/gtc/quaternion.rs | 26 +- nalgebra-glm/src/gtc/round.rs | 68 ++- nalgebra-glm/src/gtc/type_ptr.rs | 114 ++-- nalgebra-glm/src/gtc/ulp.rs | 3 +- nalgebra-glm/src/gtx/component_wise.rs | 32 +- nalgebra-glm/src/gtx/euler_angles.rs | 82 +-- nalgebra-glm/src/gtx/exterior_product.rs | 2 +- .../src/gtx/handed_coordinate_space.rs | 8 +- nalgebra-glm/src/gtx/matrix_cross_product.rs | 4 +- nalgebra-glm/src/gtx/matrix_operation.rs | 18 +- nalgebra-glm/src/gtx/norm.rs | 44 +- nalgebra-glm/src/gtx/normal.rs | 2 +- nalgebra-glm/src/gtx/normalize_dot.rs | 13 +- nalgebra-glm/src/gtx/quaternion.rs | 40 +- .../src/gtx/rotate_normalized_axis.rs | 4 +- nalgebra-glm/src/gtx/rotate_vector.rs | 22 +- nalgebra-glm/src/gtx/transform.rs | 12 +- nalgebra-glm/src/gtx/transform2.rs | 60 +- nalgebra-glm/src/gtx/transform2d.rs | 6 +- nalgebra-glm/src/gtx/vector_angle.rs | 12 +- nalgebra-glm/src/gtx/vector_query.rs | 45 +- nalgebra-glm/src/integer.rs | 95 ++- nalgebra-glm/src/lib.rs | 4 +- nalgebra-glm/src/matrix.rs | 42 +- nalgebra-glm/src/packing.rs | 27 +- nalgebra-glm/src/traits.rs | 68 +-- nalgebra-glm/src/trigonometric.rs | 82 +-- nalgebra-glm/src/vector_relational.rs | 52 +- nalgebra-lapack/src/cholesky.rs | 56 +- nalgebra-lapack/src/eigen.rs | 82 +-- nalgebra-lapack/src/hessenberg.rs | 62 +- nalgebra-lapack/src/lu.rs | 116 ++-- nalgebra-lapack/src/qr.rs | 76 +-- nalgebra-lapack/src/schur.rs | 60 +- nalgebra-lapack/src/svd.rs | 78 +-- nalgebra-lapack/src/symmetric_eigen.rs | 62 +- nalgebra-sparse/src/ops/impl_std_ops.rs | 8 +- src/base/alias.rs | 181 +++--- src/base/alias_slice.rs | 507 ++++++++-------- src/base/allocator.rs | 50 +- src/base/array_storage.rs | 126 ++-- src/base/blas.rs | 454 +++++++------- src/base/cg.rs | 214 ++++--- src/base/componentwise.rs | 78 +-- src/base/construction.rs | 208 ++++--- src/base/construction_slice.rs | 62 +- src/base/conversion.rs | 255 ++++---- src/base/coordinates.rs | 14 +- src/base/default_allocator.rs | 84 +-- src/base/edition.rs | 275 ++++----- src/base/indexing.rs | 112 ++-- src/base/interpolation.rs | 54 +- src/base/iter.rs | 100 ++-- src/base/matrix.rs | 533 +++++++++-------- src/base/matrix_simba.rs | 18 +- src/base/matrix_slice.rs | 208 ++++--- src/base/min_max.rs | 62 +- src/base/norm.rs | 216 +++---- src/base/ops.rs | 404 +++++++------ src/base/properties.rs | 38 +- src/base/scalar.rs | 2 +- src/base/statistics.rs | 116 ++-- src/base/storage.rs | 64 +- src/base/swizzle.rs | 4 +- src/base/unit.rs | 70 +-- src/base/vec_storage.rs | 130 ++-- src/debug/random_orthogonal.rs | 30 +- src/debug/random_sdp.rs | 26 +- src/geometry/abstract_rotation.rs | 78 +-- src/geometry/dual_quaternion.rs | 142 ++--- src/geometry/dual_quaternion_construction.rs | 56 +- src/geometry/dual_quaternion_conversion.rs | 110 ++-- src/geometry/dual_quaternion_ops.rs | 558 +++++++++--------- src/geometry/isometry.rs | 124 ++-- src/geometry/isometry_alias.rs | 8 +- src/geometry/isometry_construction.rs | 112 ++-- src/geometry/isometry_conversion.rs | 212 +++---- src/geometry/isometry_interpolation.rs | 32 +- src/geometry/isometry_ops.rs | 122 ++-- src/geometry/isometry_simba.rs | 14 +- src/geometry/op_macros.rs | 54 +- src/geometry/orthographic.rs | 134 ++--- src/geometry/perspective.rs | 116 ++-- src/geometry/point.rs | 130 ++-- src/geometry/point_alias.rs | 12 +- src/geometry/point_construction.rs | 62 +- src/geometry/point_conversion.rs | 109 ++-- src/geometry/point_coordinates.rs | 8 +- src/geometry/point_ops.rs | 106 ++-- src/geometry/point_simba.rs | 14 +- src/geometry/quaternion.rs | 238 ++++---- src/geometry/quaternion_construction.rs | 236 ++++---- src/geometry/quaternion_conversion.rs | 220 +++---- src/geometry/quaternion_coordinates.rs | 6 +- src/geometry/quaternion_ops.rs | 280 ++++----- src/geometry/quaternion_simba.rs | 20 +- src/geometry/reflection.rs | 50 +- src/geometry/rotation.rs | 137 ++--- src/geometry/rotation_alias.rs | 4 +- src/geometry/rotation_construction.rs | 19 +- src/geometry/rotation_conversion.rs | 221 +++---- src/geometry/rotation_interpolation.rs | 16 +- src/geometry/rotation_ops.rs | 44 +- src/geometry/rotation_simba.rs | 16 +- src/geometry/rotation_specialization.rs | 274 ++++----- src/geometry/similarity.rs | 143 +++-- src/geometry/similarity_alias.rs | 8 +- src/geometry/similarity_construction.rs | 104 ++-- src/geometry/similarity_conversion.rs | 211 +++---- src/geometry/similarity_ops.rs | 118 ++-- src/geometry/similarity_simba.rs | 16 +- src/geometry/swizzle.rs | 4 +- src/geometry/transform.rs | 162 ++--- src/geometry/transform_alias.rs | 12 +- src/geometry/transform_construction.rs | 16 +- src/geometry/transform_conversion.rs | 55 +- src/geometry/transform_ops.rs | 202 +++---- src/geometry/transform_simba.rs | 18 +- src/geometry/translation.rs | 110 ++-- src/geometry/translation_alias.rs | 12 +- src/geometry/translation_construction.rs | 40 +- src/geometry/translation_conversion.rs | 178 +++--- src/geometry/translation_coordinates.rs | 9 +- src/geometry/translation_ops.rs | 32 +- src/geometry/translation_simba.rs | 14 +- src/geometry/unit_complex.rs | 84 +-- src/geometry/unit_complex_construction.rs | 110 ++-- src/geometry/unit_complex_conversion.rs | 160 ++--- src/geometry/unit_complex_ops.rs | 160 ++--- src/geometry/unit_complex_simba.rs | 10 +- src/io/matrix_market.rs | 6 +- src/lib.rs | 59 +- src/linalg/balancing.rs | 20 +- src/linalg/bidiagonal.rs | 157 ++--- src/linalg/cholesky.rs | 122 ++-- src/linalg/col_piv_qr.rs | 116 ++-- src/linalg/convolution.rs | 34 +- src/linalg/decomposition.rs | 138 ++--- src/linalg/determinant.rs | 8 +- src/linalg/eigen.rs | 51 +- src/linalg/exp.rs | 154 ++--- src/linalg/full_piv_lu.rs | 74 +-- src/linalg/givens.rs | 38 +- src/linalg/hessenberg.rs | 70 +-- src/linalg/householder.rs | 42 +- src/linalg/inverse.rs | 24 +- src/linalg/lu.rs | 136 ++--- src/linalg/permutation_sequence.rs | 34 +- src/linalg/qr.rs | 106 ++-- src/linalg/schur.rs | 175 +++--- src/linalg/solve.rs | 238 ++++---- src/linalg/svd.rs | 250 ++++---- src/linalg/symmetric_eigen.rs | 94 +-- src/linalg/symmetric_tridiagonal.rs | 88 +-- src/linalg/udu.rs | 40 +- src/proptest/mod.rs | 54 +- src/sparse/cs_matrix.rs | 113 ++-- src/sparse/cs_matrix_cholesky.rs | 60 +- src/sparse/cs_matrix_conversion.rs | 30 +- src/sparse/cs_matrix_ops.rs | 89 +-- src/sparse/cs_matrix_solve.rs | 50 +- src/sparse/cs_utils.rs | 4 +- src/third_party/alga/alga_dual_quaternion.rs | 90 +-- src/third_party/alga/alga_isometry.rs | 68 +-- src/third_party/alga/alga_matrix.rs | 156 ++--- src/third_party/alga/alga_point.rs | 28 +- src/third_party/alga/alga_quaternion.rs | 88 +-- src/third_party/alga/alga_rotation.rs | 66 +-- src/third_party/alga/alga_similarity.rs | 72 +-- src/third_party/alga/alga_transform.rs | 68 ++- src/third_party/alga/alga_translation.rs | 54 +- src/third_party/alga/alga_unit_complex.rs | 46 +- src/third_party/mint/mint_matrix.rs | 54 +- src/third_party/mint/mint_point.rs | 34 +- src/third_party/mint/mint_quaternion.rs | 12 +- src/third_party/mint/mint_rotation.rs | 4 +- tests/core/edition.rs | 26 +- tests/core/helper.rs | 20 +- tests/core/matrix.rs | 10 +- tests/core/matrix_slice.rs | 15 +- tests/core/matrixcompare.rs | 10 +- tests/linalg/eigen.rs | 6 +- tests/linalg/full_piv_lu.rs | 6 +- tests/linalg/solve.rs | 4 +- tests/proptest/mod.rs | 14 +- tests/sparse/cs_matrix_market.rs | 2 +- 217 files changed, 8542 insertions(+), 8952 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 09fec7a1..15bf01fb 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -36,7 +36,7 @@ no_unsound_assume_init = [ ] # Conversion convert-mint = [ "mint" ] convert-glam = [ "glam" ] -convert-glam-unchecked = [ "convert-glam" ] # Unable edgy conversions like Mat4 -> Isometry3 +convert-glam-unchecked = [ "convert-glam" ] # Enable edgy conversions like Mat4 -> Isometry3 convert-bytemuck = [ "bytemuck" ] # Serialization diff --git a/benches/core/matrix.rs b/benches/core/matrix.rs index 7f4432e3..af716e9e 100644 --- a/benches/core/matrix.rs +++ b/benches/core/matrix.rs @@ -1,4 +1,4 @@ -use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, MatrixN, Vector2, Vector3, Vector4, U10}; +use na::{DMatrix, DVector, Matrix2, Matrix3, Matrix4, OMatrix, Vector2, Vector3, Vector4, U10}; use rand::Rng; use rand_isaac::IsaacRng; use std::ops::{Add, Div, Mul, Sub}; @@ -116,8 +116,8 @@ fn mat10_mul_mat10(bench: &mut criterion::Criterion) { } fn mat10_mul_mat10_static(bench: &mut criterion::Criterion) { - let a = MatrixN::::new_random(); - let b = MatrixN::::new_random(); + let a = OMatrix::::new_random(); + let b = OMatrix::::new_random(); bench.bench_function("mat10_mul_mat10_static", move |bh| bh.iter(|| &a * &b)); } diff --git a/benches/core/vector.rs b/benches/core/vector.rs index 2806d034..eaee542d 100644 --- a/benches/core/vector.rs +++ b/benches/core/vector.rs @@ -1,4 +1,4 @@ -use na::{DVector, Vector2, Vector3, Vector4, VectorN}; +use na::{DVector, OVector, Vector2, Vector3, Vector4}; use rand::Rng; use rand_isaac::IsaacRng; use std::ops::{Add, Div, Mul, Sub}; @@ -45,8 +45,8 @@ bench_unop!(vec2_normalize, Vector2, normalize); bench_unop!(vec3_normalize, Vector3, normalize); bench_unop!(vec4_normalize, Vector4, normalize); -bench_binop_ref!(vec10000_dot_f64, VectorN, VectorN, dot); -bench_binop_ref!(vec10000_dot_f32, VectorN, VectorN, dot); +bench_binop_ref!(vec10000_dot_f64, OVector, OVector, dot); +bench_binop_ref!(vec10000_dot_f32, OVector, OVector, dot); fn vec10000_axpy_f64(bh: &mut criterion::Criterion) { use rand::SeedableRng; @@ -93,11 +93,11 @@ fn vec10000_axpy_f64_slice(bh: &mut criterion::Criterion) { fn vec10000_axpy_f64_static(bh: &mut criterion::Criterion) { use rand::SeedableRng; let mut rng = IsaacRng::seed_from_u64(0); - let mut a = VectorN::::new_random(); - let b = VectorN::::new_random(); + let mut a = OVector::::new_random(); + let b = OVector::::new_random(); let n = rng.gen::(); - // NOTE: for some reasons, it is much faster if the arument are boxed (Box::new(VectorN...)). + // NOTE: for some reasons, it is much faster if the arument are boxed (Box::new(OVector...)). bh.bench_function("vec10000_axpy_f64_static", move |bh| { bh.iter(|| a.axpy(n, &b, 1.0)) }); diff --git a/examples/dimensional_genericity.rs b/examples/dimensional_genericity.rs index 00c40f14..1fdd5a5f 100644 --- a/examples/dimensional_genericity.rs +++ b/examples/dimensional_genericity.rs @@ -2,26 +2,26 @@ extern crate nalgebra as na; use na::allocator::Allocator; use na::dimension::Dim; -use na::{DefaultAllocator, RealField, Unit, Vector2, Vector3, VectorN}; +use na::{DefaultAllocator, OVector, RealField, Unit, Vector2, Vector3}; /// Reflects a vector wrt. the hyperplane with normal `plane_normal`. -fn reflect_wrt_hyperplane_with_dimensional_genericity( - plane_normal: &Unit>, - vector: &VectorN, -) -> VectorN +fn reflect_wrt_hyperplane_with_dimensional_genericity( + plane_normal: &Unit>, + vector: &OVector, +) -> OVector where - N: RealField, + T: RealField, D: Dim, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let n = plane_normal.as_ref(); // Get the underlying V. vector - n * (n.dot(vector) * na::convert(2.0)) } /// Reflects a 2D vector wrt. the 2D line with normal `plane_normal`. -fn reflect_wrt_hyperplane2(plane_normal: &Unit>, vector: &Vector2) -> Vector2 +fn reflect_wrt_hyperplane2(plane_normal: &Unit>, vector: &Vector2) -> Vector2 where - N: RealField, + T: RealField, { let n = plane_normal.as_ref(); // Get the underlying Vector2 vector - n * (n.dot(vector) * na::convert(2.0)) @@ -29,9 +29,9 @@ 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 +fn reflect_wrt_hyperplane3(plane_normal: &Unit>, vector: &Vector3) -> Vector3 where - N: RealField, + T: RealField, { let n = plane_normal.as_ref(); // Get the underlying Vector3 vector - n * (n.dot(vector) * na::convert(2.0)) diff --git a/examples/matrixcompare.rs b/examples/matrixcompare.rs index 713be25f..293739de 100644 --- a/examples/matrixcompare.rs +++ b/examples/matrixcompare.rs @@ -2,20 +2,20 @@ extern crate nalgebra as na; use matrixcompare::comparators::{AbsoluteElementwiseComparator, ExactElementwiseComparator}; use matrixcompare::compare_matrices; -use na::{MatrixMN, U3, U4}; +use na::{OMatrix, U3, U4}; fn compare_integers_fail() { println!("Comparing two integer matrices."); #[rustfmt::skip] - let a = MatrixMN::<_, U3, U4>::from_row_slice(&[ + let a = OMatrix::<_, U3, U4>::from_row_slice(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, -2, 11 ]); #[rustfmt::skip] - let b = MatrixMN::<_, U3, U4>::from_row_slice(&[ + let b = OMatrix::<_, U3, U4>::from_row_slice(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 @@ -29,14 +29,14 @@ fn compare_integers_fail() { fn compare_different_size() { println!("Comparing matrices of different size."); #[rustfmt::skip] - let a = MatrixMN::<_, U3, U3>::from_row_slice(&[ + let a = OMatrix::<_, U3, U3>::from_row_slice(&[ 0, 1, 2, 4, 5, 6, 8, 9, 10, ]); #[rustfmt::skip] - let b = MatrixMN::<_, U3, U4>::from_row_slice(&[ + let b = OMatrix::<_, U3, U4>::from_row_slice(&[ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11 @@ -51,14 +51,14 @@ fn compare_f64_abs_tol_fail() { println!("Comparing two f64 matrices."); #[rustfmt::skip] - let a = MatrixMN::::from_row_slice(&[ + let a = OMatrix::::from_row_slice(&[ 0.0, 1.0, 2.0 + 1e-10, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0, ]); #[rustfmt::skip] - let b = MatrixMN::<_, U3, U3>::from_row_slice(&[ + let b = OMatrix::<_, U3, U3>::from_row_slice(&[ 0.0, 1.0, 2.0, 4.0, 5.0, 6.0, 8.0, 9.0, 10.0 diff --git a/examples/scalar_genericity.rs b/examples/scalar_genericity.rs index 403f9ec2..58559ec6 100644 --- a/examples/scalar_genericity.rs +++ b/examples/scalar_genericity.rs @@ -3,15 +3,15 @@ extern crate nalgebra as na; use na::{Scalar, Vector3}; use simba::scalar::RealField; -fn print_vector(m: &Vector3) { +fn print_vector(m: &Vector3) { println!("{:?}", m) } -fn print_norm(v: &Vector3) { +fn print_norm(v: &Vector3) { // NOTE: alternatively, nalgebra already defines `v.norm()`. let norm = v.dot(v).sqrt(); - // The RealField bound implies that N is Display so we can + // The RealField bound implies that T is Display so we can // use "{}" instead of "{:?}" for the format string. println!("{}", norm) } diff --git a/nalgebra-glm/src/aliases.rs b/nalgebra-glm/src/aliases.rs index 206a8abe..0bf7b639 100644 --- a/nalgebra-glm/src/aliases.rs +++ b/nalgebra-glm/src/aliases.rs @@ -1,9 +1,9 @@ use na::{ Matrix2, Matrix2x3, Matrix2x4, Matrix3, Matrix3x2, Matrix3x4, Matrix4, Matrix4x2, Matrix4x3, - MatrixMN, Quaternion, VectorN, U1, U2, U3, U4, + Quaternion, SMatrix, SVector, }; -/// A matrix with components of type `N`. It has `R` rows, and `C` columns. +/// A matrix with components of type `T`. It has `R` rows, and `C` columns. /// /// In this library, vectors, represented as [`TVec`](type.TVec.html) and /// friends, are also matrices. Operations that operate on a matrix will @@ -24,8 +24,8 @@ use na::{ /// * [`TMat4x3`](type.TMat4x3.html) /// * [`TMat4x4`](type.TMat4x4.html) /// * [`TVec`](type.TVec.html) -pub type TMat = MatrixMN; -/// A column vector with components of type `N`. It has `D` rows (and one column). +pub type TMat = SMatrix; +/// A column vector with components of type `T`. It has `D` rows (and one column). /// /// In this library, vectors are represented as a single column matrix, so /// operations on [`TMat`](type.TMat.html) are also valid on vectors. @@ -37,11 +37,11 @@ pub type TMat = MatrixMN; /// * [`TVec2`](type.TVec2.html) /// * [`TVec3`](type.TVec3.html) /// * [`TVec4`](type.TVec4.html) -pub type TVec = VectorN; -/// A quaternion with components of type `N`. -pub type Qua = Quaternion; +pub type TVec = SVector; +/// A quaternion with components of type `T`. +pub type Qua = Quaternion; -/// A 1D vector with components of type `N`. +/// A 1D vector with components of type `T`. /// /// # See also: /// @@ -69,8 +69,8 @@ pub type Qua = Quaternion; /// * [`U64Vec1`](type.U64Vec1.html) /// * [`U8Vec1`](type.U8Vec1.html) /// * [`Vec1`](type.Vec1.html) -pub type TVec1 = TVec; -/// A 2D vector with components of type `N`. +pub type TVec1 = TVec; +/// A 2D vector with components of type `T`. /// /// # See also: /// @@ -99,8 +99,8 @@ pub type TVec1 = TVec; /// * [`U64Vec2`](type.U64Vec2.html) /// * [`U8Vec2`](type.U8Vec2.html) /// * [`Vec2`](type.Vec2.html) -pub type TVec2 = TVec; -/// A 3D vector with components of type `N`. +pub type TVec2 = TVec; +/// A 3D vector with components of type `T`. /// /// # See also: /// @@ -129,8 +129,8 @@ pub type TVec2 = TVec; /// * [`U64Vec3`](type.U64Vec3.html) /// * [`U8Vec3`](type.U8Vec3.html) /// * [`Vec3`](type.Vec3.html) -pub type TVec3 = TVec; -/// A 4D vector with components of type `N`. +pub type TVec3 = TVec; +/// A 4D vector with components of type `T`. /// /// # See also: /// @@ -158,7 +158,7 @@ pub type TVec3 = TVec; /// * [`U64Vec4`](type.U64Vec4.html) /// * [`U8Vec4`](type.U8Vec4.html) /// * [`Vec4`](type.Vec4.html) -pub type TVec4 = TVec; +pub type TVec4 = TVec; /// A 1D vector with boolean components. pub type BVec1 = TVec1; /// A 2D vector with boolean components. @@ -268,31 +268,31 @@ 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`. -pub type TMat2x2 = Matrix2; -/// A 2x3 matrix with components of type `N`. -pub type TMat2x3 = Matrix2x3; -/// A 2x4 matrix with components of type `N`. -pub type TMat2x4 = Matrix2x4; -/// A 3x3 matrix with components of type `N`. -pub type TMat3 = Matrix3; -/// A 3x2 matrix with components of type `N`. -pub type TMat3x2 = Matrix3x2; -/// A 3x3 matrix with components of type `N`. -pub type TMat3x3 = Matrix3; -/// A 3x4 matrix with components of type `N`. -pub type TMat3x4 = Matrix3x4; -/// A 4x4 matrix with components of type `N`. -pub type TMat4 = Matrix4; -/// A 4x2 matrix with components of type `N`. -pub type TMat4x2 = Matrix4x2; -/// A 4x3 matrix with components of type `N`. -pub type TMat4x3 = Matrix4x3; -/// A 4x4 matrix with components of type `N`. -pub type TMat4x4 = Matrix4; -/// A 2x2 matrix with components of type `N`. +/// A 2x2 matrix with components of type `T`. +pub type TMat2 = Matrix2; +/// A 2x2 matrix with components of type `T`. +pub type TMat2x2 = Matrix2; +/// A 2x3 matrix with components of type `T`. +pub type TMat2x3 = Matrix2x3; +/// A 2x4 matrix with components of type `T`. +pub type TMat2x4 = Matrix2x4; +/// A 3x3 matrix with components of type `T`. +pub type TMat3 = Matrix3; +/// A 3x2 matrix with components of type `T`. +pub type TMat3x2 = Matrix3x2; +/// A 3x3 matrix with components of type `T`. +pub type TMat3x3 = Matrix3; +/// A 3x4 matrix with components of type `T`. +pub type TMat3x4 = Matrix3x4; +/// A 4x4 matrix with components of type `T`. +pub type TMat4 = Matrix4; +/// A 4x2 matrix with components of type `T`. +pub type TMat4x2 = Matrix4x2; +/// A 4x3 matrix with components of type `T`. +pub type TMat4x3 = Matrix4x3; +/// A 4x4 matrix with components of type `T`. +pub type TMat4x4 = Matrix4; +/// A 2x2 matrix with components of type `T`. pub type DMat2 = Matrix2; /// A 2x2 matrix with `f64` components. pub type DMat2x2 = Matrix2; diff --git a/nalgebra-glm/src/common.rs b/nalgebra-glm/src/common.rs index 2df38714..1efa80a3 100644 --- a/nalgebra-glm/src/common.rs +++ b/nalgebra-glm/src/common.rs @@ -1,9 +1,9 @@ use core::mem; -use na::{self, DefaultAllocator, RealField}; +use na::{self, RealField}; use num::FromPrimitive; use crate::aliases::{TMat, TVec}; -use crate::traits::{Alloc, Dimension, Number}; +use crate::traits::Number; /// For each matrix or vector component `x` if `x >= 0`; otherwise, it returns `-x`. /// @@ -21,10 +21,7 @@ use crate::traits::{Alloc, Dimension, Number}; /// # See also: /// /// * [`sign`](fn.sign.html) -pub fn abs(x: &TMat) -> TMat -where - DefaultAllocator: Alloc, -{ +pub fn abs(x: &TMat) -> TMat { x.abs() } @@ -45,10 +42,7 @@ where /// * [`fract`](fn.fract.html) /// * [`round`](fn.round.html) /// * [`trunc`](fn.trunc.html) -pub fn ceil(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn ceil(x: &TVec) -> TVec { x.map(|x| x.ceil()) } @@ -73,7 +67,7 @@ where /// /// * [`clamp`](fn.clamp.html) /// * [`clamp_vec`](fn.clamp_vec.html) -pub fn clamp_scalar(x: N, min_val: N, max_val: N) -> N { +pub fn clamp_scalar(x: T, min_val: T, max_val: T) -> T { na::clamp(x, min_val, max_val) } @@ -97,10 +91,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, -{ +pub fn clamp(x: &TVec, min_val: T, max_val: T) -> TVec { x.map(|x| na::clamp(x, min_val, max_val)) } @@ -131,14 +122,11 @@ where /// /// * [`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 { x.zip_zip_map(min_val, max_val, |a, min, max| na::clamp(a, min, max)) } @@ -172,10 +160,7 @@ pub fn float_bits_to_int(v: f32) -> i32 { /// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html) /// * [`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, -{ +pub fn float_bits_to_int_vec(v: &TVec) -> TVec { v.map(float_bits_to_int) } @@ -209,10 +194,7 @@ pub fn float_bits_to_uint(v: f32) -> u32 { /// * [`int_bits_to_float_vec`](fn.int_bits_to_float_vec.html) /// * [`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, -{ +pub fn float_bits_to_uint_vec(v: &TVec) -> TVec { v.map(float_bits_to_uint) } @@ -232,15 +214,12 @@ where /// * [`fract`](fn.fract.html) /// * [`round`](fn.round.html) /// * [`trunc`](fn.trunc.html) -pub fn floor(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn floor(x: &TVec) -> TVec { x.map(|x| x.floor()) } //// TODO: should be implemented for TVec/TMat? -//pub fn fma(a: N, b: N, c: N) -> N { +//pub fn fma(a: T, b: T, c: T) -> T { // // TODO: use an actual FMA // a * b + c //} @@ -261,16 +240,13 @@ where /// * [`floor`](fn.floor.html) /// * [`round`](fn.round.html) /// * [`trunc`](fn.trunc.html) -pub fn fract(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn fract(x: &TVec) -> TVec { x.map(|x| x.fract()) } //// TODO: should be implemented for TVec/TMat? ///// Returns the (significant, exponent) of this float number. -//pub fn frexp(x: N, exp: N) -> (N, N) { +//pub fn frexp(x: T, exp: T) -> (T, T) { // // TODO: is there a better approach? // let e = x.log2().ceil(); // (x * (-e).exp2(), e) @@ -306,27 +282,22 @@ pub fn int_bits_to_float(v: i32) -> f32 { /// * [`int_bits_to_float`](fn.int_bits_to_float.html) /// * [`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, -{ +pub fn int_bits_to_float_vec(v: &TVec) -> TVec { v.map(int_bits_to_float) } -//pub fn isinf(x: &TVec) -> TVec -// where DefaultAllocator: Alloc { +//pub fn isinf(x: &TVec) -> TVec { // unimplemented!() // //} // -//pub fn isnan(x: &TVec) -> TVec -// where DefaultAllocator: Alloc { +//pub fn isnan(x: &TVec) -> TVec { // unimplemented!() // //} ///// Returns the (significant, exponent) of this float number. -//pub fn ldexp(x: N, exp: N) -> N { +//pub fn ldexp(x: T, exp: T) -> T { // // TODO: is there a better approach? // x * (exp).exp2() //} @@ -346,8 +317,8 @@ where /// /// * [`mix`](fn.mix.html) /// * [`mix_vec`](fn.mix_vec.html) -pub fn mix_scalar(x: N, y: N, a: N) -> N { - x * (N::one() - a) + y * a +pub fn mix_scalar(x: T, y: T, a: T) -> T { + x * (T::one() - a) + y * a } /// Returns `x * (1.0 - a) + y * a`, i.e., the linear blend of the vectors x and y using the scalar value a. @@ -367,11 +338,8 @@ pub fn mix_scalar(x: N, y: N, a: N) -> N { /// /// * [`mix_scalar`](fn.mix_scalar.html) /// * [`mix_vec`](fn.mix_vec.html) -pub fn mix(x: &TVec, y: &TVec, a: N) -> TVec -where - DefaultAllocator: Alloc, -{ - x * (N::one() - a) + y * a +pub fn mix(x: &TVec, y: &TVec, a: T) -> TVec { + x * (T::one() - a) + y * a } /// Returns `x * (1.0 - a) + y * a`, i.e., the component-wise linear blend of `x` and `y` using the components of @@ -393,15 +361,12 @@ where /// /// * [`mix_scalar`](fn.mix_scalar.html) /// * [`mix`](fn.mix.html) -pub fn mix_vec( - x: &TVec, - y: &TVec, - a: &TVec, -) -> TVec -where - DefaultAllocator: Alloc, -{ - x.component_mul(&(TVec::::repeat(N::one()) - a)) + y.component_mul(&a) +pub fn mix_vec( + x: &TVec, + y: &TVec, + a: &TVec, +) -> TVec { + x.component_mul(&(TVec::::repeat(T::one()) - a)) + y.component_mul(&a) } /// Returns `x * (1.0 - a) + y * a`, i.e., the linear blend of the scalars x and y using the scalar value a. @@ -420,7 +385,7 @@ where /// /// * [`lerp`](fn.lerp.html) /// * [`lerp_vec`](fn.lerp_vec.html) -pub fn lerp_scalar(x: N, y: N, a: N) -> N { +pub fn lerp_scalar(x: T, y: T, a: T) -> T { mix_scalar(x, y, a) } @@ -442,10 +407,7 @@ pub fn lerp_scalar(x: N, y: N, a: N) -> N { /// /// * [`lerp_scalar`](fn.lerp_scalar.html) /// * [`lerp_vec`](fn.lerp_vec.html) -pub fn lerp(x: &TVec, y: &TVec, a: N) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn lerp(x: &TVec, y: &TVec, a: T) -> TVec { mix(x, y, a) } @@ -469,14 +431,11 @@ where /// /// * [`lerp_scalar`](fn.lerp_scalar.html) /// * [`lerp`](fn.lerp.html) -pub fn lerp_vec( - x: &TVec, - y: &TVec, - a: &TVec, -) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn lerp_vec( + x: &TVec, + y: &TVec, + a: &TVec, +) -> TVec { mix_vec(x, y, a) } @@ -487,10 +446,7 @@ where /// # See also: /// /// * [`modf`](fn.modf.html) -pub fn modf_vec(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn modf_vec(x: &TVec, y: &TVec) -> TVec { x.zip_map(y, |x, y| x % y) } @@ -499,7 +455,7 @@ where /// # See also: /// /// * [`modf_vec`](fn.modf_vec.html) -pub fn modf(x: N, i: N) -> N { +pub fn modf(x: T, i: T) -> T { x % i } @@ -521,15 +477,11 @@ pub fn modf(x: N, i: N) -> N { /// * [`floor`](fn.floor.html) /// * [`fract`](fn.fract.html) /// * [`trunc`](fn.trunc.html) -pub fn round(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn round(x: &TVec) -> TVec { x.map(|x| x.round()) } -//pub fn roundEven(x: &TVec) -> TVec -// where DefaultAllocator: Alloc { +//pub fn roundEven(x: &TVec) -> TVec { // unimplemented!() //} @@ -547,46 +499,37 @@ where /// /// * [`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() }) +pub fn sign(x: &TVec) -> TVec { + x.map(|x| if x.is_zero() { T::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`. /// /// This is useful in cases where you would want a threshold function with a smooth transition. /// This is equivalent to: `let result = clamp((x - edge0) / (edge1 - edge0), 0, 1); return t * t * (3 - 2 * t);` Results are undefined if `edge0 >= edge1`. -pub fn smoothstep(edge0: N, edge1: N, x: N) -> N { - let _3: N = FromPrimitive::from_f64(3.0).unwrap(); - let _2: N = FromPrimitive::from_f64(2.0).unwrap(); - let t = na::clamp((x - edge0) / (edge1 - edge0), N::zero(), N::one()); +pub fn smoothstep(edge0: T, edge1: T, x: T) -> T { + let _3: T = FromPrimitive::from_f64(3.0).unwrap(); + let _2: T = FromPrimitive::from_f64(2.0).unwrap(); + let t = na::clamp((x - edge0) / (edge1 - edge0), T::zero(), T::one()); t * t * (_3 - t * _2) } /// Returns 0.0 if `x < edge`, otherwise it returns 1.0. -pub fn step_scalar(edge: N, x: N) -> N { +pub fn step_scalar(edge: T, x: T) -> T { if edge > x { - N::zero() + T::zero() } else { - N::one() + T::one() } } /// Returns 0.0 if `x[i] < edge`, otherwise it returns 1.0. -pub fn step(edge: N, x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn step(edge: T, x: &TVec) -> TVec { 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, -{ +pub fn step_vec(edge: &TVec, x: &TVec) -> TVec { edge.zip_map(x, step_scalar) } @@ -606,10 +549,7 @@ where /// * [`floor`](fn.floor.html) /// * [`fract`](fn.fract.html) /// * [`round`](fn.round.html) -pub fn trunc(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn trunc(x: &TVec) -> TVec { x.map(|x| x.trunc()) } @@ -643,9 +583,6 @@ pub fn uint_bits_to_float_scalar(v: u32) -> f32 { /// * [`int_bits_to_float`](fn.int_bits_to_float.html) /// * [`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, -{ +pub fn uint_bits_to_float(v: &TVec) -> TVec { v.map(uint_bits_to_float_scalar) } diff --git a/nalgebra-glm/src/constructors.rs b/nalgebra-glm/src/constructors.rs index 175626a1..c6641c6e 100644 --- a/nalgebra-glm/src/constructors.rs +++ b/nalgebra-glm/src/constructors.rs @@ -2,7 +2,7 @@ use crate::aliases::{ Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1, TVec2, TVec3, TVec4, }; -use na::{RealField, Scalar, U2, U3, U4}; +use na::{RealField, Scalar}; /// Creates a new 1D vector. /// @@ -14,30 +14,30 @@ use na::{RealField, Scalar, U2, U3, U4}; /// # use nalgebra_glm as glm; /// let v = glm::vec1(true); /// ``` -pub fn vec1(x: N) -> TVec1 { +pub fn vec1(x: T) -> TVec1 { TVec1::new(x) } /// Creates a new 2D vector. -pub fn vec2(x: N, y: N) -> TVec2 { +pub fn vec2(x: T, y: T) -> TVec2 { TVec2::new(x, y) } /// Creates a new 3D vector. -pub fn vec3(x: N, y: N, z: N) -> TVec3 { +pub fn vec3(x: T, y: T, z: T) -> TVec3 { TVec3::new(x, y, z) } /// Creates a new 4D vector. -pub fn vec4(x: N, y: N, z: N, w: N) -> TVec4 { +pub fn vec4(x: T, y: T, z: T, w: T) -> TVec4 { TVec4::new(x, y, z, w) } /// Create a new 2x2 matrix. #[rustfmt::skip] -pub fn mat2(m11: N, m12: N, - m21: N, m22: N) -> TMat2 { - TMat::::new( +pub fn mat2(m11: T, m12: T, + m21: T, m22: T) -> TMat2 { + TMat::::new( m11, m12, m21, m22, ) @@ -45,9 +45,9 @@ pub fn mat2(m11: N, m12: N, /// Create a new 2x2 matrix. #[rustfmt::skip] -pub fn mat2x2(m11: N, m12: N, - m21: N, m22: N) -> TMat2 { - TMat::::new( +pub fn mat2x2(m11: T, m12: T, + m21: T, m22: T) -> TMat2 { + TMat::::new( m11, m12, m21, m22, ) @@ -55,9 +55,9 @@ pub fn mat2x2(m11: N, m12: N, /// Create a new 2x3 matrix. #[rustfmt::skip] -pub fn mat2x3(m11: N, m12: N, m13: N, - m21: N, m22: N, m23: N) -> TMat2x3 { - TMat::::new( +pub fn mat2x3(m11: T, m12: T, m13: T, + m21: T, m22: T, m23: T) -> TMat2x3 { + TMat::::new( m11, m12, m13, m21, m22, m23, ) @@ -65,9 +65,9 @@ pub fn mat2x3(m11: N, m12: N, m13: N, /// Create a new 2x4 matrix. #[rustfmt::skip] -pub fn mat2x4(m11: N, m12: N, m13: N, m14: N, - m21: N, m22: N, m23: N, m24: N) -> TMat2x4 { - TMat::::new( +pub fn mat2x4(m11: T, m12: T, m13: T, m14: T, + m21: T, m22: T, m23: T, m24: T) -> TMat2x4 { + TMat::::new( m11, m12, m13, m14, m21, m22, m23, m24, ) @@ -75,10 +75,10 @@ pub fn mat2x4(m11: N, m12: N, m13: N, m14: N, /// Create a new 3x3 matrix. #[rustfmt::skip] -pub fn mat3(m11: N, m12: N, m13: N, - m21: N, m22: N, m23: N, - m31: N, m32: N, m33: N) -> TMat3 { - TMat::::new( +pub fn mat3(m11: T, m12: T, m13: T, + m21: T, m22: T, m23: T, + m31: T, m32: T, m33: T) -> TMat3 { + TMat::::new( m11, m12, m13, m21, m22, m23, m31, m32, m33, @@ -87,10 +87,10 @@ pub fn mat3(m11: N, m12: N, m13: N, /// Create a new 3x2 matrix. #[rustfmt::skip] -pub fn mat3x2(m11: N, m12: N, - m21: N, m22: N, - m31: N, m32: N) -> TMat3x2 { - TMat::::new( +pub fn mat3x2(m11: T, m12: T, + m21: T, m22: T, + m31: T, m32: T) -> TMat3x2 { + TMat::::new( m11, m12, m21, m22, m31, m32, @@ -99,10 +99,10 @@ pub fn mat3x2(m11: N, m12: N, /// Create a new 3x3 matrix. #[rustfmt::skip] -pub fn mat3x3(m11: N, m12: N, m13: N, - m21: N, m22: N, m23: N, - m31: N, m32: N, m33: N) -> TMat3 { - TMat::::new( +pub fn mat3x3(m11: T, m12: T, m13: T, + m21: T, m22: T, m23: T, + m31: T, m32: T, m33: T) -> TMat3 { + TMat::::new( m11, m12, m13, m31, m32, m33, m21, m22, m23, @@ -111,10 +111,10 @@ pub fn mat3x3(m11: N, m12: N, m13: N, /// Create a new 3x4 matrix. #[rustfmt::skip] -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( +pub fn mat3x4(m11: T, m12: T, m13: T, m14: T, + m21: T, m22: T, m23: T, m24: T, + m31: T, m32: T, m33: T, m34: T) -> TMat3x4 { + TMat::::new( m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, @@ -123,11 +123,11 @@ pub fn mat3x4(m11: N, m12: N, m13: N, m14: N, /// Create a new 4x2 matrix. #[rustfmt::skip] -pub fn mat4x2(m11: N, m12: N, - m21: N, m22: N, - m31: N, m32: N, - m41: N, m42: N) -> TMat4x2 { - TMat::::new( +pub fn mat4x2(m11: T, m12: T, + m21: T, m22: T, + m31: T, m32: T, + m41: T, m42: T) -> TMat4x2 { + TMat::::new( m11, m12, m21, m22, m31, m32, @@ -137,11 +137,11 @@ pub fn mat4x2(m11: N, m12: N, /// Create a new 4x3 matrix. #[rustfmt::skip] -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( +pub fn mat4x3(m11: T, m12: T, m13: T, + m21: T, m22: T, m23: T, + m31: T, m32: T, m33: T, + m41: T, m42: T, m43: T) -> TMat4x3 { + TMat::::new( m11, m12, m13, m21, m22, m23, m31, m32, m33, @@ -151,11 +151,11 @@ pub fn mat4x3(m11: N, m12: N, m13: N, /// Create a new 4x4 matrix. #[rustfmt::skip] -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( +pub fn mat4x4(m11: T, m12: T, m13: T, m14: T, + m21: T, m22: T, m23: T, m24: T, + m31: T, m32: T, m33: T, m34: T, + m41: T, m42: T, m43: T, m44: T) -> TMat4 { + TMat::::new( m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, @@ -165,11 +165,11 @@ pub fn mat4x4(m11: N, m12: N, m13: N, m14: N, /// Create a new 4x4 matrix. #[rustfmt::skip] -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( +pub fn mat4(m11: T, m12: T, m13: T, m14: T, + m21: T, m22: T, m23: T, m24: T, + m31: T, m32: T, m33: T, m34: T, + m41: T, m42: T, m43: T, m44: T) -> TMat4 { + TMat::::new( m11, m12, m13, m14, m21, m22, m23, m24, m31, m32, m33, m34, @@ -178,6 +178,6 @@ pub fn mat4(m11: N, m12: N, m13: N, m14: N, } /// Creates a new quaternion. -pub fn quat(x: N, y: N, z: N, w: N) -> Qua { +pub fn quat(x: T, y: T, z: T, w: T) -> Qua { Qua::new(w, x, y, z) } diff --git a/nalgebra-glm/src/exponential.rs b/nalgebra-glm/src/exponential.rs index 5830704a..54502123 100644 --- a/nalgebra-glm/src/exponential.rs +++ b/nalgebra-glm/src/exponential.rs @@ -1,16 +1,12 @@ use crate::aliases::TVec; -use crate::traits::{Alloc, Dimension}; -use na::{DefaultAllocator, RealField}; +use na::RealField; /// Component-wise exponential. /// /// # See also: /// /// * [`exp2`](fn.exp2.html) -pub fn exp(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn exp(v: &TVec) -> TVec { v.map(|x| x.exp()) } @@ -19,10 +15,7 @@ where /// # See also: /// /// * [`exp`](fn.exp.html) -pub fn exp2(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn exp2(v: &TVec) -> TVec { v.map(|x| x.exp2()) } @@ -31,11 +24,8 @@ where /// # See also: /// /// * [`sqrt`](fn.sqrt.html) -pub fn inversesqrt(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ - v.map(|x| N::one() / x.sqrt()) +pub fn inversesqrt(v: &TVec) -> TVec { + v.map(|x| T::one() / x.sqrt()) } /// Component-wise logarithm. @@ -43,10 +33,7 @@ where /// # See also: /// /// * [`log2`](fn.log2.html) -pub fn log(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn log(v: &TVec) -> TVec { v.map(|x| x.ln()) } @@ -55,18 +42,12 @@ where /// # See also: /// /// * [`log`](fn.log.html) -pub fn log2(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn log2(v: &TVec) -> TVec { v.map(|x| x.log2()) } /// Component-wise power. -pub fn pow(base: &TVec, exponent: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn pow(base: &TVec, exponent: &TVec) -> TVec { base.zip_map(exponent, |b, e| b.powf(e)) } @@ -78,9 +59,6 @@ where /// * [`exp2`](fn.exp2.html) /// * [`inversesqrt`](fn.inversesqrt.html) /// * [`pow`](fn.pow.html) -pub fn sqrt(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn sqrt(v: &TVec) -> TVec { 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 5ee725ae..bb268a54 100644 --- a/nalgebra-glm/src/ext/matrix_clip_space.rs +++ b/nalgebra-glm/src/ext/matrix_clip_space.rs @@ -1,51 +1,51 @@ use crate::aliases::TMat4; use na::RealField; -//pub fn frustum(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { +//pub fn frustum(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} -//pub fn frustum_lh(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { +//pub fn frustum_lh(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_lr_no(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { +//pub fn frustum_lr_no(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_lh_zo(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { +//pub fn frustum_lh_zo(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_no(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { +//pub fn frustum_no(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_rh(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { +//pub fn frustum_rh(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_rh_no(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { +//pub fn frustum_rh_no(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_rh_zo(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { +//pub fn frustum_rh_zo(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} // -//pub fn frustum_zo(left: N, right: N, bottom: N, top: N, near: N, far: N) -> TMat4 { +//pub fn frustum_zo(left: T, right: T, bottom: T, top: T, near: T, far: T) -> TMat4 { // unimplemented!() //} -//pub fn infinite_perspective(fovy: N, aspect: N, near: N) -> TMat4 { +//pub fn infinite_perspective(fovy: T, aspect: T, near: T) -> TMat4 { // unimplemented!() //} // -//pub fn infinite_perspective_lh(fovy: N, aspect: N, near: N) -> TMat4 { +//pub fn infinite_perspective_lh(fovy: T, aspect: T, near: T) -> TMat4 { // unimplemented!() //} // -//pub fn infinite_ortho(left: N, right: N, bottom: N, top: N) -> TMat4 { +//pub fn infinite_ortho(left: T, right: T, bottom: T, top: T) -> TMat4 { // unimplemented!() //} @@ -60,7 +60,7 @@ use na::RealField; /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { +pub fn ortho(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4 { ortho_rh_no(left, right, bottom, top, znear, zfar) } @@ -75,7 +75,7 @@ pub fn ortho(left: N, right: N, bottom: N, top: N, znear: N, zfar: /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_lh(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { +pub fn ortho_lh(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4 { ortho_lh_no(left, right, bottom, top, znear, zfar) } @@ -90,16 +90,16 @@ pub fn ortho_lh(left: N, right: N, bottom: N, top: N, znear: N, zf /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_lh_no( - left: N, - right: N, - bottom: N, - top: N, - znear: N, - zfar: N, -) -> TMat4 { - let two: N = crate::convert(2.0); - let mut mat: TMat4 = TMat4::::identity(); +pub fn ortho_lh_no( + left: T, + right: T, + bottom: T, + top: T, + znear: T, + zfar: T, +) -> TMat4 { + let two: T = crate::convert(2.0); + let mut mat: TMat4 = TMat4::::identity(); mat[(0, 0)] = two / (right - left); mat[(0, 3)] = -(right + left) / (right - left); @@ -122,17 +122,17 @@ pub fn ortho_lh_no( /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_lh_zo( - left: N, - right: N, - bottom: N, - top: N, - znear: N, - zfar: N, -) -> TMat4 { - let one: N = N::one(); - let two: N = crate::convert(2.0); - let mut mat: TMat4 = TMat4::::identity(); +pub fn ortho_lh_zo( + left: T, + right: T, + bottom: T, + top: T, + znear: T, + zfar: T, +) -> TMat4 { + let one: T = T::one(); + let two: T = crate::convert(2.0); + let mut mat: TMat4 = TMat4::::identity(); mat[(0, 0)] = two / (right - left); mat[(0, 3)] = -(right + left) / (right - left); @@ -155,7 +155,7 @@ pub fn ortho_lh_zo( /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_no(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { +pub fn ortho_no(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4 { ortho_rh_no(left, right, bottom, top, znear, zfar) } @@ -170,7 +170,7 @@ pub fn ortho_no(left: N, right: N, bottom: N, top: N, znear: N, zf /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_rh(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { +pub fn ortho_rh(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4 { ortho_rh_no(left, right, bottom, top, znear, zfar) } @@ -185,16 +185,16 @@ pub fn ortho_rh(left: N, right: N, bottom: N, top: N, znear: N, zf /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_rh_no( - left: N, - right: N, - bottom: N, - top: N, - znear: N, - zfar: N, -) -> TMat4 { - let two: N = crate::convert(2.0); - let mut mat: TMat4 = TMat4::::identity(); +pub fn ortho_rh_no( + left: T, + right: T, + bottom: T, + top: T, + znear: T, + zfar: T, +) -> TMat4 { + let two: T = crate::convert(2.0); + let mut mat: TMat4 = TMat4::::identity(); mat[(0, 0)] = two / (right - left); mat[(0, 3)] = -(right + left) / (right - left); @@ -217,17 +217,17 @@ pub fn ortho_rh_no( /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_rh_zo( - left: N, - right: N, - bottom: N, - top: N, - znear: N, - zfar: N, -) -> TMat4 { - let one: N = N::one(); - let two: N = crate::convert(2.0); - let mut mat: TMat4 = TMat4::::identity(); +pub fn ortho_rh_zo( + left: T, + right: T, + bottom: T, + top: T, + znear: T, + zfar: T, +) -> TMat4 { + let one: T = T::one(); + let two: T = crate::convert(2.0); + let mut mat: TMat4 = TMat4::::identity(); mat[(0, 0)] = two / (right - left); mat[(0, 3)] = -(right + left) / (right - left); @@ -250,7 +250,7 @@ pub fn ortho_rh_zo( /// * `znear` - Distance from the viewer to the near clipping plane /// * `zfar` - Distance from the viewer to the far clipping plane /// -pub fn ortho_zo(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> TMat4 { +pub fn ortho_zo(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> TMat4 { ortho_rh_zo(left, right, bottom, top, znear, zfar) } @@ -264,7 +264,7 @@ pub fn ortho_zo(left: N, right: N, bottom: N, top: N, znear: N, zf /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { +pub fn perspective_fov(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { perspective_fov_rh_no(fov, width, height, near, far) } @@ -278,7 +278,7 @@ pub fn perspective_fov(fov: N, width: N, height: N, near: N, far: /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_lh(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { +pub fn perspective_fov_lh(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { perspective_fov_lh_no(fov, width, height, near, far) } @@ -292,16 +292,16 @@ pub fn perspective_fov_lh(fov: N, width: N, height: N, near: N, fa /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_lh_no( - fov: N, - width: N, - height: N, - near: N, - far: N, -) -> TMat4 { - assert!(width > N::zero(), "The width must be greater than zero"); - assert!(height > N::zero(), "The height must be greater than zero."); - assert!(fov > N::zero(), "The fov must be greater than zero"); +pub fn perspective_fov_lh_no( + fov: T, + width: T, + height: T, + near: T, + far: T, +) -> TMat4 { + assert!(width > T::zero(), "The width must be greater than zero"); + assert!(height > T::zero(), "The height must be greater than zero."); + assert!(fov > T::zero(), "The fov must be greater than zero"); let mut mat = TMat4::zeros(); @@ -313,7 +313,7 @@ pub fn perspective_fov_lh_no( mat[(1, 1)] = h; mat[(2, 2)] = (far + near) / (far - near); mat[(2, 3)] = -(far * near * crate::convert(2.0)) / (far - near); - mat[(3, 2)] = N::one(); + mat[(3, 2)] = T::one(); mat } @@ -328,16 +328,16 @@ pub fn perspective_fov_lh_no( /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_lh_zo( - fov: N, - width: N, - height: N, - near: N, - far: N, -) -> TMat4 { - assert!(width > N::zero(), "The width must be greater than zero"); - assert!(height > N::zero(), "The height must be greater than zero."); - assert!(fov > N::zero(), "The fov must be greater than zero"); +pub fn perspective_fov_lh_zo( + fov: T, + width: T, + height: T, + near: T, + far: T, +) -> TMat4 { + assert!(width > T::zero(), "The width must be greater than zero"); + assert!(height > T::zero(), "The height must be greater than zero."); + assert!(fov > T::zero(), "The fov must be greater than zero"); let mut mat = TMat4::zeros(); @@ -349,7 +349,7 @@ pub fn perspective_fov_lh_zo( mat[(1, 1)] = h; mat[(2, 2)] = far / (far - near); mat[(2, 3)] = -(far * near) / (far - near); - mat[(3, 2)] = N::one(); + mat[(3, 2)] = T::one(); mat } @@ -364,7 +364,7 @@ pub fn perspective_fov_lh_zo( /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_no(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { +pub fn perspective_fov_no(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { perspective_fov_rh_no(fov, width, height, near, far) } @@ -378,7 +378,7 @@ pub fn perspective_fov_no(fov: N, width: N, height: N, near: N, fa /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_rh(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { +pub fn perspective_fov_rh(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { perspective_fov_rh_no(fov, width, height, near, far) } @@ -392,16 +392,16 @@ pub fn perspective_fov_rh(fov: N, width: N, height: N, near: N, fa /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_rh_no( - fov: N, - width: N, - height: N, - near: N, - far: N, -) -> TMat4 { - assert!(width > N::zero(), "The width must be greater than zero"); - assert!(height > N::zero(), "The height must be greater than zero."); - assert!(fov > N::zero(), "The fov must be greater than zero"); +pub fn perspective_fov_rh_no( + fov: T, + width: T, + height: T, + near: T, + far: T, +) -> TMat4 { + assert!(width > T::zero(), "The width must be greater than zero"); + assert!(height > T::zero(), "The height must be greater than zero."); + assert!(fov > T::zero(), "The fov must be greater than zero"); let mut mat = TMat4::zeros(); @@ -413,7 +413,7 @@ pub fn perspective_fov_rh_no( mat[(1, 1)] = h; mat[(2, 2)] = -(far + near) / (far - near); mat[(2, 3)] = -(far * near * crate::convert(2.0)) / (far - near); - mat[(3, 2)] = -N::one(); + mat[(3, 2)] = -T::one(); mat } @@ -428,16 +428,16 @@ pub fn perspective_fov_rh_no( /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_rh_zo( - fov: N, - width: N, - height: N, - near: N, - far: N, -) -> TMat4 { - assert!(width > N::zero(), "The width must be greater than zero"); - assert!(height > N::zero(), "The height must be greater than zero."); - assert!(fov > N::zero(), "The fov must be greater than zero"); +pub fn perspective_fov_rh_zo( + fov: T, + width: T, + height: T, + near: T, + far: T, +) -> TMat4 { + assert!(width > T::zero(), "The width must be greater than zero"); + assert!(height > T::zero(), "The height must be greater than zero."); + assert!(fov > T::zero(), "The fov must be greater than zero"); let mut mat = TMat4::zeros(); @@ -449,7 +449,7 @@ pub fn perspective_fov_rh_zo( mat[(1, 1)] = h; mat[(2, 2)] = far / (near - far); mat[(2, 3)] = -(far * near) / (far - near); - mat[(3, 2)] = -N::one(); + mat[(3, 2)] = -T::one(); mat } @@ -464,7 +464,7 @@ pub fn perspective_fov_rh_zo( /// * `near` - Distance from the viewer to the near clipping plane /// * `far` - Distance from the viewer to the far clipping plane /// -pub fn perspective_fov_zo(fov: N, width: N, height: N, near: N, far: N) -> TMat4 { +pub fn perspective_fov_zo(fov: T, width: T, height: T, near: T, far: T) -> TMat4 { perspective_fov_rh_zo(fov, width, height, near, far) } @@ -479,7 +479,7 @@ pub fn perspective_fov_zo(fov: N, width: N, height: N, near: N, fa /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective(aspect: N, fovy: N, near: N, far: N) -> TMat4 { +pub fn perspective(aspect: T, fovy: T, near: T, far: T) -> TMat4 { // TODO: Breaking change - revert back to proper glm conventions? // // Prior to changes to support configuring the behaviour of this function it was simply @@ -508,7 +508,7 @@ pub fn perspective(aspect: N, fovy: N, near: N, far: N) -> TMat4(aspect: N, fovy: N, near: N, far: N) -> TMat4 { +pub fn perspective_lh(aspect: T, fovy: T, near: T, far: T) -> TMat4 { perspective_lh_no(aspect, fovy, near, far) } @@ -523,19 +523,19 @@ pub fn perspective_lh(aspect: N, fovy: N, near: N, far: N) -> TMat /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_lh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4 { +pub fn perspective_lh_no(aspect: T, fovy: T, near: T, far: T) -> TMat4 { assert!( - !relative_eq!(far - near, N::zero()), + !relative_eq!(far - near, T::zero()), "The near-plane and far-plane must not be superimposed." ); assert!( - !relative_eq!(aspect, N::zero()), + !relative_eq!(aspect, T::zero()), "The aspect ratio must not be zero." ); - let one = N::one(); - let two: N = crate::convert(2.0); - let mut mat: TMat4 = TMat4::zeros(); + let one = T::one(); + let two: T = crate::convert(2.0); + let mut mat: TMat4 = TMat4::zeros(); let tan_half_fovy = (fovy / two).tan(); @@ -559,19 +559,19 @@ pub fn perspective_lh_no(aspect: N, fovy: N, near: N, far: N) -> T /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_lh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4 { +pub fn perspective_lh_zo(aspect: T, fovy: T, near: T, far: T) -> TMat4 { assert!( - !relative_eq!(far - near, N::zero()), + !relative_eq!(far - near, T::zero()), "The near-plane and far-plane must not be superimposed." ); assert!( - !relative_eq!(aspect, N::zero()), + !relative_eq!(aspect, T::zero()), "The aspect ratio must not be zero." ); - let one = N::one(); - let two: N = crate::convert(2.0); - let mut mat: TMat4 = TMat4::zeros(); + let one = T::one(); + let two: T = crate::convert(2.0); + let mut mat: TMat4 = TMat4::zeros(); let tan_half_fovy = (fovy / two).tan(); @@ -595,7 +595,7 @@ pub fn perspective_lh_zo(aspect: N, fovy: N, near: N, far: N) -> T /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_no(aspect: N, fovy: N, near: N, far: N) -> TMat4 { +pub fn perspective_no(aspect: T, fovy: T, near: T, far: T) -> TMat4 { perspective_rh_no(aspect, fovy, near, far) } @@ -610,7 +610,7 @@ pub fn perspective_no(aspect: N, fovy: N, near: N, far: N) -> TMat /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_rh(aspect: N, fovy: N, near: N, far: N) -> TMat4 { +pub fn perspective_rh(aspect: T, fovy: T, near: T, far: T) -> TMat4 { perspective_rh_no(aspect, fovy, near, far) } @@ -625,19 +625,19 @@ pub fn perspective_rh(aspect: N, fovy: N, near: N, far: N) -> TMat /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_rh_no(aspect: N, fovy: N, near: N, far: N) -> TMat4 { +pub fn perspective_rh_no(aspect: T, fovy: T, near: T, far: T) -> TMat4 { assert!( - !relative_eq!(far - near, N::zero()), + !relative_eq!(far - near, T::zero()), "The near-plane and far-plane must not be superimposed." ); assert!( - !relative_eq!(aspect, N::zero()), + !relative_eq!(aspect, T::zero()), "The aspect ratio must not be zero." ); - let negone = -N::one(); - let one = N::one(); - let two: N = crate::convert(2.0); + let negone = -T::one(); + let one = T::one(); + let two: T = crate::convert(2.0); let mut mat = TMat4::zeros(); let tan_half_fovy = (fovy / two).tan(); @@ -662,18 +662,18 @@ pub fn perspective_rh_no(aspect: N, fovy: N, near: N, far: N) -> T /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_rh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4 { +pub fn perspective_rh_zo(aspect: T, fovy: T, near: T, far: T) -> TMat4 { assert!( - !relative_eq!(far - near, N::zero()), + !relative_eq!(far - near, T::zero()), "The near-plane and far-plane must not be superimposed." ); assert!( - !relative_eq!(aspect, N::zero()), + !relative_eq!(aspect, T::zero()), "The aspect ratio must not be zero." ); - let negone = -N::one(); - let one = N::one(); + let negone = -T::one(); + let one = T::one(); let two = crate::convert(2.0); let mut mat = TMat4::zeros(); @@ -699,7 +699,7 @@ pub fn perspective_rh_zo(aspect: N, fovy: N, near: N, far: N) -> T /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn perspective_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4 { +pub fn perspective_zo(aspect: T, fovy: T, near: T, far: T) -> TMat4 { perspective_rh_zo(aspect, fovy, near, far) } @@ -713,15 +713,15 @@ pub fn perspective_zo(aspect: N, fovy: N, near: N, far: N) -> TMat /// /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. -pub fn infinite_perspective_rh_no(aspect: N, fovy: N, near: N) -> TMat4 { - let f = N::one() / (fovy * na::convert(0.5)).tan(); +pub fn infinite_perspective_rh_no(aspect: T, fovy: T, near: T) -> TMat4 { + let f = T::one() / (fovy * na::convert(0.5)).tan(); let mut mat = TMat4::zeros(); mat[(0, 0)] = f / aspect; mat[(1, 1)] = f; - mat[(2, 2)] = -N::one(); + mat[(2, 2)] = -T::one(); mat[(2, 3)] = -near * na::convert(2.0); - mat[(3, 2)] = -N::one(); + mat[(3, 2)] = -T::one(); mat } @@ -738,15 +738,15 @@ pub fn infinite_perspective_rh_no(aspect: N, fovy: N, near: N) -> /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. /// // https://discourse.nphysics.org/t/reversed-z-and-infinite-zfar-in-projections/341/2 -pub fn infinite_perspective_rh_zo(aspect: N, fovy: N, near: N) -> TMat4 { - let f = N::one() / (fovy * na::convert(0.5)).tan(); +pub fn infinite_perspective_rh_zo(aspect: T, fovy: T, near: T) -> TMat4 { + let f = T::one() / (fovy * na::convert(0.5)).tan(); let mut mat = TMat4::zeros(); mat[(0, 0)] = f / aspect; mat[(1, 1)] = f; - mat[(2, 2)] = -N::one(); + mat[(2, 2)] = -T::one(); mat[(2, 3)] = -near; - mat[(3, 2)] = -N::one(); + mat[(3, 2)] = -T::one(); mat } @@ -763,8 +763,8 @@ pub fn infinite_perspective_rh_zo(aspect: N, fovy: N, near: N) -> /// # Important note /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. // NOTE: The variants `_no` of reversed perspective are not useful. -pub fn reversed_perspective_rh_zo(aspect: N, fovy: N, near: N, far: N) -> TMat4 { - let one = N::one(); +pub fn reversed_perspective_rh_zo(aspect: T, fovy: T, near: T, far: T) -> TMat4 { + let one = T::one(); let two = crate::convert(2.0); let mut mat = TMat4::zeros(); @@ -791,22 +791,22 @@ pub fn reversed_perspective_rh_zo(aspect: N, fovy: N, near: N, far /// The `aspect` and `fovy` argument are interchanged compared to the original GLM API. // Credit: https://discourse.nphysics.org/t/reversed-z-and-infinite-zfar-in-projections/341/2 // NOTE: The variants `_no` of reversed perspective are not useful. -pub fn reversed_infinite_perspective_rh_zo(aspect: N, fovy: N, near: N) -> TMat4 { - let f = N::one() / (fovy * na::convert(0.5)).tan(); +pub fn reversed_infinite_perspective_rh_zo(aspect: T, fovy: T, near: T) -> TMat4 { + let f = T::one() / (fovy * na::convert(0.5)).tan(); let mut mat = TMat4::zeros(); mat[(0, 0)] = f / aspect; mat[(1, 1)] = f; mat[(2, 3)] = near; - mat[(3, 2)] = -N::one(); + mat[(3, 2)] = -T::one(); mat } -//pub fn tweaked_infinite_perspective(fovy: N, aspect: N, near: N) -> TMat4 { +//pub fn tweaked_infinite_perspective(fovy: T, aspect: T, near: T) -> TMat4 { // unimplemented!() //} // -//pub fn tweaked_infinite_perspective_ep(fovy: N, aspect: N, near: N, ep: N) -> TMat4 { +//pub fn tweaked_infinite_perspective_ep(fovy: T, aspect: T, near: T, ep: T) -> TMat4 { // unimplemented!() //} diff --git a/nalgebra-glm/src/ext/matrix_projection.rs b/nalgebra-glm/src/ext/matrix_projection.rs index 93c8d664..b9d8f045 100644 --- a/nalgebra-glm/src/ext/matrix_projection.rs +++ b/nalgebra-glm/src/ext/matrix_projection.rs @@ -1,4 +1,4 @@ -use na::{self, RealField, U3}; +use na::{self, RealField}; use crate::aliases::{TMat4, TVec2, TVec3, TVec4}; @@ -9,22 +9,22 @@ use crate::aliases::{TMat4, TVec2, TVec3, TVec4}; /// * `center` - Specify the center of a picking region in window coordinates. /// * `delta` - Specify the width and height, respectively, of the picking region in window coordinates. /// * `viewport` - Rendering viewport. -pub fn pick_matrix( - center: &TVec2, - delta: &TVec2, - viewport: &TVec4, -) -> TMat4 { +pub fn pick_matrix( + center: &TVec2, + delta: &TVec2, + viewport: &TVec4, +) -> TMat4 { 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(), + T::zero(), ); let result = TMat4::new_translation(&shift); result.prepend_nonuniform_scaling(&TVec3::new( viewport.z / delta.x, viewport.w / delta.y, - N::one(), + T::one(), )) } @@ -45,12 +45,12 @@ pub fn pick_matrix( /// * [`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) } @@ -72,12 +72,12 @@ pub fn project( /// * [`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)) } @@ -100,18 +100,18 @@ pub fn project_no( /// * [`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 { - let normalized = proj * model * TVec4::new(obj.x, obj.y, obj.z, N::one()); - let scale = N::one() / normalized.w; +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, T::one()); + let scale = T::one() / normalized.w; TVec3::new( - viewport.x + (viewport.z * (normalized.x * scale + N::one()) * na::convert(0.5)), - viewport.y + (viewport.w * (normalized.y * scale + N::one()) * na::convert(0.5)), + viewport.x + (viewport.z * (normalized.x * scale + T::one()) * na::convert(0.5)), + viewport.y + (viewport.w * (normalized.y * scale + T::one()) * na::convert(0.5)), normalized.z * scale, ) } @@ -133,12 +133,12 @@ pub fn project_zo( /// * [`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) } @@ -160,23 +160,23 @@ pub fn unproject( /// * [`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 { - let _2: N = na::convert(2.0); +pub fn unproject_no( + win: &TVec3, + model: &TMat4, + proj: &TMat4, + viewport: TVec4, +) -> TVec3 { + let _2: T = na::convert(2.0); let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros); let pt = TVec4::new( - _2 * (win.x - viewport.x) / viewport.z - N::one(), - _2 * (win.y - viewport.y) / viewport.w - N::one(), - _2 * win.z - N::one(), - N::one(), + _2 * (win.x - viewport.x) / viewport.z - T::one(), + _2 * (win.y - viewport.y) / viewport.w - T::one(), + _2 * win.z - T::one(), + T::one(), ); let result = transform * pt; - result.fixed_rows::(0) / result.w + result.fixed_rows::<3>(0) / result.w } /// Map the specified window coordinates (win.x, win.y, win.z) into object coordinates. @@ -197,21 +197,21 @@ pub fn unproject_no( /// * [`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 { - let _2: N = na::convert(2.0); +pub fn unproject_zo( + win: &TVec3, + model: &TMat4, + proj: &TMat4, + viewport: TVec4, +) -> TVec3 { + let _2: T = na::convert(2.0); let transform = (proj * model).try_inverse().unwrap_or_else(TMat4::zeros); let pt = TVec4::new( - _2 * (win.x - viewport.x) / viewport.z - N::one(), - _2 * (win.y - viewport.y) / viewport.w - N::one(), + _2 * (win.x - viewport.x) / viewport.z - T::one(), + _2 * (win.y - viewport.y) / viewport.w - T::one(), win.z, - N::one(), + T::one(), ); let result = transform * pt; - result.fixed_rows::(0) / result.w + result.fixed_rows::<3>(0) / result.w } diff --git a/nalgebra-glm/src/ext/matrix_relationnal.rs b/nalgebra-glm/src/ext/matrix_relationnal.rs index 7866e72a..e8d1e2fd 100644 --- a/nalgebra-glm/src/ext/matrix_relationnal.rs +++ b/nalgebra-glm/src/ext/matrix_relationnal.rs @@ -1,21 +1,16 @@ -use na::DefaultAllocator; - use crate::aliases::{TMat, TVec}; -use crate::traits::{Alloc, Dimension, Number}; +use crate::traits::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 { let mut res = TVec::<_, C>::repeat(false); - for i in 0..C::dim() { + for i in 0..C { res[i] = x.column(i) == y.column(i) } @@ -25,31 +20,25 @@ where /// 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: T, +) -> TVec { 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 { let mut res = TVec::<_, C>::repeat(false); - for i in 0..C::dim() { + for i in 0..C { res[i] = (x.column(i) - y.column(i)).abs() < TVec::<_, R>::repeat(epsilon[i]) } @@ -59,16 +48,13 @@ where /// Perform a component-wise not-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 not_equal_columns( - x: &TMat, - y: &TMat, -) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn not_equal_columns( + x: &TMat, + y: &TMat, +) -> TVec { let mut res = TVec::<_, C>::repeat(false); - for i in 0..C::dim() { + for i in 0..C { res[i] = x.column(i) != y.column(i) } @@ -78,31 +64,25 @@ where /// Returns the component-wise comparison of `|x - y| < epsilon`. /// /// True if this expression is not satisfied. -pub fn not_equal_columns_eps( - x: &TMat, - y: &TMat, - epsilon: N, -) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn not_equal_columns_eps( + x: &TMat, + y: &TMat, + epsilon: T, +) -> TVec { 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 { let mut res = TVec::<_, C>::repeat(false); - for i in 0..C::dim() { + for i in 0..C { res[i] = (x.column(i) - y.column(i)).abs() >= TVec::<_, R>::repeat(epsilon[i]) } diff --git a/nalgebra-glm/src/ext/matrix_transform.rs b/nalgebra-glm/src/ext/matrix_transform.rs index df0696a4..821b585a 100644 --- a/nalgebra-glm/src/ext/matrix_transform.rs +++ b/nalgebra-glm/src/ext/matrix_transform.rs @@ -1,14 +1,11 @@ -use na::{DefaultAllocator, Point3, RealField, Rotation3, Unit}; +use na::{Point3, RealField, Rotation3, Unit}; use crate::aliases::{TMat, TMat4, TVec, TVec3}; -use crate::traits::{Alloc, Dimension, Number}; +use crate::traits::Number; /// The identity matrix. -pub fn identity() -> TMat -where - DefaultAllocator: Alloc, -{ - TMat::::identity() +pub fn identity() -> TMat { + TMat::::identity() } /// Build a look at view matrix based on the right handedness. @@ -23,7 +20,7 @@ where /// /// * [`look_at_lh`](fn.look_at_lh.html) /// * [`look_at_rh`](fn.look_at_rh.html) -pub fn look_at(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { +pub fn look_at(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { look_at_rh(eye, center, up) } @@ -39,7 +36,7 @@ pub fn look_at(eye: &TVec3, center: &TVec3, up: &TVec3) - /// /// * [`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 { +pub fn look_at_lh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { TMat::look_at_lh(&Point3::from(*eye), &Point3::from(*center), up) } @@ -55,7 +52,7 @@ 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 { +pub fn look_at_rh(eye: &TVec3, center: &TVec3, up: &TVec3) -> TMat4 { TMat::look_at_rh(&Point3::from(*eye), &Point3::from(*center), up) } @@ -74,7 +71,7 @@ pub fn look_at_rh(eye: &TVec3, center: &TVec3, up: &TVec3 /// * [`rotate_z`](fn.rotate_z.html) /// * [`scale`](fn.scale.html) /// * [`translate`](fn.translate.html) -pub fn rotate(m: &TMat4, angle: N, axis: &TVec3) -> TMat4 { +pub fn rotate(m: &TMat4, angle: T, axis: &TVec3) -> TMat4 { m * Rotation3::from_axis_angle(&Unit::new_normalize(*axis), angle).to_homogeneous() } @@ -92,7 +89,7 @@ pub fn rotate(m: &TMat4, angle: N, axis: &TVec3) -> TMat4 /// * [`rotate_z`](fn.rotate_z.html) /// * [`scale`](fn.scale.html) /// * [`translate`](fn.translate.html) -pub fn rotate_x(m: &TMat4, angle: N) -> TMat4 { +pub fn rotate_x(m: &TMat4, angle: T) -> TMat4 { rotate(m, angle, &TVec::x()) } @@ -110,7 +107,7 @@ pub fn rotate_x(m: &TMat4, angle: N) -> TMat4 { /// * [`rotate_z`](fn.rotate_z.html) /// * [`scale`](fn.scale.html) /// * [`translate`](fn.translate.html) -pub fn rotate_y(m: &TMat4, angle: N) -> TMat4 { +pub fn rotate_y(m: &TMat4, angle: T) -> TMat4 { rotate(m, angle, &TVec::y()) } @@ -128,7 +125,7 @@ pub fn rotate_y(m: &TMat4, angle: N) -> TMat4 { /// * [`rotate_y`](fn.rotate_y.html) /// * [`scale`](fn.scale.html) /// * [`translate`](fn.translate.html) -pub fn rotate_z(m: &TMat4, angle: N) -> TMat4 { +pub fn rotate_z(m: &TMat4, angle: T) -> TMat4 { rotate(m, angle, &TVec::z()) } @@ -146,7 +143,7 @@ pub fn rotate_z(m: &TMat4, angle: N) -> TMat4 { /// * [`rotate_y`](fn.rotate_y.html) /// * [`rotate_z`](fn.rotate_z.html) /// * [`translate`](fn.translate.html) -pub fn scale(m: &TMat4, v: &TVec3) -> TMat4 { +pub fn scale(m: &TMat4, v: &TVec3) -> TMat4 { m.prepend_nonuniform_scaling(v) } @@ -164,6 +161,6 @@ pub fn scale(m: &TMat4, v: &TVec3) -> TMat4 { /// * [`rotate_y`](fn.rotate_y.html) /// * [`rotate_z`](fn.rotate_z.html) /// * [`scale`](fn.scale.html) -pub fn translate(m: &TMat4, v: &TVec3) -> TMat4 { +pub fn translate(m: &TMat4, v: &TVec3) -> TMat4 { m.prepend_translation(v) } diff --git a/nalgebra-glm/src/ext/quaternion_common.rs b/nalgebra-glm/src/ext/quaternion_common.rs index 072b57e2..fd3dbc2b 100644 --- a/nalgebra-glm/src/ext/quaternion_common.rs +++ b/nalgebra-glm/src/ext/quaternion_common.rs @@ -3,34 +3,34 @@ use na::{self, RealField, Unit}; use crate::aliases::Qua; /// The conjugate of `q`. -pub fn quat_conjugate(q: &Qua) -> Qua { +pub fn quat_conjugate(q: &Qua) -> Qua { q.conjugate() } /// The inverse of `q`. -pub fn quat_inverse(q: &Qua) -> Qua { +pub fn quat_inverse(q: &Qua) -> Qua { q.try_inverse().unwrap_or_else(na::zero) } -//pub fn quat_isinf(x: &Qua) -> TVec { +//pub fn quat_isinf(x: &Qua) -> TVec { // x.coords.map(|e| e.is_inf()) //} -//pub fn quat_isnan(x: &Qua) -> TVec { +//pub fn quat_isnan(x: &Qua) -> TVec { // x.coords.map(|e| e.is_nan()) //} /// Interpolate linearly between `x` and `y`. -pub fn quat_lerp(x: &Qua, y: &Qua, a: N) -> Qua { +pub fn quat_lerp(x: &Qua, y: &Qua, a: T) -> Qua { x.lerp(y, a) } -//pub fn quat_mix(x: &Qua, y: &Qua, a: N) -> Qua { -// x * (N::one() - a) + y * a +//pub fn quat_mix(x: &Qua, y: &Qua, a: T) -> Qua { +// x * (T::one() - a) + y * a //} /// Interpolate spherically between `x` and `y`. -pub fn quat_slerp(x: &Qua, y: &Qua, a: N) -> Qua { +pub fn quat_slerp(x: &Qua, y: &Qua, a: T) -> Qua { Unit::new_normalize(*x) .slerp(&Unit::new_normalize(*y), a) .into_inner() diff --git a/nalgebra-glm/src/ext/quaternion_geometric.rs b/nalgebra-glm/src/ext/quaternion_geometric.rs index 24d9310d..7930a8da 100644 --- a/nalgebra-glm/src/ext/quaternion_geometric.rs +++ b/nalgebra-glm/src/ext/quaternion_geometric.rs @@ -3,26 +3,26 @@ use na::RealField; use crate::aliases::Qua; /// Multiplies two quaternions. -pub fn quat_cross(q1: &Qua, q2: &Qua) -> Qua { +pub fn quat_cross(q1: &Qua, q2: &Qua) -> Qua { q1 * q2 } /// The scalar product of two quaternions. -pub fn quat_dot(x: &Qua, y: &Qua) -> N { +pub fn quat_dot(x: &Qua, y: &Qua) -> T { x.dot(y) } /// The magnitude of the quaternion `q`. -pub fn quat_length(q: &Qua) -> N { +pub fn quat_length(q: &Qua) -> T { q.norm() } /// The magnitude of the quaternion `q`. -pub fn quat_magnitude(q: &Qua) -> N { +pub fn quat_magnitude(q: &Qua) -> T { q.norm() } /// Normalizes the quaternion `q`. -pub fn quat_normalize(q: &Qua) -> Qua { +pub fn quat_normalize(q: &Qua) -> Qua { q.normalize() } diff --git a/nalgebra-glm/src/ext/quaternion_relational.rs b/nalgebra-glm/src/ext/quaternion_relational.rs index bd24edbe..282a3614 100644 --- a/nalgebra-glm/src/ext/quaternion_relational.rs +++ b/nalgebra-glm/src/ext/quaternion_relational.rs @@ -1,23 +1,23 @@ -use na::{RealField, U4}; +use na::RealField; use crate::aliases::{Qua, TVec}; /// Component-wise equality comparison between two quaternions. -pub fn quat_equal(x: &Qua, y: &Qua) -> TVec { +pub fn quat_equal(x: &Qua, y: &Qua) -> TVec { crate::equal(&x.coords, &y.coords) } /// Component-wise approximate equality comparison between two quaternions. -pub fn quat_equal_eps(x: &Qua, y: &Qua, epsilon: N) -> TVec { +pub fn quat_equal_eps(x: &Qua, y: &Qua, epsilon: T) -> TVec { crate::equal_eps(&x.coords, &y.coords, epsilon) } /// Component-wise non-equality comparison between two quaternions. -pub fn quat_not_equal(x: &Qua, y: &Qua) -> TVec { +pub fn quat_not_equal(x: &Qua, y: &Qua) -> TVec { crate::not_equal(&x.coords, &y.coords) } /// Component-wise approximate non-equality comparison between two quaternions. -pub fn quat_not_equal_eps(x: &Qua, y: &Qua, epsilon: N) -> TVec { +pub fn quat_not_equal_eps(x: &Qua, y: &Qua, epsilon: T) -> TVec { crate::not_equal_eps(&x.coords, &y.coords, epsilon) } diff --git a/nalgebra-glm/src/ext/quaternion_transform.rs b/nalgebra-glm/src/ext/quaternion_transform.rs index 1e4e9771..34689cb4 100644 --- a/nalgebra-glm/src/ext/quaternion_transform.rs +++ b/nalgebra-glm/src/ext/quaternion_transform.rs @@ -3,25 +3,25 @@ use na::{RealField, Unit, UnitQuaternion}; use crate::aliases::{Qua, TVec3}; /// Computes the quaternion exponential. -pub fn quat_exp(q: &Qua) -> Qua { +pub fn quat_exp(q: &Qua) -> Qua { q.exp() } /// Computes the quaternion logarithm. -pub fn quat_log(q: &Qua) -> Qua { +pub fn quat_log(q: &Qua) -> Qua { q.ln() } /// Raises the quaternion `q` to the power `y`. -pub fn quat_pow(q: &Qua, y: N) -> Qua { +pub fn quat_pow(q: &Qua, y: T) -> Qua { q.powf(y) } /// Builds a quaternion from an axis and an angle, and right-multiply it to the quaternion `q`. -pub fn quat_rotate(q: &Qua, angle: N, axis: &TVec3) -> Qua { +pub fn quat_rotate(q: &Qua, angle: T, axis: &TVec3) -> Qua { q * UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).into_inner() } -//pub fn quat_sqrt(q: &Qua) -> Qua { +//pub fn quat_sqrt(q: &Qua) -> Qua { // unimplemented!() //} diff --git a/nalgebra-glm/src/ext/quaternion_trigonometric.rs b/nalgebra-glm/src/ext/quaternion_trigonometric.rs index a711e69a..fdd21250 100644 --- a/nalgebra-glm/src/ext/quaternion_trigonometric.rs +++ b/nalgebra-glm/src/ext/quaternion_trigonometric.rs @@ -3,17 +3,17 @@ use na::{RealField, Unit, UnitQuaternion}; use crate::aliases::{Qua, TVec3}; /// The rotation angle of this quaternion assumed to be normalized. -pub fn quat_angle(x: &Qua) -> N { +pub fn quat_angle(x: &Qua) -> T { UnitQuaternion::from_quaternion(*x).angle() } /// Creates a quaternion from an axis and an angle. -pub fn quat_angle_axis(angle: N, axis: &TVec3) -> Qua { +pub fn quat_angle_axis(angle: T, axis: &TVec3) -> Qua { UnitQuaternion::from_axis_angle(&Unit::new_normalize(*axis), angle).into_inner() } /// The rotation axis of a quaternion assumed to be normalized. -pub fn quat_axis(x: &Qua) -> TVec3 { +pub fn quat_axis(x: &Qua) -> TVec3 { if let Some(a) = UnitQuaternion::from_quaternion(*x).axis() { a.into_inner() } else { diff --git a/nalgebra-glm/src/ext/scalar_common.rs b/nalgebra-glm/src/ext/scalar_common.rs index b3bd9c13..696b97e4 100644 --- a/nalgebra-glm/src/ext/scalar_common.rs +++ b/nalgebra-glm/src/ext/scalar_common.rs @@ -15,7 +15,7 @@ use crate::traits::Number; /// * [`max4_scalar`](fn.max4_scalar.html) /// * [`min3_scalar`](fn.min3_scalar.html) /// * [`min4_scalar`](fn.min4_scalar.html) -pub fn max2_scalar(a: N, b: N) -> N { +pub fn max2_scalar(a: T, b: T) -> T { if a >= b { a } else { @@ -38,7 +38,7 @@ pub fn max2_scalar(a: N, b: N) -> N { /// * [`max4_scalar`](fn.max4_scalar.html) /// * [`min3_scalar`](fn.min3_scalar.html) /// * [`min4_scalar`](fn.min4_scalar.html) -pub fn min2_scalar(a: N, b: N) -> N { +pub fn min2_scalar(a: T, b: T) -> T { if a <= b { a } else { @@ -61,7 +61,7 @@ pub fn min2_scalar(a: N, b: N) -> N { /// * [`max4_scalar`](fn.max4_scalar.html) /// * [`min3_scalar`](fn.min3_scalar.html) /// * [`min4_scalar`](fn.min4_scalar.html) -pub fn max3_scalar(a: N, b: N, c: N) -> N { +pub fn max3_scalar(a: T, b: T, c: T) -> T { max2_scalar(max2_scalar(a, b), c) } @@ -80,7 +80,7 @@ pub fn max3_scalar(a: N, b: N, c: N) -> N { /// * [`max3_scalar`](fn.max3_scalar.html) /// * [`min3_scalar`](fn.min3_scalar.html) /// * [`min4_scalar`](fn.min4_scalar.html) -pub fn max4_scalar(a: N, b: N, c: N, d: N) -> N { +pub fn max4_scalar(a: T, b: T, c: T, d: T) -> T { max2_scalar(max2_scalar(a, b), max2_scalar(c, d)) } @@ -99,7 +99,7 @@ pub fn max4_scalar(a: N, b: N, c: N, d: N) -> N { /// * [`max3_scalar`](fn.max3_scalar.html) /// * [`max4_scalar`](fn.max4_scalar.html) /// * [`min4_scalar`](fn.min4_scalar.html) -pub fn min3_scalar(a: N, b: N, c: N) -> N { +pub fn min3_scalar(a: T, b: T, c: T) -> T { min2_scalar(min2_scalar(a, b), c) } @@ -118,6 +118,6 @@ pub fn min3_scalar(a: N, b: N, c: N) -> N { /// * [`max3_scalar`](fn.max3_scalar.html) /// * [`max4_scalar`](fn.max4_scalar.html) /// * [`min3_scalar`](fn.min3_scalar.html) -pub fn min4_scalar(a: N, b: N, c: N, d: N) -> N { +pub fn min4_scalar(a: T, b: T, c: T, d: T) -> T { min2_scalar(min2_scalar(a, b), min2_scalar(c, d)) } diff --git a/nalgebra-glm/src/ext/scalar_constants.rs b/nalgebra-glm/src/ext/scalar_constants.rs index e0741465..89d6f969 100644 --- a/nalgebra-glm/src/ext/scalar_constants.rs +++ b/nalgebra-glm/src/ext/scalar_constants.rs @@ -2,8 +2,8 @@ use approx::AbsDiffEq; use na::RealField; /// Default epsilon value used for approximate comparison. -pub fn epsilon>() -> N { - N::default_epsilon() +pub fn epsilon>() -> T { + T::default_epsilon() } /// The value of PI. @@ -22,6 +22,6 @@ pub fn epsilon>() -> N { /// * [`two_over_pi`](fn.two_over_pi.html) /// * [`two_over_root_pi`](fn.two_over_root_pi.html) /// * [`two_pi`](fn.two_pi.html) -pub fn pi() -> N { - N::pi() +pub fn pi() -> T { + T::pi() } diff --git a/nalgebra-glm/src/ext/vector_common.rs b/nalgebra-glm/src/ext/vector_common.rs index ff892f1e..4e1f7446 100644 --- a/nalgebra-glm/src/ext/vector_common.rs +++ b/nalgebra-glm/src/ext/vector_common.rs @@ -1,7 +1,5 @@ -use na::{self, DefaultAllocator}; - use crate::aliases::TVec; -use crate::traits::{Alloc, Dimension, Number}; +use crate::traits::Number; /// Component-wise maximum between a vector and a scalar. /// @@ -16,10 +14,7 @@ use crate::traits::{Alloc, Dimension, Number}; /// * [`min2`](fn.min2.html) /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) -pub fn max(a: &TVec, b: N) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn max(a: &TVec, b: T) -> TVec { a.map(|a| crate::max2_scalar(a, b)) } @@ -36,10 +31,7 @@ where /// * [`min2`](fn.min2.html) /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) -pub fn max2(a: &TVec, b: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn max2(a: &TVec, b: &TVec) -> TVec { a.zip_map(b, |a, b| crate::max2_scalar(a, b)) } @@ -56,10 +48,11 @@ where /// * [`min2`](fn.min2.html) /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) -pub fn max3(a: &TVec, b: &TVec, c: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn max3( + a: &TVec, + b: &TVec, + c: &TVec, +) -> TVec { max2(&max2(a, b), c) } @@ -76,15 +69,12 @@ where /// * [`min2`](fn.min2.html) /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) -pub fn max4( - a: &TVec, - b: &TVec, - c: &TVec, - d: &TVec, -) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn max4( + a: &TVec, + b: &TVec, + c: &TVec, + d: &TVec, +) -> TVec { max2(&max2(a, b), &max2(c, d)) } @@ -101,10 +91,7 @@ where /// * [`min2`](fn.min2.html) /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) -pub fn min(x: &TVec, y: N) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn min(x: &TVec, y: T) -> TVec { x.map(|x| crate::min2_scalar(x, y)) } @@ -121,10 +108,7 @@ where /// * [`min`](fn.min.html) /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) -pub fn min2(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn min2(x: &TVec, y: &TVec) -> TVec { x.zip_map(y, |a, b| crate::min2_scalar(a, b)) } @@ -141,10 +125,11 @@ where /// * [`min`](fn.min.html) /// * [`min2`](fn.min2.html) /// * [`min4`](fn.min4.html) -pub fn min3(a: &TVec, b: &TVec, c: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn min3( + a: &TVec, + b: &TVec, + c: &TVec, +) -> TVec { min2(&min2(a, b), c) } @@ -161,14 +146,11 @@ where /// * [`min`](fn.min.html) /// * [`min2`](fn.min2.html) /// * [`min3`](fn.min3.html) -pub fn min4( - a: &TVec, - b: &TVec, - c: &TVec, - d: &TVec, -) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn min4( + a: &TVec, + b: &TVec, + c: &TVec, + d: &TVec, +) -> TVec { 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 a5071336..baefe1bd 100644 --- a/nalgebra-glm/src/ext/vector_relational.rs +++ b/nalgebra-glm/src/ext/vector_relational.rs @@ -1,7 +1,5 @@ -use na::DefaultAllocator; - use crate::aliases::TVec; -use crate::traits::{Alloc, Dimension, Number}; +use crate::traits::Number; /// Component-wise approximate equality of two vectors, using a scalar epsilon. /// @@ -10,14 +8,11 @@ use crate::traits::{Alloc, Dimension, Number}; /// * [`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: T, +) -> TVec { x.zip_map(y, |x, y| abs_diff_eq!(x, y, epsilon = epsilon)) } @@ -28,14 +23,11 @@ where /// * [`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 { x.zip_zip_map(y, epsilon, |x, y, eps| abs_diff_eq!(x, y, epsilon = eps)) } @@ -46,14 +38,11 @@ where /// * [`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: T, +) -> TVec { x.zip_map(y, |x, y| abs_diff_ne!(x, y, epsilon = epsilon)) } @@ -64,13 +53,10 @@ where /// * [`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 { 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 a4b0b988..3942756d 100644 --- a/nalgebra-glm/src/geometric.rs +++ b/nalgebra-glm/src/geometric.rs @@ -1,10 +1,10 @@ -use na::{DefaultAllocator, RealField}; +use na::RealField; use crate::aliases::{TVec, TVec3}; -use crate::traits::{Alloc, Dimension, Number}; +use crate::traits::Number; /// The cross product of two vectors. -pub fn cross(x: &TVec3, y: &TVec3) -> TVec3 { +pub fn cross(x: &TVec3, y: &TVec3) -> TVec3 { x.cross(y) } @@ -13,31 +13,22 @@ pub fn cross(x: &TVec3, y: &TVec3) -> TVec3 { /// # See also: /// /// * [`distance2`](fn.distance2.html) -pub fn distance(p0: &TVec, p1: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn distance(p0: &TVec, p1: &TVec) -> T { (p1 - p0).norm() } /// The dot product of two vectors. -pub fn dot(x: &TVec, y: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn dot(x: &TVec, y: &TVec) -> T { 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, -{ - if nref.dot(i) < N::zero() { +pub fn faceforward( + n: &TVec, + i: &TVec, + nref: &TVec, +) -> TVec { + if nref.dot(i) < T::zero() { n.clone() } else { -n.clone() @@ -53,10 +44,7 @@ where /// * [`length2`](fn.length2.html) /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) -pub fn length(x: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn length(x: &TVec) -> T { x.norm() } @@ -69,39 +57,31 @@ where /// * [`length`](fn.length.html) /// * [`magnitude2`](fn.magnitude2.html) /// * [`nalgebra::norm`](../nalgebra/fn.norm.html) -pub fn magnitude(x: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn magnitude(x: &TVec) -> T { x.norm() } /// Normalizes a vector. -pub fn normalize(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn normalize(x: &TVec) -> TVec { 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, -{ - let _2 = N::one() + N::one(); +pub fn reflect_vec(i: &TVec, n: &TVec) -> TVec { + let _2 = T::one() + T::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, -{ +pub fn refract_vec( + i: &TVec, + n: &TVec, + eta: T, +) -> TVec { let ni = n.dot(i); - let k = N::one() - eta * eta * (N::one() - ni * ni); + let k = T::one() - eta * eta * (T::one() - ni * ni); - if k < N::zero() { + if k < T::zero() { TVec::<_, D>::zeros() } else { i * eta - n * (eta * dot(n, i) + k.sqrt()) diff --git a/nalgebra-glm/src/gtc/bitfield.rs b/nalgebra-glm/src/gtc/bitfield.rs index bdf18552..b37f0591 100644 --- a/nalgebra-glm/src/gtc/bitfield.rs +++ b/nalgebra-glm/src/gtc/bitfield.rs @@ -1,6 +1,5 @@ -use na::{Scalar, DefaultAllocator}; +use na::{DefaultAllocator, Scalar}; -use crate::traits::{Alloc, Dimension}; use crate::aliases::*; pub fn bitfieldDeinterleave(x: u16) -> U8Vec2 { @@ -19,8 +18,11 @@ pub fn bitfieldFillOne(Value: IU, FirstBit: i32, BitCount: i32) -> IU { unimplemented!() } -pub fn bitfieldFillOne2(Value: &TVec, FirstBit: i32, BitCount: i32) -> TVec - where DefaultAllocator: Alloc { +pub fn bitfieldFillOne2( + Value: &TVec, + FirstBit: i32, + BitCount: i32, +) -> TVec { unimplemented!() } @@ -28,8 +30,11 @@ pub fn bitfieldFillZero(Value: IU, FirstBit: i32, BitCount: i32) -> IU { unimplemented!() } -pub fn bitfieldFillZero2(Value: &TVec, FirstBit: i32, BitCount: i32) -> TVec - where DefaultAllocator: Alloc { +pub fn bitfieldFillZero2( + Value: &TVec, + FirstBit: i32, + BitCount: i32, +) -> TVec { unimplemented!() } @@ -113,8 +118,7 @@ pub fn bitfieldRotateLeft(In: IU, Shift: i32) -> IU { unimplemented!() } -pub fn bitfieldRotateLeft2(In: &TVec, Shift: i32) -> TVec - where DefaultAllocator: Alloc { +pub fn bitfieldRotateLeft2(In: &TVec, Shift: i32) -> TVec { unimplemented!() } @@ -122,8 +126,7 @@ pub fn bitfieldRotateRight(In: IU, Shift: i32) -> IU { unimplemented!() } -pub fn bitfieldRotateRight2(In: &TVec, Shift: i32) -> TVec - where DefaultAllocator: Alloc { +pub fn bitfieldRotateRight2(In: &TVec, Shift: i32) -> TVec { unimplemented!() } @@ -131,7 +134,6 @@ pub fn mask(Bits: IU) -> IU { unimplemented!() } -pub fn mask2(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn mask2(v: &TVec) -> TVec { unimplemented!() } diff --git a/nalgebra-glm/src/gtc/constants.rs b/nalgebra-glm/src/gtc/constants.rs index 81375ee3..545d6b17 100644 --- a/nalgebra-glm/src/gtc/constants.rs +++ b/nalgebra-glm/src/gtc/constants.rs @@ -3,13 +3,13 @@ use na::{self, RealField}; /// The Euler constant. /// /// This is a shorthand alias for [`euler`](fn.euler.html). -pub fn e() -> N { - N::e() +pub fn e() -> T { + T::e() } /// The Euler constant. -pub fn euler() -> N { - N::e() +pub fn euler() -> T { + T::e() } /// Returns `4 / pi`. @@ -28,13 +28,13 @@ pub fn euler() -> N { /// * [`two_over_pi`](fn.two_over_pi.html) /// * [`two_over_root_pi`](fn.two_over_root_pi.html) /// * [`two_pi`](fn.two_pi.html) -pub fn four_over_pi() -> N { - na::convert::<_, N>(4.0) / N::pi() +pub fn four_over_pi() -> T { + na::convert::<_, T>(4.0) / T::pi() } /// Returns the golden ratio. -pub fn golden_ratio() -> N { - (N::one() + root_five()) / na::convert(2.0) +pub fn golden_ratio() -> T { + (T::one() + root_five()) / na::convert(2.0) } /// Returns `pi / 2`. @@ -53,8 +53,8 @@ pub fn golden_ratio() -> N { /// * [`two_over_pi`](fn.two_over_pi.html) /// * [`two_over_root_pi`](fn.two_over_root_pi.html) /// * [`two_pi`](fn.two_pi.html) -pub fn half_pi() -> N { - N::frac_pi_2() +pub fn half_pi() -> T { + T::frac_pi_2() } /// Returns `ln(ln(2))`. @@ -63,8 +63,8 @@ pub fn half_pi() -> N { /// /// * [`ln_ten`](fn.ln_ten.html) /// * [`ln_two`](fn.ln_two.html) -pub fn ln_ln_two() -> N { - N::ln_2().ln() +pub fn ln_ln_two() -> T { + T::ln_2().ln() } /// Returns `ln(10)`. @@ -73,8 +73,8 @@ pub fn ln_ln_two() -> N { /// /// * [`ln_ln_two`](fn.ln_ln_two.html) /// * [`ln_two`](fn.ln_two.html) -pub fn ln_ten() -> N { - N::ln_10() +pub fn ln_ten() -> T { + T::ln_10() } /// Returns `ln(2)`. @@ -83,8 +83,8 @@ pub fn ln_ten() -> N { /// /// * [`ln_ln_two`](fn.ln_ln_two.html) /// * [`ln_ten`](fn.ln_ten.html) -pub fn ln_two() -> N { - N::ln_2() +pub fn ln_two() -> T { + T::ln_2() } /// Returns `1`. @@ -106,13 +106,13 @@ pub use na::one; /// * [`two_over_pi`](fn.two_over_pi.html) /// * [`two_over_root_pi`](fn.two_over_root_pi.html) /// * [`two_pi`](fn.two_pi.html) -pub fn one_over_pi() -> N { - N::frac_1_pi() +pub fn one_over_pi() -> T { + T::frac_1_pi() } /// Returns `1 / sqrt(2)`. -pub fn one_over_root_two() -> N { - N::one() / root_two() +pub fn one_over_root_two() -> T { + T::one() / root_two() } /// Returns `1 / (2pi)`. @@ -131,8 +131,8 @@ pub fn one_over_root_two() -> N { /// * [`two_over_pi`](fn.two_over_pi.html) /// * [`two_over_root_pi`](fn.two_over_root_pi.html) /// * [`two_pi`](fn.two_pi.html) -pub fn one_over_two_pi() -> N { - N::frac_1_pi() * na::convert(0.5) +pub fn one_over_two_pi() -> T { + T::frac_1_pi() * na::convert(0.5) } /// Returns `pi / 4`. @@ -151,8 +151,8 @@ pub fn one_over_two_pi() -> N { /// * [`two_over_pi`](fn.two_over_pi.html) /// * [`two_over_root_pi`](fn.two_over_root_pi.html) /// * [`two_pi`](fn.two_pi.html) -pub fn quarter_pi() -> N { - N::frac_pi_4() +pub fn quarter_pi() -> T { + T::frac_pi_4() } /// Returns `sqrt(5)`. @@ -161,8 +161,8 @@ pub fn quarter_pi() -> N { /// /// * [`root_three`](fn.root_three.html) /// * [`root_two`](fn.root_two.html) -pub fn root_five() -> N { - na::convert::<_, N>(5.0).sqrt() +pub fn root_five() -> T { + na::convert::<_, T>(5.0).sqrt() } /// Returns `sqrt(pi / 2)`. @@ -181,13 +181,13 @@ pub fn root_five() -> N { /// * [`two_over_pi`](fn.two_over_pi.html) /// * [`two_over_root_pi`](fn.two_over_root_pi.html) /// * [`two_pi`](fn.two_pi.html) -pub fn root_half_pi() -> N { - (N::pi() / na::convert(2.0)).sqrt() +pub fn root_half_pi() -> T { + (T::pi() / na::convert(2.0)).sqrt() } /// Returns `sqrt(ln(4))`. -pub fn root_ln_four() -> N { - na::convert::<_, N>(4.0).ln().sqrt() +pub fn root_ln_four() -> T { + na::convert::<_, T>(4.0).ln().sqrt() } /// Returns the square root of pi. @@ -206,8 +206,8 @@ pub fn root_ln_four() -> N { /// * [`two_over_pi`](fn.two_over_pi.html) /// * [`two_over_root_pi`](fn.two_over_root_pi.html) /// * [`two_pi`](fn.two_pi.html) -pub fn root_pi() -> N { - N::pi().sqrt() +pub fn root_pi() -> T { + T::pi().sqrt() } /// Returns the square root of 3. @@ -216,8 +216,8 @@ pub fn root_pi() -> N { /// /// * [`root_five`](fn.root_five.html) /// * [`root_two`](fn.root_two.html) -pub fn root_three() -> N { - na::convert::<_, N>(3.0).sqrt() +pub fn root_three() -> T { + na::convert::<_, T>(3.0).sqrt() } /// Returns the square root of 2. @@ -226,9 +226,9 @@ pub fn root_three() -> N { /// /// * [`root_five`](fn.root_five.html) /// * [`root_three`](fn.root_three.html) -pub fn root_two() -> N { +pub fn root_two() -> T { // TODO: there should be a crate::sqrt_2() on the RealField trait. - na::convert::<_, N>(2.0).sqrt() + na::convert::<_, T>(2.0).sqrt() } /// Returns the square root of 2pi. @@ -247,8 +247,8 @@ pub fn root_two() -> N { /// * [`two_over_pi`](fn.two_over_pi.html) /// * [`two_over_root_pi`](fn.two_over_root_pi.html) /// * [`two_pi`](fn.two_pi.html) -pub fn root_two_pi() -> N { - N::two_pi().sqrt() +pub fn root_two_pi() -> T { + T::two_pi().sqrt() } /// Returns `1 / 3`. @@ -256,7 +256,7 @@ pub fn root_two_pi() -> N { /// # See also: /// /// * [`two_thirds`](fn.two_thirds.html) -pub fn third() -> N { +pub fn third() -> T { na::convert(1.0 / 3.0) } @@ -276,8 +276,8 @@ pub fn third() -> N { /// * [`two_over_pi`](fn.two_over_pi.html) /// * [`two_over_root_pi`](fn.two_over_root_pi.html) /// * [`two_pi`](fn.two_pi.html) -pub fn three_over_two_pi() -> N { - na::convert::<_, N>(3.0) / N::two_pi() +pub fn three_over_two_pi() -> T { + na::convert::<_, T>(3.0) / T::two_pi() } /// Returns `2 / pi`. @@ -295,8 +295,8 @@ pub fn three_over_two_pi() -> N { /// * [`three_over_two_pi`](fn.three_over_two_pi.html) /// * [`two_over_root_pi`](fn.two_over_root_pi.html) /// * [`two_pi`](fn.two_pi.html) -pub fn two_over_pi() -> N { - N::frac_2_pi() +pub fn two_over_pi() -> T { + T::frac_2_pi() } /// Returns `2 / sqrt(pi)`. @@ -315,8 +315,8 @@ pub fn two_over_pi() -> N { /// * [`three_over_two_pi`](fn.three_over_two_pi.html) /// * [`two_over_pi`](fn.two_over_pi.html) /// * [`two_pi`](fn.two_pi.html) -pub fn two_over_root_pi() -> N { - N::frac_2_sqrt_pi() +pub fn two_over_root_pi() -> T { + T::frac_2_sqrt_pi() } /// Returns `2pi`. @@ -335,8 +335,8 @@ pub fn two_over_root_pi() -> N { /// * [`three_over_two_pi`](fn.three_over_two_pi.html) /// * [`two_over_pi`](fn.two_over_pi.html) /// * [`two_over_root_pi`](fn.two_over_root_pi.html) -pub fn two_pi() -> N { - N::two_pi() +pub fn two_pi() -> T { + T::two_pi() } /// Returns `2 / 3`. @@ -344,7 +344,7 @@ pub fn two_pi() -> N { /// # See also: /// /// * [`third`](fn.third.html) -pub fn two_thirds() -> N { +pub fn two_thirds() -> T { na::convert(2.0 / 3.0) } diff --git a/nalgebra-glm/src/gtc/epsilon.rs b/nalgebra-glm/src/gtc/epsilon.rs index 81ac2e6c..fae29981 100644 --- a/nalgebra-glm/src/gtc/epsilon.rs +++ b/nalgebra-glm/src/gtc/epsilon.rs @@ -8,24 +8,24 @@ use crate::traits::{Alloc, Number, Dimension}; use crate::aliases::TVec; /// Component-wise approximate equality beween two vectors. -pub fn epsilon_equal(x: &TVec, y: &TVec, epsilon: N) -> TVec - where DefaultAllocator: Alloc { +pub fn epsilon_equal(x: &TVec, y: &TVec, epsilon: T) -> TVec + where DefaultAllocator: Alloc { x.zip_map(y, |x, y| abs_diff_eq!(x, y, epsilon = epsilon)) } /// Component-wise approximate equality beween two scalars. -pub fn epsilon_equal2>(x: N, y: N, epsilon: N) -> bool { +pub fn epsilon_equal2>(x: T, y: T, epsilon: T) -> bool { abs_diff_eq!(x, y, epsilon = epsilon) } /// Component-wise approximate non-equality beween two vectors. -pub fn epsilon_not_equal(x: &TVec, y: &TVec, epsilon: N) -> TVec - where DefaultAllocator: Alloc { +pub fn epsilon_not_equal(x: &TVec, y: &TVec, epsilon: T) -> TVec + where DefaultAllocator: Alloc { x.zip_map(y, |x, y| abs_diff_ne!(x, y, epsilon = epsilon)) } /// Component-wise approximate non-equality beween two scalars. -pub fn epsilon_not_equal2>(x: N, y: N, epsilon: N) -> bool { +pub fn epsilon_not_equal2>(x: T, y: T, epsilon: T) -> bool { abs_diff_ne!(x, y, epsilon = epsilon) } */ diff --git a/nalgebra-glm/src/gtc/integer.rs b/nalgebra-glm/src/gtc/integer.rs index a972a4ab..cf1225ea 100644 --- a/nalgebra-glm/src/gtc/integer.rs +++ b/nalgebra-glm/src/gtc/integer.rs @@ -1,10 +1,9 @@ -//use na::{Scalar, DefaultAllocator}; +//use na::Scalar; +// // -//use crate::traits::{Alloc, Dimension}; //use crate::aliases::TVec; -//pub fn iround(x: &TVec) -> TVec -// where DefaultAllocator: Alloc { +//pub fn iround(x: &TVec) -> TVec { // x.map(|x| x.round()) //} // @@ -12,7 +11,6 @@ // unimplemented!() //} // -//pub fn uround(x: &TVec) -> TVec -// where DefaultAllocator: Alloc { +//pub fn uround(x: &TVec) -> TVec { // unimplemented!() //} diff --git a/nalgebra-glm/src/gtc/matrix_access.rs b/nalgebra-glm/src/gtc/matrix_access.rs index 2713b8be..798c3b14 100644 --- a/nalgebra-glm/src/gtc/matrix_access.rs +++ b/nalgebra-glm/src/gtc/matrix_access.rs @@ -1,7 +1,6 @@ -use na::{DefaultAllocator, Scalar}; +use na::Scalar; use crate::aliases::{TMat, TVec}; -use crate::traits::{Alloc, Dimension}; /// The `index`-th column of the matrix `m`. /// @@ -10,10 +9,10 @@ use crate::traits::{Alloc, Dimension}; /// * [`row`](fn.row.html) /// * [`set_column`](fn.set_column.html) /// * [`set_row`](fn.set_row.html) -pub fn column(m: &TMat, index: usize) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn column( + m: &TMat, + index: usize, +) -> TVec { m.column(index).into_owned() } @@ -24,14 +23,11 @@ where /// * [`column`](fn.column.html) /// * [`row`](fn.row.html) /// * [`set_row`](fn.set_row.html) -pub fn set_column( - m: &TMat, +pub fn set_column( + m: &TMat, index: usize, - x: &TVec, -) -> TMat -where - DefaultAllocator: Alloc, -{ + x: &TVec, +) -> TMat { let mut res = m.clone(); res.set_column(index, x); res @@ -44,10 +40,10 @@ where /// * [`column`](fn.column.html) /// * [`set_column`](fn.set_column.html) /// * [`set_row`](fn.set_row.html) -pub fn row(m: &TMat, index: usize) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn row( + m: &TMat, + index: usize, +) -> TVec { m.row(index).into_owned().transpose() } @@ -58,14 +54,11 @@ where /// * [`column`](fn.column.html) /// * [`row`](fn.row.html) /// * [`set_column`](fn.set_column.html) -pub fn set_row( - m: &TMat, +pub fn set_row( + m: &TMat, index: usize, - x: &TVec, -) -> TMat -where - DefaultAllocator: Alloc, -{ + x: &TVec, +) -> TMat { 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 c71a11f9..c0df4486 100644 --- a/nalgebra-glm/src/gtc/matrix_inverse.rs +++ b/nalgebra-glm/src/gtc/matrix_inverse.rs @@ -1,22 +1,15 @@ -use na::{DefaultAllocator, RealField}; +use na::RealField; use crate::aliases::TMat; -use crate::traits::{Alloc, Dimension}; /// Fast matrix inverse for affine matrix. -pub fn affine_inverse(m: TMat) -> TMat -where - DefaultAllocator: Alloc, -{ +pub fn affine_inverse(m: TMat) -> TMat { // TODO: 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, -{ +pub fn inverse_transpose(m: TMat) -> TMat { m.try_inverse() .unwrap_or_else(TMat::<_, D, D>::zeros) .transpose() diff --git a/nalgebra-glm/src/gtc/packing.rs b/nalgebra-glm/src/gtc/packing.rs index ea5acac4..9635bdf9 100644 --- a/nalgebra-glm/src/gtc/packing.rs +++ b/nalgebra-glm/src/gtc/packing.rs @@ -1,9 +1,7 @@ -use na::{Scalar, RealField, DefaultAllocator, U3, U4}; +use na::{DefaultAllocator, RealField, Scalar, U3, U4}; -use crate::traits::{Alloc, Dimension}; use crate::aliases::*; - pub fn packF2x11_1x10(v: &Vec3) -> i32 { unimplemented!() } @@ -12,8 +10,10 @@ pub fn packF3x9_E1x5(v: &Vec3) -> i32 { unimplemented!() } -pub fn packHalf(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn packHalf(v: &TVec) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } @@ -49,12 +49,14 @@ pub fn packInt4x8(v: &I8Vec4) -> i32 { unimplemented!() } -pub fn packRGBM(rgb: &TVec3) -> TVec4 { +pub fn packRGBM(rgb: &TVec3) -> TVec4 { unimplemented!() } -pub fn packSnorm(v: TVec) -> TVec - where DefaultAllocator: Alloc + Alloc { +pub fn packSnorm(v: TVec) -> TVec +where + DefaultAllocator: Alloc + Alloc, +{ unimplemented!() } @@ -102,8 +104,10 @@ pub fn packUint4x8(v: &U8Vec4) -> i32 { unimplemented!() } -pub fn packUnorm(v: &TVec) -> TVec - where DefaultAllocator: Alloc + Alloc { +pub fn packUnorm(v: &TVec) -> TVec +where + DefaultAllocator: Alloc + Alloc, +{ unimplemented!() } @@ -155,8 +159,7 @@ pub fn unpackF3x9_E1x5(p: i32) -> Vec3 { unimplemented!() } -pub fn unpackHalf(p: TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn unpackHalf(p: TVec) -> TVec { unimplemented!() } @@ -192,12 +195,14 @@ pub fn unpackInt4x8(p: i32) -> I8Vec4 { unimplemented!() } -pub fn unpackRGBM(rgbm: &TVec4) -> TVec3 { +pub fn unpackRGBM(rgbm: &TVec4) -> TVec3 { unimplemented!() } -pub fn unpackSnorm(v: &TVec) -> TVec - where DefaultAllocator: Alloc + Alloc { +pub fn unpackSnorm(v: &TVec) -> TVec +where + DefaultAllocator: Alloc + Alloc, +{ unimplemented!() } @@ -245,8 +250,10 @@ pub fn unpackUint4x8(p: i32) -> U8Vec4 { unimplemented!() } -pub fn unpackUnorm(v: &TVec) -> TVec - where DefaultAllocator: Alloc + Alloc { +pub fn unpackUnorm(v: &TVec) -> TVec +where + DefaultAllocator: Alloc + Alloc, +{ unimplemented!() } diff --git a/nalgebra-glm/src/gtc/quaternion.rs b/nalgebra-glm/src/gtc/quaternion.rs index 63a42511..6d483fe5 100644 --- a/nalgebra-glm/src/gtc/quaternion.rs +++ b/nalgebra-glm/src/gtc/quaternion.rs @@ -1,36 +1,36 @@ -use na::{RealField, UnitQuaternion, U4}; +use na::{RealField, UnitQuaternion}; use crate::aliases::{Qua, TMat4, TVec, TVec3}; /// Euler angles of the quaternion `q` as (pitch, yaw, roll). -pub fn quat_euler_angles(x: &Qua) -> TVec3 { +pub fn quat_euler_angles(x: &Qua) -> TVec3 { let q = UnitQuaternion::new_unchecked(*x); let a = q.euler_angles(); TVec3::new(a.2, a.1, a.0) } /// Component-wise `>` comparison between two quaternions. -pub fn quat_greater_than(x: &Qua, y: &Qua) -> TVec { +pub fn quat_greater_than(x: &Qua, y: &Qua) -> TVec { crate::greater_than(&x.coords, &y.coords) } /// Component-wise `>=` comparison between two quaternions. -pub fn quat_greater_than_equal(x: &Qua, y: &Qua) -> TVec { +pub fn quat_greater_than_equal(x: &Qua, y: &Qua) -> TVec { crate::greater_than_equal(&x.coords, &y.coords) } /// Component-wise `<` comparison between two quaternions. -pub fn quat_less_than(x: &Qua, y: &Qua) -> TVec { +pub fn quat_less_than(x: &Qua, y: &Qua) -> TVec { crate::less_than(&x.coords, &y.coords) } /// Component-wise `<=` comparison between two quaternions. -pub fn quat_less_than_equal(x: &Qua, y: &Qua) -> TVec { +pub fn quat_less_than_equal(x: &Qua, y: &Qua) -> TVec { crate::less_than_equal(&x.coords, &y.coords) } /// Convert a quaternion to a rotation matrix in homogeneous coordinates. -pub fn quat_cast(x: &Qua) -> TMat4 { +pub fn quat_cast(x: &Qua) -> TMat4 { crate::quat_to_mat4(x) } @@ -41,34 +41,34 @@ pub fn quat_cast(x: &Qua) -> TMat4 { /// * `direction` - Direction vector point at where to look /// * `up` - Object up vector /// -pub fn quat_look_at(direction: &TVec3, up: &TVec3) -> Qua { +pub fn quat_look_at(direction: &TVec3, up: &TVec3) -> Qua { quat_look_at_rh(direction, up) } /// Computes a left-handed look-at quaternion (equivalent to a left-handed look-at matrix). -pub fn quat_look_at_lh(direction: &TVec3, up: &TVec3) -> Qua { +pub fn quat_look_at_lh(direction: &TVec3, up: &TVec3) -> Qua { UnitQuaternion::look_at_lh(direction, up).into_inner() } /// Computes a right-handed look-at quaternion (equivalent to a right-handed look-at matrix). -pub fn quat_look_at_rh(direction: &TVec3, up: &TVec3) -> Qua { +pub fn quat_look_at_rh(direction: &TVec3, up: &TVec3) -> Qua { UnitQuaternion::look_at_rh(direction, up).into_inner() } /// The "roll" Euler angle of the quaternion `x` assumed to be normalized. -pub fn quat_roll(x: &Qua) -> N { +pub fn quat_roll(x: &Qua) -> T { // TODO: optimize this. quat_euler_angles(x).z } /// The "yaw" Euler angle of the quaternion `x` assumed to be normalized. -pub fn quat_yaw(x: &Qua) -> N { +pub fn quat_yaw(x: &Qua) -> T { // TODO: optimize this. quat_euler_angles(x).y } /// The "pitch" Euler angle of the quaternion `x` assumed to be normalized. -pub fn quat_pitch(x: &Qua) -> N { +pub fn quat_pitch(x: &Qua) -> T { // TODO: optimize this. quat_euler_angles(x).x } diff --git a/nalgebra-glm/src/gtc/round.rs b/nalgebra-glm/src/gtc/round.rs index 5ad95780..5cf75936 100644 --- a/nalgebra-glm/src/gtc/round.rs +++ b/nalgebra-glm/src/gtc/round.rs @@ -1,15 +1,16 @@ -use na::{Scalar, RealField, U3, DefaultAllocator}; +use na::{DefaultAllocator, RealField, Scalar, U3}; -use crate::traits::{Number, Alloc, Dimension}; use crate::aliases::TVec; - +use crate::traits::{Alloc, Dimension, Number}; pub fn ceilMultiple(v: T, Multiple: T) -> T { unimplemented!() } -pub fn ceilMultiple2(v: &TVec, Multiple: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn ceilMultiple2(v: &TVec, Multiple: &TVec) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } @@ -17,8 +18,10 @@ pub fn ceilPowerOfTwo(v: IU) -> IU { unimplemented!() } -pub fn ceilPowerOfTwo2(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn ceilPowerOfTwo2(v: &TVec) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } @@ -26,8 +29,13 @@ pub fn floorMultiple(v: T, Multiple: T) -> T { unimplemented!() } -pub fn floorMultiple2(v: &TVec, Multiple: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn floorMultiple2( + v: &TVec, + Multiple: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } @@ -35,8 +43,10 @@ pub fn floorPowerOfTwo(v: IU) -> IU { unimplemented!() } -pub fn floorPowerOfTwo2(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn floorPowerOfTwo2(v: &TVec) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } @@ -44,13 +54,20 @@ pub fn isMultiple(v: IU, Multiple: IU) -> bool { unimplemented!() } -pub fn isMultiple2(v: &TVec,Multiple: N) -> TVec - where DefaultAllocator: Alloc { +pub fn isMultiple2(v: &TVec, Multiple: T) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } -pub fn isMultiple3(v: &TVec, Multiple: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn isMultiple3( + v: &TVec, + Multiple: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } @@ -58,8 +75,10 @@ pub fn isPowerOfTwo2(v: IU) -> bool { unimplemented!() } -pub fn isPowerOfTwo(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn isPowerOfTwo(v: &TVec) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } @@ -67,8 +86,13 @@ pub fn roundMultiple(v: T, Multiple: T) -> T { unimplemented!() } -pub fn roundMultiple2(v: &TVec, Multiple: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn roundMultiple2( + v: &TVec, + Multiple: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } @@ -76,7 +100,9 @@ pub fn roundPowerOfTwo(v: IU) -> IU { unimplemented!() } -pub fn roundPowerOfTwo2(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn roundPowerOfTwo2(v: &TVec) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } diff --git a/nalgebra-glm/src/gtc/type_ptr.rs b/nalgebra-glm/src/gtc/type_ptr.rs index f8c6698b..bdd72585 100644 --- a/nalgebra-glm/src/gtc/type_ptr.rs +++ b/nalgebra-glm/src/gtc/type_ptr.rs @@ -1,81 +1,81 @@ -use na::{DefaultAllocator, Quaternion, RealField, Scalar}; +use na::{Quaternion, RealField, Scalar}; use crate::aliases::{ Qua, TMat, TMat2, TMat2x3, TMat2x4, TMat3, TMat3x2, TMat3x4, TMat4, TMat4x2, TMat4x3, TVec1, TVec2, TVec3, TVec4, }; -use crate::traits::{Alloc, Dimension, Number}; +use crate::traits::Number; /// Creates a 2x2 matrix from a slice arranged in column-major order. -pub fn make_mat2(ptr: &[N]) -> TMat2 { +pub fn make_mat2(ptr: &[T]) -> TMat2 { TMat2::from_column_slice(ptr) } /// Creates a 2x2 matrix from a slice arranged in column-major order. -pub fn make_mat2x2(ptr: &[N]) -> TMat2 { +pub fn make_mat2x2(ptr: &[T]) -> TMat2 { TMat2::from_column_slice(ptr) } /// Creates a 2x3 matrix from a slice arranged in column-major order. -pub fn make_mat2x3(ptr: &[N]) -> TMat2x3 { +pub fn make_mat2x3(ptr: &[T]) -> TMat2x3 { TMat2x3::from_column_slice(ptr) } /// Creates a 2x4 matrix from a slice arranged in column-major order. -pub fn make_mat2x4(ptr: &[N]) -> TMat2x4 { +pub fn make_mat2x4(ptr: &[T]) -> TMat2x4 { TMat2x4::from_column_slice(ptr) } /// Creates a 3 matrix from a slice arranged in column-major order. -pub fn make_mat3(ptr: &[N]) -> TMat3 { +pub fn make_mat3(ptr: &[T]) -> TMat3 { TMat3::from_column_slice(ptr) } /// Creates a 3x2 matrix from a slice arranged in column-major order. -pub fn make_mat3x2(ptr: &[N]) -> TMat3x2 { +pub fn make_mat3x2(ptr: &[T]) -> TMat3x2 { TMat3x2::from_column_slice(ptr) } /// Creates a 3x3 matrix from a slice arranged in column-major order. -pub fn make_mat3x3(ptr: &[N]) -> TMat3 { +pub fn make_mat3x3(ptr: &[T]) -> TMat3 { TMat3::from_column_slice(ptr) } /// Creates a 3x4 matrix from a slice arranged in column-major order. -pub fn make_mat3x4(ptr: &[N]) -> TMat3x4 { +pub fn make_mat3x4(ptr: &[T]) -> TMat3x4 { TMat3x4::from_column_slice(ptr) } /// Creates a 4x4 matrix from a slice arranged in column-major order. -pub fn make_mat4(ptr: &[N]) -> TMat4 { +pub fn make_mat4(ptr: &[T]) -> TMat4 { TMat4::from_column_slice(ptr) } /// Creates a 4x2 matrix from a slice arranged in column-major order. -pub fn make_mat4x2(ptr: &[N]) -> TMat4x2 { +pub fn make_mat4x2(ptr: &[T]) -> TMat4x2 { TMat4x2::from_column_slice(ptr) } /// Creates a 4x3 matrix from a slice arranged in column-major order. -pub fn make_mat4x3(ptr: &[N]) -> TMat4x3 { +pub fn make_mat4x3(ptr: &[T]) -> TMat4x3 { TMat4x3::from_column_slice(ptr) } /// Creates a 4x4 matrix from a slice arranged in column-major order. -pub fn make_mat4x4(ptr: &[N]) -> TMat4 { +pub fn make_mat4x4(ptr: &[T]) -> TMat4 { TMat4::from_column_slice(ptr) } /// Converts a 2x2 matrix to a 3x3 matrix. -pub fn mat2_to_mat3(m: &TMat2) -> TMat3 { - let _0 = N::zero(); - let _1 = N::one(); +pub fn mat2_to_mat3(m: &TMat2) -> TMat3 { + let _0 = T::zero(); + let _1 = T::one(); 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 { +pub fn mat3_to_mat2(m: &TMat3) -> TMat2 { TMat2::new( m.m11.inlined_clone(), m.m12.inlined_clone(), @@ -85,9 +85,9 @@ pub fn mat3_to_mat2(m: &TMat3) -> TMat2 { } /// Converts a 3x3 matrix to a 4x4 matrix. -pub fn mat3_to_mat4(m: &TMat3) -> TMat4 { - let _0 = N::zero(); - let _1 = N::one(); +pub fn mat3_to_mat4(m: &TMat3) -> TMat4 { + let _0 = T::zero(); + let _1 = T::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, @@ -95,7 +95,7 @@ pub fn mat3_to_mat4(m: &TMat3) -> TMat4 { } /// Converts a 4x4 matrix to a 3x3 matrix. -pub fn mat4_to_mat3(m: &TMat4) -> TMat3 { +pub fn mat4_to_mat3(m: &TMat4) -> TMat3 { TMat3::new( m.m11.inlined_clone(), m.m12.inlined_clone(), @@ -110,9 +110,9 @@ pub fn mat4_to_mat3(m: &TMat4) -> TMat3 { } /// Converts a 2x2 matrix to a 4x4 matrix. -pub fn mat2_to_mat4(m: &TMat2) -> TMat4 { - let _0 = N::zero(); - let _1 = N::one(); +pub fn mat2_to_mat4(m: &TMat2) -> TMat4 { + let _0 = T::zero(); + let _1 = T::one(); TMat4::new( m.m11, m.m12, _0, _0, m.m21, m.m22, _0, _0, _0, _0, _1, _0, _0, _0, _0, _1, @@ -120,7 +120,7 @@ pub fn mat2_to_mat4(m: &TMat2) -> TMat4 { } /// Converts a 4x4 matrix to a 2x2 matrix. -pub fn mat4_to_mat2(m: &TMat4) -> TMat2 { +pub fn mat4_to_mat2(m: &TMat4) -> TMat2 { TMat2::new( m.m11.inlined_clone(), m.m12.inlined_clone(), @@ -130,7 +130,7 @@ pub fn mat4_to_mat2(m: &TMat4) -> TMat2 { } /// Creates a quaternion from a slice arranged as `[x, y, z, w]`. -pub fn make_quat(ptr: &[N]) -> Qua { +pub fn make_quat(ptr: &[T]) -> Qua { Quaternion::from(TVec4::from_column_slice(ptr)) } @@ -141,7 +141,7 @@ pub fn make_quat(ptr: &[N]) -> Qua { /// * [`make_vec2`](fn.make_vec2.html) /// * [`make_vec3`](fn.make_vec3.html) /// * [`make_vec4`](fn.make_vec4.html) -pub fn make_vec1(v: &TVec1) -> TVec1 { +pub fn make_vec1(v: &TVec1) -> TVec1 { v.clone() } @@ -155,7 +155,7 @@ pub fn make_vec1(v: &TVec1) -> TVec1 { /// * [`vec1_to_vec2`](fn.vec1_to_vec2.html) /// * [`vec1_to_vec3`](fn.vec1_to_vec3.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) -pub fn vec2_to_vec1(v: &TVec2) -> TVec1 { +pub fn vec2_to_vec1(v: &TVec2) -> TVec1 { TVec1::new(v.x.inlined_clone()) } @@ -169,7 +169,7 @@ pub fn vec2_to_vec1(v: &TVec2) -> TVec1 { /// * [`vec1_to_vec2`](fn.vec1_to_vec2.html) /// * [`vec1_to_vec3`](fn.vec1_to_vec3.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) -pub fn vec3_to_vec1(v: &TVec3) -> TVec1 { +pub fn vec3_to_vec1(v: &TVec3) -> TVec1 { TVec1::new(v.x.inlined_clone()) } @@ -183,7 +183,7 @@ pub fn vec3_to_vec1(v: &TVec3) -> TVec1 { /// * [`vec1_to_vec2`](fn.vec1_to_vec2.html) /// * [`vec1_to_vec3`](fn.vec1_to_vec3.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) -pub fn vec4_to_vec1(v: &TVec4) -> TVec1 { +pub fn vec4_to_vec1(v: &TVec4) -> TVec1 { TVec1::new(v.x.inlined_clone()) } @@ -199,8 +199,8 @@ pub fn vec4_to_vec1(v: &TVec4) -> TVec1 { /// * [`vec2_to_vec2`](fn.vec2_to_vec2.html) /// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) /// * [`vec2_to_vec4`](fn.vec2_to_vec4.html) -pub fn vec1_to_vec2(v: &TVec1) -> TVec2 { - TVec2::new(v.x.inlined_clone(), N::zero()) +pub fn vec1_to_vec2(v: &TVec1) -> TVec2 { + TVec2::new(v.x.inlined_clone(), T::zero()) } /// Creates a 2D vector from another vector. @@ -214,7 +214,7 @@ pub fn vec1_to_vec2(v: &TVec1) -> TVec2 { /// * [`vec2_to_vec2`](fn.vec2_to_vec2.html) /// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) /// * [`vec2_to_vec4`](fn.vec2_to_vec4.html) -pub fn vec2_to_vec2(v: &TVec2) -> TVec2 { +pub fn vec2_to_vec2(v: &TVec2) -> TVec2 { v.clone() } @@ -228,7 +228,7 @@ pub fn vec2_to_vec2(v: &TVec2) -> TVec2 { /// * [`vec2_to_vec2`](fn.vec2_to_vec2.html) /// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) /// * [`vec2_to_vec4`](fn.vec2_to_vec4.html) -pub fn vec3_to_vec2(v: &TVec3) -> TVec2 { +pub fn vec3_to_vec2(v: &TVec3) -> TVec2 { TVec2::new(v.x.inlined_clone(), v.y.inlined_clone()) } @@ -242,7 +242,7 @@ pub fn vec3_to_vec2(v: &TVec3) -> TVec2 { /// * [`vec2_to_vec2`](fn.vec2_to_vec2.html) /// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) /// * [`vec2_to_vec4`](fn.vec2_to_vec4.html) -pub fn vec4_to_vec2(v: &TVec4) -> TVec2 { +pub fn vec4_to_vec2(v: &TVec4) -> TVec2 { TVec2::new(v.x.inlined_clone(), v.y.inlined_clone()) } @@ -253,7 +253,7 @@ pub fn vec4_to_vec2(v: &TVec4) -> TVec2 { /// * [`make_vec1`](fn.make_vec1.html) /// * [`make_vec3`](fn.make_vec3.html) /// * [`make_vec4`](fn.make_vec4.html) -pub fn make_vec2(ptr: &[N]) -> TVec2 { +pub fn make_vec2(ptr: &[T]) -> TVec2 { TVec2::from_column_slice(ptr) } @@ -268,8 +268,8 @@ pub fn make_vec2(ptr: &[N]) -> TVec2 { /// * [`vec4_to_vec3`](fn.vec4_to_vec3.html) /// * [`vec1_to_vec2`](fn.vec1_to_vec2.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) -pub fn vec1_to_vec3(v: &TVec1) -> TVec3 { - TVec3::new(v.x.inlined_clone(), N::zero(), N::zero()) +pub fn vec1_to_vec3(v: &TVec1) -> TVec3 { + TVec3::new(v.x.inlined_clone(), T::zero(), T::zero()) } /// Creates a 3D vector from another vector. @@ -284,8 +284,8 @@ pub fn vec1_to_vec3(v: &TVec1) -> TVec3 { /// * [`vec3_to_vec1`](fn.vec3_to_vec1.html) /// * [`vec3_to_vec2`](fn.vec3_to_vec2.html) /// * [`vec3_to_vec4`](fn.vec3_to_vec4.html) -pub fn vec2_to_vec3(v: &TVec2) -> TVec3 { - TVec3::new(v.x.inlined_clone(), v.y.inlined_clone(), N::zero()) +pub fn vec2_to_vec3(v: &TVec2) -> TVec3 { + TVec3::new(v.x.inlined_clone(), v.y.inlined_clone(), T::zero()) } /// Creates a 3D vector from another vector. @@ -298,7 +298,7 @@ pub fn vec2_to_vec3(v: &TVec2) -> TVec3 { /// * [`vec3_to_vec1`](fn.vec3_to_vec1.html) /// * [`vec3_to_vec2`](fn.vec3_to_vec2.html) /// * [`vec3_to_vec4`](fn.vec3_to_vec4.html) -pub fn vec3_to_vec3(v: &TVec3) -> TVec3 { +pub fn vec3_to_vec3(v: &TVec3) -> TVec3 { v.clone() } @@ -312,7 +312,7 @@ pub fn vec3_to_vec3(v: &TVec3) -> TVec3 { /// * [`vec3_to_vec1`](fn.vec3_to_vec1.html) /// * [`vec3_to_vec2`](fn.vec3_to_vec2.html) /// * [`vec3_to_vec4`](fn.vec3_to_vec4.html) -pub fn vec4_to_vec3(v: &TVec4) -> TVec3 { +pub fn vec4_to_vec3(v: &TVec4) -> TVec3 { TVec3::new( v.x.inlined_clone(), v.y.inlined_clone(), @@ -327,7 +327,7 @@ pub fn vec4_to_vec3(v: &TVec4) -> TVec3 { /// * [`make_vec1`](fn.make_vec1.html) /// * [`make_vec2`](fn.make_vec2.html) /// * [`make_vec4`](fn.make_vec4.html) -pub fn make_vec3(ptr: &[N]) -> TVec3 { +pub fn make_vec3(ptr: &[T]) -> TVec3 { TVec3::from_column_slice(ptr) } @@ -343,8 +343,8 @@ pub fn make_vec3(ptr: &[N]) -> TVec3 { /// * [`vec1_to_vec2`](fn.vec1_to_vec2.html) /// * [`vec1_to_vec3`](fn.vec1_to_vec3.html) /// * [`vec1_to_vec4`](fn.vec1_to_vec4.html) -pub fn vec1_to_vec4(v: &TVec1) -> TVec4 { - TVec4::new(v.x, N::zero(), N::zero(), N::zero()) +pub fn vec1_to_vec4(v: &TVec1) -> TVec4 { + TVec4::new(v.x, T::zero(), T::zero(), T::zero()) } /// Creates a 4D vector from another vector. @@ -359,8 +359,8 @@ pub fn vec1_to_vec4(v: &TVec1) -> TVec4 { /// * [`vec2_to_vec1`](fn.vec2_to_vec1.html) /// * [`vec2_to_vec2`](fn.vec2_to_vec2.html) /// * [`vec2_to_vec3`](fn.vec2_to_vec3.html) -pub fn vec2_to_vec4(v: &TVec2) -> TVec4 { - TVec4::new(v.x, v.y, N::zero(), N::zero()) +pub fn vec2_to_vec4(v: &TVec2) -> TVec4 { + TVec4::new(v.x, v.y, T::zero(), T::zero()) } /// Creates a 4D vector from another vector. @@ -375,8 +375,8 @@ pub fn vec2_to_vec4(v: &TVec2) -> TVec4 { /// * [`vec3_to_vec1`](fn.vec3_to_vec1.html) /// * [`vec3_to_vec2`](fn.vec3_to_vec2.html) /// * [`vec3_to_vec3`](fn.vec3_to_vec3.html) -pub fn vec3_to_vec4(v: &TVec3) -> TVec4 { - TVec4::new(v.x, v.y, v.z, N::zero()) +pub fn vec3_to_vec4(v: &TVec3) -> TVec4 { + TVec4::new(v.x, v.y, v.z, T::zero()) } /// Creates a 4D vector from another vector. @@ -389,7 +389,7 @@ pub fn vec3_to_vec4(v: &TVec3) -> TVec4 { /// * [`vec4_to_vec1`](fn.vec4_to_vec1.html) /// * [`vec4_to_vec2`](fn.vec4_to_vec2.html) /// * [`vec4_to_vec3`](fn.vec4_to_vec3.html) -pub fn vec4_to_vec4(v: &TVec4) -> TVec4 { +pub fn vec4_to_vec4(v: &TVec4) -> TVec4 { v.clone() } @@ -400,22 +400,16 @@ pub fn vec4_to_vec4(v: &TVec4) -> TVec4 { /// * [`make_vec1`](fn.make_vec1.html) /// * [`make_vec2`](fn.make_vec2.html) /// * [`make_vec3`](fn.make_vec3.html) -pub fn make_vec4(ptr: &[N]) -> TVec4 { +pub fn make_vec4(ptr: &[T]) -> TVec4 { TVec4::from_column_slice(ptr) } /// Converts a matrix or vector to a slice arranged in column-major order. -pub fn value_ptr(x: &TMat) -> &[N] -where - DefaultAllocator: Alloc, -{ +pub fn value_ptr(x: &TMat) -> &[T] { 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, -{ +pub fn value_ptr_mut(x: &mut TMat) -> &mut [T] { x.as_mut_slice() } diff --git a/nalgebra-glm/src/gtc/ulp.rs b/nalgebra-glm/src/gtc/ulp.rs index 8258d0df..4ab93826 100644 --- a/nalgebra-glm/src/gtc/ulp.rs +++ b/nalgebra-glm/src/gtc/ulp.rs @@ -2,12 +2,11 @@ use na::{Scalar, U2}; use crate::aliases::TVec; - pub fn float_distance(x: T, y: T) -> u64 { unimplemented!() } -pub fn float_distance2(x: &TVec2, y: &TVec2) -> TVec { +pub fn float_distance2(x: &TVec2, y: &TVec2) -> TVec { unimplemented!() } diff --git a/nalgebra-glm/src/gtx/component_wise.rs b/nalgebra-glm/src/gtx/component_wise.rs index cfb851f4..85d0dd71 100644 --- a/nalgebra-glm/src/gtx/component_wise.rs +++ b/nalgebra-glm/src/gtx/component_wise.rs @@ -1,7 +1,5 @@ -use na::{self, DefaultAllocator}; - use crate::aliases::TMat; -use crate::traits::{Alloc, Dimension, Number}; +use crate::traits::Number; /// The sum of every component of the given matrix or vector. /// @@ -21,11 +19,8 @@ use crate::traits::{Alloc, Dimension, Number}; /// * [`comp_max`](fn.comp_max.html) /// * [`comp_min`](fn.comp_min.html) /// * [`comp_mul`](fn.comp_mul.html) -pub fn comp_add(m: &TMat) -> N -where - DefaultAllocator: Alloc, -{ - m.iter().fold(N::zero(), |x, y| x + *y) +pub fn comp_add(m: &TMat) -> T { + m.iter().fold(T::zero(), |x, y| x + *y) } /// The maximum of every component of the given matrix or vector. @@ -50,12 +45,9 @@ where /// * [`max2`](fn.max2.html) /// * [`max3`](fn.max3.html) /// * [`max4`](fn.max4.html) -pub fn comp_max(m: &TMat) -> N -where - DefaultAllocator: Alloc, -{ +pub fn comp_max(m: &TMat) -> T { m.iter() - .fold(N::min_value(), |x, y| crate::max2_scalar(x, *y)) + .fold(T::min_value(), |x, y| crate::max2_scalar(x, *y)) } /// The minimum of every component of the given matrix or vector. @@ -80,12 +72,9 @@ where /// * [`min2`](fn.min2.html) /// * [`min3`](fn.min3.html) /// * [`min4`](fn.min4.html) -pub fn comp_min(m: &TMat) -> N -where - DefaultAllocator: Alloc, -{ +pub fn comp_min(m: &TMat) -> T { m.iter() - .fold(N::max_value(), |x, y| crate::min2_scalar(x, *y)) + .fold(T::max_value(), |x, y| crate::min2_scalar(x, *y)) } /// The product of every component of the given matrix or vector. @@ -106,11 +95,8 @@ where /// * [`comp_add`](fn.comp_add.html) /// * [`comp_max`](fn.comp_max.html) /// * [`comp_min`](fn.comp_min.html) -pub fn comp_mul(m: &TMat) -> N -where - DefaultAllocator: Alloc, -{ - m.iter().fold(N::one(), |x, y| x * *y) +pub fn comp_mul(m: &TMat) -> T { + m.iter().fold(T::one(), |x, y| x * *y) } //pub fn vec< L, floatType, Q > compNormalize (vec< L, T, Q > const &v) diff --git a/nalgebra-glm/src/gtx/euler_angles.rs b/nalgebra-glm/src/gtx/euler_angles.rs index c9d16738..4dc9f9d1 100644 --- a/nalgebra-glm/src/gtx/euler_angles.rs +++ b/nalgebra-glm/src/gtx/euler_angles.rs @@ -1,163 +1,163 @@ use na::{RealField, U3, U4}; -use crate::aliases::{TVec, TMat}; +use crate::aliases::{TMat, TVec}; -pub fn derivedEulerAngleX(angleX: N, angularVelocityX: N) -> TMat4 { +pub fn derivedEulerAngleX(angleX: T, angularVelocityX: T) -> TMat4 { unimplemented!() } -pub fn derivedEulerAngleY(angleY: N, angularVelocityY: N) -> TMat4 { +pub fn derivedEulerAngleY(angleY: T, angularVelocityY: T) -> TMat4 { unimplemented!() } -pub fn derivedEulerAngleZ(angleZ: N, angularVelocityZ: N) -> TMat4 { +pub fn derivedEulerAngleZ(angleZ: T, angularVelocityZ: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleX(angleX: N) -> TMat4 { +pub fn eulerAngleX(angleX: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleXY(angleX: N, angleY: N) -> TMat4 { +pub fn eulerAngleXY(angleX: T, angleY: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleXYX(t1: N, t2: N, t3: N) -> TMat4 { +pub fn eulerAngleXYX(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleXYZ(t1: N, t2: N, t3: N) -> TMat4 { +pub fn eulerAngleXYZ(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleXZ(angleX: N, angleZ: N) -> TMat4 { +pub fn eulerAngleXZ(angleX: T, angleZ: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleXZX(t1: N, t2: N, t3: N) -> TMat4 { +pub fn eulerAngleXZX(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleXZY(t1: N, t2: N, t3: N) -> TMat4 { +pub fn eulerAngleXZY(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleY(angleY: N) -> TMat4 { +pub fn eulerAngleY(angleY: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleYX(angleY: N, angleX: N) -> TMat4 { +pub fn eulerAngleYX(angleY: T, angleX: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleYXY(t1: N, t2: N, t3: N) -> TMat4 { +pub fn eulerAngleYXY(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleYXZ(yaw: N, pitch: N, roll: N) -> TMat4 { +pub fn eulerAngleYXZ(yaw: T, pitch: T, roll: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleYZ(angleY: N, angleZ: N) -> TMat4 { +pub fn eulerAngleYZ(angleY: T, angleZ: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleYZX(t1: N, t2: N, t3: N) -> TMat4 { +pub fn eulerAngleYZX(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleYZY(t1: N, t2: N, t3: N) -> TMat4 { +pub fn eulerAngleYZY(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZ(angleZ: N) -> TMat4 { +pub fn eulerAngleZ(angleZ: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZX(angle: N, angleX: N) -> TMat4 { +pub fn eulerAngleZX(angle: T, angleX: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZXY(t1: N, t2: N, t3: N) -> TMat4 { +pub fn eulerAngleZXY(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZXZ(t1: N, t2: N, t3: N) -> TMat4 { +pub fn eulerAngleZXZ(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZY(angleZ: N, angleY: N) -> TMat4 { +pub fn eulerAngleZY(angleZ: T, angleY: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZYX(t1: N, t2: N, t3: N) -> TMat4 { +pub fn eulerAngleZYX(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn eulerAngleZYZ(t1: N, t2: N, t3: N) -> TMat4 { +pub fn eulerAngleZYZ(t1: T, t2: T, t3: T) -> TMat4 { unimplemented!() } -pub fn extractEulerAngleXYX(M: &TMat4) -> (N, N, N) { +pub fn extractEulerAngleXYX(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleXYZ(M: &TMat4) -> (N, N, N) { +pub fn extractEulerAngleXYZ(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleXZX(M: &TMat4) -> (N, N, N) { +pub fn extractEulerAngleXZX(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleXZY(M: &TMat4) -> (N, N, N) { +pub fn extractEulerAngleXZY(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleYXY(M: &TMat4) -> (N, N, N) { +pub fn extractEulerAngleYXY(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleYXZ(M: &TMat4) -> (N, N, N) { +pub fn extractEulerAngleYXZ(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleYZX(M: &TMat4) -> (N, N, N) { +pub fn extractEulerAngleYZX(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleYZY(M: &TMat4) -> (N, N, N) { +pub fn extractEulerAngleYZY(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleZXY(M: &TMat4) -> (N, N, N) { +pub fn extractEulerAngleZXY(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleZXZ(M: &TMat4) -> (N, N, N) { +pub fn extractEulerAngleZXZ(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleZYX(M: &TMat4) -> (N, N, N) { +pub fn extractEulerAngleZYX(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn extractEulerAngleZYZ(M: &TMat4) -> (N, N, N) { +pub fn extractEulerAngleZYZ(M: &TMat4) -> (T, T, T) { unimplemented!() } -pub fn orientate2(angle: N) -> TMat3x3 { +pub fn orientate2(angle: T) -> TMat3x3 { unimplemented!() } -pub fn orientate3(angles: TVec3) -> TMat3x3 { +pub fn orientate3(angles: TVec3) -> TMat3x3 { unimplemented!() } -pub fn orientate4(angles: TVec3) -> TMat4 { +pub fn orientate4(angles: TVec3) -> TMat4 { unimplemented!() } -pub fn yawPitchRoll(yaw: N, pitch: N, roll: N) -> TMat4 { +pub fn yawPitchRoll(yaw: T, pitch: T, roll: T) -> TMat4 { unimplemented!() } diff --git a/nalgebra-glm/src/gtx/exterior_product.rs b/nalgebra-glm/src/gtx/exterior_product.rs index a95c557b..15e9f998 100644 --- a/nalgebra-glm/src/gtx/exterior_product.rs +++ b/nalgebra-glm/src/gtx/exterior_product.rs @@ -2,6 +2,6 @@ use crate::aliases::TVec2; use crate::traits::Number; /// The 2D perpendicular product between two vectors. -pub fn cross2d(v: &TVec2, u: &TVec2) -> N { +pub fn cross2d(v: &TVec2, u: &TVec2) -> T { v.perp(u) } diff --git a/nalgebra-glm/src/gtx/handed_coordinate_space.rs b/nalgebra-glm/src/gtx/handed_coordinate_space.rs index 22d25056..1063db5e 100644 --- a/nalgebra-glm/src/gtx/handed_coordinate_space.rs +++ b/nalgebra-glm/src/gtx/handed_coordinate_space.rs @@ -6,8 +6,8 @@ use crate::traits::Number; /// # See also: /// /// * [`right_handed`](fn.right_handed.html) -pub fn left_handed(a: &TVec3, b: &TVec3, c: &TVec3) -> bool { - a.cross(b).dot(c) < N::zero() +pub fn left_handed(a: &TVec3, b: &TVec3, c: &TVec3) -> bool { + a.cross(b).dot(c) < T::zero() } /// Returns `true` if `{a, b, c}` forms a right-handed trihedron. @@ -15,6 +15,6 @@ pub fn left_handed(a: &TVec3, b: &TVec3, c: &TVec3) -> bool /// # See also: /// /// * [`left_handed`](fn.left_handed.html) -pub fn right_handed(a: &TVec3, b: &TVec3, c: &TVec3) -> bool { - a.cross(b).dot(c) > N::zero() +pub fn right_handed(a: &TVec3, b: &TVec3, c: &TVec3) -> bool { + a.cross(b).dot(c) > T::zero() } diff --git a/nalgebra-glm/src/gtx/matrix_cross_product.rs b/nalgebra-glm/src/gtx/matrix_cross_product.rs index 40aa03e8..83ac881e 100644 --- a/nalgebra-glm/src/gtx/matrix_cross_product.rs +++ b/nalgebra-glm/src/gtx/matrix_cross_product.rs @@ -7,7 +7,7 @@ use crate::aliases::{TMat3, TMat4, TVec3}; /// # See also: /// /// * [`matrix_cross`](fn.matrix_cross.html) -pub fn matrix_cross3(x: &TVec3) -> TMat3 { +pub fn matrix_cross3(x: &TVec3) -> TMat3 { x.cross_matrix() } @@ -16,6 +16,6 @@ pub fn matrix_cross3(x: &TVec3) -> TMat3 { /// # See also: /// /// * [`matrix_cross3`](fn.matrix_cross3.html) -pub fn matrix_cross(x: &TVec3) -> TMat4 { +pub fn matrix_cross(x: &TVec3) -> TMat4 { crate::mat3_to_mat4(&x.cross_matrix()) } diff --git a/nalgebra-glm/src/gtx/matrix_operation.rs b/nalgebra-glm/src/gtx/matrix_operation.rs index cc051273..a46a9a5c 100644 --- a/nalgebra-glm/src/gtx/matrix_operation.rs +++ b/nalgebra-glm/src/gtx/matrix_operation.rs @@ -15,7 +15,7 @@ use crate::traits::Number; /// * [`diagonal4x2`](fn.diagonal4x2.html) /// * [`diagonal4x3`](fn.diagonal4x3.html) /// * [`diagonal4x4`](fn.diagonal4x4.html) -pub fn diagonal2x2(v: &TVec2) -> TMat2 { +pub fn diagonal2x2(v: &TVec2) -> TMat2 { TMat2::from_diagonal(v) } @@ -31,7 +31,7 @@ pub fn diagonal2x2(v: &TVec2) -> TMat2 { /// * [`diagonal4x2`](fn.diagonal4x2.html) /// * [`diagonal4x3`](fn.diagonal4x3.html) /// * [`diagonal4x4`](fn.diagonal4x4.html) -pub fn diagonal2x3(v: &TVec2) -> TMat2x3 { +pub fn diagonal2x3(v: &TVec2) -> TMat2x3 { TMat2x3::from_partial_diagonal(v.as_slice()) } @@ -47,7 +47,7 @@ pub fn diagonal2x3(v: &TVec2) -> TMat2x3 { /// * [`diagonal4x2`](fn.diagonal4x2.html) /// * [`diagonal4x3`](fn.diagonal4x3.html) /// * [`diagonal4x4`](fn.diagonal4x4.html) -pub fn diagonal2x4(v: &TVec2) -> TMat2x4 { +pub fn diagonal2x4(v: &TVec2) -> TMat2x4 { TMat2x4::from_partial_diagonal(v.as_slice()) } @@ -63,7 +63,7 @@ pub fn diagonal2x4(v: &TVec2) -> TMat2x4 { /// * [`diagonal4x2`](fn.diagonal4x2.html) /// * [`diagonal4x3`](fn.diagonal4x3.html) /// * [`diagonal4x4`](fn.diagonal4x4.html) -pub fn diagonal3x2(v: &TVec2) -> TMat3x2 { +pub fn diagonal3x2(v: &TVec2) -> TMat3x2 { TMat3x2::from_partial_diagonal(v.as_slice()) } @@ -79,7 +79,7 @@ pub fn diagonal3x2(v: &TVec2) -> TMat3x2 { /// * [`diagonal4x2`](fn.diagonal4x2.html) /// * [`diagonal4x3`](fn.diagonal4x3.html) /// * [`diagonal4x4`](fn.diagonal4x4.html) -pub fn diagonal3x3(v: &TVec3) -> TMat3 { +pub fn diagonal3x3(v: &TVec3) -> TMat3 { TMat3::from_diagonal(v) } @@ -95,7 +95,7 @@ pub fn diagonal3x3(v: &TVec3) -> TMat3 { /// * [`diagonal4x2`](fn.diagonal4x2.html) /// * [`diagonal4x3`](fn.diagonal4x3.html) /// * [`diagonal4x4`](fn.diagonal4x4.html) -pub fn diagonal3x4(v: &TVec3) -> TMat3x4 { +pub fn diagonal3x4(v: &TVec3) -> TMat3x4 { TMat3x4::from_partial_diagonal(v.as_slice()) } @@ -111,7 +111,7 @@ pub fn diagonal3x4(v: &TVec3) -> TMat3x4 { /// * [`diagonal3x4`](fn.diagonal3x4.html) /// * [`diagonal4x3`](fn.diagonal4x3.html) /// * [`diagonal4x4`](fn.diagonal4x4.html) -pub fn diagonal4x2(v: &TVec2) -> TMat4x2 { +pub fn diagonal4x2(v: &TVec2) -> TMat4x2 { TMat4x2::from_partial_diagonal(v.as_slice()) } @@ -127,7 +127,7 @@ pub fn diagonal4x2(v: &TVec2) -> TMat4x2 { /// * [`diagonal3x4`](fn.diagonal3x4.html) /// * [`diagonal4x2`](fn.diagonal4x2.html) /// * [`diagonal4x4`](fn.diagonal4x4.html) -pub fn diagonal4x3(v: &TVec3) -> TMat4x3 { +pub fn diagonal4x3(v: &TVec3) -> TMat4x3 { TMat4x3::from_partial_diagonal(v.as_slice()) } @@ -143,6 +143,6 @@ pub fn diagonal4x3(v: &TVec3) -> TMat4x3 { /// * [`diagonal3x4`](fn.diagonal3x4.html) /// * [`diagonal4x2`](fn.diagonal4x2.html) /// * [`diagonal4x3`](fn.diagonal4x3.html) -pub fn diagonal4x4(v: &TVec4) -> TMat4 { +pub fn diagonal4x4(v: &TVec4) -> TMat4 { TMat4::from_diagonal(v) } diff --git a/nalgebra-glm/src/gtx/norm.rs b/nalgebra-glm/src/gtx/norm.rs index f6fabe97..8da6ab13 100644 --- a/nalgebra-glm/src/gtx/norm.rs +++ b/nalgebra-glm/src/gtx/norm.rs @@ -1,17 +1,13 @@ -use na::{DefaultAllocator, RealField}; +use na::RealField; use crate::aliases::TVec; -use crate::traits::{Alloc, Dimension}; /// The squared distance between two points. /// /// # See also: /// /// * [`distance`](fn.distance.html) -pub fn distance2(p0: &TVec, p1: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn distance2(p0: &TVec, p1: &TVec) -> T { (p1 - p0).norm_squared() } @@ -22,10 +18,7 @@ where /// * [`l1_norm`](fn.l1_norm.html) /// * [`l2_distance`](fn.l2_distance.html) /// * [`l2_norm`](fn.l2_norm.html) -pub fn l1_distance(x: &TVec, y: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn l1_distance(x: &TVec, y: &TVec) -> T { l1_norm(&(y - x)) } @@ -39,10 +32,7 @@ where /// * [`l1_distance`](fn.l1_distance.html) /// * [`l2_distance`](fn.l2_distance.html) /// * [`l2_norm`](fn.l2_norm.html) -pub fn l1_norm(v: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn l1_norm(v: &TVec) -> T { crate::comp_add(&v.abs()) } @@ -60,10 +50,7 @@ where /// * [`length2`](fn.length2.html) /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) -pub fn l2_distance(x: &TVec, y: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn l2_distance(x: &TVec, y: &TVec) -> T { l2_norm(&(y - x)) } @@ -83,10 +70,7 @@ where /// * [`length2`](fn.length2.html) /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) -pub fn l2_norm(x: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn l2_norm(x: &TVec) -> T { x.norm() } @@ -101,10 +85,7 @@ where /// * [`length`](fn.length.html) /// * [`magnitude`](fn.magnitude.html) /// * [`magnitude2`](fn.magnitude2.html) -pub fn length2(x: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn length2(x: &TVec) -> T { x.norm_squared() } @@ -119,19 +100,14 @@ where /// * [`length2`](fn.length2.html) /// * [`magnitude`](fn.magnitude.html) /// * [`nalgebra::norm_squared`](../nalgebra/fn.norm_squared.html) -pub fn magnitude2(x: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn magnitude2(x: &TVec) -> T { x.norm_squared() } -//pub fn lxNorm(x: &TVec, y: &TVec, unsigned int Depth) -> N -// where DefaultAllocator: Alloc { +//pub fn lxNorm(x: &TVec, y: &TVec, unsigned int Depth) -> T { // unimplemented!() //} // -//pub fn lxNorm(x: &TVec, unsigned int Depth) -> N -// where DefaultAllocator: Alloc { +//pub fn lxNorm(x: &TVec, unsigned int Depth) -> T { // unimplemented!() //} diff --git a/nalgebra-glm/src/gtx/normal.rs b/nalgebra-glm/src/gtx/normal.rs index d9f48034..0686b787 100644 --- a/nalgebra-glm/src/gtx/normal.rs +++ b/nalgebra-glm/src/gtx/normal.rs @@ -5,6 +5,6 @@ use crate::aliases::TVec3; /// The normal vector of the given triangle. /// /// The normal is computed as the normalized vector `cross(p2 - p1, p3 - p1)`. -pub fn triangle_normal(p1: &TVec3, p2: &TVec3, p3: &TVec3) -> TVec3 { +pub fn triangle_normal(p1: &TVec3, p2: &TVec3, p3: &TVec3) -> TVec3 { (p2 - p1).cross(&(p3 - p1)).normalize() } diff --git a/nalgebra-glm/src/gtx/normalize_dot.rs b/nalgebra-glm/src/gtx/normalize_dot.rs index 23e6a73f..7305ee2b 100644 --- a/nalgebra-glm/src/gtx/normalize_dot.rs +++ b/nalgebra-glm/src/gtx/normalize_dot.rs @@ -1,7 +1,6 @@ -use na::{DefaultAllocator, RealField}; +use na::RealField; use crate::aliases::TVec; -use crate::traits::{Alloc, Dimension}; /// The dot product of the normalized version of `x` and `y`. /// @@ -10,10 +9,7 @@ use crate::traits::{Alloc, Dimension}; /// # See also: /// /// * [`normalize_dot`](fn.normalize_dot.html`) -pub fn fast_normalize_dot(x: &TVec, y: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn fast_normalize_dot(x: &TVec, y: &TVec) -> T { // XXX: improve those. x.normalize().dot(&y.normalize()) } @@ -23,10 +19,7 @@ where /// # See also: /// /// * [`fast_normalize_dot`](fn.fast_normalize_dot.html`) -pub fn normalize_dot(x: &TVec, y: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn normalize_dot(x: &TVec, y: &TVec) -> T { // 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 a90760d4..3f256e64 100644 --- a/nalgebra-glm/src/gtx/quaternion.rs +++ b/nalgebra-glm/src/gtx/quaternion.rs @@ -1,97 +1,97 @@ -use na::{RealField, Rotation3, Unit, UnitQuaternion, U3}; +use na::{RealField, Rotation3, Unit, UnitQuaternion}; use crate::aliases::{Qua, TMat3, TMat4, TVec3, TVec4}; /// Rotate the vector `v` by the quaternion `q` assumed to be normalized. -pub fn quat_cross_vec(q: &Qua, v: &TVec3) -> TVec3 { +pub fn quat_cross_vec(q: &Qua, v: &TVec3) -> TVec3 { UnitQuaternion::new_unchecked(*q) * v } /// Rotate the vector `v` by the inverse of the quaternion `q` assumed to be normalized. -pub fn quat_inv_cross_vec(v: &TVec3, q: &Qua) -> TVec3 { +pub fn quat_inv_cross_vec(v: &TVec3, q: &Qua) -> TVec3 { UnitQuaternion::new_unchecked(*q).inverse() * v } /// The quaternion `w` component. -pub fn quat_extract_real_component(q: &Qua) -> N { +pub fn quat_extract_real_component(q: &Qua) -> T { q.w } /// Normalized linear interpolation between two quaternions. -pub fn quat_fast_mix(x: &Qua, y: &Qua, a: N) -> Qua { +pub fn quat_fast_mix(x: &Qua, y: &Qua, a: T) -> Qua { Unit::new_unchecked(*x) .nlerp(&Unit::new_unchecked(*y), a) .into_inner() } -//pub fn quat_intermediate(prev: &Qua, curr: &Qua, next: &Qua) -> Qua { +//pub fn quat_intermediate(prev: &Qua, curr: &Qua, next: &Qua) -> Qua { // unimplemented!() //} /// The squared magnitude of a quaternion `q`. -pub fn quat_length2(q: &Qua) -> N { +pub fn quat_length2(q: &Qua) -> T { q.norm_squared() } /// The squared magnitude of a quaternion `q`. -pub fn quat_magnitude2(q: &Qua) -> N { +pub fn quat_magnitude2(q: &Qua) -> T { q.norm_squared() } /// The quaternion representing the identity rotation. -pub fn quat_identity() -> Qua { +pub fn quat_identity() -> Qua { UnitQuaternion::identity().into_inner() } /// Rotates a vector by a quaternion assumed to be normalized. -pub fn quat_rotate_vec3(q: &Qua, v: &TVec3) -> TVec3 { +pub fn quat_rotate_vec3(q: &Qua, v: &TVec3) -> TVec3 { UnitQuaternion::new_unchecked(*q) * v } /// Rotates a vector in homogeneous coordinates by a quaternion assumed to be normalized. -pub fn quat_rotate_vec(q: &Qua, v: &TVec4) -> TVec4 { - let rotated = Unit::new_unchecked(*q) * v.fixed_rows::(0); +pub fn quat_rotate_vec(q: &Qua, v: &TVec4) -> TVec4 { + let rotated = Unit::new_unchecked(*q) * v.fixed_rows::<3>(0); TVec4::new(rotated.x, rotated.y, rotated.z, v.w) } /// The rotation required to align `orig` to `dest`. -pub fn quat_rotation(orig: &TVec3, dest: &TVec3) -> Qua { +pub fn quat_rotation(orig: &TVec3, dest: &TVec3) -> Qua { UnitQuaternion::rotation_between(orig, dest) .unwrap_or_else(UnitQuaternion::identity) .into_inner() } /// The spherical linear interpolation between two quaternions. -pub fn quat_short_mix(x: &Qua, y: &Qua, a: N) -> Qua { +pub fn quat_short_mix(x: &Qua, y: &Qua, a: T) -> Qua { Unit::new_normalize(*x) .slerp(&Unit::new_normalize(*y), a) .into_inner() } -//pub fn quat_squad(q1: &Qua, q2: &Qua, s1: &Qua, s2: &Qua, h: N) -> Qua { +//pub fn quat_squad(q1: &Qua, q2: &Qua, s1: &Qua, s2: &Qua, h: T) -> Qua { // unimplemented!() //} /// Converts a quaternion to a rotation matrix. -pub fn quat_to_mat3(x: &Qua) -> TMat3 { +pub fn quat_to_mat3(x: &Qua) -> TMat3 { UnitQuaternion::new_unchecked(*x) .to_rotation_matrix() .into_inner() } /// Converts a quaternion to a rotation matrix in homogenous coordinates. -pub fn quat_to_mat4(x: &Qua) -> TMat4 { +pub fn quat_to_mat4(x: &Qua) -> TMat4 { UnitQuaternion::new_unchecked(*x).to_homogeneous() } /// Converts a rotation matrix to a quaternion. -pub fn mat3_to_quat(x: &TMat3) -> Qua { +pub fn mat3_to_quat(x: &TMat3) -> Qua { let r = Rotation3::from_matrix_unchecked(*x); UnitQuaternion::from_rotation_matrix(&r).into_inner() } /// Converts a rotation matrix in homogeneous coordinates to a quaternion. -pub fn to_quat(x: &TMat4) -> Qua { - let rot = x.fixed_slice::(0, 0).into_owned(); +pub fn to_quat(x: &TMat4) -> Qua { + let rot = x.fixed_slice::<3, 3>(0, 0).into_owned(); mat3_to_quat(&rot) } diff --git a/nalgebra-glm/src/gtx/rotate_normalized_axis.rs b/nalgebra-glm/src/gtx/rotate_normalized_axis.rs index 1672b978..e403864c 100644 --- a/nalgebra-glm/src/gtx/rotate_normalized_axis.rs +++ b/nalgebra-glm/src/gtx/rotate_normalized_axis.rs @@ -9,7 +9,7 @@ use crate::aliases::{Qua, TMat4, TVec3}; /// * `m` - Input matrix multiplied by this rotation matrix. /// * `angle` - Rotation angle expressed in radians. /// * `axis` - Rotation axis, must be normalized. -pub fn rotate_normalized_axis(m: &TMat4, angle: N, axis: &TVec3) -> TMat4 { +pub fn rotate_normalized_axis(m: &TMat4, angle: T, axis: &TVec3) -> TMat4 { m * Rotation3::from_axis_angle(&Unit::new_unchecked(*axis), angle).to_homogeneous() } @@ -20,6 +20,6 @@ pub fn rotate_normalized_axis(m: &TMat4, angle: N, axis: &TVec3 /// * `q` - Source orientation. /// * `angle` - Angle expressed in radians. /// * `axis` - Normalized axis of the rotation, must be normalized. -pub fn quat_rotate_normalized_axis(q: &Qua, angle: N, axis: &TVec3) -> Qua { +pub fn quat_rotate_normalized_axis(q: &Qua, angle: T, axis: &TVec3) -> Qua { q * UnitQuaternion::from_axis_angle(&Unit::new_unchecked(*axis), angle).into_inner() } diff --git a/nalgebra-glm/src/gtx/rotate_vector.rs b/nalgebra-glm/src/gtx/rotate_vector.rs index 30abc767..30101c30 100644 --- a/nalgebra-glm/src/gtx/rotate_vector.rs +++ b/nalgebra-glm/src/gtx/rotate_vector.rs @@ -3,7 +3,7 @@ use na::{RealField, Rotation3, Unit, UnitComplex}; use crate::aliases::{TMat4, TVec2, TVec3, TVec4}; /// Build the rotation matrix needed to align `normal` and `up`. -pub fn orientation(normal: &TVec3, up: &TVec3) -> TMat4 { +pub fn orientation(normal: &TVec3, up: &TVec3) -> TMat4 { if let Some(r) = Rotation3::rotation_between(normal, up) { r.to_homogeneous() } else { @@ -12,52 +12,52 @@ pub fn orientation(normal: &TVec3, up: &TVec3) -> TMat4 { } /// Rotate a two dimensional vector. -pub fn rotate_vec2(v: &TVec2, angle: N) -> TVec2 { +pub fn rotate_vec2(v: &TVec2, angle: T) -> TVec2 { UnitComplex::new(angle) * v } /// Rotate a three dimensional vector around an axis. -pub fn rotate_vec3(v: &TVec3, angle: N, normal: &TVec3) -> TVec3 { +pub fn rotate_vec3(v: &TVec3, angle: T, normal: &TVec3) -> TVec3 { Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle) * v } /// Rotate a thee dimensional vector in homogeneous coordinates around an axis. -pub fn rotate_vec4(v: &TVec4, angle: N, normal: &TVec3) -> TVec4 { +pub fn rotate_vec4(v: &TVec4, angle: T, normal: &TVec3) -> TVec4 { Rotation3::from_axis_angle(&Unit::new_normalize(*normal), angle).to_homogeneous() * v } /// Rotate a three dimensional vector around the `X` axis. -pub fn rotate_x_vec3(v: &TVec3, angle: N) -> TVec3 { +pub fn rotate_x_vec3(v: &TVec3, angle: T) -> TVec3 { Rotation3::from_axis_angle(&TVec3::x_axis(), angle) * v } /// Rotate a three dimensional vector in homogeneous coordinates around the `X` axis. -pub fn rotate_x_vec4(v: &TVec4, angle: N) -> TVec4 { +pub fn rotate_x_vec4(v: &TVec4, angle: T) -> TVec4 { Rotation3::from_axis_angle(&TVec3::x_axis(), angle).to_homogeneous() * v } /// Rotate a three dimensional vector around the `Y` axis. -pub fn rotate_y_vec3(v: &TVec3, angle: N) -> TVec3 { +pub fn rotate_y_vec3(v: &TVec3, angle: T) -> TVec3 { Rotation3::from_axis_angle(&TVec3::y_axis(), angle) * v } /// Rotate a three dimensional vector in homogeneous coordinates around the `Y` axis. -pub fn rotate_y_vec4(v: &TVec4, angle: N) -> TVec4 { +pub fn rotate_y_vec4(v: &TVec4, angle: T) -> TVec4 { Rotation3::from_axis_angle(&TVec3::y_axis(), angle).to_homogeneous() * v } /// Rotate a three dimensional vector around the `Z` axis. -pub fn rotate_z_vec3(v: &TVec3, angle: N) -> TVec3 { +pub fn rotate_z_vec3(v: &TVec3, angle: T) -> TVec3 { Rotation3::from_axis_angle(&TVec3::z_axis(), angle) * v } /// Rotate a three dimensional vector in homogeneous coordinates around the `Z` axis. -pub fn rotate_z_vec4(v: &TVec4, angle: N) -> TVec4 { +pub fn rotate_z_vec4(v: &TVec4, angle: T) -> TVec4 { Rotation3::from_axis_angle(&TVec3::z_axis(), angle).to_homogeneous() * v } /// 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 { +pub fn slerp(x: &TVec3, y: &TVec3, a: T) -> TVec3 { Unit::new_unchecked(*x) .slerp(&Unit::new_unchecked(*y), a) .into_inner() diff --git a/nalgebra-glm/src/gtx/transform.rs b/nalgebra-glm/src/gtx/transform.rs index 17a853c1..b1f14952 100644 --- a/nalgebra-glm/src/gtx/transform.rs +++ b/nalgebra-glm/src/gtx/transform.rs @@ -12,7 +12,7 @@ use crate::traits::Number; /// * [`rotation2d`](fn.rotation2d.html) /// * [`scaling2d`](fn.scaling2d.html) /// * [`translation2d`](fn.translation2d.html) -pub fn rotation(angle: N, v: &TVec3) -> TMat4 { +pub fn rotation(angle: T, v: &TVec3) -> TMat4 { Rotation3::from_axis_angle(&Unit::new_normalize(*v), angle).to_homogeneous() } @@ -25,7 +25,7 @@ pub fn rotation(angle: N, v: &TVec3) -> TMat4 { /// * [`rotation2d`](fn.rotation2d.html) /// * [`scaling2d`](fn.scaling2d.html) /// * [`translation2d`](fn.translation2d.html) -pub fn scaling(v: &TVec3) -> TMat4 { +pub fn scaling(v: &TVec3) -> TMat4 { TMat4::new_nonuniform_scaling(v) } @@ -38,7 +38,7 @@ pub fn scaling(v: &TVec3) -> TMat4 { /// * [`rotation2d`](fn.rotation2d.html) /// * [`scaling2d`](fn.scaling2d.html) /// * [`translation2d`](fn.translation2d.html) -pub fn translation(v: &TVec3) -> TMat4 { +pub fn translation(v: &TVec3) -> TMat4 { TMat4::new_translation(v) } @@ -51,7 +51,7 @@ pub fn translation(v: &TVec3) -> TMat4 { /// * [`translation`](fn.translation.html) /// * [`scaling2d`](fn.scaling2d.html) /// * [`translation2d`](fn.translation2d.html) -pub fn rotation2d(angle: N) -> TMat3 { +pub fn rotation2d(angle: T) -> TMat3 { Rotation2::new(angle).to_homogeneous() } @@ -64,7 +64,7 @@ pub fn rotation2d(angle: N) -> TMat3 { /// * [`translation`](fn.translation.html) /// * [`rotation2d`](fn.rotation2d.html) /// * [`translation2d`](fn.translation2d.html) -pub fn scaling2d(v: &TVec2) -> TMat3 { +pub fn scaling2d(v: &TVec2) -> TMat3 { TMat3::new_nonuniform_scaling(v) } @@ -77,6 +77,6 @@ pub fn scaling2d(v: &TVec2) -> TMat3 { /// * [`translation`](fn.translation.html) /// * [`rotation2d`](fn.rotation2d.html) /// * [`scaling2d`](fn.scaling2d.html) -pub fn translation2d(v: &TVec2) -> TMat3 { +pub fn translation2d(v: &TVec2) -> TMat3 { TMat3::new_translation(v) } diff --git a/nalgebra-glm/src/gtx/transform2.rs b/nalgebra-glm/src/gtx/transform2.rs index eaa74acb..9fcf95c7 100644 --- a/nalgebra-glm/src/gtx/transform2.rs +++ b/nalgebra-glm/src/gtx/transform2.rs @@ -1,14 +1,12 @@ -use na::{U2, U3}; - use crate::aliases::{TMat3, TMat4, TVec2, TVec3}; use crate::traits::Number; /// Build planar projection matrix along normal axis and right-multiply it to `m`. -pub fn proj2d(m: &TMat3, normal: &TVec2) -> TMat3 { +pub fn proj2d(m: &TMat3, normal: &TVec2) -> TMat3 { let mut res = TMat3::identity(); { - let mut part = res.fixed_slice_mut::(0, 0); + let mut part = res.fixed_slice_mut::<2, 2>(0, 0); part -= normal * normal.transpose(); } @@ -16,11 +14,11 @@ pub fn proj2d(m: &TMat3, normal: &TVec2) -> TMat3 { } /// Build planar projection matrix along normal axis, and right-multiply it to `m`. -pub fn proj(m: &TMat4, normal: &TVec3) -> TMat4 { +pub fn proj(m: &TMat4, normal: &TVec3) -> TMat4 { let mut res = TMat4::identity(); { - let mut part = res.fixed_slice_mut::(0, 0); + let mut part = res.fixed_slice_mut::<3, 3>(0, 0); part -= normal * normal.transpose(); } @@ -28,33 +26,33 @@ pub fn proj(m: &TMat4, normal: &TVec3) -> TMat4 { } /// Builds a reflection matrix and right-multiply it to `m`. -pub fn reflect2d(m: &TMat3, normal: &TVec2) -> TMat3 { +pub fn reflect2d(m: &TMat3, normal: &TVec2) -> TMat3 { let mut res = TMat3::identity(); { - let mut part = res.fixed_slice_mut::(0, 0); - part -= (normal * N::from_f64(2.0).unwrap()) * normal.transpose(); + let mut part = res.fixed_slice_mut::<2, 2>(0, 0); + part -= (normal * T::from_f64(2.0).unwrap()) * normal.transpose(); } m * res } /// Builds a reflection matrix, and right-multiply it to `m`. -pub fn reflect(m: &TMat4, normal: &TVec3) -> TMat4 { +pub fn reflect(m: &TMat4, normal: &TVec3) -> TMat4 { let mut res = TMat4::identity(); { - let mut part = res.fixed_slice_mut::(0, 0); - part -= (normal * N::from_f64(2.0).unwrap()) * normal.transpose(); + let mut part = res.fixed_slice_mut::<3, 3>(0, 0); + part -= (normal * T::from_f64(2.0).unwrap()) * normal.transpose(); } m * res } /// Builds a scale-bias matrix. -pub fn scale_bias_matrix(scale: N, bias: N) -> TMat4 { - let _0 = N::zero(); - let _1 = N::one(); +pub fn scale_bias_matrix(scale: T, bias: T) -> TMat4 { + let _0 = T::zero(); + let _1 = T::one(); TMat4::new( scale, _0, _0, bias, _0, scale, _0, bias, _0, _0, scale, bias, _0, _0, _0, _1, @@ -62,50 +60,50 @@ pub fn scale_bias_matrix(scale: N, bias: N) -> TMat4 { } /// Builds a scale-bias matrix, and right-multiply it to `m`. -pub fn scale_bias(m: &TMat4, scale: N, bias: N) -> TMat4 { +pub fn scale_bias(m: &TMat4, scale: T, bias: T) -> TMat4 { m * scale_bias_matrix(scale, bias) } /// Transforms a matrix with a shearing on X axis. -pub fn shear2d_x(m: &TMat3, y: N) -> TMat3 { - let _0 = N::zero(); - let _1 = N::one(); +pub fn shear2d_x(m: &TMat3, y: T) -> TMat3 { + let _0 = T::zero(); + let _1 = T::one(); let shear = TMat3::new(_1, y, _0, _0, _1, _0, _0, _0, _1); m * shear } /// Transforms a matrix with a shearing on Y axis. -pub fn shear_x(m: &TMat4, y: N, z: N) -> TMat4 { - let _0 = N::zero(); - let _1 = N::one(); +pub fn shear_x(m: &TMat4, y: T, z: T) -> TMat4 { + let _0 = T::zero(); + let _1 = T::one(); let shear = TMat4::new(_1, _0, _0, _0, y, _1, _0, _0, z, _0, _1, _0, _0, _0, _0, _1); m * shear } /// Transforms a matrix with a shearing on Y axis. -pub fn shear2d_y(m: &TMat3, x: N) -> TMat3 { - let _0 = N::zero(); - let _1 = N::one(); +pub fn shear2d_y(m: &TMat3, x: T) -> TMat3 { + let _0 = T::zero(); + let _1 = T::one(); let shear = TMat3::new(_1, _0, _0, x, _1, _0, _0, _0, _1); m * shear } /// Transforms a matrix with a shearing on Y axis. -pub fn shear_y(m: &TMat4, x: N, z: N) -> TMat4 { - let _0 = N::zero(); - let _1 = N::one(); +pub fn shear_y(m: &TMat4, x: T, z: T) -> TMat4 { + let _0 = T::zero(); + let _1 = T::one(); let shear = TMat4::new(_1, x, _0, _0, _0, _1, _0, _0, _0, z, _1, _0, _0, _0, _0, _1); m * shear } /// Transforms a matrix with a shearing on Z axis. -pub fn shear_z(m: &TMat4, x: N, y: N) -> TMat4 { - let _0 = N::zero(); - let _1 = N::one(); +pub fn shear_z(m: &TMat4, x: T, y: T) -> TMat4 { + let _0 = T::zero(); + let _1 = T::one(); 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 0c7deb18..c320628e 100644 --- a/nalgebra-glm/src/gtx/transform2d.rs +++ b/nalgebra-glm/src/gtx/transform2d.rs @@ -12,7 +12,7 @@ use crate::traits::Number; /// * [`scaling2d`](fn.scaling2d.html) /// * [`translate2d`](fn.translate2d.html) /// * [`translation2d`](fn.translation2d.html) -pub fn rotate2d(m: &TMat3, angle: N) -> TMat3 { +pub fn rotate2d(m: &TMat3, angle: T) -> TMat3 { m * UnitComplex::new(angle).to_homogeneous() } @@ -25,7 +25,7 @@ pub fn rotate2d(m: &TMat3, angle: N) -> TMat3 { /// * [`scaling2d`](fn.scaling2d.html) /// * [`translate2d`](fn.translate2d.html) /// * [`translation2d`](fn.translation2d.html) -pub fn scale2d(m: &TMat3, v: &TVec2) -> TMat3 { +pub fn scale2d(m: &TMat3, v: &TVec2) -> TMat3 { m.prepend_nonuniform_scaling(v) } @@ -38,6 +38,6 @@ pub fn scale2d(m: &TMat3, v: &TVec2) -> TMat3 { /// * [`scale2d`](fn.scale2d.html) /// * [`scaling2d`](fn.scaling2d.html) /// * [`translation2d`](fn.translation2d.html) -pub fn translate2d(m: &TMat3, v: &TVec2) -> TMat3 { +pub fn translate2d(m: &TMat3, v: &TVec2) -> TMat3 { m.prepend_translation(v) } diff --git a/nalgebra-glm/src/gtx/vector_angle.rs b/nalgebra-glm/src/gtx/vector_angle.rs index e71abafb..5b61932f 100644 --- a/nalgebra-glm/src/gtx/vector_angle.rs +++ b/nalgebra-glm/src/gtx/vector_angle.rs @@ -1,20 +1,16 @@ -use na::{DefaultAllocator, RealField}; +use na::RealField; use crate::aliases::TVec; -use crate::traits::{Alloc, Dimension}; /// The angle between two vectors. -pub fn angle(x: &TVec, y: &TVec) -> N -where - DefaultAllocator: Alloc, -{ +pub fn angle(x: &TVec, y: &TVec) -> T { x.angle(y) } -//pub fn oriented_angle(x: &TVec2, y: &TVec2) -> N { +//pub fn oriented_angle(x: &TVec2, y: &TVec2) -> T { // unimplemented!() //} // -//pub fn oriented_angle_ref(x: &TVec3, y: &TVec3, refv: &TVec3) -> N { +//pub fn oriented_angle_ref(x: &TVec3, y: &TVec3, refv: &TVec3) -> T { // unimplemented!() //} diff --git a/nalgebra-glm/src/gtx/vector_query.rs b/nalgebra-glm/src/gtx/vector_query.rs index 687d9530..1e739e24 100644 --- a/nalgebra-glm/src/gtx/vector_query.rs +++ b/nalgebra-glm/src/gtx/vector_query.rs @@ -1,14 +1,14 @@ -use na::{DefaultAllocator, RealField}; +use na::RealField; use crate::aliases::{TVec, TVec2, TVec3}; -use crate::traits::{Alloc, Dimension, Number}; +use crate::traits::Number; /// Returns `true` if two vectors are collinear (up to an epsilon). /// /// # See also: /// /// * [`are_collinear2d`](fn.are_collinear2d.html) -pub fn are_collinear(v0: &TVec3, v1: &TVec3, epsilon: N) -> bool { +pub fn are_collinear(v0: &TVec3, v1: &TVec3, epsilon: T) -> bool { is_null(&v0.cross(v1), epsilon) } @@ -17,43 +17,34 @@ pub fn are_collinear(v0: &TVec3, v1: &TVec3, epsilon: N) -> boo /// # See also: /// /// * [`are_collinear`](fn.are_collinear.html) -pub fn are_collinear2d(v0: &TVec2, v1: &TVec2, epsilon: N) -> bool { - abs_diff_eq!(v0.perp(v1), N::zero(), epsilon = epsilon) +pub fn are_collinear2d(v0: &TVec2, v1: &TVec2, epsilon: T) -> bool { + abs_diff_eq!(v0.perp(v1), T::zero(), epsilon = epsilon) } /// 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, -{ - abs_diff_eq!(v0.dot(v1), N::zero(), epsilon = epsilon) +pub fn are_orthogonal( + v0: &TVec, + v1: &TVec, + epsilon: T, +) -> bool { + abs_diff_eq!(v0.dot(v1), T::zero(), epsilon = epsilon) } -//pub fn are_orthonormal(v0: &TVec, v1: &TVec, epsilon: N) -> bool -// where DefaultAllocator: Alloc { +//pub fn are_orthonormal(v0: &TVec, v1: &TVec, epsilon: T) -> bool { // unimplemented!() //} /// 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, -{ - v.map(|x| abs_diff_eq!(x, N::zero(), epsilon = epsilon)) +pub fn is_comp_null(v: &TVec, epsilon: T) -> TVec { + v.map(|x| abs_diff_eq!(x, T::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, -{ - abs_diff_eq!(v.norm_squared(), N::one(), epsilon = epsilon * epsilon) +pub fn is_normalized(v: &TVec, epsilon: T) -> bool { + abs_diff_eq!(v.norm_squared(), T::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, -{ - abs_diff_eq!(*v, TVec::::zeros(), epsilon = epsilon) +pub fn is_null(v: &TVec, epsilon: T) -> bool { + abs_diff_eq!(*v, TVec::::zeros(), epsilon = epsilon) } diff --git a/nalgebra-glm/src/integer.rs b/nalgebra-glm/src/integer.rs index 198d737a..93aa4847 100644 --- a/nalgebra-glm/src/integer.rs +++ b/nalgebra-glm/src/integer.rs @@ -1,29 +1,46 @@ -use na::{Scalar, RealField, U3, DefaultAllocator}; +use na::{DefaultAllocator, RealField, Scalar, U3}; -use crate::traits::{Number, Alloc, Dimension}; use crate::aliases::TVec; +use crate::traits::{Alloc, Dimension, Number}; pub fn bitCount(v: T) -> i32 { unimplemented!() } -pub fn bitCount2(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn bitCount2(v: &TVec) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } -pub fn bitfieldExtract(Value: &TVec, Offset: i32, Bits: i32) -> TVec - where DefaultAllocator: Alloc { +pub fn bitfieldExtract( + Value: &TVec, + Offset: i32, + Bits: i32, +) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } -pub fn bitfieldInsert(Base: &TVec, Insert: &TVec, Offset: i32, Bits: i32) -> TVec - where DefaultAllocator: Alloc { +pub fn bitfieldInsert( + Base: &TVec, + Insert: &TVec, + Offset: i32, + Bits: i32, +) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } -pub fn bitfieldReverse(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn bitfieldReverse(v: &TVec) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } @@ -31,8 +48,10 @@ pub fn findLSB(x: IU) -> u32 { unimplemented!() } -pub fn findLSB2(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn findLSB2(v: &TVec) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } @@ -40,27 +59,53 @@ pub fn findMSB(x: IU) -> i32 { unimplemented!() } -pub fn findMSB2(v: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn findMSB2(v: &TVec) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } -pub fn imulExtended(x: &TVec, y: &TVec, msb: &TVec, lsb: &TVec) - where DefaultAllocator: Alloc { +pub fn imulExtended( + x: &TVec, + y: &TVec, + msb: &TVec, + lsb: &TVec, +) where + DefaultAllocator: Alloc, +{ unimplemented!() } -pub fn uaddCarry(x: &TVec, y: &TVec, carry: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn uaddCarry( + x: &TVec, + y: &TVec, + carry: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } -pub fn umulExtended(x: &TVec, y: &TVec, msb: &TVec, lsb: &TVec) - where DefaultAllocator: Alloc { -unimplemented!() -} - -pub fn usubBorrow(x: &TVec, y: &TVec, borrow: &TVec) -> TVec - where DefaultAllocator: Alloc { +pub fn umulExtended( + x: &TVec, + y: &TVec, + msb: &TVec, + lsb: &TVec, +) where + DefaultAllocator: Alloc, +{ + unimplemented!() +} + +pub fn usubBorrow( + x: &TVec, + y: &TVec, + borrow: &TVec, +) -> TVec +where + DefaultAllocator: Alloc, +{ unimplemented!() } diff --git a/nalgebra-glm/src/lib.rs b/nalgebra-glm/src/lib.rs index e9c64160..df578a80 100644 --- a/nalgebra-glm/src/lib.rs +++ b/nalgebra-glm/src/lib.rs @@ -54,7 +54,7 @@ ### 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 `::new` constructor. For example [`Vec3::new(x, y, z)`](../nalgebra/base/type.OMatrix.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. @@ -119,7 +119,7 @@ extern crate approx; extern crate nalgebra as na; pub use crate::aliases::*; -pub use crate::traits::{Alloc, Dimension, Number}; +pub use crate::traits::Number; 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, diff --git a/nalgebra-glm/src/matrix.rs b/nalgebra-glm/src/matrix.rs index ea887cf2..23485247 100644 --- a/nalgebra-glm/src/matrix.rs +++ b/nalgebra-glm/src/matrix.rs @@ -1,52 +1,40 @@ -use na::{DefaultAllocator, RealField, Scalar}; +use na::{Const, DimMin, RealField, Scalar}; use crate::aliases::{TMat, TVec}; -use crate::traits::{Alloc, Dimension, Number}; +use crate::traits::Number; /// The determinant of the matrix `m`. -pub fn determinant(m: &TMat) -> N +pub fn determinant(m: &TMat) -> T where - DefaultAllocator: Alloc, + Const: DimMin, Output = Const>, { m.determinant() } /// The inverse of the matrix `m`. -pub fn inverse(m: &TMat) -> TMat -where - DefaultAllocator: Alloc, -{ +pub fn inverse(m: &TMat) -> TMat { m.clone() .try_inverse() - .unwrap_or_else(TMat::::zeros) + .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 { 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 { c * r.transpose() } /// The transpose of the matrix `m`. -pub fn transpose(x: &TMat) -> TMat -where - DefaultAllocator: Alloc, -{ +pub fn transpose(x: &TMat) -> TMat { x.transpose() } diff --git a/nalgebra-glm/src/packing.rs b/nalgebra-glm/src/packing.rs index 3273fb26..35352e94 100644 --- a/nalgebra-glm/src/packing.rs +++ b/nalgebra-glm/src/packing.rs @@ -1,52 +1,51 @@ use na::Scalar; -use crate::aliases::{Vec2, Vec4, UVec2}; +use crate::aliases::{UVec2, Vec2, Vec4}; - -pub fn packDouble2x32(v: &UVec2) -> f64 { +pub fn packDouble2x32(v: &UVec2) -> f64 { unimplemented!() } -pub fn packHalf2x16(v: &Vec2) -> u32 { +pub fn packHalf2x16(v: &Vec2) -> u32 { unimplemented!() } -pub fn packSnorm2x16(v: &Vec2) -> u32 { +pub fn packSnorm2x16(v: &Vec2) -> u32 { unimplemented!() } -pub fn packSnorm4x8(v: &Vec4) -> u32 { +pub fn packSnorm4x8(v: &Vec4) -> u32 { unimplemented!() } -pub fn packUnorm2x16(v: &Vec2) -> u32 { +pub fn packUnorm2x16(v: &Vec2) -> u32 { unimplemented!() } -pub fn packUnorm4x8(v: &Vec4) -> u32 { +pub fn packUnorm4x8(v: &Vec4) -> u32 { unimplemented!() } -pub fn unpackDouble2x32(v: f64) -> UVec2 { +pub fn unpackDouble2x32(v: f64) -> UVec2 { unimplemented!() } -pub fn unpackHalf2x16(v: u32) -> Vec2 { +pub fn unpackHalf2x16(v: u32) -> Vec2 { unimplemented!() } -pub fn unpackSnorm2x16(p: u32) -> Vec2 { +pub fn unpackSnorm2x16(p: u32) -> Vec2 { unimplemented!() } -pub fn unpackSnorm4x8(p: u32) -> Vec4 { +pub fn unpackSnorm4x8(p: u32) -> Vec4 { unimplemented!() } -pub fn unpackUnorm2x16(p: u32) -> Vec2 { +pub fn unpackUnorm2x16(p: u32) -> Vec2 { unimplemented!() } -pub fn unpackUnorm4x8(p: u32) -> Vec4 { +pub fn unpackUnorm4x8(p: u32) -> Vec4 { unimplemented!() } diff --git a/nalgebra-glm/src/traits.rs b/nalgebra-glm/src/traits.rs index 24d41083..04d192c9 100644 --- a/nalgebra-glm/src/traits.rs +++ b/nalgebra-glm/src/traits.rs @@ -1,15 +1,10 @@ use approx::AbsDiffEq; use num::{Bounded, FromPrimitive, Signed}; -use na::allocator::Allocator; -use na::{DimMin, DimName, Scalar, U1}; +use na::Scalar; use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub}; use std::cmp::PartialOrd; -/// 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 @@ -39,64 +34,3 @@ impl< > 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> -{ -} - -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> -{ -} diff --git a/nalgebra-glm/src/trigonometric.rs b/nalgebra-glm/src/trigonometric.rs index adf1a211..257218d3 100644 --- a/nalgebra-glm/src/trigonometric.rs +++ b/nalgebra-glm/src/trigonometric.rs @@ -1,124 +1,78 @@ -use na::{self, DefaultAllocator, RealField}; +use na::{self, RealField}; use crate::aliases::TVec; -use crate::traits::{Alloc, Dimension}; /// Component-wise arc-cosinus. -pub fn acos(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn acos(x: &TVec) -> TVec { x.map(|e| e.acos()) } /// Component-wise hyperbolic arc-cosinus. -pub fn acosh(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn acosh(x: &TVec) -> TVec { x.map(|e| e.acosh()) } /// Component-wise arc-sinus. -pub fn asin(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn asin(x: &TVec) -> TVec { x.map(|e| e.asin()) } /// Component-wise hyperbolic arc-sinus. -pub fn asinh(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn asinh(x: &TVec) -> TVec { x.map(|e| e.asinh()) } /// Component-wise arc-tangent of `y / x`. -pub fn atan2(y: &TVec, x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn atan2(y: &TVec, x: &TVec) -> TVec { y.zip_map(x, |y, x| y.atan2(x)) } /// Component-wise arc-tangent. -pub fn atan(y_over_x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn atan(y_over_x: &TVec) -> TVec { y_over_x.map(|e| e.atan()) } /// Component-wise hyperbolic arc-tangent. -pub fn atanh(x: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn atanh(x: &TVec) -> TVec { x.map(|e| e.atanh()) } /// Component-wise cosinus. -pub fn cos(angle: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn cos(angle: &TVec) -> TVec { angle.map(|e| e.cos()) } /// Component-wise hyperbolic cosinus. -pub fn cosh(angle: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn cosh(angle: &TVec) -> TVec { angle.map(|e| e.cosh()) } /// Component-wise conversion from radians to degrees. -pub fn degrees(radians: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ - radians.map(|e| e * na::convert(180.0) / N::pi()) +pub fn degrees(radians: &TVec) -> TVec { + radians.map(|e| e * na::convert(180.0) / T::pi()) } /// Component-wise conversion fro degrees to radians. -pub fn radians(degrees: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ - degrees.map(|e| e * N::pi() / na::convert(180.0)) +pub fn radians(degrees: &TVec) -> TVec { + degrees.map(|e| e * T::pi() / na::convert(180.0)) } /// Component-wise sinus. -pub fn sin(angle: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn sin(angle: &TVec) -> TVec { angle.map(|e| e.sin()) } /// Component-wise hyperbolic sinus. -pub fn sinh(angle: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn sinh(angle: &TVec) -> TVec { angle.map(|e| e.sinh()) } /// Component-wise tangent. -pub fn tan(angle: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn tan(angle: &TVec) -> TVec { angle.map(|e| e.tan()) } /// Component-wise hyperbolic tangent. -pub fn tanh(angle: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn tanh(angle: &TVec) -> TVec { angle.map(|e| e.tanh()) } diff --git a/nalgebra-glm/src/vector_relational.rs b/nalgebra-glm/src/vector_relational.rs index be17d247..b8b3fbd7 100644 --- a/nalgebra-glm/src/vector_relational.rs +++ b/nalgebra-glm/src/vector_relational.rs @@ -1,7 +1,5 @@ -use na::DefaultAllocator; - use crate::aliases::TVec; -use crate::traits::{Alloc, Dimension, Number}; +use crate::traits::Number; /// Checks that all the vector components are `true`. /// @@ -20,10 +18,7 @@ use crate::traits::{Alloc, Dimension, Number}; /// /// * [`any`](fn.any.html) /// * [`not`](fn.not.html) -pub fn all(v: &TVec) -> bool -where - DefaultAllocator: Alloc, -{ +pub fn all(v: &TVec) -> bool { v.iter().all(|x| *x) } @@ -47,10 +42,7 @@ where /// /// * [`all`](fn.all.html) /// * [`not`](fn.not.html) -pub fn any(v: &TVec) -> bool -where - DefaultAllocator: Alloc, -{ +pub fn any(v: &TVec) -> bool { v.iter().any(|x| *x) } @@ -73,10 +65,7 @@ where /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) -pub fn equal(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn equal(x: &TVec, y: &TVec) -> TVec { x.zip_map(y, |x, y| x == y) } @@ -99,10 +88,7 @@ where /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) -pub fn greater_than(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn greater_than(x: &TVec, y: &TVec) -> TVec { x.zip_map(y, |x, y| x > y) } @@ -125,10 +111,10 @@ where /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) -pub fn greater_than_equal(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn greater_than_equal( + x: &TVec, + y: &TVec, +) -> TVec { x.zip_map(y, |x, y| x >= y) } @@ -151,10 +137,7 @@ where /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) -pub fn less_than(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn less_than(x: &TVec, y: &TVec) -> TVec { x.zip_map(y, |x, y| x < y) } @@ -177,10 +160,7 @@ where /// * [`less_than`](fn.less_than.html) /// * [`not`](fn.not.html) /// * [`not_equal`](fn.not_equal.html) -pub fn less_than_equal(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn less_than_equal(x: &TVec, y: &TVec) -> TVec { x.zip_map(y, |x, y| x <= y) } @@ -204,10 +184,7 @@ where /// * [`less_than`](fn.less_than.html) /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not_equal`](fn.not_equal.html) -pub fn not(v: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn not(v: &TVec) -> TVec { v.map(|x| !x) } @@ -230,9 +207,6 @@ where /// * [`less_than`](fn.less_than.html) /// * [`less_than_equal`](fn.less_than_equal.html) /// * [`not`](fn.not.html) -pub fn not_equal(x: &TVec, y: &TVec) -> TVec -where - DefaultAllocator: Alloc, -{ +pub fn not_equal(x: &TVec, y: &TVec) -> TVec { x.zip_map(y, |x, y| x != y) } diff --git a/nalgebra-lapack/src/cholesky.rs b/nalgebra-lapack/src/cholesky.rs index 93bf2443..fbbf6fd4 100644 --- a/nalgebra-lapack/src/cholesky.rs +++ b/nalgebra-lapack/src/cholesky.rs @@ -7,7 +7,7 @@ use num_complex::Complex; use na::allocator::Allocator; use na::dimension::Dim; use na::storage::Storage; -use na::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar}; +use na::{DefaultAllocator, Matrix, OMatrix, Scalar}; use lapack; @@ -15,39 +15,39 @@ 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, + OMatrix: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator, - MatrixN: Deserialize<'de>")) + serde(bound(deserialize = "DefaultAllocator: Allocator, + OMatrix: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct Cholesky +pub struct Cholesky where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - l: MatrixN, + l: OMatrix, } -impl Copy for Cholesky +impl Copy for Cholesky where - DefaultAllocator: Allocator, - MatrixN: Copy, + DefaultAllocator: Allocator, + OMatrix: Copy, { } -impl Cholesky +impl Cholesky where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { /// Computes the cholesky decomposition of the given symmetric-definite-positive square /// matrix. /// /// Only the lower-triangular part of the input matrix is considered. #[inline] - pub fn new(mut m: MatrixN) -> Option { + pub fn new(mut m: OMatrix) -> Option { // TODO: check symmetry as well? assert!( m.is_square(), @@ -58,14 +58,14 @@ where let dim = m.nrows() as i32; let mut info = 0; - N::xpotrf(uplo, dim, m.as_mut_slice(), dim, &mut info); + T::xpotrf(uplo, dim, m.as_mut_slice(), dim, &mut info); lapack_check!(info); Some(Self { l: m }) } /// Retrieves the lower-triangular factor of the cholesky decomposition. - pub fn unpack(mut self) -> MatrixN { + pub fn unpack(mut self) -> OMatrix { self.l.fill_upper_triangle(Zero::zero(), 1); self.l } @@ -75,12 +75,12 @@ where /// /// This is an allocation-less version of `self.l()`. The values of the strict upper-triangular /// part are garbage and should be ignored by further computations. - pub fn unpack_dirty(self) -> MatrixN { + pub fn unpack_dirty(self) -> OMatrix { self.l } /// Retrieves the lower-triangular factor of the cholesky decomposition. - pub fn l(&self) -> MatrixN { + pub fn l(&self) -> OMatrix { let mut res = self.l.clone(); res.fill_upper_triangle(Zero::zero(), 1); res @@ -91,7 +91,7 @@ where /// /// This is an allocation-less version of `self.l()`. The values of the strict upper-triangular /// part are garbage and should be ignored by further computations. - pub fn l_dirty(&self) -> &MatrixN { + pub fn l_dirty(&self) -> &OMatrix { &self.l } @@ -99,11 +99,11 @@ where /// unknown to be determined. pub fn solve( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, { let mut res = b.clone_owned(); if self.solve_mut(&mut res) { @@ -115,9 +115,9 @@ 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 + pub fn solve_mut(&self, b: &mut OMatrix) -> bool where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let dim = self.l.nrows(); @@ -131,7 +131,7 @@ where let ldb = dim as i32; let mut info = 0; - N::xpotrs( + T::xpotrs( b'L', dim as i32, nrhs, @@ -145,11 +145,11 @@ where } /// Computes the inverse of the decomposed matrix. - pub fn inverse(mut self) -> Option> { + pub fn inverse(mut self) -> Option> { let dim = self.l.nrows(); let mut info = 0; - N::xpotri( + T::xpotri( b'L', dim as i32, self.l.as_mut_slice(), diff --git a/nalgebra-lapack/src/eigen.rs b/nalgebra-lapack/src/eigen.rs index 1aae842c..2a01ba54 100644 --- a/nalgebra-lapack/src/eigen.rs +++ b/nalgebra-lapack/src/eigen.rs @@ -10,7 +10,7 @@ use crate::ComplexHelper; use na::allocator::Allocator; use na::dimension::{Dim, U1}; use na::storage::Storage; -use na::{DefaultAllocator, Matrix, MatrixN, Scalar, VectorN}; +use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar}; use lapack; @@ -19,59 +19,59 @@ use lapack; #[cfg_attr( feature = "serde-serialize", serde( - bound(serialize = "DefaultAllocator: Allocator + Allocator, - VectorN: Serialize, - MatrixN: Serialize") + bound(serialize = "DefaultAllocator: Allocator + Allocator, + OVector: Serialize, + OMatrix: Serialize") ) )] #[cfg_attr( feature = "serde-serialize", serde( - bound(deserialize = "DefaultAllocator: Allocator + Allocator, - VectorN: Serialize, - MatrixN: Deserialize<'de>") + bound(deserialize = "DefaultAllocator: Allocator + Allocator, + OVector: Serialize, + OMatrix: Deserialize<'de>") ) )] #[derive(Clone, Debug)] -pub struct Eigen +pub struct Eigen where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// The eigenvalues of the decomposed matrix. - pub eigenvalues: VectorN, + pub eigenvalues: OVector, /// The (right) eigenvectors of the decomposed matrix. - pub eigenvectors: Option>, + pub eigenvectors: Option>, /// The left eigenvectors of the decomposed matrix. - pub left_eigenvectors: Option>, + pub left_eigenvectors: Option>, } -impl Copy for Eigen +impl Copy for Eigen where - DefaultAllocator: Allocator + Allocator, - VectorN: Copy, - MatrixN: Copy, + DefaultAllocator: Allocator + Allocator, + OVector: Copy, + OMatrix: Copy, { } -impl Eigen +impl Eigen where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// Computes the eigenvalues and eigenvectors of the square matrix `m`. /// /// If `eigenvectors` is `false` then, the eigenvectors are not computed explicitly. pub fn new( - mut m: MatrixN, + mut m: OMatrix, left_eigenvectors: bool, eigenvectors: bool, - ) -> Option> { + ) -> Option> { assert!( m.is_square(), "Unable to compute the eigenvalue decomposition of a non-square matrix." ); - let ljob = if left_eigenvectors { b'V' } else { b'N' }; - let rjob = if eigenvectors { b'V' } else { b'N' }; + let ljob = if left_eigenvectors { b'V' } else { b'T' }; + let rjob = if eigenvectors { b'V' } else { b'T' }; let (nrows, ncols) = m.data.shape(); let n = nrows.value(); @@ -83,10 +83,10 @@ where let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() }; let mut info = 0; - let mut placeholder1 = [N::zero()]; - let mut placeholder2 = [N::zero()]; + let mut placeholder1 = [T::zero()]; + let mut placeholder2 = [T::zero()]; - let lwork = N::xgeev_work_size( + let lwork = T::xgeev_work_size( ljob, rjob, n as i32, @@ -112,7 +112,7 @@ where let mut vr = unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() }; - N::xgeev( + T::xgeev( ljob, rjob, n as i32, @@ -142,7 +142,7 @@ where let mut vl = unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() }; - N::xgeev( + T::xgeev( ljob, rjob, n as i32, @@ -172,7 +172,7 @@ where let mut vr = unsafe { Matrix::new_uninitialized_generic(nrows, ncols).assume_init() }; - N::xgeev( + T::xgeev( ljob, rjob, n as i32, @@ -199,7 +199,7 @@ where } } (false, false) => { - N::xgeev( + T::xgeev( ljob, rjob, n as i32, @@ -233,9 +233,9 @@ where /// The complex eigenvalues of the given matrix. /// /// Panics if the eigenvalue computation does not converge. - pub fn complex_eigenvalues(mut m: MatrixN) -> VectorN, D> + pub fn complex_eigenvalues(mut m: OMatrix) -> OVector, D> where - DefaultAllocator: Allocator, D>, + DefaultAllocator: Allocator, D>, { assert!( m.is_square(), @@ -251,12 +251,12 @@ where let mut wi = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() }; let mut info = 0; - let mut placeholder1 = [N::zero()]; - let mut placeholder2 = [N::zero()]; + let mut placeholder1 = [T::zero()]; + let mut placeholder2 = [T::zero()]; - let lwork = N::xgeev_work_size( - b'N', - b'N', + let lwork = T::xgeev_work_size( + b'T', + b'T', n as i32, m.as_mut_slice(), lda, @@ -273,9 +273,9 @@ where let mut work = unsafe { crate::uninitialized_vec(lwork as usize) }; - N::xgeev( - b'N', - b'N', + T::xgeev( + b'T', + b'T', n as i32, m.as_mut_slice(), lda, @@ -302,8 +302,8 @@ where /// The determinant of the decomposed matrix. #[inline] - pub fn determinant(&self) -> N { - let mut det = N::one(); + pub fn determinant(&self) -> T { + let mut det = T::one(); for e in self.eigenvalues.iter() { det *= *e; } diff --git a/nalgebra-lapack/src/hessenberg.rs b/nalgebra-lapack/src/hessenberg.rs index ed456ecb..8bb9d69d 100644 --- a/nalgebra-lapack/src/hessenberg.rs +++ b/nalgebra-lapack/src/hessenberg.rs @@ -5,7 +5,7 @@ use crate::ComplexHelper; use na::allocator::Allocator; use na::dimension::{DimDiff, DimSub, U1}; use na::storage::Storage; -use na::{DefaultAllocator, Matrix, MatrixN, Scalar, VectorN}; +use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar}; use lapack; @@ -13,41 +13,41 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "DefaultAllocator: Allocator + - Allocator>, - MatrixN: Serialize, - VectorN>: Serialize")) + serde(bound(serialize = "DefaultAllocator: Allocator + + Allocator>, + OMatrix: Serialize, + OVector>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator + - Allocator>, - MatrixN: Deserialize<'de>, - VectorN>: Deserialize<'de>")) + serde(bound(deserialize = "DefaultAllocator: Allocator + + Allocator>, + OMatrix: Deserialize<'de>, + OVector>: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct Hessenberg> +pub struct Hessenberg> where - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { - h: MatrixN, - tau: VectorN>, + h: OMatrix, + tau: OVector>, } -impl> Copy for Hessenberg +impl> Copy for Hessenberg where - DefaultAllocator: Allocator + Allocator>, - MatrixN: Copy, - VectorN>: Copy, + DefaultAllocator: Allocator + Allocator>, + OMatrix: Copy, + OVector>: Copy, { } -impl> Hessenberg +impl> Hessenberg where - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { /// Computes the hessenberg decomposition of the matrix `m`. - pub fn new(mut m: MatrixN) -> Self { + pub fn new(mut m: OMatrix) -> Self { let nrows = m.data.shape().0; let n = nrows.value() as i32; @@ -64,12 +64,12 @@ where let mut info = 0; let lwork = - N::xgehrd_work_size(n, 1, n, m.as_mut_slice(), n, tau.as_mut_slice(), &mut info); + T::xgehrd_work_size(n, 1, n, m.as_mut_slice(), n, tau.as_mut_slice(), &mut info); let mut work = unsafe { crate::uninitialized_vec(lwork as usize) }; lapack_panic!(info); - N::xgehrd( + T::xgehrd( n, 1, n, @@ -87,36 +87,36 @@ where /// Computes the hessenberg matrix of this decomposition. #[inline] - pub fn h(&self) -> MatrixN { + pub fn h(&self) -> OMatrix { let mut h = self.h.clone_owned(); - h.fill_lower_triangle(N::zero(), 2); + h.fill_lower_triangle(T::zero(), 2); h } } -impl> Hessenberg +impl> Hessenberg where - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { /// Computes the matrices `(Q, H)` of this decomposition. #[inline] - pub fn unpack(self) -> (MatrixN, MatrixN) { + pub fn unpack(self) -> (OMatrix, OMatrix) { (self.q(), self.h()) } /// Computes the unitary matrix `Q` of this decomposition. #[inline] - pub fn q(&self) -> MatrixN { + pub fn q(&self) -> OMatrix { let n = self.h.nrows() as i32; let mut q = self.h.clone_owned(); let mut info = 0; let lwork = - N::xorghr_work_size(n, 1, n, q.as_mut_slice(), n, self.tau.as_slice(), &mut info); - let mut work = vec![N::zero(); lwork as usize]; + T::xorghr_work_size(n, 1, n, q.as_mut_slice(), n, self.tau.as_slice(), &mut info); + let mut work = vec![T::zero(); lwork as usize]; - N::xorghr( + T::xorghr( n, 1, n, diff --git a/nalgebra-lapack/src/lu.rs b/nalgebra-lapack/src/lu.rs index 17245fb9..532c8212 100644 --- a/nalgebra-lapack/src/lu.rs +++ b/nalgebra-lapack/src/lu.rs @@ -5,7 +5,7 @@ use crate::ComplexHelper; use na::allocator::Allocator; use na::dimension::{Dim, DimMin, DimMinimum, U1}; use na::storage::Storage; -use na::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, VectorN}; +use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar}; use lapack; @@ -20,57 +20,57 @@ 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, + OMatrix: Serialize, PermutationSequence>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator + + serde(bound(deserialize = "DefaultAllocator: Allocator + Allocator>, - MatrixMN: Deserialize<'de>, + OMatrix: Deserialize<'de>, PermutationSequence>: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct LU, C: Dim> +pub struct LU, C: Dim> where - DefaultAllocator: Allocator> + Allocator, + DefaultAllocator: Allocator> + Allocator, { - lu: MatrixMN, - p: VectorN>, + lu: OMatrix, + p: OVector>, } -impl, C: Dim> Copy for LU +impl, C: Dim> Copy for LU where - DefaultAllocator: Allocator + Allocator>, - MatrixMN: Copy, - VectorN>: Copy, + DefaultAllocator: Allocator + Allocator>, + OMatrix: Copy, + OVector>: Copy, { } -impl LU +impl LU where - N: Zero + One, + T: Zero + One, R: DimMin, - DefaultAllocator: Allocator - + Allocator - + Allocator> - + Allocator, C> + DefaultAllocator: Allocator + + Allocator + + Allocator> + + Allocator, C> + Allocator>, { /// Computes the LU decomposition with partial (row) pivoting of `matrix`. - pub fn new(mut m: MatrixMN) -> Self { + pub fn new(mut m: OMatrix) -> Self { let (nrows, ncols) = m.data.shape(); let min_nrows_ncols = nrows.min(ncols); let nrows = nrows.value() as i32; let ncols = ncols.value() as i32; - let mut ipiv: VectorN = Matrix::zeros_generic(min_nrows_ncols, U1); + let mut ipiv: OVector = Matrix::zeros_generic(min_nrows_ncols, U1); let mut info = 0; - N::xgetrf( + T::xgetrf( nrows, ncols, m.as_mut_slice(), @@ -85,7 +85,7 @@ where /// Gets the lower-triangular matrix part of the decomposition. #[inline] - pub fn l(&self) -> MatrixMN> { + pub fn l(&self) -> OMatrix> { let (nrows, ncols) = self.lu.data.shape(); let mut res = self.lu.columns_generic(0, nrows.min(ncols)).into_owned(); @@ -97,7 +97,7 @@ where /// Gets the upper-triangular matrix part of the decomposition. #[inline] - pub fn u(&self) -> MatrixMN, C> { + pub fn u(&self) -> OMatrix, C> { let (nrows, ncols) = self.lu.data.shape(); let mut res = self.lu.rows_generic(0, nrows.min(ncols)).into_owned(); @@ -111,7 +111,7 @@ where /// Computing the permutation matrix explicitly is costly and usually not necessary. /// To permute rows of a matrix or vector, use the method `self.permute(...)` instead. #[inline] - pub fn p(&self) -> MatrixN { + pub fn p(&self) -> OMatrix { let (dim, _) = self.lu.data.shape(); let mut id = Matrix::identity_generic(dim, dim); self.permute(&mut id); @@ -124,19 +124,19 @@ where /// Gets the LAPACK permutation indices. #[inline] - pub fn permutation_indices(&self) -> &VectorN> { + pub fn permutation_indices(&self) -> &OVector> { &self.p } /// Applies the permutation matrix to a given matrix or vector in-place. #[inline] - pub fn permute(&self, rhs: &mut MatrixMN) + pub fn permute(&self, rhs: &mut OMatrix) where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let (nrows, ncols) = rhs.shape(); - N::xlaswp( + T::xlaswp( ncols as i32, rhs.as_mut_slice(), nrows as i32, @@ -147,9 +147,9 @@ where ); } - fn generic_solve_mut(&self, trans: u8, b: &mut MatrixMN) -> bool + fn generic_solve_mut(&self, trans: u8, b: &mut OMatrix) -> bool where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { let dim = self.lu.nrows(); @@ -167,7 +167,7 @@ where let ldb = dim as i32; let mut info = 0; - N::xgetrs( + T::xgetrs( trans, dim as i32, nrhs, @@ -184,14 +184,14 @@ where /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. pub fn solve( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, - DefaultAllocator: Allocator + Allocator, + S2: Storage, + DefaultAllocator: Allocator + Allocator, { let mut res = b.clone_owned(); - if self.generic_solve_mut(b'N', &mut res) { + if self.generic_solve_mut(b'T', &mut res) { Some(res) } else { None @@ -202,11 +202,11 @@ where /// determined. pub fn solve_transpose( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, - DefaultAllocator: Allocator + Allocator, + S2: Storage, + DefaultAllocator: Allocator + Allocator, { let mut res = b.clone_owned(); if self.generic_solve_mut(b'T', &mut res) { @@ -220,11 +220,11 @@ where /// be determined. pub fn solve_conjugate_transpose( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, - DefaultAllocator: Allocator + Allocator, + S2: Storage, + DefaultAllocator: Allocator + Allocator, { let mut res = b.clone_owned(); if self.generic_solve_mut(b'T', &mut res) { @@ -237,20 +237,20 @@ where /// Solves in-place the linear system `self * x = b`, where `x` is the unknown to be determined. /// /// Returns `false` if no solution was found (the decomposed matrix is singular). - pub fn solve_mut(&self, b: &mut MatrixMN) -> bool + pub fn solve_mut(&self, b: &mut OMatrix) -> bool where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { - self.generic_solve_mut(b'N', b) + self.generic_solve_mut(b'T', b) } /// Solves in-place the linear system `self.transpose() * x = b`, where `x` is the unknown to be /// determined. /// /// Returns `false` if no solution was found (the decomposed matrix is singular). - pub fn solve_transpose_mut(&self, b: &mut MatrixMN) -> bool + pub fn solve_transpose_mut(&self, b: &mut OMatrix) -> bool where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { self.generic_solve_mut(b'T', b) } @@ -259,25 +259,25 @@ where /// be determined. /// /// Returns `false` if no solution was found (the decomposed matrix is singular). - pub fn solve_adjoint_mut(&self, b: &mut MatrixMN) -> bool + pub fn solve_adjoint_mut(&self, b: &mut OMatrix) -> bool where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { self.generic_solve_mut(b'T', b) } } -impl LU +impl LU where - N: Zero + One, + T: Zero + One, D: DimMin, - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// Computes the inverse of the decomposed matrix. - pub fn inverse(mut self) -> Option> { + pub fn inverse(mut self) -> Option> { let dim = self.lu.nrows() as i32; let mut info = 0; - let lwork = N::xgetri_work_size( + let lwork = T::xgetri_work_size( dim, self.lu.as_mut_slice(), dim, @@ -288,7 +288,7 @@ where let mut work = unsafe { crate::uninitialized_vec(lwork as usize) }; - N::xgetri( + T::xgetri( dim, self.lu.as_mut_slice(), dim, diff --git a/nalgebra-lapack/src/qr.rs b/nalgebra-lapack/src/qr.rs index c9216135..050ba24f 100644 --- a/nalgebra-lapack/src/qr.rs +++ b/nalgebra-lapack/src/qr.rs @@ -8,7 +8,7 @@ use crate::ComplexHelper; use na::allocator::Allocator; use na::dimension::{Dim, DimMin, DimMinimum, U1}; use na::storage::Storage; -use na::{DefaultAllocator, Matrix, MatrixMN, Scalar, VectorN}; +use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar}; use lapack; @@ -16,44 +16,44 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "DefaultAllocator: Allocator + - Allocator>, - MatrixMN: Serialize, - VectorN>: Serialize")) + serde(bound(serialize = "DefaultAllocator: Allocator + + Allocator>, + OMatrix: Serialize, + OVector>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator + - Allocator>, - MatrixMN: Deserialize<'de>, - VectorN>: Deserialize<'de>")) + serde(bound(deserialize = "DefaultAllocator: Allocator + + Allocator>, + OMatrix: Deserialize<'de>, + OVector>: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct QR, C: Dim> +pub struct QR, C: Dim> where - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { - qr: MatrixMN, - tau: VectorN>, + qr: OMatrix, + tau: OVector>, } -impl, C: Dim> Copy for QR +impl, C: Dim> Copy for QR where - DefaultAllocator: Allocator + Allocator>, - MatrixMN: Copy, - VectorN>: Copy, + DefaultAllocator: Allocator + Allocator>, + OMatrix: Copy, + OVector>: Copy, { } -impl, C: Dim> QR +impl, C: Dim> QR where - DefaultAllocator: Allocator - + Allocator> - + Allocator, C> - + Allocator>, + DefaultAllocator: Allocator + + Allocator> + + Allocator, C> + + Allocator>, { /// Computes the QR decomposition of the matrix `m`. - pub fn new(mut m: MatrixMN) -> Self { + pub fn new(mut m: OMatrix) -> Self { let (nrows, ncols) = m.data.shape(); let mut info = 0; @@ -64,7 +64,7 @@ where return Self { qr: m, tau: tau }; } - let lwork = N::xgeqrf_work_size( + let lwork = T::xgeqrf_work_size( nrows.value() as i32, ncols.value() as i32, m.as_mut_slice(), @@ -75,7 +75,7 @@ where let mut work = unsafe { crate::uninitialized_vec(lwork as usize) }; - N::xgeqrf( + T::xgeqrf( nrows.value() as i32, ncols.value() as i32, m.as_mut_slice(), @@ -91,37 +91,37 @@ where /// Retrieves the upper trapezoidal submatrix `R` of this decomposition. #[inline] - pub fn r(&self) -> MatrixMN, C> { + pub fn r(&self) -> OMatrix, C> { let (nrows, ncols) = self.qr.data.shape(); self.qr.rows_generic(0, nrows.min(ncols)).upper_triangle() } } -impl, C: Dim> QR +impl, C: Dim> QR where - DefaultAllocator: Allocator - + Allocator> - + Allocator, C> - + Allocator>, + DefaultAllocator: Allocator + + Allocator> + + Allocator, C> + + Allocator>, { /// Retrieves the matrices `(Q, R)` of this decompositions. pub fn unpack( self, ) -> ( - MatrixMN>, - MatrixMN, C>, + OMatrix>, + OMatrix, C>, ) { (self.q(), self.r()) } /// Computes the orthogonal matrix `Q` of this decomposition. #[inline] - pub fn q(&self) -> MatrixMN> { + pub fn q(&self) -> OMatrix> { let (nrows, ncols) = self.qr.data.shape(); let min_nrows_ncols = nrows.min(ncols); if min_nrows_ncols.value() == 0 { - return MatrixMN::from_element_generic(nrows, min_nrows_ncols, N::zero()); + return OMatrix::from_element_generic(nrows, min_nrows_ncols, T::zero()); } let mut q = self @@ -132,7 +132,7 @@ where let mut info = 0; let nrows = nrows.value() as i32; - let lwork = N::xorgqr_work_size( + let lwork = T::xorgqr_work_size( nrows, min_nrows_ncols.value() as i32, self.tau.len() as i32, @@ -142,9 +142,9 @@ where &mut info, ); - let mut work = vec![N::zero(); lwork as usize]; + let mut work = vec![T::zero(); lwork as usize]; - N::xorgqr( + T::xorgqr( nrows, min_nrows_ncols.value() as i32, self.tau.len() as i32, diff --git a/nalgebra-lapack/src/schur.rs b/nalgebra-lapack/src/schur.rs index 0480f73f..340e7e31 100644 --- a/nalgebra-lapack/src/schur.rs +++ b/nalgebra-lapack/src/schur.rs @@ -10,7 +10,7 @@ use crate::ComplexHelper; use na::allocator::Allocator; use na::dimension::{Dim, U1}; use na::storage::Storage; -use na::{DefaultAllocator, Matrix, MatrixN, Scalar, VectorN}; +use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar}; use lapack; @@ -19,53 +19,53 @@ use lapack; #[cfg_attr( feature = "serde-serialize", serde( - bound(serialize = "DefaultAllocator: Allocator + Allocator, - VectorN: Serialize, - MatrixN: Serialize") + bound(serialize = "DefaultAllocator: Allocator + Allocator, + OVector: Serialize, + OMatrix: Serialize") ) )] #[cfg_attr( feature = "serde-serialize", serde( - bound(deserialize = "DefaultAllocator: Allocator + Allocator, - VectorN: Serialize, - MatrixN: Deserialize<'de>") + bound(deserialize = "DefaultAllocator: Allocator + Allocator, + OVector: Serialize, + OMatrix: Deserialize<'de>") ) )] #[derive(Clone, Debug)] -pub struct Schur +pub struct Schur where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { - re: VectorN, - im: VectorN, - t: MatrixN, - q: MatrixN, + re: OVector, + im: OVector, + t: OMatrix, + q: OMatrix, } -impl Copy for Schur +impl Copy for Schur where - DefaultAllocator: Allocator + Allocator, - MatrixN: Copy, - VectorN: Copy, + DefaultAllocator: Allocator + Allocator, + OMatrix: Copy, + OVector: Copy, { } -impl Schur +impl Schur where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// Computes the eigenvalues and real Schur form of the matrix `m`. /// /// Panics if the method did not converge. - pub fn new(m: MatrixN) -> Self { + pub fn new(m: OMatrix) -> Self { Self::try_new(m).expect("Schur decomposition: convergence failed.") } /// Computes the eigenvalues and real Schur form of the matrix `m`. /// /// Returns `None` if the method did not converge. - pub fn try_new(mut m: MatrixN) -> Option { + pub fn try_new(mut m: OMatrix) -> Option { assert!( m.is_square(), "Unable to compute the eigenvalue decomposition of a non-square matrix." @@ -85,9 +85,9 @@ where let mut bwork = [0i32]; let mut unused = 0; - let lwork = N::xgees_work_size( + let lwork = T::xgees_work_size( b'V', - b'N', + b'T', n as i32, m.as_mut_slice(), lda, @@ -103,9 +103,9 @@ where let mut work = unsafe { crate::uninitialized_vec(lwork as usize) }; - N::xgees( + T::xgees( b'V', - b'N', + b'T', n as i32, m.as_mut_slice(), lda, @@ -131,14 +131,14 @@ where /// Retrieves the unitary matrix `Q` and the upper-quasitriangular matrix `T` such that the /// decomposed matrix equals `Q * T * Q.transpose()`. - pub fn unpack(self) -> (MatrixN, MatrixN) { + pub fn unpack(self) -> (OMatrix, OMatrix) { (self.q, self.t) } /// Computes the real eigenvalues of the decomposed matrix. /// /// Return `None` if some eigenvalues are complex. - pub fn eigenvalues(&self) -> Option> { + pub fn eigenvalues(&self) -> Option> { if self.im.iter().all(|e| e.is_zero()) { Some(self.re.clone()) } else { @@ -147,12 +147,12 @@ where } /// Computes the complex eigenvalues of the decomposed matrix. - pub fn complex_eigenvalues(&self) -> VectorN, D> + pub fn complex_eigenvalues(&self) -> OVector, D> where - DefaultAllocator: Allocator, D>, + DefaultAllocator: Allocator, D>, { let mut out = - unsafe { VectorN::new_uninitialized_generic(self.t.data.shape().0, U1).assume_init() }; + unsafe { OVector::new_uninitialized_generic(self.t.data.shape().0, U1).assume_init() }; for i in 0..out.len() { out[i] = Complex::new(self.re[i], self.im[i]) diff --git a/nalgebra-lapack/src/svd.rs b/nalgebra-lapack/src/svd.rs index 70c7fd18..95269270 100644 --- a/nalgebra-lapack/src/svd.rs +++ b/nalgebra-lapack/src/svd.rs @@ -7,7 +7,7 @@ use std::cmp; use na::allocator::Allocator; use na::dimension::{Dim, DimMin, DimMinimum, U1}; use na::storage::Storage; -use na::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, VectorN}; +use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar}; use lapack; @@ -15,41 +15,41 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "DefaultAllocator: Allocator> + - Allocator + - Allocator, - MatrixN: Serialize, - MatrixN: Serialize, - VectorN>: Serialize")) + serde(bound(serialize = "DefaultAllocator: Allocator> + + Allocator + + Allocator, + OMatrix: Serialize, + OMatrix: Serialize, + OVector>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "DefaultAllocator: Allocator> + - Allocator + - Allocator, - MatrixN: Deserialize<'de>, - MatrixN: Deserialize<'de>, - VectorN>: Deserialize<'de>")) + serde(bound(serialize = "DefaultAllocator: Allocator> + + Allocator + + Allocator, + OMatrix: Deserialize<'de>, + OMatrix: Deserialize<'de>, + OVector>: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct SVD, C: Dim> +pub struct SVD, C: Dim> where - DefaultAllocator: Allocator + Allocator> + Allocator, + DefaultAllocator: Allocator + Allocator> + Allocator, { /// The left-singular vectors `U` of this SVD. - pub u: MatrixN, // TODO: should be MatrixMN> + pub u: OMatrix, // TODO: should be OMatrix> /// The right-singular vectors `V^t` of this SVD. - pub vt: MatrixN, // TODO: should be MatrixMN, C> + pub vt: OMatrix, // TODO: should be OMatrix, C> /// The singular values of this SVD. - pub singular_values: VectorN>, + pub singular_values: OVector>, } -impl, C: Dim> Copy for SVD +impl, C: Dim> Copy for SVD where - DefaultAllocator: Allocator + Allocator + Allocator>, - MatrixMN: Copy, - MatrixMN: Copy, - VectorN>: Copy, + DefaultAllocator: Allocator + Allocator + Allocator>, + OMatrix: Copy, + OMatrix: Copy, + OVector>: Copy, { } @@ -63,19 +63,19 @@ where + Allocator, { /// Computes the SVD decomposition of `m`. - fn compute(m: MatrixMN) -> Option>; + fn compute(m: OMatrix) -> Option>; } -impl, R: DimMin, C: Dim> SVD +impl, R: DimMin, C: Dim> SVD where - DefaultAllocator: Allocator - + Allocator - + Allocator> - + Allocator, + DefaultAllocator: Allocator + + Allocator + + Allocator> + + Allocator, { /// Computes the Singular Value Decomposition of `matrix`. - pub fn new(m: MatrixMN) -> Option { - N::compute(m) + pub fn new(m: OMatrix) -> Option { + T::compute(m) } } @@ -88,7 +88,7 @@ macro_rules! svd_impl( Allocator<$t, C, C> + Allocator<$t, DimMinimum> { - fn compute(mut m: MatrixMN<$t, R, C>) -> Option> { + fn compute(mut m: OMatrix<$t, R, C>) -> Option> { let (nrows, ncols) = m.data.shape(); if nrows.value() == 0 || ncols.value() == 0 { @@ -150,12 +150,12 @@ macro_rules! svd_impl( /// Useful if some components (e.g. some singular values) of this decomposition have /// been manually changed by the user. #[inline] - pub fn recompose(self) -> MatrixMN<$t, R, C> { + pub fn recompose(self) -> OMatrix<$t, R, C> { let nrows = self.u.data.shape().0; let ncols = self.vt.data.shape().1; let min_nrows_ncols = nrows.min(ncols); - let mut res: MatrixMN<_, R, C> = Matrix::zeros_generic(nrows, ncols); + let mut res: OMatrix<_, R, C> = Matrix::zeros_generic(nrows, ncols); { let mut sres = res.generic_slice_mut((0, 0), (min_nrows_ncols, ncols)); @@ -175,12 +175,12 @@ macro_rules! svd_impl( /// /// All singular value below epsilon will be set to zero instead of being inverted. #[inline] - pub fn pseudo_inverse(&self, epsilon: $t) -> MatrixMN<$t, C, R> { + pub fn pseudo_inverse(&self, epsilon: $t) -> OMatrix<$t, C, R> { let nrows = self.u.data.shape().0; let ncols = self.vt.data.shape().1; let min_nrows_ncols = nrows.min(ncols); - let mut res: MatrixMN<_, C, R> = Matrix::zeros_generic(ncols, nrows); + let mut res: OMatrix<_, C, R> = Matrix::zeros_generic(ncols, nrows); { let mut sres = res.generic_slice_mut((0, 0), (min_nrows_ncols, nrows)); @@ -230,9 +230,9 @@ macro_rules! svd_complex_impl( ($name: ident, $t: ty, $lapack_func: path) => ( impl SVDScalar for Complex<$t> { fn compute(mut m: Matrix<$t, R, C, S>) -> Option> - Option<(MatrixN, R, S::Alloc>, - VectorN<$t, DimMinimum, S::Alloc>, - MatrixN, C, S::Alloc>)> + Option<(OMatrix, R, S::Alloc>, + OVector<$t, DimMinimum, S::Alloc>, + OMatrix, C, S::Alloc>)> where R: DimMin, S: ContiguousStorage, R, C>, S::Alloc: OwnedAllocator, R, C, S> + diff --git a/nalgebra-lapack/src/symmetric_eigen.rs b/nalgebra-lapack/src/symmetric_eigen.rs index c255058d..f0cdc950 100644 --- a/nalgebra-lapack/src/symmetric_eigen.rs +++ b/nalgebra-lapack/src/symmetric_eigen.rs @@ -10,7 +10,7 @@ use crate::ComplexHelper; use na::allocator::Allocator; use na::dimension::{Dim, U1}; use na::storage::Storage; -use na::{DefaultAllocator, Matrix, MatrixN, Scalar, VectorN}; +use na::{DefaultAllocator, Matrix, OMatrix, OVector, Scalar}; use lapack; @@ -18,47 +18,47 @@ use lapack; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "DefaultAllocator: Allocator + - Allocator, - VectorN: Serialize, - MatrixN: Serialize")) + serde(bound(serialize = "DefaultAllocator: Allocator + + Allocator, + OVector: Serialize, + OMatrix: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator + - Allocator, - VectorN: Deserialize<'de>, - MatrixN: Deserialize<'de>")) + serde(bound(deserialize = "DefaultAllocator: Allocator + + Allocator, + OVector: Deserialize<'de>, + OMatrix: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct SymmetricEigen +pub struct SymmetricEigen where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// The eigenvectors of the decomposed matrix. - pub eigenvectors: MatrixN, + pub eigenvectors: OMatrix, /// The unsorted eigenvalues of the decomposed matrix. - pub eigenvalues: VectorN, + pub eigenvalues: OVector, } -impl Copy for SymmetricEigen +impl Copy for SymmetricEigen where - DefaultAllocator: Allocator + Allocator, - MatrixN: Copy, - VectorN: Copy, + DefaultAllocator: Allocator + Allocator, + OMatrix: Copy, + OVector: Copy, { } -impl SymmetricEigen +impl SymmetricEigen where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// Computes the eigenvalues and eigenvectors of the symmetric matrix `m`. /// /// Only the lower-triangular part of `m` is read. If `eigenvectors` is `false` then, the /// eigenvectors are not computed explicitly. Panics if the method did not converge. - pub fn new(m: MatrixN) -> Self { + pub fn new(m: OMatrix) -> Self { let (vals, vecs) = Self::do_decompose(m, true).expect("SymmetricEigen: convergence failure."); Self { @@ -71,7 +71,7 @@ where /// /// Only the lower-triangular part of `m` is read. If `eigenvectors` is `false` then, the /// eigenvectors are not computed explicitly. Returns `None` if the method did not converge. - pub fn try_new(m: MatrixN) -> Option { + pub fn try_new(m: OMatrix) -> Option { Self::do_decompose(m, true).map(|(vals, vecs)| SymmetricEigen { eigenvalues: vals, eigenvectors: vecs.unwrap(), @@ -79,15 +79,15 @@ where } fn do_decompose( - mut m: MatrixN, + mut m: OMatrix, eigenvectors: bool, - ) -> Option<(VectorN, Option>)> { + ) -> Option<(OVector, Option>)> { assert!( m.is_square(), "Unable to compute the eigenvalue decomposition of a non-square matrix." ); - let jobz = if eigenvectors { b'V' } else { b'N' }; + let jobz = if eigenvectors { b'V' } else { b'T' }; let nrows = m.data.shape().0; let n = nrows.value(); @@ -97,12 +97,12 @@ where let mut values = unsafe { Matrix::new_uninitialized_generic(nrows, U1).assume_init() }; let mut info = 0; - let lwork = N::xsyev_work_size(jobz, b'L', n as i32, m.as_mut_slice(), lda, &mut info); + let lwork = T::xsyev_work_size(jobz, b'L', n as i32, m.as_mut_slice(), lda, &mut info); lapack_check!(info); let mut work = unsafe { crate::uninitialized_vec(lwork as usize) }; - N::xsyev( + T::xsyev( jobz, b'L', n as i32, @@ -122,7 +122,7 @@ where /// Computes only the eigenvalues of the input matrix. /// /// Panics if the method does not converge. - pub fn eigenvalues(m: MatrixN) -> VectorN { + pub fn eigenvalues(m: OMatrix) -> OVector { Self::do_decompose(m, false) .expect("SymmetricEigen eigenvalues: convergence failure.") .0 @@ -131,14 +131,14 @@ where /// Computes only the eigenvalues of the input matrix. /// /// Returns `None` if the method does not converge. - pub fn try_eigenvalues(m: MatrixN) -> Option> { + pub fn try_eigenvalues(m: OMatrix) -> Option> { Self::do_decompose(m, false).map(|res| res.0) } /// The determinant of the decomposed matrix. #[inline] - pub fn determinant(&self) -> N { - let mut det = N::one(); + pub fn determinant(&self) -> T { + let mut det = T::one(); for e in self.eigenvalues.iter() { det *= *e; } @@ -149,7 +149,7 @@ where /// Rebuild the original matrix. /// /// This is useful if some of the eigenvalues have been manually modified. - pub fn recompose(&self) -> MatrixN { + pub fn recompose(&self) -> OMatrix { let mut u_t = self.eigenvectors.clone(); for i in 0..self.eigenvalues.len() { let val = self.eigenvalues[i]; diff --git a/nalgebra-sparse/src/ops/impl_std_ops.rs b/nalgebra-sparse/src/ops/impl_std_ops.rs index 75645bed..590bd934 100644 --- a/nalgebra-sparse/src/ops/impl_std_ops.rs +++ b/nalgebra-sparse/src/ops/impl_std_ops.rs @@ -10,7 +10,7 @@ use nalgebra::allocator::Allocator; use nalgebra::base::storage::Storage; use nalgebra::constraint::{DimEq, ShapeConstraint}; use nalgebra::{ - ClosedAdd, ClosedDiv, ClosedMul, ClosedSub, DefaultAllocator, Dim, Dynamic, Matrix, MatrixMN, + ClosedAdd, ClosedDiv, ClosedMul, ClosedSub, DefaultAllocator, Dim, Dynamic, Matrix, OMatrix, Scalar, U1, }; use num_traits::{One, Zero}; @@ -274,7 +274,7 @@ macro_rules! impl_spmm_cs_dense { impl_spmm_cs_dense!(&'a $matrix_type_name, &'a Matrix, $spmm_fn, |lhs, rhs| { let (_, ncols) = rhs.data.shape(); let nrows = Dynamic::new(lhs.nrows()); - let mut result = MatrixMN::::zeros_generic(nrows, ncols); + let mut result = OMatrix::::zeros_generic(nrows, ncols); $spmm_fn(T::zero(), &mut result, T::one(), Op::NoOp(lhs), Op::NoOp(rhs)); result }); @@ -305,7 +305,7 @@ macro_rules! impl_spmm_cs_dense { DefaultAllocator: Allocator, // TODO: Is it possible to simplify these bounds? ShapeConstraint: - // Bounds so that we can turn MatrixMN into a DMatrixSliceMut + // Bounds so that we can turn OMatrix into a DMatrixSliceMut DimEq>::Buffer as Storage>::RStride> + DimEq + DimEq>::Buffer as Storage>::CStride> @@ -316,7 +316,7 @@ macro_rules! impl_spmm_cs_dense { { // We need the column dimension to be generic, so that if RHS is a vector, then // we also get a vector (and not a matrix) - type Output = MatrixMN; + type Output = OMatrix; fn mul(self, rhs: $dense_matrix_type) -> Self::Output { let $lhs = self; diff --git a/src/base/alias.rs b/src/base/alias.rs index fdfda45a..5d4ecdde 100644 --- a/src/base/alias.rs +++ b/src/base/alias.rs @@ -13,247 +13,248 @@ use crate::base::{Const, Matrix, Unit}; * * */ -/// A statically sized column-major matrix with `R` rows and `C` columns. + +/// An owned matrix column-major matrix with `R` rows and `C` columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -#[deprecated(note = "This matrix name contains a typo. Use MatrixMN instead.")] -pub type MatrixNM = Matrix>; +pub type OMatrix = Matrix>; + +/// An owned matrix column-major matrix with `R` rows and `C` columns. +/// +/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** +#[deprecated( + note = "use SMatrix for a statically-sized matrix using integer dimensions, or OMatrix for an owned matrix using types as dimensions." +)] +pub type MatrixMN = Matrix>; /// A statically sized column-major matrix with `R` rows and `C` columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixMN = Matrix>; -pub type CMatrixMN = - Matrix, Const, Owned, Const>>; - -/// A statically sized column-major square matrix with `D` rows and columns. -/// -/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixN = Matrix>; -pub type CMatrixN = Matrix, Const, Owned, Const>>; +pub type SMatrix = + Matrix, Const, Owned, Const>>; /// A dynamically sized column-major matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type DMatrix = Matrix>; +pub type DMatrix = Matrix>; /// A heap-allocated, column-major, matrix with a dynamic number of rows and 1 columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type MatrixXx1 = Matrix>; +pub type MatrixXx1 = Matrix>; /// A heap-allocated, column-major, matrix with a dynamic number of rows and 2 columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type MatrixXx2 = Matrix>; +pub type MatrixXx2 = Matrix>; /// A heap-allocated, column-major, matrix with a dynamic number of rows and 3 columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type MatrixXx3 = Matrix>; +pub type MatrixXx3 = Matrix>; /// A heap-allocated, column-major, matrix with a dynamic number of rows and 4 columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type MatrixXx4 = Matrix>; +pub type MatrixXx4 = Matrix>; /// A heap-allocated, column-major, matrix with a dynamic number of rows and 5 columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type MatrixXx5 = Matrix>; +pub type MatrixXx5 = Matrix>; /// A heap-allocated, column-major, matrix with a dynamic number of rows and 6 columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type MatrixXx6 = Matrix>; +pub type MatrixXx6 = Matrix>; /// A heap-allocated, row-major, matrix with 1 rows and a dynamic number of columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type Matrix1xX = Matrix>; +pub type Matrix1xX = Matrix>; /// A heap-allocated, row-major, matrix with 2 rows and a dynamic number of columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type Matrix2xX = Matrix>; +pub type Matrix2xX = Matrix>; /// A heap-allocated, row-major, matrix with 3 rows and a dynamic number of columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type Matrix3xX = Matrix>; +pub type Matrix3xX = Matrix>; /// A heap-allocated, row-major, matrix with 4 rows and a dynamic number of columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type Matrix4xX = Matrix>; +pub type Matrix4xX = Matrix>; /// A heap-allocated, row-major, matrix with 5 rows and a dynamic number of columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type Matrix5xX = Matrix>; +pub type Matrix5xX = Matrix>; /// A heap-allocated, row-major, matrix with 6 rows and a dynamic number of columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** #[cfg(any(feature = "std", feature = "alloc"))] -pub type Matrix6xX = Matrix>; +pub type Matrix6xX = Matrix>; /// A stack-allocated, column-major, 1x1 square matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix1 = Matrix>; +pub type Matrix1 = Matrix>; /// A stack-allocated, column-major, 2x2 square matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix2 = Matrix>; +pub type Matrix2 = Matrix>; /// A stack-allocated, column-major, 3x3 square matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix3 = Matrix>; +pub type Matrix3 = Matrix>; /// A stack-allocated, column-major, 4x4 square matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix4 = Matrix>; +pub type Matrix4 = Matrix>; /// A stack-allocated, column-major, 5x5 square matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix5 = Matrix>; +pub type Matrix5 = Matrix>; /// A stack-allocated, column-major, 6x6 square matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix6 = Matrix>; +pub type Matrix6 = Matrix>; /// A stack-allocated, column-major, 1x2 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix1x2 = Matrix>; +pub type Matrix1x2 = Matrix>; /// A stack-allocated, column-major, 1x3 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix1x3 = Matrix>; +pub type Matrix1x3 = Matrix>; /// A stack-allocated, column-major, 1x4 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix1x4 = Matrix>; +pub type Matrix1x4 = Matrix>; /// A stack-allocated, column-major, 1x5 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix1x5 = Matrix>; +pub type Matrix1x5 = Matrix>; /// A stack-allocated, column-major, 1x6 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix1x6 = Matrix>; +pub type Matrix1x6 = Matrix>; /// A stack-allocated, column-major, 2x3 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix2x3 = Matrix>; +pub type Matrix2x3 = Matrix>; /// A stack-allocated, column-major, 2x4 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix2x4 = Matrix>; +pub type Matrix2x4 = Matrix>; /// A stack-allocated, column-major, 2x5 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix2x5 = Matrix>; +pub type Matrix2x5 = Matrix>; /// A stack-allocated, column-major, 2x6 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix2x6 = Matrix>; +pub type Matrix2x6 = Matrix>; /// A stack-allocated, column-major, 3x4 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix3x4 = Matrix>; +pub type Matrix3x4 = Matrix>; /// A stack-allocated, column-major, 3x5 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix3x5 = Matrix>; +pub type Matrix3x5 = Matrix>; /// A stack-allocated, column-major, 3x6 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix3x6 = Matrix>; +pub type Matrix3x6 = Matrix>; /// A stack-allocated, column-major, 4x5 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix4x5 = Matrix>; +pub type Matrix4x5 = Matrix>; /// A stack-allocated, column-major, 4x6 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix4x6 = Matrix>; +pub type Matrix4x6 = Matrix>; /// A stack-allocated, column-major, 5x6 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix5x6 = Matrix>; +pub type Matrix5x6 = Matrix>; /// A stack-allocated, column-major, 2x1 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix2x1 = Matrix>; +pub type Matrix2x1 = Matrix>; /// A stack-allocated, column-major, 3x1 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix3x1 = Matrix>; +pub type Matrix3x1 = Matrix>; /// A stack-allocated, column-major, 4x1 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix4x1 = Matrix>; +pub type Matrix4x1 = Matrix>; /// A stack-allocated, column-major, 5x1 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix5x1 = Matrix>; +pub type Matrix5x1 = Matrix>; /// A stack-allocated, column-major, 6x1 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix6x1 = Matrix>; +pub type Matrix6x1 = Matrix>; /// A stack-allocated, column-major, 3x2 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix3x2 = Matrix>; +pub type Matrix3x2 = Matrix>; /// A stack-allocated, column-major, 4x2 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix4x2 = Matrix>; +pub type Matrix4x2 = Matrix>; /// A stack-allocated, column-major, 5x2 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix5x2 = Matrix>; +pub type Matrix5x2 = Matrix>; /// A stack-allocated, column-major, 6x2 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix6x2 = Matrix>; +pub type Matrix6x2 = Matrix>; /// A stack-allocated, column-major, 4x3 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix4x3 = Matrix>; +pub type Matrix4x3 = Matrix>; /// A stack-allocated, column-major, 5x3 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix5x3 = Matrix>; +pub type Matrix5x3 = Matrix>; /// A stack-allocated, column-major, 6x3 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix6x3 = Matrix>; +pub type Matrix6x3 = Matrix>; /// A stack-allocated, column-major, 5x4 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix5x4 = Matrix>; +pub type Matrix5x4 = Matrix>; /// A stack-allocated, column-major, 6x4 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix6x4 = Matrix>; +pub type Matrix6x4 = Matrix>; /// A stack-allocated, column-major, 6x5 matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type Matrix6x5 = Matrix>; +pub type Matrix6x5 = Matrix>; /* * @@ -264,24 +265,33 @@ pub type Matrix6x5 = Matrix>; */ /// A dynamically sized column vector. #[cfg(any(feature = "std", feature = "alloc"))] -pub type DVector = Matrix>; +pub type DVector = Matrix>; +/// An owned D-dimensional column vector. +pub type OVector = Matrix>; /// A statically sized D-dimensional column vector. -pub type VectorN = Matrix>; -pub type CVectorN = Matrix, U1, Owned, U1>>; +pub type SVector = Matrix, U1, Owned, U1>>; + +/// An owned matrix column-major matrix with `R` rows and `C` columns. +/// +/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** +#[deprecated( + note = "use SVector for a statically-sized matrix using integer dimensions, or OVector for an owned matrix using types as dimensions." +)] +pub type VectorN = Matrix>; /// A stack-allocated, 1-dimensional column vector. -pub type Vector1 = Matrix>; +pub type Vector1 = Matrix>; /// A stack-allocated, 2-dimensional column vector. -pub type Vector2 = Matrix>; +pub type Vector2 = Matrix>; /// A stack-allocated, 3-dimensional column vector. -pub type Vector3 = Matrix>; +pub type Vector3 = Matrix>; /// A stack-allocated, 4-dimensional column vector. -pub type Vector4 = Matrix>; +pub type Vector4 = Matrix>; /// A stack-allocated, 5-dimensional column vector. -pub type Vector5 = Matrix>; +pub type Vector5 = Matrix>; /// A stack-allocated, 6-dimensional column vector. -pub type Vector6 = Matrix>; +pub type Vector6 = Matrix>; /* * @@ -292,23 +302,26 @@ pub type Vector6 = Matrix>; */ /// A dynamically sized row vector. #[cfg(any(feature = "std", feature = "alloc"))] -pub type RowDVector = Matrix>; +pub type RowDVector = Matrix>; + +/// An owned D-dimensional row vector. +pub type RowOVector = Matrix>; /// A statically sized D-dimensional row vector. -pub type RowVectorN = Matrix>; +pub type RowSVector = Matrix, Owned>>; /// A stack-allocated, 1-dimensional row vector. -pub type RowVector1 = Matrix>; +pub type RowVector1 = Matrix>; /// A stack-allocated, 2-dimensional row vector. -pub type RowVector2 = Matrix>; +pub type RowVector2 = Matrix>; /// A stack-allocated, 3-dimensional row vector. -pub type RowVector3 = Matrix>; +pub type RowVector3 = Matrix>; /// A stack-allocated, 4-dimensional row vector. -pub type RowVector4 = Matrix>; +pub type RowVector4 = Matrix>; /// A stack-allocated, 5-dimensional row vector. -pub type RowVector5 = Matrix>; +pub type RowVector5 = Matrix>; /// A stack-allocated, 6-dimensional row vector. -pub type RowVector6 = Matrix>; +pub type RowVector6 = Matrix>; /* * @@ -318,14 +331,14 @@ pub type RowVector6 = Matrix>; * */ /// A stack-allocated, 1-dimensional unit vector. -pub type UnitVector1 = Unit>>; +pub type UnitVector1 = Unit>>; /// A stack-allocated, 2-dimensional unit vector. -pub type UnitVector2 = Unit>>; +pub type UnitVector2 = Unit>>; /// A stack-allocated, 3-dimensional unit vector. -pub type UnitVector3 = Unit>>; +pub type UnitVector3 = Unit>>; /// A stack-allocated, 4-dimensional unit vector. -pub type UnitVector4 = Unit>>; +pub type UnitVector4 = Unit>>; /// A stack-allocated, 5-dimensional unit vector. -pub type UnitVector5 = Unit>>; +pub type UnitVector5 = Unit>>; /// A stack-allocated, 6-dimensional unit vector. -pub type UnitVector6 = Unit>>; +pub type UnitVector6 = Unit>>; diff --git a/src/base/alias_slice.rs b/src/base/alias_slice.rs index d919fef9..929d2f03 100644 --- a/src/base/alias_slice.rs +++ b/src/base/alias_slice.rs @@ -1,6 +1,6 @@ use crate::base::dimension::{Dynamic, U1, U2, U3, U4, U5, U6}; use crate::base::matrix_slice::{SliceStorage, SliceStorageMut}; -use crate::base::Matrix; +use crate::base::{Const, Matrix}; /* * @@ -9,287 +9,290 @@ use crate::base::Matrix; * * */ -/// A column-major matrix slice with `R` rows and `C` columns. +// NOTE: we can't provide defaults for the strides because it's not supported yet by min_const_generics. +/// A column-major matrix slice with dimensions known at compile-time. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMN<'a, N, R, C, RStride = U1, CStride = R> = - Matrix>; - -/// A column-major matrix slice with `D` rows and columns. -/// -/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceN<'a, N, D, RStride = U1, CStride = D> = - Matrix>; +pub type SMatrixSlice<'a, T, const R: usize, const C: usize> = + Matrix, Const, SliceStorage<'a, T, Const, Const, Const<1>, Const>>; /// A column-major matrix slice dynamic numbers of rows and columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type DMatrixSlice<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type DMatrixSlice<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A column-major 1x1 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice1<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSlice1<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major 2x2 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice2<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSlice2<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major 3x3 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice3<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSlice3<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major 4x4 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice4<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSlice4<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major 5x5 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice5<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSlice5<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major 6x6 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice6<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSlice6<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major 1x2 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice1x2<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSlice1x2<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major 1x3 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice1x3<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSlice1x3<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major 1x4 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice1x4<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSlice1x4<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major 1x5 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice1x5<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSlice1x5<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major 1x6 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice1x6<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSlice1x6<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major 2x1 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice2x1<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSlice2x1<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major 2x3 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice2x3<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSlice2x3<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major 2x4 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice2x4<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSlice2x4<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major 2x5 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice2x5<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSlice2x5<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major 2x6 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice2x6<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSlice2x6<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major 3x1 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice3x1<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSlice3x1<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major 3x2 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice3x2<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSlice3x2<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major 3x4 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice3x4<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSlice3x4<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major 3x5 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice3x5<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSlice3x5<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major 3x6 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice3x6<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSlice3x6<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major 4x1 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice4x1<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSlice4x1<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major 4x2 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice4x2<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSlice4x2<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major 4x3 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice4x3<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSlice4x3<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major 4x5 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice4x5<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSlice4x5<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major 4x6 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice4x6<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSlice4x6<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major 5x1 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice5x1<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSlice5x1<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major 5x2 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice5x2<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSlice5x2<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major 5x3 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice5x3<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSlice5x3<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major 5x4 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice5x4<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSlice5x4<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major 5x6 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice5x6<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSlice5x6<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major 6x1 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice6x1<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSlice6x1<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major 6x2 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice6x2<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSlice6x2<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major 6x3 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice6x3<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSlice6x3<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major 6x4 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice6x4<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSlice6x4<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major 6x5 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSlice6x5<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSlice6x5<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major matrix slice with 1 row and a number of columns chosen at runtime. -pub type MatrixSlice1xX<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSlice1xX<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major matrix slice with 2 rows and a number of columns chosen at runtime. -pub type MatrixSlice2xX<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSlice2xX<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major matrix slice with 3 rows and a number of columns chosen at runtime. -pub type MatrixSlice3xX<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSlice3xX<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major matrix slice with 4 rows and a number of columns chosen at runtime. -pub type MatrixSlice4xX<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSlice4xX<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major matrix slice with 5 rows and a number of columns chosen at runtime. -pub type MatrixSlice5xX<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSlice5xX<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major matrix slice with 6 rows and a number of columns chosen at runtime. -pub type MatrixSlice6xX<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSlice6xX<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major matrix slice with a number of rows chosen at runtime and 1 column. -pub type MatrixSliceXx1<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type MatrixSliceXx1<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A column-major matrix slice with a number of rows chosen at runtime and 2 columns. -pub type MatrixSliceXx2<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type MatrixSliceXx2<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A column-major matrix slice with a number of rows chosen at runtime and 3 columns. -pub type MatrixSliceXx3<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type MatrixSliceXx3<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A column-major matrix slice with a number of rows chosen at runtime and 4 columns. -pub type MatrixSliceXx4<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type MatrixSliceXx4<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A column-major matrix slice with a number of rows chosen at runtime and 5 columns. -pub type MatrixSliceXx5<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type MatrixSliceXx5<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A column-major matrix slice with a number of rows chosen at runtime and 6 columns. -pub type MatrixSliceXx6<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type MatrixSliceXx6<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; -/// A column vector slice with `D` rows. -pub type VectorSliceN<'a, N, D, RStride = U1, CStride = D> = - Matrix>; +/// A column vector slice with dimensions known at compile-time. +/// +/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** +pub type VectorSlice<'a, T, D, RStride = U1, CStride = D> = + Matrix>; + +/// A column vector slice with dimensions known at compile-time. +/// +/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** +pub type SVectorSlice<'a, T, const D: usize> = + Matrix, Const<1>, SliceStorage<'a, T, Const, Const<1>, Const<1>, Const>>; /// A column vector slice dynamic numbers of rows and columns. -pub type DVectorSlice<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type DVectorSlice<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A 1D column vector slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type VectorSlice1<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type VectorSlice1<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A 2D column vector slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type VectorSlice2<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type VectorSlice2<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A 3D column vector slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type VectorSlice3<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type VectorSlice3<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A 4D column vector slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type VectorSlice4<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type VectorSlice4<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A 5D column vector slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type VectorSlice5<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type VectorSlice5<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A 6D column vector slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type VectorSlice6<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type VectorSlice6<'a, T, RStride = U1, CStride = U6> = + Matrix>; /* * @@ -301,281 +304,297 @@ pub type VectorSlice6<'a, N, RStride = U1, CStride = U6> = /// A column-major matrix slice with `R` rows and `C` columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMutMN<'a, N, R, C, RStride = U1, CStride = R> = - Matrix>; +pub type MatrixSliceMutMN<'a, T, R, C, RStride = U1, CStride = R> = + Matrix>; /// A column-major matrix slice with `D` rows and columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMutN<'a, N, D, RStride = U1, CStride = D> = - Matrix>; +pub type MatrixSliceMutN<'a, T, D, RStride = U1, CStride = D> = + Matrix>; + +/// A column-major matrix slice with dimensions known at compile-time. +/// +/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** +pub type SMatrixSliceMut<'a, T, const R: usize, const C: usize> = + Matrix, Const, SliceStorageMut<'a, T, Const, Const, Const<1>, Const>>; /// A column-major matrix slice dynamic numbers of rows and columns. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type DMatrixSliceMut<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type DMatrixSliceMut<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A column-major 1x1 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut1<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSliceMut1<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major 2x2 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut2<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSliceMut2<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major 3x3 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut3<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSliceMut3<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major 4x4 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut4<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSliceMut4<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major 5x5 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut5<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSliceMut5<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major 6x6 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut6<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSliceMut6<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major 1x2 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut1x2<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSliceMut1x2<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major 1x3 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut1x3<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSliceMut1x3<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major 1x4 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut1x4<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSliceMut1x4<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major 1x5 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut1x5<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSliceMut1x5<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major 1x6 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut1x6<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSliceMut1x6<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major 2x1 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut2x1<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSliceMut2x1<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major 2x3 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut2x3<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSliceMut2x3<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major 2x4 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut2x4<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSliceMut2x4<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major 2x5 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut2x5<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSliceMut2x5<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major 2x6 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut2x6<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSliceMut2x6<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major 3x1 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut3x1<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSliceMut3x1<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major 3x2 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut3x2<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSliceMut3x2<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major 3x4 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut3x4<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSliceMut3x4<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major 3x5 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut3x5<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSliceMut3x5<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major 3x6 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut3x6<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSliceMut3x6<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major 4x1 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut4x1<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSliceMut4x1<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major 4x2 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut4x2<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSliceMut4x2<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major 4x3 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut4x3<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSliceMut4x3<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major 4x5 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut4x5<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSliceMut4x5<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major 4x6 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut4x6<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSliceMut4x6<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major 5x1 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut5x1<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSliceMut5x1<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major 5x2 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut5x2<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSliceMut5x2<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major 5x3 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut5x3<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSliceMut5x3<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major 5x4 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut5x4<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSliceMut5x4<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major 5x6 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut5x6<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSliceMut5x6<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major 6x1 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut6x1<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSliceMut6x1<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major 6x2 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut6x2<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSliceMut6x2<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major 6x3 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut6x3<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSliceMut6x3<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major 6x4 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut6x4<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSliceMut6x4<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major 6x5 matrix slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type MatrixSliceMut6x5<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSliceMut6x5<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major matrix slice with 1 row and a number of columns chosen at runtime. -pub type MatrixSliceMut1xX<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type MatrixSliceMut1xX<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A column-major matrix slice with 2 rows and a number of columns chosen at runtime. -pub type MatrixSliceMut2xX<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type MatrixSliceMut2xX<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A column-major matrix slice with 3 rows and a number of columns chosen at runtime. -pub type MatrixSliceMut3xX<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type MatrixSliceMut3xX<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A column-major matrix slice with 4 rows and a number of columns chosen at runtime. -pub type MatrixSliceMut4xX<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type MatrixSliceMut4xX<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A column-major matrix slice with 5 rows and a number of columns chosen at runtime. -pub type MatrixSliceMut5xX<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type MatrixSliceMut5xX<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A column-major matrix slice with 6 rows and a number of columns chosen at runtime. -pub type MatrixSliceMut6xX<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type MatrixSliceMut6xX<'a, T, RStride = U1, CStride = U6> = + Matrix>; /// A column-major matrix slice with a number of rows chosen at runtime and 1 column. -pub type MatrixSliceMutXx1<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type MatrixSliceMutXx1<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A column-major matrix slice with a number of rows chosen at runtime and 2 columns. -pub type MatrixSliceMutXx2<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type MatrixSliceMutXx2<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A column-major matrix slice with a number of rows chosen at runtime and 3 columns. -pub type MatrixSliceMutXx3<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type MatrixSliceMutXx3<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A column-major matrix slice with a number of rows chosen at runtime and 4 columns. -pub type MatrixSliceMutXx4<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type MatrixSliceMutXx4<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A column-major matrix slice with a number of rows chosen at runtime and 5 columns. -pub type MatrixSliceMutXx5<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type MatrixSliceMutXx5<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A column-major matrix slice with a number of rows chosen at runtime and 6 columns. -pub type MatrixSliceMutXx6<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +pub type MatrixSliceMutXx6<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; -/// A column vector slice with `D` rows. -pub type VectorSliceMutN<'a, N, D, RStride = U1, CStride = D> = - Matrix>; +/// A column vector slice with dimensions known at compile-time. +/// +/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** +pub type VectorSliceMut<'a, T, D, RStride = U1, CStride = D> = + Matrix>; + +/// A column vector slice with dimensions known at compile-time. +/// +/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** +pub type SVectorSliceMut<'a, T, const D: usize> = + Matrix, Const<1>, SliceStorageMut<'a, T, Const, Const<1>, Const<1>, Const>>; /// A column vector slice dynamic numbers of rows and columns. -pub type DVectorSliceMut<'a, N, RStride = U1, CStride = Dynamic> = - Matrix>; +/// +/// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** +pub type DVectorSliceMut<'a, T, RStride = U1, CStride = Dynamic> = + Matrix>; /// A 1D column vector slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type VectorSliceMut1<'a, N, RStride = U1, CStride = U1> = - Matrix>; +pub type VectorSliceMut1<'a, T, RStride = U1, CStride = U1> = + Matrix>; /// A 2D column vector slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type VectorSliceMut2<'a, N, RStride = U1, CStride = U2> = - Matrix>; +pub type VectorSliceMut2<'a, T, RStride = U1, CStride = U2> = + Matrix>; /// A 3D column vector slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type VectorSliceMut3<'a, N, RStride = U1, CStride = U3> = - Matrix>; +pub type VectorSliceMut3<'a, T, RStride = U1, CStride = U3> = + Matrix>; /// A 4D column vector slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type VectorSliceMut4<'a, N, RStride = U1, CStride = U4> = - Matrix>; +pub type VectorSliceMut4<'a, T, RStride = U1, CStride = U4> = + Matrix>; /// A 5D column vector slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type VectorSliceMut5<'a, N, RStride = U1, CStride = U5> = - Matrix>; +pub type VectorSliceMut5<'a, T, RStride = U1, CStride = U5> = + Matrix>; /// A 6D column vector slice. /// /// **Because this is an alias, not all its methods are listed here. See the [`Matrix`](crate::base::Matrix) type too.** -pub type VectorSliceMut6<'a, N, RStride = U1, CStride = U6> = - Matrix>; +pub type VectorSliceMut6<'a, T, RStride = U1, CStride = U6> = + Matrix>; diff --git a/src/base/allocator.rs b/src/base/allocator.rs index 3632cf5d..77a08c9e 100644 --- a/src/base/allocator.rs +++ b/src/base/allocator.rs @@ -9,7 +9,7 @@ use crate::base::storage::ContiguousStorageMut; use crate::base::{DefaultAllocator, Scalar}; /// A matrix allocator of a memory buffer that may contain `R::to_usize() * C::to_usize()` -/// elements of type `N`. +/// elements of type `T`. /// /// An allocator is said to be: /// − static: if `R` and `C` both implement `DimName`. @@ -17,25 +17,35 @@ use crate::base::{DefaultAllocator, Scalar}; /// /// Every allocator must be both static and dynamic. Though not all implementations may share the /// same `Buffer` type. -pub trait Allocator: Any + Sized { +pub trait Allocator: Any + Sized { /// The type of buffer this allocator can instanciate. - type Buffer: ContiguousStorageMut + Clone; + type Buffer: ContiguousStorageMut + Clone; /// Allocates a buffer with the given number of rows and columns without initializing its content. unsafe fn allocate_uninitialized(nrows: R, ncols: C) -> mem::MaybeUninit; /// Allocates a buffer initialized with the content of the given iterator. - fn allocate_from_iterator>( + fn allocate_from_iterator>( nrows: R, ncols: C, iter: I, ) -> Self::Buffer; + + unsafe fn allocate_more( + nrows: R2, + ncols: C2, + ) -> mem::MaybeUninit<>::Buffer> + where + Self: Allocator, + { + >::allocate_uninitialized(nrows, ncols) + } } /// A matrix reallocator. Changes the size of the memory buffer that initially contains (RFrom × /// CFrom) elements to a smaller or larger size (RTo, CTo). -pub trait Reallocator: - Allocator + Allocator +pub trait Reallocator: + Allocator + Allocator { /// Reallocates a buffer of shape `(RTo, CTo)`, possibly reusing a previously allocated buffer /// `buf`. Data stored by `buf` are linearly copied to the output: @@ -47,8 +57,8 @@ pub trait Reallocator: unsafe fn reallocate_copy( nrows: RTo, ncols: CTo, - buf: >::Buffer, - ) -> >::Buffer; + buf: >::Buffer, + ) -> >::Buffer; } /// The number of rows of the result of a componentwise operation on two matrices. @@ -59,48 +69,48 @@ pub type SameShapeC = >:: // TODO: Bad name. /// Restricts the given number of rows and columns to be respectively the same. -pub trait SameShapeAllocator: - Allocator + Allocator, SameShapeC> +pub trait SameShapeAllocator: + Allocator + Allocator, SameShapeC> where R1: Dim, R2: Dim, C1: Dim, C2: Dim, - N: Scalar, + T: Scalar, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { } -impl SameShapeAllocator for DefaultAllocator +impl SameShapeAllocator for DefaultAllocator where R1: Dim, R2: Dim, C1: Dim, C2: Dim, - N: Scalar, - DefaultAllocator: Allocator + Allocator, SameShapeC>, + T: Scalar, + DefaultAllocator: Allocator + Allocator, SameShapeC>, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { } // XXX: Bad name. /// Restricts the given number of rows to be equal. -pub trait SameShapeVectorAllocator: - Allocator + Allocator> + SameShapeAllocator +pub trait SameShapeVectorAllocator: + Allocator + Allocator> + SameShapeAllocator where R1: Dim, R2: Dim, - N: Scalar, + T: Scalar, ShapeConstraint: SameNumberOfRows, { } -impl SameShapeVectorAllocator for DefaultAllocator +impl SameShapeVectorAllocator for DefaultAllocator where R1: Dim, R2: Dim, - N: Scalar, - DefaultAllocator: Allocator + Allocator>, + T: Scalar, + DefaultAllocator: Allocator + Allocator>, ShapeConstraint: SameNumberOfRows, { } diff --git a/src/base/array_storage.rs b/src/base/array_storage.rs index 029d960c..67384a39 100644 --- a/src/base/array_storage.rs +++ b/src/base/array_storage.rs @@ -34,42 +34,38 @@ use crate::base::Scalar; /// A array-based statically sized matrix data storage. #[repr(C)] #[derive(Copy, Clone, PartialEq, Eq, Hash)] -pub struct ArrayStorage { - data: [[N; R]; C], -} +pub struct ArrayStorage(pub [[T; R]; C]); // TODO: remove this once the stdlib implements Default for arrays. -impl Default for ArrayStorage +impl Default for ArrayStorage where - [[N; R]; C]: Default, + [[T; R]; C]: Default, { #[inline] fn default() -> Self { - Self { - data: Default::default(), - } + Self(Default::default()) } } -impl Debug for ArrayStorage { +impl Debug for ArrayStorage { #[inline] fn fmt(&self, fmt: &mut Formatter) -> fmt::Result { - self.data.fmt(fmt) + self.0.fmt(fmt) } } -unsafe impl Storage, Const> - for ArrayStorage +unsafe impl Storage, Const> + for ArrayStorage where - N: Scalar, - DefaultAllocator: Allocator, Const, Buffer = Self>, + T: Scalar, + DefaultAllocator: Allocator, Const, Buffer = Self>, { type RStride = Const<1>; type CStride = Const; #[inline] - fn ptr(&self) -> *const N { - self.data.as_ptr() as *const N + fn ptr(&self) -> *const T { + self.0.as_ptr() as *const T } #[inline] @@ -88,65 +84,65 @@ where } #[inline] - fn into_owned(self) -> Owned, Const> + fn into_owned(self) -> Owned, Const> where - DefaultAllocator: Allocator, Const>, + DefaultAllocator: Allocator, Const>, { self } #[inline] - fn clone_owned(&self) -> Owned, Const> + fn clone_owned(&self) -> Owned, Const> where - DefaultAllocator: Allocator, Const>, + DefaultAllocator: Allocator, Const>, { let it = self.as_slice().iter().cloned(); DefaultAllocator::allocate_from_iterator(self.shape().0, self.shape().1, it) } #[inline] - fn as_slice(&self) -> &[N] { + fn as_slice(&self) -> &[T] { unsafe { std::slice::from_raw_parts(self.ptr(), R * C) } } } -unsafe impl StorageMut, Const> - for ArrayStorage +unsafe impl StorageMut, Const> + for ArrayStorage where - N: Scalar, - DefaultAllocator: Allocator, Const, Buffer = Self>, + T: Scalar, + DefaultAllocator: Allocator, Const, Buffer = Self>, { #[inline] - fn ptr_mut(&mut self) -> *mut N { - self.data.as_mut_ptr() as *mut N + fn ptr_mut(&mut self) -> *mut T { + self.0.as_mut_ptr() as *mut T } #[inline] - fn as_mut_slice(&mut self) -> &mut [N] { + fn as_mut_slice(&mut self) -> &mut [T] { unsafe { std::slice::from_raw_parts_mut(self.ptr_mut(), R * C) } } } -unsafe impl ContiguousStorage, Const> - for ArrayStorage +unsafe impl ContiguousStorage, Const> + for ArrayStorage where - N: Scalar, - DefaultAllocator: Allocator, Const, Buffer = Self>, + T: Scalar, + DefaultAllocator: Allocator, Const, Buffer = Self>, { } -unsafe impl ContiguousStorageMut, Const> - for ArrayStorage +unsafe impl ContiguousStorageMut, Const> + for ArrayStorage where - N: Scalar, - DefaultAllocator: Allocator, Const, Buffer = Self>, + T: Scalar, + DefaultAllocator: Allocator, Const, Buffer = Self>, { } -impl - ReshapableStorage, Const, Const, Const> for ArrayStorage +impl + ReshapableStorage, Const, Const, Const> for ArrayStorage where - N: Scalar, + T: Scalar, Const: ToTypenum, Const: ToTypenum, Const: ToTypenum, @@ -160,13 +156,13 @@ where >, >, { - type Output = ArrayStorage; + type Output = ArrayStorage; fn reshape_generic(self, _: Const, _: Const) -> Self::Output { unsafe { - let data: [[N; R2]; C2] = std::mem::transmute_copy(&self.data); - std::mem::forget(self.data); - ArrayStorage { data } + let data: [[T; R2]; C2] = std::mem::transmute_copy(&self.0); + std::mem::forget(self.0); + ArrayStorage(data) } } } @@ -178,9 +174,9 @@ where */ // XXX: open an issue for serde so that it allows the serialization/deserialization of all arrays? #[cfg(feature = "serde-serialize")] -impl Serialize for ArrayStorage +impl Serialize for ArrayStorage where - N: Scalar + Serialize, + T: Scalar + Serialize, { fn serialize(&self, serializer: S) -> Result where @@ -197,9 +193,9 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N, const R: usize, const C: usize> Deserialize<'a> for ArrayStorage +impl<'a, T, const R: usize, const C: usize> Deserialize<'a> for ArrayStorage where - N: Scalar + Deserialize<'a>, + T: Scalar + Deserialize<'a>, { fn deserialize(deserializer: D) -> Result where @@ -211,14 +207,14 @@ where #[cfg(feature = "serde-serialize")] /// A visitor that produces a matrix array. -struct ArrayStorageVisitor { - marker: PhantomData, +struct ArrayStorageVisitor { + marker: PhantomData, } #[cfg(feature = "serde-serialize")] -impl ArrayStorageVisitor +impl ArrayStorageVisitor where - N: Scalar, + T: Scalar, { /// Construct a new sequence visitor. pub fn new() -> Self { @@ -229,18 +225,18 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N, const R: usize, const C: usize> Visitor<'a> for ArrayStorageVisitor +impl<'a, T, const R: usize, const C: usize> Visitor<'a> for ArrayStorageVisitor where - N: Scalar + Deserialize<'a>, + T: Scalar + Deserialize<'a>, { - type Value = ArrayStorage; + type Value = ArrayStorage; fn expecting(&self, formatter: &mut Formatter) -> fmt::Result { formatter.write_str("a matrix array") } #[inline] - fn visit_seq(self, mut visitor: V) -> Result, V::Error> + fn visit_seq(self, mut visitor: V) -> Result, V::Error> where V: SeqAccess<'a>, { @@ -263,29 +259,21 @@ where } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Zeroable - for ArrayStorage -where - R::Value: Mul, - Prod: ArrayLength, - Self: Copy, +unsafe impl + bytemuck::Zeroable for ArrayStorage { } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Pod - for ArrayStorage -where - R::Value: Mul, - Prod: ArrayLength, - Self: Copy, +unsafe impl bytemuck::Pod + for ArrayStorage { } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for ArrayStorage +impl Abomonation for ArrayStorage where - N: Scalar + Abomonation, + T: Scalar + Abomonation, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { for element in self.as_slice() { diff --git a/src/base/blas.rs b/src/base/blas.rs index fe5933e7..05705f17 100644 --- a/src/base/blas.rs +++ b/src/base/blas.rs @@ -13,22 +13,22 @@ use crate::base::constraint::{ use crate::base::dimension::{Const, Dim, Dynamic, U1, U2, U3, U4}; use crate::base::storage::{Storage, StorageMut}; use crate::base::{ - DVectorSlice, DefaultAllocator, Matrix, Scalar, SquareMatrix, Vector, VectorSliceN, + DVectorSlice, DefaultAllocator, Matrix, Scalar, SquareMatrix, Vector, VectorSlice, }; /// # Dot/scalar product -impl> Matrix +impl> Matrix where - N: Scalar + Zero + ClosedAdd + ClosedMul, + T: Scalar + Zero + ClosedAdd + ClosedMul, { #[inline(always)] fn dotx( &self, - rhs: &Matrix, - conjugate: impl Fn(N) -> N, - ) -> N + rhs: &Matrix, + conjugate: impl Fn(T) -> T, + ) -> T where - SB: Storage, + SB: Storage, ShapeConstraint: DimEq + DimEq, { assert!( @@ -92,7 +92,7 @@ where // // And this comment from bluss: // https://users.rust-lang.org/t/how-to-zip-two-slices-efficiently/2048/12 - let mut res = N::zero(); + let mut res = T::zero(); // We have to define them outside of the loop (and not inside at first assignment) // otherwise vectorization won't kick in for some reason. @@ -108,14 +108,14 @@ where for j in 0..self.ncols() { let mut i = 0; - acc0 = N::zero(); - acc1 = N::zero(); - acc2 = N::zero(); - acc3 = N::zero(); - acc4 = N::zero(); - acc5 = N::zero(); - acc6 = N::zero(); - acc7 = N::zero(); + acc0 = T::zero(); + acc1 = T::zero(); + acc2 = T::zero(); + acc3 = T::zero(); + acc4 = T::zero(); + acc5 = T::zero(); + acc6 = T::zero(); + acc7 = T::zero(); while self.nrows() - i >= 8 { acc0 += unsafe { @@ -193,9 +193,9 @@ where /// ``` /// #[inline] - pub fn dot(&self, rhs: &Matrix) -> N + pub fn dot(&self, rhs: &Matrix) -> T where - SB: Storage, + SB: Storage, ShapeConstraint: DimEq + DimEq, { self.dotx(rhs, |e| e) @@ -221,13 +221,13 @@ where /// assert_ne!(vec1.dotc(&vec2), vec1.dot(&vec2)); /// ``` #[inline] - pub fn dotc(&self, rhs: &Matrix) -> N + pub fn dotc(&self, rhs: &Matrix) -> T where - N: SimdComplexField, - SB: Storage, + T: SimdComplexField, + SB: Storage, ShapeConstraint: DimEq + DimEq, { - self.dotx(rhs, N::simd_conjugate) + self.dotx(rhs, T::simd_conjugate) } /// The dot product between the transpose of `self` and `rhs`. @@ -248,9 +248,9 @@ where /// assert_eq!(mat1.tr_dot(&mat2), 9.1); /// ``` #[inline] - pub fn tr_dot(&self, rhs: &Matrix) -> N + pub fn tr_dot(&self, rhs: &Matrix) -> T where - SB: Storage, + SB: Storage, ShapeConstraint: DimEq + DimEq, { let (nrows, ncols) = self.shape(); @@ -260,7 +260,7 @@ where "Transposed dot product dimension mismatch." ); - let mut res = N::zero(); + let mut res = T::zero(); for j in 0..self.nrows() { for i in 0..self.ncols() { @@ -275,17 +275,17 @@ where } } -fn array_axcpy( - y: &mut [N], - a: N, - x: &[N], - c: N, - beta: N, +fn array_axcpy( + y: &mut [T], + a: T, + x: &[T], + c: T, + beta: T, stride1: usize, stride2: usize, len: usize, ) where - N: Scalar + Zero + ClosedAdd + ClosedMul, + T: Scalar + Zero + ClosedAdd + ClosedMul, { for i in 0..len { unsafe { @@ -298,9 +298,9 @@ fn array_axcpy( } } -fn array_axc(y: &mut [N], a: N, x: &[N], c: N, stride1: usize, stride2: usize, len: usize) +fn array_axc(y: &mut [T], a: T, x: &[T], c: T, stride1: usize, stride2: usize, len: usize) where - N: Scalar + Zero + ClosedAdd + ClosedMul, + T: Scalar + Zero + ClosedAdd + ClosedMul, { for i in 0..len { unsafe { @@ -312,10 +312,10 @@ where } /// # BLAS functions -impl Vector +impl Vector where - N: Scalar + Zero + ClosedAdd + ClosedMul, - S: StorageMut, + T: Scalar + Zero + ClosedAdd + ClosedMul, + S: StorageMut, { /// Computes `self = a * x * c + b * self`. /// @@ -331,9 +331,9 @@ where /// assert_eq!(vec1, Vector3::new(6.0, 12.0, 18.0)); /// ``` #[inline] - pub fn axcpy(&mut self, a: N, x: &Vector, c: N, b: N) + pub fn axcpy(&mut self, a: T, x: &Vector, c: T, b: T) where - SB: Storage, + SB: Storage, ShapeConstraint: DimEq, { assert_eq!(self.nrows(), x.nrows(), "Axcpy: mismatched vector shapes."); @@ -365,14 +365,14 @@ where /// assert_eq!(vec1, Vector3::new(6.0, 12.0, 18.0)); /// ``` #[inline] - pub fn axpy(&mut self, a: N, x: &Vector, b: N) + pub fn axpy(&mut self, a: T, x: &Vector, b: T) where - N: One, - SB: Storage, + T: One, + SB: Storage, ShapeConstraint: DimEq, { assert_eq!(self.nrows(), x.nrows(), "Axpy: mismatched vector shapes."); - self.axcpy(a, x, N::one(), b) + self.axcpy(a, x, T::one(), b) } /// Computes `self = alpha * a * x + beta * self`, where `a` is a matrix, `x` a vector, and @@ -394,14 +394,14 @@ where #[inline] pub fn gemv( &mut self, - alpha: N, - a: &Matrix, - x: &Vector, - beta: N, + alpha: T, + a: &Matrix, + x: &Vector, + beta: T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + AreMultipliable, { let dim1 = self.nrows(); @@ -418,7 +418,7 @@ where // because we documented the guaranty that `self` is // never read if `beta` is zero. if beta.is_zero() { - self.fill(N::zero()); + self.fill(T::zero()); } else { *self *= beta; } @@ -434,25 +434,25 @@ where let col2 = a.column(j); let val = unsafe { x.vget_unchecked(j).inlined_clone() }; - self.axcpy(alpha.inlined_clone(), &col2, val, N::one()); + self.axcpy(alpha.inlined_clone(), &col2, val, T::one()); } } #[inline(always)] fn xxgemv( &mut self, - alpha: N, - a: &SquareMatrix, - x: &Vector, - beta: N, + alpha: T, + a: &SquareMatrix, + x: &Vector, + beta: T, dot: impl Fn( - &DVectorSlice, - &DVectorSlice, - ) -> N, + &DVectorSlice, + &DVectorSlice, + ) -> T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + AreMultipliable, { let dim1 = self.nrows(); @@ -490,7 +490,7 @@ where self.rows_range_mut(j + 1..).axpy( alpha.inlined_clone() * val, &col2.rows_range(j + 1..), - N::one(), + T::one(), ); } } @@ -501,14 +501,14 @@ where #[deprecated(note = "This is renamed `sygemv` to match the original BLAS terminology.")] pub fn gemv_symm( &mut self, - alpha: N, - a: &SquareMatrix, - x: &Vector, - beta: N, + alpha: T, + a: &SquareMatrix, + x: &Vector, + beta: T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + AreMultipliable, { self.sygemv(alpha, a, x, beta) @@ -545,14 +545,14 @@ where #[inline] pub fn sygemv( &mut self, - alpha: N, - a: &SquareMatrix, - x: &Vector, - beta: N, + alpha: T, + a: &SquareMatrix, + x: &Vector, + beta: T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + AreMultipliable, { self.xxgemv(alpha, a, x, beta, |a, b| a.dot(b)) @@ -590,14 +590,14 @@ where #[inline] pub fn hegemv( &mut self, - alpha: N, - a: &SquareMatrix, - x: &Vector, - beta: N, + alpha: T, + a: &SquareMatrix, + x: &Vector, + beta: T, ) where - N: SimdComplexField, - SB: Storage, - SC: Storage, + T: SimdComplexField, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + AreMultipliable, { self.xxgemv(alpha, a, x, beta, |a, b| a.dotc(b)) @@ -606,15 +606,15 @@ where #[inline(always)] fn gemv_xx( &mut self, - alpha: N, - a: &Matrix, - x: &Vector, - beta: N, - dot: impl Fn(&VectorSliceN, &Vector) -> N, + alpha: T, + a: &Matrix, + x: &Vector, + beta: T, + dot: impl Fn(&VectorSlice, &Vector) -> T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + AreMultipliable, { let dim1 = self.nrows(); @@ -665,14 +665,14 @@ where #[inline] pub fn gemv_tr( &mut self, - alpha: N, - a: &Matrix, - x: &Vector, - beta: N, + alpha: T, + a: &Matrix, + x: &Vector, + beta: T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + AreMultipliable, { self.gemv_xx(alpha, a, x, beta, |a, b| a.dot(b)) @@ -700,36 +700,36 @@ where #[inline] pub fn gemv_ad( &mut self, - alpha: N, - a: &Matrix, - x: &Vector, - beta: N, + alpha: T, + a: &Matrix, + x: &Vector, + beta: T, ) where - N: SimdComplexField, - SB: Storage, - SC: Storage, + T: SimdComplexField, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + AreMultipliable, { self.gemv_xx(alpha, a, x, beta, |a, b| a.dotc(b)) } } -impl> Matrix +impl> Matrix where - N: Scalar + Zero + ClosedAdd + ClosedMul, + T: Scalar + Zero + ClosedAdd + ClosedMul, { #[inline(always)] fn gerx( &mut self, - alpha: N, - x: &Vector, - y: &Vector, - beta: N, - conjugate: impl Fn(N) -> N, + alpha: T, + x: &Vector, + y: &Vector, + beta: T, + conjugate: impl Fn(T) -> T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + DimEq, { let (nrows1, ncols1) = self.shape(); @@ -768,14 +768,14 @@ where #[inline] pub fn ger( &mut self, - alpha: N, - x: &Vector, - y: &Vector, - beta: N, + alpha: T, + x: &Vector, + y: &Vector, + beta: T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + DimEq, { self.gerx(alpha, x, y, beta, |e| e) @@ -801,14 +801,14 @@ where #[inline] pub fn gerc( &mut self, - alpha: N, - x: &Vector, - y: &Vector, - beta: N, + alpha: T, + x: &Vector, + y: &Vector, + beta: T, ) where - N: SimdComplexField, - SB: Storage, - SC: Storage, + T: SimdComplexField, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + DimEq, { self.gerx(alpha, x, y, beta, SimdComplexField::simd_conjugate) @@ -838,14 +838,14 @@ where #[inline] pub fn gemm( &mut self, - alpha: N, - a: &Matrix, - b: &Matrix, - beta: N, + alpha: T, + a: &Matrix, + b: &Matrix, + beta: T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns + AreMultipliable, @@ -897,14 +897,14 @@ where // because we documented the guaranty that `self` is // never read if `beta` is zero. if beta.is_zero() { - self.fill(N::zero()); + self.fill(T::zero()); } else { *self *= beta; } return; } - if N::is::() { + if T::is::() { let (rsa, csa) = a.strides(); let (rsb, csb) = b.strides(); let (rsc, csc) = self.strides(); @@ -928,7 +928,7 @@ where ); } return; - } else if N::is::() { + } else if T::is::() { let (rsa, csa) = a.strides(); let (rsb, csb) = b.strides(); let (rsc, csc) = self.strides(); @@ -993,14 +993,14 @@ where #[inline] pub fn gemm_tr( &mut self, - alpha: N, - a: &Matrix, - b: &Matrix, - beta: N, + alpha: T, + a: &Matrix, + b: &Matrix, + beta: T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns + AreMultipliable, @@ -1055,14 +1055,14 @@ where #[inline] pub fn gemm_ad( &mut self, - alpha: N, - a: &Matrix, - b: &Matrix, - beta: N, + alpha: T, + a: &Matrix, + b: &Matrix, + beta: T, ) where - N: SimdComplexField, - SB: Storage, - SC: Storage, + T: SimdComplexField, + SB: Storage, + SC: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns + AreMultipliable, @@ -1088,22 +1088,22 @@ where } } -impl> Matrix +impl> Matrix where - N: Scalar + Zero + ClosedAdd + ClosedMul, + T: Scalar + Zero + ClosedAdd + ClosedMul, { #[inline(always)] fn xxgerx( &mut self, - alpha: N, - x: &Vector, - y: &Vector, - beta: N, - conjugate: impl Fn(N) -> N, + alpha: T, + x: &Vector, + y: &Vector, + beta: T, + conjugate: impl Fn(T) -> T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + DimEq, { let dim1 = self.nrows(); @@ -1151,14 +1151,14 @@ where #[deprecated(note = "This is renamed `syger` to match the original BLAS terminology.")] pub fn ger_symm( &mut self, - alpha: N, - x: &Vector, - y: &Vector, - beta: N, + alpha: T, + x: &Vector, + y: &Vector, + beta: T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + DimEq, { self.syger(alpha, x, y, beta) @@ -1187,14 +1187,14 @@ where #[inline] pub fn syger( &mut self, - alpha: N, - x: &Vector, - y: &Vector, - beta: N, + alpha: T, + x: &Vector, + y: &Vector, + beta: T, ) where - N: One, - SB: Storage, - SC: Storage, + T: One, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + DimEq, { self.xxgerx(alpha, x, y, beta, |e| e) @@ -1222,23 +1222,23 @@ where #[inline] pub fn hegerc( &mut self, - alpha: N, - x: &Vector, - y: &Vector, - beta: N, + alpha: T, + x: &Vector, + y: &Vector, + beta: T, ) where - N: SimdComplexField, - SB: Storage, - SC: Storage, + T: SimdComplexField, + SB: Storage, + SC: Storage, ShapeConstraint: DimEq + DimEq, { self.xxgerx(alpha, x, y, beta, SimdComplexField::simd_conjugate) } } -impl> SquareMatrix +impl> SquareMatrix where - N: Scalar + Zero + One + ClosedAdd + ClosedMul, + T: Scalar + Zero + One + ClosedAdd + ClosedMul, { /// Computes the quadratic form `self = alpha * lhs * mid * lhs.transpose() + beta * self`. /// @@ -1268,27 +1268,27 @@ where /// assert_relative_eq!(mat, expected); pub fn quadform_tr_with_workspace( &mut self, - work: &mut Vector, - alpha: N, - lhs: &Matrix, - mid: &SquareMatrix, - beta: N, + work: &mut Vector, + alpha: T, + lhs: &Matrix, + mid: &SquareMatrix, + beta: T, ) where D2: Dim, R3: Dim, C3: Dim, D4: Dim, - S2: StorageMut, - S3: Storage, - S4: Storage, + S2: StorageMut, + S3: Storage, + S4: Storage, ShapeConstraint: DimEq + DimEq + DimEq + DimEq, { - work.gemv(N::one(), lhs, &mid.column(0), N::zero()); + work.gemv(T::one(), lhs, &mid.column(0), T::zero()); self.ger(alpha.inlined_clone(), work, &lhs.column(0), beta); for j in 1..mid.ncols() { - work.gemv(N::one(), lhs, &mid.column(j), N::zero()); - self.ger(alpha.inlined_clone(), work, &lhs.column(j), N::one()); + work.gemv(T::one(), lhs, &mid.column(j), T::zero()); + self.ger(alpha.inlined_clone(), work, &lhs.column(j), T::one()); } } @@ -1315,21 +1315,22 @@ where /// assert_relative_eq!(mat, expected); pub fn quadform_tr( &mut self, - alpha: N, - lhs: &Matrix, - mid: &SquareMatrix, - beta: N, + alpha: T, + lhs: &Matrix, + mid: &SquareMatrix, + beta: T, ) where R3: Dim, C3: Dim, D4: Dim, - S3: Storage, - S4: Storage, + S3: Storage, + S4: Storage, ShapeConstraint: DimEq + DimEq + DimEq, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - let mut work = - unsafe { crate::unimplemented_or_uninitialized_generic!(self.data.shape().0, Const::<1>) }; + let mut work = unsafe { + crate::unimplemented_or_uninitialized_generic!(self.data.shape().0, Const::<1>) + }; self.quadform_tr_with_workspace(&mut work, alpha, lhs, mid, beta) } @@ -1360,28 +1361,28 @@ where /// assert_relative_eq!(mat, expected); pub fn quadform_with_workspace( &mut self, - work: &mut Vector, - alpha: N, - mid: &SquareMatrix, - rhs: &Matrix, - beta: N, + work: &mut Vector, + alpha: T, + mid: &SquareMatrix, + rhs: &Matrix, + beta: T, ) where D2: Dim, D3: Dim, R4: Dim, C4: Dim, - S2: StorageMut, - S3: Storage, - S4: Storage, + S2: StorageMut, + S3: Storage, + S4: Storage, ShapeConstraint: DimEq + DimEq + DimEq + AreMultipliable, { - work.gemv(N::one(), mid, &rhs.column(0), N::zero()); + work.gemv(T::one(), mid, &rhs.column(0), T::zero()); self.column_mut(0) .gemv_tr(alpha.inlined_clone(), &rhs, work, beta.inlined_clone()); for j in 1..rhs.ncols() { - work.gemv(N::one(), mid, &rhs.column(j), N::zero()); + work.gemv(T::one(), mid, &rhs.column(j), T::zero()); self.column_mut(j) .gemv_tr(alpha.inlined_clone(), &rhs, work, beta.inlined_clone()); } @@ -1409,21 +1410,22 @@ where /// assert_relative_eq!(mat, expected); pub fn quadform( &mut self, - alpha: N, - mid: &SquareMatrix, - rhs: &Matrix, - beta: N, + alpha: T, + mid: &SquareMatrix, + rhs: &Matrix, + beta: T, ) where D2: Dim, R3: Dim, C3: Dim, - S2: Storage, - S3: Storage, + S2: Storage, + S3: Storage, ShapeConstraint: DimEq + DimEq + AreMultipliable, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - let mut work = - unsafe { crate::unimplemented_or_uninitialized_generic!(mid.data.shape().0, Const::<1>) }; + let mut work = unsafe { + crate::unimplemented_or_uninitialized_generic!(mid.data.shape().0, Const::<1>) + }; self.quadform_with_workspace(&mut work, alpha, mid, rhs, beta) } } diff --git a/src/base/cg.rs b/src/base/cg.rs index 2464bce1..2b62524b 100644 --- a/src/base/cg.rs +++ b/src/base/cg.rs @@ -11,8 +11,8 @@ use crate::base::allocator::Allocator; use crate::base::dimension::{DimName, DimNameDiff, DimNameSub, U1}; use crate::base::storage::{Storage, StorageMut}; use crate::base::{ - Const, DefaultAllocator, Matrix3, Matrix4, MatrixN, Scalar, SquareMatrix, Unit, Vector, - Vector2, Vector3, VectorN, + Const, DefaultAllocator, Matrix3, Matrix4, OMatrix, OVector, Scalar, SquareMatrix, Unit, + Vector, Vector2, Vector3, }; use crate::geometry::{ Isometry, IsometryMatrix3, Orthographic3, Perspective3, Point, Point2, Point3, Rotation2, @@ -22,26 +22,26 @@ use crate::geometry::{ use simba::scalar::{ClosedAdd, ClosedMul, RealField}; /// # Translation and scaling in any dimension -impl MatrixN +impl OMatrix where - N: Scalar + Zero + One, - DefaultAllocator: Allocator, + T: Scalar + Zero + One, + DefaultAllocator: Allocator, { /// Creates a new homogeneous matrix that applies the same scaling factor on each dimension. #[inline] - pub fn new_scaling(scaling: N) -> Self { + pub fn new_scaling(scaling: T) -> Self { let mut res = Self::from_diagonal_element(scaling); - res[(D::dim() - 1, D::dim() - 1)] = N::one(); + res[(D::dim() - 1, D::dim() - 1)] = T::one(); res } /// Creates a new homogeneous matrix that applies a distinct scaling factor for each dimension. #[inline] - pub fn new_nonuniform_scaling(scaling: &Vector, SB>) -> Self + pub fn new_nonuniform_scaling(scaling: &Vector, SB>) -> Self where D: DimNameSub, - SB: Storage>, + SB: Storage>, { let mut res = Self::identity(); for i in 0..scaling.len() { @@ -53,24 +53,27 @@ where /// Creates a new homogeneous matrix that applies a pure translation. #[inline] - pub fn new_translation(translation: &Vector, SB>) -> Self + pub fn new_translation(translation: &Vector, SB>) -> Self where D: DimNameSub, - SB: Storage>, + SB: Storage>, { let mut res = Self::identity(); - res.fixed_slice_mut::, U1>(0, D::dim() - 1) - .copy_from(translation); + res.generic_slice_mut( + (0, D::dim() - 1), + (DimNameDiff::::name(), Const::<1>), + ) + .copy_from(translation); res } } /// # 2D transformations as a Matrix3 -impl Matrix3 { +impl Matrix3 { /// Builds a 2 dimensional homogeneous rotation matrix from an angle in radian. #[inline] - pub fn new_rotation(angle: N) -> Self { + pub fn new_rotation(angle: T) -> Self { Rotation2::new(angle).to_homogeneous() } @@ -78,9 +81,9 @@ impl Matrix3 { /// /// Can be used to implement "zoom_to" functionality. #[inline] - pub fn new_nonuniform_scaling_wrt_point(scaling: &Vector2, pt: &Point2) -> Self { - let zero = N::zero(); - let one = N::one(); + pub fn new_nonuniform_scaling_wrt_point(scaling: &Vector2, pt: &Point2) -> Self { + let zero = T::zero(); + let one = T::one(); Matrix3::new( scaling.x, zero, @@ -96,12 +99,12 @@ impl Matrix3 { } /// # 3D transformations as a Matrix4 -impl Matrix4 { +impl Matrix4 { /// Builds a 3D homogeneous rotation matrix from an axis and an angle (multiplied together). /// /// Returns the identity matrix if the given argument is zero. #[inline] - pub fn new_rotation(axisangle: Vector3) -> Self { + pub fn new_rotation(axisangle: Vector3) -> Self { Rotation3::new(axisangle).to_homogeneous() } @@ -109,7 +112,7 @@ impl Matrix4 { /// /// Returns the identity matrix if the given argument is zero. #[inline] - pub fn new_rotation_wrt_point(axisangle: Vector3, pt: Point3) -> Self { + pub fn new_rotation_wrt_point(axisangle: Vector3, pt: Point3) -> Self { let rot = Rotation3::from_scaled_axis(axisangle); Isometry::rotation_wrt_point(rot, pt).to_homogeneous() } @@ -118,9 +121,9 @@ impl Matrix4 { /// /// Can be used to implement "zoom_to" functionality. #[inline] - pub fn new_nonuniform_scaling_wrt_point(scaling: &Vector3, pt: &Point3) -> Self { - let zero = N::zero(); - let one = N::one(); + pub fn new_nonuniform_scaling_wrt_point(scaling: &Vector3, pt: &Point3) -> Self { + let zero = T::zero(); + let one = T::one(); Matrix4::new( scaling.x, zero, @@ -146,31 +149,31 @@ impl Matrix4 { /// Returns the identity matrix if the given argument is zero. /// This is identical to `Self::new_rotation`. #[inline] - pub fn from_scaled_axis(axisangle: Vector3) -> Self { + pub fn from_scaled_axis(axisangle: Vector3) -> Self { Rotation3::from_scaled_axis(axisangle).to_homogeneous() } /// Creates a new rotation from Euler angles. /// /// The primitive rotations are applied in order: 1 roll − 2 pitch − 3 yaw. - pub fn from_euler_angles(roll: N, pitch: N, yaw: N) -> Self { + pub fn from_euler_angles(roll: T, pitch: T, yaw: T) -> Self { Rotation3::from_euler_angles(roll, pitch, yaw).to_homogeneous() } /// Builds a 3D homogeneous rotation matrix from an axis and a rotation angle. - pub fn from_axis_angle(axis: &Unit>, angle: N) -> Self { + pub fn from_axis_angle(axis: &Unit>, angle: T) -> Self { Rotation3::from_axis_angle(axis, angle).to_homogeneous() } /// Creates a new homogeneous matrix for an orthographic projection. #[inline] - pub fn new_orthographic(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Self { + pub fn new_orthographic(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> Self { Orthographic3::new(left, right, bottom, top, znear, zfar).into_inner() } /// Creates a new homogeneous matrix for a perspective projection. #[inline] - pub fn new_perspective(aspect: N, fovy: N, znear: N, zfar: N) -> Self { + pub fn new_perspective(aspect: T, fovy: T, znear: T, zfar: T) -> Self { Perspective3::new(aspect, fovy, znear, zfar).into_inner() } @@ -180,40 +183,40 @@ impl Matrix4 { /// It maps the view direction `target - eye` to the positive `z` axis and the origin to the /// `eye`. #[inline] - pub fn face_towards(eye: &Point3, target: &Point3, up: &Vector3) -> Self { + pub fn face_towards(eye: &Point3, target: &Point3, up: &Vector3) -> Self { IsometryMatrix3::face_towards(eye, target, up).to_homogeneous() } /// Deprecated: Use [Matrix4::face_towards] instead. #[deprecated(note = "renamed to `face_towards`")] - pub fn new_observer_frame(eye: &Point3, target: &Point3, up: &Vector3) -> Self { + pub fn new_observer_frame(eye: &Point3, target: &Point3, up: &Vector3) -> Self { Matrix4::face_towards(eye, target, up) } /// Builds a right-handed look-at view matrix. #[inline] - pub fn look_at_rh(eye: &Point3, target: &Point3, up: &Vector3) -> Self { + pub fn look_at_rh(eye: &Point3, target: &Point3, up: &Vector3) -> Self { IsometryMatrix3::look_at_rh(eye, target, up).to_homogeneous() } /// Builds a left-handed look-at view matrix. #[inline] - pub fn look_at_lh(eye: &Point3, target: &Point3, up: &Vector3) -> Self { + pub fn look_at_lh(eye: &Point3, target: &Point3, up: &Vector3) -> Self { IsometryMatrix3::look_at_lh(eye, target, up).to_homogeneous() } } /// # Append/prepend translation and scaling -impl> - SquareMatrix +impl> + SquareMatrix { /// Computes the transformation equal to `self` followed by an uniform scaling factor. #[inline] #[must_use = "Did you mean to use append_scaling_mut()?"] - pub fn append_scaling(&self, scaling: N) -> MatrixN + pub fn append_scaling(&self, scaling: T) -> OMatrix where D: DimNameSub, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let mut res = self.clone_owned(); res.append_scaling_mut(scaling); @@ -223,10 +226,10 @@ impl MatrixN + pub fn prepend_scaling(&self, scaling: T) -> OMatrix where D: DimNameSub, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let mut res = self.clone_owned(); res.prepend_scaling_mut(scaling); @@ -238,12 +241,12 @@ impl( &self, - scaling: &Vector, SB>, - ) -> MatrixN + scaling: &Vector, SB>, + ) -> OMatrix where D: DimNameSub, - SB: Storage>, - DefaultAllocator: Allocator, + SB: Storage>, + DefaultAllocator: Allocator, { let mut res = self.clone_owned(); res.append_nonuniform_scaling_mut(scaling); @@ -255,12 +258,12 @@ impl( &self, - scaling: &Vector, SB>, - ) -> MatrixN + scaling: &Vector, SB>, + ) -> OMatrix where D: DimNameSub, - SB: Storage>, - DefaultAllocator: Allocator, + SB: Storage>, + DefaultAllocator: Allocator, { let mut res = self.clone_owned(); res.prepend_nonuniform_scaling_mut(scaling); @@ -270,11 +273,14 @@ impl(&self, shift: &Vector, SB>) -> MatrixN + pub fn append_translation( + &self, + shift: &Vector, SB>, + ) -> OMatrix where D: DimNameSub, - SB: Storage>, - DefaultAllocator: Allocator, + SB: Storage>, + DefaultAllocator: Allocator, { let mut res = self.clone_owned(); res.append_translation_mut(shift); @@ -286,12 +292,12 @@ impl( &self, - shift: &Vector, SB>, - ) -> MatrixN + shift: &Vector, SB>, + ) -> OMatrix where D: DimNameSub, - SB: Storage>, - DefaultAllocator: Allocator + Allocator>, + SB: Storage>, + DefaultAllocator: Allocator + Allocator>, { let mut res = self.clone_owned(); res.prepend_translation_mut(shift); @@ -300,36 +306,36 @@ impl, + S: StorageMut, D: DimNameSub, { - let mut to_scale = self.fixed_rows_mut::>(0); + let mut to_scale = self.rows_generic_mut(0, DimNameDiff::::name()); to_scale *= scaling; } /// Computes in-place the transformation equal to an uniform scaling factor followed by `self`. #[inline] - pub fn prepend_scaling_mut(&mut self, scaling: N) + pub fn prepend_scaling_mut(&mut self, scaling: T) where - S: StorageMut, + S: StorageMut, D: DimNameSub, { - let mut to_scale = self.fixed_columns_mut::>(0); + let mut to_scale = self.columns_generic_mut(0, DimNameDiff::::name()); to_scale *= scaling; } /// Computes in-place the transformation equal to `self` followed by a non-uniform scaling factor. #[inline] - pub fn append_nonuniform_scaling_mut(&mut self, scaling: &Vector, SB>) + pub fn append_nonuniform_scaling_mut(&mut self, scaling: &Vector, SB>) where - S: StorageMut, + S: StorageMut, D: DimNameSub, - SB: Storage>, + SB: Storage>, { for i in 0..scaling.len() { - let mut to_scale = self.fixed_rows_mut::(i); + let mut to_scale = self.fixed_rows_mut::<1>(i); to_scale *= scaling[i].inlined_clone(); } } @@ -338,25 +344,25 @@ impl( &mut self, - scaling: &Vector, SB>, + scaling: &Vector, SB>, ) where - S: StorageMut, + S: StorageMut, D: DimNameSub, - SB: Storage>, + SB: Storage>, { for i in 0..scaling.len() { - let mut to_scale = self.fixed_columns_mut::(i); + let mut to_scale = self.fixed_columns_mut::<1>(i); to_scale *= scaling[i].inlined_clone(); } } /// Computes the transformation equal to `self` followed by a translation. #[inline] - pub fn append_translation_mut(&mut self, shift: &Vector, SB>) + pub fn append_translation_mut(&mut self, shift: &Vector, SB>) where - S: StorageMut, + S: StorageMut, D: DimNameSub, - SB: Storage>, + SB: Storage>, { for i in 0..D::dim() { for j in 0..D::dim() - 1 { @@ -368,41 +374,55 @@ impl(&mut self, shift: &Vector, SB>) + pub fn prepend_translation_mut(&mut self, shift: &Vector, SB>) where D: DimNameSub, - S: StorageMut, - SB: Storage>, - DefaultAllocator: Allocator>, + S: StorageMut, + SB: Storage>, + DefaultAllocator: Allocator>, { let scale = self - .fixed_slice::>(D::dim() - 1, 0) + .generic_slice( + (D::dim() - 1, 0), + (Const::<1>, DimNameDiff::::name()), + ) .tr_dot(&shift); - let post_translation = - self.fixed_slice::, DimNameDiff>(0, 0) * shift; + let post_translation = self.generic_slice( + (0, 0), + (DimNameDiff::::name(), DimNameDiff::::name()), + ) * shift; self[(D::dim() - 1, D::dim() - 1)] += scale; - let mut translation = self.fixed_slice_mut::, U1>(0, D::dim() - 1); + let mut translation = self.generic_slice_mut( + (0, D::dim() - 1), + (DimNameDiff::::name(), Const::<1>), + ); translation += post_translation; } } /// # Transformation of vectors and points -impl, S: Storage> SquareMatrix +impl, S: Storage> SquareMatrix where - DefaultAllocator: Allocator - + Allocator> - + Allocator, DimNameDiff>, + DefaultAllocator: Allocator + + Allocator> + + Allocator, DimNameDiff>, { /// Transforms the given vector, assuming the matrix `self` uses homogeneous coordinates. #[inline] pub fn transform_vector( &self, - v: &VectorN>, - ) -> VectorN> { - let transform = self.fixed_slice::, DimNameDiff>(0, 0); - let normalizer = self.fixed_slice::>(D::dim() - 1, 0); + v: &OVector>, + ) -> OVector> { + let transform = self.generic_slice( + (0, 0), + (DimNameDiff::::name(), DimNameDiff::::name()), + ); + let normalizer = self.generic_slice( + (D::dim() - 1, 0), + (Const::<1>, DimNameDiff::::name()), + ); let n = normalizer.tr_dot(&v); if !n.is_zero() { @@ -413,13 +433,13 @@ where } } -impl, Const<3>>> SquareMatrix, S> { +impl, Const<3>>> SquareMatrix, S> { /// Transforms the given point, assuming the matrix `self` uses homogeneous coordinates. #[inline] - pub fn transform_point(&self, pt: &Point) -> Point { - let transform = self.fixed_slice::, Const<2>>(0, 0); - let translation = self.fixed_slice::, U1>(0, 2); - let normalizer = self.fixed_slice::>(2, 0); + pub fn transform_point(&self, pt: &Point) -> Point { + let transform = self.fixed_slice::<2, 2>(0, 0); + let translation = self.fixed_slice::<2, 1>(0, 2); + let normalizer = self.fixed_slice::<1, 2>(2, 0); let n = normalizer.tr_dot(&pt.coords) + unsafe { *self.get_unchecked((2, 2)) }; if !n.is_zero() { @@ -430,13 +450,13 @@ impl, Const<3>>> SquareMatrix, } } -impl, Const<4>>> SquareMatrix, S> { +impl, Const<4>>> SquareMatrix, S> { /// Transforms the given point, assuming the matrix `self` uses homogeneous coordinates. #[inline] - pub fn transform_point(&self, pt: &Point) -> Point { - let transform = self.fixed_slice::, Const<3>>(0, 0); - let translation = self.fixed_slice::, U1>(0, 3); - let normalizer = self.fixed_slice::>(3, 0); + pub fn transform_point(&self, pt: &Point) -> Point { + let transform = self.fixed_slice::<3, 3>(0, 0); + let translation = self.fixed_slice::<3, 1>(0, 3); + let normalizer = self.fixed_slice::<1, 3>(3, 0); let n = normalizer.tr_dot(&pt.coords) + unsafe { *self.get_unchecked((3, 3)) }; if !n.is_zero() { diff --git a/src/base/componentwise.rs b/src/base/componentwise.rs index dcc4ece1..b7030f61 100644 --- a/src/base/componentwise.rs +++ b/src/base/componentwise.rs @@ -10,13 +10,13 @@ use crate::base::allocator::{Allocator, SameShapeAllocator}; use crate::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; use crate::base::dimension::Dim; use crate::base::storage::{Storage, StorageMut}; -use crate::base::{DefaultAllocator, Matrix, MatrixMN, MatrixSum, Scalar}; +use crate::base::{DefaultAllocator, Matrix, MatrixSum, OMatrix, Scalar}; use crate::ClosedAdd; /// The type of the result of a matrix component-wise operation. -pub type MatrixComponentOp = MatrixSum; +pub type MatrixComponentOp = MatrixSum; -impl> Matrix { +impl> Matrix { /// Computes the component-wise absolute value. /// /// # Example @@ -28,10 +28,10 @@ impl> Matrix { /// assert_eq!(a.abs(), Matrix2::new(0.0, 1.0, 2.0, 3.0)) /// ``` #[inline] - pub fn abs(&self) -> MatrixMN + pub fn abs(&self) -> OMatrix where - N: Signed, - DefaultAllocator: Allocator, + T: Signed, + DefaultAllocator: Allocator, { let mut res = self.clone_owned(); @@ -49,11 +49,11 @@ macro_rules! component_binop_impl( ($($binop: ident, $binop_mut: ident, $binop_assign: ident, $cmpy: ident, $Trait: ident . $op: ident . $op_assign: ident, $desc:expr, $desc_cmpy:expr, $desc_mut:expr);* $(;)*) => {$( #[doc = $desc] #[inline] - pub fn $binop(&self, rhs: &Matrix) -> MatrixComponentOp - where N: $Trait, + pub fn $binop(&self, rhs: &Matrix) -> MatrixComponentOp + where T: $Trait, R2: Dim, C2: Dim, - SB: Storage, - DefaultAllocator: SameShapeAllocator, + SB: Storage, + DefaultAllocator: SameShapeAllocator, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns { assert_eq!(self.shape(), rhs.shape(), "Componentwise mul/div: mismatched matrix dimensions."); @@ -73,13 +73,13 @@ macro_rules! component_binop_impl( // componentwise binop plus Y. #[doc = $desc_cmpy] #[inline] - pub fn $cmpy(&mut self, alpha: N, a: &Matrix, b: &Matrix, beta: N) - where N: $Trait + Zero + Mul + Add, + pub fn $cmpy(&mut self, alpha: T, a: &Matrix, b: &Matrix, beta: T) + where T: $Trait + Zero + Mul + Add, R2: Dim, C2: Dim, R3: Dim, C3: Dim, - SA: StorageMut, - SB: Storage, - SC: Storage, + SA: StorageMut, + SB: Storage, + SC: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns + SameNumberOfRows + SameNumberOfColumns { assert_eq!(self.shape(), a.shape(), "Componentwise mul/div: mismatched matrix dimensions."); @@ -109,12 +109,12 @@ macro_rules! component_binop_impl( #[doc = $desc_mut] #[inline] - pub fn $binop_assign(&mut self, rhs: &Matrix) - where N: $Trait, + pub fn $binop_assign(&mut self, rhs: &Matrix) + where T: $Trait, R2: Dim, C2: Dim, - SA: StorageMut, - SB: Storage, + SA: StorageMut, + SB: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns { assert_eq!(self.shape(), rhs.shape(), "Componentwise mul/div: mismatched matrix dimensions."); @@ -131,12 +131,12 @@ macro_rules! component_binop_impl( #[doc = $desc_mut] #[inline] #[deprecated(note = "This is renamed using the `_assign` suffix instead of the `_mut` suffix.")] - pub fn $binop_mut(&mut self, rhs: &Matrix) - where N: $Trait, + pub fn $binop_mut(&mut self, rhs: &Matrix) + where T: $Trait, R2: Dim, C2: Dim, - SA: StorageMut, - SB: Storage, + SA: StorageMut, + SB: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns { self.$binop_assign(rhs) } @@ -144,7 +144,7 @@ macro_rules! component_binop_impl( ); /// # Componentwise operations -impl> Matrix { +impl> Matrix { component_binop_impl!( component_mul, component_mul_mut, component_mul_assign, cmpy, ClosedMul.mul.mul_assign, r" @@ -241,30 +241,30 @@ impl> Matrix /// Computes the infimum (aka. componentwise min) of two matrices/vectors. #[inline] - pub fn inf(&self, other: &Self) -> MatrixMN + pub fn inf(&self, other: &Self) -> OMatrix where - N: SimdPartialOrd, - DefaultAllocator: Allocator, + T: SimdPartialOrd, + DefaultAllocator: Allocator, { self.zip_map(other, |a, b| a.simd_min(b)) } /// Computes the supremum (aka. componentwise max) of two matrices/vectors. #[inline] - pub fn sup(&self, other: &Self) -> MatrixMN + pub fn sup(&self, other: &Self) -> OMatrix where - N: SimdPartialOrd, - DefaultAllocator: Allocator, + T: SimdPartialOrd, + DefaultAllocator: Allocator, { self.zip_map(other, |a, b| a.simd_max(b)) } /// Computes the (infimum, supremum) of two matrices/vectors. #[inline] - pub fn inf_sup(&self, other: &Self) -> (MatrixMN, MatrixMN) + pub fn inf_sup(&self, other: &Self) -> (OMatrix, OMatrix) where - N: SimdPartialOrd, - DefaultAllocator: Allocator, + T: SimdPartialOrd, + DefaultAllocator: Allocator, { // TODO: can this be optimized? (self.inf(other), self.sup(other)) @@ -273,10 +273,10 @@ impl> Matrix /// Adds a scalar to `self`. #[inline] #[must_use = "Did you mean to use add_scalar_mut()?"] - pub fn add_scalar(&self, rhs: N) -> MatrixMN + pub fn add_scalar(&self, rhs: T) -> OMatrix where - N: ClosedAdd, - DefaultAllocator: Allocator, + T: ClosedAdd, + DefaultAllocator: Allocator, { let mut res = self.clone_owned(); res.add_scalar_mut(rhs); @@ -285,10 +285,10 @@ impl> Matrix /// Adds a scalar to `self` in-place. #[inline] - pub fn add_scalar_mut(&mut self, rhs: N) + pub fn add_scalar_mut(&mut self, rhs: T) where - N: ClosedAdd, - SA: StorageMut, + T: ClosedAdd, + SA: StorageMut, { for e in self.iter_mut() { *e += rhs.inlined_clone() diff --git a/src/base/construction.rs b/src/base/construction.rs index a48e57a2..ef9d7c0f 100644 --- a/src/base/construction.rs +++ b/src/base/construction.rs @@ -22,9 +22,7 @@ use simba::scalar::{ClosedAdd, ClosedMul}; use crate::base::allocator::Allocator; use crate::base::dimension::{Dim, DimName, Dynamic, ToTypenum}; use crate::base::storage::Storage; -use crate::base::{ - Const, DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar, Unit, Vector, VectorN, -}; +use crate::base::{Const, DefaultAllocator, Matrix, OMatrix, OVector, Scalar, Unit, Vector}; /// When "no_unsound_assume_init" is enabled, expands to `unimplemented!()` instead of `new_uninitialized_generic().assume_init()`. /// Intended as a placeholder, each callsite should be refactored to use uninitialized memory soundly @@ -33,7 +31,7 @@ macro_rules! unimplemented_or_uninitialized_generic { ($nrows:expr, $ncols:expr) => {{ #[cfg(feature="no_unsound_assume_init")] { // Some of the call sites need the number of rows and columns from this to infer a type, so - // uninitialized memory is used to infer the type, as `N: Zero` isn't available at all callsites. + // uninitialized memory is used to infer the type, as `T: Zero` isn't available at all callsites. // This may technically still be UB even though the assume_init is dead code, but all callsites should be fixed before #556 is closed. let typeinference_helper = crate::base::Matrix::new_uninitialized_generic($nrows, $ncols); unimplemented!(); @@ -49,9 +47,9 @@ macro_rules! unimplemented_or_uninitialized_generic { /// the dimension as inputs. /// /// These functions should only be used when working on dimension-generic code. -impl MatrixMN +impl OMatrix where - DefaultAllocator: Allocator, + 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()`. @@ -62,7 +60,7 @@ where /// Creates a matrix with all its elements set to `elem`. #[inline] - pub fn from_element_generic(nrows: R, ncols: C, elem: N) -> Self { + pub fn from_element_generic(nrows: R, ncols: C, elem: T) -> Self { let len = nrows.value() * ncols.value(); Self::from_iterator_generic(nrows, ncols, iter::repeat(elem).take(len)) } @@ -71,7 +69,7 @@ where /// /// Same as `from_element_generic`. #[inline] - pub fn repeat_generic(nrows: R, ncols: C, elem: N) -> Self { + pub fn repeat_generic(nrows: R, ncols: C, elem: T) -> Self { let len = nrows.value() * ncols.value(); Self::from_iterator_generic(nrows, ncols, iter::repeat(elem).take(len)) } @@ -80,16 +78,16 @@ where #[inline] pub fn zeros_generic(nrows: R, ncols: C) -> Self where - N: Zero, + T: Zero, { - Self::from_element_generic(nrows, ncols, N::zero()) + Self::from_element_generic(nrows, ncols, T::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, + I: IntoIterator, { Self::from_data(DefaultAllocator::allocate_from_iterator(nrows, ncols, iter)) } @@ -100,7 +98,7 @@ where /// The order of elements in the slice must follow the usual mathematic writing, i.e., /// row-by-row. #[inline] - pub fn from_row_slice_generic(nrows: R, ncols: C, slice: &[N]) -> Self { + pub fn from_row_slice_generic(nrows: R, ncols: C, slice: &[T]) -> Self { assert!( slice.len() == nrows.value() * ncols.value(), "Matrix init. error: the slice did not contain the right number of elements." @@ -121,7 +119,7 @@ where /// Creates a matrix with its elements filled with the components provided by a slice. The /// components must have the same layout as the matrix data storage (i.e. column-major). #[inline] - pub fn from_column_slice_generic(nrows: R, ncols: C, slice: &[N]) -> Self { + pub fn from_column_slice_generic(nrows: R, ncols: C, slice: &[T]) -> Self { Self::from_iterator_generic(nrows, ncols, slice.iter().cloned()) } @@ -130,7 +128,7 @@ where #[inline] pub fn from_fn_generic(nrows: R, ncols: C, mut f: F) -> Self where - F: FnMut(usize, usize) -> N, + F: FnMut(usize, usize) -> T, { let mut res: Self = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; @@ -150,9 +148,9 @@ where #[inline] pub fn identity_generic(nrows: R, ncols: C) -> Self where - N: Zero + One, + T: Zero + One, { - Self::from_diagonal_element_generic(nrows, ncols, N::one()) + Self::from_diagonal_element_generic(nrows, ncols, T::one()) } /// Creates a new matrix with its diagonal filled with copies of `elt`. @@ -160,9 +158,9 @@ where /// If the matrix is not square, the largest square submatrix starting at index `(0, 0)` is set /// 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 + pub fn from_diagonal_element_generic(nrows: R, ncols: C, elt: T) -> Self where - N: Zero + One, + T: Zero + One, { let mut res = Self::zeros_generic(nrows, ncols); @@ -178,9 +176,9 @@ 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 + pub fn from_partial_diagonal_generic(nrows: R, ncols: C, elts: &[T]) -> Self where - N: Zero, + T: Zero, { let mut res = Self::zeros_generic(nrows, ncols); assert!( @@ -212,9 +210,9 @@ where /// m.m31 == 7.0 && m.m32 == 8.0 && m.m33 == 9.0); /// ``` #[inline] - pub fn from_rows(rows: &[Matrix, C, SB>]) -> Self + pub fn from_rows(rows: &[Matrix, C, SB>]) -> Self where - SB: Storage, C>, + SB: Storage, C>, { assert!(!rows.is_empty(), "At least one row must be given."); let nrows = R::try_to_usize().unwrap_or_else(|| rows.len()); @@ -254,9 +252,9 @@ where /// m.m31 == 3.0 && m.m32 == 6.0 && m.m33 == 9.0); /// ``` #[inline] - pub fn from_columns(columns: &[Vector]) -> Self + pub fn from_columns(columns: &[Vector]) -> Self where - SB: Storage, + SB: Storage, { assert!(!columns.is_empty(), "At least one column must be given."); let ncols = C::try_to_usize().unwrap_or_else(|| columns.len()); @@ -284,7 +282,7 @@ where #[cfg(feature = "rand")] pub fn new_random_generic(nrows: R, ncols: C) -> Self where - Standard: Distribution, + Standard: Distribution, { let mut rng = rand::thread_rng(); Self::from_fn_generic(nrows, ncols, |_, _| rng.gen()) @@ -293,7 +291,7 @@ where /// Creates a matrix filled with random values from the given distribution. #[inline] #[cfg(feature = "rand-no-std")] - pub fn from_distribution_generic + ?Sized, G: Rng + ?Sized>( + pub fn from_distribution_generic + ?Sized, G: Rng + ?Sized>( nrows: R, ncols: C, distribution: &Distr, @@ -321,15 +319,15 @@ where /// ``` #[inline] #[cfg(any(feature = "std", feature = "alloc"))] - pub fn from_vec_generic(nrows: R, ncols: C, data: Vec) -> Self { + pub fn from_vec_generic(nrows: R, ncols: C, data: Vec) -> Self { Self::from_iterator_generic(nrows, ncols, data) } } -impl MatrixN +impl OMatrix where - N: Scalar, - DefaultAllocator: Allocator, + T: Scalar, + DefaultAllocator: Allocator, { /// Creates a square matrix with its diagonal set to `diag` and all other entries set to 0. /// @@ -350,9 +348,9 @@ where /// dm[(2, 0)] == 0.0 && dm[(2, 1)] == 0.0 && dm[(2, 2)] == 3.0); /// ``` #[inline] - pub fn from_diagonal>(diag: &Vector) -> Self + pub fn from_diagonal>(diag: &Vector) -> Self where - N: Zero, + T: Zero, { let (dim, _) = diag.data.shape(); let mut res = Self::zeros_generic(dim, dim); @@ -401,7 +399,7 @@ macro_rules! impl_constructors( /// dm[(1, 0)] == 2.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 2.0); /// ``` #[inline] - pub fn from_element($($args: usize,)* elem: N) -> Self { + pub fn from_element($($args: usize,)* elem: T) -> Self { Self::from_element_generic($($gargs, )* elem) } @@ -428,7 +426,7 @@ macro_rules! impl_constructors( /// dm[(1, 0)] == 2.0 && dm[(1, 1)] == 2.0 && dm[(1, 2)] == 2.0); /// ``` #[inline] - pub fn repeat($($args: usize,)* elem: N) -> Self { + pub fn repeat($($args: usize,)* elem: T) -> Self { Self::repeat_generic($($gargs, )* elem) } @@ -454,7 +452,7 @@ macro_rules! impl_constructors( /// ``` #[inline] pub fn zeros($($args: usize),*) -> Self - where N: Zero { + where T: Zero { Self::zeros_generic($($gargs),*) } @@ -483,7 +481,7 @@ macro_rules! impl_constructors( /// ``` #[inline] pub fn from_iterator($($args: usize,)* iter: I) -> Self - where I: IntoIterator { + where I: IntoIterator { Self::from_iterator_generic($($gargs, )* iter) } @@ -511,7 +509,7 @@ macro_rules! impl_constructors( /// ``` #[inline] pub fn from_fn($($args: usize,)* f: F) -> Self - where F: FnMut(usize, usize) -> N { + where F: FnMut(usize, usize) -> T { Self::from_fn_generic($($gargs, )* f) } @@ -535,7 +533,7 @@ macro_rules! impl_constructors( /// ``` #[inline] pub fn identity($($args: usize,)*) -> Self - where N: Zero + One { + where T: Zero + One { Self::identity_generic($($gargs),* ) } @@ -557,8 +555,8 @@ macro_rules! impl_constructors( /// dm[(1, 0)] == 0.0 && dm[(1, 1)] == 5.0 && dm[(1, 2)] == 0.0); /// ``` #[inline] - pub fn from_diagonal_element($($args: usize,)* elt: N) -> Self - where N: Zero + One { + pub fn from_diagonal_element($($args: usize,)* elt: T) -> Self + where T: Zero + One { Self::from_diagonal_element_generic($($gargs, )* elt) } @@ -584,15 +582,15 @@ macro_rules! impl_constructors( /// dm[(2, 0)] == 0.0 && dm[(2, 1)] == 0.0 && dm[(2, 2)] == 0.0); /// ``` #[inline] - pub fn from_partial_diagonal($($args: usize,)* elts: &[N]) -> Self - where N: Zero { + pub fn from_partial_diagonal($($args: usize,)* elts: &[T]) -> Self + where T: Zero { Self::from_partial_diagonal_generic($($gargs, )* elts) } /// Creates a matrix or vector filled with random values from the given distribution. #[inline] #[cfg(feature = "rand-no-std")] - pub fn from_distribution + ?Sized, G: Rng + ?Sized>( + pub fn from_distribution + ?Sized, G: Rng + ?Sized>( $($args: usize,)* distribution: &Distr, rng: &mut G, @@ -604,28 +602,28 @@ macro_rules! impl_constructors( #[inline] #[cfg(feature = "rand")] pub fn new_random($($args: usize),*) -> Self - where Standard: Distribution { + where Standard: Distribution { Self::new_random_generic($($gargs),*) } } ); /// # Constructors of statically-sized vectors or statically-sized matrices -impl MatrixMN +impl OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - // TODO: this is not very pretty. We could find a better call syntax. - impl_constructors!(R, C; // Arguments for Matrix - => R: DimName, => C: DimName; // Type parameters for impl + // TODO: this is not very pretty. We could find a better call syntax. + impl_constructors!(R, C; // Arguments for Matrix + => R: DimName, => C: DimName; // Type parameters for impl R::name(), C::name(); // Arguments for `_generic` constructors. ); // Arguments for non-generic constructors. } /// # Constructors of matrices with a dynamic number of columns -impl MatrixMN +impl OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { impl_constructors!(R, Dynamic; => R: DimName; @@ -634,9 +632,9 @@ where } /// # Constructors of dynamic vectors and matrices with a dynamic number of rows -impl MatrixMN +impl OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { impl_constructors!(Dynamic, C; => C: DimName; @@ -645,9 +643,9 @@ where } /// # Constructors of fully dynamic matrices -impl MatrixMN +impl OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { impl_constructors!(Dynamic, Dynamic; ; @@ -663,8 +661,8 @@ where */ macro_rules! impl_constructors_from_data( ($data: ident; $($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => { - impl MatrixMN - where DefaultAllocator: Allocator { + impl OMatrix + where DefaultAllocator: Allocator { /// Creates a matrix with its elements filled with the components provided by a slice /// in row-major order. /// @@ -691,7 +689,7 @@ macro_rules! impl_constructors_from_data( /// dm[(1, 0)] == 3 && dm[(1, 1)] == 4 && dm[(1, 2)] == 5); /// ``` #[inline] - pub fn from_row_slice($($args: usize,)* $data: &[N]) -> Self { + pub fn from_row_slice($($args: usize,)* $data: &[T]) -> Self { Self::from_row_slice_generic($($gargs, )* $data) } @@ -718,7 +716,7 @@ macro_rules! impl_constructors_from_data( /// dm[(1, 0)] == 1 && dm[(1, 1)] == 3 && dm[(1, 2)] == 5); /// ``` #[inline] - pub fn from_column_slice($($args: usize,)* $data: &[N]) -> Self { + pub fn from_column_slice($($args: usize,)* $data: &[T]) -> Self { Self::from_column_slice_generic($($gargs, )* $data) } @@ -744,7 +742,7 @@ macro_rules! impl_constructors_from_data( /// ``` #[inline] #[cfg(any(feature = "std", feature = "alloc"))] - pub fn from_vec($($args: usize,)* $data: Vec) -> Self { + pub fn from_vec($($args: usize,)* $data: Vec) -> Self { Self::from_vec_generic($($gargs, )* $data) } } @@ -752,8 +750,8 @@ macro_rules! impl_constructors_from_data( ); // TODO: this is not very pretty. We could find a better call syntax. -impl_constructors_from_data!(data; R, C; // Arguments for Matrix -=> R: DimName, => C: DimName; // Type parameters for impl +impl_constructors_from_data!(data; R, C; // Arguments for Matrix +=> R: DimName, => C: DimName; // Type parameters for impl R::name(), C::name(); // Arguments for `_generic` constructors. ); // Arguments for non-generic constructors. @@ -777,14 +775,14 @@ impl_constructors_from_data!(data; Dynamic, Dynamic; * Zero, One, Rand traits. * */ -impl Zero for MatrixMN +impl Zero for OMatrix where - N: Scalar + Zero + ClosedAdd, - DefaultAllocator: Allocator, + T: Scalar + Zero + ClosedAdd, + DefaultAllocator: Allocator, { #[inline] fn zero() -> Self { - Self::from_element(N::zero()) + Self::from_element(T::zero()) } #[inline] @@ -793,10 +791,10 @@ where } } -impl One for MatrixN +impl One for OMatrix where - N: Scalar + Zero + One + ClosedMul + ClosedAdd, - DefaultAllocator: Allocator, + T: Scalar + Zero + One + ClosedMul + ClosedAdd, + DefaultAllocator: Allocator, { #[inline] fn one() -> Self { @@ -804,45 +802,45 @@ where } } -impl Bounded for MatrixMN +impl Bounded for OMatrix where - N: Scalar + Bounded, - DefaultAllocator: Allocator, + T: Scalar + Bounded, + DefaultAllocator: Allocator, { #[inline] fn max_value() -> Self { - Self::from_element(N::max_value()) + Self::from_element(T::max_value()) } #[inline] fn min_value() -> Self { - Self::from_element(N::min_value()) + Self::from_element(T::min_value()) } } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - DefaultAllocator: Allocator, - Standard: Distribution, + DefaultAllocator: Allocator, + Standard: Distribution, { #[inline] - fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> MatrixMN { + fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> OMatrix { let nrows = R::try_to_usize().unwrap_or_else(|| rng.gen_range(0..10)); let ncols = C::try_to_usize().unwrap_or_else(|| rng.gen_range(0..10)); - MatrixMN::from_fn_generic(R::from_usize(nrows), C::from_usize(ncols), |_, _| rng.gen()) + OMatrix::from_fn_generic(R::from_usize(nrows), C::from_usize(ncols), |_, _| rng.gen()) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for MatrixMN +impl Arbitrary for OMatrix where R: Dim, C: Dim, - N: Scalar + Arbitrary + Send, - DefaultAllocator: Allocator, - Owned: Clone + Send, + T: Scalar + Arbitrary + Send, + DefaultAllocator: Allocator, + Owned: Clone + Send, { #[inline] fn arbitrary(g: &mut Gen) -> Self { @@ -850,22 +848,22 @@ where let ncols = C::try_to_usize().unwrap_or(usize::arbitrary(g) % 10); Self::from_fn_generic(R::from_usize(nrows), C::from_usize(ncols), |_, _| { - N::arbitrary(g) + T::arbitrary(g) }) } } // TODO(specialization): faster impls possible for D≤4 (see rand_distr::{UnitCircle, UnitSphere}) #[cfg(feature = "rand")] -impl Distribution>> for Standard +impl Distribution>> for Standard where - DefaultAllocator: Allocator, - rand_distr::StandardNormal: Distribution, + DefaultAllocator: Allocator, + rand_distr::StandardNormal: Distribution, { /// Generate a uniformly distributed random unit vector. #[inline] - fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Unit> { - Unit::new_normalize(VectorN::from_distribution_generic( + fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Unit> { + Unit::new_normalize(OVector::from_distribution_generic( D::name(), Const::<1>, &rand_distr::StandardNormal, @@ -881,12 +879,12 @@ where */ macro_rules! componentwise_constructors_impl( ($($R: expr, $C: expr, $($args: ident:($irow: expr,$icol: expr)),*);* $(;)*) => {$( - impl MatrixMN, Const<$C>> - where N: Scalar, - DefaultAllocator: Allocator, Const<$C>> { + impl OMatrix, Const<$C>> + where T: Scalar, + DefaultAllocator: Allocator, Const<$C>> { /// Initializes this matrix from its components. #[inline] - pub fn new($($args: N),*) -> Self { + pub fn new($($args: T),*) -> Self { unsafe { #[cfg(feature="no_unsound_assume_init")] let mut res: Self = unimplemented!(); @@ -1051,24 +1049,24 @@ componentwise_constructors_impl!( * Axis constructors. * */ -impl VectorN +impl OVector where R: ToTypenum, - N: Scalar + Zero + One, - DefaultAllocator: Allocator, + T: Scalar + Zero + One, + DefaultAllocator: Allocator, { /// The column vector with `val` as its i-th component. #[inline] - pub fn ith(i: usize, val: N) -> Self { + pub fn ith(i: usize, val: T) -> Self { let mut res = Self::zeros(); res[i] = val; res } - /// The column unit vector with `N::one()` as its i-th component. + /// The column unit vector with `T::one()` as its i-th component. #[inline] pub fn ith_axis(i: usize) -> Unit { - Unit::new_unchecked(Self::ith(i, N::one())) + Unit::new_unchecked(Self::ith(i, T::one())) } /// The column vector with a 1 as its first component, and zero elsewhere. @@ -1079,7 +1077,7 @@ where { let mut res = Self::zeros(); unsafe { - *res.vget_unchecked_mut(0) = N::one(); + *res.vget_unchecked_mut(0) = T::one(); } res @@ -1093,7 +1091,7 @@ where { let mut res = Self::zeros(); unsafe { - *res.vget_unchecked_mut(1) = N::one(); + *res.vget_unchecked_mut(1) = T::one(); } res @@ -1107,7 +1105,7 @@ where { let mut res = Self::zeros(); unsafe { - *res.vget_unchecked_mut(2) = N::one(); + *res.vget_unchecked_mut(2) = T::one(); } res @@ -1121,7 +1119,7 @@ where { let mut res = Self::zeros(); unsafe { - *res.vget_unchecked_mut(3) = N::one(); + *res.vget_unchecked_mut(3) = T::one(); } res @@ -1135,7 +1133,7 @@ where { let mut res = Self::zeros(); unsafe { - *res.vget_unchecked_mut(4) = N::one(); + *res.vget_unchecked_mut(4) = T::one(); } res @@ -1149,7 +1147,7 @@ where { let mut res = Self::zeros(); unsafe { - *res.vget_unchecked_mut(5) = N::one(); + *res.vget_unchecked_mut(5) = T::one(); } res diff --git a/src/base/construction_slice.rs b/src/base/construction_slice.rs index 82ccf69e..43f3692b 100644 --- a/src/base/construction_slice.rs +++ b/src/base/construction_slice.rs @@ -1,12 +1,12 @@ use crate::base::dimension::{Const, Dim, DimName, Dynamic}; use crate::base::matrix_slice::{SliceStorage, SliceStorageMut}; -use crate::base::{MatrixSliceMN, MatrixSliceMutMN, Scalar}; +use crate::base::{MatrixSlice, MatrixSliceMutMN, Scalar}; use num_rational::Ratio; /// # Creating matrix slices from `&[T]` -impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> - MatrixSliceMN<'a, N, R, C, RStride, CStride> +impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> + MatrixSlice<'a, T, R, C, RStride, CStride> { /// Creates, without bound-checking, a matrix slice from an array and with dimensions and strides specified by generic types instances. /// @@ -14,7 +14,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> /// The generic types `R`, `C`, `RStride`, `CStride` can either be type-level integers or integers wrapped with `Dynamic::new()`. #[inline] pub unsafe fn from_slice_with_strides_generic_unchecked( - data: &'a [N], + data: &'a [T], start: usize, nrows: R, ncols: C, @@ -35,7 +35,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> /// The generic types `R`, `C`, `RStride`, `CStride` can either be type-level integers or integers wrapped with `Dynamic::new()`. #[inline] pub fn from_slice_with_strides_generic( - data: &'a [N], + data: &'a [T], nrows: R, ncols: C, rstride: RStride, @@ -56,14 +56,14 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> } } -impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMN<'a, N, R, C> { +impl<'a, T: Scalar, R: Dim, C: Dim> MatrixSlice<'a, T, R, C> { /// Creates, without bound-checking, a matrix slice from an array and with dimensions specified by generic types instances. /// /// This method is unsafe because the input data array is not checked to contain enough elements. /// The generic types `R` and `C` can either be type-level integers or integers wrapped with `Dynamic::new()`. #[inline] pub unsafe fn from_slice_generic_unchecked( - data: &'a [N], + data: &'a [T], start: usize, nrows: R, ncols: C, @@ -78,41 +78,41 @@ impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMN<'a, N, R, C> { /// Panics if the input data array dose not contain enough elements. /// The generic types `R` and `C` can either be type-level integers or integers wrapped with `Dynamic::new()`. #[inline] - pub fn from_slice_generic(data: &'a [N], nrows: R, ncols: C) -> Self { + pub fn from_slice_generic(data: &'a [T], nrows: R, ncols: C) -> Self { Self::from_slice_with_strides_generic(data, nrows, ncols, Const::<1>, nrows) } } macro_rules! impl_constructors( ($($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => { - impl<'a, N: Scalar, $($DimIdent: $DimBound),*> MatrixSliceMN<'a, N, $($Dims),*> { + impl<'a, T: Scalar, $($DimIdent: $DimBound),*> MatrixSlice<'a, T, $($Dims),*> { /// Creates a new matrix slice from the given data array. /// /// Panics if `data` does not contain enough elements. #[inline] - pub fn from_slice(data: &'a [N], $($args: usize),*) -> Self { + pub fn from_slice(data: &'a [T], $($args: usize),*) -> Self { Self::from_slice_generic(data, $($gargs),*) } /// Creates, without bound checking, a new matrix slice from the given data array. #[inline] - pub unsafe fn from_slice_unchecked(data: &'a [N], start: usize, $($args: usize),*) -> Self { + pub unsafe fn from_slice_unchecked(data: &'a [T], start: usize, $($args: usize),*) -> Self { Self::from_slice_generic_unchecked(data, start, $($gargs),*) } } - impl<'a, N: Scalar, $($DimIdent: $DimBound, )*> MatrixSliceMN<'a, N, $($Dims,)* Dynamic, Dynamic> { + impl<'a, T: Scalar, $($DimIdent: $DimBound, )*> MatrixSlice<'a, T, $($Dims,)* Dynamic, Dynamic> { /// Creates a new matrix slice with the specified strides from the given data array. /// /// Panics if `data` does not contain enough elements. #[inline] - pub fn from_slice_with_strides(data: &'a [N], $($args: usize,)* rstride: usize, cstride: usize) -> Self { + pub fn from_slice_with_strides(data: &'a [T], $($args: usize,)* rstride: usize, cstride: usize) -> Self { Self::from_slice_with_strides_generic(data, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride)) } /// Creates, without bound checking, a new matrix slice with the specified strides from the given data array. #[inline] - pub unsafe fn from_slice_with_strides_unchecked(data: &'a [N], start: usize, $($args: usize,)* rstride: usize, cstride: usize) -> Self { + pub unsafe fn from_slice_with_strides_unchecked(data: &'a [T], start: usize, $($args: usize,)* rstride: usize, cstride: usize) -> Self { Self::from_slice_with_strides_generic_unchecked(data, start, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride)) } } @@ -120,8 +120,8 @@ macro_rules! impl_constructors( ); // TODO: this is not very pretty. We could find a better call syntax. -impl_constructors!(R, C; // Arguments for Matrix -=> R: DimName, => C: DimName; // Type parameters for impl +impl_constructors!(R, C; // Arguments for Matrix +=> R: DimName, => C: DimName; // Type parameters for impl R::name(), C::name(); // Arguments for `_generic` constructors. ); // Arguments for non-generic constructors. @@ -141,8 +141,8 @@ impl_constructors!(Dynamic, Dynamic; nrows, ncols); /// # Creating mutable matrix slices from `&mut [T]` -impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> - MatrixSliceMutMN<'a, N, R, C, RStride, CStride> +impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> + MatrixSliceMutMN<'a, T, R, C, RStride, CStride> { /// Creates, without bound-checking, a mutable matrix slice from an array and with dimensions and strides specified by generic types instances. /// @@ -150,7 +150,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> /// The generic types `R`, `C`, `RStride`, `CStride` can either be type-level integers or integers wrapped with `Dynamic::new()`. #[inline] pub unsafe fn from_slice_with_strides_generic_unchecked( - data: &'a mut [N], + data: &'a mut [T], start: usize, nrows: R, ncols: C, @@ -171,7 +171,7 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> /// The generic types `R`, `C`, `RStride`, `CStride` can either be type-level integers or integers wrapped with `Dynamic::new()`. #[inline] pub fn from_slice_with_strides_generic( - data: &'a mut [N], + data: &'a mut [T], nrows: R, ncols: C, rstride: RStride, @@ -214,14 +214,14 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> } } -impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMutMN<'a, N, R, C> { +impl<'a, T: Scalar, R: Dim, C: Dim> MatrixSliceMutMN<'a, T, R, C> { /// Creates, without bound-checking, a mutable matrix slice from an array and with dimensions specified by generic types instances. /// /// This method is unsafe because the input data array is not checked to contain enough elements. /// The generic types `R` and `C` can either be type-level integers or integers wrapped with `Dynamic::new()`. #[inline] pub unsafe fn from_slice_generic_unchecked( - data: &'a mut [N], + data: &'a mut [T], start: usize, nrows: R, ncols: C, @@ -236,42 +236,42 @@ impl<'a, N: Scalar, R: Dim, C: Dim> MatrixSliceMutMN<'a, N, R, C> { /// Panics if the input data array dose not contain enough elements. /// The generic types `R` and `C` can either be type-level integers or integers wrapped with `Dynamic::new()`. #[inline] - pub fn from_slice_generic(data: &'a mut [N], nrows: R, ncols: C) -> Self { + pub fn from_slice_generic(data: &'a mut [T], nrows: R, ncols: C) -> Self { Self::from_slice_with_strides_generic(data, nrows, ncols, Const::<1>, nrows) } } macro_rules! impl_constructors_mut( ($($Dims: ty),*; $(=> $DimIdent: ident: $DimBound: ident),*; $($gargs: expr),*; $($args: ident),*) => { - impl<'a, N: Scalar, $($DimIdent: $DimBound),*> MatrixSliceMutMN<'a, N, $($Dims),*> { + impl<'a, T: Scalar, $($DimIdent: $DimBound),*> MatrixSliceMutMN<'a, T, $($Dims),*> { /// Creates a new mutable matrix slice from the given data array. /// /// Panics if `data` does not contain enough elements. #[inline] - pub fn from_slice(data: &'a mut [N], $($args: usize),*) -> Self { + pub fn from_slice(data: &'a mut [T], $($args: usize),*) -> Self { Self::from_slice_generic(data, $($gargs),*) } /// Creates, without bound checking, a new mutable matrix slice from the given data array. #[inline] - pub unsafe fn from_slice_unchecked(data: &'a mut [N], start: usize, $($args: usize),*) -> Self { + pub unsafe fn from_slice_unchecked(data: &'a mut [T], start: usize, $($args: usize),*) -> Self { Self::from_slice_generic_unchecked(data, start, $($gargs),*) } } - impl<'a, N: Scalar, $($DimIdent: $DimBound, )*> MatrixSliceMutMN<'a, N, $($Dims,)* Dynamic, Dynamic> { + impl<'a, T: Scalar, $($DimIdent: $DimBound, )*> MatrixSliceMutMN<'a, T, $($Dims,)* Dynamic, Dynamic> { /// Creates a new mutable matrix slice with the specified strides from the given data array. /// /// Panics if `data` does not contain enough elements. #[inline] - pub fn from_slice_with_strides_mut(data: &'a mut [N], $($args: usize,)* rstride: usize, cstride: usize) -> Self { + pub fn from_slice_with_strides_mut(data: &'a mut [T], $($args: usize,)* rstride: usize, cstride: usize) -> Self { Self::from_slice_with_strides_generic( data, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride)) } /// Creates, without bound checking, a new mutable matrix slice with the specified strides from the given data array. #[inline] - pub unsafe fn from_slice_with_strides_unchecked(data: &'a mut [N], start: usize, $($args: usize,)* rstride: usize, cstride: usize) -> Self { + pub unsafe fn from_slice_with_strides_unchecked(data: &'a mut [T], start: usize, $($args: usize,)* rstride: usize, cstride: usize) -> Self { Self::from_slice_with_strides_generic_unchecked( data, start, $($gargs,)* Dynamic::new(rstride), Dynamic::new(cstride)) } @@ -280,8 +280,8 @@ macro_rules! impl_constructors_mut( ); // TODO: this is not very pretty. We could find a better call syntax. -impl_constructors_mut!(R, C; // Arguments for Matrix -=> R: DimName, => C: DimName; // Type parameters for impl +impl_constructors_mut!(R, C; // Arguments for Matrix +=> R: DimName, => C: DimName; // Type parameters for impl R::name(), C::name(); // Arguments for `_generic` constructors. ); // Arguments for non-generic constructors. diff --git a/src/base/conversion.rs b/src/base/conversion.rs index a5627e4a..24a088a2 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -17,8 +17,8 @@ use crate::base::dimension::{ use crate::base::iter::{MatrixIter, MatrixIterMut}; use crate::base::storage::{ContiguousStorage, ContiguousStorageMut, Storage, StorageMut}; use crate::base::{ - ArrayStorage, DVectorSlice, DVectorSliceMut, DefaultAllocator, Matrix, MatrixMN, MatrixSlice, - MatrixSliceMut, Scalar, + ArrayStorage, DVectorSlice, DVectorSliceMut, DefaultAllocator, Matrix, MatrixSlice, + MatrixSliceMut, OMatrix, Scalar, }; #[cfg(any(feature = "std", feature = "alloc"))] use crate::base::{DVector, VecStorage}; @@ -26,30 +26,30 @@ use crate::base::{SliceStorage, SliceStorageMut}; use crate::constraint::DimEq; // TODO: too bad this won't work allo slice conversions. -impl SubsetOf> for MatrixMN +impl SubsetOf> for OMatrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N1: Scalar, - N2: Scalar + SupersetOf, + T1: Scalar, + T2: Scalar + SupersetOf, DefaultAllocator: - Allocator + Allocator + SameShapeAllocator, + Allocator + Allocator + SameShapeAllocator, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { #[inline] - fn to_superset(&self) -> MatrixMN { + fn to_superset(&self) -> OMatrix { let (nrows, ncols) = self.shape(); let nrows2 = R2::from_usize(nrows); let ncols2 = C2::from_usize(ncols); - let mut res: MatrixMN = + let mut res: OMatrix = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows2, ncols2) }; for i in 0..nrows { for j in 0..ncols { unsafe { - *res.get_unchecked_mut((i, j)) = N2::from_subset(self.get_unchecked((i, j))) + *res.get_unchecked_mut((i, j)) = T2::from_subset(self.get_unchecked((i, j))) } } } @@ -58,12 +58,12 @@ where } #[inline] - fn is_in_subset(m: &MatrixMN) -> bool { + fn is_in_subset(m: &OMatrix) -> bool { m.iter().all(|e| e.is_in_subset()) } #[inline] - fn from_superset_unchecked(m: &MatrixMN) -> Self { + fn from_superset_unchecked(m: &OMatrix) -> Self { let (nrows2, ncols2) = m.shape(); let nrows = R1::from_usize(nrows2); let ncols = C1::from_usize(ncols2); @@ -81,9 +81,9 @@ where } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: Storage> IntoIterator for &'a Matrix { - type Item = &'a N; - type IntoIter = MatrixIter<'a, N, R, C, S>; +impl<'a, T: Scalar, R: Dim, C: Dim, S: Storage> IntoIterator for &'a Matrix { + type Item = &'a T; + type IntoIter = MatrixIter<'a, T, R, C, S>; #[inline] fn into_iter(self) -> Self::IntoIter { @@ -91,11 +91,11 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: Storage> IntoIterator for &'a Ma } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut> IntoIterator - for &'a mut Matrix +impl<'a, T: Scalar, R: Dim, C: Dim, S: StorageMut> IntoIterator + for &'a mut Matrix { - type Item = &'a mut N; - type IntoIter = MatrixIterMut<'a, N, R, C, S>; + type Item = &'a mut T; + type IntoIter = MatrixIterMut<'a, T, R, C, S>; #[inline] fn into_iter(self) -> Self::IntoIter { @@ -105,11 +105,11 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut> IntoIterator macro_rules! impl_from_into_asref_1D( ($(($NRows: ident, $NCols: ident) => $SZ: expr);* $(;)*) => {$( - impl From<[N; $SZ]> for MatrixMN - where N: Scalar, - DefaultAllocator: Allocator { + impl From<[T; $SZ]> for OMatrix + where T: Scalar, + DefaultAllocator: Allocator { #[inline] - fn from(arr: [N; $SZ]) -> Self { + fn from(arr: [T; $SZ]) -> Self { unsafe { let mut res = Self::new_uninitialized(); ptr::copy_nonoverlapping(&arr[0], (*res.as_mut_ptr()).data.ptr_mut(), $SZ); @@ -119,35 +119,35 @@ macro_rules! impl_from_into_asref_1D( } } - impl Into<[N; $SZ]> for Matrix - where N: Scalar, - S: ContiguousStorage { + impl Into<[T; $SZ]> for Matrix + where T: Scalar, + S: ContiguousStorage { #[inline] - fn into(self) -> [N; $SZ] { - let mut res = mem::MaybeUninit::<[N; $SZ]>::uninit(); + fn into(self) -> [T; $SZ] { + let mut res = mem::MaybeUninit::<[T; $SZ]>::uninit(); - unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut N, $SZ) }; + unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut T, $SZ) }; unsafe { res.assume_init() } } } - impl AsRef<[N; $SZ]> for Matrix - where N: Scalar, - S: ContiguousStorage { + impl AsRef<[T; $SZ]> for Matrix + where T: Scalar, + S: ContiguousStorage { #[inline] - fn as_ref(&self) -> &[N; $SZ] { + fn as_ref(&self) -> &[T; $SZ] { unsafe { mem::transmute(self.data.ptr()) } } } - impl AsMut<[N; $SZ]> for Matrix - where N: Scalar, - S: ContiguousStorageMut { + impl AsMut<[T; $SZ]> for Matrix + where T: Scalar, + S: ContiguousStorageMut { #[inline] - fn as_mut(&mut self) -> &mut [N; $SZ] { + fn as_mut(&mut self) -> &mut [T; $SZ] { unsafe { mem::transmute(self.data.ptr_mut()) } @@ -173,10 +173,10 @@ impl_from_into_asref_1D!( macro_rules! impl_from_into_asref_2D( ($(($NRows: ty, $NCols: ty) => ($SZRows: expr, $SZCols: expr));* $(;)*) => {$( - impl From<[[N; $SZRows]; $SZCols]> for MatrixMN - where DefaultAllocator: Allocator { + impl From<[[T; $SZRows]; $SZCols]> for OMatrix + where DefaultAllocator: Allocator { #[inline] - fn from(arr: [[N; $SZRows]; $SZCols]) -> Self { + fn from(arr: [[T; $SZRows]; $SZCols]) -> Self { unsafe { let mut res = Self::new_uninitialized(); ptr::copy_nonoverlapping(&arr[0][0], (*res.as_mut_ptr()).data.ptr_mut(), $SZRows * $SZCols); @@ -186,32 +186,32 @@ macro_rules! impl_from_into_asref_2D( } } - impl Into<[[N; $SZRows]; $SZCols]> for Matrix - where S: ContiguousStorage { + impl Into<[[T; $SZRows]; $SZCols]> for Matrix + where S: ContiguousStorage { #[inline] - fn into(self) -> [[N; $SZRows]; $SZCols] { - let mut res = mem::MaybeUninit::<[[N; $SZRows]; $SZCols]>::uninit(); + fn into(self) -> [[T; $SZRows]; $SZCols] { + let mut res = mem::MaybeUninit::<[[T; $SZRows]; $SZCols]>::uninit(); - unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut N, $SZRows * $SZCols) }; + unsafe { ptr::copy_nonoverlapping(self.data.ptr(), res.as_mut_ptr() as *mut T, $SZRows * $SZCols) }; unsafe { res.assume_init() } } } - impl AsRef<[[N; $SZRows]; $SZCols]> for Matrix - where S: ContiguousStorage { + impl AsRef<[[T; $SZRows]; $SZCols]> for Matrix + where S: ContiguousStorage { #[inline] - fn as_ref(&self) -> &[[N; $SZRows]; $SZCols] { + fn as_ref(&self) -> &[[T; $SZRows]; $SZCols] { unsafe { mem::transmute(self.data.ptr()) } } } - impl AsMut<[[N; $SZRows]; $SZCols]> for Matrix - where S: ContiguousStorageMut { + impl AsMut<[[T; $SZRows]; $SZCols]> for Matrix + where S: ContiguousStorageMut { #[inline] - fn as_mut(&mut self) -> &mut [[N; $SZRows]; $SZCols] { + fn as_mut(&mut self) -> &mut [[T; $SZRows]; $SZCols] { unsafe { mem::transmute(self.data.ptr_mut()) } @@ -229,106 +229,105 @@ impl_from_into_asref_2D!( (U6, U2) => (6, 2); (U6, U3) => (6, 3); (U6, U4) => (6, 4); (U6, U5) => (6, 5); (U6, U6) => (6, 6); ); - -impl<'a, N, RStride, CStride, const R: usize, const C: usize> - From, Const, RStride, CStride>> - for Matrix, Const, ArrayStorage> +impl<'a, T, RStride, CStride, const R: usize, const C: usize> + From, Const, RStride, CStride>> + for Matrix, Const, ArrayStorage> where - N: Scalar, + T: Scalar, RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixSlice<'a, N, Const, Const, RStride, CStride>) -> Self { + fn from(matrix_slice: MatrixSlice<'a, T, Const, Const, RStride, CStride>) -> Self { matrix_slice.into_owned() } } #[cfg(any(feature = "std", feature = "alloc"))] -impl<'a, N, C, RStride, CStride> From> - for Matrix> +impl<'a, T, C, RStride, CStride> From> + for Matrix> where - N: Scalar, + T: Scalar, C: Dim, RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixSlice<'a, N, Dynamic, C, RStride, CStride>) -> Self { + fn from(matrix_slice: MatrixSlice<'a, T, Dynamic, C, RStride, CStride>) -> Self { matrix_slice.into_owned() } } #[cfg(any(feature = "std", feature = "alloc"))] -impl<'a, N, R, RStride, CStride> From> - for Matrix> +impl<'a, T, R, RStride, CStride> From> + for Matrix> where - N: Scalar, + T: Scalar, R: DimName, RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixSlice<'a, N, R, Dynamic, RStride, CStride>) -> Self { + fn from(matrix_slice: MatrixSlice<'a, T, R, Dynamic, RStride, CStride>) -> Self { matrix_slice.into_owned() } } -impl<'a, N, RStride, CStride, const R: usize, const C: usize> - From, Const, RStride, CStride>> - for Matrix, Const, ArrayStorage> +impl<'a, T, RStride, CStride, const R: usize, const C: usize> + From, Const, RStride, CStride>> + for Matrix, Const, ArrayStorage> where - N: Scalar, + T: Scalar, RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixSliceMut<'a, N, Const, Const, RStride, CStride>) -> Self { + fn from(matrix_slice: MatrixSliceMut<'a, T, Const, Const, RStride, CStride>) -> Self { matrix_slice.into_owned() } } #[cfg(any(feature = "std", feature = "alloc"))] -impl<'a, N, C, RStride, CStride> From> - for Matrix> +impl<'a, T, C, RStride, CStride> From> + for Matrix> where - N: Scalar, + T: Scalar, C: Dim, RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixSliceMut<'a, N, Dynamic, C, RStride, CStride>) -> Self { + fn from(matrix_slice: MatrixSliceMut<'a, T, Dynamic, C, RStride, CStride>) -> Self { matrix_slice.into_owned() } } #[cfg(any(feature = "std", feature = "alloc"))] -impl<'a, N, R, RStride, CStride> From> - for Matrix> +impl<'a, T, R, RStride, CStride> From> + for Matrix> where - N: Scalar, + T: Scalar, R: DimName, RStride: Dim, CStride: Dim, { - fn from(matrix_slice: MatrixSliceMut<'a, N, R, Dynamic, RStride, CStride>) -> Self { + fn from(matrix_slice: MatrixSliceMut<'a, T, R, Dynamic, RStride, CStride>) -> Self { matrix_slice.into_owned() } } -impl<'a, N, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a Matrix> - for MatrixSlice<'a, N, RSlice, CSlice, RStride, CStride> +impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a Matrix> + for MatrixSlice<'a, T, RSlice, CSlice, RStride, CStride> where - N: Scalar, + T: Scalar, R: Dim, C: Dim, RSlice: Dim, CSlice: Dim, RStride: Dim, CStride: Dim, - S: Storage, + S: Storage, ShapeConstraint: DimEq + DimEq + DimEq + DimEq, { - fn from(m: &'a Matrix) -> Self { + fn from(m: &'a Matrix) -> Self { let (row, col) = m.data.shape(); let row_slice = RSlice::from_usize(row.value()); let col_slice = CSlice::from_usize(col.value()); @@ -349,23 +348,23 @@ where } } -impl<'a, N, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix> - for MatrixSlice<'a, N, RSlice, CSlice, RStride, CStride> +impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix> + for MatrixSlice<'a, T, RSlice, CSlice, RStride, CStride> where - N: Scalar, + T: Scalar, R: Dim, C: Dim, RSlice: Dim, CSlice: Dim, RStride: Dim, CStride: Dim, - S: Storage, + S: Storage, ShapeConstraint: DimEq + DimEq + DimEq + DimEq, { - fn from(m: &'a mut Matrix) -> Self { + fn from(m: &'a mut Matrix) -> Self { let (row, col) = m.data.shape(); let row_slice = RSlice::from_usize(row.value()); let col_slice = CSlice::from_usize(col.value()); @@ -386,23 +385,23 @@ where } } -impl<'a, N, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix> - for MatrixSliceMut<'a, N, RSlice, CSlice, RStride, CStride> +impl<'a, T, R, C, RSlice, CSlice, RStride, CStride, S> From<&'a mut Matrix> + for MatrixSliceMut<'a, T, RSlice, CSlice, RStride, CStride> where - N: Scalar, + T: Scalar, R: Dim, C: Dim, RSlice: Dim, CSlice: Dim, RStride: Dim, CStride: Dim, - S: StorageMut, + S: StorageMut, ShapeConstraint: DimEq + DimEq + DimEq + DimEq, { - fn from(m: &'a mut Matrix) -> Self { + fn from(m: &'a mut Matrix) -> Self { let (row, col) = m.data.shape(); let row_slice = RSlice::from_usize(row.value()); let col_slice = CSlice::from_usize(col.value()); @@ -424,54 +423,54 @@ where } #[cfg(any(feature = "std", feature = "alloc"))] -impl<'a, N: Scalar> From> for DVector { +impl<'a, T: Scalar> From> for DVector { #[inline] - fn from(vec: Vec) -> Self { + fn from(vec: Vec) -> Self { Self::from_vec(vec) } } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorage> Into<&'a [N]> - for &'a Matrix +impl<'a, T: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorage> Into<&'a [T]> + for &'a Matrix { #[inline] - fn into(self) -> &'a [N] { + fn into(self) -> &'a [T] { self.as_slice() } } -impl<'a, N: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorageMut> Into<&'a mut [N]> - for &'a mut Matrix +impl<'a, T: Scalar + Copy, R: Dim, C: Dim, S: ContiguousStorageMut> Into<&'a mut [T]> + for &'a mut Matrix { #[inline] - fn into(self) -> &'a mut [N] { + fn into(self) -> &'a mut [T] { self.as_mut_slice() } } -impl<'a, N: Scalar + Copy> From<&'a [N]> for DVectorSlice<'a, N> { +impl<'a, T: Scalar + Copy> From<&'a [T]> for DVectorSlice<'a, T> { #[inline] - fn from(slice: &'a [N]) -> Self { + fn from(slice: &'a [T]) -> Self { Self::from_slice(slice, slice.len()) } } -impl<'a, N: Scalar + Copy> From<&'a mut [N]> for DVectorSliceMut<'a, N> { +impl<'a, T: Scalar + Copy> From<&'a mut [T]> for DVectorSliceMut<'a, T> { #[inline] - fn from(slice: &'a mut [N]) -> Self { + fn from(slice: &'a mut [T]) -> Self { Self::from_slice(slice, slice.len()) } } -impl From<[MatrixMN; 2]> - for MatrixMN +impl From<[OMatrix; 2]> + for OMatrix where - N: From<[::Element; 2]>, - N::Element: Scalar + SimdValue, - DefaultAllocator: Allocator + Allocator, + T: From<[::Element; 2]>, + T::Element: Scalar + SimdValue, + DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [MatrixMN; 2]) -> Self { + fn from(arr: [OMatrix; 2]) -> Self { let (nrows, ncols) = arr[0].data.shape(); Self::from_fn_generic(nrows, ncols, |i, j| { @@ -484,15 +483,15 @@ where } } -impl From<[MatrixMN; 4]> - for MatrixMN +impl From<[OMatrix; 4]> + for OMatrix where - N: From<[::Element; 4]>, - N::Element: Scalar + SimdValue, - DefaultAllocator: Allocator + Allocator, + T: From<[::Element; 4]>, + T::Element: Scalar + SimdValue, + DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [MatrixMN; 4]) -> Self { + fn from(arr: [OMatrix; 4]) -> Self { let (nrows, ncols) = arr[0].data.shape(); Self::from_fn_generic(nrows, ncols, |i, j| { @@ -507,15 +506,15 @@ where } } -impl From<[MatrixMN; 8]> - for MatrixMN +impl From<[OMatrix; 8]> + for OMatrix where - N: From<[::Element; 8]>, - N::Element: Scalar + SimdValue, - DefaultAllocator: Allocator + Allocator, + T: From<[::Element; 8]>, + T::Element: Scalar + SimdValue, + DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [MatrixMN; 8]) -> Self { + fn from(arr: [OMatrix; 8]) -> Self { let (nrows, ncols) = arr[0].data.shape(); Self::from_fn_generic(nrows, ncols, |i, j| { @@ -534,14 +533,14 @@ where } } -impl From<[MatrixMN; 16]> - for MatrixMN +impl From<[OMatrix; 16]> + for OMatrix where - N: From<[::Element; 16]>, - N::Element: Scalar + SimdValue, - DefaultAllocator: Allocator + Allocator, + T: From<[::Element; 16]>, + T::Element: Scalar + SimdValue, + DefaultAllocator: Allocator + Allocator, { - fn from(arr: [MatrixMN; 16]) -> Self { + fn from(arr: [OMatrix; 16]) -> Self { let (nrows, ncols) = arr[0].data.shape(); Self::from_fn_generic(nrows, ncols, |i, j| { diff --git a/src/base/coordinates.rs b/src/base/coordinates.rs index 832723e3..9cf6bd33 100644 --- a/src/base/coordinates.rs +++ b/src/base/coordinates.rs @@ -24,17 +24,17 @@ macro_rules! coords_impl( #[repr(C)] #[derive(Eq, PartialEq, Clone, Hash, Debug, Copy)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] - pub struct $T { - $(pub $comps: N),* + pub struct $T { + $(pub $comps: T),* } } ); macro_rules! deref_impl( ($R: ty, $C: ty; $Target: ident) => { - impl Deref for Matrix - where S: ContiguousStorage { - type Target = $Target; + impl Deref for Matrix + where S: ContiguousStorage { + type Target = $Target; #[inline] fn deref(&self) -> &Self::Target { @@ -42,8 +42,8 @@ macro_rules! deref_impl( } } - impl DerefMut for Matrix - where S: ContiguousStorageMut { + impl DerefMut for Matrix + where S: ContiguousStorageMut { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { unsafe { mem::transmute(self.data.ptr_mut()) } diff --git a/src/base/default_allocator.rs b/src/base/default_allocator.rs index 03f86fb9..a9f994fe 100644 --- a/src/base/default_allocator.rs +++ b/src/base/default_allocator.rs @@ -31,10 +31,10 @@ use crate::base::Scalar; pub struct DefaultAllocator; // Static - Static -impl Allocator, Const> +impl Allocator, Const> for DefaultAllocator { - type Buffer = ArrayStorage; + type Buffer = ArrayStorage; #[inline] unsafe fn allocate_uninitialized(_: Const, _: Const) -> mem::MaybeUninit { @@ -42,7 +42,7 @@ impl Allocator, Const> } #[inline] - fn allocate_from_iterator>( + fn allocate_from_iterator>( nrows: Const, ncols: Const, iter: I, @@ -70,8 +70,8 @@ impl Allocator, Const> // Dynamic - Static // Dynamic - Dynamic #[cfg(any(feature = "std", feature = "alloc"))] -impl Allocator for DefaultAllocator { - type Buffer = VecStorage; +impl Allocator for DefaultAllocator { + type Buffer = VecStorage; #[inline] unsafe fn allocate_uninitialized(nrows: Dynamic, ncols: C) -> mem::MaybeUninit { @@ -84,13 +84,13 @@ impl Allocator for DefaultAllocator { } #[inline] - fn allocate_from_iterator>( + fn allocate_from_iterator>( nrows: Dynamic, ncols: C, iter: I, ) -> Self::Buffer { let it = iter.into_iter(); - let res: Vec = it.collect(); + let res: Vec = it.collect(); assert!(res.len() == nrows.value() * ncols.value(), "Allocation from iterator error: the iterator did not yield the correct number of elements."); @@ -100,8 +100,8 @@ impl Allocator for DefaultAllocator { // Static - Dynamic #[cfg(any(feature = "std", feature = "alloc"))] -impl Allocator for DefaultAllocator { - type Buffer = VecStorage; +impl Allocator for DefaultAllocator { + type Buffer = VecStorage; #[inline] unsafe fn allocate_uninitialized(nrows: R, ncols: Dynamic) -> mem::MaybeUninit { @@ -114,13 +114,13 @@ impl Allocator for DefaultAllocator { } #[inline] - fn allocate_from_iterator>( + fn allocate_from_iterator>( nrows: R, ncols: Dynamic, iter: I, ) -> Self::Buffer { let it = iter.into_iter(); - let res: Vec = it.collect(); + let res: Vec = it.collect(); assert!(res.len() == nrows.value() * ncols.value(), "Allocation from iterator error: the iterator did not yield the correct number of elements."); @@ -134,24 +134,24 @@ impl Allocator for DefaultAllocator { * */ // Anything -> Static × Static -impl - Reallocator, Const> for DefaultAllocator +impl + Reallocator, Const> for DefaultAllocator where RFrom: Dim, CFrom: Dim, - Self: Allocator, + Self: Allocator, { #[inline] unsafe fn reallocate_copy( rto: Const, cto: Const, - buf: >::Buffer, - ) -> ArrayStorage { + buf: >::Buffer, + ) -> ArrayStorage { #[cfg(feature = "no_unsound_assume_init")] - let mut res: ArrayStorage = unimplemented!(); + let mut res: ArrayStorage = unimplemented!(); #[cfg(not(feature = "no_unsound_assume_init"))] let mut res = - , Const>>::allocate_uninitialized(rto, cto) + , Const>>::allocate_uninitialized(rto, cto) .assume_init(); let (rfrom, cfrom) = buf.shape(); @@ -166,8 +166,8 @@ where // Static × Static -> Dynamic × Any #[cfg(any(feature = "std", feature = "alloc"))] -impl - Reallocator, Const, Dynamic, CTo> for DefaultAllocator +impl + Reallocator, Const, Dynamic, CTo> for DefaultAllocator where CTo: Dim, { @@ -175,13 +175,13 @@ where unsafe fn reallocate_copy( rto: Dynamic, cto: CTo, - buf: ArrayStorage, - ) -> VecStorage { + buf: ArrayStorage, + ) -> VecStorage { #[cfg(feature = "no_unsound_assume_init")] - let mut res: VecStorage = unimplemented!(); + let mut res: VecStorage = unimplemented!(); #[cfg(not(feature = "no_unsound_assume_init"))] let mut res = - >::allocate_uninitialized(rto, cto).assume_init(); + >::allocate_uninitialized(rto, cto).assume_init(); let (rfrom, cfrom) = buf.shape(); @@ -195,8 +195,8 @@ where // Static × Static -> Static × Dynamic #[cfg(any(feature = "std", feature = "alloc"))] -impl - Reallocator, Const, RTo, Dynamic> for DefaultAllocator +impl + Reallocator, Const, RTo, Dynamic> for DefaultAllocator where RTo: DimName, { @@ -204,13 +204,13 @@ where unsafe fn reallocate_copy( rto: RTo, cto: Dynamic, - buf: ArrayStorage, - ) -> VecStorage { + buf: ArrayStorage, + ) -> VecStorage { #[cfg(feature = "no_unsound_assume_init")] - let mut res: VecStorage = unimplemented!(); + let mut res: VecStorage = unimplemented!(); #[cfg(not(feature = "no_unsound_assume_init"))] let mut res = - >::allocate_uninitialized(rto, cto).assume_init(); + >::allocate_uninitialized(rto, cto).assume_init(); let (rfrom, cfrom) = buf.shape(); @@ -224,60 +224,60 @@ where // All conversion from a dynamic buffer to a dynamic buffer. #[cfg(any(feature = "std", feature = "alloc"))] -impl Reallocator +impl Reallocator for DefaultAllocator { #[inline] unsafe fn reallocate_copy( rto: Dynamic, cto: CTo, - buf: VecStorage, - ) -> VecStorage { + buf: VecStorage, + ) -> VecStorage { let new_buf = buf.resize(rto.value() * cto.value()); VecStorage::new(rto, cto, new_buf) } } #[cfg(any(feature = "std", feature = "alloc"))] -impl Reallocator +impl Reallocator for DefaultAllocator { #[inline] unsafe fn reallocate_copy( rto: RTo, cto: Dynamic, - buf: VecStorage, - ) -> VecStorage { + buf: VecStorage, + ) -> VecStorage { let new_buf = buf.resize(rto.value() * cto.value()); VecStorage::new(rto, cto, new_buf) } } #[cfg(any(feature = "std", feature = "alloc"))] -impl Reallocator +impl Reallocator for DefaultAllocator { #[inline] unsafe fn reallocate_copy( rto: Dynamic, cto: CTo, - buf: VecStorage, - ) -> VecStorage { + buf: VecStorage, + ) -> VecStorage { let new_buf = buf.resize(rto.value() * cto.value()); VecStorage::new(rto, cto, new_buf) } } #[cfg(any(feature = "std", feature = "alloc"))] -impl Reallocator +impl Reallocator for DefaultAllocator { #[inline] unsafe fn reallocate_copy( rto: RTo, cto: Dynamic, - buf: VecStorage, - ) -> VecStorage { + buf: VecStorage, + ) -> VecStorage { let new_buf = buf.resize(rto.value() * cto.value()); VecStorage::new(rto, cto, new_buf) } diff --git a/src/base/edition.rs b/src/base/edition.rs index 0074e483..189b234c 100644 --- a/src/base/edition.rs +++ b/src/base/edition.rs @@ -10,47 +10,45 @@ use crate::base::allocator::{Allocator, Reallocator}; use crate::base::constraint::{DimEq, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; #[cfg(any(feature = "std", feature = "alloc"))] use crate::base::dimension::Dynamic; -use crate::base::dimension::{ - Dim, DimAdd, DimDiff, DimMin, DimMinimum, DimName, DimSub, DimSum, U1, -}; +use crate::base::dimension::{Const, Dim, DimAdd, DimDiff, DimMin, DimMinimum, DimSub, DimSum, U1}; use crate::base::storage::{ReshapableStorage, Storage, StorageMut}; #[cfg(any(feature = "std", feature = "alloc"))] use crate::base::DMatrix; -use crate::base::{DefaultAllocator, Matrix, MatrixMN, RowVector, Scalar, Vector}; +use crate::base::{DefaultAllocator, Matrix, OMatrix, RowVector, SMatrix, Scalar, Vector}; /// # Rows and columns extraction -impl> Matrix { +impl> Matrix { /// Extracts the upper triangular part of this matrix (including the diagonal). #[inline] - pub fn upper_triangle(&self) -> MatrixMN + pub fn upper_triangle(&self) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let mut res = self.clone_owned(); - res.fill_lower_triangle(N::zero(), 1); + res.fill_lower_triangle(T::zero(), 1); res } /// Extracts the lower triangular part of this matrix (including the diagonal). #[inline] - pub fn lower_triangle(&self) -> MatrixMN + pub fn lower_triangle(&self) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let mut res = self.clone_owned(); - res.fill_upper_triangle(N::zero(), 1); + res.fill_upper_triangle(T::zero(), 1); res } /// Creates a new matrix by extracting the given set of rows from `self`. #[cfg(any(feature = "std", feature = "alloc"))] - pub fn select_rows<'a, I>(&self, irows: I) -> MatrixMN + pub fn select_rows<'a, I>(&self, irows: I) -> OMatrix where I: IntoIterator, I::IntoIter: ExactSizeIterator + Clone, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let irows = irows.into_iter(); let ncols = self.data.shape().1; @@ -82,11 +80,11 @@ impl> Matrix { /// Creates a new matrix by extracting the given set of columns from `self`. #[cfg(any(feature = "std", feature = "alloc"))] - pub fn select_columns<'a, I>(&self, icols: I) -> MatrixMN + pub fn select_columns<'a, I>(&self, icols: I) -> OMatrix where I: IntoIterator, I::IntoIter: ExactSizeIterator, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let icols = icols.into_iter(); let nrows = self.data.shape().0; @@ -103,13 +101,13 @@ impl> Matrix { } /// # Set rows, columns, and diagonal -impl> Matrix { +impl> Matrix { /// Fills the diagonal of this matrix with the content of the given vector. #[inline] - pub fn set_diagonal(&mut self, diag: &Vector) + pub fn set_diagonal(&mut self, diag: &Vector) where R: DimMin, - S2: Storage, + S2: Storage, ShapeConstraint: DimEq, R2>, { let (nrows, ncols) = self.shape(); @@ -127,7 +125,7 @@ impl> Matrix { /// minimum of the number of rows and columns of `self`, and starting with the /// diagonal element at index (0, 0). #[inline] - pub fn set_partial_diagonal(&mut self, diag: impl Iterator) { + pub fn set_partial_diagonal(&mut self, diag: impl Iterator) { let (nrows, ncols) = self.shape(); let min_nrows_ncols = cmp::min(nrows, ncols); @@ -138,9 +136,9 @@ impl> Matrix { /// Fills the selected row of this matrix with the content of the given vector. #[inline] - pub fn set_row(&mut self, i: usize, row: &RowVector) + pub fn set_row(&mut self, i: usize, row: &RowVector) where - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfColumns, { self.row_mut(i).copy_from(row); @@ -148,9 +146,9 @@ impl> Matrix { /// Fills the selected column of this matrix with the content of the given vector. #[inline] - pub fn set_column(&mut self, i: usize, column: &Vector) + pub fn set_column(&mut self, i: usize, column: &Vector) where - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfRows, { self.column_mut(i).copy_from(column); @@ -158,10 +156,10 @@ impl> Matrix { } /// # In-place filling -impl> Matrix { +impl> Matrix { /// Sets all the elements of this matrix to `val`. #[inline] - pub fn fill(&mut self, val: N) { + pub fn fill(&mut self, val: T) { for e in self.iter_mut() { *e = val.inlined_clone() } @@ -171,15 +169,15 @@ impl> Matrix { #[inline] pub fn fill_with_identity(&mut self) where - N: Zero + One, + T: Zero + One, { - self.fill(N::zero()); - self.fill_diagonal(N::one()); + self.fill(T::zero()); + self.fill_diagonal(T::one()); } /// Sets all the diagonal elements of this matrix to `val`. #[inline] - pub fn fill_diagonal(&mut self, val: N) { + pub fn fill_diagonal(&mut self, val: T) { let (nrows, ncols) = self.shape(); let n = cmp::min(nrows, ncols); @@ -190,7 +188,7 @@ impl> Matrix { /// Sets all the elements of the selected row to `val`. #[inline] - pub fn fill_row(&mut self, i: usize, val: N) { + pub fn fill_row(&mut self, i: usize, val: T) { assert!(i < self.nrows(), "Row index out of bounds."); for j in 0..self.ncols() { unsafe { *self.get_unchecked_mut((i, j)) = val.inlined_clone() } @@ -199,7 +197,7 @@ impl> Matrix { /// Sets all the elements of the selected column to `val`. #[inline] - pub fn fill_column(&mut self, j: usize, val: N) { + pub fn fill_column(&mut self, j: usize, val: T) { assert!(j < self.ncols(), "Row index out of bounds."); for i in 0..self.nrows() { unsafe { *self.get_unchecked_mut((i, j)) = val.inlined_clone() } @@ -214,7 +212,7 @@ impl> Matrix { /// * If `shift > 1`, then the diagonal and the first `shift - 1` subdiagonals are left /// untouched. #[inline] - pub fn fill_lower_triangle(&mut self, val: N, shift: usize) { + pub fn fill_lower_triangle(&mut self, val: T, shift: usize) { for j in 0..self.ncols() { for i in (j + shift)..self.nrows() { unsafe { *self.get_unchecked_mut((i, j)) = val.inlined_clone() } @@ -230,7 +228,7 @@ impl> Matrix { /// * If `shift > 1`, then the diagonal and the first `shift - 1` superdiagonals are left /// untouched. #[inline] - pub fn fill_upper_triangle(&mut self, val: N, shift: usize) { + pub fn fill_upper_triangle(&mut self, val: T, shift: usize) { for j in shift..self.ncols() { // TODO: is there a more efficient way to avoid the min ? // (necessary for rectangular matrices) @@ -241,7 +239,7 @@ impl> Matrix { } } -impl> Matrix { +impl> Matrix { /// Copies the upper-triangle of this matrix to its lower-triangular part. /// /// This makes the matrix symmetric. Panics if the matrix is not square. @@ -275,7 +273,7 @@ impl> Matrix { } /// # In-place swapping -impl> Matrix { +impl> Matrix { /// Swaps two rows in-place. #[inline] pub fn swap_rows(&mut self, irow1: usize, irow2: usize) { @@ -311,7 +309,7 @@ impl> Matrix { * */ /// # Rows and columns removal -impl> Matrix { +impl> Matrix { /* * * Column removal. @@ -319,20 +317,20 @@ impl> Matrix { */ /// Removes the `i`-th column from this matrix. #[inline] - pub fn remove_column(self, i: usize) -> MatrixMN> + pub fn remove_column(self, i: usize) -> OMatrix> where C: DimSub, - DefaultAllocator: Reallocator>, + DefaultAllocator: Reallocator>, { - self.remove_fixed_columns::(i) + self.remove_fixed_columns::<1>(i) } /// Removes all columns in `indices` #[cfg(any(feature = "std", feature = "alloc"))] - pub fn remove_columns_at(self, indices: &[usize]) -> MatrixMN + pub fn remove_columns_at(self, indices: &[usize]) -> OMatrix where C: DimSub, - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { let mut m = self.into_owned(); let (nrows, ncols) = m.data.shape(); @@ -363,10 +361,10 @@ impl> Matrix { /// Removes all rows in `indices` #[cfg(any(feature = "std", feature = "alloc"))] - pub fn remove_rows_at(self, indices: &[usize]) -> MatrixMN + pub fn remove_rows_at(self, indices: &[usize]) -> OMatrix where R: DimSub, - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { let mut m = self.into_owned(); let (nrows, ncols) = m.data.shape(); @@ -398,22 +396,24 @@ impl> Matrix { /// Removes `D::dim()` consecutive columns from this matrix, starting with the `i`-th /// (included). #[inline] - pub fn remove_fixed_columns(self, i: usize) -> MatrixMN> + pub fn remove_fixed_columns( + self, + i: usize, + ) -> OMatrix>> where - D: DimName, - C: DimSub, - DefaultAllocator: Reallocator>, + C: DimSub>, + DefaultAllocator: Reallocator>>, { - self.remove_columns_generic(i, D::name()) + self.remove_columns_generic(i, Const::) } /// Removes `n` consecutive columns from this matrix, starting with the `i`-th (included). #[inline] #[cfg(any(feature = "std", feature = "alloc"))] - pub fn remove_columns(self, i: usize, n: usize) -> MatrixMN + pub fn remove_columns(self, i: usize, n: usize) -> OMatrix where C: DimSub, - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { self.remove_columns_generic(i, Dynamic::new(n)) } @@ -423,11 +423,11 @@ impl> Matrix { /// This is the generic implementation of `.remove_columns(...)` and /// `.remove_fixed_columns(...)` which have nicer API interfaces. #[inline] - pub fn remove_columns_generic(self, i: usize, nremove: D) -> MatrixMN> + pub fn remove_columns_generic(self, i: usize, nremove: D) -> OMatrix> where D: Dim, C: DimSub, - DefaultAllocator: Reallocator>, + DefaultAllocator: Reallocator>, { let mut m = self.into_owned(); let (nrows, ncols) = m.data.shape(); @@ -468,32 +468,31 @@ impl> Matrix { */ /// Removes the `i`-th row from this matrix. #[inline] - pub fn remove_row(self, i: usize) -> MatrixMN, C> + pub fn remove_row(self, i: usize) -> OMatrix, C> where R: DimSub, - DefaultAllocator: Reallocator, C>, + DefaultAllocator: Reallocator, C>, { - self.remove_fixed_rows::(i) + self.remove_fixed_rows::<1>(i) } /// Removes `D::dim()` consecutive rows from this matrix, starting with the `i`-th (included). #[inline] - pub fn remove_fixed_rows(self, i: usize) -> MatrixMN, C> + pub fn remove_fixed_rows(self, i: usize) -> OMatrix>, C> where - D: DimName, - R: DimSub, - DefaultAllocator: Reallocator, C>, + R: DimSub>, + DefaultAllocator: Reallocator>, C>, { - self.remove_rows_generic(i, D::name()) + self.remove_rows_generic(i, Const::) } /// Removes `n` consecutive rows from this matrix, starting with the `i`-th (included). #[inline] #[cfg(any(feature = "std", feature = "alloc"))] - pub fn remove_rows(self, i: usize, n: usize) -> MatrixMN + pub fn remove_rows(self, i: usize, n: usize) -> OMatrix where R: DimSub, - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { self.remove_rows_generic(i, Dynamic::new(n)) } @@ -503,11 +502,11 @@ impl> Matrix { /// This is the generic implementation of `.remove_rows(...)` and `.remove_fixed_rows(...)` /// which have nicer API interfaces. #[inline] - pub fn remove_rows_generic(self, i: usize, nremove: D) -> MatrixMN, C> + pub fn remove_rows_generic(self, i: usize, nremove: D) -> OMatrix, C> where D: Dim, R: DimSub, - DefaultAllocator: Reallocator, C>, + DefaultAllocator: Reallocator, C>, { let mut m = self.into_owned(); let (nrows, ncols) = m.data.shape(); @@ -539,7 +538,7 @@ impl> Matrix { } /// # Rows and columns insertion -impl> Matrix { +impl> Matrix { /* * * Columns insertion. @@ -547,23 +546,26 @@ impl> Matrix { */ /// Inserts a column filled with `val` at the `i-th` position. #[inline] - pub fn insert_column(self, i: usize, val: N) -> MatrixMN> + pub fn insert_column(self, i: usize, val: T) -> OMatrix> where C: DimAdd, - DefaultAllocator: Reallocator>, + DefaultAllocator: Reallocator>, { - self.insert_fixed_columns::(i, val) + self.insert_fixed_columns::<1>(i, val) } - /// Inserts `D::dim()` columns filled with `val` starting at the `i-th` position. + /// Inserts `D` columns filled with `val` starting at the `i-th` position. #[inline] - pub fn insert_fixed_columns(self, i: usize, val: N) -> MatrixMN> + pub fn insert_fixed_columns( + self, + i: usize, + val: T, + ) -> OMatrix>> where - D: DimName, - C: DimAdd, - DefaultAllocator: Reallocator>, + C: DimAdd>, + DefaultAllocator: Reallocator>>, { - let mut res = unsafe { self.insert_columns_generic_uninitialized(i, D::name()) }; + let mut res = unsafe { self.insert_columns_generic_uninitialized(i, Const::) }; res.fixed_columns_mut::(i).fill(val); res } @@ -571,10 +573,10 @@ impl> Matrix { /// Inserts `n` columns filled with `val` starting at the `i-th` position. #[inline] #[cfg(any(feature = "std", feature = "alloc"))] - pub fn insert_columns(self, i: usize, n: usize, val: N) -> MatrixMN + pub fn insert_columns(self, i: usize, n: usize, val: T) -> OMatrix where C: DimAdd, - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { let mut res = unsafe { self.insert_columns_generic_uninitialized(i, Dynamic::new(n)) }; res.columns_mut(i, n).fill(val); @@ -589,11 +591,11 @@ impl> Matrix { self, i: usize, ninsert: D, - ) -> MatrixMN> + ) -> OMatrix> where D: Dim, C: DimAdd, - DefaultAllocator: Reallocator>, + DefaultAllocator: Reallocator>, { let m = self.into_owned(); let (nrows, ncols) = m.data.shape(); @@ -625,23 +627,26 @@ impl> Matrix { */ /// Inserts a row filled with `val` at the `i-th` position. #[inline] - pub fn insert_row(self, i: usize, val: N) -> MatrixMN, C> + pub fn insert_row(self, i: usize, val: T) -> OMatrix, C> where R: DimAdd, - DefaultAllocator: Reallocator, C>, + DefaultAllocator: Reallocator, C>, { - self.insert_fixed_rows::(i, val) + self.insert_fixed_rows::<1>(i, val) } /// Inserts `D::dim()` rows filled with `val` starting at the `i-th` position. #[inline] - pub fn insert_fixed_rows(self, i: usize, val: N) -> MatrixMN, C> + pub fn insert_fixed_rows( + self, + i: usize, + val: T, + ) -> OMatrix>, C> where - D: DimName, - R: DimAdd, - DefaultAllocator: Reallocator, C>, + R: DimAdd>, + DefaultAllocator: Reallocator>, C>, { - let mut res = unsafe { self.insert_rows_generic_uninitialized(i, D::name()) }; + let mut res = unsafe { self.insert_rows_generic_uninitialized(i, Const::) }; res.fixed_rows_mut::(i).fill(val); res } @@ -649,10 +654,10 @@ impl> Matrix { /// Inserts `n` rows filled with `val` starting at the `i-th` position. #[inline] #[cfg(any(feature = "std", feature = "alloc"))] - pub fn insert_rows(self, i: usize, n: usize, val: N) -> MatrixMN + pub fn insert_rows(self, i: usize, n: usize, val: T) -> OMatrix where R: DimAdd, - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { let mut res = unsafe { self.insert_rows_generic_uninitialized(i, Dynamic::new(n)) }; res.rows_mut(i, n).fill(val); @@ -669,11 +674,11 @@ impl> Matrix { self, i: usize, ninsert: D, - ) -> MatrixMN, C> + ) -> OMatrix, C> where D: Dim, R: DimAdd, - DefaultAllocator: Reallocator, C>, + DefaultAllocator: Reallocator, C>, { let m = self.into_owned(); let (nrows, ncols) = m.data.shape(); @@ -700,15 +705,15 @@ impl> Matrix { } /// # Resizing and reshaping -impl> Matrix { +impl> Matrix { /// Resizes this matrix so that it contains `new_nrows` rows and `new_ncols` columns. /// /// 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`. #[cfg(any(feature = "std", feature = "alloc"))] - pub fn resize(self, new_nrows: usize, new_ncols: usize, val: N) -> DMatrix + pub fn resize(self, new_nrows: usize, new_ncols: usize, val: T) -> DMatrix where - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { self.resize_generic(Dynamic::new(new_nrows), Dynamic::new(new_ncols), val) } @@ -718,9 +723,9 @@ impl> Matrix { /// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more /// rows than `self`, then the extra rows are filled with `val`. #[cfg(any(feature = "std", feature = "alloc"))] - pub fn resize_vertically(self, new_nrows: usize, val: N) -> MatrixMN + pub fn resize_vertically(self, new_nrows: usize, val: T) -> OMatrix where - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { let ncols = self.data.shape().1; self.resize_generic(Dynamic::new(new_nrows), ncols, val) @@ -731,9 +736,9 @@ impl> Matrix { /// The values are copied such that `self[(i, j)] == result[(i, j)]`. If the result has more /// columns than `self`, then the extra columns are filled with `val`. #[cfg(any(feature = "std", feature = "alloc"))] - pub fn resize_horizontally(self, new_ncols: usize, val: N) -> MatrixMN + pub fn resize_horizontally(self, new_ncols: usize, val: T) -> OMatrix where - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { let nrows = self.data.shape().0; self.resize_generic(nrows, Dynamic::new(new_ncols), val) @@ -743,11 +748,11 @@ 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 + pub fn fixed_resize(self, val: T) -> SMatrix where - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, Const>, { - self.resize_generic(R2::name(), C2::name(), val) + self.resize_generic(Const::, Const::, val) } /// Resizes `self` such that it has dimensions `new_nrows × new_ncols`. @@ -759,10 +764,10 @@ impl> Matrix { self, new_nrows: R2, new_ncols: C2, - val: N, - ) -> MatrixMN + val: T, + ) -> OMatrix where - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { let (nrows, ncols) = self.shape(); let mut data = self.data.into_owned(); @@ -874,11 +879,11 @@ impl> Matrix { self, new_nrows: R2, new_ncols: C2, - ) -> Matrix + ) -> Matrix where R2: Dim, C2: Dim, - S: ReshapableStorage, + S: ReshapableStorage, { let data = self.data.reshape_generic(new_nrows, new_ncols); Matrix::from_data(data) @@ -887,16 +892,16 @@ impl> Matrix { /// # In-place resizing #[cfg(any(feature = "std", feature = "alloc"))] -impl DMatrix { +impl DMatrix { /// Resizes this matrix in-place. /// /// 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`. /// /// Defined only for owned fully-dynamic matrices, i.e., `DMatrix`. - pub fn resize_mut(&mut self, new_nrows: usize, new_ncols: usize, val: N) + pub fn resize_mut(&mut self, new_nrows: usize, new_ncols: usize, val: T) where - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { let placeholder = unsafe { crate::unimplemented_or_uninitialized_generic!(Dynamic::new(0), Dynamic::new(0)) @@ -908,9 +913,9 @@ impl DMatrix { } #[cfg(any(feature = "std", feature = "alloc"))] -impl MatrixMN +impl OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { /// Changes the number of rows of this matrix in-place. /// @@ -919,9 +924,9 @@ where /// /// Defined only for owned matrices with a dynamic number of rows (for example, `DVector`). #[cfg(any(feature = "std", feature = "alloc"))] - pub fn resize_vertically_mut(&mut self, new_nrows: usize, val: N) + pub fn resize_vertically_mut(&mut self, new_nrows: usize, val: T) where - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { let placeholder = unsafe { crate::unimplemented_or_uninitialized_generic!(Dynamic::new(0), self.data.shape().1) @@ -933,9 +938,9 @@ where } #[cfg(any(feature = "std", feature = "alloc"))] -impl MatrixMN +impl OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { /// Changes the number of column of this matrix in-place. /// @@ -944,9 +949,9 @@ where /// /// Defined only for owned matrices with a dynamic number of columns (for example, `DVector`). #[cfg(any(feature = "std", feature = "alloc"))] - pub fn resize_horizontally_mut(&mut self, new_ncols: usize, val: N) + pub fn resize_horizontally_mut(&mut self, new_ncols: usize, val: T) where - DefaultAllocator: Reallocator, + DefaultAllocator: Reallocator, { let placeholder = unsafe { crate::unimplemented_or_uninitialized_generic!(self.data.shape().0, Dynamic::new(0)) @@ -957,8 +962,8 @@ where } } -unsafe fn compress_rows( - data: &mut [N], +unsafe fn compress_rows( + data: &mut [T], nrows: usize, ncols: usize, i: usize, @@ -996,8 +1001,8 @@ unsafe fn compress_rows( // Moves entries of a matrix buffer to make place for `ninsert` emty rows starting at the `i-th` row index. // The `data` buffer is assumed to contained at least `(nrows + ninsert) * ncols` elements. -unsafe fn extend_rows( - data: &mut [N], +unsafe fn extend_rows( + data: &mut [T], nrows: usize, ncols: usize, i: usize, @@ -1032,18 +1037,18 @@ unsafe fn extend_rows( /// Extend the number of columns of the `Matrix` with elements from /// a given iterator. #[cfg(any(feature = "std", feature = "alloc"))] -impl Extend for Matrix +impl Extend for Matrix where - N: Scalar, + T: Scalar, R: Dim, - S: Extend, + S: Extend, { /// Extend the number of columns of the `Matrix` with elements /// from the given iterator. /// /// # Example /// ``` - /// # use nalgebra::{DMatrix, Dynamic, Matrix, MatrixMN, Matrix3}; + /// # use nalgebra::{DMatrix, Dynamic, Matrix, OMatrix, Matrix3}; /// /// let data = vec![0, 1, 2, // column 1 /// 3, 4, 5]; // column 2 @@ -1063,7 +1068,7 @@ where /// `Matrix`. /// /// ```should_panic - /// # use nalgebra::{DMatrix, Dynamic, MatrixMN}; + /// # use nalgebra::{DMatrix, Dynamic, OMatrix}; /// let data = vec![0, 1, 2, // column 1 /// 3, 4, 5]; // column 2 /// @@ -1072,7 +1077,7 @@ where /// // The following panics because the vec length is not a multiple of 3. /// matrix.extend(vec![6, 7, 8, 9]); /// ``` - fn extend>(&mut self, iter: I) { + fn extend>(&mut self, iter: I) { self.data.extend(iter); } } @@ -1080,10 +1085,10 @@ where /// Extend the number of rows of the `Vector` with elements from /// a given iterator. #[cfg(any(feature = "std", feature = "alloc"))] -impl Extend for Matrix +impl Extend for Matrix where - N: Scalar, - S: Extend, + T: Scalar, + S: Extend, { /// Extend the number of rows of a `Vector` with elements /// from the given iterator. @@ -1095,19 +1100,19 @@ where /// vector.extend(vec![3, 4, 5]); /// assert!(vector.eq(&DVector::from_vec(vec![0, 1, 2, 3, 4, 5]))); /// ``` - fn extend>(&mut self, iter: I) { + fn extend>(&mut self, iter: I) { self.data.extend(iter); } } #[cfg(any(feature = "std", feature = "alloc"))] -impl Extend> for Matrix +impl Extend> for Matrix where - N: Scalar, + T: Scalar, R: Dim, - S: Extend>, + S: Extend>, RV: Dim, - SV: Storage, + SV: Storage, ShapeConstraint: SameNumberOfRows, { /// Extends the number of columns of a `Matrix` with `Vector`s @@ -1159,7 +1164,7 @@ where /// matrix.extend( /// vec![Vector4::new(6, 7, 8, 9)]); // too few dimensions! /// ``` - fn extend>>(&mut self, iter: I) { + fn extend>>(&mut self, iter: I) { self.data.extend(iter); } } diff --git a/src/base/indexing.rs b/src/base/indexing.rs index 2e2643c3..17fd1f66 100644 --- a/src/base/indexing.rs +++ b/src/base/indexing.rs @@ -7,7 +7,7 @@ use crate::base::{ use std::ops; -// N.B.: Not a public trait! +// T.B.: Not a public trait! trait DimRange { /// The number of elements indexed by this range. type Length: Dim; @@ -315,19 +315,19 @@ fn dimrange_rangetoinclusive_usize() { } /// A helper trait used for indexing operations. -pub trait MatrixIndex<'a, N: Scalar, R: Dim, C: Dim, S: Storage>: Sized { +pub trait MatrixIndex<'a, T: Scalar, R: Dim, C: Dim, S: Storage>: Sized { /// The output type returned by methods. type Output: 'a; /// Produces true if the given matrix is contained by this index. #[doc(hidden)] - fn contained_by(&self, matrix: &Matrix) -> bool; + fn contained_by(&self, matrix: &Matrix) -> bool; /// Produces a shared view of the data at this location if in bounds, /// or `None`, otherwise. #[doc(hidden)] #[inline(always)] - fn get(self, matrix: &'a Matrix) -> Option { + fn get(self, matrix: &'a Matrix) -> Option { if self.contained_by(matrix) { Some(unsafe { self.get_unchecked(matrix) }) } else { @@ -338,20 +338,20 @@ pub trait MatrixIndex<'a, N: Scalar, R: Dim, C: Dim, S: Storage>: Sized /// Produces a shared view of the data at this location if in bounds /// without any bounds checking. #[doc(hidden)] - unsafe fn get_unchecked(self, matrix: &'a Matrix) -> Self::Output; + unsafe fn get_unchecked(self, matrix: &'a Matrix) -> Self::Output; /// Produces a shared view to the data at this location, or panics /// if out of bounds. #[doc(hidden)] #[inline(always)] - fn index(self, matrix: &'a Matrix) -> Self::Output { + fn index(self, matrix: &'a Matrix) -> Self::Output { self.get(matrix).expect("Index out of bounds.") } } /// A helper trait used for indexing operations. -pub trait MatrixIndexMut<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut>: - MatrixIndex<'a, N, R, C, S> +pub trait MatrixIndexMut<'a, T: Scalar, R: Dim, C: Dim, S: StorageMut>: + MatrixIndex<'a, T, R, C, S> { /// The output type returned by methods. type OutputMut: 'a; @@ -359,13 +359,13 @@ pub trait MatrixIndexMut<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut>: /// Produces a mutable view of the data at this location, without /// performing any bounds checking. #[doc(hidden)] - unsafe fn get_unchecked_mut(self, matrix: &'a mut Matrix) -> Self::OutputMut; + unsafe fn get_unchecked_mut(self, matrix: &'a mut Matrix) -> Self::OutputMut; /// Produces a mutable view of the data at this location, if in /// bounds. #[doc(hidden)] #[inline(always)] - fn get_mut(self, matrix: &'a mut Matrix) -> Option { + fn get_mut(self, matrix: &'a mut Matrix) -> Option { if self.contained_by(matrix) { Some(unsafe { self.get_unchecked_mut(matrix) }) } else { @@ -377,7 +377,7 @@ pub trait MatrixIndexMut<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut>: /// if out of bounds. #[doc(hidden)] #[inline(always)] - fn index_mut(self, matrix: &'a mut Matrix) -> Self::OutputMut { + fn index_mut(self, matrix: &'a mut Matrix) -> Self::OutputMut { self.get_mut(matrix).expect("Index out of bounds.") } } @@ -481,13 +481,13 @@ pub trait MatrixIndexMut<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut>: /// 4, 7, /// 5, 8))); /// ``` -impl> Matrix { +impl> Matrix { /// Produces a view of the data at the given index, or /// `None` if the index is out of bounds. #[inline] pub fn get<'a, I>(&'a self, index: I) -> Option where - I: MatrixIndex<'a, N, R, C, S>, + I: MatrixIndex<'a, T, R, C, S>, { index.get(self) } @@ -497,8 +497,8 @@ impl> Matrix { #[inline] pub fn get_mut<'a, I>(&'a mut self, index: I) -> Option where - S: StorageMut, - I: MatrixIndexMut<'a, N, R, C, S>, + S: StorageMut, + I: MatrixIndexMut<'a, T, R, C, S>, { index.get_mut(self) } @@ -508,7 +508,7 @@ impl> Matrix { #[inline] pub fn index<'a, I>(&'a self, index: I) -> I::Output where - I: MatrixIndex<'a, N, R, C, S>, + I: MatrixIndex<'a, T, R, C, S>, { index.index(self) } @@ -518,8 +518,8 @@ impl> Matrix { #[inline] pub fn index_mut<'a, I>(&'a mut self, index: I) -> I::OutputMut where - S: StorageMut, - I: MatrixIndexMut<'a, N, R, C, S>, + S: StorageMut, + I: MatrixIndexMut<'a, T, R, C, S>, { index.index_mut(self) } @@ -529,7 +529,7 @@ impl> Matrix { #[inline] pub unsafe fn get_unchecked<'a, I>(&'a self, index: I) -> I::Output where - I: MatrixIndex<'a, N, R, C, S>, + I: MatrixIndex<'a, T, R, C, S>, { index.get_unchecked(self) } @@ -539,8 +539,8 @@ impl> Matrix { #[inline] pub unsafe fn get_unchecked_mut<'a, I>(&'a mut self, index: I) -> I::OutputMut where - S: StorageMut, - I: MatrixIndexMut<'a, N, R, C, S>, + S: StorageMut, + I: MatrixIndexMut<'a, T, R, C, S>, { index.get_unchecked_mut(self) } @@ -548,42 +548,42 @@ impl> Matrix { // EXTRACT A SINGLE ELEMENT BY 1D LINEAR ADDRESS -impl<'a, N, R, C, S> MatrixIndex<'a, N, R, C, S> for usize +impl<'a, T, R, C, S> MatrixIndex<'a, T, R, C, S> for usize where - N: Scalar, + T: Scalar, R: Dim, C: Dim, - S: Storage, + S: Storage, { - type Output = &'a N; + type Output = &'a T; #[doc(hidden)] #[inline(always)] - fn contained_by(&self, matrix: &Matrix) -> bool { + fn contained_by(&self, matrix: &Matrix) -> bool { *self < matrix.len() } #[doc(hidden)] #[inline(always)] - unsafe fn get_unchecked(self, matrix: &'a Matrix) -> Self::Output { + unsafe fn get_unchecked(self, matrix: &'a Matrix) -> Self::Output { matrix.data.get_unchecked_linear(self) } } -impl<'a, N, R, C, S> MatrixIndexMut<'a, N, R, C, S> for usize +impl<'a, T, R, C, S> MatrixIndexMut<'a, T, R, C, S> for usize where - N: Scalar, + T: Scalar, R: Dim, C: Dim, - S: StorageMut, + S: StorageMut, { - type OutputMut = &'a mut N; + type OutputMut = &'a mut T; #[doc(hidden)] #[inline(always)] - unsafe fn get_unchecked_mut(self, matrix: &'a mut Matrix) -> Self::OutputMut + unsafe fn get_unchecked_mut(self, matrix: &'a mut Matrix) -> Self::OutputMut where - S: StorageMut, + S: StorageMut, { matrix.data.get_unchecked_linear_mut(self) } @@ -591,18 +591,18 @@ where // EXTRACT A SINGLE ELEMENT BY 2D COORDINATES -impl<'a, N, R, C, S> MatrixIndex<'a, N, R, C, S> for (usize, usize) +impl<'a, T, R, C, S> MatrixIndex<'a, T, R, C, S> for (usize, usize) where - N: Scalar, + T: Scalar, R: Dim, C: Dim, - S: Storage, + S: Storage, { - type Output = &'a N; + type Output = &'a T; #[doc(hidden)] #[inline(always)] - fn contained_by(&self, matrix: &Matrix) -> bool { + fn contained_by(&self, matrix: &Matrix) -> bool { let (rows, cols) = self; let (nrows, ncols) = matrix.data.shape(); DimRange::contained_by(rows, nrows) && DimRange::contained_by(cols, ncols) @@ -610,26 +610,26 @@ where #[doc(hidden)] #[inline(always)] - unsafe fn get_unchecked(self, matrix: &'a Matrix) -> Self::Output { + unsafe fn get_unchecked(self, matrix: &'a Matrix) -> Self::Output { let (row, col) = self; matrix.data.get_unchecked(row, col) } } -impl<'a, N, R, C, S> MatrixIndexMut<'a, N, R, C, S> for (usize, usize) +impl<'a, T, R, C, S> MatrixIndexMut<'a, T, R, C, S> for (usize, usize) where - N: Scalar, + T: Scalar, R: Dim, C: Dim, - S: StorageMut, + S: StorageMut, { - type OutputMut = &'a mut N; + type OutputMut = &'a mut T; #[doc(hidden)] #[inline(always)] - unsafe fn get_unchecked_mut(self, matrix: &'a mut Matrix) -> Self::OutputMut + unsafe fn get_unchecked_mut(self, matrix: &'a mut Matrix) -> Self::OutputMut where - S: StorageMut, + S: StorageMut, { let (row, col) = self; matrix.data.get_unchecked_mut(row, col) @@ -655,20 +655,20 @@ macro_rules! impl_index_pair { $(where $CConstraintType: ty: $CConstraintBound: ident $(<$($CConstraintBoundParams: ty $( = $CEqBound: ty )*),*>)* )*] ) => { - impl<'a, N, $R, $C, S, $($RTyP : $RTyPB,)* $($CTyP : $CTyPB),*> MatrixIndex<'a, N, $R, $C, S> for ($RIdx, $CIdx) + impl<'a, T, $R, $C, S, $($RTyP : $RTyPB,)* $($CTyP : $CTyPB),*> MatrixIndex<'a, T, $R, $C, S> for ($RIdx, $CIdx) where - N: Scalar, + T: Scalar, $R: Dim, $C: Dim, - S: Storage, + S: Storage, $( $RConstraintType: $RConstraintBound $(<$( $RConstraintBoundParams $( = $REqBound )*),*>)* ,)* $( $CConstraintType: $CConstraintBound $(<$( $CConstraintBoundParams $( = $CEqBound )*),*>)* ),* { - type Output = MatrixSlice<'a, N, $ROut, $COut, S::RStride, S::CStride>; + type Output = MatrixSlice<'a, T, $ROut, $COut, S::RStride, S::CStride>; #[doc(hidden)] #[inline(always)] - fn contained_by(&self, matrix: &Matrix) -> bool { + fn contained_by(&self, matrix: &Matrix) -> bool { let (rows, cols) = self; let (nrows, ncols) = matrix.data.shape(); DimRange::contained_by(rows, nrows) && DimRange::contained_by(cols, ncols) @@ -676,7 +676,7 @@ macro_rules! impl_index_pair { #[doc(hidden)] #[inline(always)] - unsafe fn get_unchecked(self, matrix: &'a Matrix) -> Self::Output { + unsafe fn get_unchecked(self, matrix: &'a Matrix) -> Self::Output { use crate::base::SliceStorage; let (rows, cols) = self; @@ -691,20 +691,20 @@ macro_rules! impl_index_pair { } } - impl<'a, N, $R, $C, S, $($RTyP : $RTyPB,)* $($CTyP : $CTyPB),*> MatrixIndexMut<'a, N, $R, $C, S> for ($RIdx, $CIdx) + impl<'a, T, $R, $C, S, $($RTyP : $RTyPB,)* $($CTyP : $CTyPB),*> MatrixIndexMut<'a, T, $R, $C, S> for ($RIdx, $CIdx) where - N: Scalar, + T: Scalar, $R: Dim, $C: Dim, - S: StorageMut, + S: StorageMut, $( $RConstraintType: $RConstraintBound $(<$( $RConstraintBoundParams $( = $REqBound )*),*>)* ,)* $( $CConstraintType: $CConstraintBound $(<$( $CConstraintBoundParams $( = $CEqBound )*),*>)* ),* { - type OutputMut = MatrixSliceMut<'a, N, $ROut, $COut, S::RStride, S::CStride>; + type OutputMut = MatrixSliceMut<'a, T, $ROut, $COut, S::RStride, S::CStride>; #[doc(hidden)] #[inline(always)] - unsafe fn get_unchecked_mut(self, matrix: &'a mut Matrix) -> Self::OutputMut { + unsafe fn get_unchecked_mut(self, matrix: &'a mut Matrix) -> Self::OutputMut { use crate::base::SliceStorageMut; let (rows, cols) = self; diff --git a/src/base/interpolation.rs b/src/base/interpolation.rs index 1d74d203..c008743a 100644 --- a/src/base/interpolation.rs +++ b/src/base/interpolation.rs @@ -1,12 +1,12 @@ use crate::storage::Storage; use crate::{ - Allocator, DefaultAllocator, Dim, One, RealField, Scalar, Unit, Vector, VectorN, Zero, + Allocator, DefaultAllocator, Dim, OVector, One, RealField, Scalar, Unit, Vector, Zero, }; use simba::scalar::{ClosedAdd, ClosedMul, ClosedSub}; /// # Interpolation -impl> - Vector +impl> + Vector { /// Returns `self * (1.0 - t) + rhs * t`, i.e., the linear blend of the vectors x and y using the scalar value a. /// @@ -20,12 +20,12 @@ impl>(&self, rhs: &Vector, t: N) -> VectorN + pub fn lerp>(&self, rhs: &Vector, t: T) -> OVector where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let mut res = self.clone_owned(); - res.axpy(t.inlined_clone(), rhs, N::one() - t); + res.axpy(t.inlined_clone(), rhs, T::one() - t); res } @@ -45,10 +45,10 @@ impl>(&self, rhs: &Vector, t: N) -> VectorN + pub fn slerp>(&self, rhs: &Vector, t: T) -> OVector where - N: RealField, - DefaultAllocator: Allocator, + T: RealField, + DefaultAllocator: Allocator, { let me = Unit::new_normalize(self.clone_owned()); let rhs = Unit::new_normalize(rhs.clone_owned()); @@ -57,7 +57,7 @@ impl> Unit> { +impl> Unit> { /// Computes the spherical linear interpolation between two unit vectors. /// /// # Examples: @@ -72,16 +72,16 @@ impl> Unit> { /// /// assert_eq!(v, v2); /// ``` - pub fn slerp>( + pub fn slerp>( &self, - rhs: &Unit>, - t: N, - ) -> Unit> + rhs: &Unit>, + t: T, + ) -> Unit> where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { // TODO: the result is wrong when self and rhs are collinear with opposite direction. - self.try_slerp(rhs, t, N::default_epsilon()) + self.try_slerp(rhs, t, T::default_epsilon()) .unwrap_or_else(|| Unit::new_unchecked(self.clone_owned())) } @@ -89,33 +89,33 @@ impl> Unit> { /// /// Returns `None` if the two vectors are almost collinear and with opposite direction /// (in this case, there is an infinity of possible results). - pub fn try_slerp>( + pub fn try_slerp>( &self, - rhs: &Unit>, - t: N, - epsilon: N, - ) -> Option>> + rhs: &Unit>, + t: T, + epsilon: T, + ) -> Option>> where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let c_hang = self.dot(rhs); // self == other - if c_hang >= N::one() { + if c_hang >= T::one() { return Some(Unit::new_unchecked(self.clone_owned())); } let hang = c_hang.acos(); - let s_hang = (N::one() - c_hang * c_hang).sqrt(); + let s_hang = (T::one() - c_hang * c_hang).sqrt(); // TODO: what if s_hang is 0.0 ? The result is not well-defined. - if relative_eq!(s_hang, N::zero(), epsilon = epsilon) { + if relative_eq!(s_hang, T::zero(), epsilon = epsilon) { None } else { - let ta = ((N::one() - t) * hang).sin() / s_hang; + let ta = ((T::one() - t) * hang).sin() / s_hang; let tb = (t * hang).sin() / s_hang; let mut res = self.scale(ta); - res.axpy(tb, &**rhs, N::one()); + res.axpy(tb, &**rhs, T::one()); Some(Unit::new_unchecked(res)) } diff --git a/src/base/iter.rs b/src/base/iter.rs index f744cf02..1592299d 100644 --- a/src/base/iter.rs +++ b/src/base/iter.rs @@ -11,7 +11,7 @@ use crate::base::{Matrix, MatrixSlice, MatrixSliceMut, Scalar}; macro_rules! iterator { (struct $Name:ident for $Storage:ident.$ptr: ident -> $Ptr:ty, $Ref:ty, $SRef: ty) => { /// An iterator through a dense matrix with arbitrary strides matrix. - pub struct $Name<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage> { + pub struct $Name<'a, T: Scalar, R: Dim, C: Dim, S: 'a + $Storage> { ptr: $Ptr, inner_ptr: $Ptr, inner_end: $Ptr, @@ -22,9 +22,9 @@ macro_rules! iterator { // TODO: we need to specialize for the case where the matrix storage is owned (in which // case the iterator is trivial because it does not have any stride). - impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage> $Name<'a, N, R, C, S> { + impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + $Storage> $Name<'a, T, R, C, S> { /// Creates a new iterator for the given matrix storage. - pub fn new(storage: $SRef) -> $Name<'a, N, R, C, S> { + pub fn new(storage: $SRef) -> $Name<'a, T, R, C, S> { let shape = storage.shape(); let strides = storage.strides(); let inner_offset = shape.0.value() * strides.0.value(); @@ -59,8 +59,8 @@ macro_rules! iterator { } } - impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage> Iterator - for $Name<'a, N, R, C, S> + impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + $Storage> Iterator + for $Name<'a, T, R, C, S> { type Item = $Ref; @@ -112,8 +112,8 @@ macro_rules! iterator { } } - impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage> DoubleEndedIterator - for $Name<'a, N, R, C, S> + impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + $Storage> DoubleEndedIterator + for $Name<'a, T, R, C, S> { #[inline] fn next_back(&mut self) -> Option<$Ref> { @@ -152,8 +152,8 @@ macro_rules! iterator { } } - impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage> ExactSizeIterator - for $Name<'a, N, R, C, S> + impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + $Storage> ExactSizeIterator + for $Name<'a, T, R, C, S> { #[inline] fn len(&self) -> usize { @@ -161,15 +161,15 @@ macro_rules! iterator { } } - impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + $Storage> FusedIterator - for $Name<'a, N, R, C, S> + impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + $Storage> FusedIterator + for $Name<'a, T, R, C, S> { } }; } -iterator!(struct MatrixIter for Storage.ptr -> *const N, &'a N, &'a S); -iterator!(struct MatrixIterMut for StorageMut.ptr_mut -> *mut N, &'a mut N, &'a mut S); +iterator!(struct MatrixIter for Storage.ptr -> *const T, &'a T, &'a S); +iterator!(struct MatrixIterMut for StorageMut.ptr_mut -> *mut T, &'a mut T, &'a mut S); /* * @@ -178,19 +178,19 @@ iterator!(struct MatrixIterMut for StorageMut.ptr_mut -> *mut N, &'a mut N, &'a */ #[derive(Clone)] /// An iterator through the rows of a matrix. -pub struct RowIter<'a, N: Scalar, R: Dim, C: Dim, S: Storage> { - mat: &'a Matrix, +pub struct RowIter<'a, T: Scalar, R: Dim, C: Dim, S: Storage> { + mat: &'a Matrix, curr: usize, } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> RowIter<'a, N, R, C, S> { - pub(crate) fn new(mat: &'a Matrix) -> Self { +impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + Storage> RowIter<'a, T, R, C, S> { + pub(crate) fn new(mat: &'a Matrix) -> Self { RowIter { mat, curr: 0 } } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator for RowIter<'a, N, R, C, S> { - type Item = MatrixSlice<'a, N, U1, C, S::RStride, S::CStride>; +impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator for RowIter<'a, T, R, C, S> { + type Item = MatrixSlice<'a, T, U1, C, S::RStride, S::CStride>; #[inline] fn next(&mut self) -> Option { @@ -217,8 +217,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator for RowIt } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator - for RowIter<'a, N, R, C, S> +impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator + for RowIter<'a, T, R, C, S> { #[inline] fn len(&self) -> usize { @@ -227,14 +227,14 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator } /// An iterator through the mutable rows of a matrix. -pub struct RowIterMut<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut> { - mat: *mut Matrix, +pub struct RowIterMut<'a, T: Scalar, R: Dim, C: Dim, S: StorageMut> { + mat: *mut Matrix, curr: usize, - phantom: PhantomData<&'a mut Matrix>, + phantom: PhantomData<&'a mut Matrix>, } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> RowIterMut<'a, N, R, C, S> { - pub(crate) fn new(mat: &'a mut Matrix) -> Self { +impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> RowIterMut<'a, T, R, C, S> { + pub(crate) fn new(mat: &'a mut Matrix) -> Self { RowIterMut { mat, curr: 0, @@ -247,10 +247,10 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> RowIterMut<'a, } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> Iterator - for RowIterMut<'a, N, R, C, S> +impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> Iterator + for RowIterMut<'a, T, R, C, S> { - type Item = MatrixSliceMut<'a, N, U1, C, S::RStride, S::CStride>; + type Item = MatrixSliceMut<'a, T, U1, C, S::RStride, S::CStride>; #[inline] fn next(&mut self) -> Option { @@ -274,8 +274,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> Iterator } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterator - for RowIterMut<'a, N, R, C, S> +impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterator + for RowIterMut<'a, T, R, C, S> { #[inline] fn len(&self) -> usize { @@ -290,21 +290,21 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterat */ #[derive(Clone)] /// An iterator through the columns of a matrix. -pub struct ColumnIter<'a, N: Scalar, R: Dim, C: Dim, S: Storage> { - mat: &'a Matrix, +pub struct ColumnIter<'a, T: Scalar, R: Dim, C: Dim, S: Storage> { + mat: &'a Matrix, curr: usize, } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> ColumnIter<'a, N, R, C, S> { - pub(crate) fn new(mat: &'a Matrix) -> Self { +impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + Storage> ColumnIter<'a, T, R, C, S> { + pub(crate) fn new(mat: &'a Matrix) -> Self { ColumnIter { mat, curr: 0 } } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator - for ColumnIter<'a, N, R, C, S> +impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator + for ColumnIter<'a, T, R, C, S> { - type Item = MatrixSlice<'a, N, R, U1, S::RStride, S::CStride>; + type Item = MatrixSlice<'a, T, R, U1, S::RStride, S::CStride>; #[inline] fn next(&mut self) -> Option { @@ -331,8 +331,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> Iterator } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator - for ColumnIter<'a, N, R, C, S> +impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator + for ColumnIter<'a, T, R, C, S> { #[inline] fn len(&self) -> usize { @@ -341,14 +341,14 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + Storage> ExactSizeIterator } /// An iterator through the mutable columns of a matrix. -pub struct ColumnIterMut<'a, N: Scalar, R: Dim, C: Dim, S: StorageMut> { - mat: *mut Matrix, +pub struct ColumnIterMut<'a, T: Scalar, R: Dim, C: Dim, S: StorageMut> { + mat: *mut Matrix, curr: usize, - phantom: PhantomData<&'a mut Matrix>, + phantom: PhantomData<&'a mut Matrix>, } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ColumnIterMut<'a, N, R, C, S> { - pub(crate) fn new(mat: &'a mut Matrix) -> Self { +impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ColumnIterMut<'a, T, R, C, S> { + pub(crate) fn new(mat: &'a mut Matrix) -> Self { ColumnIterMut { mat, curr: 0, @@ -361,10 +361,10 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ColumnIterMut<' } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> Iterator - for ColumnIterMut<'a, N, R, C, S> +impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> Iterator + for ColumnIterMut<'a, T, R, C, S> { - type Item = MatrixSliceMut<'a, N, R, U1, S::RStride, S::CStride>; + type Item = MatrixSliceMut<'a, T, R, U1, S::RStride, S::CStride>; #[inline] fn next(&mut self) -> Option { @@ -388,8 +388,8 @@ impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> Iterator } } -impl<'a, N: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterator - for ColumnIterMut<'a, N, R, C, S> +impl<'a, T: Scalar, R: Dim, C: Dim, S: 'a + StorageMut> ExactSizeIterator + for ColumnIterMut<'a, T, R, C, S> { #[inline] fn len(&self) -> usize { diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 6914fbb4..6d326e58 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -28,29 +28,29 @@ use crate::base::iter::{ use crate::base::storage::{ ContiguousStorage, ContiguousStorageMut, Owned, SameShapeStorage, Storage, StorageMut, }; -use crate::base::{Const, DefaultAllocator, MatrixMN, MatrixN, Scalar, Unit, VectorN}; +use crate::base::{Const, DefaultAllocator, OMatrix, OVector, Scalar, Unit}; use crate::SimdComplexField; /// A square matrix. -pub type SquareMatrix = Matrix; +pub type SquareMatrix = Matrix; /// A matrix with one column and `D` rows. -pub type Vector = Matrix; +pub type Vector = Matrix; /// A matrix with one row and `D` columns . -pub type RowVector = Matrix; +pub type RowVector = Matrix; /// The type of the result of a matrix sum. -pub type MatrixSum = - Matrix, SameShapeC, SameShapeStorage>; +pub type MatrixSum = + Matrix, SameShapeC, SameShapeStorage>; /// The type of the result of a matrix sum. -pub type VectorSum = - Matrix, U1, SameShapeStorage>; +pub type VectorSum = + Matrix, U1, SameShapeStorage>; /// The type of the result of a matrix cross product. -pub type MatrixCross = - Matrix, SameShapeC, SameShapeStorage>; +pub type MatrixCross = + Matrix, SameShapeC, SameShapeStorage>; /// The most generic column-major matrix (and vector) type. /// @@ -128,7 +128,7 @@ pub type MatrixCross = /// /// # Type parameters /// The generic `Matrix` type has four type parameters: -/// - `N`: for the matrix components scalar type. +/// - `T`: for the matrix components scalar type. /// - `R`: for the matrix number of rows. /// - `C`: for the matrix number of columns. /// - `S`: for the matrix data storage, i.e., the buffer that actually contains the matrix @@ -146,11 +146,11 @@ pub type MatrixCross = /// matrix shape. /// /// Note that mixing `Dynamic` with type-level unsigned integers is allowed. Actually, a -/// dynamically-sized column vector should be represented as a `Matrix` (given -/// some concrete types for `N` and a compatible data storage type `S`). +/// dynamically-sized column vector should be represented as a `Matrix` (given +/// some concrete types for `T` and a compatible data storage type `S`). #[repr(C)] #[derive(Clone, Copy)] -pub struct Matrix { +pub struct Matrix { /// The data storage that contains all the matrix components. Disappointed? /// /// Well, if you came here to see how you can access the matrix components, @@ -176,10 +176,10 @@ pub struct Matrix { /// starts at 0 as you would expect. pub data: S, - _phantoms: PhantomData<(N, R, C)>, + _phantoms: PhantomData<(T, R, C)>, } -impl fmt::Debug for Matrix { +impl fmt::Debug for Matrix { fn fmt(&self, formatter: &mut fmt::Formatter) -> Result<(), fmt::Error> { formatter .debug_struct("Matrix") @@ -188,9 +188,9 @@ impl fmt::Debug for Matrix } } -impl Default for Matrix +impl Default for Matrix where - N: Scalar, + T: Scalar, R: Dim, C: Dim, S: Default, @@ -204,25 +204,25 @@ where } #[cfg(feature = "serde-serialize")] -impl Serialize for Matrix +impl Serialize for Matrix where - N: Scalar, + T: Scalar, R: Dim, C: Dim, S: Serialize, { - fn serialize(&self, serializer: T) -> Result + fn serialize(&self, serializer: Ser) -> Result where - T: Serializer, + Ser: Serializer, { self.data.serialize(serializer) } } #[cfg(feature = "serde-serialize")] -impl<'de, N, R, C, S> Deserialize<'de> for Matrix +impl<'de, T, R, C, S> Deserialize<'de> for Matrix where - N: Scalar, + T: Scalar, R: Dim, C: Dim, S: Deserialize<'de>, @@ -239,7 +239,7 @@ where } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Matrix { +impl Abomonation for Matrix { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.data.entomb(writer) } @@ -254,8 +254,8 @@ impl Abomonation for Matrix> matrixcompare_core::Matrix - for Matrix +impl> matrixcompare_core::Matrix + for Matrix { fn rows(&self) -> usize { self.nrows() @@ -265,41 +265,41 @@ impl> matrixcompare_core::Matrix< self.ncols() } - fn access(&self) -> matrixcompare_core::Access { + fn access(&self) -> matrixcompare_core::Access { matrixcompare_core::Access::Dense(self) } } #[cfg(feature = "compare")] -impl> matrixcompare_core::DenseAccess - for Matrix +impl> matrixcompare_core::DenseAccess + for Matrix { - fn fetch_single(&self, row: usize, col: usize) -> N { + fn fetch_single(&self, row: usize, col: usize) -> T { self.index((row, col)).clone() } } #[cfg(feature = "bytemuck")] -unsafe impl> bytemuck::Zeroable - for Matrix +unsafe impl> bytemuck::Zeroable + for Matrix where S: bytemuck::Zeroable, { } #[cfg(feature = "bytemuck")] -unsafe impl> bytemuck::Pod for Matrix +unsafe impl> bytemuck::Pod for Matrix where S: bytemuck::Pod, Self: Copy, { } -impl Matrix { +impl Matrix { /// Creates a new matrix with the given data without statically checking that the matrix /// dimension matches the storage dimension. #[inline] - pub unsafe fn from_data_statically_unchecked(data: S) -> Matrix { + pub unsafe fn from_data_statically_unchecked(data: S) -> Matrix { Matrix { data, _phantoms: PhantomData, @@ -307,7 +307,7 @@ impl Matrix { } } -impl> Matrix { +impl> Matrix { /// Creates a new matrix with the given data. #[inline] pub fn from_data(data: S) -> Self { @@ -316,16 +316,16 @@ impl> Matrix { /// Creates a new uninitialized matrix with the given uninitialized data pub unsafe fn from_uninitialized_data(data: mem::MaybeUninit) -> mem::MaybeUninit { - let res: Matrix> = Matrix { + let res: Matrix> = Matrix { data, _phantoms: PhantomData, }; - let res: mem::MaybeUninit>> = + let res: mem::MaybeUninit>> = mem::MaybeUninit::new(res); // safety: since we wrap the inner MaybeUninit in an outer MaybeUninit above, the fact that the `data` field is partially-uninitialized is still opaque. - // with s/transmute_copy/transmute/, rustc claims that `MaybeUninit>>` may be of a different size from `MaybeUninit>` + // with s/transmute_copy/transmute/, rustc claims that `MaybeUninit>>` may be of a different size from `MaybeUninit>` // but MaybeUninit's documentation says "MaybeUninit is guaranteed to have the same size, alignment, and ABI as T", which implies those types should be the same size - let res: mem::MaybeUninit> = mem::transmute_copy(&res); + let res: mem::MaybeUninit> = mem::transmute_copy(&res); res } @@ -426,7 +426,7 @@ impl> Matrix { /// assert_eq!(unsafe { *ptr }, m[0]); /// ``` #[inline] - pub fn as_ptr(&self) -> *const N { + pub fn as_ptr(&self) -> *const T { self.data.ptr() } @@ -436,16 +436,16 @@ impl> Matrix { #[inline] pub fn relative_eq( &self, - other: &Matrix, - eps: N::Epsilon, - max_relative: N::Epsilon, + other: &Matrix, + eps: T::Epsilon, + max_relative: T::Epsilon, ) -> bool where - N: RelativeEq, + T: RelativeEq, R2: Dim, C2: Dim, - SB: Storage, - N::Epsilon: Copy, + SB: Storage, + T::Epsilon: Copy, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { assert!(self.shape() == other.shape()); @@ -456,12 +456,12 @@ impl> Matrix { /// Tests whether `self` and `rhs` are exactly equal. #[inline] - pub fn eq(&self, other: &Matrix) -> bool + pub fn eq(&self, other: &Matrix) -> bool where - N: PartialEq, + T: PartialEq, R2: Dim, C2: Dim, - SB: Storage, + SB: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { assert!(self.shape() == other.shape()); @@ -470,9 +470,9 @@ impl> Matrix { /// Moves this matrix into one that owns its data. #[inline] - pub fn into_owned(self) -> MatrixMN + pub fn into_owned(self) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { Matrix::from_data(self.data.into_owned()) } @@ -482,14 +482,14 @@ impl> Matrix { /// Moves this matrix into one that owns its data. The actual type of the result depends on /// matrix storage combination rules for addition. #[inline] - pub fn into_owned_sum(self) -> MatrixSum + pub fn into_owned_sum(self) -> MatrixSum where R2: Dim, C2: Dim, - DefaultAllocator: SameShapeAllocator, + DefaultAllocator: SameShapeAllocator, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { - if TypeId::of::>() == TypeId::of::>() { + if TypeId::of::>() == TypeId::of::>() { // We can just return `self.into_owned()`. unsafe { @@ -506,9 +506,9 @@ impl> Matrix { /// Clones this matrix to one that owns its data. #[inline] - pub fn clone_owned(&self) -> MatrixMN + pub fn clone_owned(&self) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { Matrix::from_data(self.data.clone_owned()) } @@ -516,18 +516,18 @@ impl> Matrix { /// Clones this matrix into one that owns its data. The actual type of the result depends on /// matrix storage combination rules for addition. #[inline] - pub fn clone_owned_sum(&self) -> MatrixSum + pub fn clone_owned_sum(&self) -> MatrixSum where R2: Dim, C2: Dim, - DefaultAllocator: SameShapeAllocator, + DefaultAllocator: SameShapeAllocator, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { let (nrows, ncols) = self.shape(); let nrows: SameShapeR = Dim::from_usize(nrows); let ncols: SameShapeC = Dim::from_usize(ncols); - let mut res: MatrixSum = + let mut res: MatrixSum = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; // TODO: use copy_from @@ -544,11 +544,11 @@ impl> Matrix { /// Transposes `self` and store the result into `out`. #[inline] - pub fn transpose_to(&self, out: &mut Matrix) + pub fn transpose_to(&self, out: &mut Matrix) where R2: Dim, C2: Dim, - SB: StorageMut, + SB: StorageMut, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { let (nrows, ncols) = self.shape(); @@ -570,9 +570,9 @@ impl> Matrix { /// Transposes `self`. #[inline] #[must_use = "Did you mean to use transpose_mut()?"] - pub fn transpose(&self) -> MatrixMN + pub fn transpose(&self) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let (nrows, ncols) = self.data.shape(); @@ -586,16 +586,16 @@ impl> Matrix { } /// # Elementwise mapping and folding -impl> Matrix { +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 + pub fn map T2>(&self, mut f: F) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let (nrows, ncols) = self.data.shape(); - let mut res: MatrixMN = + let mut res: OMatrix = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; for j in 0..ncols.value() { @@ -619,10 +619,10 @@ impl> Matrix { /// let q2 = q.cast::(); /// assert_eq!(q2, Vector3::new(1.0f32, 2.0, 3.0)); /// ``` - pub fn cast(self) -> MatrixMN + pub fn cast(self) -> OMatrix where - MatrixMN: SupersetOf, - DefaultAllocator: Allocator, + OMatrix: SupersetOf, + DefaultAllocator: Allocator, { crate::convert(self) } @@ -635,11 +635,11 @@ impl> Matrix { /// - If the matrix has has least one component, then `init_f` is called with the first component /// to compute the initial value. Folding then continues on all the remaining components of the matrix. #[inline] - pub fn fold_with( + pub fn fold_with( &self, - init_f: impl FnOnce(Option<&N>) -> N2, - f: impl FnMut(N2, &N) -> N2, - ) -> N2 { + init_f: impl FnOnce(Option<&T>) -> T2, + f: impl FnMut(T2, &T) -> T2, + ) -> T2 { let mut it = self.iter(); let init = init_f(it.next()); it.fold(init, f) @@ -648,16 +648,16 @@ impl> Matrix { /// Returns a matrix containing the result of `f` applied to each of its entries. Unlike `map`, /// `f` also gets passed the row and column index, i.e. `f(row, col, value)`. #[inline] - pub fn map_with_location N2>( + pub fn map_with_location T2>( &self, mut f: F, - ) -> MatrixMN + ) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let (nrows, ncols) = self.data.shape(); - let mut res: MatrixMN = + let mut res: OMatrix = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; for j in 0..ncols.value() { @@ -675,17 +675,17 @@ impl> Matrix { /// Returns a matrix containing the result of `f` applied to each entries of `self` and /// `rhs`. #[inline] - pub fn zip_map(&self, rhs: &Matrix, mut f: F) -> MatrixMN + pub fn zip_map(&self, rhs: &Matrix, mut f: F) -> OMatrix where - N2: Scalar, + T2: Scalar, N3: Scalar, - S2: Storage, - F: FnMut(N, N2) -> N3, + S2: Storage, + F: FnMut(T, T2) -> N3, DefaultAllocator: Allocator, { let (nrows, ncols) = self.data.shape(); - let mut res: MatrixMN = + let mut res: OMatrix = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; assert_eq!( @@ -710,24 +710,24 @@ impl> Matrix { /// Returns a matrix containing the result of `f` applied to each entries of `self` and /// `b`, and `c`. #[inline] - pub fn zip_zip_map( + pub fn zip_zip_map( &self, - b: &Matrix, + b: &Matrix, c: &Matrix, mut f: F, - ) -> MatrixMN + ) -> OMatrix where - N2: Scalar, + T2: Scalar, N3: Scalar, N4: Scalar, - S2: Storage, + S2: Storage, S3: Storage, - F: FnMut(N, N2, N3) -> N4, + F: FnMut(T, T2, N3) -> N4, DefaultAllocator: Allocator, { let (nrows, ncols) = self.data.shape(); - let mut res: MatrixMN = + let mut res: OMatrix = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, ncols) }; assert_eq!( @@ -757,7 +757,7 @@ impl> Matrix { /// Folds a function `f` on each entry of `self`. #[inline] - pub fn fold(&self, init: Acc, mut f: impl FnMut(Acc, N) -> Acc) -> Acc { + pub fn fold(&self, init: Acc, mut f: impl FnMut(Acc, T) -> Acc) -> Acc { let (nrows, ncols) = self.data.shape(); let mut res = init; @@ -776,17 +776,17 @@ impl> Matrix { /// Folds a function `f` on each pairs of entries from `self` and `rhs`. #[inline] - pub fn zip_fold( + pub fn zip_fold( &self, - rhs: &Matrix, + rhs: &Matrix, init: Acc, - mut f: impl FnMut(Acc, N, N2) -> Acc, + mut f: impl FnMut(Acc, T, T2) -> Acc, ) -> Acc where - N2: Scalar, + T2: Scalar, R2: Dim, C2: Dim, - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { let (nrows, ncols) = self.data.shape(); @@ -814,9 +814,9 @@ 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) + pub fn apply T>(&mut self, mut f: F) where - S: StorageMut, + S: StorageMut, { let (nrows, ncols) = self.shape(); @@ -833,16 +833,16 @@ impl> Matrix { /// Replaces each component of `self` by the result of a closure `f` applied on its components /// joined with the components from `rhs`. #[inline] - pub fn zip_apply( + pub fn zip_apply( &mut self, - rhs: &Matrix, - mut f: impl FnMut(N, N2) -> N, + rhs: &Matrix, + mut f: impl FnMut(T, T2) -> T, ) where - S: StorageMut, - N2: Scalar, + S: StorageMut, + T2: Scalar, R2: Dim, C2: Dim, - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { let (nrows, ncols) = self.shape(); @@ -867,17 +867,17 @@ impl> Matrix { /// Replaces each component of `self` by the result of a closure `f` applied on its components /// joined with the components from `b` and `c`. #[inline] - pub fn zip_zip_apply( + pub fn zip_zip_apply( &mut self, - b: &Matrix, + b: &Matrix, c: &Matrix, - mut f: impl FnMut(N, N2, N3) -> N, + mut f: impl FnMut(T, T2, N3) -> T, ) where - S: StorageMut, - N2: Scalar, + S: StorageMut, + T2: Scalar, R2: Dim, C2: Dim, - S2: Storage, + S2: Storage, N3: Scalar, R3: Dim, C3: Dim, @@ -912,7 +912,7 @@ impl> Matrix { } /// # Iteration on components, rows, and columns -impl> Matrix { +impl> Matrix { /// Iterates through this matrix coordinates in column-major order. /// /// # Examples: @@ -930,7 +930,7 @@ impl> Matrix { /// assert_eq!(*it.next().unwrap(), 23); /// assert!(it.next().is_none()); #[inline] - pub fn iter(&self) -> MatrixIter { + pub fn iter(&self) -> MatrixIter { MatrixIter::new(&self.data) } @@ -946,7 +946,7 @@ impl> Matrix { /// } /// ``` #[inline] - pub fn row_iter(&self) -> RowIter { + pub fn row_iter(&self) -> RowIter { RowIter::new(self) } @@ -961,15 +961,15 @@ impl> Matrix { /// } /// ``` #[inline] - pub fn column_iter(&self) -> ColumnIter { + pub fn column_iter(&self) -> ColumnIter { ColumnIter::new(self) } /// Mutably iterates through this matrix coordinates. #[inline] - pub fn iter_mut(&mut self) -> MatrixIterMut + pub fn iter_mut(&mut self) -> MatrixIterMut where - S: StorageMut, + S: StorageMut, { MatrixIterMut::new(&mut self.data) } @@ -990,9 +990,9 @@ impl> Matrix { /// assert_eq!(a, expected); /// ``` #[inline] - pub fn row_iter_mut(&mut self) -> RowIterMut + pub fn row_iter_mut(&mut self) -> RowIterMut where - S: StorageMut, + S: StorageMut, { RowIterMut::new(self) } @@ -1013,21 +1013,21 @@ impl> Matrix { /// assert_eq!(a, expected); /// ``` #[inline] - pub fn column_iter_mut(&mut self) -> ColumnIterMut + pub fn column_iter_mut(&mut self) -> ColumnIterMut where - S: StorageMut, + S: StorageMut, { ColumnIterMut::new(self) } } -impl> Matrix { +impl> Matrix { /// Returns a mutable pointer to the start of the matrix. /// /// If the matrix is not empty, this pointer is guaranteed to be aligned /// and non-null. #[inline] - pub fn as_mut_ptr(&mut self) -> *mut N { + pub fn as_mut_ptr(&mut self) -> *mut T { self.data.ptr_mut() } @@ -1058,7 +1058,7 @@ impl> Matrix { /// /// The components of the slice are assumed to be ordered in column-major order. #[inline] - pub fn copy_from_slice(&mut self, slice: &[N]) { + pub fn copy_from_slice(&mut self, slice: &[T]) { let (nrows, ncols) = self.shape(); assert!( @@ -1078,11 +1078,11 @@ impl> Matrix { /// Fills this matrix with the content of another one. Both must have the same shape. #[inline] - pub fn copy_from(&mut self, other: &Matrix) + pub fn copy_from(&mut self, other: &Matrix) where R2: Dim, C2: Dim, - SB: Storage, + SB: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { assert!( @@ -1101,11 +1101,11 @@ impl> Matrix { /// Fills this matrix with the content of the transpose another one. #[inline] - pub fn tr_copy_from(&mut self, other: &Matrix) + pub fn tr_copy_from(&mut self, other: &Matrix) where R2: Dim, C2: Dim, - SB: Storage, + SB: Storage, ShapeConstraint: DimEq + SameNumberOfColumns, { let (nrows, ncols) = self.shape(); @@ -1126,49 +1126,49 @@ impl> Matrix { // TODO: rename `apply` to `apply_mut` and `apply_into` to `apply`? /// Returns `self` with each of its components replaced by the result of a closure `f` applied on it. #[inline] - pub fn apply_into N>(mut self, f: F) -> Self { + pub fn apply_into T>(mut self, f: F) -> Self { self.apply(f); self } } -impl> Vector { +impl> Vector { /// Gets a reference to the i-th element of this column vector without bound checking. #[inline] - pub unsafe fn vget_unchecked(&self, i: usize) -> &N { + pub unsafe fn vget_unchecked(&self, i: usize) -> &T { debug_assert!(i < self.nrows(), "Vector index out of bounds."); let i = i * self.strides().0; self.data.get_unchecked_linear(i) } } -impl> Vector { +impl> Vector { /// Gets a mutable reference to the i-th element of this column vector without bound checking. #[inline] - pub unsafe fn vget_unchecked_mut(&mut self, i: usize) -> &mut N { + pub unsafe fn vget_unchecked_mut(&mut self, i: usize) -> &mut T { debug_assert!(i < self.nrows(), "Vector index out of bounds."); let i = i * self.strides().0; self.data.get_unchecked_linear_mut(i) } } -impl> Matrix { +impl> Matrix { /// Extracts a slice containing the entire matrix entries ordered column-by-columns. #[inline] - pub fn as_slice(&self) -> &[N] { + pub fn as_slice(&self) -> &[T] { self.data.as_slice() } } -impl> Matrix { +impl> Matrix { /// Extracts a mutable slice containing the entire matrix entries ordered column-by-columns. #[inline] - pub fn as_mut_slice(&mut self) -> &mut [N] { + pub fn as_mut_slice(&mut self) -> &mut [T] { self.data.as_mut_slice() } } -impl> Matrix { +impl> Matrix { /// Transposes the square matrix `self` in-place. pub fn transpose_mut(&mut self) { assert!( @@ -1186,14 +1186,14 @@ impl> Matrix { } } -impl> Matrix { +impl> Matrix { /// Takes the adjoint (aka. conjugate-transpose) of `self` and store the result into `out`. #[inline] - pub fn adjoint_to(&self, out: &mut Matrix) + pub fn adjoint_to(&self, out: &mut Matrix) where R2: Dim, C2: Dim, - SB: StorageMut, + SB: StorageMut, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { let (nrows, ncols) = self.shape(); @@ -1215,14 +1215,14 @@ impl> Matrix MatrixMN + pub fn adjoint(&self) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let (nrows, ncols) = self.data.shape(); unsafe { - let mut res: MatrixMN<_, C, R> = + let mut res: OMatrix<_, C, R> = crate::unimplemented_or_uninitialized_generic!(ncols, nrows); self.adjoint_to(&mut res); @@ -1233,11 +1233,11 @@ impl> Matrix(&self, out: &mut Matrix) + pub fn conjugate_transpose_to(&self, out: &mut Matrix) where R2: Dim, C2: Dim, - SB: StorageMut, + SB: StorageMut, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { self.adjoint_to(out) @@ -1246,9 +1246,9 @@ impl> Matrix MatrixMN + pub fn conjugate_transpose(&self) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { self.adjoint() } @@ -1256,9 +1256,9 @@ impl> Matrix MatrixMN + pub fn conjugate(&self) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { self.map(|e| e.simd_conjugate()) } @@ -1266,9 +1266,9 @@ impl> Matrix MatrixMN + pub fn unscale(&self, real: T::SimdRealField) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { self.map(|e| e.simd_unscale(real)) } @@ -1276,15 +1276,15 @@ impl> Matrix MatrixMN + pub fn scale(&self, real: T::SimdRealField) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { self.map(|e| e.simd_scale(real)) } } -impl> Matrix { +impl> Matrix { /// The conjugate of the complex matrix `self` computed in-place. #[inline] pub fn conjugate_mut(&mut self) { @@ -1293,18 +1293,18 @@ impl> Matrix> Matrix { +impl> Matrix { /// Sets `self` to its adjoint. #[deprecated(note = "Renamed to `self.adjoint_mut()`.")] pub fn conjugate_transform_mut(&mut self) { @@ -1323,8 +1323,8 @@ impl> Matrix { for i in 0..dim { for j in 0..i { unsafe { - let ref_ij = self.get_unchecked_mut((i, j)) as *mut N; - let ref_ji = self.get_unchecked_mut((j, i)) as *mut N; + let ref_ij = self.get_unchecked_mut((i, j)) as *mut T; + let ref_ji = self.get_unchecked_mut((j, i)) as *mut T; let conj_ij = (*ref_ij).simd_conjugate(); let conj_ji = (*ref_ji).simd_conjugate(); *ref_ij = conj_ji; @@ -1340,12 +1340,12 @@ impl> Matrix { } } -impl> SquareMatrix { +impl> SquareMatrix { /// The diagonal of this matrix. #[inline] - pub fn diagonal(&self) -> VectorN + pub fn diagonal(&self) -> OVector where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { self.map_diagonal(|e| e) } @@ -1354,9 +1354,9 @@ impl> SquareMatrix { /// /// This is a more efficient version of `self.diagonal().map(f)` since this /// allocates only once. - pub fn map_diagonal(&self, mut f: impl FnMut(N) -> N2) -> VectorN + pub fn map_diagonal(&self, mut f: impl FnMut(T) -> T2) -> OVector where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { assert!( self.is_square(), @@ -1364,7 +1364,7 @@ impl> SquareMatrix { ); let dim = self.data.shape().0; - let mut res: VectorN = + let mut res: OVector = unsafe { crate::unimplemented_or_uninitialized_generic!(dim, Const::<1>) }; for i in 0..dim.value() { @@ -1378,9 +1378,9 @@ impl> SquareMatrix { /// Computes a trace of a square matrix, i.e., the sum of its diagonal elements. #[inline] - pub fn trace(&self) -> N + pub fn trace(&self) -> T where - N: Scalar + Zero + ClosedAdd, + T: Scalar + Zero + ClosedAdd, { assert!( self.is_square(), @@ -1388,7 +1388,7 @@ impl> SquareMatrix { ); let dim = self.data.shape().0; - let mut res = N::zero(); + let mut res = T::zero(); for i in 0..dim.value() { res += unsafe { self.get_unchecked((i, i)).inlined_clone() }; @@ -1398,12 +1398,12 @@ impl> SquareMatrix { } } -impl> SquareMatrix { +impl> SquareMatrix { /// The symmetric part of `self`, i.e., `0.5 * (self + self.transpose())`. #[inline] - pub fn symmetric_part(&self) -> MatrixMN + pub fn symmetric_part(&self) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { assert!( self.is_square(), @@ -1411,15 +1411,15 @@ impl> SquareMatrix { ); let mut tr = self.transpose(); tr += self; - tr *= crate::convert::<_, N>(0.5); + tr *= crate::convert::<_, T>(0.5); tr } /// The hermitian part of `self`, i.e., `0.5 * (self + self.adjoint())`. #[inline] - pub fn hermitian_part(&self) -> MatrixMN + pub fn hermitian_part(&self) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { assert!( self.is_square(), @@ -1428,51 +1428,51 @@ impl> SquareMatrix { let mut tr = self.adjoint(); tr += self; - tr *= crate::convert::<_, N>(0.5); + tr *= crate::convert::<_, T>(0.5); tr } } -impl + IsNotStaticOne, S: Storage> - Matrix +impl + IsNotStaticOne, S: Storage> + Matrix { /// Yields the homogeneous matrix for this matrix, i.e., appending an additional dimension and /// and setting the diagonal element to `1`. #[inline] - pub fn to_homogeneous(&self) -> MatrixN> + pub fn to_homogeneous(&self) -> OMatrix, DimSum> where - DefaultAllocator: Allocator, DimSum>, + DefaultAllocator: Allocator, DimSum>, { assert!( self.is_square(), "Only square matrices can currently be transformed to homogeneous coordinates." ); let dim = DimSum::::from_usize(self.nrows() + 1); - let mut res = MatrixN::identity_generic(dim, dim); + let mut res = OMatrix::identity_generic(dim, dim); res.generic_slice_mut::((0, 0), self.data.shape()) .copy_from(&self); res } } -impl, S: Storage> Vector { +impl, S: Storage> Vector { /// Computes the coordinates in projective space of this vector, i.e., appends a `0` to its /// coordinates. #[inline] - pub fn to_homogeneous(&self) -> VectorN> + pub fn to_homogeneous(&self) -> OVector> where - DefaultAllocator: Allocator>, + DefaultAllocator: Allocator>, { - self.push(N::zero()) + self.push(T::zero()) } /// Constructs a vector from coordinates in projective space, i.e., removes a `0` at the end of /// `self`. Returns `None` if this last component is not zero. #[inline] - pub fn from_homogeneous(v: Vector, SB>) -> Option> + pub fn from_homogeneous(v: Vector, SB>) -> Option> where - SB: Storage>, - DefaultAllocator: Allocator, + SB: Storage>, + DefaultAllocator: Allocator, { if v[v.len() - 1].is_zero() { let nrows = D::from_usize(v.len() - 1); @@ -1483,16 +1483,16 @@ impl, S: Storage> Vector { } } -impl, S: Storage> Vector { +impl, S: Storage> Vector { /// Constructs a new vector of higher dimension by appending `element` to the end of `self`. #[inline] - pub fn push(&self, element: N) -> VectorN> + pub fn push(&self, element: T) -> OVector> where - DefaultAllocator: Allocator>, + DefaultAllocator: Allocator>, { let len = self.len(); let hnrows = DimSum::::from_usize(len + 1); - let mut res: VectorN = + let mut res: OVector = unsafe { crate::unimplemented_or_uninitialized_generic!(hnrows, Const::<1>) }; res.generic_slice_mut((0, 0), self.data.shape()) .copy_from(self); @@ -1502,17 +1502,17 @@ impl, S: Storage> Vector { } } -impl AbsDiffEq for Matrix +impl AbsDiffEq for Matrix where - N: Scalar + AbsDiffEq, - S: Storage, - N::Epsilon: Copy, + T: Scalar + AbsDiffEq, + S: Storage, + T::Epsilon: Copy, { - type Epsilon = N::Epsilon; + type Epsilon = T::Epsilon; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -1523,15 +1523,15 @@ where } } -impl RelativeEq for Matrix +impl RelativeEq for Matrix where - N: Scalar + RelativeEq, - S: Storage, - N::Epsilon: Copy, + T: Scalar + RelativeEq, + S: Storage, + T::Epsilon: Copy, { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -1545,15 +1545,15 @@ where } } -impl UlpsEq for Matrix +impl UlpsEq for Matrix where - N: Scalar + UlpsEq, - S: Storage, - N::Epsilon: Copy, + T: Scalar + UlpsEq, + S: Storage, + T::Epsilon: Copy, { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] @@ -1565,10 +1565,10 @@ where } } -impl PartialOrd for Matrix +impl PartialOrd for Matrix where - N: Scalar + PartialOrd, - S: Storage, + T: Scalar + PartialOrd, + S: Storage, { #[inline] fn partial_cmp(&self, other: &Self) -> Option { @@ -1657,40 +1657,40 @@ where } } -impl Eq for Matrix +impl Eq for Matrix where - N: Scalar + Eq, - S: Storage, + T: Scalar + Eq, + S: Storage, { } -impl PartialEq> for Matrix +impl PartialEq> for Matrix where - N: Scalar + PartialEq, + T: Scalar + PartialEq, C: Dim, C2: Dim, R: Dim, R2: Dim, - S: Storage, - S2: Storage, + S: Storage, + S2: Storage, { #[inline] - fn eq(&self, right: &Matrix) -> bool { + fn eq(&self, right: &Matrix) -> bool { self.shape() == right.shape() && self.iter().zip(right.iter()).all(|(l, r)| l == r) } } macro_rules! impl_fmt { ($trait: path, $fmt_str_without_precision: expr, $fmt_str_with_precision: expr) => { - impl $trait for Matrix + impl $trait for Matrix where - N: Scalar + $trait, - S: Storage, + T: Scalar + $trait, + S: Storage, DefaultAllocator: Allocator, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { #[cfg(feature = "std")] - fn val_width(val: &N, f: &mut fmt::Formatter) -> usize { + fn val_width(val: &T, f: &mut fmt::Formatter) -> usize { match f.precision() { Some(precision) => format!($fmt_str_with_precision, val, precision) .chars() @@ -1700,7 +1700,7 @@ macro_rules! impl_fmt { } #[cfg(not(feature = "std"))] - fn val_width(_: &N, _: &mut fmt::Formatter) -> usize { + fn val_width(_: &T, _: &mut fmt::Formatter) -> usize { 4 } @@ -1711,7 +1711,7 @@ macro_rules! impl_fmt { } let mut max_length = 0; - let mut lengths: MatrixMN = Matrix::zeros_generic(nrows, ncols); + let mut lengths: OMatrix = Matrix::zeros_generic(nrows, ncols); let (nrows, ncols) = self.shape(); for i in 0..nrows { @@ -1783,16 +1783,16 @@ fn lower_exp() { } /// # Cross product -impl> - Matrix +impl> + Matrix { /// The perpendicular product between two 2D column vectors, i.e. `a.x * b.y - a.y * b.x`. #[inline] - pub fn perp(&self, b: &Matrix) -> N + pub fn perp(&self, b: &Matrix) -> T where R2: Dim, C2: Dim, - SB: Storage, + SB: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns + SameNumberOfRows @@ -1817,12 +1817,12 @@ impl(&self, b: &Matrix) -> MatrixCross + pub fn cross(&self, b: &Matrix) -> MatrixCross where R2: Dim, C2: Dim, - SB: Storage, - DefaultAllocator: SameShapeAllocator, + SB: Storage, + DefaultAllocator: SameShapeAllocator, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { let shape = self.shape(); @@ -1838,7 +1838,7 @@ impl::from_usize(3); let ncols = SameShapeC::::from_usize(1); - let mut res: MatrixCross = + let mut res: MatrixCross = crate::unimplemented_or_uninitialized_generic!(nrows, ncols); let ax = self.get_unchecked((0, 0)); @@ -1863,7 +1863,7 @@ impl::from_usize(1); let ncols = SameShapeC::::from_usize(3); - let mut res: MatrixCross = + let mut res: MatrixCross = crate::unimplemented_or_uninitialized_generic!(nrows, ncols); let ax = self.get_unchecked((0, 0)); @@ -1887,33 +1887,30 @@ impl> Vector -where - DefaultAllocator: Allocator, -{ +impl> Vector { /// Computes the matrix `M` such that for all vector `v` we have `M * v == self.cross(&v)`. #[inline] - pub fn cross_matrix(&self) -> MatrixN { - MatrixN::::new( - N::zero(), + pub fn cross_matrix(&self) -> OMatrix { + OMatrix::::new( + T::zero(), -self[2].inlined_clone(), self[1].inlined_clone(), self[2].inlined_clone(), - N::zero(), + T::zero(), -self[0].inlined_clone(), -self[1].inlined_clone(), self[0].inlined_clone(), - N::zero(), + T::zero(), ) } } -impl> Matrix { +impl> Matrix { /// The smallest angle between two vectors. #[inline] - pub fn angle(&self, other: &Matrix) -> N::SimdRealField + pub fn angle(&self, other: &Matrix) -> T::SimdRealField where - SB: Storage, + SB: Storage, ShapeConstraint: DimEq + DimEq, { let prod = self.dotc(other); @@ -1921,26 +1918,26 @@ impl> Matrix AbsDiffEq for Unit> +impl AbsDiffEq for Unit> where - N: Scalar + AbsDiffEq, - S: Storage, - N::Epsilon: Copy, + T: Scalar + AbsDiffEq, + S: Storage, + T::Epsilon: Copy, { - type Epsilon = N::Epsilon; + type Epsilon = T::Epsilon; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -1949,15 +1946,15 @@ where } } -impl RelativeEq for Unit> +impl RelativeEq for Unit> where - N: Scalar + RelativeEq, - S: Storage, - N::Epsilon: Copy, + T: Scalar + RelativeEq, + S: Storage, + T::Epsilon: Copy, { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -1972,15 +1969,15 @@ where } } -impl UlpsEq for Unit> +impl UlpsEq for Unit> where - N: Scalar + UlpsEq, - S: Storage, - N::Epsilon: Copy, + T: Scalar + UlpsEq, + S: Storage, + T::Epsilon: Copy, { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] @@ -1989,12 +1986,12 @@ where } } -impl Hash for Matrix +impl Hash for Matrix where - N: Scalar + Hash, + T: Scalar + Hash, R: Dim, C: Dim, - S: Storage, + S: Storage, { fn hash(&self, state: &mut H) { let (nrows, ncols) = self.shape(); diff --git a/src/base/matrix_simba.rs b/src/base/matrix_simba.rs index 09bc937f..e0333f45 100644 --- a/src/base/matrix_simba.rs +++ b/src/base/matrix_simba.rs @@ -2,32 +2,32 @@ use simba::simd::SimdValue; use crate::base::allocator::Allocator; use crate::base::dimension::Dim; -use crate::base::{DefaultAllocator, MatrixMN, Scalar}; +use crate::base::{DefaultAllocator, OMatrix, Scalar}; /* * * Simd structures. * */ -impl SimdValue for MatrixMN +impl SimdValue for OMatrix where - N: Scalar + SimdValue, + T: Scalar + SimdValue, R: Dim, C: Dim, - N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + T::Element: Scalar, + DefaultAllocator: Allocator + Allocator, { - type Element = MatrixMN; - type SimdBool = N::SimdBool; + type Element = OMatrix; + type SimdBool = T::SimdBool; #[inline] fn lanes() -> usize { - N::lanes() + T::lanes() } #[inline] fn splat(val: Self::Element) -> Self { - val.map(N::splat) + val.map(T::splat) } #[inline] diff --git a/src/base/matrix_slice.rs b/src/base/matrix_slice.rs index cda4282b..6b03c7b2 100644 --- a/src/base/matrix_slice.rs +++ b/src/base/matrix_slice.rs @@ -13,22 +13,22 @@ macro_rules! slice_storage_impl( ($doc: expr; $Storage: ident as $SRef: ty; $T: ident.$get_addr: ident ($Ptr: ty as $Ref: ty)) => { #[doc = $doc] #[derive(Debug)] - pub struct $T<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> { + pub struct $T<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> { ptr: $Ptr, shape: (R, C), strides: (RStride, CStride), _phantoms: PhantomData<$Ref>, } - unsafe impl<'a, N: Scalar + Send, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Send - for $T<'a, N, R, C, RStride, CStride> + unsafe impl<'a, T: Scalar + Send, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Send + for $T<'a, T, R, C, RStride, CStride> {} - unsafe impl<'a, N: Scalar + Sync, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Sync - for $T<'a, N, R, C, RStride, CStride> + unsafe impl<'a, T: Scalar + Sync, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Sync + for $T<'a, T, R, C, RStride, CStride> {} - impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> $T<'a, N, R, C, RStride, CStride> { + impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> $T<'a, T, R, C, RStride, CStride> { /// Create a new matrix slice without bound checking and from a raw pointer. #[inline] pub unsafe fn from_raw_parts(ptr: $Ptr, @@ -48,14 +48,14 @@ macro_rules! slice_storage_impl( } // Dynamic is arbitrary. It's just to be able to call the constructors with `Slice::` - impl<'a, N: Scalar, R: Dim, C: Dim> $T<'a, N, R, C, Dynamic, Dynamic> { + impl<'a, T: Scalar, R: Dim, C: Dim> $T<'a, T, R, C, Dynamic, Dynamic> { /// Create a new matrix slice without bound checking. #[inline] pub unsafe fn new_unchecked(storage: $SRef, start: (usize, usize), shape: (R, C)) - -> $T<'a, N, R, C, S::RStride, S::CStride> + -> $T<'a, T, R, C, S::RStride, S::CStride> where RStor: Dim, CStor: Dim, - S: $Storage { + S: $Storage { let strides = storage.strides(); $T::new_with_strides_unchecked(storage, start, shape, strides) @@ -67,10 +67,10 @@ macro_rules! slice_storage_impl( start: (usize, usize), shape: (R, C), strides: (RStride, CStride)) - -> $T<'a, N, R, C, RStride, CStride> + -> $T<'a, T, R, C, RStride, CStride> where RStor: Dim, CStor: Dim, - S: $Storage, + S: $Storage, RStride: Dim, CStride: Dim { @@ -82,20 +82,20 @@ macro_rules! slice_storage_impl( slice_storage_impl!("A matrix data storage for a matrix slice. Only contains an internal reference \ to another matrix data storage."; - Storage as &'a S; SliceStorage.get_address_unchecked(*const N as &'a N)); + Storage as &'a S; SliceStorage.get_address_unchecked(*const T as &'a T)); slice_storage_impl!("A mutable matrix data storage for mutable matrix slice. Only contains an \ internal mutable reference to another matrix data storage."; - StorageMut as &'a mut S; SliceStorageMut.get_address_unchecked_mut(*mut N as &'a mut N) + StorageMut as &'a mut S; SliceStorageMut.get_address_unchecked_mut(*mut T as &'a mut T) ); -impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Copy - for SliceStorage<'a, N, R, C, RStride, CStride> +impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Copy + for SliceStorage<'a, T, 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> +impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Clone + for SliceStorage<'a, T, R, C, RStride, CStride> { #[inline] fn clone(&self) -> Self { @@ -110,14 +110,14 @@ impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Clone macro_rules! storage_impl( ($($T: ident),* $(,)*) => {$( - unsafe impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Storage - for $T<'a, N, R, C, RStride, CStride> { + unsafe impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> Storage + for $T<'a, T, R, C, RStride, CStride> { type RStride = RStride; type CStride = CStride; #[inline] - fn ptr(&self) -> *const N { + fn ptr(&self) -> *const T { self.ptr } @@ -148,21 +148,21 @@ macro_rules! storage_impl( } #[inline] - fn into_owned(self) -> Owned - where DefaultAllocator: Allocator { + fn into_owned(self) -> Owned + where DefaultAllocator: Allocator { self.clone_owned() } #[inline] - fn clone_owned(&self) -> Owned - where DefaultAllocator: Allocator { + fn clone_owned(&self) -> Owned + where DefaultAllocator: Allocator { let (nrows, ncols) = self.shape(); let it = MatrixIter::new(self).cloned(); DefaultAllocator::allocate_from_iterator(nrows, ncols, it) } #[inline] - fn as_slice(&self) -> &[N] { + fn as_slice(&self) -> &[T] { let (nrows, ncols) = self.shape(); if nrows.value() != 0 && ncols.value() != 0 { let sz = self.linear_index(nrows.value() - 1, ncols.value() - 1); @@ -178,16 +178,16 @@ macro_rules! storage_impl( storage_impl!(SliceStorage, SliceStorageMut); -unsafe impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> StorageMut - for SliceStorageMut<'a, N, R, C, RStride, CStride> +unsafe impl<'a, T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> StorageMut + for SliceStorageMut<'a, T, R, C, RStride, CStride> { #[inline] - fn ptr_mut(&mut self) -> *mut N { + fn ptr_mut(&mut self) -> *mut T { self.ptr } #[inline] - fn as_mut_slice(&mut self) -> &mut [N] { + fn as_mut_slice(&mut self) -> &mut [T] { let (nrows, ncols) = self.shape(); if nrows.value() != 0 && ncols.value() != 0 { let sz = self.linear_index(nrows.value() - 1, ncols.value() - 1); @@ -198,33 +198,33 @@ unsafe impl<'a, N: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim> StorageMu } } -unsafe impl<'a, N: Scalar, R: Dim, CStride: Dim> ContiguousStorage - for SliceStorage<'a, N, R, U1, U1, CStride> +unsafe impl<'a, T: Scalar, R: Dim, CStride: Dim> ContiguousStorage + for SliceStorage<'a, T, R, U1, U1, CStride> { } -unsafe impl<'a, N: Scalar, R: Dim, CStride: Dim> ContiguousStorage - for SliceStorageMut<'a, N, R, U1, U1, CStride> +unsafe impl<'a, T: Scalar, R: Dim, CStride: Dim> ContiguousStorage + for SliceStorageMut<'a, T, R, U1, U1, CStride> { } -unsafe impl<'a, N: Scalar, R: Dim, CStride: Dim> ContiguousStorageMut - for SliceStorageMut<'a, N, R, U1, U1, CStride> +unsafe impl<'a, T: Scalar, R: Dim, CStride: Dim> ContiguousStorageMut + for SliceStorageMut<'a, T, R, U1, U1, CStride> { } -unsafe impl<'a, N: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage - for SliceStorage<'a, N, R, C, U1, R> +unsafe impl<'a, T: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage + for SliceStorage<'a, T, R, C, U1, R> { } -unsafe impl<'a, N: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage - for SliceStorageMut<'a, N, R, C, U1, R> +unsafe impl<'a, T: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorage + for SliceStorageMut<'a, T, R, C, U1, R> { } -unsafe impl<'a, N: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorageMut - for SliceStorageMut<'a, N, R, C, U1, R> +unsafe impl<'a, T: Scalar, R: DimName, C: Dim + IsNotStaticOne> ContiguousStorageMut + for SliceStorageMut<'a, T, R, C, U1, R> { } -impl> Matrix { +impl> Matrix { #[inline] fn assert_slice_index( &self, @@ -281,20 +281,20 @@ macro_rules! matrix_slice_impl( */ /// Returns a slice containing the i-th row of this matrix. #[inline] - pub fn $row($me: $Me, i: usize) -> $MatrixSlice { - $me.$fixed_rows::(i) + pub fn $row($me: $Me, i: usize) -> $MatrixSlice { + $me.$fixed_rows::<1>(i) } /// Returns a slice containing the `n` first elements of the i-th row of this matrix. #[inline] - pub fn $row_part($me: $Me, i: usize, n: usize) -> $MatrixSlice { + pub fn $row_part($me: $Me, i: usize, n: usize) -> $MatrixSlice { $me.$generic_slice((i, 0), (Const::<1>, Dynamic::new(n))) } /// Extracts from this matrix a set of consecutive rows. #[inline] pub fn $rows($me: $Me, first_row: usize, nrows: usize) - -> $MatrixSlice { + -> $MatrixSlice { $me.$rows_generic(first_row, Dynamic::new(nrows)) } @@ -302,33 +302,33 @@ macro_rules! matrix_slice_impl( /// Extracts from this matrix a set of consecutive rows regularly skipping `step` rows. #[inline] pub fn $rows_with_step($me: $Me, first_row: usize, nrows: usize, step: usize) - -> $MatrixSlice { + -> $MatrixSlice { $me.$rows_generic_with_step(first_row, Dynamic::new(nrows), step) } /// Extracts a compile-time number of consecutive rows from this matrix. #[inline] - pub fn $fixed_rows($me: $Me, first_row: usize) - -> $MatrixSlice { + pub fn $fixed_rows($me: $Me, first_row: usize) + -> $MatrixSlice, C, S::RStride, S::CStride> { - $me.$rows_generic(first_row, RSlice::name()) + $me.$rows_generic(first_row, Const::) } /// Extracts from this matrix a compile-time number of rows regularly skipping `step` /// rows. #[inline] - pub fn $fixed_rows_with_step($me: $Me, first_row: usize, step: usize) - -> $MatrixSlice { + pub fn $fixed_rows_with_step($me: $Me, first_row: usize, step: usize) + -> $MatrixSlice, C, Dynamic, S::CStride> { - $me.$rows_generic_with_step(first_row, RSlice::name(), step) + $me.$rows_generic_with_step(first_row, Const::, step) } /// Extracts from this matrix `nrows` rows regularly skipping `step` rows. Both /// argument may or may not be values known at compile-time. #[inline] pub fn $rows_generic($me: $Me, row_start: usize, nrows: RSlice) - -> $MatrixSlice { + -> $MatrixSlice { let my_shape = $me.data.shape(); $me.assert_slice_index((row_start, 0), (nrows.value(), my_shape.1.value()), (0, 0)); @@ -345,7 +345,7 @@ macro_rules! matrix_slice_impl( /// argument may or may not be values known at compile-time. #[inline] pub fn $rows_generic_with_step($me: $Me, row_start: usize, nrows: RSlice, step: usize) - -> $MatrixSlice + -> $MatrixSlice where RSlice: Dim { let my_shape = $me.data.shape(); @@ -368,20 +368,20 @@ macro_rules! matrix_slice_impl( */ /// Returns a slice containing the i-th column of this matrix. #[inline] - pub fn $column($me: $Me, i: usize) -> $MatrixSlice { - $me.$fixed_columns::(i) + pub fn $column($me: $Me, i: usize) -> $MatrixSlice { + $me.$fixed_columns::<1>(i) } /// Returns a slice containing the `n` first elements of the i-th column of this matrix. #[inline] - pub fn $column_part($me: $Me, i: usize, n: usize) -> $MatrixSlice { + pub fn $column_part($me: $Me, i: usize, n: usize) -> $MatrixSlice { $me.$generic_slice((0, i), (Dynamic::new(n), Const::<1>)) } /// Extracts from this matrix a set of consecutive columns. #[inline] pub fn $columns($me: $Me, first_col: usize, ncols: usize) - -> $MatrixSlice { + -> $MatrixSlice { $me.$columns_generic(first_col, Dynamic::new(ncols)) } @@ -390,33 +390,33 @@ macro_rules! matrix_slice_impl( /// columns. #[inline] pub fn $columns_with_step($me: $Me, first_col: usize, ncols: usize, step: usize) - -> $MatrixSlice { + -> $MatrixSlice { $me.$columns_generic_with_step(first_col, Dynamic::new(ncols), step) } /// Extracts a compile-time number of consecutive columns from this matrix. #[inline] - pub fn $fixed_columns($me: $Me, first_col: usize) - -> $MatrixSlice { + pub fn $fixed_columns($me: $Me, first_col: usize) + -> $MatrixSlice, S::RStride, S::CStride> { - $me.$columns_generic(first_col, CSlice::name()) + $me.$columns_generic(first_col, Const::) } /// Extracts from this matrix a compile-time number of columns regularly skipping /// `step` columns. #[inline] - pub fn $fixed_columns_with_step($me: $Me, first_col: usize, step: usize) - -> $MatrixSlice { + pub fn $fixed_columns_with_step($me: $Me, first_col: usize, step: usize) + -> $MatrixSlice, S::RStride, Dynamic> { - $me.$columns_generic_with_step(first_col, CSlice::name(), step) + $me.$columns_generic_with_step(first_col, Const::, step) } /// Extracts from this matrix `ncols` columns. The number of columns may or may not be /// known at compile-time. #[inline] pub fn $columns_generic($me: $Me, first_col: usize, ncols: CSlice) - -> $MatrixSlice { + -> $MatrixSlice { let my_shape = $me.data.shape(); $me.assert_slice_index((0, first_col), (my_shape.0.value(), ncols.value()), (0, 0)); @@ -433,7 +433,7 @@ macro_rules! matrix_slice_impl( /// or may not be values known at compile-time. #[inline] pub fn $columns_generic_with_step($me: $Me, first_col: usize, ncols: CSlice, step: usize) - -> $MatrixSlice { + -> $MatrixSlice { let my_shape = $me.data.shape(); let my_strides = $me.data.strides(); @@ -458,7 +458,7 @@ macro_rules! matrix_slice_impl( /// consecutive elements. #[inline] pub fn $slice($me: $Me, start: (usize, usize), shape: (usize, usize)) - -> $MatrixSlice { + -> $MatrixSlice { $me.assert_slice_index(start, shape, (0, 0)); let shape = (Dynamic::new(shape.0), Dynamic::new(shape.1)); @@ -476,7 +476,7 @@ macro_rules! matrix_slice_impl( /// original matrix. #[inline] pub fn $slice_with_steps($me: $Me, start: (usize, usize), shape: (usize, usize), steps: (usize, usize)) - -> $MatrixSlice { + -> $MatrixSlice { let shape = (Dynamic::new(shape.0), Dynamic::new(shape.1)); $me.$generic_slice_with_steps(start, shape, steps) @@ -485,13 +485,11 @@ macro_rules! matrix_slice_impl( /// Slices this matrix starting at its component `(irow, icol)` and with `(R::dim(), /// CSlice::dim())` consecutive components. #[inline] - pub fn $fixed_slice($me: $Me, irow: usize, icol: usize) - -> $MatrixSlice - where RSlice: DimName, - CSlice: DimName { + pub fn $fixed_slice($me: $Me, irow: usize, icol: usize) + -> $MatrixSlice, Const, S::RStride, S::CStride> { - $me.assert_slice_index((irow, icol), (RSlice::dim(), CSlice::dim()), (0, 0)); - let shape = (RSlice::name(), CSlice::name()); + $me.assert_slice_index((irow, icol), (RSLICE, CSLICE), (0, 0)); + let shape = (Const::, Const::); unsafe { let data = $SliceStorage::new_unchecked($data, (irow, icol), shape); @@ -500,22 +498,20 @@ macro_rules! matrix_slice_impl( } /// Slices this matrix starting at its component `(start.0, start.1)` and with - /// `(R::dim(), CSlice::dim())` components. Each row (resp. column) of the sliced + /// `(RSLICE, CSLICE)` components. Each row (resp. column) of the sliced /// matrix is separated by `steps.0` (resp. `steps.1`) ignored rows (resp. columns) of /// the original matrix. #[inline] - pub fn $fixed_slice_with_steps($me: $Me, start: (usize, usize), steps: (usize, usize)) - -> $MatrixSlice - where RSlice: DimName, - CSlice: DimName { - let shape = (RSlice::name(), CSlice::name()); + pub fn $fixed_slice_with_steps($me: $Me, start: (usize, usize), steps: (usize, usize)) + -> $MatrixSlice, Const, Dynamic, Dynamic> { + let shape = (Const::, Const::); $me.$generic_slice_with_steps(start, shape, steps) } /// Creates a slice that may or may not have a fixed size and stride. #[inline] pub fn $generic_slice($me: $Me, start: (usize, usize), shape: (RSlice, CSlice)) - -> $MatrixSlice + -> $MatrixSlice where RSlice: Dim, CSlice: Dim { @@ -533,7 +529,7 @@ macro_rules! matrix_slice_impl( start: (usize, usize), shape: (RSlice, CSlice), steps: (usize, usize)) - -> $MatrixSlice + -> $MatrixSlice where RSlice: Dim, CSlice: Dim { @@ -559,8 +555,8 @@ macro_rules! matrix_slice_impl( /// Panics if the ranges overlap or if the first range is empty. #[inline] pub fn $rows_range_pair, Range2: SliceRange>($me: $Me, r1: Range1, r2: Range2) - -> ($MatrixSlice, - $MatrixSlice) { + -> ($MatrixSlice, + $MatrixSlice) { let (nrows, ncols) = $me.data.shape(); let strides = $me.data.strides(); @@ -595,8 +591,8 @@ macro_rules! matrix_slice_impl( /// Panics if the ranges overlap or if the first range is empty. #[inline] pub fn $columns_range_pair, Range2: SliceRange>($me: $Me, r1: Range1, r2: Range2) - -> ($MatrixSlice, - $MatrixSlice) { + -> ($MatrixSlice, + $MatrixSlice) { let (nrows, ncols) = $me.data.shape(); let strides = $me.data.strides(); @@ -629,14 +625,14 @@ macro_rules! matrix_slice_impl( ); /// A matrix slice. -pub type MatrixSlice<'a, N, R, C, RStride, CStride> = - Matrix>; +pub type MatrixSlice<'a, T, R, C, RStride = U1, CStride = R> = + Matrix>; /// A mutable matrix slice. -pub type MatrixSliceMut<'a, N, R, C, RStride, CStride> = - Matrix>; +pub type MatrixSliceMut<'a, T, R, C, RStride = U1, CStride = R> = + Matrix>; /// # Slicing based on index and length -impl> Matrix { +impl> Matrix { matrix_slice_impl!( self: &Self, MatrixSlice, SliceStorage, Storage.get_address_unchecked(), &self.data; row, @@ -666,7 +662,7 @@ impl> Matrix { } /// # Mutable slicing based on index and length -impl> Matrix { +impl> Matrix { matrix_slice_impl!( self: &mut Self, MatrixSliceMut, SliceStorageMut, StorageMut.get_address_unchecked_mut(), &mut self.data; row_mut, @@ -812,7 +808,7 @@ impl SliceRange for RangeFull { // TODO: see how much of this overlaps with the general indexing // methods from indexing.rs. -impl> Matrix { +impl> Matrix { /// Slices a sub-matrix containing the rows indexed by the range `rows` and the columns indexed /// by the range `cols`. #[inline] @@ -820,7 +816,7 @@ impl> Matrix { &self, rows: RowRange, cols: ColRange, - ) -> MatrixSlice + ) -> MatrixSlice where RowRange: SliceRange, ColRange: SliceRange, @@ -837,7 +833,7 @@ impl> Matrix { pub fn rows_range>( &self, rows: RowRange, - ) -> MatrixSlice { + ) -> MatrixSlice { self.slice_range(rows, ..) } @@ -846,21 +842,21 @@ impl> Matrix { pub fn columns_range>( &self, cols: ColRange, - ) -> MatrixSlice { + ) -> MatrixSlice { self.slice_range(.., cols) } } // TODO: see how much of this overlaps with the general indexing // methods from indexing.rs. -impl> Matrix { +impl> Matrix { /// Slices a mutable sub-matrix containing the rows indexed by the range `rows` and the columns /// indexed by the range `cols`. pub fn slice_range_mut( &mut self, rows: RowRange, cols: ColRange, - ) -> MatrixSliceMut + ) -> MatrixSliceMut where RowRange: SliceRange, ColRange: SliceRange, @@ -877,7 +873,7 @@ impl> Matrix { pub fn rows_range_mut>( &mut self, rows: RowRange, - ) -> MatrixSliceMut { + ) -> MatrixSliceMut { self.slice_range_mut(rows, ..) } @@ -886,21 +882,21 @@ impl> Matrix { pub fn columns_range_mut>( &mut self, cols: ColRange, - ) -> MatrixSliceMut { + ) -> MatrixSliceMut { self.slice_range_mut(.., cols) } } -impl<'a, N, R, C, RStride, CStride> From> - for MatrixSlice<'a, N, R, C, RStride, CStride> +impl<'a, T, R, C, RStride, CStride> From> + for MatrixSlice<'a, T, R, C, RStride, CStride> where - N: Scalar, + T: Scalar, R: Dim, C: Dim, RStride: Dim, CStride: Dim, { - fn from(slice_mut: MatrixSliceMut<'a, N, R, C, RStride, CStride>) -> Self { + fn from(slice_mut: MatrixSliceMut<'a, T, R, C, RStride, CStride>) -> Self { let data = SliceStorage { ptr: slice_mut.data.ptr, shape: slice_mut.data.shape, diff --git a/src/base/min_max.rs b/src/base/min_max.rs index 0bddd4b0..d532d87a 100644 --- a/src/base/min_max.rs +++ b/src/base/min_max.rs @@ -4,7 +4,7 @@ use num::{Signed, Zero}; use simba::simd::SimdSigned; /// # Find the min and max components -impl> Matrix { +impl> Matrix { /// Returns the absolute value of the component with the largest absolute value. /// # Example /// ``` @@ -13,12 +13,12 @@ impl> Matrix { /// assert_eq!(Vector3::new(-1.0, -2.0, -3.0).amax(), 3.0); /// ``` #[inline] - pub fn amax(&self) -> N + pub fn amax(&self) -> T where - N: Zero + SimdSigned + SimdPartialOrd, + T: Zero + SimdSigned + SimdPartialOrd, { self.fold_with( - |e| e.unwrap_or(&N::zero()).simd_abs(), + |e| e.unwrap_or(&T::zero()).simd_abs(), |a, b| a.simd_max(b.simd_abs()), ) } @@ -33,12 +33,12 @@ impl> Matrix { /// Complex::new(1.0, 3.0)).camax(), 5.0); /// ``` #[inline] - pub fn camax(&self) -> N::SimdRealField + pub fn camax(&self) -> T::SimdRealField where - N: SimdComplexField, + T: SimdComplexField, { self.fold_with( - |e| e.unwrap_or(&N::zero()).simd_norm1(), + |e| e.unwrap_or(&T::zero()).simd_norm1(), |a, b| a.simd_max(b.simd_norm1()), ) } @@ -52,12 +52,12 @@ impl> Matrix { /// assert_eq!(Vector3::new(5u32, 2, 3).max(), 5); /// ``` #[inline] - pub fn max(&self) -> N + pub fn max(&self) -> T where - N: SimdPartialOrd + Zero, + T: SimdPartialOrd + Zero, { self.fold_with( - |e| e.map(|e| e.inlined_clone()).unwrap_or_else(N::zero), + |e| e.map(|e| e.inlined_clone()).unwrap_or_else(T::zero), |a, b| a.simd_max(b.inlined_clone()), ) } @@ -70,12 +70,12 @@ impl> Matrix { /// assert_eq!(Vector3::new(10.0, 2.0, 30.0).amin(), 2.0); /// ``` #[inline] - pub fn amin(&self) -> N + pub fn amin(&self) -> T where - N: Zero + SimdPartialOrd + SimdSigned, + T: Zero + SimdPartialOrd + SimdSigned, { self.fold_with( - |e| e.map(|e| e.simd_abs()).unwrap_or_else(N::zero), + |e| e.map(|e| e.simd_abs()).unwrap_or_else(T::zero), |a, b| a.simd_min(b.simd_abs()), ) } @@ -90,14 +90,14 @@ impl> Matrix { /// Complex::new(1.0, 3.0)).camin(), 3.0); /// ``` #[inline] - pub fn camin(&self) -> N::SimdRealField + pub fn camin(&self) -> T::SimdRealField where - N: SimdComplexField, + T: SimdComplexField, { self.fold_with( |e| { e.map(|e| e.simd_norm1()) - .unwrap_or_else(N::SimdRealField::zero) + .unwrap_or_else(T::SimdRealField::zero) }, |a, b| a.simd_min(b.simd_norm1()), ) @@ -112,12 +112,12 @@ impl> Matrix { /// assert_eq!(Vector3::new(5u32, 2, 3).min(), 2); /// ``` #[inline] - pub fn min(&self) -> N + pub fn min(&self) -> T where - N: SimdPartialOrd + Zero, + T: SimdPartialOrd + Zero, { self.fold_with( - |e| e.map(|e| e.inlined_clone()).unwrap_or_else(N::zero), + |e| e.map(|e| e.inlined_clone()).unwrap_or_else(T::zero), |a, b| a.simd_min(b.inlined_clone()), ) } @@ -138,7 +138,7 @@ impl> Matrix { #[inline] pub fn icamax_full(&self) -> (usize, usize) where - N: ComplexField, + T: ComplexField, { assert!(!self.is_empty(), "The input matrix must not be empty."); @@ -160,7 +160,7 @@ impl> Matrix { } } -impl> Matrix { +impl> Matrix { /// Computes the index of the matrix component with the largest absolute value. /// /// # Examples: @@ -195,7 +195,7 @@ impl> Matri // TODO: find a way to avoid code duplication just for complex number support. /// # Find the min and max components (vector-specific methods) -impl> Vector { +impl> Vector { /// Computes the index of the vector component with the largest complex or real absolute value. /// /// # Examples: @@ -211,7 +211,7 @@ impl> Vector { #[inline] pub fn icamax(&self) -> usize where - N: ComplexField, + T: ComplexField, { assert!(!self.is_empty(), "The input vector must not be empty."); @@ -240,9 +240,9 @@ impl> Vector { /// assert_eq!(vec.argmax(), (2, 13)); /// ``` #[inline] - pub fn argmax(&self) -> (usize, N) + pub fn argmax(&self) -> (usize, T) where - N: PartialOrd, + T: PartialOrd, { assert!(!self.is_empty(), "The input vector must not be empty."); @@ -273,7 +273,7 @@ impl> Vector { #[inline] pub fn imax(&self) -> usize where - N: PartialOrd, + T: PartialOrd, { self.argmax().0 } @@ -290,7 +290,7 @@ impl> Vector { #[inline] pub fn iamax(&self) -> usize where - N: PartialOrd + Signed, + T: PartialOrd + Signed, { assert!(!self.is_empty(), "The input vector must not be empty."); @@ -319,9 +319,9 @@ impl> Vector { /// assert_eq!(vec.argmin(), (1, -15)); /// ``` #[inline] - pub fn argmin(&self) -> (usize, N) + pub fn argmin(&self) -> (usize, T) where - N: PartialOrd, + T: PartialOrd, { assert!(!self.is_empty(), "The input vector must not be empty."); @@ -352,7 +352,7 @@ impl> Vector { #[inline] pub fn imin(&self) -> usize where - N: PartialOrd, + T: PartialOrd, { self.argmin().0 } @@ -369,7 +369,7 @@ impl> Vector { #[inline] pub fn iamin(&self) -> usize where - N: PartialOrd + Signed, + T: PartialOrd + Signed, { assert!(!self.is_empty(), "The input vector must not be empty."); diff --git a/src/base/norm.rs b/src/base/norm.rs index 3f0508f2..251bf661 100644 --- a/src/base/norm.rs +++ b/src/base/norm.rs @@ -5,7 +5,7 @@ use num::Zero; use std::ops::Neg; use crate::allocator::Allocator; -use crate::base::{DefaultAllocator, Dim, DimName, Matrix, MatrixMN, Normed, VectorN}; +use crate::base::{DefaultAllocator, Dim, DimName, Matrix, Normed, OMatrix, OVector}; use crate::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; use crate::storage::{Storage, StorageMut}; use crate::{ComplexField, Scalar, SimdComplexField, Unit}; @@ -16,26 +16,26 @@ use simba::simd::{SimdOption, SimdPartialOrd, SimdValue}; /// A trait for abstract matrix norms. /// /// This may be moved to the alga crate in the future. -pub trait Norm { +pub trait Norm { /// Apply this norm to the given matrix. - fn norm(&self, m: &Matrix) -> N::SimdRealField + fn norm(&self, m: &Matrix) -> T::SimdRealField where R: Dim, C: Dim, - S: Storage; + S: Storage; /// Use the metric induced by this norm to compute the metric distance between the two given matrices. fn metric_distance( &self, - m1: &Matrix, - m2: &Matrix, - ) -> N::SimdRealField + m1: &Matrix, + m2: &Matrix, + ) -> T::SimdRealField where R1: Dim, C1: Dim, - S1: Storage, + S1: Storage, R2: Dim, C2: Dim, - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns; } @@ -46,13 +46,13 @@ pub struct LpNorm(pub i32); /// L-infinite norm aka. Chebytchev norm aka. uniform norm aka. suppremum norm. pub struct UniformNorm; -impl Norm for EuclideanNorm { +impl Norm for EuclideanNorm { #[inline] - fn norm(&self, m: &Matrix) -> N::SimdRealField + fn norm(&self, m: &Matrix) -> T::SimdRealField where R: Dim, C: Dim, - S: Storage, + S: Storage, { m.norm_squared().simd_sqrt() } @@ -60,19 +60,19 @@ impl Norm for EuclideanNorm { #[inline] fn metric_distance( &self, - m1: &Matrix, - m2: &Matrix, - ) -> N::SimdRealField + m1: &Matrix, + m2: &Matrix, + ) -> T::SimdRealField where R1: Dim, C1: Dim, - S1: Storage, + S1: Storage, R2: Dim, C2: Dim, - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { - m1.zip_fold(m2, N::SimdRealField::zero(), |acc, a, b| { + m1.zip_fold(m2, T::SimdRealField::zero(), |acc, a, b| { let diff = a - b; acc + diff.simd_modulus_squared() }) @@ -80,15 +80,15 @@ impl Norm for EuclideanNorm { } } -impl Norm for LpNorm { +impl Norm for LpNorm { #[inline] - fn norm(&self, m: &Matrix) -> N::SimdRealField + fn norm(&self, m: &Matrix) -> T::SimdRealField where R: Dim, C: Dim, - S: Storage, + S: Storage, { - m.fold(N::SimdRealField::zero(), |a, b| { + m.fold(T::SimdRealField::zero(), |a, b| { a + b.simd_modulus().simd_powi(self.0) }) .simd_powf(crate::convert(1.0 / (self.0 as f64))) @@ -97,19 +97,19 @@ impl Norm for LpNorm { #[inline] fn metric_distance( &self, - m1: &Matrix, - m2: &Matrix, - ) -> N::SimdRealField + m1: &Matrix, + m2: &Matrix, + ) -> T::SimdRealField where R1: Dim, C1: Dim, - S1: Storage, + S1: Storage, R2: Dim, C2: Dim, - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { - m1.zip_fold(m2, N::SimdRealField::zero(), |acc, a, b| { + m1.zip_fold(m2, T::SimdRealField::zero(), |acc, a, b| { let diff = a - b; acc + diff.simd_modulus().simd_powi(self.0) }) @@ -117,17 +117,17 @@ impl Norm for LpNorm { } } -impl Norm for UniformNorm { +impl Norm for UniformNorm { #[inline] - fn norm(&self, m: &Matrix) -> N::SimdRealField + fn norm(&self, m: &Matrix) -> T::SimdRealField where R: Dim, C: Dim, - S: Storage, + S: Storage, { // NOTE: we don't use `m.amax()` here because for the complex // numbers this will return the max norm1 instead of the modulus. - m.fold(N::SimdRealField::zero(), |acc, a| { + m.fold(T::SimdRealField::zero(), |acc, a| { acc.simd_max(a.simd_modulus()) }) } @@ -135,19 +135,19 @@ impl Norm for UniformNorm { #[inline] fn metric_distance( &self, - m1: &Matrix, - m2: &Matrix, - ) -> N::SimdRealField + m1: &Matrix, + m2: &Matrix, + ) -> T::SimdRealField where R1: Dim, C1: Dim, - S1: Storage, + S1: Storage, R2: Dim, C2: Dim, - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { - m1.zip_fold(m2, N::SimdRealField::zero(), |acc, a, b| { + m1.zip_fold(m2, T::SimdRealField::zero(), |acc, a, b| { let val = (a - b).simd_modulus(); acc.simd_max(val) }) @@ -155,14 +155,14 @@ impl Norm for UniformNorm { } /// # Magnitude and norms -impl> Matrix { +impl> Matrix { /// The squared L2 norm of this vector. #[inline] - pub fn norm_squared(&self) -> N::SimdRealField + pub fn norm_squared(&self) -> T::SimdRealField where - N: SimdComplexField, + T: SimdComplexField, { - let mut res = N::SimdRealField::zero(); + let mut res = T::SimdRealField::zero(); for i in 0..self.ncols() { let col = self.column(i); @@ -176,9 +176,9 @@ impl> Matrix { /// /// Use `.apply_norm` to apply a custom norm. #[inline] - pub fn norm(&self) -> N::SimdRealField + pub fn norm(&self) -> T::SimdRealField where - N: SimdComplexField, + T: SimdComplexField, { self.norm_squared().simd_sqrt() } @@ -187,12 +187,12 @@ impl> Matrix { /// /// Use `.apply_metric_distance` to apply a custom norm. #[inline] - pub fn metric_distance(&self, rhs: &Matrix) -> N::SimdRealField + pub fn metric_distance(&self, rhs: &Matrix) -> T::SimdRealField where - N: SimdComplexField, + T: SimdComplexField, R2: Dim, C2: Dim, - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { self.apply_metric_distance(rhs, &EuclideanNorm) @@ -211,9 +211,9 @@ impl> Matrix { /// assert_eq!(v.apply_norm(&EuclideanNorm), v.norm()); /// ``` #[inline] - pub fn apply_norm(&self, norm: &impl Norm) -> N::SimdRealField + pub fn apply_norm(&self, norm: &impl Norm) -> T::SimdRealField where - N: SimdComplexField, + T: SimdComplexField, { norm.norm(self) } @@ -235,14 +235,14 @@ impl> Matrix { #[inline] pub fn apply_metric_distance( &self, - rhs: &Matrix, - norm: &impl Norm, - ) -> N::SimdRealField + rhs: &Matrix, + norm: &impl Norm, + ) -> T::SimdRealField where - N: SimdComplexField, + T: SimdComplexField, R2: Dim, C2: Dim, - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns, { norm.metric_distance(self, rhs) @@ -254,9 +254,9 @@ impl> Matrix { /// /// This function is simply implemented as a call to `norm()` #[inline] - pub fn magnitude(&self) -> N::SimdRealField + pub fn magnitude(&self) -> T::SimdRealField where - N: SimdComplexField, + T: SimdComplexField, { self.norm() } @@ -267,19 +267,19 @@ impl> Matrix { /// /// This function is simply implemented as a call to `norm_squared()` #[inline] - pub fn magnitude_squared(&self) -> N::SimdRealField + pub fn magnitude_squared(&self) -> T::SimdRealField where - N: SimdComplexField, + T: SimdComplexField, { self.norm_squared() } /// Sets the magnitude of this vector. #[inline] - pub fn set_magnitude(&mut self, magnitude: N::SimdRealField) + pub fn set_magnitude(&mut self, magnitude: T::SimdRealField) where - N: SimdComplexField, - S: StorageMut, + T: SimdComplexField, + S: StorageMut, { let n = self.norm(); self.scale_mut(magnitude / n) @@ -288,19 +288,19 @@ impl> Matrix { /// Returns a normalized version of this matrix. #[inline] #[must_use = "Did you mean to use normalize_mut()?"] - pub fn normalize(&self) -> MatrixMN + pub fn normalize(&self) -> OMatrix where - N: SimdComplexField, - DefaultAllocator: Allocator, + T: SimdComplexField, + DefaultAllocator: Allocator, { self.unscale(self.norm()) } /// The Lp norm of this matrix. #[inline] - pub fn lp_norm(&self, p: i32) -> N::SimdRealField + pub fn lp_norm(&self, p: i32) -> T::SimdRealField where - N: SimdComplexField, + T: SimdComplexField, { self.apply_norm(&LpNorm(p)) } @@ -310,11 +310,11 @@ impl> Matrix { /// The components of this matrix can be SIMD types. #[inline] #[must_use = "Did you mean to use simd_try_normalize_mut()?"] - pub fn simd_try_normalize(&self, min_norm: N::SimdRealField) -> SimdOption> + pub fn simd_try_normalize(&self, min_norm: T::SimdRealField) -> SimdOption> where - N: SimdComplexField, - N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + T: SimdComplexField, + T::Element: Scalar, + DefaultAllocator: Allocator + Allocator, { let n = self.norm(); let le = n.simd_le(min_norm); @@ -327,10 +327,10 @@ impl> Matrix { /// If `self.magnitude()` is smaller than `min_magnitude`, it will be left unchanged. /// Otherwise this is equivalent to: `*self = self.normalize() * magnitude. #[inline] - pub fn try_set_magnitude(&mut self, magnitude: N::RealField, min_magnitude: N::RealField) + pub fn try_set_magnitude(&mut self, magnitude: T::RealField, min_magnitude: T::RealField) where - N: ComplexField, - S: StorageMut, + T: ComplexField, + S: StorageMut, { let n = self.norm(); @@ -341,10 +341,10 @@ impl> Matrix { /// Returns a new vector with the same magnitude as `self` clamped between `0.0` and `max`. #[inline] - pub fn cap_magnitude(&self, max: N::RealField) -> MatrixMN + pub fn cap_magnitude(&self, max: T::RealField) -> OMatrix where - N: ComplexField, - DefaultAllocator: Allocator, + T: ComplexField, + DefaultAllocator: Allocator, { let n = self.norm(); @@ -357,11 +357,11 @@ impl> Matrix { /// Returns a new vector with the same magnitude as `self` clamped between `0.0` and `max`. #[inline] - pub fn simd_cap_magnitude(&self, max: N::SimdRealField) -> MatrixMN + pub fn simd_cap_magnitude(&self, max: T::SimdRealField) -> OMatrix where - N: SimdComplexField, - N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + T: SimdComplexField, + T::Element: Scalar, + DefaultAllocator: Allocator + Allocator, { let n = self.norm(); let scaled = self.scale(max / n); @@ -374,10 +374,10 @@ impl> Matrix { /// The components of this matrix cannot be SIMD types (see `simd_try_normalize`) instead. #[inline] #[must_use = "Did you mean to use try_normalize_mut()?"] - pub fn try_normalize(&self, min_norm: N::RealField) -> Option> + pub fn try_normalize(&self, min_norm: T::RealField) -> Option> where - N: ComplexField, - DefaultAllocator: Allocator, + T: ComplexField, + DefaultAllocator: Allocator, { let n = self.norm(); @@ -390,14 +390,14 @@ impl> Matrix { } /// # In-place normalization -impl> Matrix { +impl> Matrix { /// Normalizes this matrix in-place and returns its norm. /// /// The components of the matrix cannot be SIMD types (see `simd_try_normalize_mut` instead). #[inline] - pub fn normalize_mut(&mut self) -> N::SimdRealField + pub fn normalize_mut(&mut self) -> T::SimdRealField where - N: SimdComplexField, + T: SimdComplexField, { let n = self.norm(); self.unscale_mut(n); @@ -412,12 +412,12 @@ impl> Matrix { #[must_use = "Did you mean to use simd_try_normalize_mut()?"] pub fn simd_try_normalize_mut( &mut self, - min_norm: N::SimdRealField, - ) -> SimdOption + min_norm: T::SimdRealField, + ) -> SimdOption where - N: SimdComplexField, - N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + T: SimdComplexField, + T::Element: Scalar, + DefaultAllocator: Allocator + Allocator, { let n = self.norm(); let le = n.simd_le(min_norm); @@ -429,9 +429,9 @@ impl> Matrix { /// /// If the normalization succeeded, returns the old norm of this matrix. #[inline] - pub fn try_normalize_mut(&mut self, min_norm: N::RealField) -> Option + pub fn try_normalize_mut(&mut self, min_norm: T::RealField) -> Option where - N: ComplexField, + T: ComplexField, { let n = self.norm(); @@ -444,19 +444,19 @@ impl> Matrix { } } -impl Normed for MatrixMN +impl Normed for OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - type Norm = N::SimdRealField; + type Norm = T::SimdRealField; #[inline] - fn norm(&self) -> N::SimdRealField { + fn norm(&self) -> T::SimdRealField { self.norm() } #[inline] - fn norm_squared(&self) -> N::SimdRealField { + fn norm_squared(&self) -> T::SimdRealField { self.norm_squared() } @@ -471,11 +471,11 @@ where } } -impl Neg for Unit> +impl Neg for Unit> where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - type Output = Unit>; + type Output = Unit>; #[inline] fn neg(self) -> Self::Output { @@ -488,9 +488,9 @@ where // − use `x()` instead of `::canonical_basis_element` // − use `::new(x, y, z)` instead of `::from_slice` /// # Basis and orthogonalization -impl VectorN +impl OVector where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { /// The i-the canonical basis element. #[inline] @@ -499,7 +499,7 @@ where let mut res = Self::zero(); unsafe { - *res.data.get_unchecked_linear_mut(i) = N::one(); + *res.data.get_unchecked_linear_mut(i) = T::one(); } res @@ -521,7 +521,7 @@ where } } - if vs[i].try_normalize_mut(N::RealField::zero()).is_some() { + if vs[i].try_normalize_mut(T::RealField::zero()).is_some() { // TODO: this will be efficient on dynamically-allocated vectors but for // statically-allocated ones, `.clone_from` would be better. vs.swap(nbasis_elements, i); @@ -581,9 +581,9 @@ where let mut a; if v[0].norm1() > v[1].norm1() { - a = Self::from_column_slice(&[v[2], N::zero(), -v[0]]); + a = Self::from_column_slice(&[v[2], T::zero(), -v[0]]); } else { - a = Self::from_column_slice(&[N::zero(), -v[2], v[1]]); + a = Self::from_column_slice(&[T::zero(), -v[2], v[1]]); }; let _ = a.normalize_mut(); @@ -612,7 +612,7 @@ where elt -= v * elt.dot(v) } - if let Some(subsp_elt) = elt.try_normalize(N::RealField::zero()) { + if let Some(subsp_elt) = elt.try_normalize(T::RealField::zero()) { if !f(&subsp_elt) { return; }; diff --git a/src/base/ops.rs b/src/base/ops.rs index 73f18a8c..8917efb1 100644 --- a/src/base/ops.rs +++ b/src/base/ops.rs @@ -12,7 +12,7 @@ use crate::base::constraint::{ }; use crate::base::dimension::{Dim, DimMul, DimName, DimProd, Dynamic}; use crate::base::storage::{ContiguousStorageMut, Storage, StorageMut}; -use crate::base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, MatrixSum, Scalar, VectorSliceN}; +use crate::base::{DefaultAllocator, Matrix, MatrixSum, OMatrix, Scalar, VectorSlice}; use crate::SimdComplexField; /* @@ -20,8 +20,8 @@ use crate::SimdComplexField; * Indexing. * */ -impl> Index for Matrix { - type Output = N; +impl> Index for Matrix { + type Output = T; #[inline] fn index(&self, i: usize) -> &Self::Output { @@ -30,12 +30,12 @@ impl> Index for Matrix Index<(usize, usize)> for Matrix +impl Index<(usize, usize)> for Matrix where - N: Scalar, - S: Storage, + T: Scalar, + S: Storage, { - type Output = N; + type Output = T; #[inline] fn index(&self, ij: (usize, usize)) -> &Self::Output { @@ -50,21 +50,21 @@ where } // Mutable versions. -impl> IndexMut for Matrix { +impl> IndexMut for Matrix { #[inline] - fn index_mut(&mut self, i: usize) -> &mut N { + fn index_mut(&mut self, i: usize) -> &mut T { let ij = self.vector_to_matrix_index(i); &mut self[ij] } } -impl IndexMut<(usize, usize)> for Matrix +impl IndexMut<(usize, usize)> for Matrix where - N: Scalar, - S: StorageMut, + T: Scalar, + S: StorageMut, { #[inline] - fn index_mut(&mut self, ij: (usize, usize)) -> &mut N { + fn index_mut(&mut self, ij: (usize, usize)) -> &mut T { let shape = self.shape(); assert!( ij.0 < shape.0 && ij.1 < shape.1, @@ -80,13 +80,13 @@ where * Neg * */ -impl Neg for Matrix +impl Neg for Matrix where - N: Scalar + ClosedNeg, - S: Storage, - DefaultAllocator: Allocator, + T: Scalar + ClosedNeg, + S: Storage, + DefaultAllocator: Allocator, { - type Output = MatrixMN; + type Output = OMatrix; #[inline] fn neg(self) -> Self::Output { @@ -96,13 +96,13 @@ where } } -impl<'a, N, R: Dim, C: Dim, S> Neg for &'a Matrix +impl<'a, T, R: Dim, C: Dim, S> Neg for &'a Matrix where - N: Scalar + ClosedNeg, - S: Storage, - DefaultAllocator: Allocator, + T: Scalar + ClosedNeg, + S: Storage, + DefaultAllocator: Allocator, { - type Output = MatrixMN; + type Output = OMatrix; #[inline] fn neg(self) -> Self::Output { @@ -110,10 +110,10 @@ where } } -impl Matrix +impl Matrix where - N: Scalar + ClosedNeg, - S: StorageMut, + T: Scalar + ClosedNeg, + S: StorageMut, { /// Negates `self` in-place. #[inline] @@ -136,8 +136,8 @@ macro_rules! componentwise_binop_impl( $method_assign_statically_unchecked_rhs: ident; $method_to: ident, $method_to_statically_unchecked: ident) => { - impl> Matrix - where N: Scalar + $bound { + impl> Matrix + where T: Scalar + $bound { /* * @@ -149,10 +149,10 @@ macro_rules! componentwise_binop_impl( #[inline] fn $method_to_statically_unchecked(&self, - rhs: &Matrix, - out: &mut Matrix) - where SB: Storage, - SC: StorageMut { + rhs: &Matrix, + out: &mut Matrix) + where SB: Storage, + SC: StorageMut { assert_eq!(self.shape(), rhs.shape(), "Matrix addition/subtraction dimensions mismatch."); assert_eq!(self.shape(), out.shape(), "Matrix addition/subtraction output dimensions mismatch."); @@ -182,11 +182,11 @@ macro_rules! componentwise_binop_impl( #[inline] - fn $method_assign_statically_unchecked(&mut self, rhs: &Matrix) + fn $method_assign_statically_unchecked(&mut self, rhs: &Matrix) where R2: Dim, C2: Dim, - SA: StorageMut, - SB: Storage { + SA: StorageMut, + SB: Storage { assert_eq!(self.shape(), rhs.shape(), "Matrix addition/subtraction dimensions mismatch."); // This is the most common case and should be deduced at compile-time. @@ -213,10 +213,10 @@ macro_rules! componentwise_binop_impl( #[inline] - fn $method_assign_statically_unchecked_rhs(&self, rhs: &mut Matrix) + fn $method_assign_statically_unchecked_rhs(&self, rhs: &mut Matrix) where R2: Dim, C2: Dim, - SB: StorageMut { + SB: StorageMut { assert_eq!(self.shape(), rhs.shape(), "Matrix addition/subtraction dimensions mismatch."); // This is the most common case and should be deduced at compile-time. @@ -255,27 +255,27 @@ macro_rules! componentwise_binop_impl( #[inline] pub fn $method_to(&self, - rhs: &Matrix, - out: &mut Matrix) - where SB: Storage, - SC: StorageMut, + rhs: &Matrix, + out: &mut Matrix) + where SB: Storage, + SC: StorageMut, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns + SameNumberOfRows + SameNumberOfColumns { self.$method_to_statically_unchecked(rhs, out) } } - impl<'b, N, R1, C1, R2, C2, SA, SB> $Trait<&'b Matrix> for Matrix + impl<'b, T, R1, C1, R2, C2, SA, SB> $Trait<&'b Matrix> for Matrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N: Scalar + $bound, - SA: Storage, - SB: Storage, - DefaultAllocator: SameShapeAllocator, + T: Scalar + $bound, + SA: Storage, + SB: Storage, + DefaultAllocator: SameShapeAllocator, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns { - type Output = MatrixSum; + type Output = MatrixSum; #[inline] - fn $method(self, rhs: &'b Matrix) -> Self::Output { + fn $method(self, rhs: &'b Matrix) -> Self::Output { assert_eq!(self.shape(), rhs.shape(), "Matrix addition/subtraction dimensions mismatch."); let mut res = self.into_owned_sum::(); res.$method_assign_statically_unchecked(rhs); @@ -283,17 +283,17 @@ macro_rules! componentwise_binop_impl( } } - impl<'a, N, R1, C1, R2, C2, SA, SB> $Trait> for &'a Matrix + impl<'a, T, R1, C1, R2, C2, SA, SB> $Trait> for &'a Matrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N: Scalar + $bound, - SA: Storage, - SB: Storage, - DefaultAllocator: SameShapeAllocator, + T: Scalar + $bound, + SA: Storage, + SB: Storage, + DefaultAllocator: SameShapeAllocator, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns { - type Output = MatrixSum; + type Output = MatrixSum; #[inline] - fn $method(self, rhs: Matrix) -> Self::Output { + fn $method(self, rhs: Matrix) -> Self::Output { let mut rhs = rhs.into_owned_sum::(); assert_eq!(self.shape(), rhs.shape(), "Matrix addition/subtraction dimensions mismatch."); self.$method_assign_statically_unchecked_rhs(&mut rhs); @@ -301,32 +301,32 @@ macro_rules! componentwise_binop_impl( } } - impl $Trait> for Matrix + impl $Trait> for Matrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N: Scalar + $bound, - SA: Storage, - SB: Storage, - DefaultAllocator: SameShapeAllocator, + T: Scalar + $bound, + SA: Storage, + SB: Storage, + DefaultAllocator: SameShapeAllocator, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns { - type Output = MatrixSum; + type Output = MatrixSum; #[inline] - fn $method(self, rhs: Matrix) -> Self::Output { + fn $method(self, rhs: Matrix) -> Self::Output { self.$method(&rhs) } } - impl<'a, 'b, N, R1, C1, R2, C2, SA, SB> $Trait<&'b Matrix> for &'a Matrix + impl<'a, 'b, T, R1, C1, R2, C2, SA, SB> $Trait<&'b Matrix> for &'a Matrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N: Scalar + $bound, - SA: Storage, - SB: Storage, - DefaultAllocator: SameShapeAllocator, + T: Scalar + $bound, + SA: Storage, + SB: Storage, + DefaultAllocator: SameShapeAllocator, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns { - type Output = MatrixSum; + type Output = MatrixSum; #[inline] - fn $method(self, rhs: &'b Matrix) -> Self::Output { + fn $method(self, rhs: &'b Matrix) -> Self::Output { let mut res = unsafe { let (nrows, ncols) = self.shape(); let nrows: SameShapeR = Dim::from_usize(nrows); @@ -339,28 +339,28 @@ macro_rules! componentwise_binop_impl( } } - impl<'b, N, R1, C1, R2, C2, SA, SB> $TraitAssign<&'b Matrix> for Matrix + impl<'b, T, R1, C1, R2, C2, SA, SB> $TraitAssign<&'b Matrix> for Matrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N: Scalar + $bound, - SA: StorageMut, - SB: Storage, + T: Scalar + $bound, + SA: StorageMut, + SB: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns { #[inline] - fn $method_assign(&mut self, rhs: &'b Matrix) { + fn $method_assign(&mut self, rhs: &'b Matrix) { self.$method_assign_statically_unchecked(rhs) } } - impl $TraitAssign> for Matrix + impl $TraitAssign> for Matrix where R1: Dim, C1: Dim, R2: Dim, C2: Dim, - N: Scalar + $bound, - SA: StorageMut, - SB: Storage, + T: Scalar + $bound, + SA: StorageMut, + SB: Storage, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns { #[inline] - fn $method_assign(&mut self, rhs: Matrix) { + fn $method_assign(&mut self, rhs: Matrix) { self.$method_assign(&rhs) } } @@ -374,20 +374,20 @@ componentwise_binop_impl!(Sub, sub, ClosedSub; SubAssign, sub_assign, sub_assign_statically_unchecked, sub_assign_statically_unchecked_mut; sub_to, sub_to_statically_unchecked); -impl iter::Sum for MatrixMN +impl iter::Sum for OMatrix where - N: Scalar + ClosedAdd + Zero, - DefaultAllocator: Allocator, + T: Scalar + ClosedAdd + Zero, + DefaultAllocator: Allocator, { - fn sum>>(iter: I) -> MatrixMN { + fn sum>>(iter: I) -> OMatrix { iter.fold(Matrix::zero(), |acc, x| acc + x) } } -impl iter::Sum for MatrixMN +impl iter::Sum for OMatrix where - N: Scalar + ClosedAdd + Zero, - DefaultAllocator: Allocator, + T: Scalar + ClosedAdd + Zero, + DefaultAllocator: Allocator, { /// # Example /// ``` @@ -405,7 +405,7 @@ where /// # use nalgebra::DMatrix; /// iter::empty::>().sum::>(); // panics! /// ``` - fn sum>>(mut iter: I) -> MatrixMN { + fn sum>>(mut iter: I) -> OMatrix { if let Some(first) = iter.next() { iter.fold(first, |acc, x| acc + x) } else { @@ -414,20 +414,20 @@ where } } -impl<'a, N, R: DimName, C: DimName> iter::Sum<&'a MatrixMN> for MatrixMN +impl<'a, T, R: DimName, C: DimName> iter::Sum<&'a OMatrix> for OMatrix where - N: Scalar + ClosedAdd + Zero, - DefaultAllocator: Allocator, + T: Scalar + ClosedAdd + Zero, + DefaultAllocator: Allocator, { - fn sum>>(iter: I) -> MatrixMN { + fn sum>>(iter: I) -> OMatrix { iter.fold(Matrix::zero(), |acc, x| acc + x) } } -impl<'a, N, C: Dim> iter::Sum<&'a MatrixMN> for MatrixMN +impl<'a, T, C: Dim> iter::Sum<&'a OMatrix> for OMatrix where - N: Scalar + ClosedAdd + Zero, - DefaultAllocator: Allocator, + T: Scalar + ClosedAdd + Zero, + DefaultAllocator: Allocator, { /// # Example /// ``` @@ -445,9 +445,7 @@ where /// # use nalgebra::DMatrix; /// iter::empty::<&DMatrix>().sum::>(); // panics! /// ``` - fn sum>>( - mut iter: I, - ) -> MatrixMN { + fn sum>>(mut iter: I) -> OMatrix { if let Some(first) = iter.next() { iter.fold(first.clone(), |acc, x| acc + x) } else { @@ -467,14 +465,14 @@ where macro_rules! componentwise_scalarop_impl( ($Trait: ident, $method: ident, $bound: ident; $TraitAssign: ident, $method_assign: ident) => { - impl $Trait for Matrix - where N: Scalar + $bound, - S: Storage, - DefaultAllocator: Allocator { - type Output = MatrixMN; + impl $Trait for Matrix + where T: Scalar + $bound, + S: Storage, + DefaultAllocator: Allocator { + type Output = OMatrix; #[inline] - fn $method(self, rhs: N) -> Self::Output { + fn $method(self, rhs: T) -> Self::Output { let mut res = self.into_owned(); // XXX: optimize our iterator! @@ -491,23 +489,23 @@ macro_rules! componentwise_scalarop_impl( } } - impl<'a, N, R: Dim, C: Dim, S> $Trait for &'a Matrix - where N: Scalar + $bound, - S: Storage, - DefaultAllocator: Allocator { - type Output = MatrixMN; + impl<'a, T, R: Dim, C: Dim, S> $Trait for &'a Matrix + where T: Scalar + $bound, + S: Storage, + DefaultAllocator: Allocator { + type Output = OMatrix; #[inline] - fn $method(self, rhs: N) -> Self::Output { + fn $method(self, rhs: T) -> Self::Output { self.clone_owned().$method(rhs) } } - impl $TraitAssign for Matrix - where N: Scalar + $bound, - S: StorageMut { + impl $TraitAssign for Matrix + where T: Scalar + $bound, + S: StorageMut { #[inline] - fn $method_assign(&mut self, rhs: N) { + fn $method_assign(&mut self, rhs: T) { for j in 0 .. self.ncols() { for i in 0 .. self.nrows() { unsafe { self.get_unchecked_mut((i, j)).$method_assign(rhs.inlined_clone()) }; @@ -525,7 +523,7 @@ macro_rules! left_scalar_mul_impl( ($($T: ty),* $(,)*) => {$( impl> Mul> for $T where DefaultAllocator: Allocator<$T, R, C> { - type Output = MatrixMN<$T, R, C>; + type Output = OMatrix<$T, R, C>; #[inline] fn mul(self, rhs: Matrix<$T, R, C, S>) -> Self::Output { @@ -547,7 +545,7 @@ macro_rules! left_scalar_mul_impl( impl<'b, R: Dim, C: Dim, S: Storage<$T, R, C>> Mul<&'b Matrix<$T, R, C, S>> for $T where DefaultAllocator: Allocator<$T, R, C> { - type Output = MatrixMN<$T, R, C>; + type Output = OMatrix<$T, R, C>; #[inline] fn mul(self, rhs: &'b Matrix<$T, R, C, S>) -> Self::Output { @@ -560,19 +558,19 @@ macro_rules! left_scalar_mul_impl( left_scalar_mul_impl!(u8, u16, u32, u64, usize, i8, i16, i32, i64, isize, f32, f64); // Matrix × Matrix -impl<'a, 'b, N, R1: Dim, C1: Dim, R2: Dim, C2: Dim, SA, SB> Mul<&'b Matrix> - for &'a Matrix +impl<'a, 'b, T, R1: Dim, C1: Dim, R2: Dim, C2: Dim, SA, SB> Mul<&'b Matrix> + for &'a Matrix where - N: Scalar + Zero + One + ClosedAdd + ClosedMul, - SA: Storage, - SB: Storage, - DefaultAllocator: Allocator, + T: Scalar + Zero + One + ClosedAdd + ClosedMul, + SA: Storage, + SB: Storage, + DefaultAllocator: Allocator, ShapeConstraint: AreMultipliable, { - type Output = MatrixMN; + type Output = OMatrix; #[inline] - fn mul(self, rhs: &'b Matrix) -> Self::Output { + fn mul(self, rhs: &'b Matrix) -> Self::Output { let mut res = unsafe { crate::unimplemented_or_uninitialized_generic!(self.data.shape().0, rhs.data.shape().1) }; @@ -581,53 +579,53 @@ where } } -impl<'a, N, R1: Dim, C1: Dim, R2: Dim, C2: Dim, SA, SB> Mul> - for &'a Matrix +impl<'a, T, R1: Dim, C1: Dim, R2: Dim, C2: Dim, SA, SB> Mul> + for &'a Matrix where - N: Scalar + Zero + One + ClosedAdd + ClosedMul, - SB: Storage, - SA: Storage, - DefaultAllocator: Allocator, + T: Scalar + Zero + One + ClosedAdd + ClosedMul, + SB: Storage, + SA: Storage, + DefaultAllocator: Allocator, ShapeConstraint: AreMultipliable, { - type Output = MatrixMN; + type Output = OMatrix; #[inline] - fn mul(self, rhs: Matrix) -> Self::Output { + fn mul(self, rhs: Matrix) -> Self::Output { self * &rhs } } -impl<'b, N, R1: Dim, C1: Dim, R2: Dim, C2: Dim, SA, SB> Mul<&'b Matrix> - for Matrix +impl<'b, T, R1: Dim, C1: Dim, R2: Dim, C2: Dim, SA, SB> Mul<&'b Matrix> + for Matrix where - N: Scalar + Zero + One + ClosedAdd + ClosedMul, - SB: Storage, - SA: Storage, - DefaultAllocator: Allocator, + T: Scalar + Zero + One + ClosedAdd + ClosedMul, + SB: Storage, + SA: Storage, + DefaultAllocator: Allocator, ShapeConstraint: AreMultipliable, { - type Output = MatrixMN; + type Output = OMatrix; #[inline] - fn mul(self, rhs: &'b Matrix) -> Self::Output { + fn mul(self, rhs: &'b Matrix) -> Self::Output { &self * rhs } } -impl Mul> - for Matrix +impl Mul> + for Matrix where - N: Scalar + Zero + One + ClosedAdd + ClosedMul, - SB: Storage, - SA: Storage, - DefaultAllocator: Allocator, + T: Scalar + Zero + One + ClosedAdd + ClosedMul, + SB: Storage, + SA: Storage, + DefaultAllocator: Allocator, ShapeConstraint: AreMultipliable, { - type Output = MatrixMN; + type Output = OMatrix; #[inline] - fn mul(self, rhs: Matrix) -> Self::Output { + fn mul(self, rhs: Matrix) -> Self::Output { &self * &rhs } } @@ -635,53 +633,53 @@ where // TODO: this is too restrictive: // − we can't use `a *= b` when `a` is a mutable slice. // − we can't use `a *= b` when C2 is not equal to C1. -impl MulAssign> for Matrix +impl MulAssign> for Matrix where R1: Dim, C1: Dim, R2: Dim, - N: Scalar + Zero + One + ClosedAdd + ClosedMul, - SB: Storage, - SA: ContiguousStorageMut + Clone, + T: Scalar + Zero + One + ClosedAdd + ClosedMul, + SB: Storage, + SA: ContiguousStorageMut + Clone, ShapeConstraint: AreMultipliable, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { #[inline] - fn mul_assign(&mut self, rhs: Matrix) { + fn mul_assign(&mut self, rhs: Matrix) { *self = &*self * rhs } } -impl<'b, N, R1, C1, R2, SA, SB> MulAssign<&'b Matrix> for Matrix +impl<'b, T, R1, C1, R2, SA, SB> MulAssign<&'b Matrix> for Matrix where R1: Dim, C1: Dim, R2: Dim, - N: Scalar + Zero + One + ClosedAdd + ClosedMul, - SB: Storage, - SA: ContiguousStorageMut + Clone, + T: Scalar + Zero + One + ClosedAdd + ClosedMul, + SB: Storage, + SA: ContiguousStorageMut + Clone, ShapeConstraint: AreMultipliable, // TODO: this is too restrictive. See comments for the non-ref version. - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { #[inline] - fn mul_assign(&mut self, rhs: &'b Matrix) { + fn mul_assign(&mut self, rhs: &'b Matrix) { *self = &*self * rhs } } /// # Special multiplications. -impl Matrix +impl Matrix where - N: Scalar + Zero + One + ClosedAdd + ClosedMul, - SA: Storage, + T: Scalar + Zero + One + ClosedAdd + ClosedMul, + SA: Storage, { /// Equivalent to `self.transpose() * rhs`. #[inline] - pub fn tr_mul(&self, rhs: &Matrix) -> MatrixMN + pub fn tr_mul(&self, rhs: &Matrix) -> OMatrix where - SB: Storage, - DefaultAllocator: Allocator, + SB: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = unsafe { @@ -694,11 +692,11 @@ where /// Equivalent to `self.adjoint() * rhs`. #[inline] - pub fn ad_mul(&self, rhs: &Matrix) -> MatrixMN + pub fn ad_mul(&self, rhs: &Matrix) -> OMatrix where - N: SimdComplexField, - SB: Storage, - DefaultAllocator: Allocator, + T: SimdComplexField, + SB: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = unsafe { @@ -712,15 +710,15 @@ where #[inline(always)] fn xx_mul_to( &self, - rhs: &Matrix, - out: &mut Matrix, + rhs: &Matrix, + out: &mut Matrix, dot: impl Fn( - &VectorSliceN, - &VectorSliceN, - ) -> N, + &VectorSlice, + &VectorSlice, + ) -> T, ) where - SB: Storage, - SC: StorageMut, + SB: Storage, + SC: StorageMut, ShapeConstraint: SameNumberOfRows + DimEq + DimEq, { let (nrows1, ncols1) = self.shape(); @@ -759,11 +757,11 @@ where #[inline] pub fn tr_mul_to( &self, - rhs: &Matrix, - out: &mut Matrix, + rhs: &Matrix, + out: &mut Matrix, ) where - SB: Storage, - SC: StorageMut, + SB: Storage, + SC: StorageMut, ShapeConstraint: SameNumberOfRows + DimEq + DimEq, { self.xx_mul_to(rhs, out, |a, b| a.dot(b)) @@ -774,12 +772,12 @@ where #[inline] pub fn ad_mul_to( &self, - rhs: &Matrix, - out: &mut Matrix, + rhs: &Matrix, + out: &mut Matrix, ) where - N: SimdComplexField, - SB: Storage, - SC: StorageMut, + T: SimdComplexField, + SB: Storage, + SC: StorageMut, ShapeConstraint: SameNumberOfRows + DimEq + DimEq, { self.xx_mul_to(rhs, out, |a, b| a.dotc(b)) @@ -789,30 +787,30 @@ where #[inline] pub fn mul_to( &self, - rhs: &Matrix, - out: &mut Matrix, + rhs: &Matrix, + out: &mut Matrix, ) where - SB: Storage, - SC: StorageMut, + SB: Storage, + SC: StorageMut, ShapeConstraint: SameNumberOfRows + SameNumberOfColumns + AreMultipliable, { - out.gemm(N::one(), self, rhs, N::zero()); + out.gemm(T::one(), self, rhs, T::zero()); } /// The kronecker product of two matrices (aka. tensor product of the corresponding linear /// maps). pub fn kronecker( &self, - rhs: &Matrix, - ) -> MatrixMN, DimProd> + rhs: &Matrix, + ) -> OMatrix, DimProd> where - N: ClosedMul, + T: ClosedMul, R1: DimMul, C1: DimMul, - SB: Storage, - DefaultAllocator: Allocator, DimProd>, + SB: Storage, + DefaultAllocator: Allocator, DimProd>, { let (nrows1, ncols1) = self.data.shape(); let (nrows2, ncols2) = rhs.data.shape(); @@ -845,22 +843,22 @@ where } } -impl iter::Product for MatrixN +impl iter::Product for OMatrix where - N: Scalar + Zero + One + ClosedMul + ClosedAdd, - DefaultAllocator: Allocator, + T: Scalar + Zero + One + ClosedMul + ClosedAdd, + DefaultAllocator: Allocator, { - fn product>>(iter: I) -> MatrixN { + fn product>>(iter: I) -> OMatrix { iter.fold(Matrix::one(), |acc, x| acc * x) } } -impl<'a, N, D: DimName> iter::Product<&'a MatrixN> for MatrixN +impl<'a, T, D: DimName> iter::Product<&'a OMatrix> for OMatrix where - N: Scalar + Zero + One + ClosedMul + ClosedAdd, - DefaultAllocator: Allocator, + T: Scalar + Zero + One + ClosedMul + ClosedAdd, + DefaultAllocator: Allocator, { - fn product>>(iter: I) -> MatrixN { + fn product>>(iter: I) -> OMatrix { iter.fold(Matrix::one(), |acc, x| acc * x) } } diff --git a/src/base/properties.rs b/src/base/properties.rs index d1119afe..1cbff719 100644 --- a/src/base/properties.rs +++ b/src/base/properties.rs @@ -9,7 +9,7 @@ use crate::base::dimension::{Dim, DimMin}; use crate::base::storage::Storage; use crate::base::{DefaultAllocator, Matrix, Scalar, SquareMatrix}; -impl> Matrix { +impl> Matrix { /// The total number of elements of this matrix. /// /// # Examples: @@ -52,10 +52,10 @@ impl> Matrix { /// If the matrix is diagonal, this checks that diagonal elements (i.e. at coordinates `(i, i)` /// for i from `0` to `min(R, C)`) are equal one; and that all other elements are zero. #[inline] - pub fn is_identity(&self, eps: N::Epsilon) -> bool + pub fn is_identity(&self, eps: T::Epsilon) -> bool where - N: Zero + One + RelativeEq, - N::Epsilon: Copy, + T: Zero + One + RelativeEq, + T::Epsilon: Copy, { let (nrows, ncols) = self.shape(); let d; @@ -65,7 +65,7 @@ impl> Matrix { for i in d..nrows { for j in 0..ncols { - if !relative_eq!(self[(i, j)], N::zero(), epsilon = eps) { + if !relative_eq!(self[(i, j)], T::zero(), epsilon = eps) { return false; } } @@ -76,7 +76,7 @@ impl> Matrix { for i in 0..nrows { for j in d..ncols { - if !relative_eq!(self[(i, j)], N::zero(), epsilon = eps) { + if !relative_eq!(self[(i, j)], T::zero(), epsilon = eps) { return false; } } @@ -87,8 +87,8 @@ impl> Matrix { for i in 1..d { for j in 0..i { // TODO: use unsafe indexing. - if !relative_eq!(self[(i, j)], N::zero(), epsilon = eps) - || !relative_eq!(self[(j, i)], N::zero(), epsilon = eps) + if !relative_eq!(self[(i, j)], T::zero(), epsilon = eps) + || !relative_eq!(self[(j, i)], T::zero(), epsilon = eps) { return false; } @@ -97,7 +97,7 @@ impl> Matrix { // Diagonal elements of the sub-square matrix. for i in 0..d { - if !relative_eq!(self[(i, i)], N::one(), epsilon = eps) { + if !relative_eq!(self[(i, i)], T::one(), epsilon = eps) { return false; } } @@ -106,35 +106,35 @@ impl> Matrix { } } -impl> Matrix { +impl> Matrix { /// Checks that `Mᵀ × M = Id`. /// /// In this definition `Id` is approximately equal to the identity matrix with a relative error /// equal to `eps`. #[inline] - pub fn is_orthogonal(&self, eps: N::Epsilon) -> bool + pub fn is_orthogonal(&self, eps: T::Epsilon) -> bool where - N: Zero + One + ClosedAdd + ClosedMul + RelativeEq, - S: Storage, - N::Epsilon: Copy, - DefaultAllocator: Allocator + Allocator, + T: Zero + One + ClosedAdd + ClosedMul + RelativeEq, + S: Storage, + T::Epsilon: Copy, + DefaultAllocator: Allocator + Allocator, { (self.ad_mul(self)).is_identity(eps) } } -impl> SquareMatrix +impl> SquareMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { /// Checks that this matrix is orthogonal and has a determinant equal to 1. #[inline] - pub fn is_special_orthogonal(&self, eps: N) -> bool + pub fn is_special_orthogonal(&self, eps: T) -> bool where D: DimMin, DefaultAllocator: Allocator<(usize, usize), D>, { - self.is_square() && self.is_orthogonal(eps) && self.determinant() > N::zero() + self.is_square() && self.is_orthogonal(eps) && self.determinant() > T::zero() } /// Returns `true` if this matrix is invertible. diff --git a/src/base/scalar.rs b/src/base/scalar.rs index a8008ddf..db9e458d 100644 --- a/src/base/scalar.rs +++ b/src/base/scalar.rs @@ -9,7 +9,7 @@ pub trait Scalar: Clone + PartialEq + Debug + Any { #[inline] /// Tests if `Self` the same as the type `T` /// - /// Typically used to test of `Self` is a f32 or a f64 with `N::is::()`. + /// Typically used to test of `Self` is a f32 or a f64 with `T::is::()`. fn is() -> bool { TypeId::of::() == TypeId::of::() } diff --git a/src/base/statistics.rs b/src/base/statistics.rs index 653e822b..8f6c77ce 100644 --- a/src/base/statistics.rs +++ b/src/base/statistics.rs @@ -1,23 +1,23 @@ use crate::allocator::Allocator; use crate::storage::Storage; -use crate::{Const, DefaultAllocator, Dim, Matrix, RowVectorN, Scalar, VectorN, VectorSliceN, U1}; +use crate::{Const, DefaultAllocator, Dim, Matrix, OVector, RowOVector, Scalar, VectorSlice, U1}; use num::Zero; use simba::scalar::{ClosedAdd, Field, SupersetOf}; /// # Folding on columns and rows -impl> Matrix { +impl> Matrix { /// Returns a row vector where each element is the result of the application of `f` on the /// corresponding column of the original matrix. #[inline] pub fn compress_rows( &self, - f: impl Fn(VectorSliceN) -> N, - ) -> RowVectorN + f: impl Fn(VectorSlice) -> T, + ) -> RowOVector where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let ncols = self.data.shape().1; - let mut res: RowVectorN = + let mut res: RowOVector = unsafe { crate::unimplemented_or_uninitialized_generic!(Const::<1>, ncols) }; for i in 0..ncols.value() { @@ -37,13 +37,13 @@ impl> Matrix { #[inline] pub fn compress_rows_tr( &self, - f: impl Fn(VectorSliceN) -> N, - ) -> VectorN + f: impl Fn(VectorSlice) -> T, + ) -> OVector where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let ncols = self.data.shape().1; - let mut res: VectorN = + let mut res: OVector = unsafe { crate::unimplemented_or_uninitialized_generic!(ncols, Const::<1>) }; for i in 0..ncols.value() { @@ -60,11 +60,11 @@ impl> Matrix { #[inline] pub fn compress_columns( &self, - init: VectorN, - f: impl Fn(&mut VectorN, VectorSliceN), - ) -> VectorN + init: OVector, + f: impl Fn(&mut OVector, VectorSlice), + ) -> OVector where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let mut res = init; @@ -77,7 +77,7 @@ impl> Matrix { } /// # Common statistics operations -impl> Matrix { +impl> Matrix { /* * * Sum computation. @@ -95,11 +95,11 @@ impl> Matrix { /// assert_eq!(m.sum(), 21.0); /// ``` #[inline] - pub fn sum(&self) -> N + pub fn sum(&self) -> T where - N: ClosedAdd + Zero, + T: ClosedAdd + Zero, { - self.iter().cloned().fold(N::zero(), |a, b| a + b) + self.iter().cloned().fold(T::zero(), |a, b| a + b) } /// The sum of all the rows of this matrix. @@ -120,10 +120,10 @@ impl> Matrix { /// assert_eq!(mint.row_sum(), RowVector2::new(9,12)); /// ``` #[inline] - pub fn row_sum(&self) -> RowVectorN + pub fn row_sum(&self) -> RowOVector where - N: ClosedAdd + Zero, - DefaultAllocator: Allocator, + T: ClosedAdd + Zero, + DefaultAllocator: Allocator, { self.compress_rows(|col| col.sum()) } @@ -144,10 +144,10 @@ impl> Matrix { /// assert_eq!(mint.row_sum_tr(), Vector2::new(9,12)); /// ``` #[inline] - pub fn row_sum_tr(&self) -> VectorN + pub fn row_sum_tr(&self) -> OVector where - N: ClosedAdd + Zero, - DefaultAllocator: Allocator, + T: ClosedAdd + Zero, + DefaultAllocator: Allocator, { self.compress_rows_tr(|col| col.sum()) } @@ -168,13 +168,13 @@ impl> Matrix { /// assert_eq!(mint.column_sum(), Vector3::new(3,7,11)); /// ``` #[inline] - pub fn column_sum(&self) -> VectorN + pub fn column_sum(&self) -> OVector where - N: ClosedAdd + Zero, - DefaultAllocator: Allocator, + T: ClosedAdd + Zero, + DefaultAllocator: Allocator, { let nrows = self.data.shape().0; - self.compress_columns(VectorN::zeros_generic(nrows, Const::<1>), |out, col| { + self.compress_columns(OVector::zeros_generic(nrows, Const::<1>), |out, col| { *out += col; }) } @@ -197,17 +197,17 @@ impl> Matrix { /// assert_relative_eq!(m.variance(), 35.0 / 12.0, epsilon = 1.0e-8); /// ``` #[inline] - pub fn variance(&self) -> N + pub fn variance(&self) -> T where - N: Field + SupersetOf, + T: Field + SupersetOf, { if self.is_empty() { - N::zero() + T::zero() } else { - let val = self.iter().cloned().fold((N::zero(), N::zero()), |a, b| { + let val = self.iter().cloned().fold((T::zero(), T::zero()), |a, b| { (a.0 + b.inlined_clone() * b.inlined_clone(), a.1 + b) }); - let denom = N::one() / crate::convert::<_, N>(self.len() as f64); + let denom = T::one() / crate::convert::<_, T>(self.len() as f64); let vd = val.1 * denom.inlined_clone(); val.0 * denom - vd.inlined_clone() * vd } @@ -226,10 +226,10 @@ impl> Matrix { /// assert_eq!(m.row_variance(), RowVector3::new(2.25, 2.25, 2.25)); /// ``` #[inline] - pub fn row_variance(&self) -> RowVectorN + pub fn row_variance(&self) -> RowOVector where - N: Field + SupersetOf, - DefaultAllocator: Allocator, + T: Field + SupersetOf, + DefaultAllocator: Allocator, { self.compress_rows(|col| col.variance()) } @@ -246,10 +246,10 @@ impl> Matrix { /// assert_eq!(m.row_variance_tr(), Vector3::new(2.25, 2.25, 2.25)); /// ``` #[inline] - pub fn row_variance_tr(&self) -> VectorN + pub fn row_variance_tr(&self) -> OVector where - N: Field + SupersetOf, - DefaultAllocator: Allocator, + T: Field + SupersetOf, + DefaultAllocator: Allocator, { self.compress_rows_tr(|col| col.variance()) } @@ -267,17 +267,17 @@ impl> Matrix { /// assert_relative_eq!(m.column_variance(), Vector2::new(2.0 / 3.0, 2.0 / 3.0), epsilon = 1.0e-8); /// ``` #[inline] - pub fn column_variance(&self) -> VectorN + pub fn column_variance(&self) -> OVector where - N: Field + SupersetOf, - DefaultAllocator: Allocator, + T: Field + SupersetOf, + DefaultAllocator: Allocator, { let (nrows, ncols) = self.data.shape(); let mut mean = self.column_mean(); mean.apply(|e| -(e.inlined_clone() * e)); - let denom = N::one() / crate::convert::<_, N>(ncols.value() as f64); + let denom = T::one() / crate::convert::<_, T>(ncols.value() as f64); self.compress_columns(mean, |out, col| { for i in 0..nrows.value() { unsafe { @@ -306,12 +306,12 @@ impl> Matrix { /// assert_eq!(m.mean(), 3.5); /// ``` #[inline] - pub fn mean(&self) -> N + pub fn mean(&self) -> T where - N: Field + SupersetOf, + T: Field + SupersetOf, { if self.is_empty() { - N::zero() + T::zero() } else { self.sum() / crate::convert(self.len() as f64) } @@ -331,10 +331,10 @@ impl> Matrix { /// assert_eq!(m.row_mean(), RowVector3::new(2.5, 3.5, 4.5)); /// ``` #[inline] - pub fn row_mean(&self) -> RowVectorN + pub fn row_mean(&self) -> RowOVector where - N: Field + SupersetOf, - DefaultAllocator: Allocator, + T: Field + SupersetOf, + DefaultAllocator: Allocator, { self.compress_rows(|col| col.mean()) } @@ -351,10 +351,10 @@ impl> Matrix { /// assert_eq!(m.row_mean_tr(), Vector3::new(2.5, 3.5, 4.5)); /// ``` #[inline] - pub fn row_mean_tr(&self) -> VectorN + pub fn row_mean_tr(&self) -> OVector where - N: Field + SupersetOf, - DefaultAllocator: Allocator, + T: Field + SupersetOf, + DefaultAllocator: Allocator, { self.compress_rows_tr(|col| col.mean()) } @@ -371,15 +371,15 @@ impl> Matrix { /// assert_eq!(m.column_mean(), Vector2::new(2.0, 5.0)); /// ``` #[inline] - pub fn column_mean(&self) -> VectorN + pub fn column_mean(&self) -> OVector where - N: Field + SupersetOf, - DefaultAllocator: Allocator, + T: Field + SupersetOf, + DefaultAllocator: Allocator, { let (nrows, ncols) = self.data.shape(); - let denom = N::one() / crate::convert::<_, N>(ncols.value() as f64); - self.compress_columns(VectorN::zeros_generic(nrows, Const::<1>), |out, col| { - out.axpy(denom.inlined_clone(), &col, N::one()) + let denom = T::one() / crate::convert::<_, T>(ncols.value() as f64); + self.compress_columns(OVector::zeros_generic(nrows, Const::<1>), |out, col| { + out.axpy(denom.inlined_clone(), &col, T::one()) }) } } diff --git a/src/base/storage.rs b/src/base/storage.rs index 038884e3..0238b36c 100644 --- a/src/base/storage.rs +++ b/src/base/storage.rs @@ -12,20 +12,20 @@ use crate::base::Scalar; * Aliases for allocation results. */ /// The data storage for the sum of two matrices with dimensions `(R1, C1)` and `(R2, C2)`. -pub type SameShapeStorage = - , SameShapeC>>::Buffer; +pub type SameShapeStorage = + , SameShapeC>>::Buffer; // TODO: better name than Owned ? /// The owned data storage that can be allocated from `S`. -pub type Owned = >::Buffer; +pub type Owned = >::Buffer; /// The row-stride of the owned data storage for a buffer of dimension `(R, C)`. -pub type RStride = - <>::Buffer as Storage>::RStride; +pub type RStride = + <>::Buffer as Storage>::RStride; /// The column-stride of the owned data storage for a buffer of dimension `(R, C)`. -pub type CStride = - <>::Buffer as Storage>::CStride; +pub type CStride = + <>::Buffer as Storage>::CStride; /// The trait shared by all matrix data storage. /// @@ -36,7 +36,7 @@ pub type CStride = /// should **not** allow the user to modify the size of the underlying buffer with safe methods /// (for example the `VecStorage::data_mut` method is unsafe because the user could change the /// vector's size so that it no longer contains enough elements: this will lead to UB. -pub unsafe trait Storage: Debug + Sized { +pub unsafe trait Storage: Debug + Sized { /// The static stride of this storage's rows. type RStride: Dim; @@ -44,7 +44,7 @@ pub unsafe trait Storage: Debug + Sized { type CStride: Dim; /// The matrix data pointer. - fn ptr(&self) -> *const N; + fn ptr(&self) -> *const T; /// The dimension of the matrix at run-time. Arr length of zero indicates the additive identity /// element of any dimension. Must be equal to `Self::dimension()` if it is not `None`. @@ -71,25 +71,25 @@ pub unsafe trait Storage: Debug + Sized { /// Gets the address of the i-th matrix component without performing bound-checking. #[inline] - unsafe fn get_address_unchecked_linear(&self, i: usize) -> *const N { + unsafe fn get_address_unchecked_linear(&self, i: usize) -> *const T { self.ptr().wrapping_add(i) } /// Gets the address of the i-th matrix component without performing bound-checking. #[inline] - unsafe fn get_address_unchecked(&self, irow: usize, icol: usize) -> *const N { + unsafe fn get_address_unchecked(&self, irow: usize, icol: usize) -> *const T { self.get_address_unchecked_linear(self.linear_index(irow, icol)) } /// Retrieves a reference to the i-th element without bound-checking. #[inline] - unsafe fn get_unchecked_linear(&self, i: usize) -> &N { + unsafe fn get_unchecked_linear(&self, i: usize) -> &T { &*self.get_address_unchecked_linear(i) } /// Retrieves a reference to the i-th element without bound-checking. #[inline] - unsafe fn get_unchecked(&self, irow: usize, icol: usize) -> &N { + unsafe fn get_unchecked(&self, irow: usize, icol: usize) -> &T { self.get_unchecked_linear(self.linear_index(irow, icol)) } @@ -99,17 +99,17 @@ pub unsafe trait Storage: Debug + Sized { /// Retrieves the data buffer as a contiguous slice. /// /// The matrix components may not be stored in a contiguous way, depending on the strides. - fn as_slice(&self) -> &[N]; + fn as_slice(&self) -> &[T]; /// Builds a matrix data storage that does not contain any reference. - fn into_owned(self) -> Owned + fn into_owned(self) -> Owned where - DefaultAllocator: Allocator; + DefaultAllocator: Allocator; /// Clones this data storage to one that does not contain any reference. - fn clone_owned(&self) -> Owned + fn clone_owned(&self) -> Owned where - DefaultAllocator: Allocator; + DefaultAllocator: Allocator; } /// Trait implemented by matrix data storage that can provide a mutable access to its elements. @@ -117,31 +117,31 @@ pub unsafe trait Storage: Debug + Sized { /// Note that a mutable access does not mean that the matrix owns its data. For example, a mutable /// matrix slice can provide mutable access to its elements even if it does not own its data (it /// contains only an internal reference to them). -pub unsafe trait StorageMut: Storage { +pub unsafe trait StorageMut: Storage { /// The matrix mutable data pointer. - fn ptr_mut(&mut self) -> *mut N; + fn ptr_mut(&mut self) -> *mut T; /// Gets the mutable address of the i-th matrix component without performing bound-checking. #[inline] - unsafe fn get_address_unchecked_linear_mut(&mut self, i: usize) -> *mut N { + unsafe fn get_address_unchecked_linear_mut(&mut self, i: usize) -> *mut T { self.ptr_mut().wrapping_add(i) } /// Gets the mutable address of the i-th matrix component without performing bound-checking. #[inline] - unsafe fn get_address_unchecked_mut(&mut self, irow: usize, icol: usize) -> *mut N { + unsafe fn get_address_unchecked_mut(&mut self, irow: usize, icol: usize) -> *mut T { let lid = self.linear_index(irow, icol); self.get_address_unchecked_linear_mut(lid) } /// Retrieves a mutable reference to the i-th element without bound-checking. - unsafe fn get_unchecked_linear_mut(&mut self, i: usize) -> &mut N { + unsafe fn get_unchecked_linear_mut(&mut self, i: usize) -> &mut T { &mut *self.get_address_unchecked_linear_mut(i) } /// Retrieves a mutable reference to the element at `(irow, icol)` without bound-checking. #[inline] - unsafe fn get_unchecked_mut(&mut self, irow: usize, icol: usize) -> &mut N { + unsafe fn get_unchecked_mut(&mut self, irow: usize, icol: usize) -> &mut T { &mut *self.get_address_unchecked_mut(irow, icol) } @@ -166,7 +166,7 @@ pub unsafe trait StorageMut: Storage { /// Retrieves the mutable data buffer as a contiguous slice. /// /// Matrix components may not be contiguous, depending on its strides. - fn as_mut_slice(&mut self) -> &mut [N]; + fn as_mut_slice(&mut self) -> &mut [T]; } /// A matrix storage that is stored contiguously in memory. @@ -174,8 +174,8 @@ pub unsafe trait StorageMut: Storage { /// The storage requirement means that for any value of `i` in `[0, nrows * ncols - 1]`, the value /// `.get_unchecked_linear` returns one of the matrix component. This trait is unsafe because /// failing to comply to this may cause Undefined Behaviors. -pub unsafe trait ContiguousStorage: - Storage +pub unsafe trait ContiguousStorage: + Storage { } @@ -184,22 +184,22 @@ pub unsafe trait ContiguousStorage: /// The storage requirement means that for any value of `i` in `[0, nrows * ncols - 1]`, the value /// `.get_unchecked_linear` returns one of the matrix component. This trait is unsafe because /// failing to comply to this may cause Undefined Behaviors. -pub unsafe trait ContiguousStorageMut: - ContiguousStorage + StorageMut +pub unsafe trait ContiguousStorageMut: + ContiguousStorage + StorageMut { } /// A matrix storage that can be reshaped in-place. -pub trait ReshapableStorage: Storage +pub trait ReshapableStorage: Storage where - N: Scalar, + T: Scalar, R1: Dim, C1: Dim, R2: Dim, C2: Dim, { /// The reshaped storage type. - type Output: Storage; + type Output: Storage; /// Reshapes the storage into the output storage type. fn reshape_generic(self, nrows: R2, ncols: C2) -> Self::Output; diff --git a/src/base/swizzle.rs b/src/base/swizzle.rs index a4ae1a46..1e2f0e4c 100644 --- a/src/base/swizzle.rs +++ b/src/base/swizzle.rs @@ -8,7 +8,7 @@ macro_rules! impl_swizzle { $( /// Builds a new vector from components of `self`. #[inline] - pub fn $name(&self) -> $Result + pub fn $name(&self) -> $Result where D::Typenum: Cmp { $Result::new($(self[$i].inlined_clone()),*) } @@ -18,7 +18,7 @@ macro_rules! impl_swizzle { } /// # Swizzling -impl> Vector +impl> Vector where D: DimName + ToTypenum, { diff --git a/src/base/unit.rs b/src/base/unit.rs index 70e3a927..527f7503 100644 --- a/src/base/unit.rs +++ b/src/base/unit.rs @@ -12,7 +12,7 @@ use abomonation::Abomonation; use crate::allocator::Allocator; use crate::base::DefaultAllocator; use crate::storage::Storage; -use crate::{Dim, Matrix, MatrixMN, RealField, Scalar, SimdComplexField, SimdRealField}; +use crate::{Dim, Matrix, OMatrix, RealField, Scalar, SimdComplexField, SimdRealField}; /// A wrapper that ensures the underlying algebraic entity has a unit norm. /// @@ -71,12 +71,12 @@ impl Abomonation for Unit { } } -impl PartialEq for Unit> +impl PartialEq for Unit> where - N: Scalar + PartialEq, + T: Scalar + PartialEq, R: Dim, C: Dim, - S: Storage, + S: Storage, { #[inline] fn eq(&self, rhs: &Self) -> bool { @@ -84,12 +84,12 @@ where } } -impl Eq for Unit> +impl Eq for Unit> where - N: Scalar + Eq, + T: Scalar + Eq, R: Dim, C: Dim, - S: Storage, + S: Storage, { } @@ -298,32 +298,32 @@ impl Deref for Unit { // NOTE: we can't use a generic implementation for `Unit` because // num_complex::Complex does not implement `From[Complex<...>...]` (and can't // because of the orphan rules). -impl - From<[Unit>; 2]> for Unit> +impl + From<[Unit>; 2]> for Unit> where - N: From<[::Element; 2]>, - N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + T: From<[::Element; 2]>, + T::Element: Scalar, + DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [Unit>; 2]) -> Self { - Self::new_unchecked(MatrixMN::from([ + fn from(arr: [Unit>; 2]) -> Self { + Self::new_unchecked(OMatrix::from([ arr[0].clone().into_inner(), arr[1].clone().into_inner(), ])) } } -impl - From<[Unit>; 4]> for Unit> +impl + From<[Unit>; 4]> for Unit> where - N: From<[::Element; 4]>, - N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + T: From<[::Element; 4]>, + T::Element: Scalar, + DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [Unit>; 4]) -> Self { - Self::new_unchecked(MatrixMN::from([ + fn from(arr: [Unit>; 4]) -> Self { + Self::new_unchecked(OMatrix::from([ arr[0].clone().into_inner(), arr[1].clone().into_inner(), arr[2].clone().into_inner(), @@ -332,16 +332,16 @@ where } } -impl - From<[Unit>; 8]> for Unit> +impl + From<[Unit>; 8]> for Unit> where - N: From<[::Element; 8]>, - N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + T: From<[::Element; 8]>, + T::Element: Scalar, + DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [Unit>; 8]) -> Self { - Self::new_unchecked(MatrixMN::from([ + fn from(arr: [Unit>; 8]) -> Self { + Self::new_unchecked(OMatrix::from([ arr[0].clone().into_inner(), arr[1].clone().into_inner(), arr[2].clone().into_inner(), @@ -354,16 +354,16 @@ where } } -impl - From<[Unit>; 16]> for Unit> +impl + From<[Unit>; 16]> for Unit> where - N: From<[::Element; 16]>, - N::Element: Scalar, - DefaultAllocator: Allocator + Allocator, + T: From<[::Element; 16]>, + T::Element: Scalar, + DefaultAllocator: Allocator + Allocator, { #[inline] - fn from(arr: [Unit>; 16]) -> Self { - Self::new_unchecked(MatrixMN::from([ + fn from(arr: [Unit>; 16]) -> Self { + Self::new_unchecked(OMatrix::from([ arr[0].clone().into_inner(), arr[1].clone().into_inner(), arr[2].clone().into_inner(), diff --git a/src/base/vec_storage.rs b/src/base/vec_storage.rs index 03f032e8..29da127d 100644 --- a/src/base/vec_storage.rs +++ b/src/base/vec_storage.rs @@ -25,20 +25,20 @@ use abomonation::Abomonation; #[repr(C)] #[derive(Eq, Debug, Clone, PartialEq)] #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] -pub struct VecStorage { - data: Vec, +pub struct VecStorage { + data: Vec, nrows: R, ncols: C, } #[deprecated(note = "renamed to `VecStorage`")] /// Renamed to [VecStorage]. -pub type MatrixVec = VecStorage; +pub type MatrixVec = VecStorage; -impl VecStorage { +impl VecStorage { /// Creates a new dynamic matrix data storage from the given vector and shape. #[inline] - pub fn new(nrows: R, ncols: C, data: Vec) -> Self { + pub fn new(nrows: R, ncols: C, data: Vec) -> Self { assert!( nrows.value() * ncols.value() == data.len(), "Data storage buffer dimension mismatch." @@ -48,7 +48,7 @@ impl VecStorage { /// The underlying data storage. #[inline] - pub fn as_vec(&self) -> &Vec { + pub fn as_vec(&self) -> &Vec { &self.data } @@ -57,7 +57,7 @@ impl VecStorage { /// This is unsafe because this may cause UB if the size of the vector is changed /// by the user. #[inline] - pub unsafe fn as_vec_mut(&mut self) -> &mut Vec { + pub unsafe fn as_vec_mut(&mut self) -> &mut Vec { &mut self.data } @@ -66,7 +66,7 @@ impl VecStorage { /// If `sz` is larger than the current size, additional elements are uninitialized. /// If `sz` is smaller than the current size, additional elements are truncated. #[inline] - pub unsafe fn resize(mut self, sz: usize) -> Vec { + pub unsafe fn resize(mut self, sz: usize) -> Vec { let len = self.len(); if sz < len { @@ -93,8 +93,8 @@ impl VecStorage { } } -impl Into> for VecStorage { - fn into(self) -> Vec { +impl Into> for VecStorage { + fn into(self) -> Vec { self.data } } @@ -105,15 +105,15 @@ impl Into> for VecStorage { * Dynamic − Dynamic * */ -unsafe impl Storage for VecStorage +unsafe impl Storage for VecStorage where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { type RStride = U1; type CStride = Dynamic; #[inline] - fn ptr(&self) -> *const N { + fn ptr(&self) -> *const T { self.data.as_ptr() } @@ -133,36 +133,36 @@ where } #[inline] - fn into_owned(self) -> Owned + fn into_owned(self) -> Owned where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { self } #[inline] - fn clone_owned(&self) -> Owned + fn clone_owned(&self) -> Owned where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { self.clone() } #[inline] - fn as_slice(&self) -> &[N] { + fn as_slice(&self) -> &[T] { &self.data } } -unsafe impl Storage for VecStorage +unsafe impl Storage for VecStorage where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { type RStride = U1; type CStride = R; #[inline] - fn ptr(&self) -> *const N { + fn ptr(&self) -> *const T { self.data.as_ptr() } @@ -182,23 +182,23 @@ where } #[inline] - fn into_owned(self) -> Owned + fn into_owned(self) -> Owned where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { self } #[inline] - fn clone_owned(&self) -> Owned + fn clone_owned(&self) -> Owned where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { self.clone() } #[inline] - fn as_slice(&self) -> &[N] { + fn as_slice(&self) -> &[T] { &self.data } } @@ -208,38 +208,38 @@ where * StorageMut, ContiguousStorage. * */ -unsafe impl StorageMut for VecStorage +unsafe impl StorageMut for VecStorage where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { #[inline] - fn ptr_mut(&mut self) -> *mut N { + fn ptr_mut(&mut self) -> *mut T { self.data.as_mut_ptr() } #[inline] - fn as_mut_slice(&mut self) -> &mut [N] { + fn as_mut_slice(&mut self) -> &mut [T] { &mut self.data[..] } } -unsafe impl ContiguousStorage for VecStorage where - DefaultAllocator: Allocator +unsafe impl ContiguousStorage for VecStorage where + DefaultAllocator: Allocator { } -unsafe impl ContiguousStorageMut for VecStorage where - DefaultAllocator: Allocator +unsafe impl ContiguousStorageMut for VecStorage where + DefaultAllocator: Allocator { } -impl ReshapableStorage for VecStorage +impl ReshapableStorage for VecStorage where - N: Scalar, + T: Scalar, C1: Dim, C2: Dim, { - type Output = VecStorage; + type Output = VecStorage; fn reshape_generic(self, nrows: Dynamic, ncols: C2) -> Self::Output { assert_eq!(nrows.value() * ncols.value(), self.data.len()); @@ -251,13 +251,13 @@ where } } -impl ReshapableStorage for VecStorage +impl ReshapableStorage for VecStorage where - N: Scalar, + T: Scalar, C1: Dim, R2: DimName, { - type Output = VecStorage; + type Output = VecStorage; fn reshape_generic(self, nrows: R2, ncols: Dynamic) -> Self::Output { assert_eq!(nrows.value() * ncols.value(), self.data.len()); @@ -269,28 +269,28 @@ where } } -unsafe impl StorageMut for VecStorage +unsafe impl StorageMut for VecStorage where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { #[inline] - fn ptr_mut(&mut self) -> *mut N { + fn ptr_mut(&mut self) -> *mut T { self.data.as_mut_ptr() } #[inline] - fn as_mut_slice(&mut self) -> &mut [N] { + fn as_mut_slice(&mut self) -> &mut [T] { &mut self.data[..] } } -impl ReshapableStorage for VecStorage +impl ReshapableStorage for VecStorage where - N: Scalar, + T: Scalar, R1: DimName, C2: Dim, { - type Output = VecStorage; + type Output = VecStorage; fn reshape_generic(self, nrows: Dynamic, ncols: C2) -> Self::Output { assert_eq!(nrows.value() * ncols.value(), self.data.len()); @@ -302,13 +302,13 @@ where } } -impl ReshapableStorage for VecStorage +impl ReshapableStorage for VecStorage where - N: Scalar, + T: Scalar, R1: DimName, R2: DimName, { - type Output = VecStorage; + type Output = VecStorage; fn reshape_generic(self, nrows: R2, ncols: Dynamic) -> Self::Output { assert_eq!(nrows.value() * ncols.value(), self.data.len()); @@ -321,7 +321,7 @@ where } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for VecStorage { +impl Abomonation for VecStorage { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.data.entomb(writer) } @@ -335,17 +335,17 @@ impl Abomonation for VecStorage { } } -unsafe impl ContiguousStorage for VecStorage where - DefaultAllocator: Allocator +unsafe impl ContiguousStorage for VecStorage where + DefaultAllocator: Allocator { } -unsafe impl ContiguousStorageMut for VecStorage where - DefaultAllocator: Allocator +unsafe impl ContiguousStorageMut for VecStorage where + DefaultAllocator: Allocator { } -impl Extend for VecStorage { +impl Extend for VecStorage { /// Extends the number of columns of the `VecStorage` with elements /// from the given iterator. /// @@ -353,7 +353,7 @@ impl Extend for VecStorage { /// This function panics if the number of elements yielded by the /// given iterator is not a multiple of the number of rows of the /// `VecStorage`. - fn extend>(&mut self, iter: I) { + fn extend>(&mut self, iter: I) { self.data.extend(iter); self.ncols = Dynamic::new(self.data.len() / self.nrows.value()); assert!(self.data.len() % self.nrows.value() == 0, @@ -361,7 +361,7 @@ impl Extend for VecStorage { } } -impl<'a, N: 'a + Copy, R: Dim> Extend<&'a N> for VecStorage { +impl<'a, T: 'a + Copy, R: Dim> Extend<&'a T> for VecStorage { /// Extends the number of columns of the `VecStorage` with elements /// from the given iterator. /// @@ -369,17 +369,17 @@ impl<'a, N: 'a + Copy, R: Dim> Extend<&'a N> for VecStorage { /// This function panics if the number of elements yielded by the /// given iterator is not a multiple of the number of rows of the /// `VecStorage`. - fn extend>(&mut self, iter: I) { + fn extend>(&mut self, iter: I) { self.extend(iter.into_iter().copied()) } } -impl Extend> for VecStorage +impl Extend> for VecStorage where - N: Scalar, + T: Scalar, R: Dim, RV: Dim, - SV: Storage, + SV: Storage, ShapeConstraint: SameNumberOfRows, { /// Extends the number of columns of the `VecStorage` with vectors @@ -389,7 +389,7 @@ where /// This function panics if the number of rows of each `Vector` /// yielded by the iterator is not equal to the number of rows /// of this `VecStorage`. - fn extend>>(&mut self, iter: I) { + fn extend>>(&mut self, iter: I) { let nrows = self.nrows.value(); let iter = iter.into_iter(); let (lower, _upper) = iter.size_hint(); @@ -402,10 +402,10 @@ where } } -impl Extend for VecStorage { +impl Extend for VecStorage { /// Extends the number of rows of the `VecStorage` with elements /// from the given iterator. - fn extend>(&mut self, iter: I) { + fn extend>(&mut self, iter: I) { self.data.extend(iter); self.nrows = Dynamic::new(self.data.len()); } diff --git a/src/debug/random_orthogonal.rs b/src/debug/random_orthogonal.rs index fc740dc2..c9684238 100644 --- a/src/debug/random_orthogonal.rs +++ b/src/debug/random_orthogonal.rs @@ -4,38 +4,38 @@ use crate::base::storage::Owned; use quickcheck::{Arbitrary, Gen}; use crate::base::allocator::Allocator; -use crate::base::dimension::{Dim, Dynamic, U2}; +use crate::base::dimension::{Dim, Dynamic}; use crate::base::Scalar; -use crate::base::{DefaultAllocator, MatrixN}; +use crate::base::{DefaultAllocator, OMatrix}; use crate::linalg::givens::GivensRotation; use simba::scalar::ComplexField; /// A random orthogonal matrix. #[derive(Clone, Debug)] -pub struct RandomOrthogonal +pub struct RandomOrthogonal where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - m: MatrixN, + m: OMatrix, } -impl RandomOrthogonal +impl RandomOrthogonal where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { /// Retrieve the generated matrix. - pub fn unwrap(self) -> MatrixN { + pub fn unwrap(self) -> OMatrix { self.m } /// Creates a new random orthogonal matrix from its dimension and a random reals generators. - pub fn new N>(dim: D, mut rand: Rand) -> Self { - let mut res = MatrixN::identity_generic(dim, dim); + pub fn new T>(dim: D, mut rand: Rand) -> Self { + let mut res = OMatrix::identity_generic(dim, dim); // Create an orthogonal matrix by composing random Givens rotations rotations. for i in 0..dim.value() - 1 { let rot = GivensRotation::new(rand(), rand()).0; - rot.rotate(&mut res.fixed_rows_mut::(i)); + rot.rotate(&mut res.fixed_rows_mut::<2>(i)); } RandomOrthogonal { m: res } @@ -43,13 +43,13 @@ where } #[cfg(feature = "arbitrary")] -impl Arbitrary for RandomOrthogonal +impl Arbitrary for RandomOrthogonal where - DefaultAllocator: Allocator, - Owned: Clone + Send, + DefaultAllocator: Allocator, + Owned: Clone + Send, { fn arbitrary(g: &mut Gen) -> Self { let dim = D::try_to_usize().unwrap_or(1 + usize::arbitrary(g) % 50); - Self::new(D::from_usize(dim), || N::arbitrary(g)) + Self::new(D::from_usize(dim), || T::arbitrary(g)) } } diff --git a/src/debug/random_sdp.rs b/src/debug/random_sdp.rs index fa2ef118..a915f2fc 100644 --- a/src/debug/random_sdp.rs +++ b/src/debug/random_sdp.rs @@ -6,38 +6,38 @@ use quickcheck::{Arbitrary, Gen}; use crate::base::allocator::Allocator; use crate::base::dimension::{Dim, Dynamic}; use crate::base::Scalar; -use crate::base::{DefaultAllocator, MatrixN}; +use crate::base::{DefaultAllocator, OMatrix}; use simba::scalar::ComplexField; use crate::debug::RandomOrthogonal; /// A random, well-conditioned, symmetric definite-positive matrix. #[derive(Clone, Debug)] -pub struct RandomSDP +pub struct RandomSDP where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - m: MatrixN, + m: OMatrix, } -impl RandomSDP +impl RandomSDP where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { /// Retrieve the generated matrix. - pub fn unwrap(self) -> MatrixN { + pub fn unwrap(self) -> OMatrix { self.m } /// Creates a new well conditioned symmetric definite-positive matrix from its dimension and a /// random reals generators. - pub fn new N>(dim: D, mut rand: Rand) -> Self { + pub fn new T>(dim: D, mut rand: Rand) -> Self { let mut m = RandomOrthogonal::new(dim, || rand()).unwrap(); let mt = m.adjoint(); for i in 0..dim.value() { let mut col = m.column_mut(i); - let eigenval = N::one() + N::from_real(rand().modulus()); + let eigenval = T::one() + T::from_real(rand().modulus()); col *= eigenval; } @@ -46,13 +46,13 @@ where } #[cfg(feature = "arbitrary")] -impl Arbitrary for RandomSDP +impl Arbitrary for RandomSDP where - DefaultAllocator: Allocator, - Owned: Clone + Send, + DefaultAllocator: Allocator, + Owned: Clone + Send, { fn arbitrary(g: &mut Gen) -> Self { let dim = D::try_to_usize().unwrap_or(1 + usize::arbitrary(g) % 50); - Self::new(D::from_usize(dim), || N::arbitrary(g)) + Self::new(D::from_usize(dim), || T::arbitrary(g)) } } diff --git a/src/geometry/abstract_rotation.rs b/src/geometry/abstract_rotation.rs index 749d7473..4bbabea2 100644 --- a/src/geometry/abstract_rotation.rs +++ b/src/geometry/abstract_rotation.rs @@ -1,10 +1,10 @@ use crate::geometry::{Rotation, UnitComplex, UnitQuaternion}; -use crate::{CVectorN, Const, Point, Scalar, SimdRealField, Unit, VectorN}; +use crate::{Const, OVector, Point, SVector, Scalar, SimdRealField, Unit}; use simba::scalar::ClosedMul; /// Trait implemented by rotations that can be used inside of an `Isometry` or `Similarity`. -pub trait AbstractRotation: PartialEq + ClosedMul + Clone { +pub trait AbstractRotation: PartialEq + ClosedMul + Clone { /// The rotation identity. fn identity() -> Self; /// The rotation inverse. @@ -12,33 +12,22 @@ pub trait AbstractRotation: PartialEq + ClosedMul + C /// Change `self` to its inverse. fn inverse_mut(&mut self); /// Apply the rotation to the given vector. - fn transform_vector(&self, v: &CVectorN) -> CVectorN; - // where - // DefaultAllocator: Allocator; + fn transform_vector(&self, v: &SVector) -> SVector; /// Apply the rotation to the given point. - fn transform_point(&self, p: &Point) -> Point; - // where - // DefaultAllocator: Allocator; + fn transform_point(&self, p: &Point) -> Point; /// Apply the inverse rotation to the given vector. - fn inverse_transform_vector(&self, v: &VectorN>) -> VectorN>; - // where - // DefaultAllocator: Allocator; + fn inverse_transform_vector(&self, v: &OVector>) -> OVector>; /// Apply the inverse rotation to the given unit vector. - fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> -// where - // DefaultAllocator: Allocator, - { + fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { Unit::new_unchecked(self.inverse_transform_vector(&**v)) } /// Apply the inverse rotation to the given point. - fn inverse_transform_point(&self, p: &Point) -> Point; - // where - // DefaultAllocator: Allocator; + fn inverse_transform_point(&self, p: &Point) -> Point; } -impl AbstractRotation for Rotation +impl AbstractRotation for Rotation where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] fn identity() -> Self { @@ -56,49 +45,34 @@ where } #[inline] - fn transform_vector(&self, v: &CVectorN) -> CVectorN -// where - // DefaultAllocator: Allocator, - { + fn transform_vector(&self, v: &SVector) -> SVector { self * v } #[inline] - fn transform_point(&self, p: &Point) -> Point -// where - // DefaultAllocator: Allocator, - { + fn transform_point(&self, p: &Point) -> Point { self * p } #[inline] - fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN -// where - // DefaultAllocator: Allocator, - { + fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.inverse_transform_vector(v) } #[inline] - fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> -// where - // DefaultAllocator: Allocator, - { + fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { self.inverse_transform_unit_vector(v) } #[inline] - fn inverse_transform_point(&self, p: &Point) -> Point -// where - // DefaultAllocator: Allocator, - { + fn inverse_transform_point(&self, p: &Point) -> Point { self.inverse_transform_point(p) } } -impl AbstractRotation for UnitQuaternion +impl AbstractRotation for UnitQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] fn identity() -> Self { @@ -116,29 +90,29 @@ where } #[inline] - fn transform_vector(&self, v: &CVectorN) -> CVectorN { + fn transform_vector(&self, v: &SVector) -> SVector { self * v } #[inline] - fn transform_point(&self, p: &Point) -> Point { + fn transform_point(&self, p: &Point) -> Point { self * p } #[inline] - fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { + fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.inverse_transform_vector(v) } #[inline] - fn inverse_transform_point(&self, p: &Point) -> Point { + fn inverse_transform_point(&self, p: &Point) -> Point { self.inverse_transform_point(p) } } -impl AbstractRotation for UnitComplex +impl AbstractRotation for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] fn identity() -> Self { @@ -156,22 +130,22 @@ where } #[inline] - fn transform_vector(&self, v: &CVectorN) -> CVectorN { + fn transform_vector(&self, v: &SVector) -> SVector { self * v } #[inline] - fn transform_point(&self, p: &Point) -> Point { + fn transform_point(&self, p: &Point) -> Point { self * p } #[inline] - fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { + fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.inverse_transform_vector(v) } #[inline] - fn inverse_transform_point(&self, p: &Point) -> Point { + fn inverse_transform_point(&self, p: &Point) -> Point { self.inverse_transform_point(p) } } diff --git a/src/geometry/dual_quaternion.rs b/src/geometry/dual_quaternion.rs index b11e7364..471e08bf 100644 --- a/src/geometry/dual_quaternion.rs +++ b/src/geometry/dual_quaternion.rs @@ -1,6 +1,6 @@ use crate::{ - Isometry3, Matrix4, Normed, Point3, Quaternion, Scalar, SimdRealField, Translation3, Unit, - UnitQuaternion, Vector3, VectorN, Zero, U8, + Isometry3, Matrix4, Normed, OVector, Point3, Quaternion, Scalar, SimdRealField, Translation3, + Unit, UnitQuaternion, Vector3, Zero, U8, }; use approx::{AbsDiffEq, RelativeEq, UlpsEq}; #[cfg(feature = "serde-serialize")] @@ -36,14 +36,14 @@ use simba::scalar::{ClosedNeg, RealField}; /// See https://github.com/dimforge/nalgebra/issues/487 #[repr(C)] #[derive(Debug, Eq, PartialEq, Copy, Clone)] -pub struct DualQuaternion { +pub struct DualQuaternion { /// The real component of the quaternion - pub real: Quaternion, + pub real: Quaternion, /// The dual component of the quaternion - pub dual: Quaternion, + pub dual: Quaternion, } -impl Default for DualQuaternion { +impl Default for DualQuaternion { fn default() -> Self { Self { real: Quaternion::default(), @@ -52,9 +52,9 @@ impl Default for DualQuaternion { } } -impl DualQuaternion +impl DualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Normalizes this quaternion. /// @@ -93,7 +93,7 @@ where /// relative_eq!(dq.real.norm(), 1.0); /// ``` #[inline] - pub fn normalize_mut(&mut self) -> N { + pub fn normalize_mut(&mut self) -> T { let real_norm = self.real.norm(); self.real /= real_norm; self.dual /= real_norm; @@ -168,7 +168,7 @@ where #[must_use = "Did you mean to use try_inverse_mut()?"] pub fn try_inverse(&self) -> Option where - N: RealField, + T: RealField, { let mut res = *self; if res.try_inverse_mut() { @@ -200,7 +200,7 @@ where #[inline] pub fn try_inverse_mut(&mut self) -> bool where - N: RealField, + T: RealField, { let inverted = self.real.try_inverse_mut(); if inverted { @@ -232,15 +232,15 @@ where /// )); /// ``` #[inline] - pub fn lerp(&self, other: &Self, t: N) -> Self { - self * (N::one() - t) + other * t + pub fn lerp(&self, other: &Self, t: T) -> Self { + self * (T::one() - t) + other * t } } #[cfg(feature = "serde-serialize")] -impl Serialize for DualQuaternion +impl Serialize for DualQuaternion where - N: Serialize, + T: Serialize, { fn serialize(&self, serializer: S) -> Result<::Ok, ::Error> where @@ -251,17 +251,17 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N: SimdRealField> Deserialize<'a> for DualQuaternion +impl<'a, T: SimdRealField> Deserialize<'a> for DualQuaternion where - N: Deserialize<'a>, + T: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result where Des: Deserializer<'a>, { - type Dq = [N; 8]; + type Dq = [T; 8]; - let dq: Dq = Dq::::deserialize(deserializer)?; + let dq: Dq = Dq::::deserialize(deserializer)?; Ok(Self { real: Quaternion::new(dq[3], dq[0], dq[1], dq[2]), @@ -270,18 +270,18 @@ where } } -impl DualQuaternion { - fn to_vector(&self) -> VectorN { +impl DualQuaternion { + fn to_vector(&self) -> OVector { self.as_ref().clone().into() } } -impl> AbsDiffEq for DualQuaternion { - type Epsilon = N; +impl> AbsDiffEq for DualQuaternion { + type Epsilon = T; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -292,10 +292,10 @@ impl> AbsDiffEq for DualQuaternion { } } -impl> RelativeEq for DualQuaternion { +impl> RelativeEq for DualQuaternion { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -311,10 +311,10 @@ impl> RelativeEq for DualQuaternion { } } -impl> UlpsEq for DualQuaternion { +impl> UlpsEq for DualQuaternion { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] @@ -326,27 +326,27 @@ impl> UlpsEq for DualQuaternion { } /// A unit quaternions. May be used to represent a rotation followed by a translation. -pub type UnitDualQuaternion = Unit>; +pub type UnitDualQuaternion = Unit>; -impl PartialEq for UnitDualQuaternion { +impl PartialEq for UnitDualQuaternion { #[inline] fn eq(&self, rhs: &Self) -> bool { self.as_ref().eq(rhs.as_ref()) } } -impl Eq for UnitDualQuaternion {} +impl Eq for UnitDualQuaternion {} -impl Normed for DualQuaternion { - type Norm = N::SimdRealField; +impl Normed for DualQuaternion { + type Norm = T::SimdRealField; #[inline] - fn norm(&self) -> N::SimdRealField { + fn norm(&self) -> T::SimdRealField { self.real.norm() } #[inline] - fn norm_squared(&self) -> N::SimdRealField { + fn norm_squared(&self) -> T::SimdRealField { self.real.norm_squared() } @@ -363,9 +363,9 @@ impl Normed for DualQuaternion { } } -impl UnitDualQuaternion +impl UnitDualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// The underlying dual quaternion. /// @@ -381,7 +381,7 @@ where /// )); /// ``` #[inline] - pub fn dual_quaternion(&self) -> &DualQuaternion { + pub fn dual_quaternion(&self) -> &DualQuaternion { self.as_ref() } @@ -518,7 +518,7 @@ where /// ); /// ``` #[inline] - pub fn lerp(&self, other: &Self, t: N) -> DualQuaternion { + pub fn lerp(&self, other: &Self, t: T) -> DualQuaternion { self.as_ref().lerp(other.as_ref(), t) } @@ -546,7 +546,7 @@ where /// ), epsilon = 1.0e-6); /// ``` #[inline] - pub fn nlerp(&self, other: &Self, t: N) -> Self { + pub fn nlerp(&self, other: &Self, t: T) -> Self { let mut res = self.lerp(other, t); let _ = res.normalize_mut(); @@ -581,11 +581,11 @@ where /// ); /// assert_relative_eq!(dq.translation().vector.y, 3.0, epsilon = 1.0e-6); #[inline] - pub fn sclerp(&self, other: &Self, t: N) -> Self + pub fn sclerp(&self, other: &Self, t: T) -> Self where - N: RealField, + T: RealField, { - self.try_sclerp(other, t, N::default_epsilon()) + self.try_sclerp(other, t, T::default_epsilon()) .expect("DualQuaternion sclerp: ambiguous configuration.") } @@ -600,18 +600,18 @@ where /// * `epsilon`: the value below which the sinus of the angle separating both quaternion /// must be to return `None`. #[inline] - pub fn try_sclerp(&self, other: &Self, t: N, epsilon: N) -> Option + pub fn try_sclerp(&self, other: &Self, t: T, epsilon: T) -> Option where - N: RealField, + T: RealField, { - let two = N::one() + N::one(); - let half = N::one() / two; + let two = T::one() + T::one(); + let half = T::one() / two; // Invert one of the quaternions if we've got a longest-path // interpolation. let other = { let dot_product = self.as_ref().real.coords.dot(&other.as_ref().real.coords); - if dot_product < N::zero() { + if dot_product < T::zero() { -other.clone() } else { other.clone() @@ -620,11 +620,11 @@ where let difference = self.as_ref().conjugate() * other.as_ref(); let norm_squared = difference.real.vector().norm_squared(); - if relative_eq!(norm_squared, N::zero(), epsilon = epsilon) { + if relative_eq!(norm_squared, T::zero(), epsilon = epsilon) { return None; } - let inverse_norm_squared = N::one() / norm_squared; + let inverse_norm_squared = T::one() / norm_squared; let inverse_norm = inverse_norm_squared.sqrt(); let mut angle = two * difference.real.scalar().acos(); @@ -667,7 +667,7 @@ where /// ); /// ``` #[inline] - pub fn rotation(&self) -> UnitQuaternion { + pub fn rotation(&self) -> UnitQuaternion { Unit::new_unchecked(self.as_ref().real) } @@ -686,8 +686,8 @@ where /// ); /// ``` #[inline] - pub fn translation(&self) -> Translation3 { - let two = N::one() + N::one(); + pub fn translation(&self) -> Translation3 { + let two = T::one() + T::one(); Translation3::from( ((self.as_ref().dual * self.as_ref().real.conjugate()) * two) .vector() @@ -712,7 +712,7 @@ where /// assert_relative_eq!(iso.translation.vector, translation, epsilon = 1.0e-6); /// ``` #[inline] - pub fn to_isometry(&self) -> Isometry3 { + pub fn to_isometry(&self) -> Isometry3 { Isometry3::from_parts(self.translation(), self.rotation()) } @@ -735,7 +735,7 @@ where /// ); /// ``` #[inline] - pub fn transform_point(&self, pt: &Point3) -> Point3 { + pub fn transform_point(&self, pt: &Point3) -> Point3 { self * pt } @@ -758,7 +758,7 @@ where /// ); /// ``` #[inline] - pub fn transform_vector(&self, v: &Vector3) -> Vector3 { + pub fn transform_vector(&self, v: &Vector3) -> Vector3 { self * v } @@ -781,7 +781,7 @@ where /// ); /// ``` #[inline] - pub fn inverse_transform_point(&self, pt: &Point3) -> Point3 { + pub fn inverse_transform_point(&self, pt: &Point3) -> Point3 { self.inverse() * pt } @@ -805,7 +805,7 @@ where /// ); /// ``` #[inline] - pub fn inverse_transform_vector(&self, v: &Vector3) -> Vector3 { + pub fn inverse_transform_vector(&self, v: &Vector3) -> Vector3 { self.inverse() * v } @@ -830,14 +830,14 @@ where /// ); /// ``` #[inline] - pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { + pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { self.inverse() * v } } -impl UnitDualQuaternion +impl UnitDualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Converts this unit dual quaternion interpreted as an isometry /// into its equivalent homogeneous transformation matrix. @@ -857,18 +857,18 @@ where /// assert_relative_eq!(dq.to_homogeneous(), expected, epsilon = 1.0e-6); /// ``` #[inline] - pub fn to_homogeneous(&self) -> Matrix4 { + pub fn to_homogeneous(&self) -> Matrix4 { self.to_isometry().to_homogeneous() } } -impl Default for UnitDualQuaternion { +impl Default for UnitDualQuaternion { fn default() -> Self { Self::identity() } } -impl fmt::Display for UnitDualQuaternion { +impl fmt::Display for UnitDualQuaternion { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(axis) = self.rotation().axis() { let axis = axis.into_inner(); @@ -892,12 +892,12 @@ impl fmt::Display for UnitDualQuaternion { } } -impl> AbsDiffEq for UnitDualQuaternion { - type Epsilon = N; +impl> AbsDiffEq for UnitDualQuaternion { + type Epsilon = T; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -906,10 +906,10 @@ impl> AbsDiffEq for UnitDualQuaternion } } -impl> RelativeEq for UnitDualQuaternion { +impl> RelativeEq for UnitDualQuaternion { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -924,10 +924,10 @@ impl> RelativeEq for UnitDualQuaternion> UlpsEq for UnitDualQuaternion { +impl> UlpsEq for UnitDualQuaternion { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] diff --git a/src/geometry/dual_quaternion_construction.rs b/src/geometry/dual_quaternion_construction.rs index 047a9a2b..be274cf4 100644 --- a/src/geometry/dual_quaternion_construction.rs +++ b/src/geometry/dual_quaternion_construction.rs @@ -7,7 +7,7 @@ use num::{One, Zero}; use quickcheck::{Arbitrary, Gen}; use simba::scalar::SupersetOf; -impl DualQuaternion { +impl DualQuaternion { /// Creates a dual quaternion from its rotation and translation components. /// /// # Example @@ -20,7 +20,7 @@ impl DualQuaternion { /// assert_eq!(dq.real.w, 1.0); /// ``` #[inline] - pub fn from_real_and_dual(real: Quaternion, dual: Quaternion) -> Self { + pub fn from_real_and_dual(real: Quaternion, dual: Quaternion) -> Self { Self { real, dual } } @@ -43,11 +43,11 @@ impl DualQuaternion { #[inline] pub fn identity() -> Self where - N: SimdRealField, + T: SimdRealField, { Self::from_real_and_dual( - Quaternion::from_real(N::one()), - Quaternion::from_real(N::zero()), + Quaternion::from_real(T::one()), + Quaternion::from_real(T::zero()), ) } @@ -68,9 +68,9 @@ impl DualQuaternion { } } -impl DualQuaternion +impl DualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Creates a dual quaternion from only its real part, with no translation /// component. @@ -85,7 +85,7 @@ where /// assert_eq!(dq.dual.w, 0.0); /// ``` #[inline] - pub fn from_real(real: Quaternion) -> Self { + pub fn from_real(real: Quaternion) -> Self { Self { real, dual: Quaternion::zero(), @@ -93,9 +93,9 @@ where } } -impl One for DualQuaternion +impl One for DualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] fn one() -> Self { @@ -103,9 +103,9 @@ where } } -impl Zero for DualQuaternion +impl Zero for DualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] fn zero() -> Self { @@ -119,10 +119,10 @@ where } #[cfg(feature = "arbitrary")] -impl Arbitrary for DualQuaternion +impl Arbitrary for DualQuaternion where - N: SimdRealField + Arbitrary + Send, - N::Element: SimdRealField, + T: SimdRealField + Arbitrary + Send, + T::Element: SimdRealField, { #[inline] fn arbitrary(rng: &mut Gen) -> Self { @@ -130,7 +130,7 @@ where } } -impl UnitDualQuaternion { +impl UnitDualQuaternion { /// The unit dual quaternion multiplicative identity, which also represents /// the identity transformation as an isometry. /// @@ -164,9 +164,9 @@ impl UnitDualQuaternion { } } -impl UnitDualQuaternion +impl UnitDualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Return a dual quaternion representing the translation and orientation /// given by the provided rotation quaternion and translation vector. @@ -183,11 +183,11 @@ where /// assert_relative_eq!(dq * point, Point3::new(1.0, 0.0, 2.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn from_parts(translation: Translation3, rotation: UnitQuaternion) -> Self { - let half: N = crate::convert(0.5f64); + pub fn from_parts(translation: Translation3, rotation: UnitQuaternion) -> Self { + let half: T = crate::convert(0.5f64); UnitDualQuaternion::new_unchecked(DualQuaternion { real: rotation.clone().into_inner(), - dual: Quaternion::from_parts(N::zero(), translation.vector) + dual: Quaternion::from_parts(T::zero(), translation.vector) * rotation.clone().into_inner() * half, }) @@ -209,7 +209,7 @@ where /// assert_relative_eq!(dq * point, iso * point, epsilon = 1.0e-6); /// ``` #[inline] - pub fn from_isometry(isometry: &Isometry3) -> Self { + pub fn from_isometry(isometry: &Isometry3) -> Self { UnitDualQuaternion::from_parts(isometry.translation, isometry.rotation) } @@ -227,14 +227,14 @@ where /// assert_eq!(dq.as_ref().dual.norm(), 0.0); /// ``` #[inline] - pub fn from_rotation(rotation: UnitQuaternion) -> Self { + pub fn from_rotation(rotation: UnitQuaternion) -> Self { Self::new_unchecked(DualQuaternion::from_real(rotation.into_inner())) } } -impl One for UnitDualQuaternion +impl One for UnitDualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] fn one() -> Self { @@ -243,10 +243,10 @@ where } #[cfg(feature = "arbitrary")] -impl Arbitrary for UnitDualQuaternion +impl Arbitrary for UnitDualQuaternion where - N: SimdRealField + Arbitrary + Send, - N::Element: SimdRealField, + T: SimdRealField + Arbitrary + Send, + T::Element: SimdRealField, { #[inline] fn arbitrary(rng: &mut Gen) -> Self { diff --git a/src/geometry/dual_quaternion_conversion.rs b/src/geometry/dual_quaternion_conversion.rs index 26f3592e..94ef9e97 100644 --- a/src/geometry/dual_quaternion_conversion.rs +++ b/src/geometry/dual_quaternion_conversion.rs @@ -22,24 +22,24 @@ use crate::geometry::{ * UnitDualQuaternion -> DualQuaternion is already provided by: Unit -> T */ -impl SubsetOf> for DualQuaternion +impl SubsetOf> for DualQuaternion where - N1: SimdRealField, - N2: SimdRealField + SupersetOf, + T1: SimdRealField, + T2: SimdRealField + SupersetOf, { #[inline] - fn to_superset(&self) -> DualQuaternion { + fn to_superset(&self) -> DualQuaternion { DualQuaternion::from_real_and_dual(self.real.to_superset(), self.dual.to_superset()) } #[inline] - fn is_in_subset(dq: &DualQuaternion) -> bool { - crate::is_convertible::<_, Vector4>(&dq.real.coords) - && crate::is_convertible::<_, Vector4>(&dq.dual.coords) + fn is_in_subset(dq: &DualQuaternion) -> bool { + crate::is_convertible::<_, Vector4>(&dq.real.coords) + && crate::is_convertible::<_, Vector4>(&dq.dual.coords) } #[inline] - fn from_superset_unchecked(dq: &DualQuaternion) -> Self { + fn from_superset_unchecked(dq: &DualQuaternion) -> Self { DualQuaternion::from_real_and_dual( dq.real.to_subset_unchecked(), dq.dual.to_subset_unchecked(), @@ -47,141 +47,141 @@ where } } -impl SubsetOf> for UnitDualQuaternion +impl SubsetOf> for UnitDualQuaternion where - N1: SimdRealField, - N2: SimdRealField + SupersetOf, + T1: SimdRealField, + T2: SimdRealField + SupersetOf, { #[inline] - fn to_superset(&self) -> UnitDualQuaternion { + fn to_superset(&self) -> UnitDualQuaternion { UnitDualQuaternion::new_unchecked(self.as_ref().to_superset()) } #[inline] - fn is_in_subset(dq: &UnitDualQuaternion) -> bool { - crate::is_convertible::<_, DualQuaternion>(dq.as_ref()) + fn is_in_subset(dq: &UnitDualQuaternion) -> bool { + crate::is_convertible::<_, DualQuaternion>(dq.as_ref()) } #[inline] - fn from_superset_unchecked(dq: &UnitDualQuaternion) -> Self { + fn from_superset_unchecked(dq: &UnitDualQuaternion) -> Self { Self::new_unchecked(crate::convert_ref_unchecked(dq.as_ref())) } } -impl SubsetOf> for UnitDualQuaternion +impl SubsetOf> for UnitDualQuaternion where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, { #[inline] - fn to_superset(&self) -> Isometry3 { - let dq: UnitDualQuaternion = self.to_superset(); + fn to_superset(&self) -> Isometry3 { + let dq: UnitDualQuaternion = self.to_superset(); let iso = dq.to_isometry(); crate::convert_unchecked(iso) } #[inline] - fn is_in_subset(iso: &Isometry3) -> bool { - crate::is_convertible::<_, UnitQuaternion>(&iso.rotation) - && crate::is_convertible::<_, Translation3>(&iso.translation) + fn is_in_subset(iso: &Isometry3) -> bool { + crate::is_convertible::<_, UnitQuaternion>(&iso.rotation) + && crate::is_convertible::<_, Translation3>(&iso.translation) } #[inline] - fn from_superset_unchecked(iso: &Isometry3) -> Self { - let dq = UnitDualQuaternion::::from_isometry(iso); + fn from_superset_unchecked(iso: &Isometry3) -> Self { + let dq = UnitDualQuaternion::::from_isometry(iso); crate::convert_unchecked(dq) } } -impl SubsetOf> for UnitDualQuaternion +impl SubsetOf> for UnitDualQuaternion where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, { #[inline] - fn to_superset(&self) -> Similarity3 { - Similarity3::from_isometry(crate::convert_ref(self), N2::one()) + fn to_superset(&self) -> Similarity3 { + Similarity3::from_isometry(crate::convert_ref(self), T2::one()) } #[inline] - fn is_in_subset(sim: &Similarity3) -> bool { - sim.scaling() == N2::one() + fn is_in_subset(sim: &Similarity3) -> bool { + sim.scaling() == T2::one() } #[inline] - fn from_superset_unchecked(sim: &Similarity3) -> Self { + fn from_superset_unchecked(sim: &Similarity3) -> Self { crate::convert_ref_unchecked(&sim.isometry) } } -impl SubsetOf> for UnitDualQuaternion +impl SubsetOf> for UnitDualQuaternion where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, C: SuperTCategoryOf, { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl> SubsetOf> - for UnitDualQuaternion +impl> SubsetOf> + for UnitDualQuaternion { #[inline] - fn to_superset(&self) -> Matrix4 { + fn to_superset(&self) -> Matrix4 { self.to_homogeneous().to_superset() } #[inline] - fn is_in_subset(m: &Matrix4) -> bool { - crate::is_convertible::<_, Isometry3>(m) + fn is_in_subset(m: &Matrix4) -> bool { + crate::is_convertible::<_, Isometry3>(m) } #[inline] - fn from_superset_unchecked(m: &Matrix4) -> Self { - let iso: Isometry3 = crate::convert_ref_unchecked(m); + fn from_superset_unchecked(m: &Matrix4) -> Self { + let iso: Isometry3 = crate::convert_ref_unchecked(m); Self::from_isometry(&iso) } } -impl From> for Matrix4 +impl From> for Matrix4 where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn from(dq: UnitDualQuaternion) -> Self { + fn from(dq: UnitDualQuaternion) -> Self { dq.to_homogeneous() } } -impl From> for Isometry3 +impl From> for Isometry3 where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn from(dq: UnitDualQuaternion) -> Self { + fn from(dq: UnitDualQuaternion) -> Self { dq.to_isometry() } } -impl From> for UnitDualQuaternion +impl From> for UnitDualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn from(iso: Isometry3) -> Self { + fn from(iso: Isometry3) -> Self { Self::from_isometry(&iso) } } diff --git a/src/geometry/dual_quaternion_ops.rs b/src/geometry/dual_quaternion_ops.rs index 44d36b97..26a9f09f 100644 --- a/src/geometry/dual_quaternion_ops.rs +++ b/src/geometry/dual_quaternion_ops.rs @@ -55,22 +55,22 @@ use std::ops::{ Add, AddAssign, Div, DivAssign, Index, IndexMut, Mul, MulAssign, Neg, Sub, SubAssign, }; -impl AsRef<[N; 8]> for DualQuaternion { +impl AsRef<[T; 8]> for DualQuaternion { #[inline] - fn as_ref(&self) -> &[N; 8] { + fn as_ref(&self) -> &[T; 8] { unsafe { mem::transmute(self) } } } -impl AsMut<[N; 8]> for DualQuaternion { +impl AsMut<[T; 8]> for DualQuaternion { #[inline] - fn as_mut(&mut self) -> &mut [N; 8] { + fn as_mut(&mut self) -> &mut [T; 8] { unsafe { mem::transmute(self) } } } -impl Index for DualQuaternion { - type Output = N; +impl Index for DualQuaternion { + type Output = T; #[inline] fn index(&self, i: usize) -> &Self::Output { @@ -78,18 +78,18 @@ impl Index for DualQuaternion { } } -impl IndexMut for DualQuaternion { +impl IndexMut for DualQuaternion { #[inline] - fn index_mut(&mut self, i: usize) -> &mut N { + fn index_mut(&mut self, i: usize) -> &mut T { &mut self.as_mut()[i] } } -impl Neg for DualQuaternion +impl Neg for DualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { - type Output = DualQuaternion; + type Output = DualQuaternion; #[inline] fn neg(self) -> Self::Output { @@ -97,11 +97,11 @@ where } } -impl<'a, N: SimdRealField> Neg for &'a DualQuaternion +impl<'a, T: SimdRealField> Neg for &'a DualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { - type Output = DualQuaternion; + type Output = DualQuaternion; #[inline] fn neg(self) -> Self::Output { @@ -109,11 +109,11 @@ where } } -impl Neg for UnitDualQuaternion +impl Neg for UnitDualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { - type Output = UnitDualQuaternion; + type Output = UnitDualQuaternion; #[inline] fn neg(self) -> Self::Output { @@ -121,11 +121,11 @@ where } } -impl<'a, N: SimdRealField> Neg for &'a UnitDualQuaternion +impl<'a, T: SimdRealField> Neg for &'a UnitDualQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { - type Output = UnitDualQuaternion; + type Output = UnitDualQuaternion; #[inline] fn neg(self) -> Self::Output { @@ -139,10 +139,10 @@ macro_rules! dual_quaternion_op_impl( $(for $Storage: ident: $StoragesBound: ident $(<$($BoundParam: ty),*>)*),*; $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Result: ty $(=> $VDimA: ty, $VDimB: ty)*; $action: expr; $($lives: tt),*) => { - impl<$($lives ,)* N: SimdRealField $(, $Storage: $StoragesBound $(<$($BoundParam),*>)*)*> $Op<$Rhs> for $Lhs - where N::Element: SimdRealField, - DefaultAllocator: Allocator + - Allocator { + impl<$($lives ,)* T: SimdRealField $(, $Storage: $StoragesBound $(<$($BoundParam),*>)*)*> $Op<$Rhs> for $Lhs + where T::Element: SimdRealField, + DefaultAllocator: Allocator + + Allocator { type Output = $Result; #[inline] @@ -157,7 +157,7 @@ macro_rules! dual_quaternion_op_impl( dual_quaternion_op_impl!( Add, add; (U4, U1), (U4, U1); - self: &'a DualQuaternion, rhs: &'b DualQuaternion, Output = DualQuaternion; + self: &'a DualQuaternion, rhs: &'b DualQuaternion, Output = DualQuaternion; DualQuaternion::from_real_and_dual( &self.real + &rhs.real, &self.dual + &rhs.dual, @@ -167,7 +167,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Add, add; (U4, U1), (U4, U1); - self: &'a DualQuaternion, rhs: DualQuaternion, Output = DualQuaternion; + self: &'a DualQuaternion, rhs: DualQuaternion, Output = DualQuaternion; DualQuaternion::from_real_and_dual( &self.real + rhs.real, &self.dual + rhs.dual, @@ -177,7 +177,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Add, add; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: &'b DualQuaternion, Output = DualQuaternion; + self: DualQuaternion, rhs: &'b DualQuaternion, Output = DualQuaternion; DualQuaternion::from_real_and_dual( self.real + &rhs.real, self.dual + &rhs.dual, @@ -187,7 +187,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Add, add; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: DualQuaternion, Output = DualQuaternion; + self: DualQuaternion, rhs: DualQuaternion, Output = DualQuaternion; DualQuaternion::from_real_and_dual( self.real + rhs.real, self.dual + rhs.dual, @@ -197,7 +197,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Sub, sub; (U4, U1), (U4, U1); - self: &'a DualQuaternion, rhs: &'b DualQuaternion, Output = DualQuaternion; + self: &'a DualQuaternion, rhs: &'b DualQuaternion, Output = DualQuaternion; DualQuaternion::from_real_and_dual( &self.real - &rhs.real, &self.dual - &rhs.dual, @@ -207,7 +207,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Sub, sub; (U4, U1), (U4, U1); - self: &'a DualQuaternion, rhs: DualQuaternion, Output = DualQuaternion; + self: &'a DualQuaternion, rhs: DualQuaternion, Output = DualQuaternion; DualQuaternion::from_real_and_dual( &self.real - rhs.real, &self.dual - rhs.dual, @@ -217,7 +217,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Sub, sub; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: &'b DualQuaternion, Output = DualQuaternion; + self: DualQuaternion, rhs: &'b DualQuaternion, Output = DualQuaternion; DualQuaternion::from_real_and_dual( self.real - &rhs.real, self.dual - &rhs.dual, @@ -227,7 +227,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Sub, sub; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: DualQuaternion, Output = DualQuaternion; + self: DualQuaternion, rhs: DualQuaternion, Output = DualQuaternion; DualQuaternion::from_real_and_dual( self.real - rhs.real, self.dual - rhs.dual, @@ -237,7 +237,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: &'a DualQuaternion, rhs: &'b DualQuaternion, Output = DualQuaternion; + self: &'a DualQuaternion, rhs: &'b DualQuaternion, Output = DualQuaternion; DualQuaternion::from_real_and_dual( &self.real * &rhs.real, &self.real * &rhs.dual + &self.dual * &rhs.real, @@ -247,56 +247,56 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: &'a DualQuaternion, rhs: DualQuaternion, Output = DualQuaternion; + self: &'a DualQuaternion, rhs: DualQuaternion, Output = DualQuaternion; self * &rhs; 'a); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: &'b DualQuaternion, Output = DualQuaternion; + self: DualQuaternion, rhs: &'b DualQuaternion, Output = DualQuaternion; &self * rhs; 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: DualQuaternion, Output = DualQuaternion; + self: DualQuaternion, rhs: DualQuaternion, Output = DualQuaternion; &self * &rhs; ); // DualQuaternion × UnitDualQuaternion dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: &'a DualQuaternion, rhs: &'b UnitDualQuaternion, Output = DualQuaternion; + self: &'a DualQuaternion, rhs: &'b UnitDualQuaternion, Output = DualQuaternion; self * rhs.dual_quaternion(); 'a, 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: &'a DualQuaternion, rhs: UnitDualQuaternion, Output = DualQuaternion; + self: &'a DualQuaternion, rhs: UnitDualQuaternion, Output = DualQuaternion; self * rhs.dual_quaternion(); 'a); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: &'b UnitDualQuaternion, Output = DualQuaternion; + self: DualQuaternion, rhs: &'b UnitDualQuaternion, Output = DualQuaternion; self * rhs.dual_quaternion(); 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: UnitDualQuaternion, Output = DualQuaternion; + self: DualQuaternion, rhs: UnitDualQuaternion, Output = DualQuaternion; self * rhs.dual_quaternion();); // DualQuaternion ÷ UnitDualQuaternion dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: &'a DualQuaternion, rhs: &'b UnitDualQuaternion, Output = DualQuaternion; + self: &'a DualQuaternion, rhs: &'b UnitDualQuaternion, Output = DualQuaternion; #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse().dual_quaternion() }; 'a, 'b); @@ -304,7 +304,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: &'a DualQuaternion, rhs: UnitDualQuaternion, Output = DualQuaternion; + self: &'a DualQuaternion, rhs: UnitDualQuaternion, Output = DualQuaternion; #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse().dual_quaternion() }; 'a); @@ -312,7 +312,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: &'b UnitDualQuaternion, Output = DualQuaternion; + self: DualQuaternion, rhs: &'b UnitDualQuaternion, Output = DualQuaternion; #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse().dual_quaternion() }; 'b); @@ -320,7 +320,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: UnitDualQuaternion, Output = DualQuaternion; + self: DualQuaternion, rhs: UnitDualQuaternion, Output = DualQuaternion; #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse().dual_quaternion() };); @@ -328,199 +328,199 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: &'a UnitDualQuaternion, rhs: &'b UnitDualQuaternion, Output = UnitDualQuaternion; + self: &'a UnitDualQuaternion, rhs: &'b UnitDualQuaternion, Output = UnitDualQuaternion; UnitDualQuaternion::new_unchecked(self.as_ref() * rhs.as_ref()); 'a, 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: &'a UnitDualQuaternion, rhs: UnitDualQuaternion, Output = UnitDualQuaternion; + self: &'a UnitDualQuaternion, rhs: UnitDualQuaternion, Output = UnitDualQuaternion; self * &rhs; 'a); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: &'b UnitDualQuaternion, Output = UnitDualQuaternion; + self: UnitDualQuaternion, rhs: &'b UnitDualQuaternion, Output = UnitDualQuaternion; &self * rhs; 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: UnitDualQuaternion, Output = UnitDualQuaternion; + self: UnitDualQuaternion, rhs: UnitDualQuaternion, Output = UnitDualQuaternion; &self * &rhs; ); // UnitDualQuaternion ÷ UnitDualQuaternion dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: &'a UnitDualQuaternion, rhs: &'b UnitDualQuaternion, Output = UnitDualQuaternion; + self: &'a UnitDualQuaternion, rhs: &'b UnitDualQuaternion, Output = UnitDualQuaternion; #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; 'a, 'b); dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: &'a UnitDualQuaternion, rhs: UnitDualQuaternion, Output = UnitDualQuaternion; + self: &'a UnitDualQuaternion, rhs: UnitDualQuaternion, Output = UnitDualQuaternion; self / &rhs; 'a); dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: &'b UnitDualQuaternion, Output = UnitDualQuaternion; + self: UnitDualQuaternion, rhs: &'b UnitDualQuaternion, Output = UnitDualQuaternion; &self / rhs; 'b); dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: UnitDualQuaternion, Output = UnitDualQuaternion; + self: UnitDualQuaternion, rhs: UnitDualQuaternion, Output = UnitDualQuaternion; &self / &rhs; ); // UnitDualQuaternion × DualQuaternion dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: &'a UnitDualQuaternion, rhs: &'b DualQuaternion, - Output = DualQuaternion => U1, U4; + self: &'a UnitDualQuaternion, rhs: &'b DualQuaternion, + Output = DualQuaternion => U1, U4; self.dual_quaternion() * rhs; 'a, 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: &'a UnitDualQuaternion, rhs: DualQuaternion, - Output = DualQuaternion => U3, U3; + self: &'a UnitDualQuaternion, rhs: DualQuaternion, + Output = DualQuaternion => U3, U3; self.dual_quaternion() * rhs; 'a); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: &'b DualQuaternion, - Output = DualQuaternion => U3, U3; + self: UnitDualQuaternion, rhs: &'b DualQuaternion, + Output = DualQuaternion => U3, U3; self.dual_quaternion() * rhs; 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: DualQuaternion, - Output = DualQuaternion => U3, U3; + self: UnitDualQuaternion, rhs: DualQuaternion, + Output = DualQuaternion => U3, U3; self.dual_quaternion() * rhs;); // UnitDualQuaternion × UnitQuaternion dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: &'a UnitDualQuaternion, rhs: &'b UnitQuaternion, - Output = UnitDualQuaternion => U1, U4; - self * UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(rhs.into_inner())); + self: &'a UnitDualQuaternion, rhs: &'b UnitQuaternion, + Output = UnitDualQuaternion => U1, U4; + self * UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(rhs.into_inner())); 'a, 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: &'a UnitDualQuaternion, rhs: UnitQuaternion, - Output = UnitDualQuaternion => U3, U3; - self * UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(rhs.into_inner())); + self: &'a UnitDualQuaternion, rhs: UnitQuaternion, + Output = UnitDualQuaternion => U3, U3; + self * UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(rhs.into_inner())); 'a); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: &'b UnitQuaternion, - Output = UnitDualQuaternion => U3, U3; - self * UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(rhs.into_inner())); + self: UnitDualQuaternion, rhs: &'b UnitQuaternion, + Output = UnitDualQuaternion => U3, U3; + self * UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(rhs.into_inner())); 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: UnitQuaternion, - Output = UnitDualQuaternion => U3, U3; - self * UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(rhs.into_inner()));); + self: UnitDualQuaternion, rhs: UnitQuaternion, + Output = UnitDualQuaternion => U3, U3; + self * UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(rhs.into_inner()));); // UnitQuaternion × UnitDualQuaternion dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: &'a UnitQuaternion, rhs: &'b UnitDualQuaternion, - Output = UnitDualQuaternion => U1, U4; - UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(self.into_inner())) * rhs; + self: &'a UnitQuaternion, rhs: &'b UnitDualQuaternion, + Output = UnitDualQuaternion => U1, U4; + UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(self.into_inner())) * rhs; 'a, 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: &'a UnitQuaternion, rhs: UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U3; - UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(self.into_inner())) * rhs; + self: &'a UnitQuaternion, rhs: UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U3; + UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(self.into_inner())) * rhs; 'a); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: UnitQuaternion, rhs: &'b UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U3; - UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(self.into_inner())) * rhs; + self: UnitQuaternion, rhs: &'b UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U3; + UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(self.into_inner())) * rhs; 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U4, U1); - self: UnitQuaternion, rhs: UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U3; - UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(self.into_inner())) * rhs;); + self: UnitQuaternion, rhs: UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U3; + UnitDualQuaternion::::new_unchecked(DualQuaternion::from_real(self.into_inner())) * rhs;); // UnitDualQuaternion ÷ UnitQuaternion dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: &'a UnitDualQuaternion, rhs: &'b UnitQuaternion, - Output = UnitDualQuaternion => U1, U4; + self: &'a UnitDualQuaternion, rhs: &'b UnitQuaternion, + Output = UnitDualQuaternion => U1, U4; #[allow(clippy::suspicious_arithmetic_impl)] - { self * UnitDualQuaternion::::from_rotation(rhs.inverse()) }; + { self * UnitDualQuaternion::::from_rotation(rhs.inverse()) }; 'a, 'b); dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: &'a UnitDualQuaternion, rhs: UnitQuaternion, - Output = UnitDualQuaternion => U3, U3; + self: &'a UnitDualQuaternion, rhs: UnitQuaternion, + Output = UnitDualQuaternion => U3, U3; #[allow(clippy::suspicious_arithmetic_impl)] - { self * UnitDualQuaternion::::from_rotation(rhs.inverse()) }; + { self * UnitDualQuaternion::::from_rotation(rhs.inverse()) }; 'a); dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: &'b UnitQuaternion, - Output = UnitDualQuaternion => U3, U3; + self: UnitDualQuaternion, rhs: &'b UnitQuaternion, + Output = UnitDualQuaternion => U3, U3; #[allow(clippy::suspicious_arithmetic_impl)] - { self * UnitDualQuaternion::::from_rotation(rhs.inverse()) }; + { self * UnitDualQuaternion::::from_rotation(rhs.inverse()) }; 'b); dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: UnitQuaternion, - Output = UnitDualQuaternion => U3, U3; + self: UnitDualQuaternion, rhs: UnitQuaternion, + Output = UnitDualQuaternion => U3, U3; #[allow(clippy::suspicious_arithmetic_impl)] - { self * UnitDualQuaternion::::from_rotation(rhs.inverse()) };); + { self * UnitDualQuaternion::::from_rotation(rhs.inverse()) };); // UnitQuaternion ÷ UnitDualQuaternion dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: &'a UnitQuaternion, rhs: &'b UnitDualQuaternion, - Output = UnitDualQuaternion => U1, U4; + self: &'a UnitQuaternion, rhs: &'b UnitDualQuaternion, + Output = UnitDualQuaternion => U1, U4; #[allow(clippy::suspicious_arithmetic_impl)] { - UnitDualQuaternion::::new_unchecked( + UnitDualQuaternion::::new_unchecked( DualQuaternion::from_real(self.into_inner()) ) * rhs.inverse() }; 'a, 'b); @@ -528,11 +528,11 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: &'a UnitQuaternion, rhs: UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U3; + self: &'a UnitQuaternion, rhs: UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U3; #[allow(clippy::suspicious_arithmetic_impl)] { - UnitDualQuaternion::::new_unchecked( + UnitDualQuaternion::::new_unchecked( DualQuaternion::from_real(self.into_inner()) ) * rhs.inverse() }; 'a); @@ -540,11 +540,11 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: UnitQuaternion, rhs: &'b UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U3; + self: UnitQuaternion, rhs: &'b UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U3; #[allow(clippy::suspicious_arithmetic_impl)] { - UnitDualQuaternion::::new_unchecked( + UnitDualQuaternion::::new_unchecked( DualQuaternion::from_real(self.into_inner()) ) * rhs.inverse() }; 'b); @@ -552,11 +552,11 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Div, div; (U4, U1), (U4, U1); - self: UnitQuaternion, rhs: UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U3; + self: UnitQuaternion, rhs: UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U3; #[allow(clippy::suspicious_arithmetic_impl)] { - UnitDualQuaternion::::new_unchecked( + UnitDualQuaternion::::new_unchecked( DualQuaternion::from_real(self.into_inner()) ) * rhs.inverse() };); @@ -565,305 +565,305 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U3, U1); - self: &'a UnitDualQuaternion, rhs: &'b Translation3, - Output = UnitDualQuaternion => U3, U1; - self * UnitDualQuaternion::::from_parts(rhs.clone(), UnitQuaternion::identity()); + self: &'a UnitDualQuaternion, rhs: &'b Translation3, + Output = UnitDualQuaternion => U3, U1; + self * UnitDualQuaternion::::from_parts(rhs.clone(), UnitQuaternion::identity()); 'a, 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U3, U3); - self: &'a UnitDualQuaternion, rhs: Translation3, - Output = UnitDualQuaternion => U3, U1; - self * UnitDualQuaternion::::from_parts(rhs, UnitQuaternion::identity()); + self: &'a UnitDualQuaternion, rhs: Translation3, + Output = UnitDualQuaternion => U3, U1; + self * UnitDualQuaternion::::from_parts(rhs, UnitQuaternion::identity()); 'a); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U3, U3); - self: UnitDualQuaternion, rhs: &'b Translation3, - Output = UnitDualQuaternion => U3, U1; - self * UnitDualQuaternion::::from_parts(rhs.clone(), UnitQuaternion::identity()); + self: UnitDualQuaternion, rhs: &'b Translation3, + Output = UnitDualQuaternion => U3, U1; + self * UnitDualQuaternion::::from_parts(rhs.clone(), UnitQuaternion::identity()); 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U3, U3); - self: UnitDualQuaternion, rhs: Translation3, - Output = UnitDualQuaternion => U3, U1; - self * UnitDualQuaternion::::from_parts(rhs, UnitQuaternion::identity()); ); + self: UnitDualQuaternion, rhs: Translation3, + Output = UnitDualQuaternion => U3, U1; + self * UnitDualQuaternion::::from_parts(rhs, UnitQuaternion::identity()); ); // UnitDualQuaternion ÷ Translation3 dual_quaternion_op_impl!( Div, div; (U4, U1), (U3, U1); - self: &'a UnitDualQuaternion, rhs: &'b Translation3, - Output = UnitDualQuaternion => U3, U1; + self: &'a UnitDualQuaternion, rhs: &'b Translation3, + Output = UnitDualQuaternion => U3, U1; #[allow(clippy::suspicious_arithmetic_impl)] - { self * UnitDualQuaternion::::from_parts(rhs.inverse(), UnitQuaternion::identity()) }; + { self * UnitDualQuaternion::::from_parts(rhs.inverse(), UnitQuaternion::identity()) }; 'a, 'b); dual_quaternion_op_impl!( Div, div; (U4, U1), (U3, U3); - self: &'a UnitDualQuaternion, rhs: Translation3, - Output = UnitDualQuaternion => U3, U1; + self: &'a UnitDualQuaternion, rhs: Translation3, + Output = UnitDualQuaternion => U3, U1; #[allow(clippy::suspicious_arithmetic_impl)] - { self * UnitDualQuaternion::::from_parts(rhs.inverse(), UnitQuaternion::identity()) }; + { self * UnitDualQuaternion::::from_parts(rhs.inverse(), UnitQuaternion::identity()) }; 'a); dual_quaternion_op_impl!( Div, div; (U4, U1), (U3, U3); - self: UnitDualQuaternion, rhs: &'b Translation3, - Output = UnitDualQuaternion => U3, U1; + self: UnitDualQuaternion, rhs: &'b Translation3, + Output = UnitDualQuaternion => U3, U1; #[allow(clippy::suspicious_arithmetic_impl)] - { self * UnitDualQuaternion::::from_parts(rhs.inverse(), UnitQuaternion::identity()) }; + { self * UnitDualQuaternion::::from_parts(rhs.inverse(), UnitQuaternion::identity()) }; 'b); dual_quaternion_op_impl!( Div, div; (U4, U1), (U3, U3); - self: UnitDualQuaternion, rhs: Translation3, - Output = UnitDualQuaternion => U3, U1; + self: UnitDualQuaternion, rhs: Translation3, + Output = UnitDualQuaternion => U3, U1; #[allow(clippy::suspicious_arithmetic_impl)] - { self * UnitDualQuaternion::::from_parts(rhs.inverse(), UnitQuaternion::identity()) };); + { self * UnitDualQuaternion::::from_parts(rhs.inverse(), UnitQuaternion::identity()) };); // Translation3 × UnitDualQuaternion dual_quaternion_op_impl!( Mul, mul; (U3, U1), (U4, U1); - self: &'b Translation3, rhs: &'a UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) * rhs; + self: &'b Translation3, rhs: &'a UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) * rhs; 'a, 'b); dual_quaternion_op_impl!( Mul, mul; (U3, U1), (U4, U1); - self: &'a Translation3, rhs: UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) * rhs; + self: &'a Translation3, rhs: UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) * rhs; 'a); dual_quaternion_op_impl!( Mul, mul; (U3, U1), (U4, U1); - self: Translation3, rhs: &'b UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(self, UnitQuaternion::identity()) * rhs; + self: Translation3, rhs: &'b UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_parts(self, UnitQuaternion::identity()) * rhs; 'b); dual_quaternion_op_impl!( Mul, mul; (U3, U1), (U4, U1); - self: Translation3, rhs: UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(self, UnitQuaternion::identity()) * rhs;); + self: Translation3, rhs: UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_parts(self, UnitQuaternion::identity()) * rhs;); // Translation3 ÷ UnitDualQuaternion dual_quaternion_op_impl!( Div, div; (U3, U1), (U4, U1); - self: &'b Translation3, rhs: &'a UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) / rhs; + self: &'b Translation3, rhs: &'a UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) / rhs; 'a, 'b); dual_quaternion_op_impl!( Div, div; (U3, U1), (U4, U1); - self: &'a Translation3, rhs: UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) / rhs; + self: &'a Translation3, rhs: UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()) / rhs; 'a); dual_quaternion_op_impl!( Div, div; (U3, U1), (U4, U1); - self: Translation3, rhs: &'b UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(self, UnitQuaternion::identity()) / rhs; + self: Translation3, rhs: &'b UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_parts(self, UnitQuaternion::identity()) / rhs; 'b); dual_quaternion_op_impl!( Div, div; (U3, U1), (U4, U1); - self: Translation3, rhs: UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_parts(self, UnitQuaternion::identity()) / rhs;); + self: Translation3, rhs: UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_parts(self, UnitQuaternion::identity()) / rhs;); // UnitDualQuaternion × Isometry3 dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U3, U1); - self: &'a UnitDualQuaternion, rhs: &'b Isometry3, - Output = UnitDualQuaternion => U3, U1; - self * UnitDualQuaternion::::from_isometry(rhs); + self: &'a UnitDualQuaternion, rhs: &'b Isometry3, + Output = UnitDualQuaternion => U3, U1; + self * UnitDualQuaternion::::from_isometry(rhs); 'a, 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U3, U3); - self: &'a UnitDualQuaternion, rhs: Isometry3, - Output = UnitDualQuaternion => U3, U1; - self * UnitDualQuaternion::::from_isometry(&rhs); + self: &'a UnitDualQuaternion, rhs: Isometry3, + Output = UnitDualQuaternion => U3, U1; + self * UnitDualQuaternion::::from_isometry(&rhs); 'a); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U3, U3); - self: UnitDualQuaternion, rhs: &'b Isometry3, - Output = UnitDualQuaternion => U3, U1; - self * UnitDualQuaternion::::from_isometry(rhs); + self: UnitDualQuaternion, rhs: &'b Isometry3, + Output = UnitDualQuaternion => U3, U1; + self * UnitDualQuaternion::::from_isometry(rhs); 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U3, U3); - self: UnitDualQuaternion, rhs: Isometry3, - Output = UnitDualQuaternion => U3, U1; - self * UnitDualQuaternion::::from_isometry(&rhs); ); + self: UnitDualQuaternion, rhs: Isometry3, + Output = UnitDualQuaternion => U3, U1; + self * UnitDualQuaternion::::from_isometry(&rhs); ); // UnitDualQuaternion ÷ Isometry3 dual_quaternion_op_impl!( Div, div; (U4, U1), (U3, U1); - self: &'a UnitDualQuaternion, rhs: &'b Isometry3, - Output = UnitDualQuaternion => U3, U1; + self: &'a UnitDualQuaternion, rhs: &'b Isometry3, + Output = UnitDualQuaternion => U3, U1; // TODO: can we avoid the conversion to a rotation matrix? - self / UnitDualQuaternion::::from_isometry(rhs); + self / UnitDualQuaternion::::from_isometry(rhs); 'a, 'b); dual_quaternion_op_impl!( Div, div; (U4, U1), (U3, U3); - self: &'a UnitDualQuaternion, rhs: Isometry3, - Output = UnitDualQuaternion => U3, U1; - self / UnitDualQuaternion::::from_isometry(&rhs); + self: &'a UnitDualQuaternion, rhs: Isometry3, + Output = UnitDualQuaternion => U3, U1; + self / UnitDualQuaternion::::from_isometry(&rhs); 'a); dual_quaternion_op_impl!( Div, div; (U4, U1), (U3, U3); - self: UnitDualQuaternion, rhs: &'b Isometry3, - Output = UnitDualQuaternion => U3, U1; - self / UnitDualQuaternion::::from_isometry(rhs); + self: UnitDualQuaternion, rhs: &'b Isometry3, + Output = UnitDualQuaternion => U3, U1; + self / UnitDualQuaternion::::from_isometry(rhs); 'b); dual_quaternion_op_impl!( Div, div; (U4, U1), (U3, U3); - self: UnitDualQuaternion, rhs: Isometry3, - Output = UnitDualQuaternion => U3, U1; - self / UnitDualQuaternion::::from_isometry(&rhs); ); + self: UnitDualQuaternion, rhs: Isometry3, + Output = UnitDualQuaternion => U3, U1; + self / UnitDualQuaternion::::from_isometry(&rhs); ); // Isometry × UnitDualQuaternion dual_quaternion_op_impl!( Mul, mul; (U3, U1), (U4, U1); - self: &'a Isometry3, rhs: &'b UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_isometry(self) * rhs; + self: &'a Isometry3, rhs: &'b UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_isometry(self) * rhs; 'a, 'b); dual_quaternion_op_impl!( Mul, mul; (U3, U1), (U4, U1); - self: &'a Isometry3, rhs: UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_isometry(self) * rhs; + self: &'a Isometry3, rhs: UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_isometry(self) * rhs; 'a); dual_quaternion_op_impl!( Mul, mul; (U3, U1), (U4, U1); - self: Isometry3, rhs: &'b UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_isometry(&self) * rhs; + self: Isometry3, rhs: &'b UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_isometry(&self) * rhs; 'b); dual_quaternion_op_impl!( Mul, mul; (U3, U1), (U4, U1); - self: Isometry3, rhs: UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_isometry(&self) * rhs; ); + self: Isometry3, rhs: UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_isometry(&self) * rhs; ); // Isometry ÷ UnitDualQuaternion dual_quaternion_op_impl!( Div, div; (U3, U1), (U4, U1); - self: &'a Isometry3, rhs: &'b UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; + self: &'a Isometry3, rhs: &'b UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; // TODO: can we avoid the conversion from a rotation matrix? - UnitDualQuaternion::::from_isometry(self) / rhs; + UnitDualQuaternion::::from_isometry(self) / rhs; 'a, 'b); dual_quaternion_op_impl!( Div, div; (U3, U1), (U4, U1); - self: &'a Isometry3, rhs: UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_isometry(self) / rhs; + self: &'a Isometry3, rhs: UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_isometry(self) / rhs; 'a); dual_quaternion_op_impl!( Div, div; (U3, U1), (U4, U1); - self: Isometry3, rhs: &'b UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_isometry(&self) / rhs; + self: Isometry3, rhs: &'b UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_isometry(&self) / rhs; 'b); dual_quaternion_op_impl!( Div, div; (U3, U1), (U4, U1); - self: Isometry3, rhs: UnitDualQuaternion, - Output = UnitDualQuaternion => U3, U1; - UnitDualQuaternion::::from_isometry(&self) / rhs; ); + self: Isometry3, rhs: UnitDualQuaternion, + Output = UnitDualQuaternion => U3, U1; + UnitDualQuaternion::::from_isometry(&self) / rhs; ); // UnitDualQuaternion × Vector dual_quaternion_op_impl!( Mul, mul; - (U4, U1), (U3, U1) for SB: Storage ; - self: &'a UnitDualQuaternion, rhs: &'b Vector, - Output = Vector3 => U3, U1; + (U4, U1), (U3, U1) for SB: Storage ; + self: &'a UnitDualQuaternion, rhs: &'b Vector, + Output = Vector3 => U3, U1; Unit::new_unchecked(self.as_ref().real) * rhs; 'a, 'b); dual_quaternion_op_impl!( Mul, mul; - (U4, U1), (U3, U1) for SB: Storage ; - self: &'a UnitDualQuaternion, rhs: Vector, - Output = Vector3 => U3, U1; + (U4, U1), (U3, U1) for SB: Storage ; + self: &'a UnitDualQuaternion, rhs: Vector, + Output = Vector3 => U3, U1; self * &rhs; 'a); dual_quaternion_op_impl!( Mul, mul; - (U4, U1), (U3, U1) for SB: Storage ; - self: UnitDualQuaternion, rhs: &'b Vector, - Output = Vector3 => U3, U1; + (U4, U1), (U3, U1) for SB: Storage ; + self: UnitDualQuaternion, rhs: &'b Vector, + Output = Vector3 => U3, U1; &self * rhs; 'b); dual_quaternion_op_impl!( Mul, mul; - (U4, U1), (U3, U1) for SB: Storage ; - self: UnitDualQuaternion, rhs: Vector, - Output = Vector3 => U3, U1; + (U4, U1), (U3, U1) for SB: Storage ; + self: UnitDualQuaternion, rhs: Vector, + Output = Vector3 => U3, U1; &self * &rhs; ); // UnitDualQuaternion × Point dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U3, U1); - self: &'a UnitDualQuaternion, rhs: &'b Point3, - Output = Point3 => U3, U1; + self: &'a UnitDualQuaternion, rhs: &'b Point3, + Output = Point3 => U3, U1; { - let two: N = crate::convert(2.0f64); - let q_point = Quaternion::from_parts(N::zero(), rhs.coords.clone()); + let two: T = crate::convert(2.0f64); + let q_point = Quaternion::from_parts(T::zero(), rhs.coords.clone()); Point::from( ((self.as_ref().real * q_point + self.as_ref().dual * two) * self.as_ref().real.conjugate()) .vector() @@ -875,56 +875,56 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U3, U1); - self: &'a UnitDualQuaternion, rhs: Point3, - Output = Point3 => U3, U1; + self: &'a UnitDualQuaternion, rhs: Point3, + Output = Point3 => U3, U1; self * &rhs; 'a); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U3, U1); - self: UnitDualQuaternion, rhs: &'b Point3, - Output = Point3 => U3, U1; + self: UnitDualQuaternion, rhs: &'b Point3, + Output = Point3 => U3, U1; &self * rhs; 'b); dual_quaternion_op_impl!( Mul, mul; (U4, U1), (U3, U1); - self: UnitDualQuaternion, rhs: Point3, - Output = Point3 => U3, U1; + self: UnitDualQuaternion, rhs: Point3, + Output = Point3 => U3, U1; &self * &rhs; ); // UnitDualQuaternion × Unit dual_quaternion_op_impl!( Mul, mul; - (U4, U1), (U3, U1) for SB: Storage ; - self: &'a UnitDualQuaternion, rhs: &'b Unit>, - Output = Unit> => U3, U4; + (U4, U1), (U3, U1) for SB: Storage ; + self: &'a UnitDualQuaternion, rhs: &'b Unit>, + Output = Unit> => U3, U4; Unit::new_unchecked(self * rhs.as_ref()); 'a, 'b); dual_quaternion_op_impl!( Mul, mul; - (U4, U1), (U3, U1) for SB: Storage ; - self: &'a UnitDualQuaternion, rhs: Unit>, - Output = Unit> => U3, U4; + (U4, U1), (U3, U1) for SB: Storage ; + self: &'a UnitDualQuaternion, rhs: Unit>, + Output = Unit> => U3, U4; Unit::new_unchecked(self * rhs.into_inner()); 'a); dual_quaternion_op_impl!( Mul, mul; - (U4, U1), (U3, U1) for SB: Storage ; - self: UnitDualQuaternion, rhs: &'b Unit>, - Output = Unit> => U3, U4; + (U4, U1), (U3, U1) for SB: Storage ; + self: UnitDualQuaternion, rhs: &'b Unit>, + Output = Unit> => U3, U4; Unit::new_unchecked(self * rhs.as_ref()); 'b); dual_quaternion_op_impl!( Mul, mul; - (U4, U1), (U3, U1) for SB: Storage ; - self: UnitDualQuaternion, rhs: Unit>, - Output = Unit> => U3, U4; + (U4, U1), (U3, U1) for SB: Storage ; + self: UnitDualQuaternion, rhs: Unit>, + Output = Unit> => U3, U4; Unit::new_unchecked(self * rhs.into_inner()); ); macro_rules! left_scalar_mul_impl( @@ -962,10 +962,10 @@ macro_rules! dual_quaternion_op_impl( ($LhsRDim: ident, $LhsCDim: ident), ($RhsRDim: ident, $RhsCDim: ident); $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty $(=> $VDimA: ty, $VDimB: ty)*; $action: expr; $($lives: tt),*) => { - impl<$($lives ,)* N: SimdRealField> $OpAssign<$Rhs> for $Lhs - where N::Element: SimdRealField, - DefaultAllocator: Allocator + - Allocator { + impl<$($lives ,)* T: SimdRealField> $OpAssign<$Rhs> for $Lhs + where T::Element: SimdRealField, + DefaultAllocator: Allocator + + Allocator { #[inline] fn $op_assign(&mut $lhs, $rhs: $Rhs) { @@ -979,7 +979,7 @@ macro_rules! dual_quaternion_op_impl( dual_quaternion_op_impl!( AddAssign, add_assign; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: &'b DualQuaternion; + self: DualQuaternion, rhs: &'b DualQuaternion; { self.real += &rhs.real; self.dual += &rhs.dual; @@ -989,7 +989,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( AddAssign, add_assign; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: DualQuaternion; + self: DualQuaternion, rhs: DualQuaternion; { self.real += rhs.real; self.dual += rhs.dual; @@ -999,7 +999,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( SubAssign, sub_assign; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: &'b DualQuaternion; + self: DualQuaternion, rhs: &'b DualQuaternion; { self.real -= &rhs.real; self.dual -= &rhs.dual; @@ -1009,7 +1009,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( SubAssign, sub_assign; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: DualQuaternion; + self: DualQuaternion, rhs: DualQuaternion; { self.real -= rhs.real; self.dual -= rhs.dual; @@ -1019,7 +1019,7 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: &'b DualQuaternion; + self: DualQuaternion, rhs: &'b DualQuaternion; { let res = &*self * rhs; self.real.coords.copy_from(&res.real.coords); @@ -1030,14 +1030,14 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: DualQuaternion; + self: DualQuaternion, rhs: DualQuaternion; *self *= &rhs;); // DualQuaternion ×= UnitDualQuaternion dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: &'b UnitDualQuaternion; + self: DualQuaternion, rhs: &'b UnitDualQuaternion; { let res = &*self * rhs; self.real.coords.copy_from(&res.real.coords); @@ -1048,14 +1048,14 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: UnitDualQuaternion; + self: DualQuaternion, rhs: UnitDualQuaternion; *self *= &rhs; ); // DualQuaternion ÷= UnitDualQuaternion dual_quaternion_op_impl!( DivAssign, div_assign; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: &'b UnitDualQuaternion; + self: DualQuaternion, rhs: &'b UnitDualQuaternion; { let res = &*self / rhs; self.real.coords.copy_from(&res.real.coords); @@ -1066,14 +1066,14 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( DivAssign, div_assign; (U4, U1), (U4, U1); - self: DualQuaternion, rhs: UnitDualQuaternion; + self: DualQuaternion, rhs: UnitDualQuaternion; *self /= &rhs; ); // UnitDualQuaternion ×= UnitDualQuaternion dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: &'b UnitDualQuaternion; + self: UnitDualQuaternion, rhs: &'b UnitDualQuaternion; { let res = &*self * rhs; self.as_mut_unchecked().real.coords.copy_from(&res.as_ref().real.coords); @@ -1084,14 +1084,14 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: UnitDualQuaternion; + self: UnitDualQuaternion, rhs: UnitDualQuaternion; *self *= &rhs; ); // UnitDualQuaternion ÷= UnitDualQuaternion dual_quaternion_op_impl!( DivAssign, div_assign; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: &'b UnitDualQuaternion; + self: UnitDualQuaternion, rhs: &'b UnitDualQuaternion; { let res = &*self / rhs; self.as_mut_unchecked().real.coords.copy_from(&res.as_ref().real.coords); @@ -1102,14 +1102,14 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( DivAssign, div_assign; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: UnitDualQuaternion; + self: UnitDualQuaternion, rhs: UnitDualQuaternion; *self /= &rhs; ); // UnitDualQuaternion ×= UnitQuaternion dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: UnitQuaternion; + self: UnitDualQuaternion, rhs: UnitQuaternion; { let res = &*self * UnitDualQuaternion::from_rotation(rhs); self.as_mut_unchecked().real.coords.copy_from(&res.as_ref().real.coords); @@ -1119,14 +1119,14 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: &'b UnitQuaternion; + self: UnitDualQuaternion, rhs: &'b UnitQuaternion; *self *= rhs.clone(); 'b); // UnitDualQuaternion ÷= UnitQuaternion dual_quaternion_op_impl!( DivAssign, div_assign; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: &'b UnitQuaternion; + self: UnitDualQuaternion, rhs: &'b UnitQuaternion; #[allow(clippy::suspicious_op_assign_impl)] { let res = &*self * UnitDualQuaternion::from_rotation(rhs.inverse()); @@ -1138,14 +1138,14 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( DivAssign, div_assign; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: UnitQuaternion; + self: UnitDualQuaternion, rhs: UnitQuaternion; *self /= &rhs; ); // UnitDualQuaternion ×= Translation3 dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: Translation3; + self: UnitDualQuaternion, rhs: Translation3; { let res = &*self * UnitDualQuaternion::from_parts(rhs, UnitQuaternion::identity()); self.as_mut_unchecked().real.coords.copy_from(&res.as_ref().real.coords); @@ -1155,14 +1155,14 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: &'b Translation3; + self: UnitDualQuaternion, rhs: &'b Translation3; *self *= rhs.clone(); 'b); // UnitDualQuaternion ÷= Translation3 dual_quaternion_op_impl!( DivAssign, div_assign; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: &'b Translation3; + self: UnitDualQuaternion, rhs: &'b Translation3; #[allow(clippy::suspicious_op_assign_impl)] { let res = &*self * UnitDualQuaternion::from_parts(rhs.inverse(), UnitQuaternion::identity()); @@ -1174,14 +1174,14 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( DivAssign, div_assign; (U4, U1), (U4, U1); - self: UnitDualQuaternion, rhs: Translation3; + self: UnitDualQuaternion, rhs: Translation3; *self /= &rhs; ); // UnitDualQuaternion ×= Isometry3 dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U3, U1); - self: UnitDualQuaternion, rhs: &'b Isometry3 => U3, U1; + self: UnitDualQuaternion, rhs: &'b Isometry3 => U3, U1; { let res = &*self * rhs; self.as_mut_unchecked().real.coords.copy_from(&res.as_ref().real.coords); @@ -1192,14 +1192,14 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( MulAssign, mul_assign; (U4, U1), (U3, U1); - self: UnitDualQuaternion, rhs: Isometry3 => U3, U1; + self: UnitDualQuaternion, rhs: Isometry3 => U3, U1; *self *= &rhs; ); // UnitDualQuaternion ÷= Isometry3 dual_quaternion_op_impl!( DivAssign, div_assign; (U4, U1), (U3, U1); - self: UnitDualQuaternion, rhs: &'b Isometry3 => U3, U1; + self: UnitDualQuaternion, rhs: &'b Isometry3 => U3, U1; { let res = &*self / rhs; self.as_mut_unchecked().real.coords.copy_from(&res.as_ref().real.coords); @@ -1210,17 +1210,17 @@ dual_quaternion_op_impl!( dual_quaternion_op_impl!( DivAssign, div_assign; (U4, U1), (U3, U1); - self: UnitDualQuaternion, rhs: Isometry3 => U3, U1; + self: UnitDualQuaternion, rhs: Isometry3 => U3, U1; *self /= &rhs; ); macro_rules! scalar_op_impl( ($($Op: ident, $op: ident, $OpAssign: ident, $op_assign: ident);* $(;)*) => {$( - impl $Op for DualQuaternion - where N::Element: SimdRealField { - type Output = DualQuaternion; + impl $Op for DualQuaternion + where T::Element: SimdRealField { + type Output = DualQuaternion; #[inline] - fn $op(self, n: N) -> Self::Output { + fn $op(self, n: T) -> Self::Output { DualQuaternion::from_real_and_dual( self.real.$op(n), self.dual.$op(n) @@ -1228,12 +1228,12 @@ macro_rules! scalar_op_impl( } } - impl<'a, N: SimdRealField> $Op for &'a DualQuaternion - where N::Element: SimdRealField { - type Output = DualQuaternion; + impl<'a, T: SimdRealField> $Op for &'a DualQuaternion + where T::Element: SimdRealField { + type Output = DualQuaternion; #[inline] - fn $op(self, n: N) -> Self::Output { + fn $op(self, n: T) -> Self::Output { DualQuaternion::from_real_and_dual( self.real.$op(n), self.dual.$op(n) @@ -1241,11 +1241,11 @@ macro_rules! scalar_op_impl( } } - impl $OpAssign for DualQuaternion - where N::Element: SimdRealField { + impl $OpAssign for DualQuaternion + where T::Element: SimdRealField { #[inline] - fn $op_assign(&mut self, n: N) { + fn $op_assign(&mut self, n: T) { self.real.$op_assign(n); self.dual.$op_assign(n); } diff --git a/src/geometry/isometry.rs b/src/geometry/isometry.rs index 065800d4..5d79901f 100755 --- a/src/geometry/isometry.rs +++ b/src/geometry/isometry.rs @@ -16,7 +16,7 @@ use simba::simd::SimdRealField; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::storage::Owned; -use crate::base::{CVectorN, Const, DefaultAllocator, MatrixN, Scalar, Unit}; +use crate::base::{Const, DefaultAllocator, OMatrix, SVector, Scalar, Unit}; use crate::geometry::{AbstractRotation, Point, Translation}; /// A direct isometry, i.e., a rotation followed by a translation (aka. a rigid-body motion). @@ -59,31 +59,28 @@ use crate::geometry::{AbstractRotation, Point, Translation}; #[cfg_attr( feature = "serde-serialize", serde(bound(serialize = "R: Serialize, - DefaultAllocator: Allocator>, - Owned>: Serialize")) + DefaultAllocator: Allocator>, + Owned>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", serde(bound(deserialize = "R: Deserialize<'de>, - DefaultAllocator: Allocator>, - Owned>: Deserialize<'de>")) + DefaultAllocator: Allocator>, + Owned>: Deserialize<'de>")) )] -pub struct Isometry -// where -// DefaultAllocator: Allocator, -{ +pub struct Isometry { /// The pure rotational part of this isometry. pub rotation: R, /// The pure translational part of this isometry. - pub translation: Translation, + pub translation: Translation, } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Isometry +impl Abomonation for Isometry where - N: SimdRealField, + T: SimdRealField, R: Abomonation, - Translation: Abomonation, + Translation: Abomonation, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.rotation.entomb(writer)?; @@ -101,9 +98,9 @@ where } } -impl hash::Hash for Isometry +impl hash::Hash for Isometry where - Owned>: hash::Hash, + Owned>: hash::Hash, { fn hash(&self, state: &mut H) { self.translation.hash(state); @@ -111,15 +108,12 @@ where } } -impl Copy for Isometry where - Owned>: Copy +impl Copy for Isometry where + Owned>: Copy { } -impl Clone for Isometry -// where -// DefaultAllocator: Allocator, -{ +impl Clone for Isometry { #[inline] fn clone(&self) -> Self { Self { @@ -129,10 +123,7 @@ impl Clone for Isometry } } /// # From the translation and rotation parts -impl, const D: usize> Isometry -// where -// DefaultAllocator: Allocator, -{ +impl, const D: usize> Isometry { /// Creates a new isometry from its rotational and translational parts. /// /// # Example @@ -148,7 +139,7 @@ impl, const D: usize> Isometry /// assert_relative_eq!(iso * Point3::new(1.0, 2.0, 3.0), Point3::new(-1.0, 2.0, 0.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn from_parts(translation: Translation, rotation: R) -> Self { + pub fn from_parts(translation: Translation, rotation: R) -> Self { Self { rotation, translation, @@ -157,9 +148,9 @@ impl, const D: usize> Isometry } /// # Inversion and in-place composition -impl, const D: usize> Isometry +impl, const D: usize> Isometry where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Inverts `self`. /// @@ -216,7 +207,7 @@ where /// assert_eq!(iso1.inverse() * iso2, iso1.inv_mul(&iso2)); /// ``` #[inline] - pub fn inv_mul(&self, rhs: &Isometry) -> Self { + pub fn inv_mul(&self, rhs: &Isometry) -> Self { let inv_rot1 = self.rotation.inverse(); let tr_12 = rhs.translation.vector.clone() - self.translation.vector.clone(); Isometry::from_parts( @@ -240,7 +231,7 @@ where /// assert_eq!(iso.translation, Translation2::new(4.0, 6.0)); /// ``` #[inline] - pub fn append_translation_mut(&mut self, t: &Translation) { + pub fn append_translation_mut(&mut self, t: &Translation) { self.translation.vector += &t.vector } @@ -282,7 +273,7 @@ where /// assert_relative_eq!(iso * pt, Point2::new(-2.0, 0.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn append_rotation_wrt_point_mut(&mut self, r: &R, p: &Point) { + pub fn append_rotation_wrt_point_mut(&mut self, r: &R, p: &Point) { self.translation.vector -= &p.coords; self.append_rotation_mut(r); self.translation.vector += &p.coords; @@ -311,9 +302,9 @@ where } /// # Transformation of a vector or a point -impl, const D: usize> Isometry +impl, const D: usize> Isometry where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Transform the given point by this isometry. /// @@ -333,7 +324,7 @@ where /// assert_relative_eq!(transformed_point, Point3::new(3.0, 2.0, 2.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn transform_point(&self, pt: &Point) -> Point { + pub fn transform_point(&self, pt: &Point) -> Point { self * pt } @@ -356,7 +347,7 @@ where /// assert_relative_eq!(transformed_point, Vector3::new(3.0, 2.0, -1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn transform_vector(&self, v: &CVectorN) -> CVectorN { + pub fn transform_vector(&self, v: &SVector) -> SVector { self * v } @@ -378,7 +369,7 @@ where /// assert_relative_eq!(transformed_point, Point3::new(0.0, 2.0, 1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_point(&self, pt: &Point) -> Point { + pub fn inverse_transform_point(&self, pt: &Point) -> Point { self.rotation .inverse_transform_point(&(pt - &self.translation.vector)) } @@ -402,7 +393,7 @@ where /// assert_relative_eq!(transformed_point, Vector3::new(-3.0, 2.0, 1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { + pub fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.rotation.inverse_transform_vector(v) } @@ -425,7 +416,7 @@ where /// assert_relative_eq!(transformed_point, -Vector3::y_axis(), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { + pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { self.rotation.inverse_transform_unit_vector(v) } } @@ -435,10 +426,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). /// # Conversion to a matrix -impl Isometry -// where -// DefaultAllocator: Allocator, -{ +impl Isometry { /// Converts this isometry into its equivalent homogeneous transformation matrix. /// /// This is the same as `self.to_matrix()`. @@ -457,14 +445,14 @@ impl Isometry /// assert_relative_eq!(iso.to_homogeneous(), expected, epsilon = 1.0e-6); /// ``` #[inline] - pub fn to_homogeneous(&self) -> MatrixN, U1>> + pub fn to_homogeneous(&self) -> OMatrix, U1>, DimNameSum, U1>> where Const: DimNameAdd, - R: SubsetOf, U1>>>, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + R: SubsetOf, U1>, DimNameSum, U1>>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { - let mut res: MatrixN = crate::convert_ref(&self.rotation); - res.fixed_slice_mut::, U1>(0, D) + let mut res: OMatrix = crate::convert_ref(&self.rotation); + res.fixed_slice_mut::(0, D) .copy_from(&self.translation.vector); res @@ -488,24 +476,24 @@ impl Isometry /// assert_relative_eq!(iso.to_matrix(), expected, epsilon = 1.0e-6); /// ``` #[inline] - pub fn to_matrix(&self) -> MatrixN, U1>> + pub fn to_matrix(&self) -> OMatrix, U1>, DimNameSum, U1>> where Const: DimNameAdd, - R: SubsetOf, U1>>>, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + R: SubsetOf, U1>, DimNameSum, U1>>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { self.to_homogeneous() } } -impl Eq for Isometry where - R: AbstractRotation + Eq +impl Eq for Isometry where + R: AbstractRotation + Eq { } -impl PartialEq for Isometry +impl PartialEq for Isometry where - R: AbstractRotation + PartialEq, + R: AbstractRotation + PartialEq, { #[inline] fn eq(&self, right: &Self) -> bool { @@ -513,16 +501,16 @@ where } } -impl AbsDiffEq for Isometry +impl AbsDiffEq for Isometry where - R: AbstractRotation + AbsDiffEq, - N::Epsilon: Copy, + R: AbstractRotation + AbsDiffEq, + T::Epsilon: Copy, { - type Epsilon = N::Epsilon; + type Epsilon = T::Epsilon; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -532,14 +520,14 @@ where } } -impl RelativeEq for Isometry +impl RelativeEq for Isometry where - R: AbstractRotation + RelativeEq, - N::Epsilon: Copy, + R: AbstractRotation + RelativeEq, + T::Epsilon: Copy, { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -557,14 +545,14 @@ where } } -impl UlpsEq for Isometry +impl UlpsEq for Isometry where - R: AbstractRotation + UlpsEq, - N::Epsilon: Copy, + R: AbstractRotation + UlpsEq, + T::Epsilon: Copy, { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] @@ -580,7 +568,7 @@ where * Display * */ -impl fmt::Display for Isometry +impl fmt::Display for Isometry where R: fmt::Display, { diff --git a/src/geometry/isometry_alias.rs b/src/geometry/isometry_alias.rs index 3ac2db56..98206812 100644 --- a/src/geometry/isometry_alias.rs +++ b/src/geometry/isometry_alias.rs @@ -6,28 +6,28 @@ use crate::geometry::{Isometry, Rotation2, Rotation3, UnitComplex, UnitQuaternio /// /// Also known as a 2D rigid-body motion, or as an element of SE(2). -pub type Isometry2 = Isometry, 2>; +pub type Isometry2 = Isometry, 2>; /// A 3-dimensional direct isometry using a unit quaternion for its rotational part. /// /// **Because this is an alias, not all its methods are listed here. See the [`Isometry`](crate::Isometry) type too.** /// /// Also known as a rigid-body motion, or as an element of SE(3). -pub type Isometry3 = Isometry, 3>; +pub type Isometry3 = Isometry, 3>; /// A 2-dimensional direct isometry using a rotation matrix for its rotational part. /// /// **Because this is an alias, not all its methods are listed here. See the [`Isometry`](crate::Isometry) type too.** /// /// Also known as a rigid-body motion, or as an element of SE(2). -pub type IsometryMatrix2 = Isometry, 2>; +pub type IsometryMatrix2 = Isometry, 2>; /// A 3-dimensional direct isometry using a rotation matrix for its rotational part. /// /// **Because this is an alias, not all its methods are listed here. See the [`Isometry`](crate::Isometry) type too.** /// /// Also known as a rigid-body motion, or as an element of SE(3). -pub type IsometryMatrix3 = Isometry, 3>; +pub type IsometryMatrix3 = Isometry, 3>; // This tests that the types correctly implement `Copy`, without having to run tests // (when targeting no-std for example). diff --git a/src/geometry/isometry_construction.rs b/src/geometry/isometry_construction.rs index 60b5f6e2..e13bde29 100644 --- a/src/geometry/isometry_construction.rs +++ b/src/geometry/isometry_construction.rs @@ -16,14 +16,14 @@ use simba::simd::SimdRealField; use crate::base::{Vector2, Vector3}; use crate::{ - AbstractRotation, Const, Isometry, Isometry2, Isometry3, IsometryMatrix2, IsometryMatrix3, - Point, Point3, Rotation, Rotation3, Scalar, Translation, Translation2, Translation3, - UnitComplex, UnitQuaternion, + AbstractRotation, Isometry, Isometry2, Isometry3, IsometryMatrix2, IsometryMatrix3, Point, + Point3, Rotation, Rotation3, Scalar, Translation, Translation2, Translation3, UnitComplex, + UnitQuaternion, }; -impl, const D: usize> Isometry +impl, const D: usize> Isometry where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Creates a new identity isometry. /// @@ -62,15 +62,15 @@ where /// assert_relative_eq!(iso * Point2::new(1.0, 2.0), Point2::new(1.0, -2.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn rotation_wrt_point(r: R, p: Point) -> Self { + pub fn rotation_wrt_point(r: R, p: Point) -> Self { let shift = r.transform_vector(&-&p.coords); Self::from_parts(Translation::from(shift + p.coords), r) } } -impl, const D: usize> One for Isometry +impl, const D: usize> One for Isometry where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Creates a new identity isometry. #[inline] @@ -80,24 +80,24 @@ where } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - R: AbstractRotation, - Standard: Distribution + Distribution, + R: AbstractRotation, + Standard: Distribution + Distribution, { #[inline] - fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Isometry { + fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Isometry { Isometry::from_parts(rng.gen(), rng.gen()) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Isometry +impl Arbitrary for Isometry where - N: SimdRealField + Arbitrary + Send, - N::Element: SimdRealField, - R: AbstractRotation + Arbitrary + Send, - Owned>: Send, + T: SimdRealField + Arbitrary + Send, + T::Element: SimdRealField, + R: AbstractRotation + Arbitrary + Send, + Owned>: Send, { #[inline] fn arbitrary(rng: &mut Gen) -> Self { @@ -112,9 +112,9 @@ where */ /// # Construction from a 2D vector and/or a rotation angle -impl IsometryMatrix2 +impl IsometryMatrix2 where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Creates a new 2D isometry from a translation and a rotation angle. /// @@ -130,19 +130,19 @@ where /// assert_eq!(iso * Point2::new(3.0, 4.0), Point2::new(-3.0, 5.0)); /// ``` #[inline] - pub fn new(translation: Vector2, angle: N) -> Self { - Self::from_parts(Translation::from(translation), Rotation::::new(angle)) + pub fn new(translation: Vector2, angle: T) -> Self { + Self::from_parts(Translation::from(translation), Rotation::::new(angle)) } /// Creates a new isometry from the given translation coordinates. #[inline] - pub fn translation(x: N, y: N) -> Self { - Self::new(Vector2::new(x, y), N::zero()) + pub fn translation(x: T, y: T) -> Self { + Self::new(Vector2::new(x, y), T::zero()) } /// Creates a new isometry from the given rotation angle. #[inline] - pub fn rotation(angle: N) -> Self { + pub fn rotation(angle: T) -> Self { Self::new(Vector2::zeros(), angle) } @@ -163,9 +163,9 @@ where } } -impl Isometry2 +impl Isometry2 where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Creates a new 2D isometry from a translation and a rotation angle. /// @@ -181,7 +181,7 @@ where /// assert_eq!(iso * Point2::new(3.0, 4.0), Point2::new(-3.0, 5.0)); /// ``` #[inline] - pub fn new(translation: Vector2, angle: N) -> Self { + pub fn new(translation: Vector2, angle: T) -> Self { Self::from_parts( Translation::from(translation), UnitComplex::from_angle(angle), @@ -190,13 +190,13 @@ where /// Creates a new isometry from the given translation coordinates. #[inline] - pub fn translation(x: N, y: N) -> Self { + pub fn translation(x: T, y: T) -> Self { Self::from_parts(Translation2::new(x, y), UnitComplex::identity()) } /// Creates a new isometry from the given rotation angle. #[inline] - pub fn rotation(angle: N) -> Self { + pub fn rotation(angle: T) -> Self { Self::new(Vector2::zeros(), angle) } @@ -245,7 +245,7 @@ macro_rules! basic_isometry_construction_impl( /// assert_relative_eq!(iso * vec, Vector3::new(6.0, 5.0, -4.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn new(translation: Vector3, axisangle: Vector3) -> Self { + pub fn new(translation: Vector3, axisangle: Vector3) -> Self { Self::from_parts( Translation::from(translation), $RotId::<$($RotParams),*>::from_scaled_axis(axisangle)) @@ -253,13 +253,13 @@ macro_rules! basic_isometry_construction_impl( /// Creates a new isometry from the given translation coordinates. #[inline] - pub fn translation(x: N, y: N, z: N) -> Self { + pub fn translation(x: T, y: T, z: T) -> Self { Self::from_parts(Translation3::new(x, y, z), $RotId::identity()) } /// Creates a new isometry from the given rotation angle. #[inline] - pub fn rotation(axisangle: Vector3) -> Self { + pub fn rotation(axisangle: Vector3) -> Self { Self::new(Vector3::zeros(), axisangle) } } @@ -299,9 +299,9 @@ macro_rules! look_at_isometry_construction_impl( /// assert_relative_eq!(iso * Vector3::z(), Vector3::x()); /// ``` #[inline] - pub fn face_towards(eye: &Point3, - target: &Point3, - up: &Vector3) + pub fn face_towards(eye: &Point3, + target: &Point3, + up: &Vector3) -> Self { Self::from_parts( Translation::from(eye.coords.clone()), @@ -310,9 +310,9 @@ macro_rules! look_at_isometry_construction_impl( /// Deprecated: Use [Isometry::face_towards] instead. #[deprecated(note="renamed to `face_towards`")] - pub fn new_observer_frame(eye: &Point3, - target: &Point3, - up: &Vector3) + pub fn new_observer_frame(eye: &Point3, + target: &Point3, + up: &Vector3) -> Self { Self::face_towards(eye, target, up) } @@ -350,9 +350,9 @@ macro_rules! look_at_isometry_construction_impl( /// assert_relative_eq!(iso * Vector3::x(), -Vector3::z()); /// ``` #[inline] - pub fn look_at_rh(eye: &Point3, - target: &Point3, - up: &Vector3) + pub fn look_at_rh(eye: &Point3, + target: &Point3, + up: &Vector3) -> Self { let rotation = $RotId::look_at_rh(&(target - eye), up); let trans = &rotation * (-eye); @@ -393,9 +393,9 @@ macro_rules! look_at_isometry_construction_impl( /// assert_relative_eq!(iso * Vector3::x(), Vector3::z()); /// ``` #[inline] - pub fn look_at_lh(eye: &Point3, - target: &Point3, - up: &Vector3) + pub fn look_at_lh(eye: &Point3, + target: &Point3, + up: &Vector3) -> Self { let rotation = $RotId::look_at_lh(&(target - eye), up); let trans = &rotation * (-eye); @@ -406,11 +406,11 @@ macro_rules! look_at_isometry_construction_impl( ); /// # Construction from a 3D vector and/or an axis-angle -impl Isometry3 +impl Isometry3 where - N::Element: SimdRealField, + T::Element: SimdRealField, { - basic_isometry_construction_impl!(UnitQuaternion); + basic_isometry_construction_impl!(UnitQuaternion); /// Cast the components of `self` to another type. /// @@ -429,11 +429,11 @@ where } } -impl IsometryMatrix3 +impl IsometryMatrix3 where - N::Element: SimdRealField, + T::Element: SimdRealField, { - basic_isometry_construction_impl!(Rotation3); + basic_isometry_construction_impl!(Rotation3); /// Cast the components of `self` to another type. /// @@ -453,16 +453,16 @@ where } /// # Construction from a 3D eye position and target point -impl Isometry3 +impl Isometry3 where - N::Element: SimdRealField, + T::Element: SimdRealField, { - look_at_isometry_construction_impl!(UnitQuaternion); + look_at_isometry_construction_impl!(UnitQuaternion); } -impl IsometryMatrix3 +impl IsometryMatrix3 where - N::Element: SimdRealField, + T::Element: SimdRealField, { - look_at_isometry_construction_impl!(Rotation3); + look_at_isometry_construction_impl!(Rotation3); } diff --git a/src/geometry/isometry_conversion.rs b/src/geometry/isometry_conversion.rs index 235b120e..b8cc4568 100644 --- a/src/geometry/isometry_conversion.rs +++ b/src/geometry/isometry_conversion.rs @@ -3,7 +3,7 @@ use simba::simd::{PrimitiveSimdValue, SimdRealField, SimdValue}; use crate::base::allocator::Allocator; use crate::base::dimension::{DimMin, DimNameAdd, DimNameSum, U1}; -use crate::base::{Const, DefaultAllocator, MatrixN, Scalar}; +use crate::base::{Const, DefaultAllocator, OMatrix, Scalar}; use crate::geometry::{ AbstractRotation, Isometry, Isometry3, Similarity, SuperTCategoryOf, TAffine, Transform, @@ -21,26 +21,26 @@ use crate::geometry::{ * Isometry -> Matrix (homogeneous) */ -impl SubsetOf> for Isometry +impl SubsetOf> for Isometry where - N1: RealField, - N2: RealField + SupersetOf, - R1: AbstractRotation + SubsetOf, - R2: AbstractRotation, + T1: RealField, + T2: RealField + SupersetOf, + R1: AbstractRotation + SubsetOf, + R2: AbstractRotation, { #[inline] - fn to_superset(&self) -> Isometry { + fn to_superset(&self) -> Isometry { Isometry::from_parts(self.translation.to_superset(), self.rotation.to_superset()) } #[inline] - fn is_in_subset(iso: &Isometry) -> bool { - crate::is_convertible::<_, Translation>(&iso.translation) + fn is_in_subset(iso: &Isometry) -> bool { + crate::is_convertible::<_, Translation>(&iso.translation) && crate::is_convertible::<_, R1>(&iso.rotation) } #[inline] - fn from_superset_unchecked(iso: &Isometry) -> Self { + fn from_superset_unchecked(iso: &Isometry) -> Self { Isometry::from_parts( iso.translation.to_subset_unchecked(), iso.rotation.to_subset_unchecked(), @@ -48,124 +48,126 @@ where } } -impl SubsetOf> for Isometry3 +impl SubsetOf> for Isometry3 where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, { #[inline] - fn to_superset(&self) -> UnitDualQuaternion { - let dq = UnitDualQuaternion::::from_isometry(self); + fn to_superset(&self) -> UnitDualQuaternion { + let dq = UnitDualQuaternion::::from_isometry(self); dq.to_superset() } #[inline] - fn is_in_subset(dq: &UnitDualQuaternion) -> bool { - crate::is_convertible::<_, UnitQuaternion>(&dq.rotation()) - && crate::is_convertible::<_, Translation>(&dq.translation()) + fn is_in_subset(dq: &UnitDualQuaternion) -> bool { + crate::is_convertible::<_, UnitQuaternion>(&dq.rotation()) + && crate::is_convertible::<_, Translation>(&dq.translation()) } #[inline] - fn from_superset_unchecked(dq: &UnitDualQuaternion) -> Self { - let dq: UnitDualQuaternion = crate::convert_ref_unchecked(dq); + fn from_superset_unchecked(dq: &UnitDualQuaternion) -> Self { + let dq: UnitDualQuaternion = crate::convert_ref_unchecked(dq); dq.to_isometry() } } -impl SubsetOf> for Isometry +impl SubsetOf> for Isometry where - N1: RealField, - N2: RealField + SupersetOf, - R1: AbstractRotation + SubsetOf, - R2: AbstractRotation, + T1: RealField, + T2: RealField + SupersetOf, + R1: AbstractRotation + SubsetOf, + R2: AbstractRotation, { #[inline] - fn to_superset(&self) -> Similarity { - Similarity::from_isometry(self.to_superset(), N2::one()) + fn to_superset(&self) -> Similarity { + Similarity::from_isometry(self.to_superset(), T2::one()) } #[inline] - fn is_in_subset(sim: &Similarity) -> bool { - crate::is_convertible::<_, Isometry>(&sim.isometry) && sim.scaling() == N2::one() + fn is_in_subset(sim: &Similarity) -> bool { + crate::is_convertible::<_, Isometry>(&sim.isometry) && sim.scaling() == T2::one() } #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { + fn from_superset_unchecked(sim: &Similarity) -> Self { crate::convert_ref_unchecked(&sim.isometry) } } -impl SubsetOf> for Isometry +impl SubsetOf> for Isometry where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, C: SuperTCategoryOf, - R: AbstractRotation - + SubsetOf, U1>>> - + SubsetOf, U1>>>, + R: AbstractRotation + + SubsetOf, U1>, DimNameSum, U1>>> + + SubsetOf, U1>, DimNameSum, U1>>>, Const: DimNameAdd + DimMin, Output = Const>, // needed by .is_special_orthogonal() - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>>, - // + Allocator + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, + // + Allocator // + Allocator<(usize, usize), D> - // + Allocator - // + Allocator + // + Allocator + // + Allocator { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl SubsetOf, U1>>> - for Isometry +impl + SubsetOf, U1>, DimNameSum, U1>>> for Isometry where - N1: RealField, - N2: RealField + SupersetOf, - R: AbstractRotation - + SubsetOf, U1>>> - + SubsetOf, U1>>>, + T1: RealField, + T2: RealField + SupersetOf, + R: AbstractRotation + + SubsetOf, U1>, DimNameSum, U1>>> + + SubsetOf, U1>, DimNameSum, U1>>>, Const: DimNameAdd + DimMin, Output = Const>, // needed by .is_special_orthogonal() - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>>, // + Allocator<(usize, usize), D> - // + Allocator - // + Allocator - // + Allocator - // + Allocator + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, // + Allocator<(usize, usize), D> + // + Allocator + // + Allocator + // + Allocator + // + Allocator { #[inline] - fn to_superset(&self) -> MatrixN, U1>> { + fn to_superset(&self) -> OMatrix, U1>, DimNameSum, U1>> { self.to_homogeneous().to_superset() } #[inline] - fn is_in_subset(m: &MatrixN, U1>>) -> bool { - let rot = m.fixed_slice::, Const>(0, 0); - let bottom = m.fixed_slice::>(D, 0); + fn is_in_subset(m: &OMatrix, U1>, DimNameSum, U1>>) -> bool { + let rot = m.fixed_slice::(0, 0); + let bottom = m.fixed_slice::<1, D>(D, 0); // Scalar types agree. - m.iter().all(|e| SupersetOf::::is_in_subset(e)) && + m.iter().all(|e| SupersetOf::::is_in_subset(e)) && // The block part is a rotation. - rot.is_special_orthogonal(N2::default_epsilon() * crate::convert(100.0)) && + rot.is_special_orthogonal(T2::default_epsilon() * crate::convert(100.0)) && // The bottom row is (0, 0, ..., 1) - bottom.iter().all(|e| e.is_zero()) && m[(D, D)] == N2::one() + bottom.iter().all(|e| e.is_zero()) && m[(D, D)] == T2::one() } #[inline] - fn from_superset_unchecked(m: &MatrixN, U1>>) -> Self { - let t = m.fixed_slice::, U1>(0, D).into_owned(); + fn from_superset_unchecked( + m: &OMatrix, U1>, DimNameSum, U1>>, + ) -> Self { + let t = m.fixed_slice::(0, D).into_owned(); let t = Translation { vector: crate::convert_unchecked(t), }; @@ -174,41 +176,39 @@ where } } -impl, const D: usize> From> - for Isometry -// where -// DefaultAllocator: Allocator, +impl, const D: usize> From> + for Isometry { #[inline] - fn from(tra: Translation) -> Self { + fn from(tra: Translation) -> Self { Self::from_parts(tra, R::identity()) } } -impl From> - for MatrixN, U1>> +impl From> + for OMatrix, U1>, DimNameSum, U1>> where Const: DimNameAdd, - R: SubsetOf, U1>>>, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, // + Allocator, + R: SubsetOf, U1>, DimNameSum, U1>>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, // + Allocator, { #[inline] - fn from(iso: Isometry) -> Self { + fn from(iso: Isometry) -> Self { iso.to_homogeneous() } } -impl - From<[Isometry; 2]> for Isometry +impl + From<[Isometry; 2]> for Isometry where - N: From<[::Element; 2]>, - R: SimdValue + AbstractRotation + From<[::Element; 2]>, - R::Element: AbstractRotation, - N::Element: Scalar + Copy, + T: From<[::Element; 2]>, + R: SimdValue + AbstractRotation + From<[::Element; 2]>, + R::Element: AbstractRotation, + T::Element: Scalar + Copy, R::Element: Scalar + Copy, { #[inline] - fn from(arr: [Isometry; 2]) -> Self { + fn from(arr: [Isometry; 2]) -> Self { let tra = Translation::from([arr[0].translation.clone(), arr[1].translation.clone()]); let rot = R::from([arr[0].rotation, arr[0].rotation]); @@ -216,17 +216,17 @@ where } } -impl - From<[Isometry; 4]> for Isometry +impl + From<[Isometry; 4]> for Isometry where - N: From<[::Element; 4]>, - R: SimdValue + AbstractRotation + From<[::Element; 4]>, - R::Element: AbstractRotation, - N::Element: Scalar + Copy, + T: From<[::Element; 4]>, + R: SimdValue + AbstractRotation + From<[::Element; 4]>, + R::Element: AbstractRotation, + T::Element: Scalar + Copy, R::Element: Scalar + Copy, { #[inline] - fn from(arr: [Isometry; 4]) -> Self { + fn from(arr: [Isometry; 4]) -> Self { let tra = Translation::from([ arr[0].translation.clone(), arr[1].translation.clone(), @@ -244,17 +244,17 @@ where } } -impl - From<[Isometry; 8]> for Isometry +impl + From<[Isometry; 8]> for Isometry where - N: From<[::Element; 8]>, - R: SimdValue + AbstractRotation + From<[::Element; 8]>, - R::Element: AbstractRotation, - N::Element: Scalar + Copy, + T: From<[::Element; 8]>, + R: SimdValue + AbstractRotation + From<[::Element; 8]>, + R::Element: AbstractRotation, + T::Element: Scalar + Copy, R::Element: Scalar + Copy, { #[inline] - fn from(arr: [Isometry; 8]) -> Self { + fn from(arr: [Isometry; 8]) -> Self { let tra = Translation::from([ arr[0].translation.clone(), arr[1].translation.clone(), @@ -280,17 +280,17 @@ where } } -impl - From<[Isometry; 16]> for Isometry +impl + From<[Isometry; 16]> for Isometry where - N: From<[::Element; 16]>, - R: SimdValue + AbstractRotation + From<[::Element; 16]>, - R::Element: AbstractRotation, - N::Element: Scalar + Copy, + T: From<[::Element; 16]>, + R: SimdValue + AbstractRotation + From<[::Element; 16]>, + R::Element: AbstractRotation, + T::Element: Scalar + Copy, R::Element: Scalar + Copy, { #[inline] - fn from(arr: [Isometry; 16]) -> Self { + fn from(arr: [Isometry; 16]) -> Self { let tra = Translation::from([ arr[0].translation.clone(), arr[1].translation.clone(), diff --git a/src/geometry/isometry_interpolation.rs b/src/geometry/isometry_interpolation.rs index f58b4115..2ee5461a 100644 --- a/src/geometry/isometry_interpolation.rs +++ b/src/geometry/isometry_interpolation.rs @@ -1,7 +1,7 @@ use crate::{Isometry2, Isometry3, IsometryMatrix2, IsometryMatrix3, RealField, SimdRealField}; /// # Interpolation -impl Isometry3 { +impl Isometry3 { /// Interpolates between two isometries using a linear interpolation for the translation part, /// and a spherical interpolation for the rotation part. /// @@ -26,9 +26,9 @@ impl Isometry3 { /// assert_eq!(iso3.rotation.euler_angles(), (std::f32::consts::FRAC_PI_2, 0.0, 0.0)); /// ``` #[inline] - pub fn lerp_slerp(&self, other: &Self, t: N) -> Self + pub fn lerp_slerp(&self, other: &Self, t: T) -> Self where - N: RealField, + T: RealField, { let tr = self.translation.vector.lerp(&other.translation.vector, t); let rot = self.rotation.slerp(&other.rotation, t); @@ -59,9 +59,9 @@ impl Isometry3 { /// assert_eq!(iso3.rotation.euler_angles(), (std::f32::consts::FRAC_PI_2, 0.0, 0.0)); /// ``` #[inline] - pub fn try_lerp_slerp(&self, other: &Self, t: N, epsilon: N) -> Option + pub fn try_lerp_slerp(&self, other: &Self, t: T, epsilon: T) -> Option where - N: RealField, + T: RealField, { let tr = self.translation.vector.lerp(&other.translation.vector, t); let rot = self.rotation.try_slerp(&other.rotation, t, epsilon)?; @@ -69,7 +69,7 @@ impl Isometry3 { } } -impl IsometryMatrix3 { +impl IsometryMatrix3 { /// Interpolates between two isometries using a linear interpolation for the translation part, /// and a spherical interpolation for the rotation part. /// @@ -94,9 +94,9 @@ impl IsometryMatrix3 { /// assert_eq!(iso3.rotation.euler_angles(), (std::f32::consts::FRAC_PI_2, 0.0, 0.0)); /// ``` #[inline] - pub fn lerp_slerp(&self, other: &Self, t: N) -> Self + pub fn lerp_slerp(&self, other: &Self, t: T) -> Self where - N: RealField, + T: RealField, { let tr = self.translation.vector.lerp(&other.translation.vector, t); let rot = self.rotation.slerp(&other.rotation, t); @@ -127,9 +127,9 @@ impl IsometryMatrix3 { /// assert_eq!(iso3.rotation.euler_angles(), (std::f32::consts::FRAC_PI_2, 0.0, 0.0)); /// ``` #[inline] - pub fn try_lerp_slerp(&self, other: &Self, t: N, epsilon: N) -> Option + pub fn try_lerp_slerp(&self, other: &Self, t: T, epsilon: T) -> Option where - N: RealField, + T: RealField, { let tr = self.translation.vector.lerp(&other.translation.vector, t); let rot = self.rotation.try_slerp(&other.rotation, t, epsilon)?; @@ -137,7 +137,7 @@ impl IsometryMatrix3 { } } -impl Isometry2 { +impl Isometry2 { /// Interpolates between two isometries using a linear interpolation for the translation part, /// and a spherical interpolation for the rotation part. /// @@ -163,9 +163,9 @@ impl Isometry2 { /// assert_relative_eq!(iso3.rotation.angle(), std::f32::consts::FRAC_PI_2); /// ``` #[inline] - pub fn lerp_slerp(&self, other: &Self, t: N) -> Self + pub fn lerp_slerp(&self, other: &Self, t: T) -> Self where - N: RealField, + T: RealField, { let tr = self.translation.vector.lerp(&other.translation.vector, t); let rot = self.rotation.slerp(&other.rotation, t); @@ -173,7 +173,7 @@ impl Isometry2 { } } -impl IsometryMatrix2 { +impl IsometryMatrix2 { /// Interpolates between two isometries using a linear interpolation for the translation part, /// and a spherical interpolation for the rotation part. /// @@ -199,9 +199,9 @@ impl IsometryMatrix2 { /// assert_relative_eq!(iso3.rotation.angle(), std::f32::consts::FRAC_PI_2); /// ``` #[inline] - pub fn lerp_slerp(&self, other: &Self, t: N) -> Self + pub fn lerp_slerp(&self, other: &Self, t: T) -> Self where - N: RealField, + T: RealField, { let tr = self.translation.vector.lerp(&other.translation.vector, t); let rot = self.rotation.slerp(&other.rotation, t); diff --git a/src/geometry/isometry_ops.rs b/src/geometry/isometry_ops.rs index f6fff378..9d6928a2 100644 --- a/src/geometry/isometry_ops.rs +++ b/src/geometry/isometry_ops.rs @@ -6,7 +6,7 @@ use simba::simd::SimdRealField; use crate::base::allocator::Allocator; use crate::base::dimension::{U1, U2, U3}; -use crate::base::{CVectorN, Const, DefaultAllocator, Unit}; +use crate::base::{Const, DefaultAllocator, SVector, Unit}; use crate::Scalar; use crate::geometry::{ @@ -68,9 +68,9 @@ macro_rules! isometry_binop_impl( ($Op: ident, $op: ident; $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Output: ty; $action: expr; $($lives: tt),*) => { - impl<$($lives ,)* N: SimdRealField, R, const D: usize> $Op<$Rhs> for $Lhs - where N::Element: SimdRealField, - R: AbstractRotation, { + impl<$($lives ,)* T: SimdRealField, R, const D: usize> $Op<$Rhs> for $Lhs + where T::Element: SimdRealField, + R: AbstractRotation, { type Output = $Output; #[inline] @@ -115,18 +115,18 @@ macro_rules! isometry_binop_assign_impl_all( $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty; [val] => $action_val: expr; [ref] => $action_ref: expr;) => { - impl $OpAssign<$Rhs> for $Lhs - where N::Element: SimdRealField, - R: AbstractRotation { + impl $OpAssign<$Rhs> for $Lhs + where T::Element: SimdRealField, + R: AbstractRotation { #[inline] fn $op_assign(&mut $lhs, $rhs: $Rhs) { $action_val } } - impl<'b, N: SimdRealField, R, const D: usize> $OpAssign<&'b $Rhs> for $Lhs - where N::Element: SimdRealField, - R: AbstractRotation { + impl<'b, T: SimdRealField, R, const D: usize> $OpAssign<&'b $Rhs> for $Lhs + where T::Element: SimdRealField, + R: AbstractRotation { #[inline] fn $op_assign(&mut $lhs, $rhs: &'b $Rhs) { $action_ref @@ -139,7 +139,7 @@ macro_rules! isometry_binop_assign_impl_all( // Isometry ÷ Isometry isometry_binop_impl_all!( Mul, mul; - self: Isometry, rhs: Isometry, Output = Isometry; + self: Isometry, rhs: Isometry, Output = Isometry; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -154,7 +154,7 @@ isometry_binop_impl_all!( isometry_binop_impl_all!( Div, div; - self: Isometry, rhs: Isometry, Output = Isometry; + self: Isometry, rhs: Isometry, Output = Isometry; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -164,7 +164,7 @@ isometry_binop_impl_all!( // Isometry ×= Translation isometry_binop_assign_impl_all!( MulAssign, mul_assign; - self: Isometry, rhs: Translation; + self: Isometry, rhs: Translation; [val] => *self *= &rhs; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { let shift = self.rotation.transform_vector(&rhs.vector); @@ -176,7 +176,7 @@ isometry_binop_assign_impl_all!( // Isometry ÷= Isometry isometry_binop_assign_impl_all!( MulAssign, mul_assign; - self: Isometry, rhs: Isometry; + self: Isometry, rhs: Isometry; [val] => *self *= &rhs; [ref] => { let shift = self.rotation.transform_vector(&rhs.translation.vector); @@ -187,7 +187,7 @@ isometry_binop_assign_impl_all!( isometry_binop_assign_impl_all!( DivAssign, div_assign; - self: Isometry, rhs: Isometry; + self: Isometry, rhs: Isometry; [val] => *self /= &rhs; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; ); @@ -195,57 +195,57 @@ isometry_binop_assign_impl_all!( // Isometry ×= R // Isometry ÷= R md_assign_impl_all!( - MulAssign, mul_assign where N: SimdRealField for N::Element: SimdRealField; + MulAssign, mul_assign where T: SimdRealField for T::Element: SimdRealField; (Const, U1), (Const, Const) const D; for; where; - self: Isometry, D>, rhs: Rotation; + self: Isometry, D>, rhs: Rotation; [val] => self.rotation *= rhs; [ref] => self.rotation *= rhs.clone(); ); md_assign_impl_all!( - DivAssign, div_assign where N: SimdRealField for N::Element: SimdRealField; + DivAssign, div_assign where T: SimdRealField for T::Element: SimdRealField; (Const, U1), (Const, Const) const D; for; where; - self: Isometry, D>, rhs: Rotation; + self: Isometry, D>, rhs: Rotation; // TODO: don't invert explicitly? [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; ); md_assign_impl_all!( - MulAssign, mul_assign where N: SimdRealField for N::Element: SimdRealField; + MulAssign, mul_assign where T: SimdRealField for T::Element: SimdRealField; (U3, U3), (U3, U3) const; for; where; - self: Isometry, 3>, rhs: UnitQuaternion; + self: Isometry, 3>, rhs: UnitQuaternion; [val] => self.rotation *= rhs; [ref] => self.rotation *= *rhs; ); md_assign_impl_all!( - DivAssign, div_assign where N: SimdRealField for N::Element: SimdRealField; + DivAssign, div_assign where T: SimdRealField for T::Element: SimdRealField; (U3, U3), (U3, U3) const; for; where; - self: Isometry, 3>, rhs: UnitQuaternion; + self: Isometry, 3>, rhs: UnitQuaternion; // TODO: don't invert explicitly? [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; ); md_assign_impl_all!( - MulAssign, mul_assign where N: SimdRealField for N::Element: SimdRealField; + MulAssign, mul_assign where T: SimdRealField for T::Element: SimdRealField; (U2, U2), (U2, U2) const; for; where; - self: Isometry, 2>, rhs: UnitComplex; + self: Isometry, 2>, rhs: UnitComplex; [val] => self.rotation *= rhs; [ref] => self.rotation *= *rhs; ); md_assign_impl_all!( - DivAssign, div_assign where N: SimdRealField for N::Element: SimdRealField; + DivAssign, div_assign where T: SimdRealField for T::Element: SimdRealField; (U2, U2), (U2, U2) const; for; where; - self: Isometry, 2>, rhs: UnitComplex; + self: Isometry, 2>, rhs: UnitComplex; // TODO: don't invert explicitly? [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; @@ -254,7 +254,7 @@ md_assign_impl_all!( // Isometry × Point isometry_binop_impl_all!( Mul, mul; - self: Isometry, right: Point, Output = Point; + self: Isometry, right: Point, Output = Point; [val val] => self.translation * self.rotation.transform_point(&right); [ref val] => &self.translation * self.rotation.transform_point(&right); [val ref] => self.translation * self.rotation.transform_point(right); @@ -265,8 +265,8 @@ isometry_binop_impl_all!( isometry_binop_impl_all!( Mul, mul; // TODO: because of `transform_vector`, we cant use a generic storage type for the rhs vector, - // i.e., right: Vector where S: Storage. - self: Isometry, right: CVectorN, Output = CVectorN; + // i.e., right: Vector where S: Storage. + self: Isometry, right: SVector, Output = SVector; [val val] => self.rotation.transform_vector(&right); [ref val] => self.rotation.transform_vector(&right); [val ref] => self.rotation.transform_vector(right); @@ -277,8 +277,8 @@ isometry_binop_impl_all!( isometry_binop_impl_all!( Mul, mul; // TODO: because of `transform_vector`, we cant use a generic storage type for the rhs vector, - // i.e., right: Vector where S: Storage. - self: Isometry, right: Unit>, Output = Unit>; + // i.e., right: Vector where S: Storage. + self: Isometry, right: Unit>, Output = Unit>; [val val] => Unit::new_unchecked(self.rotation.transform_vector(right.as_ref())); [ref val] => Unit::new_unchecked(self.rotation.transform_vector(right.as_ref())); [val ref] => Unit::new_unchecked(self.rotation.transform_vector(right.as_ref())); @@ -288,7 +288,7 @@ isometry_binop_impl_all!( // Isometry × Translation isometry_binop_impl_all!( Mul, mul; - self: Isometry, right: Translation, Output = Isometry; + self: Isometry, right: Translation, Output = Isometry; [val val] => &self * &right; [ref val] => self * &right; [val ref] => &self * right; @@ -302,7 +302,7 @@ isometry_binop_impl_all!( // Translation × Isometry isometry_binop_impl_all!( Mul, mul; - self: Translation, right: Isometry, Output = Isometry; + self: Translation, right: Isometry, Output = Isometry; [val val] => Isometry::from_parts(self * right.translation, right.rotation); [ref val] => Isometry::from_parts(self * &right.translation, right.rotation); [val ref] => Isometry::from_parts(self * &right.translation, right.rotation.clone()); @@ -314,8 +314,8 @@ macro_rules! isometry_from_composition_impl( $($Dims: ident),*; $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Output: ty; $action: expr; $($lives: tt),*) => { - impl<$($lives ,)* N: SimdRealField $(, const $Dims: usize)*> $Op<$Rhs> for $Lhs - where N::Element: SimdRealField { + impl<$($lives ,)* T: SimdRealField $(, const $Dims: usize)*> $Op<$Rhs> for $Lhs + where T::Element: SimdRealField { type Output = $Output; #[inline] @@ -365,7 +365,7 @@ macro_rules! isometry_from_composition_impl_all( isometry_from_composition_impl_all!( Mul, mul; D; - self: Rotation, right: Translation, Output = Isometry, D>; + self: Rotation, right: Translation, Output = Isometry, D>; [val val] => Isometry::from_parts(Translation::from(&self * right.vector), self); [ref val] => Isometry::from_parts(Translation::from(self * right.vector), self.clone()); [val ref] => Isometry::from_parts(Translation::from(&self * &right.vector), self); @@ -376,8 +376,8 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Mul, mul; ; - self: UnitQuaternion, right: Translation, - Output = Isometry, 3>; + self: UnitQuaternion, right: Translation, + Output = Isometry, 3>; [val val] => Isometry::from_parts(Translation::from(&self * right.vector), self); [ref val] => Isometry::from_parts(Translation::from( self * right.vector), *self); [val ref] => Isometry::from_parts(Translation::from(&self * &right.vector), self); @@ -388,8 +388,8 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Mul, mul; D; - self: Isometry, D>, rhs: Rotation, - Output = Isometry, D>; + self: Isometry, D>, rhs: Rotation, + Output = Isometry, D>; [val val] => Isometry::from_parts(self.translation, self.rotation * rhs); [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs); // TODO: do not clone. [val ref] => Isometry::from_parts(self.translation, self.rotation * rhs.clone()); @@ -400,8 +400,8 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Mul, mul; D; - self: Rotation, right: Isometry, D>, - Output = Isometry, D>; + self: Rotation, right: Isometry, D>, + Output = Isometry, D>; [val val] => &self * &right; [ref val] => self * &right; [val ref] => &self * right; @@ -415,8 +415,8 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Div, div; D; - self: Isometry, D>, rhs: Rotation, - Output = Isometry, D>; + self: Isometry, D>, rhs: Rotation, + Output = Isometry, D>; [val val] => Isometry::from_parts(self.translation, self.rotation / rhs); [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs); // TODO: do not clone. [val ref] => Isometry::from_parts(self.translation, self.rotation / rhs.clone()); @@ -427,8 +427,8 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Div, div; D; - self: Rotation, right: Isometry, D>, - Output = Isometry, D>; + self: Rotation, right: Isometry, D>, + Output = Isometry, D>; // TODO: don't call inverse explicitly? [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; @@ -440,8 +440,8 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Mul, mul; ; - self: Isometry, 3>, rhs: UnitQuaternion, - Output = Isometry, 3>; + self: Isometry, 3>, rhs: UnitQuaternion, + Output = Isometry, 3>; [val val] => Isometry::from_parts(self.translation, self.rotation * rhs); [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation * rhs); // TODO: do not clone. [val ref] => Isometry::from_parts(self.translation, self.rotation * *rhs); @@ -452,8 +452,8 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Mul, mul; ; - self: UnitQuaternion, right: Isometry, 3>, - Output = Isometry, 3>; + self: UnitQuaternion, right: Isometry, 3>, + Output = Isometry, 3>; [val val] => &self * &right; [ref val] => self * &right; [val ref] => &self * right; @@ -467,8 +467,8 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Div, div; ; - self: Isometry, 3>, rhs: UnitQuaternion, - Output = Isometry, 3>; + self: Isometry, 3>, rhs: UnitQuaternion, + Output = Isometry, 3>; [val val] => Isometry::from_parts(self.translation, self.rotation / rhs); [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation / rhs); // TODO: do not clone. [val ref] => Isometry::from_parts(self.translation, self.rotation / *rhs); @@ -479,8 +479,8 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Div, div; ; - self: UnitQuaternion, right: Isometry, 3>, - Output = Isometry, 3>; + self: UnitQuaternion, right: Isometry, 3>, + Output = Isometry, 3>; // TODO: don't call inverse explicitly? [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; @@ -492,7 +492,7 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Mul, mul; D; - self: Translation, right: Rotation, Output = Isometry, D>; + self: Translation, right: Rotation, Output = Isometry, D>; [val val] => Isometry::from_parts(self, right); [ref val] => Isometry::from_parts(self.clone(), right); [val ref] => Isometry::from_parts(self, right.clone()); @@ -503,7 +503,7 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Mul, mul; ; - self: Translation, right: UnitQuaternion, Output = Isometry, 3>; + self: Translation, right: UnitQuaternion, Output = Isometry, 3>; [val val] => Isometry::from_parts(self, right); [ref val] => Isometry::from_parts(self.clone(), right); [val ref] => Isometry::from_parts(self, *right); @@ -514,8 +514,8 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Mul, mul; ; - self: Isometry, 2>, rhs: UnitComplex, - Output = Isometry, 2>; + self: Isometry, 2>, rhs: UnitComplex, + Output = Isometry, 2>; [val val] => Isometry::from_parts(self.translation, self.rotation * rhs); [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation * rhs); // TODO: do not clone. [val ref] => Isometry::from_parts(self.translation, self.rotation * *rhs); @@ -526,8 +526,8 @@ isometry_from_composition_impl_all!( isometry_from_composition_impl_all!( Div, div; ; - self: Isometry, 2>, rhs: UnitComplex, - Output = Isometry, 2>; + self: Isometry, 2>, rhs: UnitComplex, + Output = Isometry, 2>; [val val] => Isometry::from_parts(self.translation, self.rotation / rhs); [ref val] => Isometry::from_parts(self.translation.clone(), self.rotation / rhs); // TODO: do not clone. [val ref] => Isometry::from_parts(self.translation, self.rotation / *rhs); diff --git a/src/geometry/isometry_simba.rs b/src/geometry/isometry_simba.rs index 1ba8b765..ad482356 100755 --- a/src/geometry/isometry_simba.rs +++ b/src/geometry/isometry_simba.rs @@ -4,18 +4,18 @@ use crate::SimdRealField; use crate::geometry::{AbstractRotation, Isometry, Translation}; -impl SimdValue for Isometry +impl SimdValue for Isometry where - N::Element: SimdRealField, - R: SimdValue + AbstractRotation, - R::Element: AbstractRotation, + T::Element: SimdRealField, + R: SimdValue + AbstractRotation, + R::Element: AbstractRotation, { - type Element = Isometry; - type SimdBool = N::SimdBool; + type Element = Isometry; + type SimdBool = T::SimdBool; #[inline] fn lanes() -> usize { - N::lanes() + T::lanes() } #[inline] diff --git a/src/geometry/op_macros.rs b/src/geometry/op_macros.rs index 05194fd2..08c00870 100644 --- a/src/geometry/op_macros.rs +++ b/src/geometry/op_macros.rs @@ -5,7 +5,7 @@ macro_rules! md_impl( ( // Operator, operator method, and scalar bounds. - $Op: ident, $op: ident $(where N: $($ScalarBounds: ident),*)*; + $Op: ident, $op: ident $(where T: $($ScalarBounds: ident),*)*; // Storage dimensions, and dimension bounds. ($R1: ty, $C1: ty),($R2: ty, $C2: ty) // Const type declaration @@ -20,11 +20,11 @@ macro_rules! md_impl( $action: expr; // Lifetime. $($lives: tt),*) => { - impl<$($lives ,)* N $(, $DimsDecl)* $(, const $D: usize)*> $Op<$Rhs> for $Lhs - where N: Scalar + Zero + One + ClosedAdd + ClosedMul $($(+ $ScalarBounds)*)*, - DefaultAllocator: Allocator + - Allocator + - Allocator, + impl<$($lives ,)* T $(, $DimsDecl)* $(, const $D: usize)*> $Op<$Rhs> for $Lhs + where T: Scalar + Zero + One + ClosedAdd + ClosedMul $($(+ $ScalarBounds)*)*, + DefaultAllocator: Allocator + + Allocator + + Allocator, $( $ConstraintType: $ConstraintBound$(<$( $ConstraintBoundParams $( = $EqBound )*),*>)* ),* { type Output = $Result; @@ -42,7 +42,7 @@ macro_rules! md_impl( macro_rules! md_impl_all( ( // Operator, operator method, and scalar bounds. - $Op: ident, $op: ident $(where N: $($ScalarBounds: ident),*)*; + $Op: ident, $op: ident $(where T: $($ScalarBounds: ident),*)*; // Storage dimensions, and dimension bounds. ($R1: ty, $C1: ty),($R2: ty, $C2: ty) // Const type declaration @@ -60,7 +60,7 @@ macro_rules! md_impl_all( [ref ref] => $action_ref_ref: expr;) => { md_impl!( - $Op, $op $(where N: $($ScalarBounds),*)*; + $Op, $op $(where T: $($ScalarBounds),*)*; ($R1, $C1),($R2, $C2) const $($D),*; for $($DimsDecl),*; @@ -69,7 +69,7 @@ macro_rules! md_impl_all( $action_val_val; ); md_impl!( - $Op, $op $(where N: $($ScalarBounds),*)*; + $Op, $op $(where T: $($ScalarBounds),*)*; ($R1, $C1),($R2, $C2) const $($D),*; for $($DimsDecl),*; @@ -78,7 +78,7 @@ macro_rules! md_impl_all( $action_ref_val; 'a); md_impl!( - $Op, $op $(where N: $($ScalarBounds),*)*; + $Op, $op $(where T: $($ScalarBounds),*)*; ($R1, $C1),($R2, $C2) const $($D),*; for $($DimsDecl),*; @@ -87,7 +87,7 @@ macro_rules! md_impl_all( $action_val_ref; 'b); md_impl!( - $Op, $op $(where N: $($ScalarBounds),*)*; + $Op, $op $(where T: $($ScalarBounds),*)*; ($R1, $C1),($R2, $C2) const $($D),*; for $($DimsDecl),*; @@ -101,7 +101,7 @@ macro_rules! md_impl_all( macro_rules! md_assign_impl( ( // Operator, operator method, and scalar bounds. - $Op: ident, $op: ident $(where N: $($ScalarBounds: ident),*)* $(for N::Element: $($ElementBounds: ident),*)*; + $Op: ident, $op: ident $(where T: $($ScalarBounds: ident),*)* $(for T::Element: $($ElementBounds: ident),*)*; // Storage dimensions, and dimension bounds. ($R1: ty, $C1: ty),($R2: ty, $C2: ty) // Const type declaration @@ -114,11 +114,11 @@ macro_rules! md_assign_impl( $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty; // Actual implementation and lifetimes. $action: expr; $($lives: tt),*) => { - impl<$($lives ,)* N $(, $DimsDecl)* $(, const $D: usize)*> $Op<$Rhs> for $Lhs - where N: Scalar + Zero + One + ClosedAdd + ClosedMul $($(+ $ScalarBounds)*)*, - $($(N::Element: $ElementBounds,)*)* - DefaultAllocator: Allocator + - Allocator, + impl<$($lives ,)* T $(, $DimsDecl)* $(, const $D: usize)*> $Op<$Rhs> for $Lhs + where T: Scalar + Zero + One + ClosedAdd + ClosedMul $($(+ $ScalarBounds)*)*, + $($(T::Element: $ElementBounds,)*)* + DefaultAllocator: Allocator + + Allocator, $( $ConstraintType: $ConstraintBound $(<$( $ConstraintBoundParams $( = $EqBound )*),*>)* ),* { #[inline] @@ -134,7 +134,7 @@ macro_rules! md_assign_impl( macro_rules! md_assign_impl_all( ( // Operator, operator method, and scalar bounds. - $Op: ident, $op: ident $(where N: $($ScalarBounds: ident),*)* $(for N::Element: $($ElementBounds: ident),*)*; + $Op: ident, $op: ident $(where T: $($ScalarBounds: ident),*)* $(for T::Element: $($ElementBounds: ident),*)*; // Storage dimensions, and dimension bounds. ($R1: ty, $C1: ty),($R2: ty, $C2: ty) // Const type declaration @@ -149,7 +149,7 @@ macro_rules! md_assign_impl_all( [val] => $action_val: expr; [ref] => $action_ref: expr;) => { md_assign_impl!( - $Op, $op $(where N: $($ScalarBounds),*)* $(for N::Element: $($ElementBounds),*)*; + $Op, $op $(where T: $($ScalarBounds),*)* $(for T::Element: $($ElementBounds),*)*; ($R1, $C1),($R2, $C2) const $($D),*; for $($DimsDecl),*; @@ -158,7 +158,7 @@ macro_rules! md_assign_impl_all( $action_val; ); md_assign_impl!( - $Op, $op $(where N: $($ScalarBounds),*)* $(for N::Element: $($ElementBounds),*)*; + $Op, $op $(where T: $($ScalarBounds),*)* $(for T::Element: $($ElementBounds),*)*; ($R1, $C1),($R2, $C2) const $($D),*; for $($DimsDecl),*; @@ -181,11 +181,11 @@ macro_rules! add_sub_impl( where $($ConstraintType: ty: $ConstraintBound: ident$(<$($ConstraintBoundParams: ty $( = $EqBound: ty )*),*>)*),*; $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Result: ty; $action: expr; $($lives: tt),*) => { - impl<$($lives ,)* N $(, $DimsDecl)* $(, const $D: usize)*> $Op<$Rhs> for $Lhs - where N: Scalar + $bound, - DefaultAllocator: Allocator + - Allocator + - SameShapeAllocator, + impl<$($lives ,)* T $(, $DimsDecl)* $(, const $D: usize)*> $Op<$Rhs> for $Lhs + where T: Scalar + $bound, + DefaultAllocator: Allocator + + Allocator + + SameShapeAllocator, ShapeConstraint: SameNumberOfRows<$R1, $R2 $(, Representative = $RRes)*> + SameNumberOfColumns<$C1, $C2>, $( $ConstraintType: $ConstraintBound$(<$( $ConstraintBoundParams $( = $EqBound )*),*>)* ),* { @@ -206,8 +206,8 @@ macro_rules! add_sub_assign_impl( $(const $D: ident),*; $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty; $action: expr; $($lives: tt),*) => { - impl<$($lives ,)* N $(, const $D: usize),*> $Op<$Rhs> for $Lhs - where N: Scalar + $bound { + impl<$($lives ,)* T $(, const $D: usize),*> $Op<$Rhs> for $Lhs + where T: Scalar + $bound { #[inline] fn $op(&mut $lhs, $rhs: $Rhs) { $action diff --git a/src/geometry/orthographic.rs b/src/geometry/orthographic.rs index 43bf45c6..255faac1 100644 --- a/src/geometry/orthographic.rs +++ b/src/geometry/orthographic.rs @@ -19,26 +19,26 @@ use crate::base::{Matrix4, Vector, Vector3}; use crate::geometry::{Point3, Projective3}; /// A 3D orthographic projection stored as a homogeneous 4x4 matrix. -pub struct Orthographic3 { - matrix: Matrix4, +pub struct Orthographic3 { + matrix: Matrix4, } -impl Copy for Orthographic3 {} +impl Copy for Orthographic3 {} -impl Clone for Orthographic3 { +impl Clone for Orthographic3 { #[inline] fn clone(&self) -> Self { Self::from_matrix_unchecked(self.matrix) } } -impl fmt::Debug for Orthographic3 { +impl fmt::Debug for Orthographic3 { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { self.matrix.fmt(f) } } -impl PartialEq for Orthographic3 { +impl PartialEq for Orthographic3 { #[inline] fn eq(&self, right: &Self) -> bool { self.matrix == right.matrix @@ -46,7 +46,7 @@ impl PartialEq for Orthographic3 { } #[cfg(feature = "serde-serialize")] -impl Serialize for Orthographic3 { +impl Serialize for Orthographic3 { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -56,18 +56,18 @@ impl Serialize for Orthographic3 { } #[cfg(feature = "serde-serialize")] -impl<'a, N: RealField + Deserialize<'a>> Deserialize<'a> for Orthographic3 { +impl<'a, T: RealField + Deserialize<'a>> Deserialize<'a> for Orthographic3 { fn deserialize(deserializer: Des) -> Result where Des: Deserializer<'a>, { - let matrix = Matrix4::::deserialize(deserializer)?; + let matrix = Matrix4::::deserialize(deserializer)?; Ok(Self::from_matrix_unchecked(matrix)) } } -impl Orthographic3 { +impl Orthographic3 { /// Creates a new orthographic projection matrix. /// /// This follows the OpenGL convention, so this will flip the `z` axis. @@ -111,8 +111,8 @@ impl Orthographic3 { /// assert_relative_eq!(proj.project_point(&p8), Point3::new(-1.0, -1.0, -1.0)); /// ``` #[inline] - pub fn new(left: N, right: N, bottom: N, top: N, znear: N, zfar: N) -> Self { - let matrix = Matrix4::::identity(); + pub fn new(left: T, right: T, bottom: T, top: T, znear: T, zfar: T) -> Self { + let matrix = Matrix4::::identity(); let mut res = Self::from_matrix_unchecked(matrix); res.set_left_and_right(left, right); @@ -140,23 +140,23 @@ impl Orthographic3 { /// assert_eq!(proj, Orthographic3::new(1.0, 10.0, 2.0, 20.0, 0.1, 1000.0)); /// ``` #[inline] - pub fn from_matrix_unchecked(matrix: Matrix4) -> Self { + pub fn from_matrix_unchecked(matrix: Matrix4) -> Self { Self { matrix } } /// Creates a new orthographic projection matrix from an aspect ratio and the vertical field of view. #[inline] - pub fn from_fov(aspect: N, vfov: N, znear: N, zfar: N) -> Self { + pub fn from_fov(aspect: T, vfov: T, znear: T, zfar: T) -> Self { assert!( znear != zfar, "The far plane must not be equal to the near plane." ); assert!( - !relative_eq!(aspect, N::zero()), + !relative_eq!(aspect, T::zero()), "The aspect ratio must not be zero." ); - let half: N = crate::convert(0.5); + let half: T = crate::convert(0.5); let width = zfar * (vfov * half).tan(); let height = width / aspect; @@ -188,12 +188,12 @@ impl Orthographic3 { /// assert_relative_eq!(proj.as_matrix() * inv, Matrix4::identity()); /// ``` #[inline] - pub fn inverse(&self) -> Matrix4 { + pub fn inverse(&self) -> Matrix4 { let mut res = self.to_homogeneous(); - let inv_m11 = N::one() / self.matrix[(0, 0)]; - let inv_m22 = N::one() / self.matrix[(1, 1)]; - let inv_m33 = N::one() / self.matrix[(2, 2)]; + let inv_m11 = T::one() / self.matrix[(0, 0)]; + let inv_m22 = T::one() / self.matrix[(1, 1)]; + let inv_m33 = T::one() / self.matrix[(2, 2)]; res[(0, 0)] = inv_m11; res[(1, 1)] = inv_m22; @@ -221,7 +221,7 @@ impl Orthographic3 { /// assert_eq!(proj.to_homogeneous(), expected); /// ``` #[inline] - pub fn to_homogeneous(&self) -> Matrix4 { + pub fn to_homogeneous(&self) -> Matrix4 { self.matrix } @@ -240,7 +240,7 @@ impl Orthographic3 { /// assert_eq!(*proj.as_matrix(), expected); /// ``` #[inline] - pub fn as_matrix(&self) -> &Matrix4 { + pub fn as_matrix(&self) -> &Matrix4 { &self.matrix } @@ -253,7 +253,7 @@ impl Orthographic3 { /// assert_eq!(proj.as_projective().to_homogeneous(), proj.to_homogeneous()); /// ``` #[inline] - pub fn as_projective(&self) -> &Projective3 { + pub fn as_projective(&self) -> &Projective3 { unsafe { mem::transmute(self) } } @@ -266,7 +266,7 @@ impl Orthographic3 { /// assert_eq!(proj.to_projective().to_homogeneous(), proj.to_homogeneous()); /// ``` #[inline] - pub fn to_projective(&self) -> Projective3 { + pub fn to_projective(&self) -> Projective3 { Projective3::from_matrix_unchecked(self.matrix) } @@ -286,7 +286,7 @@ impl Orthographic3 { /// assert_eq!(proj.into_inner(), expected); /// ``` #[inline] - pub fn into_inner(self) -> Matrix4 { + pub fn into_inner(self) -> Matrix4 { self.matrix } @@ -294,7 +294,7 @@ impl Orthographic3 { /// Deprecated: Use [Orthographic3::into_inner] instead. #[deprecated(note = "use `.into_inner()` instead")] #[inline] - pub fn unwrap(self) -> Matrix4 { + pub fn unwrap(self) -> Matrix4 { self.matrix } @@ -310,8 +310,8 @@ impl Orthographic3 { /// assert_relative_eq!(proj.left(), 10.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn left(&self) -> N { - (-N::one() - self.matrix[(0, 3)]) / self.matrix[(0, 0)] + pub fn left(&self) -> T { + (-T::one() - self.matrix[(0, 3)]) / self.matrix[(0, 0)] } /// The right offset of the view cuboid. @@ -326,8 +326,8 @@ impl Orthographic3 { /// assert_relative_eq!(proj.right(), 1.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn right(&self) -> N { - (N::one() - self.matrix[(0, 3)]) / self.matrix[(0, 0)] + pub fn right(&self) -> T { + (T::one() - self.matrix[(0, 3)]) / self.matrix[(0, 0)] } /// The bottom offset of the view cuboid. @@ -342,8 +342,8 @@ impl Orthographic3 { /// assert_relative_eq!(proj.bottom(), 20.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn bottom(&self) -> N { - (-N::one() - self.matrix[(1, 3)]) / self.matrix[(1, 1)] + pub fn bottom(&self) -> T { + (-T::one() - self.matrix[(1, 3)]) / self.matrix[(1, 1)] } /// The top offset of the view cuboid. @@ -358,8 +358,8 @@ impl Orthographic3 { /// assert_relative_eq!(proj.top(), 2.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn top(&self) -> N { - (N::one() - self.matrix[(1, 3)]) / self.matrix[(1, 1)] + pub fn top(&self) -> T { + (T::one() - self.matrix[(1, 3)]) / self.matrix[(1, 1)] } /// The near plane offset of the view cuboid. @@ -374,8 +374,8 @@ impl Orthographic3 { /// assert_relative_eq!(proj.znear(), 1000.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn znear(&self) -> N { - (N::one() + self.matrix[(2, 3)]) / self.matrix[(2, 2)] + pub fn znear(&self) -> T { + (T::one() + self.matrix[(2, 3)]) / self.matrix[(2, 2)] } /// The far plane offset of the view cuboid. @@ -390,8 +390,8 @@ impl Orthographic3 { /// assert_relative_eq!(proj.zfar(), 0.1, epsilon = 1.0e-6); /// ``` #[inline] - pub fn zfar(&self) -> N { - (-N::one() + self.matrix[(2, 3)]) / self.matrix[(2, 2)] + pub fn zfar(&self) -> T { + (-T::one() + self.matrix[(2, 3)]) / self.matrix[(2, 2)] } // TODO: when we get specialization, specialize the Mul impl instead. @@ -422,7 +422,7 @@ impl Orthographic3 { /// assert_relative_eq!(proj.project_point(&p8), Point3::new( 1.0, 1.0, 1.0)); /// ``` #[inline] - pub fn project_point(&self, p: &Point3) -> Point3 { + pub fn project_point(&self, p: &Point3) -> Point3 { Point3::new( self.matrix[(0, 0)] * p[0] + self.matrix[(0, 3)], self.matrix[(1, 1)] * p[1] + self.matrix[(1, 3)], @@ -457,7 +457,7 @@ impl Orthographic3 { /// assert_relative_eq!(proj.unproject_point(&p8), Point3::new(10.0, 20.0, -1000.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn unproject_point(&self, p: &Point3) -> Point3 { + pub fn unproject_point(&self, p: &Point3) -> Point3 { Point3::new( (p[0] - self.matrix[(0, 3)]) / self.matrix[(0, 0)], (p[1] - self.matrix[(1, 3)]) / self.matrix[(1, 1)], @@ -485,9 +485,9 @@ impl Orthographic3 { /// assert_relative_eq!(proj.project_vector(&v3), Vector3::z() * -2.0 / 999.9); /// ``` #[inline] - pub fn project_vector(&self, p: &Vector) -> Vector3 + pub fn project_vector(&self, p: &Vector) -> Vector3 where - SB: Storage, + SB: Storage, { Vector3::new( self.matrix[(0, 0)] * p[0], @@ -510,7 +510,7 @@ impl Orthographic3 { /// assert_relative_eq!(proj.left(), 20.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn set_left(&mut self, left: N) { + pub fn set_left(&mut self, left: T) { let right = self.right(); self.set_left_and_right(left, right); } @@ -529,7 +529,7 @@ impl Orthographic3 { /// assert_relative_eq!(proj.right(), -3.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn set_right(&mut self, right: N) { + pub fn set_right(&mut self, right: T) { let left = self.left(); self.set_left_and_right(left, right); } @@ -548,7 +548,7 @@ impl Orthographic3 { /// assert_relative_eq!(proj.bottom(), 50.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn set_bottom(&mut self, bottom: N) { + pub fn set_bottom(&mut self, bottom: T) { let top = self.top(); self.set_bottom_and_top(bottom, top); } @@ -567,7 +567,7 @@ impl Orthographic3 { /// assert_relative_eq!(proj.top(), -3.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn set_top(&mut self, top: N) { + pub fn set_top(&mut self, top: T) { let bottom = self.bottom(); self.set_bottom_and_top(bottom, top); } @@ -586,7 +586,7 @@ impl Orthographic3 { /// assert_relative_eq!(proj.znear(), 5000.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn set_znear(&mut self, znear: N) { + pub fn set_znear(&mut self, znear: T) { let zfar = self.zfar(); self.set_znear_and_zfar(znear, zfar); } @@ -605,7 +605,7 @@ impl Orthographic3 { /// assert_relative_eq!(proj.zfar(), -3.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn set_zfar(&mut self, zfar: N) { + pub fn set_zfar(&mut self, zfar: T) { let znear = self.znear(); self.set_znear_and_zfar(znear, zfar); } @@ -626,12 +626,12 @@ impl Orthographic3 { /// assert_relative_eq!(proj.right(), 7.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn set_left_and_right(&mut self, left: N, right: N) { + pub fn set_left_and_right(&mut self, left: T, right: T) { assert!( left != right, "The left corner must not be equal to the right corner." ); - self.matrix[(0, 0)] = crate::convert::<_, N>(2.0) / (right - left); + self.matrix[(0, 0)] = crate::convert::<_, T>(2.0) / (right - left); self.matrix[(0, 3)] = -(right + left) / (right - left); } @@ -651,12 +651,12 @@ impl Orthographic3 { /// assert_relative_eq!(proj.top(), 7.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn set_bottom_and_top(&mut self, bottom: N, top: N) { + pub fn set_bottom_and_top(&mut self, bottom: T, top: T) { assert!( bottom != top, "The top corner must not be equal to the bottom corner." ); - self.matrix[(1, 1)] = crate::convert::<_, N>(2.0) / (top - bottom); + self.matrix[(1, 1)] = crate::convert::<_, T>(2.0) / (top - bottom); self.matrix[(1, 3)] = -(top + bottom) / (top - bottom); } @@ -676,56 +676,56 @@ impl Orthographic3 { /// assert_relative_eq!(proj.zfar(), 0.5, epsilon = 1.0e-6); /// ``` #[inline] - pub fn set_znear_and_zfar(&mut self, znear: N, zfar: N) { + pub fn set_znear_and_zfar(&mut self, znear: T, zfar: T) { assert!( zfar != znear, "The near-plane and far-plane must not be superimposed." ); - self.matrix[(2, 2)] = -crate::convert::<_, N>(2.0) / (zfar - znear); + self.matrix[(2, 2)] = -crate::convert::<_, T>(2.0) / (zfar - znear); self.matrix[(2, 3)] = -(zfar + znear) / (zfar - znear); } } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - Standard: Distribution, + Standard: Distribution, { /// Generate an arbitrary random variate for testing purposes. - fn sample(&self, r: &mut R) -> Orthographic3 { + fn sample(&self, r: &mut R) -> Orthographic3 { use crate::base::helper; let left = r.gen(); - let right = helper::reject_rand(r, |x: &N| *x > left); + let right = helper::reject_rand(r, |x: &T| *x > left); let bottom = r.gen(); - let top = helper::reject_rand(r, |x: &N| *x > bottom); + let top = helper::reject_rand(r, |x: &T| *x > bottom); let znear = r.gen(); - let zfar = helper::reject_rand(r, |x: &N| *x > znear); + let zfar = helper::reject_rand(r, |x: &T| *x > znear); Orthographic3::new(left, right, bottom, top, znear, zfar) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Orthographic3 +impl Arbitrary for Orthographic3 where - Matrix4: Send, + Matrix4: Send, { fn arbitrary(g: &mut Gen) -> Self { use crate::base::helper; let left = Arbitrary::arbitrary(g); - let right = helper::reject(g, |x: &N| *x > left); + let right = helper::reject(g, |x: &T| *x > left); let bottom = Arbitrary::arbitrary(g); - let top = helper::reject(g, |x: &N| *x > bottom); + let top = helper::reject(g, |x: &T| *x > bottom); let znear = Arbitrary::arbitrary(g); - let zfar = helper::reject(g, |x: &N| *x > znear); + let zfar = helper::reject(g, |x: &T| *x > znear); Self::new(left, right, bottom, top, znear, zfar) } } -impl From> for Matrix4 { +impl From> for Matrix4 { #[inline] - fn from(orth: Orthographic3) -> Self { + fn from(orth: Orthographic3) -> Self { orth.into_inner() } } diff --git a/src/geometry/perspective.rs b/src/geometry/perspective.rs index 64861fbd..e8f582ef 100644 --- a/src/geometry/perspective.rs +++ b/src/geometry/perspective.rs @@ -20,26 +20,26 @@ use crate::base::{Matrix4, Scalar, Vector, Vector3}; use crate::geometry::{Point3, Projective3}; /// A 3D perspective projection stored as a homogeneous 4x4 matrix. -pub struct Perspective3 { - matrix: Matrix4, +pub struct Perspective3 { + matrix: Matrix4, } -impl Copy for Perspective3 {} +impl Copy for Perspective3 {} -impl Clone for Perspective3 { +impl Clone for Perspective3 { #[inline] fn clone(&self) -> Self { Self::from_matrix_unchecked(self.matrix) } } -impl fmt::Debug for Perspective3 { +impl fmt::Debug for Perspective3 { fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> { self.matrix.fmt(f) } } -impl PartialEq for Perspective3 { +impl PartialEq for Perspective3 { #[inline] fn eq(&self, right: &Self) -> bool { self.matrix == right.matrix @@ -47,7 +47,7 @@ impl PartialEq for Perspective3 { } #[cfg(feature = "serde-serialize")] -impl Serialize for Perspective3 { +impl Serialize for Perspective3 { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -57,26 +57,26 @@ impl Serialize for Perspective3 { } #[cfg(feature = "serde-serialize")] -impl<'a, N: RealField + Deserialize<'a>> Deserialize<'a> for Perspective3 { +impl<'a, T: RealField + Deserialize<'a>> Deserialize<'a> for Perspective3 { fn deserialize(deserializer: Des) -> Result where Des: Deserializer<'a>, { - let matrix = Matrix4::::deserialize(deserializer)?; + let matrix = Matrix4::::deserialize(deserializer)?; Ok(Self::from_matrix_unchecked(matrix)) } } -impl Perspective3 { +impl Perspective3 { /// Creates a new perspective matrix from the aspect ratio, y field of view, and near/far planes. - pub fn new(aspect: N, fovy: N, znear: N, zfar: N) -> Self { + pub fn new(aspect: T, fovy: T, znear: T, zfar: T) -> Self { assert!( - !relative_eq!(zfar - znear, N::zero()), + !relative_eq!(zfar - znear, T::zero()), "The near-plane and far-plane must not be superimposed." ); assert!( - !relative_eq!(aspect, N::zero()), + !relative_eq!(aspect, T::zero()), "The aspect ratio must not be zero." ); @@ -87,8 +87,8 @@ impl Perspective3 { res.set_aspect(aspect); res.set_znear_and_zfar(znear, zfar); - res.matrix[(3, 3)] = N::zero(); - res.matrix[(3, 2)] = -N::one(); + res.matrix[(3, 3)] = T::zero(); + res.matrix[(3, 2)] = -T::one(); res } @@ -98,24 +98,24 @@ impl Perspective3 { /// It is not checked whether or not the given matrix actually represents a perspective /// projection. #[inline] - pub fn from_matrix_unchecked(matrix: Matrix4) -> Self { + pub fn from_matrix_unchecked(matrix: Matrix4) -> Self { Self { matrix } } /// Retrieves the inverse of the underlying homogeneous matrix. #[inline] - pub fn inverse(&self) -> Matrix4 { + pub fn inverse(&self) -> Matrix4 { let mut res = self.to_homogeneous(); - res[(0, 0)] = N::one() / self.matrix[(0, 0)]; - res[(1, 1)] = N::one() / self.matrix[(1, 1)]; - res[(2, 2)] = N::zero(); + res[(0, 0)] = T::one() / self.matrix[(0, 0)]; + res[(1, 1)] = T::one() / self.matrix[(1, 1)]; + res[(2, 2)] = T::zero(); let m23 = self.matrix[(2, 3)]; let m32 = self.matrix[(3, 2)]; - res[(2, 3)] = N::one() / m32; - res[(3, 2)] = N::one() / m23; + res[(2, 3)] = T::one() / m32; + res[(3, 2)] = T::one() / m23; res[(3, 3)] = -self.matrix[(2, 2)] / (m23 * m32); res @@ -123,31 +123,31 @@ impl Perspective3 { /// Computes the corresponding homogeneous matrix. #[inline] - pub fn to_homogeneous(&self) -> Matrix4 { + pub fn to_homogeneous(&self) -> Matrix4 { self.matrix.clone_owned() } /// A reference to the underlying homogeneous transformation matrix. #[inline] - pub fn as_matrix(&self) -> &Matrix4 { + pub fn as_matrix(&self) -> &Matrix4 { &self.matrix } /// A reference to this transformation seen as a `Projective3`. #[inline] - pub fn as_projective(&self) -> &Projective3 { + pub fn as_projective(&self) -> &Projective3 { unsafe { mem::transmute(self) } } /// This transformation seen as a `Projective3`. #[inline] - pub fn to_projective(&self) -> Projective3 { + pub fn to_projective(&self) -> Projective3 { Projective3::from_matrix_unchecked(self.matrix) } /// Retrieves the underlying homogeneous matrix. #[inline] - pub fn into_inner(self) -> Matrix4 { + pub fn into_inner(self) -> Matrix4 { self.matrix } @@ -155,26 +155,26 @@ impl Perspective3 { /// Deprecated: Use [Perspective3::into_inner] instead. #[deprecated(note = "use `.into_inner()` instead")] #[inline] - pub fn unwrap(self) -> Matrix4 { + pub fn unwrap(self) -> Matrix4 { self.matrix } /// Gets the `width / height` aspect ratio of the view frustum. #[inline] - pub fn aspect(&self) -> N { + pub fn aspect(&self) -> T { self.matrix[(1, 1)] / self.matrix[(0, 0)] } /// Gets the y field of view of the view frustum. #[inline] - pub fn fovy(&self) -> N { - (N::one() / self.matrix[(1, 1)]).atan() * crate::convert(2.0) + pub fn fovy(&self) -> T { + (T::one() / self.matrix[(1, 1)]).atan() * crate::convert(2.0) } /// Gets the near plane offset of the view frustum. #[inline] - pub fn znear(&self) -> N { - let ratio = (-self.matrix[(2, 2)] + N::one()) / (-self.matrix[(2, 2)] - N::one()); + pub fn znear(&self) -> T { + let ratio = (-self.matrix[(2, 2)] + T::one()) / (-self.matrix[(2, 2)] - T::one()); self.matrix[(2, 3)] / (ratio * crate::convert(2.0)) - self.matrix[(2, 3)] / crate::convert(2.0) @@ -182,8 +182,8 @@ impl Perspective3 { /// Gets the far plane offset of the view frustum. #[inline] - pub fn zfar(&self) -> N { - let ratio = (-self.matrix[(2, 2)] + N::one()) / (-self.matrix[(2, 2)] - N::one()); + pub fn zfar(&self) -> T { + let ratio = (-self.matrix[(2, 2)] + T::one()) / (-self.matrix[(2, 2)] - T::one()); (self.matrix[(2, 3)] - ratio * self.matrix[(2, 3)]) / crate::convert(2.0) } @@ -193,8 +193,8 @@ impl Perspective3 { // TODO: when we get specialization, specialize the Mul impl instead. /// Projects a point. Faster than matrix multiplication. #[inline] - pub fn project_point(&self, p: &Point3) -> Point3 { - let inverse_denom = -N::one() / p[2]; + pub fn project_point(&self, p: &Point3) -> Point3 { + let inverse_denom = -T::one() / p[2]; Point3::new( self.matrix[(0, 0)] * p[0] * inverse_denom, self.matrix[(1, 1)] * p[1] * inverse_denom, @@ -204,7 +204,7 @@ impl Perspective3 { /// Un-projects a point. Faster than multiplication by the matrix inverse. #[inline] - pub fn unproject_point(&self, p: &Point3) -> Point3 { + pub fn unproject_point(&self, p: &Point3) -> Point3 { let inverse_denom = self.matrix[(2, 3)] / (p[2] + self.matrix[(2, 2)]); Point3::new( @@ -217,11 +217,11 @@ impl Perspective3 { // TODO: when we get specialization, specialize the Mul impl instead. /// Projects a vector. Faster than matrix multiplication. #[inline] - pub fn project_vector(&self, p: &Vector) -> Vector3 + pub fn project_vector(&self, p: &Vector) -> Vector3 where - SB: Storage, + SB: Storage, { - let inverse_denom = -N::one() / p[2]; + let inverse_denom = -T::one() / p[2]; Vector3::new( self.matrix[(0, 0)] * p[0] * inverse_denom, self.matrix[(1, 1)] * p[1] * inverse_denom, @@ -232,9 +232,9 @@ impl Perspective3 { /// Updates this perspective matrix with a new `width / height` aspect ratio of the view /// frustum. #[inline] - pub fn set_aspect(&mut self, aspect: N) { + pub fn set_aspect(&mut self, aspect: T) { assert!( - !relative_eq!(aspect, N::zero()), + !relative_eq!(aspect, T::zero()), "The aspect ratio must not be zero." ); self.matrix[(0, 0)] = self.matrix[(1, 1)] / aspect; @@ -242,65 +242,65 @@ impl Perspective3 { /// Updates this perspective with a new y field of view of the view frustum. #[inline] - pub fn set_fovy(&mut self, fovy: N) { + pub fn set_fovy(&mut self, fovy: T) { let old_m22 = self.matrix[(1, 1)]; - self.matrix[(1, 1)] = N::one() / (fovy / crate::convert(2.0)).tan(); + self.matrix[(1, 1)] = T::one() / (fovy / crate::convert(2.0)).tan(); self.matrix[(0, 0)] = self.matrix[(0, 0)] * (self.matrix[(1, 1)] / old_m22); } /// Updates this perspective matrix with a new near plane offset of the view frustum. #[inline] - pub fn set_znear(&mut self, znear: N) { + pub fn set_znear(&mut self, znear: T) { let zfar = self.zfar(); self.set_znear_and_zfar(znear, zfar); } /// Updates this perspective matrix with a new far plane offset of the view frustum. #[inline] - pub fn set_zfar(&mut self, zfar: N) { + pub fn set_zfar(&mut self, zfar: T) { let znear = self.znear(); self.set_znear_and_zfar(znear, zfar); } /// Updates this perspective matrix with new near and far plane offsets of the view frustum. #[inline] - pub fn set_znear_and_zfar(&mut self, znear: N, zfar: N) { + pub fn set_znear_and_zfar(&mut self, znear: T, zfar: T) { self.matrix[(2, 2)] = (zfar + znear) / (znear - zfar); self.matrix[(2, 3)] = zfar * znear * crate::convert(2.0) / (znear - zfar); } } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - Standard: Distribution, + Standard: Distribution, { /// Generate an arbitrary random variate for testing purposes. - fn sample<'a, R: Rng + ?Sized>(&self, r: &'a mut R) -> Perspective3 { + fn sample<'a, R: Rng + ?Sized>(&self, r: &'a mut R) -> Perspective3 { use crate::base::helper; let znear = r.gen(); - let zfar = helper::reject_rand(r, |&x: &N| !(x - znear).is_zero()); - let aspect = helper::reject_rand(r, |&x: &N| !x.is_zero()); + let zfar = helper::reject_rand(r, |&x: &T| !(x - znear).is_zero()); + let aspect = helper::reject_rand(r, |&x: &T| !x.is_zero()); Perspective3::new(aspect, r.gen(), znear, zfar) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Perspective3 { +impl Arbitrary for Perspective3 { fn arbitrary(g: &mut Gen) -> Self { use crate::base::helper; let znear = Arbitrary::arbitrary(g); - let zfar = helper::reject(g, |&x: &N| !(x - znear).is_zero()); - let aspect = helper::reject(g, |&x: &N| !x.is_zero()); + let zfar = helper::reject(g, |&x: &T| !(x - znear).is_zero()); + let aspect = helper::reject(g, |&x: &T| !x.is_zero()); Self::new(aspect, Arbitrary::arbitrary(g), znear, zfar) } } -impl From> for Matrix4 { +impl From> for Matrix4 { #[inline] - fn from(pers: Perspective3) -> Self { + fn from(pers: Perspective3) -> Self { pers.into_inner() } } diff --git a/src/geometry/point.rs b/src/geometry/point.rs index 4944e158..e5dcbc25 100644 --- a/src/geometry/point.rs +++ b/src/geometry/point.rs @@ -17,7 +17,7 @@ use simba::simd::SimdPartialOrd; use crate::base::allocator::Allocator; use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; use crate::base::iter::{MatrixIter, MatrixIterMut}; -use crate::base::{CVectorN, Const, DefaultAllocator, Scalar, VectorN}; +use crate::base::{Const, DefaultAllocator, OVector, Scalar}; /// A point in an euclidean space. /// @@ -40,44 +40,35 @@ use crate::base::{CVectorN, Const, DefaultAllocator, Scalar, VectorN}; /// of said transformations for details. #[repr(C)] #[derive(Debug, Clone)] -pub struct Point { +pub struct Point { /// The coordinates of this point, i.e., the shift from the origin. - pub coords: VectorN>, + pub coords: OVector>, } -impl hash::Hash for Point -// where -// DefaultAllocator: Allocator, -// >::Buffer: hash::Hash, -{ +impl hash::Hash for Point { fn hash(&self, state: &mut H) { self.coords.hash(state) } } -impl Copy for Point -// where -// DefaultAllocator: Allocator, -// >::Buffer: Copy, +impl Copy for Point {} + +#[cfg(feature = "bytemuck")] +unsafe impl bytemuck::Zeroable for Point where + OVector>: bytemuck::Zeroable { } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Zeroable for Point where - VectorN>: bytemuck::Zeroable -{ -} - -#[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Pod for Point +unsafe impl bytemuck::Pod for Point where - N: Copy, - VectorN>: bytemuck::Pod, + T: Copy, + OVector>: bytemuck::Pod, { } #[cfg(feature = "serde-serialize")] -impl Serialize for Point { +impl Serialize for Point { fn serialize(&self, serializer: S) -> Result where S: Serializer, @@ -87,22 +78,23 @@ impl Serialize for Point { } #[cfg(feature = "serde-serialize")] -impl<'a, N: Scalar + Deserialize<'a>, const D: usize> Deserialize<'a> for Point { +impl<'a, T: Scalar + Deserialize<'a>, const D: usize> Deserialize<'a> for Point { fn deserialize(deserializer: Des) -> Result where Des: Deserializer<'a>, { - let coords = CVectorN::::deserialize(deserializer)?; + use crate::SVector; + let coords = SVector::::deserialize(deserializer)?; Ok(Self::from(coords)) } } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Point +impl Abomonation for Point where - N: Scalar, - VectorN>: Abomonation, + T: Scalar, + OVector>: Abomonation, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.coords.entomb(writer) @@ -117,10 +109,7 @@ where } } -impl Point -// where -// DefaultAllocator: Allocator, -{ +impl Point { /// Returns a point containing the result of `f` applied to each of its entries. /// /// # Example @@ -134,10 +123,7 @@ impl Point /// assert_eq!(p.map(|e| e as u32), Point3::new(1, 2, 3)); /// ``` #[inline] - pub fn map N2>(&self, f: F) -> Point -// where - // DefaultAllocator: Allocator, - { + pub fn map T2>(&self, f: F) -> Point { self.coords.map(f).into() } @@ -156,7 +142,7 @@ impl Point /// assert_eq!(p, Point3::new(10.0, 20.0, 30.0)); /// ``` #[inline] - pub fn apply N>(&mut self, f: F) { + pub fn apply T>(&mut self, f: F) { self.coords.apply(f) } @@ -176,11 +162,11 @@ impl Point /// assert_eq!(p.to_homogeneous(), Vector4::new(10.0, 20.0, 30.0, 1.0)); /// ``` #[inline] - pub fn to_homogeneous(&self) -> VectorN, U1>> + pub fn to_homogeneous(&self) -> OVector, U1>> where - N: One, + T: One, Const: DimNameAdd, - DefaultAllocator: Allocator, U1>>, + DefaultAllocator: Allocator, U1>>, { let mut res = unsafe { crate::unimplemented_or_uninitialized_generic!( @@ -188,9 +174,8 @@ impl Point Const::<1> ) }; - res.fixed_slice_mut::, U1>(0, 0) - .copy_from(&self.coords); - res[(D, 0)] = N::one(); + res.fixed_slice_mut::(0, 0).copy_from(&self.coords); + res[(D, 0)] = T::one(); res } @@ -198,7 +183,7 @@ impl Point /// Creates a new point with the given coordinates. #[deprecated(note = "Use Point::from(vector) instead.")] #[inline] - pub fn from_coordinates(coords: VectorN>) -> Self { + pub fn from_coordinates(coords: OVector>) -> Self { Self { coords } } @@ -255,14 +240,14 @@ impl Point #[inline] pub fn iter( &self, - ) -> MatrixIter, Const<1>, >>::Buffer> + ) -> MatrixIter, Const<1>, >>::Buffer> { self.coords.iter() } /// Gets a reference to i-th element of this point without bound-checking. #[inline] - pub unsafe fn get_unchecked(&self, i: usize) -> &N { + pub unsafe fn get_unchecked(&self, i: usize) -> &T { self.coords.vget_unchecked(i) } @@ -281,14 +266,14 @@ impl Point #[inline] pub fn iter_mut( &mut self, - ) -> MatrixIterMut, Const<1>, >>::Buffer> + ) -> MatrixIterMut, Const<1>, >>::Buffer> { self.coords.iter_mut() } /// Gets a mutable reference to i-th element of this point without bound-checking. #[inline] - pub unsafe fn get_unchecked_mut(&mut self, i: usize) -> &mut N { + pub unsafe fn get_unchecked_mut(&mut self, i: usize) -> &mut T { self.coords.vget_unchecked_mut(i) } @@ -299,15 +284,15 @@ impl Point } } -impl AbsDiffEq for Point +impl AbsDiffEq for Point where - N::Epsilon: Copy, + T::Epsilon: Copy, { - type Epsilon = N::Epsilon; + type Epsilon = T::Epsilon; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -316,13 +301,13 @@ where } } -impl RelativeEq for Point +impl RelativeEq for Point where - N::Epsilon: Copy, + T::Epsilon: Copy, { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -337,13 +322,13 @@ where } } -impl UlpsEq for Point +impl UlpsEq for Point where - N::Epsilon: Copy, + T::Epsilon: Copy, { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] @@ -352,25 +337,16 @@ where } } -impl Eq for Point -// where DefaultAllocator: Allocator -{ -} +impl Eq for Point {} -impl PartialEq for Point -// where -// DefaultAllocator: Allocator, -{ +impl PartialEq for Point { #[inline] fn eq(&self, right: &Self) -> bool { self.coords == right.coords } } -impl PartialOrd for Point -// where -// DefaultAllocator: Allocator, -{ +impl PartialOrd for Point { #[inline] fn partial_cmp(&self, other: &Self) -> Option { self.coords.partial_cmp(&other.coords) @@ -400,25 +376,22 @@ impl PartialOrd for Point /* * inf/sup */ -impl Point -// where -// DefaultAllocator: Allocator, -{ +impl Point { /// Computes the infimum (aka. componentwise min) of two points. #[inline] - pub fn inf(&self, other: &Self) -> Point { + pub fn inf(&self, other: &Self) -> Point { self.coords.inf(&other.coords).into() } /// Computes the supremum (aka. componentwise max) of two points. #[inline] - pub fn sup(&self, other: &Self) -> Point { + pub fn sup(&self, other: &Self) -> Point { self.coords.sup(&other.coords).into() } /// Computes the (infimum, supremum) of two points. #[inline] - pub fn inf_sup(&self, other: &Self) -> (Point, Point) { + pub fn inf_sup(&self, other: &Self) -> (Point, Point) { let (inf, sup) = self.coords.inf_sup(&other.coords); (inf.into(), sup.into()) } @@ -429,10 +402,7 @@ impl Point * Display * */ -impl fmt::Display for Point -// where -// DefaultAllocator: Allocator, -{ +impl fmt::Display for Point { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "{{")?; diff --git a/src/geometry/point_alias.rs b/src/geometry/point_alias.rs index 402c1201..54441b09 100644 --- a/src/geometry/point_alias.rs +++ b/src/geometry/point_alias.rs @@ -3,24 +3,24 @@ use crate::geometry::Point; /// A statically sized 1-dimensional column point. /// /// **Because this is an alias, not all its methods are listed here. See the [`Point`](crate::Point) type too.** -pub type Point1 = Point; +pub type Point1 = Point; /// A statically sized 2-dimensional column point. /// /// **Because this is an alias, not all its methods are listed here. See the [`Point`](crate::Point) type too.** -pub type Point2 = Point; +pub type Point2 = Point; /// A statically sized 3-dimensional column point. /// /// **Because this is an alias, not all its methods are listed here. See the [`Point`](crate::Point) type too.** -pub type Point3 = Point; +pub type Point3 = Point; /// A statically sized 4-dimensional column point. /// /// **Because this is an alias, not all its methods are listed here. See the [`Point`](crate::Point) type too.** -pub type Point4 = Point; +pub type Point4 = Point; /// A statically sized 5-dimensional column point. /// /// **Because this is an alias, not all its methods are listed here. See the [`Point`](crate::Point) type too.** -pub type Point5 = Point; +pub type Point5 = Point; /// A statically sized 6-dimensional column point. /// /// **Because this is an alias, not all its methods are listed here. See the [`Point`](crate::Point) type too.** -pub type Point6 = Point; +pub type Point6 = Point; diff --git a/src/geometry/point_construction.rs b/src/geometry/point_construction.rs index 6d58dd87..3e7b2554 100644 --- a/src/geometry/point_construction.rs +++ b/src/geometry/point_construction.rs @@ -10,20 +10,17 @@ use rand::{ use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; -use crate::base::{CVectorN, DefaultAllocator, Scalar}; +use crate::base::{DefaultAllocator, SVector, Scalar}; use crate::{ - Const, Point1, Point2, Point3, Point4, Point5, Point6, Vector1, Vector2, Vector3, Vector4, - Vector5, Vector6, VectorN, + Const, OVector, Point1, Point2, Point3, Point4, Point5, Point6, Vector1, Vector2, Vector3, + Vector4, Vector5, Vector6, }; use simba::scalar::{ClosedDiv, SupersetOf}; use crate::geometry::Point; /// # Other construction methods -impl Point -// where -// DefaultAllocator: Allocator, -{ +impl Point { /// Creates a new point with uninitialized coordinates. #[inline] pub unsafe fn new_uninitialized() -> Self { @@ -50,9 +47,9 @@ impl Point #[inline] pub fn origin() -> Self where - N: Zero, + T: Zero, { - Self::from(CVectorN::from_element(N::zero())) + Self::from(SVector::from_element(T::zero())) } /// Creates a new point from a slice. @@ -70,8 +67,8 @@ impl Point /// assert_eq!(pt, Point3::new(1.0, 2.0, 3.0)); /// ``` #[inline] - pub fn from_slice(components: &[N]) -> Self { - Self::from(CVectorN::from_row_slice(components)) + pub fn from_slice(components: &[T]) -> Self { + Self::from(SVector::from_row_slice(components)) } /// Creates a new point from its homogeneous vector representation. @@ -105,14 +102,14 @@ impl Point /// assert_eq!(pt, Some(Point2::new(1.0, 2.0))); /// ``` #[inline] - pub fn from_homogeneous(v: VectorN, U1>>) -> Option + pub fn from_homogeneous(v: OVector, U1>>) -> Option where - N: Scalar + Zero + One + ClosedDiv, + T: Scalar + Zero + One + ClosedDiv, Const: DimNameAdd, - DefaultAllocator: Allocator, U1>>, + DefaultAllocator: Allocator, U1>>, { if !v[D].is_zero() { - let coords = v.fixed_slice::, U1>(0, 0) / v[D].inlined_clone(); + let coords = v.fixed_slice::(0, 0) / v[D].inlined_clone(); Some(Self::from(coords)) } else { None @@ -141,41 +138,38 @@ impl Point * Traits that build points. * */ -impl Bounded for Point -// where -// DefaultAllocator: Allocator, -{ +impl Bounded for Point { #[inline] fn max_value() -> Self { - Self::from(CVectorN::max_value()) + Self::from(SVector::max_value()) } #[inline] fn min_value() -> Self { - Self::from(CVectorN::min_value()) + Self::from(SVector::min_value()) } } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - Standard: Distribution, + Standard: Distribution, { /// Generate a `Point` where each coordinate is an independent variate from `[0, 1)`. #[inline] - fn sample<'a, G: Rng + ?Sized>(&self, rng: &mut G) -> Point { - Point::from(rng.gen::>()) + fn sample<'a, G: Rng + ?Sized>(&self, rng: &mut G) -> Point { + Point::from(rng.gen::>()) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Point +impl Arbitrary for Point where - >>::Buffer: Send, + >>::Buffer: Send, { #[inline] fn arbitrary(g: &mut Gen) -> Self { - Self::from(CVectorN::arbitrary(g)) + Self::from(SVector::arbitrary(g)) } } @@ -187,7 +181,7 @@ where // NOTE: the impl for Point1 is not with the others so that we // can add a section with the impl block comment. /// # Construction from individual components -impl Point1 { +impl Point1 { /// Initializes this point from its components. /// /// # Example @@ -198,19 +192,19 @@ impl Point1 { /// assert_eq!(p.x, 1.0); /// ``` #[inline] - pub fn new(x: N) -> Self { + pub fn new(x: T) -> Self { Vector1::new(x).into() } } macro_rules! componentwise_constructors_impl( ($($doc: expr; $Point: ident, $Vector: ident, $($args: ident:$irow: expr),*);* $(;)*) => {$( - impl $Point { + impl $Point { #[doc = "Initializes this point from its components."] #[doc = "# Example\n```"] #[doc = $doc] #[doc = "```"] #[inline] - pub fn new($($args: N),*) -> Self { + pub fn new($($args: T),*) -> Self { $Vector::new($($args),*).into() } } @@ -232,8 +226,8 @@ componentwise_constructors_impl!( macro_rules! from_array_impl( ($($Point: ident, $len: expr);*) => {$( - impl From<[N; $len]> for $Point { - fn from(coords: [N; $len]) -> Self { + impl From<[T; $len]> for $Point { + fn from(coords: [T; $len]) -> Self { Self { coords: coords.into() } diff --git a/src/geometry/point_conversion.rs b/src/geometry/point_conversion.rs index 43cc7bc7..08438ec0 100644 --- a/src/geometry/point_conversion.rs +++ b/src/geometry/point_conversion.rs @@ -4,7 +4,7 @@ use simba::simd::PrimitiveSimdValue; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; -use crate::base::{Const, DefaultAllocator, Matrix, Scalar, VectorN}; +use crate::base::{Const, DefaultAllocator, Matrix, OVector, Scalar}; use crate::geometry::Point; @@ -16,104 +16,101 @@ use crate::geometry::Point; * Point -> Vector (homogeneous) */ -impl SubsetOf> for Point +impl SubsetOf> for Point where - N1: Scalar, - N2: Scalar + SupersetOf, + T1: Scalar, + T2: Scalar + SupersetOf, { #[inline] - fn to_superset(&self) -> Point { + fn to_superset(&self) -> Point { Point::from(self.coords.to_superset()) } #[inline] - fn is_in_subset(m: &Point) -> bool { + fn is_in_subset(m: &Point) -> bool { // TODO: is there a way to reuse the `.is_in_subset` from the matrix implementation of // SubsetOf? m.iter().all(|e| e.is_in_subset()) } #[inline] - fn from_superset_unchecked(m: &Point) -> Self { + fn from_superset_unchecked(m: &Point) -> Self { Self::from(Matrix::from_superset_unchecked(&m.coords)) } } -impl SubsetOf, U1>>> for Point +impl SubsetOf, U1>>> for Point where Const: DimNameAdd, - N1: Scalar, - N2: Scalar + Zero + One + ClosedDiv + SupersetOf, + T1: Scalar, + T2: Scalar + Zero + One + ClosedDiv + SupersetOf, DefaultAllocator: - Allocator, U1>> + Allocator, U1>>, - // + Allocator - // + Allocator, + Allocator, U1>> + Allocator, U1>>, + // + Allocator + // + Allocator, { #[inline] - fn to_superset(&self) -> VectorN, U1>> { - let p: Point = self.to_superset(); + fn to_superset(&self) -> OVector, U1>> { + let p: Point = self.to_superset(); p.to_homogeneous() } #[inline] - fn is_in_subset(v: &VectorN, U1>>) -> bool { - crate::is_convertible::<_, VectorN, U1>>>(v) && !v[D].is_zero() + fn is_in_subset(v: &OVector, U1>>) -> bool { + crate::is_convertible::<_, OVector, U1>>>(v) && !v[D].is_zero() } #[inline] - fn from_superset_unchecked(v: &VectorN, U1>>) -> Self { - let coords = v.fixed_slice::, U1>(0, 0) / v[D].inlined_clone(); + fn from_superset_unchecked(v: &OVector, U1>>) -> Self { + let coords = v.fixed_slice::(0, 0) / v[D].inlined_clone(); Self { coords: crate::convert_unchecked(coords), } } } -impl From> - for VectorN, U1>> +impl From> + for OVector, U1>> where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>>, + DefaultAllocator: Allocator, U1>>, { #[inline] - fn from(t: Point) -> Self { + fn from(t: Point) -> Self { t.to_homogeneous() } } -impl From>> for Point -// where -// DefaultAllocator: Allocator, -{ +impl From>> for Point { #[inline] - fn from(coords: VectorN>) -> Self { + fn from(coords: OVector>) -> Self { Point { coords } } } -impl From<[Point; 2]> - for Point +impl From<[Point; 2]> + for Point where - N: From<[::Element; 2]>, - N::Element: Scalar + Copy, - >>::Buffer: Copy, + T: From<[::Element; 2]>, + T::Element: Scalar + Copy, + >>::Buffer: Copy, { #[inline] - fn from(arr: [Point; 2]) -> Self { - Self::from(VectorN::from([arr[0].coords, arr[1].coords])) + fn from(arr: [Point; 2]) -> Self { + Self::from(OVector::from([arr[0].coords, arr[1].coords])) } } -impl From<[Point; 4]> - for Point +impl From<[Point; 4]> + for Point where - N: From<[::Element; 4]>, - N::Element: Scalar + Copy, - >>::Buffer: Copy, + T: From<[::Element; 4]>, + T::Element: Scalar + Copy, + >>::Buffer: Copy, { #[inline] - fn from(arr: [Point; 4]) -> Self { - Self::from(VectorN::from([ + fn from(arr: [Point; 4]) -> Self { + Self::from(OVector::from([ arr[0].coords, arr[1].coords, arr[2].coords, @@ -122,16 +119,16 @@ where } } -impl From<[Point; 8]> - for Point +impl From<[Point; 8]> + for Point where - N: From<[::Element; 8]>, - N::Element: Scalar + Copy, - >>::Buffer: Copy, + T: From<[::Element; 8]>, + T::Element: Scalar + Copy, + >>::Buffer: Copy, { #[inline] - fn from(arr: [Point; 8]) -> Self { - Self::from(VectorN::from([ + fn from(arr: [Point; 8]) -> Self { + Self::from(OVector::from([ arr[0].coords, arr[1].coords, arr[2].coords, @@ -144,16 +141,16 @@ where } } -impl From<[Point; 16]> - for Point +impl From<[Point; 16]> + for Point where - N: From<[::Element; 16]>, - N::Element: Scalar + Copy, - >>::Buffer: Copy, + T: From<[::Element; 16]>, + T::Element: Scalar + Copy, + >>::Buffer: Copy, { #[inline] - fn from(arr: [Point; 16]) -> Self { - Self::from(VectorN::from([ + fn from(arr: [Point; 16]) -> Self { + Self::from(OVector::from([ arr[0].coords, arr[1].coords, arr[2].coords, diff --git a/src/geometry/point_coordinates.rs b/src/geometry/point_coordinates.rs index 3d54d899..8d9e9ccc 100644 --- a/src/geometry/point_coordinates.rs +++ b/src/geometry/point_coordinates.rs @@ -13,10 +13,9 @@ use crate::geometry::Point; macro_rules! deref_impl( ($D: expr, $Target: ident $(, $comps: ident)*) => { - impl Deref for Point - // where DefaultAllocator: Allocator + impl Deref for Point { - type Target = $Target; + type Target = $Target; #[inline] fn deref(&self) -> &Self::Target { @@ -24,8 +23,7 @@ macro_rules! deref_impl( } } - impl DerefMut for Point - // where DefaultAllocator: Allocator + impl DerefMut for Point { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { diff --git a/src/geometry/point_ops.rs b/src/geometry/point_ops.rs index 4702b5bb..d1054364 100644 --- a/src/geometry/point_ops.rs +++ b/src/geometry/point_ops.rs @@ -20,11 +20,8 @@ use crate::geometry::Point; * Indexing. * */ -impl Index for Point -// where -// DefaultAllocator: Allocator, -{ - type Output = N; +impl Index for Point { + type Output = T; #[inline] fn index(&self, i: usize) -> &Self::Output { @@ -32,10 +29,7 @@ impl Index for Point } } -impl IndexMut for Point -// where -// DefaultAllocator: Allocator, -{ +impl IndexMut for Point { #[inline] fn index_mut(&mut self, i: usize) -> &mut Self::Output { &mut self.coords[i] @@ -47,10 +41,7 @@ impl IndexMut for Point * Neg. * */ -impl Neg for Point -// where -// DefaultAllocator: Allocator, -{ +impl Neg for Point { type Output = Self; #[inline] @@ -59,11 +50,8 @@ impl Neg for Point } } -impl<'a, N: Scalar + ClosedNeg, const D: usize> Neg for &'a Point -// where -// DefaultAllocator: Allocator, -{ - type Output = Point; +impl<'a, T: Scalar + ClosedNeg, const D: usize> Neg for &'a Point { + type Output = Point; #[inline] fn neg(self) -> Self::Output { @@ -81,25 +69,25 @@ impl<'a, N: Scalar + ClosedNeg, const D: usize> Neg for &'a Point add_sub_impl!(Sub, sub, ClosedSub; (Const, U1), (Const, U1) const D; for; where; - self: &'a Point, right: &'b Point, Output = VectorSum, Const>; + self: &'a Point, right: &'b Point, Output = VectorSum, Const>; &self.coords - &right.coords; 'a, 'b); add_sub_impl!(Sub, sub, ClosedSub; (Const, U1), (Const, U1) const D; for; where; - self: &'a Point, right: Point, Output = VectorSum, Const>; + self: &'a Point, right: Point, Output = VectorSum, Const>; &self.coords - right.coords; 'a); add_sub_impl!(Sub, sub, ClosedSub; (Const, U1), (Const, U1) const D; for; where; - self: Point, right: &'b Point, Output = VectorSum, Const>; + self: Point, right: &'b Point, Output = VectorSum, Const>; self.coords - &right.coords; 'b); add_sub_impl!(Sub, sub, ClosedSub; (Const, U1), (Const, U1) const D; for; where; - self: Point, right: Point, Output = VectorSum, Const>; + self: Point, right: Point, Output = VectorSum, Const>; self.coords - right.coords; ); // Point - Vector @@ -107,32 +95,32 @@ add_sub_impl!(Sub, sub, ClosedSub; (Const, U1), (D2, U1) -> (Const) const D1; for D2, SB; - where D2: Dim, SB: Storage; - self: &'a Point, right: &'b Vector, Output = Point; + where D2: Dim, SB: Storage; + self: &'a Point, right: &'b Vector, Output = Point; Self::Output::from(&self.coords - right); 'a, 'b); add_sub_impl!(Sub, sub, ClosedSub; (Const, U1), (D2, U1) -> (Const) const D1; for D2, SB; - where D2: Dim, SB: Storage; - self: &'a Point, right: Vector, Output = Point; + where D2: Dim, SB: Storage; + self: &'a Point, right: Vector, Output = Point; Self::Output::from(&self.coords - &right); 'a); // TODO: should not be a ref to `right`. add_sub_impl!(Sub, sub, ClosedSub; (Const, U1), (D2, U1) -> (Const) const D1; for D2, SB; - where D2: Dim, SB: Storage; - self: Point, right: &'b Vector, Output = Point; + where D2: Dim, SB: Storage; + self: Point, right: &'b Vector, Output = Point; Self::Output::from(self.coords - right); 'b); add_sub_impl!(Sub, sub, ClosedSub; (Const, U1), (D2, U1) -> (Const) const D1; for D2, SB; - where D2: Dim, SB: Storage; - self: Point, right: Vector, Output = Point; + where D2: Dim, SB: Storage; + self: Point, right: Vector, Output = Point; Self::Output::from(self.coords - right); ); // Point + Vector @@ -140,55 +128,55 @@ add_sub_impl!(Add, add, ClosedAdd; (Const, U1), (D2, U1) -> (Const) const D1; for D2, SB; - where D2: Dim, SB: Storage; - self: &'a Point, right: &'b Vector, Output = Point; + where D2: Dim, SB: Storage; + self: &'a Point, right: &'b Vector, Output = Point; Self::Output::from(&self.coords + right); 'a, 'b); add_sub_impl!(Add, add, ClosedAdd; (Const, U1), (D2, U1) -> (Const) const D1; for D2, SB; - where D2: Dim, SB: Storage; - self: &'a Point, right: Vector, Output = Point; + where D2: Dim, SB: Storage; + self: &'a Point, right: Vector, Output = Point; Self::Output::from(&self.coords + &right); 'a); // TODO: should not be a ref to `right`. add_sub_impl!(Add, add, ClosedAdd; (Const, U1), (D2, U1) -> (Const) const D1; for D2, SB; - where D2: Dim, SB: Storage; - self: Point, right: &'b Vector, Output = Point; + where D2: Dim, SB: Storage; + self: Point, right: &'b Vector, Output = Point; Self::Output::from(self.coords + right); 'b); add_sub_impl!(Add, add, ClosedAdd; (Const, U1), (D2, U1) -> (Const) const D1; for D2, SB; - where D2: Dim, SB: Storage; - self: Point, right: Vector, Output = Point; + where D2: Dim, SB: Storage; + self: Point, right: Vector, Output = Point; Self::Output::from(self.coords + right); ); // TODO: replace by the shared macro: add_sub_assign_impl? macro_rules! op_assign_impl( ($($TraitAssign: ident, $method_assign: ident, $bound: ident);* $(;)*) => {$( - impl<'b, N, D2: Dim, SB, const D1: usize> $TraitAssign<&'b Vector> for Point - where N: Scalar + $bound, - SB: Storage, + impl<'b, T, D2: Dim, SB, const D1: usize> $TraitAssign<&'b Vector> for Point + where T: Scalar + $bound, + SB: Storage, ShapeConstraint: SameNumberOfRows, D2> { #[inline] - fn $method_assign(&mut self, right: &'b Vector) { + fn $method_assign(&mut self, right: &'b Vector) { self.coords.$method_assign(right) } } - impl $TraitAssign> for Point - where N: Scalar + $bound, - SB: Storage, + impl $TraitAssign> for Point + where T: Scalar + $bound, + SB: Storage, ShapeConstraint: SameNumberOfRows, D2> { #[inline] - fn $method_assign(&mut self, right: Vector) { + fn $method_assign(&mut self, right: Vector) { self.coords.$method_assign(right) } } @@ -210,9 +198,9 @@ md_impl_all!( (Const, Const), (Const, U1) const D2, R1, C1; for SA; - where SA: Storage, Const>, + where SA: Storage, Const>, ShapeConstraint: AreMultipliable, Const, Const, U1>; - self: Matrix, Const, SA>, right: Point, Output = Point; + self: Matrix, Const, SA>, right: Point, Output = Point; [val val] => Point::from(self * right.coords); [ref val] => Point::from(self * right.coords); [val ref] => Point::from(self * &right.coords); @@ -227,33 +215,31 @@ md_impl_all!( macro_rules! componentwise_scalarop_impl( ($Trait: ident, $method: ident, $bound: ident; $TraitAssign: ident, $method_assign: ident) => { - impl $Trait for Point - // where DefaultAllocator: Allocator + impl $Trait for Point { - type Output = Point; + type Output = Point; #[inline] - fn $method(self, right: N) -> Self::Output { + fn $method(self, right: T) -> Self::Output { Point::from(self.coords.$method(right)) } } - impl<'a, N: Scalar + $bound, const D: usize> $Trait for &'a Point - // where DefaultAllocator: Allocator + impl<'a, T: Scalar + $bound, const D: usize> $Trait for &'a Point { - type Output = Point; + type Output = Point; #[inline] - fn $method(self, right: N) -> Self::Output { + fn $method(self, right: T) -> Self::Output { Point::from((&self.coords).$method(right)) } } - impl $TraitAssign for Point - /* where DefaultAllocator: Allocator */ + impl $TraitAssign for Point + /* where DefaultAllocator: Allocator */ { #[inline] - fn $method_assign(&mut self, right: N) { + fn $method_assign(&mut self, right: T) { self.coords.$method_assign(right) } } @@ -266,7 +252,6 @@ componentwise_scalarop_impl!(Div, div, ClosedDiv; DivAssign, div_assign); macro_rules! left_scalar_mul_impl( ($($T: ty),* $(,)*) => {$( impl Mul> for $T - // where DefaultAllocator: Allocator<$T, D> { type Output = Point<$T, D>; @@ -277,7 +262,6 @@ macro_rules! left_scalar_mul_impl( } impl<'b, const D: usize> Mul<&'b Point<$T, D>> for $T - // where DefaultAllocator: Allocator<$T, D> { type Output = Point<$T, D>; diff --git a/src/geometry/point_simba.rs b/src/geometry/point_simba.rs index b5f25be0..ad7433af 100644 --- a/src/geometry/point_simba.rs +++ b/src/geometry/point_simba.rs @@ -1,24 +1,24 @@ use simba::simd::SimdValue; -use crate::base::{Scalar, VectorN}; +use crate::base::{OVector, Scalar}; use crate::geometry::Point; -impl SimdValue for Point +impl SimdValue for Point where - N::Element: Scalar, + T::Element: Scalar, { - type Element = Point; - type SimdBool = N::SimdBool; + type Element = Point; + type SimdBool = T::SimdBool; #[inline] fn lanes() -> usize { - N::lanes() + T::lanes() } #[inline] fn splat(val: Self::Element) -> Self { - VectorN::splat(val.coords).into() + OVector::splat(val.coords).into() } #[inline] diff --git a/src/geometry/quaternion.rs b/src/geometry/quaternion.rs index 48a2d2ca..3a51d299 100755 --- a/src/geometry/quaternion.rs +++ b/src/geometry/quaternion.rs @@ -27,12 +27,12 @@ use crate::geometry::{Point3, Rotation}; /// that may be used as a rotation. #[repr(C)] #[derive(Debug, Copy, Clone, Hash, PartialEq, Eq)] -pub struct Quaternion { +pub struct Quaternion { /// This quaternion as a 4D vector of coordinates in the `[ x, y, z, w ]` storage order. - pub coords: Vector4, + pub coords: Vector4, } -impl Default for Quaternion { +impl Default for Quaternion { fn default() -> Self { Quaternion { coords: Vector4::zeros(), @@ -41,20 +41,20 @@ impl Default for Quaternion { } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Zeroable for Quaternion where Vector4: bytemuck::Zeroable {} +unsafe impl bytemuck::Zeroable for Quaternion where Vector4: bytemuck::Zeroable {} #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Pod for Quaternion +unsafe impl bytemuck::Pod for Quaternion where - Vector4: bytemuck::Pod, - N: Copy, + Vector4: bytemuck::Pod, + T: Copy, { } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Quaternion +impl Abomonation for Quaternion where - Vector4: Abomonation, + Vector4: Abomonation, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.coords.entomb(writer) @@ -70,9 +70,9 @@ where } #[cfg(feature = "serde-serialize")] -impl Serialize for Quaternion +impl Serialize for Quaternion where - Owned: Serialize, + Owned: Serialize, { fn serialize(&self, serializer: S) -> Result where @@ -83,23 +83,23 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N: Scalar> Deserialize<'a> for Quaternion +impl<'a, T: Scalar> Deserialize<'a> for Quaternion where - Owned: Deserialize<'a>, + Owned: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result where Des: Deserializer<'a>, { - let coords = Vector4::::deserialize(deserializer)?; + let coords = Vector4::::deserialize(deserializer)?; Ok(Self::from(coords)) } } -impl Quaternion +impl Quaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Moves this unit quaternion into one that owns its data. #[inline] @@ -133,7 +133,7 @@ where /// The imaginary part of this quaternion. #[inline] - pub fn imag(&self) -> Vector3 { + pub fn imag(&self) -> Vector3 { self.coords.xyz() } @@ -165,8 +165,8 @@ where /// assert_eq!(q1.lerp(&q2, 0.1), Quaternion::new(1.9, 3.8, 5.7, 7.6)); /// ``` #[inline] - pub fn lerp(&self, other: &Self, t: N) -> Self { - self * (N::one() - t) + other * t + pub fn lerp(&self, other: &Self, t: T) -> Self { + self * (T::one() - t) + other * t } /// The vector part `(i, j, k)` of this quaternion. @@ -180,8 +180,8 @@ where /// assert_eq!(q.vector()[2], 4.0); /// ``` #[inline] - pub fn vector(&self) -> MatrixSlice, CStride> { - self.coords.fixed_rows::(0) + pub fn vector(&self) -> MatrixSlice, CStride> { + self.coords.fixed_rows::<3>(0) } /// The scalar part `w` of this quaternion. @@ -193,7 +193,7 @@ where /// assert_eq!(q.scalar(), 1.0); /// ``` #[inline] - pub fn scalar(&self) -> N { + pub fn scalar(&self) -> T { self.coords[3] } @@ -208,7 +208,7 @@ where /// assert_eq!(*q.as_vector(), Vector4::new(2.0, 3.0, 4.0, 1.0)); /// ``` #[inline] - pub fn as_vector(&self) -> &Vector4 { + pub fn as_vector(&self) -> &Vector4 { &self.coords } @@ -222,7 +222,7 @@ where /// assert_relative_eq!(q.norm(), 5.47722557, epsilon = 1.0e-6); /// ``` #[inline] - pub fn norm(&self) -> N { + pub fn norm(&self) -> T { self.coords.norm() } @@ -239,7 +239,7 @@ where /// assert_relative_eq!(q.magnitude(), 5.47722557, epsilon = 1.0e-6); /// ``` #[inline] - pub fn magnitude(&self) -> N { + pub fn magnitude(&self) -> T { self.norm() } @@ -252,7 +252,7 @@ where /// assert_eq!(q.magnitude_squared(), 30.0); /// ``` #[inline] - pub fn norm_squared(&self) -> N { + pub fn norm_squared(&self) -> T { self.coords.norm_squared() } @@ -268,7 +268,7 @@ where /// assert_eq!(q.magnitude_squared(), 30.0); /// ``` #[inline] - pub fn magnitude_squared(&self) -> N { + pub fn magnitude_squared(&self) -> T { self.norm_squared() } @@ -282,14 +282,14 @@ where /// assert_eq!(q1.dot(&q2), 70.0); /// ``` #[inline] - pub fn dot(&self, rhs: &Self) -> N { + pub fn dot(&self, rhs: &Self) -> T { self.coords.dot(&rhs.coords) } } -impl Quaternion +impl Quaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Inverts this quaternion if it is not zero. /// @@ -315,7 +315,7 @@ where #[must_use = "Did you mean to use try_inverse_mut()?"] pub fn try_inverse(&self) -> Option where - N: RealField, + T: RealField, { let mut res = *self; @@ -333,7 +333,7 @@ where #[must_use = "Did you mean to use try_inverse_mut()?"] pub fn simd_try_inverse(&self) -> SimdOption { let norm_squared = self.norm_squared(); - let ge = norm_squared.simd_ge(N::simd_default_epsilon()); + let ge = norm_squared.simd_ge(T::simd_default_epsilon()); SimdOption::new(self.conjugate() / norm_squared, ge) } @@ -392,7 +392,7 @@ where #[inline] pub fn project(&self, other: &Self) -> Option where - N: RealField, + T: RealField, { self.inner(other).right_div(other) } @@ -414,7 +414,7 @@ where #[inline] pub fn reject(&self, other: &Self) -> Option where - N: RealField, + T: RealField, { self.outer(other).right_div(other) } @@ -434,20 +434,20 @@ where /// assert_eq!(half_ang, f32::consts::FRAC_PI_2); /// assert_eq!(axis, Some(Vector3::x_axis())); /// ``` - pub fn polar_decomposition(&self) -> (N, N, Option>>) + pub fn polar_decomposition(&self) -> (T, T, Option>>) where - N: RealField, + T: RealField, { - if let Some((q, n)) = Unit::try_new_and_get(*self, N::zero()) { - if let Some(axis) = Unit::try_new(self.vector().clone_owned(), N::zero()) { + if let Some((q, n)) = Unit::try_new_and_get(*self, T::zero()) { + if let Some(axis) = Unit::try_new(self.vector().clone_owned(), T::zero()) { let angle = q.angle() / crate::convert(2.0f64); (n, angle, Some(axis)) } else { - (n, N::zero(), None) + (n, T::zero(), None) } } else { - (N::zero(), N::zero(), None) + (T::zero(), T::zero(), None) } } @@ -480,7 +480,7 @@ where /// ``` #[inline] pub fn exp(&self) -> Self { - self.exp_eps(N::simd_default_epsilon()) + self.exp_eps(T::simd_default_epsilon()) } /// Compute the exponential of a quaternion. Returns the identity if the vector part of this quaternion @@ -498,7 +498,7 @@ where /// assert_eq!(q.exp_eps(1.0e-6), Quaternion::identity()); /// ``` #[inline] - pub fn exp_eps(&self, eps: N) -> Self { + pub fn exp_eps(&self, eps: T) -> Self { let v = self.vector(); let nn = v.norm_squared(); let le = nn.simd_le(eps * eps); @@ -521,7 +521,7 @@ where /// assert_relative_eq!(q.powf(1.5), Quaternion::new( -6.2576659, 4.1549037, 6.2323556, 8.3098075), epsilon = 1.0e-6); /// ``` #[inline] - pub fn powf(&self, n: N) -> Self { + pub fn powf(&self, n: T) -> Self { (self.ln() * n).exp() } @@ -535,7 +535,7 @@ where /// assert!(q.i == 1.0 && q.j == 2.0 && q.k == 3.0 && q.w == 4.0); /// ``` #[inline] - pub fn as_vector_mut(&mut self) -> &mut Vector4 { + pub fn as_vector_mut(&mut self) -> &mut Vector4 { &mut self.coords } @@ -556,8 +556,8 @@ where #[inline] pub fn vector_mut( &mut self, - ) -> MatrixSliceMut, CStride> { - self.coords.fixed_rows_mut::(0) + ) -> MatrixSliceMut, CStride> { + self.coords.fixed_rows_mut::<3>(0) } /// Replaces this quaternion by its conjugate. @@ -592,9 +592,9 @@ where /// assert!(!q.try_inverse_mut()); /// ``` #[inline] - pub fn try_inverse_mut(&mut self) -> N::SimdBool { + pub fn try_inverse_mut(&mut self) -> T::SimdBool { let norm_squared = self.norm_squared(); - let ge = norm_squared.simd_ge(N::simd_default_epsilon()); + let ge = norm_squared.simd_ge(T::simd_default_epsilon()); *self = ge.if_else(|| self.conjugate() / norm_squared, || *self); ge } @@ -610,7 +610,7 @@ where /// assert_relative_eq!(q.norm(), 1.0); /// ``` #[inline] - pub fn normalize_mut(&mut self) -> N { + pub fn normalize_mut(&mut self) -> T { self.coords.normalize_mut() } @@ -652,7 +652,7 @@ where #[inline] pub fn left_div(&self, other: &Self) -> Option where - N: RealField, + T: RealField, { other.try_inverse().map(|inv| inv * self) } @@ -674,7 +674,7 @@ where #[inline] pub fn right_div(&self, other: &Self) -> Option where - N: RealField, + T: RealField, { other.try_inverse().map(|inv| self * inv) } @@ -769,7 +769,7 @@ where #[inline] pub fn tan(&self) -> Self where - N: RealField, + T: RealField, { self.sin().right_div(&self.cos()).unwrap() } @@ -787,7 +787,7 @@ where #[inline] pub fn atan(&self) -> Self where - N: RealField, + T: RealField, { let u = Self::from_imag(self.imag().normalize()); let num = u + self; @@ -877,7 +877,7 @@ where #[inline] pub fn tanh(&self) -> Self where - N: RealField, + T: RealField, { self.sinh().right_div(&self.cosh()).unwrap() } @@ -900,12 +900,12 @@ where } } -impl> AbsDiffEq for Quaternion { - type Epsilon = N; +impl> AbsDiffEq for Quaternion { + type Epsilon = T; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -916,10 +916,10 @@ impl> AbsDiffEq for Quaternion { } } -impl> RelativeEq for Quaternion { +impl> RelativeEq for Quaternion { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -935,10 +935,10 @@ impl> RelativeEq for Quaternion { } } -impl> UlpsEq for Quaternion { +impl> UlpsEq for Quaternion { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] @@ -949,7 +949,7 @@ impl> UlpsEq for Quaternion { } } -impl fmt::Display for Quaternion { +impl fmt::Display for Quaternion { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!( f, @@ -960,9 +960,9 @@ impl fmt::Display for Quaternion { } /// A unit quaternions. May be used to represent a rotation. -pub type UnitQuaternion = Unit>; +pub type UnitQuaternion = Unit>; -impl PartialEq for UnitQuaternion { +impl PartialEq for UnitQuaternion { #[inline] fn eq(&self, rhs: &Self) -> bool { self.coords == rhs.coords || @@ -971,18 +971,18 @@ impl PartialEq for UnitQuaternion { } } -impl Eq for UnitQuaternion {} +impl Eq for UnitQuaternion {} -impl Normed for Quaternion { - type Norm = N::SimdRealField; +impl Normed for Quaternion { + type Norm = T::SimdRealField; #[inline] - fn norm(&self) -> N::SimdRealField { + fn norm(&self) -> T::SimdRealField { self.coords.norm() } #[inline] - fn norm_squared(&self) -> N::SimdRealField { + fn norm_squared(&self) -> T::SimdRealField { self.coords.norm_squared() } @@ -997,9 +997,9 @@ impl Normed for Quaternion { } } -impl UnitQuaternion +impl UnitQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// The rotation angle in [0; pi] of this unit quaternion. /// @@ -1011,7 +1011,7 @@ where /// assert_eq!(rot.angle(), 1.78); /// ``` #[inline] - pub fn angle(&self) -> N { + pub fn angle(&self) -> T { let w = self.quaternion().scalar().simd_abs(); self.quaternion().imag().norm().simd_atan2(w) * crate::convert(2.0f64) } @@ -1027,7 +1027,7 @@ where /// assert_eq!(*axis.quaternion(), Quaternion::new(1.0, 0.0, 0.0, 0.0)); /// ``` #[inline] - pub fn quaternion(&self) -> &Quaternion { + pub fn quaternion(&self) -> &Quaternion { self.as_ref() } @@ -1075,7 +1075,7 @@ where /// assert_relative_eq!(rot1.angle_to(&rot2), 1.0045657, epsilon = 1.0e-6); /// ``` #[inline] - pub fn angle_to(&self, other: &Self) -> N { + pub fn angle_to(&self, other: &Self) -> T { let delta = self.rotation_to(other); delta.angle() } @@ -1110,7 +1110,7 @@ where /// assert_eq!(q1.lerp(&q2, 0.1), Quaternion::new(0.9, 0.1, 0.0, 0.0)); /// ``` #[inline] - pub fn lerp(&self, other: &Self, t: N) -> Quaternion { + pub fn lerp(&self, other: &Self, t: T) -> Quaternion { self.as_ref().lerp(other.as_ref(), t) } @@ -1126,7 +1126,7 @@ where /// assert_eq!(q1.nlerp(&q2, 0.1), UnitQuaternion::new_normalize(Quaternion::new(0.9, 0.1, 0.0, 0.0))); /// ``` #[inline] - pub fn nlerp(&self, other: &Self, t: N) -> Self { + pub fn nlerp(&self, other: &Self, t: T) -> Self { let mut res = self.lerp(other, t); let _ = res.normalize_mut(); @@ -1151,11 +1151,11 @@ where /// assert_eq!(q.euler_angles(), (std::f32::consts::FRAC_PI_2, 0.0, 0.0)); /// ``` #[inline] - pub fn slerp(&self, other: &Self, t: N) -> Self + pub fn slerp(&self, other: &Self, t: T) -> Self where - N: RealField, + T: RealField, { - self.try_slerp(other, t, N::default_epsilon()) + self.try_slerp(other, t, T::default_epsilon()) .expect("Quaternion slerp: ambiguous configuration.") } @@ -1170,11 +1170,11 @@ where /// * `epsilon`: the value below which the sinus of the angle separating both quaternion /// must be to return `None`. #[inline] - pub fn try_slerp(&self, other: &Self, t: N, epsilon: N) -> Option + pub fn try_slerp(&self, other: &Self, t: T, epsilon: T) -> Option where - N: RealField, + T: RealField, { - let coords = if self.coords.dot(&other.coords) < N::zero() { + let coords = if self.coords.dot(&other.coords) < T::zero() { Unit::new_unchecked(self.coords).try_slerp( &Unit::new_unchecked(-other.coords), t, @@ -1229,17 +1229,17 @@ where /// assert!(rot.axis().is_none()); /// ``` #[inline] - pub fn axis(&self) -> Option>> + pub fn axis(&self) -> Option>> where - N: RealField, + T: RealField, { - let v = if self.quaternion().scalar() >= N::zero() { + let v = if self.quaternion().scalar() >= T::zero() { self.as_ref().vector().clone_owned() } else { -self.as_ref().vector() }; - Unit::try_new(v, N::zero()) + Unit::try_new(v, T::zero()) } /// The rotation axis of this unit quaternion multiplied by the rotation angle. @@ -1253,9 +1253,9 @@ where /// assert_relative_eq!(rot.scaled_axis(), axisangle, epsilon = 1.0e-6); /// ``` #[inline] - pub fn scaled_axis(&self) -> Vector3 + pub fn scaled_axis(&self) -> Vector3 where - N: RealField, + T: RealField, { if let Some(axis) = self.axis() { axis.into_inner() * self.angle() @@ -1281,24 +1281,24 @@ where /// assert!(rot.axis_angle().is_none()); /// ``` #[inline] - pub fn axis_angle(&self) -> Option<(Unit>, N)> + pub fn axis_angle(&self) -> Option<(Unit>, T)> where - N: RealField, + T: RealField, { self.axis().map(|axis| (axis, self.angle())) } /// Compute the exponential of a quaternion. /// - /// Note that this function yields a `Quaternion` because it loses the unit property. + /// Note that this function yields a `Quaternion` because it loses the unit property. #[inline] - pub fn exp(&self) -> Quaternion { + pub fn exp(&self) -> Quaternion { self.as_ref().exp() } /// Compute the natural logarithm of a quaternion. /// - /// Note that this function yields a `Quaternion` because it loses the unit property. + /// Note that this function yields a `Quaternion` because it loses the unit property. /// The vector part of the return value corresponds to the axis-angle representation (divided /// by 2.0) of this unit quaternion. /// @@ -1311,9 +1311,9 @@ where /// assert_relative_eq!(q.ln().vector().into_owned(), axisangle, epsilon = 1.0e-6); /// ``` #[inline] - pub fn ln(&self) -> Quaternion + pub fn ln(&self) -> Quaternion where - N: RealField, + T: RealField, { if let Some(v) = self.axis() { Quaternion::from_imag(v.into_inner() * self.angle()) @@ -1339,9 +1339,9 @@ where /// assert_eq!(pow.angle(), 2.4); /// ``` #[inline] - pub fn powf(&self, n: N) -> Self + pub fn powf(&self, n: T) -> Self where - N: RealField, + T: RealField, { if let Some(v) = self.axis() { Self::from_axis_angle(&v, self.angle() * n) @@ -1367,7 +1367,7 @@ where /// assert_relative_eq!(*rot.matrix(), expected, epsilon = 1.0e-6); /// ``` #[inline] - pub fn to_rotation_matrix(&self) -> Rotation { + pub fn to_rotation_matrix(&self) -> Rotation { let i = self.as_ref()[0]; let j = self.as_ref()[1]; let k = self.as_ref()[2]; @@ -1402,9 +1402,9 @@ where /// The angles are produced in the form (roll, pitch, yaw). #[inline] #[deprecated(note = "This is renamed to use `.euler_angles()`.")] - pub fn to_euler_angles(&self) -> (N, N, N) + pub fn to_euler_angles(&self) -> (T, T, T) where - N: RealField, + T: RealField, { self.euler_angles() } @@ -1424,9 +1424,9 @@ where /// assert_relative_eq!(euler.2, 0.3, epsilon = 1.0e-6); /// ``` #[inline] - pub fn euler_angles(&self) -> (N, N, N) + pub fn euler_angles(&self) -> (T, T, T) where - N: RealField, + T: RealField, { self.to_rotation_matrix().euler_angles() } @@ -1448,7 +1448,7 @@ where /// assert_relative_eq!(rot.to_homogeneous(), expected, epsilon = 1.0e-6); /// ``` #[inline] - pub fn to_homogeneous(&self) -> Matrix4 { + pub fn to_homogeneous(&self) -> Matrix4 { self.to_rotation_matrix().to_homogeneous() } @@ -1468,7 +1468,7 @@ where /// assert_relative_eq!(transformed_point, Point3::new(3.0, 2.0, -1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn transform_point(&self, pt: &Point3) -> Point3 { + pub fn transform_point(&self, pt: &Point3) -> Point3 { self * pt } @@ -1488,7 +1488,7 @@ where /// assert_relative_eq!(transformed_vector, Vector3::new(3.0, 2.0, -1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn transform_vector(&self, v: &Vector3) -> Vector3 { + pub fn transform_vector(&self, v: &Vector3) -> Vector3 { self * v } @@ -1508,7 +1508,7 @@ where /// assert_relative_eq!(transformed_point, Point3::new(-3.0, 2.0, 1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_point(&self, pt: &Point3) -> Point3 { + pub fn inverse_transform_point(&self, pt: &Point3) -> Point3 { // TODO: would it be useful performancewise not to call inverse explicitly (i-e. implement // the inverse transformation explicitly here) ? self.inverse() * pt @@ -1530,7 +1530,7 @@ where /// assert_relative_eq!(transformed_vector, Vector3::new(-3.0, 2.0, 1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_vector(&self, v: &Vector3) -> Vector3 { + pub fn inverse_transform_vector(&self, v: &Vector3) -> Vector3 { self.inverse() * v } @@ -1550,7 +1550,7 @@ where /// assert_relative_eq!(transformed_vector, -Vector3::y_axis(), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { + pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { self.inverse() * v } @@ -1558,21 +1558,21 @@ where /// /// This is faster, but approximate, way to compute `UnitQuaternion::new(axisangle) * self`. #[inline] - pub fn append_axisangle_linearized(&self, axisangle: &Vector3) -> Self { - let half: N = crate::convert(0.5); + pub fn append_axisangle_linearized(&self, axisangle: &Vector3) -> Self { + let half: T = crate::convert(0.5); let q1 = self.into_inner(); let q2 = Quaternion::from_imag(axisangle * half); Unit::new_normalize(q1 + q2 * q1) } } -impl Default for UnitQuaternion { +impl Default for UnitQuaternion { fn default() -> Self { Self::identity() } } -impl fmt::Display for UnitQuaternion { +impl fmt::Display for UnitQuaternion { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { if let Some(axis) = self.axis() { let axis = axis.into_inner(); @@ -1594,12 +1594,12 @@ impl fmt::Display for UnitQuaternion { } } -impl> AbsDiffEq for UnitQuaternion { - type Epsilon = N; +impl> AbsDiffEq for UnitQuaternion { + type Epsilon = T; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -1608,10 +1608,10 @@ impl> AbsDiffEq for UnitQuaternion { } } -impl> RelativeEq for UnitQuaternion { +impl> RelativeEq for UnitQuaternion { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -1626,10 +1626,10 @@ impl> RelativeEq for UnitQuaternion { } } -impl> UlpsEq for UnitQuaternion { +impl> UlpsEq for UnitQuaternion { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] diff --git a/src/geometry/quaternion_construction.rs b/src/geometry/quaternion_construction.rs index 1b87dba0..d3ce3763 100644 --- a/src/geometry/quaternion_construction.rs +++ b/src/geometry/quaternion_construction.rs @@ -23,12 +23,12 @@ use crate::{Scalar, SimdRealField}; use crate::geometry::{Quaternion, Rotation3, UnitQuaternion}; -impl Quaternion { +impl Quaternion { /// Creates a quaternion from a 4D vector. The quaternion scalar part corresponds to the `w` /// vector component. #[inline] #[deprecated(note = "Use `::from` instead.")] - pub fn from_vector(vector: Vector4) -> Self { + pub fn from_vector(vector: Vector4) -> Self { Self { coords: vector } } @@ -46,7 +46,7 @@ impl Quaternion { /// assert_eq!(*q.as_vector(), Vector4::new(2.0, 3.0, 4.0, 1.0)); /// ``` #[inline] - pub fn new(w: N, i: N, j: N, k: N) -> Self { + pub fn new(w: T, i: T, j: T, k: T) -> Self { Self::from(Vector4::new(i, j, k, w)) } @@ -61,17 +61,17 @@ impl Quaternion { /// ``` pub fn cast(self) -> Quaternion where - To: SupersetOf, + To: SupersetOf, { crate::convert(self) } } -impl Quaternion { +impl Quaternion { /// Constructs a pure quaternion. #[inline] - pub fn from_imag(vector: Vector3) -> Self { - Self::from_parts(N::zero(), vector) + pub fn from_imag(vector: Vector3) -> Self { + Self::from_parts(T::zero(), vector) } /// Creates a new quaternion from its scalar and vector parts. Note that the arguments order does @@ -90,16 +90,16 @@ impl Quaternion { /// ``` #[inline] // TODO: take a reference to `vector`? - pub fn from_parts(scalar: N, vector: Vector) -> Self + pub fn from_parts(scalar: T, vector: Vector) -> Self where - SB: Storage, + SB: Storage, { Self::new(scalar, vector[0], vector[1], vector[2]) } /// Constructs a real quaternion. #[inline] - pub fn from_real(r: N) -> Self { + pub fn from_real(r: T) -> Self { Self::from_parts(r, Vector3::zero()) } @@ -116,32 +116,32 @@ impl Quaternion { /// ``` #[inline] pub fn identity() -> Self { - Self::from_real(N::one()) + Self::from_real(T::one()) } } // TODO: merge with the previous block. -impl Quaternion +impl Quaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Creates a new quaternion from its polar decomposition. /// /// Note that `axis` is assumed to be a unit vector. // TODO: take a reference to `axis`? - pub fn from_polar_decomposition(scale: N, theta: N, axis: Unit>) -> Self + pub fn from_polar_decomposition(scale: T, theta: T, axis: Unit>) -> Self where - SB: Storage, + SB: Storage, { - let rot = UnitQuaternion::::from_axis_angle(&axis, theta * crate::convert(2.0f64)); + let rot = UnitQuaternion::::from_axis_angle(&axis, theta * crate::convert(2.0f64)); rot.into_inner() * scale } } -impl One for Quaternion +impl One for Quaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] fn one() -> Self { @@ -149,9 +149,9 @@ where } } -impl Zero for Quaternion +impl Zero for Quaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] fn zero() -> Self { @@ -165,35 +165,35 @@ where } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - Standard: Distribution, + Standard: Distribution, { #[inline] - fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> Quaternion { + fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> Quaternion { Quaternion::new(rng.gen(), rng.gen(), rng.gen(), rng.gen()) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Quaternion +impl Arbitrary for Quaternion where - Owned: Send, + Owned: Send, { #[inline] fn arbitrary(g: &mut Gen) -> Self { Self::new( - N::arbitrary(g), - N::arbitrary(g), - N::arbitrary(g), - N::arbitrary(g), + T::arbitrary(g), + T::arbitrary(g), + T::arbitrary(g), + T::arbitrary(g), ) } } -impl UnitQuaternion +impl UnitQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// The rotation identity. /// @@ -227,7 +227,7 @@ where /// ``` pub fn cast(self) -> UnitQuaternion where - To: SupersetOf, + To: SupersetOf, { crate::convert(self) } @@ -256,9 +256,9 @@ where /// assert_eq!(UnitQuaternion::from_scaled_axis(Vector3::::zeros()), UnitQuaternion::identity()); /// ``` #[inline] - pub fn from_axis_angle(axis: &Unit>, angle: N) -> Self + pub fn from_axis_angle(axis: &Unit>, angle: T) -> Self where - SB: Storage, + SB: Storage, { let (sang, cang) = (angle / crate::convert(2.0f64)).simd_sin_cos(); @@ -270,7 +270,7 @@ where /// /// The input quaternion will be normalized. #[inline] - pub fn from_quaternion(q: Quaternion) -> Self { + pub fn from_quaternion(q: Quaternion) -> Self { Self::new_normalize(q) } @@ -289,7 +289,7 @@ where /// assert_relative_eq!(euler.2, 0.3, epsilon = 1.0e-6); /// ``` #[inline] - pub fn from_euler_angles(roll: N, pitch: N, yaw: N) -> Self { + pub fn from_euler_angles(roll: T, pitch: T, yaw: T) -> Self { let (sr, cr) = (roll * crate::convert(0.5f64)).simd_sin_cos(); let (sp, cp) = (pitch * crate::convert(0.5f64)).simd_sin_cos(); let (sy, cy) = (yaw * crate::convert(0.5f64)).simd_sin_cos(); @@ -310,7 +310,7 @@ where /// orthonormal basis, i.e., all vectors are normalized, and the are /// all orthogonal to each other. These invariants are not checked /// by this method. - pub fn from_basis_unchecked(basis: &[Vector3; 3]) -> Self { + pub fn from_basis_unchecked(basis: &[Vector3; 3]) -> Self { let rot = Rotation3::from_basis_unchecked(basis); Self::from_rotation_matrix(&rot) } @@ -330,15 +330,15 @@ where /// assert_relative_eq!(q.angle(), rot.angle(), epsilon = 1.0e-6); /// ``` #[inline] - pub fn from_rotation_matrix(rotmat: &Rotation3) -> Self { + pub fn from_rotation_matrix(rotmat: &Rotation3) -> Self { // Robust matrix to quaternion transformation. // See https://www.euclideanspace.com/maths/geometry/rotations/conversions/matrixToQuaternion let tr = rotmat[(0, 0)] + rotmat[(1, 1)] + rotmat[(2, 2)]; - let quarter: N = crate::convert(0.25); + let quarter: T = crate::convert(0.25); - let res = tr.simd_gt(N::zero()).if_else3( + let res = tr.simd_gt(T::zero()).if_else3( || { - let denom = (tr + N::one()).simd_sqrt() * crate::convert(2.0); + let denom = (tr + T::one()).simd_sqrt() * crate::convert(2.0); Quaternion::new( quarter * denom, (rotmat[(2, 1)] - rotmat[(1, 2)]) / denom, @@ -349,7 +349,7 @@ where ( || rotmat[(0, 0)].simd_gt(rotmat[(1, 1)]) & rotmat[(0, 0)].simd_gt(rotmat[(2, 2)]), || { - let denom = (N::one() + rotmat[(0, 0)] - rotmat[(1, 1)] - rotmat[(2, 2)]) + let denom = (T::one() + rotmat[(0, 0)] - rotmat[(1, 1)] - rotmat[(2, 2)]) .simd_sqrt() * crate::convert(2.0); Quaternion::new( @@ -363,7 +363,7 @@ where ( || rotmat[(1, 1)].simd_gt(rotmat[(2, 2)]), || { - let denom = (N::one() + rotmat[(1, 1)] - rotmat[(0, 0)] - rotmat[(2, 2)]) + let denom = (T::one() + rotmat[(1, 1)] - rotmat[(0, 0)] - rotmat[(2, 2)]) .simd_sqrt() * crate::convert(2.0); Quaternion::new( @@ -375,7 +375,7 @@ where }, ), || { - let denom = (N::one() + rotmat[(2, 2)] - rotmat[(0, 0)] - rotmat[(1, 1)]) + let denom = (T::one() + rotmat[(2, 2)] - rotmat[(0, 0)] - rotmat[(1, 1)]) .simd_sqrt() * crate::convert(2.0); Quaternion::new( @@ -395,9 +395,9 @@ where /// This is an iterative method. See `.from_matrix_eps` to provide mover /// convergence parameters and starting solution. /// This implements "A Robust Method to Extract the Rotational Part of Deformations" by Müller et al. - pub fn from_matrix(m: &Matrix3) -> Self + pub fn from_matrix(m: &Matrix3) -> Self where - N: RealField, + T: RealField, { Rotation3::from_matrix(m).into() } @@ -414,9 +414,9 @@ where /// * `guess`: an estimate of the solution. Convergence will be significantly faster if an initial solution close /// to the actual solution is provided. Can be set to `UnitQuaternion::identity()` if no other /// guesses come to mind. - pub fn from_matrix_eps(m: &Matrix3, eps: N, max_iter: usize, guess: Self) -> Self + pub fn from_matrix_eps(m: &Matrix3, eps: T, max_iter: usize, guess: Self) -> Self where - N: RealField, + T: RealField, { let guess = Rotation3::from(guess); Rotation3::from_matrix_eps(m, eps, max_iter, guess).into() @@ -437,13 +437,13 @@ where /// assert_relative_eq!(q.inverse() * b, a); /// ``` #[inline] - pub fn rotation_between(a: &Vector, b: &Vector) -> Option + pub fn rotation_between(a: &Vector, b: &Vector) -> Option where - N: RealField, - SB: Storage, - SC: Storage, + T: RealField, + SB: Storage, + SC: Storage, { - Self::scaled_rotation_between(a, b, N::one()) + Self::scaled_rotation_between(a, b, T::one()) } /// The smallest rotation needed to make `a` and `b` collinear and point toward the same @@ -462,19 +462,19 @@ where /// ``` #[inline] pub fn scaled_rotation_between( - a: &Vector, - b: &Vector, - s: N, + a: &Vector, + b: &Vector, + s: T, ) -> Option where - N: RealField, - SB: Storage, - SC: Storage, + T: RealField, + SB: Storage, + SC: Storage, { // TODO: code duplication with Rotation. if let (Some(na), Some(nb)) = ( - Unit::try_new(a.clone_owned(), N::zero()), - Unit::try_new(b.clone_owned(), N::zero()), + Unit::try_new(a.clone_owned(), T::zero()), + Unit::try_new(b.clone_owned(), T::zero()), ) { Self::scaled_rotation_between_axis(&na, &nb, s) } else { @@ -497,15 +497,15 @@ where /// ``` #[inline] pub fn rotation_between_axis( - a: &Unit>, - b: &Unit>, + a: &Unit>, + b: &Unit>, ) -> Option where - N: RealField, - SB: Storage, - SC: Storage, + T: RealField, + SB: Storage, + SC: Storage, { - Self::scaled_rotation_between_axis(a, b, N::one()) + Self::scaled_rotation_between_axis(a, b, T::one()) } /// The smallest rotation needed to make `a` and `b` collinear and point toward the same @@ -524,30 +524,30 @@ where /// ``` #[inline] pub fn scaled_rotation_between_axis( - na: &Unit>, - nb: &Unit>, - s: N, + na: &Unit>, + nb: &Unit>, + s: T, ) -> Option where - N: RealField, - SB: Storage, - SC: Storage, + T: RealField, + SB: Storage, + SC: Storage, { // TODO: code duplication with Rotation. let c = na.cross(&nb); - if let Some(axis) = Unit::try_new(c, N::default_epsilon()) { + if let Some(axis) = Unit::try_new(c, T::default_epsilon()) { let cos = na.dot(&nb); // The cosinus may be out of [-1, 1] because of inaccuracies. - if cos <= -N::one() { + if cos <= -T::one() { None - } else if cos >= N::one() { + } else if cos >= T::one() { Some(Self::identity()) } else { Some(Self::from_axis_angle(&axis, cos.acos() * s)) } - } else if na.dot(&nb) < N::zero() { + } else if na.dot(&nb) < T::zero() { // PI // // The rotation axis is undefined but the angle not zero. This is not a @@ -582,20 +582,20 @@ where /// assert_relative_eq!(q * Vector3::z(), dir.normalize()); /// ``` #[inline] - pub fn face_towards(dir: &Vector, up: &Vector) -> Self + pub fn face_towards(dir: &Vector, up: &Vector) -> Self where - SB: Storage, - SC: Storage, + SB: Storage, + SC: Storage, { Self::from_rotation_matrix(&Rotation3::face_towards(dir, up)) } /// Deprecated: Use [UnitQuaternion::face_towards] instead. #[deprecated(note = "renamed to `face_towards`")] - pub fn new_observer_frames(dir: &Vector, up: &Vector) -> Self + pub fn new_observer_frames(dir: &Vector, up: &Vector) -> Self where - SB: Storage, - SC: Storage, + SB: Storage, + SC: Storage, { Self::face_towards(dir, up) } @@ -623,10 +623,10 @@ where /// assert_relative_eq!(q * dir.normalize(), -Vector3::z()); /// ``` #[inline] - pub fn look_at_rh(dir: &Vector, up: &Vector) -> Self + pub fn look_at_rh(dir: &Vector, up: &Vector) -> Self where - SB: Storage, - SC: Storage, + SB: Storage, + SC: Storage, { Self::face_towards(&-dir, up).inverse() } @@ -654,17 +654,17 @@ where /// assert_relative_eq!(q * dir.normalize(), Vector3::z()); /// ``` #[inline] - pub fn look_at_lh(dir: &Vector, up: &Vector) -> Self + pub fn look_at_lh(dir: &Vector, up: &Vector) -> Self where - SB: Storage, - SC: Storage, + SB: Storage, + SC: Storage, { Self::face_towards(dir, up).inverse() } /// Creates a new unit quaternion rotation from a rotation axis scaled by the rotation angle. /// - /// If `axisangle` has a magnitude smaller than `N::default_epsilon()`, this returns the identity rotation. + /// If `axisangle` has a magnitude smaller than `T::default_epsilon()`, this returns the identity rotation. /// /// # Example /// ``` @@ -684,12 +684,12 @@ where /// assert_eq!(UnitQuaternion::new(Vector3::::zeros()), UnitQuaternion::identity()); /// ``` #[inline] - pub fn new(axisangle: Vector) -> Self + pub fn new(axisangle: Vector) -> Self where - SB: Storage, + SB: Storage, { - let two: N = crate::convert(2.0f64); - let q = Quaternion::::from_imag(axisangle / two).exp(); + let two: T = crate::convert(2.0f64); + let q = Quaternion::::from_imag(axisangle / two).exp(); Self::new_unchecked(q) } @@ -715,18 +715,18 @@ where /// assert_eq!(UnitQuaternion::new_eps(Vector3::new(1.0e-8, 1.0e-9, 1.0e-7), 1.0e-6), UnitQuaternion::identity()); /// ``` #[inline] - pub fn new_eps(axisangle: Vector, eps: N) -> Self + pub fn new_eps(axisangle: Vector, eps: T) -> Self where - SB: Storage, + SB: Storage, { - let two: N = crate::convert(2.0f64); - let q = Quaternion::::from_imag(axisangle / two).exp_eps(eps); + let two: T = crate::convert(2.0f64); + let q = Quaternion::::from_imag(axisangle / two).exp_eps(eps); Self::new_unchecked(q) } /// Creates a new unit quaternion rotation from a rotation axis scaled by the rotation angle. /// - /// If `axisangle` has a magnitude smaller than `N::default_epsilon()`, this returns the identity rotation. + /// If `axisangle` has a magnitude smaller than `T::default_epsilon()`, this returns the identity rotation. /// Same as `Self::new(axisangle)`. /// /// # Example @@ -747,9 +747,9 @@ where /// assert_eq!(UnitQuaternion::from_scaled_axis(Vector3::::zeros()), UnitQuaternion::identity()); /// ``` #[inline] - pub fn from_scaled_axis(axisangle: Vector) -> Self + pub fn from_scaled_axis(axisangle: Vector) -> Self where - SB: Storage, + SB: Storage, { Self::new(axisangle) } @@ -777,9 +777,9 @@ where /// assert_eq!(UnitQuaternion::from_scaled_axis_eps(Vector3::new(1.0e-8, 1.0e-9, 1.0e-7), 1.0e-6), UnitQuaternion::identity()); /// ``` #[inline] - pub fn from_scaled_axis_eps(axisangle: Vector, eps: N) -> Self + pub fn from_scaled_axis_eps(axisangle: Vector, eps: T) -> Self where - SB: Storage, + SB: Storage, { Self::new_eps(axisangle, eps) } @@ -811,9 +811,9 @@ where #[inline] pub fn mean_of(unit_quaternions: impl IntoIterator) -> Self where - N: RealField, + T: RealField, { - let quaternions_matrix: Matrix4 = unit_quaternions + let quaternions_matrix: Matrix4 = unit_quaternions .into_iter() .map(|q| q.as_vector() * q.as_vector().transpose()) .sum(); @@ -821,7 +821,7 @@ where assert!(!quaternions_matrix.is_zero()); let eigen_matrix = quaternions_matrix - .try_symmetric_eigen(N::RealField::default_epsilon(), 10) + .try_symmetric_eigen(T::RealField::default_epsilon(), 10) .expect("Quaternions matrix could not be diagonalized. This behavior should not be possible."); let max_eigenvalue_index = eigen_matrix @@ -840,9 +840,9 @@ where } } -impl One for UnitQuaternion +impl One for UnitQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] fn one() -> Self { @@ -851,37 +851,37 @@ where } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - N::Element: SimdRealField, - OpenClosed01: Distribution, - N: SampleUniform, + T::Element: SimdRealField, + OpenClosed01: Distribution, + T: SampleUniform, { /// Generate a uniformly distributed random rotation quaternion. #[inline] - fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> UnitQuaternion { + fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> UnitQuaternion { // Ken Shoemake's Subgroup Algorithm // Uniform random rotations. // In D. Kirk, editor, Graphics Gems III, pages 124-132. Academic, New York, 1992. let x0 = rng.sample(OpenClosed01); - let twopi = Uniform::new(N::zero(), N::simd_two_pi()); + let twopi = Uniform::new(T::zero(), T::simd_two_pi()); let theta1 = rng.sample(&twopi); let theta2 = rng.sample(&twopi); let s1 = theta1.simd_sin(); let c1 = theta1.simd_cos(); let s2 = theta2.simd_sin(); let c2 = theta2.simd_cos(); - let r1 = (N::one() - x0).simd_sqrt(); + let r1 = (T::one() - x0).simd_sqrt(); let r2 = x0.simd_sqrt(); Unit::new_unchecked(Quaternion::new(s1 * r1, c1 * r1, s2 * r2, c2 * r2)) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for UnitQuaternion +impl Arbitrary for UnitQuaternion where - Owned: Send, - Owned: Send, + Owned: Send, + Owned: Send, { #[inline] fn arbitrary(g: &mut Gen) -> Self { diff --git a/src/geometry/quaternion_conversion.rs b/src/geometry/quaternion_conversion.rs index c1b18221..6dfbfbc6 100644 --- a/src/geometry/quaternion_conversion.rs +++ b/src/geometry/quaternion_conversion.rs @@ -26,253 +26,253 @@ use crate::geometry::{ * UnitQuaternion -> Quaternion is already provided by: Unit -> T */ -impl SubsetOf> for Quaternion +impl SubsetOf> for Quaternion where - N1: Scalar, - N2: Scalar + SupersetOf, + T1: Scalar, + T2: Scalar + SupersetOf, { #[inline] - fn to_superset(&self) -> Quaternion { + fn to_superset(&self) -> Quaternion { Quaternion::from(self.coords.to_superset()) } #[inline] - fn is_in_subset(q: &Quaternion) -> bool { - crate::is_convertible::<_, Vector4>(&q.coords) + fn is_in_subset(q: &Quaternion) -> bool { + crate::is_convertible::<_, Vector4>(&q.coords) } #[inline] - fn from_superset_unchecked(q: &Quaternion) -> Self { + fn from_superset_unchecked(q: &Quaternion) -> Self { Self { coords: q.coords.to_subset_unchecked(), } } } -impl SubsetOf> for UnitQuaternion +impl SubsetOf> for UnitQuaternion where - N1: Scalar, - N2: Scalar + SupersetOf, + T1: Scalar, + T2: Scalar + SupersetOf, { #[inline] - fn to_superset(&self) -> UnitQuaternion { + fn to_superset(&self) -> UnitQuaternion { UnitQuaternion::new_unchecked(self.as_ref().to_superset()) } #[inline] - fn is_in_subset(uq: &UnitQuaternion) -> bool { - crate::is_convertible::<_, Quaternion>(uq.as_ref()) + fn is_in_subset(uq: &UnitQuaternion) -> bool { + crate::is_convertible::<_, Quaternion>(uq.as_ref()) } #[inline] - fn from_superset_unchecked(uq: &UnitQuaternion) -> Self { + fn from_superset_unchecked(uq: &UnitQuaternion) -> Self { Self::new_unchecked(crate::convert_ref_unchecked(uq.as_ref())) } } -impl SubsetOf> for UnitQuaternion +impl SubsetOf> for UnitQuaternion where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, { #[inline] - fn to_superset(&self) -> Rotation3 { - let q: UnitQuaternion = self.to_superset(); + fn to_superset(&self) -> Rotation3 { + let q: UnitQuaternion = self.to_superset(); q.to_rotation_matrix() } #[inline] - fn is_in_subset(rot: &Rotation3) -> bool { - crate::is_convertible::<_, Rotation3>(rot) + fn is_in_subset(rot: &Rotation3) -> bool { + crate::is_convertible::<_, Rotation3>(rot) } #[inline] - fn from_superset_unchecked(rot: &Rotation3) -> Self { - let q = UnitQuaternion::::from_rotation_matrix(rot); + fn from_superset_unchecked(rot: &Rotation3) -> Self { + let q = UnitQuaternion::::from_rotation_matrix(rot); crate::convert_unchecked(q) } } -impl SubsetOf> for UnitQuaternion +impl SubsetOf> for UnitQuaternion where - N1: RealField, - N2: RealField + SupersetOf, - R: AbstractRotation + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, + R: AbstractRotation + SupersetOf, { #[inline] - fn to_superset(&self) -> Isometry { + fn to_superset(&self) -> Isometry { Isometry::from_parts(Translation::identity(), crate::convert_ref(self)) } #[inline] - fn is_in_subset(iso: &Isometry) -> bool { + fn is_in_subset(iso: &Isometry) -> bool { iso.translation.vector.is_zero() } #[inline] - fn from_superset_unchecked(iso: &Isometry) -> Self { + fn from_superset_unchecked(iso: &Isometry) -> Self { crate::convert_ref_unchecked(&iso.rotation) } } -impl SubsetOf> for UnitQuaternion +impl SubsetOf> for UnitQuaternion where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, { #[inline] - fn to_superset(&self) -> UnitDualQuaternion { - let q: UnitQuaternion = crate::convert_ref(self); + fn to_superset(&self) -> UnitDualQuaternion { + let q: UnitQuaternion = crate::convert_ref(self); UnitDualQuaternion::from_rotation(q) } #[inline] - fn is_in_subset(dq: &UnitDualQuaternion) -> bool { + fn is_in_subset(dq: &UnitDualQuaternion) -> bool { dq.translation().vector.is_zero() } #[inline] - fn from_superset_unchecked(dq: &UnitDualQuaternion) -> Self { + fn from_superset_unchecked(dq: &UnitDualQuaternion) -> Self { crate::convert_unchecked(dq.rotation()) } } -impl SubsetOf> for UnitQuaternion +impl SubsetOf> for UnitQuaternion where - N1: RealField, - N2: RealField + SupersetOf, - R: AbstractRotation + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, + R: AbstractRotation + SupersetOf, { #[inline] - fn to_superset(&self) -> Similarity { - Similarity::from_isometry(crate::convert_ref(self), N2::one()) + fn to_superset(&self) -> Similarity { + Similarity::from_isometry(crate::convert_ref(self), T2::one()) } #[inline] - fn is_in_subset(sim: &Similarity) -> bool { - sim.isometry.translation.vector.is_zero() && sim.scaling() == N2::one() + fn is_in_subset(sim: &Similarity) -> bool { + sim.isometry.translation.vector.is_zero() && sim.scaling() == T2::one() } #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { + fn from_superset_unchecked(sim: &Similarity) -> Self { crate::convert_ref_unchecked(&sim.isometry) } } -impl SubsetOf> for UnitQuaternion +impl SubsetOf> for UnitQuaternion where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, C: SuperTCategoryOf, { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl> SubsetOf> for UnitQuaternion { +impl> SubsetOf> for UnitQuaternion { #[inline] - fn to_superset(&self) -> Matrix4 { + fn to_superset(&self) -> Matrix4 { self.to_homogeneous().to_superset() } #[inline] - fn is_in_subset(m: &Matrix4) -> bool { - crate::is_convertible::<_, Rotation3>(m) + fn is_in_subset(m: &Matrix4) -> bool { + crate::is_convertible::<_, Rotation3>(m) } #[inline] - fn from_superset_unchecked(m: &Matrix4) -> Self { - let rot: Rotation3 = crate::convert_ref_unchecked(m); + fn from_superset_unchecked(m: &Matrix4) -> Self { + let rot: Rotation3 = crate::convert_ref_unchecked(m); Self::from_rotation_matrix(&rot) } } -impl From> for Matrix4 +impl From> for Matrix4 where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn from(q: UnitQuaternion) -> Self { + fn from(q: UnitQuaternion) -> Self { q.to_homogeneous() } } -impl From> for Rotation3 +impl From> for Rotation3 where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn from(q: UnitQuaternion) -> Self { + fn from(q: UnitQuaternion) -> Self { q.to_rotation_matrix() } } -impl From> for UnitQuaternion +impl From> for UnitQuaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn from(q: Rotation3) -> Self { + fn from(q: Rotation3) -> Self { Self::from_rotation_matrix(&q) } } -impl From> for Matrix3 +impl From> for Matrix3 where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn from(q: UnitQuaternion) -> Self { + fn from(q: UnitQuaternion) -> Self { q.to_rotation_matrix().into_inner() } } -impl From> for Quaternion { +impl From> for Quaternion { #[inline] - fn from(coords: Vector4) -> Self { + fn from(coords: Vector4) -> Self { Self { coords } } } -impl From<[N; 4]> for Quaternion { +impl From<[T; 4]> for Quaternion { #[inline] - fn from(coords: [N; 4]) -> Self { + fn from(coords: [T; 4]) -> Self { Self { coords: coords.into(), } } } -impl From<[Quaternion; 2]> for Quaternion +impl From<[Quaternion; 2]> for Quaternion where - N: From<[::Element; 2]>, - N::Element: Scalar + Copy, + T: From<[::Element; 2]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [Quaternion; 2]) -> Self { + fn from(arr: [Quaternion; 2]) -> Self { Self::from(Vector4::from([arr[0].coords, arr[1].coords])) } } -impl From<[Quaternion; 4]> for Quaternion +impl From<[Quaternion; 4]> for Quaternion where - N: From<[::Element; 4]>, - N::Element: Scalar + Copy, + T: From<[::Element; 4]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [Quaternion; 4]) -> Self { + fn from(arr: [Quaternion; 4]) -> Self { Self::from(Vector4::from([ arr[0].coords, arr[1].coords, @@ -282,13 +282,13 @@ where } } -impl From<[Quaternion; 8]> for Quaternion +impl From<[Quaternion; 8]> for Quaternion where - N: From<[::Element; 8]>, - N::Element: Scalar + Copy, + T: From<[::Element; 8]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [Quaternion; 8]) -> Self { + fn from(arr: [Quaternion; 8]) -> Self { Self::from(Vector4::from([ arr[0].coords, arr[1].coords, @@ -302,13 +302,13 @@ where } } -impl From<[Quaternion; 16]> for Quaternion +impl From<[Quaternion; 16]> for Quaternion where - N: From<[::Element; 16]>, - N::Element: Scalar + Copy, + T: From<[::Element; 16]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [Quaternion; 16]) -> Self { + fn from(arr: [Quaternion; 16]) -> Self { Self::from(Vector4::from([ arr[0].coords, arr[1].coords, @@ -330,26 +330,26 @@ where } } -impl From<[UnitQuaternion; 2]> - for UnitQuaternion +impl From<[UnitQuaternion; 2]> + for UnitQuaternion where - N: From<[::Element; 2]>, - N::Element: Scalar + Copy, + T: From<[::Element; 2]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [UnitQuaternion; 2]) -> Self { + fn from(arr: [UnitQuaternion; 2]) -> Self { Self::new_unchecked(Quaternion::from([arr[0].into_inner(), arr[1].into_inner()])) } } -impl From<[UnitQuaternion; 4]> - for UnitQuaternion +impl From<[UnitQuaternion; 4]> + for UnitQuaternion where - N: From<[::Element; 4]>, - N::Element: Scalar + Copy, + T: From<[::Element; 4]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [UnitQuaternion; 4]) -> Self { + fn from(arr: [UnitQuaternion; 4]) -> Self { Self::new_unchecked(Quaternion::from([ arr[0].into_inner(), arr[1].into_inner(), @@ -359,14 +359,14 @@ where } } -impl From<[UnitQuaternion; 8]> - for UnitQuaternion +impl From<[UnitQuaternion; 8]> + for UnitQuaternion where - N: From<[::Element; 8]>, - N::Element: Scalar + Copy, + T: From<[::Element; 8]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [UnitQuaternion; 8]) -> Self { + fn from(arr: [UnitQuaternion; 8]) -> Self { Self::new_unchecked(Quaternion::from([ arr[0].into_inner(), arr[1].into_inner(), @@ -380,14 +380,14 @@ where } } -impl From<[UnitQuaternion; 16]> - for UnitQuaternion +impl From<[UnitQuaternion; 16]> + for UnitQuaternion where - N: From<[::Element; 16]>, - N::Element: Scalar + Copy, + T: From<[::Element; 16]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [UnitQuaternion; 16]) -> Self { + fn from(arr: [UnitQuaternion; 16]) -> Self { Self::new_unchecked(Quaternion::from([ arr[0].into_inner(), arr[1].into_inner(), diff --git a/src/geometry/quaternion_coordinates.rs b/src/geometry/quaternion_coordinates.rs index 0d318087..d9901888 100644 --- a/src/geometry/quaternion_coordinates.rs +++ b/src/geometry/quaternion_coordinates.rs @@ -8,8 +8,8 @@ use crate::Scalar; use crate::geometry::Quaternion; -impl Deref for Quaternion { - type Target = IJKW; +impl Deref for Quaternion { + type Target = IJKW; #[inline] fn deref(&self) -> &Self::Target { @@ -17,7 +17,7 @@ impl Deref for Quaternion { } } -impl DerefMut for Quaternion { +impl DerefMut for Quaternion { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { unsafe { mem::transmute(self) } diff --git a/src/geometry/quaternion_ops.rs b/src/geometry/quaternion_ops.rs index c19984f3..6a2c87a0 100644 --- a/src/geometry/quaternion_ops.rs +++ b/src/geometry/quaternion_ops.rs @@ -61,8 +61,8 @@ use crate::SimdRealField; use crate::geometry::{Point3, Quaternion, Rotation, UnitQuaternion}; -impl Index for Quaternion { - type Output = N; +impl Index for Quaternion { + type Output = T; #[inline] fn index(&self, i: usize) -> &Self::Output { @@ -70,9 +70,9 @@ impl Index for Quaternion { } } -impl IndexMut for Quaternion { +impl IndexMut for Quaternion { #[inline] - fn index_mut(&mut self, i: usize) -> &mut N { + fn index_mut(&mut self, i: usize) -> &mut T { &mut self.coords[i] } } @@ -82,8 +82,8 @@ macro_rules! quaternion_op_impl( $($Storage: ident: $StoragesBound: ident $(<$($BoundParam: ty),*>)*),*; $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Result: ty; $action: expr; $($lives: tt),*) => { - impl<$($lives ,)* N: SimdRealField $(, $Storage: $StoragesBound $(<$($BoundParam),*>)*)*> $Op<$Rhs> for $Lhs - where N::Element: SimdRealField { + impl<$($lives ,)* T: SimdRealField $(, $Storage: $StoragesBound $(<$($BoundParam),*>)*)*> $Op<$Rhs> for $Lhs + where T::Element: SimdRealField { type Output = $Result; #[inline] @@ -98,63 +98,63 @@ macro_rules! quaternion_op_impl( quaternion_op_impl!( Add, add; ; - self: &'a Quaternion, rhs: &'b Quaternion, Output = Quaternion; + self: &'a Quaternion, rhs: &'b Quaternion, Output = Quaternion; Quaternion::from(&self.coords + &rhs.coords); 'a, 'b); quaternion_op_impl!( Add, add; ; - self: &'a Quaternion, rhs: Quaternion, Output = Quaternion; + self: &'a Quaternion, rhs: Quaternion, Output = Quaternion; Quaternion::from(&self.coords + rhs.coords); 'a); quaternion_op_impl!( Add, add; ; - self: Quaternion, rhs: &'b Quaternion, Output = Quaternion; + self: Quaternion, rhs: &'b Quaternion, Output = Quaternion; Quaternion::from(self.coords + &rhs.coords); 'b); quaternion_op_impl!( Add, add; ; - self: Quaternion, rhs: Quaternion, Output = Quaternion; + self: Quaternion, rhs: Quaternion, Output = Quaternion; Quaternion::from(self.coords + rhs.coords); ); // Quaternion - Quaternion quaternion_op_impl!( Sub, sub; ; - self: &'a Quaternion, rhs: &'b Quaternion, Output = Quaternion; + self: &'a Quaternion, rhs: &'b Quaternion, Output = Quaternion; Quaternion::from(&self.coords - &rhs.coords); 'a, 'b); quaternion_op_impl!( Sub, sub; ; - self: &'a Quaternion, rhs: Quaternion, Output = Quaternion; + self: &'a Quaternion, rhs: Quaternion, Output = Quaternion; Quaternion::from(&self.coords - rhs.coords); 'a); quaternion_op_impl!( Sub, sub; ; - self: Quaternion, rhs: &'b Quaternion, Output = Quaternion; + self: Quaternion, rhs: &'b Quaternion, Output = Quaternion; Quaternion::from(self.coords - &rhs.coords); 'b); quaternion_op_impl!( Sub, sub; ; - self: Quaternion, rhs: Quaternion, Output = Quaternion; + self: Quaternion, rhs: Quaternion, Output = Quaternion; Quaternion::from(self.coords - rhs.coords); ); // Quaternion × Quaternion quaternion_op_impl!( Mul, mul; ; - self: &'a Quaternion, rhs: &'b Quaternion, Output = Quaternion; + self: &'a Quaternion, rhs: &'b Quaternion, Output = Quaternion; Quaternion::new( self[3] * rhs[3] - self[0] * rhs[0] - self[1] * rhs[1] - self[2] * rhs[2], self[3] * rhs[0] + self[0] * rhs[3] + self[1] * rhs[2] - self[2] * rhs[1], @@ -165,219 +165,219 @@ quaternion_op_impl!( quaternion_op_impl!( Mul, mul; ; - self: &'a Quaternion, rhs: Quaternion, Output = Quaternion; + self: &'a Quaternion, rhs: Quaternion, Output = Quaternion; self * &rhs; 'a); quaternion_op_impl!( Mul, mul; ; - self: Quaternion, rhs: &'b Quaternion, Output = Quaternion; + self: Quaternion, rhs: &'b Quaternion, Output = Quaternion; &self * rhs; 'b); quaternion_op_impl!( Mul, mul; ; - self: Quaternion, rhs: Quaternion, Output = Quaternion; + self: Quaternion, rhs: Quaternion, Output = Quaternion; &self * &rhs; ); // UnitQuaternion × UnitQuaternion quaternion_op_impl!( Mul, mul; ; - self: &'a UnitQuaternion, rhs: &'b UnitQuaternion, Output = UnitQuaternion; + self: &'a UnitQuaternion, rhs: &'b UnitQuaternion, Output = UnitQuaternion; UnitQuaternion::new_unchecked(self.quaternion() * rhs.quaternion()); 'a, 'b); quaternion_op_impl!( Mul, mul; ; - self: &'a UnitQuaternion, rhs: UnitQuaternion, Output = UnitQuaternion; + self: &'a UnitQuaternion, rhs: UnitQuaternion, Output = UnitQuaternion; self * &rhs; 'a); quaternion_op_impl!( Mul, mul; ; - self: UnitQuaternion, rhs: &'b UnitQuaternion, Output = UnitQuaternion; + self: UnitQuaternion, rhs: &'b UnitQuaternion, Output = UnitQuaternion; &self * rhs; 'b); quaternion_op_impl!( Mul, mul; ; - self: UnitQuaternion, rhs: UnitQuaternion, Output = UnitQuaternion; + self: UnitQuaternion, rhs: UnitQuaternion, Output = UnitQuaternion; &self * &rhs; ); // UnitQuaternion ÷ UnitQuaternion quaternion_op_impl!( Div, div; ; - self: &'a UnitQuaternion, rhs: &'b UnitQuaternion, Output = UnitQuaternion; + self: &'a UnitQuaternion, rhs: &'b UnitQuaternion, Output = UnitQuaternion; #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; 'a, 'b); quaternion_op_impl!( Div, div; ; - self: &'a UnitQuaternion, rhs: UnitQuaternion, Output = UnitQuaternion; + self: &'a UnitQuaternion, rhs: UnitQuaternion, Output = UnitQuaternion; self / &rhs; 'a); quaternion_op_impl!( Div, div; ; - self: UnitQuaternion, rhs: &'b UnitQuaternion, Output = UnitQuaternion; + self: UnitQuaternion, rhs: &'b UnitQuaternion, Output = UnitQuaternion; &self / rhs; 'b); quaternion_op_impl!( Div, div; ; - self: UnitQuaternion, rhs: UnitQuaternion, Output = UnitQuaternion; + self: UnitQuaternion, rhs: UnitQuaternion, Output = UnitQuaternion; &self / &rhs; ); // UnitQuaternion × Rotation quaternion_op_impl!( Mul, mul; ; - self: &'a UnitQuaternion, rhs: &'b Rotation, - Output = UnitQuaternion; + self: &'a UnitQuaternion, rhs: &'b Rotation, + Output = UnitQuaternion; // TODO: can we avoid the conversion from a rotation matrix? - self * UnitQuaternion::::from_rotation_matrix(rhs); + self * UnitQuaternion::::from_rotation_matrix(rhs); 'a, 'b); quaternion_op_impl!( Mul, mul; ; - self: &'a UnitQuaternion, rhs: Rotation, - Output = UnitQuaternion; - self * UnitQuaternion::::from_rotation_matrix(&rhs); + self: &'a UnitQuaternion, rhs: Rotation, + Output = UnitQuaternion; + self * UnitQuaternion::::from_rotation_matrix(&rhs); 'a); quaternion_op_impl!( Mul, mul; ; - self: UnitQuaternion, rhs: &'b Rotation, - Output = UnitQuaternion; - self * UnitQuaternion::::from_rotation_matrix(rhs); + self: UnitQuaternion, rhs: &'b Rotation, + Output = UnitQuaternion; + self * UnitQuaternion::::from_rotation_matrix(rhs); 'b); quaternion_op_impl!( Mul, mul; ; - self: UnitQuaternion, rhs: Rotation, - Output = UnitQuaternion; - self * UnitQuaternion::::from_rotation_matrix(&rhs); ); + self: UnitQuaternion, rhs: Rotation, + Output = UnitQuaternion; + self * UnitQuaternion::::from_rotation_matrix(&rhs); ); // UnitQuaternion ÷ Rotation quaternion_op_impl!( Div, div; ; - self: &'a UnitQuaternion, rhs: &'b Rotation, - Output = UnitQuaternion; + self: &'a UnitQuaternion, rhs: &'b Rotation, + Output = UnitQuaternion; // TODO: can we avoid the conversion to a rotation matrix? - self / UnitQuaternion::::from_rotation_matrix(rhs); + self / UnitQuaternion::::from_rotation_matrix(rhs); 'a, 'b); quaternion_op_impl!( Div, div; ; - self: &'a UnitQuaternion, rhs: Rotation, - Output = UnitQuaternion; - self / UnitQuaternion::::from_rotation_matrix(&rhs); + self: &'a UnitQuaternion, rhs: Rotation, + Output = UnitQuaternion; + self / UnitQuaternion::::from_rotation_matrix(&rhs); 'a); quaternion_op_impl!( Div, div; ; - self: UnitQuaternion, rhs: &'b Rotation, - Output = UnitQuaternion; - self / UnitQuaternion::::from_rotation_matrix(rhs); + self: UnitQuaternion, rhs: &'b Rotation, + Output = UnitQuaternion; + self / UnitQuaternion::::from_rotation_matrix(rhs); 'b); quaternion_op_impl!( Div, div; ; - self: UnitQuaternion, rhs: Rotation, - Output = UnitQuaternion; - self / UnitQuaternion::::from_rotation_matrix(&rhs); ); + self: UnitQuaternion, rhs: Rotation, + Output = UnitQuaternion; + self / UnitQuaternion::::from_rotation_matrix(&rhs); ); // Rotation × UnitQuaternion quaternion_op_impl!( Mul, mul; ; - self: &'a Rotation, rhs: &'b UnitQuaternion, - Output = UnitQuaternion; + self: &'a Rotation, rhs: &'b UnitQuaternion, + Output = UnitQuaternion; // TODO: can we avoid the conversion from a rotation matrix? - UnitQuaternion::::from_rotation_matrix(self) * rhs; + UnitQuaternion::::from_rotation_matrix(self) * rhs; 'a, 'b); quaternion_op_impl!( Mul, mul; ; - self: &'a Rotation, rhs: UnitQuaternion, - Output = UnitQuaternion; - UnitQuaternion::::from_rotation_matrix(self) * rhs; + self: &'a Rotation, rhs: UnitQuaternion, + Output = UnitQuaternion; + UnitQuaternion::::from_rotation_matrix(self) * rhs; 'a); quaternion_op_impl!( Mul, mul; ; - self: Rotation, rhs: &'b UnitQuaternion, - Output = UnitQuaternion; - UnitQuaternion::::from_rotation_matrix(&self) * rhs; + self: Rotation, rhs: &'b UnitQuaternion, + Output = UnitQuaternion; + UnitQuaternion::::from_rotation_matrix(&self) * rhs; 'b); quaternion_op_impl!( Mul, mul; ; - self: Rotation, rhs: UnitQuaternion, - Output = UnitQuaternion; - UnitQuaternion::::from_rotation_matrix(&self) * rhs; ); + self: Rotation, rhs: UnitQuaternion, + Output = UnitQuaternion; + UnitQuaternion::::from_rotation_matrix(&self) * rhs; ); // Rotation ÷ UnitQuaternion quaternion_op_impl!( Div, div; ; - self: &'a Rotation, rhs: &'b UnitQuaternion, - Output = UnitQuaternion; + self: &'a Rotation, rhs: &'b UnitQuaternion, + Output = UnitQuaternion; // TODO: can we avoid the conversion from a rotation matrix? - UnitQuaternion::::from_rotation_matrix(self) / rhs; + UnitQuaternion::::from_rotation_matrix(self) / rhs; 'a, 'b); quaternion_op_impl!( Div, div; ; - self: &'a Rotation, rhs: UnitQuaternion, - Output = UnitQuaternion; - UnitQuaternion::::from_rotation_matrix(self) / rhs; + self: &'a Rotation, rhs: UnitQuaternion, + Output = UnitQuaternion; + UnitQuaternion::::from_rotation_matrix(self) / rhs; 'a); quaternion_op_impl!( Div, div; ; - self: Rotation, rhs: &'b UnitQuaternion, - Output = UnitQuaternion; - UnitQuaternion::::from_rotation_matrix(&self) / rhs; + self: Rotation, rhs: &'b UnitQuaternion, + Output = UnitQuaternion; + UnitQuaternion::::from_rotation_matrix(&self) / rhs; 'b); quaternion_op_impl!( Div, div; ; - self: Rotation, rhs: UnitQuaternion, - Output = UnitQuaternion; - UnitQuaternion::::from_rotation_matrix(&self) / rhs; ); + self: Rotation, rhs: UnitQuaternion, + Output = UnitQuaternion; + UnitQuaternion::::from_rotation_matrix(&self) / rhs; ); // UnitQuaternion × Vector quaternion_op_impl!( Mul, mul; - SB: Storage> ; - self: &'a UnitQuaternion, rhs: &'b Vector, SB>, - Output = Vector3; + SB: Storage> ; + self: &'a UnitQuaternion, rhs: &'b Vector, SB>, + Output = Vector3; { - let two: N = crate::convert(2.0f64); + let two: T = crate::convert(2.0f64); let t = self.as_ref().vector().cross(rhs) * two; let cross = self.as_ref().vector().cross(&t); @@ -387,118 +387,118 @@ quaternion_op_impl!( quaternion_op_impl!( Mul, mul; - SB: Storage> ; - self: &'a UnitQuaternion, rhs: Vector, - Output = Vector3; + SB: Storage> ; + self: &'a UnitQuaternion, rhs: Vector, + Output = Vector3; self * &rhs; 'a); quaternion_op_impl!( Mul, mul; - SB: Storage> ; - self: UnitQuaternion, rhs: &'b Vector, - Output = Vector3; + SB: Storage> ; + self: UnitQuaternion, rhs: &'b Vector, + Output = Vector3; &self * rhs; 'b); quaternion_op_impl!( Mul, mul; - SB: Storage> ; - self: UnitQuaternion, rhs: Vector, - Output = Vector3; + SB: Storage> ; + self: UnitQuaternion, rhs: Vector, + Output = Vector3; &self * &rhs; ); // UnitQuaternion × Point quaternion_op_impl!( Mul, mul; ; - self: &'a UnitQuaternion, rhs: &'b Point3, - Output = Point3; + self: &'a UnitQuaternion, rhs: &'b Point3, + Output = Point3; Point3::from(self * &rhs.coords); 'a, 'b); quaternion_op_impl!( Mul, mul; ; - self: &'a UnitQuaternion, rhs: Point3, - Output = Point3; + self: &'a UnitQuaternion, rhs: Point3, + Output = Point3; Point3::from(self * rhs.coords); 'a); quaternion_op_impl!( Mul, mul; ; - self: UnitQuaternion, rhs: &'b Point3, - Output = Point3; + self: UnitQuaternion, rhs: &'b Point3, + Output = Point3; Point3::from(self * &rhs.coords); 'b); quaternion_op_impl!( Mul, mul; ; - self: UnitQuaternion, rhs: Point3, - Output = Point3; + self: UnitQuaternion, rhs: Point3, + Output = Point3; Point3::from(self * rhs.coords); ); // UnitQuaternion × Unit quaternion_op_impl!( Mul, mul; - SB: Storage> ; - self: &'a UnitQuaternion, rhs: &'b Unit>, - Output = Unit>; + SB: Storage> ; + self: &'a UnitQuaternion, rhs: &'b Unit>, + Output = Unit>; Unit::new_unchecked(self * rhs.as_ref()); 'a, 'b); quaternion_op_impl!( Mul, mul; - SB: Storage> ; - self: &'a UnitQuaternion, rhs: Unit>, - Output = Unit>; + SB: Storage> ; + self: &'a UnitQuaternion, rhs: Unit>, + Output = Unit>; Unit::new_unchecked(self * rhs.into_inner()); 'a); quaternion_op_impl!( Mul, mul; - SB: Storage> ; - self: UnitQuaternion, rhs: &'b Unit>, - Output = Unit>; + SB: Storage> ; + self: UnitQuaternion, rhs: &'b Unit>, + Output = Unit>; Unit::new_unchecked(self * rhs.as_ref()); 'b); quaternion_op_impl!( Mul, mul; - SB: Storage> ; - self: UnitQuaternion, rhs: Unit>, - Output = Unit>; + SB: Storage> ; + self: UnitQuaternion, rhs: Unit>, + Output = Unit>; Unit::new_unchecked(self * rhs.into_inner()); ); macro_rules! scalar_op_impl( ($($Op: ident, $op: ident, $OpAssign: ident, $op_assign: ident);* $(;)*) => {$( - impl $Op for Quaternion - where N::Element: SimdRealField { - type Output = Quaternion; + impl $Op for Quaternion + where T::Element: SimdRealField { + type Output = Quaternion; #[inline] - fn $op(self, n: N) -> Self::Output { + fn $op(self, n: T) -> Self::Output { Quaternion::from(self.coords.$op(n)) } } - impl<'a, N: SimdRealField> $Op for &'a Quaternion - where N::Element: SimdRealField { - type Output = Quaternion; + impl<'a, T: SimdRealField> $Op for &'a Quaternion + where T::Element: SimdRealField { + type Output = Quaternion; #[inline] - fn $op(self, n: N) -> Self::Output { + fn $op(self, n: T) -> Self::Output { Quaternion::from((&self.coords).$op(n)) } } - impl $OpAssign for Quaternion - where N::Element: SimdRealField { + impl $OpAssign for Quaternion + where T::Element: SimdRealField { #[inline] - fn $op_assign(&mut self, n: N) { + fn $op_assign(&mut self, n: T) { self.coords.$op_assign(n) } } @@ -534,11 +534,11 @@ macro_rules! left_scalar_mul_impl( left_scalar_mul_impl!(f32, f64); -impl Neg for Quaternion +impl Neg for Quaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { - type Output = Quaternion; + type Output = Quaternion; #[inline] fn neg(self) -> Self::Output { @@ -546,11 +546,11 @@ where } } -impl<'a, N: SimdRealField> Neg for &'a Quaternion +impl<'a, T: SimdRealField> Neg for &'a Quaternion where - N::Element: SimdRealField, + T::Element: SimdRealField, { - type Output = Quaternion; + type Output = Quaternion; #[inline] fn neg(self) -> Self::Output { @@ -562,8 +562,8 @@ macro_rules! quaternion_op_impl( ($OpAssign: ident, $op_assign: ident; $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty $(=> $VDimA: ty, $VDimB: ty)*; $action: expr; $($lives: tt),*) => { - impl<$($lives ,)* N: SimdRealField> $OpAssign<$Rhs> for $Lhs - where N::Element: SimdRealField { + impl<$($lives ,)* T: SimdRealField> $OpAssign<$Rhs> for $Lhs + where T::Element: SimdRealField { #[inline] fn $op_assign(&mut $lhs, $rhs: $Rhs) { @@ -576,31 +576,31 @@ macro_rules! quaternion_op_impl( // Quaternion += Quaternion quaternion_op_impl!( AddAssign, add_assign; - self: Quaternion, rhs: &'b Quaternion; + self: Quaternion, rhs: &'b Quaternion; self.coords += &rhs.coords; 'b); quaternion_op_impl!( AddAssign, add_assign; - self: Quaternion, rhs: Quaternion; + self: Quaternion, rhs: Quaternion; self.coords += rhs.coords; ); // Quaternion -= Quaternion quaternion_op_impl!( SubAssign, sub_assign; - self: Quaternion, rhs: &'b Quaternion; + self: Quaternion, rhs: &'b Quaternion; self.coords -= &rhs.coords; 'b); quaternion_op_impl!( SubAssign, sub_assign; - self: Quaternion, rhs: Quaternion; + self: Quaternion, rhs: Quaternion; self.coords -= rhs.coords; ); // Quaternion ×= Quaternion quaternion_op_impl!( MulAssign, mul_assign; - self: Quaternion, rhs: &'b Quaternion; + self: Quaternion, rhs: &'b Quaternion; { let res = &*self * rhs; // TODO: will this be optimized away? @@ -610,13 +610,13 @@ quaternion_op_impl!( quaternion_op_impl!( MulAssign, mul_assign; - self: Quaternion, rhs: Quaternion; + self: Quaternion, rhs: Quaternion; *self *= &rhs; ); // UnitQuaternion ×= UnitQuaternion quaternion_op_impl!( MulAssign, mul_assign; - self: UnitQuaternion, rhs: &'b UnitQuaternion; + self: UnitQuaternion, rhs: &'b UnitQuaternion; { let res = &*self * rhs; self.as_mut_unchecked().coords.copy_from(&res.as_ref().coords); @@ -625,13 +625,13 @@ quaternion_op_impl!( quaternion_op_impl!( MulAssign, mul_assign; - self: UnitQuaternion, rhs: UnitQuaternion; + self: UnitQuaternion, rhs: UnitQuaternion; *self *= &rhs; ); // UnitQuaternion ÷= UnitQuaternion quaternion_op_impl!( DivAssign, div_assign; - self: UnitQuaternion, rhs: &'b UnitQuaternion; + self: UnitQuaternion, rhs: &'b UnitQuaternion; { let res = &*self / rhs; self.as_mut_unchecked().coords.copy_from(&res.as_ref().coords); @@ -640,13 +640,13 @@ quaternion_op_impl!( quaternion_op_impl!( DivAssign, div_assign; - self: UnitQuaternion, rhs: UnitQuaternion; + self: UnitQuaternion, rhs: UnitQuaternion; *self /= &rhs; ); // UnitQuaternion ×= Rotation quaternion_op_impl!( MulAssign, mul_assign; - self: UnitQuaternion, rhs: &'b Rotation; + self: UnitQuaternion, rhs: &'b Rotation; { let res = &*self * rhs; self.as_mut_unchecked().coords.copy_from(&res.as_ref().coords); @@ -655,13 +655,13 @@ quaternion_op_impl!( quaternion_op_impl!( MulAssign, mul_assign; - self: UnitQuaternion, rhs: Rotation; + self: UnitQuaternion, rhs: Rotation; *self *= &rhs; ); // UnitQuaternion ÷= Rotation quaternion_op_impl!( DivAssign, div_assign; - self: UnitQuaternion, rhs: &'b Rotation; + self: UnitQuaternion, rhs: &'b Rotation; { let res = &*self / rhs; self.as_mut_unchecked().coords.copy_from(&res.as_ref().coords); @@ -670,5 +670,5 @@ quaternion_op_impl!( quaternion_op_impl!( DivAssign, div_assign; - self: UnitQuaternion, rhs: Rotation; + self: UnitQuaternion, rhs: Rotation; *self /= &rhs; ); diff --git a/src/geometry/quaternion_simba.rs b/src/geometry/quaternion_simba.rs index b43db8d9..162d7a63 100755 --- a/src/geometry/quaternion_simba.rs +++ b/src/geometry/quaternion_simba.rs @@ -4,16 +4,16 @@ use crate::base::Vector4; use crate::geometry::{Quaternion, UnitQuaternion}; use crate::Scalar; -impl SimdValue for Quaternion +impl SimdValue for Quaternion where - N::Element: Scalar, + T::Element: Scalar, { - type Element = Quaternion; - type SimdBool = N::SimdBool; + type Element = Quaternion; + type SimdBool = T::SimdBool; #[inline] fn lanes() -> usize { - N::lanes() + T::lanes() } #[inline] @@ -47,16 +47,16 @@ where } } -impl SimdValue for UnitQuaternion +impl SimdValue for UnitQuaternion where - N::Element: Scalar, + T::Element: Scalar, { - type Element = UnitQuaternion; - type SimdBool = N::SimdBool; + type Element = UnitQuaternion; + type SimdBool = T::SimdBool; #[inline] fn lanes() -> usize { - N::lanes() + T::lanes() } #[inline] diff --git a/src/geometry/reflection.rs b/src/geometry/reflection.rs index 7ed220ca..e48c700a 100644 --- a/src/geometry/reflection.rs +++ b/src/geometry/reflection.rs @@ -7,26 +7,26 @@ use simba::scalar::ComplexField; use crate::geometry::Point; /// A reflection wrt. a plane. -pub struct Reflection> { - axis: Vector, - bias: N, +pub struct Reflection> { + axis: Vector, + bias: T, } -impl>, const D: usize> Reflection, S> { +impl>, const D: usize> Reflection, S> { /// Creates a new reflection wrt. the plane orthogonal to the given axis and that contains the /// point `pt`. - pub fn new_containing_point(axis: Unit, S>>, pt: &Point) -> Self { + pub fn new_containing_point(axis: Unit, S>>, pt: &Point) -> Self { let bias = axis.dotc(&pt.coords); Self::new(axis, bias) } } -impl> Reflection { +impl> Reflection { /// Creates a new reflection wrt the plane orthogonal to the given axis and bias. /// /// The bias is the position of the plane on the axis. In particular, a bias equal to zero /// represents a plane that passes through the origin. - pub fn new(axis: Unit>, bias: N) -> Self { + pub fn new(axis: Unit>, bias: T) -> Self { Self { axis: axis.into_inner(), bias, @@ -34,32 +34,32 @@ impl> Reflection { } /// The reflexion axis. - pub fn axis(&self) -> &Vector { + pub fn axis(&self) -> &Vector { &self.axis } // TODO: naming convention: reflect_to, reflect_assign ? /// Applies the reflection to the columns of `rhs`. - pub fn reflect(&self, rhs: &mut Matrix) + pub fn reflect(&self, rhs: &mut Matrix) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { for i in 0..rhs.ncols() { // NOTE: we borrow the column twice here. First it is borrowed immutably for the // dot product, and then mutably. Somehow, this allows significantly // better optimizations of the dot product from the compiler. - let m_two: N = crate::convert(-2.0f64); + let m_two: T = crate::convert(-2.0f64); let factor = (self.axis.dotc(&rhs.column(i)) - self.bias) * m_two; - rhs.column_mut(i).axpy(factor, &self.axis, N::one()); + rhs.column_mut(i).axpy(factor, &self.axis, T::one()); } } // TODO: naming convention: reflect_to, reflect_assign ? /// Applies the reflection to the columns of `rhs`. - pub fn reflect_with_sign(&self, rhs: &mut Matrix, sign: N) + pub fn reflect_with_sign(&self, rhs: &mut Matrix, sign: T) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { for i in 0..rhs.ncols() { @@ -75,11 +75,11 @@ impl> Reflection { /// Applies the reflection to the rows of `lhs`. pub fn reflect_rows( &self, - lhs: &mut Matrix, - work: &mut Vector, + lhs: &mut Matrix, + work: &mut Vector, ) where - S2: StorageMut, - S3: StorageMut, + S2: StorageMut, + S3: StorageMut, ShapeConstraint: DimEq + AreMultipliable, { lhs.mul_to(&self.axis, work); @@ -88,19 +88,19 @@ impl> Reflection { work.add_scalar_mut(-self.bias); } - let m_two: N = crate::convert(-2.0f64); - lhs.gerc(m_two, &work, &self.axis, N::one()); + let m_two: T = crate::convert(-2.0f64); + lhs.gerc(m_two, &work, &self.axis, T::one()); } /// Applies the reflection to the rows of `lhs`. pub fn reflect_rows_with_sign( &self, - lhs: &mut Matrix, - work: &mut Vector, - sign: N, + lhs: &mut Matrix, + work: &mut Vector, + sign: T, ) where - S2: StorageMut, - S3: StorageMut, + S2: StorageMut, + S3: StorageMut, ShapeConstraint: DimEq + AreMultipliable, { lhs.mul_to(&self.axis, work); diff --git a/src/geometry/rotation.rs b/src/geometry/rotation.rs index 2783f9b1..74843b21 100755 --- a/src/geometry/rotation.rs +++ b/src/geometry/rotation.rs @@ -19,7 +19,7 @@ use simba::simd::SimdRealField; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; -use crate::base::{CMatrixN, CVectorN, Const, DefaultAllocator, MatrixN, Scalar, Unit}; +use crate::base::{Const, DefaultAllocator, OMatrix, SMatrix, SVector, Scalar, Unit}; use crate::geometry::Point; /// A rotation matrix. @@ -55,30 +55,27 @@ use crate::geometry::Point; /// #[repr(C)] #[derive(Debug)] -pub struct Rotation -// where -// DefaultAllocator: Allocator, -{ - matrix: CMatrixN, +pub struct Rotation { + matrix: SMatrix, } -impl hash::Hash for Rotation +impl hash::Hash for Rotation where - , Const>>::Buffer: hash::Hash, + , Const>>::Buffer: hash::Hash, { fn hash(&self, state: &mut H) { self.matrix.hash(state) } } -impl Copy for Rotation where - , Const>>::Buffer: Copy +impl Copy for Rotation where + , Const>>::Buffer: Copy { } -impl Clone for Rotation +impl Clone for Rotation where - , Const>>::Buffer: Clone, + , Const>>::Buffer: Clone, { #[inline] fn clone(&self) -> Self { @@ -87,10 +84,10 @@ where } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Rotation +impl Abomonation for Rotation where - N: Scalar, - CMatrixN: Abomonation, + T: Scalar, + SMatrix: Abomonation, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.matrix.entomb(writer) @@ -106,9 +103,9 @@ where } #[cfg(feature = "serde-serialize")] -impl Serialize for Rotation +impl Serialize for Rotation where - Owned, Const>: Serialize, + Owned, Const>: Serialize, { fn serialize(&self, serializer: S) -> Result where @@ -119,24 +116,21 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N: Scalar, const D: usize> Deserialize<'a> for Rotation +impl<'a, T: Scalar, const D: usize> Deserialize<'a> for Rotation where - Owned, Const>: Deserialize<'a>, + Owned, Const>: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result where Des: Deserializer<'a>, { - let matrix = CMatrixN::::deserialize(deserializer)?; + let matrix = SMatrix::::deserialize(deserializer)?; Ok(Self::from_matrix_unchecked(matrix)) } } -impl Rotation -// where -// DefaultAllocator: Allocator, -{ +impl Rotation { /// Creates a new rotation from the given square matrix. /// /// The matrix squareness is checked but not its orthonormality. @@ -160,7 +154,7 @@ impl Rotation /// assert_eq!(*rot.matrix(), mat); /// ``` #[inline] - pub fn from_matrix_unchecked(matrix: CMatrixN) -> Self { + pub fn from_matrix_unchecked(matrix: SMatrix) -> Self { assert!( matrix.is_square(), "Unable to create a rotation from a non-square matrix." @@ -171,10 +165,7 @@ impl Rotation } /// # Conversion to a matrix -impl Rotation -// where -// DefaultAllocator: Allocator, -{ +impl Rotation { /// A reference to the underlying matrix representation of this rotation. /// /// # Example @@ -194,14 +185,14 @@ impl Rotation /// assert_eq!(*rot.matrix(), expected); /// ``` #[inline] - pub fn matrix(&self) -> &CMatrixN { + pub fn matrix(&self) -> &SMatrix { &self.matrix } /// A mutable reference to the underlying matrix representation of this rotation. #[inline] #[deprecated(note = "Use `.matrix_mut_unchecked()` instead.")] - pub unsafe fn matrix_mut(&mut self) -> &mut CMatrixN { + pub unsafe fn matrix_mut(&mut self) -> &mut SMatrix { &mut self.matrix } @@ -211,7 +202,7 @@ impl Rotation /// non-square, non-inversible, or non-orthonormal. If one of those properties is broken, /// subsequent method calls may be UB. #[inline] - pub fn matrix_mut_unchecked(&mut self) -> &mut CMatrixN { + pub fn matrix_mut_unchecked(&mut self) -> &mut SMatrix { &mut self.matrix } @@ -236,7 +227,7 @@ impl Rotation /// assert_eq!(mat, expected); /// ``` #[inline] - pub fn into_inner(self) -> CMatrixN { + pub fn into_inner(self) -> SMatrix { self.matrix } @@ -244,7 +235,7 @@ impl Rotation /// Deprecated: Use [Rotation::into_inner] instead. #[deprecated(note = "use `.into_inner()` instead")] #[inline] - pub fn unwrap(self) -> CMatrixN { + pub fn unwrap(self) -> SMatrix { self.matrix } @@ -271,28 +262,24 @@ impl Rotation /// assert_eq!(rot.to_homogeneous(), expected); /// ``` #[inline] - pub fn to_homogeneous(&self) -> MatrixN, U1>> + pub fn to_homogeneous(&self) -> OMatrix, U1>, DimNameSum, U1>> where - N: Zero + One, + T: Zero + One, Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { - // We could use `CMatrixN::to_homogeneous()` here, but that would imply + // We could use `SMatrix::to_homogeneous()` here, but that would imply // adding the additional traits `DimAdd` and `IsNotStaticOne`. Maybe // these things will get nicer once specialization lands in Rust. - let mut res = MatrixN::, U1>>::identity(); - res.fixed_slice_mut::, Const>(0, 0) - .copy_from(&self.matrix); + let mut res = OMatrix::, U1>, DimNameSum, U1>>::identity(); + res.fixed_slice_mut::(0, 0).copy_from(&self.matrix); res } } /// # Transposition and inversion -impl Rotation -// where -// DefaultAllocator: Allocator, -{ +impl Rotation { /// Transposes `self`. /// /// Same as `.inverse()` because the inverse of a rotation matrix is its transform. @@ -397,9 +384,9 @@ impl Rotation } /// # Transformation of a vector or a point -impl Rotation +impl Rotation where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Rotate the given point. /// @@ -416,7 +403,7 @@ where /// assert_relative_eq!(transformed_point, Point3::new(3.0, 2.0, -1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn transform_point(&self, pt: &Point) -> Point { + pub fn transform_point(&self, pt: &Point) -> Point { self * pt } @@ -435,7 +422,7 @@ where /// assert_relative_eq!(transformed_vector, Vector3::new(3.0, 2.0, -1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn transform_vector(&self, v: &CVectorN) -> CVectorN { + pub fn transform_vector(&self, v: &SVector) -> SVector { self * v } @@ -454,7 +441,7 @@ where /// assert_relative_eq!(transformed_point, Point3::new(-3.0, 2.0, 1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_point(&self, pt: &Point) -> Point { + pub fn inverse_transform_point(&self, pt: &Point) -> Point { Point::from(self.inverse_transform_vector(&pt.coords)) } @@ -473,7 +460,7 @@ where /// assert_relative_eq!(transformed_vector, Vector3::new(-3.0, 2.0, 1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { + pub fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.matrix().tr_mul(v) } @@ -492,36 +479,30 @@ where /// assert_relative_eq!(transformed_vector, -Vector3::y_axis(), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { + pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { Unit::new_unchecked(self.inverse_transform_vector(&**v)) } } -impl Eq for Rotation -// where DefaultAllocator: Allocator -{ -} +impl Eq for Rotation {} -impl PartialEq for Rotation -// where -// DefaultAllocator: Allocator, -{ +impl PartialEq for Rotation { #[inline] fn eq(&self, right: &Self) -> bool { self.matrix == right.matrix } } -impl AbsDiffEq for Rotation +impl AbsDiffEq for Rotation where - N: Scalar + AbsDiffEq, - N::Epsilon: Copy, + T: Scalar + AbsDiffEq, + T::Epsilon: Copy, { - type Epsilon = N::Epsilon; + type Epsilon = T::Epsilon; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -530,14 +511,14 @@ where } } -impl RelativeEq for Rotation +impl RelativeEq for Rotation where - N: Scalar + RelativeEq, - N::Epsilon: Copy, + T: Scalar + RelativeEq, + T::Epsilon: Copy, { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -552,14 +533,14 @@ where } } -impl UlpsEq for Rotation +impl UlpsEq for Rotation where - N: Scalar + UlpsEq, - N::Epsilon: Copy, + T: Scalar + UlpsEq, + T::Epsilon: Copy, { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] @@ -573,9 +554,9 @@ where * Display * */ -impl fmt::Display for Rotation +impl fmt::Display for Rotation where - N: RealField + fmt::Display, + T: RealField + fmt::Display, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let precision = f.precision().unwrap_or(3); @@ -591,11 +572,11 @@ where // // * Absolute // // * // // */ -// // impl Absolute for $t { -// // type AbsoluteValue = $submatrix; +// // impl Absolute for $t { +// // type AbsoluteValue = $submatrix; // // // // #[inline] -// // fn abs(m: &$t) -> $submatrix { +// // fn abs(m: &$t) -> $submatrix { // // Absolute::abs(&m.submatrix) // // } // // } diff --git a/src/geometry/rotation_alias.rs b/src/geometry/rotation_alias.rs index 09d86152..f44e24bc 100644 --- a/src/geometry/rotation_alias.rs +++ b/src/geometry/rotation_alias.rs @@ -3,9 +3,9 @@ use crate::geometry::Rotation; /// A 2-dimensional rotation matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Rotation`](crate::Rotation) type too.** -pub type Rotation2 = Rotation; +pub type Rotation2 = Rotation; /// A 3-dimensional rotation matrix. /// /// **Because this is an alias, not all its methods are listed here. See the [`Rotation`](crate::Rotation) type too.** -pub type Rotation3 = Rotation; +pub type Rotation3 = Rotation; diff --git a/src/geometry/rotation_construction.rs b/src/geometry/rotation_construction.rs index 0db4997a..c18c6a58 100644 --- a/src/geometry/rotation_construction.rs +++ b/src/geometry/rotation_construction.rs @@ -2,14 +2,14 @@ use num::{One, Zero}; use simba::scalar::{ClosedAdd, ClosedMul, SupersetOf}; -use crate::base::{CMatrixN, Scalar}; +use crate::base::{SMatrix, Scalar}; use crate::geometry::Rotation; /// # Identity -impl Rotation +impl Rotation where - N: Scalar + Zero + One, + T: Scalar + Zero + One, { /// Creates a new square identity rotation of the given `dimension`. /// @@ -23,15 +23,12 @@ where /// assert_eq!(rot2 * rot1, rot2); /// ``` #[inline] - pub fn identity() -> Rotation { - Self::from_matrix_unchecked(CMatrixN::::identity()) + pub fn identity() -> Rotation { + Self::from_matrix_unchecked(SMatrix::::identity()) } } -impl Rotation -// where -// DefaultAllocator: Allocator, -{ +impl Rotation { /// Cast the components of `self` to another type. /// /// # Example @@ -49,9 +46,9 @@ impl Rotation } } -impl One for Rotation +impl One for Rotation where - N: Scalar + Zero + One + ClosedAdd + ClosedMul, + T: Scalar + Zero + One + ClosedAdd + ClosedMul, { #[inline] fn one() -> Self { diff --git a/src/geometry/rotation_conversion.rs b/src/geometry/rotation_conversion.rs index 02285419..0e83d60f 100644 --- a/src/geometry/rotation_conversion.rs +++ b/src/geometry/rotation_conversion.rs @@ -5,7 +5,7 @@ use simba::simd::{PrimitiveSimdValue, SimdValue}; use crate::base::allocator::Allocator; use crate::base::dimension::{DimMin, DimNameAdd, DimNameSum, U1}; -use crate::base::{CMatrixN, Const, DefaultAllocator, Matrix2, Matrix3, Matrix4, MatrixN, Scalar}; +use crate::base::{Const, DefaultAllocator, Matrix2, Matrix3, Matrix4, OMatrix, SMatrix, Scalar}; use crate::geometry::{ AbstractRotation, Isometry, Rotation, Rotation2, Rotation3, Similarity, SuperTCategoryOf, @@ -27,259 +27,262 @@ use crate::geometry::{ */ -impl SubsetOf> for Rotation +impl SubsetOf> for Rotation where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, { #[inline] - fn to_superset(&self) -> Rotation { + fn to_superset(&self) -> Rotation { Rotation::from_matrix_unchecked(self.matrix().to_superset()) } #[inline] - fn is_in_subset(rot: &Rotation) -> bool { - crate::is_convertible::<_, CMatrixN>(rot.matrix()) + fn is_in_subset(rot: &Rotation) -> bool { + crate::is_convertible::<_, SMatrix>(rot.matrix()) } #[inline] - fn from_superset_unchecked(rot: &Rotation) -> Self { + fn from_superset_unchecked(rot: &Rotation) -> Self { Rotation::from_matrix_unchecked(rot.matrix().to_subset_unchecked()) } } -impl SubsetOf> for Rotation3 +impl SubsetOf> for Rotation3 where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, { #[inline] - fn to_superset(&self) -> UnitQuaternion { - let q = UnitQuaternion::::from_rotation_matrix(self); + fn to_superset(&self) -> UnitQuaternion { + let q = UnitQuaternion::::from_rotation_matrix(self); q.to_superset() } #[inline] - fn is_in_subset(q: &UnitQuaternion) -> bool { - crate::is_convertible::<_, UnitQuaternion>(q) + fn is_in_subset(q: &UnitQuaternion) -> bool { + crate::is_convertible::<_, UnitQuaternion>(q) } #[inline] - fn from_superset_unchecked(q: &UnitQuaternion) -> Self { - let q: UnitQuaternion = crate::convert_ref_unchecked(q); + fn from_superset_unchecked(q: &UnitQuaternion) -> Self { + let q: UnitQuaternion = crate::convert_ref_unchecked(q); q.to_rotation_matrix() } } -impl SubsetOf> for Rotation3 +impl SubsetOf> for Rotation3 where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, { #[inline] - fn to_superset(&self) -> UnitDualQuaternion { - let q = UnitQuaternion::::from_rotation_matrix(self); + fn to_superset(&self) -> UnitDualQuaternion { + let q = UnitQuaternion::::from_rotation_matrix(self); let dq = UnitDualQuaternion::from_rotation(q); dq.to_superset() } #[inline] - fn is_in_subset(dq: &UnitDualQuaternion) -> bool { - crate::is_convertible::<_, UnitQuaternion>(&dq.rotation()) + fn is_in_subset(dq: &UnitDualQuaternion) -> bool { + crate::is_convertible::<_, UnitQuaternion>(&dq.rotation()) && dq.translation().vector.is_zero() } #[inline] - fn from_superset_unchecked(dq: &UnitDualQuaternion) -> Self { - let dq: UnitDualQuaternion = crate::convert_ref_unchecked(dq); + fn from_superset_unchecked(dq: &UnitDualQuaternion) -> Self { + let dq: UnitDualQuaternion = crate::convert_ref_unchecked(dq); dq.rotation().to_rotation_matrix() } } -impl SubsetOf> for Rotation2 +impl SubsetOf> for Rotation2 where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, { #[inline] - fn to_superset(&self) -> UnitComplex { - let q = UnitComplex::::from_rotation_matrix(self); + fn to_superset(&self) -> UnitComplex { + let q = UnitComplex::::from_rotation_matrix(self); q.to_superset() } #[inline] - fn is_in_subset(q: &UnitComplex) -> bool { - crate::is_convertible::<_, UnitComplex>(q) + fn is_in_subset(q: &UnitComplex) -> bool { + crate::is_convertible::<_, UnitComplex>(q) } #[inline] - fn from_superset_unchecked(q: &UnitComplex) -> Self { - let q: UnitComplex = crate::convert_ref_unchecked(q); + fn from_superset_unchecked(q: &UnitComplex) -> Self { + let q: UnitComplex = crate::convert_ref_unchecked(q); q.to_rotation_matrix() } } -impl SubsetOf> for Rotation +impl SubsetOf> for Rotation where - N1: RealField, - N2: RealField + SupersetOf, - R: AbstractRotation + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, + R: AbstractRotation + SupersetOf, { #[inline] - fn to_superset(&self) -> Isometry { + fn to_superset(&self) -> Isometry { Isometry::from_parts(Translation::identity(), crate::convert_ref(self)) } #[inline] - fn is_in_subset(iso: &Isometry) -> bool { + fn is_in_subset(iso: &Isometry) -> bool { iso.translation.vector.is_zero() } #[inline] - fn from_superset_unchecked(iso: &Isometry) -> Self { + fn from_superset_unchecked(iso: &Isometry) -> Self { crate::convert_ref_unchecked(&iso.rotation) } } -impl SubsetOf> for Rotation +impl SubsetOf> for Rotation where - N1: RealField, - N2: RealField + SupersetOf, - R: AbstractRotation + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, + R: AbstractRotation + SupersetOf, { #[inline] - fn to_superset(&self) -> Similarity { - Similarity::from_parts(Translation::identity(), crate::convert_ref(self), N2::one()) + fn to_superset(&self) -> Similarity { + Similarity::from_parts(Translation::identity(), crate::convert_ref(self), T2::one()) } #[inline] - fn is_in_subset(sim: &Similarity) -> bool { - sim.isometry.translation.vector.is_zero() && sim.scaling() == N2::one() + fn is_in_subset(sim: &Similarity) -> bool { + sim.isometry.translation.vector.is_zero() && sim.scaling() == T2::one() } #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { + fn from_superset_unchecked(sim: &Similarity) -> Self { crate::convert_ref_unchecked(&sim.isometry.rotation) } } -impl SubsetOf> for Rotation +impl SubsetOf> for Rotation where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, C: SuperTCategoryOf, Const: DimNameAdd + DimMin, Output = Const>, // needed by .is_special_orthogonal() - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, // + Allocator<(usize, usize), D>, - // Allocator - // + Allocator + // Allocator + // + Allocator { // needed by .is_special_orthogonal() #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl SubsetOf, U1>>> for Rotation +impl + SubsetOf, U1>, DimNameSum, U1>>> for Rotation where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, Const: DimNameAdd + DimMin, Output = Const>, // needed by .is_special_orthogonal() - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>>, // + Allocator<(usize, usize), D>, - // + Allocator - // + Allocator + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, // + Allocator<(usize, usize), D>, + // + Allocator + // + Allocator { // needed by .is_special_orthogonal() #[inline] - fn to_superset(&self) -> MatrixN, U1>> { + fn to_superset(&self) -> OMatrix, U1>, DimNameSum, U1>> { self.to_homogeneous().to_superset() } #[inline] - fn is_in_subset(m: &MatrixN, U1>>) -> bool { - let rot = m.fixed_slice::, Const>(0, 0); - let bottom = m.fixed_slice::>(D, 0); + fn is_in_subset(m: &OMatrix, U1>, DimNameSum, U1>>) -> bool { + let rot = m.fixed_slice::(0, 0); + let bottom = m.fixed_slice::<1, D>(D, 0); // Scalar types agree. - m.iter().all(|e| SupersetOf::::is_in_subset(e)) && + m.iter().all(|e| SupersetOf::::is_in_subset(e)) && // The block part is a rotation. - rot.is_special_orthogonal(N2::default_epsilon() * crate::convert(100.0)) && + rot.is_special_orthogonal(T2::default_epsilon() * crate::convert(100.0)) && // The bottom row is (0, 0, ..., 1) - bottom.iter().all(|e| e.is_zero()) && m[(D, D)] == N2::one() + bottom.iter().all(|e| e.is_zero()) && m[(D, D)] == T2::one() } #[inline] - fn from_superset_unchecked(m: &MatrixN, U1>>) -> Self { - let r = m.fixed_slice::, Const>(0, 0); + fn from_superset_unchecked( + m: &OMatrix, U1>, DimNameSum, U1>>, + ) -> Self { + let r = m.fixed_slice::(0, 0); Self::from_matrix_unchecked(crate::convert_unchecked(r.into_owned())) } } -impl From> for Matrix3 { +impl From> for Matrix3 { #[inline] - fn from(q: Rotation2) -> Self { + fn from(q: Rotation2) -> Self { q.to_homogeneous() } } -impl From> for Matrix2 { +impl From> for Matrix2 { #[inline] - fn from(q: Rotation2) -> Self { + fn from(q: Rotation2) -> Self { q.into_inner() } } -impl From> for Matrix4 { +impl From> for Matrix4 { #[inline] - fn from(q: Rotation3) -> Self { + fn from(q: Rotation3) -> Self { q.to_homogeneous() } } -impl From> for Matrix3 { +impl From> for Matrix3 { #[inline] - fn from(q: Rotation3) -> Self { + fn from(q: Rotation3) -> Self { q.into_inner() } } -impl From<[Rotation; 2]> - for Rotation +impl From<[Rotation; 2]> + for Rotation where - N: From<[::Element; 2]>, - N::Element: Scalar + Copy, + T: From<[::Element; 2]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [Rotation; 2]) -> Self { - Self::from_matrix_unchecked(MatrixN::from([ + fn from(arr: [Rotation; 2]) -> Self { + Self::from_matrix_unchecked(OMatrix::from([ arr[0].clone().into_inner(), arr[1].clone().into_inner(), ])) } } -impl From<[Rotation; 4]> - for Rotation +impl From<[Rotation; 4]> + for Rotation where - N: From<[::Element; 4]>, - N::Element: Scalar + Copy, + T: From<[::Element; 4]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [Rotation; 4]) -> Self { - Self::from_matrix_unchecked(MatrixN::from([ + fn from(arr: [Rotation; 4]) -> Self { + Self::from_matrix_unchecked(OMatrix::from([ arr[0].clone().into_inner(), arr[1].clone().into_inner(), arr[2].clone().into_inner(), @@ -288,15 +291,15 @@ where } } -impl From<[Rotation; 8]> - for Rotation +impl From<[Rotation; 8]> + for Rotation where - N: From<[::Element; 8]>, - N::Element: Scalar + Copy, + T: From<[::Element; 8]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [Rotation; 8]) -> Self { - Self::from_matrix_unchecked(MatrixN::from([ + fn from(arr: [Rotation; 8]) -> Self { + Self::from_matrix_unchecked(OMatrix::from([ arr[0].clone().into_inner(), arr[1].clone().into_inner(), arr[2].clone().into_inner(), @@ -309,15 +312,15 @@ where } } -impl From<[Rotation; 16]> - for Rotation +impl From<[Rotation; 16]> + for Rotation where - N: From<[::Element; 16]>, - N::Element: Scalar + Copy, + T: From<[::Element; 16]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [Rotation; 16]) -> Self { - Self::from_matrix_unchecked(MatrixN::from([ + fn from(arr: [Rotation; 16]) -> Self { + Self::from_matrix_unchecked(OMatrix::from([ arr[0].clone().into_inner(), arr[1].clone().into_inner(), arr[2].clone().into_inner(), diff --git a/src/geometry/rotation_interpolation.rs b/src/geometry/rotation_interpolation.rs index 5f861428..bf1c9094 100644 --- a/src/geometry/rotation_interpolation.rs +++ b/src/geometry/rotation_interpolation.rs @@ -1,7 +1,7 @@ use crate::{RealField, Rotation2, Rotation3, SimdRealField, UnitComplex, UnitQuaternion}; /// # Interpolation -impl Rotation2 { +impl Rotation2 { /// Spherical linear interpolation between two rotation matrices. /// /// # Examples: @@ -18,9 +18,9 @@ impl Rotation2 { /// assert_relative_eq!(rot.angle(), std::f32::consts::FRAC_PI_2); /// ``` #[inline] - pub fn slerp(&self, other: &Self, t: N) -> Self + pub fn slerp(&self, other: &Self, t: T) -> Self where - N::Element: SimdRealField, + T::Element: SimdRealField, { let c1 = UnitComplex::from(*self); let c2 = UnitComplex::from(*other); @@ -28,7 +28,7 @@ impl Rotation2 { } } -impl Rotation3 { +impl Rotation3 { /// Spherical linear interpolation between two rotation matrices. /// /// Panics if the angle between both rotations is 180 degrees (in which case the interpolation @@ -47,9 +47,9 @@ impl Rotation3 { /// assert_eq!(q.euler_angles(), (std::f32::consts::FRAC_PI_2, 0.0, 0.0)); /// ``` #[inline] - pub fn slerp(&self, other: &Self, t: N) -> Self + pub fn slerp(&self, other: &Self, t: T) -> Self where - N: RealField, + T: RealField, { let q1 = UnitQuaternion::from(*self); let q2 = UnitQuaternion::from(*other); @@ -67,9 +67,9 @@ impl Rotation3 { /// * `epsilon`: the value below which the sinus of the angle separating both rotations /// must be to return `None`. #[inline] - pub fn try_slerp(&self, other: &Self, t: N, epsilon: N) -> Option + pub fn try_slerp(&self, other: &Self, t: T, epsilon: T) -> Option where - N: RealField, + T: RealField, { let q1 = Rotation3::from(*self); let q2 = Rotation3::from(*other); diff --git a/src/geometry/rotation_ops.rs b/src/geometry/rotation_ops.rs index 4821328d..863acd39 100644 --- a/src/geometry/rotation_ops.rs +++ b/src/geometry/rotation_ops.rs @@ -27,16 +27,16 @@ use crate::base::constraint::{AreMultipliable, ShapeConstraint}; use crate::base::dimension::{Dim, U1}; use crate::base::storage::Storage; use crate::base::{ - CMatrixMN, CVectorN, Const, DefaultAllocator, Matrix, MatrixMN, Scalar, Unit, Vector, + Const, DefaultAllocator, Matrix, OMatrix, SMatrix, SVector, Scalar, Unit, Vector, }; use crate::geometry::{Point, Rotation}; -impl Index<(usize, usize)> for Rotation { - type Output = N; +impl Index<(usize, usize)> for Rotation { + type Output = T; #[inline] - fn index(&self, row_col: (usize, usize)) -> &N { + fn index(&self, row_col: (usize, usize)) -> &T { self.matrix().index(row_col) } } @@ -48,7 +48,7 @@ md_impl_all!( const D; for; where; - self: Rotation, right: Rotation, Output = Rotation; + self: Rotation, right: Rotation, Output = Rotation; [val val] => Rotation::from_matrix_unchecked(self.into_inner() * right.into_inner()); [ref val] => Rotation::from_matrix_unchecked(self.matrix() * right.into_inner()); [val ref] => Rotation::from_matrix_unchecked(self.into_inner() * right.matrix()); @@ -63,7 +63,7 @@ md_impl_all!( const D; for; where; - self: Rotation, right: Rotation, Output = Rotation; + self: Rotation, right: Rotation, Output = Rotation; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; @@ -76,10 +76,10 @@ md_impl_all!( (Const, Const), (R2, C2) const D1; for R2, C2, SB; - where R2: Dim, C2: Dim, SB: Storage, - DefaultAllocator: Allocator, C2>, + where R2: Dim, C2: Dim, SB: Storage, + DefaultAllocator: Allocator, C2>, ShapeConstraint: AreMultipliable, Const, R2, C2>; - self: Rotation, right: Matrix, Output = MatrixMN, C2>; + self: Rotation, right: Matrix, Output = OMatrix, C2>; [val val] => self.into_inner() * right; [ref val] => self.matrix() * right; [val ref] => self.into_inner() * right; @@ -92,10 +92,10 @@ md_impl_all!( (R1, C1), (Const, Const) const D2; for R1, C1, SA; - where R1: Dim, C1: Dim, SA: Storage, - DefaultAllocator: Allocator>, + where R1: Dim, C1: Dim, SA: Storage, + DefaultAllocator: Allocator>, ShapeConstraint: AreMultipliable, Const>; - self: Matrix, right: Rotation, Output = MatrixMN>; + self: Matrix, right: Rotation, Output = OMatrix>; [val val] => self * right.into_inner(); [ref val] => self * right.into_inner(); [val ref] => self * right.matrix(); @@ -108,10 +108,10 @@ md_impl_all!( (R1, C1), (Const, Const) const D2; for R1, C1, SA; - where R1: Dim, C1: Dim, SA: Storage, - DefaultAllocator: Allocator>, + where R1: Dim, C1: Dim, SA: Storage, + DefaultAllocator: Allocator>, ShapeConstraint: AreMultipliable, Const>; - self: Matrix, right: Rotation, Output = MatrixMN>; + self: Matrix, right: Rotation, Output = OMatrix>; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; @@ -127,7 +127,7 @@ md_impl_all!( const D; for; where ShapeConstraint: AreMultipliable, Const, Const, U1>; - self: Rotation, right: Point, Output = Point; + self: Rotation, right: Point, Output = Point; [val val] => self.into_inner() * right; [ref val] => self.matrix() * right; [val ref] => self.into_inner() * right; @@ -140,9 +140,9 @@ md_impl_all!( (Const, Const), (Const, U1) const D; for S; - where S: Storage>, + where S: Storage>, ShapeConstraint: AreMultipliable, Const, Const, U1>; - self: Rotation, right: Unit, S>>, Output = Unit>; + self: Rotation, right: Unit, S>>, Output = Unit>; [val val] => Unit::new_unchecked(self.into_inner() * right.into_inner()); [ref val] => Unit::new_unchecked(self.matrix() * right.into_inner()); [val ref] => Unit::new_unchecked(self.into_inner() * right.as_ref()); @@ -156,7 +156,7 @@ md_assign_impl_all!( MulAssign, mul_assign; (Const, Const), (Const, Const) const D; for; where; - self: Rotation, right: Rotation; + self: Rotation, right: Rotation; [val] => self.matrix_mut_unchecked().mul_assign(right.into_inner()); [ref] => self.matrix_mut_unchecked().mul_assign(right.matrix()); ); @@ -165,7 +165,7 @@ md_assign_impl_all!( DivAssign, div_assign; (Const, Const), (Const, Const) const D; for; where; - self: Rotation, right: Rotation; + self: Rotation, right: Rotation; [val] => self.matrix_mut_unchecked().mul_assign(right.inverse().into_inner()); [ref] => self.matrix_mut_unchecked().mul_assign(right.inverse().matrix()); ); @@ -180,7 +180,7 @@ md_assign_impl_all!( MulAssign, mul_assign; (Const, Const), (Const, Const) const R1, C1; for; where; - self: CMatrixMN, right: Rotation; + self: SMatrix, right: Rotation; [val] => self.mul_assign(right.into_inner()); [ref] => self.mul_assign(right.matrix()); ); @@ -189,7 +189,7 @@ md_assign_impl_all!( DivAssign, div_assign; (Const, Const), (Const, Const) const R1, C1; for; where; - self: CMatrixMN, right: Rotation; + self: SMatrix, right: Rotation; [val] => self.mul_assign(right.inverse().into_inner()); [ref] => self.mul_assign(right.inverse().matrix()); ); diff --git a/src/geometry/rotation_simba.rs b/src/geometry/rotation_simba.rs index cb0aa13b..39b60aa3 100755 --- a/src/geometry/rotation_simba.rs +++ b/src/geometry/rotation_simba.rs @@ -1,25 +1,25 @@ use simba::simd::SimdValue; -use crate::base::{MatrixN, Scalar}; +use crate::base::{OMatrix, Scalar}; use crate::geometry::Rotation; -impl SimdValue for Rotation +impl SimdValue for Rotation where - N: Scalar + SimdValue, - N::Element: Scalar, + T: Scalar + SimdValue, + T::Element: Scalar, { - type Element = Rotation; - type SimdBool = N::SimdBool; + type Element = Rotation; + type SimdBool = T::SimdBool; #[inline] fn lanes() -> usize { - N::lanes() + T::lanes() } #[inline] fn splat(val: Self::Element) -> Self { - Rotation::from_matrix_unchecked(MatrixN::splat(val.into_inner())) + Rotation::from_matrix_unchecked(OMatrix::splat(val.into_inner())) } #[inline] diff --git a/src/geometry/rotation_specialization.rs b/src/geometry/rotation_specialization.rs index fe431804..38d05897 100644 --- a/src/geometry/rotation_specialization.rs +++ b/src/geometry/rotation_specialization.rs @@ -17,7 +17,7 @@ use std::ops::Neg; use crate::base::dimension::{U1, U2, U3}; use crate::base::storage::Storage; -use crate::base::{Matrix2, Matrix3, MatrixN, Unit, Vector, Vector1, Vector2, Vector3, VectorN}; +use crate::base::{Matrix2, Matrix3, SMatrix, SVector, Unit, Vector, Vector1, Vector2, Vector3}; use crate::geometry::{Rotation2, Rotation3, UnitComplex, UnitQuaternion}; @@ -27,7 +27,7 @@ use crate::geometry::{Rotation2, Rotation3, UnitComplex, UnitQuaternion}; * */ /// # Construction from a 2D rotation angle -impl Rotation2 { +impl Rotation2 { /// Builds a 2 dimensional rotation matrix from an angle in radian. /// /// # Example @@ -40,7 +40,7 @@ impl Rotation2 { /// /// assert_relative_eq!(rot * Point2::new(3.0, 4.0), Point2::new(-4.0, 3.0)); /// ``` - pub fn new(angle: N) -> Self { + pub fn new(angle: T) -> Self { let (sia, coa) = angle.simd_sin_cos(); Self::from_matrix_unchecked(Matrix2::new(coa, -sia, sia, coa)) } @@ -51,20 +51,20 @@ impl Rotation2 { /// This is generally used in the context of generic programming. Using /// the `::new(angle)` method instead is more common. #[inline] - pub fn from_scaled_axis>(axisangle: Vector) -> Self { + pub fn from_scaled_axis>(axisangle: Vector) -> Self { Self::new(axisangle[0]) } } /// # Construction from an existing 2D matrix or rotations -impl Rotation2 { +impl Rotation2 { /// Builds a rotation from a basis assumed to be orthonormal. /// /// In order to get a valid unit-quaternion, the input must be an /// orthonormal basis, i.e., all vectors are normalized, and the are /// all orthogonal to each other. These invariants are not checked /// by this method. - pub fn from_basis_unchecked(basis: &[Vector2; 2]) -> Self { + pub fn from_basis_unchecked(basis: &[Vector2; 2]) -> Self { let mat = Matrix2::from_columns(&basis[..]); Self::from_matrix_unchecked(mat) } @@ -74,11 +74,11 @@ impl Rotation2 { /// This is an iterative method. See `.from_matrix_eps` to provide mover /// convergence parameters and starting solution. /// This implements "A Robust Method to Extract the Rotational Part of Deformations" by Müller et al. - pub fn from_matrix(m: &Matrix2) -> Self + pub fn from_matrix(m: &Matrix2) -> Self where - N: RealField, + T: RealField, { - Self::from_matrix_eps(m, N::default_epsilon(), 0, Self::identity()) + Self::from_matrix_eps(m, T::default_epsilon(), 0, Self::identity()) } /// Builds a rotation matrix by extracting the rotation part of the given transformation `m`. @@ -93,9 +93,9 @@ impl Rotation2 { /// * `guess`: an estimate of the solution. Convergence will be significantly faster if an initial solution close /// to the actual solution is provided. Can be set to `Rotation2::identity()` if no other /// guesses come to mind. - pub fn from_matrix_eps(m: &Matrix2, eps: N, mut max_iter: usize, guess: Self) -> Self + pub fn from_matrix_eps(m: &Matrix2, eps: T, mut max_iter: usize, guess: Self) -> Self where - N: RealField, + T: RealField, { if max_iter == 0 { max_iter = usize::max_value(); @@ -107,7 +107,7 @@ impl Rotation2 { let axis = rot.column(0).perp(&m.column(0)) + rot.column(1).perp(&m.column(1)); let denom = rot.column(0).dot(&m.column(0)) + rot.column(1).dot(&m.column(1)); - let angle = axis / (denom.abs() + N::default_epsilon()); + let angle = axis / (denom.abs() + T::default_epsilon()); if angle.abs() > eps { rot = Self::new(angle) * rot; } else { @@ -133,11 +133,11 @@ impl Rotation2 { /// assert_relative_eq!(rot.inverse() * b, a); /// ``` #[inline] - pub fn rotation_between(a: &Vector, b: &Vector) -> Self + pub fn rotation_between(a: &Vector, b: &Vector) -> Self where - N: RealField, - SB: Storage, - SC: Storage, + T: RealField, + SB: Storage, + SC: Storage, { crate::convert(UnitComplex::rotation_between(a, b).to_rotation_matrix()) } @@ -158,14 +158,14 @@ impl Rotation2 { /// ``` #[inline] pub fn scaled_rotation_between( - a: &Vector, - b: &Vector, - s: N, + a: &Vector, + b: &Vector, + s: T, ) -> Self where - N: RealField, - SB: Storage, - SC: Storage, + T: RealField, + SB: Storage, + SC: Storage, { crate::convert(UnitComplex::scaled_rotation_between(a, b, s).to_rotation_matrix()) } @@ -195,12 +195,12 @@ impl Rotation2 { #[inline] pub fn renormalize(&mut self) where - N: RealField, + T: RealField, { let mut c = UnitComplex::from(*self); let _ = c.renormalize(); - *self = Self::from_matrix_eps(self.matrix(), N::default_epsilon(), 0, c.into()) + *self = Self::from_matrix_eps(self.matrix(), T::default_epsilon(), 0, c.into()) } /// Raise the quaternion to a given floating power, i.e., returns the rotation with the angle @@ -215,13 +215,13 @@ impl Rotation2 { /// assert_relative_eq!(pow.angle(), 2.0 * 0.78); /// ``` #[inline] - pub fn powf(&self, n: N) -> Self { + pub fn powf(&self, n: T) -> Self { Self::new(self.angle() * n) } } /// # 2D angle extraction -impl Rotation2 { +impl Rotation2 { /// The rotation angle. /// /// # Example @@ -232,7 +232,7 @@ impl Rotation2 { /// assert_relative_eq!(rot.angle(), 1.78); /// ``` #[inline] - pub fn angle(&self) -> N { + pub fn angle(&self) -> T { self.matrix()[(1, 0)].simd_atan2(self.matrix()[(0, 0)]) } @@ -247,7 +247,7 @@ impl Rotation2 { /// assert_relative_eq!(rot1.angle_to(&rot2), 1.6); /// ``` #[inline] - pub fn angle_to(&self, other: &Self) -> N { + pub fn angle_to(&self, other: &Self) -> T { self.rotation_to(other).angle() } @@ -256,34 +256,34 @@ impl Rotation2 { /// This is generally used in the context of generic programming. Using /// the `.angle()` method instead is more common. #[inline] - pub fn scaled_axis(&self) -> VectorN { + pub fn scaled_axis(&self) -> SVector { Vector1::new(self.angle()) } } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - N::Element: SimdRealField, - N: SampleUniform, + T::Element: SimdRealField, + T: SampleUniform, { /// Generate a uniformly distributed random rotation. #[inline] - fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> Rotation2 { - let twopi = Uniform::new(N::zero(), N::simd_two_pi()); + fn sample<'a, R: Rng + ?Sized>(&self, rng: &'a mut R) -> Rotation2 { + let twopi = Uniform::new(T::zero(), T::simd_two_pi()); Rotation2::new(rng.sample(twopi)) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Rotation2 +impl Arbitrary for Rotation2 where - N::Element: SimdRealField, - Owned: Send, + T::Element: SimdRealField, + Owned: Send, { #[inline] fn arbitrary(g: &mut Gen) -> Self { - Self::new(N::arbitrary(g)) + Self::new(T::arbitrary(g)) } } @@ -293,9 +293,9 @@ where * */ /// # Construction from a 3D axis and/or angles -impl Rotation3 +impl Rotation3 where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Builds a 3 dimensional rotation matrix from an axis and an angle. /// @@ -320,7 +320,7 @@ where /// // A zero vector yields an identity. /// assert_eq!(Rotation3::new(Vector3::::zeros()), Rotation3::identity()); /// ``` - pub fn new>(axisangle: Vector) -> Self { + pub fn new>(axisangle: Vector) -> Self { let axisangle = axisangle.into_owned(); let (axis, angle) = Unit::new_and_get(axisangle); Self::from_axis_angle(&axis, angle) @@ -347,7 +347,7 @@ where /// // A zero vector yields an identity. /// assert_eq!(Rotation3::from_scaled_axis(Vector3::::zeros()), Rotation3::identity()); /// ``` - pub fn from_scaled_axis>(axisangle: Vector) -> Self { + pub fn from_scaled_axis>(axisangle: Vector) -> Self { Self::new(axisangle) } @@ -373,11 +373,11 @@ where /// // A zero vector yields an identity. /// assert_eq!(Rotation3::from_scaled_axis(Vector3::::zeros()), Rotation3::identity()); /// ``` - pub fn from_axis_angle(axis: &Unit>, angle: N) -> Self + pub fn from_axis_angle(axis: &Unit>, angle: T) -> Self where - SB: Storage, + SB: Storage, { - angle.simd_ne(N::zero()).if_else( + angle.simd_ne(T::zero()).if_else( || { let ux = axis.as_ref()[0]; let uy = axis.as_ref()[1]; @@ -386,18 +386,18 @@ where let sqy = uy * uy; let sqz = uz * uz; let (sin, cos) = angle.simd_sin_cos(); - let one_m_cos = N::one() - cos; + let one_m_cos = T::one() - cos; - Self::from_matrix_unchecked(MatrixN::::new( - sqx + (N::one() - sqx) * cos, + Self::from_matrix_unchecked(SMatrix::::new( + sqx + (T::one() - sqx) * cos, ux * uy * one_m_cos - uz * sin, ux * uz * one_m_cos + uy * sin, ux * uy * one_m_cos + uz * sin, - sqy + (N::one() - sqy) * cos, + sqy + (T::one() - sqy) * cos, uy * uz * one_m_cos - ux * sin, ux * uz * one_m_cos - uy * sin, uy * uz * one_m_cos + ux * sin, - sqz + (N::one() - sqz) * cos, + sqz + (T::one() - sqz) * cos, )) }, Self::identity, @@ -418,12 +418,12 @@ where /// assert_relative_eq!(euler.1, 0.2, epsilon = 1.0e-6); /// assert_relative_eq!(euler.2, 0.3, epsilon = 1.0e-6); /// ``` - pub fn from_euler_angles(roll: N, pitch: N, yaw: N) -> Self { + pub fn from_euler_angles(roll: T, pitch: T, yaw: T) -> Self { let (sr, cr) = roll.simd_sin_cos(); let (sp, cp) = pitch.simd_sin_cos(); let (sy, cy) = yaw.simd_sin_cos(); - Self::from_matrix_unchecked(MatrixN::::new( + Self::from_matrix_unchecked(SMatrix::::new( cy * cp, cy * sp * sr - sy * cr, cy * sp * cr + sy * sr, @@ -438,9 +438,9 @@ where } /// # Construction from a 3D eye position and target point -impl Rotation3 +impl Rotation3 where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Creates a rotation that corresponds to the local frame of an observer standing at the /// origin and looking toward `dir`. @@ -464,26 +464,26 @@ where /// assert_relative_eq!(rot * Vector3::z(), dir.normalize()); /// ``` #[inline] - pub fn face_towards(dir: &Vector, up: &Vector) -> Self + pub fn face_towards(dir: &Vector, up: &Vector) -> Self where - SB: Storage, - SC: Storage, + SB: Storage, + SC: Storage, { let zaxis = dir.normalize(); let xaxis = up.cross(&zaxis).normalize(); let yaxis = zaxis.cross(&xaxis).normalize(); - Self::from_matrix_unchecked(MatrixN::::new( + Self::from_matrix_unchecked(SMatrix::::new( xaxis.x, yaxis.x, zaxis.x, xaxis.y, yaxis.y, zaxis.y, xaxis.z, yaxis.z, zaxis.z, )) } /// Deprecated: Use [Rotation3::face_towards] instead. #[deprecated(note = "renamed to `face_towards`")] - pub fn new_observer_frames(dir: &Vector, up: &Vector) -> Self + pub fn new_observer_frames(dir: &Vector, up: &Vector) -> Self where - SB: Storage, - SC: Storage, + SB: Storage, + SC: Storage, { Self::face_towards(dir, up) } @@ -511,10 +511,10 @@ where /// assert_relative_eq!(rot * dir.normalize(), -Vector3::z()); /// ``` #[inline] - pub fn look_at_rh(dir: &Vector, up: &Vector) -> Self + pub fn look_at_rh(dir: &Vector, up: &Vector) -> Self where - SB: Storage, - SC: Storage, + SB: Storage, + SC: Storage, { Self::face_towards(&dir.neg(), up).inverse() } @@ -542,19 +542,19 @@ where /// assert_relative_eq!(rot * dir.normalize(), Vector3::z()); /// ``` #[inline] - pub fn look_at_lh(dir: &Vector, up: &Vector) -> Self + pub fn look_at_lh(dir: &Vector, up: &Vector) -> Self where - SB: Storage, - SC: Storage, + SB: Storage, + SC: Storage, { Self::face_towards(dir, up).inverse() } } /// # Construction from an existing 3D matrix or rotations -impl Rotation3 +impl Rotation3 where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// The rotation matrix required to align `a` and `b` but with its angle. /// @@ -571,13 +571,13 @@ where /// assert_relative_eq!(rot.inverse() * b, a, epsilon = 1.0e-6); /// ``` #[inline] - pub fn rotation_between(a: &Vector, b: &Vector) -> Option + pub fn rotation_between(a: &Vector, b: &Vector) -> Option where - N: RealField, - SB: Storage, - SC: Storage, + T: RealField, + SB: Storage, + SC: Storage, { - Self::scaled_rotation_between(a, b, N::one()) + Self::scaled_rotation_between(a, b, T::one()) } /// The smallest rotation needed to make `a` and `b` collinear and point toward the same @@ -596,25 +596,25 @@ where /// ``` #[inline] pub fn scaled_rotation_between( - a: &Vector, - b: &Vector, - n: N, + a: &Vector, + b: &Vector, + n: T, ) -> Option where - N: RealField, - SB: Storage, - SC: Storage, + T: RealField, + SB: Storage, + SC: Storage, { // TODO: code duplication with Rotation. - if let (Some(na), Some(nb)) = (a.try_normalize(N::zero()), b.try_normalize(N::zero())) { + if let (Some(na), Some(nb)) = (a.try_normalize(T::zero()), b.try_normalize(T::zero())) { let c = na.cross(&nb); - if let Some(axis) = Unit::try_new(c, N::default_epsilon()) { + if let Some(axis) = Unit::try_new(c, T::default_epsilon()) { return Some(Self::from_axis_angle(&axis, na.dot(&nb).acos() * n)); } // Zero or PI. - if na.dot(&nb) < N::zero() { + if na.dot(&nb) < T::zero() { // PI // // The rotation axis is undefined but the angle not zero. This is not a @@ -659,14 +659,14 @@ where /// assert_eq!(pow.angle(), 2.4); /// ``` #[inline] - pub fn powf(&self, n: N) -> Self + pub fn powf(&self, n: T) -> Self where - N: RealField, + T: RealField, { if let Some(axis) = self.axis() { Self::from_axis_angle(&axis, self.angle() * n) - } else if self.matrix()[(0, 0)] < N::zero() { - let minus_id = MatrixN::::from_diagonal_element(-N::one()); + } else if self.matrix()[(0, 0)] < T::zero() { + let minus_id = SMatrix::::from_diagonal_element(-T::one()); Self::from_matrix_unchecked(minus_id) } else { Self::identity() @@ -679,7 +679,7 @@ where /// orthonormal basis, i.e., all vectors are normalized, and the are /// all orthogonal to each other. These invariants are not checked /// by this method. - pub fn from_basis_unchecked(basis: &[Vector3; 3]) -> Self { + pub fn from_basis_unchecked(basis: &[Vector3; 3]) -> Self { let mat = Matrix3::from_columns(&basis[..]); Self::from_matrix_unchecked(mat) } @@ -689,11 +689,11 @@ where /// This is an iterative method. See `.from_matrix_eps` to provide mover /// convergence parameters and starting solution. /// This implements "A Robust Method to Extract the Rotational Part of Deformations" by Müller et al. - pub fn from_matrix(m: &Matrix3) -> Self + pub fn from_matrix(m: &Matrix3) -> Self where - N: RealField, + T: RealField, { - Self::from_matrix_eps(m, N::default_epsilon(), 0, Self::identity()) + Self::from_matrix_eps(m, T::default_epsilon(), 0, Self::identity()) } /// Builds a rotation matrix by extracting the rotation part of the given transformation `m`. @@ -708,9 +708,9 @@ where /// * `guess`: a guess of the solution. Convergence will be significantly faster if an initial solution close /// to the actual solution is provided. Can be set to `Rotation3::identity()` if no other /// guesses come to mind. - pub fn from_matrix_eps(m: &Matrix3, eps: N, mut max_iter: usize, guess: Self) -> Self + pub fn from_matrix_eps(m: &Matrix3, eps: T, mut max_iter: usize, guess: Self) -> Self where - N: RealField, + T: RealField, { if max_iter == 0 { max_iter = usize::max_value(); @@ -726,7 +726,7 @@ where + rot.column(1).dot(&m.column(1)) + rot.column(2).dot(&m.column(2)); - let axisangle = axis / (denom.abs() + N::default_epsilon()); + let axisangle = axis / (denom.abs() + T::default_epsilon()); if let Some((axis, angle)) = Unit::try_new_and_get(axisangle, eps) { rot = Rotation3::from_axis_angle(&axis, angle) * rot; @@ -743,17 +743,17 @@ where #[inline] pub fn renormalize(&mut self) where - N: RealField, + T: RealField, { let mut c = UnitQuaternion::from(*self); let _ = c.renormalize(); - *self = Self::from_matrix_eps(self.matrix(), N::default_epsilon(), 0, c.into()) + *self = Self::from_matrix_eps(self.matrix(), T::default_epsilon(), 0, c.into()) } } /// # 3D axis and angle extraction -impl Rotation3 { +impl Rotation3 { /// The rotation angle in [0; pi]. /// /// # Example @@ -765,8 +765,8 @@ impl Rotation3 { /// assert_relative_eq!(rot.angle(), 1.78); /// ``` #[inline] - pub fn angle(&self) -> N { - ((self.matrix()[(0, 0)] + self.matrix()[(1, 1)] + self.matrix()[(2, 2)] - N::one()) + pub fn angle(&self) -> T { + ((self.matrix()[(0, 0)] + self.matrix()[(1, 1)] + self.matrix()[(2, 2)] - T::one()) / crate::convert(2.0)) .simd_acos() } @@ -787,17 +787,17 @@ impl Rotation3 { /// assert!(rot.axis().is_none()); /// ``` #[inline] - pub fn axis(&self) -> Option>> + pub fn axis(&self) -> Option>> where - N: RealField, + T: RealField, { - let axis = VectorN::::new( + let axis = SVector::::new( self.matrix()[(2, 1)] - self.matrix()[(1, 2)], self.matrix()[(0, 2)] - self.matrix()[(2, 0)], self.matrix()[(1, 0)] - self.matrix()[(0, 1)], ); - Unit::try_new(axis, N::default_epsilon()) + Unit::try_new(axis, T::default_epsilon()) } /// The rotation axis multiplied by the rotation angle. @@ -811,9 +811,9 @@ impl Rotation3 { /// assert_relative_eq!(rot.scaled_axis(), axisangle, epsilon = 1.0e-6); /// ``` #[inline] - pub fn scaled_axis(&self) -> Vector3 + pub fn scaled_axis(&self) -> Vector3 where - N: RealField, + T: RealField, { if let Some(axis) = self.axis() { axis.into_inner() * self.angle() @@ -842,9 +842,9 @@ impl Rotation3 { /// assert!(rot.axis_angle().is_none()); /// ``` #[inline] - pub fn axis_angle(&self) -> Option<(Unit>, N)> + pub fn axis_angle(&self) -> Option<(Unit>, T)> where - N: RealField, + T: RealField, { if let Some(axis) = self.axis() { Some((axis, self.angle())) @@ -864,9 +864,9 @@ impl Rotation3 { /// assert_relative_eq!(rot1.angle_to(&rot2), 1.0045657, epsilon = 1.0e-6); /// ``` #[inline] - pub fn angle_to(&self, other: &Self) -> N + pub fn angle_to(&self, other: &Self) -> T where - N::Element: SimdRealField, + T::Element: SimdRealField, { self.rotation_to(other).angle() } @@ -875,9 +875,9 @@ impl Rotation3 { /// /// The angles are produced in the form (roll, pitch, yaw). #[deprecated(note = "This is renamed to use `.euler_angles()`.")] - pub fn to_euler_angles(&self) -> (N, N, N) + pub fn to_euler_angles(&self) -> (T, T, T) where - N: RealField, + T: RealField, { self.euler_angles() } @@ -896,57 +896,57 @@ impl Rotation3 { /// assert_relative_eq!(euler.1, 0.2, epsilon = 1.0e-6); /// assert_relative_eq!(euler.2, 0.3, epsilon = 1.0e-6); /// ``` - pub fn euler_angles(&self) -> (N, N, N) + pub fn euler_angles(&self) -> (T, T, T) where - N: RealField, + T: RealField, { // Implementation informed by "Computing Euler angles from a rotation matrix", by Gregory G. Slabaugh // https://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.371.6578 - if self[(2, 0)].abs() < N::one() { + if self[(2, 0)].abs() < T::one() { let yaw = -self[(2, 0)].asin(); let roll = (self[(2, 1)] / yaw.cos()).atan2(self[(2, 2)] / yaw.cos()); let pitch = (self[(1, 0)] / yaw.cos()).atan2(self[(0, 0)] / yaw.cos()); (roll, yaw, pitch) - } else if self[(2, 0)] <= -N::one() { - (self[(0, 1)].atan2(self[(0, 2)]), N::frac_pi_2(), N::zero()) + } else if self[(2, 0)] <= -T::one() { + (self[(0, 1)].atan2(self[(0, 2)]), T::frac_pi_2(), T::zero()) } else { ( -self[(0, 1)].atan2(-self[(0, 2)]), - -N::frac_pi_2(), - N::zero(), + -T::frac_pi_2(), + T::zero(), ) } } } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - N::Element: SimdRealField, - OpenClosed01: Distribution, - N: SampleUniform, + T::Element: SimdRealField, + OpenClosed01: Distribution, + T: SampleUniform, { /// Generate a uniformly distributed random rotation. #[inline] - fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> Rotation3 { + fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> Rotation3 { // James Arvo. // Fast random rotation matrices. // In D. Kirk, editor, Graphics Gems III, pages 117-120. Academic, New York, 1992. // Compute a random rotation around Z - let twopi = Uniform::new(N::zero(), N::simd_two_pi()); + let twopi = Uniform::new(T::zero(), T::simd_two_pi()); let theta = rng.sample(&twopi); let (ts, tc) = theta.simd_sin_cos(); - let a = MatrixN::::new( + let a = SMatrix::::new( tc, ts, - N::zero(), + T::zero(), -ts, tc, - N::zero(), - N::zero(), - N::zero(), - N::one(), + T::zero(), + T::zero(), + T::zero(), + T::one(), ); // Compute a random rotation *of* Z @@ -954,24 +954,24 @@ where let z = rng.sample(OpenClosed01); let (ps, pc) = phi.simd_sin_cos(); let sqrt_z = z.simd_sqrt(); - let v = Vector3::new(pc * sqrt_z, ps * sqrt_z, (N::one() - z).simd_sqrt()); + let v = Vector3::new(pc * sqrt_z, ps * sqrt_z, (T::one() - z).simd_sqrt()); let mut b = v * v.transpose(); b += b; - b -= MatrixN::::identity(); + b -= SMatrix::::identity(); Rotation3::from_matrix_unchecked(b * a) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Rotation3 +impl Arbitrary for Rotation3 where - N::Element: SimdRealField, - Owned: Send, - Owned: Send, + T::Element: SimdRealField, + Owned: Send, + Owned: Send, { #[inline] fn arbitrary(g: &mut Gen) -> Self { - Self::new(VectorN::arbitrary(g)) + Self::new(SVector::arbitrary(g)) } } diff --git a/src/geometry/similarity.rs b/src/geometry/similarity.rs index 8e813456..c11de6aa 100755 --- a/src/geometry/similarity.rs +++ b/src/geometry/similarity.rs @@ -18,7 +18,7 @@ use simba::simd::SimdRealField; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::storage::Owned; -use crate::base::{CVectorN, Const, DefaultAllocator, MatrixN, Scalar}; +use crate::base::{Const, DefaultAllocator, OMatrix, SVector, Scalar}; use crate::geometry::{AbstractRotation, Isometry, Point, Translation}; /// A similarity, i.e., an uniform scaling, followed by a rotation, followed by a translation. @@ -27,31 +27,28 @@ use crate::geometry::{AbstractRotation, Isometry, Point, Translation}; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "N: Serialize, + serde(bound(serialize = "T: Serialize, R: Serialize, - DefaultAllocator: Allocator>, - Owned>: Serialize")) + DefaultAllocator: Allocator>, + Owned>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "N: Deserialize<'de>, + serde(bound(deserialize = "T: Deserialize<'de>, R: Deserialize<'de>, - DefaultAllocator: Allocator>, - Owned>: Deserialize<'de>")) + DefaultAllocator: Allocator>, + Owned>: Deserialize<'de>")) )] -pub struct Similarity -// where -// DefaultAllocator: Allocator, -{ +pub struct Similarity { /// The part of this similarity that does not include the scaling factor. - pub isometry: Isometry, - scaling: N, + pub isometry: Isometry, + scaling: T, } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Similarity +impl Abomonation for Similarity where - Isometry: Abomonation, + Isometry: Abomonation, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.isometry.entomb(writer) @@ -66,9 +63,9 @@ where } } -impl hash::Hash for Similarity +impl hash::Hash for Similarity where - Owned>: hash::Hash, + Owned>: hash::Hash, { fn hash(&self, state: &mut H) { self.isometry.hash(state); @@ -76,17 +73,15 @@ where } } -impl + Copy, const D: usize> Copy - for Similarity +impl + Copy, const D: usize> Copy + for Similarity where - Owned>: Copy, + Owned>: Copy, { } -impl + Clone, const D: usize> Clone - for Similarity -// where -// DefaultAllocator: Allocator, +impl + Clone, const D: usize> Clone + for Similarity { #[inline] fn clone(&self) -> Self { @@ -94,19 +89,19 @@ impl + Clone, const D: usize> Clone } } -impl Similarity +impl Similarity where - R: AbstractRotation, + R: AbstractRotation, { /// Creates a new similarity from its rotational and translational parts. #[inline] - pub fn from_parts(translation: Translation, rotation: R, scaling: N) -> Self { + pub fn from_parts(translation: Translation, rotation: R, scaling: T) -> Self { Self::from_isometry(Isometry::from_parts(translation, rotation), scaling) } /// Creates a new similarity from its rotational and translational parts. #[inline] - pub fn from_isometry(isometry: Isometry, scaling: N) -> Self { + pub fn from_isometry(isometry: Isometry, scaling: T) -> Self { assert!(!scaling.is_zero(), "The scaling factor must not be zero."); Self { isometry, scaling } @@ -114,7 +109,7 @@ where /// The scaling factor of this similarity transformation. #[inline] - pub fn set_scaling(&mut self, scaling: N) { + pub fn set_scaling(&mut self, scaling: T) { assert!( !scaling.is_zero(), "The similarity scaling factor must not be zero." @@ -124,25 +119,22 @@ where } } -impl Similarity -// where -// DefaultAllocator: Allocator, -{ +impl Similarity { /// The scaling factor of this similarity transformation. #[inline] - pub fn scaling(&self) -> N { + pub fn scaling(&self) -> T { self.scaling.inlined_clone() } } -impl Similarity +impl Similarity where - N::Element: SimdRealField, - R: AbstractRotation, + T::Element: SimdRealField, + R: AbstractRotation, { /// Creates a new similarity that applies only a scaling factor. #[inline] - pub fn from_scaling(scaling: N) -> Self { + pub fn from_scaling(scaling: T) -> Self { Self::from_isometry(Isometry::identity(), scaling) } @@ -158,7 +150,7 @@ where /// Inverts `self` in-place. #[inline] pub fn inverse_mut(&mut self) { - self.scaling = N::one() / self.scaling; + self.scaling = T::one() / self.scaling; self.isometry.inverse_mut(); self.isometry.translation.vector *= self.scaling; } @@ -166,7 +158,7 @@ where /// The similarity transformation that applies a scaling factor `scaling` before `self`. #[inline] #[must_use = "Did you mean to use prepend_scaling_mut()?"] - pub fn prepend_scaling(&self, scaling: N) -> Self { + pub fn prepend_scaling(&self, scaling: T) -> Self { assert!( !scaling.is_zero(), "The similarity scaling factor must not be zero." @@ -178,7 +170,7 @@ where /// The similarity transformation that applies a scaling factor `scaling` after `self`. #[inline] #[must_use = "Did you mean to use append_scaling_mut()?"] - pub fn append_scaling(&self, scaling: N) -> Self { + pub fn append_scaling(&self, scaling: T) -> Self { assert!( !scaling.is_zero(), "The similarity scaling factor must not be zero." @@ -193,7 +185,7 @@ where /// Sets `self` to the similarity transformation that applies a scaling factor `scaling` before `self`. #[inline] - pub fn prepend_scaling_mut(&mut self, scaling: N) { + pub fn prepend_scaling_mut(&mut self, scaling: T) { assert!( !scaling.is_zero(), "The similarity scaling factor must not be zero." @@ -204,7 +196,7 @@ where /// Sets `self` to the similarity transformation that applies a scaling factor `scaling` after `self`. #[inline] - pub fn append_scaling_mut(&mut self, scaling: N) { + pub fn append_scaling_mut(&mut self, scaling: T) { assert!( !scaling.is_zero(), "The similarity scaling factor must not be zero." @@ -216,7 +208,7 @@ where /// Appends to `self` the given translation in-place. #[inline] - pub fn append_translation_mut(&mut self, t: &Translation) { + pub fn append_translation_mut(&mut self, t: &Translation) { self.isometry.append_translation_mut(t) } @@ -229,7 +221,7 @@ where /// Appends in-place to `self` a rotation centered at the point `p`, i.e., the rotation that /// lets `p` invariant. #[inline] - pub fn append_rotation_wrt_point_mut(&mut self, r: &R, p: &Point) { + pub fn append_rotation_wrt_point_mut(&mut self, r: &R, p: &Point) { self.isometry.append_rotation_wrt_point_mut(r, p) } @@ -256,7 +248,7 @@ where /// assert_relative_eq!(transformed_point, Point3::new(19.0, 17.0, -9.0), epsilon = 1.0e-5); /// ``` #[inline] - pub fn transform_point(&self, pt: &Point) -> Point { + pub fn transform_point(&self, pt: &Point) -> Point { self * pt } @@ -277,7 +269,7 @@ where /// assert_relative_eq!(transformed_vector, Vector3::new(18.0, 15.0, -12.0), epsilon = 1.0e-5); /// ``` #[inline] - pub fn transform_vector(&self, v: &CVectorN) -> CVectorN { + pub fn transform_vector(&self, v: &SVector) -> SVector { self * v } @@ -297,7 +289,7 @@ where /// assert_relative_eq!(transformed_point, Point3::new(-1.5, 1.5, 1.5), epsilon = 1.0e-5); /// ``` #[inline] - pub fn inverse_transform_point(&self, pt: &Point) -> Point { + pub fn inverse_transform_point(&self, pt: &Point) -> Point { self.isometry.inverse_transform_point(pt) / self.scaling() } @@ -317,7 +309,7 @@ where /// assert_relative_eq!(transformed_vector, Vector3::new(-3.0, 2.5, 2.0), epsilon = 1.0e-5); /// ``` #[inline] - pub fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { + pub fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.isometry.inverse_transform_vector(v) / self.scaling() } } @@ -326,21 +318,18 @@ where // and makes it harder to use it, e.g., for Transform × Isometry implementation. // 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, -{ +impl Similarity { /// Converts this similarity into its equivalent homogeneous transformation matrix. #[inline] - pub fn to_homogeneous(&self) -> MatrixN, U1>> + pub fn to_homogeneous(&self) -> OMatrix, U1>, DimNameSum, U1>> where Const: DimNameAdd, - R: SubsetOf, U1>>>, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + R: SubsetOf, U1>, DimNameSum, U1>>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { let mut res = self.isometry.to_homogeneous(); - for e in res.fixed_slice_mut::, Const>(0, 0).iter_mut() { + for e in res.fixed_slice_mut::(0, 0).iter_mut() { *e *= self.scaling } @@ -348,14 +337,14 @@ impl Similarity } } -impl Eq for Similarity where - R: AbstractRotation + Eq +impl Eq for Similarity where + R: AbstractRotation + Eq { } -impl PartialEq for Similarity +impl PartialEq for Similarity where - R: AbstractRotation + PartialEq, + R: AbstractRotation + PartialEq, { #[inline] fn eq(&self, right: &Self) -> bool { @@ -363,16 +352,16 @@ where } } -impl AbsDiffEq for Similarity +impl AbsDiffEq for Similarity where - R: AbstractRotation + AbsDiffEq, - N::Epsilon: Copy, + R: AbstractRotation + AbsDiffEq, + T::Epsilon: Copy, { - type Epsilon = N::Epsilon; + type Epsilon = T::Epsilon; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -382,14 +371,14 @@ where } } -impl RelativeEq for Similarity +impl RelativeEq for Similarity where - R: AbstractRotation + RelativeEq, - N::Epsilon: Copy, + R: AbstractRotation + RelativeEq, + T::Epsilon: Copy, { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -407,14 +396,14 @@ where } } -impl UlpsEq for Similarity +impl UlpsEq for Similarity where - R: AbstractRotation + UlpsEq, - N::Epsilon: Copy, + R: AbstractRotation + UlpsEq, + T::Epsilon: Copy, { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] @@ -429,10 +418,10 @@ where * Display * */ -impl fmt::Display for Similarity +impl fmt::Display for Similarity where - N: RealField + fmt::Display, - R: AbstractRotation + fmt::Display, + T: RealField + fmt::Display, + R: AbstractRotation + fmt::Display, { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let precision = f.precision().unwrap_or(3); diff --git a/src/geometry/similarity_alias.rs b/src/geometry/similarity_alias.rs index 9b397bbd..184769a1 100644 --- a/src/geometry/similarity_alias.rs +++ b/src/geometry/similarity_alias.rs @@ -1,13 +1,13 @@ use crate::geometry::{Rotation2, Rotation3, Similarity, UnitComplex, UnitQuaternion}; /// A 2-dimensional similarity. -pub type Similarity2 = Similarity, 2>; +pub type Similarity2 = Similarity, 2>; /// A 3-dimensional similarity. -pub type Similarity3 = Similarity, 3>; +pub type Similarity3 = Similarity, 3>; /// A 2-dimensional similarity using a rotation matrix for its rotation part. -pub type SimilarityMatrix2 = Similarity, 2>; +pub type SimilarityMatrix2 = Similarity, 2>; /// A 3-dimensional similarity using a rotation matrix for its rotation part. -pub type SimilarityMatrix3 = Similarity, 3>; +pub type SimilarityMatrix3 = Similarity, 3>; diff --git a/src/geometry/similarity_construction.rs b/src/geometry/similarity_construction.rs index 00847367..3c1b2b42 100644 --- a/src/geometry/similarity_construction.rs +++ b/src/geometry/similarity_construction.rs @@ -16,14 +16,14 @@ use simba::simd::SimdRealField; use crate::base::{Vector2, Vector3}; use crate::{ - AbstractRotation, Const, Isometry, Point, Point3, Rotation2, Rotation3, Scalar, Similarity, + AbstractRotation, Isometry, Point, Point3, Rotation2, Rotation3, Scalar, Similarity, Translation, UnitComplex, UnitQuaternion, }; -impl Similarity +impl Similarity where - N::Element: SimdRealField, - R: AbstractRotation, + T::Element: SimdRealField, + R: AbstractRotation, { /// Creates a new identity similarity. /// @@ -42,14 +42,14 @@ where /// ``` #[inline] pub fn identity() -> Self { - Self::from_isometry(Isometry::identity(), N::one()) + Self::from_isometry(Isometry::identity(), T::one()) } } -impl One for Similarity +impl One for Similarity where - N::Element: SimdRealField, - R: AbstractRotation, + T::Element: SimdRealField, + R: AbstractRotation, { /// Creates a new identity similarity. #[inline] @@ -59,16 +59,16 @@ where } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - R: AbstractRotation, - Standard: Distribution + Distribution, + R: AbstractRotation, + Standard: Distribution + Distribution, { /// Generate an arbitrary random variate for testing purposes. #[inline] - fn sample<'a, G: Rng + ?Sized>(&self, rng: &mut G) -> Similarity { + fn sample<'a, G: Rng + ?Sized>(&self, rng: &mut G) -> Similarity { let mut s = rng.gen(); - while relative_eq!(s, N::zero()) { + while relative_eq!(s, T::zero()) { s = rng.gen() } @@ -76,10 +76,10 @@ where } } -impl Similarity +impl Similarity where - N::Element: SimdRealField, - R: AbstractRotation, + T::Element: SimdRealField, + R: AbstractRotation, { /// The similarity that applies the scaling factor `scaling`, followed by the rotation `r` with /// its axis passing through the point `p`. @@ -97,23 +97,23 @@ where /// assert_relative_eq!(sim * Point2::new(1.0, 2.0), Point2::new(-3.0, 3.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn rotation_wrt_point(r: R, p: Point, scaling: N) -> Self { + pub fn rotation_wrt_point(r: R, p: Point, scaling: T) -> Self { let shift = r.transform_vector(&-&p.coords); Self::from_parts(Translation::from(shift + p.coords), r, scaling) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Similarity +impl Arbitrary for Similarity where - N: crate::RealField + Arbitrary + Send, - N::Element: crate::RealField, - R: AbstractRotation + Arbitrary + Send, - Owned>: Send, + T: crate::RealField + Arbitrary + Send, + T::Element: crate::RealField, + R: AbstractRotation + Arbitrary + Send, + Owned>: Send, { #[inline] fn arbitrary(rng: &mut Gen) -> Self { - let mut s: N = Arbitrary::arbitrary(rng); + let mut s: T = Arbitrary::arbitrary(rng); while s.is_zero() { s = Arbitrary::arbitrary(rng) } @@ -129,9 +129,9 @@ where */ // 2D similarity. -impl Similarity, 2> +impl Similarity, 2> where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Creates a new similarity from a translation, a rotation, and an uniform scaling factor. /// @@ -146,7 +146,7 @@ where /// assert_relative_eq!(sim * Point2::new(2.0, 4.0), Point2::new(-11.0, 8.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn new(translation: Vector2, angle: N, scaling: N) -> Self { + pub fn new(translation: Vector2, angle: T, scaling: T) -> Self { Self::from_parts( Translation::from(translation), Rotation2::new(angle), @@ -171,9 +171,9 @@ where } } -impl Similarity, 2> +impl Similarity, 2> where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Creates a new similarity from a translation and a rotation angle. /// @@ -188,7 +188,7 @@ where /// assert_relative_eq!(sim * Point2::new(2.0, 4.0), Point2::new(-11.0, 8.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn new(translation: Vector2, angle: N, scaling: N) -> Self { + pub fn new(translation: Vector2, angle: T, scaling: T) -> Self { Self::from_parts( Translation::from(translation), UnitComplex::new(angle), @@ -216,8 +216,8 @@ where // 3D rotation. macro_rules! similarity_construction_impl( ($Rot: ident) => { - impl Similarity, 3> - where N::Element: SimdRealField { + impl Similarity, 3> + where T::Element: SimdRealField { /// Creates a new similarity from a translation, rotation axis-angle, and scaling /// factor. /// @@ -244,9 +244,9 @@ macro_rules! similarity_construction_impl( /// assert_relative_eq!(sim * vec, Vector3::new(18.0, 15.0, -12.0), epsilon = 1.0e-5); /// ``` #[inline] - pub fn new(translation: Vector3, axisangle: Vector3, scaling: N) -> Self + pub fn new(translation: Vector3, axisangle: Vector3, scaling: T) -> Self { - Self::from_isometry(Isometry::<_, $Rot, 3>::new(translation, axisangle), scaling) + Self::from_isometry(Isometry::<_, $Rot, 3>::new(translation, axisangle), scaling) } /// Cast the components of `self` to another type. @@ -298,20 +298,20 @@ macro_rules! similarity_construction_impl( /// assert_relative_eq!(sim * Vector3::z(), Vector3::x() * 3.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn face_towards(eye: &Point3, - target: &Point3, - up: &Vector3, - scaling: N) + pub fn face_towards(eye: &Point3, + target: &Point3, + up: &Vector3, + scaling: T) -> Self { - Self::from_isometry(Isometry::<_, $Rot, 3>::face_towards(eye, target, up), scaling) + Self::from_isometry(Isometry::<_, $Rot, 3>::face_towards(eye, target, up), scaling) } /// Deprecated: Use [SimilarityMatrix3::face_towards] instead. #[deprecated(note="renamed to `face_towards`")] - pub fn new_observer_frames(eye: &Point3, - target: &Point3, - up: &Vector3, - scaling: N) + pub fn new_observer_frames(eye: &Point3, + target: &Point3, + up: &Vector3, + scaling: T) -> Self { Self::face_towards(eye, target, up, scaling) } @@ -346,12 +346,12 @@ macro_rules! similarity_construction_impl( /// assert_relative_eq!(iso * Vector3::x(), -Vector3::z() * 3.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn look_at_rh(eye: &Point3, - target: &Point3, - up: &Vector3, - scaling: N) + pub fn look_at_rh(eye: &Point3, + target: &Point3, + up: &Vector3, + scaling: T) -> Self { - Self::from_isometry(Isometry::<_, $Rot, 3>::look_at_rh(eye, target, up), scaling) + Self::from_isometry(Isometry::<_, $Rot, 3>::look_at_rh(eye, target, up), scaling) } /// Builds a left-handed look-at view matrix including a scaling factor. @@ -384,12 +384,12 @@ macro_rules! similarity_construction_impl( /// assert_relative_eq!(sim * Vector3::x(), Vector3::z() * 3.0, epsilon = 1.0e-6); /// ``` #[inline] - pub fn look_at_lh(eye: &Point3, - target: &Point3, - up: &Vector3, - scaling: N) + pub fn look_at_lh(eye: &Point3, + target: &Point3, + up: &Vector3, + scaling: T) -> Self { - Self::from_isometry(Isometry::<_, $Rot, 3>::look_at_lh(eye, target, up), scaling) + Self::from_isometry(Isometry::<_, $Rot, 3>::look_at_lh(eye, target, up), scaling) } } } diff --git a/src/geometry/similarity_conversion.rs b/src/geometry/similarity_conversion.rs index d22d4e3e..2a2338b0 100644 --- a/src/geometry/similarity_conversion.rs +++ b/src/geometry/similarity_conversion.rs @@ -5,7 +5,7 @@ use simba::simd::{PrimitiveSimdValue, SimdRealField, SimdValue}; use crate::base::allocator::Allocator; use crate::base::dimension::{DimMin, DimNameAdd, DimNameSum, U1}; -use crate::base::{Const, DefaultAllocator, MatrixN, Scalar}; +use crate::base::{Const, DefaultAllocator, OMatrix, Scalar}; use crate::geometry::{ AbstractRotation, Isometry, Similarity, SuperTCategoryOf, TAffine, Transform, Translation, @@ -20,26 +20,26 @@ use crate::geometry::{ * Similarity -> Matrix (homogeneous) */ -impl SubsetOf> for Similarity +impl SubsetOf> for Similarity where - N1: RealField + SubsetOf, - N2: RealField + SupersetOf, - R1: AbstractRotation + SubsetOf, - R2: AbstractRotation, + T1: RealField + SubsetOf, + T2: RealField + SupersetOf, + R1: AbstractRotation + SubsetOf, + R2: AbstractRotation, { #[inline] - fn to_superset(&self) -> Similarity { + fn to_superset(&self) -> Similarity { Similarity::from_isometry(self.isometry.to_superset(), self.scaling().to_superset()) } #[inline] - fn is_in_subset(sim: &Similarity) -> bool { - crate::is_convertible::<_, Isometry>(&sim.isometry) - && crate::is_convertible::<_, N1>(&sim.scaling()) + fn is_in_subset(sim: &Similarity) -> bool { + crate::is_convertible::<_, Isometry>(&sim.isometry) + && crate::is_convertible::<_, T1>(&sim.scaling()) } #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { + fn from_superset_unchecked(sim: &Similarity) -> Self { Similarity::from_isometry( sim.isometry.to_subset_unchecked(), sim.scaling().to_subset_unchecked(), @@ -47,117 +47,120 @@ where } } -impl SubsetOf> for Similarity +impl SubsetOf> for Similarity where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, C: SuperTCategoryOf, - R: AbstractRotation - + SubsetOf, U1>>> - + SubsetOf, U1>>>, + R: AbstractRotation + + SubsetOf, U1>, DimNameSum, U1>>> + + SubsetOf, U1>, DimNameSum, U1>>>, Const: DimNameAdd + DimMin, Output = Const>, // needed by .determinant() - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, // + Allocator<(usize, usize), D> - // + Allocator - // + Allocator - // + Allocator - // + Allocator, + // + Allocator + // + Allocator + // + Allocator + // + Allocator, { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl SubsetOf, U1>>> - for Similarity +impl + SubsetOf, U1>, DimNameSum, U1>>> + for Similarity where - N1: RealField, - N2: RealField + SupersetOf, - R: AbstractRotation - + SubsetOf, U1>>> - + SubsetOf, U1>>>, + T1: RealField, + T2: RealField + SupersetOf, + R: AbstractRotation + + SubsetOf, U1>, DimNameSum, U1>>> + + SubsetOf, U1>, DimNameSum, U1>>>, Const: DimNameAdd + DimMin, Output = Const>, // needed by .determinant() - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>>, // + Allocator<(usize, usize), D> - // + Allocator - // + Allocator - // + Allocator - // + Allocator + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, // + Allocator<(usize, usize), D> + // + Allocator + // + Allocator + // + Allocator + // + Allocator { #[inline] - fn to_superset(&self) -> MatrixN, U1>> { + fn to_superset(&self) -> OMatrix, U1>, DimNameSum, U1>> { self.to_homogeneous().to_superset() } #[inline] - fn is_in_subset(m: &MatrixN, U1>>) -> bool { - let mut rot = m.fixed_slice::, Const>(0, 0).clone_owned(); + fn is_in_subset(m: &OMatrix, U1>, DimNameSum, U1>>) -> bool { + let mut rot = m.fixed_slice::(0, 0).clone_owned(); if rot - .fixed_columns_mut::(0) - .try_normalize_mut(N2::zero()) + .fixed_columns_mut::<1>(0) + .try_normalize_mut(T2::zero()) .is_some() && rot - .fixed_columns_mut::(1) - .try_normalize_mut(N2::zero()) + .fixed_columns_mut::<1>(1) + .try_normalize_mut(T2::zero()) .is_some() && rot - .fixed_columns_mut::(2) - .try_normalize_mut(N2::zero()) + .fixed_columns_mut::<1>(2) + .try_normalize_mut(T2::zero()) .is_some() { // TODO: could we avoid explicit the computation of the determinant? // (its sign is needed to see if the scaling factor is negative). - if rot.determinant() < N2::zero() { - rot.fixed_columns_mut::(0).neg_mut(); - rot.fixed_columns_mut::(1).neg_mut(); - rot.fixed_columns_mut::(2).neg_mut(); + if rot.determinant() < T2::zero() { + rot.fixed_columns_mut::<1>(0).neg_mut(); + rot.fixed_columns_mut::<1>(1).neg_mut(); + rot.fixed_columns_mut::<1>(2).neg_mut(); } - let bottom = m.fixed_slice::>(D, 0); + let bottom = m.fixed_slice::<1, D>(D, 0); // Scalar types agree. - m.iter().all(|e| SupersetOf::::is_in_subset(e)) && + m.iter().all(|e| SupersetOf::::is_in_subset(e)) && // The normalized block part is a rotation. - // rot.is_special_orthogonal(N2::default_epsilon().sqrt()) && + // rot.is_special_orthogonal(T2::default_epsilon().sqrt()) && // The bottom row is (0, 0, ..., 1) - bottom.iter().all(|e| e.is_zero()) && m[(D, D)] == N2::one() + bottom.iter().all(|e| e.is_zero()) && m[(D, D)] == T2::one() } else { false } } #[inline] - fn from_superset_unchecked(m: &MatrixN, U1>>) -> Self { + fn from_superset_unchecked( + m: &OMatrix, U1>, DimNameSum, U1>>, + ) -> Self { let mut mm = m.clone_owned(); - let na = mm.fixed_slice_mut::, U1>(0, 0).normalize_mut(); - let nb = mm.fixed_slice_mut::, U1>(0, 1).normalize_mut(); - let nc = mm.fixed_slice_mut::, U1>(0, 2).normalize_mut(); + let na = mm.fixed_slice_mut::(0, 0).normalize_mut(); + let nb = mm.fixed_slice_mut::(0, 1).normalize_mut(); + let nc = mm.fixed_slice_mut::(0, 2).normalize_mut(); let mut scale = (na + nb + nc) / crate::convert(3.0); // We take the mean, for robustness. // TODO: could we avoid the explicit computation of the determinant? // (its sign is needed to see if the scaling factor is negative). - if mm.fixed_slice::, Const>(0, 0).determinant() < N2::zero() { - mm.fixed_slice_mut::, U1>(0, 0).neg_mut(); - mm.fixed_slice_mut::, U1>(0, 1).neg_mut(); - mm.fixed_slice_mut::, U1>(0, 2).neg_mut(); + if mm.fixed_slice::(0, 0).determinant() < T2::zero() { + mm.fixed_slice_mut::(0, 0).neg_mut(); + mm.fixed_slice_mut::(0, 1).neg_mut(); + mm.fixed_slice_mut::(0, 2).neg_mut(); scale = -scale; } - let t = m.fixed_slice::, U1>(0, D).into_owned(); + let t = m.fixed_slice::(0, D).into_owned(); let t = Translation { vector: crate::convert_unchecked(t), }; @@ -170,55 +173,55 @@ where } } -impl From> - for MatrixN, U1>> +impl From> + for OMatrix, U1>, DimNameSum, U1>> where Const: DimNameAdd, - R: SubsetOf, U1>>>, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, // + Allocator + R: SubsetOf, U1>, DimNameSum, U1>>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, // + Allocator { #[inline] - fn from(sim: Similarity) -> Self { + fn from(sim: Similarity) -> Self { sim.to_homogeneous() } } -impl - From<[Similarity; 2]> for Similarity +impl + From<[Similarity; 2]> for Similarity where - N: From<[::Element; 2]>, - R: SimdValue + AbstractRotation + From<[::Element; 2]>, - R::Element: AbstractRotation, - N::Element: Scalar + Zero + Copy, + T: From<[::Element; 2]>, + R: SimdValue + AbstractRotation + From<[::Element; 2]>, + R::Element: AbstractRotation, + T::Element: Scalar + Zero + Copy, R::Element: Scalar + Zero + Copy, { #[inline] - fn from(arr: [Similarity; 2]) -> Self { + fn from(arr: [Similarity; 2]) -> Self { let iso = Isometry::from([arr[0].isometry.clone(), arr[1].isometry.clone()]); - let scale = N::from([arr[0].scaling(), arr[1].scaling()]); + let scale = T::from([arr[0].scaling(), arr[1].scaling()]); Self::from_isometry(iso, scale) } } -impl - From<[Similarity; 4]> for Similarity +impl + From<[Similarity; 4]> for Similarity where - N: From<[::Element; 4]>, - R: SimdValue + AbstractRotation + From<[::Element; 4]>, - R::Element: AbstractRotation, - N::Element: Scalar + Zero + Copy, + T: From<[::Element; 4]>, + R: SimdValue + AbstractRotation + From<[::Element; 4]>, + R::Element: AbstractRotation, + T::Element: Scalar + Zero + Copy, R::Element: Scalar + Zero + Copy, { #[inline] - fn from(arr: [Similarity; 4]) -> Self { + fn from(arr: [Similarity; 4]) -> Self { let iso = Isometry::from([ arr[0].isometry.clone(), arr[1].isometry.clone(), arr[2].isometry.clone(), arr[3].isometry.clone(), ]); - let scale = N::from([ + let scale = T::from([ arr[0].scaling(), arr[1].scaling(), arr[2].scaling(), @@ -229,17 +232,17 @@ where } } -impl - From<[Similarity; 8]> for Similarity +impl + From<[Similarity; 8]> for Similarity where - N: From<[::Element; 8]>, - R: SimdValue + AbstractRotation + From<[::Element; 8]>, - R::Element: AbstractRotation, - N::Element: Scalar + Zero + Copy, + T: From<[::Element; 8]>, + R: SimdValue + AbstractRotation + From<[::Element; 8]>, + R::Element: AbstractRotation, + T::Element: Scalar + Zero + Copy, R::Element: Scalar + Zero + Copy, { #[inline] - fn from(arr: [Similarity; 8]) -> Self { + fn from(arr: [Similarity; 8]) -> Self { let iso = Isometry::from([ arr[0].isometry.clone(), arr[1].isometry.clone(), @@ -250,7 +253,7 @@ where arr[6].isometry.clone(), arr[7].isometry.clone(), ]); - let scale = N::from([ + let scale = T::from([ arr[0].scaling(), arr[1].scaling(), arr[2].scaling(), @@ -265,17 +268,17 @@ where } } -impl - From<[Similarity; 16]> for Similarity +impl + From<[Similarity; 16]> for Similarity where - N: From<[::Element; 16]>, - R: SimdValue + AbstractRotation + From<[::Element; 16]>, - R::Element: AbstractRotation, - N::Element: Scalar + Zero + Copy, + T: From<[::Element; 16]>, + R: SimdValue + AbstractRotation + From<[::Element; 16]>, + R::Element: AbstractRotation, + T::Element: Scalar + Zero + Copy, R::Element: Scalar + Zero + Copy, { #[inline] - fn from(arr: [Similarity; 16]) -> Self { + fn from(arr: [Similarity; 16]) -> Self { let iso = Isometry::from([ arr[0].isometry.clone(), arr[1].isometry.clone(), @@ -294,7 +297,7 @@ where arr[14].isometry.clone(), arr[15].isometry.clone(), ]); - let scale = N::from([ + let scale = T::from([ arr[0].scaling(), arr[1].scaling(), arr[2].scaling(), diff --git a/src/geometry/similarity_ops.rs b/src/geometry/similarity_ops.rs index b1818f4a..65b8b4a5 100644 --- a/src/geometry/similarity_ops.rs +++ b/src/geometry/similarity_ops.rs @@ -6,7 +6,7 @@ use simba::simd::SimdRealField; use crate::base::allocator::Allocator; use crate::base::dimension::{U1, U2, U3}; -use crate::base::{CVectorN, Const, DefaultAllocator, Scalar}; +use crate::base::{Const, DefaultAllocator, SVector, Scalar}; use crate::geometry::{ AbstractRotation, Isometry, Point, Rotation, Similarity, Translation, UnitComplex, @@ -70,9 +70,9 @@ macro_rules! similarity_binop_impl( ($Op: ident, $op: ident; $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Output: ty; $action: expr; $($lives: tt),*) => { - impl<$($lives ,)* N: SimdRealField, R, const D: usize> $Op<$Rhs> for $Lhs - where N::Element: SimdRealField, - R: AbstractRotation { + impl<$($lives ,)* T: SimdRealField, R, const D: usize> $Op<$Rhs> for $Lhs + where T::Element: SimdRealField, + R: AbstractRotation { type Output = $Output; #[inline] @@ -117,18 +117,18 @@ macro_rules! similarity_binop_assign_impl_all( $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty; [val] => $action_val: expr; [ref] => $action_ref: expr;) => { - impl $OpAssign<$Rhs> for $Lhs - where N::Element: SimdRealField, - R: AbstractRotation{ + impl $OpAssign<$Rhs> for $Lhs + where T::Element: SimdRealField, + R: AbstractRotation{ #[inline] fn $op_assign(&mut $lhs, $rhs: $Rhs) { $action_val } } - impl<'b, N: SimdRealField, R, const D: usize> $OpAssign<&'b $Rhs> for $Lhs - where N::Element: SimdRealField, - R: AbstractRotation { + impl<'b, T: SimdRealField, R, const D: usize> $OpAssign<&'b $Rhs> for $Lhs + where T::Element: SimdRealField, + R: AbstractRotation { #[inline] fn $op_assign(&mut $lhs, $rhs: &'b $Rhs) { $action_ref @@ -141,7 +141,7 @@ macro_rules! similarity_binop_assign_impl_all( // Similarity ÷ Similarity similarity_binop_impl_all!( Mul, mul; - self: Similarity, rhs: Similarity, Output = Similarity; + self: Similarity, rhs: Similarity, Output = Similarity; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -154,7 +154,7 @@ similarity_binop_impl_all!( similarity_binop_impl_all!( Div, div; - self: Similarity, rhs: Similarity, Output = Similarity; + self: Similarity, rhs: Similarity, Output = Similarity; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -164,7 +164,7 @@ similarity_binop_impl_all!( // Similarity ×= Translation similarity_binop_assign_impl_all!( MulAssign, mul_assign; - self: Similarity, rhs: Translation; + self: Similarity, rhs: Translation; [val] => *self *= &rhs; [ref] => { let shift = self.isometry.rotation.transform_vector(&rhs.vector) * self.scaling(); @@ -176,7 +176,7 @@ similarity_binop_assign_impl_all!( // Similarity ÷= Similarity similarity_binop_assign_impl_all!( MulAssign, mul_assign; - self: Similarity, rhs: Similarity; + self: Similarity, rhs: Similarity; [val] => *self *= &rhs; [ref] => { *self *= &rhs.isometry; @@ -186,7 +186,7 @@ similarity_binop_assign_impl_all!( similarity_binop_assign_impl_all!( DivAssign, div_assign; - self: Similarity, rhs: Similarity; + self: Similarity, rhs: Similarity; [val] => *self /= &rhs; // TODO: don't invert explicitly. [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; @@ -196,7 +196,7 @@ similarity_binop_assign_impl_all!( // Similarity ÷= Isometry similarity_binop_assign_impl_all!( MulAssign, mul_assign; - self: Similarity, rhs: Isometry; + self: Similarity, rhs: Isometry; [val] => *self *= &rhs; [ref] => { let shift = self.isometry.rotation.transform_vector(&rhs.translation.vector) * self.scaling(); @@ -207,7 +207,7 @@ similarity_binop_assign_impl_all!( similarity_binop_assign_impl_all!( DivAssign, div_assign; - self: Similarity, rhs: Isometry; + self: Similarity, rhs: Isometry; [val] => *self /= &rhs; // TODO: don't invert explicitly. [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; @@ -216,57 +216,57 @@ similarity_binop_assign_impl_all!( // Similarity ×= R // Similarity ÷= R md_assign_impl_all!( - MulAssign, mul_assign where N: SimdRealField for N::Element: SimdRealField; + MulAssign, mul_assign where T: SimdRealField for T::Element: SimdRealField; (Const, U1), (Const, Const) const D; for; where; - self: Similarity, D>, rhs: Rotation; + self: Similarity, D>, rhs: Rotation; [val] => self.isometry.rotation *= rhs; [ref] => self.isometry.rotation *= rhs.clone(); ); md_assign_impl_all!( - DivAssign, div_assign where N: SimdRealField for N::Element: SimdRealField; + DivAssign, div_assign where T: SimdRealField for T::Element: SimdRealField; (Const, U1), (Const, Const) const D; for; where; - self: Similarity, D>, rhs: Rotation; + self: Similarity, D>, rhs: Rotation; // TODO: don't invert explicitly? [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; ); md_assign_impl_all!( - MulAssign, mul_assign where N: SimdRealField for N::Element: SimdRealField; + MulAssign, mul_assign where T: SimdRealField for T::Element: SimdRealField; (U3, U3), (U3, U3) const; for; where; - self: Similarity, 3>, rhs: UnitQuaternion; + self: Similarity, 3>, rhs: UnitQuaternion; [val] => self.isometry.rotation *= rhs; [ref] => self.isometry.rotation *= *rhs; ); md_assign_impl_all!( - DivAssign, div_assign where N: SimdRealField for N::Element: SimdRealField; + DivAssign, div_assign where T: SimdRealField for T::Element: SimdRealField; (U3, U3), (U3, U3) const; for; where; - self: Similarity, 3>, rhs: UnitQuaternion; + self: Similarity, 3>, rhs: UnitQuaternion; // TODO: don't invert explicitly? [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; ); md_assign_impl_all!( - MulAssign, mul_assign where N: SimdRealField for N::Element: SimdRealField; + MulAssign, mul_assign where T: SimdRealField for T::Element: SimdRealField; (U2, U2), (U2, U2) const; for; where; - self: Similarity, 2>, rhs: UnitComplex; + self: Similarity, 2>, rhs: UnitComplex; [val] => self.isometry.rotation *= rhs; [ref] => self.isometry.rotation *= *rhs; ); md_assign_impl_all!( - DivAssign, div_assign where N: SimdRealField for N::Element: SimdRealField; + DivAssign, div_assign where T: SimdRealField for T::Element: SimdRealField; (U2, U2), (U2, U2) const; for; where; - self: Similarity, 2>, rhs: UnitComplex; + self: Similarity, 2>, rhs: UnitComplex; // TODO: don't invert explicitly? [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; @@ -276,7 +276,7 @@ md_assign_impl_all!( // Similarity ÷ Isometry similarity_binop_impl_all!( Mul, mul; - self: Similarity, rhs: Isometry, Output = Similarity; + self: Similarity, rhs: Isometry, Output = Similarity; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -292,7 +292,7 @@ similarity_binop_impl_all!( similarity_binop_impl_all!( Div, div; - self: Similarity, rhs: Isometry, Output = Similarity; + self: Similarity, rhs: Isometry, Output = Similarity; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -303,7 +303,7 @@ similarity_binop_impl_all!( // Isometry ÷ Similarity similarity_binop_impl_all!( Mul, mul; - self: Isometry, rhs: Similarity, Output = Similarity; + self: Isometry, rhs: Similarity, Output = Similarity; [val val] => { let scaling = rhs.scaling(); Similarity::from_isometry(self * rhs.isometry, scaling) @@ -324,7 +324,7 @@ similarity_binop_impl_all!( similarity_binop_impl_all!( Div, div; - self: Isometry, rhs: Similarity, Output = Similarity; + self: Isometry, rhs: Similarity, Output = Similarity; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -334,7 +334,7 @@ similarity_binop_impl_all!( // Similarity × Point similarity_binop_impl_all!( Mul, mul; - self: Similarity, right: Point, Output = Point; + self: Similarity, right: Point, Output = Point; [val val] => { let scaling = self.scaling(); self.isometry.translation * (self.isometry.rotation.transform_point(&right) * scaling) @@ -350,7 +350,7 @@ similarity_binop_impl_all!( // Similarity × Vector similarity_binop_impl_all!( Mul, mul; - self: Similarity, right: CVectorN, Output = CVectorN; + self: Similarity, right: SVector, Output = SVector; [val val] => self.isometry.rotation.transform_vector(&right) * self.scaling(); [ref val] => self.isometry.rotation.transform_vector(&right) * self.scaling(); [val ref] => self.isometry.rotation.transform_vector(right) * self.scaling(); @@ -360,7 +360,7 @@ similarity_binop_impl_all!( // Similarity × Translation similarity_binop_impl_all!( Mul, mul; - self: Similarity, right: Translation, Output = Similarity; + self: Similarity, right: Translation, Output = Similarity; [val val] => &self * &right; [ref val] => self * &right; [val ref] => &self * right; @@ -377,7 +377,7 @@ similarity_binop_impl_all!( // Translation × Similarity similarity_binop_impl_all!( Mul, mul; - self: Translation, right: Similarity, Output = Similarity; + self: Translation, right: Similarity, Output = Similarity; [val val] => { let scaling = right.scaling(); Similarity::from_isometry(self * right.isometry, scaling) @@ -395,8 +395,8 @@ macro_rules! similarity_from_composition_impl( $($Dims: ident),*; $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Output: ty; $action: expr; $($lives: tt),*) => { - impl<$($lives ,)* N: SimdRealField $(, const $Dims: usize)*> $Op<$Rhs> for $Lhs - where N::Element: SimdRealField { + impl<$($lives ,)* T: SimdRealField $(, const $Dims: usize)*> $Op<$Rhs> for $Lhs + where T::Element: SimdRealField { type Output = $Output; #[inline] @@ -446,8 +446,8 @@ macro_rules! similarity_from_composition_impl_all( similarity_from_composition_impl_all!( Mul, mul; D; - self: Similarity, D>, rhs: Rotation, - Output = Similarity, D>; + self: Similarity, D>, rhs: Rotation, + Output = Similarity, D>; [val val] => { let scaling = self.scaling(); Similarity::from_isometry(self.isometry * rhs, scaling) @@ -464,8 +464,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Mul, mul; D; - self: Rotation, right: Similarity, D>, - Output = Similarity, D>; + self: Rotation, right: Similarity, D>, + Output = Similarity, D>; [val val] => &self * &right; [ref val] => self * &right; [val ref] => &self * right; @@ -476,8 +476,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Div, div; D; - self: Similarity, D>, rhs: Rotation, - Output = Similarity, D>; + self: Similarity, D>, rhs: Rotation, + Output = Similarity, D>; [val val] => { let scaling = self.scaling(); Similarity::from_isometry(self.isometry / rhs, scaling) @@ -494,8 +494,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Div, div; D; - self: Rotation, right: Similarity, D>, - Output = Similarity, D>; + self: Rotation, right: Similarity, D>, + Output = Similarity, D>; // TODO: don't call inverse explicitly? [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; @@ -507,8 +507,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Mul, mul; ; - self: Similarity, 3>, rhs: UnitQuaternion, - Output = Similarity, 3>; + self: Similarity, 3>, rhs: UnitQuaternion, + Output = Similarity, 3>; [val val] => { let scaling = self.scaling(); Similarity::from_isometry(self.isometry * rhs, scaling) @@ -525,8 +525,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Mul, mul; ; - self: UnitQuaternion, right: Similarity, 3>, - Output = Similarity, 3>; + self: UnitQuaternion, right: Similarity, 3>, + Output = Similarity, 3>; [val val] => &self * &right; [ref val] => self * &right; [val ref] => &self * right; @@ -537,8 +537,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Div, div; ; - self: Similarity, 3>, rhs: UnitQuaternion, - Output = Similarity, 3>; + self: Similarity, 3>, rhs: UnitQuaternion, + Output = Similarity, 3>; [val val] => { let scaling = self.scaling(); Similarity::from_isometry(self.isometry / rhs, scaling) @@ -555,8 +555,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Div, div; ; - self: UnitQuaternion, right: Similarity, 3>, - Output = Similarity, 3>; + self: UnitQuaternion, right: Similarity, 3>, + Output = Similarity, 3>; // TODO: don't call inverse explicitly? [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * right.inverse() }; @@ -568,8 +568,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Mul, mul; ; - self: Similarity, 2>, rhs: UnitComplex, - Output = Similarity, 2>; + self: Similarity, 2>, rhs: UnitComplex, + Output = Similarity, 2>; [val val] => { let scaling = self.scaling(); Similarity::from_isometry(self.isometry * rhs, scaling) @@ -586,8 +586,8 @@ similarity_from_composition_impl_all!( similarity_from_composition_impl_all!( Div, div; ; - self: Similarity, 2>, rhs: UnitComplex, - Output = Similarity, 2>; + self: Similarity, 2>, rhs: UnitComplex, + Output = Similarity, 2>; [val val] => { let scaling = self.scaling(); Similarity::from_isometry(self.isometry / rhs, scaling) diff --git a/src/geometry/similarity_simba.rs b/src/geometry/similarity_simba.rs index 91a9e733..e4de581d 100755 --- a/src/geometry/similarity_simba.rs +++ b/src/geometry/similarity_simba.rs @@ -2,23 +2,23 @@ use simba::simd::{SimdRealField, SimdValue}; use crate::geometry::{AbstractRotation, Isometry, Similarity}; -impl SimdValue for Similarity +impl SimdValue for Similarity where - N::Element: SimdRealField, - R: SimdValue + AbstractRotation, - R::Element: AbstractRotation, + T::Element: SimdRealField, + R: SimdValue + AbstractRotation, + R::Element: AbstractRotation, { - type Element = Similarity; - type SimdBool = N::SimdBool; + type Element = Similarity; + type SimdBool = T::SimdBool; #[inline] fn lanes() -> usize { - N::lanes() + T::lanes() } #[inline] fn splat(val: Self::Element) -> Self { - let scaling = N::splat(val.scaling()); + let scaling = T::splat(val.scaling()); Similarity::from_isometry(Isometry::splat(val.isometry), scaling) } diff --git a/src/geometry/swizzle.rs b/src/geometry/swizzle.rs index d76464e6..6e4c6df8 100644 --- a/src/geometry/swizzle.rs +++ b/src/geometry/swizzle.rs @@ -8,7 +8,7 @@ macro_rules! impl_swizzle { $( /// Builds a new point from components of `self`. #[inline] - pub fn $name(&self) -> $Result + pub fn $name(&self) -> $Result where as ToTypenum>::Typenum: Cmp { $Result::new($(self[$i].inlined_clone()),*) } @@ -18,7 +18,7 @@ macro_rules! impl_swizzle { } /// # Swizzling -impl Point +impl Point where Const: ToTypenum, { diff --git a/src/geometry/transform.rs b/src/geometry/transform.rs index fceae681..cbc855ea 100755 --- a/src/geometry/transform.rs +++ b/src/geometry/transform.rs @@ -11,7 +11,7 @@ use simba::scalar::RealField; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::storage::Owned; -use crate::base::{CVectorN, Const, DefaultAllocator, DimName, MatrixN}; +use crate::base::{Const, DefaultAllocator, DimName, OMatrix, SVector}; use crate::geometry::Point; @@ -28,10 +28,10 @@ pub trait TCategory: Any + Debug + Copy + PartialEq + Send { /// Checks that the given matrix is a valid homogeneous representation of an element of the /// category `Self`. - fn check_homogeneous_invariants(mat: &MatrixN) -> bool + fn check_homogeneous_invariants(mat: &OMatrix) -> bool where - N::Epsilon: Copy, - DefaultAllocator: Allocator; + T::Epsilon: Copy, + DefaultAllocator: Allocator; } /// Traits that gives the `Transform` category that is compatible with the result of the @@ -71,10 +71,10 @@ pub enum TAffine {} impl TCategory for TGeneral { #[inline] - fn check_homogeneous_invariants(_: &MatrixN) -> bool + fn check_homogeneous_invariants(_: &OMatrix) -> bool where - N::Epsilon: Copy, - DefaultAllocator: Allocator, + T::Epsilon: Copy, + DefaultAllocator: Allocator, { true } @@ -82,10 +82,10 @@ impl TCategory for TGeneral { impl TCategory for TProjective { #[inline] - fn check_homogeneous_invariants(mat: &MatrixN) -> bool + fn check_homogeneous_invariants(mat: &OMatrix) -> bool where - N::Epsilon: Copy, - DefaultAllocator: Allocator, + T::Epsilon: Copy, + DefaultAllocator: Allocator, { mat.is_invertible() } @@ -98,14 +98,14 @@ impl TCategory for TAffine { } #[inline] - fn check_homogeneous_invariants(mat: &MatrixN) -> bool + fn check_homogeneous_invariants(mat: &OMatrix) -> bool where - N::Epsilon: Copy, - DefaultAllocator: Allocator, + T::Epsilon: Copy, + DefaultAllocator: Allocator, { let last = D::dim() - 1; mat.is_invertible() - && mat[(last, last)] == N::one() + && mat[(last, last)] == T::one() && (0..last).all(|i| mat[(last, i)].is_zero()) } } @@ -157,36 +157,36 @@ super_tcategory_impl!( /// 3D transformation. #[repr(C)] #[derive(Debug)] -pub struct Transform +pub struct Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { - matrix: MatrixN, U1>>, + matrix: OMatrix, U1>, DimNameSum, U1>>, _phantom: PhantomData, } // TODO -// impl + hash::Hash, C: TCategory> hash::Hash for Transform -// where DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, -// Owned, U1>, DimNameSum, U1>>: hash::Hash { +// impl + hash::Hash, C: TCategory> hash::Hash for Transform +// where DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, +// Owned, U1>, DimNameSum, U1>>: hash::Hash { // fn hash(&self, state: &mut H) { // self.matrix.hash(state); // } // } -impl Copy for Transform +impl Copy for Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, - Owned, U1>, DimNameSum, U1>>: Copy, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + Owned, U1>, DimNameSum, U1>>: Copy, { } -impl Clone for Transform +impl Clone for Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn clone(&self) -> Self { @@ -195,11 +195,11 @@ where } #[cfg(feature = "serde-serialize")] -impl Serialize for Transform +impl Serialize for Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, - Owned, U1>, DimNameSum, U1>>: Serialize, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + Owned, U1>, DimNameSum, U1>>: Serialize, { fn serialize(&self, serializer: S) -> Result where @@ -210,33 +210,35 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N: RealField, C: TCategory, const D: usize> Deserialize<'a> for Transform +impl<'a, T: RealField, C: TCategory, const D: usize> Deserialize<'a> for Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, - Owned, U1>, DimNameSum, U1>>: Deserialize<'a>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + Owned, U1>, DimNameSum, U1>>: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result where Des: Deserializer<'a>, { - let matrix = MatrixN::, U1>>::deserialize(deserializer)?; + let matrix = OMatrix::, U1>, DimNameSum, U1>>::deserialize( + deserializer, + )?; Ok(Transform::from_matrix_unchecked(matrix)) } } -impl Eq for Transform +impl Eq for Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { } -impl PartialEq for Transform +impl PartialEq for Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn eq(&self, right: &Self) -> bool { @@ -244,15 +246,17 @@ where } } -impl Transform +impl Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { /// Creates a new transformation from the given homogeneous matrix. The transformation category /// of `Self` is not checked to be verified by the given matrix. #[inline] - pub fn from_matrix_unchecked(matrix: MatrixN, U1>>) -> Self { + pub fn from_matrix_unchecked( + matrix: OMatrix, U1>, DimNameSum, U1>>, + ) -> Self { Transform { matrix, _phantom: PhantomData, @@ -272,7 +276,7 @@ where /// assert_eq!(t.into_inner(), m); /// ``` #[inline] - pub fn into_inner(self) -> MatrixN, U1>> { + pub fn into_inner(self) -> OMatrix, U1>, DimNameSum, U1>> { self.matrix } @@ -280,7 +284,7 @@ where /// Deprecated: Use [Transform::into_inner] instead. #[deprecated(note = "use `.into_inner()` instead")] #[inline] - pub fn unwrap(self) -> MatrixN, U1>> { + pub fn unwrap(self) -> OMatrix, U1>, DimNameSum, U1>> { self.matrix } @@ -297,7 +301,7 @@ where /// assert_eq!(*t.matrix(), m); /// ``` #[inline] - pub fn matrix(&self) -> &MatrixN, U1>> { + pub fn matrix(&self) -> &OMatrix, U1>, DimNameSum, U1>> { &self.matrix } @@ -324,7 +328,9 @@ where /// assert_eq!(*t.matrix(), expected); /// ``` #[inline] - pub fn matrix_mut_unchecked(&mut self) -> &mut MatrixN, U1>> { + pub fn matrix_mut_unchecked( + &mut self, + ) -> &mut OMatrix, U1>, DimNameSum, U1>> { &mut self.matrix } @@ -335,7 +341,7 @@ where /// `TAffine` because not all projective transformations are affine (the other way-round is /// valid though). #[inline] - pub fn set_category>(self) -> Transform { + pub fn set_category>(self) -> Transform { Transform::from_matrix_unchecked(self.matrix) } @@ -344,7 +350,7 @@ where #[deprecated( note = "This method is redundant with automatic `Copy` and the `.clone()` method and will be removed in a future release." )] - pub fn clone_owned(&self) -> Transform { + pub fn clone_owned(&self) -> Transform { Transform::from_matrix_unchecked(self.matrix.clone_owned()) } @@ -361,7 +367,7 @@ where /// assert_eq!(t.into_inner(), m); /// ``` #[inline] - pub fn to_homogeneous(&self) -> MatrixN, U1>> { + pub fn to_homogeneous(&self) -> OMatrix, U1>, DimNameSum, U1>> { self.matrix().clone_owned() } @@ -390,7 +396,7 @@ where /// ``` #[inline] #[must_use = "Did you mean to use try_inverse_mut()?"] - pub fn try_inverse(self) -> Option> { + pub fn try_inverse(self) -> Option> { if let Some(m) = self.matrix.try_inverse() { Some(Transform::from_matrix_unchecked(m)) } else { @@ -416,7 +422,7 @@ where /// ``` #[inline] #[must_use = "Did you mean to use inverse_mut()?"] - pub fn inverse(self) -> Transform + pub fn inverse(self) -> Transform where C: SubTCategoryOf, { @@ -479,20 +485,20 @@ where } } -impl Transform +impl Transform where - N: RealField, + T: RealField, C: TCategory, Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>>, // + Allocator - // + Allocator + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>>, // + Allocator + // + Allocator { /// Transform the given point by this transformation. /// /// This is the same as the multiplication `self * pt`. #[inline] - pub fn transform_point(&self, pt: &Point) -> Point { + pub fn transform_point(&self, pt: &Point) -> Point { self * pt } @@ -501,24 +507,24 @@ where /// /// This is the same as the multiplication `self * v`. #[inline] - pub fn transform_vector(&self, v: &CVectorN) -> CVectorN { + pub fn transform_vector(&self, v: &SVector) -> SVector { self * v } } -impl Transform +impl Transform where Const: DimNameAdd, C: SubTCategoryOf, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>>, // + Allocator - // + Allocator + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>>, // + Allocator + // + Allocator { /// Transform the given point by the inverse of this transformation. /// This may be cheaper than inverting the transformation and transforming /// the point. #[inline] - pub fn inverse_transform_point(&self, pt: &Point) -> Point { + pub fn inverse_transform_point(&self, pt: &Point) -> Point { self.clone().inverse() * pt } @@ -526,35 +532,37 @@ where /// This may be cheaper than inverting the transformation and transforming /// the vector. #[inline] - pub fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { + pub fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.clone().inverse() * v } } -impl Transform +impl Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { /// A mutable reference to underlying matrix. Use `.matrix_mut_unchecked` instead if this /// transformation category is not `TGeneral`. #[inline] - pub fn matrix_mut(&mut self) -> &mut MatrixN, U1>> { + pub fn matrix_mut( + &mut self, + ) -> &mut OMatrix, U1>, DimNameSum, U1>> { self.matrix_mut_unchecked() } } -impl AbsDiffEq for Transform +impl AbsDiffEq for Transform where Const: DimNameAdd, - N::Epsilon: Copy, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + T::Epsilon: Copy, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { - type Epsilon = N::Epsilon; + type Epsilon = T::Epsilon; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -563,15 +571,15 @@ where } } -impl RelativeEq for Transform +impl RelativeEq for Transform where Const: DimNameAdd, - N::Epsilon: Copy, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + T::Epsilon: Copy, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -586,15 +594,15 @@ where } } -impl UlpsEq for Transform +impl UlpsEq for Transform where Const: DimNameAdd, - N::Epsilon: Copy, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + T::Epsilon: Copy, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] diff --git a/src/geometry/transform_alias.rs b/src/geometry/transform_alias.rs index f869f0e2..179a8189 100644 --- a/src/geometry/transform_alias.rs +++ b/src/geometry/transform_alias.rs @@ -1,15 +1,15 @@ use crate::geometry::{TAffine, TGeneral, TProjective, Transform}; /// A 2D general transformation that may not be invertible. Stored as a homogeneous 3x3 matrix. -pub type Transform2 = Transform; +pub type Transform2 = Transform; /// An invertible 2D general transformation. Stored as a homogeneous 3x3 matrix. -pub type Projective2 = Transform; +pub type Projective2 = Transform; /// A 2D affine transformation. Stored as a homogeneous 3x3 matrix. -pub type Affine2 = Transform; +pub type Affine2 = Transform; /// A 3D general transformation that may not be inversible. Stored as a homogeneous 4x4 matrix. -pub type Transform3 = Transform; +pub type Transform3 = Transform; /// An invertible 3D general transformation. Stored as a homogeneous 4x4 matrix. -pub type Projective3 = Transform; +pub type Projective3 = Transform; /// A 3D affine transformation. Stored as a homogeneous 4x4 matrix. -pub type Affine3 = Transform; +pub type Affine3 = Transform; diff --git a/src/geometry/transform_construction.rs b/src/geometry/transform_construction.rs index 0d5f8b1e..e9601864 100644 --- a/src/geometry/transform_construction.rs +++ b/src/geometry/transform_construction.rs @@ -4,14 +4,14 @@ use simba::scalar::RealField; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; -use crate::base::{Const, DefaultAllocator, MatrixN}; +use crate::base::{Const, DefaultAllocator, OMatrix}; use crate::geometry::{TCategory, Transform}; -impl Transform +impl Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { /// Creates a new identity transform. /// @@ -43,14 +43,18 @@ where /// ``` #[inline] pub fn identity() -> Self { - Self::from_matrix_unchecked(MatrixN::<_, DimNameSum, U1>>::identity()) + Self::from_matrix_unchecked(OMatrix::< + _, + DimNameSum, U1>, + DimNameSum, U1>, + >::identity()) } } -impl One for Transform +impl One for Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { /// Creates a new identity transform. #[inline] diff --git a/src/geometry/transform_conversion.rs b/src/geometry/transform_conversion.rs index 0522f7a2..e8eb3908 100644 --- a/src/geometry/transform_conversion.rs +++ b/src/geometry/transform_conversion.rs @@ -2,75 +2,78 @@ use simba::scalar::{RealField, SubsetOf}; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; -use crate::base::{Const, DefaultAllocator, MatrixN}; +use crate::base::{Const, DefaultAllocator, OMatrix}; use crate::geometry::{SuperTCategoryOf, TCategory, Transform}; -impl SubsetOf> for Transform +impl SubsetOf> for Transform where - N1: RealField + SubsetOf, - N2: RealField, + T1: RealField + SubsetOf, + T2: RealField, C1: TCategory, C2: SuperTCategoryOf, Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>>, - N1::Epsilon: Copy, - N2::Epsilon: Copy, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, + T1::Epsilon: Copy, + T2::Epsilon: Copy, { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl SubsetOf, U1>>> - for Transform +impl + SubsetOf, U1>, DimNameSum, U1>>> + for Transform where - N1: RealField + SubsetOf, - N2: RealField, + T1: RealField + SubsetOf, + T2: RealField, C: TCategory, Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>>, - N1::Epsilon: Copy, - N2::Epsilon: Copy, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, + T1::Epsilon: Copy, + T2::Epsilon: Copy, { #[inline] - fn to_superset(&self) -> MatrixN, U1>> { + fn to_superset(&self) -> OMatrix, U1>, DimNameSum, U1>> { self.matrix().to_superset() } #[inline] - fn is_in_subset(m: &MatrixN, U1>>) -> bool { + fn is_in_subset(m: &OMatrix, U1>, DimNameSum, U1>>) -> bool { C::check_homogeneous_invariants(m) } #[inline] - fn from_superset_unchecked(m: &MatrixN, U1>>) -> Self { + fn from_superset_unchecked( + m: &OMatrix, U1>, DimNameSum, U1>>, + ) -> Self { Self::from_matrix_unchecked(crate::convert_ref_unchecked(m)) } } -impl From> - for MatrixN, U1>> +impl From> + for OMatrix, U1>, DimNameSum, U1>> where Const: DimNameAdd, C: TCategory, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] - fn from(t: Transform) -> Self { + fn from(t: Transform) -> Self { t.to_homogeneous() } } diff --git a/src/geometry/transform_ops.rs b/src/geometry/transform_ops.rs index 7a70c546..ceefd280 100644 --- a/src/geometry/transform_ops.rs +++ b/src/geometry/transform_ops.rs @@ -5,7 +5,7 @@ use simba::scalar::{ClosedAdd, ClosedMul, RealField, SubsetOf}; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1, U4}; -use crate::base::{CVectorN, Const, DefaultAllocator, MatrixN, Scalar}; +use crate::base::{Const, DefaultAllocator, OMatrix, SVector, Scalar}; use crate::geometry::{ Isometry, Point, Rotation, Similarity, SubTCategoryOf, SuperTCategoryOf, TAffine, TCategory, @@ -79,47 +79,47 @@ use crate::geometry::{ * Indexing. * */ -impl Index<(usize, usize)> for Transform +impl Index<(usize, usize)> for Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { - type Output = N; + type Output = T; #[inline] - fn index(&self, ij: (usize, usize)) -> &N { + fn index(&self, ij: (usize, usize)) -> &T { self.matrix().index(ij) } } // Only general transformations are mutably indexable. -impl IndexMut<(usize, usize)> for Transform +impl IndexMut<(usize, usize)> for Transform where Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] - fn index_mut(&mut self, ij: (usize, usize)) -> &mut N { + fn index_mut(&mut self, ij: (usize, usize)) -> &mut T { self.matrix_mut().index_mut(ij) } } // Transform × Vector md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C; where Const: DimNameAdd, C: TCategory; - self: Transform, rhs: CVectorN, Output = CVectorN; + self: Transform, rhs: SVector, Output = SVector; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; [ref ref] => { - let transform = self.matrix().fixed_slice::, Const>(0, 0); + let transform = self.matrix().fixed_slice::(0, 0); if C::has_normalizer() { - let normalizer = self.matrix().fixed_slice::>(D, 0); + let normalizer = self.matrix().fixed_slice::<1, D>(D, 0); let n = normalizer.tr_dot(&rhs); if !n.is_zero() { @@ -133,21 +133,21 @@ md_impl_all!( // Transform × Point md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C; where Const: DimNameAdd, C: TCategory; - self: Transform, rhs: Point, Output = Point; + self: Transform, rhs: Point, Output = Point; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; [ref ref] => { - let transform = self.matrix().fixed_slice::, Const>(0, 0); - let translation = self.matrix().fixed_slice::, U1>(0, D); + let transform = self.matrix().fixed_slice::(0, 0); + let translation = self.matrix().fixed_slice::(0, D); if C::has_normalizer() { - let normalizer = self.matrix().fixed_slice::>(D, 0); + let normalizer = self.matrix().fixed_slice::<1, D>(D, 0); #[allow(clippy::suspicious_arithmetic_impl)] let n = normalizer.tr_dot(&rhs.coords) + unsafe { *self.matrix().get_unchecked((D, D)) }; @@ -162,12 +162,12 @@ md_impl_all!( // Transform × Transform md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (DimNameSum, U1>, DimNameSum, U1>) const D; for CA, CB; where Const: DimNameAdd, CA: TCategoryMul, CB: TCategory; - self: Transform, rhs: Transform, Output = Transform; + self: Transform, rhs: Transform, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.into_inner()); [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.into_inner()); [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.matrix()); @@ -176,12 +176,12 @@ md_impl_all!( // Transform × Rotation md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, Const) const D; for C; where Const: DimNameAdd, C: TCategoryMul; - self: Transform, rhs: Rotation, Output = Transform; + self: Transform, rhs: Rotation, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); @@ -190,12 +190,12 @@ md_impl_all!( // Rotation × Transform md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (Const, Const), (DimNameSum, U1>, DimNameSum, U1>) const D; for C; where Const: DimNameAdd, C: TCategoryMul; - self: Rotation, rhs: Transform, Output = Transform; + self: Rotation, rhs: Transform, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); [ref val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); [val ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); @@ -204,12 +204,12 @@ md_impl_all!( // Transform × UnitQuaternion md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (U4, U4), (U4, U1) const; for C; where C: TCategoryMul; - self: Transform, rhs: UnitQuaternion, Output = Transform; + self: Transform, rhs: UnitQuaternion, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); @@ -218,12 +218,12 @@ md_impl_all!( // UnitQuaternion × Transform md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (U4, U1), (U4, U4) const; for C; where C: TCategoryMul; - self: UnitQuaternion, rhs: Transform, Output = Transform; + self: UnitQuaternion, rhs: Transform, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); [ref val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); [val ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); @@ -232,12 +232,12 @@ md_impl_all!( // Transform × Isometry md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C, R; - where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>> >; - self: Transform, rhs: Isometry, Output = Transform; + where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> >; + self: Transform, rhs: Isometry, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); @@ -246,12 +246,12 @@ md_impl_all!( // Isometry × Transform md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (Const, U1), (DimNameSum, U1>, DimNameSum, U1>) const D; for C, R; - where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>> >; - self: Isometry, rhs: Transform, Output = Transform; + where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> >; + self: Isometry, rhs: Transform, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); [ref val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); [val ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); @@ -260,12 +260,12 @@ md_impl_all!( // Transform × Similarity md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C, R; - where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>> >; - self: Transform, rhs: Similarity, Output = Transform; + where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> >; + self: Transform, rhs: Similarity, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); @@ -274,12 +274,12 @@ md_impl_all!( // Similarity × Transform md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (Const, U1), (DimNameSum, U1>, DimNameSum, U1>) const D; for C, R; - where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>> >; - self: Similarity, rhs: Transform, Output = Transform; + where Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> >; + self: Similarity, rhs: Transform, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); [ref val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); [val ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); @@ -296,12 +296,12 @@ md_impl_all!( */ // Transform × Translation md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C; where Const: DimNameAdd, C: TCategoryMul; - self: Transform, rhs: Translation, Output = Transform; + self: Transform, rhs: Translation, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); @@ -310,12 +310,12 @@ md_impl_all!( // Translation × Transform md_impl_all!( - Mul, mul where N: RealField; + Mul, mul where T: RealField; (Const, U1), (DimNameSum, U1>, DimNameSum, U1>) const D; for C; where Const: DimNameAdd, C: TCategoryMul; - self: Translation, rhs: Transform, Output = Transform; + self: Translation, rhs: Transform, Output = Transform; [val val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); [ref val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); [val ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); @@ -324,12 +324,12 @@ md_impl_all!( // Transform ÷ Transform md_impl_all!( - Div, div where N: RealField; + Div, div where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (DimNameSum, U1>, DimNameSum, U1>) const D; for CA, CB; where Const: DimNameAdd, CA: TCategoryMul, CB: SubTCategoryOf; - self: Transform, rhs: Transform, Output = Transform; + self: Transform, rhs: Transform, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.clone().inverse() }; @@ -338,12 +338,12 @@ md_impl_all!( // Transform ÷ Rotation md_impl_all!( - Div, div where N: RealField; + Div, div where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, Const) const D; for C; where Const: DimNameAdd, C: TCategoryMul; - self: Transform, rhs: Rotation, Output = Transform; + self: Transform, rhs: Rotation, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -352,12 +352,12 @@ md_impl_all!( // Rotation ÷ Transform md_impl_all!( - Div, div where N: RealField; + Div, div where T: RealField; (Const, Const), (DimNameSum, U1>, DimNameSum, U1>) const D; for C; where Const: DimNameAdd, C: TCategoryMul; - self: Rotation, rhs: Transform, Output = Transform; + self: Rotation, rhs: Transform, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; @@ -366,12 +366,12 @@ md_impl_all!( // Transform ÷ UnitQuaternion md_impl_all!( - Div, div where N: RealField; + Div, div where T: RealField; (U4, U4), (U4, U1) const; for C; where C: TCategoryMul; - self: Transform, rhs: UnitQuaternion, Output = Transform; + self: Transform, rhs: UnitQuaternion, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -380,12 +380,12 @@ md_impl_all!( // UnitQuaternion ÷ Transform md_impl_all!( - Div, div where N: RealField; + Div, div where T: RealField; (U4, U1), (U4, U4) const; for C; where C: TCategoryMul; - self: UnitQuaternion, rhs: Transform, Output = Transform; + self: UnitQuaternion, rhs: Transform, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; @@ -394,11 +394,11 @@ md_impl_all!( // // Transform ÷ Isometry // md_impl_all!( -// Div, div where N: RealField; +// Div, div where T: RealField; // (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) -// for Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>> > -// where SB::Alloc: Allocator, U1>, DimNameSum, U1> >; -// self: Transform, rhs: Isometry, Output = Transform; +// for Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> > +// where SB::Alloc: Allocator, U1>, DimNameSum, U1> >; +// self: Transform, rhs: Isometry, Output = Transform; // [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.inverse().to_homogeneous()); // [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.inverse().to_homogeneous()); // [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.inverse().to_homogeneous()); @@ -407,11 +407,11 @@ md_impl_all!( // // Isometry ÷ Transform // md_impl_all!( -// Div, div where N: RealField; +// Div, div where T: RealField; // (Const, U1), (DimNameSum, U1>, DimNameSum, U1>) -// for Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>> > -// where SA::Alloc: Allocator, U1>, DimNameSum, U1> >; -// self: Isometry, rhs: Transform, Output = Transform; +// for Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> > +// where SA::Alloc: Allocator, U1>, DimNameSum, U1> >; +// self: Isometry, rhs: Transform, Output = Transform; // [val val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); // [ref val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); // [val ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); @@ -420,12 +420,12 @@ md_impl_all!( // // Transform ÷ Similarity // md_impl_all!( -// Div, div where N: RealField; +// Div, div where T: RealField; // (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) -// for Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>> > -// where SB::Alloc: Allocator -// where SB::Alloc: Allocator, U1>, DimNameSum, U1> >; -// self: Transform, rhs: Similarity, Output = Transform; +// for Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> > +// where SB::Alloc: Allocator +// where SB::Alloc: Allocator, U1>, DimNameSum, U1> >; +// self: Transform, rhs: Similarity, Output = Transform; // [val val] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); // [ref val] => Self::Output::from_matrix_unchecked(self.matrix() * rhs.to_homogeneous()); // [val ref] => Self::Output::from_matrix_unchecked(self.into_inner() * rhs.to_homogeneous()); @@ -434,12 +434,12 @@ md_impl_all!( // // Similarity ÷ Transform // md_impl_all!( -// Div, div where N: RealField; +// Div, div where T: RealField; // (Const, U1), (DimNameSum, U1>, DimNameSum, U1>) -// for Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>> > -// where SA::Alloc: Allocator -// where SA::Alloc: Allocator, U1>, DimNameSum, U1> >; -// self: Similarity, rhs: Transform, Output = Transform; +// for Const: DimNameAdd, C: TCategoryMul, R: SubsetOf, U1>, DimNameSum, U1>> > +// where SA::Alloc: Allocator +// where SA::Alloc: Allocator, U1>, DimNameSum, U1> >; +// self: Similarity, rhs: Transform, Output = Transform; // [val val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); // [ref val] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.into_inner()); // [val ref] => Self::Output::from_matrix_unchecked(self.to_homogeneous() * rhs.matrix()); @@ -448,12 +448,12 @@ md_impl_all!( // Transform ÷ Translation md_impl_all!( - Div, div where N: RealField; + Div, div where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C; where Const: DimNameAdd, C: TCategoryMul; - self: Transform, rhs: Translation, Output = Transform; + self: Transform, rhs: Translation, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self * rhs.inverse() }; @@ -462,12 +462,12 @@ md_impl_all!( // Translation ÷ Transform md_impl_all!( - Div, div where N: RealField; + Div, div where T: RealField; (Const, U1), (DimNameSum, U1>, DimNameSum, U1>) const D; for C; where Const: DimNameAdd, C: TCategoryMul; - self: Translation, rhs: Transform, Output = Transform; + self: Translation, rhs: Transform, Output = Transform; [val val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; [ref val] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; [val ref] => #[allow(clippy::suspicious_arithmetic_impl)] { self.inverse() * rhs }; @@ -476,36 +476,36 @@ md_impl_all!( // Transform ×= Transform md_assign_impl_all!( - MulAssign, mul_assign where N: RealField; + MulAssign, mul_assign where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (DimNameSum, U1>, DimNameSum, U1>) const D; for CA, CB; where Const: DimNameAdd, CA: TCategory, CB: SubTCategoryOf; - self: Transform, rhs: Transform; + self: Transform, rhs: Transform; [val] => *self.matrix_mut_unchecked() *= rhs.into_inner(); [ref] => *self.matrix_mut_unchecked() *= rhs.matrix(); ); // Transform ×= Similarity md_assign_impl_all!( - MulAssign, mul_assign where N: RealField; + MulAssign, mul_assign where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C, R; - where Const: DimNameAdd, C: TCategory, R: SubsetOf, U1>> >; - self: Transform, rhs: Similarity; + where Const: DimNameAdd, C: TCategory, R: SubsetOf, U1>, DimNameSum, U1>> >; + self: Transform, rhs: Similarity; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); ); // Transform ×= Isometry md_assign_impl_all!( - MulAssign, mul_assign where N: RealField; + MulAssign, mul_assign where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C, R; - where Const: DimNameAdd, C: TCategory, R: SubsetOf, U1>> >; - self: Transform, rhs: Isometry; + where Const: DimNameAdd, C: TCategory, R: SubsetOf, U1>, DimNameSum, U1>> >; + self: Transform, rhs: Isometry; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); ); @@ -520,48 +520,48 @@ md_assign_impl_all!( */ // Transform ×= Translation md_assign_impl_all!( - MulAssign, mul_assign where N: RealField; + MulAssign, mul_assign where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C; where Const: DimNameAdd, C: TCategory; - self: Transform, rhs: Translation; + self: Transform, rhs: Translation; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); ); // Transform ×= Rotation md_assign_impl_all!( - MulAssign, mul_assign where N: RealField; + MulAssign, mul_assign where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, Const) const D; for C; where Const: DimNameAdd, C: TCategory; - self: Transform, rhs: Rotation; + self: Transform, rhs: Rotation; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); ); // Transform ×= UnitQuaternion md_assign_impl_all!( - MulAssign, mul_assign where N: RealField; + MulAssign, mul_assign where T: RealField; (U4, U4), (U4, U1) const; for C; where C: TCategory; - self: Transform, rhs: UnitQuaternion; + self: Transform, rhs: UnitQuaternion; [val] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); [ref] => *self.matrix_mut_unchecked() *= rhs.to_homogeneous(); ); // Transform ÷= Transform md_assign_impl_all!( - DivAssign, div_assign where N: RealField; + DivAssign, div_assign where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (DimNameSum, U1>, DimNameSum, U1>) const D; for CA, CB; where Const: DimNameAdd, CA: SuperTCategoryOf, CB: SubTCategoryOf; - self: Transform, rhs: Transform; + self: Transform, rhs: Transform; [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.clone().inverse() }; ); @@ -570,8 +570,8 @@ md_assign_impl_all!( // md_assign_impl_all!( // DivAssign, div_assign; // (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) -// for Const: DimNameAdd, C: TCategory, R: SubsetOf, U1>> >; -// self: Transform, rhs: Similarity; +// for Const: DimNameAdd, C: TCategory, R: SubsetOf, U1>, DimNameSum, U1>> >; +// self: Transform, rhs: Similarity; // [val] => *self *= rhs.inverse(); // [ref] => *self *= rhs.inverse(); // ); @@ -581,44 +581,44 @@ md_assign_impl_all!( // md_assign_impl_all!( // DivAssign, div_assign; // (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) -// for Const: DimNameAdd, C: TCategory, R: SubsetOf, U1>> >; -// self: Transform, rhs: Isometry; +// for Const: DimNameAdd, C: TCategory, R: SubsetOf, U1>, DimNameSum, U1>> >; +// self: Transform, rhs: Isometry; // [val] => *self *= rhs.inverse(); // [ref] => *self *= rhs.inverse(); // ); // Transform ÷= Translation md_assign_impl_all!( - DivAssign, div_assign where N: RealField; + DivAssign, div_assign where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, U1) const D; for C; where Const: DimNameAdd, C: TCategory; - self: Transform, rhs: Translation; + self: Transform, rhs: Translation; [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; ); // Transform ÷= Rotation md_assign_impl_all!( - DivAssign, div_assign where N: RealField; + DivAssign, div_assign where T: RealField; (DimNameSum, U1>, DimNameSum, U1>), (Const, Const) const D; for C; where Const: DimNameAdd, C: TCategory; - self: Transform, rhs: Rotation; + self: Transform, rhs: Rotation; [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; ); // Transform ÷= UnitQuaternion md_assign_impl_all!( - DivAssign, div_assign where N: RealField; + DivAssign, div_assign where T: RealField; (U4, U4), (U4, U1) const; for C; where C: TCategory; - self: Transform, rhs: UnitQuaternion; + self: Transform, rhs: UnitQuaternion; [val] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; [ref] => #[allow(clippy::suspicious_op_assign_impl)] { *self *= rhs.inverse() }; ); diff --git a/src/geometry/transform_simba.rs b/src/geometry/transform_simba.rs index 0d116137..db794712 100755 --- a/src/geometry/transform_simba.rs +++ b/src/geometry/transform_simba.rs @@ -2,30 +2,30 @@ use simba::simd::SimdValue; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; -use crate::base::{Const, DefaultAllocator, MatrixN, Scalar}; +use crate::base::{Const, DefaultAllocator, OMatrix, Scalar}; use crate::RealField; use crate::geometry::{TCategory, Transform}; -impl SimdValue for Transform +impl SimdValue for Transform where - N::Element: Scalar, + T::Element: Scalar, C: TCategory, Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, { - type Element = Transform; - type SimdBool = N::SimdBool; + type Element = Transform; + type SimdBool = T::SimdBool; #[inline] fn lanes() -> usize { - N::lanes() + T::lanes() } #[inline] fn splat(val: Self::Element) -> Self { - Transform::from_matrix_unchecked(MatrixN::splat(val.into_inner())) + Transform::from_matrix_unchecked(OMatrix::splat(val.into_inner())) } #[inline] diff --git a/src/geometry/translation.rs b/src/geometry/translation.rs index 0fc450cc..6f6f0de1 100755 --- a/src/geometry/translation.rs +++ b/src/geometry/translation.rs @@ -16,36 +16,33 @@ use simba::scalar::{ClosedAdd, ClosedNeg, ClosedSub}; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::storage::Owned; -use crate::base::{CVectorN, Const, DefaultAllocator, MatrixN, Scalar}; +use crate::base::{Const, DefaultAllocator, OMatrix, SVector, Scalar}; use crate::geometry::Point; /// A translation. #[repr(C)] #[derive(Debug)] -pub struct Translation -// where -// DefaultAllocator: Allocator, -{ +pub struct Translation { /// The translation coordinates, i.e., how much is added to a point's coordinates when it is /// translated. - pub vector: CVectorN, + pub vector: SVector, } -impl hash::Hash for Translation +impl hash::Hash for Translation where - Owned>: hash::Hash, + Owned>: hash::Hash, { fn hash(&self, state: &mut H) { self.vector.hash(state) } } -impl Copy for Translation where Owned>: Copy {} +impl Copy for Translation where Owned>: Copy {} -impl Clone for Translation +impl Clone for Translation where - Owned>: Clone, + Owned>: Clone, { #[inline] fn clone(&self) -> Self { @@ -54,10 +51,10 @@ where } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Translation +impl Abomonation for Translation where - N: Scalar, - CVectorN: Abomonation, + T: Scalar, + SVector: Abomonation, { unsafe fn entomb(&self, writer: &mut W) -> IOResult<()> { self.vector.entomb(writer) @@ -73,9 +70,9 @@ where } #[cfg(feature = "serde-serialize")] -impl Serialize for Translation +impl Serialize for Translation where - Owned>: Serialize, + Owned>: Serialize, { fn serialize(&self, serializer: S) -> Result where @@ -86,28 +83,25 @@ where } #[cfg(feature = "serde-serialize")] -impl<'a, N: Scalar, const D: usize> Deserialize<'a> for Translation +impl<'a, T: Scalar, const D: usize> Deserialize<'a> for Translation where - Owned>: Deserialize<'a>, + Owned>: Deserialize<'a>, { fn deserialize(deserializer: Des) -> Result where Des: Deserializer<'a>, { - let matrix = CVectorN::::deserialize(deserializer)?; + let matrix = SVector::::deserialize(deserializer)?; Ok(Translation::from(matrix)) } } -impl Translation -// where -// DefaultAllocator: Allocator, -{ +impl Translation { /// Creates a new translation from the given vector. #[inline] #[deprecated(note = "Use `::from` instead.")] - pub fn from_vector(vector: CVectorN) -> Translation { + pub fn from_vector(vector: SVector) -> Translation { Translation { vector } } @@ -127,9 +121,9 @@ impl Translation /// ``` #[inline] #[must_use = "Did you mean to use inverse_mut()?"] - pub fn inverse(&self) -> Translation + pub fn inverse(&self) -> Translation where - N: ClosedNeg, + T: ClosedNeg, { Translation::from(-&self.vector) } @@ -153,15 +147,14 @@ impl Translation /// assert_eq!(t.to_homogeneous(), expected); /// ``` #[inline] - pub fn to_homogeneous(&self) -> MatrixN, U1>> + pub fn to_homogeneous(&self) -> OMatrix, U1>, DimNameSum, U1>> where - N: Zero + One, + T: Zero + One, Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { - let mut res = MatrixN::, U1>>::identity(); - res.fixed_slice_mut::, U1>(0, D) - .copy_from(&self.vector); + let mut res = OMatrix::, U1>, DimNameSum, U1>>::identity(); + res.fixed_slice_mut::(0, D).copy_from(&self.vector); res } @@ -187,16 +180,13 @@ impl Translation #[inline] pub fn inverse_mut(&mut self) where - N: ClosedNeg, + T: ClosedNeg, { self.vector.neg_mut() } } -impl Translation -// where -// DefaultAllocator: Allocator, -{ +impl Translation { /// Translate the given point. /// /// This is the same as the multiplication `self * pt`. @@ -208,15 +198,12 @@ impl Translation /// let transformed_point = t.transform_point(&Point3::new(4.0, 5.0, 6.0)); /// assert_eq!(transformed_point, Point3::new(5.0, 7.0, 9.0)); #[inline] - pub fn transform_point(&self, pt: &Point) -> Point { + pub fn transform_point(&self, pt: &Point) -> Point { pt + &self.vector } } -impl Translation -// where -// DefaultAllocator: Allocator, -{ +impl Translation { /// Translate the given point by the inverse of this translation. /// /// # Example @@ -226,35 +213,29 @@ impl Translation /// let transformed_point = t.inverse_transform_point(&Point3::new(4.0, 5.0, 6.0)); /// assert_eq!(transformed_point, Point3::new(3.0, 3.0, 3.0)); #[inline] - pub fn inverse_transform_point(&self, pt: &Point) -> Point { + pub fn inverse_transform_point(&self, pt: &Point) -> Point { pt - &self.vector } } -impl Eq for Translation -// where DefaultAllocator: Allocator -{ -} +impl Eq for Translation {} -impl PartialEq for Translation -// where -// DefaultAllocator: Allocator, -{ +impl PartialEq for Translation { #[inline] - fn eq(&self, right: &Translation) -> bool { + fn eq(&self, right: &Translation) -> bool { self.vector == right.vector } } -impl AbsDiffEq for Translation +impl AbsDiffEq for Translation where - N::Epsilon: Copy, + T::Epsilon: Copy, { - type Epsilon = N::Epsilon; + type Epsilon = T::Epsilon; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -263,13 +244,13 @@ where } } -impl RelativeEq for Translation +impl RelativeEq for Translation where - N::Epsilon: Copy, + T::Epsilon: Copy, { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -284,13 +265,13 @@ where } } -impl UlpsEq for Translation +impl UlpsEq for Translation where - N::Epsilon: Copy, + T::Epsilon: Copy, { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] @@ -304,10 +285,7 @@ where * Display * */ -impl fmt::Display for Translation -// where -// DefaultAllocator: Allocator + Allocator, -{ +impl fmt::Display for Translation { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let precision = f.precision().unwrap_or(3); diff --git a/src/geometry/translation_alias.rs b/src/geometry/translation_alias.rs index 554fecc5..06dc0794 100644 --- a/src/geometry/translation_alias.rs +++ b/src/geometry/translation_alias.rs @@ -1,19 +1,19 @@ use crate::geometry::Translation; /// A 1-dimensional translation. -pub type Translation1 = Translation; +pub type Translation1 = Translation; /// A 2-dimensional translation. -pub type Translation2 = Translation; +pub type Translation2 = Translation; /// A 3-dimensional translation. -pub type Translation3 = Translation; +pub type Translation3 = Translation; /// A 4-dimensional translation. -pub type Translation4 = Translation; +pub type Translation4 = Translation; /// A 5-dimensional translation. -pub type Translation5 = Translation; +pub type Translation5 = Translation; /// A 6-dimensional translation. -pub type Translation6 = Translation; +pub type Translation6 = Translation; diff --git a/src/geometry/translation_construction.rs b/src/geometry/translation_construction.rs index 7ee2359c..ca87d389 100644 --- a/src/geometry/translation_construction.rs +++ b/src/geometry/translation_construction.rs @@ -12,14 +12,10 @@ use rand::{ use simba::scalar::{ClosedAdd, SupersetOf}; -use crate::base::{CVectorN, Const, Scalar}; - +use crate::base::{SVector, Scalar}; use crate::geometry::Translation; -impl Translation -// where -// DefaultAllocator: Allocator, -{ +impl Translation { /// Creates a new identity translation. /// /// # Example @@ -35,11 +31,11 @@ impl Translation /// assert_eq!(t * p, p); /// ``` #[inline] - pub fn identity() -> Translation + pub fn identity() -> Translation where - N: Zero, + T: Zero, { - Self::from(CVectorN::::from_element(N::zero())) + Self::from(SVector::::from_element(T::zero())) } /// Cast the components of `self` to another type. @@ -59,10 +55,7 @@ impl Translation } } -impl One for Translation -// where -// DefaultAllocator: Allocator, -{ +impl One for Translation { #[inline] fn one() -> Self { Self::identity() @@ -70,25 +63,25 @@ impl One for Translation } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - Standard: Distribution, + Standard: Distribution, { /// Generate an arbitrary random variate for testing purposes. #[inline] - fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Translation { - Translation::from(rng.gen::>()) + fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Translation { + Translation::from(rng.gen::>()) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Translation +impl Arbitrary for Translation where - Owned>: Send, + Owned>: Send, { #[inline] fn arbitrary(rng: &mut Gen) -> Self { - let v: CVectorN = Arbitrary::arbitrary(rng); + let v: SVector = Arbitrary::arbitrary(rng); Self::from(v) } } @@ -100,16 +93,15 @@ where */ macro_rules! componentwise_constructors_impl( ($($doc: expr; $D: expr, $($args: ident:$irow: expr),*);* $(;)*) => {$( - impl Translation - // where DefaultAllocator: Allocator + impl Translation { #[doc = "Initializes this translation from its components."] #[doc = "# Example\n```"] #[doc = $doc] #[doc = "```"] #[inline] - pub fn new($($args: N),*) -> Self { - Self::from(CVectorN::::new($($args),*)) + pub fn new($($args: T),*) -> Self { + Self::from(SVector::::new($($args),*)) } } )*} diff --git a/src/geometry/translation_conversion.rs b/src/geometry/translation_conversion.rs index ca5daa25..8c8f860f 100644 --- a/src/geometry/translation_conversion.rs +++ b/src/geometry/translation_conversion.rs @@ -5,7 +5,7 @@ use simba::simd::PrimitiveSimdValue; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; -use crate::base::{CVectorN, Const, DefaultAllocator, MatrixN, Scalar, VectorN}; +use crate::base::{Const, DefaultAllocator, DimName, OMatrix, OVector, SVector, Scalar}; use crate::geometry::{ AbstractRotation, Isometry, Similarity, SuperTCategoryOf, TAffine, Transform, Translation, @@ -24,205 +24,205 @@ use crate::geometry::{ * Translation -> Matrix (homogeneous) */ -impl SubsetOf> for Translation +impl SubsetOf> for Translation where - N1: Scalar, - N2: Scalar + SupersetOf, + T1: Scalar, + T2: Scalar + SupersetOf, { #[inline] - fn to_superset(&self) -> Translation { + fn to_superset(&self) -> Translation { Translation::from(self.vector.to_superset()) } #[inline] - fn is_in_subset(rot: &Translation) -> bool { - crate::is_convertible::<_, CVectorN>(&rot.vector) + fn is_in_subset(rot: &Translation) -> bool { + crate::is_convertible::<_, SVector>(&rot.vector) } #[inline] - fn from_superset_unchecked(rot: &Translation) -> Self { + fn from_superset_unchecked(rot: &Translation) -> Self { Translation { vector: rot.vector.to_subset_unchecked(), } } } -impl SubsetOf> for Translation +impl SubsetOf> for Translation where - N1: RealField, - N2: RealField + SupersetOf, - R: AbstractRotation, + T1: RealField, + T2: RealField + SupersetOf, + R: AbstractRotation, { #[inline] - fn to_superset(&self) -> Isometry { + fn to_superset(&self) -> Isometry { Isometry::from_parts(self.to_superset(), R::identity()) } #[inline] - fn is_in_subset(iso: &Isometry) -> bool { + fn is_in_subset(iso: &Isometry) -> bool { iso.rotation == R::identity() } #[inline] - fn from_superset_unchecked(iso: &Isometry) -> Self { + fn from_superset_unchecked(iso: &Isometry) -> Self { Self::from_superset_unchecked(&iso.translation) } } -impl SubsetOf> for Translation3 +impl SubsetOf> for Translation3 where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, { #[inline] - fn to_superset(&self) -> UnitDualQuaternion { - let dq = UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()); + fn to_superset(&self) -> UnitDualQuaternion { + let dq = UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()); dq.to_superset() } #[inline] - fn is_in_subset(dq: &UnitDualQuaternion) -> bool { - crate::is_convertible::<_, Translation>(&dq.translation()) + fn is_in_subset(dq: &UnitDualQuaternion) -> bool { + crate::is_convertible::<_, Translation>(&dq.translation()) && dq.rotation() == UnitQuaternion::identity() } #[inline] - fn from_superset_unchecked(dq: &UnitDualQuaternion) -> Self { - let dq: UnitDualQuaternion = crate::convert_ref_unchecked(dq); + fn from_superset_unchecked(dq: &UnitDualQuaternion) -> Self { + let dq: UnitDualQuaternion = crate::convert_ref_unchecked(dq); dq.translation() } } -impl SubsetOf> for Translation +impl SubsetOf> for Translation where - N1: RealField, - N2: RealField + SupersetOf, - R: AbstractRotation, + T1: RealField, + T2: RealField + SupersetOf, + R: AbstractRotation, { #[inline] - fn to_superset(&self) -> Similarity { - Similarity::from_parts(self.to_superset(), R::identity(), N2::one()) + fn to_superset(&self) -> Similarity { + Similarity::from_parts(self.to_superset(), R::identity(), T2::one()) } #[inline] - fn is_in_subset(sim: &Similarity) -> bool { - sim.isometry.rotation == R::identity() && sim.scaling() == N2::one() + fn is_in_subset(sim: &Similarity) -> bool { + sim.isometry.rotation == R::identity() && sim.scaling() == T2::one() } #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { + fn from_superset_unchecked(sim: &Similarity) -> Self { Self::from_superset_unchecked(&sim.isometry.translation) } } -impl SubsetOf> for Translation +impl SubsetOf> for Translation where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, C: SuperTCategoryOf, Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl SubsetOf, U1>>> for Translation +impl + SubsetOf, U1>, DimNameSum, U1>>> for Translation where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, Const: DimNameAdd, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>, DimNameSum, U1>>, - // + Allocator - // + Allocator + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>, DimNameSum, U1>>, + // + Allocator + // + Allocator { #[inline] - fn to_superset(&self) -> MatrixN, U1>> { + fn to_superset(&self) -> OMatrix, U1>, DimNameSum, U1>> { self.to_homogeneous().to_superset() } #[inline] - fn is_in_subset(m: &MatrixN, U1>>) -> bool { - let id = m.fixed_slice::, U1>, Const>(0, 0); + fn is_in_subset(m: &OMatrix, U1>, DimNameSum, U1>>) -> bool { + let id = m.generic_slice((0, 0), (DimNameSum::, U1>::name(), Const::)); // Scalar types agree. - m.iter().all(|e| SupersetOf::::is_in_subset(e)) && + m.iter().all(|e| SupersetOf::::is_in_subset(e)) && // The block part does nothing. - id.is_identity(N2::zero()) && + id.is_identity(T2::zero()) && // The normalization factor is one. - m[(D, D)] == N2::one() + m[(D, D)] == T2::one() } #[inline] - fn from_superset_unchecked(m: &MatrixN, U1>>) -> Self { - let t = m.fixed_slice::, U1>(0, D); + fn from_superset_unchecked( + m: &OMatrix, U1>, DimNameSum, U1>>, + ) -> Self { + let t = m.fixed_slice::(0, D); Self { vector: crate::convert_unchecked(t.into_owned()), } } } -impl From> - for MatrixN, U1>> +impl From> + for OMatrix, U1>, DimNameSum, U1>> where Const: DimNameAdd, DefaultAllocator: - Allocator, U1>, DimNameSum, U1>> + Allocator>, + Allocator, U1>, DimNameSum, U1>> + Allocator>, { #[inline] - fn from(t: Translation) -> Self { + fn from(t: Translation) -> Self { t.to_homogeneous() } } -impl From>> for Translation -// where -// DefaultAllocator: Allocator, -{ +impl From>> for Translation { #[inline] - fn from(vector: VectorN>) -> Self { + fn from(vector: OVector>) -> Self { Translation { vector } } } -impl From<[Translation; 2]> - for Translation +impl From<[Translation; 2]> + for Translation where - N: From<[::Element; 2]>, - N::Element: Scalar, + T: From<[::Element; 2]>, + T::Element: Scalar, { #[inline] - fn from(arr: [Translation; 2]) -> Self { - Self::from(VectorN::from([ + fn from(arr: [Translation; 2]) -> Self { + Self::from(OVector::from([ arr[0].vector.clone(), arr[1].vector.clone(), ])) } } -impl From<[Translation; 4]> - for Translation +impl From<[Translation; 4]> + for Translation where - N: From<[::Element; 4]>, - N::Element: Scalar, + T: From<[::Element; 4]>, + T::Element: Scalar, { #[inline] - fn from(arr: [Translation; 4]) -> Self { - Self::from(VectorN::from([ + fn from(arr: [Translation; 4]) -> Self { + Self::from(OVector::from([ arr[0].vector.clone(), arr[1].vector.clone(), arr[2].vector.clone(), @@ -231,15 +231,15 @@ where } } -impl From<[Translation; 8]> - for Translation +impl From<[Translation; 8]> + for Translation where - N: From<[::Element; 8]>, - N::Element: Scalar, + T: From<[::Element; 8]>, + T::Element: Scalar, { #[inline] - fn from(arr: [Translation; 8]) -> Self { - Self::from(VectorN::from([ + fn from(arr: [Translation; 8]) -> Self { + Self::from(OVector::from([ arr[0].vector.clone(), arr[1].vector.clone(), arr[2].vector.clone(), @@ -252,15 +252,15 @@ where } } -impl From<[Translation; 16]> - for Translation +impl From<[Translation; 16]> + for Translation where - N: From<[::Element; 16]>, - N::Element: Scalar, + T: From<[::Element; 16]>, + T::Element: Scalar, { #[inline] - fn from(arr: [Translation; 16]) -> Self { - Self::from(VectorN::from([ + fn from(arr: [Translation; 16]) -> Self { + Self::from(OVector::from([ arr[0].vector.clone(), arr[1].vector.clone(), arr[2].vector.clone(), diff --git a/src/geometry/translation_coordinates.rs b/src/geometry/translation_coordinates.rs index 28d9bde2..9a9bf44a 100644 --- a/src/geometry/translation_coordinates.rs +++ b/src/geometry/translation_coordinates.rs @@ -14,10 +14,8 @@ use crate::geometry::Translation; macro_rules! deref_impl( ($D: expr, $Target: ident $(, $comps: ident)*) => { - impl Deref for Translation - // where DefaultAllocator: Allocator - { - type Target = $Target; + impl Deref for Translation { + type Target = $Target; #[inline] fn deref(&self) -> &Self::Target { @@ -25,8 +23,7 @@ macro_rules! deref_impl( } } - impl DerefMut for Translation - // where DefaultAllocator: Allocator + impl DerefMut for Translation { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { diff --git a/src/geometry/translation_ops.rs b/src/geometry/translation_ops.rs index 11d18469..5944fdeb 100644 --- a/src/geometry/translation_ops.rs +++ b/src/geometry/translation_ops.rs @@ -13,28 +13,28 @@ use crate::geometry::{Point, Translation}; add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const) const D; for; where; - self: &'a Translation, right: &'b Translation, Output = Translation; + self: &'a Translation, right: &'b Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector + &right.vector) }; 'a, 'b); add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const) const D; for; where; - self: &'a Translation, right: Translation, Output = Translation; + self: &'a Translation, right: Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector + right.vector) }; 'a); add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const) const D; for; where; - self: Translation, right: &'b Translation, Output = Translation; + self: Translation, right: &'b Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector + &right.vector) }; 'b); add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const) const D; for; where; - self: Translation, right: Translation, Output = Translation; + self: Translation, right: Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector + right.vector) }; ); // Translation ÷ Translation @@ -42,28 +42,28 @@ add_sub_impl!(Mul, mul, ClosedAdd; add_sub_impl!(Div, div, ClosedSub; (Const, U1), (Const, U1) -> (Const) const D; for; where; - self: &'a Translation, right: &'b Translation, Output = Translation; + self: &'a Translation, right: &'b Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector - &right.vector) }; 'a, 'b); add_sub_impl!(Div, div, ClosedSub; (Const, U1), (Const, U1) -> (Const) const D; for; where; - self: &'a Translation, right: Translation, Output = Translation; + self: &'a Translation, right: Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector - right.vector) }; 'a); add_sub_impl!(Div, div, ClosedSub; (Const, U1), (Const, U1) -> (Const) const D; for; where; - self: Translation, right: &'b Translation, Output = Translation; + self: Translation, right: &'b Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector - &right.vector) }; 'b); add_sub_impl!(Div, div, ClosedSub; (Const, U1), (Const, U1) -> (Const) const D; for; where; - self: Translation, right: Translation, Output = Translation; + self: Translation, right: Translation, Output = Translation; #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector - right.vector) }; ); // Translation × Point @@ -72,49 +72,49 @@ add_sub_impl!(Div, div, ClosedSub; add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const) const D; for; where; - self: &'a Translation, right: &'b Point, Output = Point; + self: &'a Translation, right: &'b Point, Output = Point; #[allow(clippy::suspicious_arithmetic_impl)] { right + &self.vector }; 'a, 'b); add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const) const D; for; where; - self: &'a Translation, right: Point, Output = Point; + self: &'a Translation, right: Point, Output = Point; #[allow(clippy::suspicious_arithmetic_impl)] { right + &self.vector }; 'a); add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const) const D; for; where; - self: Translation, right: &'b Point, Output = Point; + self: Translation, right: &'b Point, Output = Point; #[allow(clippy::suspicious_arithmetic_impl)] { right + self.vector }; 'b); add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const) const D; for; where; - self: Translation, right: Point, Output = Point; + self: Translation, right: Point, Output = Point; #[allow(clippy::suspicious_arithmetic_impl)] { right + self.vector }; ); // Translation *= Translation add_sub_assign_impl!(MulAssign, mul_assign, ClosedAdd; const D; - self: Translation, right: &'b Translation; + self: Translation, right: &'b Translation; #[allow(clippy::suspicious_op_assign_impl)] { self.vector += &right.vector }; 'b); add_sub_assign_impl!(MulAssign, mul_assign, ClosedAdd; const D; - self: Translation, right: Translation; + self: Translation, right: Translation; #[allow(clippy::suspicious_op_assign_impl)] { self.vector += right.vector }; ); add_sub_assign_impl!(DivAssign, div_assign, ClosedSub; const D; - self: Translation, right: &'b Translation; + self: Translation, right: &'b Translation; #[allow(clippy::suspicious_op_assign_impl)] { self.vector -= &right.vector }; 'b); add_sub_assign_impl!(DivAssign, div_assign, ClosedSub; const D; - self: Translation, right: Translation; + self: Translation, right: Translation; #[allow(clippy::suspicious_op_assign_impl)] { self.vector -= right.vector }; ); diff --git a/src/geometry/translation_simba.rs b/src/geometry/translation_simba.rs index 60d6e53f..7f7f7ebf 100755 --- a/src/geometry/translation_simba.rs +++ b/src/geometry/translation_simba.rs @@ -1,25 +1,25 @@ use simba::simd::SimdValue; -use crate::base::VectorN; +use crate::base::OVector; use crate::Scalar; use crate::geometry::Translation; -impl SimdValue for Translation +impl SimdValue for Translation where - N::Element: Scalar, + T::Element: Scalar, { - type Element = Translation; - type SimdBool = N::SimdBool; + type Element = Translation; + type SimdBool = T::SimdBool; #[inline] fn lanes() -> usize { - N::lanes() + T::lanes() } #[inline] fn splat(val: Self::Element) -> Self { - VectorN::splat(val.vector).into() + OVector::splat(val.vector).into() } #[inline] diff --git a/src/geometry/unit_complex.rs b/src/geometry/unit_complex.rs index 43ef7324..fe2e87ba 100755 --- a/src/geometry/unit_complex.rs +++ b/src/geometry/unit_complex.rs @@ -29,29 +29,29 @@ use std::cmp::{Eq, PartialEq}; /// /// # Conversion /// * [Conversion to a matrix `to_rotation_matrix`, `to_homogeneous`…](#conversion-to-a-matrix) -pub type UnitComplex = Unit>; +pub type UnitComplex = Unit>; -impl PartialEq for UnitComplex { +impl PartialEq for UnitComplex { #[inline] fn eq(&self, rhs: &Self) -> bool { (**self).eq(&**rhs) } } -impl Eq for UnitComplex {} +impl Eq for UnitComplex {} -impl Normed for Complex { - type Norm = N::SimdRealField; +impl Normed for Complex { + type Norm = T::SimdRealField; #[inline] - fn norm(&self) -> N::SimdRealField { + fn norm(&self) -> T::SimdRealField { // We don't use `.norm_sqr()` because it requires // some very strong Num trait requirements. (self.re * self.re + self.im * self.im).simd_sqrt() } #[inline] - fn norm_squared(&self) -> N::SimdRealField { + fn norm_squared(&self) -> T::SimdRealField { // We don't use `.norm_sqr()` because it requires // some very strong Num trait requirements. self.re * self.re + self.im * self.im @@ -71,9 +71,9 @@ impl Normed for Complex { } /// # Angle extraction -impl UnitComplex +impl UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// The rotation angle in `]-pi; pi]` of this unit complex number. /// @@ -84,7 +84,7 @@ where /// assert_eq!(rot.angle(), 1.78); /// ``` #[inline] - pub fn angle(&self) -> N { + pub fn angle(&self) -> T { self.im.simd_atan2(self.re) } @@ -98,7 +98,7 @@ where /// assert_eq!(rot.sin_angle(), angle.sin()); /// ``` #[inline] - pub fn sin_angle(&self) -> N { + pub fn sin_angle(&self) -> T { self.im } @@ -112,7 +112,7 @@ where /// assert_eq!(rot.cos_angle(),angle.cos()); /// ``` #[inline] - pub fn cos_angle(&self) -> N { + pub fn cos_angle(&self) -> T { self.re } @@ -121,7 +121,7 @@ where /// This is generally used in the context of generic programming. Using /// the `.angle()` method instead is more common. #[inline] - pub fn scaled_axis(&self) -> Vector1 { + pub fn scaled_axis(&self) -> Vector1 { Vector1::new(self.angle()) } @@ -131,9 +131,9 @@ where /// the `.angle()` method instead is more common. /// Returns `None` if the angle is zero. #[inline] - pub fn axis_angle(&self) -> Option<(Unit>, N)> + pub fn axis_angle(&self) -> Option<(Unit>, T)> where - N: RealField, + T: RealField, { let ang = self.angle(); @@ -142,7 +142,7 @@ where } else if ang.is_sign_negative() { Some((Unit::new_unchecked(Vector1::x()), -ang)) } else { - Some((Unit::new_unchecked(-Vector1::::x()), ang)) + Some((Unit::new_unchecked(-Vector1::::x()), ang)) } } @@ -157,16 +157,16 @@ where /// assert_relative_eq!(rot1.angle_to(&rot2), 1.6); /// ``` #[inline] - pub fn angle_to(&self, other: &Self) -> N { + pub fn angle_to(&self, other: &Self) -> T { let delta = self.rotation_to(other); delta.angle() } } /// # Conjugation and inversion -impl UnitComplex +impl UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Compute the conjugate of this unit complex number. /// @@ -239,9 +239,9 @@ where } /// # Conversion to a matrix -impl UnitComplex +impl UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Builds the rotation matrix corresponding to this unit complex number. /// @@ -254,7 +254,7 @@ where /// assert_eq!(rot.to_rotation_matrix(), expected); /// ``` #[inline] - pub fn to_rotation_matrix(&self) -> Rotation2 { + pub fn to_rotation_matrix(&self) -> Rotation2 { let r = self.re; let i = self.im; @@ -274,15 +274,15 @@ where /// assert_eq!(rot.to_homogeneous(), expected); /// ``` #[inline] - pub fn to_homogeneous(&self) -> Matrix3 { + pub fn to_homogeneous(&self) -> Matrix3 { self.to_rotation_matrix().to_homogeneous() } } /// # Transformation of a vector or a point -impl UnitComplex +impl UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Rotate the given point by this unit complex number. /// @@ -298,7 +298,7 @@ where /// assert_relative_eq!(transformed_point, Point2::new(-2.0, 1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn transform_point(&self, pt: &Point2) -> Point2 { + pub fn transform_point(&self, pt: &Point2) -> Point2 { self * pt } @@ -316,7 +316,7 @@ where /// assert_relative_eq!(transformed_vector, Vector2::new(-2.0, 1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn transform_vector(&self, v: &Vector2) -> Vector2 { + pub fn transform_vector(&self, v: &Vector2) -> Vector2 { self * v } @@ -332,7 +332,7 @@ where /// assert_relative_eq!(transformed_point, Point2::new(2.0, -1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_point(&self, pt: &Point2) -> Point2 { + pub fn inverse_transform_point(&self, pt: &Point2) -> Point2 { // TODO: would it be useful performancewise not to call inverse explicitly (i-e. implement // the inverse transformation explicitly here) ? self.inverse() * pt @@ -350,7 +350,7 @@ where /// assert_relative_eq!(transformed_vector, Vector2::new(2.0, -1.0), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_vector(&self, v: &Vector2) -> Vector2 { + pub fn inverse_transform_vector(&self, v: &Vector2) -> Vector2 { self.inverse() * v } @@ -366,15 +366,15 @@ where /// assert_relative_eq!(transformed_vector, -Vector2::y_axis(), epsilon = 1.0e-6); /// ``` #[inline] - pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { + pub fn inverse_transform_unit_vector(&self, v: &Unit>) -> Unit> { self.inverse() * v } } /// # Interpolation -impl UnitComplex +impl UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Spherical linear interpolation between two rotations represented as unit complex numbers. /// @@ -392,23 +392,23 @@ where /// assert_relative_eq!(rot.angle(), std::f32::consts::FRAC_PI_2); /// ``` #[inline] - pub fn slerp(&self, other: &Self, t: N) -> Self { - Self::new(self.angle() * (N::one() - t) + other.angle() * t) + pub fn slerp(&self, other: &Self, t: T) -> Self { + Self::new(self.angle() * (T::one() - t) + other.angle() * t) } } -impl fmt::Display for UnitComplex { +impl fmt::Display for UnitComplex { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { write!(f, "UnitComplex angle: {}", self.angle()) } } -impl AbsDiffEq for UnitComplex { - type Epsilon = N; +impl AbsDiffEq for UnitComplex { + type Epsilon = T; #[inline] fn default_epsilon() -> Self::Epsilon { - N::default_epsilon() + T::default_epsilon() } #[inline] @@ -417,10 +417,10 @@ impl AbsDiffEq for UnitComplex { } } -impl RelativeEq for UnitComplex { +impl RelativeEq for UnitComplex { #[inline] fn default_max_relative() -> Self::Epsilon { - N::default_max_relative() + T::default_max_relative() } #[inline] @@ -435,10 +435,10 @@ impl RelativeEq for UnitComplex { } } -impl UlpsEq for UnitComplex { +impl UlpsEq for UnitComplex { #[inline] fn default_max_ulps() -> u32 { - N::default_max_ulps() + T::default_max_ulps() } #[inline] diff --git a/src/geometry/unit_complex_construction.rs b/src/geometry/unit_complex_construction.rs index 9f300f3d..c244883d 100644 --- a/src/geometry/unit_complex_construction.rs +++ b/src/geometry/unit_complex_construction.rs @@ -15,9 +15,9 @@ use simba::scalar::{RealField, SupersetOf}; use simba::simd::SimdRealField; /// # Identity -impl UnitComplex +impl UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// The unit complex number multiplicative identity. /// @@ -32,14 +32,14 @@ where /// ``` #[inline] pub fn identity() -> Self { - Self::new_unchecked(Complex::new(N::one(), N::zero())) + Self::new_unchecked(Complex::new(T::one(), T::zero())) } } /// # Construction from a 2D rotation angle -impl UnitComplex +impl UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Builds the unit complex number corresponding to the rotation with the given angle. /// @@ -54,7 +54,7 @@ where /// assert_relative_eq!(rot * Point2::new(3.0, 4.0), Point2::new(-4.0, 3.0)); /// ``` #[inline] - pub fn new(angle: N) -> Self { + pub fn new(angle: T) -> Self { let (sin, cos) = angle.simd_sin_cos(); Self::from_cos_sin_unchecked(cos, sin) } @@ -75,7 +75,7 @@ where /// ``` // TODO: deprecate this. #[inline] - pub fn from_angle(angle: N) -> Self { + pub fn from_angle(angle: T) -> Self { Self::new(angle) } @@ -96,7 +96,7 @@ where /// assert_relative_eq!(rot * Point2::new(3.0, 4.0), Point2::new(-4.0, 3.0)); /// ``` #[inline] - pub fn from_cos_sin_unchecked(cos: N, sin: N) -> Self { + pub fn from_cos_sin_unchecked(cos: T, sin: T) -> Self { Self::new_unchecked(Complex::new(cos, sin)) } @@ -105,15 +105,15 @@ where /// This is generally used in the context of generic programming. Using /// the `::new(angle)` method instead is more common. #[inline] - pub fn from_scaled_axis>(axisangle: Vector) -> Self { + pub fn from_scaled_axis>(axisangle: Vector) -> Self { Self::from_angle(axisangle[0]) } } /// # Construction from an existing 2D matrix or complex number -impl UnitComplex +impl UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// Cast the components of `self` to another type. /// @@ -145,7 +145,7 @@ where /// assert_eq!(*rot.complex(), Complex::new(angle.cos(), angle.sin())); /// ``` #[inline] - pub fn complex(&self) -> &Complex { + pub fn complex(&self) -> &Complex { self.as_ref() } @@ -153,7 +153,7 @@ where /// /// The input complex number will be normalized. #[inline] - pub fn from_complex(q: Complex) -> Self { + pub fn from_complex(q: Complex) -> Self { Self::from_complex_and_get(q).0 } @@ -161,7 +161,7 @@ where /// /// The input complex number will be normalized. Returns the norm of the complex number as well. #[inline] - pub fn from_complex_and_get(q: Complex) -> (Self, N) { + pub fn from_complex_and_get(q: Complex) -> (Self, T) { let norm = (q.im * q.im + q.re * q.re).simd_sqrt(); (Self::new_unchecked(q / norm), norm) } @@ -177,7 +177,7 @@ where /// ``` // TODO: add UnitComplex::from(...) instead? #[inline] - pub fn from_rotation_matrix(rotmat: &Rotation2) -> Self { + pub fn from_rotation_matrix(rotmat: &Rotation2) -> Self { Self::new_unchecked(Complex::new(rotmat[(0, 0)], rotmat[(1, 0)])) } @@ -187,7 +187,7 @@ where /// orthonormal basis, i.e., all vectors are normalized, and the are /// all orthogonal to each other. These invariants are not checked /// by this method. - pub fn from_basis_unchecked(basis: &[Vector2; 2]) -> Self { + pub fn from_basis_unchecked(basis: &[Vector2; 2]) -> Self { let mat = Matrix2::from_columns(&basis[..]); let rot = Rotation2::from_matrix_unchecked(mat); Self::from_rotation_matrix(&rot) @@ -198,9 +198,9 @@ where /// This is an iterative method. See `.from_matrix_eps` to provide mover /// convergence parameters and starting solution. /// This implements "A Robust Method to Extract the Rotational Part of Deformations" by Müller et al. - pub fn from_matrix(m: &Matrix2) -> Self + pub fn from_matrix(m: &Matrix2) -> Self where - N: RealField, + T: RealField, { Rotation2::from_matrix(m).into() } @@ -217,9 +217,9 @@ where /// * `guess`: an estimate of the solution. Convergence will be significantly faster if an initial solution close /// to the actual solution is provided. Can be set to `UnitQuaternion::identity()` if no other /// guesses come to mind. - pub fn from_matrix_eps(m: &Matrix2, eps: N, max_iter: usize, guess: Self) -> Self + pub fn from_matrix_eps(m: &Matrix2, eps: T, max_iter: usize, guess: Self) -> Self where - N: RealField, + T: RealField, { let guess = Rotation2::from(guess); Rotation2::from_matrix_eps(m, eps, max_iter, guess).into() @@ -259,15 +259,15 @@ where /// assert_relative_eq!(pow.angle(), 2.0 * 0.78); /// ``` #[inline] - pub fn powf(&self, n: N) -> Self { + pub fn powf(&self, n: T) -> Self { Self::from_angle(self.angle() * n) } } /// # Construction from two vectors -impl UnitComplex +impl UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { /// The unit complex needed to make `a` and `b` be collinear and point toward the same /// direction. @@ -283,13 +283,13 @@ where /// assert_relative_eq!(rot.inverse() * b, a); /// ``` #[inline] - pub fn rotation_between(a: &Vector, b: &Vector) -> Self + pub fn rotation_between(a: &Vector, b: &Vector) -> Self where - N: RealField, - SB: Storage, - SC: Storage, + T: RealField, + SB: Storage, + SC: Storage, { - Self::scaled_rotation_between(a, b, N::one()) + Self::scaled_rotation_between(a, b, T::one()) } /// The smallest rotation needed to make `a` and `b` collinear and point toward the same @@ -308,19 +308,19 @@ where /// ``` #[inline] pub fn scaled_rotation_between( - a: &Vector, - b: &Vector, - s: N, + a: &Vector, + b: &Vector, + s: T, ) -> Self where - N: RealField, - SB: Storage, - SC: Storage, + T: RealField, + SB: Storage, + SC: Storage, { // TODO: code duplication with Rotation. if let (Some(na), Some(nb)) = ( - Unit::try_new(a.clone_owned(), N::zero()), - Unit::try_new(b.clone_owned(), N::zero()), + Unit::try_new(a.clone_owned(), T::zero()), + Unit::try_new(b.clone_owned(), T::zero()), ) { Self::scaled_rotation_between_axis(&na, &nb, s) } else { @@ -343,14 +343,14 @@ where /// ``` #[inline] pub fn rotation_between_axis( - a: &Unit>, - b: &Unit>, + a: &Unit>, + b: &Unit>, ) -> Self where - SB: Storage, - SC: Storage, + SB: Storage, + SC: Storage, { - Self::scaled_rotation_between_axis(a, b, N::one()) + Self::scaled_rotation_between_axis(a, b, T::one()) } /// The smallest rotation needed to make `a` and `b` collinear and point toward the same @@ -369,13 +369,13 @@ where /// ``` #[inline] pub fn scaled_rotation_between_axis( - na: &Unit>, - nb: &Unit>, - s: N, + na: &Unit>, + nb: &Unit>, + s: T, ) -> Self where - SB: Storage, - SC: Storage, + SB: Storage, + SC: Storage, { let sang = na.perp(&nb); let cang = na.dot(&nb); @@ -384,9 +384,9 @@ where } } -impl One for UnitComplex +impl One for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] fn one() -> Self { @@ -395,26 +395,26 @@ where } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where - N::Element: SimdRealField, - rand_distr::UnitCircle: Distribution<[N; 2]>, + T::Element: SimdRealField, + rand_distr::UnitCircle: Distribution<[T; 2]>, { /// Generate a uniformly distributed random `UnitComplex`. #[inline] - fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> UnitComplex { + fn sample<'a, R: Rng + ?Sized>(&self, rng: &mut R) -> UnitComplex { let x = rng.sample(rand_distr::UnitCircle); UnitComplex::new_unchecked(Complex::new(x[0], x[1])) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for UnitComplex +impl Arbitrary for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] fn arbitrary(g: &mut Gen) -> Self { - UnitComplex::from_angle(N::arbitrary(g)) + UnitComplex::from_angle(T::arbitrary(g)) } } diff --git a/src/geometry/unit_complex_conversion.rs b/src/geometry/unit_complex_conversion.rs index f2c02b85..04fb41ac 100644 --- a/src/geometry/unit_complex_conversion.rs +++ b/src/geometry/unit_complex_conversion.rs @@ -25,215 +25,215 @@ use crate::geometry::{ * UnitComplex -> Complex is already provided by: Unit -> T */ -impl SubsetOf> for UnitComplex +impl SubsetOf> for UnitComplex where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, { #[inline] - fn to_superset(&self) -> UnitComplex { + fn to_superset(&self) -> UnitComplex { UnitComplex::new_unchecked(self.as_ref().to_superset()) } #[inline] - fn is_in_subset(uq: &UnitComplex) -> bool { - crate::is_convertible::<_, Complex>(uq.as_ref()) + fn is_in_subset(uq: &UnitComplex) -> bool { + crate::is_convertible::<_, Complex>(uq.as_ref()) } #[inline] - fn from_superset_unchecked(uq: &UnitComplex) -> Self { + fn from_superset_unchecked(uq: &UnitComplex) -> Self { Self::new_unchecked(crate::convert_ref_unchecked(uq.as_ref())) } } -impl SubsetOf> for UnitComplex +impl SubsetOf> for UnitComplex where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, { #[inline] - fn to_superset(&self) -> Rotation2 { - let q: UnitComplex = self.to_superset(); + fn to_superset(&self) -> Rotation2 { + let q: UnitComplex = self.to_superset(); q.to_rotation_matrix().to_superset() } #[inline] - fn is_in_subset(rot: &Rotation2) -> bool { - crate::is_convertible::<_, Rotation2>(rot) + fn is_in_subset(rot: &Rotation2) -> bool { + crate::is_convertible::<_, Rotation2>(rot) } #[inline] - fn from_superset_unchecked(rot: &Rotation2) -> Self { - let q = UnitComplex::::from_rotation_matrix(rot); + fn from_superset_unchecked(rot: &Rotation2) -> Self { + let q = UnitComplex::::from_rotation_matrix(rot); crate::convert_unchecked(q) } } -impl SubsetOf> for UnitComplex +impl SubsetOf> for UnitComplex where - N1: RealField, - N2: RealField + SupersetOf, - R: AbstractRotation + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, + R: AbstractRotation + SupersetOf, { #[inline] - fn to_superset(&self) -> Isometry { + fn to_superset(&self) -> Isometry { Isometry::from_parts(Translation::identity(), crate::convert_ref(self)) } #[inline] - fn is_in_subset(iso: &Isometry) -> bool { + fn is_in_subset(iso: &Isometry) -> bool { iso.translation.vector.is_zero() } #[inline] - fn from_superset_unchecked(iso: &Isometry) -> Self { + fn from_superset_unchecked(iso: &Isometry) -> Self { crate::convert_ref_unchecked(&iso.rotation) } } -impl SubsetOf> for UnitComplex +impl SubsetOf> for UnitComplex where - N1: RealField, - N2: RealField + SupersetOf, - R: AbstractRotation + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, + R: AbstractRotation + SupersetOf, { #[inline] - fn to_superset(&self) -> Similarity { - Similarity::from_isometry(crate::convert_ref(self), N2::one()) + fn to_superset(&self) -> Similarity { + Similarity::from_isometry(crate::convert_ref(self), T2::one()) } #[inline] - fn is_in_subset(sim: &Similarity) -> bool { - sim.isometry.translation.vector.is_zero() && sim.scaling() == N2::one() + fn is_in_subset(sim: &Similarity) -> bool { + sim.isometry.translation.vector.is_zero() && sim.scaling() == T2::one() } #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { + fn from_superset_unchecked(sim: &Similarity) -> Self { crate::convert_ref_unchecked(&sim.isometry) } } -impl SubsetOf> for UnitComplex +impl SubsetOf> for UnitComplex where - N1: RealField, - N2: RealField + SupersetOf, + T1: RealField, + T2: RealField + SupersetOf, C: SuperTCategoryOf, { #[inline] - fn to_superset(&self) -> Transform { + fn to_superset(&self) -> Transform { Transform::from_matrix_unchecked(self.to_homogeneous().to_superset()) } #[inline] - fn is_in_subset(t: &Transform) -> bool { + fn is_in_subset(t: &Transform) -> bool { >::is_in_subset(t.matrix()) } #[inline] - fn from_superset_unchecked(t: &Transform) -> Self { + fn from_superset_unchecked(t: &Transform) -> Self { Self::from_superset_unchecked(t.matrix()) } } -impl> SubsetOf> for UnitComplex { +impl> SubsetOf> for UnitComplex { #[inline] - fn to_superset(&self) -> Matrix3 { + fn to_superset(&self) -> Matrix3 { self.to_homogeneous().to_superset() } #[inline] - fn is_in_subset(m: &Matrix3) -> bool { - crate::is_convertible::<_, Rotation2>(m) + fn is_in_subset(m: &Matrix3) -> bool { + crate::is_convertible::<_, Rotation2>(m) } #[inline] - fn from_superset_unchecked(m: &Matrix3) -> Self { - let rot: Rotation2 = crate::convert_ref_unchecked(m); + fn from_superset_unchecked(m: &Matrix3) -> Self { + let rot: Rotation2 = crate::convert_ref_unchecked(m); Self::from_rotation_matrix(&rot) } } -impl From> for Rotation2 +impl From> for Rotation2 where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn from(q: UnitComplex) -> Self { + fn from(q: UnitComplex) -> Self { q.to_rotation_matrix() } } -impl From> for UnitComplex +impl From> for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn from(q: Rotation2) -> Self { + fn from(q: Rotation2) -> Self { Self::from_rotation_matrix(&q) } } -impl From> for Matrix3 +impl From> for Matrix3 where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn from(q: UnitComplex) -> Matrix3 { + fn from(q: UnitComplex) -> Matrix3 { q.to_homogeneous() } } -impl From> for Matrix2 +impl From> for Matrix2 where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn from(q: UnitComplex) -> Self { + fn from(q: UnitComplex) -> Self { q.to_rotation_matrix().into_inner() } } -impl From<[UnitComplex; 2]> for UnitComplex +impl From<[UnitComplex; 2]> for UnitComplex where - N: From<[::Element; 2]>, - N::Element: Scalar + Copy, + T: From<[::Element; 2]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [UnitComplex; 2]) -> Self { + fn from(arr: [UnitComplex; 2]) -> Self { Self::new_unchecked(Complex { - re: N::from([arr[0].re, arr[1].re]), - im: N::from([arr[0].im, arr[1].im]), + re: T::from([arr[0].re, arr[1].re]), + im: T::from([arr[0].im, arr[1].im]), }) } } -impl From<[UnitComplex; 4]> for UnitComplex +impl From<[UnitComplex; 4]> for UnitComplex where - N: From<[::Element; 4]>, - N::Element: Scalar + Copy, + T: From<[::Element; 4]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [UnitComplex; 4]) -> Self { + fn from(arr: [UnitComplex; 4]) -> Self { Self::new_unchecked(Complex { - re: N::from([arr[0].re, arr[1].re, arr[2].re, arr[3].re]), - im: N::from([arr[0].im, arr[1].im, arr[2].im, arr[3].im]), + re: T::from([arr[0].re, arr[1].re, arr[2].re, arr[3].re]), + im: T::from([arr[0].im, arr[1].im, arr[2].im, arr[3].im]), }) } } -impl From<[UnitComplex; 8]> for UnitComplex +impl From<[UnitComplex; 8]> for UnitComplex where - N: From<[::Element; 8]>, - N::Element: Scalar + Copy, + T: From<[::Element; 8]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [UnitComplex; 8]) -> Self { + fn from(arr: [UnitComplex; 8]) -> Self { Self::new_unchecked(Complex { - re: N::from([ + re: T::from([ arr[0].re, arr[1].re, arr[2].re, arr[3].re, arr[4].re, arr[5].re, arr[6].re, arr[7].re, ]), - im: N::from([ + im: T::from([ arr[0].im, arr[1].im, arr[2].im, arr[3].im, arr[4].im, arr[5].im, arr[6].im, arr[7].im, ]), @@ -241,20 +241,20 @@ where } } -impl From<[UnitComplex; 16]> for UnitComplex +impl From<[UnitComplex; 16]> for UnitComplex where - N: From<[::Element; 16]>, - N::Element: Scalar + Copy, + T: From<[::Element; 16]>, + T::Element: Scalar + Copy, { #[inline] - fn from(arr: [UnitComplex; 16]) -> Self { + fn from(arr: [UnitComplex; 16]) -> Self { Self::new_unchecked(Complex { - re: N::from([ + re: T::from([ arr[0].re, arr[1].re, arr[2].re, arr[3].re, arr[4].re, arr[5].re, arr[6].re, arr[7].re, arr[8].re, arr[9].re, arr[10].re, arr[11].re, arr[12].re, arr[13].re, arr[14].re, arr[15].re, ]), - im: N::from([ + im: T::from([ arr[0].im, arr[1].im, arr[2].im, arr[3].im, arr[4].im, arr[5].im, arr[6].im, arr[7].im, arr[8].im, arr[9].im, arr[10].im, arr[11].im, arr[12].im, arr[13].im, arr[14].im, arr[15].im, diff --git a/src/geometry/unit_complex_ops.rs b/src/geometry/unit_complex_ops.rs index 621dd46a..abaa9d4f 100644 --- a/src/geometry/unit_complex_ops.rs +++ b/src/geometry/unit_complex_ops.rs @@ -40,7 +40,7 @@ use simba::simd::SimdRealField; */ // UnitComplex × UnitComplex -impl Mul for UnitComplex { +impl Mul for UnitComplex { type Output = Self; #[inline] @@ -49,46 +49,46 @@ impl Mul for UnitComplex { } } -impl<'a, N: SimdRealField> Mul> for &'a UnitComplex +impl<'a, T: SimdRealField> Mul> for &'a UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { - type Output = UnitComplex; + type Output = UnitComplex; #[inline] - fn mul(self, rhs: UnitComplex) -> Self::Output { + fn mul(self, rhs: UnitComplex) -> Self::Output { Unit::new_unchecked(self.complex() * rhs.into_inner()) } } -impl<'b, N: SimdRealField> Mul<&'b UnitComplex> for UnitComplex +impl<'b, T: SimdRealField> Mul<&'b UnitComplex> for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { type Output = Self; #[inline] - fn mul(self, rhs: &'b UnitComplex) -> Self::Output { + fn mul(self, rhs: &'b UnitComplex) -> Self::Output { Unit::new_unchecked(self.into_inner() * rhs.as_ref()) } } -impl<'a, 'b, N: SimdRealField> Mul<&'b UnitComplex> for &'a UnitComplex +impl<'a, 'b, T: SimdRealField> Mul<&'b UnitComplex> for &'a UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { - type Output = UnitComplex; + type Output = UnitComplex; #[inline] - fn mul(self, rhs: &'b UnitComplex) -> Self::Output { + fn mul(self, rhs: &'b UnitComplex) -> Self::Output { Unit::new_unchecked(self.complex() * rhs.as_ref()) } } // UnitComplex ÷ UnitComplex -impl Div for UnitComplex +impl Div for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { type Output = Self; @@ -99,40 +99,40 @@ where } } -impl<'a, N: SimdRealField> Div> for &'a UnitComplex +impl<'a, T: SimdRealField> Div> for &'a UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { - type Output = UnitComplex; + type Output = UnitComplex; #[inline] - fn div(self, rhs: UnitComplex) -> Self::Output { + fn div(self, rhs: UnitComplex) -> Self::Output { #[allow(clippy::suspicious_arithmetic_impl)] Unit::new_unchecked(self.complex() * rhs.conjugate().into_inner()) } } -impl<'b, N: SimdRealField> Div<&'b UnitComplex> for UnitComplex +impl<'b, T: SimdRealField> Div<&'b UnitComplex> for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { type Output = Self; #[inline] - fn div(self, rhs: &'b UnitComplex) -> Self::Output { + fn div(self, rhs: &'b UnitComplex) -> Self::Output { #[allow(clippy::suspicious_arithmetic_impl)] Unit::new_unchecked(self.into_inner() * rhs.conjugate().into_inner()) } } -impl<'a, 'b, N: SimdRealField> Div<&'b UnitComplex> for &'a UnitComplex +impl<'a, 'b, T: SimdRealField> Div<&'b UnitComplex> for &'a UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { - type Output = UnitComplex; + type Output = UnitComplex; #[inline] - fn div(self, rhs: &'b UnitComplex) -> Self::Output { + fn div(self, rhs: &'b UnitComplex) -> Self::Output { #[allow(clippy::suspicious_arithmetic_impl)] Unit::new_unchecked(self.complex() * rhs.conjugate().into_inner()) } @@ -143,8 +143,8 @@ macro_rules! complex_op_impl( $($Storage: ident: $StoragesBound: ident $(<$($BoundParam: ty),*>)*),*; $lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Result: ty; $action: expr; $($lives: tt),*) => { - impl<$($lives ,)* N: SimdRealField $(, $Storage: $StoragesBound $(<$($BoundParam),*>)*)*> $Op<$Rhs> for $Lhs - where N::Element: SimdRealField { + impl<$($lives ,)* T: SimdRealField $(, $Storage: $StoragesBound $(<$($BoundParam),*>)*)*> $Op<$Rhs> for $Lhs + where T::Element: SimdRealField { type Output = $Result; #[inline] @@ -192,7 +192,7 @@ macro_rules! complex_op_impl_all( complex_op_impl_all!( Mul, mul; ; - self: UnitComplex, rhs: Rotation, Output = UnitComplex; + self: UnitComplex, rhs: Rotation, Output = UnitComplex; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -203,7 +203,7 @@ complex_op_impl_all!( complex_op_impl_all!( Div, div; ; - self: UnitComplex, rhs: Rotation, Output = UnitComplex; + self: UnitComplex, rhs: Rotation, Output = UnitComplex; [val val] => &self / &rhs; [ref val] => self / &rhs; [val ref] => &self / rhs; @@ -214,7 +214,7 @@ complex_op_impl_all!( complex_op_impl_all!( Mul, mul; ; - self: Rotation, rhs: UnitComplex, Output = UnitComplex; + self: Rotation, rhs: UnitComplex, Output = UnitComplex; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -225,7 +225,7 @@ complex_op_impl_all!( complex_op_impl_all!( Div, div; ; - self: Rotation, rhs: UnitComplex, Output = UnitComplex; + self: Rotation, rhs: UnitComplex, Output = UnitComplex; [val val] => &self / &rhs; [ref val] => self / &rhs; [val ref] => &self / rhs; @@ -236,7 +236,7 @@ complex_op_impl_all!( complex_op_impl_all!( Mul, mul; ; - self: UnitComplex, rhs: Point2, Output = Point2; + self: UnitComplex, rhs: Point2, Output = Point2; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -246,8 +246,8 @@ complex_op_impl_all!( // UnitComplex × Vector complex_op_impl_all!( Mul, mul; - S: Storage>; - self: UnitComplex, rhs: Vector, S>, Output = Vector2; + S: Storage>; + self: UnitComplex, rhs: Vector, S>, Output = Vector2; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -261,8 +261,8 @@ complex_op_impl_all!( // UnitComplex × Unit complex_op_impl_all!( Mul, mul; - S: Storage>; - self: UnitComplex, rhs: Unit, S>>, Output = Unit>; + S: Storage>; + self: UnitComplex, rhs: Unit, S>>, Output = Unit>; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -273,8 +273,8 @@ complex_op_impl_all!( complex_op_impl_all!( Mul, mul; ; - self: UnitComplex, rhs: Isometry, 2>, - Output = Isometry, 2>; + self: UnitComplex, rhs: Isometry, 2>, + Output = Isometry, 2>; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -288,8 +288,8 @@ complex_op_impl_all!( complex_op_impl_all!( Mul, mul; ; - self: UnitComplex, rhs: Similarity, 2>, - Output = Similarity, 2>; + self: UnitComplex, rhs: Similarity, 2>, + Output = Similarity, 2>; [val val] => &self * &rhs; [ref val] => self * &rhs; [val ref] => &self * rhs; @@ -300,8 +300,8 @@ complex_op_impl_all!( complex_op_impl_all!( Mul, mul; ; - self: UnitComplex, rhs: Translation, - Output = Isometry, 2>; + self: UnitComplex, rhs: Translation, + Output = Isometry, 2>; [val val] => Isometry::from_parts(Translation::from(&self * rhs.vector), self); [ref val] => Isometry::from_parts(Translation::from( self * rhs.vector), *self); [val ref] => Isometry::from_parts(Translation::from(&self * &rhs.vector), self); @@ -312,8 +312,8 @@ complex_op_impl_all!( complex_op_impl_all!( Mul, mul; ; - self: Translation, right: UnitComplex, - Output = Isometry, 2>; + self: Translation, right: UnitComplex, + Output = Isometry, 2>; [val val] => Isometry::from_parts(self, right); [ref val] => Isometry::from_parts(self.clone(), right); [val ref] => Isometry::from_parts(self, *right); @@ -321,127 +321,127 @@ complex_op_impl_all!( ); // UnitComplex ×= UnitComplex -impl MulAssign> for UnitComplex +impl MulAssign> for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn mul_assign(&mut self, rhs: UnitComplex) { + fn mul_assign(&mut self, rhs: UnitComplex) { *self = &*self * rhs } } -impl<'b, N: SimdRealField> MulAssign<&'b UnitComplex> for UnitComplex +impl<'b, T: SimdRealField> MulAssign<&'b UnitComplex> for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn mul_assign(&mut self, rhs: &'b UnitComplex) { + fn mul_assign(&mut self, rhs: &'b UnitComplex) { *self = &*self * rhs } } // UnitComplex /= UnitComplex -impl DivAssign> for UnitComplex +impl DivAssign> for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn div_assign(&mut self, rhs: UnitComplex) { + fn div_assign(&mut self, rhs: UnitComplex) { *self = &*self / rhs } } -impl<'b, N: SimdRealField> DivAssign<&'b UnitComplex> for UnitComplex +impl<'b, T: SimdRealField> DivAssign<&'b UnitComplex> for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn div_assign(&mut self, rhs: &'b UnitComplex) { + fn div_assign(&mut self, rhs: &'b UnitComplex) { *self = &*self / rhs } } // UnitComplex ×= Rotation -impl MulAssign> for UnitComplex +impl MulAssign> for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn mul_assign(&mut self, rhs: Rotation) { + fn mul_assign(&mut self, rhs: Rotation) { *self = &*self * rhs } } -impl<'b, N: SimdRealField> MulAssign<&'b Rotation> for UnitComplex +impl<'b, T: SimdRealField> MulAssign<&'b Rotation> for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn mul_assign(&mut self, rhs: &'b Rotation) { + fn mul_assign(&mut self, rhs: &'b Rotation) { *self = &*self * rhs } } // UnitComplex ÷= Rotation -impl DivAssign> for UnitComplex +impl DivAssign> for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn div_assign(&mut self, rhs: Rotation) { + fn div_assign(&mut self, rhs: Rotation) { *self = &*self / rhs } } -impl<'b, N: SimdRealField> DivAssign<&'b Rotation> for UnitComplex +impl<'b, T: SimdRealField> DivAssign<&'b Rotation> for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn div_assign(&mut self, rhs: &'b Rotation) { + fn div_assign(&mut self, rhs: &'b Rotation) { *self = &*self / rhs } } // Rotation ×= UnitComplex -impl MulAssign> for Rotation +impl MulAssign> for Rotation where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn mul_assign(&mut self, rhs: UnitComplex) { + fn mul_assign(&mut self, rhs: UnitComplex) { self.mul_assign(rhs.to_rotation_matrix()) } } -impl<'b, N: SimdRealField> MulAssign<&'b UnitComplex> for Rotation +impl<'b, T: SimdRealField> MulAssign<&'b UnitComplex> for Rotation where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn mul_assign(&mut self, rhs: &'b UnitComplex) { + fn mul_assign(&mut self, rhs: &'b UnitComplex) { self.mul_assign(rhs.to_rotation_matrix()) } } // Rotation ÷= UnitComplex -impl DivAssign> for Rotation +impl DivAssign> for Rotation where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn div_assign(&mut self, rhs: UnitComplex) { + fn div_assign(&mut self, rhs: UnitComplex) { self.div_assign(rhs.to_rotation_matrix()) } } -impl<'b, N: SimdRealField> DivAssign<&'b UnitComplex> for Rotation +impl<'b, T: SimdRealField> DivAssign<&'b UnitComplex> for Rotation where - N::Element: SimdRealField, + T::Element: SimdRealField, { #[inline] - fn div_assign(&mut self, rhs: &'b UnitComplex) { + fn div_assign(&mut self, rhs: &'b UnitComplex) { self.div_assign(rhs.to_rotation_matrix()) } } diff --git a/src/geometry/unit_complex_simba.rs b/src/geometry/unit_complex_simba.rs index 5e8bfa78..156cd63a 100755 --- a/src/geometry/unit_complex_simba.rs +++ b/src/geometry/unit_complex_simba.rs @@ -6,16 +6,16 @@ use crate::base::Unit; use crate::geometry::UnitComplex; use crate::SimdRealField; -impl SimdValue for UnitComplex +impl SimdValue for UnitComplex where - N::Element: SimdRealField, + T::Element: SimdRealField, { - type Element = UnitComplex; - type SimdBool = N::SimdBool; + type Element = UnitComplex; + type SimdBool = T::SimdBool; #[inline] fn lanes() -> usize { - N::lanes() + T::lanes() } #[inline] diff --git a/src/io/matrix_market.rs b/src/io/matrix_market.rs index 9df66661..2b0a0182 100644 --- a/src/io/matrix_market.rs +++ b/src/io/matrix_market.rs @@ -11,21 +11,21 @@ struct MatrixMarketParser; // TODO: return an Error instead of an Option. /// Parses a Matrix Market file at the given path, and returns the corresponding sparse matrix. -pub fn cs_matrix_from_matrix_market>(path: P) -> Option> { +pub fn cs_matrix_from_matrix_market>(path: P) -> Option> { let file = fs::read_to_string(path).ok()?; cs_matrix_from_matrix_market_str(&file) } // TODO: return an Error instead of an Option. /// Parses a Matrix Market file described by the given string, and returns the corresponding sparse matrix. -pub fn cs_matrix_from_matrix_market_str(data: &str) -> Option> { +pub fn cs_matrix_from_matrix_market_str(data: &str) -> Option> { let file = MatrixMarketParser::parse(Rule::Document, data) .unwrap() .next()?; let mut shape = (0, 0, 0); let mut rows: Vec = Vec::new(); let mut cols: Vec = Vec::new(); - let mut data: Vec = Vec::new(); + let mut data: Vec = Vec::new(); for line in file.into_inner() { match line.as_rule() { diff --git a/src/lib.rs b/src/lib.rs index a64182be..c593d0a2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -253,10 +253,10 @@ pub fn abs(a: &T) -> T { /// Returns the infimum of `a` and `b`. #[deprecated(note = "use the inherent method `Matrix::inf` instead")] #[inline] -pub fn inf(a: &MatrixMN, b: &MatrixMN) -> MatrixMN +pub fn inf(a: &OMatrix, b: &OMatrix) -> OMatrix where - N: Scalar + SimdPartialOrd, - DefaultAllocator: Allocator, + T: Scalar + SimdPartialOrd, + DefaultAllocator: Allocator, { a.inf(b) } @@ -264,10 +264,10 @@ where /// Returns the supremum of `a` and `b`. #[deprecated(note = "use the inherent method `Matrix::sup` instead")] #[inline] -pub fn sup(a: &MatrixMN, b: &MatrixMN) -> MatrixMN +pub fn sup(a: &OMatrix, b: &OMatrix) -> OMatrix where - N: Scalar + SimdPartialOrd, - DefaultAllocator: Allocator, + T: Scalar + SimdPartialOrd, + DefaultAllocator: Allocator, { a.sup(b) } @@ -275,13 +275,13 @@ where /// Returns simultaneously the infimum and supremum of `a` and `b`. #[deprecated(note = "use the inherent method `Matrix::inf_sup` instead")] #[inline] -pub fn inf_sup( - a: &MatrixMN, - b: &MatrixMN, -) -> (MatrixMN, MatrixMN) +pub fn inf_sup( + a: &OMatrix, + b: &OMatrix, +) -> (OMatrix, OMatrix) where - N: Scalar + SimdPartialOrd, - DefaultAllocator: Allocator, + T: Scalar + SimdPartialOrd, + DefaultAllocator: Allocator, { a.inf_sup(b) } @@ -384,14 +384,11 @@ pub fn partial_sort2<'a, T: PartialOrd>(a: &'a T, b: &'a T) -> Option<(&'a T, &' /// * [distance](fn.distance.html) /// * [distance_squared](fn.distance_squared.html) #[inline] -pub fn center( - p1: &Point, - p2: &Point, -) -> Point -// where -// DefaultAllocator: Allocator, -{ - ((&p1.coords + &p2.coords) * convert::<_, N>(0.5)).into() +pub fn center( + p1: &Point, + p2: &Point, +) -> Point { + ((&p1.coords + &p2.coords) * convert::<_, T>(0.5)).into() } /// The distance between two points. @@ -401,13 +398,10 @@ pub fn center( /// * [center](fn.center.html) /// * [distance_squared](fn.distance_squared.html) #[inline] -pub fn distance( - p1: &Point, - p2: &Point, -) -> N::SimdRealField -// where -// DefaultAllocator: Allocator, -{ +pub fn distance( + p1: &Point, + p2: &Point, +) -> T::SimdRealField { (&p2.coords - &p1.coords).norm() } @@ -418,13 +412,10 @@ pub fn distance( /// * [center](fn.center.html) /// * [distance](fn.distance.html) #[inline] -pub fn distance_squared( - p1: &Point, - p2: &Point, -) -> N::SimdRealField -// where -// DefaultAllocator: Allocator, -{ +pub fn distance_squared( + p1: &Point, + p2: &Point, +) -> T::SimdRealField { (&p2.coords - &p1.coords).norm_squared() } diff --git a/src/linalg/balancing.rs b/src/linalg/balancing.rs index 0995819c..3b834563 100644 --- a/src/linalg/balancing.rs +++ b/src/linalg/balancing.rs @@ -6,21 +6,21 @@ use std::ops::{DivAssign, MulAssign}; use crate::allocator::Allocator; use crate::base::dimension::Dim; use crate::base::storage::Storage; -use crate::base::{Const, DefaultAllocator, MatrixN, VectorN}; +use crate::base::{Const, DefaultAllocator, OMatrix, OVector}; /// Applies in-place a modified Parlett and Reinsch matrix balancing with 2-norm to the matrix `m` and returns /// the corresponding diagonal transformation. /// /// See https://arxiv.org/pdf/1401.5766.pdf -pub fn balance_parlett_reinsch(m: &mut MatrixN) -> VectorN +pub fn balance_parlett_reinsch(m: &mut OMatrix) -> OVector where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { assert!(m.is_square(), "Unable to balance a non-square matrix."); let dim = m.data.shape().0; - let radix: N = crate::convert(2.0f64); - let mut d = VectorN::from_element_generic(dim, Const::<1>, N::one()); + let radix: T = crate::convert(2.0f64); + let mut d = OVector::from_element_generic(dim, Const::<1>, T::one()); let mut converged = false; @@ -30,7 +30,7 @@ where for i in 0..dim.value() { let mut c = m.column(i).norm_squared(); let mut r = m.row(i).norm_squared(); - let mut f = N::one(); + let mut f = T::one(); let s = c + r; c = c.sqrt(); @@ -52,7 +52,7 @@ where f /= radix; } - let eps: N = crate::convert(0.95); + let eps: T = crate::convert(0.95); if c * c + r * r < eps * s { converged = false; d[i] *= f; @@ -66,16 +66,16 @@ where } /// Computes in-place `D * m * D.inverse()`, where `D` is the matrix with diagonal `d`. -pub fn unbalance(m: &mut MatrixN, d: &VectorN) +pub fn unbalance(m: &mut OMatrix, d: &OVector) where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { assert!(m.is_square(), "Unable to unbalance a non-square matrix."); assert_eq!(m.nrows(), d.len(), "Unbalancing: mismatched dimensions."); for j in 0..d.len() { let mut col = m.column_mut(j); - let denom = N::one() / d[j]; + let denom = T::one() / d[j]; for i in 0..d.len() { col[i] *= d[i] * denom; diff --git a/src/linalg/bidiagonal.rs b/src/linalg/bidiagonal.rs index 8f846104..c7c36702 100644 --- a/src/linalg/bidiagonal.rs +++ b/src/linalg/bidiagonal.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::allocator::Allocator; -use crate::base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Unit, VectorN}; +use crate::base::{DefaultAllocator, Matrix, OMatrix, OVector, Unit}; use crate::dimension::{Const, Dim, DimDiff, DimMin, DimMinimum, DimSub, U1}; use crate::storage::Storage; use simba::scalar::ComplexField; @@ -15,64 +15,64 @@ use crate::linalg::householder; #[cfg_attr( feature = "serde-serialize", serde(bound(serialize = "DimMinimum: DimSub, - DefaultAllocator: Allocator + - Allocator> + - Allocator, U1>>, - MatrixMN: Serialize, - VectorN>: Serialize, - VectorN, U1>>: Serialize")) + DefaultAllocator: Allocator + + Allocator> + + Allocator, U1>>, + OMatrix: Serialize, + OVector>: Serialize, + OVector, U1>>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", serde(bound(deserialize = "DimMinimum: DimSub, - DefaultAllocator: Allocator + - Allocator> + - Allocator, U1>>, - MatrixMN: Deserialize<'de>, - VectorN>: Deserialize<'de>, - VectorN, U1>>: Deserialize<'de>")) + DefaultAllocator: Allocator + + Allocator> + + Allocator, U1>>, + OMatrix: Deserialize<'de>, + OVector>: Deserialize<'de>, + OVector, U1>>: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct Bidiagonal, C: Dim> +pub struct Bidiagonal, C: Dim> where DimMinimum: DimSub, - DefaultAllocator: Allocator - + Allocator> - + Allocator, U1>>, + DefaultAllocator: Allocator + + Allocator> + + Allocator, U1>>, { // TODO: perhaps we should pack the axes into different vectors so that axes for `v_t` are // contiguous. This prevents some useless copies. - uv: MatrixMN, + uv: OMatrix, /// The diagonal elements of the decomposed matrix. - diagonal: VectorN>, + diagonal: OVector>, /// The off-diagonal elements of the decomposed matrix. - off_diagonal: VectorN, U1>>, + off_diagonal: OVector, U1>>, upper_diagonal: bool, } -impl, C: Dim> Copy for Bidiagonal +impl, C: Dim> Copy for Bidiagonal where DimMinimum: DimSub, - DefaultAllocator: Allocator - + Allocator> - + Allocator, U1>>, - MatrixMN: Copy, - VectorN>: Copy, - VectorN, U1>>: Copy, + DefaultAllocator: Allocator + + Allocator> + + Allocator, U1>>, + OMatrix: Copy, + OVector>: Copy, + OVector, U1>>: Copy, { } -impl, C: Dim> Bidiagonal +impl, C: Dim> Bidiagonal where DimMinimum: DimSub, - DefaultAllocator: Allocator - + Allocator - + Allocator - + Allocator> - + Allocator, U1>>, + DefaultAllocator: Allocator + + Allocator + + Allocator + + Allocator> + + Allocator, U1>>, { /// Computes the Bidiagonal decomposition using householder reflections. - pub fn new(mut matrix: MatrixMN) -> Self { + pub fn new(mut matrix: OMatrix) -> Self { let (nrows, ncols) = matrix.data.shape(); let min_nrows_ncols = nrows.min(ncols); let dim = min_nrows_ncols.value(); @@ -83,9 +83,14 @@ where let mut diagonal = unsafe { crate::unimplemented_or_uninitialized_generic!(min_nrows_ncols, Const::<1>) }; - let mut off_diagonal = - unsafe { crate::unimplemented_or_uninitialized_generic!(min_nrows_ncols.sub(Const::<1>), Const::<1>) }; - let mut axis_packed = unsafe { crate::unimplemented_or_uninitialized_generic!(ncols, Const::<1>) }; + let mut off_diagonal = unsafe { + crate::unimplemented_or_uninitialized_generic!( + min_nrows_ncols.sub(Const::<1>), + Const::<1> + ) + }; + let mut axis_packed = + unsafe { crate::unimplemented_or_uninitialized_generic!(ncols, Const::<1>) }; let mut work = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, Const::<1>) }; let upper_diagonal = nrows.value() >= ncols.value(); @@ -168,14 +173,14 @@ where pub fn unpack( self, ) -> ( - MatrixMN>, - MatrixN>, - MatrixMN, C>, + OMatrix>, + OMatrix, DimMinimum>, + OMatrix, C>, ) where - DefaultAllocator: Allocator, DimMinimum> - + Allocator> - + Allocator, C>, + DefaultAllocator: Allocator, DimMinimum> + + Allocator> + + Allocator, C>, { // TODO: optimize by calling a reallocator. (self.u(), self.d(), self.v_t()) @@ -183,28 +188,28 @@ where /// Retrieves the upper trapezoidal submatrix `R` of this decomposition. #[inline] - pub fn d(&self) -> MatrixN> + pub fn d(&self) -> OMatrix, DimMinimum> where - DefaultAllocator: Allocator, DimMinimum>, + DefaultAllocator: Allocator, DimMinimum>, { let (nrows, ncols) = self.uv.data.shape(); let d = nrows.min(ncols); - let mut res = MatrixN::identity_generic(d, d); - res.set_partial_diagonal(self.diagonal.iter().map(|e| N::from_real(e.modulus()))); + let mut res = OMatrix::identity_generic(d, d); + res.set_partial_diagonal(self.diagonal.iter().map(|e| T::from_real(e.modulus()))); let start = self.axis_shift(); res.slice_mut(start, (d.value() - 1, d.value() - 1)) - .set_partial_diagonal(self.off_diagonal.iter().map(|e| N::from_real(e.modulus()))); + .set_partial_diagonal(self.off_diagonal.iter().map(|e| T::from_real(e.modulus()))); res } /// Computes the orthogonal matrix `U` of this `U * D * V` decomposition. // TODO: code duplication with householder::assemble_q. // Except that we are returning a rectangular matrix here. - pub fn u(&self) -> MatrixMN> + pub fn u(&self) -> OMatrix> where - DefaultAllocator: Allocator>, + DefaultAllocator: Allocator>, { let (nrows, ncols) = self.uv.data.shape(); @@ -215,7 +220,7 @@ where for i in (0..dim - shift).rev() { let axis = self.uv.slice_range(i + shift.., i); // TODO: sometimes, the axis might have a zero magnitude. - let refl = Reflection::new(Unit::new_unchecked(axis), N::zero()); + let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let mut res_rows = res.slice_range_mut(i + shift.., i..); @@ -232,9 +237,9 @@ where } /// Computes the orthogonal matrix `V_t` of this `U * D * V_t` decomposition. - pub fn v_t(&self) -> MatrixMN, C> + pub fn v_t(&self) -> OMatrix, C> where - DefaultAllocator: Allocator, C>, + DefaultAllocator: Allocator, C>, { let (nrows, ncols) = self.uv.data.shape(); let min_nrows_ncols = nrows.min(ncols); @@ -242,7 +247,8 @@ where let mut res = Matrix::identity_generic(min_nrows_ncols, ncols); let mut work = unsafe { crate::unimplemented_or_uninitialized_generic!(min_nrows_ncols, Const::<1>) }; - let mut axis_packed = unsafe { crate::unimplemented_or_uninitialized_generic!(ncols, Const::<1>) }; + let mut axis_packed = + unsafe { crate::unimplemented_or_uninitialized_generic!(ncols, Const::<1>) }; let shift = self.axis_shift().1; @@ -251,7 +257,7 @@ where let mut axis_packed = axis_packed.rows_range_mut(i + shift..); axis_packed.tr_copy_from(&axis); // TODO: sometimes, the axis might have a zero magnitude. - let refl = Reflection::new(Unit::new_unchecked(axis_packed), N::zero()); + let refl = Reflection::new(Unit::new_unchecked(axis_packed), T::zero()); let mut res_rows = res.slice_range_mut(i.., i + shift..); @@ -268,43 +274,42 @@ where } /// The diagonal part of this decomposed matrix. - pub fn diagonal(&self) -> VectorN> + pub fn diagonal(&self) -> OVector> where - DefaultAllocator: Allocator>, + DefaultAllocator: Allocator>, { self.diagonal.map(|e| e.modulus()) } /// The off-diagonal part of this decomposed matrix. - pub fn off_diagonal(&self) -> VectorN, U1>> + pub fn off_diagonal(&self) -> OVector, U1>> where - DefaultAllocator: Allocator, U1>>, + DefaultAllocator: Allocator, U1>>, { self.off_diagonal.map(|e| e.modulus()) } #[doc(hidden)] - pub fn uv_internal(&self) -> &MatrixMN { + pub fn uv_internal(&self) -> &OMatrix { &self.uv } } -// impl + DimSub> Bidiagonal -// where DefaultAllocator: Allocator + -// Allocator { +// impl + DimSub> Bidiagonal +// where DefaultAllocator: Allocator + +// Allocator { // /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. -// pub fn solve(&self, b: &Matrix) -> MatrixMN -// where S2: StorageMut, -// ShapeConstraint: SameNumberOfRows, -// DefaultAllocator: Allocator { +// pub fn solve(&self, b: &Matrix) -> OMatrix +// where S2: StorageMut, +// ShapeConstraint: SameNumberOfRows { // let mut res = b.clone_owned(); // self.solve_mut(&mut res); // res // } // // /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. -// pub fn solve_mut(&self, b: &mut Matrix) -// where S2: StorageMut, +// pub fn solve_mut(&self, b: &mut Matrix) +// where S2: StorageMut, // ShapeConstraint: SameNumberOfRows { // // assert_eq!(self.uv.nrows(), b.nrows(), "Bidiagonal solve matrix dimension mismatch."); @@ -315,8 +320,8 @@ where // } // // // TODO: duplicate code from the `solve` module. -// fn solve_upper_triangular_mut(&self, b: &mut Matrix) -// where S2: StorageMut, +// fn solve_upper_triangular_mut(&self, b: &mut Matrix) +// where S2: StorageMut, // ShapeConstraint: SameNumberOfRows { // // let dim = self.uv.nrows(); @@ -332,28 +337,28 @@ where // *b.vget_unchecked_mut(i) = coeff; // } // -// b.rows_range_mut(.. i).axpy(-coeff, &self.uv.slice_range(.. i, i), N::one()); +// b.rows_range_mut(.. i).axpy(-coeff, &self.uv.slice_range(.. i, i), T::one()); // } // } // } // // /// Computes the inverse of the decomposed matrix. -// pub fn inverse(&self) -> MatrixN { +// pub fn inverse(&self) -> OMatrix { // assert!(self.uv.is_square(), "Bidiagonal inverse: unable to compute the inverse of a non-square matrix."); // // // TODO: is there a less naive method ? // let (nrows, ncols) = self.uv.data.shape(); -// let mut res = MatrixN::identity_generic(nrows, ncols); +// let mut res = OMatrix::identity_generic(nrows, ncols); // self.solve_mut(&mut res); // res // } // // // /// Computes the determinant of the decomposed matrix. -// // pub fn determinant(&self) -> N { +// // pub fn determinant(&self) -> T { // // let dim = self.uv.nrows(); // // assert!(self.uv.is_square(), "Bidiagonal determinant: unable to compute the determinant of a non-square matrix."); // -// // let mut res = N::one(); +// // let mut res = T::one(); // // for i in 0 .. dim { // // res *= unsafe { *self.diag.vget_unchecked(i) }; // // } diff --git a/src/linalg/cholesky.rs b/src/linalg/cholesky.rs index b6e5d78c..312fd6cd 100644 --- a/src/linalg/cholesky.rs +++ b/src/linalg/cholesky.rs @@ -6,7 +6,7 @@ use simba::scalar::ComplexField; use simba::simd::SimdComplexField; use crate::allocator::Allocator; -use crate::base::{Const, DefaultAllocator, Matrix, MatrixMN, MatrixN, Vector}; +use crate::base::{Const, DefaultAllocator, Matrix, OMatrix, Vector}; use crate::constraint::{SameNumberOfRows, ShapeConstraint}; use crate::dimension::{Dim, DimAdd, DimDiff, DimSub, DimSum, U1}; use crate::storage::{Storage, StorageMut}; @@ -15,37 +15,37 @@ use crate::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, + OMatrix: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator, - MatrixN: Deserialize<'de>")) + serde(bound(deserialize = "DefaultAllocator: Allocator, + OMatrix: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct Cholesky +pub struct Cholesky where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - chol: MatrixN, + chol: OMatrix, } -impl Copy for Cholesky +impl Copy for Cholesky where - DefaultAllocator: Allocator, - MatrixN: Copy, + DefaultAllocator: Allocator, + OMatrix: Copy, { } -impl Cholesky +impl Cholesky where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { /// Computes the Cholesky decomposition of `matrix` without checking that the matrix is definite-positive. /// /// If the input matrix is not definite-positive, the decomposition may contain trash values (Inf, NaN, etc.) - pub fn new_unchecked(mut matrix: MatrixN) -> Self { + pub fn new_unchecked(mut matrix: OMatrix) -> Self { assert!(matrix.is_square(), "The input matrix must be square."); let n = matrix.nrows(); @@ -57,7 +57,7 @@ where let (mut col_j, col_k) = matrix.columns_range_pair_mut(j, k); let mut col_j = col_j.rows_range_mut(j..); let col_k = col_k.rows_range(j..); - col_j.axpy(factor.simd_conjugate(), &col_k, N::one()); + col_j.axpy(factor.simd_conjugate(), &col_k, T::one()); } let diag = unsafe { *matrix.get_unchecked((j, j)) }; @@ -76,8 +76,8 @@ where /// Retrieves the lower-triangular factor of the Cholesky decomposition with its strictly /// upper-triangular part filled with zeros. - pub fn unpack(mut self) -> MatrixN { - self.chol.fill_upper_triangle(N::zero(), 1); + pub fn unpack(mut self) -> OMatrix { + self.chol.fill_upper_triangle(T::zero(), 1); self.chol } @@ -86,13 +86,13 @@ where /// /// The values of the strict upper-triangular part are garbage and should be ignored by further /// computations. - pub fn unpack_dirty(self) -> MatrixN { + pub fn unpack_dirty(self) -> OMatrix { self.chol } /// Retrieves the lower-triangular factor of the Cholesky decomposition with its strictly /// uppen-triangular part filled with zeros. - pub fn l(&self) -> MatrixN { + pub fn l(&self) -> OMatrix { self.chol.lower_triangle() } @@ -101,16 +101,16 @@ where /// /// This is an allocation-less version of `self.l()`. The values of the strict upper-triangular /// part are garbage and should be ignored by further computations. - pub fn l_dirty(&self) -> &MatrixN { + pub fn l_dirty(&self) -> &OMatrix { &self.chol } /// Solves the system `self * x = b` where `self` is the decomposed matrix and `x` the unknown. /// /// The result is stored on `b`. - pub fn solve_mut(&self, b: &mut Matrix) + pub fn solve_mut(&self, b: &mut Matrix) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { self.chol.solve_lower_triangular_unchecked_mut(b); @@ -119,10 +119,10 @@ where /// Returns the solution of the system `self * x = b` where `self` is the decomposed matrix and /// `x` the unknown. - pub fn solve(&self, b: &Matrix) -> MatrixMN + pub fn solve(&self, b: &Matrix) -> OMatrix where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -131,9 +131,9 @@ where } /// Computes the inverse of the decomposed matrix. - pub fn inverse(&self) -> MatrixN { + pub fn inverse(&self) -> OMatrix { let shape = self.chol.data.shape(); - let mut res = MatrixN::identity_generic(shape.0, shape.1); + let mut res = OMatrix::identity_generic(shape.0, shape.1); self.solve_mut(&mut res); res @@ -150,15 +150,15 @@ where } } -impl Cholesky +impl Cholesky where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { /// Attempts to compute the Cholesky decomposition of `matrix`. /// /// Returns `None` if the input matrix is not definite-positive. The input matrix is assumed /// to be symmetric and only the lower-triangular part is read. - pub fn new(mut matrix: MatrixN) -> Option { + pub fn new(mut matrix: OMatrix) -> Option { assert!(matrix.is_square(), "The input matrix must be square."); let n = matrix.nrows(); @@ -171,7 +171,7 @@ where let mut col_j = col_j.rows_range_mut(j..); let col_k = col_k.rows_range(j..); - col_j.axpy(factor.conjugate(), &col_k, N::one()); + col_j.axpy(factor.conjugate(), &col_k, T::one()); } let diag = unsafe { *matrix.get_unchecked((j, j)) }; @@ -198,10 +198,10 @@ where /// Given the Cholesky decomposition of a matrix `M`, a scalar `sigma` and a vector `v`, /// performs a rank one update such that we end up with the decomposition of `M + sigma * (v * v.adjoint())`. #[inline] - pub fn rank_one_update(&mut self, x: &Vector, sigma: N::RealField) + pub fn rank_one_update(&mut self, x: &Vector, sigma: T::RealField) where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { Self::xx_rank_one_update(&mut self.chol, &mut x.clone_owned(), sigma) @@ -212,13 +212,13 @@ where pub fn insert_column( &self, j: usize, - col: Vector, - ) -> Cholesky> + col: Vector, + ) -> Cholesky> where D: DimAdd, R2: Dim, - S2: Storage, - DefaultAllocator: Allocator, DimSum> + Allocator, + S2: Storage, + DefaultAllocator: Allocator, DimSum> + Allocator, ShapeConstraint: SameNumberOfRows>, { let mut col = col.into_owned(); @@ -260,17 +260,17 @@ where new_rowj_adjoint.adjoint_to(&mut chol.slice_range_mut(j, ..j)); // update the center element - let center_element = N::sqrt(col_j - N::from_real(new_rowj_adjoint.norm_squared())); + let center_element = T::sqrt(col_j - T::from_real(new_rowj_adjoint.norm_squared())); chol[(j, j)] = center_element; // update the jth column let bottom_left_corner = self.chol.slice_range(j.., ..j); // new_colj = (col_jplus - bottom_left_corner * new_rowj.adjoint()) / center_element; new_colj.gemm( - -N::one() / center_element, + -T::one() / center_element, &bottom_left_corner, &new_rowj_adjoint, - N::one() / center_element, + T::one() / center_element, ); chol.slice_range_mut(j + 1.., j).copy_from(&new_colj); @@ -279,7 +279,7 @@ where Self::xx_rank_one_update( &mut bottom_right_corner, &mut new_colj, - -N::RealField::one(), + -T::RealField::one(), ); Cholesky { chol } @@ -287,10 +287,10 @@ where /// Updates the decomposition such that we get the decomposition of the factored matrix with its `j`th column removed. /// Since the matrix is square, the `j`th row will also be removed. - pub fn remove_column(&self, j: usize) -> Cholesky> + pub fn remove_column(&self, j: usize) -> Cholesky> where D: DimSub, - DefaultAllocator: Allocator, DimDiff> + Allocator, + DefaultAllocator: Allocator, DimDiff> + Allocator, { let n = self.chol.nrows(); assert!(n > 0, "The matrix needs at least one column."); @@ -316,7 +316,7 @@ where let mut bottom_right_corner = chol.slice_range_mut(j.., j..); let mut workspace = self.chol.column(j).clone_owned(); let mut old_colj = workspace.rows_range_mut(j + 1..); - Self::xx_rank_one_update(&mut bottom_right_corner, &mut old_colj, N::RealField::one()); + Self::xx_rank_one_update(&mut bottom_right_corner, &mut old_colj, T::RealField::one()); Cholesky { chol } } @@ -327,15 +327,15 @@ where /// This helper method is called by `rank_one_update` but also `insert_column` and `remove_column` /// where it is used on a square slice of the decomposition fn xx_rank_one_update( - chol: &mut Matrix, - x: &mut Vector, - sigma: N::RealField, + chol: &mut Matrix, + x: &mut Vector, + sigma: T::RealField, ) where - //N: ComplexField, + //T: ComplexField, Dm: Dim, Rx: Dim, - Sm: StorageMut, - Sx: StorageMut, + Sm: StorageMut, + Sx: StorageMut, { // heavily inspired by Eigen's `llt_rank_update_lower` implementation https://eigen.tuxfamily.org/dox/LLT_8h_source.html let n = x.nrows(); @@ -345,29 +345,29 @@ where "The input vector must be of the same size as the factorized matrix." ); - let mut beta = crate::one::(); + let mut beta = crate::one::(); for j in 0..n { // updates the diagonal - let diag = N::real(unsafe { *chol.get_unchecked((j, j)) }); + let diag = T::real(unsafe { *chol.get_unchecked((j, j)) }); let diag2 = diag * diag; let xj = unsafe { *x.get_unchecked(j) }; - let sigma_xj2 = sigma * N::modulus_squared(xj); + let sigma_xj2 = sigma * T::modulus_squared(xj); let gamma = diag2 * beta + sigma_xj2; let new_diag = (diag2 + sigma_xj2 / beta).sqrt(); - unsafe { *chol.get_unchecked_mut((j, j)) = N::from_real(new_diag) }; + unsafe { *chol.get_unchecked_mut((j, j)) = T::from_real(new_diag) }; beta += sigma_xj2 / diag2; // updates the terms of L let mut xjplus = x.rows_range_mut(j + 1..); let mut col_j = chol.slice_range_mut(j + 1.., j); - // temp_jplus -= (wj / N::from_real(diag)) * col_j; - xjplus.axpy(-xj / N::from_real(diag), &col_j, N::one()); - if gamma != crate::zero::() { - // col_j = N::from_real(nljj / diag) * col_j + (N::from_real(nljj * sigma / gamma) * N::conjugate(wj)) * temp_jplus; + // temp_jplus -= (wj / T::from_real(diag)) * col_j; + xjplus.axpy(-xj / T::from_real(diag), &col_j, T::one()); + if gamma != crate::zero::() { + // col_j = T::from_real(nljj / diag) * col_j + (T::from_real(nljj * sigma / gamma) * T::conjugate(wj)) * temp_jplus; col_j.axpy( - N::from_real(new_diag * sigma / gamma) * N::conjugate(xj), + T::from_real(new_diag * sigma / gamma) * T::conjugate(xj), &xjplus, - N::from_real(new_diag / diag), + T::from_real(new_diag / diag), ); } } diff --git a/src/linalg/col_piv_qr.rs b/src/linalg/col_piv_qr.rs index 91083634..5c776b2d 100644 --- a/src/linalg/col_piv_qr.rs +++ b/src/linalg/col_piv_qr.rs @@ -3,7 +3,7 @@ use num::Zero; use serde::{Deserialize, Serialize}; use crate::allocator::{Allocator, Reallocator}; -use crate::base::{Const, DefaultAllocator, Matrix, MatrixMN, MatrixN, Unit, VectorN}; +use crate::base::{Const, DefaultAllocator, Matrix, OMatrix, OVector, Unit}; use crate::constraint::{SameNumberOfRows, ShapeConstraint}; use crate::dimension::{Dim, DimMin, DimMinimum}; use crate::storage::{Storage, StorageMut}; @@ -16,52 +16,52 @@ use crate::linalg::{householder, PermutationSequence}; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "DefaultAllocator: Allocator + - Allocator>, - MatrixMN: Serialize, + serde(bound(serialize = "DefaultAllocator: Allocator + + Allocator>, + OMatrix: Serialize, PermutationSequence>: Serialize, - VectorN>: Serialize")) + OVector>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator + - Allocator>, - MatrixMN: Deserialize<'de>, + serde(bound(deserialize = "DefaultAllocator: Allocator + + Allocator>, + OMatrix: Deserialize<'de>, PermutationSequence>: Deserialize<'de>, - VectorN>: Deserialize<'de>")) + OVector>: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct ColPivQR, C: Dim> +pub struct ColPivQR, C: Dim> where - DefaultAllocator: Allocator - + Allocator> + DefaultAllocator: Allocator + + Allocator> + Allocator<(usize, usize), DimMinimum>, { - col_piv_qr: MatrixMN, + col_piv_qr: OMatrix, p: PermutationSequence>, - diag: VectorN>, + diag: OVector>, } -impl, C: Dim> Copy for ColPivQR +impl, C: Dim> Copy for ColPivQR where - DefaultAllocator: Allocator - + Allocator> + DefaultAllocator: Allocator + + Allocator> + Allocator<(usize, usize), DimMinimum>, - MatrixMN: Copy, + OMatrix: Copy, PermutationSequence>: Copy, - VectorN>: Copy, + OVector>: Copy, { } -impl, C: Dim> ColPivQR +impl, C: Dim> ColPivQR where - DefaultAllocator: Allocator - + Allocator - + Allocator> + DefaultAllocator: Allocator + + Allocator + + Allocator> + Allocator<(usize, usize), DimMinimum>, { /// Computes the ColPivQR decomposition using householder reflections. - pub fn new(mut matrix: MatrixMN) -> Self { + pub fn new(mut matrix: OMatrix) -> Self { let (nrows, ncols) = matrix.data.shape(); let min_nrows_ncols = nrows.min(ncols); let mut p = PermutationSequence::identity_generic(min_nrows_ncols); @@ -95,16 +95,16 @@ where /// Retrieves the upper trapezoidal submatrix `R` of this decomposition. #[inline] - pub fn r(&self) -> MatrixMN, C> + pub fn r(&self) -> OMatrix, C> where - DefaultAllocator: Allocator, C>, + DefaultAllocator: Allocator, C>, { let (nrows, ncols) = self.col_piv_qr.data.shape(); let mut res = self .col_piv_qr .rows_generic(0, nrows.min(ncols)) .upper_triangle(); - res.set_partial_diagonal(self.diag.iter().map(|e| N::from_real(e.modulus()))); + res.set_partial_diagonal(self.diag.iter().map(|e| T::from_real(e.modulus()))); res } @@ -112,23 +112,23 @@ where /// /// This is usually faster than `r` but consumes `self`. #[inline] - pub fn unpack_r(self) -> MatrixMN, C> + pub fn unpack_r(self) -> OMatrix, C> where - DefaultAllocator: Reallocator, C>, + DefaultAllocator: Reallocator, C>, { let (nrows, ncols) = self.col_piv_qr.data.shape(); let mut res = self .col_piv_qr - .resize_generic(nrows.min(ncols), ncols, N::zero()); - res.fill_lower_triangle(N::zero(), 1); - res.set_partial_diagonal(self.diag.iter().map(|e| N::from_real(e.modulus()))); + .resize_generic(nrows.min(ncols), ncols, T::zero()); + res.fill_lower_triangle(T::zero(), 1); + res.set_partial_diagonal(self.diag.iter().map(|e| T::from_real(e.modulus()))); res } /// Computes the orthogonal matrix `Q` of this decomposition. - pub fn q(&self) -> MatrixMN> + pub fn q(&self) -> OMatrix> where - DefaultAllocator: Allocator>, + DefaultAllocator: Allocator>, { let (nrows, ncols) = self.col_piv_qr.data.shape(); @@ -140,7 +140,7 @@ where for i in (0..dim).rev() { let axis = self.col_piv_qr.slice_range(i.., i); // TODO: sometimes, the axis might have a zero magnitude. - let refl = Reflection::new(Unit::new_unchecked(axis), N::zero()); + let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let mut res_rows = res.slice_range_mut(i.., i..); refl.reflect_with_sign(&mut res_rows, self.diag[i].signum()); @@ -158,34 +158,34 @@ where pub fn unpack( self, ) -> ( - MatrixMN>, - MatrixMN, C>, + OMatrix>, + OMatrix, C>, PermutationSequence>, ) where DimMinimum: DimMin>, - DefaultAllocator: Allocator> - + Reallocator, C> + DefaultAllocator: Allocator> + + Reallocator, C> + Allocator<(usize, usize), DimMinimum>, { (self.q(), self.r(), self.p) } #[doc(hidden)] - pub fn col_piv_qr_internal(&self) -> &MatrixMN { + pub fn col_piv_qr_internal(&self) -> &OMatrix { &self.col_piv_qr } /// Multiplies the provided matrix by the transpose of the `Q` matrix of this decomposition. - pub fn q_tr_mul(&self, rhs: &mut Matrix) + pub fn q_tr_mul(&self, rhs: &mut Matrix) where - S2: StorageMut, + S2: StorageMut, { let dim = self.diag.len(); for i in 0..dim { let axis = self.col_piv_qr.slice_range(i.., i); - let refl = Reflection::new(Unit::new_unchecked(axis), N::zero()); + let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let mut rhs_rows = rhs.rows_range_mut(i..); refl.reflect_with_sign(&mut rhs_rows, self.diag[i].signum().conjugate()); @@ -193,22 +193,22 @@ where } } -impl> ColPivQR +impl> ColPivQR where DefaultAllocator: - Allocator + Allocator + Allocator<(usize, usize), DimMinimum>, + Allocator + Allocator + Allocator<(usize, usize), DimMinimum>, { /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. /// /// Returns `None` if `self` is not invertible. pub fn solve( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let mut res = b.clone_owned(); @@ -223,9 +223,9 @@ where /// /// If the decomposed matrix is not invertible, this returns `false` and its input `b` is /// overwritten with garbage. - pub fn solve_mut(&self, b: &mut Matrix) -> bool + pub fn solve_mut(&self, b: &mut Matrix) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { assert_eq!( @@ -248,10 +248,10 @@ where // TODO: duplicate code from the `solve` module. fn solve_upper_triangular_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let dim = self.col_piv_qr.nrows(); @@ -273,7 +273,7 @@ where } b.rows_range_mut(..i) - .axpy(-coeff, &self.col_piv_qr.slice_range(..i, i), N::one()); + .axpy(-coeff, &self.col_piv_qr.slice_range(..i, i), T::one()); } } @@ -283,7 +283,7 @@ where /// Computes the inverse of the decomposed matrix. /// /// Returns `None` if the decomposed matrix is not invertible. - pub fn try_inverse(&self) -> Option> { + pub fn try_inverse(&self) -> Option> { assert!( self.col_piv_qr.is_square(), "ColPivQR inverse: unable to compute the inverse of a non-square matrix." @@ -291,7 +291,7 @@ where // TODO: is there a less naive method ? let (nrows, ncols) = self.col_piv_qr.data.shape(); - let mut res = MatrixN::identity_generic(nrows, ncols); + let mut res = OMatrix::identity_generic(nrows, ncols); if self.solve_mut(&mut res) { Some(res) @@ -317,14 +317,14 @@ where } /// Computes the determinant of the decomposed matrix. - pub fn determinant(&self) -> N { + pub fn determinant(&self) -> T { let dim = self.col_piv_qr.nrows(); assert!( self.col_piv_qr.is_square(), "ColPivQR determinant: unable to compute the determinant of a non-square matrix." ); - let mut res = N::one(); + let mut res = T::one(); for i in 0..dim { res *= unsafe { *self.diag.vget_unchecked(i) }; } diff --git a/src/linalg/convolution.rs b/src/linalg/convolution.rs index c2b408e5..2729b66b 100644 --- a/src/linalg/convolution.rs +++ b/src/linalg/convolution.rs @@ -4,9 +4,9 @@ use crate::base::allocator::Allocator; use crate::base::default_allocator::DefaultAllocator; use crate::base::dimension::{Const, Dim, DimAdd, DimDiff, DimSub, DimSum}; use crate::storage::Storage; -use crate::{zero, RealField, Vector, VectorN, U1}; +use crate::{zero, OVector, RealField, Vector, U1}; -impl> Vector { +impl> Vector { /// Returns the convolution of the target vector and a kernel. /// /// # Arguments @@ -18,14 +18,14 @@ impl> Vector { /// pub fn convolve_full( &self, - kernel: Vector, - ) -> VectorN, U1>> + kernel: Vector, + ) -> OVector, U1>> where D1: DimAdd, D2: DimAdd>, DimSum: DimSub, - S2: Storage, - DefaultAllocator: Allocator, U1>>, + S2: Storage, + DefaultAllocator: Allocator, U1>>, { let vec = self.len(); let ker = kernel.len(); @@ -40,7 +40,7 @@ impl> Vector { .0 .add(kernel.data.shape().0) .sub(Const::<1>); - let mut conv = VectorN::zeros_generic(result_len, Const::<1>); + let mut conv = OVector::zeros_generic(result_len, Const::<1>); for i in 0..(vec + ker - 1) { let u_i = if i > vec { i - ker } else { 0 }; @@ -71,14 +71,14 @@ impl> Vector { /// pub fn convolve_valid( &self, - kernel: Vector, - ) -> VectorN, D2>> + kernel: Vector, + ) -> OVector, D2>> where D1: DimAdd, D2: Dim, DimSum: DimSub, - S2: Storage, - DefaultAllocator: Allocator, D2>>, + S2: Storage, + DefaultAllocator: Allocator, D2>>, { let vec = self.len(); let ker = kernel.len(); @@ -93,7 +93,7 @@ impl> Vector { .0 .add(Const::<1>) .sub(kernel.data.shape().0); - let mut conv = VectorN::zeros_generic(result_len, Const::<1>); + let mut conv = OVector::zeros_generic(result_len, Const::<1>); for i in 0..(vec - ker + 1) { for j in 0..ker { @@ -112,11 +112,11 @@ impl> Vector { /// /// # Errors /// Inputs must satisfy `self.len() >= kernel.len() > 0`. - pub fn convolve_same(&self, kernel: Vector) -> VectorN + pub fn convolve_same(&self, kernel: Vector) -> OVector where D2: Dim, - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, { let vec = self.len(); let ker = kernel.len(); @@ -125,12 +125,12 @@ impl> Vector { panic!("convolve_same expects `self.len() >= kernel.len() > 0`, received {} and {} respectively.",vec,ker); } - let mut conv = VectorN::zeros_generic(self.data.shape().0, Const::<1>); + let mut conv = OVector::zeros_generic(self.data.shape().0, Const::<1>); for i in 0..vec { for j in 0..ker { let val = if i + j < 1 || i + j >= vec + 1 { - zero::() + zero::() } else { self[i + j - 1] }; diff --git a/src/linalg/decomposition.rs b/src/linalg/decomposition.rs index 6428856b..5b56b65a 100644 --- a/src/linalg/decomposition.rs +++ b/src/linalg/decomposition.rs @@ -17,17 +17,17 @@ use crate::{ /// | LU with partial pivoting | `P⁻¹ * L * U` | `L` is lower-triangular with a diagonal filled with `1` and `U` is upper-triangular. `P` is a permutation matrix. | /// | LU with full pivoting | `P⁻¹ * L * U * Q⁻¹` | `L` is lower-triangular with a diagonal filled with `1` and `U` is upper-triangular. `P` and `Q` are permutation matrices. | /// | SVD | `U * Σ * Vᵀ` | `U` and `V` are two orthogonal matrices and `Σ` is a diagonal matrix containing the singular values. | -impl> Matrix { +impl> Matrix { /// Computes the bidiagonalization using householder reflections. - pub fn bidiagonalize(self) -> Bidiagonal + pub fn bidiagonalize(self) -> Bidiagonal where R: DimMin, DimMinimum: DimSub, - DefaultAllocator: Allocator - + Allocator - + Allocator - + Allocator> - + Allocator, U1>>, + DefaultAllocator: Allocator + + Allocator + + Allocator + + Allocator> + + Allocator, U1>>, { Bidiagonal::new(self.into_owned()) } @@ -35,58 +35,58 @@ impl> Matrix { /// Computes the LU decomposition with full pivoting of `matrix`. /// /// This effectively computes `P, L, U, Q` such that `P * matrix * Q = LU`. - pub fn full_piv_lu(self) -> FullPivLU + pub fn full_piv_lu(self) -> FullPivLU where R: DimMin, - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { FullPivLU::new(self.into_owned()) } /// Computes the LU decomposition with partial (row) pivoting of `matrix`. - pub fn lu(self) -> LU + pub fn lu(self) -> LU where R: DimMin, - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { LU::new(self.into_owned()) } /// Computes the QR decomposition of this matrix. - pub fn qr(self) -> QR + pub fn qr(self) -> QR where R: DimMin, - DefaultAllocator: Allocator + Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator + Allocator>, { QR::new(self.into_owned()) } /// Computes the QR decomposition (with column pivoting) of this matrix. - pub fn col_piv_qr(self) -> ColPivQR + pub fn col_piv_qr(self) -> ColPivQR where R: DimMin, - DefaultAllocator: Allocator - + Allocator - + Allocator> + DefaultAllocator: Allocator + + Allocator + + Allocator> + Allocator<(usize, usize), DimMinimum>, { ColPivQR::new(self.into_owned()) } /// Computes the Singular Value Decomposition using implicit shift. - pub fn svd(self, compute_u: bool, compute_v: bool) -> SVD + pub fn svd(self, compute_u: bool, compute_v: bool) -> SVD where R: DimMin, DimMinimum: DimSub, // for Bidiagonal. - DefaultAllocator: Allocator - + Allocator - + Allocator - + Allocator, U1>> - + Allocator, C> - + Allocator> - + Allocator> - + Allocator> - + Allocator, U1>>, + DefaultAllocator: Allocator + + Allocator + + Allocator + + Allocator, U1>> + + Allocator, C> + + Allocator> + + Allocator> + + Allocator> + + Allocator, U1>>, { SVD::new(self.into_owned(), compute_u, compute_v) } @@ -105,21 +105,21 @@ impl> Matrix { self, compute_u: bool, compute_v: bool, - eps: N::RealField, + eps: T::RealField, max_niter: usize, - ) -> Option> + ) -> Option> where R: DimMin, DimMinimum: DimSub, // for Bidiagonal. - DefaultAllocator: Allocator - + Allocator - + Allocator - + Allocator, U1>> - + Allocator, C> - + Allocator> - + Allocator> - + Allocator> - + Allocator, U1>>, + DefaultAllocator: Allocator + + Allocator + + Allocator + + Allocator, U1>> + + Allocator, C> + + Allocator> + + Allocator> + + Allocator> + + Allocator, U1>>, { SVD::try_new(self.into_owned(), compute_u, compute_v, eps, max_niter) } @@ -138,14 +138,14 @@ impl> Matrix { /// | Schur decomposition | `Q * T * Qᵀ` | `Q` is an unitary matrix and `T` a quasi-upper-triangular matrix. | /// | Symmetric eigendecomposition | `Q ~ Λ ~ Qᵀ` | `Q` is an unitary matrix, and `Λ` is a real diagonal matrix. | /// | Symmetric tridiagonalization | `Q ~ T ~ Qᵀ` | `Q` is an unitary matrix, and `T` is a tridiagonal matrix. | -impl> Matrix { +impl> Matrix { /// Attempts to compute the Cholesky decomposition of this matrix. /// /// Returns `None` if the input matrix is not definite-positive. The input matrix is assumed /// to be symmetric and only the lower-triangular part is read. - pub fn cholesky(self) -> Option> + pub fn cholesky(self) -> Option> where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { Cholesky::new(self.into_owned()) } @@ -154,31 +154,31 @@ impl> Matrix { /// /// The input matrix `self` is assumed to be symmetric and this decomposition will only read /// the upper-triangular part of `self`. - pub fn udu(self) -> Option> + pub fn udu(self) -> Option> where - N: RealField, - DefaultAllocator: Allocator + Allocator, + T: RealField, + DefaultAllocator: Allocator + Allocator, { UDU::new(self.into_owned()) } /// Computes the Hessenberg decomposition of this matrix using householder reflections. - pub fn hessenberg(self) -> Hessenberg + pub fn hessenberg(self) -> Hessenberg where D: DimSub, - DefaultAllocator: Allocator + Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator + Allocator>, { Hessenberg::new(self.into_owned()) } /// Computes the Schur decomposition of a square matrix. - pub fn schur(self) -> Schur + pub fn schur(self) -> Schur where D: DimSub, // For Hessenberg. - DefaultAllocator: Allocator> - + Allocator> - + Allocator - + Allocator, + DefaultAllocator: Allocator> + + Allocator> + + Allocator + + Allocator, { Schur::new(self.into_owned()) } @@ -194,13 +194,13 @@ impl> Matrix { /// * `max_niter` − maximum total number of iterations performed by the algorithm. If this /// number of iteration is exceeded, `None` is returned. If `niter == 0`, then the algorithm /// continues indefinitely until convergence. - pub fn try_schur(self, eps: N::RealField, max_niter: usize) -> Option> + pub fn try_schur(self, eps: T::RealField, max_niter: usize) -> Option> where D: DimSub, // For Hessenberg. - DefaultAllocator: Allocator> - + Allocator> - + Allocator - + Allocator, + DefaultAllocator: Allocator> + + Allocator> + + Allocator + + Allocator, { Schur::try_new(self.into_owned(), eps, max_niter) } @@ -208,13 +208,13 @@ impl> Matrix { /// Computes the eigendecomposition of this symmetric matrix. /// /// Only the lower-triangular part (including the diagonal) of `m` is read. - pub fn symmetric_eigen(self) -> SymmetricEigen + pub fn symmetric_eigen(self) -> SymmetricEigen where D: DimSub, - DefaultAllocator: Allocator - + Allocator> - + Allocator - + Allocator>, + DefaultAllocator: Allocator + + Allocator> + + Allocator + + Allocator>, { SymmetricEigen::new(self.into_owned()) } @@ -232,15 +232,15 @@ impl> Matrix { /// continues indefinitely until convergence. pub fn try_symmetric_eigen( self, - eps: N::RealField, + eps: T::RealField, max_niter: usize, - ) -> Option> + ) -> Option> where D: DimSub, - DefaultAllocator: Allocator - + Allocator> - + Allocator - + Allocator>, + DefaultAllocator: Allocator + + Allocator> + + Allocator + + Allocator>, { SymmetricEigen::try_new(self.into_owned(), eps, max_niter) } @@ -248,10 +248,10 @@ impl> Matrix { /// Computes the tridiagonalization of this symmetric matrix. /// /// Only the lower-triangular part (including the diagonal) of `m` is read. - pub fn symmetric_tridiagonalize(self) -> SymmetricTridiagonal + pub fn symmetric_tridiagonalize(self) -> SymmetricTridiagonal where D: DimSub, - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { SymmetricTridiagonal::new(self.into_owned()) } diff --git a/src/linalg/determinant.rs b/src/linalg/determinant.rs index 73365d78..aa04ff3f 100644 --- a/src/linalg/determinant.rs +++ b/src/linalg/determinant.rs @@ -7,14 +7,14 @@ use crate::base::{DefaultAllocator, SquareMatrix}; use crate::linalg::LU; -impl, S: Storage> SquareMatrix { +impl, S: Storage> SquareMatrix { /// Computes the matrix determinant. /// /// If the matrix has a dimension larger than 3, an LU decomposition is used. #[inline] - pub fn determinant(&self) -> N + pub fn determinant(&self) -> T where - DefaultAllocator: Allocator + Allocator<(usize, usize), D>, + DefaultAllocator: Allocator + Allocator<(usize, usize), D>, { assert!( self.is_square(), @@ -24,7 +24,7 @@ impl, S: Storage> SquareMatri unsafe { match dim { - 0 => N::one(), + 0 => T::one(), 1 => *self.get_unchecked((0, 0)), 2 => { let m11 = *self.get_unchecked((0, 0)); diff --git a/src/linalg/eigen.rs b/src/linalg/eigen.rs index 2177903e..12d83a02 100644 --- a/src/linalg/eigen.rs +++ b/src/linalg/eigen.rs @@ -11,7 +11,7 @@ use crate::allocator::Allocator; use crate::base::dimension::{Dim, DimDiff, DimSub, Dynamic, U1, U2, U3}; use crate::base::storage::Storage; use crate::base::{ - DefaultAllocator, Hessenberg, MatrixN, SquareMatrix, Unit, Vector2, Vector3, VectorN, + DefaultAllocator, Hessenberg, OMatrix, OVector, SquareMatrix, Unit, Vector2, Vector3, }; use crate::constraint::{DimEq, ShapeConstraint}; @@ -23,46 +23,47 @@ use crate::linalg::Schur; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "DefaultAllocator: Allocator, - VectorN: Serialize, - MatrixN: Serialize")) + serde(bound(serialize = "DefaultAllocator: Allocator, + OVector: Serialize, + OMatrix: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator, - VectorN: Serialize, - MatrixN: Deserialize<'de>")) + serde(bound(deserialize = "DefaultAllocator: Allocator, + OVector: Serialize, + OMatrix: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct Eigen -where DefaultAllocator: Allocator + Allocator -{ - pub eigenvectors: MatrixN, - pub eigenvalues: VectorN, -} - -impl Copy for Eigen +pub struct Eigen where - DefaultAllocator: Allocator + Allocator, - MatrixN: Copy, - VectorN: Copy, + DefaultAllocator: Allocator + Allocator, +{ + pub eigenvectors: OMatrix, + pub eigenvalues: OVector, +} + +impl Copy for Eigen +where + DefaultAllocator: Allocator + Allocator, + OMatrix: Copy, + OVector: Copy, { } -impl Eigen +impl Eigen where D: DimSub, // For Hessenberg. ShapeConstraint: DimEq>, // For Hessenberg. - DefaultAllocator: Allocator> - + Allocator> - + Allocator - + Allocator, + DefaultAllocator: Allocator> + + Allocator> + + Allocator + + Allocator, // XXX: for debug DefaultAllocator: Allocator, - MatrixN: Display, + OMatrix: Display, { /// Computes the eigendecomposition of a diagonalizable matrix with Complex eigenvalues. - pub fn new(m: MatrixN) -> Option> { + pub fn new(m: OMatrix) -> Option> { assert!( m.is_square(), "Unable to compute the eigendecomposition of a non-square matrix." diff --git a/src/linalg/exp.rs b/src/linalg/exp.rs index 9011b588..598c6350 100644 --- a/src/linalg/exp.rs +++ b/src/linalg/exp.rs @@ -7,50 +7,50 @@ use crate::{ storage::Storage, DefaultAllocator, }, - convert, try_convert, ComplexField, MatrixN, RealField, + convert, try_convert, ComplexField, OMatrix, RealField, }; use crate::num::Zero; // https://github.com/scipy/scipy/blob/c1372d8aa90a73d8a52f135529293ff4edb98fc8/scipy/sparse/linalg/matfuncs.py -struct ExpmPadeHelper +struct ExpmPadeHelper where - N: ComplexField, + T: ComplexField, D: DimMin, - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { use_exact_norm: bool, - ident: MatrixN, + ident: OMatrix, - a: MatrixN, - a2: Option>, - a4: Option>, - a6: Option>, - a8: Option>, - a10: Option>, + a: OMatrix, + a2: Option>, + a4: Option>, + a6: Option>, + a8: Option>, + a10: Option>, - d4_exact: Option, - d6_exact: Option, - d8_exact: Option, - d10_exact: Option, + d4_exact: Option, + d6_exact: Option, + d8_exact: Option, + d10_exact: Option, - d4_approx: Option, - d6_approx: Option, - d8_approx: Option, - d10_approx: Option, + d4_approx: Option, + d6_approx: Option, + d8_approx: Option, + d10_approx: Option, } -impl ExpmPadeHelper +impl ExpmPadeHelper where - N: ComplexField, + T: ComplexField, D: DimMin, - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { - fn new(a: MatrixN, use_exact_norm: bool) -> Self { + fn new(a: OMatrix, use_exact_norm: bool) -> Self { let (nrows, ncols) = a.data.shape(); ExpmPadeHelper { use_exact_norm, - ident: MatrixN::::identity_generic(nrows, ncols), + ident: OMatrix::::identity_generic(nrows, ncols), a, a2: None, a4: None, @@ -112,7 +112,7 @@ where } } - fn d4_tight(&mut self) -> N::RealField { + fn d4_tight(&mut self) -> T::RealField { if self.d4_exact.is_none() { self.calc_a4(); self.d4_exact = Some(one_norm(self.a4.as_ref().unwrap()).powf(convert(0.25))); @@ -120,7 +120,7 @@ where self.d4_exact.unwrap() } - fn d6_tight(&mut self) -> N::RealField { + fn d6_tight(&mut self) -> T::RealField { if self.d6_exact.is_none() { self.calc_a6(); self.d6_exact = Some(one_norm(self.a6.as_ref().unwrap()).powf(convert(1.0 / 6.0))); @@ -128,7 +128,7 @@ where self.d6_exact.unwrap() } - fn d8_tight(&mut self) -> N::RealField { + fn d8_tight(&mut self) -> T::RealField { if self.d8_exact.is_none() { self.calc_a8(); self.d8_exact = Some(one_norm(self.a8.as_ref().unwrap()).powf(convert(1.0 / 8.0))); @@ -136,7 +136,7 @@ where self.d8_exact.unwrap() } - fn d10_tight(&mut self) -> N::RealField { + fn d10_tight(&mut self) -> T::RealField { if self.d10_exact.is_none() { self.calc_a10(); self.d10_exact = Some(one_norm(self.a10.as_ref().unwrap()).powf(convert(1.0 / 10.0))); @@ -144,7 +144,7 @@ where self.d10_exact.unwrap() } - fn d4_loose(&mut self) -> N::RealField { + fn d4_loose(&mut self) -> T::RealField { if self.use_exact_norm { return self.d4_tight(); } @@ -161,7 +161,7 @@ where self.d4_approx.unwrap() } - fn d6_loose(&mut self) -> N::RealField { + fn d6_loose(&mut self) -> T::RealField { if self.use_exact_norm { return self.d6_tight(); } @@ -178,7 +178,7 @@ where self.d6_approx.unwrap() } - fn d8_loose(&mut self) -> N::RealField { + fn d8_loose(&mut self) -> T::RealField { if self.use_exact_norm { return self.d8_tight(); } @@ -195,7 +195,7 @@ where self.d8_approx.unwrap() } - fn d10_loose(&mut self) -> N::RealField { + fn d10_loose(&mut self) -> T::RealField { if self.use_exact_norm { return self.d10_tight(); } @@ -212,8 +212,8 @@ where self.d10_approx.unwrap() } - fn pade3(&mut self) -> (MatrixN, MatrixN) { - let b: [N; 4] = [convert(120.0), convert(60.0), convert(12.0), convert(1.0)]; + fn pade3(&mut self) -> (OMatrix, OMatrix) { + let b: [T; 4] = [convert(120.0), convert(60.0), convert(12.0), convert(1.0)]; self.calc_a2(); let a2 = self.a2.as_ref().unwrap(); let u = &self.a * (a2 * b[3] + &self.ident * b[1]); @@ -221,8 +221,8 @@ where (u, v) } - fn pade5(&mut self) -> (MatrixN, MatrixN) { - let b: [N; 6] = [ + fn pade5(&mut self) -> (OMatrix, OMatrix) { + let b: [T; 6] = [ convert(30240.0), convert(15120.0), convert(3360.0), @@ -242,8 +242,8 @@ where (u, v) } - fn pade7(&mut self) -> (MatrixN, MatrixN) { - let b: [N; 8] = [ + fn pade7(&mut self) -> (OMatrix, OMatrix) { + let b: [T; 8] = [ convert(17_297_280.0), convert(8_648_640.0), convert(1_995_840.0), @@ -268,8 +268,8 @@ where (u, v) } - fn pade9(&mut self) -> (MatrixN, MatrixN) { - let b: [N; 10] = [ + fn pade9(&mut self) -> (OMatrix, OMatrix) { + let b: [T; 10] = [ convert(17_643_225_600.0), convert(8_821_612_800.0), convert(2_075_673_600.0), @@ -299,8 +299,8 @@ where (u, v) } - fn pade13_scaled(&mut self, s: u64) -> (MatrixN, MatrixN) { - let b: [N; 14] = [ + fn pade13_scaled(&mut self, s: u64) -> (OMatrix, OMatrix) { + let b: [T; 14] = [ convert(64_764_752_532_480_000.0), convert(32_382_376_266_240_000.0), convert(7_771_770_303_897_600.0), @@ -318,13 +318,13 @@ where ]; let s = s as f64; - let mb = &self.a * convert::(2.0_f64.powf(-s)); + let mb = &self.a * convert::(2.0_f64.powf(-s)); self.calc_a2(); self.calc_a4(); self.calc_a6(); - let mb2 = self.a2.as_ref().unwrap() * convert::(2.0_f64.powf(-2.0 * s)); - let mb4 = self.a4.as_ref().unwrap() * convert::(2.0.powf(-4.0 * s)); - let mb6 = self.a6.as_ref().unwrap() * convert::(2.0.powf(-6.0 * s)); + let mb2 = self.a2.as_ref().unwrap() * convert::(2.0_f64.powf(-2.0 * s)); + let mb4 = self.a4.as_ref().unwrap() * convert::(2.0.powf(-4.0 * s)); + let mb6 = self.a6.as_ref().unwrap() * convert::(2.0.powf(-6.0 * s)); let u2 = &mb6 * (&mb6 * b[13] + &mb4 * b[11] + &mb2 * b[9]); let u = &mb * (&u2 + &mb6 * b[7] + &mb4 * b[5] + &mb2 * b[3] + &self.ident * b[1]); @@ -342,14 +342,14 @@ fn factorial(n: u128) -> u128 { } /// Compute the 1-norm of a non-negative integer power of a non-negative matrix. -fn onenorm_matrix_power_nonm(a: &MatrixN, p: u64) -> N +fn onenorm_matrix_power_nonm(a: &OMatrix, p: u64) -> T where - N: RealField, + T: RealField, D: Dim, - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { let nrows = a.data.shape().0; - let mut v = crate::VectorN::::repeat_generic(nrows, Const::<1>, convert(1.0)); + let mut v = crate::OVector::::repeat_generic(nrows, Const::<1>, convert(1.0)); let m = a.transpose(); for _ in 0..p { @@ -359,14 +359,14 @@ where v.max() } -fn ell(a: &MatrixN, m: u64) -> u64 +fn ell(a: &OMatrix, m: u64) -> u64 where - N: ComplexField, + T: ComplexField, D: Dim, - DefaultAllocator: Allocator - + Allocator - + Allocator - + Allocator, + DefaultAllocator: Allocator + + Allocator + + Allocator + + Allocator, { // 2m choose m = (2m)!/(m! * (2m-m)!) @@ -374,7 +374,7 @@ where let a_abs_onenorm = onenorm_matrix_power_nonm(&a_abs, 2 * m + 1); - if a_abs_onenorm == ::RealField::zero() { + if a_abs_onenorm == ::RealField::zero() { return 0; } @@ -394,11 +394,11 @@ where } } -fn solve_p_q(u: MatrixN, v: MatrixN) -> MatrixN +fn solve_p_q(u: OMatrix, v: OMatrix) -> OMatrix where - N: ComplexField, + T: ComplexField, D: DimMin, - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { let p = &u + &v; let q = &v - &u; @@ -406,33 +406,33 @@ where q.lu().solve(&p).unwrap() } -fn one_norm(m: &MatrixN) -> N::RealField +fn one_norm(m: &OMatrix) -> T::RealField where - N: ComplexField, + T: ComplexField, D: Dim, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - let mut max = ::RealField::zero(); + let mut max = ::RealField::zero(); for i in 0..m.ncols() { let col = m.column(i); max = max.max( col.iter() - .fold(::RealField::zero(), |a, b| a + b.abs()), + .fold(::RealField::zero(), |a, b| a + b.abs()), ); } max } -impl MatrixN +impl OMatrix where D: DimMin, - DefaultAllocator: Allocator + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum> - + Allocator - + Allocator - + Allocator, + + Allocator + + Allocator + + Allocator, { /// Computes exponential of this matrix pub fn exp(&self) -> Self { @@ -443,19 +443,19 @@ where let mut h = ExpmPadeHelper::new(self.clone(), true); - let eta_1 = N::RealField::max(h.d4_loose(), h.d6_loose()); + let eta_1 = T::RealField::max(h.d4_loose(), h.d6_loose()); if eta_1 < convert(1.495_585_217_958_292e-2) && ell(&h.a, 3) == 0 { let (u, v) = h.pade3(); return solve_p_q(u, v); } - let eta_2 = N::RealField::max(h.d4_tight(), h.d6_loose()); + let eta_2 = T::RealField::max(h.d4_tight(), h.d6_loose()); if eta_2 < convert(2.539_398_330_063_230e-1) && ell(&h.a, 5) == 0 { let (u, v) = h.pade5(); return solve_p_q(u, v); } - let eta_3 = N::RealField::max(h.d6_tight(), h.d8_loose()); + let eta_3 = T::RealField::max(h.d6_tight(), h.d8_loose()); if eta_3 < convert(9.504_178_996_162_932e-1) && ell(&h.a, 7) == 0 { let (u, v) = h.pade7(); return solve_p_q(u, v); @@ -465,11 +465,11 @@ where return solve_p_q(u, v); } - let eta_4 = N::RealField::max(h.d8_loose(), h.d10_loose()); - let eta_5 = N::RealField::min(eta_3, eta_4); + let eta_4 = T::RealField::max(h.d8_loose(), h.d10_loose()); + let eta_5 = T::RealField::min(eta_3, eta_4); let theta_13 = convert(4.25); - let mut s = if eta_5 == N::RealField::zero() { + let mut s = if eta_5 == T::RealField::zero() { 0 } else { let l2 = try_convert((eta_5 / theta_13).log2().ceil()).unwrap(); @@ -481,7 +481,7 @@ where } }; - s += ell(&(&h.a * convert::(2.0_f64.powf(-(s as f64)))), 13); + s += ell(&(&h.a * convert::(2.0_f64.powf(-(s as f64)))), 13); let (u, v) = h.pade13_scaled(s); let mut x = solve_p_q(u, v); diff --git a/src/linalg/full_piv_lu.rs b/src/linalg/full_piv_lu.rs index fb8ff670..ae14f827 100644 --- a/src/linalg/full_piv_lu.rs +++ b/src/linalg/full_piv_lu.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::allocator::Allocator; -use crate::base::{DefaultAllocator, Matrix, MatrixMN, MatrixN}; +use crate::base::{DefaultAllocator, Matrix, OMatrix}; use crate::constraint::{SameNumberOfRows, ShapeConstraint}; use crate::dimension::{Dim, DimMin, DimMinimum}; use crate::storage::{Storage, StorageMut}; @@ -15,44 +15,44 @@ use crate::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, + OMatrix: 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>, + OMatrix: Deserialize<'de>, PermutationSequence>: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct FullPivLU, C: Dim> +pub struct FullPivLU, C: Dim> where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { - lu: MatrixMN, + lu: OMatrix, p: PermutationSequence>, q: PermutationSequence>, } -impl, C: Dim> Copy for FullPivLU +impl, C: Dim> Copy for FullPivLU where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, - MatrixMN: Copy, + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + OMatrix: Copy, PermutationSequence>: Copy, { } -impl, C: Dim> FullPivLU +impl, C: Dim> FullPivLU where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { /// Computes the LU decomposition with full pivoting of `matrix`. /// /// This effectively computes `P, L, U, Q` such that `P * matrix * Q = LU`. - pub fn new(mut matrix: MatrixMN) -> Self { + pub fn new(mut matrix: OMatrix) -> Self { let (nrows, ncols) = matrix.data.shape(); let min_nrows_ncols = nrows.min(ncols); @@ -90,28 +90,28 @@ where } #[doc(hidden)] - pub fn lu_internal(&self) -> &MatrixMN { + pub fn lu_internal(&self) -> &OMatrix { &self.lu } /// The lower triangular matrix of this decomposition. #[inline] - pub fn l(&self) -> MatrixMN> + pub fn l(&self) -> OMatrix> where - DefaultAllocator: Allocator>, + 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); - m.fill_diagonal(N::one()); + m.fill_upper_triangle(T::zero(), 1); + m.fill_diagonal(T::one()); m } /// The upper triangular matrix of this decomposition. #[inline] - pub fn u(&self) -> MatrixMN, C> + pub fn u(&self) -> OMatrix, C> where - DefaultAllocator: Allocator, C>, + DefaultAllocator: Allocator, C>, { let (nrows, ncols) = self.lu.data.shape(); self.lu.rows_generic(0, nrows.min(ncols)).upper_triangle() @@ -135,12 +135,12 @@ where self, ) -> ( PermutationSequence>, - MatrixMN>, - MatrixMN, C>, + OMatrix>, + OMatrix, C>, PermutationSequence>, ) where - DefaultAllocator: Allocator> + Allocator, C>, + DefaultAllocator: Allocator> + Allocator, C>, { // Use reallocation for either l or u. let l = self.l(); @@ -152,21 +152,21 @@ where } } -impl> FullPivLU +impl> FullPivLU where - DefaultAllocator: Allocator + Allocator<(usize, usize), D>, + DefaultAllocator: Allocator + Allocator<(usize, usize), D>, { /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. /// /// Returns `None` if the decomposed matrix is not invertible. pub fn solve( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfRows, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let mut res = b.clone_owned(); if self.solve_mut(&mut res) { @@ -180,9 +180,9 @@ where /// /// If the decomposed matrix is not invertible, this returns `false` and its input `b` may /// be overwritten with garbage. - pub fn solve_mut(&self, b: &mut Matrix) -> bool + pub fn solve_mut(&self, b: &mut Matrix) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { assert_eq!( @@ -197,7 +197,7 @@ where if self.is_invertible() { self.p.permute_rows(b); - let _ = self.lu.solve_lower_triangular_with_diag_mut(b, N::one()); + let _ = self.lu.solve_lower_triangular_with_diag_mut(b, T::one()); let _ = self.lu.solve_upper_triangular_mut(b); self.q.inv_permute_rows(b); @@ -210,7 +210,7 @@ where /// Computes the inverse of the decomposed matrix. /// /// Returns `None` if the decomposed matrix is not invertible. - pub fn try_inverse(&self) -> Option> { + pub fn try_inverse(&self) -> Option> { assert!( self.lu.is_square(), "FullPivLU inverse: unable to compute the inverse of a non-square matrix." @@ -218,7 +218,7 @@ where let (nrows, ncols) = self.lu.data.shape(); - let mut res = MatrixN::identity_generic(nrows, ncols); + let mut res = OMatrix::identity_generic(nrows, ncols); if self.solve_mut(&mut res) { Some(res) } else { @@ -238,7 +238,7 @@ where } /// Computes the determinant of the decomposed matrix. - pub fn determinant(&self) -> N { + pub fn determinant(&self) -> T { assert!( self.lu.is_square(), "FullPivLU determinant: unable to compute the determinant of a non-square matrix." @@ -253,7 +253,7 @@ where res * self.p.determinant() * self.q.determinant() } else { - N::zero() + T::zero() } } } diff --git a/src/linalg/givens.rs b/src/linalg/givens.rs index 32a4204e..6073634e 100644 --- a/src/linalg/givens.rs +++ b/src/linalg/givens.rs @@ -10,18 +10,18 @@ use crate::base::{Matrix, Vector}; /// A Givens rotation. #[derive(Debug, Clone, Copy)] -pub struct GivensRotation { - c: N::RealField, - s: N, +pub struct GivensRotation { + c: T::RealField, + s: T, } // Matrix = UnitComplex * Matrix -impl GivensRotation { +impl GivensRotation { /// The Givents rotation that does nothing. pub fn identity() -> Self { Self { - c: N::RealField::one(), - s: N::zero(), + c: T::RealField::one(), + s: T::zero(), } } @@ -29,18 +29,18 @@ impl GivensRotation { /// /// The components are copies as-is. It is not checked whether they describe /// an actually valid Givens rotation. - pub fn new_unchecked(c: N::RealField, s: N) -> Self { + pub fn new_unchecked(c: T::RealField, s: T) -> Self { Self { c, s } } /// Initializes a Givens rotation from its non-normalized cosine an sine components. - pub fn new(c: N, s: N) -> (Self, N) { - Self::try_new(c, s, N::RealField::zero()) - .unwrap_or_else(|| (GivensRotation::identity(), N::zero())) + pub fn new(c: T, s: T) -> (Self, T) { + Self::try_new(c, s, T::RealField::zero()) + .unwrap_or_else(|| (GivensRotation::identity(), T::zero())) } /// Initializes a Givens rotation form its non-normalized cosine an sine components. - pub fn try_new(c: N, s: N, eps: N::RealField) -> Option<(Self, N)> { + pub fn try_new(c: T, s: T, eps: T::RealField) -> Option<(Self, T)> { let (mod0, sign0) = c.to_exp(); let denom = (mod0 * mod0 + s.modulus_squared()).sqrt(); @@ -58,7 +58,7 @@ impl GivensRotation { /// /// Returns `None` if no rotation is needed (i.e. if `v.y == 0`). Otherwise, this returns the norm /// of `v` and the rotation `r` such that `R * v = [ |v|, 0.0 ]^t` where `|v|` is the norm of `v`. - pub fn cancel_y>(v: &Vector) -> Option<(Self, N)> { + pub fn cancel_y>(v: &Vector) -> Option<(Self, T)> { if !v[1].is_zero() { let (mod0, sign0) = v[0].to_exp(); let denom = (mod0 * mod0 + v[1].modulus_squared()).sqrt(); @@ -75,7 +75,7 @@ impl GivensRotation { /// /// Returns `None` if no rotation is needed (i.e. if `v.x == 0`). Otherwise, this returns the norm /// of `v` and the rotation `r` such that `R * v = [ 0.0, |v| ]^t` where `|v|` is the norm of `v`. - pub fn cancel_x>(v: &Vector) -> Option<(Self, N)> { + pub fn cancel_x>(v: &Vector) -> Option<(Self, T)> { if !v[0].is_zero() { let (mod1, sign1) = v[1].to_exp(); let denom = (mod1 * mod1 + v[0].modulus_squared()).sqrt(); @@ -89,12 +89,12 @@ impl GivensRotation { } /// The cos part of this roration. - pub fn c(&self) -> N::RealField { + pub fn c(&self) -> T::RealField { self.c } /// The sin part of this roration. - pub fn s(&self) -> N { + pub fn s(&self) -> T { self.s } @@ -107,9 +107,9 @@ impl GivensRotation { } /// Performs the multiplication `rhs = self * rhs` in-place. - pub fn rotate>( + pub fn rotate>( &self, - rhs: &mut Matrix, + rhs: &mut Matrix, ) where ShapeConstraint: DimEq, { @@ -133,9 +133,9 @@ impl GivensRotation { } /// Performs the multiplication `lhs = lhs * self` in-place. - pub fn rotate_rows>( + pub fn rotate_rows>( &self, - lhs: &mut Matrix, + lhs: &mut Matrix, ) where ShapeConstraint: DimEq, { diff --git a/src/linalg/hessenberg.rs b/src/linalg/hessenberg.rs index c7b17239..09a7d180 100644 --- a/src/linalg/hessenberg.rs +++ b/src/linalg/hessenberg.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::allocator::Allocator; -use crate::base::{DefaultAllocator, MatrixN, VectorN}; +use crate::base::{DefaultAllocator, OMatrix, OVector}; use crate::dimension::{Const, DimDiff, DimSub, U1}; use crate::storage::Storage; use simba::scalar::ComplexField; @@ -13,43 +13,44 @@ use crate::linalg::householder; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "DefaultAllocator: Allocator + - Allocator>, - MatrixN: Serialize, - VectorN>: Serialize")) + serde(bound(serialize = "DefaultAllocator: Allocator + + Allocator>, + OMatrix: Serialize, + OVector>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator + - Allocator>, - MatrixN: Deserialize<'de>, - VectorN>: Deserialize<'de>")) + serde(bound(deserialize = "DefaultAllocator: Allocator + + Allocator>, + OMatrix: Deserialize<'de>, + OVector>: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct Hessenberg> +pub struct Hessenberg> where - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { - hess: MatrixN, - subdiag: VectorN>, + hess: OMatrix, + subdiag: OVector>, } -impl> Copy for Hessenberg +impl> Copy for Hessenberg where - DefaultAllocator: Allocator + Allocator>, - MatrixN: Copy, - VectorN>: Copy, + DefaultAllocator: Allocator + Allocator>, + OMatrix: Copy, + OVector>: Copy, { } -impl> Hessenberg +impl> Hessenberg where - DefaultAllocator: Allocator + Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator + Allocator>, { /// Computes the Hessenberg decomposition using householder reflections. - pub fn new(hess: MatrixN) -> Self { - let mut work = - unsafe { crate::unimplemented_or_uninitialized_generic!(hess.data.shape().0, Const::<1>) }; + pub fn new(hess: OMatrix) -> Self { + let mut work = unsafe { + crate::unimplemented_or_uninitialized_generic!(hess.data.shape().0, Const::<1>) + }; Self::new_with_workspace(hess, &mut work) } @@ -57,7 +58,7 @@ where /// /// The workspace containing `D` elements must be provided but its content does not have to be /// initialized. - pub fn new_with_workspace(mut hess: MatrixN, work: &mut VectorN) -> Self { + pub fn new_with_workspace(mut hess: OMatrix, work: &mut OVector) -> Self { assert!( hess.is_square(), "Cannot compute the hessenberg decomposition of a non-square matrix." @@ -75,8 +76,9 @@ where "Hessenberg: invalid workspace size." ); - let mut subdiag = - unsafe { crate::unimplemented_or_uninitialized_generic!(dim.sub(Const::<1>), Const::<1>) }; + let mut subdiag = unsafe { + crate::unimplemented_or_uninitialized_generic!(dim.sub(Const::<1>), Const::<1>) + }; if dim.value() == 0 { return Hessenberg { hess, subdiag }; @@ -92,7 +94,7 @@ where /// Retrieves `(q, h)` with `q` the orthogonal matrix of this decomposition and `h` the /// hessenberg matrix. #[inline] - pub fn unpack(self) -> (MatrixN, MatrixN) { + pub fn unpack(self) -> (OMatrix, OMatrix) { let q = self.q(); (q, self.unpack_h()) @@ -100,12 +102,12 @@ where /// Retrieves the upper trapezoidal submatrix `H` of this decomposition. #[inline] - pub fn unpack_h(mut self) -> MatrixN { + pub fn unpack_h(mut self) -> OMatrix { let dim = self.hess.nrows(); - self.hess.fill_lower_triangle(N::zero(), 2); + self.hess.fill_lower_triangle(T::zero(), 2); self.hess .slice_mut((1, 0), (dim - 1, dim - 1)) - .set_partial_diagonal(self.subdiag.iter().map(|e| N::from_real(e.modulus()))); + .set_partial_diagonal(self.subdiag.iter().map(|e| T::from_real(e.modulus()))); self.hess } @@ -114,22 +116,22 @@ where /// /// This is less efficient than `.unpack_h()` as it allocates a new matrix. #[inline] - pub fn h(&self) -> MatrixN { + pub fn h(&self) -> OMatrix { let dim = self.hess.nrows(); let mut res = self.hess.clone(); - res.fill_lower_triangle(N::zero(), 2); + res.fill_lower_triangle(T::zero(), 2); res.slice_mut((1, 0), (dim - 1, dim - 1)) - .set_partial_diagonal(self.subdiag.iter().map(|e| N::from_real(e.modulus()))); + .set_partial_diagonal(self.subdiag.iter().map(|e| T::from_real(e.modulus()))); res } /// Computes the orthogonal matrix `Q` of this decomposition. - pub fn q(&self) -> MatrixN { + pub fn q(&self) -> OMatrix { householder::assemble_q(&self.hess, self.subdiag.as_slice()) } #[doc(hidden)] - pub fn hess_internal(&self) -> &MatrixN { + pub fn hess_internal(&self) -> &OMatrix { &self.hess } } diff --git a/src/linalg/householder.rs b/src/linalg/householder.rs index ebbffd30..fbb24e77 100644 --- a/src/linalg/householder.rs +++ b/src/linalg/householder.rs @@ -1,7 +1,7 @@ //! Construction of householder elementary reflections. use crate::allocator::Allocator; -use crate::base::{DefaultAllocator, MatrixMN, MatrixN, Unit, Vector, VectorN}; +use crate::base::{DefaultAllocator, OMatrix, OVector, Unit, Vector}; use crate::dimension::Dim; use crate::storage::{Storage, StorageMut}; use num::Zero; @@ -16,9 +16,9 @@ use crate::geometry::Reflection; /// `column` after reflection and `false` if no reflection was necessary. #[doc(hidden)] #[inline(always)] -pub fn reflection_axis_mut>( - column: &mut Vector, -) -> (N, bool) { +pub fn reflection_axis_mut>( + column: &mut Vector, +) -> (T, bool) { let reflection_sq_norm = column.norm_squared(); let reflection_norm = reflection_sq_norm.sqrt(); @@ -44,14 +44,14 @@ pub fn reflection_axis_mut>( /// Uses an householder reflection to zero out the `icol`-th column, starting with the `shift + 1`-th /// subdiagonal element. #[doc(hidden)] -pub fn clear_column_unchecked( - matrix: &mut MatrixMN, - diag_elt: &mut N, +pub fn clear_column_unchecked( + matrix: &mut OMatrix, + diag_elt: &mut T, icol: usize, shift: usize, - bilateral: Option<&mut VectorN>, + bilateral: Option<&mut OVector>, ) where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { let (mut left, mut right) = matrix.columns_range_pair_mut(icol, icol + 1..); let mut axis = left.rows_range_mut(icol + shift..); @@ -60,7 +60,7 @@ pub fn clear_column_unchecked( *diag_elt = reflection_norm; if not_zero { - let refl = Reflection::new(Unit::new_unchecked(axis), N::zero()); + let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let sign = reflection_norm.signum(); if let Some(mut work) = bilateral { refl.reflect_rows_with_sign(&mut right, &mut work, sign); @@ -72,15 +72,15 @@ pub fn clear_column_unchecked( /// Uses an householder reflection to zero out the `irow`-th row, ending before the `shift + 1`-th /// superdiagonal element. #[doc(hidden)] -pub fn clear_row_unchecked( - matrix: &mut MatrixMN, - diag_elt: &mut N, - axis_packed: &mut VectorN, - work: &mut VectorN, +pub fn clear_row_unchecked( + matrix: &mut OMatrix, + diag_elt: &mut T, + axis_packed: &mut OVector, + work: &mut OVector, irow: usize, shift: usize, ) where - DefaultAllocator: Allocator + Allocator + Allocator, + DefaultAllocator: Allocator + Allocator + Allocator, { let (mut top, mut bottom) = matrix.rows_range_pair_mut(irow, irow + 1..); let mut axis = axis_packed.rows_range_mut(irow + shift..); @@ -91,7 +91,7 @@ pub fn clear_row_unchecked( *diag_elt = reflection_norm; if not_zero { - let refl = Reflection::new(Unit::new_unchecked(axis), N::zero()); + let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); refl.reflect_rows_with_sign( &mut bottom.columns_range_mut(irow + shift..), &mut work.rows_range_mut(irow + 1..), @@ -108,20 +108,20 @@ pub fn clear_row_unchecked( /// the lower-diagonal element of the given matrix. /// matrices. #[doc(hidden)] -pub fn assemble_q(m: &MatrixN, signs: &[N]) -> MatrixN +pub fn assemble_q(m: &OMatrix, signs: &[T]) -> OMatrix where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { assert!(m.is_square()); let dim = m.data.shape().0; // NOTE: we could build the identity matrix and call p_mult on it. // Instead we don't so that we take in account the matrix sparseness. - let mut res = MatrixN::identity_generic(dim, dim); + let mut res = OMatrix::identity_generic(dim, dim); for i in (0..dim.value() - 1).rev() { let axis = m.slice_range(i + 1.., i); - let refl = Reflection::new(Unit::new_unchecked(axis), N::zero()); + let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let mut res_rows = res.slice_range_mut(i + 1.., i..); refl.reflect_with_sign(&mut res_rows, signs[i].signum()); diff --git a/src/linalg/inverse.rs b/src/linalg/inverse.rs index 2cb10351..f56a95ec 100644 --- a/src/linalg/inverse.rs +++ b/src/linalg/inverse.rs @@ -3,17 +3,17 @@ use simba::scalar::ComplexField; use crate::base::allocator::Allocator; use crate::base::dimension::Dim; use crate::base::storage::{Storage, StorageMut}; -use crate::base::{DefaultAllocator, MatrixN, SquareMatrix}; +use crate::base::{DefaultAllocator, OMatrix, SquareMatrix}; use crate::linalg::lu; -impl> SquareMatrix { +impl> SquareMatrix { /// Attempts to invert this matrix. #[inline] #[must_use = "Did you mean to use try_inverse_mut()?"] - pub fn try_inverse(self) -> Option> + pub fn try_inverse(self) -> Option> where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let mut me = self.into_owned(); if me.try_inverse_mut() { @@ -24,13 +24,13 @@ impl> SquareMatrix { } } -impl> SquareMatrix { +impl> SquareMatrix { /// Attempts to invert this matrix in-place. Returns `false` and leaves `self` untouched if /// inversion fails. #[inline] pub fn try_inverse_mut(&mut self) -> bool where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { assert!(self.is_square(), "Unable to invert a non-square matrix."); @@ -44,7 +44,7 @@ impl> SquareMatrix { if determinant.is_zero() { false } else { - *self.get_unchecked_mut((0, 0)) = N::one() / determinant; + *self.get_unchecked_mut((0, 0)) = T::one() / determinant; true } } @@ -120,12 +120,12 @@ impl> SquareMatrix { } // NOTE: this is an extremely efficient, loop-unrolled matrix inverse from MESA (MIT licensed). -fn do_inverse4>( - m: &MatrixN, - out: &mut SquareMatrix, +fn do_inverse4>( + m: &OMatrix, + out: &mut SquareMatrix, ) -> bool where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let m = m.data.as_slice(); @@ -212,7 +212,7 @@ where let det = m[0] * out[(0, 0)] + m[1] * out[(0, 1)] + m[2] * out[(0, 2)] + m[3] * out[(0, 3)]; if !det.is_zero() { - let inv_det = N::one() / det; + let inv_det = T::one() / det; for j in 0..4 { for i in 0..4 { diff --git a/src/linalg/lu.rs b/src/linalg/lu.rs index 9e417f10..c09a5b77 100644 --- a/src/linalg/lu.rs +++ b/src/linalg/lu.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::allocator::{Allocator, Reallocator}; -use crate::base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Scalar}; +use crate::base::{DefaultAllocator, Matrix, OMatrix, Scalar}; use crate::constraint::{SameNumberOfRows, ShapeConstraint}; use crate::dimension::{Dim, DimMin, DimMinimum}; use crate::storage::{Storage, StorageMut}; @@ -15,31 +15,31 @@ use crate::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, + OMatrix: 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>, + OMatrix: Deserialize<'de>, PermutationSequence>: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct LU, C: Dim> +pub struct LU, C: Dim> where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { - lu: MatrixMN, + lu: OMatrix, p: PermutationSequence>, } -impl, C: Dim> Copy for LU +impl, C: Dim> Copy for LU where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, - MatrixMN: Copy, + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + OMatrix: Copy, PermutationSequence>: Copy, { } @@ -47,13 +47,13 @@ where /// Performs a LU decomposition to overwrite `out` with the inverse of `matrix`. /// /// If `matrix` is not invertible, `false` is returned and `out` may contain invalid data. -pub fn try_invert_to( - mut matrix: MatrixN, - out: &mut Matrix, +pub fn try_invert_to( + mut matrix: OMatrix, + out: &mut Matrix, ) -> bool where - S: StorageMut, - DefaultAllocator: Allocator, + S: StorageMut, + DefaultAllocator: Allocator, { assert!( matrix.is_square(), @@ -80,16 +80,16 @@ where } } - let _ = matrix.solve_lower_triangular_with_diag_mut(out, N::one()); + let _ = matrix.solve_lower_triangular_with_diag_mut(out, T::one()); matrix.solve_upper_triangular_mut(out) } -impl, C: Dim> LU +impl, C: Dim> LU where - DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, + DefaultAllocator: Allocator + Allocator<(usize, usize), DimMinimum>, { /// Computes the LU decomposition with partial (row) pivoting of `matrix`. - pub fn new(mut matrix: MatrixMN) -> Self { + pub fn new(mut matrix: OMatrix) -> Self { let (nrows, ncols) = matrix.data.shape(); let min_nrows_ncols = nrows.min(ncols); @@ -121,20 +121,20 @@ where } #[doc(hidden)] - pub fn lu_internal(&self) -> &MatrixMN { + pub fn lu_internal(&self) -> &OMatrix { &self.lu } /// The lower triangular matrix of this decomposition. #[inline] - pub fn l(&self) -> MatrixMN> + pub fn l(&self) -> OMatrix> where - DefaultAllocator: Allocator>, + 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); - m.fill_diagonal(N::one()); + m.fill_upper_triangle(T::zero(), 1); + m.fill_diagonal(T::one()); m } @@ -142,37 +142,37 @@ where fn l_unpack_with_p( self, ) -> ( - MatrixMN>, + OMatrix>, PermutationSequence>, ) where - DefaultAllocator: Reallocator>, + 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); - m.fill_diagonal(N::one()); + let mut m = self.lu.resize_generic(nrows, nrows.min(ncols), T::zero()); + m.fill_upper_triangle(T::zero(), 1); + m.fill_diagonal(T::one()); (m, self.p) } /// The lower triangular matrix of this decomposition. #[inline] - pub fn l_unpack(self) -> MatrixMN> + pub fn l_unpack(self) -> OMatrix> where - DefaultAllocator: Reallocator>, + 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); - m.fill_diagonal(N::one()); + let mut m = self.lu.resize_generic(nrows, nrows.min(ncols), T::zero()); + m.fill_upper_triangle(T::zero(), 1); + m.fill_diagonal(T::one()); m } /// The upper triangular matrix of this decomposition. #[inline] - pub fn u(&self) -> MatrixMN, C> + pub fn u(&self) -> OMatrix, C> where - DefaultAllocator: Allocator, C>, + DefaultAllocator: Allocator, C>, { let (nrows, ncols) = self.lu.data.shape(); self.lu.rows_generic(0, nrows.min(ncols)).upper_triangle() @@ -190,13 +190,13 @@ where self, ) -> ( PermutationSequence>, - MatrixMN>, - MatrixMN, C>, + OMatrix>, + OMatrix, C>, ) where - DefaultAllocator: Allocator> - + Allocator, C> - + Reallocator>, + DefaultAllocator: Allocator> + + Allocator, C> + + Reallocator>, { // Use reallocation for either l or u. let u = self.u(); @@ -206,21 +206,21 @@ where } } -impl> LU +impl> LU where - DefaultAllocator: Allocator + Allocator<(usize, usize), D>, + DefaultAllocator: Allocator + Allocator<(usize, usize), D>, { /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. /// /// Returns `None` if `self` is not invertible. pub fn solve( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfRows, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let mut res = b.clone_owned(); if self.solve_mut(&mut res) { @@ -234,9 +234,9 @@ where /// /// If the decomposed matrix is not invertible, this returns `false` and its input `b` may /// be overwritten with garbage. - pub fn solve_mut(&self, b: &mut Matrix) -> bool + pub fn solve_mut(&self, b: &mut Matrix) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { assert_eq!( @@ -250,21 +250,21 @@ where ); self.p.permute_rows(b); - let _ = self.lu.solve_lower_triangular_with_diag_mut(b, N::one()); + let _ = self.lu.solve_lower_triangular_with_diag_mut(b, T::one()); self.lu.solve_upper_triangular_mut(b) } /// Computes the inverse of the decomposed matrix. /// /// Returns `None` if the matrix is not invertible. - pub fn try_inverse(&self) -> Option> { + pub fn try_inverse(&self) -> Option> { assert!( self.lu.is_square(), "LU inverse: unable to compute the inverse of a non-square matrix." ); let (nrows, ncols) = self.lu.data.shape(); - let mut res = MatrixN::identity_generic(nrows, ncols); + let mut res = OMatrix::identity_generic(nrows, ncols); if self.try_inverse_to(&mut res) { Some(res) } else { @@ -276,7 +276,7 @@ where /// /// If the decomposed matrix is not invertible, this returns `false` and `out` may be /// overwritten with garbage. - pub fn try_inverse_to>(&self, out: &mut Matrix) -> bool { + pub fn try_inverse_to>(&self, out: &mut Matrix) -> bool { assert!( self.lu.is_square(), "LU inverse: unable to compute the inverse of a non-square matrix." @@ -291,14 +291,14 @@ where } /// Computes the determinant of the decomposed matrix. - pub fn determinant(&self) -> N { + pub fn determinant(&self) -> T { let dim = self.lu.nrows(); assert!( self.lu.is_square(), "LU determinant: unable to compute the determinant of a non-square matrix." ); - let mut res = N::one(); + let mut res = T::one(); for i in 0..dim { res *= unsafe { *self.lu.get_unchecked((i, i)) }; } @@ -326,14 +326,14 @@ where #[doc(hidden)] /// Executes one step of gaussian elimination on the i-th row and column of `matrix`. The diagonal /// element `matrix[(i, i)]` is provided as argument. -pub fn gauss_step(matrix: &mut Matrix, diag: N, i: usize) +pub fn gauss_step(matrix: &mut Matrix, diag: T, i: usize) where - N: Scalar + Field, - S: StorageMut, + T: Scalar + Field, + S: StorageMut, { let mut submat = matrix.slice_range_mut(i.., i..); - let inv_diag = N::one() / diag; + let inv_diag = T::one() / diag; let (mut coeffs, mut submat) = submat.columns_range_pair_mut(0, 1..); @@ -344,26 +344,26 @@ where for k in 0..pivot_row.ncols() { down.column_mut(k) - .axpy(-pivot_row[k].inlined_clone(), &coeffs, N::one()); + .axpy(-pivot_row[k].inlined_clone(), &coeffs, T::one()); } } #[doc(hidden)] /// Swaps the rows `i` with the row `piv` and executes one step of gaussian elimination on the i-th /// row and column of `matrix`. The diagonal element `matrix[(i, i)]` is provided as argument. -pub fn gauss_step_swap( - matrix: &mut Matrix, - diag: N, +pub fn gauss_step_swap( + matrix: &mut Matrix, + diag: T, i: usize, piv: usize, ) where - N: Scalar + Field, - S: StorageMut, + T: Scalar + Field, + S: StorageMut, { let piv = piv - i; let mut submat = matrix.slice_range_mut(i.., i..); - let inv_diag = N::one() / diag; + let inv_diag = T::one() / diag; let (mut coeffs, mut submat) = submat.columns_range_pair_mut(0, 1..); @@ -376,6 +376,6 @@ pub fn gauss_step_swap( for k in 0..pivot_row.ncols() { mem::swap(&mut pivot_row[k], &mut down[(piv - 1, k)]); down.column_mut(k) - .axpy(-pivot_row[k].inlined_clone(), &coeffs, N::one()); + .axpy(-pivot_row[k].inlined_clone(), &coeffs, T::one()); } } diff --git a/src/linalg/permutation_sequence.rs b/src/linalg/permutation_sequence.rs index 47df3cfd..09aa4f90 100644 --- a/src/linalg/permutation_sequence.rs +++ b/src/linalg/permutation_sequence.rs @@ -5,7 +5,7 @@ use num::One; use simba::scalar::ClosedNeg; use crate::allocator::Allocator; -use crate::base::{DefaultAllocator, Matrix, Scalar, VectorN}; +use crate::base::{DefaultAllocator, Matrix, OVector, Scalar}; #[cfg(any(feature = "std", feature = "alloc"))] use crate::dimension::Dynamic; use crate::dimension::{Const, Dim, DimName}; @@ -16,12 +16,12 @@ use crate::storage::StorageMut; #[cfg_attr( feature = "serde-serialize", serde(bound(serialize = "DefaultAllocator: Allocator<(usize, usize), D>, - VectorN<(usize, usize), D>: Serialize")) + OVector<(usize, usize), D>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", serde(bound(deserialize = "DefaultAllocator: Allocator<(usize, usize), D>, - VectorN<(usize, usize), D>: Deserialize<'de>")) + OVector<(usize, usize), D>: Deserialize<'de>")) )] #[derive(Clone, Debug)] pub struct PermutationSequence @@ -29,13 +29,13 @@ where DefaultAllocator: Allocator<(usize, usize), D>, { len: usize, - ipiv: VectorN<(usize, usize), D>, + ipiv: OVector<(usize, usize), D>, } impl Copy for PermutationSequence where DefaultAllocator: Allocator<(usize, usize), D>, - VectorN<(usize, usize), D>: Copy, + OVector<(usize, usize), D>: Copy, { } @@ -93,9 +93,9 @@ where /// Applies this sequence of permutations to the rows of `rhs`. #[inline] - pub fn permute_rows(&self, rhs: &mut Matrix) + pub fn permute_rows(&self, rhs: &mut Matrix) where - S2: StorageMut, + S2: StorageMut, { for i in self.ipiv.rows_range(..self.len).iter() { rhs.swap_rows(i.0, i.1) @@ -104,9 +104,9 @@ where /// Applies this sequence of permutations in reverse to the rows of `rhs`. #[inline] - pub fn inv_permute_rows(&self, rhs: &mut Matrix) + pub fn inv_permute_rows(&self, rhs: &mut Matrix) where - S2: StorageMut, + S2: StorageMut, { for i in 0..self.len { let (i1, i2) = self.ipiv[self.len - i - 1]; @@ -116,9 +116,9 @@ where /// Applies this sequence of permutations to the columns of `rhs`. #[inline] - pub fn permute_columns(&self, rhs: &mut Matrix) + pub fn permute_columns(&self, rhs: &mut Matrix) where - S2: StorageMut, + S2: StorageMut, { for i in self.ipiv.rows_range(..self.len).iter() { rhs.swap_columns(i.0, i.1) @@ -127,11 +127,11 @@ where /// Applies this sequence of permutations in reverse to the columns of `rhs`. #[inline] - pub fn inv_permute_columns( + pub fn inv_permute_columns( &self, - rhs: &mut Matrix, + rhs: &mut Matrix, ) where - S2: StorageMut, + S2: StorageMut, { for i in 0..self.len { let (i1, i2) = self.ipiv[self.len - i - 1]; @@ -151,11 +151,11 @@ where /// The determinant of the matrix corresponding to this permutation. #[inline] - pub fn determinant(&self) -> N { + pub fn determinant(&self) -> T { if self.len % 2 == 0 { - N::one() + T::one() } else { - -N::one() + -T::one() } } } diff --git a/src/linalg/qr.rs b/src/linalg/qr.rs index 2314a478..a09842d0 100644 --- a/src/linalg/qr.rs +++ b/src/linalg/qr.rs @@ -3,7 +3,7 @@ use num::Zero; use serde::{Deserialize, Serialize}; use crate::allocator::{Allocator, Reallocator}; -use crate::base::{DefaultAllocator, Matrix, MatrixMN, MatrixN, Unit, VectorN}; +use crate::base::{DefaultAllocator, Matrix, OMatrix, OVector, Unit}; use crate::constraint::{SameNumberOfRows, ShapeConstraint}; use crate::dimension::{Const, Dim, DimMin, DimMinimum}; use crate::storage::{Storage, StorageMut}; @@ -16,41 +16,41 @@ use crate::linalg::householder; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "DefaultAllocator: Allocator + - Allocator>, - MatrixMN: Serialize, - VectorN>: Serialize")) + serde(bound(serialize = "DefaultAllocator: Allocator + + Allocator>, + OMatrix: Serialize, + OVector>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator + - Allocator>, - MatrixMN: Deserialize<'de>, - VectorN>: Deserialize<'de>")) + serde(bound(deserialize = "DefaultAllocator: Allocator + + Allocator>, + OMatrix: Deserialize<'de>, + OVector>: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct QR, C: Dim> +pub struct QR, C: Dim> where - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { - qr: MatrixMN, - diag: VectorN>, + qr: OMatrix, + diag: OVector>, } -impl, C: Dim> Copy for QR +impl, C: Dim> Copy for QR where - DefaultAllocator: Allocator + Allocator>, - MatrixMN: Copy, - VectorN>: Copy, + DefaultAllocator: Allocator + Allocator>, + OMatrix: Copy, + OVector>: Copy, { } -impl, C: Dim> QR +impl, C: Dim> QR where - DefaultAllocator: Allocator + Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator + Allocator>, { /// Computes the QR decomposition using householder reflections. - pub fn new(mut matrix: MatrixMN) -> Self { + pub fn new(mut matrix: OMatrix) -> Self { let (nrows, ncols) = matrix.data.shape(); let min_nrows_ncols = nrows.min(ncols); @@ -70,13 +70,13 @@ where /// Retrieves the upper trapezoidal submatrix `R` of this decomposition. #[inline] - pub fn r(&self) -> MatrixMN, C> + pub fn r(&self) -> OMatrix, C> where - DefaultAllocator: Allocator, C>, + DefaultAllocator: Allocator, C>, { let (nrows, ncols) = self.qr.data.shape(); let mut res = self.qr.rows_generic(0, nrows.min(ncols)).upper_triangle(); - res.set_partial_diagonal(self.diag.iter().map(|e| N::from_real(e.modulus()))); + res.set_partial_diagonal(self.diag.iter().map(|e| T::from_real(e.modulus()))); res } @@ -84,21 +84,21 @@ where /// /// This is usually faster than `r` but consumes `self`. #[inline] - pub fn unpack_r(self) -> MatrixMN, C> + pub fn unpack_r(self) -> OMatrix, C> where - DefaultAllocator: Reallocator, C>, + DefaultAllocator: Reallocator, C>, { let (nrows, ncols) = self.qr.data.shape(); - let mut res = self.qr.resize_generic(nrows.min(ncols), ncols, N::zero()); - res.fill_lower_triangle(N::zero(), 1); - res.set_partial_diagonal(self.diag.iter().map(|e| N::from_real(e.modulus()))); + let mut res = self.qr.resize_generic(nrows.min(ncols), ncols, T::zero()); + res.fill_lower_triangle(T::zero(), 1); + res.set_partial_diagonal(self.diag.iter().map(|e| T::from_real(e.modulus()))); res } /// Computes the orthogonal matrix `Q` of this decomposition. - pub fn q(&self) -> MatrixMN> + pub fn q(&self) -> OMatrix> where - DefaultAllocator: Allocator>, + DefaultAllocator: Allocator>, { let (nrows, ncols) = self.qr.data.shape(); @@ -110,7 +110,7 @@ where for i in (0..dim).rev() { let axis = self.qr.slice_range(i.., i); // TODO: sometimes, the axis might have a zero magnitude. - let refl = Reflection::new(Unit::new_unchecked(axis), N::zero()); + let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let mut res_rows = res.slice_range_mut(i.., i..); refl.reflect_with_sign(&mut res_rows, self.diag[i].signum()); @@ -123,33 +123,33 @@ where pub fn unpack( self, ) -> ( - MatrixMN>, - MatrixMN, C>, + OMatrix>, + OMatrix, C>, ) where DimMinimum: DimMin>, DefaultAllocator: - Allocator> + Reallocator, C>, + Allocator> + Reallocator, C>, { (self.q(), self.unpack_r()) } #[doc(hidden)] - pub fn qr_internal(&self) -> &MatrixMN { + pub fn qr_internal(&self) -> &OMatrix { &self.qr } /// Multiplies the provided matrix by the transpose of the `Q` matrix of this decomposition. - pub fn q_tr_mul(&self, rhs: &mut Matrix) + pub fn q_tr_mul(&self, rhs: &mut Matrix) // TODO: do we need a static constraint on the number of rows of rhs? where - S2: StorageMut, + S2: StorageMut, { let dim = self.diag.len(); for i in 0..dim { let axis = self.qr.slice_range(i.., i); - let refl = Reflection::new(Unit::new_unchecked(axis), N::zero()); + let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); let mut rhs_rows = rhs.rows_range_mut(i..); refl.reflect_with_sign(&mut rhs_rows, self.diag[i].signum().conjugate()); @@ -157,21 +157,21 @@ where } } -impl> QR +impl> QR where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// Solves the linear system `self * x = b`, where `x` is the unknown to be determined. /// /// Returns `None` if `self` is not invertible. pub fn solve( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, + S2: Storage, ShapeConstraint: SameNumberOfRows, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let mut res = b.clone_owned(); @@ -186,9 +186,9 @@ where /// /// If the decomposed matrix is not invertible, this returns `false` and its input `b` is /// overwritten with garbage. - pub fn solve_mut(&self, b: &mut Matrix) -> bool + pub fn solve_mut(&self, b: &mut Matrix) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { assert_eq!( @@ -208,10 +208,10 @@ where // TODO: duplicate code from the `solve` module. fn solve_upper_triangular_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let dim = self.qr.nrows(); @@ -233,7 +233,7 @@ where } b.rows_range_mut(..i) - .axpy(-coeff, &self.qr.slice_range(..i, i), N::one()); + .axpy(-coeff, &self.qr.slice_range(..i, i), T::one()); } } @@ -243,7 +243,7 @@ where /// Computes the inverse of the decomposed matrix. /// /// Returns `None` if the decomposed matrix is not invertible. - pub fn try_inverse(&self) -> Option> { + pub fn try_inverse(&self) -> Option> { assert!( self.qr.is_square(), "QR inverse: unable to compute the inverse of a non-square matrix." @@ -251,7 +251,7 @@ where // TODO: is there a less naive method ? let (nrows, ncols) = self.qr.data.shape(); - let mut res = MatrixN::identity_generic(nrows, ncols); + let mut res = OMatrix::identity_generic(nrows, ncols); if self.solve_mut(&mut res) { Some(res) @@ -277,11 +277,11 @@ where } // /// Computes the determinant of the decomposed matrix. - // pub fn determinant(&self) -> N { + // pub fn determinant(&self) -> T { // let dim = self.qr.nrows(); // assert!(self.qr.is_square(), "QR determinant: unable to compute the determinant of a non-square matrix."); - // let mut res = N::one(); + // let mut res = T::one(); // for i in 0 .. dim { // res *= unsafe { *self.diag.vget_unchecked(i) }; // } diff --git a/src/linalg/schur.rs b/src/linalg/schur.rs index c9a8f02d..1726ffc9 100644 --- a/src/linalg/schur.rs +++ b/src/linalg/schur.rs @@ -9,7 +9,7 @@ use std::cmp; use crate::allocator::Allocator; use crate::base::dimension::{Const, Dim, DimDiff, DimSub, Dynamic, U1, U2}; use crate::base::storage::Storage; -use crate::base::{DefaultAllocator, MatrixN, SquareMatrix, Unit, Vector2, Vector3, VectorN}; +use crate::base::{DefaultAllocator, OMatrix, OVector, SquareMatrix, Unit, Vector2, Vector3}; use crate::geometry::Reflection; use crate::linalg::givens::GivensRotation; @@ -22,41 +22,41 @@ use crate::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, + OMatrix: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator, - MatrixN: Deserialize<'de>")) + serde(bound(deserialize = "DefaultAllocator: Allocator, + OMatrix: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct Schur +pub struct Schur where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - q: MatrixN, - t: MatrixN, + q: OMatrix, + t: OMatrix, } -impl Copy for Schur +impl Copy for Schur where - DefaultAllocator: Allocator, - MatrixN: Copy, + DefaultAllocator: Allocator, + OMatrix: Copy, { } -impl Schur +impl Schur where D: DimSub, // For Hessenberg. - DefaultAllocator: Allocator> - + Allocator> - + Allocator - + Allocator, + DefaultAllocator: Allocator> + + Allocator> + + Allocator + + Allocator, { /// Computes the Schur decomposition of a square matrix. - pub fn new(m: MatrixN) -> Self { - Self::try_new(m, N::RealField::default_epsilon(), 0).unwrap() + pub fn new(m: OMatrix) -> Self { + Self::try_new(m, T::RealField::default_epsilon(), 0).unwrap() } /// Attempts to compute the Schur decomposition of a square matrix. @@ -70,7 +70,7 @@ where /// * `max_niter` − maximum total number of iterations performed by the algorithm. If this /// number of iteration is exceeded, `None` is returned. If `niter == 0`, then the algorithm /// continues indefinitely until convergence. - pub fn try_new(m: MatrixN, eps: N::RealField, max_niter: usize) -> Option { + pub fn try_new(m: OMatrix, eps: T::RealField, max_niter: usize) -> Option { let mut work = unsafe { crate::unimplemented_or_uninitialized_generic!(m.data.shape().0, Const::<1>) }; @@ -79,12 +79,12 @@ where } fn do_decompose( - mut m: MatrixN, - work: &mut VectorN, - eps: N::RealField, + mut m: OMatrix, + work: &mut OVector, + eps: T::RealField, max_niter: usize, compute_q: bool, - ) -> Option<(Option>, MatrixN)> { + ) -> Option<(Option>, OMatrix)> { assert!( m.is_square(), "Unable to compute the eigenvectors and eigenvalues of a non-square matrix." @@ -94,12 +94,12 @@ where // Specialization would make this easier. if dim.value() == 0 { - let vecs = Some(MatrixN::from_element_generic(dim, dim, N::zero())); - let vals = MatrixN::from_element_generic(dim, dim, N::zero()); + let vecs = Some(OMatrix::from_element_generic(dim, dim, T::zero())); + let vals = OMatrix::from_element_generic(dim, dim, T::zero()); return Some((vecs, vals)); } else if dim.value() == 1 { if compute_q { - let q = MatrixN::from_element_generic(dim, dim, N::one()); + let q = OMatrix::from_element_generic(dim, dim, T::one()); return Some((Some(q), m)); } else { return Some((None, m)); @@ -163,11 +163,11 @@ where if not_zero { if k > start { t[(k, k - 1)] = norm; - t[(k + 1, k - 1)] = N::zero(); - t[(k + 2, k - 1)] = N::zero(); + t[(k + 1, k - 1)] = T::zero(); + t[(k + 2, k - 1)] = T::zero(); } - let refl = Reflection::new(Unit::new_unchecked(axis), N::zero()); + let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); { let krows = cmp::min(k + 4, end + 1); @@ -202,10 +202,10 @@ where let (norm, not_zero) = householder::reflection_axis_mut(&mut axis); if not_zero { - let refl = Reflection::new(Unit::new_unchecked(axis), N::zero()); + let refl = Reflection::new(Unit::new_unchecked(axis), T::zero()); t[(m, m - 1)] = norm; - t[(n, m - 1)] = N::zero(); + t[(n, m - 1)] = T::zero(); { let mut work = work.rows_mut(0, end + 1); @@ -228,7 +228,7 @@ where } } else { // Decouple the 2x2 block if it has real eigenvalues. - if let Some(rot) = compute_2x2_basis(&t.fixed_slice::(start, start)) { + if let Some(rot) = compute_2x2_basis(&t.fixed_slice::<2, 2>(start, start)) { let inv_rot = rot.inverse(); inv_rot.rotate(&mut t.generic_slice_mut( (start, start), @@ -237,7 +237,7 @@ where rot.rotate_rows( &mut t.generic_slice_mut((0, start), (Dynamic::new(end + 1), Const::<2>)), ); - t[(end, start)] = N::zero(); + t[(end, start)] = T::zero(); if let Some(ref mut q) = q { rot.rotate_rows(&mut q.generic_slice_mut((0, start), (dim, Const::<2>))); @@ -269,7 +269,7 @@ where } /// Computes the eigenvalues of the decomposed matrix. - fn do_eigenvalues(t: &MatrixN, out: &mut VectorN) -> bool { + fn do_eigenvalues(t: &OMatrix, out: &mut OVector) -> bool { let dim = t.nrows(); let mut m = 0; @@ -293,10 +293,10 @@ where } /// Computes the complex eigenvalues of the decomposed matrix. - fn do_complex_eigenvalues(t: &MatrixN, out: &mut VectorN, D>) + fn do_complex_eigenvalues(t: &OMatrix, out: &mut OVector, D>) where - N: RealField, - DefaultAllocator: Allocator, D>, + T: RealField, + DefaultAllocator: Allocator, D>, { let dim = t.nrows(); let mut m = 0; @@ -305,7 +305,7 @@ where let n = m + 1; if t[(n, m)].is_zero() { - out[m] = NumComplex::new(t[(m, m)], N::zero()); + out[m] = NumComplex::new(t[(m, m)], T::zero()); m += 1; } else { // Solve the 2x2 eigenvalue subproblem. @@ -320,25 +320,25 @@ where // All 2x2 blocks have negative discriminant because we already decoupled those // with positive eigenvalues. - let sqrt_discr = NumComplex::new(N::zero(), (-discr).sqrt()); + let sqrt_discr = NumComplex::new(T::zero(), (-discr).sqrt()); let half_tra = (hnn + hmm) * crate::convert(0.5); - out[m] = NumComplex::new(half_tra, N::zero()) + sqrt_discr; - out[m + 1] = NumComplex::new(half_tra, N::zero()) - sqrt_discr; + out[m] = NumComplex::new(half_tra, T::zero()) + sqrt_discr; + out[m + 1] = NumComplex::new(half_tra, T::zero()) - sqrt_discr; m += 2; } } if m == dim - 1 { - out[m] = NumComplex::new(t[(m, m)], N::zero()); + out[m] = NumComplex::new(t[(m, m)], T::zero()); } } - fn delimit_subproblem(t: &mut MatrixN, eps: N::RealField, end: usize) -> (usize, usize) + fn delimit_subproblem(t: &mut OMatrix, eps: T::RealField, end: usize) -> (usize, usize) where D: DimSub, - DefaultAllocator: Allocator>, + DefaultAllocator: Allocator>, { let mut n = end; @@ -346,7 +346,7 @@ where let m = n - 1; if t[(n, m)].norm1() <= eps * (t[(n, n)].norm1() + t[(m, m)].norm1()) { - t[(n, m)] = N::zero(); + t[(n, m)] = T::zero(); } else { break; } @@ -366,7 +366,7 @@ where if off_diag.is_zero() || off_diag.norm1() <= eps * (t[(new_start, new_start)].norm1() + t[(m, m)].norm1()) { - t[(new_start, m)] = N::zero(); + t[(new_start, m)] = T::zero(); break; } @@ -378,16 +378,17 @@ where /// Retrieves the unitary matrix `Q` and the upper-quasitriangular matrix `T` such that the /// decomposed matrix equals `Q * T * Q.transpose()`. - pub fn unpack(self) -> (MatrixN, MatrixN) { + pub fn unpack(self) -> (OMatrix, OMatrix) { (self.q, self.t) } /// Computes the real eigenvalues of the decomposed matrix. /// /// Return `None` if some eigenvalues are complex. - pub fn eigenvalues(&self) -> Option> { - let mut out = - unsafe { crate::unimplemented_or_uninitialized_generic!(self.t.data.shape().0, Const::<1>) }; + pub fn eigenvalues(&self) -> Option> { + let mut out = unsafe { + crate::unimplemented_or_uninitialized_generic!(self.t.data.shape().0, Const::<1>) + }; if Self::do_eigenvalues(&self.t, &mut out) { Some(out) } else { @@ -396,40 +397,41 @@ where } /// Computes the complex eigenvalues of the decomposed matrix. - pub fn complex_eigenvalues(&self) -> VectorN, D> + pub fn complex_eigenvalues(&self) -> OVector, D> where - N: RealField, - DefaultAllocator: Allocator, D>, + T: RealField, + DefaultAllocator: Allocator, D>, { - let mut out = - unsafe { crate::unimplemented_or_uninitialized_generic!(self.t.data.shape().0, Const::<1>) }; + let mut out = unsafe { + crate::unimplemented_or_uninitialized_generic!(self.t.data.shape().0, Const::<1>) + }; Self::do_complex_eigenvalues(&self.t, &mut out); out } } -fn decompose_2x2( - mut m: MatrixN, +fn decompose_2x2( + mut m: OMatrix, compute_q: bool, -) -> Option<(Option>, MatrixN)> +) -> Option<(Option>, OMatrix)> where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { let dim = m.data.shape().0; let mut q = None; - match compute_2x2_basis(&m.fixed_slice::(0, 0)) { + match compute_2x2_basis(&m.fixed_slice::<2, 2>(0, 0)) { Some(rot) => { - let mut m = m.fixed_slice_mut::(0, 0); + let mut m = m.fixed_slice_mut::<2, 2>(0, 0); let inv_rot = rot.inverse(); inv_rot.rotate(&mut m); rot.rotate_rows(&mut m); - m[(1, 0)] = N::zero(); + m[(1, 0)] = T::zero(); if compute_q { // XXX: we have to build the matrix manually because // rot.to_rotation_matrix().unwrap() causes an ICE. - let c = N::from_real(rot.c()); - q = Some(MatrixN::from_column_slice_generic( + let c = T::from_real(rot.c()); + q = Some(OMatrix::from_column_slice_generic( dim, dim, &[c, rot.s(), -rot.s().conjugate(), c], @@ -438,7 +440,7 @@ where } None => { if compute_q { - q = Some(MatrixN::identity_generic(dim, dim)); + q = Some(OMatrix::identity_generic(dim, dim)); } } }; @@ -446,9 +448,9 @@ where Some((q, m)) } -fn compute_2x2_eigvals>( - m: &SquareMatrix, -) -> Option<(N, N)> { +fn compute_2x2_eigvals>( + m: &SquareMatrix, +) -> Option<(T, T)> { // Solve the 2x2 eigenvalue subproblem. let h00 = m[(0, 0)]; let h10 = m[(1, 0)]; @@ -472,9 +474,9 @@ fn compute_2x2_eigvals>( /// /// Returns `None` if the matrix has complex eigenvalues, or is upper-triangular. In both case, /// the basis is the identity. -fn compute_2x2_basis>( - m: &SquareMatrix, -) -> Option> { +fn compute_2x2_basis>( + m: &SquareMatrix, +) -> Option> { let h10 = m[(1, 0)]; if h10.is_zero() { @@ -498,29 +500,30 @@ fn compute_2x2_basis>( } } -impl> SquareMatrix +impl> SquareMatrix where D: DimSub, // For Hessenberg. - DefaultAllocator: Allocator> - + Allocator> - + Allocator - + Allocator, + DefaultAllocator: Allocator> + + Allocator> + + Allocator + + Allocator, { /// Computes the eigenvalues of this matrix. - pub fn eigenvalues(&self) -> Option> { + pub fn eigenvalues(&self) -> Option> { assert!( self.is_square(), "Unable to compute eigenvalues of a non-square matrix." ); - let mut work = - unsafe { crate::unimplemented_or_uninitialized_generic!(self.data.shape().0, Const::<1>) }; + let mut work = unsafe { + crate::unimplemented_or_uninitialized_generic!(self.data.shape().0, Const::<1>) + }; // Special case for 2x2 matrices. if self.nrows() == 2 { // TODO: can we avoid this slicing // (which is needed here just to transform D to U2)? - let me = self.fixed_slice::(0, 0); + let me = self.fixed_slice::<2, 2>(0, 0); return match compute_2x2_eigvals(&me) { Some((a, b)) => { work[0] = a; @@ -535,7 +538,7 @@ where let schur = Schur::do_decompose( self.clone_owned(), &mut work, - N::RealField::default_epsilon(), + T::RealField::default_epsilon(), 0, false, ) @@ -548,11 +551,11 @@ where } /// Computes the eigenvalues of this matrix. - pub fn complex_eigenvalues(&self) -> VectorN, D> + pub fn complex_eigenvalues(&self) -> OVector, D> // TODO: add balancing? where - N: RealField, - DefaultAllocator: Allocator, D>, + T: RealField, + DefaultAllocator: Allocator, D>, { let dim = self.data.shape().0; let mut work = unsafe { crate::unimplemented_or_uninitialized_generic!(dim, Const::<1>) }; @@ -560,7 +563,7 @@ where let schur = Schur::do_decompose( self.clone_owned(), &mut work, - N::default_epsilon(), + T::default_epsilon(), 0, false, ) diff --git a/src/linalg/solve.rs b/src/linalg/solve.rs index dddc5ecf..8fdab47e 100644 --- a/src/linalg/solve.rs +++ b/src/linalg/solve.rs @@ -5,19 +5,19 @@ use crate::base::allocator::Allocator; use crate::base::constraint::{SameNumberOfRows, ShapeConstraint}; use crate::base::dimension::{Dim, U1}; use crate::base::storage::{Storage, StorageMut}; -use crate::base::{DVectorSlice, DefaultAllocator, Matrix, MatrixMN, SquareMatrix, Vector}; +use crate::base::{DVectorSlice, DefaultAllocator, Matrix, OMatrix, SquareMatrix, Vector}; -impl> SquareMatrix { +impl> SquareMatrix { /// Computes the solution of the linear system `self . x = b` where `x` is the unknown and only /// the lower-triangular part of `self` (including the diagonal) is considered not-zero. #[inline] pub fn solve_lower_triangular( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -33,11 +33,11 @@ impl> SquareMatrix { #[inline] pub fn solve_upper_triangular( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -52,10 +52,10 @@ impl> SquareMatrix { /// lower-triangular part of `self` (including the diagonal) is considered not-zero. pub fn solve_lower_triangular_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let cols = b.ncols(); @@ -69,9 +69,9 @@ impl> SquareMatrix { true } - fn solve_lower_triangular_vector_mut(&self, b: &mut Vector) -> bool + fn solve_lower_triangular_vector_mut(&self, b: &mut Vector) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let dim = self.nrows(); @@ -91,7 +91,7 @@ impl> SquareMatrix { } b.rows_range_mut(i + 1..) - .axpy(-coeff, &self.slice_range(i + 1.., i), N::one()); + .axpy(-coeff, &self.slice_range(i + 1.., i), T::one()); } true @@ -103,11 +103,11 @@ impl> SquareMatrix { /// assumed to be equal to `diag`. Returns `false` and does not modify its inputs if `diag` is zero. pub fn solve_lower_triangular_with_diag_mut( &self, - b: &mut Matrix, - diag: N, + b: &mut Matrix, + diag: T, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { if diag.is_zero() { @@ -123,7 +123,7 @@ impl> SquareMatrix { for i in 0..dim - 1 { let coeff = unsafe { *bcol.vget_unchecked(i) } / diag; bcol.rows_range_mut(i + 1..) - .axpy(-coeff, &self.slice_range(i + 1.., i), N::one()); + .axpy(-coeff, &self.slice_range(i + 1.., i), T::one()); } } @@ -134,10 +134,10 @@ impl> SquareMatrix { /// upper-triangular part of `self` (including the diagonal) is considered not-zero. pub fn solve_upper_triangular_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let cols = b.ncols(); @@ -151,9 +151,9 @@ impl> SquareMatrix { true } - fn solve_upper_triangular_vector_mut(&self, b: &mut Vector) -> bool + fn solve_upper_triangular_vector_mut(&self, b: &mut Vector) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let dim = self.nrows(); @@ -173,7 +173,7 @@ impl> SquareMatrix { } b.rows_range_mut(..i) - .axpy(-coeff, &self.slice_range(..i, i), N::one()); + .axpy(-coeff, &self.slice_range(..i, i), T::one()); } true @@ -189,11 +189,11 @@ impl> SquareMatrix { #[inline] pub fn tr_solve_lower_triangular( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -209,11 +209,11 @@ impl> SquareMatrix { #[inline] pub fn tr_solve_upper_triangular( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -228,10 +228,10 @@ impl> SquareMatrix { /// lower-triangular part of `self` (including the diagonal) is considered not-zero. pub fn tr_solve_lower_triangular_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let cols = b.ncols(); @@ -253,10 +253,10 @@ impl> SquareMatrix { /// upper-triangular part of `self` (including the diagonal) is considered not-zero. pub fn tr_solve_upper_triangular_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let cols = b.ncols(); @@ -279,11 +279,11 @@ impl> SquareMatrix { #[inline] pub fn ad_solve_lower_triangular( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -299,11 +299,11 @@ impl> SquareMatrix { #[inline] pub fn ad_solve_upper_triangular( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -318,10 +318,10 @@ impl> SquareMatrix { /// lower-triangular part of `self` (including the diagonal) is considered not-zero. pub fn ad_solve_lower_triangular_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let cols = b.ncols(); @@ -343,10 +343,10 @@ impl> SquareMatrix { /// upper-triangular part of `self` (including the diagonal) is considered not-zero. pub fn ad_solve_upper_triangular_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let cols = b.ncols(); @@ -367,15 +367,15 @@ impl> SquareMatrix { #[inline(always)] fn xx_solve_lower_triangular_vector_mut( &self, - b: &mut Vector, - conjugate: impl Fn(N) -> N, + b: &mut Vector, + conjugate: impl Fn(T) -> T, dot: impl Fn( - &DVectorSlice, - &DVectorSlice, - ) -> N, + &DVectorSlice, + &DVectorSlice, + ) -> T, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let dim = self.nrows(); @@ -402,15 +402,15 @@ impl> SquareMatrix { #[inline(always)] fn xx_solve_upper_triangular_vector_mut( &self, - b: &mut Vector, - conjugate: impl Fn(N) -> N, + b: &mut Vector, + conjugate: impl Fn(T) -> T, dot: impl Fn( - &DVectorSlice, - &DVectorSlice, - ) -> N, + &DVectorSlice, + &DVectorSlice, + ) -> T, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let dim = self.nrows(); @@ -440,17 +440,17 @@ impl> SquareMatrix { * */ -impl> SquareMatrix { +impl> SquareMatrix { /// Computes the solution of the linear system `self . x = b` where `x` is the unknown and only /// the lower-triangular part of `self` (including the diagonal) is considered not-zero. #[inline] pub fn solve_lower_triangular_unchecked( &self, - b: &Matrix, - ) -> MatrixMN + b: &Matrix, + ) -> OMatrix where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -463,11 +463,11 @@ impl> SquareMatrix { #[inline] pub fn solve_upper_triangular_unchecked( &self, - b: &Matrix, - ) -> MatrixMN + b: &Matrix, + ) -> OMatrix where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -479,9 +479,9 @@ impl> SquareMatrix { /// lower-triangular part of `self` (including the diagonal) is considered not-zero. pub fn solve_lower_triangular_unchecked_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { for i in 0..b.ncols() { @@ -489,9 +489,9 @@ impl> SquareMatrix { } } - fn solve_lower_triangular_vector_unchecked_mut(&self, b: &mut Vector) + fn solve_lower_triangular_vector_unchecked_mut(&self, b: &mut Vector) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let dim = self.nrows(); @@ -506,7 +506,7 @@ impl> SquareMatrix { } b.rows_range_mut(i + 1..) - .axpy(-coeff, &self.slice_range(i + 1.., i), N::one()); + .axpy(-coeff, &self.slice_range(i + 1.., i), T::one()); } } @@ -516,10 +516,10 @@ impl> SquareMatrix { /// assumed to be equal to `diag`. Returns `false` and does not modify its inputs if `diag` is zero. pub fn solve_lower_triangular_with_diag_unchecked_mut( &self, - b: &mut Matrix, - diag: N, + b: &mut Matrix, + diag: T, ) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let dim = self.nrows(); @@ -531,7 +531,7 @@ impl> SquareMatrix { for i in 0..dim - 1 { let coeff = unsafe { *bcol.vget_unchecked(i) } / diag; bcol.rows_range_mut(i + 1..) - .axpy(-coeff, &self.slice_range(i + 1.., i), N::one()); + .axpy(-coeff, &self.slice_range(i + 1.., i), T::one()); } } } @@ -540,9 +540,9 @@ impl> SquareMatrix { /// upper-triangular part of `self` (including the diagonal) is considered not-zero. pub fn solve_upper_triangular_unchecked_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { for i in 0..b.ncols() { @@ -550,9 +550,9 @@ impl> SquareMatrix { } } - fn solve_upper_triangular_vector_unchecked_mut(&self, b: &mut Vector) + fn solve_upper_triangular_vector_unchecked_mut(&self, b: &mut Vector) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let dim = self.nrows(); @@ -567,7 +567,7 @@ impl> SquareMatrix { } b.rows_range_mut(..i) - .axpy(-coeff, &self.slice_range(..i, i), N::one()); + .axpy(-coeff, &self.slice_range(..i, i), T::one()); } } @@ -581,11 +581,11 @@ impl> SquareMatrix { #[inline] pub fn tr_solve_lower_triangular_unchecked( &self, - b: &Matrix, - ) -> MatrixMN + b: &Matrix, + ) -> OMatrix where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -598,11 +598,11 @@ impl> SquareMatrix { #[inline] pub fn tr_solve_upper_triangular_unchecked( &self, - b: &Matrix, - ) -> MatrixMN + b: &Matrix, + ) -> OMatrix where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -614,9 +614,9 @@ impl> SquareMatrix { /// lower-triangular part of `self` (including the diagonal) is considered not-zero. pub fn tr_solve_lower_triangular_unchecked_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { for i in 0..b.ncols() { @@ -632,9 +632,9 @@ impl> SquareMatrix { /// upper-triangular part of `self` (including the diagonal) is considered not-zero. pub fn tr_solve_upper_triangular_unchecked_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { for i in 0..b.ncols() { @@ -651,11 +651,11 @@ impl> SquareMatrix { #[inline] pub fn ad_solve_lower_triangular_unchecked( &self, - b: &Matrix, - ) -> MatrixMN + b: &Matrix, + ) -> OMatrix where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -668,11 +668,11 @@ impl> SquareMatrix { #[inline] pub fn ad_solve_upper_triangular_unchecked( &self, - b: &Matrix, - ) -> MatrixMN + b: &Matrix, + ) -> OMatrix where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut res = b.clone_owned(); @@ -684,9 +684,9 @@ impl> SquareMatrix { /// lower-triangular part of `self` (including the diagonal) is considered not-zero. pub fn ad_solve_lower_triangular_unchecked_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { for i in 0..b.ncols() { @@ -702,9 +702,9 @@ impl> SquareMatrix { /// upper-triangular part of `self` (including the diagonal) is considered not-zero. pub fn ad_solve_upper_triangular_unchecked_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { for i in 0..b.ncols() { @@ -719,14 +719,14 @@ impl> SquareMatrix { #[inline(always)] fn xx_solve_lower_triangular_vector_unchecked_mut( &self, - b: &mut Vector, - conjugate: impl Fn(N) -> N, + b: &mut Vector, + conjugate: impl Fn(T) -> T, dot: impl Fn( - &DVectorSlice, - &DVectorSlice, - ) -> N, + &DVectorSlice, + &DVectorSlice, + ) -> T, ) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let dim = self.nrows(); @@ -745,14 +745,14 @@ impl> SquareMatrix { #[inline(always)] fn xx_solve_upper_triangular_vector_unchecked_mut( &self, - b: &mut Vector, - conjugate: impl Fn(N) -> N, + b: &mut Vector, + conjugate: impl Fn(T) -> T, dot: impl Fn( - &DVectorSlice, - &DVectorSlice, - ) -> N, + &DVectorSlice, + &DVectorSlice, + ) -> T, ) where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { for i in 0..self.nrows() { diff --git a/src/linalg/svd.rs b/src/linalg/svd.rs index 1e942e69..b259ae95 100644 --- a/src/linalg/svd.rs +++ b/src/linalg/svd.rs @@ -5,9 +5,9 @@ use approx::AbsDiffEq; use num::{One, Zero}; use crate::allocator::Allocator; -use crate::base::{DefaultAllocator, Matrix, Matrix2x3, MatrixMN, Vector2, VectorN}; +use crate::base::{DefaultAllocator, Matrix, Matrix2x3, OMatrix, OVector, Vector2}; use crate::constraint::{SameNumberOfRows, ShapeConstraint}; -use crate::dimension::{Dim, DimDiff, DimMin, DimMinimum, DimSub, U1, U2}; +use crate::dimension::{Dim, DimDiff, DimMin, DimMinimum, DimSub, U1}; use crate::storage::Storage; use simba::scalar::{ComplexField, RealField}; @@ -20,71 +20,71 @@ use crate::linalg::Bidiagonal; #[cfg_attr( feature = "serde-serialize", serde(bound( - serialize = "DefaultAllocator: Allocator> + - Allocator, C> + - Allocator>, - MatrixMN>: Serialize, - MatrixMN, C>: Serialize, - VectorN>: Serialize" + serialize = "DefaultAllocator: Allocator> + + Allocator, C> + + Allocator>, + OMatrix>: Serialize, + OMatrix, C>: Serialize, + OVector>: Serialize" )) )] #[cfg_attr( feature = "serde-serialize", serde(bound( - deserialize = "DefaultAllocator: Allocator> + - Allocator, C> + - Allocator>, - MatrixMN>: Deserialize<'de>, - MatrixMN, C>: Deserialize<'de>, - VectorN>: Deserialize<'de>" + deserialize = "DefaultAllocator: Allocator> + + Allocator, C> + + Allocator>, + OMatrix>: Deserialize<'de>, + OMatrix, C>: Deserialize<'de>, + OVector>: Deserialize<'de>" )) )] #[derive(Clone, Debug)] -pub struct SVD, C: Dim> +pub struct SVD, C: Dim> where - DefaultAllocator: Allocator, C> - + Allocator> - + Allocator>, + DefaultAllocator: Allocator, C> + + Allocator> + + Allocator>, { /// The left-singular vectors `U` of this SVD. - pub u: Option>>, + pub u: Option>>, /// The right-singular vectors `V^t` of this SVD. - pub v_t: Option, C>>, + pub v_t: Option, C>>, /// The singular values of this SVD. - pub singular_values: VectorN>, + pub singular_values: OVector>, } -impl, C: Dim> Copy for SVD +impl, C: Dim> Copy for SVD where - DefaultAllocator: Allocator, C> - + Allocator> - + Allocator>, - MatrixMN>: Copy, - MatrixMN, C>: Copy, - VectorN>: Copy, + DefaultAllocator: Allocator, C> + + Allocator> + + Allocator>, + OMatrix>: Copy, + OMatrix, C>: Copy, + OVector>: Copy, { } -impl, C: Dim> SVD +impl, C: Dim> SVD where DimMinimum: DimSub, // for Bidiagonal. - DefaultAllocator: Allocator - + Allocator - + Allocator - + Allocator, U1>> - + Allocator, C> - + Allocator> - + Allocator> - + Allocator> - + Allocator, U1>>, + DefaultAllocator: Allocator + + Allocator + + Allocator + + Allocator, U1>> + + Allocator, C> + + Allocator> + + Allocator> + + Allocator> + + Allocator, U1>>, { /// Computes the Singular Value Decomposition of `matrix` using implicit shift. - pub fn new(matrix: MatrixMN, compute_u: bool, compute_v: bool) -> Self { + pub fn new(matrix: OMatrix, compute_u: bool, compute_v: bool) -> Self { Self::try_new( matrix, compute_u, compute_v, - N::RealField::default_epsilon(), + T::RealField::default_epsilon(), 0, ) .unwrap() @@ -101,10 +101,10 @@ where /// number of iteration is exceeded, `None` is returned. If `niter == 0`, then the algorithm /// continues indefinitely until convergence. pub fn try_new( - mut matrix: MatrixMN, + mut matrix: OMatrix, compute_u: bool, compute_v: bool, - eps: N::RealField, + eps: T::RealField, max_niter: usize, ) -> Option { assert!( @@ -166,7 +166,7 @@ where for k in start..n { let m12 = if k == n - 1 { - N::RealField::zero() + T::RealField::zero() } else { off_diagonal[k + 1] }; @@ -174,16 +174,16 @@ where let mut subm = Matrix2x3::new( diagonal[k], off_diagonal[k], - N::RealField::zero(), - N::RealField::zero(), + T::RealField::zero(), + T::RealField::zero(), diagonal[k + 1], m12, ); if let Some((rot1, norm1)) = GivensRotation::cancel_y(&vec) { rot1.inverse() - .rotate_rows(&mut subm.fixed_columns_mut::(0)); - let rot1 = GivensRotation::new_unchecked(rot1.c(), N::from_real(rot1.s())); + .rotate_rows(&mut subm.fixed_columns_mut::<2>(0)); + let rot1 = GivensRotation::new_unchecked(rot1.c(), T::from_real(rot1.s())); if k > start { // This is not the first iteration. @@ -195,26 +195,24 @@ where let (rot2, norm2) = GivensRotation::cancel_y(&v) .unwrap_or((GivensRotation::identity(), subm[(0, 0)])); - rot2.rotate(&mut subm.fixed_columns_mut::(1)); - let rot2 = GivensRotation::new_unchecked(rot2.c(), N::from_real(rot2.s())); + rot2.rotate(&mut subm.fixed_columns_mut::<2>(1)); + let rot2 = GivensRotation::new_unchecked(rot2.c(), T::from_real(rot2.s())); subm[(0, 0)] = norm2; if let Some(ref mut v_t) = v_t { if b.is_upper_diagonal() { - rot1.rotate(&mut v_t.fixed_rows_mut::(k)); + rot1.rotate(&mut v_t.fixed_rows_mut::<2>(k)); } else { - rot2.rotate(&mut v_t.fixed_rows_mut::(k)); + rot2.rotate(&mut v_t.fixed_rows_mut::<2>(k)); } } if let Some(ref mut u) = u { if b.is_upper_diagonal() { - rot2.inverse() - .rotate_rows(&mut u.fixed_columns_mut::(k)); + rot2.inverse().rotate_rows(&mut u.fixed_columns_mut::<2>(k)); } else { - rot1.inverse() - .rotate_rows(&mut u.fixed_columns_mut::(k)); + rot1.inverse().rotate_rows(&mut u.fixed_columns_mut::<2>(k)); } } @@ -241,12 +239,12 @@ where compute_u && b.is_upper_diagonal() || compute_v && !b.is_upper_diagonal(), compute_v && b.is_upper_diagonal() || compute_u && !b.is_upper_diagonal(), ); - let u2 = u2.map(|u2| GivensRotation::new_unchecked(u2.c(), N::from_real(u2.s()))); - let v2 = v2.map(|v2| GivensRotation::new_unchecked(v2.c(), N::from_real(v2.s()))); + let u2 = u2.map(|u2| GivensRotation::new_unchecked(u2.c(), T::from_real(u2.s()))); + let v2 = v2.map(|v2| GivensRotation::new_unchecked(v2.c(), T::from_real(v2.s()))); diagonal[start] = s[0]; diagonal[start + 1] = s[1]; - off_diagonal[start] = N::RealField::zero(); + off_diagonal[start] = T::RealField::zero(); if let Some(ref mut u) = u { let rot = if b.is_upper_diagonal() { @@ -254,7 +252,7 @@ where } else { v2.unwrap() }; - rot.rotate_rows(&mut u.fixed_columns_mut::(start)); + rot.rotate_rows(&mut u.fixed_columns_mut::<2>(start)); } if let Some(ref mut v_t) = v_t { @@ -263,7 +261,7 @@ where } else { u2.unwrap() }; - rot.inverse().rotate(&mut v_t.fixed_rows_mut::(start)); + rot.inverse().rotate(&mut v_t.fixed_rows_mut::<2>(start)); } end -= 1; @@ -294,7 +292,7 @@ where for i in 0..dim { let sval = diagonal[i]; - if sval < N::RealField::zero() { + if sval < T::RealField::zero() { diagonal[i] = -sval; if let Some(ref mut u) = u { @@ -311,7 +309,7 @@ where } /* - fn display_bidiag(b: &Bidiagonal, begin: usize, end: usize) { + fn display_bidiag(b: &Bidiagonal, begin: usize, end: usize) { for i in begin .. end { for k in begin .. i { print!(" "); @@ -326,13 +324,13 @@ where */ fn delimit_subproblem( - diagonal: &mut VectorN>, - off_diagonal: &mut VectorN, U1>>, - u: &mut Option>>, - v_t: &mut Option, C>>, + diagonal: &mut OVector>, + off_diagonal: &mut OVector, U1>>, + u: &mut Option>>, + v_t: &mut Option, C>>, is_upper_diagonal: bool, end: usize, - eps: N::RealField, + eps: T::RealField, ) -> (usize, usize) { let mut n = end; @@ -342,9 +340,9 @@ where if off_diagonal[m].is_zero() || off_diagonal[m].norm1() <= eps * (diagonal[n].norm1() + diagonal[m].norm1()) { - off_diagonal[m] = N::RealField::zero(); + off_diagonal[m] = T::RealField::zero(); } else if diagonal[m].norm1() <= eps { - diagonal[m] = N::RealField::zero(); + diagonal[m] = T::RealField::zero(); Self::cancel_horizontal_off_diagonal_elt( diagonal, off_diagonal, @@ -366,7 +364,7 @@ where ); } } else if diagonal[n].norm1() <= eps { - diagonal[n] = N::RealField::zero(); + diagonal[n] = T::RealField::zero(); Self::cancel_vertical_off_diagonal_elt( diagonal, off_diagonal, @@ -392,12 +390,12 @@ where if off_diagonal[m].norm1() <= eps * (diagonal[new_start].norm1() + diagonal[m].norm1()) { - off_diagonal[m] = N::RealField::zero(); + off_diagonal[m] = T::RealField::zero(); break; } // TODO: write a test that enters this case. else if diagonal[m].norm1() <= eps { - diagonal[m] = N::RealField::zero(); + diagonal[m] = T::RealField::zero(); Self::cancel_horizontal_off_diagonal_elt( diagonal, off_diagonal, @@ -429,29 +427,29 @@ where // Cancels the i-th off-diagonal element using givens rotations. fn cancel_horizontal_off_diagonal_elt( - diagonal: &mut VectorN>, - off_diagonal: &mut VectorN, U1>>, - u: &mut Option>>, - v_t: &mut Option, C>>, + diagonal: &mut OVector>, + off_diagonal: &mut OVector, U1>>, + u: &mut Option>>, + v_t: &mut Option, C>>, is_upper_diagonal: bool, i: usize, end: usize, ) { let mut v = Vector2::new(off_diagonal[i], diagonal[i + 1]); - off_diagonal[i] = N::RealField::zero(); + off_diagonal[i] = T::RealField::zero(); for k in i..end { if let Some((rot, norm)) = GivensRotation::cancel_x(&v) { - let rot = GivensRotation::new_unchecked(rot.c(), N::from_real(rot.s())); + let rot = GivensRotation::new_unchecked(rot.c(), T::from_real(rot.s())); diagonal[k + 1] = norm; if is_upper_diagonal { if let Some(ref mut u) = *u { rot.inverse() - .rotate_rows(&mut u.fixed_columns_with_step_mut::(i, k - i)); + .rotate_rows(&mut u.fixed_columns_with_step_mut::<2>(i, k - i)); } } else if let Some(ref mut v_t) = *v_t { - rot.rotate(&mut v_t.fixed_rows_with_step_mut::(i, k - i)); + rot.rotate(&mut v_t.fixed_rows_with_step_mut::<2>(i, k - i)); } if k + 1 != end { @@ -467,28 +465,28 @@ where // Cancels the i-th off-diagonal element using givens rotations. fn cancel_vertical_off_diagonal_elt( - diagonal: &mut VectorN>, - off_diagonal: &mut VectorN, U1>>, - u: &mut Option>>, - v_t: &mut Option, C>>, + diagonal: &mut OVector>, + off_diagonal: &mut OVector, U1>>, + u: &mut Option>>, + v_t: &mut Option, C>>, is_upper_diagonal: bool, i: usize, ) { let mut v = Vector2::new(diagonal[i], off_diagonal[i]); - off_diagonal[i] = N::RealField::zero(); + off_diagonal[i] = T::RealField::zero(); for k in (0..i + 1).rev() { if let Some((rot, norm)) = GivensRotation::cancel_y(&v) { - let rot = GivensRotation::new_unchecked(rot.c(), N::from_real(rot.s())); + let rot = GivensRotation::new_unchecked(rot.c(), T::from_real(rot.s())); diagonal[k] = norm; if is_upper_diagonal { if let Some(ref mut v_t) = *v_t { - rot.rotate(&mut v_t.fixed_rows_with_step_mut::(k, i - k)); + rot.rotate(&mut v_t.fixed_rows_with_step_mut::<2>(k, i - k)); } } else if let Some(ref mut u) = *u { rot.inverse() - .rotate_rows(&mut u.fixed_columns_with_step_mut::(k, i - k)); + .rotate_rows(&mut u.fixed_columns_with_step_mut::<2>(k, i - k)); } if k > 0 { @@ -504,9 +502,9 @@ where /// Computes the rank of the decomposed matrix, i.e., the number of singular values greater /// than `eps`. - pub fn rank(&self, eps: N::RealField) -> usize { + pub fn rank(&self, eps: T::RealField) -> usize { assert!( - eps >= N::RealField::zero(), + eps >= T::RealField::zero(), "SVD rank: the epsilon must be non-negative." ); self.singular_values.iter().filter(|e| **e > eps).count() @@ -517,7 +515,7 @@ where /// This is useful if some of the singular values have been manually modified. /// Returns `Err` if the right- and left- singular vectors have not been /// computed at construction-time. - pub fn recompose(self) -> Result, &'static str> { + pub fn recompose(self) -> Result, &'static str> { match (self.u, self.v_t) { (Some(mut u), Some(v_t)) => { for i in 0..self.singular_values.len() { @@ -537,20 +535,20 @@ where /// Any singular value smaller than `eps` is assumed to be zero. /// Returns `Err` if the right- and left- singular vectors have not /// been computed at construction-time. - pub fn pseudo_inverse(mut self, eps: N::RealField) -> Result, &'static str> + pub fn pseudo_inverse(mut self, eps: T::RealField) -> Result, &'static str> where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - if eps < N::RealField::zero() { + if eps < T::RealField::zero() { Err("SVD pseudo inverse: the epsilon must be non-negative.") } else { for i in 0..self.singular_values.len() { let val = self.singular_values[i]; if val > eps { - self.singular_values[i] = N::RealField::one() / val; + self.singular_values[i] = T::RealField::one() / val; } else { - self.singular_values[i] = N::RealField::zero(); + self.singular_values[i] = T::RealField::zero(); } } @@ -565,15 +563,15 @@ where // TODO: make this more generic wrt the storage types and the dimensions for `b`. pub fn solve( &self, - b: &Matrix, - eps: N::RealField, - ) -> Result, &'static str> + b: &Matrix, + eps: T::RealField, + ) -> Result, &'static str> where - S2: Storage, - DefaultAllocator: Allocator + Allocator, C2>, + S2: Storage, + DefaultAllocator: Allocator + Allocator, C2>, ShapeConstraint: SameNumberOfRows, { - if eps < N::RealField::zero() { + if eps < T::RealField::zero() { Err("SVD solve: the epsilon must be non-negative.") } else { match (&self.u, &self.v_t) { @@ -588,7 +586,7 @@ where if val > eps { col[i] = col[i].unscale(val); } else { - col[i] = N::zero(); + col[i] = T::zero(); } } } @@ -603,28 +601,28 @@ where } } -impl, C: Dim, S: Storage> Matrix +impl, C: Dim, S: Storage> Matrix where DimMinimum: DimSub, // for Bidiagonal. - DefaultAllocator: Allocator - + Allocator - + Allocator - + Allocator, U1>> - + Allocator, C> - + Allocator> - + Allocator> - + Allocator> - + Allocator, U1>>, + DefaultAllocator: Allocator + + Allocator + + Allocator + + Allocator, U1>> + + Allocator, C> + + Allocator> + + Allocator> + + Allocator> + + Allocator, U1>>, { /// Computes the singular values of this matrix. - pub fn singular_values(&self) -> VectorN> { + pub fn singular_values(&self) -> OVector> { SVD::new(self.clone_owned(), false, false).singular_values } /// Computes the rank of this matrix. /// /// All singular values below `eps` are considered equal to 0. - pub fn rank(&self, eps: N::RealField) -> usize { + pub fn rank(&self, eps: T::RealField) -> usize { let svd = SVD::new(self.clone_owned(), false, false); svd.rank(eps) } @@ -632,9 +630,9 @@ where /// Computes the pseudo-inverse of this matrix. /// /// All singular values below `eps` are considered equal to 0. - pub fn pseudo_inverse(self, eps: N::RealField) -> Result, &'static str> + pub fn pseudo_inverse(self, eps: T::RealField) -> Result, &'static str> where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { SVD::new(self.clone_owned(), true, true).pseudo_inverse(eps) } @@ -643,19 +641,19 @@ where // Explicit formulae inspired from the paper "Computing the Singular Values of 2-by-2 Complex // Matrices", Sanzheng Qiao and Xiaohong Wang. // http://www.cas.mcmaster.ca/sqrl/papers/sqrl5.pdf -fn compute_2x2_uptrig_svd( - m11: N, - m12: N, - m22: N, +fn compute_2x2_uptrig_svd( + m11: T, + m12: T, + m22: T, compute_u: bool, compute_v: bool, ) -> ( - Option>, - Vector2, - Option>, + Option>, + Vector2, + Option>, ) { - let two: N::RealField = crate::convert(2.0f64); - let half: N::RealField = crate::convert(0.5f64); + let two: T::RealField = crate::convert(2.0f64); + let half: T::RealField = crate::convert(0.5f64); let denom = (m11 + m22).hypot(m12) + (m11 - m22).hypot(m12); diff --git a/src/linalg/symmetric_eigen.rs b/src/linalg/symmetric_eigen.rs index d30c2f80..370df26e 100644 --- a/src/linalg/symmetric_eigen.rs +++ b/src/linalg/symmetric_eigen.rs @@ -5,8 +5,8 @@ use approx::AbsDiffEq; use num::Zero; use crate::allocator::Allocator; -use crate::base::{DefaultAllocator, Matrix2, MatrixN, SquareMatrix, Vector2, VectorN}; -use crate::dimension::{Dim, DimDiff, DimSub, U1, U2}; +use crate::base::{DefaultAllocator, Matrix2, OMatrix, OVector, SquareMatrix, Vector2}; +use crate::dimension::{Dim, DimDiff, DimSub, U1}; use crate::storage::Storage; use simba::scalar::ComplexField; @@ -17,51 +17,51 @@ use crate::linalg::SymmetricTridiagonal; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "DefaultAllocator: Allocator + - Allocator, - VectorN: Serialize, - MatrixN: Serialize")) + serde(bound(serialize = "DefaultAllocator: Allocator + + Allocator, + OVector: Serialize, + OMatrix: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator + - Allocator, - VectorN: Deserialize<'de>, - MatrixN: Deserialize<'de>")) + serde(bound(deserialize = "DefaultAllocator: Allocator + + Allocator, + OVector: Deserialize<'de>, + OMatrix: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct SymmetricEigen +pub struct SymmetricEigen where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// The eigenvectors of the decomposed matrix. - pub eigenvectors: MatrixN, + pub eigenvectors: OMatrix, /// The unsorted eigenvalues of the decomposed matrix. - pub eigenvalues: VectorN, + pub eigenvalues: OVector, } -impl Copy for SymmetricEigen +impl Copy for SymmetricEigen where - DefaultAllocator: Allocator + Allocator, - MatrixN: Copy, - VectorN: Copy, + DefaultAllocator: Allocator + Allocator, + OMatrix: Copy, + OVector: Copy, { } -impl SymmetricEigen +impl SymmetricEigen where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// Computes the eigendecomposition of the given symmetric matrix. /// /// Only the lower-triangular parts (including its diagonal) of `m` is read. - pub fn new(m: MatrixN) -> Self + pub fn new(m: OMatrix) -> Self where D: DimSub, - DefaultAllocator: Allocator> + Allocator>, + DefaultAllocator: Allocator> + Allocator>, { - Self::try_new(m, N::RealField::default_epsilon(), 0).unwrap() + Self::try_new(m, T::RealField::default_epsilon(), 0).unwrap() } /// Computes the eigendecomposition of the given symmetric matrix with user-specified @@ -75,10 +75,10 @@ where /// * `max_niter` − maximum total number of iterations performed by the algorithm. If this /// number of iteration is exceeded, `None` is returned. If `niter == 0`, then the algorithm /// continues indefinitely until convergence. - pub fn try_new(m: MatrixN, eps: N::RealField, max_niter: usize) -> Option + pub fn try_new(m: OMatrix, eps: T::RealField, max_niter: usize) -> Option where D: DimSub, - DefaultAllocator: Allocator> + Allocator>, + DefaultAllocator: Allocator> + Allocator>, { Self::do_decompose(m, true, eps, max_niter).map(|(vals, vecs)| SymmetricEigen { eigenvectors: vecs.unwrap(), @@ -87,14 +87,14 @@ where } fn do_decompose( - mut m: MatrixN, + mut m: OMatrix, eigenvectors: bool, - eps: N::RealField, + eps: T::RealField, max_niter: usize, - ) -> Option<(VectorN, Option>)> + ) -> Option<(OVector, Option>)> where D: DimSub, - DefaultAllocator: Allocator> + Allocator>, + DefaultAllocator: Allocator> + Allocator>, { assert!( m.is_square(), @@ -171,8 +171,8 @@ where } if let Some(ref mut q) = q { - let rot = GivensRotation::new_unchecked(rot.c(), N::from_real(rot.s())); - rot.inverse().rotate_rows(&mut q.fixed_columns_mut::(i)); + let rot = GivensRotation::new_unchecked(rot.c(), T::from_real(rot.s())); + rot.inverse().rotate_rows(&mut q.fixed_columns_mut::<2>(i)); } } else { break; @@ -197,8 +197,8 @@ where if let Some(ref mut q) = q { if let Some((rot, _)) = GivensRotation::try_new(basis.x, basis.y, eps) { - let rot = GivensRotation::new_unchecked(rot.c(), N::from_real(rot.s())); - rot.rotate_rows(&mut q.fixed_columns_mut::(start)); + let rot = GivensRotation::new_unchecked(rot.c(), T::from_real(rot.s())); + rot.rotate_rows(&mut q.fixed_columns_mut::<2>(start)); } } @@ -223,14 +223,14 @@ where } fn delimit_subproblem( - diag: &VectorN, - off_diag: &mut VectorN>, + diag: &OVector, + off_diag: &mut OVector>, end: usize, - eps: N::RealField, + eps: T::RealField, ) -> (usize, usize) where D: DimSub, - DefaultAllocator: Allocator>, + DefaultAllocator: Allocator>, { let mut n = end; @@ -255,7 +255,7 @@ where if off_diag[m].is_zero() || off_diag[m].norm1() <= eps * (diag[new_start].norm1() + diag[m].norm1()) { - off_diag[m] = N::RealField::zero(); + off_diag[m] = T::RealField::zero(); break; } @@ -268,7 +268,7 @@ where /// Rebuild the original matrix. /// /// This is useful if some of the eigenvalues have been manually modified. - pub fn recompose(&self) -> MatrixN { + pub fn recompose(&self) -> OMatrix { let mut u_t = self.eigenvectors.clone(); for i in 0..self.eigenvalues.len() { let val = self.eigenvalues[i]; @@ -285,7 +285,7 @@ where /// The inputs are interpreted as the 2x2 matrix: /// tmm tmn /// tmn tnn -pub fn wilkinson_shift(tmm: N, tnn: N, tmn: N) -> N { +pub fn wilkinson_shift(tmm: T, tnn: T, tmn: T) -> T { let sq_tmn = tmn * tmn; if !sq_tmn.is_zero() { // We have the guarantee that the denominator won't be zero. @@ -301,21 +301,21 @@ pub fn wilkinson_shift(tmm: N, tnn: N, tmn: N) -> N { * Computations of eigenvalues for symmetric matrices. * */ -impl, S: Storage> SquareMatrix +impl, S: Storage> SquareMatrix where - DefaultAllocator: Allocator - + Allocator> - + Allocator - + Allocator>, + DefaultAllocator: Allocator + + Allocator> + + Allocator + + Allocator>, { /// Computes the eigenvalues of this symmetric matrix. /// /// Only the lower-triangular part of the matrix is read. - pub fn symmetric_eigenvalues(&self) -> VectorN { + pub fn symmetric_eigenvalues(&self) -> OVector { SymmetricEigen::do_decompose( self.clone_owned(), false, - N::RealField::default_epsilon(), + T::RealField::default_epsilon(), 0, ) .unwrap() diff --git a/src/linalg/symmetric_tridiagonal.rs b/src/linalg/symmetric_tridiagonal.rs index e0416d66..4e70b59b 100644 --- a/src/linalg/symmetric_tridiagonal.rs +++ b/src/linalg/symmetric_tridiagonal.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::allocator::Allocator; -use crate::base::{DefaultAllocator, MatrixN, VectorN}; +use crate::base::{DefaultAllocator, OMatrix, OVector}; use crate::dimension::{Const, DimDiff, DimSub, U1}; use crate::storage::Storage; use simba::scalar::ComplexField; @@ -13,43 +13,43 @@ use crate::linalg::householder; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "DefaultAllocator: Allocator + - Allocator>, - MatrixN: Serialize, - VectorN>: Serialize")) + serde(bound(serialize = "DefaultAllocator: Allocator + + Allocator>, + OMatrix: Serialize, + OVector>: Serialize")) )] #[cfg_attr( feature = "serde-serialize", - serde(bound(deserialize = "DefaultAllocator: Allocator + - Allocator>, - MatrixN: Deserialize<'de>, - VectorN>: Deserialize<'de>")) + serde(bound(deserialize = "DefaultAllocator: Allocator + + Allocator>, + OMatrix: Deserialize<'de>, + OVector>: Deserialize<'de>")) )] #[derive(Clone, Debug)] -pub struct SymmetricTridiagonal> +pub struct SymmetricTridiagonal> where - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { - tri: MatrixN, - off_diagonal: VectorN>, + tri: OMatrix, + off_diagonal: OVector>, } -impl> Copy for SymmetricTridiagonal +impl> Copy for SymmetricTridiagonal where - DefaultAllocator: Allocator + Allocator>, - MatrixN: Copy, - VectorN>: Copy, + DefaultAllocator: Allocator + Allocator>, + OMatrix: Copy, + OVector>: Copy, { } -impl> SymmetricTridiagonal +impl> SymmetricTridiagonal where - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { /// Computes the tridiagonalization of the symmetric matrix `m`. /// /// Only the lower-triangular part (including the diagonal) of `m` is read. - pub fn new(mut m: MatrixN) -> Self { + pub fn new(mut m: OMatrix) -> Self { let dim = m.data.shape().0; assert!( @@ -78,12 +78,12 @@ where if not_zero { let mut p = p.rows_range_mut(i..); - p.hegemv(crate::convert(2.0), &m, &axis, N::zero()); + p.hegemv(crate::convert(2.0), &m, &axis, T::zero()); let dot = axis.dotc(&p); - m.hegerc(-N::one(), &p, &axis, N::one()); - m.hegerc(-N::one(), &axis, &p, N::one()); - m.hegerc(dot * crate::convert(2.0), &axis, &axis, N::one()); + m.hegerc(-T::one(), &p, &axis, T::one()); + m.hegerc(-T::one(), &axis, &p, T::one()); + m.hegerc(dot * crate::convert(2.0), &axis, &axis, T::one()); } } @@ -95,7 +95,7 @@ where #[doc(hidden)] // For debugging. - pub fn internal_tri(&self) -> &MatrixN { + pub fn internal_tri(&self) -> &OMatrix { &self.tri } @@ -104,61 +104,61 @@ where pub fn unpack( self, ) -> ( - MatrixN, - VectorN, - VectorN>, + OMatrix, + OVector, + OVector>, ) where - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { let diag = self.diagonal(); let q = self.q(); - (q, diag, self.off_diagonal.map(N::modulus)) + (q, diag, self.off_diagonal.map(T::modulus)) } /// Retrieve the diagonal, and off diagonal elements of this decomposition. pub fn unpack_tridiagonal( self, ) -> ( - VectorN, - VectorN>, + OVector, + OVector>, ) where - DefaultAllocator: Allocator + Allocator>, + DefaultAllocator: Allocator + Allocator>, { - (self.diagonal(), self.off_diagonal.map(N::modulus)) + (self.diagonal(), self.off_diagonal.map(T::modulus)) } /// The diagonal components of this decomposition. - pub fn diagonal(&self) -> VectorN + pub fn diagonal(&self) -> OVector where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { self.tri.map_diagonal(|e| e.real()) } /// The off-diagonal components of this decomposition. - pub fn off_diagonal(&self) -> VectorN> + pub fn off_diagonal(&self) -> OVector> where - DefaultAllocator: Allocator>, + DefaultAllocator: Allocator>, { - self.off_diagonal.map(N::modulus) + self.off_diagonal.map(T::modulus) } /// Computes the orthogonal matrix `Q` of this decomposition. - pub fn q(&self) -> MatrixN { + pub fn q(&self) -> OMatrix { householder::assemble_q(&self.tri, self.off_diagonal.as_slice()) } /// Recomputes the original symmetric matrix. - pub fn recompose(mut self) -> MatrixN { + pub fn recompose(mut self) -> OMatrix { let q = self.q(); - self.tri.fill_lower_triangle(N::zero(), 2); - self.tri.fill_upper_triangle(N::zero(), 2); + self.tri.fill_lower_triangle(T::zero(), 2); + self.tri.fill_upper_triangle(T::zero(), 2); for i in 0..self.off_diagonal.len() { - let val = N::from_real(self.off_diagonal[i].modulus()); + let val = T::from_real(self.off_diagonal[i].modulus()); self.tri[(i + 1, i)] = val; self.tri[(i, i + 1)] = val; } diff --git a/src/linalg/udu.rs b/src/linalg/udu.rs index b3ea5ff9..de3cd2e3 100644 --- a/src/linalg/udu.rs +++ b/src/linalg/udu.rs @@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize}; use crate::allocator::Allocator; -use crate::base::{Const, DefaultAllocator, MatrixN, VectorN}; +use crate::base::{Const, DefaultAllocator, OMatrix, OVector}; use crate::dimension::Dim; use crate::storage::Storage; use simba::scalar::RealField; @@ -11,36 +11,36 @@ use simba::scalar::RealField; #[cfg_attr(feature = "serde-serialize", derive(Serialize, Deserialize))] #[cfg_attr( feature = "serde-serialize", - serde(bound(serialize = "VectorN: Serialize, MatrixN: Serialize")) + serde(bound(serialize = "OVector: Serialize, OMatrix: Serialize")) )] #[cfg_attr( feature = "serde-serialize", serde(bound( - deserialize = "VectorN: Deserialize<'de>, MatrixN: Deserialize<'de>" + deserialize = "OVector: Deserialize<'de>, OMatrix: Deserialize<'de>" )) )] #[derive(Clone, Debug)] -pub struct UDU +pub struct UDU where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// The upper triangular matrix resulting from the factorization - pub u: MatrixN, + pub u: OMatrix, /// The diagonal matrix resulting from the factorization - pub d: VectorN, + pub d: OVector, } -impl Copy for UDU +impl Copy for UDU where - DefaultAllocator: Allocator + Allocator, - VectorN: Copy, - MatrixN: Copy, + DefaultAllocator: Allocator + Allocator, + OVector: Copy, + OMatrix: Copy, { } -impl UDU +impl UDU where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// Computes the UDU^T factorization. /// @@ -48,12 +48,12 @@ where /// the upper-triangular part of `p`. /// /// Ref.: "Optimal control and estimation-Dover Publications", Robert F. Stengel, (1994) page 360 - pub fn new(p: MatrixN) -> Option { + pub fn new(p: OMatrix) -> Option { let n = p.ncols(); let n_dim = p.data.shape().1; - let mut d = VectorN::zeros_generic(n_dim, Const::<1>); - let mut u = MatrixN::zeros_generic(n_dim, n_dim); + let mut d = OVector::zeros_generic(n_dim, Const::<1>); + let mut u = OMatrix::zeros_generic(n_dim, n_dim); d[n - 1] = p[(n - 1, n - 1)]; @@ -62,7 +62,7 @@ where } u.column_mut(n - 1) - .axpy(N::one() / d[n - 1], &p.column(n - 1), N::zero()); + .axpy(T::one() / d[n - 1], &p.column(n - 1), T::zero()); for j in (0..n - 1).rev() { let mut d_j = d[j]; @@ -85,14 +85,14 @@ where u[(i, j)] = (p[(i, j)] - u_ij) / d[j]; } - u[(j, j)] = N::one(); + u[(j, j)] = T::one(); } Some(Self { u, d }) } /// Returns the diagonal elements as a matrix - pub fn d_matrix(&self) -> MatrixN { - MatrixN::from_diagonal(&self.d) + pub fn d_matrix(&self) -> OMatrix { + OMatrix::from_diagonal(&self.d) } } diff --git a/src/proptest/mod.rs b/src/proptest/mod.rs index 2551aa3d..d85cd6a2 100644 --- a/src/proptest/mod.rs +++ b/src/proptest/mod.rs @@ -18,7 +18,7 @@ //! //! - Using the [matrix](fn.matrix.html) function to generate matrices with constraints //! on dimensions and elements. -//! - Relying on the `Arbitrary` implementation of `MatrixMN`. +//! - Relying on the `Arbitrary` implementation of `OMatrix`. //! //! The first variant is almost always preferred in practice. Read on to discover why. //! @@ -53,11 +53,11 @@ //! with [matrix](fn.matrix.html) as follows: //! //! ```rust -//! use nalgebra::{Dynamic, MatrixMN, Const}; +//! use nalgebra::{Dynamic, OMatrix, Const}; //! use nalgebra::proptest::matrix; //! use proptest::prelude::*; //! -//! type MyMatrix = MatrixMN, Dynamic>; +//! type MyMatrix = OMatrix, Dynamic>; //! //! /// Returns a strategy for pairs of matrices with `U3` rows and the same number of //! /// columns. @@ -93,7 +93,7 @@ //! If you don't care about the dimensions of matrices, you can write tests like these: //! //! ```rust -//! use nalgebra::{DMatrix, DVector, Dynamic, Matrix3, MatrixMN, Vector3, U3}; +//! use nalgebra::{DMatrix, DVector, Dynamic, Matrix3, OMatrix, Vector3, U3}; //! use proptest::prelude::*; //! //! proptest! { @@ -108,7 +108,7 @@ //! # /* //! #[test] //! # */ -//! fn test_static_and_mixed(matrix: Matrix3, matrix2: MatrixMN) { +//! fn test_static_and_mixed(matrix: Matrix3, matrix2: OMatrix) { //! // Test some property involving these matrices //! } //! @@ -141,7 +141,7 @@ //! PROPTEST_MAX_SHRINK_ITERS=100000 cargo test my_failing_test //! ``` use crate::allocator::Allocator; -use crate::{Const, DefaultAllocator, Dim, DimName, Dynamic, MatrixMN, Scalar, U1}; +use crate::{Const, DefaultAllocator, Dim, DimName, Dynamic, OMatrix, Scalar, U1}; use proptest::arbitrary::Arbitrary; use proptest::collection::vec; use proptest::strategy::{BoxedStrategy, Just, NewTree, Strategy, ValueTree}; @@ -225,7 +225,7 @@ fn dynamic_dim_range() -> DimRange { /// ## Examples /// ``` /// use nalgebra::proptest::matrix; -/// use nalgebra::{MatrixMN, Const, Dynamic}; +/// use nalgebra::{OMatrix, Const, Dynamic}; /// use proptest::prelude::*; /// /// proptest! { @@ -234,7 +234,7 @@ fn dynamic_dim_range() -> DimRange { /// # */ /// fn my_test(a in matrix(0 .. 5i32, Const::<3>, 0 ..= 5)) { /// // Let's make sure we've got the correct type first -/// let a: MatrixMN<_, Const::<3>, Dynamic> = a; +/// let a: OMatrix<_, Const::<3>, Dynamic> = a; /// prop_assert!(a.nrows() == 3); /// prop_assert!(a.ncols() <= 5); /// prop_assert!(a.iter().all(|x_ij| *x_ij >= 0 && *x_ij < 5)); @@ -305,7 +305,7 @@ where // Note: R/C::from_usize will panic if nrows/ncols does not fit in the dimension type. // However, this should never fail, because we should only be generating // this stuff in the first place - MatrixMN::from_iterator_generic(R::from_usize(nrows), C::from_usize(ncols), values) + OMatrix::from_iterator_generic(R::from_usize(nrows), C::from_usize(ncols), values) }) .boxed(); @@ -388,23 +388,23 @@ where } } -impl Arbitrary for MatrixMN +impl Arbitrary for OMatrix where - N: Scalar + Arbitrary, - ::Strategy: Clone, + T: Scalar + Arbitrary, + ::Strategy: Clone, R: Dim, C: Dim, - MatrixParameters: Default, - DefaultAllocator: Allocator, + MatrixParameters: Default, + DefaultAllocator: Allocator, { - type Parameters = MatrixParameters; + type Parameters = MatrixParameters; fn arbitrary_with(args: Self::Parameters) -> Self::Strategy { - let value_strategy = N::arbitrary_with(args.value_parameters); + let value_strategy = T::arbitrary_with(args.value_parameters); matrix(value_strategy, args.rows, args.cols) } - type Strategy = MatrixStrategy; + type Strategy = MatrixStrategy; } /// A strategy for generating matrices. @@ -418,7 +418,7 @@ where // For now we only internally hold a boxed strategy. The reason for introducing this // separate wrapper struct is so that we can replace the strategy logic with custom logic // later down the road without introducing significant breaking changes - strategy: BoxedStrategy>, + strategy: BoxedStrategy>, } impl Strategy for MatrixStrategy @@ -430,7 +430,7 @@ where DefaultAllocator: Allocator, { type Tree = MatrixValueTree; - type Value = MatrixMN; + type Value = OMatrix; fn new_tree(&self, runner: &mut TestRunner) -> NewTree { let underlying_tree = self.strategy.new_tree(runner)?; @@ -441,26 +441,26 @@ where } /// A value tree for matrices. -pub struct MatrixValueTree +pub struct MatrixValueTree where - N: Scalar, + T: Scalar, R: Dim, C: Dim, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { // For now we only wrap a boxed value tree. The reason for wrapping is that this allows us // to swap out the value tree logic down the road without significant breaking changes. - value_tree: Box>>, + value_tree: Box>>, } -impl ValueTree for MatrixValueTree +impl ValueTree for MatrixValueTree where - N: Scalar, + T: Scalar, R: Dim, C: Dim, - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { - type Value = MatrixMN; + type Value = OMatrix; fn current(&self) -> Self::Value { self.value_tree.current() diff --git a/src/sparse/cs_matrix.rs b/src/sparse/cs_matrix.rs index a1879312..c4a0c901 100644 --- a/src/sparse/cs_matrix.rs +++ b/src/sparse/cs_matrix.rs @@ -7,24 +7,24 @@ use std::slice; use crate::allocator::Allocator; use crate::sparse::cs_utils; -use crate::{Const, DefaultAllocator, Dim, Dynamic, Scalar, Vector, VectorN, U1}; +use crate::{Const, DefaultAllocator, Dim, Dynamic, OVector, Scalar, Vector, U1}; -pub struct ColumnEntries<'a, N> { +pub struct ColumnEntries<'a, T> { curr: usize, i: &'a [usize], - v: &'a [N], + v: &'a [T], } -impl<'a, N> ColumnEntries<'a, N> { +impl<'a, T> ColumnEntries<'a, T> { #[inline] - pub fn new(i: &'a [usize], v: &'a [N]) -> Self { + pub fn new(i: &'a [usize], v: &'a [T]) -> Self { assert_eq!(i.len(), v.len()); Self { curr: 0, i, v } } } -impl<'a, N: Clone> Iterator for ColumnEntries<'a, N> { - type Item = (usize, N); +impl<'a, T: Clone> Iterator for ColumnEntries<'a, T> { + type Item = (usize, T); #[inline] fn next(&mut self) -> Option { @@ -45,11 +45,11 @@ impl<'a, N: Clone> Iterator for ColumnEntries<'a, N> { // TODO: this structure exists for now only because impl trait // cannot be used for trait method return types. /// Trait for iterable compressed-column matrix storage. -pub trait CsStorageIter<'a, N, R, C = U1> { +pub trait CsStorageIter<'a, T, R, C = U1> { /// Iterator through all the rows of a specific columns. /// /// The elements are given as a tuple (row_index, value). - type ColumnEntries: Iterator; + type ColumnEntries: Iterator; /// Iterator through the row indices of a specific column. type ColumnRowIndices: Iterator; @@ -60,13 +60,13 @@ pub trait CsStorageIter<'a, N, R, C = U1> { } /// Trait for mutably iterable compressed-column sparse matrix storage. -pub trait CsStorageIterMut<'a, N: 'a, R, C = U1> { +pub trait CsStorageIterMut<'a, T: 'a, R, C = U1> { /// Mutable iterator through all the values of the sparse matrix. - type ValuesMut: Iterator; + type ValuesMut: Iterator; /// Mutable iterator through all the rows of a specific columns. /// /// The elements are given as a tuple (row_index, value). - type ColumnEntriesMut: Iterator; + type ColumnEntriesMut: Iterator; /// A mutable iterator through the values buffer of the sparse matrix. fn values_mut(&'a mut self) -> Self::ValuesMut; @@ -75,7 +75,7 @@ pub trait CsStorageIterMut<'a, N: 'a, R, C = U1> { } /// Trait for compressed column sparse matrix storage. -pub trait CsStorage: for<'a> CsStorageIter<'a, N, R, C> { +pub trait CsStorage: for<'a> CsStorageIter<'a, T, R, C> { /// The shape of the stored matrix. fn shape(&self) -> (R, C); /// Retrieve the i-th row index of the underlying row index buffer. @@ -85,9 +85,9 @@ pub trait CsStorage: for<'a> CsStorageIter<'a, N, R, C> { /// The i-th value on the contiguous value buffer of this storage. /// /// No bound-checking is performed. - unsafe fn get_value_unchecked(&self, i: usize) -> &N; + unsafe fn get_value_unchecked(&self, i: usize) -> &T; /// The i-th value on the contiguous value buffer of this storage. - fn get_value(&self, i: usize) -> &N; + fn get_value(&self, i: usize) -> &T; /// Retrieve the i-th row index of the underlying row index buffer. fn row_index(&self, i: usize) -> usize; /// The value indices for the `i`-th column. @@ -97,29 +97,29 @@ pub trait CsStorage: for<'a> CsStorageIter<'a, N, R, C> { } /// Trait for compressed column sparse matrix mutable storage. -pub trait CsStorageMut: - CsStorage + for<'a> CsStorageIterMut<'a, N, R, C> +pub trait CsStorageMut: + CsStorage + for<'a> CsStorageIterMut<'a, T, R, C> { } /// A storage of column-compressed sparse matrix based on a Vec. #[derive(Clone, Debug, PartialEq)] -pub struct CsVecStorage +pub struct CsVecStorage where DefaultAllocator: Allocator, { pub(crate) shape: (R, C), - pub(crate) p: VectorN, + pub(crate) p: OVector, pub(crate) i: Vec, - pub(crate) vals: Vec, + pub(crate) vals: Vec, } -impl CsVecStorage +impl CsVecStorage where DefaultAllocator: Allocator, { /// The value buffer of this storage. - pub fn values(&self) -> &[N] { + pub fn values(&self) -> &[T] { &self.vals } @@ -134,13 +134,13 @@ where } } -impl CsVecStorage where DefaultAllocator: Allocator {} +impl CsVecStorage where DefaultAllocator: Allocator {} -impl<'a, N: Scalar, R: Dim, C: Dim> CsStorageIter<'a, N, R, C> for CsVecStorage +impl<'a, T: Scalar, R: Dim, C: Dim> CsStorageIter<'a, T, R, C> for CsVecStorage where DefaultAllocator: Allocator, { - type ColumnEntries = ColumnEntries<'a, N>; + type ColumnEntries = ColumnEntries<'a, T>; type ColumnRowIndices = iter::Cloned>; #[inline] @@ -156,7 +156,7 @@ where } } -impl CsStorage for CsVecStorage +impl CsStorage for CsVecStorage where DefaultAllocator: Allocator, { @@ -181,12 +181,12 @@ where } #[inline] - unsafe fn get_value_unchecked(&self, i: usize) -> &N { + unsafe fn get_value_unchecked(&self, i: usize) -> &T { self.vals.get_unchecked(i) } #[inline] - fn get_value(&self, i: usize) -> &N { + fn get_value(&self, i: usize) -> &T { &self.vals[i] } @@ -202,12 +202,12 @@ where } } -impl<'a, N: Scalar, R: Dim, C: Dim> CsStorageIterMut<'a, N, R, C> for CsVecStorage +impl<'a, T: Scalar, R: Dim, C: Dim> CsStorageIterMut<'a, T, R, C> for CsVecStorage where DefaultAllocator: Allocator, { - type ValuesMut = slice::IterMut<'a, N>; - type ColumnEntriesMut = iter::Zip>, slice::IterMut<'a, N>>; + type ValuesMut = slice::IterMut<'a, T>; + type ColumnEntriesMut = iter::Zip>, slice::IterMut<'a, T>>; #[inline] fn values_mut(&'a mut self) -> Self::ValuesMut { @@ -224,35 +224,35 @@ where } } -impl CsStorageMut for CsVecStorage where +impl CsStorageMut for CsVecStorage where DefaultAllocator: Allocator { } /* -pub struct CsSliceStorage<'a, N: Scalar, R: Dim, C: DimAdd> { +pub struct CsSliceStorage<'a, T: Scalar, R: Dim, C: DimAdd> { shape: (R, C), p: VectorSlice>, i: VectorSlice, - vals: VectorSlice, + vals: VectorSlice, }*/ /// A compressed sparse column matrix. #[derive(Clone, Debug, PartialEq)] pub struct CsMatrix< - N: Scalar, + T: Scalar, R: Dim = Dynamic, C: Dim = Dynamic, - S: CsStorage = CsVecStorage, + S: CsStorage = CsVecStorage, > { pub(crate) data: S, - _phantoms: PhantomData<(N, R, C)>, + _phantoms: PhantomData<(T, R, C)>, } /// A column compressed sparse vector. -pub type CsVector> = CsMatrix; +pub type CsVector> = CsMatrix; -impl CsMatrix +impl CsMatrix where DefaultAllocator: Allocator, { @@ -274,7 +274,7 @@ where CsMatrix { data: CsVecStorage { shape: (nrows, ncols), - p: VectorN::zeros_generic(ncols, Const::<1>), + p: OVector::zeros_generic(ncols, Const::<1>), i, vals, }, @@ -286,13 +286,13 @@ where pub(crate) fn from_parts_generic( nrows: R, ncols: C, - p: VectorN, + p: OVector, i: Vec, - vals: Vec, + vals: Vec, ) -> Self where - N: Zero + ClosedAdd, - DefaultAllocator: Allocator, + T: Zero + ClosedAdd, + DefaultAllocator: Allocator, { assert_eq!(ncols.value(), p.len(), "Invalid inptr size."); assert_eq!(i.len(), vals.len(), "Invalid value size."); @@ -330,13 +330,13 @@ where } /* -impl CsMatrix { +impl CsMatrix { pub(crate) fn from_parts( nrows: usize, ncols: usize, p: Vec, i: Vec, - vals: Vec, + vals: Vec, ) -> Self { let nrows = Dynamic::new(nrows); @@ -347,7 +347,7 @@ impl CsMatrix { } */ -impl> CsMatrix { +impl> CsMatrix { pub(crate) fn from_data(data: S) -> Self { CsMatrix { data, @@ -409,7 +409,7 @@ impl> CsMatrix { } /// Computes the transpose of this sparse matrix. - pub fn transpose(&self) -> CsMatrix + pub fn transpose(&self) -> CsMatrix where DefaultAllocator: Allocator, { @@ -442,29 +442,30 @@ impl> CsMatrix { } } -impl> CsMatrix { +impl> CsMatrix { /// Iterator through all the mutable values of this sparse matrix. #[inline] - pub fn values_mut(&mut self) -> impl Iterator { + pub fn values_mut(&mut self) -> impl Iterator { self.data.values_mut() } } -impl CsMatrix +impl CsMatrix where DefaultAllocator: Allocator, { pub(crate) fn sort(&mut self) where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { // Size = R let nrows = self.data.shape().0; - let mut workspace = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, Const::<1>) }; + let mut workspace = + unsafe { crate::unimplemented_or_uninitialized_generic!(nrows, Const::<1>) }; self.sort_with_workspace(workspace.as_mut_slice()); } - pub(crate) fn sort_with_workspace(&mut self, workspace: &mut [N]) { + pub(crate) fn sort_with_workspace(&mut self, workspace: &mut [T]) { assert!( workspace.len() >= self.nrows(), "Workspace must be able to hold at least self.nrows() elements." @@ -490,7 +491,7 @@ where // Remove dupliate entries on a sorted CsMatrix. pub(crate) fn dedup(&mut self) where - N: Zero + ClosedAdd, + T: Zero + ClosedAdd, { let mut curr_i = 0; @@ -499,7 +500,7 @@ where self.data.p[j] = curr_i; if range.start != range.end { - let mut value = N::zero(); + let mut value = T::zero(); let mut irow = self.data.i[range.start]; for idx in range { diff --git a/src/sparse/cs_matrix_cholesky.rs b/src/sparse/cs_matrix_cholesky.rs index 2581f302..4cd61d2a 100644 --- a/src/sparse/cs_matrix_cholesky.rs +++ b/src/sparse/cs_matrix_cholesky.rs @@ -3,12 +3,12 @@ use std::mem; use crate::allocator::Allocator; use crate::sparse::{CsMatrix, CsStorage, CsStorageIter, CsStorageIterMut, CsVecStorage}; -use crate::{Const, DefaultAllocator, Dim, RealField, VectorN}; +use crate::{Const, DefaultAllocator, Dim, OVector, RealField}; /// The cholesky decomposition of a column compressed sparse matrix. -pub struct CsCholesky +pub struct CsCholesky where - DefaultAllocator: Allocator + Allocator, + 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 @@ -16,22 +16,22 @@ where original_p: Vec, original_i: Vec, // Decomposition result. - l: CsMatrix, + l: CsMatrix, // Used only for the pattern. // TODO: store only the nonzero pattern instead. - u: CsMatrix, + u: CsMatrix, ok: bool, // Workspaces. - work_x: VectorN, - work_c: VectorN, + work_x: OVector, + work_c: OVector, } -impl CsCholesky +impl CsCholesky where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// Computes the cholesky decomposition of the sparse matrix `m`. - pub fn new(m: &CsMatrix) -> Self { + pub fn new(m: &CsMatrix) -> Self { let mut me = Self::new_symbolic(m); let _ = me.decompose_left_looking(&m.data.vals); me @@ -39,7 +39,7 @@ where /// Perform symbolic analysis for the given matrix. /// /// This does not access the numerical values of `m`. - pub fn new_symbolic(m: &CsMatrix) -> Self { + pub fn new_symbolic(m: &CsMatrix) -> Self { assert!( m.is_square(), "The matrix `m` must be square to compute its elimination tree." @@ -67,7 +67,7 @@ where } /// The lower-triangular matrix of the cholesky decomposition. - pub fn l(&self) -> Option<&CsMatrix> { + pub fn l(&self) -> Option<&CsMatrix> { if self.ok { Some(&self.l) } else { @@ -76,7 +76,7 @@ where } /// Extracts the lower-triangular matrix of the cholesky decomposition. - pub fn unwrap_l(self) -> Option> { + pub fn unwrap_l(self) -> Option> { if self.ok { Some(self.l) } else { @@ -86,7 +86,7 @@ where /// Perform a numerical left-looking cholesky decomposition of a matrix with the same structure as the /// one used to initialize `self`, but with different non-zero values provided by `values`. - pub fn decompose_left_looking(&mut self, values: &[N]) -> bool { + pub fn decompose_left_looking(&mut self, values: &[T]) -> bool { assert!( values.len() >= self.original_i.len(), "The set of values is too small." @@ -103,7 +103,7 @@ where let range_k = *self.original_p.get_unchecked(k)..*self.original_p.get_unchecked(k + 1); - *self.work_x.vget_unchecked_mut(k) = N::zero(); + *self.work_x.vget_unchecked_mut(k) = T::zero(); for p in range_k.clone() { let irow = *self.original_i.get_unchecked(p); @@ -131,7 +131,7 @@ where let diag = *self.work_x.vget_unchecked(k); - if diag > N::zero() { + if diag > T::zero() { let denom = diag.sqrt(); *self .l @@ -141,7 +141,7 @@ where for (p, val) in self.l.data.column_entries_mut(k) { *val = *self.work_x.vget_unchecked(p) / denom; - *self.work_x.vget_unchecked_mut(p) = N::zero(); + *self.work_x.vget_unchecked_mut(p) = T::zero(); } } else { self.ok = false; @@ -156,7 +156,7 @@ where /// Perform a numerical up-looking cholesky decomposition of a matrix with the same structure as the /// one used to initialize `self`, but with different non-zero values provided by `values`. - pub fn decompose_up_looking(&mut self, values: &[N]) -> bool { + pub fn decompose_up_looking(&mut self, values: &[T]) -> bool { assert!( values.len() >= self.original_i.len(), "The set of values is too small." @@ -172,7 +172,7 @@ where let column_range = *self.original_p.get_unchecked(k)..*self.original_p.get_unchecked(k + 1); - *self.work_x.vget_unchecked_mut(k) = N::zero(); + *self.work_x.vget_unchecked_mut(k) = T::zero(); for p in column_range.clone() { let irow = *self.original_i.get_unchecked(p); @@ -182,7 +182,7 @@ where } let mut diag = *self.work_x.vget_unchecked(k); - *self.work_x.vget_unchecked_mut(k) = N::zero(); + *self.work_x.vget_unchecked_mut(k) = T::zero(); // Triangular solve. for irow in self.u.data.column_row_indices(k) { @@ -196,7 +196,7 @@ where .data .vals .get_unchecked(*self.l.data.p.vget_unchecked(irow)); - *self.work_x.vget_unchecked_mut(irow) = N::zero(); + *self.work_x.vget_unchecked_mut(irow) = T::zero(); for p in *self.l.data.p.vget_unchecked(irow) + 1..*self.work_c.vget_unchecked(irow) @@ -214,7 +214,7 @@ where *self.l.data.vals.get_unchecked_mut(p) = lki; } - if diag <= N::zero() { + if diag <= T::zero() { self.ok = false; return false; } @@ -231,7 +231,7 @@ where true } - fn elimination_tree>(m: &CsMatrix) -> Vec { + fn elimination_tree>(m: &CsMatrix) -> Vec { let nrows = m.nrows(); let mut forest: Vec<_> = iter::repeat(usize::max_value()).take(nrows).collect(); let mut ancestor: Vec<_> = iter::repeat(usize::max_value()).take(nrows).collect(); @@ -257,8 +257,8 @@ where forest } - fn reach>( - m: &CsMatrix, + fn reach>( + m: &CsMatrix, j: usize, max_j: usize, tree: &[usize], @@ -287,9 +287,9 @@ where out.append(&mut res); } - fn nonzero_pattern>( - m: &CsMatrix, - ) -> (CsMatrix, CsMatrix) { + fn nonzero_pattern>( + m: &CsMatrix, + ) -> (CsMatrix, CsMatrix) { let etree = Self::elimination_tree(m); let (nrows, ncols) = m.data.shape(); let mut rows = Vec::with_capacity(m.len()); @@ -329,8 +329,8 @@ where * NOTE: All the following methods are untested and currently unused. * * - fn column_counts>( - m: &CsMatrix, + fn column_counts>( + m: &CsMatrix, tree: &[usize], ) -> Vec { let len = m.data.shape().0.value(); diff --git a/src/sparse/cs_matrix_conversion.rs b/src/sparse/cs_matrix_conversion.rs index 8025f94e..4fefd325 100644 --- a/src/sparse/cs_matrix_conversion.rs +++ b/src/sparse/cs_matrix_conversion.rs @@ -5,24 +5,24 @@ use crate::allocator::Allocator; use crate::sparse::cs_utils; use crate::sparse::{CsMatrix, CsStorage}; use crate::storage::Storage; -use crate::{DefaultAllocator, Dim, Dynamic, Matrix, MatrixMN, Scalar}; +use crate::{DefaultAllocator, Dim, Dynamic, Matrix, OMatrix, Scalar}; -impl<'a, N: Scalar + Zero + ClosedAdd> CsMatrix { +impl<'a, T: Scalar + Zero + ClosedAdd> CsMatrix { /// Creates a column-compressed sparse matrix from a sparse matrix in triplet form. pub fn from_triplet( nrows: usize, ncols: usize, irows: &[usize], icols: &[usize], - vals: &[N], + vals: &[T], ) -> 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 +impl<'a, T: Scalar + Zero + ClosedAdd, R: Dim, C: Dim> CsMatrix where - DefaultAllocator: Allocator + Allocator, + DefaultAllocator: Allocator + Allocator, { /// Creates a column-compressed sparse matrix from a sparse matrix in triplet form. pub fn from_triplet_generic( @@ -30,7 +30,7 @@ where ncols: C, irows: &[usize], icols: &[usize], - vals: &[N], + vals: &[T], ) -> Self { assert!(vals.len() == irows.len()); assert!(vals.len() == icols.len()); @@ -65,14 +65,14 @@ where } } -impl<'a, N: Scalar + Zero, R: Dim, C: Dim, S> From> for MatrixMN +impl<'a, T: Scalar + Zero, R: Dim, C: Dim, S> From> for OMatrix where - S: CsStorage, - DefaultAllocator: Allocator, + S: CsStorage, + DefaultAllocator: Allocator, { - fn from(m: CsMatrix) -> Self { + fn from(m: CsMatrix) -> Self { let (nrows, ncols) = m.data.shape(); - let mut res = MatrixMN::zeros_generic(nrows, ncols); + let mut res = OMatrix::zeros_generic(nrows, ncols); for j in 0..ncols.value() { for (i, val) in m.data.column_entries(j) { @@ -84,12 +84,12 @@ where } } -impl<'a, N: Scalar + Zero, R: Dim, C: Dim, S> From> for CsMatrix +impl<'a, T: Scalar + Zero, R: Dim, C: Dim, S> From> for CsMatrix where - S: Storage, - DefaultAllocator: Allocator + Allocator, + S: Storage, + DefaultAllocator: Allocator + Allocator, { - fn from(m: Matrix) -> Self { + fn from(m: Matrix) -> Self { let (nrows, ncols) = m.data.shape(); let len = m.iter().filter(|e| !e.is_zero()).count(); let mut res = CsMatrix::new_uninitialized_generic(nrows, ncols, len); diff --git a/src/sparse/cs_matrix_ops.rs b/src/sparse/cs_matrix_ops.rs index 27aa696a..e9daa4ae 100644 --- a/src/sparse/cs_matrix_ops.rs +++ b/src/sparse/cs_matrix_ops.rs @@ -6,21 +6,21 @@ use crate::allocator::Allocator; use crate::constraint::{AreMultipliable, DimEq, ShapeConstraint}; use crate::sparse::{CsMatrix, CsStorage, CsStorageMut, CsVector}; use crate::storage::StorageMut; -use crate::{Const, DefaultAllocator, Dim, Scalar, Vector, VectorN}; +use crate::{Const, DefaultAllocator, Dim, OVector, Scalar, Vector}; -impl> CsMatrix { +impl> CsMatrix { fn scatter( &self, j: usize, - beta: N, + beta: T, timestamps: &mut [usize], timestamp: usize, - workspace: &mut [N], + workspace: &mut [T], mut nz: usize, - res: &mut CsMatrix, + res: &mut CsMatrix, ) -> usize where - N: ClosedAdd + ClosedMul, + T: ClosedAdd + ClosedMul, DefaultAllocator: Allocator, { for (i, val) in self.data.column_entries(j) { @@ -39,8 +39,8 @@ impl> CsMatrix { } /* -impl CsVector { - pub fn axpy(&mut self, alpha: N, x: CsVector, beta: N) { +impl CsVector { + pub fn axpy(&mut self, alpha: T, x: CsVector, beta: T) { // First, compute the number of non-zero entries. let mut nnzero = 0; @@ -76,11 +76,11 @@ impl CsVector { } */ -impl> Vector { +impl> Vector { /// Perform a sparse axpy operation: `self = alpha * x + beta * self` operation. - pub fn axpy_cs(&mut self, alpha: N, x: &CsVector, beta: N) + pub fn axpy_cs(&mut self, alpha: T, x: &CsVector, beta: T) where - S2: CsStorage, + S2: CsStorage, ShapeConstraint: DimEq, { if beta.is_zero() { @@ -106,9 +106,9 @@ impl> Vect } /* - pub fn gemv_sparse(&mut self, alpha: N, a: &CsMatrix, x: &DVector, beta: N) + pub fn gemv_sparse(&mut self, alpha: T, a: &CsMatrix, x: &DVector, beta: T) where - S2: CsStorage { + S2: CsStorage { let col2 = a.column(0); let val = unsafe { *x.vget_unchecked(0) }; self.axpy_sparse(alpha * val, &col2, beta); @@ -117,28 +117,28 @@ impl> Vect let col2 = a.column(j); let val = unsafe { *x.vget_unchecked(j) }; - self.axpy_sparse(alpha * val, &col2, N::one()); + self.axpy_sparse(alpha * val, &col2, T::one()); } } */ } -impl<'a, 'b, N, R1, R2, C1, C2, S1, S2> Mul<&'b CsMatrix> - for &'a CsMatrix +impl<'a, 'b, T, R1, R2, C1, C2, S1, S2> Mul<&'b CsMatrix> + for &'a CsMatrix where - N: Scalar + ClosedAdd + ClosedMul + Zero, + T: Scalar + ClosedAdd + ClosedMul + Zero, R1: Dim, C1: Dim, R2: Dim, C2: Dim, - S1: CsStorage, - S2: CsStorage, + S1: CsStorage, + S2: CsStorage, ShapeConstraint: AreMultipliable, - DefaultAllocator: Allocator + Allocator + Allocator, + DefaultAllocator: Allocator + Allocator + Allocator, { - type Output = CsMatrix; + type Output = CsMatrix; - fn mul(self, rhs: &'b CsMatrix) -> Self::Output { + fn mul(self, rhs: &'b CsMatrix) -> Self::Output { let (nrows1, ncols1) = self.data.shape(); let (nrows2, ncols2) = rhs.data.shape(); assert_eq!( @@ -148,14 +148,14 @@ where ); let mut res = CsMatrix::new_uninitialized_generic(nrows1, ncols2, self.len() + rhs.len()); - let mut workspace = VectorN::::zeros_generic(nrows1, Const::<1>); + let mut workspace = OVector::::zeros_generic(nrows1, Const::<1>); let mut nz = 0; for j in 0..ncols2.value() { res.data.p[j] = nz; let new_size_bound = nz + nrows1.value(); res.data.i.resize(new_size_bound, 0); - res.data.vals.resize(new_size_bound, N::zero()); + res.data.vals.resize(new_size_bound, T::zero()); for (i, beta) in rhs.data.column_entries(j) { for (k, val) in self.data.column_entries(i) { @@ -167,7 +167,7 @@ where if !val.is_zero() { res.data.i[nz] = i; res.data.vals[nz] = val.inlined_clone(); - *val = N::zero(); + *val = T::zero(); nz += 1; } } @@ -177,15 +177,15 @@ where // of branching inside of the inner loop. // // let mut res = CsMatrix::new_uninitialized_generic(nrows1, ncols2, self.len() + rhs.len()); - // let mut timestamps = VectorN::zeros_generic(nrows1, Const::<)>; - // let mut workspace = unsafe { VectorN::new_uninitialized_generic(nrows1, Const::<)> }; + // let mut timestamps = OVector::zeros_generic(nrows1, Const::<)>; + // let mut workspace = unsafe { OVector::new_uninitialized_generic(nrows1, Const::<)> }; // let mut nz = 0; // // for j in 0..ncols2.value() { // res.data.p[j] = nz; // let new_size_bound = nz + nrows1.value(); // res.data.i.resize(new_size_bound, 0); - // res.data.vals.resize(new_size_bound, N::zero()); + // res.data.vals.resize(new_size_bound, T::zero()); // // for (i, val) in rhs.data.column_entries(j) { // nz = self.scatter( @@ -216,22 +216,22 @@ where } } -impl<'a, 'b, N, R1, R2, C1, C2, S1, S2> Add<&'b CsMatrix> - for &'a CsMatrix +impl<'a, 'b, T, R1, R2, C1, C2, S1, S2> Add<&'b CsMatrix> + for &'a CsMatrix where - N: Scalar + ClosedAdd + ClosedMul + One, + T: Scalar + ClosedAdd + ClosedMul + One, R1: Dim, C1: Dim, R2: Dim, C2: Dim, - S1: CsStorage, - S2: CsStorage, + S1: CsStorage, + S2: CsStorage, ShapeConstraint: DimEq + DimEq, - DefaultAllocator: Allocator + Allocator + Allocator, + DefaultAllocator: Allocator + Allocator + Allocator, { - type Output = CsMatrix; + type Output = CsMatrix; - fn add(self, rhs: &'b CsMatrix) -> Self::Output { + fn add(self, rhs: &'b CsMatrix) -> Self::Output { let (nrows1, ncols1) = self.data.shape(); let (nrows2, ncols2) = rhs.data.shape(); assert_eq!( @@ -241,8 +241,9 @@ where ); let mut res = CsMatrix::new_uninitialized_generic(nrows1, ncols2, self.len() + rhs.len()); - let mut timestamps = VectorN::zeros_generic(nrows1, Const::<1>); - let mut workspace = unsafe { crate::unimplemented_or_uninitialized_generic!(nrows1, Const::<1>) }; + let mut timestamps = OVector::zeros_generic(nrows1, Const::<1>); + let mut workspace = + unsafe { crate::unimplemented_or_uninitialized_generic!(nrows1, Const::<1>) }; let mut nz = 0; for j in 0..ncols2.value() { @@ -250,7 +251,7 @@ where nz = self.scatter( j, - N::one(), + T::one(), timestamps.as_mut_slice(), j + 1, workspace.as_mut_slice(), @@ -260,7 +261,7 @@ where nz = rhs.scatter( j, - N::one(), + T::one(), timestamps.as_mut_slice(), j + 1, workspace.as_mut_slice(), @@ -285,16 +286,16 @@ where } } -impl<'a, 'b, N, R, C, S> Mul for CsMatrix +impl<'a, 'b, T, R, C, S> Mul for CsMatrix where - N: Scalar + ClosedAdd + ClosedMul + Zero, + T: Scalar + ClosedAdd + ClosedMul + Zero, R: Dim, C: Dim, - S: CsStorageMut, + S: CsStorageMut, { type Output = Self; - fn mul(mut self, rhs: N) -> Self::Output { + fn mul(mut self, rhs: T) -> Self::Output { for e in self.values_mut() { *e *= rhs.inlined_clone() } diff --git a/src/sparse/cs_matrix_solve.rs b/src/sparse/cs_matrix_solve.rs index c781d4ad..52065747 100644 --- a/src/sparse/cs_matrix_solve.rs +++ b/src/sparse/cs_matrix_solve.rs @@ -2,17 +2,17 @@ use crate::allocator::Allocator; use crate::constraint::{SameNumberOfRows, ShapeConstraint}; use crate::sparse::{CsMatrix, CsStorage, CsVector}; use crate::storage::{Storage, StorageMut}; -use crate::{Const, DefaultAllocator, Dim, Matrix, MatrixMN, RealField, VectorN}; +use crate::{Const, DefaultAllocator, Dim, Matrix, OMatrix, OVector, RealField}; -impl> CsMatrix { +impl> CsMatrix { /// Solve a lower-triangular system with a dense right-hand-side. pub fn solve_lower_triangular( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut b = b.clone_owned(); @@ -26,11 +26,11 @@ impl> CsMatrix { /// Solve a lower-triangular system with `self` transposed and a dense right-hand-side. pub fn tr_solve_lower_triangular( &self, - b: &Matrix, - ) -> Option> + b: &Matrix, + ) -> Option> where - S2: Storage, - DefaultAllocator: Allocator, + S2: Storage, + DefaultAllocator: Allocator, ShapeConstraint: SameNumberOfRows, { let mut b = b.clone_owned(); @@ -44,10 +44,10 @@ impl> CsMatrix { /// Solve in-place a lower-triangular system with a dense right-hand-side. pub fn solve_lower_triangular_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let (nrows, ncols) = self.data.shape(); @@ -90,10 +90,10 @@ impl> CsMatrix { /// Solve a lower-triangular system with `self` transposed and a dense right-hand-side. pub fn tr_solve_lower_triangular_mut( &self, - b: &mut Matrix, + b: &mut Matrix, ) -> bool where - S2: StorageMut, + S2: StorageMut, ShapeConstraint: SameNumberOfRows, { let (nrows, ncols) = self.data.shape(); @@ -137,11 +137,11 @@ impl> CsMatrix { /// Solve a lower-triangular system with a sparse right-hand-side. pub fn solve_lower_triangular_cs( &self, - b: &CsVector, - ) -> Option> + b: &CsVector, + ) -> Option> where - S2: CsStorage, - DefaultAllocator: Allocator + Allocator + Allocator, + S2: CsStorage, + DefaultAllocator: Allocator + Allocator + Allocator, ShapeConstraint: SameNumberOfRows, { let mut reach = Vec::new(); @@ -153,7 +153,7 @@ impl> CsMatrix { unsafe { crate::unimplemented_or_uninitialized_generic!(b.data.shape().0, Const::<1>) }; for i in reach.iter().cloned() { - workspace[i] = N::zero(); + workspace[i] = T::zero(); } for (i, val) in b.data.column_entries(0) { @@ -202,13 +202,13 @@ impl> CsMatrix { // Computes the reachable, post-ordered, nodes from `b`. fn lower_triangular_reach_postordered( &self, - b: &CsVector, + b: &CsVector, xi: &mut Vec, ) where - S2: CsStorage, + S2: CsStorage, DefaultAllocator: Allocator, { - let mut visited = VectorN::repeat_generic(self.data.shape().1, U1, false); + let mut visited = OVector::repeat_generic(self.data.shape().1, U1, false); let mut stack = Vec::new(); for i in b.data.column_range(0) { @@ -247,12 +247,12 @@ impl> CsMatrix { */ // Computes the nodes reachable from `b` in an arbitrary order. - fn lower_triangular_reach(&self, b: &CsVector, xi: &mut Vec) + fn lower_triangular_reach(&self, b: &CsVector, xi: &mut Vec) where - S2: CsStorage, + S2: CsStorage, DefaultAllocator: Allocator, { - let mut visited = VectorN::repeat_generic(self.data.shape().1, Const::<1>, false); + let mut visited = OVector::repeat_generic(self.data.shape().1, Const::<1>, false); let mut stack = Vec::new(); for irow in b.data.column_row_indices(0) { diff --git a/src/sparse/cs_utils.rs b/src/sparse/cs_utils.rs index c73b9639..5b9d86b0 100644 --- a/src/sparse/cs_utils.rs +++ b/src/sparse/cs_utils.rs @@ -1,7 +1,7 @@ use crate::allocator::Allocator; -use crate::{DefaultAllocator, Dim, VectorN}; +use crate::{DefaultAllocator, Dim, OVector}; -pub fn cumsum(a: &mut VectorN, b: &mut VectorN) -> usize +pub fn cumsum(a: &mut OVector, b: &mut OVector) -> usize where DefaultAllocator: Allocator, { diff --git a/src/third_party/alga/alga_dual_quaternion.rs b/src/third_party/alga/alga_dual_quaternion.rs index f6ee9e10..d6a5861e 100644 --- a/src/third_party/alga/alga_dual_quaternion.rs +++ b/src/third_party/alga/alga_dual_quaternion.rs @@ -15,35 +15,35 @@ use crate::geometry::{ DualQuaternion, Point3, Quaternion, Translation3, UnitDualQuaternion, UnitQuaternion, }; -impl Identity for DualQuaternion { +impl Identity for DualQuaternion { #[inline] fn identity() -> Self { Self::identity() } } -impl Identity for DualQuaternion { +impl Identity for DualQuaternion { #[inline] fn identity() -> Self { Self::zero() } } -impl AbstractMagma for DualQuaternion { +impl AbstractMagma for DualQuaternion { #[inline] fn operate(&self, rhs: &Self) -> Self { self * rhs } } -impl AbstractMagma for DualQuaternion { +impl AbstractMagma for DualQuaternion { #[inline] fn operate(&self, rhs: &Self) -> Self { self + rhs } } -impl TwoSidedInverse for DualQuaternion { +impl TwoSidedInverse for DualQuaternion { #[inline] fn two_sided_inverse(&self) -> Self { -self @@ -52,7 +52,7 @@ impl TwoSidedInverse for Dual macro_rules! impl_structures( ($DualQuaternion: ident; $($marker: ident<$operator: ident>),* $(,)*) => {$( - impl $marker<$operator> for $DualQuaternion { } + impl $marker<$operator> for $DualQuaternion { } )*} ); @@ -74,24 +74,24 @@ impl_structures!( * Vector space. * */ -impl AbstractModule for DualQuaternion { - type AbstractRing = N; +impl AbstractModule for DualQuaternion { + type AbstractRing = T; #[inline] - fn multiply_by(&self, n: N) -> Self { + fn multiply_by(&self, n: T) -> Self { self * n } } -impl Module for DualQuaternion { - type Ring = N; +impl Module for DualQuaternion { + type Ring = T; } -impl VectorSpace for DualQuaternion { - type Field = N; +impl VectorSpace for DualQuaternion { + type Field = T; } -impl FiniteDimVectorSpace for DualQuaternion { +impl FiniteDimVectorSpace for DualQuaternion { #[inline] fn dimension() -> usize { 8 @@ -113,32 +113,32 @@ impl FiniteDimVectorSpace for DualQuate } #[inline] - fn dot(&self, other: &Self) -> N { + fn dot(&self, other: &Self) -> T { self.real.dot(&other.real) + self.dual.dot(&other.dual) } #[inline] - unsafe fn component_unchecked(&self, i: usize) -> &N { + unsafe fn component_unchecked(&self, i: usize) -> &T { self.as_ref().get_unchecked(i) } #[inline] - unsafe fn component_unchecked_mut(&mut self, i: usize) -> &mut N { + unsafe fn component_unchecked_mut(&mut self, i: usize) -> &mut T { self.as_mut().get_unchecked_mut(i) } } -impl NormedSpace for DualQuaternion { - type RealField = N; - type ComplexField = N; +impl NormedSpace for DualQuaternion { + type RealField = T; + type ComplexField = T; #[inline] - fn norm_squared(&self) -> N { + fn norm_squared(&self) -> T { self.real.norm_squared() } #[inline] - fn norm(&self) -> N { + fn norm(&self) -> T { self.real.norm() } @@ -148,12 +148,12 @@ impl NormedSpace for DualQuaternion } #[inline] - fn normalize_mut(&mut self) -> N { + fn normalize_mut(&mut self) -> T { self.normalize_mut() } #[inline] - fn try_normalize(&self, min_norm: N) -> Option { + fn try_normalize(&self, min_norm: T) -> Option { let real_norm = self.real.norm(); if real_norm > min_norm { Some(Self::from_real_and_dual( @@ -166,7 +166,7 @@ impl NormedSpace for DualQuaternion } #[inline] - fn try_normalize_mut(&mut self, min_norm: N) -> Option { + fn try_normalize_mut(&mut self, min_norm: T) -> Option { let real_norm = self.real.norm(); if real_norm > min_norm { self.real /= real_norm; @@ -183,15 +183,15 @@ impl NormedSpace for DualQuaternion * Implementations for UnitDualQuaternion. * */ -impl Identity for UnitDualQuaternion { +impl Identity for UnitDualQuaternion { #[inline] fn identity() -> Self { Self::identity() } } -impl AbstractMagma - for UnitDualQuaternion +impl AbstractMagma + for UnitDualQuaternion { #[inline] fn operate(&self, rhs: &Self) -> Self { @@ -199,8 +199,8 @@ impl AbstractMagma } } -impl TwoSidedInverse - for UnitDualQuaternion +impl TwoSidedInverse + for UnitDualQuaternion { #[inline] fn two_sided_inverse(&self) -> Self { @@ -222,38 +222,38 @@ impl_structures!( AbstractGroup ); -impl Transformation> for UnitDualQuaternion { +impl Transformation> for UnitDualQuaternion { #[inline] - fn transform_point(&self, pt: &Point3) -> Point3 { + fn transform_point(&self, pt: &Point3) -> Point3 { self.transform_point(pt) } #[inline] - fn transform_vector(&self, v: &Vector3) -> Vector3 { + fn transform_vector(&self, v: &Vector3) -> Vector3 { self.transform_vector(v) } } -impl ProjectiveTransformation> - for UnitDualQuaternion +impl ProjectiveTransformation> + for UnitDualQuaternion { #[inline] - fn inverse_transform_point(&self, pt: &Point3) -> Point3 { + fn inverse_transform_point(&self, pt: &Point3) -> Point3 { self.inverse_transform_point(pt) } #[inline] - fn inverse_transform_vector(&self, v: &Vector3) -> Vector3 { + fn inverse_transform_vector(&self, v: &Vector3) -> Vector3 { self.inverse_transform_vector(v) } } -impl AffineTransformation> - for UnitDualQuaternion +impl AffineTransformation> + for UnitDualQuaternion { - type Rotation = UnitQuaternion; + type Rotation = UnitQuaternion; type NonUniformScaling = Id; - type Translation = Translation3; + type Translation = Translation3; #[inline] fn decompose(&self) -> (Self::Translation, Self::Rotation, Id, Self::Rotation) { @@ -296,16 +296,16 @@ impl AffineTransformation> } } -impl Similarity> for UnitDualQuaternion { +impl Similarity> for UnitDualQuaternion { type Scaling = Id; #[inline] - fn translation(&self) -> Translation3 { + fn translation(&self) -> Translation3 { self.translation() } #[inline] - fn rotation(&self) -> UnitQuaternion { + fn rotation(&self) -> UnitQuaternion { self.rotation() } @@ -317,7 +317,7 @@ impl Similarity> for UnitDual macro_rules! marker_impl( ($($Trait: ident),*) => {$( - impl $Trait> for UnitDualQuaternion { } + impl $Trait> for UnitDualQuaternion { } )*} ); diff --git a/src/third_party/alga/alga_isometry.rs b/src/third_party/alga/alga_isometry.rs index 68788494..e0ec2924 100755 --- a/src/third_party/alga/alga_isometry.rs +++ b/src/third_party/alga/alga_isometry.rs @@ -8,7 +8,7 @@ use alga::linear::{ Transformation, }; -use crate::base::CVectorN; +use crate::base::SVector; use crate::geometry::{AbstractRotation, Isometry, Point, Translation}; @@ -17,10 +17,10 @@ use crate::geometry::{AbstractRotation, Isometry, Point, Translation}; * Algebraic structures. * */ -impl Identity - for Isometry +impl Identity + for Isometry where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { #[inline] fn identity() -> Self { @@ -28,10 +28,10 @@ where } } -impl TwoSidedInverse - for Isometry +impl TwoSidedInverse + for Isometry where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { #[inline] #[must_use = "Did you mean to use two_sided_inverse_mut()?"] @@ -45,10 +45,10 @@ where } } -impl AbstractMagma - for Isometry +impl AbstractMagma + for Isometry where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { #[inline] fn operate(&self, rhs: &Self) -> Self { @@ -58,8 +58,8 @@ where macro_rules! impl_multiplicative_structures( ($($marker: ident<$operator: ident>),* $(,)*) => {$( - impl $marker<$operator> for Isometry - where R: Rotation> + AbstractRotation { } + impl $marker<$operator> for Isometry + where R: Rotation> + AbstractRotation { } )*} ); @@ -76,46 +76,46 @@ impl_multiplicative_structures!( * Transformation groups. * */ -impl Transformation> - for Isometry +impl Transformation> + for Isometry where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { #[inline] - fn transform_point(&self, pt: &Point) -> Point { + fn transform_point(&self, pt: &Point) -> Point { self.transform_point(pt) } #[inline] - fn transform_vector(&self, v: &CVectorN) -> CVectorN { + fn transform_vector(&self, v: &SVector) -> SVector { self.transform_vector(v) } } -impl - ProjectiveTransformation> for Isometry +impl + ProjectiveTransformation> for Isometry where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { #[inline] - fn inverse_transform_point(&self, pt: &Point) -> Point { + fn inverse_transform_point(&self, pt: &Point) -> Point { self.inverse_transform_point(pt) } #[inline] - fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { + fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.inverse_transform_vector(v) } } -impl AffineTransformation> - for Isometry +impl AffineTransformation> + for Isometry where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { type Rotation = R; type NonUniformScaling = Id; - type Translation = Translation; + type Translation = Translation; #[inline] fn decompose(&self) -> (Self::Translation, R, Id, R) { @@ -123,7 +123,7 @@ where self.translation.clone(), self.rotation.clone(), Id::new(), - >::identity(), + >::identity(), ) } @@ -159,22 +159,22 @@ where } #[inline] - fn append_rotation_wrt_point(&self, r: &Self::Rotation, p: &Point) -> Option { + fn append_rotation_wrt_point(&self, r: &Self::Rotation, p: &Point) -> Option { let mut res = self.clone(); res.append_rotation_wrt_point_mut(r, p); Some(res) } } -impl Similarity> - for Isometry +impl Similarity> + for Isometry where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { type Scaling = Id; #[inline] - fn translation(&self) -> Translation { + fn translation(&self) -> Translation { self.translation.clone() } @@ -191,8 +191,8 @@ where macro_rules! marker_impl( ($($Trait: ident),*) => {$( - impl $Trait> for Isometry - where R: Rotation> + AbstractRotation { } + impl $Trait> for Isometry + where R: Rotation> + AbstractRotation { } )*} ); diff --git a/src/third_party/alga/alga_matrix.rs b/src/third_party/alga/alga_matrix.rs index 6e97aedb..0ddd4fdf 100644 --- a/src/third_party/alga/alga_matrix.rs +++ b/src/third_party/alga/alga_matrix.rs @@ -16,28 +16,28 @@ use alga::linear::{ use crate::base::allocator::Allocator; use crate::base::dimension::{Dim, DimName}; use crate::base::storage::{Storage, StorageMut}; -use crate::base::{DefaultAllocator, MatrixMN, MatrixN, Scalar}; +use crate::base::{DefaultAllocator, OMatrix, Scalar}; /* * * Additive structures. * */ -impl Identity for MatrixMN +impl Identity for OMatrix where - N: Scalar + Zero, - DefaultAllocator: Allocator, + T: Scalar + Zero, + DefaultAllocator: Allocator, { #[inline] fn identity() -> Self { - Self::from_element(N::zero()) + Self::from_element(T::zero()) } } -impl AbstractMagma for MatrixMN +impl AbstractMagma for OMatrix where - N: Scalar + ClosedAdd, - DefaultAllocator: Allocator, + T: Scalar + ClosedAdd, + DefaultAllocator: Allocator, { #[inline] fn operate(&self, other: &Self) -> Self { @@ -45,10 +45,10 @@ where } } -impl TwoSidedInverse for MatrixMN +impl TwoSidedInverse for OMatrix where - N: Scalar + ClosedNeg, - DefaultAllocator: Allocator, + T: Scalar + ClosedNeg, + DefaultAllocator: Allocator, { #[inline] #[must_use = "Did you mean to use two_sided_inverse_mut()?"] @@ -64,9 +64,9 @@ where macro_rules! inherit_additive_structure( ($($marker: ident<$operator: ident> $(+ $bounds: ident)*),* $(,)*) => {$( - impl $marker<$operator> for MatrixMN - where N: Scalar + $marker<$operator> $(+ $bounds)*, - DefaultAllocator: Allocator { } + impl $marker<$operator> for OMatrix + where T: Scalar + $marker<$operator> $(+ $bounds)*, + DefaultAllocator: Allocator { } )*} ); @@ -79,39 +79,39 @@ inherit_additive_structure!( AbstractGroupAbelian + Zero + ClosedAdd + ClosedNeg ); -impl AbstractModule for MatrixMN +impl AbstractModule for OMatrix where - N: Scalar + RingCommutative, - DefaultAllocator: Allocator, + T: Scalar + RingCommutative, + DefaultAllocator: Allocator, { - type AbstractRing = N; + type AbstractRing = T; #[inline] - fn multiply_by(&self, n: N) -> Self { + fn multiply_by(&self, n: T) -> Self { self * n } } -impl Module for MatrixMN +impl Module for OMatrix where - N: Scalar + RingCommutative, - DefaultAllocator: Allocator, + T: Scalar + RingCommutative, + DefaultAllocator: Allocator, { - type Ring = N; + type Ring = T; } -impl VectorSpace for MatrixMN +impl VectorSpace for OMatrix where - N: Scalar + Field, - DefaultAllocator: Allocator, + T: Scalar + Field, + DefaultAllocator: Allocator, { - type Field = N; + type Field = T; } -impl FiniteDimVectorSpace for MatrixMN +impl FiniteDimVectorSpace for OMatrix where - N: Scalar + Field, - DefaultAllocator: Allocator, + T: Scalar + Field, + DefaultAllocator: Allocator, { #[inline] fn dimension() -> usize { @@ -124,47 +124,47 @@ where let mut res = Self::zero(); unsafe { - *res.data.get_unchecked_linear_mut(i) = N::one(); + *res.data.get_unchecked_linear_mut(i) = T::one(); } res } #[inline] - fn dot(&self, other: &Self) -> N { + fn dot(&self, other: &Self) -> T { self.dot(other) } #[inline] - unsafe fn component_unchecked(&self, i: usize) -> &N { + unsafe fn component_unchecked(&self, i: usize) -> &T { self.data.get_unchecked_linear(i) } #[inline] - unsafe fn component_unchecked_mut(&mut self, i: usize) -> &mut N { + unsafe fn component_unchecked_mut(&mut self, i: usize) -> &mut T { self.data.get_unchecked_linear_mut(i) } } impl< - N: ComplexField + simba::scalar::ComplexField::RealField>, + T: ComplexField + simba::scalar::ComplexField::RealField>, R: DimName, C: DimName, - > NormedSpace for MatrixMN + > NormedSpace for OMatrix where - ::RealField: simba::scalar::RealField, - DefaultAllocator: Allocator, + ::RealField: simba::scalar::RealField, + DefaultAllocator: Allocator, { - type RealField = ::RealField; - type ComplexField = N; + type RealField = ::RealField; + type ComplexField = T; #[inline] - fn norm_squared(&self) -> ::RealField { + fn norm_squared(&self) -> ::RealField { self.norm_squared() } #[inline] - fn norm(&self) -> ::RealField { + fn norm(&self) -> ::RealField { self.norm() } @@ -175,41 +175,41 @@ where } #[inline] - fn normalize_mut(&mut self) -> ::RealField { + fn normalize_mut(&mut self) -> ::RealField { self.normalize_mut() } #[inline] #[must_use = "Did you mean to use try_normalize_mut()?"] - fn try_normalize(&self, min_norm: ::RealField) -> Option { + fn try_normalize(&self, min_norm: ::RealField) -> Option { self.try_normalize(min_norm) } #[inline] fn try_normalize_mut( &mut self, - min_norm: ::RealField, - ) -> Option<::RealField> { + min_norm: ::RealField, + ) -> Option<::RealField> { self.try_normalize_mut(min_norm) } } impl< - N: ComplexField + simba::scalar::ComplexField::RealField>, + T: ComplexField + simba::scalar::ComplexField::RealField>, R: DimName, C: DimName, - > InnerSpace for MatrixMN + > InnerSpace for OMatrix where - ::RealField: simba::scalar::RealField, - DefaultAllocator: Allocator, + ::RealField: simba::scalar::RealField, + DefaultAllocator: Allocator, { #[inline] - fn angle(&self, other: &Self) -> ::RealField { + fn angle(&self, other: &Self) -> ::RealField { self.angle(other) } #[inline] - fn inner_product(&self, other: &Self) -> N { + fn inner_product(&self, other: &Self) -> T { self.dotc(other) } } @@ -219,13 +219,13 @@ where // − use `x()` instead of `::canonical_basis_element` // − use `::new(x, y, z)` instead of `::from_slice` impl< - N: ComplexField + simba::scalar::ComplexField::RealField>, + T: ComplexField + simba::scalar::ComplexField::RealField>, R: DimName, C: DimName, - > FiniteDimInnerSpace for MatrixMN + > FiniteDimInnerSpace for OMatrix where - ::RealField: simba::scalar::RealField, - DefaultAllocator: Allocator, + ::RealField: simba::scalar::RealField, + DefaultAllocator: Allocator, { #[inline] fn orthonormalize(vs: &mut [Self]) -> usize { @@ -241,7 +241,7 @@ where } if vs[i] - .try_normalize_mut(::RealField::zero()) + .try_normalize_mut(::RealField::zero()) .is_some() { // TODO: this will be efficient on dynamically-allocated vectors but for @@ -299,9 +299,9 @@ where let mut a; if ComplexField::norm1(v[0]) > ComplexField::norm1(v[1]) { - a = Self::from_column_slice(&[v[2], N::zero(), -v[0]]); + a = Self::from_column_slice(&[v[2], T::zero(), -v[0]]); } else { - a = Self::from_column_slice(&[N::zero(), -v[2], v[1]]); + a = Self::from_column_slice(&[T::zero(), -v[2], v[1]]); }; let _ = a.normalize_mut(); @@ -331,7 +331,7 @@ where } if let Some(subsp_elt) = - elt.try_normalize(::RealField::zero()) + elt.try_normalize(::RealField::zero()) { if !f(&subsp_elt) { return; @@ -358,10 +358,10 @@ where * * */ -impl Identity for MatrixN +impl Identity for OMatrix where - N: Scalar + Zero + One, - DefaultAllocator: Allocator, + T: Scalar + Zero + One, + DefaultAllocator: Allocator, { #[inline] fn identity() -> Self { @@ -369,10 +369,10 @@ where } } -impl AbstractMagma for MatrixN +impl AbstractMagma for OMatrix where - N: Scalar + Zero + One + ClosedAdd + ClosedMul, - DefaultAllocator: Allocator, + T: Scalar + Zero + One + ClosedAdd + ClosedMul, + DefaultAllocator: Allocator, { #[inline] fn operate(&self, other: &Self) -> Self { @@ -382,9 +382,9 @@ where macro_rules! impl_multiplicative_structure( ($($marker: ident<$operator: ident> $(+ $bounds: ident)*),* $(,)*) => {$( - impl $marker<$operator> for MatrixN - where N: Scalar + Zero + One + ClosedAdd + ClosedMul + $marker<$operator> $(+ $bounds)*, - DefaultAllocator: Allocator { } + impl $marker<$operator> for OMatrix + where T: Scalar + Zero + One + ClosedAdd + ClosedMul + $marker<$operator> $(+ $bounds)*, + DefaultAllocator: Allocator { } )*} ); @@ -398,10 +398,10 @@ impl_multiplicative_structure!( * Ordering * */ -impl MeetSemilattice for MatrixMN +impl MeetSemilattice for OMatrix where - N: Scalar + MeetSemilattice, - DefaultAllocator: Allocator, + T: Scalar + MeetSemilattice, + DefaultAllocator: Allocator, { #[inline] fn meet(&self, other: &Self) -> Self { @@ -409,10 +409,10 @@ where } } -impl JoinSemilattice for MatrixMN +impl JoinSemilattice for OMatrix where - N: Scalar + JoinSemilattice, - DefaultAllocator: Allocator, + T: Scalar + JoinSemilattice, + DefaultAllocator: Allocator, { #[inline] fn join(&self, other: &Self) -> Self { @@ -420,10 +420,10 @@ where } } -impl Lattice for MatrixMN +impl Lattice for OMatrix where - N: Scalar + Lattice, - DefaultAllocator: Allocator, + T: Scalar + Lattice, + DefaultAllocator: Allocator, { #[inline] fn meet_join(&self, other: &Self) -> (Self, Self) { diff --git a/src/third_party/alga/alga_point.rs b/src/third_party/alga/alga_point.rs index 2e8064f9..f1365af4 100644 --- a/src/third_party/alga/alga_point.rs +++ b/src/third_party/alga/alga_point.rs @@ -1,20 +1,20 @@ use alga::general::{Field, JoinSemilattice, Lattice, MeetSemilattice, RealField}; use alga::linear::{AffineSpace, EuclideanSpace}; -use crate::base::{CVectorN, Scalar}; +use crate::base::{SVector, Scalar}; use crate::geometry::Point; -impl AffineSpace for Point +impl AffineSpace for Point where - N: Scalar + Field, + T: Scalar + Field, { - type Translation = CVectorN; + type Translation = SVector; } -impl EuclideanSpace for Point { - type Coordinates = CVectorN; - type RealField = N; +impl EuclideanSpace for Point { + type Coordinates = SVector; + type RealField = T; #[inline] fn origin() -> Self { @@ -32,7 +32,7 @@ impl EuclideanSpace for } #[inline] - fn scale_by(&self, n: N) -> Self { + fn scale_by(&self, n: T) -> Self { self * n } } @@ -42,9 +42,9 @@ impl EuclideanSpace for * Ordering * */ -impl MeetSemilattice for Point +impl MeetSemilattice for Point where - N: Scalar + MeetSemilattice, + T: Scalar + MeetSemilattice, { #[inline] fn meet(&self, other: &Self) -> Self { @@ -52,9 +52,9 @@ where } } -impl JoinSemilattice for Point +impl JoinSemilattice for Point where - N: Scalar + JoinSemilattice, + T: Scalar + JoinSemilattice, { #[inline] fn join(&self, other: &Self) -> Self { @@ -62,9 +62,9 @@ where } } -impl Lattice for Point +impl Lattice for Point where - N: Scalar + Lattice, + T: Scalar + Lattice, { #[inline] fn meet_join(&self, other: &Self) -> (Self, Self) { diff --git a/src/third_party/alga/alga_quaternion.rs b/src/third_party/alga/alga_quaternion.rs index 087c8a58..0885f44f 100755 --- a/src/third_party/alga/alga_quaternion.rs +++ b/src/third_party/alga/alga_quaternion.rs @@ -14,35 +14,35 @@ use alga::linear::{ use crate::base::{Vector3, Vector4}; use crate::geometry::{Point3, Quaternion, UnitQuaternion}; -impl Identity for Quaternion { +impl Identity for Quaternion { #[inline] fn identity() -> Self { Self::identity() } } -impl Identity for Quaternion { +impl Identity for Quaternion { #[inline] fn identity() -> Self { Self::zero() } } -impl AbstractMagma for Quaternion { +impl AbstractMagma for Quaternion { #[inline] fn operate(&self, rhs: &Self) -> Self { self * rhs } } -impl AbstractMagma for Quaternion { +impl AbstractMagma for Quaternion { #[inline] fn operate(&self, rhs: &Self) -> Self { self + rhs } } -impl TwoSidedInverse for Quaternion { +impl TwoSidedInverse for Quaternion { #[inline] fn two_sided_inverse(&self) -> Self { -self @@ -51,7 +51,7 @@ impl TwoSidedInverse for Quat macro_rules! impl_structures( ($Quaternion: ident; $($marker: ident<$operator: ident>),* $(,)*) => {$( - impl $marker<$operator> for $Quaternion { } + impl $marker<$operator> for $Quaternion { } )*} ); @@ -73,24 +73,24 @@ impl_structures!( * Vector space. * */ -impl AbstractModule for Quaternion { - type AbstractRing = N; +impl AbstractModule for Quaternion { + type AbstractRing = T; #[inline] - fn multiply_by(&self, n: N) -> Self { + fn multiply_by(&self, n: T) -> Self { self * n } } -impl Module for Quaternion { - type Ring = N; +impl Module for Quaternion { + type Ring = T; } -impl VectorSpace for Quaternion { - type Field = N; +impl VectorSpace for Quaternion { + type Field = T; } -impl FiniteDimVectorSpace for Quaternion { +impl FiniteDimVectorSpace for Quaternion { #[inline] fn dimension() -> usize { 4 @@ -102,32 +102,32 @@ impl FiniteDimVectorSpace for Quaternio } #[inline] - fn dot(&self, other: &Self) -> N { + fn dot(&self, other: &Self) -> T { self.coords.dot(&other.coords) } #[inline] - unsafe fn component_unchecked(&self, i: usize) -> &N { + unsafe fn component_unchecked(&self, i: usize) -> &T { self.coords.component_unchecked(i) } #[inline] - unsafe fn component_unchecked_mut(&mut self, i: usize) -> &mut N { + unsafe fn component_unchecked_mut(&mut self, i: usize) -> &mut T { self.coords.component_unchecked_mut(i) } } -impl NormedSpace for Quaternion { - type RealField = N; - type ComplexField = N; +impl NormedSpace for Quaternion { + type RealField = T; + type ComplexField = T; #[inline] - fn norm_squared(&self) -> N { + fn norm_squared(&self) -> T { self.coords.norm_squared() } #[inline] - fn norm(&self) -> N { + fn norm(&self) -> T { self.as_vector().norm() } @@ -138,12 +138,12 @@ impl NormedSpace for Quaternion { } #[inline] - fn normalize_mut(&mut self) -> N { + fn normalize_mut(&mut self) -> T { self.coords.normalize_mut() } #[inline] - fn try_normalize(&self, min_norm: N) -> Option { + fn try_normalize(&self, min_norm: T) -> Option { if let Some(v) = self.coords.try_normalize(min_norm) { Some(Self::from(v)) } else { @@ -152,7 +152,7 @@ impl NormedSpace for Quaternion { } #[inline] - fn try_normalize_mut(&mut self, min_norm: N) -> Option { + fn try_normalize_mut(&mut self, min_norm: T) -> Option { self.coords.try_normalize_mut(min_norm) } } @@ -162,22 +162,22 @@ impl NormedSpace for Quaternion { * Implementations for UnitQuaternion. * */ -impl Identity for UnitQuaternion { +impl Identity for UnitQuaternion { #[inline] fn identity() -> Self { Self::identity() } } -impl AbstractMagma for UnitQuaternion { +impl AbstractMagma for UnitQuaternion { #[inline] fn operate(&self, rhs: &Self) -> Self { self * rhs } } -impl TwoSidedInverse - for UnitQuaternion +impl TwoSidedInverse + for UnitQuaternion { #[inline] fn two_sided_inverse(&self) -> Self { @@ -199,34 +199,34 @@ impl_structures!( AbstractGroup ); -impl Transformation> for UnitQuaternion { +impl Transformation> for UnitQuaternion { #[inline] - fn transform_point(&self, pt: &Point3) -> Point3 { + fn transform_point(&self, pt: &Point3) -> Point3 { self.transform_point(pt) } #[inline] - fn transform_vector(&self, v: &Vector3) -> Vector3 { + fn transform_vector(&self, v: &Vector3) -> Vector3 { self.transform_vector(v) } } -impl ProjectiveTransformation> - for UnitQuaternion +impl ProjectiveTransformation> + for UnitQuaternion { #[inline] - fn inverse_transform_point(&self, pt: &Point3) -> Point3 { + fn inverse_transform_point(&self, pt: &Point3) -> Point3 { self.inverse_transform_point(pt) } #[inline] - fn inverse_transform_vector(&self, v: &Vector3) -> Vector3 { + fn inverse_transform_vector(&self, v: &Vector3) -> Vector3 { self.inverse_transform_vector(v) } } -impl AffineTransformation> - for UnitQuaternion +impl AffineTransformation> + for UnitQuaternion { type Rotation = Self; type NonUniformScaling = Id; @@ -268,7 +268,7 @@ impl AffineTransformation> } } -impl Similarity> for UnitQuaternion { +impl Similarity> for UnitQuaternion { type Scaling = Id; #[inline] @@ -289,25 +289,25 @@ impl Similarity> for UnitQuat macro_rules! marker_impl( ($($Trait: ident),*) => {$( - impl $Trait> for UnitQuaternion { } + impl $Trait> for UnitQuaternion { } )*} ); marker_impl!(Isometry, DirectIsometry, OrthogonalTransformation); -impl Rotation> for UnitQuaternion { +impl Rotation> for UnitQuaternion { #[inline] - fn powf(&self, n: N) -> Option { + fn powf(&self, n: T) -> Option { Some(self.powf(n)) } #[inline] - fn rotation_between(a: &Vector3, b: &Vector3) -> Option { + fn rotation_between(a: &Vector3, b: &Vector3) -> Option { Self::rotation_between(a, b) } #[inline] - fn scaled_rotation_between(a: &Vector3, b: &Vector3, s: N) -> Option { + fn scaled_rotation_between(a: &Vector3, b: &Vector3, s: T) -> Option { Self::scaled_rotation_between(a, b, s) } } diff --git a/src/third_party/alga/alga_rotation.rs b/src/third_party/alga/alga_rotation.rs index 100d3b30..a63d7f84 100755 --- a/src/third_party/alga/alga_rotation.rs +++ b/src/third_party/alga/alga_rotation.rs @@ -7,7 +7,7 @@ use alga::linear::{ ProjectiveTransformation, Similarity, Transformation, }; -use crate::base::CVectorN; +use crate::base::SVector; use crate::geometry::{Point, Rotation}; /* @@ -15,8 +15,8 @@ use crate::geometry::{Point, Rotation}; * Algebraic structures. * */ -impl Identity - for Rotation +impl Identity + for Rotation { #[inline] fn identity() -> Self { @@ -24,8 +24,8 @@ impl Identity TwoSidedInverse - for Rotation +impl TwoSidedInverse + for Rotation { #[inline] #[must_use = "Did you mean to use two_sided_inverse_mut()?"] @@ -39,8 +39,8 @@ impl TwoSidedInverse AbstractMagma - for Rotation +impl AbstractMagma + for Rotation { #[inline] fn operate(&self, rhs: &Self) -> Self { @@ -50,7 +50,7 @@ impl AbstractMagma),* $(,)*) => {$( - impl $marker<$operator> for Rotation + impl $marker<$operator> for Rotation { } )*} ); @@ -68,36 +68,36 @@ impl_multiplicative_structures!( * Transformation groups. * */ -impl Transformation> - for Rotation +impl Transformation> + for Rotation { #[inline] - fn transform_point(&self, pt: &Point) -> Point { + fn transform_point(&self, pt: &Point) -> Point { self.transform_point(pt) } #[inline] - fn transform_vector(&self, v: &CVectorN) -> CVectorN { + fn transform_vector(&self, v: &SVector) -> SVector { self.transform_vector(v) } } -impl ProjectiveTransformation> - for Rotation +impl ProjectiveTransformation> + for Rotation { #[inline] - fn inverse_transform_point(&self, pt: &Point) -> Point { + fn inverse_transform_point(&self, pt: &Point) -> Point { self.inverse_transform_point(pt) } #[inline] - fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { + fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.inverse_transform_vector(v) } } -impl AffineTransformation> - for Rotation +impl AffineTransformation> + for Rotation { type Rotation = Self; type NonUniformScaling = Id; @@ -139,8 +139,8 @@ impl AffineTransformati } } -impl Similarity> - for Rotation +impl Similarity> + for Rotation { type Scaling = Id; @@ -162,7 +162,7 @@ impl Similarity {$( - impl $Trait> for Rotation + impl $Trait> for Rotation { } )*} ); @@ -170,25 +170,25 @@ macro_rules! marker_impl( marker_impl!(Isometry, DirectIsometry, OrthogonalTransformation); /// Subgroups of the n-dimensional rotation group `SO(n)`. -impl linear::Rotation> - for Rotation +impl linear::Rotation> + for Rotation { #[inline] - fn powf(&self, _: N) -> Option { + fn powf(&self, _: T) -> Option { // XXX: Add the general case. // XXX: Use specialization for 2D and 3D. unimplemented!() } #[inline] - fn rotation_between(_: &CVectorN, _: &CVectorN) -> Option { + fn rotation_between(_: &SVector, _: &SVector) -> Option { // XXX: Add the general case. // XXX: Use specialization for 2D and 3D. unimplemented!() } #[inline] - fn scaled_rotation_between(_: &CVectorN, _: &CVectorN, _: N) -> Option { + fn scaled_rotation_between(_: &SVector, _: &SVector, _: T) -> Option { // XXX: Add the general case. // XXX: Use specialization for 2D and 3D. unimplemented!() @@ -196,10 +196,10 @@ impl linear::Rotation

Matrix for Rotation { - type Field = N; - type Row = Matrix; - type Column = Matrix; +impl Matrix for Rotation { + type Field = T; + type Row = Matrix; + type Column = Matrix; type Transpose = Self; #[inline] @@ -238,8 +238,8 @@ impl Matrix for Rotation { } } -impl SquareMatrix for Rotation { - type Vector = Matrix; +impl SquareMatrix for Rotation { + type Vector = Matrix; #[inline] fn diagonal(&self) -> Self::Coordinates { @@ -268,5 +268,5 @@ impl SquareMatrix for Rotation { } } -impl InversibleSquareMatrix for Rotation { } +impl InversibleSquareMatrix for Rotation { } */ diff --git a/src/third_party/alga/alga_similarity.rs b/src/third_party/alga/alga_similarity.rs index 8f3bb126..3825b1c8 100755 --- a/src/third_party/alga/alga_similarity.rs +++ b/src/third_party/alga/alga_similarity.rs @@ -5,7 +5,7 @@ use alga::general::{ use alga::linear::Similarity as AlgaSimilarity; use alga::linear::{AffineTransformation, ProjectiveTransformation, Rotation, Transformation}; -use crate::base::CVectorN; +use crate::base::SVector; use crate::geometry::{AbstractRotation, Point, Similarity, Translation}; /* @@ -13,10 +13,10 @@ use crate::geometry::{AbstractRotation, Point, Similarity, Translation}; * Algebraic structures. * */ -impl Identity - for Similarity +impl Identity + for Similarity where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { #[inline] fn identity() -> Self { @@ -24,10 +24,10 @@ where } } -impl TwoSidedInverse - for Similarity +impl TwoSidedInverse + for Similarity where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { #[inline] #[must_use = "Did you mean to use two_sided_inverse_mut()?"] @@ -41,10 +41,10 @@ where } } -impl AbstractMagma - for Similarity +impl AbstractMagma + for Similarity where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { #[inline] fn operate(&self, rhs: &Self) -> Self { @@ -54,8 +54,8 @@ where macro_rules! impl_multiplicative_structures( ($($marker: ident<$operator: ident>),* $(,)*) => {$( - impl $marker<$operator> for Similarity - where R: Rotation> + AbstractRotation, + impl $marker<$operator> for Similarity + where R: Rotation> + AbstractRotation, { } )*} ); @@ -73,54 +73,54 @@ impl_multiplicative_structures!( * Transformation groups. * */ -impl Transformation> - for Similarity +impl Transformation> + for Similarity where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { #[inline] - fn transform_point(&self, pt: &Point) -> Point { + fn transform_point(&self, pt: &Point) -> Point { self.transform_point(pt) } #[inline] - fn transform_vector(&self, v: &CVectorN) -> CVectorN { + fn transform_vector(&self, v: &SVector) -> SVector { self.transform_vector(v) } } -impl - ProjectiveTransformation> for Similarity +impl + ProjectiveTransformation> for Similarity where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { #[inline] - fn inverse_transform_point(&self, pt: &Point) -> Point { + fn inverse_transform_point(&self, pt: &Point) -> Point { self.inverse_transform_point(pt) } #[inline] - fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { + fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.inverse_transform_vector(v) } } -impl AffineTransformation> - for Similarity +impl AffineTransformation> + for Similarity where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { - type NonUniformScaling = N; + type NonUniformScaling = T; type Rotation = R; - type Translation = Translation; + type Translation = Translation; #[inline] - fn decompose(&self) -> (Translation, R, N, R) { + fn decompose(&self) -> (Translation, R, T, R) { ( self.isometry.translation.clone(), self.isometry.rotation.clone(), self.scaling(), - >::identity(), + >::identity(), ) } @@ -155,22 +155,22 @@ where } #[inline] - fn append_rotation_wrt_point(&self, r: &Self::Rotation, p: &Point) -> Option { + fn append_rotation_wrt_point(&self, r: &Self::Rotation, p: &Point) -> Option { let mut res = self.clone(); res.append_rotation_wrt_point_mut(r, p); Some(res) } } -impl AlgaSimilarity> - for Similarity +impl AlgaSimilarity> + for Similarity where - R: Rotation> + AbstractRotation, + R: Rotation> + AbstractRotation, { - type Scaling = N; + type Scaling = T; #[inline] - fn translation(&self) -> Translation { + fn translation(&self) -> Translation { self.isometry.translation() } @@ -180,7 +180,7 @@ where } #[inline] - fn scaling(&self) -> N { + fn scaling(&self) -> T { self.scaling() } } diff --git a/src/third_party/alga/alga_transform.rs b/src/third_party/alga/alga_transform.rs index a4c23e4f..ed75018f 100755 --- a/src/third_party/alga/alga_transform.rs +++ b/src/third_party/alga/alga_transform.rs @@ -6,7 +6,7 @@ use alga::linear::{ProjectiveTransformation, Transformation}; use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; -use crate::base::{CVectorN, Const, DefaultAllocator}; +use crate::base::{Const, DefaultAllocator, SVector}; use crate::geometry::{Point, SubTCategoryOf, TCategory, TProjective, Transform}; @@ -15,12 +15,12 @@ use crate::geometry::{Point, SubTCategoryOf, TCategory, TProjective, Transform}; * Algebraic structures. * */ -impl Identity - for Transform +impl Identity + for Transform where Const: DimNameAdd, C: TCategory, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn identity() -> Self { @@ -28,12 +28,12 @@ where } } -impl TwoSidedInverse - for Transform +impl TwoSidedInverse + for Transform where Const: DimNameAdd, C: SubTCategoryOf, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] #[must_use = "Did you mean to use two_sided_inverse_mut()?"] @@ -47,12 +47,12 @@ where } } -impl AbstractMagma - for Transform +impl AbstractMagma + for Transform where Const: DimNameAdd, C: TCategory, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { #[inline] fn operate(&self, rhs: &Self) -> Self { @@ -62,21 +62,21 @@ where macro_rules! impl_multiplicative_structures( ($($marker: ident<$operator: ident>),* $(,)*) => {$( - impl $marker<$operator> for Transform + impl $marker<$operator> for Transform where Const: DimNameAdd, C: TCategory, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> { } + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> { } )*} ); macro_rules! impl_inversible_multiplicative_structures( ($($marker: ident<$operator: ident>),* $(,)*) => {$( - impl $marker<$operator> for Transform + impl $marker<$operator> for Transform where Const: DimNameAdd, C: SubTCategoryOf, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> { } + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> { } )*} ); @@ -96,56 +96,54 @@ impl_inversible_multiplicative_structures!( * Transformation groups. * */ -impl Transformation> for Transform +impl Transformation> for Transform where Const: DimNameAdd, - N: RealField + simba::scalar::RealField, + T: RealField + simba::scalar::RealField, C: TCategory, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>>, { #[inline] - fn transform_point(&self, pt: &Point) -> Point { + fn transform_point(&self, pt: &Point) -> Point { self.transform_point(pt) } #[inline] - fn transform_vector(&self, v: &CVectorN) -> CVectorN { + fn transform_vector(&self, v: &SVector) -> SVector { self.transform_vector(v) } } -impl ProjectiveTransformation> for Transform +impl ProjectiveTransformation> for Transform where Const: DimNameAdd, - N: RealField + simba::scalar::RealField, + T: RealField + simba::scalar::RealField, C: SubTCategoryOf, - DefaultAllocator: Allocator, U1>, DimNameSum, U1>> - + Allocator, U1>>, + DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + + Allocator, U1>>, { #[inline] - fn inverse_transform_point(&self, pt: &Point) -> Point { + fn inverse_transform_point(&self, pt: &Point) -> Point { self.inverse_transform_point(pt) } #[inline] - fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { + fn inverse_transform_vector(&self, v: &SVector) -> SVector { self.inverse_transform_vector(v) } } // TODO: we need to implement an SVD for this. // -// impl AffineTransformation> for Transform -// where N: RealField, +// impl AffineTransformation> for Transform +// where T: RealField, // C: SubTCategoryOf, -// DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + -// Allocator + -// Allocator { -// type PreRotation = Rotation; -// type NonUniformScaling = VectorN; -// type PostRotation = Rotation; -// type Translation = Translation; +// DefaultAllocator: Allocator, U1>, DimNameSum, U1>> { +// type PreRotation = Rotation; +// type NonUniformScaling = OVector; +// type PostRotation = Rotation; +// type Translation = Translation; // // #[inline] // fn decompose(&self) -> (Self::Translation, Self::PostRotation, Self::NonUniformScaling, Self::PreRotation) { diff --git a/src/third_party/alga/alga_translation.rs b/src/third_party/alga/alga_translation.rs index 542fde0b..bca6d13f 100755 --- a/src/third_party/alga/alga_translation.rs +++ b/src/third_party/alga/alga_translation.rs @@ -8,7 +8,7 @@ use alga::linear::{ Transformation, }; -use crate::base::CVectorN; +use crate::base::SVector; use crate::geometry::{Point, Translation}; /* @@ -16,8 +16,8 @@ use crate::geometry::{Point, Translation}; * Algebraic structures. * */ -impl Identity - for Translation +impl Identity + for Translation { #[inline] fn identity() -> Self { @@ -25,8 +25,8 @@ impl Identity TwoSidedInverse - for Translation +impl TwoSidedInverse + for Translation { #[inline] #[must_use = "Did you mean to use two_sided_inverse_mut()?"] @@ -40,8 +40,8 @@ impl TwoSidedInverse AbstractMagma - for Translation +impl AbstractMagma + for Translation { #[inline] fn operate(&self, rhs: &Self) -> Self { @@ -51,7 +51,7 @@ impl AbstractMagma),* $(,)*) => {$( - impl $marker<$operator> for Translation + impl $marker<$operator> for Translation { } )*} ); @@ -69,36 +69,36 @@ impl_multiplicative_structures!( * Transformation groups. * */ -impl Transformation> - for Translation +impl Transformation> + for Translation { #[inline] - fn transform_point(&self, pt: &Point) -> Point { + fn transform_point(&self, pt: &Point) -> Point { self.transform_point(pt) } #[inline] - fn transform_vector(&self, v: &CVectorN) -> CVectorN { + fn transform_vector(&self, v: &SVector) -> SVector { v.clone() } } -impl ProjectiveTransformation> - for Translation +impl ProjectiveTransformation> + for Translation { #[inline] - fn inverse_transform_point(&self, pt: &Point) -> Point { + fn inverse_transform_point(&self, pt: &Point) -> Point { self.inverse_transform_point(pt) } #[inline] - fn inverse_transform_vector(&self, v: &CVectorN) -> CVectorN { + fn inverse_transform_vector(&self, v: &SVector) -> SVector { v.clone() } } -impl AffineTransformation> - for Translation +impl AffineTransformation> + for Translation { type Rotation = Id; type NonUniformScaling = Id; @@ -140,8 +140,8 @@ impl AffineTransformati } } -impl Similarity> - for Translation +impl Similarity> + for Translation { type Scaling = Id; @@ -163,7 +163,7 @@ impl Similarity {$( - impl $Trait> for Translation + impl $Trait> for Translation { } )*} ); @@ -171,26 +171,26 @@ macro_rules! marker_impl( marker_impl!(Isometry, DirectIsometry); /// Subgroups of the n-dimensional translation group `T(n)`. -impl AlgaTranslation> - for Translation +impl AlgaTranslation> + for Translation { #[inline] - fn to_vector(&self) -> CVectorN { + fn to_vector(&self) -> SVector { self.vector.clone() } #[inline] - fn from_vector(v: CVectorN) -> Option { + fn from_vector(v: SVector) -> Option { Some(Self::from(v)) } #[inline] - fn powf(&self, n: N) -> Option { + fn powf(&self, n: T) -> Option { Some(Self::from(&self.vector * n)) } #[inline] - fn translation_between(a: &Point, b: &Point) -> Option { + fn translation_between(a: &Point, b: &Point) -> Option { Some(Self::from(b - a)) } } diff --git a/src/third_party/alga/alga_unit_complex.rs b/src/third_party/alga/alga_unit_complex.rs index 46e30535..7ae9c6df 100755 --- a/src/third_party/alga/alga_unit_complex.rs +++ b/src/third_party/alga/alga_unit_complex.rs @@ -17,21 +17,21 @@ use crate::geometry::{Point2, UnitComplex}; * Implementations for UnitComplex. * */ -impl Identity for UnitComplex { +impl Identity for UnitComplex { #[inline] fn identity() -> Self { Self::identity() } } -impl AbstractMagma for UnitComplex { +impl AbstractMagma for UnitComplex { #[inline] fn operate(&self, rhs: &Self) -> Self { self * rhs } } -impl TwoSidedInverse for UnitComplex { +impl TwoSidedInverse for UnitComplex { #[inline] #[must_use = "Did you mean to use two_sided_inverse_mut()?"] fn two_sided_inverse(&self) -> Self { @@ -46,7 +46,7 @@ impl TwoSidedInverse fo macro_rules! impl_structures( ($($marker: ident<$operator: ident>),* $(,)*) => {$( - impl $marker<$operator> for UnitComplex { + impl $marker<$operator> for UnitComplex { } )*} ); @@ -59,39 +59,39 @@ impl_structures!( AbstractGroup ); -impl Transformation> for UnitComplex +impl Transformation> for UnitComplex where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { #[inline] - fn transform_point(&self, pt: &Point2) -> Point2 { + fn transform_point(&self, pt: &Point2) -> Point2 { self.transform_point(pt) } #[inline] - fn transform_vector(&self, v: &Vector2) -> Vector2 { + fn transform_vector(&self, v: &Vector2) -> Vector2 { self.transform_vector(v) } } -impl ProjectiveTransformation> for UnitComplex +impl ProjectiveTransformation> for UnitComplex where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { #[inline] - fn inverse_transform_point(&self, pt: &Point2) -> Point2 { + fn inverse_transform_point(&self, pt: &Point2) -> Point2 { self.inverse_transform_point(pt) } #[inline] - fn inverse_transform_vector(&self, v: &Vector2) -> Vector2 { + fn inverse_transform_vector(&self, v: &Vector2) -> Vector2 { self.inverse_transform_vector(v) } } -impl AffineTransformation> for UnitComplex +impl AffineTransformation> for UnitComplex where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { type Rotation = Self; type NonUniformScaling = Id; @@ -133,9 +133,9 @@ where } } -impl Similarity> for UnitComplex +impl Similarity> for UnitComplex where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { type Scaling = Id; @@ -157,29 +157,29 @@ where macro_rules! marker_impl( ($($Trait: ident),*) => {$( - impl $Trait> for UnitComplex - where DefaultAllocator: Allocator { } + impl $Trait> for UnitComplex + where DefaultAllocator: Allocator { } )*} ); marker_impl!(Isometry, DirectIsometry, OrthogonalTransformation); -impl Rotation> for UnitComplex +impl Rotation> for UnitComplex where - DefaultAllocator: Allocator, + DefaultAllocator: Allocator, { #[inline] - fn powf(&self, n: N) -> Option { + fn powf(&self, n: T) -> Option { Some(self.powf(n)) } #[inline] - fn rotation_between(a: &Vector2, b: &Vector2) -> Option { + fn rotation_between(a: &Vector2, b: &Vector2) -> Option { Some(Self::rotation_between(a, b)) } #[inline] - fn scaled_rotation_between(a: &Vector2, b: &Vector2, s: N) -> Option { + fn scaled_rotation_between(a: &Vector2, b: &Vector2, s: T) -> Option { Some(Self::scaled_rotation_between(a, b, s)) } } diff --git a/src/third_party/mint/mint_matrix.rs b/src/third_party/mint/mint_matrix.rs index 30800f65..1e0a4d54 100644 --- a/src/third_party/mint/mint_matrix.rs +++ b/src/third_party/mint/mint_matrix.rs @@ -5,15 +5,15 @@ use std::ptr; use crate::base::allocator::Allocator; use crate::base::dimension::{U1, U2, U3, U4}; use crate::base::storage::{ContiguousStorage, ContiguousStorageMut, Storage, StorageMut}; -use crate::base::{DefaultAllocator, Matrix, MatrixMN, Scalar}; +use crate::base::{DefaultAllocator, Matrix, OMatrix, Scalar}; macro_rules! impl_from_into_mint_1D( ($($NRows: ident => $VT:ident [$SZ: expr]);* $(;)*) => {$( - impl From> for MatrixMN - where N: Scalar, - DefaultAllocator: Allocator { + impl From> for OMatrix + where T: Scalar, + DefaultAllocator: Allocator { #[inline] - fn from(v: mint::$VT) -> Self { + fn from(v: mint::$VT) -> Self { unsafe { let mut res = Self::new_uninitialized(); ptr::copy_nonoverlapping(&v.x, (*res.as_mut_ptr()).data.ptr_mut(), $SZ); @@ -23,35 +23,35 @@ macro_rules! impl_from_into_mint_1D( } } - impl Into> for Matrix - where N: Scalar, - S: ContiguousStorage { + impl Into> for Matrix + where T: Scalar, + S: ContiguousStorage { #[inline] - fn into(self) -> mint::$VT { + fn into(self) -> mint::$VT { unsafe { - let mut res: mint::$VT = mem::MaybeUninit::uninit().assume_init(); + let mut res: mint::$VT = mem::MaybeUninit::uninit().assume_init(); ptr::copy_nonoverlapping(self.data.ptr(), &mut res.x, $SZ); res } } } - impl AsRef> for Matrix - where N: Scalar, - S: ContiguousStorage { + impl AsRef> for Matrix + where T: Scalar, + S: ContiguousStorage { #[inline] - fn as_ref(&self) -> &mint::$VT { + fn as_ref(&self) -> &mint::$VT { unsafe { mem::transmute(self.data.ptr()) } } } - impl AsMut> for Matrix - where N: Scalar, - S: ContiguousStorageMut { + impl AsMut> for Matrix + where T: Scalar, + S: ContiguousStorageMut { #[inline] - fn as_mut(&mut self) -> &mut mint::$VT { + fn as_mut(&mut self) -> &mut mint::$VT { unsafe { mem::transmute(self.data.ptr_mut()) } @@ -69,11 +69,11 @@ impl_from_into_mint_1D!( macro_rules! impl_from_into_mint_2D( ($(($NRows: ty, $NCols: ty) => $MV:ident{ $($component:ident),* }[$SZRows: expr]);* $(;)*) => {$( - impl From> for MatrixMN - where N: Scalar, - DefaultAllocator: Allocator { + impl From> for OMatrix + where T: Scalar, + DefaultAllocator: Allocator { #[inline] - fn from(m: mint::$MV) -> Self { + fn from(m: mint::$MV) -> Self { unsafe { let mut res = Self::new_uninitialized(); let mut ptr = (*res.as_mut_ptr()).data.ptr_mut(); @@ -87,13 +87,13 @@ macro_rules! impl_from_into_mint_2D( } } - impl Into> for MatrixMN - where N: Scalar, - DefaultAllocator: Allocator { + impl Into> for OMatrix + where T: Scalar, + DefaultAllocator: Allocator { #[inline] - fn into(self) -> mint::$MV { + fn into(self) -> mint::$MV { unsafe { - let mut res: mint::$MV = mem::MaybeUninit::uninit().assume_init(); + let mut res: mint::$MV = mem::MaybeUninit::uninit().assume_init(); let mut ptr = self.data.ptr(); $( ptr::copy_nonoverlapping(ptr, &mut res.$component.x, $SZRows); diff --git a/src/third_party/mint/mint_point.rs b/src/third_party/mint/mint_point.rs index 62a2bf77..0b60762a 100644 --- a/src/third_party/mint/mint_point.rs +++ b/src/third_party/mint/mint_point.rs @@ -1,44 +1,44 @@ use crate::base::storage::{Storage, StorageMut}; -use crate::{Point, Scalar, VectorN, U2, U3}; +use crate::{OVector, Point, Scalar, U2, U3}; use std::convert::{AsMut, AsRef}; macro_rules! impl_from_into_mint_1D( ($($NRows: ident => $PT:ident, $VT:ident [$SZ: expr]);* $(;)*) => {$( - impl From> for Point - where N: Scalar { + impl From> for Point + where T: Scalar { #[inline] - fn from(p: mint::$PT) -> Self { + fn from(p: mint::$PT) -> Self { Self { - coords: VectorN::from(mint::$VT::from(p)), + coords: OVector::from(mint::$VT::from(p)), } } } - impl Into> for Point - where N: Scalar { + impl Into> for Point + where T: Scalar { #[inline] - fn into(self) -> mint::$PT { - let mint_vec: mint::$VT = self.coords.into(); + fn into(self) -> mint::$PT { + let mint_vec: mint::$VT = self.coords.into(); mint::$PT::from(mint_vec) } } - impl AsRef> for Point - where N: Scalar { + impl AsRef> for Point + where T: Scalar { #[inline] - fn as_ref(&self) -> &mint::$PT { + fn as_ref(&self) -> &mint::$PT { unsafe { - &*(self.coords.data.ptr() as *const mint::$PT) + &*(self.coords.data.ptr() as *const mint::$PT) } } } - impl AsMut> for Point - where N: Scalar { + impl AsMut> for Point + where T: Scalar { #[inline] - fn as_mut(&mut self) -> &mut mint::$PT { + fn as_mut(&mut self) -> &mut mint::$PT { unsafe { - &mut *(self.coords.data.ptr_mut() as *mut mint::$PT) + &mut *(self.coords.data.ptr_mut() as *mut mint::$PT) } } } diff --git a/src/third_party/mint/mint_quaternion.rs b/src/third_party/mint/mint_quaternion.rs index 01a1a94c..f41815ce 100644 --- a/src/third_party/mint/mint_quaternion.rs +++ b/src/third_party/mint/mint_quaternion.rs @@ -1,13 +1,13 @@ use crate::{Quaternion, Scalar, SimdValue, UnitQuaternion}; -impl From> for Quaternion { - fn from(q: mint::Quaternion) -> Self { +impl From> for Quaternion { + fn from(q: mint::Quaternion) -> Self { Self::new(q.s, q.v.x, q.v.y, q.v.z) } } -impl Into> for Quaternion { - fn into(self) -> mint::Quaternion { +impl Into> for Quaternion { + fn into(self) -> mint::Quaternion { mint::Quaternion { v: mint::Vector3 { x: self[0].inlined_clone(), @@ -19,8 +19,8 @@ impl Into> for Quaternion { } } -impl Into> for UnitQuaternion { - fn into(self) -> mint::Quaternion { +impl Into> for UnitQuaternion { + fn into(self) -> mint::Quaternion { mint::Quaternion { v: mint::Vector3 { x: self[0].inlined_clone(), diff --git a/src/third_party/mint/mint_rotation.rs b/src/third_party/mint/mint_rotation.rs index 9903da5d..ce57694e 100644 --- a/src/third_party/mint/mint_rotation.rs +++ b/src/third_party/mint/mint_rotation.rs @@ -1,7 +1,7 @@ use crate::{RealField, Rotation3}; -impl From> for Rotation3 { - fn from(euler: mint::EulerAngles) -> Self { +impl From> for Rotation3 { + fn from(euler: mint::EulerAngles) -> Self { Self::from_euler_angles(euler.a, euler.b, euler.c) } } diff --git a/tests/core/edition.rs b/tests/core/edition.rs index dac25d45..a8ee2536 100644 --- a/tests/core/edition.rs +++ b/tests/core/edition.rs @@ -2,7 +2,7 @@ use na::{ DMatrix, Matrix, Matrix3, Matrix3x4, Matrix3x5, Matrix4, Matrix4x3, Matrix4x5, Matrix5, Matrix5x3, Matrix5x4, }; -use na::{Dynamic, U2, U3, U5}; +use na::{Dynamic, U3, U5}; #[test] #[rustfmt::skip] @@ -252,9 +252,9 @@ fn remove_columns() { 21, 22, 25, 31, 32, 35); - assert_eq!(m.remove_fixed_columns::(0), expected1); - assert_eq!(m.remove_fixed_columns::(3), expected2); - assert_eq!(m.remove_fixed_columns::(2), expected3); + assert_eq!(m.remove_fixed_columns::<2>(0), expected1); + assert_eq!(m.remove_fixed_columns::<2>(3), expected2); + assert_eq!(m.remove_fixed_columns::<2>(2), expected3); // The following is just to verify that the return type dimensions is correctly inferred. let computed: Matrix<_, U3, Dynamic, _> = m.remove_columns(3, 2); @@ -366,9 +366,9 @@ fn remove_rows() { 21, 22, 23, 51, 52, 53); - assert_eq!(m.remove_fixed_rows::(0), expected1); - assert_eq!(m.remove_fixed_rows::(3), expected2); - assert_eq!(m.remove_fixed_rows::(2), expected3); + assert_eq!(m.remove_fixed_rows::<2>(0), expected1); + assert_eq!(m.remove_fixed_rows::<2>(3), expected2); + assert_eq!(m.remove_fixed_rows::<2>(2), expected3); // The following is just to verify that the return type dimensions is correctly inferred. let computed: Matrix<_, Dynamic, U3, _> = m.remove_rows(3, 2); @@ -483,9 +483,9 @@ fn insert_columns() { 41, 42, 0, 0, 43, 51, 52, 0, 0, 53); - assert_eq!(m.insert_fixed_columns::(0, 0), expected1); - assert_eq!(m.insert_fixed_columns::(3, 0), expected2); - assert_eq!(m.insert_fixed_columns::(2, 0), expected3); + assert_eq!(m.insert_fixed_columns::<2>(0, 0), expected1); + assert_eq!(m.insert_fixed_columns::<2>(3, 0), expected2); + assert_eq!(m.insert_fixed_columns::<2>(2, 0), expected3); // The following is just to verify that the return type dimensions is correctly inferred. let computed: Matrix<_, U5, Dynamic, _> = m.insert_columns(3, 2, 0); @@ -556,9 +556,9 @@ fn insert_rows() { 0, 0, 0, 0, 0, 31, 32, 33, 34, 35); - assert_eq!(m.insert_fixed_rows::(0, 0), expected1); - assert_eq!(m.insert_fixed_rows::(3, 0), expected2); - assert_eq!(m.insert_fixed_rows::(2, 0), expected3); + assert_eq!(m.insert_fixed_rows::<2>(0, 0), expected1); + assert_eq!(m.insert_fixed_rows::<2>(3, 0), expected2); + assert_eq!(m.insert_fixed_rows::<2>(2, 0), expected3); // The following is just to verify that the return type dimensions is correctly inferred. let computed: Matrix<_, Dynamic, U5, _> = m.insert_rows(3, 2, 0); diff --git a/tests/core/helper.rs b/tests/core/helper.rs index ec214fc0..4666089d 100644 --- a/tests/core/helper.rs +++ b/tests/core/helper.rs @@ -8,9 +8,9 @@ use rand::distributions::{Distribution, Standard}; use rand::Rng; #[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub struct RandComplex(pub Complex); +pub struct RandComplex(pub Complex); -impl Arbitrary for RandComplex { +impl Arbitrary for RandComplex { #[inline] fn arbitrary(rng: &mut Gen) -> Self { let im = Arbitrary::arbitrary(rng); @@ -19,12 +19,12 @@ impl Arbitrary for RandComplex { } } -impl Distribution> for Standard +impl Distribution> for Standard where - Standard: Distribution, + Standard: Distribution, { #[inline] - fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> RandComplex { + fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> RandComplex { let re = rng.gen(); let im = rng.gen(); RandComplex(Complex::new(re, im)) @@ -36,21 +36,21 @@ where // // Generates variates in the range [0, 1). #[derive(Copy, Clone, Debug, PartialEq, Eq)] -pub struct RandScalar(pub N); +pub struct RandScalar(pub T); -impl Arbitrary for RandScalar { +impl Arbitrary for RandScalar { #[inline] fn arbitrary(rng: &mut Gen) -> Self { RandScalar(Arbitrary::arbitrary(rng)) } } -impl Distribution> for Standard +impl Distribution> for Standard where - Standard: Distribution, + Standard: Distribution, { #[inline] - fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> RandScalar { + fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> RandScalar { RandScalar(self.sample(rng)) } } diff --git a/tests/core/matrix.rs b/tests/core/matrix.rs index a88f2c1f..7befd351 100644 --- a/tests/core/matrix.rs +++ b/tests/core/matrix.rs @@ -4,7 +4,7 @@ use std::cmp::Ordering; use na::dimension::{U15, U8}; use na::{ self, Const, DMatrix, DVector, Matrix2, Matrix2x3, Matrix2x4, Matrix3, Matrix3x2, Matrix3x4, - Matrix4, Matrix4x3, Matrix4x5, Matrix5, Matrix6, MatrixMN, RowVector3, RowVector4, RowVector5, + Matrix4, Matrix4x3, Matrix4x5, Matrix5, Matrix6, OMatrix, RowVector3, RowVector4, RowVector5, Vector1, Vector2, Vector3, Vector4, Vector5, Vector6, }; @@ -703,7 +703,7 @@ fn kronecker() { 440, 450, ); - let expected = MatrixMN::<_, U8, U15>::from_row_slice(&[ + let expected = OMatrix::<_, U8, U15>::from_row_slice(&[ 1210, 1320, 1430, 1540, 1650, 1320, 1440, 1560, 1680, 1800, 1430, 1560, 1690, 1820, 1950, 2310, 2420, 2530, 2640, 2750, 2520, 2640, 2760, 2880, 3000, 2730, 2860, 2990, 3120, 3250, 3410, 3520, 3630, 3740, 3850, 3720, 3840, 3960, 4080, 4200, 4030, 4160, 4290, 4420, 4550, @@ -1065,13 +1065,13 @@ fn partial_eq_different_types() { let dynamic_mat = DMatrix::from_row_slice(2, 4, &[1, 2, 3, 4, 5, 6, 7, 8]); let static_mat = Matrix2x4::new(1, 2, 3, 4, 5, 6, 7, 8); - let mut typenum_static_mat = MatrixMN::, Const<4>>::zeros(); + let mut typenum_static_mat = OMatrix::, Const<4>>::zeros(); let mut slice = typenum_static_mat.slice_mut((0, 0), (2, 4)); slice += static_mat; - let fslice_of_dmat = dynamic_mat.fixed_slice::, Const<2>>(0, 0); + let fslice_of_dmat = dynamic_mat.fixed_slice::<2, 2>(0, 0); let dslice_of_dmat = dynamic_mat.slice((0, 0), (2, 2)); - let fslice_of_smat = static_mat.fixed_slice::, Const<2>>(0, 0); + let fslice_of_smat = static_mat.fixed_slice::<2, 2>(0, 0); let dslice_of_smat = static_mat.slice((0, 0), (2, 2)); assert_eq!(dynamic_mat, static_mat); diff --git a/tests/core/matrix_slice.rs b/tests/core/matrix_slice.rs index 5fd90b0f..ada5297e 100644 --- a/tests/core/matrix_slice.rs +++ b/tests/core/matrix_slice.rs @@ -6,7 +6,6 @@ use na::{ MatrixSlice3, MatrixSlice3x2, MatrixSliceMut2, MatrixSliceMut2x3, MatrixSliceMut2xX, MatrixSliceMut3, MatrixSliceMut3x2, MatrixSliceMutXx3, MatrixSliceXx3, RowVector4, Vector3, }; -use na::{U2, U3, U4}; #[test] #[rustfmt::skip] @@ -15,9 +14,9 @@ fn nested_fixed_slices() { 21.0, 22.0, 23.0, 24.0, 31.0, 32.0, 33.0, 34.0); - let s1 = a.fixed_slice::(0, 1); // Simple slice. - let s2 = s1.fixed_slice::(1, 1); // Slice of slice. - let s3 = s1.fixed_slice_with_steps::((0, 0), (1, 1)); // Slice of slice with steps. + let s1 = a.fixed_slice::<3, 3>(0, 1); // Simple slice. + let s2 = s1.fixed_slice::<2, 2>(1, 1); // Slice of slice. + let s3 = s1.fixed_slice_with_steps::<2, 2>((0, 0), (1, 1)); // Slice of slice with steps. let expected_owned_s1 = Matrix3::new(12.0, 13.0, 14.0, 22.0, 23.0, 24.0, @@ -89,8 +88,8 @@ fn nested_row_slices() { 41.0, 42.0, 51.0, 52.0, 61.0, 62.0); - let s1 = a.fixed_rows::(1); - let s2 = s1.fixed_rows_with_step::(1, 1); + let s1 = a.fixed_rows::<4>(1); + let s2 = s1.fixed_rows_with_step::<2>(1, 1); let expected_owned_s1 = Matrix4x2::new(21.0, 22.0, 31.0, 32.0, @@ -134,8 +133,8 @@ fn row_slice_mut() { fn nested_col_slices() { let a = Matrix2x6::new(11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0); - let s1 = a.fixed_columns::(1); - let s2 = s1.fixed_columns_with_step::(1, 1); + let s1 = a.fixed_columns::<4>(1); + let s2 = s1.fixed_columns_with_step::<2>(1, 1); let expected_owned_s1 = Matrix2x4::new(12.0, 13.0, 14.0, 15.0, 22.0, 23.0, 24.0, 25.0); diff --git a/tests/core/matrixcompare.rs b/tests/core/matrixcompare.rs index ab3ecc2c..5c40d679 100644 --- a/tests/core/matrixcompare.rs +++ b/tests/core/matrixcompare.rs @@ -5,7 +5,7 @@ //! in addition to some sanity checks with example input. use matrixcompare::assert_matrix_eq; -use nalgebra::{MatrixMN, U4, U5}; +use nalgebra::{OMatrix, U4, U5}; #[cfg(feature = "proptest-support")] use { @@ -36,7 +36,7 @@ proptest! { #[test] fn assert_matrix_eq_dense_positive_comparison() { #[rustfmt::skip] - let a = MatrixMN::<_, U4, U5>::from_row_slice(&[ + let a = OMatrix::<_, U4, U5>::from_row_slice(&[ 1210, 1320, 1430, 1540, 1650, 2310, 2420, 2530, 2640, 2750, 3410, 3520, 3630, 3740, 3850, @@ -44,7 +44,7 @@ fn assert_matrix_eq_dense_positive_comparison() { ]); #[rustfmt::skip] - let b = MatrixMN::<_, U4, U5>::from_row_slice(&[ + let b = OMatrix::<_, U4, U5>::from_row_slice(&[ 1210, 1320, 1430, 1540, 1650, 2310, 2420, 2530, 2640, 2750, 3410, 3520, 3630, 3740, 3850, @@ -70,7 +70,7 @@ fn assert_matrix_eq_dense_positive_comparison() { #[should_panic] fn assert_matrix_eq_dense_negative_comparison() { #[rustfmt::skip] - let a = MatrixMN::<_, U4, U5>::from_row_slice(&[ + let a = OMatrix::<_, U4, U5>::from_row_slice(&[ 1210, 1320, 1430, 1540, 1650, 2310, 2420, 2530, 2640, 2750, 3410, 3520, 3630, 3740, 3850, @@ -78,7 +78,7 @@ fn assert_matrix_eq_dense_negative_comparison() { ]); #[rustfmt::skip] - let b = MatrixMN::<_, U4, U5>::from_row_slice(&[ + let b = OMatrix::<_, U4, U5>::from_row_slice(&[ 1210, 1320, 1430, 1540, 1650, 2310, 2420, 2530, 2640, 2750, 3410, 3520, 3630, 3740, 3850, diff --git a/tests/linalg/eigen.rs b/tests/linalg/eigen.rs index e9c0522b..162aad6a 100644 --- a/tests/linalg/eigen.rs +++ b/tests/linalg/eigen.rs @@ -180,13 +180,13 @@ fn symmetric_eigen_singular_24x24() { // } // } // -// fn verify_eigenvectors(m: MatrixN, mut eig: RealEigen) -> bool +// fn verify_eigenvectors(m: OMatrix, mut eig: RealEigen) -> bool // where DefaultAllocator: Allocator + // Allocator + // Allocator + // Allocator, -// MatrixN: Display, -// VectorN: Display { +// OMatrix: Display, +// OVector: Display { // let mv = &m * &eig.eigenvectors; // // println!("eigenvalues: {}eigenvectors: {}", eig.eigenvalues, eig.eigenvectors); diff --git a/tests/linalg/full_piv_lu.rs b/tests/linalg/full_piv_lu.rs index f782d8fd..7ac95b0f 100644 --- a/tests/linalg/full_piv_lu.rs +++ b/tests/linalg/full_piv_lu.rs @@ -429,9 +429,9 @@ fn insert_rows() { 0, 0, 0, 0, 0, 31, 32, 33, 34, 35); - assert_eq!(m.insert_fixed_rows::(0, 0), expected1); - assert_eq!(m.insert_fixed_rows::(3, 0), expected2); - assert_eq!(m.insert_fixed_rows::(2, 0), expected3); + assert_eq!(m.insert_fixed_rows::<2>(0, 0), expected1); + assert_eq!(m.insert_fixed_rows::<2>(3, 0), expected2); + assert_eq!(m.insert_fixed_rows::<2>(2, 0), expected3); // The following is just to verify that the return type dimensions is correctly inferred. let computed: Matrix<_, Dynamic, U5, _> = m.insert_rows(3, 2, 0); diff --git a/tests/linalg/solve.rs b/tests/linalg/solve.rs index 81cd1c71..1918af45 100644 --- a/tests/linalg/solve.rs +++ b/tests/linalg/solve.rs @@ -9,10 +9,10 @@ macro_rules! gen_tests( use crate::proptest::*; use proptest::{prop_assert, proptest}; - fn unzero_diagonal(a: &mut Matrix4) { + fn unzero_diagonal(a: &mut Matrix4) { for i in 0..4 { if a[(i, i)].norm1() < na::convert(1.0e-7) { - a[(i, i)] = N::one(); + a[(i, i)] = T::one(); } } } diff --git a/tests/proptest/mod.rs b/tests/proptest/mod.rs index be77f501..9164b95d 100644 --- a/tests/proptest/mod.rs +++ b/tests/proptest/mod.rs @@ -7,7 +7,7 @@ use nalgebra::base::dimension::*; use nalgebra::proptest::{DimRange, MatrixStrategy}; use nalgebra::{ DMatrix, DVector, DefaultAllocator, Dim, DualQuaternion, Isometry2, Isometry3, Matrix3, - MatrixMN, Point2, Point3, Quaternion, Rotation2, Rotation3, Scalar, Similarity3, Translation2, + OMatrix, Point2, Point3, Quaternion, Rotation2, Rotation3, Scalar, Similarity3, Translation2, Translation3, UnitComplex, UnitDualQuaternion, UnitQuaternion, Vector3, U3, U4, }; use num_complex::Complex; @@ -121,11 +121,11 @@ where macro_rules! define_strategies( ($($strategy_: ident $strategy: ident<$nrows: literal, $ncols: literal>),*) => {$( - pub fn $strategy() -> impl Strategy, Const<$ncols>>> { + pub fn $strategy() -> impl Strategy, Const<$ncols>>> { matrix(PROPTEST_F64, Const::<$nrows>, Const::<$ncols>) } - pub fn $strategy_(scalar_strategy: ScalarStrategy) -> impl Strategy, Const<$ncols>>> + pub fn $strategy_(scalar_strategy: ScalarStrategy) -> impl Strategy, Const<$ncols>>> where ScalarStrategy: Strategy + Clone + 'static, ScalarStrategy::Value: Scalar, { @@ -165,7 +165,7 @@ macro_rules! generate_matrix_sanity_test { proptest! { #[test] fn $test_name(a in matrix(-5 ..= 5i32, $rows, $cols)) { - // let a: MatrixMN<_, $rows, $cols> = a; + // let a: OMatrix<_, $rows, $cols> = a; let rows_range = DimRange::from($rows); let cols_range = DimRange::from($cols); prop_assert!(a.nrows() >= rows_range.lower_bound().value() @@ -218,17 +218,17 @@ fn test_matrix_output_types() { let _: MatrixStrategy<_, Dynamic, Dynamic> = matrix(-5..5, 1..=5, 1..=5); } -// Below we have some tests to ensure that specific instances of MatrixMN are usable +// Below we have some tests to ensure that specific instances of OMatrix are usable // in a typical proptest scenario where we (implicitly) use the `Arbitrary` trait proptest! { #[test] fn ensure_arbitrary_test_compiles_matrix3(_: Matrix3) {} #[test] - fn ensure_arbitrary_test_compiles_matrixmn_u3_dynamic(_: MatrixMN) {} + fn ensure_arbitrary_test_compiles_matrixmn_u3_dynamic(_: OMatrix) {} #[test] - fn ensure_arbitrary_test_compiles_matrixmn_dynamic_u3(_: MatrixMN) {} + fn ensure_arbitrary_test_compiles_matrixmn_dynamic_u3(_: OMatrix) {} #[test] fn ensure_arbitrary_test_compiles_dmatrix(_: DMatrix) {} diff --git a/tests/sparse/cs_matrix_market.rs b/tests/sparse/cs_matrix_market.rs index 7c0cee43..9490464f 100644 --- a/tests/sparse/cs_matrix_market.rs +++ b/tests/sparse/cs_matrix_market.rs @@ -18,7 +18,7 @@ fn cs_matrix_market() { % |% | <--+ % |% comments | |-- 0 or more comment lines % |% | <--+ -% | M N L | <--- rows, columns, entries +% | M T L | <--- rows, columns, entries % | I1 J1 A(I1, J1) | <--+ % | I2 J2 A(I2, J2) | | % | I3 J3 A(I3, J3) | |-- L lines