1
0
Fork 0

vector2d: implement subtraction of vectors

Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
Matej Focko 2022-12-09 12:15:40 +01:00
parent cb82cbb433
commit 3219400a73
Signed by: mfocko
GPG key ID: 7C47D46246790496

View file

@ -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<T> {
@ -81,6 +81,17 @@ impl<T: Add + Add<Output = U>, U> Add for Vector2D<T> {
}
}
impl<T: Sub + Sub<Output = U>, U> Sub for Vector2D<T> {
type Output = Vector2D<U>;
fn sub(self, rhs: Self) -> Self::Output {
Vector2D {
x: self.x - rhs.x,
y: self.y - rhs.y,
}
}
}
impl<T: Mul + Mul<Output = U>, U> Mul for Vector2D<T> {
type Output = Vector2D<U>;