glam/usize/
usizevec4.rs

1// Generated from vec.rs.tera template. Edit the template, not the generated file.
2
3#[cfg(not(feature = "scalar-math"))]
4use crate::BVec4A;
5use crate::{
6    BVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, U8Vec4, USizeVec2, USizeVec3, UVec4,
7};
8
9use core::fmt;
10use core::iter::{Product, Sum};
11use core::{f32, ops::*};
12
13/// Creates a 4-dimensional vector.
14#[inline(always)]
15#[must_use]
16pub const fn usizevec4(x: usize, y: usize, z: usize, w: usize) -> USizeVec4 {
17    USizeVec4::new(x, y, z, w)
18}
19
20/// A 4-dimensional vector.
21#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
22#[derive(Clone, Copy, PartialEq, Eq)]
23#[cfg_attr(feature = "cuda", repr(align(16)))]
24#[cfg_attr(not(target_arch = "spirv"), repr(C))]
25#[cfg_attr(target_arch = "spirv", repr(simd))]
26pub struct USizeVec4 {
27    pub x: usize,
28    pub y: usize,
29    pub z: usize,
30    pub w: usize,
31}
32
33impl USizeVec4 {
34    /// All zeroes.
35    pub const ZERO: Self = Self::splat(0);
36
37    /// All ones.
38    pub const ONE: Self = Self::splat(1);
39
40    /// All `usize::MIN`.
41    pub const MIN: Self = Self::splat(usize::MIN);
42
43    /// All `usize::MAX`.
44    pub const MAX: Self = Self::splat(usize::MAX);
45
46    /// A unit vector pointing along the positive X axis.
47    pub const X: Self = Self::new(1, 0, 0, 0);
48
49    /// A unit vector pointing along the positive Y axis.
50    pub const Y: Self = Self::new(0, 1, 0, 0);
51
52    /// A unit vector pointing along the positive Z axis.
53    pub const Z: Self = Self::new(0, 0, 1, 0);
54
55    /// A unit vector pointing along the positive W axis.
56    pub const W: Self = Self::new(0, 0, 0, 1);
57
58    /// The unit axes.
59    pub const AXES: [Self; 4] = [Self::X, Self::Y, Self::Z, Self::W];
60
61    /// Creates a new vector.
62    #[inline(always)]
63    #[must_use]
64    pub const fn new(x: usize, y: usize, z: usize, w: usize) -> Self {
65        Self { x, y, z, w }
66    }
67
68    /// Creates a vector with all elements set to `v`.
69    #[inline]
70    #[must_use]
71    pub const fn splat(v: usize) -> Self {
72        Self {
73            x: v,
74
75            y: v,
76
77            z: v,
78
79            w: v,
80        }
81    }
82
83    /// Returns a vector containing each element of `self` modified by a mapping function `f`.
84    #[inline]
85    #[must_use]
86    pub fn map<F>(self, f: F) -> Self
87    where
88        F: Fn(usize) -> usize,
89    {
90        Self::new(f(self.x), f(self.y), f(self.z), f(self.w))
91    }
92
93    /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
94    /// for each element of `self`.
95    ///
96    /// A true element in the mask uses the corresponding element from `if_true`, and false
97    /// uses the element from `if_false`.
98    #[inline]
99    #[must_use]
100    pub fn select(mask: BVec4, if_true: Self, if_false: Self) -> Self {
101        Self {
102            x: if mask.test(0) { if_true.x } else { if_false.x },
103            y: if mask.test(1) { if_true.y } else { if_false.y },
104            z: if mask.test(2) { if_true.z } else { if_false.z },
105            w: if mask.test(3) { if_true.w } else { if_false.w },
106        }
107    }
108
109    /// Creates a new vector from an array.
110    #[inline]
111    #[must_use]
112    pub const fn from_array(a: [usize; 4]) -> Self {
113        Self::new(a[0], a[1], a[2], a[3])
114    }
115
116    /// `[x, y, z, w]`
117    #[inline]
118    #[must_use]
119    pub const fn to_array(&self) -> [usize; 4] {
120        [self.x, self.y, self.z, self.w]
121    }
122
123    /// Creates a vector from the first 4 values in `slice`.
124    ///
125    /// # Panics
126    ///
127    /// Panics if `slice` is less than 4 elements long.
128    #[inline]
129    #[must_use]
130    pub const fn from_slice(slice: &[usize]) -> Self {
131        assert!(slice.len() >= 4);
132        Self::new(slice[0], slice[1], slice[2], slice[3])
133    }
134
135    /// Writes the elements of `self` to the first 4 elements in `slice`.
136    ///
137    /// # Panics
138    ///
139    /// Panics if `slice` is less than 4 elements long.
140    #[inline]
141    pub fn write_to_slice(self, slice: &mut [usize]) {
142        slice[..4].copy_from_slice(&self.to_array());
143    }
144
145    /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`.
146    ///
147    /// Truncation to [`USizeVec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()].
148    #[inline]
149    #[must_use]
150    pub fn truncate(self) -> USizeVec3 {
151        use crate::swizzles::Vec4Swizzles;
152        self.xyz()
153    }
154
155    /// Creates a 4D vector from `self` with the given value of `x`.
156    #[inline]
157    #[must_use]
158    pub fn with_x(mut self, x: usize) -> Self {
159        self.x = x;
160        self
161    }
162
163    /// Creates a 4D vector from `self` with the given value of `y`.
164    #[inline]
165    #[must_use]
166    pub fn with_y(mut self, y: usize) -> Self {
167        self.y = y;
168        self
169    }
170
171    /// Creates a 4D vector from `self` with the given value of `z`.
172    #[inline]
173    #[must_use]
174    pub fn with_z(mut self, z: usize) -> Self {
175        self.z = z;
176        self
177    }
178
179    /// Creates a 4D vector from `self` with the given value of `w`.
180    #[inline]
181    #[must_use]
182    pub fn with_w(mut self, w: usize) -> Self {
183        self.w = w;
184        self
185    }
186
187    /// Computes the dot product of `self` and `rhs`.
188    #[inline]
189    #[must_use]
190    pub fn dot(self, rhs: Self) -> usize {
191        (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z) + (self.w * rhs.w)
192    }
193
194    /// Returns a vector where every component is the dot product of `self` and `rhs`.
195    #[inline]
196    #[must_use]
197    pub fn dot_into_vec(self, rhs: Self) -> Self {
198        Self::splat(self.dot(rhs))
199    }
200
201    /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
202    ///
203    /// In other words this computes `[min(x, rhs.x), min(self.y, rhs.y), ..]`.
204    #[inline]
205    #[must_use]
206    pub fn min(self, rhs: Self) -> Self {
207        Self {
208            x: if self.x < rhs.x { self.x } else { rhs.x },
209            y: if self.y < rhs.y { self.y } else { rhs.y },
210            z: if self.z < rhs.z { self.z } else { rhs.z },
211            w: if self.w < rhs.w { self.w } else { rhs.w },
212        }
213    }
214
215    /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
216    ///
217    /// In other words this computes `[max(self.x, rhs.x), max(self.y, rhs.y), ..]`.
218    #[inline]
219    #[must_use]
220    pub fn max(self, rhs: Self) -> Self {
221        Self {
222            x: if self.x > rhs.x { self.x } else { rhs.x },
223            y: if self.y > rhs.y { self.y } else { rhs.y },
224            z: if self.z > rhs.z { self.z } else { rhs.z },
225            w: if self.w > rhs.w { self.w } else { rhs.w },
226        }
227    }
228
229    /// Component-wise clamping of values, similar to [`usize::clamp`].
230    ///
231    /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
232    ///
233    /// # Panics
234    ///
235    /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
236    #[inline]
237    #[must_use]
238    pub fn clamp(self, min: Self, max: Self) -> Self {
239        glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
240        self.max(min).min(max)
241    }
242
243    /// Returns the horizontal minimum of `self`.
244    ///
245    /// In other words this computes `min(x, y, ..)`.
246    #[inline]
247    #[must_use]
248    pub fn min_element(self) -> usize {
249        let min = |a, b| if a < b { a } else { b };
250        min(self.x, min(self.y, min(self.z, self.w)))
251    }
252
253    /// Returns the horizontal maximum of `self`.
254    ///
255    /// In other words this computes `max(x, y, ..)`.
256    #[inline]
257    #[must_use]
258    pub fn max_element(self) -> usize {
259        let max = |a, b| if a > b { a } else { b };
260        max(self.x, max(self.y, max(self.z, self.w)))
261    }
262
263    /// Returns the index of the first minimum element of `self`.
264    #[doc(alias = "argmin")]
265    #[inline]
266    #[must_use]
267    pub fn min_position(self) -> usize {
268        let mut min = self.x;
269        let mut index = 0;
270        if self.y < min {
271            min = self.y;
272            index = 1;
273        }
274        if self.z < min {
275            min = self.z;
276            index = 2;
277        }
278        if self.w < min {
279            index = 3;
280        }
281        index
282    }
283
284    /// Returns the index of the first maximum element of `self`.
285    #[doc(alias = "argmax")]
286    #[inline]
287    #[must_use]
288    pub fn max_position(self) -> usize {
289        let mut max = self.x;
290        let mut index = 0;
291        if self.y > max {
292            max = self.y;
293            index = 1;
294        }
295        if self.z > max {
296            max = self.z;
297            index = 2;
298        }
299        if self.w > max {
300            index = 3;
301        }
302        index
303    }
304
305    /// Returns the sum of all elements of `self`.
306    ///
307    /// In other words, this computes `self.x + self.y + ..`.
308    #[inline]
309    #[must_use]
310    pub fn element_sum(self) -> usize {
311        self.x + self.y + self.z + self.w
312    }
313
314    /// Returns the product of all elements of `self`.
315    ///
316    /// In other words, this computes `self.x * self.y * ..`.
317    #[inline]
318    #[must_use]
319    pub fn element_product(self) -> usize {
320        self.x * self.y * self.z * self.w
321    }
322
323    /// Returns a vector mask containing the result of a `==` comparison for each element of
324    /// `self` and `rhs`.
325    ///
326    /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
327    /// elements.
328    #[inline]
329    #[must_use]
330    pub fn cmpeq(self, rhs: Self) -> BVec4 {
331        BVec4::new(
332            self.x.eq(&rhs.x),
333            self.y.eq(&rhs.y),
334            self.z.eq(&rhs.z),
335            self.w.eq(&rhs.w),
336        )
337    }
338
339    /// Returns a vector mask containing the result of a `!=` comparison for each element of
340    /// `self` and `rhs`.
341    ///
342    /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
343    /// elements.
344    #[inline]
345    #[must_use]
346    pub fn cmpne(self, rhs: Self) -> BVec4 {
347        BVec4::new(
348            self.x.ne(&rhs.x),
349            self.y.ne(&rhs.y),
350            self.z.ne(&rhs.z),
351            self.w.ne(&rhs.w),
352        )
353    }
354
355    /// Returns a vector mask containing the result of a `>=` comparison for each element of
356    /// `self` and `rhs`.
357    ///
358    /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
359    /// elements.
360    #[inline]
361    #[must_use]
362    pub fn cmpge(self, rhs: Self) -> BVec4 {
363        BVec4::new(
364            self.x.ge(&rhs.x),
365            self.y.ge(&rhs.y),
366            self.z.ge(&rhs.z),
367            self.w.ge(&rhs.w),
368        )
369    }
370
371    /// Returns a vector mask containing the result of a `>` comparison for each element of
372    /// `self` and `rhs`.
373    ///
374    /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
375    /// elements.
376    #[inline]
377    #[must_use]
378    pub fn cmpgt(self, rhs: Self) -> BVec4 {
379        BVec4::new(
380            self.x.gt(&rhs.x),
381            self.y.gt(&rhs.y),
382            self.z.gt(&rhs.z),
383            self.w.gt(&rhs.w),
384        )
385    }
386
387    /// Returns a vector mask containing the result of a `<=` comparison for each element of
388    /// `self` and `rhs`.
389    ///
390    /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
391    /// elements.
392    #[inline]
393    #[must_use]
394    pub fn cmple(self, rhs: Self) -> BVec4 {
395        BVec4::new(
396            self.x.le(&rhs.x),
397            self.y.le(&rhs.y),
398            self.z.le(&rhs.z),
399            self.w.le(&rhs.w),
400        )
401    }
402
403    /// Returns a vector mask containing the result of a `<` comparison for each element of
404    /// `self` and `rhs`.
405    ///
406    /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
407    /// elements.
408    #[inline]
409    #[must_use]
410    pub fn cmplt(self, rhs: Self) -> BVec4 {
411        BVec4::new(
412            self.x.lt(&rhs.x),
413            self.y.lt(&rhs.y),
414            self.z.lt(&rhs.z),
415            self.w.lt(&rhs.w),
416        )
417    }
418
419    /// Computes the squared length of `self`.
420    #[doc(alias = "magnitude2")]
421    #[inline]
422    #[must_use]
423    pub fn length_squared(self) -> usize {
424        self.dot(self)
425    }
426
427    /// Computes the [manhattan distance] between two points.
428    ///
429    /// # Overflow
430    /// This method may overflow if the result is greater than [`usize::MAX`].
431    ///
432    /// See also [`checked_manhattan_distance`][USizeVec4::checked_manhattan_distance].
433    ///
434    /// [manhattan distance]: https://en.wikipedia.org/wiki/Taxicab_geometry
435    #[inline]
436    #[must_use]
437    pub fn manhattan_distance(self, other: Self) -> usize {
438        self.x.abs_diff(other.x)
439            + self.y.abs_diff(other.y)
440            + self.z.abs_diff(other.z)
441            + self.w.abs_diff(other.w)
442    }
443
444    /// Computes the [manhattan distance] between two points.
445    ///
446    /// This will returns [`None`] if the result is greater than [`usize::MAX`].
447    ///
448    /// [manhattan distance]: https://en.wikipedia.org/wiki/Taxicab_geometry
449    #[inline]
450    #[must_use]
451    pub fn checked_manhattan_distance(self, other: Self) -> Option<usize> {
452        let d = self.x.abs_diff(other.x);
453        let d = d.checked_add(self.y.abs_diff(other.y))?;
454        let d = d.checked_add(self.z.abs_diff(other.z))?;
455        d.checked_add(self.w.abs_diff(other.w))
456    }
457
458    /// Computes the [chebyshev distance] between two points.
459    ///
460    /// [chebyshev distance]: https://en.wikipedia.org/wiki/Chebyshev_distance
461    #[inline]
462    #[must_use]
463    pub fn chebyshev_distance(self, other: Self) -> usize {
464        // Note: the compiler will eventually optimize out the loop
465        [
466            self.x.abs_diff(other.x),
467            self.y.abs_diff(other.y),
468            self.z.abs_diff(other.z),
469            self.w.abs_diff(other.w),
470        ]
471        .into_iter()
472        .max()
473        .unwrap()
474    }
475
476    /// Casts all elements of `self` to `f32`.
477    #[inline]
478    #[must_use]
479    pub fn as_vec4(&self) -> crate::Vec4 {
480        crate::Vec4::new(self.x as f32, self.y as f32, self.z as f32, self.w as f32)
481    }
482
483    /// Casts all elements of `self` to `f64`.
484    #[inline]
485    #[must_use]
486    pub fn as_dvec4(&self) -> crate::DVec4 {
487        crate::DVec4::new(self.x as f64, self.y as f64, self.z as f64, self.w as f64)
488    }
489
490    /// Casts all elements of `self` to `i8`.
491    #[inline]
492    #[must_use]
493    pub fn as_i8vec4(&self) -> crate::I8Vec4 {
494        crate::I8Vec4::new(self.x as i8, self.y as i8, self.z as i8, self.w as i8)
495    }
496
497    /// Casts all elements of `self` to `u8`.
498    #[inline]
499    #[must_use]
500    pub fn as_u8vec4(&self) -> crate::U8Vec4 {
501        crate::U8Vec4::new(self.x as u8, self.y as u8, self.z as u8, self.w as u8)
502    }
503
504    /// Casts all elements of `self` to `i16`.
505    #[inline]
506    #[must_use]
507    pub fn as_i16vec4(&self) -> crate::I16Vec4 {
508        crate::I16Vec4::new(self.x as i16, self.y as i16, self.z as i16, self.w as i16)
509    }
510
511    /// Casts all elements of `self` to `u16`.
512    #[inline]
513    #[must_use]
514    pub fn as_u16vec4(&self) -> crate::U16Vec4 {
515        crate::U16Vec4::new(self.x as u16, self.y as u16, self.z as u16, self.w as u16)
516    }
517
518    /// Casts all elements of `self` to `i32`.
519    #[inline]
520    #[must_use]
521    pub fn as_ivec4(&self) -> crate::IVec4 {
522        crate::IVec4::new(self.x as i32, self.y as i32, self.z as i32, self.w as i32)
523    }
524
525    /// Casts all elements of `self` to `u32`.
526    #[inline]
527    #[must_use]
528    pub fn as_uvec4(&self) -> crate::UVec4 {
529        crate::UVec4::new(self.x as u32, self.y as u32, self.z as u32, self.w as u32)
530    }
531
532    /// Casts all elements of `self` to `i64`.
533    #[inline]
534    #[must_use]
535    pub fn as_i64vec4(&self) -> crate::I64Vec4 {
536        crate::I64Vec4::new(self.x as i64, self.y as i64, self.z as i64, self.w as i64)
537    }
538
539    /// Casts all elements of `self` to `u64`.
540    #[inline]
541    #[must_use]
542    pub fn as_u64vec4(&self) -> crate::U64Vec4 {
543        crate::U64Vec4::new(self.x as u64, self.y as u64, self.z as u64, self.w as u64)
544    }
545
546    /// Returns a vector containing the wrapping addition of `self` and `rhs`.
547    ///
548    /// In other words this computes `Some([self.x + rhs.x, self.y + rhs.y, ..])` but returns `None` on any overflow.
549    #[inline]
550    #[must_use]
551    pub const fn checked_add(self, rhs: Self) -> Option<Self> {
552        let x = match self.x.checked_add(rhs.x) {
553            Some(v) => v,
554            None => return None,
555        };
556        let y = match self.y.checked_add(rhs.y) {
557            Some(v) => v,
558            None => return None,
559        };
560        let z = match self.z.checked_add(rhs.z) {
561            Some(v) => v,
562            None => return None,
563        };
564        let w = match self.w.checked_add(rhs.w) {
565            Some(v) => v,
566            None => return None,
567        };
568
569        Some(Self { x, y, z, w })
570    }
571
572    /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
573    ///
574    /// In other words this computes `Some([self.x - rhs.x, self.y - rhs.y, ..])` but returns `None` on any overflow.
575    #[inline]
576    #[must_use]
577    pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
578        let x = match self.x.checked_sub(rhs.x) {
579            Some(v) => v,
580            None => return None,
581        };
582        let y = match self.y.checked_sub(rhs.y) {
583            Some(v) => v,
584            None => return None,
585        };
586        let z = match self.z.checked_sub(rhs.z) {
587            Some(v) => v,
588            None => return None,
589        };
590        let w = match self.w.checked_sub(rhs.w) {
591            Some(v) => v,
592            None => return None,
593        };
594
595        Some(Self { x, y, z, w })
596    }
597
598    /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
599    ///
600    /// In other words this computes `Some([self.x * rhs.x, self.y * rhs.y, ..])` but returns `None` on any overflow.
601    #[inline]
602    #[must_use]
603    pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
604        let x = match self.x.checked_mul(rhs.x) {
605            Some(v) => v,
606            None => return None,
607        };
608        let y = match self.y.checked_mul(rhs.y) {
609            Some(v) => v,
610            None => return None,
611        };
612        let z = match self.z.checked_mul(rhs.z) {
613            Some(v) => v,
614            None => return None,
615        };
616        let w = match self.w.checked_mul(rhs.w) {
617            Some(v) => v,
618            None => return None,
619        };
620
621        Some(Self { x, y, z, w })
622    }
623
624    /// Returns a vector containing the wrapping division of `self` and `rhs`.
625    ///
626    /// In other words this computes `Some([self.x / rhs.x, self.y / rhs.y, ..])` but returns `None` on any division by zero.
627    #[inline]
628    #[must_use]
629    pub const fn checked_div(self, rhs: Self) -> Option<Self> {
630        let x = match self.x.checked_div(rhs.x) {
631            Some(v) => v,
632            None => return None,
633        };
634        let y = match self.y.checked_div(rhs.y) {
635            Some(v) => v,
636            None => return None,
637        };
638        let z = match self.z.checked_div(rhs.z) {
639            Some(v) => v,
640            None => return None,
641        };
642        let w = match self.w.checked_div(rhs.w) {
643            Some(v) => v,
644            None => return None,
645        };
646
647        Some(Self { x, y, z, w })
648    }
649
650    /// Returns a vector containing the wrapping addition of `self` and `rhs`.
651    ///
652    /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`.
653    #[inline]
654    #[must_use]
655    pub const fn wrapping_add(self, rhs: Self) -> Self {
656        Self {
657            x: self.x.wrapping_add(rhs.x),
658            y: self.y.wrapping_add(rhs.y),
659            z: self.z.wrapping_add(rhs.z),
660            w: self.w.wrapping_add(rhs.w),
661        }
662    }
663
664    /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
665    ///
666    /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`.
667    #[inline]
668    #[must_use]
669    pub const fn wrapping_sub(self, rhs: Self) -> Self {
670        Self {
671            x: self.x.wrapping_sub(rhs.x),
672            y: self.y.wrapping_sub(rhs.y),
673            z: self.z.wrapping_sub(rhs.z),
674            w: self.w.wrapping_sub(rhs.w),
675        }
676    }
677
678    /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
679    ///
680    /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`.
681    #[inline]
682    #[must_use]
683    pub const fn wrapping_mul(self, rhs: Self) -> Self {
684        Self {
685            x: self.x.wrapping_mul(rhs.x),
686            y: self.y.wrapping_mul(rhs.y),
687            z: self.z.wrapping_mul(rhs.z),
688            w: self.w.wrapping_mul(rhs.w),
689        }
690    }
691
692    /// Returns a vector containing the wrapping division of `self` and `rhs`.
693    ///
694    /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`.
695    #[inline]
696    #[must_use]
697    pub const fn wrapping_div(self, rhs: Self) -> Self {
698        Self {
699            x: self.x.wrapping_div(rhs.x),
700            y: self.y.wrapping_div(rhs.y),
701            z: self.z.wrapping_div(rhs.z),
702            w: self.w.wrapping_div(rhs.w),
703        }
704    }
705
706    /// Returns a vector containing the saturating addition of `self` and `rhs`.
707    ///
708    /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`.
709    #[inline]
710    #[must_use]
711    pub const fn saturating_add(self, rhs: Self) -> Self {
712        Self {
713            x: self.x.saturating_add(rhs.x),
714            y: self.y.saturating_add(rhs.y),
715            z: self.z.saturating_add(rhs.z),
716            w: self.w.saturating_add(rhs.w),
717        }
718    }
719
720    /// Returns a vector containing the saturating subtraction of `self` and `rhs`.
721    ///
722    /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`.
723    #[inline]
724    #[must_use]
725    pub const fn saturating_sub(self, rhs: Self) -> Self {
726        Self {
727            x: self.x.saturating_sub(rhs.x),
728            y: self.y.saturating_sub(rhs.y),
729            z: self.z.saturating_sub(rhs.z),
730            w: self.w.saturating_sub(rhs.w),
731        }
732    }
733
734    /// Returns a vector containing the saturating multiplication of `self` and `rhs`.
735    ///
736    /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`.
737    #[inline]
738    #[must_use]
739    pub const fn saturating_mul(self, rhs: Self) -> Self {
740        Self {
741            x: self.x.saturating_mul(rhs.x),
742            y: self.y.saturating_mul(rhs.y),
743            z: self.z.saturating_mul(rhs.z),
744            w: self.w.saturating_mul(rhs.w),
745        }
746    }
747
748    /// Returns a vector containing the saturating division of `self` and `rhs`.
749    ///
750    /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`.
751    #[inline]
752    #[must_use]
753    pub const fn saturating_div(self, rhs: Self) -> Self {
754        Self {
755            x: self.x.saturating_div(rhs.x),
756            y: self.y.saturating_div(rhs.y),
757            z: self.z.saturating_div(rhs.z),
758            w: self.w.saturating_div(rhs.w),
759        }
760    }
761}
762
763impl Default for USizeVec4 {
764    #[inline(always)]
765    fn default() -> Self {
766        Self::ZERO
767    }
768}
769
770impl Div<USizeVec4> for USizeVec4 {
771    type Output = Self;
772    #[inline]
773    fn div(self, rhs: Self) -> Self {
774        Self {
775            x: self.x.div(rhs.x),
776            y: self.y.div(rhs.y),
777            z: self.z.div(rhs.z),
778            w: self.w.div(rhs.w),
779        }
780    }
781}
782
783impl Div<&USizeVec4> for USizeVec4 {
784    type Output = USizeVec4;
785    #[inline]
786    fn div(self, rhs: &USizeVec4) -> USizeVec4 {
787        self.div(*rhs)
788    }
789}
790
791impl Div<&USizeVec4> for &USizeVec4 {
792    type Output = USizeVec4;
793    #[inline]
794    fn div(self, rhs: &USizeVec4) -> USizeVec4 {
795        (*self).div(*rhs)
796    }
797}
798
799impl Div<USizeVec4> for &USizeVec4 {
800    type Output = USizeVec4;
801    #[inline]
802    fn div(self, rhs: USizeVec4) -> USizeVec4 {
803        (*self).div(rhs)
804    }
805}
806
807impl DivAssign<USizeVec4> for USizeVec4 {
808    #[inline]
809    fn div_assign(&mut self, rhs: Self) {
810        self.x.div_assign(rhs.x);
811        self.y.div_assign(rhs.y);
812        self.z.div_assign(rhs.z);
813        self.w.div_assign(rhs.w);
814    }
815}
816
817impl DivAssign<&USizeVec4> for USizeVec4 {
818    #[inline]
819    fn div_assign(&mut self, rhs: &USizeVec4) {
820        self.div_assign(*rhs)
821    }
822}
823
824impl Div<usize> for USizeVec4 {
825    type Output = Self;
826    #[inline]
827    fn div(self, rhs: usize) -> Self {
828        Self {
829            x: self.x.div(rhs),
830            y: self.y.div(rhs),
831            z: self.z.div(rhs),
832            w: self.w.div(rhs),
833        }
834    }
835}
836
837impl Div<&usize> for USizeVec4 {
838    type Output = USizeVec4;
839    #[inline]
840    fn div(self, rhs: &usize) -> USizeVec4 {
841        self.div(*rhs)
842    }
843}
844
845impl Div<&usize> for &USizeVec4 {
846    type Output = USizeVec4;
847    #[inline]
848    fn div(self, rhs: &usize) -> USizeVec4 {
849        (*self).div(*rhs)
850    }
851}
852
853impl Div<usize> for &USizeVec4 {
854    type Output = USizeVec4;
855    #[inline]
856    fn div(self, rhs: usize) -> USizeVec4 {
857        (*self).div(rhs)
858    }
859}
860
861impl DivAssign<usize> for USizeVec4 {
862    #[inline]
863    fn div_assign(&mut self, rhs: usize) {
864        self.x.div_assign(rhs);
865        self.y.div_assign(rhs);
866        self.z.div_assign(rhs);
867        self.w.div_assign(rhs);
868    }
869}
870
871impl DivAssign<&usize> for USizeVec4 {
872    #[inline]
873    fn div_assign(&mut self, rhs: &usize) {
874        self.div_assign(*rhs)
875    }
876}
877
878impl Div<USizeVec4> for usize {
879    type Output = USizeVec4;
880    #[inline]
881    fn div(self, rhs: USizeVec4) -> USizeVec4 {
882        USizeVec4 {
883            x: self.div(rhs.x),
884            y: self.div(rhs.y),
885            z: self.div(rhs.z),
886            w: self.div(rhs.w),
887        }
888    }
889}
890
891impl Div<&USizeVec4> for usize {
892    type Output = USizeVec4;
893    #[inline]
894    fn div(self, rhs: &USizeVec4) -> USizeVec4 {
895        self.div(*rhs)
896    }
897}
898
899impl Div<&USizeVec4> for &usize {
900    type Output = USizeVec4;
901    #[inline]
902    fn div(self, rhs: &USizeVec4) -> USizeVec4 {
903        (*self).div(*rhs)
904    }
905}
906
907impl Div<USizeVec4> for &usize {
908    type Output = USizeVec4;
909    #[inline]
910    fn div(self, rhs: USizeVec4) -> USizeVec4 {
911        (*self).div(rhs)
912    }
913}
914
915impl Mul<USizeVec4> for USizeVec4 {
916    type Output = Self;
917    #[inline]
918    fn mul(self, rhs: Self) -> Self {
919        Self {
920            x: self.x.mul(rhs.x),
921            y: self.y.mul(rhs.y),
922            z: self.z.mul(rhs.z),
923            w: self.w.mul(rhs.w),
924        }
925    }
926}
927
928impl Mul<&USizeVec4> for USizeVec4 {
929    type Output = USizeVec4;
930    #[inline]
931    fn mul(self, rhs: &USizeVec4) -> USizeVec4 {
932        self.mul(*rhs)
933    }
934}
935
936impl Mul<&USizeVec4> for &USizeVec4 {
937    type Output = USizeVec4;
938    #[inline]
939    fn mul(self, rhs: &USizeVec4) -> USizeVec4 {
940        (*self).mul(*rhs)
941    }
942}
943
944impl Mul<USizeVec4> for &USizeVec4 {
945    type Output = USizeVec4;
946    #[inline]
947    fn mul(self, rhs: USizeVec4) -> USizeVec4 {
948        (*self).mul(rhs)
949    }
950}
951
952impl MulAssign<USizeVec4> for USizeVec4 {
953    #[inline]
954    fn mul_assign(&mut self, rhs: Self) {
955        self.x.mul_assign(rhs.x);
956        self.y.mul_assign(rhs.y);
957        self.z.mul_assign(rhs.z);
958        self.w.mul_assign(rhs.w);
959    }
960}
961
962impl MulAssign<&USizeVec4> for USizeVec4 {
963    #[inline]
964    fn mul_assign(&mut self, rhs: &USizeVec4) {
965        self.mul_assign(*rhs)
966    }
967}
968
969impl Mul<usize> for USizeVec4 {
970    type Output = Self;
971    #[inline]
972    fn mul(self, rhs: usize) -> Self {
973        Self {
974            x: self.x.mul(rhs),
975            y: self.y.mul(rhs),
976            z: self.z.mul(rhs),
977            w: self.w.mul(rhs),
978        }
979    }
980}
981
982impl Mul<&usize> for USizeVec4 {
983    type Output = USizeVec4;
984    #[inline]
985    fn mul(self, rhs: &usize) -> USizeVec4 {
986        self.mul(*rhs)
987    }
988}
989
990impl Mul<&usize> for &USizeVec4 {
991    type Output = USizeVec4;
992    #[inline]
993    fn mul(self, rhs: &usize) -> USizeVec4 {
994        (*self).mul(*rhs)
995    }
996}
997
998impl Mul<usize> for &USizeVec4 {
999    type Output = USizeVec4;
1000    #[inline]
1001    fn mul(self, rhs: usize) -> USizeVec4 {
1002        (*self).mul(rhs)
1003    }
1004}
1005
1006impl MulAssign<usize> for USizeVec4 {
1007    #[inline]
1008    fn mul_assign(&mut self, rhs: usize) {
1009        self.x.mul_assign(rhs);
1010        self.y.mul_assign(rhs);
1011        self.z.mul_assign(rhs);
1012        self.w.mul_assign(rhs);
1013    }
1014}
1015
1016impl MulAssign<&usize> for USizeVec4 {
1017    #[inline]
1018    fn mul_assign(&mut self, rhs: &usize) {
1019        self.mul_assign(*rhs)
1020    }
1021}
1022
1023impl Mul<USizeVec4> for usize {
1024    type Output = USizeVec4;
1025    #[inline]
1026    fn mul(self, rhs: USizeVec4) -> USizeVec4 {
1027        USizeVec4 {
1028            x: self.mul(rhs.x),
1029            y: self.mul(rhs.y),
1030            z: self.mul(rhs.z),
1031            w: self.mul(rhs.w),
1032        }
1033    }
1034}
1035
1036impl Mul<&USizeVec4> for usize {
1037    type Output = USizeVec4;
1038    #[inline]
1039    fn mul(self, rhs: &USizeVec4) -> USizeVec4 {
1040        self.mul(*rhs)
1041    }
1042}
1043
1044impl Mul<&USizeVec4> for &usize {
1045    type Output = USizeVec4;
1046    #[inline]
1047    fn mul(self, rhs: &USizeVec4) -> USizeVec4 {
1048        (*self).mul(*rhs)
1049    }
1050}
1051
1052impl Mul<USizeVec4> for &usize {
1053    type Output = USizeVec4;
1054    #[inline]
1055    fn mul(self, rhs: USizeVec4) -> USizeVec4 {
1056        (*self).mul(rhs)
1057    }
1058}
1059
1060impl Add<USizeVec4> for USizeVec4 {
1061    type Output = Self;
1062    #[inline]
1063    fn add(self, rhs: Self) -> Self {
1064        Self {
1065            x: self.x.add(rhs.x),
1066            y: self.y.add(rhs.y),
1067            z: self.z.add(rhs.z),
1068            w: self.w.add(rhs.w),
1069        }
1070    }
1071}
1072
1073impl Add<&USizeVec4> for USizeVec4 {
1074    type Output = USizeVec4;
1075    #[inline]
1076    fn add(self, rhs: &USizeVec4) -> USizeVec4 {
1077        self.add(*rhs)
1078    }
1079}
1080
1081impl Add<&USizeVec4> for &USizeVec4 {
1082    type Output = USizeVec4;
1083    #[inline]
1084    fn add(self, rhs: &USizeVec4) -> USizeVec4 {
1085        (*self).add(*rhs)
1086    }
1087}
1088
1089impl Add<USizeVec4> for &USizeVec4 {
1090    type Output = USizeVec4;
1091    #[inline]
1092    fn add(self, rhs: USizeVec4) -> USizeVec4 {
1093        (*self).add(rhs)
1094    }
1095}
1096
1097impl AddAssign<USizeVec4> for USizeVec4 {
1098    #[inline]
1099    fn add_assign(&mut self, rhs: Self) {
1100        self.x.add_assign(rhs.x);
1101        self.y.add_assign(rhs.y);
1102        self.z.add_assign(rhs.z);
1103        self.w.add_assign(rhs.w);
1104    }
1105}
1106
1107impl AddAssign<&USizeVec4> for USizeVec4 {
1108    #[inline]
1109    fn add_assign(&mut self, rhs: &USizeVec4) {
1110        self.add_assign(*rhs)
1111    }
1112}
1113
1114impl Add<usize> for USizeVec4 {
1115    type Output = Self;
1116    #[inline]
1117    fn add(self, rhs: usize) -> Self {
1118        Self {
1119            x: self.x.add(rhs),
1120            y: self.y.add(rhs),
1121            z: self.z.add(rhs),
1122            w: self.w.add(rhs),
1123        }
1124    }
1125}
1126
1127impl Add<&usize> for USizeVec4 {
1128    type Output = USizeVec4;
1129    #[inline]
1130    fn add(self, rhs: &usize) -> USizeVec4 {
1131        self.add(*rhs)
1132    }
1133}
1134
1135impl Add<&usize> for &USizeVec4 {
1136    type Output = USizeVec4;
1137    #[inline]
1138    fn add(self, rhs: &usize) -> USizeVec4 {
1139        (*self).add(*rhs)
1140    }
1141}
1142
1143impl Add<usize> for &USizeVec4 {
1144    type Output = USizeVec4;
1145    #[inline]
1146    fn add(self, rhs: usize) -> USizeVec4 {
1147        (*self).add(rhs)
1148    }
1149}
1150
1151impl AddAssign<usize> for USizeVec4 {
1152    #[inline]
1153    fn add_assign(&mut self, rhs: usize) {
1154        self.x.add_assign(rhs);
1155        self.y.add_assign(rhs);
1156        self.z.add_assign(rhs);
1157        self.w.add_assign(rhs);
1158    }
1159}
1160
1161impl AddAssign<&usize> for USizeVec4 {
1162    #[inline]
1163    fn add_assign(&mut self, rhs: &usize) {
1164        self.add_assign(*rhs)
1165    }
1166}
1167
1168impl Add<USizeVec4> for usize {
1169    type Output = USizeVec4;
1170    #[inline]
1171    fn add(self, rhs: USizeVec4) -> USizeVec4 {
1172        USizeVec4 {
1173            x: self.add(rhs.x),
1174            y: self.add(rhs.y),
1175            z: self.add(rhs.z),
1176            w: self.add(rhs.w),
1177        }
1178    }
1179}
1180
1181impl Add<&USizeVec4> for usize {
1182    type Output = USizeVec4;
1183    #[inline]
1184    fn add(self, rhs: &USizeVec4) -> USizeVec4 {
1185        self.add(*rhs)
1186    }
1187}
1188
1189impl Add<&USizeVec4> for &usize {
1190    type Output = USizeVec4;
1191    #[inline]
1192    fn add(self, rhs: &USizeVec4) -> USizeVec4 {
1193        (*self).add(*rhs)
1194    }
1195}
1196
1197impl Add<USizeVec4> for &usize {
1198    type Output = USizeVec4;
1199    #[inline]
1200    fn add(self, rhs: USizeVec4) -> USizeVec4 {
1201        (*self).add(rhs)
1202    }
1203}
1204
1205impl Sub<USizeVec4> for USizeVec4 {
1206    type Output = Self;
1207    #[inline]
1208    fn sub(self, rhs: Self) -> Self {
1209        Self {
1210            x: self.x.sub(rhs.x),
1211            y: self.y.sub(rhs.y),
1212            z: self.z.sub(rhs.z),
1213            w: self.w.sub(rhs.w),
1214        }
1215    }
1216}
1217
1218impl Sub<&USizeVec4> for USizeVec4 {
1219    type Output = USizeVec4;
1220    #[inline]
1221    fn sub(self, rhs: &USizeVec4) -> USizeVec4 {
1222        self.sub(*rhs)
1223    }
1224}
1225
1226impl Sub<&USizeVec4> for &USizeVec4 {
1227    type Output = USizeVec4;
1228    #[inline]
1229    fn sub(self, rhs: &USizeVec4) -> USizeVec4 {
1230        (*self).sub(*rhs)
1231    }
1232}
1233
1234impl Sub<USizeVec4> for &USizeVec4 {
1235    type Output = USizeVec4;
1236    #[inline]
1237    fn sub(self, rhs: USizeVec4) -> USizeVec4 {
1238        (*self).sub(rhs)
1239    }
1240}
1241
1242impl SubAssign<USizeVec4> for USizeVec4 {
1243    #[inline]
1244    fn sub_assign(&mut self, rhs: USizeVec4) {
1245        self.x.sub_assign(rhs.x);
1246        self.y.sub_assign(rhs.y);
1247        self.z.sub_assign(rhs.z);
1248        self.w.sub_assign(rhs.w);
1249    }
1250}
1251
1252impl SubAssign<&USizeVec4> for USizeVec4 {
1253    #[inline]
1254    fn sub_assign(&mut self, rhs: &USizeVec4) {
1255        self.sub_assign(*rhs)
1256    }
1257}
1258
1259impl Sub<usize> for USizeVec4 {
1260    type Output = Self;
1261    #[inline]
1262    fn sub(self, rhs: usize) -> Self {
1263        Self {
1264            x: self.x.sub(rhs),
1265            y: self.y.sub(rhs),
1266            z: self.z.sub(rhs),
1267            w: self.w.sub(rhs),
1268        }
1269    }
1270}
1271
1272impl Sub<&usize> for USizeVec4 {
1273    type Output = USizeVec4;
1274    #[inline]
1275    fn sub(self, rhs: &usize) -> USizeVec4 {
1276        self.sub(*rhs)
1277    }
1278}
1279
1280impl Sub<&usize> for &USizeVec4 {
1281    type Output = USizeVec4;
1282    #[inline]
1283    fn sub(self, rhs: &usize) -> USizeVec4 {
1284        (*self).sub(*rhs)
1285    }
1286}
1287
1288impl Sub<usize> for &USizeVec4 {
1289    type Output = USizeVec4;
1290    #[inline]
1291    fn sub(self, rhs: usize) -> USizeVec4 {
1292        (*self).sub(rhs)
1293    }
1294}
1295
1296impl SubAssign<usize> for USizeVec4 {
1297    #[inline]
1298    fn sub_assign(&mut self, rhs: usize) {
1299        self.x.sub_assign(rhs);
1300        self.y.sub_assign(rhs);
1301        self.z.sub_assign(rhs);
1302        self.w.sub_assign(rhs);
1303    }
1304}
1305
1306impl SubAssign<&usize> for USizeVec4 {
1307    #[inline]
1308    fn sub_assign(&mut self, rhs: &usize) {
1309        self.sub_assign(*rhs)
1310    }
1311}
1312
1313impl Sub<USizeVec4> for usize {
1314    type Output = USizeVec4;
1315    #[inline]
1316    fn sub(self, rhs: USizeVec4) -> USizeVec4 {
1317        USizeVec4 {
1318            x: self.sub(rhs.x),
1319            y: self.sub(rhs.y),
1320            z: self.sub(rhs.z),
1321            w: self.sub(rhs.w),
1322        }
1323    }
1324}
1325
1326impl Sub<&USizeVec4> for usize {
1327    type Output = USizeVec4;
1328    #[inline]
1329    fn sub(self, rhs: &USizeVec4) -> USizeVec4 {
1330        self.sub(*rhs)
1331    }
1332}
1333
1334impl Sub<&USizeVec4> for &usize {
1335    type Output = USizeVec4;
1336    #[inline]
1337    fn sub(self, rhs: &USizeVec4) -> USizeVec4 {
1338        (*self).sub(*rhs)
1339    }
1340}
1341
1342impl Sub<USizeVec4> for &usize {
1343    type Output = USizeVec4;
1344    #[inline]
1345    fn sub(self, rhs: USizeVec4) -> USizeVec4 {
1346        (*self).sub(rhs)
1347    }
1348}
1349
1350impl Rem<USizeVec4> for USizeVec4 {
1351    type Output = Self;
1352    #[inline]
1353    fn rem(self, rhs: Self) -> Self {
1354        Self {
1355            x: self.x.rem(rhs.x),
1356            y: self.y.rem(rhs.y),
1357            z: self.z.rem(rhs.z),
1358            w: self.w.rem(rhs.w),
1359        }
1360    }
1361}
1362
1363impl Rem<&USizeVec4> for USizeVec4 {
1364    type Output = USizeVec4;
1365    #[inline]
1366    fn rem(self, rhs: &USizeVec4) -> USizeVec4 {
1367        self.rem(*rhs)
1368    }
1369}
1370
1371impl Rem<&USizeVec4> for &USizeVec4 {
1372    type Output = USizeVec4;
1373    #[inline]
1374    fn rem(self, rhs: &USizeVec4) -> USizeVec4 {
1375        (*self).rem(*rhs)
1376    }
1377}
1378
1379impl Rem<USizeVec4> for &USizeVec4 {
1380    type Output = USizeVec4;
1381    #[inline]
1382    fn rem(self, rhs: USizeVec4) -> USizeVec4 {
1383        (*self).rem(rhs)
1384    }
1385}
1386
1387impl RemAssign<USizeVec4> for USizeVec4 {
1388    #[inline]
1389    fn rem_assign(&mut self, rhs: Self) {
1390        self.x.rem_assign(rhs.x);
1391        self.y.rem_assign(rhs.y);
1392        self.z.rem_assign(rhs.z);
1393        self.w.rem_assign(rhs.w);
1394    }
1395}
1396
1397impl RemAssign<&USizeVec4> for USizeVec4 {
1398    #[inline]
1399    fn rem_assign(&mut self, rhs: &USizeVec4) {
1400        self.rem_assign(*rhs)
1401    }
1402}
1403
1404impl Rem<usize> for USizeVec4 {
1405    type Output = Self;
1406    #[inline]
1407    fn rem(self, rhs: usize) -> Self {
1408        Self {
1409            x: self.x.rem(rhs),
1410            y: self.y.rem(rhs),
1411            z: self.z.rem(rhs),
1412            w: self.w.rem(rhs),
1413        }
1414    }
1415}
1416
1417impl Rem<&usize> for USizeVec4 {
1418    type Output = USizeVec4;
1419    #[inline]
1420    fn rem(self, rhs: &usize) -> USizeVec4 {
1421        self.rem(*rhs)
1422    }
1423}
1424
1425impl Rem<&usize> for &USizeVec4 {
1426    type Output = USizeVec4;
1427    #[inline]
1428    fn rem(self, rhs: &usize) -> USizeVec4 {
1429        (*self).rem(*rhs)
1430    }
1431}
1432
1433impl Rem<usize> for &USizeVec4 {
1434    type Output = USizeVec4;
1435    #[inline]
1436    fn rem(self, rhs: usize) -> USizeVec4 {
1437        (*self).rem(rhs)
1438    }
1439}
1440
1441impl RemAssign<usize> for USizeVec4 {
1442    #[inline]
1443    fn rem_assign(&mut self, rhs: usize) {
1444        self.x.rem_assign(rhs);
1445        self.y.rem_assign(rhs);
1446        self.z.rem_assign(rhs);
1447        self.w.rem_assign(rhs);
1448    }
1449}
1450
1451impl RemAssign<&usize> for USizeVec4 {
1452    #[inline]
1453    fn rem_assign(&mut self, rhs: &usize) {
1454        self.rem_assign(*rhs)
1455    }
1456}
1457
1458impl Rem<USizeVec4> for usize {
1459    type Output = USizeVec4;
1460    #[inline]
1461    fn rem(self, rhs: USizeVec4) -> USizeVec4 {
1462        USizeVec4 {
1463            x: self.rem(rhs.x),
1464            y: self.rem(rhs.y),
1465            z: self.rem(rhs.z),
1466            w: self.rem(rhs.w),
1467        }
1468    }
1469}
1470
1471impl Rem<&USizeVec4> for usize {
1472    type Output = USizeVec4;
1473    #[inline]
1474    fn rem(self, rhs: &USizeVec4) -> USizeVec4 {
1475        self.rem(*rhs)
1476    }
1477}
1478
1479impl Rem<&USizeVec4> for &usize {
1480    type Output = USizeVec4;
1481    #[inline]
1482    fn rem(self, rhs: &USizeVec4) -> USizeVec4 {
1483        (*self).rem(*rhs)
1484    }
1485}
1486
1487impl Rem<USizeVec4> for &usize {
1488    type Output = USizeVec4;
1489    #[inline]
1490    fn rem(self, rhs: USizeVec4) -> USizeVec4 {
1491        (*self).rem(rhs)
1492    }
1493}
1494
1495#[cfg(not(target_arch = "spirv"))]
1496impl AsRef<[usize; 4]> for USizeVec4 {
1497    #[inline]
1498    fn as_ref(&self) -> &[usize; 4] {
1499        unsafe { &*(self as *const USizeVec4 as *const [usize; 4]) }
1500    }
1501}
1502
1503#[cfg(not(target_arch = "spirv"))]
1504impl AsMut<[usize; 4]> for USizeVec4 {
1505    #[inline]
1506    fn as_mut(&mut self) -> &mut [usize; 4] {
1507        unsafe { &mut *(self as *mut USizeVec4 as *mut [usize; 4]) }
1508    }
1509}
1510
1511impl Sum for USizeVec4 {
1512    #[inline]
1513    fn sum<I>(iter: I) -> Self
1514    where
1515        I: Iterator<Item = Self>,
1516    {
1517        iter.fold(Self::ZERO, Self::add)
1518    }
1519}
1520
1521impl<'a> Sum<&'a Self> for USizeVec4 {
1522    #[inline]
1523    fn sum<I>(iter: I) -> Self
1524    where
1525        I: Iterator<Item = &'a Self>,
1526    {
1527        iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1528    }
1529}
1530
1531impl Product for USizeVec4 {
1532    #[inline]
1533    fn product<I>(iter: I) -> Self
1534    where
1535        I: Iterator<Item = Self>,
1536    {
1537        iter.fold(Self::ONE, Self::mul)
1538    }
1539}
1540
1541impl<'a> Product<&'a Self> for USizeVec4 {
1542    #[inline]
1543    fn product<I>(iter: I) -> Self
1544    where
1545        I: Iterator<Item = &'a Self>,
1546    {
1547        iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1548    }
1549}
1550
1551impl Not for USizeVec4 {
1552    type Output = Self;
1553    #[inline]
1554    fn not(self) -> Self::Output {
1555        Self {
1556            x: self.x.not(),
1557            y: self.y.not(),
1558            z: self.z.not(),
1559            w: self.w.not(),
1560        }
1561    }
1562}
1563
1564impl BitAnd for USizeVec4 {
1565    type Output = Self;
1566    #[inline]
1567    fn bitand(self, rhs: Self) -> Self::Output {
1568        Self {
1569            x: self.x.bitand(rhs.x),
1570            y: self.y.bitand(rhs.y),
1571            z: self.z.bitand(rhs.z),
1572            w: self.w.bitand(rhs.w),
1573        }
1574    }
1575}
1576
1577impl BitOr for USizeVec4 {
1578    type Output = Self;
1579    #[inline]
1580    fn bitor(self, rhs: Self) -> Self::Output {
1581        Self {
1582            x: self.x.bitor(rhs.x),
1583            y: self.y.bitor(rhs.y),
1584            z: self.z.bitor(rhs.z),
1585            w: self.w.bitor(rhs.w),
1586        }
1587    }
1588}
1589
1590impl BitXor for USizeVec4 {
1591    type Output = Self;
1592    #[inline]
1593    fn bitxor(self, rhs: Self) -> Self::Output {
1594        Self {
1595            x: self.x.bitxor(rhs.x),
1596            y: self.y.bitxor(rhs.y),
1597            z: self.z.bitxor(rhs.z),
1598            w: self.w.bitxor(rhs.w),
1599        }
1600    }
1601}
1602
1603impl BitAnd<usize> for USizeVec4 {
1604    type Output = Self;
1605    #[inline]
1606    fn bitand(self, rhs: usize) -> Self::Output {
1607        Self {
1608            x: self.x.bitand(rhs),
1609            y: self.y.bitand(rhs),
1610            z: self.z.bitand(rhs),
1611            w: self.w.bitand(rhs),
1612        }
1613    }
1614}
1615
1616impl BitOr<usize> for USizeVec4 {
1617    type Output = Self;
1618    #[inline]
1619    fn bitor(self, rhs: usize) -> Self::Output {
1620        Self {
1621            x: self.x.bitor(rhs),
1622            y: self.y.bitor(rhs),
1623            z: self.z.bitor(rhs),
1624            w: self.w.bitor(rhs),
1625        }
1626    }
1627}
1628
1629impl BitXor<usize> for USizeVec4 {
1630    type Output = Self;
1631    #[inline]
1632    fn bitxor(self, rhs: usize) -> Self::Output {
1633        Self {
1634            x: self.x.bitxor(rhs),
1635            y: self.y.bitxor(rhs),
1636            z: self.z.bitxor(rhs),
1637            w: self.w.bitxor(rhs),
1638        }
1639    }
1640}
1641
1642impl Shl<i8> for USizeVec4 {
1643    type Output = Self;
1644    #[inline]
1645    fn shl(self, rhs: i8) -> Self::Output {
1646        Self {
1647            x: self.x.shl(rhs),
1648            y: self.y.shl(rhs),
1649            z: self.z.shl(rhs),
1650            w: self.w.shl(rhs),
1651        }
1652    }
1653}
1654
1655impl Shr<i8> for USizeVec4 {
1656    type Output = Self;
1657    #[inline]
1658    fn shr(self, rhs: i8) -> Self::Output {
1659        Self {
1660            x: self.x.shr(rhs),
1661            y: self.y.shr(rhs),
1662            z: self.z.shr(rhs),
1663            w: self.w.shr(rhs),
1664        }
1665    }
1666}
1667
1668impl Shl<i16> for USizeVec4 {
1669    type Output = Self;
1670    #[inline]
1671    fn shl(self, rhs: i16) -> Self::Output {
1672        Self {
1673            x: self.x.shl(rhs),
1674            y: self.y.shl(rhs),
1675            z: self.z.shl(rhs),
1676            w: self.w.shl(rhs),
1677        }
1678    }
1679}
1680
1681impl Shr<i16> for USizeVec4 {
1682    type Output = Self;
1683    #[inline]
1684    fn shr(self, rhs: i16) -> Self::Output {
1685        Self {
1686            x: self.x.shr(rhs),
1687            y: self.y.shr(rhs),
1688            z: self.z.shr(rhs),
1689            w: self.w.shr(rhs),
1690        }
1691    }
1692}
1693
1694impl Shl<i32> for USizeVec4 {
1695    type Output = Self;
1696    #[inline]
1697    fn shl(self, rhs: i32) -> Self::Output {
1698        Self {
1699            x: self.x.shl(rhs),
1700            y: self.y.shl(rhs),
1701            z: self.z.shl(rhs),
1702            w: self.w.shl(rhs),
1703        }
1704    }
1705}
1706
1707impl Shr<i32> for USizeVec4 {
1708    type Output = Self;
1709    #[inline]
1710    fn shr(self, rhs: i32) -> Self::Output {
1711        Self {
1712            x: self.x.shr(rhs),
1713            y: self.y.shr(rhs),
1714            z: self.z.shr(rhs),
1715            w: self.w.shr(rhs),
1716        }
1717    }
1718}
1719
1720impl Shl<i64> for USizeVec4 {
1721    type Output = Self;
1722    #[inline]
1723    fn shl(self, rhs: i64) -> Self::Output {
1724        Self {
1725            x: self.x.shl(rhs),
1726            y: self.y.shl(rhs),
1727            z: self.z.shl(rhs),
1728            w: self.w.shl(rhs),
1729        }
1730    }
1731}
1732
1733impl Shr<i64> for USizeVec4 {
1734    type Output = Self;
1735    #[inline]
1736    fn shr(self, rhs: i64) -> Self::Output {
1737        Self {
1738            x: self.x.shr(rhs),
1739            y: self.y.shr(rhs),
1740            z: self.z.shr(rhs),
1741            w: self.w.shr(rhs),
1742        }
1743    }
1744}
1745
1746impl Shl<u8> for USizeVec4 {
1747    type Output = Self;
1748    #[inline]
1749    fn shl(self, rhs: u8) -> Self::Output {
1750        Self {
1751            x: self.x.shl(rhs),
1752            y: self.y.shl(rhs),
1753            z: self.z.shl(rhs),
1754            w: self.w.shl(rhs),
1755        }
1756    }
1757}
1758
1759impl Shr<u8> for USizeVec4 {
1760    type Output = Self;
1761    #[inline]
1762    fn shr(self, rhs: u8) -> Self::Output {
1763        Self {
1764            x: self.x.shr(rhs),
1765            y: self.y.shr(rhs),
1766            z: self.z.shr(rhs),
1767            w: self.w.shr(rhs),
1768        }
1769    }
1770}
1771
1772impl Shl<u16> for USizeVec4 {
1773    type Output = Self;
1774    #[inline]
1775    fn shl(self, rhs: u16) -> Self::Output {
1776        Self {
1777            x: self.x.shl(rhs),
1778            y: self.y.shl(rhs),
1779            z: self.z.shl(rhs),
1780            w: self.w.shl(rhs),
1781        }
1782    }
1783}
1784
1785impl Shr<u16> for USizeVec4 {
1786    type Output = Self;
1787    #[inline]
1788    fn shr(self, rhs: u16) -> Self::Output {
1789        Self {
1790            x: self.x.shr(rhs),
1791            y: self.y.shr(rhs),
1792            z: self.z.shr(rhs),
1793            w: self.w.shr(rhs),
1794        }
1795    }
1796}
1797
1798impl Shl<u32> for USizeVec4 {
1799    type Output = Self;
1800    #[inline]
1801    fn shl(self, rhs: u32) -> Self::Output {
1802        Self {
1803            x: self.x.shl(rhs),
1804            y: self.y.shl(rhs),
1805            z: self.z.shl(rhs),
1806            w: self.w.shl(rhs),
1807        }
1808    }
1809}
1810
1811impl Shr<u32> for USizeVec4 {
1812    type Output = Self;
1813    #[inline]
1814    fn shr(self, rhs: u32) -> Self::Output {
1815        Self {
1816            x: self.x.shr(rhs),
1817            y: self.y.shr(rhs),
1818            z: self.z.shr(rhs),
1819            w: self.w.shr(rhs),
1820        }
1821    }
1822}
1823
1824impl Shl<u64> for USizeVec4 {
1825    type Output = Self;
1826    #[inline]
1827    fn shl(self, rhs: u64) -> Self::Output {
1828        Self {
1829            x: self.x.shl(rhs),
1830            y: self.y.shl(rhs),
1831            z: self.z.shl(rhs),
1832            w: self.w.shl(rhs),
1833        }
1834    }
1835}
1836
1837impl Shr<u64> for USizeVec4 {
1838    type Output = Self;
1839    #[inline]
1840    fn shr(self, rhs: u64) -> Self::Output {
1841        Self {
1842            x: self.x.shr(rhs),
1843            y: self.y.shr(rhs),
1844            z: self.z.shr(rhs),
1845            w: self.w.shr(rhs),
1846        }
1847    }
1848}
1849
1850impl Shl<crate::IVec4> for USizeVec4 {
1851    type Output = Self;
1852    #[inline]
1853    fn shl(self, rhs: crate::IVec4) -> Self::Output {
1854        Self {
1855            x: self.x.shl(rhs.x),
1856            y: self.y.shl(rhs.y),
1857            z: self.z.shl(rhs.z),
1858            w: self.w.shl(rhs.w),
1859        }
1860    }
1861}
1862
1863impl Shr<crate::IVec4> for USizeVec4 {
1864    type Output = Self;
1865    #[inline]
1866    fn shr(self, rhs: crate::IVec4) -> Self::Output {
1867        Self {
1868            x: self.x.shr(rhs.x),
1869            y: self.y.shr(rhs.y),
1870            z: self.z.shr(rhs.z),
1871            w: self.w.shr(rhs.w),
1872        }
1873    }
1874}
1875
1876impl Shl<crate::UVec4> for USizeVec4 {
1877    type Output = Self;
1878    #[inline]
1879    fn shl(self, rhs: crate::UVec4) -> Self::Output {
1880        Self {
1881            x: self.x.shl(rhs.x),
1882            y: self.y.shl(rhs.y),
1883            z: self.z.shl(rhs.z),
1884            w: self.w.shl(rhs.w),
1885        }
1886    }
1887}
1888
1889impl Shr<crate::UVec4> for USizeVec4 {
1890    type Output = Self;
1891    #[inline]
1892    fn shr(self, rhs: crate::UVec4) -> Self::Output {
1893        Self {
1894            x: self.x.shr(rhs.x),
1895            y: self.y.shr(rhs.y),
1896            z: self.z.shr(rhs.z),
1897            w: self.w.shr(rhs.w),
1898        }
1899    }
1900}
1901
1902impl Index<usize> for USizeVec4 {
1903    type Output = usize;
1904    #[inline]
1905    fn index(&self, index: usize) -> &Self::Output {
1906        match index {
1907            0 => &self.x,
1908            1 => &self.y,
1909            2 => &self.z,
1910            3 => &self.w,
1911            _ => panic!("index out of bounds"),
1912        }
1913    }
1914}
1915
1916impl IndexMut<usize> for USizeVec4 {
1917    #[inline]
1918    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1919        match index {
1920            0 => &mut self.x,
1921            1 => &mut self.y,
1922            2 => &mut self.z,
1923            3 => &mut self.w,
1924            _ => panic!("index out of bounds"),
1925        }
1926    }
1927}
1928
1929impl fmt::Display for USizeVec4 {
1930    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1931        write!(f, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w)
1932    }
1933}
1934
1935impl fmt::Debug for USizeVec4 {
1936    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1937        fmt.debug_tuple(stringify!(USizeVec4))
1938            .field(&self.x)
1939            .field(&self.y)
1940            .field(&self.z)
1941            .field(&self.w)
1942            .finish()
1943    }
1944}
1945
1946impl From<[usize; 4]> for USizeVec4 {
1947    #[inline]
1948    fn from(a: [usize; 4]) -> Self {
1949        Self::new(a[0], a[1], a[2], a[3])
1950    }
1951}
1952
1953impl From<USizeVec4> for [usize; 4] {
1954    #[inline]
1955    fn from(v: USizeVec4) -> Self {
1956        [v.x, v.y, v.z, v.w]
1957    }
1958}
1959
1960impl From<(usize, usize, usize, usize)> for USizeVec4 {
1961    #[inline]
1962    fn from(t: (usize, usize, usize, usize)) -> Self {
1963        Self::new(t.0, t.1, t.2, t.3)
1964    }
1965}
1966
1967impl From<USizeVec4> for (usize, usize, usize, usize) {
1968    #[inline]
1969    fn from(v: USizeVec4) -> Self {
1970        (v.x, v.y, v.z, v.w)
1971    }
1972}
1973
1974impl From<(USizeVec3, usize)> for USizeVec4 {
1975    #[inline]
1976    fn from((v, w): (USizeVec3, usize)) -> Self {
1977        Self::new(v.x, v.y, v.z, w)
1978    }
1979}
1980
1981impl From<(usize, USizeVec3)> for USizeVec4 {
1982    #[inline]
1983    fn from((x, v): (usize, USizeVec3)) -> Self {
1984        Self::new(x, v.x, v.y, v.z)
1985    }
1986}
1987
1988impl From<(USizeVec2, usize, usize)> for USizeVec4 {
1989    #[inline]
1990    fn from((v, z, w): (USizeVec2, usize, usize)) -> Self {
1991        Self::new(v.x, v.y, z, w)
1992    }
1993}
1994
1995impl From<(USizeVec2, USizeVec2)> for USizeVec4 {
1996    #[inline]
1997    fn from((v, u): (USizeVec2, USizeVec2)) -> Self {
1998        Self::new(v.x, v.y, u.x, u.y)
1999    }
2000}
2001
2002impl From<U8Vec4> for USizeVec4 {
2003    #[inline]
2004    fn from(v: U8Vec4) -> Self {
2005        Self::new(
2006            usize::from(v.x),
2007            usize::from(v.y),
2008            usize::from(v.z),
2009            usize::from(v.w),
2010        )
2011    }
2012}
2013
2014impl From<U16Vec4> for USizeVec4 {
2015    #[inline]
2016    fn from(v: U16Vec4) -> Self {
2017        Self::new(
2018            usize::from(v.x),
2019            usize::from(v.y),
2020            usize::from(v.z),
2021            usize::from(v.w),
2022        )
2023    }
2024}
2025
2026impl TryFrom<I8Vec4> for USizeVec4 {
2027    type Error = core::num::TryFromIntError;
2028
2029    #[inline]
2030    fn try_from(v: I8Vec4) -> Result<Self, Self::Error> {
2031        Ok(Self::new(
2032            usize::try_from(v.x)?,
2033            usize::try_from(v.y)?,
2034            usize::try_from(v.z)?,
2035            usize::try_from(v.w)?,
2036        ))
2037    }
2038}
2039
2040impl TryFrom<I16Vec4> for USizeVec4 {
2041    type Error = core::num::TryFromIntError;
2042
2043    #[inline]
2044    fn try_from(v: I16Vec4) -> Result<Self, Self::Error> {
2045        Ok(Self::new(
2046            usize::try_from(v.x)?,
2047            usize::try_from(v.y)?,
2048            usize::try_from(v.z)?,
2049            usize::try_from(v.w)?,
2050        ))
2051    }
2052}
2053
2054impl TryFrom<IVec4> for USizeVec4 {
2055    type Error = core::num::TryFromIntError;
2056
2057    #[inline]
2058    fn try_from(v: IVec4) -> Result<Self, Self::Error> {
2059        Ok(Self::new(
2060            usize::try_from(v.x)?,
2061            usize::try_from(v.y)?,
2062            usize::try_from(v.z)?,
2063            usize::try_from(v.w)?,
2064        ))
2065    }
2066}
2067
2068impl TryFrom<I64Vec4> for USizeVec4 {
2069    type Error = core::num::TryFromIntError;
2070
2071    #[inline]
2072    fn try_from(v: I64Vec4) -> Result<Self, Self::Error> {
2073        Ok(Self::new(
2074            usize::try_from(v.x)?,
2075            usize::try_from(v.y)?,
2076            usize::try_from(v.z)?,
2077            usize::try_from(v.w)?,
2078        ))
2079    }
2080}
2081
2082impl TryFrom<UVec4> for USizeVec4 {
2083    type Error = core::num::TryFromIntError;
2084
2085    #[inline]
2086    fn try_from(v: UVec4) -> Result<Self, Self::Error> {
2087        Ok(Self::new(
2088            usize::try_from(v.x)?,
2089            usize::try_from(v.y)?,
2090            usize::try_from(v.z)?,
2091            usize::try_from(v.w)?,
2092        ))
2093    }
2094}
2095
2096impl TryFrom<U64Vec4> for USizeVec4 {
2097    type Error = core::num::TryFromIntError;
2098
2099    #[inline]
2100    fn try_from(v: U64Vec4) -> Result<Self, Self::Error> {
2101        Ok(Self::new(
2102            usize::try_from(v.x)?,
2103            usize::try_from(v.y)?,
2104            usize::try_from(v.z)?,
2105            usize::try_from(v.w)?,
2106        ))
2107    }
2108}
2109
2110impl From<BVec4> for USizeVec4 {
2111    #[inline]
2112    fn from(v: BVec4) -> Self {
2113        Self::new(
2114            usize::from(v.x),
2115            usize::from(v.y),
2116            usize::from(v.z),
2117            usize::from(v.w),
2118        )
2119    }
2120}
2121
2122#[cfg(not(feature = "scalar-math"))]
2123impl From<BVec4A> for USizeVec4 {
2124    #[inline]
2125    fn from(v: BVec4A) -> Self {
2126        let bool_array: [bool; 4] = v.into();
2127        Self::new(
2128            usize::from(bool_array[0]),
2129            usize::from(bool_array[1]),
2130            usize::from(bool_array[2]),
2131            usize::from(bool_array[3]),
2132        )
2133    }
2134}