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