• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Generated from vec.rs.tera template. Edit the template, not the generated file.
2 
3 use crate::{BVec2, I16Vec2, I64Vec2, I8Vec2, IVec2, U16Vec2, U64Vec2, U8Vec3, UVec2};
4 
5 use core::fmt;
6 use core::iter::{Product, Sum};
7 use core::{f32, ops::*};
8 
9 /// Creates a 2-dimensional vector.
10 #[inline(always)]
11 #[must_use]
u8vec2(x: u8, y: u8) -> U8Vec212 pub const fn u8vec2(x: u8, y: u8) -> U8Vec2 {
13     U8Vec2::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))]
22 pub struct U8Vec2 {
23     pub x: u8,
24     pub y: u8,
25 }
26 
27 impl U8Vec2 {
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 `u8::MIN`.
35     pub const MIN: Self = Self::splat(u8::MIN);
36 
37     /// All `u8::MAX`.
38     pub const MAX: Self = Self::splat(u8::MAX);
39 
40     /// A unit vector pointing along the positive X axis.
41     pub const X: Self = Self::new(1, 0);
42 
43     /// A unit vector pointing along the positive Y axis.
44     pub const Y: Self = Self::new(0, 1);
45 
46     /// The unit axes.
47     pub const AXES: [Self; 2] = [Self::X, Self::Y];
48 
49     /// Creates a new vector.
50     #[inline(always)]
51     #[must_use]
new(x: u8, y: u8) -> Self52     pub const fn new(x: u8, y: u8) -> Self {
53         Self { x, y }
54     }
55 
56     /// Creates a vector with all elements set to `v`.
57     #[inline]
58     #[must_use]
splat(v: u8) -> Self59     pub const fn splat(v: u8) -> Self {
60         Self { x: v, y: v }
61     }
62 
63     /// Returns a vector containing each element of `self` modified by a mapping function `f`.
64     #[inline]
65     #[must_use]
map<F>(self, f: F) -> Self where F: Fn(u8) -> u8,66     pub fn map<F>(self, f: F) -> Self
67     where
68         F: Fn(u8) -> u8,
69     {
70         Self::new(f(self.x), f(self.y))
71     }
72 
73     /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
74     /// for each element of `self`.
75     ///
76     /// A true element in the mask uses the corresponding element from `if_true`, and false
77     /// uses the element from `if_false`.
78     #[inline]
79     #[must_use]
select(mask: BVec2, if_true: Self, if_false: Self) -> Self80     pub fn select(mask: BVec2, if_true: Self, if_false: Self) -> Self {
81         Self {
82             x: if mask.test(0) { if_true.x } else { if_false.x },
83             y: if mask.test(1) { if_true.y } else { if_false.y },
84         }
85     }
86 
87     /// Creates a new vector from an array.
88     #[inline]
89     #[must_use]
from_array(a: [u8; 2]) -> Self90     pub const fn from_array(a: [u8; 2]) -> Self {
91         Self::new(a[0], a[1])
92     }
93 
94     /// `[x, y]`
95     #[inline]
96     #[must_use]
to_array(&self) -> [u8; 2]97     pub const fn to_array(&self) -> [u8; 2] {
98         [self.x, self.y]
99     }
100 
101     /// Creates a vector from the first 2 values in `slice`.
102     ///
103     /// # Panics
104     ///
105     /// Panics if `slice` is less than 2 elements long.
106     #[inline]
107     #[must_use]
from_slice(slice: &[u8]) -> Self108     pub const fn from_slice(slice: &[u8]) -> Self {
109         assert!(slice.len() >= 2);
110         Self::new(slice[0], slice[1])
111     }
112 
113     /// Writes the elements of `self` to the first 2 elements in `slice`.
114     ///
115     /// # Panics
116     ///
117     /// Panics if `slice` is less than 2 elements long.
118     #[inline]
write_to_slice(self, slice: &mut [u8])119     pub fn write_to_slice(self, slice: &mut [u8]) {
120         slice[..2].copy_from_slice(&self.to_array());
121     }
122 
123     /// Creates a 3D vector from `self` and the given `z` value.
124     #[inline]
125     #[must_use]
extend(self, z: u8) -> U8Vec3126     pub const fn extend(self, z: u8) -> U8Vec3 {
127         U8Vec3::new(self.x, self.y, z)
128     }
129 
130     /// Creates a 2D vector from `self` with the given value of `x`.
131     #[inline]
132     #[must_use]
with_x(mut self, x: u8) -> Self133     pub fn with_x(mut self, x: u8) -> Self {
134         self.x = x;
135         self
136     }
137 
138     /// Creates a 2D vector from `self` with the given value of `y`.
139     #[inline]
140     #[must_use]
with_y(mut self, y: u8) -> Self141     pub fn with_y(mut self, y: u8) -> Self {
142         self.y = y;
143         self
144     }
145 
146     /// Computes the dot product of `self` and `rhs`.
147     #[inline]
148     #[must_use]
dot(self, rhs: Self) -> u8149     pub fn dot(self, rhs: Self) -> u8 {
150         (self.x * rhs.x) + (self.y * rhs.y)
151     }
152 
153     /// Returns a vector where every component is the dot product of `self` and `rhs`.
154     #[inline]
155     #[must_use]
dot_into_vec(self, rhs: Self) -> Self156     pub fn dot_into_vec(self, rhs: Self) -> Self {
157         Self::splat(self.dot(rhs))
158     }
159 
160     /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
161     ///
162     /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
163     #[inline]
164     #[must_use]
min(self, rhs: Self) -> Self165     pub fn min(self, rhs: Self) -> Self {
166         Self {
167             x: self.x.min(rhs.x),
168             y: self.y.min(rhs.y),
169         }
170     }
171 
172     /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
173     ///
174     /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
175     #[inline]
176     #[must_use]
max(self, rhs: Self) -> Self177     pub fn max(self, rhs: Self) -> Self {
178         Self {
179             x: self.x.max(rhs.x),
180             y: self.y.max(rhs.y),
181         }
182     }
183 
184     /// Component-wise clamping of values, similar to [`u8::clamp`].
185     ///
186     /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
187     ///
188     /// # Panics
189     ///
190     /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
191     #[inline]
192     #[must_use]
clamp(self, min: Self, max: Self) -> Self193     pub fn clamp(self, min: Self, max: Self) -> Self {
194         glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
195         self.max(min).min(max)
196     }
197 
198     /// Returns the horizontal minimum of `self`.
199     ///
200     /// In other words this computes `min(x, y, ..)`.
201     #[inline]
202     #[must_use]
min_element(self) -> u8203     pub fn min_element(self) -> u8 {
204         self.x.min(self.y)
205     }
206 
207     /// Returns the horizontal maximum of `self`.
208     ///
209     /// In other words this computes `max(x, y, ..)`.
210     #[inline]
211     #[must_use]
max_element(self) -> u8212     pub fn max_element(self) -> u8 {
213         self.x.max(self.y)
214     }
215 
216     /// Returns the sum of all elements of `self`.
217     ///
218     /// In other words, this computes `self.x + self.y + ..`.
219     #[inline]
220     #[must_use]
element_sum(self) -> u8221     pub fn element_sum(self) -> u8 {
222         self.x + self.y
223     }
224 
225     /// Returns the product of all elements of `self`.
226     ///
227     /// In other words, this computes `self.x * self.y * ..`.
228     #[inline]
229     #[must_use]
element_product(self) -> u8230     pub fn element_product(self) -> u8 {
231         self.x * self.y
232     }
233 
234     /// Returns a vector mask containing the result of a `==` comparison for each element of
235     /// `self` and `rhs`.
236     ///
237     /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
238     /// elements.
239     #[inline]
240     #[must_use]
cmpeq(self, rhs: Self) -> BVec2241     pub fn cmpeq(self, rhs: Self) -> BVec2 {
242         BVec2::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y))
243     }
244 
245     /// Returns a vector mask containing the result of a `!=` comparison for each element of
246     /// `self` and `rhs`.
247     ///
248     /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
249     /// elements.
250     #[inline]
251     #[must_use]
cmpne(self, rhs: Self) -> BVec2252     pub fn cmpne(self, rhs: Self) -> BVec2 {
253         BVec2::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y))
254     }
255 
256     /// Returns a vector mask containing the result of a `>=` comparison for each element of
257     /// `self` and `rhs`.
258     ///
259     /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
260     /// elements.
261     #[inline]
262     #[must_use]
cmpge(self, rhs: Self) -> BVec2263     pub fn cmpge(self, rhs: Self) -> BVec2 {
264         BVec2::new(self.x.ge(&rhs.x), self.y.ge(&rhs.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]
cmpgt(self, rhs: Self) -> BVec2274     pub fn cmpgt(self, rhs: Self) -> BVec2 {
275         BVec2::new(self.x.gt(&rhs.x), self.y.gt(&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]
cmple(self, rhs: Self) -> BVec2285     pub fn cmple(self, rhs: Self) -> BVec2 {
286         BVec2::new(self.x.le(&rhs.x), self.y.le(&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]
cmplt(self, rhs: Self) -> BVec2296     pub fn cmplt(self, rhs: Self) -> BVec2 {
297         BVec2::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y))
298     }
299 
300     /// Computes the squared length of `self`.
301     #[doc(alias = "magnitude2")]
302     #[inline]
303     #[must_use]
length_squared(self) -> u8304     pub fn length_squared(self) -> u8 {
305         self.dot(self)
306     }
307 
308     /// Computes the [manhattan distance] between two points.
309     ///
310     /// # Overflow
311     /// This method may overflow if the result is greater than [`u8::MAX`].
312     ///
313     /// See also [`checked_manhattan_distance`][U8Vec2::checked_manhattan_distance].
314     ///
315     /// [manhattan distance]: https://en.wikipedia.org/wiki/Taxicab_geometry
316     #[inline]
317     #[must_use]
manhattan_distance(self, other: Self) -> u8318     pub fn manhattan_distance(self, other: Self) -> u8 {
319         self.x.abs_diff(other.x) + self.y.abs_diff(other.y)
320     }
321 
322     /// Computes the [manhattan distance] between two points.
323     ///
324     /// This will returns [`None`] if the result is greater than [`u8::MAX`].
325     ///
326     /// [manhattan distance]: https://en.wikipedia.org/wiki/Taxicab_geometry
327     #[inline]
328     #[must_use]
checked_manhattan_distance(self, other: Self) -> Option<u8>329     pub fn checked_manhattan_distance(self, other: Self) -> Option<u8> {
330         let d = self.x.abs_diff(other.x);
331         d.checked_add(self.y.abs_diff(other.y))
332     }
333 
334     /// Computes the [chebyshev distance] between two points.
335     ///
336     /// [chebyshev distance]: https://en.wikipedia.org/wiki/Chebyshev_distance
337     #[inline]
338     #[must_use]
chebyshev_distance(self, other: Self) -> u8339     pub fn chebyshev_distance(self, other: Self) -> u8 {
340         // Note: the compiler will eventually optimize out the loop
341         [self.x.abs_diff(other.x), self.y.abs_diff(other.y)]
342             .into_iter()
343             .max()
344             .unwrap()
345     }
346 
347     /// Casts all elements of `self` to `f32`.
348     #[inline]
349     #[must_use]
as_vec2(&self) -> crate::Vec2350     pub fn as_vec2(&self) -> crate::Vec2 {
351         crate::Vec2::new(self.x as f32, self.y as f32)
352     }
353 
354     /// Casts all elements of `self` to `f64`.
355     #[inline]
356     #[must_use]
as_dvec2(&self) -> crate::DVec2357     pub fn as_dvec2(&self) -> crate::DVec2 {
358         crate::DVec2::new(self.x as f64, self.y as f64)
359     }
360 
361     /// Casts all elements of `self` to `i8`.
362     #[inline]
363     #[must_use]
as_i8vec2(&self) -> crate::I8Vec2364     pub fn as_i8vec2(&self) -> crate::I8Vec2 {
365         crate::I8Vec2::new(self.x as i8, self.y as i8)
366     }
367 
368     /// Casts all elements of `self` to `i16`.
369     #[inline]
370     #[must_use]
as_i16vec2(&self) -> crate::I16Vec2371     pub fn as_i16vec2(&self) -> crate::I16Vec2 {
372         crate::I16Vec2::new(self.x as i16, self.y as i16)
373     }
374 
375     /// Casts all elements of `self` to `u16`.
376     #[inline]
377     #[must_use]
as_u16vec2(&self) -> crate::U16Vec2378     pub fn as_u16vec2(&self) -> crate::U16Vec2 {
379         crate::U16Vec2::new(self.x as u16, self.y as u16)
380     }
381 
382     /// Casts all elements of `self` to `i32`.
383     #[inline]
384     #[must_use]
as_ivec2(&self) -> crate::IVec2385     pub fn as_ivec2(&self) -> crate::IVec2 {
386         crate::IVec2::new(self.x as i32, self.y as i32)
387     }
388 
389     /// Casts all elements of `self` to `u32`.
390     #[inline]
391     #[must_use]
as_uvec2(&self) -> crate::UVec2392     pub fn as_uvec2(&self) -> crate::UVec2 {
393         crate::UVec2::new(self.x as u32, self.y as u32)
394     }
395 
396     /// Casts all elements of `self` to `i64`.
397     #[inline]
398     #[must_use]
as_i64vec2(&self) -> crate::I64Vec2399     pub fn as_i64vec2(&self) -> crate::I64Vec2 {
400         crate::I64Vec2::new(self.x as i64, self.y as i64)
401     }
402 
403     /// Casts all elements of `self` to `u64`.
404     #[inline]
405     #[must_use]
as_u64vec2(&self) -> crate::U64Vec2406     pub fn as_u64vec2(&self) -> crate::U64Vec2 {
407         crate::U64Vec2::new(self.x as u64, self.y as u64)
408     }
409 
410     /// Returns a vector containing the wrapping addition of `self` and `rhs`.
411     ///
412     /// In other words this computes `Some([self.x + rhs.x, self.y + rhs.y, ..])` but returns `None` on any overflow.
413     #[inline]
414     #[must_use]
checked_add(self, rhs: Self) -> Option<Self>415     pub const fn checked_add(self, rhs: Self) -> Option<Self> {
416         let x = match self.x.checked_add(rhs.x) {
417             Some(v) => v,
418             None => return None,
419         };
420         let y = match self.y.checked_add(rhs.y) {
421             Some(v) => v,
422             None => return None,
423         };
424 
425         Some(Self { x, y })
426     }
427 
428     /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
429     ///
430     /// In other words this computes `Some([self.x - rhs.x, self.y - rhs.y, ..])` but returns `None` on any overflow.
431     #[inline]
432     #[must_use]
checked_sub(self, rhs: Self) -> Option<Self>433     pub const fn checked_sub(self, rhs: Self) -> Option<Self> {
434         let x = match self.x.checked_sub(rhs.x) {
435             Some(v) => v,
436             None => return None,
437         };
438         let y = match self.y.checked_sub(rhs.y) {
439             Some(v) => v,
440             None => return None,
441         };
442 
443         Some(Self { x, y })
444     }
445 
446     /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
447     ///
448     /// In other words this computes `Some([self.x * rhs.x, self.y * rhs.y, ..])` but returns `None` on any overflow.
449     #[inline]
450     #[must_use]
checked_mul(self, rhs: Self) -> Option<Self>451     pub const fn checked_mul(self, rhs: Self) -> Option<Self> {
452         let x = match self.x.checked_mul(rhs.x) {
453             Some(v) => v,
454             None => return None,
455         };
456         let y = match self.y.checked_mul(rhs.y) {
457             Some(v) => v,
458             None => return None,
459         };
460 
461         Some(Self { x, y })
462     }
463 
464     /// Returns a vector containing the wrapping division of `self` and `rhs`.
465     ///
466     /// In other words this computes `Some([self.x / rhs.x, self.y / rhs.y, ..])` but returns `None` on any division by zero.
467     #[inline]
468     #[must_use]
checked_div(self, rhs: Self) -> Option<Self>469     pub const fn checked_div(self, rhs: Self) -> Option<Self> {
470         let x = match self.x.checked_div(rhs.x) {
471             Some(v) => v,
472             None => return None,
473         };
474         let y = match self.y.checked_div(rhs.y) {
475             Some(v) => v,
476             None => return None,
477         };
478 
479         Some(Self { x, y })
480     }
481 
482     /// Returns a vector containing the wrapping addition of `self` and `rhs`.
483     ///
484     /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`.
485     #[inline]
486     #[must_use]
wrapping_add(self, rhs: Self) -> Self487     pub const fn wrapping_add(self, rhs: Self) -> Self {
488         Self {
489             x: self.x.wrapping_add(rhs.x),
490             y: self.y.wrapping_add(rhs.y),
491         }
492     }
493 
494     /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
495     ///
496     /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`.
497     #[inline]
498     #[must_use]
wrapping_sub(self, rhs: Self) -> Self499     pub const fn wrapping_sub(self, rhs: Self) -> Self {
500         Self {
501             x: self.x.wrapping_sub(rhs.x),
502             y: self.y.wrapping_sub(rhs.y),
503         }
504     }
505 
506     /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
507     ///
508     /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`.
509     #[inline]
510     #[must_use]
wrapping_mul(self, rhs: Self) -> Self511     pub const fn wrapping_mul(self, rhs: Self) -> Self {
512         Self {
513             x: self.x.wrapping_mul(rhs.x),
514             y: self.y.wrapping_mul(rhs.y),
515         }
516     }
517 
518     /// Returns a vector containing the wrapping division of `self` and `rhs`.
519     ///
520     /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`.
521     #[inline]
522     #[must_use]
wrapping_div(self, rhs: Self) -> Self523     pub const fn wrapping_div(self, rhs: Self) -> Self {
524         Self {
525             x: self.x.wrapping_div(rhs.x),
526             y: self.y.wrapping_div(rhs.y),
527         }
528     }
529 
530     /// Returns a vector containing the saturating addition of `self` and `rhs`.
531     ///
532     /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`.
533     #[inline]
534     #[must_use]
saturating_add(self, rhs: Self) -> Self535     pub const fn saturating_add(self, rhs: Self) -> Self {
536         Self {
537             x: self.x.saturating_add(rhs.x),
538             y: self.y.saturating_add(rhs.y),
539         }
540     }
541 
542     /// Returns a vector containing the saturating subtraction of `self` and `rhs`.
543     ///
544     /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`.
545     #[inline]
546     #[must_use]
saturating_sub(self, rhs: Self) -> Self547     pub const fn saturating_sub(self, rhs: Self) -> Self {
548         Self {
549             x: self.x.saturating_sub(rhs.x),
550             y: self.y.saturating_sub(rhs.y),
551         }
552     }
553 
554     /// Returns a vector containing the saturating multiplication of `self` and `rhs`.
555     ///
556     /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`.
557     #[inline]
558     #[must_use]
saturating_mul(self, rhs: Self) -> Self559     pub const fn saturating_mul(self, rhs: Self) -> Self {
560         Self {
561             x: self.x.saturating_mul(rhs.x),
562             y: self.y.saturating_mul(rhs.y),
563         }
564     }
565 
566     /// Returns a vector containing the saturating division of `self` and `rhs`.
567     ///
568     /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`.
569     #[inline]
570     #[must_use]
saturating_div(self, rhs: Self) -> Self571     pub const fn saturating_div(self, rhs: Self) -> Self {
572         Self {
573             x: self.x.saturating_div(rhs.x),
574             y: self.y.saturating_div(rhs.y),
575         }
576     }
577 
578     /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`.
579     ///
580     /// In other words this computes `Some([self.x + rhs.x, self.y + rhs.y, ..])` but returns `None` on any overflow.
581     #[inline]
582     #[must_use]
checked_add_signed(self, rhs: I8Vec2) -> Option<Self>583     pub const fn checked_add_signed(self, rhs: I8Vec2) -> Option<Self> {
584         let x = match self.x.checked_add_signed(rhs.x) {
585             Some(v) => v,
586             None => return None,
587         };
588         let y = match self.y.checked_add_signed(rhs.y) {
589             Some(v) => v,
590             None => return None,
591         };
592 
593         Some(Self { x, y })
594     }
595 
596     /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`.
597     ///
598     /// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`.
599     #[inline]
600     #[must_use]
wrapping_add_signed(self, rhs: I8Vec2) -> Self601     pub const fn wrapping_add_signed(self, rhs: I8Vec2) -> Self {
602         Self {
603             x: self.x.wrapping_add_signed(rhs.x),
604             y: self.y.wrapping_add_signed(rhs.y),
605         }
606     }
607 
608     /// Returns a vector containing the saturating addition of `self` and signed vector `rhs`.
609     ///
610     /// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`.
611     #[inline]
612     #[must_use]
saturating_add_signed(self, rhs: I8Vec2) -> Self613     pub const fn saturating_add_signed(self, rhs: I8Vec2) -> Self {
614         Self {
615             x: self.x.saturating_add_signed(rhs.x),
616             y: self.y.saturating_add_signed(rhs.y),
617         }
618     }
619 }
620 
621 impl Default for U8Vec2 {
622     #[inline(always)]
default() -> Self623     fn default() -> Self {
624         Self::ZERO
625     }
626 }
627 
628 impl Div<U8Vec2> for U8Vec2 {
629     type Output = Self;
630     #[inline]
div(self, rhs: Self) -> Self631     fn div(self, rhs: Self) -> Self {
632         Self {
633             x: self.x.div(rhs.x),
634             y: self.y.div(rhs.y),
635         }
636     }
637 }
638 
639 impl Div<&U8Vec2> for U8Vec2 {
640     type Output = U8Vec2;
641     #[inline]
div(self, rhs: &U8Vec2) -> U8Vec2642     fn div(self, rhs: &U8Vec2) -> U8Vec2 {
643         self.div(*rhs)
644     }
645 }
646 
647 impl Div<&U8Vec2> for &U8Vec2 {
648     type Output = U8Vec2;
649     #[inline]
div(self, rhs: &U8Vec2) -> U8Vec2650     fn div(self, rhs: &U8Vec2) -> U8Vec2 {
651         (*self).div(*rhs)
652     }
653 }
654 
655 impl Div<U8Vec2> for &U8Vec2 {
656     type Output = U8Vec2;
657     #[inline]
div(self, rhs: U8Vec2) -> U8Vec2658     fn div(self, rhs: U8Vec2) -> U8Vec2 {
659         (*self).div(rhs)
660     }
661 }
662 
663 impl DivAssign<U8Vec2> for U8Vec2 {
664     #[inline]
div_assign(&mut self, rhs: Self)665     fn div_assign(&mut self, rhs: Self) {
666         self.x.div_assign(rhs.x);
667         self.y.div_assign(rhs.y);
668     }
669 }
670 
671 impl DivAssign<&U8Vec2> for U8Vec2 {
672     #[inline]
div_assign(&mut self, rhs: &U8Vec2)673     fn div_assign(&mut self, rhs: &U8Vec2) {
674         self.div_assign(*rhs)
675     }
676 }
677 
678 impl Div<u8> for U8Vec2 {
679     type Output = Self;
680     #[inline]
div(self, rhs: u8) -> Self681     fn div(self, rhs: u8) -> Self {
682         Self {
683             x: self.x.div(rhs),
684             y: self.y.div(rhs),
685         }
686     }
687 }
688 
689 impl Div<&u8> for U8Vec2 {
690     type Output = U8Vec2;
691     #[inline]
div(self, rhs: &u8) -> U8Vec2692     fn div(self, rhs: &u8) -> U8Vec2 {
693         self.div(*rhs)
694     }
695 }
696 
697 impl Div<&u8> for &U8Vec2 {
698     type Output = U8Vec2;
699     #[inline]
div(self, rhs: &u8) -> U8Vec2700     fn div(self, rhs: &u8) -> U8Vec2 {
701         (*self).div(*rhs)
702     }
703 }
704 
705 impl Div<u8> for &U8Vec2 {
706     type Output = U8Vec2;
707     #[inline]
div(self, rhs: u8) -> U8Vec2708     fn div(self, rhs: u8) -> U8Vec2 {
709         (*self).div(rhs)
710     }
711 }
712 
713 impl DivAssign<u8> for U8Vec2 {
714     #[inline]
div_assign(&mut self, rhs: u8)715     fn div_assign(&mut self, rhs: u8) {
716         self.x.div_assign(rhs);
717         self.y.div_assign(rhs);
718     }
719 }
720 
721 impl DivAssign<&u8> for U8Vec2 {
722     #[inline]
div_assign(&mut self, rhs: &u8)723     fn div_assign(&mut self, rhs: &u8) {
724         self.div_assign(*rhs)
725     }
726 }
727 
728 impl Div<U8Vec2> for u8 {
729     type Output = U8Vec2;
730     #[inline]
div(self, rhs: U8Vec2) -> U8Vec2731     fn div(self, rhs: U8Vec2) -> U8Vec2 {
732         U8Vec2 {
733             x: self.div(rhs.x),
734             y: self.div(rhs.y),
735         }
736     }
737 }
738 
739 impl Div<&U8Vec2> for u8 {
740     type Output = U8Vec2;
741     #[inline]
div(self, rhs: &U8Vec2) -> U8Vec2742     fn div(self, rhs: &U8Vec2) -> U8Vec2 {
743         self.div(*rhs)
744     }
745 }
746 
747 impl Div<&U8Vec2> for &u8 {
748     type Output = U8Vec2;
749     #[inline]
div(self, rhs: &U8Vec2) -> U8Vec2750     fn div(self, rhs: &U8Vec2) -> U8Vec2 {
751         (*self).div(*rhs)
752     }
753 }
754 
755 impl Div<U8Vec2> for &u8 {
756     type Output = U8Vec2;
757     #[inline]
div(self, rhs: U8Vec2) -> U8Vec2758     fn div(self, rhs: U8Vec2) -> U8Vec2 {
759         (*self).div(rhs)
760     }
761 }
762 
763 impl Mul<U8Vec2> for U8Vec2 {
764     type Output = Self;
765     #[inline]
mul(self, rhs: Self) -> Self766     fn mul(self, rhs: Self) -> Self {
767         Self {
768             x: self.x.mul(rhs.x),
769             y: self.y.mul(rhs.y),
770         }
771     }
772 }
773 
774 impl Mul<&U8Vec2> for U8Vec2 {
775     type Output = U8Vec2;
776     #[inline]
mul(self, rhs: &U8Vec2) -> U8Vec2777     fn mul(self, rhs: &U8Vec2) -> U8Vec2 {
778         self.mul(*rhs)
779     }
780 }
781 
782 impl Mul<&U8Vec2> for &U8Vec2 {
783     type Output = U8Vec2;
784     #[inline]
mul(self, rhs: &U8Vec2) -> U8Vec2785     fn mul(self, rhs: &U8Vec2) -> U8Vec2 {
786         (*self).mul(*rhs)
787     }
788 }
789 
790 impl Mul<U8Vec2> for &U8Vec2 {
791     type Output = U8Vec2;
792     #[inline]
mul(self, rhs: U8Vec2) -> U8Vec2793     fn mul(self, rhs: U8Vec2) -> U8Vec2 {
794         (*self).mul(rhs)
795     }
796 }
797 
798 impl MulAssign<U8Vec2> for U8Vec2 {
799     #[inline]
mul_assign(&mut self, rhs: Self)800     fn mul_assign(&mut self, rhs: Self) {
801         self.x.mul_assign(rhs.x);
802         self.y.mul_assign(rhs.y);
803     }
804 }
805 
806 impl MulAssign<&U8Vec2> for U8Vec2 {
807     #[inline]
mul_assign(&mut self, rhs: &U8Vec2)808     fn mul_assign(&mut self, rhs: &U8Vec2) {
809         self.mul_assign(*rhs)
810     }
811 }
812 
813 impl Mul<u8> for U8Vec2 {
814     type Output = Self;
815     #[inline]
mul(self, rhs: u8) -> Self816     fn mul(self, rhs: u8) -> Self {
817         Self {
818             x: self.x.mul(rhs),
819             y: self.y.mul(rhs),
820         }
821     }
822 }
823 
824 impl Mul<&u8> for U8Vec2 {
825     type Output = U8Vec2;
826     #[inline]
mul(self, rhs: &u8) -> U8Vec2827     fn mul(self, rhs: &u8) -> U8Vec2 {
828         self.mul(*rhs)
829     }
830 }
831 
832 impl Mul<&u8> for &U8Vec2 {
833     type Output = U8Vec2;
834     #[inline]
mul(self, rhs: &u8) -> U8Vec2835     fn mul(self, rhs: &u8) -> U8Vec2 {
836         (*self).mul(*rhs)
837     }
838 }
839 
840 impl Mul<u8> for &U8Vec2 {
841     type Output = U8Vec2;
842     #[inline]
mul(self, rhs: u8) -> U8Vec2843     fn mul(self, rhs: u8) -> U8Vec2 {
844         (*self).mul(rhs)
845     }
846 }
847 
848 impl MulAssign<u8> for U8Vec2 {
849     #[inline]
mul_assign(&mut self, rhs: u8)850     fn mul_assign(&mut self, rhs: u8) {
851         self.x.mul_assign(rhs);
852         self.y.mul_assign(rhs);
853     }
854 }
855 
856 impl MulAssign<&u8> for U8Vec2 {
857     #[inline]
mul_assign(&mut self, rhs: &u8)858     fn mul_assign(&mut self, rhs: &u8) {
859         self.mul_assign(*rhs)
860     }
861 }
862 
863 impl Mul<U8Vec2> for u8 {
864     type Output = U8Vec2;
865     #[inline]
mul(self, rhs: U8Vec2) -> U8Vec2866     fn mul(self, rhs: U8Vec2) -> U8Vec2 {
867         U8Vec2 {
868             x: self.mul(rhs.x),
869             y: self.mul(rhs.y),
870         }
871     }
872 }
873 
874 impl Mul<&U8Vec2> for u8 {
875     type Output = U8Vec2;
876     #[inline]
mul(self, rhs: &U8Vec2) -> U8Vec2877     fn mul(self, rhs: &U8Vec2) -> U8Vec2 {
878         self.mul(*rhs)
879     }
880 }
881 
882 impl Mul<&U8Vec2> for &u8 {
883     type Output = U8Vec2;
884     #[inline]
mul(self, rhs: &U8Vec2) -> U8Vec2885     fn mul(self, rhs: &U8Vec2) -> U8Vec2 {
886         (*self).mul(*rhs)
887     }
888 }
889 
890 impl Mul<U8Vec2> for &u8 {
891     type Output = U8Vec2;
892     #[inline]
mul(self, rhs: U8Vec2) -> U8Vec2893     fn mul(self, rhs: U8Vec2) -> U8Vec2 {
894         (*self).mul(rhs)
895     }
896 }
897 
898 impl Add<U8Vec2> for U8Vec2 {
899     type Output = Self;
900     #[inline]
add(self, rhs: Self) -> Self901     fn add(self, rhs: Self) -> Self {
902         Self {
903             x: self.x.add(rhs.x),
904             y: self.y.add(rhs.y),
905         }
906     }
907 }
908 
909 impl Add<&U8Vec2> for U8Vec2 {
910     type Output = U8Vec2;
911     #[inline]
add(self, rhs: &U8Vec2) -> U8Vec2912     fn add(self, rhs: &U8Vec2) -> U8Vec2 {
913         self.add(*rhs)
914     }
915 }
916 
917 impl Add<&U8Vec2> for &U8Vec2 {
918     type Output = U8Vec2;
919     #[inline]
add(self, rhs: &U8Vec2) -> U8Vec2920     fn add(self, rhs: &U8Vec2) -> U8Vec2 {
921         (*self).add(*rhs)
922     }
923 }
924 
925 impl Add<U8Vec2> for &U8Vec2 {
926     type Output = U8Vec2;
927     #[inline]
add(self, rhs: U8Vec2) -> U8Vec2928     fn add(self, rhs: U8Vec2) -> U8Vec2 {
929         (*self).add(rhs)
930     }
931 }
932 
933 impl AddAssign<U8Vec2> for U8Vec2 {
934     #[inline]
add_assign(&mut self, rhs: Self)935     fn add_assign(&mut self, rhs: Self) {
936         self.x.add_assign(rhs.x);
937         self.y.add_assign(rhs.y);
938     }
939 }
940 
941 impl AddAssign<&U8Vec2> for U8Vec2 {
942     #[inline]
add_assign(&mut self, rhs: &U8Vec2)943     fn add_assign(&mut self, rhs: &U8Vec2) {
944         self.add_assign(*rhs)
945     }
946 }
947 
948 impl Add<u8> for U8Vec2 {
949     type Output = Self;
950     #[inline]
add(self, rhs: u8) -> Self951     fn add(self, rhs: u8) -> Self {
952         Self {
953             x: self.x.add(rhs),
954             y: self.y.add(rhs),
955         }
956     }
957 }
958 
959 impl Add<&u8> for U8Vec2 {
960     type Output = U8Vec2;
961     #[inline]
add(self, rhs: &u8) -> U8Vec2962     fn add(self, rhs: &u8) -> U8Vec2 {
963         self.add(*rhs)
964     }
965 }
966 
967 impl Add<&u8> for &U8Vec2 {
968     type Output = U8Vec2;
969     #[inline]
add(self, rhs: &u8) -> U8Vec2970     fn add(self, rhs: &u8) -> U8Vec2 {
971         (*self).add(*rhs)
972     }
973 }
974 
975 impl Add<u8> for &U8Vec2 {
976     type Output = U8Vec2;
977     #[inline]
add(self, rhs: u8) -> U8Vec2978     fn add(self, rhs: u8) -> U8Vec2 {
979         (*self).add(rhs)
980     }
981 }
982 
983 impl AddAssign<u8> for U8Vec2 {
984     #[inline]
add_assign(&mut self, rhs: u8)985     fn add_assign(&mut self, rhs: u8) {
986         self.x.add_assign(rhs);
987         self.y.add_assign(rhs);
988     }
989 }
990 
991 impl AddAssign<&u8> for U8Vec2 {
992     #[inline]
add_assign(&mut self, rhs: &u8)993     fn add_assign(&mut self, rhs: &u8) {
994         self.add_assign(*rhs)
995     }
996 }
997 
998 impl Add<U8Vec2> for u8 {
999     type Output = U8Vec2;
1000     #[inline]
add(self, rhs: U8Vec2) -> U8Vec21001     fn add(self, rhs: U8Vec2) -> U8Vec2 {
1002         U8Vec2 {
1003             x: self.add(rhs.x),
1004             y: self.add(rhs.y),
1005         }
1006     }
1007 }
1008 
1009 impl Add<&U8Vec2> for u8 {
1010     type Output = U8Vec2;
1011     #[inline]
add(self, rhs: &U8Vec2) -> U8Vec21012     fn add(self, rhs: &U8Vec2) -> U8Vec2 {
1013         self.add(*rhs)
1014     }
1015 }
1016 
1017 impl Add<&U8Vec2> for &u8 {
1018     type Output = U8Vec2;
1019     #[inline]
add(self, rhs: &U8Vec2) -> U8Vec21020     fn add(self, rhs: &U8Vec2) -> U8Vec2 {
1021         (*self).add(*rhs)
1022     }
1023 }
1024 
1025 impl Add<U8Vec2> for &u8 {
1026     type Output = U8Vec2;
1027     #[inline]
add(self, rhs: U8Vec2) -> U8Vec21028     fn add(self, rhs: U8Vec2) -> U8Vec2 {
1029         (*self).add(rhs)
1030     }
1031 }
1032 
1033 impl Sub<U8Vec2> for U8Vec2 {
1034     type Output = Self;
1035     #[inline]
sub(self, rhs: Self) -> Self1036     fn sub(self, rhs: Self) -> Self {
1037         Self {
1038             x: self.x.sub(rhs.x),
1039             y: self.y.sub(rhs.y),
1040         }
1041     }
1042 }
1043 
1044 impl Sub<&U8Vec2> for U8Vec2 {
1045     type Output = U8Vec2;
1046     #[inline]
sub(self, rhs: &U8Vec2) -> U8Vec21047     fn sub(self, rhs: &U8Vec2) -> U8Vec2 {
1048         self.sub(*rhs)
1049     }
1050 }
1051 
1052 impl Sub<&U8Vec2> for &U8Vec2 {
1053     type Output = U8Vec2;
1054     #[inline]
sub(self, rhs: &U8Vec2) -> U8Vec21055     fn sub(self, rhs: &U8Vec2) -> U8Vec2 {
1056         (*self).sub(*rhs)
1057     }
1058 }
1059 
1060 impl Sub<U8Vec2> for &U8Vec2 {
1061     type Output = U8Vec2;
1062     #[inline]
sub(self, rhs: U8Vec2) -> U8Vec21063     fn sub(self, rhs: U8Vec2) -> U8Vec2 {
1064         (*self).sub(rhs)
1065     }
1066 }
1067 
1068 impl SubAssign<U8Vec2> for U8Vec2 {
1069     #[inline]
sub_assign(&mut self, rhs: U8Vec2)1070     fn sub_assign(&mut self, rhs: U8Vec2) {
1071         self.x.sub_assign(rhs.x);
1072         self.y.sub_assign(rhs.y);
1073     }
1074 }
1075 
1076 impl SubAssign<&U8Vec2> for U8Vec2 {
1077     #[inline]
sub_assign(&mut self, rhs: &U8Vec2)1078     fn sub_assign(&mut self, rhs: &U8Vec2) {
1079         self.sub_assign(*rhs)
1080     }
1081 }
1082 
1083 impl Sub<u8> for U8Vec2 {
1084     type Output = Self;
1085     #[inline]
sub(self, rhs: u8) -> Self1086     fn sub(self, rhs: u8) -> Self {
1087         Self {
1088             x: self.x.sub(rhs),
1089             y: self.y.sub(rhs),
1090         }
1091     }
1092 }
1093 
1094 impl Sub<&u8> for U8Vec2 {
1095     type Output = U8Vec2;
1096     #[inline]
sub(self, rhs: &u8) -> U8Vec21097     fn sub(self, rhs: &u8) -> U8Vec2 {
1098         self.sub(*rhs)
1099     }
1100 }
1101 
1102 impl Sub<&u8> for &U8Vec2 {
1103     type Output = U8Vec2;
1104     #[inline]
sub(self, rhs: &u8) -> U8Vec21105     fn sub(self, rhs: &u8) -> U8Vec2 {
1106         (*self).sub(*rhs)
1107     }
1108 }
1109 
1110 impl Sub<u8> for &U8Vec2 {
1111     type Output = U8Vec2;
1112     #[inline]
sub(self, rhs: u8) -> U8Vec21113     fn sub(self, rhs: u8) -> U8Vec2 {
1114         (*self).sub(rhs)
1115     }
1116 }
1117 
1118 impl SubAssign<u8> for U8Vec2 {
1119     #[inline]
sub_assign(&mut self, rhs: u8)1120     fn sub_assign(&mut self, rhs: u8) {
1121         self.x.sub_assign(rhs);
1122         self.y.sub_assign(rhs);
1123     }
1124 }
1125 
1126 impl SubAssign<&u8> for U8Vec2 {
1127     #[inline]
sub_assign(&mut self, rhs: &u8)1128     fn sub_assign(&mut self, rhs: &u8) {
1129         self.sub_assign(*rhs)
1130     }
1131 }
1132 
1133 impl Sub<U8Vec2> for u8 {
1134     type Output = U8Vec2;
1135     #[inline]
sub(self, rhs: U8Vec2) -> U8Vec21136     fn sub(self, rhs: U8Vec2) -> U8Vec2 {
1137         U8Vec2 {
1138             x: self.sub(rhs.x),
1139             y: self.sub(rhs.y),
1140         }
1141     }
1142 }
1143 
1144 impl Sub<&U8Vec2> for u8 {
1145     type Output = U8Vec2;
1146     #[inline]
sub(self, rhs: &U8Vec2) -> U8Vec21147     fn sub(self, rhs: &U8Vec2) -> U8Vec2 {
1148         self.sub(*rhs)
1149     }
1150 }
1151 
1152 impl Sub<&U8Vec2> for &u8 {
1153     type Output = U8Vec2;
1154     #[inline]
sub(self, rhs: &U8Vec2) -> U8Vec21155     fn sub(self, rhs: &U8Vec2) -> U8Vec2 {
1156         (*self).sub(*rhs)
1157     }
1158 }
1159 
1160 impl Sub<U8Vec2> for &u8 {
1161     type Output = U8Vec2;
1162     #[inline]
sub(self, rhs: U8Vec2) -> U8Vec21163     fn sub(self, rhs: U8Vec2) -> U8Vec2 {
1164         (*self).sub(rhs)
1165     }
1166 }
1167 
1168 impl Rem<U8Vec2> for U8Vec2 {
1169     type Output = Self;
1170     #[inline]
rem(self, rhs: Self) -> Self1171     fn rem(self, rhs: Self) -> Self {
1172         Self {
1173             x: self.x.rem(rhs.x),
1174             y: self.y.rem(rhs.y),
1175         }
1176     }
1177 }
1178 
1179 impl Rem<&U8Vec2> for U8Vec2 {
1180     type Output = U8Vec2;
1181     #[inline]
rem(self, rhs: &U8Vec2) -> U8Vec21182     fn rem(self, rhs: &U8Vec2) -> U8Vec2 {
1183         self.rem(*rhs)
1184     }
1185 }
1186 
1187 impl Rem<&U8Vec2> for &U8Vec2 {
1188     type Output = U8Vec2;
1189     #[inline]
rem(self, rhs: &U8Vec2) -> U8Vec21190     fn rem(self, rhs: &U8Vec2) -> U8Vec2 {
1191         (*self).rem(*rhs)
1192     }
1193 }
1194 
1195 impl Rem<U8Vec2> for &U8Vec2 {
1196     type Output = U8Vec2;
1197     #[inline]
rem(self, rhs: U8Vec2) -> U8Vec21198     fn rem(self, rhs: U8Vec2) -> U8Vec2 {
1199         (*self).rem(rhs)
1200     }
1201 }
1202 
1203 impl RemAssign<U8Vec2> for U8Vec2 {
1204     #[inline]
rem_assign(&mut self, rhs: Self)1205     fn rem_assign(&mut self, rhs: Self) {
1206         self.x.rem_assign(rhs.x);
1207         self.y.rem_assign(rhs.y);
1208     }
1209 }
1210 
1211 impl RemAssign<&U8Vec2> for U8Vec2 {
1212     #[inline]
rem_assign(&mut self, rhs: &U8Vec2)1213     fn rem_assign(&mut self, rhs: &U8Vec2) {
1214         self.rem_assign(*rhs)
1215     }
1216 }
1217 
1218 impl Rem<u8> for U8Vec2 {
1219     type Output = Self;
1220     #[inline]
rem(self, rhs: u8) -> Self1221     fn rem(self, rhs: u8) -> Self {
1222         Self {
1223             x: self.x.rem(rhs),
1224             y: self.y.rem(rhs),
1225         }
1226     }
1227 }
1228 
1229 impl Rem<&u8> for U8Vec2 {
1230     type Output = U8Vec2;
1231     #[inline]
rem(self, rhs: &u8) -> U8Vec21232     fn rem(self, rhs: &u8) -> U8Vec2 {
1233         self.rem(*rhs)
1234     }
1235 }
1236 
1237 impl Rem<&u8> for &U8Vec2 {
1238     type Output = U8Vec2;
1239     #[inline]
rem(self, rhs: &u8) -> U8Vec21240     fn rem(self, rhs: &u8) -> U8Vec2 {
1241         (*self).rem(*rhs)
1242     }
1243 }
1244 
1245 impl Rem<u8> for &U8Vec2 {
1246     type Output = U8Vec2;
1247     #[inline]
rem(self, rhs: u8) -> U8Vec21248     fn rem(self, rhs: u8) -> U8Vec2 {
1249         (*self).rem(rhs)
1250     }
1251 }
1252 
1253 impl RemAssign<u8> for U8Vec2 {
1254     #[inline]
rem_assign(&mut self, rhs: u8)1255     fn rem_assign(&mut self, rhs: u8) {
1256         self.x.rem_assign(rhs);
1257         self.y.rem_assign(rhs);
1258     }
1259 }
1260 
1261 impl RemAssign<&u8> for U8Vec2 {
1262     #[inline]
rem_assign(&mut self, rhs: &u8)1263     fn rem_assign(&mut self, rhs: &u8) {
1264         self.rem_assign(*rhs)
1265     }
1266 }
1267 
1268 impl Rem<U8Vec2> for u8 {
1269     type Output = U8Vec2;
1270     #[inline]
rem(self, rhs: U8Vec2) -> U8Vec21271     fn rem(self, rhs: U8Vec2) -> U8Vec2 {
1272         U8Vec2 {
1273             x: self.rem(rhs.x),
1274             y: self.rem(rhs.y),
1275         }
1276     }
1277 }
1278 
1279 impl Rem<&U8Vec2> for u8 {
1280     type Output = U8Vec2;
1281     #[inline]
rem(self, rhs: &U8Vec2) -> U8Vec21282     fn rem(self, rhs: &U8Vec2) -> U8Vec2 {
1283         self.rem(*rhs)
1284     }
1285 }
1286 
1287 impl Rem<&U8Vec2> for &u8 {
1288     type Output = U8Vec2;
1289     #[inline]
rem(self, rhs: &U8Vec2) -> U8Vec21290     fn rem(self, rhs: &U8Vec2) -> U8Vec2 {
1291         (*self).rem(*rhs)
1292     }
1293 }
1294 
1295 impl Rem<U8Vec2> for &u8 {
1296     type Output = U8Vec2;
1297     #[inline]
rem(self, rhs: U8Vec2) -> U8Vec21298     fn rem(self, rhs: U8Vec2) -> U8Vec2 {
1299         (*self).rem(rhs)
1300     }
1301 }
1302 
1303 #[cfg(not(target_arch = "spirv"))]
1304 impl AsRef<[u8; 2]> for U8Vec2 {
1305     #[inline]
as_ref(&self) -> &[u8; 2]1306     fn as_ref(&self) -> &[u8; 2] {
1307         unsafe { &*(self as *const U8Vec2 as *const [u8; 2]) }
1308     }
1309 }
1310 
1311 #[cfg(not(target_arch = "spirv"))]
1312 impl AsMut<[u8; 2]> for U8Vec2 {
1313     #[inline]
as_mut(&mut self) -> &mut [u8; 2]1314     fn as_mut(&mut self) -> &mut [u8; 2] {
1315         unsafe { &mut *(self as *mut U8Vec2 as *mut [u8; 2]) }
1316     }
1317 }
1318 
1319 impl Sum for U8Vec2 {
1320     #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = Self>,1321     fn sum<I>(iter: I) -> Self
1322     where
1323         I: Iterator<Item = Self>,
1324     {
1325         iter.fold(Self::ZERO, Self::add)
1326     }
1327 }
1328 
1329 impl<'a> Sum<&'a Self> for U8Vec2 {
1330     #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,1331     fn sum<I>(iter: I) -> Self
1332     where
1333         I: Iterator<Item = &'a Self>,
1334     {
1335         iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1336     }
1337 }
1338 
1339 impl Product for U8Vec2 {
1340     #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = Self>,1341     fn product<I>(iter: I) -> Self
1342     where
1343         I: Iterator<Item = Self>,
1344     {
1345         iter.fold(Self::ONE, Self::mul)
1346     }
1347 }
1348 
1349 impl<'a> Product<&'a Self> for U8Vec2 {
1350     #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,1351     fn product<I>(iter: I) -> Self
1352     where
1353         I: Iterator<Item = &'a Self>,
1354     {
1355         iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1356     }
1357 }
1358 
1359 impl Not for U8Vec2 {
1360     type Output = Self;
1361     #[inline]
not(self) -> Self::Output1362     fn not(self) -> Self::Output {
1363         Self {
1364             x: self.x.not(),
1365             y: self.y.not(),
1366         }
1367     }
1368 }
1369 
1370 impl BitAnd for U8Vec2 {
1371     type Output = Self;
1372     #[inline]
bitand(self, rhs: Self) -> Self::Output1373     fn bitand(self, rhs: Self) -> Self::Output {
1374         Self {
1375             x: self.x.bitand(rhs.x),
1376             y: self.y.bitand(rhs.y),
1377         }
1378     }
1379 }
1380 
1381 impl BitOr for U8Vec2 {
1382     type Output = Self;
1383     #[inline]
bitor(self, rhs: Self) -> Self::Output1384     fn bitor(self, rhs: Self) -> Self::Output {
1385         Self {
1386             x: self.x.bitor(rhs.x),
1387             y: self.y.bitor(rhs.y),
1388         }
1389     }
1390 }
1391 
1392 impl BitXor for U8Vec2 {
1393     type Output = Self;
1394     #[inline]
bitxor(self, rhs: Self) -> Self::Output1395     fn bitxor(self, rhs: Self) -> Self::Output {
1396         Self {
1397             x: self.x.bitxor(rhs.x),
1398             y: self.y.bitxor(rhs.y),
1399         }
1400     }
1401 }
1402 
1403 impl BitAnd<u8> for U8Vec2 {
1404     type Output = Self;
1405     #[inline]
bitand(self, rhs: u8) -> Self::Output1406     fn bitand(self, rhs: u8) -> Self::Output {
1407         Self {
1408             x: self.x.bitand(rhs),
1409             y: self.y.bitand(rhs),
1410         }
1411     }
1412 }
1413 
1414 impl BitOr<u8> for U8Vec2 {
1415     type Output = Self;
1416     #[inline]
bitor(self, rhs: u8) -> Self::Output1417     fn bitor(self, rhs: u8) -> Self::Output {
1418         Self {
1419             x: self.x.bitor(rhs),
1420             y: self.y.bitor(rhs),
1421         }
1422     }
1423 }
1424 
1425 impl BitXor<u8> for U8Vec2 {
1426     type Output = Self;
1427     #[inline]
bitxor(self, rhs: u8) -> Self::Output1428     fn bitxor(self, rhs: u8) -> Self::Output {
1429         Self {
1430             x: self.x.bitxor(rhs),
1431             y: self.y.bitxor(rhs),
1432         }
1433     }
1434 }
1435 
1436 impl Shl<i8> for U8Vec2 {
1437     type Output = Self;
1438     #[inline]
shl(self, rhs: i8) -> Self::Output1439     fn shl(self, rhs: i8) -> Self::Output {
1440         Self {
1441             x: self.x.shl(rhs),
1442             y: self.y.shl(rhs),
1443         }
1444     }
1445 }
1446 
1447 impl Shr<i8> for U8Vec2 {
1448     type Output = Self;
1449     #[inline]
shr(self, rhs: i8) -> Self::Output1450     fn shr(self, rhs: i8) -> Self::Output {
1451         Self {
1452             x: self.x.shr(rhs),
1453             y: self.y.shr(rhs),
1454         }
1455     }
1456 }
1457 
1458 impl Shl<i16> for U8Vec2 {
1459     type Output = Self;
1460     #[inline]
shl(self, rhs: i16) -> Self::Output1461     fn shl(self, rhs: i16) -> Self::Output {
1462         Self {
1463             x: self.x.shl(rhs),
1464             y: self.y.shl(rhs),
1465         }
1466     }
1467 }
1468 
1469 impl Shr<i16> for U8Vec2 {
1470     type Output = Self;
1471     #[inline]
shr(self, rhs: i16) -> Self::Output1472     fn shr(self, rhs: i16) -> Self::Output {
1473         Self {
1474             x: self.x.shr(rhs),
1475             y: self.y.shr(rhs),
1476         }
1477     }
1478 }
1479 
1480 impl Shl<i32> for U8Vec2 {
1481     type Output = Self;
1482     #[inline]
shl(self, rhs: i32) -> Self::Output1483     fn shl(self, rhs: i32) -> Self::Output {
1484         Self {
1485             x: self.x.shl(rhs),
1486             y: self.y.shl(rhs),
1487         }
1488     }
1489 }
1490 
1491 impl Shr<i32> for U8Vec2 {
1492     type Output = Self;
1493     #[inline]
shr(self, rhs: i32) -> Self::Output1494     fn shr(self, rhs: i32) -> Self::Output {
1495         Self {
1496             x: self.x.shr(rhs),
1497             y: self.y.shr(rhs),
1498         }
1499     }
1500 }
1501 
1502 impl Shl<i64> for U8Vec2 {
1503     type Output = Self;
1504     #[inline]
shl(self, rhs: i64) -> Self::Output1505     fn shl(self, rhs: i64) -> Self::Output {
1506         Self {
1507             x: self.x.shl(rhs),
1508             y: self.y.shl(rhs),
1509         }
1510     }
1511 }
1512 
1513 impl Shr<i64> for U8Vec2 {
1514     type Output = Self;
1515     #[inline]
shr(self, rhs: i64) -> Self::Output1516     fn shr(self, rhs: i64) -> Self::Output {
1517         Self {
1518             x: self.x.shr(rhs),
1519             y: self.y.shr(rhs),
1520         }
1521     }
1522 }
1523 
1524 impl Shl<u8> for U8Vec2 {
1525     type Output = Self;
1526     #[inline]
shl(self, rhs: u8) -> Self::Output1527     fn shl(self, rhs: u8) -> Self::Output {
1528         Self {
1529             x: self.x.shl(rhs),
1530             y: self.y.shl(rhs),
1531         }
1532     }
1533 }
1534 
1535 impl Shr<u8> for U8Vec2 {
1536     type Output = Self;
1537     #[inline]
shr(self, rhs: u8) -> Self::Output1538     fn shr(self, rhs: u8) -> Self::Output {
1539         Self {
1540             x: self.x.shr(rhs),
1541             y: self.y.shr(rhs),
1542         }
1543     }
1544 }
1545 
1546 impl Shl<u16> for U8Vec2 {
1547     type Output = Self;
1548     #[inline]
shl(self, rhs: u16) -> Self::Output1549     fn shl(self, rhs: u16) -> Self::Output {
1550         Self {
1551             x: self.x.shl(rhs),
1552             y: self.y.shl(rhs),
1553         }
1554     }
1555 }
1556 
1557 impl Shr<u16> for U8Vec2 {
1558     type Output = Self;
1559     #[inline]
shr(self, rhs: u16) -> Self::Output1560     fn shr(self, rhs: u16) -> Self::Output {
1561         Self {
1562             x: self.x.shr(rhs),
1563             y: self.y.shr(rhs),
1564         }
1565     }
1566 }
1567 
1568 impl Shl<u32> for U8Vec2 {
1569     type Output = Self;
1570     #[inline]
shl(self, rhs: u32) -> Self::Output1571     fn shl(self, rhs: u32) -> Self::Output {
1572         Self {
1573             x: self.x.shl(rhs),
1574             y: self.y.shl(rhs),
1575         }
1576     }
1577 }
1578 
1579 impl Shr<u32> for U8Vec2 {
1580     type Output = Self;
1581     #[inline]
shr(self, rhs: u32) -> Self::Output1582     fn shr(self, rhs: u32) -> Self::Output {
1583         Self {
1584             x: self.x.shr(rhs),
1585             y: self.y.shr(rhs),
1586         }
1587     }
1588 }
1589 
1590 impl Shl<u64> for U8Vec2 {
1591     type Output = Self;
1592     #[inline]
shl(self, rhs: u64) -> Self::Output1593     fn shl(self, rhs: u64) -> Self::Output {
1594         Self {
1595             x: self.x.shl(rhs),
1596             y: self.y.shl(rhs),
1597         }
1598     }
1599 }
1600 
1601 impl Shr<u64> for U8Vec2 {
1602     type Output = Self;
1603     #[inline]
shr(self, rhs: u64) -> Self::Output1604     fn shr(self, rhs: u64) -> Self::Output {
1605         Self {
1606             x: self.x.shr(rhs),
1607             y: self.y.shr(rhs),
1608         }
1609     }
1610 }
1611 
1612 impl Shl<crate::IVec2> for U8Vec2 {
1613     type Output = Self;
1614     #[inline]
shl(self, rhs: crate::IVec2) -> Self::Output1615     fn shl(self, rhs: crate::IVec2) -> Self::Output {
1616         Self {
1617             x: self.x.shl(rhs.x),
1618             y: self.y.shl(rhs.y),
1619         }
1620     }
1621 }
1622 
1623 impl Shr<crate::IVec2> for U8Vec2 {
1624     type Output = Self;
1625     #[inline]
shr(self, rhs: crate::IVec2) -> Self::Output1626     fn shr(self, rhs: crate::IVec2) -> Self::Output {
1627         Self {
1628             x: self.x.shr(rhs.x),
1629             y: self.y.shr(rhs.y),
1630         }
1631     }
1632 }
1633 
1634 impl Shl<crate::UVec2> for U8Vec2 {
1635     type Output = Self;
1636     #[inline]
shl(self, rhs: crate::UVec2) -> Self::Output1637     fn shl(self, rhs: crate::UVec2) -> Self::Output {
1638         Self {
1639             x: self.x.shl(rhs.x),
1640             y: self.y.shl(rhs.y),
1641         }
1642     }
1643 }
1644 
1645 impl Shr<crate::UVec2> for U8Vec2 {
1646     type Output = Self;
1647     #[inline]
shr(self, rhs: crate::UVec2) -> Self::Output1648     fn shr(self, rhs: crate::UVec2) -> Self::Output {
1649         Self {
1650             x: self.x.shr(rhs.x),
1651             y: self.y.shr(rhs.y),
1652         }
1653     }
1654 }
1655 
1656 impl Index<usize> for U8Vec2 {
1657     type Output = u8;
1658     #[inline]
index(&self, index: usize) -> &Self::Output1659     fn index(&self, index: usize) -> &Self::Output {
1660         match index {
1661             0 => &self.x,
1662             1 => &self.y,
1663             _ => panic!("index out of bounds"),
1664         }
1665     }
1666 }
1667 
1668 impl IndexMut<usize> for U8Vec2 {
1669     #[inline]
index_mut(&mut self, index: usize) -> &mut Self::Output1670     fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1671         match index {
1672             0 => &mut self.x,
1673             1 => &mut self.y,
1674             _ => panic!("index out of bounds"),
1675         }
1676     }
1677 }
1678 
1679 impl fmt::Display for U8Vec2 {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result1680     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1681         write!(f, "[{}, {}]", self.x, self.y)
1682     }
1683 }
1684 
1685 impl fmt::Debug for U8Vec2 {
fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result1686     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1687         fmt.debug_tuple(stringify!(U8Vec2))
1688             .field(&self.x)
1689             .field(&self.y)
1690             .finish()
1691     }
1692 }
1693 
1694 impl From<[u8; 2]> for U8Vec2 {
1695     #[inline]
from(a: [u8; 2]) -> Self1696     fn from(a: [u8; 2]) -> Self {
1697         Self::new(a[0], a[1])
1698     }
1699 }
1700 
1701 impl From<U8Vec2> for [u8; 2] {
1702     #[inline]
from(v: U8Vec2) -> Self1703     fn from(v: U8Vec2) -> Self {
1704         [v.x, v.y]
1705     }
1706 }
1707 
1708 impl From<(u8, u8)> for U8Vec2 {
1709     #[inline]
from(t: (u8, u8)) -> Self1710     fn from(t: (u8, u8)) -> Self {
1711         Self::new(t.0, t.1)
1712     }
1713 }
1714 
1715 impl From<U8Vec2> for (u8, u8) {
1716     #[inline]
from(v: U8Vec2) -> Self1717     fn from(v: U8Vec2) -> Self {
1718         (v.x, v.y)
1719     }
1720 }
1721 
1722 impl TryFrom<I8Vec2> for U8Vec2 {
1723     type Error = core::num::TryFromIntError;
1724 
1725     #[inline]
try_from(v: I8Vec2) -> Result<Self, Self::Error>1726     fn try_from(v: I8Vec2) -> Result<Self, Self::Error> {
1727         Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
1728     }
1729 }
1730 
1731 impl TryFrom<I16Vec2> for U8Vec2 {
1732     type Error = core::num::TryFromIntError;
1733 
1734     #[inline]
try_from(v: I16Vec2) -> Result<Self, Self::Error>1735     fn try_from(v: I16Vec2) -> Result<Self, Self::Error> {
1736         Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
1737     }
1738 }
1739 
1740 impl TryFrom<U16Vec2> for U8Vec2 {
1741     type Error = core::num::TryFromIntError;
1742 
1743     #[inline]
try_from(v: U16Vec2) -> Result<Self, Self::Error>1744     fn try_from(v: U16Vec2) -> Result<Self, Self::Error> {
1745         Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
1746     }
1747 }
1748 
1749 impl TryFrom<IVec2> for U8Vec2 {
1750     type Error = core::num::TryFromIntError;
1751 
1752     #[inline]
try_from(v: IVec2) -> Result<Self, Self::Error>1753     fn try_from(v: IVec2) -> Result<Self, Self::Error> {
1754         Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
1755     }
1756 }
1757 
1758 impl TryFrom<UVec2> for U8Vec2 {
1759     type Error = core::num::TryFromIntError;
1760 
1761     #[inline]
try_from(v: UVec2) -> Result<Self, Self::Error>1762     fn try_from(v: UVec2) -> Result<Self, Self::Error> {
1763         Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
1764     }
1765 }
1766 
1767 impl TryFrom<I64Vec2> for U8Vec2 {
1768     type Error = core::num::TryFromIntError;
1769 
1770     #[inline]
try_from(v: I64Vec2) -> Result<Self, Self::Error>1771     fn try_from(v: I64Vec2) -> Result<Self, Self::Error> {
1772         Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
1773     }
1774 }
1775 
1776 impl TryFrom<U64Vec2> for U8Vec2 {
1777     type Error = core::num::TryFromIntError;
1778 
1779     #[inline]
try_from(v: U64Vec2) -> Result<Self, Self::Error>1780     fn try_from(v: U64Vec2) -> Result<Self, Self::Error> {
1781         Ok(Self::new(u8::try_from(v.x)?, u8::try_from(v.y)?))
1782     }
1783 }
1784 
1785 impl From<BVec2> for U8Vec2 {
1786     #[inline]
from(v: BVec2) -> Self1787     fn from(v: BVec2) -> Self {
1788         Self::new(u8::from(v.x), u8::from(v.y))
1789     }
1790 }
1791