1use crate::{BVec2, I16Vec2, I64Vec2, IVec2, U16Vec2, U64Vec3, UVec2};
4
5#[cfg(not(target_arch = "spirv"))]
6use core::fmt;
7use core::iter::{Product, Sum};
8use core::{f32, ops::*};
9
10#[inline(always)]
12#[must_use]
13pub const fn u64vec2(x: u64, y: u64) -> U64Vec2 {
14 U64Vec2::new(x, y)
15}
16
17#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
19#[derive(Clone, Copy, PartialEq, Eq)]
20#[cfg_attr(feature = "cuda", repr(align(16)))]
21#[cfg_attr(not(target_arch = "spirv"), repr(C))]
22#[cfg_attr(target_arch = "spirv", repr(simd))]
23pub struct U64Vec2 {
24 pub x: u64,
25 pub y: u64,
26}
27
28impl U64Vec2 {
29 pub const ZERO: Self = Self::splat(0);
31
32 pub const ONE: Self = Self::splat(1);
34
35 pub const MIN: Self = Self::splat(u64::MIN);
37
38 pub const MAX: Self = Self::splat(u64::MAX);
40
41 pub const X: Self = Self::new(1, 0);
43
44 pub const Y: Self = Self::new(0, 1);
46
47 pub const AXES: [Self; 2] = [Self::X, Self::Y];
49
50 #[inline(always)]
52 #[must_use]
53 pub const fn new(x: u64, y: u64) -> Self {
54 Self { x, y }
55 }
56
57 #[inline]
59 #[must_use]
60 pub const fn splat(v: u64) -> Self {
61 Self { x: v, y: v }
62 }
63
64 #[inline]
70 #[must_use]
71 pub fn select(mask: BVec2, if_true: Self, if_false: Self) -> Self {
72 Self {
73 x: if mask.test(0) { if_true.x } else { if_false.x },
74 y: if mask.test(1) { if_true.y } else { if_false.y },
75 }
76 }
77
78 #[inline]
80 #[must_use]
81 pub const fn from_array(a: [u64; 2]) -> Self {
82 Self::new(a[0], a[1])
83 }
84
85 #[inline]
87 #[must_use]
88 pub const fn to_array(&self) -> [u64; 2] {
89 [self.x, self.y]
90 }
91
92 #[inline]
98 #[must_use]
99 pub const fn from_slice(slice: &[u64]) -> Self {
100 Self::new(slice[0], slice[1])
101 }
102
103 #[inline]
109 pub fn write_to_slice(self, slice: &mut [u64]) {
110 slice[0] = self.x;
111 slice[1] = self.y;
112 }
113
114 #[inline]
116 #[must_use]
117 pub const fn extend(self, z: u64) -> U64Vec3 {
118 U64Vec3::new(self.x, self.y, z)
119 }
120
121 #[inline]
123 #[must_use]
124 pub fn dot(self, rhs: Self) -> u64 {
125 (self.x * rhs.x) + (self.y * rhs.y)
126 }
127
128 #[inline]
130 #[must_use]
131 pub fn dot_into_vec(self, rhs: Self) -> Self {
132 Self::splat(self.dot(rhs))
133 }
134
135 #[inline]
139 #[must_use]
140 pub fn min(self, rhs: Self) -> Self {
141 Self {
142 x: self.x.min(rhs.x),
143 y: self.y.min(rhs.y),
144 }
145 }
146
147 #[inline]
151 #[must_use]
152 pub fn max(self, rhs: Self) -> Self {
153 Self {
154 x: self.x.max(rhs.x),
155 y: self.y.max(rhs.y),
156 }
157 }
158
159 #[inline]
167 #[must_use]
168 pub fn clamp(self, min: Self, max: Self) -> Self {
169 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
170 self.max(min).min(max)
171 }
172
173 #[inline]
177 #[must_use]
178 pub fn min_element(self) -> u64 {
179 self.x.min(self.y)
180 }
181
182 #[inline]
186 #[must_use]
187 pub fn max_element(self) -> u64 {
188 self.x.max(self.y)
189 }
190
191 #[inline]
197 #[must_use]
198 pub fn cmpeq(self, rhs: Self) -> BVec2 {
199 BVec2::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y))
200 }
201
202 #[inline]
208 #[must_use]
209 pub fn cmpne(self, rhs: Self) -> BVec2 {
210 BVec2::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y))
211 }
212
213 #[inline]
219 #[must_use]
220 pub fn cmpge(self, rhs: Self) -> BVec2 {
221 BVec2::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y))
222 }
223
224 #[inline]
230 #[must_use]
231 pub fn cmpgt(self, rhs: Self) -> BVec2 {
232 BVec2::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y))
233 }
234
235 #[inline]
241 #[must_use]
242 pub fn cmple(self, rhs: Self) -> BVec2 {
243 BVec2::new(self.x.le(&rhs.x), self.y.le(&rhs.y))
244 }
245
246 #[inline]
252 #[must_use]
253 pub fn cmplt(self, rhs: Self) -> BVec2 {
254 BVec2::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y))
255 }
256
257 #[doc(alias = "magnitude2")]
259 #[inline]
260 #[must_use]
261 pub fn length_squared(self) -> u64 {
262 self.dot(self)
263 }
264
265 #[inline]
267 #[must_use]
268 pub fn as_vec2(&self) -> crate::Vec2 {
269 crate::Vec2::new(self.x as f32, self.y as f32)
270 }
271
272 #[inline]
274 #[must_use]
275 pub fn as_dvec2(&self) -> crate::DVec2 {
276 crate::DVec2::new(self.x as f64, self.y as f64)
277 }
278
279 #[inline]
281 #[must_use]
282 pub fn as_i16vec2(&self) -> crate::I16Vec2 {
283 crate::I16Vec2::new(self.x as i16, self.y as i16)
284 }
285
286 #[inline]
288 #[must_use]
289 pub fn as_u16vec2(&self) -> crate::U16Vec2 {
290 crate::U16Vec2::new(self.x as u16, self.y as u16)
291 }
292
293 #[inline]
295 #[must_use]
296 pub fn as_ivec2(&self) -> crate::IVec2 {
297 crate::IVec2::new(self.x as i32, self.y as i32)
298 }
299
300 #[inline]
302 #[must_use]
303 pub fn as_uvec2(&self) -> crate::UVec2 {
304 crate::UVec2::new(self.x as u32, self.y as u32)
305 }
306
307 #[inline]
309 #[must_use]
310 pub fn as_i64vec2(&self) -> crate::I64Vec2 {
311 crate::I64Vec2::new(self.x as i64, self.y as i64)
312 }
313
314 #[inline]
318 #[must_use]
319 pub const fn wrapping_add(self, rhs: Self) -> Self {
320 Self {
321 x: self.x.wrapping_add(rhs.x),
322 y: self.y.wrapping_add(rhs.y),
323 }
324 }
325
326 #[inline]
330 #[must_use]
331 pub const fn wrapping_sub(self, rhs: Self) -> Self {
332 Self {
333 x: self.x.wrapping_sub(rhs.x),
334 y: self.y.wrapping_sub(rhs.y),
335 }
336 }
337
338 #[inline]
342 #[must_use]
343 pub const fn wrapping_mul(self, rhs: Self) -> Self {
344 Self {
345 x: self.x.wrapping_mul(rhs.x),
346 y: self.y.wrapping_mul(rhs.y),
347 }
348 }
349
350 #[inline]
354 #[must_use]
355 pub const fn wrapping_div(self, rhs: Self) -> Self {
356 Self {
357 x: self.x.wrapping_div(rhs.x),
358 y: self.y.wrapping_div(rhs.y),
359 }
360 }
361
362 #[inline]
366 #[must_use]
367 pub const fn saturating_add(self, rhs: Self) -> Self {
368 Self {
369 x: self.x.saturating_add(rhs.x),
370 y: self.y.saturating_add(rhs.y),
371 }
372 }
373
374 #[inline]
378 #[must_use]
379 pub const fn saturating_sub(self, rhs: Self) -> Self {
380 Self {
381 x: self.x.saturating_sub(rhs.x),
382 y: self.y.saturating_sub(rhs.y),
383 }
384 }
385
386 #[inline]
390 #[must_use]
391 pub const fn saturating_mul(self, rhs: Self) -> Self {
392 Self {
393 x: self.x.saturating_mul(rhs.x),
394 y: self.y.saturating_mul(rhs.y),
395 }
396 }
397
398 #[inline]
402 #[must_use]
403 pub const fn saturating_div(self, rhs: Self) -> Self {
404 Self {
405 x: self.x.saturating_div(rhs.x),
406 y: self.y.saturating_div(rhs.y),
407 }
408 }
409}
410
411impl Default for U64Vec2 {
412 #[inline(always)]
413 fn default() -> Self {
414 Self::ZERO
415 }
416}
417
418impl Div<U64Vec2> for U64Vec2 {
419 type Output = Self;
420 #[inline]
421 fn div(self, rhs: Self) -> Self {
422 Self {
423 x: self.x.div(rhs.x),
424 y: self.y.div(rhs.y),
425 }
426 }
427}
428
429impl DivAssign<U64Vec2> for U64Vec2 {
430 #[inline]
431 fn div_assign(&mut self, rhs: Self) {
432 self.x.div_assign(rhs.x);
433 self.y.div_assign(rhs.y);
434 }
435}
436
437impl Div<u64> for U64Vec2 {
438 type Output = Self;
439 #[inline]
440 fn div(self, rhs: u64) -> Self {
441 Self {
442 x: self.x.div(rhs),
443 y: self.y.div(rhs),
444 }
445 }
446}
447
448impl DivAssign<u64> for U64Vec2 {
449 #[inline]
450 fn div_assign(&mut self, rhs: u64) {
451 self.x.div_assign(rhs);
452 self.y.div_assign(rhs);
453 }
454}
455
456impl Div<U64Vec2> for u64 {
457 type Output = U64Vec2;
458 #[inline]
459 fn div(self, rhs: U64Vec2) -> U64Vec2 {
460 U64Vec2 {
461 x: self.div(rhs.x),
462 y: self.div(rhs.y),
463 }
464 }
465}
466
467impl Mul<U64Vec2> for U64Vec2 {
468 type Output = Self;
469 #[inline]
470 fn mul(self, rhs: Self) -> Self {
471 Self {
472 x: self.x.mul(rhs.x),
473 y: self.y.mul(rhs.y),
474 }
475 }
476}
477
478impl MulAssign<U64Vec2> for U64Vec2 {
479 #[inline]
480 fn mul_assign(&mut self, rhs: Self) {
481 self.x.mul_assign(rhs.x);
482 self.y.mul_assign(rhs.y);
483 }
484}
485
486impl Mul<u64> for U64Vec2 {
487 type Output = Self;
488 #[inline]
489 fn mul(self, rhs: u64) -> Self {
490 Self {
491 x: self.x.mul(rhs),
492 y: self.y.mul(rhs),
493 }
494 }
495}
496
497impl MulAssign<u64> for U64Vec2 {
498 #[inline]
499 fn mul_assign(&mut self, rhs: u64) {
500 self.x.mul_assign(rhs);
501 self.y.mul_assign(rhs);
502 }
503}
504
505impl Mul<U64Vec2> for u64 {
506 type Output = U64Vec2;
507 #[inline]
508 fn mul(self, rhs: U64Vec2) -> U64Vec2 {
509 U64Vec2 {
510 x: self.mul(rhs.x),
511 y: self.mul(rhs.y),
512 }
513 }
514}
515
516impl Add<U64Vec2> for U64Vec2 {
517 type Output = Self;
518 #[inline]
519 fn add(self, rhs: Self) -> Self {
520 Self {
521 x: self.x.add(rhs.x),
522 y: self.y.add(rhs.y),
523 }
524 }
525}
526
527impl AddAssign<U64Vec2> for U64Vec2 {
528 #[inline]
529 fn add_assign(&mut self, rhs: Self) {
530 self.x.add_assign(rhs.x);
531 self.y.add_assign(rhs.y);
532 }
533}
534
535impl Add<u64> for U64Vec2 {
536 type Output = Self;
537 #[inline]
538 fn add(self, rhs: u64) -> Self {
539 Self {
540 x: self.x.add(rhs),
541 y: self.y.add(rhs),
542 }
543 }
544}
545
546impl AddAssign<u64> for U64Vec2 {
547 #[inline]
548 fn add_assign(&mut self, rhs: u64) {
549 self.x.add_assign(rhs);
550 self.y.add_assign(rhs);
551 }
552}
553
554impl Add<U64Vec2> for u64 {
555 type Output = U64Vec2;
556 #[inline]
557 fn add(self, rhs: U64Vec2) -> U64Vec2 {
558 U64Vec2 {
559 x: self.add(rhs.x),
560 y: self.add(rhs.y),
561 }
562 }
563}
564
565impl Sub<U64Vec2> for U64Vec2 {
566 type Output = Self;
567 #[inline]
568 fn sub(self, rhs: Self) -> Self {
569 Self {
570 x: self.x.sub(rhs.x),
571 y: self.y.sub(rhs.y),
572 }
573 }
574}
575
576impl SubAssign<U64Vec2> for U64Vec2 {
577 #[inline]
578 fn sub_assign(&mut self, rhs: U64Vec2) {
579 self.x.sub_assign(rhs.x);
580 self.y.sub_assign(rhs.y);
581 }
582}
583
584impl Sub<u64> for U64Vec2 {
585 type Output = Self;
586 #[inline]
587 fn sub(self, rhs: u64) -> Self {
588 Self {
589 x: self.x.sub(rhs),
590 y: self.y.sub(rhs),
591 }
592 }
593}
594
595impl SubAssign<u64> for U64Vec2 {
596 #[inline]
597 fn sub_assign(&mut self, rhs: u64) {
598 self.x.sub_assign(rhs);
599 self.y.sub_assign(rhs);
600 }
601}
602
603impl Sub<U64Vec2> for u64 {
604 type Output = U64Vec2;
605 #[inline]
606 fn sub(self, rhs: U64Vec2) -> U64Vec2 {
607 U64Vec2 {
608 x: self.sub(rhs.x),
609 y: self.sub(rhs.y),
610 }
611 }
612}
613
614impl Rem<U64Vec2> for U64Vec2 {
615 type Output = Self;
616 #[inline]
617 fn rem(self, rhs: Self) -> Self {
618 Self {
619 x: self.x.rem(rhs.x),
620 y: self.y.rem(rhs.y),
621 }
622 }
623}
624
625impl RemAssign<U64Vec2> for U64Vec2 {
626 #[inline]
627 fn rem_assign(&mut self, rhs: Self) {
628 self.x.rem_assign(rhs.x);
629 self.y.rem_assign(rhs.y);
630 }
631}
632
633impl Rem<u64> for U64Vec2 {
634 type Output = Self;
635 #[inline]
636 fn rem(self, rhs: u64) -> Self {
637 Self {
638 x: self.x.rem(rhs),
639 y: self.y.rem(rhs),
640 }
641 }
642}
643
644impl RemAssign<u64> for U64Vec2 {
645 #[inline]
646 fn rem_assign(&mut self, rhs: u64) {
647 self.x.rem_assign(rhs);
648 self.y.rem_assign(rhs);
649 }
650}
651
652impl Rem<U64Vec2> for u64 {
653 type Output = U64Vec2;
654 #[inline]
655 fn rem(self, rhs: U64Vec2) -> U64Vec2 {
656 U64Vec2 {
657 x: self.rem(rhs.x),
658 y: self.rem(rhs.y),
659 }
660 }
661}
662
663#[cfg(not(target_arch = "spirv"))]
664impl AsRef<[u64; 2]> for U64Vec2 {
665 #[inline]
666 fn as_ref(&self) -> &[u64; 2] {
667 unsafe { &*(self as *const U64Vec2 as *const [u64; 2]) }
668 }
669}
670
671#[cfg(not(target_arch = "spirv"))]
672impl AsMut<[u64; 2]> for U64Vec2 {
673 #[inline]
674 fn as_mut(&mut self) -> &mut [u64; 2] {
675 unsafe { &mut *(self as *mut U64Vec2 as *mut [u64; 2]) }
676 }
677}
678
679impl Sum for U64Vec2 {
680 #[inline]
681 fn sum<I>(iter: I) -> Self
682 where
683 I: Iterator<Item = Self>,
684 {
685 iter.fold(Self::ZERO, Self::add)
686 }
687}
688
689impl<'a> Sum<&'a Self> for U64Vec2 {
690 #[inline]
691 fn sum<I>(iter: I) -> Self
692 where
693 I: Iterator<Item = &'a Self>,
694 {
695 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
696 }
697}
698
699impl Product for U64Vec2 {
700 #[inline]
701 fn product<I>(iter: I) -> Self
702 where
703 I: Iterator<Item = Self>,
704 {
705 iter.fold(Self::ONE, Self::mul)
706 }
707}
708
709impl<'a> Product<&'a Self> for U64Vec2 {
710 #[inline]
711 fn product<I>(iter: I) -> Self
712 where
713 I: Iterator<Item = &'a Self>,
714 {
715 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
716 }
717}
718
719impl Not for U64Vec2 {
720 type Output = Self;
721 #[inline]
722 fn not(self) -> Self::Output {
723 Self {
724 x: self.x.not(),
725 y: self.y.not(),
726 }
727 }
728}
729
730impl BitAnd for U64Vec2 {
731 type Output = Self;
732 #[inline]
733 fn bitand(self, rhs: Self) -> Self::Output {
734 Self {
735 x: self.x.bitand(rhs.x),
736 y: self.y.bitand(rhs.y),
737 }
738 }
739}
740
741impl BitOr for U64Vec2 {
742 type Output = Self;
743 #[inline]
744 fn bitor(self, rhs: Self) -> Self::Output {
745 Self {
746 x: self.x.bitor(rhs.x),
747 y: self.y.bitor(rhs.y),
748 }
749 }
750}
751
752impl BitXor for U64Vec2 {
753 type Output = Self;
754 #[inline]
755 fn bitxor(self, rhs: Self) -> Self::Output {
756 Self {
757 x: self.x.bitxor(rhs.x),
758 y: self.y.bitxor(rhs.y),
759 }
760 }
761}
762
763impl BitAnd<u64> for U64Vec2 {
764 type Output = Self;
765 #[inline]
766 fn bitand(self, rhs: u64) -> Self::Output {
767 Self {
768 x: self.x.bitand(rhs),
769 y: self.y.bitand(rhs),
770 }
771 }
772}
773
774impl BitOr<u64> for U64Vec2 {
775 type Output = Self;
776 #[inline]
777 fn bitor(self, rhs: u64) -> Self::Output {
778 Self {
779 x: self.x.bitor(rhs),
780 y: self.y.bitor(rhs),
781 }
782 }
783}
784
785impl BitXor<u64> for U64Vec2 {
786 type Output = Self;
787 #[inline]
788 fn bitxor(self, rhs: u64) -> Self::Output {
789 Self {
790 x: self.x.bitxor(rhs),
791 y: self.y.bitxor(rhs),
792 }
793 }
794}
795
796impl Shl<i8> for U64Vec2 {
797 type Output = Self;
798 #[inline]
799 fn shl(self, rhs: i8) -> Self::Output {
800 Self {
801 x: self.x.shl(rhs),
802 y: self.y.shl(rhs),
803 }
804 }
805}
806
807impl Shr<i8> for U64Vec2 {
808 type Output = Self;
809 #[inline]
810 fn shr(self, rhs: i8) -> Self::Output {
811 Self {
812 x: self.x.shr(rhs),
813 y: self.y.shr(rhs),
814 }
815 }
816}
817
818impl Shl<i16> for U64Vec2 {
819 type Output = Self;
820 #[inline]
821 fn shl(self, rhs: i16) -> Self::Output {
822 Self {
823 x: self.x.shl(rhs),
824 y: self.y.shl(rhs),
825 }
826 }
827}
828
829impl Shr<i16> for U64Vec2 {
830 type Output = Self;
831 #[inline]
832 fn shr(self, rhs: i16) -> Self::Output {
833 Self {
834 x: self.x.shr(rhs),
835 y: self.y.shr(rhs),
836 }
837 }
838}
839
840impl Shl<i32> for U64Vec2 {
841 type Output = Self;
842 #[inline]
843 fn shl(self, rhs: i32) -> Self::Output {
844 Self {
845 x: self.x.shl(rhs),
846 y: self.y.shl(rhs),
847 }
848 }
849}
850
851impl Shr<i32> for U64Vec2 {
852 type Output = Self;
853 #[inline]
854 fn shr(self, rhs: i32) -> Self::Output {
855 Self {
856 x: self.x.shr(rhs),
857 y: self.y.shr(rhs),
858 }
859 }
860}
861
862impl Shl<i64> for U64Vec2 {
863 type Output = Self;
864 #[inline]
865 fn shl(self, rhs: i64) -> Self::Output {
866 Self {
867 x: self.x.shl(rhs),
868 y: self.y.shl(rhs),
869 }
870 }
871}
872
873impl Shr<i64> for U64Vec2 {
874 type Output = Self;
875 #[inline]
876 fn shr(self, rhs: i64) -> Self::Output {
877 Self {
878 x: self.x.shr(rhs),
879 y: self.y.shr(rhs),
880 }
881 }
882}
883
884impl Shl<u8> for U64Vec2 {
885 type Output = Self;
886 #[inline]
887 fn shl(self, rhs: u8) -> Self::Output {
888 Self {
889 x: self.x.shl(rhs),
890 y: self.y.shl(rhs),
891 }
892 }
893}
894
895impl Shr<u8> for U64Vec2 {
896 type Output = Self;
897 #[inline]
898 fn shr(self, rhs: u8) -> Self::Output {
899 Self {
900 x: self.x.shr(rhs),
901 y: self.y.shr(rhs),
902 }
903 }
904}
905
906impl Shl<u16> for U64Vec2 {
907 type Output = Self;
908 #[inline]
909 fn shl(self, rhs: u16) -> Self::Output {
910 Self {
911 x: self.x.shl(rhs),
912 y: self.y.shl(rhs),
913 }
914 }
915}
916
917impl Shr<u16> for U64Vec2 {
918 type Output = Self;
919 #[inline]
920 fn shr(self, rhs: u16) -> Self::Output {
921 Self {
922 x: self.x.shr(rhs),
923 y: self.y.shr(rhs),
924 }
925 }
926}
927
928impl Shl<u32> for U64Vec2 {
929 type Output = Self;
930 #[inline]
931 fn shl(self, rhs: u32) -> Self::Output {
932 Self {
933 x: self.x.shl(rhs),
934 y: self.y.shl(rhs),
935 }
936 }
937}
938
939impl Shr<u32> for U64Vec2 {
940 type Output = Self;
941 #[inline]
942 fn shr(self, rhs: u32) -> Self::Output {
943 Self {
944 x: self.x.shr(rhs),
945 y: self.y.shr(rhs),
946 }
947 }
948}
949
950impl Shl<u64> for U64Vec2 {
951 type Output = Self;
952 #[inline]
953 fn shl(self, rhs: u64) -> Self::Output {
954 Self {
955 x: self.x.shl(rhs),
956 y: self.y.shl(rhs),
957 }
958 }
959}
960
961impl Shr<u64> for U64Vec2 {
962 type Output = Self;
963 #[inline]
964 fn shr(self, rhs: u64) -> Self::Output {
965 Self {
966 x: self.x.shr(rhs),
967 y: self.y.shr(rhs),
968 }
969 }
970}
971
972impl Shl<crate::IVec2> for U64Vec2 {
973 type Output = Self;
974 #[inline]
975 fn shl(self, rhs: crate::IVec2) -> Self::Output {
976 Self {
977 x: self.x.shl(rhs.x),
978 y: self.y.shl(rhs.y),
979 }
980 }
981}
982
983impl Shr<crate::IVec2> for U64Vec2 {
984 type Output = Self;
985 #[inline]
986 fn shr(self, rhs: crate::IVec2) -> Self::Output {
987 Self {
988 x: self.x.shr(rhs.x),
989 y: self.y.shr(rhs.y),
990 }
991 }
992}
993
994impl Shl<crate::UVec2> for U64Vec2 {
995 type Output = Self;
996 #[inline]
997 fn shl(self, rhs: crate::UVec2) -> Self::Output {
998 Self {
999 x: self.x.shl(rhs.x),
1000 y: self.y.shl(rhs.y),
1001 }
1002 }
1003}
1004
1005impl Shr<crate::UVec2> for U64Vec2 {
1006 type Output = Self;
1007 #[inline]
1008 fn shr(self, rhs: crate::UVec2) -> Self::Output {
1009 Self {
1010 x: self.x.shr(rhs.x),
1011 y: self.y.shr(rhs.y),
1012 }
1013 }
1014}
1015
1016impl Index<usize> for U64Vec2 {
1017 type Output = u64;
1018 #[inline]
1019 fn index(&self, index: usize) -> &Self::Output {
1020 match index {
1021 0 => &self.x,
1022 1 => &self.y,
1023 _ => panic!("index out of bounds"),
1024 }
1025 }
1026}
1027
1028impl IndexMut<usize> for U64Vec2 {
1029 #[inline]
1030 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1031 match index {
1032 0 => &mut self.x,
1033 1 => &mut self.y,
1034 _ => panic!("index out of bounds"),
1035 }
1036 }
1037}
1038
1039#[cfg(not(target_arch = "spirv"))]
1040impl fmt::Display for U64Vec2 {
1041 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1042 write!(f, "[{}, {}]", self.x, self.y)
1043 }
1044}
1045
1046#[cfg(not(target_arch = "spirv"))]
1047impl fmt::Debug for U64Vec2 {
1048 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1049 fmt.debug_tuple(stringify!(U64Vec2))
1050 .field(&self.x)
1051 .field(&self.y)
1052 .finish()
1053 }
1054}
1055
1056impl From<[u64; 2]> for U64Vec2 {
1057 #[inline]
1058 fn from(a: [u64; 2]) -> Self {
1059 Self::new(a[0], a[1])
1060 }
1061}
1062
1063impl From<U64Vec2> for [u64; 2] {
1064 #[inline]
1065 fn from(v: U64Vec2) -> Self {
1066 [v.x, v.y]
1067 }
1068}
1069
1070impl From<(u64, u64)> for U64Vec2 {
1071 #[inline]
1072 fn from(t: (u64, u64)) -> Self {
1073 Self::new(t.0, t.1)
1074 }
1075}
1076
1077impl From<U64Vec2> for (u64, u64) {
1078 #[inline]
1079 fn from(v: U64Vec2) -> Self {
1080 (v.x, v.y)
1081 }
1082}
1083
1084impl From<U16Vec2> for U64Vec2 {
1085 #[inline]
1086 fn from(v: U16Vec2) -> Self {
1087 Self::new(u64::from(v.x), u64::from(v.y))
1088 }
1089}
1090
1091impl From<UVec2> for U64Vec2 {
1092 #[inline]
1093 fn from(v: UVec2) -> Self {
1094 Self::new(u64::from(v.x), u64::from(v.y))
1095 }
1096}
1097
1098impl TryFrom<I16Vec2> for U64Vec2 {
1099 type Error = core::num::TryFromIntError;
1100
1101 #[inline]
1102 fn try_from(v: I16Vec2) -> Result<Self, Self::Error> {
1103 Ok(Self::new(u64::try_from(v.x)?, u64::try_from(v.y)?))
1104 }
1105}
1106
1107impl TryFrom<IVec2> for U64Vec2 {
1108 type Error = core::num::TryFromIntError;
1109
1110 #[inline]
1111 fn try_from(v: IVec2) -> Result<Self, Self::Error> {
1112 Ok(Self::new(u64::try_from(v.x)?, u64::try_from(v.y)?))
1113 }
1114}
1115
1116impl TryFrom<I64Vec2> for U64Vec2 {
1117 type Error = core::num::TryFromIntError;
1118
1119 #[inline]
1120 fn try_from(v: I64Vec2) -> Result<Self, Self::Error> {
1121 Ok(Self::new(u64::try_from(v.x)?, u64::try_from(v.y)?))
1122 }
1123}