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