Added inverse, inverse_mut inverse_transform_point and transform_point

This commit is contained in:
Yuri Edward 2021-10-19 15:02:50 +02:00
parent cf811abb92
commit c249cc76b0
1 changed files with 11 additions and 17 deletions

View File

@ -11,12 +11,12 @@ use serde::{Deserialize, Deserializer, Serialize, Serializer};
#[cfg(feature = "abomonation-serialize")] #[cfg(feature = "abomonation-serialize")]
use abomonation::Abomonation; use abomonation::Abomonation;
use simba::scalar::{ClosedAdd, ClosedNeg, ClosedSub};
use crate::base::allocator::Allocator; use crate::base::allocator::Allocator;
use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::dimension::{DimNameAdd, DimNameSum, U1};
use crate::base::storage::Owned; use crate::base::storage::Owned;
use crate::base::{Const, DefaultAllocator, OMatrix, SVector, Scalar}; use crate::base::{Const, DefaultAllocator, OMatrix, SVector, Scalar};
use crate::ClosedDiv;
use crate::ClosedMul;
use crate::geometry::Point; use crate::geometry::Point;
@ -162,13 +162,6 @@ mod rkyv_impl {
} }
impl<T: Scalar, const D: usize> Scale<T, D> { impl<T: Scalar, const D: usize> Scale<T, D> {
/// Creates a new Scale from the given vector.
#[inline]
#[deprecated(note = "Use `::from` instead.")]
pub fn from_vector(vector: SVector<T, D>) -> Scale<T, D> {
Scale { vector }
}
/// Inverts `self`. /// Inverts `self`.
/// ///
/// # Example /// # Example
@ -187,9 +180,10 @@ impl<T: Scalar, const D: usize> Scale<T, D> {
#[must_use = "Did you mean to use inverse_mut()?"] #[must_use = "Did you mean to use inverse_mut()?"]
pub fn inverse(&self) -> Scale<T, D> pub fn inverse(&self) -> Scale<T, D>
where where
T: ClosedNeg, T: ClosedDiv + One,
{ {
todo!(); let useless: SVector<T, D> = SVector::from_element(T::one());
return useless.component_div(&self.vector).into();
} }
/// Converts this Scale into its equivalent homogeneous transformation matrix. /// Converts this Scale into its equivalent homogeneous transformation matrix.
@ -242,13 +236,13 @@ impl<T: Scalar, const D: usize> Scale<T, D> {
#[inline] #[inline]
pub fn inverse_mut(&mut self) pub fn inverse_mut(&mut self)
where where
T: ClosedNeg, T: ClosedDiv + One,
{ {
todo!(); self.vector = self.inverse().vector;
} }
} }
impl<T: Scalar + ClosedAdd, const D: usize> Scale<T, D> { impl<T: Scalar + ClosedMul, const D: usize> Scale<T, D> {
/// Translate the given point. /// Translate the given point.
/// ///
/// This is the same as the multiplication `self * pt`. /// This is the same as the multiplication `self * pt`.
@ -262,11 +256,11 @@ impl<T: Scalar + ClosedAdd, const D: usize> Scale<T, D> {
#[inline] #[inline]
#[must_use] #[must_use]
pub fn transform_point(&self, pt: &Point<T, D>) -> Point<T, D> { pub fn transform_point(&self, pt: &Point<T, D>) -> Point<T, D> {
todo!(); return self * pt;
} }
} }
impl<T: Scalar + ClosedSub, const D: usize> Scale<T, D> { impl<T: Scalar + ClosedDiv + ClosedMul + One, const D: usize> Scale<T, D> {
/// Translate the given point by the inverse of this Scale. /// Translate the given point by the inverse of this Scale.
/// ///
/// # Example /// # Example
@ -278,7 +272,7 @@ impl<T: Scalar + ClosedSub, const D: usize> Scale<T, D> {
#[inline] #[inline]
#[must_use] #[must_use]
pub fn inverse_transform_point(&self, pt: &Point<T, D>) -> Point<T, D> { pub fn inverse_transform_point(&self, pt: &Point<T, D>) -> Point<T, D> {
todo!(); return self.inverse() * pt;
} }
} }