Select Git revision
vec.rs 713 B
use std::ops::{Add, Sub, Mul};
#[derive(Debug, Clone, Copy)]
pub struct Vector {
x: i128,
y: i128,
}
impl Vector {
pub fn new(x: i128, y: i128) -> Vector {
Vector { x, y }
}
}
impl Add for Vector {
type Output = Vector;
fn add(self, rhs: Self) -> Vector {
Vector {
x: self.x + rhs.x,
y: self.y + rhs.y,
}
}
}
impl Sub for Vector {
type Output = Vector;
fn sub(self, rhs: Self) -> Vector {
Vector {
x: self.x - rhs.x,
y: self.y - rhs.y,
}
}
}
impl Mul for Vector {
type Output = i128;
fn mul(self, rhs: Self) -> i128 {
self.x * rhs.x + self.y * rhs.y
}
}