Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Treat zero-angle rotation as identity when axis is invalid #8952

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ namespace rerun.components;

/// 3D rotation represented by a rotation around a given axis.
///
/// If normalization of the rotation axis fails the rotation is treated as an invalid transform.
/// If normalization of the rotation axis fails the rotation is treated as an invalid transform, unless the
/// angle is zero in which case it is treated as an identity.
table RotationAxisAngle (
"attr.rust.derive": "Default, Copy, PartialEq",
"attr.rust.repr": "transparent"
Expand All @@ -12,7 +13,8 @@ table RotationAxisAngle (

/// 3D rotation represented by a rotation around a given axis that doesn't propagate in the transform hierarchy.
///
/// If normalization of the rotation axis fails the rotation is treated as an invalid transform.
/// If normalization of the rotation axis fails the rotation is treated as an invalid transform, unless the
/// angle is zero in which case it is treated as an identity.
table PoseRotationAxisAngle (
"attr.rust.derive": "Default, Copy, PartialEq",
"attr.rust.repr": "transparent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ table RotationAxisAngle (
///
/// This is not required to be normalized.
/// However, if normalization of the rotation axis fails (typically due to a zero vector)
/// the rotation is treated as an invalid transform.
/// the rotation is treated as an invalid transform, unless the angle is zero in which case
/// it is treated as an identity.
axis: rerun.datatypes.Vec3D (order: 100);

/// How much to rotate around the axis.
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,14 @@ impl TryFrom<PoseRotationAxisAngle> for glam::Affine3A {

#[inline]
fn try_from(val: PoseRotationAxisAngle) -> Result<Self, Self::Error> {
glam::Vec3::from(val.0.axis)
.try_normalize()
.map(|normalized| Self::from_axis_angle(normalized, val.0.angle.radians()))
.ok_or(())
// 0 degrees around any axis is an identity transform.
if val.angle.radians == 0. {
Ok(Self::IDENTITY)
} else {
glam::Vec3::from(val.0.axis)
.try_normalize()
.map(|normalized| Self::from_axis_angle(normalized, val.0.angle.radians()))
.ok_or(())
}
}
}
3 changes: 2 additions & 1 deletion crates/store/re_types/src/components/rotation_axis_angle.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion crates/store/re_types/src/datatypes/rotation_axis_angle.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions crates/store/re_types/src/reflection/mod.rs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rerun_cpp/src/rerun/components/pose_rotation_axis_angle.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rerun_cpp/src/rerun/components/rotation_axis_angle.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rerun_cpp/src/rerun/datatypes/rotation_axis_angle.hpp

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rerun_py/rerun_sdk/rerun/components/rotation_axis_angle.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion rerun_py/rerun_sdk/rerun/datatypes/rotation_axis_angle.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading