Skip to content

Commit

Permalink
Implement Mul<Vector> and Mul<Dir> for Rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Jondolf committed Feb 18, 2024
1 parent a38e86b commit c287f09
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions src/components/rotation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,50 @@ impl SubAssign<Self> for Rotation {
}
}

impl core::ops::Mul<Vector> for Rotation {
type Output = Vector;

fn mul(self, vector: Vector) -> Self::Output {
let rotated = self.rotate(vector);

// Make sure the result is normalized.
// This can fail for non-unit quaternions.
debug_assert!(rotated.is_normalized());

rotated
}
}

impl core::ops::Mul<Dir> for Rotation {
type Output = Dir;

fn mul(self, direction: Dir) -> Self::Output {
Dir::new_unchecked(self.rotate(direction.adjust_precision()).f32())
}
}

impl core::ops::Mul<Vector> for &Rotation {
type Output = Vector;

fn mul(self, vector: Vector) -> Self::Output {
let rotated = self.rotate(vector);

// Make sure the result is normalized.
// This can fail for non-unit quaternions.
debug_assert!(rotated.is_normalized());

rotated
}
}

impl core::ops::Mul<Dir> for &Rotation {
type Output = Dir;

fn mul(self, direction: Dir) -> Self::Output {
Dir::new_unchecked(self.rotate(direction.adjust_precision()).f32())
}
}

#[cfg(feature = "2d")]
impl From<Rotation> for Scalar {
fn from(rot: Rotation) -> Self {
Expand Down

0 comments on commit c287f09

Please sign in to comment.