mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-24 08:41:34 +11:00
multiplication and division by constant
This commit is contained in:
parent
0ea0f1df3f
commit
81db1b861c
|
@ -462,6 +462,35 @@ impl<T: Number> Add<Vector2D<T>> for Vector2D<T> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Number> Mul<T> for Vector2D<T> {
|
||||||
|
type Output = Vector2D<T>;
|
||||||
|
fn mul(self, rhs: T) -> Self::Output {
|
||||||
|
Vector2D {
|
||||||
|
x: self.x * rhs,
|
||||||
|
y: self.y * rhs,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T: Number> Div<T> for Vector2D<T> {
|
||||||
|
type Output = Vector2D<T>;
|
||||||
|
fn div(self, rhs: T) -> Self::Output {
|
||||||
|
Vector2D {
|
||||||
|
x: self.x / rhs,
|
||||||
|
y: self.y / rhs,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test_case]
|
||||||
|
fn test_vector_multiplication_and_division(_gba: &mut super::Gba) {
|
||||||
|
let a: Vector2D<i32> = (1, 2).into();
|
||||||
|
let b = a * 5;
|
||||||
|
let c = b / 5;
|
||||||
|
assert_eq!(b, (5, 10).into());
|
||||||
|
assert_eq!(a, c);
|
||||||
|
}
|
||||||
|
|
||||||
impl<T: Number> AddAssign<Self> for Vector2D<T> {
|
impl<T: Number> AddAssign<Self> for Vector2D<T> {
|
||||||
fn add_assign(&mut self, rhs: Self) {
|
fn add_assign(&mut self, rhs: Self) {
|
||||||
*self = *self + rhs;
|
*self = *self + rhs;
|
||||||
|
|
Loading…
Reference in a new issue