diff options
Diffstat (limited to 'src/i32/ivec4.rs')
-rw-r--r-- | src/i32/ivec4.rs | 374 |
1 files changed, 21 insertions, 353 deletions
diff --git a/src/i32/ivec4.rs b/src/i32/ivec4.rs index 5ebdd69..7c07621 100644 --- a/src/i32/ivec4.rs +++ b/src/i32/ivec4.rs @@ -1,6 +1,6 @@ // Generated from vec.rs.tera template. Edit the template, not the generated file. -use crate::{BVec4, I16Vec4, I64Vec4, IVec2, IVec3, U16Vec4, U64Vec4, UVec4}; +use crate::{BVec4, IVec2, IVec3}; #[cfg(not(target_arch = "spirv"))] use core::fmt; @@ -9,7 +9,6 @@ use core::{f32, ops::*}; /// Creates a 4-dimensional vector. #[inline(always)] -#[must_use] pub const fn ivec4(x: i32, y: i32, z: i32, w: i32) -> IVec4 { IVec4::new(x, y, z, w) } @@ -37,34 +36,28 @@ impl IVec4 { /// All negative ones. pub const NEG_ONE: Self = Self::splat(-1); - /// All `i32::MIN`. - pub const MIN: Self = Self::splat(i32::MIN); - - /// All `i32::MAX`. - pub const MAX: Self = Self::splat(i32::MAX); - - /// A unit vector pointing along the positive X axis. + /// A unit-length vector pointing along the positive X axis. pub const X: Self = Self::new(1, 0, 0, 0); - /// A unit vector pointing along the positive Y axis. + /// A unit-length vector pointing along the positive Y axis. pub const Y: Self = Self::new(0, 1, 0, 0); - /// A unit vector pointing along the positive Z axis. + /// A unit-length vector pointing along the positive Z axis. pub const Z: Self = Self::new(0, 0, 1, 0); - /// A unit vector pointing along the positive W axis. + /// A unit-length vector pointing along the positive W axis. pub const W: Self = Self::new(0, 0, 0, 1); - /// A unit vector pointing along the negative X axis. + /// A unit-length vector pointing along the negative X axis. pub const NEG_X: Self = Self::new(-1, 0, 0, 0); - /// A unit vector pointing along the negative Y axis. + /// A unit-length vector pointing along the negative Y axis. pub const NEG_Y: Self = Self::new(0, -1, 0, 0); - /// A unit vector pointing along the negative Z axis. + /// A unit-length vector pointing along the negative Z axis. pub const NEG_Z: Self = Self::new(0, 0, -1, 0); - /// A unit vector pointing along the negative W axis. + /// A unit-length vector pointing along the negative W axis. pub const NEG_W: Self = Self::new(0, 0, 0, -1); /// The unit axes. @@ -72,14 +65,12 @@ impl IVec4 { /// Creates a new vector. #[inline(always)] - #[must_use] pub const fn new(x: i32, y: i32, z: i32, w: i32) -> Self { Self { x, y, z, w } } /// Creates a vector with all elements set to `v`. #[inline] - #[must_use] pub const fn splat(v: i32) -> Self { Self { x: v, @@ -98,26 +89,23 @@ impl IVec4 { /// A true element in the mask uses the corresponding element from `if_true`, and false /// uses the element from `if_false`. #[inline] - #[must_use] pub fn select(mask: BVec4, if_true: Self, if_false: Self) -> Self { Self { - x: if mask.test(0) { if_true.x } else { if_false.x }, - y: if mask.test(1) { if_true.y } else { if_false.y }, - z: if mask.test(2) { if_true.z } else { if_false.z }, - w: if mask.test(3) { if_true.w } else { if_false.w }, + x: if mask.x { if_true.x } else { if_false.x }, + y: if mask.y { if_true.y } else { if_false.y }, + z: if mask.z { if_true.z } else { if_false.z }, + w: if mask.w { if_true.w } else { if_false.w }, } } /// Creates a new vector from an array. #[inline] - #[must_use] pub const fn from_array(a: [i32; 4]) -> Self { Self::new(a[0], a[1], a[2], a[3]) } /// `[x, y, z, w]` #[inline] - #[must_use] pub const fn to_array(&self) -> [i32; 4] { [self.x, self.y, self.z, self.w] } @@ -128,7 +116,6 @@ impl IVec4 { /// /// Panics if `slice` is less than 4 elements long. #[inline] - #[must_use] pub const fn from_slice(slice: &[i32]) -> Self { Self::new(slice[0], slice[1], slice[2], slice[3]) } @@ -146,11 +133,10 @@ impl IVec4 { slice[3] = self.w; } - /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. + /// Creates a 2D vector from the `x`, `y` and `z` elements of `self`, discarding `w`. /// - /// Truncation to [`IVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()]. + /// Truncation to `IVec3` may also be performed by using `self.xyz()` or `IVec3::from()`. #[inline] - #[must_use] pub fn truncate(self) -> IVec3 { use crate::swizzles::Vec4Swizzles; self.xyz() @@ -158,14 +144,12 @@ impl IVec4 { /// Computes the dot product of `self` and `rhs`. #[inline] - #[must_use] pub fn dot(self, rhs: Self) -> i32 { (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z) + (self.w * rhs.w) } /// Returns a vector where every component is the dot product of `self` and `rhs`. #[inline] - #[must_use] pub fn dot_into_vec(self, rhs: Self) -> Self { Self::splat(self.dot(rhs)) } @@ -174,7 +158,6 @@ impl IVec4 { /// /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`. #[inline] - #[must_use] pub fn min(self, rhs: Self) -> Self { Self { x: self.x.min(rhs.x), @@ -188,7 +171,6 @@ impl IVec4 { /// /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`. #[inline] - #[must_use] pub fn max(self, rhs: Self) -> Self { Self { x: self.x.max(rhs.x), @@ -206,7 +188,6 @@ impl IVec4 { /// /// Will panic if `min` is greater than `max` when `glam_assert` is enabled. #[inline] - #[must_use] pub fn clamp(self, min: Self, max: Self) -> Self { glam_assert!(min.cmple(max).all(), "clamp: expected min <= max"); self.max(min).min(max) @@ -216,7 +197,6 @@ impl IVec4 { /// /// In other words this computes `min(x, y, ..)`. #[inline] - #[must_use] pub fn min_element(self) -> i32 { self.x.min(self.y.min(self.z.min(self.w))) } @@ -225,7 +205,6 @@ impl IVec4 { /// /// In other words this computes `max(x, y, ..)`. #[inline] - #[must_use] pub fn max_element(self) -> i32 { self.x.max(self.y.max(self.z.max(self.w))) } @@ -236,7 +215,6 @@ impl IVec4 { /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all /// elements. #[inline] - #[must_use] pub fn cmpeq(self, rhs: Self) -> BVec4 { BVec4::new( self.x.eq(&rhs.x), @@ -252,7 +230,6 @@ impl IVec4 { /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all /// elements. #[inline] - #[must_use] pub fn cmpne(self, rhs: Self) -> BVec4 { BVec4::new( self.x.ne(&rhs.x), @@ -268,7 +245,6 @@ impl IVec4 { /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all /// elements. #[inline] - #[must_use] pub fn cmpge(self, rhs: Self) -> BVec4 { BVec4::new( self.x.ge(&rhs.x), @@ -284,7 +260,6 @@ impl IVec4 { /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all /// elements. #[inline] - #[must_use] pub fn cmpgt(self, rhs: Self) -> BVec4 { BVec4::new( self.x.gt(&rhs.x), @@ -300,7 +275,6 @@ impl IVec4 { /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all /// elements. #[inline] - #[must_use] pub fn cmple(self, rhs: Self) -> BVec4 { BVec4::new( self.x.le(&rhs.x), @@ -316,7 +290,6 @@ impl IVec4 { /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all /// elements. #[inline] - #[must_use] pub fn cmplt(self, rhs: Self) -> BVec4 { BVec4::new( self.x.lt(&rhs.x), @@ -328,7 +301,6 @@ impl IVec4 { /// Returns a vector containing the absolute value of each element of `self`. #[inline] - #[must_use] pub fn abs(self) -> Self { Self { x: self.x.abs(), @@ -344,7 +316,6 @@ impl IVec4 { /// - `1` if the number is positive /// - `-1` if the number is negative #[inline] - #[must_use] pub fn signum(self) -> Self { Self { x: self.x.signum(), @@ -354,12 +325,17 @@ impl IVec4 { } } + /// Returns a vector with signs of `rhs` and the magnitudes of `self`. + #[inline] + pub fn copysign(self, rhs: Self) -> Self { + Self::select(rhs.cmpge(Self::ZERO), self, -self) + } + /// Returns a bitmask with the lowest 4 bits set to the sign bits from the elements of `self`. /// /// A negative element results in a `1` bit and a positive element in a `0` bit. Element `x` goes /// into the first lowest bit, element `y` into the second, etc. #[inline] - #[must_use] pub fn is_negative_bitmask(self) -> u32 { (self.x.is_negative() as u32) | (self.y.is_negative() as u32) << 1 @@ -367,213 +343,23 @@ impl IVec4 { | (self.w.is_negative() as u32) << 3 } - /// Computes the squared length of `self`. - #[doc(alias = "magnitude2")] - #[inline] - #[must_use] - pub fn length_squared(self) -> i32 { - self.dot(self) - } - - /// Compute the squared euclidean distance between two points in space. - #[inline] - #[must_use] - pub fn distance_squared(self, rhs: Self) -> i32 { - (self - rhs).length_squared() - } - - /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`. - /// - /// # Panics - /// This function will panic if any `rhs` element is 0 or the division results in overflow. - #[inline] - #[must_use] - pub fn div_euclid(self, rhs: Self) -> Self { - Self::new( - self.x.div_euclid(rhs.x), - self.y.div_euclid(rhs.y), - self.z.div_euclid(rhs.z), - self.w.div_euclid(rhs.w), - ) - } - - /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`. - /// - /// # Panics - /// This function will panic if any `rhs` element is 0 or the division results in overflow. - /// - /// [Euclidean division]: i32::rem_euclid - #[inline] - #[must_use] - pub fn rem_euclid(self, rhs: Self) -> Self { - Self::new( - self.x.rem_euclid(rhs.x), - self.y.rem_euclid(rhs.y), - self.z.rem_euclid(rhs.z), - self.w.rem_euclid(rhs.w), - ) - } - /// Casts all elements of `self` to `f32`. #[inline] - #[must_use] pub fn as_vec4(&self) -> crate::Vec4 { crate::Vec4::new(self.x as f32, self.y as f32, self.z as f32, self.w as f32) } /// Casts all elements of `self` to `f64`. #[inline] - #[must_use] pub fn as_dvec4(&self) -> crate::DVec4 { crate::DVec4::new(self.x as f64, self.y as f64, self.z as f64, self.w as f64) } - /// Casts all elements of `self` to `i16`. - #[inline] - #[must_use] - pub fn as_i16vec4(&self) -> crate::I16Vec4 { - crate::I16Vec4::new(self.x as i16, self.y as i16, self.z as i16, self.w as i16) - } - - /// Casts all elements of `self` to `u16`. - #[inline] - #[must_use] - pub fn as_u16vec4(&self) -> crate::U16Vec4 { - crate::U16Vec4::new(self.x as u16, self.y as u16, self.z as u16, self.w as u16) - } - /// Casts all elements of `self` to `u32`. #[inline] - #[must_use] pub fn as_uvec4(&self) -> crate::UVec4 { crate::UVec4::new(self.x as u32, self.y as u32, self.z as u32, self.w as u32) } - - /// Casts all elements of `self` to `i64`. - #[inline] - #[must_use] - pub fn as_i64vec4(&self) -> crate::I64Vec4 { - crate::I64Vec4::new(self.x as i64, self.y as i64, self.z as i64, self.w as i64) - } - - /// Casts all elements of `self` to `u64`. - #[inline] - #[must_use] - pub fn as_u64vec4(&self) -> crate::U64Vec4 { - crate::U64Vec4::new(self.x as u64, self.y as u64, self.z as u64, self.w as u64) - } - - /// Returns a vector containing the wrapping addition of `self` and `rhs`. - /// - /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`. - #[inline] - #[must_use] - pub const fn wrapping_add(self, rhs: Self) -> Self { - Self { - x: self.x.wrapping_add(rhs.x), - y: self.y.wrapping_add(rhs.y), - z: self.z.wrapping_add(rhs.z), - w: self.w.wrapping_add(rhs.w), - } - } - - /// Returns a vector containing the wrapping subtraction of `self` and `rhs`. - /// - /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`. - #[inline] - #[must_use] - pub const fn wrapping_sub(self, rhs: Self) -> Self { - Self { - x: self.x.wrapping_sub(rhs.x), - y: self.y.wrapping_sub(rhs.y), - z: self.z.wrapping_sub(rhs.z), - w: self.w.wrapping_sub(rhs.w), - } - } - - /// Returns a vector containing the wrapping multiplication of `self` and `rhs`. - /// - /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`. - #[inline] - #[must_use] - pub const fn wrapping_mul(self, rhs: Self) -> Self { - Self { - x: self.x.wrapping_mul(rhs.x), - y: self.y.wrapping_mul(rhs.y), - z: self.z.wrapping_mul(rhs.z), - w: self.w.wrapping_mul(rhs.w), - } - } - - /// Returns a vector containing the wrapping division of `self` and `rhs`. - /// - /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`. - #[inline] - #[must_use] - pub const fn wrapping_div(self, rhs: Self) -> Self { - Self { - x: self.x.wrapping_div(rhs.x), - y: self.y.wrapping_div(rhs.y), - z: self.z.wrapping_div(rhs.z), - w: self.w.wrapping_div(rhs.w), - } - } - - /// Returns a vector containing the saturating addition of `self` and `rhs`. - /// - /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`. - #[inline] - #[must_use] - pub const fn saturating_add(self, rhs: Self) -> Self { - Self { - x: self.x.saturating_add(rhs.x), - y: self.y.saturating_add(rhs.y), - z: self.z.saturating_add(rhs.z), - w: self.w.saturating_add(rhs.w), - } - } - - /// Returns a vector containing the saturating subtraction of `self` and `rhs`. - /// - /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`. - #[inline] - #[must_use] - pub const fn saturating_sub(self, rhs: Self) -> Self { - Self { - x: self.x.saturating_sub(rhs.x), - y: self.y.saturating_sub(rhs.y), - z: self.z.saturating_sub(rhs.z), - w: self.w.saturating_sub(rhs.w), - } - } - - /// Returns a vector containing the saturating multiplication of `self` and `rhs`. - /// - /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`. - #[inline] - #[must_use] - pub const fn saturating_mul(self, rhs: Self) -> Self { - Self { - x: self.x.saturating_mul(rhs.x), - y: self.y.saturating_mul(rhs.y), - z: self.z.saturating_mul(rhs.z), - w: self.w.saturating_mul(rhs.w), - } - } - - /// Returns a vector containing the saturating division of `self` and `rhs`. - /// - /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`. - #[inline] - #[must_use] - pub const fn saturating_div(self, rhs: Self) -> Self { - Self { - x: self.x.saturating_div(rhs.x), - y: self.y.saturating_div(rhs.y), - z: self.z.saturating_div(rhs.z), - w: self.w.saturating_div(rhs.w), - } - } } impl Default for IVec4 { @@ -1116,32 +902,6 @@ impl Shr<i32> for IVec4 { } } -impl Shl<i64> for IVec4 { - type Output = Self; - #[inline] - fn shl(self, rhs: i64) -> Self::Output { - Self { - x: self.x.shl(rhs), - y: self.y.shl(rhs), - z: self.z.shl(rhs), - w: self.w.shl(rhs), - } - } -} - -impl Shr<i64> for IVec4 { - type Output = Self; - #[inline] - fn shr(self, rhs: i64) -> Self::Output { - Self { - x: self.x.shr(rhs), - y: self.y.shr(rhs), - z: self.z.shr(rhs), - w: self.w.shr(rhs), - } - } -} - impl Shl<u8> for IVec4 { type Output = Self; #[inline] @@ -1220,32 +980,6 @@ impl Shr<u32> for IVec4 { } } -impl Shl<u64> for IVec4 { - type Output = Self; - #[inline] - fn shl(self, rhs: u64) -> Self::Output { - Self { - x: self.x.shl(rhs), - y: self.y.shl(rhs), - z: self.z.shl(rhs), - w: self.w.shl(rhs), - } - } -} - -impl Shr<u64> for IVec4 { - type Output = Self; - #[inline] - fn shr(self, rhs: u64) -> Self::Output { - Self { - x: self.x.shr(rhs), - y: self.y.shr(rhs), - z: self.z.shr(rhs), - w: self.w.shr(rhs), - } - } -} - impl Shl<crate::IVec4> for IVec4 { type Output = Self; #[inline] @@ -1399,69 +1133,3 @@ impl From<(IVec2, IVec2)> for IVec4 { Self::new(v.x, v.y, u.x, u.y) } } - -impl From<I16Vec4> for IVec4 { - #[inline] - fn from(v: I16Vec4) -> Self { - Self::new( - i32::from(v.x), - i32::from(v.y), - i32::from(v.z), - i32::from(v.w), - ) - } -} - -impl From<U16Vec4> for IVec4 { - #[inline] - fn from(v: U16Vec4) -> Self { - Self::new( - i32::from(v.x), - i32::from(v.y), - i32::from(v.z), - i32::from(v.w), - ) - } -} - -impl TryFrom<UVec4> for IVec4 { - type Error = core::num::TryFromIntError; - - #[inline] - fn try_from(v: UVec4) -> Result<Self, Self::Error> { - Ok(Self::new( - i32::try_from(v.x)?, - i32::try_from(v.y)?, - i32::try_from(v.z)?, - i32::try_from(v.w)?, - )) - } -} - -impl TryFrom<I64Vec4> for IVec4 { - type Error = core::num::TryFromIntError; - - #[inline] - fn try_from(v: I64Vec4) -> Result<Self, Self::Error> { - Ok(Self::new( - i32::try_from(v.x)?, - i32::try_from(v.y)?, - i32::try_from(v.z)?, - i32::try_from(v.w)?, - )) - } -} - -impl TryFrom<U64Vec4> for IVec4 { - type Error = core::num::TryFromIntError; - - #[inline] - fn try_from(v: U64Vec4) -> Result<Self, Self::Error> { - Ok(Self::new( - i32::try_from(v.x)?, - i32::try_from(v.y)?, - i32::try_from(v.z)?, - i32::try_from(v.w)?, - )) - } -} |