1use crate::{BVec4, I16Vec4, I64Vec4, IVec4, U16Vec4, U64Vec4, UVec2, UVec3};
4
5#[cfg(not(target_arch = "spirv"))]
6use core::fmt;
7use core::iter::{Product, Sum};
8use core::{f32, ops::*};
9
10#[inline(always)]
12#[must_use]
13pub const fn uvec4(x: u32, y: u32, z: u32, w: u32) -> UVec4 {
14 UVec4::new(x, y, z, w)
15}
16
17#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
19#[derive(Clone, Copy, PartialEq, Eq)]
20#[cfg_attr(feature = "cuda", repr(align(16)))]
21#[cfg_attr(not(target_arch = "spirv"), repr(C))]
22#[cfg_attr(target_arch = "spirv", repr(simd))]
23pub struct UVec4 {
24 pub x: u32,
25 pub y: u32,
26 pub z: u32,
27 pub w: u32,
28}
29
30impl UVec4 {
31 pub const ZERO: Self = Self::splat(0);
33
34 pub const ONE: Self = Self::splat(1);
36
37 pub const MIN: Self = Self::splat(u32::MIN);
39
40 pub const MAX: Self = Self::splat(u32::MAX);
42
43 pub const X: Self = Self::new(1, 0, 0, 0);
45
46 pub const Y: Self = Self::new(0, 1, 0, 0);
48
49 pub const Z: Self = Self::new(0, 0, 1, 0);
51
52 pub const W: Self = Self::new(0, 0, 0, 1);
54
55 pub const AXES: [Self; 4] = [Self::X, Self::Y, Self::Z, Self::W];
57
58 #[inline(always)]
60 #[must_use]
61 pub const fn new(x: u32, y: u32, z: u32, w: u32) -> Self {
62 Self { x, y, z, w }
63 }
64
65 #[inline]
67 #[must_use]
68 pub const fn splat(v: u32) -> Self {
69 Self {
70 x: v,
71
72 y: v,
73
74 z: v,
75
76 w: v,
77 }
78 }
79
80 #[inline]
86 #[must_use]
87 pub fn select(mask: BVec4, if_true: Self, if_false: Self) -> Self {
88 Self {
89 x: if mask.test(0) { if_true.x } else { if_false.x },
90 y: if mask.test(1) { if_true.y } else { if_false.y },
91 z: if mask.test(2) { if_true.z } else { if_false.z },
92 w: if mask.test(3) { if_true.w } else { if_false.w },
93 }
94 }
95
96 #[inline]
98 #[must_use]
99 pub const fn from_array(a: [u32; 4]) -> Self {
100 Self::new(a[0], a[1], a[2], a[3])
101 }
102
103 #[inline]
105 #[must_use]
106 pub const fn to_array(&self) -> [u32; 4] {
107 [self.x, self.y, self.z, self.w]
108 }
109
110 #[inline]
116 #[must_use]
117 pub const fn from_slice(slice: &[u32]) -> Self {
118 Self::new(slice[0], slice[1], slice[2], slice[3])
119 }
120
121 #[inline]
127 pub fn write_to_slice(self, slice: &mut [u32]) {
128 slice[0] = self.x;
129 slice[1] = self.y;
130 slice[2] = self.z;
131 slice[3] = self.w;
132 }
133
134 #[inline]
138 #[must_use]
139 pub fn truncate(self) -> UVec3 {
140 use crate::swizzles::Vec4Swizzles;
141 self.xyz()
142 }
143
144 #[inline]
146 #[must_use]
147 pub fn dot(self, rhs: Self) -> u32 {
148 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z) + (self.w * rhs.w)
149 }
150
151 #[inline]
153 #[must_use]
154 pub fn dot_into_vec(self, rhs: Self) -> Self {
155 Self::splat(self.dot(rhs))
156 }
157
158 #[inline]
162 #[must_use]
163 pub fn min(self, rhs: Self) -> Self {
164 Self {
165 x: self.x.min(rhs.x),
166 y: self.y.min(rhs.y),
167 z: self.z.min(rhs.z),
168 w: self.w.min(rhs.w),
169 }
170 }
171
172 #[inline]
176 #[must_use]
177 pub fn max(self, rhs: Self) -> Self {
178 Self {
179 x: self.x.max(rhs.x),
180 y: self.y.max(rhs.y),
181 z: self.z.max(rhs.z),
182 w: self.w.max(rhs.w),
183 }
184 }
185
186 #[inline]
194 #[must_use]
195 pub fn clamp(self, min: Self, max: Self) -> Self {
196 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
197 self.max(min).min(max)
198 }
199
200 #[inline]
204 #[must_use]
205 pub fn min_element(self) -> u32 {
206 self.x.min(self.y.min(self.z.min(self.w)))
207 }
208
209 #[inline]
213 #[must_use]
214 pub fn max_element(self) -> u32 {
215 self.x.max(self.y.max(self.z.max(self.w)))
216 }
217
218 #[inline]
224 #[must_use]
225 pub fn cmpeq(self, rhs: Self) -> BVec4 {
226 BVec4::new(
227 self.x.eq(&rhs.x),
228 self.y.eq(&rhs.y),
229 self.z.eq(&rhs.z),
230 self.w.eq(&rhs.w),
231 )
232 }
233
234 #[inline]
240 #[must_use]
241 pub fn cmpne(self, rhs: Self) -> BVec4 {
242 BVec4::new(
243 self.x.ne(&rhs.x),
244 self.y.ne(&rhs.y),
245 self.z.ne(&rhs.z),
246 self.w.ne(&rhs.w),
247 )
248 }
249
250 #[inline]
256 #[must_use]
257 pub fn cmpge(self, rhs: Self) -> BVec4 {
258 BVec4::new(
259 self.x.ge(&rhs.x),
260 self.y.ge(&rhs.y),
261 self.z.ge(&rhs.z),
262 self.w.ge(&rhs.w),
263 )
264 }
265
266 #[inline]
272 #[must_use]
273 pub fn cmpgt(self, rhs: Self) -> BVec4 {
274 BVec4::new(
275 self.x.gt(&rhs.x),
276 self.y.gt(&rhs.y),
277 self.z.gt(&rhs.z),
278 self.w.gt(&rhs.w),
279 )
280 }
281
282 #[inline]
288 #[must_use]
289 pub fn cmple(self, rhs: Self) -> BVec4 {
290 BVec4::new(
291 self.x.le(&rhs.x),
292 self.y.le(&rhs.y),
293 self.z.le(&rhs.z),
294 self.w.le(&rhs.w),
295 )
296 }
297
298 #[inline]
304 #[must_use]
305 pub fn cmplt(self, rhs: Self) -> BVec4 {
306 BVec4::new(
307 self.x.lt(&rhs.x),
308 self.y.lt(&rhs.y),
309 self.z.lt(&rhs.z),
310 self.w.lt(&rhs.w),
311 )
312 }
313
314 #[doc(alias = "magnitude2")]
316 #[inline]
317 #[must_use]
318 pub fn length_squared(self) -> u32 {
319 self.dot(self)
320 }
321
322 #[inline]
324 #[must_use]
325 pub fn as_vec4(&self) -> crate::Vec4 {
326 crate::Vec4::new(self.x as f32, self.y as f32, self.z as f32, self.w as f32)
327 }
328
329 #[inline]
331 #[must_use]
332 pub fn as_dvec4(&self) -> crate::DVec4 {
333 crate::DVec4::new(self.x as f64, self.y as f64, self.z as f64, self.w as f64)
334 }
335
336 #[inline]
338 #[must_use]
339 pub fn as_i16vec4(&self) -> crate::I16Vec4 {
340 crate::I16Vec4::new(self.x as i16, self.y as i16, self.z as i16, self.w as i16)
341 }
342
343 #[inline]
345 #[must_use]
346 pub fn as_u16vec4(&self) -> crate::U16Vec4 {
347 crate::U16Vec4::new(self.x as u16, self.y as u16, self.z as u16, self.w as u16)
348 }
349
350 #[inline]
352 #[must_use]
353 pub fn as_ivec4(&self) -> crate::IVec4 {
354 crate::IVec4::new(self.x as i32, self.y as i32, self.z as i32, self.w as i32)
355 }
356
357 #[inline]
359 #[must_use]
360 pub fn as_i64vec4(&self) -> crate::I64Vec4 {
361 crate::I64Vec4::new(self.x as i64, self.y as i64, self.z as i64, self.w as i64)
362 }
363
364 #[inline]
366 #[must_use]
367 pub fn as_u64vec4(&self) -> crate::U64Vec4 {
368 crate::U64Vec4::new(self.x as u64, self.y as u64, self.z as u64, self.w as u64)
369 }
370
371 #[inline]
375 #[must_use]
376 pub const fn wrapping_add(self, rhs: Self) -> Self {
377 Self {
378 x: self.x.wrapping_add(rhs.x),
379 y: self.y.wrapping_add(rhs.y),
380 z: self.z.wrapping_add(rhs.z),
381 w: self.w.wrapping_add(rhs.w),
382 }
383 }
384
385 #[inline]
389 #[must_use]
390 pub const fn wrapping_sub(self, rhs: Self) -> Self {
391 Self {
392 x: self.x.wrapping_sub(rhs.x),
393 y: self.y.wrapping_sub(rhs.y),
394 z: self.z.wrapping_sub(rhs.z),
395 w: self.w.wrapping_sub(rhs.w),
396 }
397 }
398
399 #[inline]
403 #[must_use]
404 pub const fn wrapping_mul(self, rhs: Self) -> Self {
405 Self {
406 x: self.x.wrapping_mul(rhs.x),
407 y: self.y.wrapping_mul(rhs.y),
408 z: self.z.wrapping_mul(rhs.z),
409 w: self.w.wrapping_mul(rhs.w),
410 }
411 }
412
413 #[inline]
417 #[must_use]
418 pub const fn wrapping_div(self, rhs: Self) -> Self {
419 Self {
420 x: self.x.wrapping_div(rhs.x),
421 y: self.y.wrapping_div(rhs.y),
422 z: self.z.wrapping_div(rhs.z),
423 w: self.w.wrapping_div(rhs.w),
424 }
425 }
426
427 #[inline]
431 #[must_use]
432 pub const fn saturating_add(self, rhs: Self) -> Self {
433 Self {
434 x: self.x.saturating_add(rhs.x),
435 y: self.y.saturating_add(rhs.y),
436 z: self.z.saturating_add(rhs.z),
437 w: self.w.saturating_add(rhs.w),
438 }
439 }
440
441 #[inline]
445 #[must_use]
446 pub const fn saturating_sub(self, rhs: Self) -> Self {
447 Self {
448 x: self.x.saturating_sub(rhs.x),
449 y: self.y.saturating_sub(rhs.y),
450 z: self.z.saturating_sub(rhs.z),
451 w: self.w.saturating_sub(rhs.w),
452 }
453 }
454
455 #[inline]
459 #[must_use]
460 pub const fn saturating_mul(self, rhs: Self) -> Self {
461 Self {
462 x: self.x.saturating_mul(rhs.x),
463 y: self.y.saturating_mul(rhs.y),
464 z: self.z.saturating_mul(rhs.z),
465 w: self.w.saturating_mul(rhs.w),
466 }
467 }
468
469 #[inline]
473 #[must_use]
474 pub const fn saturating_div(self, rhs: Self) -> Self {
475 Self {
476 x: self.x.saturating_div(rhs.x),
477 y: self.y.saturating_div(rhs.y),
478 z: self.z.saturating_div(rhs.z),
479 w: self.w.saturating_div(rhs.w),
480 }
481 }
482}
483
484impl Default for UVec4 {
485 #[inline(always)]
486 fn default() -> Self {
487 Self::ZERO
488 }
489}
490
491impl Div<UVec4> for UVec4 {
492 type Output = Self;
493 #[inline]
494 fn div(self, rhs: Self) -> Self {
495 Self {
496 x: self.x.div(rhs.x),
497 y: self.y.div(rhs.y),
498 z: self.z.div(rhs.z),
499 w: self.w.div(rhs.w),
500 }
501 }
502}
503
504impl DivAssign<UVec4> for UVec4 {
505 #[inline]
506 fn div_assign(&mut self, rhs: Self) {
507 self.x.div_assign(rhs.x);
508 self.y.div_assign(rhs.y);
509 self.z.div_assign(rhs.z);
510 self.w.div_assign(rhs.w);
511 }
512}
513
514impl Div<u32> for UVec4 {
515 type Output = Self;
516 #[inline]
517 fn div(self, rhs: u32) -> Self {
518 Self {
519 x: self.x.div(rhs),
520 y: self.y.div(rhs),
521 z: self.z.div(rhs),
522 w: self.w.div(rhs),
523 }
524 }
525}
526
527impl DivAssign<u32> for UVec4 {
528 #[inline]
529 fn div_assign(&mut self, rhs: u32) {
530 self.x.div_assign(rhs);
531 self.y.div_assign(rhs);
532 self.z.div_assign(rhs);
533 self.w.div_assign(rhs);
534 }
535}
536
537impl Div<UVec4> for u32 {
538 type Output = UVec4;
539 #[inline]
540 fn div(self, rhs: UVec4) -> UVec4 {
541 UVec4 {
542 x: self.div(rhs.x),
543 y: self.div(rhs.y),
544 z: self.div(rhs.z),
545 w: self.div(rhs.w),
546 }
547 }
548}
549
550impl Mul<UVec4> for UVec4 {
551 type Output = Self;
552 #[inline]
553 fn mul(self, rhs: Self) -> Self {
554 Self {
555 x: self.x.mul(rhs.x),
556 y: self.y.mul(rhs.y),
557 z: self.z.mul(rhs.z),
558 w: self.w.mul(rhs.w),
559 }
560 }
561}
562
563impl MulAssign<UVec4> for UVec4 {
564 #[inline]
565 fn mul_assign(&mut self, rhs: Self) {
566 self.x.mul_assign(rhs.x);
567 self.y.mul_assign(rhs.y);
568 self.z.mul_assign(rhs.z);
569 self.w.mul_assign(rhs.w);
570 }
571}
572
573impl Mul<u32> for UVec4 {
574 type Output = Self;
575 #[inline]
576 fn mul(self, rhs: u32) -> Self {
577 Self {
578 x: self.x.mul(rhs),
579 y: self.y.mul(rhs),
580 z: self.z.mul(rhs),
581 w: self.w.mul(rhs),
582 }
583 }
584}
585
586impl MulAssign<u32> for UVec4 {
587 #[inline]
588 fn mul_assign(&mut self, rhs: u32) {
589 self.x.mul_assign(rhs);
590 self.y.mul_assign(rhs);
591 self.z.mul_assign(rhs);
592 self.w.mul_assign(rhs);
593 }
594}
595
596impl Mul<UVec4> for u32 {
597 type Output = UVec4;
598 #[inline]
599 fn mul(self, rhs: UVec4) -> UVec4 {
600 UVec4 {
601 x: self.mul(rhs.x),
602 y: self.mul(rhs.y),
603 z: self.mul(rhs.z),
604 w: self.mul(rhs.w),
605 }
606 }
607}
608
609impl Add<UVec4> for UVec4 {
610 type Output = Self;
611 #[inline]
612 fn add(self, rhs: Self) -> Self {
613 Self {
614 x: self.x.add(rhs.x),
615 y: self.y.add(rhs.y),
616 z: self.z.add(rhs.z),
617 w: self.w.add(rhs.w),
618 }
619 }
620}
621
622impl AddAssign<UVec4> for UVec4 {
623 #[inline]
624 fn add_assign(&mut self, rhs: Self) {
625 self.x.add_assign(rhs.x);
626 self.y.add_assign(rhs.y);
627 self.z.add_assign(rhs.z);
628 self.w.add_assign(rhs.w);
629 }
630}
631
632impl Add<u32> for UVec4 {
633 type Output = Self;
634 #[inline]
635 fn add(self, rhs: u32) -> Self {
636 Self {
637 x: self.x.add(rhs),
638 y: self.y.add(rhs),
639 z: self.z.add(rhs),
640 w: self.w.add(rhs),
641 }
642 }
643}
644
645impl AddAssign<u32> for UVec4 {
646 #[inline]
647 fn add_assign(&mut self, rhs: u32) {
648 self.x.add_assign(rhs);
649 self.y.add_assign(rhs);
650 self.z.add_assign(rhs);
651 self.w.add_assign(rhs);
652 }
653}
654
655impl Add<UVec4> for u32 {
656 type Output = UVec4;
657 #[inline]
658 fn add(self, rhs: UVec4) -> UVec4 {
659 UVec4 {
660 x: self.add(rhs.x),
661 y: self.add(rhs.y),
662 z: self.add(rhs.z),
663 w: self.add(rhs.w),
664 }
665 }
666}
667
668impl Sub<UVec4> for UVec4 {
669 type Output = Self;
670 #[inline]
671 fn sub(self, rhs: Self) -> Self {
672 Self {
673 x: self.x.sub(rhs.x),
674 y: self.y.sub(rhs.y),
675 z: self.z.sub(rhs.z),
676 w: self.w.sub(rhs.w),
677 }
678 }
679}
680
681impl SubAssign<UVec4> for UVec4 {
682 #[inline]
683 fn sub_assign(&mut self, rhs: UVec4) {
684 self.x.sub_assign(rhs.x);
685 self.y.sub_assign(rhs.y);
686 self.z.sub_assign(rhs.z);
687 self.w.sub_assign(rhs.w);
688 }
689}
690
691impl Sub<u32> for UVec4 {
692 type Output = Self;
693 #[inline]
694 fn sub(self, rhs: u32) -> Self {
695 Self {
696 x: self.x.sub(rhs),
697 y: self.y.sub(rhs),
698 z: self.z.sub(rhs),
699 w: self.w.sub(rhs),
700 }
701 }
702}
703
704impl SubAssign<u32> for UVec4 {
705 #[inline]
706 fn sub_assign(&mut self, rhs: u32) {
707 self.x.sub_assign(rhs);
708 self.y.sub_assign(rhs);
709 self.z.sub_assign(rhs);
710 self.w.sub_assign(rhs);
711 }
712}
713
714impl Sub<UVec4> for u32 {
715 type Output = UVec4;
716 #[inline]
717 fn sub(self, rhs: UVec4) -> UVec4 {
718 UVec4 {
719 x: self.sub(rhs.x),
720 y: self.sub(rhs.y),
721 z: self.sub(rhs.z),
722 w: self.sub(rhs.w),
723 }
724 }
725}
726
727impl Rem<UVec4> for UVec4 {
728 type Output = Self;
729 #[inline]
730 fn rem(self, rhs: Self) -> Self {
731 Self {
732 x: self.x.rem(rhs.x),
733 y: self.y.rem(rhs.y),
734 z: self.z.rem(rhs.z),
735 w: self.w.rem(rhs.w),
736 }
737 }
738}
739
740impl RemAssign<UVec4> for UVec4 {
741 #[inline]
742 fn rem_assign(&mut self, rhs: Self) {
743 self.x.rem_assign(rhs.x);
744 self.y.rem_assign(rhs.y);
745 self.z.rem_assign(rhs.z);
746 self.w.rem_assign(rhs.w);
747 }
748}
749
750impl Rem<u32> for UVec4 {
751 type Output = Self;
752 #[inline]
753 fn rem(self, rhs: u32) -> Self {
754 Self {
755 x: self.x.rem(rhs),
756 y: self.y.rem(rhs),
757 z: self.z.rem(rhs),
758 w: self.w.rem(rhs),
759 }
760 }
761}
762
763impl RemAssign<u32> for UVec4 {
764 #[inline]
765 fn rem_assign(&mut self, rhs: u32) {
766 self.x.rem_assign(rhs);
767 self.y.rem_assign(rhs);
768 self.z.rem_assign(rhs);
769 self.w.rem_assign(rhs);
770 }
771}
772
773impl Rem<UVec4> for u32 {
774 type Output = UVec4;
775 #[inline]
776 fn rem(self, rhs: UVec4) -> UVec4 {
777 UVec4 {
778 x: self.rem(rhs.x),
779 y: self.rem(rhs.y),
780 z: self.rem(rhs.z),
781 w: self.rem(rhs.w),
782 }
783 }
784}
785
786#[cfg(not(target_arch = "spirv"))]
787impl AsRef<[u32; 4]> for UVec4 {
788 #[inline]
789 fn as_ref(&self) -> &[u32; 4] {
790 unsafe { &*(self as *const UVec4 as *const [u32; 4]) }
791 }
792}
793
794#[cfg(not(target_arch = "spirv"))]
795impl AsMut<[u32; 4]> for UVec4 {
796 #[inline]
797 fn as_mut(&mut self) -> &mut [u32; 4] {
798 unsafe { &mut *(self as *mut UVec4 as *mut [u32; 4]) }
799 }
800}
801
802impl Sum for UVec4 {
803 #[inline]
804 fn sum<I>(iter: I) -> Self
805 where
806 I: Iterator<Item = Self>,
807 {
808 iter.fold(Self::ZERO, Self::add)
809 }
810}
811
812impl<'a> Sum<&'a Self> for UVec4 {
813 #[inline]
814 fn sum<I>(iter: I) -> Self
815 where
816 I: Iterator<Item = &'a Self>,
817 {
818 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
819 }
820}
821
822impl Product for UVec4 {
823 #[inline]
824 fn product<I>(iter: I) -> Self
825 where
826 I: Iterator<Item = Self>,
827 {
828 iter.fold(Self::ONE, Self::mul)
829 }
830}
831
832impl<'a> Product<&'a Self> for UVec4 {
833 #[inline]
834 fn product<I>(iter: I) -> Self
835 where
836 I: Iterator<Item = &'a Self>,
837 {
838 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
839 }
840}
841
842impl Not for UVec4 {
843 type Output = Self;
844 #[inline]
845 fn not(self) -> Self::Output {
846 Self {
847 x: self.x.not(),
848 y: self.y.not(),
849 z: self.z.not(),
850 w: self.w.not(),
851 }
852 }
853}
854
855impl BitAnd for UVec4 {
856 type Output = Self;
857 #[inline]
858 fn bitand(self, rhs: Self) -> Self::Output {
859 Self {
860 x: self.x.bitand(rhs.x),
861 y: self.y.bitand(rhs.y),
862 z: self.z.bitand(rhs.z),
863 w: self.w.bitand(rhs.w),
864 }
865 }
866}
867
868impl BitOr for UVec4 {
869 type Output = Self;
870 #[inline]
871 fn bitor(self, rhs: Self) -> Self::Output {
872 Self {
873 x: self.x.bitor(rhs.x),
874 y: self.y.bitor(rhs.y),
875 z: self.z.bitor(rhs.z),
876 w: self.w.bitor(rhs.w),
877 }
878 }
879}
880
881impl BitXor for UVec4 {
882 type Output = Self;
883 #[inline]
884 fn bitxor(self, rhs: Self) -> Self::Output {
885 Self {
886 x: self.x.bitxor(rhs.x),
887 y: self.y.bitxor(rhs.y),
888 z: self.z.bitxor(rhs.z),
889 w: self.w.bitxor(rhs.w),
890 }
891 }
892}
893
894impl BitAnd<u32> for UVec4 {
895 type Output = Self;
896 #[inline]
897 fn bitand(self, rhs: u32) -> Self::Output {
898 Self {
899 x: self.x.bitand(rhs),
900 y: self.y.bitand(rhs),
901 z: self.z.bitand(rhs),
902 w: self.w.bitand(rhs),
903 }
904 }
905}
906
907impl BitOr<u32> for UVec4 {
908 type Output = Self;
909 #[inline]
910 fn bitor(self, rhs: u32) -> Self::Output {
911 Self {
912 x: self.x.bitor(rhs),
913 y: self.y.bitor(rhs),
914 z: self.z.bitor(rhs),
915 w: self.w.bitor(rhs),
916 }
917 }
918}
919
920impl BitXor<u32> for UVec4 {
921 type Output = Self;
922 #[inline]
923 fn bitxor(self, rhs: u32) -> Self::Output {
924 Self {
925 x: self.x.bitxor(rhs),
926 y: self.y.bitxor(rhs),
927 z: self.z.bitxor(rhs),
928 w: self.w.bitxor(rhs),
929 }
930 }
931}
932
933impl Shl<i8> for UVec4 {
934 type Output = Self;
935 #[inline]
936 fn shl(self, rhs: i8) -> Self::Output {
937 Self {
938 x: self.x.shl(rhs),
939 y: self.y.shl(rhs),
940 z: self.z.shl(rhs),
941 w: self.w.shl(rhs),
942 }
943 }
944}
945
946impl Shr<i8> for UVec4 {
947 type Output = Self;
948 #[inline]
949 fn shr(self, rhs: i8) -> Self::Output {
950 Self {
951 x: self.x.shr(rhs),
952 y: self.y.shr(rhs),
953 z: self.z.shr(rhs),
954 w: self.w.shr(rhs),
955 }
956 }
957}
958
959impl Shl<i16> for UVec4 {
960 type Output = Self;
961 #[inline]
962 fn shl(self, rhs: i16) -> Self::Output {
963 Self {
964 x: self.x.shl(rhs),
965 y: self.y.shl(rhs),
966 z: self.z.shl(rhs),
967 w: self.w.shl(rhs),
968 }
969 }
970}
971
972impl Shr<i16> for UVec4 {
973 type Output = Self;
974 #[inline]
975 fn shr(self, rhs: i16) -> Self::Output {
976 Self {
977 x: self.x.shr(rhs),
978 y: self.y.shr(rhs),
979 z: self.z.shr(rhs),
980 w: self.w.shr(rhs),
981 }
982 }
983}
984
985impl Shl<i32> for UVec4 {
986 type Output = Self;
987 #[inline]
988 fn shl(self, rhs: i32) -> Self::Output {
989 Self {
990 x: self.x.shl(rhs),
991 y: self.y.shl(rhs),
992 z: self.z.shl(rhs),
993 w: self.w.shl(rhs),
994 }
995 }
996}
997
998impl Shr<i32> for UVec4 {
999 type Output = Self;
1000 #[inline]
1001 fn shr(self, rhs: i32) -> Self::Output {
1002 Self {
1003 x: self.x.shr(rhs),
1004 y: self.y.shr(rhs),
1005 z: self.z.shr(rhs),
1006 w: self.w.shr(rhs),
1007 }
1008 }
1009}
1010
1011impl Shl<i64> for UVec4 {
1012 type Output = Self;
1013 #[inline]
1014 fn shl(self, rhs: i64) -> Self::Output {
1015 Self {
1016 x: self.x.shl(rhs),
1017 y: self.y.shl(rhs),
1018 z: self.z.shl(rhs),
1019 w: self.w.shl(rhs),
1020 }
1021 }
1022}
1023
1024impl Shr<i64> for UVec4 {
1025 type Output = Self;
1026 #[inline]
1027 fn shr(self, rhs: i64) -> Self::Output {
1028 Self {
1029 x: self.x.shr(rhs),
1030 y: self.y.shr(rhs),
1031 z: self.z.shr(rhs),
1032 w: self.w.shr(rhs),
1033 }
1034 }
1035}
1036
1037impl Shl<u8> for UVec4 {
1038 type Output = Self;
1039 #[inline]
1040 fn shl(self, rhs: u8) -> Self::Output {
1041 Self {
1042 x: self.x.shl(rhs),
1043 y: self.y.shl(rhs),
1044 z: self.z.shl(rhs),
1045 w: self.w.shl(rhs),
1046 }
1047 }
1048}
1049
1050impl Shr<u8> for UVec4 {
1051 type Output = Self;
1052 #[inline]
1053 fn shr(self, rhs: u8) -> Self::Output {
1054 Self {
1055 x: self.x.shr(rhs),
1056 y: self.y.shr(rhs),
1057 z: self.z.shr(rhs),
1058 w: self.w.shr(rhs),
1059 }
1060 }
1061}
1062
1063impl Shl<u16> for UVec4 {
1064 type Output = Self;
1065 #[inline]
1066 fn shl(self, rhs: u16) -> Self::Output {
1067 Self {
1068 x: self.x.shl(rhs),
1069 y: self.y.shl(rhs),
1070 z: self.z.shl(rhs),
1071 w: self.w.shl(rhs),
1072 }
1073 }
1074}
1075
1076impl Shr<u16> for UVec4 {
1077 type Output = Self;
1078 #[inline]
1079 fn shr(self, rhs: u16) -> Self::Output {
1080 Self {
1081 x: self.x.shr(rhs),
1082 y: self.y.shr(rhs),
1083 z: self.z.shr(rhs),
1084 w: self.w.shr(rhs),
1085 }
1086 }
1087}
1088
1089impl Shl<u32> for UVec4 {
1090 type Output = Self;
1091 #[inline]
1092 fn shl(self, rhs: u32) -> Self::Output {
1093 Self {
1094 x: self.x.shl(rhs),
1095 y: self.y.shl(rhs),
1096 z: self.z.shl(rhs),
1097 w: self.w.shl(rhs),
1098 }
1099 }
1100}
1101
1102impl Shr<u32> for UVec4 {
1103 type Output = Self;
1104 #[inline]
1105 fn shr(self, rhs: u32) -> Self::Output {
1106 Self {
1107 x: self.x.shr(rhs),
1108 y: self.y.shr(rhs),
1109 z: self.z.shr(rhs),
1110 w: self.w.shr(rhs),
1111 }
1112 }
1113}
1114
1115impl Shl<u64> for UVec4 {
1116 type Output = Self;
1117 #[inline]
1118 fn shl(self, rhs: u64) -> Self::Output {
1119 Self {
1120 x: self.x.shl(rhs),
1121 y: self.y.shl(rhs),
1122 z: self.z.shl(rhs),
1123 w: self.w.shl(rhs),
1124 }
1125 }
1126}
1127
1128impl Shr<u64> for UVec4 {
1129 type Output = Self;
1130 #[inline]
1131 fn shr(self, rhs: u64) -> Self::Output {
1132 Self {
1133 x: self.x.shr(rhs),
1134 y: self.y.shr(rhs),
1135 z: self.z.shr(rhs),
1136 w: self.w.shr(rhs),
1137 }
1138 }
1139}
1140
1141impl Shl<crate::IVec4> for UVec4 {
1142 type Output = Self;
1143 #[inline]
1144 fn shl(self, rhs: crate::IVec4) -> Self::Output {
1145 Self {
1146 x: self.x.shl(rhs.x),
1147 y: self.y.shl(rhs.y),
1148 z: self.z.shl(rhs.z),
1149 w: self.w.shl(rhs.w),
1150 }
1151 }
1152}
1153
1154impl Shr<crate::IVec4> for UVec4 {
1155 type Output = Self;
1156 #[inline]
1157 fn shr(self, rhs: crate::IVec4) -> Self::Output {
1158 Self {
1159 x: self.x.shr(rhs.x),
1160 y: self.y.shr(rhs.y),
1161 z: self.z.shr(rhs.z),
1162 w: self.w.shr(rhs.w),
1163 }
1164 }
1165}
1166
1167impl Shl<crate::UVec4> for UVec4 {
1168 type Output = Self;
1169 #[inline]
1170 fn shl(self, rhs: crate::UVec4) -> Self::Output {
1171 Self {
1172 x: self.x.shl(rhs.x),
1173 y: self.y.shl(rhs.y),
1174 z: self.z.shl(rhs.z),
1175 w: self.w.shl(rhs.w),
1176 }
1177 }
1178}
1179
1180impl Shr<crate::UVec4> for UVec4 {
1181 type Output = Self;
1182 #[inline]
1183 fn shr(self, rhs: crate::UVec4) -> Self::Output {
1184 Self {
1185 x: self.x.shr(rhs.x),
1186 y: self.y.shr(rhs.y),
1187 z: self.z.shr(rhs.z),
1188 w: self.w.shr(rhs.w),
1189 }
1190 }
1191}
1192
1193impl Index<usize> for UVec4 {
1194 type Output = u32;
1195 #[inline]
1196 fn index(&self, index: usize) -> &Self::Output {
1197 match index {
1198 0 => &self.x,
1199 1 => &self.y,
1200 2 => &self.z,
1201 3 => &self.w,
1202 _ => panic!("index out of bounds"),
1203 }
1204 }
1205}
1206
1207impl IndexMut<usize> for UVec4 {
1208 #[inline]
1209 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1210 match index {
1211 0 => &mut self.x,
1212 1 => &mut self.y,
1213 2 => &mut self.z,
1214 3 => &mut self.w,
1215 _ => panic!("index out of bounds"),
1216 }
1217 }
1218}
1219
1220#[cfg(not(target_arch = "spirv"))]
1221impl fmt::Display for UVec4 {
1222 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1223 write!(f, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w)
1224 }
1225}
1226
1227#[cfg(not(target_arch = "spirv"))]
1228impl fmt::Debug for UVec4 {
1229 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1230 fmt.debug_tuple(stringify!(UVec4))
1231 .field(&self.x)
1232 .field(&self.y)
1233 .field(&self.z)
1234 .field(&self.w)
1235 .finish()
1236 }
1237}
1238
1239impl From<[u32; 4]> for UVec4 {
1240 #[inline]
1241 fn from(a: [u32; 4]) -> Self {
1242 Self::new(a[0], a[1], a[2], a[3])
1243 }
1244}
1245
1246impl From<UVec4> for [u32; 4] {
1247 #[inline]
1248 fn from(v: UVec4) -> Self {
1249 [v.x, v.y, v.z, v.w]
1250 }
1251}
1252
1253impl From<(u32, u32, u32, u32)> for UVec4 {
1254 #[inline]
1255 fn from(t: (u32, u32, u32, u32)) -> Self {
1256 Self::new(t.0, t.1, t.2, t.3)
1257 }
1258}
1259
1260impl From<UVec4> for (u32, u32, u32, u32) {
1261 #[inline]
1262 fn from(v: UVec4) -> Self {
1263 (v.x, v.y, v.z, v.w)
1264 }
1265}
1266
1267impl From<(UVec3, u32)> for UVec4 {
1268 #[inline]
1269 fn from((v, w): (UVec3, u32)) -> Self {
1270 Self::new(v.x, v.y, v.z, w)
1271 }
1272}
1273
1274impl From<(u32, UVec3)> for UVec4 {
1275 #[inline]
1276 fn from((x, v): (u32, UVec3)) -> Self {
1277 Self::new(x, v.x, v.y, v.z)
1278 }
1279}
1280
1281impl From<(UVec2, u32, u32)> for UVec4 {
1282 #[inline]
1283 fn from((v, z, w): (UVec2, u32, u32)) -> Self {
1284 Self::new(v.x, v.y, z, w)
1285 }
1286}
1287
1288impl From<(UVec2, UVec2)> for UVec4 {
1289 #[inline]
1290 fn from((v, u): (UVec2, UVec2)) -> Self {
1291 Self::new(v.x, v.y, u.x, u.y)
1292 }
1293}
1294
1295impl From<U16Vec4> for UVec4 {
1296 #[inline]
1297 fn from(v: U16Vec4) -> Self {
1298 Self::new(
1299 u32::from(v.x),
1300 u32::from(v.y),
1301 u32::from(v.z),
1302 u32::from(v.w),
1303 )
1304 }
1305}
1306
1307impl TryFrom<I16Vec4> for UVec4 {
1308 type Error = core::num::TryFromIntError;
1309
1310 #[inline]
1311 fn try_from(v: I16Vec4) -> Result<Self, Self::Error> {
1312 Ok(Self::new(
1313 u32::try_from(v.x)?,
1314 u32::try_from(v.y)?,
1315 u32::try_from(v.z)?,
1316 u32::try_from(v.w)?,
1317 ))
1318 }
1319}
1320
1321impl TryFrom<IVec4> for UVec4 {
1322 type Error = core::num::TryFromIntError;
1323
1324 #[inline]
1325 fn try_from(v: IVec4) -> Result<Self, Self::Error> {
1326 Ok(Self::new(
1327 u32::try_from(v.x)?,
1328 u32::try_from(v.y)?,
1329 u32::try_from(v.z)?,
1330 u32::try_from(v.w)?,
1331 ))
1332 }
1333}
1334
1335impl TryFrom<I64Vec4> for UVec4 {
1336 type Error = core::num::TryFromIntError;
1337
1338 #[inline]
1339 fn try_from(v: I64Vec4) -> Result<Self, Self::Error> {
1340 Ok(Self::new(
1341 u32::try_from(v.x)?,
1342 u32::try_from(v.y)?,
1343 u32::try_from(v.z)?,
1344 u32::try_from(v.w)?,
1345 ))
1346 }
1347}
1348
1349impl TryFrom<U64Vec4> for UVec4 {
1350 type Error = core::num::TryFromIntError;
1351
1352 #[inline]
1353 fn try_from(v: U64Vec4) -> Result<Self, Self::Error> {
1354 Ok(Self::new(
1355 u32::try_from(v.x)?,
1356 u32::try_from(v.y)?,
1357 u32::try_from(v.z)?,
1358 u32::try_from(v.w)?,
1359 ))
1360 }
1361}