1use crate::{
4 BVec3, BVec3A, I16Vec3, I64Vec3, I8Vec3, IVec3, U16Vec3, U64Vec3, U8Vec3, UVec2, UVec4,
5};
6
7use core::fmt;
8use core::iter::{Product, Sum};
9use core::{f32, ops::*};
10
11#[inline(always)]
13#[must_use]
14pub const fn uvec3(x: u32, y: u32, z: u32) -> UVec3 {
15 UVec3::new(x, y, z)
16}
17
18#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
20#[derive(Clone, Copy, PartialEq, Eq)]
21#[cfg_attr(not(target_arch = "spirv"), repr(C))]
22#[cfg_attr(target_arch = "spirv", repr(simd))]
23pub struct UVec3 {
24 pub x: u32,
25 pub y: u32,
26 pub z: u32,
27}
28
29impl UVec3 {
30 pub const ZERO: Self = Self::splat(0);
32
33 pub const ONE: Self = Self::splat(1);
35
36 pub const MIN: Self = Self::splat(u32::MIN);
38
39 pub const MAX: Self = Self::splat(u32::MAX);
41
42 pub const X: Self = Self::new(1, 0, 0);
44
45 pub const Y: Self = Self::new(0, 1, 0);
47
48 pub const Z: Self = Self::new(0, 0, 1);
50
51 pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
53
54 #[inline(always)]
56 #[must_use]
57 pub const fn new(x: u32, y: u32, z: u32) -> Self {
58 Self { x, y, z }
59 }
60
61 #[inline]
63 #[must_use]
64 pub const fn splat(v: u32) -> Self {
65 Self { x: v, y: v, z: v }
66 }
67
68 #[inline]
70 #[must_use]
71 pub fn map<F>(self, f: F) -> Self
72 where
73 F: Fn(u32) -> u32,
74 {
75 Self::new(f(self.x), f(self.y), f(self.z))
76 }
77
78 #[inline]
84 #[must_use]
85 pub fn select(mask: BVec3, if_true: Self, if_false: Self) -> Self {
86 Self {
87 x: if mask.test(0) { if_true.x } else { if_false.x },
88 y: if mask.test(1) { if_true.y } else { if_false.y },
89 z: if mask.test(2) { if_true.z } else { if_false.z },
90 }
91 }
92
93 #[inline]
95 #[must_use]
96 pub const fn from_array(a: [u32; 3]) -> Self {
97 Self::new(a[0], a[1], a[2])
98 }
99
100 #[inline]
102 #[must_use]
103 pub const fn to_array(&self) -> [u32; 3] {
104 [self.x, self.y, self.z]
105 }
106
107 #[inline]
113 #[must_use]
114 pub const fn from_slice(slice: &[u32]) -> Self {
115 assert!(slice.len() >= 3);
116 Self::new(slice[0], slice[1], slice[2])
117 }
118
119 #[inline]
125 pub fn write_to_slice(self, slice: &mut [u32]) {
126 slice[..3].copy_from_slice(&self.to_array());
127 }
128
129 #[allow(dead_code)]
131 #[inline]
132 #[must_use]
133 pub(crate) fn from_vec4(v: UVec4) -> Self {
134 Self {
135 x: v.x,
136 y: v.y,
137 z: v.z,
138 }
139 }
140
141 #[inline]
143 #[must_use]
144 pub fn extend(self, w: u32) -> UVec4 {
145 UVec4::new(self.x, self.y, self.z, w)
146 }
147
148 #[inline]
152 #[must_use]
153 pub fn truncate(self) -> UVec2 {
154 use crate::swizzles::Vec3Swizzles;
155 self.xy()
156 }
157
158 #[inline]
160 #[must_use]
161 pub fn with_x(mut self, x: u32) -> Self {
162 self.x = x;
163 self
164 }
165
166 #[inline]
168 #[must_use]
169 pub fn with_y(mut self, y: u32) -> Self {
170 self.y = y;
171 self
172 }
173
174 #[inline]
176 #[must_use]
177 pub fn with_z(mut self, z: u32) -> Self {
178 self.z = z;
179 self
180 }
181
182 #[inline]
184 #[must_use]
185 pub fn dot(self, rhs: Self) -> u32 {
186 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z)
187 }
188
189 #[inline]
191 #[must_use]
192 pub fn dot_into_vec(self, rhs: Self) -> Self {
193 Self::splat(self.dot(rhs))
194 }
195
196 #[inline]
198 #[must_use]
199 pub fn cross(self, rhs: Self) -> Self {
200 Self {
201 x: self.y * rhs.z - rhs.y * self.z,
202 y: self.z * rhs.x - rhs.z * self.x,
203 z: self.x * rhs.y - rhs.x * self.y,
204 }
205 }
206
207 #[inline]
211 #[must_use]
212 pub fn min(self, rhs: Self) -> Self {
213 Self {
214 x: self.x.min(rhs.x),
215 y: self.y.min(rhs.y),
216 z: self.z.min(rhs.z),
217 }
218 }
219
220 #[inline]
224 #[must_use]
225 pub fn max(self, rhs: Self) -> Self {
226 Self {
227 x: self.x.max(rhs.x),
228 y: self.y.max(rhs.y),
229 z: self.z.max(rhs.z),
230 }
231 }
232
233 #[inline]
241 #[must_use]
242 pub fn clamp(self, min: Self, max: Self) -> Self {
243 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
244 self.max(min).min(max)
245 }
246
247 #[inline]
251 #[must_use]
252 pub fn min_element(self) -> u32 {
253 self.x.min(self.y.min(self.z))
254 }
255
256 #[inline]
260 #[must_use]
261 pub fn max_element(self) -> u32 {
262 self.x.max(self.y.max(self.z))
263 }
264
265 #[inline]
269 #[must_use]
270 pub fn element_sum(self) -> u32 {
271 self.x + self.y + self.z
272 }
273
274 #[inline]
278 #[must_use]
279 pub fn element_product(self) -> u32 {
280 self.x * self.y * self.z
281 }
282
283 #[inline]
289 #[must_use]
290 pub fn cmpeq(self, rhs: Self) -> BVec3 {
291 BVec3::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
292 }
293
294 #[inline]
300 #[must_use]
301 pub fn cmpne(self, rhs: Self) -> BVec3 {
302 BVec3::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
303 }
304
305 #[inline]
311 #[must_use]
312 pub fn cmpge(self, rhs: Self) -> BVec3 {
313 BVec3::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
314 }
315
316 #[inline]
322 #[must_use]
323 pub fn cmpgt(self, rhs: Self) -> BVec3 {
324 BVec3::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
325 }
326
327 #[inline]
333 #[must_use]
334 pub fn cmple(self, rhs: Self) -> BVec3 {
335 BVec3::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
336 }
337
338 #[inline]
344 #[must_use]
345 pub fn cmplt(self, rhs: Self) -> BVec3 {
346 BVec3::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
347 }
348
349 #[doc(alias = "magnitude2")]
351 #[inline]
352 #[must_use]
353 pub fn length_squared(self) -> u32 {
354 self.dot(self)
355 }
356
357 #[inline]
359 #[must_use]
360 pub fn as_vec3(&self) -> crate::Vec3 {
361 crate::Vec3::new(self.x as f32, self.y as f32, self.z as f32)
362 }
363
364 #[inline]
366 #[must_use]
367 pub fn as_vec3a(&self) -> crate::Vec3A {
368 crate::Vec3A::new(self.x as f32, self.y as f32, self.z as f32)
369 }
370
371 #[inline]
373 #[must_use]
374 pub fn as_dvec3(&self) -> crate::DVec3 {
375 crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
376 }
377
378 #[inline]
380 #[must_use]
381 pub fn as_i8vec3(&self) -> crate::I8Vec3 {
382 crate::I8Vec3::new(self.x as i8, self.y as i8, self.z as i8)
383 }
384
385 #[inline]
387 #[must_use]
388 pub fn as_u8vec3(&self) -> crate::U8Vec3 {
389 crate::U8Vec3::new(self.x as u8, self.y as u8, self.z as u8)
390 }
391
392 #[inline]
394 #[must_use]
395 pub fn as_i16vec3(&self) -> crate::I16Vec3 {
396 crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
397 }
398
399 #[inline]
401 #[must_use]
402 pub fn as_u16vec3(&self) -> crate::U16Vec3 {
403 crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
404 }
405
406 #[inline]
408 #[must_use]
409 pub fn as_ivec3(&self) -> crate::IVec3 {
410 crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
411 }
412
413 #[inline]
415 #[must_use]
416 pub fn as_i64vec3(&self) -> crate::I64Vec3 {
417 crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
418 }
419
420 #[inline]
422 #[must_use]
423 pub fn as_u64vec3(&self) -> crate::U64Vec3 {
424 crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
425 }
426
427 #[inline]
431 #[must_use]
432 pub const fn wrapping_add(self, rhs: Self) -> Self {
433 Self {
434 x: self.x.wrapping_add(rhs.x),
435 y: self.y.wrapping_add(rhs.y),
436 z: self.z.wrapping_add(rhs.z),
437 }
438 }
439
440 #[inline]
444 #[must_use]
445 pub const fn wrapping_sub(self, rhs: Self) -> Self {
446 Self {
447 x: self.x.wrapping_sub(rhs.x),
448 y: self.y.wrapping_sub(rhs.y),
449 z: self.z.wrapping_sub(rhs.z),
450 }
451 }
452
453 #[inline]
457 #[must_use]
458 pub const fn wrapping_mul(self, rhs: Self) -> Self {
459 Self {
460 x: self.x.wrapping_mul(rhs.x),
461 y: self.y.wrapping_mul(rhs.y),
462 z: self.z.wrapping_mul(rhs.z),
463 }
464 }
465
466 #[inline]
470 #[must_use]
471 pub const fn wrapping_div(self, rhs: Self) -> Self {
472 Self {
473 x: self.x.wrapping_div(rhs.x),
474 y: self.y.wrapping_div(rhs.y),
475 z: self.z.wrapping_div(rhs.z),
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 }
490 }
491
492 #[inline]
496 #[must_use]
497 pub const fn saturating_sub(self, rhs: Self) -> Self {
498 Self {
499 x: self.x.saturating_sub(rhs.x),
500 y: self.y.saturating_sub(rhs.y),
501 z: self.z.saturating_sub(rhs.z),
502 }
503 }
504
505 #[inline]
509 #[must_use]
510 pub const fn saturating_mul(self, rhs: Self) -> Self {
511 Self {
512 x: self.x.saturating_mul(rhs.x),
513 y: self.y.saturating_mul(rhs.y),
514 z: self.z.saturating_mul(rhs.z),
515 }
516 }
517
518 #[inline]
522 #[must_use]
523 pub const fn saturating_div(self, rhs: Self) -> Self {
524 Self {
525 x: self.x.saturating_div(rhs.x),
526 y: self.y.saturating_div(rhs.y),
527 z: self.z.saturating_div(rhs.z),
528 }
529 }
530
531 #[inline]
535 #[must_use]
536 pub const fn wrapping_add_signed(self, rhs: IVec3) -> Self {
537 Self {
538 x: self.x.wrapping_add_signed(rhs.x),
539 y: self.y.wrapping_add_signed(rhs.y),
540 z: self.z.wrapping_add_signed(rhs.z),
541 }
542 }
543
544 #[inline]
548 #[must_use]
549 pub const fn saturating_add_signed(self, rhs: IVec3) -> Self {
550 Self {
551 x: self.x.saturating_add_signed(rhs.x),
552 y: self.y.saturating_add_signed(rhs.y),
553 z: self.z.saturating_add_signed(rhs.z),
554 }
555 }
556}
557
558impl Default for UVec3 {
559 #[inline(always)]
560 fn default() -> Self {
561 Self::ZERO
562 }
563}
564
565impl Div<UVec3> for UVec3 {
566 type Output = Self;
567 #[inline]
568 fn div(self, rhs: Self) -> Self {
569 Self {
570 x: self.x.div(rhs.x),
571 y: self.y.div(rhs.y),
572 z: self.z.div(rhs.z),
573 }
574 }
575}
576
577impl Div<&UVec3> for UVec3 {
578 type Output = UVec3;
579 #[inline]
580 fn div(self, rhs: &UVec3) -> UVec3 {
581 self.div(*rhs)
582 }
583}
584
585impl Div<&UVec3> for &UVec3 {
586 type Output = UVec3;
587 #[inline]
588 fn div(self, rhs: &UVec3) -> UVec3 {
589 (*self).div(*rhs)
590 }
591}
592
593impl Div<UVec3> for &UVec3 {
594 type Output = UVec3;
595 #[inline]
596 fn div(self, rhs: UVec3) -> UVec3 {
597 (*self).div(rhs)
598 }
599}
600
601impl DivAssign<UVec3> for UVec3 {
602 #[inline]
603 fn div_assign(&mut self, rhs: Self) {
604 self.x.div_assign(rhs.x);
605 self.y.div_assign(rhs.y);
606 self.z.div_assign(rhs.z);
607 }
608}
609
610impl DivAssign<&Self> for UVec3 {
611 #[inline]
612 fn div_assign(&mut self, rhs: &Self) {
613 self.div_assign(*rhs)
614 }
615}
616
617impl Div<u32> for UVec3 {
618 type Output = Self;
619 #[inline]
620 fn div(self, rhs: u32) -> Self {
621 Self {
622 x: self.x.div(rhs),
623 y: self.y.div(rhs),
624 z: self.z.div(rhs),
625 }
626 }
627}
628
629impl Div<&u32> for UVec3 {
630 type Output = UVec3;
631 #[inline]
632 fn div(self, rhs: &u32) -> UVec3 {
633 self.div(*rhs)
634 }
635}
636
637impl Div<&u32> for &UVec3 {
638 type Output = UVec3;
639 #[inline]
640 fn div(self, rhs: &u32) -> UVec3 {
641 (*self).div(*rhs)
642 }
643}
644
645impl Div<u32> for &UVec3 {
646 type Output = UVec3;
647 #[inline]
648 fn div(self, rhs: u32) -> UVec3 {
649 (*self).div(rhs)
650 }
651}
652
653impl DivAssign<u32> for UVec3 {
654 #[inline]
655 fn div_assign(&mut self, rhs: u32) {
656 self.x.div_assign(rhs);
657 self.y.div_assign(rhs);
658 self.z.div_assign(rhs);
659 }
660}
661
662impl DivAssign<&u32> for UVec3 {
663 #[inline]
664 fn div_assign(&mut self, rhs: &u32) {
665 self.div_assign(*rhs)
666 }
667}
668
669impl Div<UVec3> for u32 {
670 type Output = UVec3;
671 #[inline]
672 fn div(self, rhs: UVec3) -> UVec3 {
673 UVec3 {
674 x: self.div(rhs.x),
675 y: self.div(rhs.y),
676 z: self.div(rhs.z),
677 }
678 }
679}
680
681impl Div<&UVec3> for u32 {
682 type Output = UVec3;
683 #[inline]
684 fn div(self, rhs: &UVec3) -> UVec3 {
685 self.div(*rhs)
686 }
687}
688
689impl Div<&UVec3> for &u32 {
690 type Output = UVec3;
691 #[inline]
692 fn div(self, rhs: &UVec3) -> UVec3 {
693 (*self).div(*rhs)
694 }
695}
696
697impl Div<UVec3> for &u32 {
698 type Output = UVec3;
699 #[inline]
700 fn div(self, rhs: UVec3) -> UVec3 {
701 (*self).div(rhs)
702 }
703}
704
705impl Mul<UVec3> for UVec3 {
706 type Output = Self;
707 #[inline]
708 fn mul(self, rhs: Self) -> Self {
709 Self {
710 x: self.x.mul(rhs.x),
711 y: self.y.mul(rhs.y),
712 z: self.z.mul(rhs.z),
713 }
714 }
715}
716
717impl Mul<&UVec3> for UVec3 {
718 type Output = UVec3;
719 #[inline]
720 fn mul(self, rhs: &UVec3) -> UVec3 {
721 self.mul(*rhs)
722 }
723}
724
725impl Mul<&UVec3> for &UVec3 {
726 type Output = UVec3;
727 #[inline]
728 fn mul(self, rhs: &UVec3) -> UVec3 {
729 (*self).mul(*rhs)
730 }
731}
732
733impl Mul<UVec3> for &UVec3 {
734 type Output = UVec3;
735 #[inline]
736 fn mul(self, rhs: UVec3) -> UVec3 {
737 (*self).mul(rhs)
738 }
739}
740
741impl MulAssign<UVec3> for UVec3 {
742 #[inline]
743 fn mul_assign(&mut self, rhs: Self) {
744 self.x.mul_assign(rhs.x);
745 self.y.mul_assign(rhs.y);
746 self.z.mul_assign(rhs.z);
747 }
748}
749
750impl MulAssign<&Self> for UVec3 {
751 #[inline]
752 fn mul_assign(&mut self, rhs: &Self) {
753 self.mul_assign(*rhs)
754 }
755}
756
757impl Mul<u32> for UVec3 {
758 type Output = Self;
759 #[inline]
760 fn mul(self, rhs: u32) -> Self {
761 Self {
762 x: self.x.mul(rhs),
763 y: self.y.mul(rhs),
764 z: self.z.mul(rhs),
765 }
766 }
767}
768
769impl Mul<&u32> for UVec3 {
770 type Output = UVec3;
771 #[inline]
772 fn mul(self, rhs: &u32) -> UVec3 {
773 self.mul(*rhs)
774 }
775}
776
777impl Mul<&u32> for &UVec3 {
778 type Output = UVec3;
779 #[inline]
780 fn mul(self, rhs: &u32) -> UVec3 {
781 (*self).mul(*rhs)
782 }
783}
784
785impl Mul<u32> for &UVec3 {
786 type Output = UVec3;
787 #[inline]
788 fn mul(self, rhs: u32) -> UVec3 {
789 (*self).mul(rhs)
790 }
791}
792
793impl MulAssign<u32> for UVec3 {
794 #[inline]
795 fn mul_assign(&mut self, rhs: u32) {
796 self.x.mul_assign(rhs);
797 self.y.mul_assign(rhs);
798 self.z.mul_assign(rhs);
799 }
800}
801
802impl MulAssign<&u32> for UVec3 {
803 #[inline]
804 fn mul_assign(&mut self, rhs: &u32) {
805 self.mul_assign(*rhs)
806 }
807}
808
809impl Mul<UVec3> for u32 {
810 type Output = UVec3;
811 #[inline]
812 fn mul(self, rhs: UVec3) -> UVec3 {
813 UVec3 {
814 x: self.mul(rhs.x),
815 y: self.mul(rhs.y),
816 z: self.mul(rhs.z),
817 }
818 }
819}
820
821impl Mul<&UVec3> for u32 {
822 type Output = UVec3;
823 #[inline]
824 fn mul(self, rhs: &UVec3) -> UVec3 {
825 self.mul(*rhs)
826 }
827}
828
829impl Mul<&UVec3> for &u32 {
830 type Output = UVec3;
831 #[inline]
832 fn mul(self, rhs: &UVec3) -> UVec3 {
833 (*self).mul(*rhs)
834 }
835}
836
837impl Mul<UVec3> for &u32 {
838 type Output = UVec3;
839 #[inline]
840 fn mul(self, rhs: UVec3) -> UVec3 {
841 (*self).mul(rhs)
842 }
843}
844
845impl Add<UVec3> for UVec3 {
846 type Output = Self;
847 #[inline]
848 fn add(self, rhs: Self) -> Self {
849 Self {
850 x: self.x.add(rhs.x),
851 y: self.y.add(rhs.y),
852 z: self.z.add(rhs.z),
853 }
854 }
855}
856
857impl Add<&UVec3> for UVec3 {
858 type Output = UVec3;
859 #[inline]
860 fn add(self, rhs: &UVec3) -> UVec3 {
861 self.add(*rhs)
862 }
863}
864
865impl Add<&UVec3> for &UVec3 {
866 type Output = UVec3;
867 #[inline]
868 fn add(self, rhs: &UVec3) -> UVec3 {
869 (*self).add(*rhs)
870 }
871}
872
873impl Add<UVec3> for &UVec3 {
874 type Output = UVec3;
875 #[inline]
876 fn add(self, rhs: UVec3) -> UVec3 {
877 (*self).add(rhs)
878 }
879}
880
881impl AddAssign<UVec3> for UVec3 {
882 #[inline]
883 fn add_assign(&mut self, rhs: Self) {
884 self.x.add_assign(rhs.x);
885 self.y.add_assign(rhs.y);
886 self.z.add_assign(rhs.z);
887 }
888}
889
890impl AddAssign<&Self> for UVec3 {
891 #[inline]
892 fn add_assign(&mut self, rhs: &Self) {
893 self.add_assign(*rhs)
894 }
895}
896
897impl Add<u32> for UVec3 {
898 type Output = Self;
899 #[inline]
900 fn add(self, rhs: u32) -> Self {
901 Self {
902 x: self.x.add(rhs),
903 y: self.y.add(rhs),
904 z: self.z.add(rhs),
905 }
906 }
907}
908
909impl Add<&u32> for UVec3 {
910 type Output = UVec3;
911 #[inline]
912 fn add(self, rhs: &u32) -> UVec3 {
913 self.add(*rhs)
914 }
915}
916
917impl Add<&u32> for &UVec3 {
918 type Output = UVec3;
919 #[inline]
920 fn add(self, rhs: &u32) -> UVec3 {
921 (*self).add(*rhs)
922 }
923}
924
925impl Add<u32> for &UVec3 {
926 type Output = UVec3;
927 #[inline]
928 fn add(self, rhs: u32) -> UVec3 {
929 (*self).add(rhs)
930 }
931}
932
933impl AddAssign<u32> for UVec3 {
934 #[inline]
935 fn add_assign(&mut self, rhs: u32) {
936 self.x.add_assign(rhs);
937 self.y.add_assign(rhs);
938 self.z.add_assign(rhs);
939 }
940}
941
942impl AddAssign<&u32> for UVec3 {
943 #[inline]
944 fn add_assign(&mut self, rhs: &u32) {
945 self.add_assign(*rhs)
946 }
947}
948
949impl Add<UVec3> for u32 {
950 type Output = UVec3;
951 #[inline]
952 fn add(self, rhs: UVec3) -> UVec3 {
953 UVec3 {
954 x: self.add(rhs.x),
955 y: self.add(rhs.y),
956 z: self.add(rhs.z),
957 }
958 }
959}
960
961impl Add<&UVec3> for u32 {
962 type Output = UVec3;
963 #[inline]
964 fn add(self, rhs: &UVec3) -> UVec3 {
965 self.add(*rhs)
966 }
967}
968
969impl Add<&UVec3> for &u32 {
970 type Output = UVec3;
971 #[inline]
972 fn add(self, rhs: &UVec3) -> UVec3 {
973 (*self).add(*rhs)
974 }
975}
976
977impl Add<UVec3> for &u32 {
978 type Output = UVec3;
979 #[inline]
980 fn add(self, rhs: UVec3) -> UVec3 {
981 (*self).add(rhs)
982 }
983}
984
985impl Sub<UVec3> for UVec3 {
986 type Output = Self;
987 #[inline]
988 fn sub(self, rhs: Self) -> Self {
989 Self {
990 x: self.x.sub(rhs.x),
991 y: self.y.sub(rhs.y),
992 z: self.z.sub(rhs.z),
993 }
994 }
995}
996
997impl Sub<&UVec3> for UVec3 {
998 type Output = UVec3;
999 #[inline]
1000 fn sub(self, rhs: &UVec3) -> UVec3 {
1001 self.sub(*rhs)
1002 }
1003}
1004
1005impl Sub<&UVec3> for &UVec3 {
1006 type Output = UVec3;
1007 #[inline]
1008 fn sub(self, rhs: &UVec3) -> UVec3 {
1009 (*self).sub(*rhs)
1010 }
1011}
1012
1013impl Sub<UVec3> for &UVec3 {
1014 type Output = UVec3;
1015 #[inline]
1016 fn sub(self, rhs: UVec3) -> UVec3 {
1017 (*self).sub(rhs)
1018 }
1019}
1020
1021impl SubAssign<UVec3> for UVec3 {
1022 #[inline]
1023 fn sub_assign(&mut self, rhs: UVec3) {
1024 self.x.sub_assign(rhs.x);
1025 self.y.sub_assign(rhs.y);
1026 self.z.sub_assign(rhs.z);
1027 }
1028}
1029
1030impl SubAssign<&Self> for UVec3 {
1031 #[inline]
1032 fn sub_assign(&mut self, rhs: &Self) {
1033 self.sub_assign(*rhs)
1034 }
1035}
1036
1037impl Sub<u32> for UVec3 {
1038 type Output = Self;
1039 #[inline]
1040 fn sub(self, rhs: u32) -> Self {
1041 Self {
1042 x: self.x.sub(rhs),
1043 y: self.y.sub(rhs),
1044 z: self.z.sub(rhs),
1045 }
1046 }
1047}
1048
1049impl Sub<&u32> for UVec3 {
1050 type Output = UVec3;
1051 #[inline]
1052 fn sub(self, rhs: &u32) -> UVec3 {
1053 self.sub(*rhs)
1054 }
1055}
1056
1057impl Sub<&u32> for &UVec3 {
1058 type Output = UVec3;
1059 #[inline]
1060 fn sub(self, rhs: &u32) -> UVec3 {
1061 (*self).sub(*rhs)
1062 }
1063}
1064
1065impl Sub<u32> for &UVec3 {
1066 type Output = UVec3;
1067 #[inline]
1068 fn sub(self, rhs: u32) -> UVec3 {
1069 (*self).sub(rhs)
1070 }
1071}
1072
1073impl SubAssign<u32> for UVec3 {
1074 #[inline]
1075 fn sub_assign(&mut self, rhs: u32) {
1076 self.x.sub_assign(rhs);
1077 self.y.sub_assign(rhs);
1078 self.z.sub_assign(rhs);
1079 }
1080}
1081
1082impl SubAssign<&u32> for UVec3 {
1083 #[inline]
1084 fn sub_assign(&mut self, rhs: &u32) {
1085 self.sub_assign(*rhs)
1086 }
1087}
1088
1089impl Sub<UVec3> for u32 {
1090 type Output = UVec3;
1091 #[inline]
1092 fn sub(self, rhs: UVec3) -> UVec3 {
1093 UVec3 {
1094 x: self.sub(rhs.x),
1095 y: self.sub(rhs.y),
1096 z: self.sub(rhs.z),
1097 }
1098 }
1099}
1100
1101impl Sub<&UVec3> for u32 {
1102 type Output = UVec3;
1103 #[inline]
1104 fn sub(self, rhs: &UVec3) -> UVec3 {
1105 self.sub(*rhs)
1106 }
1107}
1108
1109impl Sub<&UVec3> for &u32 {
1110 type Output = UVec3;
1111 #[inline]
1112 fn sub(self, rhs: &UVec3) -> UVec3 {
1113 (*self).sub(*rhs)
1114 }
1115}
1116
1117impl Sub<UVec3> for &u32 {
1118 type Output = UVec3;
1119 #[inline]
1120 fn sub(self, rhs: UVec3) -> UVec3 {
1121 (*self).sub(rhs)
1122 }
1123}
1124
1125impl Rem<UVec3> for UVec3 {
1126 type Output = Self;
1127 #[inline]
1128 fn rem(self, rhs: Self) -> Self {
1129 Self {
1130 x: self.x.rem(rhs.x),
1131 y: self.y.rem(rhs.y),
1132 z: self.z.rem(rhs.z),
1133 }
1134 }
1135}
1136
1137impl Rem<&UVec3> for UVec3 {
1138 type Output = UVec3;
1139 #[inline]
1140 fn rem(self, rhs: &UVec3) -> UVec3 {
1141 self.rem(*rhs)
1142 }
1143}
1144
1145impl Rem<&UVec3> for &UVec3 {
1146 type Output = UVec3;
1147 #[inline]
1148 fn rem(self, rhs: &UVec3) -> UVec3 {
1149 (*self).rem(*rhs)
1150 }
1151}
1152
1153impl Rem<UVec3> for &UVec3 {
1154 type Output = UVec3;
1155 #[inline]
1156 fn rem(self, rhs: UVec3) -> UVec3 {
1157 (*self).rem(rhs)
1158 }
1159}
1160
1161impl RemAssign<UVec3> for UVec3 {
1162 #[inline]
1163 fn rem_assign(&mut self, rhs: Self) {
1164 self.x.rem_assign(rhs.x);
1165 self.y.rem_assign(rhs.y);
1166 self.z.rem_assign(rhs.z);
1167 }
1168}
1169
1170impl RemAssign<&Self> for UVec3 {
1171 #[inline]
1172 fn rem_assign(&mut self, rhs: &Self) {
1173 self.rem_assign(*rhs)
1174 }
1175}
1176
1177impl Rem<u32> for UVec3 {
1178 type Output = Self;
1179 #[inline]
1180 fn rem(self, rhs: u32) -> Self {
1181 Self {
1182 x: self.x.rem(rhs),
1183 y: self.y.rem(rhs),
1184 z: self.z.rem(rhs),
1185 }
1186 }
1187}
1188
1189impl Rem<&u32> for UVec3 {
1190 type Output = UVec3;
1191 #[inline]
1192 fn rem(self, rhs: &u32) -> UVec3 {
1193 self.rem(*rhs)
1194 }
1195}
1196
1197impl Rem<&u32> for &UVec3 {
1198 type Output = UVec3;
1199 #[inline]
1200 fn rem(self, rhs: &u32) -> UVec3 {
1201 (*self).rem(*rhs)
1202 }
1203}
1204
1205impl Rem<u32> for &UVec3 {
1206 type Output = UVec3;
1207 #[inline]
1208 fn rem(self, rhs: u32) -> UVec3 {
1209 (*self).rem(rhs)
1210 }
1211}
1212
1213impl RemAssign<u32> for UVec3 {
1214 #[inline]
1215 fn rem_assign(&mut self, rhs: u32) {
1216 self.x.rem_assign(rhs);
1217 self.y.rem_assign(rhs);
1218 self.z.rem_assign(rhs);
1219 }
1220}
1221
1222impl RemAssign<&u32> for UVec3 {
1223 #[inline]
1224 fn rem_assign(&mut self, rhs: &u32) {
1225 self.rem_assign(*rhs)
1226 }
1227}
1228
1229impl Rem<UVec3> for u32 {
1230 type Output = UVec3;
1231 #[inline]
1232 fn rem(self, rhs: UVec3) -> UVec3 {
1233 UVec3 {
1234 x: self.rem(rhs.x),
1235 y: self.rem(rhs.y),
1236 z: self.rem(rhs.z),
1237 }
1238 }
1239}
1240
1241impl Rem<&UVec3> for u32 {
1242 type Output = UVec3;
1243 #[inline]
1244 fn rem(self, rhs: &UVec3) -> UVec3 {
1245 self.rem(*rhs)
1246 }
1247}
1248
1249impl Rem<&UVec3> for &u32 {
1250 type Output = UVec3;
1251 #[inline]
1252 fn rem(self, rhs: &UVec3) -> UVec3 {
1253 (*self).rem(*rhs)
1254 }
1255}
1256
1257impl Rem<UVec3> for &u32 {
1258 type Output = UVec3;
1259 #[inline]
1260 fn rem(self, rhs: UVec3) -> UVec3 {
1261 (*self).rem(rhs)
1262 }
1263}
1264
1265#[cfg(not(target_arch = "spirv"))]
1266impl AsRef<[u32; 3]> for UVec3 {
1267 #[inline]
1268 fn as_ref(&self) -> &[u32; 3] {
1269 unsafe { &*(self as *const UVec3 as *const [u32; 3]) }
1270 }
1271}
1272
1273#[cfg(not(target_arch = "spirv"))]
1274impl AsMut<[u32; 3]> for UVec3 {
1275 #[inline]
1276 fn as_mut(&mut self) -> &mut [u32; 3] {
1277 unsafe { &mut *(self as *mut UVec3 as *mut [u32; 3]) }
1278 }
1279}
1280
1281impl Sum for UVec3 {
1282 #[inline]
1283 fn sum<I>(iter: I) -> Self
1284 where
1285 I: Iterator<Item = Self>,
1286 {
1287 iter.fold(Self::ZERO, Self::add)
1288 }
1289}
1290
1291impl<'a> Sum<&'a Self> for UVec3 {
1292 #[inline]
1293 fn sum<I>(iter: I) -> Self
1294 where
1295 I: Iterator<Item = &'a Self>,
1296 {
1297 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1298 }
1299}
1300
1301impl Product for UVec3 {
1302 #[inline]
1303 fn product<I>(iter: I) -> Self
1304 where
1305 I: Iterator<Item = Self>,
1306 {
1307 iter.fold(Self::ONE, Self::mul)
1308 }
1309}
1310
1311impl<'a> Product<&'a Self> for UVec3 {
1312 #[inline]
1313 fn product<I>(iter: I) -> Self
1314 where
1315 I: Iterator<Item = &'a Self>,
1316 {
1317 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1318 }
1319}
1320
1321impl Not for UVec3 {
1322 type Output = Self;
1323 #[inline]
1324 fn not(self) -> Self::Output {
1325 Self {
1326 x: self.x.not(),
1327 y: self.y.not(),
1328 z: self.z.not(),
1329 }
1330 }
1331}
1332
1333impl BitAnd for UVec3 {
1334 type Output = Self;
1335 #[inline]
1336 fn bitand(self, rhs: Self) -> Self::Output {
1337 Self {
1338 x: self.x.bitand(rhs.x),
1339 y: self.y.bitand(rhs.y),
1340 z: self.z.bitand(rhs.z),
1341 }
1342 }
1343}
1344
1345impl BitOr for UVec3 {
1346 type Output = Self;
1347 #[inline]
1348 fn bitor(self, rhs: Self) -> Self::Output {
1349 Self {
1350 x: self.x.bitor(rhs.x),
1351 y: self.y.bitor(rhs.y),
1352 z: self.z.bitor(rhs.z),
1353 }
1354 }
1355}
1356
1357impl BitXor for UVec3 {
1358 type Output = Self;
1359 #[inline]
1360 fn bitxor(self, rhs: Self) -> Self::Output {
1361 Self {
1362 x: self.x.bitxor(rhs.x),
1363 y: self.y.bitxor(rhs.y),
1364 z: self.z.bitxor(rhs.z),
1365 }
1366 }
1367}
1368
1369impl BitAnd<u32> for UVec3 {
1370 type Output = Self;
1371 #[inline]
1372 fn bitand(self, rhs: u32) -> Self::Output {
1373 Self {
1374 x: self.x.bitand(rhs),
1375 y: self.y.bitand(rhs),
1376 z: self.z.bitand(rhs),
1377 }
1378 }
1379}
1380
1381impl BitOr<u32> for UVec3 {
1382 type Output = Self;
1383 #[inline]
1384 fn bitor(self, rhs: u32) -> Self::Output {
1385 Self {
1386 x: self.x.bitor(rhs),
1387 y: self.y.bitor(rhs),
1388 z: self.z.bitor(rhs),
1389 }
1390 }
1391}
1392
1393impl BitXor<u32> for UVec3 {
1394 type Output = Self;
1395 #[inline]
1396 fn bitxor(self, rhs: u32) -> Self::Output {
1397 Self {
1398 x: self.x.bitxor(rhs),
1399 y: self.y.bitxor(rhs),
1400 z: self.z.bitxor(rhs),
1401 }
1402 }
1403}
1404
1405impl Shl<i8> for UVec3 {
1406 type Output = Self;
1407 #[inline]
1408 fn shl(self, rhs: i8) -> Self::Output {
1409 Self {
1410 x: self.x.shl(rhs),
1411 y: self.y.shl(rhs),
1412 z: self.z.shl(rhs),
1413 }
1414 }
1415}
1416
1417impl Shr<i8> for UVec3 {
1418 type Output = Self;
1419 #[inline]
1420 fn shr(self, rhs: i8) -> Self::Output {
1421 Self {
1422 x: self.x.shr(rhs),
1423 y: self.y.shr(rhs),
1424 z: self.z.shr(rhs),
1425 }
1426 }
1427}
1428
1429impl Shl<i16> for UVec3 {
1430 type Output = Self;
1431 #[inline]
1432 fn shl(self, rhs: i16) -> Self::Output {
1433 Self {
1434 x: self.x.shl(rhs),
1435 y: self.y.shl(rhs),
1436 z: self.z.shl(rhs),
1437 }
1438 }
1439}
1440
1441impl Shr<i16> for UVec3 {
1442 type Output = Self;
1443 #[inline]
1444 fn shr(self, rhs: i16) -> Self::Output {
1445 Self {
1446 x: self.x.shr(rhs),
1447 y: self.y.shr(rhs),
1448 z: self.z.shr(rhs),
1449 }
1450 }
1451}
1452
1453impl Shl<i32> for UVec3 {
1454 type Output = Self;
1455 #[inline]
1456 fn shl(self, rhs: i32) -> Self::Output {
1457 Self {
1458 x: self.x.shl(rhs),
1459 y: self.y.shl(rhs),
1460 z: self.z.shl(rhs),
1461 }
1462 }
1463}
1464
1465impl Shr<i32> for UVec3 {
1466 type Output = Self;
1467 #[inline]
1468 fn shr(self, rhs: i32) -> Self::Output {
1469 Self {
1470 x: self.x.shr(rhs),
1471 y: self.y.shr(rhs),
1472 z: self.z.shr(rhs),
1473 }
1474 }
1475}
1476
1477impl Shl<i64> for UVec3 {
1478 type Output = Self;
1479 #[inline]
1480 fn shl(self, rhs: i64) -> Self::Output {
1481 Self {
1482 x: self.x.shl(rhs),
1483 y: self.y.shl(rhs),
1484 z: self.z.shl(rhs),
1485 }
1486 }
1487}
1488
1489impl Shr<i64> for UVec3 {
1490 type Output = Self;
1491 #[inline]
1492 fn shr(self, rhs: i64) -> Self::Output {
1493 Self {
1494 x: self.x.shr(rhs),
1495 y: self.y.shr(rhs),
1496 z: self.z.shr(rhs),
1497 }
1498 }
1499}
1500
1501impl Shl<u8> for UVec3 {
1502 type Output = Self;
1503 #[inline]
1504 fn shl(self, rhs: u8) -> Self::Output {
1505 Self {
1506 x: self.x.shl(rhs),
1507 y: self.y.shl(rhs),
1508 z: self.z.shl(rhs),
1509 }
1510 }
1511}
1512
1513impl Shr<u8> for UVec3 {
1514 type Output = Self;
1515 #[inline]
1516 fn shr(self, rhs: u8) -> Self::Output {
1517 Self {
1518 x: self.x.shr(rhs),
1519 y: self.y.shr(rhs),
1520 z: self.z.shr(rhs),
1521 }
1522 }
1523}
1524
1525impl Shl<u16> for UVec3 {
1526 type Output = Self;
1527 #[inline]
1528 fn shl(self, rhs: u16) -> Self::Output {
1529 Self {
1530 x: self.x.shl(rhs),
1531 y: self.y.shl(rhs),
1532 z: self.z.shl(rhs),
1533 }
1534 }
1535}
1536
1537impl Shr<u16> for UVec3 {
1538 type Output = Self;
1539 #[inline]
1540 fn shr(self, rhs: u16) -> Self::Output {
1541 Self {
1542 x: self.x.shr(rhs),
1543 y: self.y.shr(rhs),
1544 z: self.z.shr(rhs),
1545 }
1546 }
1547}
1548
1549impl Shl<u32> for UVec3 {
1550 type Output = Self;
1551 #[inline]
1552 fn shl(self, rhs: u32) -> Self::Output {
1553 Self {
1554 x: self.x.shl(rhs),
1555 y: self.y.shl(rhs),
1556 z: self.z.shl(rhs),
1557 }
1558 }
1559}
1560
1561impl Shr<u32> for UVec3 {
1562 type Output = Self;
1563 #[inline]
1564 fn shr(self, rhs: u32) -> Self::Output {
1565 Self {
1566 x: self.x.shr(rhs),
1567 y: self.y.shr(rhs),
1568 z: self.z.shr(rhs),
1569 }
1570 }
1571}
1572
1573impl Shl<u64> for UVec3 {
1574 type Output = Self;
1575 #[inline]
1576 fn shl(self, rhs: u64) -> Self::Output {
1577 Self {
1578 x: self.x.shl(rhs),
1579 y: self.y.shl(rhs),
1580 z: self.z.shl(rhs),
1581 }
1582 }
1583}
1584
1585impl Shr<u64> for UVec3 {
1586 type Output = Self;
1587 #[inline]
1588 fn shr(self, rhs: u64) -> Self::Output {
1589 Self {
1590 x: self.x.shr(rhs),
1591 y: self.y.shr(rhs),
1592 z: self.z.shr(rhs),
1593 }
1594 }
1595}
1596
1597impl Shl<crate::IVec3> for UVec3 {
1598 type Output = Self;
1599 #[inline]
1600 fn shl(self, rhs: crate::IVec3) -> Self::Output {
1601 Self {
1602 x: self.x.shl(rhs.x),
1603 y: self.y.shl(rhs.y),
1604 z: self.z.shl(rhs.z),
1605 }
1606 }
1607}
1608
1609impl Shr<crate::IVec3> for UVec3 {
1610 type Output = Self;
1611 #[inline]
1612 fn shr(self, rhs: crate::IVec3) -> Self::Output {
1613 Self {
1614 x: self.x.shr(rhs.x),
1615 y: self.y.shr(rhs.y),
1616 z: self.z.shr(rhs.z),
1617 }
1618 }
1619}
1620
1621impl Shl<crate::UVec3> for UVec3 {
1622 type Output = Self;
1623 #[inline]
1624 fn shl(self, rhs: crate::UVec3) -> Self::Output {
1625 Self {
1626 x: self.x.shl(rhs.x),
1627 y: self.y.shl(rhs.y),
1628 z: self.z.shl(rhs.z),
1629 }
1630 }
1631}
1632
1633impl Shr<crate::UVec3> for UVec3 {
1634 type Output = Self;
1635 #[inline]
1636 fn shr(self, rhs: crate::UVec3) -> Self::Output {
1637 Self {
1638 x: self.x.shr(rhs.x),
1639 y: self.y.shr(rhs.y),
1640 z: self.z.shr(rhs.z),
1641 }
1642 }
1643}
1644
1645impl Index<usize> for UVec3 {
1646 type Output = u32;
1647 #[inline]
1648 fn index(&self, index: usize) -> &Self::Output {
1649 match index {
1650 0 => &self.x,
1651 1 => &self.y,
1652 2 => &self.z,
1653 _ => panic!("index out of bounds"),
1654 }
1655 }
1656}
1657
1658impl IndexMut<usize> for UVec3 {
1659 #[inline]
1660 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1661 match index {
1662 0 => &mut self.x,
1663 1 => &mut self.y,
1664 2 => &mut self.z,
1665 _ => panic!("index out of bounds"),
1666 }
1667 }
1668}
1669
1670impl fmt::Display for UVec3 {
1671 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1672 write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
1673 }
1674}
1675
1676impl fmt::Debug for UVec3 {
1677 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1678 fmt.debug_tuple(stringify!(UVec3))
1679 .field(&self.x)
1680 .field(&self.y)
1681 .field(&self.z)
1682 .finish()
1683 }
1684}
1685
1686impl From<[u32; 3]> for UVec3 {
1687 #[inline]
1688 fn from(a: [u32; 3]) -> Self {
1689 Self::new(a[0], a[1], a[2])
1690 }
1691}
1692
1693impl From<UVec3> for [u32; 3] {
1694 #[inline]
1695 fn from(v: UVec3) -> Self {
1696 [v.x, v.y, v.z]
1697 }
1698}
1699
1700impl From<(u32, u32, u32)> for UVec3 {
1701 #[inline]
1702 fn from(t: (u32, u32, u32)) -> Self {
1703 Self::new(t.0, t.1, t.2)
1704 }
1705}
1706
1707impl From<UVec3> for (u32, u32, u32) {
1708 #[inline]
1709 fn from(v: UVec3) -> Self {
1710 (v.x, v.y, v.z)
1711 }
1712}
1713
1714impl From<(UVec2, u32)> for UVec3 {
1715 #[inline]
1716 fn from((v, z): (UVec2, u32)) -> Self {
1717 Self::new(v.x, v.y, z)
1718 }
1719}
1720
1721impl From<U8Vec3> for UVec3 {
1722 #[inline]
1723 fn from(v: U8Vec3) -> Self {
1724 Self::new(u32::from(v.x), u32::from(v.y), u32::from(v.z))
1725 }
1726}
1727
1728impl From<U16Vec3> for UVec3 {
1729 #[inline]
1730 fn from(v: U16Vec3) -> Self {
1731 Self::new(u32::from(v.x), u32::from(v.y), u32::from(v.z))
1732 }
1733}
1734
1735impl TryFrom<I8Vec3> for UVec3 {
1736 type Error = core::num::TryFromIntError;
1737
1738 #[inline]
1739 fn try_from(v: I8Vec3) -> Result<Self, Self::Error> {
1740 Ok(Self::new(
1741 u32::try_from(v.x)?,
1742 u32::try_from(v.y)?,
1743 u32::try_from(v.z)?,
1744 ))
1745 }
1746}
1747
1748impl TryFrom<I16Vec3> for UVec3 {
1749 type Error = core::num::TryFromIntError;
1750
1751 #[inline]
1752 fn try_from(v: I16Vec3) -> Result<Self, Self::Error> {
1753 Ok(Self::new(
1754 u32::try_from(v.x)?,
1755 u32::try_from(v.y)?,
1756 u32::try_from(v.z)?,
1757 ))
1758 }
1759}
1760
1761impl TryFrom<IVec3> for UVec3 {
1762 type Error = core::num::TryFromIntError;
1763
1764 #[inline]
1765 fn try_from(v: IVec3) -> Result<Self, Self::Error> {
1766 Ok(Self::new(
1767 u32::try_from(v.x)?,
1768 u32::try_from(v.y)?,
1769 u32::try_from(v.z)?,
1770 ))
1771 }
1772}
1773
1774impl TryFrom<I64Vec3> for UVec3 {
1775 type Error = core::num::TryFromIntError;
1776
1777 #[inline]
1778 fn try_from(v: I64Vec3) -> Result<Self, Self::Error> {
1779 Ok(Self::new(
1780 u32::try_from(v.x)?,
1781 u32::try_from(v.y)?,
1782 u32::try_from(v.z)?,
1783 ))
1784 }
1785}
1786
1787impl TryFrom<U64Vec3> for UVec3 {
1788 type Error = core::num::TryFromIntError;
1789
1790 #[inline]
1791 fn try_from(v: U64Vec3) -> Result<Self, Self::Error> {
1792 Ok(Self::new(
1793 u32::try_from(v.x)?,
1794 u32::try_from(v.y)?,
1795 u32::try_from(v.z)?,
1796 ))
1797 }
1798}
1799
1800impl From<BVec3> for UVec3 {
1801 #[inline]
1802 fn from(v: BVec3) -> Self {
1803 Self::new(u32::from(v.x), u32::from(v.y), u32::from(v.z))
1804 }
1805}
1806
1807impl From<BVec3A> for UVec3 {
1808 #[inline]
1809 fn from(v: BVec3A) -> Self {
1810 let bool_array: [bool; 3] = v.into();
1811 Self::new(
1812 u32::from(bool_array[0]),
1813 u32::from(bool_array[1]),
1814 u32::from(bool_array[2]),
1815 )
1816 }
1817}