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