1use crate::{BVec3, I16Vec3, I64Vec3, IVec3, U16Vec3, U64Vec3, UVec2, UVec4};
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 uvec3(x: u32, y: u32, z: u32) -> UVec3 {
14 UVec3::new(x, y, z)
15}
16
17#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
19#[derive(Clone, Copy, PartialEq, Eq)]
20#[cfg_attr(not(target_arch = "spirv"), repr(C))]
21#[cfg_attr(target_arch = "spirv", repr(simd))]
22pub struct UVec3 {
23 pub x: u32,
24 pub y: u32,
25 pub z: u32,
26}
27
28impl UVec3 {
29 pub const ZERO: Self = Self::splat(0);
31
32 pub const ONE: Self = Self::splat(1);
34
35 pub const MIN: Self = Self::splat(u32::MIN);
37
38 pub const MAX: Self = Self::splat(u32::MAX);
40
41 pub const X: Self = Self::new(1, 0, 0);
43
44 pub const Y: Self = Self::new(0, 1, 0);
46
47 pub const Z: Self = Self::new(0, 0, 1);
49
50 pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
52
53 #[inline(always)]
55 #[must_use]
56 pub const fn new(x: u32, y: u32, z: u32) -> Self {
57 Self { x, y, z }
58 }
59
60 #[inline]
62 #[must_use]
63 pub const fn splat(v: u32) -> Self {
64 Self { x: v, y: v, z: v }
65 }
66
67 #[inline]
73 #[must_use]
74 pub fn select(mask: BVec3, if_true: Self, if_false: Self) -> Self {
75 Self {
76 x: if mask.test(0) { if_true.x } else { if_false.x },
77 y: if mask.test(1) { if_true.y } else { if_false.y },
78 z: if mask.test(2) { if_true.z } else { if_false.z },
79 }
80 }
81
82 #[inline]
84 #[must_use]
85 pub const fn from_array(a: [u32; 3]) -> Self {
86 Self::new(a[0], a[1], a[2])
87 }
88
89 #[inline]
91 #[must_use]
92 pub const fn to_array(&self) -> [u32; 3] {
93 [self.x, self.y, self.z]
94 }
95
96 #[inline]
102 #[must_use]
103 pub const fn from_slice(slice: &[u32]) -> Self {
104 Self::new(slice[0], slice[1], slice[2])
105 }
106
107 #[inline]
113 pub fn write_to_slice(self, slice: &mut [u32]) {
114 slice[0] = self.x;
115 slice[1] = self.y;
116 slice[2] = self.z;
117 }
118
119 #[allow(dead_code)]
121 #[inline]
122 #[must_use]
123 pub(crate) fn from_vec4(v: UVec4) -> Self {
124 Self {
125 x: v.x,
126 y: v.y,
127 z: v.z,
128 }
129 }
130
131 #[inline]
133 #[must_use]
134 pub fn extend(self, w: u32) -> UVec4 {
135 UVec4::new(self.x, self.y, self.z, w)
136 }
137
138 #[inline]
142 #[must_use]
143 pub fn truncate(self) -> UVec2 {
144 use crate::swizzles::Vec3Swizzles;
145 self.xy()
146 }
147
148 #[inline]
150 #[must_use]
151 pub fn dot(self, rhs: Self) -> u32 {
152 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z)
153 }
154
155 #[inline]
157 #[must_use]
158 pub fn dot_into_vec(self, rhs: Self) -> Self {
159 Self::splat(self.dot(rhs))
160 }
161
162 #[inline]
164 #[must_use]
165 pub fn cross(self, rhs: Self) -> Self {
166 Self {
167 x: self.y * rhs.z - rhs.y * self.z,
168 y: self.z * rhs.x - rhs.z * self.x,
169 z: self.x * rhs.y - rhs.x * self.y,
170 }
171 }
172
173 #[inline]
177 #[must_use]
178 pub fn min(self, rhs: Self) -> Self {
179 Self {
180 x: self.x.min(rhs.x),
181 y: self.y.min(rhs.y),
182 z: self.z.min(rhs.z),
183 }
184 }
185
186 #[inline]
190 #[must_use]
191 pub fn max(self, rhs: Self) -> Self {
192 Self {
193 x: self.x.max(rhs.x),
194 y: self.y.max(rhs.y),
195 z: self.z.max(rhs.z),
196 }
197 }
198
199 #[inline]
207 #[must_use]
208 pub fn clamp(self, min: Self, max: Self) -> Self {
209 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
210 self.max(min).min(max)
211 }
212
213 #[inline]
217 #[must_use]
218 pub fn min_element(self) -> u32 {
219 self.x.min(self.y.min(self.z))
220 }
221
222 #[inline]
226 #[must_use]
227 pub fn max_element(self) -> u32 {
228 self.x.max(self.y.max(self.z))
229 }
230
231 #[inline]
237 #[must_use]
238 pub fn cmpeq(self, rhs: Self) -> BVec3 {
239 BVec3::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
240 }
241
242 #[inline]
248 #[must_use]
249 pub fn cmpne(self, rhs: Self) -> BVec3 {
250 BVec3::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
251 }
252
253 #[inline]
259 #[must_use]
260 pub fn cmpge(self, rhs: Self) -> BVec3 {
261 BVec3::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
262 }
263
264 #[inline]
270 #[must_use]
271 pub fn cmpgt(self, rhs: Self) -> BVec3 {
272 BVec3::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
273 }
274
275 #[inline]
281 #[must_use]
282 pub fn cmple(self, rhs: Self) -> BVec3 {
283 BVec3::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
284 }
285
286 #[inline]
292 #[must_use]
293 pub fn cmplt(self, rhs: Self) -> BVec3 {
294 BVec3::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
295 }
296
297 #[doc(alias = "magnitude2")]
299 #[inline]
300 #[must_use]
301 pub fn length_squared(self) -> u32 {
302 self.dot(self)
303 }
304
305 #[inline]
307 #[must_use]
308 pub fn as_vec3(&self) -> crate::Vec3 {
309 crate::Vec3::new(self.x as f32, self.y as f32, self.z as f32)
310 }
311
312 #[inline]
314 #[must_use]
315 pub fn as_vec3a(&self) -> crate::Vec3A {
316 crate::Vec3A::new(self.x as f32, self.y as f32, self.z as f32)
317 }
318
319 #[inline]
321 #[must_use]
322 pub fn as_dvec3(&self) -> crate::DVec3 {
323 crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
324 }
325
326 #[inline]
328 #[must_use]
329 pub fn as_i16vec3(&self) -> crate::I16Vec3 {
330 crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
331 }
332
333 #[inline]
335 #[must_use]
336 pub fn as_u16vec3(&self) -> crate::U16Vec3 {
337 crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
338 }
339
340 #[inline]
342 #[must_use]
343 pub fn as_ivec3(&self) -> crate::IVec3 {
344 crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
345 }
346
347 #[inline]
349 #[must_use]
350 pub fn as_i64vec3(&self) -> crate::I64Vec3 {
351 crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
352 }
353
354 #[inline]
356 #[must_use]
357 pub fn as_u64vec3(&self) -> crate::U64Vec3 {
358 crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
359 }
360
361 #[inline]
365 #[must_use]
366 pub const fn wrapping_add(self, rhs: Self) -> Self {
367 Self {
368 x: self.x.wrapping_add(rhs.x),
369 y: self.y.wrapping_add(rhs.y),
370 z: self.z.wrapping_add(rhs.z),
371 }
372 }
373
374 #[inline]
378 #[must_use]
379 pub const fn wrapping_sub(self, rhs: Self) -> Self {
380 Self {
381 x: self.x.wrapping_sub(rhs.x),
382 y: self.y.wrapping_sub(rhs.y),
383 z: self.z.wrapping_sub(rhs.z),
384 }
385 }
386
387 #[inline]
391 #[must_use]
392 pub const fn wrapping_mul(self, rhs: Self) -> Self {
393 Self {
394 x: self.x.wrapping_mul(rhs.x),
395 y: self.y.wrapping_mul(rhs.y),
396 z: self.z.wrapping_mul(rhs.z),
397 }
398 }
399
400 #[inline]
404 #[must_use]
405 pub const fn wrapping_div(self, rhs: Self) -> Self {
406 Self {
407 x: self.x.wrapping_div(rhs.x),
408 y: self.y.wrapping_div(rhs.y),
409 z: self.z.wrapping_div(rhs.z),
410 }
411 }
412
413 #[inline]
417 #[must_use]
418 pub const fn saturating_add(self, rhs: Self) -> Self {
419 Self {
420 x: self.x.saturating_add(rhs.x),
421 y: self.y.saturating_add(rhs.y),
422 z: self.z.saturating_add(rhs.z),
423 }
424 }
425
426 #[inline]
430 #[must_use]
431 pub const fn saturating_sub(self, rhs: Self) -> Self {
432 Self {
433 x: self.x.saturating_sub(rhs.x),
434 y: self.y.saturating_sub(rhs.y),
435 z: self.z.saturating_sub(rhs.z),
436 }
437 }
438
439 #[inline]
443 #[must_use]
444 pub const fn saturating_mul(self, rhs: Self) -> Self {
445 Self {
446 x: self.x.saturating_mul(rhs.x),
447 y: self.y.saturating_mul(rhs.y),
448 z: self.z.saturating_mul(rhs.z),
449 }
450 }
451
452 #[inline]
456 #[must_use]
457 pub const fn saturating_div(self, rhs: Self) -> Self {
458 Self {
459 x: self.x.saturating_div(rhs.x),
460 y: self.y.saturating_div(rhs.y),
461 z: self.z.saturating_div(rhs.z),
462 }
463 }
464}
465
466impl Default for UVec3 {
467 #[inline(always)]
468 fn default() -> Self {
469 Self::ZERO
470 }
471}
472
473impl Div<UVec3> for UVec3 {
474 type Output = Self;
475 #[inline]
476 fn div(self, rhs: Self) -> Self {
477 Self {
478 x: self.x.div(rhs.x),
479 y: self.y.div(rhs.y),
480 z: self.z.div(rhs.z),
481 }
482 }
483}
484
485impl DivAssign<UVec3> for UVec3 {
486 #[inline]
487 fn div_assign(&mut self, rhs: Self) {
488 self.x.div_assign(rhs.x);
489 self.y.div_assign(rhs.y);
490 self.z.div_assign(rhs.z);
491 }
492}
493
494impl Div<u32> for UVec3 {
495 type Output = Self;
496 #[inline]
497 fn div(self, rhs: u32) -> Self {
498 Self {
499 x: self.x.div(rhs),
500 y: self.y.div(rhs),
501 z: self.z.div(rhs),
502 }
503 }
504}
505
506impl DivAssign<u32> for UVec3 {
507 #[inline]
508 fn div_assign(&mut self, rhs: u32) {
509 self.x.div_assign(rhs);
510 self.y.div_assign(rhs);
511 self.z.div_assign(rhs);
512 }
513}
514
515impl Div<UVec3> for u32 {
516 type Output = UVec3;
517 #[inline]
518 fn div(self, rhs: UVec3) -> UVec3 {
519 UVec3 {
520 x: self.div(rhs.x),
521 y: self.div(rhs.y),
522 z: self.div(rhs.z),
523 }
524 }
525}
526
527impl Mul<UVec3> for UVec3 {
528 type Output = Self;
529 #[inline]
530 fn mul(self, rhs: Self) -> Self {
531 Self {
532 x: self.x.mul(rhs.x),
533 y: self.y.mul(rhs.y),
534 z: self.z.mul(rhs.z),
535 }
536 }
537}
538
539impl MulAssign<UVec3> for UVec3 {
540 #[inline]
541 fn mul_assign(&mut self, rhs: Self) {
542 self.x.mul_assign(rhs.x);
543 self.y.mul_assign(rhs.y);
544 self.z.mul_assign(rhs.z);
545 }
546}
547
548impl Mul<u32> for UVec3 {
549 type Output = Self;
550 #[inline]
551 fn mul(self, rhs: u32) -> Self {
552 Self {
553 x: self.x.mul(rhs),
554 y: self.y.mul(rhs),
555 z: self.z.mul(rhs),
556 }
557 }
558}
559
560impl MulAssign<u32> for UVec3 {
561 #[inline]
562 fn mul_assign(&mut self, rhs: u32) {
563 self.x.mul_assign(rhs);
564 self.y.mul_assign(rhs);
565 self.z.mul_assign(rhs);
566 }
567}
568
569impl Mul<UVec3> for u32 {
570 type Output = UVec3;
571 #[inline]
572 fn mul(self, rhs: UVec3) -> UVec3 {
573 UVec3 {
574 x: self.mul(rhs.x),
575 y: self.mul(rhs.y),
576 z: self.mul(rhs.z),
577 }
578 }
579}
580
581impl Add<UVec3> for UVec3 {
582 type Output = Self;
583 #[inline]
584 fn add(self, rhs: Self) -> Self {
585 Self {
586 x: self.x.add(rhs.x),
587 y: self.y.add(rhs.y),
588 z: self.z.add(rhs.z),
589 }
590 }
591}
592
593impl AddAssign<UVec3> for UVec3 {
594 #[inline]
595 fn add_assign(&mut self, rhs: Self) {
596 self.x.add_assign(rhs.x);
597 self.y.add_assign(rhs.y);
598 self.z.add_assign(rhs.z);
599 }
600}
601
602impl Add<u32> for UVec3 {
603 type Output = Self;
604 #[inline]
605 fn add(self, rhs: u32) -> Self {
606 Self {
607 x: self.x.add(rhs),
608 y: self.y.add(rhs),
609 z: self.z.add(rhs),
610 }
611 }
612}
613
614impl AddAssign<u32> for UVec3 {
615 #[inline]
616 fn add_assign(&mut self, rhs: u32) {
617 self.x.add_assign(rhs);
618 self.y.add_assign(rhs);
619 self.z.add_assign(rhs);
620 }
621}
622
623impl Add<UVec3> for u32 {
624 type Output = UVec3;
625 #[inline]
626 fn add(self, rhs: UVec3) -> UVec3 {
627 UVec3 {
628 x: self.add(rhs.x),
629 y: self.add(rhs.y),
630 z: self.add(rhs.z),
631 }
632 }
633}
634
635impl Sub<UVec3> for UVec3 {
636 type Output = Self;
637 #[inline]
638 fn sub(self, rhs: Self) -> Self {
639 Self {
640 x: self.x.sub(rhs.x),
641 y: self.y.sub(rhs.y),
642 z: self.z.sub(rhs.z),
643 }
644 }
645}
646
647impl SubAssign<UVec3> for UVec3 {
648 #[inline]
649 fn sub_assign(&mut self, rhs: UVec3) {
650 self.x.sub_assign(rhs.x);
651 self.y.sub_assign(rhs.y);
652 self.z.sub_assign(rhs.z);
653 }
654}
655
656impl Sub<u32> for UVec3 {
657 type Output = Self;
658 #[inline]
659 fn sub(self, rhs: u32) -> Self {
660 Self {
661 x: self.x.sub(rhs),
662 y: self.y.sub(rhs),
663 z: self.z.sub(rhs),
664 }
665 }
666}
667
668impl SubAssign<u32> for UVec3 {
669 #[inline]
670 fn sub_assign(&mut self, rhs: u32) {
671 self.x.sub_assign(rhs);
672 self.y.sub_assign(rhs);
673 self.z.sub_assign(rhs);
674 }
675}
676
677impl Sub<UVec3> for u32 {
678 type Output = UVec3;
679 #[inline]
680 fn sub(self, rhs: UVec3) -> UVec3 {
681 UVec3 {
682 x: self.sub(rhs.x),
683 y: self.sub(rhs.y),
684 z: self.sub(rhs.z),
685 }
686 }
687}
688
689impl Rem<UVec3> for UVec3 {
690 type Output = Self;
691 #[inline]
692 fn rem(self, rhs: Self) -> Self {
693 Self {
694 x: self.x.rem(rhs.x),
695 y: self.y.rem(rhs.y),
696 z: self.z.rem(rhs.z),
697 }
698 }
699}
700
701impl RemAssign<UVec3> for UVec3 {
702 #[inline]
703 fn rem_assign(&mut self, rhs: Self) {
704 self.x.rem_assign(rhs.x);
705 self.y.rem_assign(rhs.y);
706 self.z.rem_assign(rhs.z);
707 }
708}
709
710impl Rem<u32> for UVec3 {
711 type Output = Self;
712 #[inline]
713 fn rem(self, rhs: u32) -> Self {
714 Self {
715 x: self.x.rem(rhs),
716 y: self.y.rem(rhs),
717 z: self.z.rem(rhs),
718 }
719 }
720}
721
722impl RemAssign<u32> for UVec3 {
723 #[inline]
724 fn rem_assign(&mut self, rhs: u32) {
725 self.x.rem_assign(rhs);
726 self.y.rem_assign(rhs);
727 self.z.rem_assign(rhs);
728 }
729}
730
731impl Rem<UVec3> for u32 {
732 type Output = UVec3;
733 #[inline]
734 fn rem(self, rhs: UVec3) -> UVec3 {
735 UVec3 {
736 x: self.rem(rhs.x),
737 y: self.rem(rhs.y),
738 z: self.rem(rhs.z),
739 }
740 }
741}
742
743#[cfg(not(target_arch = "spirv"))]
744impl AsRef<[u32; 3]> for UVec3 {
745 #[inline]
746 fn as_ref(&self) -> &[u32; 3] {
747 unsafe { &*(self as *const UVec3 as *const [u32; 3]) }
748 }
749}
750
751#[cfg(not(target_arch = "spirv"))]
752impl AsMut<[u32; 3]> for UVec3 {
753 #[inline]
754 fn as_mut(&mut self) -> &mut [u32; 3] {
755 unsafe { &mut *(self as *mut UVec3 as *mut [u32; 3]) }
756 }
757}
758
759impl Sum for UVec3 {
760 #[inline]
761 fn sum<I>(iter: I) -> Self
762 where
763 I: Iterator<Item = Self>,
764 {
765 iter.fold(Self::ZERO, Self::add)
766 }
767}
768
769impl<'a> Sum<&'a Self> for UVec3 {
770 #[inline]
771 fn sum<I>(iter: I) -> Self
772 where
773 I: Iterator<Item = &'a Self>,
774 {
775 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
776 }
777}
778
779impl Product for UVec3 {
780 #[inline]
781 fn product<I>(iter: I) -> Self
782 where
783 I: Iterator<Item = Self>,
784 {
785 iter.fold(Self::ONE, Self::mul)
786 }
787}
788
789impl<'a> Product<&'a Self> for UVec3 {
790 #[inline]
791 fn product<I>(iter: I) -> Self
792 where
793 I: Iterator<Item = &'a Self>,
794 {
795 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
796 }
797}
798
799impl Not for UVec3 {
800 type Output = Self;
801 #[inline]
802 fn not(self) -> Self::Output {
803 Self {
804 x: self.x.not(),
805 y: self.y.not(),
806 z: self.z.not(),
807 }
808 }
809}
810
811impl BitAnd for UVec3 {
812 type Output = Self;
813 #[inline]
814 fn bitand(self, rhs: Self) -> Self::Output {
815 Self {
816 x: self.x.bitand(rhs.x),
817 y: self.y.bitand(rhs.y),
818 z: self.z.bitand(rhs.z),
819 }
820 }
821}
822
823impl BitOr for UVec3 {
824 type Output = Self;
825 #[inline]
826 fn bitor(self, rhs: Self) -> Self::Output {
827 Self {
828 x: self.x.bitor(rhs.x),
829 y: self.y.bitor(rhs.y),
830 z: self.z.bitor(rhs.z),
831 }
832 }
833}
834
835impl BitXor for UVec3 {
836 type Output = Self;
837 #[inline]
838 fn bitxor(self, rhs: Self) -> Self::Output {
839 Self {
840 x: self.x.bitxor(rhs.x),
841 y: self.y.bitxor(rhs.y),
842 z: self.z.bitxor(rhs.z),
843 }
844 }
845}
846
847impl BitAnd<u32> for UVec3 {
848 type Output = Self;
849 #[inline]
850 fn bitand(self, rhs: u32) -> Self::Output {
851 Self {
852 x: self.x.bitand(rhs),
853 y: self.y.bitand(rhs),
854 z: self.z.bitand(rhs),
855 }
856 }
857}
858
859impl BitOr<u32> for UVec3 {
860 type Output = Self;
861 #[inline]
862 fn bitor(self, rhs: u32) -> Self::Output {
863 Self {
864 x: self.x.bitor(rhs),
865 y: self.y.bitor(rhs),
866 z: self.z.bitor(rhs),
867 }
868 }
869}
870
871impl BitXor<u32> for UVec3 {
872 type Output = Self;
873 #[inline]
874 fn bitxor(self, rhs: u32) -> Self::Output {
875 Self {
876 x: self.x.bitxor(rhs),
877 y: self.y.bitxor(rhs),
878 z: self.z.bitxor(rhs),
879 }
880 }
881}
882
883impl Shl<i8> for UVec3 {
884 type Output = Self;
885 #[inline]
886 fn shl(self, rhs: i8) -> Self::Output {
887 Self {
888 x: self.x.shl(rhs),
889 y: self.y.shl(rhs),
890 z: self.z.shl(rhs),
891 }
892 }
893}
894
895impl Shr<i8> for UVec3 {
896 type Output = Self;
897 #[inline]
898 fn shr(self, rhs: i8) -> Self::Output {
899 Self {
900 x: self.x.shr(rhs),
901 y: self.y.shr(rhs),
902 z: self.z.shr(rhs),
903 }
904 }
905}
906
907impl Shl<i16> for UVec3 {
908 type Output = Self;
909 #[inline]
910 fn shl(self, rhs: i16) -> Self::Output {
911 Self {
912 x: self.x.shl(rhs),
913 y: self.y.shl(rhs),
914 z: self.z.shl(rhs),
915 }
916 }
917}
918
919impl Shr<i16> for UVec3 {
920 type Output = Self;
921 #[inline]
922 fn shr(self, rhs: i16) -> Self::Output {
923 Self {
924 x: self.x.shr(rhs),
925 y: self.y.shr(rhs),
926 z: self.z.shr(rhs),
927 }
928 }
929}
930
931impl Shl<i32> for UVec3 {
932 type Output = Self;
933 #[inline]
934 fn shl(self, rhs: i32) -> Self::Output {
935 Self {
936 x: self.x.shl(rhs),
937 y: self.y.shl(rhs),
938 z: self.z.shl(rhs),
939 }
940 }
941}
942
943impl Shr<i32> for UVec3 {
944 type Output = Self;
945 #[inline]
946 fn shr(self, rhs: i32) -> Self::Output {
947 Self {
948 x: self.x.shr(rhs),
949 y: self.y.shr(rhs),
950 z: self.z.shr(rhs),
951 }
952 }
953}
954
955impl Shl<i64> for UVec3 {
956 type Output = Self;
957 #[inline]
958 fn shl(self, rhs: i64) -> Self::Output {
959 Self {
960 x: self.x.shl(rhs),
961 y: self.y.shl(rhs),
962 z: self.z.shl(rhs),
963 }
964 }
965}
966
967impl Shr<i64> for UVec3 {
968 type Output = Self;
969 #[inline]
970 fn shr(self, rhs: i64) -> Self::Output {
971 Self {
972 x: self.x.shr(rhs),
973 y: self.y.shr(rhs),
974 z: self.z.shr(rhs),
975 }
976 }
977}
978
979impl Shl<u8> for UVec3 {
980 type Output = Self;
981 #[inline]
982 fn shl(self, rhs: u8) -> Self::Output {
983 Self {
984 x: self.x.shl(rhs),
985 y: self.y.shl(rhs),
986 z: self.z.shl(rhs),
987 }
988 }
989}
990
991impl Shr<u8> for UVec3 {
992 type Output = Self;
993 #[inline]
994 fn shr(self, rhs: u8) -> Self::Output {
995 Self {
996 x: self.x.shr(rhs),
997 y: self.y.shr(rhs),
998 z: self.z.shr(rhs),
999 }
1000 }
1001}
1002
1003impl Shl<u16> for UVec3 {
1004 type Output = Self;
1005 #[inline]
1006 fn shl(self, rhs: u16) -> Self::Output {
1007 Self {
1008 x: self.x.shl(rhs),
1009 y: self.y.shl(rhs),
1010 z: self.z.shl(rhs),
1011 }
1012 }
1013}
1014
1015impl Shr<u16> for UVec3 {
1016 type Output = Self;
1017 #[inline]
1018 fn shr(self, rhs: u16) -> Self::Output {
1019 Self {
1020 x: self.x.shr(rhs),
1021 y: self.y.shr(rhs),
1022 z: self.z.shr(rhs),
1023 }
1024 }
1025}
1026
1027impl Shl<u32> for UVec3 {
1028 type Output = Self;
1029 #[inline]
1030 fn shl(self, rhs: u32) -> Self::Output {
1031 Self {
1032 x: self.x.shl(rhs),
1033 y: self.y.shl(rhs),
1034 z: self.z.shl(rhs),
1035 }
1036 }
1037}
1038
1039impl Shr<u32> for UVec3 {
1040 type Output = Self;
1041 #[inline]
1042 fn shr(self, rhs: u32) -> Self::Output {
1043 Self {
1044 x: self.x.shr(rhs),
1045 y: self.y.shr(rhs),
1046 z: self.z.shr(rhs),
1047 }
1048 }
1049}
1050
1051impl Shl<u64> for UVec3 {
1052 type Output = Self;
1053 #[inline]
1054 fn shl(self, rhs: u64) -> Self::Output {
1055 Self {
1056 x: self.x.shl(rhs),
1057 y: self.y.shl(rhs),
1058 z: self.z.shl(rhs),
1059 }
1060 }
1061}
1062
1063impl Shr<u64> for UVec3 {
1064 type Output = Self;
1065 #[inline]
1066 fn shr(self, rhs: u64) -> Self::Output {
1067 Self {
1068 x: self.x.shr(rhs),
1069 y: self.y.shr(rhs),
1070 z: self.z.shr(rhs),
1071 }
1072 }
1073}
1074
1075impl Shl<crate::IVec3> for UVec3 {
1076 type Output = Self;
1077 #[inline]
1078 fn shl(self, rhs: crate::IVec3) -> Self::Output {
1079 Self {
1080 x: self.x.shl(rhs.x),
1081 y: self.y.shl(rhs.y),
1082 z: self.z.shl(rhs.z),
1083 }
1084 }
1085}
1086
1087impl Shr<crate::IVec3> for UVec3 {
1088 type Output = Self;
1089 #[inline]
1090 fn shr(self, rhs: crate::IVec3) -> Self::Output {
1091 Self {
1092 x: self.x.shr(rhs.x),
1093 y: self.y.shr(rhs.y),
1094 z: self.z.shr(rhs.z),
1095 }
1096 }
1097}
1098
1099impl Shl<crate::UVec3> for UVec3 {
1100 type Output = Self;
1101 #[inline]
1102 fn shl(self, rhs: crate::UVec3) -> Self::Output {
1103 Self {
1104 x: self.x.shl(rhs.x),
1105 y: self.y.shl(rhs.y),
1106 z: self.z.shl(rhs.z),
1107 }
1108 }
1109}
1110
1111impl Shr<crate::UVec3> for UVec3 {
1112 type Output = Self;
1113 #[inline]
1114 fn shr(self, rhs: crate::UVec3) -> Self::Output {
1115 Self {
1116 x: self.x.shr(rhs.x),
1117 y: self.y.shr(rhs.y),
1118 z: self.z.shr(rhs.z),
1119 }
1120 }
1121}
1122
1123impl Index<usize> for UVec3 {
1124 type Output = u32;
1125 #[inline]
1126 fn index(&self, index: usize) -> &Self::Output {
1127 match index {
1128 0 => &self.x,
1129 1 => &self.y,
1130 2 => &self.z,
1131 _ => panic!("index out of bounds"),
1132 }
1133 }
1134}
1135
1136impl IndexMut<usize> for UVec3 {
1137 #[inline]
1138 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1139 match index {
1140 0 => &mut self.x,
1141 1 => &mut self.y,
1142 2 => &mut self.z,
1143 _ => panic!("index out of bounds"),
1144 }
1145 }
1146}
1147
1148#[cfg(not(target_arch = "spirv"))]
1149impl fmt::Display for UVec3 {
1150 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1151 write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
1152 }
1153}
1154
1155#[cfg(not(target_arch = "spirv"))]
1156impl fmt::Debug for UVec3 {
1157 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1158 fmt.debug_tuple(stringify!(UVec3))
1159 .field(&self.x)
1160 .field(&self.y)
1161 .field(&self.z)
1162 .finish()
1163 }
1164}
1165
1166impl From<[u32; 3]> for UVec3 {
1167 #[inline]
1168 fn from(a: [u32; 3]) -> Self {
1169 Self::new(a[0], a[1], a[2])
1170 }
1171}
1172
1173impl From<UVec3> for [u32; 3] {
1174 #[inline]
1175 fn from(v: UVec3) -> Self {
1176 [v.x, v.y, v.z]
1177 }
1178}
1179
1180impl From<(u32, u32, u32)> for UVec3 {
1181 #[inline]
1182 fn from(t: (u32, u32, u32)) -> Self {
1183 Self::new(t.0, t.1, t.2)
1184 }
1185}
1186
1187impl From<UVec3> for (u32, u32, u32) {
1188 #[inline]
1189 fn from(v: UVec3) -> Self {
1190 (v.x, v.y, v.z)
1191 }
1192}
1193
1194impl From<(UVec2, u32)> for UVec3 {
1195 #[inline]
1196 fn from((v, z): (UVec2, u32)) -> Self {
1197 Self::new(v.x, v.y, z)
1198 }
1199}
1200
1201impl From<U16Vec3> for UVec3 {
1202 #[inline]
1203 fn from(v: U16Vec3) -> Self {
1204 Self::new(u32::from(v.x), u32::from(v.y), u32::from(v.z))
1205 }
1206}
1207
1208impl TryFrom<I16Vec3> for UVec3 {
1209 type Error = core::num::TryFromIntError;
1210
1211 #[inline]
1212 fn try_from(v: I16Vec3) -> Result<Self, Self::Error> {
1213 Ok(Self::new(
1214 u32::try_from(v.x)?,
1215 u32::try_from(v.y)?,
1216 u32::try_from(v.z)?,
1217 ))
1218 }
1219}
1220
1221impl TryFrom<IVec3> for UVec3 {
1222 type Error = core::num::TryFromIntError;
1223
1224 #[inline]
1225 fn try_from(v: IVec3) -> Result<Self, Self::Error> {
1226 Ok(Self::new(
1227 u32::try_from(v.x)?,
1228 u32::try_from(v.y)?,
1229 u32::try_from(v.z)?,
1230 ))
1231 }
1232}
1233
1234impl TryFrom<I64Vec3> for UVec3 {
1235 type Error = core::num::TryFromIntError;
1236
1237 #[inline]
1238 fn try_from(v: I64Vec3) -> Result<Self, Self::Error> {
1239 Ok(Self::new(
1240 u32::try_from(v.x)?,
1241 u32::try_from(v.y)?,
1242 u32::try_from(v.z)?,
1243 ))
1244 }
1245}
1246
1247impl TryFrom<U64Vec3> for UVec3 {
1248 type Error = core::num::TryFromIntError;
1249
1250 #[inline]
1251 fn try_from(v: U64Vec3) -> Result<Self, Self::Error> {
1252 Ok(Self::new(
1253 u32::try_from(v.x)?,
1254 u32::try_from(v.y)?,
1255 u32::try_from(v.z)?,
1256 ))
1257 }
1258}