Added to_homogeneous

This commit is contained in:
Yuri Edward 2021-10-19 16:01:02 +02:00
parent f1f947b924
commit d82b39ca9a
2 changed files with 10 additions and 6 deletions

View File

@ -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<T: Scalar, const D: usize> Scale<T, D> {
#[must_use]
pub fn to_homogeneous(&self) -> OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>
where
T: Zero + One + ClosedAdd + Clone,
T: Zero + One + Clone,
Const<D>: DimNameAdd<U1>,
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> + Allocator<T, DimNameSum<Const<D>, U1>, U1>,
{
let mut v = OVector::<T, DimNameSum<Const<D>, 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<D>
// 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::<T, DimNameSum<Const<D>, 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::<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>::from_diagonal(&v);
}

View File

@ -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<T: Scalar + Zero + One + ClosedAdd, const D: usize> From<Scale<T, D>>
impl<T: Scalar + Zero + One, const D: usize> From<Scale<T, D>>
for OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>
where
Const<D>: DimNameAdd<U1>,