use crate::{BVec4, UPoint2, UPoint3, UVec4};
#[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 upoint4(x: u32, y: u32, z: u32, w: u32) -> UPoint4 {
UPoint4::new(x, y, z, w)
}
#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(transparent)]
pub struct UPoint4(pub(crate) UVec4);
impl UPoint4 {
pub const ZERO: Self = Self::splat(0);
pub const ONE: Self = Self::splat(1);
pub const X: Self = Self::new(1, 0, 0, 0);
pub const Y: Self = Self::new(0, 1, 0, 0);
pub const Z: Self = Self::new(0, 0, 1, 0);
pub const W: Self = Self::new(0, 0, 0, 1);
pub const AXES: [Self; 4] = [Self::X, Self::Y, Self::Z, Self::W];
#[inline]
pub const fn new(x: u32, y: u32, z: u32, w: u32) -> Self {
Self(UVec4::new(x, y, z, w))
}
#[inline]
pub const fn splat(v: u32) -> Self {
Self(UVec4::splat(v))
}
#[inline]
pub fn select(mask: BVec4, if_true: Self, if_false: Self) -> Self {
Self(UVec4::select(mask, if_true.0, if_false.0))
}
#[inline]
pub const fn from_array(a: [u32; 4]) -> Self {
Self::new(a[0], a[1], a[2], a[3])
}
#[inline]
pub const fn to_array(&self) -> [u32; 4] {
self.0.to_array()
}
#[inline]
pub const fn from_slice(slice: &[u32]) -> Self {
Self::new(slice[0], slice[1], slice[2], slice[3])
}
#[inline]
pub fn write_to_slice(self, slice: &mut [u32]) {
self.0.write_to_slice(slice)
}
#[inline]
pub fn truncate(self) -> UPoint3 {
use crate::swizzles::Vec4Swizzles;
self.xyz()
}
#[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) -> BVec4 {
self.0.cmpeq(rhs.0)
}
#[inline]
pub fn cmpne(self, rhs: Self) -> BVec4 {
self.0.cmpne(rhs.0)
}
#[inline]
pub fn cmpge(self, rhs: Self) -> BVec4 {
self.0.cmpge(rhs.0)
}
#[inline]
pub fn cmpgt(self, rhs: Self) -> BVec4 {
self.0.cmpgt(rhs.0)
}
#[inline]
pub fn cmple(self, rhs: Self) -> BVec4 {
self.0.cmple(rhs.0)
}
#[inline]
pub fn cmplt(self, rhs: Self) -> BVec4 {
self.0.cmplt(rhs.0)
}
#[inline]
pub fn as_point4(&self) -> crate::Point4 {
crate::Point4::new(self.x as f32, self.y as f32, self.z as f32, self.w as f32)
}
#[inline]
pub fn as_dpoint4(&self) -> crate::DPoint4 {
crate::DPoint4::new(self.x as f64, self.y as f64, self.z as f64, self.w as f64)
}
#[inline]
pub fn as_ipoint4(&self) -> crate::IPoint4 {
crate::IPoint4::new(self.x as i32, self.y as i32, self.z as i32, self.w as i32)
}
#[inline]
pub fn as_uvec4(&self) -> UVec4 {
self.0
}
#[inline]
pub fn from_uvec4(v: UVec4) -> Self {
Self(v)
}
}
impl Default for UPoint4 {
#[inline]
fn default() -> Self {
Self::ZERO
}
}
impl_op_ex_commutative!(+ |a: &UPoint4, b: &UVec4| -> UPoint4 { UPoint4(a.0 + b) });
impl_op_ex_commutative!(+ |a: &UPoint4, b: &u32| -> UPoint4 { UPoint4(a.0 + b) });
impl_op!(+= |a: &mut UPoint4, b: &UVec4| { a.0 += b });
impl_op!(-= |a: &mut UPoint4, b: &UVec4| { a.0 -= b });
impl_op!(+= |a: &mut UPoint4, b: UVec4| { a.0 += b });
impl_op!(-= |a: &mut UPoint4, b: UVec4| { a.0 -= b });
impl_op_ex!(-|a: &UPoint4, b: &UVec4| -> UPoint4 { UPoint4(a.0 - b) });
impl_op_ex!(-|a: &UPoint4, b: &u32| -> UPoint4 { UPoint4(a.0 - b) });
impl_op_ex!(-|a: &UPoint4, b: &UPoint4| -> UVec4 { a.0 - b.0 });
impl Not for UPoint4 {
type Output = Self;
#[inline]
fn not(self) -> Self::Output {
Self(self.0.not())
}
}
impl BitAnd for UPoint4 {
type Output = Self;
#[inline]
fn bitand(self, rhs: Self) -> Self::Output {
Self(self.0.bitand(rhs.0))
}
}
impl BitOr for UPoint4 {
type Output = Self;
#[inline]
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0.bitor(rhs.0))
}
}
impl BitXor for UPoint4 {
type Output = Self;
#[inline]
fn bitxor(self, rhs: Self) -> Self::Output {
Self(self.0.bitxor(rhs.0))
}
}
impl BitAnd<u32> for UPoint4 {
type Output = Self;
#[inline]
fn bitand(self, rhs: u32) -> Self::Output {
Self(self.0.bitand(rhs))
}
}
impl BitOr<u32> for UPoint4 {
type Output = Self;
#[inline]
fn bitor(self, rhs: u32) -> Self::Output {
Self(self.0.bitor(rhs))
}
}
impl BitXor<u32> for UPoint4 {
type Output = Self;
#[inline]
fn bitxor(self, rhs: u32) -> Self::Output {
Self(self.0.bitxor(rhs))
}
}
impl Shl<i8> for UPoint4 {
type Output = Self;
#[inline]
fn shl(self, rhs: i8) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<i8> for UPoint4 {
type Output = Self;
#[inline]
fn shr(self, rhs: i8) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<i16> for UPoint4 {
type Output = Self;
#[inline]
fn shl(self, rhs: i16) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<i16> for UPoint4 {
type Output = Self;
#[inline]
fn shr(self, rhs: i16) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<i32> for UPoint4 {
type Output = Self;
#[inline]
fn shl(self, rhs: i32) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<i32> for UPoint4 {
type Output = Self;
#[inline]
fn shr(self, rhs: i32) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<u8> for UPoint4 {
type Output = Self;
#[inline]
fn shl(self, rhs: u8) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<u8> for UPoint4 {
type Output = Self;
#[inline]
fn shr(self, rhs: u8) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<u16> for UPoint4 {
type Output = Self;
#[inline]
fn shl(self, rhs: u16) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<u16> for UPoint4 {
type Output = Self;
#[inline]
fn shr(self, rhs: u16) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<u32> for UPoint4 {
type Output = Self;
#[inline]
fn shl(self, rhs: u32) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<u32> for UPoint4 {
type Output = Self;
#[inline]
fn shr(self, rhs: u32) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<crate::IVec4> for UPoint4 {
type Output = Self;
#[inline]
fn shl(self, rhs: crate::IVec4) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<crate::IVec4> for UPoint4 {
type Output = Self;
#[inline]
fn shr(self, rhs: crate::IVec4) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<crate::UVec4> for UPoint4 {
type Output = Self;
#[inline]
fn shl(self, rhs: crate::UVec4) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<crate::UVec4> for UPoint4 {
type Output = Self;
#[inline]
fn shr(self, rhs: crate::UVec4) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Index<usize> for UPoint4 {
type Output = u32;
#[inline]
fn index(&self, index: usize) -> &Self::Output {
self.0.index(index)
}
}
impl IndexMut<usize> for UPoint4 {
#[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 UPoint4 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w)
}
}
#[cfg(not(target_arch = "spirv"))]
impl fmt::Debug for UPoint4 {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple(stringify!(UPoint4))
.field(&self.x)
.field(&self.y)
.field(&self.z)
.field(&self.w)
.finish()
}
}
impl From<[u32; 4]> for UPoint4 {
#[inline]
fn from(a: [u32; 4]) -> Self {
Self(UVec4::from(a))
}
}
impl From<UPoint4> for [u32; 4] {
#[inline]
fn from(v: UPoint4) -> Self {
v.0.into()
}
}
impl From<(u32, u32, u32, u32)> for UPoint4 {
#[inline]
fn from(t: (u32, u32, u32, u32)) -> Self {
Self(UVec4::from(t))
}
}
impl From<UPoint4> for (u32, u32, u32, u32) {
#[inline]
fn from(v: UPoint4) -> Self {
v.0.into()
}
}
impl From<(UPoint3, u32)> for UPoint4 {
#[inline]
fn from((v, w): (UPoint3, u32)) -> Self {
Self::new(v.x, v.y, v.z, w)
}
}
impl From<(u32, UPoint3)> for UPoint4 {
#[inline]
fn from((x, v): (u32, UPoint3)) -> Self {
Self::new(x, v.x, v.y, v.z)
}
}
impl From<(UPoint2, u32, u32)> for UPoint4 {
#[inline]
fn from((v, z, w): (UPoint2, u32, u32)) -> Self {
Self::new(v.x, v.y, z, w)
}
}
impl From<(UPoint2, UPoint2)> for UPoint4 {
#[inline]
fn from((v, u): (UPoint2, UPoint2)) -> Self {
Self::new(v.x, v.y, u.x, u.y)
}
}
impl Deref for UPoint4 {
type Target = crate::deref::Vec4<u32>;
#[inline]
fn deref(&self) -> &Self::Target {
unsafe { &*(self as *const Self).cast() }
}
}
impl DerefMut for UPoint4 {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *(self as *mut Self).cast() }
}
}
#[cfg(not(target_arch = "spirv"))]
impl AsRef<[u32; 4]> for UPoint4 {
#[inline]
fn as_ref(&self) -> &[u32; 4] {
unsafe { &*(self as *const UPoint4 as *const [u32; 4]) }
}
}
#[cfg(not(target_arch = "spirv"))]
impl AsMut<[u32; 4]> for UPoint4 {
#[inline]
fn as_mut(&mut self) -> &mut [u32; 4] {
unsafe { &mut *(self as *mut UPoint4 as *mut [u32; 4]) }
}
}