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

Optimize unnecessary normalizations for Transform::local_{xyz} #14171

Merged
merged 3 commits into from
Jul 8, 2024
Merged
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
12 changes: 6 additions & 6 deletions crates/bevy_transform/src/components/transform.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,8 +222,8 @@ impl Transform {
/// Get the unit vector in the local `X` direction.
#[inline]
pub fn local_x(&self) -> Dir3 {
// Dir3::new(x) panics if x is of invalid length, but quat * unit vector is length 1
Dir3::new(self.rotation * Vec3::X).unwrap()
// Quat * unit vector is length 1
Dir3::new_unchecked(self.rotation * Vec3::X)
}

/// Equivalent to [`-local_x()`][Transform::local_x()]
Expand All @@ -241,8 +241,8 @@ impl Transform {
/// Get the unit vector in the local `Y` direction.
#[inline]
pub fn local_y(&self) -> Dir3 {
// Dir3::new(x) panics if x is of invalid length, but quat * unit vector is length 1
Dir3::new(self.rotation * Vec3::Y).unwrap()
// Quat * unit vector is length 1
Dir3::new_unchecked(self.rotation * Vec3::Y)
}

/// Equivalent to [`local_y()`][Transform::local_y]
Expand All @@ -260,8 +260,8 @@ impl Transform {
/// Get the unit vector in the local `Z` direction.
#[inline]
pub fn local_z(&self) -> Dir3 {
// Dir3::new(x) panics if x is of invalid length, but quat * unit vector is length 1
Dir3::new(self.rotation * Vec3::Z).unwrap()
// Quat * unit vector is length 1
Dir3::new_unchecked(self.rotation * Vec3::Z)
}

/// Equivalent to [`-local_z()`][Transform::local_z]
Expand Down