1use crate::{BVec3, BVec3A, I16Vec3, I64Vec3, IVec2, IVec4, U16Vec3, U64Vec3, UVec3};
4
5#[cfg(not(target_arch = "spirv"))]
6use core::fmt;
7use core::iter::{Product, Sum};
8use core::{f32, ops::*};
9
10#[inline(always)]
12#[must_use]
13pub const fn ivec3(x: i32, y: i32, z: i32) -> IVec3 {
14 IVec3::new(x, y, z)
15}
16
17#[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 IVec3 {
23 pub x: i32,
24 pub y: i32,
25 pub z: i32,
26}
27
28impl IVec3 {
29 pub const ZERO: Self = Self::splat(0);
31
32 pub const ONE: Self = Self::splat(1);
34
35 pub const NEG_ONE: Self = Self::splat(-1);
37
38 pub const MIN: Self = Self::splat(i32::MIN);
40
41 pub const MAX: Self = Self::splat(i32::MAX);
43
44 pub const X: Self = Self::new(1, 0, 0);
46
47 pub const Y: Self = Self::new(0, 1, 0);
49
50 pub const Z: Self = Self::new(0, 0, 1);
52
53 pub const NEG_X: Self = Self::new(-1, 0, 0);
55
56 pub const NEG_Y: Self = Self::new(0, -1, 0);
58
59 pub const NEG_Z: Self = Self::new(0, 0, -1);
61
62 pub const AXES: [Self; 3] = [Self::X, Self::Y, Self::Z];
64
65 #[inline(always)]
67 #[must_use]
68 pub const fn new(x: i32, y: i32, z: i32) -> Self {
69 Self { x, y, z }
70 }
71
72 #[inline]
74 #[must_use]
75 pub const fn splat(v: i32) -> Self {
76 Self { x: v, y: v, z: v }
77 }
78
79 #[inline]
85 #[must_use]
86 pub fn select(mask: BVec3, if_true: Self, if_false: Self) -> Self {
87 Self {
88 x: if mask.test(0) { if_true.x } else { if_false.x },
89 y: if mask.test(1) { if_true.y } else { if_false.y },
90 z: if mask.test(2) { if_true.z } else { if_false.z },
91 }
92 }
93
94 #[inline]
96 #[must_use]
97 pub const fn from_array(a: [i32; 3]) -> Self {
98 Self::new(a[0], a[1], a[2])
99 }
100
101 #[inline]
103 #[must_use]
104 pub const fn to_array(&self) -> [i32; 3] {
105 [self.x, self.y, self.z]
106 }
107
108 #[inline]
114 #[must_use]
115 pub const fn from_slice(slice: &[i32]) -> Self {
116 Self::new(slice[0], slice[1], slice[2])
117 }
118
119 #[inline]
125 pub fn write_to_slice(self, slice: &mut [i32]) {
126 slice[0] = self.x;
127 slice[1] = self.y;
128 slice[2] = self.z;
129 }
130
131 #[allow(dead_code)]
133 #[inline]
134 #[must_use]
135 pub(crate) fn from_vec4(v: IVec4) -> Self {
136 Self {
137 x: v.x,
138 y: v.y,
139 z: v.z,
140 }
141 }
142
143 #[inline]
145 #[must_use]
146 pub fn extend(self, w: i32) -> IVec4 {
147 IVec4::new(self.x, self.y, self.z, w)
148 }
149
150 #[inline]
154 #[must_use]
155 pub fn truncate(self) -> IVec2 {
156 use crate::swizzles::Vec3Swizzles;
157 self.xy()
158 }
159
160 #[inline]
162 #[must_use]
163 pub fn with_x(mut self, x: i32) -> Self {
164 self.x = x;
165 self
166 }
167
168 #[inline]
170 #[must_use]
171 pub fn with_y(mut self, y: i32) -> Self {
172 self.y = y;
173 self
174 }
175
176 #[inline]
178 #[must_use]
179 pub fn with_z(mut self, z: i32) -> Self {
180 self.z = z;
181 self
182 }
183
184 #[inline]
186 #[must_use]
187 pub fn dot(self, rhs: Self) -> i32 {
188 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z)
189 }
190
191 #[inline]
193 #[must_use]
194 pub fn dot_into_vec(self, rhs: Self) -> Self {
195 Self::splat(self.dot(rhs))
196 }
197
198 #[inline]
200 #[must_use]
201 pub fn cross(self, rhs: Self) -> Self {
202 Self {
203 x: self.y * rhs.z - rhs.y * self.z,
204 y: self.z * rhs.x - rhs.z * self.x,
205 z: self.x * rhs.y - rhs.x * self.y,
206 }
207 }
208
209 #[inline]
213 #[must_use]
214 pub fn min(self, rhs: Self) -> Self {
215 Self {
216 x: self.x.min(rhs.x),
217 y: self.y.min(rhs.y),
218 z: self.z.min(rhs.z),
219 }
220 }
221
222 #[inline]
226 #[must_use]
227 pub fn max(self, rhs: Self) -> Self {
228 Self {
229 x: self.x.max(rhs.x),
230 y: self.y.max(rhs.y),
231 z: self.z.max(rhs.z),
232 }
233 }
234
235 #[inline]
243 #[must_use]
244 pub fn clamp(self, min: Self, max: Self) -> Self {
245 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
246 self.max(min).min(max)
247 }
248
249 #[inline]
253 #[must_use]
254 pub fn min_element(self) -> i32 {
255 self.x.min(self.y.min(self.z))
256 }
257
258 #[inline]
262 #[must_use]
263 pub fn max_element(self) -> i32 {
264 self.x.max(self.y.max(self.z))
265 }
266
267 #[inline]
271 #[must_use]
272 pub fn element_sum(self) -> i32 {
273 self.x + self.y + self.z
274 }
275
276 #[inline]
280 #[must_use]
281 pub fn element_product(self) -> i32 {
282 self.x * self.y * self.z
283 }
284
285 #[inline]
291 #[must_use]
292 pub fn cmpeq(self, rhs: Self) -> BVec3 {
293 BVec3::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y), self.z.eq(&rhs.z))
294 }
295
296 #[inline]
302 #[must_use]
303 pub fn cmpne(self, rhs: Self) -> BVec3 {
304 BVec3::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y), self.z.ne(&rhs.z))
305 }
306
307 #[inline]
313 #[must_use]
314 pub fn cmpge(self, rhs: Self) -> BVec3 {
315 BVec3::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y), self.z.ge(&rhs.z))
316 }
317
318 #[inline]
324 #[must_use]
325 pub fn cmpgt(self, rhs: Self) -> BVec3 {
326 BVec3::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y), self.z.gt(&rhs.z))
327 }
328
329 #[inline]
335 #[must_use]
336 pub fn cmple(self, rhs: Self) -> BVec3 {
337 BVec3::new(self.x.le(&rhs.x), self.y.le(&rhs.y), self.z.le(&rhs.z))
338 }
339
340 #[inline]
346 #[must_use]
347 pub fn cmplt(self, rhs: Self) -> BVec3 {
348 BVec3::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y), self.z.lt(&rhs.z))
349 }
350
351 #[inline]
353 #[must_use]
354 pub fn abs(self) -> Self {
355 Self {
356 x: self.x.abs(),
357 y: self.y.abs(),
358 z: self.z.abs(),
359 }
360 }
361
362 #[inline]
368 #[must_use]
369 pub fn signum(self) -> Self {
370 Self {
371 x: self.x.signum(),
372 y: self.y.signum(),
373 z: self.z.signum(),
374 }
375 }
376
377 #[inline]
382 #[must_use]
383 pub fn is_negative_bitmask(self) -> u32 {
384 (self.x.is_negative() as u32)
385 | (self.y.is_negative() as u32) << 1
386 | (self.z.is_negative() as u32) << 2
387 }
388
389 #[doc(alias = "magnitude2")]
391 #[inline]
392 #[must_use]
393 pub fn length_squared(self) -> i32 {
394 self.dot(self)
395 }
396
397 #[inline]
399 #[must_use]
400 pub fn distance_squared(self, rhs: Self) -> i32 {
401 (self - rhs).length_squared()
402 }
403
404 #[inline]
409 #[must_use]
410 pub fn div_euclid(self, rhs: Self) -> Self {
411 Self::new(
412 self.x.div_euclid(rhs.x),
413 self.y.div_euclid(rhs.y),
414 self.z.div_euclid(rhs.z),
415 )
416 }
417
418 #[inline]
425 #[must_use]
426 pub fn rem_euclid(self, rhs: Self) -> Self {
427 Self::new(
428 self.x.rem_euclid(rhs.x),
429 self.y.rem_euclid(rhs.y),
430 self.z.rem_euclid(rhs.z),
431 )
432 }
433
434 #[inline]
436 #[must_use]
437 pub fn as_vec3(&self) -> crate::Vec3 {
438 crate::Vec3::new(self.x as f32, self.y as f32, self.z as f32)
439 }
440
441 #[inline]
443 #[must_use]
444 pub fn as_vec3a(&self) -> crate::Vec3A {
445 crate::Vec3A::new(self.x as f32, self.y as f32, self.z as f32)
446 }
447
448 #[inline]
450 #[must_use]
451 pub fn as_dvec3(&self) -> crate::DVec3 {
452 crate::DVec3::new(self.x as f64, self.y as f64, self.z as f64)
453 }
454
455 #[inline]
457 #[must_use]
458 pub fn as_i16vec3(&self) -> crate::I16Vec3 {
459 crate::I16Vec3::new(self.x as i16, self.y as i16, self.z as i16)
460 }
461
462 #[inline]
464 #[must_use]
465 pub fn as_u16vec3(&self) -> crate::U16Vec3 {
466 crate::U16Vec3::new(self.x as u16, self.y as u16, self.z as u16)
467 }
468
469 #[inline]
471 #[must_use]
472 pub fn as_uvec3(&self) -> crate::UVec3 {
473 crate::UVec3::new(self.x as u32, self.y as u32, self.z as u32)
474 }
475
476 #[inline]
478 #[must_use]
479 pub fn as_i64vec3(&self) -> crate::I64Vec3 {
480 crate::I64Vec3::new(self.x as i64, self.y as i64, self.z as i64)
481 }
482
483 #[inline]
485 #[must_use]
486 pub fn as_u64vec3(&self) -> crate::U64Vec3 {
487 crate::U64Vec3::new(self.x as u64, self.y as u64, self.z as u64)
488 }
489
490 #[inline]
494 #[must_use]
495 pub const fn wrapping_add(self, rhs: Self) -> Self {
496 Self {
497 x: self.x.wrapping_add(rhs.x),
498 y: self.y.wrapping_add(rhs.y),
499 z: self.z.wrapping_add(rhs.z),
500 }
501 }
502
503 #[inline]
507 #[must_use]
508 pub const fn wrapping_sub(self, rhs: Self) -> Self {
509 Self {
510 x: self.x.wrapping_sub(rhs.x),
511 y: self.y.wrapping_sub(rhs.y),
512 z: self.z.wrapping_sub(rhs.z),
513 }
514 }
515
516 #[inline]
520 #[must_use]
521 pub const fn wrapping_mul(self, rhs: Self) -> Self {
522 Self {
523 x: self.x.wrapping_mul(rhs.x),
524 y: self.y.wrapping_mul(rhs.y),
525 z: self.z.wrapping_mul(rhs.z),
526 }
527 }
528
529 #[inline]
533 #[must_use]
534 pub const fn wrapping_div(self, rhs: Self) -> Self {
535 Self {
536 x: self.x.wrapping_div(rhs.x),
537 y: self.y.wrapping_div(rhs.y),
538 z: self.z.wrapping_div(rhs.z),
539 }
540 }
541
542 #[inline]
546 #[must_use]
547 pub const fn saturating_add(self, rhs: Self) -> Self {
548 Self {
549 x: self.x.saturating_add(rhs.x),
550 y: self.y.saturating_add(rhs.y),
551 z: self.z.saturating_add(rhs.z),
552 }
553 }
554
555 #[inline]
559 #[must_use]
560 pub const fn saturating_sub(self, rhs: Self) -> Self {
561 Self {
562 x: self.x.saturating_sub(rhs.x),
563 y: self.y.saturating_sub(rhs.y),
564 z: self.z.saturating_sub(rhs.z),
565 }
566 }
567
568 #[inline]
572 #[must_use]
573 pub const fn saturating_mul(self, rhs: Self) -> Self {
574 Self {
575 x: self.x.saturating_mul(rhs.x),
576 y: self.y.saturating_mul(rhs.y),
577 z: self.z.saturating_mul(rhs.z),
578 }
579 }
580
581 #[inline]
585 #[must_use]
586 pub const fn saturating_div(self, rhs: Self) -> Self {
587 Self {
588 x: self.x.saturating_div(rhs.x),
589 y: self.y.saturating_div(rhs.y),
590 z: self.z.saturating_div(rhs.z),
591 }
592 }
593
594 #[inline]
598 #[must_use]
599 pub const fn wrapping_add_unsigned(self, rhs: UVec3) -> Self {
600 Self {
601 x: self.x.wrapping_add_unsigned(rhs.x),
602 y: self.y.wrapping_add_unsigned(rhs.y),
603 z: self.z.wrapping_add_unsigned(rhs.z),
604 }
605 }
606
607 #[inline]
611 #[must_use]
612 pub const fn wrapping_sub_unsigned(self, rhs: UVec3) -> Self {
613 Self {
614 x: self.x.wrapping_sub_unsigned(rhs.x),
615 y: self.y.wrapping_sub_unsigned(rhs.y),
616 z: self.z.wrapping_sub_unsigned(rhs.z),
617 }
618 }
619
620 #[inline]
624 #[must_use]
625 pub const fn saturating_add_unsigned(self, rhs: UVec3) -> Self {
626 Self {
627 x: self.x.saturating_add_unsigned(rhs.x),
628 y: self.y.saturating_add_unsigned(rhs.y),
629 z: self.z.saturating_add_unsigned(rhs.z),
630 }
631 }
632
633 #[inline]
637 #[must_use]
638 pub const fn saturating_sub_unsigned(self, rhs: UVec3) -> Self {
639 Self {
640 x: self.x.saturating_sub_unsigned(rhs.x),
641 y: self.y.saturating_sub_unsigned(rhs.y),
642 z: self.z.saturating_sub_unsigned(rhs.z),
643 }
644 }
645}
646
647impl Default for IVec3 {
648 #[inline(always)]
649 fn default() -> Self {
650 Self::ZERO
651 }
652}
653
654impl Div<IVec3> for IVec3 {
655 type Output = Self;
656 #[inline]
657 fn div(self, rhs: Self) -> Self {
658 Self {
659 x: self.x.div(rhs.x),
660 y: self.y.div(rhs.y),
661 z: self.z.div(rhs.z),
662 }
663 }
664}
665
666impl DivAssign<IVec3> for IVec3 {
667 #[inline]
668 fn div_assign(&mut self, rhs: Self) {
669 self.x.div_assign(rhs.x);
670 self.y.div_assign(rhs.y);
671 self.z.div_assign(rhs.z);
672 }
673}
674
675impl Div<i32> for IVec3 {
676 type Output = Self;
677 #[inline]
678 fn div(self, rhs: i32) -> Self {
679 Self {
680 x: self.x.div(rhs),
681 y: self.y.div(rhs),
682 z: self.z.div(rhs),
683 }
684 }
685}
686
687impl DivAssign<i32> for IVec3 {
688 #[inline]
689 fn div_assign(&mut self, rhs: i32) {
690 self.x.div_assign(rhs);
691 self.y.div_assign(rhs);
692 self.z.div_assign(rhs);
693 }
694}
695
696impl Div<IVec3> for i32 {
697 type Output = IVec3;
698 #[inline]
699 fn div(self, rhs: IVec3) -> IVec3 {
700 IVec3 {
701 x: self.div(rhs.x),
702 y: self.div(rhs.y),
703 z: self.div(rhs.z),
704 }
705 }
706}
707
708impl Mul<IVec3> for IVec3 {
709 type Output = Self;
710 #[inline]
711 fn mul(self, rhs: Self) -> Self {
712 Self {
713 x: self.x.mul(rhs.x),
714 y: self.y.mul(rhs.y),
715 z: self.z.mul(rhs.z),
716 }
717 }
718}
719
720impl MulAssign<IVec3> for IVec3 {
721 #[inline]
722 fn mul_assign(&mut self, rhs: Self) {
723 self.x.mul_assign(rhs.x);
724 self.y.mul_assign(rhs.y);
725 self.z.mul_assign(rhs.z);
726 }
727}
728
729impl Mul<i32> for IVec3 {
730 type Output = Self;
731 #[inline]
732 fn mul(self, rhs: i32) -> Self {
733 Self {
734 x: self.x.mul(rhs),
735 y: self.y.mul(rhs),
736 z: self.z.mul(rhs),
737 }
738 }
739}
740
741impl MulAssign<i32> for IVec3 {
742 #[inline]
743 fn mul_assign(&mut self, rhs: i32) {
744 self.x.mul_assign(rhs);
745 self.y.mul_assign(rhs);
746 self.z.mul_assign(rhs);
747 }
748}
749
750impl Mul<IVec3> for i32 {
751 type Output = IVec3;
752 #[inline]
753 fn mul(self, rhs: IVec3) -> IVec3 {
754 IVec3 {
755 x: self.mul(rhs.x),
756 y: self.mul(rhs.y),
757 z: self.mul(rhs.z),
758 }
759 }
760}
761
762impl Add<IVec3> for IVec3 {
763 type Output = Self;
764 #[inline]
765 fn add(self, rhs: Self) -> Self {
766 Self {
767 x: self.x.add(rhs.x),
768 y: self.y.add(rhs.y),
769 z: self.z.add(rhs.z),
770 }
771 }
772}
773
774impl AddAssign<IVec3> for IVec3 {
775 #[inline]
776 fn add_assign(&mut self, rhs: Self) {
777 self.x.add_assign(rhs.x);
778 self.y.add_assign(rhs.y);
779 self.z.add_assign(rhs.z);
780 }
781}
782
783impl Add<i32> for IVec3 {
784 type Output = Self;
785 #[inline]
786 fn add(self, rhs: i32) -> Self {
787 Self {
788 x: self.x.add(rhs),
789 y: self.y.add(rhs),
790 z: self.z.add(rhs),
791 }
792 }
793}
794
795impl AddAssign<i32> for IVec3 {
796 #[inline]
797 fn add_assign(&mut self, rhs: i32) {
798 self.x.add_assign(rhs);
799 self.y.add_assign(rhs);
800 self.z.add_assign(rhs);
801 }
802}
803
804impl Add<IVec3> for i32 {
805 type Output = IVec3;
806 #[inline]
807 fn add(self, rhs: IVec3) -> IVec3 {
808 IVec3 {
809 x: self.add(rhs.x),
810 y: self.add(rhs.y),
811 z: self.add(rhs.z),
812 }
813 }
814}
815
816impl Sub<IVec3> for IVec3 {
817 type Output = Self;
818 #[inline]
819 fn sub(self, rhs: Self) -> Self {
820 Self {
821 x: self.x.sub(rhs.x),
822 y: self.y.sub(rhs.y),
823 z: self.z.sub(rhs.z),
824 }
825 }
826}
827
828impl SubAssign<IVec3> for IVec3 {
829 #[inline]
830 fn sub_assign(&mut self, rhs: IVec3) {
831 self.x.sub_assign(rhs.x);
832 self.y.sub_assign(rhs.y);
833 self.z.sub_assign(rhs.z);
834 }
835}
836
837impl Sub<i32> for IVec3 {
838 type Output = Self;
839 #[inline]
840 fn sub(self, rhs: i32) -> Self {
841 Self {
842 x: self.x.sub(rhs),
843 y: self.y.sub(rhs),
844 z: self.z.sub(rhs),
845 }
846 }
847}
848
849impl SubAssign<i32> for IVec3 {
850 #[inline]
851 fn sub_assign(&mut self, rhs: i32) {
852 self.x.sub_assign(rhs);
853 self.y.sub_assign(rhs);
854 self.z.sub_assign(rhs);
855 }
856}
857
858impl Sub<IVec3> for i32 {
859 type Output = IVec3;
860 #[inline]
861 fn sub(self, rhs: IVec3) -> IVec3 {
862 IVec3 {
863 x: self.sub(rhs.x),
864 y: self.sub(rhs.y),
865 z: self.sub(rhs.z),
866 }
867 }
868}
869
870impl Rem<IVec3> for IVec3 {
871 type Output = Self;
872 #[inline]
873 fn rem(self, rhs: Self) -> Self {
874 Self {
875 x: self.x.rem(rhs.x),
876 y: self.y.rem(rhs.y),
877 z: self.z.rem(rhs.z),
878 }
879 }
880}
881
882impl RemAssign<IVec3> for IVec3 {
883 #[inline]
884 fn rem_assign(&mut self, rhs: Self) {
885 self.x.rem_assign(rhs.x);
886 self.y.rem_assign(rhs.y);
887 self.z.rem_assign(rhs.z);
888 }
889}
890
891impl Rem<i32> for IVec3 {
892 type Output = Self;
893 #[inline]
894 fn rem(self, rhs: i32) -> Self {
895 Self {
896 x: self.x.rem(rhs),
897 y: self.y.rem(rhs),
898 z: self.z.rem(rhs),
899 }
900 }
901}
902
903impl RemAssign<i32> for IVec3 {
904 #[inline]
905 fn rem_assign(&mut self, rhs: i32) {
906 self.x.rem_assign(rhs);
907 self.y.rem_assign(rhs);
908 self.z.rem_assign(rhs);
909 }
910}
911
912impl Rem<IVec3> for i32 {
913 type Output = IVec3;
914 #[inline]
915 fn rem(self, rhs: IVec3) -> IVec3 {
916 IVec3 {
917 x: self.rem(rhs.x),
918 y: self.rem(rhs.y),
919 z: self.rem(rhs.z),
920 }
921 }
922}
923
924#[cfg(not(target_arch = "spirv"))]
925impl AsRef<[i32; 3]> for IVec3 {
926 #[inline]
927 fn as_ref(&self) -> &[i32; 3] {
928 unsafe { &*(self as *const IVec3 as *const [i32; 3]) }
929 }
930}
931
932#[cfg(not(target_arch = "spirv"))]
933impl AsMut<[i32; 3]> for IVec3 {
934 #[inline]
935 fn as_mut(&mut self) -> &mut [i32; 3] {
936 unsafe { &mut *(self as *mut IVec3 as *mut [i32; 3]) }
937 }
938}
939
940impl Sum for IVec3 {
941 #[inline]
942 fn sum<I>(iter: I) -> Self
943 where
944 I: Iterator<Item = Self>,
945 {
946 iter.fold(Self::ZERO, Self::add)
947 }
948}
949
950impl<'a> Sum<&'a Self> for IVec3 {
951 #[inline]
952 fn sum<I>(iter: I) -> Self
953 where
954 I: Iterator<Item = &'a Self>,
955 {
956 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
957 }
958}
959
960impl Product for IVec3 {
961 #[inline]
962 fn product<I>(iter: I) -> Self
963 where
964 I: Iterator<Item = Self>,
965 {
966 iter.fold(Self::ONE, Self::mul)
967 }
968}
969
970impl<'a> Product<&'a Self> for IVec3 {
971 #[inline]
972 fn product<I>(iter: I) -> Self
973 where
974 I: Iterator<Item = &'a Self>,
975 {
976 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
977 }
978}
979
980impl Neg for IVec3 {
981 type Output = Self;
982 #[inline]
983 fn neg(self) -> Self {
984 Self {
985 x: self.x.neg(),
986 y: self.y.neg(),
987 z: self.z.neg(),
988 }
989 }
990}
991
992impl Not for IVec3 {
993 type Output = Self;
994 #[inline]
995 fn not(self) -> Self::Output {
996 Self {
997 x: self.x.not(),
998 y: self.y.not(),
999 z: self.z.not(),
1000 }
1001 }
1002}
1003
1004impl BitAnd for IVec3 {
1005 type Output = Self;
1006 #[inline]
1007 fn bitand(self, rhs: Self) -> Self::Output {
1008 Self {
1009 x: self.x.bitand(rhs.x),
1010 y: self.y.bitand(rhs.y),
1011 z: self.z.bitand(rhs.z),
1012 }
1013 }
1014}
1015
1016impl BitOr for IVec3 {
1017 type Output = Self;
1018 #[inline]
1019 fn bitor(self, rhs: Self) -> Self::Output {
1020 Self {
1021 x: self.x.bitor(rhs.x),
1022 y: self.y.bitor(rhs.y),
1023 z: self.z.bitor(rhs.z),
1024 }
1025 }
1026}
1027
1028impl BitXor for IVec3 {
1029 type Output = Self;
1030 #[inline]
1031 fn bitxor(self, rhs: Self) -> Self::Output {
1032 Self {
1033 x: self.x.bitxor(rhs.x),
1034 y: self.y.bitxor(rhs.y),
1035 z: self.z.bitxor(rhs.z),
1036 }
1037 }
1038}
1039
1040impl BitAnd<i32> for IVec3 {
1041 type Output = Self;
1042 #[inline]
1043 fn bitand(self, rhs: i32) -> Self::Output {
1044 Self {
1045 x: self.x.bitand(rhs),
1046 y: self.y.bitand(rhs),
1047 z: self.z.bitand(rhs),
1048 }
1049 }
1050}
1051
1052impl BitOr<i32> for IVec3 {
1053 type Output = Self;
1054 #[inline]
1055 fn bitor(self, rhs: i32) -> Self::Output {
1056 Self {
1057 x: self.x.bitor(rhs),
1058 y: self.y.bitor(rhs),
1059 z: self.z.bitor(rhs),
1060 }
1061 }
1062}
1063
1064impl BitXor<i32> for IVec3 {
1065 type Output = Self;
1066 #[inline]
1067 fn bitxor(self, rhs: i32) -> Self::Output {
1068 Self {
1069 x: self.x.bitxor(rhs),
1070 y: self.y.bitxor(rhs),
1071 z: self.z.bitxor(rhs),
1072 }
1073 }
1074}
1075
1076impl Shl<i8> for IVec3 {
1077 type Output = Self;
1078 #[inline]
1079 fn shl(self, rhs: i8) -> Self::Output {
1080 Self {
1081 x: self.x.shl(rhs),
1082 y: self.y.shl(rhs),
1083 z: self.z.shl(rhs),
1084 }
1085 }
1086}
1087
1088impl Shr<i8> for IVec3 {
1089 type Output = Self;
1090 #[inline]
1091 fn shr(self, rhs: i8) -> Self::Output {
1092 Self {
1093 x: self.x.shr(rhs),
1094 y: self.y.shr(rhs),
1095 z: self.z.shr(rhs),
1096 }
1097 }
1098}
1099
1100impl Shl<i16> for IVec3 {
1101 type Output = Self;
1102 #[inline]
1103 fn shl(self, rhs: i16) -> Self::Output {
1104 Self {
1105 x: self.x.shl(rhs),
1106 y: self.y.shl(rhs),
1107 z: self.z.shl(rhs),
1108 }
1109 }
1110}
1111
1112impl Shr<i16> for IVec3 {
1113 type Output = Self;
1114 #[inline]
1115 fn shr(self, rhs: i16) -> Self::Output {
1116 Self {
1117 x: self.x.shr(rhs),
1118 y: self.y.shr(rhs),
1119 z: self.z.shr(rhs),
1120 }
1121 }
1122}
1123
1124impl Shl<i32> for IVec3 {
1125 type Output = Self;
1126 #[inline]
1127 fn shl(self, rhs: i32) -> Self::Output {
1128 Self {
1129 x: self.x.shl(rhs),
1130 y: self.y.shl(rhs),
1131 z: self.z.shl(rhs),
1132 }
1133 }
1134}
1135
1136impl Shr<i32> for IVec3 {
1137 type Output = Self;
1138 #[inline]
1139 fn shr(self, rhs: i32) -> Self::Output {
1140 Self {
1141 x: self.x.shr(rhs),
1142 y: self.y.shr(rhs),
1143 z: self.z.shr(rhs),
1144 }
1145 }
1146}
1147
1148impl Shl<i64> for IVec3 {
1149 type Output = Self;
1150 #[inline]
1151 fn shl(self, rhs: i64) -> Self::Output {
1152 Self {
1153 x: self.x.shl(rhs),
1154 y: self.y.shl(rhs),
1155 z: self.z.shl(rhs),
1156 }
1157 }
1158}
1159
1160impl Shr<i64> for IVec3 {
1161 type Output = Self;
1162 #[inline]
1163 fn shr(self, rhs: i64) -> Self::Output {
1164 Self {
1165 x: self.x.shr(rhs),
1166 y: self.y.shr(rhs),
1167 z: self.z.shr(rhs),
1168 }
1169 }
1170}
1171
1172impl Shl<u8> for IVec3 {
1173 type Output = Self;
1174 #[inline]
1175 fn shl(self, rhs: u8) -> Self::Output {
1176 Self {
1177 x: self.x.shl(rhs),
1178 y: self.y.shl(rhs),
1179 z: self.z.shl(rhs),
1180 }
1181 }
1182}
1183
1184impl Shr<u8> for IVec3 {
1185 type Output = Self;
1186 #[inline]
1187 fn shr(self, rhs: u8) -> Self::Output {
1188 Self {
1189 x: self.x.shr(rhs),
1190 y: self.y.shr(rhs),
1191 z: self.z.shr(rhs),
1192 }
1193 }
1194}
1195
1196impl Shl<u16> for IVec3 {
1197 type Output = Self;
1198 #[inline]
1199 fn shl(self, rhs: u16) -> Self::Output {
1200 Self {
1201 x: self.x.shl(rhs),
1202 y: self.y.shl(rhs),
1203 z: self.z.shl(rhs),
1204 }
1205 }
1206}
1207
1208impl Shr<u16> for IVec3 {
1209 type Output = Self;
1210 #[inline]
1211 fn shr(self, rhs: u16) -> Self::Output {
1212 Self {
1213 x: self.x.shr(rhs),
1214 y: self.y.shr(rhs),
1215 z: self.z.shr(rhs),
1216 }
1217 }
1218}
1219
1220impl Shl<u32> for IVec3 {
1221 type Output = Self;
1222 #[inline]
1223 fn shl(self, rhs: u32) -> Self::Output {
1224 Self {
1225 x: self.x.shl(rhs),
1226 y: self.y.shl(rhs),
1227 z: self.z.shl(rhs),
1228 }
1229 }
1230}
1231
1232impl Shr<u32> for IVec3 {
1233 type Output = Self;
1234 #[inline]
1235 fn shr(self, rhs: u32) -> Self::Output {
1236 Self {
1237 x: self.x.shr(rhs),
1238 y: self.y.shr(rhs),
1239 z: self.z.shr(rhs),
1240 }
1241 }
1242}
1243
1244impl Shl<u64> for IVec3 {
1245 type Output = Self;
1246 #[inline]
1247 fn shl(self, rhs: u64) -> Self::Output {
1248 Self {
1249 x: self.x.shl(rhs),
1250 y: self.y.shl(rhs),
1251 z: self.z.shl(rhs),
1252 }
1253 }
1254}
1255
1256impl Shr<u64> for IVec3 {
1257 type Output = Self;
1258 #[inline]
1259 fn shr(self, rhs: u64) -> Self::Output {
1260 Self {
1261 x: self.x.shr(rhs),
1262 y: self.y.shr(rhs),
1263 z: self.z.shr(rhs),
1264 }
1265 }
1266}
1267
1268impl Shl<crate::IVec3> for IVec3 {
1269 type Output = Self;
1270 #[inline]
1271 fn shl(self, rhs: crate::IVec3) -> Self::Output {
1272 Self {
1273 x: self.x.shl(rhs.x),
1274 y: self.y.shl(rhs.y),
1275 z: self.z.shl(rhs.z),
1276 }
1277 }
1278}
1279
1280impl Shr<crate::IVec3> for IVec3 {
1281 type Output = Self;
1282 #[inline]
1283 fn shr(self, rhs: crate::IVec3) -> Self::Output {
1284 Self {
1285 x: self.x.shr(rhs.x),
1286 y: self.y.shr(rhs.y),
1287 z: self.z.shr(rhs.z),
1288 }
1289 }
1290}
1291
1292impl Shl<crate::UVec3> for IVec3 {
1293 type Output = Self;
1294 #[inline]
1295 fn shl(self, rhs: crate::UVec3) -> Self::Output {
1296 Self {
1297 x: self.x.shl(rhs.x),
1298 y: self.y.shl(rhs.y),
1299 z: self.z.shl(rhs.z),
1300 }
1301 }
1302}
1303
1304impl Shr<crate::UVec3> for IVec3 {
1305 type Output = Self;
1306 #[inline]
1307 fn shr(self, rhs: crate::UVec3) -> Self::Output {
1308 Self {
1309 x: self.x.shr(rhs.x),
1310 y: self.y.shr(rhs.y),
1311 z: self.z.shr(rhs.z),
1312 }
1313 }
1314}
1315
1316impl Index<usize> for IVec3 {
1317 type Output = i32;
1318 #[inline]
1319 fn index(&self, index: usize) -> &Self::Output {
1320 match index {
1321 0 => &self.x,
1322 1 => &self.y,
1323 2 => &self.z,
1324 _ => panic!("index out of bounds"),
1325 }
1326 }
1327}
1328
1329impl IndexMut<usize> for IVec3 {
1330 #[inline]
1331 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1332 match index {
1333 0 => &mut self.x,
1334 1 => &mut self.y,
1335 2 => &mut self.z,
1336 _ => panic!("index out of bounds"),
1337 }
1338 }
1339}
1340
1341#[cfg(not(target_arch = "spirv"))]
1342impl fmt::Display for IVec3 {
1343 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1344 write!(f, "[{}, {}, {}]", self.x, self.y, self.z)
1345 }
1346}
1347
1348#[cfg(not(target_arch = "spirv"))]
1349impl fmt::Debug for IVec3 {
1350 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1351 fmt.debug_tuple(stringify!(IVec3))
1352 .field(&self.x)
1353 .field(&self.y)
1354 .field(&self.z)
1355 .finish()
1356 }
1357}
1358
1359impl From<[i32; 3]> for IVec3 {
1360 #[inline]
1361 fn from(a: [i32; 3]) -> Self {
1362 Self::new(a[0], a[1], a[2])
1363 }
1364}
1365
1366impl From<IVec3> for [i32; 3] {
1367 #[inline]
1368 fn from(v: IVec3) -> Self {
1369 [v.x, v.y, v.z]
1370 }
1371}
1372
1373impl From<(i32, i32, i32)> for IVec3 {
1374 #[inline]
1375 fn from(t: (i32, i32, i32)) -> Self {
1376 Self::new(t.0, t.1, t.2)
1377 }
1378}
1379
1380impl From<IVec3> for (i32, i32, i32) {
1381 #[inline]
1382 fn from(v: IVec3) -> Self {
1383 (v.x, v.y, v.z)
1384 }
1385}
1386
1387impl From<(IVec2, i32)> for IVec3 {
1388 #[inline]
1389 fn from((v, z): (IVec2, i32)) -> Self {
1390 Self::new(v.x, v.y, z)
1391 }
1392}
1393
1394impl From<I16Vec3> for IVec3 {
1395 #[inline]
1396 fn from(v: I16Vec3) -> Self {
1397 Self::new(i32::from(v.x), i32::from(v.y), i32::from(v.z))
1398 }
1399}
1400
1401impl From<U16Vec3> for IVec3 {
1402 #[inline]
1403 fn from(v: U16Vec3) -> Self {
1404 Self::new(i32::from(v.x), i32::from(v.y), i32::from(v.z))
1405 }
1406}
1407
1408impl TryFrom<UVec3> for IVec3 {
1409 type Error = core::num::TryFromIntError;
1410
1411 #[inline]
1412 fn try_from(v: UVec3) -> Result<Self, Self::Error> {
1413 Ok(Self::new(
1414 i32::try_from(v.x)?,
1415 i32::try_from(v.y)?,
1416 i32::try_from(v.z)?,
1417 ))
1418 }
1419}
1420
1421impl TryFrom<I64Vec3> for IVec3 {
1422 type Error = core::num::TryFromIntError;
1423
1424 #[inline]
1425 fn try_from(v: I64Vec3) -> Result<Self, Self::Error> {
1426 Ok(Self::new(
1427 i32::try_from(v.x)?,
1428 i32::try_from(v.y)?,
1429 i32::try_from(v.z)?,
1430 ))
1431 }
1432}
1433
1434impl TryFrom<U64Vec3> for IVec3 {
1435 type Error = core::num::TryFromIntError;
1436
1437 #[inline]
1438 fn try_from(v: U64Vec3) -> Result<Self, Self::Error> {
1439 Ok(Self::new(
1440 i32::try_from(v.x)?,
1441 i32::try_from(v.y)?,
1442 i32::try_from(v.z)?,
1443 ))
1444 }
1445}
1446
1447impl From<BVec3> for IVec3 {
1448 #[inline]
1449 fn from(v: BVec3) -> Self {
1450 Self::new(i32::from(v.x), i32::from(v.y), i32::from(v.z))
1451 }
1452}
1453
1454impl From<BVec3A> for IVec3 {
1455 #[inline]
1456 fn from(v: BVec3A) -> Self {
1457 let bool_array: [bool; 3] = v.into();
1458 Self::new(
1459 i32::from(bool_array[0]),
1460 i32::from(bool_array[1]),
1461 i32::from(bool_array[2]),
1462 )
1463 }
1464}