2016-12-05 05:44:42 +08:00
|
|
|
use num::{One, Zero};
|
2018-02-02 19:26:35 +08:00
|
|
|
use alga::general::{ClosedDiv, SubsetOf, SupersetOf};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2018-02-02 19:26:35 +08:00
|
|
|
use core::{DefaultAllocator, Matrix, Scalar, VectorN};
|
|
|
|
use core::dimension::{DimName, DimNameAdd, DimNameSum, U1};
|
2017-08-03 01:37:44 +08:00
|
|
|
use core::allocator::Allocator;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
use geometry::Point;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* This file provides the following conversions:
|
|
|
|
* =============================================
|
|
|
|
*
|
2017-08-03 01:37:44 +08:00
|
|
|
* Point -> Point
|
|
|
|
* Point -> Vector (homogeneous)
|
2016-12-05 05:44:42 +08:00
|
|
|
*/
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N1, N2, D> SubsetOf<Point<N2, D>> for Point<N1, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
D: DimName,
|
|
|
|
N1: Scalar,
|
|
|
|
N2: Scalar + SupersetOf<N1>,
|
|
|
|
DefaultAllocator: Allocator<N2, D> + Allocator<N1, D>,
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn to_superset(&self) -> Point<N2, D> {
|
|
|
|
Point::from_coordinates(self.coords.to_superset())
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn is_in_subset(m: &Point<N2, D>) -> bool {
|
2016-12-05 05:44:42 +08:00
|
|
|
// 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]
|
2017-08-03 01:37:44 +08:00
|
|
|
unsafe fn from_superset_unchecked(m: &Point<N2, D>) -> Self {
|
|
|
|
Point::from_coordinates(Matrix::from_superset_unchecked(&m.coords))
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N1, N2, D> SubsetOf<VectorN<N2, DimNameSum<D, U1>>> for Point<N1, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
D: DimNameAdd<U1>,
|
|
|
|
N1: Scalar,
|
|
|
|
N2: Scalar + Zero + One + ClosedDiv + SupersetOf<N1>,
|
|
|
|
DefaultAllocator: Allocator<N1, D>
|
|
|
|
+ Allocator<N1, DimNameSum<D, U1>>
|
|
|
|
+ Allocator<N2, DimNameSum<D, U1>>
|
|
|
|
+ Allocator<N2, D>,
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn to_superset(&self) -> VectorN<N2, DimNameSum<D, U1>> {
|
|
|
|
let p: Point<N2, D> = self.to_superset();
|
2016-12-05 05:44:42 +08:00
|
|
|
p.to_homogeneous()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn is_in_subset(v: &VectorN<N2, DimNameSum<D, U1>>) -> bool {
|
2018-02-02 19:26:35 +08:00
|
|
|
::is_convertible::<_, VectorN<N1, DimNameSum<D, U1>>>(v) && !v[D::dim()].is_zero()
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
unsafe fn from_superset_unchecked(v: &VectorN<N2, DimNameSum<D, U1>>) -> Self {
|
2018-02-02 19:26:35 +08:00
|
|
|
let coords = v.fixed_slice::<D, U1>(0, 0) / v[D::dim()];
|
2016-12-05 05:44:42 +08:00
|
|
|
Self::from_coordinates(::convert_unchecked(coords))
|
|
|
|
}
|
|
|
|
}
|