glam/i32/
ivec2.rs

1// Generated from vec.rs.tera template. Edit the template, not the generated file.
2
3use crate::{BVec2, I16Vec2, I64Vec2, I8Vec2, IVec3, U16Vec2, U64Vec2, U8Vec2, USizeVec2, UVec2};
4
5use core::fmt;
6use core::iter::{Product, Sum};
7use core::{f32, ops::*};
8
9/// Creates a 2-dimensional vector.
10#[inline(always)]
11#[must_use]
12pub const fn ivec2(x: i32, y: i32) -> IVec2 {
13    IVec2::new(x, y)
14}
15
16/// A 2-dimensional vector.
17#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
18#[derive(Clone, Copy, PartialEq, Eq)]
19#[cfg_attr(feature = "cuda", repr(align(8)))]
20#[cfg_attr(not(target_arch = "spirv"), repr(C))]
21#[cfg_attr(target_arch = "spirv", repr(simd))]
22pub struct IVec2 {
23    pub x: i32,
24    pub y: i32,
25}
26
27impl IVec2 {
28    /// All zeroes.
29    pub const ZERO: Self = Self::splat(0);
30
31    /// All ones.
32    pub const ONE: Self = Self::splat(1);
33
34    /// All negative ones.
35    pub const NEG_ONE: Self = Self::splat(-1);
36
37    /// All `i32::MIN`.
38    pub const MIN: Self = Self::splat(i32::MIN);
39
40    /// All `i32::MAX`.
41    pub const MAX: Self = Self::splat(i32::MAX);
42
43    /// A unit vector pointing along the positive X axis.
44    pub const X: Self = Self::new(1, 0);
45
46    /// A unit vector pointing along the positive Y axis.
47    pub const Y: Self = Self::new(0, 1);
48
49    /// A unit vector pointing along the negative X axis.
50    pub const NEG_X: Self = Self::new(-1, 0);
51
52    /// A unit vector pointing along the negative Y axis.
53    pub const NEG_Y: Self = Self::new(0, -1);
54
55    /// The unit axes.
56    pub const AXES: [Self; 2] = [Self::X, Self::Y];
57
58    /// Creates a new vector.
59    #[inline(always)]
60    #[must_use]
61    pub const fn new(x: i32, y: i32) -> Self {
62        Self { x, y }
63    }
64
65    /// Creates a vector with all elements set to `v`.
66    #[inline]
67    #[must_use]
68    pub const fn splat(v: i32) -> Self {
69        Self { x: v, y: v }
70    }
71
72    /// Returns a vector containing each element of `self` modified by a mapping function `f`.
73    #[inline]
74    #[must_use]
75    pub fn map<F>(self, f: F) -> Self
76    where
77        F: Fn(i32) -> i32,
78    {
79        Self::new(f(self.x), f(self.y))
80    }
81
82    /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
83    /// for each element of `self`.
84    ///
85    /// A true element in the mask uses the corresponding element from `if_true`, and false
86    /// uses the element from `if_false`.
87    #[inline]
88    #[must_use]
89    pub fn select(mask: BVec2, if_true: Self, if_false: Self) -> Self {
90        Self {
91            x: if mask.test(0) { if_true.x } else { if_false.x },
92            y: if mask.test(1) { if_true.y } else { if_false.y },
93        }
94    }
95
96    /// Creates a new vector from an array.
97    #[inline]
98    #[must_use]
99    pub const fn from_array(a: [i32; 2]) -> Self {
100        Self::new(a[0], a[1])
101    }
102
103    /// `[x, y]`
104    #[inline]
105    #[must_use]
106    pub const fn to_array(&self) -> [i32; 2] {
107        [self.x, self.y]
108    }
109
110    /// Creates a vector from the first 2 values in `slice`.
111    ///
112    /// # Panics
113    ///
114    /// Panics if `slice` is less than 2 elements long.
115    #[inline]
116    #[must_use]
117    pub const fn from_slice(slice: &[i32]) -> Self {
118        assert!(slice.len() >= 2);
119        Self::new(slice[0], slice[1])
120    }
121
122    /// Writes the elements of `self` to the first 2 elements in `slice`.
123    ///
124    /// # Panics
125    ///
126    /// Panics if `slice` is less than 2 elements long.
127    #[inline]
128    pub fn write_to_slice(self, slice: &mut [i32]) {
129        slice[..2].copy_from_slice(&self.to_array());
130    }
131
132    /// Creates a 3D vector from `self` and the given `z` value.
133    #[inline]
134    #[must_use]
135    pub const fn extend(self, z: i32) -> IVec3 {
136        IVec3::new(self.x, self.y, z)
137    }
138
139    /// Creates a 2D vector from `self` with the given value of `x`.
140    #[inline]
141    #[must_use]
142    pub fn with_x(mut self, x: i32) -> Self {
143        self.x = x;
144        self
145    }
146
147    /// Creates a 2D vector from `self` with the given value of `y`.
148    #[inline]
149    #[must_use]
150    pub fn with_y(mut self, y: i32) -> Self {
151        self.y = y;
152        self
153    }
154
155    /// Computes the dot product of `self` and `rhs`.
156    #[inline]
157    #[must_use]
158    pub fn dot(self, rhs: Self) -> i32 {
159        (self.x * rhs.x) + (self.y * rhs.y)
160    }
161
162    /// Returns a vector where every component is the dot product of `self` and `rhs`.
163    #[inline]
164    #[must_use]
165    pub fn dot_into_vec(self, rhs: Self) -> Self {
166        Self::splat(self.dot(rhs))
167    }
168
169    /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
170    ///
171    /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
172    #[inline]
173    #[must_use]
174    pub fn min(self, rhs: Self) -> Self {
175        Self {
176            x: self.x.min(rhs.x),
177            y: self.y.min(rhs.y),
178        }
179    }
180
181    /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
182    ///
183    /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
184    #[inline]
185    #[must_use]
186    pub fn max(self, rhs: Self) -> Self {
187        Self {
188            x: self.x.max(rhs.x),
189            y: self.y.max(rhs.y),
190        }
191    }
192
193    /// Component-wise clamping of values, similar to [`i32::clamp`].
194    ///
195    /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
196    ///
197    /// # Panics
198    ///
199    /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
200    #[inline]
201    #[must_use]
202    pub fn clamp(self, min: Self, max: Self) -> Self {
203        glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
204        self.max(min).min(max)
205    }
206
207    /// Returns the horizontal minimum of `self`.
208    ///
209    /// In other words this computes `min(x, y, ..)`.
210    #[inline]
211    #[must_use]
212    pub fn min_element(self) -> i32 {
213        self.x.min(self.y)
214    }
215
216    /// Returns the horizontal maximum of `self`.
217    ///
218    /// In other words this computes `max(x, y, ..)`.
219    #[inline]
220    #[must_use]
221    pub fn max_element(self) -> i32 {
222        self.x.max(self.y)
223    }
224
225    /// Returns the index of the first minimum element of `self`.
226    #[doc(alias = "argmin")]
227    #[inline]
228    #[must_use]
229    pub fn min_position(self) -> usize {
230        if self.x <= self.y {
231            0
232        } else {
233            1
234        }
235    }
236
237    /// Returns the index of the first maximum element of `self`.
238    #[doc(alias = "argmax")]
239    #[inline]
240    #[must_use]
241    pub fn max_position(self) -> usize {
242        if self.x >= self.y {
243            0
244        } else {
245            1
246        }
247    }
248
249    /// Returns the sum of all elements of `self`.
250    ///
251    /// In other words, this computes `self.x + self.y + ..`.
252    #[inline]
253    #[must_use]
254    pub fn element_sum(self) -> i32 {
255        self.x + self.y
256    }
257
258    /// Returns the product of all elements of `self`.
259    ///
260    /// In other words, this computes `self.x * self.y * ..`.
261    #[inline]
262    #[must_use]
263    pub fn element_product(self) -> i32 {
264        self.x * self.y
265    }
266
267    /// Returns a vector mask containing the result of a `==` comparison for each element of
268    /// `self` and `rhs`.
269    ///
270    /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
271    /// elements.
272    #[inline]
273    #[must_use]
274    pub fn cmpeq(self, rhs: Self) -> BVec2 {
275        BVec2::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y))
276    }
277
278    /// Returns a vector mask containing the result of a `!=` comparison for each element of
279    /// `self` and `rhs`.
280    ///
281    /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
282    /// elements.
283    #[inline]
284    #[must_use]
285    pub fn cmpne(self, rhs: Self) -> BVec2 {
286        BVec2::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y))
287    }
288
289    /// Returns a vector mask containing the result of a `>=` comparison for each element of
290    /// `self` and `rhs`.
291    ///
292    /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
293    /// elements.
294    #[inline]
295    #[must_use]
296    pub fn cmpge(self, rhs: Self) -> BVec2 {
297        BVec2::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y))
298    }
299
300    /// Returns a vector mask containing the result of a `>` comparison for each element of
301    /// `self` and `rhs`.
302    ///
303    /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
304    /// elements.
305    #[inline]
306    #[must_use]
307    pub fn cmpgt(self, rhs: Self) -> BVec2 {
308        BVec2::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y))
309    }
310
311    /// Returns a vector mask containing the result of a `<=` comparison for each element of
312    /// `self` and `rhs`.
313    ///
314    /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
315    /// elements.
316    #[inline]
317    #[must_use]
318    pub fn cmple(self, rhs: Self) -> BVec2 {
319        BVec2::new(self.x.le(&rhs.x), self.y.le(&rhs.y))
320    }
321
322    /// Returns a vector mask containing the result of a `<` comparison for each element of
323    /// `self` and `rhs`.
324    ///
325    /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
326    /// elements.
327    #[inline]
328    #[must_use]
329    pub fn cmplt(self, rhs: Self) -> BVec2 {
330        BVec2::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y))
331    }
332
333    /// Returns a vector containing the absolute value of each element of `self`.
334    #[inline]
335    #[must_use]
336    pub fn abs(self) -> Self {
337        Self {
338            x: self.x.abs(),
339            y: self.y.abs(),
340        }
341    }
342
343    /// Returns a vector with elements representing the sign of `self`.
344    ///
345    ///  - `0` if the number is zero
346    ///  - `1` if the number is positive
347    ///  - `-1` if the number is negative
348    #[inline]
349    #[must_use]
350    pub fn signum(self) -> Self {
351        Self {
352            x: self.x.signum(),
353            y: self.y.signum(),
354        }
355    }
356
357    /// Returns a bitmask with the lowest 2 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) | ((self.y.is_negative() as u32) << 1)
365    }
366
367    /// Computes the squared length of `self`.
368    #[doc(alias = "magnitude2")]
369    #[inline]
370    #[must_use]
371    pub fn length_squared(self) -> i32 {
372        self.dot(self)
373    }
374
375    /// Compute the squared euclidean distance between two points in space.
376    #[inline]
377    #[must_use]
378    pub fn distance_squared(self, rhs: Self) -> i32 {
379        (self - rhs).length_squared()
380    }
381
382    /// Returns the element-wise quotient of [Euclidean division] of `self` by `rhs`.
383    ///
384    /// # Panics
385    /// This function will panic if any `rhs` element is 0 or the division results in overflow.
386    #[inline]
387    #[must_use]
388    pub fn div_euclid(self, rhs: Self) -> Self {
389        Self::new(self.x.div_euclid(rhs.x), self.y.div_euclid(rhs.y))
390    }
391
392    /// Returns the element-wise remainder of [Euclidean division] of `self` by `rhs`.
393    ///
394    /// # Panics
395    /// This function will panic if any `rhs` element is 0 or the division results in overflow.
396    ///
397    /// [Euclidean division]: i32::rem_euclid
398    #[inline]
399    #[must_use]
400    pub fn rem_euclid(self, rhs: Self) -> Self {
401        Self::new(self.x.rem_euclid(rhs.x), self.y.rem_euclid(rhs.y))
402    }
403
404    /// Computes the [manhattan distance] between two points.
405    ///
406    /// # Overflow
407    /// This method may overflow if the result is greater than [`u32::MAX`].
408    ///
409    /// See also [`checked_manhattan_distance`][IVec2::checked_manhattan_distance].
410    ///
411    /// [manhattan distance]: https://en.wikipedia.org/wiki/Taxicab_geometry
412    #[inline]
413    #[must_use]
414    pub fn manhattan_distance(self, other: Self) -> u32 {
415        self.x.abs_diff(other.x) + self.y.abs_diff(other.y)
416    }
417
418    /// Computes the [manhattan distance] between two points.
419    ///
420    /// This will returns [`None`] if the result is greater than [`u32::MAX`].
421    ///
422    /// [manhattan distance]: https://en.wikipedia.org/wiki/Taxicab_geometry
423    #[inline]
424    #[must_use]
425    pub fn checked_manhattan_distance(self, other: Self) -> Option<u32> {
426        let d = self.x.abs_diff(other.x);
427        d.checked_add(self.y.abs_diff(other.y))
428    }
429
430    /// Computes the [chebyshev distance] between two points.
431    ///
432    /// [chebyshev distance]: https://en.wikipedia.org/wiki/Chebyshev_distance
433    #[inline]
434    #[must_use]
435    pub fn chebyshev_distance(self, other: Self) -> u32 {
436        // Note: the compiler will eventually optimize out the loop
437        [self.x.abs_diff(other.x), self.y.abs_diff(other.y)]
438            .into_iter()
439            .max()
440            .unwrap()
441    }
442
443    /// Returns a vector that is equal to `self` rotated by 90 degrees.
444    #[inline]
445    #[must_use]
446    pub fn perp(self) -> Self {
447        Self {
448            x: -self.y,
449            y: self.x,
450        }
451    }
452
453    /// The perpendicular dot product of `self` and `rhs`.
454    /// Also known as the wedge product, 2D cross product, and determinant.
455    #[doc(alias = "wedge")]
456    #[doc(alias = "cross")]
457    #[doc(alias = "determinant")]
458    #[inline]
459    #[must_use]
460    pub fn perp_dot(self, rhs: Self) -> i32 {
461        (self.x * rhs.y) - (self.y * rhs.x)
462    }
463
464    /// Returns `rhs` rotated by the angle of `self`. If `self` is normalized,
465    /// then this just rotation. This is what you usually want. Otherwise,
466    /// it will be like a rotation with a multiplication by `self`'s length.
467    #[inline]
468    #[must_use]
469    pub fn rotate(self, rhs: Self) -> Self {
470        Self {
471            x: self.x * rhs.x - self.y * rhs.y,
472            y: self.y * rhs.x + self.x * rhs.y,
473        }
474    }
475
476    /// Casts all elements of `self` to `f32`.
477    #[inline]
478    #[must_use]
479    pub fn as_vec2(&self) -> crate::Vec2 {
480        crate::Vec2::new(self.x as f32, self.y as f32)
481    }
482
483    /// Casts all elements of `self` to `f64`.
484    #[inline]
485    #[must_use]
486    pub fn as_dvec2(&self) -> crate::DVec2 {
487        crate::DVec2::new(self.x as f64, self.y as f64)
488    }
489
490    /// Casts all elements of `self` to `i8`.
491    #[inline]
492    #[must_use]
493    pub fn as_i8vec2(&self) -> crate::I8Vec2 {
494        crate::I8Vec2::new(self.x as i8, self.y as i8)
495    }
496
497    /// Casts all elements of `self` to `u8`.
498    #[inline]
499    #[must_use]
500    pub fn as_u8vec2(&self) -> crate::U8Vec2 {
501        crate::U8Vec2::new(self.x as u8, self.y as u8)
502    }
503
504    /// Casts all elements of `self` to `i16`.
505    #[inline]
506    #[must_use]
507    pub fn as_i16vec2(&self) -> crate::I16Vec2 {
508        crate::I16Vec2::new(self.x as i16, self.y as i16)
509    }
510
511    /// Casts all elements of `self` to `u16`.
512    #[inline]
513    #[must_use]
514    pub fn as_u16vec2(&self) -> crate::U16Vec2 {
515        crate::U16Vec2::new(self.x as u16, self.y as u16)
516    }
517
518    /// Casts all elements of `self` to `u32`.
519    #[inline]
520    #[must_use]
521    pub fn as_uvec2(&self) -> crate::UVec2 {
522        crate::UVec2::new(self.x as u32, self.y as u32)
523    }
524
525    /// Casts all elements of `self` to `i64`.
526    #[inline]
527    #[must_use]
528    pub fn as_i64vec2(&self) -> crate::I64Vec2 {
529        crate::I64Vec2::new(self.x as i64, self.y as i64)
530    }
531
532    /// Casts all elements of `self` to `u64`.
533    #[inline]
534    #[must_use]
535    pub fn as_u64vec2(&self) -> crate::U64Vec2 {
536        crate::U64Vec2::new(self.x as u64, self.y as u64)
537    }
538
539    /// Casts all elements of `self` to `usize`.
540    #[inline]
541    #[must_use]
542    pub fn as_usizevec2(&self) -> crate::USizeVec2 {
543        crate::USizeVec2::new(self.x as usize, self.y as usize)
544    }
545
546    /// Returns a vector containing the wrapping addition of `self` and `rhs`.
547    ///
548    /// In other words this computes `Some([self.x + rhs.x, self.y + rhs.y, ..])` but returns `None` on any overflow.
549    #[inline]
550    #[must_use]
551    pub const fn checked_add(self, rhs: Self) -> Option<Self> {
552        let x = match self.x.checked_add(rhs.x) {
553            Some(v) => v,
554            None => return None,
555        };
556        let y = match self.y.checked_add(rhs.y) {
557            Some(v) => v,
558            None => return None,
559        };
560
561        Some(Self { x, y })
562    }
563
564    /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
565    ///
566    /// In other words this computes `Some([self.x - rhs.x, self.y - rhs.y, ..])` but returns `None` on any overflow.
567    #[inline]
568    #[must_use]
569    pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
570        let x = match self.x.checked_sub(rhs.x) {
571            Some(v) => v,
572            None => return None,
573        };
574        let y = match self.y.checked_sub(rhs.y) {
575            Some(v) => v,
576            None => return None,
577        };
578
579        Some(Self { x, y })
580    }
581
582    /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
583    ///
584    /// In other words this computes `Some([self.x * rhs.x, self.y * rhs.y, ..])` but returns `None` on any overflow.
585    #[inline]
586    #[must_use]
587    pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
588        let x = match self.x.checked_mul(rhs.x) {
589            Some(v) => v,
590            None => return None,
591        };
592        let y = match self.y.checked_mul(rhs.y) {
593            Some(v) => v,
594            None => return None,
595        };
596
597        Some(Self { x, y })
598    }
599
600    /// Returns a vector containing the wrapping division of `self` and `rhs`.
601    ///
602    /// In other words this computes `Some([self.x / rhs.x, self.y / rhs.y, ..])` but returns `None` on any division by zero.
603    #[inline]
604    #[must_use]
605    pub const fn checked_div(self, rhs: Self) -> Option<Self> {
606        let x = match self.x.checked_div(rhs.x) {
607            Some(v) => v,
608            None => return None,
609        };
610        let y = match self.y.checked_div(rhs.y) {
611            Some(v) => v,
612            None => return None,
613        };
614
615        Some(Self { x, y })
616    }
617
618    /// Returns a vector containing the wrapping addition of `self` and `rhs`.
619    ///
620    /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`.
621    #[inline]
622    #[must_use]
623    pub const fn wrapping_add(self, rhs: Self) -> Self {
624        Self {
625            x: self.x.wrapping_add(rhs.x),
626            y: self.y.wrapping_add(rhs.y),
627        }
628    }
629
630    /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
631    ///
632    /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`.
633    #[inline]
634    #[must_use]
635    pub const fn wrapping_sub(self, rhs: Self) -> Self {
636        Self {
637            x: self.x.wrapping_sub(rhs.x),
638            y: self.y.wrapping_sub(rhs.y),
639        }
640    }
641
642    /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
643    ///
644    /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`.
645    #[inline]
646    #[must_use]
647    pub const fn wrapping_mul(self, rhs: Self) -> Self {
648        Self {
649            x: self.x.wrapping_mul(rhs.x),
650            y: self.y.wrapping_mul(rhs.y),
651        }
652    }
653
654    /// Returns a vector containing the wrapping division of `self` and `rhs`.
655    ///
656    /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`.
657    #[inline]
658    #[must_use]
659    pub const fn wrapping_div(self, rhs: Self) -> Self {
660        Self {
661            x: self.x.wrapping_div(rhs.x),
662            y: self.y.wrapping_div(rhs.y),
663        }
664    }
665
666    /// Returns a vector containing the saturating addition of `self` and `rhs`.
667    ///
668    /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`.
669    #[inline]
670    #[must_use]
671    pub const fn saturating_add(self, rhs: Self) -> Self {
672        Self {
673            x: self.x.saturating_add(rhs.x),
674            y: self.y.saturating_add(rhs.y),
675        }
676    }
677
678    /// Returns a vector containing the saturating subtraction of `self` and `rhs`.
679    ///
680    /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`.
681    #[inline]
682    #[must_use]
683    pub const fn saturating_sub(self, rhs: Self) -> Self {
684        Self {
685            x: self.x.saturating_sub(rhs.x),
686            y: self.y.saturating_sub(rhs.y),
687        }
688    }
689
690    /// Returns a vector containing the saturating multiplication of `self` and `rhs`.
691    ///
692    /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`.
693    #[inline]
694    #[must_use]
695    pub const fn saturating_mul(self, rhs: Self) -> Self {
696        Self {
697            x: self.x.saturating_mul(rhs.x),
698            y: self.y.saturating_mul(rhs.y),
699        }
700    }
701
702    /// Returns a vector containing the saturating division of `self` and `rhs`.
703    ///
704    /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`.
705    #[inline]
706    #[must_use]
707    pub const fn saturating_div(self, rhs: Self) -> Self {
708        Self {
709            x: self.x.saturating_div(rhs.x),
710            y: self.y.saturating_div(rhs.y),
711        }
712    }
713
714    /// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`.
715    ///
716    /// In other words this computes `Some([self.x + rhs.x, self.y + rhs.y, ..])` but returns `None` on any overflow.
717    #[inline]
718    #[must_use]
719    pub const fn checked_add_unsigned(self, rhs: UVec2) -> Option<Self> {
720        let x = match self.x.checked_add_unsigned(rhs.x) {
721            Some(v) => v,
722            None => return None,
723        };
724        let y = match self.y.checked_add_unsigned(rhs.y) {
725            Some(v) => v,
726            None => return None,
727        };
728
729        Some(Self { x, y })
730    }
731
732    /// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`.
733    ///
734    /// In other words this computes `Some([self.x - rhs.x, self.y - rhs.y, ..])` but returns `None` on any overflow.
735    #[inline]
736    #[must_use]
737    pub const fn checked_sub_unsigned(self, rhs: UVec2) -> Option<Self> {
738        let x = match self.x.checked_sub_unsigned(rhs.x) {
739            Some(v) => v,
740            None => return None,
741        };
742        let y = match self.y.checked_sub_unsigned(rhs.y) {
743            Some(v) => v,
744            None => return None,
745        };
746
747        Some(Self { x, y })
748    }
749
750    /// Returns a vector containing the wrapping addition of `self` and unsigned vector `rhs`.
751    ///
752    /// In other words this computes `[self.x.wrapping_add_unsigned(rhs.x), self.y.wrapping_add_unsigned(rhs.y), ..]`.
753    #[inline]
754    #[must_use]
755    pub const fn wrapping_add_unsigned(self, rhs: UVec2) -> Self {
756        Self {
757            x: self.x.wrapping_add_unsigned(rhs.x),
758            y: self.y.wrapping_add_unsigned(rhs.y),
759        }
760    }
761
762    /// Returns a vector containing the wrapping subtraction of `self` and unsigned vector `rhs`.
763    ///
764    /// In other words this computes `[self.x.wrapping_sub_unsigned(rhs.x), self.y.wrapping_sub_unsigned(rhs.y), ..]`.
765    #[inline]
766    #[must_use]
767    pub const fn wrapping_sub_unsigned(self, rhs: UVec2) -> Self {
768        Self {
769            x: self.x.wrapping_sub_unsigned(rhs.x),
770            y: self.y.wrapping_sub_unsigned(rhs.y),
771        }
772    }
773
774    // Returns a vector containing the saturating addition of `self` and unsigned vector `rhs`.
775    ///
776    /// In other words this computes `[self.x.saturating_add_unsigned(rhs.x), self.y.saturating_add_unsigned(rhs.y), ..]`.
777    #[inline]
778    #[must_use]
779    pub const fn saturating_add_unsigned(self, rhs: UVec2) -> Self {
780        Self {
781            x: self.x.saturating_add_unsigned(rhs.x),
782            y: self.y.saturating_add_unsigned(rhs.y),
783        }
784    }
785
786    /// Returns a vector containing the saturating subtraction of `self` and unsigned vector `rhs`.
787    ///
788    /// In other words this computes `[self.x.saturating_sub_unsigned(rhs.x), self.y.saturating_sub_unsigned(rhs.y), ..]`.
789    #[inline]
790    #[must_use]
791    pub const fn saturating_sub_unsigned(self, rhs: UVec2) -> Self {
792        Self {
793            x: self.x.saturating_sub_unsigned(rhs.x),
794            y: self.y.saturating_sub_unsigned(rhs.y),
795        }
796    }
797}
798
799impl Default for IVec2 {
800    #[inline(always)]
801    fn default() -> Self {
802        Self::ZERO
803    }
804}
805
806impl Div<IVec2> for IVec2 {
807    type Output = Self;
808    #[inline]
809    fn div(self, rhs: Self) -> Self {
810        Self {
811            x: self.x.div(rhs.x),
812            y: self.y.div(rhs.y),
813        }
814    }
815}
816
817impl Div<&IVec2> for IVec2 {
818    type Output = IVec2;
819    #[inline]
820    fn div(self, rhs: &IVec2) -> IVec2 {
821        self.div(*rhs)
822    }
823}
824
825impl Div<&IVec2> for &IVec2 {
826    type Output = IVec2;
827    #[inline]
828    fn div(self, rhs: &IVec2) -> IVec2 {
829        (*self).div(*rhs)
830    }
831}
832
833impl Div<IVec2> for &IVec2 {
834    type Output = IVec2;
835    #[inline]
836    fn div(self, rhs: IVec2) -> IVec2 {
837        (*self).div(rhs)
838    }
839}
840
841impl DivAssign<IVec2> for IVec2 {
842    #[inline]
843    fn div_assign(&mut self, rhs: Self) {
844        self.x.div_assign(rhs.x);
845        self.y.div_assign(rhs.y);
846    }
847}
848
849impl DivAssign<&IVec2> for IVec2 {
850    #[inline]
851    fn div_assign(&mut self, rhs: &IVec2) {
852        self.div_assign(*rhs)
853    }
854}
855
856impl Div<i32> for IVec2 {
857    type Output = Self;
858    #[inline]
859    fn div(self, rhs: i32) -> Self {
860        Self {
861            x: self.x.div(rhs),
862            y: self.y.div(rhs),
863        }
864    }
865}
866
867impl Div<&i32> for IVec2 {
868    type Output = IVec2;
869    #[inline]
870    fn div(self, rhs: &i32) -> IVec2 {
871        self.div(*rhs)
872    }
873}
874
875impl Div<&i32> for &IVec2 {
876    type Output = IVec2;
877    #[inline]
878    fn div(self, rhs: &i32) -> IVec2 {
879        (*self).div(*rhs)
880    }
881}
882
883impl Div<i32> for &IVec2 {
884    type Output = IVec2;
885    #[inline]
886    fn div(self, rhs: i32) -> IVec2 {
887        (*self).div(rhs)
888    }
889}
890
891impl DivAssign<i32> for IVec2 {
892    #[inline]
893    fn div_assign(&mut self, rhs: i32) {
894        self.x.div_assign(rhs);
895        self.y.div_assign(rhs);
896    }
897}
898
899impl DivAssign<&i32> for IVec2 {
900    #[inline]
901    fn div_assign(&mut self, rhs: &i32) {
902        self.div_assign(*rhs)
903    }
904}
905
906impl Div<IVec2> for i32 {
907    type Output = IVec2;
908    #[inline]
909    fn div(self, rhs: IVec2) -> IVec2 {
910        IVec2 {
911            x: self.div(rhs.x),
912            y: self.div(rhs.y),
913        }
914    }
915}
916
917impl Div<&IVec2> for i32 {
918    type Output = IVec2;
919    #[inline]
920    fn div(self, rhs: &IVec2) -> IVec2 {
921        self.div(*rhs)
922    }
923}
924
925impl Div<&IVec2> for &i32 {
926    type Output = IVec2;
927    #[inline]
928    fn div(self, rhs: &IVec2) -> IVec2 {
929        (*self).div(*rhs)
930    }
931}
932
933impl Div<IVec2> for &i32 {
934    type Output = IVec2;
935    #[inline]
936    fn div(self, rhs: IVec2) -> IVec2 {
937        (*self).div(rhs)
938    }
939}
940
941impl Mul<IVec2> for IVec2 {
942    type Output = Self;
943    #[inline]
944    fn mul(self, rhs: Self) -> Self {
945        Self {
946            x: self.x.mul(rhs.x),
947            y: self.y.mul(rhs.y),
948        }
949    }
950}
951
952impl Mul<&IVec2> for IVec2 {
953    type Output = IVec2;
954    #[inline]
955    fn mul(self, rhs: &IVec2) -> IVec2 {
956        self.mul(*rhs)
957    }
958}
959
960impl Mul<&IVec2> for &IVec2 {
961    type Output = IVec2;
962    #[inline]
963    fn mul(self, rhs: &IVec2) -> IVec2 {
964        (*self).mul(*rhs)
965    }
966}
967
968impl Mul<IVec2> for &IVec2 {
969    type Output = IVec2;
970    #[inline]
971    fn mul(self, rhs: IVec2) -> IVec2 {
972        (*self).mul(rhs)
973    }
974}
975
976impl MulAssign<IVec2> for IVec2 {
977    #[inline]
978    fn mul_assign(&mut self, rhs: Self) {
979        self.x.mul_assign(rhs.x);
980        self.y.mul_assign(rhs.y);
981    }
982}
983
984impl MulAssign<&IVec2> for IVec2 {
985    #[inline]
986    fn mul_assign(&mut self, rhs: &IVec2) {
987        self.mul_assign(*rhs)
988    }
989}
990
991impl Mul<i32> for IVec2 {
992    type Output = Self;
993    #[inline]
994    fn mul(self, rhs: i32) -> Self {
995        Self {
996            x: self.x.mul(rhs),
997            y: self.y.mul(rhs),
998        }
999    }
1000}
1001
1002impl Mul<&i32> for IVec2 {
1003    type Output = IVec2;
1004    #[inline]
1005    fn mul(self, rhs: &i32) -> IVec2 {
1006        self.mul(*rhs)
1007    }
1008}
1009
1010impl Mul<&i32> for &IVec2 {
1011    type Output = IVec2;
1012    #[inline]
1013    fn mul(self, rhs: &i32) -> IVec2 {
1014        (*self).mul(*rhs)
1015    }
1016}
1017
1018impl Mul<i32> for &IVec2 {
1019    type Output = IVec2;
1020    #[inline]
1021    fn mul(self, rhs: i32) -> IVec2 {
1022        (*self).mul(rhs)
1023    }
1024}
1025
1026impl MulAssign<i32> for IVec2 {
1027    #[inline]
1028    fn mul_assign(&mut self, rhs: i32) {
1029        self.x.mul_assign(rhs);
1030        self.y.mul_assign(rhs);
1031    }
1032}
1033
1034impl MulAssign<&i32> for IVec2 {
1035    #[inline]
1036    fn mul_assign(&mut self, rhs: &i32) {
1037        self.mul_assign(*rhs)
1038    }
1039}
1040
1041impl Mul<IVec2> for i32 {
1042    type Output = IVec2;
1043    #[inline]
1044    fn mul(self, rhs: IVec2) -> IVec2 {
1045        IVec2 {
1046            x: self.mul(rhs.x),
1047            y: self.mul(rhs.y),
1048        }
1049    }
1050}
1051
1052impl Mul<&IVec2> for i32 {
1053    type Output = IVec2;
1054    #[inline]
1055    fn mul(self, rhs: &IVec2) -> IVec2 {
1056        self.mul(*rhs)
1057    }
1058}
1059
1060impl Mul<&IVec2> for &i32 {
1061    type Output = IVec2;
1062    #[inline]
1063    fn mul(self, rhs: &IVec2) -> IVec2 {
1064        (*self).mul(*rhs)
1065    }
1066}
1067
1068impl Mul<IVec2> for &i32 {
1069    type Output = IVec2;
1070    #[inline]
1071    fn mul(self, rhs: IVec2) -> IVec2 {
1072        (*self).mul(rhs)
1073    }
1074}
1075
1076impl Add<IVec2> for IVec2 {
1077    type Output = Self;
1078    #[inline]
1079    fn add(self, rhs: Self) -> Self {
1080        Self {
1081            x: self.x.add(rhs.x),
1082            y: self.y.add(rhs.y),
1083        }
1084    }
1085}
1086
1087impl Add<&IVec2> for IVec2 {
1088    type Output = IVec2;
1089    #[inline]
1090    fn add(self, rhs: &IVec2) -> IVec2 {
1091        self.add(*rhs)
1092    }
1093}
1094
1095impl Add<&IVec2> for &IVec2 {
1096    type Output = IVec2;
1097    #[inline]
1098    fn add(self, rhs: &IVec2) -> IVec2 {
1099        (*self).add(*rhs)
1100    }
1101}
1102
1103impl Add<IVec2> for &IVec2 {
1104    type Output = IVec2;
1105    #[inline]
1106    fn add(self, rhs: IVec2) -> IVec2 {
1107        (*self).add(rhs)
1108    }
1109}
1110
1111impl AddAssign<IVec2> for IVec2 {
1112    #[inline]
1113    fn add_assign(&mut self, rhs: Self) {
1114        self.x.add_assign(rhs.x);
1115        self.y.add_assign(rhs.y);
1116    }
1117}
1118
1119impl AddAssign<&IVec2> for IVec2 {
1120    #[inline]
1121    fn add_assign(&mut self, rhs: &IVec2) {
1122        self.add_assign(*rhs)
1123    }
1124}
1125
1126impl Add<i32> for IVec2 {
1127    type Output = Self;
1128    #[inline]
1129    fn add(self, rhs: i32) -> Self {
1130        Self {
1131            x: self.x.add(rhs),
1132            y: self.y.add(rhs),
1133        }
1134    }
1135}
1136
1137impl Add<&i32> for IVec2 {
1138    type Output = IVec2;
1139    #[inline]
1140    fn add(self, rhs: &i32) -> IVec2 {
1141        self.add(*rhs)
1142    }
1143}
1144
1145impl Add<&i32> for &IVec2 {
1146    type Output = IVec2;
1147    #[inline]
1148    fn add(self, rhs: &i32) -> IVec2 {
1149        (*self).add(*rhs)
1150    }
1151}
1152
1153impl Add<i32> for &IVec2 {
1154    type Output = IVec2;
1155    #[inline]
1156    fn add(self, rhs: i32) -> IVec2 {
1157        (*self).add(rhs)
1158    }
1159}
1160
1161impl AddAssign<i32> for IVec2 {
1162    #[inline]
1163    fn add_assign(&mut self, rhs: i32) {
1164        self.x.add_assign(rhs);
1165        self.y.add_assign(rhs);
1166    }
1167}
1168
1169impl AddAssign<&i32> for IVec2 {
1170    #[inline]
1171    fn add_assign(&mut self, rhs: &i32) {
1172        self.add_assign(*rhs)
1173    }
1174}
1175
1176impl Add<IVec2> for i32 {
1177    type Output = IVec2;
1178    #[inline]
1179    fn add(self, rhs: IVec2) -> IVec2 {
1180        IVec2 {
1181            x: self.add(rhs.x),
1182            y: self.add(rhs.y),
1183        }
1184    }
1185}
1186
1187impl Add<&IVec2> for i32 {
1188    type Output = IVec2;
1189    #[inline]
1190    fn add(self, rhs: &IVec2) -> IVec2 {
1191        self.add(*rhs)
1192    }
1193}
1194
1195impl Add<&IVec2> for &i32 {
1196    type Output = IVec2;
1197    #[inline]
1198    fn add(self, rhs: &IVec2) -> IVec2 {
1199        (*self).add(*rhs)
1200    }
1201}
1202
1203impl Add<IVec2> for &i32 {
1204    type Output = IVec2;
1205    #[inline]
1206    fn add(self, rhs: IVec2) -> IVec2 {
1207        (*self).add(rhs)
1208    }
1209}
1210
1211impl Sub<IVec2> for IVec2 {
1212    type Output = Self;
1213    #[inline]
1214    fn sub(self, rhs: Self) -> Self {
1215        Self {
1216            x: self.x.sub(rhs.x),
1217            y: self.y.sub(rhs.y),
1218        }
1219    }
1220}
1221
1222impl Sub<&IVec2> for IVec2 {
1223    type Output = IVec2;
1224    #[inline]
1225    fn sub(self, rhs: &IVec2) -> IVec2 {
1226        self.sub(*rhs)
1227    }
1228}
1229
1230impl Sub<&IVec2> for &IVec2 {
1231    type Output = IVec2;
1232    #[inline]
1233    fn sub(self, rhs: &IVec2) -> IVec2 {
1234        (*self).sub(*rhs)
1235    }
1236}
1237
1238impl Sub<IVec2> for &IVec2 {
1239    type Output = IVec2;
1240    #[inline]
1241    fn sub(self, rhs: IVec2) -> IVec2 {
1242        (*self).sub(rhs)
1243    }
1244}
1245
1246impl SubAssign<IVec2> for IVec2 {
1247    #[inline]
1248    fn sub_assign(&mut self, rhs: IVec2) {
1249        self.x.sub_assign(rhs.x);
1250        self.y.sub_assign(rhs.y);
1251    }
1252}
1253
1254impl SubAssign<&IVec2> for IVec2 {
1255    #[inline]
1256    fn sub_assign(&mut self, rhs: &IVec2) {
1257        self.sub_assign(*rhs)
1258    }
1259}
1260
1261impl Sub<i32> for IVec2 {
1262    type Output = Self;
1263    #[inline]
1264    fn sub(self, rhs: i32) -> Self {
1265        Self {
1266            x: self.x.sub(rhs),
1267            y: self.y.sub(rhs),
1268        }
1269    }
1270}
1271
1272impl Sub<&i32> for IVec2 {
1273    type Output = IVec2;
1274    #[inline]
1275    fn sub(self, rhs: &i32) -> IVec2 {
1276        self.sub(*rhs)
1277    }
1278}
1279
1280impl Sub<&i32> for &IVec2 {
1281    type Output = IVec2;
1282    #[inline]
1283    fn sub(self, rhs: &i32) -> IVec2 {
1284        (*self).sub(*rhs)
1285    }
1286}
1287
1288impl Sub<i32> for &IVec2 {
1289    type Output = IVec2;
1290    #[inline]
1291    fn sub(self, rhs: i32) -> IVec2 {
1292        (*self).sub(rhs)
1293    }
1294}
1295
1296impl SubAssign<i32> for IVec2 {
1297    #[inline]
1298    fn sub_assign(&mut self, rhs: i32) {
1299        self.x.sub_assign(rhs);
1300        self.y.sub_assign(rhs);
1301    }
1302}
1303
1304impl SubAssign<&i32> for IVec2 {
1305    #[inline]
1306    fn sub_assign(&mut self, rhs: &i32) {
1307        self.sub_assign(*rhs)
1308    }
1309}
1310
1311impl Sub<IVec2> for i32 {
1312    type Output = IVec2;
1313    #[inline]
1314    fn sub(self, rhs: IVec2) -> IVec2 {
1315        IVec2 {
1316            x: self.sub(rhs.x),
1317            y: self.sub(rhs.y),
1318        }
1319    }
1320}
1321
1322impl Sub<&IVec2> for i32 {
1323    type Output = IVec2;
1324    #[inline]
1325    fn sub(self, rhs: &IVec2) -> IVec2 {
1326        self.sub(*rhs)
1327    }
1328}
1329
1330impl Sub<&IVec2> for &i32 {
1331    type Output = IVec2;
1332    #[inline]
1333    fn sub(self, rhs: &IVec2) -> IVec2 {
1334        (*self).sub(*rhs)
1335    }
1336}
1337
1338impl Sub<IVec2> for &i32 {
1339    type Output = IVec2;
1340    #[inline]
1341    fn sub(self, rhs: IVec2) -> IVec2 {
1342        (*self).sub(rhs)
1343    }
1344}
1345
1346impl Rem<IVec2> for IVec2 {
1347    type Output = Self;
1348    #[inline]
1349    fn rem(self, rhs: Self) -> Self {
1350        Self {
1351            x: self.x.rem(rhs.x),
1352            y: self.y.rem(rhs.y),
1353        }
1354    }
1355}
1356
1357impl Rem<&IVec2> for IVec2 {
1358    type Output = IVec2;
1359    #[inline]
1360    fn rem(self, rhs: &IVec2) -> IVec2 {
1361        self.rem(*rhs)
1362    }
1363}
1364
1365impl Rem<&IVec2> for &IVec2 {
1366    type Output = IVec2;
1367    #[inline]
1368    fn rem(self, rhs: &IVec2) -> IVec2 {
1369        (*self).rem(*rhs)
1370    }
1371}
1372
1373impl Rem<IVec2> for &IVec2 {
1374    type Output = IVec2;
1375    #[inline]
1376    fn rem(self, rhs: IVec2) -> IVec2 {
1377        (*self).rem(rhs)
1378    }
1379}
1380
1381impl RemAssign<IVec2> for IVec2 {
1382    #[inline]
1383    fn rem_assign(&mut self, rhs: Self) {
1384        self.x.rem_assign(rhs.x);
1385        self.y.rem_assign(rhs.y);
1386    }
1387}
1388
1389impl RemAssign<&IVec2> for IVec2 {
1390    #[inline]
1391    fn rem_assign(&mut self, rhs: &IVec2) {
1392        self.rem_assign(*rhs)
1393    }
1394}
1395
1396impl Rem<i32> for IVec2 {
1397    type Output = Self;
1398    #[inline]
1399    fn rem(self, rhs: i32) -> Self {
1400        Self {
1401            x: self.x.rem(rhs),
1402            y: self.y.rem(rhs),
1403        }
1404    }
1405}
1406
1407impl Rem<&i32> for IVec2 {
1408    type Output = IVec2;
1409    #[inline]
1410    fn rem(self, rhs: &i32) -> IVec2 {
1411        self.rem(*rhs)
1412    }
1413}
1414
1415impl Rem<&i32> for &IVec2 {
1416    type Output = IVec2;
1417    #[inline]
1418    fn rem(self, rhs: &i32) -> IVec2 {
1419        (*self).rem(*rhs)
1420    }
1421}
1422
1423impl Rem<i32> for &IVec2 {
1424    type Output = IVec2;
1425    #[inline]
1426    fn rem(self, rhs: i32) -> IVec2 {
1427        (*self).rem(rhs)
1428    }
1429}
1430
1431impl RemAssign<i32> for IVec2 {
1432    #[inline]
1433    fn rem_assign(&mut self, rhs: i32) {
1434        self.x.rem_assign(rhs);
1435        self.y.rem_assign(rhs);
1436    }
1437}
1438
1439impl RemAssign<&i32> for IVec2 {
1440    #[inline]
1441    fn rem_assign(&mut self, rhs: &i32) {
1442        self.rem_assign(*rhs)
1443    }
1444}
1445
1446impl Rem<IVec2> for i32 {
1447    type Output = IVec2;
1448    #[inline]
1449    fn rem(self, rhs: IVec2) -> IVec2 {
1450        IVec2 {
1451            x: self.rem(rhs.x),
1452            y: self.rem(rhs.y),
1453        }
1454    }
1455}
1456
1457impl Rem<&IVec2> for i32 {
1458    type Output = IVec2;
1459    #[inline]
1460    fn rem(self, rhs: &IVec2) -> IVec2 {
1461        self.rem(*rhs)
1462    }
1463}
1464
1465impl Rem<&IVec2> for &i32 {
1466    type Output = IVec2;
1467    #[inline]
1468    fn rem(self, rhs: &IVec2) -> IVec2 {
1469        (*self).rem(*rhs)
1470    }
1471}
1472
1473impl Rem<IVec2> for &i32 {
1474    type Output = IVec2;
1475    #[inline]
1476    fn rem(self, rhs: IVec2) -> IVec2 {
1477        (*self).rem(rhs)
1478    }
1479}
1480
1481#[cfg(not(target_arch = "spirv"))]
1482impl AsRef<[i32; 2]> for IVec2 {
1483    #[inline]
1484    fn as_ref(&self) -> &[i32; 2] {
1485        unsafe { &*(self as *const IVec2 as *const [i32; 2]) }
1486    }
1487}
1488
1489#[cfg(not(target_arch = "spirv"))]
1490impl AsMut<[i32; 2]> for IVec2 {
1491    #[inline]
1492    fn as_mut(&mut self) -> &mut [i32; 2] {
1493        unsafe { &mut *(self as *mut IVec2 as *mut [i32; 2]) }
1494    }
1495}
1496
1497impl Sum for IVec2 {
1498    #[inline]
1499    fn sum<I>(iter: I) -> Self
1500    where
1501        I: Iterator<Item = Self>,
1502    {
1503        iter.fold(Self::ZERO, Self::add)
1504    }
1505}
1506
1507impl<'a> Sum<&'a Self> for IVec2 {
1508    #[inline]
1509    fn sum<I>(iter: I) -> Self
1510    where
1511        I: Iterator<Item = &'a Self>,
1512    {
1513        iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1514    }
1515}
1516
1517impl Product for IVec2 {
1518    #[inline]
1519    fn product<I>(iter: I) -> Self
1520    where
1521        I: Iterator<Item = Self>,
1522    {
1523        iter.fold(Self::ONE, Self::mul)
1524    }
1525}
1526
1527impl<'a> Product<&'a Self> for IVec2 {
1528    #[inline]
1529    fn product<I>(iter: I) -> Self
1530    where
1531        I: Iterator<Item = &'a Self>,
1532    {
1533        iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1534    }
1535}
1536
1537impl Neg for IVec2 {
1538    type Output = Self;
1539    #[inline]
1540    fn neg(self) -> Self {
1541        Self {
1542            x: self.x.neg(),
1543            y: self.y.neg(),
1544        }
1545    }
1546}
1547
1548impl Neg for &IVec2 {
1549    type Output = IVec2;
1550    #[inline]
1551    fn neg(self) -> IVec2 {
1552        (*self).neg()
1553    }
1554}
1555
1556impl Not for IVec2 {
1557    type Output = Self;
1558    #[inline]
1559    fn not(self) -> Self::Output {
1560        Self {
1561            x: self.x.not(),
1562            y: self.y.not(),
1563        }
1564    }
1565}
1566
1567impl BitAnd for IVec2 {
1568    type Output = Self;
1569    #[inline]
1570    fn bitand(self, rhs: Self) -> Self::Output {
1571        Self {
1572            x: self.x.bitand(rhs.x),
1573            y: self.y.bitand(rhs.y),
1574        }
1575    }
1576}
1577
1578impl BitOr for IVec2 {
1579    type Output = Self;
1580    #[inline]
1581    fn bitor(self, rhs: Self) -> Self::Output {
1582        Self {
1583            x: self.x.bitor(rhs.x),
1584            y: self.y.bitor(rhs.y),
1585        }
1586    }
1587}
1588
1589impl BitXor for IVec2 {
1590    type Output = Self;
1591    #[inline]
1592    fn bitxor(self, rhs: Self) -> Self::Output {
1593        Self {
1594            x: self.x.bitxor(rhs.x),
1595            y: self.y.bitxor(rhs.y),
1596        }
1597    }
1598}
1599
1600impl BitAnd<i32> for IVec2 {
1601    type Output = Self;
1602    #[inline]
1603    fn bitand(self, rhs: i32) -> Self::Output {
1604        Self {
1605            x: self.x.bitand(rhs),
1606            y: self.y.bitand(rhs),
1607        }
1608    }
1609}
1610
1611impl BitOr<i32> for IVec2 {
1612    type Output = Self;
1613    #[inline]
1614    fn bitor(self, rhs: i32) -> Self::Output {
1615        Self {
1616            x: self.x.bitor(rhs),
1617            y: self.y.bitor(rhs),
1618        }
1619    }
1620}
1621
1622impl BitXor<i32> for IVec2 {
1623    type Output = Self;
1624    #[inline]
1625    fn bitxor(self, rhs: i32) -> Self::Output {
1626        Self {
1627            x: self.x.bitxor(rhs),
1628            y: self.y.bitxor(rhs),
1629        }
1630    }
1631}
1632
1633impl Shl<i8> for IVec2 {
1634    type Output = Self;
1635    #[inline]
1636    fn shl(self, rhs: i8) -> Self::Output {
1637        Self {
1638            x: self.x.shl(rhs),
1639            y: self.y.shl(rhs),
1640        }
1641    }
1642}
1643
1644impl Shr<i8> for IVec2 {
1645    type Output = Self;
1646    #[inline]
1647    fn shr(self, rhs: i8) -> Self::Output {
1648        Self {
1649            x: self.x.shr(rhs),
1650            y: self.y.shr(rhs),
1651        }
1652    }
1653}
1654
1655impl Shl<i16> for IVec2 {
1656    type Output = Self;
1657    #[inline]
1658    fn shl(self, rhs: i16) -> Self::Output {
1659        Self {
1660            x: self.x.shl(rhs),
1661            y: self.y.shl(rhs),
1662        }
1663    }
1664}
1665
1666impl Shr<i16> for IVec2 {
1667    type Output = Self;
1668    #[inline]
1669    fn shr(self, rhs: i16) -> Self::Output {
1670        Self {
1671            x: self.x.shr(rhs),
1672            y: self.y.shr(rhs),
1673        }
1674    }
1675}
1676
1677impl Shl<i32> for IVec2 {
1678    type Output = Self;
1679    #[inline]
1680    fn shl(self, rhs: i32) -> Self::Output {
1681        Self {
1682            x: self.x.shl(rhs),
1683            y: self.y.shl(rhs),
1684        }
1685    }
1686}
1687
1688impl Shr<i32> for IVec2 {
1689    type Output = Self;
1690    #[inline]
1691    fn shr(self, rhs: i32) -> Self::Output {
1692        Self {
1693            x: self.x.shr(rhs),
1694            y: self.y.shr(rhs),
1695        }
1696    }
1697}
1698
1699impl Shl<i64> for IVec2 {
1700    type Output = Self;
1701    #[inline]
1702    fn shl(self, rhs: i64) -> Self::Output {
1703        Self {
1704            x: self.x.shl(rhs),
1705            y: self.y.shl(rhs),
1706        }
1707    }
1708}
1709
1710impl Shr<i64> for IVec2 {
1711    type Output = Self;
1712    #[inline]
1713    fn shr(self, rhs: i64) -> Self::Output {
1714        Self {
1715            x: self.x.shr(rhs),
1716            y: self.y.shr(rhs),
1717        }
1718    }
1719}
1720
1721impl Shl<u8> for IVec2 {
1722    type Output = Self;
1723    #[inline]
1724    fn shl(self, rhs: u8) -> Self::Output {
1725        Self {
1726            x: self.x.shl(rhs),
1727            y: self.y.shl(rhs),
1728        }
1729    }
1730}
1731
1732impl Shr<u8> for IVec2 {
1733    type Output = Self;
1734    #[inline]
1735    fn shr(self, rhs: u8) -> Self::Output {
1736        Self {
1737            x: self.x.shr(rhs),
1738            y: self.y.shr(rhs),
1739        }
1740    }
1741}
1742
1743impl Shl<u16> for IVec2 {
1744    type Output = Self;
1745    #[inline]
1746    fn shl(self, rhs: u16) -> Self::Output {
1747        Self {
1748            x: self.x.shl(rhs),
1749            y: self.y.shl(rhs),
1750        }
1751    }
1752}
1753
1754impl Shr<u16> for IVec2 {
1755    type Output = Self;
1756    #[inline]
1757    fn shr(self, rhs: u16) -> Self::Output {
1758        Self {
1759            x: self.x.shr(rhs),
1760            y: self.y.shr(rhs),
1761        }
1762    }
1763}
1764
1765impl Shl<u32> for IVec2 {
1766    type Output = Self;
1767    #[inline]
1768    fn shl(self, rhs: u32) -> Self::Output {
1769        Self {
1770            x: self.x.shl(rhs),
1771            y: self.y.shl(rhs),
1772        }
1773    }
1774}
1775
1776impl Shr<u32> for IVec2 {
1777    type Output = Self;
1778    #[inline]
1779    fn shr(self, rhs: u32) -> Self::Output {
1780        Self {
1781            x: self.x.shr(rhs),
1782            y: self.y.shr(rhs),
1783        }
1784    }
1785}
1786
1787impl Shl<u64> for IVec2 {
1788    type Output = Self;
1789    #[inline]
1790    fn shl(self, rhs: u64) -> Self::Output {
1791        Self {
1792            x: self.x.shl(rhs),
1793            y: self.y.shl(rhs),
1794        }
1795    }
1796}
1797
1798impl Shr<u64> for IVec2 {
1799    type Output = Self;
1800    #[inline]
1801    fn shr(self, rhs: u64) -> Self::Output {
1802        Self {
1803            x: self.x.shr(rhs),
1804            y: self.y.shr(rhs),
1805        }
1806    }
1807}
1808
1809impl Shl<crate::IVec2> for IVec2 {
1810    type Output = Self;
1811    #[inline]
1812    fn shl(self, rhs: crate::IVec2) -> Self::Output {
1813        Self {
1814            x: self.x.shl(rhs.x),
1815            y: self.y.shl(rhs.y),
1816        }
1817    }
1818}
1819
1820impl Shr<crate::IVec2> for IVec2 {
1821    type Output = Self;
1822    #[inline]
1823    fn shr(self, rhs: crate::IVec2) -> Self::Output {
1824        Self {
1825            x: self.x.shr(rhs.x),
1826            y: self.y.shr(rhs.y),
1827        }
1828    }
1829}
1830
1831impl Shl<crate::UVec2> for IVec2 {
1832    type Output = Self;
1833    #[inline]
1834    fn shl(self, rhs: crate::UVec2) -> Self::Output {
1835        Self {
1836            x: self.x.shl(rhs.x),
1837            y: self.y.shl(rhs.y),
1838        }
1839    }
1840}
1841
1842impl Shr<crate::UVec2> for IVec2 {
1843    type Output = Self;
1844    #[inline]
1845    fn shr(self, rhs: crate::UVec2) -> Self::Output {
1846        Self {
1847            x: self.x.shr(rhs.x),
1848            y: self.y.shr(rhs.y),
1849        }
1850    }
1851}
1852
1853impl Index<usize> for IVec2 {
1854    type Output = i32;
1855    #[inline]
1856    fn index(&self, index: usize) -> &Self::Output {
1857        match index {
1858            0 => &self.x,
1859            1 => &self.y,
1860            _ => panic!("index out of bounds"),
1861        }
1862    }
1863}
1864
1865impl IndexMut<usize> for IVec2 {
1866    #[inline]
1867    fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1868        match index {
1869            0 => &mut self.x,
1870            1 => &mut self.y,
1871            _ => panic!("index out of bounds"),
1872        }
1873    }
1874}
1875
1876impl fmt::Display for IVec2 {
1877    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1878        write!(f, "[{}, {}]", self.x, self.y)
1879    }
1880}
1881
1882impl fmt::Debug for IVec2 {
1883    fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1884        fmt.debug_tuple(stringify!(IVec2))
1885            .field(&self.x)
1886            .field(&self.y)
1887            .finish()
1888    }
1889}
1890
1891impl From<[i32; 2]> for IVec2 {
1892    #[inline]
1893    fn from(a: [i32; 2]) -> Self {
1894        Self::new(a[0], a[1])
1895    }
1896}
1897
1898impl From<IVec2> for [i32; 2] {
1899    #[inline]
1900    fn from(v: IVec2) -> Self {
1901        [v.x, v.y]
1902    }
1903}
1904
1905impl From<(i32, i32)> for IVec2 {
1906    #[inline]
1907    fn from(t: (i32, i32)) -> Self {
1908        Self::new(t.0, t.1)
1909    }
1910}
1911
1912impl From<IVec2> for (i32, i32) {
1913    #[inline]
1914    fn from(v: IVec2) -> Self {
1915        (v.x, v.y)
1916    }
1917}
1918
1919impl From<I8Vec2> for IVec2 {
1920    #[inline]
1921    fn from(v: I8Vec2) -> Self {
1922        Self::new(i32::from(v.x), i32::from(v.y))
1923    }
1924}
1925
1926impl From<U8Vec2> for IVec2 {
1927    #[inline]
1928    fn from(v: U8Vec2) -> Self {
1929        Self::new(i32::from(v.x), i32::from(v.y))
1930    }
1931}
1932
1933impl From<I16Vec2> for IVec2 {
1934    #[inline]
1935    fn from(v: I16Vec2) -> Self {
1936        Self::new(i32::from(v.x), i32::from(v.y))
1937    }
1938}
1939
1940impl From<U16Vec2> for IVec2 {
1941    #[inline]
1942    fn from(v: U16Vec2) -> Self {
1943        Self::new(i32::from(v.x), i32::from(v.y))
1944    }
1945}
1946
1947impl TryFrom<UVec2> for IVec2 {
1948    type Error = core::num::TryFromIntError;
1949
1950    #[inline]
1951    fn try_from(v: UVec2) -> Result<Self, Self::Error> {
1952        Ok(Self::new(i32::try_from(v.x)?, i32::try_from(v.y)?))
1953    }
1954}
1955
1956impl TryFrom<I64Vec2> for IVec2 {
1957    type Error = core::num::TryFromIntError;
1958
1959    #[inline]
1960    fn try_from(v: I64Vec2) -> Result<Self, Self::Error> {
1961        Ok(Self::new(i32::try_from(v.x)?, i32::try_from(v.y)?))
1962    }
1963}
1964
1965impl TryFrom<U64Vec2> for IVec2 {
1966    type Error = core::num::TryFromIntError;
1967
1968    #[inline]
1969    fn try_from(v: U64Vec2) -> Result<Self, Self::Error> {
1970        Ok(Self::new(i32::try_from(v.x)?, i32::try_from(v.y)?))
1971    }
1972}
1973
1974impl TryFrom<USizeVec2> for IVec2 {
1975    type Error = core::num::TryFromIntError;
1976
1977    #[inline]
1978    fn try_from(v: USizeVec2) -> Result<Self, Self::Error> {
1979        Ok(Self::new(i32::try_from(v.x)?, i32::try_from(v.y)?))
1980    }
1981}
1982
1983impl From<BVec2> for IVec2 {
1984    #[inline]
1985    fn from(v: BVec2) -> Self {
1986        Self::new(i32::from(v.x), i32::from(v.y))
1987    }
1988}