use std::ops::{Index, IndexMut, AddAssign, SubAssign, MulAssign, DivAssign, Add, Sub, Mul, Div};
use std::fmt::{Debug, Formatter, Result};
pub struct USize2 {
pub x: usize,
pub y: usize,
}
impl USize2 {
pub fn new_default() -> USize2 {
return USize2 {
x: 0,
y: 0,
};
}
pub fn new(x_: usize, y_: usize) -> USize2 {
return USize2 {
x: x_,
y: y_,
};
}
pub fn new_lst(lst: [usize; 2]) -> USize2 {
return USize2 {
x: lst[0],
y: lst[1],
};
}
}
impl USize2 {
pub fn set_scalar(&mut self, s: usize) {
self.x = s;
self.y = s;
}
pub fn set_scalar2(&mut self, x: usize, y: usize) {
self.x = x;
self.y = y;
}
pub fn set_lst(&mut self, lst: [usize; 2]) {
self.x = lst[0];
self.y = lst[1];
}
pub fn set_self(&mut self, pt: USize2) {
self.x = pt.x;
self.y = pt.y;
}
pub fn set_zero(&mut self) {
self.x = 0;
self.y = 0;
}
}
impl USize2 {
pub fn add_scalar(&self, v: usize) -> USize2 {
return USize2::new(self.x + v, self.y + v);
}
pub fn add_vec(&self, v: USize2) -> USize2 {
return USize2::new(self.x + v.x, self.y + v.y);
}
pub fn sub_scalar(&self, v: usize) -> USize2 {
return USize2::new(self.x - v, self.y - v);
}
pub fn sub_vec(&self, v: USize2) -> USize2 {
return USize2::new(self.x - v.x, self.y - v.y);
}
pub fn mul_scalar(&self, v: usize) -> USize2 {
return USize2::new(self.x * v, self.y * v);
}
pub fn mul_vec(&self, v: USize2) -> USize2 {
return USize2::new(self.x * v.x, self.y * v.y);
}
pub fn div_scalar(&self, v: usize) -> USize2 {
return USize2::new(self.x / v, self.y / v);
}
pub fn div_vec(&self, v: USize2) -> USize2 {
return USize2::new(self.x / v.x, self.y / v.y);
}
}
impl USize2 {
pub fn rsub_scalar(&self, v: usize) -> USize2 {
return USize2::new(v - self.x, v - self.y);
}
pub fn rsub_vec(&self, v: USize2) -> USize2 {
return USize2::new(v.x - self.x, v.y - self.y);
}
pub fn rdiv_scalar(&self, v: usize) -> USize2 {
return USize2::new(v / self.x, v / self.y);
}
pub fn rdiv_vec(&self, v: USize2) -> USize2 {
return USize2::new(v.x / self.x, v.y / self.y);
}
}
impl USize2 {
pub fn iadd_scalar(&mut self, v: usize) {
self.x = usize::add(self.x, v);
self.y = usize::add(self.y, v);
}
pub fn iadd_vec(&mut self, v: USize2) {
self.x = usize::add(self.x, v.x);
self.y = usize::add(self.y, v.y);
}
pub fn isub_scalar(&mut self, v: usize) {
self.x = usize::sub(self.x, v);
self.y = usize::sub(self.y, v);
}
pub fn isub_vec(&mut self, v: USize2) {
self.x = usize::sub(self.x, v.x);
self.y = usize::sub(self.y, v.y);
}
pub fn imul_scalar(&mut self, v: usize) {
self.x = usize::mul(self.x, v);
self.y = usize::mul(self.y, v);
}
pub fn imul_vec(&mut self, v: USize2) {
self.x = usize::mul(self.x, v.x);
self.y = usize::mul(self.y, v.y);
}
pub fn idiv_scalar(&mut self, v: usize) {
self.x = usize::div(self.x, v);
self.y = usize::div(self.y, v);
}
pub fn idiv_vec(&mut self, v: USize2) {
self.x = usize::div(self.x, v.x);
self.y = usize::div(self.y, v.y);
}
}
impl USize2 {
pub fn at(&self, i: usize) -> &usize {
match i {
0 => return &self.x,
1 => return &self.y,
_ => { panic!() }
}
}
pub fn at_mut(&mut self, i: usize) -> &mut usize {
match i {
0 => return &mut self.x,
1 => return &mut self.y,
_ => { panic!() }
}
}
pub fn sum(&self) -> usize {
return self.x + self.y;
}
pub fn min(&self) -> usize {
return self.x.min(self.y);
}
pub fn max(&self) -> usize {
return self.x.max(self.y);
}
pub fn dominant_axis(&self) -> usize {
match self.x > self.y {
true => 0,
false => 1
}
}
pub fn subminant_axis(&self) -> usize {
match self.x < self.y {
true => 0,
false => 1
}
}
pub fn is_equal(&self, other: &USize2) -> bool {
return self.x == other.x && self.y == other.y;
}
}
impl Clone for USize2 {
fn clone(&self) -> Self {
return USize2 {
x: self.x,
y: self.y,
};
}
}
impl Copy for USize2 {}
impl Index<usize> for USize2 {
type Output = usize;
fn index(&self, index: usize) -> &Self::Output {
return self.at(index);
}
}
impl IndexMut<usize> for USize2 {
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
return self.at_mut(index);
}
}
impl AddAssign<usize> for USize2 {
fn add_assign(&mut self, rhs: usize) {
self.iadd_scalar(rhs);
}
}
impl AddAssign for USize2 {
fn add_assign(&mut self, rhs: Self) {
self.iadd_vec(rhs);
}
}
impl SubAssign<usize> for USize2 {
fn sub_assign(&mut self, rhs: usize) {
self.isub_scalar(rhs);
}
}
impl SubAssign for USize2 {
fn sub_assign(&mut self, rhs: Self) {
self.isub_vec(rhs);
}
}
impl MulAssign<usize> for USize2 {
fn mul_assign(&mut self, rhs: usize) {
self.imul_scalar(rhs);
}
}
impl MulAssign for USize2 {
fn mul_assign(&mut self, rhs: Self) {
self.imul_vec(rhs);
}
}
impl DivAssign<usize> for USize2 {
fn div_assign(&mut self, rhs: usize) {
self.idiv_scalar(rhs);
}
}
impl DivAssign for USize2 {
fn div_assign(&mut self, rhs: Self) {
self.idiv_vec(rhs);
}
}
impl PartialEq for USize2 {
fn eq(&self, other: &Self) -> bool {
return self.is_equal(other);
}
}
impl Eq for USize2 {}
impl Add<usize> for USize2 {
type Output = USize2;
fn add(self, rhs: usize) -> Self::Output {
return self.add_scalar(rhs);
}
}
impl Add for USize2 {
type Output = USize2;
fn add(self, rhs: Self) -> Self::Output {
return self.add_vec(rhs);
}
}
impl Sub<usize> for USize2 {
type Output = USize2;
fn sub(self, rhs: usize) -> Self::Output {
return self.sub_scalar(rhs);
}
}
impl Sub for USize2 {
type Output = USize2;
fn sub(self, rhs: Self) -> Self::Output {
return self.sub_vec(rhs);
}
}
impl Mul<usize> for USize2 {
type Output = USize2;
fn mul(self, rhs: usize) -> Self::Output {
return self.mul_scalar(rhs);
}
}
impl Mul for USize2 {
type Output = USize2;
fn mul(self, rhs: Self) -> Self::Output {
return self.mul_vec(rhs);
}
}
impl Div<usize> for USize2 {
type Output = USize2;
fn div(self, rhs: usize) -> Self::Output {
return self.div_scalar(rhs);
}
}
impl Div for USize2 {
type Output = USize2;
fn div(self, rhs: Self) -> Self::Output {
return self.div_vec(rhs);
}
}
impl Debug for USize2 {
fn fmt(&self, f: &mut Formatter<'_>) -> Result {
f.debug_tuple("")
.field(&self.x)
.field(&self.y)
.finish()
}
}
pub fn min(a: &USize2, b: &USize2) -> USize2 {
return USize2::new(usize::min(a.x, b.x), usize::min(a.y, b.y));
}
pub fn max(a: &USize2, b: &USize2) -> USize2 {
return USize2::new(usize::max(a.x, b.x), usize::max(a.y, b.y));
}
pub fn clamp(v: &USize2, low: &USize2, high: &USize2) -> USize2 {
return USize2::new(usize::clamp(v.x, low.x, high.x),
usize::clamp(v.y, low.y, high.y));
}