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