Re-add some missing transform multiplications.

This commit is contained in:
Sébastien Crozet 2020-03-24 19:06:28 +01:00
parent 81bb9e94f8
commit a095a7dfcd
6 changed files with 172 additions and 27 deletions

View File

@ -5,11 +5,13 @@ use simba::scalar::{ClosedAdd, ClosedMul};
use simba::simd::SimdRealField; use simba::simd::SimdRealField;
use crate::base::allocator::Allocator; use crate::base::allocator::Allocator;
use crate::base::dimension::{DimName, U1, U3, U4}; use crate::base::dimension::{DimName, U1, U2, U3, U4};
use crate::base::{DefaultAllocator, Unit, VectorN}; use crate::base::{DefaultAllocator, Unit, VectorN};
use crate::Scalar; use crate::Scalar;
use crate::geometry::{AbstractRotation, Isometry, Point, Rotation, Translation, UnitQuaternion}; use crate::geometry::{
AbstractRotation, Isometry, Point, Rotation, Translation, UnitComplex, UnitQuaternion,
};
// FIXME: there are several cloning of rotations that we could probably get rid of (but we didn't // FIXME: there are several cloning of rotations that we could probably get rid of (but we didn't
// yet because that would require to add a bound like `where for<'a, 'b> &'a R: Mul<&'b R, Output = R>` // yet because that would require to add a bound like `where for<'a, 'b> &'a R: Mul<&'b R, Output = R>`
@ -228,6 +230,23 @@ md_assign_impl_all!(
[ref] => *self *= rhs.inverse(); [ref] => *self *= rhs.inverse();
); );
md_assign_impl_all!(
MulAssign, mul_assign where N: SimdRealField for N::Element: SimdRealField;
(U2, U2), (U2, U2) for;
self: Isometry<N, U2, UnitComplex<N>>, rhs: UnitComplex<N>;
[val] => self.rotation *= rhs;
[ref] => self.rotation *= rhs.clone();
);
md_assign_impl_all!(
DivAssign, div_assign where N: SimdRealField for N::Element: SimdRealField;
(U2, U2), (U2, U2) for;
self: Isometry<N, U2, UnitComplex<N>>, rhs: UnitComplex<N>;
// FIXME: don't invert explicitly?
[val] => *self *= rhs.inverse();
[ref] => *self *= rhs.inverse();
);
// Isometry × Point // Isometry × Point
isometry_binop_impl_all!( isometry_binop_impl_all!(
Mul, mul; Mul, mul;
@ -487,3 +506,27 @@ isometry_from_composition_impl_all!(
[val ref] => Isometry::from_parts(self, right.clone()); [val ref] => Isometry::from_parts(self, right.clone());
[ref ref] => Isometry::from_parts(self.clone(), right.clone()); [ref ref] => Isometry::from_parts(self.clone(), right.clone());
); );
// Isometry × UnitComplex
isometry_from_composition_impl_all!(
Mul, mul;
(U2, U1), (U2, U1);
self: Isometry<N, U2, UnitComplex<N>>, rhs: UnitComplex<N>,
Output = Isometry<N, U2, UnitComplex<N>>;
[val val] => Isometry::from_parts(self.translation, self.rotation * rhs);
[ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs); // FIXME: do not clone.
[val ref] => Isometry::from_parts(self.translation, self.rotation * rhs.clone());
[ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() * rhs.clone());
);
// Isometry ÷ UnitComplex
isometry_from_composition_impl_all!(
Div, div;
(U2, U1), (U2, U1);
self: Isometry<N, U2, UnitComplex<N>>, rhs: UnitComplex<N>,
Output = Isometry<N, U2, UnitComplex<N>>;
[val val] => Isometry::from_parts(self.translation, self.rotation / rhs);
[ref val] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs); // FIXME: do not clone.
[val ref] => Isometry::from_parts(self.translation, self.rotation / rhs.clone());
[ref ref] => Isometry::from_parts(self.translation.clone(), self.rotation.clone() / rhs.clone());
);

View File

