summaryrefslogtreecommitdiff
path: root/engine
diff options
context:
space:
mode:
authorHampusM <hampus@hampusmat.com>2023-11-28 19:34:29 +0100
committerHampusM <hampus@hampusmat.com>2023-11-28 19:34:29 +0100
commita924aaf2b0dee84835dfe5f6f5381076017fb18a (patch)
tree568a4924aa68790d20a16f1dbfa8a183370339aa /engine
parentc04ff88876e48cdf09223fe99b77e4724f2024aa (diff)
feat(engine): add Vec2 Add, Sub, Mul & Div impls
Diffstat (limited to 'engine')
-rw-r--r--engine/src/vector.rs62
1 files changed, 61 insertions, 1 deletions
diff --git a/engine/src/vector.rs b/engine/src/vector.rs
index e0aa262..1d2ea93 100644
--- a/engine/src/vector.rs
+++ b/engine/src/vector.rs
@@ -1,4 +1,4 @@
-use std::ops::{Add, AddAssign, Mul, Neg, Sub, SubAssign};
+use std::ops::{Add, AddAssign, Div, Mul, Neg, Sub, SubAssign};
use crate::color::Color;
@@ -14,6 +14,66 @@ impl Vec2<u32>
pub const ZERO: Self = Self { x: 0, y: 0 };
}
+impl<Value> Add<Value> for Vec2<Value>
+where
+ Value: Add<Output = Value> + Clone,
+{
+ type Output = Self;
+
+ fn add(self, rhs: Value) -> Self::Output
+ {
+ Self {
+ x: self.x + rhs.clone(),
+ y: self.y + rhs,
+ }
+ }
+}
+
+impl<Value> Sub<Value> for Vec2<Value>
+where
+ Value: Sub<Output = Value> + Clone,
+{
+ type Output = Self;
+
+ fn sub(self, rhs: Value) -> Self::Output
+ {
+ Self {
+ x: self.x - rhs.clone(),
+ y: self.y - rhs,
+ }
+ }
+}
+
+impl<Value> Mul<Value> for Vec2<Value>
+where
+ Value: Mul<Output = Value> + Clone,
+{
+ type Output = Self;
+
+ fn mul(self, rhs: Value) -> Self::Output
+ {
+ Self {
+ x: self.x * rhs.clone(),
+ y: self.y * rhs,
+ }
+ }
+}
+
+impl<Value> Div<Value> for Vec2<Value>
+where
+ Value: Div<Output = Value> + Clone,
+{
+ type Output = Self;
+
+ fn div(self, rhs: Value) -> Self::Output
+ {
+ Self {
+ x: self.x / rhs.clone(),
+ y: self.y / rhs,
+ }
+ }
+}
+
#[derive(Debug, Default, Clone)]
#[repr(C)]
pub struct Vec3<Value>