glam/u16/
u16vec4.rs

1// Generated from vec.rs.tera template. Edit the template, not the generated file.
2
3#[cfg(not(feature = "scalar-math"))]
4use crate::BVec4A;
5use crate::{BVec4, I16Vec4, I64Vec4, IVec4, U16Vec2, U16Vec3, U64Vec4, UVec4};
6
7#[cfg(not(target_arch = "spirv"))]
8use core::fmt;
9use core::iter::{Product, Sum};
10use core::{f32, ops::*};
11
12/// Creates a 4-dimensional vector.
13#[inline(always)]
14#[must_use]
15pub const fn u16vec4(x: u16, y: u16, z: u16, w: u16) -> U16Vec4 {
16    U16Vec4::new(x, y, z, w)
17}
18
19/// A 4-dimensional vector.
20#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
21#[derive(Clone, Copy, PartialEq, Eq)]
22#[cfg_attr(feature = "cuda", repr(align(8)))]
23#[cfg_attr(not(target_arch = "spirv"), repr(C))]
24#[cfg_attr(target_arch = "spirv", repr(simd))]
25pub struct U16Vec4 {
26    pub x: u16,
27    pub y: u16,
28    pub z: u16,
29    pub w: u16,
30}
31
32impl U16Vec4 {
33    /// All zeroes.
34    pub const ZERO: Self = Self::splat(0);
35
36    /// All ones.
37    pub const ONE: Self = Self::splat(1);
38
39    /// All `u16::MIN`.
40    pub const MIN: Self = Self::splat(u16::MIN);
41
42    /// All `u16::MAX`.
43    pub const MAX: Self = Self::splat(u16::MAX);
44
45    /// A unit vector pointing along the positive X axis.
46    pub const X: Self = Self::new(1, 0, 0, 0);
47
48    /// A unit vector pointing along the positive Y axis.
49    pub const Y: Self = Self::new(0, 1, 0, 0);
50
51    /// A unit vector pointing along the positive Z axis.
52    pub const Z: Self = Self::new(0, 0, 1, 0);
53
54    /// A unit vector pointing along the positive W axis.
55    pub const W: Self = Self::new(0, 0, 0, 1);
56
57    /// The unit axes.
58    pub const AXES: [Self; 4] = [Self::X, Self::Y, Self::Z, Self::W];
59
60    /// Creates a new vector.
61    #[inline(always)]
62    #[must_use]
63    pub const fn new(x: u16, y: u16, z: u16, w: u16) -> Self {
64        Self { x, y, z, w }
65    }
66
67    /// Creates a vector with all elements set to `v`.
68    #[inline]
69    #[must_use]
70    pub const fn splat(v: u16) -> Self {
71        Self {
72            x: v,
73
74            y: v,
75
76            z: v,
77
78            w: v,
79        }
80    }
81
82    /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
83    /// for each element of `self`.
84    ///
85    /// A true element in the mask uses the corresponding element from `if_true`, and false
86    /// uses the element from `if_false`.
87    #[inline]
88    #[must_use]
89    pub fn select(mask: BVec4, if_true: Self, if_false: Self) -> Self {
90        Self {
91            x: if mask.test(0) { if_true.x } else { if_false.x },
92            y: if mask.test(1) { if_true.y } else { if_false.y },
93            z: if mask.test(2) { if_true.z } else { if_false.z },
94            w: if mask.test(3) { if_true.w } else { if_false.w },
95        }
96    }
97
98    /// Creates a new vector from an array.
99    #[inline]
100    #[must_use]
101    pub const fn from_array(a: [u16; 4]) -> Self {
102        Self::new(a[0], a[1], a[2], a[3])
103    }
104
105    /// `[x, y, z, w]`
106    #[inline]
107    #[must_use]
108    pub const fn to_array(&self) -> [u16; 4] {
109        [self.x, self.y, self.z, self.w]
110    }
111
112    /// Creates a vector from the first 4 values in `slice`.
113    ///
114    /// # Panics
115    ///
116    /// Panics if `slice` is less than 4 elements long.
117    #[inline]
118    #[must_use]
119    pub const fn from_slice(slice: &[u16]) -> Self {
120        Self::new(slice[0], slice[1], slice[2], slice[3])
121    }
122
123    /// Writes the elements of `self` to the first 4 elements in `slice`.
124    ///
125    /// # Panics
126    ///
127    /// Panics if `slice` is less than 4 elements long.
128    #[inline]
129    pub fn write_to_slice(self, slice: &mut [u16]) {
130        slice[0] = self.x;
131        slice[1] = self.y;
132        slice[2] = self.z;
133        slice[3] = self.w;
134    }
135
136    /// Creates a 3D vector from the `x`, `y` and `z` elements of `self`, discarding `w`.
137    ///
138    /// Truncation to [`U16Vec3`] may also be performed by using [`self.xyz()`][crate::swizzles::Vec4Swizzles::xyz()].
139    #[inline]
140    #[must_use]
141    pub fn truncate(self) -> U16Vec3 {
142        use crate::swizzles::Vec4Swizzles;
143        self.xyz()
144    }
145
146    /// Creates a 4D vector from `self` with the given value of `x`.
147    #[inline]
148    #[must_use]
149    pub fn with_x(mut self, x: u16) -> Self {
150        self.x = x;
151        self
152    }
153
154    /// Creates a 4D vector from `self` with the given value of `y`.
155    #[inline]
156    #[must_use]
157    pub fn with_y(mut self, y: u16) -> Self {
158        self.y = y;
159        self
160    }
161
162    /// Creates a 4D vector from `self` with the given value of `z`.
163    #[inline]
164    #[must_use]
165    pub fn with_z(mut self, z: u16) -> Self {
166        self.z = z;
167        self
168    }
169
170    /// Creates a 4D vector from `self` with the given value of `w`.
171    #[inline]
172    #[must_use]
173    pub fn with_w(mut self, w: u16) -> Self {
174        self.w = w;
175        self
176    }
177
178    /// Computes the dot product of `self` and `rhs`.
179    #[inline]
180    #[must_use]
181    pub fn dot(self, rhs: Self) -> u16 {
182        (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z) + (self.w * rhs.w)
183    }
184
185    /// Returns a vector where every component is the dot product of `self` and `rhs`.
186    #[inline]
187    #[must_use]
188    pub fn dot_into_vec(self, rhs: Self) -> Self {
189        Self::splat(self.dot(rhs))
190    }
191
192    /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
193    ///
194    /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
195    #[inline]
196    #[must_use]
197    pub fn min(self, rhs: Self) -> Self {
198        Self {
199            x: self.x.min(rhs.x),
200            y: self.y.min(rhs.y),
201            z: self.z.min(rhs.z),
202            w: self.w.min(rhs.w),
203        }
204    }
205
206    /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
207    ///
208    /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
209    #[inline]
210    #[must_use]
211    pub fn max(self, rhs: Self) -> Self {
212        Self {
213            x: self.x.max(rhs.x),
214            y: self.y.max(rhs.y),
215            z: self.z.max(rhs.z),
216            w: self.w.max(rhs.w),
217        }
218    }
219
220    /// Component-wise clamping of values, similar to [`u16::clamp`].
221    ///
222    /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
223    ///
224    /// # Panics
225    ///
226    /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
227    #[inline]
228    #[must_use]
229    pub fn clamp(self, min: Self, max: Self) -> Self {
230        glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
231        self.max(min).min(max)
232    }
233
234    /// Returns the horizontal minimum of `self`.
235    ///
236    /// In other words this computes `min(x, y, ..)`.
237    #[inline]
238    #[must_use]
239    pub fn min_element(self) -> u16 {
240        self.x.min(self.y.min(self.z.min(self.w)))
241    }
242
243    /// Returns the horizontal maximum of `self`.
244    ///
245    /// In other words this computes `max(x, y, ..)`.
246    #[inline]
247    #[must_use]
248    pub fn max_element(self) -> u16 {
249        self.x.max(self.y.max(self.z.max(self.w)))
250    }
251
252    /// Returns the sum of all elements of `self`.
253    ///
254    /// In other words, this computes `self.x + self.y + ..`.
255    #[inline]
256    #[must_use]
257    pub fn element_sum(self) -> u16 {
258        self.x + self.y + self.z + self.w
259    }
260
261    /// Returns the product of all elements of `self`.
262    ///
263    /// In other words, this computes `self.x * self.y * ..`.
264    #[inline]
265    #[must_use]
266    pub fn element_product(self) -> u16 {
267        self.x * self.y * self.z * self.w
268    }
269
270    /// Returns a vector mask containing the result of a `==` comparison for each element of
271    /// `self` and `rhs`.
272    ///
273    /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
274    /// elements.
275    #[inline]
276    #[must_use]
277    pub fn cmpeq(self, rhs: Self) -> BVec4 {
278        BVec4::new(
279            self.x.eq(&rhs.x),
280            self.y.eq(&rhs.y),
281            self.z.eq(&rhs.z),
282            self.w.eq(&rhs.w),
283        )
284    }
285
286    /// Returns a vector mask containing the result of a `!=` comparison for each element of
287    /// `self` and `rhs`.
288    ///
289    /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
290    /// elements.
291    #[inline]
292    #[must_use]
293    pub fn cmpne(self, rhs: Self) -> BVec4 {
294        BVec4::new(
295            self.x.ne(&rhs.x),
296            self.y.ne(&rhs.y),
297            self.z.ne(&rhs.z),
298            self.w.ne(&rhs.w),
299        )
300    }
301
302    /// Returns a vector mask containing the result of a `>=` comparison for each element of
303    /// `self` and `rhs`.
304    ///
305    /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
306    /// elements.
307    #[inline]
308    #[must_use]
309    pub fn cmpge(self, rhs: Self) -> BVec4 {
310        BVec4::new(
311            self.x.ge(&rhs.x),
312            self.y.ge(&rhs.y),
313            self.z.ge(&rhs.z),
314            self.w.ge(&rhs.w),
315        )
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 cmpgt(self, rhs: Self) -> BVec4 {
326        BVec4::new(
327            self.x.gt(&rhs.x),
328            self.y.gt(&rhs.y),
329            self.z.gt(&rhs.z),
330            self.w.gt(&rhs.w),
331        )
332    }
333
334    /// Returns a vector mask containing the result of a `<=` comparison for each element of
335    /// `self` and `rhs`.
336    ///
337    /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
338    /// elements.
339    #[inline]
340    #[must_use]
341    pub fn cmple(self, rhs: Self) -> BVec4 {
342        BVec4::new(
343            self.x.le(&rhs.x),
344            self.y.le(&rhs.y),
345            self.z.le(&rhs.z),
346            self.w.le(&rhs.w),
347        )
348    }
349
350    /// Returns a vector mask containing the result of a `<` comparison for each element of
351    /// `self` and `rhs`.
352    ///
353    /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
354    /// elements.
355    #[inline]
356    #[must_use]
357    pub fn cmplt(self, rhs: Self) -> BVec4 {
358        BVec4::new(
359            self.x.lt(&rhs.x),
360            self.y.lt(&rhs.y),
361            self.z.lt(&rhs.z),
362            self.w.lt(&rhs.w),
363        )
364    }
365
366    /// Computes the squared length of `self`.
367    #[doc(alias = "magnitude2")]
368    #[inline]
369    #[must_use]
370    pub fn length_squared(self) -> u16 {
371        self.dot(self)
372    }
373
374    /// Casts all elements of `self` to `f32`.
375    #[inline]
376    #[must_use]
377    pub fn as_vec4(&self) -> crate::Vec4 {
378        crate::Vec4::new(self.x as f32, self.y as f32, self.z as f32, self.w as f32)
379    }
380
381    /// Casts all elements of `self` to `f64`.
382    #[inline]
383    #[must_use]
384    pub fn as_dvec4(&self) -> crate::DVec4 {
385        crate::DVec4::new(self.x as f64, self.y as f64, self.z as f64, self.w as f64)
386    }
387
388    /// Casts all elements of `self` to `i16`.
389    #[inline]
390    #[must_use]
391    pub fn as_i16vec4(&self) -> crate::I16Vec4 {
392        crate::I16Vec4::new(self.x as i16, self.y as i16, self.z as i16, self.w as i16)
393    }
394
395    /// Casts all elements of `self` to `i32`.
396    #[inline]
397    #[must_use]
398    pub fn as_ivec4(&self) -> crate::IVec4 {
399        crate::IVec4::new(self.x as i32, self.y as i32, self.z as i32, self.w as i32)
400    }
401
402    /// Casts all elements of `self` to `u32`.
403    #[inline]
404    #[must_use]
405    pub fn as_uvec4(&self) -> crate::UVec4 {
406        crate::UVec4::new(self.x as u32, self.y as u32, self.z as u32, self.w as u32)
407    }
408
409    /// Casts all elements of `self` to `i64`.
410    #[inline]
411    #[must_use]
412    pub fn as_i64vec4(&self) -> crate::I64Vec4 {
413        crate::I64Vec4::new(self.x as i64, self.y as i64, self.z as i64, self.w as i64)
414    }
415
416    /// Casts all elements of `self` to `u64`.
417    #[inline]
418    #[must_use]
419    pub fn as_u64vec4(&self) -> crate::U64Vec4 {
420        crate::U64Vec4::new(self.x as u64, self.y as u64, self.z as u64, self.w as u64)
421    }
422
423    /// Returns a vector containing the wrapping addition of `self` and `rhs`.
424    ///
425    /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`.
426    #[inline]
427    #[must_use]
428    pub const fn wrapping_add(self, rhs: Self) -> Self {
429        Self {
430            x: self.x.wrapping_add(rhs.x),
431            y: self.y.wrapping_add(rhs.y),
432            z: self.z.wrapping_add(rhs.z),
433            w: self.w.wrapping_add(rhs.w),
434        }
435    }
436
437    /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
438    ///
439    /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`.
440    #[inline]
441    #[must_use]
442    pub const fn wrapping_sub(self, rhs: Self) -> Self {
443        Self {
444            x: self.x.wrapping_sub(rhs.x),
445            y: self.y.wrapping_sub(rhs.y),
446            z: self.z.wrapping_sub(rhs.z),
447            w: self.w.wrapping_sub(rhs.w),
448        }
449    }
450
451    /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
452    ///
453    /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`.
454    #[inline]
455    #[must_use]
456    pub const fn wrapping_mul(self, rhs: Self) -> Self {
457        Self {
458            x: self.x.wrapping_mul(rhs.x),
459            y: self.y.wrapping_mul(rhs.y),
460            z: self.z.wrapping_mul(rhs.z),
461            w: self.w.wrapping_mul(rhs.w),
462        }
463    }
464
465    /// Returns a vector containing the wrapping division of `self` and `rhs`.
466    ///
467    /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`.
468    #[inline]
469    #[must_use]
470    pub const fn wrapping_div(self, rhs: Self) -> Self {
471        Self {
472            x: self.x.wrapping_div(rhs.x),
473            y: self.y.wrapping_div(rhs.y),
474            z: self.z.wrapping_div(rhs.z),
475            w: self.w.wrapping_div(rhs.w),
476        }
477    }
478
479    /// Returns a vector containing the saturating addition of `self` and `rhs`.
480    ///
481    /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`.
482    #[inline]
483    #[must_use]
484    pub const fn saturating_add(self, rhs: Self) -> Self {
485        Self {
486            x: self.x.saturating_add(rhs.x),
487            y: self.y.saturating_add(rhs.y),
488            z: self.z.saturating_add(rhs.z),
489            w: self.w.saturating_add(rhs.w),
490        }
491    }
492
493    /// Returns a vector containing the saturating subtraction of `self` and `rhs`.
494    ///
495    /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`.
496    #[inline]
497    #[must_use]
498    pub const fn saturating_sub(self, rhs: Self) -> Self {
499        Self {
500            x: self.x.saturating_sub(rhs.x),
501            y: self.y.saturating_sub(rhs.y),
502            z: self.z.saturating_sub(rhs.z),
503            w: self.w.saturating_sub(rhs.w),
504        }
505    }
506
507    /// Returns a vector containing the saturating multiplication of `self` and `rhs`.
508    ///
509    /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`.
510    #[inline]
511    #[must_use]
512    pub const fn saturating_mul(self, rhs: Self) -> Self {
513        Self {
514            x: self.x.saturating_mul(rhs.x),
515            y: self.y.saturating_mul(rhs.y),
516            z: self.z.saturating_mul(rhs.z),
517            w: self.w.saturating_mul(rhs.w),
518        }
519    }
520
521    /// Returns a vector containing the saturating division of `self` and `rhs`.
522    ///
523    /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`.
524    #[inline]
525    #[must_use]
526    pub const fn saturating_div(self, rhs: Self) -> Self {
527        Self {
528            x: self.x.saturating_div(rhs.x),
529            y: self.y.saturating_div(rhs.y),
530            z: self.z.saturating_div(rhs.z),
531            w: self.w.saturating_div(rhs.w),
532        }
533    }
534
535    /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`.
536    ///
537    /// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`.
538    #[inline]
539    #[must_use]
540    pub const fn wrapping_add_signed(self, rhs: I16Vec4) -> Self {
541        Self {
542            x: self.x.wrapping_add_signed(rhs.x),
543            y: self.y.wrapping_add_signed(rhs.y),
544            z: self.z.wrapping_add_signed(rhs.z),
545            w: self.w.wrapping_add_signed(rhs.w),
546        }
547    }
548
549    /// Returns a vector containing the saturating addition of `self` and signed vector `rhs`.
550    ///
551    /// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`.
552    #[inline]
553    #[must_use]
554    pub const fn saturating_add_signed(self, rhs: I16Vec4) -> Self {
555        Self {
556            x: self.x.saturating_add_signed(rhs.x),
557            y: self.y.saturating_add_signed(rhs.y),
558            z: self.z.saturating_add_signed(rhs.z),
559            w: self.w.saturating_add_signed(rhs.w),
560        }
561    }
562}
563
564impl Default for U16Vec4 {
565    #[inline(always)]
566    fn default() -> Self {
567        Self::ZERO
568    }
569}
570
571impl Div<U16Vec4> for U16Vec4 {
572    type Output = Self;
573    #[inline]
574    fn div(self, rhs: Self) -> Self {
575        Self {
576            x: self.x.div(rhs.x),
577            y: self.y.div(rhs.y),
578            z: self.z.div(rhs.z),
579            w: self.w.div(rhs.w),
580        }
581    }
582}
583
584impl DivAssign<U16Vec4> for U16Vec4 {
585    #[inline]
586    fn div_assign(&mut self, rhs: Self) {
587        self.x.div_assign(rhs.x);
588        self.y.div_assign(rhs.y);
589        self.z.div_assign(rhs.z);
590        self.w.div_assign(rhs.w);
591    }
592}
593
594impl Div<u16> for U16Vec4 {
595    type Output = Self;
596    #[inline]
597    fn div(self, rhs: u16) -> Self {
598        Self {
599            x: self.x.div(rhs),
600            y: self.y.div(rhs),
601            z: self.z.div(rhs),
602            w: self.w.div(rhs),
603        }
604    }
605}
606
607impl DivAssign<u16> for U16Vec4 {
608    #[inline]
609    fn div_assign(&mut self, rhs: u16) {
610        self.x.div_assign(rhs);
611        self.y.div_assign(rhs);
612        self.z.div_assign(rhs);
613        self.w.div_assign(rhs);
614    }
615}
616
617impl Div<U16Vec4> for u16 {
618    type Output = U16Vec4;
619    #[inline]
620    fn div(self, rhs: U16Vec4) -> U16Vec4 {
621        U16Vec4 {
622            x: self.div(rhs.x),
623            y: self.div(rhs.y),
624            z: self.div(rhs.z),
625            w: self.div(rhs.w),
626        }
627    }
628}
629
630impl Mul<U16Vec4> for U16Vec4 {
631    type Output = Self;
632    #[inline]
633    fn mul(self, rhs: Self) -> Self {
634        Self {
635            x: self.x.mul(rhs.x),
636            y: self.y.mul(rhs.y),
637            z: self.z.mul(rhs.z),
638            w: self.w.mul(rhs.w),
639        }
640    }
641}
642
643impl MulAssign<U16Vec4> for U16Vec4 {
644    #[inline]
645    fn mul_assign(&mut self, rhs: Self) {
646        self.x.mul_assign(rhs.x);
647        self.y.mul_assign(rhs.y);
648        self.z.mul_assign(rhs.z);
649        self.w.mul_assign(rhs.w);
650    }
651}
652
653impl Mul<u16> for U16Vec4 {
654    type Output = Self;
655    #[inline]
656    fn mul(self, rhs: u16) -> Self {
657        Self {
658            x: self.x.mul(rhs),
659            y: self.y.mul(rhs),
660            z: self.z.mul(rhs),
661            w: self.w.mul(rhs),
662        }
663    }
664}
665
666impl MulAssign<u16> for U16Vec4 {
667    #[inline]
668    fn mul_assign(&mut self, rhs: u16) {
669        self.x.mul_assign(rhs);
670        self.y.mul_assign(rhs);
671        self.z.mul_assign(rhs);
672        self.w.mul_assign(rhs);
673    }
674}
675
676impl Mul<U16Vec4> for u16 {
677    type Output = U16Vec4;
678    #[inline]
679    fn mul(self, rhs: U16Vec4) -> U16Vec4 {
680        U16Vec4 {
681            x: self.mul(rhs.x),
682            y: self.mul(rhs.y),
683            z: self.mul(rhs.z),
684            w: self.mul(rhs.w),
685        }
686    }
687}
688
689impl Add<U16Vec4> for U16Vec4 {
690    type Output = Self;
691    #[inline]
692    fn add(self, rhs: Self) -> Self {
693        Self {
694            x: self.x.add(rhs.x),
695            y: self.y.add(rhs.y),
696            z: self.z.add(rhs.z),
697            w: self.w.add(rhs.w),
698        }
699    }
700}
701
702impl AddAssign<U16Vec4> for U16Vec4 {
703    #[inline]
704    fn add_assign(&mut self, rhs: Self) {
705        self.x.add_assign(rhs.x);
706        self.y.add_assign(rhs.y);
707        self.z.add_assign(rhs.z);
708        self.w.add_assign(rhs.w);
709    }
710}
711
712impl Add<u16> for U16Vec4 {
713    type Output = Self;
714    #[inline]
715    fn add(self, rhs: u16) -> Self {
716        Self {
717            x: self.x.add(rhs),
718            y: self.y.add(rhs),
719            z: self.z.add(rhs),
720            w: self.w.add(rhs),
721        }
722    }
723}
724
725impl AddAssign<u16> for U16Vec4 {
726    #[inline]
727    fn add_assign(&mut self, rhs: u16) {
728        self.x.add_assign(rhs);
729        self.y.add_assign(rhs);
730        self.z.add_assign(rhs);
731        self.w.add_assign(rhs);
732    }
733}
734
735impl Add<U16Vec4> for u16 {
736    type Output = U16Vec4;
737    #[inline]
738    fn add(self, rhs: U16Vec4) -> U16Vec4 {
739        U16Vec4 {
740            x: self.add(rhs.x),
741            y: self.add(rhs.y),
742            z: self.add(rhs.z),
743            w: self.add(rhs.w),
744        }
745    }
746}
747
748impl Sub<U16Vec4> for U16Vec4 {
749    type Output = Self;
750    #[inline]
751    fn sub(self, rhs: Self) -> Self {
752        Self {
753            x: self.x.sub(rhs.x),
754            y: self.y.sub(rhs.y),
755            z: self.z.sub(rhs.z),
756            w: self.w.sub(rhs.w),
757        }
758    }
759}
760
761impl SubAssign<U16Vec4> for U16Vec4 {
762    #[inline]
763    fn sub_assign(&mut self, rhs: U16Vec4) {
764        self.x.sub_assign(rhs.x);
765        self.y.sub_assign(rhs.y);
766        self.z.sub_assign(rhs.z);
767        self.w.sub_assign(rhs.w);
768    }
769}
770
771impl Sub<u16> for U16Vec4 {
772    type Output = Self;
773    #[inline]
774    fn sub(self, rhs: u16) -> Self {
775        Self {
776            x: self.x.sub(rhs),
777            y: self.y.sub(rhs),
778            z: self.z.sub(rhs),
779            w: self.w.sub(rhs),
780        }
781    }
782}
783
784impl SubAssign<u16> for U16Vec4 {
785    #[inline]
786    fn sub_assign(&mut self, rhs: u16) {
787        self.x.sub_assign(rhs);
788        self.y.sub_assign(rhs);
789        self.z.sub_assign(rhs);
790        self.w.sub_assign(rhs);
791    }
792}
793
794impl Sub<U16Vec4> for u16 {
795    type Output = U16Vec4;
796    #[inline]
797    fn sub(self, rhs: U16Vec4) -> U16Vec4 {
798        U16Vec4 {
799            x: self.sub(rhs.x),
800            y: self.sub(rhs.y),
801            z: self.sub(rhs.z),
802            w: self.sub(rhs.w),
803        }
804    }
805}
806
807impl Rem<U16Vec4> for U16Vec4 {
808    type Output = Self;
809    #[inline]
810    fn rem(self, rhs: Self) -> Self {
811        Self {
812            x: self.x.rem(rhs.x),
813            y: self.y.rem(rhs.y),
814            z: self.z.rem(rhs.z),
815            w: self.w.rem(rhs.w),
816        }
817    }
818}
819
820impl RemAssign<U16Vec4> for U16Vec4 {
821    #[inline]
822    fn rem_assign(&mut self, rhs: Self) {
823        self.x.rem_assign(rhs.x);
824        self.y.rem_assign(rhs.y);
825        self.z.rem_assign(rhs.z);
826        self.w.rem_assign(rhs.w);
827    }
828}
829
830impl Rem<u16> for U16Vec4 {
831    type Output = Self;
832    #[inline]
833    fn rem(self, rhs: u16) -> Self {
834        Self {
835            x: self.x.rem(rhs),
836            y: self.y.rem(rhs),
837            z: self.z.rem(rhs),
838            w: self.w.rem(rhs),
839        }
840    }
841}
842
843impl RemAssign<u16> for U16Vec4 {
844    #[inline]
845    fn rem_assign(&mut self, rhs: u16) {
846        self.x.rem_assign(rhs);
847        self.y.rem_assign(rhs);
848        self.z.rem_assign(rhs);
849        self.w.rem_assign(rhs);
850    }
851}
852
853impl Rem<U16Vec4> for u16 {
854    type Output = U16Vec4;
855    #[inline]
856    fn rem(self, rhs: U16Vec4) -> U16Vec4 {
857        U16Vec4 {
858            x: self.rem(rhs.x),
859            y: self.rem(rhs.y),
860            z: self.rem(rhs.z),
861            w: self.rem(rhs.w),
862        }
863    }
864}
865
866#[cfg(not(target_arch = "spirv"))]
867impl AsRef<[u16; 4]> for U16Vec4 {
868    #[inline]
869    fn as_ref(&self) -> &[u16; 4] {
870        unsafe { &*(self as *const U16Vec4 as *const [u16; 4]) }
871    }
872}
873
874#[cfg(not(target_arch = "spirv"))]
875impl AsMut<[u16; 4]> for U16Vec4 {
876    #[inline]
877    fn as_mut(&mut self) -> &mut [u16; 4] {
878        unsafe { &mut *(self as *mut U16Vec4 as *mut [u16; 4]) }
879    }
880}
881
882impl Sum for U16Vec4 {
883    #[inline]
884    fn sum<I>(iter: I) -> Self
885    where
886        I: Iterator<Item = Self>,
887    {
888        iter.fold(Self::ZERO, Self::add)
889    }
890}
891
892impl<'a> Sum<&'a Self> for U16Vec4 {
893    #[inline]
894    fn sum<I>(iter: I) -> Self
895    where
896        I: Iterator<Item = &'a Self>,
897    {
898        iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
899    }
900}
901
902impl Product for U16Vec4 {
903    #[inline]
904    fn product<I>(iter: I) -> Self
905    where
906        I: Iterator<Item = Self>,
907    {
908        iter.fold(Self::ONE, Self::mul)
909    }
910}
911
912impl<'a> Product<&'a Self> for U16Vec4 {
913    #[inline]
914    fn product<I>(iter: I) -> Self
915    where
916        I: Iterator<Item = &'a Self>,
917    {
918        iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
919    }
920}
921
922impl Not for U16Vec4 {
923    type Output = Self;
924    #[inline]
925    fn not(self) -> Self::Output {
926        Self {
927            x: self.x.not(),
928            y: self.y.not(),
929            z: self.z.not(),
930            w: self.w.not(),
931        }
932    }
933}
934
935impl BitAnd for U16Vec4 {
936    type Output = Self;
937    #[inline]
938    fn bitand(self, rhs: Self) -> Self::Output {
939        Self {
940            x: self.x.bitand(rhs.x),
941            y: self.y.bitand(rhs.y),
942            z: self.z.bitand(rhs.z),
943            w: self.w.bitand(rhs.w),
944        }
945    }
946}
947
948impl BitOr for U16Vec4 {
949    type Output = Self;
950    #[inline]
951    fn bitor(self, rhs: Self) -> Self::Output {
952        Self {
953            x: self.x.bitor(rhs.x),
954            y: self.y.bitor(rhs.y),
955            z: self.z.bitor(rhs.z),
956            w: self.w.bitor(rhs.w),
957        }
958    }
959}
960
961impl BitXor for U16Vec4 {
962    type Output = Self;
963    #[inline]
964    fn bitxor(self, rhs: Self) -> Self::Output {
965        Self {
966            x: self.x.bitxor(rhs.x),
967            y: self.y.bitxor(rhs.y),
968            z: self.z.bitxor(rhs.z),
969            w: self.w.bitxor(rhs.w),
970        }
971    }
972}
973
974impl BitAnd<u16> for U16Vec4 {
975    type Output = Self;
976    #[inline]
977    fn bitand(self, rhs: u16) -> Self::Output {
978        Self {
979            x: self.x.bitand(rhs),
980            y: self.y.bitand(rhs),
981            z: self.z.bitand(rhs),
982            w: self.w.bitand(rhs),
983        }
984    }
985}
986
987impl BitOr<u16> for U16Vec4 {
988    type Output = Self;
989    #[inline]
990    fn bitor(self, rhs: u16) -> Self::Output {
991        Self {
992            x: self.x.bitor(rhs),
993            y: self.y.bitor(rhs),
994            z: self.z.bitor(rhs),
995            w: self.w.bitor(rhs),
996        }
997    }
998}
999
1000impl BitXor<u16> for U16Vec4 {
1001    type Output = Self;
1002    #[inline]
1003    fn bitxor(self, rhs: u16) -> Self::Output {
1004        Self {
1005            x: self.x.bitxor(rhs),
1006            y: self.y.bitxor(rhs),
1007            z: self.z.bitxor(rhs),
1008            w: self.w.bitxor(rhs),
1009        }
1010    }
1011}
1012
1013impl Shl<i8> for U16Vec4 {
1014    type Output = Self;
1015    #[inline]
1016    fn shl(self, rhs: i8) -> Self::Output {
1017        Self {
1018            x: self.x.shl(rhs),
1019            y: self.y.shl(rhs),
1020            z: self.z.shl(rhs),
1021            w: self.w.shl(rhs),
1022        }
1023    }
1024}
1025
1026impl Shr<i8> for U16Vec4 {
1027    type Output = Self;
1028    #[inline]
1029    fn shr(self, rhs: i8) -> Self::Output {
1030        Self {
1031            x: self.x.shr(rhs),
1032            y: self.y.shr(rhs),
1033            z: self.z.shr(rhs),
1034            w: self.w.shr(rhs),
1035        }
1036    }
1037}
1038
1039impl Shl<i16> for U16Vec4 {
1040    type Output = Self;
1041    #[inline]
1042    fn shl(self, rhs: i16) -> Self::Output {
1043        Self {
1044            x: self.x.shl(rhs),
1045            y: self.y.shl(rhs),
1046            z: self.z.shl(rhs),
1047            w: self.w.shl(rhs),
1048        }
1049    }
1050}
1051
1052impl Shr<i16> for U16Vec4 {
1053    type Output = Self;
1054    #[inline]
1055    fn shr(self, rhs: i16) -> Self::Output {
1056        Self {
1057            x: self.x.shr(rhs),
1058            y: self.y.shr(rhs),
1059            z: self.z.shr(rhs),
1060            w: self.w.shr(rhs),
1061        }
1062    }
1063}
1064
1065impl Shl<i32> for U16Vec4 {
1066    type Output = Self;
1067    #[inline]
1068    fn shl(self, rhs: i32) -> Self::Output {
1069        Self {
1070            x: self.x.shl(rhs),
1071            y: self.y.shl(rhs),
1072            z: self.z.shl(rhs),
1073            w: self.w.shl(rhs),
1074        }
1075    }
1076}
1077
1078impl Shr<i32> for U16Vec4 {
1079    type Output = Self;
1080    #[inline]
1081    fn shr(self, rhs: i32) -> Self::Output {
1082        Self {
1083            x: self.x.shr(rhs),
1084            y: self.y.shr(rhs),
1085            z: self.z.shr(rhs),
1086            w: self.w.shr(rhs),
1087        }
1088    }
1089}
1090
1091impl Shl<i64> for U16Vec4 {
1092    type Output = Self;
1093    #[inline]
1094    fn shl(self, rhs: i64) -> Self::Output {
1095        Self {
1096            x: self.x.shl(rhs),
1097            y: self.y.shl(rhs),
1098            z: self.z.shl(rhs),
1099            w: self.w.shl(rhs),
1100        }
1101    }
1102}
1103
1104impl Shr<i64> for U16Vec4 {
1105    type Output = Self;
1106    #[inline]
1107    fn shr(self, rhs: i64) -> Self::Output {
1108        Self {
1109            x: self.x.shr(rhs),
1110            y: self.y.shr(rhs),
1111            z: self.z.shr(rhs),
1112            w: self.w.shr(rhs),
1113        }
1114    }
1115}
1116
1117impl Shl<u8> for U16Vec4 {
1118    type Output = Self;
1119    #[inline]
1120    fn shl(self, rhs: u8) -> Self::Output {
1121        Self {
1122            x: self.x.shl(rhs),
1123            y: self.y.shl(rhs),
1124            z: self.z.shl(rhs),
1125            w: self.w.shl(rhs),
1126        }
1127    }
1128}
1129
1130impl Shr<u8> for U16Vec4 {
1131    type Output = Self;
1132    #[inline]
1133    fn shr(self, rhs: u8) -> Self::Output {
1134        Self {
1135            x: self.x.shr(rhs),
1136            y: self.y.shr(rhs),
1137            z: self.z.shr(rhs),
1138            w: self.w.shr(rhs),
1139        }
1140    }
1141}
1142
1143impl Shl<u16> for U16Vec4 {
1144    type Output = Self;
1145    #[inline]
1146    fn shl(self, rhs: u16) -> Self::Output {
1147        Self {
1148            x: self.x.shl(rhs),
1149            y: self.y.shl(rhs),
1150            z: self.z.shl(rhs),
1151            w: self.w.shl(rhs),
1152        }
1153    }
1154}
1155
1156impl Shr<u16> for U16Vec4 {
1157    type Output = Self;
1158    #[inline]
1159    fn shr(self, rhs: u16) -> Self::Output {
1160        Self {
1161            x: self.x.shr(rhs),
1162            y: self.y.shr(rhs),
1163            z: self.z.shr(rhs),
1164            w: self.w.shr(rhs),
1165        }
1166    }
1167}
1168
1169impl Shl<u32> for U16Vec4 {
1170    type Output = Self;
1171    #[inline]
1172    fn shl(self, rhs: u32) -> Self::Output {
1173        Self {
1174            x: self.x.shl(rhs),
1175            y: self.y.shl(rhs),
1176            z: self.z.shl(rhs),
1177            w: self.w.shl(rhs),
1178        }
1179    }
1180}
1181
1182impl Shr<u32> for U16Vec4 {
1183    type Output = Self;
1184    #[inline]
1185    fn shr(self, rhs: u32) -> Self::Output {
1186        Self {
1187            x: self.x.shr(rhs),
1188            y: self.y.shr(rhs),
1189            z: self.z.shr(rhs),
1190            w: self.w.shr(rhs),
1191        }
1192    }
1193}
1194
1195impl Shl<u64> for U16Vec4 {
1196    type Output = Self;
1197    #[inline]
1198    fn shl(self, rhs: u64) -> Self::Output {
1199        Self {
1200            x: self.x.shl(rhs),
1201            y: self.y.shl(rhs),
1202            z: self.z.shl(rhs),
1203            w: self.w.shl(rhs),
1204        }
1205    }
1206}
1207
1208impl Shr<u64> for U16Vec4 {
1209    type Output = Self;
1210    #[inline]
1211    fn shr(self, rhs: u64) -> Self::Output {
1212        Self {
1213            x: self.x.shr(rhs),
1214            y: self.y.shr(rhs),
1215            z: self.z.shr(rhs),
1216            w: self.w.shr(rhs),
1217        }
1218    }
1219}
1220
1221impl Shl<crate::IVec4> for U16Vec4 {
1222    type Output = Self;
1223    #[inline]
1224    fn shl(self, rhs: crate::IVec4) -> Self::Output {
1225        Self {
1226            x: self.x.shl(rhs.x),
1227            y: self.y.shl(rhs.y),
1228            z: self.z.shl(rhs.z),
1229            w: self.w.shl(rhs.w),
1230        }
1231    }
1232}
1233
1234impl Shr<crate::IVec4> for U16Vec4 {
1235    type Output = Self;
1236    #[inline]
1237    fn shr(self, rhs: crate::IVec4) -> Self::Output {
1238        Self {
1239            x: self.x.shr(rhs.x),
1240            y: self.y.shr(rhs.y),
1241            z: self.z.shr(rhs.z),
1242            w: self.w.shr(rhs.w),
1243        }
1244    }
1245}
1246
1247impl Shl<crate::UVec4> for U16Vec4 {
1248    type Output = Self;
1249    #[inline]
1250    fn shl(self, rhs: crate::UVec4) -> Self::Output {
1251        Self {
1252            x: self.x.shl(rhs.x),
1253            y: self.y.shl(rhs.y),
1254            z: self.z.shl(rhs.z),
1255            w: self.w.shl(rhs.w),
1256        }
1257    }
1258}
1259
1260impl Shr<crate::UVec4> for U16Vec4 {
1261    type Output = Self;
1262    #[inline]
1263    fn shr(self, rhs: crate::UVec4) -> Self::Output {
1264        Self {
1265            x: self.x.shr(rhs.x),
1266            y: self.y.shr(rhs.y),
1267            z: self.z.shr(rhs.z),
1268            w: self.w.shr(rhs.w),
1269        }
1270    }
1271}
1272
1273impl Index<usize> for U16Vec4 {
1274    type Output = u16;
1275    #[inline]
1276    fn index(&self, index: usize) -> &Self::Output {
1277        match index {
1278            0 => &self.x,
1279            1 => &self.y,
1280            2 => &self.z,
1281            3 => &self.w,
1282            _ => panic!("index out of bounds"),
1283        }
1284    }
1285}
1286
1287impl IndexMut<usize> for U16Vec4 {
1288    #[inline]
1289    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1290        match index {
1291            0 => &mut self.x,
1292            1 => &mut self.y,
1293            2 => &mut self.z,
1294            3 => &mut self.w,
1295            _ => panic!("index out of bounds"),
1296        }
1297    }
1298}
1299
1300#[cfg(not(target_arch = "spirv"))]
1301impl fmt::Display for U16Vec4 {
1302    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1303        write!(f, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w)
1304    }
1305}
1306
1307#[cfg(not(target_arch = "spirv"))]
1308impl fmt::Debug for U16Vec4 {
1309    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1310        fmt.debug_tuple(stringify!(U16Vec4))
1311            .field(&self.x)
1312            .field(&self.y)
1313            .field(&self.z)
1314            .field(&self.w)
1315            .finish()
1316    }
1317}
1318
1319impl From<[u16; 4]> for U16Vec4 {
1320    #[inline]
1321    fn from(a: [u16; 4]) -> Self {
1322        Self::new(a[0], a[1], a[2], a[3])
1323    }
1324}
1325
1326impl From<U16Vec4> for [u16; 4] {
1327    #[inline]
1328    fn from(v: U16Vec4) -> Self {
1329        [v.x, v.y, v.z, v.w]
1330    }
1331}
1332
1333impl From<(u16, u16, u16, u16)> for U16Vec4 {
1334    #[inline]
1335    fn from(t: (u16, u16, u16, u16)) -> Self {
1336        Self::new(t.0, t.1, t.2, t.3)
1337    }
1338}
1339
1340impl From<U16Vec4> for (u16, u16, u16, u16) {
1341    #[inline]
1342    fn from(v: U16Vec4) -> Self {
1343        (v.x, v.y, v.z, v.w)
1344    }
1345}
1346
1347impl From<(U16Vec3, u16)> for U16Vec4 {
1348    #[inline]
1349    fn from((v, w): (U16Vec3, u16)) -> Self {
1350        Self::new(v.x, v.y, v.z, w)
1351    }
1352}
1353
1354impl From<(u16, U16Vec3)> for U16Vec4 {
1355    #[inline]
1356    fn from((x, v): (u16, U16Vec3)) -> Self {
1357        Self::new(x, v.x, v.y, v.z)
1358    }
1359}
1360
1361impl From<(U16Vec2, u16, u16)> for U16Vec4 {
1362    #[inline]
1363    fn from((v, z, w): (U16Vec2, u16, u16)) -> Self {
1364        Self::new(v.x, v.y, z, w)
1365    }
1366}
1367
1368impl From<(U16Vec2, U16Vec2)> for U16Vec4 {
1369    #[inline]
1370    fn from((v, u): (U16Vec2, U16Vec2)) -> Self {
1371        Self::new(v.x, v.y, u.x, u.y)
1372    }
1373}
1374
1375impl TryFrom<I16Vec4> for U16Vec4 {
1376    type Error = core::num::TryFromIntError;
1377
1378    #[inline]
1379    fn try_from(v: I16Vec4) -> Result<Self, Self::Error> {
1380        Ok(Self::new(
1381            u16::try_from(v.x)?,
1382            u16::try_from(v.y)?,
1383            u16::try_from(v.z)?,
1384            u16::try_from(v.w)?,
1385        ))
1386    }
1387}
1388
1389impl TryFrom<IVec4> for U16Vec4 {
1390    type Error = core::num::TryFromIntError;
1391
1392    #[inline]
1393    fn try_from(v: IVec4) -> Result<Self, Self::Error> {
1394        Ok(Self::new(
1395            u16::try_from(v.x)?,
1396            u16::try_from(v.y)?,
1397            u16::try_from(v.z)?,
1398            u16::try_from(v.w)?,
1399        ))
1400    }
1401}
1402
1403impl TryFrom<UVec4> for U16Vec4 {
1404    type Error = core::num::TryFromIntError;
1405
1406    #[inline]
1407    fn try_from(v: UVec4) -> Result<Self, Self::Error> {
1408        Ok(Self::new(
1409            u16::try_from(v.x)?,
1410            u16::try_from(v.y)?,
1411            u16::try_from(v.z)?,
1412            u16::try_from(v.w)?,
1413        ))
1414    }
1415}
1416
1417impl TryFrom<I64Vec4> for U16Vec4 {
1418    type Error = core::num::TryFromIntError;
1419
1420    #[inline]
1421    fn try_from(v: I64Vec4) -> Result<Self, Self::Error> {
1422        Ok(Self::new(
1423            u16::try_from(v.x)?,
1424            u16::try_from(v.y)?,
1425            u16::try_from(v.z)?,
1426            u16::try_from(v.w)?,
1427        ))
1428    }
1429}
1430
1431impl TryFrom<U64Vec4> for U16Vec4 {
1432    type Error = core::num::TryFromIntError;
1433
1434    #[inline]
1435    fn try_from(v: U64Vec4) -> Result<Self, Self::Error> {
1436        Ok(Self::new(
1437            u16::try_from(v.x)?,
1438            u16::try_from(v.y)?,
1439            u16::try_from(v.z)?,
1440            u16::try_from(v.w)?,
1441        ))
1442    }
1443}
1444
1445impl From<BVec4> for U16Vec4 {
1446    #[inline]
1447    fn from(v: BVec4) -> Self {
1448        Self::new(
1449            u16::from(v.x),
1450            u16::from(v.y),
1451            u16::from(v.z),
1452            u16::from(v.w),
1453        )
1454    }
1455}
1456
1457#[cfg(not(feature = "scalar-math"))]
1458
1459impl From<BVec4A> for U16Vec4 {
1460    #[inline]
1461    fn from(v: BVec4A) -> Self {
1462        let bool_array: [bool; 4] = v.into();
1463        Self::new(
1464            u16::from(bool_array[0]),
1465            u16::from(bool_array[1]),
1466            u16::from(bool_array[2]),
1467            u16::from(bool_array[3]),
1468        )
1469    }
1470}