1
0
Fork 0

lib(vec3d): support add/sub-assign

Signed-off-by: Matej Focko <me@mfocko.xyz>
This commit is contained in:
Matej Focko 2024-07-07 16:18:51 +02:00
parent 45603e36bf
commit 5fd223dfb3
Signed by: mfocko
SSH key fingerprint: SHA256:5YXD7WbPuK60gxnG6DjAwJiS9+swoWj33/HFu8g8JVo

View file

@ -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>;