1use crate::{BVec2, DVec3, f64::math};
4
5use crate::Vec2;
6
7#[cfg(feature = "i32")]
8use crate::IVec2;
9
10#[cfg(feature = "u32")]
11use crate::UVec2;
12
13use core::fmt;
14use core::iter::{Product, Sum};
15use core::ops::*;
16
17#[cfg(feature = "zerocopy-08")]
18use zerocopy_derive_08::*;
19
20#[inline(always)]
22#[must_use]
23pub const fn dvec2(x: f64, y: f64) -> DVec2 {
24 DVec2::new(x, y)
25}
26
27#[derive(Clone, Copy, PartialEq)]
29#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
30#[cfg_attr(
31 feature = "zerocopy-08",
32 derive(FromBytes, Immutable, IntoBytes, KnownLayout)
33)]
34#[cfg_attr(feature = "cuda", repr(align(16)))]
35#[repr(C)]
36#[cfg_attr(target_arch = "spirv", rust_gpu::vector::v1)]
37pub struct DVec2 {
38 pub x: f64,
39 pub y: f64,
40}
41
42impl DVec2 {
43 pub const ZERO: Self = Self::splat(0.0);
45
46 pub const ONE: Self = Self::splat(1.0);
48
49 pub const NEG_ONE: Self = Self::splat(-1.0);
51
52 pub const MIN: Self = Self::splat(f64::MIN);
54
55 pub const MAX: Self = Self::splat(f64::MAX);
57
58 pub const NAN: Self = Self::splat(f64::NAN);
60
61 pub const INFINITY: Self = Self::splat(f64::INFINITY);
63
64 pub const NEG_INFINITY: Self = Self::splat(f64::NEG_INFINITY);
66
67 pub const X: Self = Self::new(1.0, 0.0);
69
70 pub const Y: Self = Self::new(0.0, 1.0);
72
73 pub const NEG_X: Self = Self::new(-1.0, 0.0);
75
76 pub const NEG_Y: Self = Self::new(0.0, -1.0);
78
79 pub const AXES: [Self; 2] = [Self::X, Self::Y];
81
82 pub const USES_CORE_SIMD: bool = false;
84 pub const USES_NEON: bool = false;
86 pub const USES_SCALAR_MATH: bool = true;
88 pub const USES_SSE2: bool = false;
90 pub const USES_WASM_SIMD: bool = false;
92
93 #[inline(always)]
95 #[must_use]
96 pub const fn new(x: f64, y: f64) -> Self {
97 Self { x, y }
98 }
99
100 #[inline]
102 #[must_use]
103 pub const fn splat(v: f64) -> Self {
104 Self::new(v, v)
105 }
106
107 #[inline]
109 #[must_use]
110 pub fn map<F>(self, mut f: F) -> Self
111 where
112 F: FnMut(f64) -> f64,
113 {
114 Self::new(f(self.x), f(self.y))
115 }
116
117 #[inline]
123 #[must_use]
124 pub fn select(mask: BVec2, if_true: Self, if_false: Self) -> Self {
125 Self::new(
126 if mask.test(0) { if_true.x } else { if_false.x },
127 if mask.test(1) { if_true.y } else { if_false.y },
128 )
129 }
130
131 #[inline]
133 #[must_use]
134 pub const fn from_array(a: [f64; 2]) -> Self {
135 Self::new(a[0], a[1])
136 }
137
138 #[inline]
140 #[must_use]
141 pub const fn to_array(&self) -> [f64; 2] {
142 [self.x, self.y]
143 }
144
145 #[inline]
151 #[must_use]
152 #[track_caller]
153 pub const fn from_slice(slice: &[f64]) -> Self {
154 assert!(slice.len() >= 2);
155 Self::new(slice[0], slice[1])
156 }
157
158 #[inline]
164 #[track_caller]
165 pub fn write_to_slice(self, slice: &mut [f64]) {
166 slice[..2].copy_from_slice(&self.to_array());
167 }
168
169 #[inline]
171 #[must_use]
172 pub const fn extend(self, z: f64) -> DVec3 {
173 DVec3::new(self.x, self.y, z)
174 }
175
176 #[inline]
178 #[must_use]
179 pub fn with_x(mut self, x: f64) -> Self {
180 self.x = x;
181 self
182 }
183
184 #[inline]
186 #[must_use]
187 pub fn with_y(mut self, y: f64) -> Self {
188 self.y = y;
189 self
190 }
191
192 #[inline]
194 #[must_use]
195 pub fn dot(self, rhs: Self) -> f64 {
196 (self.x * rhs.x) + (self.y * rhs.y)
197 }
198
199 #[inline]
201 #[must_use]
202 pub fn dot_into_vec(self, rhs: Self) -> Self {
203 Self::splat(self.dot(rhs))
204 }
205
206 #[inline]
214 #[must_use]
215 pub fn min(self, rhs: Self) -> Self {
216 Self::new(
217 if self.x < rhs.x { self.x } else { rhs.x },
218 if self.y < rhs.y { self.y } else { rhs.y },
219 )
220 }
221
222 #[inline]
230 #[must_use]
231 pub fn max(self, rhs: Self) -> Self {
232 Self::new(
233 if self.x > rhs.x { self.x } else { rhs.x },
234 if self.y > rhs.y { self.y } else { rhs.y },
235 )
236 }
237
238 #[inline]
248 #[must_use]
249 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
250 pub fn clamp(self, min: Self, max: Self) -> Self {
251 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
252 self.max(min).min(max)
253 }
254
255 #[inline]
261 #[must_use]
262 pub fn min_element(self) -> f64 {
263 let min = |a, b| if a < b { a } else { b };
264 min(self.x, self.y)
265 }
266
267 #[inline]
273 #[must_use]
274 pub fn max_element(self) -> f64 {
275 let max = |a, b| if a > b { a } else { b };
276 max(self.x, self.y)
277 }
278
279 #[doc(alias = "argmin")]
281 #[inline]
282 #[must_use]
283 pub fn min_position(self) -> usize {
284 if self.x <= self.y { 0 } else { 1 }
285 }
286
287 #[doc(alias = "argmax")]
289 #[inline]
290 #[must_use]
291 pub fn max_position(self) -> usize {
292 if self.x >= self.y { 0 } else { 1 }
293 }
294
295 #[inline]
299 #[must_use]
300 pub fn element_sum(self) -> f64 {
301 self.x + self.y
302 }
303
304 #[inline]
308 #[must_use]
309 pub fn element_product(self) -> f64 {
310 self.x * self.y
311 }
312
313 #[inline]
319 #[must_use]
320 pub fn cmpeq(self, rhs: Self) -> BVec2 {
321 BVec2::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y))
322 }
323
324 #[inline]
330 #[must_use]
331 pub fn cmpne(self, rhs: Self) -> BVec2 {
332 BVec2::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y))
333 }
334
335 #[inline]
341 #[must_use]
342 pub fn cmpge(self, rhs: Self) -> BVec2 {
343 BVec2::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y))
344 }
345
346 #[inline]
352 #[must_use]
353 pub fn cmpgt(self, rhs: Self) -> BVec2 {
354 BVec2::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y))
355 }
356
357 #[inline]
363 #[must_use]
364 pub fn cmple(self, rhs: Self) -> BVec2 {
365 BVec2::new(self.x.le(&rhs.x), self.y.le(&rhs.y))
366 }
367
368 #[inline]
374 #[must_use]
375 pub fn cmplt(self, rhs: Self) -> BVec2 {
376 BVec2::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y))
377 }
378
379 #[inline]
381 #[must_use]
382 pub fn abs(self) -> Self {
383 Self::new(self.x.abs(), self.y.abs())
384 }
385
386 #[inline]
392 #[must_use]
393 pub fn signum(self) -> Self {
394 Self::new(self.x.signum(), self.y.signum())
395 }
396
397 #[inline]
399 #[must_use]
400 pub fn copysign(self, rhs: Self) -> Self {
401 Self::new(self.x.copysign(rhs.x), self.y.copysign(rhs.y))
402 }
403
404 #[inline]
412 #[must_use]
413 pub fn is_negative_bitmask(self) -> u32 {
414 (self.x.is_sign_negative() as u32) | ((self.y.is_sign_negative() as u32) << 1)
415 }
416
417 #[inline]
422 #[must_use]
423 pub fn is_negative_mask(self) -> BVec2 {
424 BVec2::new(self.x.is_sign_negative(), self.y.is_sign_negative())
425 }
426
427 #[inline]
430 #[must_use]
431 pub fn is_finite(self) -> bool {
432 self.x.is_finite() && self.y.is_finite()
433 }
434
435 #[inline]
439 #[must_use]
440 pub fn is_finite_mask(self) -> BVec2 {
441 BVec2::new(self.x.is_finite(), self.y.is_finite())
442 }
443
444 #[inline]
446 #[must_use]
447 pub fn is_nan(self) -> bool {
448 self.x.is_nan() || self.y.is_nan()
449 }
450
451 #[inline]
455 #[must_use]
456 pub fn is_nan_mask(self) -> BVec2 {
457 BVec2::new(self.x.is_nan(), self.y.is_nan())
458 }
459
460 #[doc(alias = "magnitude")]
462 #[inline]
463 #[must_use]
464 pub fn length(self) -> f64 {
465 math::sqrt(self.dot(self))
466 }
467
468 #[allow(dead_code)]
470 fn is_non_zero(self) -> bool {
471 self.length_squared() > 0.0
472 }
473
474 #[doc(alias = "magnitude2")]
478 #[inline]
479 #[must_use]
480 pub fn length_squared(self) -> f64 {
481 self.dot(self)
482 }
483
484 #[inline]
488 #[must_use]
489 pub fn length_recip(self) -> f64 {
490 1.0 / self.length()
491 }
492
493 #[inline]
495 #[must_use]
496 pub fn distance(self, rhs: Self) -> f64 {
497 (self - rhs).length()
498 }
499
500 #[inline]
502 #[must_use]
503 pub fn distance_squared(self, rhs: Self) -> f64 {
504 (self - rhs).length_squared()
505 }
506
507 #[inline]
509 #[must_use]
510 pub fn div_euclid(self, rhs: Self) -> Self {
511 Self::new(
512 math::div_euclid(self.x, rhs.x),
513 math::div_euclid(self.y, rhs.y),
514 )
515 }
516
517 #[inline]
521 #[must_use]
522 pub fn rem_euclid(self, rhs: Self) -> Self {
523 Self::new(
524 math::rem_euclid(self.x, rhs.x),
525 math::rem_euclid(self.y, rhs.y),
526 )
527 }
528
529 #[inline]
539 #[must_use]
540 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
541 pub fn normalize(self) -> Self {
542 #[allow(clippy::let_and_return)]
543 let normalized = self.mul(self.length_recip());
544 glam_assert!(normalized.is_finite());
545 normalized
546 }
547
548 #[inline]
555 #[must_use]
556 pub fn try_normalize(self) -> Option<Self> {
557 let rcp = self.length_recip();
558 if rcp.is_finite() && rcp > 0.0 {
559 Some(self * rcp)
560 } else {
561 None
562 }
563 }
564
565 #[inline]
573 #[must_use]
574 pub fn normalize_or(self, fallback: Self) -> Self {
575 let rcp = self.length_recip();
576 if rcp.is_finite() && rcp > 0.0 {
577 self * rcp
578 } else {
579 fallback
580 }
581 }
582
583 #[inline]
590 #[must_use]
591 pub fn normalize_or_zero(self) -> Self {
592 self.normalize_or(Self::ZERO)
593 }
594
595 #[inline]
599 #[must_use]
600 pub fn normalize_and_length(self) -> (Self, f64) {
601 let length = self.length();
602 let rcp = 1.0 / length;
603 if rcp.is_finite() && rcp > 0.0 {
604 (self * rcp, length)
605 } else {
606 (Self::X, 0.0)
607 }
608 }
609
610 #[inline]
614 #[must_use]
615 pub fn is_normalized(self) -> bool {
616 (self.length_squared() - 1.0).abs() <= 2e-4
617 }
618
619 #[inline]
627 #[must_use]
628 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
629 pub fn project_onto(self, rhs: Self) -> Self {
630 let rhs_len_sq = rhs.dot(rhs);
631 glam_assert!(rhs_len_sq != 0.0);
632 rhs * (self.dot(rhs) / rhs_len_sq)
633 }
634
635 #[doc(alias("plane"))]
646 #[inline]
647 #[must_use]
648 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
649 pub fn reject_from(self, rhs: Self) -> Self {
650 self - self.project_onto(rhs)
651 }
652
653 #[inline]
661 #[must_use]
662 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
663 pub fn project_onto_normalized(self, rhs: Self) -> Self {
664 glam_assert!(rhs.is_normalized());
665 rhs * self.dot(rhs)
666 }
667
668 #[doc(alias("plane"))]
679 #[inline]
680 #[must_use]
681 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
682 pub fn reject_from_normalized(self, rhs: Self) -> Self {
683 self - self.project_onto_normalized(rhs)
684 }
685
686 #[inline]
689 #[must_use]
690 pub fn round(self) -> Self {
691 Self::new(math::round(self.x), math::round(self.y))
692 }
693
694 #[inline]
697 #[must_use]
698 pub fn floor(self) -> Self {
699 Self::new(math::floor(self.x), math::floor(self.y))
700 }
701
702 #[inline]
705 #[must_use]
706 pub fn ceil(self) -> Self {
707 Self::new(math::ceil(self.x), math::ceil(self.y))
708 }
709
710 #[inline]
713 #[must_use]
714 pub fn trunc(self) -> Self {
715 Self::new(math::trunc(self.x), math::trunc(self.y))
716 }
717
718 #[inline]
722 #[must_use]
723 pub fn step(self, rhs: Self) -> Self {
724 Self::select(rhs.cmplt(self), Self::ZERO, Self::ONE)
725 }
726
727 #[inline]
738 #[must_use]
739 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
740 pub fn smoothstep(self, edge0: Self, edge1: Self) -> Self {
741 glam_assert!(edge0.cmplt(edge1).all());
742 let t = ((self - edge0) / (edge1 - edge0)).saturate();
743 t * t * (Self::splat(3.0) - Self::splat(2.0) * t)
744 }
745
746 #[inline]
748 #[must_use]
749 pub fn saturate(self) -> Self {
750 self.clamp(Self::ZERO, Self::ONE)
751 }
752
753 #[inline]
760 #[must_use]
761 pub fn fract(self) -> Self {
762 self - self.trunc()
763 }
764
765 #[inline]
772 #[must_use]
773 pub fn fract_gl(self) -> Self {
774 self - self.floor()
775 }
776
777 #[inline]
780 #[must_use]
781 pub fn exp(self) -> Self {
782 Self::new(math::exp(self.x), math::exp(self.y))
783 }
784
785 #[inline]
787 #[must_use]
788 pub fn exp2(self) -> Self {
789 Self::new(math::exp2(self.x), math::exp2(self.y))
790 }
791
792 #[inline]
795 #[must_use]
796 pub fn ln(self) -> Self {
797 Self::new(math::ln(self.x), math::ln(self.y))
798 }
799
800 #[inline]
803 #[must_use]
804 pub fn log2(self) -> Self {
805 Self::new(math::log2(self.x), math::log2(self.y))
806 }
807
808 #[inline]
810 #[must_use]
811 pub fn powf(self, n: f64) -> Self {
812 Self::new(math::powf(self.x, n), math::powf(self.y, n))
813 }
814
815 #[inline]
818 #[must_use]
819 pub fn sqrt(self) -> Self {
820 Self::new(math::sqrt(self.x), math::sqrt(self.y))
821 }
822
823 #[inline]
825 #[must_use]
826 pub fn cos(self) -> Self {
827 Self::new(math::cos(self.x), math::cos(self.y))
828 }
829
830 #[inline]
832 #[must_use]
833 pub fn sin(self) -> Self {
834 Self::new(math::sin(self.x), math::sin(self.y))
835 }
836
837 #[inline]
839 #[must_use]
840 pub fn sin_cos(self) -> (Self, Self) {
841 let (sin_x, cos_x) = math::sin_cos(self.x);
842 let (sin_y, cos_y) = math::sin_cos(self.y);
843
844 (Self::new(sin_x, sin_y), Self::new(cos_x, cos_y))
845 }
846
847 #[inline]
849 #[must_use]
850 pub fn recip(self) -> Self {
851 Self::new(1.0 / self.x, 1.0 / self.y)
852 }
853
854 #[doc(alias = "mix")]
866 #[inline]
867 #[must_use]
868 pub fn lerp(self, rhs: Self, s: f64) -> Self {
869 self * (1.0 - s) + rhs * s
870 }
871
872 #[doc(alias = "mix")]
889 #[inline]
890 #[must_use]
891 pub fn lerp_monotonic(self, rhs: Self, s: f64) -> Self {
892 self + (rhs - self) * s
893 }
894
895 #[inline]
900 #[must_use]
901 pub fn move_towards(self, rhs: Self, d: f64) -> Self {
902 let a = rhs - self;
903 let len = a.length();
904 if len <= d || len <= 1e-4 {
905 return rhs;
906 }
907 self + a / len * d
908 }
909
910 #[inline]
916 pub fn midpoint(self, rhs: Self) -> Self {
917 (self + rhs) * 0.5
918 }
919
920 #[inline]
930 #[must_use]
931 pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f64) -> bool {
932 self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
933 }
934
935 #[inline]
941 #[must_use]
942 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
943 pub fn clamp_length(self, min: f64, max: f64) -> Self {
944 glam_assert!(0.0 <= min);
945 glam_assert!(min <= max);
946 let length_sq = self.length_squared();
947 if length_sq < min * min {
948 min * (self / math::sqrt(length_sq))
949 } else if length_sq > max * max {
950 max * (self / math::sqrt(length_sq))
951 } else {
952 self
953 }
954 }
955
956 #[inline]
962 #[must_use]
963 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
964 pub fn clamp_length_max(self, max: f64) -> Self {
965 glam_assert!(0.0 <= max);
966 let length_sq = self.length_squared();
967 if length_sq > max * max {
968 max * (self / math::sqrt(length_sq))
969 } else {
970 self
971 }
972 }
973
974 #[inline]
980 #[must_use]
981 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
982 pub fn clamp_length_min(self, min: f64) -> Self {
983 glam_assert!(0.0 <= min);
984 let length_sq = self.length_squared();
985 if length_sq < min * min {
986 min * (self / math::sqrt(length_sq))
987 } else {
988 self
989 }
990 }
991
992 #[inline]
1000 #[must_use]
1001 pub fn mul_add(self, a: Self, b: Self) -> Self {
1002 Self::new(
1003 math::mul_add(self.x, a.x, b.x),
1004 math::mul_add(self.y, a.y, b.y),
1005 )
1006 }
1007
1008 #[inline]
1017 #[must_use]
1018 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1019 pub fn reflect(self, normal: Self) -> Self {
1020 glam_assert!(normal.is_normalized());
1021 self - 2.0 * self.dot(normal) * normal
1022 }
1023
1024 #[inline]
1034 #[must_use]
1035 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1036 pub fn refract(self, normal: Self, eta: f64) -> Self {
1037 glam_assert!(self.is_normalized());
1038 glam_assert!(normal.is_normalized());
1039 let n_dot_i = normal.dot(self);
1040 let k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1041 if k >= 0.0 {
1042 eta * self - (eta * n_dot_i + math::sqrt(k)) * normal
1043 } else {
1044 Self::ZERO
1045 }
1046 }
1047
1048 #[inline]
1053 #[must_use]
1054 pub fn from_angle(angle: f64) -> Self {
1055 let (sin, cos) = math::sin_cos(angle);
1056 Self::new(cos, sin)
1057 }
1058
1059 #[inline]
1063 #[must_use]
1064 pub fn to_angle(self) -> f64 {
1065 math::atan2(self.y, self.x)
1066 }
1067
1068 #[inline]
1079 #[must_use]
1080 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1081 pub fn angle_to(self, rhs: Self) -> f64 {
1082 glam_assert!(self.is_non_zero());
1083 glam_assert!(rhs.is_non_zero());
1084 let angle = math::acos_approx(
1085 self.dot(rhs) / math::sqrt(self.length_squared() * rhs.length_squared()),
1086 );
1087
1088 angle * self.perp_dot(rhs).signum()
1089 }
1090
1091 #[inline]
1093 #[must_use]
1094 pub fn perp(self) -> Self {
1095 Self::new(-self.y, self.x)
1096 }
1097
1098 #[doc(alias = "wedge")]
1101 #[doc(alias = "cross")]
1102 #[doc(alias = "determinant")]
1103 #[inline]
1104 #[must_use]
1105 pub fn perp_dot(self, rhs: Self) -> f64 {
1106 (self.x * rhs.y) - (self.y * rhs.x)
1107 }
1108
1109 #[inline]
1117 #[must_use]
1118 pub fn rotate(self, rhs: Self) -> Self {
1119 Self::new(
1120 self.x * rhs.x - self.y * rhs.y,
1121 self.y * rhs.x + self.x * rhs.y,
1122 )
1123 }
1124
1125 #[inline]
1128 #[must_use]
1129 pub fn rotate_angle(self, angle: f64) -> Self {
1130 self.rotate(Self::from_angle(angle))
1131 }
1132
1133 #[inline]
1143 #[must_use]
1144 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1145 pub fn rotate_towards(self, rhs: Self, max_angle: f64) -> Self {
1146 let a = self.angle_to(rhs);
1147 let abs_a = a.abs();
1148 let angle = max_angle.clamp(abs_a - core::f64::consts::PI, abs_a) * a.signum();
1150 Self::from_angle(angle).rotate(self)
1151 }
1152
1153 #[inline]
1155 #[must_use]
1156 pub fn as_vec2(self) -> crate::Vec2 {
1157 crate::Vec2::new(self.x as f32, self.y as f32)
1158 }
1159
1160 #[cfg(feature = "i8")]
1162 #[inline]
1163 #[must_use]
1164 pub fn as_i8vec2(self) -> crate::I8Vec2 {
1165 crate::I8Vec2::new(self.x as i8, self.y as i8)
1166 }
1167
1168 #[cfg(feature = "u8")]
1170 #[inline]
1171 #[must_use]
1172 pub fn as_u8vec2(self) -> crate::U8Vec2 {
1173 crate::U8Vec2::new(self.x as u8, self.y as u8)
1174 }
1175
1176 #[cfg(feature = "i16")]
1178 #[inline]
1179 #[must_use]
1180 pub fn as_i16vec2(self) -> crate::I16Vec2 {
1181 crate::I16Vec2::new(self.x as i16, self.y as i16)
1182 }
1183
1184 #[cfg(feature = "u16")]
1186 #[inline]
1187 #[must_use]
1188 pub fn as_u16vec2(self) -> crate::U16Vec2 {
1189 crate::U16Vec2::new(self.x as u16, self.y as u16)
1190 }
1191
1192 #[cfg(feature = "i32")]
1194 #[inline]
1195 #[must_use]
1196 pub fn as_ivec2(self) -> crate::IVec2 {
1197 crate::IVec2::new(self.x as i32, self.y as i32)
1198 }
1199
1200 #[cfg(feature = "u32")]
1202 #[inline]
1203 #[must_use]
1204 pub fn as_uvec2(self) -> crate::UVec2 {
1205 crate::UVec2::new(self.x as u32, self.y as u32)
1206 }
1207
1208 #[cfg(feature = "i64")]
1210 #[inline]
1211 #[must_use]
1212 pub fn as_i64vec2(self) -> crate::I64Vec2 {
1213 crate::I64Vec2::new(self.x as i64, self.y as i64)
1214 }
1215
1216 #[cfg(feature = "u64")]
1218 #[inline]
1219 #[must_use]
1220 pub fn as_u64vec2(self) -> crate::U64Vec2 {
1221 crate::U64Vec2::new(self.x as u64, self.y as u64)
1222 }
1223
1224 #[cfg(feature = "isize")]
1226 #[inline]
1227 #[must_use]
1228 pub fn as_isizevec2(self) -> crate::ISizeVec2 {
1229 crate::ISizeVec2::new(self.x as isize, self.y as isize)
1230 }
1231
1232 #[cfg(feature = "usize")]
1234 #[inline]
1235 #[must_use]
1236 pub fn as_usizevec2(self) -> crate::USizeVec2 {
1237 crate::USizeVec2::new(self.x as usize, self.y as usize)
1238 }
1239}
1240
1241impl Default for DVec2 {
1242 #[inline(always)]
1243 fn default() -> Self {
1244 Self::ZERO
1245 }
1246}
1247
1248impl Div for DVec2 {
1249 type Output = Self;
1250 #[inline]
1251 fn div(self, rhs: Self) -> Self {
1252 Self::new(self.x.div(rhs.x), self.y.div(rhs.y))
1253 }
1254}
1255
1256impl Div<&Self> for DVec2 {
1257 type Output = Self;
1258 #[inline]
1259 fn div(self, rhs: &Self) -> Self {
1260 self.div(*rhs)
1261 }
1262}
1263
1264impl Div<&DVec2> for &DVec2 {
1265 type Output = DVec2;
1266 #[inline]
1267 fn div(self, rhs: &DVec2) -> DVec2 {
1268 (*self).div(*rhs)
1269 }
1270}
1271
1272impl Div<DVec2> for &DVec2 {
1273 type Output = DVec2;
1274 #[inline]
1275 fn div(self, rhs: DVec2) -> DVec2 {
1276 (*self).div(rhs)
1277 }
1278}
1279
1280impl DivAssign for DVec2 {
1281 #[inline]
1282 fn div_assign(&mut self, rhs: Self) {
1283 self.x.div_assign(rhs.x);
1284 self.y.div_assign(rhs.y);
1285 }
1286}
1287
1288impl DivAssign<&Self> for DVec2 {
1289 #[inline]
1290 fn div_assign(&mut self, rhs: &Self) {
1291 self.div_assign(*rhs);
1292 }
1293}
1294
1295impl Div<f64> for DVec2 {
1296 type Output = Self;
1297 #[inline]
1298 fn div(self, rhs: f64) -> Self {
1299 Self::new(self.x.div(rhs), self.y.div(rhs))
1300 }
1301}
1302
1303impl Div<&f64> for DVec2 {
1304 type Output = Self;
1305 #[inline]
1306 fn div(self, rhs: &f64) -> Self {
1307 self.div(*rhs)
1308 }
1309}
1310
1311impl Div<&f64> for &DVec2 {
1312 type Output = DVec2;
1313 #[inline]
1314 fn div(self, rhs: &f64) -> DVec2 {
1315 (*self).div(*rhs)
1316 }
1317}
1318
1319impl Div<f64> for &DVec2 {
1320 type Output = DVec2;
1321 #[inline]
1322 fn div(self, rhs: f64) -> DVec2 {
1323 (*self).div(rhs)
1324 }
1325}
1326
1327impl DivAssign<f64> for DVec2 {
1328 #[inline]
1329 fn div_assign(&mut self, rhs: f64) {
1330 self.x.div_assign(rhs);
1331 self.y.div_assign(rhs);
1332 }
1333}
1334
1335impl DivAssign<&f64> for DVec2 {
1336 #[inline]
1337 fn div_assign(&mut self, rhs: &f64) {
1338 self.div_assign(*rhs);
1339 }
1340}
1341
1342impl Div<DVec2> for f64 {
1343 type Output = DVec2;
1344 #[inline]
1345 fn div(self, rhs: DVec2) -> DVec2 {
1346 DVec2::new(self.div(rhs.x), self.div(rhs.y))
1347 }
1348}
1349
1350impl Div<&DVec2> for f64 {
1351 type Output = DVec2;
1352 #[inline]
1353 fn div(self, rhs: &DVec2) -> DVec2 {
1354 self.div(*rhs)
1355 }
1356}
1357
1358impl Div<&DVec2> for &f64 {
1359 type Output = DVec2;
1360 #[inline]
1361 fn div(self, rhs: &DVec2) -> DVec2 {
1362 (*self).div(*rhs)
1363 }
1364}
1365
1366impl Div<DVec2> for &f64 {
1367 type Output = DVec2;
1368 #[inline]
1369 fn div(self, rhs: DVec2) -> DVec2 {
1370 (*self).div(rhs)
1371 }
1372}
1373
1374impl Mul for DVec2 {
1375 type Output = Self;
1376 #[inline]
1377 fn mul(self, rhs: Self) -> Self {
1378 Self::new(self.x.mul(rhs.x), self.y.mul(rhs.y))
1379 }
1380}
1381
1382impl Mul<&Self> for DVec2 {
1383 type Output = Self;
1384 #[inline]
1385 fn mul(self, rhs: &Self) -> Self {
1386 self.mul(*rhs)
1387 }
1388}
1389
1390impl Mul<&DVec2> for &DVec2 {
1391 type Output = DVec2;
1392 #[inline]
1393 fn mul(self, rhs: &DVec2) -> DVec2 {
1394 (*self).mul(*rhs)
1395 }
1396}
1397
1398impl Mul<DVec2> for &DVec2 {
1399 type Output = DVec2;
1400 #[inline]
1401 fn mul(self, rhs: DVec2) -> DVec2 {
1402 (*self).mul(rhs)
1403 }
1404}
1405
1406impl MulAssign for DVec2 {
1407 #[inline]
1408 fn mul_assign(&mut self, rhs: Self) {
1409 self.x.mul_assign(rhs.x);
1410 self.y.mul_assign(rhs.y);
1411 }
1412}
1413
1414impl MulAssign<&Self> for DVec2 {
1415 #[inline]
1416 fn mul_assign(&mut self, rhs: &Self) {
1417 self.mul_assign(*rhs);
1418 }
1419}
1420
1421impl Mul<f64> for DVec2 {
1422 type Output = Self;
1423 #[inline]
1424 fn mul(self, rhs: f64) -> Self {
1425 Self::new(self.x.mul(rhs), self.y.mul(rhs))
1426 }
1427}
1428
1429impl Mul<&f64> for DVec2 {
1430 type Output = Self;
1431 #[inline]
1432 fn mul(self, rhs: &f64) -> Self {
1433 self.mul(*rhs)
1434 }
1435}
1436
1437impl Mul<&f64> for &DVec2 {
1438 type Output = DVec2;
1439 #[inline]
1440 fn mul(self, rhs: &f64) -> DVec2 {
1441 (*self).mul(*rhs)
1442 }
1443}
1444
1445impl Mul<f64> for &DVec2 {
1446 type Output = DVec2;
1447 #[inline]
1448 fn mul(self, rhs: f64) -> DVec2 {
1449 (*self).mul(rhs)
1450 }
1451}
1452
1453impl MulAssign<f64> for DVec2 {
1454 #[inline]
1455 fn mul_assign(&mut self, rhs: f64) {
1456 self.x.mul_assign(rhs);
1457 self.y.mul_assign(rhs);
1458 }
1459}
1460
1461impl MulAssign<&f64> for DVec2 {
1462 #[inline]
1463 fn mul_assign(&mut self, rhs: &f64) {
1464 self.mul_assign(*rhs);
1465 }
1466}
1467
1468impl Mul<DVec2> for f64 {
1469 type Output = DVec2;
1470 #[inline]
1471 fn mul(self, rhs: DVec2) -> DVec2 {
1472 DVec2::new(self.mul(rhs.x), self.mul(rhs.y))
1473 }
1474}
1475
1476impl Mul<&DVec2> for f64 {
1477 type Output = DVec2;
1478 #[inline]
1479 fn mul(self, rhs: &DVec2) -> DVec2 {
1480 self.mul(*rhs)
1481 }
1482}
1483
1484impl Mul<&DVec2> for &f64 {
1485 type Output = DVec2;
1486 #[inline]
1487 fn mul(self, rhs: &DVec2) -> DVec2 {
1488 (*self).mul(*rhs)
1489 }
1490}
1491
1492impl Mul<DVec2> for &f64 {
1493 type Output = DVec2;
1494 #[inline]
1495 fn mul(self, rhs: DVec2) -> DVec2 {
1496 (*self).mul(rhs)
1497 }
1498}
1499
1500impl Add for DVec2 {
1501 type Output = Self;
1502 #[inline]
1503 fn add(self, rhs: Self) -> Self {
1504 Self::new(self.x.add(rhs.x), self.y.add(rhs.y))
1505 }
1506}
1507
1508impl Add<&Self> for DVec2 {
1509 type Output = Self;
1510 #[inline]
1511 fn add(self, rhs: &Self) -> Self {
1512 self.add(*rhs)
1513 }
1514}
1515
1516impl Add<&DVec2> for &DVec2 {
1517 type Output = DVec2;
1518 #[inline]
1519 fn add(self, rhs: &DVec2) -> DVec2 {
1520 (*self).add(*rhs)
1521 }
1522}
1523
1524impl Add<DVec2> for &DVec2 {
1525 type Output = DVec2;
1526 #[inline]
1527 fn add(self, rhs: DVec2) -> DVec2 {
1528 (*self).add(rhs)
1529 }
1530}
1531
1532impl AddAssign for DVec2 {
1533 #[inline]
1534 fn add_assign(&mut self, rhs: Self) {
1535 self.x.add_assign(rhs.x);
1536 self.y.add_assign(rhs.y);
1537 }
1538}
1539
1540impl AddAssign<&Self> for DVec2 {
1541 #[inline]
1542 fn add_assign(&mut self, rhs: &Self) {
1543 self.add_assign(*rhs);
1544 }
1545}
1546
1547impl Add<f64> for DVec2 {
1548 type Output = Self;
1549 #[inline]
1550 fn add(self, rhs: f64) -> Self {
1551 Self::new(self.x.add(rhs), self.y.add(rhs))
1552 }
1553}
1554
1555impl Add<&f64> for DVec2 {
1556 type Output = Self;
1557 #[inline]
1558 fn add(self, rhs: &f64) -> Self {
1559 self.add(*rhs)
1560 }
1561}
1562
1563impl Add<&f64> for &DVec2 {
1564 type Output = DVec2;
1565 #[inline]
1566 fn add(self, rhs: &f64) -> DVec2 {
1567 (*self).add(*rhs)
1568 }
1569}
1570
1571impl Add<f64> for &DVec2 {
1572 type Output = DVec2;
1573 #[inline]
1574 fn add(self, rhs: f64) -> DVec2 {
1575 (*self).add(rhs)
1576 }
1577}
1578
1579impl AddAssign<f64> for DVec2 {
1580 #[inline]
1581 fn add_assign(&mut self, rhs: f64) {
1582 self.x.add_assign(rhs);
1583 self.y.add_assign(rhs);
1584 }
1585}
1586
1587impl AddAssign<&f64> for DVec2 {
1588 #[inline]
1589 fn add_assign(&mut self, rhs: &f64) {
1590 self.add_assign(*rhs);
1591 }
1592}
1593
1594impl Add<DVec2> for f64 {
1595 type Output = DVec2;
1596 #[inline]
1597 fn add(self, rhs: DVec2) -> DVec2 {
1598 DVec2::new(self.add(rhs.x), self.add(rhs.y))
1599 }
1600}
1601
1602impl Add<&DVec2> for f64 {
1603 type Output = DVec2;
1604 #[inline]
1605 fn add(self, rhs: &DVec2) -> DVec2 {
1606 self.add(*rhs)
1607 }
1608}
1609
1610impl Add<&DVec2> for &f64 {
1611 type Output = DVec2;
1612 #[inline]
1613 fn add(self, rhs: &DVec2) -> DVec2 {
1614 (*self).add(*rhs)
1615 }
1616}
1617
1618impl Add<DVec2> for &f64 {
1619 type Output = DVec2;
1620 #[inline]
1621 fn add(self, rhs: DVec2) -> DVec2 {
1622 (*self).add(rhs)
1623 }
1624}
1625
1626impl Sub for DVec2 {
1627 type Output = Self;
1628 #[inline]
1629 fn sub(self, rhs: Self) -> Self {
1630 Self::new(self.x.sub(rhs.x), self.y.sub(rhs.y))
1631 }
1632}
1633
1634impl Sub<&Self> for DVec2 {
1635 type Output = Self;
1636 #[inline]
1637 fn sub(self, rhs: &Self) -> Self {
1638 self.sub(*rhs)
1639 }
1640}
1641
1642impl Sub<&DVec2> for &DVec2 {
1643 type Output = DVec2;
1644 #[inline]
1645 fn sub(self, rhs: &DVec2) -> DVec2 {
1646 (*self).sub(*rhs)
1647 }
1648}
1649
1650impl Sub<DVec2> for &DVec2 {
1651 type Output = DVec2;
1652 #[inline]
1653 fn sub(self, rhs: DVec2) -> DVec2 {
1654 (*self).sub(rhs)
1655 }
1656}
1657
1658impl SubAssign for DVec2 {
1659 #[inline]
1660 fn sub_assign(&mut self, rhs: Self) {
1661 self.x.sub_assign(rhs.x);
1662 self.y.sub_assign(rhs.y);
1663 }
1664}
1665
1666impl SubAssign<&Self> for DVec2 {
1667 #[inline]
1668 fn sub_assign(&mut self, rhs: &Self) {
1669 self.sub_assign(*rhs);
1670 }
1671}
1672
1673impl Sub<f64> for DVec2 {
1674 type Output = Self;
1675 #[inline]
1676 fn sub(self, rhs: f64) -> Self {
1677 Self::new(self.x.sub(rhs), self.y.sub(rhs))
1678 }
1679}
1680
1681impl Sub<&f64> for DVec2 {
1682 type Output = Self;
1683 #[inline]
1684 fn sub(self, rhs: &f64) -> Self {
1685 self.sub(*rhs)
1686 }
1687}
1688
1689impl Sub<&f64> for &DVec2 {
1690 type Output = DVec2;
1691 #[inline]
1692 fn sub(self, rhs: &f64) -> DVec2 {
1693 (*self).sub(*rhs)
1694 }
1695}
1696
1697impl Sub<f64> for &DVec2 {
1698 type Output = DVec2;
1699 #[inline]
1700 fn sub(self, rhs: f64) -> DVec2 {
1701 (*self).sub(rhs)
1702 }
1703}
1704
1705impl SubAssign<f64> for DVec2 {
1706 #[inline]
1707 fn sub_assign(&mut self, rhs: f64) {
1708 self.x.sub_assign(rhs);
1709 self.y.sub_assign(rhs);
1710 }
1711}
1712
1713impl SubAssign<&f64> for DVec2 {
1714 #[inline]
1715 fn sub_assign(&mut self, rhs: &f64) {
1716 self.sub_assign(*rhs);
1717 }
1718}
1719
1720impl Sub<DVec2> for f64 {
1721 type Output = DVec2;
1722 #[inline]
1723 fn sub(self, rhs: DVec2) -> DVec2 {
1724 DVec2::new(self.sub(rhs.x), self.sub(rhs.y))
1725 }
1726}
1727
1728impl Sub<&DVec2> for f64 {
1729 type Output = DVec2;
1730 #[inline]
1731 fn sub(self, rhs: &DVec2) -> DVec2 {
1732 self.sub(*rhs)
1733 }
1734}
1735
1736impl Sub<&DVec2> for &f64 {
1737 type Output = DVec2;
1738 #[inline]
1739 fn sub(self, rhs: &DVec2) -> DVec2 {
1740 (*self).sub(*rhs)
1741 }
1742}
1743
1744impl Sub<DVec2> for &f64 {
1745 type Output = DVec2;
1746 #[inline]
1747 fn sub(self, rhs: DVec2) -> DVec2 {
1748 (*self).sub(rhs)
1749 }
1750}
1751
1752impl Rem for DVec2 {
1753 type Output = Self;
1754 #[inline]
1755 fn rem(self, rhs: Self) -> Self {
1756 Self::new(self.x.rem(rhs.x), self.y.rem(rhs.y))
1757 }
1758}
1759
1760impl Rem<&Self> for DVec2 {
1761 type Output = Self;
1762 #[inline]
1763 fn rem(self, rhs: &Self) -> Self {
1764 self.rem(*rhs)
1765 }
1766}
1767
1768impl Rem<&DVec2> for &DVec2 {
1769 type Output = DVec2;
1770 #[inline]
1771 fn rem(self, rhs: &DVec2) -> DVec2 {
1772 (*self).rem(*rhs)
1773 }
1774}
1775
1776impl Rem<DVec2> for &DVec2 {
1777 type Output = DVec2;
1778 #[inline]
1779 fn rem(self, rhs: DVec2) -> DVec2 {
1780 (*self).rem(rhs)
1781 }
1782}
1783
1784impl RemAssign for DVec2 {
1785 #[inline]
1786 fn rem_assign(&mut self, rhs: Self) {
1787 self.x.rem_assign(rhs.x);
1788 self.y.rem_assign(rhs.y);
1789 }
1790}
1791
1792impl RemAssign<&Self> for DVec2 {
1793 #[inline]
1794 fn rem_assign(&mut self, rhs: &Self) {
1795 self.rem_assign(*rhs);
1796 }
1797}
1798
1799impl Rem<f64> for DVec2 {
1800 type Output = Self;
1801 #[inline]
1802 fn rem(self, rhs: f64) -> Self {
1803 Self::new(self.x.rem(rhs), self.y.rem(rhs))
1804 }
1805}
1806
1807impl Rem<&f64> for DVec2 {
1808 type Output = Self;
1809 #[inline]
1810 fn rem(self, rhs: &f64) -> Self {
1811 self.rem(*rhs)
1812 }
1813}
1814
1815impl Rem<&f64> for &DVec2 {
1816 type Output = DVec2;
1817 #[inline]
1818 fn rem(self, rhs: &f64) -> DVec2 {
1819 (*self).rem(*rhs)
1820 }
1821}
1822
1823impl Rem<f64> for &DVec2 {
1824 type Output = DVec2;
1825 #[inline]
1826 fn rem(self, rhs: f64) -> DVec2 {
1827 (*self).rem(rhs)
1828 }
1829}
1830
1831impl RemAssign<f64> for DVec2 {
1832 #[inline]
1833 fn rem_assign(&mut self, rhs: f64) {
1834 self.x.rem_assign(rhs);
1835 self.y.rem_assign(rhs);
1836 }
1837}
1838
1839impl RemAssign<&f64> for DVec2 {
1840 #[inline]
1841 fn rem_assign(&mut self, rhs: &f64) {
1842 self.rem_assign(*rhs);
1843 }
1844}
1845
1846impl Rem<DVec2> for f64 {
1847 type Output = DVec2;
1848 #[inline]
1849 fn rem(self, rhs: DVec2) -> DVec2 {
1850 DVec2::new(self.rem(rhs.x), self.rem(rhs.y))
1851 }
1852}
1853
1854impl Rem<&DVec2> for f64 {
1855 type Output = DVec2;
1856 #[inline]
1857 fn rem(self, rhs: &DVec2) -> DVec2 {
1858 self.rem(*rhs)
1859 }
1860}
1861
1862impl Rem<&DVec2> for &f64 {
1863 type Output = DVec2;
1864 #[inline]
1865 fn rem(self, rhs: &DVec2) -> DVec2 {
1866 (*self).rem(*rhs)
1867 }
1868}
1869
1870impl Rem<DVec2> for &f64 {
1871 type Output = DVec2;
1872 #[inline]
1873 fn rem(self, rhs: DVec2) -> DVec2 {
1874 (*self).rem(rhs)
1875 }
1876}
1877
1878impl AsRef<[f64; 2]> for DVec2 {
1879 #[inline]
1880 fn as_ref(&self) -> &[f64; 2] {
1881 unsafe { &*(self as *const Self as *const [f64; 2]) }
1882 }
1883}
1884
1885impl AsMut<[f64; 2]> for DVec2 {
1886 #[inline]
1887 fn as_mut(&mut self) -> &mut [f64; 2] {
1888 unsafe { &mut *(self as *mut Self as *mut [f64; 2]) }
1889 }
1890}
1891
1892impl Sum for DVec2 {
1893 #[inline]
1894 fn sum<I>(iter: I) -> Self
1895 where
1896 I: Iterator<Item = Self>,
1897 {
1898 iter.fold(Self::ZERO, Self::add)
1899 }
1900}
1901
1902impl<'a> Sum<&'a Self> for DVec2 {
1903 #[inline]
1904 fn sum<I>(iter: I) -> Self
1905 where
1906 I: Iterator<Item = &'a Self>,
1907 {
1908 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1909 }
1910}
1911
1912impl Product for DVec2 {
1913 #[inline]
1914 fn product<I>(iter: I) -> Self
1915 where
1916 I: Iterator<Item = Self>,
1917 {
1918 iter.fold(Self::ONE, Self::mul)
1919 }
1920}
1921
1922impl<'a> Product<&'a Self> for DVec2 {
1923 #[inline]
1924 fn product<I>(iter: I) -> Self
1925 where
1926 I: Iterator<Item = &'a Self>,
1927 {
1928 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1929 }
1930}
1931
1932impl Neg for DVec2 {
1933 type Output = Self;
1934 #[inline]
1935 fn neg(self) -> Self {
1936 Self::new(self.x.neg(), self.y.neg())
1937 }
1938}
1939
1940impl Neg for &DVec2 {
1941 type Output = DVec2;
1942 #[inline]
1943 fn neg(self) -> DVec2 {
1944 (*self).neg()
1945 }
1946}
1947
1948impl Index<usize> for DVec2 {
1949 type Output = f64;
1950 #[inline]
1951 #[track_caller]
1952 fn index(&self, index: usize) -> &Self::Output {
1953 match index {
1954 0 => &self.x,
1955 1 => &self.y,
1956 _ => panic!("index out of bounds"),
1957 }
1958 }
1959}
1960
1961impl IndexMut<usize> for DVec2 {
1962 #[inline]
1963 #[track_caller]
1964 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1965 match index {
1966 0 => &mut self.x,
1967 1 => &mut self.y,
1968 _ => panic!("index out of bounds"),
1969 }
1970 }
1971}
1972
1973impl fmt::Display for DVec2 {
1974 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1975 if let Some(p) = f.precision() {
1976 write!(f, "[{:.*}, {:.*}]", p, self.x, p, self.y)
1977 } else {
1978 write!(f, "[{}, {}]", self.x, self.y)
1979 }
1980 }
1981}
1982
1983impl fmt::Debug for DVec2 {
1984 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1985 fmt.debug_tuple(stringify!(DVec2))
1986 .field(&self.x)
1987 .field(&self.y)
1988 .finish()
1989 }
1990}
1991
1992impl From<[f64; 2]> for DVec2 {
1993 #[inline]
1994 fn from(a: [f64; 2]) -> Self {
1995 Self::new(a[0], a[1])
1996 }
1997}
1998
1999impl From<DVec2> for [f64; 2] {
2000 #[inline]
2001 fn from(v: DVec2) -> Self {
2002 [v.x, v.y]
2003 }
2004}
2005
2006impl From<(f64, f64)> for DVec2 {
2007 #[inline]
2008 fn from(t: (f64, f64)) -> Self {
2009 Self::new(t.0, t.1)
2010 }
2011}
2012
2013impl From<DVec2> for (f64, f64) {
2014 #[inline]
2015 fn from(v: DVec2) -> Self {
2016 (v.x, v.y)
2017 }
2018}
2019
2020impl From<Vec2> for DVec2 {
2021 #[inline]
2022 fn from(v: Vec2) -> Self {
2023 Self::new(f64::from(v.x), f64::from(v.y))
2024 }
2025}
2026
2027#[cfg(feature = "i32")]
2028impl From<IVec2> for DVec2 {
2029 #[inline]
2030 fn from(v: IVec2) -> Self {
2031 Self::new(f64::from(v.x), f64::from(v.y))
2032 }
2033}
2034
2035#[cfg(feature = "u32")]
2036impl From<UVec2> for DVec2 {
2037 #[inline]
2038 fn from(v: UVec2) -> Self {
2039 Self::new(f64::from(v.x), f64::from(v.y))
2040 }
2041}
2042
2043impl From<BVec2> for DVec2 {
2044 #[inline]
2045 fn from(v: BVec2) -> Self {
2046 Self::new(f64::from(v.x), f64::from(v.y))
2047 }
2048}