From 1314eb29763be6f2592aba7db66538d25680ae56 Mon Sep 17 00:00:00 2001 From: atlas Date: Sat, 19 Jul 2025 01:03:51 -0400 Subject: [PATCH 1/4] Split any_orthonormal_pair into _rh and _lh variants --- src/f32/coresimd/vec3a.rs | 17 +++++++++++++++-- src/f32/neon/vec3a.rs | 17 +++++++++++++++-- src/f32/scalar/vec3a.rs | 17 +++++++++++++++-- src/f32/sse2/vec3a.rs | 17 +++++++++++++++-- src/f32/vec3.rs | 17 +++++++++++++++-- src/f32/wasm32/vec3a.rs | 17 +++++++++++++++-- src/f64/dvec3.rs | 17 +++++++++++++++-- templates/vec.rs.tera | 17 +++++++++++++++-- 8 files changed, 120 insertions(+), 16 deletions(-) diff --git a/src/f32/coresimd/vec3a.rs b/src/f32/coresimd/vec3a.rs index f9c72d8d..7f241efb 100644 --- a/src/f32/coresimd/vec3a.rs +++ b/src/f32/coresimd/vec3a.rs @@ -1020,7 +1020,7 @@ impl Vec3A { Self::new(b, sign + self.y * self.y * a, -self.y) } - /// Given a unit vector return two other vectors that together form an orthonormal + /// Given a unit vector return two other vectors that together form a left-handed orthonormal /// basis. That is, all three vectors are orthogonal to each other and are normalized. /// /// # Panics @@ -1028,7 +1028,20 @@ impl Vec3A { /// Will panic if `self` is not normalized when `glam_assert` is enabled. #[inline] #[must_use] - pub fn any_orthonormal_pair(&self) -> (Self, Self) { + pub fn any_orthonormal_pair_lh(&self) -> (Self, Self) { + let (a, b) = self.any_orthonormal_pair_rh(); + (-a, b) + } + + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + pub fn any_orthonormal_pair_rh(&self) -> (Self, Self) { glam_assert!(self.is_normalized()); // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf let sign = math::signum(self.z); diff --git a/src/f32/neon/vec3a.rs b/src/f32/neon/vec3a.rs index 5f0f18ca..ae7865ec 100644 --- a/src/f32/neon/vec3a.rs +++ b/src/f32/neon/vec3a.rs @@ -1062,7 +1062,7 @@ impl Vec3A { Self::new(b, sign + self.y * self.y * a, -self.y) } - /// Given a unit vector return two other vectors that together form an orthonormal + /// Given a unit vector return two other vectors that together form a left-handed orthonormal /// basis. That is, all three vectors are orthogonal to each other and are normalized. /// /// # Panics @@ -1070,7 +1070,20 @@ impl Vec3A { /// Will panic if `self` is not normalized when `glam_assert` is enabled. #[inline] #[must_use] - pub fn any_orthonormal_pair(&self) -> (Self, Self) { + pub fn any_orthonormal_pair_lh(&self) -> (Self, Self) { + let (a, b) = self.any_orthonormal_pair_rh(); + (-a, b) + } + + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + pub fn any_orthonormal_pair_rh(&self) -> (Self, Self) { glam_assert!(self.is_normalized()); // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf let sign = math::signum(self.z); diff --git a/src/f32/scalar/vec3a.rs b/src/f32/scalar/vec3a.rs index 980fdeb0..e49e80d0 100644 --- a/src/f32/scalar/vec3a.rs +++ b/src/f32/scalar/vec3a.rs @@ -1067,7 +1067,7 @@ impl Vec3A { Self::new(b, sign + self.y * self.y * a, -self.y) } - /// Given a unit vector return two other vectors that together form an orthonormal + /// Given a unit vector return two other vectors that together form a left-handed orthonormal /// basis. That is, all three vectors are orthogonal to each other and are normalized. /// /// # Panics @@ -1075,7 +1075,20 @@ impl Vec3A { /// Will panic if `self` is not normalized when `glam_assert` is enabled. #[inline] #[must_use] - pub fn any_orthonormal_pair(&self) -> (Self, Self) { + pub fn any_orthonormal_pair_lh(&self) -> (Self, Self) { + let (a, b) = self.any_orthonormal_pair_rh(); + (-a, b) + } + + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + pub fn any_orthonormal_pair_rh(&self) -> (Self, Self) { glam_assert!(self.is_normalized()); // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf let sign = math::signum(self.z); diff --git a/src/f32/sse2/vec3a.rs b/src/f32/sse2/vec3a.rs index aba67170..d0789de7 100644 --- a/src/f32/sse2/vec3a.rs +++ b/src/f32/sse2/vec3a.rs @@ -1070,7 +1070,7 @@ impl Vec3A { Self::new(b, sign + self.y * self.y * a, -self.y) } - /// Given a unit vector return two other vectors that together form an orthonormal + /// Given a unit vector return two other vectors that together form a left-handed orthonormal /// basis. That is, all three vectors are orthogonal to each other and are normalized. /// /// # Panics @@ -1078,7 +1078,20 @@ impl Vec3A { /// Will panic if `self` is not normalized when `glam_assert` is enabled. #[inline] #[must_use] - pub fn any_orthonormal_pair(&self) -> (Self, Self) { + pub fn any_orthonormal_pair_lh(&self) -> (Self, Self) { + let (a, b) = self.any_orthonormal_pair_rh(); + (-a, b) + } + + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + pub fn any_orthonormal_pair_rh(&self) -> (Self, Self) { glam_assert!(self.is_normalized()); // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf let sign = math::signum(self.z); diff --git a/src/f32/vec3.rs b/src/f32/vec3.rs index f71279ad..7bcc6f02 100644 --- a/src/f32/vec3.rs +++ b/src/f32/vec3.rs @@ -1057,7 +1057,7 @@ impl Vec3 { Self::new(b, sign + self.y * self.y * a, -self.y) } - /// Given a unit vector return two other vectors that together form an orthonormal + /// Given a unit vector return two other vectors that together form a left-handed orthonormal /// basis. That is, all three vectors are orthogonal to each other and are normalized. /// /// # Panics @@ -1065,7 +1065,20 @@ impl Vec3 { /// Will panic if `self` is not normalized when `glam_assert` is enabled. #[inline] #[must_use] - pub fn any_orthonormal_pair(&self) -> (Self, Self) { + pub fn any_orthonormal_pair_lh(&self) -> (Self, Self) { + let (a, b) = self.any_orthonormal_pair_rh(); + (-a, b) + } + + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + pub fn any_orthonormal_pair_rh(&self) -> (Self, Self) { glam_assert!(self.is_normalized()); // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf let sign = math::signum(self.z); diff --git a/src/f32/wasm32/vec3a.rs b/src/f32/wasm32/vec3a.rs index d05a48c4..cabb8494 100644 --- a/src/f32/wasm32/vec3a.rs +++ b/src/f32/wasm32/vec3a.rs @@ -1033,7 +1033,7 @@ impl Vec3A { Self::new(b, sign + self.y * self.y * a, -self.y) } - /// Given a unit vector return two other vectors that together form an orthonormal + /// Given a unit vector return two other vectors that together form a left-handed orthonormal /// basis. That is, all three vectors are orthogonal to each other and are normalized. /// /// # Panics @@ -1041,7 +1041,20 @@ impl Vec3A { /// Will panic if `self` is not normalized when `glam_assert` is enabled. #[inline] #[must_use] - pub fn any_orthonormal_pair(&self) -> (Self, Self) { + pub fn any_orthonormal_pair_lh(&self) -> (Self, Self) { + let (a, b) = self.any_orthonormal_pair_rh(); + (-a, b) + } + + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + pub fn any_orthonormal_pair_rh(&self) -> (Self, Self) { glam_assert!(self.is_normalized()); // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf let sign = math::signum(self.z); diff --git a/src/f64/dvec3.rs b/src/f64/dvec3.rs index 4b71c124..1f9b65ee 100644 --- a/src/f64/dvec3.rs +++ b/src/f64/dvec3.rs @@ -1057,7 +1057,7 @@ impl DVec3 { Self::new(b, sign + self.y * self.y * a, -self.y) } - /// Given a unit vector return two other vectors that together form an orthonormal + /// Given a unit vector return two other vectors that together form a left-handed orthonormal /// basis. That is, all three vectors are orthogonal to each other and are normalized. /// /// # Panics @@ -1065,7 +1065,20 @@ impl DVec3 { /// Will panic if `self` is not normalized when `glam_assert` is enabled. #[inline] #[must_use] - pub fn any_orthonormal_pair(&self) -> (Self, Self) { + pub fn any_orthonormal_pair_lh(&self) -> (Self, Self) { + let (a, b) = self.any_orthonormal_pair_rh(); + (-a, b) + } + + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + pub fn any_orthonormal_pair_rh(&self) -> (Self, Self) { glam_assert!(self.is_normalized()); // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf let sign = math::signum(self.z); diff --git a/templates/vec.rs.tera b/templates/vec.rs.tera index 4d7ddb0f..dd4bdf5b 100644 --- a/templates/vec.rs.tera +++ b/templates/vec.rs.tera @@ -2337,7 +2337,7 @@ impl {{ self_t }} { Self::new(b, sign + self.y * self.y * a, -self.y) } - /// Given a unit vector return two other vectors that together form an orthonormal + /// Given a unit vector return two other vectors that together form a left-handed orthonormal /// basis. That is, all three vectors are orthogonal to each other and are normalized. /// /// # Panics @@ -2345,7 +2345,20 @@ impl {{ self_t }} { /// Will panic if `self` is not normalized when `glam_assert` is enabled. #[inline] #[must_use] - pub fn any_orthonormal_pair(&self) -> (Self, Self) { + pub fn any_orthonormal_pair_lh(&self) -> (Self, Self) { + let (a, b) = self.any_orthonormal_pair_rh(); + (-a, b) + } + + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + pub fn any_orthonormal_pair_rh(&self) -> (Self, Self) { glam_assert!(self.is_normalized()); // From https://graphics.pixar.com/library/OrthonormalB/paper.pdf let sign = math::signum(self.z); From 32021f67d2fd837186ba9c06a3bcce68ff1d3504 Mon Sep 17 00:00:00 2001 From: atlas Date: Sat, 19 Jul 2025 01:08:51 -0400 Subject: [PATCH 2/4] Add deprecated legacy to avoid breaking people --- src/f32/coresimd/vec3a.rs | 16 ++++++++++++++++ src/f32/neon/vec3a.rs | 16 ++++++++++++++++ src/f32/scalar/vec3a.rs | 16 ++++++++++++++++ src/f32/sse2/vec3a.rs | 16 ++++++++++++++++ src/f32/vec3.rs | 16 ++++++++++++++++ src/f32/wasm32/vec3a.rs | 16 ++++++++++++++++ src/f64/dvec3.rs | 16 ++++++++++++++++ templates/vec.rs.tera | 16 ++++++++++++++++ 8 files changed, 128 insertions(+) diff --git a/src/f32/coresimd/vec3a.rs b/src/f32/coresimd/vec3a.rs index 7f241efb..6fc90de7 100644 --- a/src/f32/coresimd/vec3a.rs +++ b/src/f32/coresimd/vec3a.rs @@ -1053,6 +1053,22 @@ impl Vec3A { ) } + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + #[deprecated( + since = "0.30.4", + note = "Use any_orthonormal_pair_rh() instead to preserve identical functionality, or any_orthonormal_pair_lh if you a left-handed basis." + )] + pub fn any_orthonormal_pair(&self) -> (Self, Self) { + self.any_orthonormal_pair_rh() + } + /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`. /// /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result diff --git a/src/f32/neon/vec3a.rs b/src/f32/neon/vec3a.rs index ae7865ec..10d81de1 100644 --- a/src/f32/neon/vec3a.rs +++ b/src/f32/neon/vec3a.rs @@ -1095,6 +1095,22 @@ impl Vec3A { ) } + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + #[deprecated( + since = "0.30.4", + note = "Use any_orthonormal_pair_rh() instead to preserve identical functionality, or any_orthonormal_pair_lh if you a left-handed basis." + )] + pub fn any_orthonormal_pair(&self) -> (Self, Self) { + self.any_orthonormal_pair_rh() + } + /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`. /// /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result diff --git a/src/f32/scalar/vec3a.rs b/src/f32/scalar/vec3a.rs index e49e80d0..dd6b039a 100644 --- a/src/f32/scalar/vec3a.rs +++ b/src/f32/scalar/vec3a.rs @@ -1100,6 +1100,22 @@ impl Vec3A { ) } + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + #[deprecated( + since = "0.30.4", + note = "Use any_orthonormal_pair_rh() instead to preserve identical functionality, or any_orthonormal_pair_lh if you a left-handed basis." + )] + pub fn any_orthonormal_pair(&self) -> (Self, Self) { + self.any_orthonormal_pair_rh() + } + /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`. /// /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result diff --git a/src/f32/sse2/vec3a.rs b/src/f32/sse2/vec3a.rs index d0789de7..769d8cb9 100644 --- a/src/f32/sse2/vec3a.rs +++ b/src/f32/sse2/vec3a.rs @@ -1103,6 +1103,22 @@ impl Vec3A { ) } + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + #[deprecated( + since = "0.30.4", + note = "Use any_orthonormal_pair_rh() instead to preserve identical functionality, or any_orthonormal_pair_lh if you a left-handed basis." + )] + pub fn any_orthonormal_pair(&self) -> (Self, Self) { + self.any_orthonormal_pair_rh() + } + /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`. /// /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result diff --git a/src/f32/vec3.rs b/src/f32/vec3.rs index 7bcc6f02..88bd0f22 100644 --- a/src/f32/vec3.rs +++ b/src/f32/vec3.rs @@ -1090,6 +1090,22 @@ impl Vec3 { ) } + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + #[deprecated( + since = "0.30.4", + note = "Use any_orthonormal_pair_rh() instead to preserve identical functionality, or any_orthonormal_pair_lh if you a left-handed basis." + )] + pub fn any_orthonormal_pair(&self) -> (Self, Self) { + self.any_orthonormal_pair_rh() + } + /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`. /// /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result diff --git a/src/f32/wasm32/vec3a.rs b/src/f32/wasm32/vec3a.rs index cabb8494..aea5caa0 100644 --- a/src/f32/wasm32/vec3a.rs +++ b/src/f32/wasm32/vec3a.rs @@ -1066,6 +1066,22 @@ impl Vec3A { ) } + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + #[deprecated( + since = "0.30.4", + note = "Use any_orthonormal_pair_rh() instead to preserve identical functionality, or any_orthonormal_pair_lh if you a left-handed basis." + )] + pub fn any_orthonormal_pair(&self) -> (Self, Self) { + self.any_orthonormal_pair_rh() + } + /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`. /// /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result diff --git a/src/f64/dvec3.rs b/src/f64/dvec3.rs index 1f9b65ee..83a68984 100644 --- a/src/f64/dvec3.rs +++ b/src/f64/dvec3.rs @@ -1090,6 +1090,22 @@ impl DVec3 { ) } + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + #[deprecated( + since = "0.30.4", + note = "Use any_orthonormal_pair_rh() instead to preserve identical functionality, or any_orthonormal_pair_lh if you a left-handed basis." + )] + pub fn any_orthonormal_pair(&self) -> (Self, Self) { + self.any_orthonormal_pair_rh() + } + /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`. /// /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result diff --git a/templates/vec.rs.tera b/templates/vec.rs.tera index dd4bdf5b..6e7ed85b 100644 --- a/templates/vec.rs.tera +++ b/templates/vec.rs.tera @@ -2370,6 +2370,22 @@ impl {{ self_t }} { ) } + /// Given a unit vector return two other vectors that together form a right-handed orthonormal + /// basis. That is, all three vectors are orthogonal to each other and are normalized. + /// + /// # Panics + /// + /// Will panic if `self` is not normalized when `glam_assert` is enabled. + #[inline] + #[must_use] + #[deprecated( + since = "0.30.4", + note = "Use any_orthonormal_pair_rh() instead to preserve identical functionality, or any_orthonormal_pair_lh if you a left-handed basis." + )] + pub fn any_orthonormal_pair(&self) -> (Self, Self) { + self.any_orthonormal_pair_rh() + } + /// Performs a spherical linear interpolation between `self` and `rhs` based on the value `s`. /// /// When `s` is `0.0`, the result will be equal to `self`. When `s` is `1.0`, the result From 05f28a5677cf64416706299c9f89a235a902f3d2 Mon Sep 17 00:00:00 2001 From: atlas Date: Sat, 19 Jul 2025 01:20:34 -0400 Subject: [PATCH 3/4] Fix bench --- benches/vec3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/benches/vec3.rs b/benches/vec3.rs index c378e1e5..d1214343 100644 --- a/benches/vec3.rs +++ b/benches/vec3.rs @@ -131,7 +131,7 @@ bench_func!( #[inline(always)] fn vec3_any_orthonormal_pair(v: Vec3) -> (Vec3, Vec3) { - v.any_orthonormal_pair() + v.any_orthonormal_pair_rh() } bench_func!( From 4803e42359c59917e5006e679b1119471cd1aa61 Mon Sep 17 00:00:00 2001 From: atlas Date: Sat, 19 Jul 2025 01:28:34 -0400 Subject: [PATCH 4/4] fix tests --- tests/vec3.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/vec3.rs b/tests/vec3.rs index 525177bf..12c15408 100644 --- a/tests/vec3.rs +++ b/tests/vec3.rs @@ -1791,7 +1791,7 @@ macro_rules! impl_vec3_float_tests { assert!(orthonormal.is_normalized()); assert!(n.dot(orthonormal).abs() < eps); - let (a, b) = n.any_orthonormal_pair(); + let (a, b) = n.any_orthonormal_pair_rh(); assert!(a.is_normalized() && n.dot(a).abs() < eps); assert!(b.is_normalized() && n.dot(b).abs() < eps); }