From a924aaf2b0dee84835dfe5f6f5381076017fb18a Mon Sep 17 00:00:00 2001 From: HampusM Date: Tue, 28 Nov 2023 19:34:29 +0100 Subject: feat(engine): add Vec2 Add, Sub, Mul & Div impls --- engine/src/vector.rs | 62 +++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) (limited to 'engine') 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 pub const ZERO: Self = Self { x: 0, y: 0 }; } +impl Add for Vec2 +where + Value: Add + Clone, +{ + type Output = Self; + + fn add(self, rhs: Value) -> Self::Output + { + Self { + x: self.x + rhs.clone(), + y: self.y + rhs, + } + } +} + +impl Sub for Vec2 +where + Value: Sub + Clone, +{ + type Output = Self; + + fn sub(self, rhs: Value) -> Self::Output + { + Self { + x: self.x - rhs.clone(), + y: self.y - rhs, + } + } +} + +impl Mul for Vec2 +where + Value: Mul + Clone, +{ + type Output = Self; + + fn mul(self, rhs: Value) -> Self::Output + { + Self { + x: self.x * rhs.clone(), + y: self.y * rhs, + } + } +} + +impl Div for Vec2 +where + Value: Div + 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 -- cgit v1.2.3-18-g5258