aboutsummaryrefslogtreecommitdiff
path: root/src/u32/uvec3.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/u32/uvec3.rs')
-rw-r--r--src/u32/uvec3.rs297
1 files changed, 289 insertions, 8 deletions
diff --git a/src/u32/uvec3.rs b/src/u32/uvec3.rs
index 040b482..ca06d46 100644
--- a/src/u32/uvec3.rs
+++ b/src/u32/uvec3.rs
@@ -1,6 +1,6 @@
// Generated from vec.rs.tera template. Edit the template, not the generated file.
-use crate::{BVec3, UVec2, UVec4};
+use crate::{BVec3, I16Vec3, I64Vec3, IVec3, U16Vec3, U64Vec3, UVec2, UVec4};
#[cfg(not(target_arch = "spirv"))]
use core::fmt;
@@ -9,6 +9,7 @@ use core::{f32, ops::*};
/// Creates a 3-dimensional vector.
#[inline(always)]
+#[must_use]
pub const fn uvec3(x: u32, y: u32, z: u32) -> UVec3 {
UVec3::new(x, y, z)
}
@@ -31,13 +32,19 @@ impl UVec3 {
/// All ones.
pub const ONE: Self = Self::splat(1);
- /// A unit-length vector pointing along the positive X axis.
+ /// All `u32::MIN`.
+ pub const MIN: Self = Self::splat(u32::MIN);
+
+ /// All `u32::MAX`.
+ pub const MAX: Self = Self::splat(u32::MAX);
+
+ /// A unit vector pointing along the positive X axis.
pub const X: Self = Self::new(1, 0, 0);
- /// A unit-length vector pointing along the positive Y axis.
+ /// A unit vector pointing along the positive Y axis.
pub const Y: Self = Self::new(0, 1, 0);
- /// A unit-length vector pointing along the positive Z axis.
+ /// A unit vector pointing along the positive Z axis.
pub const Z: Self = Self::new(0, 0, 1);
/// The unit axes.
@@ -45,12 +52,14 @@ impl UVec3 {
/// Creates a new vector.
#[inline(always)]
+ #[must_use]
pub const fn new(x: u32, y: u32, z: u32) -> Self {
Self { x, y, z }
}
/// Creates a vector with all elements set to `v`.
#[inline]
+ #[must_use]
pub const fn splat(v: u32) -> Self {
Self { x: v, y: v, z: v }
}
@@ -61,22 +70,25 @@ impl UVec3 {
/// 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: BVec3, if_true: Self, if_false: Self) -> Self {
Self {
- 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 },
+ 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 },
}
}
/// Creates a new vector from an array.
#[inline]
+ #[must_use]
pub const fn from_array(a: [u32; 3]) -> Self {
Self::new(a[0], a[1], a[2])
}
/// `[x, y, z]`
#[inline]
+ #[must_use]
pub const fn to_array(&self) -> [u32; 3] {
[self.x, self.y, self.z]
}
@@ -87,6 +99,7 @@ impl UVec3 {
///
/// Panics if `slice` is less than 3 elements long.
#[inline]
+ #[must_use]
pub const fn from_slice(slice: &[u32]) -> Self {
Self::new(slice[0], slice[1], slice[2])
}
@@ -106,6 +119,7 @@ impl UVec3 {
/// Internal method for creating a 3D vector from a 4D vector, discarding `w`.
#[allow(dead_code)]
#[inline]
+ #[must_use]
pub(crate) fn from_vec4(v: UVec4) -> Self {
Self {
x: v.x,
@@ -116,14 +130,16 @@ impl UVec3 {
/// Creates a 4D vector from `self` and the given `w` value.
#[inline]
+ #[must_use]
pub fn extend(self, w: u32) -> UVec4 {
UVec4::new(self.x, self.y, self.z, w)
}
/// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`.
///
- /// Truncation may also be performed by using `self.xy()` or `UVec2::from()`.
+ /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()].
#[inline]
+ #[must_use]
pub fn truncate(self) -> UVec2 {
use crate::swizzles::Vec3Swizzles;
self.xy()
@@ -131,18 +147,21 @@ impl UVec3 {
/// Computes the dot product of `self` and `rhs`.
#[inline]
+ #[must_use]
pub fn dot(self, rhs: Self) -> u32 {
(self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z)
}
/// 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))
}
/// Computes the cross product of `self` and `rhs`.
#[inline]
+ #[must_use]
pub fn cross(self, rhs: Self) -> Self {
Self {
x: self.y * rhs.z - rhs.y * self.z,
@@ -155,6 +174,7 @@ impl UVec3 {
///
/// 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),
@@ -167,6 +187,7 @@ impl UVec3 {
///
/// 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),
@@ -183,6 +204,7 @@ impl UVec3 {
///
/// 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)
@@ -192,6 +214,7 @@ impl UVec3 {
///
/// In other words this computes `min(x, y, ..)`.
#[inline]
+ #[must_use]
pub fn min_element(self) -> u32 {
self.x.min(self.y.min(self.z))
}
@@ -200,6 +223,7 @@ impl UVec3 {
///
/// In other words this computes `max(x, y, ..)`.
#[inline]
+ #[must_use]
pub fn max_element(self) -> u32 {
self.x.max(self.y.max(self.z))
}
@@ -210,6 +234,7 @@ impl UVec3 {
/// 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) -> BVec3 {
BVec3::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
}
@@ -220,6 +245,7 @@ impl UVec3 {
/// 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) -> BVec3 {
BVec3::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
}
@@ -230,6 +256,7 @@ impl UVec3 {
/// 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) -> BVec3 {
BVec3::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
}
@@ -240,6 +267,7 @@ impl UVec3 {
/// 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) -> BVec3 {
BVec3::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
}
@@ -250,6 +278,7 @@ impl UVec3 {
/// 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) -> BVec3 {
BVec3::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
}
@@ -260,33 +289,178 @@ impl UVec3 {
/// 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) -> BVec3 {
BVec3::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
}
+ /// Computes the squared length of `self`.
+ #[doc(alias = "magnitude2")]
+ #[inline]
+ #[must_use]
+ pub fn length_squared(self) -> u32 {
+ self.dot(self)
+ }
+
/// Casts all elements of `self` to `f32`.
#[inline]
+ #[must_use]
pub fn as_vec3(&self) -> crate::Vec3 {
crate::Vec3::new(self.x as f32, self.y as f32, self.z as f32)
}
/// Casts all elements of `self` to `f32`.
#[inline]
+ #[must_use]
pub fn as_vec3a(&self) -> crate::Vec3A {
crate::Vec3A::new(self.x as f32, self.y as f32, self.z as f32)
}
/// Casts all elements of `self` to `f64`.
#[inline]
+ #[must_use]
pub fn as_dvec3(&self) -> crate::DVec3 {
crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
}
+ /// Casts all elements of `self` to `i16`.
+ #[inline]
+ #[must_use]
+ pub fn as_i16vec3(&self) -> crate::I16Vec3 {
+ crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
+ }
+
+ /// Casts all elements of `self` to `u16`.
+ #[inline]
+ #[must_use]
+ pub fn as_u16vec3(&self) -> crate::U16Vec3 {
+ crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
+ }
+
/// Casts all elements of `self` to `i32`.
#[inline]
+ #[must_use]
pub fn as_ivec3(&self) -> crate::IVec3 {
crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
}
+
+ /// Casts all elements of `self` to `i64`.
+ #[inline]
+ #[must_use]
+ pub fn as_i64vec3(&self) -> crate::I64Vec3 {
+ crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
+ }
+
+ /// Casts all elements of `self` to `u64`.
+ #[inline]
+ #[must_use]
+ pub fn as_u64vec3(&self) -> crate::U64Vec3 {
+ crate::U64Vec3::new(self.x as u64, self.y as u64, self.z 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),
+ }
+ }
+
+ /// 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),
+ }
+ }
+
+ /// 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),
+ }
+ }
+
+ /// 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),
+ }
+ }
+
+ /// 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),
+ }
+ }
+
+ /// 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),
+ }
+ }
+
+ /// 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),
+ }
+ }
+
+ /// 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),
+ }
+ }
}
impl Default for UVec3 {
@@ -778,6 +952,30 @@ impl Shr<i32> for UVec3 {
}
}
+impl Shl<i64> for UVec3 {
+ 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),
+ }
+ }
+}
+
+impl Shr<i64> for UVec3 {
+ 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),
+ }
+ }
+}
+
impl Shl<u8> for UVec3 {
type Output = Self;
#[inline]
@@ -850,6 +1048,30 @@ impl Shr<u32> for UVec3 {
}
}
+impl Shl<u64> for UVec3 {
+ 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),
+ }
+ }
+}
+
+impl Shr<u64> for UVec3 {
+ 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),
+ }
+ }
+}
+
impl Shl<crate::IVec3> for UVec3 {
type Output = Self;
#[inline]
@@ -975,3 +1197,62 @@ impl From<(UVec2, u32)> for UVec3 {
Self::new(v.x, v.y, z)
}
}
+
+impl From<U16Vec3> for UVec3 {
+ #[inline]
+ fn from(v: U16Vec3) -> Self {
+ Self::new(u32::from(v.x), u32::from(v.y), u32::from(v.z))
+ }
+}
+
+impl TryFrom<I16Vec3> for UVec3 {
+ type Error = core::num::TryFromIntError;
+
+ #[inline]
+ fn try_from(v: I16Vec3) -> Result<Self, Self::Error> {
+ Ok(Self::new(
+ u32::try_from(v.x)?,
+ u32::try_from(v.y)?,
+ u32::try_from(v.z)?,
+ ))
+ }
+}
+
+impl TryFrom<IVec3> for UVec3 {
+ type Error = core::num::TryFromIntError;
+
+ #[inline]
+ fn try_from(v: IVec3) -> Result<Self, Self::Error> {
+ Ok(Self::new(
+ u32::try_from(v.x)?,
+ u32::try_from(v.y)?,
+ u32::try_from(v.z)?,
+ ))
+ }
+}
+
+impl TryFrom<I64Vec3> for UVec3 {
+ type Error = core::num::TryFromIntError;
+
+ #[inline]
+ fn try_from(v: I64Vec3) -> Result<Self, Self::Error> {
+ Ok(Self::new(
+ u32::try_from(v.x)?,
+ u32::try_from(v.y)?,
+ u32::try_from(v.z)?,
+ ))
+ }
+}
+
+impl TryFrom<U64Vec3> for UVec3 {
+ type Error = core::num::TryFromIntError;
+
+ #[inline]
+ fn try_from(v: U64Vec3) -> Result<Self, Self::Error> {
+ Ok(Self::new(
+ u32::try_from(v.x)?,
+ u32::try_from(v.y)?,
+ u32::try_from(v.z)?,
+ ))
+ }
+}