lib(vec3d): support add/sub-assign
Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
parent
45603e36bf
commit
5fd223dfb3
1 changed files with 17 additions and 1 deletions
|
@ -2,7 +2,7 @@ use std::cmp::Eq;
|
||||||
// use std::collections::VecDeque;
|
// use std::collections::VecDeque;
|
||||||
use std::fmt::Debug;
|
use std::fmt::Debug;
|
||||||
use std::hash::Hash;
|
use std::hash::Hash;
|
||||||
use std::ops::{Add, /* Index, IndexMut, */ Mul, Sub};
|
use std::ops::{Add, AddAssign, Mul, Sub, SubAssign};
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub struct Vector3D<T> {
|
pub struct Vector3D<T> {
|
||||||
|
@ -101,6 +101,14 @@ impl<T: Add + Add<Output = U>, U> Add for Vector3D<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: AddAssign> AddAssign for Vector3D<T> {
|
||||||
|
fn add_assign(&mut self, rhs: Self) {
|
||||||
|
self.x += rhs.x;
|
||||||
|
self.y += rhs.y;
|
||||||
|
self.z += rhs.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Sub + Sub<Output = U>, U> Sub for Vector3D<T> {
|
impl<T: Sub + Sub<Output = U>, U> Sub for Vector3D<T> {
|
||||||
type Output = Vector3D<U>;
|
type Output = Vector3D<U>;
|
||||||
|
|
||||||
|
@ -113,6 +121,14 @@ impl<T: Sub + Sub<Output = U>, U> Sub for Vector3D<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: SubAssign> SubAssign for Vector3D<T> {
|
||||||
|
fn sub_assign(&mut self, rhs: Self) {
|
||||||
|
self.x -= rhs.x;
|
||||||
|
self.y -= rhs.y;
|
||||||
|
self.z -= rhs.z;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Mul + Mul<Output = U>, U> Mul for Vector3D<T> {
|
impl<T: Mul + Mul<Output = U>, U> Mul for Vector3D<T> {
|
||||||
type Output = Vector3D<U>;
|
type Output = Vector3D<U>;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue