glam/u8/
u8vec4.rs

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