Mint rebase

This commit is contained in:
Dzmitry Malyshau 2017-10-09 13:58:09 -04:00 committed by Sébastien Crozet
parent 6b6a0717c2
commit 94db3f533b
6 changed files with 96 additions and 107 deletions

View File

@ -222,10 +222,9 @@ impl_from_into_asref_2D!(
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
macro_rules! impl_from_into_mint_1D( macro_rules! impl_from_into_mint_1D(
($($NRows: ident => $VT:ident [$SZ: expr]);* $(;)*) => {$( ($($NRows: ident => $VT:ident [$SZ: expr]);* $(;)*) => {$(
impl<N, S> From<mint::$VT<N>> for Matrix<N, $NRows, U1, S> impl<N> From<mint::$VT<N>> for MatrixMN<N, $NRows, U1>
where N: Scalar, where N: Scalar,
S: OwnedStorage<N, $NRows, U1>, DefaultAllocator: Allocator<N, $NRows, U1> {
S::Alloc: OwnedAllocator<N, $NRows, U1, S> {
#[inline] #[inline]
fn from(v: mint::$VT<N>) -> Self { fn from(v: mint::$VT<N>) -> Self {
unsafe { unsafe {
@ -239,8 +238,7 @@ macro_rules! impl_from_into_mint_1D(
impl<N, S> Into<mint::$VT<N>> for Matrix<N, $NRows, U1, S> impl<N, S> Into<mint::$VT<N>> for Matrix<N, $NRows, U1, S>
where N: Scalar, where N: Scalar,
S: OwnedStorage<N, $NRows, U1>, S: ContiguousStorage<N, $NRows, U1> {
S::Alloc: OwnedAllocator<N, $NRows, U1, S> {
#[inline] #[inline]
fn into(self) -> mint::$VT<N> { fn into(self) -> mint::$VT<N> {
unsafe { unsafe {
@ -254,8 +252,7 @@ macro_rules! impl_from_into_mint_1D(
impl<N, S> AsRef<mint::$VT<N>> for Matrix<N, $NRows, U1, S> impl<N, S> AsRef<mint::$VT<N>> for Matrix<N, $NRows, U1, S>
where N: Scalar, where N: Scalar,
S: OwnedStorage<N, $NRows, U1>, S: ContiguousStorage<N, $NRows, U1> {
S::Alloc: OwnedAllocator<N, $NRows, U1, S> {
#[inline] #[inline]
fn as_ref(&self) -> &mint::$VT<N> { fn as_ref(&self) -> &mint::$VT<N> {
unsafe { unsafe {
@ -266,8 +263,7 @@ macro_rules! impl_from_into_mint_1D(
impl<N, S> AsMut<mint::$VT<N>> for Matrix<N, $NRows, U1, S> impl<N, S> AsMut<mint::$VT<N>> for Matrix<N, $NRows, U1, S>
where N: Scalar, where N: Scalar,
S: OwnedStorage<N, $NRows, U1>, S: ContiguousStorageMut<N, $NRows, U1> {
S::Alloc: OwnedAllocator<N, $NRows, U1, S> {
#[inline] #[inline]
fn as_mut(&mut self) -> &mut mint::$VT<N> { fn as_mut(&mut self) -> &mut mint::$VT<N> {
unsafe { unsafe {
@ -289,10 +285,9 @@ impl_from_into_mint_1D!(
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
macro_rules! impl_from_into_mint_2D( macro_rules! impl_from_into_mint_2D(
($(($NRows: ty, $NCols: ty) => $MV:ident{ $($component:ident),* }[$SZRows: expr]);* $(;)*) => {$( ($(($NRows: ty, $NCols: ty) => $MV:ident{ $($component:ident),* }[$SZRows: expr]);* $(;)*) => {$(
impl<N, S> From<mint::$MV<N>> for Matrix<N, $NRows, $NCols, S> impl<N> From<mint::$MV<N>> for MatrixMN<N, $NRows, $NCols>
where N: Scalar, where N: Scalar,
S: OwnedStorage<N, $NRows, $NCols>, DefaultAllocator: Allocator<N, $NRows, $NCols> {
S::Alloc: OwnedAllocator<N, $NRows, $NCols, S> {
#[inline] #[inline]
fn from(m: mint::$MV<N>) -> Self { fn from(m: mint::$MV<N>) -> Self {
unsafe { unsafe {
@ -308,10 +303,9 @@ macro_rules! impl_from_into_mint_2D(
} }
} }
impl<N, S> Into<mint::$MV<N>> for Matrix<N, $NRows, $NCols, S> impl<N> Into<mint::$MV<N>> for MatrixMN<N, $NRows, $NCols>
where N: Scalar, where N: Scalar,
S: OwnedStorage<N, $NRows, $NCols>, DefaultAllocator: Allocator<N, $NRows, $NCols> {
S::Alloc: OwnedAllocator<N, $NRows, $NCols, S> {
#[inline] #[inline]
fn into(self) -> mint::$MV<N> { fn into(self) -> mint::$MV<N> {
unsafe { unsafe {

View File

@ -3,10 +3,11 @@ use num::Zero;
use alga::general::{SubsetOf, SupersetOf, Real}; use alga::general::{SubsetOf, SupersetOf, Real};
use alga::linear::Rotation as AlgaRotation; use alga::linear::Rotation as AlgaRotation;
#[cfg(feature = "mint")]
use mint;
use core::{Vector4, Matrix4}; use core::{Vector4, Matrix4};
use core::dimension::U3; use core::dimension::U3;
#[cfg(feature = "mint")]
use core::storage::Storage;
use geometry::{Quaternion, UnitQuaternion, Rotation, Isometry, Similarity, use geometry::{Quaternion, UnitQuaternion, Rotation, Isometry, Similarity,
Transform, SuperTCategoryOf, TAffine, Translation, Transform, SuperTCategoryOf, TAffine, Translation,
Rotation3, Point3}; Rotation3, Point3};
@ -173,19 +174,14 @@ impl<N1: Real, N2: Real + SupersetOf<N1>> SubsetOf<Matrix4<N2>> for UnitQuaterni
} }
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
impl<N, S> From<mint::Quaternion<N>> for QuaternionBase<N, S> impl<N: Real> From<mint::Quaternion<N>> for Quaternion<N> {
where
N: Real,
S: OwnedStorage<N, U4, U1>,
S::Alloc: OwnedAllocator<N, U4, U1, S> {
fn from(q: mint::Quaternion<N>) -> Self { fn from(q: mint::Quaternion<N>) -> 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")] #[cfg(feature = "mint")]
impl<N: Real, S: Storage<N, U4, U1>> Into<mint::Quaternion<N>> for QuaternionBase<N, S> { impl<N: Real> Into<mint::Quaternion<N>> for Quaternion<N> {
fn into(self) -> mint::Quaternion<N> { fn into(self) -> mint::Quaternion<N> {
mint::Quaternion { mint::Quaternion {
v: mint::Vector3 { v: mint::Vector3 {
@ -199,7 +195,7 @@ impl<N: Real, S: Storage<N, U4, U1>> Into<mint::Quaternion<N>> for QuaternionBas
} }
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
impl<N: Real, S: Storage<N, U4, U1>> Into<mint::Quaternion<N>> for UnitQuaternionBase<N, S> { impl<N: Real> Into<mint::Quaternion<N>> for UnitQuaternion<N> {
fn into(self) -> mint::Quaternion<N> { fn into(self) -> mint::Quaternion<N> {
mint::Quaternion { mint::Quaternion {
v: mint::Vector3 { v: mint::Vector3 {

View File

@ -3,6 +3,9 @@ use num::Zero;
use alga::general::{Real, SubsetOf, SupersetOf}; use alga::general::{Real, SubsetOf, SupersetOf};
use alga::linear::Rotation as AlgaRotation; use alga::linear::Rotation as AlgaRotation;
#[cfg(feature = "mint")]
use mint;
use core::{DefaultAllocator, MatrixN}; use core::{DefaultAllocator, MatrixN};
use core::dimension::{DimName, DimNameSum, DimNameAdd, DimMin, U1}; use core::dimension::{DimName, DimNameSum, DimNameAdd, DimMin, U1};
use core::allocator::Allocator; use core::allocator::Allocator;
@ -22,7 +25,7 @@ use geometry::{Point, Translation, Rotation, UnitQuaternion, UnitComplex, Isomet
* Rotation -> Similarity * Rotation -> Similarity
* Rotation -> Transform * Rotation -> Transform
* Rotation -> Matrix (homogeneous) * Rotation -> Matrix (homogeneous)
* mint::EulerAngles -> RotationBase * mint::EulerAngles -> Rotation
*/ */
@ -205,11 +208,7 @@ impl<N1, N2, D> SubsetOf<MatrixN<N2, DimNameSum<D, U1>>> for Rotation<N1, D>
} }
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
impl<N, S> From<mint::EulerAngles<N, mint::IntraXYZ>> for RotationBase<N, U3, S> impl<N: Real> From<mint::EulerAngles<N, mint::IntraXYZ>> for Rotation3<N> {
where N: Real,
S: OwnedStorage<N, U3, U3>,
S::Alloc: OwnedAllocator<N, U3, U3, S> {
fn from(euler: mint::EulerAngles<N, mint::IntraXYZ>) -> Self { fn from(euler: mint::EulerAngles<N, mint::IntraXYZ>) -> Self {
Self::from_euler_angles(euler.a, euler.b, euler.c) Self::from_euler_angles(euler.a, euler.b, euler.c)
} }

View File

@ -11,8 +11,6 @@ use na::{
Matrix6x2, Matrix6x3, Matrix6x4, Matrix6x5, Matrix6x2, Matrix6x3, Matrix6x4, Matrix6x5,
Point3, Translation3, Isometry3, Similarity3, Affine3, Point3, Translation3, Isometry3, Similarity3, Affine3,
Projective3, Transform3, Rotation3, UnitQuaternion}; Projective3, Transform3, Rotation3, UnitQuaternion};
#[cfg(feature = "mint")]
use na::Quaternion;
#[cfg(feature = "arbitrary")] #[cfg(feature = "arbitrary")]
@ -257,74 +255,3 @@ array_matrix_conversion!(
array_matrix_conversion_6_5, Matrix6x5, (6, 5); array_matrix_conversion_6_5, Matrix6x5, (6, 5);
array_matrix_conversion_6_6, Matrix6, (6, 6); 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<usize> = v.into();
let mv_ref: &mint::$Vector<usize> = 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<f64> = 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<usize> = 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);
);

73
tests/core/mint.rs Normal file
View File

@ -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<usize> = v.into();
let mv_ref: &mint::$Vector<usize> = 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<f64> = 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<usize> = 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);
);

View File

@ -7,4 +7,4 @@ mod serde;
#[cfg(feature = "abomonation-serialize")] #[cfg(feature = "abomonation-serialize")]
mod abomonation; mod abomonation;
#[cfg(feature = "mint")] #[cfg(feature = "mint")]
extern crate mint; mod mint;