2018-10-22 13:00:10 +08:00
|
|
|
use alga::general::{
|
|
|
|
AbstractGroup, AbstractLoop, AbstractMagma, AbstractMonoid, AbstractQuasigroup,
|
2019-02-03 22:45:25 +08:00
|
|
|
AbstractSemigroup, Id, Identity, TwoSidedInverse, Multiplicative, Real,
|
2018-10-22 13:00:10 +08:00
|
|
|
};
|
|
|
|
use alga::linear::{
|
|
|
|
self, AffineTransformation, DirectIsometry, Isometry, OrthogonalTransformation,
|
|
|
|
ProjectiveTransformation, Similarity, Transformation,
|
|
|
|
};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2018-05-19 23:15:15 +08:00
|
|
|
use base::allocator::Allocator;
|
2018-10-22 13:00:10 +08:00
|
|
|
use base::dimension::DimName;
|
|
|
|
use base::{DefaultAllocator, VectorN};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
2018-02-02 19:26:35 +08:00
|
|
|
use geometry::{Point, Rotation};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Algebraic structures.
|
|
|
|
*
|
|
|
|
*/
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Real, D: DimName> Identity<Multiplicative> for Rotation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
|
|
|
fn identity() -> Self {
|
|
|
|
Self::identity()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-03 22:45:25 +08:00
|
|
|
impl<N: Real, D: DimName> TwoSidedInverse<Multiplicative> for Rotation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
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.transpose()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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.transpose_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Real, D: DimName> AbstractMagma<Multiplicative> for Rotation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D, 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>),* $(,)*) => {$(
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Real, D: DimName> $marker<$operator> for Rotation<N, D>
|
|
|
|
where DefaultAllocator: Allocator<N, D, D> { }
|
2016-12-05 05:44:42 +08:00
|
|
|
)*}
|
|
|
|
);
|
|
|
|
|
|
|
|
impl_multiplicative_structures!(
|
|
|
|
AbstractSemigroup<Multiplicative>,
|
|
|
|
AbstractMonoid<Multiplicative>,
|
|
|
|
AbstractQuasigroup<Multiplicative>,
|
|
|
|
AbstractLoop<Multiplicative>,
|
|
|
|
AbstractGroup<Multiplicative>
|
|
|
|
);
|
|
|
|
|
|
|
|
/*
|
|
|
|
*
|
|
|
|
* Transformation groups.
|
|
|
|
*
|
|
|
|
*/
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Real, D: DimName> Transformation<Point<N, D>> for Rotation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2017-08-03 01:37:44 +08:00
|
|
|
#[inline]
|
|
|
|
fn transform_point(&self, pt: &Point<N, D>) -> Point<N, D> {
|
2016-12-05 05:44:42 +08:00
|
|
|
self * pt
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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
|
|
|
self * v
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Real, D: DimName> ProjectiveTransformation<Point<N, D>> for Rotation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D, D> + 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> {
|
2018-10-24 02:47:42 +08:00
|
|
|
Point::from(self.inverse_transform_vector(&pt.coords))
|
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
|
|
|
self.matrix().tr_mul(v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Real, D: DimName> AffineTransformation<Point<N, D>> for Rotation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
|
|
|
type Rotation = Self;
|
2016-12-05 05:44:42 +08:00
|
|
|
type NonUniformScaling = Id;
|
2018-02-02 19:26:35 +08:00
|
|
|
type Translation = Id;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn decompose(&self) -> (Id, Self, Id, Self) {
|
|
|
|
(Id::new(), self.clone(), Id::new(), Self::identity())
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn append_translation(&self, _: &Self::Translation) -> Self {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn prepend_translation(&self, _: &Self::Translation) -> Self {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn append_rotation(&self, r: &Self::Rotation) -> Self {
|
|
|
|
r * self
|
|
|
|
}
|
|
|
|
|
|
|
|
#[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()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Real, D: DimName> Similarity<Point<N, D>> for Rotation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
|
|
|
type Scaling = Id;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn translation(&self) -> Id {
|
|
|
|
Id::new()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn rotation(&self) -> Self {
|
|
|
|
self.clone()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn scaling(&self) -> Id {
|
|
|
|
Id::new()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
macro_rules! marker_impl(
|
|
|
|
($($Trait: ident),*) => {$(
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Real, D: DimName> $Trait<Point<N, D>> for Rotation<N, D>
|
|
|
|
where DefaultAllocator: Allocator<N, D, D> +
|
|
|
|
Allocator<N, D> { }
|
2016-12-05 05:44:42 +08:00
|
|
|
)*}
|
|
|
|
);
|
|
|
|
|
|
|
|
marker_impl!(Isometry, DirectIsometry, OrthogonalTransformation);
|
|
|
|
|
|
|
|
/// Subgroups of the n-dimensional rotation group `SO(n)`.
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Real, D: DimName> linear::Rotation<Point<N, D>> for Rotation<N, D>
|
2018-10-22 13:00:10 +08:00
|
|
|
where DefaultAllocator: Allocator<N, D, D> + Allocator<N, D>
|
2018-02-02 19:26:35 +08:00
|
|
|
{
|
2016-12-05 05:44:42 +08:00
|
|
|
#[inline]
|
2017-02-13 01:17:09 +08:00
|
|
|
fn powf(&self, _: N) -> Option<Self> {
|
|
|
|
// XXX: Add the general case.
|
|
|
|
// XXX: Use specialization for 2D and 3D.
|
2016-12-05 05:44:42 +08:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn rotation_between(_: &VectorN<N, D>, _: &VectorN<N, D>) -> Option<Self> {
|
2017-02-13 01:17:09 +08:00
|
|
|
// XXX: Add the general case.
|
|
|
|
// XXX: Use specialization for 2D and 3D.
|
2016-12-05 05:44:42 +08:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
fn scaled_rotation_between(_: &VectorN<N, D>, _: &VectorN<N, D>, _: N) -> Option<Self> {
|
2017-02-13 01:17:09 +08:00
|
|
|
// XXX: Add the general case.
|
|
|
|
// XXX: Use specialization for 2D and 3D.
|
2016-12-05 05:44:42 +08:00
|
|
|
unimplemented!()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Real> Matrix for Rotation<N> {
|
2016-12-05 05:44:42 +08:00
|
|
|
type Field = N;
|
|
|
|
type Row = Matrix<N>;
|
|
|
|
type Column = Matrix<N>;
|
|
|
|
type Transpose = Self;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn nrows(&self) -> usize {
|
|
|
|
self.submatrix.nrows()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn ncolumns(&self) -> usize {
|
|
|
|
self.submatrix.ncolumns()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn row(&self, i: usize) -> Self::Row {
|
|
|
|
self.submatrix.row(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn column(&self, i: usize) -> Self::Column {
|
|
|
|
self.submatrix.column(i)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn get(&self, i: usize, j: usize) -> Self::Field {
|
|
|
|
self.submatrix[(i, j)]
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
unsafe fn get_unchecked(&self, i: usize, j: usize) -> Self::Field {
|
|
|
|
self.submatrix.at_fast(i, j)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn transpose(&self) -> Self::Transpose {
|
2017-08-03 01:37:44 +08:00
|
|
|
Rotation::from_matrix_unchecked(self.submatrix.transpose())
|
2016-12-05 05:44:42 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Real> SquareMatrix for Rotation<N> {
|
2016-12-05 05:44:42 +08:00
|
|
|
type Vector = Matrix<N>;
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn diagonal(&self) -> Self::Coordinates {
|
|
|
|
self.submatrix.diagonal()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn determinant(&self) -> Self::Field {
|
|
|
|
::one()
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn try_inverse(&self) -> Option<Self> {
|
|
|
|
Some(::transpose(self))
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn try_inverse_mut(&mut self) -> bool {
|
|
|
|
self.transpose_mut();
|
|
|
|
true
|
|
|
|
}
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
fn transpose_mut(&mut self) {
|
|
|
|
self.submatrix.transpose_mut()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
impl<N: Real> InversibleSquareMatrix for Rotation<N> { }
|
2016-12-05 05:44:42 +08:00
|
|
|
*/
|