@ -12,6 +12,8 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cfg(feature = "abomonation-serialize")] #[cfg(feature = "abomonation-serialize")]
use abomonation::Abomonation; use abomonation::Abomonation;
use simba::simd::SimdPartialOrd;
use crate::base::allocator::Allocator; use crate::base::allocator::Allocator;
use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1}; use crate::base::dimension::{DimName, DimNameAdd, DimNameSum, U1};
use crate::base::iter::{MatrixIter, MatrixIterMut}; use crate::base::iter::{MatrixIter, MatrixIterMut};
@ -307,6 +309,32 @@ where DefaultAllocator: Allocator<N, D>
} }
} }
/*
* inf/sup
*/
impl<N: Scalar + SimdPartialOrd, D: DimName> Point<N, D>
where DefaultAllocator: Allocator<N, D>
{
/// Computes the infimum (aka. componentwise min) of two points.
#[inline]
pub fn inf(&self, other: &Self) -> Point<N, D> {
self.coords.inf(&other.coords).into()
}
/// Computes the supremum (aka. componentwise max) of two points.
#[inline]
pub fn sup(&self, other: &Self) -> Point<N, D> {
self.coords.sup(&other.coords).into()
}
/// Computes the (infimum, supremum) of two points.
#[inline]
pub fn inf_sup(&self, other: &Self) -> (Point<N, D>, Point<N, D>) {
let (inf, sup) = self.coords.inf_sup(&other.coords);
(inf.into(), sup.into())
}
}
/* /*
* *
* Display * Display

View File

@ -124,11 +124,15 @@ where
self.scaling = scaling; self.scaling = scaling;
} }
}
impl<N: Scalar, D: DimName, R> Similarity<N, D, R>
where DefaultAllocator: Allocator<N, D>
{
/// The scaling factor of this similarity transformation. /// The scaling factor of this similarity transformation.
#[inline] #[inline]
pub fn scaling(&self) -> N { pub fn scaling(&self) -> N {
self.scaling.clone() self.scaling.inlined_clone()
} }
} }

View File

@ -5,11 +5,12 @@ use simba::scalar::{ClosedAdd, ClosedMul};
use simba::simd::SimdRealField; use simba::simd::SimdRealField;
use crate::base::allocator::Allocator; use crate::base::allocator::Allocator;
use crate::base::dimension::{DimName, U1, U3, U4}; use crate::base::dimension::{DimName, U1, U2, U3, U4};
use crate::base::{DefaultAllocator, Scalar, VectorN}; use crate::base::{DefaultAllocator, Scalar, VectorN};
use crate::geometry::{ use crate::geometry::{
AbstractRotation, Isometry, Point, Rotation, Similarity, Translation, UnitQuaternion, AbstractRotation, Isometry, Point, Rotation, Similarity, Translation, UnitComplex,
UnitQuaternion,
}; };
// FIXME: there are several cloning of rotations that we could probably get rid of (but we didn't // FIXME: there are several cloning of rotations that we could probably get rid of (but we didn't
@ -252,6 +253,23 @@ md_assign_impl_all!(
[ref] => *self *= rhs.inverse(); [ref] => *self *= rhs.inverse();
); );
md_assign_impl_all!(
MulAssign, mul_assign where N: SimdRealField for N::Element: SimdRealField;
(U2, U2), (U2, U2) for;
self: Similarity<N, U2, UnitComplex<N>>, rhs: UnitComplex<N>;
[val] => self.isometry.rotation *= rhs;
[ref] => self.isometry.rotation *= rhs.clone();
);
md_assign_impl_all!(
DivAssign, div_assign where N: SimdRealField for N::Element: SimdRealField;
(U2, U2), (U2, U2) for;
self: Similarity<N, U2, UnitComplex<N>>, rhs: UnitComplex<N>;
// FIXME: don't invert explicitly?
[val] => *self *= rhs.inverse();
[ref] => *self *= rhs.inverse();
);
// Similarity × Isometry // Similarity × Isometry
// Similarity ÷ Isometry // Similarity ÷ Isometry
similarity_binop_impl_all!( similarity_binop_impl_all!(
@ -513,7 +531,7 @@ similarity_from_composition_impl_all!(
[ref ref] => Similarity::from_isometry(self * &right.isometry, right.scaling()); [ref ref] => Similarity::from_isometry(self * &right.isometry, right.scaling());
); );
// Similarity ÷ Rotation // Similarity ÷ UnitQuaternion
similarity_from_composition_impl_all!( similarity_from_composition_impl_all!(
Div, div; Div, div;
(U4, U1), (U3, U1); (U4, U1), (U3, U1);
@ -543,3 +561,39 @@ similarity_from_composition_impl_all!(
[val ref] => self * right.inverse(); [val ref] => self * right.inverse();
[ref ref] => self * right.inverse(); [ref ref] => self * right.inverse();
); );
// Similarity × UnitComplex
similarity_from_composition_impl_all!(
Mul, mul;
(U2, U1), (U2, U1);
self: Similarity<N, U2, UnitComplex<N>>, rhs: UnitComplex<N>,
Output = Similarity<N, U2, UnitComplex<N>>;
[val val] => {
let scaling = self.scaling();
Similarity::from_isometry(self.isometry * rhs, scaling)
};
[ref val] => Similarity::from_isometry(&self.isometry * rhs, self.scaling());
[val ref] => {
let scaling = self.scaling();
Similarity::from_isometry(self.isometry * rhs, scaling)
};
[ref ref] => Similarity::from_isometry(&self.isometry * rhs, self.scaling());
);
// Similarity ÷ UnitComplex
similarity_from_composition_impl_all!(
Div, div;
(U2, U1), (U2, U1);
self: Similarity<N, U2, UnitComplex<N>>, rhs: UnitComplex<N>,
Output = Similarity<N, U2, UnitComplex<N>>;
[val val] => {
let scaling = self.scaling();
Similarity::from_isometry(self.isometry / rhs, scaling)
};
[ref val] => Similarity::from_isometry(&self.isometry / rhs, self.scaling());
[val ref] => {
let scaling = self.scaling();
Similarity::from_isometry(self.isometry / rhs, scaling)
};
[ref ref] => Similarity::from_isometry(&self.isometry / rhs, self.scaling());
);

View File

@ -29,8 +29,6 @@ use simba::simd::SimdRealField;
* UnitComplex × Similarity<UnitComplex> * UnitComplex × Similarity<UnitComplex>
* UnitComplex × Translation -> Isometry<UnitComplex> * UnitComplex × Translation -> Isometry<UnitComplex>
* *
* NOTE: -UnitComplex is already provided by `Unit<T>`.
*
* (Assignment Operators) * (Assignment Operators)
* *
* UnitComplex ×= UnitComplex * UnitComplex ×= UnitComplex

View File

@ -153,7 +153,7 @@ pub use num_complex::Complex;
pub use simba::scalar::{ pub use simba::scalar::{
ClosedAdd, ClosedDiv, ClosedMul, ClosedSub, ComplexField, Field, RealField, ClosedAdd, ClosedDiv, ClosedMul, ClosedSub, ComplexField, Field, RealField,
}; };
pub use simba::simd::{SimdBool, SimdComplexField, SimdRealField}; pub use simba::simd::{SimdBool, SimdComplexField, SimdPartialOrd, SimdRealField};
/// Gets the multiplicative identity element. /// Gets the multiplicative identity element.
/// ///
@ -249,29 +249,47 @@ pub fn min<T: Ord>(a: T, b: T) -> T {
/// The absolute value of `a`. /// The absolute value of `a`.
/// ///
/// Deprecated: Use [Matrix::abs] or [RealField::abs] instead. /// Deprecated: Use [Matrix::abs] or [RealField::abs] instead.
#[deprecated(note = "use `Matrix::abs` or `RealField::abs` instead")] #[deprecated(note = "use the inherent method `Matrix::abs` or `RealField::abs` instead")]
#[inline] #[inline]
pub fn abs<T: Signed>(a: &T) -> T { pub fn abs<T: Signed>(a: &T) -> T {
a.abs() a.abs()
} }
///// Returns the infimum of `a` and `b`. /// Returns the infimum of `a` and `b`.
//#[inline] #[deprecated(note = "use the inherent method `Matrix::inf` instead")]
//pub fn inf<T: MeetSemilattice>(a: &T, b: &T) -> T { #[inline]
// a.meet(b) pub fn inf<N, R: Dim, C: Dim>(a: &MatrixMN<N, R, C>, b: &MatrixMN<N, R, C>) -> MatrixMN<N, R, C>
//} where
// N: Scalar + SimdPartialOrd,
///// Returns the supremum of `a` and `b`. DefaultAllocator: Allocator<N, R, C>,
//#[inline] {
//pub fn sup<T: JoinSemilattice>(a: &T, b: &T) -> T { a.inf(b)
// a.join(b) }
//}
// /// Returns the supremum of `a` and `b`.
///// Returns simultaneously the infimum and supremum of `a` and `b`. #[deprecated(note = "use the inherent method `Matrix::sup` instead")]
//#[inline] #[inline]
//pub fn inf_sup<T: Lattice>(a: &T, b: &T) -> (T, T) { pub fn sup<N, R: Dim, C: Dim>(a: &MatrixMN<N, R, C>, b: &MatrixMN<N, R, C>) -> MatrixMN<N, R, C>
// a.meet_join(b) where
//} N: Scalar + SimdPartialOrd,
DefaultAllocator: Allocator<N, R, C>,
{
a.sup(b)
}
/// Returns simultaneously the infimum and supremum of `a` and `b`.
#[deprecated(note = "use the inherent method `Matrix::inf_sup` instead")]
#[inline]
pub fn inf_sup<N, R: Dim, C: Dim>(
a: &MatrixMN<N, R, C>,
b: &MatrixMN<N, R, C>,
) -> (MatrixMN<N, R, C>, MatrixMN<N, R, C>)
where
N: Scalar + SimdPartialOrd,
DefaultAllocator: Allocator<N, R, C>,
{
a.inf_sup(b)
}
/// Compare `a` and `b` using a partial ordering relation. /// Compare `a` and `b` using a partial ordering relation.
#[inline] #[inline]