1#[cfg(not(feature = "scalar-math"))]
4use crate::BVec4A;
5use crate::{f64::math, BVec4, DVec2, DVec3};
6
7use crate::Vec4;
8
9#[cfg(feature = "i32")]
10use crate::IVec4;
11
12#[cfg(feature = "u32")]
13use crate::UVec4;
14
15use core::fmt;
16use core::iter::{Product, Sum};
17use core::ops::*;
18
19#[cfg(feature = "zerocopy-08")]
20use zerocopy_derive_08::*;
21
22#[inline(always)]
24#[must_use]
25pub const fn dvec4(x: f64, y: f64, z: f64, w: f64) -> DVec4 {
26 DVec4::new(x, y, z, w)
27}
28
29#[derive(Clone, Copy, PartialEq)]
31#[cfg_attr(feature = "bytemuck", derive(bytemuck::Pod, bytemuck::Zeroable))]
32#[cfg_attr(
33 feature = "zerocopy-08",
34 derive(FromBytes, Immutable, IntoBytes, KnownLayout)
35)]
36#[cfg_attr(feature = "cuda", repr(align(16)))]
37#[repr(C)]
38#[cfg_attr(target_arch = "spirv", rust_gpu::vector::v1)]
39pub struct DVec4 {
40 pub x: f64,
41 pub y: f64,
42 pub z: f64,
43 pub w: f64,
44}
45
46impl DVec4 {
47 pub const ZERO: Self = Self::splat(0.0);
49
50 pub const ONE: Self = Self::splat(1.0);
52
53 pub const NEG_ONE: Self = Self::splat(-1.0);
55
56 pub const MIN: Self = Self::splat(f64::MIN);
58
59 pub const MAX: Self = Self::splat(f64::MAX);
61
62 pub const NAN: Self = Self::splat(f64::NAN);
64
65 pub const INFINITY: Self = Self::splat(f64::INFINITY);
67
68 pub const NEG_INFINITY: Self = Self::splat(f64::NEG_INFINITY);
70
71 pub const X: Self = Self::new(1.0, 0.0, 0.0, 0.0);
73
74 pub const Y: Self = Self::new(0.0, 1.0, 0.0, 0.0);
76
77 pub const Z: Self = Self::new(0.0, 0.0, 1.0, 0.0);
79
80 pub const W: Self = Self::new(0.0, 0.0, 0.0, 1.0);
82
83 pub const NEG_X: Self = Self::new(-1.0, 0.0, 0.0, 0.0);
85
86 pub const NEG_Y: Self = Self::new(0.0, -1.0, 0.0, 0.0);
88
89 pub const NEG_Z: Self = Self::new(0.0, 0.0, -1.0, 0.0);
91
92 pub const NEG_W: Self = Self::new(0.0, 0.0, 0.0, -1.0);
94
95 pub const AXES: [Self; 4] = [Self::X, Self::Y, Self::Z, Self::W];
97
98 pub const USES_CORE_SIMD: bool = false;
100 pub const USES_NEON: bool = false;
102 pub const USES_SCALAR_MATH: bool = true;
104 pub const USES_SSE2: bool = false;
106 pub const USES_WASM_SIMD: bool = false;
108 #[deprecated(since = "0.31.0", note = "Renamed to USES_WASM_SIMD")]
109 pub const USES_WASM32_SIMD: bool = false;
110
111 #[inline(always)]
113 #[must_use]
114 pub const fn new(x: f64, y: f64, z: f64, w: f64) -> Self {
115 Self { x, y, z, w }
116 }
117
118 #[inline]
120 #[must_use]
121 pub const fn splat(v: f64) -> Self {
122 Self::new(v, v, v, v)
123 }
124
125 #[inline]
127 #[must_use]
128 pub fn map<F>(self, mut f: F) -> Self
129 where
130 F: FnMut(f64) -> f64,
131 {
132 Self::new(f(self.x), f(self.y), f(self.z), f(self.w))
133 }
134
135 #[inline]
141 #[must_use]
142 pub fn select(mask: BVec4, if_true: Self, if_false: Self) -> Self {
143 Self::new(
144 if mask.test(0) { if_true.x } else { if_false.x },
145 if mask.test(1) { if_true.y } else { if_false.y },
146 if mask.test(2) { if_true.z } else { if_false.z },
147 if mask.test(3) { if_true.w } else { if_false.w },
148 )
149 }
150
151 #[inline]
153 #[must_use]
154 pub const fn from_array(a: [f64; 4]) -> Self {
155 Self::new(a[0], a[1], a[2], a[3])
156 }
157
158 #[inline]
160 #[must_use]
161 pub const fn to_array(&self) -> [f64; 4] {
162 [self.x, self.y, self.z, self.w]
163 }
164
165 #[inline]
171 #[must_use]
172 pub const fn from_slice(slice: &[f64]) -> Self {
173 assert!(slice.len() >= 4);
174 Self::new(slice[0], slice[1], slice[2], slice[3])
175 }
176
177 #[inline]
183 pub fn write_to_slice(self, slice: &mut [f64]) {
184 slice[..4].copy_from_slice(&self.to_array());
185 }
186
187 #[inline]
191 #[must_use]
192 pub fn truncate(self) -> DVec3 {
193 use crate::swizzles::Vec4Swizzles;
194 self.xyz()
195 }
196
197 #[inline]
203 #[must_use]
204 pub fn project(self) -> DVec3 {
205 DVec3::from_homogeneous(self)
206 }
207
208 #[inline]
210 #[must_use]
211 pub fn with_x(mut self, x: f64) -> Self {
212 self.x = x;
213 self
214 }
215
216 #[inline]
218 #[must_use]
219 pub fn with_y(mut self, y: f64) -> Self {
220 self.y = y;
221 self
222 }
223
224 #[inline]
226 #[must_use]
227 pub fn with_z(mut self, z: f64) -> Self {
228 self.z = z;
229 self
230 }
231
232 #[inline]
234 #[must_use]
235 pub fn with_w(mut self, w: f64) -> Self {
236 self.w = w;
237 self
238 }
239
240 #[inline]
242 #[must_use]
243 pub fn dot(self, rhs: Self) -> f64 {
244 (self.x * rhs.x) + (self.y * rhs.y) + (self.z * rhs.z) + (self.w * rhs.w)
245 }
246
247 #[inline]
249 #[must_use]
250 pub fn dot_into_vec(self, rhs: Self) -> Self {
251 Self::splat(self.dot(rhs))
252 }
253
254 #[inline]
261 #[must_use]
262 pub fn min(self, rhs: Self) -> Self {
263 Self::new(
264 if self.x < rhs.x { self.x } else { rhs.x },
265 if self.y < rhs.y { self.y } else { rhs.y },
266 if self.z < rhs.z { self.z } else { rhs.z },
267 if self.w < rhs.w { self.w } else { rhs.w },
268 )
269 }
270
271 #[inline]
278 #[must_use]
279 pub fn max(self, rhs: Self) -> Self {
280 Self::new(
281 if self.x > rhs.x { self.x } else { rhs.x },
282 if self.y > rhs.y { self.y } else { rhs.y },
283 if self.z > rhs.z { self.z } else { rhs.z },
284 if self.w > rhs.w { self.w } else { rhs.w },
285 )
286 }
287
288 #[inline]
299 #[must_use]
300 pub fn clamp(self, min: Self, max: Self) -> Self {
301 glam_assert!(min.cmple(max).all(), "clamp: expected min <= max");
302 self.max(min).min(max)
303 }
304
305 #[inline]
312 #[must_use]
313 pub fn min_element(self) -> f64 {
314 let min = |a, b| if a < b { a } else { b };
315 min(self.x, min(self.y, min(self.z, self.w)))
316 }
317
318 #[inline]
325 #[must_use]
326 pub fn max_element(self) -> f64 {
327 let max = |a, b| if a > b { a } else { b };
328 max(self.x, max(self.y, max(self.z, self.w)))
329 }
330
331 #[doc(alias = "argmin")]
333 #[inline]
334 #[must_use]
335 pub fn min_position(self) -> usize {
336 let mut min = self.x;
337 let mut index = 0;
338 if self.y < min {
339 min = self.y;
340 index = 1;
341 }
342 if self.z < min {
343 min = self.z;
344 index = 2;
345 }
346 if self.w < min {
347 index = 3;
348 }
349 index
350 }
351
352 #[doc(alias = "argmax")]
354 #[inline]
355 #[must_use]
356 pub fn max_position(self) -> usize {
357 let mut max = self.x;
358 let mut index = 0;
359 if self.y > max {
360 max = self.y;
361 index = 1;
362 }
363 if self.z > max {
364 max = self.z;
365 index = 2;
366 }
367 if self.w > max {
368 index = 3;
369 }
370 index
371 }
372
373 #[inline]
377 #[must_use]
378 pub fn element_sum(self) -> f64 {
379 self.x + self.y + self.z + self.w
380 }
381
382 #[inline]
386 #[must_use]
387 pub fn element_product(self) -> f64 {
388 self.x * self.y * self.z * self.w
389 }
390
391 #[inline]
397 #[must_use]
398 pub fn cmpeq(self, rhs: Self) -> BVec4 {
399 BVec4::new(
400 self.x.eq(&rhs.x),
401 self.y.eq(&rhs.y),
402 self.z.eq(&rhs.z),
403 self.w.eq(&rhs.w),
404 )
405 }
406
407 #[inline]
413 #[must_use]
414 pub fn cmpne(self, rhs: Self) -> BVec4 {
415 BVec4::new(
416 self.x.ne(&rhs.x),
417 self.y.ne(&rhs.y),
418 self.z.ne(&rhs.z),
419 self.w.ne(&rhs.w),
420 )
421 }
422
423 #[inline]
429 #[must_use]
430 pub fn cmpge(self, rhs: Self) -> BVec4 {
431 BVec4::new(
432 self.x.ge(&rhs.x),
433 self.y.ge(&rhs.y),
434 self.z.ge(&rhs.z),
435 self.w.ge(&rhs.w),
436 )
437 }
438
439 #[inline]
445 #[must_use]
446 pub fn cmpgt(self, rhs: Self) -> BVec4 {
447 BVec4::new(
448 self.x.gt(&rhs.x),
449 self.y.gt(&rhs.y),
450 self.z.gt(&rhs.z),
451 self.w.gt(&rhs.w),
452 )
453 }
454
455 #[inline]
461 #[must_use]
462 pub fn cmple(self, rhs: Self) -> BVec4 {
463 BVec4::new(
464 self.x.le(&rhs.x),
465 self.y.le(&rhs.y),
466 self.z.le(&rhs.z),
467 self.w.le(&rhs.w),
468 )
469 }
470
471 #[inline]
477 #[must_use]
478 pub fn cmplt(self, rhs: Self) -> BVec4 {
479 BVec4::new(
480 self.x.lt(&rhs.x),
481 self.y.lt(&rhs.y),
482 self.z.lt(&rhs.z),
483 self.w.lt(&rhs.w),
484 )
485 }
486
487 #[inline]
489 #[must_use]
490 pub fn abs(self) -> Self {
491 Self::new(
492 math::abs(self.x),
493 math::abs(self.y),
494 math::abs(self.z),
495 math::abs(self.w),
496 )
497 }
498
499 #[inline]
505 #[must_use]
506 pub fn signum(self) -> Self {
507 Self::new(
508 math::signum(self.x),
509 math::signum(self.y),
510 math::signum(self.z),
511 math::signum(self.w),
512 )
513 }
514
515 #[inline]
517 #[must_use]
518 pub fn copysign(self, rhs: Self) -> Self {
519 Self::new(
520 math::copysign(self.x, rhs.x),
521 math::copysign(self.y, rhs.y),
522 math::copysign(self.z, rhs.z),
523 math::copysign(self.w, rhs.w),
524 )
525 }
526
527 #[inline]
535 #[must_use]
536 pub fn is_negative_bitmask(self) -> u32 {
537 (self.x.is_sign_negative() as u32)
538 | ((self.y.is_sign_negative() as u32) << 1)
539 | ((self.z.is_sign_negative() as u32) << 2)
540 | ((self.w.is_sign_negative() as u32) << 3)
541 }
542
543 #[inline]
548 #[must_use]
549 pub fn is_negative_mask(self) -> BVec4 {
550 BVec4::new(
551 self.x.is_sign_negative(),
552 self.y.is_sign_negative(),
553 self.z.is_sign_negative(),
554 self.w.is_sign_negative(),
555 )
556 }
557
558 #[inline]
561 #[must_use]
562 pub fn is_finite(self) -> bool {
563 self.x.is_finite() && self.y.is_finite() && self.z.is_finite() && self.w.is_finite()
564 }
565
566 #[inline]
570 #[must_use]
571 pub fn is_finite_mask(self) -> BVec4 {
572 BVec4::new(
573 self.x.is_finite(),
574 self.y.is_finite(),
575 self.z.is_finite(),
576 self.w.is_finite(),
577 )
578 }
579
580 #[inline]
582 #[must_use]
583 pub fn is_nan(self) -> bool {
584 self.x.is_nan() || self.y.is_nan() || self.z.is_nan() || self.w.is_nan()
585 }
586
587 #[inline]
591 #[must_use]
592 pub fn is_nan_mask(self) -> BVec4 {
593 BVec4::new(
594 self.x.is_nan(),
595 self.y.is_nan(),
596 self.z.is_nan(),
597 self.w.is_nan(),
598 )
599 }
600
601 #[doc(alias = "magnitude")]
603 #[inline]
604 #[must_use]
605 pub fn length(self) -> f64 {
606 math::sqrt(self.dot(self))
607 }
608
609 #[allow(dead_code)]
611 fn is_non_zero(self) -> bool {
612 self.length_squared() > 0.0
613 }
614
615 #[doc(alias = "magnitude2")]
619 #[inline]
620 #[must_use]
621 pub fn length_squared(self) -> f64 {
622 self.dot(self)
623 }
624
625 #[inline]
629 #[must_use]
630 pub fn length_recip(self) -> f64 {
631 1.0 / self.length()
632 }
633
634 #[inline]
636 #[must_use]
637 pub fn distance(self, rhs: Self) -> f64 {
638 (self - rhs).length()
639 }
640
641 #[inline]
643 #[must_use]
644 pub fn distance_squared(self, rhs: Self) -> f64 {
645 (self - rhs).length_squared()
646 }
647
648 #[inline]
650 #[must_use]
651 pub fn div_euclid(self, rhs: Self) -> Self {
652 Self::new(
653 math::div_euclid(self.x, rhs.x),
654 math::div_euclid(self.y, rhs.y),
655 math::div_euclid(self.z, rhs.z),
656 math::div_euclid(self.w, rhs.w),
657 )
658 }
659
660 #[inline]
664 #[must_use]
665 pub fn rem_euclid(self, rhs: Self) -> Self {
666 Self::new(
667 math::rem_euclid(self.x, rhs.x),
668 math::rem_euclid(self.y, rhs.y),
669 math::rem_euclid(self.z, rhs.z),
670 math::rem_euclid(self.w, rhs.w),
671 )
672 }
673
674 #[inline]
684 #[must_use]
685 pub fn normalize(self) -> Self {
686 #[allow(clippy::let_and_return)]
687 let normalized = self.mul(self.length_recip());
688 glam_assert!(normalized.is_finite());
689 normalized
690 }
691
692 #[inline]
699 #[must_use]
700 pub fn try_normalize(self) -> Option<Self> {
701 let rcp = self.length_recip();
702 if rcp.is_finite() && rcp > 0.0 {
703 Some(self * rcp)
704 } else {
705 None
706 }
707 }
708
709 #[inline]
717 #[must_use]
718 pub fn normalize_or(self, fallback: Self) -> Self {
719 let rcp = self.length_recip();
720 if rcp.is_finite() && rcp > 0.0 {
721 self * rcp
722 } else {
723 fallback
724 }
725 }
726
727 #[inline]
734 #[must_use]
735 pub fn normalize_or_zero(self) -> Self {
736 self.normalize_or(Self::ZERO)
737 }
738
739 #[inline]
743 #[must_use]
744 pub fn normalize_and_length(self) -> (Self, f64) {
745 let length = self.length();
746 let rcp = 1.0 / length;
747 if rcp.is_finite() && rcp > 0.0 {
748 (self * rcp, length)
749 } else {
750 (Self::X, 0.0)
751 }
752 }
753
754 #[inline]
758 #[must_use]
759 pub fn is_normalized(self) -> bool {
760 math::abs(self.length_squared() - 1.0) <= 2e-4
761 }
762
763 #[inline]
771 #[must_use]
772 pub fn project_onto(self, rhs: Self) -> Self {
773 let other_len_sq_rcp = 1.0 / rhs.dot(rhs);
774 glam_assert!(other_len_sq_rcp.is_finite());
775 rhs * self.dot(rhs) * other_len_sq_rcp
776 }
777
778 #[doc(alias("plane"))]
789 #[inline]
790 #[must_use]
791 pub fn reject_from(self, rhs: Self) -> Self {
792 self - self.project_onto(rhs)
793 }
794
795 #[inline]
803 #[must_use]
804 pub fn project_onto_normalized(self, rhs: Self) -> Self {
805 glam_assert!(rhs.is_normalized());
806 rhs * self.dot(rhs)
807 }
808
809 #[doc(alias("plane"))]
820 #[inline]
821 #[must_use]
822 pub fn reject_from_normalized(self, rhs: Self) -> Self {
823 self - self.project_onto_normalized(rhs)
824 }
825
826 #[inline]
829 #[must_use]
830 pub fn round(self) -> Self {
831 Self::new(
832 math::round(self.x),
833 math::round(self.y),
834 math::round(self.z),
835 math::round(self.w),
836 )
837 }
838
839 #[inline]
842 #[must_use]
843 pub fn floor(self) -> Self {
844 Self::new(
845 math::floor(self.x),
846 math::floor(self.y),
847 math::floor(self.z),
848 math::floor(self.w),
849 )
850 }
851
852 #[inline]
855 #[must_use]
856 pub fn ceil(self) -> Self {
857 Self::new(
858 math::ceil(self.x),
859 math::ceil(self.y),
860 math::ceil(self.z),
861 math::ceil(self.w),
862 )
863 }
864
865 #[inline]
868 #[must_use]
869 pub fn trunc(self) -> Self {
870 Self::new(
871 math::trunc(self.x),
872 math::trunc(self.y),
873 math::trunc(self.z),
874 math::trunc(self.w),
875 )
876 }
877
878 #[inline]
882 #[must_use]
883 pub fn step(self, rhs: Self) -> Self {
884 Self::select(rhs.cmplt(self), Self::ZERO, Self::ONE)
885 }
886
887 #[inline]
898 #[must_use]
899 pub fn smoothstep(self, edge0: Self, edge1: Self) -> Self {
900 glam_assert!(edge0.cmplt(edge1).all());
901 let t = ((self - edge0) / (edge1 - edge0)).saturate();
902 t * t * (Self::splat(3.0) - Self::splat(2.0) * t)
903 }
904
905 #[inline]
907 #[must_use]
908 pub fn saturate(self) -> Self {
909 self.clamp(Self::ZERO, Self::ONE)
910 }
911
912 #[inline]
919 #[must_use]
920 pub fn fract(self) -> Self {
921 self - self.trunc()
922 }
923
924 #[inline]
931 #[must_use]
932 pub fn fract_gl(self) -> Self {
933 self - self.floor()
934 }
935
936 #[inline]
939 #[must_use]
940 pub fn exp(self) -> Self {
941 Self::new(
942 math::exp(self.x),
943 math::exp(self.y),
944 math::exp(self.z),
945 math::exp(self.w),
946 )
947 }
948
949 #[inline]
951 #[must_use]
952 pub fn exp2(self) -> Self {
953 Self::new(
954 math::exp2(self.x),
955 math::exp2(self.y),
956 math::exp2(self.z),
957 math::exp2(self.w),
958 )
959 }
960
961 #[inline]
964 #[must_use]
965 pub fn ln(self) -> Self {
966 Self::new(
967 math::ln(self.x),
968 math::ln(self.y),
969 math::ln(self.z),
970 math::ln(self.w),
971 )
972 }
973
974 #[inline]
977 #[must_use]
978 pub fn log2(self) -> Self {
979 Self::new(
980 math::log2(self.x),
981 math::log2(self.y),
982 math::log2(self.z),
983 math::log2(self.w),
984 )
985 }
986
987 #[inline]
989 #[must_use]
990 pub fn powf(self, n: f64) -> Self {
991 Self::new(
992 math::powf(self.x, n),
993 math::powf(self.y, n),
994 math::powf(self.z, n),
995 math::powf(self.w, n),
996 )
997 }
998
999 #[inline]
1002 #[must_use]
1003 pub fn sqrt(self) -> Self {
1004 Self::new(
1005 math::sqrt(self.x),
1006 math::sqrt(self.y),
1007 math::sqrt(self.z),
1008 math::sqrt(self.w),
1009 )
1010 }
1011
1012 #[inline]
1014 #[must_use]
1015 pub fn cos(self) -> Self {
1016 Self::new(
1017 math::cos(self.x),
1018 math::cos(self.y),
1019 math::cos(self.z),
1020 math::cos(self.w),
1021 )
1022 }
1023
1024 #[inline]
1026 #[must_use]
1027 pub fn sin(self) -> Self {
1028 Self::new(
1029 math::sin(self.x),
1030 math::sin(self.y),
1031 math::sin(self.z),
1032 math::sin(self.w),
1033 )
1034 }
1035
1036 #[inline]
1038 #[must_use]
1039 pub fn sin_cos(self) -> (Self, Self) {
1040 let (sin_x, cos_x) = math::sin_cos(self.x);
1041 let (sin_y, cos_y) = math::sin_cos(self.y);
1042 let (sin_z, cos_z) = math::sin_cos(self.z);
1043 let (sin_w, cos_w) = math::sin_cos(self.w);
1044
1045 (
1046 Self::new(sin_x, sin_y, sin_z, sin_w),
1047 Self::new(cos_x, cos_y, cos_z, cos_w),
1048 )
1049 }
1050
1051 #[inline]
1053 #[must_use]
1054 pub fn recip(self) -> Self {
1055 Self::new(1.0 / self.x, 1.0 / self.y, 1.0 / self.z, 1.0 / self.w)
1056 }
1057
1058 #[doc(alias = "mix")]
1070 #[inline]
1071 #[must_use]
1072 pub fn lerp(self, rhs: Self, s: f64) -> Self {
1073 self * (1.0 - s) + rhs * s
1074 }
1075
1076 #[doc(alias = "mix")]
1093 #[inline]
1094 #[must_use]
1095 pub fn lerp_monotonic(self, rhs: Self, s: f64) -> Self {
1096 self + (rhs - self) * s
1097 }
1098
1099 #[inline]
1104 #[must_use]
1105 pub fn move_towards(self, rhs: Self, d: f64) -> Self {
1106 let a = rhs - self;
1107 let len = a.length();
1108 if len <= d || len <= 1e-4 {
1109 return rhs;
1110 }
1111 self + a / len * d
1112 }
1113
1114 #[inline]
1120 pub fn midpoint(self, rhs: Self) -> Self {
1121 (self + rhs) * 0.5
1122 }
1123
1124 #[inline]
1134 #[must_use]
1135 pub fn abs_diff_eq(self, rhs: Self, max_abs_diff: f64) -> bool {
1136 self.sub(rhs).abs().cmple(Self::splat(max_abs_diff)).all()
1137 }
1138
1139 #[inline]
1145 #[must_use]
1146 pub fn clamp_length(self, min: f64, max: f64) -> Self {
1147 glam_assert!(0.0 <= min);
1148 glam_assert!(min <= max);
1149 let length_sq = self.length_squared();
1150 if length_sq < min * min {
1151 min * (self / math::sqrt(length_sq))
1152 } else if length_sq > max * max {
1153 max * (self / math::sqrt(length_sq))
1154 } else {
1155 self
1156 }
1157 }
1158
1159 #[inline]
1165 #[must_use]
1166 pub fn clamp_length_max(self, max: f64) -> Self {
1167 glam_assert!(0.0 <= max);
1168 let length_sq = self.length_squared();
1169 if length_sq > max * max {
1170 max * (self / math::sqrt(length_sq))
1171 } else {
1172 self
1173 }
1174 }
1175
1176 #[inline]
1182 #[must_use]
1183 pub fn clamp_length_min(self, min: f64) -> Self {
1184 glam_assert!(0.0 <= min);
1185 let length_sq = self.length_squared();
1186 if length_sq < min * min {
1187 min * (self / math::sqrt(length_sq))
1188 } else {
1189 self
1190 }
1191 }
1192
1193 #[inline]
1201 #[must_use]
1202 pub fn mul_add(self, a: Self, b: Self) -> Self {
1203 Self::new(
1204 math::mul_add(self.x, a.x, b.x),
1205 math::mul_add(self.y, a.y, b.y),
1206 math::mul_add(self.z, a.z, b.z),
1207 math::mul_add(self.w, a.w, b.w),
1208 )
1209 }
1210
1211 #[inline]
1220 #[must_use]
1221 pub fn reflect(self, normal: Self) -> Self {
1222 glam_assert!(normal.is_normalized());
1223 self - 2.0 * self.dot(normal) * normal
1224 }
1225
1226 #[inline]
1236 #[must_use]
1237 pub fn refract(self, normal: Self, eta: f64) -> Self {
1238 glam_assert!(self.is_normalized());
1239 glam_assert!(normal.is_normalized());
1240 let n_dot_i = normal.dot(self);
1241 let k = 1.0 - eta * eta * (1.0 - n_dot_i * n_dot_i);
1242 if k >= 0.0 {
1243 eta * self - (eta * n_dot_i + math::sqrt(k)) * normal
1244 } else {
1245 Self::ZERO
1246 }
1247 }
1248
1249 #[inline]
1251 #[must_use]
1252 pub fn as_vec4(self) -> crate::Vec4 {
1253 crate::Vec4::new(self.x as f32, self.y as f32, self.z as f32, self.w as f32)
1254 }
1255
1256 #[cfg(feature = "i8")]
1258 #[inline]
1259 #[must_use]
1260 pub fn as_i8vec4(self) -> crate::I8Vec4 {
1261 crate::I8Vec4::new(self.x as i8, self.y as i8, self.z as i8, self.w as i8)
1262 }
1263
1264 #[cfg(feature = "u8")]
1266 #[inline]
1267 #[must_use]
1268 pub fn as_u8vec4(self) -> crate::U8Vec4 {
1269 crate::U8Vec4::new(self.x as u8, self.y as u8, self.z as u8, self.w as u8)
1270 }
1271
1272 #[cfg(feature = "i16")]
1274 #[inline]
1275 #[must_use]
1276 pub fn as_i16vec4(self) -> crate::I16Vec4 {
1277 crate::I16Vec4::new(self.x as i16, self.y as i16, self.z as i16, self.w as i16)
1278 }
1279
1280 #[cfg(feature = "u16")]
1282 #[inline]
1283 #[must_use]
1284 pub fn as_u16vec4(self) -> crate::U16Vec4 {
1285 crate::U16Vec4::new(self.x as u16, self.y as u16, self.z as u16, self.w as u16)
1286 }
1287
1288 #[cfg(feature = "i32")]
1290 #[inline]
1291 #[must_use]
1292 pub fn as_ivec4(self) -> crate::IVec4 {
1293 crate::IVec4::new(self.x as i32, self.y as i32, self.z as i32, self.w as i32)
1294 }
1295
1296 #[cfg(feature = "u32")]
1298 #[inline]
1299 #[must_use]
1300 pub fn as_uvec4(self) -> crate::UVec4 {
1301 crate::UVec4::new(self.x as u32, self.y as u32, self.z as u32, self.w as u32)
1302 }
1303
1304 #[cfg(feature = "i64")]
1306 #[inline]
1307 #[must_use]
1308 pub fn as_i64vec4(self) -> crate::I64Vec4 {
1309 crate::I64Vec4::new(self.x as i64, self.y as i64, self.z as i64, self.w as i64)
1310 }
1311
1312 #[cfg(feature = "u64")]
1314 #[inline]
1315 #[must_use]
1316 pub fn as_u64vec4(self) -> crate::U64Vec4 {
1317 crate::U64Vec4::new(self.x as u64, self.y as u64, self.z as u64, self.w as u64)
1318 }
1319
1320 #[cfg(feature = "isize")]
1322 #[inline]
1323 #[must_use]
1324 pub fn as_isizevec4(self) -> crate::ISizeVec4 {
1325 crate::ISizeVec4::new(
1326 self.x as isize,
1327 self.y as isize,
1328 self.z as isize,
1329 self.w as isize,
1330 )
1331 }
1332
1333 #[cfg(feature = "usize")]
1335 #[inline]
1336 #[must_use]
1337 pub fn as_usizevec4(self) -> crate::USizeVec4 {
1338 crate::USizeVec4::new(
1339 self.x as usize,
1340 self.y as usize,
1341 self.z as usize,
1342 self.w as usize,
1343 )
1344 }
1345}
1346
1347impl Default for DVec4 {
1348 #[inline(always)]
1349 fn default() -> Self {
1350 Self::ZERO
1351 }
1352}
1353
1354impl Div for DVec4 {
1355 type Output = Self;
1356 #[inline]
1357 fn div(self, rhs: Self) -> Self {
1358 Self::new(
1359 self.x.div(rhs.x),
1360 self.y.div(rhs.y),
1361 self.z.div(rhs.z),
1362 self.w.div(rhs.w),
1363 )
1364 }
1365}
1366
1367impl Div<&Self> for DVec4 {
1368 type Output = Self;
1369 #[inline]
1370 fn div(self, rhs: &Self) -> Self {
1371 self.div(*rhs)
1372 }
1373}
1374
1375impl Div<&DVec4> for &DVec4 {
1376 type Output = DVec4;
1377 #[inline]
1378 fn div(self, rhs: &DVec4) -> DVec4 {
1379 (*self).div(*rhs)
1380 }
1381}
1382
1383impl Div<DVec4> for &DVec4 {
1384 type Output = DVec4;
1385 #[inline]
1386 fn div(self, rhs: DVec4) -> DVec4 {
1387 (*self).div(rhs)
1388 }
1389}
1390
1391impl DivAssign for DVec4 {
1392 #[inline]
1393 fn div_assign(&mut self, rhs: Self) {
1394 self.x.div_assign(rhs.x);
1395 self.y.div_assign(rhs.y);
1396 self.z.div_assign(rhs.z);
1397 self.w.div_assign(rhs.w);
1398 }
1399}
1400
1401impl DivAssign<&Self> for DVec4 {
1402 #[inline]
1403 fn div_assign(&mut self, rhs: &Self) {
1404 self.div_assign(*rhs);
1405 }
1406}
1407
1408impl Div<f64> for DVec4 {
1409 type Output = Self;
1410 #[inline]
1411 fn div(self, rhs: f64) -> Self {
1412 Self::new(
1413 self.x.div(rhs),
1414 self.y.div(rhs),
1415 self.z.div(rhs),
1416 self.w.div(rhs),
1417 )
1418 }
1419}
1420
1421impl Div<&f64> for DVec4 {
1422 type Output = Self;
1423 #[inline]
1424 fn div(self, rhs: &f64) -> Self {
1425 self.div(*rhs)
1426 }
1427}
1428
1429impl Div<&f64> for &DVec4 {
1430 type Output = DVec4;
1431 #[inline]
1432 fn div(self, rhs: &f64) -> DVec4 {
1433 (*self).div(*rhs)
1434 }
1435}
1436
1437impl Div<f64> for &DVec4 {
1438 type Output = DVec4;
1439 #[inline]
1440 fn div(self, rhs: f64) -> DVec4 {
1441 (*self).div(rhs)
1442 }
1443}
1444
1445impl DivAssign<f64> for DVec4 {
1446 #[inline]
1447 fn div_assign(&mut self, rhs: f64) {
1448 self.x.div_assign(rhs);
1449 self.y.div_assign(rhs);
1450 self.z.div_assign(rhs);
1451 self.w.div_assign(rhs);
1452 }
1453}
1454
1455impl DivAssign<&f64> for DVec4 {
1456 #[inline]
1457 fn div_assign(&mut self, rhs: &f64) {
1458 self.div_assign(*rhs);
1459 }
1460}
1461
1462impl Div<DVec4> for f64 {
1463 type Output = DVec4;
1464 #[inline]
1465 fn div(self, rhs: DVec4) -> DVec4 {
1466 DVec4::new(
1467 self.div(rhs.x),
1468 self.div(rhs.y),
1469 self.div(rhs.z),
1470 self.div(rhs.w),
1471 )
1472 }
1473}
1474
1475impl Div<&DVec4> for f64 {
1476 type Output = DVec4;
1477 #[inline]
1478 fn div(self, rhs: &DVec4) -> DVec4 {
1479 self.div(*rhs)
1480 }
1481}
1482
1483impl Div<&DVec4> for &f64 {
1484 type Output = DVec4;
1485 #[inline]
1486 fn div(self, rhs: &DVec4) -> DVec4 {
1487 (*self).div(*rhs)
1488 }
1489}
1490
1491impl Div<DVec4> for &f64 {
1492 type Output = DVec4;
1493 #[inline]
1494 fn div(self, rhs: DVec4) -> DVec4 {
1495 (*self).div(rhs)
1496 }
1497}
1498
1499impl Mul for DVec4 {
1500 type Output = Self;
1501 #[inline]
1502 fn mul(self, rhs: Self) -> Self {
1503 Self::new(
1504 self.x.mul(rhs.x),
1505 self.y.mul(rhs.y),
1506 self.z.mul(rhs.z),
1507 self.w.mul(rhs.w),
1508 )
1509 }
1510}
1511
1512impl Mul<&Self> for DVec4 {
1513 type Output = Self;
1514 #[inline]
1515 fn mul(self, rhs: &Self) -> Self {
1516 self.mul(*rhs)
1517 }
1518}
1519
1520impl Mul<&DVec4> for &DVec4 {
1521 type Output = DVec4;
1522 #[inline]
1523 fn mul(self, rhs: &DVec4) -> DVec4 {
1524 (*self).mul(*rhs)
1525 }
1526}
1527
1528impl Mul<DVec4> for &DVec4 {
1529 type Output = DVec4;
1530 #[inline]
1531 fn mul(self, rhs: DVec4) -> DVec4 {
1532 (*self).mul(rhs)
1533 }
1534}
1535
1536impl MulAssign for DVec4 {
1537 #[inline]
1538 fn mul_assign(&mut self, rhs: Self) {
1539 self.x.mul_assign(rhs.x);
1540 self.y.mul_assign(rhs.y);
1541 self.z.mul_assign(rhs.z);
1542 self.w.mul_assign(rhs.w);
1543 }
1544}
1545
1546impl MulAssign<&Self> for DVec4 {
1547 #[inline]
1548 fn mul_assign(&mut self, rhs: &Self) {
1549 self.mul_assign(*rhs);
1550 }
1551}
1552
1553impl Mul<f64> for DVec4 {
1554 type Output = Self;
1555 #[inline]
1556 fn mul(self, rhs: f64) -> Self {
1557 Self::new(
1558 self.x.mul(rhs),
1559 self.y.mul(rhs),
1560 self.z.mul(rhs),
1561 self.w.mul(rhs),
1562 )
1563 }
1564}
1565
1566impl Mul<&f64> for DVec4 {
1567 type Output = Self;
1568 #[inline]
1569 fn mul(self, rhs: &f64) -> Self {
1570 self.mul(*rhs)
1571 }
1572}
1573
1574impl Mul<&f64> for &DVec4 {
1575 type Output = DVec4;
1576 #[inline]
1577 fn mul(self, rhs: &f64) -> DVec4 {
1578 (*self).mul(*rhs)
1579 }
1580}
1581
1582impl Mul<f64> for &DVec4 {
1583 type Output = DVec4;
1584 #[inline]
1585 fn mul(self, rhs: f64) -> DVec4 {
1586 (*self).mul(rhs)
1587 }
1588}
1589
1590impl MulAssign<f64> for DVec4 {
1591 #[inline]
1592 fn mul_assign(&mut self, rhs: f64) {
1593 self.x.mul_assign(rhs);
1594 self.y.mul_assign(rhs);
1595 self.z.mul_assign(rhs);
1596 self.w.mul_assign(rhs);
1597 }
1598}
1599
1600impl MulAssign<&f64> for DVec4 {
1601 #[inline]
1602 fn mul_assign(&mut self, rhs: &f64) {
1603 self.mul_assign(*rhs);
1604 }
1605}
1606
1607impl Mul<DVec4> for f64 {
1608 type Output = DVec4;
1609 #[inline]
1610 fn mul(self, rhs: DVec4) -> DVec4 {
1611 DVec4::new(
1612 self.mul(rhs.x),
1613 self.mul(rhs.y),
1614 self.mul(rhs.z),
1615 self.mul(rhs.w),
1616 )
1617 }
1618}
1619
1620impl Mul<&DVec4> for f64 {
1621 type Output = DVec4;
1622 #[inline]
1623 fn mul(self, rhs: &DVec4) -> DVec4 {
1624 self.mul(*rhs)
1625 }
1626}
1627
1628impl Mul<&DVec4> for &f64 {
1629 type Output = DVec4;
1630 #[inline]
1631 fn mul(self, rhs: &DVec4) -> DVec4 {
1632 (*self).mul(*rhs)
1633 }
1634}
1635
1636impl Mul<DVec4> for &f64 {
1637 type Output = DVec4;
1638 #[inline]
1639 fn mul(self, rhs: DVec4) -> DVec4 {
1640 (*self).mul(rhs)
1641 }
1642}
1643
1644impl Add for DVec4 {
1645 type Output = Self;
1646 #[inline]
1647 fn add(self, rhs: Self) -> Self {
1648 Self::new(
1649 self.x.add(rhs.x),
1650 self.y.add(rhs.y),
1651 self.z.add(rhs.z),
1652 self.w.add(rhs.w),
1653 )
1654 }
1655}
1656
1657impl Add<&Self> for DVec4 {
1658 type Output = Self;
1659 #[inline]
1660 fn add(self, rhs: &Self) -> Self {
1661 self.add(*rhs)
1662 }
1663}
1664
1665impl Add<&DVec4> for &DVec4 {
1666 type Output = DVec4;
1667 #[inline]
1668 fn add(self, rhs: &DVec4) -> DVec4 {
1669 (*self).add(*rhs)
1670 }
1671}
1672
1673impl Add<DVec4> for &DVec4 {
1674 type Output = DVec4;
1675 #[inline]
1676 fn add(self, rhs: DVec4) -> DVec4 {
1677 (*self).add(rhs)
1678 }
1679}
1680
1681impl AddAssign for DVec4 {
1682 #[inline]
1683 fn add_assign(&mut self, rhs: Self) {
1684 self.x.add_assign(rhs.x);
1685 self.y.add_assign(rhs.y);
1686 self.z.add_assign(rhs.z);
1687 self.w.add_assign(rhs.w);
1688 }
1689}
1690
1691impl AddAssign<&Self> for DVec4 {
1692 #[inline]
1693 fn add_assign(&mut self, rhs: &Self) {
1694 self.add_assign(*rhs);
1695 }
1696}
1697
1698impl Add<f64> for DVec4 {
1699 type Output = Self;
1700 #[inline]
1701 fn add(self, rhs: f64) -> Self {
1702 Self::new(
1703 self.x.add(rhs),
1704 self.y.add(rhs),
1705 self.z.add(rhs),
1706 self.w.add(rhs),
1707 )
1708 }
1709}
1710
1711impl Add<&f64> for DVec4 {
1712 type Output = Self;
1713 #[inline]
1714 fn add(self, rhs: &f64) -> Self {
1715 self.add(*rhs)
1716 }
1717}
1718
1719impl Add<&f64> for &DVec4 {
1720 type Output = DVec4;
1721 #[inline]
1722 fn add(self, rhs: &f64) -> DVec4 {
1723 (*self).add(*rhs)
1724 }
1725}
1726
1727impl Add<f64> for &DVec4 {
1728 type Output = DVec4;
1729 #[inline]
1730 fn add(self, rhs: f64) -> DVec4 {
1731 (*self).add(rhs)
1732 }
1733}
1734
1735impl AddAssign<f64> for DVec4 {
1736 #[inline]
1737 fn add_assign(&mut self, rhs: f64) {
1738 self.x.add_assign(rhs);
1739 self.y.add_assign(rhs);
1740 self.z.add_assign(rhs);
1741 self.w.add_assign(rhs);
1742 }
1743}
1744
1745impl AddAssign<&f64> for DVec4 {
1746 #[inline]
1747 fn add_assign(&mut self, rhs: &f64) {
1748 self.add_assign(*rhs);
1749 }
1750}
1751
1752impl Add<DVec4> for f64 {
1753 type Output = DVec4;
1754 #[inline]
1755 fn add(self, rhs: DVec4) -> DVec4 {
1756 DVec4::new(
1757 self.add(rhs.x),
1758 self.add(rhs.y),
1759 self.add(rhs.z),
1760 self.add(rhs.w),
1761 )
1762 }
1763}
1764
1765impl Add<&DVec4> for f64 {
1766 type Output = DVec4;
1767 #[inline]
1768 fn add(self, rhs: &DVec4) -> DVec4 {
1769 self.add(*rhs)
1770 }
1771}
1772
1773impl Add<&DVec4> for &f64 {
1774 type Output = DVec4;
1775 #[inline]
1776 fn add(self, rhs: &DVec4) -> DVec4 {
1777 (*self).add(*rhs)
1778 }
1779}
1780
1781impl Add<DVec4> for &f64 {
1782 type Output = DVec4;
1783 #[inline]
1784 fn add(self, rhs: DVec4) -> DVec4 {
1785 (*self).add(rhs)
1786 }
1787}
1788
1789impl Sub for DVec4 {
1790 type Output = Self;
1791 #[inline]
1792 fn sub(self, rhs: Self) -> Self {
1793 Self::new(
1794 self.x.sub(rhs.x),
1795 self.y.sub(rhs.y),
1796 self.z.sub(rhs.z),
1797 self.w.sub(rhs.w),
1798 )
1799 }
1800}
1801
1802impl Sub<&Self> for DVec4 {
1803 type Output = Self;
1804 #[inline]
1805 fn sub(self, rhs: &Self) -> Self {
1806 self.sub(*rhs)
1807 }
1808}
1809
1810impl Sub<&DVec4> for &DVec4 {
1811 type Output = DVec4;
1812 #[inline]
1813 fn sub(self, rhs: &DVec4) -> DVec4 {
1814 (*self).sub(*rhs)
1815 }
1816}
1817
1818impl Sub<DVec4> for &DVec4 {
1819 type Output = DVec4;
1820 #[inline]
1821 fn sub(self, rhs: DVec4) -> DVec4 {
1822 (*self).sub(rhs)
1823 }
1824}
1825
1826impl SubAssign for DVec4 {
1827 #[inline]
1828 fn sub_assign(&mut self, rhs: Self) {
1829 self.x.sub_assign(rhs.x);
1830 self.y.sub_assign(rhs.y);
1831 self.z.sub_assign(rhs.z);
1832 self.w.sub_assign(rhs.w);
1833 }
1834}
1835
1836impl SubAssign<&Self> for DVec4 {
1837 #[inline]
1838 fn sub_assign(&mut self, rhs: &Self) {
1839 self.sub_assign(*rhs);
1840 }
1841}
1842
1843impl Sub<f64> for DVec4 {
1844 type Output = Self;
1845 #[inline]
1846 fn sub(self, rhs: f64) -> Self {
1847 Self::new(
1848 self.x.sub(rhs),
1849 self.y.sub(rhs),
1850 self.z.sub(rhs),
1851 self.w.sub(rhs),
1852 )
1853 }
1854}
1855
1856impl Sub<&f64> for DVec4 {
1857 type Output = Self;
1858 #[inline]
1859 fn sub(self, rhs: &f64) -> Self {
1860 self.sub(*rhs)
1861 }
1862}
1863
1864impl Sub<&f64> for &DVec4 {
1865 type Output = DVec4;
1866 #[inline]
1867 fn sub(self, rhs: &f64) -> DVec4 {
1868 (*self).sub(*rhs)
1869 }
1870}
1871
1872impl Sub<f64> for &DVec4 {
1873 type Output = DVec4;
1874 #[inline]
1875 fn sub(self, rhs: f64) -> DVec4 {
1876 (*self).sub(rhs)
1877 }
1878}
1879
1880impl SubAssign<f64> for DVec4 {
1881 #[inline]
1882 fn sub_assign(&mut self, rhs: f64) {
1883 self.x.sub_assign(rhs);
1884 self.y.sub_assign(rhs);
1885 self.z.sub_assign(rhs);
1886 self.w.sub_assign(rhs);
1887 }
1888}
1889
1890impl SubAssign<&f64> for DVec4 {
1891 #[inline]
1892 fn sub_assign(&mut self, rhs: &f64) {
1893 self.sub_assign(*rhs);
1894 }
1895}
1896
1897impl Sub<DVec4> for f64 {
1898 type Output = DVec4;
1899 #[inline]
1900 fn sub(self, rhs: DVec4) -> DVec4 {
1901 DVec4::new(
1902 self.sub(rhs.x),
1903 self.sub(rhs.y),
1904 self.sub(rhs.z),
1905 self.sub(rhs.w),
1906 )
1907 }
1908}
1909
1910impl Sub<&DVec4> for f64 {
1911 type Output = DVec4;
1912 #[inline]
1913 fn sub(self, rhs: &DVec4) -> DVec4 {
1914 self.sub(*rhs)
1915 }
1916}
1917
1918impl Sub<&DVec4> for &f64 {
1919 type Output = DVec4;
1920 #[inline]
1921 fn sub(self, rhs: &DVec4) -> DVec4 {
1922 (*self).sub(*rhs)
1923 }
1924}
1925
1926impl Sub<DVec4> for &f64 {
1927 type Output = DVec4;
1928 #[inline]
1929 fn sub(self, rhs: DVec4) -> DVec4 {
1930 (*self).sub(rhs)
1931 }
1932}
1933
1934impl Rem for DVec4 {
1935 type Output = Self;
1936 #[inline]
1937 fn rem(self, rhs: Self) -> Self {
1938 Self::new(
1939 self.x.rem(rhs.x),
1940 self.y.rem(rhs.y),
1941 self.z.rem(rhs.z),
1942 self.w.rem(rhs.w),
1943 )
1944 }
1945}
1946
1947impl Rem<&Self> for DVec4 {
1948 type Output = Self;
1949 #[inline]
1950 fn rem(self, rhs: &Self) -> Self {
1951 self.rem(*rhs)
1952 }
1953}
1954
1955impl Rem<&DVec4> for &DVec4 {
1956 type Output = DVec4;
1957 #[inline]
1958 fn rem(self, rhs: &DVec4) -> DVec4 {
1959 (*self).rem(*rhs)
1960 }
1961}
1962
1963impl Rem<DVec4> for &DVec4 {
1964 type Output = DVec4;
1965 #[inline]
1966 fn rem(self, rhs: DVec4) -> DVec4 {
1967 (*self).rem(rhs)
1968 }
1969}
1970
1971impl RemAssign for DVec4 {
1972 #[inline]
1973 fn rem_assign(&mut self, rhs: Self) {
1974 self.x.rem_assign(rhs.x);
1975 self.y.rem_assign(rhs.y);
1976 self.z.rem_assign(rhs.z);
1977 self.w.rem_assign(rhs.w);
1978 }
1979}
1980
1981impl RemAssign<&Self> for DVec4 {
1982 #[inline]
1983 fn rem_assign(&mut self, rhs: &Self) {
1984 self.rem_assign(*rhs);
1985 }
1986}
1987
1988impl Rem<f64> for DVec4 {
1989 type Output = Self;
1990 #[inline]
1991 fn rem(self, rhs: f64) -> Self {
1992 Self::new(
1993 self.x.rem(rhs),
1994 self.y.rem(rhs),
1995 self.z.rem(rhs),
1996 self.w.rem(rhs),
1997 )
1998 }
1999}
2000
2001impl Rem<&f64> for DVec4 {
2002 type Output = Self;
2003 #[inline]
2004 fn rem(self, rhs: &f64) -> Self {
2005 self.rem(*rhs)
2006 }
2007}
2008
2009impl Rem<&f64> for &DVec4 {
2010 type Output = DVec4;
2011 #[inline]
2012 fn rem(self, rhs: &f64) -> DVec4 {
2013 (*self).rem(*rhs)
2014 }
2015}
2016
2017impl Rem<f64> for &DVec4 {
2018 type Output = DVec4;
2019 #[inline]
2020 fn rem(self, rhs: f64) -> DVec4 {
2021 (*self).rem(rhs)
2022 }
2023}
2024
2025impl RemAssign<f64> for DVec4 {
2026 #[inline]
2027 fn rem_assign(&mut self, rhs: f64) {
2028 self.x.rem_assign(rhs);
2029 self.y.rem_assign(rhs);
2030 self.z.rem_assign(rhs);
2031 self.w.rem_assign(rhs);
2032 }
2033}
2034
2035impl RemAssign<&f64> for DVec4 {
2036 #[inline]
2037 fn rem_assign(&mut self, rhs: &f64) {
2038 self.rem_assign(*rhs);
2039 }
2040}
2041
2042impl Rem<DVec4> for f64 {
2043 type Output = DVec4;
2044 #[inline]
2045 fn rem(self, rhs: DVec4) -> DVec4 {
2046 DVec4::new(
2047 self.rem(rhs.x),
2048 self.rem(rhs.y),
2049 self.rem(rhs.z),
2050 self.rem(rhs.w),
2051 )
2052 }
2053}
2054
2055impl Rem<&DVec4> for f64 {
2056 type Output = DVec4;
2057 #[inline]
2058 fn rem(self, rhs: &DVec4) -> DVec4 {
2059 self.rem(*rhs)
2060 }
2061}
2062
2063impl Rem<&DVec4> for &f64 {
2064 type Output = DVec4;
2065 #[inline]
2066 fn rem(self, rhs: &DVec4) -> DVec4 {
2067 (*self).rem(*rhs)
2068 }
2069}
2070
2071impl Rem<DVec4> for &f64 {
2072 type Output = DVec4;
2073 #[inline]
2074 fn rem(self, rhs: DVec4) -> DVec4 {
2075 (*self).rem(rhs)
2076 }
2077}
2078
2079impl AsRef<[f64; 4]> for DVec4 {
2080 #[inline]
2081 fn as_ref(&self) -> &[f64; 4] {
2082 unsafe { &*(self as *const Self as *const [f64; 4]) }
2083 }
2084}
2085
2086impl AsMut<[f64; 4]> for DVec4 {
2087 #[inline]
2088 fn as_mut(&mut self) -> &mut [f64; 4] {
2089 unsafe { &mut *(self as *mut Self as *mut [f64; 4]) }
2090 }
2091}
2092
2093impl Sum for DVec4 {
2094 #[inline]
2095 fn sum<I>(iter: I) -> Self
2096 where
2097 I: Iterator<Item = Self>,
2098 {
2099 iter.fold(Self::ZERO, Self::add)
2100 }
2101}
2102
2103impl<'a> Sum<&'a Self> for DVec4 {
2104 #[inline]
2105 fn sum<I>(iter: I) -> Self
2106 where
2107 I: Iterator<Item = &'a Self>,
2108 {
2109 iter.fold(Self::ZERO, |a, &b| Self::add(a, b))
2110 }
2111}
2112
2113impl Product for DVec4 {
2114 #[inline]
2115 fn product<I>(iter: I) -> Self
2116 where
2117 I: Iterator<Item = Self>,
2118 {
2119 iter.fold(Self::ONE, Self::mul)
2120 }
2121}
2122
2123impl<'a> Product<&'a Self> for DVec4 {
2124 #[inline]
2125 fn product<I>(iter: I) -> Self
2126 where
2127 I: Iterator<Item = &'a Self>,
2128 {
2129 iter.fold(Self::ONE, |a, &b| Self::mul(a, b))
2130 }
2131}
2132
2133impl Neg for DVec4 {
2134 type Output = Self;
2135 #[inline]
2136 fn neg(self) -> Self {
2137 Self::new(self.x.neg(), self.y.neg(), self.z.neg(), self.w.neg())
2138 }
2139}
2140
2141impl Neg for &DVec4 {
2142 type Output = DVec4;
2143 #[inline]
2144 fn neg(self) -> DVec4 {
2145 (*self).neg()
2146 }
2147}
2148
2149impl Index<usize> for DVec4 {
2150 type Output = f64;
2151 #[inline]
2152 fn index(&self, index: usize) -> &Self::Output {
2153 match index {
2154 0 => &self.x,
2155 1 => &self.y,
2156 2 => &self.z,
2157 3 => &self.w,
2158 _ => panic!("index out of bounds"),
2159 }
2160 }
2161}
2162
2163impl IndexMut<usize> for DVec4 {
2164 #[inline]
2165 fn index_mut(&mut self, index: usize) -> &mut Self::Output {
2166 match index {
2167 0 => &mut self.x,
2168 1 => &mut self.y,
2169 2 => &mut self.z,
2170 3 => &mut self.w,
2171 _ => panic!("index out of bounds"),
2172 }
2173 }
2174}
2175
2176impl fmt::Display for DVec4 {
2177 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
2178 if let Some(p) = f.precision() {
2179 write!(
2180 f,
2181 "[{:.*}, {:.*}, {:.*}, {:.*}]",
2182 p, self.x, p, self.y, p, self.z, p, self.w
2183 )
2184 } else {
2185 write!(f, "[{}, {}, {}, {}]", self.x, self.y, self.z, self.w)
2186 }
2187 }
2188}
2189
2190impl fmt::Debug for DVec4 {
2191 fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
2192 fmt.debug_tuple(stringify!(DVec4))
2193 .field(&self.x)
2194 .field(&self.y)
2195 .field(&self.z)
2196 .field(&self.w)
2197 .finish()
2198 }
2199}
2200
2201impl From<[f64; 4]> for DVec4 {
2202 #[inline]
2203 fn from(a: [f64; 4]) -> Self {
2204 Self::new(a[0], a[1], a[2], a[3])
2205 }
2206}
2207
2208impl From<DVec4> for [f64; 4] {
2209 #[inline]
2210 fn from(v: DVec4) -> Self {
2211 [v.x, v.y, v.z, v.w]
2212 }
2213}
2214
2215impl From<(f64, f64, f64, f64)> for DVec4 {
2216 #[inline]
2217 fn from(t: (f64, f64, f64, f64)) -> Self {
2218 Self::new(t.0, t.1, t.2, t.3)
2219 }
2220}
2221
2222impl From<DVec4> for (f64, f64, f64, f64) {
2223 #[inline]
2224 fn from(v: DVec4) -> Self {
2225 (v.x, v.y, v.z, v.w)
2226 }
2227}
2228
2229impl From<(DVec3, f64)> for DVec4 {
2230 #[inline]
2231 fn from((v, w): (DVec3, f64)) -> Self {
2232 Self::new(v.x, v.y, v.z, w)
2233 }
2234}
2235
2236impl From<(f64, DVec3)> for DVec4 {
2237 #[inline]
2238 fn from((x, v): (f64, DVec3)) -> Self {
2239 Self::new(x, v.x, v.y, v.z)
2240 }
2241}
2242
2243impl From<(DVec2, f64, f64)> for DVec4 {
2244 #[inline]
2245 fn from((v, z, w): (DVec2, f64, f64)) -> Self {
2246 Self::new(v.x, v.y, z, w)
2247 }
2248}
2249
2250impl From<(DVec2, DVec2)> for DVec4 {
2251 #[inline]
2252 fn from((v, u): (DVec2, DVec2)) -> Self {
2253 Self::new(v.x, v.y, u.x, u.y)
2254 }
2255}
2256
2257impl From<Vec4> for DVec4 {
2258 #[inline]
2259 fn from(v: Vec4) -> Self {
2260 Self::new(
2261 f64::from(v.x),
2262 f64::from(v.y),
2263 f64::from(v.z),
2264 f64::from(v.w),
2265 )
2266 }
2267}
2268
2269#[cfg(feature = "i32")]
2270impl From<IVec4> for DVec4 {
2271 #[inline]
2272 fn from(v: IVec4) -> Self {
2273 Self::new(
2274 f64::from(v.x),
2275 f64::from(v.y),
2276 f64::from(v.z),
2277 f64::from(v.w),
2278 )
2279 }
2280}
2281
2282#[cfg(feature = "u32")]
2283impl From<UVec4> for DVec4 {
2284 #[inline]
2285 fn from(v: UVec4) -> Self {
2286 Self::new(
2287 f64::from(v.x),
2288 f64::from(v.y),
2289 f64::from(v.z),
2290 f64::from(v.w),
2291 )
2292 }
2293}
2294
2295impl From<BVec4> for DVec4 {
2296 #[inline]
2297 fn from(v: BVec4) -> Self {
2298 Self::new(
2299 f64::from(v.x),
2300 f64::from(v.y),
2301 f64::from(v.z),
2302 f64::from(v.w),
2303 )
2304 }
2305}
2306
2307#[cfg(not(feature = "scalar-math"))]
2308impl From<BVec4A> for DVec4 {
2309 #[inline]
2310 fn from(v: BVec4A) -> Self {
2311 let bool_array: [bool; 4] = v.into();
2312 Self::new(
2313 f64::from(bool_array[0]),
2314 f64::from(bool_array[1]),
2315 f64::from(bool_array[2]),
2316 f64::from(bool_array[3]),
2317 )
2318 }
2319}