From 6086d4193ef71aa0c6c1bc7c9609d56d9915e188 Mon Sep 17 00:00:00 2001 From: Joona Aalto Date: Tue, 2 Jan 2024 18:46:03 +0200 Subject: [PATCH] Implement `Neg` for `Direction2d` and `Direction3d` (#11179) # Objective I frequently encounter cases where I need to get the opposite direction. This currently requires something like `Direction2d::from_normalized(-*direction)`, which is very inconvenient. ## Solution Implement `Neg` for `Direction2d` and `Direction3d`. --- crates/bevy_math/src/primitives/dim2.rs | 7 +++++++ crates/bevy_math/src/primitives/dim3.rs | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/crates/bevy_math/src/primitives/dim2.rs b/crates/bevy_math/src/primitives/dim2.rs index fbb7811cfb..8b34a100eb 100644 --- a/crates/bevy_math/src/primitives/dim2.rs +++ b/crates/bevy_math/src/primitives/dim2.rs @@ -58,6 +58,13 @@ impl std::ops::Deref for Direction2d { } } +impl std::ops::Neg for Direction2d { + type Output = Self; + fn neg(self) -> Self::Output { + Self(-self.0) + } +} + /// A circle primitive #[derive(Clone, Copy, Debug)] pub struct Circle { diff --git a/crates/bevy_math/src/primitives/dim3.rs b/crates/bevy_math/src/primitives/dim3.rs index 0177d03fc3..93b92fbc6c 100644 --- a/crates/bevy_math/src/primitives/dim3.rs +++ b/crates/bevy_math/src/primitives/dim3.rs @@ -58,6 +58,13 @@ impl std::ops::Deref for Direction3d { } } +impl std::ops::Neg for Direction3d { + type Output = Self; + fn neg(self) -> Self::Output { + Self(-self.0) + } +} + /// A sphere primitive #[derive(Clone, Copy, Debug)] pub struct Sphere {