#[cfg(feature = "arbitrary")] use quickcheck::{Arbitrary, Gen}; use rand::{Rand, Rng}; use num::{Zero, One, Bounded}; use alga::general::ClosedDiv; use core::{Scalar, ColumnVector}; use core::storage::{Storage, OwnedStorage}; use core::allocator::{Allocator, OwnedAllocator}; use core::dimension::{DimName, DimNameAdd, DimNameSum, U1, U2, U3, U4, U5, U6}; use geometry::PointBase; impl PointBase where N: Scalar, S: OwnedStorage, S::Alloc: OwnedAllocator { /// Creates a new point with uninitialized coordinates. #[inline] pub unsafe fn new_uninitialized() -> Self { Self::from_coordinates(ColumnVector::<_, D, _>::new_uninitialized()) } /// Creates a new point with all coordinates equal to zero. #[inline] pub fn origin() -> Self where N: Zero { Self::from_coordinates(ColumnVector::<_, D, _>::from_element(N::zero())) } /// Creates a new point from its homogeneous vector representation. /// /// In practice, this builds a D-dimensional points with the same first D component as `v` /// divided by the last component of `v`. Returns `None` if this divisor is zero. #[inline] pub fn from_homogeneous(v: ColumnVector, SB>) -> Option where N: Scalar + Zero + One + ClosedDiv, D: DimNameAdd, SB: Storage, U1, Alloc = S::Alloc>, S::Alloc: Allocator, U1> { if !v[D::dim()].is_zero() { let coords = v.fixed_slice::(0, 0) / v[D::dim()]; Some(Self::from_coordinates(coords)) } else { None } } } /* * * Traits that buid points. * */ impl Bounded for PointBase where N: Scalar + Bounded, S: OwnedStorage, S::Alloc: OwnedAllocator { #[inline] fn max_value() -> Self { Self::from_coordinates(ColumnVector::max_value()) } #[inline] fn min_value() -> Self { Self::from_coordinates(ColumnVector::min_value()) } } impl Rand for PointBase where N: Scalar + Rand, S: OwnedStorage, S::Alloc: OwnedAllocator { #[inline] fn rand(rng: &mut G) -> Self { PointBase::from_coordinates(rng.gen()) } } #[cfg(feature="arbitrary")] impl Arbitrary for PointBase where N: Scalar + Arbitrary + Send, S: OwnedStorage + Send, S::Alloc: OwnedAllocator { #[inline] fn arbitrary(g: &mut G) -> Self { PointBase::from_coordinates(ColumnVector::arbitrary(g)) } } /* * * Small points construction from components. * */ macro_rules! componentwise_constructors_impl( ($($D: ty, $($args: ident:$irow: expr),*);* $(;)*) => {$( impl PointBase where N: Scalar, S: OwnedStorage, S::Alloc: OwnedAllocator { /// Initializes this matrix from its components. #[inline] pub fn new($($args: N),*) -> PointBase { unsafe { let mut res = Self::new_uninitialized(); $( *res.get_unchecked_mut($irow) = $args; )* res } } } )*} ); componentwise_constructors_impl!( U1, x:0; U2, x:0, y:1; U3, x:0, y:1, z:2; U4, x:0, y:1, z:2, w:3; U5, x:0, y:1, z:2, w:3, a:4; U6, x:0, y:1, z:2, w:3, a:4, b:5; );