use num::{One, Zero}; use alga::general::{SubsetOf, SupersetOf, ClosedDiv}; use core::{Scalar, Matrix, ColumnVector, OwnedColumnVector}; use core::dimension::{DimName, DimNameSum, DimNameAdd, U1}; use core::storage::OwnedStorage; use core::allocator::{Allocator, OwnedAllocator}; use geometry::{PointBase, OwnedPoint}; /* * This file provides the following conversions: * ============================================= * * PointBase -> PointBase * PointBase -> ColumnVector (homogeneous) */ impl SubsetOf> for PointBase where D: DimName, N1: Scalar, N2: Scalar + SupersetOf, SA: OwnedStorage, SB: OwnedStorage, SB::Alloc: OwnedAllocator, SA::Alloc: OwnedAllocator { #[inline] fn to_superset(&self) -> PointBase { PointBase::from_coordinates(self.coords.to_superset()) } #[inline] fn is_in_subset(m: &PointBase) -> bool { // FIXME: is there a way to reuse the `.is_in_subset` from the matrix implementation of // SubsetOf? m.iter().all(|e| e.is_in_subset()) } #[inline] unsafe fn from_superset_unchecked(m: &PointBase) -> Self { PointBase::from_coordinates(Matrix::from_superset_unchecked(&m.coords)) } } impl SubsetOf, SB>> for PointBase where D: DimNameAdd, N1: Scalar, N2: Scalar + Zero + One + ClosedDiv + SupersetOf, SA: OwnedStorage, SB: OwnedStorage, U1>, SA::Alloc: OwnedAllocator + Allocator, U1>, SB::Alloc: OwnedAllocator, U1, SB> + Allocator { #[inline] fn to_superset(&self) -> ColumnVector, SB> { let p: OwnedPoint = self.to_superset(); p.to_homogeneous() } #[inline] fn is_in_subset(v: &ColumnVector, SB>) -> bool { ::is_convertible::<_, OwnedColumnVector, SA::Alloc>>(v) && !v[D::dim()].is_zero() } #[inline] unsafe fn from_superset_unchecked(v: &ColumnVector, SB>) -> Self { let coords = v.fixed_slice::(0, 0) / v[D::dim()]; Self::from_coordinates(::convert_unchecked(coords)) } }