From b398a5e1894300d4e3efdd4ccf0e528700513093 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Crozet=20S=C3=A9bastien?= Date: Thu, 6 May 2021 18:22:04 +0200 Subject: [PATCH] Re-add conversion between arrays and row vectors. --- src/base/conversion.rs | 24 ++++++++++++++++++++++-- tests/core/conversion.rs | 11 ++--------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/base/conversion.rs b/src/base/conversion.rs index b329dba1..532ab8ed 100644 --- a/src/base/conversion.rs +++ b/src/base/conversion.rs @@ -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 SubsetOf> for OMatrix where R1: Dim, @@ -118,6 +118,26 @@ impl Into<[T; D]> for SVector { } } +impl From<[T; D]> for RowSVector +where + Const: IsNotStaticOne, +{ + #[inline] + fn from(arr: [T; D]) -> Self { + SVector::::from(arr).transpose() + } +} + +impl Into<[T; D]> for RowSVector +where + Const: IsNotStaticOne, +{ + #[inline] + fn into(self) -> [T; D] { + self.transpose().into() + } +} + macro_rules! impl_from_into_asref_1D( ($(($NRows: ident, $NCols: ident) => $SZ: expr);* $(;)*) => {$( impl AsRef<[T; $SZ]> for Matrix diff --git a/tests/core/conversion.rs b/tests/core/conversion.rs index 58ac179a..5374c399 100644 --- a/tests/core/conversion.rs +++ b/tests/core/conversion.rs @@ -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, @@ -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 = na::convert(t); let sim: Similarity3 = na::convert(t); let aff: Affine3 = na::convert(t); @@ -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);