1use std::ops::{Add, Div, Mul, Sub};
2
3#[derive(Debug, Default, Clone, PartialEq)]
5pub struct Vec2 {
6 pub x: usize,
7 pub y: usize,
8}
9impl Vec2 {
10 pub fn to_tuple(&self) -> (usize, usize) {
11 (self.x, self.y)
12 }
13}
14impl Add for Vec2 {
15 type Output = Self;
16 fn add(self, other: Self) -> Self {
17 Self {
18 x: self.x + other.x,
19 y: self.y + other.y,
20 }
21 }
22}
23impl Sub for Vec2 {
24 type Output = Self;
25 fn sub(self, other: Self) -> Self {
26 Self {
27 x: self.x - other.x,
28 y: self.y - other.y,
29 }
30 }
31}
32impl Mul for Vec2 {
33 type Output = Self;
34 fn mul(self, other: Self) -> Self {
35 Self {
36 x: self.x * other.x,
37 y: self.y * other.y,
38 }
39 }
40}
41impl Div for Vec2 {
42 type Output = Self;
43 fn div(self, other: Self) -> Self {
44 Self {
45 x: self.x / other.x,
46 y: self.y / other.y,
47 }
48 }
49}
50
51impl std::fmt::Display for Vec2 {
52 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
53 write!(f, "({}, {})", self.x, self.y)
54 }
55}