glam/u16/
u16vec2.rs

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