vector2d: implement subtraction of vectors
Signed-off-by: Matej Focko <mfocko@redhat.com>
This commit is contained in:
parent
cb82cbb433
commit
3219400a73
1 changed files with 12 additions and 1 deletions
|
@ -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>;
|
||||
|
||||
|
|
Loading…
Reference in a new issue