[go: up one dir, main page]

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