1#[cfg(not(feature = "scalar-math"))]
4use crate::BVec4A;
5use crate::{
6 BVec4, I16Vec4, I64Vec4, I8Vec4, IVec4, U16Vec4, U64Vec4, U8Vec2, U8Vec3, USizeVec4, UVec4,
7};
8
9use core::fmt;
10use core::iter::{Product, Sum};
11use core::{f32, ops::*};
12
13#[inline(always)]
15#[must_use]
16pub const fn u8vec4(x: u8, y: u8, z: u8, w: u8) -> U8Vec4 {
17 U8Vec4::new(x, y, z, w)
18}
19
20#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
22#[derive(Clone, Copy, PartialEq, Eq)]
23#[cfg_attr(feature = "cuda", repr(align(4)))]
24#[cfg_attr(not(target_arch = "spirv"), repr(C))]
25#[cfg_attr(target_arch = "spirv", repr(simd))]
26pub struct U8Vec4 {
27 pub x: u8,
28 pub y: u8,
29 pub z: u8,
30 pub w: u8,
31}
32
33impl U8Vec4 {
34 pub const ZERO: Self = Self::splat(0);
36
37 pub const ONE: Self = Self::splat(1);
39
40 pub const MIN: Self = Self::splat(u8::MIN);
42
43 pub const MAX: Self = Self::splat(u8::MAX);
45
46 pub const X: Self = Self::new(1, 0, 0, 0);
48
49 pub const Y: Self = Self::new(0, 1, 0, 0);
51
52 pub const Z: Self = Self::new(0, 0, 1, 0);
54
55 pub const W: Self = Self::new(0, 0, 0, 1);
57
58 pub const AXES: [Self; 4] = [Self::X, Self::Y, Self::Z, Self::W];
60
61 #[inline(always)]
63 #[must_use]
64 pub const fn new(x: u8, y: u8, z: u8, w: u8) -> Self {
65 Self { x, y, z, w }
66 }
67
68 #[inline]
70 #[must_use]
71 pub const fn splat(v: u8) -> Self {
72 Self {
73 x: v,
74
75 y: v,
76
77 z: v,
78
79 w: v,
80 }
81 }
82
83 #[inline]
85 #[must_use]
86 pub fn map<F>(self, f: F) -> Self
87 where
88 F: Fn(u8) -> u8,
89 {
90 Self::new(f(self.x), f(self.y), f(self.z), f(self.w))
91 }
92
93 #[inline]
99 #[must_use]
100 pub fn select(mask: BVec4, if_true: Self, if_false: Self) -> Self {
101 Self {
102 x: if mask.test(0) { if_true.x } else { if_false.x },
103 y: if mask.test(1) { if_true.y } else { if_false.y },
104 z: if mask.test(2) { if_true.z } else { if_false.z },
105 w: if mask.test(3) { if_true.w } else { if_false.w },
106 }
107 }
108
109 #[inline]
111 #[must_use]
112 pub const fn from_array(a: [u8; 4]) -> Self {
113 Self::new(a[0], a[1], a[2], a[3])
114 }
115
116 #[inline]
118 #[must_use]
119 pub const fn to_array(&self) -> [u8; 4] {
120 [self.x, self.y, self.z, self.w]
121 }
122
123 #[inline]
129 #[must_use]
130 pub const fn from_slice(slice: &[u8]) -> Self {
131 assert!(slice.len() >= 4);
132 Self::new(slice[0], slice[1], slice[2], slice[3])
133 }
134
135 #[inline]
141 pub fn write_to_slice(self, slice: &mut [u8]) {
142 slice[..4].copy_from_slice(&self.to_array());
143 }
144
145 #[inline]
149 #[must_use]
150 pub fn truncate(self) -> U8Vec3 {
151 use crate::swizzles::Vec4Swizzles;
152 self.xyz()
153 }
154
155 #[inline]
157 #[must_use]
158 pub fn with_x(mut self, x: u8) -> Self {
159 self.x = x;
160 self
161 }
162
163 #[inline]
165 #[must_use]
166 pub fn with_y(mut self, y: u8) -> Self {
167 self.y = y;
168 self
169 }
170
171 #[inline]
173 #[must_use]
174 pub fn with_z(mut self, z: u8) -> Self {
175 self.z = z;
176 self
177 }
178
179 #[inline]
181 #[must_use]
182 pub fn with_w(mut self, w: u8) -> Self {
183 self.w = w;
184 self
185 }
186
187 #[inline]
189 #[must_use]
190 pub fn dot(self, rhs: Self) -> u8 {
191 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z) + (self.w * rhs.w)
192 }
193
194 #[inline]
196 #[must_use]
197 pub fn dot_into_vec(self, rhs: Self) -> Self {
198 Self::splat(self.dot(rhs))
199 }
200
201 #[inline]
205 #[must_use]
206 pub fn min(self, rhs: Self) -> Self {
207 Self {
208 x: self.x.min(rhs.x),
209 y: self.y.min(rhs.y),
210 z: self.z.min(rhs.z),
211 w: self.w.min(rhs.w),
212 }
213 }
214
215 #[inline]
219 #[must_use]
220 pub fn max(self, rhs: Self) -> Self {
221 Self {
222 x: self.x.max(rhs.x),
223 y: self.y.max(rhs.y),
224 z: self.z.max(rhs.z),
225 w: self.w.max(rhs.w),
226 }
227 }
228
229 #[inline]
237 #[must_use]
238 pub fn clamp(self, min: Self, max: Self) -> Self {
239 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
240 self.max(min).min(max)
241 }
242
243 #[inline]
247 #[must_use]
248 pub fn min_element(self) -> u8 {
249 self.x.min(self.y.min(self.z.min(self.w)))
250 }
251
252 #[inline]
256 #[must_use]
257 pub fn max_element(self) -> u8 {
258 self.x.max(self.y.max(self.z.max(self.w)))
259 }
260
261 #[doc(alias = "argmin")]
263 #[inline]
264 #[must_use]
265 pub fn min_position(self) -> usize {
266 let mut min = self.x;
267 let mut index = 0;
268 if self.y < min {
269 min = self.y;
270 index = 1;
271 }
272 if self.z < min {
273 min = self.z;
274 index = 2;
275 }
276 if self.w < min {
277 index = 3;
278 }
279 index
280 }
281
282 #[doc(alias = "argmax")]
284 #[inline]
285 #[must_use]
286 pub fn max_position(self) -> usize {
287 let mut max = self.x;
288 let mut index = 0;
289 if self.y > max {
290 max = self.y;
291 index = 1;
292 }
293 if self.z > max {
294 max = self.z;
295 index = 2;
296 }
297 if self.w > max {
298 index = 3;
299 }
300 index
301 }
302
303 #[inline]
307 #[must_use]
308 pub fn element_sum(self) -> u8 {
309 self.x + self.y + self.z + self.w
310 }
311
312 #[inline]
316 #[must_use]
317 pub fn element_product(self) -> u8 {
318 self.x * self.y * self.z * self.w
319 }
320
321 #[inline]
327 #[must_use]
328 pub fn cmpeq(self, rhs: Self) -> BVec4 {
329 BVec4::new(
330 self.x.eq(&rhs.x),
331 self.y.eq(&rhs.y),
332 self.z.eq(&rhs.z),
333 self.w.eq(&rhs.w),
334 )
335 }
336
337 #[inline]
343 #[must_use]
344 pub fn cmpne(self, rhs: Self) -> BVec4 {
345 BVec4::new(
346 self.x.ne(&rhs.x),
347 self.y.ne(&rhs.y),
348 self.z.ne(&rhs.z),
349 self.w.ne(&rhs.w),
350 )
351 }
352
353 #[inline]
359 #[must_use]
360 pub fn cmpge(self, rhs: Self) -> BVec4 {
361 BVec4::new(
362 self.x.ge(&rhs.x),
363 self.y.ge(&rhs.y),
364 self.z.ge(&rhs.z),
365 self.w.ge(&rhs.w),
366 )
367 }
368
369 #[inline]
375 #[must_use]
376 pub fn cmpgt(self, rhs: Self) -> BVec4 {
377 BVec4::new(
378 self.x.gt(&rhs.x),
379 self.y.gt(&rhs.y),
380 self.z.gt(&rhs.z),
381 self.w.gt(&rhs.w),
382 )
383 }
384
385 #[inline]
391 #[must_use]
392 pub fn cmple(self, rhs: Self) -> BVec4 {
393 BVec4::new(
394 self.x.le(&rhs.x),
395 self.y.le(&rhs.y),
396 self.z.le(&rhs.z),
397 self.w.le(&rhs.w),
398 )
399 }
400
401 #[inline]
407 #[must_use]
408 pub fn cmplt(self, rhs: Self) -> BVec4 {
409 BVec4::new(
410 self.x.lt(&rhs.x),
411 self.y.lt(&rhs.y),
412 self.z.lt(&rhs.z),
413 self.w.lt(&rhs.w),
414 )
415 }
416
417 #[doc(alias = "magnitude2")]
419 #[inline]
420 #[must_use]
421 pub fn length_squared(self) -> u8 {
422 self.dot(self)
423 }
424
425 #[inline]
434 #[must_use]
435 pub fn manhattan_distance(self, other: Self) -> u8 {
436 self.x.abs_diff(other.x)
437 + self.y.abs_diff(other.y)
438 + self.z.abs_diff(other.z)
439 + self.w.abs_diff(other.w)
440 }
441
442 #[inline]
448 #[must_use]
449 pub fn checked_manhattan_distance(self, other: Self) -> Option<u8> {
450 let d = self.x.abs_diff(other.x);
451 let d = d.checked_add(self.y.abs_diff(other.y))?;
452 let d = d.checked_add(self.z.abs_diff(other.z))?;
453 d.checked_add(self.w.abs_diff(other.w))
454 }
455
456 #[inline]
460 #[must_use]
461 pub fn chebyshev_distance(self, other: Self) -> u8 {
462 [
464 self.x.abs_diff(other.x),
465 self.y.abs_diff(other.y),
466 self.z.abs_diff(other.z),
467 self.w.abs_diff(other.w),
468 ]
469 .into_iter()
470 .max()
471 .unwrap()
472 }
473
474 #[inline]
476 #[must_use]
477 pub fn as_vec4(&self) -> crate::Vec4 {
478 crate::Vec4::new(self.x as f32, self.y as f32, self.z as f32, self.w as f32)
479 }
480
481 #[inline]
483 #[must_use]
484 pub fn as_dvec4(&self) -> crate::DVec4 {
485 crate::DVec4::new(self.x as f64, self.y as f64, self.z as f64, self.w as f64)
486 }
487
488 #[inline]
490 #[must_use]
491 pub fn as_i8vec4(&self) -> crate::I8Vec4 {
492 crate::I8Vec4::new(self.x as i8, self.y as i8, self.z as i8, self.w as i8)
493 }
494
495 #[inline]
497 #[must_use]
498 pub fn as_i16vec4(&self) -> crate::I16Vec4 {
499 crate::I16Vec4::new(self.x as i16, self.y as i16, self.z as i16, self.w as i16)
500 }
501
502 #[inline]
504 #[must_use]
505 pub fn as_u16vec4(&self) -> crate::U16Vec4 {
506 crate::U16Vec4::new(self.x as u16, self.y as u16, self.z as u16, self.w as u16)
507 }
508
509 #[inline]
511 #[must_use]
512 pub fn as_ivec4(&self) -> crate::IVec4 {
513 crate::IVec4::new(self.x as i32, self.y as i32, self.z as i32, self.w as i32)
514 }
515
516 #[inline]
518 #[must_use]
519 pub fn as_uvec4(&self) -> crate::UVec4 {
520 crate::UVec4::new(self.x as u32, self.y as u32, self.z as u32, self.w as u32)
521 }
522
523 #[inline]
525 #[must_use]
526 pub fn as_i64vec4(&self) -> crate::I64Vec4 {
527 crate::I64Vec4::new(self.x as i64, self.y as i64, self.z as i64, self.w as i64)
528 }
529
530 #[inline]
532 #[must_use]
533 pub fn as_u64vec4(&self) -> crate::U64Vec4 {
534 crate::U64Vec4::new(self.x as u64, self.y as u64, self.z as u64, self.w as u64)
535 }
536
537 #[inline]
539 #[must_use]
540 pub fn as_usizevec4(&self) -> crate::USizeVec4 {
541 crate::USizeVec4::new(
542 self.x as usize,
543 self.y as usize,
544 self.z as usize,
545 self.w as usize,
546 )
547 }
548
549 #[inline]
553 #[must_use]
554 pub const fn checked_add(self, rhs: Self) -> Option<Self> {
555 let x = match self.x.checked_add(rhs.x) {
556 Some(v) => v,
557 None => return None,
558 };
559 let y = match self.y.checked_add(rhs.y) {
560 Some(v) => v,
561 None => return None,
562 };
563 let z = match self.z.checked_add(rhs.z) {
564 Some(v) => v,
565 None => return None,
566 };
567 let w = match self.w.checked_add(rhs.w) {
568 Some(v) => v,
569 None => return None,
570 };
571
572 Some(Self { x, y, z, w })
573 }
574
575 #[inline]
579 #[must_use]
580 pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
581 let x = match self.x.checked_sub(rhs.x) {
582 Some(v) => v,
583 None => return None,
584 };
585 let y = match self.y.checked_sub(rhs.y) {
586 Some(v) => v,
587 None => return None,
588 };
589 let z = match self.z.checked_sub(rhs.z) {
590 Some(v) => v,
591 None => return None,
592 };
593 let w = match self.w.checked_sub(rhs.w) {
594 Some(v) => v,
595 None => return None,
596 };
597
598 Some(Self { x, y, z, w })
599 }
600
601 #[inline]
605 #[must_use]
606 pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
607 let x = match self.x.checked_mul(rhs.x) {
608 Some(v) => v,
609 None => return None,
610 };
611 let y = match self.y.checked_mul(rhs.y) {
612 Some(v) => v,
613 None => return None,
614 };
615 let z = match self.z.checked_mul(rhs.z) {
616 Some(v) => v,
617 None => return None,
618 };
619 let w = match self.w.checked_mul(rhs.w) {
620 Some(v) => v,
621 None => return None,
622 };
623
624 Some(Self { x, y, z, w })
625 }
626
627 #[inline]
631 #[must_use]
632 pub const fn checked_div(self, rhs: Self) -> Option<Self> {
633 let x = match self.x.checked_div(rhs.x) {
634 Some(v) => v,
635 None => return None,
636 };
637 let y = match self.y.checked_div(rhs.y) {
638 Some(v) => v,
639 None => return None,
640 };
641 let z = match self.z.checked_div(rhs.z) {
642 Some(v) => v,
643 None => return None,
644 };
645 let w = match self.w.checked_div(rhs.w) {
646 Some(v) => v,
647 None => return None,
648 };
649
650 Some(Self { x, y, z, w })
651 }
652
653 #[inline]
657 #[must_use]
658 pub const fn wrapping_add(self, rhs: Self) -> Self {
659 Self {
660 x: self.x.wrapping_add(rhs.x),
661 y: self.y.wrapping_add(rhs.y),
662 z: self.z.wrapping_add(rhs.z),
663 w: self.w.wrapping_add(rhs.w),
664 }
665 }
666
667 #[inline]
671 #[must_use]
672 pub const fn wrapping_sub(self, rhs: Self) -> Self {
673 Self {
674 x: self.x.wrapping_sub(rhs.x),
675 y: self.y.wrapping_sub(rhs.y),
676 z: self.z.wrapping_sub(rhs.z),
677 w: self.w.wrapping_sub(rhs.w),
678 }
679 }
680
681 #[inline]
685 #[must_use]
686 pub const fn wrapping_mul(self, rhs: Self) -> Self {
687 Self {
688 x: self.x.wrapping_mul(rhs.x),
689 y: self.y.wrapping_mul(rhs.y),
690 z: self.z.wrapping_mul(rhs.z),
691 w: self.w.wrapping_mul(rhs.w),
692 }
693 }
694
695 #[inline]
699 #[must_use]
700 pub const fn wrapping_div(self, rhs: Self) -> Self {
701 Self {
702 x: self.x.wrapping_div(rhs.x),
703 y: self.y.wrapping_div(rhs.y),
704 z: self.z.wrapping_div(rhs.z),
705 w: self.w.wrapping_div(rhs.w),
706 }
707 }
708
709 #[inline]
713 #[must_use]
714 pub const fn saturating_add(self, rhs: Self) -> Self {
715 Self {
716 x: self.x.saturating_add(rhs.x),
717 y: self.y.saturating_add(rhs.y),
718 z: self.z.saturating_add(rhs.z),
719 w: self.w.saturating_add(rhs.w),
720 }
721 }
722
723 #[inline]
727 #[must_use]
728 pub const fn saturating_sub(self, rhs: Self) -> Self {
729 Self {
730 x: self.x.saturating_sub(rhs.x),
731 y: self.y.saturating_sub(rhs.y),
732 z: self.z.saturating_sub(rhs.z),
733 w: self.w.saturating_sub(rhs.w),
734 }
735 }
736
737 #[inline]
741 #[must_use]
742 pub const fn saturating_mul(self, rhs: Self) -> Self {
743 Self {
744 x: self.x.saturating_mul(rhs.x),
745 y: self.y.saturating_mul(rhs.y),
746 z: self.z.saturating_mul(rhs.z),
747 w: self.w.saturating_mul(rhs.w),
748 }
749 }
750
751 #[inline]
755 #[must_use]
756 pub const fn saturating_div(self, rhs: Self) -> Self {
757 Self {
758 x: self.x.saturating_div(rhs.x),
759 y: self.y.saturating_div(rhs.y),
760 z: self.z.saturating_div(rhs.z),
761 w: self.w.saturating_div(rhs.w),
762 }
763 }
764
765 #[inline]
769 #[must_use]
770 pub const fn checked_add_signed(self, rhs: I8Vec4) -> Option<Self> {
771 let x = match self.x.checked_add_signed(rhs.x) {
772 Some(v) => v,
773 None => return None,
774 };
775 let y = match self.y.checked_add_signed(rhs.y) {
776 Some(v) => v,
777 None => return None,
778 };
779 let z = match self.z.checked_add_signed(rhs.z) {
780 Some(v) => v,
781 None => return None,
782 };
783 let w = match self.w.checked_add_signed(rhs.w) {
784 Some(v) => v,
785 None => return None,
786 };
787
788 Some(Self { x, y, z, w })
789 }
790
791 #[inline]
795 #[must_use]
796 pub const fn wrapping_add_signed(self, rhs: I8Vec4) -> Self {
797 Self {
798 x: self.x.wrapping_add_signed(rhs.x),
799 y: self.y.wrapping_add_signed(rhs.y),
800 z: self.z.wrapping_add_signed(rhs.z),
801 w: self.w.wrapping_add_signed(rhs.w),
802 }
803 }
804
805 #[inline]
809 #[must_use]
810 pub const fn saturating_add_signed(self, rhs: I8Vec4) -> Self {
811 Self {
812 x: self.x.saturating_add_signed(rhs.x),
813 y: self.y.saturating_add_signed(rhs.y),
814 z: self.z.saturating_add_signed(rhs.z),
815 w: self.w.saturating_add_signed(rhs.w),
816 }
817 }
818}
819
820impl Default for U8Vec4 {
821 #[inline(always)]
822 fn default() -> Self {
823 Self::ZERO
824 }
825}
826
827impl Div<U8Vec4> for U8Vec4 {
828 type Output = Self;
829 #[inline]
830 fn div(self, rhs: Self) -> Self {
831 Self {
832 x: self.x.div(rhs.x),
833 y: self.y.div(rhs.y),
834 z: self.z.div(rhs.z),
835 w: self.w.div(rhs.w),
836 }
837 }
838}
839
840impl Div<&U8Vec4> for U8Vec4 {
841 type Output = U8Vec4;
842 #[inline]
843 fn div(self, rhs: &U8Vec4) -> U8Vec4 {
844 self.div(*rhs)
845 }
846}
847
848impl Div<&U8Vec4> for &U8Vec4 {
849 type Output = U8Vec4;
850 #[inline]
851 fn div(self, rhs: &U8Vec4) -> U8Vec4 {
852 (*self).div(*rhs)
853 }
854}
855
856impl Div<U8Vec4> for &U8Vec4 {
857 type Output = U8Vec4;
858 #[inline]
859 fn div(self, rhs: U8Vec4) -> U8Vec4 {
860 (*self).div(rhs)
861 }
862}
863
864impl DivAssign<U8Vec4> for U8Vec4 {
865 #[inline]
866 fn div_assign(&mut self, rhs: Self) {
867 self.x.div_assign(rhs.x);
868 self.y.div_assign(rhs.y);
869 self.z.div_assign(rhs.z);
870 self.w.div_assign(rhs.w);
871 }
872}
873
874impl DivAssign<&U8Vec4> for U8Vec4 {
875 #[inline]
876 fn div_assign(&mut self, rhs: &U8Vec4) {
877 self.div_assign(*rhs)
878 }
879}
880
881impl Div<u8> for U8Vec4 {
882 type Output = Self;
883 #[inline]
884 fn div(self, rhs: u8) -> Self {
885 Self {
886 x: self.x.div(rhs),
887 y: self.y.div(rhs),
888 z: self.z.div(rhs),
889 w: self.w.div(rhs),
890 }
891 }
892}
893
894impl Div<&u8> for U8Vec4 {
895 type Output = U8Vec4;
896 #[inline]
897 fn div(self, rhs: &u8) -> U8Vec4 {
898 self.div(*rhs)
899 }
900}
901
902impl Div<&u8> for &U8Vec4 {
903 type Output = U8Vec4;
904 #[inline]
905 fn div(self, rhs: &u8) -> U8Vec4 {
906 (*self).div(*rhs)
907 }
908}
909
910impl Div<u8> for &U8Vec4 {
911 type Output = U8Vec4;
912 #[inline]
913 fn div(self, rhs: u8) -> U8Vec4 {
914 (*self).div(rhs)
915 }
916}
917
918impl DivAssign<u8> for U8Vec4 {
919 #[inline]
920 fn div_assign(&mut self, rhs: u8) {
921 self.x.div_assign(rhs);
922 self.y.div_assign(rhs);
923 self.z.div_assign(rhs);
924 self.w.div_assign(rhs);
925 }
926}
927
928impl DivAssign<&u8> for U8Vec4 {
929 #[inline]
930 fn div_assign(&mut self, rhs: &u8) {
931 self.div_assign(*rhs)
932 }
933}
934
935impl Div<U8Vec4> for u8 {
936 type Output = U8Vec4;
937 #[inline]
938 fn div(self, rhs: U8Vec4) -> U8Vec4 {
939 U8Vec4 {
940 x: self.div(rhs.x),
941 y: self.div(rhs.y),
942 z: self.div(rhs.z),
943 w: self.div(rhs.w),
944 }
945 }
946}
947
948impl Div<&U8Vec4> for u8 {
949 type Output = U8Vec4;
950 #[inline]
951 fn div(self, rhs: &U8Vec4) -> U8Vec4 {
952 self.div(*rhs)
953 }
954}
955
956impl Div<&U8Vec4> for &u8 {
957 type Output = U8Vec4;
958 #[inline]
959 fn div(self, rhs: &U8Vec4) -> U8Vec4 {
960 (*self).div(*rhs)
961 }
962}
963
964impl Div<U8Vec4> for &u8 {
965 type Output = U8Vec4;
966 #[inline]
967 fn div(self, rhs: U8Vec4) -> U8Vec4 {
968 (*self).div(rhs)
969 }
970}
971
972impl Mul<U8Vec4> for U8Vec4 {
973 type Output = Self;
974 #[inline]
975 fn mul(self, rhs: Self) -> Self {
976 Self {
977 x: self.x.mul(rhs.x),
978 y: self.y.mul(rhs.y),
979 z: self.z.mul(rhs.z),
980 w: self.w.mul(rhs.w),
981 }
982 }
983}
984
985impl Mul<&U8Vec4> for U8Vec4 {
986 type Output = U8Vec4;
987 #[inline]
988 fn mul(self, rhs: &U8Vec4) -> U8Vec4 {
989 self.mul(*rhs)
990 }
991}
992
993impl Mul<&U8Vec4> for &U8Vec4 {
994 type Output = U8Vec4;
995 #[inline]
996 fn mul(self, rhs: &U8Vec4) -> U8Vec4 {
997 (*self).mul(*rhs)
998 }
999}
1000
1001impl Mul<U8Vec4> for &U8Vec4 {
1002 type Output = U8Vec4;
1003 #[inline]
1004 fn mul(self, rhs: U8Vec4) -> U8Vec4 {
1005 (*self).mul(rhs)
1006 }
1007}
1008
1009impl MulAssign<U8Vec4> for U8Vec4 {
1010 #[inline]
1011 fn mul_assign(&mut self, rhs: Self) {
1012 self.x.mul_assign(rhs.x);
1013 self.y.mul_assign(rhs.y);
1014 self.z.mul_assign(rhs.z);
1015 self.w.mul_assign(rhs.w);
1016 }
1017}
1018
1019impl MulAssign<&U8Vec4> for U8Vec4 {
1020 #[inline]
1021 fn mul_assign(&mut self, rhs: &U8Vec4) {
1022 self.mul_assign(*rhs)
1023 }
1024}
1025
1026impl Mul<u8> for U8Vec4 {
1027 type Output = Self;
1028 #[inline]
1029 fn mul(self, rhs: u8) -> Self {
1030 Self {
1031 x: self.x.mul(rhs),
1032 y: self.y.mul(rhs),
1033 z: self.z.mul(rhs),
1034 w: self.w.mul(rhs),
1035 }
1036 }
1037}
1038
1039impl Mul<&u8> for U8Vec4 {
1040 type Output = U8Vec4;
1041 #[inline]
1042 fn mul(self, rhs: &u8) -> U8Vec4 {
1043 self.mul(*rhs)
1044 }
1045}
1046
1047impl Mul<&u8> for &U8Vec4 {
1048 type Output = U8Vec4;
1049 #[inline]
1050 fn mul(self, rhs: &u8) -> U8Vec4 {
1051 (*self).mul(*rhs)
1052 }
1053}
1054
1055impl Mul<u8> for &U8Vec4 {
1056 type Output = U8Vec4;
1057 #[inline]
1058 fn mul(self, rhs: u8) -> U8Vec4 {
1059 (*self).mul(rhs)
1060 }
1061}
1062
1063impl MulAssign<u8> for U8Vec4 {
1064 #[inline]
1065 fn mul_assign(&mut self, rhs: u8) {
1066 self.x.mul_assign(rhs);
1067 self.y.mul_assign(rhs);
1068 self.z.mul_assign(rhs);
1069 self.w.mul_assign(rhs);
1070 }
1071}
1072
1073impl MulAssign<&u8> for U8Vec4 {
1074 #[inline]
1075 fn mul_assign(&mut self, rhs: &u8) {
1076 self.mul_assign(*rhs)
1077 }
1078}
1079
1080impl Mul<U8Vec4> for u8 {
1081 type Output = U8Vec4;
1082 #[inline]
1083 fn mul(self, rhs: U8Vec4) -> U8Vec4 {
1084 U8Vec4 {
1085 x: self.mul(rhs.x),
1086 y: self.mul(rhs.y),
1087 z: self.mul(rhs.z),
1088 w: self.mul(rhs.w),
1089 }
1090 }
1091}
1092
1093impl Mul<&U8Vec4> for u8 {
1094 type Output = U8Vec4;
1095 #[inline]
1096 fn mul(self, rhs: &U8Vec4) -> U8Vec4 {
1097 self.mul(*rhs)
1098 }
1099}
1100
1101impl Mul<&U8Vec4> for &u8 {
1102 type Output = U8Vec4;
1103 #[inline]
1104 fn mul(self, rhs: &U8Vec4) -> U8Vec4 {
1105 (*self).mul(*rhs)
1106 }
1107}
1108
1109impl Mul<U8Vec4> for &u8 {
1110 type Output = U8Vec4;
1111 #[inline]
1112 fn mul(self, rhs: U8Vec4) -> U8Vec4 {
1113 (*self).mul(rhs)
1114 }
1115}
1116
1117impl Add<U8Vec4> for U8Vec4 {
1118 type Output = Self;
1119 #[inline]
1120 fn add(self, rhs: Self) -> Self {
1121 Self {
1122 x: self.x.add(rhs.x),
1123 y: self.y.add(rhs.y),
1124 z: self.z.add(rhs.z),
1125 w: self.w.add(rhs.w),
1126 }
1127 }
1128}
1129
1130impl Add<&U8Vec4> for U8Vec4 {
1131 type Output = U8Vec4;
1132 #[inline]
1133 fn add(self, rhs: &U8Vec4) -> U8Vec4 {
1134 self.add(*rhs)
1135 }
1136}
1137
1138impl Add<&U8Vec4> for &U8Vec4 {
1139 type Output = U8Vec4;
1140 #[inline]
1141 fn add(self, rhs: &U8Vec4) -> U8Vec4 {
1142 (*self).add(*rhs)
1143 }
1144}
1145
1146impl Add<U8Vec4> for &U8Vec4 {
1147 type Output = U8Vec4;
1148 #[inline]
1149 fn add(self, rhs: U8Vec4) -> U8Vec4 {
1150 (*self).add(rhs)
1151 }
1152}
1153
1154impl AddAssign<U8Vec4> for U8Vec4 {
1155 #[inline]
1156 fn add_assign(&mut self, rhs: Self) {
1157 self.x.add_assign(rhs.x);
1158 self.y.add_assign(rhs.y);
1159 self.z.add_assign(rhs.z);
1160 self.w.add_assign(rhs.w);
1161 }
1162}
1163
1164impl AddAssign<&U8Vec4> for U8Vec4 {
1165 #[inline]
1166 fn add_assign(&mut self, rhs: &U8Vec4) {
1167 self.add_assign(*rhs)
1168 }
1169}
1170
1171impl Add<u8> for U8Vec4 {
1172 type Output = Self;
1173 #[inline]
1174 fn add(self, rhs: u8) -> Self {
1175 Self {
1176 x: self.x.add(rhs),
1177 y: self.y.add(rhs),
1178 z: self.z.add(rhs),
1179 w: self.w.add(rhs),
1180 }
1181 }
1182}
1183
1184impl Add<&u8> for U8Vec4 {
1185 type Output = U8Vec4;
1186 #[inline]
1187 fn add(self, rhs: &u8) -> U8Vec4 {
1188 self.add(*rhs)
1189 }
1190}
1191
1192impl Add<&u8> for &U8Vec4 {
1193 type Output = U8Vec4;
1194 #[inline]
1195 fn add(self, rhs: &u8) -> U8Vec4 {
1196 (*self).add(*rhs)
1197 }
1198}
1199
1200impl Add<u8> for &U8Vec4 {
1201 type Output = U8Vec4;
1202 #[inline]
1203 fn add(self, rhs: u8) -> U8Vec4 {
1204 (*self).add(rhs)
1205 }
1206}
1207
1208impl AddAssign<u8> for U8Vec4 {
1209 #[inline]
1210 fn add_assign(&mut self, rhs: u8) {
1211 self.x.add_assign(rhs);
1212 self.y.add_assign(rhs);
1213 self.z.add_assign(rhs);
1214 self.w.add_assign(rhs);
1215 }
1216}
1217
1218impl AddAssign<&u8> for U8Vec4 {
1219 #[inline]
1220 fn add_assign(&mut self, rhs: &u8) {
1221 self.add_assign(*rhs)
1222 }
1223}
1224
1225impl Add<U8Vec4> for u8 {
1226 type Output = U8Vec4;
1227 #[inline]
1228 fn add(self, rhs: U8Vec4) -> U8Vec4 {
1229 U8Vec4 {
1230 x: self.add(rhs.x),
1231 y: self.add(rhs.y),
1232 z: self.add(rhs.z),
1233 w: self.add(rhs.w),
1234 }
1235 }
1236}
1237
1238impl Add<&U8Vec4> for u8 {
1239 type Output = U8Vec4;
1240 #[inline]
1241 fn add(self, rhs: &U8Vec4) -> U8Vec4 {
1242 self.add(*rhs)
1243 }
1244}
1245
1246impl Add<&U8Vec4> for &u8 {
1247 type Output = U8Vec4;
1248 #[inline]
1249 fn add(self, rhs: &U8Vec4) -> U8Vec4 {
1250 (*self).add(*rhs)
1251 }
1252}
1253
1254impl Add<U8Vec4> for &u8 {
1255 type Output = U8Vec4;
1256 #[inline]
1257 fn add(self, rhs: U8Vec4) -> U8Vec4 {
1258 (*self).add(rhs)
1259 }
1260}
1261
1262impl Sub<U8Vec4> for U8Vec4 {
1263 type Output = Self;
1264 #[inline]
1265 fn sub(self, rhs: Self) -> Self {
1266 Self {
1267 x: self.x.sub(rhs.x),
1268 y: self.y.sub(rhs.y),
1269 z: self.z.sub(rhs.z),
1270 w: self.w.sub(rhs.w),
1271 }
1272 }
1273}
1274
1275impl Sub<&U8Vec4> for U8Vec4 {
1276 type Output = U8Vec4;
1277 #[inline]
1278 fn sub(self, rhs: &U8Vec4) -> U8Vec4 {
1279 self.sub(*rhs)
1280 }
1281}
1282
1283impl Sub<&U8Vec4> for &U8Vec4 {
1284 type Output = U8Vec4;
1285 #[inline]
1286 fn sub(self, rhs: &U8Vec4) -> U8Vec4 {
1287 (*self).sub(*rhs)
1288 }
1289}
1290
1291impl Sub<U8Vec4> for &U8Vec4 {
1292 type Output = U8Vec4;
1293 #[inline]
1294 fn sub(self, rhs: U8Vec4) -> U8Vec4 {
1295 (*self).sub(rhs)
1296 }
1297}
1298
1299impl SubAssign<U8Vec4> for U8Vec4 {
1300 #[inline]
1301 fn sub_assign(&mut self, rhs: U8Vec4) {
1302 self.x.sub_assign(rhs.x);
1303 self.y.sub_assign(rhs.y);
1304 self.z.sub_assign(rhs.z);
1305 self.w.sub_assign(rhs.w);
1306 }
1307}
1308
1309impl SubAssign<&U8Vec4> for U8Vec4 {
1310 #[inline]
1311 fn sub_assign(&mut self, rhs: &U8Vec4) {
1312 self.sub_assign(*rhs)
1313 }
1314}
1315
1316impl Sub<u8> for U8Vec4 {
1317 type Output = Self;
1318 #[inline]
1319 fn sub(self, rhs: u8) -> Self {
1320 Self {
1321 x: self.x.sub(rhs),
1322 y: self.y.sub(rhs),
1323 z: self.z.sub(rhs),
1324 w: self.w.sub(rhs),
1325 }
1326 }
1327}
1328
1329impl Sub<&u8> for U8Vec4 {
1330 type Output = U8Vec4;
1331 #[inline]
1332 fn sub(self, rhs: &u8) -> U8Vec4 {
1333 self.sub(*rhs)
1334 }
1335}
1336
1337impl Sub<&u8> for &U8Vec4 {
1338 type Output = U8Vec4;
1339 #[inline]
1340 fn sub(self, rhs: &u8) -> U8Vec4 {
1341 (*self).sub(*rhs)
1342 }
1343}
1344
1345impl Sub<u8> for &U8Vec4 {
1346 type Output = U8Vec4;
1347 #[inline]
1348 fn sub(self, rhs: u8) -> U8Vec4 {
1349 (*self).sub(rhs)
1350 }
1351}
1352
1353impl SubAssign<u8> for U8Vec4 {
1354 #[inline]
1355 fn sub_assign(&mut self, rhs: u8) {
1356 self.x.sub_assign(rhs);
1357 self.y.sub_assign(rhs);
1358 self.z.sub_assign(rhs);
1359 self.w.sub_assign(rhs);
1360 }
1361}
1362
1363impl SubAssign<&u8> for U8Vec4 {
1364 #[inline]
1365 fn sub_assign(&mut self, rhs: &u8) {
1366 self.sub_assign(*rhs)
1367 }
1368}
1369
1370impl Sub<U8Vec4> for u8 {
1371 type Output = U8Vec4;
1372 #[inline]
1373 fn sub(self, rhs: U8Vec4) -> U8Vec4 {
1374 U8Vec4 {
1375 x: self.sub(rhs.x),
1376 y: self.sub(rhs.y),
1377 z: self.sub(rhs.z),
1378 w: self.sub(rhs.w),
1379 }
1380 }
1381}
1382
1383impl Sub<&U8Vec4> for u8 {
1384 type Output = U8Vec4;
1385 #[inline]
1386 fn sub(self, rhs: &U8Vec4) -> U8Vec4 {
1387 self.sub(*rhs)
1388 }
1389}
1390
1391impl Sub<&U8Vec4> for &u8 {
1392 type Output = U8Vec4;
1393 #[inline]
1394 fn sub(self, rhs: &U8Vec4) -> U8Vec4 {
1395 (*self).sub(*rhs)
1396 }
1397}
1398
1399impl Sub<U8Vec4> for &u8 {
1400 type Output = U8Vec4;
1401 #[inline]
1402 fn sub(self, rhs: U8Vec4) -> U8Vec4 {
1403 (*self).sub(rhs)
1404 }
1405}
1406
1407impl Rem<U8Vec4> for U8Vec4 {
1408 type Output = Self;
1409 #[inline]
1410 fn rem(self, rhs: Self) -> Self {
1411 Self {
1412 x: self.x.rem(rhs.x),
1413 y: self.y.rem(rhs.y),
1414 z: self.z.rem(rhs.z),
1415 w: self.w.rem(rhs.w),
1416 }
1417 }
1418}
1419
1420impl Rem<&U8Vec4> for U8Vec4 {
1421 type Output = U8Vec4;
1422 #[inline]
1423 fn rem(self, rhs: &U8Vec4) -> U8Vec4 {
1424 self.rem(*rhs)
1425 }
1426}
1427
1428impl Rem<&U8Vec4> for &U8Vec4 {
1429 type Output = U8Vec4;
1430 #[inline]
1431 fn rem(self, rhs: &U8Vec4) -> U8Vec4 {
1432 (*self).rem(*rhs)
1433 }
1434}
1435
1436impl Rem<U8Vec4> for &U8Vec4 {
1437 type Output = U8Vec4;
1438 #[inline]
1439 fn rem(self, rhs: U8Vec4) -> U8Vec4 {
1440 (*self).rem(rhs)
1441 }
1442}
1443
1444impl RemAssign<U8Vec4> for U8Vec4 {
1445 #[inline]
1446 fn rem_assign(&mut self, rhs: Self) {
1447 self.x.rem_assign(rhs.x);
1448 self.y.rem_assign(rhs.y);
1449 self.z.rem_assign(rhs.z);
1450 self.w.rem_assign(rhs.w);
1451 }
1452}
1453
1454impl RemAssign<&U8Vec4> for U8Vec4 {
1455 #[inline]
1456 fn rem_assign(&mut self, rhs: &U8Vec4) {
1457 self.rem_assign(*rhs)
1458 }
1459}
1460
1461impl Rem<u8> for U8Vec4 {
1462 type Output = Self;
1463 #[inline]
1464 fn rem(self, rhs: u8) -> Self {
1465 Self {
1466 x: self.x.rem(rhs),
1467 y: self.y.rem(rhs),
1468 z: self.z.rem(rhs),
1469 w: self.w.rem(rhs),
1470 }
1471 }
1472}
1473
1474impl Rem<&u8> for U8Vec4 {
1475 type Output = U8Vec4;
1476 #[inline]
1477 fn rem(self, rhs: &u8) -> U8Vec4 {
1478 self.rem(*rhs)
1479 }
1480}
1481
1482impl Rem<&u8> for &U8Vec4 {
1483 type Output = U8Vec4;
1484 #[inline]
1485 fn rem(self, rhs: &u8) -> U8Vec4 {
1486 (*self).rem(*rhs)
1487 }
1488}
1489
1490impl Rem<u8> for &U8Vec4 {
1491 type Output = U8Vec4;
1492 #[inline]
1493 fn rem(self, rhs: u8) -> U8Vec4 {
1494 (*self).rem(rhs)
1495 }
1496}
1497
1498impl RemAssign<u8> for U8Vec4 {
1499 #[inline]
1500 fn rem_assign(&mut self, rhs: u8) {
1501 self.x.rem_assign(rhs);
1502 self.y.rem_assign(rhs);
1503 self.z.rem_assign(rhs);
1504 self.w.rem_assign(rhs);
1505 }
1506}
1507
1508impl RemAssign<&u8> for U8Vec4 {
1509 #[inline]
1510 fn rem_assign(&mut self, rhs: &u8) {
1511 self.rem_assign(*rhs)
1512 }
1513}
1514
1515impl Rem<U8Vec4> for u8 {
1516 type Output = U8Vec4;
1517 #[inline]
1518 fn rem(self, rhs: U8Vec4) -> U8Vec4 {
1519 U8Vec4 {
1520 x: self.rem(rhs.x),
1521 y: self.rem(rhs.y),
1522 z: self.rem(rhs.z),
1523 w: self.rem(rhs.w),
1524 }
1525 }
1526}
1527
1528impl Rem<&U8Vec4> for u8 {
1529 type Output = U8Vec4;
1530 #[inline]
1531 fn rem(self, rhs: &U8Vec4) -> U8Vec4 {
1532 self.rem(*rhs)
1533 }
1534}
1535
1536impl Rem<&U8Vec4> for &u8 {
1537 type Output = U8Vec4;
1538 #[inline]
1539 fn rem(self, rhs: &U8Vec4) -> U8Vec4 {
1540 (*self).rem(*rhs)
1541 }
1542}
1543
1544impl Rem<U8Vec4> for &u8 {
1545 type Output = U8Vec4;
1546 #[inline]
1547 fn rem(self, rhs: U8Vec4) -> U8Vec4 {
1548 (*self).rem(rhs)
1549 }
1550}
1551
1552#[cfg(not(target_arch = "spirv"))]
1553impl AsRef<[u8; 4]> for U8Vec4 {
1554 #[inline]
1555 fn as_ref(&self) -> &[u8; 4] {
1556 unsafe { &*(self as *const U8Vec4 as *const [u8; 4]) }
1557 }
1558}
1559
1560#[cfg(not(target_arch = "spirv"))]
1561impl AsMut<[u8; 4]> for U8Vec4 {
1562 #[inline]
1563 fn as_mut(&mut self) -> &mut [u8; 4] {
1564 unsafe { &mut *(self as *mut U8Vec4 as *mut [u8; 4]) }
1565 }
1566}
1567
1568impl Sum for U8Vec4 {
1569 #[inline]
1570 fn sum<I>(iter: I) -> Self
1571 where
1572 I: Iterator<Item = Self>,
1573 {
1574 iter.fold(Self::ZERO, Self::add)
1575 }
1576}
1577
1578impl<'a> Sum<&'a Self> for U8Vec4 {
1579 #[inline]
1580 fn sum<I>(iter: I) -> Self
1581 where
1582 I: Iterator<Item = &'a Self>,
1583 {
1584 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1585 }
1586}
1587
1588impl Product for U8Vec4 {
1589 #[inline]
1590 fn product<I>(iter: I) -> Self
1591 where
1592 I: Iterator<Item = Self>,
1593 {
1594 iter.fold(Self::ONE, Self::mul)
1595 }
1596}
1597
1598impl<'a> Product<&'a Self> for U8Vec4 {
1599 #[inline]
1600 fn product<I>(iter: I) -> Self
1601 where
1602 I: Iterator<Item = &'a Self>,
1603 {
1604 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1605 }
1606}
1607
1608impl Not for U8Vec4 {
1609 type Output = Self;
1610 #[inline]
1611 fn not(self) -> Self::Output {
1612 Self {
1613 x: self.x.not(),
1614 y: self.y.not(),
1615 z: self.z.not(),
1616 w: self.w.not(),
1617 }
1618 }
1619}
1620
1621impl BitAnd for U8Vec4 {
1622 type Output = Self;
1623 #[inline]
1624 fn bitand(self, rhs: Self) -> Self::Output {
1625 Self {
1626 x: self.x.bitand(rhs.x),
1627 y: self.y.bitand(rhs.y),
1628 z: self.z.bitand(rhs.z),
1629 w: self.w.bitand(rhs.w),
1630 }
1631 }
1632}
1633
1634impl BitOr for U8Vec4 {
1635 type Output = Self;
1636 #[inline]
1637 fn bitor(self, rhs: Self) -> Self::Output {
1638 Self {
1639 x: self.x.bitor(rhs.x),
1640 y: self.y.bitor(rhs.y),
1641 z: self.z.bitor(rhs.z),
1642 w: self.w.bitor(rhs.w),
1643 }
1644 }
1645}
1646
1647impl BitXor for U8Vec4 {
1648 type Output = Self;
1649 #[inline]
1650 fn bitxor(self, rhs: Self) -> Self::Output {
1651 Self {
1652 x: self.x.bitxor(rhs.x),
1653 y: self.y.bitxor(rhs.y),
1654 z: self.z.bitxor(rhs.z),
1655 w: self.w.bitxor(rhs.w),
1656 }
1657 }
1658}
1659
1660impl BitAnd<u8> for U8Vec4 {
1661 type Output = Self;
1662 #[inline]
1663 fn bitand(self, rhs: u8) -> Self::Output {
1664 Self {
1665 x: self.x.bitand(rhs),
1666 y: self.y.bitand(rhs),
1667 z: self.z.bitand(rhs),
1668 w: self.w.bitand(rhs),
1669 }
1670 }
1671}
1672
1673impl BitOr<u8> for U8Vec4 {
1674 type Output = Self;
1675 #[inline]
1676 fn bitor(self, rhs: u8) -> Self::Output {
1677 Self {
1678 x: self.x.bitor(rhs),
1679 y: self.y.bitor(rhs),
1680 z: self.z.bitor(rhs),
1681 w: self.w.bitor(rhs),
1682 }
1683 }
1684}
1685
1686impl BitXor<u8> for U8Vec4 {
1687 type Output = Self;
1688 #[inline]
1689 fn bitxor(self, rhs: u8) -> Self::Output {
1690 Self {
1691 x: self.x.bitxor(rhs),
1692 y: self.y.bitxor(rhs),
1693 z: self.z.bitxor(rhs),
1694 w: self.w.bitxor(rhs),
1695 }
1696 }
1697}
1698
1699impl Shl<i8> for U8Vec4 {
1700 type Output = Self;
1701 #[inline]
1702 fn shl(self, rhs: i8) -> Self::Output {
1703 Self {
1704 x: self.x.shl(rhs),
1705 y: self.y.shl(rhs),
1706 z: self.z.shl(rhs),
1707 w: self.w.shl(rhs),
1708 }
1709 }
1710}
1711
1712impl Shr<i8> for U8Vec4 {
1713 type Output = Self;
1714 #[inline]
1715 fn shr(self, rhs: i8) -> Self::Output {
1716 Self {
1717 x: self.x.shr(rhs),
1718 y: self.y.shr(rhs),
1719 z: self.z.shr(rhs),
1720 w: self.w.shr(rhs),
1721 }
1722 }
1723}
1724
1725impl Shl<i16> for U8Vec4 {
1726 type Output = Self;
1727 #[inline]
1728 fn shl(self, rhs: i16) -> Self::Output {
1729 Self {
1730 x: self.x.shl(rhs),
1731 y: self.y.shl(rhs),
1732 z: self.z.shl(rhs),
1733 w: self.w.shl(rhs),
1734 }
1735 }
1736}
1737
1738impl Shr<i16> for U8Vec4 {
1739 type Output = Self;
1740 #[inline]
1741 fn shr(self, rhs: i16) -> Self::Output {
1742 Self {
1743 x: self.x.shr(rhs),
1744 y: self.y.shr(rhs),
1745 z: self.z.shr(rhs),
1746 w: self.w.shr(rhs),
1747 }
1748 }
1749}
1750
1751impl Shl<i32> for U8Vec4 {
1752 type Output = Self;
1753 #[inline]
1754 fn shl(self, rhs: i32) -> Self::Output {
1755 Self {
1756 x: self.x.shl(rhs),
1757 y: self.y.shl(rhs),
1758 z: self.z.shl(rhs),
1759 w: self.w.shl(rhs),
1760 }
1761 }
1762}
1763
1764impl Shr<i32> for U8Vec4 {
1765 type Output = Self;
1766 #[inline]
1767 fn shr(self, rhs: i32) -> Self::Output {
1768 Self {
1769 x: self.x.shr(rhs),
1770 y: self.y.shr(rhs),
1771 z: self.z.shr(rhs),
1772 w: self.w.shr(rhs),
1773 }
1774 }
1775}
1776
1777impl Shl<i64> for U8Vec4 {
1778 type Output = Self;
1779 #[inline]
1780 fn shl(self, rhs: i64) -> Self::Output {
1781 Self {
1782 x: self.x.shl(rhs),
1783 y: self.y.shl(rhs),
1784 z: self.z.shl(rhs),
1785 w: self.w.shl(rhs),
1786 }
1787 }
1788}
1789
1790impl Shr<i64> for U8Vec4 {
1791 type Output = Self;
1792 #[inline]
1793 fn shr(self, rhs: i64) -> Self::Output {
1794 Self {
1795 x: self.x.shr(rhs),
1796 y: self.y.shr(rhs),
1797 z: self.z.shr(rhs),
1798 w: self.w.shr(rhs),
1799 }
1800 }
1801}
1802
1803impl Shl<u8> for U8Vec4 {
1804 type Output = Self;
1805 #[inline]
1806 fn shl(self, rhs: u8) -> Self::Output {
1807 Self {
1808 x: self.x.shl(rhs),
1809 y: self.y.shl(rhs),
1810 z: self.z.shl(rhs),
1811 w: self.w.shl(rhs),
1812 }
1813 }
1814}
1815
1816impl Shr<u8> for U8Vec4 {
1817 type Output = Self;
1818 #[inline]
1819 fn shr(self, rhs: u8) -> Self::Output {
1820 Self {
1821 x: self.x.shr(rhs),
1822 y: self.y.shr(rhs),
1823 z: self.z.shr(rhs),
1824 w: self.w.shr(rhs),
1825 }
1826 }
1827}
1828
1829impl Shl<u16> for U8Vec4 {
1830 type Output = Self;
1831 #[inline]
1832 fn shl(self, rhs: u16) -> Self::Output {
1833 Self {
1834 x: self.x.shl(rhs),
1835 y: self.y.shl(rhs),
1836 z: self.z.shl(rhs),
1837 w: self.w.shl(rhs),
1838 }
1839 }
1840}
1841
1842impl Shr<u16> for U8Vec4 {
1843 type Output = Self;
1844 #[inline]
1845 fn shr(self, rhs: u16) -> Self::Output {
1846 Self {
1847 x: self.x.shr(rhs),
1848 y: self.y.shr(rhs),
1849 z: self.z.shr(rhs),
1850 w: self.w.shr(rhs),
1851 }
1852 }
1853}
1854
1855impl Shl<u32> for U8Vec4 {
1856 type Output = Self;
1857 #[inline]
1858 fn shl(self, rhs: u32) -> Self::Output {
1859 Self {
1860 x: self.x.shl(rhs),
1861 y: self.y.shl(rhs),
1862 z: self.z.shl(rhs),
1863 w: self.w.shl(rhs),
1864 }
1865 }
1866}
1867
1868impl Shr<u32> for U8Vec4 {
1869 type Output = Self;
1870 #[inline]
1871 fn shr(self, rhs: u32) -> Self::Output {
1872 Self {
1873 x: self.x.shr(rhs),
1874 y: self.y.shr(rhs),
1875 z: self.z.shr(rhs),
1876 w: self.w.shr(rhs),
1877 }
1878 }
1879}
1880
1881impl Shl<u64> for U8Vec4 {
1882 type Output = Self;
1883 #[inline]
1884 fn shl(self, rhs: u64) -> Self::Output {
1885 Self {
1886 x: self.x.shl(rhs),
1887 y: self.y.shl(rhs),
1888 z: self.z.shl(rhs),
1889 w: self.w.shl(rhs),
1890 }
1891 }
1892}
1893
1894impl Shr<u64> for U8Vec4 {
1895 type Output = Self;
1896 #[inline]
1897 fn shr(self, rhs: u64) -> Self::Output {
1898 Self {
1899 x: self.x.shr(rhs),
1900 y: self.y.shr(rhs),
1901 z: self.z.shr(rhs),
1902 w: self.w.shr(rhs),
1903 }
1904 }
1905}
1906
1907impl Shl<crate::IVec4> for U8Vec4 {
1908 type Output = Self;
1909 #[inline]
1910 fn shl(self, rhs: crate::IVec4) -> Self::Output {
1911 Self {
1912 x: self.x.shl(rhs.x),
1913 y: self.y.shl(rhs.y),
1914 z: self.z.shl(rhs.z),
1915 w: self.w.shl(rhs.w),
1916 }
1917 }
1918}
1919
1920impl Shr<crate::IVec4> for U8Vec4 {
1921 type Output = Self;
1922 #[inline]
1923 fn shr(self, rhs: crate::IVec4) -> Self::Output {
1924 Self {
1925 x: self.x.shr(rhs.x),
1926 y: self.y.shr(rhs.y),
1927 z: self.z.shr(rhs.z),
1928 w: self.w.shr(rhs.w),
1929 }
1930 }
1931}
1932
1933impl Shl<crate::UVec4> for U8Vec4 {
1934 type Output = Self;
1935 #[inline]
1936 fn shl(self, rhs: crate::UVec4) -> Self::Output {
1937 Self {
1938 x: self.x.shl(rhs.x),
1939 y: self.y.shl(rhs.y),
1940 z: self.z.shl(rhs.z),
1941 w: self.w.shl(rhs.w),
1942 }
1943 }
1944}
1945
1946impl Shr<crate::UVec4> for U8Vec4 {
1947 type Output = Self;
1948 #[inline]
1949 fn shr(self, rhs: crate::UVec4) -> Self::Output {
1950 Self {
1951 x: self.x.shr(rhs.x),
1952 y: self.y.shr(rhs.y),
1953 z: self.z.shr(rhs.z),
1954 w: self.w.shr(rhs.w),
1955 }
1956 }
1957}
1958
1959impl Index<usize> for U8Vec4 {
1960 type Output = u8;
1961 #[inline]
1962 fn index(&self, index: usize) -> &Self::Output {
1963 match index {
1964 0 => &self.x,
1965 1 => &self.y,
1966 2 => &self.z,
1967 3 => &self.w,
1968 _ => panic!("index out of bounds"),
1969 }
1970 }
1971}
1972
1973impl IndexMut<usize> for U8Vec4 {
1974 #[inline]
1975 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1976 match index {
1977 0 => &mut self.x,
1978 1 => &mut self.y,
1979 2 => &mut self.z,
1980 3 => &mut self.w,
1981 _ => panic!("index out of bounds"),
1982 }
1983 }
1984}
1985
1986impl fmt::Display for U8Vec4 {
1987 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1988 write!(f, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w)
1989 }
1990}
1991
1992impl fmt::Debug for U8Vec4 {
1993 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1994 fmt.debug_tuple(stringify!(U8Vec4))
1995 .field(&self.x)
1996 .field(&self.y)
1997 .field(&self.z)
1998 .field(&self.w)
1999 .finish()
2000 }
2001}
2002
2003impl From<[u8; 4]> for U8Vec4 {
2004 #[inline]
2005 fn from(a: [u8; 4]) -> Self {
2006 Self::new(a[0], a[1], a[2], a[3])
2007 }
2008}
2009
2010impl From<U8Vec4> for [u8; 4] {
2011 #[inline]
2012 fn from(v: U8Vec4) -> Self {
2013 [v.x, v.y, v.z, v.w]
2014 }
2015}
2016
2017impl From<(u8, u8, u8, u8)> for U8Vec4 {
2018 #[inline]
2019 fn from(t: (u8, u8, u8, u8)) -> Self {
2020 Self::new(t.0, t.1, t.2, t.3)
2021 }
2022}
2023
2024impl From<U8Vec4> for (u8, u8, u8, u8) {
2025 #[inline]
2026 fn from(v: U8Vec4) -> Self {
2027 (v.x, v.y, v.z, v.w)
2028 }
2029}
2030
2031impl From<(U8Vec3, u8)> for U8Vec4 {
2032 #[inline]
2033 fn from((v, w): (U8Vec3, u8)) -> Self {
2034 Self::new(v.x, v.y, v.z, w)
2035 }
2036}
2037
2038impl From<(u8, U8Vec3)> for U8Vec4 {
2039 #[inline]
2040 fn from((x, v): (u8, U8Vec3)) -> Self {
2041 Self::new(x, v.x, v.y, v.z)
2042 }
2043}
2044
2045impl From<(U8Vec2, u8, u8)> for U8Vec4 {
2046 #[inline]
2047 fn from((v, z, w): (U8Vec2, u8, u8)) -> Self {
2048 Self::new(v.x, v.y, z, w)
2049 }
2050}
2051
2052impl From<(U8Vec2, U8Vec2)> for U8Vec4 {
2053 #[inline]
2054 fn from((v, u): (U8Vec2, U8Vec2)) -> Self {
2055 Self::new(v.x, v.y, u.x, u.y)
2056 }
2057}
2058
2059impl TryFrom<I8Vec4> for U8Vec4 {
2060 type Error = core::num::TryFromIntError;
2061
2062 #[inline]
2063 fn try_from(v: I8Vec4) -> Result<Self, Self::Error> {
2064 Ok(Self::new(
2065 u8::try_from(v.x)?,
2066 u8::try_from(v.y)?,
2067 u8::try_from(v.z)?,
2068 u8::try_from(v.w)?,
2069 ))
2070 }
2071}
2072
2073impl TryFrom<I16Vec4> for U8Vec4 {
2074 type Error = core::num::TryFromIntError;
2075
2076 #[inline]
2077 fn try_from(v: I16Vec4) -> Result<Self, Self::Error> {
2078 Ok(Self::new(
2079 u8::try_from(v.x)?,
2080 u8::try_from(v.y)?,
2081 u8::try_from(v.z)?,
2082 u8::try_from(v.w)?,
2083 ))
2084 }
2085}
2086
2087impl TryFrom<U16Vec4> for U8Vec4 {
2088 type Error = core::num::TryFromIntError;
2089
2090 #[inline]
2091 fn try_from(v: U16Vec4) -> Result<Self, Self::Error> {
2092 Ok(Self::new(
2093 u8::try_from(v.x)?,
2094 u8::try_from(v.y)?,
2095 u8::try_from(v.z)?,
2096 u8::try_from(v.w)?,
2097 ))
2098 }
2099}
2100
2101impl TryFrom<IVec4> for U8Vec4 {
2102 type Error = core::num::TryFromIntError;
2103
2104 #[inline]
2105 fn try_from(v: IVec4) -> Result<Self, Self::Error> {
2106 Ok(Self::new(
2107 u8::try_from(v.x)?,
2108 u8::try_from(v.y)?,
2109 u8::try_from(v.z)?,
2110 u8::try_from(v.w)?,
2111 ))
2112 }
2113}
2114
2115impl TryFrom<UVec4> for U8Vec4 {
2116 type Error = core::num::TryFromIntError;
2117
2118 #[inline]
2119 fn try_from(v: UVec4) -> Result<Self, Self::Error> {
2120 Ok(Self::new(
2121 u8::try_from(v.x)?,
2122 u8::try_from(v.y)?,
2123 u8::try_from(v.z)?,
2124 u8::try_from(v.w)?,
2125 ))
2126 }
2127}
2128
2129impl TryFrom<I64Vec4> for U8Vec4 {
2130 type Error = core::num::TryFromIntError;
2131
2132 #[inline]
2133 fn try_from(v: I64Vec4) -> Result<Self, Self::Error> {
2134 Ok(Self::new(
2135 u8::try_from(v.x)?,
2136 u8::try_from(v.y)?,
2137 u8::try_from(v.z)?,
2138 u8::try_from(v.w)?,
2139 ))
2140 }
2141}
2142
2143impl TryFrom<U64Vec4> for U8Vec4 {
2144 type Error = core::num::TryFromIntError;
2145
2146 #[inline]
2147 fn try_from(v: U64Vec4) -> Result<Self, Self::Error> {
2148 Ok(Self::new(
2149 u8::try_from(v.x)?,
2150 u8::try_from(v.y)?,
2151 u8::try_from(v.z)?,
2152 u8::try_from(v.w)?,
2153 ))
2154 }
2155}
2156
2157impl TryFrom<USizeVec4> for U8Vec4 {
2158 type Error = core::num::TryFromIntError;
2159
2160 #[inline]
2161 fn try_from(v: USizeVec4) -> Result<Self, Self::Error> {
2162 Ok(Self::new(
2163 u8::try_from(v.x)?,
2164 u8::try_from(v.y)?,
2165 u8::try_from(v.z)?,
2166 u8::try_from(v.w)?,
2167 ))
2168 }
2169}
2170
2171impl From<BVec4> for U8Vec4 {
2172 #[inline]
2173 fn from(v: BVec4) -> Self {
2174 Self::new(u8::from(v.x), u8::from(v.y), u8::from(v.z), u8::from(v.w))
2175 }
2176}
2177
2178#[cfg(not(feature = "scalar-math"))]
2179impl From<BVec4A> for U8Vec4 {
2180 #[inline]
2181 fn from(v: BVec4A) -> Self {
2182 let bool_array: [bool; 4] = v.into();
2183 Self::new(
2184 u8::from(bool_array[0]),
2185 u8::from(bool_array[1]),
2186 u8::from(bool_array[2]),
2187 u8::from(bool_array[3]),
2188 )
2189 }
2190}