use std::ops::{Add, Sub, Mul, Div};
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct Point {
pub x: i32,
pub y: i32,
}
impl Point {
pub fn new(x: i32, y: i32) -> Self {
Self {
x,
y,
}
}
}
impl Add for Point {
type Output = Self;
fn add(self, other: Self) -> Self {
Self {
x: self.x + other.x,
y: self.y + other.y,
}
}
}
impl Sub for Point {
type Output = Self;
fn sub(self, other: Self) -> Self {
Self {
x: self.x - other.x,
y: self.y - other.y,
}
}
}
impl Mul for Point {
type Output = Self;
fn mul(self, other: Self) -> Self {
Self {
x: self.x * other.x,
y: self.y * other.y,
}
}
}
impl Div for Point {
type Output = Self;
fn div(self, other: Self) -> Self {
Self {
x: self.x / other.x,
y: self.y / other.y,
}
}
}
impl Into<(i32, i32)> for Point {
fn into(self) -> (i32, i32) {
(self.x, self.y)
}
}
impl From<(i32, i32)> for Point {
fn from(values: (i32, i32)) -> Self {
Self::new(values.0, values.1)
}
}