use std::{cmp::Ord, ops::*};
#[derive(Copy, Clone, Eq, PartialEq, Default, Hash, Debug)]
pub struct Vecc<T> {
#[allow(missing_docs)]
pub x: T,
#[allow(missing_docs)]
pub y: T,
}
impl<T> Vecc<T> {
pub fn new(x: T, y: T) -> Self {
Self { x, y }
}
pub fn dot(self, rhs: Vecc<T>) -> T
where
T: Add<Output = T> + Mul<Output = T> + Copy,
{
self.x * rhs.x + self.y * rhs.y
}
pub fn cross(self, rhs: Vecc<T>) -> T
where
T: Sub<Output = T> + Mul<Output = T> + Copy,
{
self.x * rhs.y - self.y * rhs.x
}
}
pub auto trait Notf64 {}
impl !Notf64 for f64 {}
impl<T> Vecc<T>
where
T: Ord + Notf64,
{
pub fn min(self, rhs: Vecc<T>) -> Vecc<T> {
Self {
x: self.x.min(rhs.x),
y: self.y.min(rhs.y),
}
}
pub fn max(self, rhs: Vecc<T>) -> Vecc<T> {
Self {
x: self.x.max(rhs.x),
y: self.y.max(rhs.y),
}
}
pub fn clamp(self, min: Vecc<T>, max: Vecc<T>) -> Vecc<T> {
Self {
x: self.x.clamp(min.x, max.x),
y: self.y.clamp(min.y, max.y),
}
}
}
impl<T> From<(T, T)> for Vecc<T> {
fn from((x, y): (T, T)) -> Self {
Self { x, y }
}
}
#[allow(clippy::from_over_into)]
impl<T> Into<(T, T)> for Vecc<T> {
fn into(self) -> (T, T) {
(self.x, self.y)
}
}
pub auto trait Different {}
impl<T> !Different for (T, T) {}
impl<T, U> From<Vecc<U>> for Vecc<T>
where
T: From<U>,
(T, U): Different,
{
fn from(other: Vecc<U>) -> Vecc<T> {
Vecc {
x: From::from(other.x),
y: From::from(other.y),
}
}
}
impl<T, U> Neg for Vecc<T>
where
T: Neg<Output = U>,
{
type Output = Vecc<U>;
fn neg(self) -> Self::Output {
Vecc {
x: self.x.neg(),
y: self.y.neg(),
}
}
}
impl<T, U> Neg for &Vecc<T>
where
T: Neg<Output = U> + Copy,
{
type Output = Vecc<U>;
fn neg(self) -> Self::Output {
Vecc {
x: self.x.neg(),
y: self.y.neg(),
}
}
}
impl<T, U> Not for Vecc<T>
where
T: Not<Output = U>,
{
type Output = Vecc<U>;
fn not(self) -> Self::Output {
Vecc {
x: self.x.not(),
y: self.y.not(),
}
}
}
impl<T, U> Not for &Vecc<T>
where
T: Not<Output = U> + Copy,
{
type Output = Vecc<U>;
fn not(self) -> Self::Output {
Vecc {
x: self.x.not(),
y: self.y.not(),
}
}
}
impl<T> Add<Vecc<T>> for Vecc<T>
where
T: Add<Output = T>,
{
type Output = Vecc<T>;
fn add(self, rhs: Vecc<T>) -> Self::Output {
Vecc {
x: self.x.add(rhs.x),
y: self.y.add(rhs.y),
}
}
}
impl<T> Add<&Vecc<T>> for Vecc<T>
where
T: Add<Output = T> + Copy,
{
type Output = Vecc<T>;
fn add(self, rhs: &Vecc<T>) -> Self::Output {
Vecc {
x: self.x.add(rhs.x),
y: self.y.add(rhs.y),
}
}
}
impl<T> Add<Vecc<T>> for &Vecc<T>
where
T: Add<Output = T> + Copy,
{
type Output = Vecc<T>;
fn add(self, rhs: Vecc<T>) -> Self::Output {
Vecc {
x: self.x.add(rhs.x),
y: self.y.add(rhs.y),
}
}
}
impl<T> Add<&Vecc<T>> for &Vecc<T>
where
T: Add<Output = T> + Copy,
{
type Output = Vecc<T>;
fn add(self, rhs: &Vecc<T>) -> Self::Output {
Vecc {
x: self.x.add(rhs.x),
y: self.y.add(rhs.y),
}
}
}
impl<T> Sub<Vecc<T>> for Vecc<T>
where
T: Sub<Output = T>,
{
type Output = Vecc<T>;
fn sub(self, rhs: Vecc<T>) -> Self::Output {
Vecc {
x: self.x.sub(rhs.x),
y: self.y.sub(rhs.y),
}
}
}
impl<T> Sub<&Vecc<T>> for Vecc<T>
where
T: Sub<Output = T> + Copy,
{
type Output = Vecc<T>;
fn sub(self, rhs: &Vecc<T>) -> Self::Output {
Vecc {
x: self.x.sub(rhs.x),
y: self.y.sub(rhs.y),
}
}
}
impl<T> Sub<Vecc<T>> for &Vecc<T>
where
T: Sub<Output = T> + Copy,
{
type Output = Vecc<T>;
fn sub(self, rhs: Vecc<T>) -> Self::Output {
Vecc {
x: self.x.sub(rhs.x),
y: self.y.sub(rhs.y),
}
}
}
impl<T> Sub<&Vecc<T>> for &Vecc<T>
where
T: Sub<Output = T> + Copy,
{
type Output = Vecc<T>;
fn sub(self, rhs: &Vecc<T>) -> Self::Output {
Vecc {
x: self.x.sub(rhs.x),
y: self.y.sub(rhs.y),
}
}
}
impl<T> Mul<T> for Vecc<T>
where
T: Mul<Output = T> + Copy,
{
type Output = Vecc<T>;
fn mul(self, rhs: T) -> Self::Output {
Vecc {
x: self.x.mul(rhs),
y: self.y.mul(rhs),
}
}
}
impl<T> Mul<&T> for Vecc<T>
where
T: Mul<Output = T> + Copy,
{
type Output = Vecc<T>;
fn mul(self, rhs: &T) -> Self::Output {
Vecc {
x: self.x.mul(*rhs),
y: self.y.mul(*rhs),
}
}
}
impl<T> Mul<T> for &Vecc<T>
where
T: Mul<Output = T> + Copy,
{
type Output = Vecc<T>;
fn mul(self, rhs: T) -> Self::Output {
Vecc {
x: self.x.mul(rhs),
y: self.y.mul(rhs),
}
}
}
impl<T> Mul<&T> for &Vecc<T>
where
T: Mul<Output = T> + Copy,
{
type Output = Vecc<T>;
fn mul(self, rhs: &T) -> Self::Output {
Vecc {
x: self.x.mul(*rhs),
y: self.y.mul(*rhs),
}
}
}
impl<T> Div<T> for Vecc<T>
where
T: Div<Output = T> + Copy,
{
type Output = Vecc<T>;
fn div(self, rhs: T) -> Self::Output {
Vecc {
x: self.x.div(rhs),
y: self.y.div(rhs),
}
}
}
impl<T> Div<&T> for Vecc<T>
where
T: Div<Output = T> + Copy,
{
type Output = Vecc<T>;
fn div(self, rhs: &T) -> Self::Output {
Vecc {
x: self.x.div(*rhs),
y: self.y.div(*rhs),
}
}
}
impl<T> Div<T> for &Vecc<T>
where
T: Div<Output = T> + Copy,
{
type Output = Vecc<T>;
fn div(self, rhs: T) -> Self::Output {
Vecc {
x: self.x.div(rhs),
y: self.y.div(rhs),
}
}
}
impl<T> Div<&T> for &Vecc<T>
where
T: Div<Output = T> + Copy,
{
type Output = Vecc<T>;
fn div(self, rhs: &T) -> Self::Output {
Vecc {
x: self.x.div(*rhs),
y: self.y.div(*rhs),
}
}
}
impl<T> Rem<Vecc<T>> for Vecc<T>
where
T: Rem<Output = T> + Notf64,
{
type Output = Vecc<T>;
fn rem(self, rhs: Vecc<T>) -> Self::Output {
Vecc {
x: self.x.rem(rhs.x),
y: self.y.rem(rhs.y),
}
}
}
impl<T> Rem<&Vecc<T>> for Vecc<T>
where
T: Rem<Output = T> + Copy + Notf64,
{
type Output = Vecc<T>;
fn rem(self, rhs: &Vecc<T>) -> Self::Output {
Vecc {
x: self.x.rem(rhs.x),
y: self.y.rem(rhs.y),
}
}
}
impl<T> Rem<Vecc<T>> for &Vecc<T>
where
T: Rem<Output = T> + Copy + Notf64,
{
type Output = Vecc<T>;
fn rem(self, rhs: Vecc<T>) -> Self::Output {
Vecc {
x: self.x.rem(rhs.x),
y: self.y.rem(rhs.y),
}
}
}
impl<T> Rem<&Vecc<T>> for &Vecc<T>
where
T: Rem<Output = T> + Copy + Notf64,
{
type Output = Vecc<T>;
fn rem(self, rhs: &Vecc<T>) -> Self::Output {
Vecc {
x: self.x.rem(rhs.x),
y: self.y.rem(rhs.y),
}
}
}
impl<T> Rem<T> for Vecc<T>
where
T: Rem<Output = T> + Copy + Notf64,
{
type Output = Vecc<T>;
fn rem(self, rhs: T) -> Self::Output {
Vecc {
x: self.x.rem(rhs),
y: self.y.rem(rhs),
}
}
}
impl<T> Rem<&T> for Vecc<T>
where
T: Rem<Output = T> + Copy + Notf64,
{
type Output = Vecc<T>;
fn rem(self, rhs: &T) -> Self::Output {
Vecc {
x: self.x.rem(*rhs),
y: self.y.rem(*rhs),
}
}
}
impl<T> Rem<T> for &Vecc<T>
where
T: Rem<Output = T> + Copy + Notf64,
{
type Output = Vecc<T>;
fn rem(self, rhs: T) -> Self::Output {
Vecc {
x: self.x.rem(rhs),
y: self.y.rem(rhs),
}
}
}
impl<T> Rem<&T> for &Vecc<T>
where
T: Rem<Output = T> + Copy + Notf64,
{
type Output = Vecc<T>;
fn rem(self, rhs: &T) -> Self::Output {
Vecc {
x: self.x.rem(*rhs),
y: self.y.rem(*rhs),
}
}
}
impl<T> AddAssign<Vecc<T>> for Vecc<T>
where
T: AddAssign<T>,
{
fn add_assign(&mut self, other: Vecc<T>) {
self.x.add_assign(other.x);
self.y.add_assign(other.y);
}
}
impl<T> AddAssign<&Vecc<T>> for Vecc<T>
where
T: AddAssign<T> + Copy,
{
fn add_assign(&mut self, other: &Vecc<T>) {
self.x.add_assign(other.x);
self.y.add_assign(other.y);
}
}
impl<T> SubAssign<Vecc<T>> for Vecc<T>
where
T: SubAssign<T>,
{
fn sub_assign(&mut self, rhs: Vecc<T>) {
self.x.sub_assign(rhs.x);
self.y.sub_assign(rhs.y);
}
}
impl<T> SubAssign<&Vecc<T>> for Vecc<T>
where
T: SubAssign<T> + Copy,
{
fn sub_assign(&mut self, rhs: &Vecc<T>) {
self.x.sub_assign(rhs.x);
self.y.sub_assign(rhs.y);
}
}
impl<T> MulAssign<T> for Vecc<T>
where
T: MulAssign<T> + Copy,
{
fn mul_assign(&mut self, rhs: T) {
self.x.mul_assign(rhs);
self.y.mul_assign(rhs);
}
}
impl<T> MulAssign<&T> for Vecc<T>
where
T: MulAssign<T> + Copy,
{
fn mul_assign(&mut self, rhs: &T) {
self.x.mul_assign(*rhs);
self.y.mul_assign(*rhs);
}
}
impl<T> DivAssign<T> for Vecc<T>
where
T: DivAssign<T> + Copy,
{
fn div_assign(&mut self, rhs: T) {
self.x.div_assign(rhs);
self.y.div_assign(rhs);
}
}
impl<T> DivAssign<&T> for Vecc<T>
where
T: DivAssign<T> + Copy,
{
fn div_assign(&mut self, rhs: &T) {
self.x.div_assign(*rhs);
self.y.div_assign(*rhs);
}
}
impl<T> RemAssign<Vecc<T>> for Vecc<T>
where
T: RemAssign<T> + Notf64,
{
fn rem_assign(&mut self, rhs: Vecc<T>) {
self.x.rem_assign(rhs.x);
self.y.rem_assign(rhs.y);
}
}
impl<T> RemAssign<&Vecc<T>> for Vecc<T>
where
T: RemAssign<T> + Copy + Notf64,
{
fn rem_assign(&mut self, rhs: &Vecc<T>) {
self.x.rem_assign(rhs.x);
self.y.rem_assign(rhs.y);
}
}
impl<T> RemAssign<T> for Vecc<T>
where
T: RemAssign<T> + Copy + Notf64,
{
fn rem_assign(&mut self, rhs: T) {
self.x.rem_assign(rhs);
self.y.rem_assign(rhs);
}
}
impl<T> RemAssign<&T> for Vecc<T>
where
T: RemAssign<T> + Copy + Notf64,
{
fn rem_assign(&mut self, rhs: &T) {
self.x.rem_assign(*rhs);
self.y.rem_assign(*rhs);
}
}