Debian Codegraph @

debian/missing-sources/glam-0.28.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, BVec3A, I16Vec3, I64Vec3, IVec3, U16Vec3, U64Vec3, 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 #[must_use]
13 pub const fn uvec3(x: u32, y: u32, z: u32) -> UVec3 {
14 UVec3::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 UVec3 {
23 pub x: u32,
24 pub y: u32,
25 pub z: u32,
26 }
27
28 impl UVec3 {
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 `u32::MIN`.
36 pub const MIN: Self = Self::splat(u32::MIN);
37
38 /// All `u32::MAX`.
39 pub const MAX: Self = Self::splat(u32::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: u32, y: u32, z: u32) -> 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: u32) -> 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: [u32; 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) -> [u32; 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: &[u32]) -> 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 [u32]) {
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: UVec4) -> 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: u32) -> UVec4 {
135 UVec4::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) -> UVec2 {
144 use crate::swizzles::Vec3Swizzles;
145 self.xy()
146 }
147
148 /// Creates a 3D vector from `self` with the given value of `x`.
149 #[inline]
150 #[must_use]
151 pub fn with_x(mut self, x: u32) -> Self {
152 self.x = x;
153 self
154 }
155
156 /// Creates a 3D vector from `self` with the given value of `y`.
157 #[inline]
158 #[must_use]
159 pub fn with_y(mut self, y: u32) -> Self {
160 self.y = y;
161 self
162 }
163
164 /// Creates a 3D vector from `self` with the given value of `z`.
165 #[inline]
166 #[must_use]
167 pub fn with_z(mut self, z: u32) -> Self {
168 self.z = z;
169 self
170 }
171
172 /// Computes the dot product of `self` and `rhs`.
173 #[inline]
174 #[must_use]
175 pub fn dot(self, rhs: Self) -> u32 {
176 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z)
177 }
178
179 /// Returns a vector where every component is the dot product of `self` and `rhs`.
180 #[inline]
181 #[must_use]
182 pub fn dot_into_vec(self, rhs: Self) -> Self {
183 Self::splat(self.dot(rhs))
184 }
185
186 /// Computes the cross product of `self` and `rhs`.
187 #[inline]
188 #[must_use]
189 pub fn cross(self, rhs: Self) -> Self {
190 Self {
191 x: self.y * rhs.z - rhs.y * self.z,
192 y: self.z * rhs.x - rhs.z * self.x,
193 z: self.x * rhs.y - rhs.x * self.y,
194 }
195 }
196
197 /// Returns a vector containing the minimum values for each element of `self` and `rhs`.
198 ///
199 /// In other words this computes `[self.x.min(rhs.x), self.y.min(rhs.y), ..]`.
200 #[inline]
201 #[must_use]
202 pub fn min(self, rhs: Self) -> Self {
203 Self {
204 x: self.x.min(rhs.x),
205 y: self.y.min(rhs.y),
206 z: self.z.min(rhs.z),
207 }
208 }
209
210 /// Returns a vector containing the maximum values for each element of `self` and `rhs`.
211 ///
212 /// In other words this computes `[self.x.max(rhs.x), self.y.max(rhs.y), ..]`.
213 #[inline]
214 #[must_use]
215 pub fn max(self, rhs: Self) -> Self {
216 Self {
217 x: self.x.max(rhs.x),
218 y: self.y.max(rhs.y),
219 z: self.z.max(rhs.z),
220 }
221 }
222
223 /// Component-wise clamping of values, similar to [`u32::clamp`].
224 ///
225 /// Each element in `min` must be less-or-equal to the corresponding element in `max`.
226 ///
227 /// # Panics
228 ///
229 /// Will panic if `min` is greater than `max` when `glam_assert` is enabled.
230 #[inline]
231 #[must_use]
232 pub fn clamp(self, min: Self, max: Self) -> Self {
233 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
234 self.max(min).min(max)
235 }
236
237 /// Returns the horizontal minimum of `self`.
238 ///
239 /// In other words this computes `min(x, y, ..)`.
240 #[inline]
241 #[must_use]
242 pub fn min_element(self) -> u32 {
243 self.x.min(self.y.min(self.z))
244 }
245
246 /// Returns the horizontal maximum of `self`.
247 ///
248 /// In other words this computes `max(x, y, ..)`.
249 #[inline]
250 #[must_use]
251 pub fn max_element(self) -> u32 {
252 self.x.max(self.y.max(self.z))
253 }
254
255 /// Returns the sum of all elements of `self`.
256 ///
257 /// In other words, this computes `self.x + self.y + ..`.
258 #[inline]
259 #[must_use]
260 pub fn element_sum(self) -> u32 {
261 self.x + self.y + self.z
262 }
263
264 /// Returns the product of all elements of `self`.
265 ///
266 /// In other words, this computes `self.x * self.y * ..`.
267 #[inline]
268 #[must_use]
269 pub fn element_product(self) -> u32 {
270 self.x * self.y * self.z
271 }
272
273 /// Returns a vector mask containing the result of a `==` comparison for each element of
274 /// `self` and `rhs`.
275 ///
276 /// In other words, this computes `[self.x == rhs.x, self.y == rhs.y, ..]` for all
277 /// elements.
278 #[inline]
279 #[must_use]
280 pub fn cmpeq(self, rhs: Self) -> BVec3 {
281 BVec3::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
282 }
283
284 /// Returns a vector mask containing the result of a `!=` comparison for each element of
285 /// `self` and `rhs`.
286 ///
287 /// In other words this computes `[self.x != rhs.x, self.y != rhs.y, ..]` for all
288 /// elements.
289 #[inline]
290 #[must_use]
291 pub fn cmpne(self, rhs: Self) -> BVec3 {
292 BVec3::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
293 }
294
295 /// Returns a vector mask containing the result of a `>=` comparison for each element of
296 /// `self` and `rhs`.
297 ///
298 /// In other words this computes `[self.x >= rhs.x, self.y >= rhs.y, ..]` for all
299 /// elements.
300 #[inline]
301 #[must_use]
302 pub fn cmpge(self, rhs: Self) -> BVec3 {
303 BVec3::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
304 }
305
306 /// Returns a vector mask containing the result of a `>` comparison for each element of
307 /// `self` and `rhs`.
308 ///
309 /// In other words this computes `[self.x > rhs.x, self.y > rhs.y, ..]` for all
310 /// elements.
311 #[inline]
312 #[must_use]
313 pub fn cmpgt(self, rhs: Self) -> BVec3 {
314 BVec3::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
315 }
316
317 /// Returns a vector mask containing the result of a `<=` comparison for each element of
318 /// `self` and `rhs`.
319 ///
320 /// In other words this computes `[self.x <= rhs.x, self.y <= rhs.y, ..]` for all
321 /// elements.
322 #[inline]
323 #[must_use]
324 pub fn cmple(self, rhs: Self) -> BVec3 {
325 BVec3::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
326 }
327
328 /// Returns a vector mask containing the result of a `<` comparison for each element of
329 /// `self` and `rhs`.
330 ///
331 /// In other words this computes `[self.x < rhs.x, self.y < rhs.y, ..]` for all
332 /// elements.
333 #[inline]
334 #[must_use]
335 pub fn cmplt(self, rhs: Self) -> BVec3 {
336 BVec3::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
337 }
338
339 /// Computes the squared length of `self`.
340 #[doc(alias = "magnitude2")]
341 #[inline]
342 #[must_use]
343 pub fn length_squared(self) -> u32 {
344 self.dot(self)
345 }
346
347 /// Casts all elements of `self` to `f32`.
348 #[inline]
349 #[must_use]
350 pub fn as_vec3(&self) -> crate::Vec3 {
351 crate::Vec3::new(self.x as f32, self.y as f32, self.z as f32)
352 }
353
354 /// Casts all elements of `self` to `f32`.
355 #[inline]
356 #[must_use]
357 pub fn as_vec3a(&self) -> crate::Vec3A {
358 crate::Vec3A::new(self.x as f32, self.y as f32, self.z as f32)
359 }
360
361 /// Casts all elements of `self` to `f64`.
362 #[inline]
363 #[must_use]
364 pub fn as_dvec3(&self) -> crate::DVec3 {
365 crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
366 }
367
368 /// Casts all elements of `self` to `i16`.
369 #[inline]
370 #[must_use]
371 pub fn as_i16vec3(&self) -> crate::I16Vec3 {
372 crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
373 }
374
375 /// Casts all elements of `self` to `u16`.
376 #[inline]
377 #[must_use]
378 pub fn as_u16vec3(&self) -> crate::U16Vec3 {
379 crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
380 }
381
382 /// Casts all elements of `self` to `i32`.
383 #[inline]
384 #[must_use]
385 pub fn as_ivec3(&self) -> crate::IVec3 {
386 crate::IVec3::new(self.x as i32, self.y as i32, self.z as i32)
387 }
388
389 /// Casts all elements of `self` to `i64`.
390 #[inline]
391 #[must_use]
392 pub fn as_i64vec3(&self) -> crate::I64Vec3 {
393 crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
394 }
395
396 /// Casts all elements of `self` to `u64`.
397 #[inline]
398 #[must_use]
399 pub fn as_u64vec3(&self) -> crate::U64Vec3 {
400 crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
401 }
402
403 /// Returns a vector containing the wrapping addition of `self` and `rhs`.
404 ///
405 /// In other words this computes `[self.x.wrapping_add(rhs.x), self.y.wrapping_add(rhs.y), ..]`.
406 #[inline]
407 #[must_use]
408 pub const fn wrapping_add(self, rhs: Self) -> Self {
409 Self {
410 x: self.x.wrapping_add(rhs.x),
411 y: self.y.wrapping_add(rhs.y),
412 z: self.z.wrapping_add(rhs.z),
413 }
414 }
415
416 /// Returns a vector containing the wrapping subtraction of `self` and `rhs`.
417 ///
418 /// In other words this computes `[self.x.wrapping_sub(rhs.x), self.y.wrapping_sub(rhs.y), ..]`.
419 #[inline]
420 #[must_use]
421 pub const fn wrapping_sub(self, rhs: Self) -> Self {
422 Self {
423 x: self.x.wrapping_sub(rhs.x),
424 y: self.y.wrapping_sub(rhs.y),
425 z: self.z.wrapping_sub(rhs.z),
426 }
427 }
428
429 /// Returns a vector containing the wrapping multiplication of `self` and `rhs`.
430 ///
431 /// In other words this computes `[self.x.wrapping_mul(rhs.x), self.y.wrapping_mul(rhs.y), ..]`.
432 #[inline]
433 #[must_use]
434 pub const fn wrapping_mul(self, rhs: Self) -> Self {
435 Self {
436 x: self.x.wrapping_mul(rhs.x),
437 y: self.y.wrapping_mul(rhs.y),
438 z: self.z.wrapping_mul(rhs.z),
439 }
440 }
441
442 /// Returns a vector containing the wrapping division of `self` and `rhs`.
443 ///
444 /// In other words this computes `[self.x.wrapping_div(rhs.x), self.y.wrapping_div(rhs.y), ..]`.
445 #[inline]
446 #[must_use]
447 pub const fn wrapping_div(self, rhs: Self) -> Self {
448 Self {
449 x: self.x.wrapping_div(rhs.x),
450 y: self.y.wrapping_div(rhs.y),
451 z: self.z.wrapping_div(rhs.z),
452 }
453 }
454
455 /// Returns a vector containing the saturating addition of `self` and `rhs`.
456 ///
457 /// In other words this computes `[self.x.saturating_add(rhs.x), self.y.saturating_add(rhs.y), ..]`.
458 #[inline]
459 #[must_use]
460 pub const fn saturating_add(self, rhs: Self) -> Self {
461 Self {
462 x: self.x.saturating_add(rhs.x),
463 y: self.y.saturating_add(rhs.y),
464 z: self.z.saturating_add(rhs.z),
465 }
466 }
467
468 /// Returns a vector containing the saturating subtraction of `self` and `rhs`.
469 ///
470 /// In other words this computes `[self.x.saturating_sub(rhs.x), self.y.saturating_sub(rhs.y), ..]`.
471 #[inline]
472 #[must_use]
473 pub const fn saturating_sub(self, rhs: Self) -> Self {
474 Self {
475 x: self.x.saturating_sub(rhs.x),
476 y: self.y.saturating_sub(rhs.y),
477 z: self.z.saturating_sub(rhs.z),
478 }
479 }
480
481 /// Returns a vector containing the saturating multiplication of `self` and `rhs`.
482 ///
483 /// In other words this computes `[self.x.saturating_mul(rhs.x), self.y.saturating_mul(rhs.y), ..]`.
484 #[inline]
485 #[must_use]
486 pub const fn saturating_mul(self, rhs: Self) -> Self {
487 Self {
488 x: self.x.saturating_mul(rhs.x),
489 y: self.y.saturating_mul(rhs.y),
490 z: self.z.saturating_mul(rhs.z),
491 }
492 }
493
494 /// Returns a vector containing the saturating division of `self` and `rhs`.
495 ///
496 /// In other words this computes `[self.x.saturating_div(rhs.x), self.y.saturating_div(rhs.y), ..]`.
497 #[inline]
498 #[must_use]
499 pub const fn saturating_div(self, rhs: Self) -> Self {
500 Self {
501 x: self.x.saturating_div(rhs.x),
502 y: self.y.saturating_div(rhs.y),
503 z: self.z.saturating_div(rhs.z),
504 }
505 }
506
507 /// Returns a vector containing the wrapping addition of `self` and signed vector `rhs`.
508 ///
509 /// In other words this computes `[self.x.wrapping_add_signed(rhs.x), self.y.wrapping_add_signed(rhs.y), ..]`.
510 #[inline]
511 #[must_use]
512 pub const fn wrapping_add_signed(self, rhs: IVec3) -> Self {
513 Self {
514 x: self.x.wrapping_add_signed(rhs.x),
515 y: self.y.wrapping_add_signed(rhs.y),
516 z: self.z.wrapping_add_signed(rhs.z),
517 }
518 }
519
520 /// Returns a vector containing the saturating addition of `self` and signed vector `rhs`.
521 ///
522 /// In other words this computes `[self.x.saturating_add_signed(rhs.x), self.y.saturating_add_signed(rhs.y), ..]`.
523 #[inline]
524 #[must_use]
525 pub const fn saturating_add_signed(self, rhs: IVec3) -> Self {
526 Self {
527 x: self.x.saturating_add_signed(rhs.x),
528 y: self.y.saturating_add_signed(rhs.y),
529 z: self.z.saturating_add_signed(rhs.z),
530 }
531 }
532 }
533
534 impl Default for UVec3 {
535 #[inline(always)]
536 fn default() -> Self {
537 Self::ZERO
538 }
539 }
540
541 impl Div<UVec3> for UVec3 {
542 type Output = Self;
543 #[inline]
544 fn div(self, rhs: Self) -> Self {
545 Self {
546 x: self.x.div(rhs.x),
547 y: self.y.div(rhs.y),
548 z: self.z.div(rhs.z),
549 }
550 }
551 }
552
553 impl DivAssign<UVec3> for UVec3 {
554 #[inline]
555 fn div_assign(&mut self, rhs: Self) {
556 self.x.div_assign(rhs.x);
557 self.y.div_assign(rhs.y);
558 self.z.div_assign(rhs.z);
559 }
560 }
561
562 impl Div<u32> for UVec3 {
563 type Output = Self;
564 #[inline]
565 fn div(self, rhs: u32) -> Self {
566 Self {
567 x: self.x.div(rhs),
568 y: self.y.div(rhs),
569 z: self.z.div(rhs),
570 }
571 }
572 }
573
574 impl DivAssign<u32> for UVec3 {
575 #[inline]
576 fn div_assign(&mut self, rhs: u32) {
577 self.x.div_assign(rhs);
578 self.y.div_assign(rhs);
579 self.z.div_assign(rhs);
580 }
581 }
582
583 impl Div<UVec3> for u32 {
584 type Output = UVec3;
585 #[inline]
586 fn div(self, rhs: UVec3) -> UVec3 {
587 UVec3 {
588 x: self.div(rhs.x),
589 y: self.div(rhs.y),
590 z: self.div(rhs.z),
591 }
592 }
593 }
594
595 impl Mul<UVec3> for UVec3 {
596 type Output = Self;
597 #[inline]
598 fn mul(self, rhs: Self) -> Self {
599 Self {
600 x: self.x.mul(rhs.x),
601 y: self.y.mul(rhs.y),
602 z: self.z.mul(rhs.z),
603 }
604 }
605 }
606
607 impl MulAssign<UVec3> for UVec3 {
608 #[inline]
609 fn mul_assign(&mut self, rhs: Self) {
610 self.x.mul_assign(rhs.x);
611 self.y.mul_assign(rhs.y);
612 self.z.mul_assign(rhs.z);
613 }
614 }
615
616 impl Mul<u32> for UVec3 {
617 type Output = Self;
618 #[inline]
619 fn mul(self, rhs: u32) -> Self {
620 Self {
621 x: self.x.mul(rhs),
622 y: self.y.mul(rhs),
623 z: self.z.mul(rhs),
624 }
625 }
626 }
627
628 impl MulAssign<u32> for UVec3 {
629 #[inline]
630 fn mul_assign(&mut self, rhs: u32) {
631 self.x.mul_assign(rhs);
632 self.y.mul_assign(rhs);
633 self.z.mul_assign(rhs);
634 }
635 }
636
637 impl Mul<UVec3> for u32 {
638 type Output = UVec3;
639 #[inline]
640 fn mul(self, rhs: UVec3) -> UVec3 {
641 UVec3 {
642 x: self.mul(rhs.x),
643 y: self.mul(rhs.y),
644 z: self.mul(rhs.z),
645 }
646 }
647 }
648
649 impl Add<UVec3> for UVec3 {
650 type Output = Self;
651 #[inline]
652 fn add(self, rhs: Self) -> Self {
653 Self {
654 x: self.x.add(rhs.x),
655 y: self.y.add(rhs.y),
656 z: self.z.add(rhs.z),
657 }
658 }
659 }
660
661 impl AddAssign<UVec3> for UVec3 {
662 #[inline]
663 fn add_assign(&mut self, rhs: Self) {
664 self.x.add_assign(rhs.x);
665 self.y.add_assign(rhs.y);
666 self.z.add_assign(rhs.z);
667 }
668 }
669
670 impl Add<u32> for UVec3 {
671 type Output = Self;
672 #[inline]
673 fn add(self, rhs: u32) -> Self {
674 Self {
675 x: self.x.add(rhs),
676 y: self.y.add(rhs),
677 z: self.z.add(rhs),
678 }
679 }
680 }
681
682 impl AddAssign<u32> for UVec3 {
683 #[inline]
684 fn add_assign(&mut self, rhs: u32) {
685 self.x.add_assign(rhs);
686 self.y.add_assign(rhs);
687 self.z.add_assign(rhs);
688 }
689 }
690
691 impl Add<UVec3> for u32 {
692 type Output = UVec3;
693 #[inline]
694 fn add(self, rhs: UVec3) -> UVec3 {
695 UVec3 {
696 x: self.add(rhs.x),
697 y: self.add(rhs.y),
698 z: self.add(rhs.z),
699 }
700 }
701 }
702
703 impl Sub<UVec3> for UVec3 {
704 type Output = Self;
705 #[inline]
706 fn sub(self, rhs: Self) -> Self {
707 Self {
708 x: self.x.sub(rhs.x),
709 y: self.y.sub(rhs.y),
710 z: self.z.sub(rhs.z),
711 }
712 }
713 }
714
715 impl SubAssign<UVec3> for UVec3 {
716 #[inline]
717 fn sub_assign(&mut self, rhs: UVec3) {
718 self.x.sub_assign(rhs.x);
719 self.y.sub_assign(rhs.y);
720 self.z.sub_assign(rhs.z);
721 }
722 }
723
724 impl Sub<u32> for UVec3 {
725 type Output = Self;
726 #[inline]
727 fn sub(self, rhs: u32) -> Self {
728 Self {
729 x: self.x.sub(rhs),
730 y: self.y.sub(rhs),
731 z: self.z.sub(rhs),
732 }
733 }
734 }
735
736 impl SubAssign<u32> for UVec3 {
737 #[inline]
738 fn sub_assign(&mut self, rhs: u32) {
739 self.x.sub_assign(rhs);
740 self.y.sub_assign(rhs);
741 self.z.sub_assign(rhs);
742 }
743 }
744
745 impl Sub<UVec3> for u32 {
746 type Output = UVec3;
747 #[inline]
748 fn sub(self, rhs: UVec3) -> UVec3 {
749 UVec3 {
750 x: self.sub(rhs.x),
751 y: self.sub(rhs.y),
752 z: self.sub(rhs.z),
753 }
754 }
755 }
756
757 impl Rem<UVec3> for UVec3 {
758 type Output = Self;
759 #[inline]
760 fn rem(self, rhs: Self) -> Self {
761 Self {
762 x: self.x.rem(rhs.x),
763 y: self.y.rem(rhs.y),
764 z: self.z.rem(rhs.z),
765 }
766 }
767 }
768
769 impl RemAssign<UVec3> for UVec3 {
770 #[inline]
771 fn rem_assign(&mut self, rhs: Self) {
772 self.x.rem_assign(rhs.x);
773 self.y.rem_assign(rhs.y);
774 self.z.rem_assign(rhs.z);
775 }
776 }
777
778 impl Rem<u32> for UVec3 {
779 type Output = Self;
780 #[inline]
781 fn rem(self, rhs: u32) -> Self {
782 Self {
783 x: self.x.rem(rhs),
784 y: self.y.rem(rhs),
785 z: self.z.rem(rhs),
786 }
787 }
788 }
789
790 impl RemAssign<u32> for UVec3 {
791 #[inline]
792 fn rem_assign(&mut self, rhs: u32) {
793 self.x.rem_assign(rhs);
794 self.y.rem_assign(rhs);
795 self.z.rem_assign(rhs);
796 }
797 }
798
799 impl Rem<UVec3> for u32 {
800 type Output = UVec3;
801 #[inline]
802 fn rem(self, rhs: UVec3) -> UVec3 {
803 UVec3 {
804 x: self.rem(rhs.x),
805 y: self.rem(rhs.y),
806 z: self.rem(rhs.z),
807 }
808 }
809 }
810
811 #[cfg(not(target_arch = "spirv"))]
812 impl AsRef<[u32; 3]> for UVec3 {
813 #[inline]
814 fn as_ref(&self) -> &[u32; 3] {
815 unsafe { &*(self as *const UVec3 as *const [u32; 3]) }
816 }
817 }
818
819 #[cfg(not(target_arch = "spirv"))]
820 impl AsMut<[u32; 3]> for UVec3 {
821 #[inline]
822 fn as_mut(&mut self) -> &mut [u32; 3] {
823 unsafe { &mut *(self as *mut UVec3 as *mut [u32; 3]) }
824 }
825 }
826
827 impl Sum for UVec3 {
828 #[inline]
829 fn sum<I>(iter: I) -> Self
830 where
831 I: Iterator<Item = Self>,
832 {
833 iter.fold(Self::ZERO, Self::add)
834 }
835 }
836
837 impl<'a> Sum<&'a Self> for UVec3 {
838 #[inline]
839 fn sum<I>(iter: I) -> Self
840 where
841 I: Iterator<Item = &'a Self>,
842 {
843 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
844 }
845 }
846
847 impl Product for UVec3 {
848 #[inline]
849 fn product<I>(iter: I) -> Self
850 where
851 I: Iterator<Item = Self>,
852 {
853 iter.fold(Self::ONE, Self::mul)
854 }
855 }
856
857 impl<'a> Product<&'a Self> for UVec3 {
858 #[inline]
859 fn product<I>(iter: I) -> Self
860 where
861 I: Iterator<Item = &'a Self>,
862 {
863 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
864 }
865 }
866
867 impl Not for UVec3 {
868 type Output = Self;
869 #[inline]
870 fn not(self) -> Self::Output {
871 Self {
872 x: self.x.not(),
873 y: self.y.not(),
874 z: self.z.not(),
875 }
876 }
877 }
878
879 impl BitAnd for UVec3 {
880 type Output = Self;
881 #[inline]
882 fn bitand(self, rhs: Self) -> Self::Output {
883 Self {
884 x: self.x.bitand(rhs.x),
885 y: self.y.bitand(rhs.y),
886 z: self.z.bitand(rhs.z),
887 }
888 }
889 }
890
891 impl BitOr for UVec3 {
892 type Output = Self;
893 #[inline]
894 fn bitor(self, rhs: Self) -> Self::Output {
895 Self {
896 x: self.x.bitor(rhs.x),
897 y: self.y.bitor(rhs.y),
898 z: self.z.bitor(rhs.z),
899 }
900 }
901 }
902
903 impl BitXor for UVec3 {
904 type Output = Self;
905 #[inline]
906 fn bitxor(self, rhs: Self) -> Self::Output {
907 Self {
908 x: self.x.bitxor(rhs.x),
909 y: self.y.bitxor(rhs.y),
910 z: self.z.bitxor(rhs.z),
911 }
912 }
913 }
914
915 impl BitAnd<u32> for UVec3 {
916 type Output = Self;
917 #[inline]
918 fn bitand(self, rhs: u32) -> Self::Output {
919 Self {
920 x: self.x.bitand(rhs),
921 y: self.y.bitand(rhs),
922 z: self.z.bitand(rhs),
923 }
924 }
925 }
926
927 impl BitOr<u32> for UVec3 {
928 type Output = Self;
929 #[inline]
930 fn bitor(self, rhs: u32) -> Self::Output {
931 Self {
932 x: self.x.bitor(rhs),
933 y: self.y.bitor(rhs),
934 z: self.z.bitor(rhs),
935 }
936 }
937 }
938
939 impl BitXor<u32> for UVec3 {
940 type Output = Self;
941 #[inline]
942 fn bitxor(self, rhs: u32) -> Self::Output {
943 Self {
944 x: self.x.bitxor(rhs),
945 y: self.y.bitxor(rhs),
946 z: self.z.bitxor(rhs),
947 }
948 }
949 }
950
951 impl Shl<i8> for UVec3 {
952 type Output = Self;
953 #[inline]
954 fn shl(self, rhs: i8) -> Self::Output {
955 Self {
956 x: self.x.shl(rhs),
957 y: self.y.shl(rhs),
958 z: self.z.shl(rhs),
959 }
960 }
961 }
962
963 impl Shr<i8> for UVec3 {
964 type Output = Self;
965 #[inline]
966 fn shr(self, rhs: i8) -> Self::Output {
967 Self {
968 x: self.x.shr(rhs),
969 y: self.y.shr(rhs),
970 z: self.z.shr(rhs),
971 }
972 }
973 }
974
975 impl Shl<i16> for UVec3 {
976 type Output = Self;
977 #[inline]
978 fn shl(self, rhs: i16) -> Self::Output {
979 Self {
980 x: self.x.shl(rhs),
981 y: self.y.shl(rhs),
982 z: self.z.shl(rhs),
983 }
984 }
985 }
986
987 impl Shr<i16> for UVec3 {
988 type Output = Self;
989 #[inline]
990 fn shr(self, rhs: i16) -> Self::Output {
991 Self {
992 x: self.x.shr(rhs),
993 y: self.y.shr(rhs),
994 z: self.z.shr(rhs),
995 }
996 }
997 }
998
999 impl Shl<i32> for UVec3 {
1000 type Output = Self;
1001 #[inline]
1002 fn shl(self, rhs: i32) -> Self::Output {
1003 Self {
1004 x: self.x.shl(rhs),
1005 y: self.y.shl(rhs),
1006 z: self.z.shl(rhs),
1007 }
1008 }
1009 }
1010
1011 impl Shr<i32> for UVec3 {
1012 type Output = Self;
1013 #[inline]
1014 fn shr(self, rhs: i32) -> Self::Output {
1015 Self {
1016 x: self.x.shr(rhs),
1017 y: self.y.shr(rhs),
1018 z: self.z.shr(rhs),
1019 }
1020 }
1021 }
1022
1023 impl Shl<i64> for UVec3 {
1024 type Output = Self;
1025 #[inline]
1026 fn shl(self, rhs: i64) -> Self::Output {
1027 Self {
1028 x: self.x.shl(rhs),
1029 y: self.y.shl(rhs),
1030 z: self.z.shl(rhs),
1031 }
1032 }
1033 }
1034
1035 impl Shr<i64> for UVec3 {
1036 type Output = Self;
1037 #[inline]
1038 fn shr(self, rhs: i64) -> Self::Output {
1039 Self {
1040 x: self.x.shr(rhs),
1041 y: self.y.shr(rhs),
1042 z: self.z.shr(rhs),
1043 }
1044 }
1045 }
1046
1047 impl Shl<u8> for UVec3 {
1048 type Output = Self;
1049 #[inline]
1050 fn shl(self, rhs: u8) -> Self::Output {
1051 Self {
1052 x: self.x.shl(rhs),
1053 y: self.y.shl(rhs),
1054 z: self.z.shl(rhs),
1055 }
1056 }
1057 }
1058
1059 impl Shr<u8> for UVec3 {
1060 type Output = Self;
1061 #[inline]
1062 fn shr(self, rhs: u8) -> Self::Output {
1063 Self {
1064 x: self.x.shr(rhs),
1065 y: self.y.shr(rhs),
1066 z: self.z.shr(rhs),
1067 }
1068 }
1069 }
1070
1071 impl Shl<u16> for UVec3 {
1072 type Output = Self;
1073 #[inline]
1074 fn shl(self, rhs: u16) -> Self::Output {
1075 Self {
1076 x: self.x.shl(rhs),
1077 y: self.y.shl(rhs),
1078 z: self.z.shl(rhs),
1079 }
1080 }
1081 }
1082
1083 impl Shr<u16> for UVec3 {
1084 type Output = Self;
1085 #[inline]
1086 fn shr(self, rhs: u16) -> Self::Output {
1087 Self {
1088 x: self.x.shr(rhs),
1089 y: self.y.shr(rhs),
1090 z: self.z.shr(rhs),
1091 }
1092 }
1093 }
1094
1095 impl Shl<u32> for UVec3 {
1096 type Output = Self;
1097 #[inline]
1098 fn shl(self, rhs: u32) -> Self::Output {
1099 Self {
1100 x: self.x.shl(rhs),
1101 y: self.y.shl(rhs),
1102 z: self.z.shl(rhs),
1103 }
1104 }
1105 }
1106
1107 impl Shr<u32> for UVec3 {
1108 type Output = Self;
1109 #[inline]
1110 fn shr(self, rhs: u32) -> Self::Output {
1111 Self {
1112 x: self.x.shr(rhs),
1113 y: self.y.shr(rhs),
1114 z: self.z.shr(rhs),
1115 }
1116 }
1117 }
1118
1119 impl Shl<u64> for UVec3 {
1120 type Output = Self;
1121 #[inline]
1122 fn shl(self, rhs: u64) -> Self::Output {
1123 Self {
1124 x: self.x.shl(rhs),
1125 y: self.y.shl(rhs),
1126 z: self.z.shl(rhs),
1127 }
1128 }
1129 }
1130
1131 impl Shr<u64> for UVec3 {
1132 type Output = Self;
1133 #[inline]
1134 fn shr(self, rhs: u64) -> Self::Output {
1135 Self {
1136 x: self.x.shr(rhs),
1137 y: self.y.shr(rhs),
1138 z: self.z.shr(rhs),
1139 }
1140 }
1141 }
1142
1143 impl Shl<crate::IVec3> for UVec3 {
1144 type Output = Self;
1145 #[inline]
1146 fn shl(self, rhs: crate::IVec3) -> Self::Output {
1147 Self {
1148 x: self.x.shl(rhs.x),
1149 y: self.y.shl(rhs.y),
1150 z: self.z.shl(rhs.z),
1151 }
1152 }
1153 }
1154
1155 impl Shr<crate::IVec3> for UVec3 {
1156 type Output = Self;
1157 #[inline]
1158 fn shr(self, rhs: crate::IVec3) -> Self::Output {
1159 Self {
1160 x: self.x.shr(rhs.x),
1161 y: self.y.shr(rhs.y),
1162 z: self.z.shr(rhs.z),
1163 }
1164 }
1165 }
1166
1167 impl Shl<crate::UVec3> for UVec3 {
1168 type Output = Self;
1169 #[inline]
1170 fn shl(self, rhs: crate::UVec3) -> Self::Output {
1171 Self {
1172 x: self.x.shl(rhs.x),
1173 y: self.y.shl(rhs.y),
1174 z: self.z.shl(rhs.z),
1175 }
1176 }
1177 }
1178
1179 impl Shr<crate::UVec3> for UVec3 {
1180 type Output = Self;
1181 #[inline]
1182 fn shr(self, rhs: crate::UVec3) -> Self::Output {
1183 Self {
1184 x: self.x.shr(rhs.x),
1185 y: self.y.shr(rhs.y),
1186 z: self.z.shr(rhs.z),
1187 }
1188 }
1189 }
1190
1191 impl Index<usize> for UVec3 {
1192 type Output = u32;
1193 #[inline]
1194 fn index(&self, index: usize) -> &Self::Output {
1195 match index {
1196 0 => &self.x,
1197 1 => &self.y,
1198 2 => &self.z,
1199 _ => panic!("index out of bounds"),
1200 }
1201 }
1202 }
1203
1204 impl IndexMut<usize> for UVec3 {
1205 #[inline]
1206 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1207 match index {
1208 0 => &mut self.x,
1209 1 => &mut self.y,
1210 2 => &mut self.z,
1211 _ => panic!("index out of bounds"),
1212 }
1213 }
1214 }
1215
1216 #[cfg(not(target_arch = "spirv"))]
1217 impl fmt::Display for UVec3 {
1218 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1219 write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
1220 }
1221 }
1222
1223 #[cfg(not(target_arch = "spirv"))]
1224 impl fmt::Debug for UVec3 {
1225 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1226 fmt.debug_tuple(stringify!(UVec3))
1227 .field(&self.x)
1228 .field(&self.y)
1229 .field(&self.z)
1230 .finish()
1231 }
1232 }
1233
1234 impl From<[u32; 3]> for UVec3 {
1235 #[inline]
1236 fn from(a: [u32; 3]) -> Self {
1237 Self::new(a[0], a[1], a[2])
1238 }
1239 }
1240
1241 impl From<UVec3> for [u32; 3] {
1242 #[inline]
1243 fn from(v: UVec3) -> Self {
1244 [v.x, v.y, v.z]
1245 }
1246 }
1247
1248 impl From<(u32, u32, u32)> for UVec3 {
1249 #[inline]
1250 fn from(t: (u32, u32, u32)) -> Self {
1251 Self::new(t.0, t.1, t.2)
1252 }
1253 }
1254
1255 impl From<UVec3> for (u32, u32, u32) {
1256 #[inline]
1257 fn from(v: UVec3) -> Self {
1258 (v.x, v.y, v.z)
1259 }
1260 }
1261
1262 impl From<(UVec2, u32)> for UVec3 {
1263 #[inline]
1264 fn from((v, z): (UVec2, u32)) -> Self {
1265 Self::new(v.x, v.y, z)
1266 }
1267 }
1268
1269 impl From<U16Vec3> for UVec3 {
1270 #[inline]
1271 fn from(v: U16Vec3) -> Self {
1272 Self::new(u32::from(v.x), u32::from(v.y), u32::from(v.z))
1273 }
1274 }
1275
1276 impl TryFrom<I16Vec3> for UVec3 {
1277 type Error = core::num::TryFromIntError;
1278
1279 #[inline]
1280 fn try_from(v: I16Vec3) -> Result<Self, Self::Error> {
1281 Ok(Self::new(
1282 u32::try_from(v.x)?,
1283 u32::try_from(v.y)?,
1284 u32::try_from(v.z)?,
1285 ))
1286 }
1287 }
1288
1289 impl TryFrom<IVec3> for UVec3 {
1290 type Error = core::num::TryFromIntError;
1291
1292 #[inline]
1293 fn try_from(v: IVec3) -> Result<Self, Self::Error> {
1294 Ok(Self::new(
1295 u32::try_from(v.x)?,
1296 u32::try_from(v.y)?,
1297 u32::try_from(v.z)?,
1298 ))
1299 }
1300 }
1301
1302 impl TryFrom<I64Vec3> for UVec3 {
1303 type Error = core::num::TryFromIntError;
1304
1305 #[inline]
1306 fn try_from(v: I64Vec3) -> Result<Self, Self::Error> {
1307 Ok(Self::new(
1308 u32::try_from(v.x)?,
1309 u32::try_from(v.y)?,
1310 u32::try_from(v.z)?,
1311 ))
1312 }
1313 }
1314
1315 impl TryFrom<U64Vec3> for UVec3 {
1316 type Error = core::num::TryFromIntError;
1317
1318 #[inline]
1319 fn try_from(v: U64Vec3) -> Result<Self, Self::Error> {
1320 Ok(Self::new(
1321 u32::try_from(v.x)?,
1322 u32::try_from(v.y)?,
1323 u32::try_from(v.z)?,
1324 ))
1325 }
1326 }
1327
1328 impl From<BVec3> for UVec3 {
1329 #[inline]
1330 fn from(v: BVec3) -> Self {
1331 Self::new(u32::from(v.x), u32::from(v.y), u32::from(v.z))
1332 }
1333 }
1334
1335 impl From<BVec3A> for UVec3 {
1336 #[inline]
1337 fn from(v: BVec3A) -> Self {
1338 let bool_array: [bool; 3] = v.into();
1339 Self::new(
1340 u32::from(bool_array[0]),
1341 u32::from(bool_array[1]),
1342 u32::from(bool_array[2]),
1343 )
1344 }
1345 }