glam/i16/
i16vec2.rs

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