Skip to content

Commit

Permalink
Vector arithmetic ops implementations for references (#549)
Browse files Browse the repository at this point in the history
* Reference type ops impls added for AddAssign/SubAssign/MulAsign/DivAssign/RemAssign/Neg
  • Loading branch information
Aceeri authored Aug 16, 2024
1 parent 7cc4dce commit 913395d
Show file tree
Hide file tree
Showing 37 changed files with 15,126 additions and 0 deletions.
438 changes: 438 additions & 0 deletions codegen/templates/vec.rs.tera

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f32/coresimd/vec3a.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f32/coresimd/vec4.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f32/neon/vec3a.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f32/neon/vec4.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f32/scalar/vec3a.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f32/scalar/vec4.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f32/sse2/vec3a.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f32/sse2/vec4.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f32/vec2.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f32/vec3.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f32/wasm32/vec3a.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f32/wasm32/vec4.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f64/dvec2.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f64/dvec3.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/f64/dvec4.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/i16/i16vec2.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/i16/i16vec3.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/i16/i16vec4.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/i32/ivec2.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/i32/ivec3.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/i32/ivec4.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/i64/i64vec2.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/i64/i64vec3.rs

Large diffs are not rendered by default.

438 changes: 438 additions & 0 deletions src/i64/i64vec4.rs

Large diffs are not rendered by default.

430 changes: 430 additions & 0 deletions src/u16/u16vec2.rs

Large diffs are not rendered by default.

430 changes: 430 additions & 0 deletions src/u16/u16vec3.rs

Large diffs are not rendered by default.

430 changes: 430 additions & 0 deletions src/u16/u16vec4.rs

Large diffs are not rendered by default.

430 changes: 430 additions & 0 deletions src/u32/uvec2.rs

Large diffs are not rendered by default.

430 changes: 430 additions & 0 deletions src/u32/uvec3.rs

Large diffs are not rendered by default.

430 changes: 430 additions & 0 deletions src/u32/uvec4.rs

Large diffs are not rendered by default.

430 changes: 430 additions & 0 deletions src/u64/u64vec2.rs

Large diffs are not rendered by default.

430 changes: 430 additions & 0 deletions src/u64/u64vec3.rs

Large diffs are not rendered by default.

430 changes: 430 additions & 0 deletions src/u64/u64vec4.rs

Large diffs are not rendered by default.

102 changes: 102 additions & 0 deletions tests/vec2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,62 @@ macro_rules! impl_vec2_tests {
assert_eq!($new(2 as $t, 4 as $t), a % 8 as $t);
});

glam_test!(test_ops_propagated, {
let vec = $new(2 as $t, 4 as $t);
let scalar = 2 as $t;
let g_scalar = 16 as $t;

assert_eq!((vec + vec), (vec + &vec));
assert_eq!((vec + vec), (&vec + vec));
assert_eq!((vec + vec), (&vec + &vec));
assert_eq!((vec + scalar), (vec + &scalar));
assert_eq!((vec + scalar), (&vec + &scalar));
assert_eq!((vec + scalar), (&vec + scalar));
assert_eq!((scalar + vec), (&scalar + vec));
assert_eq!((scalar + vec), (&scalar + &vec));
assert_eq!((scalar + vec), (scalar + &vec));

assert_eq!((vec - vec), (vec - &vec));
assert_eq!((vec - vec), (&vec - vec));
assert_eq!((vec - vec), (&vec - &vec));
assert_eq!((vec - scalar), (vec - &scalar));
assert_eq!((vec - scalar), (&vec - &scalar));
assert_eq!((vec - scalar), (&vec - scalar));
assert_eq!((g_scalar - vec), (&g_scalar - vec));
assert_eq!((g_scalar - vec), (&g_scalar - &vec));
assert_eq!((g_scalar - vec), (g_scalar - &vec));

assert_eq!((vec * vec), (vec * &vec));
assert_eq!((vec * vec), (&vec * vec));
assert_eq!((vec * vec), (&vec * &vec));
assert_eq!((vec * scalar), (vec * &scalar));
assert_eq!((vec * scalar), (&vec * &scalar));
assert_eq!((vec * scalar), (&vec * scalar));
assert_eq!((scalar * vec), (&scalar * vec));
assert_eq!((scalar * vec), (&scalar * &vec));
assert_eq!((scalar * vec), (scalar * &vec));

assert_eq!((vec / vec), (vec / &vec));
assert_eq!((vec / vec), (&vec / vec));
assert_eq!((vec / vec), (&vec / &vec));
assert_eq!((vec / scalar), (vec / &scalar));
assert_eq!((vec / scalar), (&vec / &scalar));
assert_eq!((vec / scalar), (&vec / scalar));
assert_eq!((scalar / vec), (&scalar / vec));
assert_eq!((scalar / vec), (&scalar / &vec));
assert_eq!((scalar / vec), (scalar / &vec));

assert_eq!((vec % vec), (vec % &vec));
assert_eq!((vec % vec), (&vec % vec));
assert_eq!((vec % vec), (&vec % &vec));
assert_eq!((vec % scalar), (vec % &scalar));
assert_eq!((vec % scalar), (&vec % &scalar));
assert_eq!((vec % scalar), (&vec % scalar));
assert_eq!((scalar % vec), (&scalar % vec));
assert_eq!((scalar % vec), (&scalar % &vec));
assert_eq!((scalar % vec), (scalar % &vec));
});

