use crate::bool::simd_alias::BVec3A;
use crate::f32::simd_alias::{Point4, Vec3A};
use crate::{Point2, Point3, Vec3};
#[cfg(not(target_arch = "spirv"))]
use core::fmt;
use core::ops::*;
use core::arch::aarch64::*;
use auto_ops_det::{impl_op, impl_op_ex, impl_op_ex_commutative};
use core::ops;
#[inline]
pub const fn point3a(x: f32, y: f32, z: f32) -> Point3A {
Point3A::new(x, y, z)
}
#[derive(Clone, Copy)]
#[repr(transparent)]
pub struct Point3A(pub(crate) Vec3A);
impl Point3A {
pub const ZERO: Self = Self::splat(0.0_f32);
pub const ONE: Self = Self::splat(1.0_f32);
pub const NEG_ONE: Self = Self::splat(-1.0_f32);
pub const NAN: Self = Self::splat(f32::NAN);
pub const X: Self = Self::new(1.0_f32, 0.0_f32, 0.0_f32);
pub const Y: Self = Self::new(0.0_f32, 1.0_f32, 0.0_f32);
pub const Z: Self = Self::new(0.0_f32, 0.0_f32, 1.0_f32);
pub const NEG_X: Self = Self::new(-1.0_f32, 0.0_f32, 0.0_f32);
pub const NEG_Y: Self = Self::new(0.0_f32, -1.0_f32, 0.0_f32);
pub const NEG_Z: Self = Self::new(0.0_f32, 0.0_f32, -1.0_f32);
pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
#[inline]
pub const fn new(x: f32, y: f32, z: f32) -> Self {
Self(Vec3A::new(x, y, z))
}
#[inline]
pub const fn splat(v: f32) -> Self {
Self(Vec3A::splat(v))
}
#[inline]
pub fn select(mask: BVec3A, if_true: Self, if_false: Self) -> Self {
Self(Vec3A::select(mask, if_true.0, if_false.0))
}
#[inline]
pub const fn from_array(a: [f32; 3]) -> Self {
Self::new(a[0], a[1], a[2])
}
#[inline]
pub const fn to_array(&self) -> [f32; 3] {
self.0.to_array()
}
#[inline]
pub const fn from_slice(slice: &[f32]) -> Self {
Self::new(slice[0], slice[1], slice[2])
}
#[inline]
pub fn write_to_slice(self, slice: &mut [f32]) {
self.0.write_to_slice(slice)
}
#[inline]
pub fn extend(self, w: f32) -> Point4 {
Point4::new(self.x, self.y, self.z, w)
}
#[inline]
pub fn truncate(self) -> Point2 {
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) -> f32 {
self.0.min_element()
}
#[inline]
pub fn max_element(self) -> f32 {
self.0.max_element()
}
#[inline]
pub fn cmpeq(self, rhs: Self) -> BVec3A {
self.0.cmpeq(rhs.0)
}
#[inline]
pub fn cmpne(self, rhs: Self) -> BVec3A {
self.0.cmpne(rhs.0)
}
#[inline]
pub fn cmpge(self, rhs: Self) -> BVec3A {
self.0.cmpge(rhs.0)
}
#[inline]
pub fn cmpgt(self, rhs: Self) -> BVec3A {
self.0.cmpgt(rhs.0)
}
#[inline]
pub fn cmple(self, rhs: Self) -> BVec3A {
self.0.cmple(rhs.0)
}
#[inline]
pub fn cmplt(self, rhs: Self) -> BVec3A {
self.0.cmplt(rhs.0)
}
#[inline]
pub fn abs(self) -> Self {
Self(self.0.abs())
}
#[inline]
pub fn signum(self) -> Vec3A {
self.0.signum()
}
#[inline]
pub fn is_finite(self) -> bool {
self.0.is_finite()
}
#[inline]
pub fn is_nan(self) -> bool {
self.0.is_nan()
}
#[inline]
pub fn is_nan_mask(self) -> BVec3A {
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: f32) -> Self {
Self(self.0.powf(n))
}
#[inline]
pub fn recip(self) -> Self {
Self(self.0.recip())
}
#[inline]
pub fn length(self) -> f32 {
self.0.length()
}
#[inline]
pub fn length_squared(self) -> f32 {
self.0.length_squared()
}
#[inline]
pub fn length_recip(self) -> f32 {
self.0.length_recip()
}
#[inline]
pub fn distance(self, rhs: Self) -> f32 {
self.0.distance(rhs.0)
}
#[inline]
pub fn distance_squared(self, rhs: Self) -> f32 {
self.0.distance_squared(rhs.0)
}
#[doc(alias = "mix")]
#[inline]
pub fn lerp(self, rhs: Self, s: f32) -> Self {
Self(self.0.lerp(rhs.0, s))
}
#[inline]
pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f32) -> bool {
self.0.abs_diff_eq(rhs.0, max_abs_diff)
}
#[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_ipoint3(&self) -> crate::IPoint3 {
crate::IPoint3::new(self.x as i32, self.y as i32, self.z as i32)
}
#[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_vec3a(&self) -> Vec3A {
self.0
}
#[inline]
pub fn from_vec3a(v: Vec3A) -> Self {
Self(v)
}
}
impl Default for Point3A {
#[inline]
fn default() -> Self {
Self::ZERO
}
}
impl PartialEq for Point3A {
#[inline]
fn eq(&self, rhs: &Self) -> bool {
self.cmpeq(*rhs).all()
}
}
impl_op_ex_commutative!(+ |a: &Point3A, b: &Vec3A| -> Point3A { Point3A(a.0 + b) });
impl_op_ex_commutative!(+ |a: &Point3A, b: &f32| -> Point3A { Point3A(a.0 + b) });
impl_op!(+= |a: &mut Point3A, b: &Vec3A| { a.0 += b });
impl_op!(-= |a: &mut Point3A, b: &Vec3A| { a.0 -= b });
impl_op!(+= |a: &mut Point3A, b: Vec3A| { a.0 += b });
impl_op!(-= |a: &mut Point3A, b: Vec3A| { a.0 -= b });
impl_op_ex!(-|a: &Point3A, b: &Vec3A| -> Point3A { Point3A(a.0 - b) });
impl_op_ex!(-|a: &Point3A, b: &f32| -> Point3A { Point3A(a.0 - b) });
impl_op_ex!(-|a: &Point3A, b: &Point3A| -> Vec3A { a.0 - b.0 });
impl Neg for Point3A {
type Output = Self;
#[inline]
fn neg(self) -> Self {
Self(self.0.neg())
}
}
impl Index<usize> for Point3A {
type Output = f32;
#[inline]
fn index(&self, index: usize) -> &Self::Output {
self.0.index(index)
}
}
impl IndexMut<usize> for Point3A {
#[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 Point3A {
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 Point3A {
fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
fmt.debug_tuple(stringify!(Point3A))
.field(&self.x)
.field(&self.y)
.field(&self.z)
.finish()
}
}
impl From<Point3A> for float32x4_t {
#[inline]
fn from(t: Point3A) -> Self {
t.0 .0
}
}
impl From<float32x4_t> for Point3A {
#[inline]
fn from(t: float32x4_t) -> Self {
Self(Vec3A::from(t))
}
}
impl From<[f32; 3]> for Point3A {
#[inline]
fn from(a: [f32; 3]) -> Self {
Self(Vec3A::from(a))
}
}
impl From<Point3A> for [f32; 3] {
#[inline]
fn from(v: Point3A) -> Self {
v.0.into()
}
}
impl From<(f32, f32, f32)> for Point3A {
#[inline]
fn from(t: (f32, f32, f32)) -> Self {
Self(Vec3A::from(t))
}
}
impl From<Point3A> for (f32, f32, f32) {
#[inline]
fn from(v: Point3A) -> Self {
v.0.into()
}
}
impl From<Point3> for Point3A {
#[inline]
fn from(v: Point3) -> Self {
Self::new(v.x, v.y, v.z)
}
}
impl From<Point4> for Point3A {
#[inline]
fn from(v: Point4) -> Self {
Self(Vec3A::from(v.0))
}
}
impl From<Point3A> for Point3 {
#[inline]
fn from(v: Point3A) -> Self {
Self(Vec3::from(v.0))
}
}
impl From<(Point2, f32)> for Point3A {
#[inline]
fn from((v, z): (Point2, f32)) -> Self {
Self::new(v.x, v.y, z)
}
}
impl Deref for Point3A {
type Target = crate::deref::Vec3<f32>;
#[inline]
fn deref(&self) -> &Self::Target {
unsafe { &*(self as *const Self).cast() }
}
}
impl DerefMut for Point3A {
#[inline]
fn deref_mut(&mut self) -> &mut Self::Target {
unsafe { &mut *(self as *mut Self).cast() }
}
}
#[cfg(not(target_arch = "spirv"))]
impl AsRef<[f32; 3]> for Point3A {
#[inline]
fn as_ref(&self) -> &[f32; 3] {
unsafe { &*(self as *const Point3A as *const [f32; 3]) }
}
}
#[cfg(not(target_arch = "spirv"))]
impl AsMut<[f32; 3]> for Point3A {
#[inline]
fn as_mut(&mut self) -> &mut [f32; 3] {
unsafe { &mut *(self as *mut Point3A as *mut [f32; 3]) }
}
}