1use crate::{BVec2, I16Vec3, I64Vec2, I8Vec2, IVec2, U16Vec2, U64Vec2, U8Vec2, UVec2};
4
5use core::fmt;
6use core::iter::{Product, Sum};
7use core::{f32, ops::*};
8
9#[inline(always)]
11#[must_use]
12pub const fn i16vec2(x: i16, y: i16) -> I16Vec2 {
13 I16Vec2::new(x, y)
14}
15
16#[cfg_attr(not(target_arch = "spirv"), derive(Hash))]
18#[derive(Clone, Copy, PartialEq, Eq)]
19#[cfg_attr(feature = "cuda", repr(align(4)))]
20#[cfg_attr(not(target_arch = "spirv"), repr(C))]
21#[cfg_attr(target_arch = "spirv", repr(simd))]
22pub struct I16Vec2 {
23 pub x: i16,
24 pub y: i16,
25}
26
27impl I16Vec2 {
28 pub const ZERO: Self = Self::splat(0);
30
31 pub const ONE: Self = Self::splat(1);
33
34 pub const NEG_ONE: Self = Self::splat(-1);
36
37 pub const MIN: Self = Self::splat(i16::MIN);
39
40 pub const MAX: Self = Self::splat(i16::MAX);
42
43 pub const X: Self = Self::new(1, 0);
45
46 pub const Y: Self = Self::new(0, 1);
48
49 pub const NEG_X: Self = Self::new(-1, 0);
51
52 pub const NEG_Y: Self = Self::new(0, -1);
54
55 pub const AXES: [Self; 2] = [Self::X, Self::Y];
57
58 #[inline(always)]
60 #[must_use]
61 pub const fn new(x: i16, y: i16) -> Self {
62 Self { x, y }
63 }
64
65 #[inline]
67 #[must_use]
68 pub const fn splat(v: i16) -> Self {
69 Self { x: v, y: v }
70 }
71
72 #[inline]
74 #[must_use]
75 pub fn map<F>(self, f: F) -> Self
76 where
77 F: Fn(i16) -> i16,
78 {
79 Self::new(f(self.x), f(self.y))
80 }
81
82 #[inline]
88 #[must_use]
89 pub fn select(mask: BVec2, if_true: Self, if_false: Self) -> Self {
90 Self {
91 x: if mask.test(0) { if_true.x } else { if_false.x },
92 y: if mask.test(1) { if_true.y } else { if_false.y },
93 }
94 }
95
96 #[inline]
98 #[must_use]
99 pub const fn from_array(a: [i16; 2]) -> Self {
100 Self::new(a[0], a[1])
101 }
102
103 #[inline]
105 #[must_use]
106 pub const fn to_array(&self) -> [i16; 2] {
107 [self.x, self.y]
108 }
109
110 #[inline]
116 #[must_use]
117 pub const fn from_slice(slice: &[i16]) -> Self {
118 assert!(slice.len() >= 2);
119 Self::new(slice[0], slice[1])
120 }
121
122 #[inline]
128 pub fn write_to_slice(self, slice: &mut [i16]) {
129 slice[..2].copy_from_slice(&self.to_array());
130 }
131
132 #[inline]
134 #[must_use]
135 pub const fn extend(self, z: i16) -> I16Vec3 {
136 I16Vec3::new(self.x, self.y, z)
137 }
138
139 #[inline]
141 #[must_use]
142 pub fn with_x(mut self, x: i16) -> Self {
143 self.x = x;
144 self
145 }
146
147 #[inline]
149 #[must_use]
150 pub fn with_y(mut self, y: i16) -> Self {
151 self.y = y;
152 self
153 }
154
155 #[inline]
157 #[must_use]
158 pub fn dot(self, rhs: Self) -> i16 {
159 (self.x * rhs.x) + (self.y * rhs.y)
160 }
161
162 #[inline]
164 #[must_use]
165 pub fn dot_into_vec(self, rhs: Self) -> Self {
166 Self::splat(self.dot(rhs))
167 }
168
169 #[inline]
173 #[must_use]
174 pub fn min(self, rhs: Self) -> Self {
175 Self {
176 x: self.x.min(rhs.x),
177 y: self.y.min(rhs.y),
178 }
179 }
180
181 #[inline]
185 #[must_use]
186 pub fn max(self, rhs: Self) -> Self {
187 Self {
188 x: self.x.max(rhs.x),
189 y: self.y.max(rhs.y),
190 }
191 }
192
193 #[inline]
201 #[must_use]
202 pub fn clamp(self, min: Self, max: Self) -> Self {
203 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
204 self.max(min).min(max)
205 }
206
207 #[inline]
211 #[must_use]
212 pub fn min_element(self) -> i16 {
213 self.x.min(self.y)
214 }
215
216 #[inline]
220 #[must_use]
221 pub fn max_element(self) -> i16 {
222 self.x.max(self.y)
223 }
224
225 #[inline]
229 #[must_use]
230 pub fn element_sum(self) -> i16 {
231 self.x + self.y
232 }
233
234 #[inline]
238 #[must_use]
239 pub fn element_product(self) -> i16 {
240 self.x * self.y
241 }
242
243 #[inline]
249 #[must_use]
250 pub fn cmpeq(self, rhs: Self) -> BVec2 {
251 BVec2::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y))
252 }
253
254 #[inline]
260 #[must_use]
261 pub fn cmpne(self, rhs: Self) -> BVec2 {
262 BVec2::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y))
263 }
264
265 #[inline]
271 #[must_use]
272 pub fn cmpge(self, rhs: Self) -> BVec2 {
273 BVec2::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y))
274 }
275
276 #[inline]
282 #[must_use]
283 pub fn cmpgt(self, rhs: Self) -> BVec2 {
284 BVec2::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y))
285 }
286
287 #[inline]
293 #[must_use]
294 pub fn cmple(self, rhs: Self) -> BVec2 {
295 BVec2::new(self.x.le(&rhs.x), self.y.le(&rhs.y))
296 }
297
298 #[inline]
304 #[must_use]
305 pub fn cmplt(self, rhs: Self) -> BVec2 {
306 BVec2::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y))
307 }
308
309 #[inline]
311 #[must_use]
312 pub fn abs(self) -> Self {
313 Self {
314 x: self.x.abs(),
315 y: self.y.abs(),
316 }
317 }
318
319 #[inline]
325 #[must_use]
326 pub fn signum(self) -> Self {
327 Self {
328 x: self.x.signum(),
329 y: self.y.signum(),
330 }
331 }
332
333 #[inline]
338 #[must_use]
339 pub fn is_negative_bitmask(self) -> u32 {
340 (self.x.is_negative() as u32) | (self.y.is_negative() as u32) << 1
341 }
342
343 #[doc(alias = "magnitude2")]
345 #[inline]
346 #[must_use]
347 pub fn length_squared(self) -> i16 {
348 self.dot(self)
349 }
350
351 #[inline]
353 #[must_use]
354 pub fn distance_squared(self, rhs: Self) -> i16 {
355 (self - rhs).length_squared()
356 }
357
358 #[inline]
363 #[must_use]
364 pub fn div_euclid(self, rhs: Self) -> Self {
365 Self::new(self.x.div_euclid(rhs.x), self.y.div_euclid(rhs.y))
366 }
367
368 #[inline]
375 #[must_use]
376 pub fn rem_euclid(self, rhs: Self) -> Self {
377 Self::new(self.x.rem_euclid(rhs.x), self.y.rem_euclid(rhs.y))
378 }
379
380 #[inline]
382 #[must_use]
383 pub fn perp(self) -> Self {
384 Self {
385 x: -self.y,
386 y: self.x,
387 }
388 }
389
390 #[doc(alias = "wedge")]
393 #[doc(alias = "cross")]
394 #[doc(alias = "determinant")]
395 #[inline]
396 #[must_use]
397 pub fn perp_dot(self, rhs: Self) -> i16 {
398 (self.x * rhs.y) - (self.y * rhs.x)
399 }
400
401 #[inline]
405 #[must_use]
406 pub fn rotate(self, rhs: Self) -> Self {
407 Self {
408 x: self.x * rhs.x - self.y * rhs.y,
409 y: self.y * rhs.x + self.x * rhs.y,
410 }
411 }
412
413 #[inline]
415 #[must_use]
416 pub fn as_vec2(&self) -> crate::Vec2 {
417 crate::Vec2::new(self.x as f32, self.y as f32)
418 }
419
420 #[inline]
422 #[must_use]
423 pub fn as_dvec2(&self) -> crate::DVec2 {
424 crate::DVec2::new(self.x as f64, self.y as f64)
425 }
426
427 #[inline]
429 #[must_use]
430 pub fn as_i8vec2(&self) -> crate::I8Vec2 {
431 crate::I8Vec2::new(self.x as i8, self.y as i8)
432 }
433
434 #[inline]
436 #[must_use]
437 pub fn as_u8vec2(&self) -> crate::U8Vec2 {
438 crate::U8Vec2::new(self.x as u8, self.y as u8)
439 }
440
441 #[inline]
443 #[must_use]
444 pub fn as_u16vec2(&self) -> crate::U16Vec2 {
445 crate::U16Vec2::new(self.x as u16, self.y as u16)
446 }
447
448 #[inline]
450 #[must_use]
451 pub fn as_ivec2(&self) -> crate::IVec2 {
452 crate::IVec2::new(self.x as i32, self.y as i32)
453 }
454
455 #[inline]
457 #[must_use]
458 pub fn as_uvec2(&self) -> crate::UVec2 {
459 crate::UVec2::new(self.x as u32, self.y as u32)
460 }
461
462 #[inline]
464 #[must_use]
465 pub fn as_i64vec2(&self) -> crate::I64Vec2 {
466 crate::I64Vec2::new(self.x as i64, self.y as i64)
467 }
468
469 #[inline]
471 #[must_use]
472 pub fn as_u64vec2(&self) -> crate::U64Vec2 {
473 crate::U64Vec2::new(self.x as u64, self.y as u64)
474 }
475
476 #[inline]
480 #[must_use]
481 pub const fn wrapping_add(self, rhs: Self) -> Self {
482 Self {
483 x: self.x.wrapping_add(rhs.x),
484 y: self.y.wrapping_add(rhs.y),
485 }
486 }
487
488 #[inline]
492 #[must_use]
493 pub const fn wrapping_sub(self, rhs: Self) -> Self {
494 Self {
495 x: self.x.wrapping_sub(rhs.x),
496 y: self.y.wrapping_sub(rhs.y),
497 }
498 }
499
500 #[inline]
504 #[must_use]
505 pub const fn wrapping_mul(self, rhs: Self) -> Self {
506 Self {
507 x: self.x.wrapping_mul(rhs.x),
508 y: self.y.wrapping_mul(rhs.y),
509 }
510 }
511
512 #[inline]
516 #[must_use]
517 pub const fn wrapping_div(self, rhs: Self) -> Self {
518 Self {
519 x: self.x.wrapping_div(rhs.x),
520 y: self.y.wrapping_div(rhs.y),
521 }
522 }
523
524 #[inline]
528 #[must_use]
529 pub const fn saturating_add(self, rhs: Self) -> Self {
530 Self {
531 x: self.x.saturating_add(rhs.x),
532 y: self.y.saturating_add(rhs.y),
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 }
546 }
547
548 #[inline]
552 #[must_use]
553 pub const fn saturating_mul(self, rhs: Self) -> Self {
554 Self {
555 x: self.x.saturating_mul(rhs.x),
556 y: self.y.saturating_mul(rhs.y),
557 }
558 }
559
560 #[inline]
564 #[must_use]
565 pub const fn saturating_div(self, rhs: Self) -> Self {
566 Self {
567 x: self.x.saturating_div(rhs.x),
568 y: self.y.saturating_div(rhs.y),
569 }
570 }
571
572 #[inline]
576 #[must_use]
577 pub const fn wrapping_add_unsigned(self, rhs: U16Vec2) -> Self {
578 Self {
579 x: self.x.wrapping_add_unsigned(rhs.x),
580 y: self.y.wrapping_add_unsigned(rhs.y),
581 }
582 }
583
584 #[inline]
588 #[must_use]
589 pub const fn wrapping_sub_unsigned(self, rhs: U16Vec2) -> Self {
590 Self {
591 x: self.x.wrapping_sub_unsigned(rhs.x),
592 y: self.y.wrapping_sub_unsigned(rhs.y),
593 }
594 }
595
596 #[inline]
600 #[must_use]
601 pub const fn saturating_add_unsigned(self, rhs: U16Vec2) -> Self {
602 Self {
603 x: self.x.saturating_add_unsigned(rhs.x),
604 y: self.y.saturating_add_unsigned(rhs.y),
605 }
606 }
607
608 #[inline]
612 #[must_use]
613 pub const fn saturating_sub_unsigned(self, rhs: U16Vec2) -> Self {
614 Self {
615 x: self.x.saturating_sub_unsigned(rhs.x),
616 y: self.y.saturating_sub_unsigned(rhs.y),
617 }
618 }
619}
620
621impl Default for I16Vec2 {
622 #[inline(always)]
623 fn default() -> Self {
624 Self::ZERO
625 }
626}
627
628impl Div<I16Vec2> for I16Vec2 {
629 type Output = Self;
630 #[inline]
631 fn div(self, rhs: Self) -> Self {
632 Self {
633 x: self.x.div(rhs.x),
634 y: self.y.div(rhs.y),
635 }
636 }
637}
638
639impl Div<&I16Vec2> for I16Vec2 {
640 type Output = I16Vec2;
641 #[inline]
642 fn div(self, rhs: &I16Vec2) -> I16Vec2 {
643 self.div(*rhs)
644 }
645}
646
647impl Div<&I16Vec2> for &I16Vec2 {
648 type Output = I16Vec2;
649 #[inline]
650 fn div(self, rhs: &I16Vec2) -> I16Vec2 {
651 (*self).div(*rhs)
652 }
653}
654
655impl Div<I16Vec2> for &I16Vec2 {
656 type Output = I16Vec2;
657 #[inline]
658 fn div(self, rhs: I16Vec2) -> I16Vec2 {
659 (*self).div(rhs)
660 }
661}
662
663impl DivAssign<I16Vec2> for I16Vec2 {
664 #[inline]
665 fn div_assign(&mut self, rhs: Self) {
666 self.x.div_assign(rhs.x);
667 self.y.div_assign(rhs.y);
668 }
669}
670
671impl DivAssign<&Self> for I16Vec2 {
672 #[inline]
673 fn div_assign(&mut self, rhs: &Self) {
674 self.div_assign(*rhs)
675 }
676}
677
678impl Div<i16> for I16Vec2 {
679 type Output = Self;
680 #[inline]
681 fn div(self, rhs: i16) -> Self {
682 Self {
683 x: self.x.div(rhs),
684 y: self.y.div(rhs),
685 }
686 }
687}
688
689impl Div<&i16> for I16Vec2 {
690 type Output = I16Vec2;
691 #[inline]
692 fn div(self, rhs: &i16) -> I16Vec2 {
693 self.div(*rhs)
694 }
695}
696
697impl Div<&i16> for &I16Vec2 {
698 type Output = I16Vec2;
699 #[inline]
700 fn div(self, rhs: &i16) -> I16Vec2 {
701 (*self).div(*rhs)
702 }
703}
704
705impl Div<i16> for &I16Vec2 {
706 type Output = I16Vec2;
707 #[inline]
708 fn div(self, rhs: i16) -> I16Vec2 {
709 (*self).div(rhs)
710 }
711}
712
713impl DivAssign<i16> for I16Vec2 {
714 #[inline]
715 fn div_assign(&mut self, rhs: i16) {
716 self.x.div_assign(rhs);
717 self.y.div_assign(rhs);
718 }
719}
720
721impl DivAssign<&i16> for I16Vec2 {
722 #[inline]
723 fn div_assign(&mut self, rhs: &i16) {
724 self.div_assign(*rhs)
725 }
726}
727
728impl Div<I16Vec2> for i16 {
729 type Output = I16Vec2;
730 #[inline]
731 fn div(self, rhs: I16Vec2) -> I16Vec2 {
732 I16Vec2 {
733 x: self.div(rhs.x),
734 y: self.div(rhs.y),
735 }
736 }
737}
738
739impl Div<&I16Vec2> for i16 {
740 type Output = I16Vec2;
741 #[inline]
742 fn div(self, rhs: &I16Vec2) -> I16Vec2 {
743 self.div(*rhs)
744 }
745}
746
747impl Div<&I16Vec2> for &i16 {
748 type Output = I16Vec2;
749 #[inline]
750 fn div(self, rhs: &I16Vec2) -> I16Vec2 {
751 (*self).div(*rhs)
752 }
753}
754
755impl Div<I16Vec2> for &i16 {
756 type Output = I16Vec2;
757 #[inline]
758 fn div(self, rhs: I16Vec2) -> I16Vec2 {
759 (*self).div(rhs)
760 }
761}
762
763impl Mul<I16Vec2> for I16Vec2 {
764 type Output = Self;
765 #[inline]
766 fn mul(self, rhs: Self) -> Self {
767 Self {
768 x: self.x.mul(rhs.x),
769 y: self.y.mul(rhs.y),
770 }
771 }
772}
773
774impl Mul<&I16Vec2> for I16Vec2 {
775 type Output = I16Vec2;
776 #[inline]
777 fn mul(self, rhs: &I16Vec2) -> I16Vec2 {
778 self.mul(*rhs)
779 }
780}
781
782impl Mul<&I16Vec2> for &I16Vec2 {
783 type Output = I16Vec2;
784 #[inline]
785 fn mul(self, rhs: &I16Vec2) -> I16Vec2 {
786 (*self).mul(*rhs)
787 }
788}
789
790impl Mul<I16Vec2> for &I16Vec2 {
791 type Output = I16Vec2;
792 #[inline]
793 fn mul(self, rhs: I16Vec2) -> I16Vec2 {
794 (*self).mul(rhs)
795 }
796}
797
798impl MulAssign<I16Vec2> for I16Vec2 {
799 #[inline]
800 fn mul_assign(&mut self, rhs: Self) {
801 self.x.mul_assign(rhs.x);
802 self.y.mul_assign(rhs.y);
803 }
804}
805
806impl MulAssign<&Self> for I16Vec2 {
807 #[inline]
808 fn mul_assign(&mut self, rhs: &Self) {
809 self.mul_assign(*rhs)
810 }
811}
812
813impl Mul<i16> for I16Vec2 {
814 type Output = Self;
815 #[inline]
816 fn mul(self, rhs: i16) -> Self {
817 Self {
818 x: self.x.mul(rhs),
819 y: self.y.mul(rhs),
820 }
821 }
822}
823
824impl Mul<&i16> for I16Vec2 {
825 type Output = I16Vec2;
826 #[inline]
827 fn mul(self, rhs: &i16) -> I16Vec2 {
828 self.mul(*rhs)
829 }
830}
831
832impl Mul<&i16> for &I16Vec2 {
833 type Output = I16Vec2;
834 #[inline]
835 fn mul(self, rhs: &i16) -> I16Vec2 {
836 (*self).mul(*rhs)
837 }
838}
839
840impl Mul<i16> for &I16Vec2 {
841 type Output = I16Vec2;
842 #[inline]
843 fn mul(self, rhs: i16) -> I16Vec2 {
844 (*self).mul(rhs)
845 }
846}
847
848impl MulAssign<i16> for I16Vec2 {
849 #[inline]
850 fn mul_assign(&mut self, rhs: i16) {
851 self.x.mul_assign(rhs);
852 self.y.mul_assign(rhs);
853 }
854}
855
856impl MulAssign<&i16> for I16Vec2 {
857 #[inline]
858 fn mul_assign(&mut self, rhs: &i16) {
859 self.mul_assign(*rhs)
860 }
861}
862
863impl Mul<I16Vec2> for i16 {
864 type Output = I16Vec2;
865 #[inline]
866 fn mul(self, rhs: I16Vec2) -> I16Vec2 {
867 I16Vec2 {
868 x: self.mul(rhs.x),
869 y: self.mul(rhs.y),
870 }
871 }
872}
873
874impl Mul<&I16Vec2> for i16 {
875 type Output = I16Vec2;
876 #[inline]
877 fn mul(self, rhs: &I16Vec2) -> I16Vec2 {
878 self.mul(*rhs)
879 }
880}
881
882impl Mul<&I16Vec2> for &i16 {
883 type Output = I16Vec2;
884 #[inline]
885 fn mul(self, rhs: &I16Vec2) -> I16Vec2 {
886 (*self).mul(*rhs)
887 }
888}
889
890impl Mul<I16Vec2> for &i16 {
891 type Output = I16Vec2;
892 #[inline]
893 fn mul(self, rhs: I16Vec2) -> I16Vec2 {
894 (*self).mul(rhs)
895 }
896}
897
898impl Add<I16Vec2> for I16Vec2 {
899 type Output = Self;
900 #[inline]
901 fn add(self, rhs: Self) -> Self {
902 Self {
903 x: self.x.add(rhs.x),
904 y: self.y.add(rhs.y),
905 }
906 }
907}
908
909impl Add<&I16Vec2> for I16Vec2 {
910 type Output = I16Vec2;
911 #[inline]
912 fn add(self, rhs: &I16Vec2) -> I16Vec2 {
913 self.add(*rhs)
914 }
915}
916
917impl Add<&I16Vec2> for &I16Vec2 {
918 type Output = I16Vec2;
919 #[inline]
920 fn add(self, rhs: &I16Vec2) -> I16Vec2 {
921 (*self).add(*rhs)
922 }
923}
924
925impl Add<I16Vec2> for &I16Vec2 {
926 type Output = I16Vec2;
927 #[inline]
928 fn add(self, rhs: I16Vec2) -> I16Vec2 {
929 (*self).add(rhs)
930 }
931}
932
933impl AddAssign<I16Vec2> for I16Vec2 {
934 #[inline]
935 fn add_assign(&mut self, rhs: Self) {
936 self.x.add_assign(rhs.x);
937 self.y.add_assign(rhs.y);
938 }
939}
940
941impl AddAssign<&Self> for I16Vec2 {
942 #[inline]
943 fn add_assign(&mut self, rhs: &Self) {
944 self.add_assign(*rhs)
945 }
946}
947
948impl Add<i16> for I16Vec2 {
949 type Output = Self;
950 #[inline]
951 fn add(self, rhs: i16) -> Self {
952 Self {
953 x: self.x.add(rhs),
954 y: self.y.add(rhs),
955 }
956 }
957}
958
959impl Add<&i16> for I16Vec2 {
960 type Output = I16Vec2;
961 #[inline]
962 fn add(self, rhs: &i16) -> I16Vec2 {
963 self.add(*rhs)
964 }
965}
966
967impl Add<&i16> for &I16Vec2 {
968 type Output = I16Vec2;
969 #[inline]
970 fn add(self, rhs: &i16) -> I16Vec2 {
971 (*self).add(*rhs)
972 }
973}
974
975impl Add<i16> for &I16Vec2 {
976 type Output = I16Vec2;
977 #[inline]
978 fn add(self, rhs: i16) -> I16Vec2 {
979 (*self).add(rhs)
980 }
981}
982
983impl AddAssign<i16> for I16Vec2 {
984 #[inline]
985 fn add_assign(&mut self, rhs: i16) {
986 self.x.add_assign(rhs);
987 self.y.add_assign(rhs);
988 }
989}
990
991impl AddAssign<&i16> for I16Vec2 {
992 #[inline]
993 fn add_assign(&mut self, rhs: &i16) {
994 self.add_assign(*rhs)
995 }
996}
997
998impl Add<I16Vec2> for i16 {
999 type Output = I16Vec2;
1000 #[inline]
1001 fn add(self, rhs: I16Vec2) -> I16Vec2 {
1002 I16Vec2 {
1003 x: self.add(rhs.x),
1004 y: self.add(rhs.y),
1005 }
1006 }
1007}
1008
1009impl Add<&I16Vec2> for i16 {
1010 type Output = I16Vec2;
1011 #[inline]
1012 fn add(self, rhs: &I16Vec2) -> I16Vec2 {
1013 self.add(*rhs)
1014 }
1015}
1016
1017impl Add<&I16Vec2> for &i16 {
1018 type Output = I16Vec2;
1019 #[inline]
1020 fn add(self, rhs: &I16Vec2) -> I16Vec2 {
1021 (*self).add(*rhs)
1022 }
1023}
1024
1025impl Add<I16Vec2> for &i16 {
1026 type Output = I16Vec2;
1027 #[inline]
1028 fn add(self, rhs: I16Vec2) -> I16Vec2 {
1029 (*self).add(rhs)
1030 }
1031}
1032
1033impl Sub<I16Vec2> for I16Vec2 {
1034 type Output = Self;
1035 #[inline]
1036 fn sub(self, rhs: Self) -> Self {
1037 Self {
1038 x: self.x.sub(rhs.x),
1039 y: self.y.sub(rhs.y),
1040 }
1041 }
1042}
1043
1044impl Sub<&I16Vec2> for I16Vec2 {
1045 type Output = I16Vec2;
1046 #[inline]
1047 fn sub(self, rhs: &I16Vec2) -> I16Vec2 {
1048 self.sub(*rhs)
1049 }
1050}
1051
1052impl Sub<&I16Vec2> for &I16Vec2 {
1053 type Output = I16Vec2;
1054 #[inline]
1055 fn sub(self, rhs: &I16Vec2) -> I16Vec2 {
1056 (*self).sub(*rhs)
1057 }
1058}
1059
1060impl Sub<I16Vec2> for &I16Vec2 {
1061 type Output = I16Vec2;
1062 #[inline]
1063 fn sub(self, rhs: I16Vec2) -> I16Vec2 {
1064 (*self).sub(rhs)
1065 }
1066}
1067
1068impl SubAssign<I16Vec2> for I16Vec2 {
1069 #[inline]
1070 fn sub_assign(&mut self, rhs: I16Vec2) {
1071 self.x.sub_assign(rhs.x);
1072 self.y.sub_assign(rhs.y);
1073 }
1074}
1075
1076impl SubAssign<&Self> for I16Vec2 {
1077 #[inline]
1078 fn sub_assign(&mut self, rhs: &Self) {
1079 self.sub_assign(*rhs)
1080 }
1081}
1082
1083impl Sub<i16> for I16Vec2 {
1084 type Output = Self;
1085 #[inline]
1086 fn sub(self, rhs: i16) -> Self {
1087 Self {
1088 x: self.x.sub(rhs),
1089 y: self.y.sub(rhs),
1090 }
1091 }
1092}
1093
1094impl Sub<&i16> for I16Vec2 {
1095 type Output = I16Vec2;
1096 #[inline]
1097 fn sub(self, rhs: &i16) -> I16Vec2 {
1098 self.sub(*rhs)
1099 }
1100}
1101
1102impl Sub<&i16> for &I16Vec2 {
1103 type Output = I16Vec2;
1104 #[inline]
1105 fn sub(self, rhs: &i16) -> I16Vec2 {
1106 (*self).sub(*rhs)
1107 }
1108}
1109
1110impl Sub<i16> for &I16Vec2 {
1111 type Output = I16Vec2;
1112 #[inline]
1113 fn sub(self, rhs: i16) -> I16Vec2 {
1114 (*self).sub(rhs)
1115 }
1116}
1117
1118impl SubAssign<i16> for I16Vec2 {
1119 #[inline]
1120 fn sub_assign(&mut self, rhs: i16) {
1121 self.x.sub_assign(rhs);
1122 self.y.sub_assign(rhs);
1123 }
1124}
1125
1126impl SubAssign<&i16> for I16Vec2 {
1127 #[inline]
1128 fn sub_assign(&mut self, rhs: &i16) {
1129 self.sub_assign(*rhs)
1130 }
1131}
1132
1133impl Sub<I16Vec2> for i16 {
1134 type Output = I16Vec2;
1135 #[inline]
1136 fn sub(self, rhs: I16Vec2) -> I16Vec2 {
1137 I16Vec2 {
1138 x: self.sub(rhs.x),
1139 y: self.sub(rhs.y),
1140 }
1141 }
1142}
1143
1144impl Sub<&I16Vec2> for i16 {
1145 type Output = I16Vec2;
1146 #[inline]
1147 fn sub(self, rhs: &I16Vec2) -> I16Vec2 {
1148 self.sub(*rhs)
1149 }
1150}
1151
1152impl Sub<&I16Vec2> for &i16 {
1153 type Output = I16Vec2;
1154 #[inline]
1155 fn sub(self, rhs: &I16Vec2) -> I16Vec2 {
1156 (*self).sub(*rhs)
1157 }
1158}
1159
1160impl Sub<I16Vec2> for &i16 {
1161 type Output = I16Vec2;
1162 #[inline]
1163 fn sub(self, rhs: I16Vec2) -> I16Vec2 {
1164 (*self).sub(rhs)
1165 }
1166}
1167
1168impl Rem<I16Vec2> for I16Vec2 {
1169 type Output = Self;
1170 #[inline]
1171 fn rem(self, rhs: Self) -> Self {
1172 Self {
1173 x: self.x.rem(rhs.x),
1174 y: self.y.rem(rhs.y),
1175 }
1176 }
1177}
1178
1179impl Rem<&I16Vec2> for I16Vec2 {
1180 type Output = I16Vec2;
1181 #[inline]
1182 fn rem(self, rhs: &I16Vec2) -> I16Vec2 {
1183 self.rem(*rhs)
1184 }
1185}
1186
1187impl Rem<&I16Vec2> for &I16Vec2 {
1188 type Output = I16Vec2;
1189 #[inline]
1190 fn rem(self, rhs: &I16Vec2) -> I16Vec2 {
1191 (*self).rem(*rhs)
1192 }
1193}
1194
1195impl Rem<I16Vec2> for &I16Vec2 {
1196 type Output = I16Vec2;
1197 #[inline]
1198 fn rem(self, rhs: I16Vec2) -> I16Vec2 {
1199 (*self).rem(rhs)
1200 }
1201}
1202
1203impl RemAssign<I16Vec2> for I16Vec2 {
1204 #[inline]
1205 fn rem_assign(&mut self, rhs: Self) {
1206 self.x.rem_assign(rhs.x);
1207 self.y.rem_assign(rhs.y);
1208 }
1209}
1210
1211impl RemAssign<&Self> for I16Vec2 {
1212 #[inline]
1213 fn rem_assign(&mut self, rhs: &Self) {
1214 self.rem_assign(*rhs)
1215 }
1216}
1217
1218impl Rem<i16> for I16Vec2 {
1219 type Output = Self;
1220 #[inline]
1221 fn rem(self, rhs: i16) -> Self {
1222 Self {
1223 x: self.x.rem(rhs),
1224 y: self.y.rem(rhs),
1225 }
1226 }
1227}
1228
1229impl Rem<&i16> for I16Vec2 {
1230 type Output = I16Vec2;
1231 #[inline]
1232 fn rem(self, rhs: &i16) -> I16Vec2 {
1233 self.rem(*rhs)
1234 }
1235}
1236
1237impl Rem<&i16> for &I16Vec2 {
1238 type Output = I16Vec2;
1239 #[inline]
1240 fn rem(self, rhs: &i16) -> I16Vec2 {
1241 (*self).rem(*rhs)
1242 }
1243}
1244
1245impl Rem<i16> for &I16Vec2 {
1246 type Output = I16Vec2;
1247 #[inline]
1248 fn rem(self, rhs: i16) -> I16Vec2 {
1249 (*self).rem(rhs)
1250 }
1251}
1252
1253impl RemAssign<i16> for I16Vec2 {
1254 #[inline]
1255 fn rem_assign(&mut self, rhs: i16) {
1256 self.x.rem_assign(rhs);
1257 self.y.rem_assign(rhs);
1258 }
1259}
1260
1261impl RemAssign<&i16> for I16Vec2 {
1262 #[inline]
1263 fn rem_assign(&mut self, rhs: &i16) {
1264 self.rem_assign(*rhs)
1265 }
1266}
1267
1268impl Rem<I16Vec2> for i16 {
1269 type Output = I16Vec2;
1270 #[inline]
1271 fn rem(self, rhs: I16Vec2) -> I16Vec2 {
1272 I16Vec2 {
1273 x: self.rem(rhs.x),
1274 y: self.rem(rhs.y),
1275 }
1276 }
1277}
1278
1279impl Rem<&I16Vec2> for i16 {
1280 type Output = I16Vec2;
1281 #[inline]
1282 fn rem(self, rhs: &I16Vec2) -> I16Vec2 {
1283 self.rem(*rhs)
1284 }
1285}
1286
1287impl Rem<&I16Vec2> for &i16 {
1288 type Output = I16Vec2;
1289 #[inline]
1290 fn rem(self, rhs: &I16Vec2) -> I16Vec2 {
1291 (*self).rem(*rhs)
1292 }
1293}
1294
1295impl Rem<I16Vec2> for &i16 {
1296 type Output = I16Vec2;
1297 #[inline]
1298 fn rem(self, rhs: I16Vec2) -> I16Vec2 {
1299 (*self).rem(rhs)
1300 }
1301}
1302
1303#[cfg(not(target_arch = "spirv"))]
1304impl AsRef<[i16; 2]> for I16Vec2 {
1305 #[inline]
1306 fn as_ref(&self) -> &[i16; 2] {
1307 unsafe { &*(self as *const I16Vec2 as *const [i16; 2]) }
1308 }
1309}
1310
1311#[cfg(not(target_arch = "spirv"))]
1312impl AsMut<[i16; 2]> for I16Vec2 {
1313 #[inline]
1314 fn as_mut(&mut self) -> &mut [i16; 2] {
1315 unsafe { &mut *(self as *mut I16Vec2 as *mut [i16; 2]) }
1316 }
1317}
1318
1319impl Sum for I16Vec2 {
1320 #[inline]
1321 fn sum<I>(iter: I) -> Self
1322 where
1323 I: Iterator<Item = Self>,
1324 {
1325 iter.fold(Self::ZERO, Self::add)
1326 }
1327}
1328
1329impl<'a> Sum<&'a Self> for I16Vec2 {
1330 #[inline]
1331 fn sum<I>(iter: I) -> Self
1332 where
1333 I: Iterator<Item = &'a Self>,
1334 {
1335 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1336 }
1337}
1338
1339impl Product for I16Vec2 {
1340 #[inline]
1341 fn product<I>(iter: I) -> Self
1342 where
1343 I: Iterator<Item = Self>,
1344 {
1345 iter.fold(Self::ONE, Self::mul)
1346 }
1347}
1348
1349impl<'a> Product<&'a Self> for I16Vec2 {
1350 #[inline]
1351 fn product<I>(iter: I) -> Self
1352 where
1353 I: Iterator<Item = &'a Self>,
1354 {
1355 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1356 }
1357}
1358
1359impl Neg for I16Vec2 {
1360 type Output = Self;
1361 #[inline]
1362 fn neg(self) -> Self {
1363 Self {
1364 x: self.x.neg(),
1365 y: self.y.neg(),
1366 }
1367 }
1368}
1369
1370impl Neg for &I16Vec2 {
1371 type Output = I16Vec2;
1372 #[inline]
1373 fn neg(self) -> I16Vec2 {
1374 (*self).neg()
1375 }
1376}
1377
1378impl Not for I16Vec2 {
1379 type Output = Self;
1380 #[inline]
1381 fn not(self) -> Self::Output {
1382 Self {
1383 x: self.x.not(),
1384 y: self.y.not(),
1385 }
1386 }
1387}
1388
1389impl BitAnd for I16Vec2 {
1390 type Output = Self;
1391 #[inline]
1392 fn bitand(self, rhs: Self) -> Self::Output {
1393 Self {
1394 x: self.x.bitand(rhs.x),
1395 y: self.y.bitand(rhs.y),
1396 }
1397 }
1398}
1399
1400impl BitOr for I16Vec2 {
1401 type Output = Self;
1402 #[inline]
1403 fn bitor(self, rhs: Self) -> Self::Output {
1404 Self {
1405 x: self.x.bitor(rhs.x),
1406 y: self.y.bitor(rhs.y),
1407 }
1408 }
1409}
1410
1411impl BitXor for I16Vec2 {
1412 type Output = Self;
1413 #[inline]
1414 fn bitxor(self, rhs: Self) -> Self::Output {
1415 Self {
1416 x: self.x.bitxor(rhs.x),
1417 y: self.y.bitxor(rhs.y),
1418 }
1419 }
1420}
1421
1422impl BitAnd<i16> for I16Vec2 {
1423 type Output = Self;
1424 #[inline]
1425 fn bitand(self, rhs: i16) -> Self::Output {
1426 Self {
1427 x: self.x.bitand(rhs),
1428 y: self.y.bitand(rhs),
1429 }
1430 }
1431}
1432
1433impl BitOr<i16> for I16Vec2 {
1434 type Output = Self;
1435 #[inline]
1436 fn bitor(self, rhs: i16) -> Self::Output {
1437 Self {
1438 x: self.x.bitor(rhs),
1439 y: self.y.bitor(rhs),
1440 }
1441 }
1442}
1443
1444impl BitXor<i16> for I16Vec2 {
1445 type Output = Self;
1446 #[inline]
1447 fn bitxor(self, rhs: i16) -> Self::Output {
1448 Self {
1449 x: self.x.bitxor(rhs),
1450 y: self.y.bitxor(rhs),
1451 }
1452 }
1453}
1454
1455impl Shl<i8> for I16Vec2 {
1456 type Output = Self;
1457 #[inline]
1458 fn shl(self, rhs: i8) -> Self::Output {
1459 Self {
1460 x: self.x.shl(rhs),
1461 y: self.y.shl(rhs),
1462 }
1463 }
1464}
1465
1466impl Shr<i8> for I16Vec2 {
1467 type Output = Self;
1468 #[inline]
1469 fn shr(self, rhs: i8) -> Self::Output {
1470 Self {
1471 x: self.x.shr(rhs),
1472 y: self.y.shr(rhs),
1473 }
1474 }
1475}
1476
1477impl Shl<i16> for I16Vec2 {
1478 type Output = Self;
1479 #[inline]
1480 fn shl(self, rhs: i16) -> Self::Output {
1481 Self {
1482 x: self.x.shl(rhs),
1483 y: self.y.shl(rhs),
1484 }
1485 }
1486}
1487
1488impl Shr<i16> for I16Vec2 {
1489 type Output = Self;
1490 #[inline]
1491 fn shr(self, rhs: i16) -> Self::Output {
1492 Self {
1493 x: self.x.shr(rhs),
1494 y: self.y.shr(rhs),
1495 }
1496 }
1497}
1498
1499impl Shl<i32> for I16Vec2 {
1500 type Output = Self;
1501 #[inline]
1502 fn shl(self, rhs: i32) -> Self::Output {
1503 Self {
1504 x: self.x.shl(rhs),
1505 y: self.y.shl(rhs),
1506 }
1507 }
1508}
1509
1510impl Shr<i32> for I16Vec2 {
1511 type Output = Self;
1512 #[inline]
1513 fn shr(self, rhs: i32) -> Self::Output {
1514 Self {
1515 x: self.x.shr(rhs),
1516 y: self.y.shr(rhs),
1517 }
1518 }
1519}
1520
1521impl Shl<i64> for I16Vec2 {
1522 type Output = Self;
1523 #[inline]
1524 fn shl(self, rhs: i64) -> Self::Output {
1525 Self {
1526 x: self.x.shl(rhs),
1527 y: self.y.shl(rhs),
1528 }
1529 }
1530}
1531
1532impl Shr<i64> for I16Vec2 {
1533 type Output = Self;
1534 #[inline]
1535 fn shr(self, rhs: i64) -> Self::Output {
1536 Self {
1537 x: self.x.shr(rhs),
1538 y: self.y.shr(rhs),
1539 }
1540 }
1541}
1542
1543impl Shl<u8> for I16Vec2 {
1544 type Output = Self;
1545 #[inline]
1546 fn shl(self, rhs: u8) -> Self::Output {
1547 Self {
1548 x: self.x.shl(rhs),
1549 y: self.y.shl(rhs),
1550 }
1551 }
1552}
1553
1554impl Shr<u8> for I16Vec2 {
1555 type Output = Self;
1556 #[inline]
1557 fn shr(self, rhs: u8) -> Self::Output {
1558 Self {
1559 x: self.x.shr(rhs),
1560 y: self.y.shr(rhs),
1561 }
1562 }
1563}
1564
1565impl Shl<u16> for I16Vec2 {
1566 type Output = Self;
1567 #[inline]
1568 fn shl(self, rhs: u16) -> Self::Output {
1569 Self {
1570 x: self.x.shl(rhs),
1571 y: self.y.shl(rhs),
1572 }
1573 }
1574}
1575
1576impl Shr<u16> for I16Vec2 {
1577 type Output = Self;
1578 #[inline]
1579 fn shr(self, rhs: u16) -> Self::Output {
1580 Self {
1581 x: self.x.shr(rhs),
1582 y: self.y.shr(rhs),
1583 }
1584 }
1585}
1586
1587impl Shl<u32> for I16Vec2 {
1588 type Output = Self;
1589 #[inline]
1590 fn shl(self, rhs: u32) -> Self::Output {
1591 Self {
1592 x: self.x.shl(rhs),
1593 y: self.y.shl(rhs),
1594 }
1595 }
1596}
1597
1598impl Shr<u32> for I16Vec2 {
1599 type Output = Self;
1600 #[inline]
1601 fn shr(self, rhs: u32) -> Self::Output {
1602 Self {
1603 x: self.x.shr(rhs),
1604 y: self.y.shr(rhs),
1605 }
1606 }
1607}
1608
1609impl Shl<u64> for I16Vec2 {
1610 type Output = Self;
1611 #[inline]
1612 fn shl(self, rhs: u64) -> Self::Output {
1613 Self {
1614 x: self.x.shl(rhs),
1615 y: self.y.shl(rhs),
1616 }
1617 }
1618}
1619
1620impl Shr<u64> for I16Vec2 {
1621 type Output = Self;
1622 #[inline]
1623 fn shr(self, rhs: u64) -> Self::Output {
1624 Self {
1625 x: self.x.shr(rhs),
1626 y: self.y.shr(rhs),
1627 }
1628 }
1629}
1630
1631impl Shl<crate::IVec2> for I16Vec2 {
1632 type Output = Self;
1633 #[inline]
1634 fn shl(self, rhs: crate::IVec2) -> Self::Output {
1635 Self {
1636 x: self.x.shl(rhs.x),
1637 y: self.y.shl(rhs.y),
1638 }
1639 }
1640}
1641
1642impl Shr<crate::IVec2> for I16Vec2 {
1643 type Output = Self;
1644 #[inline]
1645 fn shr(self, rhs: crate::IVec2) -> Self::Output {
1646 Self {
1647 x: self.x.shr(rhs.x),
1648 y: self.y.shr(rhs.y),
1649 }
1650 }
1651}
1652
1653impl Shl<crate::UVec2> for I16Vec2 {
1654 type Output = Self;
1655 #[inline]
1656 fn shl(self, rhs: crate::UVec2) -> Self::Output {
1657 Self {
1658 x: self.x.shl(rhs.x),
1659 y: self.y.shl(rhs.y),
1660 }
1661 }
1662}
1663
1664impl Shr<crate::UVec2> for I16Vec2 {
1665 type Output = Self;
1666 #[inline]
1667 fn shr(self, rhs: crate::UVec2) -> Self::Output {
1668 Self {
1669 x: self.x.shr(rhs.x),
1670 y: self.y.shr(rhs.y),
1671 }
1672 }
1673}
1674
1675impl Index<usize> for I16Vec2 {
1676 type Output = i16;
1677 #[inline]
1678 fn index(&self, index: usize) -> &Self::Output {
1679 match index {
1680 0 => &self.x,
1681 1 => &self.y,
1682 _ => panic!("index out of bounds"),
1683 }
1684 }
1685}
1686
1687impl IndexMut<usize> for I16Vec2 {
1688 #[inline]
1689 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1690 match index {
1691 0 => &mut self.x,
1692 1 => &mut self.y,
1693 _ => panic!("index out of bounds"),
1694 }
1695 }
1696}
1697
1698impl fmt::Display for I16Vec2 {
1699 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1700 write!(f, "[{}, {}]", self.x, self.y)
1701 }
1702}
1703
1704impl fmt::Debug for I16Vec2 {
1705 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1706 fmt.debug_tuple(stringify!(I16Vec2))
1707 .field(&self.x)
1708 .field(&self.y)
1709 .finish()
1710 }
1711}
1712
1713impl From<[i16; 2]> for I16Vec2 {
1714 #[inline]
1715 fn from(a: [i16; 2]) -> Self {
1716 Self::new(a[0], a[1])
1717 }
1718}
1719
1720impl From<I16Vec2> for [i16; 2] {
1721 #[inline]
1722 fn from(v: I16Vec2) -> Self {
1723 [v.x, v.y]
1724 }
1725}
1726
1727impl From<(i16, i16)> for I16Vec2 {
1728 #[inline]
1729 fn from(t: (i16, i16)) -> Self {
1730 Self::new(t.0, t.1)
1731 }
1732}
1733
1734impl From<I16Vec2> for (i16, i16) {
1735 #[inline]
1736 fn from(v: I16Vec2) -> Self {
1737 (v.x, v.y)
1738 }
1739}
1740
1741impl From<I8Vec2> for I16Vec2 {
1742 #[inline]
1743 fn from(v: I8Vec2) -> Self {
1744 Self::new(i16::from(v.x), i16::from(v.y))
1745 }
1746}
1747
1748impl From<U8Vec2> for I16Vec2 {
1749 #[inline]
1750 fn from(v: U8Vec2) -> Self {
1751 Self::new(i16::from(v.x), i16::from(v.y))
1752 }
1753}
1754
1755impl TryFrom<U16Vec2> for I16Vec2 {
1756 type Error = core::num::TryFromIntError;
1757
1758 #[inline]
1759 fn try_from(v: U16Vec2) -> Result<Self, Self::Error> {
1760 Ok(Self::new(i16::try_from(v.x)?, i16::try_from(v.y)?))
1761 }
1762}
1763
1764impl TryFrom<IVec2> for I16Vec2 {
1765 type Error = core::num::TryFromIntError;
1766
1767 #[inline]
1768 fn try_from(v: IVec2) -> Result<Self, Self::Error> {
1769 Ok(Self::new(i16::try_from(v.x)?, i16::try_from(v.y)?))
1770 }
1771}
1772
1773impl TryFrom<UVec2> for I16Vec2 {
1774 type Error = core::num::TryFromIntError;
1775
1776 #[inline]
1777 fn try_from(v: UVec2) -> Result<Self, Self::Error> {
1778 Ok(Self::new(i16::try_from(v.x)?, i16::try_from(v.y)?))
1779 }
1780}
1781
1782impl TryFrom<I64Vec2> for I16Vec2 {
1783 type Error = core::num::TryFromIntError;
1784
1785 #[inline]
1786 fn try_from(v: I64Vec2) -> Result<Self, Self::Error> {
1787 Ok(Self::new(i16::try_from(v.x)?, i16::try_from(v.y)?))
1788 }
1789}
1790
1791impl TryFrom<U64Vec2> for I16Vec2 {
1792 type Error = core::num::TryFromIntError;
1793
1794 #[inline]
1795 fn try_from(v: U64Vec2) -> Result<Self, Self::Error> {
1796 Ok(Self::new(i16::try_from(v.x)?, i16::try_from(v.y)?))
1797 }
1798}
1799
1800impl From<BVec2> for I16Vec2 {
1801 #[inline]
1802 fn from(v: BVec2) -> Self {
1803 Self::new(i16::from(v.x), i16::from(v.y))
1804 }
1805}