Skip to content

Commit

Permalink
Implement MulAssign for affine types (#425)
Browse files Browse the repository at this point in the history
  • Loading branch information
terrybrash authored Sep 22, 2023
1 parent 121d0e2 commit 030c4e2
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 5 deletions.
9 changes: 8 additions & 1 deletion codegen/templates/affine.rs.tera
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use crate::{
{{ mat_t }}, {{ col_t}}, {{ mat4_t }}, {{ quat_t }},
{% endif %}
};
use core::ops::{Deref, DerefMut, Mul};
use core::ops::{Deref, DerefMut, Mul, MulAssign};

/// A {{ dim }}D affine transform, which can represent translation, rotation, scaling and shear.
{%- if is_align %}
Expand Down Expand Up @@ -727,6 +727,13 @@ impl Mul for {{ self_t }} {
}
}

impl MulAssign for {{ self_t }} {
#[inline]
fn mul_assign(&mut self, rhs: {{ self_t }}) {
*self = self.mul(rhs);
}
}

{% if dim == 2 %}
impl From<{{ self_t }}> for {{ mat3_t }} {
#[inline]
Expand Down
9 changes: 8 additions & 1 deletion src/f32/affine2.rs
Original file line number Diff line number Diff line change
@@ -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::{Deref, DerefMut, Mul};
use core::ops::{Deref, DerefMut, Mul, MulAssign};

/// A 2D affine transform, which can represent translation, rotation, scaling and shear.
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -366,6 +366,13 @@ impl Mul for Affine2 {
}
}

impl MulAssign for Affine2 {
#[inline]
fn mul_assign(&mut self, rhs: Affine2) {
*self = self.mul(rhs);
}
}

impl From<Affine2> for Mat3 {
#[inline]
fn from(m: Affine2) -> Mat3 {
Expand Down
9 changes: 8 additions & 1 deletion src/f32/affine3a.rs
Original file line number Diff line number Diff line change
@@ -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::{Deref, DerefMut, Mul};
use core::ops::{Deref, DerefMut, Mul, MulAssign};

/// A 3D affine transform, which can represent translation, rotation, scaling and shear.
///
Expand Down Expand Up @@ -499,6 +499,13 @@ impl Mul for Affine3A {
}
}

impl MulAssign for Affine3A {
#[inline]
fn mul_assign(&mut self, rhs: Affine3A) {
*self = self.mul(rhs);
}
}

impl From<Affine3A> for Mat4 {
#[inline]
fn from(m: Affine3A) -> Mat4 {
Expand Down
9 changes: 8 additions & 1 deletion src/f64/daffine2.rs
Original file line number Diff line number Diff line change
@@ -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::{Deref, DerefMut, Mul};
use core::ops::{Deref, DerefMut, Mul, MulAssign};

/// A 2D affine transform, which can represent translation, rotation, scaling and shear.
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -356,6 +356,13 @@ impl Mul for DAffine2 {
}
}

impl MulAssign for DAffine2 {
#[inline]
fn mul_assign(&mut self, rhs: DAffine2) {
*self = self.mul(rhs);
}
}

impl From<DAffine2> for DMat3 {
#[inline]
fn from(m: DAffine2) -> DMat3 {
Expand Down
9 changes: 8 additions & 1 deletion src/f64/daffine3.rs
Original file line number Diff line number Diff line change
@@ -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::{Deref, DerefMut, Mul};
use core::ops::{Deref, DerefMut, Mul, MulAssign};

/// A 3D affine transform, which can represent translation, rotation, scaling and shear.
#[derive(Copy, Clone)]
Expand Down Expand Up @@ -486,6 +486,13 @@ impl Mul for DAffine3 {
}
}

impl MulAssign for DAffine3 {
#[inline]
fn mul_assign(&mut self, rhs: DAffine3) {
*self = self.mul(rhs);
}
}

impl From<DAffine3> for DMat4 {
#[inline]
fn from(m: DAffine3) -> DMat4 {
Expand Down

0 comments on commit 030c4e2

Please sign in to comment.