use core::ops::{AddAssign, DivAssign, MulAssign, SubAssign}; pub trait Coordinate: Copy + Clone + PartialEq + AddAssign + MulAssign + SubAssign + DivAssign { } impl Coordinate for usize {} impl Coordinate for isize {} impl Coordinate for u8 {} impl Coordinate for i8 {} impl Coordinate for u16 {} impl Coordinate for i16 {} impl Coordinate for u32 {} impl Coordinate for i32 {} impl Coordinate for u64 {} impl Coordinate for i64 {} impl Coordinate for u128 {} impl Coordinate for i128 {} impl Coordinate for f32 {} impl Coordinate for f64 {} #[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Debug)] pub struct Vec2 { x: T, y: T, } impl Vec2 { pub const fn new(x: T, y: T) -> Self { Self { x, y } } pub fn into>(&self) -> Vec2 { Vec2::new(self.x.into(), self.y.into()) } pub const fn x(&self) -> T { self.x } pub const fn y(&self) -> T { self.y } } impl AddAssign for Vec2 { fn add_assign(&mut self, rhs: Self) { self.x += rhs.x; self.y += rhs.y; } } impl SubAssign for Vec2 { fn sub_assign(&mut self, rhs: Self) { self.x -= rhs.x; self.y -= rhs.y; } } impl MulAssign for Vec2 { fn mul_assign(&mut self, rhs: T) { self.x *= rhs; self.y *= rhs; } } impl DivAssign for Vec2 { fn div_assign(&mut self, rhs: T) { self.x /= rhs; self.y /= rhs; } } impl From> for (T, T) { fn from(value: Vec2) -> Self { (value.x, value.y) } }