1 // Generated from vec.rs.tera template. Edit the template, not the generated file.
2 
3 use crate::{BVec3, I16Vec3, I64Vec3, IVec3, U16Vec2, U16Vec4, U64Vec3, UVec3};
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 3-dimensional vector.
11 #[inline(always)]
12 #[must_use]
u16vec3(x: u16, y: u16, z: u16) -> U16Vec313 pub const fn u16vec3(x: u16, y: u16, z: u16) -> U16Vec3 {
14     U16Vec3::new(x, y, z)
15 }
16 
17 /// A 3-dimensional vector.
18 #[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
19 #[derive(Clone, Copy, PartialEq, Eq)]
20 #[cfg_attr(not(target_arch = "spirv"), repr(C))]
21 #[cfg_attr(target_arch = "spirv", repr(simd))]
22 pub struct U16Vec3 {
23     pub x: u16,
24     pub y: u16,
25     pub z: u16,
26 }
27 
28 impl U16Vec3 {
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, 0);
43 
44     /// A unit vector pointing along the positive Y axis.
45     pub const Y: Self = Self::new(0, 1, 0);
46 
47     /// A unit vector pointing along the positive Z axis.
48     pub const Z: Self = Self::new(0, 0, 1);
49 
50     /// The unit axes.
51     pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
52 
53     /// Creates a new vector.
54     #[inline(always)]
55     #[must_use]
new(x: u16, y: u16, z: u16) -> Self56     pub const fn new(x: u16, y: u16, z: u16) -> Self {
57         Self { x, y, z }
58     }
59 
60     /// Creates a vector with all elements set to `v`.
61     #[inline]
62     #[must_use]
splat(v: u16) -> Self63     pub const fn splat(v: u16) -> Self {
64         Self { x: v, y: v, z: v }
65     }
66 
67     /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
68     /// for each element of `self`.
69     ///
70     /// A true element in the mask uses the corresponding element from `if_true`, and false
71     /// uses the element from `if_false`.
72     #[inline]
73     #[must_use]
select(mask: BVec3, if_true: Self, if_false: Self) -> Self74     pub fn select(mask: BVec3, if_true: Self, if_false: Self) -> Self {
75         Self {
76             x: if mask.test(0) { if_true.x } else { if_false.x },
77             y: if mask.test(1) { if_true.y } else { if_false.y },
78             z: if mask.test(2) { if_true.z } else { if_false.z },
79         }
80     }
81 
82     /// Creates a new vector from an array.
83     #[inline]
84     #[must_use]
from_array(a: [u16; 3]) -> Self85     pub const fn from_array(a: [u16; 3]) -> Self {
86         Self::new(a[0], a[1], a[2])
87     }
88 
89     /// `[x, y, z]`
90     #[inline]
91     #[must_use]
to_array(&self) -> [u16; 3]92     pub const fn to_array(&self) -> [u16; 3] {
93         [self.x, self.y, self.z]
94     }
95 
96     /// Creates a vector from the first 3 values in `slice`.
97     ///
98     /// # Panics
99     ///
100     /// Panics if `slice` is less than 3 elements long.
101     #[inline]
102     #[must_use]
from_slice(slice: &[u16]) -> Self103     pub const fn from_slice(slice: &[u16]) -> Self {
104         Self::new(slice[0], slice[1], slice[2])
105     }
106 
107     /// Writes the elements of `self` to the first 3 elements in `slice`.
108     ///
109     /// # Panics
110     ///
111     /// Panics if `slice` is less than 3 elements long.
112     #[inline]
write_to_slice(self, slice: &mut [u16])113     pub fn write_to_slice(self, slice: &mut [u16]) {
114         slice[0] = self.x;
115         slice[1] = self.y;
116         slice[2] = self.z;
117     }
118 
119     /// Internal method for creating a 3D vector from a 4D vector, discarding `w`.
120     #[allow(dead_code)]
121     #[inline]
122     #[must_use]
from_vec4(v: U16Vec4) -> Self123     pub(crate) fn from_vec4(v: U16Vec4) -> Self {
124         Self {
125             x: v.x,
126             y: v.y,
127             z: v.z,
128         }
129     }
130 
131     /// Creates a 4D vector from `self` and the given `w` value.
132     #[inline]
133     #[must_use]
extend(self, w: u16) -> U16Vec4134     pub fn extend(self, w: u16) -> U16Vec4 {
135         U16Vec4::new(self.x, self.y, self.z, w)
136     }
137 
138     /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`.
139     ///
140     /// Truncation may also be performed by using [`self.xy()`][crate::swizzles::Vec3Swizzles::xy()].
141     #[inline]
142     #[must_use]
truncate(self) -> U16Vec2143     pub fn truncate(self) -> U16Vec2 {
144         use crate::swizzles::Vec3Swizzles;
145         self.xy()
146     }
147 
148     /// Computes the dot product of `self` and `rhs`.
149     #[inline]
150     #[must_use]
dot(self, rhs: Self) -> u16151     pub fn dot(self, rhs: Self) -> u16 {
152         (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z)
153     }
154 
155     /// Returns a vector where every component is the dot product of `self` and `rhs`.
156     #[inline]
157     #[must_use]
dot_into_vec(self, rhs: Self) -> Self158     pub fn dot_into_vec(self, rhs: Self) -> Self {
159         Self::splat(self.dot(rhs))
160     }
161 
162     /// Computes the cross product of `self` and `rhs`.
163     #[inline]
164     #[must_use]
cross(self, rhs: Self) -> Self165     pub fn cross(self, rhs: Self) -> Self {
166         Self {
167             x: self.y * rhs.z - rhs.y * self.z,
168             y: self.z * rhs.x - rhs.z * self.x,
169             z: self.x * rhs.y - rhs.x * self.y,
170         }
171     }
172 
173     /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
174     ///
175     /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
176     #[inline]
177     #[must_use]
min(self, rhs: Self) -> Self178     pub fn min(self, rhs: Self) -> Self {
179         Self {
180             x: self.x.min(rhs.x),
181             y: self.y.min(rhs.y),
182             z: self.z.min(rhs.z),
183         }
184     }
185 
186     /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
187     ///
188     /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
189     #[inline]
190     #[must_use]
max(self, rhs: Self) -> Self191     pub fn max(self, rhs: Self) -> Self {
192         Self {
193             x: self.x.max(rhs.x),
194             y: self.y.max(rhs.y),
195             z: self.z.max(rhs.z),
196         }
197     }
198 
199     /// Component-wise clamping of values, similar to [`u16::clamp`].
200     ///
201     /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
202     ///
203     /// # Panics
204     ///
205     /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
206     #[inline]
207     #[must_use]
clamp(self, min: Self, max: Self) -> Self208     pub fn clamp(self, min: Self, max: Self) -> Self {
209         glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
210         self.max(min).min(max)
211     }
212 
213     /// Returns the horizontal minimum of `self`.
214     ///
215     /// In other words this computes `min(x, y, ..)`.
216     #[inline]
217     #[must_use]
min_element(self) -> u16218     pub fn min_element(self) -> u16 {
219         self.x.min(self.y.min(self.z))
220     }
221 
222     /// Returns the horizontal maximum of `self`.
223     ///
224     /// In other words this computes `max(x, y, ..)`.
225     #[inline]
226     #[must_use]
max_element(self) -> u16227     pub fn max_element(self) -> u16 {
228         self.x.max(self.y.max(self.z))
229     }
230 
231     /// Returns a vector mask containing the result of a `==` comparison for each element of
232     /// `self` and `rhs`.
233     ///
234     /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
235     /// elements.
236     #[inline]
237     #[must_use]
cmpeq(self, rhs: Self) -> BVec3238     pub fn cmpeq(self, rhs: Self) -> BVec3 {
239         BVec3::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
240     }
241 
242     /// Returns a vector mask containing the result of a `!=` comparison for each element of
243     /// `self` and `rhs`.
244     ///
245     /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
246     /// elements.
247     #[inline]
248     #[must_use]
cmpne(self, rhs: Self) -> BVec3249     pub fn cmpne(self, rhs: Self) -> BVec3 {
250         BVec3::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
251     }
252 
253     /// Returns a vector mask containing the result of a `>=` comparison for each element of
254     /// `self` and `rhs`.
255     ///
256     /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
257     /// elements.
258     #[inline]
259     #[must_use]
cmpge(self, rhs: Self) -> BVec3260     pub fn cmpge(self, rhs: Self) -> BVec3 {
261         BVec3::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
262     }
263 
264     /// Returns a vector mask containing the result of a `>` comparison for each element of
265     /// `self` and `rhs`.
266     ///
267     /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
268     /// elements.
269     #[inline]
270     #[must_use]
cmpgt(self, rhs: Self) -> BVec3271     pub fn cmpgt(self, rhs: Self) -> BVec3 {
272         BVec3::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
273     }
274 
275     /// Returns a vector mask containing the result of a `<=` comparison for each element of
276     /// `self` and `rhs`.
277     ///
278     /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
279     /// elements.
280     #[inline]
281     #[must_use]
cmple(self, rhs: Self) -> BVec3282     pub fn cmple(self, rhs: Self) -> BVec3 {
283         BVec3::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
284     }
285 
286     /// Returns a vector mask containing the result of a `<` comparison for each element of
287     /// `self` and `rhs`.
288     ///
289     /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
290     /// elements.
291     #[inline]
292     #[must_use]
cmplt(self, rhs: Self) -> BVec3293     pub fn cmplt(self, rhs: Self) -> BVec3 {
294         BVec3::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
295     }
296 
297     /// Computes the squared length of `self`.
298     #[doc(alias = "magnitude2")]
299     #[inline]
300     #[must_use]
length_squared(self) -> u16301     pub fn length_squared(self) -> u16 {
302         self.dot(self)
303     }
304 
305     /// Casts all elements of `self` to `f32`.
306     #[inline]
307     #[must_use]
as_vec3(&self) -> crate::Vec3308     pub fn as_vec3(&self) -> crate::Vec3 {
309         crate::Vec3::new(self.x as f32, self.y as f32, self.z as f32)
310     }
311 
312     /// Casts all elements of `self` to `f32`.
313     #[inline]
314     #[must_use]
as_vec3a(&self) -> crate::Vec3A315     pub fn as_vec3a(&self) -> crate::Vec3A {
316         crate::Vec3A::new(self.x as f32, self.y as f32, self.z as f32)
317     }
318 
319     /// Casts all elements of `self` to `f64`.
320     #[inline]
321     #[must_use]
as_dvec3(&self) -> crate::DVec3322     pub fn as_dvec3(&self) -> crate::DVec3 {
323         crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
324     }
325 
326     /// Casts all elements of `self` to `i16`.
327     #[inline]
328     #[must_use]
as_i16vec3(&self) -> crate::I16Vec3329     pub fn as_i16vec3(&self) -> crate::I16Vec3 {
330         crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
331     }
332 
333     /// Casts all elements of `self` to `i32`.
334     #[inline]
335     #[must_use]
as_ivec3(&self) -> crate::IVec3336     pub fn as_ivec3(&self) -> crate::IVec3 {
337         crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
338     }
339 
340     /// Casts all elements of `self` to `u32`.
341     #[inline]
342     #[must_use]
as_uvec3(&self) -> crate::UVec3343     pub fn as_uvec3(&self) -> crate::UVec3 {
344         crate::UVec3::new(self.x as u32, self.y as u32, self.z as u32)
345     }
346 
347     /// Casts all elements of `self` to `i64`.
348     #[inline]
349     #[must_use]
as_i64vec3(&self) -> crate::I64Vec3350     pub fn as_i64vec3(&self) -> crate::I64Vec3 {
351         crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
352     }
353 
354     /// Casts all elements of `self` to `u64`.
355     #[inline]
356     #[must_use]
as_u64vec3(&self) -> crate::U64Vec3357     pub fn as_u64vec3(&self) -> crate::U64Vec3 {
358         crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
359     }
360 
361     /// Returns a vector containing the wrapping addition of `self` and `rhs`.
362     ///
363     /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`.
364     #[inline]
365     #[must_use]
wrapping_add(self, rhs: Self) -> Self366     pub const fn wrapping_add(self, rhs: Self) -> Self {
367         Self {
368             x: self.x.wrapping_add(rhs.x),
369             y: self.y.wrapping_add(rhs.y),
370             z: self.z.wrapping_add(rhs.z),
371         }
372     }
373 
374     /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
375     ///
376     /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`.
377     #[inline]
378     #[must_use]
wrapping_sub(self, rhs: Self) -> Self379     pub const fn wrapping_sub(self, rhs: Self) -> Self {
380         Self {
381             x: self.x.wrapping_sub(rhs.x),
382             y: self.y.wrapping_sub(rhs.y),
383             z: self.z.wrapping_sub(rhs.z),
384         }
385     }
386 
387     /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
388     ///
389     /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`.
390     #[inline]
391     #[must_use]
wrapping_mul(self, rhs: Self) -> Self392     pub const fn wrapping_mul(self, rhs: Self) -> Self {
393         Self {
394             x: self.x.wrapping_mul(rhs.x),
395             y: self.y.wrapping_mul(rhs.y),
396             z: self.z.wrapping_mul(rhs.z),
397         }
398     }
399 
400     /// Returns a vector containing the wrapping division of `self` and `rhs`.
401     ///
402     /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`.
403     #[inline]
404     #[must_use]
wrapping_div(self, rhs: Self) -> Self405     pub const fn wrapping_div(self, rhs: Self) -> Self {
406         Self {
407             x: self.x.wrapping_div(rhs.x),
408             y: self.y.wrapping_div(rhs.y),
409             z: self.z.wrapping_div(rhs.z),
410         }
411     }
412 
413     /// Returns a vector containing the saturating addition of `self` and `rhs`.
414     ///
415     /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`.
416     #[inline]
417     #[must_use]
saturating_add(self, rhs: Self) -> Self418     pub const fn saturating_add(self, rhs: Self) -> Self {
419         Self {
420             x: self.x.saturating_add(rhs.x),
421             y: self.y.saturating_add(rhs.y),
422             z: self.z.saturating_add(rhs.z),
423         }
424     }
425 
426     /// Returns a vector containing the saturating subtraction of `self` and `rhs`.
427     ///
428     /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`.
429     #[inline]
430     #[must_use]
saturating_sub(self, rhs: Self) -> Self431     pub const fn saturating_sub(self, rhs: Self) -> Self {
432         Self {
433             x: self.x.saturating_sub(rhs.x),
434             y: self.y.saturating_sub(rhs.y),
435             z: self.z.saturating_sub(rhs.z),
436         }
437     }
438 
439     /// Returns a vector containing the saturating multiplication of `self` and `rhs`.
440     ///
441     /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`.
442     #[inline]
443     #[must_use]
saturating_mul(self, rhs: Self) -> Self444     pub const fn saturating_mul(self, rhs: Self) -> Self {
445         Self {
446             x: self.x.saturating_mul(rhs.x),
447             y: self.y.saturating_mul(rhs.y),
448             z: self.z.saturating_mul(rhs.z),
449         }
450     }
451 
452     /// Returns a vector containing the saturating division of `self` and `rhs`.
453     ///
454     /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`.
455     #[inline]
456     #[must_use]
saturating_div(self, rhs: Self) -> Self457     pub const fn saturating_div(self, rhs: Self) -> Self {
458         Self {
459             x: self.x.saturating_div(rhs.x),
460             y: self.y.saturating_div(rhs.y),
461             z: self.z.saturating_div(rhs.z),
462         }
463     }
464 }
465 
466 impl Default for U16Vec3 {
467     #[inline(always)]
default() -> Self468     fn default() -> Self {
469         Self::ZERO
470     }
471 }
472 
473 impl Div<U16Vec3> for U16Vec3 {
474     type Output = Self;
475     #[inline]
div(self, rhs: Self) -> Self476     fn div(self, rhs: Self) -> Self {
477         Self {
478             x: self.x.div(rhs.x),
479             y: self.y.div(rhs.y),
480             z: self.z.div(rhs.z),
481         }
482     }
483 }
484 
485 impl DivAssign<U16Vec3> for U16Vec3 {
486     #[inline]
div_assign(&mut self, rhs: Self)487     fn div_assign(&mut self, rhs: Self) {
488         self.x.div_assign(rhs.x);
489         self.y.div_assign(rhs.y);
490         self.z.div_assign(rhs.z);
491     }
492 }
493 
494 impl Div<u16> for U16Vec3 {
495     type Output = Self;
496     #[inline]
div(self, rhs: u16) -> Self497     fn div(self, rhs: u16) -> Self {
498         Self {
499             x: self.x.div(rhs),
500             y: self.y.div(rhs),
501             z: self.z.div(rhs),
502         }
503     }
504 }
505 
506 impl DivAssign<u16> for U16Vec3 {
507     #[inline]
div_assign(&mut self, rhs: u16)508     fn div_assign(&mut self, rhs: u16) {
509         self.x.div_assign(rhs);
510         self.y.div_assign(rhs);
511         self.z.div_assign(rhs);
512     }
513 }
514 
515 impl Div<U16Vec3> for u16 {
516     type Output = U16Vec3;
517     #[inline]
div(self, rhs: U16Vec3) -> U16Vec3518     fn div(self, rhs: U16Vec3) -> U16Vec3 {
519         U16Vec3 {
520             x: self.div(rhs.x),
521             y: self.div(rhs.y),
522             z: self.div(rhs.z),
523         }
524     }
525 }
526 
527 impl Mul<U16Vec3> for U16Vec3 {
528     type Output = Self;
529     #[inline]
mul(self, rhs: Self) -> Self530     fn mul(self, rhs: Self) -> Self {
531         Self {
532             x: self.x.mul(rhs.x),
533             y: self.y.mul(rhs.y),
534             z: self.z.mul(rhs.z),
535         }
536     }
537 }
538 
539 impl MulAssign<U16Vec3> for U16Vec3 {
540     #[inline]
mul_assign(&mut self, rhs: Self)541     fn mul_assign(&mut self, rhs: Self) {
542         self.x.mul_assign(rhs.x);
543         self.y.mul_assign(rhs.y);
544         self.z.mul_assign(rhs.z);
545     }
546 }
547 
548 impl Mul<u16> for U16Vec3 {
549     type Output = Self;
550     #[inline]
mul(self, rhs: u16) -> Self551     fn mul(self, rhs: u16) -> Self {
552         Self {
553             x: self.x.mul(rhs),
554             y: self.y.mul(rhs),
555             z: self.z.mul(rhs),
556         }
557     }
558 }
559 
560 impl MulAssign<u16> for U16Vec3 {
561     #[inline]
mul_assign(&mut self, rhs: u16)562     fn mul_assign(&mut self, rhs: u16) {
563         self.x.mul_assign(rhs);
564         self.y.mul_assign(rhs);
565         self.z.mul_assign(rhs);
566     }
567 }
568 
569 impl Mul<U16Vec3> for u16 {
570     type Output = U16Vec3;
571     #[inline]
mul(self, rhs: U16Vec3) -> U16Vec3572     fn mul(self, rhs: U16Vec3) -> U16Vec3 {
573         U16Vec3 {
574             x: self.mul(rhs.x),
575             y: self.mul(rhs.y),
576             z: self.mul(rhs.z),
577         }
578     }
579 }
580 
581 impl Add<U16Vec3> for U16Vec3 {
582     type Output = Self;
583     #[inline]
add(self, rhs: Self) -> Self584     fn add(self, rhs: Self) -> Self {
585         Self {
586             x: self.x.add(rhs.x),
587             y: self.y.add(rhs.y),
588             z: self.z.add(rhs.z),
589         }
590     }
591 }
592 
593 impl AddAssign<U16Vec3> for U16Vec3 {
594     #[inline]
add_assign(&mut self, rhs: Self)595     fn add_assign(&mut self, rhs: Self) {
596         self.x.add_assign(rhs.x);
597         self.y.add_assign(rhs.y);
598         self.z.add_assign(rhs.z);
599     }
600 }
601 
602 impl Add<u16> for U16Vec3 {
603     type Output = Self;
604     #[inline]
add(self, rhs: u16) -> Self605     fn add(self, rhs: u16) -> Self {
606         Self {
607             x: self.x.add(rhs),
608             y: self.y.add(rhs),
609             z: self.z.add(rhs),
610         }
611     }
612 }
613 
614 impl AddAssign<u16> for U16Vec3 {
615     #[inline]
add_assign(&mut self, rhs: u16)616     fn add_assign(&mut self, rhs: u16) {
617         self.x.add_assign(rhs);
618         self.y.add_assign(rhs);
619         self.z.add_assign(rhs);
620     }
621 }
622 
623 impl Add<U16Vec3> for u16 {
624     type Output = U16Vec3;
625     #[inline]
add(self, rhs: U16Vec3) -> U16Vec3626     fn add(self, rhs: U16Vec3) -> U16Vec3 {
627         U16Vec3 {
628             x: self.add(rhs.x),
629             y: self.add(rhs.y),
630             z: self.add(rhs.z),
631         }
632     }
633 }
634 
635 impl Sub<U16Vec3> for U16Vec3 {
636     type Output = Self;
637     #[inline]
sub(self, rhs: Self) -> Self638     fn sub(self, rhs: Self) -> Self {
639         Self {
640             x: self.x.sub(rhs.x),
641             y: self.y.sub(rhs.y),
642             z: self.z.sub(rhs.z),
643         }
644     }
645 }
646 
647 impl SubAssign<U16Vec3> for U16Vec3 {
648     #[inline]
sub_assign(&mut self, rhs: U16Vec3)649     fn sub_assign(&mut self, rhs: U16Vec3) {
650         self.x.sub_assign(rhs.x);
651         self.y.sub_assign(rhs.y);
652         self.z.sub_assign(rhs.z);
653     }
654 }
655 
656 impl Sub<u16> for U16Vec3 {
657     type Output = Self;
658     #[inline]
sub(self, rhs: u16) -> Self659     fn sub(self, rhs: u16) -> Self {
660         Self {
661             x: self.x.sub(rhs),
662             y: self.y.sub(rhs),
663             z: self.z.sub(rhs),
664         }
665     }
666 }
667 
668 impl SubAssign<u16> for U16Vec3 {
669     #[inline]
sub_assign(&mut self, rhs: u16)670     fn sub_assign(&mut self, rhs: u16) {
671         self.x.sub_assign(rhs);
672         self.y.sub_assign(rhs);
673         self.z.sub_assign(rhs);
674     }
675 }
676 
677 impl Sub<U16Vec3> for u16 {
678     type Output = U16Vec3;
679     #[inline]
sub(self, rhs: U16Vec3) -> U16Vec3680     fn sub(self, rhs: U16Vec3) -> U16Vec3 {
681         U16Vec3 {
682             x: self.sub(rhs.x),
683             y: self.sub(rhs.y),
684             z: self.sub(rhs.z),
685         }
686     }
687 }
688 
689 impl Rem<U16Vec3> for U16Vec3 {
690     type Output = Self;
691     #[inline]
rem(self, rhs: Self) -> Self692     fn rem(self, rhs: Self) -> Self {
693         Self {
694             x: self.x.rem(rhs.x),
695             y: self.y.rem(rhs.y),
696             z: self.z.rem(rhs.z),
697         }
698     }
699 }
700 
701 impl RemAssign<U16Vec3> for U16Vec3 {
702     #[inline]
rem_assign(&mut self, rhs: Self)703     fn rem_assign(&mut self, rhs: Self) {
704         self.x.rem_assign(rhs.x);
705         self.y.rem_assign(rhs.y);
706         self.z.rem_assign(rhs.z);
707     }
708 }
709 
710 impl Rem<u16> for U16Vec3 {
711     type Output = Self;
712     #[inline]
rem(self, rhs: u16) -> Self713     fn rem(self, rhs: u16) -> Self {
714         Self {
715             x: self.x.rem(rhs),
716             y: self.y.rem(rhs),
717             z: self.z.rem(rhs),
718         }
719     }
720 }
721 
722 impl RemAssign<u16> for U16Vec3 {
723     #[inline]
rem_assign(&mut self, rhs: u16)724     fn rem_assign(&mut self, rhs: u16) {
725         self.x.rem_assign(rhs);
726         self.y.rem_assign(rhs);
727         self.z.rem_assign(rhs);
728     }
729 }
730 
731 impl Rem<U16Vec3> for u16 {
732     type Output = U16Vec3;
733     #[inline]
rem(self, rhs: U16Vec3) -> U16Vec3734     fn rem(self, rhs: U16Vec3) -> U16Vec3 {
735         U16Vec3 {
736             x: self.rem(rhs.x),
737             y: self.rem(rhs.y),
738             z: self.rem(rhs.z),
739         }
740     }
741 }
742 
743 #[cfg(not(target_arch = "spirv"))]
744 impl AsRef<[u16; 3]> for U16Vec3 {
745     #[inline]
as_ref(&self) -> &[u16; 3]746     fn as_ref(&self) -> &[u16; 3] {
747         unsafe { &*(self as *const U16Vec3 as *const [u16; 3]) }
748     }
749 }
750 
751 #[cfg(not(target_arch = "spirv"))]
752 impl AsMut<[u16; 3]> for U16Vec3 {
753     #[inline]
as_mut(&mut self) -> &mut [u16; 3]754     fn as_mut(&mut self) -> &mut [u16; 3] {
755         unsafe { &mut *(self as *mut U16Vec3 as *mut [u16; 3]) }
756     }
757 }
758 
759 impl Sum for U16Vec3 {
760     #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = Self>,761     fn sum<I>(iter: I) -> Self
762     where
763         I: Iterator<Item = Self>,
764     {
765         iter.fold(Self::ZERO, Self::add)
766     }
767 }
768 
769 impl<'a> Sum<&'a Self> for U16Vec3 {
770     #[inline]
sum<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,771     fn sum<I>(iter: I) -> Self
772     where
773         I: Iterator<Item = &'a Self>,
774     {
775         iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
776     }
777 }
778 
779 impl Product for U16Vec3 {
780     #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = Self>,781     fn product<I>(iter: I) -> Self
782     where
783         I: Iterator<Item = Self>,
784     {
785         iter.fold(Self::ONE, Self::mul)
786     }
787 }
788 
789 impl<'a> Product<&'a Self> for U16Vec3 {
790     #[inline]
product<I>(iter: I) -> Self where I: Iterator<Item = &'a Self>,791     fn product<I>(iter: I) -> Self
792     where
793         I: Iterator<Item = &'a Self>,
794     {
795         iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
796     }
797 }
798 
799 impl Not for U16Vec3 {
800     type Output = Self;
801     #[inline]
not(self) -> Self::Output802     fn not(self) -> Self::Output {
803         Self {
804             x: self.x.not(),
805             y: self.y.not(),
806             z: self.z.not(),
807         }
808     }
809 }
810 
811 impl BitAnd for U16Vec3 {
812     type Output = Self;
813     #[inline]
bitand(self, rhs: Self) -> Self::Output814     fn bitand(self, rhs: Self) -> Self::Output {
815         Self {
816             x: self.x.bitand(rhs.x),
817             y: self.y.bitand(rhs.y),
818             z: self.z.bitand(rhs.z),
819         }
820     }
821 }
822 
823 impl BitOr for U16Vec3 {
824     type Output = Self;
825     #[inline]
bitor(self, rhs: Self) -> Self::Output826     fn bitor(self, rhs: Self) -> Self::Output {
827         Self {
828             x: self.x.bitor(rhs.x),
829             y: self.y.bitor(rhs.y),
830             z: self.z.bitor(rhs.z),
831         }
832     }
833 }
834 
835 impl BitXor for U16Vec3 {
836     type Output = Self;
837     #[inline]
bitxor(self, rhs: Self) -> Self::Output838     fn bitxor(self, rhs: Self) -> Self::Output {
839         Self {
840             x: self.x.bitxor(rhs.x),
841             y: self.y.bitxor(rhs.y),
842             z: self.z.bitxor(rhs.z),
843         }
844     }
845 }
846 
847 impl BitAnd<u16> for U16Vec3 {
848     type Output = Self;
849     #[inline]
bitand(self, rhs: u16) -> Self::Output850     fn bitand(self, rhs: u16) -> Self::Output {
851         Self {
852             x: self.x.bitand(rhs),
853             y: self.y.bitand(rhs),
854             z: self.z.bitand(rhs),
855         }
856     }
857 }
858 
859 impl BitOr<u16> for U16Vec3 {
860     type Output = Self;
861     #[inline]
bitor(self, rhs: u16) -> Self::Output862     fn bitor(self, rhs: u16) -> Self::Output {
863         Self {
864             x: self.x.bitor(rhs),
865             y: self.y.bitor(rhs),
866             z: self.z.bitor(rhs),
867         }
868     }
869 }
870 
871 impl BitXor<u16> for U16Vec3 {
872     type Output = Self;
873     #[inline]
bitxor(self, rhs: u16) -> Self::Output874     fn bitxor(self, rhs: u16) -> Self::Output {
875         Self {
876             x: self.x.bitxor(rhs),
877             y: self.y.bitxor(rhs),
878             z: self.z.bitxor(rhs),
879         }
880     }
881 }
882 
883 impl Shl<i8> for U16Vec3 {
884     type Output = Self;
885     #[inline]
shl(self, rhs: i8) -> Self::Output886     fn shl(self, rhs: i8) -> Self::Output {
887         Self {
888             x: self.x.shl(rhs),
889             y: self.y.shl(rhs),
890             z: self.z.shl(rhs),
891         }
892     }
893 }
894 
895 impl Shr<i8> for U16Vec3 {
896     type Output = Self;
897     #[inline]
shr(self, rhs: i8) -> Self::Output898     fn shr(self, rhs: i8) -> Self::Output {
899         Self {
900             x: self.x.shr(rhs),
901             y: self.y.shr(rhs),
902             z: self.z.shr(rhs),
903         }
904     }
905 }
906 
907 impl Shl<i16> for U16Vec3 {
908     type Output = Self;
909     #[inline]
shl(self, rhs: i16) -> Self::Output910     fn shl(self, rhs: i16) -> Self::Output {
911         Self {
912             x: self.x.shl(rhs),
913             y: self.y.shl(rhs),
914             z: self.z.shl(rhs),
915         }
916     }
917 }
918 
919 impl Shr<i16> for U16Vec3 {
920     type Output = Self;
921     #[inline]
shr(self, rhs: i16) -> Self::Output922     fn shr(self, rhs: i16) -> Self::Output {
923         Self {
924             x: self.x.shr(rhs),
925             y: self.y.shr(rhs),
926             z: self.z.shr(rhs),
927         }
928     }
929 }
930 
931 impl Shl<i32> for U16Vec3 {
932     type Output = Self;
933     #[inline]
shl(self, rhs: i32) -> Self::Output934     fn shl(self, rhs: i32) -> Self::Output {
935         Self {
936             x: self.x.shl(rhs),
937             y: self.y.shl(rhs),
938             z: self.z.shl(rhs),
939         }
940     }
941 }
942 
943 impl Shr<i32> for U16Vec3 {
944     type Output = Self;
945     #[inline]
shr(self, rhs: i32) -> Self::Output946     fn shr(self, rhs: i32) -> Self::Output {
947         Self {
948             x: self.x.shr(rhs),
949             y: self.y.shr(rhs),
950             z: self.z.shr(rhs),
951         }
952     }
953 }
954 
955 impl Shl<i64> for U16Vec3 {
956     type Output = Self;
957     #[inline]
shl(self, rhs: i64) -> Self::Output958     fn shl(self, rhs: i64) -> Self::Output {
959         Self {
960             x: self.x.shl(rhs),
961             y: self.y.shl(rhs),
962             z: self.z.shl(rhs),
963         }
964     }
965 }
966 
967 impl Shr<i64> for U16Vec3 {
968     type Output = Self;
969     #[inline]
shr(self, rhs: i64) -> Self::Output970     fn shr(self, rhs: i64) -> Self::Output {
971         Self {
972             x: self.x.shr(rhs),
973             y: self.y.shr(rhs),
974             z: self.z.shr(rhs),
975         }
976     }
977 }
978 
979 impl Shl<u8> for U16Vec3 {
980     type Output = Self;
981     #[inline]
shl(self, rhs: u8) -> Self::Output982     fn shl(self, rhs: u8) -> Self::Output {
983         Self {
984             x: self.x.shl(rhs),
985             y: self.y.shl(rhs),
986             z: self.z.shl(rhs),
987         }
988     }
989 }
990 
991 impl Shr<u8> for U16Vec3 {
992     type Output = Self;
993     #[inline]
shr(self, rhs: u8) -> Self::Output994     fn shr(self, rhs: u8) -> Self::Output {
995         Self {
996             x: self.x.shr(rhs),
997             y: self.y.shr(rhs),
998             z: self.z.shr(rhs),
999         }
1000     }
1001 }
1002 
1003 impl Shl<u16> for U16Vec3 {
1004     type Output = Self;
1005     #[inline]
shl(self, rhs: u16) -> Self::Output1006     fn shl(self, rhs: u16) -> Self::Output {
1007         Self {
1008             x: self.x.shl(rhs),
1009             y: self.y.shl(rhs),
1010             z: self.z.shl(rhs),
1011         }
1012     }
1013 }
1014 
1015 impl Shr<u16> for U16Vec3 {
1016     type Output = Self;
1017     #[inline]
shr(self, rhs: u16) -> Self::Output1018     fn shr(self, rhs: u16) -> Self::Output {
1019         Self {
1020             x: self.x.shr(rhs),
1021             y: self.y.shr(rhs),
1022             z: self.z.shr(rhs),
1023         }
1024     }
1025 }
1026 
1027 impl Shl<u32> for U16Vec3 {
1028     type Output = Self;
1029     #[inline]
shl(self, rhs: u32) -> Self::Output1030     fn shl(self, rhs: u32) -> Self::Output {
1031         Self {
1032             x: self.x.shl(rhs),
1033             y: self.y.shl(rhs),
1034             z: self.z.shl(rhs),
1035         }
1036     }
1037 }
1038 
1039 impl Shr<u32> for U16Vec3 {
1040     type Output = Self;
1041     #[inline]
shr(self, rhs: u32) -> Self::Output1042     fn shr(self, rhs: u32) -> Self::Output {
1043         Self {
1044             x: self.x.shr(rhs),
1045             y: self.y.shr(rhs),
1046             z: self.z.shr(rhs),
1047         }
1048     }
1049 }
1050 
1051 impl Shl<u64> for U16Vec3 {
1052     type Output = Self;
1053     #[inline]
shl(self, rhs: u64) -> Self::Output1054     fn shl(self, rhs: u64) -> Self::Output {
1055         Self {
1056             x: self.x.shl(rhs),
1057             y: self.y.shl(rhs),
1058             z: self.z.shl(rhs),
1059         }
1060     }
1061 }
1062 
1063 impl Shr<u64> for U16Vec3 {
1064     type Output = Self;
1065     #[inline]
shr(self, rhs: u64) -> Self::Output1066     fn shr(self, rhs: u64) -> Self::Output {
1067         Self {
1068             x: self.x.shr(rhs),
1069             y: self.y.shr(rhs),
1070             z: self.z.shr(rhs),
1071         }
1072     }
1073 }
1074 
1075 impl Shl<crate::IVec3> for U16Vec3 {
1076     type Output = Self;
1077     #[inline]
shl(self, rhs: crate::IVec3) -> Self::Output1078     fn shl(self, rhs: crate::IVec3) -> Self::Output {
1079         Self {
1080             x: self.x.shl(rhs.x),
1081             y: self.y.shl(rhs.y),
1082             z: self.z.shl(rhs.z),
1083         }
1084     }
1085 }
1086 
1087 impl Shr<crate::IVec3> for U16Vec3 {
1088     type Output = Self;
1089     #[inline]
shr(self, rhs: crate::IVec3) -> Self::Output1090     fn shr(self, rhs: crate::IVec3) -> Self::Output {
1091         Self {
1092             x: self.x.shr(rhs.x),
1093             y: self.y.shr(rhs.y),
1094             z: self.z.shr(rhs.z),
1095         }
1096     }
1097 }
1098 
1099 impl Shl<crate::UVec3> for U16Vec3 {
1100     type Output = Self;
1101     #[inline]
shl(self, rhs: crate::UVec3) -> Self::Output1102     fn shl(self, rhs: crate::UVec3) -> Self::Output {
1103         Self {
1104             x: self.x.shl(rhs.x),
1105             y: self.y.shl(rhs.y),
1106             z: self.z.shl(rhs.z),
1107         }
1108     }
1109 }
1110 
1111 impl Shr<crate::UVec3> for U16Vec3 {
1112     type Output = Self;
1113     #[inline]
shr(self, rhs: crate::UVec3) -> Self::Output1114     fn shr(self, rhs: crate::UVec3) -> Self::Output {
1115         Self {
1116             x: self.x.shr(rhs.x),
1117             y: self.y.shr(rhs.y),
1118             z: self.z.shr(rhs.z),
1119         }
1120     }
1121 }
1122 
1123 impl Index<usize> for U16Vec3 {
1124     type Output = u16;
1125     #[inline]
index(&self, index: usize) -> &Self::Output1126     fn index(&self, index: usize) -> &Self::Output {
1127         match index {
1128             0 => &self.x,
1129             1 => &self.y,
1130             2 => &self.z,
1131             _ => panic!("index out of bounds"),
1132         }
1133     }
1134 }
1135 
1136 impl IndexMut<usize> for U16Vec3 {
1137     #[inline]
index_mut(&mut self, index: usize) -> &mut Self::Output1138     fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1139         match index {
1140             0 => &mut self.x,
1141             1 => &mut self.y,
1142             2 => &mut self.z,
1143             _ => panic!("index out of bounds"),
1144         }
1145     }
1146 }
1147 
1148 #[cfg(not(target_arch = "spirv"))]
1149 impl fmt::Display for U16Vec3 {
fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result1150     fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1151         write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
1152     }
1153 }
1154 
1155 #[cfg(not(target_arch = "spirv"))]
1156 impl fmt::Debug for U16Vec3 {
fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result1157     fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1158         fmt.debug_tuple(stringify!(U16Vec3))
1159             .field(&self.x)
1160             .field(&self.y)
1161             .field(&self.z)
1162             .finish()
1163     }
1164 }
1165 
1166 impl From<[u16; 3]> for U16Vec3 {
1167     #[inline]
from(a: [u16; 3]) -> Self1168     fn from(a: [u16; 3]) -> Self {
1169         Self::new(a[0], a[1], a[2])
1170     }
1171 }
1172 
1173 impl From<U16Vec3> for [u16; 3] {
1174     #[inline]
from(v: U16Vec3) -> Self1175     fn from(v: U16Vec3) -> Self {
1176         [v.x, v.y, v.z]
1177     }
1178 }
1179 
1180 impl From<(u16, u16, u16)> for U16Vec3 {
1181     #[inline]
from(t: (u16, u16, u16)) -> Self1182     fn from(t: (u16, u16, u16)) -> Self {
1183         Self::new(t.0, t.1, t.2)
1184     }
1185 }
1186 
1187 impl From<U16Vec3> for (u16, u16, u16) {
1188     #[inline]
from(v: U16Vec3) -> Self1189     fn from(v: U16Vec3) -> Self {
1190         (v.x, v.y, v.z)
1191     }
1192 }
1193 
1194 impl From<(U16Vec2, u16)> for U16Vec3 {
1195     #[inline]
from((v, z): (U16Vec2, u16)) -> Self1196     fn from((v, z): (U16Vec2, u16)) -> Self {
1197         Self::new(v.x, v.y, z)
1198     }
1199 }
1200 
1201 impl TryFrom<I16Vec3> for U16Vec3 {
1202     type Error = core::num::TryFromIntError;
1203 
1204     #[inline]
try_from(v: I16Vec3) -> Result<Self, Self::Error>1205     fn try_from(v: I16Vec3) -> Result<Self, Self::Error> {
1206         Ok(Self::new(
1207             u16::try_from(v.x)?,
1208             u16::try_from(v.y)?,
1209             u16::try_from(v.z)?,
1210         ))
1211     }
1212 }
1213 
1214 impl TryFrom<IVec3> for U16Vec3 {
1215     type Error = core::num::TryFromIntError;
1216 
1217     #[inline]
try_from(v: IVec3) -> Result<Self, Self::Error>1218     fn try_from(v: IVec3) -> Result<Self, Self::Error> {
1219         Ok(Self::new(
1220             u16::try_from(v.x)?,
1221             u16::try_from(v.y)?,
1222             u16::try_from(v.z)?,
1223         ))
1224     }
1225 }
1226 
1227 impl TryFrom<UVec3> for U16Vec3 {
1228     type Error = core::num::TryFromIntError;
1229 
1230     #[inline]
try_from(v: UVec3) -> Result<Self, Self::Error>1231     fn try_from(v: UVec3) -> Result<Self, Self::Error> {
1232         Ok(Self::new(
1233             u16::try_from(v.x)?,
1234             u16::try_from(v.y)?,
1235             u16::try_from(v.z)?,
1236         ))
1237     }
1238 }
1239 
1240 impl TryFrom<I64Vec3> for U16Vec3 {
1241     type Error = core::num::TryFromIntError;
1242 
1243     #[inline]
try_from(v: I64Vec3) -> Result<Self, Self::Error>1244     fn try_from(v: I64Vec3) -> Result<Self, Self::Error> {
1245         Ok(Self::new(
1246             u16::try_from(v.x)?,
1247             u16::try_from(v.y)?,
1248             u16::try_from(v.z)?,
1249         ))
1250     }
1251 }
1252 
1253 impl TryFrom<U64Vec3> for U16Vec3 {
1254     type Error = core::num::TryFromIntError;
1255 
1256     #[inline]
try_from(v: U64Vec3) -> Result<Self, Self::Error>1257     fn try_from(v: U64Vec3) -> Result<Self, Self::Error> {
1258         Ok(Self::new(
1259             u16::try_from(v.x)?,
1260             u16::try_from(v.y)?,
1261             u16::try_from(v.z)?,
1262         ))
1263     }
1264 }
1265