Added to_homogeneous
This commit is contained in:
parent
f1f947b924
commit
d82b39ca9a
|
@ -15,7 +15,7 @@ use crate::base::allocator::Allocator;
|
||||||
use crate::base::dimension::{DimNameAdd, DimNameSum, U1};
|
use crate::base::dimension::{DimNameAdd, DimNameSum, U1};
|
||||||
use crate::base::storage::Owned;
|
use crate::base::storage::Owned;
|
||||||
use crate::base::{Const, DefaultAllocator, OMatrix, OVector, SVector, Scalar};
|
use crate::base::{Const, DefaultAllocator, OMatrix, OVector, SVector, Scalar};
|
||||||
use crate::{ClosedAdd, ClosedDiv};
|
use crate::ClosedDiv;
|
||||||
use crate::ClosedMul;
|
use crate::ClosedMul;
|
||||||
|
|
||||||
use crate::geometry::Point;
|
use crate::geometry::Point;
|
||||||
|
@ -208,15 +208,19 @@ impl<T: Scalar, const D: usize> Scale<T, D> {
|
||||||
#[must_use]
|
#[must_use]
|
||||||
pub fn to_homogeneous(&self) -> OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>
|
pub fn to_homogeneous(&self) -> OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>
|
||||||
where
|
where
|
||||||
T: Zero + One + ClosedAdd + Clone,
|
T: Zero + One + Clone,
|
||||||
Const<D>: DimNameAdd<U1>,
|
Const<D>: DimNameAdd<U1>,
|
||||||
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> + Allocator<T, DimNameSum<Const<D>, U1>, 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 {
|
for i in 0..D {
|
||||||
v[(i, 0)] = self.vector[(i, 0)].clone();
|
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);
|
return OMatrix::<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>::from_diagonal(&v);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,7 @@ use crate::base::{Const, DefaultAllocator, DimName, OMatrix, OVector, SVector, S
|
||||||
use crate::geometry::{
|
use crate::geometry::{
|
||||||
SuperTCategoryOf, TAffine, Transform, Scale
|
SuperTCategoryOf, TAffine, Transform, Scale
|
||||||
};
|
};
|
||||||
use crate::{ClosedAdd, Point};
|
use crate::Point;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file provides the following conversions:
|
* 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>>
|
for OMatrix<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>
|
||||||
where
|
where
|
||||||
Const<D>: DimNameAdd<U1>,
|
Const<D>: DimNameAdd<U1>,
|
||||||
|
|
Loading…
Reference in New Issue