diff --git a/src/geometry/mod.rs b/src/geometry/mod.rs index 37ca57f9..f79311e3 100644 --- a/src/geometry/mod.rs +++ b/src/geometry/mod.rs @@ -48,6 +48,13 @@ mod translation_coordinates; mod translation_ops; mod translation_simba; +mod scale; +mod scale_alias; +mod scale_construction; +mod scale_conversion; +mod scale_coordinates; +mod scale_ops; + mod isometry; mod isometry_alias; mod isometry_construction; @@ -95,6 +102,9 @@ pub use self::unit_complex::*; pub use self::translation::*; pub use self::translation_alias::*; +pub use self::scale::*; +pub use self::scale_alias::*; + pub use self::isometry::*; pub use self::isometry_alias::*; diff --git a/src/geometry/scale.rs b/src/geometry/scale.rs index 48656f9c..aa83c63c 100755 --- a/src/geometry/scale.rs +++ b/src/geometry/scale.rs @@ -20,21 +20,21 @@ use crate::base::{Const, DefaultAllocator, OMatrix, SVector, Scalar}; use crate::geometry::Point; -/// A translation. +/// A scale which supports non-uniform scaling. #[repr(C)] -pub struct Translation { - /// The translation coordinates, i.e., how much is added to a point's coordinates when it is - /// translated. +pub struct Scale { + /// The scale coordinates, i.e., how much is multiplied to a point's coordinates when it is + /// scaled. pub vector: SVector, } -impl fmt::Debug for Translation { +impl fmt::Debug for Scale { fn fmt(&self, formatter: &mut fmt::Formatter<'_>) -> Result<(), fmt::Error> { self.vector.as_slice().fmt(formatter) } } -impl hash::Hash for Translation +impl hash::Hash for Scale where Owned>: hash::Hash, { @@ -43,20 +43,20 @@ where } } -impl Copy for Translation {} +impl Copy for Scale {} -impl Clone for Translation +impl Clone for Scale where Owned>: Clone, { #[inline] fn clone(&self) -> Self { - Translation::from(self.vector.clone()) + Scale::from(self.vector.clone()) } } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Zeroable for Translation +unsafe impl bytemuck::Zeroable for Scale where T: Scalar + bytemuck::Zeroable, SVector: bytemuck::Zeroable, @@ -64,7 +64,7 @@ where } #[cfg(feature = "bytemuck")] -unsafe impl bytemuck::Pod for Translation +unsafe impl bytemuck::Pod for Scale where T: Scalar + bytemuck::Pod, SVector: bytemuck::Pod, @@ -72,7 +72,7 @@ where } #[cfg(feature = "abomonation-serialize")] -impl Abomonation for Translation +impl Abomonation for Scale where T: Scalar, SVector: Abomonation, @@ -91,7 +91,7 @@ where } #[cfg(feature = "serde-serialize-no-std")] -impl Serialize for Translation +impl Serialize for Scale where Owned>: Serialize, { @@ -104,7 +104,7 @@ where } #[cfg(feature = "serde-serialize-no-std")] -impl<'a, T: Scalar, const D: usize> Deserialize<'a> for Translation +impl<'a, T: Scalar, const D: usize> Deserialize<'a> for Scale where Owned>: Deserialize<'a>, { @@ -114,18 +114,18 @@ where { let matrix = SVector::::deserialize(deserializer)?; - Ok(Translation::from(matrix)) + Ok(Scale::from(matrix)) } } #[cfg(feature = "rkyv-serialize-no-std")] mod rkyv_impl { - use super::Translation; + use super::Scale; use crate::base::SVector; use rkyv::{offset_of, project_struct, Archive, Deserialize, Fallible, Serialize}; - impl Archive for Translation { - type Archived = Translation; + impl Archive for Scale { + type Archived = Scale; type Resolver = as Archive>::Resolver; fn resolve( @@ -142,69 +142,69 @@ mod rkyv_impl { } } - impl, S: Fallible + ?Sized, const D: usize> Serialize for Translation { + impl, S: Fallible + ?Sized, const D: usize> Serialize for Scale { fn serialize(&self, serializer: &mut S) -> Result { self.vector.serialize(serializer) } } - impl Deserialize, _D> - for Translation + impl Deserialize, _D> + for Scale where T::Archived: Deserialize, { - fn deserialize(&self, deserializer: &mut _D) -> Result, _D::Error> { - Ok(Translation { + fn deserialize(&self, deserializer: &mut _D) -> Result, _D::Error> { + Ok(Scale { vector: self.vector.deserialize(deserializer)?, }) } } } -impl Translation { - /// Creates a new translation from the given vector. +impl Scale { + /// Creates a new Scale from the given vector. #[inline] #[deprecated(note = "Use `::from` instead.")] - pub fn from_vector(vector: SVector) -> Translation { - Translation { vector } + pub fn from_vector(vector: SVector) -> Scale { + Scale { vector } } /// Inverts `self`. /// /// # Example /// ``` - /// # use nalgebra::{Translation2, Translation3}; - /// let t = Translation3::new(1.0, 2.0, 3.0); - /// assert_eq!(t * t.inverse(), Translation3::identity()); - /// assert_eq!(t.inverse() * t, Translation3::identity()); + /// # use nalgebra::{Scale2, Scale3}; + /// let t = Scale3::new(1.0, 2.0, 3.0); + /// assert_eq!(t * t.inverse(), Scale3::identity()); + /// assert_eq!(t.inverse() * t, Scale3::identity()); /// /// // Work in all dimensions. - /// let t = Translation2::new(1.0, 2.0); - /// assert_eq!(t * t.inverse(), Translation2::identity()); - /// assert_eq!(t.inverse() * t, Translation2::identity()); + /// let t = Scale2::new(1.0, 2.0); + /// assert_eq!(t * t.inverse(), Scale2::identity()); + /// assert_eq!(t.inverse() * t, Scale2::identity()); /// ``` #[inline] #[must_use = "Did you mean to use inverse_mut()?"] - pub fn inverse(&self) -> Translation + pub fn inverse(&self) -> Scale where T: ClosedNeg, { - Translation::from(-&self.vector) + todo!(); } - /// Converts this translation into its equivalent homogeneous transformation matrix. + /// Converts this Scale into its equivalent homogeneous transformation matrix. /// /// # Example /// ``` - /// # use nalgebra::{Translation2, Translation3, Matrix3, Matrix4}; - /// let t = Translation3::new(10.0, 20.0, 30.0); + /// # use nalgebra::{Scale2, Scale3, Matrix3, Matrix4}; + /// let t = Scale3::new(10.0, 20.0, 30.0); /// let expected = Matrix4::new(1.0, 0.0, 0.0, 10.0, /// 0.0, 1.0, 0.0, 20.0, /// 0.0, 0.0, 1.0, 30.0, /// 0.0, 0.0, 0.0, 1.0); /// assert_eq!(t.to_homogeneous(), expected); /// - /// let t = Translation2::new(10.0, 20.0); + /// let t = Scale2::new(10.0, 20.0); /// let expected = Matrix3::new(1.0, 0.0, 10.0, /// 0.0, 1.0, 20.0, /// 0.0, 0.0, 1.0); @@ -218,83 +218,80 @@ impl Translation { Const: DimNameAdd, DefaultAllocator: Allocator, U1>, DimNameSum, U1>>, { - let mut res = OMatrix::, U1>, DimNameSum, U1>>::identity(); - res.fixed_slice_mut::(0, D).copy_from(&self.vector); - - res + todo!(); } /// Inverts `self` in-place. /// /// # Example /// ``` - /// # use nalgebra::{Translation2, Translation3}; - /// let t = Translation3::new(1.0, 2.0, 3.0); - /// let mut inv_t = Translation3::new(1.0, 2.0, 3.0); + /// # use nalgebra::{Scale2, Scale3}; + /// let t = Scale3::new(1.0, 2.0, 3.0); + /// let mut inv_t = Scale3::new(1.0, 2.0, 3.0); /// inv_t.inverse_mut(); - /// assert_eq!(t * inv_t, Translation3::identity()); - /// assert_eq!(inv_t * t, Translation3::identity()); + /// assert_eq!(t * inv_t, Scale3::identity()); + /// assert_eq!(inv_t * t, Scale3::identity()); /// /// // Work in all dimensions. - /// let t = Translation2::new(1.0, 2.0); - /// let mut inv_t = Translation2::new(1.0, 2.0); + /// let t = Scale2::new(1.0, 2.0); + /// let mut inv_t = Scale2::new(1.0, 2.0); /// inv_t.inverse_mut(); - /// assert_eq!(t * inv_t, Translation2::identity()); - /// assert_eq!(inv_t * t, Translation2::identity()); + /// assert_eq!(t * inv_t, Scale2::identity()); + /// assert_eq!(inv_t * t, Scale2::identity()); /// ``` #[inline] pub fn inverse_mut(&mut self) where T: ClosedNeg, { - self.vector.neg_mut() + todo!(); } } -impl Translation { +impl Scale { /// Translate the given point. /// /// This is the same as the multiplication `self * pt`. /// /// # Example /// ``` - /// # use nalgebra::{Translation3, Point3}; - /// let t = Translation3::new(1.0, 2.0, 3.0); + /// # use nalgebra::{Scale3, Point3}; + /// let t = Scale3::new(1.0, 2.0, 3.0); /// let transformed_point = t.transform_point(&Point3::new(4.0, 5.0, 6.0)); /// assert_eq!(transformed_point, Point3::new(5.0, 7.0, 9.0)); #[inline] #[must_use] pub fn transform_point(&self, pt: &Point) -> Point { - pt + &self.vector + todo!(); } } -impl Translation { - /// Translate the given point by the inverse of this translation. +impl Scale { + /// Translate the given point by the inverse of this Scale. /// /// # Example /// ``` - /// # use nalgebra::{Translation3, Point3}; - /// let t = Translation3::new(1.0, 2.0, 3.0); + /// # use nalgebra::{Scale3, Point3}; + /// let t = Scale3::new(1.0, 2.0, 3.0); /// let transformed_point = t.inverse_transform_point(&Point3::new(4.0, 5.0, 6.0)); /// assert_eq!(transformed_point, Point3::new(3.0, 3.0, 3.0)); #[inline] #[must_use] pub fn inverse_transform_point(&self, pt: &Point) -> Point { - pt - &self.vector + todo!(); } } -impl Eq for Translation {} +impl Eq for Scale {} -impl PartialEq for Translation { +impl PartialEq for Scale { #[inline] - fn eq(&self, right: &Translation) -> bool { + fn eq(&self, right: &Scale) -> bool { self.vector == right.vector } } -impl AbsDiffEq for Translation +impl AbsDiffEq for Scale where T::Epsilon: Clone, { @@ -311,7 +308,7 @@ where } } -impl RelativeEq for Translation +impl RelativeEq for Scale where T::Epsilon: Clone, { @@ -332,7 +329,7 @@ where } } -impl UlpsEq for Translation +impl UlpsEq for Scale where T::Epsilon: Clone, { @@ -352,11 +349,11 @@ where * Display * */ -impl fmt::Display for Translation { +impl fmt::Display for Scale { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { let precision = f.precision().unwrap_or(3); - writeln!(f, "Translation {{")?; + writeln!(f, "Scale {{")?; write!(f, "{:.*}", precision, self.vector)?; writeln!(f, "}}") } diff --git a/src/geometry/scale_alias.rs b/src/geometry/scale_alias.rs index 06dc0794..87932442 100644 --- a/src/geometry/scale_alias.rs +++ b/src/geometry/scale_alias.rs @@ -1,19 +1,19 @@ -use crate::geometry::Translation; +use crate::geometry::Scale; -/// A 1-dimensional translation. -pub type Translation1 = Translation; +/// A 1-dimensional scale. +pub type Scale1 = Scale; -/// A 2-dimensional translation. -pub type Translation2 = Translation; +/// A 2-dimensional scale. +pub type Scale2 = Scale; -/// A 3-dimensional translation. -pub type Translation3 = Translation; +/// A 3-dimensional scale. +pub type Scale3 = Scale; -/// A 4-dimensional translation. -pub type Translation4 = Translation; +/// A 4-dimensional scale. +pub type Scale4 = Scale; -/// A 5-dimensional translation. -pub type Translation5 = Translation; +/// A 5-dimensional scale. +pub type Scale5 = Scale; -/// A 6-dimensional translation. -pub type Translation6 = Translation; +/// A 6-dimensional scale. +pub type Scale6 = Scale; diff --git a/src/geometry/scale_construction.rs b/src/geometry/scale_construction.rs index 5371b648..a3d9b151 100644 --- a/src/geometry/scale_construction.rs +++ b/src/geometry/scale_construction.rs @@ -13,49 +13,49 @@ use rand::{ use simba::scalar::{ClosedAdd, SupersetOf}; use crate::base::{SVector, Scalar}; -use crate::geometry::Translation; +use crate::geometry::Scale; -impl Translation { - /// Creates a new identity translation. +impl Scale { + /// Creates a new identity scale. /// /// # Example /// ``` - /// # use nalgebra::{Point2, Point3, Translation2, Translation3}; - /// let t = Translation2::identity(); + /// # use nalgebra::{Point2, Point3, Scale2, Scale3}; + /// let t = Scale2::identity(); /// let p = Point2::new(1.0, 2.0); /// assert_eq!(t * p, p); /// /// // Works in all dimensions. - /// let t = Translation3::identity(); + /// let t = Scale3::identity(); /// let p = Point3::new(1.0, 2.0, 3.0); /// assert_eq!(t * p, p); /// ``` #[inline] - pub fn identity() -> Translation + pub fn identity() -> Scale where T: Zero, { - Self::from(SVector::::from_element(T::zero())) + todo!(); } /// Cast the components of `self` to another type. /// /// # Example /// ``` - /// # use nalgebra::Translation2; - /// let tra = Translation2::new(1.0f64, 2.0); + /// # use nalgebra::Scale2; + /// let tra = Scale2::new(1.0f64, 2.0); /// let tra2 = tra.cast::(); - /// assert_eq!(tra2, Translation2::new(1.0f32, 2.0)); + /// assert_eq!(tra2, Scale2::new(1.0f32, 2.0)); /// ``` - pub fn cast(self) -> Translation + pub fn cast(self) -> Scale where - Translation: SupersetOf, + Scale: SupersetOf, { crate::convert(self) } } -impl One for Translation { +impl One for Scale { #[inline] fn one() -> Self { Self::identity() @@ -63,19 +63,19 @@ impl One for Translation { } #[cfg(feature = "rand-no-std")] -impl Distribution> for Standard +impl Distribution> for Standard where Standard: Distribution, { /// Generate an arbitrary random variate for testing purposes. #[inline] - fn sample(&self, rng: &mut G) -> Translation { - Translation::from(rng.gen::>()) + fn sample(&self, rng: &mut G) -> Scale { + Scale::from(rng.gen::>()) } } #[cfg(feature = "arbitrary")] -impl Arbitrary for Translation +impl Arbitrary for Scale where Owned>: Send, { @@ -88,14 +88,14 @@ where /* * - * Small translation construction from components. + * Small Scale construction from components. * */ macro_rules! componentwise_constructors_impl( ($($doc: expr; $D: expr, $($args: ident:$irow: expr),*);* $(;)*) => {$( - impl Translation + impl Scale { - #[doc = "Initializes this translation from its components."] + #[doc = "Initializes this Scale from its components."] #[doc = "# Example\n```"] #[doc = $doc] #[doc = "```"] @@ -108,16 +108,16 @@ macro_rules! componentwise_constructors_impl( ); componentwise_constructors_impl!( - "# use nalgebra::Translation1;\nlet t = Translation1::new(1.0);\nassert!(t.vector.x == 1.0);"; + "# use nalgebra::Scale1;\nlet t = Scale1::new(1.0);\nassert!(t.vector.x == 1.0);"; 1, x:0; - "# use nalgebra::Translation2;\nlet t = Translation2::new(1.0, 2.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0);"; + "# use nalgebra::Scale2;\nlet t = Scale2::new(1.0, 2.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0);"; 2, x:0, y:1; - "# use nalgebra::Translation3;\nlet t = Translation3::new(1.0, 2.0, 3.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0 && t.vector.z == 3.0);"; + "# use nalgebra::Scale3;\nlet t = Scale3::new(1.0, 2.0, 3.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0 && t.vector.z == 3.0);"; 3, x:0, y:1, z:2; - "# use nalgebra::Translation4;\nlet t = Translation4::new(1.0, 2.0, 3.0, 4.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0 && t.vector.z == 3.0 && t.vector.w == 4.0);"; + "# use nalgebra::Scale4;\nlet t = Scale4::new(1.0, 2.0, 3.0, 4.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0 && t.vector.z == 3.0 && t.vector.w == 4.0);"; 4, x:0, y:1, z:2, w:3; - "# use nalgebra::Translation5;\nlet t = Translation5::new(1.0, 2.0, 3.0, 4.0, 5.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0 && t.vector.z == 3.0 && t.vector.w == 4.0 && t.vector.a == 5.0);"; + "# use nalgebra::Scale5;\nlet t = Scale5::new(1.0, 2.0, 3.0, 4.0, 5.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0 && t.vector.z == 3.0 && t.vector.w == 4.0 && t.vector.a == 5.0);"; 5, x:0, y:1, z:2, w:3, a:4; - "# use nalgebra::Translation6;\nlet t = Translation6::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0 && t.vector.z == 3.0 && t.vector.w == 4.0 && t.vector.a == 5.0 && t.vector.b == 6.0);"; + "# use nalgebra::Scale6;\nlet t = Scale6::new(1.0, 2.0, 3.0, 4.0, 5.0, 6.0);\nassert!(t.vector.x == 1.0 && t.vector.y == 2.0 && t.vector.z == 3.0 && t.vector.w == 4.0 && t.vector.a == 5.0 && t.vector.b == 6.0);"; 6, x:0, y:1, z:2, w:3, a:4, b:5; ); diff --git a/src/geometry/scale_conversion.rs b/src/geometry/scale_conversion.rs index 70000efb..ed8d4c7a 100644 --- a/src/geometry/scale_conversion.rs +++ b/src/geometry/scale_conversion.rs @@ -8,8 +8,7 @@ use crate::base::dimension::{DimNameAdd, DimNameSum, U1}; use crate::base::{Const, DefaultAllocator, DimName, OMatrix, OVector, SVector, Scalar}; use crate::geometry::{ - AbstractRotation, Isometry, Similarity, SuperTCategoryOf, TAffine, Transform, Translation, - Translation3, UnitDualQuaternion, UnitQuaternion, + SuperTCategoryOf, TAffine, Transform, Scale }; use crate::Point; @@ -17,106 +16,35 @@ use crate::Point; * This file provides the following conversions: * ============================================= * - * Translation -> Translation - * Translation -> Isometry - * Translation3 -> UnitDualQuaternion - * Translation -> Similarity - * Translation -> Transform - * Translation -> Matrix (homogeneous) + * Scale -> Scale + * Scale -> Transform + * Scale -> Matrix (homogeneous) */ -impl SubsetOf> for Translation +impl SubsetOf> for Scale where T1: Scalar, T2: Scalar + SupersetOf, { #[inline] - fn to_superset(&self) -> Translation { - Translation::from(self.vector.to_superset()) + fn to_superset(&self) -> Scale { + Scale::from(self.vector.to_superset()) } #[inline] - fn is_in_subset(rot: &Translation) -> bool { + fn is_in_subset(rot: &Scale) -> bool { crate::is_convertible::<_, SVector>(&rot.vector) } #[inline] - fn from_superset_unchecked(rot: &Translation) -> Self { - Translation { + fn from_superset_unchecked(rot: &Scale) -> Self { + Scale { vector: rot.vector.to_subset_unchecked(), } } } -impl SubsetOf> for Translation -where - T1: RealField, - T2: RealField + SupersetOf, - R: AbstractRotation, -{ - #[inline] - fn to_superset(&self) -> Isometry { - Isometry::from_parts(self.to_superset(), R::identity()) - } - - #[inline] - fn is_in_subset(iso: &Isometry) -> bool { - iso.rotation == R::identity() - } - - #[inline] - fn from_superset_unchecked(iso: &Isometry) -> Self { - Self::from_superset_unchecked(&iso.translation) - } -} - -impl SubsetOf> for Translation3 -where - T1: RealField, - T2: RealField + SupersetOf, -{ - #[inline] - fn to_superset(&self) -> UnitDualQuaternion { - let dq = UnitDualQuaternion::::from_parts(self.clone(), UnitQuaternion::identity()); - dq.to_superset() - } - - #[inline] - fn is_in_subset(dq: &UnitDualQuaternion) -> bool { - crate::is_convertible::<_, Translation>(&dq.translation()) - && dq.rotation() == UnitQuaternion::identity() - } - - #[inline] - fn from_superset_unchecked(dq: &UnitDualQuaternion) -> Self { - let dq: UnitDualQuaternion = crate::convert_ref_unchecked(dq); - dq.translation() - } -} - -impl SubsetOf> for Translation -where - T1: RealField, - T2: RealField + SupersetOf, - R: AbstractRotation, -{ - #[inline] - fn to_superset(&self) -> Similarity { - Similarity::from_parts(self.to_superset(), R::identity(), T2::one()) - } - - #[inline] - fn is_in_subset(sim: &Similarity) -> bool { - sim.isometry.rotation == R::identity() && sim.scaling() == T2::one() - } - - #[inline] - fn from_superset_unchecked(sim: &Similarity) -> Self { - Self::from_superset_unchecked(&sim.isometry.translation) - } -} - -impl SubsetOf> for Translation +impl SubsetOf> for Scale where T1: RealField, T2: RealField + SupersetOf, @@ -142,7 +70,7 @@ where } impl - SubsetOf, U1>, DimNameSum, U1>>> for Translation + SubsetOf, U1>, DimNameSum, U1>>> for Scale where T1: RealField, T2: RealField + SupersetOf, @@ -180,7 +108,7 @@ where } } -impl From> +impl From> for OMatrix, U1>, DimNameSum, U1>> where Const: DimNameAdd, @@ -188,49 +116,49 @@ where Allocator, U1>, DimNameSum, U1>> + Allocator>, { #[inline] - fn from(t: Translation) -> Self { + fn from(t: Scale) -> Self { t.to_homogeneous() } } -impl From>> for Translation { +impl From>> for Scale { #[inline] fn from(vector: OVector>) -> Self { - Translation { vector } + Scale { vector } } } -impl From<[T; D]> for Translation { +impl From<[T; D]> for Scale { #[inline] fn from(coords: [T; D]) -> Self { - Translation { + Scale { vector: coords.into(), } } } -impl From> for Translation { +impl From> for Scale { #[inline] fn from(pt: Point) -> Self { - Translation { vector: pt.coords } + Scale { vector: pt.coords } } } -impl From> for [T; D] { +impl From> for [T; D] { #[inline] - fn from(t: Translation) -> Self { + fn from(t: Scale) -> Self { t.vector.into() } } -impl From<[Translation; 2]> - for Translation +impl From<[Scale; 2]> + for Scale where T: From<[::Element; 2]>, T::Element: Scalar, { #[inline] - fn from(arr: [Translation; 2]) -> Self { + fn from(arr: [Scale; 2]) -> Self { Self::from(OVector::from([ arr[0].vector.clone(), arr[1].vector.clone(), @@ -238,14 +166,14 @@ where } } -impl From<[Translation; 4]> - for Translation +impl From<[Scale; 4]> + for Scale where T: From<[::Element; 4]>, T::Element: Scalar, { #[inline] - fn from(arr: [Translation; 4]) -> Self { + fn from(arr: [Scale; 4]) -> Self { Self::from(OVector::from([ arr[0].vector.clone(), arr[1].vector.clone(), @@ -255,14 +183,14 @@ where } } -impl From<[Translation; 8]> - for Translation +impl From<[Scale; 8]> + for Scale where T: From<[::Element; 8]>, T::Element: Scalar, { #[inline] - fn from(arr: [Translation; 8]) -> Self { + fn from(arr: [Scale; 8]) -> Self { Self::from(OVector::from([ arr[0].vector.clone(), arr[1].vector.clone(), @@ -276,14 +204,14 @@ where } } -impl From<[Translation; 16]> - for Translation +impl From<[Scale; 16]> + for Scale where T: From<[::Element; 16]>, T::Element: Scalar, { #[inline] - fn from(arr: [Translation; 16]) -> Self { + fn from(arr: [Scale; 16]) -> Self { Self::from(OVector::from([ arr[0].vector.clone(), arr[1].vector.clone(), diff --git a/src/geometry/scale_coordinates.rs b/src/geometry/scale_coordinates.rs index 80267e06..2f3fb5bc 100644 --- a/src/geometry/scale_coordinates.rs +++ b/src/geometry/scale_coordinates.rs @@ -3,29 +3,29 @@ use std::ops::{Deref, DerefMut}; use crate::base::coordinates::{X, XY, XYZ, XYZW, XYZWA, XYZWAB}; use crate::base::Scalar; -use crate::geometry::Translation; +use crate::geometry::Scale; /* * - * Give coordinates to Translation{1 .. 6} + * Give coordinates to Scale{1 .. 6} * */ macro_rules! deref_impl( ($D: expr, $Target: ident $(, $comps: ident)*) => { - impl Deref for Translation { + impl Deref for Scale { type Target = $Target; #[inline] fn deref(&self) -> &Self::Target { - unsafe { &*(self as *const Translation as *const Self::Target) } + unsafe { &*(self as *const Scale as *const Self::Target) } } } - impl DerefMut for Translation { + impl DerefMut for Scale { #[inline] fn deref_mut(&mut self) -> &mut Self::Target { - unsafe { &mut *(self as *mut Translation as *mut Self::Target) } + unsafe { &mut *(self as *mut Scale as *mut Self::Target) } } } } diff --git a/src/geometry/scale_ops.rs b/src/geometry/scale_ops.rs index 8851183a..3bb04c83 100644 --- a/src/geometry/scale_ops.rs +++ b/src/geometry/scale_ops.rs @@ -6,114 +6,114 @@ use crate::base::constraint::{SameNumberOfColumns, SameNumberOfRows, ShapeConstr use crate::base::dimension::U1; use crate::base::{Const, Scalar}; -use crate::geometry::{Point, Translation}; +use crate::geometry::{Point, Scale}; -// Translation × Translation +// Scale × Scale add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: &'a Translation, right: &'b Translation, Output = Translation; - #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector + &right.vector) }; + self: &'a Scale, right: &'b Scale, Output = Scale; + #[allow(clippy::suspicious_arithmetic_impl)] { todo!(); }; 'a, 'b); add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: &'a Translation, right: Translation, Output = Translation; - #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector + right.vector) }; + self: &'a Scale, right: Scale, Output = Scale; + #[allow(clippy::suspicious_arithmetic_impl)] { todo!(); }; 'a); add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: Translation, right: &'b Translation, Output = Translation; - #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector + &right.vector) }; + self: Scale, right: &'b Scale, Output = Scale; + #[allow(clippy::suspicious_arithmetic_impl)] { todo!(); }; 'b); add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: Translation, right: Translation, Output = Translation; - #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector + right.vector) }; ); + self: Scale, right: Scale, Output = Scale; + #[allow(clippy::suspicious_arithmetic_impl)] { todo!(); }; ); -// Translation ÷ Translation +// Scale ÷ Scale // TODO: instead of calling inverse explicitly, could we just add a `mul_tr` or `mul_inv` method? add_sub_impl!(Div, div, ClosedSub; (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: &'a Translation, right: &'b Translation, Output = Translation; - #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector - &right.vector) }; + self: &'a Scale, right: &'b Scale, Output = Scale; + #[allow(clippy::suspicious_arithmetic_impl)] { todo!(); }; 'a, 'b); add_sub_impl!(Div, div, ClosedSub; (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: &'a Translation, right: Translation, Output = Translation; - #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(&self.vector - right.vector) }; + self: &'a Scale, right: Scale, Output = Scale; + #[allow(clippy::suspicious_arithmetic_impl)] { todo!(); }; 'a); add_sub_impl!(Div, div, ClosedSub; (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: Translation, right: &'b Translation, Output = Translation; - #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector - &right.vector) }; + self: Scale, right: &'b Scale, Output = Scale; + #[allow(clippy::suspicious_arithmetic_impl)] { todo!(); }; 'b); add_sub_impl!(Div, div, ClosedSub; (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: Translation, right: Translation, Output = Translation; - #[allow(clippy::suspicious_arithmetic_impl)] { Translation::from(self.vector - right.vector) }; ); + self: Scale, right: Scale, Output = Scale; + #[allow(clippy::suspicious_arithmetic_impl)] { todo!(); }; ); -// Translation × Point +// Scale × Point // TODO: we don't handle properly non-zero origins here. Do we want this to be the intended // behavior? add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: &'a Translation, right: &'b Point, Output = Point; - #[allow(clippy::suspicious_arithmetic_impl)] { right + &self.vector }; + self: &'a Scale, right: &'b Point, Output = Point; + #[allow(clippy::suspicious_arithmetic_impl)] { todo!(); }; 'a, 'b); add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: &'a Translation, right: Point, Output = Point; - #[allow(clippy::suspicious_arithmetic_impl)] { right + &self.vector }; + self: &'a Scale, right: Point, Output = Point; + #[allow(clippy::suspicious_arithmetic_impl)] { todo!(); }; 'a); add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: Translation, right: &'b Point, Output = Point; - #[allow(clippy::suspicious_arithmetic_impl)] { right + self.vector }; + self: Scale, right: &'b Point, Output = Point; + #[allow(clippy::suspicious_arithmetic_impl)] { todo!(); }; 'b); add_sub_impl!(Mul, mul, ClosedAdd; (Const, U1), (Const, U1) -> (Const, U1) const D; for; where; - self: Translation, right: Point, Output = Point; - #[allow(clippy::suspicious_arithmetic_impl)] { right + self.vector }; ); + self: Scale, right: Point, Output = Point; + #[allow(clippy::suspicious_arithmetic_impl)] { todo!(); }; ); -// Translation *= Translation +// Scale *= Scale add_sub_assign_impl!(MulAssign, mul_assign, ClosedAdd; const D; - self: Translation, right: &'b Translation; - #[allow(clippy::suspicious_op_assign_impl)] { self.vector += &right.vector }; + self: Scale, right: &'b Scale; + #[allow(clippy::suspicious_op_assign_impl)] { todo!(); }; 'b); add_sub_assign_impl!(MulAssign, mul_assign, ClosedAdd; const D; - self: Translation, right: Translation; - #[allow(clippy::suspicious_op_assign_impl)] { self.vector += right.vector }; ); + self: Scale, right: Scale; + #[allow(clippy::suspicious_op_assign_impl)] { todo!(); }; ); add_sub_assign_impl!(DivAssign, div_assign, ClosedSub; const D; - self: Translation, right: &'b Translation; - #[allow(clippy::suspicious_op_assign_impl)] { self.vector -= &right.vector }; + self: Scale, right: &'b Scale; + #[allow(clippy::suspicious_op_assign_impl)] { todo!(); }; 'b); add_sub_assign_impl!(DivAssign, div_assign, ClosedSub; const D; - self: Translation, right: Translation; - #[allow(clippy::suspicious_op_assign_impl)] { self.vector -= right.vector }; ); + self: Scale, right: Scale; + #[allow(clippy::suspicious_op_assign_impl)] { todo!(); }; );