Skip to content

Commit a49cf46

Browse files
committed
fix handling unnormalized axis for (Pose)RotationAxisAngle
1 parent 2a33e76 commit a49cf46

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

crates/store/re_types/src/components/pose_rotation_axis_angle_ext.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ impl PoseRotationAxisAngle {
1717
impl From<PoseRotationAxisAngle> for glam::Affine3A {
1818
#[inline]
1919
fn from(val: PoseRotationAxisAngle) -> Self {
20-
Self::from_axis_angle(val.0.axis.into(), val.0.angle.radians())
20+
if let Some(normalized) = glam::Vec3::from(val.0.axis).try_normalize() {
21+
Self::from_axis_angle(normalized, val.0.angle.radians())
22+
} else {
23+
// If the axis is zero length, we can't normalize it, so we just use the identity rotation.
24+
Self::IDENTITY
25+
}
2126
}
2227
}

crates/store/re_types/src/components/rotation_axis_angle_ext.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@ impl RotationAxisAngle {
1717
impl From<RotationAxisAngle> for glam::Affine3A {
1818
#[inline]
1919
fn from(val: RotationAxisAngle) -> Self {
20-
Self::from_axis_angle(val.0.axis.into(), val.0.angle.radians())
20+
if let Some(normalized) = glam::Vec3::from(val.0.axis).try_normalize() {
21+
Self::from_axis_angle(normalized, val.0.angle.radians())
22+
} else {
23+
// If the axis is zero length, we can't normalize it, so we just use the identity rotation.
24+
Self::IDENTITY
25+
}
2126
}
2227
}

0 commit comments

Comments
 (0)