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