Skip to content

Commit

Permalink
add missing conversions and tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
bitshifter committed Feb 17, 2024
1 parent 24bd718 commit 6dd8147
Show file tree
Hide file tree
Showing 15 changed files with 229 additions and 62 deletions.
36 changes: 36 additions & 0 deletions codegen/templates/mat.rs.tera
Expand Up @@ -68,6 +68,11 @@ use crate::{
Mat{{ dim }},
{% endif %}
{% if dim == 2 %}
{% if is_align %}
{{ mat2_t }},
{% elif scalar_t == "f32" %}
Mat2A,
{% endif %}
{{ mat3_t }}, {{ vec2_t }},
{% if scalar_t == "f32" %}
Mat3A,
Expand Down Expand Up @@ -2238,6 +2243,21 @@ impl MulAssign<{{ scalar_t }}> for {{ self_t }} {
}
}

{% if self_t == "Mat2" %}
impl From<Mat2A> for Mat2 {
#[inline]
fn from(m: Mat2A) -> Self {
Self::from_cols(m.x_axis, m.y_axis)
}
}
{% elif self_t == "Mat2A" %}
impl From<Mat2> for Mat2A {
#[inline]
fn from(m: Mat2) -> Self {
Self::from_cols(m.x_axis, m.y_axis)
}
}
{% endif %}
{% if self_t == "Mat3" %}
impl Mul<Vec3A> for Mat3 {
type Output = Vec3A;
Expand Down Expand Up @@ -2279,6 +2299,14 @@ impl From<Mat3> for Mat3A {
{% endif %}

{% if self_t == "Mat4" %}
impl Mul<Vec4A> for Mat4 {
type Output = Vec4A;
#[inline]
fn mul(self, rhs: Vec4A) -> Vec4A {
self.mul_vec4a(rhs)
}
}

impl From<Mat4A> for Mat4 {
#[inline]
fn from(m: Mat4A) -> Self {
Expand All @@ -2291,6 +2319,14 @@ impl From<Mat4A> for Mat4 {
}
}
{% elif self_t == "Mat4A" %}
impl Mul<Vec4> for Mat4A {
type Output = Vec4;
#[inline]
fn mul(self, rhs: Vec4) -> Vec4 {
self.mul_vec4a(rhs.into()).into()
}
}

impl From<Mat4> for Mat4A {
#[inline]
fn from(m: Mat4) -> Self {
Expand Down
9 changes: 8 additions & 1 deletion src/f32/coresimd/mat2a.rs
@@ -1,6 +1,6 @@
// Generated from mat.rs.tera template. Edit the template, not the generated file.

use crate::{f32::math, swizzles::*, DMat2, Mat3, Mat3A, Vec2};
use crate::{f32::math, swizzles::*, DMat2, Mat2, Mat3, Mat3A, Vec2};
#[cfg(not(target_arch = "spirv"))]
use core::fmt;
use core::iter::{Product, Sum};
Expand Down Expand Up @@ -406,6 +406,13 @@ impl MulAssign<f32> for Mat2A {
}
}

impl From<Mat2> for Mat2A {
#[inline]
fn from(m: Mat2) -> Self {
Self::from_cols(m.x_axis, m.y_axis)
}
}

impl Sum<Self> for Mat2A {
fn sum<I>(iter: I) -> Self
where
Expand Down
8 changes: 8 additions & 0 deletions src/f32/coresimd/mat4a.rs
Expand Up @@ -1334,6 +1334,14 @@ impl MulAssign<f32> for Mat4A {
}
}

impl Mul<Vec4> for Mat4A {
type Output = Vec4;
#[inline]
fn mul(self, rhs: Vec4) -> Vec4 {
self.mul_vec4a(rhs.into()).into()
}
}

impl From<Mat4> for Mat4A {
#[inline]
fn from(m: Mat4) -> Self {
Expand Down
9 changes: 8 additions & 1 deletion src/f32/mat2.rs
@@ -1,6 +1,6 @@
// Generated from mat.rs.tera template. Edit the template, not the generated file.

use crate::{f32::math, swizzles::*, DMat2, Mat3, Mat3A, Vec2};
use crate::{f32::math, swizzles::*, DMat2, Mat2A, Mat3, Mat3A, Vec2};
#[cfg(not(target_arch = "spirv"))]
use core::fmt;
use core::iter::{Product, Sum};
Expand Down Expand Up @@ -396,6 +396,13 @@ impl MulAssign<f32> for Mat2 {
}
}

impl From<Mat2A> for Mat2 {
#[inline]
fn from(m: Mat2A) -> Self {
Self::from_cols(m.x_axis, m.y_axis)
}
}

impl Sum<Self> for Mat2 {
fn sum<I>(iter: I) -> Self
where
Expand Down
8 changes: 8 additions & 0 deletions src/f32/mat4.rs
Expand Up @@ -1240,6 +1240,14 @@ impl MulAssign<f32> for Mat4 {
}
}

impl Mul<Vec4A> for Mat4 {
type Output = Vec4A;
#[inline]
fn mul(self, rhs: Vec4A) -> Vec4A {
self.mul_vec4a(rhs)
}
}

impl From<Mat4A> for Mat4 {
#[inline]
fn from(m: Mat4A) -> Self {
Expand Down
9 changes: 8 additions & 1 deletion src/f32/scalar/mat2a.rs
@@ -1,6 +1,6 @@
// Generated from mat.rs.tera template. Edit the template, not the generated file.

use crate::{f32::math, swizzles::*, DMat2, Mat3, Mat3A, Vec2};
use crate::{f32::math, swizzles::*, DMat2, Mat2, Mat3, Mat3A, Vec2};
#[cfg(not(target_arch = "spirv"))]
use core::fmt;
use core::iter::{Product, Sum};
Expand Down Expand Up @@ -398,6 +398,13 @@ impl MulAssign<f32> for Mat2A {
}
}

impl From<Mat2> for Mat2A {
#[inline]
fn from(m: Mat2) -> Self {
Self::from_cols(m.x_axis, m.y_axis)
}
}

impl Sum<Self> for Mat2A {
fn sum<I>(iter: I) -> Self
where
Expand Down
8 changes: 8 additions & 0 deletions src/f32/scalar/mat4a.rs
Expand Up @@ -1241,6 +1241,14 @@ impl MulAssign<f32> for Mat4A {
}
}

impl Mul<Vec4> for Mat4A {
type Output = Vec4;
#[inline]
fn mul(self, rhs: Vec4) -> Vec4 {
self.mul_vec4a(rhs.into()).into()
}
}

impl From<Mat4> for Mat4A {
#[inline]
fn from(m: Mat4) -> Self {
Expand Down
9 changes: 8 additions & 1 deletion src/f32/sse2/mat2a.rs
@@ -1,6 +1,6 @@
// Generated from mat.rs.tera template. Edit the template, not the generated file.

use crate::{f32::math, swizzles::*, DMat2, Mat3, Mat3A, Vec2};
use crate::{f32::math, swizzles::*, DMat2, Mat2, Mat3, Mat3A, Vec2};
#[cfg(not(target_arch = "spirv"))]
use core::fmt;
use core::iter::{Product, Sum};
Expand Down Expand Up @@ -438,6 +438,13 @@ impl MulAssign<f32> for Mat2A {
}
}

impl From<Mat2> for Mat2A {
#[inline]
fn from(m: Mat2) -> Self {
Self::from_cols(m.x_axis, m.y_axis)
}
}

impl Sum<Self> for Mat2A {
fn sum<I>(iter: I) -> Self
where
Expand Down
8 changes: 8 additions & 0 deletions src/f32/sse2/mat4a.rs
Expand Up @@ -1343,6 +1343,14 @@ impl MulAssign<f32> for Mat4A {
}
}

impl Mul<Vec4> for Mat4A {
type Output = Vec4;
#[inline]
fn mul(self, rhs: Vec4) -> Vec4 {
self.mul_vec4a(rhs.into()).into()
}
}

impl From<Mat4> for Mat4A {
#[inline]
fn from(m: Mat4) -> Self {
Expand Down
9 changes: 8 additions & 1 deletion src/f32/wasm32/mat2a.rs
@@ -1,6 +1,6 @@
// Generated from mat.rs.tera template. Edit the template, not the generated file.

use crate::{f32::math, swizzles::*, DMat2, Mat3, Mat3A, Vec2};
use crate::{f32::math, swizzles::*, DMat2, Mat2, Mat3, Mat3A, Vec2};
#[cfg(not(target_arch = "spirv"))]
use core::fmt;
use core::iter::{Product, Sum};
Expand Down Expand Up @@ -412,6 +412,13 @@ impl MulAssign<f32> for Mat2A {
}
}

impl From<Mat2> for Mat2A {
#[inline]
fn from(m: Mat2) -> Self {
Self::from_cols(m.x_axis, m.y_axis)
}
}

impl Sum<Self> for Mat2A {
fn sum<I>(iter: I) -> Self
where
Expand Down
8 changes: 8 additions & 0 deletions src/f32/wasm32/mat4a.rs
Expand Up @@ -1334,6 +1334,14 @@ impl MulAssign<f32> for Mat4A {
}
}

impl Mul<Vec4> for Mat4A {
type Output = Vec4;
#[inline]
fn mul(self, rhs: Vec4) -> Vec4 {
self.mul_vec4a(rhs.into()).into()
}
}

impl From<Mat4> for Mat4A {
#[inline]
fn from(m: Mat4) -> Self {
Expand Down
9 changes: 9 additions & 0 deletions tests/mat2.rs
Expand Up @@ -281,6 +281,15 @@ mod mat2a {
assert_eq!(16, mem::align_of::<Mat2A>());
});

glam_test!(test_from_mat2, {
use glam::Mat2;
let m1 = Mat2::from_cols_array_2d(&MATRIX);
let m2: Mat2A = m1.into();
let m3: Mat2 = m2.into();
assert_eq!(Mat2A::from_cols_array_2d(&MATRIX), m2);
assert_eq!(Mat2::from_cols_array_2d(&MATRIX), m3);
});

glam_test!(test_from_mat3a, {
use glam::Mat3A;
let m3 = Mat3A::from_cols_array_2d(&[[1.0, 2.0, 3.0], [4.0, 5.0, 6.0], [7.0, 8.0, 9.0]]);
Expand Down
15 changes: 12 additions & 3 deletions tests/mat3.rs
Expand Up @@ -394,10 +394,10 @@ mod mat3 {
use glam::DMat3;
assert_eq!(
DMat3::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]),
Mat3::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]).as_dmat3()
Mat3::from_cols_array(&MATRIX1D).as_dmat3()
);
assert_eq!(
Mat3::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]),
Mat3::from_cols_array(&MATRIX1D),
DMat3::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]).as_mat3()
);
});
Expand All @@ -416,6 +416,15 @@ mod mat3a {
assert_eq!(mem::align_of::<Vec3A>(), mem::align_of::<Mat3A>());
});

glam_test!(test_from_mat3, {
use glam::Mat3;
let m1 = Mat3::from_cols_array_2d(&MATRIX);
let m2: Mat3A = m1.into();
let m3: Mat3 = m2.into();
assert_eq!(Mat3A::from_cols_array_2d(&MATRIX), m2);
assert_eq!(Mat3::from_cols_array_2d(&MATRIX), m3);
});

glam_test!(test_mul_vec3a, {
let mat_a = Mat3A::from_axis_angle(Vec3::Z, deg(90.0));
assert_approx_eq!(vec3a(-1.0, 0.0, 0.0), mat_a * Vec3A::Y);
Expand All @@ -426,7 +435,7 @@ mod mat3a {
use glam::DMat3;
assert_eq!(
DMat3::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]),
Mat3A::from_cols_array(&[1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0]).as_dmat3()
Mat3A::from_cols_array(&MATRIX1D).as_dmat3()
);
});

Expand Down

0 comments on commit 6dd8147

Please sign in to comment.