Skip to content

Commit

Permalink
Merge pull request #890 from dimforge/row_vector_array_convert
Browse files Browse the repository at this point in the history
Re-add conversion between arrays and row vectors.
  • Loading branch information
sebcrozet committed May 9, 2021
2 parents d268c4d + b398a5e commit 02614cb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
24 changes: 22 additions & 2 deletions src/base/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ use crate::base::{
use crate::base::{DVector, VecStorage};
use crate::base::{SliceStorage, SliceStorageMut};
use crate::constraint::DimEq;
use crate::{SMatrix, SVector};
use crate::{IsNotStaticOne, RowSVector, SMatrix, SVector};

// TODO: too bad this won't work allo slice conversions.
// TODO: too bad this won't work for slice conversions.
impl<T1, T2, R1, C1, R2, C2> SubsetOf<OMatrix<T2, R2, C2>> for OMatrix<T1, R1, C1>
where
R1: Dim,
Expand Down Expand Up @@ -118,6 +118,26 @@ impl<T: Scalar, const D: usize> Into<[T; D]> for SVector<T, D> {
}
}

impl<T: Scalar, const D: usize> From<[T; D]> for RowSVector<T, D>
where
Const<D>: IsNotStaticOne,
{
#[inline]
fn from(arr: [T; D]) -> Self {
SVector::<T, D>::from(arr).transpose()
}
}

impl<T: Scalar, const D: usize> Into<[T; D]> for RowSVector<T, D>
where
Const<D>: IsNotStaticOne,
{
#[inline]
fn into(self) -> [T; D] {
self.transpose().into()
}
}

macro_rules! impl_from_into_asref_1D(
($(($NRows: ident, $NCols: ident) => $SZ: expr);* $(;)*) => {$(
impl<T, S> AsRef<[T; $SZ]> for Matrix<T, $NRows, $NCols, S>
Expand Down
11 changes: 2 additions & 9 deletions tests/core/conversion.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#![cfg(all(feature = "proptest-support", feature = "alga"))]
use alga::linear::Transformation;
#![cfg(all(feature = "proptest-support"))]
use na::{
self, Affine3, Isometry3, Matrix2, Matrix2x3, Matrix2x4, Matrix2x5, Matrix2x6, Matrix3,
Matrix3x2, Matrix3x4, Matrix3x5, Matrix3x6, Matrix4, Matrix4x2, Matrix4x3, Matrix4x5,
Expand All @@ -16,7 +15,7 @@ use proptest::{prop_assert, prop_assert_eq, proptest};

proptest! {
#[test]
fn translation_conversion(t in translation3(), v in vector3(), p in point3()) {
fn translation_conversion(t in translation3(), p in point3()) {
let iso: Isometry3<f64> = na::convert(t);
let sim: Similarity3<f64> = na::convert(t);
let aff: Affine3<f64> = na::convert(t);
Expand All @@ -29,12 +28,6 @@ proptest! {
prop_assert_eq!(t, na::try_convert(prj).unwrap());
prop_assert_eq!(t, na::try_convert(tr).unwrap() );

prop_assert_eq!(t.transform_vector(&v), iso * v);
prop_assert_eq!(t.transform_vector(&v), sim * v);
prop_assert_eq!(t.transform_vector(&v), aff * v);
prop_assert_eq!(t.transform_vector(&v), prj * v);
prop_assert_eq!(t.transform_vector(&v), tr * v);

prop_assert_eq!(t * p, iso * p);
prop_assert_eq!(t * p, sim * p);
prop_assert_eq!(t * p, aff * p);
Expand Down

0 comments on commit 02614cb

Please sign in to comment.