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