glam/u8/
u8vec3.rs

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