use core::ops::{AddAssign, Mul, MulAssign, Add};
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, PartialEq, Eq, Debug, Hash)]
pub struct Point2<T> {
pub x: T,
pub y: T,
}
impl<T> AddAssign for Point2<T>
where
T: AddAssign<T>,
{
fn add_assign(&mut self, rhs: Self) {
self.x += rhs.x;
self.y += rhs.y;
}
}
impl<T> Add for Point2<T>
where
T: Add<T, Output = T>,
{
type Output = Self;
fn add(self, rhs: Self) -> Self {
Self {
x: self.x + rhs.x,
y: self.y + rhs.y,
}
}
}
impl<T> Add<&Self> for Point2<T>
where
T: Add<T, Output = T> + Clone,
{
type Output = Self;
fn add(self, rhs: &Self) -> Self {
Self {
x: self.x + rhs.x.clone(),
y: self.y + rhs.y.clone(),
}
}
}
impl<T> Add<Self> for &Point2<T>
where
T: Add<T, Output = T> + Clone,
{
type Output = Point2<T>;
fn add(self, rhs: Self) -> Point2<T> {
Point2 {
x: self.x.clone() + rhs.x.clone(),
y: self.y.clone() + rhs.y.clone(),
}
}
}
impl<T> AddAssign<&Point2<T>> for Point2<T>
where
T: AddAssign<T> + Copy,
{
fn add_assign(&mut self, rhs: &Point2<T>) {
self.x += rhs.x;
self.y += rhs.y;
}
}
impl<T> AddAssign<Vector2<T>> for Point2<T>
where
T: AddAssign<T> + Copy,
{
fn add_assign(&mut self, rhs: Vector2<T>) {
self.x += rhs.x;
self.y += rhs.y;
}
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct Size2<T> {
pub width: T,
pub height: T,
}
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
pub struct Vector2<T> {
pub x: T,
pub y: T,
}
impl<T> Mul<T> for Vector2<T>
where
T: MulAssign<T> + Copy,
{
type Output = Vector2<T>;
fn mul(mut self, rhs: T) -> Self {
self.x *= rhs;
self.y *= rhs;
self
}
}