1use crate::{BVec2, I16Vec2, I64Vec2, I8Vec2, IVec2, U16Vec2, U64Vec2, U8Vec2, USizeVec3, UVec2};
4
5use core::fmt;
6use core::iter::{Product, Sum};
7use core::{f32, ops::*};
8
9#[inline(always)]
11#[must_use]
12pub const fn usizevec2(x: usize, y: usize) -> USizeVec2 {
13 USizeVec2::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(16)))]
20#[cfg_attr(not(target_arch = "spirv"), repr(C))]
21#[cfg_attr(target_arch = "spirv", repr(simd))]
22pub struct USizeVec2 {
23 pub x: usize,
24 pub y: usize,
25}
26
27impl USizeVec2 {
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(usize::MIN);
36
37 pub const MAX: Self = Self::splat(usize::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: usize, y: usize) -> Self {
53 Self { x, y }
54 }
55
56 #[inline]
58 #[must_use]
59 pub const fn splat(v: usize) -> 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(usize) -> usize,
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: [usize; 2]) -> Self {
91 Self::new(a[0], a[1])
92 }
93
94 #[inline]
96 #[must_use]
97 pub const fn to_array(&self) -> [usize; 2] {
98 [self.x, self.y]
99 }
100
101 #[inline]
107 #[must_use]
108 pub const fn from_slice(slice: &[usize]) -> 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 [usize]) {
120 slice[..2].copy_from_slice(&self.to_array());
121 }
122
123 #[inline]
125 #[must_use]
126 pub const fn extend(self, z: usize) -> USizeVec3 {
127 USizeVec3::new(self.x, self.y, z)
128 }
129
130 #[inline]
132 #[must_use]
133 pub fn with_x(mut self, x: usize) -> Self {
134 self.x = x;
135 self
136 }
137
138 #[inline]
140 #[must_use]
141 pub fn with_y(mut self, y: usize) -> Self {
142 self.y = y;
143 self
144 }
145
146 #[inline]
148 #[must_use]
149 pub fn dot(self, rhs: Self) -> usize {
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) -> usize {
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) -> usize {
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) -> usize {
248 self.x + self.y
249 }
250
251 #[inline]
255 #[must_use]
256 pub fn element_product(self) -> usize {
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) -> usize {
331 self.dot(self)
332 }
333
334 #[inline]
343 #[must_use]
344 pub fn manhattan_distance(self, other: Self) -> usize {
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<usize> {
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) -> usize {
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_uvec2(&self) -> crate::UVec2 {
426 crate::UVec2::new(self.x as u32, self.y as u32)
427 }
428
429 #[inline]
431 #[must_use]
432 pub fn as_i64vec2(&self) -> crate::I64Vec2 {
433 crate::I64Vec2::new(self.x as i64, self.y as i64)
434 }
435
436 #[inline]
438 #[must_use]
439 pub fn as_u64vec2(&self) -> crate::U64Vec2 {
440 crate::U64Vec2::new(self.x as u64, self.y as u64)
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
612impl Default for USizeVec2 {
613 #[inline(always)]
614 fn default() -> Self {
615 Self::ZERO
616 }
617}
618
619impl Div<USizeVec2> for USizeVec2 {
620 type Output = Self;
621 #[inline]
622 fn div(self, rhs: Self) -> Self {
623 Self {
624 x: self.x.div(rhs.x),
625 y: self.y.div(rhs.y),
626 }
627 }
628}
629
630impl Div<&USizeVec2> for USizeVec2 {
631 type Output = USizeVec2;
632 #[inline]
633 fn div(self, rhs: &USizeVec2) -> USizeVec2 {
634 self.div(*rhs)
635 }
636}
637
638impl Div<&USizeVec2> for &USizeVec2 {
639 type Output = USizeVec2;
640 #[inline]
641 fn div(self, rhs: &USizeVec2) -> USizeVec2 {
642 (*self).div(*rhs)
643 }
644}
645
646impl Div<USizeVec2> for &USizeVec2 {
647 type Output = USizeVec2;
648 #[inline]
649 fn div(self, rhs: USizeVec2) -> USizeVec2 {
650 (*self).div(rhs)
651 }
652}
653
654impl DivAssign<USizeVec2> for USizeVec2 {
655 #[inline]
656 fn div_assign(&mut self, rhs: Self) {
657 self.x.div_assign(rhs.x);
658 self.y.div_assign(rhs.y);
659 }
660}
661
662impl DivAssign<&USizeVec2> for USizeVec2 {
663 #[inline]
664 fn div_assign(&mut self, rhs: &USizeVec2) {
665 self.div_assign(*rhs)
666 }
667}
668
669impl Div<usize> for USizeVec2 {
670 type Output = Self;
671 #[inline]
672 fn div(self, rhs: usize) -> Self {
673 Self {
674 x: self.x.div(rhs),
675 y: self.y.div(rhs),
676 }
677 }
678}
679
680impl Div<&usize> for USizeVec2 {
681 type Output = USizeVec2;
682 #[inline]
683 fn div(self, rhs: &usize) -> USizeVec2 {
684 self.div(*rhs)
685 }
686}
687
688impl Div<&usize> for &USizeVec2 {
689 type Output = USizeVec2;
690 #[inline]
691 fn div(self, rhs: &usize) -> USizeVec2 {
692 (*self).div(*rhs)
693 }
694}
695
696impl Div<usize> for &USizeVec2 {
697 type Output = USizeVec2;
698 #[inline]
699 fn div(self, rhs: usize) -> USizeVec2 {
700 (*self).div(rhs)
701 }
702}
703
704impl DivAssign<usize> for USizeVec2 {
705 #[inline]
706 fn div_assign(&mut self, rhs: usize) {
707 self.x.div_assign(rhs);
708 self.y.div_assign(rhs);
709 }
710}
711
712impl DivAssign<&usize> for USizeVec2 {
713 #[inline]
714 fn div_assign(&mut self, rhs: &usize) {
715 self.div_assign(*rhs)
716 }
717}
718
719impl Div<USizeVec2> for usize {
720 type Output = USizeVec2;
721 #[inline]
722 fn div(self, rhs: USizeVec2) -> USizeVec2 {
723 USizeVec2 {
724 x: self.div(rhs.x),
725 y: self.div(rhs.y),
726 }
727 }
728}
729
730impl Div<&USizeVec2> for usize {
731 type Output = USizeVec2;
732 #[inline]
733 fn div(self, rhs: &USizeVec2) -> USizeVec2 {
734 self.div(*rhs)
735 }
736}
737
738impl Div<&USizeVec2> for &usize {
739 type Output = USizeVec2;
740 #[inline]
741 fn div(self, rhs: &USizeVec2) -> USizeVec2 {
742 (*self).div(*rhs)
743 }
744}
745
746impl Div<USizeVec2> for &usize {
747 type Output = USizeVec2;
748 #[inline]
749 fn div(self, rhs: USizeVec2) -> USizeVec2 {
750 (*self).div(rhs)
751 }
752}
753
754impl Mul<USizeVec2> for USizeVec2 {
755 type Output = Self;
756 #[inline]
757 fn mul(self, rhs: Self) -> Self {
758 Self {
759 x: self.x.mul(rhs.x),
760 y: self.y.mul(rhs.y),
761 }
762 }
763}
764
765impl Mul<&USizeVec2> for USizeVec2 {
766 type Output = USizeVec2;
767 #[inline]
768 fn mul(self, rhs: &USizeVec2) -> USizeVec2 {
769 self.mul(*rhs)
770 }
771}
772
773impl Mul<&USizeVec2> for &USizeVec2 {
774 type Output = USizeVec2;
775 #[inline]
776 fn mul(self, rhs: &USizeVec2) -> USizeVec2 {
777 (*self).mul(*rhs)
778 }
779}
780
781impl Mul<USizeVec2> for &USizeVec2 {
782 type Output = USizeVec2;
783 #[inline]
784 fn mul(self, rhs: USizeVec2) -> USizeVec2 {
785 (*self).mul(rhs)
786 }
787}
788
789impl MulAssign<USizeVec2> for USizeVec2 {
790 #[inline]
791 fn mul_assign(&mut self, rhs: Self) {
792 self.x.mul_assign(rhs.x);
793 self.y.mul_assign(rhs.y);
794 }
795}
796
797impl MulAssign<&USizeVec2> for USizeVec2 {
798 #[inline]
799 fn mul_assign(&mut self, rhs: &USizeVec2) {
800 self.mul_assign(*rhs)
801 }
802}
803
804impl Mul<usize> for USizeVec2 {
805 type Output = Self;
806 #[inline]
807 fn mul(self, rhs: usize) -> Self {
808 Self {
809 x: self.x.mul(rhs),
810 y: self.y.mul(rhs),
811 }
812 }
813}
814
815impl Mul<&usize> for USizeVec2 {
816 type Output = USizeVec2;
817 #[inline]
818 fn mul(self, rhs: &usize) -> USizeVec2 {
819 self.mul(*rhs)
820 }
821}
822
823impl Mul<&usize> for &USizeVec2 {
824 type Output = USizeVec2;
825 #[inline]
826 fn mul(self, rhs: &usize) -> USizeVec2 {
827 (*self).mul(*rhs)
828 }
829}
830
831impl Mul<usize> for &USizeVec2 {
832 type Output = USizeVec2;
833 #[inline]
834 fn mul(self, rhs: usize) -> USizeVec2 {
835 (*self).mul(rhs)
836 }
837}
838
839impl MulAssign<usize> for USizeVec2 {
840 #[inline]
841 fn mul_assign(&mut self, rhs: usize) {
842 self.x.mul_assign(rhs);
843 self.y.mul_assign(rhs);
844 }
845}
846
847impl MulAssign<&usize> for USizeVec2 {
848 #[inline]
849 fn mul_assign(&mut self, rhs: &usize) {
850 self.mul_assign(*rhs)
851 }
852}
853
854impl Mul<USizeVec2> for usize {
855 type Output = USizeVec2;
856 #[inline]
857 fn mul(self, rhs: USizeVec2) -> USizeVec2 {
858 USizeVec2 {
859 x: self.mul(rhs.x),
860 y: self.mul(rhs.y),
861 }
862 }
863}
864
865impl Mul<&USizeVec2> for usize {
866 type Output = USizeVec2;
867 #[inline]
868 fn mul(self, rhs: &USizeVec2) -> USizeVec2 {
869 self.mul(*rhs)
870 }
871}
872
873impl Mul<&USizeVec2> for &usize {
874 type Output = USizeVec2;
875 #[inline]
876 fn mul(self, rhs: &USizeVec2) -> USizeVec2 {
877 (*self).mul(*rhs)
878 }
879}
880
881impl Mul<USizeVec2> for &usize {
882 type Output = USizeVec2;
883 #[inline]
884 fn mul(self, rhs: USizeVec2) -> USizeVec2 {
885 (*self).mul(rhs)
886 }
887}
888
889impl Add<USizeVec2> for USizeVec2 {
890 type Output = Self;
891 #[inline]
892 fn add(self, rhs: Self) -> Self {
893 Self {
894 x: self.x.add(rhs.x),
895 y: self.y.add(rhs.y),
896 }
897 }
898}
899
900impl Add<&USizeVec2> for USizeVec2 {
901 type Output = USizeVec2;
902 #[inline]
903 fn add(self, rhs: &USizeVec2) -> USizeVec2 {
904 self.add(*rhs)
905 }
906}
907
908impl Add<&USizeVec2> for &USizeVec2 {
909 type Output = USizeVec2;
910 #[inline]
911 fn add(self, rhs: &USizeVec2) -> USizeVec2 {
912 (*self).add(*rhs)
913 }
914}
915
916impl Add<USizeVec2> for &USizeVec2 {
917 type Output = USizeVec2;
918 #[inline]
919 fn add(self, rhs: USizeVec2) -> USizeVec2 {
920 (*self).add(rhs)
921 }
922}
923
924impl AddAssign<USizeVec2> for USizeVec2 {
925 #[inline]
926 fn add_assign(&mut self, rhs: Self) {
927 self.x.add_assign(rhs.x);
928 self.y.add_assign(rhs.y);
929 }
930}
931
932impl AddAssign<&USizeVec2> for USizeVec2 {
933 #[inline]
934 fn add_assign(&mut self, rhs: &USizeVec2) {
935 self.add_assign(*rhs)
936 }
937}
938
939impl Add<usize> for USizeVec2 {
940 type Output = Self;
941 #[inline]
942 fn add(self, rhs: usize) -> Self {
943 Self {
944 x: self.x.add(rhs),
945 y: self.y.add(rhs),
946 }
947 }
948}
949
950impl Add<&usize> for USizeVec2 {
951 type Output = USizeVec2;
952 #[inline]
953 fn add(self, rhs: &usize) -> USizeVec2 {
954 self.add(*rhs)
955 }
956}
957
958impl Add<&usize> for &USizeVec2 {
959 type Output = USizeVec2;
960 #[inline]
961 fn add(self, rhs: &usize) -> USizeVec2 {
962 (*self).add(*rhs)
963 }
964}
965
966impl Add<usize> for &USizeVec2 {
967 type Output = USizeVec2;
968 #[inline]
969 fn add(self, rhs: usize) -> USizeVec2 {
970 (*self).add(rhs)
971 }
972}
973
974impl AddAssign<usize> for USizeVec2 {
975 #[inline]
976 fn add_assign(&mut self, rhs: usize) {
977 self.x.add_assign(rhs);
978 self.y.add_assign(rhs);
979 }
980}
981
982impl AddAssign<&usize> for USizeVec2 {
983 #[inline]
984 fn add_assign(&mut self, rhs: &usize) {
985 self.add_assign(*rhs)
986 }
987}
988
989impl Add<USizeVec2> for usize {
990 type Output = USizeVec2;
991 #[inline]
992 fn add(self, rhs: USizeVec2) -> USizeVec2 {
993 USizeVec2 {
994 x: self.add(rhs.x),
995 y: self.add(rhs.y),
996 }
997 }
998}
999
1000impl Add<&USizeVec2> for usize {
1001 type Output = USizeVec2;
1002 #[inline]
1003 fn add(self, rhs: &USizeVec2) -> USizeVec2 {
1004 self.add(*rhs)
1005 }
1006}
1007
1008impl Add<&USizeVec2> for &usize {
1009 type Output = USizeVec2;
1010 #[inline]
1011 fn add(self, rhs: &USizeVec2) -> USizeVec2 {
1012 (*self).add(*rhs)
1013 }
1014}
1015
1016impl Add<USizeVec2> for &usize {
1017 type Output = USizeVec2;
1018 #[inline]
1019 fn add(self, rhs: USizeVec2) -> USizeVec2 {
1020 (*self).add(rhs)
1021 }
1022}
1023
1024impl Sub<USizeVec2> for USizeVec2 {
1025 type Output = Self;
1026 #[inline]
1027 fn sub(self, rhs: Self) -> Self {
1028 Self {
1029 x: self.x.sub(rhs.x),
1030 y: self.y.sub(rhs.y),
1031 }
1032 }
1033}
1034
1035impl Sub<&USizeVec2> for USizeVec2 {
1036 type Output = USizeVec2;
1037 #[inline]
1038 fn sub(self, rhs: &USizeVec2) -> USizeVec2 {
1039 self.sub(*rhs)
1040 }
1041}
1042
1043impl Sub<&USizeVec2> for &USizeVec2 {
1044 type Output = USizeVec2;
1045 #[inline]
1046 fn sub(self, rhs: &USizeVec2) -> USizeVec2 {
1047 (*self).sub(*rhs)
1048 }
1049}
1050
1051impl Sub<USizeVec2> for &USizeVec2 {
1052 type Output = USizeVec2;
1053 #[inline]
1054 fn sub(self, rhs: USizeVec2) -> USizeVec2 {
1055 (*self).sub(rhs)
1056 }
1057}
1058
1059impl SubAssign<USizeVec2> for USizeVec2 {
1060 #[inline]
1061 fn sub_assign(&mut self, rhs: USizeVec2) {
1062 self.x.sub_assign(rhs.x);
1063 self.y.sub_assign(rhs.y);
1064 }
1065}
1066
1067impl SubAssign<&USizeVec2> for USizeVec2 {
1068 #[inline]
1069 fn sub_assign(&mut self, rhs: &USizeVec2) {
1070 self.sub_assign(*rhs)
1071 }
1072}
1073
1074impl Sub<usize> for USizeVec2 {
1075 type Output = Self;
1076 #[inline]
1077 fn sub(self, rhs: usize) -> Self {
1078 Self {
1079 x: self.x.sub(rhs),
1080 y: self.y.sub(rhs),
1081 }
1082 }
1083}
1084
1085impl Sub<&usize> for USizeVec2 {
1086 type Output = USizeVec2;
1087 #[inline]
1088 fn sub(self, rhs: &usize) -> USizeVec2 {
1089 self.sub(*rhs)
1090 }
1091}
1092
1093impl Sub<&usize> for &USizeVec2 {
1094 type Output = USizeVec2;
1095 #[inline]
1096 fn sub(self, rhs: &usize) -> USizeVec2 {
1097 (*self).sub(*rhs)
1098 }
1099}
1100
1101impl Sub<usize> for &USizeVec2 {
1102 type Output = USizeVec2;
1103 #[inline]
1104 fn sub(self, rhs: usize) -> USizeVec2 {
1105 (*self).sub(rhs)
1106 }
1107}
1108
1109impl SubAssign<usize> for USizeVec2 {
1110 #[inline]
1111 fn sub_assign(&mut self, rhs: usize) {
1112 self.x.sub_assign(rhs);
1113 self.y.sub_assign(rhs);
1114 }
1115}
1116
1117impl SubAssign<&usize> for USizeVec2 {
1118 #[inline]
1119 fn sub_assign(&mut self, rhs: &usize) {
1120 self.sub_assign(*rhs)
1121 }
1122}
1123
1124impl Sub<USizeVec2> for usize {
1125 type Output = USizeVec2;
1126 #[inline]
1127 fn sub(self, rhs: USizeVec2) -> USizeVec2 {
1128 USizeVec2 {
1129 x: self.sub(rhs.x),
1130 y: self.sub(rhs.y),
1131 }
1132 }
1133}
1134
1135impl Sub<&USizeVec2> for usize {
1136 type Output = USizeVec2;
1137 #[inline]
1138 fn sub(self, rhs: &USizeVec2) -> USizeVec2 {
1139 self.sub(*rhs)
1140 }
1141}
1142
1143impl Sub<&USizeVec2> for &usize {
1144 type Output = USizeVec2;
1145 #[inline]
1146 fn sub(self, rhs: &USizeVec2) -> USizeVec2 {
1147 (*self).sub(*rhs)
1148 }
1149}
1150
1151impl Sub<USizeVec2> for &usize {
1152 type Output = USizeVec2;
1153 #[inline]
1154 fn sub(self, rhs: USizeVec2) -> USizeVec2 {
1155 (*self).sub(rhs)
1156 }
1157}
1158
1159impl Rem<USizeVec2> for USizeVec2 {
1160 type Output = Self;
1161 #[inline]
1162 fn rem(self, rhs: Self) -> Self {
1163 Self {
1164 x: self.x.rem(rhs.x),
1165 y: self.y.rem(rhs.y),
1166 }
1167 }
1168}
1169
1170impl Rem<&USizeVec2> for USizeVec2 {
1171 type Output = USizeVec2;
1172 #[inline]
1173 fn rem(self, rhs: &USizeVec2) -> USizeVec2 {
1174 self.rem(*rhs)
1175 }
1176}
1177
1178impl Rem<&USizeVec2> for &USizeVec2 {
1179 type Output = USizeVec2;
1180 #[inline]
1181 fn rem(self, rhs: &USizeVec2) -> USizeVec2 {
1182 (*self).rem(*rhs)
1183 }
1184}
1185
1186impl Rem<USizeVec2> for &USizeVec2 {
1187 type Output = USizeVec2;
1188 #[inline]
1189 fn rem(self, rhs: USizeVec2) -> USizeVec2 {
1190 (*self).rem(rhs)
1191 }
1192}
1193
1194impl RemAssign<USizeVec2> for USizeVec2 {
1195 #[inline]
1196 fn rem_assign(&mut self, rhs: Self) {
1197 self.x.rem_assign(rhs.x);
1198 self.y.rem_assign(rhs.y);
1199 }
1200}
1201
1202impl RemAssign<&USizeVec2> for USizeVec2 {
1203 #[inline]
1204 fn rem_assign(&mut self, rhs: &USizeVec2) {
1205 self.rem_assign(*rhs)
1206 }
1207}
1208
1209impl Rem<usize> for USizeVec2 {
1210 type Output = Self;
1211 #[inline]
1212 fn rem(self, rhs: usize) -> Self {
1213 Self {
1214 x: self.x.rem(rhs),
1215 y: self.y.rem(rhs),
1216 }
1217 }
1218}
1219
1220impl Rem<&usize> for USizeVec2 {
1221 type Output = USizeVec2;
1222 #[inline]
1223 fn rem(self, rhs: &usize) -> USizeVec2 {
1224 self.rem(*rhs)
1225 }
1226}
1227
1228impl Rem<&usize> for &USizeVec2 {
1229 type Output = USizeVec2;
1230 #[inline]
1231 fn rem(self, rhs: &usize) -> USizeVec2 {
1232 (*self).rem(*rhs)
1233 }
1234}
1235
1236impl Rem<usize> for &USizeVec2 {
1237 type Output = USizeVec2;
1238 #[inline]
1239 fn rem(self, rhs: usize) -> USizeVec2 {
1240 (*self).rem(rhs)
1241 }
1242}
1243
1244impl RemAssign<usize> for USizeVec2 {
1245 #[inline]
1246 fn rem_assign(&mut self, rhs: usize) {
1247 self.x.rem_assign(rhs);
1248 self.y.rem_assign(rhs);
1249 }
1250}
1251
1252impl RemAssign<&usize> for USizeVec2 {
1253 #[inline]
1254 fn rem_assign(&mut self, rhs: &usize) {
1255 self.rem_assign(*rhs)
1256 }
1257}
1258
1259impl Rem<USizeVec2> for usize {
1260 type Output = USizeVec2;
1261 #[inline]
1262 fn rem(self, rhs: USizeVec2) -> USizeVec2 {
1263 USizeVec2 {
1264 x: self.rem(rhs.x),
1265 y: self.rem(rhs.y),
1266 }
1267 }
1268}
1269
1270impl Rem<&USizeVec2> for usize {
1271 type Output = USizeVec2;
1272 #[inline]
1273 fn rem(self, rhs: &USizeVec2) -> USizeVec2 {
1274 self.rem(*rhs)
1275 }
1276}
1277
1278impl Rem<&USizeVec2> for &usize {
1279 type Output = USizeVec2;
1280 #[inline]
1281 fn rem(self, rhs: &USizeVec2) -> USizeVec2 {
1282 (*self).rem(*rhs)
1283 }
1284}
1285
1286impl Rem<USizeVec2> for &usize {
1287 type Output = USizeVec2;
1288 #[inline]
1289 fn rem(self, rhs: USizeVec2) -> USizeVec2 {
1290 (*self).rem(rhs)
1291 }
1292}
1293
1294#[cfg(not(target_arch = "spirv"))]
1295impl AsRef<[usize; 2]> for USizeVec2 {
1296 #[inline]
1297 fn as_ref(&self) -> &[usize; 2] {
1298 unsafe { &*(self as *const USizeVec2 as *const [usize; 2]) }
1299 }
1300}
1301
1302#[cfg(not(target_arch = "spirv"))]
1303impl AsMut<[usize; 2]> for USizeVec2 {
1304 #[inline]
1305 fn as_mut(&mut self) -> &mut [usize; 2] {
1306 unsafe { &mut *(self as *mut USizeVec2 as *mut [usize; 2]) }
1307 }
1308}
1309
1310impl Sum for USizeVec2 {
1311 #[inline]
1312 fn sum<I>(iter: I) -> Self
1313 where
1314 I: Iterator<Item = Self>,
1315 {
1316 iter.fold(Self::ZERO, Self::add)
1317 }
1318}
1319
1320impl<'a> Sum<&'a Self> for USizeVec2 {
1321 #[inline]
1322 fn sum<I>(iter: I) -> Self
1323 where
1324 I: Iterator<Item = &'a Self>,
1325 {
1326 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1327 }
1328}
1329
1330impl Product for USizeVec2 {
1331 #[inline]
1332 fn product<I>(iter: I) -> Self
1333 where
1334 I: Iterator<Item = Self>,
1335 {
1336 iter.fold(Self::ONE, Self::mul)
1337 }
1338}
1339
1340impl<'a> Product<&'a Self> for USizeVec2 {
1341 #[inline]
1342 fn product<I>(iter: I) -> Self
1343 where
1344 I: Iterator<Item = &'a Self>,
1345 {
1346 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1347 }
1348}
1349
1350impl Not for USizeVec2 {
1351 type Output = Self;
1352 #[inline]
1353 fn not(self) -> Self::Output {
1354 Self {
1355 x: self.x.not(),
1356 y: self.y.not(),
1357 }
1358 }
1359}
1360
1361impl BitAnd for USizeVec2 {
1362 type Output = Self;
1363 #[inline]
1364 fn bitand(self, rhs: Self) -> Self::Output {
1365 Self {
1366 x: self.x.bitand(rhs.x),
1367 y: self.y.bitand(rhs.y),
1368 }
1369 }
1370}
1371
1372impl BitOr for USizeVec2 {
1373 type Output = Self;
1374 #[inline]
1375 fn bitor(self, rhs: Self) -> Self::Output {
1376 Self {
1377 x: self.x.bitor(rhs.x),
1378 y: self.y.bitor(rhs.y),
1379 }
1380 }
1381}
1382
1383impl BitXor for USizeVec2 {
1384 type Output = Self;
1385 #[inline]
1386 fn bitxor(self, rhs: Self) -> Self::Output {
1387 Self {
1388 x: self.x.bitxor(rhs.x),
1389 y: self.y.bitxor(rhs.y),
1390 }
1391 }
1392}
1393
1394impl BitAnd<usize> for USizeVec2 {
1395 type Output = Self;
1396 #[inline]
1397 fn bitand(self, rhs: usize) -> Self::Output {
1398 Self {
1399 x: self.x.bitand(rhs),
1400 y: self.y.bitand(rhs),
1401 }
1402 }
1403}
1404
1405impl BitOr<usize> for USizeVec2 {
1406 type Output = Self;
1407 #[inline]
1408 fn bitor(self, rhs: usize) -> Self::Output {
1409 Self {
1410 x: self.x.bitor(rhs),
1411 y: self.y.bitor(rhs),
1412 }
1413 }
1414}
1415
1416impl BitXor<usize> for USizeVec2 {
1417 type Output = Self;
1418 #[inline]
1419 fn bitxor(self, rhs: usize) -> Self::Output {
1420 Self {
1421 x: self.x.bitxor(rhs),
1422 y: self.y.bitxor(rhs),
1423 }
1424 }
1425}
1426
1427impl Shl<i8> for USizeVec2 {
1428 type Output = Self;
1429 #[inline]
1430 fn shl(self, rhs: i8) -> Self::Output {
1431 Self {
1432 x: self.x.shl(rhs),
1433 y: self.y.shl(rhs),
1434 }
1435 }
1436}
1437
1438impl Shr<i8> for USizeVec2 {
1439 type Output = Self;
1440 #[inline]
1441 fn shr(self, rhs: i8) -> Self::Output {
1442 Self {
1443 x: self.x.shr(rhs),
1444 y: self.y.shr(rhs),
1445 }
1446 }
1447}
1448
1449impl Shl<i16> for USizeVec2 {
1450 type Output = Self;
1451 #[inline]
1452 fn shl(self, rhs: i16) -> Self::Output {
1453 Self {
1454 x: self.x.shl(rhs),
1455 y: self.y.shl(rhs),
1456 }
1457 }
1458}
1459
1460impl Shr<i16> for USizeVec2 {
1461 type Output = Self;
1462 #[inline]
1463 fn shr(self, rhs: i16) -> Self::Output {
1464 Self {
1465 x: self.x.shr(rhs),
1466 y: self.y.shr(rhs),
1467 }
1468 }
1469}
1470
1471impl Shl<i32> for USizeVec2 {
1472 type Output = Self;
1473 #[inline]
1474 fn shl(self, rhs: i32) -> Self::Output {
1475 Self {
1476 x: self.x.shl(rhs),
1477 y: self.y.shl(rhs),
1478 }
1479 }
1480}
1481
1482impl Shr<i32> for USizeVec2 {
1483 type Output = Self;
1484 #[inline]
1485 fn shr(self, rhs: i32) -> Self::Output {
1486 Self {
1487 x: self.x.shr(rhs),
1488 y: self.y.shr(rhs),
1489 }
1490 }
1491}
1492
1493impl Shl<i64> for USizeVec2 {
1494 type Output = Self;
1495 #[inline]
1496 fn shl(self, rhs: i64) -> Self::Output {
1497 Self {
1498 x: self.x.shl(rhs),
1499 y: self.y.shl(rhs),
1500 }
1501 }
1502}
1503
1504impl Shr<i64> for USizeVec2 {
1505 type Output = Self;
1506 #[inline]
1507 fn shr(self, rhs: i64) -> Self::Output {
1508 Self {
1509 x: self.x.shr(rhs),
1510 y: self.y.shr(rhs),
1511 }
1512 }
1513}
1514
1515impl Shl<u8> for USizeVec2 {
1516 type Output = Self;
1517 #[inline]
1518 fn shl(self, rhs: u8) -> Self::Output {
1519 Self {
1520 x: self.x.shl(rhs),
1521 y: self.y.shl(rhs),
1522 }
1523 }
1524}
1525
1526impl Shr<u8> for USizeVec2 {
1527 type Output = Self;
1528 #[inline]
1529 fn shr(self, rhs: u8) -> Self::Output {
1530 Self {
1531 x: self.x.shr(rhs),
1532 y: self.y.shr(rhs),
1533 }
1534 }
1535}
1536
1537impl Shl<u16> for USizeVec2 {
1538 type Output = Self;
1539 #[inline]
1540 fn shl(self, rhs: u16) -> Self::Output {
1541 Self {
1542 x: self.x.shl(rhs),
1543 y: self.y.shl(rhs),
1544 }
1545 }
1546}
1547
1548impl Shr<u16> for USizeVec2 {
1549 type Output = Self;
1550 #[inline]
1551 fn shr(self, rhs: u16) -> Self::Output {
1552 Self {
1553 x: self.x.shr(rhs),
1554 y: self.y.shr(rhs),
1555 }
1556 }
1557}
1558
1559impl Shl<u32> for USizeVec2 {
1560 type Output = Self;
1561 #[inline]
1562 fn shl(self, rhs: u32) -> Self::Output {
1563 Self {
1564 x: self.x.shl(rhs),
1565 y: self.y.shl(rhs),
1566 }
1567 }
1568}
1569
1570impl Shr<u32> for USizeVec2 {
1571 type Output = Self;
1572 #[inline]
1573 fn shr(self, rhs: u32) -> Self::Output {
1574 Self {
1575 x: self.x.shr(rhs),
1576 y: self.y.shr(rhs),
1577 }
1578 }
1579}
1580
1581impl Shl<u64> for USizeVec2 {
1582 type Output = Self;
1583 #[inline]
1584 fn shl(self, rhs: u64) -> Self::Output {
1585 Self {
1586 x: self.x.shl(rhs),
1587 y: self.y.shl(rhs),
1588 }
1589 }
1590}
1591
1592impl Shr<u64> for USizeVec2 {
1593 type Output = Self;
1594 #[inline]
1595 fn shr(self, rhs: u64) -> Self::Output {
1596 Self {
1597 x: self.x.shr(rhs),
1598 y: self.y.shr(rhs),
1599 }
1600 }
1601}
1602
1603impl Shl<crate::IVec2> for USizeVec2 {
1604 type Output = Self;
1605 #[inline]
1606 fn shl(self, rhs: crate::IVec2) -> Self::Output {
1607 Self {
1608 x: self.x.shl(rhs.x),
1609 y: self.y.shl(rhs.y),
1610 }
1611 }
1612}
1613
1614impl Shr<crate::IVec2> for USizeVec2 {
1615 type Output = Self;
1616 #[inline]
1617 fn shr(self, rhs: crate::IVec2) -> Self::Output {
1618 Self {
1619 x: self.x.shr(rhs.x),
1620 y: self.y.shr(rhs.y),
1621 }
1622 }
1623}
1624
1625impl Shl<crate::UVec2> for USizeVec2 {
1626 type Output = Self;
1627 #[inline]
1628 fn shl(self, rhs: crate::UVec2) -> Self::Output {
1629 Self {
1630 x: self.x.shl(rhs.x),
1631 y: self.y.shl(rhs.y),
1632 }
1633 }
1634}
1635
1636impl Shr<crate::UVec2> for USizeVec2 {
1637 type Output = Self;
1638 #[inline]
1639 fn shr(self, rhs: crate::UVec2) -> Self::Output {
1640 Self {
1641 x: self.x.shr(rhs.x),
1642 y: self.y.shr(rhs.y),
1643 }
1644 }
1645}
1646
1647impl Index<usize> for USizeVec2 {
1648 type Output = usize;
1649 #[inline]
1650 fn index(&self, index: usize) -> &Self::Output {
1651 match index {
1652 0 => &self.x,
1653 1 => &self.y,
1654 _ => panic!("index out of bounds"),
1655 }
1656 }
1657}
1658
1659impl IndexMut<usize> for USizeVec2 {
1660 #[inline]
1661 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1662 match index {
1663 0 => &mut self.x,
1664 1 => &mut self.y,
1665 _ => panic!("index out of bounds"),
1666 }
1667 }
1668}
1669
1670impl fmt::Display for USizeVec2 {
1671 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1672 write!(f, "[{}, {}]", self.x, self.y)
1673 }
1674}
1675
1676impl fmt::Debug for USizeVec2 {
1677 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1678 fmt.debug_tuple(stringify!(USizeVec2))
1679 .field(&self.x)
1680 .field(&self.y)
1681 .finish()
1682 }
1683}
1684
1685impl From<[usize; 2]> for USizeVec2 {
1686 #[inline]
1687 fn from(a: [usize; 2]) -> Self {
1688 Self::new(a[0], a[1])
1689 }
1690}
1691
1692impl From<USizeVec2> for [usize; 2] {
1693 #[inline]
1694 fn from(v: USizeVec2) -> Self {
1695 [v.x, v.y]
1696 }
1697}
1698
1699impl From<(usize, usize)> for USizeVec2 {
1700 #[inline]
1701 fn from(t: (usize, usize)) -> Self {
1702 Self::new(t.0, t.1)
1703 }
1704}
1705
1706impl From<USizeVec2> for (usize, usize) {
1707 #[inline]
1708 fn from(v: USizeVec2) -> Self {
1709 (v.x, v.y)
1710 }
1711}
1712
1713impl From<U8Vec2> for USizeVec2 {
1714 #[inline]
1715 fn from(v: U8Vec2) -> Self {
1716 Self::new(usize::from(v.x), usize::from(v.y))
1717 }
1718}
1719
1720impl From<U16Vec2> for USizeVec2 {
1721 #[inline]
1722 fn from(v: U16Vec2) -> Self {
1723 Self::new(usize::from(v.x), usize::from(v.y))
1724 }
1725}
1726
1727impl TryFrom<I8Vec2> for USizeVec2 {
1728 type Error = core::num::TryFromIntError;
1729
1730 #[inline]
1731 fn try_from(v: I8Vec2) -> Result<Self, Self::Error> {
1732 Ok(Self::new(usize::try_from(v.x)?, usize::try_from(v.y)?))
1733 }
1734}
1735
1736impl TryFrom<I16Vec2> for USizeVec2 {
1737 type Error = core::num::TryFromIntError;
1738
1739 #[inline]
1740 fn try_from(v: I16Vec2) -> Result<Self, Self::Error> {
1741 Ok(Self::new(usize::try_from(v.x)?, usize::try_from(v.y)?))
1742 }
1743}
1744
1745impl TryFrom<IVec2> for USizeVec2 {
1746 type Error = core::num::TryFromIntError;
1747
1748 #[inline]
1749 fn try_from(v: IVec2) -> Result<Self, Self::Error> {
1750 Ok(Self::new(usize::try_from(v.x)?, usize::try_from(v.y)?))
1751 }
1752}
1753
1754impl TryFrom<I64Vec2> for USizeVec2 {
1755 type Error = core::num::TryFromIntError;
1756
1757 #[inline]
1758 fn try_from(v: I64Vec2) -> Result<Self, Self::Error> {
1759 Ok(Self::new(usize::try_from(v.x)?, usize::try_from(v.y)?))
1760 }
1761}
1762
1763impl TryFrom<UVec2> for USizeVec2 {
1764 type Error = core::num::TryFromIntError;
1765
1766 #[inline]
1767 fn try_from(v: UVec2) -> Result<Self, Self::Error> {
1768 Ok(Self::new(usize::try_from(v.x)?, usize::try_from(v.y)?))
1769 }
1770}
1771
1772impl TryFrom<U64Vec2> for USizeVec2 {
1773 type Error = core::num::TryFromIntError;
1774
1775 #[inline]
1776 fn try_from(v: U64Vec2) -> Result<Self, Self::Error> {
1777 Ok(Self::new(usize::try_from(v.x)?, usize::try_from(v.y)?))
1778 }
1779}
1780
1781impl From<BVec2> for USizeVec2 {
1782 #[inline]
1783 fn from(v: BVec2) -> Self {
1784 Self::new(usize::from(v.x), usize::from(v.y))
1785 }
1786}