2016-12-05 05:44:42 +08:00
|
|
|
#[cfg(feature = "arbitrary")]
|
2018-05-19 23:15:15 +08:00
|
|
|
use base::storage::Owned;
|
2018-05-23 05:58:14 +08:00
|
|
|
#[cfg(feature = "arbitrary")]
|
|
|
|
use quickcheck::{Arbitrary, Gen};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2018-02-02 19:26:35 +08:00
|
|
|
use num::{One, Zero};
|
2018-05-23 05:58:14 +08:00
|
|
|
use rand::distributions::{Distribution, Standard};
|
|
|
|
use rand::Rng;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
use alga::general::ClosedAdd;
|
|
|
|
|
2018-05-19 23:15:15 +08:00
|
|
|
use base::allocator::Allocator;
|
2018-05-23 05:58:14 +08:00
|
|
|
use base::dimension::{DimName, U1, U2, U3, U4, U5, U6};
|
|
|
|
use base::{DefaultAllocator, Scalar, VectorN};
|
2017-08-03 01:37:44 +08:00
|
|
|
|
|
|
|
use geometry::Translation;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Scalar + Zero, D: DimName> Translation<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
DefaultAllocator: Allocator<N, D>,
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
/// Creates a new square identity rotation of the given `dimension`.
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
pub fn identity() -> Translation<N, D> {
|
|
|
|
Self::from_vector(VectorN::<N, D>::from_element(N::zero()))
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Scalar + Zero + ClosedAdd, D: DimName> One for Translation<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
DefaultAllocator: Allocator<N, D>,
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
|
|
|
fn one() -> Self {
|
|
|
|
Self::identity()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-05-23 05:58:14 +08:00
|
|
|
impl<N: Scalar, D: DimName> Distribution<Translation<N, D>> for Standard
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
DefaultAllocator: Allocator<N, D>,
|
2018-05-23 05:58:14 +08:00
|
|
|
Standard: Distribution<N>,
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
2018-05-23 05:58:14 +08:00
|
|
|
fn sample<'a, G: Rng + ?Sized>(&self, rng: &'a mut G) -> Translation<N, D> {
|
|
|
|
Translation::from_vector(rng.gen::<VectorN<N, D>>())
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(feature = "arbitrary")]
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Scalar + Arbitrary, D: DimName> Arbitrary for Translation<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
DefaultAllocator: Allocator<N, D>,
|
|
|
|
Owned<N, D>: Send,
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
|
|
|
fn arbitrary<G: Gen>(rng: &mut G) -> Self {
|
|
|
|
Self::from_vector(Arbitrary::arbitrary(rng))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Small translation construction from components.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
macro_rules! componentwise_constructors_impl(
|
|
|
|
($($D: ty, $($args: ident:$irow: expr),*);* $(;)*) => {$(
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Scalar> Translation<N, $D>
|
|
|
|
where DefaultAllocator: Allocator<N, $D> {
|
2016-12-05 05:44:42 +08:00
|
|
|
/// Initializes this matrix from its components.
|
|
|
|
#[inline]
|
|
|
|
pub fn new($($args: N),*) -> Self {
|
2017-08-03 01:37:44 +08:00
|
|
|
Self::from_vector(VectorN::<N, $D>::new($($args),*))
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
)*}
|
|
|
|
);
|
|
|
|
|
|
|
|
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;
|
|
|
|
);
|