From 9bac81e6be543139a7120c7a47c5299a8b72b445 Mon Sep 17 00:00:00 2001 From: HampusM Date: Wed, 25 Oct 2023 21:20:40 +0200 Subject: feat(engine): make Vec3 implement Add --- engine/src/vector.rs | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) (limited to 'engine/src') 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 @@ -100,6 +100,38 @@ where } } +impl Add for Vec3 +where + Value: Add, +{ + 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 Add for &Vec3 +where + for<'a, 'b> &'a Value: Add<&'b Value, Output = Value>, +{ + type Output = Vec3; + + 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 Neg for Vec3 where Value: Neg, -- cgit v1.2.3-18-g5258