use crate::{BVec3, IPoint2, IPoint4, IVec3};
#[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 ipoint3(x: i32, y: i32, z: i32) -> IPoint3 {
IPoint3::new(x, y, z)
}
#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
#[derive(Clone, Copy, PartialEq, Eq)]
#[repr(transparent)]
pub struct IPoint3(pub(crate) IVec3);
impl IPoint3 {
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, 0);
pub const Y: Self = Self::new(0, 1, 0);
pub const Z: Self = Self::new(0, 0, 1);
pub const NEG_X: Self = Self::new(-1, 0, 0);
pub const NEG_Y: Self = Self::new(0, -1, 0);
pub const NEG_Z: Self = Self::new(0, 0, -1);
pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
#[inline]
pub const fn new(x: i32, y: i32, z: i32) -> Self {
Self(IVec3::new(x, y, z))
}
#[inline]
pub const fn splat(v: i32) -> Self {
Self(IVec3::splat(v))
}
#[inline]
pub fn select(mask: BVec3, if_true: Self, if_false: Self) -> Self {
Self(IVec3::select(mask, if_true.0, if_false.0))
}
#[inline]
pub const fn from_array(a: [i32; 3]) -> Self {
Self::new(a[0], a[1], a[2])
}
#[inline]
pub const fn to_array(&self) -> [i32; 3] {
self.0.to_array()
}
#[inline]
pub const fn from_slice(slice: &[i32]) -> Self {
Self::new(slice[0], slice[1], slice[2])
}
#[inline]
pub fn write_to_slice(self, slice: &mut [i32]) {
self.0.write_to_slice(slice)
}
#[inline]
pub fn extend(self, w: i32) -> IPoint4 {
IPoint4::new(self.x, self.y, self.z, w)
}
#[inline]
pub fn truncate(self) -> IPoint2 {
use crate::swizzles::Vec3Swizzles;
self.xy()
}
#[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) -> BVec3 {
self.0.cmpeq(rhs.0)
}
#[inline]
pub fn cmpne(self, rhs: Self) -> BVec3 {
self.0.cmpne(rhs.0)
}
#[inline]
pub fn cmpge(self, rhs: Self) -> BVec3 {
self.0.cmpge(rhs.0)
}
#[inline]
pub fn cmpgt(self, rhs: Self) -> BVec3 {
self.0.cmpgt(rhs.0)
}
#[inline]
pub fn cmple(self, rhs: Self) -> BVec3 {
self.0.cmple(rhs.0)
}
#[inline]
pub fn cmplt(self, rhs: Self) -> BVec3 {
self.0.cmplt(rhs.0)
}
#[inline]
pub fn abs(self) -> Self {
Self(self.0.abs())
}
#[inline]
pub fn signum(self) -> IVec3 {
self.0.signum()
}
#[inline]
pub fn as_point3(&self) -> crate::Point3 {
crate::Point3::new(self.x as f32, self.y as f32, self.z as f32)
}
#[inline]
pub fn as_point3a(&self) -> crate::Point3A {
crate::Point3A::new(self.x as f32, self.y as f32, self.z as f32)
}
#[inline]
pub fn as_dpoint3(&self) -> crate::DPoint3 {
crate::DPoint3::new(self.x as f64, self.y as f64, self.z as f64)
}
#[inline]
pub fn as_upoint3(&self) -> crate::UPoint3 {
crate::UPoint3::new(self.x as u32, self.y as u32, self.z as u32)
}
#[inline]
pub fn as_ivec3(&self) -> IVec3 {
self.0
}
#[inline]
pub fn from_ivec3(v: IVec3) -> Self {
Self(v)
}
}
impl Default for IPoint3 {
#[inline]
fn default() -> Self {
Self::ZERO
}
}
impl_op_ex_commutative!(+ |a: &IPoint3, b: &IVec3| -> IPoint3 { IPoint3(a.0 + b) });
impl_op_ex_commutative!(+ |a: &IPoint3, b: &i32| -> IPoint3 { IPoint3(a.0 + b) });
impl_op!(+= |a: &mut IPoint3, b: &IVec3| { a.0 += b });
impl_op!(-= |a: &mut IPoint3, b: &IVec3| { a.0 -= b });
impl_op!(+= |a: &mut IPoint3, b: IVec3| { a.0 += b });
impl_op!(-= |a: &mut IPoint3, b: IVec3| { a.0 -= b });
impl_op_ex!(-|a: &IPoint3, b: &IVec3| -> IPoint3 { IPoint3(a.0 - b) });
impl_op_ex!(-|a: &IPoint3, b: &i32| -> IPoint3 { IPoint3(a.0 - b) });
impl_op_ex!(-|a: &IPoint3, b: &IPoint3| -> IVec3 { a.0 - b.0 });
impl Neg for IPoint3 {
type Output = Self;
#[inline]
fn neg(self) -> Self {
Self(self.0.neg())
}
}
impl Not for IPoint3 {
type Output = Self;
#[inline]
fn not(self) -> Self::Output {
Self(self.0.not())
}
}
impl BitAnd for IPoint3 {
type Output = Self;
#[inline]
fn bitand(self, rhs: Self) -> Self::Output {
Self(self.0.bitand(rhs.0))
}
}
impl BitOr for IPoint3 {
type Output = Self;
#[inline]
fn bitor(self, rhs: Self) -> Self::Output {
Self(self.0.bitor(rhs.0))
}
}
impl BitXor for IPoint3 {
type Output = Self;
#[inline]
fn bitxor(self, rhs: Self) -> Self::Output {
Self(self.0.bitxor(rhs.0))
}
}
impl BitAnd<i32> for IPoint3 {
type Output = Self;
#[inline]
fn bitand(self, rhs: i32) -> Self::Output {
Self(self.0.bitand(rhs))
}
}
impl BitOr<i32> for IPoint3 {
type Output = Self;
#[inline]
fn bitor(self, rhs: i32) -> Self::Output {
Self(self.0.bitor(rhs))
}
}
impl BitXor<i32> for IPoint3 {
type Output = Self;
#[inline]
fn bitxor(self, rhs: i32) -> Self::Output {
Self(self.0.bitxor(rhs))
}
}
impl Shl<i8> for IPoint3 {
type Output = Self;
#[inline]
fn shl(self, rhs: i8) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<i8> for IPoint3 {
type Output = Self;
#[inline]
fn shr(self, rhs: i8) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<i16> for IPoint3 {
type Output = Self;
#[inline]
fn shl(self, rhs: i16) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<i16> for IPoint3 {
type Output = Self;
#[inline]
fn shr(self, rhs: i16) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<i32> for IPoint3 {
type Output = Self;
#[inline]
fn shl(self, rhs: i32) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<i32> for IPoint3 {
type Output = Self;
#[inline]
fn shr(self, rhs: i32) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<u8> for IPoint3 {
type Output = Self;
#[inline]
fn shl(self, rhs: u8) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<u8> for IPoint3 {
type Output = Self;
#[inline]
fn shr(self, rhs: u8) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<u16> for IPoint3 {
type Output = Self;
#[inline]
fn shl(self, rhs: u16) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<u16> for IPoint3 {
type Output = Self;
#[inline]
fn shr(self, rhs: u16) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<u32> for IPoint3 {
type Output = Self;
#[inline]
fn shl(self, rhs: u32) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<u32> for IPoint3 {
type Output = Self;
#[inline]
fn shr(self, rhs: u32) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<crate::IVec3> for IPoint3 {
type Output = Self;
#[inline]
fn shl(self, rhs: crate::IVec3) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<crate::IVec3> for IPoint3 {
type Output = Self;
#[inline]
fn shr(self, rhs: crate::IVec3) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Shl<crate::UVec3> for IPoint3 {
type Output = Self;
#[inline]
fn shl(self, rhs: crate::UVec3) -> Self::Output {
Self(self.0.shl(rhs))
}
}
impl Shr<crate::UVec3> for IPoint3 {
type Output = Self;
#[inline]
fn shr(self, rhs: crate::UVec3) -> Self::Output {
Self(self.0.shr(rhs))
}
}
impl Index<usize> for IPoint3 {
type Output = i32;
#[inline]
fn index(&self, index: usize) -> &Self::Output {
self.0.index(index)
}
}
impl IndexMut<usize> for IPoint3 {
#[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 IPoint3 {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
}
}
#[cfg(not(target_arch = "spirv"))]
impl fmt::Debug for IPoint3 {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple(stringify!(IPoint3))
.field(&self.x)
.field(&self.y)
.field(&self.z)
.finish()
}
}
impl From<[i32; 3]> for IPoint3 {
#[inline]
fn from(a: [i32; 3]) -> Self {
Self(IVec3::from(a))
}
}
impl From<IPoint3> for [i32; 3] {
#[inline]
fn from(v: IPoint3) -> Self {
v.0.into()
}
}
impl From<(i32, i32, i32)> for IPoint3 {
#[inline]
fn from(t: (i32, i32, i32)) -> Self {
Self(IVec3::from(t))
}
}
impl From<IPoint3> for (i32, i32, i32) {
#[inline]
fn from(v: IPoint3) -> Self {
v.0.into()
}
}
impl From<(IPoint2, i32)> for IPoint3 {
#[inline]
fn from((v, z): (IPoint2, i32)) -> Self {
Self::new(v.x, v.y, z)
}
}
impl Deref for IPoint3 {
type Target = crate::deref::Vec3<i32>;
#[inline]
fn deref(&self) -> &Self::Target {
unsafe { &*(self as *const Self).cast() }
}
}
impl DerefMut for IPoint3 {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *(self as *mut Self).cast() }
}
}
#[cfg(not(target_arch = "spirv"))]
impl AsRef<[i32; 3]> for IPoint3 {
#[inline]
fn as_ref(&self) -> &[i32; 3] {
unsafe { &*(self as *const IPoint3 as *const [i32; 3]) }
}
}
#[cfg(not(target_arch = "spirv"))]
impl AsMut<[i32; 3]> for IPoint3 {
#[inline]
fn as_mut(&mut self) -> &mut [i32; 3] {
unsafe { &mut *(self as *mut IPoint3 as *mut [i32; 3]) }
}
}