use crate::{BVec2, IPoint3, IVec2};
#[cfg(not(target_arch = "spirv"))]
use core::fmt;
use core::ops::*;
use auto_ops_det::{impl_op, impl_op_ex, impl_op_ex_commutative};
use core::ops;
#[inline]
pub const fn ipoint2(x: i32, y: i32) -> IPoint2 {
IPoint2::new(x, y)
}
#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(transparent)]
pub struct IPoint2(pub(crate) IVec2);
impl IPoint2 {
pub const ZERO: Self = Self::splat(0);
pub const ONE: Self = Self::splat(1);
pub const NEG_ONE: Self = Self::splat(-1);
pub const X: Self = Self::new(1, 0);
pub const Y: Self = Self::new(0, 1);
pub const NEG_X: Self = Self::new(-1, 0);
pub const NEG_Y: Self = Self::new(0, -1);
pub const AXES: [Self; 2] = [Self::X, Self::Y];
#[inline]
pub const fn new(x: i32, y: i32) -> Self {
Self(IVec2::new(x, y))
}
#[inline]
pub const fn splat(v: i32) -> Self {
Self(IVec2::splat(v))
}
#[inline]
pub fn select(mask: BVec2, if_true: Self, if_false: Self) -> Self {
Self(IVec2::select(mask, if_true.0, if_false.0))
}
#[inline]
pub const fn from_array(a: [i32; 2]) -> Self {
Self::new(a[0], a[1])
}
#[inline]
pub const fn to_array(&self) -> [i32; 2] {
self.0.to_array()
}
#[inline]
pub const fn from_slice(slice: &[i32]) -> Self {
Self::new(slice[0], slice[1])
}
#[inline]
pub fn write_to_slice(self, slice: &mut [i32]) {
self.0.write_to_slice(slice)
}
#[inline]
pub const fn extend(self, z: i32) -> IPoint3 {
IPoint3(self.0.extend(z))
}
#[inline]
pub fn min(self, rhs: Self) -> Self {
Self(self.0.min(rhs.0))
}
#[inline]
pub fn max(self, rhs: Self) -> Self {
Self(self.0.max(rhs.0))
}
#[inline]
pub fn clamp(self, min: Self, max: Self) -> Self {
Self(self.0.clamp(min.0, max.0))
}
#[inline]
pub fn min_element(self) -> i32 {
self.0.min_element()
}
#[inline]
pub fn max_element(self) -> i32 {
self.0.max_element()
}
#[inline]
pub fn cmpeq(self, rhs: Self) -> BVec2 {
self.0.cmpeq(rhs.0)
}
#[inline]
pub fn cmpne(self, rhs: Self) -> BVec2 {
self.0.cmpne(rhs.0)
}
#[inline]
pub fn cmpge(self, rhs: Self) -> BVec2 {
self.0.cmpge(rhs.0)
}
#[inline]
pub fn cmpgt(self, rhs: Self) -> BVec2 {
self.0.cmpgt(rhs.0)
}
#[inline]
pub fn cmple(self, rhs: Self) -> BVec2 {
self.0.cmple(rhs.0)
}
#[inline]
pub fn cmplt(self, rhs: Self) -> BVec2 {
self.0.cmplt(rhs.0)
}
#[inline]
pub fn abs(self) -> Self {
Self(self.0.abs())
}
#[inline]
pub fn signum(self) -> IVec2 {
self.0.signum()
}
#[inline]
pub fn as_point2(&self) -> crate::Point2 {
crate::Point2::new(self.x as f32, self.y as f32)
}
#[inline]
pub fn as_dpoint2(&self) -> crate::DPoint2 {
crate::DPoint2::new(self.x as f64, self.y as f64)
}
#[inline]
pub fn as_upoint2(&self) -> crate::UPoint2 {
crate::UPoint2::new(self.x as u32, self.y as u32)
}
#[inline]
pub fn as_ivec2(&self) -> IVec2 {
self.0
}
#[inline]
pub fn from_ivec2(v: IVec2) -> Self {
Self(v)
}
}
impl Default for IPoint2 {
#[inline]
fn default() -> Self {
Self::ZERO
}
}
impl_op_ex_commutative!(+ |a: &IPoint2, b: &IVec2| -> IPoint2 { IPoint2(a.0 + b) });
impl_op_ex_commutative!(+ |a: &IPoint2, b: &i32| -> IPoint2 { IPoint2(a.0 + b) });
impl_op!(+= |a: &mut IPoint2, b: &IVec2| { a.0 += b });
impl_op!(-= |a: &mut IPoint2, b: &IVec2| { a.0 -= b });
impl_op!(+= |a: &mut IPoint2, b: IVec2| { a.0 += b });
impl_op!(-= |a: &mut IPoint2, b: IVec2| { a.0 -= b });
impl_op_ex!(-|a: &IPoint2, b: &IVec2| -> IPoint2 { IPoint2(a.0 - b) });
impl_op_ex!(-|a: &IPoint2, b: &i32| -> IPoint2 { IPoint2(a.0 - b) });
impl_op_ex!(-|a: &IPoint2, b: &IPoint2| -> IVec2 { a.0 - b.0 });
impl Neg for IPoint2 {
type Output = Self;
#[inline]
fn neg(self) -> Self {
Self(self.0.neg())
}
}
impl Not for IPoint2 {
type Output = Self;
#[inline]
fn not(self) -> Self::Output {
Self(self.0.not())
}
}
impl BitAnd for IPoint2 {
type Output = Self;
#[inline]
fn bitand(self, rhs: Self) -> Self::Output {
Self(self.0.bitand(rhs.0))
}
}
impl BitOr for IPoint2 {
type Output = Self;
#[inline]
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0.bitor(rhs.0))
}
}
impl BitXor for IPoint2 {
type Output = Self;
#[inline]
fn bitxor(self, rhs: Self) -> Self::Output {
Self(self.0.bitxor(rhs.0))
}
}
impl BitAnd<i32> for IPoint2 {
type Output = Self;
#[inline]
fn bitand(self, rhs: i32) -> Self::Output {
Self(self.0.bitand(rhs))
}
}
impl BitOr<i32> for IPoint2 {
type Output = Self;
#[inline]
fn bitor(self, rhs: i32) -> Self::Output {
Self(self.0.bitor(rhs))
}
}
impl BitXor<i32> for IPoint2 {
type Output = Self;
#[inline]
fn bitxor(self, rhs: i32) -> Self::Output {
Self(self.0.bitxor(rhs))
}
}
impl Shl<i8> for IPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: i8) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<i8> for IPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: i8) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<i16> for IPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: i16) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<i16> for IPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: i16) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<i32> for IPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: i32) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<i32> for IPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: i32) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<u8> for IPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: u8) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<u8> for IPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: u8) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<u16> for IPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: u16) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<u16> for IPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: u16) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<u32> for IPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: u32) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<u32> for IPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: u32) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<crate::IVec2> for IPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: crate::IVec2) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<crate::IVec2> for IPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: crate::IVec2) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<crate::UVec2> for IPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: crate::UVec2) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<crate::UVec2> for IPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: crate::UVec2) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Index<usize> for IPoint2 {
type Output = i32;
#[inline]
fn index(&self, index: usize) -> &Self::Output {
self.0.index(index)
}
}
impl IndexMut<usize> for IPoint2 {
#[inline]
fn index_mut(&mut self, index: usize) -> &mut Self::Output {
self.0.index_mut(index)
}
}
#[cfg(not(target_arch = "spirv"))]
impl fmt::Display for IPoint2 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{}, {}]", self.x, self.y)
}
}
#[cfg(not(target_arch = "spirv"))]
impl fmt::Debug for IPoint2 {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple(stringify!(IPoint2))
.field(&self.x)
.field(&self.y)
.finish()
}
}
impl From<[i32; 2]> for IPoint2 {
#[inline]
fn from(a: [i32; 2]) -> Self {
Self(IVec2::from(a))
}
}
impl From<IPoint2> for [i32; 2] {
#[inline]
fn from(v: IPoint2) -> Self {
v.0.into()
}
}
impl From<(i32, i32)> for IPoint2 {
#[inline]
fn from(t: (i32, i32)) -> Self {
Self(IVec2::from(t))
}
}
impl From<IPoint2> for (i32, i32) {
#[inline]
fn from(v: IPoint2) -> Self {
v.0.into()
}
}
impl Deref for IPoint2 {
type Target = crate::deref::Vec2<i32>;
#[inline]
fn deref(&self) -> &Self::Target {
unsafe { &*(self as *const Self).cast() }
}
}
impl DerefMut for IPoint2 {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *(self as *mut Self).cast() }
}
}
#[cfg(not(target_arch = "spirv"))]
impl AsRef<[i32; 2]> for IPoint2 {
#[inline]
fn as_ref(&self) -> &[i32; 2] {
unsafe { &*(self as *const IPoint2 as *const [i32; 2]) }
}
}
#[cfg(not(target_arch = "spirv"))]
impl AsMut<[i32; 2]> for IPoint2 {
#[inline]
fn as_mut(&mut self) -> &mut [i32; 2] {
unsafe { &mut *(self as *mut IPoint2 as *mut [i32; 2]) }
}
}