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
|
|
|
};
|
2018-04-27 13:52:41 +08:00
|
|
|
use alga::linear::Isometry as AlgaIsometry;
|
2018-10-22 13:00:10 +08:00
|
|
|
use alga::linear::{
|
|
|
|
AffineTransformation, DirectIsometry, ProjectiveTransformation, Rotation, 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::{Isometry, 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, R> Identity<Multiplicative> for Isometry<N, D, R>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
R: Rotation<Point<N, D>>,
|
|
|
|
DefaultAllocator: Allocator<N, D>,
|
|
|
|
{
|
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, R> TwoSidedInverse<Multiplicative> for Isometry<N, D, R>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
R: Rotation<Point<N, D>>,
|
|
|
|
DefaultAllocator: Allocator<N, D>,
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
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, R> AbstractMagma<Multiplicative> for Isometry<N, D, R>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
R: Rotation<Point<N, D>>,
|
|
|
|
DefaultAllocator: Allocator<N, D>,
|
|
|
|
{
|
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, R> $marker<$operator> for Isometry<N, D, R>
|
2017-08-03 01:37:44 +08:00
|
|
|
where R: Rotation<Point<N, D>>,
|
|
|
|
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, R> Transformation<Point<N, D>> for Isometry<N, D, R>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
R: Rotation<Point<N, D>>,
|
|
|
|
DefaultAllocator: Allocator<N, D>,
|
|
|
|
{
|
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> {
|
2019-02-25 00:29:27 +08:00
|
|
|
self.transform_vector(v)
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName, R> ProjectiveTransformation<Point<N, D>> for Isometry<N, D, R>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
R: Rotation<Point<N, D>>,
|
|
|
|
DefaultAllocator: Allocator<N, D>,
|
|
|
|
{
|
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> {
|
2019-02-25 00:29:27 +08:00
|
|
|
self.inverse_transform_vector(v)
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName, R> AffineTransformation<Point<N, D>> for Isometry<N, D, R>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
R: Rotation<Point<N, D>>,
|
|
|
|
DefaultAllocator: Allocator<N, D>,
|
|
|
|
{
|
|
|
|
type Rotation = R;
|
2016-12-05 05:44:42 +08:00
|
|
|
type NonUniformScaling = Id;
|
2018-02-02 19:26:35 +08:00
|
|
|
type Translation = Translation<N, D>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
#[inline]
|
2019-02-17 05:29:41 +08:00
|
|
|
fn decompose(&self) -> (Self::Translation, R, Id, R) {
|
2018-02-02 19:26:35 +08:00
|
|
|
(
|
|
|
|
self.translation.clone(),
|
|
|
|
self.rotation.clone(),
|
|
|
|
Id::new(),
|
|
|
|
R::identity(),
|
|
|
|
)
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[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, r: &Self::Rotation) -> Self {
|
|
|
|
let shift = r.transform_vector(&self.translation.vector);
|
2018-10-28 14:33:39 +08:00
|
|
|
Isometry::from_parts(Translation::from(shift), r.clone() * self.rotation.clone())
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn prepend_rotation(&self, r: &Self::Rotation) -> Self {
|
|
|
|
self * r
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn append_scaling(&self, _: &Self::NonUniformScaling) -> Self {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn prepend_scaling(&self, _: &Self::NonUniformScaling) -> Self {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn append_rotation_wrt_point(&self, r: &Self::Rotation, p: &Point<N, D>) -> Option<Self> {
|
2016-12-05 05:44:42 +08:00
|
|
|
let mut res = self.clone();
|
|
|
|
res.append_rotation_wrt_point_mut(r, p);
|
|
|
|
Some(res)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-25 18:21:41 +08:00
|
|
|
impl<N: RealField, D: DimName, R> Similarity<Point<N, D>> for Isometry<N, D, R>
|
2018-02-02 19:26:35 +08:00
|
|
|
where
|
|
|
|
R: Rotation<Point<N, D>>,
|
|
|
|
DefaultAllocator: Allocator<N, D>,
|
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
type Scaling = Id;
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn translation(&self) -> Translation<N, D> {
|
2016-12-05 05:44:42 +08:00
|
|
|
self.translation.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn rotation(&self) -> R {
|
|
|
|
self.rotation.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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, R> $Trait<Point<N, D>> for Isometry<N, D, R>
|
2017-08-03 01:37:44 +08:00
|
|
|
where R: Rotation<Point<N, D>>,
|
|
|
|
DefaultAllocator: Allocator<N, D> { }
|
2016-12-05 05:44:42 +08:00
|
|
|
)*}
|
|
|
|
);
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
marker_impl!(AlgaIsometry, DirectIsometry);
|