use std::ops::{Add, AddAssign, Sub};
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Vector(pub f32, pub f32);
impl Vector {
pub fn from_tuple(tuple: (f32, f32)) -> Vector {
Vector(tuple.0, tuple.1)
}
pub fn norm2sq(&self) -> f32 {
self.0 * self.0 + self.1 * self.1
}
pub fn scale(&mut self, factor: f32) {
self.0 *= factor;
self.1 *= factor;
}
}
impl Add for Vector {
type Output = Vector;
fn add(self, other: Vector) -> Vector {
Vector(self.0 + other.0, self.1 + other.1)
}
}
impl AddAssign for Vector {
fn add_assign(&mut self, rhs: Vector) {
self.0 += rhs.0;
self.1 += rhs.1;
}
}
impl Sub for Vector {
type Output = Vector;
fn sub(self, other: Vector) -> Vector {
Vector(self.0 - other.0, self.1 - other.1)
}
}