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`.
This commit is contained in:
Joona Aalto 2024-01-02 18:46:03 +02:00 committed by GitHub
parent 4034740396
commit 6086d4193e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -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 {

View file

@ -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 {