From 3219400a737ebf54188ca6958412c4d508709896 Mon Sep 17 00:00:00 2001 From: Matej Focko Date: Fri, 9 Dec 2022 12:15:40 +0100 Subject: [PATCH] vector2d: implement subtraction of vectors Signed-off-by: Matej Focko --- src/vector2d.rs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/vector2d.rs b/src/vector2d.rs index d89bb15..742f794 100644 --- a/src/vector2d.rs +++ b/src/vector2d.rs @@ -1,7 +1,7 @@ use std::cmp::Eq; use std::fmt::Debug; use std::hash::Hash; -use std::ops::{Add, Mul}; +use std::ops::{Add, Mul, Sub}; #[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct Vector2D { @@ -81,6 +81,17 @@ impl, U> Add for Vector2D { } } +impl, U> Sub for Vector2D { + type Output = Vector2D; + + fn sub(self, rhs: Self) -> Self::Output { + Vector2D { + x: self.x - rhs.x, + y: self.y - rhs.y, + } + } +} + impl, U> Mul for Vector2D { type Output = Vector2D;