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