diff --git a/src/core/conversion.rs b/src/core/conversion.rs index 34486c4a..de4f177e 100644 --- a/src/core/conversion.rs +++ b/src/core/conversion.rs @@ -222,10 +222,9 @@ impl_from_into_asref_2D!( #[cfg(feature = "mint")] macro_rules! impl_from_into_mint_1D( ($($NRows: ident => $VT:ident [$SZ: expr]);* $(;)*) => {$( - impl From> for Matrix + impl From> for MatrixMN where N: Scalar, - S: OwnedStorage, - S::Alloc: OwnedAllocator { + DefaultAllocator: Allocator { #[inline] fn from(v: mint::$VT) -> Self { unsafe { @@ -239,8 +238,7 @@ macro_rules! impl_from_into_mint_1D( impl Into> for Matrix where N: Scalar, - S: OwnedStorage, - S::Alloc: OwnedAllocator { + S: ContiguousStorage { #[inline] fn into(self) -> mint::$VT { unsafe { @@ -254,8 +252,7 @@ macro_rules! impl_from_into_mint_1D( impl AsRef> for Matrix where N: Scalar, - S: OwnedStorage, - S::Alloc: OwnedAllocator { + S: ContiguousStorage { #[inline] fn as_ref(&self) -> &mint::$VT { unsafe { @@ -266,8 +263,7 @@ macro_rules! impl_from_into_mint_1D( impl AsMut> for Matrix where N: Scalar, - S: OwnedStorage, - S::Alloc: OwnedAllocator { + S: ContiguousStorageMut { #[inline] fn as_mut(&mut self) -> &mut mint::$VT { unsafe { @@ -289,10 +285,9 @@ impl_from_into_mint_1D!( #[cfg(feature = "mint")] macro_rules! impl_from_into_mint_2D( ($(($NRows: ty, $NCols: ty) => $MV:ident{ $($component:ident),* }[$SZRows: expr]);* $(;)*) => {$( - impl From> for Matrix + impl From> for MatrixMN where N: Scalar, - S: OwnedStorage, - S::Alloc: OwnedAllocator { + DefaultAllocator: Allocator { #[inline] fn from(m: mint::$MV) -> Self { unsafe { @@ -308,10 +303,9 @@ macro_rules! impl_from_into_mint_2D( } } - impl Into> for Matrix + impl Into> for MatrixMN where N: Scalar, - S: OwnedStorage, - S::Alloc: OwnedAllocator { + DefaultAllocator: Allocator { #[inline] fn into(self) -> mint::$MV { unsafe { diff --git a/src/geometry/quaternion_conversion.rs b/src/geometry/quaternion_conversion.rs index 7f1e2c5e..67d02909 100644 --- a/src/geometry/quaternion_conversion.rs +++ b/src/geometry/quaternion_conversion.rs @@ -3,10 +3,11 @@ use num::Zero; use alga::general::{SubsetOf, SupersetOf, Real}; use alga::linear::Rotation as AlgaRotation; +#[cfg(feature = "mint")] +use mint; + use core::{Vector4, Matrix4}; use core::dimension::U3; -#[cfg(feature = "mint")] -use core::storage::Storage; use geometry::{Quaternion, UnitQuaternion, Rotation, Isometry, Similarity, Transform, SuperTCategoryOf, TAffine, Translation, Rotation3, Point3}; @@ -173,19 +174,14 @@ impl> SubsetOf> for UnitQuaterni } #[cfg(feature = "mint")] -impl From> for QuaternionBase -where - N: Real, - S: OwnedStorage, - S::Alloc: OwnedAllocator { - +impl From> for Quaternion { fn from(q: mint::Quaternion) -> Self { - QuaternionBase::new(q.s, q.v.x, q.v.y, q.v.z) + Quaternion::new(q.s, q.v.x, q.v.y, q.v.z) } } #[cfg(feature = "mint")] -impl> Into> for QuaternionBase { +impl Into> for Quaternion { fn into(self) -> mint::Quaternion { mint::Quaternion { v: mint::Vector3 { @@ -199,7 +195,7 @@ impl> Into> for QuaternionBas } #[cfg(feature = "mint")] -impl> Into> for UnitQuaternionBase { +impl Into> for UnitQuaternion { fn into(self) -> mint::Quaternion { mint::Quaternion { v: mint::Vector3 { diff --git a/src/geometry/rotation_conversion.rs b/src/geometry/rotation_conversion.rs index 07ef9d81..9c37594f 100644 --- a/src/geometry/rotation_conversion.rs +++ b/src/geometry/rotation_conversion.rs @@ -3,6 +3,9 @@ use num::Zero; use alga::general::{Real, SubsetOf, SupersetOf}; use alga::linear::Rotation as AlgaRotation; +#[cfg(feature = "mint")] +use mint; + use core::{DefaultAllocator, MatrixN}; use core::dimension::{DimName, DimNameSum, DimNameAdd, DimMin, U1}; use core::allocator::Allocator; @@ -22,8 +25,8 @@ use geometry::{Point, Translation, Rotation, UnitQuaternion, UnitComplex, Isomet * Rotation -> Similarity * Rotation -> Transform * Rotation -> Matrix (homogeneous) - * mint::EulerAngles -> RotationBase - + * mint::EulerAngles -> Rotation + */ @@ -205,11 +208,7 @@ impl SubsetOf>> for Rotation } #[cfg(feature = "mint")] -impl From> for RotationBase -where N: Real, - S: OwnedStorage, - S::Alloc: OwnedAllocator { - +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/conversion.rs b/tests/core/conversion.rs index 355dcb14..d2dfbcea 100644 --- a/tests/core/conversion.rs +++ b/tests/core/conversion.rs @@ -11,8 +11,6 @@ use na::{ Matrix6x2, Matrix6x3, Matrix6x4, Matrix6x5, Point3, Translation3, Isometry3, Similarity3, Affine3, Projective3, Transform3, Rotation3, UnitQuaternion}; -#[cfg(feature = "mint")] -use na::Quaternion; #[cfg(feature = "arbitrary")] @@ -257,74 +255,3 @@ array_matrix_conversion!( array_matrix_conversion_6_5, Matrix6x5, (6, 5); array_matrix_conversion_6_6, Matrix6, (6, 6); ); - -#[cfg(feature = "mint")] -macro_rules! mint_vector_conversion( - ($($mint_vector_conversion_i: ident, $Vector: ident, $SZ: expr);* $(;)*) => {$( - #[test] - fn $mint_vector_conversion_i() { - let v = $Vector::from_fn(|i, _| i); - let mv: mint::$Vector = v.into(); - let mv_ref: &mint::$Vector = v.as_ref(); - let v2 = $Vector::from(mv); - let arr: [usize; $SZ] = mv.into(); - - for i in 0 .. $SZ { - assert_eq!(arr[i], i); - } - - assert_eq!(&mv, mv_ref); - assert_eq!(v, v2); - } - )*} -); - -#[cfg(feature = "mint")] -mint_vector_conversion!( - mint_vector_conversion_2, Vector2, 2; - mint_vector_conversion_3, Vector3, 3; - mint_vector_conversion_4, Vector4, 4; -); - - -#[test] -fn mint_quaternion_conversions() { - let q = Quaternion::new(0.1f64, 0.2, 0.3, 0.4); - let mq: mint::Quaternion = q.into(); - let q2 = Quaternion::from(mq); - - assert_eq!(mq.v.x, q[0]); - assert_eq!(mq.v.y, q[1]); - assert_eq!(mq.v.z, q[2]); - assert_eq!(mq.s, q[3]); - - assert_eq!(q, q2); -} - -macro_rules! mint_matrix_conversion( - ($($mint_matrix_conversion_i_j: ident, $Matrix: ident, $Mint: ident, ($NRows: expr, $NCols: expr));* $(;)*) => {$( - #[test] - fn $mint_matrix_conversion_i_j() { - let m = $Matrix::from_fn(|i, j| i * 10 + j); - let mm: mint::$Mint = m.into(); - let m2 = $Matrix::from(mm); - let arr: [[usize; $NRows]; $NCols] = mm.into(); - - for i in 0 .. $NRows { - for j in 0 .. $NCols { - assert_eq!(arr[j][i], i * 10 + j); - } - } - - assert_eq!(m, m2); - } - )*} -); - -mint_matrix_conversion!( - mint_matrix_conversion_2_2, Matrix2, ColumnMatrix2, (2, 2); - mint_matrix_conversion_3_2, Matrix3x2, ColumnMatrix3x2, (3, 2); - mint_matrix_conversion_3_3, Matrix3, ColumnMatrix3, (3, 3); - mint_matrix_conversion_4_3, Matrix4x3, ColumnMatrix4x3, (4, 3); - mint_matrix_conversion_4_4, Matrix4, ColumnMatrix4, (4, 4); -); diff --git a/tests/core/mint.rs b/tests/core/mint.rs new file mode 100644 index 00000000..264d8209 --- /dev/null +++ b/tests/core/mint.rs @@ -0,0 +1,73 @@ +use mint; +use na::{ + Matrix2, Matrix3, Matrix4, Matrix3x2, Matrix4x3, + Quaternion, Vector2, Vector3, Vector4, +}; + +macro_rules! mint_vector_conversion( + ($($mint_vector_conversion_i: ident, $Vector: ident, $SZ: expr);* $(;)*) => {$( + #[test] + fn $mint_vector_conversion_i() { + let v = $Vector::from_fn(|i, _| i); + let mv: mint::$Vector = v.into(); + let mv_ref: &mint::$Vector = v.as_ref(); + let v2 = $Vector::from(mv); + let arr: [usize; $SZ] = mv.into(); + + for i in 0 .. $SZ { + assert_eq!(arr[i], i); + } + + assert_eq!(&mv, mv_ref); + assert_eq!(v, v2); + } + )*} +); + +mint_vector_conversion!( + mint_vector_conversion_2, Vector2, 2; + mint_vector_conversion_3, Vector3, 3; + mint_vector_conversion_4, Vector4, 4; +); + +#[test] +fn mint_quaternion_conversions() { + let q = Quaternion::new(0.1f64, 0.2, 0.3, 0.4); + let mq: mint::Quaternion = q.into(); + let q2 = Quaternion::from(mq); + + assert_eq!(mq.v.x, q[0]); + assert_eq!(mq.v.y, q[1]); + assert_eq!(mq.v.z, q[2]); + assert_eq!(mq.s, q[3]); + + assert_eq!(q, q2); +} + +macro_rules! mint_matrix_conversion( + ($($mint_matrix_conversion_i_j: ident, $Matrix: ident, $Mint: ident, ($NRows: expr, $NCols: expr));* $(;)*) => {$( + #[test] + fn $mint_matrix_conversion_i_j() { + let m = $Matrix::from_fn(|i, j| i * 10 + j); + let mm: mint::$Mint = m.into(); + let m2 = $Matrix::from(mm); + let arr: [[usize; $NRows]; $NCols] = mm.into(); + + for i in 0 .. $NRows { + for j in 0 .. $NCols { + assert_eq!(arr[j][i], i * 10 + j); + } + } + + assert_eq!(m, m2); + } + )*} +); + +mint_matrix_conversion!( + mint_matrix_conversion_2_2, Matrix2, ColumnMatrix2, (2, 2); + mint_matrix_conversion_3_2, Matrix3x2, ColumnMatrix3x2, (3, 2); + mint_matrix_conversion_3_3, Matrix3, ColumnMatrix3, (3, 3); + mint_matrix_conversion_4_3, Matrix4x3, ColumnMatrix4x3, (4, 3); + mint_matrix_conversion_4_4, Matrix4, ColumnMatrix4, (4, 4); +); diff --git a/tests/core/mod.rs b/tests/core/mod.rs index 95a54767..e8bac456 100644 --- a/tests/core/mod.rs +++ b/tests/core/mod.rs @@ -7,4 +7,4 @@ mod serde; #[cfg(feature = "abomonation-serialize")] mod abomonation; #[cfg(feature = "mint")] -extern crate mint; +mod mint;