summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-10-25 21:20:40 +0200
committerHampusM <hampus@hampusmat.com>2023-10-25 21:20:40 +0200
commit9bac81e6be543139a7120c7a47c5299a8b72b445 (patch)
tree029f15971ca1dcc6fb2c8d06b932ee911b57fbe7
parentfd535654369b31e1283a609ba8e8fcf0df42100b (diff)
feat(engine): make Vec3 implement Add
-rw-r--r--engine/src/vector.rs34
1 files changed, 33 insertions, 1 deletions
diff --git a/engine/src/vector.rs b/engine/src/vector.rs
index 88a8198..0a2f88b 100644
--- a/engine/src/vector.rs
+++ b/engine/src/vector.rs
@@ -1,4 +1,4 @@
-use std::ops::{Neg, Sub};
+use std::ops::{Add, Neg, Sub};
#[derive(Debug)]
pub struct Vec2<Value>
@@ -100,6 +100,38 @@ where
}
}
+impl<Value> Add for Vec3<Value>
+where
+ Value: Add<Value, Output = Value>,
+{
+ type Output = Self;
+
+ fn add(self, rhs: Self) -> Self::Output
+ {
+ Self::Output {
+ x: self.x + rhs.x,
+ y: self.y + rhs.y,
+ z: self.z + rhs.z,
+ }
+ }
+}
+
+impl<Value> Add for &Vec3<Value>
+where
+ for<'a, 'b> &'a Value: Add<&'b Value, Output = Value>,
+{
+ type Output = Vec3<Value>;
+
+ fn add(self, rhs: Self) -> Self::Output
+ {
+ Self::Output {
+ x: &self.x + &rhs.x,
+ y: &self.y + &rhs.y,
+ z: &self.z + &rhs.z,
+ }
+ }
+}
+
impl<Value> Neg for Vec3<Value>
where
Value: Neg<Output = Value>,