glam_test!(test_assign_ops, {
let a = $new(1 as $t, 2 as $t);
let mut b = a;
Expand Down Expand Up @@ -186,6 +242,47 @@ macro_rules! impl_vec2_tests {
assert_eq!($new(0 as $t, 0 as $t), b);
});

glam_test!(test_assign_ops_propagation, {
let vec = $new(1 as $t, 2 as $t);
let mut a = vec;
let mut b = vec;
let scalar = 2 as $t;

a += &scalar;
b += scalar;
assert_eq!(b, a, "AddAssign<Scalar>");
a -= &scalar;
b -= scalar;
assert_eq!(b, a, "SubAssign<Scalar>");
a *= &scalar;
b *= scalar;
assert_eq!(b, a, "MulAssign<Scalar>");
a /= &scalar;
b /= scalar;
assert_eq!(b, a, "DivAssign<Scalar>");
a %= &scalar;
b %= scalar;
assert_eq!(b, a, "MulAssign<Scalar>");

a = vec;
b = vec;
a += &vec;
b += vec;
assert_eq!(b, a, "AddAssign<Vec>");
a -= &vec;
b -= vec;
assert_eq!(b, a, "SubAssign<Vec>");
a *= &vec;
b *= vec;
assert_eq!(b, a, "MulAssign<Vec>");
a /= &vec;
b /= vec;
assert_eq!(b, a, "DivAssign<Vec>");
a %= &vec;
b %= vec;
assert_eq!(b, a, "RemAssign<Vec>");
});

glam_test!(test_min_max, {
let a = $new(0 as $t, 2 as $t);
let b = $new(1 as $t, 1 as $t);
Expand Down Expand Up @@ -577,6 +674,11 @@ macro_rules! impl_vec2_signed_tests {
assert_eq!($new(0.0 as $t, -0.0 as $t), -$new(-0.0 as $t, 0.0 as $t));
});

glam_test!(test_neg_propagation, {
let a = $new(1 as $t, 2 as $t);
assert_eq!(-a, -(&a));
});

glam_test!(test_perp, {
let v1 = $vec2::new(1 as $t, 2 as $t);
let v2 = $vec2::new(1 as $t, 1 as $t);
Expand Down
102 changes: 102 additions & 0 deletions tests/vec3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,62 @@ macro_rules! impl_vec3_tests {
assert_eq!($new(2 as $t, 4 as $t, 0 as $t), a % 8 as $t);
});

glam_test!(test_ops_propagated, {
let vec = $new(2 as $t, 4 as $t, 8 as $t);
let scalar = 2 as $t;
let g_scalar = 16 as $t;

assert_eq!((vec + vec), (vec + &vec));
assert_eq!((vec + vec), (&vec + vec));
assert_eq!((vec + vec), (&vec + &vec));
assert_eq!((vec + scalar), (vec + &scalar));
assert_eq!((vec + scalar), (&vec + &scalar));
assert_eq!((vec + scalar), (&vec + scalar));
assert_eq!((scalar + vec), (&scalar + vec));
assert_eq!((scalar + vec), (&scalar + &vec));
assert_eq!((scalar + vec), (scalar + &vec));

assert_eq!((vec - vec), (vec - &vec));
assert_eq!((vec - vec), (&vec - vec));
assert_eq!((vec - vec), (&vec - &vec));
assert_eq!((vec - scalar), (vec - &scalar));
assert_eq!((vec - scalar), (&vec - &scalar));
assert_eq!((vec - scalar), (&vec - scalar));
assert_eq!((g_scalar - vec), (&g_scalar - vec));
assert_eq!((g_scalar - vec), (&g_scalar - &vec));
assert_eq!((g_scalar - vec), (g_scalar - &vec));

assert_eq!((vec * vec), (vec * &vec));
assert_eq!((vec * vec), (&vec * vec));
assert_eq!((vec * vec), (&vec * &vec));
assert_eq!((vec * scalar), (vec * &scalar));
assert_eq!((vec * scalar), (&vec * &scalar));
assert_eq!((vec * scalar), (&vec * scalar));
assert_eq!((scalar * vec), (&scalar * vec));
assert_eq!((scalar * vec), (&scalar * &vec));
assert_eq!((scalar * vec), (scalar * &vec));

assert_eq!((vec / vec), (vec / &vec));
assert_eq!((vec / vec), (&vec / vec));
assert_eq!((vec / vec), (&vec / &vec));
assert_eq!((vec / scalar), (vec / &scalar));
assert_eq!((vec / scalar), (&vec / &scalar));
assert_eq!((vec / scalar), (&vec / scalar));
assert_eq!((scalar / vec), (&scalar / vec));
assert_eq!((scalar / vec), (&scalar / &vec));
assert_eq!((scalar / vec), (scalar / &vec));

assert_eq!((vec % vec), (vec % &vec));
assert_eq!((vec % vec), (&vec % vec));
assert_eq!((vec % vec), (&vec % &vec));
assert_eq!((vec % scalar), (vec % &scalar));
assert_eq!((vec % scalar), (&vec % &scalar));
assert_eq!((vec % scalar), (&vec % scalar));
assert_eq!((scalar % vec), (&scalar % vec));
assert_eq!((scalar % vec), (&scalar % &vec));
assert_eq!((scalar % vec), (scalar % &vec));
});

glam_test!(test_assign_ops, {
let a = $new(1 as $t, 2 as $t, 3 as $t);
let mut b = a;
Expand Down Expand Up @@ -223,6 +279,47 @@ macro_rules! impl_vec3_tests {
assert_eq!($new(0 as $t, 0 as $t, 0 as $t), b);
});

glam_test!(test_assign_ops_propagation, {
let vec = $new(1 as $t, 2 as $t, 3 as $t);
let mut a = vec;
let mut b = vec;
let scalar = 2 as $t;

a += &scalar;
b += scalar;
assert_eq!(b, a, "AddAssign<Scalar>");
a -= &scalar;
b -= scalar;
assert_eq!(b, a, "SubAssign<Scalar>");
a *= &scalar;
b *= scalar;
assert_eq!(b, a, "MulAssign<Scalar>");
a /= &scalar;
b /= scalar;
assert_eq!(b, a, "DivAssign<Scalar>");
a %= &scalar;
b %= scalar;
assert_eq!(b, a, "MulAssign<Scalar>");

a = vec;
b = vec;
a += &vec;
b += vec;
assert_eq!(b, a, "AddAssign<Vec>");
a -= &vec;
b -= vec;
assert_eq!(b, a, "SubAssign<Vec>");
a *= &vec;
b *= vec;
assert_eq!(b, a, "MulAssign<Vec>");
a /= &vec;
b /= vec;
assert_eq!(b, a, "DivAssign<Vec>");
a %= &vec;
b %= vec;
assert_eq!(b, a, "RemAssign<Vec>");
});

glam_test!(test_min_max, {
let a = $new(3 as $t, 5 as $t, 1 as $t);
let b = $new(4 as $t, 2 as $t, 6 as $t);
Expand Down Expand Up @@ -656,6 +753,11 @@ macro_rules! impl_vec3_signed_tests {
);
});

glam_test!(test_neg_propagation, {
let a = $new(1 as $t, 2 as $t, 3 as $t);
assert_eq!(-a, -(&a));
});

glam_test!(test_is_negative_bitmask, {
assert_eq!($vec3::ZERO.is_negative_bitmask(), 0b000);
assert_eq!($vec3::ONE.is_negative_bitmask(), 0b000);
Expand Down
102 changes: 102 additions & 0 deletions tests/vec4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,62 @@ macro_rules! impl_vec4_tests {
assert_eq!($new(2 as $t, 4 as $t, 0 as $t, 0 as $t), a % 8 as $t);
});

glam_test!(test_ops_propagated, {
let vec = $new(2 as $t, 4 as $t, 8 as $t, 16 as $t);
let scalar = 2 as $t;
let g_scalar = 16 as $t;

assert_eq!((vec + vec), (vec + &vec));
assert_eq!((vec + vec), (&vec + vec));
assert_eq!((vec + vec), (&vec + &vec));
assert_eq!((vec + scalar), (vec + &scalar));
assert_eq!((vec + scalar), (&vec + &scalar));
assert_eq!((vec + scalar), (&vec + scalar));
assert_eq!((scalar + vec), (&scalar + vec));
assert_eq!((scalar + vec), (&scalar + &vec));
assert_eq!((scalar + vec), (scalar + &vec));

assert_eq!((vec - vec), (vec - &vec));
assert_eq!((vec - vec), (&vec - vec));
assert_eq!((vec - vec), (&vec - &vec));
assert_eq!((vec - scalar), (vec - &scalar));
assert_eq!((vec - scalar), (&vec - &scalar));
assert_eq!((vec - scalar), (&vec - scalar));
assert_eq!((g_scalar - vec), (&g_scalar - vec));
assert_eq!((g_scalar - vec), (&g_scalar - &vec));
assert_eq!((g_scalar - vec), (g_scalar - &vec));

assert_eq!((vec * vec), (vec * &vec));
assert_eq!((vec * vec), (&vec * vec));
assert_eq!((vec * vec), (&vec * &vec));
assert_eq!((vec * scalar), (vec * &scalar));
assert_eq!((vec * scalar), (&vec * &scalar));
assert_eq!((vec * scalar), (&vec * scalar));
assert_eq!((scalar * vec), (&scalar * vec));
assert_eq!((scalar * vec), (&scalar * &vec));
assert_eq!((scalar * vec), (scalar * &vec));

assert_eq!((vec / vec), (vec / &vec));
assert_eq!((vec / vec), (&vec / vec));
assert_eq!((vec / vec), (&vec / &vec));
assert_eq!((vec / scalar), (vec / &scalar));
assert_eq!((vec / scalar), (&vec / &scalar));
assert_eq!((vec / scalar), (&vec / scalar));
assert_eq!((scalar / vec), (&scalar / vec));
assert_eq!((scalar / vec), (&scalar / &vec));
assert_eq!((scalar / vec), (scalar / &vec));

assert_eq!((vec % vec), (vec % &vec));
assert_eq!((vec % vec), (&vec % vec));
assert_eq!((vec % vec), (&vec % &vec));
assert_eq!((vec % scalar), (vec % &scalar));
assert_eq!((vec % scalar), (&vec % &scalar));
assert_eq!((vec % scalar), (&vec % scalar));
assert_eq!((scalar % vec), (&scalar % vec));
assert_eq!((scalar % vec), (&scalar % &vec));
assert_eq!((scalar % vec), (scalar % &vec));
});

glam_test!(test_assign_ops, {
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
let mut b = a;
Expand Down Expand Up @@ -273,6 +329,47 @@ macro_rules! impl_vec4_tests {
assert_eq!($new(0 as $t, 0 as $t, 0 as $t, 0 as $t), b);
});

glam_test!(test_assign_ops_propagation, {
let vec = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
let mut a = vec;
let mut b = vec;
let scalar = 2 as $t;

a += &scalar;
b += scalar;
assert_eq!(b, a, "AddAssign<Scalar>");
a -= &scalar;
b -= scalar;
assert_eq!(b, a, "SubAssign<Scalar>");
a *= &scalar;
b *= scalar;
assert_eq!(b, a, "MulAssign<Scalar>");
a /= &scalar;
b /= scalar;
assert_eq!(b, a, "DivAssign<Scalar>");
a %= &scalar;
b %= scalar;
assert_eq!(b, a, "MulAssign<Scalar>");

a = vec;
b = vec;
a += &vec;
b += vec;
assert_eq!(b, a, "AddAssign<Vec>");
a -= &vec;
b -= vec;
assert_eq!(b, a, "SubAssign<Vec>");
a *= &vec;
b *= vec;
assert_eq!(b, a, "MulAssign<Vec>");
a /= &vec;
b /= vec;
assert_eq!(b, a, "DivAssign<Vec>");
a %= &vec;
b %= vec;
assert_eq!(b, a, "RemAssign<Vec>");
});

glam_test!(test_min_max, {
let a = $new(4 as $t, 6 as $t, 2 as $t, 8 as $t);
let b = $new(5 as $t, 3 as $t, 7 as $t, 1 as $t);
Expand Down Expand Up @@ -772,6 +869,11 @@ macro_rules! impl_vec4_signed_tests {
);
});

glam_test!(test_neg_propagation, {
let a = $new(1 as $t, 2 as $t, 3 as $t, 4 as $t);
assert_eq!(-a, -(&a));
});

glam_test!(test_is_negative_bitmask, {
assert_eq!($vec4::ZERO.is_negative_bitmask(), 0b0000);
assert_eq!($vec4::ONE.is_negative_bitmask(), 0b0000);
Expand Down

0 comments on commit 913395d

Please sign in to comment.