From 7c03e64e3edf8a2519a068507ba012197af36600 Mon Sep 17 00:00:00 2001 From: Cameron Hart Date: Mon, 24 Oct 2022 21:47:19 +1300 Subject: [PATCH] Removed affine transform ops that didn't make sense. (#354) Multiplying by scalar, adding and subtracting an affine transform don't really make sense when using a matrix to store an affine transform, therefore they don't make sense on the affine interface either. --- codegen/templates/affine.rs.tera | 46 +------------------------------- src/f32/affine2.rs | 46 +------------------------------- src/f32/affine3a.rs | 46 +------------------------------- src/f64/daffine2.rs | 46 +------------------------------- src/f64/daffine3.rs | 46 +------------------------------- tests/affine2.rs | 13 +++------ tests/affine3.rs | 20 ++++---------- 7 files changed, 14 insertions(+), 249 deletions(-) diff --git a/codegen/templates/affine.rs.tera b/codegen/templates/affine.rs.tera index 52064480..1946e7f9 100644 --- a/codegen/templates/affine.rs.tera +++ b/codegen/templates/affine.rs.tera @@ -47,7 +47,7 @@ use crate::{ {{ mat_t }}, {{ col_t}}, {{ mat4_t }}, {{ quat_t }}, {% endif %} }; -use core::ops::{Add, Deref, DerefMut, Mul, Sub}; +use core::ops::{Deref, DerefMut, Mul}; /// A {{ dim }}D affine transform, which can represent translation, rotation, scaling and shear. #[derive(Copy, Clone)] @@ -699,50 +699,6 @@ impl Mul for {{ self_t }} { } } -impl Mul<{{ self_t }}> for {{ scalar_t }} { - type Output = {{ self_t }}; - #[inline] - fn mul(self, rhs: {{ self_t }}) -> Self::Output { - {{ self_t }} { - matrix{{ dim }}: self * rhs.matrix{{ dim }}, - translation: self * rhs.translation, - } - } -} - -impl Mul<{{ scalar_t }}> for {{ self_t }} { - type Output = Self; - #[inline] - fn mul(self, rhs: {{ scalar_t }}) -> Self::Output { - Self { - matrix{{ dim }}: self.matrix{{ dim }} * rhs, - translation: self.translation * rhs, - } - } -} - -impl Add<{{ self_t }}> for {{ self_t }} { - type Output = Self; - #[inline] - fn add(self, rhs: Self) -> Self::Output { - Self { - matrix{{ dim }}: self.matrix{{ dim }} + rhs.matrix{{ dim }}, - translation: self.translation + rhs.translation, - } - } -} - -impl Sub<{{ self_t }}> for {{ self_t }} { - type Output = Self; - #[inline] - fn sub(self, rhs: Self) -> Self::Output { - Self { - matrix{{ dim }}: self.matrix{{ dim }} - rhs.matrix{{ dim }}, - translation: self.translation - rhs.translation, - } - } -} - {% if dim == 2 %} impl From<{{ self_t }}> for {{ mat3_t }} { #[inline] diff --git a/src/f32/affine2.rs b/src/f32/affine2.rs index 2befa9a9..c2a438e7 100644 --- a/src/f32/affine2.rs +++ b/src/f32/affine2.rs @@ -1,7 +1,7 @@ // Generated from affine.rs.tera template. Edit the template, not the generated file. use crate::{Mat2, Mat3, Mat3A, Vec2, Vec3A}; -use core::ops::{Add, Deref, DerefMut, Mul, Sub}; +use core::ops::{Deref, DerefMut, Mul}; /// A 2D affine transform, which can represent translation, rotation, scaling and shear. #[derive(Copy, Clone)] @@ -339,50 +339,6 @@ impl Mul for Affine2 { } } -impl Mul for f32 { - type Output = Affine2; - #[inline] - fn mul(self, rhs: Affine2) -> Self::Output { - Affine2 { - matrix2: self * rhs.matrix2, - translation: self * rhs.translation, - } - } -} - -impl Mul for Affine2 { - type Output = Self; - #[inline] - fn mul(self, rhs: f32) -> Self::Output { - Self { - matrix2: self.matrix2 * rhs, - translation: self.translation * rhs, - } - } -} - -impl Add for Affine2 { - type Output = Self; - #[inline] - fn add(self, rhs: Self) -> Self::Output { - Self { - matrix2: self.matrix2 + rhs.matrix2, - translation: self.translation + rhs.translation, - } - } -} - -impl Sub for Affine2 { - type Output = Self; - #[inline] - fn sub(self, rhs: Self) -> Self::Output { - Self { - matrix2: self.matrix2 - rhs.matrix2, - translation: self.translation - rhs.translation, - } - } -} - impl From for Mat3 { #[inline] fn from(m: Affine2) -> Mat3 { diff --git a/src/f32/affine3a.rs b/src/f32/affine3a.rs index a6f27dd6..40cc66e6 100644 --- a/src/f32/affine3a.rs +++ b/src/f32/affine3a.rs @@ -1,7 +1,7 @@ // Generated from affine.rs.tera template. Edit the template, not the generated file. use crate::{Mat3, Mat3A, Mat4, Quat, Vec3, Vec3A}; -use core::ops::{Add, Deref, DerefMut, Mul, Sub}; +use core::ops::{Deref, DerefMut, Mul}; /// A 3D affine transform, which can represent translation, rotation, scaling and shear. #[derive(Copy, Clone)] @@ -500,50 +500,6 @@ impl Mul for Affine3A { } } -impl Mul for f32 { - type Output = Affine3A; - #[inline] - fn mul(self, rhs: Affine3A) -> Self::Output { - Affine3A { - matrix3: self * rhs.matrix3, - translation: self * rhs.translation, - } - } -} - -impl Mul for Affine3A { - type Output = Self; - #[inline] - fn mul(self, rhs: f32) -> Self::Output { - Self { - matrix3: self.matrix3 * rhs, - translation: self.translation * rhs, - } - } -} - -impl Add for Affine3A { - type Output = Self; - #[inline] - fn add(self, rhs: Self) -> Self::Output { - Self { - matrix3: self.matrix3 + rhs.matrix3, - translation: self.translation + rhs.translation, - } - } -} - -impl Sub for Affine3A { - type Output = Self; - #[inline] - fn sub(self, rhs: Self) -> Self::Output { - Self { - matrix3: self.matrix3 - rhs.matrix3, - translation: self.translation - rhs.translation, - } - } -} - impl From for Mat4 { #[inline] fn from(m: Affine3A) -> Mat4 { diff --git a/src/f64/daffine2.rs b/src/f64/daffine2.rs index 31014919..4e1d76a6 100644 --- a/src/f64/daffine2.rs +++ b/src/f64/daffine2.rs @@ -1,7 +1,7 @@ // Generated from affine.rs.tera template. Edit the template, not the generated file. use crate::{DMat2, DMat3, DVec2}; -use core::ops::{Add, Deref, DerefMut, Mul, Sub}; +use core::ops::{Deref, DerefMut, Mul}; /// A 2D affine transform, which can represent translation, rotation, scaling and shear. #[derive(Copy, Clone)] @@ -329,50 +329,6 @@ impl Mul for DAffine2 { } } -impl Mul for f64 { - type Output = DAffine2; - #[inline] - fn mul(self, rhs: DAffine2) -> Self::Output { - DAffine2 { - matrix2: self * rhs.matrix2, - translation: self * rhs.translation, - } - } -} - -impl Mul for DAffine2 { - type Output = Self; - #[inline] - fn mul(self, rhs: f64) -> Self::Output { - Self { - matrix2: self.matrix2 * rhs, - translation: self.translation * rhs, - } - } -} - -impl Add for DAffine2 { - type Output = Self; - #[inline] - fn add(self, rhs: Self) -> Self::Output { - Self { - matrix2: self.matrix2 + rhs.matrix2, - translation: self.translation + rhs.translation, - } - } -} - -impl Sub for DAffine2 { - type Output = Self; - #[inline] - fn sub(self, rhs: Self) -> Self::Output { - Self { - matrix2: self.matrix2 - rhs.matrix2, - translation: self.translation - rhs.translation, - } - } -} - impl From for DMat3 { #[inline] fn from(m: DAffine2) -> DMat3 { diff --git a/src/f64/daffine3.rs b/src/f64/daffine3.rs index fb112a21..a5f45350 100644 --- a/src/f64/daffine3.rs +++ b/src/f64/daffine3.rs @@ -1,7 +1,7 @@ // Generated from affine.rs.tera template. Edit the template, not the generated file. use crate::{DMat3, DMat4, DQuat, DVec3}; -use core::ops::{Add, Deref, DerefMut, Mul, Sub}; +use core::ops::{Deref, DerefMut, Mul}; /// A 3D affine transform, which can represent translation, rotation, scaling and shear. #[derive(Copy, Clone)] @@ -489,50 +489,6 @@ impl Mul for DAffine3 { } } -impl Mul for f64 { - type Output = DAffine3; - #[inline] - fn mul(self, rhs: DAffine3) -> Self::Output { - DAffine3 { - matrix3: self * rhs.matrix3, - translation: self * rhs.translation, - } - } -} - -impl Mul for DAffine3 { - type Output = Self; - #[inline] - fn mul(self, rhs: f64) -> Self::Output { - Self { - matrix3: self.matrix3 * rhs, - translation: self.translation * rhs, - } - } -} - -impl Add for DAffine3 { - type Output = Self; - #[inline] - fn add(self, rhs: Self) -> Self::Output { - Self { - matrix3: self.matrix3 + rhs.matrix3, - translation: self.translation + rhs.translation, - } - } -} - -impl Sub for DAffine3 { - type Output = Self; - #[inline] - fn sub(self, rhs: Self) -> Self::Output { - Self { - matrix3: self.matrix3 - rhs.matrix3, - translation: self.translation - rhs.translation, - } - } -} - impl From for DMat4 { #[inline] fn from(m: DAffine3) -> DMat4 { diff --git a/tests/affine2.rs b/tests/affine2.rs index 98b29c67..e547dbbb 100644 --- a/tests/affine2.rs +++ b/tests/affine2.rs @@ -48,10 +48,10 @@ macro_rules! impl_affine2_tests { assert_eq!(MATRIX2D[2], a.z_axis.to_array()); let mut b = a; - b.x_axis *= 2.0; - b.y_axis *= 2.0; - b.z_axis *= 2.0; - assert_eq!(a * 2.0, b); + b.x_axis *= 0.0; + b.y_axis *= 0.0; + b.z_axis *= 0.0; + assert_eq!($affine2::ZERO, b); }); glam_test!(test_affine2_from_mat2, { @@ -149,11 +149,6 @@ macro_rules! impl_affine2_tests { glam_test!(test_affine2_ops, { let m0 = $affine2::from_cols_array_2d(&MATRIX2D); - let m0x2 = $affine2::from_cols_array_2d(&[[2.0, 4.0], [6.0, 8.0], [10.0, 12.0]]); - assert_eq!(m0x2, m0 * 2.0); - assert_eq!(m0x2, 2.0 * m0); - assert_eq!(m0x2, m0 + m0); - assert_eq!($affine2::ZERO, m0 - m0); assert_approx_eq!(m0, m0 * $affine2::IDENTITY); assert_approx_eq!(m0, $affine2::IDENTITY * m0); diff --git a/tests/affine3.rs b/tests/affine3.rs index 4527341c..86d5a53d 100644 --- a/tests/affine3.rs +++ b/tests/affine3.rs @@ -57,11 +57,11 @@ macro_rules! impl_affine3_tests { assert_eq!(MATRIX2D[3], a.w_axis.to_array()); let mut b = a; - b.x_axis *= 2.0; - b.y_axis *= 2.0; - b.z_axis *= 2.0; - b.w_axis *= 2.0; - assert_eq!(a * 2.0, b); + b.x_axis *= 0.0; + b.y_axis *= 0.0; + b.z_axis *= 0.0; + b.w_axis *= 0.0; + assert_eq!($affine3::ZERO, b); }); glam_test!(test_affine3_from_mat3, { @@ -291,16 +291,6 @@ macro_rules! impl_affine3_tests { glam_test!(test_affine3_ops, { let m0 = $affine3::from_cols_array_2d(&MATRIX2D); - let m0x2 = $affine3::from_cols_array_2d(&[ - [2.0, 4.0, 6.0], - [8.0, 10.0, 12.0], - [14.0, 16.0, 18.0], - [20.0, 22.0, 24.0], - ]); - assert_eq!(m0x2, m0 * 2.0); - assert_eq!(m0x2, 2.0 * m0); - assert_eq!(m0x2, m0 + m0); - assert_eq!($affine3::ZERO, m0 - m0); assert_approx_eq!(m0, m0 * $affine3::IDENTITY); assert_approx_eq!(m0, $affine3::IDENTITY * m0);