Skip to content

Commit 6032978

Browse files
authored
Implement Mul between f32 and direction types (#12276)
# Objective Bevy's `Dir3` and `Dir3A` only implement `Mul<f32>` and not vice versa, and `Dir2` can not be multiplied by `f32` at all. They all should implement multiplication both ways, just like Glam's vector types. ## Solution Implement `Mul<Dir2>`, `Mul<Dir3>`, and `Mul<Dir3A>` for `f32`, and `Mul<f32>` for `Dir2`.
1 parent 57733bb commit 6032978

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

crates/bevy_math/src/direction.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,20 @@ impl std::ops::Neg for Dir2 {
132132
}
133133
}
134134

135+
impl std::ops::Mul<f32> for Dir2 {
136+
type Output = Vec2;
137+
fn mul(self, rhs: f32) -> Self::Output {
138+
self.0 * rhs
139+
}
140+
}
141+
142+
impl std::ops::Mul<Dir2> for f32 {
143+
type Output = Vec2;
144+
fn mul(self, rhs: Dir2) -> Self::Output {
145+
self * rhs.0
146+
}
147+
}
148+
135149
#[cfg(feature = "approx")]
136150
impl approx::AbsDiffEq for Dir2 {
137151
type Epsilon = f32;
@@ -261,6 +275,13 @@ impl std::ops::Mul<f32> for Dir3 {
261275
}
262276
}
263277

278+
impl std::ops::Mul<Dir3> for f32 {
279+
type Output = Vec3;
280+
fn mul(self, rhs: Dir3) -> Self::Output {
281+
self * rhs.0
282+
}
283+
}
284+
264285
impl std::ops::Mul<Dir3> for Quat {
265286
type Output = Dir3;
266287

@@ -408,6 +429,13 @@ impl std::ops::Mul<f32> for Dir3A {
408429
}
409430
}
410431

432+
impl std::ops::Mul<Dir3A> for f32 {
433+
type Output = Vec3A;
434+
fn mul(self, rhs: Dir3A) -> Self::Output {
435+
self * rhs.0
436+
}
437+
}
438+
411439
impl std::ops::Mul<Dir3A> for Quat {
412440
type Output = Dir3A;
413441

0 commit comments

Comments
 (0)