glam/u16/
u16vec3.rs

1// Generated from vec.rs.tera template. Edit the template, not the generated file.
2
3use crate::{BVec3, I16Vec3, I64Vec3, IVec3, U16Vec2, U16Vec4, U64Vec3, UVec3};
4
5#[cfg(not(target_arch = "spirv"))]
6use core::fmt;
7use core::iter::{Product, Sum};
8use core::{f32, ops::*};
9
10/// Creates a 3-dimensional vector.
11#[inline(always)]
12#[must_use]
13pub 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))]
22pub struct U16Vec3 {
23    pub x: u16,
24    pub y: u16,
25    pub z: u16,
26}
27
28impl 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]
56    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]
63    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]
74    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]
85    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]
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]
103    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]
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]
123    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]
134    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]
143    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]
151    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]
158    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]
165    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]
178    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]
191    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]
208    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]
218    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]
227    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]
238    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]
249    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]
260    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]
271    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]
282    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]
293    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]
301    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]
308    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]
315    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]
322    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]
329    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]
336    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]
343    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]
350    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]
357    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]
366    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]
379    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]
392    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]
405    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]
418    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]
431    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]
444    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]
457    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
466impl Default for U16Vec3 {
467    #[inline(always)]
468    fn default() -> Self {
469        Self::ZERO
470    }
471}
472
473impl Div<U16Vec3> for U16Vec3 {
474    type Output = Self;
475    #[inline]
476    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
485impl DivAssign<U16Vec3> for U16Vec3 {
486    #[inline]
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
494impl Div<u16> for U16Vec3 {
495    type Output = Self;
496    #[inline]
497    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
506impl DivAssign<u16> for U16Vec3 {
507    #[inline]
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
515impl Div<U16Vec3> for u16 {
516    type Output = U16Vec3;
517    #[inline]
518    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
527impl Mul<U16Vec3> for U16Vec3 {
528    type Output = Self;
529    #[inline]
530    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
539impl MulAssign<U16Vec3> for U16Vec3 {
540    #[inline]
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
548impl Mul<u16> for U16Vec3 {
549    type Output = Self;
550    #[inline]
551    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
560impl MulAssign<u16> for U16Vec3 {
561    #[inline]
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
569impl Mul<U16Vec3> for u16 {
570    type Output = U16Vec3;
571    #[inline]
572    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
581impl Add<U16Vec3> for U16Vec3 {
582    type Output = Self;
583    #[inline]
584    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
593impl AddAssign<U16Vec3> for U16Vec3 {
594    #[inline]
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
602impl Add<u16> for U16Vec3 {
603    type Output = Self;
604    #[inline]
605    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
614impl AddAssign<u16> for U16Vec3 {
615    #[inline]
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
623impl Add<U16Vec3> for u16 {
624    type Output = U16Vec3;
625    #[inline]
626    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
635impl Sub<U16Vec3> for U16Vec3 {
636    type Output = Self;
637    #[inline]
638    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
647impl SubAssign<U16Vec3> for U16Vec3 {
648    #[inline]
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
656impl Sub<u16> for U16Vec3 {
657    type Output = Self;
658    #[inline]
659    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
668impl SubAssign<u16> for U16Vec3 {
669    #[inline]
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
677impl Sub<U16Vec3> for u16 {
678    type Output = U16Vec3;
679    #[inline]
680    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
689impl Rem<U16Vec3> for U16Vec3 {
690    type Output = Self;
691    #[inline]
692    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
701impl RemAssign<U16Vec3> for U16Vec3 {
702    #[inline]
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
710impl Rem<u16> for U16Vec3 {
711    type Output = Self;
712    #[inline]
713    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
722impl RemAssign<u16> for U16Vec3 {
723    #[inline]
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
731impl Rem<U16Vec3> for u16 {
732    type Output = U16Vec3;
733    #[inline]
734    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"))]
744impl AsRef<[u16; 3]> for U16Vec3 {
745    #[inline]
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"))]
752impl AsMut<[u16; 3]> for U16Vec3 {
753    #[inline]
754    fn as_mut(&mut self) -> &mut [u16; 3] {
755        unsafe { &mut *(self as *mut U16Vec3 as *mut [u16; 3]) }
756    }
757}
758
759impl Sum for U16Vec3 {
760    #[inline]
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
769impl<'a> Sum<&'a Self> for U16Vec3 {
770    #[inline]
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
779impl Product for U16Vec3 {
780    #[inline]
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
789impl<'a> Product<&'a Self> for U16Vec3 {
790    #[inline]
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
799impl Not for U16Vec3 {
800    type Output = Self;
801    #[inline]
802    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
811impl BitAnd for U16Vec3 {
812    type Output = Self;
813    #[inline]
814    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
823impl BitOr for U16Vec3 {
824    type Output = Self;
825    #[inline]
826    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
835impl BitXor for U16Vec3 {
836    type Output = Self;
837    #[inline]
838    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
847impl BitAnd<u16> for U16Vec3 {
848    type Output = Self;
849    #[inline]
850    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
859impl BitOr<u16> for U16Vec3 {
860    type Output = Self;
861    #[inline]
862    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
871impl BitXor<u16> for U16Vec3 {
872    type Output = Self;
873    #[inline]
874    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
883impl Shl<i8> for U16Vec3 {
884    type Output = Self;
885    #[inline]
886    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
895impl Shr<i8> for U16Vec3 {
896    type Output = Self;
897    #[inline]
898    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
907impl Shl<i16> for U16Vec3 {
908    type Output = Self;
909    #[inline]
910    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
919impl Shr<i16> for U16Vec3 {
920    type Output = Self;
921    #[inline]
922    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
931impl Shl<i32> for U16Vec3 {
932    type Output = Self;
933    #[inline]
934    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
943impl Shr<i32> for U16Vec3 {
944    type Output = Self;
945    #[inline]
946    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
955impl Shl<i64> for U16Vec3 {
956    type Output = Self;
957    #[inline]
958    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
967impl Shr<i64> for U16Vec3 {
968    type Output = Self;
969    #[inline]
970    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
979impl Shl<u8> for U16Vec3 {
980    type Output = Self;
981    #[inline]
982    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
991impl Shr<u8> for U16Vec3 {
992    type Output = Self;
993    #[inline]
994    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
1003impl Shl<u16> for U16Vec3 {
1004    type Output = Self;
1005    #[inline]
1006    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
1015impl Shr<u16> for U16Vec3 {
1016    type Output = Self;
1017    #[inline]
1018    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
1027impl Shl<u32> for U16Vec3 {
1028    type Output = Self;
1029    #[inline]
1030    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
1039impl Shr<u32> for U16Vec3 {
1040    type Output = Self;
1041    #[inline]
1042    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
1051impl Shl<u64> for U16Vec3 {
1052    type Output = Self;
1053    #[inline]
1054    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
1063impl Shr<u64> for U16Vec3 {
1064    type Output = Self;
1065    #[inline]
1066    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
1075impl Shl<crate::IVec3> for U16Vec3 {
1076    type Output = Self;
1077    #[inline]
1078    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
1087impl Shr<crate::IVec3> for U16Vec3 {
1088    type Output = Self;
1089    #[inline]
1090    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
1099impl Shl<crate::UVec3> for U16Vec3 {
1100    type Output = Self;
1101    #[inline]
1102    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
1111impl Shr<crate::UVec3> for U16Vec3 {
1112    type Output = Self;
1113    #[inline]
1114    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
1123impl Index<usize> for U16Vec3 {
1124    type Output = u16;
1125    #[inline]
1126    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
1136impl IndexMut<usize> for U16Vec3 {
1137    #[inline]
1138    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"))]
1149impl fmt::Display for U16Vec3 {
1150    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"))]
1156impl fmt::Debug for U16Vec3 {
1157    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
1166impl From<[u16; 3]> for U16Vec3 {
1167    #[inline]
1168    fn from(a: [u16; 3]) -> Self {
1169        Self::new(a[0], a[1], a[2])
1170    }
1171}
1172
1173impl From<U16Vec3> for [u16; 3] {
1174    #[inline]
1175    fn from(v: U16Vec3) -> Self {
1176        [v.x, v.y, v.z]
1177    }
1178}
1179
1180impl From<(u16, u16, u16)> for U16Vec3 {
1181    #[inline]
1182    fn from(t: (u16, u16, u16)) -> Self {
1183        Self::new(t.0, t.1, t.2)
1184    }
1185}
1186
1187impl From<U16Vec3> for (u16, u16, u16) {
1188    #[inline]
1189    fn from(v: U16Vec3) -> Self {
1190        (v.x, v.y, v.z)
1191    }
1192}
1193
1194impl From<(U16Vec2, u16)> for U16Vec3 {
1195    #[inline]
1196    fn from((v, z): (U16Vec2, u16)) -> Self {
1197        Self::new(v.x, v.y, z)
1198    }
1199}
1200
1201impl TryFrom<I16Vec3> for U16Vec3 {
1202    type Error = core::num::TryFromIntError;
1203
1204    #[inline]
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
1214impl TryFrom<IVec3> for U16Vec3 {
1215    type Error = core::num::TryFromIntError;
1216
1217    #[inline]
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
1227impl TryFrom<UVec3> for U16Vec3 {
1228    type Error = core::num::TryFromIntError;
1229
1230    #[inline]
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
1240impl TryFrom<I64Vec3> for U16Vec3 {
1241    type Error = core::num::TryFromIntError;
1242
1243    #[inline]
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
1253impl TryFrom<U64Vec3> for U16Vec3 {
1254    type Error = core::num::TryFromIntError;
1255
1256    #[inline]
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}