nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: bitshifter/glam-rs
Pull request #20 (2019-09-17 13:44:35)

Fix Mat4::look_at_lh/rh
The `Mat4::look_at_lh` implementation was a broken with lacking normalization, doing the cross products in the wrong order and some flips. 

I'm not 100% sure if this is correct but with these fixes it matches the behavior of `glm::look_at_rh` and also the implementation in DirectXMath `XMMatrixLookToLH`, though I've only in practice tested the right-handed version as that is what we use.


Patch:
diff --git a/src/f32/mat4.rs b/src/f32/mat4.rs
index 00c7ef1..8b54b17 100644
--- a/src/f32/mat4.rs
+++ b/src/f32/mat4.rs
@@ -389,17 +389,17 @@ impl Mat4 {
     // TODO: make public at some point
     fn look_to_lh(eye: Vec3, dir: Vec3, up: Vec3) -> Self {
         let f = dir.normalize();
+        let s = up.cross(f).normalize();
+        let u = f.cross(s);
         let (fx, fy, fz) = f.into();
-        let s = f.cross(up);
         let (sx, sy, sz) = s.into();
-        let u = s.cross(f);
         let (ux, uy, uz) = u.into();
-        Self {
-            x_axis: Vec4::new(sx, ux, -fx, 0.0),
-            y_axis: Vec4::new(sy, uy, -fy, 0.0),
-            z_axis: Vec4::new(sz, uz, -fz, 0.0),
-            w_axis: Vec4::new(-s.dot(eye), -u.dot(eye), f.dot(eye), 1.0),
-        }
+        Mat4::new(
+            Vec4::new(sx, ux, fx, 0.0),
+            Vec4::new(sy, uy, fy, 0.0),
+            Vec4::new(sz, uz, fz, 0.0),
+            Vec4::new(-s.dot(eye), -u.dot(eye), -f.dot(eye), 1.0),
+        )
     }
 
     #[inline]


Test patch:
diff --git a/tests/mat4.rs b/tests/mat4.rs
index 3c8e6a4..8ad3ad7 100644
--- a/tests/mat4.rs
+++ b/tests/mat4.rs
@@ -249,8 +249,8 @@ fn test_mat4_look_at() {
     let lh = Mat4::look_at_lh(eye, center, up);
     let rh = Mat4::look_at_rh(eye, center, up);
     let point = Vec3::new(1.0, 0.0, 0.0);
-    assert_ulps_eq!(lh.transform_point3(point), Vec3::new(0.0, 1.0, -5.0));
-    assert_ulps_eq!(rh.transform_point3(point), Vec3::new(0.0, 1.0, 5.0));
+    assert_ulps_eq!(lh.transform_point3(point), Vec3::new(0.0, 1.0, 5.0));
+    assert_ulps_eq!(rh.transform_point3(point), Vec3::new(0.0, 1.0, -5.0));
 }
 
 #[test]
Repository: bitshifter/glam-rs
Pull request #39 (2019-12-21 09:32:02)

Changed name from Mat4::perspective_lh_dx to Mat4::perspective_lh.


Patch:
diff --git a/src/f32/mat4.rs b/src/f32/mat4.rs
index 1f8f1fa..fef92ea 100644
--- a/src/f32/mat4.rs
+++ b/src/f32/mat4.rs
@@ -577,7 +577,7 @@ impl Mat4 {
     }
 
     /// Creates a left-handed perspective projection matrix with [0,1] depth range.
-    pub fn perspective_lh_dx(
+    pub fn perspective_lh(
         fov_y_radians: f32,
         aspect_ratio: f32,
         z_near: f32,


Test patch:
diff --git a/tests/mat4.rs b/tests/mat4.rs
index 33f7b30..492d22d 100644
--- a/tests/mat4.rs
+++ b/tests/mat4.rs
@@ -340,8 +340,8 @@ fn test_mat4_perspective_gl_rh() {
 }
 
 #[test]
-fn test_mat4_perspective_dx_lh() {
-    let projection = Mat4::perspective_lh_dx(f32::to_radians(90.0), 2.0, 5.0, 15.0);
+fn test_mat4_perspective_lh() {
+    let projection = Mat4::perspective_lh(f32::to_radians(90.0), 2.0, 5.0, 15.0);
 
     let original = Vec3::new(5.0, 5.0, 15.0);
     let projected = projection * original.extend(1.0);
Repository: bitshifter/glam-rs
Pull request #40 (2019-12-21 11:22:21)

Added Mat4::perspective_infinite_lh and Mat4::perspective_infinite_re…
…verse_lh.

bitshifter: Thanks! Will merge it when I'm next at my PC.

Patch:
diff --git a/src/f32/mat4.rs b/src/f32/mat4.rs
index 8ec9fac..ef74576 100644
--- a/src/f32/mat4.rs
+++ b/src/f32/mat4.rs
@@ -591,6 +591,38 @@ impl Mat4 {
         )
     }
 
+    /// Creates an infinite left-handed perspective projection matrix with [0,1] depth range.
+    pub fn perspective_infinite_lh(fov_y_radians: f32, aspect_ratio: f32, z_near: f32) -> Self {
+        glam_assert!(z_near > 0.0);
+        let (sin_fov, cos_fov) = scalar_sin_cos(0.5 * fov_y_radians);
+        let h = cos_fov / sin_fov;
+        let w = h / aspect_ratio;
+        Mat4::from_cols(
+            Vec4::new(w, 0.0, 0.0, 0.0),
+            Vec4::new(0.0, h, 0.0, 0.0),
+            Vec4::new(0.0, 0.0, 1.0, 1.0),
+            Vec4::new(0.0, 0.0, -z_near, 0.0),
+        )
+    }
+
+    /// Creates an infinite left-handed perspective projection matrix with [0,1] depth range.
+    pub fn perspective_infinite_reverse_lh(
+        fov_y_radians: f32,
+        aspect_ratio: f32,
+        z_near: f32,
+    ) -> Self {
+        glam_assert!(z_near > 0.0);
+        let (sin_fov, cos_fov) = scalar_sin_cos(0.5 * fov_y_radians);
+        let h = cos_fov / sin_fov;
+        let w = h / aspect_ratio;
+        Mat4::from_cols(
+            Vec4::new(w, 0.0, 0.0, 0.0),
+            Vec4::new(0.0, h, 0.0, 0.0),
+            Vec4::new(0.0, 0.0, 0.0, 1.0),
+            Vec4::new(0.0, 0.0, z_near, 0.0),
+        )
+    }
+
     #[inline]
     #[deprecated(since = "0.8.2", note = "please use `Mat4::perspective_rh_gl` instead")]
     pub fn perspective_glu_rh(


Test patch:
diff --git a/tests/mat4.rs b/tests/mat4.rs
index 492d22d..7cdcd46 100644
--- a/tests/mat4.rs
+++ b/tests/mat4.rs
@@ -352,6 +352,32 @@ fn test_mat4_perspective_lh() {
     assert_approx_eq!(Vec4::new(2.5, 5.0, 0.0, 5.0), projected);
 }
 
+#[test]
+fn test_mat4_perspective_infinite_lh() {
+    let projection = Mat4::perspective_infinite_lh(f32::to_radians(90.0), 2.0, 5.0);
+
+    let original = Vec3::new(5.0, 5.0, 15.0);
+    let projected = projection * original.extend(1.0);
+    assert_approx_eq!(Vec4::new(2.5, 5.0, 10.0, 15.0), projected);
+
+    let original = Vec3::new(5.0, 5.0, 5.0);
+    let projected = projection * original.extend(1.0);
+    assert_approx_eq!(Vec4::new(2.5, 5.0, 0.0, 5.0), projected);
+}
+
+#[test]
+fn test_mat4_perspective_infinite_reverse_lh() {
+    let projection = Mat4::perspective_infinite_reverse_lh(f32::to_radians(90.0), 2.0, 5.0);
+
+    let original = Vec3::new(5.0, 5.0, 15.0);
+    let projected = projection * original.extend(1.0);
+    assert_approx_eq!(Vec4::new(2.5, 5.0, 5.0, 15.0), projected);
+
+    let original = Vec3::new(5.0, 5.0, 5.0);
+    let projected = projection * original.extend(1.0);
+    assert_approx_eq!(Vec4::new(2.5, 5.0, 5.0, 5.0), projected);
+}
+
 #[test]
 fn test_mat4_orthographic_gl_rh() {
     let projection = Mat4::orthographic_rh_gl(-10.0, 10.0, -5.0, 5.0, 0.0, -10.0);
Repository: bitshifter/glam-rs
Pull request #96 (2020-11-15 23:09:38)

Add perp() method to Vec2
A perp() method for Vec2 that returns (-y, x) is pretty useful.
Given that there's already a perp_dot I think it makes sense to have this too.



Patch:
diff --git a/src/f32/vec2.rs b/src/f32/vec2.rs
index 8b4131c..fee71c6 100644
--- a/src/f32/vec2.rs
+++ b/src/f32/vec2.rs
@@ -375,6 +375,14 @@ impl Vec2 {
         }
     }
 
+    /// Returns a `Vec2` that is equal to `self` rotated by 90 degrees.
+    pub fn perp(self) -> Self {
+        return Self {
+            x: -self.y,
+            y: self.x
+        }
+    }
+
     /// The perpendicular dot product of the vector and `other`.
     #[inline]
     pub fn perp_dot(self, other: Vec2) -> f32 {


Test patch:
diff --git a/tests/vec2.rs b/tests/vec2.rs
index 271f676..40fbe09 100644
--- a/tests/vec2.rs
+++ b/tests/vec2.rs
@@ -1,6 +1,6 @@
 mod support;
 
-use glam::{vec2, vec3, Vec2, Vec2Mask, Vec3};
+use glam::{vec2, vec3, Vec2, Vec2Mask, Vec3, Mat2};
 use std::f32;
 
 #[test]
@@ -479,6 +479,21 @@ fn test_vec2_angle_between() {
     assert_approx_eq!(-f32::consts::FRAC_PI_2, angle, 1e-6);
 }
 
+#[test]
+fn test_vec2_perp() {
+    let v1 = Vec2::new(1.0, 2.0);
+    let v2 = Vec2::new(1.0, 1.0);
+    let v1_perp = Vec2::new(-2.0, 1.0);
+    let rot90 = Mat2::from_angle(90.0_f32.to_radians());
+    
+    assert_eq!(v1_perp, v1.perp());
+    assert_eq!(v1.perp().dot(v1), 0.0);
+    assert_eq!(v2.perp().dot(v2), 0.0);
+    assert_eq!(v1.perp().dot(v2), v1.perp_dot(v2));
+
+    assert_approx_eq!(v1.perp(), rot90 * v1);
+}
+
 #[cfg(feature = "serde")]
 #[test]
 fn test_vec2_serde() {
Repository: bitshifter/glam-rs
Pull request #153 (2021-03-30 08:58:48)

Add `Quat::from_scaled_axis` and `to_scaled_axis`
The first derivative of a quaternion is the angular velocity, expressed as a scaled axis.

So in physics code you will often want to do something like:

`let delta_rot = Quat::from_scaled_axis(dt * angular_velocity);`


Patch:
diff --git a/src/quat.rs b/src/quat.rs
index bcce2be..e9087be 100644
--- a/src/quat.rs
+++ b/src/quat.rs
@@ -87,6 +87,20 @@ macro_rules! impl_quat_methods {
             Self($inner::from_axis_angle(axis.0, angle))
         }
 
+        /// Create a quaternion that rotates `v.length()` radians around `v.normalize()`.
+        ///
+        /// `from_scaled_axis(Vec3::ZERO)` results in the identity quaternion.
+        #[inline(always)]
+        pub fn from_scaled_axis(v: $vec3) -> Self {
+            // Self($inner::from_scaled_axis(v.0))
+            let length = v.length();
+            if length == 0.0 {
+                Self::IDENTITY
+            } else {
+                Self::from_axis_angle(v / length, length)
+            }
+        }
+
         /// Creates a quaternion from the `angle` (in radians) around the x axis.
         #[inline(always)]
         pub fn from_rotation_x(angle: $t) -> Self {
@@ -187,6 +201,13 @@ macro_rules! impl_quat_methods {
             ($vec3(axis), angle)
         }
 
+        /// Returns the rotation axis scaled by the rotation in radians.
+        #[inline(always)]
+        pub fn to_scaled_axis(self) -> $vec3 {
+            let (axis, angle) = self.0.to_axis_angle();
+            $vec3(axis) * angle
+        }
+
         /// Returns the quaternion conjugate of `self`. For a unit quaternion the
         /// conjugate is also the inverse.
         #[inline(always)]


Test patch:
diff --git a/tests/quat.rs b/tests/quat.rs
index f04e5d9..0fbf492 100644
--- a/tests/quat.rs
+++ b/tests/quat.rs
@@ -127,6 +127,33 @@ macro_rules! impl_quat_tests {
             assert_eq!(angle, rad(0.0));
         }
 
+        #[test]
+        fn test_from_scaled_axis() {
+            assert_eq!($quat::from_scaled_axis($vec3::ZERO), $quat::IDENTITY);
+            assert_eq!(
+                $quat::from_scaled_axis($vec3::Y * 1e-10),
+                $quat::from_axis_angle($vec3::Y, 1e-10)
+            );
+            assert_eq!(
+                $quat::from_scaled_axis($vec3::X * 1.0),
+                $quat::from_axis_angle($vec3::X, 1.0)
+            );
+            assert_eq!(
+                $quat::from_scaled_axis($vec3::Z * 2.0),
+                $quat::from_axis_angle($vec3::Z, 2.0)
+            );
+
+            assert_eq!(
+                $quat::from_scaled_axis($vec3::ZERO).to_scaled_axis(),
+                $vec3::ZERO
+            );
+            for &v in &vec3_float_test_vectors!($vec3) {
+                if v.length() < core::$t::consts::PI {
+                    assert!(($quat::from_scaled_axis(v).to_scaled_axis() - v).length() < 1e-6,);
+                }
+            }
+        }
+
         #[test]
         fn test_mul_vec3() {
             let qrz = $quat::from_rotation_z(deg(90.0));
Repository: bitshifter/glam-rs
Pull request #267 (2021-12-27 18:14:12)

Add `Quat::to_array` function
Add `Quat::to_array` function to simplify conversion from `Quat` type to plain array.
`Quat` already has `from_array` function and vector types have `from_array` function so as a user of this library I would expect to have such function implemented for `Quat` struct as well.


Patch:
diff --git a/src/quat.rs b/src/quat.rs
index 0fb4abe..135c942 100644
--- a/src/quat.rs
+++ b/src/quat.rs
@@ -282,6 +282,12 @@ macro_rules! impl_quat_methods {
             euler.convert_quat(self)
         }
 
+        /// `[x, y, z, w]`
+        #[inline(always)]
+        pub fn to_array(&self) -> [$t; 4] {
+            [self.x, self.y, self.z, self.w]
+        }
+
         /// Returns the vector part of the quaternion.
         #[inline(always)]
         pub fn xyz(self) -> $vec3 {


Test patch:
diff --git a/tests/quat.rs b/tests/quat.rs
index 7ec942c..831bf0f 100644
--- a/tests/quat.rs
+++ b/tests/quat.rs
@@ -461,6 +461,10 @@ macro_rules! impl_quat_tests {
             should_glam_assert!({ $quat::from_rotation_arc_2d($vec2::ZERO, $vec2::X) });
             should_glam_assert!({ $quat::from_rotation_arc_2d($vec2::X, $vec2::ZERO) });
         });
+
+        glam_test!(test_to_array, {
+            assert!($new(1.0, 2.0, 3.0, 4.0).to_array() == [1.0, 2.0, 3.0, 4.0]);
+        });
     };
 }
Repository: bitshifter/glam-rs
Pull request #299 (2022-06-22 11:03:52)

codegen: Allow running from anywhere (e.g. workspace root)
Depends on #298

When running `cargo r -p codegen` straight from the root, `GLAM_ROOT = ".."` ends up outside the current directory, forcing the user to `cd` into `codegen/` first.  While `GLAM_ROOT` could have been updated with some smart detection `tera` templates rely on the PWD (or should alternatively receive more elaborate paths).  Change into the `codegen/` directory for the user so that they don't have to do this themselves, making the workflow ever so slightly more convenient.



Patch:
diff --git a/codegen/Cargo.toml b/codegen/Cargo.toml
index 08fa86a..51df774 100644
--- a/codegen/Cargo.toml
+++ b/codegen/Cargo.toml
@@ -6,7 +6,7 @@ edition = "2021"
 # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
 
 [dependencies]
-anyhow = { version = "1", default-features = false }
+anyhow = { version = "1" }
 clap = { version = "3", default-features = false, features = ["cargo", "std"] }
 git2 = { version = "0.14", default-features = false }
 globset = { version = "0.4", default-features = false }
diff --git a/codegen/src/main.rs b/codegen/src/main.rs
index 1cde7e7..bc88942 100644
--- a/codegen/src/main.rs
+++ b/codegen/src/main.rs
@@ -517,6 +517,9 @@ fn build_output_pairs() -> HashMap<&'static str, tera::Context> {
 }
 
 fn main() -> anyhow::Result<()> {
+    // Change into `./codegen` dir for convenience to the user
+    std::env::set_current_dir(env!("CARGO_MANIFEST_DIR"))?;
+
     let matches = command!()
         .arg(arg!([GLOB]))
         .arg(arg!(-f - -force))


Test patch:
diff --git a/build_and_test_features.sh b/build_and_test_features.sh
index 8270574..47d82a5 100755
--- a/build_and_test_features.sh
+++ b/build_and_test_features.sh
@@ -26,4 +26,4 @@ done
 
 RUSTFLAGS='-C target-feature=+fma' cargo check
 
-cargo check -p glam-no_std
+cargo check -p glam-no_std
\ No newline at end of file
Repository: bitshifter/glam-rs
Pull request #455 (2023-12-26 13:07:20)

In some build configs, BVec4 was an unused import.
The uses of this were protected by only `scalar_math` so only protect the import by the same.


Patch:
diff --git a/.github/workflows/cargo-deny.yml b/.github/workflows/cargo-deny.yml
index f5452f7..9c2e622 100644
--- a/.github/workflows/cargo-deny.yml
+++ b/.github/workflows/cargo-deny.yml
@@ -4,5 +4,5 @@ jobs:
   cargo-deny:
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v1
+      - uses: actions/checkout@v4
       - uses: EmbarkStudios/cargo-deny-action@v1
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 1991595..bde8e32 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -6,7 +6,7 @@ jobs:
     name: Lint
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
 
       - uses: actions-rs/toolchain@v1
         with:
@@ -40,7 +40,7 @@ jobs:
         toolchain: [stable, beta, nightly]
     runs-on: ${{ matrix.os }}
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - run: rustup update --no-self-update ${{ matrix.toolchain }}
       - run: rustup default ${{ matrix.toolchain }}
       - run: ./build_and_test_features.sh
@@ -54,7 +54,7 @@ jobs:
         toolchain: [nightly]
     runs-on: ${{ matrix.os }}
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
       - run: rustup update --no-self-update ${{ matrix.toolchain }}
       - run: rustup default ${{ matrix.toolchain }}
       - run: cargo test --features core-simd
@@ -68,7 +68,7 @@ jobs:
         os: [ubuntu-latest]
     runs-on: ${{ matrix.os }}
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
 
       - name: Install
         run: curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh
diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml
index e93e9c4..e88f4a1 100644
--- a/.github/workflows/coverage.yml
+++ b/.github/workflows/coverage.yml
@@ -7,7 +7,7 @@ jobs:
       options: --security-opt seccomp=unconfined
     runs-on: ubuntu-latest
     steps:
-      - uses: actions/checkout@v2
+      - uses: actions/checkout@v4
 
       - name: Update nightly
         run: rustup update nightly


Test patch:
diff --git a/tests/vec4.rs b/tests/vec4.rs
index 2560d2d..22ce97f 100644
--- a/tests/vec4.rs
+++ b/tests/vec4.rs
@@ -1280,10 +1280,7 @@ macro_rules! impl_vec4_bit_op_tests {
 }
 
 mod vec4 {
-    #[cfg(any(
-        not(any(target_feature = "sse2", target_feature = "simd128")),
-        feature = "scalar-math"
-    ))]
+    #[cfg(feature = "scalar-math")]
     use glam::BVec4;
     #[cfg(not(feature = "scalar-math"))]
     use glam::BVec4A;