From 12af48feb8f04bb52a61078e798d63b92c2d83d1 Mon Sep 17 00:00:00 2001 From: Buncys Date: Sat, 24 Jan 2026 12:57:34 +0100 Subject: [PATCH 1/2] feat: add From trait implementations between Pose2/Pose3 and tuples --- src/pose2.rs | 27 +++++++++++++++++++++++++++ src/pose3.rs | 30 ++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/src/pose2.rs b/src/pose2.rs index 44c10ce..63cae35 100644 --- a/src/pose2.rs +++ b/src/pose2.rs @@ -315,6 +315,23 @@ macro_rules! impl_pose2 { } } + impl From<($Vec2, $Real)> for $Pose2 { + #[inline] + fn from((translation, rotation): ($Vec2, $Real)) -> Self { + Self { + translation, + rotation: $Rot2::new(rotation), + } + } + } + + impl From<$Pose2> for ($Vec2, $Real) { + #[inline] + fn from(pose: $Pose2) -> ($Vec2, $Real) { + (pose.translation, pose.rotation.angle()) + } + } + #[cfg(feature = "approx")] impl approx::AbsDiffEq for $Pose2 { type Epsilon = $Real; @@ -529,4 +546,14 @@ mod tests { assert_relative_eq!(p.translation.x, 1.0, epsilon = 1e-10); assert_relative_eq!(p.translation.y, 2.0, epsilon = 1e-10); } + + #[test] + fn test_convert_back_to_equal_pose2() { + let (t1, r1) = (glam::Vec2::new(1.0, 2.0), PI / 4.0); + let p: Pose2 = (t1, r1).into(); + let (t2, r2) = p.into(); + + assert_relative_eq!(t1, t2, epsilon = 1e-6); + assert_relative_eq!(r1, r2, epsilon = 1e-6); + } } diff --git a/src/pose3.rs b/src/pose3.rs index cfab565..ad4e5c9 100644 --- a/src/pose3.rs +++ b/src/pose3.rs @@ -381,6 +381,23 @@ macro_rules! impl_pose3 { } } + impl From<($Vec3, $Rot3)> for $Pose3 { + #[inline] + fn from((translation, rotation): ($Vec3, $Rot3)) -> Self { + Self { + translation, + rotation, + } + } + } + + impl From<$Pose3> for ($Vec3, $Rot3) { + #[inline] + fn from(pose: $Pose3) -> ($Vec3, $Rot3) { + (pose.translation, pose.rotation) + } + } + #[cfg(feature = "approx")] impl approx::AbsDiffEq for $Pose3 { type Epsilon = $Real; @@ -645,4 +662,17 @@ mod tests { assert_relative_eq!(p.translation.y, 2.0, epsilon = 1e-10); assert_relative_eq!(p.translation.z, 3.0, epsilon = 1e-10); } + + #[test] + fn test_convert_back_to_equal_pose3() { + let (t1, r1) = ( + glam::Vec3::new(1.0, 2.0, 3.0), + glam::Quat::from_rotation_x(PI / 4.0), + ); + let p: Pose3 = (t1, r1).into(); + let (t2, r2) = p.into(); + + assert_relative_eq!(t1, t2, epsilon = 1e-6); + assert!(r1.dot(r2).abs() > 1.0 - 1e-5); + } } From 2773d08a4d3113061faced79152e35ff01ab2593 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Crozet?= Date: Thu, 17 Sep 2026 23:07:21 +0200 Subject: [PATCH 2/2] fix CI --- src/pose3.rs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/pose3.rs b/src/pose3.rs index ad4e5c9..ce91c9c 100644 --- a/src/pose3.rs +++ b/src/pose3.rs @@ -384,10 +384,7 @@ macro_rules! impl_pose3 { impl From<($Vec3, $Rot3)> for $Pose3 { #[inline] fn from((translation, rotation): ($Vec3, $Rot3)) -> Self { - Self { - translation, - rotation, - } + Self::from_parts(translation, rotation) } }