From d82b39ca9af5aab057db157fdce2f9c78a2cf477 Mon Sep 17 00:00:00 2001 From: Yuri Edward Date: Tue, 19 Oct 2021 16:01:02 +0200 Subject: [PATCH] Added to_homogeneous --- src/geometry/scale.rs | 12 ++++++++---- src/geometry/scale_conversion.rs | 4 ++-- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/src/geometry/scale.rs b/src/geometry/scale.rs index deb0116b..ead932b1 100755 --- a/src/geometry/scale.rs +++ b/src/geometry/scale.rs @@ -15,7 +15,7 @@ use crate::base::allocator::Allocator; use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::storage::Owned; use crate::base::{Const, DefaultAllocator, OMatrix, OVector, SVector, Scalar}; -use crate::{ClosedAdd, ClosedDiv}; +use crate::ClosedDiv; use crate::ClosedMul; use crate::geometry::Point; @@ -208,15 +208,19 @@ impl Scale { #[must_use] pub fn to_homogeneous(&self) -> OMatrix, U1>, DimNameSum, U1>> where - T: Zero + One + ClosedAdd + Clone, + T: Zero + One + Clone, Const: DimNameAdd, DefaultAllocator: Allocator, U1>, DimNameSum, U1>> + Allocator, U1>, U1>, { - let mut v = OVector::, U1>>::zero(); + // Unfortunately rust refuses at all costs to allow calling .to_homogeneous on a SVector + // (self.vector) so I had to do a manual copy in a new OVector + // The exact error is that to_homogeneous when called on a SVector requires DimAdd on Const + // not DimNameAdd which will strangely bring rust into thinking that DimNameAdd is a + // trait object and no longer a generic parameter. + let mut v = OVector::, U1>>::from_element(T::one()); for i in 0..D { v[(i, 0)] = self.vector[(i, 0)].clone(); } - v[(D, 0)] = T::one(); return OMatrix::, U1>, DimNameSum, U1>>::from_diagonal(&v); } diff --git a/src/geometry/scale_conversion.rs b/src/geometry/scale_conversion.rs index e6f8573b..4b627e5c 100644 --- a/src/geometry/scale_conversion.rs +++ b/src/geometry/scale_conversion.rs @@ -10,7 +10,7 @@ use crate::base::{Const, DefaultAllocator, DimName, OMatrix, OVector, SVector, S use crate::geometry::{ SuperTCategoryOf, TAffine, Transform, Scale }; -use crate::{ClosedAdd, Point}; +use crate::Point; /* * This file provides the following conversions: @@ -112,7 +112,7 @@ where } } -impl From> +impl From> for OMatrix, U1>, DimNameSum, U1>> where Const: DimNameAdd,