glam/i8/
i8vec2.rs

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