glam/i16/
i16vec4.rs

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