2018-10-22 13:00:10 +08:00
|
|
|
use alga::general::{
|
|
|
|
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
2019-03-25 18:21:41 +08:00
|
|
|
AbstractSemigroup, Id, Identity, TwoSidedInverse, Multiplicative, RealField,
|
2018-10-22 13:00:10 +08:00
|
|
|
};
|
2017-08-03 01:37:44 +08:00
|
|
|
use alga::linear::Translation as AlgaTranslation;
|
2018-10-22 13:00:10 +08:00
|
|
|
use alga::linear::{
|
|
|
|
AffineTransformation, DirectIsometry, Isometry, ProjectiveTransformation, Similarity,
|
|
|
|
Transformation,
|
|
|
|
};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::base::allocator::Allocator;
|
|
|
|
use crate::base::dimension::DimName;
|
|
|
|
use crate::base::{DefaultAllocator, VectorN};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2019-03-23 21:29:07 +08:00
|
|
|
use crate::geometry::{Point, Translation};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Algebraic structures.
|
|
|
|
*
|
|
|
|
*/
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName> Identity<Multiplicative> for Translation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
|
|
|
fn identity() -> Self {
|
|
|
|
Self::identity()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName> TwoSidedInverse<Multiplicative> for Translation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
2019-06-06 05:04:04 +08:00
|
|
|
#[must_use = "Did you mean to use two_sided_inverse_mut()?"]
|
2019-02-03 22:45:25 +08:00
|
|
|
fn two_sided_inverse(&self) -> Self {
|
2016-12-05 05:44:42 +08:00
|
|
|
self.inverse()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2019-02-03 22:45:25 +08:00
|
|
|
fn two_sided_inverse_mut(&mut self) {
|
2016-12-05 05:44:42 +08:00
|
|
|
self.inverse_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName> AbstractMagma<Multiplicative> for Translation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
|
|
|
fn operate(&self, rhs: &Self) -> Self {
|
|
|
|
self * rhs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! impl_multiplicative_structures(
|
|
|
|
($($marker: ident<$operator: ident>),* $(,)*) => {$(
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName> $marker<$operator> for Translation<N, D>
|
2017-08-03 01:37:44 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D> { }
|
2016-12-05 05:44:42 +08:00
|
|
|
)*}
|
|
|
|
);
|
|
|
|
|
|
|
|
impl_multiplicative_structures!(
|
|
|
|
AbstractSemigroup<Multiplicative>,
|
|
|
|
AbstractMonoid<Multiplicative>,
|
|
|
|
AbstractQuasigroup<Multiplicative>,
|
|
|
|
AbstractLoop<Multiplicative>,
|
|
|
|
AbstractGroup<Multiplicative>
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Transformation groups.
|
|
|
|
*
|
|
|
|
*/
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName> Transformation<Point<N, D>> for Translation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn transform_point(&self, pt: &Point<N, D>) -> Point<N, D> {
|
2019-02-25 00:29:27 +08:00
|
|
|
self.transform_point(pt)
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn transform_vector(&self, v: &VectorN<N, D>) -> VectorN<N, D> {
|
2016-12-05 05:44:42 +08:00
|
|
|
v.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName> ProjectiveTransformation<Point<N, D>> for Translation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn inverse_transform_point(&self, pt: &Point<N, D>) -> Point<N, D> {
|
2019-02-25 00:29:27 +08:00
|
|
|
self.inverse_transform_point(pt)
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn inverse_transform_vector(&self, v: &VectorN<N, D>) -> VectorN<N, D> {
|
2016-12-05 05:44:42 +08:00
|
|
|
v.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName> AffineTransformation<Point<N, D>> for Translation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
|
|
|
type Rotation = Id;
|
2016-12-05 05:44:42 +08:00
|
|
|
type NonUniformScaling = Id;
|
2018-02-02 19:26:35 +08:00
|
|
|
type Translation = Self;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn decompose(&self) -> (Self, Id, Id, Id) {
|
|
|
|
(self.clone(), Id::new(), Id::new(), Id::new())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn append_translation(&self, t: &Self::Translation) -> Self {
|
|
|
|
t * self
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn prepend_translation(&self, t: &Self::Translation) -> Self {
|
|
|
|
self * t
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn append_rotation(&self, _: &Self::Rotation) -> Self {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn prepend_rotation(&self, _: &Self::Rotation) -> Self {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn append_scaling(&self, _: &Self::NonUniformScaling) -> Self {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn prepend_scaling(&self, _: &Self::NonUniformScaling) -> Self {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName> Similarity<Point<N, D>> for Translation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
type Scaling = Id;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn translation(&self) -> Self {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn rotation(&self) -> Id {
|
|
|
|
Id::new()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn scaling(&self) -> Id {
|
|
|
|
Id::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! marker_impl(
|
|
|
|
($($Trait: ident),*) => {$(
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName> $Trait<Point<N, D>> for Translation<N, D>
|
2017-08-03 01:37:44 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D> { }
|
2016-12-05 05:44:42 +08:00
|
|
|
)*}
|
|
|
|
);
|
|
|
|
|
|
|
|
marker_impl!(Isometry, DirectIsometry);
|
|
|
|
|
|
|
|
/// Subgroups of the n-dimensional translation group `T(n)`.
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName> AlgaTranslation<Point<N, D>> for Translation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn to_vector(&self) -> VectorN<N, D> {
|
2016-12-05 05:44:42 +08:00
|
|
|
self.vector.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn from_vector(v: VectorN<N, D>) -> Option<Self> {
|
2018-10-28 14:33:14 +08:00
|
|
|
Some(Self::from(v))
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn powf(&self, n: N) -> Option<Self> {
|
2018-10-28 14:33:14 +08:00
|
|
|
Some(Self::from(&self.vector * n))
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn translation_between(a: &Point<N, D>, b: &Point<N, D>) -> Option<Self> {
|
2018-10-28 14:33:14 +08:00
|
|
|
Some(Self::from(b - a))
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|