1use crate::{f64::math, BVec2, DVec3};
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 #[deprecated(since = "0.31.0", note = "Renamed to USES_WASM_SIMD")]
93 pub const USES_WASM32_SIMD: bool = false;
94
95 #[inline(always)]
97 #[must_use]
98 pub const fn new(x: f64, y: f64) -> Self {
99 Self { x, y }
100 }
101
102 #[inline]
104 #[must_use]
105 pub const fn splat(v: f64) -> Self {
106 Self::new(v, v)
107 }
108
109 #[inline]
111 #[must_use]
112 pub fn map<F>(self, mut f: F) -> Self
113 where
114 F: FnMut(f64) -> f64,
115 {
116 Self::new(f(self.x), f(self.y))
117 }
118
119 #[inline]
125 #[must_use]
126 pub fn select(mask: BVec2, if_true: Self, if_false: Self) -> Self {
127 Self::new(
128 if mask.test(0) { if_true.x } else { if_false.x },
129 if mask.test(1) { if_true.y } else { if_false.y },
130 )
131 }
132
133 #[inline]
135 #[must_use]
136 pub const fn from_array(a: [f64; 2]) -> Self {
137 Self::new(a[0], a[1])
138 }
139
140 #[inline]
142 #[must_use]
143 pub const fn to_array(&self) -> [f64; 2] {
144 [self.x, self.y]
145 }
146
147 #[inline]
153 #[must_use]
154 #[track_caller]
155 pub const fn from_slice(slice: &[f64]) -> Self {
156 assert!(slice.len() >= 2);
157 Self::new(slice[0], slice[1])
158 }
159
160 #[inline]
166 #[track_caller]
167 pub fn write_to_slice(self, slice: &mut [f64]) {
168 slice[..2].copy_from_slice(&self.to_array());
169 }
170
171 #[inline]
173 #[must_use]
174 pub const fn extend(self, z: f64) -> DVec3 {
175 DVec3::new(self.x, self.y, z)
176 }
177
178 #[inline]
180 #[must_use]
181 pub fn with_x(mut self, x: f64) -> Self {
182 self.x = x;
183 self
184 }
185
186 #[inline]
188 #[must_use]
189 pub fn with_y(mut self, y: f64) -> Self {
190 self.y = y;
191 self
192 }
193
194 #[inline]
196 #[must_use]
197 pub fn dot(self, rhs: Self) -> f64 {
198 (self.x * rhs.x) + (self.y * rhs.y)
199 }
200
201 #[inline]
203 #[must_use]
204 pub fn dot_into_vec(self, rhs: Self) -> Self {
205 Self::splat(self.dot(rhs))
206 }
207
208 #[inline]
215 #[must_use]
216 pub fn min(self, rhs: Self) -> Self {
217 Self::new(
218 if self.x < rhs.x { self.x } else { rhs.x },
219 if self.y < rhs.y { self.y } else { rhs.y },
220 )
221 }
222
223 #[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]
249 #[must_use]
250 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
251 pub fn clamp(self, min: Self, max: Self) -> Self {
252 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
253 self.max(min).min(max)
254 }
255
256 #[inline]
263 #[must_use]
264 pub fn min_element(self) -> f64 {
265 let min = |a, b| if a < b { a } else { b };
266 min(self.x, self.y)
267 }
268
269 #[inline]
276 #[must_use]
277 pub fn max_element(self) -> f64 {
278 let max = |a, b| if a > b { a } else { b };
279 max(self.x, self.y)
280 }
281
282 #[doc(alias = "argmin")]
284 #[inline]
285 #[must_use]
286 pub fn min_position(self) -> usize {
287 if self.x <= self.y {
288 0
289 } else {
290 1
291 }
292 }
293
294 #[doc(alias = "argmax")]
296 #[inline]
297 #[must_use]
298 pub fn max_position(self) -> usize {
299 if self.x >= self.y {
300 0
301 } else {
302 1
303 }
304 }
305
306 #[inline]
310 #[must_use]
311 pub fn element_sum(self) -> f64 {
312 self.x + self.y
313 }
314
315 #[inline]
319 #[must_use]
320 pub fn element_product(self) -> f64 {
321 self.x * self.y
322 }
323
324 #[inline]
330 #[must_use]
331 pub fn cmpeq(self, rhs: Self) -> BVec2 {
332 BVec2::new(self.x.eq(&rhs.x), self.y.eq(&rhs.y))
333 }
334
335 #[inline]
341 #[must_use]
342 pub fn cmpne(self, rhs: Self) -> BVec2 {
343 BVec2::new(self.x.ne(&rhs.x), self.y.ne(&rhs.y))
344 }
345
346 #[inline]
352 #[must_use]
353 pub fn cmpge(self, rhs: Self) -> BVec2 {
354 BVec2::new(self.x.ge(&rhs.x), self.y.ge(&rhs.y))
355 }
356
357 #[inline]
363 #[must_use]
364 pub fn cmpgt(self, rhs: Self) -> BVec2 {
365 BVec2::new(self.x.gt(&rhs.x), self.y.gt(&rhs.y))
366 }
367
368 #[inline]
374 #[must_use]
375 pub fn cmple(self, rhs: Self) -> BVec2 {
376 BVec2::new(self.x.le(&rhs.x), self.y.le(&rhs.y))
377 }
378
379 #[inline]
385 #[must_use]
386 pub fn cmplt(self, rhs: Self) -> BVec2 {
387 BVec2::new(self.x.lt(&rhs.x), self.y.lt(&rhs.y))
388 }
389
390 #[inline]
392 #[must_use]
393 pub fn abs(self) -> Self {
394 Self::new(math::abs(self.x), math::abs(self.y))
395 }
396
397 #[inline]
403 #[must_use]
404 pub fn signum(self) -> Self {
405 Self::new(math::signum(self.x), math::signum(self.y))
406 }
407
408 #[inline]
410 #[must_use]
411 pub fn copysign(self, rhs: Self) -> Self {
412 Self::new(math::copysign(self.x, rhs.x), math::copysign(self.y, rhs.y))
413 }
414
415 #[inline]
423 #[must_use]
424 pub fn is_negative_bitmask(self) -> u32 {
425 (self.x.is_sign_negative() as u32) | ((self.y.is_sign_negative() as u32) << 1)
426 }
427
428 #[inline]
433 #[must_use]
434 pub fn is_negative_mask(self) -> BVec2 {
435 BVec2::new(self.x.is_sign_negative(), self.y.is_sign_negative())
436 }
437
438 #[inline]
441 #[must_use]
442 pub fn is_finite(self) -> bool {
443 self.x.is_finite() && self.y.is_finite()
444 }
445
446 #[inline]
450 #[must_use]
451 pub fn is_finite_mask(self) -> BVec2 {
452 BVec2::new(self.x.is_finite(), self.y.is_finite())
453 }
454
455 #[inline]
457 #[must_use]
458 pub fn is_nan(self) -> bool {
459 self.x.is_nan() || self.y.is_nan()
460 }
461
462 #[inline]
466 #[must_use]
467 pub fn is_nan_mask(self) -> BVec2 {
468 BVec2::new(self.x.is_nan(), self.y.is_nan())
469 }
470
471 #[doc(alias = "magnitude")]
473 #[inline]
474 #[must_use]
475 pub fn length(self) -> f64 {
476 math::sqrt(self.dot(self))
477 }
478
479 #[allow(dead_code)]
481 fn is_non_zero(self) -> bool {
482 self.length_squared() > 0.0
483 }
484
485 #[doc(alias = "magnitude2")]
489 #[inline]
490 #[must_use]
491 pub fn length_squared(self) -> f64 {
492 self.dot(self)
493 }
494
495 #[inline]
499 #[must_use]
500 pub fn length_recip(self) -> f64 {
501 1.0 / self.length()
502 }
503
504 #[inline]
506 #[must_use]
507 pub fn distance(self, rhs: Self) -> f64 {
508 (self - rhs).length()
509 }
510
511 #[inline]
513 #[must_use]
514 pub fn distance_squared(self, rhs: Self) -> f64 {
515 (self - rhs).length_squared()
516 }
517
518 #[inline]
520 #[must_use]
521 pub fn div_euclid(self, rhs: Self) -> Self {
522 Self::new(
523 math::div_euclid(self.x, rhs.x),
524 math::div_euclid(self.y, rhs.y),
525 )
526 }
527
528 #[inline]
532 #[must_use]
533 pub fn rem_euclid(self, rhs: Self) -> Self {
534 Self::new(
535 math::rem_euclid(self.x, rhs.x),
536 math::rem_euclid(self.y, rhs.y),
537 )
538 }
539
540 #[inline]
550 #[must_use]
551 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
552 pub fn normalize(self) -> Self {
553 #[allow(clippy::let_and_return)]
554 let normalized = self.mul(self.length_recip());
555 glam_assert!(normalized.is_finite());
556 normalized
557 }
558
559 #[inline]
566 #[must_use]
567 pub fn try_normalize(self) -> Option<Self> {
568 let rcp = self.length_recip();
569 if rcp.is_finite() && rcp > 0.0 {
570 Some(self * rcp)
571 } else {
572 None
573 }
574 }
575
576 #[inline]
584 #[must_use]
585 pub fn normalize_or(self, fallback: Self) -> Self {
586 let rcp = self.length_recip();
587 if rcp.is_finite() && rcp > 0.0 {
588 self * rcp
589 } else {
590 fallback
591 }
592 }
593
594 #[inline]
601 #[must_use]
602 pub fn normalize_or_zero(self) -> Self {
603 self.normalize_or(Self::ZERO)
604 }
605
606 #[inline]
610 #[must_use]
611 pub fn normalize_and_length(self) -> (Self, f64) {
612 let length = self.length();
613 let rcp = 1.0 / length;
614 if rcp.is_finite() && rcp > 0.0 {
615 (self * rcp, length)
616 } else {
617 (Self::X, 0.0)
618 }
619 }
620
621 #[inline]
625 #[must_use]
626 pub fn is_normalized(self) -> bool {
627 math::abs(self.length_squared() - 1.0) <= 2e-4
628 }
629
630 #[inline]
638 #[must_use]
639 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
640 pub fn project_onto(self, rhs: Self) -> Self {
641 let rhs_len_sq = rhs.dot(rhs);
642 glam_assert!(rhs_len_sq != 0.0);
643 rhs * (self.dot(rhs) / rhs_len_sq)
644 }
645
646 #[doc(alias("plane"))]
657 #[inline]
658 #[must_use]
659 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
660 pub fn reject_from(self, rhs: Self) -> Self {
661 self - self.project_onto(rhs)
662 }
663
664 #[inline]
672 #[must_use]
673 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
674 pub fn project_onto_normalized(self, rhs: Self) -> Self {
675 glam_assert!(rhs.is_normalized());
676 rhs * self.dot(rhs)
677 }
678
679 #[doc(alias("plane"))]
690 #[inline]
691 #[must_use]
692 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
693 pub fn reject_from_normalized(self, rhs: Self) -> Self {
694 self - self.project_onto_normalized(rhs)
695 }
696
697 #[inline]
700 #[must_use]
701 pub fn round(self) -> Self {
702 Self::new(math::round(self.x), math::round(self.y))
703 }
704
705 #[inline]
708 #[must_use]
709 pub fn floor(self) -> Self {
710 Self::new(math::floor(self.x), math::floor(self.y))
711 }
712
713 #[inline]
716 #[must_use]
717 pub fn ceil(self) -> Self {
718 Self::new(math::ceil(self.x), math::ceil(self.y))
719 }
720
721 #[inline]
724 #[must_use]
725 pub fn trunc(self) -> Self {
726 Self::new(math::trunc(self.x), math::trunc(self.y))
727 }
728
729 #[inline]
733 #[must_use]
734 pub fn step(self, rhs: Self) -> Self {
735 Self::select(rhs.cmplt(self), Self::ZERO, Self::ONE)
736 }
737
738 #[inline]
749 #[must_use]
750 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
751 pub fn smoothstep(self, edge0: Self, edge1: Self) -> Self {
752 glam_assert!(edge0.cmplt(edge1).all());
753 let t = ((self - edge0) / (edge1 - edge0)).saturate();
754 t * t * (Self::splat(3.0) - Self::splat(2.0) * t)
755 }
756
757 #[inline]
759 #[must_use]
760 pub fn saturate(self) -> Self {
761 self.clamp(Self::ZERO, Self::ONE)
762 }
763
764 #[inline]
771 #[must_use]
772 pub fn fract(self) -> Self {
773 self - self.trunc()
774 }
775
776 #[inline]
783 #[must_use]
784 pub fn fract_gl(self) -> Self {
785 self - self.floor()
786 }
787
788 #[inline]
791 #[must_use]
792 pub fn exp(self) -> Self {
793 Self::new(math::exp(self.x), math::exp(self.y))
794 }
795
796 #[inline]
798 #[must_use]
799 pub fn exp2(self) -> Self {
800 Self::new(math::exp2(self.x), math::exp2(self.y))
801 }
802
803 #[inline]
806 #[must_use]
807 pub fn ln(self) -> Self {
808 Self::new(math::ln(self.x), math::ln(self.y))
809 }
810
811 #[inline]
814 #[must_use]
815 pub fn log2(self) -> Self {
816 Self::new(math::log2(self.x), math::log2(self.y))
817 }
818
819 #[inline]
821 #[must_use]
822 pub fn powf(self, n: f64) -> Self {
823 Self::new(math::powf(self.x, n), math::powf(self.y, n))
824 }
825
826 #[inline]
829 #[must_use]
830 pub fn sqrt(self) -> Self {
831 Self::new(math::sqrt(self.x), math::sqrt(self.y))
832 }
833
834 #[inline]
836 #[must_use]
837 pub fn cos(self) -> Self {
838 Self::new(math::cos(self.x), math::cos(self.y))
839 }
840
841 #[inline]
843 #[must_use]
844 pub fn sin(self) -> Self {
845 Self::new(math::sin(self.x), math::sin(self.y))
846 }
847
848 #[inline]
850 #[must_use]
851 pub fn sin_cos(self) -> (Self, Self) {
852 let (sin_x, cos_x) = math::sin_cos(self.x);
853 let (sin_y, cos_y) = math::sin_cos(self.y);
854
855 (Self::new(sin_x, sin_y), Self::new(cos_x, cos_y))
856 }
857
858 #[inline]
860 #[must_use]
861 pub fn recip(self) -> Self {
862 Self::new(1.0 / self.x, 1.0 / self.y)
863 }
864
865 #[doc(alias = "mix")]
877 #[inline]
878 #[must_use]
879 pub fn lerp(self, rhs: Self, s: f64) -> Self {
880 self * (1.0 - s) + rhs * s
881 }
882
883 #[doc(alias = "mix")]
900 #[inline]
901 #[must_use]
902 pub fn lerp_monotonic(self, rhs: Self, s: f64) -> Self {
903 self + (rhs - self) * s
904 }
905
906 #[inline]
911 #[must_use]
912 pub fn move_towards(self, rhs: Self, d: f64) -> Self {
913 let a = rhs - self;
914 let len = a.length();
915 if len <= d || len <= 1e-4 {
916 return rhs;
917 }
918 self + a / len * d
919 }
920
921 #[inline]
927 pub fn midpoint(self, rhs: Self) -> Self {
928 (self + rhs) * 0.5
929 }
930
931 #[inline]
941 #[must_use]
942 pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f64) -> bool {
943 self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
944 }
945
946 #[inline]
952 #[must_use]
953 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
954 pub fn clamp_length(self, min: f64, max: f64) -> Self {
955 glam_assert!(0.0 <= min);
956 glam_assert!(min <= max);
957 let length_sq = self.length_squared();
958 if length_sq < min * min {
959 min * (self / math::sqrt(length_sq))
960 } else if length_sq > max * max {
961 max * (self / math::sqrt(length_sq))
962 } else {
963 self
964 }
965 }
966
967 #[inline]
973 #[must_use]
974 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
975 pub fn clamp_length_max(self, max: f64) -> Self {
976 glam_assert!(0.0 <= max);
977 let length_sq = self.length_squared();
978 if length_sq > max * max {
979 max * (self / math::sqrt(length_sq))
980 } else {
981 self
982 }
983 }
984
985 #[inline]
991 #[must_use]
992 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
993 pub fn clamp_length_min(self, min: f64) -> Self {
994 glam_assert!(0.0 <= min);
995 let length_sq = self.length_squared();
996 if length_sq < min * min {
997 min * (self / math::sqrt(length_sq))
998 } else {
999 self
1000 }
1001 }
1002
1003 #[inline]
1011 #[must_use]
1012 pub fn mul_add(self, a: Self, b: Self) -> Self {
1013 Self::new(
1014 math::mul_add(self.x, a.x, b.x),
1015 math::mul_add(self.y, a.y, b.y),
1016 )
1017 }
1018
1019 #[inline]
1028 #[must_use]
1029 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1030 pub fn reflect(self, normal: Self) -> Self {
1031 glam_assert!(normal.is_normalized());
1032 self - 2.0 * self.dot(normal) * normal
1033 }
1034
1035 #[inline]
1045 #[must_use]
1046 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1047 pub fn refract(self, normal: Self, eta: f64) -> Self {
1048 glam_assert!(self.is_normalized());
1049 glam_assert!(normal.is_normalized());
1050 let n_dot_i = normal.dot(self);
1051 let k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1052 if k >= 0.0 {
1053 eta * self - (eta * n_dot_i + math::sqrt(k)) * normal
1054 } else {
1055 Self::ZERO
1056 }
1057 }
1058
1059 #[inline]
1064 #[must_use]
1065 pub fn from_angle(angle: f64) -> Self {
1066 let (sin, cos) = math::sin_cos(angle);
1067 Self::new(cos, sin)
1068 }
1069
1070 #[inline]
1074 #[must_use]
1075 pub fn to_angle(self) -> f64 {
1076 math::atan2(self.y, self.x)
1077 }
1078
1079 #[inline]
1090 #[must_use]
1091 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1092 pub fn angle_to(self, rhs: Self) -> f64 {
1093 glam_assert!(self.is_non_zero());
1094 glam_assert!(rhs.is_non_zero());
1095 let angle = math::acos_approx(
1096 self.dot(rhs) / math::sqrt(self.length_squared() * rhs.length_squared()),
1097 );
1098
1099 angle * math::signum(self.perp_dot(rhs))
1100 }
1101
1102 #[inline]
1104 #[must_use]
1105 pub fn perp(self) -> Self {
1106 Self::new(-self.y, self.x)
1107 }
1108
1109 #[doc(alias = "wedge")]
1112 #[doc(alias = "cross")]
1113 #[doc(alias = "determinant")]
1114 #[inline]
1115 #[must_use]
1116 pub fn perp_dot(self, rhs: Self) -> f64 {
1117 (self.x * rhs.y) - (self.y * rhs.x)
1118 }
1119
1120 #[inline]
1128 #[must_use]
1129 pub fn rotate(self, rhs: Self) -> Self {
1130 Self::new(
1131 self.x * rhs.x - self.y * rhs.y,
1132 self.y * rhs.x + self.x * rhs.y,
1133 )
1134 }
1135
1136 #[inline]
1139 #[must_use]
1140 pub fn rotate_angle(self, angle: f64) -> Self {
1141 self.rotate(Self::from_angle(angle))
1142 }
1143
1144 #[inline]
1154 #[must_use]
1155 #[cfg_attr(any(debug_assertions, feature = "glam-assert"), track_caller)]
1156 pub fn rotate_towards(self, rhs: Self, max_angle: f64) -> Self {
1157 let a = self.angle_to(rhs);
1158 let abs_a = math::abs(a);
1159 let angle = max_angle.clamp(abs_a - core::f64::consts::PI, abs_a) * math::signum(a);
1161 Self::from_angle(angle).rotate(self)
1162 }
1163
1164 #[inline]
1166 #[must_use]
1167 pub fn as_vec2(self) -> crate::Vec2 {
1168 crate::Vec2::new(self.x as f32, self.y as f32)
1169 }
1170
1171 #[cfg(feature = "i8")]
1173 #[inline]
1174 #[must_use]
1175 pub fn as_i8vec2(self) -> crate::I8Vec2 {
1176 crate::I8Vec2::new(self.x as i8, self.y as i8)
1177 }
1178
1179 #[cfg(feature = "u8")]
1181 #[inline]
1182 #[must_use]
1183 pub fn as_u8vec2(self) -> crate::U8Vec2 {
1184 crate::U8Vec2::new(self.x as u8, self.y as u8)
1185 }
1186
1187 #[cfg(feature = "i16")]
1189 #[inline]
1190 #[must_use]
1191 pub fn as_i16vec2(self) -> crate::I16Vec2 {
1192 crate::I16Vec2::new(self.x as i16, self.y as i16)
1193 }
1194
1195 #[cfg(feature = "u16")]
1197 #[inline]
1198 #[must_use]
1199 pub fn as_u16vec2(self) -> crate::U16Vec2 {
1200 crate::U16Vec2::new(self.x as u16, self.y as u16)
1201 }
1202
1203 #[cfg(feature = "i32")]
1205 #[inline]
1206 #[must_use]
1207 pub fn as_ivec2(self) -> crate::IVec2 {
1208 crate::IVec2::new(self.x as i32, self.y as i32)
1209 }
1210
1211 #[cfg(feature = "u32")]
1213 #[inline]
1214 #[must_use]
1215 pub fn as_uvec2(self) -> crate::UVec2 {
1216 crate::UVec2::new(self.x as u32, self.y as u32)
1217 }
1218
1219 #[cfg(feature = "i64")]
1221 #[inline]
1222 #[must_use]
1223 pub fn as_i64vec2(self) -> crate::I64Vec2 {
1224 crate::I64Vec2::new(self.x as i64, self.y as i64)
1225 }
1226
1227 #[cfg(feature = "u64")]
1229 #[inline]
1230 #[must_use]
1231 pub fn as_u64vec2(self) -> crate::U64Vec2 {
1232 crate::U64Vec2::new(self.x as u64, self.y as u64)
1233 }
1234
1235 #[cfg(feature = "isize")]
1237 #[inline]
1238 #[must_use]
1239 pub fn as_isizevec2(self) -> crate::ISizeVec2 {
1240 crate::ISizeVec2::new(self.x as isize, self.y as isize)
1241 }
1242
1243 #[cfg(feature = "usize")]
1245 #[inline]
1246 #[must_use]
1247 pub fn as_usizevec2(self) -> crate::USizeVec2 {
1248 crate::USizeVec2::new(self.x as usize, self.y as usize)
1249 }
1250}
1251
1252impl Default for DVec2 {
1253 #[inline(always)]
1254 fn default() -> Self {
1255 Self::ZERO
1256 }
1257}
1258
1259impl Div for DVec2 {
1260 type Output = Self;
1261 #[inline]
1262 fn div(self, rhs: Self) -> Self {
1263 Self::new(self.x.div(rhs.x), self.y.div(rhs.y))
1264 }
1265}
1266
1267impl Div<&Self> for DVec2 {
1268 type Output = Self;
1269 #[inline]
1270 fn div(self, rhs: &Self) -> Self {
1271 self.div(*rhs)
1272 }
1273}
1274
1275impl Div<&DVec2> for &DVec2 {
1276 type Output = DVec2;
1277 #[inline]
1278 fn div(self, rhs: &DVec2) -> DVec2 {
1279 (*self).div(*rhs)
1280 }
1281}
1282
1283impl Div<DVec2> for &DVec2 {
1284 type Output = DVec2;
1285 #[inline]
1286 fn div(self, rhs: DVec2) -> DVec2 {
1287 (*self).div(rhs)
1288 }
1289}
1290
1291impl DivAssign for DVec2 {
1292 #[inline]
1293 fn div_assign(&mut self, rhs: Self) {
1294 self.x.div_assign(rhs.x);
1295 self.y.div_assign(rhs.y);
1296 }
1297}
1298
1299impl DivAssign<&Self> for DVec2 {
1300 #[inline]
1301 fn div_assign(&mut self, rhs: &Self) {
1302 self.div_assign(*rhs);
1303 }
1304}
1305
1306impl Div<f64> for DVec2 {
1307 type Output = Self;
1308 #[inline]
1309 fn div(self, rhs: f64) -> Self {
1310 Self::new(self.x.div(rhs), self.y.div(rhs))
1311 }
1312}
1313
1314impl Div<&f64> for DVec2 {
1315 type Output = Self;
1316 #[inline]
1317 fn div(self, rhs: &f64) -> Self {
1318 self.div(*rhs)
1319 }
1320}
1321
1322impl Div<&f64> for &DVec2 {
1323 type Output = DVec2;
1324 #[inline]
1325 fn div(self, rhs: &f64) -> DVec2 {
1326 (*self).div(*rhs)
1327 }
1328}
1329
1330impl Div<f64> for &DVec2 {
1331 type Output = DVec2;
1332 #[inline]
1333 fn div(self, rhs: f64) -> DVec2 {
1334 (*self).div(rhs)
1335 }
1336}
1337
1338impl DivAssign<f64> for DVec2 {
1339 #[inline]
1340 fn div_assign(&mut self, rhs: f64) {
1341 self.x.div_assign(rhs);
1342 self.y.div_assign(rhs);
1343 }
1344}
1345
1346impl DivAssign<&f64> for DVec2 {
1347 #[inline]
1348 fn div_assign(&mut self, rhs: &f64) {
1349 self.div_assign(*rhs);
1350 }
1351}
1352
1353impl Div<DVec2> for f64 {
1354 type Output = DVec2;
1355 #[inline]
1356 fn div(self, rhs: DVec2) -> DVec2 {
1357 DVec2::new(self.div(rhs.x), self.div(rhs.y))
1358 }
1359}
1360
1361impl Div<&DVec2> for f64 {
1362 type Output = DVec2;
1363 #[inline]
1364 fn div(self, rhs: &DVec2) -> DVec2 {
1365 self.div(*rhs)
1366 }
1367}
1368
1369impl Div<&DVec2> for &f64 {
1370 type Output = DVec2;
1371 #[inline]
1372 fn div(self, rhs: &DVec2) -> DVec2 {
1373 (*self).div(*rhs)
1374 }
1375}
1376
1377impl Div<DVec2> for &f64 {
1378 type Output = DVec2;
1379 #[inline]
1380 fn div(self, rhs: DVec2) -> DVec2 {
1381 (*self).div(rhs)
1382 }
1383}
1384
1385impl Mul for DVec2 {
1386 type Output = Self;
1387 #[inline]
1388 fn mul(self, rhs: Self) -> Self {
1389 Self::new(self.x.mul(rhs.x), self.y.mul(rhs.y))
1390 }
1391}
1392
1393impl Mul<&Self> for DVec2 {
1394 type Output = Self;
1395 #[inline]
1396 fn mul(self, rhs: &Self) -> Self {
1397 self.mul(*rhs)
1398 }
1399}
1400
1401impl Mul<&DVec2> for &DVec2 {
1402 type Output = DVec2;
1403 #[inline]
1404 fn mul(self, rhs: &DVec2) -> DVec2 {
1405 (*self).mul(*rhs)
1406 }
1407}
1408
1409impl Mul<DVec2> for &DVec2 {
1410 type Output = DVec2;
1411 #[inline]
1412 fn mul(self, rhs: DVec2) -> DVec2 {
1413 (*self).mul(rhs)
1414 }
1415}
1416
1417impl MulAssign for DVec2 {
1418 #[inline]
1419 fn mul_assign(&mut self, rhs: Self) {
1420 self.x.mul_assign(rhs.x);
1421 self.y.mul_assign(rhs.y);
1422 }
1423}
1424
1425impl MulAssign<&Self> for DVec2 {
1426 #[inline]
1427 fn mul_assign(&mut self, rhs: &Self) {
1428 self.mul_assign(*rhs);
1429 }
1430}
1431
1432impl Mul<f64> for DVec2 {
1433 type Output = Self;
1434 #[inline]
1435 fn mul(self, rhs: f64) -> Self {
1436 Self::new(self.x.mul(rhs), self.y.mul(rhs))
1437 }
1438}
1439
1440impl Mul<&f64> for DVec2 {
1441 type Output = Self;
1442 #[inline]
1443 fn mul(self, rhs: &f64) -> Self {
1444 self.mul(*rhs)
1445 }
1446}
1447
1448impl Mul<&f64> for &DVec2 {
1449 type Output = DVec2;
1450 #[inline]
1451 fn mul(self, rhs: &f64) -> DVec2 {
1452 (*self).mul(*rhs)
1453 }
1454}
1455
1456impl Mul<f64> for &DVec2 {
1457 type Output = DVec2;
1458 #[inline]
1459 fn mul(self, rhs: f64) -> DVec2 {
1460 (*self).mul(rhs)
1461 }
1462}
1463
1464impl MulAssign<f64> for DVec2 {
1465 #[inline]
1466 fn mul_assign(&mut self, rhs: f64) {
1467 self.x.mul_assign(rhs);
1468 self.y.mul_assign(rhs);
1469 }
1470}
1471
1472impl MulAssign<&f64> for DVec2 {
1473 #[inline]
1474 fn mul_assign(&mut self, rhs: &f64) {
1475 self.mul_assign(*rhs);
1476 }
1477}
1478
1479impl Mul<DVec2> for f64 {
1480 type Output = DVec2;
1481 #[inline]
1482 fn mul(self, rhs: DVec2) -> DVec2 {
1483 DVec2::new(self.mul(rhs.x), self.mul(rhs.y))
1484 }
1485}
1486
1487impl Mul<&DVec2> for f64 {
1488 type Output = DVec2;
1489 #[inline]
1490 fn mul(self, rhs: &DVec2) -> DVec2 {
1491 self.mul(*rhs)
1492 }
1493}
1494
1495impl Mul<&DVec2> for &f64 {
1496 type Output = DVec2;
1497 #[inline]
1498 fn mul(self, rhs: &DVec2) -> DVec2 {
1499 (*self).mul(*rhs)
1500 }
1501}
1502
1503impl Mul<DVec2> for &f64 {
1504 type Output = DVec2;
1505 #[inline]
1506 fn mul(self, rhs: DVec2) -> DVec2 {
1507 (*self).mul(rhs)
1508 }
1509}
1510
1511impl Add for DVec2 {
1512 type Output = Self;
1513 #[inline]
1514 fn add(self, rhs: Self) -> Self {
1515 Self::new(self.x.add(rhs.x), self.y.add(rhs.y))
1516 }
1517}
1518
1519impl Add<&Self> for DVec2 {
1520 type Output = Self;
1521 #[inline]
1522 fn add(self, rhs: &Self) -> Self {
1523 self.add(*rhs)
1524 }
1525}
1526
1527impl Add<&DVec2> for &DVec2 {
1528 type Output = DVec2;
1529 #[inline]
1530 fn add(self, rhs: &DVec2) -> DVec2 {
1531 (*self).add(*rhs)
1532 }
1533}
1534
1535impl Add<DVec2> for &DVec2 {
1536 type Output = DVec2;
1537 #[inline]
1538 fn add(self, rhs: DVec2) -> DVec2 {
1539 (*self).add(rhs)
1540 }
1541}
1542
1543impl AddAssign for DVec2 {
1544 #[inline]
1545 fn add_assign(&mut self, rhs: Self) {
1546 self.x.add_assign(rhs.x);
1547 self.y.add_assign(rhs.y);
1548 }
1549}
1550
1551impl AddAssign<&Self> for DVec2 {
1552 #[inline]
1553 fn add_assign(&mut self, rhs: &Self) {
1554 self.add_assign(*rhs);
1555 }
1556}
1557
1558impl Add<f64> for DVec2 {
1559 type Output = Self;
1560 #[inline]
1561 fn add(self, rhs: f64) -> Self {
1562 Self::new(self.x.add(rhs), self.y.add(rhs))
1563 }
1564}
1565
1566impl Add<&f64> for DVec2 {
1567 type Output = Self;
1568 #[inline]
1569 fn add(self, rhs: &f64) -> Self {
1570 self.add(*rhs)
1571 }
1572}
1573
1574impl Add<&f64> for &DVec2 {
1575 type Output = DVec2;
1576 #[inline]
1577 fn add(self, rhs: &f64) -> DVec2 {
1578 (*self).add(*rhs)
1579 }
1580}
1581
1582impl Add<f64> for &DVec2 {
1583 type Output = DVec2;
1584 #[inline]
1585 fn add(self, rhs: f64) -> DVec2 {
1586 (*self).add(rhs)
1587 }
1588}
1589
1590impl AddAssign<f64> for DVec2 {
1591 #[inline]
1592 fn add_assign(&mut self, rhs: f64) {
1593 self.x.add_assign(rhs);
1594 self.y.add_assign(rhs);
1595 }
1596}
1597
1598impl AddAssign<&f64> for DVec2 {
1599 #[inline]
1600 fn add_assign(&mut self, rhs: &f64) {
1601 self.add_assign(*rhs);
1602 }
1603}
1604
1605impl Add<DVec2> for f64 {
1606 type Output = DVec2;
1607 #[inline]
1608 fn add(self, rhs: DVec2) -> DVec2 {
1609 DVec2::new(self.add(rhs.x), self.add(rhs.y))
1610 }
1611}
1612
1613impl Add<&DVec2> for f64 {
1614 type Output = DVec2;
1615 #[inline]
1616 fn add(self, rhs: &DVec2) -> DVec2 {
1617 self.add(*rhs)
1618 }
1619}
1620
1621impl Add<&DVec2> for &f64 {
1622 type Output = DVec2;
1623 #[inline]
1624 fn add(self, rhs: &DVec2) -> DVec2 {
1625 (*self).add(*rhs)
1626 }
1627}
1628
1629impl Add<DVec2> for &f64 {
1630 type Output = DVec2;
1631 #[inline]
1632 fn add(self, rhs: DVec2) -> DVec2 {
1633 (*self).add(rhs)
1634 }
1635}
1636
1637impl Sub for DVec2 {
1638 type Output = Self;
1639 #[inline]
1640 fn sub(self, rhs: Self) -> Self {
1641 Self::new(self.x.sub(rhs.x), self.y.sub(rhs.y))
1642 }
1643}
1644
1645impl Sub<&Self> for DVec2 {
1646 type Output = Self;
1647 #[inline]
1648 fn sub(self, rhs: &Self) -> Self {
1649 self.sub(*rhs)
1650 }
1651}
1652
1653impl Sub<&DVec2> for &DVec2 {
1654 type Output = DVec2;
1655 #[inline]
1656 fn sub(self, rhs: &DVec2) -> DVec2 {
1657 (*self).sub(*rhs)
1658 }
1659}
1660
1661impl Sub<DVec2> for &DVec2 {
1662 type Output = DVec2;
1663 #[inline]
1664 fn sub(self, rhs: DVec2) -> DVec2 {
1665 (*self).sub(rhs)
1666 }
1667}
1668
1669impl SubAssign for DVec2 {
1670 #[inline]
1671 fn sub_assign(&mut self, rhs: Self) {
1672 self.x.sub_assign(rhs.x);
1673 self.y.sub_assign(rhs.y);
1674 }
1675}
1676
1677impl SubAssign<&Self> for DVec2 {
1678 #[inline]
1679 fn sub_assign(&mut self, rhs: &Self) {
1680 self.sub_assign(*rhs);
1681 }
1682}
1683
1684impl Sub<f64> for DVec2 {
1685 type Output = Self;
1686 #[inline]
1687 fn sub(self, rhs: f64) -> Self {
1688 Self::new(self.x.sub(rhs), self.y.sub(rhs))
1689 }
1690}
1691
1692impl Sub<&f64> for DVec2 {
1693 type Output = Self;
1694 #[inline]
1695 fn sub(self, rhs: &f64) -> Self {
1696 self.sub(*rhs)
1697 }
1698}
1699
1700impl Sub<&f64> for &DVec2 {
1701 type Output = DVec2;
1702 #[inline]
1703 fn sub(self, rhs: &f64) -> DVec2 {
1704 (*self).sub(*rhs)
1705 }
1706}
1707
1708impl Sub<f64> for &DVec2 {
1709 type Output = DVec2;
1710 #[inline]
1711 fn sub(self, rhs: f64) -> DVec2 {
1712 (*self).sub(rhs)
1713 }
1714}
1715
1716impl SubAssign<f64> for DVec2 {
1717 #[inline]
1718 fn sub_assign(&mut self, rhs: f64) {
1719 self.x.sub_assign(rhs);
1720 self.y.sub_assign(rhs);
1721 }
1722}
1723
1724impl SubAssign<&f64> for DVec2 {
1725 #[inline]
1726 fn sub_assign(&mut self, rhs: &f64) {
1727 self.sub_assign(*rhs);
1728 }
1729}
1730
1731impl Sub<DVec2> for f64 {
1732 type Output = DVec2;
1733 #[inline]
1734 fn sub(self, rhs: DVec2) -> DVec2 {
1735 DVec2::new(self.sub(rhs.x), self.sub(rhs.y))
1736 }
1737}
1738
1739impl Sub<&DVec2> for f64 {
1740 type Output = DVec2;
1741 #[inline]
1742 fn sub(self, rhs: &DVec2) -> DVec2 {
1743 self.sub(*rhs)
1744 }
1745}
1746
1747impl Sub<&DVec2> for &f64 {
1748 type Output = DVec2;
1749 #[inline]
1750 fn sub(self, rhs: &DVec2) -> DVec2 {
1751 (*self).sub(*rhs)
1752 }
1753}
1754
1755impl Sub<DVec2> for &f64 {
1756 type Output = DVec2;
1757 #[inline]
1758 fn sub(self, rhs: DVec2) -> DVec2 {
1759 (*self).sub(rhs)
1760 }
1761}
1762
1763impl Rem for DVec2 {
1764 type Output = Self;
1765 #[inline]
1766 fn rem(self, rhs: Self) -> Self {
1767 Self::new(self.x.rem(rhs.x), self.y.rem(rhs.y))
1768 }
1769}
1770
1771impl Rem<&Self> for DVec2 {
1772 type Output = Self;
1773 #[inline]
1774 fn rem(self, rhs: &Self) -> Self {
1775 self.rem(*rhs)
1776 }
1777}
1778
1779impl Rem<&DVec2> for &DVec2 {
1780 type Output = DVec2;
1781 #[inline]
1782 fn rem(self, rhs: &DVec2) -> DVec2 {
1783 (*self).rem(*rhs)
1784 }
1785}
1786
1787impl Rem<DVec2> for &DVec2 {
1788 type Output = DVec2;
1789 #[inline]
1790 fn rem(self, rhs: DVec2) -> DVec2 {
1791 (*self).rem(rhs)
1792 }
1793}
1794
1795impl RemAssign for DVec2 {
1796 #[inline]
1797 fn rem_assign(&mut self, rhs: Self) {
1798 self.x.rem_assign(rhs.x);
1799 self.y.rem_assign(rhs.y);
1800 }
1801}
1802
1803impl RemAssign<&Self> for DVec2 {
1804 #[inline]
1805 fn rem_assign(&mut self, rhs: &Self) {
1806 self.rem_assign(*rhs);
1807 }
1808}
1809
1810impl Rem<f64> for DVec2 {
1811 type Output = Self;
1812 #[inline]
1813 fn rem(self, rhs: f64) -> Self {
1814 Self::new(self.x.rem(rhs), self.y.rem(rhs))
1815 }
1816}
1817
1818impl Rem<&f64> for DVec2 {
1819 type Output = Self;
1820 #[inline]
1821 fn rem(self, rhs: &f64) -> Self {
1822 self.rem(*rhs)
1823 }
1824}
1825
1826impl Rem<&f64> for &DVec2 {
1827 type Output = DVec2;
1828 #[inline]
1829 fn rem(self, rhs: &f64) -> DVec2 {
1830 (*self).rem(*rhs)
1831 }
1832}
1833
1834impl Rem<f64> for &DVec2 {
1835 type Output = DVec2;
1836 #[inline]
1837 fn rem(self, rhs: f64) -> DVec2 {
1838 (*self).rem(rhs)
1839 }
1840}
1841
1842impl RemAssign<f64> for DVec2 {
1843 #[inline]
1844 fn rem_assign(&mut self, rhs: f64) {
1845 self.x.rem_assign(rhs);
1846 self.y.rem_assign(rhs);
1847 }
1848}
1849
1850impl RemAssign<&f64> for DVec2 {
1851 #[inline]
1852 fn rem_assign(&mut self, rhs: &f64) {
1853 self.rem_assign(*rhs);
1854 }
1855}
1856
1857impl Rem<DVec2> for f64 {
1858 type Output = DVec2;
1859 #[inline]
1860 fn rem(self, rhs: DVec2) -> DVec2 {
1861 DVec2::new(self.rem(rhs.x), self.rem(rhs.y))
1862 }
1863}
1864
1865impl Rem<&DVec2> for f64 {
1866 type Output = DVec2;
1867 #[inline]
1868 fn rem(self, rhs: &DVec2) -> DVec2 {
1869 self.rem(*rhs)
1870 }
1871}
1872
1873impl Rem<&DVec2> for &f64 {
1874 type Output = DVec2;
1875 #[inline]
1876 fn rem(self, rhs: &DVec2) -> DVec2 {
1877 (*self).rem(*rhs)
1878 }
1879}
1880
1881impl Rem<DVec2> for &f64 {
1882 type Output = DVec2;
1883 #[inline]
1884 fn rem(self, rhs: DVec2) -> DVec2 {
1885 (*self).rem(rhs)
1886 }
1887}
1888
1889impl AsRef<[f64; 2]> for DVec2 {
1890 #[inline]
1891 fn as_ref(&self) -> &[f64; 2] {
1892 unsafe { &*(self as *const Self as *const [f64; 2]) }
1893 }
1894}
1895
1896impl AsMut<[f64; 2]> for DVec2 {
1897 #[inline]
1898 fn as_mut(&mut self) -> &mut [f64; 2] {
1899 unsafe { &mut *(self as *mut Self as *mut [f64; 2]) }
1900 }
1901}
1902
1903impl Sum for DVec2 {
1904 #[inline]
1905 fn sum<I>(iter: I) -> Self
1906 where
1907 I: Iterator<Item = Self>,
1908 {
1909 iter.fold(Self::ZERO, Self::add)
1910 }
1911}
1912
1913impl<'a> Sum<&'a Self> for DVec2 {
1914 #[inline]
1915 fn sum<I>(iter: I) -> Self
1916 where
1917 I: Iterator<Item = &'a Self>,
1918 {
1919 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
1920 }
1921}
1922
1923impl Product for DVec2 {
1924 #[inline]
1925 fn product<I>(iter: I) -> Self
1926 where
1927 I: Iterator<Item = Self>,
1928 {
1929 iter.fold(Self::ONE, Self::mul)
1930 }
1931}
1932
1933impl<'a> Product<&'a Self> for DVec2 {
1934 #[inline]
1935 fn product<I>(iter: I) -> Self
1936 where
1937 I: Iterator<Item = &'a Self>,
1938 {
1939 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
1940 }
1941}
1942
1943impl Neg for DVec2 {
1944 type Output = Self;
1945 #[inline]
1946 fn neg(self) -> Self {
1947 Self::new(self.x.neg(), self.y.neg())
1948 }
1949}
1950
1951impl Neg for &DVec2 {
1952 type Output = DVec2;
1953 #[inline]
1954 fn neg(self) -> DVec2 {
1955 (*self).neg()
1956 }
1957}
1958
1959impl Index<usize> for DVec2 {
1960 type Output = f64;
1961 #[inline]
1962 #[track_caller]
1963 fn index(&self, index: usize) -> &Self::Output {
1964 match index {
1965 0 => &self.x,
1966 1 => &self.y,
1967 _ => panic!("index out of bounds"),
1968 }
1969 }
1970}
1971
1972impl IndexMut<usize> for DVec2 {
1973 #[inline]
1974 #[track_caller]
1975 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
1976 match index {
1977 0 => &mut self.x,
1978 1 => &mut self.y,
1979 _ => panic!("index out of bounds"),
1980 }
1981 }
1982}
1983
1984impl fmt::Display for DVec2 {
1985 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
1986 if let Some(p) = f.precision() {
1987 write!(f, "[{:.*}, {:.*}]", p, self.x, p, self.y)
1988 } else {
1989 write!(f, "[{}, {}]", self.x, self.y)
1990 }
1991 }
1992}
1993
1994impl fmt::Debug for DVec2 {
1995 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
1996 fmt.debug_tuple(stringify!(DVec2))
1997 .field(&self.x)
1998 .field(&self.y)
1999 .finish()
2000 }
2001}
2002
2003impl From<[f64; 2]> for DVec2 {
2004 #[inline]
2005 fn from(a: [f64; 2]) -> Self {
2006 Self::new(a[0], a[1])
2007 }
2008}
2009
2010impl From<DVec2> for [f64; 2] {
2011 #[inline]
2012 fn from(v: DVec2) -> Self {
2013 [v.x, v.y]
2014 }
2015}
2016
2017impl From<(f64, f64)> for DVec2 {
2018 #[inline]
2019 fn from(t: (f64, f64)) -> Self {
2020 Self::new(t.0, t.1)
2021 }
2022}
2023
2024impl From<DVec2> for (f64, f64) {
2025 #[inline]
2026 fn from(v: DVec2) -> Self {
2027 (v.x, v.y)
2028 }
2029}
2030
2031impl From<Vec2> for DVec2 {
2032 #[inline]
2033 fn from(v: Vec2) -> Self {
2034 Self::new(f64::from(v.x), f64::from(v.y))
2035 }
2036}
2037
2038#[cfg(feature = "i32")]
2039impl From<IVec2> for DVec2 {
2040 #[inline]
2041 fn from(v: IVec2) -> Self {
2042 Self::new(f64::from(v.x), f64::from(v.y))
2043 }
2044}
2045
2046#[cfg(feature = "u32")]
2047impl From<UVec2> for DVec2 {
2048 #[inline]
2049 fn from(v: UVec2) -> Self {
2050 Self::new(f64::from(v.x), f64::from(v.y))
2051 }
2052}
2053
2054impl From<BVec2> for DVec2 {
2055 #[inline]
2056 fn from(v: BVec2) -> Self {
2057 Self::new(f64::from(v.x), f64::from(v.y))
2058 }
2059}