From 72f61918f4af0cae7689c8205e69a749c04ad811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20G=C3=B6rtler?= Date: Mon, 19 Nov 2018 21:21:25 +0100 Subject: [PATCH] RFC: Fix type annotations --- src/base/matrix.rs | 14 ++++++++------ tests/core/matrix.rs | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/base/matrix.rs b/src/base/matrix.rs index 8f700ea9..73fb886d 100644 --- a/src/base/matrix.rs +++ b/src/base/matrix.rs @@ -20,7 +20,7 @@ use alga::general::{ClosedAdd, ClosedMul, ClosedSub, Real, Ring}; use base::allocator::{Allocator, SameShapeAllocator, SameShapeC, SameShapeR}; use base::constraint::{DimEq, SameNumberOfColumns, SameNumberOfRows, ShapeConstraint}; -use base::dimension::{Dim, DimNameAdd, DimAdd, DimNameSum, DimSum, IsNotStaticOne, U1, U2, U3}; +use base::dimension::{Dim, DimAdd, DimSum, IsNotStaticOne, U1, U2, U3}; use base::iter::{MatrixIter, MatrixIterMut}; use base::storage::{ ContiguousStorage, ContiguousStorageMut, Owned, SameShapeStorage, Storage, StorageMut, @@ -830,15 +830,17 @@ impl> SquareMatrix { } } -impl + IsNotStaticOne> MatrixN { +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> - where DefaultAllocator: Allocator, DimNameSum> { - let mut res = MatrixN::>::identity(); - res.fixed_slice_mut::(0, 0).copy_from(&self); + pub fn to_homogeneous(&self) -> MatrixN> + where 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); + res.generic_slice_mut::((0, 0), self.data.shape()).copy_from(&self); res } diff --git a/tests/core/matrix.rs b/tests/core/matrix.rs index 18dfdcf2..2569ea7a 100644 --- a/tests/core/matrix.rs +++ b/tests/core/matrix.rs @@ -278,7 +278,7 @@ fn to_homogeneous() { let c = Matrix2::new(1.0, 2.0, 3.0, 4.0); let expected_c = Matrix3::new(1.0, 2.0, 0.0, 3.0, 4.0, 0.0, 0.0, 0.0, 1.0); - let d = DMatrix::from_row_slice(2, &[1.0, 2.0, 3.0, 4.0]); + let d = DMatrix::from_row_slice(2, 2, &[1.0, 2.0, 3.0, 4.0]); let expected_d = DMatrix::from_row_slice(3, 3, &[1.0, 2.0, 0.0, 3.0, 4.0, 0.0, 0.0, 0.0, 1.0]); assert_eq!(a.to_homogeneous(), expected_a);