Debian Codegraph @

debian/missing-sources/glam-0.23.0/src/u32/uvec3.rs

raw symbols SCIP
1 // Generated from vec.rs.tera template. Edit the template, not the generated file.
2
3 use crate::{BVec3, UVec2, UVec4};
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 pub const fn uvec3(x: u32, y: u32, z: u32) -> UVec3 {
13 UVec3::new(x, y, z)
14 }
15
16 /// A 3-dimensional vector.
17 #[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
18 #[derive(Clone, Copy, PartialEq, Eq)]
19 #[cfg_attr(not(target_arch = "spirv"), repr(C))]
20 #[cfg_attr(target_arch = "spirv", repr(simd))]
21 pub struct UVec3 {
22 pub x: u32,
23 pub y: u32,
24 pub z: u32,
25 }
26
27 impl UVec3 {
28 /// All zeroes.
29 pub const ZERO: Self = Self::splat(0);
30
31 /// All ones.
32 pub const ONE: Self = Self::splat(1);
33
34 /// A unit-length vector pointing along the positive X axis.
35 pub const X: Self = Self::new(1, 0, 0);
36
37 /// A unit-length vector pointing along the positive Y axis.
38 pub const Y: Self = Self::new(0, 1, 0);
39
40 /// A unit-length vector pointing along the positive Z axis.
41 pub const Z: Self = Self::new(0, 0, 1);
42
43 /// The unit axes.
44 pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
45
46 /// Creates a new vector.
47 #[inline(always)]
48 pub const fn new(x: u32, y: u32, z: u32) -> Self {
49 Self { x, y, z }
50 }
51
52 /// Creates a vector with all elements set to `v`.
53 #[inline]
54 pub const fn splat(v: u32) -> Self {
55 Self { x: v, y: v, z: v }
56 }
57
58 /// Creates a vector from the elements in `if_true` and `if_false`, selecting which to use
59 /// for each element of `self`.
60 ///
61 /// A true element in the mask uses the corresponding element from `if_true`, and false
62 /// uses the element from `if_false`.
63 #[inline]
64 pub fn select(mask: BVec3, if_true: Self, if_false: Self) -> Self {
65 Self {
66 x: if mask.x { if_true.x } else { if_false.x },
67 y: if mask.y { if_true.y } else { if_false.y },
68 z: if mask.z { if_true.z } else { if_false.z },
69 }
70 }
71
72 /// Creates a new vector from an array.
73 #[inline]
74 pub const fn from_array(a: [u32; 3]) -> Self {
75 Self::new(a[0], a[1], a[2])
76 }
77
78 /// `[x, y, z]`
79 #[inline]
80 pub const fn to_array(&self) -> [u32; 3] {
81 [self.x, self.y, self.z]
82 }
83
84 /// Creates a vector from the first 3 values in `slice`.
85 ///
86 /// # Panics
87 ///
88 /// Panics if `slice` is less than 3 elements long.
89 #[inline]
90 pub const fn from_slice(slice: &[u32]) -> Self {
91 Self::new(slice[0], slice[1], slice[2])
92 }
93
94 /// Writes the elements of `self` to the first 3 elements in `slice`.
95 ///
96 /// # Panics
97 ///
98 /// Panics if `slice` is less than 3 elements long.
99 #[inline]
100 pub fn write_to_slice(self, slice: &mut [u32]) {
101 slice[0] = self.x;
102 slice[1] = self.y;
103 slice[2] = self.z;
104 }
105
106 /// Internal method for creating a 3D vector from a 4D vector, discarding `w`.
107 #[allow(dead_code)]
108 #[inline]
109 pub(crate) fn from_vec4(v: UVec4) -> Self {
110 Self {
111 x: v.x,
112 y: v.y,
113 z: v.z,
114 }
115 }
116
117 /// Creates a 4D vector from `self` and the given `w` value.
118 #[inline]
119 pub fn extend(self, w: u32) -> UVec4 {
120 UVec4::new(self.x, self.y, self.z, w)
121 }
122
123 /// Creates a 2D vector from the `x` and `y` elements of `self`, discarding `z`.
124 ///
125 /// Truncation may also be performed by using `self.xy()` or `UVec2::from()`.
126 #[inline]
127 pub fn truncate(self) -> UVec2 {
128 use crate::swizzles::Vec3Swizzles;
129 self.xy()
130 }
131
132 /// Computes the dot product of `self` and `rhs`.
133 #[inline]
134 pub fn dot(self, rhs: Self) -> u32 {
135 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z)
136 }
137
138 /// Returns a vector where every component is the dot product of `self` and `rhs`.
139 #[inline]
140 pub fn dot_into_vec(self, rhs: Self) -> Self {
141 Self::splat(self.dot(rhs))
142 }
143
144 /// Computes the cross product of `self` and `rhs`.
145 #[inline]
146 pub fn cross(self, rhs: Self) -> Self {
147 Self {
148 x: self.y * rhs.z - rhs.y * self.z,
149 y: self.z * rhs.x - rhs.z * self.x,
150 z: self.x * rhs.y - rhs.x * self.y,
151 }
152 }
153
154 /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
155 ///
156 /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
157 #[inline]
158 pub fn min(self, rhs: Self) -> Self {
159 Self {
160 x: self.x.min(rhs.x),
161 y: self.y.min(rhs.y),
162 z: self.z.min(rhs.z),
163 }
164 }
165
166 /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
167 ///
168 /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
169 #[inline]
170 pub fn max(self, rhs: Self) -> Self {
171 Self {
172 x: self.x.max(rhs.x),
173 y: self.y.max(rhs.y),
174 z: self.z.max(rhs.z),
175 }
176 }
177
178 /// Component-wise clamping of values, similar to [`u32::clamp`].
179 ///
180 /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
181 ///
182 /// # Panics
183 ///
184 /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
185 #[inline]
186 pub fn clamp(self, min: Self, max: Self) -> Self {
187 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
188 self.max(min).min(max)
189 }
190
191 /// Returns the horizontal minimum of `self`.
192 ///
193 /// In other words this computes `min(x, y, ..)`.
194 #[inline]
195 pub fn min_element(self) -> u32 {
196 self.x.min(self.y.min(self.z))
197 }
198
199 /// Returns the horizontal maximum of `self`.
200 ///
201 /// In other words this computes `max(x, y, ..)`.
202 #[inline]
203 pub fn max_element(self) -> u32 {
204 self.x.max(self.y.max(self.z))
205 }
206
207 /// Returns a vector mask containing the result of a `==` comparison for each element of
208 /// `self` and `rhs`.
209 ///
210 /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
211 /// elements.
212 #[inline]
213 pub fn cmpeq(self, rhs: Self) -> BVec3 {
214 BVec3::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
215 }
216
217 /// Returns a vector mask containing the result of a `!=` comparison for each element of
218 /// `self` and `rhs`.
219 ///
220 /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
221 /// elements.
222 #[inline]
223 pub fn cmpne(self, rhs: Self) -> BVec3 {
224 BVec3::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
225 }
226
227 /// Returns a vector mask containing the result of a `>=` comparison for each element of
228 /// `self` and `rhs`.
229 ///
230 /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
231 /// elements.
232 #[inline]
233 pub fn cmpge(self, rhs: Self) -> BVec3 {
234 BVec3::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
235 }
236
237 /// Returns a vector mask containing the result of a `>` comparison for each element of
238 /// `self` and `rhs`.
239 ///
240 /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
241 /// elements.
242 #[inline]
243 pub fn cmpgt(self, rhs: Self) -> BVec3 {
244 BVec3::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
245 }
246
247 /// Returns a vector mask containing the result of a `<=` comparison for each element of
248 /// `self` and `rhs`.
249 ///
250 /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
251 /// elements.
252 #[inline]
253 pub fn cmple(self, rhs: Self) -> BVec3 {
254 BVec3::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
255 }
256
257 /// Returns a vector mask containing the result of a `<` comparison for each element of
258 /// `self` and `rhs`.
259 ///
260 /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
261 /// elements.
262 #[inline]
263 pub fn cmplt(self, rhs: Self) -> BVec3 {
264 BVec3::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
265 }
266
267 /// Casts all elements of `self` to `f32`.
268 #[inline]
269 pub fn as_vec3(&self) -> crate::Vec3 {
270 crate::Vec3::new(self.x as f32, self.y as f32, self.z as f32)
271 }
272
273 /// Casts all elements of `self` to `f32`.
274 #[inline]
275 pub fn as_vec3a(&self) -> crate::Vec3A {
276 crate::Vec3A::new(self.x as f32, self.y as f32, self.z as f32)
277 }
278
279 /// Casts all elements of `self` to `f64`.
280 #[inline]
281 pub fn as_dvec3(&self) -> crate::DVec3 {
282 crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
283 }
284
285 /// Casts all elements of `self` to `i32`.
286 #[inline]
287 pub fn as_ivec3(&self) -> crate::IVec3 {
288 crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
289 }
290 }
291
292 impl Default for UVec3 {
293 #[inline(always)]
294 fn default() -> Self {
295 Self::ZERO
296 }
297 }
298
299 impl Div<UVec3> for UVec3 {
300 type Output = Self;
301 #[inline]
302 fn div(self, rhs: Self) -> Self {
303 Self {
304 x: self.x.div(rhs.x),
305 y: self.y.div(rhs.y),
306 z: self.z.div(rhs.z),
307 }
308 }
309 }
310
311 impl DivAssign<UVec3> for UVec3 {
312 #[inline]
313 fn div_assign(&mut self, rhs: Self) {
314 self.x.div_assign(rhs.x);
315 self.y.div_assign(rhs.y);
316 self.z.div_assign(rhs.z);
317 }
318 }
319
320 impl Div<u32> for UVec3 {
321 type Output = Self;
322 #[inline]
323 fn div(self, rhs: u32) -> Self {
324 Self {
325 x: self.x.div(rhs),
326 y: self.y.div(rhs),
327 z: self.z.div(rhs),
328 }
329 }
330 }
331
332 impl DivAssign<u32> for UVec3 {
333 #[inline]
334 fn div_assign(&mut self, rhs: u32) {
335 self.x.div_assign(rhs);
336 self.y.div_assign(rhs);
337 self.z.div_assign(rhs);
338 }
339 }
340
341 impl Div<UVec3> for u32 {
342 type Output = UVec3;
343 #[inline]
344 fn div(self, rhs: UVec3) -> UVec3 {
345 UVec3 {
346 x: self.div(rhs.x),
347 y: self.div(rhs.y),
348 z: self.div(rhs.z),
349 }
350 }
351 }
352
353 impl Mul<UVec3> for UVec3 {
354 type Output = Self;
355 #[inline]
356 fn mul(self, rhs: Self) -> Self {
357 Self {
358 x: self.x.mul(rhs.x),
359 y: self.y.mul(rhs.y),
360 z: self.z.mul(rhs.z),
361 }
362 }
363 }
364
365 impl MulAssign<UVec3> for UVec3 {
366 #[inline]
367 fn mul_assign(&mut self, rhs: Self) {
368 self.x.mul_assign(rhs.x);
369 self.y.mul_assign(rhs.y);
370 self.z.mul_assign(rhs.z);
371 }
372 }
373
374 impl Mul<u32> for UVec3 {
375 type Output = Self;
376 #[inline]
377 fn mul(self, rhs: u32) -> Self {
378 Self {
379 x: self.x.mul(rhs),
380 y: self.y.mul(rhs),
381 z: self.z.mul(rhs),
382 }
383 }
384 }
385
386 impl MulAssign<u32> for UVec3 {
387 #[inline]
388 fn mul_assign(&mut self, rhs: u32) {
389 self.x.mul_assign(rhs);
390 self.y.mul_assign(rhs);
391 self.z.mul_assign(rhs);
392 }
393 }
394
395 impl Mul<UVec3> for u32 {
396 type Output = UVec3;
397 #[inline]
398 fn mul(self, rhs: UVec3) -> UVec3 {
399 UVec3 {
400 x: self.mul(rhs.x),
401 y: self.mul(rhs.y),
402 z: self.mul(rhs.z),
403 }
404 }
405 }
406
407 impl Add<UVec3> for UVec3 {
408 type Output = Self;
409 #[inline]
410 fn add(self, rhs: Self) -> Self {
411 Self {
412 x: self.x.add(rhs.x),
413 y: self.y.add(rhs.y),
414 z: self.z.add(rhs.z),
415 }
416 }
417 }
418
419 impl AddAssign<UVec3> for UVec3 {
420 #[inline]
421 fn add_assign(&mut self, rhs: Self) {
422 self.x.add_assign(rhs.x);
423 self.y.add_assign(rhs.y);
424 self.z.add_assign(rhs.z);
425 }
426 }
427
428 impl Add<u32> for UVec3 {
429 type Output = Self;
430 #[inline]
431 fn add(self, rhs: u32) -> Self {
432 Self {
433 x: self.x.add(rhs),
434 y: self.y.add(rhs),
435 z: self.z.add(rhs),
436 }
437 }
438 }
439
440 impl AddAssign<u32> for UVec3 {
441 #[inline]
442 fn add_assign(&mut self, rhs: u32) {
443 self.x.add_assign(rhs);
444 self.y.add_assign(rhs);
445 self.z.add_assign(rhs);
446 }
447 }
448
449 impl Add<UVec3> for u32 {
450 type Output = UVec3;
451 #[inline]
452 fn add(self, rhs: UVec3) -> UVec3 {
453 UVec3 {
454 x: self.add(rhs.x),
455 y: self.add(rhs.y),
456 z: self.add(rhs.z),
457 }
458 }
459 }
460
461 impl Sub<UVec3> for UVec3 {
462 type Output = Self;
463 #[inline]
464 fn sub(self, rhs: Self) -> Self {
465 Self {
466 x: self.x.sub(rhs.x),
467 y: self.y.sub(rhs.y),
468 z: self.z.sub(rhs.z),
469 }
470 }
471 }
472
473 impl SubAssign<UVec3> for UVec3 {
474 #[inline]
475 fn sub_assign(&mut self, rhs: UVec3) {
476 self.x.sub_assign(rhs.x);
477 self.y.sub_assign(rhs.y);
478 self.z.sub_assign(rhs.z);
479 }
480 }
481
482 impl Sub<u32> for UVec3 {
483 type Output = Self;
484 #[inline]
485 fn sub(self, rhs: u32) -> Self {
486 Self {
487 x: self.x.sub(rhs),
488 y: self.y.sub(rhs),
489 z: self.z.sub(rhs),
490 }
491 }
492 }
493
494 impl SubAssign<u32> for UVec3 {
495 #[inline]
496 fn sub_assign(&mut self, rhs: u32) {
497 self.x.sub_assign(rhs);
498 self.y.sub_assign(rhs);
499 self.z.sub_assign(rhs);
500 }
501 }
502
503 impl Sub<UVec3> for u32 {
504 type Output = UVec3;
505 #[inline]
506 fn sub(self, rhs: UVec3) -> UVec3 {
507 UVec3 {
508 x: self.sub(rhs.x),
509 y: self.sub(rhs.y),
510 z: self.sub(rhs.z),
511 }
512 }
513 }
514
515 impl Rem<UVec3> for UVec3 {
516 type Output = Self;
517 #[inline]
518 fn rem(self, rhs: Self) -> Self {
519 Self {
520 x: self.x.rem(rhs.x),
521 y: self.y.rem(rhs.y),
522 z: self.z.rem(rhs.z),
523 }
524 }
525 }
526
527 impl RemAssign<UVec3> for UVec3 {
528 #[inline]
529 fn rem_assign(&mut self, rhs: Self) {
530 self.x.rem_assign(rhs.x);
531 self.y.rem_assign(rhs.y);
532 self.z.rem_assign(rhs.z);
533 }
534 }
535
536 impl Rem<u32> for UVec3 {
537 type Output = Self;
538 #[inline]
539 fn rem(self, rhs: u32) -> Self {
540 Self {
541 x: self.x.rem(rhs),
542 y: self.y.rem(rhs),
543 z: self.z.rem(rhs),
544 }
545 }
546 }
547
548 impl RemAssign<u32> for UVec3 {
549 #[inline]
550 fn rem_assign(&mut self, rhs: u32) {
551 self.x.rem_assign(rhs);
552 self.y.rem_assign(rhs);
553 self.z.rem_assign(rhs);
554 }
555 }
556
557 impl Rem<UVec3> for u32 {
558 type Output = UVec3;
559 #[inline]
560 fn rem(self, rhs: UVec3) -> UVec3 {
561 UVec3 {
562 x: self.rem(rhs.x),
563 y: self.rem(rhs.y),
564 z: self.rem(rhs.z),
565 }
566 }
567 }
568
569 #[cfg(not(target_arch = "spirv"))]
570 impl AsRef<[u32; 3]> for UVec3 {
571 #[inline]
572 fn as_ref(&self) -> &[u32; 3] {
573 unsafe { &*(self as *const UVec3 as *const [u32; 3]) }
574 }
575 }
576
577 #[cfg(not(target_arch = "spirv"))]
578 impl AsMut<[u32; 3]> for UVec3 {
579 #[inline]
580 fn as_mut(&mut self) -> &mut [u32; 3] {
581 unsafe { &mut *(self as *mut UVec3 as *mut [u32; 3]) }
582 }
583 }
584
585 impl Sum for UVec3 {
586 #[inline]
587 fn sum<I>(iter: I) -> Self
588 where
589 I: Iterator<Item = Self>,
590 {
591 iter.fold(Self::ZERO, Self::add)
592 }
593 }
594
595 impl<'a> Sum<&'a Self> for UVec3 {
596 #[inline]
597 fn sum<I>(iter: I) -> Self
598 where
599 I: Iterator<Item = &'a Self>,
600 {
601 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
602 }
603 }
604
605 impl Product for UVec3 {
606 #[inline]
607 fn product<I>(iter: I) -> Self
608 where
609 I: Iterator<Item = Self>,
610 {
611 iter.fold(Self::ONE, Self::mul)
612 }
613 }
614
615 impl<'a> Product<&'a Self> for UVec3 {
616 #[inline]
617 fn product<I>(iter: I) -> Self
618 where
619 I: Iterator<Item = &'a Self>,
620 {
621 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
622 }
623 }
624
625 impl Not for UVec3 {
626 type Output = Self;
627 #[inline]
628 fn not(self) -> Self::Output {
629 Self {
630 x: self.x.not(),
631 y: self.y.not(),
632 z: self.z.not(),
633 }
634 }
635 }
636
637 impl BitAnd for UVec3 {
638 type Output = Self;
639 #[inline]
640 fn bitand(self, rhs: Self) -> Self::Output {
641 Self {
642 x: self.x.bitand(rhs.x),
643 y: self.y.bitand(rhs.y),
644 z: self.z.bitand(rhs.z),
645 }
646 }
647 }
648
649 impl BitOr for UVec3 {
650 type Output = Self;
651 #[inline]
652 fn bitor(self, rhs: Self) -> Self::Output {
653 Self {
654 x: self.x.bitor(rhs.x),
655 y: self.y.bitor(rhs.y),
656 z: self.z.bitor(rhs.z),
657 }
658 }
659 }
660
661 impl BitXor for UVec3 {
662 type Output = Self;
663 #[inline]
664 fn bitxor(self, rhs: Self) -> Self::Output {
665 Self {
666 x: self.x.bitxor(rhs.x),
667 y: self.y.bitxor(rhs.y),
668 z: self.z.bitxor(rhs.z),
669 }
670 }
671 }
672
673 impl BitAnd<u32> for UVec3 {
674 type Output = Self;
675 #[inline]
676 fn bitand(self, rhs: u32) -> Self::Output {
677 Self {
678 x: self.x.bitand(rhs),
679 y: self.y.bitand(rhs),
680 z: self.z.bitand(rhs),
681 }
682 }
683 }
684
685 impl BitOr<u32> for UVec3 {
686 type Output = Self;
687 #[inline]
688 fn bitor(self, rhs: u32) -> Self::Output {
689 Self {
690 x: self.x.bitor(rhs),
691 y: self.y.bitor(rhs),
692 z: self.z.bitor(rhs),
693 }
694 }
695 }
696
697 impl BitXor<u32> for UVec3 {
698 type Output = Self;
699 #[inline]
700 fn bitxor(self, rhs: u32) -> Self::Output {
701 Self {
702 x: self.x.bitxor(rhs),
703 y: self.y.bitxor(rhs),
704 z: self.z.bitxor(rhs),
705 }
706 }
707 }
708
709 impl Shl<i8> for UVec3 {
710 type Output = Self;
711 #[inline]
712 fn shl(self, rhs: i8) -> Self::Output {
713 Self {
714 x: self.x.shl(rhs),
715 y: self.y.shl(rhs),
716 z: self.z.shl(rhs),
717 }
718 }
719 }
720
721 impl Shr<i8> for UVec3 {
722 type Output = Self;
723 #[inline]
724 fn shr(self, rhs: i8) -> Self::Output {
725 Self {
726 x: self.x.shr(rhs),
727 y: self.y.shr(rhs),
728 z: self.z.shr(rhs),
729 }
730 }
731 }
732
733 impl Shl<i16> for UVec3 {
734 type Output = Self;
735 #[inline]
736 fn shl(self, rhs: i16) -> Self::Output {
737 Self {
738 x: self.x.shl(rhs),
739 y: self.y.shl(rhs),
740 z: self.z.shl(rhs),
741 }
742 }
743 }
744
745 impl Shr<i16> for UVec3 {
746 type Output = Self;
747 #[inline]
748 fn shr(self, rhs: i16) -> Self::Output {
749 Self {
750 x: self.x.shr(rhs),
751 y: self.y.shr(rhs),
752 z: self.z.shr(rhs),
753 }
754 }
755 }
756
757 impl Shl<i32> for UVec3 {
758 type Output = Self;
759 #[inline]
760 fn shl(self, rhs: i32) -> Self::Output {
761 Self {
762 x: self.x.shl(rhs),
763 y: self.y.shl(rhs),
764 z: self.z.shl(rhs),
765 }
766 }
767 }
768
769 impl Shr<i32> for UVec3 {
770 type Output = Self;
771 #[inline]
772 fn shr(self, rhs: i32) -> Self::Output {
773 Self {
774 x: self.x.shr(rhs),
775 y: self.y.shr(rhs),
776 z: self.z.shr(rhs),
777 }
778 }
779 }
780
781 impl Shl<u8> for UVec3 {
782 type Output = Self;
783 #[inline]
784 fn shl(self, rhs: u8) -> Self::Output {
785 Self {
786 x: self.x.shl(rhs),
787 y: self.y.shl(rhs),
788 z: self.z.shl(rhs),
789 }
790 }
791 }
792
793 impl Shr<u8> for UVec3 {
794 type Output = Self;
795 #[inline]
796 fn shr(self, rhs: u8) -> Self::Output {
797 Self {
798 x: self.x.shr(rhs),
799 y: self.y.shr(rhs),
800 z: self.z.shr(rhs),
801 }
802 }
803 }
804
805 impl Shl<u16> for UVec3 {
806 type Output = Self;
807 #[inline]
808 fn shl(self, rhs: u16) -> Self::Output {
809 Self {
810 x: self.x.shl(rhs),
811 y: self.y.shl(rhs),
812 z: self.z.shl(rhs),
813 }
814 }
815 }
816
817 impl Shr<u16> for UVec3 {
818 type Output = Self;
819 #[inline]
820 fn shr(self, rhs: u16) -> Self::Output {
821 Self {
822 x: self.x.shr(rhs),
823 y: self.y.shr(rhs),
824 z: self.z.shr(rhs),
825 }
826 }
827 }
828
829 impl Shl<u32> for UVec3 {
830 type Output = Self;
831 #[inline]
832 fn shl(self, rhs: u32) -> Self::Output {
833 Self {
834 x: self.x.shl(rhs),
835 y: self.y.shl(rhs),
836 z: self.z.shl(rhs),
837 }
838 }
839 }
840
841 impl Shr<u32> for UVec3 {
842 type Output = Self;
843 #[inline]
844 fn shr(self, rhs: u32) -> Self::Output {
845 Self {
846 x: self.x.shr(rhs),
847 y: self.y.shr(rhs),
848 z: self.z.shr(rhs),
849 }
850 }
851 }
852
853 impl Shl<crate::IVec3> for UVec3 {
854 type Output = Self;
855 #[inline]
856 fn shl(self, rhs: crate::IVec3) -> Self::Output {
857 Self {
858 x: self.x.shl(rhs.x),
859 y: self.y.shl(rhs.y),
860 z: self.z.shl(rhs.z),
861 }
862 }
863 }
864
865 impl Shr<crate::IVec3> for UVec3 {
866 type Output = Self;
867 #[inline]
868 fn shr(self, rhs: crate::IVec3) -> Self::Output {
869 Self {
870 x: self.x.shr(rhs.x),
871 y: self.y.shr(rhs.y),
872 z: self.z.shr(rhs.z),
873 }
874 }
875 }
876
877 impl Shl<crate::UVec3> for UVec3 {
878 type Output = Self;
879 #[inline]
880 fn shl(self, rhs: crate::UVec3) -> Self::Output {
881 Self {
882 x: self.x.shl(rhs.x),
883 y: self.y.shl(rhs.y),
884 z: self.z.shl(rhs.z),
885 }
886 }
887 }
888
889 impl Shr<crate::UVec3> for UVec3 {
890 type Output = Self;
891 #[inline]
892 fn shr(self, rhs: crate::UVec3) -> Self::Output {
893 Self {
894 x: self.x.shr(rhs.x),
895 y: self.y.shr(rhs.y),
896 z: self.z.shr(rhs.z),
897 }
898 }
899 }
900
901 impl Index<usize> for UVec3 {
902 type Output = u32;
903 #[inline]
904 fn index(&self, index: usize) -> &Self::Output {
905 match index {
906 0 => &self.x,
907 1 => &self.y,
908 2 => &self.z,
909 _ => panic!("index out of bounds"),
910 }
911 }
912 }
913
914 impl IndexMut<usize> for UVec3 {
915 #[inline]
916 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
917 match index {
918 0 => &mut self.x,
919 1 => &mut self.y,
920 2 => &mut self.z,
921 _ => panic!("index out of bounds"),
922 }
923 }
924 }
925
926 #[cfg(not(target_arch = "spirv"))]
927 impl fmt::Display for UVec3 {
928 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
929 write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
930 }
931 }
932
933 #[cfg(not(target_arch = "spirv"))]
934 impl fmt::Debug for UVec3 {
935 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
936 fmt.debug_tuple(stringify!(UVec3))
937 .field(&self.x)
938 .field(&self.y)
939 .field(&self.z)
940 .finish()
941 }
942 }
943
944 impl From<[u32; 3]> for UVec3 {
945 #[inline]
946 fn from(a: [u32; 3]) -> Self {
947 Self::new(a[0], a[1], a[2])
948 }
949 }
950
951 impl From<UVec3> for [u32; 3] {
952 #[inline]
953 fn from(v: UVec3) -> Self {
954 [v.x, v.y, v.z]
955 }
956 }
957
958 impl From<(u32, u32, u32)> for UVec3 {
959 #[inline]
960 fn from(t: (u32, u32, u32)) -> Self {
961 Self::new(t.0, t.1, t.2)
962 }
963 }
964
965 impl From<UVec3> for (u32, u32, u32) {
966 #[inline]
967 fn from(v: UVec3) -> Self {
968 (v.x, v.y, v.z)
969 }
970 }
971
972 impl From<(UVec2, u32)> for UVec3 {
973 #[inline]
974 fn from((v, z): (UVec2, u32)) -> Self {
975 Self::new(v.x, v.y, z)
976 }
977 }