diff --git a/crates/bevy_math/src/primitives/dim2.rs b/crates/bevy_math/src/primitives/dim2.rs index 8b34a100eb..b2c664377c 100644 --- a/crates/bevy_math/src/primitives/dim2.rs +++ b/crates/bevy_math/src/primitives/dim2.rs @@ -7,6 +7,15 @@ use crate::Vec2; pub struct Direction2d(Vec2); impl Direction2d { + /// A unit vector pointing along the positive X axis. + pub const X: Self = Self(Vec2::X); + /// A unit vector pointing along the positive Y axis. + pub const Y: Self = Self(Vec2::Y); + /// A unit vector pointing along the negative X axis. + pub const NEG_X: Self = Self(Vec2::NEG_X); + /// A unit vector pointing along the negative Y axis. + pub const NEG_Y: Self = Self(Vec2::NEG_Y); + /// Create a direction from a finite, nonzero [`Vec2`]. /// /// Returns [`Err(InvalidDirectionError)`](InvalidDirectionError) if the length @@ -378,10 +387,7 @@ mod tests { #[test] fn direction_creation() { - assert_eq!( - Direction2d::new(Vec2::X * 12.5), - Ok(Direction2d::from_normalized(Vec2::X)) - ); + assert_eq!(Direction2d::new(Vec2::X * 12.5), Ok(Direction2d::X)); assert_eq!( Direction2d::new(Vec2::new(0.0, 0.0)), Err(InvalidDirectionError::Zero) diff --git a/crates/bevy_math/src/primitives/dim3.rs b/crates/bevy_math/src/primitives/dim3.rs index 93b92fbc6c..2f490e77de 100644 --- a/crates/bevy_math/src/primitives/dim3.rs +++ b/crates/bevy_math/src/primitives/dim3.rs @@ -7,6 +7,19 @@ use crate::Vec3; pub struct Direction3d(Vec3); impl Direction3d { + /// A unit vector pointing along the positive X axis. + pub const X: Self = Self(Vec3::X); + /// A unit vector pointing along the positive Y axis. + pub const Y: Self = Self(Vec3::Y); + /// A unit vector pointing along the positive Z axis. + pub const Z: Self = Self(Vec3::Z); + /// A unit vector pointing along the negative X axis. + pub const NEG_X: Self = Self(Vec3::NEG_X); + /// A unit vector pointing along the negative Y axis. + pub const NEG_Y: Self = Self(Vec3::NEG_Y); + /// A unit vector pointing along the negative Z axis. + pub const NEG_Z: Self = Self(Vec3::NEG_Z); + /// Create a direction from a finite, nonzero [`Vec3`]. /// /// Returns [`Err(InvalidDirectionError)`](InvalidDirectionError) if the length @@ -391,10 +404,7 @@ mod test { #[test] fn direction_creation() { - assert_eq!( - Direction3d::new(Vec3::X * 12.5), - Ok(Direction3d::from_normalized(Vec3::X)) - ); + assert_eq!(Direction3d::new(Vec3::X * 12.5), Ok(Direction3d::X)); assert_eq!( Direction3d::new(Vec3::new(0.0, 0.0, 0.0)), Err(InvalidDirectionError::Zero)