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