2016-12-05 05:44:42 +08:00
|
|
|
|
use std::ops::{Mul, MulAssign, Div, DivAssign};
|
|
|
|
|
|
|
|
|
|
use alga::general::Real;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
use core::{DefaultAllocator, Unit, Vector, Vector2, Matrix};
|
|
|
|
|
use core::dimension::{Dim, U1, U2};
|
|
|
|
|
use core::storage::{Storage, StorageMut};
|
|
|
|
|
use core::allocator::Allocator;
|
|
|
|
|
use core::constraint::{ShapeConstraint, DimEq};
|
|
|
|
|
use geometry::{UnitComplex, Rotation, Isometry, Similarity, Translation, Point2};
|
2016-12-05 05:44:42 +08:00
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* This file provides:
|
|
|
|
|
* ===================
|
|
|
|
|
*
|
|
|
|
|
* UnitComplex × UnitComplex
|
2017-08-03 01:37:44 +08:00
|
|
|
|
* UnitComplex × Rotation -> UnitComplex
|
|
|
|
|
* Rotation × UnitComplex -> UnitComplex
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*
|
|
|
|
|
* UnitComplex ÷ UnitComplex
|
2017-08-03 01:37:44 +08:00
|
|
|
|
* UnitComplex ÷ Rotation -> UnitComplex
|
|
|
|
|
* Rotation ÷ UnitComplex -> UnitComplex
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*
|
|
|
|
|
*
|
2017-08-03 01:37:44 +08:00
|
|
|
|
* UnitComplex × Point
|
|
|
|
|
* UnitComplex × Vector
|
2016-12-05 05:44:42 +08:00
|
|
|
|
* UnitComplex × Unit<T>
|
|
|
|
|
*
|
2017-08-03 01:37:44 +08:00
|
|
|
|
* UnitComplex × Isometry<UnitComplex>
|
|
|
|
|
* UnitComplex × Similarity<UnitComplex>
|
|
|
|
|
* UnitComplex × Translation -> Isometry<UnitComplex>
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*
|
2017-02-13 01:17:09 +08:00
|
|
|
|
* NOTE: -UnitComplex is already provided by `Unit<T>`.
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*
|
|
|
|
|
* (Assignment Operators)
|
|
|
|
|
*
|
|
|
|
|
* UnitComplex ×= UnitComplex
|
2017-08-03 01:37:44 +08:00
|
|
|
|
* UnitComplex ×= Rotation
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*
|
|
|
|
|
* UnitComplex ÷= UnitComplex
|
2017-08-03 01:37:44 +08:00
|
|
|
|
* UnitComplex ÷= Rotation
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*
|
2017-08-03 01:37:44 +08:00
|
|
|
|
* Rotation ×= UnitComplex
|
|
|
|
|
* Rotation ÷= UnitComplex
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
// UnitComplex × UnitComplex
|
|
|
|
|
impl<N: Real> Mul<UnitComplex<N>> for UnitComplex<N> {
|
|
|
|
|
type Output = UnitComplex<N>;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn mul(self, rhs: UnitComplex<N>) -> UnitComplex<N> {
|
|
|
|
|
Unit::new_unchecked(self.unwrap() * rhs.unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, N: Real> Mul<UnitComplex<N>> for &'a UnitComplex<N> {
|
|
|
|
|
type Output = UnitComplex<N>;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn mul(self, rhs: UnitComplex<N>) -> UnitComplex<N> {
|
|
|
|
|
Unit::new_unchecked(self.complex() * rhs.unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'b, N: Real> Mul<&'b UnitComplex<N>> for UnitComplex<N> {
|
|
|
|
|
type Output = UnitComplex<N>;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn mul(self, rhs: &'b UnitComplex<N>) -> UnitComplex<N> {
|
|
|
|
|
Unit::new_unchecked(self.unwrap() * rhs.complex())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, 'b, N: Real> Mul<&'b UnitComplex<N>> for &'a UnitComplex<N> {
|
|
|
|
|
type Output = UnitComplex<N>;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn mul(self, rhs: &'b UnitComplex<N>) -> UnitComplex<N> {
|
|
|
|
|
Unit::new_unchecked(self.complex() * rhs.complex())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UnitComplex ÷ UnitComplex
|
|
|
|
|
impl<N: Real> Div<UnitComplex<N>> for UnitComplex<N> {
|
|
|
|
|
type Output = UnitComplex<N>;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn div(self, rhs: UnitComplex<N>) -> UnitComplex<N> {
|
|
|
|
|
Unit::new_unchecked(self.unwrap() * rhs.conjugate().unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, N: Real> Div<UnitComplex<N>> for &'a UnitComplex<N> {
|
|
|
|
|
type Output = UnitComplex<N>;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn div(self, rhs: UnitComplex<N>) -> UnitComplex<N> {
|
|
|
|
|
Unit::new_unchecked(self.complex() * rhs.conjugate().unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'b, N: Real> Div<&'b UnitComplex<N>> for UnitComplex<N> {
|
|
|
|
|
type Output = UnitComplex<N>;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn div(self, rhs: &'b UnitComplex<N>) -> UnitComplex<N> {
|
|
|
|
|
Unit::new_unchecked(self.unwrap() * rhs.conjugate().unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'a, 'b, N: Real> Div<&'b UnitComplex<N>> for &'a UnitComplex<N> {
|
|
|
|
|
type Output = UnitComplex<N>;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn div(self, rhs: &'b UnitComplex<N>) -> UnitComplex<N> {
|
|
|
|
|
Unit::new_unchecked(self.complex() * rhs.conjugate().unwrap())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
macro_rules! complex_op_impl(
|
|
|
|
|
($Op: ident, $op: ident;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
($RDim: ident, $CDim: ident) $(for $Storage: ident: $StoragesBound: ident $(<$($BoundParam: ty),*>)*),*;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
$lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Result: ty;
|
|
|
|
|
$action: expr; $($lives: tt),*) => {
|
2017-08-03 01:37:44 +08:00
|
|
|
|
impl<$($lives ,)* N: Real $(, $Storage: $StoragesBound $(<$($BoundParam),*>)*)*> $Op<$Rhs> for $Lhs
|
|
|
|
|
where DefaultAllocator: Allocator<N, $RDim, $CDim> {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
type Output = $Result;
|
|
|
|
|
|
|
|
|
|
#[inline]
|
|
|
|
|
fn $op($lhs, $rhs: $Rhs) -> Self::Output {
|
|
|
|
|
$action
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
macro_rules! complex_op_impl_all(
|
|
|
|
|
($Op: ident, $op: ident;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
($RDim: ident, $CDim: ident) $(for $Storage: ident: $StoragesBound: ident $(<$($BoundParam: ty),*>)*),*;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
$lhs: ident: $Lhs: ty, $rhs: ident: $Rhs: ty, Output = $Result: ty;
|
|
|
|
|
[val val] => $action_val_val: expr;
|
|
|
|
|
[ref val] => $action_ref_val: expr;
|
|
|
|
|
[val ref] => $action_val_ref: expr;
|
|
|
|
|
[ref ref] => $action_ref_ref: expr;) => {
|
|
|
|
|
|
|
|
|
|
complex_op_impl!($Op, $op;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
($RDim, $CDim) $(for $Storage: $StoragesBound $(<$($BoundParam),*>)*),*;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
$lhs: $Lhs, $rhs: $Rhs, Output = $Result;
|
|
|
|
|
$action_val_val; );
|
|
|
|
|
|
|
|
|
|
complex_op_impl!($Op, $op;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
($RDim, $CDim) $(for $Storage: $StoragesBound $(<$($BoundParam),*>)*),*;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
$lhs: &'a $Lhs, $rhs: $Rhs, Output = $Result;
|
|
|
|
|
$action_ref_val; 'a);
|
|
|
|
|
|
|
|
|
|
complex_op_impl!($Op, $op;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
($RDim, $CDim) $(for $Storage: $StoragesBound $(<$($BoundParam),*>)*),*;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
$lhs: $Lhs, $rhs: &'b $Rhs, Output = $Result;
|
|
|
|
|
$action_val_ref; 'b);
|
|
|
|
|
|
|
|
|
|
complex_op_impl!($Op, $op;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
($RDim, $CDim) $(for $Storage: $StoragesBound $(<$($BoundParam),*>)*),*;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
$lhs: &'a $Lhs, $rhs: &'b $Rhs, Output = $Result;
|
|
|
|
|
$action_ref_ref; 'a, 'b);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// UnitComplex × Rotation
|
2016-12-05 05:44:42 +08:00
|
|
|
|
complex_op_impl_all!(
|
|
|
|
|
Mul, mul;
|
|
|
|
|
(U2, U2);
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: UnitComplex<N>, rhs: Rotation<N, U2>, Output = UnitComplex<N>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val val] => &self * &rhs;
|
|
|
|
|
[ref val] => self * &rhs;
|
|
|
|
|
[val ref] => &self * rhs;
|
|
|
|
|
[ref ref] => self * UnitComplex::from_rotation_matrix(rhs);
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// UnitComplex ÷ Rotation
|
2016-12-05 05:44:42 +08:00
|
|
|
|
complex_op_impl_all!(
|
|
|
|
|
Div, div;
|
|
|
|
|
(U2, U2);
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: UnitComplex<N>, rhs: Rotation<N, U2>, Output = UnitComplex<N>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val val] => &self / &rhs;
|
|
|
|
|
[ref val] => self / &rhs;
|
|
|
|
|
[val ref] => &self / rhs;
|
|
|
|
|
[ref ref] => self * UnitComplex::from_rotation_matrix(rhs).inverse();
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Rotation × UnitComplex
|
2016-12-05 05:44:42 +08:00
|
|
|
|
complex_op_impl_all!(
|
|
|
|
|
Mul, mul;
|
|
|
|
|
(U2, U2);
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: Rotation<N, U2>, rhs: UnitComplex<N>, Output = UnitComplex<N>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val val] => &self * &rhs;
|
|
|
|
|
[ref val] => self * &rhs;
|
|
|
|
|
[val ref] => &self * rhs;
|
|
|
|
|
[ref ref] => UnitComplex::from_rotation_matrix(self) * rhs;
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Rotation ÷ UnitComplex
|
2016-12-05 05:44:42 +08:00
|
|
|
|
complex_op_impl_all!(
|
|
|
|
|
Div, div;
|
|
|
|
|
(U2, U2);
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: Rotation<N, U2>, rhs: UnitComplex<N>, Output = UnitComplex<N>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val val] => &self / &rhs;
|
|
|
|
|
[ref val] => self / &rhs;
|
|
|
|
|
[val ref] => &self / rhs;
|
|
|
|
|
[ref ref] => UnitComplex::from_rotation_matrix(self) * rhs.inverse();
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// UnitComplex × Point
|
2016-12-05 05:44:42 +08:00
|
|
|
|
complex_op_impl_all!(
|
|
|
|
|
Mul, mul;
|
|
|
|
|
(U2, U1);
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: UnitComplex<N>, rhs: Point2<N>, Output = Point2<N>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val val] => &self * &rhs;
|
|
|
|
|
[ref val] => self * &rhs;
|
|
|
|
|
[val ref] => &self * rhs;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
[ref ref] => Point2::from_coordinates(self * &rhs.coords);
|
2016-12-05 05:44:42 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// UnitComplex × Vector
|
2016-12-05 05:44:42 +08:00
|
|
|
|
complex_op_impl_all!(
|
|
|
|
|
Mul, mul;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
(U2, U1) for S: Storage<N, U2>;
|
|
|
|
|
self: UnitComplex<N>, rhs: Vector<N, U2, S>, Output = Vector2<N>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val val] => &self * &rhs;
|
|
|
|
|
[ref val] => self * &rhs;
|
|
|
|
|
[val ref] => &self * rhs;
|
|
|
|
|
[ref ref] => {
|
|
|
|
|
let i = self.as_ref().im;
|
|
|
|
|
let r = self.as_ref().re;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
Vector2::new(r * rhs[0] - i * rhs[1], i * rhs[0] + r * rhs[1])
|
2016-12-05 05:44:42 +08:00
|
|
|
|
};
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// UnitComplex × Unit<Vector>
|
|
|
|
|
complex_op_impl_all!(
|
|
|
|
|
Mul, mul;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
(U2, U1) for S: Storage<N, U2>;
|
|
|
|
|
self: UnitComplex<N>, rhs: Unit<Vector<N, U2, S>>, Output = Unit<Vector2<N>>;
|
2016-12-05 05:44:42 +08:00
|
|
|
|
[val val] => &self * &rhs;
|
|
|
|
|
[ref val] => self * &rhs;
|
|
|
|
|
[val ref] => &self * rhs;
|
|
|
|
|
[ref ref] => Unit::new_unchecked(self * rhs.as_ref());
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// UnitComplex × Isometry<UnitComplex>
|
2017-02-13 01:17:09 +08:00
|
|
|
|
complex_op_impl_all!(
|
|
|
|
|
Mul, mul;
|
|
|
|
|
(U2, U1);
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: UnitComplex<N>, rhs: Isometry<N, U2, UnitComplex<N>>,
|
|
|
|
|
Output = Isometry<N, U2, UnitComplex<N>>;
|
2017-02-13 01:17:09 +08:00
|
|
|
|
[val val] => &self * &rhs;
|
|
|
|
|
[ref val] => self * &rhs;
|
|
|
|
|
[val ref] => &self * rhs;
|
|
|
|
|
[ref ref] => {
|
|
|
|
|
let shift = self * &rhs.translation.vector;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
Isometry::from_parts(Translation::from_vector(shift), self * &rhs.rotation)
|
2017-02-13 01:17:09 +08:00
|
|
|
|
};
|
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// UnitComplex × Similarity<UnitComplex>
|
2017-02-13 01:17:09 +08:00
|
|
|
|
complex_op_impl_all!(
|
|
|
|
|
Mul, mul;
|
|
|
|
|
(U2, U1);
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: UnitComplex<N>, rhs: Similarity<N, U2, UnitComplex<N>>,
|
|
|
|
|
Output = Similarity<N, U2, UnitComplex<N>>;
|
2017-02-13 01:17:09 +08:00
|
|
|
|
[val val] => &self * &rhs;
|
|
|
|
|
[ref val] => self * &rhs;
|
|
|
|
|
[val ref] => &self * rhs;
|
2017-08-03 01:37:44 +08:00
|
|
|
|
[ref ref] => Similarity::from_isometry(self * &rhs.isometry, rhs.scaling());
|
2017-02-13 01:17:09 +08:00
|
|
|
|
);
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// UnitComplex × Translation
|
2017-02-13 01:17:09 +08:00
|
|
|
|
complex_op_impl_all!(
|
|
|
|
|
Mul, mul;
|
|
|
|
|
(U2, U1);
|
2017-08-03 01:37:44 +08:00
|
|
|
|
self: UnitComplex<N>, rhs: Translation<N, U2>,
|
|
|
|
|
Output = Isometry<N, U2, UnitComplex<N>>;
|
|
|
|
|
[val val] => Isometry::from_parts(Translation::from_vector(&self * rhs.vector), self);
|
|
|
|
|
[ref val] => Isometry::from_parts(Translation::from_vector( self * rhs.vector), self.clone());
|
|
|
|
|
[val ref] => Isometry::from_parts(Translation::from_vector(&self * &rhs.vector), self);
|
|
|
|
|
[ref ref] => Isometry::from_parts(Translation::from_vector( self * &rhs.vector), self.clone());
|
2017-02-13 01:17:09 +08:00
|
|
|
|
);
|
|
|
|
|
|
2016-12-05 05:44:42 +08:00
|
|
|
|
// UnitComplex ×= UnitComplex
|
|
|
|
|
impl<N: Real> MulAssign<UnitComplex<N>> for UnitComplex<N> {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn mul_assign(&mut self, rhs: UnitComplex<N>) {
|
|
|
|
|
*self = &*self * rhs
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'b, N: Real> MulAssign<&'b UnitComplex<N>> for UnitComplex<N> {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn mul_assign(&mut self, rhs: &'b UnitComplex<N>) {
|
|
|
|
|
*self = &*self * rhs
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// UnitComplex /= UnitComplex
|
|
|
|
|
impl<N: Real> DivAssign<UnitComplex<N>> for UnitComplex<N> {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn div_assign(&mut self, rhs: UnitComplex<N>) {
|
|
|
|
|
*self = &*self / rhs
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
impl<'b, N: Real> DivAssign<&'b UnitComplex<N>> for UnitComplex<N> {
|
|
|
|
|
#[inline]
|
|
|
|
|
fn div_assign(&mut self, rhs: &'b UnitComplex<N>) {
|
|
|
|
|
*self = &*self / rhs
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// UnitComplex ×= Rotation
|
|
|
|
|
impl<N: Real> MulAssign<Rotation<N, U2>> for UnitComplex<N>
|
|
|
|
|
where DefaultAllocator: Allocator<N, U2, U2> {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
|
fn mul_assign(&mut self, rhs: Rotation<N, U2>) {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*self = &*self * rhs
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
impl<'b, N: Real> MulAssign<&'b Rotation<N, U2>> for UnitComplex<N>
|
|
|
|
|
where DefaultAllocator: Allocator<N, U2, U2> {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
|
fn mul_assign(&mut self, rhs: &'b Rotation<N, U2>) {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*self = &*self * rhs
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// UnitComplex ÷= Rotation
|
|
|
|
|
impl<N: Real> DivAssign<Rotation<N, U2>> for UnitComplex<N>
|
|
|
|
|
where DefaultAllocator: Allocator<N, U2, U2> {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
|
fn div_assign(&mut self, rhs: Rotation<N, U2>) {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*self = &*self / rhs
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
impl<'b, N: Real> DivAssign<&'b Rotation<N, U2>> for UnitComplex<N>
|
|
|
|
|
where DefaultAllocator: Allocator<N, U2, U2> {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
#[inline]
|
2017-08-03 01:37:44 +08:00
|
|
|
|
fn div_assign(&mut self, rhs: &'b Rotation<N, U2>) {
|
2016-12-05 05:44:42 +08:00
|
|
|
|
*self = &*self / rhs
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-02-13 01:17:09 +08:00
|
|
|
|
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Rotation ×= UnitComplex
|
|
|
|
|
impl<N: Real> MulAssign<UnitComplex<N>> for Rotation<N, U2>
|
|
|
|
|
where DefaultAllocator: Allocator<N, U2, U2> {
|
2017-02-13 01:17:09 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn mul_assign(&mut self, rhs: UnitComplex<N>) {
|
|
|
|
|
self.mul_assign(rhs.to_rotation_matrix())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
impl<'b, N: Real> MulAssign<&'b UnitComplex<N>> for Rotation<N, U2>
|
|
|
|
|
where DefaultAllocator: Allocator<N, U2, U2> {
|
2017-02-13 01:17:09 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn mul_assign(&mut self, rhs: &'b UnitComplex<N>) {
|
|
|
|
|
self.mul_assign(rhs.to_rotation_matrix())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
// Rotation ÷= UnitComplex
|
|
|
|
|
impl<N: Real> DivAssign<UnitComplex<N>> for Rotation<N, U2>
|
|
|
|
|
where DefaultAllocator: Allocator<N, U2, U2> {
|
2017-02-13 01:17:09 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn div_assign(&mut self, rhs: UnitComplex<N>) {
|
|
|
|
|
self.div_assign(rhs.to_rotation_matrix())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-08-03 01:37:44 +08:00
|
|
|
|
impl<'b, N: Real> DivAssign<&'b UnitComplex<N>> for Rotation<N, U2>
|
|
|
|
|
where DefaultAllocator: Allocator<N, U2, U2> {
|
2017-02-13 01:17:09 +08:00
|
|
|
|
#[inline]
|
|
|
|
|
fn div_assign(&mut self, rhs: &'b UnitComplex<N>) {
|
|
|
|
|
self.div_assign(rhs.to_rotation_matrix())
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-08-03 01:37:44 +08:00
|
|
|
|
|
|
|
|
|
// Matrix = UnitComplex * Matrix
|
|
|
|
|
impl<N: Real> UnitComplex<N> {
|
|
|
|
|
/// Performs the multiplication `rhs = self * rhs` in-place.
|
|
|
|
|
pub fn rotate<R2: Dim, C2: Dim, S2: StorageMut<N, R2, C2>>(&self, rhs: &mut Matrix<N, R2, C2, S2>)
|
|
|
|
|
where ShapeConstraint: DimEq<R2, U2> {
|
|
|
|
|
|
|
|
|
|
assert_eq!(rhs.nrows(), 2, "Unit complex rotation: the input matrix must have exactly two rows.");
|
|
|
|
|
let i = self.as_ref().im;
|
|
|
|
|
let r = self.as_ref().re;
|
|
|
|
|
|
|
|
|
|
for j in 0 .. rhs.ncols() {
|
|
|
|
|
unsafe {
|
|
|
|
|
let a = *rhs.get_unchecked(0, j);
|
|
|
|
|
let b = *rhs.get_unchecked(1, j);
|
|
|
|
|
|
|
|
|
|
*rhs.get_unchecked_mut(0, j) = r * a - i * b;
|
|
|
|
|
*rhs.get_unchecked_mut(1, j) = i * a + r * b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Performs the multiplication `lhs = lhs * self` in-place.
|
|
|
|
|
pub fn rotate_rows<R2: Dim, C2: Dim, S2: StorageMut<N, R2, C2>>(&self, lhs: &mut Matrix<N, R2, C2, S2>)
|
|
|
|
|
where ShapeConstraint: DimEq<C2, U2> {
|
|
|
|
|
|
|
|
|
|
assert_eq!(lhs.ncols(), 2, "Unit complex rotation: the input matrix must have exactly two columns.");
|
|
|
|
|
let i = self.as_ref().im;
|
|
|
|
|
let r = self.as_ref().re;
|
|
|
|
|
|
|
|
|
|
// FIXME: can we optimize that to iterate on one column at a time ?
|
|
|
|
|
for j in 0 .. lhs.nrows() {
|
|
|
|
|
unsafe {
|
|
|
|
|
let a = *lhs.get_unchecked(j, 0);
|
|
|
|
|
let b = *lhs.get_unchecked(j, 1);
|
|
|
|
|
|
|
|
|
|
*lhs.get_unchecked_mut(j, 0) = r * a + i * b;
|
|
|
|
|
*lhs.get_unchecked_mut(j, 1) = -i * a + r * b;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|