Added to_homogeneous

This commit is contained in:
Yuri Edward 2021-10-19 15:55:06 +02:00
parent c249cc76b0
commit f1f947b924
2 changed files with 21 additions and 10 deletions

View File

@ -14,8 +14,8 @@ use abomonation::Abomonation;
use crate::base::allocator::Allocator; 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, SVector, Scalar}; use crate::base::{Const, DefaultAllocator, OMatrix, OVector, SVector, Scalar};
use crate::ClosedDiv; use crate::{ClosedAdd, ClosedDiv};
use crate::ClosedMul; use crate::ClosedMul;
use crate::geometry::Point; use crate::geometry::Point;
@ -208,11 +208,16 @@ 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, T: Zero + One + ClosedAdd + Clone,
Const<D>: DimNameAdd<U1>, Const<D>: DimNameAdd<U1>,
DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>, DefaultAllocator: Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> + Allocator<T, DimNameSum<Const<D>, U1>, U1>,
{ {
todo!(); let mut v = OVector::<T, DimNameSum<Const<D>, U1>>::zero();
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);
} }
/// Inverts `self` in-place. /// Inverts `self` in-place.

View File

@ -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::Point; use crate::{ClosedAdd, Point};
/* /*
* This file provides the following conversions: * This file provides the following conversions:
@ -50,7 +50,9 @@ where
T2: RealField + SupersetOf<T1>, T2: RealField + SupersetOf<T1>,
C: SuperTCategoryOf<TAffine>, C: SuperTCategoryOf<TAffine>,
Const<D>: DimNameAdd<U1>, Const<D>: DimNameAdd<U1>,
DefaultAllocator: Allocator<T1, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> DefaultAllocator:
Allocator<T1, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>
+ Allocator<T1, DimNameSum<Const<D>, U1>, U1>
+ Allocator<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>, + Allocator<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
{ {
#[inline] #[inline]
@ -75,7 +77,9 @@ where
T1: RealField, T1: RealField,
T2: RealField + SupersetOf<T1>, T2: RealField + SupersetOf<T1>,
Const<D>: DimNameAdd<U1>, Const<D>: DimNameAdd<U1>,
DefaultAllocator: Allocator<T1, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> DefaultAllocator:
Allocator<T1, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>
+ Allocator<T1, DimNameSum<Const<D>, U1>, U1>
+ Allocator<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>, + Allocator<T2, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>,
// + Allocator<T1, D> // + Allocator<T1, D>
// + Allocator<T2, D> // + Allocator<T2, D>
@ -108,12 +112,14 @@ where
} }
} }
impl<T: Scalar + Zero + One, const D: usize> From<Scale<T, D>> impl<T: Scalar + Zero + One + ClosedAdd, 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>,
DefaultAllocator: DefaultAllocator:
Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>> + Allocator<T, Const<D>>, Allocator<T, DimNameSum<Const<D>, U1>, DimNameSum<Const<D>, U1>>
+ Allocator<T, DimNameSum<Const<D>, U1>, U1>
+ Allocator<T, Const<D>>,
{ {
#[inline] #[inline]
fn from(t: Scale<T, D>) -> Self { fn from(t: Scale<T, D>) -> Self {