use crate::nums::*;
use crate::{BVec4x4, Point2x4, Point3x4, Vec4x4};
use crate::Point4;
#[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 point4x4(x: f32x4, y: f32x4, z: f32x4, w: f32x4) -> Point4x4 {
Point4x4::new(x, y, z, w)
}
#[derive(Clone, Copy, PartialEq)]
#[repr(transparent)]
pub struct Point4x4(pub(crate) Vec4x4);
impl Point4x4 {
pub const ZERO: Self = Self::splat(f32x4::ZERO);
pub const ONE: Self = Self::splat(f32x4::ONE);
pub const NEG_ONE: Self = Self::splat(f32x4::NEG_ONE);
pub const NAN: Self = Self::splat(f32x4::NAN);
pub const X: Self = Self::new(f32x4::ONE, f32x4::ZERO, f32x4::ZERO, f32x4::ZERO);
pub const Y: Self = Self::new(f32x4::ZERO, f32x4::ONE, f32x4::ZERO, f32x4::ZERO);
pub const Z: Self = Self::new(f32x4::ZERO, f32x4::ZERO, f32x4::ONE, f32x4::ZERO);
pub const W: Self = Self::new(f32x4::ZERO, f32x4::ZERO, f32x4::ZERO, f32x4::ONE);
pub const NEG_X: Self = Self::new(f32x4::NEG_ONE, f32x4::ZERO, f32x4::ZERO, f32x4::ZERO);
pub const NEG_Y: Self = Self::new(f32x4::ZERO, f32x4::NEG_ONE, f32x4::ZERO, f32x4::ZERO);
pub const NEG_Z: Self = Self::new(f32x4::ZERO, f32x4::ZERO, f32x4::NEG_ONE, f32x4::ZERO);
pub const NEG_W: Self = Self::new(f32x4::ZERO, f32x4::ZERO, f32x4::ZERO, f32x4::NEG_ONE);
pub const AXES: [Self; 4] = [Self::X, Self::Y, Self::Z, Self::W];
#[inline]
pub const fn new(x: f32x4, y: f32x4, z: f32x4, w: f32x4) -> Self {
Self(Vec4x4::new(x, y, z, w))
}
#[inline]
pub const fn splat(v: f32x4) -> Self {
Self(Vec4x4::splat(v))
}
#[inline]
pub fn select(mask: BVec4x4, if_true: Self, if_false: Self) -> Self {
Self(Vec4x4::select(mask, if_true.0, if_false.0))
}
#[inline]
pub const fn from_array(a: [f32x4; 4]) -> Self {
Self::new(a[0], a[1], a[2], a[3])
}
#[inline]
pub const fn to_array(&self) -> [f32x4; 4] {
self.0.to_array()
}
#[inline]
pub const fn from_slice(slice: &[f32x4]) -> Self {
Self::new(slice[0], slice[1], slice[2], slice[3])
}
#[inline]
pub fn write_to_slice(self, slice: &mut [f32x4]) {
self.0.write_to_slice(slice)
}
#[inline]
pub fn truncate(self) -> Point3x4 {
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) -> f32x4 {
self.0.min_element()
}
#[inline]
pub fn max_element(self) -> f32x4 {
self.0.max_element()
}
#[inline]
pub fn cmpeq(self, rhs: Self) -> BVec4x4 {
self.0.cmpeq(rhs.0)
}
#[inline]
pub fn cmpne(self, rhs: Self) -> BVec4x4 {
self.0.cmpne(rhs.0)
}
#[inline]
pub fn cmpge(self, rhs: Self) -> BVec4x4 {
self.0.cmpge(rhs.0)
}
#[inline]
pub fn cmpgt(self, rhs: Self) -> BVec4x4 {
self.0.cmpgt(rhs.0)
}
#[inline]
pub fn cmple(self, rhs: Self) -> BVec4x4 {
self.0.cmple(rhs.0)
}
#[inline]
pub fn cmplt(self, rhs: Self) -> BVec4x4 {
self.0.cmplt(rhs.0)
}
#[inline]
pub fn abs(self) -> Self {
Self(self.0.abs())
}
#[inline]
pub fn signum(self) -> Vec4x4 {
self.0.signum()
}
#[inline]
pub fn is_finite(self) -> bool32x4 {
self.0.is_finite()
}
#[inline]
pub fn is_nan(self) -> bool32x4 {
self.0.is_nan()
}
#[inline]
pub fn is_nan_mask(self) -> BVec4x4 {
self.0.is_nan_mask()
}
#[inline]
pub fn round(self) -> Self {
Self(self.0.round())
}
#[inline]
pub fn floor(self) -> Self {
Self(self.0.floor())
}
#[inline]
pub fn ceil(self) -> Self {
Self(self.0.ceil())
}
#[inline]
pub fn fract(self) -> Self {
Self(self.0.fract())
}
#[inline]
pub fn exp(self) -> Self {
Self(self.0.exp())
}
#[inline]
pub fn powf(self, n: f32x4) -> Self {
Self(self.0.powf(n))
}
#[inline]
pub fn recip(self) -> Self {
Self(self.0.recip())
}
#[inline]
pub fn length(self) -> f32x4 {
self.0.length()
}
#[inline]
pub fn length_squared(self) -> f32x4 {
self.0.length_squared()
}
#[inline]
pub fn length_recip(self) -> f32x4 {
self.0.length_recip()
}
#[inline]
pub fn distance(self, rhs: Self) -> f32x4 {
self.0.distance(rhs.0)
}
#[inline]
pub fn distance_squared(self, rhs: Self) -> f32x4 {
self.0.distance_squared(rhs.0)
}
#[inline]
pub fn lane_select(cond: bool32x4, if_true: Self, if_false: Self) -> Self {
Self(Vec4x4::lane_select(cond, if_true.0, if_false.0))
}
#[inline]
pub fn splat_soa(v: Point4) -> Self {
Self(Vec4x4::splat_soa(v.0))
}
#[inline]
pub fn extract_lane(&self, i: usize) -> Point4 {
Point4(self.0.extract_lane(i))
}
#[inline]
pub fn replace_lane(&mut self, i: usize, v: Point4) {
self.0.replace_lane(i, v.0);
}
#[inline]
pub fn split_soa(self) -> [Point4; 4] {
[
self.extract_lane(0),
self.extract_lane(1),
self.extract_lane(2),
self.extract_lane(3),
]
}
#[inline]
pub fn compose_soa(a: &[Point4; 4]) -> Point4x4 {
let mut v = Self::default();
v.replace_lane(0, a[0]);
v.replace_lane(1, a[1]);
v.replace_lane(2, a[2]);
v.replace_lane(3, a[3]);
v
}
#[doc(alias = "mix")]
#[inline]
pub fn lerp(self, rhs: Self, s: f32x4) -> Self {
Self(self.0.lerp(rhs.0, s))
}
#[inline]
pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f32x4) -> bool32x4 {
self.0.abs_diff_eq(rhs.0, max_abs_diff)
}
#[inline]
pub fn as_vec4x4(&self) -> Vec4x4 {
self.0
}
#[inline]
pub fn from_vec4x4(v: Vec4x4) -> Self {
Self(v)
}
}
impl Default for Point4x4 {
#[inline]
fn default() -> Self {
Self::ZERO
}
}
impl_op_ex_commutative!(+ |a: &Point4x4, b: &Vec4x4| -> Point4x4 { Point4x4(a.0 + b) });
impl_op_ex_commutative!(+ |a: &Point4x4, b: &f32x4| -> Point4x4 { Point4x4(a.0 + b) });
impl_op!(+= |a: &mut Point4x4, b: &Vec4x4| { a.0 += b });
impl_op!(-= |a: &mut Point4x4, b: &Vec4x4| { a.0 -= b });
impl_op!(+= |a: &mut Point4x4, b: Vec4x4| { a.0 += b });
impl_op!(-= |a: &mut Point4x4, b: Vec4x4| { a.0 -= b });
impl_op_ex!(-|a: &Point4x4, b: &Vec4x4| -> Point4x4 { Point4x4(a.0 - b) });
impl_op_ex!(-|a: &Point4x4, b: &f32x4| -> Point4x4 { Point4x4(a.0 - b) });
impl_op_ex!(-|a: &Point4x4, b: &Point4x4| -> Vec4x4 { a.0 - b.0 });
impl Neg for Point4x4 {
type Output = Self;
#[inline]
fn neg(self) -> Self {
Self(self.0.neg())
}
}
impl Index<usize> for Point4x4 {
type Output = f32x4;
#[inline]
fn index(&self, index: usize) -> &Self::Output {
self.0.index(index)
}
}
impl IndexMut<usize> for Point4x4 {
#[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 Point4x4 {
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 Point4x4 {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple(stringify!(Point4x4))
.field(&self.x)
.field(&self.y)
.field(&self.z)
.field(&self.w)
.finish()
}
}
impl From<[f32x4; 4]> for Point4x4 {
#[inline]
fn from(a: [f32x4; 4]) -> Self {
Self(Vec4x4::from(a))
}
}
impl From<Point4x4> for [f32x4; 4] {
#[inline]
fn from(v: Point4x4) -> Self {
v.0.into()
}
}
impl From<(f32x4, f32x4, f32x4, f32x4)> for Point4x4 {
#[inline]
fn from(t: (f32x4, f32x4, f32x4, f32x4)) -> Self {
Self(Vec4x4::from(t))
}
}
impl From<Point4x4> for (f32x4, f32x4, f32x4, f32x4) {
#[inline]
fn from(v: Point4x4) -> Self {
v.0.into()
}
}
impl From<(Point3x4, f32x4)> for Point4x4 {
#[inline]
fn from((v, w): (Point3x4, f32x4)) -> Self {
Self::new(v.x, v.y, v.z, w)
}
}
impl From<(f32x4, Point3x4)> for Point4x4 {
#[inline]
fn from((x, v): (f32x4, Point3x4)) -> Self {
Self::new(x, v.x, v.y, v.z)
}
}
impl From<(Point2x4, f32x4, f32x4)> for Point4x4 {
#[inline]
fn from((v, z, w): (Point2x4, f32x4, f32x4)) -> Self {
Self::new(v.x, v.y, z, w)
}
}
impl From<(Point2x4, Point2x4)> for Point4x4 {
#[inline]
fn from((v, u): (Point2x4, Point2x4)) -> Self {
Self::new(v.x, v.y, u.x, u.y)
}
}
impl Deref for Point4x4 {
type Target = crate::deref::Vec4<f32x4>;
#[inline]
fn deref(&self) -> &Self::Target {
unsafe { &*(self as *const Self).cast() }
}
}
impl DerefMut for Point4x4 {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *(self as *mut Self).cast() }
}
}
#[cfg(not(target_arch = "spirv"))]
impl AsRef<[f32x4; 4]> for Point4x4 {
#[inline]
fn as_ref(&self) -> &[f32x4; 4] {
unsafe { &*(self as *const Point4x4 as *const [f32x4; 4]) }
}
}
#[cfg(not(target_arch = "spirv"))]
impl AsMut<[f32x4; 4]> for Point4x4 {
#[inline]
fn as_mut(&mut self) -> &mut [f32x4; 4] {
unsafe { &mut *(self as *mut Point4x4 as *mut [f32x4; 4]) }
}
}