use crate::{BVec2, UPoint3, UVec2};
#[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 upoint2(x: u32, y: u32) -> UPoint2 {
UPoint2::new(x, y)
}
#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(transparent)]
pub struct UPoint2(pub(crate) UVec2);
impl UPoint2 {
pub const ZERO: Self = Self::splat(0);
pub const ONE: Self = Self::splat(1);
pub const X: Self = Self::new(1, 0);
pub const Y: Self = Self::new(0, 1);
pub const AXES: [Self; 2] = [Self::X, Self::Y];
#[inline]
pub const fn new(x: u32, y: u32) -> Self {
Self(UVec2::new(x, y))
}
#[inline]
pub const fn splat(v: u32) -> Self {
Self(UVec2::splat(v))
}
#[inline]
pub fn select(mask: BVec2, if_true: Self, if_false: Self) -> Self {
Self(UVec2::select(mask, if_true.0, if_false.0))
}
#[inline]
pub const fn from_array(a: [u32; 2]) -> Self {
Self::new(a[0], a[1])
}
#[inline]
pub const fn to_array(&self) -> [u32; 2] {
self.0.to_array()
}
#[inline]
pub const fn from_slice(slice: &[u32]) -> Self {
Self::new(slice[0], slice[1])
}
#[inline]
pub fn write_to_slice(self, slice: &mut [u32]) {
self.0.write_to_slice(slice)
}
#[inline]
pub const fn extend(self, z: u32) -> UPoint3 {
UPoint3(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) -> u32 {
self.0.min_element()
}
#[inline]
pub fn max_element(self) -> u32 {
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 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_ipoint2(&self) -> crate::IPoint2 {
crate::IPoint2::new(self.x as i32, self.y as i32)
}
#[inline]
pub fn as_uvec2(&self) -> UVec2 {
self.0
}
#[inline]
pub fn from_uvec2(v: UVec2) -> Self {
Self(v)
}
}
impl Default for UPoint2 {
#[inline]
fn default() -> Self {
Self::ZERO
}
}
impl_op_ex_commutative!(+ |a: &UPoint2, b: &UVec2| -> UPoint2 { UPoint2(a.0 + b) });
impl_op_ex_commutative!(+ |a: &UPoint2, b: &u32| -> UPoint2 { UPoint2(a.0 + b) });
impl_op!(+= |a: &mut UPoint2, b: &UVec2| { a.0 += b });
impl_op!(-= |a: &mut UPoint2, b: &UVec2| { a.0 -= b });
impl_op!(+= |a: &mut UPoint2, b: UVec2| { a.0 += b });
impl_op!(-= |a: &mut UPoint2, b: UVec2| { a.0 -= b });
impl_op_ex!(-|a: &UPoint2, b: &UVec2| -> UPoint2 { UPoint2(a.0 - b) });
impl_op_ex!(-|a: &UPoint2, b: &u32| -> UPoint2 { UPoint2(a.0 - b) });
impl_op_ex!(-|a: &UPoint2, b: &UPoint2| -> UVec2 { a.0 - b.0 });
impl Not for UPoint2 {
type Output = Self;
#[inline]
fn not(self) -> Self::Output {
Self(self.0.not())
}
}
impl BitAnd for UPoint2 {
type Output = Self;
#[inline]
fn bitand(self, rhs: Self) -> Self::Output {
Self(self.0.bitand(rhs.0))
}
}
impl BitOr for UPoint2 {
type Output = Self;
#[inline]
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0.bitor(rhs.0))
}
}
impl BitXor for UPoint2 {
type Output = Self;
#[inline]
fn bitxor(self, rhs: Self) -> Self::Output {
Self(self.0.bitxor(rhs.0))
}
}
impl BitAnd<u32> for UPoint2 {
type Output = Self;
#[inline]
fn bitand(self, rhs: u32) -> Self::Output {
Self(self.0.bitand(rhs))
}
}
impl BitOr<u32> for UPoint2 {
type Output = Self;
#[inline]
fn bitor(self, rhs: u32) -> Self::Output {
Self(self.0.bitor(rhs))
}
}
impl BitXor<u32> for UPoint2 {
type Output = Self;
#[inline]
fn bitxor(self, rhs: u32) -> Self::Output {
Self(self.0.bitxor(rhs))
}
}
impl Shl<i8> for UPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: i8) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<i8> for UPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: i8) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<i16> for UPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: i16) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<i16> for UPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: i16) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<i32> for UPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: i32) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<i32> for UPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: i32) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<u8> for UPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: u8) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<u8> for UPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: u8) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<u16> for UPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: u16) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<u16> for UPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: u16) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<u32> for UPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: u32) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<u32> for UPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: u32) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<crate::IVec2> for UPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: crate::IVec2) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<crate::IVec2> for UPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: crate::IVec2) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<crate::UVec2> for UPoint2 {
type Output = Self;
#[inline]
fn shl(self, rhs: crate::UVec2) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<crate::UVec2> for UPoint2 {
type Output = Self;
#[inline]
fn shr(self, rhs: crate::UVec2) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Index<usize> for UPoint2 {
type Output = u32;
#[inline]
fn index(&self, index: usize) -> &Self::Output {
self.0.index(index)
}
}
impl IndexMut<usize> for UPoint2 {
#[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 UPoint2 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{}, {}]", self.x, self.y)
}
}
#[cfg(not(target_arch = "spirv"))]
impl fmt::Debug for UPoint2 {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple(stringify!(UPoint2))
.field(&self.x)
.field(&self.y)
.finish()
}
}
impl From<[u32; 2]> for UPoint2 {
#[inline]
fn from(a: [u32; 2]) -> Self {
Self(UVec2::from(a))
}
}
impl From<UPoint2> for [u32; 2] {
#[inline]
fn from(v: UPoint2) -> Self {
v.0.into()
}
}
impl From<(u32, u32)> for UPoint2 {
#[inline]
fn from(t: (u32, u32)) -> Self {
Self(UVec2::from(t))
}
}
impl From<UPoint2> for (u32, u32) {
#[inline]
fn from(v: UPoint2) -> Self {
v.0.into()
}
}
impl Deref for UPoint2 {
type Target = crate::deref::Vec2<u32>;
#[inline]
fn deref(&self) -> &Self::Target {
unsafe { &*(self as *const Self).cast() }
}
}
impl DerefMut for UPoint2 {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *(self as *mut Self).cast() }
}
}
#[cfg(not(target_arch = "spirv"))]
impl AsRef<[u32; 2]> for UPoint2 {
#[inline]
fn as_ref(&self) -> &[u32; 2] {
unsafe { &*(self as *const UPoint2 as *const [u32; 2]) }
}
}
#[cfg(not(target_arch = "spirv"))]
impl AsMut<[u32; 2]> for UPoint2 {
#[inline]
fn as_mut(&mut self) -> &mut [u32; 2] {
unsafe { &mut *(self as *mut UPoint2 as *mut [u32; 2]) }
}
}